Skip to content

Fix Math endowment in Node.js#1347

Merged
FrederikBolding merged 3 commits intomainfrom
fb/fix-math-endowment
Apr 13, 2023
Merged

Fix Math endowment in Node.js#1347
FrederikBolding merged 3 commits intomainfrom
fb/fix-math-endowment

Conversation

@FrederikBolding
Copy link
Copy Markdown
Member

Fixes the Math endowment when running in Node.js. Previously we would assume crypto to be available, but that isn't the case in the scope where we are creating the Math endowment.

@FrederikBolding FrederikBolding requested a review from a team as a code owner April 13, 2023 10:55
Mrtenz
Mrtenz previously approved these changes Apr 13, 2023
@FrederikBolding FrederikBolding merged commit cc3a483 into main Apr 13, 2023
@FrederikBolding FrederikBolding deleted the fb/fix-math-endowment branch April 13, 2023 11:18
cryptotavares added a commit to MetaMask/metamask-desktop that referenced this pull request Apr 13, 2023
There's a bug on snaps node
execution services that prevents
the Math to be used within a snap
env.
Issue: MetaMask/snaps#1347
cryptotavares added a commit to MetaMask/metamask-desktop that referenced this pull request May 11, 2023
* chore: update submodule to latest extension master

* chore: align dependencies with extension

* fix: extension release trigger ci workflow

* fix: add babel plugin to remove explicit ts import

Currently the extension has explicit ts
import files (example - import * 'test.ts').
This is not a good pattern for node, as the
ts build will output js files. And thus during
the runtime the node process breaks as it cannot
find the imported file. On the Extension it does not
have any issues because of the bundling that we have
in place. It creates a reference to the path and as so
it can have ts and js files beig explicitly imported,
but in reality it is only running js.
The fix that we are doing here, is just to
remove the .ts file extension from any import (as the
ts file itself is already transpiled into js and
has the js file extension)

* chore: update to electron 23.2.2

* fix: update deps to fix GHSA-7jxr-cg7f-gpgv

* chore: update lavamoat policy files

* fix: add external references to lavamoat policy file

* fix: update chromedriver version

* fix: add classnames.d.ts from extension to fix tsc

* fix: patch snaps node exec env

There's a bug on snaps node
execution services that prevents
the Math to be used within a snap
env.
Issue: MetaMask/snaps#1347

* test increase e2e tests timeout

* fix: update node types to node 18

This is in line with the node version
that electron 23 is using

* fix: get NFT image from data base64

The NFTController is always fetching the
NFT image, even if the image is a data base64
encoded. Fetching anything other than http/https
is supported in the browser but not by node-fetch
(which uses the underlying http/https node native modules).
To fix this we will use the native node fetch
(available by default since node 18) to perform
any fetch actions that are not http/https.

* chore: update to latest extension master

* fix: align deps

* fix: vm2 vuln and depcheck

* fix: lint and update babel targets

* chore: add eth keyring types

* fix: lavamoat policies

* fix: depcheck missing '

* chore: remove unnecessary fetch log

* fix: desktop app e2e tests

* fix: e2e test desktop app

* feat: update browser runtime id

Update the node browser runtime id
whenever we get an internal connection
and the sender id does not match the
browser id

* fix: unit test

* fix: node 18 dns resolution using ipv6 first

There's an issue with node 18
where dns will resolve using ipv6
and not fallback to ipv4. This was
causing the tests to fail, because
localhost resolves to ::1:<port>
instead of 127.0.0.1:<port>. This
was preventing from running the tests
locally

* fix: ens resolution extension e2e tests

When running the extension e2e tests
it is expected that the infura project
id is set to 00000000000000000000000000000000.
If not we might not be hitting the mockserver

* fix: get runtime id for firefox

Firefox generates a different runtime id
for the extension. In order to get the
actual runtime id, we can parse the url
from an internal connection created by either
the popup, notification or fullscreen extension

* fix: runtime getUrl

This method is not async in the browser.
Due to that on the Extension we are calling
it synchronously to go back to the home page
(from the phishing blocked script). When on Desktop
we proxy this requests to the actual browser, meaning
that the request will be async. This was causing
the phishing detection to not return to the extension
home page when clicking on the back to safety button.
Also, it is worth mentioning that the
protocol for chrome and firefox extensions are different.
So added a method to update the browser info
accordingly and route to the correct url.

* fix: patch snaps execution env

snaps 0.32.2 updated the bundled from
webpack to browserify, so we need to reintroduce
this patch (now adpated to browserify)

* fix: lavamoat policies to prevent override global fetch

trezor connect and isomorphic fetch were
overriding global.fetch. Open a topic
with lavamoat team to clarify why
setting the policy to write
would not identify that the global.fetch
was previously set.

* fix: unit tests

Mock connectRemote env type constants

* chore: revert e2e test timeout

* fix: skip snaps rpc test

This test is skiped in the extension.
There is a bung in the snaps controller.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants