Skip to content

Commit

Permalink
chore: Bump Snaps packages (#26086)
Browse files Browse the repository at this point in the history
## **Description**

This bumps all Snaps packages to the latest versions and handles
breaking changes. It also introduces some new components and RPC
methods.

Summary of changes in the snaps deps:
- Add new `snap_dialog` confirmation type that uses fully custom UI
- Add `Container` and `Footer` component
- Add `RadioGroup` component
- Add `Card` component
- Add `snap_getPreferences` to return user preferences
- Add `snap_resolveInterface` to resolve existing interfaces
- Handle initial connections for preinstalled Snaps
- Enforce stricter size limits for source code, static auxiliary files,
and `snap_getFile` return values
- Account for revoked origins when calculating the difference in
`initialConnections`


Closes MetaMask/MetaMask-planning#1571
Closes MetaMask/MetaMask-planning#2125
Closes MetaMask/snaps#2622
Closes MetaMask/MetaMask-planning#1956

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26086?quickstart=1)

---------

Co-authored-by: Frederik Bolding <[email protected]>
Co-authored-by: David Drazic <[email protected]>
Co-authored-by: Guillaume Roux <[email protected]>
  • Loading branch information
4 people authored Aug 15, 2024
1 parent df95e54 commit f461e37
Show file tree
Hide file tree
Showing 55 changed files with 2,274 additions and 520 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/package.json b/package.json
index 7e70a2db3606d673d92d38a2755e155bf2af5fd3..67cff443e63bd04e5699279d8101ef4ec547e9cb 100644
index 9464ffc2614c6c648051df5cb5c9c9b9e651a831..5b1bcb34b8167cf6bbc5b2854b1f196e0fa0204f 100644
--- a/package.json
+++ b/package.json
@@ -9,7 +9,7 @@
Expand Down
30 changes: 0 additions & 30 deletions .yarn/patches/@metamask-snaps-utils-npm-7.7.0-2cc1f044af.patch

This file was deleted.

8 changes: 8 additions & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ApprovalType } from '@metamask/controller-utils';
import PortStream from 'extension-port-stream';

import { ethErrors } from 'eth-rpc-errors';
import { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';
import {
ENVIRONMENT_TYPE_POPUP,
ENVIRONMENT_TYPE_NOTIFICATION,
Expand Down Expand Up @@ -1102,6 +1103,7 @@ export function setupController(
switch (type) {
case ApprovalType.SnapDialogAlert:
case ApprovalType.SnapDialogPrompt:
case DIALOG_APPROVAL_TYPES.default:
controller.approvalController.accept(id, null);
break;
case ApprovalType.SnapDialogConfirmation:
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/permissions/specifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ export const unrestrictedMethods = Object.freeze([
'snap_createInterface',
'snap_updateInterface',
'snap_getInterfaceState',
'snap_resolveInterface',
///: BEGIN:ONLY_INCLUDE_IF(build-mmi)
'metamaskinstitutional_authenticate',
'metamaskinstitutional_reauthenticate',
Expand Down
24 changes: 16 additions & 8 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ import { UI_NOTIFICATIONS } from '../../shared/notifications';
import { MILLISECOND, SECOND } from '../../shared/constants/time';
import {
ORIGIN_METAMASK,
SNAP_DIALOG_TYPES,
POLLING_TOKEN_ENVIRONMENT_TYPES,
} from '../../shared/constants/app';
import {
Expand Down Expand Up @@ -1409,6 +1408,8 @@ export default class MetamaskController extends EventEmitter {
allowedActions: [
`${this.phishingController.name}:maybeUpdateState`,
`${this.phishingController.name}:testOrigin`,
`${this.approvalController.name}:hasRequest`,
`${this.approvalController.name}:acceptRequest`,
],
});

Expand Down Expand Up @@ -2572,7 +2573,11 @@ export default class MetamaskController extends EventEmitter {
...buildSnapRestrictedMethodSpecifications(
Object.keys(ExcludedSnapPermissions),
{
getLocale: this.getLocale.bind(this),
getPreferences: () => {
const locale = this.getLocale();
const currency = this.currencyRateController.state.currentCurrency;
return { locale, currency };
},
clearSnapState: this.controllerMessenger.call.bind(
this.controllerMessenger,
'SnapController:clearSnapState',
Expand All @@ -2590,12 +2595,10 @@ export default class MetamaskController extends EventEmitter {
this.controllerMessenger,
'SnapController:getSnapState',
),
showDialog: (origin, type, id, placeholder) =>
this.approvalController.addAndShowApprovalRequest({
origin,
type: SNAP_DIALOG_TYPES[type],
requestData: { id, placeholder },
}),
requestUserApproval:
this.approvalController.addAndShowApprovalRequest.bind(
this.approvalController,
),
showNativeNotification: (origin, args) =>
this.controllerMessenger.call(
'RateLimitController:call',
Expand Down Expand Up @@ -5667,6 +5670,11 @@ export default class MetamaskController extends EventEmitter {
'SnapInterfaceController:updateInterface',
origin,
),
resolveInterface: this.controllerMessenger.call.bind(
this.controllerMessenger,
'SnapInterfaceController:resolveInterface',
origin,
),
getSnap: this.controllerMessenger.call.bind(
this.controllerMessenger,
'SnapController:get',
Expand Down
5 changes: 3 additions & 2 deletions app/scripts/snaps/preinstalled-snaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import MessageSigningSnap from '@metamask/message-signing-snap/dist/preinstalled
import BitcoinWalletSnap from '@metamask/bitcoin-wallet-snap/dist/preinstalled-snap.json';
///: END:ONLY_INCLUDE_IF

// The casts here are less than ideal but we expect the SnapController to validate the inputs.
const PREINSTALLED_SNAPS: readonly PreinstalledSnap[] = Object.freeze([
MessageSigningSnap as PreinstalledSnap,
MessageSigningSnap as unknown as PreinstalledSnap,
///: BEGIN:ONLY_INCLUDE_IF(build-flask)
BitcoinWalletSnap as PreinstalledSnap,
BitcoinWalletSnap as unknown as PreinstalledSnap,
///: END:ONLY_INCLUDE_IF
]);

Expand Down
8 changes: 4 additions & 4 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ buildTypes:
- SEGMENT_WRITE_KEY_REF: SEGMENT_PROD_WRITE_KEY
- ALLOW_LOCAL_SNAPS: false
- REQUIRE_SNAPS_ALLOWLIST: true
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.5.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.6.2/index.html
- ACCOUNT_SNAPS_DIRECTORY_URL: https://snaps.metamask.io/account-management
# Main build uses the default browser manifest
manifestOverrides: false
Expand All @@ -46,7 +46,7 @@ buildTypes:
- SEGMENT_WRITE_KEY_REF: SEGMENT_BETA_WRITE_KEY
- ALLOW_LOCAL_SNAPS: false
- REQUIRE_SNAPS_ALLOWLIST: true
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.5.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.6.2/index.html
- ACCOUNT_SNAPS_DIRECTORY_URL: https://snaps.metamask.io/account-management
# Modifies how the version is displayed.
# eg. instead of 10.25.0 -> 10.25.0-beta.2
Expand All @@ -67,7 +67,7 @@ buildTypes:
- SEGMENT_FLASK_WRITE_KEY
- ALLOW_LOCAL_SNAPS: true
- REQUIRE_SNAPS_ALLOWLIST: false
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.5.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.6.2/index.html
- SUPPORT_LINK: https://support.metamask.io/
- SUPPORT_REQUEST_LINK: https://support.metamask.io/
- INFURA_ENV_KEY_REF: INFURA_FLASK_PROJECT_ID
Expand All @@ -90,7 +90,7 @@ buildTypes:
- SEGMENT_WRITE_KEY_REF: SEGMENT_MMI_WRITE_KEY
- ALLOW_LOCAL_SNAPS: false
- REQUIRE_SNAPS_ALLOWLIST: true
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.5.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.6.2/index.html
- MMI_CONFIGURATION_SERVICE_URL: https://configuration.metamask-institutional.io/v2/configuration/default
- SUPPORT_LINK: https://mmi-support.metamask.io/hc/en-us
- SUPPORT_REQUEST_LINK: https://mmi-support.metamask.io/hc/en-us/requests/new
Expand Down
6 changes: 5 additions & 1 deletion development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,11 @@ function setupBundlerDefaults(
[
babelify,
{
only: ['./**/node_modules/firebase', './**/node_modules/@firebase'],
only: [
'./**/node_modules/firebase',
'./**/node_modules/@firebase',
'./**/node_modules/marked',
],
global: true,
},
],
Expand Down
Loading

0 comments on commit f461e37

Please sign in to comment.