@metamask/snaps-controllers 0.25.0 → 0.26.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.
@@ -1,12 +1,13 @@
1
1
  import { AddApprovalRequest } from '@metamask/approval-controller';
2
2
  import { BaseControllerV2 as BaseController, RestrictedControllerMessenger } from '@metamask/base-controller';
3
3
  import { GetEndowments, GetPermissions, GrantPermissions, HasPermission, HasPermissions, RevokeAllPermissions, RevokePermissionForAllSubjects, RevokePermissions } from '@metamask/permission-controller';
4
- import { BlockedSnapInfo, InstallSnapsResult, PersistedSnap, RequestedSnapPermissions, Snap, SnapId, SnapManifest, SnapRpcHook, SnapRpcHookArgs, SnapStatusEvents, StatusContext, StatusEvents, StatusStates, TruncatedSnap, ValidatedSnapId } from '@metamask/snaps-utils';
4
+ import { BlockedSnapInfo, InstallSnapsResult, PersistedSnap, RequestedSnapPermissions, Snap, SnapId, SnapRpcHook, SnapRpcHookArgs, SnapStatusEvents, StatusContext, StatusEvents, StatusStates, TruncatedSnap, ValidatedSnapId } from '@metamask/snaps-utils';
5
5
  import { GetSubjectMetadata } from '@metamask/subject-metadata-controller';
6
6
  import { Json } from '@metamask/utils';
7
7
  import { StateMachine } from '@xstate/fsm';
8
8
  import type { Patch } from 'immer';
9
9
  import { ExecuteSnapAction, ExecutionServiceEvents, HandleRpcRequestAction, SnapErrorJson, TerminateAllSnapsAction, TerminateSnapAction } from '../services';
10
+ import { detectSnapLocation, SnapLocation } from './location';
10
11
  import { Timer } from './Timer';
11
12
  export declare const controllerName = "SnapController";
12
13
  export declare const SNAP_APPROVAL_INSTALL = "wallet_installSnap";
@@ -67,23 +68,6 @@ export declare type SnapError = {
67
68
  code: number;
68
69
  data?: Json;
69
70
  };
70
- /**
71
- * The return type of {@link SnapController.fetchSnap} and its sibling methods.
72
- */
73
- declare type FetchSnapResult = {
74
- /**
75
- * The manifest of the fetched Snap.
76
- */
77
- manifest: SnapManifest;
78
- /**
79
- * The source code of the fetched Snap.
80
- */
81
- sourceCode: string;
82
- /**
83
- * The raw XML content of the Snap's SVG icon, if any.
84
- */
85
- svgIcon?: string;
86
- };
87
71
  declare type CloseAllConnectionsFunction = (origin: string) => void;
88
72
  declare type StoredSnaps = Record<SnapId, Snap>;
89
73
  export declare type SnapControllerState = {
@@ -232,6 +216,13 @@ export declare type SnapUpdated = {
232
216
  type: `${typeof controllerName}:snapUpdated`;
233
217
  payload: [snap: TruncatedSnap, oldVersion: string];
234
218
  };
219
+ /**
220
+ * Emitted when a snap is rolled back.
221
+ */
222
+ export declare type SnapRolledback = {
223
+ type: `${typeof controllerName}:snapRolledback`;
224
+ payload: [snap: TruncatedSnap, failedVersion: string];
225
+ };
235
226
  /**
236
227
  * Emitted when a Snap is terminated. This is different from the snap being
237
228
  * stopped as it can also be triggered when a snap fails initialization.
@@ -240,7 +231,7 @@ export declare type SnapTerminated = {
240
231
  type: `${typeof controllerName}:snapTerminated`;
241
232
  payload: [snap: TruncatedSnap];
242
233
  };
243
- export declare type SnapControllerEvents = SnapAdded | SnapBlocked | SnapInstalled | SnapRemoved | SnapStateChange | SnapUnblocked | SnapUpdated | SnapTerminated;
234
+ export declare type SnapControllerEvents = SnapAdded | SnapBlocked | SnapInstalled | SnapRemoved | SnapStateChange | SnapUnblocked | SnapUpdated | SnapRolledback | SnapTerminated;
244
235
  export declare type AllowedActions = GetEndowments | GetPermissions | GetSubjectMetadata | HasPermission | HasPermissions | RevokePermissions | RevokeAllPermissions | RevokePermissionForAllSubjects | GrantPermissions | AddApprovalRequest | HandleRpcRequestAction | ExecuteSnapAction | TerminateAllSnapsAction | TerminateSnapAction;
245
236
  export declare type AllowedEvents = ExecutionServiceEvents;
246
237
  declare type SnapControllerMessenger = RestrictedControllerMessenger<typeof controllerName, SnapControllerActions | AllowedActions, SnapControllerEvents | AllowedEvents, AllowedActions['type'], AllowedEvents['type']>;
@@ -329,12 +320,18 @@ declare type SnapControllerArgs = {
329
320
  * Persisted state that will be used for rehydration.
330
321
  */
331
322
  state?: PersistedSnapControllerState;
323
+ /**
324
+ * A function that takes Snap Id and converts it into a class that fetches files.
325
+ *
326
+ * Used for test overrides.
327
+ */
328
+ detectSnapLocation?: typeof detectSnapLocation;
332
329
  };
333
330
  export declare class SnapController extends BaseController<string, SnapControllerState, SnapControllerMessenger> {
334
331
  #private;
335
332
  private readonly maxRequestTime;
336
333
  private readonly snapsRuntimeData;
337
- constructor({ closeAllConnections, messenger, state, getAppKey, environmentEndowmentPermissions, npmRegistryUrl, idleTimeCheckInterval, checkBlockList, maxIdleTime, maxRequestTime, fetchFunction, featureFlags, }: SnapControllerArgs);
334
+ constructor({ closeAllConnections, messenger, state, getAppKey, environmentEndowmentPermissions, npmRegistryUrl, idleTimeCheckInterval, checkBlockList, maxIdleTime, maxRequestTime, fetchFunction, featureFlags, detectSnapLocation: detectSnapLocationFunction, }: SnapControllerArgs);
338
335
  /**
339
336
  * Checks all installed snaps against the block list and
340
337
  * blocks/unblocks snaps as appropriate. See {@link SnapController.blockSnap}
@@ -560,19 +557,10 @@ export declare class SnapController extends BaseController<string, SnapControlle
560
557
  * @param origin - The origin requesting the snap update.
561
558
  * @param snapId - The id of the Snap to be updated.
562
559
  * @param newVersionRange - A semver version range in which the maximum version will be chosen.
560
+ * @param location - Optional location that was already used during installation flow.
563
561
  * @returns The snap metadata if updated, `null` otherwise.
564
562
  */
565
- updateSnap(origin: string, snapId: ValidatedSnapId, newVersionRange?: string): Promise<TruncatedSnap | null>;
566
- /**
567
- * Fetches the manifest and source code of a snap.
568
- *
569
- * This function is not hash private yet because of tests.
570
- *
571
- * @param snapId - The id of the Snap.
572
- * @param versionRange - The SemVer version of the Snap to fetch.
573
- * @returns A tuple of the Snap manifest object and the Snap source code.
574
- */
575
- fetchSnap(snapId: ValidatedSnapId, versionRange?: string): Promise<FetchSnapResult>;
563
+ updateSnap(origin: string, snapId: ValidatedSnapId, newVersionRange?: string, location?: SnapLocation): Promise<TruncatedSnap | null>;
576
564
  /**
577
565
  * Initiates a request for the given snap's initial permissions.
578
566
  * Must be called in order. See processRequestedSnap.