Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ship our own metamask stub #443

Closed
wants to merge 2 commits into from
Closed

fix: ship our own metamask stub #443

wants to merge 2 commits into from

Conversation

mrnerdhair
Copy link
Contributor

@mrnerdhair mrnerdhair commented Nov 18, 2021

Description

This prevents the need for 'unsafe-inline' in the CSP to talk to MM on Firefox: MetaMask/metamask-extension#3133

(Further reference: https://bugzilla.mozilla.org/show_bug.cgi?id=1267027)

Notice

Before submitting a pull request, please make sure you have answered the following:

  • Have you followed the guidelines in our Contributing guide?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?
  • Do all new and existing tests pass? Does the linter pass?

Pull Request Type

  • 🐛 Bug fix (Non-breaking Change: Fixes an issue)
  • 🛠️ Chore (Non-breaking Change: Doc updates, pkg upgrades, typos, etc..)
  • 💅 New Feature (Breaking/Non-breaking Change)

@vercel
Copy link

vercel bot commented Nov 18, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/shapeshift/web/6PpGF4YDcsCUVnkCY1E9QHhnHv1d
✅ Preview: https://web-git-metamask-stub-shapeshift.vercel.app

@vercel
Copy link

vercel bot commented Nov 18, 2021

Deployment failed with the following error:

Resource is limited - try again after in 1 minute (more than 100, code: "api-deployments-free-per-day").

@mrnerdhair mrnerdhair marked this pull request as ready for review November 18, 2021 18:44
@mrnerdhair mrnerdhair requested a review from a team as a code owner November 18, 2021 18:44
@mrnerdhair mrnerdhair marked this pull request as draft November 18, 2021 18:45
@mrnerdhair mrnerdhair changed the title feat: ship our own metamask stub fix: ship our own metamask stub Nov 18, 2021
@mrnerdhair mrnerdhair marked this pull request as ready for review November 18, 2021 21:28
this prevents the need for 'unsafe-inline' in the CSP to talk to MM on Firefox
Comment on lines +6 to +45
function universalProxy(pseudoTarget: object) {
return {
proxy: new Proxy(
{},
new Proxy(
{},
{
get(_, p) {
return (_t: any, p2: any, r: any) => {
switch (p) {
case 'get': {
const out = Reflect.get(pseudoTarget, p2, r)
if (typeof out === 'function') return out.bind(pseudoTarget)
return out
}
case 'getOwnPropertyDescriptor': {
const out = Reflect.getOwnPropertyDescriptor(pseudoTarget, p2)
if (out) out.configurable = true
return out
}
case 'isExtensible':
return true
case 'preventExtensions':
return false
default:
return (Reflect as any)[p](pseudoTarget, p2, r)
}
}
}
}
)
),
getPseudoTarget() {
return pseudoTarget
},
setPseudoTarget(value: object) {
pseudoTarget = value
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is built on the universalProxyHandler code in hdwallet's revocable(), so it should be pretty robust; a similar wrappers are around everything returned from a native vault. The difference here is that the (pseudo-)target can be changed after creation, which lets us return a "placeholder" proxy object for any on-load references to window.ethereum, which can be filled in later once we decide which stub to use.

src/lib/metamaskInpageProvider.ts Show resolved Hide resolved
@cjthompson
Copy link
Contributor

This is a change that I think requires more discussion about the reason behind it. FF is not an officially supported browser.

@vercel
Copy link

vercel bot commented Nov 18, 2021

Deployment failed with the following error:

Resource is limited - try again after in 14 minutes (more than 100, code: "api-deployments-free-per-day").

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