Skip to content

Commit

Permalink
Move #validatePlatformVersion call to #assertIsInstallAllowed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Oct 22, 2024
1 parent 77ab66e commit 50b8f80
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,10 @@ export class SnapController extends BaseController<

async #assertIsInstallAllowed(
snapId: SnapId,
snapInfo: SnapsRegistryInfo & { permissions: SnapPermissions },
snapInfo: SnapsRegistryInfo & {
permissions: SnapPermissions;
platformVersion: string | undefined;
},
) {
const results = await this.messagingSystem.call('SnapsRegistry:get', {
[snapId]: snapInfo,
Expand Down Expand Up @@ -1370,6 +1373,8 @@ export class SnapController extends BaseController<
}`,
);
}

this.#validatePlatformVersion(snapId, snapInfo.platformVersion);
}

/**
Expand Down Expand Up @@ -2555,11 +2560,11 @@ export class SnapController extends BaseController<
);
}

this.#validatePlatformVersion(manifest);
await this.#assertIsInstallAllowed(snapId, {
version: newVersion,
checksum: manifest.source.shasum,
permissions: manifest.initialPermissions,
platformVersion: manifest.platformVersion,
});

const processedPermissions = processSnapPermissions(
Expand Down Expand Up @@ -2741,11 +2746,11 @@ export class SnapController extends BaseController<
);
}

this.#validatePlatformVersion(manifest);
await this.#assertIsInstallAllowed(snapId, {
version: manifest.version,
checksum: manifest.source.shasum,
permissions: manifest.initialPermissions,
platformVersion: manifest.platformVersion,
});

return this.#set({
Expand Down Expand Up @@ -3021,19 +3026,21 @@ export class SnapController extends BaseController<
* Validate that the platform version specified in the manifest (if any) is
* compatible with the current platform version.
*
* @param manifest - The Snap manifest.
* @param snapId - The ID of the Snap.
* @param platformVersion - The platform version to validate against.
* @throws If the platform version is greater than the current platform
* version.
*/
#validatePlatformVersion(manifest: SnapManifest) {
if (manifest.platformVersion === undefined) {
#validatePlatformVersion(
snapId: SnapId,
platformVersion: string | undefined,
) {
if (platformVersion === undefined) {
return;
}

if (semver.gt(manifest.platformVersion, getPlatformVersion())) {
const message = `The Snap requires platform version "${
manifest.platformVersion
}" which is greater than the current platform version "${getPlatformVersion()}".`;
if (semver.gt(platformVersion, getPlatformVersion())) {
const message = `The Snap "${snapId}" requires platform version "${platformVersion}" which is greater than the current platform version "${getPlatformVersion()}".`;

if (this.#featureFlags.rejectInvalidPlatformVersion) {
throw new Error(message);
Expand Down

0 comments on commit 50b8f80

Please sign in to comment.