Skip to content

Commit

Permalink
Merge branch 'develop' into rekmarks/reorder-permission-middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
legobeat committed May 29, 2024
2 parents 3175d64 + 038dbbb commit 782af6c
Show file tree
Hide file tree
Showing 47 changed files with 3,192 additions and 1,652 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ jobs:
GH_LABEL=team-mmi
if [ -z "$CIRCLE_PULL_REQUESTS" ]; then
echo "Skipping tag check; this is not a PR."
echo "false" > ./RUN_MMI_OPTIONAL
exit 0
fi
Expand Down
8 changes: 2 additions & 6 deletions app/_locales/en/messages.json

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

11 changes: 5 additions & 6 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import './lib/setup-initial-state-hooks';

import EventEmitter from 'events';
import endOfStream from 'end-of-stream';
import pump from 'pump';
import { finished, pipeline } from 'readable-stream';
import debounce from 'debounce-stream';
import log from 'loglevel';
import browser from 'webextension-polyfill';
Expand Down Expand Up @@ -580,7 +579,7 @@ export function setupController(
});

// setup state persistence
pump(
pipeline(
storeAsStream(controller.store),
debounce(1000),
createStreamSink(async (state) => {
Expand Down Expand Up @@ -683,7 +682,7 @@ export function setupController(

if (processName === ENVIRONMENT_TYPE_POPUP) {
openPopupCount += 1;
endOfStream(portStream, () => {
finished(portStream, () => {
openPopupCount -= 1;
const isClientOpen = isClientOpenStatus();
controller.isClientOpen = isClientOpen;
Expand All @@ -694,7 +693,7 @@ export function setupController(
if (processName === ENVIRONMENT_TYPE_NOTIFICATION) {
notificationIsOpen = true;

endOfStream(portStream, () => {
finished(portStream, () => {
notificationIsOpen = false;
const isClientOpen = isClientOpenStatus();
controller.isClientOpen = isClientOpen;
Expand All @@ -709,7 +708,7 @@ export function setupController(
const tabId = remotePort.sender.tab.id;
openMetamaskTabsIDs[tabId] = true;

endOfStream(portStream, () => {
finished(portStream, () => {
delete openMetamaskTabsIDs[tabId];
const isClientOpen = isClientOpenStatus();
controller.isClientOpen = isClientOpen;
Expand Down
58 changes: 33 additions & 25 deletions app/scripts/contentscript.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { WindowPostMessageStream } from '@metamask/post-message-stream';
import PortStream from 'extension-port-stream';
import ObjectMultiplex from '@metamask/object-multiplex';
import pump from 'pump';
import { obj as createThoughStream } from 'through2';
import { pipeline, Transform } from 'readable-stream';
import browser from 'webextension-polyfill';
import { EXTENSION_MESSAGES } from '../../shared/constants/app';
import {
Expand Down Expand Up @@ -70,7 +69,7 @@ function setupPhishingPageStreams() {
phishingPageMux = new ObjectMultiplex();
phishingPageMux.setMaxListeners(25);

pump(phishingPageMux, phishingPageStream, phishingPageMux, (err) =>
pipeline(phishingPageMux, phishingPageStream, phishingPageMux, (err) =>
logStreamDisconnectWarning('MetaMask Inpage Multiplex', err),
);

Expand All @@ -88,7 +87,7 @@ const setupPhishingExtStreams = () => {
phishingExtMux = new ObjectMultiplex();
phishingExtMux.setMaxListeners(25);

pump(phishingExtMux, phishingExtStream, phishingExtMux, (err) => {
pipeline(phishingExtMux, phishingExtStream, phishingExtMux, (err) => {
logStreamDisconnectWarning('MetaMask Background Multiplex', err);
window.postMessage(
{
Expand All @@ -108,11 +107,15 @@ const setupPhishingExtStreams = () => {

// forward communication across inpage-background for these channels only
phishingExtChannel = phishingExtMux.createStream(PHISHING_SAFELIST);
pump(phishingPageChannel, phishingExtChannel, phishingPageChannel, (error) =>
console.debug(
`MetaMask: Muxed traffic for channel "${PHISHING_SAFELIST}" failed.`,
error,
),
pipeline(
phishingPageChannel,
phishingExtChannel,
phishingPageChannel,
(error) =>
console.debug(
`MetaMask: Muxed traffic for channel "${PHISHING_SAFELIST}" failed.`,
error,
),
);

// eslint-disable-next-line no-use-before-define
Expand Down Expand Up @@ -206,7 +209,7 @@ const setupPageStreams = () => {
pageMux = new ObjectMultiplex();
pageMux.setMaxListeners(25);

pump(pageMux, pageStream, pageMux, (err) =>
pipeline(pageMux, pageStream, pageMux, (err) =>
logStreamDisconnectWarning('MetaMask Inpage Multiplex', err),
);

Expand All @@ -228,14 +231,14 @@ const setupExtensionStreams = () => {
extensionMux.setMaxListeners(25);
extensionMux.ignoreStream(LEGACY_PUBLIC_CONFIG); // TODO:LegacyProvider: Delete

pump(extensionMux, extensionStream, extensionMux, (err) => {
pipeline(extensionMux, extensionStream, extensionMux, (err) => {
logStreamDisconnectWarning('MetaMask Background Multiplex', err);
notifyInpageOfStreamFailure();
});

// forward communication across inpage-background for these channels only
extensionChannel = extensionMux.createStream(PROVIDER);
pump(pageChannel, extensionChannel, pageChannel, (error) =>
pipeline(pageChannel, extensionChannel, pageChannel, (error) =>
console.debug(
`MetaMask: Muxed traffic for channel "${PROVIDER}" failed.`,
error,
Expand Down Expand Up @@ -278,7 +281,7 @@ const setupLegacyPageStreams = () => {
legacyPageMux = new ObjectMultiplex();
legacyPageMux.setMaxListeners(25);

pump(legacyPageMux, legacyPageStream, legacyPageMux, (err) =>
pipeline(legacyPageMux, legacyPageStream, legacyPageMux, (err) =>
logStreamDisconnectWarning('MetaMask Legacy Inpage Multiplex', err),
);

Expand All @@ -294,7 +297,7 @@ const setupLegacyExtensionStreams = () => {
legacyExtMux.setMaxListeners(25);

notificationTransformStream = getNotificationTransformStream();
pump(
pipeline(
legacyExtMux,
extensionStream,
notificationTransformStream,
Expand All @@ -306,7 +309,7 @@ const setupLegacyExtensionStreams = () => {
);

legacyExtChannel = legacyExtMux.createStream(PROVIDER);
pump(
pipeline(
legacyPageMuxLegacyProviderChannel,
legacyExtChannel,
legacyPageMuxLegacyProviderChannel,
Expand All @@ -319,7 +322,7 @@ const setupLegacyExtensionStreams = () => {

legacyExtPublicConfigChannel =
legacyExtMux.createStream(LEGACY_PUBLIC_CONFIG);
pump(
pipeline(
legacyPagePublicConfigChannel,
legacyExtPublicConfigChannel,
legacyPagePublicConfigChannel,
Expand Down Expand Up @@ -412,16 +415,21 @@ const initStreams = () => {

// TODO:LegacyProvider: Delete
function getNotificationTransformStream() {
return createThoughStream((chunk, _, cb) => {
if (chunk?.name === PROVIDER) {
if (chunk.data?.method === 'metamask_accountsChanged') {
chunk.data.method = 'wallet_accountsChanged';
chunk.data.result = chunk.data.params;
delete chunk.data.params;
const stream = new Transform({
highWaterMark: 16,
objectMode: true,
transform: (chunk, _, cb) => {
if (chunk?.name === PROVIDER) {
if (chunk.data?.method === 'metamask_accountsChanged') {
chunk.data.method = 'wallet_accountsChanged';
chunk.data.result = chunk.data.params;
delete chunk.data.params;
}
}
}
cb(null, chunk);
cb(null, chunk);
},
});
return stream;
}

/**
Expand Down Expand Up @@ -470,7 +478,7 @@ function extensionStreamMessageListener(msg) {
}

/**
* This function must ONLY be called in pump destruction/close callbacks.
* This function must ONLY be called in pipeline destruction/close callbacks.
* Notifies the inpage context that streams have failed, via window.postMessage.
* Relies on @metamask/object-multiplex and post-message-stream implementation details.
*/
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/lib/stream-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ObjectMultiplex from '@metamask/object-multiplex';
import pump from 'pump';
import { pipeline } from 'readable-stream';

import { EXTENSION_MESSAGES } from '../../../shared/constants/app';

Expand All @@ -17,7 +17,7 @@ export function setupMultiplex(connectionStream) {
* https://github.com/MetaMask/object-multiplex/blob/280385401de84f57ef57054d92cfeb8361ef2680/src/ObjectMultiplex.ts#L63
*/
mux.ignoreStream(EXTENSION_MESSAGES.CONNECTION_READY);
pump(connectionStream, mux, connectionStream, (err) => {
pipeline(connectionStream, mux, connectionStream, (err) => {
if (err) {
console.error(err);
}
Expand Down
39 changes: 26 additions & 13 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EventEmitter from 'events';
import pump from 'pump';
import { pipeline } from 'readable-stream';
import {
AssetsContractController,
CurrencyRateController,
Expand Down Expand Up @@ -1295,6 +1295,13 @@ export default class MetamaskController extends EventEmitter {
encryptor: encryptorFactory(600_000),
getMnemonic: this.getPrimaryKeyringMnemonic.bind(this),
preinstalledSnaps: PREINSTALLED_SNAPS,
getFeatureFlags: () => {
return {
disableSnaps:
this.preferencesController.store.getState().useExternalServices ===
false,
};
},
});

this.notificationController = new NotificationController({
Expand Down Expand Up @@ -5008,18 +5015,24 @@ export default class MetamaskController extends EventEmitter {

const connectionId = this.addConnection(origin, { engine });

pump(outStream, dupeReqFilterStream, providerStream, outStream, (err) => {
// handle any middleware cleanup
engine._middleware.forEach((mid) => {
if (mid.destroy && typeof mid.destroy === 'function') {
mid.destroy();
pipeline(
outStream,
dupeReqFilterStream,
providerStream,
outStream,
(err) => {
// handle any middleware cleanup
engine._middleware.forEach((mid) => {
if (mid.destroy && typeof mid.destroy === 'function') {
mid.destroy();
}
});
connectionId && this.removeConnection(origin, connectionId);
if (err) {
log.error(err);
}
});
connectionId && this.removeConnection(origin, connectionId);
if (err) {
log.error(err);
}
});
},
);
}

///: BEGIN:ONLY_INCLUDE_IF(snaps)
Expand Down Expand Up @@ -5430,7 +5443,7 @@ export default class MetamaskController extends EventEmitter {
setupPublicConfig(outStream) {
const configStream = storeAsStream(this.publicConfigStore);

pump(configStream, outStream, (err) => {
pipeline(configStream, outStream, (err) => {
configStream.destroy();
if (err) {
log.error(err);
Expand Down
8 changes: 4 additions & 4 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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.1.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.2.0/index.html
- ACCOUNT_SNAPS_DIRECTORY_URL: https://snaps.metamask.io/account-management
# Main build uses the default browser manifest
manifestOverrides: false
Expand Down Expand Up @@ -64,7 +64,7 @@ buildTypes:
- SEGMENT_FLASK_WRITE_KEY
- ALLOW_LOCAL_SNAPS: true
- REQUIRE_SNAPS_ALLOWLIST: false
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.1.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.2.0/index.html
- SUPPORT_LINK: https://metamask-flask.zendesk.com/hc
- SUPPORT_REQUEST_LINK: https://metamask-flask.zendesk.com/hc/en-us/requests/new
- INFURA_ENV_KEY_REF: INFURA_FLASK_PROJECT_ID
Expand All @@ -86,7 +86,7 @@ buildTypes:
- SEGMENT_FLASK_WRITE_KEY
- ALLOW_LOCAL_SNAPS: true
- REQUIRE_SNAPS_ALLOWLIST: false
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.1.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.2.0/index.html
- SUPPORT_LINK: https://metamask-flask.zendesk.com/hc
- SUPPORT_REQUEST_LINK: https://metamask-flask.zendesk.com/hc/en-us/requests/new
- INFURA_ENV_KEY_REF: INFURA_FLASK_PROJECT_ID
Expand All @@ -109,7 +109,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.1.0/index.html
- IFRAME_EXECUTION_ENVIRONMENT_URL: https://execution.metamask.io/iframe/6.2.0/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
4 changes: 2 additions & 2 deletions development/build/etc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const sort = require('gulp-sort');
const gulpZip = require('gulp-zip');
const del = require('del');
const pify = require('pify');
const pump = pify(require('pump'));
const pipeline = pify(require('readable-stream').pipeline);

const { loadBuildTypesConfig } = require('../lib/build-type');
const { TASKS } = require('./constants');
Expand Down Expand Up @@ -45,7 +45,7 @@ function createZipTask(platform, buildType, version) {
buildType === loadBuildTypesConfig().default
? `metamask-${platform}-${version}`
: `metamask-${buildType}-${platform}-${version}`;
await pump(
await pipeline(
gulp.src(`dist/${platform}/**`),
// sort files and set `mtime` to epoch to ensure zip build is deterministic
sort(),
Expand Down
4 changes: 2 additions & 2 deletions development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const sourcemaps = require('gulp-sourcemaps');
const applySourceMap = require('vinyl-sourcemaps-apply');
const pify = require('pify');
const through = require('through2');
const endOfStream = pify(require('end-of-stream'));
const finished = pify(require('readable-stream').finished);
const labeledStreamSplicer = require('labeled-stream-splicer').obj;
const wrapInStream = require('pumpify').obj;
const { Eta } = require('eta');
Expand Down Expand Up @@ -1126,7 +1126,7 @@ async function createBundle(buildConfiguration, { reloadOnChange }) {
// nothing will consume pipeline, so let it flow
pipeline.resume();

await endOfStream(pipeline);
await finished(pipeline);

// call the completion event to handle any post-processing
events.emit('bundleDone');
Expand Down
4 changes: 2 additions & 2 deletions development/build/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const watch = require('gulp-watch');
const sourcemaps = require('gulp-sourcemaps');
const rtlcss = require('postcss-rtlcss');
const postcss = require('gulp-postcss');
const pump = pify(require('pump'));
const pipeline = pify(require('readable-stream').pipeline);
const sass = require('sass-embedded');
const gulpSass = require('gulp-sass')(sass);
const { TASKS } = require('./constants');
Expand Down Expand Up @@ -64,7 +64,7 @@ function createStyleTasks({ livereload }) {
}

async function buildScssPipeline(src, dest, devMode) {
await pump(
await pipeline(
...[
// pre-process
gulp.src(src),
Expand Down
Loading

0 comments on commit 782af6c

Please sign in to comment.