-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this prevents the need for 'unsafe-inline' in the CSP to talk to MM on Firefox
- Loading branch information
1 parent
f42013a
commit 42cd14f
Showing
6 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'metamask-inpage-provider' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/// <reference path="./metamaskInpageProvider.d.ts" /> | ||
|
||
import MetamaskInpageProvider from 'metamask-inpage-provider' | ||
import LocalMessageDuplexStream from 'post-message-stream' | ||
|
||
// Be sure to give MM a chance to successfully inject its own stub | ||
setTimeout(() => { | ||
try { | ||
// Don't clobber an existing MM stub | ||
if (window && !window.ethereum) { | ||
//#region verbatim from https://github.com/MetaMask/metamask-extension/issues/3133#issuecomment-631652083 | ||
// setup background connection | ||
const metamaskStream = new LocalMessageDuplexStream({ | ||
name: 'inpage', | ||
target: 'contentscript' | ||
}) | ||
|
||
// compose the inpage provider | ||
const inpageProvider = new MetamaskInpageProvider(metamaskStream) | ||
|
||
// set a high max listener count to avoid unnecesary warnings | ||
inpageProvider.setMaxListeners(100) | ||
|
||
// Work around for web3@1.0 deleting the bound `sendAsync` but not the unbound | ||
// `sendAsync` method on the prototype, causing `this` reference issues | ||
const ethereum = new Proxy(inpageProvider, { | ||
// straight up lie that we deleted the property so that it doesnt | ||
// throw an error in strict mode | ||
deleteProperty: () => true | ||
}) | ||
//#endregion | ||
|
||
window.ethereum = ethereum | ||
} | ||
} catch (e) { | ||
console.error('metamaskInpageProvider:', e) | ||
} | ||
}, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters