mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
Integrating snow into metamask (#15580)
This commit is contained in:
parent
0e573e1e24
commit
42b8971571
@ -4,6 +4,7 @@ ignores:
|
|||||||
# webapp deps
|
# webapp deps
|
||||||
#
|
#
|
||||||
|
|
||||||
|
- '@lavamoat/snow'
|
||||||
- '@babel/runtime'
|
- '@babel/runtime'
|
||||||
- '@fortawesome/fontawesome-free'
|
- '@fortawesome/fontawesome-free'
|
||||||
- 'punycode'
|
- 'punycode'
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<script src="./snow.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script src="./use-snow.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
|
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
|
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
|
||||||
{{@if(it.applyLavaMoat)}}
|
{{@if(it.applyLavaMoat)}}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
<img class="loading-spinner" src="./images/spinner.gif" alt="" />
|
<img class="loading-spinner" src="./images/spinner.gif" alt="" />
|
||||||
</div>
|
</div>
|
||||||
<div id="popover-content"></div>
|
<div id="popover-content"></div>
|
||||||
|
<script src="./snow.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script src="./use-snow.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
|
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
|
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
|
||||||
{{@if(it.applyLavaMoat)}}
|
{{@if(it.applyLavaMoat)}}
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
<img id="loading__spinner" src="./images/spinner.gif" alt="" />
|
<img id="loading__spinner" src="./images/spinner.gif" alt="" />
|
||||||
</div>
|
</div>
|
||||||
<div id="popover-content"></div>
|
<div id="popover-content"></div>
|
||||||
|
<script src="./snow.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script src="./use-snow.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
|
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
|
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
|
||||||
{{@if(it.applyLavaMoat)}}
|
{{@if(it.applyLavaMoat)}}
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
<img class="loading-spinner" src="./images/spinner.gif" alt="" />
|
<img class="loading-spinner" src="./images/spinner.gif" alt="" />
|
||||||
</div>
|
</div>
|
||||||
<div id="popover-content"></div>
|
<div id="popover-content"></div>
|
||||||
|
<script src="./snow.js" type="text/javascript" charset="utf-8"></script>
|
||||||
|
<script src="./use-snow.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
|
<script src="./globalthis.js" type="text/javascript" charset="utf-8"></script>
|
||||||
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
|
<script src="./sentry-install.js" type="text/javascript" charset="utf-8"></script>
|
||||||
{{@if(it.applyLavaMoat)}}
|
{{@if(it.applyLavaMoat)}}
|
||||||
|
8
app/scripts/use-snow.js
Normal file
8
app/scripts/use-snow.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
// eslint-disable-next-line import/unambiguous
|
||||||
|
(function () {
|
||||||
|
const log = console.log.bind(console);
|
||||||
|
const msg = 'SNOW INTERCEPTED NEW WINDOW CREATION IN METAMASK APP: ';
|
||||||
|
window.top.SNOW((win) => {
|
||||||
|
log(msg, win, win?.frameElement);
|
||||||
|
});
|
||||||
|
})();
|
@ -66,6 +66,7 @@ async function defineAndRunBuildTasks() {
|
|||||||
isLavaMoat,
|
isLavaMoat,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldIncludeLockdown,
|
shouldIncludeLockdown,
|
||||||
|
shouldIncludeSnow,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
skipStats,
|
skipStats,
|
||||||
version,
|
version,
|
||||||
@ -81,6 +82,7 @@ async function defineAndRunBuildTasks() {
|
|||||||
livereload,
|
livereload,
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
shouldIncludeLockdown,
|
shouldIncludeLockdown,
|
||||||
|
shouldIncludeSnow,
|
||||||
buildType,
|
buildType,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -230,6 +232,12 @@ testDev: Create an unoptimized, live-reloading build for debugging e2e tests.`,
|
|||||||
'Whether to include SES lockdown files in the extension bundle. Setting this to `false` can be useful during development if you want to handle lockdown errors later.',
|
'Whether to include SES lockdown files in the extension bundle. Setting this to `false` can be useful during development if you want to handle lockdown errors later.',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
})
|
})
|
||||||
|
.option('snow', {
|
||||||
|
default: true,
|
||||||
|
description:
|
||||||
|
'Whether to include Snow files in the extension bundle. Setting this to `false` can be useful during development if you want to handle Snow errors later.',
|
||||||
|
type: 'boolean',
|
||||||
|
})
|
||||||
.option('policy-only', {
|
.option('policy-only', {
|
||||||
default: false,
|
default: false,
|
||||||
description:
|
description:
|
||||||
@ -263,6 +271,7 @@ testDev: Create an unoptimized, live-reloading build for debugging e2e tests.`,
|
|||||||
buildVersion,
|
buildVersion,
|
||||||
lintFenceFiles,
|
lintFenceFiles,
|
||||||
lockdown,
|
lockdown,
|
||||||
|
snow,
|
||||||
policyOnly,
|
policyOnly,
|
||||||
skipStats,
|
skipStats,
|
||||||
task,
|
task,
|
||||||
@ -292,6 +301,7 @@ testDev: Create an unoptimized, live-reloading build for debugging e2e tests.`,
|
|||||||
isLavaMoat: process.argv[0].includes('lavamoat'),
|
isLavaMoat: process.argv[0].includes('lavamoat'),
|
||||||
policyOnly,
|
policyOnly,
|
||||||
shouldIncludeLockdown: lockdown,
|
shouldIncludeLockdown: lockdown,
|
||||||
|
shouldIncludeSnow: snow,
|
||||||
shouldLintFenceFiles,
|
shouldLintFenceFiles,
|
||||||
skipStats,
|
skipStats,
|
||||||
version,
|
version,
|
||||||
|
@ -15,11 +15,21 @@ module.exports = function createStaticAssetTasks({
|
|||||||
livereload,
|
livereload,
|
||||||
browserPlatforms,
|
browserPlatforms,
|
||||||
shouldIncludeLockdown = true,
|
shouldIncludeLockdown = true,
|
||||||
|
shouldIncludeSnow = true,
|
||||||
buildType,
|
buildType,
|
||||||
}) {
|
}) {
|
||||||
|
const copyTargetsProds = {};
|
||||||
|
const copyTargetsDevs = {};
|
||||||
|
|
||||||
|
browserPlatforms.forEach((browser) => {
|
||||||
const [copyTargetsProd, copyTargetsDev] = getCopyTargets(
|
const [copyTargetsProd, copyTargetsDev] = getCopyTargets(
|
||||||
shouldIncludeLockdown,
|
shouldIncludeLockdown,
|
||||||
|
// Snow currently only works on Chromium based browsers
|
||||||
|
shouldIncludeSnow && browser === 'chrome',
|
||||||
);
|
);
|
||||||
|
copyTargetsProds[browser] = copyTargetsProd;
|
||||||
|
copyTargetsDevs[browser] = copyTargetsDev;
|
||||||
|
});
|
||||||
|
|
||||||
const additionalBuildTargets = {
|
const additionalBuildTargets = {
|
||||||
[BuildType.beta]: [
|
[BuildType.beta]: [
|
||||||
@ -37,60 +47,60 @@ module.exports = function createStaticAssetTasks({
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (Object.keys(additionalBuildTargets).includes(buildType)) {
|
if (Object.keys(additionalBuildTargets).includes(buildType)) {
|
||||||
copyTargetsProd.push(...additionalBuildTargets[buildType]);
|
Object.entries(copyTargetsProds).forEach(([_, copyTargetsProd]) =>
|
||||||
copyTargetsDev.push(...additionalBuildTargets[buildType]);
|
copyTargetsProd.push(...additionalBuildTargets[buildType]),
|
||||||
|
);
|
||||||
|
Object.entries(copyTargetsDevs).forEach(([_, copyTargetsDev]) =>
|
||||||
|
copyTargetsDev.push(...additionalBuildTargets[buildType]),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const prod = createTask(
|
const prodTasks = [];
|
||||||
TASKS.STATIC_PROD,
|
Object.entries(copyTargetsProds).forEach(([browser, copyTargetsProd]) => {
|
||||||
composeSeries(
|
copyTargetsProd.forEach((target) => {
|
||||||
...copyTargetsProd.map((target) => {
|
prodTasks.push(async function copyStaticAssets() {
|
||||||
return async function copyStaticAssets() {
|
await performCopy(target, browser);
|
||||||
await performCopy(target);
|
});
|
||||||
};
|
});
|
||||||
}),
|
});
|
||||||
),
|
|
||||||
);
|
const devTasks = [];
|
||||||
const dev = createTask(
|
Object.entries(copyTargetsDevs).forEach(([browser, copyTargetsDev]) => {
|
||||||
TASKS.STATIC_DEV,
|
copyTargetsDev.forEach((target) => {
|
||||||
composeSeries(
|
devTasks.push(async function copyStaticAssets() {
|
||||||
...copyTargetsDev.map((target) => {
|
await setupLiveCopy(target, browser);
|
||||||
return async function copyStaticAssets() {
|
});
|
||||||
await setupLiveCopy(target);
|
});
|
||||||
};
|
});
|
||||||
}),
|
|
||||||
),
|
const prod = createTask(TASKS.STATIC_PROD, composeSeries(...prodTasks));
|
||||||
);
|
const dev = createTask(TASKS.STATIC_DEV, composeSeries(...devTasks));
|
||||||
|
|
||||||
return { dev, prod };
|
return { dev, prod };
|
||||||
|
|
||||||
async function setupLiveCopy(target) {
|
async function setupLiveCopy(target, browser) {
|
||||||
const pattern = target.pattern || '/**/*';
|
const pattern = target.pattern || '/**/*';
|
||||||
watch(target.src + pattern, (event) => {
|
watch(target.src + pattern, (event) => {
|
||||||
livereload.changed(event.path);
|
livereload.changed(event.path);
|
||||||
performCopy(target);
|
performCopy(target, browser);
|
||||||
});
|
});
|
||||||
await performCopy(target);
|
await performCopy(target, browser);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function performCopy(target) {
|
async function performCopy(target, browser) {
|
||||||
await Promise.all(
|
|
||||||
browserPlatforms.map(async (platform) => {
|
|
||||||
if (target.pattern) {
|
if (target.pattern) {
|
||||||
await copyGlob(
|
await copyGlob(
|
||||||
target.src,
|
target.src,
|
||||||
`${target.src}${target.pattern}`,
|
`${target.src}${target.pattern}`,
|
||||||
`./dist/${platform}/${target.dest}`,
|
`./dist/${browser}/${target.dest}`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
await copyGlob(
|
await copyGlob(
|
||||||
target.src,
|
target.src,
|
||||||
`${target.src}`,
|
`${target.src}`,
|
||||||
`./dist/${platform}/${target.dest}`,
|
`./dist/${browser}/${target.dest}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function copyGlob(baseDir, srcGlob, dest) {
|
async function copyGlob(baseDir, srcGlob, dest) {
|
||||||
@ -104,7 +114,7 @@ module.exports = function createStaticAssetTasks({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function getCopyTargets(shouldIncludeLockdown) {
|
function getCopyTargets(shouldIncludeLockdown, shouldIncludeSnow) {
|
||||||
const allCopyTargets = [
|
const allCopyTargets = [
|
||||||
{
|
{
|
||||||
src: `./app/_locales/`,
|
src: `./app/_locales/`,
|
||||||
@ -147,6 +157,16 @@ function getCopyTargets(shouldIncludeLockdown) {
|
|||||||
src: `./node_modules/globalthis/dist/browser.js`,
|
src: `./node_modules/globalthis/dist/browser.js`,
|
||||||
dest: `globalthis.js`,
|
dest: `globalthis.js`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
src: shouldIncludeSnow
|
||||||
|
? `./node_modules/@lavamoat/snow/snow.prod.js`
|
||||||
|
: EMPTY_JS_FILE,
|
||||||
|
dest: `snow.js`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: shouldIncludeSnow ? `./app/scripts/use-snow.js` : EMPTY_JS_FILE,
|
||||||
|
dest: `use-snow.js`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
src: shouldIncludeLockdown
|
src: shouldIncludeLockdown
|
||||||
? `./node_modules/ses/dist/lockdown.umd.min.js`
|
? `./node_modules/ses/dist/lockdown.umd.min.js`
|
||||||
|
@ -4947,6 +4947,7 @@
|
|||||||
"Node": true
|
"Node": true
|
||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
|
"@lavamoat/snow>is-cross-origin>is-window": true,
|
||||||
"proxyquire>fill-keys>is-object": true,
|
"proxyquire>fill-keys>is-object": true,
|
||||||
"react-inspector>is-dom>is-window": true
|
"react-inspector>is-dom>is-window": true
|
||||||
}
|
}
|
||||||
|
@ -5782,6 +5782,7 @@
|
|||||||
"Node": true
|
"Node": true
|
||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
|
"@lavamoat/snow>is-cross-origin>is-window": true,
|
||||||
"proxyquire>fill-keys>is-object": true,
|
"proxyquire>fill-keys>is-object": true,
|
||||||
"react-inspector>is-dom>is-window": true
|
"react-inspector>is-dom>is-window": true
|
||||||
}
|
}
|
||||||
|
@ -4947,6 +4947,7 @@
|
|||||||
"Node": true
|
"Node": true
|
||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
|
"@lavamoat/snow>is-cross-origin>is-window": true,
|
||||||
"proxyquire>fill-keys>is-object": true,
|
"proxyquire>fill-keys>is-object": true,
|
||||||
"react-inspector>is-dom>is-window": true
|
"react-inspector>is-dom>is-window": true
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"setup": "yarn install && yarn setup:postinstall",
|
"setup": "yarn install && yarn setup:postinstall",
|
||||||
"setup:postinstall": "yarn patch-package && yarn allow-scripts",
|
"setup:postinstall": "yarn patch-package && yarn allow-scripts",
|
||||||
"start": "yarn build:dev dev --apply-lavamoat=false",
|
"start": "yarn build:dev dev --apply-lavamoat=false --snow=false",
|
||||||
"start:lavamoat": "yarn build:dev dev --apply-lavamoat=true",
|
"start:lavamoat": "yarn build:dev dev --apply-lavamoat=true",
|
||||||
"start:mv3": "ENABLE_MV3=true yarn build:dev dev --apply-lavamoat=false",
|
"start:mv3": "ENABLE_MV3=true yarn build:dev dev --apply-lavamoat=false",
|
||||||
"dist": "yarn build dist",
|
"dist": "yarn build dist",
|
||||||
@ -138,6 +138,7 @@
|
|||||||
"@spruceid/siwe-parser": "^1.1.3",
|
"@spruceid/siwe-parser": "^1.1.3",
|
||||||
"@truffle/codec": "^0.11.18",
|
"@truffle/codec": "^0.11.18",
|
||||||
"@truffle/decoder": "^5.1.0",
|
"@truffle/decoder": "^5.1.0",
|
||||||
|
"@lavamoat/snow": "^1.2.1",
|
||||||
"@zxing/browser": "^0.0.10",
|
"@zxing/browser": "^0.0.10",
|
||||||
"@zxing/library": "0.8.0",
|
"@zxing/library": "0.8.0",
|
||||||
"await-semaphore": "^0.1.1",
|
"await-semaphore": "^0.1.1",
|
||||||
|
14
yarn.lock
14
yarn.lock
@ -2559,6 +2559,13 @@
|
|||||||
through2 "^4.0.2"
|
through2 "^4.0.2"
|
||||||
umd "^3.0.3"
|
umd "^3.0.3"
|
||||||
|
|
||||||
|
"@lavamoat/snow@^1.2.1":
|
||||||
|
version "1.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@lavamoat/snow/-/snow-1.2.1.tgz#87587e46940b26a966b665e62cd867d0cfbce47e"
|
||||||
|
integrity sha512-gC4oyvjNkFOOjhL9W4wP1YC0dcdQJPYKNW8fbwcP5iYogLL2fs1KIsHoF41WIhuWQ9mUdfg1jKBCTq41m+5VSw==
|
||||||
|
dependencies:
|
||||||
|
is-cross-origin "^1.0.1"
|
||||||
|
|
||||||
"@ledgerhq/cryptoassets@^5.27.2":
|
"@ledgerhq/cryptoassets@^5.27.2":
|
||||||
version "5.53.0"
|
version "5.53.0"
|
||||||
resolved "https://registry.yarnpkg.com/@ledgerhq/cryptoassets/-/cryptoassets-5.53.0.tgz#11dcc93211960c6fd6620392e4dd91896aaabe58"
|
resolved "https://registry.yarnpkg.com/@ledgerhq/cryptoassets/-/cryptoassets-5.53.0.tgz#11dcc93211960c6fd6620392e4dd91896aaabe58"
|
||||||
@ -14476,6 +14483,13 @@ is-core-module@^2.4.0, is-core-module@^2.8.1, is-core-module@^2.9.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
has "^1.0.3"
|
has "^1.0.3"
|
||||||
|
|
||||||
|
is-cross-origin@^1.0.1:
|
||||||
|
version "1.0.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/is-cross-origin/-/is-cross-origin-1.0.1.tgz#b73ee0bbcf9f640a4c4f17bcf3cc229e3dae11e8"
|
||||||
|
integrity sha512-l0VqOliZJ0tJTFkNGa1kJilL9q+wCKw2wLX6qoXVtWUFKiqXvLaf4kAu4+9xAg6QJGKc41CDaFYSxmO9Iw1vuw==
|
||||||
|
dependencies:
|
||||||
|
is-window "^1.0.2"
|
||||||
|
|
||||||
is-data-descriptor@^0.1.4:
|
is-data-descriptor@^0.1.4:
|
||||||
version "0.1.4"
|
version "0.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56"
|
resolved "https://registry.yarnpkg.com/is-data-descriptor/-/is-data-descriptor-0.1.4.tgz#0b5ee648388e2c860282e793f1856fec3f301b56"
|
||||||
|
Loading…
Reference in New Issue
Block a user