@metamask/snaps-jest 8.1.3 → 8.3.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.
- package/CHANGELOG.md +19 -1
- package/README.md +2 -2
- package/dist/chunk-24CGIQLL.mjs +30 -0
- package/dist/chunk-24CGIQLL.mjs.map +1 -0
- package/dist/{chunk-T2PHS5FY.js → chunk-2RJYSYUB.js} +2 -2
- package/dist/chunk-2RJYSYUB.js.map +1 -0
- package/dist/{chunk-KNJNL723.mjs → chunk-3J2IBWXV.mjs} +2 -2
- package/dist/{chunk-EDFQDZNY.js → chunk-3NP6BDGK.js} +50 -17
- package/dist/chunk-3NP6BDGK.js.map +1 -0
- package/dist/{chunk-AFA4KKWW.mjs → chunk-6JPBXAHM.mjs} +250 -47
- package/dist/chunk-6JPBXAHM.mjs.map +1 -0
- package/dist/{chunk-VXPCUDBI.js → chunk-6V6MFT67.js} +8 -6
- package/dist/chunk-6V6MFT67.js.map +1 -0
- package/dist/{chunk-6V5GEUDO.mjs → chunk-7PCHIR6O.mjs} +7 -37
- package/dist/chunk-7PCHIR6O.mjs.map +1 -0
- package/dist/{chunk-2OHD2VKS.js → chunk-AMAL4SJH.js} +11 -37
- package/dist/chunk-AMAL4SJH.js.map +1 -0
- package/dist/{chunk-HOI6FPLR.mjs → chunk-C26TYXXD.mjs} +9 -9
- package/dist/chunk-C26TYXXD.mjs.map +1 -0
- package/dist/{chunk-K55LIE3W.mjs → chunk-CACRY3TX.mjs} +3 -3
- package/dist/{chunk-PZDTZGSI.js → chunk-D653LBAY.js} +1 -1
- package/dist/chunk-D653LBAY.js.map +1 -0
- package/dist/chunk-DUVKGPX5.js +509 -0
- package/dist/chunk-DUVKGPX5.js.map +1 -0
- package/dist/{chunk-IH7UNS5A.mjs → chunk-G333FBBL.mjs} +6 -4
- package/dist/chunk-G333FBBL.mjs.map +1 -0
- package/dist/{chunk-YNUVT3HC.js → chunk-GLPGOEVE.js} +4 -4
- package/dist/chunk-GLPGOEVE.js.map +1 -0
- package/dist/chunk-IWJ4HKDR.mjs +50 -0
- package/dist/chunk-IWJ4HKDR.mjs.map +1 -0
- package/dist/{chunk-WMLSD6B5.js → chunk-K7MK6LQU.js} +3 -3
- package/dist/{chunk-B73P64TE.mjs → chunk-KOPPL55J.mjs} +2 -2
- package/dist/chunk-KOPPL55J.mjs.map +1 -0
- package/dist/{chunk-XKJHFUHE.js → chunk-KPRLFCKD.js} +4 -2
- package/dist/chunk-KPRLFCKD.js.map +1 -0
- package/dist/{chunk-3FDEYMQU.js → chunk-LPMHPAZK.js} +54 -14
- package/dist/chunk-LPMHPAZK.js.map +1 -0
- package/dist/{chunk-GG2BCPQH.mjs → chunk-LSKT2AUS.mjs} +5 -3
- package/dist/chunk-LSKT2AUS.mjs.map +1 -0
- package/dist/{chunk-6KXCBUNZ.mjs → chunk-LVNNGMJ2.mjs} +3 -1
- package/dist/{chunk-6KXCBUNZ.mjs.map → chunk-LVNNGMJ2.mjs.map} +1 -1
- package/dist/{chunk-TMAWGVZP.mjs → chunk-OHRFO2BL.mjs} +7 -7
- package/dist/chunk-OHRFO2BL.mjs.map +1 -0
- package/dist/{chunk-JXAJWUVZ.js → chunk-OO6IVUCV.js} +5 -5
- package/dist/{chunk-3M4GRUMH.mjs → chunk-ORR7AE5X.mjs} +2 -2
- package/dist/{chunk-UPR3PTSA.mjs → chunk-PDOVVC74.mjs} +10 -36
- package/dist/chunk-PDOVVC74.mjs.map +1 -0
- package/dist/{chunk-E2BYTLOT.mjs → chunk-Q3I6P2ZF.mjs} +43 -10
- package/dist/chunk-Q3I6P2ZF.mjs.map +1 -0
- package/dist/chunk-QRVFWATH.mjs +14 -0
- package/dist/chunk-QRVFWATH.mjs.map +1 -0
- package/dist/{chunk-MBQHVBLA.js → chunk-QYHQ2WWX.js} +5 -5
- package/dist/chunk-QYHQ2WWX.js.map +1 -0
- package/dist/{chunk-XWGECIXI.js → chunk-RJNNNCZJ.js} +3 -3
- package/dist/{chunk-U3DVRTS2.mjs → chunk-ROCGQYSK.mjs} +46 -6
- package/dist/chunk-ROCGQYSK.mjs.map +1 -0
- package/dist/chunk-SNXRXX2O.js +30 -0
- package/dist/chunk-SNXRXX2O.js.map +1 -0
- package/dist/chunk-SW65QYFV.js +50 -0
- package/dist/chunk-SW65QYFV.js.map +1 -0
- package/dist/{chunk-44ARQBXS.js → chunk-WZ57PU2K.js} +6 -4
- package/dist/chunk-WZ57PU2K.js.map +1 -0
- package/dist/chunk-XP4YGQJA.js +14 -0
- package/dist/chunk-XP4YGQJA.js.map +1 -0
- package/dist/{chunk-KQBJQLZG.js → chunk-Y2U3ZPCK.js} +15 -45
- package/dist/chunk-Y2U3ZPCK.js.map +1 -0
- package/dist/{chunk-74TIKA2T.mjs → chunk-ZJQSGRNK.mjs} +1 -1
- package/dist/chunk-ZJQSGRNK.mjs.map +1 -0
- package/dist/environment.js +17 -17
- package/dist/environment.mjs +16 -16
- package/dist/helpers.js +30 -16
- package/dist/helpers.mjs +29 -15
- package/dist/index.js +32 -18
- package/dist/index.mjs +31 -17
- package/dist/internals/index.js +33 -21
- package/dist/internals/index.mjs +35 -23
- package/dist/internals/request.js +15 -15
- package/dist/internals/request.mjs +14 -14
- package/dist/internals/simulation/constants.js +4 -2
- package/dist/internals/simulation/constants.mjs +3 -1
- package/dist/internals/simulation/controllers.js +7 -7
- package/dist/internals/simulation/controllers.mjs +6 -6
- package/dist/internals/simulation/files.js +8 -2
- package/dist/internals/simulation/files.mjs +7 -1
- package/dist/internals/simulation/index.js +31 -19
- package/dist/internals/simulation/index.mjs +33 -21
- package/dist/internals/simulation/interface.js +15 -4
- package/dist/internals/simulation/interface.mjs +16 -5
- package/dist/internals/simulation/methods/hooks/get-preferences.js +8 -0
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs +8 -0
- package/dist/internals/simulation/methods/hooks/index.js +5 -5
- package/dist/internals/simulation/methods/hooks/index.mjs +8 -8
- package/dist/internals/simulation/methods/hooks/notifications.js +2 -2
- package/dist/internals/simulation/methods/hooks/notifications.mjs +2 -2
- package/dist/internals/simulation/methods/hooks/request-user-approval.js +14 -0
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +14 -0
- package/dist/internals/simulation/methods/hooks/state.js +2 -2
- package/dist/internals/simulation/methods/hooks/state.mjs +2 -2
- package/dist/internals/simulation/methods/index.js +6 -6
- package/dist/internals/simulation/methods/index.mjs +5 -5
- package/dist/internals/simulation/methods/specifications.js +6 -6
- package/dist/internals/simulation/methods/specifications.mjs +5 -5
- package/dist/internals/simulation/middleware/engine.js +3 -3
- package/dist/internals/simulation/middleware/engine.mjs +2 -2
- package/dist/internals/simulation/middleware/index.js +3 -3
- package/dist/internals/simulation/middleware/index.mjs +2 -2
- package/dist/internals/simulation/options.js +3 -3
- package/dist/internals/simulation/options.mjs +2 -2
- package/dist/internals/simulation/simulation.js +13 -12
- package/dist/internals/simulation/simulation.mjs +12 -11
- package/dist/internals/simulation/store/index.js +3 -3
- package/dist/internals/simulation/store/index.mjs +2 -2
- package/dist/internals/simulation/store/store.js +3 -3
- package/dist/internals/simulation/store/store.mjs +2 -2
- package/dist/internals/simulation/store/ui.js +2 -2
- package/dist/internals/simulation/store/ui.mjs +1 -1
- package/dist/internals/structs.js +2 -2
- package/dist/internals/structs.mjs +1 -1
- package/dist/matchers.js +16 -18
- package/dist/matchers.mjs +15 -17
- package/dist/options.js +2 -2
- package/dist/options.mjs +1 -1
- package/dist/setup.js +15 -15
- package/dist/setup.mjs +15 -15
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/helpers.d.ts +43 -1
- package/dist/types/internals/request.d.ts +3 -2
- package/dist/types/internals/server.d.ts +1 -1
- package/dist/types/internals/simulation/constants.d.ts +4 -0
- package/dist/types/internals/simulation/controllers.d.ts +4 -4
- package/dist/types/internals/simulation/files.d.ts +36 -0
- package/dist/types/internals/simulation/interface.d.ts +70 -8
- package/dist/types/internals/simulation/methods/hooks/get-preferences.d.ts +13 -0
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +2 -2
- package/dist/types/internals/simulation/methods/hooks/request-user-approval.d.ts +15 -0
- package/dist/types/internals/simulation/methods/specifications.d.ts +2 -2
- package/dist/types/internals/simulation/middleware/engine.d.ts +1 -1
- package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +1 -1
- package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +1 -1
- package/dist/types/internals/simulation/options.d.ts +10 -8
- package/dist/types/internals/simulation/simulation.d.ts +8 -5
- package/dist/types/internals/simulation/store/mocks.d.ts +2 -2
- package/dist/types/internals/simulation/store/notifications.d.ts +2 -2
- package/dist/types/internals/simulation/store/state.d.ts +1 -1
- package/dist/types/internals/simulation/store/store.d.ts +4 -4
- package/dist/types/internals/simulation/store/ui.d.ts +4 -3
- package/dist/types/internals/structs.d.ts +41 -41
- package/dist/types/matchers.d.ts +0 -10
- package/dist/types/options.d.ts +7 -7
- package/dist/types/types.d.ts +91 -20
- package/package.json +18 -16
- package/dist/chunk-265BMFM5.js +0 -13
- package/dist/chunk-265BMFM5.js.map +0 -1
- package/dist/chunk-2OHD2VKS.js.map +0 -1
- package/dist/chunk-3FDEYMQU.js.map +0 -1
- package/dist/chunk-44ARQBXS.js.map +0 -1
- package/dist/chunk-6V5GEUDO.mjs.map +0 -1
- package/dist/chunk-74TIKA2T.mjs.map +0 -1
- package/dist/chunk-AFA4KKWW.mjs.map +0 -1
- package/dist/chunk-B73P64TE.mjs.map +0 -1
- package/dist/chunk-E2BYTLOT.mjs.map +0 -1
- package/dist/chunk-EDFQDZNY.js.map +0 -1
- package/dist/chunk-GG2BCPQH.mjs.map +0 -1
- package/dist/chunk-HOI6FPLR.mjs.map +0 -1
- package/dist/chunk-IH7UNS5A.mjs.map +0 -1
- package/dist/chunk-KQBJQLZG.js.map +0 -1
- package/dist/chunk-KSIBNOB2.mjs +0 -13
- package/dist/chunk-KSIBNOB2.mjs.map +0 -1
- package/dist/chunk-MBQHVBLA.js.map +0 -1
- package/dist/chunk-ORO3T6BU.mjs +0 -24
- package/dist/chunk-ORO3T6BU.mjs.map +0 -1
- package/dist/chunk-PZDTZGSI.js.map +0 -1
- package/dist/chunk-R55KAAM4.js +0 -306
- package/dist/chunk-R55KAAM4.js.map +0 -1
- package/dist/chunk-RAMAN5RM.js +0 -24
- package/dist/chunk-RAMAN5RM.js.map +0 -1
- package/dist/chunk-T2PHS5FY.js.map +0 -1
- package/dist/chunk-TBDYQSRT.mjs +0 -16
- package/dist/chunk-TBDYQSRT.mjs.map +0 -1
- package/dist/chunk-TMAWGVZP.mjs.map +0 -1
- package/dist/chunk-TVD4SWH7.js +0 -16
- package/dist/chunk-TVD4SWH7.js.map +0 -1
- package/dist/chunk-U3DVRTS2.mjs.map +0 -1
- package/dist/chunk-UPR3PTSA.mjs.map +0 -1
- package/dist/chunk-VXPCUDBI.js.map +0 -1
- package/dist/chunk-XKJHFUHE.js.map +0 -1
- package/dist/chunk-YNUVT3HC.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-locale.js +0 -8
- package/dist/internals/simulation/methods/hooks/get-locale.mjs +0 -8
- package/dist/internals/simulation/methods/hooks/show-dialog.js +0 -14
- package/dist/internals/simulation/methods/hooks/show-dialog.mjs +0 -14
- package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +0 -9
- package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +0 -9
- /package/dist/{chunk-KNJNL723.mjs.map → chunk-3J2IBWXV.mjs.map} +0 -0
- /package/dist/{chunk-K55LIE3W.mjs.map → chunk-CACRY3TX.mjs.map} +0 -0
- /package/dist/{chunk-WMLSD6B5.js.map → chunk-K7MK6LQU.js.map} +0 -0
- /package/dist/{chunk-JXAJWUVZ.js.map → chunk-OO6IVUCV.js.map} +0 -0
- /package/dist/{chunk-3M4GRUMH.mjs.map → chunk-ORR7AE5X.mjs.map} +0 -0
- /package/dist/{chunk-XWGECIXI.js.map → chunk-RJNNNCZJ.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{get-locale.js.map → get-preferences.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{get-locale.mjs.map → get-preferences.mjs.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{show-dialog.js.map → request-user-approval.js.map} +0 -0
- /package/dist/internals/simulation/methods/hooks/{show-dialog.mjs.map → request-user-approval.mjs.map} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const TransactionOptionsStruct: import("superstruct").Struct<{
|
|
1
|
+
export declare const TransactionOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
2
2
|
value: `0x${string}`;
|
|
3
3
|
data: `0x${string}`;
|
|
4
4
|
from: `0x${string}`;
|
|
@@ -13,55 +13,55 @@ export declare const TransactionOptionsStruct: import("superstruct").Struct<{
|
|
|
13
13
|
/**
|
|
14
14
|
* The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.
|
|
15
15
|
*/
|
|
16
|
-
chainId: import("superstruct").Struct<string, null>;
|
|
16
|
+
chainId: import("@metamask/superstruct").Struct<string, null>;
|
|
17
17
|
/**
|
|
18
18
|
* The origin to send the transaction from. Defaults to `metamask.io`.
|
|
19
19
|
*/
|
|
20
|
-
origin: import("superstruct").Struct<string, null>;
|
|
20
|
+
origin: import("@metamask/superstruct").Struct<string, null>;
|
|
21
21
|
/**
|
|
22
22
|
* The address to send the transaction from. Defaults to a randomly generated
|
|
23
23
|
* address.
|
|
24
24
|
*/
|
|
25
|
-
from: import("superstruct").Struct<`0x${string}`, null>;
|
|
25
|
+
from: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
26
26
|
/**
|
|
27
27
|
* The address to send the transaction to. Defaults to a randomly generated
|
|
28
28
|
* address.
|
|
29
29
|
*/
|
|
30
|
-
to: import("superstruct").Struct<`0x${string}`, null>;
|
|
30
|
+
to: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
31
31
|
/**
|
|
32
32
|
* The value to send with the transaction. The value may be specified as a
|
|
33
33
|
* `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.
|
|
34
34
|
*/
|
|
35
|
-
value: import("superstruct").Struct<`0x${string}`, null>;
|
|
35
|
+
value: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
36
36
|
/**
|
|
37
37
|
* The gas limit to use for the transaction. The gas limit may be specified
|
|
38
38
|
* as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.
|
|
39
39
|
*/
|
|
40
|
-
gasLimit: import("superstruct").Struct<`0x${string}`, null>;
|
|
40
|
+
gasLimit: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
41
41
|
/**
|
|
42
42
|
* The max fee per gas (in Wei) to use for the transaction. The max fee per
|
|
43
43
|
* gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.
|
|
44
44
|
* Defaults to `1`.
|
|
45
45
|
*/
|
|
46
|
-
maxFeePerGas: import("superstruct").Struct<`0x${string}`, null>;
|
|
46
|
+
maxFeePerGas: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
47
47
|
/**
|
|
48
48
|
* The max priority fee per gas (in Wei) to use for the transaction. The max
|
|
49
49
|
* priority fee per gas may be specified as a `number`, `bigint`, `string`,
|
|
50
50
|
* or `Uint8Array`. Defaults to `1`.
|
|
51
51
|
*/
|
|
52
|
-
maxPriorityFeePerGas: import("superstruct").Struct<`0x${string}`, null>;
|
|
52
|
+
maxPriorityFeePerGas: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
53
53
|
/**
|
|
54
54
|
* The nonce to use for the transaction. The nonce may be specified as a
|
|
55
55
|
* `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.
|
|
56
56
|
*/
|
|
57
|
-
nonce: import("superstruct").Struct<`0x${string}`, null>;
|
|
57
|
+
nonce: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
58
58
|
/**
|
|
59
59
|
* The data to send with the transaction. The data may be specified as a
|
|
60
60
|
* `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.
|
|
61
61
|
*/
|
|
62
|
-
data: import("superstruct").Struct<`0x${string}`, null>;
|
|
62
|
+
data: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
63
63
|
}>;
|
|
64
|
-
export declare const SignatureOptionsStruct: import("superstruct").Struct<{
|
|
64
|
+
export declare const SignatureOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
65
65
|
data: `0x${string}` | Record<string, any> | Record<string, any>[];
|
|
66
66
|
from: `0x${string}`;
|
|
67
67
|
origin: string;
|
|
@@ -70,45 +70,45 @@ export declare const SignatureOptionsStruct: import("superstruct").Struct<{
|
|
|
70
70
|
/**
|
|
71
71
|
* The origin making the signature request.
|
|
72
72
|
*/
|
|
73
|
-
origin: import("superstruct").Struct<string, null>;
|
|
73
|
+
origin: import("@metamask/superstruct").Struct<string, null>;
|
|
74
74
|
/**
|
|
75
75
|
* The address signing the signature request. Defaults to a randomly generated
|
|
76
76
|
* address.
|
|
77
77
|
*/
|
|
78
|
-
from: import("superstruct").Struct<`0x${string}`, null>;
|
|
78
|
+
from: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
79
79
|
/**
|
|
80
80
|
* The data to send with the transaction. The data may be specified as a
|
|
81
81
|
* `string`, an object, or an array of objects. This covers the data types
|
|
82
82
|
* for the supported signature methods. Defaults to `0x`.
|
|
83
83
|
*/
|
|
84
|
-
data: import("superstruct").Struct<`0x${string}` | Record<string, any> | Record<string, any>[], null>;
|
|
84
|
+
data: import("@metamask/superstruct").Struct<`0x${string}` | Record<string, any> | Record<string, any>[], null>;
|
|
85
85
|
/**
|
|
86
86
|
* The signature method being used.
|
|
87
87
|
*/
|
|
88
|
-
signatureMethod: import("superstruct").Struct<"eth_sign" | "personal_sign" | "eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4", null>;
|
|
88
|
+
signatureMethod: import("@metamask/superstruct").Struct<"eth_sign" | "personal_sign" | "eth_signTypedData" | "eth_signTypedData_v3" | "eth_signTypedData_v4", null>;
|
|
89
89
|
}>;
|
|
90
|
-
export declare const SnapOptionsStruct: import("superstruct").Struct<{
|
|
90
|
+
export declare const SnapOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
91
91
|
timeout?: number | undefined;
|
|
92
92
|
}, {
|
|
93
93
|
/**
|
|
94
94
|
* The timeout in milliseconds to use for requests to the snap. Defaults to
|
|
95
95
|
* `1000`.
|
|
96
96
|
*/
|
|
97
|
-
timeout: import("superstruct").Struct<number | undefined, null>;
|
|
97
|
+
timeout: import("@metamask/superstruct").Struct<number | undefined, null>;
|
|
98
98
|
}>;
|
|
99
|
-
export declare const JsonRpcMockOptionsStruct: import("superstruct").Struct<{
|
|
99
|
+
export declare const JsonRpcMockOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
100
100
|
result: import("@metamask/snaps-sdk").Json;
|
|
101
101
|
method: string;
|
|
102
102
|
}, {
|
|
103
|
-
method: import("superstruct").Struct<string, null>;
|
|
104
|
-
result: import("superstruct").Struct<import("@metamask/snaps-sdk").Json, unknown>;
|
|
103
|
+
method: import("@metamask/superstruct").Struct<string, null>;
|
|
104
|
+
result: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Json, unknown>;
|
|
105
105
|
}>;
|
|
106
|
-
export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
106
|
+
export declare const InterfaceStruct: import("@metamask/superstruct").Struct<{
|
|
107
107
|
content?: import("@metamask/snaps-sdk/jsx").JSXElement | undefined;
|
|
108
108
|
}, {
|
|
109
|
-
content: import("superstruct").Struct<import("@metamask/snaps-sdk/jsx").JSXElement | undefined, null>;
|
|
109
|
+
content: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk/jsx").JSXElement | undefined, null>;
|
|
110
110
|
}>;
|
|
111
|
-
export declare const SnapResponseWithoutInterfaceStruct: import("superstruct").Struct<{
|
|
111
|
+
export declare const SnapResponseWithoutInterfaceStruct: import("@metamask/superstruct").Struct<{
|
|
112
112
|
id: string;
|
|
113
113
|
response: {
|
|
114
114
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -121,27 +121,27 @@ export declare const SnapResponseWithoutInterfaceStruct: import("superstruct").S
|
|
|
121
121
|
id: string;
|
|
122
122
|
}[];
|
|
123
123
|
}, {
|
|
124
|
-
id: import("superstruct").Struct<string, null>;
|
|
125
|
-
response: import("superstruct").Struct<{
|
|
124
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
125
|
+
response: import("@metamask/superstruct").Struct<{
|
|
126
126
|
result: import("@metamask/snaps-sdk").Json;
|
|
127
127
|
} | {
|
|
128
128
|
error: import("@metamask/snaps-sdk").Json;
|
|
129
129
|
}, null>;
|
|
130
|
-
notifications: import("superstruct").Struct<{
|
|
130
|
+
notifications: import("@metamask/superstruct").Struct<{
|
|
131
131
|
type: "native" | "inApp";
|
|
132
132
|
message: string;
|
|
133
133
|
id: string;
|
|
134
|
-
}[], import("superstruct").Struct<{
|
|
134
|
+
}[], import("@metamask/superstruct").Struct<{
|
|
135
135
|
type: "native" | "inApp";
|
|
136
136
|
message: string;
|
|
137
137
|
id: string;
|
|
138
138
|
}, {
|
|
139
|
-
id: import("superstruct").Struct<string, null>;
|
|
140
|
-
message: import("superstruct").Struct<string, null>;
|
|
141
|
-
type: import("superstruct").Struct<"native" | "inApp", null>;
|
|
139
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
140
|
+
message: import("@metamask/superstruct").Struct<string, null>;
|
|
141
|
+
type: import("@metamask/superstruct").Struct<"native" | "inApp", null>;
|
|
142
142
|
}>>;
|
|
143
143
|
}>;
|
|
144
|
-
export declare const SnapResponseWithInterfaceStruct: import("superstruct").Struct<{
|
|
144
|
+
export declare const SnapResponseWithInterfaceStruct: import("@metamask/superstruct").Struct<{
|
|
145
145
|
id: string;
|
|
146
146
|
response: {
|
|
147
147
|
result: import("@metamask/snaps-sdk").Json;
|
|
@@ -155,28 +155,28 @@ export declare const SnapResponseWithInterfaceStruct: import("superstruct").Stru
|
|
|
155
155
|
id: string;
|
|
156
156
|
}[];
|
|
157
157
|
}, {
|
|
158
|
-
getInterface: import("superstruct").Struct<Function, null>;
|
|
159
|
-
id: import("superstruct").Struct<string, null>;
|
|
160
|
-
response: import("superstruct").Struct<{
|
|
158
|
+
getInterface: import("@metamask/superstruct").Struct<Function, null>;
|
|
159
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
160
|
+
response: import("@metamask/superstruct").Struct<{
|
|
161
161
|
result: import("@metamask/snaps-sdk").Json;
|
|
162
162
|
} | {
|
|
163
163
|
error: import("@metamask/snaps-sdk").Json;
|
|
164
164
|
}, null>;
|
|
165
|
-
notifications: import("superstruct").Struct<{
|
|
165
|
+
notifications: import("@metamask/superstruct").Struct<{
|
|
166
166
|
type: "native" | "inApp";
|
|
167
167
|
message: string;
|
|
168
168
|
id: string;
|
|
169
|
-
}[], import("superstruct").Struct<{
|
|
169
|
+
}[], import("@metamask/superstruct").Struct<{
|
|
170
170
|
type: "native" | "inApp";
|
|
171
171
|
message: string;
|
|
172
172
|
id: string;
|
|
173
173
|
}, {
|
|
174
|
-
id: import("superstruct").Struct<string, null>;
|
|
175
|
-
message: import("superstruct").Struct<string, null>;
|
|
176
|
-
type: import("superstruct").Struct<"native" | "inApp", null>;
|
|
174
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
175
|
+
message: import("@metamask/superstruct").Struct<string, null>;
|
|
176
|
+
type: import("@metamask/superstruct").Struct<"native" | "inApp", null>;
|
|
177
177
|
}>>;
|
|
178
178
|
}>;
|
|
179
|
-
export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
179
|
+
export declare const SnapResponseStruct: import("@metamask/superstruct").Struct<{
|
|
180
180
|
id: string;
|
|
181
181
|
response: {
|
|
182
182
|
result: import("@metamask/snaps-sdk").Json;
|
package/dist/types/matchers.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { MatcherFunction } from '@jest/expect';
|
|
2
2
|
import type { NotificationType, EnumToUnion, ComponentOrElement } from '@metamask/snaps-sdk';
|
|
3
|
-
import type { SnapNode } from '@metamask/snaps-sdk/jsx';
|
|
4
3
|
import type { Json } from '@metamask/utils';
|
|
5
4
|
/**
|
|
6
5
|
* Check if a JSON-RPC response matches the expected value. This matcher is
|
|
@@ -25,13 +24,4 @@ export declare const toSendNotification: MatcherFunction<[
|
|
|
25
24
|
expected: string,
|
|
26
25
|
type?: EnumToUnion<NotificationType> | undefined
|
|
27
26
|
]>;
|
|
28
|
-
/**
|
|
29
|
-
* Serialise a JSX node to a string.
|
|
30
|
-
*
|
|
31
|
-
* @param node - The JSX node.
|
|
32
|
-
* @param indentation - The indentation level. Defaults to `0`. This should not
|
|
33
|
-
* be set by the caller, as it is used for recursion.
|
|
34
|
-
* @returns The serialised JSX node.
|
|
35
|
-
*/
|
|
36
|
-
export declare function serialiseJsx(node: SnapNode, indentation?: number): string;
|
|
37
27
|
export declare const toRender: MatcherFunction<[expected: ComponentOrElement]>;
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { Infer } from 'superstruct';
|
|
2
|
-
declare const SnapsEnvironmentOptionsStruct: import("superstruct").Struct<{
|
|
1
|
+
import type { Infer } from '@metamask/superstruct';
|
|
2
|
+
declare const SnapsEnvironmentOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
3
3
|
server: {
|
|
4
4
|
port: number;
|
|
5
5
|
enabled: boolean;
|
|
6
6
|
root: string;
|
|
7
7
|
};
|
|
8
8
|
}, {
|
|
9
|
-
server: import("superstruct").Struct<{
|
|
9
|
+
server: import("@metamask/superstruct").Struct<{
|
|
10
10
|
port: number;
|
|
11
11
|
enabled: boolean;
|
|
12
12
|
root: string;
|
|
13
13
|
}, {
|
|
14
|
-
enabled: import("superstruct").Struct<boolean, null>;
|
|
15
|
-
port: import("superstruct").Struct<number, null>;
|
|
16
|
-
root: import("superstruct").Struct<string, null>;
|
|
14
|
+
enabled: import("@metamask/superstruct").Struct<boolean, null>;
|
|
15
|
+
port: import("@metamask/superstruct").Struct<number, null>;
|
|
16
|
+
root: import("@metamask/superstruct").Struct<string, null>;
|
|
17
17
|
}>;
|
|
18
18
|
}>;
|
|
19
19
|
/**
|
|
@@ -41,7 +41,7 @@ declare const SnapsEnvironmentOptionsStruct: import("superstruct").Struct<{
|
|
|
41
41
|
* directory containing the snap manifest and `dist` files. If this is a
|
|
42
42
|
* relative path, it will be resolved relative to the current working directory.
|
|
43
43
|
*/
|
|
44
|
-
export
|
|
44
|
+
export type SnapsEnvironmentOptions = Infer<typeof SnapsEnvironmentOptionsStruct>;
|
|
45
45
|
/**
|
|
46
46
|
* Get the environment options. This validates the options, and returns the
|
|
47
47
|
* default options if none are provided.
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';
|
|
2
2
|
import type { JSXElement } from '@metamask/snaps-sdk/jsx';
|
|
3
3
|
import type { InferMatching } from '@metamask/snaps-utils';
|
|
4
|
+
import type { Infer } from '@metamask/superstruct';
|
|
4
5
|
import type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils';
|
|
5
|
-
import type { Infer } from 'superstruct';
|
|
6
6
|
import type { SignatureOptionsStruct, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct } from './internals';
|
|
7
|
-
export
|
|
7
|
+
export type RequestOptions = {
|
|
8
8
|
/**
|
|
9
9
|
* The JSON-RPC request ID.
|
|
10
10
|
*/
|
|
@@ -26,7 +26,7 @@ export declare type RequestOptions = {
|
|
|
26
26
|
* The `runCronjob` options. This is the same as {@link RequestOptions}, except
|
|
27
27
|
* that it does not have an `origin` property.
|
|
28
28
|
*/
|
|
29
|
-
export
|
|
29
|
+
export type CronjobOptions = Omit<RequestOptions, 'origin'>;
|
|
30
30
|
/**
|
|
31
31
|
* The options to use for transaction requests.
|
|
32
32
|
*
|
|
@@ -48,7 +48,7 @@ export declare type CronjobOptions = Omit<RequestOptions, 'origin'>;
|
|
|
48
48
|
* the transaction. Defaults to `1`.
|
|
49
49
|
* @property nonce - The nonce to use for the transaction. Defaults to `0`.
|
|
50
50
|
*/
|
|
51
|
-
export
|
|
51
|
+
export type TransactionOptions = Infer<typeof TransactionOptionsStruct>;
|
|
52
52
|
/**
|
|
53
53
|
* The options to use for signature requests.
|
|
54
54
|
*
|
|
@@ -59,14 +59,29 @@ export declare type TransactionOptions = Infer<typeof TransactionOptionsStruct>;
|
|
|
59
59
|
* @property data - The data to sign. Defaults to `0x`.
|
|
60
60
|
* @property signatureMethod - The signature method.
|
|
61
61
|
*/
|
|
62
|
-
export
|
|
62
|
+
export type SignatureOptions = Infer<typeof SignatureOptionsStruct>;
|
|
63
63
|
/**
|
|
64
64
|
* The options to use for requests to the snap.
|
|
65
65
|
*
|
|
66
66
|
* @property timeout - The timeout in milliseconds to use. Defaults to `1000`.
|
|
67
67
|
*/
|
|
68
|
-
export
|
|
69
|
-
|
|
68
|
+
export type SnapOptions = Infer<typeof SnapOptionsStruct>;
|
|
69
|
+
/**
|
|
70
|
+
* Options for uploading a file.
|
|
71
|
+
*
|
|
72
|
+
* @property fileName - The name of the file. By default, this is inferred from
|
|
73
|
+
* the file path if it's a path, and defaults to an empty string if it's a
|
|
74
|
+
* `Uint8Array`.
|
|
75
|
+
* @property contentType - The content type of the file. By default, this is
|
|
76
|
+
* inferred from the file name if it's a path, and defaults to
|
|
77
|
+
* `application/octet-stream` if it's a `Uint8Array` or the content type cannot
|
|
78
|
+
* be inferred from the file name.
|
|
79
|
+
*/
|
|
80
|
+
export type FileOptions = {
|
|
81
|
+
fileName?: string;
|
|
82
|
+
contentType?: string;
|
|
83
|
+
};
|
|
84
|
+
export type SnapInterfaceActions = {
|
|
70
85
|
/**
|
|
71
86
|
* Click on an interface element.
|
|
72
87
|
*
|
|
@@ -87,11 +102,35 @@ export declare type SnapInterfaceActions = {
|
|
|
87
102
|
* @param value - The value to type.
|
|
88
103
|
*/
|
|
89
104
|
selectInDropdown(name: string, value: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Choose an option with a value from radio group.
|
|
107
|
+
*
|
|
108
|
+
* @param name - The element name to type in.
|
|
109
|
+
* @param value - The value to type.
|
|
110
|
+
*/
|
|
111
|
+
selectFromRadioGroup(name: string, value: string): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Upload a file.
|
|
114
|
+
*
|
|
115
|
+
* @param name - The element name to upload the file to.
|
|
116
|
+
* @param file - The file to upload. This can be a path to a file or a
|
|
117
|
+
* `Uint8Array` containing the file contents. If this is a path, the file is
|
|
118
|
+
* resolved relative to the current working directory.
|
|
119
|
+
* @param options - The file options.
|
|
120
|
+
* @param options.fileName - The name of the file. By default, this is
|
|
121
|
+
* inferred from the file path if it's a path, and defaults to an empty string
|
|
122
|
+
* if it's a `Uint8Array`.
|
|
123
|
+
* @param options.contentType - The content type of the file. By default, this
|
|
124
|
+
* is inferred from the file name if it's a path, and defaults to
|
|
125
|
+
* `application/octet-stream` if it's a `Uint8Array` or the content type
|
|
126
|
+
* cannot be inferred from the file name.
|
|
127
|
+
*/
|
|
128
|
+
uploadFile(name: string, file: string | Uint8Array, options?: FileOptions): Promise<void>;
|
|
90
129
|
};
|
|
91
130
|
/**
|
|
92
131
|
* A `snap_dialog` alert interface.
|
|
93
132
|
*/
|
|
94
|
-
export
|
|
133
|
+
export type SnapAlertInterface = {
|
|
95
134
|
/**
|
|
96
135
|
* The type of the interface. This is always `alert`.
|
|
97
136
|
*/
|
|
@@ -108,7 +147,7 @@ export declare type SnapAlertInterface = {
|
|
|
108
147
|
/**
|
|
109
148
|
* A `snap_dialog` confirmation interface.
|
|
110
149
|
*/
|
|
111
|
-
export
|
|
150
|
+
export type SnapConfirmationInterface = {
|
|
112
151
|
/**
|
|
113
152
|
* The type of the interface. This is always `confirmation`.
|
|
114
153
|
*/
|
|
@@ -129,7 +168,7 @@ export declare type SnapConfirmationInterface = {
|
|
|
129
168
|
/**
|
|
130
169
|
* A `snap_dialog` prompt interface.
|
|
131
170
|
*/
|
|
132
|
-
export
|
|
171
|
+
export type SnapPromptInterface = {
|
|
133
172
|
/**
|
|
134
173
|
* The type of the interface. This is always `prompt`.
|
|
135
174
|
*/
|
|
@@ -149,8 +188,40 @@ export declare type SnapPromptInterface = {
|
|
|
149
188
|
*/
|
|
150
189
|
cancel(): Promise<void>;
|
|
151
190
|
};
|
|
152
|
-
|
|
153
|
-
|
|
191
|
+
/**
|
|
192
|
+
* A `snap_dialog` default interface that has a Footer with two buttons defined.
|
|
193
|
+
* The approval of this confirmation is handled by the snap.
|
|
194
|
+
*/
|
|
195
|
+
export type DefaultSnapInterfaceWithFooter = {
|
|
196
|
+
/**
|
|
197
|
+
* The content to show in the interface.
|
|
198
|
+
*/
|
|
199
|
+
content: JSXElement;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* A `snap_dialog` default interface that has a Footer with one button defined.
|
|
203
|
+
* A cancel button is automatically applied to the interface in this case.
|
|
204
|
+
*/
|
|
205
|
+
export type DefaultSnapInterfaceWithPartialFooter = DefaultSnapInterfaceWithFooter & {
|
|
206
|
+
/**
|
|
207
|
+
* Cancel the dialog.
|
|
208
|
+
*/
|
|
209
|
+
cancel(): Promise<void>;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* A `snap_dialog` default interface that has no Footer defined.
|
|
213
|
+
* A cancel and ok button is automatically applied to the interface in this case.
|
|
214
|
+
*/
|
|
215
|
+
export type DefaultSnapInterfaceWithoutFooter = DefaultSnapInterfaceWithPartialFooter & {
|
|
216
|
+
/**
|
|
217
|
+
* Close the dialog.
|
|
218
|
+
*
|
|
219
|
+
*/
|
|
220
|
+
ok(): Promise<void>;
|
|
221
|
+
};
|
|
222
|
+
export type DefaultSnapInterface = DefaultSnapInterfaceWithFooter | DefaultSnapInterfaceWithPartialFooter | DefaultSnapInterfaceWithoutFooter;
|
|
223
|
+
export type SnapInterface = (SnapAlertInterface | SnapConfirmationInterface | SnapPromptInterface | DefaultSnapInterface) & SnapInterfaceActions;
|
|
224
|
+
export type SnapRequestObject = {
|
|
154
225
|
/**
|
|
155
226
|
* Get a user interface object from a snap. This will throw an error if the
|
|
156
227
|
* snap does not show a user interface within the timeout.
|
|
@@ -166,11 +237,11 @@ export declare type SnapRequestObject = {
|
|
|
166
237
|
* A pending request object. This is a promise with extra
|
|
167
238
|
* {@link SnapRequestObject} fields.
|
|
168
239
|
*/
|
|
169
|
-
export
|
|
240
|
+
export type SnapRequest = Promise<SnapResponse> & SnapRequestObject;
|
|
170
241
|
/**
|
|
171
242
|
* The options to use for mocking a JSON-RPC request.
|
|
172
243
|
*/
|
|
173
|
-
export
|
|
244
|
+
export type JsonRpcMockOptions = {
|
|
174
245
|
/**
|
|
175
246
|
* The JSON-RPC request method.
|
|
176
247
|
*/
|
|
@@ -193,7 +264,7 @@ export declare type JsonRpcMockOptions = {
|
|
|
193
264
|
*
|
|
194
265
|
* expect(response).toRespondWith('Hello, world!');
|
|
195
266
|
*/
|
|
196
|
-
export
|
|
267
|
+
export type Snap = {
|
|
197
268
|
/**
|
|
198
269
|
* Send a JSON-RPC request to the snap.
|
|
199
270
|
*
|
|
@@ -292,10 +363,10 @@ export declare type Snap = {
|
|
|
292
363
|
*/
|
|
293
364
|
close(): Promise<void>;
|
|
294
365
|
};
|
|
295
|
-
export
|
|
366
|
+
export type SnapHandlerInterface = {
|
|
296
367
|
content: JSXElement;
|
|
297
368
|
} & SnapInterfaceActions;
|
|
298
|
-
export
|
|
369
|
+
export type SnapResponseWithInterface = {
|
|
299
370
|
id: string;
|
|
300
371
|
response: {
|
|
301
372
|
result: Json;
|
|
@@ -309,6 +380,6 @@ export declare type SnapResponseWithInterface = {
|
|
|
309
380
|
}[];
|
|
310
381
|
getInterface(): SnapHandlerInterface;
|
|
311
382
|
};
|
|
312
|
-
export
|
|
313
|
-
export
|
|
314
|
-
export
|
|
383
|
+
export type SnapResponseWithoutInterface = Omit<SnapResponseWithInterface, 'getInterface'>;
|
|
384
|
+
export type SnapResponseType = SnapResponseWithoutInterface | SnapResponseWithInterface;
|
|
385
|
+
export type SnapResponse = InferMatching<typeof SnapResponseStruct, SnapResponseType>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-jest",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.3.0",
|
|
4
4
|
"description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -40,26 +40,27 @@
|
|
|
40
40
|
"@jest/environment": "^29.5.0",
|
|
41
41
|
"@jest/expect": "^29.5.0",
|
|
42
42
|
"@jest/globals": "^29.5.0",
|
|
43
|
-
"@metamask/base-controller": "^6.0.
|
|
44
|
-
"@metamask/eth-json-rpc-middleware": "^
|
|
45
|
-
"@metamask/json-rpc-engine": "^9.0.
|
|
46
|
-
"@metamask/json-rpc-middleware-stream": "^8.0.
|
|
47
|
-
"@metamask/key-tree": "^9.1.
|
|
48
|
-
"@metamask/permission-controller": "^
|
|
49
|
-
"@metamask/snaps-controllers": "^9.
|
|
50
|
-
"@metamask/snaps-execution-environments": "^6.
|
|
51
|
-
"@metamask/snaps-rpc-methods": "^
|
|
52
|
-
"@metamask/snaps-sdk": "^
|
|
53
|
-
"@metamask/snaps-utils": "^
|
|
54
|
-
"@metamask/
|
|
43
|
+
"@metamask/base-controller": "^6.0.2",
|
|
44
|
+
"@metamask/eth-json-rpc-middleware": "^13.0.0",
|
|
45
|
+
"@metamask/json-rpc-engine": "^9.0.2",
|
|
46
|
+
"@metamask/json-rpc-middleware-stream": "^8.0.2",
|
|
47
|
+
"@metamask/key-tree": "^9.1.2",
|
|
48
|
+
"@metamask/permission-controller": "^11.0.0",
|
|
49
|
+
"@metamask/snaps-controllers": "^9.4.0",
|
|
50
|
+
"@metamask/snaps-execution-environments": "^6.6.2",
|
|
51
|
+
"@metamask/snaps-rpc-methods": "^11.0.0",
|
|
52
|
+
"@metamask/snaps-sdk": "^6.2.0",
|
|
53
|
+
"@metamask/snaps-utils": "^8.0.0",
|
|
54
|
+
"@metamask/superstruct": "^3.1.0",
|
|
55
|
+
"@metamask/utils": "^9.1.0",
|
|
55
56
|
"@reduxjs/toolkit": "^1.9.5",
|
|
56
57
|
"express": "^4.18.2",
|
|
57
58
|
"jest-environment-node": "^29.5.0",
|
|
58
59
|
"jest-matcher-utils": "^29.5.0",
|
|
60
|
+
"mime": "^3.0.0",
|
|
59
61
|
"readable-stream": "^3.6.2",
|
|
60
62
|
"redux": "^4.2.1",
|
|
61
|
-
"redux-saga": "^1.2.3"
|
|
62
|
-
"superstruct": "^1.0.3"
|
|
63
|
+
"redux-saga": "^1.2.3"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
66
|
"@jest/types": "^29.6.3",
|
|
@@ -72,6 +73,7 @@
|
|
|
72
73
|
"@swc/core": "1.3.78",
|
|
73
74
|
"@swc/jest": "^0.2.26",
|
|
74
75
|
"@types/jest": "^27.5.1",
|
|
76
|
+
"@types/mime": "^3.0.0",
|
|
75
77
|
"@types/semver": "^7.5.0",
|
|
76
78
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
77
79
|
"@typescript-eslint/parser": "^5.42.1",
|
|
@@ -91,7 +93,7 @@
|
|
|
91
93
|
"prettier-plugin-packagejson": "^2.2.11",
|
|
92
94
|
"rimraf": "^4.1.2",
|
|
93
95
|
"tsup": "^8.0.1",
|
|
94
|
-
"typescript": "~
|
|
96
|
+
"typescript": "~5.0.4"
|
|
95
97
|
},
|
|
96
98
|
"engines": {
|
|
97
99
|
"node": "^18.16 || >=20"
|
package/dist/chunk-265BMFM5.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internals/simulation/methods/hooks/get-locale.ts
|
|
2
|
-
function getGetLocaleMethodImplementation({
|
|
3
|
-
locale
|
|
4
|
-
}) {
|
|
5
|
-
return async () => {
|
|
6
|
-
return locale;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
exports.getGetLocaleMethodImplementation = getGetLocaleMethodImplementation;
|
|
13
|
-
//# sourceMappingURL=chunk-265BMFM5.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internals/simulation/methods/hooks/get-locale.ts"],"names":[],"mappings":";AASO,SAAS,iCAAiC;AAAA,EAC/C;AACF,GAAsB;AACpB,SAAO,YAAY;AACjB,WAAO;AAAA,EACT;AACF","sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getLocale` hook.\n *\n * @param options - The simulation options.\n * @param options.locale - The locale to use.\n * @returns The implementation of the `getLocale` hook.\n */\nexport function getGetLocaleMethodImplementation({\n locale,\n}: SimulationOptions) {\n return async () => {\n return locale;\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internals/request.ts"],"names":[],"mappings":"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","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type SnapId,\n type JsonRpcError,\n type ComponentOrElement,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\nimport { is } from 'superstruct';\n\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from '../types';\nimport {\n clearNotifications,\n clickElement,\n getInterface,\n getNotifications,\n typeInField,\n selectInDropdown,\n} from './simulation';\nimport type { RunSagaFunction, Store } from './simulation';\nimport type { RootControllerMessenger } from './simulation/controllers';\nimport { SnapResponseStruct } from './structs';\n\nexport type HandleRequestOptions = {\n snapId: SnapId;\n store: Store;\n executionService: AbstractExecutionService<unknown>;\n handler: HandlerType;\n controllerMessenger: RootControllerMessenger;\n runSaga: RunSagaFunction;\n request: RequestOptions;\n};\n\n/**\n * Send a JSON-RPC request to the Snap, and wrap the response in a\n * {@link SnapResponse} object.\n *\n * @param options - The request options.\n * @param options.snapId - The ID of the Snap to send the request to.\n * @param options.store - The Redux store.\n * @param options.executionService - The execution service to use to send the\n * request.\n * @param options.handler - The handler to use to send the request.\n * @param options.controllerMessenger - The controller messenger used to call actions.\n * @param options.runSaga - A function to run a saga outside the usual Redux\n * flow.\n * @param options.request - The request to send.\n * @param options.request.id - The ID of the request. If not provided, a random\n * ID will be generated.\n * @param options.request.origin - The origin of the request. Defaults to\n * `https://metamask.io`.\n * @returns The response, wrapped in a {@link SnapResponse} object.\n */\nexport function handleRequest({\n snapId,\n store,\n executionService,\n handler,\n controllerMessenger,\n runSaga,\n request: { id = nanoid(), origin = 'https://metamask.io', ...options },\n}: HandleRequestOptions): SnapRequest {\n const getInterfaceError = () => {\n throw new Error(\n 'Unable to get the interface from the Snap: The request to the Snap failed.',\n );\n };\n\n const promise = executionService\n .handleRpcRequest(snapId, {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n })\n .then(async (result) => {\n const notifications = getNotifications(store.getState());\n store.dispatch(clearNotifications());\n\n try {\n const getInterfaceFn = await getInterfaceApi(\n result,\n snapId,\n controllerMessenger,\n );\n\n return {\n id: String(id),\n response: {\n result: getSafeJson(result),\n },\n notifications,\n ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),\n };\n } catch (error) {\n const [unwrappedError] = unwrapError(error);\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }\n })\n .catch((error) => {\n const [unwrappedError] = unwrapError(error);\n\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }) as unknown as SnapRequest;\n\n promise.getInterface = async () => {\n const sagaPromise = runSaga(\n getInterface,\n runSaga,\n snapId,\n controllerMessenger,\n ).toPromise();\n const result = await Promise.race([promise, sagaPromise]);\n\n // If the request promise has resolved to an error, we should throw\n // instead of waiting for an interface that likely will never be displayed\n if (\n is(result, SnapResponseStruct) &&\n hasProperty(result.response, 'error')\n ) {\n throw new Error(\n `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${\n (result.response.error as JsonRpcError).message\n }`,\n );\n }\n\n return await sagaPromise;\n };\n\n return promise;\n}\n\n/**\n * Get the interface ID from the result if it's available or create a new interface if the result contains static components.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The interface ID or undefined if the result doesn't include content.\n */\nexport async function getInterfaceFromResult(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n) {\n if (isPlainObject(result) && hasProperty(result, 'id')) {\n return result.id as string;\n }\n\n if (isPlainObject(result) && hasProperty(result, 'content')) {\n assert(\n is(result.content, ComponentOrElementStruct),\n 'The Snap returned an invalid interface.',\n );\n const id = await controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n result.content as ComponentOrElement,\n );\n\n return id;\n }\n\n return undefined;\n}\n\n/**\n * Get the response content from the SnapInterfaceController and include the interaction methods.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The content components if any.\n */\nexport async function getInterfaceApi(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): Promise<(() => SnapHandlerInterface) | undefined> {\n const interfaceId = await getInterfaceFromResult(\n result,\n snapId,\n controllerMessenger,\n );\n\n if (interfaceId) {\n return () => {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n interfaceId,\n );\n\n return {\n content,\n clickElement: async (name) => {\n await clickElement(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n );\n },\n typeInField: async (name, value) => {\n await typeInField(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n value,\n );\n },\n selectInDropdown: async (name, value) => {\n await selectInDropdown(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n value,\n );\n },\n };\n };\n }\n\n return undefined;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/helpers.ts"],"names":[],"mappings":"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","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType, logInfo } from '@metamask/snaps-utils';\nimport { assertStruct, createModuleLogger } from '@metamask/utils';\nimport { create } from 'superstruct';\n\nimport {\n rootLogger,\n handleRequest,\n TransactionOptionsStruct,\n getEnvironment,\n JsonRpcMockOptionsStruct,\n SignatureOptionsStruct,\n SnapResponseWithInterfaceStruct,\n} from './internals';\nimport type { InstallSnapOptions } from './internals';\nimport {\n addJsonRpcMock,\n removeJsonRpcMock,\n} from './internals/simulation/store/mocks';\nimport type {\n SnapResponseWithInterface,\n CronjobOptions,\n JsonRpcMockOptions,\n Snap,\n SnapResponse,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Ensure that the actual response contains `getInterface`.\n *\n * @param response - The response of the handler.\n */\nfunction assertIsResponseWithInterface(\n response: SnapResponse,\n): asserts response is SnapResponseWithInterface {\n assertStruct(response, SnapResponseWithInterfaceStruct);\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n const {\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n } = await getEnvironment().installSnap(...resolvedOptions);\n\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n return {\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/internals/simulation/controllers.ts"],"names":[],"mappings":";;;;;;;;AAOA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,+BAA+B;AAMxC;AAAA,EACE,wBAAwB;AAAA,EACxB,iCAAiC;AAAA,EACjC;AAAA,OACK;AAGP,SAAS,mBAAmB;AA0CrB,SAAS,eAAe,SAA6C;AAC1E,QAAM,EAAE,oBAAoB,IAAI;AAChC,QAAM,4BAA4B,IAAI,0BAA0B;AAAA,IAC9D,WAAW,oBAAoB,cAAc;AAAA,MAC3C,MAAM;AAAA,MACN,gBAAgB,CAAC;AAAA,MACjB,eAAe,CAAC;AAAA,IAClB,CAAC;AAAA,IACD,mBAAmB;AAAA,EACrB,CAAC;AAED,QAAM,sBAAsB,IAAI,wBAAwB;AAAA,IACtD,WAAW,oBAAoB,cAAc;AAAA,MAC3C,MAAM;AAAA,MACN,gBAAgB;AAAA,QACd;AAAA,QACA;AAAA,MACF;AAAA,MACA,eAAe,CAAC;AAAA,IAClB,CAAC;AAAA,EACH,CAAC;AAED,QAAM,uBAAuB,wBAAwB,OAAO;AAE5D,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAUA,SAAS,wBAAwB,SAAgC;AAC/D,QAAM,EAAE,oBAAoB,IAAI;AAChC,QAAM,2BAA2B,4BAA4B,OAAO;AACpE,SAAO,IAAI,qBAAqB;AAAA,IAC9B,WAAW,oBAAoB,cAAc;AAAA,MAC3C,MAAM;AAAA,MACN,gBAAgB;AAAA,QACd;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA,eAAe,CAAC;AAAA,IAClB,CAAC;AAAA,IACD,sBAAsB;AAAA,MACpB,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA,EACvB,CAAC;AACH;AAWA,eAAsB,aACpB,QACA,UACA;AAAA,EACE;AAAA,EACA;AACF,GACA;AACA,4BAA0B,mBAAmB;AAAA,IAC3C,QAAQ;AAAA,IACR,aAAa,YAAY;AAAA,EAC3B,CAAC;AAED,QAAM,sBAAsB;AAAA,IAC1B,YAAY,SAAS,kBAAkB;AAAA,EACzC;AAEA,uBAAqB,iBAAiB;AAAA,IACpC;AAAA,IACA,SAAS,EAAE,QAAQ,OAAO;AAAA,IAC1B,6BAA6B;AAAA,EAC/B,CAAC;AACH","sourcesContent":["import type { ControllerMessenger } from '@metamask/base-controller';\nimport type {\n CaveatSpecificationConstraint,\n PermissionSpecificationConstraint,\n PermissionControllerActions,\n SubjectMetadataControllerActions,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapInterfaceController } from '@metamask/snaps-controllers';\nimport type {\n ExecutionServiceActions,\n SnapInterfaceControllerActions,\n SnapInterfaceControllerAllowedActions,\n} from '@metamask/snaps-controllers';\nimport {\n caveatSpecifications as snapsCaveatsSpecifications,\n endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,\n processSnapPermissions,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { SnapManifest } from '@metamask/snaps-utils';\nimport { getSafeJson } from '@metamask/utils';\n\nimport { getPermissionSpecifications } from './methods';\nimport { UNRESTRICTED_METHODS } from './methods/constants';\nimport type { SimulationOptions } from './options';\nimport type { MiddlewareHooks } from './simulation';\nimport type { RunSagaFunction } from './store';\n\nexport type RootControllerAllowedActions =\n | SnapInterfaceControllerActions\n | SnapInterfaceControllerAllowedActions\n | PermissionControllerActions\n | ExecutionServiceActions\n | SubjectMetadataControllerActions;\n\nexport type RootControllerMessenger = ControllerMessenger<\n RootControllerAllowedActions,\n any\n>;\n\nexport type GetControllersOptions = {\n controllerMessenger: ControllerMessenger<any, any>;\n hooks: MiddlewareHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\nexport type Controllers = {\n permissionController: PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n >;\n subjectMetadataController: SubjectMetadataController;\n interfaceController: SnapInterfaceController;\n};\n\n/**\n * Get the controllers for the Snap.\n *\n * @param options - The options.\n * @returns The controllers for the Snap.\n */\nexport function getControllers(options: GetControllersOptions): Controllers {\n const { controllerMessenger } = options;\n const subjectMetadataController = new SubjectMetadataController({\n messenger: controllerMessenger.getRestricted({\n name: 'SubjectMetadataController',\n allowedActions: [],\n allowedEvents: [],\n }),\n subjectCacheLimit: 100,\n });\n\n const interfaceController = new SnapInterfaceController({\n messenger: controllerMessenger.getRestricted({\n name: 'SnapInterfaceController',\n allowedActions: [\n 'PhishingController:maybeUpdateState',\n 'PhishingController:testOrigin',\n ],\n allowedEvents: [],\n }),\n });\n\n const permissionController = getPermissionController(options);\n\n return {\n permissionController,\n subjectMetadataController,\n interfaceController,\n };\n}\n\n/**\n * Get the permission controller for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.options - Miscellaneous options.\n * @returns The permission controller for the Snap.\n */\nfunction getPermissionController(options: GetControllersOptions) {\n const { controllerMessenger } = options;\n const permissionSpecifications = getPermissionSpecifications(options);\n return new PermissionController({\n messenger: controllerMessenger.getRestricted({\n name: 'PermissionController',\n allowedActions: [\n `ApprovalController:addRequest`,\n `ApprovalController:hasRequest`,\n `ApprovalController:acceptRequest`,\n `ApprovalController:rejectRequest`,\n `SnapController:getPermitted`,\n `SnapController:install`,\n `SubjectMetadataController:getSubjectMetadata`,\n ],\n allowedEvents: [],\n }),\n caveatSpecifications: {\n ...snapsCaveatsSpecifications,\n ...snapsEndowmentCaveatSpecifications,\n },\n permissionSpecifications,\n unrestrictedMethods: UNRESTRICTED_METHODS,\n });\n}\n\n/**\n * Register the Snap. This sets up the Snap's permissions and subject metadata.\n *\n * @param snapId - The ID of the Snap to install.\n * @param manifest - The parsed manifest.\n * @param controllers - The controllers for the Snap.\n * @param controllers.permissionController - The permission controller.\n * @param controllers.subjectMetadataController - The subject metadata controller.\n */\nexport async function registerSnap(\n snapId: SnapId,\n manifest: SnapManifest,\n {\n permissionController,\n subjectMetadataController,\n }: Omit<Controllers, 'interfaceController'>,\n) {\n subjectMetadataController.addSubjectMetadata({\n origin: snapId,\n subjectType: SubjectType.Snap,\n });\n\n const approvedPermissions = processSnapPermissions(\n getSafeJson(manifest.initialPermissions),\n );\n\n permissionController.grantPermissions({\n approvedPermissions,\n subject: { origin: snapId },\n preserveExistingPermissions: false,\n });\n}\n"]}
|