From 6dbdc87713a652dec4c90fa792dda08d613d4198 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Wed, 18 Apr 2018 17:24:36 -0400 Subject: [PATCH] Add generated docs --- app/scripts/config.js | 4 +- app/scripts/controllers/token-rates.js | 6 +- app/scripts/first-time-state.js | 2 +- docs/jsdocs/ComposableObservableStore.html | 541 ++++ docs/jsdocs/EdgeEncryptor.html | 545 ++++ docs/jsdocs/TokenRatesController.html | 682 +++++ docs/jsdocs/config.js.html | 148 + docs/jsdocs/contentscript.js.html | 265 ++ docs/jsdocs/controllers_token-rates.js.html | 146 + docs/jsdocs/edge-encryptor.js.html | 166 ++ docs/jsdocs/first-time-state.js.html | 92 + docs/jsdocs/global.html | 2547 ++++++++++++++++- docs/jsdocs/index.html | 104 +- docs/jsdocs/inpage.js.html | 144 + .../lib_ComposableObservableStore.js.html | 118 + docs/jsdocs/metamask-controller.js.html | 142 +- .../jsdocs/module.exports_module.exports.html | 6 +- docs/jsdocs/popup-core.js.html | 146 + 18 files changed, 5531 insertions(+), 273 deletions(-) create mode 100644 docs/jsdocs/ComposableObservableStore.html create mode 100644 docs/jsdocs/EdgeEncryptor.html create mode 100644 docs/jsdocs/TokenRatesController.html create mode 100644 docs/jsdocs/config.js.html create mode 100644 docs/jsdocs/contentscript.js.html create mode 100644 docs/jsdocs/controllers_token-rates.js.html create mode 100644 docs/jsdocs/edge-encryptor.js.html create mode 100644 docs/jsdocs/first-time-state.js.html create mode 100644 docs/jsdocs/inpage.js.html create mode 100644 docs/jsdocs/lib_ComposableObservableStore.js.html create mode 100644 docs/jsdocs/popup-core.js.html diff --git a/app/scripts/config.js b/app/scripts/config.js index 634d7a013..21905d5b4 100644 --- a/app/scripts/config.js +++ b/app/scripts/config.js @@ -47,7 +47,7 @@ global.METAMASK_DEBUG = process.env.METAMASK_DEBUG */ /** - * @type {Config} Application configuration object + * @type {Config} **/ const config = { network: { @@ -76,4 +76,4 @@ const config = { }, } -module.exports = config \ No newline at end of file +module.exports = config diff --git a/app/scripts/controllers/token-rates.js b/app/scripts/controllers/token-rates.js index 22e3e8154..28409ea10 100644 --- a/app/scripts/controllers/token-rates.js +++ b/app/scripts/controllers/token-rates.js @@ -46,7 +46,7 @@ class TokenRatesController { } /** - * @type {Number} - Interval used to poll for exchange rates + * @type {Number} */ set interval (interval) { this._handle && clearInterval(this._handle) @@ -55,7 +55,7 @@ class TokenRatesController { } /** - * @type {Object} - Preferences controller instance + * @type {Object} */ set preferences (preferences) { this._preferences && this._preferences.unsubscribe() @@ -66,7 +66,7 @@ class TokenRatesController { } /** - * @type {Array} - Array of token objects with contract addresses + * @type {Array} */ set tokens (tokens) { this._tokens = tokens diff --git a/app/scripts/first-time-state.js b/app/scripts/first-time-state.js index 0c8f35303..144534f43 100644 --- a/app/scripts/first-time-state.js +++ b/app/scripts/first-time-state.js @@ -9,7 +9,7 @@ const METAMASK_DEBUG = process.env.METAMASK_DEBUG */ /** - * @type {FirstTimeState} The default state of MetaMask + * @type {FirstTimeState} */ const initialState = { config: {}, diff --git a/docs/jsdocs/ComposableObservableStore.html b/docs/jsdocs/ComposableObservableStore.html new file mode 100644 index 000000000..fa0807608 --- /dev/null +++ b/docs/jsdocs/ComposableObservableStore.html @@ -0,0 +1,541 @@ + + + + + + + ComposableObservableStore - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

ComposableObservableStore

+ + + + + + + +
+ +
+ +

+ ComposableObservableStore +

+ +

An ObservableStore that can composes a flat +structure of child stores based on configuration

+ + +
+ +
+
+ + + + +

Constructor

+ + +

new ComposableObservableStore(initStateopt, configopt)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Create a new store

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
initState + + +Object + + + + + + <optional>
+ + + + + +

The initial store state

config + + +Object + + + + + + <optional>
+ + + + + +

Map of internal state keys to child stores

+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

getFlatState() → {Object}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Merges all child store state into a single object rather than +returning an object keyed by child store class name

+
+ + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+
    +
  • Object containing merged child store state
  • +
+
+ + + +
+
+ Type +
+
+ +Object + + +
+
+ + + + + + + + + +

updateStructure(configopt)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Composes a new internal store subscription structure

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
config + + +Object + + + + + + <optional>
+ + + + + +

Map of internal state keys to child stores

+ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +
+ + + + + + + + \ No newline at end of file diff --git a/docs/jsdocs/EdgeEncryptor.html b/docs/jsdocs/EdgeEncryptor.html new file mode 100644 index 000000000..538b14291 --- /dev/null +++ b/docs/jsdocs/EdgeEncryptor.html @@ -0,0 +1,545 @@ + + + + + + + EdgeEncryptor - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

EdgeEncryptor

+ + + + + + + +
+ +
+ +

+ EdgeEncryptor +

+ +

A Microsoft Edge-specific encryption class that exposes +the interface expected by eth-keykeyring-controller

+ + +
+ +
+
+ + + + +

Constructor

+ + +

new EdgeEncryptor()

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + +

Methods

+ + + + + + +

decrypt(password, text) → {Promise.<Object>}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Decrypts an arbitrary JavaScript object from cypher text

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
password + + +string + + + +

Password used to unlock a cryptographic key

text + + +string + + + +

Cypher text of an encrypted JavaScript object

+ + + + + + + + + + + + + + +
Returns:
+ + +
+

Promise resolving to copy of decrypted JavaScript object

+
+ + + +
+
+ Type +
+
+ +Promise.<Object> + + +
+
+ + + + + + + + + +

encrypt(password, dataObject) → {Object}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Encrypts an arbitrary JavaScript object to cypher text

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
password + + +string + + + +

Password used to unlock a cryptographic key

dataObject + + +Object + + + +

Data to encrypt

+ + + + + + + + + + + + + + +
Returns:
+ + +
+

Object containing cypher text, generation vectors, and salt

+
+ + + +
+
+ Type +
+
+ +Object + + +
+
+ + + + + + + + + + +
+ +
+ + + + +
+ +
+ + + + + + + + \ No newline at end of file diff --git a/docs/jsdocs/TokenRatesController.html b/docs/jsdocs/TokenRatesController.html new file mode 100644 index 000000000..60994b685 --- /dev/null +++ b/docs/jsdocs/TokenRatesController.html @@ -0,0 +1,682 @@ + + + + + + + TokenRatesController - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

TokenRatesController

+ + + + + + + +
+ +
+ +

+ TokenRatesController +

+ +

A controller that polls for token exchange +rates based on a user's current token list

+ + +
+ +
+
+ + + + +

Constructor

+ + +

new TokenRatesController(configopt)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Creates a TokenRatesController

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeAttributesDescription
config + + +Object + + + + + + <optional>
+ + + + + +

Options to configure controller

+ + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + +

Members

+ + + +

interval :Number

+ + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Type:
+
    +
  • + +Number + + +
  • +
+ + + + + + + + +

preferences :Object

+ + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Type:
+
    +
  • + +Object + + +
  • +
+ + + + + + + + +

tokens :Array

+ + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Type:
+
    +
  • + +Array + + +
  • +
+ + + + + + + + + + +

Methods

+ + + + + + +

(async) fetchExchangeRate(address)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Fetches a token exchange rate by address

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
address + + +String + + + +

Token contract address

+ + + + + + + + + + + + + + + + + + + + + +

(async) updateExchangeRates()

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Updates exchange rates for all tokens

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + +
+ +
+ + + + + + + + \ No newline at end of file diff --git a/docs/jsdocs/config.js.html b/docs/jsdocs/config.js.html new file mode 100644 index 000000000..425b517d1 --- /dev/null +++ b/docs/jsdocs/config.js.html @@ -0,0 +1,148 @@ + + + + + + + config.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

config.js

+ + + + + + + +
+
+
const MAINET_RPC_URL = 'https://mainnet.infura.io/metamask'
+const ROPSTEN_RPC_URL = 'https://ropsten.infura.io/metamask'
+const KOVAN_RPC_URL = 'https://kovan.infura.io/metamask'
+const RINKEBY_RPC_URL = 'https://rinkeby.infura.io/metamask'
+const LOCALHOST_RPC_URL = 'http://localhost:8545'
+
+const MAINET_RPC_URL_BETA = 'https://mainnet.infura.io/metamask2'
+const ROPSTEN_RPC_URL_BETA = 'https://ropsten.infura.io/metamask2'
+const KOVAN_RPC_URL_BETA = 'https://kovan.infura.io/metamask2'
+const RINKEBY_RPC_URL_BETA = 'https://rinkeby.infura.io/metamask2'
+
+const DEFAULT_RPC = 'rinkeby'
+const OLD_UI_NETWORK_TYPE = 'network'
+const BETA_UI_NETWORK_TYPE = 'networkBeta'
+
+global.METAMASK_DEBUG = process.env.METAMASK_DEBUG
+
+/**
+ * @typedef {Object} UrlConfig
+ * @property {string} localhost URL of local RPC provider
+ * @property {string} mainnet URL of mainnet RPC provider
+ * @property {string} ropsten URL of Ropsten testnet RPC provider
+ * @property {string} kovan URL of Kovan testnet RPC provider
+ * @property {string} rinkeby URL of Rinkeby testnet RPC provider
+ */
+
+/**
+ * @typedef {Object} NameConfig
+ * @property {string} 3 URL of local RPC provider
+ * @property {string} 4 URL of mainnet RPC provider
+ * @property {string} 42 URL of Ropsten testnet RPC provider
+ */
+
+/**
+ * @typedef {Object} EnumConfig
+ * @property {string} DEFAULT_RPC Default network provider URL
+ * @property {string} OLD_UI_NETWORK_TYPE
+ * @property {string} BETA_UI_NETWORK_TYPE
+ */
+
+/**
+ * @typedef {Object} Config
+ * @property {UrlConfig} network Network configuration parameters
+ * @property {UrlConfig} networkBeta Beta UI network configuration parameters
+ * @property {NameConfig} networkNames Network name configuration parameters
+ * @property {EnumConfig} enums Application-wide string constants
+ */
+
+/**
+ * @type {Config}
+ **/
+const config = {
+  network: {
+    localhost: LOCALHOST_RPC_URL,
+    mainnet: MAINET_RPC_URL,
+    ropsten: ROPSTEN_RPC_URL,
+    kovan: KOVAN_RPC_URL,
+    rinkeby: RINKEBY_RPC_URL,
+  },
+  networkBeta: {
+    localhost: LOCALHOST_RPC_URL,
+    mainnet: MAINET_RPC_URL_BETA,
+    ropsten: ROPSTEN_RPC_URL_BETA,
+    kovan: KOVAN_RPC_URL_BETA,
+    rinkeby: RINKEBY_RPC_URL_BETA,
+  },
+  networkNames: {
+    3: 'Ropsten',
+    4: 'Rinkeby',
+    42: 'Kovan',
+  },
+  enums: {
+    DEFAULT_RPC,
+    OLD_UI_NETWORK_TYPE,
+    BETA_UI_NETWORK_TYPE,
+  },
+}
+
+module.exports = config
+
+
+
+ + + + +
+ +
+ + + + + + + + diff --git a/docs/jsdocs/contentscript.js.html b/docs/jsdocs/contentscript.js.html new file mode 100644 index 000000000..0a798e81c --- /dev/null +++ b/docs/jsdocs/contentscript.js.html @@ -0,0 +1,265 @@ + + + + + + + contentscript.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

contentscript.js

+ + + + + + + +
+
+
const fs = require('fs')
+const path = require('path')
+const pump = require('pump')
+const LocalMessageDuplexStream = require('post-message-stream')
+const PongStream = require('ping-pong-stream/pong')
+const ObjectMultiplex = require('obj-multiplex')
+const extension = require('extensionizer')
+const PortStream = require('./lib/port-stream.js')
+
+const inpageContent = fs.readFileSync(path.join(__dirname, '..', '..', 'dist', 'chrome', 'inpage.js')).toString()
+const inpageSuffix = '//# sourceURL=' + extension.extension.getURL('inpage.js') + '\n'
+const inpageBundle = inpageContent + inpageSuffix
+
+// Eventually this streaming injection could be replaced with:
+// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components.utils.exportFunction
+//
+// But for now that is only Firefox
+// If we create a FireFox-only code path using that API,
+// MetaMask will be much faster loading and performant on Firefox.
+
+if (shouldInjectWeb3()) {
+  setupInjection()
+  setupStreams()
+}
+
+/**
+ * Creates a script tag that injects inpage.js
+ */
+function setupInjection () {
+  try {
+    // inject in-page script
+    var scriptTag = document.createElement('script')
+    scriptTag.textContent = inpageBundle
+    scriptTag.onload = function () { this.parentNode.removeChild(this) }
+    var container = document.head || document.documentElement
+    // append as first child
+    container.insertBefore(scriptTag, container.children[0])
+  } catch (e) {
+    console.error('Metamask injection failed.', e)
+  }
+}
+
+/**
+ * Sets up two-way communication streams between the
+ * browser extension and local per-page browser context
+ */
+function setupStreams () {
+  // setup communication to page and plugin
+  const pageStream = new LocalMessageDuplexStream({
+    name: 'contentscript',
+    target: 'inpage',
+  })
+  const pluginPort = extension.runtime.connect({ name: 'contentscript' })
+  const pluginStream = new PortStream(pluginPort)
+
+  // forward communication plugin->inpage
+  pump(
+    pageStream,
+    pluginStream,
+    pageStream,
+    (err) => logStreamDisconnectWarning('MetaMask Contentscript Forwarding', err)
+  )
+
+  // setup local multistream channels
+  const mux = new ObjectMultiplex()
+  mux.setMaxListeners(25)
+
+  pump(
+    mux,
+    pageStream,
+    mux,
+    (err) => logStreamDisconnectWarning('MetaMask Inpage', err)
+  )
+  pump(
+    mux,
+    pluginStream,
+    mux,
+    (err) => logStreamDisconnectWarning('MetaMask Background', err)
+  )
+
+  // connect ping stream
+  const pongStream = new PongStream({ objectMode: true })
+  pump(
+    mux,
+    pongStream,
+    mux,
+    (err) => logStreamDisconnectWarning('MetaMask PingPongStream', err)
+  )
+
+  // connect phishing warning stream
+  const phishingStream = mux.createStream('phishing')
+  phishingStream.once('data', redirectToPhishingWarning)
+
+  // ignore unused channels (handled by background, inpage)
+  mux.ignoreStream('provider')
+  mux.ignoreStream('publicConfig')
+}
+
+
+/**
+ * Error handler for page to plugin stream disconnections
+ *
+ * @param {string} remoteLabel Remote stream name
+ * @param {Error} err Stream connection error
+ */
+function logStreamDisconnectWarning (remoteLabel, err) {
+  let warningMsg = `MetamaskContentscript - lost connection to ${remoteLabel}`
+  if (err) warningMsg += '\n' + err.stack
+  console.warn(warningMsg)
+}
+
+/**
+ * Determines if Web3 should be injected
+ *
+ * @returns {boolean} True of Web3 should be injected
+ */
+function shouldInjectWeb3 () {
+  return doctypeCheck() && suffixCheck()
+    && documentElementCheck() && !blacklistedDomainCheck()
+}
+
+/**
+ * Checks the doctype of the current document if it exists
+ *
+ * @returns {boolean} True if the doctype is html or if none exists
+ */
+function doctypeCheck () {
+  const doctype = window.document.doctype
+  if (doctype) {
+    return doctype.name === 'html'
+  } else {
+    return true
+  }
+}
+
+/**
+ * Checks the current document extension
+ *
+ * @returns {boolean} True if the current extension is not prohibited
+ */
+function suffixCheck () {
+  var prohibitedTypes = ['xml', 'pdf']
+  var currentUrl = window.location.href
+  var currentRegex
+  for (let i = 0; i < prohibitedTypes.length; i++) {
+    currentRegex = new RegExp(`\\.${prohibitedTypes[i]}$`)
+    if (currentRegex.test(currentUrl)) {
+      return false
+    }
+  }
+  return true
+}
+
+/**
+ * Checks the documentElement of the current document
+ *
+ * @returns {boolean} True if the documentElement is an html node or if none exists
+ */
+function documentElementCheck () {
+  var documentElement = document.documentElement.nodeName
+  if (documentElement) {
+    return documentElement.toLowerCase() === 'html'
+  }
+  return true
+}
+
+/**
+ * Checks if the current domain is blacklisted
+ * 
+ * @returns {boolean} True if the current domain is blacklisted
+ */
+function blacklistedDomainCheck () {
+  var blacklistedDomains = [
+    'uscourts.gov',
+    'dropbox.com',
+    'webbyawards.com',
+  ]
+  var currentUrl = window.location.href
+  var currentRegex
+  for (let i = 0; i < blacklistedDomains.length; i++) {
+    const blacklistedDomain = blacklistedDomains[i].replace('.', '\\.')
+    currentRegex = new RegExp(`(?:https?:\\/\\/)(?:(?!${blacklistedDomain}).)*$`)
+    if (!currentRegex.test(currentUrl)) {
+      return true
+    }
+  }
+  return false
+}
+
+/**
+ * Redirects the current page to a phishing information page
+ */
+function redirectToPhishingWarning () {
+  console.log('MetaMask - redirecting to phishing warning')
+  window.location.href = 'https://metamask.io/phishing.html'
+}
+
+
+
+ + + + +
+ +
+ + + + + + + + diff --git a/docs/jsdocs/controllers_token-rates.js.html b/docs/jsdocs/controllers_token-rates.js.html new file mode 100644 index 000000000..12c6d70fc --- /dev/null +++ b/docs/jsdocs/controllers_token-rates.js.html @@ -0,0 +1,146 @@ + + + + + + + controllers/token-rates.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

controllers/token-rates.js

+ + + + + + + +
+
+
const ObservableStore = require('obs-store')
+
+// By default, poll every 3 minutes
+const DEFAULT_INTERVAL = 180 * 1000
+
+/**
+ * A controller that polls for token exchange
+ * rates based on a user's current token list
+ */
+class TokenRatesController {
+  /**
+   * Creates a TokenRatesController
+   *
+   * @param {Object} [config] - Options to configure controller
+   */
+  constructor ({ interval = DEFAULT_INTERVAL, preferences } = {}) {
+    this.store = new ObservableStore()
+    this.preferences = preferences
+    this.interval = interval
+  }
+
+  /**
+   * Updates exchange rates for all tokens
+   */
+  async updateExchangeRates () {
+    if (!this.isActive) { return }
+    const contractExchangeRates = {}
+    for (const i in this._tokens) {
+      const address = this._tokens[i].address
+      contractExchangeRates[address] = await this.fetchExchangeRate(address)
+    }
+    this.store.putState({ contractExchangeRates })
+  }
+
+  /**
+   * Fetches a token exchange rate by address
+   *
+   * @param {String} address - Token contract address
+   */
+  async fetchExchangeRate (address) {
+    try {
+      const response = await fetch(`https://exchanges.balanc3.net/prices?from=${address}&to=ETH&autoConversion=false&summaryOnly=true`)
+      const json = await response.json()
+      return json && json.length ? json[0].averagePrice : 0
+    } catch (error) { }
+  }
+
+  /**
+   * @type {Number}
+   */
+  set interval (interval) {
+    this._handle && clearInterval(this._handle)
+    if (!interval) { return }
+    this._handle = setInterval(() => { this.updateExchangeRates() }, interval)
+  }
+
+  /**
+   * @type {Object}
+   */
+  set preferences (preferences) {
+    this._preferences && this._preferences.unsubscribe()
+    if (!preferences) { return }
+    this._preferences = preferences
+    this.tokens = preferences.getState().tokens
+    preferences.subscribe(({ tokens = [] }) => { this.tokens = tokens })
+  }
+
+  /**
+   * @type {Array}
+   */
+  set tokens (tokens) {
+    this._tokens = tokens
+    this.updateExchangeRates()
+  }
+}
+
+module.exports = TokenRatesController
+
+
+
+ + + + +
+ +
+ + + + + + + + diff --git a/docs/jsdocs/edge-encryptor.js.html b/docs/jsdocs/edge-encryptor.js.html new file mode 100644 index 000000000..e85f444b4 --- /dev/null +++ b/docs/jsdocs/edge-encryptor.js.html @@ -0,0 +1,166 @@ + + + + + + + edge-encryptor.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

edge-encryptor.js

+ + + + + + + +
+
+
const asmcrypto = require('asmcrypto.js')
+const Unibabel = require('browserify-unibabel')
+
+/**
+ * A Microsoft Edge-specific encryption class that exposes
+ * the interface expected by eth-keykeyring-controller
+ */
+class EdgeEncryptor {
+  /**
+   * Encrypts an arbitrary JavaScript object to cypher text
+   *
+   * @param {string} password Password used to unlock a cryptographic key
+   * @param {Object} dataObject Data to encrypt
+   * @returns {Object} Object containing cypher text, generation vectors, and salt
+   */
+  encrypt (password, dataObject) {
+      var salt = this._generateSalt()
+      return this._keyFromPassword(password, salt)
+          .then(function (key) {
+              var data = JSON.stringify(dataObject)
+              var dataBuffer = Unibabel.utf8ToBuffer(data)
+              var vector = global.crypto.getRandomValues(new Uint8Array(16))
+              var resultbuffer = asmcrypto.AES_GCM.encrypt(dataBuffer, key, vector)
+
+              var buffer = new Uint8Array(resultbuffer)
+              var vectorStr = Unibabel.bufferToBase64(vector)
+              var vaultStr = Unibabel.bufferToBase64(buffer)
+              return JSON.stringify({
+                  data: vaultStr,
+                  iv: vectorStr,
+                  salt: salt,
+              })
+          })
+  }
+
+  /**
+   * Decrypts an arbitrary JavaScript object from cypher text
+   *
+   * @param {string} password Password used to unlock a cryptographic key
+   * @param {string} text Cypher text of an encrypted JavaScript object
+   * @returns {Promise<Object>} Promise resolving to copy of decrypted JavaScript object
+   */
+  decrypt (password, text) {
+      const payload = JSON.parse(text)
+      const salt = payload.salt
+      return this._keyFromPassword(password, salt)
+          .then(function (key) {
+              const encryptedData = Unibabel.base64ToBuffer(payload.data)
+              const vector = Unibabel.base64ToBuffer(payload.iv)
+              return new Promise((resolve, reject) => {
+                  var result
+                  try {
+                      result = asmcrypto.AES_GCM.decrypt(encryptedData, key, vector)
+                  } catch (err) {
+                      return reject(new Error('Incorrect password'))
+                  }
+                  const decryptedData = new Uint8Array(result)
+                  const decryptedStr = Unibabel.bufferToUtf8(decryptedData)
+                  const decryptedObj = JSON.parse(decryptedStr)
+                  resolve(decryptedObj)
+              })
+          })
+  }
+
+  /**
+   * Retrieves a cryptographic key using a password
+   *
+   * @private
+   * @param {string} password Password used to unlock a cryptographic key
+   * @param {string} salt Random base-64 data
+   * @returns {Promise<Object>} Promise resolving to a derived key
+   */
+  _keyFromPassword (password, salt) {
+
+      var passBuffer = Unibabel.utf8ToBuffer(password)
+      var saltBuffer = Unibabel.base64ToBuffer(salt)
+      return new Promise((resolve) => {
+          var key = asmcrypto.PBKDF2_HMAC_SHA256.bytes(passBuffer, saltBuffer, 10000)
+          resolve(key)
+      })
+  }
+
+  /**
+   * Generates random base-64 encoded data
+   *
+   * @private
+   * @returns {string} Randomized base-64 encoded data
+   */
+  _generateSalt (byteCount = 32) {
+      var view = new Uint8Array(byteCount)
+      global.crypto.getRandomValues(view)
+      var b64encoded = btoa(String.fromCharCode.apply(null, view))
+      return b64encoded
+  }
+}
+
+module.exports = EdgeEncryptor
+
+
+
+ + + + +
+ +
+ + + + + + + + diff --git a/docs/jsdocs/first-time-state.js.html b/docs/jsdocs/first-time-state.js.html new file mode 100644 index 000000000..431846e45 --- /dev/null +++ b/docs/jsdocs/first-time-state.js.html @@ -0,0 +1,92 @@ + + + + + + + first-time-state.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
+ +

first-time-state.js

+ + + + + + + +
+
+
// test and development environment variables
+const env = process.env.METAMASK_ENV
+const METAMASK_DEBUG = process.env.METAMASK_DEBUG
+
+/**
+ * @typedef {Object} FirstTimeState
+ * @property {Object} config Initial configuration parameters
+ * @property {Object} NetworkController Network controller state
+ */
+
+/**
+ * @type {FirstTimeState}
+ */
+const initialState = {
+  config: {},
+  NetworkController: {
+    provider: {
+      type: (METAMASK_DEBUG || env === 'test') ? 'rinkeby' : 'mainnet',
+    },
+  },
+}
+
+module.exports = initialState
+
+
+
+ + + + +
+ +
+ + + + + + + + diff --git a/docs/jsdocs/global.html b/docs/jsdocs/global.html index c06006e58..499111982 100644 --- a/docs/jsdocs/global.html +++ b/docs/jsdocs/global.html @@ -32,7 +32,7 @@
@@ -116,15 +116,11 @@ - - - - -

Type Definitions

+

Members

- -

MetaMaskOptions

+ +

(constant) config :Config

@@ -135,7 +131,1865 @@
Source:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Type:
+ + + + + + + + + +

(constant) initialState :FirstTimeState

+ + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + +
Type:
+ + + + + + + + + + + +

Methods

+ + + + + + +

blacklistedDomainCheck() → {boolean}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Checks if the current domain is blacklisted

+
+ + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+

True if the current domain is blacklisted

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + + +

cleanContextForImports()

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Caches reference to global define object and deletes it

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

connectToAccountManager(connectionStream, cb)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Establishes streamed connections to background scripts and a Web3 provider

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
connectionStream + + +any + + + +

PortStream instance establishing a background connection

cb + + +function + + + +

Called when controller connection is established

+ + + + + + + + + + + + + + + + + + + + + +

doctypeCheck() → {boolean}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Checks the doctype of the current document if it exists

+
+ + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+

True if the doctype is html or if none exists

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + + +

documentElementCheck() → {boolean}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Checks the documentElement of the current document

+
+ + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+

True if the documentElement is an html node or if none exists

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + + +

initializePopup(config, cb)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Asynchronously initializes the MetaMask popup UI

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
config + + +Object + + + +

Popup configuration object

cb + + +function + + + +

Called when initialization is comlete

+ + + + + + + + + + + + + + + + + + + + + +

logStreamDisconnectWarning(remoteLabel, err)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Error handler for page to plugin stream disconnections

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
remoteLabel + + +string + + + +

Remote stream name

err + + +Error + + + +

Stream connection error

+ + + + + + + + + + + + + + + + + + + + + +

redirectToPhishingWarning()

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Redirects the current page to a phishing information page

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

restoreContextAfterImports()

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Restores global define object from cached reference

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

setupControllerConnection(connectionStream, cb)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Establishes a streamed connection to the background account manager

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
connectionStream + + +any + + + +

PortStream instance establishing a background connection

cb + + +function + + + +

Called when the remote account manager connection is established

+ + + + + + + + + + + + + + + + + + + + + +

setupInjection()

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Creates a script tag that injects inpage.js

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

setupStreams()

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Sets up two-way communication streams between the +browser extension and local per-page browser context

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

setupWeb3Connection(connectionStream)

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Establishes a streamed connection to a Web3 provider

+
+ + + + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
connectionStream + + +any + + + +

PortStream instance establishing a background connection

+ + + + + + + + + + + + + + + + + + + + + +

shouldInjectWeb3() → {boolean}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Determines if Web3 should be injected

+
+ + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+

True of Web3 should be injected

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + + +

suffixCheck() → {boolean}

+ + + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+

Checks the current document extension

+
+ + + + + + + + + + + + + + + + + + + + + + + +
Returns:
+ + +
+

True if the current extension is not prohibited

+
+ + + +
+
+ Type +
+
+ +boolean + + +
+
+ + + + + + + + +

Type Definitions

+ + + +

Config

+ + + + + +
+ + +
Source:
+
@@ -198,13 +2052,13 @@ - platform + network -Platform +UrlConfig @@ -214,7 +2068,76 @@ -

An object including platform-specific functions.

+

Network configuration parameters

+ + + + + + + networkBeta + + + + + +UrlConfig + + + + + + + + + +

Beta UI network configuration parameters

+ + + + + + + networkNames + + + + + +NameConfig + + + + + + + + + +

Network name configuration parameters

+ + + + + + + enums + + + + + +EnumConfig + + + + + + + + + +

Application-wide string constants

@@ -232,7 +2155,7 @@
  • -object +Object
  • @@ -245,7 +2168,7 @@ -

    Platform

    +

    EnumConfig

    @@ -256,7 +2179,7 @@
    Source:
    @@ -319,13 +2242,13 @@ - reload + DEFAULT_RPC -function +string @@ -335,20 +2258,20 @@ -

    A function to reload the application.

    +

    Default network provider URL

    - openWindow + OLD_UI_NETWORK_TYPE -function +string @@ -358,20 +2281,20 @@ -

    Opens a URL in the web browser.

    + - getVersion + BETA_UI_NETWORK_TYPE -function +string @@ -381,53 +2304,7 @@ -

    Gets the current version of MetaMask.

    - - - - - - - openExtensionInBrowser - - - - - -function - - - - - - - - - -

    Opens the MetaMask UI in a full window.

    - - - - - - - getPlatformInfo - - - - - -function - - - - - - - - - -

    Callback function that returns info about the current platform.

    + @@ -439,9 +2316,149 @@ -
    -

    An object that provides a variety of platform-specific functions.

    -
    + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + + + + +

    FirstTimeState

    + + + + + +
    + + +
    Source:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    config + + +Object + + + +

    Initial configuration parameters

    NetworkController + + +Object + + + +

    Network controller state

    + + + + + @@ -449,7 +2466,387 @@
    • -object +Object + + +
    • +
    + + + + + + + + +

    NameConfig

    + + + + + +
    + + +
    Source:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    3 + + +string + + + +

    URL of local RPC provider

    4 + + +string + + + +

    URL of mainnet RPC provider

    42 + + +string + + + +

    URL of Ropsten testnet RPC provider

    + + + + + + + + +
    Type:
    +
      +
    • + +Object + + +
    • +
    + + + + + + + + +

    UrlConfig

    + + + + + +
    + + +
    Source:
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + +
    Properties:
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    NameTypeDescription
    localhost + + +string + + + +

    URL of local RPC provider

    mainnet + + +string + + + +

    URL of mainnet RPC provider

    ropsten + + +string + + + +

    URL of Ropsten testnet RPC provider

    kovan + + +string + + + +

    URL of Kovan testnet RPC provider

    rinkeby + + +string + + + +

    URL of Rinkeby testnet RPC provider

    + + + + + + + + +
    Type:
    +
      +
    • + +Object
    • @@ -476,7 +2873,7 @@
      - Documentation generated by JSDoc 3.5.5 on Thu Apr 12 2018 14:37:39 GMT-0700 (PDT) using the radgrad jsdoc theme. Derived from docdash. + Documentation generated by JSDoc 3.5.5 on Wed Apr 18 2018 17:21:38 GMT-0400 (EDT) using the radgrad jsdoc theme. Derived from docdash.
      diff --git a/docs/jsdocs/index.html b/docs/jsdocs/index.html index 7ac43e45d..0d5b08d90 100644 --- a/docs/jsdocs/index.html +++ b/docs/jsdocs/index.html @@ -32,7 +32,7 @@
      @@ -56,106 +56,6 @@ - - - - - - - -
      - -
      - -

      - controllers/transactions.js -

      - - -
      - -
      -
      - - - -
      - - -
      Source:
      -
      - - - - - - - - - - - - - - - - - - - - - - - - - - -
      License:
      -
      • MIT
      - - - - - - - - - -
      - - - - - -

      The transaction controller. Receives incoming transactions, and emits events for various states of their processing.

      - - - - -
      - - - - - - - - - - - - - - - - - - -
      - -
      @@ -265,7 +165,7 @@
      - Documentation generated by JSDoc 3.5.5 on Thu Apr 12 2018 14:37:39 GMT-0700 (PDT) using the radgrad jsdoc theme. Derived from docdash. + Documentation generated by JSDoc 3.5.5 on Wed Apr 18 2018 17:21:38 GMT-0400 (EDT) using the radgrad jsdoc theme. Derived from docdash.
      diff --git a/docs/jsdocs/inpage.js.html b/docs/jsdocs/inpage.js.html new file mode 100644 index 000000000..acfd6223c --- /dev/null +++ b/docs/jsdocs/inpage.js.html @@ -0,0 +1,144 @@ + + + + + + + inpage.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
      + +

      inpage.js

      + + + + + + + +
      +
      +
      /*global Web3*/
      +cleanContextForImports()
      +require('web3/dist/web3.min.js')
      +const log = require('loglevel')
      +const LocalMessageDuplexStream = require('post-message-stream')
      +const setupDappAutoReload = require('./lib/auto-reload.js')
      +const MetamaskInpageProvider = require('./lib/inpage-provider.js')
      +restoreContextAfterImports()
      +
      +log.setDefaultLevel(process.env.METAMASK_DEBUG ? 'debug' : 'warn')
      +
      +//
      +// setup plugin communication
      +//
      +
      +// setup background connection
      +var metamaskStream = new LocalMessageDuplexStream({
      +  name: 'inpage',
      +  target: 'contentscript',
      +})
      +
      +// compose the inpage provider
      +var inpageProvider = new MetamaskInpageProvider(metamaskStream)
      +
      +//
      +// setup web3
      +//
      +
      +if (typeof window.web3 !== 'undefined') {
      +  throw new Error(`MetaMask detected another web3.
      +     MetaMask will not work reliably with another web3 extension.
      +     This usually happens if you have two MetaMasks installed,
      +     or MetaMask and another web3 extension. Please remove one
      +     and try again.`)
      +}
      +var web3 = new Web3(inpageProvider)
      +web3.setProvider = function () {
      +  log.debug('MetaMask - overrode web3.setProvider')
      +}
      +log.debug('MetaMask - injected web3')
      +// export global web3, with usage-detection
      +setupDappAutoReload(web3, inpageProvider.publicConfigStore)
      +
      +// set web3 defaultAccount
      +inpageProvider.publicConfigStore.subscribe(function (state) {
      +  web3.eth.defaultAccount = state.selectedAddress
      +})
      +
      +// need to make sure we aren't affected by overlapping namespaces
      +// and that we dont affect the app with our namespace
      +// mostly a fix for web3's BigNumber if AMD's "define" is defined...
      +var __define
      +
      +/**
      + * Caches reference to global define object and deletes it
      + */
      +function cleanContextForImports () {
      +  __define = global.define
      +  try {
      +    global.define = undefined
      +  } catch (_) {
      +    console.warn('MetaMask - global.define could not be deleted.')
      +  }
      +}
      +
      +/**
      + * Restores global define object from cached reference
      + */
      +function restoreContextAfterImports () {
      +  try {
      +    global.define = __define
      +  } catch (_) {
      +    console.warn('MetaMask - global.define could not be overwritten.')
      +  }
      +}
      +
      +
      +
      + + + + +
      + +
      + +
      + Documentation generated by JSDoc 3.5.5 on Wed Apr 18 2018 17:21:38 GMT-0400 (EDT) using the radgrad jsdoc theme. Derived from docdash. +
      + + + + + + diff --git a/docs/jsdocs/lib_ComposableObservableStore.js.html b/docs/jsdocs/lib_ComposableObservableStore.js.html new file mode 100644 index 000000000..dc39a9f55 --- /dev/null +++ b/docs/jsdocs/lib_ComposableObservableStore.js.html @@ -0,0 +1,118 @@ + + + + + + + lib/ComposableObservableStore.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
      + +

      lib/ComposableObservableStore.js

      + + + + + + + +
      +
      +
      const ObservableStore = require('obs-store')
      +
      +/**
      + * An ObservableStore that can composes a flat
      + * structure of child stores based on configuration
      + */
      +class ComposableObservableStore extends ObservableStore {
      +  /**
      +   * Create a new store
      +   *
      +   * @param {Object} [initState] - The initial store state
      +   * @param {Object} [config] - Map of internal state keys to child stores
      +   */
      +  constructor (initState, config) {
      +    super(initState)
      +    this.updateStructure(config)
      +  }
      +
      +  /**
      +   * Composes a new internal store subscription structure
      +   *
      +   * @param {Object} [config] - Map of internal state keys to child stores
      +   */
      +  updateStructure (config) {
      +    this.config = config
      +    this.removeAllListeners()
      +    for (const key in config) {
      +      config[key].subscribe((state) => {
      +        this.updateState({ [key]: state })
      +      })
      +    }
      +  }
      +
      +  /**
      +   * Merges all child store state into a single object rather than
      +   * returning an object keyed by child store class name
      +   *
      +   * @returns {Object} - Object containing merged child store state
      +   */
      +  getFlatState () {
      +    let flatState = {}
      +    for (const key in this.config) {
      +      flatState = { ...flatState, ...this.config[key].getState() }
      +    }
      +    return flatState
      +  }
      +}
      +
      +module.exports = ComposableObservableStore
      +
      +
      +
      + + + + +
      + +
      + +
      + Documentation generated by JSDoc 3.5.5 on Wed Apr 18 2018 17:21:38 GMT-0400 (EDT) using the radgrad jsdoc theme. Derived from docdash. +
      + + + + + + diff --git a/docs/jsdocs/metamask-controller.js.html b/docs/jsdocs/metamask-controller.js.html index 2162138d1..5f8748577 100644 --- a/docs/jsdocs/metamask-controller.js.html +++ b/docs/jsdocs/metamask-controller.js.html @@ -32,7 +32,7 @@
      @@ -54,10 +54,10 @@ */ const EventEmitter = require('events') -const extend = require('xtend') const pump = require('pump') const Dnode = require('dnode') const ObservableStore = require('obs-store') +const ComposableObservableStore = require('./lib/ComposableObservableStore') const asStream = require('obs-store/lib/asStream') const AccountTracker = require('./lib/account-tracker') const RpcEngine = require('json-rpc-engine') @@ -83,6 +83,7 @@ const PersonalMessageManager = require('./lib/personal-message-manager') const TypedMessageManager = require('./lib/typed-message-manager') const TransactionController = require('./controllers/transactions') const BalancesController = require('./controllers/computed-balances') +const TokenRatesController = require('./controllers/token-rates') const ConfigManager = require('./lib/config-manager') const nodeify = require('./lib/nodeify') const accountImporter = require('./account-import-strategies') @@ -93,11 +94,7 @@ const BN = require('ethereumjs-util').BN const GWEI_BN = new BN('1000000000') const percentile = require('percentile') const seedPhraseVerifier = require('./lib/seed-phrase-verifier') - -/** - * @typedef {object} MetaMaskOptions - * @property {Platform} platform - An object including platform-specific functions. - */ +const log = require('loglevel') module.exports = class MetamaskController extends EventEmitter { @@ -108,7 +105,6 @@ module.exports = class MetamaskController extends EventEmitter { constructor (opts) { super() - // Avoids warnings when we use lots of emitters. this.defaultMaxListeners = 20 this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200) @@ -120,7 +116,7 @@ module.exports = class MetamaskController extends EventEmitter { this.platform = opts.platform // observable state store - this.store = new ObservableStore(initState) + this.store = new ComposableObservableStore(initState) // lock to ensure only one vault created at once this.createVaultMutex = new Mutex() @@ -159,6 +155,11 @@ module.exports = class MetamaskController extends EventEmitter { this.provider = this.initializeProvider() this.blockTracker = this.provider._blockTracker + // token exchange rate tracker + this.tokenRatesController = new TokenRatesController({ + preferences: this.preferencesController.store, + }) + this.recentBlocksController = new RecentBlocksController({ blockTracker: this.blockTracker, provider: this.provider, @@ -239,53 +240,37 @@ module.exports = class MetamaskController extends EventEmitter { this.typedMessageManager = new TypedMessageManager() this.publicConfigStore = this.initPublicConfigStore() - // manual disk state subscriptions - this.txController.store.subscribe((state) => { - this.store.updateState({ TransactionController: state }) - }) - this.keyringController.store.subscribe((state) => { - this.store.updateState({ KeyringController: state }) - }) - this.preferencesController.store.subscribe((state) => { - this.store.updateState({ PreferencesController: state }) - }) - this.addressBookController.store.subscribe((state) => { - this.store.updateState({ AddressBookController: state }) - }) - this.currencyController.store.subscribe((state) => { - this.store.updateState({ CurrencyController: state }) - }) - this.noticeController.store.subscribe((state) => { - this.store.updateState({ NoticeController: state }) - }) - this.shapeshiftController.store.subscribe((state) => { - this.store.updateState({ ShapeShiftController: state }) - }) - this.networkController.store.subscribe((state) => { - this.store.updateState({ NetworkController: state }) + this.store.updateStructure({ + TransactionController: this.txController.store, + KeyringController: this.keyringController.store, + PreferencesController: this.preferencesController.store, + AddressBookController: this.addressBookController.store, + CurrencyController: this.currencyController.store, + NoticeController: this.noticeController.store, + ShapeShiftController: this.shapeshiftController.store, + NetworkController: this.networkController.store, + InfuraController: this.infuraController.store, }) - this.infuraController.store.subscribe((state) => { - this.store.updateState({ InfuraController: state }) + this.memStore = new ComposableObservableStore(null, { + NetworkController: this.networkController.store, + AccountTracker: this.accountTracker.store, + TxController: this.txController.memStore, + BalancesController: this.balancesController.store, + TokenRatesController: this.tokenRatesController.store, + MessageManager: this.messageManager.memStore, + PersonalMessageManager: this.personalMessageManager.memStore, + TypesMessageManager: this.typedMessageManager.memStore, + KeyringController: this.keyringController.memStore, + PreferencesController: this.preferencesController.store, + RecentBlocksController: this.recentBlocksController.store, + AddressBookController: this.addressBookController.store, + CurrencyController: this.currencyController.store, + NoticeController: this.noticeController.memStore, + ShapeshiftController: this.shapeshiftController.store, + InfuraController: this.infuraController.store, }) - - // manual mem state subscriptions - const sendUpdate = this.sendUpdate.bind(this) - this.networkController.store.subscribe(sendUpdate) - this.accountTracker.store.subscribe(sendUpdate) - this.txController.memStore.subscribe(sendUpdate) - this.balancesController.store.subscribe(sendUpdate) - this.messageManager.memStore.subscribe(sendUpdate) - this.personalMessageManager.memStore.subscribe(sendUpdate) - this.typedMessageManager.memStore.subscribe(sendUpdate) - this.keyringController.memStore.subscribe(sendUpdate) - this.preferencesController.store.subscribe(sendUpdate) - this.recentBlocksController.store.subscribe(sendUpdate) - this.addressBookController.store.subscribe(sendUpdate) - this.currencyController.store.subscribe(sendUpdate) - this.noticeController.memStore.subscribe(sendUpdate) - this.shapeshiftController.store.subscribe(sendUpdate) - this.infuraController.store.subscribe(sendUpdate) + this.memStore.subscribe(this.sendUpdate.bind(this)) } /** @@ -334,6 +319,7 @@ module.exports = class MetamaskController extends EventEmitter { // memStore -> transform -> publicConfigStore this.on('update', (memState) => { + this.isClientOpenAndUnlocked = memState.isUnlocked && this._isClientOpen const publicState = selectPublicState(memState) publicConfigStore.putState(publicState) }) @@ -363,33 +349,16 @@ module.exports = class MetamaskController extends EventEmitter { const vault = this.keyringController.store.getState().vault const isInitialized = (!!wallet || !!vault) - return extend( - { - isInitialized, - }, - this.networkController.store.getState(), - this.accountTracker.store.getState(), - this.txController.memStore.getState(), - this.messageManager.memStore.getState(), - this.personalMessageManager.memStore.getState(), - this.typedMessageManager.memStore.getState(), - this.keyringController.memStore.getState(), - this.balancesController.store.getState(), - this.preferencesController.store.getState(), - this.addressBookController.store.getState(), - this.currencyController.store.getState(), - this.noticeController.memStore.getState(), - this.infuraController.store.getState(), - this.recentBlocksController.store.getState(), - // config manager - this.configManager.getConfig(), - this.shapeshiftController.store.getState(), - { + return { + ...{ isInitialized }, + ...this.memStore.getFlatState(), + ...this.configManager.getConfig(), + ...{ lostAccounts: this.configManager.getLostAccounts(), seedWords: this.configManager.getSeedWords(), forgottenPassword: this.configManager.getPasswordForgotten(), - } - ) + }, + } } /** @@ -1103,15 +1072,6 @@ module.exports = class MetamaskController extends EventEmitter { } } - /** - * Records the MetaMask version and time of first installation, - * mutating the initState param. - * - * @private - * - * @param {object} initState The initial state passed to the controller, - * which may be new. - */ recordFirstTimeInfo (initState) { if (!('firstTimeInfo' in initState)) { initState.firstTimeInfo = { @@ -1121,6 +1081,14 @@ module.exports = class MetamaskController extends EventEmitter { } } + set isClientOpen (open) { + this._isClientOpen = open + this.isClientOpenAndUnlocked = this.getState().isUnlocked && open + } + + set isClientOpenAndUnlocked (active) { + this.tokenRatesController.isActive = active + } } @@ -1134,7 +1102,7 @@ module.exports = class MetamaskController extends EventEmitter {
      - Documentation generated by JSDoc 3.5.5 on Thu Apr 12 2018 14:37:39 GMT-0700 (PDT) using the radgrad jsdoc theme. Derived from docdash. + Documentation generated by JSDoc 3.5.5 on Wed Apr 18 2018 17:21:38 GMT-0400 (EDT) using the radgrad jsdoc theme. Derived from docdash.
      diff --git a/docs/jsdocs/module.exports_module.exports.html b/docs/jsdocs/module.exports_module.exports.html index 5558cea07..f5c96b6eb 100644 --- a/docs/jsdocs/module.exports_module.exports.html +++ b/docs/jsdocs/module.exports_module.exports.html @@ -32,7 +32,7 @@
      @@ -75,7 +75,7 @@
      Source:
      @@ -219,7 +219,7 @@
      - Documentation generated by JSDoc 3.5.5 on Thu Apr 12 2018 14:37:39 GMT-0700 (PDT) using the radgrad jsdoc theme. Derived from docdash. + Documentation generated by JSDoc 3.5.5 on Wed Apr 18 2018 17:21:38 GMT-0400 (EDT) using the radgrad jsdoc theme. Derived from docdash.
      diff --git a/docs/jsdocs/popup-core.js.html b/docs/jsdocs/popup-core.js.html new file mode 100644 index 000000000..919637cfe --- /dev/null +++ b/docs/jsdocs/popup-core.js.html @@ -0,0 +1,146 @@ + + + + + + + popup-core.js - Documentation + + + + + + + + + + + + + + + + + + + + + +
      + +

      popup-core.js

      + + + + + + + +
      +
      +
      const EventEmitter = require('events').EventEmitter
      +const async = require('async')
      +const Dnode = require('dnode')
      +const Eth = require('ethjs')
      +const EthQuery = require('eth-query')
      +const launchMetamaskUi = require('../../ui')
      +const StreamProvider = require('web3-stream-provider')
      +const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex
      +
      +module.exports = initializePopup
      +
      +/**
      + * Asynchronously initializes the MetaMask popup UI
      + *
      + * @param {{ container: Element, connectionStream: any }} config Popup configuration object 
      + * @param {Function} cb Called when initialization is comlete
      + */
      +function initializePopup ({ container, connectionStream }, cb) {
      +  // setup app
      +  async.waterfall([
      +    (cb) => connectToAccountManager(connectionStream, cb),
      +    (accountManager, cb) => launchMetamaskUi({ container, accountManager }, cb),
      +  ], cb)
      +}
      +
      +/**
      + * Establishes streamed connections to background scripts and a Web3 provider
      + *
      + * @param {any} connectionStream PortStream instance establishing a background connection
      + * @param {Function} cb Called when controller connection is established
      + */
      +function connectToAccountManager (connectionStream, cb) {
      +  // setup communication with background
      +  // setup multiplexing
      +  var mx = setupMultiplex(connectionStream)
      +  // connect features
      +  setupControllerConnection(mx.createStream('controller'), cb)
      +  setupWeb3Connection(mx.createStream('provider'))
      +}
      +
      +/**
      + * Establishes a streamed connection to a Web3 provider
      + *
      + * @param {any} connectionStream PortStream instance establishing a background connection
      + */
      +function setupWeb3Connection (connectionStream) {
      +  var providerStream = new StreamProvider()
      +  providerStream.pipe(connectionStream).pipe(providerStream)
      +  connectionStream.on('error', console.error.bind(console))
      +  providerStream.on('error', console.error.bind(console))
      +  global.ethereumProvider = providerStream
      +  global.ethQuery = new EthQuery(providerStream)
      +  global.eth = new Eth(providerStream)
      +}
      +
      +/**
      + * Establishes a streamed connection to the background account manager
      + *
      + * @param {any} connectionStream PortStream instance establishing a background connection
      + * @param {Function} cb Called when the remote account manager connection is established
      + */
      +function setupControllerConnection (connectionStream, cb) {
      +  // this is a really sneaky way of adding EventEmitter api
      +  // to a bi-directional dnode instance
      +  var eventEmitter = new EventEmitter()
      +  var accountManagerDnode = Dnode({
      +    sendUpdate: function (state) {
      +      eventEmitter.emit('update', state)
      +    },
      +  })
      +  connectionStream.pipe(accountManagerDnode).pipe(connectionStream)
      +  accountManagerDnode.once('remote', function (accountManager) {
      +    // setup push events
      +    accountManager.on = eventEmitter.on.bind(eventEmitter)
      +    cb(null, accountManager)
      +  })
      +}
      +
      +
      +
      + + + + +
      + +
      + +
      + Documentation generated by JSDoc 3.5.5 on Wed Apr 18 2018 17:21:38 GMT-0400 (EDT) using the radgrad jsdoc theme. Derived from docdash. +
      + + + + + +