@metamask/snaps-simulation 4.1.3 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -2
- package/dist/methods/hooks/index.cjs +0 -2
- package/dist/methods/hooks/index.cjs.map +1 -1
- package/dist/methods/hooks/index.d.cts +0 -2
- package/dist/methods/hooks/index.d.cts.map +1 -1
- package/dist/methods/hooks/index.d.mts +0 -2
- package/dist/methods/hooks/index.d.mts.map +1 -1
- package/dist/methods/hooks/index.mjs +0 -2
- package/dist/methods/hooks/index.mjs.map +1 -1
- package/dist/methods/hooks/state.cjs +1 -1
- package/dist/methods/hooks/state.cjs.map +1 -1
- package/dist/methods/hooks/state.d.cts +1 -1
- package/dist/methods/hooks/state.d.cts.map +1 -1
- package/dist/methods/hooks/state.d.mts +1 -1
- package/dist/methods/hooks/state.d.mts.map +1 -1
- package/dist/methods/hooks/state.mjs +1 -1
- package/dist/methods/hooks/state.mjs.map +1 -1
- package/dist/methods/specifications.cjs +5 -14
- package/dist/methods/specifications.cjs.map +1 -1
- package/dist/methods/specifications.d.cts +7 -17
- package/dist/methods/specifications.d.cts.map +1 -1
- package/dist/methods/specifications.d.mts +7 -17
- package/dist/methods/specifications.d.mts.map +1 -1
- package/dist/methods/specifications.mjs +6 -15
- package/dist/methods/specifications.mjs.map +1 -1
- package/dist/middleware/engine.cjs +8 -4
- package/dist/middleware/engine.cjs.map +1 -1
- package/dist/middleware/engine.d.cts +7 -6
- package/dist/middleware/engine.d.cts.map +1 -1
- package/dist/middleware/engine.d.mts +7 -6
- package/dist/middleware/engine.d.mts.map +1 -1
- package/dist/middleware/engine.mjs +9 -5
- package/dist/middleware/engine.mjs.map +1 -1
- package/dist/simulation.cjs +82 -27
- package/dist/simulation.cjs.map +1 -1
- package/dist/simulation.d.cts +18 -114
- package/dist/simulation.d.cts.map +1 -1
- package/dist/simulation.d.mts +18 -114
- package/dist/simulation.d.mts.map +1 -1
- package/dist/simulation.mjs +83 -28
- package/dist/simulation.mjs.map +1 -1
- package/package.json +12 -12
- package/dist/methods/hooks/get-entropy-sources.cjs +0 -30
- package/dist/methods/hooks/get-entropy-sources.cjs.map +0 -1
- package/dist/methods/hooks/get-entropy-sources.d.cts +0 -14
- package/dist/methods/hooks/get-entropy-sources.d.cts.map +0 -1
- package/dist/methods/hooks/get-entropy-sources.d.mts +0 -14
- package/dist/methods/hooks/get-entropy-sources.d.mts.map +0 -1
- package/dist/methods/hooks/get-entropy-sources.mjs +0 -26
- package/dist/methods/hooks/get-entropy-sources.mjs.map +0 -1
- package/dist/methods/hooks/get-mnemonic-seed.cjs +0 -29
- package/dist/methods/hooks/get-mnemonic-seed.cjs.map +0 -1
- package/dist/methods/hooks/get-mnemonic-seed.d.cts +0 -9
- package/dist/methods/hooks/get-mnemonic-seed.d.cts.map +0 -1
- package/dist/methods/hooks/get-mnemonic-seed.d.mts +0 -9
- package/dist/methods/hooks/get-mnemonic-seed.d.mts.map +0 -1
- package/dist/methods/hooks/get-mnemonic-seed.mjs +0 -25
- package/dist/methods/hooks/get-mnemonic-seed.mjs.map +0 -1
- package/dist/methods/hooks/interface.cjs +0 -34
- package/dist/methods/hooks/interface.cjs.map +0 -1
- package/dist/methods/hooks/interface.d.cts +0 -24
- package/dist/methods/hooks/interface.d.cts.map +0 -1
- package/dist/methods/hooks/interface.d.mts +0 -24
- package/dist/methods/hooks/interface.d.mts.map +0 -1
- package/dist/methods/hooks/interface.mjs +0 -28
- package/dist/methods/hooks/interface.mjs.map +0 -1
package/dist/simulation.d.cts
CHANGED
|
@@ -3,8 +3,8 @@ import type { ActionConstraint, EventConstraint, NamespacedName } from "@metamas
|
|
|
3
3
|
import { Messenger } from "@metamask/messenger";
|
|
4
4
|
import { type Caveat, type RequestedPermissions } from "@metamask/permission-controller";
|
|
5
5
|
import type { ExecutionService } from "@metamask/snaps-controllers";
|
|
6
|
-
import type { TrackEventParams,
|
|
7
|
-
import type {
|
|
6
|
+
import type { TrackEventParams, SnapId, TraceRequest, EndTraceRequest, TraceContext } from "@metamask/snaps-sdk";
|
|
7
|
+
import type { Snap, VirtualFile } from "@metamask/snaps-utils";
|
|
8
8
|
import type { Hex, Json } from "@metamask/utils";
|
|
9
9
|
import type { RootControllerMessenger } from "./controllers.cjs";
|
|
10
10
|
import type { SnapHelpers } from "./helpers.cjs";
|
|
@@ -48,17 +48,9 @@ export type RestrictedMiddlewareHooks = {
|
|
|
48
48
|
/**
|
|
49
49
|
* A hook that returns the user's secret recovery phrase.
|
|
50
50
|
*
|
|
51
|
-
* @param source - The entropy source to get the mnemonic from.
|
|
52
51
|
* @returns The user's secret recovery phrase.
|
|
53
52
|
*/
|
|
54
|
-
getMnemonic: (
|
|
55
|
-
/**
|
|
56
|
-
* A hook that returns the seed derived from the user's secret recovery phrase.
|
|
57
|
-
*
|
|
58
|
-
* @param source - The entropy source to get the seed from.
|
|
59
|
-
* @returns The seed.
|
|
60
|
-
*/
|
|
61
|
-
getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
|
|
53
|
+
getMnemonic: () => Promise<Uint8Array>;
|
|
62
54
|
/**
|
|
63
55
|
* A hook that returns whether the client is locked or not.
|
|
64
56
|
*
|
|
@@ -93,19 +85,6 @@ export type RestrictedMiddlewareHooks = {
|
|
|
93
85
|
getSimulationState: () => ApplicationState;
|
|
94
86
|
};
|
|
95
87
|
export type PermittedMiddlewareHooks = {
|
|
96
|
-
/**
|
|
97
|
-
* A hook that gets whether the requesting origin has a given permission.
|
|
98
|
-
*
|
|
99
|
-
* @param permissionName - The name of the permission to check.
|
|
100
|
-
* @returns Whether the origin has the permission.
|
|
101
|
-
*/
|
|
102
|
-
hasPermission: (permissionName: string) => boolean;
|
|
103
|
-
/**
|
|
104
|
-
* A hook that returns the entropy sources available to the Snap.
|
|
105
|
-
*
|
|
106
|
-
* @returns The entropy sources available to the Snap.
|
|
107
|
-
*/
|
|
108
|
-
getEntropySources: () => EntropySource[];
|
|
109
88
|
/**
|
|
110
89
|
* A hook that returns a promise that resolves once the extension is unlocked.
|
|
111
90
|
*
|
|
@@ -113,12 +92,6 @@ export type PermittedMiddlewareHooks = {
|
|
|
113
92
|
* @returns A promise that resolves once the extension is unlocked.
|
|
114
93
|
*/
|
|
115
94
|
getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* A hook that returns whether the client is locked or not.
|
|
118
|
-
*
|
|
119
|
-
* @returns A boolean flag signaling whether the client is locked.
|
|
120
|
-
*/
|
|
121
|
-
getIsLocked: () => boolean;
|
|
122
95
|
/**
|
|
123
96
|
* A hook that returns whether the client is active or not.
|
|
124
97
|
*
|
|
@@ -131,85 +104,6 @@ export type PermittedMiddlewareHooks = {
|
|
|
131
104
|
* @returns A string that corresponds to the client version.
|
|
132
105
|
*/
|
|
133
106
|
getVersion: () => string;
|
|
134
|
-
/**
|
|
135
|
-
* A hook that returns the Snap's auxiliary file for the given path. This hook
|
|
136
|
-
* is bound to the Snap ID.
|
|
137
|
-
*
|
|
138
|
-
* @param path - The path of the auxiliary file to get.
|
|
139
|
-
* @param encoding - The encoding to use when returning the file.
|
|
140
|
-
* @returns The Snap's auxiliary file for the given path.
|
|
141
|
-
*/
|
|
142
|
-
getSnapFile: (path: string, encoding: AuxiliaryFileEncoding) => Promise<string | null>;
|
|
143
|
-
/**
|
|
144
|
-
* A hook that gets the state of the Snap. This hook is bound to the Snap ID.
|
|
145
|
-
*
|
|
146
|
-
* @param encrypted - Whether to get the encrypted or unencrypted state.
|
|
147
|
-
* @returns The current state of the Snap.
|
|
148
|
-
*/
|
|
149
|
-
getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;
|
|
150
|
-
/**
|
|
151
|
-
* A hook that updates the state of the Snap. This hook is bound to the Snap
|
|
152
|
-
* ID.
|
|
153
|
-
*
|
|
154
|
-
* @param newState - The new state.
|
|
155
|
-
* @param encrypted - Whether to update the encrypted or unencrypted state.
|
|
156
|
-
*/
|
|
157
|
-
updateSnapState: (newState: Record<string, Json>, encrypted: boolean) => Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* A hook that clears the state of the Snap. This hook is bound to the Snap
|
|
160
|
-
* ID.
|
|
161
|
-
*
|
|
162
|
-
* @param encrypted - Whether to clear the encrypted or unencrypted state.
|
|
163
|
-
*/
|
|
164
|
-
clearSnapState: (encrypted: boolean) => Promise<void>;
|
|
165
|
-
/**
|
|
166
|
-
* A hook that creates an interface for the Snap. This hook is bound to the
|
|
167
|
-
* Snap ID.
|
|
168
|
-
*
|
|
169
|
-
* @param content - The content of the interface.
|
|
170
|
-
* @param context - The context of the interface.
|
|
171
|
-
* @returns The ID of the created interface.
|
|
172
|
-
*/
|
|
173
|
-
createInterface: (content: Component, context?: InterfaceContext) => string;
|
|
174
|
-
/**
|
|
175
|
-
* A hook that updates an interface for the Snap. This hook is bound to the
|
|
176
|
-
* Snap ID.
|
|
177
|
-
*
|
|
178
|
-
* @param id - The ID of the interface to update.
|
|
179
|
-
* @param content - The content of the interface.
|
|
180
|
-
*/
|
|
181
|
-
updateInterface: (id: string, content: Component) => void;
|
|
182
|
-
/**
|
|
183
|
-
* A hook that gets the state of an interface for the Snap. This hook is bound
|
|
184
|
-
* to the Snap ID.
|
|
185
|
-
*
|
|
186
|
-
* @param id - The ID of the interface to get.
|
|
187
|
-
* @returns The state of the interface.
|
|
188
|
-
*/
|
|
189
|
-
getInterfaceState: (id: string) => InterfaceState;
|
|
190
|
-
/**
|
|
191
|
-
* A hook that gets the context of an interface for the Snap. This hook is
|
|
192
|
-
* bound to the Snap ID.
|
|
193
|
-
*
|
|
194
|
-
* @param id - The ID of the interface to get.
|
|
195
|
-
* @returns The context of the interface.
|
|
196
|
-
*/
|
|
197
|
-
getInterfaceContext: (id: string) => InterfaceContext | null;
|
|
198
|
-
/**
|
|
199
|
-
* A hook that resolves an interface for the Snap. This hook is bound to the
|
|
200
|
-
* Snap ID.
|
|
201
|
-
*
|
|
202
|
-
* @param id - The ID of the interface to resolve.
|
|
203
|
-
* @param value - The value to resolve the interface with.
|
|
204
|
-
*/
|
|
205
|
-
resolveInterface: (id: string, value: Json) => Promise<void>;
|
|
206
|
-
/**
|
|
207
|
-
* A hook that gets the Snap's metadata.
|
|
208
|
-
*
|
|
209
|
-
* @param snapId - The ID of the Snap to get.
|
|
210
|
-
* @returns The Snap's metadata.
|
|
211
|
-
*/
|
|
212
|
-
getSnap(snapId: string): Snap;
|
|
213
107
|
/**
|
|
214
108
|
* A hook that tracks an error.
|
|
215
109
|
*
|
|
@@ -235,6 +129,12 @@ export type PermittedMiddlewareHooks = {
|
|
|
235
129
|
* @returns The trace data.
|
|
236
130
|
*/
|
|
237
131
|
endTrace(request: EndTraceRequest): void;
|
|
132
|
+
/**
|
|
133
|
+
* A hook that returns the allowed keyring methods.
|
|
134
|
+
*
|
|
135
|
+
* @returns The keyring methods.
|
|
136
|
+
*/
|
|
137
|
+
getAllowedKeyringMethods(): string[];
|
|
238
138
|
};
|
|
239
139
|
export type MultichainMiddlewareHooks = {
|
|
240
140
|
/**
|
|
@@ -292,13 +192,10 @@ export declare function getRestrictedHooks(options: SimulationOptions, store: St
|
|
|
292
192
|
/**
|
|
293
193
|
* Get the permitted hooks for the simulation.
|
|
294
194
|
*
|
|
295
|
-
* @param snapId - The ID of the Snap.
|
|
296
|
-
* @param snapFiles - The fetched Snap files.
|
|
297
|
-
* @param controllerMessenger - The controller messenger.
|
|
298
195
|
* @param runSaga - The run saga function.
|
|
299
196
|
* @returns The permitted hooks for the simulation.
|
|
300
197
|
*/
|
|
301
|
-
export declare function getPermittedHooks(
|
|
198
|
+
export declare function getPermittedHooks(runSaga: RunSagaFunction): PermittedMiddlewareHooks;
|
|
302
199
|
/**
|
|
303
200
|
* Get the hooks for the multichain middleware simulation.
|
|
304
201
|
*
|
|
@@ -308,6 +205,12 @@ export declare function getPermittedHooks(snapId: SnapId, snapFiles: FetchedSnap
|
|
|
308
205
|
* @returns The hooks for the middleware.
|
|
309
206
|
*/
|
|
310
207
|
export declare function getMultichainHooks(snapId: SnapId, options: SimulationOptions, controllerMessenger: RootControllerMessenger): MultichainMiddlewareHooks;
|
|
208
|
+
/**
|
|
209
|
+
* Get the mock mnemonic for a given source ID.
|
|
210
|
+
*
|
|
211
|
+
* @param options - The simulation options.
|
|
212
|
+
* @returns The mnemonic.
|
|
213
|
+
*/
|
|
311
214
|
/**
|
|
312
215
|
* Register mocked action handlers.
|
|
313
216
|
*
|
|
@@ -315,6 +218,7 @@ export declare function getMultichainHooks(snapId: SnapId, options: SimulationOp
|
|
|
315
218
|
* @param runSaga - The run saga function.
|
|
316
219
|
* @param options - The simulation options.
|
|
317
220
|
* @param snapId - The ID of the Snap.
|
|
221
|
+
* @param auxiliaryFiles - Auxiliary files from the fetched Snap.
|
|
318
222
|
*/
|
|
319
|
-
export declare function registerActions(controllerMessenger: RootControllerMessenger, runSaga: RunSagaFunction, options: SimulationOptions, snapId: SnapId): void;
|
|
223
|
+
export declare function registerActions(controllerMessenger: RootControllerMessenger, runSaga: RunSagaFunction, options: SimulationOptions, snapId: SnapId, auxiliaryFiles: VirtualFile[]): void;
|
|
320
224
|
//# sourceMappingURL=simulation.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation.d.cts","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;
|
|
1
|
+
{"version":3,"file":"simulation.d.cts","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAEjE,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAEf,cAAc,EACf,4BAA4B;AAC7B,OAAO,EAAsB,SAAS,EAAE,4BAA4B;AACpE,OAAO,EAEL,KAAK,MAAM,EACX,KAAK,oBAAoB,EAC1B,wCAAwC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,oCAAoC;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AAE,eAAe,EACxB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,WAAW,EAAE,QAwN9B"}
|
package/dist/simulation.d.mts
CHANGED
|
@@ -3,8 +3,8 @@ import type { ActionConstraint, EventConstraint, NamespacedName } from "@metamas
|
|
|
3
3
|
import { Messenger } from "@metamask/messenger";
|
|
4
4
|
import { type Caveat, type RequestedPermissions } from "@metamask/permission-controller";
|
|
5
5
|
import type { ExecutionService } from "@metamask/snaps-controllers";
|
|
6
|
-
import type { TrackEventParams,
|
|
7
|
-
import type {
|
|
6
|
+
import type { TrackEventParams, SnapId, TraceRequest, EndTraceRequest, TraceContext } from "@metamask/snaps-sdk";
|
|
7
|
+
import type { Snap, VirtualFile } from "@metamask/snaps-utils";
|
|
8
8
|
import type { Hex, Json } from "@metamask/utils";
|
|
9
9
|
import type { RootControllerMessenger } from "./controllers.mjs";
|
|
10
10
|
import type { SnapHelpers } from "./helpers.mjs";
|
|
@@ -48,17 +48,9 @@ export type RestrictedMiddlewareHooks = {
|
|
|
48
48
|
/**
|
|
49
49
|
* A hook that returns the user's secret recovery phrase.
|
|
50
50
|
*
|
|
51
|
-
* @param source - The entropy source to get the mnemonic from.
|
|
52
51
|
* @returns The user's secret recovery phrase.
|
|
53
52
|
*/
|
|
54
|
-
getMnemonic: (
|
|
55
|
-
/**
|
|
56
|
-
* A hook that returns the seed derived from the user's secret recovery phrase.
|
|
57
|
-
*
|
|
58
|
-
* @param source - The entropy source to get the seed from.
|
|
59
|
-
* @returns The seed.
|
|
60
|
-
*/
|
|
61
|
-
getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;
|
|
53
|
+
getMnemonic: () => Promise<Uint8Array>;
|
|
62
54
|
/**
|
|
63
55
|
* A hook that returns whether the client is locked or not.
|
|
64
56
|
*
|
|
@@ -93,19 +85,6 @@ export type RestrictedMiddlewareHooks = {
|
|
|
93
85
|
getSimulationState: () => ApplicationState;
|
|
94
86
|
};
|
|
95
87
|
export type PermittedMiddlewareHooks = {
|
|
96
|
-
/**
|
|
97
|
-
* A hook that gets whether the requesting origin has a given permission.
|
|
98
|
-
*
|
|
99
|
-
* @param permissionName - The name of the permission to check.
|
|
100
|
-
* @returns Whether the origin has the permission.
|
|
101
|
-
*/
|
|
102
|
-
hasPermission: (permissionName: string) => boolean;
|
|
103
|
-
/**
|
|
104
|
-
* A hook that returns the entropy sources available to the Snap.
|
|
105
|
-
*
|
|
106
|
-
* @returns The entropy sources available to the Snap.
|
|
107
|
-
*/
|
|
108
|
-
getEntropySources: () => EntropySource[];
|
|
109
88
|
/**
|
|
110
89
|
* A hook that returns a promise that resolves once the extension is unlocked.
|
|
111
90
|
*
|
|
@@ -113,12 +92,6 @@ export type PermittedMiddlewareHooks = {
|
|
|
113
92
|
* @returns A promise that resolves once the extension is unlocked.
|
|
114
93
|
*/
|
|
115
94
|
getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
|
|
116
|
-
/**
|
|
117
|
-
* A hook that returns whether the client is locked or not.
|
|
118
|
-
*
|
|
119
|
-
* @returns A boolean flag signaling whether the client is locked.
|
|
120
|
-
*/
|
|
121
|
-
getIsLocked: () => boolean;
|
|
122
95
|
/**
|
|
123
96
|
* A hook that returns whether the client is active or not.
|
|
124
97
|
*
|
|
@@ -131,85 +104,6 @@ export type PermittedMiddlewareHooks = {
|
|
|
131
104
|
* @returns A string that corresponds to the client version.
|
|
132
105
|
*/
|
|
133
106
|
getVersion: () => string;
|
|
134
|
-
/**
|
|
135
|
-
* A hook that returns the Snap's auxiliary file for the given path. This hook
|
|
136
|
-
* is bound to the Snap ID.
|
|
137
|
-
*
|
|
138
|
-
* @param path - The path of the auxiliary file to get.
|
|
139
|
-
* @param encoding - The encoding to use when returning the file.
|
|
140
|
-
* @returns The Snap's auxiliary file for the given path.
|
|
141
|
-
*/
|
|
142
|
-
getSnapFile: (path: string, encoding: AuxiliaryFileEncoding) => Promise<string | null>;
|
|
143
|
-
/**
|
|
144
|
-
* A hook that gets the state of the Snap. This hook is bound to the Snap ID.
|
|
145
|
-
*
|
|
146
|
-
* @param encrypted - Whether to get the encrypted or unencrypted state.
|
|
147
|
-
* @returns The current state of the Snap.
|
|
148
|
-
*/
|
|
149
|
-
getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;
|
|
150
|
-
/**
|
|
151
|
-
* A hook that updates the state of the Snap. This hook is bound to the Snap
|
|
152
|
-
* ID.
|
|
153
|
-
*
|
|
154
|
-
* @param newState - The new state.
|
|
155
|
-
* @param encrypted - Whether to update the encrypted or unencrypted state.
|
|
156
|
-
*/
|
|
157
|
-
updateSnapState: (newState: Record<string, Json>, encrypted: boolean) => Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* A hook that clears the state of the Snap. This hook is bound to the Snap
|
|
160
|
-
* ID.
|
|
161
|
-
*
|
|
162
|
-
* @param encrypted - Whether to clear the encrypted or unencrypted state.
|
|
163
|
-
*/
|
|
164
|
-
clearSnapState: (encrypted: boolean) => Promise<void>;
|
|
165
|
-
/**
|
|
166
|
-
* A hook that creates an interface for the Snap. This hook is bound to the
|
|
167
|
-
* Snap ID.
|
|
168
|
-
*
|
|
169
|
-
* @param content - The content of the interface.
|
|
170
|
-
* @param context - The context of the interface.
|
|
171
|
-
* @returns The ID of the created interface.
|
|
172
|
-
*/
|
|
173
|
-
createInterface: (content: Component, context?: InterfaceContext) => string;
|
|
174
|
-
/**
|
|
175
|
-
* A hook that updates an interface for the Snap. This hook is bound to the
|
|
176
|
-
* Snap ID.
|
|
177
|
-
*
|
|
178
|
-
* @param id - The ID of the interface to update.
|
|
179
|
-
* @param content - The content of the interface.
|
|
180
|
-
*/
|
|
181
|
-
updateInterface: (id: string, content: Component) => void;
|
|
182
|
-
/**
|
|
183
|
-
* A hook that gets the state of an interface for the Snap. This hook is bound
|
|
184
|
-
* to the Snap ID.
|
|
185
|
-
*
|
|
186
|
-
* @param id - The ID of the interface to get.
|
|
187
|
-
* @returns The state of the interface.
|
|
188
|
-
*/
|
|
189
|
-
getInterfaceState: (id: string) => InterfaceState;
|
|
190
|
-
/**
|
|
191
|
-
* A hook that gets the context of an interface for the Snap. This hook is
|
|
192
|
-
* bound to the Snap ID.
|
|
193
|
-
*
|
|
194
|
-
* @param id - The ID of the interface to get.
|
|
195
|
-
* @returns The context of the interface.
|
|
196
|
-
*/
|
|
197
|
-
getInterfaceContext: (id: string) => InterfaceContext | null;
|
|
198
|
-
/**
|
|
199
|
-
* A hook that resolves an interface for the Snap. This hook is bound to the
|
|
200
|
-
* Snap ID.
|
|
201
|
-
*
|
|
202
|
-
* @param id - The ID of the interface to resolve.
|
|
203
|
-
* @param value - The value to resolve the interface with.
|
|
204
|
-
*/
|
|
205
|
-
resolveInterface: (id: string, value: Json) => Promise<void>;
|
|
206
|
-
/**
|
|
207
|
-
* A hook that gets the Snap's metadata.
|
|
208
|
-
*
|
|
209
|
-
* @param snapId - The ID of the Snap to get.
|
|
210
|
-
* @returns The Snap's metadata.
|
|
211
|
-
*/
|
|
212
|
-
getSnap(snapId: string): Snap;
|
|
213
107
|
/**
|
|
214
108
|
* A hook that tracks an error.
|
|
215
109
|
*
|
|
@@ -235,6 +129,12 @@ export type PermittedMiddlewareHooks = {
|
|
|
235
129
|
* @returns The trace data.
|
|
236
130
|
*/
|
|
237
131
|
endTrace(request: EndTraceRequest): void;
|
|
132
|
+
/**
|
|
133
|
+
* A hook that returns the allowed keyring methods.
|
|
134
|
+
*
|
|
135
|
+
* @returns The keyring methods.
|
|
136
|
+
*/
|
|
137
|
+
getAllowedKeyringMethods(): string[];
|
|
238
138
|
};
|
|
239
139
|
export type MultichainMiddlewareHooks = {
|
|
240
140
|
/**
|
|
@@ -292,13 +192,10 @@ export declare function getRestrictedHooks(options: SimulationOptions, store: St
|
|
|
292
192
|
/**
|
|
293
193
|
* Get the permitted hooks for the simulation.
|
|
294
194
|
*
|
|
295
|
-
* @param snapId - The ID of the Snap.
|
|
296
|
-
* @param snapFiles - The fetched Snap files.
|
|
297
|
-
* @param controllerMessenger - The controller messenger.
|
|
298
195
|
* @param runSaga - The run saga function.
|
|
299
196
|
* @returns The permitted hooks for the simulation.
|
|
300
197
|
*/
|
|
301
|
-
export declare function getPermittedHooks(
|
|
198
|
+
export declare function getPermittedHooks(runSaga: RunSagaFunction): PermittedMiddlewareHooks;
|
|
302
199
|
/**
|
|
303
200
|
* Get the hooks for the multichain middleware simulation.
|
|
304
201
|
*
|
|
@@ -308,6 +205,12 @@ export declare function getPermittedHooks(snapId: SnapId, snapFiles: FetchedSnap
|
|
|
308
205
|
* @returns The hooks for the middleware.
|
|
309
206
|
*/
|
|
310
207
|
export declare function getMultichainHooks(snapId: SnapId, options: SimulationOptions, controllerMessenger: RootControllerMessenger): MultichainMiddlewareHooks;
|
|
208
|
+
/**
|
|
209
|
+
* Get the mock mnemonic for a given source ID.
|
|
210
|
+
*
|
|
211
|
+
* @param options - The simulation options.
|
|
212
|
+
* @returns The mnemonic.
|
|
213
|
+
*/
|
|
311
214
|
/**
|
|
312
215
|
* Register mocked action handlers.
|
|
313
216
|
*
|
|
@@ -315,6 +218,7 @@ export declare function getMultichainHooks(snapId: SnapId, options: SimulationOp
|
|
|
315
218
|
* @param runSaga - The run saga function.
|
|
316
219
|
* @param options - The simulation options.
|
|
317
220
|
* @param snapId - The ID of the Snap.
|
|
221
|
+
* @param auxiliaryFiles - Auxiliary files from the fetched Snap.
|
|
318
222
|
*/
|
|
319
|
-
export declare function registerActions(controllerMessenger: RootControllerMessenger, runSaga: RunSagaFunction, options: SimulationOptions, snapId: SnapId): void;
|
|
223
|
+
export declare function registerActions(controllerMessenger: RootControllerMessenger, runSaga: RunSagaFunction, options: SimulationOptions, snapId: SnapId, auxiliaryFiles: VirtualFile[]): void;
|
|
320
224
|
//# sourceMappingURL=simulation.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulation.d.mts","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK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AAK,EACZ,OAAO,EAAE,eAAe,GACvB,yBAAyB,CAS3B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,eAAe,GACvB,wBAAwB,CAa1B;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iBAAiB,EAC1B,mBAAmB,EAAE,uBAAuB,GAC3C,yBAAyB,CAuC3B;AAED;;;;;GAKG;AACH;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,mBAAmB,EAAE,uBAAuB,EAC5C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,WAAW,EAAE,QAwN9B"}
|
package/dist/simulation.mjs
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { createEngineStream } from "@metamask/json-rpc-middleware-stream";
|
|
2
|
+
import { mnemonicToSeed } from "@metamask/key-tree";
|
|
2
3
|
import { MOCK_ANY_NAMESPACE, Messenger } from "@metamask/messenger";
|
|
3
4
|
import { PermissionDoesNotExistError } from "@metamask/permission-controller";
|
|
4
5
|
import { detectSnapLocation, fetchSnap, NodeThreadExecutionService, setupMultiplex } from "@metamask/snaps-controllers/node";
|
|
5
6
|
import { DIALOG_APPROVAL_TYPES } from "@metamask/snaps-rpc-methods";
|
|
6
7
|
import { logError } from "@metamask/snaps-utils";
|
|
8
|
+
import { assertExhaustive, hasProperty } from "@metamask/utils";
|
|
7
9
|
import { pipeline } from "readable-stream";
|
|
8
10
|
import { select } from "redux-saga/effects";
|
|
9
11
|
import { getControllers, registerSnap } from "./controllers.mjs";
|
|
@@ -11,8 +13,7 @@ import { getSnapFile } from "./files.mjs";
|
|
|
11
13
|
import { getHelpers } from "./helpers.mjs";
|
|
12
14
|
import { resolveWithSaga } from "./interface.mjs";
|
|
13
15
|
import { asyncResolve, getEndowments } from "./methods/index.mjs";
|
|
14
|
-
import {
|
|
15
|
-
import { getGetMnemonicSeedImplementation } from "./methods/hooks/get-mnemonic-seed.mjs";
|
|
16
|
+
import { getGetMnemonicImplementation, getGetSnapImplementation, getTrackEventImplementation, getTrackErrorImplementation, getEndTraceImplementation, getStartTraceImplementation, getSetCurrentChainImplementation, getClearSnapStateMethodImplementation, getGetSnapStateMethodImplementation, getUpdateSnapStateMethodImplementation, getRequestUserApprovalImplementation, getShowInAppNotificationImplementation, getShowNativeNotificationImplementation } from "./methods/hooks/index.mjs";
|
|
16
17
|
import { createJsonRpcEngine } from "./middleware/index.mjs";
|
|
17
18
|
import { getOptions } from "./options.mjs";
|
|
18
19
|
import { createStore, getCurrentInterface } from "./store/index.mjs";
|
|
@@ -44,10 +45,10 @@ export async function installSnap(snapId, { executionService, executionServiceOp
|
|
|
44
45
|
const controllerMessenger = new Messenger({
|
|
45
46
|
namespace: MOCK_ANY_NAMESPACE,
|
|
46
47
|
});
|
|
47
|
-
registerActions(controllerMessenger, runSaga, options, snapId);
|
|
48
|
+
registerActions(controllerMessenger, runSaga, options, snapId, snapFiles.auxiliaryFiles);
|
|
48
49
|
// Set up controllers and JSON-RPC stack.
|
|
49
50
|
const restrictedHooks = getRestrictedHooks(options, store, runSaga);
|
|
50
|
-
const permittedHooks = getPermittedHooks(
|
|
51
|
+
const permittedHooks = getPermittedHooks(runSaga);
|
|
51
52
|
const multichainHooks = getMultichainHooks(snapId, options, controllerMessenger);
|
|
52
53
|
const { subjectMetadataController, permissionController } = getControllers({
|
|
53
54
|
controllerMessenger,
|
|
@@ -55,22 +56,21 @@ export async function installSnap(snapId, { executionService, executionServiceOp
|
|
|
55
56
|
runSaga,
|
|
56
57
|
options,
|
|
57
58
|
});
|
|
58
|
-
const permissionMiddleware = permissionController.createPermissionMiddleware({
|
|
59
|
-
origin: snapId,
|
|
60
|
-
});
|
|
61
59
|
const engine = createJsonRpcEngine({
|
|
60
|
+
snapId,
|
|
61
|
+
messenger: controllerMessenger,
|
|
62
62
|
store,
|
|
63
63
|
restrictedHooks,
|
|
64
64
|
permittedHooks,
|
|
65
|
-
permissionMiddleware,
|
|
66
65
|
multichainHooks,
|
|
67
66
|
isMultichain: false,
|
|
68
67
|
});
|
|
69
68
|
const multichainEngine = createJsonRpcEngine({
|
|
69
|
+
snapId,
|
|
70
|
+
messenger: controllerMessenger,
|
|
70
71
|
store,
|
|
71
72
|
restrictedHooks,
|
|
72
73
|
permittedHooks,
|
|
73
|
-
permissionMiddleware,
|
|
74
74
|
multichainHooks,
|
|
75
75
|
isMultichain: true,
|
|
76
76
|
});
|
|
@@ -145,7 +145,6 @@ export async function installSnap(snapId, { executionService, executionServiceOp
|
|
|
145
145
|
export function getRestrictedHooks(options, store, runSaga) {
|
|
146
146
|
return {
|
|
147
147
|
getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),
|
|
148
|
-
getMnemonicSeed: getGetMnemonicSeedImplementation(options.secretRecoveryPhrase),
|
|
149
148
|
getIsLocked: () => false,
|
|
150
149
|
getClientCryptography: () => ({}),
|
|
151
150
|
getSnap: getGetSnapImplementation(true),
|
|
@@ -156,30 +155,15 @@ export function getRestrictedHooks(options, store, runSaga) {
|
|
|
156
155
|
/**
|
|
157
156
|
* Get the permitted hooks for the simulation.
|
|
158
157
|
*
|
|
159
|
-
* @param snapId - The ID of the Snap.
|
|
160
|
-
* @param snapFiles - The fetched Snap files.
|
|
161
|
-
* @param controllerMessenger - The controller messenger.
|
|
162
158
|
* @param runSaga - The run saga function.
|
|
163
159
|
* @returns The permitted hooks for the simulation.
|
|
164
160
|
*/
|
|
165
|
-
export function getPermittedHooks(
|
|
161
|
+
export function getPermittedHooks(runSaga) {
|
|
166
162
|
return {
|
|
167
|
-
hasPermission: () => true,
|
|
168
163
|
getUnlockPromise: asyncResolve(),
|
|
169
|
-
getIsLocked: () => false,
|
|
170
164
|
getIsActive: () => true,
|
|
171
165
|
getVersion: () => '13.6.0-flask.0',
|
|
172
|
-
|
|
173
|
-
createInterface: (...args) => controllerMessenger.call('SnapInterfaceController:createInterface', snapId, ...args),
|
|
174
|
-
updateInterface: (...args) => controllerMessenger.call('SnapInterfaceController:updateInterface', snapId, ...args),
|
|
175
|
-
getInterfaceState: (...args) => controllerMessenger.call('SnapInterfaceController:getInterfaceState', snapId, ...args),
|
|
176
|
-
getInterfaceContext: (...args) => controllerMessenger.call('SnapInterfaceController:getInterface', snapId, ...args).context,
|
|
177
|
-
resolveInterface: async (...args) => controllerMessenger.call('SnapInterfaceController:resolveInterface', snapId, ...args),
|
|
178
|
-
getEntropySources: getGetEntropySourcesImplementation(),
|
|
179
|
-
getSnapState: getPermittedGetSnapStateMethodImplementation(runSaga),
|
|
180
|
-
updateSnapState: getPermittedUpdateSnapStateMethodImplementation(runSaga),
|
|
181
|
-
clearSnapState: getPermittedClearSnapStateMethodImplementation(runSaga),
|
|
182
|
-
getSnap: getGetSnapImplementation(true),
|
|
166
|
+
getAllowedKeyringMethods: () => [],
|
|
183
167
|
trackError: getTrackErrorImplementation(runSaga),
|
|
184
168
|
trackEvent: getTrackEventImplementation(runSaga),
|
|
185
169
|
startTrace: getStartTraceImplementation(runSaga),
|
|
@@ -231,6 +215,12 @@ export function getMultichainHooks(snapId, options, controllerMessenger) {
|
|
|
231
215
|
},
|
|
232
216
|
};
|
|
233
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Get the mock mnemonic for a given source ID.
|
|
220
|
+
*
|
|
221
|
+
* @param options - The simulation options.
|
|
222
|
+
* @returns The mnemonic.
|
|
223
|
+
*/
|
|
234
224
|
/**
|
|
235
225
|
* Register mocked action handlers.
|
|
236
226
|
*
|
|
@@ -238,8 +228,9 @@ export function getMultichainHooks(snapId, options, controllerMessenger) {
|
|
|
238
228
|
* @param runSaga - The run saga function.
|
|
239
229
|
* @param options - The simulation options.
|
|
240
230
|
* @param snapId - The ID of the Snap.
|
|
231
|
+
* @param auxiliaryFiles - Auxiliary files from the fetched Snap.
|
|
241
232
|
*/
|
|
242
|
-
export function registerActions(controllerMessenger, runSaga, options, snapId) {
|
|
233
|
+
export function registerActions(controllerMessenger, runSaga, options, snapId, auxiliaryFiles) {
|
|
243
234
|
controllerMessenger.registerActionHandler('PhishingController:testOrigin', () => ({ result: false, type: 'all' }));
|
|
244
235
|
controllerMessenger.registerActionHandler('AccountsController:getAccountByAddress',
|
|
245
236
|
// @ts-expect-error - This is a partial account with only the necessary
|
|
@@ -293,5 +284,69 @@ export function registerActions(controllerMessenger, runSaga, options, snapId) {
|
|
|
293
284
|
await runSaga(resolveWithSaga, value).toPromise();
|
|
294
285
|
return { value };
|
|
295
286
|
});
|
|
287
|
+
controllerMessenger.registerActionHandler('ApprovalController:addRequest',
|
|
288
|
+
// @ts-expect-error Types of property 'requestData' are incompatible.
|
|
289
|
+
getRequestUserApprovalImplementation(runSaga));
|
|
290
|
+
controllerMessenger.registerActionHandler('SnapController:getSnap', getGetSnapImplementation(true));
|
|
291
|
+
controllerMessenger.registerActionHandler('SnapController:getSnapState', getGetSnapStateMethodImplementation(runSaga));
|
|
292
|
+
controllerMessenger.registerActionHandler('SnapController:updateSnapState', getUpdateSnapStateMethodImplementation(runSaga));
|
|
293
|
+
controllerMessenger.registerActionHandler('SnapController:clearSnapState', getClearSnapStateMethodImplementation(runSaga));
|
|
294
|
+
controllerMessenger.registerActionHandler('SnapController:getSnapFile', async (_snapId, path, encoding) => getSnapFile(auxiliaryFiles, path, encoding));
|
|
295
|
+
const showNativeNotification = getShowNativeNotificationImplementation(runSaga);
|
|
296
|
+
const showInAppNotification = getShowInAppNotificationImplementation(runSaga);
|
|
297
|
+
controllerMessenger.registerActionHandler(
|
|
298
|
+
// @ts-expect-error - `RateLimitController` is not part of the simulation messenger types.
|
|
299
|
+
'RateLimitController:call', async (_origin, type, ...args) => {
|
|
300
|
+
switch (type) {
|
|
301
|
+
case 'showNativeNotification':
|
|
302
|
+
return await showNativeNotification(args[0], {
|
|
303
|
+
type: 'native',
|
|
304
|
+
message: args[1],
|
|
305
|
+
});
|
|
306
|
+
case 'showInAppNotification':
|
|
307
|
+
return await showInAppNotification(args[0], args[1]);
|
|
308
|
+
/* istanbul ignore next */
|
|
309
|
+
default:
|
|
310
|
+
return assertExhaustive(type);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
const getMnemonic = getGetMnemonicImplementation(options.secretRecoveryPhrase);
|
|
314
|
+
controllerMessenger.registerActionHandler(
|
|
315
|
+
// @ts-expect-error - `KeyringController` is not part of the simulation messenger types.
|
|
316
|
+
'KeyringController:getState', () => ({
|
|
317
|
+
isUnlocked: true,
|
|
318
|
+
keyrings: [
|
|
319
|
+
{
|
|
320
|
+
type: 'HD Key Tree',
|
|
321
|
+
metadata: {
|
|
322
|
+
id: 'default',
|
|
323
|
+
name: 'Default Secret Recovery Phrase',
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
type: 'HD Key Tree',
|
|
328
|
+
metadata: {
|
|
329
|
+
id: 'alternative',
|
|
330
|
+
name: 'Alternative Secret Recovery Phrase',
|
|
331
|
+
},
|
|
332
|
+
},
|
|
333
|
+
],
|
|
334
|
+
}));
|
|
335
|
+
controllerMessenger.registerActionHandler(
|
|
336
|
+
// @ts-expect-error - `KeyringController` is not part of the simulation messenger types.
|
|
337
|
+
'KeyringController:withKeyringV2Unsafe', async (selector, operation) => {
|
|
338
|
+
const source = hasProperty(selector, 'id')
|
|
339
|
+
? selector.id
|
|
340
|
+
: undefined;
|
|
341
|
+
const mnemonic = await getMnemonic(source);
|
|
342
|
+
const seed = await mnemonicToSeed(mnemonic);
|
|
343
|
+
return await operation({
|
|
344
|
+
keyring: {
|
|
345
|
+
type: 'hd',
|
|
346
|
+
mnemonic,
|
|
347
|
+
seed,
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
});
|
|
296
351
|
}
|
|
297
352
|
//# sourceMappingURL=simulation.mjs.map
|