diff --git a/packages/snaps-controllers/src/snaps/SnapController.ts b/packages/snaps-controllers/src/snaps/SnapController.ts index 0a547002f3..66ee3f7c80 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.ts @@ -1516,6 +1516,7 @@ export class SnapController extends BaseController< versionRange: resolvedVersion, fetch: this.#fetchFunction, allowLocal: false, + useNpmProxy: true, }); await this.#updateSnap({ diff --git a/packages/snaps-controllers/src/snaps/location/npm.ts b/packages/snaps-controllers/src/snaps/location/npm.ts index 237d35e58f..9aeedcfd0a 100644 --- a/packages/snaps-controllers/src/snaps/location/npm.ts +++ b/packages/snaps-controllers/src/snaps/location/npm.ts @@ -28,6 +28,8 @@ import type { DetectSnapLocationOptions, SnapLocation } from './location'; export const DEFAULT_NPM_REGISTRY = new URL('https://registry.npmjs.org'); +export const NPM_REGISTRY_PROXY = new URL('https://npm-ota.api.cx.metamask.io'); + type NpmMeta = { registry: URL; packageName: string; @@ -48,6 +50,12 @@ export type NpmOptions = { * @default false */ allowCustomRegistries?: boolean; + /** + * Whether to use a MetaMask-owned proxy when sending requests to NPM. + * + * @default false + */ + useNpmProxy?: boolean; }; // Base class for NPM implementation, useful for extending with custom NPM fetching logic @@ -74,7 +82,7 @@ export abstract class BaseNpmLocation implements SnapLocation { url.username === '' && url.password === '' ) { - registry = DEFAULT_NPM_REGISTRY; + registry = opts.useNpmProxy ? NPM_REGISTRY_PROXY : DEFAULT_NPM_REGISTRY; } else { registry = 'https://'; if (url.username) { @@ -341,7 +349,11 @@ export function getNpmCanonicalBasePath(registryUrl: URL, packageName: string) { * @returns True if the registry is the NPM registry, otherwise false. */ function isNPM(registryUrl: URL) { - return registryUrl.toString() === DEFAULT_NPM_REGISTRY.toString(); + const registryUrlString = registryUrl.toString(); + return ( + registryUrlString === DEFAULT_NPM_REGISTRY.toString() || + registryUrlString === NPM_REGISTRY_PROXY.toString() + ); } /**