aboutsummaryrefslogtreecommitdiffstats
path: root/docs/porting_to_new_environment.md
diff options
context:
space:
mode:
authorkumavis <aaron@kumavis.me>2018-05-23 04:20:04 +0800
committerkumavis <aaron@kumavis.me>2018-05-23 04:20:04 +0800
commit3a80f3dd836889b7e4f4d4db8eaf42883623d9bf (patch)
treebcde7f3a6acbdf311bf66b70be6bfac2b3ed088a /docs/porting_to_new_environment.md
parent3084dc47d10e3e455c924e5aad0b0961c500ec8d (diff)
parentcee55b47d03006630b1dbe038c6008654ca8f674 (diff)
downloadtangerine-wallet-browser-3a80f3dd836889b7e4f4d4db8eaf42883623d9bf.tar
tangerine-wallet-browser-3a80f3dd836889b7e4f4d4db8eaf42883623d9bf.tar.gz
tangerine-wallet-browser-3a80f3dd836889b7e4f4d4db8eaf42883623d9bf.tar.bz2
tangerine-wallet-browser-3a80f3dd836889b7e4f4d4db8eaf42883623d9bf.tar.lz
tangerine-wallet-browser-3a80f3dd836889b7e4f4d4db8eaf42883623d9bf.tar.xz
tangerine-wallet-browser-3a80f3dd836889b7e4f4d4db8eaf42883623d9bf.tar.zst
tangerine-wallet-browser-3a80f3dd836889b7e4f4d4db8eaf42883623d9bf.zip
Merge branch 'develop' of github.com:MetaMask/metamask-extension into network-remove-provider-engine
Diffstat (limited to 'docs/porting_to_new_environment.md')
-rw-r--r--docs/porting_to_new_environment.md13
1 files changed, 12 insertions, 1 deletions
diff --git a/docs/porting_to_new_environment.md b/docs/porting_to_new_environment.md
index 454337d2a..983c81f3e 100644
--- a/docs/porting_to_new_environment.md
+++ b/docs/porting_to_new_environment.md
@@ -1,6 +1,16 @@
# Guide to Porting MetaMask to a New Environment
-MetaMask has been under continuous development for nearly two years now, and we’ve gradually discovered some very useful abstractions, that have allowed us to grow more easily. A couple of those layers together allow MetaMask to be ported to new environments and contexts increasingly easily.
+MetaMask has been under continuous development for nearly two years now, and we’ve gradually discovered some useful abstractions that have allowed us to grow more easily. A couple of those layers together allow MetaMask to be ported to new environments and contexts increasingly easily (although it still could be easier, and please let us know if you get stuck!)
+
+Before we get started, it's worth becoming familiar with our basic architecture:
+
+![metamask-architecture-diagram](./architecture.png)
+
+The `metamask-background` describes the file at `app/scripts/background.js`, which is the web extension singleton. This context instantiates an instance of the `MetaMask Controller`, which represents the user's accounts, a connection to the blockchain, and the interaction with new Dapps.
+
+When a new site is visited, the WebExtension creates a new `ContentScript` in that page's context, which can be seen at `app/scripts/contentscript.js`. This script represents a per-page setup process, which creates the per-page `web3` api, connects it to the background script via the Port API (wrapped in a [stream abstraction](https://github.com/substack/stream-handbook)), and injected into the DOM before anything loads.
+
+The most confusing part about porting MetaMask to a new platform is the way we provide the Web3 API over a series of streams between contexts. Once you understand how we create the [InpageProvider](../app/scripts/lib/inpage-provider.js) in the [inpage.js script](../app/scripts/inpage.js), you will be able to understand how the [port-stream](../app/scripts/lib/port-stream.js) is just a thin wrapper around the [postMessage API](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage), and a similar stream API can be wrapped around any communication channel to communicate with the `MetaMaskController` via its `setupUntrustedCommunication(stream, domain)` method.
### The MetaMask Controller
@@ -88,3 +98,4 @@ If streams seem new and confusing to you, that's ok, they can seem strange at fi
## Conclusion
I hope this has been helpful to you! If you have any other questionsm, or points you think need clarification in this guide, please [open an issue on our GitHub](https://github.com/MetaMask/metamask-plugin/issues/new)!
+