@metamask/keyring-api 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +28 -1
  2. package/README.md +7 -7
  3. package/dist/KeyringSnapControllerClient.d.ts +3 -2
  4. package/dist/KeyringSnapControllerClient.js.map +1 -1
  5. package/dist/api.d.ts +13 -7
  6. package/dist/api.js +10 -2
  7. package/dist/api.js.map +1 -1
  8. package/dist/eth/erc4337/index.d.ts +1 -0
  9. package/dist/eth/erc4337/index.js +18 -0
  10. package/dist/eth/erc4337/index.js.map +1 -0
  11. package/dist/eth/erc4337/types.d.ts +90 -0
  12. package/dist/eth/erc4337/types.js +58 -0
  13. package/dist/eth/erc4337/types.js.map +1 -0
  14. package/dist/eth/index.d.ts +2 -0
  15. package/dist/eth/index.js +19 -0
  16. package/dist/eth/index.js.map +1 -0
  17. package/dist/eth/types.d.ts +3 -0
  18. package/dist/eth/types.js +8 -0
  19. package/dist/eth/types.js.map +1 -0
  20. package/dist/index.d.ts +1 -0
  21. package/dist/index.js +1 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/internal/api.d.ts +38 -26
  24. package/dist/internal/eth/EthKeyring.d.ts +29 -0
  25. package/dist/internal/eth/EthKeyring.js +3 -0
  26. package/dist/internal/eth/EthKeyring.js.map +1 -0
  27. package/dist/internal/eth/index.d.ts +1 -0
  28. package/dist/internal/eth/index.js +18 -0
  29. package/dist/internal/eth/index.js.map +1 -0
  30. package/dist/internal/events.d.ts +30 -20
  31. package/dist/internal/index.d.ts +1 -0
  32. package/dist/internal/index.js +1 -0
  33. package/dist/internal/index.js.map +1 -1
  34. package/dist/internal/types.d.ts +8 -5
  35. package/dist/snap-utils.d.ts +2 -2
  36. package/dist/snap-utils.js.map +1 -1
  37. package/dist/superstruct.d.ts +14 -0
  38. package/dist/superstruct.js +18 -1
  39. package/dist/superstruct.js.map +1 -1
  40. package/dist/utils.js +2 -2
  41. package/dist/utils.js.map +1 -1
  42. package/package.json +5 -5
  43. package/dist/superstruct.test-d.d.ts +0 -1
  44. package/dist/superstruct.test-d.js +0 -17
  45. package/dist/superstruct.test-d.js.map +0 -1
@@ -10,32 +10,35 @@ export declare const ListAccountsRequestStruct: import("superstruct").Struct<{
10
10
  }>;
11
11
  export declare type ListAccountsRequest = Infer<typeof ListAccountsRequestStruct>;
12
12
  export declare const ListAccountsResponseStruct: import("superstruct").Struct<{
13
- type: "eip155:eoa" | "eip155:eip4337";
13
+ type: "eip155:eoa" | "eip155:erc4337";
14
14
  id: string;
15
15
  address: string;
16
16
  options: Record<string, import("@metamask/utils").Json>;
17
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
17
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
18
18
  }[], import("superstruct").Struct<{
19
- type: "eip155:eoa" | "eip155:eip4337";
19
+ type: "eip155:eoa" | "eip155:erc4337";
20
20
  id: string;
21
21
  address: string;
22
22
  options: Record<string, import("@metamask/utils").Json>;
23
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
23
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
24
24
  }, {
25
25
  id: import("superstruct").Struct<string, null>;
26
26
  address: import("superstruct").Struct<string, null>;
27
27
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
28
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
28
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
29
29
  personal_sign: "personal_sign";
30
30
  eth_sign: "eth_sign";
31
31
  eth_signTransaction: "eth_signTransaction";
32
32
  eth_signTypedData_v1: "eth_signTypedData_v1";
33
33
  eth_signTypedData_v3: "eth_signTypedData_v3";
34
34
  eth_signTypedData_v4: "eth_signTypedData_v4";
35
+ eth_prepareUserOperation: "eth_prepareUserOperation";
36
+ eth_patchUserOperation: "eth_patchUserOperation";
37
+ eth_signUserOperation: "eth_signUserOperation";
35
38
  }>>;
36
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
39
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
37
40
  "eip155:eoa": "eip155:eoa";
38
- "eip155:eip4337": "eip155:eip4337";
41
+ "eip155:erc4337": "eip155:erc4337";
39
42
  }>;
40
43
  }>>;
41
44
  export declare type ListAccountsResponse = Infer<typeof ListAccountsResponseStruct>;
@@ -58,26 +61,29 @@ export declare const GetAccountRequestStruct: import("superstruct").Struct<{
58
61
  }>;
59
62
  export declare type GetAccountRequest = Infer<typeof GetAccountRequestStruct>;
60
63
  export declare const GetAccountResponseStruct: import("superstruct").Struct<{
61
- type: "eip155:eoa" | "eip155:eip4337";
64
+ type: "eip155:eoa" | "eip155:erc4337";
62
65
  id: string;
63
66
  address: string;
64
67
  options: Record<string, import("@metamask/utils").Json>;
65
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
68
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
66
69
  }, {
67
70
  id: import("superstruct").Struct<string, null>;
68
71
  address: import("superstruct").Struct<string, null>;
69
72
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
70
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
73
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
71
74
  personal_sign: "personal_sign";
72
75
  eth_sign: "eth_sign";
73
76
  eth_signTransaction: "eth_signTransaction";
74
77
  eth_signTypedData_v1: "eth_signTypedData_v1";
75
78
  eth_signTypedData_v3: "eth_signTypedData_v3";
76
79
  eth_signTypedData_v4: "eth_signTypedData_v4";
80
+ eth_prepareUserOperation: "eth_prepareUserOperation";
81
+ eth_patchUserOperation: "eth_patchUserOperation";
82
+ eth_signUserOperation: "eth_signUserOperation";
77
83
  }>>;
78
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
84
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
79
85
  "eip155:eoa": "eip155:eoa";
80
- "eip155:eip4337": "eip155:eip4337";
86
+ "eip155:erc4337": "eip155:erc4337";
81
87
  }>;
82
88
  }>;
83
89
  export declare type GetAccountResponse = Infer<typeof GetAccountResponseStruct>;
@@ -100,26 +106,29 @@ export declare const CreateAccountRequestStruct: import("superstruct").Struct<{
100
106
  }>;
101
107
  export declare type CreateAccountRequest = Infer<typeof CreateAccountRequestStruct>;
102
108
  export declare const CreateAccountResponseStruct: import("superstruct").Struct<{
103
- type: "eip155:eoa" | "eip155:eip4337";
109
+ type: "eip155:eoa" | "eip155:erc4337";
104
110
  id: string;
105
111
  address: string;
106
112
  options: Record<string, import("@metamask/utils").Json>;
107
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
113
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
108
114
  }, {
109
115
  id: import("superstruct").Struct<string, null>;
110
116
  address: import("superstruct").Struct<string, null>;
111
117
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
112
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
118
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
113
119
  personal_sign: "personal_sign";
114
120
  eth_sign: "eth_sign";
115
121
  eth_signTransaction: "eth_signTransaction";
116
122
  eth_signTypedData_v1: "eth_signTypedData_v1";
117
123
  eth_signTypedData_v3: "eth_signTypedData_v3";
118
124
  eth_signTypedData_v4: "eth_signTypedData_v4";
125
+ eth_prepareUserOperation: "eth_prepareUserOperation";
126
+ eth_patchUserOperation: "eth_patchUserOperation";
127
+ eth_signUserOperation: "eth_signUserOperation";
119
128
  }>>;
120
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
129
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
121
130
  "eip155:eoa": "eip155:eoa";
122
- "eip155:eip4337": "eip155:eip4337";
131
+ "eip155:erc4337": "eip155:erc4337";
123
132
  }>;
124
133
  }>;
125
134
  export declare type CreateAccountResponse = Infer<typeof CreateAccountResponseStruct>;
@@ -152,45 +161,48 @@ export declare const UpdateAccountRequestStruct: import("superstruct").Struct<{
152
161
  method: "keyring_updateAccount";
153
162
  params: {
154
163
  account: {
155
- type: "eip155:eoa" | "eip155:eip4337";
164
+ type: "eip155:eoa" | "eip155:erc4337";
156
165
  id: string;
157
166
  address: string;
158
167
  options: Record<string, import("@metamask/utils").Json>;
159
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
168
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
160
169
  };
161
170
  };
162
171
  }, {
163
172
  method: import("superstruct").Struct<"keyring_updateAccount", "keyring_updateAccount">;
164
173
  params: import("superstruct").Struct<{
165
174
  account: {
166
- type: "eip155:eoa" | "eip155:eip4337";
175
+ type: "eip155:eoa" | "eip155:erc4337";
167
176
  id: string;
168
177
  address: string;
169
178
  options: Record<string, import("@metamask/utils").Json>;
170
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
179
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
171
180
  };
172
181
  }, {
173
182
  account: import("superstruct").Struct<{
174
- type: "eip155:eoa" | "eip155:eip4337";
183
+ type: "eip155:eoa" | "eip155:erc4337";
175
184
  id: string;
176
185
  address: string;
177
186
  options: Record<string, import("@metamask/utils").Json>;
178
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
187
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
179
188
  }, {
180
189
  id: import("superstruct").Struct<string, null>;
181
190
  address: import("superstruct").Struct<string, null>;
182
191
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
183
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
192
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
184
193
  personal_sign: "personal_sign";
185
194
  eth_sign: "eth_sign";
186
195
  eth_signTransaction: "eth_signTransaction";
187
196
  eth_signTypedData_v1: "eth_signTypedData_v1";
188
197
  eth_signTypedData_v3: "eth_signTypedData_v3";
189
198
  eth_signTypedData_v4: "eth_signTypedData_v4";
199
+ eth_prepareUserOperation: "eth_prepareUserOperation";
200
+ eth_patchUserOperation: "eth_patchUserOperation";
201
+ eth_signUserOperation: "eth_signUserOperation";
190
202
  }>>;
191
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
203
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
192
204
  "eip155:eoa": "eip155:eoa";
193
- "eip155:eip4337": "eip155:eip4337";
205
+ "eip155:erc4337": "eip155:erc4337";
194
206
  }>;
195
207
  }>;
196
208
  }>;
@@ -0,0 +1,29 @@
1
+ import type { Json, Keyring } from '@metamask/utils';
2
+ import type { EthBaseTransaction, EthBaseUserOperation, EthUserOperation, EthUserOperationPatch } from '../../eth';
3
+ export declare type EthKeyring<State extends Json> = Keyring<State> & {
4
+ /**
5
+ * Convert a base transaction to a base UserOperation.
6
+ *
7
+ * @param address - Address of the sender.
8
+ * @param transactions - Base transactions to include in the UserOperation.
9
+ * @returns A pseudo-UserOperation that can be used to construct a real.
10
+ */
11
+ prepareUserOperation?(address: string, transactions: EthBaseTransaction[]): Promise<EthBaseUserOperation>;
12
+ /**
13
+ * Patches properties of a UserOperation. Currently, only the
14
+ * `paymasterAndData` can be patched.
15
+ *
16
+ * @param address - Address of the sender.
17
+ * @param userOp - UserOperation to patch.
18
+ * @returns A patch to apply to the UserOperation.
19
+ */
20
+ patchUserOperation?(address: string, userOp: EthUserOperation): Promise<EthUserOperationPatch>;
21
+ /**
22
+ * Signs an UserOperation.
23
+ *
24
+ * @param address - Address of the sender.
25
+ * @param userOp - UserOperation to sign.
26
+ * @returns The signature of the UserOperation.
27
+ */
28
+ signUserOperation?(address: string, userOp: EthUserOperation): Promise<string>;
29
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=EthKeyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EthKeyring.js","sourceRoot":"","sources":["../../../src/internal/eth/EthKeyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Json, Keyring } from '@metamask/utils';\n\nimport type {\n EthBaseTransaction,\n EthBaseUserOperation,\n EthUserOperation,\n EthUserOperationPatch,\n} from '../../eth';\n\nexport type EthKeyring<State extends Json> = Keyring<State> & {\n /**\n * Convert a base transaction to a base UserOperation.\n *\n * @param address - Address of the sender.\n * @param transactions - Base transactions to include in the UserOperation.\n * @returns A pseudo-UserOperation that can be used to construct a real.\n */\n prepareUserOperation?(\n address: string,\n transactions: EthBaseTransaction[],\n ): Promise<EthBaseUserOperation>;\n\n /**\n * Patches properties of a UserOperation. Currently, only the\n * `paymasterAndData` can be patched.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to patch.\n * @returns A patch to apply to the UserOperation.\n */\n patchUserOperation?(\n address: string,\n userOp: EthUserOperation,\n ): Promise<EthUserOperationPatch>;\n\n /**\n * Signs an UserOperation.\n *\n * @param address - Address of the sender.\n * @param userOp - UserOperation to sign.\n * @returns The signature of the UserOperation.\n */\n signUserOperation?(\n address: string,\n userOp: EthUserOperation,\n ): Promise<string>;\n};\n"]}
@@ -0,0 +1 @@
1
+ export * from './EthKeyring';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./EthKeyring"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/internal/eth/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B","sourcesContent":["export * from './EthKeyring';\n"]}
@@ -2,48 +2,53 @@ export declare const AccountCreatedEventStruct: import("superstruct").Struct<{
2
2
  method: "notify:accountCreated";
3
3
  params: {
4
4
  account: {
5
- type: "eip155:eoa" | "eip155:eip4337";
5
+ type: "eip155:eoa" | "eip155:erc4337";
6
6
  id: string;
7
7
  address: string;
8
8
  options: Record<string, import("@metamask/utils").Json>;
9
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
9
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
10
10
  };
11
11
  };
12
12
  }, {
13
13
  method: import("superstruct").Struct<"notify:accountCreated", "notify:accountCreated">;
14
14
  params: import("superstruct").Struct<{
15
15
  account: {
16
- type: "eip155:eoa" | "eip155:eip4337";
16
+ type: "eip155:eoa" | "eip155:erc4337";
17
17
  id: string;
18
18
  address: string;
19
19
  options: Record<string, import("@metamask/utils").Json>;
20
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
20
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
21
21
  };
22
22
  }, {
23
23
  /**
24
24
  * New account object.
25
25
  */
26
26
  account: import("superstruct").Struct<{
27
- type: "eip155:eoa" | "eip155:eip4337";
27
+ type: "eip155:eoa" | "eip155:erc4337";
28
28
  id: string;
29
29
  address: string;
30
30
  options: Record<string, import("@metamask/utils").Json>;
31
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
31
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
32
32
  }, {
33
- id: import("superstruct").Struct<string, null>;
33
+ id: import("superstruct").Struct<string, null>; /**
34
+ * Request result.
35
+ */
34
36
  address: import("superstruct").Struct<string, null>;
35
37
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
36
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
38
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
37
39
  personal_sign: "personal_sign";
38
40
  eth_sign: "eth_sign";
39
41
  eth_signTransaction: "eth_signTransaction";
40
42
  eth_signTypedData_v1: "eth_signTypedData_v1";
41
43
  eth_signTypedData_v3: "eth_signTypedData_v3";
42
44
  eth_signTypedData_v4: "eth_signTypedData_v4";
45
+ eth_prepareUserOperation: "eth_prepareUserOperation";
46
+ eth_patchUserOperation: "eth_patchUserOperation";
47
+ eth_signUserOperation: "eth_signUserOperation";
43
48
  }>>;
44
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
49
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
45
50
  "eip155:eoa": "eip155:eoa";
46
- "eip155:eip4337": "eip155:eip4337";
51
+ "eip155:erc4337": "eip155:erc4337";
47
52
  }>;
48
53
  }>;
49
54
  }>;
@@ -52,48 +57,53 @@ export declare const AccountUpdatedEventStruct: import("superstruct").Struct<{
52
57
  method: "notify:accountUpdated";
53
58
  params: {
54
59
  account: {
55
- type: "eip155:eoa" | "eip155:eip4337";
60
+ type: "eip155:eoa" | "eip155:erc4337";
56
61
  id: string;
57
62
  address: string;
58
63
  options: Record<string, import("@metamask/utils").Json>;
59
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
64
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
60
65
  };
61
66
  };
62
67
  }, {
63
68
  method: import("superstruct").Struct<"notify:accountUpdated", "notify:accountUpdated">;
64
69
  params: import("superstruct").Struct<{
65
70
  account: {
66
- type: "eip155:eoa" | "eip155:eip4337";
71
+ type: "eip155:eoa" | "eip155:erc4337";
67
72
  id: string;
68
73
  address: string;
69
74
  options: Record<string, import("@metamask/utils").Json>;
70
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
75
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
71
76
  };
72
77
  }, {
73
78
  /**
74
79
  * Updated account object.
75
80
  */
76
81
  account: import("superstruct").Struct<{
77
- type: "eip155:eoa" | "eip155:eip4337";
82
+ type: "eip155:eoa" | "eip155:erc4337";
78
83
  id: string;
79
84
  address: string;
80
85
  options: Record<string, import("@metamask/utils").Json>;
81
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
86
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
82
87
  }, {
83
- id: import("superstruct").Struct<string, null>;
88
+ id: import("superstruct").Struct<string, null>; /**
89
+ * Request result.
90
+ */
84
91
  address: import("superstruct").Struct<string, null>;
85
92
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
86
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
93
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
87
94
  personal_sign: "personal_sign";
88
95
  eth_sign: "eth_sign";
89
96
  eth_signTransaction: "eth_signTransaction";
90
97
  eth_signTypedData_v1: "eth_signTypedData_v1";
91
98
  eth_signTypedData_v3: "eth_signTypedData_v3";
92
99
  eth_signTypedData_v4: "eth_signTypedData_v4";
100
+ eth_prepareUserOperation: "eth_prepareUserOperation";
101
+ eth_patchUserOperation: "eth_patchUserOperation";
102
+ eth_signUserOperation: "eth_signUserOperation";
93
103
  }>>;
94
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
104
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
95
105
  "eip155:eoa": "eip155:eoa";
96
- "eip155:eip4337": "eip155:eip4337";
106
+ "eip155:erc4337": "eip155:erc4337";
97
107
  }>;
98
108
  }>;
99
109
  }>;
@@ -1,4 +1,5 @@
1
1
  export * from './api';
2
+ export * from './eth';
2
3
  export * from './events';
3
4
  export * from './rpc';
4
5
  export * from './types';
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./api"), exports);
18
+ __exportStar(require("./eth"), exports);
18
19
  __exportStar(require("./events"), exports);
19
20
  __exportStar(require("./rpc"), exports);
20
21
  __exportStar(require("./types"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB;AACzB,wCAAsB;AACtB,0CAAwB","sourcesContent":["export * from './api';\nexport * from './events';\nexport * from './rpc';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/internal/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,wCAAsB;AACtB,2CAAyB;AACzB,wCAAsB;AACtB,0CAAwB","sourcesContent":["export * from './api';\nexport * from './eth';\nexport * from './events';\nexport * from './rpc';\nexport * from './types';\n"]}
@@ -1,10 +1,10 @@
1
1
  import type { Infer } from 'superstruct';
2
2
  export declare const InternalAccountStruct: import("superstruct").Struct<{
3
- type: "eip155:eoa" | "eip155:eip4337";
3
+ type: "eip155:eoa" | "eip155:erc4337";
4
4
  id: string;
5
5
  address: string;
6
6
  options: Record<string, import("@metamask/utils").Json>;
7
- methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[];
7
+ methods: ("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[];
8
8
  metadata: {
9
9
  name: string;
10
10
  keyring: {
@@ -50,17 +50,20 @@ export declare const InternalAccountStruct: import("superstruct").Struct<{
50
50
  id: import("superstruct").Struct<string, null>;
51
51
  address: import("superstruct").Struct<string, null>;
52
52
  options: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
53
- methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4", {
53
+ methods: import("superstruct").Struct<("personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation")[], import("superstruct").Struct<"personal_sign" | "eth_sign" | "eth_signTransaction" | "eth_signTypedData_v1" | "eth_signTypedData_v3" | "eth_signTypedData_v4" | "eth_prepareUserOperation" | "eth_patchUserOperation" | "eth_signUserOperation", {
54
54
  personal_sign: "personal_sign";
55
55
  eth_sign: "eth_sign";
56
56
  eth_signTransaction: "eth_signTransaction";
57
57
  eth_signTypedData_v1: "eth_signTypedData_v1";
58
58
  eth_signTypedData_v3: "eth_signTypedData_v3";
59
59
  eth_signTypedData_v4: "eth_signTypedData_v4";
60
+ eth_prepareUserOperation: "eth_prepareUserOperation";
61
+ eth_patchUserOperation: "eth_patchUserOperation";
62
+ eth_signUserOperation: "eth_signUserOperation";
60
63
  }>>;
61
- type: import("superstruct").Struct<"eip155:eoa" | "eip155:eip4337", {
64
+ type: import("superstruct").Struct<"eip155:eoa" | "eip155:erc4337", {
62
65
  "eip155:eoa": "eip155:eoa";
63
- "eip155:eip4337": "eip155:eip4337";
66
+ "eip155:erc4337": "eip155:erc4337";
64
67
  }>;
65
68
  }>;
66
69
  /**
@@ -1,4 +1,4 @@
1
- import type { SnapsGlobalObject } from '@metamask/snaps-rpc-methods';
1
+ import type { SnapsProvider } from '@metamask/snaps-sdk';
2
2
  import type { Json } from '@metamask/utils';
3
3
  import type { KeyringEvent } from './events';
4
4
  /**
@@ -8,4 +8,4 @@ import type { KeyringEvent } from './events';
8
8
  * @param event - The event name.
9
9
  * @param data - The event data.
10
10
  */
11
- export declare function emitSnapKeyringEvent(snap: SnapsGlobalObject, event: KeyringEvent, data: Record<string, Json>): Promise<void>;
11
+ export declare function emitSnapKeyringEvent(snap: SnapsProvider, event: KeyringEvent, data: Record<string, Json>): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"snap-utils.js","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,IAAuB,EACvB,KAAmB,EACnB,IAA0B;IAE1B,MAAM,IAAI,CAAC,OAAO,CAAC;QACjB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE;SACpB;KACF,CAAC,CAAC;AACL,CAAC;AAZD,oDAYC","sourcesContent":["import type { SnapsGlobalObject } from '@metamask/snaps-rpc-methods';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringEvent } from './events';\n\n/**\n * Emit a keyring event from a snap.\n *\n * @param snap - The global snap object.\n * @param event - The event name.\n * @param data - The event data.\n */\nexport async function emitSnapKeyringEvent(\n snap: SnapsGlobalObject,\n event: KeyringEvent,\n data: Record<string, Json>,\n): Promise<void> {\n await snap.request({\n method: 'snap_manageAccounts',\n params: {\n method: event,\n params: { ...data },\n },\n });\n}\n"]}
1
+ {"version":3,"file":"snap-utils.js","sourceRoot":"","sources":["../src/snap-utils.ts"],"names":[],"mappings":";;;AAKA;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,IAAmB,EACnB,KAAmB,EACnB,IAA0B;IAE1B,MAAM,IAAI,CAAC,OAAO,CAAC;QACjB,MAAM,EAAE,qBAAqB;QAC7B,MAAM,EAAE;YACN,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAE,GAAG,IAAI,EAAE;SACpB;KACF,CAAC,CAAC;AACL,CAAC;AAZD,oDAYC","sourcesContent":["import type { SnapsProvider } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\n\nimport type { KeyringEvent } from './events';\n\n/**\n * Emit a keyring event from a snap.\n *\n * @param snap - The global snap object.\n * @param event - The event name.\n * @param data - The event data.\n */\nexport async function emitSnapKeyringEvent(\n snap: SnapsProvider,\n event: KeyringEvent,\n data: Record<string, Json>,\n): Promise<void> {\n await snap.request({\n method: 'snap_manageAccounts',\n params: {\n method: event,\n params: { ...data },\n },\n });\n}\n"]}
@@ -55,4 +55,18 @@ export declare function object<Schema extends ObjectSchema>(schema: Schema): Str
55
55
  * @returns The augmented struct.
56
56
  */
57
57
  export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
58
+ /**
59
+ * Defines a new string-struct matching a regular expression.
60
+ *
61
+ * Example:
62
+ *
63
+ * ```ts
64
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
65
+ * ```
66
+ *
67
+ * @param name - Type name.
68
+ * @param pattern - Regular expression to match.
69
+ * @returns A new string-struct that matches the given pattern.
70
+ */
71
+ export declare function definePattern(name: string, pattern: RegExp): Struct<string, null>;
58
72
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.exactOptional = exports.object = void 0;
3
+ exports.definePattern = exports.exactOptional = exports.object = void 0;
4
4
  const superstruct_1 = require("superstruct");
5
5
  /**
6
6
  * Change the return type of a superstruct object struct to support exact
@@ -45,4 +45,21 @@ function exactOptional(struct) {
45
45
  });
46
46
  }
47
47
  exports.exactOptional = exactOptional;
48
+ /**
49
+ * Defines a new string-struct matching a regular expression.
50
+ *
51
+ * Example:
52
+ *
53
+ * ```ts
54
+ * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
55
+ * ```
56
+ *
57
+ * @param name - Type name.
58
+ * @param pattern - Regular expression to match.
59
+ * @returns A new string-struct that matches the given pattern.
60
+ */
61
+ function definePattern(name, pattern) {
62
+ return (0, superstruct_1.define)(name, (value) => typeof value === 'string' && pattern.test(value));
63
+ }
64
+ exports.definePattern = definePattern;
48
65
  //# sourceMappingURL=superstruct.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,6CAAyD;AAkDzD;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC","sourcesContent":["import type { Infer, Context } from 'superstruct';\nimport { Struct, object as stObject } from 'superstruct';\nimport type {\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from 'superstruct/dist/utils';\n\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n"]}
1
+ {"version":3,"file":"superstruct.js","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;;AACA,6CAAiE;AAkDjE;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAJD,wBAIC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,oBAAM,CAAC;QAChB,GAAG,MAAM;QAET,SAAS,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACxB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC;QAEnD,OAAO,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CACtB,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAa,EAAE,GAAG,CAAC;KAC1D,CAAC,CAAC;AACL,CAAC;AAZD,sCAYC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,aAAa,CAC3B,IAAY,EACZ,OAAe;IAEf,OAAO,IAAA,oBAAM,EACX,IAAI,EACJ,CAAC,KAAc,EAAW,EAAE,CAC1B,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CACnD,CAAC;AACJ,CAAC;AATD,sCASC","sourcesContent":["import type { Infer, Context } from 'superstruct';\nimport { Struct, define, object as stObject } from 'superstruct';\nimport type {\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n} from 'superstruct/dist/utils';\n\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Defines a new string-struct matching a regular expression.\n *\n * Example:\n *\n * ```ts\n * const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);\n * ```\n *\n * @param name - Type name.\n * @param pattern - Regular expression to match.\n * @returns A new string-struct that matches the given pattern.\n */\nexport function definePattern(\n name: string,\n pattern: RegExp,\n): Struct<string, null> {\n return define<string>(\n name,\n (value: unknown): boolean =>\n typeof value === 'string' && pattern.test(value),\n );\n}\n"]}
package/dist/utils.js CHANGED
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.strictMask = exports.UuidStruct = void 0;
4
4
  const superstruct_1 = require("superstruct");
5
- const UUID_V4_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
5
+ const superstruct_2 = require("./superstruct");
6
6
  /**
7
7
  * UUIDv4 struct.
8
8
  */
9
- exports.UuidStruct = (0, superstruct_1.define)('UuidV4', (id) => typeof id === 'string' && UUID_V4_REGEX.test(id));
9
+ exports.UuidStruct = (0, superstruct_2.definePattern)('UuidV4', /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu);
10
10
  /**
11
11
  * Assert that a value is valid according to a struct.
12
12
  *
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAG7C,MAAM,aAAa,GACjB,yEAAyE,CAAC;AAE5E;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,oBAAM,EAC9B,QAAQ,EACR,CAAC,EAAW,EAAW,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC,CAC3E,CAAC;AAcF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import { assert, define } from 'superstruct';\nimport type { Struct } from 'superstruct';\n\nconst UUID_V4_REGEX =\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = define<string>(\n 'UuidV4',\n (id: unknown): boolean => typeof id === 'string' && UUID_V4_REGEX.test(id),\n);\n\n/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,6CAAqC;AAGrC,+CAA8C;AAE9C;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,2BAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AAcF;;;;;;;;;;GAUG;AACH,SAAgB,UAAU,CACxB,KAAc,EACd,MAA4B,EAC5B,OAAgB;IAEhB,IAAA,oBAAM,EAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,KAAK,CAAC;AACf,CAAC;AAPD,gCAOC","sourcesContent":["import { assert } from 'superstruct';\nimport type { Struct } from 'superstruct';\n\nimport { definePattern } from './superstruct';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n\n/**\n * Omit keys from a union type.\n *\n * The normal `Omit` type does not distribute over unions. So we use this\n * workaround that applies `Omit` to each member of the union.\n *\n * See: <https://github.com/microsoft/TypeScript/issues/31501#issuecomment-1280579305>\n */\nexport type OmitUnion<Type, Key extends keyof any> = Type extends any\n ? Omit<Type, Key>\n : never;\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/keyring-api",
3
- "version": "1.1.0",
3
+ "version": "2.0.0",
4
4
  "description": "MetaMask Keyring API",
5
5
  "keywords": [
6
6
  "metamask",
@@ -38,10 +38,10 @@
38
38
  "test:watch": "jest --watch"
39
39
  },
40
40
  "dependencies": {
41
- "@metamask/providers": "^13.0.0",
42
- "@metamask/snaps-controllers": "^3.1.0",
43
- "@metamask/snaps-rpc-methods": "^3.1.0",
44
- "@metamask/snaps-utils": "^3.0.0",
41
+ "@metamask/providers": "^14.0.1",
42
+ "@metamask/snaps-controllers": "^3.4.1",
43
+ "@metamask/snaps-sdk": "^1.2.0",
44
+ "@metamask/snaps-utils": "^5.0.0",
45
45
  "@metamask/utils": "^8.1.0",
46
46
  "@types/uuid": "^9.0.1",
47
47
  "superstruct": "^1.0.3",
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const superstruct_1 = require("superstruct");
4
- const tsd_1 = require("tsd");
5
- const _1 = require(".");
6
- const exactOptionalObject = (0, _1.object)({
7
- a: (0, superstruct_1.number)(),
8
- b: (0, superstruct_1.optional)((0, superstruct_1.string)()),
9
- c: (0, _1.exactOptional)((0, superstruct_1.boolean)()),
10
- });
11
- (0, tsd_1.expectAssignable)({ a: 0 });
12
- (0, tsd_1.expectAssignable)({ a: 0, b: 'test' });
13
- (0, tsd_1.expectAssignable)({ a: 0, b: 'test', c: true });
14
- (0, tsd_1.expectAssignable)({ a: 0, b: undefined });
15
- (0, tsd_1.expectNotAssignable)({ a: 0, b: 'test', c: 0 });
16
- (0, tsd_1.expectNotAssignable)({ a: 0, b: 'test', c: undefined });
17
- //# sourceMappingURL=superstruct.test-d.js.map