@metamask/keyring-api 0.1.3 → 0.2.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 (52) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/JsonRpcRequest.d.ts +15 -0
  3. package/dist/JsonRpcRequest.js +18 -0
  4. package/dist/JsonRpcRequest.js.map +1 -0
  5. package/dist/{keyring-client.d.ts → KeyringClient.d.ts} +7 -6
  6. package/dist/{keyring-client.js → KeyringClient.js} +25 -20
  7. package/dist/KeyringClient.js.map +1 -0
  8. package/dist/{keyring-snap-controller-client.d.ts → KeyringSnapControllerClient.d.ts} +7 -1
  9. package/dist/{keyring-snap-controller-client.js → KeyringSnapControllerClient.js} +13 -7
  10. package/dist/KeyringSnapControllerClient.js.map +1 -0
  11. package/dist/{keyring-snap-rpc-client.d.ts → KeyringSnapRpcClient.d.ts} +4 -3
  12. package/dist/{keyring-snap-rpc-client.js → KeyringSnapRpcClient.js} +5 -7
  13. package/dist/KeyringSnapRpcClient.js.map +1 -0
  14. package/dist/{keyring-api.d.ts → api.d.ts} +72 -52
  15. package/dist/api.js +110 -0
  16. package/dist/api.js.map +1 -0
  17. package/dist/events.d.ts +10 -0
  18. package/dist/events.js +17 -0
  19. package/dist/events.js.map +1 -0
  20. package/dist/index.d.ts +6 -5
  21. package/dist/index.js +6 -5
  22. package/dist/index.js.map +1 -1
  23. package/dist/{keyring-internal-api.d.ts → internal/api.d.ts} +129 -260
  24. package/dist/internal/api.js +126 -0
  25. package/dist/internal/api.js.map +1 -0
  26. package/dist/internal/events.d.ts +162 -0
  27. package/dist/internal/events.js +58 -0
  28. package/dist/internal/events.js.map +1 -0
  29. package/dist/internal/index.d.ts +2 -0
  30. package/dist/internal/index.js +19 -0
  31. package/dist/internal/index.js.map +1 -0
  32. package/dist/internal/types.d.ts +67 -0
  33. package/dist/internal/types.js +19 -0
  34. package/dist/internal/types.js.map +1 -0
  35. package/dist/{keyring-rpc-dispatcher.d.ts → rpc-handler.d.ts} +17 -2
  36. package/dist/rpc-handler.js +141 -0
  37. package/dist/rpc-handler.js.map +1 -0
  38. package/dist/snap-utils.d.ts +11 -0
  39. package/dist/snap-utils.js +21 -0
  40. package/dist/snap-utils.js.map +1 -0
  41. package/dist/utils.d.ts +3 -3
  42. package/dist/utils.js.map +1 -1
  43. package/package.json +14 -10
  44. package/dist/keyring-api.js +0 -81
  45. package/dist/keyring-api.js.map +0 -1
  46. package/dist/keyring-client.js.map +0 -1
  47. package/dist/keyring-internal-api.js +0 -154
  48. package/dist/keyring-internal-api.js.map +0 -1
  49. package/dist/keyring-rpc-dispatcher.js +0 -107
  50. package/dist/keyring-rpc-dispatcher.js.map +0 -1
  51. package/dist/keyring-snap-controller-client.js.map +0 -1
  52. package/dist/keyring-snap-rpc-client.js.map +0 -1
@@ -1,21 +1,35 @@
1
- import { Json } from '@metamask/utils';
2
- import { Infer } from 'superstruct';
1
+ import { type Json } from '@metamask/utils';
2
+ import { type Infer } from 'superstruct';
3
+ /**
4
+ * Supported Ethereum methods.
5
+ */
6
+ export declare enum EthMethod {
7
+ PersonalSign = "personal_sign",
8
+ Sign = "eth_sign",
9
+ SignTransaction = "eth_signTransaction",
10
+ SignTypedData = "eth_signTypedData",
11
+ SignTypedDataV1 = "eth_signTypedData_v1",
12
+ SignTypedDataV3 = "eth_signTypedData_v3",
13
+ SignTypedDataV4 = "eth_signTypedData_v4"
14
+ }
15
+ /**
16
+ * Supported Ethereum account types.
17
+ */
18
+ export declare enum EthAccountType {
19
+ Eoa = "eip155:eoa",
20
+ Eip4337 = "eip155:eip4337"
21
+ }
3
22
  export declare const KeyringAccountStruct: import("superstruct").Struct<{
4
23
  id: string;
5
- name: string;
6
24
  address: string;
7
- options: Record<string, Json> | null;
8
- supportedMethods: ("personal_sign" | "eth_sendTransaction" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v2" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
9
- type: "eip155:eoa" | "eip155:erc4337";
25
+ options: Record<string, Json>;
26
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
27
+ type: "eip155:eoa" | "eip155:eip4337";
10
28
  }, {
11
29
  /**
12
30
  * Account ID (UUIDv4).
13
31
  */
14
32
  id: import("superstruct").Struct<string, null>;
15
- /**
16
- * User-chosen account name.
17
- */
18
- name: import("superstruct").Struct<string, null>;
19
33
  /**
20
34
  * Account address or next receive address (UTXO).
21
35
  */
@@ -23,27 +37,25 @@ export declare const KeyringAccountStruct: import("superstruct").Struct<{
23
37
  /**
24
38
  * Keyring-dependent account options.
25
39
  */
26
- options: import("superstruct").Struct<Record<string, Json> | null, null>;
40
+ options: import("superstruct").Struct<Record<string, Json>, null>;
27
41
  /**
28
42
  * Account supported methods.
29
43
  */
30
- supportedMethods: import("superstruct").Struct<("personal_sign" | "eth_sendTransaction" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v2" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sendTransaction" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v2" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
44
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
31
45
  personal_sign: "personal_sign";
32
- eth_sendTransaction: "eth_sendTransaction";
33
46
  eth_sign: "eth_sign";
34
47
  eth_signTransaction: "eth_signTransaction";
35
48
  eth_signTypedData: "eth_signTypedData";
36
49
  eth_signTypedData_v1: "eth_signTypedData_v1";
37
- eth_signTypedData_v2: "eth_signTypedData_v2";
38
50
  eth_signTypedData_v3: "eth_signTypedData_v3";
39
51
  eth_signTypedData_v4: "eth_signTypedData_v4";
40
52
  }>>;
41
53
  /**
42
54
  * Account type.
43
55
  */
44
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
56
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
45
57
  "eip155:eoa": "eip155:eoa";
46
- "eip155:erc4337": "eip155:erc4337";
58
+ "eip155:eip4337": "eip155:eip4337";
47
59
  }>;
48
60
  }>;
49
61
  /**
@@ -52,35 +64,18 @@ export declare const KeyringAccountStruct: import("superstruct").Struct<{
52
64
  * Represents an account with its properties and capabilities.
53
65
  */
54
66
  export declare type KeyringAccount = Infer<typeof KeyringAccountStruct>;
55
- export declare const KeyringJsonRpcRequestStruct: import("superstruct").Struct<{
56
- id: string;
57
- jsonrpc: "2.0";
58
- method: string;
59
- } | {
60
- id: string;
61
- jsonrpc: "2.0";
62
- method: string;
63
- params: Record<string, Json> | Json[];
64
- }, null>;
65
- /**
66
- * JSON-RPC request type.
67
- *
68
- * Represents a JSON-RPC request sent by a dApp. The request ID must be a
69
- * string and the params field cannot be undefined.
70
- */
71
- export declare type KeyringJsonRpcRequest = Infer<typeof KeyringJsonRpcRequestStruct>;
72
67
  export declare const KeyringRequestStruct: import("superstruct").Struct<{
73
68
  account: string;
74
69
  scope: string;
75
70
  request: {
76
- id: string;
77
71
  jsonrpc: "2.0";
72
+ id: string | number | null;
78
73
  method: string;
79
74
  } | {
80
- id: string;
81
75
  jsonrpc: "2.0";
76
+ id: string | number | null;
82
77
  method: string;
83
- params: Record<string, Json> | Json[];
78
+ params: Json[] | Record<string, Json>;
84
79
  };
85
80
  }, {
86
81
  /**
@@ -97,14 +92,14 @@ export declare const KeyringRequestStruct: import("superstruct").Struct<{
97
92
  * Note: The request ID must be a string.
98
93
  */
99
94
  request: import("superstruct").Struct<{
100
- id: string;
101
95
  jsonrpc: "2.0";
96
+ id: string | number | null;
102
97
  method: string;
103
98
  } | {
104
- id: string;
105
99
  jsonrpc: "2.0";
100
+ id: string | number | null;
106
101
  method: string;
107
- params: Record<string, Json> | Json[];
102
+ params: Json[] | Record<string, Json>;
108
103
  }, null>;
109
104
  }>;
110
105
  /**
@@ -113,16 +108,33 @@ export declare const KeyringRequestStruct: import("superstruct").Struct<{
113
108
  * Represents a request made to the keyring for account-related operations.
114
109
  */
115
110
  export declare type KeyringRequest = Infer<typeof KeyringRequestStruct>;
116
- export declare const SubmitRequestResponseStruct: import("superstruct").Struct<{
111
+ export declare const KeyringAccountDataStruct: import("superstruct").Struct<Record<string, Json>, null>;
112
+ /**
113
+ * Response to a call to `exportAccount`.
114
+ *
115
+ * The exact response depends on the keyring implementation.
116
+ */
117
+ export declare type KeyringAccountData = Infer<typeof KeyringAccountDataStruct>;
118
+ export declare const KeyringResponseStruct: import("superstruct").Struct<{
117
119
  pending: true;
120
+ redirect: string | null;
118
121
  } | {
119
122
  pending: false;
120
123
  result: Json;
121
124
  }, null>;
122
125
  /**
123
- * Response returned when submitting a request to the Keyring.
126
+ * Response to a call to `submitRequest`.
127
+ *
128
+ * Keyring implementations must return a response with `pending: true` if the
129
+ * request will be handled asynchronously. Otherwise, the response must contain
130
+ * the result of the request and `pending: false`.
131
+ *
132
+ * In the asynchronous case, the keyring can return a redirect URL to be shown
133
+ * to the user. The user can choose to follow the link or cancel the request.
134
+ * The main use case for this is to redirect the user to a third-party service
135
+ * to approve the request.
124
136
  */
125
- export declare type SubmitRequestResponse = Infer<typeof SubmitRequestResponseStruct>;
137
+ export declare type KeyringResponse = Infer<typeof KeyringResponseStruct>;
126
138
  /**
127
139
  * Keyring interface.
128
140
  *
@@ -152,15 +164,13 @@ export declare type Keyring = {
152
164
  /**
153
165
  * Create an account.
154
166
  *
155
- * Creates a new account with the given name, supported chains, and optional
156
- * account options.
167
+ * Creates a new account with optional, keyring-defined, account options.
157
168
  *
158
- * @param name - The name of the account.
159
169
  * @param options - Keyring-defined options for the account (optional).
160
170
  * @returns A promise that resolves to the newly created KeyringAccount
161
171
  * object without any private information.
162
172
  */
163
- createAccount(name: string, options?: Record<string, Json> | null): Promise<KeyringAccount>;
173
+ createAccount(options?: Record<string, Json>): Promise<KeyringAccount>;
164
174
  /**
165
175
  * Filter supported chains for a given account.
166
176
  *
@@ -189,6 +199,16 @@ export declare type Keyring = {
189
199
  * @returns A promise that resolves when the account is successfully deleted.
190
200
  */
191
201
  deleteAccount(id: string): Promise<void>;
202
+ /**
203
+ * Exports an account's private key.
204
+ *
205
+ * If the keyring cannot export a private key, this function should throw an
206
+ * error.
207
+ *
208
+ * @param id - The ID of the account to export.
209
+ * @returns A promise that resolves to the exported account.
210
+ */
211
+ exportAccount?(id: string): Promise<KeyringAccountData>;
192
212
  /**
193
213
  * List all submitted requests.
194
214
  *
@@ -197,7 +217,7 @@ export declare type Keyring = {
197
217
  *
198
218
  * @returns A promise that resolves to an array of KeyringRequest objects.
199
219
  */
200
- listRequests(): Promise<KeyringRequest[]>;
220
+ listRequests?(): Promise<KeyringRequest[]>;
201
221
  /**
202
222
  * Get a request.
203
223
  *
@@ -207,7 +227,7 @@ export declare type Keyring = {
207
227
  * @returns A promise that resolves to the KeyringRequest object if found, or
208
228
  * undefined otherwise.
209
229
  */
210
- getRequest(id: string): Promise<KeyringRequest | undefined>;
230
+ getRequest?(id: string): Promise<KeyringRequest | undefined>;
211
231
  /**
212
232
  * Submit a request.
213
233
  *
@@ -216,18 +236,18 @@ export declare type Keyring = {
216
236
  * @param request - The KeyringRequest object to submit.
217
237
  * @returns A promise that resolves to the request response.
218
238
  */
219
- submitRequest(request: KeyringRequest): Promise<SubmitRequestResponse>;
239
+ submitRequest(request: KeyringRequest): Promise<KeyringResponse>;
220
240
  /**
221
241
  * Approve a request.
222
242
  *
223
243
  * Approves the request with the given ID and sets the response if provided.
224
244
  *
225
245
  * @param id - The ID of the request to approve.
226
- * @param result - The response to the request (optional).
246
+ * @param data - The response to the request (optional).
227
247
  * @returns A promise that resolves when the request is successfully
228
248
  * approved.
229
249
  */
230
- approveRequest(id: string, result?: Json): Promise<void>;
250
+ approveRequest?(id: string, data?: Record<string, Json>): Promise<void>;
231
251
  /**
232
252
  * Reject a request.
233
253
  *
@@ -237,5 +257,5 @@ export declare type Keyring = {
237
257
  * @returns A promise that resolves when the request is successfully
238
258
  * rejected.
239
259
  */
240
- rejectRequest(id: string): Promise<void>;
260
+ rejectRequest?(id: string): Promise<void>;
241
261
  };
package/dist/api.js ADDED
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringResponseStruct = exports.KeyringAccountDataStruct = exports.KeyringRequestStruct = exports.KeyringAccountStruct = exports.EthAccountType = exports.EthMethod = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const superstruct_1 = require("superstruct");
6
+ const JsonRpcRequest_1 = require("./JsonRpcRequest");
7
+ const utils_2 = require("./utils");
8
+ /**
9
+ * Supported Ethereum methods.
10
+ */
11
+ var EthMethod;
12
+ (function (EthMethod) {
13
+ EthMethod["PersonalSign"] = "personal_sign";
14
+ EthMethod["Sign"] = "eth_sign";
15
+ EthMethod["SignTransaction"] = "eth_signTransaction";
16
+ EthMethod["SignTypedData"] = "eth_signTypedData";
17
+ EthMethod["SignTypedDataV1"] = "eth_signTypedData_v1";
18
+ EthMethod["SignTypedDataV3"] = "eth_signTypedData_v3";
19
+ EthMethod["SignTypedDataV4"] = "eth_signTypedData_v4";
20
+ })(EthMethod = exports.EthMethod || (exports.EthMethod = {}));
21
+ /**
22
+ * Supported Ethereum account types.
23
+ */
24
+ var EthAccountType;
25
+ (function (EthAccountType) {
26
+ EthAccountType["Eoa"] = "eip155:eoa";
27
+ EthAccountType["Eip4337"] = "eip155:eip4337";
28
+ })(EthAccountType = exports.EthAccountType || (exports.EthAccountType = {}));
29
+ exports.KeyringAccountStruct = (0, superstruct_1.object)({
30
+ /**
31
+ * Account ID (UUIDv4).
32
+ */
33
+ id: utils_2.UuidStruct,
34
+ /**
35
+ * Account address or next receive address (UTXO).
36
+ */
37
+ address: (0, superstruct_1.string)(),
38
+ /**
39
+ * Keyring-dependent account options.
40
+ */
41
+ options: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
42
+ /**
43
+ * Account supported methods.
44
+ */
45
+ methods: (0, superstruct_1.array)((0, superstruct_1.enums)([
46
+ `${EthMethod.PersonalSign}`,
47
+ `${EthMethod.Sign}`,
48
+ `${EthMethod.SignTransaction}`,
49
+ `${EthMethod.SignTypedData}`,
50
+ `${EthMethod.SignTypedDataV1}`,
51
+ `${EthMethod.SignTypedDataV3}`,
52
+ `${EthMethod.SignTypedDataV4}`,
53
+ ])),
54
+ /**
55
+ * Account type.
56
+ */
57
+ type: (0, superstruct_1.enums)([`${EthAccountType.Eoa}`, `${EthAccountType.Eip4337}`]),
58
+ });
59
+ exports.KeyringRequestStruct = (0, superstruct_1.object)({
60
+ /**
61
+ * Account ID (UUIDv4).
62
+ */
63
+ account: utils_2.UuidStruct,
64
+ /**
65
+ * Request's scope (CAIP-2 chain ID).
66
+ */
67
+ scope: (0, superstruct_1.string)(),
68
+ /**
69
+ * JSON-RPC request sent by the client application.
70
+ *
71
+ * Note: The request ID must be a string.
72
+ */
73
+ request: JsonRpcRequest_1.JsonRpcRequestStruct,
74
+ });
75
+ exports.KeyringAccountDataStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct);
76
+ exports.KeyringResponseStruct = (0, superstruct_1.union)([
77
+ (0, superstruct_1.object)({
78
+ /**
79
+ * Pending flag.
80
+ *
81
+ * Setting the pending flag to true indicates that the request will be
82
+ * handled asynchronously. The keyring must be called with `approveRequest`
83
+ * or `rejectRequest` to resolve the request.
84
+ */
85
+ pending: (0, superstruct_1.literal)(true),
86
+ /**
87
+ * Redirect URL.
88
+ *
89
+ * If present in the response, MetaMask will display a confirmation dialog
90
+ * with a link to the redirect URL. The user can choose to follow the link
91
+ * or cancel the request.
92
+ */
93
+ redirect: (0, superstruct_1.nullable)((0, superstruct_1.string)()),
94
+ }),
95
+ (0, superstruct_1.object)({
96
+ /**
97
+ * Pending flag.
98
+ *
99
+ * Setting the pending flag to false indicates that the request will be
100
+ * handled synchronously. The keyring must return the result of the
101
+ * request execution.
102
+ */
103
+ pending: (0, superstruct_1.literal)(false),
104
+ /**
105
+ * Request result.
106
+ */
107
+ result: utils_1.JsonStruct,
108
+ }),
109
+ ]);
110
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":";;;AAAA,2CAAwD;AACxD,6CAUqB;AAErB,qDAAwD;AACxD,mCAAqC;AAErC;;GAEG;AACH,IAAY,SAQX;AARD,WAAY,SAAS;IACnB,2CAA8B,CAAA;IAC9B,8BAAiB,CAAA;IACjB,oDAAuC,CAAA;IACvC,gDAAmC,CAAA;IACnC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;IACxC,qDAAwC,CAAA;AAC1C,CAAC,EARW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAQpB;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;IACH,OAAO,EAAE,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC;IAErC;;OAEG;IACH,OAAO,EAAE,IAAA,mBAAK,EACZ,IAAA,mBAAK,EAAC;QACJ,GAAG,SAAS,CAAC,YAAY,EAAE;QAC3B,GAAG,SAAS,CAAC,IAAI,EAAE;QACnB,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,aAAa,EAAE;QAC5B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;QAC9B,GAAG,SAAS,CAAC,eAAe,EAAE;KAC/B,CAAC,CACH;IAED;;OAEG;IACH,IAAI,EAAE,IAAA,mBAAK,EAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,EAAE,GAAG,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC;CACpE,CAAC,CAAC;AASU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EAAC;IACzC;;OAEG;IACH,OAAO,EAAE,kBAAU;IAEnB;;OAEG;IACH,KAAK,EAAE,IAAA,oBAAM,GAAE;IAEf;;;;OAIG;IACH,OAAO,EAAE,qCAAoB;CAC9B,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,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;KAC7B,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, JsonStruct } from '@metamask/utils';\nimport {\n type Infer,\n array,\n enums,\n literal,\n object,\n record,\n string,\n union,\n nullable,\n} from 'superstruct';\n\nimport { JsonRpcRequestStruct } from './JsonRpcRequest';\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 SignTypedData = 'eth_signTypedData',\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.SignTypedData}`,\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 * Account ID (UUIDv4).\n */\n account: UuidStruct,\n\n /**\n * Request's scope (CAIP-2 chain ID).\n */\n scope: string(),\n\n /**\n * JSON-RPC request sent by the client application.\n *\n * Note: The request ID must be a string.\n */\n request: JsonRpcRequestStruct,\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: nullable(string()),\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 to be shown\n * to the user. The user can choose to follow the link or cancel the request.\n * The main use case for this is to redirect the user to a third-party service\n * to approve 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,10 @@
1
+ /**
2
+ * Supported keyring events.
3
+ */
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"
10
+ }
package/dist/events.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringEvent = void 0;
4
+ /**
5
+ * Supported keyring events.
6
+ */
7
+ var KeyringEvent;
8
+ (function (KeyringEvent) {
9
+ // Account events
10
+ KeyringEvent["AccountCreated"] = "event:accountCreated";
11
+ KeyringEvent["AccountUpdated"] = "event:accountUpdated";
12
+ KeyringEvent["AccountDeleted"] = "event:accountDeleted";
13
+ // Request events
14
+ KeyringEvent["RequestApproved"] = "event:requestApproved";
15
+ KeyringEvent["RequestRejected"] = "event:requestRejected";
16
+ })(KeyringEvent = exports.KeyringEvent || (exports.KeyringEvent = {}));
17
+ //# sourceMappingURL=events.js.map
@@ -0,0 +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"]}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- export * from './keyring-api';
2
- export * from './keyring-client';
3
- export * from './keyring-rpc-dispatcher';
4
- export * from './keyring-snap-controller-client';
5
- export * from './keyring-snap-rpc-client';
1
+ export * from './api';
2
+ export * from './KeyringClient';
3
+ export * from './rpc-handler';
4
+ export * from './KeyringSnapControllerClient';
5
+ export * from './KeyringSnapRpcClient';
6
+ export * from './internal';
package/dist/index.js CHANGED
@@ -14,9 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./keyring-api"), exports);
18
- __exportStar(require("./keyring-client"), exports);
19
- __exportStar(require("./keyring-rpc-dispatcher"), exports);
20
- __exportStar(require("./keyring-snap-controller-client"), exports);
21
- __exportStar(require("./keyring-snap-rpc-client"), exports);
17
+ __exportStar(require("./api"), exports);
18
+ __exportStar(require("./KeyringClient"), exports);
19
+ __exportStar(require("./rpc-handler"), exports);
20
+ __exportStar(require("./KeyringSnapControllerClient"), exports);
21
+ __exportStar(require("./KeyringSnapRpcClient"), exports);
22
+ __exportStar(require("./internal"), exports);
22
23
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,mDAAiC;AACjC,2DAAyC;AACzC,mEAAiD;AACjD,4DAA0C","sourcesContent":["export * from './keyring-api';\nexport * from './keyring-client';\nexport * from './keyring-rpc-dispatcher';\nexport * from './keyring-snap-controller-client';\nexport * from './keyring-snap-rpc-client';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,kDAAgC;AAChC,gDAA8B;AAC9B,gEAA8C;AAC9C,yDAAuC;AACvC,6CAA2B","sourcesContent":["export * from './api';\nexport * from './KeyringClient';\nexport * from './rpc-handler';\nexport * from './KeyringSnapControllerClient';\nexport * from './KeyringSnapRpcClient';\nexport * from './internal';\n"]}