From 6dbdc87713a652dec4c90fa792dda08d613d4198 Mon Sep 17 00:00:00 2001 From: bitpshr Date: Wed, 18 Apr 2018 17:24:36 -0400 Subject: Add generated docs --- 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 | 2459 ++++++++++++++++++++- docs/jsdocs/index.html | 104 +- docs/jsdocs/inpage.js.html | 144 ++ docs/jsdocs/lib_ComposableObservableStore.js.html | 118 + docs/jsdocs/metamask-controller.js.html | 142 +- docs/jsdocs/module.exports_module.exports.html | 6 +- docs/jsdocs/popup-core.js.html | 146 ++ 15 files changed, 5481 insertions(+), 223 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 (limited to 'docs') 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,2370 @@ +

Members

+ + + +

(constant) config :Config

+ + + + + +
+ + +
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:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
network + + +UrlConfig + + + +

Network configuration parameters

networkBeta + + +UrlConfig + + + +

Beta UI network configuration parameters

networkNames + + +NameConfig + + + +

Network name configuration parameters

enums + + +EnumConfig + + + +

Application-wide string constants

+ + + + + + + + +
Type:
+ + + + + + + + + +

EnumConfig

+ + + + + +
+ + +
Source:
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
Properties:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -

Type Definitions

+ + + + + + + + + + + + + + + + + +
NameTypeDescription
DEFAULT_RPC + + +string + + + +

Default network provider URL

OLD_UI_NETWORK_TYPE + + +string + + + +
BETA_UI_NETWORK_TYPE + + +string + + + +
+ + + + + + + + +
Type:
+ + + + + + + + + +

FirstTimeState

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

Initial configuration parameters

NetworkController + + +Object + + + +

Network controller state

+ + + + + + + + +
Type:
+ + + + + + + + -

MetaMaskOptions

+

NameConfig

@@ -135,7 +2490,7 @@
Source:
@@ -198,13 +2553,59 @@ - platform + 3 + + + + + +string + + + + + + + + + +

URL of local RPC provider

+ + + + + + + 4 + + + + + +string + + + + + + + + + +

URL of mainnet RPC provider

+ + + + + + + 42 -Platform +string @@ -214,7 +2615,7 @@ -

An object including platform-specific functions.

+

URL of Ropsten testnet RPC provider

@@ -232,7 +2633,7 @@