diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..24e8c1a8 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,273 @@ +{ + "env": { + "browser": true, + "es6": true, + "node": true + }, + "extends": "eslint:recommended", + "parserOptions": { + "sourceType": "module" + }, + "rules": { + "accessor-pairs": "error", + "array-bracket-newline": "error", + "array-bracket-spacing": [ + "error", + "never" + ], + "array-callback-return": "off", + "array-element-newline": "off", + "arrow-body-style": "error", + "arrow-parens": "off", + "arrow-spacing": [ + "error", + { + "after": true, + "before": true + } + ], + "block-scoped-var": "error", + "block-spacing": "error", + "brace-style": "off", + "callback-return": "off", + "camelcase": "off", + "capitalized-comments": "off", + "class-methods-use-this": "off", + "comma-dangle": "error", + "comma-spacing": "off", + "comma-style": [ + "error", + "last" + ], + "complexity": "error", + "computed-property-spacing": [ + "error", + "never" + ], + "consistent-return": "off", + "consistent-this": "off", + "curly": "off", + "default-case": "error", + "dot-location": [ + "error", + "property" + ], + "dot-notation": "off", + "eol-last": "error", + "eqeqeq": "off", + "for-direction": "error", + "func-call-spacing": "error", + "func-name-matching": "error", + "func-names": "off", + "func-style": "off", + "function-paren-newline": "off", + "generator-star-spacing": "error", + "getter-return": "error", + "global-require": "off", + "guard-for-in": "off", + "handle-callback-err": "off", + "id-blacklist": "error", + "id-length": "off", + "id-match": "error", + "indent": "off", + "indent-legacy": "off", + "init-declarations": "off", + "jsx-quotes": "error", + "key-spacing": "off", + "keyword-spacing": "off", + "line-comment-position": "off", + "linebreak-style": [ + "error", + "unix" + ], + "lines-around-comment": "error", + "lines-around-directive": "error", + "max-depth": "error", + "max-len": "off", + "max-lines": "off", + "max-nested-callbacks": "error", + "max-params": "off", + "max-statements": "off", + "max-statements-per-line": "error", + "multiline-ternary": [ + "error", + "never" + ], + "new-parens": "off", + "newline-after-var": "off", + "newline-before-return": "off", + "newline-per-chained-call": "off", + "no-alert": "error", + "no-array-constructor": "error", + "no-await-in-loop": "error", + "no-bitwise": "error", + "no-buffer-constructor": "error", + "no-caller": "error", + "no-catch-shadow": "error", + "no-confusing-arrow": "error", + "no-console": "off", + "no-continue": "off", + "no-div-regex": "error", + "no-duplicate-imports": "error", + "no-else-return": "off", + "no-empty-function": "off", + "no-eq-null": "error", + "no-eval": "off", + "no-extend-native": "error", + "no-extra-bind": "error", + "no-extra-label": "error", + "no-extra-parens": "off", + "no-floating-decimal": "error", + "no-implicit-coercion": "error", + "no-implicit-globals": "error", + "no-implied-eval": "error", + "no-inline-comments": "off", + "no-inner-declarations": [ + "error", + "functions" + ], + "no-invalid-this": "off", + "no-iterator": "error", + "no-label-var": "error", + "no-labels": "error", + "no-lone-blocks": "error", + "no-lonely-if": "off", + "no-loop-func": "error", + "no-magic-numbers": "off", + "no-mixed-operators": "error", + "no-mixed-requires": "error", + "no-multi-assign": "error", + "no-multi-spaces": "off", + "no-multi-str": "error", + "no-multiple-empty-lines": "error", + "no-native-reassign": "error", + "no-negated-condition": "off", + "no-negated-in-lhs": "error", + "no-nested-ternary": "error", + "no-new": "error", + "no-new-func": "error", + "no-new-object": "error", + "no-new-require": "error", + "no-new-wrappers": "error", + "no-octal-escape": "error", + "no-param-reassign": "off", + "no-path-concat": "error", + "no-plusplus": "off", + "no-process-env": "off", + "no-process-exit": "off", + "no-proto": "error", + "no-prototype-builtins": "off", + "no-restricted-globals": "error", + "no-restricted-imports": "error", + "no-restricted-modules": "error", + "no-restricted-properties": "error", + "no-restricted-syntax": "error", + "no-return-assign": "error", + "no-return-await": "error", + "no-script-url": "error", + "no-self-compare": "error", + "no-sequences": "error", + "no-shadow": "off", + "no-shadow-restricted-names": "error", + "no-spaced-func": "error", + "no-sync": "off", + "no-tabs": "error", + "no-template-curly-in-string": "error", + "no-ternary": "off", + "no-throw-literal": "error", + "no-trailing-spaces": "off", + "no-undef-init": "error", + "no-undefined": "off", + "no-underscore-dangle": "off", + "no-unmodified-loop-condition": "error", + "no-unneeded-ternary": "error", + "no-unused-expressions": "error", + "no-unused-vars": ["error", { "argsIgnorePattern": "^_" }], + "no-use-before-define": "off", + "no-useless-call": "off", + "no-useless-computed-key": "error", + "no-useless-concat": "error", + "no-useless-constructor": "error", + "no-useless-rename": "error", + "no-useless-return": "off", + "no-var": "off", + "no-void": "error", + "no-warning-comments": "off", + "no-whitespace-before-property": "error", + "no-with": "error", + "nonblock-statement-body-position": "error", + "object-curly-newline": "off", + "object-curly-spacing": [ + "error", + "never" + ], + "object-property-newline": "off", + "object-shorthand": "off", + "one-var": "off", + "one-var-declaration-per-line": "off", + "operator-assignment": "off", + "operator-linebreak": "error", + "padded-blocks": "off", + "padding-line-between-statements": "error", + "prefer-arrow-callback": "off", + "prefer-const": "off", + "prefer-destructuring": "off", + "prefer-numeric-literals": "error", + "prefer-promise-reject-errors": "error", + "prefer-reflect": "off", + "prefer-rest-params": "off", + "prefer-spread": "off", + "prefer-template": "off", + "quote-props": "off", + "quotes": "off", + "radix": "error", + "require-await": "error", + "require-jsdoc": "off", + "rest-spread-spacing": "error", + "semi": "error", + "semi-spacing": [ + "error", + { + "after": true, + "before": false + } + ], + "semi-style": [ + "error", + "last" + ], + "sort-imports": "error", + "sort-keys": "off", + "sort-vars": "off", + "space-before-blocks": "off", + "space-before-function-paren": "off", + "space-in-parens": [ + "error", + "never" + ], + "space-infix-ops": "off", + "space-unary-ops": "error", + "spaced-comment": "off", + "strict": "error", + "switch-colon-spacing": "error", + "symbol-description": "error", + "template-curly-spacing": [ + "error", + "never" + ], + "template-tag-spacing": "error", + "unicode-bom": [ + "error", + "never" + ], + "valid-jsdoc": "error", + "vars-on-top": "off", + "wrap-iife": "error", + "wrap-regex": "error", + "yield-star-spacing": "error", + "yoda": [ + "error", + "never" + ] + } +} diff --git a/.gitignore b/.gitignore index 162b9c4d..0c56f1e4 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ test_app/.embark/development/ test_app/config/production/password test_app/node_modules/ test_app/chains.json -.idea \ No newline at end of file +.idea +.eslintrc.json diff --git a/README.md b/README.md index f6ff10ab..fc8268e8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ -[![npm](https://img.shields.io/npm/dm/embark.svg)]() -[![Gitter](https://img.shields.io/gitter/room/iurimatias/embark-framework.svg)]() +![Embark](https://github.com/iurimatias/embark-framework/raw/develop/logo.png) + +[![npm](https://img.shields.io/npm/dm/embark.svg)](https://npmjs.com/package/embark) +[![Gitter](https://img.shields.io/gitter/room/iurimatias/embark-framework.svg)](https://gitter.im/iurimatias/embark-framework) [![Build Status](https://travis-ci.org/iurimatias/embark-framework.svg?branch=develop)](https://travis-ci.org/iurimatias/embark-framework) [![Code Climate](https://codeclimate.com/github/iurimatias/embark-framework/badges/gpa.svg)](https://codeclimate.com/github/iurimatias/embark-framework) @@ -55,7 +57,7 @@ Table of Contents Installation ====== -Requirements: geth (1.5.8 or higher), node (6.9.1 or higher is recommended) and npm +Requirements: geth (1.6.5 or higher recommended, 1.6.0 or lower for whisper v1 support; whisper v5 support coming soon), node (6.9.1 or higher is recommended) and npm Optional: testrpc (3.0 or higher) if using the simulator or the test functionality. Further: depending on the dapp stack you choose: [IPFS](https://ipfs.io/) @@ -389,7 +391,7 @@ EmbarkJS - Communication **initialization** -For Whisper: +For Whisper (note: currently requires geth 1.6.0): ```Javascript EmbarkJS.Messages.setProvider('whisper') @@ -549,4 +551,4 @@ For more information on how to develop your own plugin, please see the [plugin d Donations ====== -If you like Embark, please consider donating to 0x8811FdF0F988f0CD1B7E9DE252ABfA5b18c1cDb1 +If you like Embark, please consider donating to 0xFA239D14c7117C3D2370B2a4c4238534391fadd9 diff --git a/boilerplate/config/blockchain.json b/boilerplate/config/blockchain.json index 3453a87d..26c14fcc 100644 --- a/boilerplate/config/blockchain.json +++ b/boilerplate/config/blockchain.json @@ -12,7 +12,8 @@ "rpcCorsDomain": "http://localhost:8000", "account": { "password": "config/development/password" - } + }, + "wsOrigins": "http://localhost:8000" }, "testnet": { "enabled": true, diff --git a/boilerplate/config/communication.json b/boilerplate/config/communication.json index 07c7851a..80ec2f80 100644 --- a/boilerplate/config/communication.json +++ b/boilerplate/config/communication.json @@ -2,6 +2,11 @@ "default": { "enabled": true, "provider": "whisper", - "available_providers": ["whisper", "orbit"] + "available_providers": ["whisper", "orbit"], + "connection": { + "host": "localhost", + "port": 8546, + "type": "ws" + } } } diff --git a/boilerplate/config/contracts.json b/boilerplate/config/contracts.json index f9bbf576..41db174d 100644 --- a/boilerplate/config/contracts.json +++ b/boilerplate/config/contracts.json @@ -1,5 +1,18 @@ { "default": { + "versions": { + "web3.js": "1.0.0-beta", + "solc": "0.4.17" + }, + "deployment": { + "host": "localhost", + "port": 8545, + "type": "rpc" + }, + "dappConnection": [ + "$WEB3", + "http://localhost:8545" + ], "gas": "auto", "contracts": { } diff --git a/boilerplate/config/development/genesis.json b/boilerplate/config/development/genesis.json index 9f2d1562..4a50a438 100644 --- a/boilerplate/config/development/genesis.json +++ b/boilerplate/config/development/genesis.json @@ -1,4 +1,7 @@ { + "config": { + "homesteadBlock": 1 + }, "nonce": "0x0000000000000042", "difficulty": "0x0", "alloc": { diff --git a/boilerplate/config/storage.json b/boilerplate/config/storage.json index f9516470..f1041e84 100644 --- a/boilerplate/config/storage.json +++ b/boilerplate/config/storage.json @@ -11,6 +11,7 @@ "enabled": true, "provider": "ipfs", "host": "localhost", - "port": 5001 + "port": 5001, + "getUrl": "http://localhost:8080/ipfs/" } } diff --git a/boilerplate/package.json b/boilerplate/package.json index a1ab4c7f..46a57488 100644 --- a/boilerplate/package.json +++ b/boilerplate/package.json @@ -9,7 +9,5 @@ "license": "ISC", "homepage": "", "devDependencies": { - "embark": "^2.4.3", - "mocha": "^2.2.5" } } diff --git a/boilerplate/test/contract_spec.js b/boilerplate/test/contract_spec.js index e0a6a9dc..d2a8be47 100644 --- a/boilerplate/test/contract_spec.js +++ b/boilerplate/test/contract_spec.js @@ -1,7 +1,3 @@ -var assert = require('assert'); -var EmbarkSpec = require('embark/lib/core/test.js'); - - // describe("SimpleStorage", function() { // before(function(done) { // this.timeout(0); @@ -29,4 +25,4 @@ var EmbarkSpec = require('embark/lib/core/test.js'); // }); // }); // -// }); \ No newline at end of file +// }); diff --git a/demo/app/contracts/simple_storage.sol b/demo/app/contracts/simple_storage.sol index 13957b2d..955ad899 100644 --- a/demo/app/contracts/simple_storage.sol +++ b/demo/app/contracts/simple_storage.sol @@ -2,15 +2,15 @@ pragma solidity ^0.4.7; contract SimpleStorage { uint public storedData; - function SimpleStorage(uint initialValue) { + function SimpleStorage(uint initialValue) public { storedData = initialValue; } - function set(uint x) { + function set(uint x) public { storedData = x; } - function get() constant returns (uint retVal) { + function get() public view returns (uint retVal) { return storedData; } diff --git a/demo/app/index.html b/demo/app/index.html index 9dcde044..10b27f23 100644 --- a/demo/app/index.html +++ b/demo/app/index.html @@ -77,6 +77,7 @@
+

Listen To channel

diff --git a/demo/app/js/index.js b/demo/app/js/index.js index 2db14830..7799a2f1 100644 --- a/demo/app/js/index.js +++ b/demo/app/js/index.js @@ -114,11 +114,15 @@ $(document).ready(function() { $(document).ready(function() { $("#communication .error").hide(); - web3.version.getWhisper(function(err, res) { + web3.version.getWhisper(function(err, version) { if (err) { $("#communication .error").show(); $("#communication-controls").hide(); $("#status-communication").addClass('status-offline'); + } else if (version >= 5) { + $("#communication .errorVersion").show(); + $("#communication-controls").hide(); + $("#status-communication").addClass('status-offline'); } else { EmbarkJS.Messages.setProvider('whisper'); $("#status-communication").addClass('status-online'); diff --git a/demo/config/blockchain.json b/demo/config/blockchain.json index 0bc6ca2c..18888bd8 100644 --- a/demo/config/blockchain.json +++ b/demo/config/blockchain.json @@ -12,7 +12,8 @@ "rpcCorsDomain": "http://localhost:8000", "account": { "password": "config/development/password" - } + }, + "wsOrigins": "http://localhost:8000" }, "testnet": { "enabled": true, diff --git a/demo/config/communication.json b/demo/config/communication.json index 07c7851a..80ec2f80 100644 --- a/demo/config/communication.json +++ b/demo/config/communication.json @@ -2,6 +2,11 @@ "default": { "enabled": true, "provider": "whisper", - "available_providers": ["whisper", "orbit"] + "available_providers": ["whisper", "orbit"], + "connection": { + "host": "localhost", + "port": 8546, + "type": "ws" + } } } diff --git a/demo/config/contracts.json b/demo/config/contracts.json index b899cb0f..e6dd6ac9 100644 --- a/demo/config/contracts.json +++ b/demo/config/contracts.json @@ -1,5 +1,18 @@ { "default": { + "versions": { + "web3.js": "1.0.0-beta", + "solc": "0.4.17" + }, + "deployment": { + "host": "localhost", + "port": 8545, + "type": "rpc" + }, + "dappConnection": [ + "$WEB3", + "http://localhost:8545" + ], "gas": "auto", "contracts": { "SimpleStorage": { diff --git a/demo/config/development/genesis.json b/demo/config/development/genesis.json index 9f2d1562..4a50a438 100644 --- a/demo/config/development/genesis.json +++ b/demo/config/development/genesis.json @@ -1,4 +1,7 @@ { + "config": { + "homesteadBlock": 1 + }, "nonce": "0x0000000000000042", "difficulty": "0x0", "alloc": { diff --git a/demo/config/storage.json b/demo/config/storage.json index f9516470..f1041e84 100644 --- a/demo/config/storage.json +++ b/demo/config/storage.json @@ -11,6 +11,7 @@ "enabled": true, "provider": "ipfs", "host": "localhost", - "port": 5001 + "port": 5001, + "getUrl": "http://localhost:8080/ipfs/" } } diff --git a/demo/package.json b/demo/package.json index e6a56c6a..f269f3ce 100644 --- a/demo/package.json +++ b/demo/package.json @@ -10,7 +10,5 @@ "license": "ISC", "homepage": "", "devDependencies": { - "embark": "^2.4.3", - "mocha": "^2.2.5" } } diff --git a/demo/test/simple_storage_spec.js b/demo/test/simple_storage_spec.js index b2d3cb17..f760ae3a 100644 --- a/demo/test/simple_storage_spec.js +++ b/demo/test/simple_storage_spec.js @@ -1,8 +1,3 @@ -var assert = require('assert'); -var Embark = require('embark'); -var EmbarkSpec = Embark.initTests(); -var web3 = EmbarkSpec.web3; - describe("SimpleStorage", function() { before(function(done) { this.timeout(0); diff --git a/docs/conf.py b/docs/conf.py index a8b3afd5..0e3adac1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -58,9 +58,9 @@ author = u'Iuri Matias' # built documents. # # The short X.Y version. -version = u'2.4' +version = u'2.6' # The full version, including alpha/beta/rc tags. -release = u'2.4.3' +release = u'2.6.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/donations.md b/docs/donations.md index fe9255f3..77843e33 100644 --- a/docs/donations.md +++ b/docs/donations.md @@ -1,4 +1,4 @@ Donations ====== -If you like Embark please consider donating to 0x8811FdF0F988f0CD1B7E9DE252ABfA5b18c1cDb1 +If you like Embark please consider donating to 0xFA239D14c7117C3D2370B2a4c4238534391fadd9 diff --git a/docs/donations.rst b/docs/donations.rst index d4daeb63..e8ebe277 100644 --- a/docs/donations.rst +++ b/docs/donations.rst @@ -1,5 +1,4 @@ Donations ========= -If you like Embark please consider donating to -0x8811FdF0F988f0CD1B7E9DE252ABfA5b18c1cDb1 +If you like Embark please consider donating to 0xFA239D14c7117C3D2370B2a4c4238534391fadd9 diff --git a/docs/embarkjs.rst b/docs/embarkjs.rst index dd6a39fc..a3bb1754 100644 --- a/docs/embarkjs.rst +++ b/docs/embarkjs.rst @@ -11,7 +11,7 @@ methods in EmbarkJS contracts will be converted to promises. .. code:: javascript var myContract = new EmbarkJS.Contract({abi: abiObject, address: "0x123"}); - myContract.get().then(function(value) { console.log("value is " + value.toNumber) }); + myContract.get().then(function(value) { console.log("value is " + value.toNumber()) }); **deployment** diff --git a/docs/installation.rst b/docs/installation.rst index ae27adab..c2b7c23b 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -1,7 +1,7 @@ Installation ============ -Requirements: geth (1.5.8 or higher), node (6.9.1 or higher is recommended) and npm +Requirements: geth (1.6.5 or higher recommended), node (6.9.1 or higher is recommended) and npm serpent (develop) if using contracts with Serpent, testrpc (3.0 or higher) if using the simulator or the test functionality. Further: depending on the dapp stack you choose: `IPFS `__ diff --git a/js/embark.js b/js/embark.js index 50e700bd..1387ef59 100644 --- a/js/embark.js +++ b/js/embark.js @@ -7,103 +7,122 @@ var EmbarkJS = {}; +EmbarkJS.isNewWeb3 = function() { + var _web3 = new Web3(); + if (typeof(_web3.version) === "string") { + return true; + } + return parseInt(_web3.version.api.split('.')[0], 10) >= 1; +}; + EmbarkJS.Contract = function(options) { var self = this; var i, abiElement; + var ContractClass; this.abi = options.abi; this.address = options.address; this.code = '0x' + options.code; this.web3 = options.web3 || web3; - var ContractClass = this.web3.eth.contract(this.abi); + if (EmbarkJS.isNewWeb3()) { + // TODO: + // add default **from** address + // add gasPrice + ContractClass = new this.web3.eth.Contract(this.abi, this.address); + ContractClass.setProvider(this.web3.currentProvider); - this.eventList = []; + return ContractClass; + } else { + ContractClass = this.web3.eth.contract(this.abi); - if (this.abi) { + this.eventList = []; + + if (this.abi) { for (i = 0; i < this.abi.length; i++) { - abiElement = this.abi[i]; - if (abiElement.type === 'event') { - this.eventList.push(abiElement.name); - } + abiElement = this.abi[i]; + if (abiElement.type === 'event') { + this.eventList.push(abiElement.name); + } } - } + } - var messageEvents = function() { + var messageEvents = function() { this.cb = function() {}; - }; + }; - messageEvents.prototype.then = function(cb) { + messageEvents.prototype.then = function(cb) { this.cb = cb; - }; + }; - messageEvents.prototype.error = function(err) { + messageEvents.prototype.error = function(err) { return err; - }; + }; - this._originalContractObject = ContractClass.at(this.address); - this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function(p) { + this._originalContractObject = ContractClass.at(this.address); + this._methods = Object.getOwnPropertyNames(this._originalContractObject).filter(function(p) { // TODO: check for forbidden properties if (self.eventList.indexOf(p) >= 0) { - self[p] = function() { - var promise = new messageEvents(); - var args = Array.prototype.slice.call(arguments); - args.push(function(err, result) { - if (err) { - promise.error(err); - } else { - promise.cb(result); - } - }); + self[p] = function() { + var promise = new messageEvents(); + var args = Array.prototype.slice.call(arguments); + args.push(function(err, result) { + if (err) { + promise.error(err); + } else { + promise.cb(result); + } + }); - self._originalContractObject[p].apply(self._originalContractObject[p], args); - return promise; - }; - return true; + self._originalContractObject[p].apply(self._originalContractObject[p], args); + return promise; + }; + return true; } else if (typeof self._originalContractObject[p] === 'function') { - self[p] = function(_args) { - var args = Array.prototype.slice.call(arguments); - var fn = self._originalContractObject[p]; - var props = self.abi.find((x) => x.name == p); + self[p] = function(_args) { + var args = Array.prototype.slice.call(arguments); + var fn = self._originalContractObject[p]; + var props = self.abi.find((x) => x.name == p); - var promise = new Promise(function(resolve, reject) { - args.push(function(err, transaction) { - promise.tx = transaction; - if (err) { - return reject(err); - } + var promise = new Promise(function(resolve, reject) { + args.push(function(err, transaction) { + promise.tx = transaction; + if (err) { + return reject(err); + } - var getConfirmation = function() { - self.web3.eth.getTransactionReceipt(transaction, function(err, receipt) { - if (err) { - return reject(err); - } + var getConfirmation = function() { + self.web3.eth.getTransactionReceipt(transaction, function(err, receipt) { + if (err) { + return reject(err); + } - if (receipt !== null) { - return resolve(receipt); - } + if (receipt !== null) { + return resolve(receipt); + } - setTimeout(getConfirmation, 1000); - }); - }; + setTimeout(getConfirmation, 1000); + }); + }; - if (typeof(transaction) !== "string" || props.constant) { - resolve(transaction); - } else { - getConfirmation(); - } - }); + if (typeof(transaction) !== "string" || props.constant) { + resolve(transaction); + } else { + getConfirmation(); + } + }); - fn.apply(fn, args); - }); + fn.apply(fn, args); + }); - return promise; - }; - return true; + return promise; + }; + return true; } return false; - }); + }); + } }; EmbarkJS.Contract.prototype.deploy = function(args, _options) { @@ -208,8 +227,10 @@ EmbarkJS.Storage.setProvider = function(provider, options) { try { if (options === undefined) { self.ipfsConnection = IpfsApi('localhost', '5001'); + self.getUrl = "http://localhost:8080/ipfs/"; } else { self.ipfsConnection = IpfsApi(options.server, options.port); + self.getUrl = options.getUrl || "http://localhost:8080/ipfs/"; } resolve(self); } catch (err) { @@ -299,9 +320,7 @@ EmbarkJS.Storage.IPFS.uploadFile = function(inputSelector) { }; EmbarkJS.Storage.IPFS.getUrl = function(hash) { - //var ipfsHash = web3.toAscii(hash); - - return 'http://localhost:8080/ipfs/' + hash; + return (self.getUrl || "http://localhost:8080/ipfs/") + hash; }; //========================================================= @@ -310,34 +329,80 @@ EmbarkJS.Storage.IPFS.getUrl = function(hash) { EmbarkJS.Messages = {}; +EmbarkJS.Messages.web3CompatibleWithV5 = function() { + var _web3 = new Web3(); + if (typeof(_web3.version) === "string") { + return true; + } + return parseInt(_web3.version.api.split('.')[1], 10) >= 20; +}; + +EmbarkJS.Messages.isNewWeb3 = function() { + var _web3 = new Web3(); + if (typeof(_web3.version) === "string") { + return true; + } + return parseInt(_web3.version.api.split('.')[0], 10) >= 1; +}; + +EmbarkJS.Messages.getWhisperVersion = function(cb) { + if (this.isNewWeb3()) { + this.currentMessages.web3.shh.getVersion(function(err, version) { + cb(err, version); + }); + } else { + this.currentMessages.web3.version.getWhisper(function(err, res) { + cb(err, web3.version.whisper); + }); + } +}; + EmbarkJS.Messages.setProvider = function(provider, options) { var self = this; var ipfs; if (provider === 'whisper') { + this.providerName = 'whisper'; this.currentMessages = EmbarkJS.Messages.Whisper; - if (typeof variable === 'undefined') { - if (options === undefined) { - web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); - } else { - web3 = new Web3(new Web3.providers.HttpProvider("http://" + options.server + ':' + options.port)); - } + let provider; + if (options === undefined) { + provider = "localhost:8546"; + } else { + provider = options.server + ':' + options.port; } - web3.version.getWhisper(function(err, res) { + if (this.isNewWeb3()) { + self.currentMessages.web3 = new Web3(new Web3.providers.WebsocketProvider("ws://" + provider)); + } else { + self.currentMessages.web3 = new Web3(new Web3.providers.HttpProvider("http://" + provider)); + } + self.getWhisperVersion(function(err, version) { if (err) { console.log("whisper not available"); + } else if (version >= 5) { + if (self.web3CompatibleWithV5()) { + self.currentMessages.web3.shh.newSymKey().then((id) => {self.currentMessages.symKeyID = id;}); + self.currentMessages.web3.shh.newKeyPair().then((id) => {self.currentMessages.sig = id;}); + } else { + console.log("this version of whisper in this node"); + } } else { - self.currentMessages.identity = web3.shh.newIdentity(); + self.currentMessages.identity = self.currentMessages.web3.shh.newIdentity(); } + self.currentMessages.whisperVersion = self.currentMessages.web3.version.whisper; }); } else if (provider === 'orbit') { + this.providerName = 'orbit'; this.currentMessages = EmbarkJS.Messages.Orbit; if (options === undefined) { ipfs = HaadIpfsApi('localhost', '5001'); } else { - ipfs = HaadIpfsApi(options.server, options.port); + ipfs = HaadIpfsApi(options.host, options.port); } this.currentMessages.orbit = new Orbit(ipfs); - this.currentMessages.orbit.connect(web3.eth.accounts[0]); + if (typeof(web3) === "undefined") { + this.currentMessages.orbit.connect(Math.random().toString(36).substring(2)); + } else { + this.currentMessages.orbit.connect(web3.eth.accounts[0]); + } } else { throw Error('Unknown message provider'); } @@ -354,100 +419,179 @@ EmbarkJS.Messages.listenTo = function(options) { EmbarkJS.Messages.Whisper = {}; EmbarkJS.Messages.Whisper.sendMessage = function(options) { - var topics = options.topic || options.topics; - var data = options.data || options.payload; - var identity = options.identity || this.identity || web3.shh.newIdentity(); - var ttl = options.ttl || 100; - var priority = options.priority || 1000; - var _topics; + var topics, data, ttl, priority, payload; + if (EmbarkJS.Messages.isNewWeb3()) { + topics = options.topic || options.topics; + data = options.data || options.payload; + ttl = options.ttl || 100; + priority = options.priority || 1000; + var powTime = options.powTime || 3; + var powTarget = options.powTarget || 0.5; if (topics === undefined) { - throw new Error("missing option: topic"); + throw new Error("missing option: topic"); } if (data === undefined) { - throw new Error("missing option: data"); + throw new Error("missing option: data"); + } + + topics = this.web3.utils.toHex(topics).slice(0, 10); + + payload = JSON.stringify(data); + + let message = { + symKeyID: this.symKeyID, // encrypts using the sym key ID + sig: this.sig, // signs the message using the keyPair ID + ttl: ttl, + topic: topics, + payload: EmbarkJS.Utils.fromAscii(payload), + powTime: powTime, + powTarget: powTarget + }; + + this.web3.shh.post(message, function() { }); + } else { + topics = options.topic || options.topics; + data = options.data || options.payload; + ttl = options.ttl || 100; + priority = options.priority || 1000; + var identity = options.identity || this.identity || web3.shh.newIdentity(); + var _topics; + + if (topics === undefined) { + throw new Error("missing option: topic"); + } + + if (data === undefined) { + throw new Error("missing option: data"); } - // do fromAscii to each topics unless it's already a string if (typeof topics === 'string') { - _topics = [web3.fromAscii(topics)]; + _topics = [EmbarkJS.Utils.fromAscii(topics)]; } else { - // TODO: replace with es6 + babel; - for (var i = 0; i < topics.length; i++) { - _topics.push(web3.fromAscii(topics[i])); - } + _topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t)); } topics = _topics; - var payload = JSON.stringify(data); + payload = JSON.stringify(data); - var message = { - from: identity, - topics: topics, - payload: web3.fromAscii(payload), - ttl: ttl, - priority: priority + var message; + message = { + from: identity, + topics: topics, + payload: EmbarkJS.Utils.fromAscii(payload), + ttl: ttl, + priority: priority }; - return web3.shh.post(message, function() {}); + return EmbarkJS.Messages.currentMessages.web3.shh.post(message, function() { }); + } }; EmbarkJS.Messages.Whisper.listenTo = function(options) { - var topics = options.topic || options.topics; - var _topics = []; - - if (typeof topics === 'string') { - _topics = [topics]; - } else { - // TODO: replace with es6 + babel; - for (var i = 0; i < topics.length; i++) { - _topics.push(topics[i]); - } - } - topics = _topics; - - var filterOptions = { - topics: topics - }; - - var messageEvents = function() { - this.cb = function() {}; + var topics, _topics, messageEvents; + if (EmbarkJS.Messages.isNewWeb3()) { + messageEvents = function() { + this.cb = function() {}; }; messageEvents.prototype.then = function(cb) { - this.cb = cb; + this.cb = cb; }; messageEvents.prototype.error = function(err) { - return err; + return err; }; messageEvents.prototype.stop = function() { - this.filter.stopWatching(); + this.filter.stopWatching(); }; - var promise = new messageEvents(); + topics = options.topic || options.topics; + _topics = []; - var filter = web3.shh.filter(filterOptions, function(err, result) { - var payload = JSON.parse(web3.toAscii(result.payload)); - var data; - if (err) { - promise.error(err); - } else { - data = { - topic: topics, - data: payload, - from: result.from, - time: (new Date(result.sent * 1000)) - }; - promise.cb(payload, data, result); - } + let promise = new messageEvents(); + + // listenTo + if (typeof topics === 'string') { + topics = [this.web3.utils.toHex(topics).slice(0, 10)]; + } else { + topics = topics.map((t) => this.web3.utils.toHex(t).slice(0, 10)); + } + + let filter = this.web3.shh.subscribe("messages", { + symKeyID: this.symKeyID, + topics: topics + }).on('data', function(result) { + var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload)); + var data; + data = { + topic: result.topic, + data: payload, + //from: result.from, + time: result.timestamp + }; + + promise.cb(payload, data, result); }); promise.filter = filter; return promise; + } else { + topics = options.topic || options.topics; + _topics = []; + + messageEvents = function() { + this.cb = function() {}; + }; + + messageEvents.prototype.then = function(cb) { + this.cb = cb; + }; + + messageEvents.prototype.error = function(err) { + return err; + }; + + messageEvents.prototype.stop = function() { + this.filter.stopWatching(); + }; + + if (typeof topics === 'string') { + _topics = [topics]; + } else { + _topics = topics.map((t) => EmbarkJS.Utils.fromAscii(t)); + } + topics = _topics; + + var filterOptions = { + topics: topics + }; + + let promise = new messageEvents(); + + let filter = this.web3.shh.filter(filterOptions, function(err, result) { + var payload = JSON.parse(EmbarkJS.Utils.toAscii(result.payload)); + var data; + if (err) { + promise.error(err); + } else { + data = { + topic: topics, + data: payload, + from: result.from, + time: (new Date(result.sent * 1000)) + }; + promise.cb(payload, data, result); + } + }); + + promise.filter = filter; + + return promise; + } }; EmbarkJS.Messages.Orbit = {}; @@ -521,4 +665,15 @@ EmbarkJS.Messages.Orbit.listenTo = function(options) { return promise; }; +EmbarkJS.Utils = { + fromAscii: function(str) { + var _web3 = new Web3(); + return _web3.utils ? _web3.utils.fromAscii(str) : _web3.fromAscii(str); + }, + toAscii: function(str) { + var _web3 = new Web3(); + return _web3.utils.toAscii(str); + } +}; + module.exports = EmbarkJS; diff --git a/js/web3-1.0.min.js b/js/web3-1.0.min.js new file mode 100644 index 00000000..6eef69f5 --- /dev/null +++ b/js/web3-1.0.min.js @@ -0,0 +1 @@ +"use strict";var _typeof2="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof="function"==typeof Symbol&&"symbol"===_typeof2(Symbol.iterator)?function(e){return void 0===e?"undefined":_typeof2(e)}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":void 0===e?"undefined":_typeof2(e)};!function(e){if("object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Web3=e()}}(function(){var define,module,exports;return function e(t,n,i){function r(a,s){if(!n[a]){if(!t[a]){var c="function"==typeof require&&require;if(!s&&c)return c(a,!0);if(o)return o(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var l=n[a]={exports:{}};t[a][0].call(l.exports,function(e){var n=t[a][1][e];return r(n||e)},l,l.exports,e,t,n,i)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;a>6],r=0==(32&n);if(31==(31&n)){var o=n;for(n=0;128==(128&o);){if(o=e.readUInt8(t),e.isError(o))return o;n<<=7,n|=127&o}}else n&=31;return{cls:i,primitive:r,tag:n,tagStr:f.tag[n]}}function a(e,t,n){var i=e.readUInt8(n);if(e.isError(i))return i;if(!t&&128===i)return null;if(0==(128&i))return i;var r=127&i;if(r>4)return e.error("length octect is too long");i=0;for(var o=0;o=31?i.error("Multi-octet tag encoding unsupported"):(t||(r|=32),r|=f.tagClassByName[n||"universal"]<<6)}var s=e("inherits"),c=e("buffer").Buffer,u=e("../../asn1"),l=u.base,f=u.constants.der;t.exports=i,i.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},s(r,l.Node),r.prototype._encodeComposite=function(e,t,n,i){var r=a(e,t,n,this.reporter);if(i.length<128)return(u=new c(2))[0]=r,u[1]=i.length,this._createEncoderBuffer([u,i]);for(var o=1,s=i.length;s>=256;s>>=8)o++;var u=new c(2+o);u[0]=r,u[1]=128|o;for(var s=1+o,l=i.length;l>0;s--,l>>=8)u[s]=255&l;return this._createEncoderBuffer([u,i])},r.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){for(var n=new c(2*e.length),i=0;i=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}for(var i=0,r=0;r=128;s>>=7)i++}for(var o=new c(i),a=o.length-1,r=e.length-1;r>=0;r--){var s=e[r];for(o[a--]=127&s;(s>>=7)>0;)o[a--]=128|127&s}return this._createEncoderBuffer(o)},r.prototype._encodeTime=function(e,t){var n,i=new Date(e);return"gentime"===t?n=[o(i.getFullYear()),o(i.getUTCMonth()+1),o(i.getUTCDate()),o(i.getUTCHours()),o(i.getUTCMinutes()),o(i.getUTCSeconds()),"Z"].join(""):"utctime"===t?n=[o(i.getFullYear()%100),o(i.getUTCMonth()+1),o(i.getUTCDate()),o(i.getUTCHours()),o(i.getUTCMinutes()),o(i.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(n,"octstr")},r.prototype._encodeNull=function(){return this._createEncoderBuffer("")},r.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if("number"!=typeof e&&!c.isBuffer(e)){var n=e.toArray();!e.sign&&128&n[0]&&n.unshift(0),e=new c(n)}if(c.isBuffer(e)){r=e.length;0===e.length&&r++;var i=new c(r);return e.copy(i),0===e.length&&(i[0]=0),this._createEncoderBuffer(i)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);for(var r=1,o=e;o>=256;o>>=8)r++;for(o=(i=new Array(r)).length-1;o>=0;o--)i[o]=255&e,e>>=8;return 128&i[0]&&i.unshift(0),this._createEncoderBuffer(new c(i))},r.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},r.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},r.prototype._skipDefault=function(e,t,n){var i,r=this._baseState;if(null===r.default)return!1;var o=e.join();if(void 0===r.defaultBuffer&&(r.defaultBuffer=this._encodeValue(r.default,t,n).join()),o.length!==r.defaultBuffer.length)return!1;for(i=0;i0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===e[t-2]?2:"="===e[t-1]?1:0}function r(e){return a[e>>18&63]+a[e>>12&63]+a[e>>6&63]+a[63&e]}function o(e,t,n){for(var i,o=[],a=t;a0?u-4:u;var l=0;for(t=0;t>16&255,a[l++]=r>>8&255,a[l++]=255&r;return 2===o?(r=s[e.charCodeAt(t)]<<2|s[e.charCodeAt(t+1)]>>4,a[l++]=255&r):1===o&&(r=s[e.charCodeAt(t)]<<10|s[e.charCodeAt(t+1)]<<4|s[e.charCodeAt(t+2)]>>2,a[l++]=r>>8&255,a[l++]=255&r),a},n.fromByteArray=function(e){for(var t,n=e.length,i=n%3,r="",s=[],c=0,u=n-i;cu?u:c+16383));return 1===i?(t=e[n-1],r+=a[t>>2],r+=a[t<<4&63],r+="=="):2===i&&(t=(e[n-2]<<8)+e[n-1],r+=a[t>>10],r+=a[t>>4&63],r+=a[t<<2&63],r+="="),s.push(r),s.join("")};for(var a=[],s=[],c="undefined"!=typeof Uint8Array?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,f=u.length;l>>24]^l[h>>>16&255]^f[m>>>8&255]^p[255&v]^t[b++],a=u[h>>>24]^l[m>>>16&255]^f[v>>>8&255]^p[255&d]^t[b++],s=u[m>>>24]^l[v>>>16&255]^f[d>>>8&255]^p[255&h]^t[b++],c=u[v>>>24]^l[d>>>16&255]^f[h>>>8&255]^p[255&m]^t[b++],d=o,h=a,m=s,v=c;return o=(i[d>>>24]<<24|i[h>>>16&255]<<16|i[m>>>8&255]<<8|i[255&v])^t[b++],a=(i[h>>>24]<<24|i[m>>>16&255]<<16|i[v>>>8&255]<<8|i[255&d])^t[b++],s=(i[m>>>24]<<24|i[v>>>16&255]<<16|i[d>>>8&255]<<8|i[255&h])^t[b++],c=(i[v>>>24]<<24|i[d>>>16&255]<<16|i[h>>>8&255]<<8|i[255&m])^t[b++],o>>>=0,a>>>=0,s>>>=0,c>>>=0,[o,a,s,c]}function a(e){this._key=i(e),this._reset()}var s=e("safe-buffer").Buffer,c=[0,1,2,4,8,16,32,64,128,27,54],u=function(){for(var e=new Array(256),t=0;t<256;t++)e[t]=t<128?t<<1:t<<1^283;for(var n=[],i=[],r=[[],[],[],[]],o=[[],[],[],[]],a=0,s=0,c=0;c<256;++c){var u=s^s<<1^s<<2^s<<3^s<<4;u=u>>>8^255&u^99,n[a]=u,i[u]=a;var l=e[a],f=e[l],p=e[f],d=257*e[u]^16843008*u;r[0][a]=d<<24|d>>>8,r[1][a]=d<<16|d>>>16,r[2][a]=d<<8|d>>>24,r[3][a]=d,d=16843009*p^65537*f^257*l^16843008*a,o[0][u]=d<<24|d>>>8,o[1][u]=d<<16|d>>>16,o[2][u]=d<<8|d>>>24,o[3][u]=d,0===a?a=s=1:(a=l^e[e[e[p^l]]],s^=e[e[s]])}return{SBOX:n,INV_SBOX:i,SUB_MIX:r,INV_SUB_MIX:o}}();a.blockSize=16,a.keySize=32,a.prototype.blockSize=a.blockSize,a.prototype.keySize=a.keySize,a.prototype._reset=function(){for(var e=this._key,t=e.length,n=t+6,i=4*(n+1),r=[],o=0;o>>24,a=u.SBOX[a>>>24]<<24|u.SBOX[a>>>16&255]<<16|u.SBOX[a>>>8&255]<<8|u.SBOX[255&a],a^=c[o/t|0]<<24):t>6&&o%t==4&&(a=u.SBOX[a>>>24]<<24|u.SBOX[a>>>16&255]<<16|u.SBOX[a>>>8&255]<<8|u.SBOX[255&a]),r[o]=r[o-t]^a}for(var s=[],l=0;l>>24]]^u.INV_SUB_MIX[1][u.SBOX[p>>>16&255]]^u.INV_SUB_MIX[2][u.SBOX[p>>>8&255]]^u.INV_SUB_MIX[3][u.SBOX[255&p]]}this._nRounds=n,this._keySchedule=r,this._invKeySchedule=s},a.prototype.encryptBlockRaw=function(e){return e=i(e),o(e,this._keySchedule,u.SUB_MIX,u.SBOX,this._nRounds)},a.prototype.encryptBlock=function(e){var t=this.encryptBlockRaw(e),n=s.allocUnsafe(16);return n.writeUInt32BE(t[0],0),n.writeUInt32BE(t[1],4),n.writeUInt32BE(t[2],8),n.writeUInt32BE(t[3],12),n},a.prototype.decryptBlock=function(e){var t=(e=i(e))[1];e[1]=e[3],e[3]=t;var n=o(e,this._invKeySchedule,u.INV_SUB_MIX,u.INV_SBOX,this._nRounds),r=s.allocUnsafe(16);return r.writeUInt32BE(n[0],0),r.writeUInt32BE(n[3],4),r.writeUInt32BE(n[2],8),r.writeUInt32BE(n[1],12),r},a.prototype.scrub=function(){r(this._keySchedule),r(this._invKeySchedule),r(this._key)},t.exports.AES=a},{"safe-buffer":144}],19:[function(e,t,n){function i(e,t){var n=0;e.length!==t.length&&n++;for(var i=Math.min(e.length,t.length),r=0;r16)return t=this.cache.slice(0,16),this.cache=this.cache.slice(16),t}else if(this.cache.length>=16)return t=this.cache.slice(0,16),this.cache=this.cache.slice(16),t;return null},r.prototype.flush=function(){if(this.cache.length)return this.cache},n.createDecipher=function(e,t){var n=u[e.toLowerCase()];if(!n)throw new TypeError("invalid suite type");var i=d(t,!1,n.key,n.iv);return a(e,i.key,i.iv)},n.createDecipheriv=a},{"./aes":18,"./authCipher":19,"./modes":30,"./streamCipher":33,"cipher-base":48,evp_bytestokey:84,inherits:101,"safe-buffer":144}],22:[function(e,t,n){function i(e,t,n){l.call(this),this._cache=new r,this._cipher=new f.AES(t),this._prev=c.from(n),this._mode=e,this._autopadding=!0}function r(){this.cache=c.allocUnsafe(0)}function o(e,t,n){var r=a[e.toLowerCase()];if(!r)throw new TypeError("invalid suite type");if("string"==typeof t&&(t=c.from(t)),t.length!==r.key/8)throw new TypeError("invalid key length "+t.length);if("string"==typeof n&&(n=c.from(n)),n.length!==r.iv)throw new TypeError("invalid iv length "+n.length);return"stream"===r.type?new u(r.module,t,n):"auth"===r.type?new s(r.module,t,n):new i(r.module,t,n)}var a=e("./modes"),s=e("./authCipher"),c=e("safe-buffer").Buffer,u=e("./streamCipher"),l=e("cipher-base"),f=e("./aes"),p=e("evp_bytestokey");e("inherits")(i,l),i.prototype._update=function(e){this._cache.add(e);for(var t,n,i=[];t=this._cache.get();)n=this._mode.encrypt(this,t),i.push(n);return c.concat(i)};var d=c.alloc(16,16);i.prototype._final=function(){var e=this._cache.flush();if(this._autopadding)return e=this._mode.encrypt(this,e),this._cipher.scrub(),e;if(!e.equals(d))throw this._cipher.scrub(),new Error("data not multiple of block length")},i.prototype.setAutoPadding=function(e){return this._autopadding=!!e,this},r.prototype.add=function(e){this.cache=c.concat([this.cache,e])},r.prototype.get=function(){if(this.cache.length>15){var e=this.cache.slice(0,16);return this.cache=this.cache.slice(16),e}return null},r.prototype.flush=function(){for(var e=16-this.cache.length,t=c.allocUnsafe(e),n=-1;++n>>0,0),t.writeUInt32BE(e[1]>>>0,4),t.writeUInt32BE(e[2]>>>0,8),t.writeUInt32BE(e[3]>>>0,12),t}function o(e){this.h=e,this.state=a.alloc(16,0),this.cache=a.allocUnsafe(0)}var a=e("safe-buffer").Buffer,s=a.alloc(16,0);o.prototype.ghash=function(e){for(var t=-1;++t0;e--)n[e]=n[e]>>>1|(1&n[e-1])<<31;n[0]=n[0]>>>1,t&&(n[0]=n[0]^225<<24)}this.state=r(o)},o.prototype.update=function(e){this.cache=a.concat([this.cache,e]);for(var t;this.cache.length>=16;)t=this.cache.slice(0,16),this.cache=this.cache.slice(16),this.ghash(t)},o.prototype.final=function(e,t){return this.cache.length&&this.ghash(a.concat([this.cache,s],16)),this.ghash(r([0,e,0,t])),this.state},t.exports=o},{"safe-buffer":144}],24:[function(e,t,n){var i=e("buffer-xor");n.encrypt=function(e,t){var n=i(t,e._prev);return e._prev=e._cipher.encryptBlock(n),e._prev},n.decrypt=function(e,t){var n=e._prev;e._prev=t;var r=e._cipher.decryptBlock(t);return i(r,n)}},{"buffer-xor":46}],25:[function(e,t,n){function i(e,t,n){var i=t.length,a=o(t,e._cache);return e._cache=e._cache.slice(i),e._prev=r.concat([e._prev,n?t:a]),a}var r=e("safe-buffer").Buffer,o=e("buffer-xor");n.encrypt=function(e,t,n){for(var o,a=r.allocUnsafe(0);t.length;){if(0===e._cache.length&&(e._cache=e._cipher.encryptBlock(e._prev),e._prev=r.allocUnsafe(0)),!(e._cache.length<=t.length)){a=r.concat([a,i(e,t,n)]);break}o=e._cache.length,a=r.concat([a,i(e,t.slice(0,o),n)]),t=t.slice(o)}return a}},{"buffer-xor":46,"safe-buffer":144}],26:[function(e,t,n){function i(e,t,n){for(var i,o,a,s=-1,c=0;++s<8;)i=e._cipher.encryptBlock(e._prev),o=t&1<<7-s?128:0,c+=(128&(a=i[0]^o))>>s%8,e._prev=r(e._prev,n?o:a);return c}function r(e,t){var n=e.length,i=-1,r=o.allocUnsafe(e.length);for(e=o.concat([e,o.from([t])]);++i>7;return r}var o=e("safe-buffer").Buffer;n.encrypt=function(e,t,n){for(var r=t.length,a=o.allocUnsafe(r),s=-1;++s=0||!n.umod(e.prime1)||!n.umod(e.prime2);)n=new a(s(t));return n}var a=e("bn.js"),s=e("randombytes");t.exports=r,r.getr=o}).call(this,e("buffer").Buffer)},{"bn.js":"BN",buffer:47,randombytes:127}],38:[function(e,t,n){t.exports=e("./browser/algorithms.json")},{"./browser/algorithms.json":39}],39:[function(e,t,n){t.exports={sha224WithRSAEncryption:{sign:"rsa",hash:"sha224",id:"302d300d06096086480165030402040500041c"},"RSA-SHA224":{sign:"ecdsa/rsa",hash:"sha224",id:"302d300d06096086480165030402040500041c"},sha256WithRSAEncryption:{sign:"rsa",hash:"sha256",id:"3031300d060960864801650304020105000420"},"RSA-SHA256":{sign:"ecdsa/rsa",hash:"sha256",id:"3031300d060960864801650304020105000420"},sha384WithRSAEncryption:{sign:"rsa",hash:"sha384",id:"3041300d060960864801650304020205000430"},"RSA-SHA384":{sign:"ecdsa/rsa",hash:"sha384",id:"3041300d060960864801650304020205000430"},sha512WithRSAEncryption:{sign:"rsa",hash:"sha512",id:"3051300d060960864801650304020305000440"},"RSA-SHA512":{sign:"ecdsa/rsa",hash:"sha512",id:"3051300d060960864801650304020305000440"},"RSA-SHA1":{sign:"rsa",hash:"sha1",id:"3021300906052b0e03021a05000414"},"ecdsa-with-SHA1":{sign:"ecdsa",hash:"sha1",id:""},sha256:{sign:"ecdsa",hash:"sha256",id:""},sha224:{sign:"ecdsa",hash:"sha224",id:""},sha384:{sign:"ecdsa",hash:"sha384",id:""},sha512:{sign:"ecdsa",hash:"sha512",id:""},"DSA-SHA":{sign:"dsa",hash:"sha1",id:""},"DSA-SHA1":{sign:"dsa",hash:"sha1",id:""},DSA:{sign:"dsa",hash:"sha1",id:""},"DSA-WITH-SHA224":{sign:"dsa",hash:"sha224",id:""},"DSA-SHA224":{sign:"dsa",hash:"sha224",id:""},"DSA-WITH-SHA256":{sign:"dsa",hash:"sha256",id:""},"DSA-SHA256":{sign:"dsa",hash:"sha256",id:""},"DSA-WITH-SHA384":{sign:"dsa",hash:"sha384",id:""},"DSA-SHA384":{sign:"dsa",hash:"sha384",id:""},"DSA-WITH-SHA512":{sign:"dsa",hash:"sha512",id:""},"DSA-SHA512":{sign:"dsa",hash:"sha512",id:""},"DSA-RIPEMD160":{sign:"dsa",hash:"rmd160",id:""},ripemd160WithRSA:{sign:"rsa",hash:"rmd160",id:"3021300906052b2403020105000414"},"RSA-RIPEMD160":{sign:"rsa",hash:"rmd160",id:"3021300906052b2403020105000414"},md5WithRSAEncryption:{sign:"rsa",hash:"md5",id:"3020300c06082a864886f70d020505000410"},"RSA-MD5":{sign:"rsa",hash:"md5",id:"3020300c06082a864886f70d020505000410"}}},{}],40:[function(e,t,n){t.exports={"1.3.132.0.10":"secp256k1","1.3.132.0.33":"p224","1.2.840.10045.3.1.1":"p192","1.2.840.10045.3.1.7":"p256","1.3.132.0.34":"p384","1.3.132.0.35":"p521"}},{}],41:[function(e,t,n){(function(n){function i(e){c.Writable.call(this);var t=p[e];if(!t)throw new Error("Unknown message digest");this._hashType=t.hash,this._hash=s(t.hash),this._tag=t.id,this._signType=t.sign}function r(e){c.Writable.call(this);var t=p[e];if(!t)throw new Error("Unknown message digest");this._hash=s(t.hash),this._tag=t.id,this._signType=t.sign}function o(e){return new i(e)}function a(e){return new r(e)}var s=e("create-hash"),c=e("stream"),u=e("inherits"),l=e("./sign"),f=e("./verify"),p=e("./algorithms.json");Object.keys(p).forEach(function(e){p[e].id=new n(p[e].id,"hex"),p[e.toLowerCase()]=p[e]}),u(i,c.Writable),i.prototype._write=function(e,t,n){this._hash.update(e),n()},i.prototype.update=function(e,t){return"string"==typeof e&&(e=new n(e,t)),this._hash.update(e),this},i.prototype.sign=function(e,t){this.end();var n=this._hash.digest(),i=l(n,e,this._hashType,this._signType,this._tag);return t?i.toString(t):i},u(r,c.Writable),r.prototype._write=function(e,t,n){this._hash.update(e),n()},r.prototype.update=function(e,t){return"string"==typeof e&&(e=new n(e,t)),this._hash.update(e),this},r.prototype.verify=function(e,t,i){"string"==typeof t&&(t=new n(t,i)),this.end();var r=this._hash.digest();return f(t,r,e,this._signType,this._tag)},t.exports={Sign:o,Verify:a,createSign:o,createVerify:a}}).call(this,e("buffer").Buffer)},{"./algorithms.json":39,"./sign":42,"./verify":43,buffer:47,"create-hash":51,inherits:101,stream:155}],42:[function(e,t,n){(function(n){function i(e,t){var i=v[t.curve.join(".")];if(!i)throw new Error("unknown curve "+t.curve.join("."));var r=new d(i).keyFromPrivate(t.privateKey).sign(e);return new n(r.toDER())}function r(e,t,n){for(var i,r=t.params.priv_key,c=t.params.p,f=t.params.q,p=t.params.g,d=new h(0),m=s(e,f).mod(f),v=!1,b=a(r,f,e,n);!1===v;)d=l(p,i=u(f,b,n),c,f),0===(v=i.invm(f).imul(m.add(r.mul(d))).mod(f)).cmpn(0)&&(v=!1,d=new h(0));return o(d,v)}function o(e,t){e=e.toArray(),t=t.toArray(),128&e[0]&&(e=[0].concat(e)),128&t[0]&&(t=[0].concat(t));var i=[48,e.length+t.length+4,2,e.length];return i=i.concat(e,[2,t.length],t),new n(i)}function a(e,t,i,r){if((e=new n(e.toArray())).length0&&n.ishrn(i),n}function c(e,t){e=(e=s(e,t)).mod(t);var i=new n(e.toArray());if(i.length=t)throw new Error("invalid sig")}var a=e("bn.js"),s=e("elliptic").ec,c=e("parse-asn1"),u=e("./curves.json");t.exports=function(e,t,o,s,u){var l=c(o);if("ec"===l.type){if("ecdsa"!==s&&"ecdsa/rsa"!==s)throw new Error("wrong public key type");return i(e,t,l)}if("dsa"===l.type){if("dsa"!==s)throw new Error("wrong public key type");return r(e,t,l)}if("rsa"!==s&&"ecdsa/rsa"!==s)throw new Error("wrong public key type");t=n.concat([u,t]);for(var f=l.modulus.byteLength(),p=[1],d=0;t.length+p.length+2>5==6?2:e>>4==14?3:e>>3==30?4:-1}function s(e,t,n){var i=t.length-1;if(i=0?(r>0&&(e.lastNeed=r-1),r):--i=0?(r>0&&(e.lastNeed=r-2),r):--i=0?(r>0&&(2===r?r=0:e.lastNeed=r-3),r):0}function c(e,t,n){if(128!=(192&t[0]))return e.lastNeed=0,"�".repeat(n);if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�".repeat(n+1);if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�".repeat(n+2)}}function u(e){var t=this.lastTotal-this.lastNeed,n=c(this,e,t);return void 0!==n?n:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function l(e,t){if((e.length-t)%2==0){var n=e.toString("utf16le",t);if(n){var i=n.charCodeAt(n.length-1);if(i>=55296&&i<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function f(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,n)}return t}function p(e,t){var n=(e.length-t)%3;return 0===n?e.toString("base64",t):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-n))}function d(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function h(e){return e.toString(this.encoding)}function m(e){return e&&e.length?this.write(e):""}var v=e("safe-buffer").Buffer,b=v.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};n.StringDecoder=o,o.prototype.write=function(e){if(0===e.length)return"";var t,n;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n$)throw new RangeError("Invalid typed array length");var t=new Uint8Array(e);return t.__proto__=r.prototype,t}function r(e,t,n){if("number"==typeof e){if("string"==typeof t)throw new Error("If encoding is specified then the first argument must be a string");return c(e)}return o(e,t,n)}function o(e,t,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return V(e)?f(e,t,n):"string"==typeof e?u(e,t):p(e)}function a(e){if("number"!=typeof e)throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function s(e,t,n){return a(e),e<=0?i(e):void 0!==t?"string"==typeof n?i(e).fill(t,n):i(e).fill(t):i(e)}function c(e){return a(e),i(e<0?0:0|d(e))}function u(e,t){if("string"==typeof t&&""!==t||(t="utf8"),!r.isEncoding(t))throw new TypeError('"encoding" must be a valid string encoding');var n=0|h(e,t),o=i(n),a=o.write(e,t);return a!==n&&(o=o.slice(0,a)),o}function l(e){for(var t=e.length<0?0:0|d(e.length),n=i(t),r=0;r=$)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+$.toString(16)+" bytes");return 0|e}function h(e,t){if(r.isBuffer(e))return e.length;if(K(e)||V(e))return e.byteLength;"string"!=typeof e&&(e=""+e);var n=e.length;if(0===n)return 0;for(var i=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return L(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return U(e).length;default:if(i)return L(e).length;t=(""+t).toLowerCase(),i=!0}}function m(e,t,n){var i=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,t>>>=0,n<=t)return"";for(e||(e="utf8");;)switch(e){case"hex":return T(this,t,n);case"utf8":case"utf-8":return E(this,t,n);case"ascii":return C(this,t,n);case"latin1":case"binary":return M(this,t,n);case"base64":return S(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,t,n);default:if(i)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),i=!0}}function v(e,t,n){var i=e[t];e[t]=e[n],e[n]=i}function b(e,t,n,i,o){if(0===e.length)return-1;if("string"==typeof n?(i=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,W(n)&&(n=o?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(o)return-1;n=e.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof t&&(t=r.from(t,i)),r.isBuffer(t))return 0===t.length?-1:y(e,t,n,i,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,n):Uint8Array.prototype.lastIndexOf.call(e,t,n):y(e,[t],n,i,o);throw new TypeError("val must be string, number or Buffer")}function y(e,t,n,i,r){function o(e,t){return 1===a?e[t]:e.readUInt16BE(t*a)}var a=1,s=e.length,c=t.length;if(void 0!==i&&("ucs2"===(i=String(i).toLowerCase())||"ucs-2"===i||"utf16le"===i||"utf-16le"===i)){if(e.length<2||t.length<2)return-1;a=2,s/=2,c/=2,n/=2}var u;if(r){var l=-1;for(u=n;us&&(n=s-c),u=n;u>=0;u--){for(var f=!0,p=0;pr&&(i=r):i=r;var o=t.length;if(o%2!=0)throw new TypeError("Invalid hex string");i>o/2&&(i=o/2);for(var a=0;a239?4:o>223?3:o>191?2:1;if(r+s<=n){var c,u,l,f;switch(s){case 1:o<128&&(a=o);break;case 2:128==(192&(c=e[r+1]))&&(f=(31&o)<<6|63&c)>127&&(a=f);break;case 3:c=e[r+1],u=e[r+2],128==(192&c)&&128==(192&u)&&(f=(15&o)<<12|(63&c)<<6|63&u)>2047&&(f<55296||f>57343)&&(a=f);break;case 4:c=e[r+1],u=e[r+2],l=e[r+3],128==(192&c)&&128==(192&u)&&128==(192&l)&&(f=(15&o)<<18|(63&c)<<12|(63&u)<<6|63&l)>65535&&f<1114112&&(a=f)}}null===a?(a=65533,s=1):a>65535&&(a-=65536,i.push(a>>>10&1023|55296),a=56320|1023&a),i.push(a),r+=s}return A(i)}function A(e){var t=e.length;if(t<=J)return String.fromCharCode.apply(String,e);for(var n="",i=0;ii)&&(n=i);for(var r="",o=t;on)throw new RangeError("Trying to access beyond buffer length")}function I(e,t,n,i,o,a){if(!r.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||te.length)throw new RangeError("Index out of range")}function B(e,t,n,i,r,o){if(n+i>e.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function R(e,t,n,i,r){return t=+t,n>>>=0,r||B(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38),G.write(e,t,n,i,23,4),n+4}function O(e,t,n,i,r){return t=+t,n>>>=0,r||B(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308),G.write(e,t,n,i,52,8),n+8}function N(e){if((e=e.trim().replace(Q,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}function D(e){return e<16?"0"+e.toString(16):e.toString(16)}function L(e,t){t=t||1/0;for(var n,i=e.length,r=null,o=[],a=0;a55295&&n<57344){if(!r){if(n>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(a+1===i){(t-=3)>-1&&o.push(239,191,189);continue}r=n;continue}if(n<56320){(t-=3)>-1&&o.push(239,191,189),r=n;continue}n=65536+(r-55296<<10|n-56320)}else r&&(t-=3)>-1&&o.push(239,191,189);if(r=null,n<128){if((t-=1)<0)break;o.push(n)}else if(n<2048){if((t-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((t-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function q(e){for(var t=[],n=0;n>8,r=n%256,o.push(r),o.push(i);return o}function U(e){return X.toByteArray(N(e))}function H(e,t,n,i){for(var r=0;r=t.length||r>=e.length);++r)t[r+n]=e[r];return r}function V(e){return e instanceof ArrayBuffer||null!=e&&null!=e.constructor&&"ArrayBuffer"===e.constructor.name&&"number"==typeof e.byteLength}function K(e){return"function"==typeof ArrayBuffer.isView&&ArrayBuffer.isView(e)}function W(e){return e!==e}var X=e("base64-js"),G=e("ieee754");n.Buffer=r,n.SlowBuffer=function(e){return+e!=e&&(e=0),r.alloc(+e)},n.INSPECT_MAX_BYTES=50;var $=2147483647;n.kMaxLength=$,r.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}(),r.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),"undefined"!=typeof Symbol&&Symbol.species&&r[Symbol.species]===r&&Object.defineProperty(r,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),r.poolSize=8192,r.from=function(e,t,n){return o(e,t,n)},r.prototype.__proto__=Uint8Array.prototype,r.__proto__=Uint8Array,r.alloc=function(e,t,n){return s(e,t,n)},r.allocUnsafe=function(e){return c(e)},r.allocUnsafeSlow=function(e){return c(e)},r.isBuffer=function(e){return null!=e&&!0===e._isBuffer},r.compare=function(e,t){if(!r.isBuffer(e)||!r.isBuffer(t))throw new TypeError("Arguments must be Buffers");if(e===t)return 0;for(var n=e.length,i=t.length,o=0,a=Math.min(n,i);o0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),""},r.prototype.compare=function(e,t,n,i,o){if(!r.isBuffer(e))throw new TypeError("Argument must be a Buffer");if(void 0===t&&(t=0),void 0===n&&(n=e?e.length:0),void 0===i&&(i=0),void 0===o&&(o=this.length),t<0||n>e.length||i<0||o>this.length)throw new RangeError("out of range index");if(i>=o&&t>=n)return 0;if(i>=o)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,o>>>=0,this===e)return 0;for(var a=o-i,s=n-t,c=Math.min(a,s),u=this.slice(i,o),l=e.slice(t,n),f=0;f>>=0,isFinite(n)?(n>>>=0,void 0===i&&(i="utf8")):(i=n,n=void 0)}var r=this.length-t;if((void 0===n||n>r)&&(n=r),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var o=!1;;)switch(i){case"hex":return g(this,e,t,n);case"utf8":case"utf-8":return _(this,e,t,n);case"ascii":return x(this,e,t,n);case"latin1":case"binary":return w(this,e,t,n);case"base64":return k(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),o=!0}},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var J=4096;r.prototype.slice=function(e,t){var n=this.length;e=~~e,t=void 0===t?n:~~t,e<0?(e+=n)<0&&(e=0):e>n&&(e=n),t<0?(t+=n)<0&&(t=0):t>n&&(t=n),t>>=0,t>>>=0,n||F(e,t,this.length);for(var i=this[e],r=1,o=0;++o>>=0,t>>>=0,n||F(e,t,this.length);for(var i=this[e+--t],r=1;t>0&&(r*=256);)i+=this[e+--t]*r;return i},r.prototype.readUInt8=function(e,t){return e>>>=0,t||F(e,1,this.length),this[e]},r.prototype.readUInt16LE=function(e,t){return e>>>=0,t||F(e,2,this.length),this[e]|this[e+1]<<8},r.prototype.readUInt16BE=function(e,t){return e>>>=0,t||F(e,2,this.length),this[e]<<8|this[e+1]},r.prototype.readUInt32LE=function(e,t){return e>>>=0,t||F(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},r.prototype.readUInt32BE=function(e,t){return e>>>=0,t||F(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},r.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||F(e,t,this.length);for(var i=this[e],r=1,o=0;++o=r&&(i-=Math.pow(2,8*t)),i},r.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||F(e,t,this.length);for(var i=t,r=1,o=this[e+--i];i>0&&(r*=256);)o+=this[e+--i]*r;return r*=128,o>=r&&(o-=Math.pow(2,8*t)),o},r.prototype.readInt8=function(e,t){return e>>>=0,t||F(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},r.prototype.readInt16LE=function(e,t){e>>>=0,t||F(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},r.prototype.readInt16BE=function(e,t){e>>>=0,t||F(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},r.prototype.readInt32LE=function(e,t){return e>>>=0,t||F(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},r.prototype.readInt32BE=function(e,t){return e>>>=0,t||F(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},r.prototype.readFloatLE=function(e,t){return e>>>=0,t||F(e,4,this.length),G.read(this,e,!0,23,4)},r.prototype.readFloatBE=function(e,t){return e>>>=0,t||F(e,4,this.length),G.read(this,e,!1,23,4)},r.prototype.readDoubleLE=function(e,t){return e>>>=0,t||F(e,8,this.length),G.read(this,e,!0,52,8)},r.prototype.readDoubleBE=function(e,t){return e>>>=0,t||F(e,8,this.length),G.read(this,e,!1,52,8)},r.prototype.writeUIntLE=function(e,t,n,i){e=+e,t>>>=0,n>>>=0,i||I(this,e,t,n,Math.pow(2,8*n)-1,0);var r=1,o=0;for(this[t]=255&e;++o>>=0,n>>>=0,i||I(this,e,t,n,Math.pow(2,8*n)-1,0);var r=n-1,o=1;for(this[t+r]=255&e;--r>=0&&(o*=256);)this[t+r]=e/o&255;return t+n},r.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,1,255,0),this[t]=255&e,t+1},r.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},r.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},r.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},r.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},r.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t>>>=0,!i){var r=Math.pow(2,8*n-1);I(this,e,t,n,r-1,-r)}var o=0,a=1,s=0;for(this[t]=255&e;++o>0)-s&255;return t+n},r.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t>>>=0,!i){var r=Math.pow(2,8*n-1);I(this,e,t,n,r-1,-r)}var o=n-1,a=1,s=0;for(this[t+o]=255&e;--o>=0&&(a*=256);)e<0&&0===s&&0!==this[t+o+1]&&(s=1),this[t+o]=(e/a>>0)-s&255;return t+n},r.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},r.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},r.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},r.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},r.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},r.prototype.writeFloatLE=function(e,t,n){return R(this,e,t,!0,n)},r.prototype.writeFloatBE=function(e,t,n){return R(this,e,t,!1,n)},r.prototype.writeDoubleLE=function(e,t,n){return O(this,e,t,!0,n)},r.prototype.writeDoubleBE=function(e,t,n){return O(this,e,t,!1,n)},r.prototype.copy=function(e,t,n,i){if(n||(n=0),i||0===i||(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i=this.length)throw new RangeError("sourceStart out of bounds");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t=0;--r)e[r+t]=this[r+n];else if(o<1e3)for(r=0;r>>=0,n=void 0===n?this.length:n>>>0,e||(e=0);var a;if("number"==typeof e)for(a=t;a>>2),a=0,s=0;a>5]|=128<>>9<<4)]=t;for(var n=1732584193,i=-271733879,r=-1732584194,l=271733878,f=0;f>16)+(t>>16)+(n>>16)<<16|65535&n}function l(e,t){return e<>>32-t}var f=e("./make-hash");t.exports=function(e){return f(e,i)}},{"./make-hash":52}],54:[function(e,t,n){function i(e,t){a.call(this,"digest"),"string"==typeof t&&(t=s.from(t));var n="sha512"===e||"sha384"===e?128:64;this._alg=e,this._key=t,t.length>n?t=("rmd160"===e?new u:l(e)).update(t).digest():t.lengthc?t=e(t):t.length0;i--)t+=this._buffer(e,t),n+=this._flushBuffer(r,n);return t+=this._buffer(e,t),r},i.prototype.final=function(e){var t;e&&(t=this.update(e));var n;return n="encrypt"===this.type?this._finalEncrypt():this._finalDecrypt(),t?t.concat(n):n},i.prototype._pad=function(e,t){if(0===t)return!1;for(;t>>1];n=c.r28shl(n,a),i=c.r28shl(i,a),c.pc2(n,i,e.keys,r)}},r.prototype._update=function(e,t,n,i){var r=this._desState,o=c.readUInt32BE(e,t),a=c.readUInt32BE(e,t+4);c.ip(o,a,r.tmp,0),o=r.tmp[0],a=r.tmp[1],"encrypt"===this.type?this._encrypt(r,o,a,r.tmp,0):this._decrypt(r,o,a,r.tmp,0),o=r.tmp[0],a=r.tmp[1],c.writeUInt32BE(n,o,i),c.writeUInt32BE(n,a,i+4)},r.prototype._pad=function(e,t){for(var n=e.length-t,i=t;i>>0,o=p}c.rip(a,o,i,r)},r.prototype._decrypt=function(e,t,n,i,r){for(var o=n,a=t,s=e.keys.length-2;s>=0;s-=2){var u=e.keys[s],l=e.keys[s+1];c.expand(o,e.tmp,0),u^=e.tmp[0],l^=e.tmp[1];var f=c.substitute(u,l),p=o;o=(a^c.permute(f))>>>0,a=p}c.rip(o,a,i,r)}},{"../des":57,inherits:101,"minimalistic-assert":106}],61:[function(e,t,n){function i(e,t){o.equal(t.length,24,"Invalid key length");var n=t.slice(0,8),i=t.slice(8,16),r=t.slice(16,24);this.ciphers="encrypt"===e?[u.create({type:"encrypt",key:n}),u.create({type:"decrypt",key:i}),u.create({type:"encrypt",key:r})]:[u.create({type:"decrypt",key:r}),u.create({type:"encrypt",key:i}),u.create({type:"decrypt",key:n})]}function r(e){c.call(this,e);var t=new i(this.type,this.options.key);this._edeState=t}var o=e("minimalistic-assert"),a=e("inherits"),s=e("../des"),c=s.Cipher,u=s.DES;a(r,c),t.exports=r,r.create=function(e){return new r(e)},r.prototype._update=function(e,t,n,i){var r=this._edeState;r.ciphers[0]._update(e,t,n,i),r.ciphers[1]._update(n,i,n,i),r.ciphers[2]._update(n,i,n,i)},r.prototype._pad=u.prototype._pad,r.prototype._unpad=u.prototype._unpad},{"../des":57,inherits:101,"minimalistic-assert":106}],62:[function(e,t,n){n.readUInt32BE=function(e,t){return(e[0+t]<<24|e[1+t]<<16|e[2+t]<<8|e[3+t])>>>0},n.writeUInt32BE=function(e,t,n){e[0+n]=t>>>24,e[1+n]=t>>>16&255,e[2+n]=t>>>8&255,e[3+n]=255&t},n.ip=function(e,t,n,i){for(var r=0,o=0,a=6;a>=0;a-=2){for(s=0;s<=24;s+=8)r<<=1,r|=t>>>s+a&1;for(s=0;s<=24;s+=8)r<<=1,r|=e>>>s+a&1}for(a=6;a>=0;a-=2){for(s=1;s<=25;s+=8)o<<=1,o|=t>>>s+a&1;for(var s=1;s<=25;s+=8)o<<=1,o|=e>>>s+a&1}n[i+0]=r>>>0,n[i+1]=o>>>0},n.rip=function(e,t,n,i){for(var r=0,o=0,a=0;a<4;a++)for(s=24;s>=0;s-=8)r<<=1,r|=t>>>s+a&1,r<<=1,r|=e>>>s+a&1;for(a=4;a<8;a++)for(var s=24;s>=0;s-=8)o<<=1,o|=t>>>s+a&1,o<<=1,o|=e>>>s+a&1;n[i+0]=r>>>0,n[i+1]=o>>>0},n.pc1=function(e,t,n,i){for(var r=0,o=0,a=7;a>=5;a--){for(s=0;s<=24;s+=8)r<<=1,r|=t>>s+a&1;for(s=0;s<=24;s+=8)r<<=1,r|=e>>s+a&1}for(s=0;s<=24;s+=8)r<<=1,r|=t>>s+a&1;for(a=1;a<=3;a++){for(s=0;s<=24;s+=8)o<<=1,o|=t>>s+a&1;for(s=0;s<=24;s+=8)o<<=1,o|=e>>s+a&1}for(var s=0;s<=24;s+=8)o<<=1,o|=e>>s+a&1;n[i+0]=r>>>0,n[i+1]=o>>>0},n.r28shl=function(e,t){return e<>>28-t};var i=[14,11,17,4,27,23,25,0,13,22,7,18,5,9,16,24,2,20,12,21,1,8,15,26,15,4,25,19,9,1,26,16,5,11,23,8,12,7,17,0,22,3,10,14,6,20,27,24];n.pc2=function(e,t,n,r){for(var o=0,a=0,s=i.length>>>1,c=0;c>>i[c]&1;for(c=s;c>>i[c]&1;n[r+0]=o>>>0,n[r+1]=a>>>0},n.expand=function(e,t,n){var i=0,r=0;i=(1&e)<<5|e>>>27;for(o=23;o>=15;o-=4)i<<=6,i|=e>>>o&63;for(var o=11;o>=3;o-=4)r|=e>>>o&63,r<<=6;r|=(31&e)<<1|e>>>31,t[n+0]=i>>>0,t[n+1]=r>>>0};var r=[14,0,4,15,13,7,1,4,2,14,15,2,11,13,8,1,3,10,10,6,6,12,12,11,5,9,9,5,0,3,7,8,4,15,1,12,14,8,8,2,13,4,6,9,2,1,11,7,15,5,12,11,9,3,7,14,3,10,10,0,5,6,0,13,15,3,1,13,8,4,14,7,6,15,11,2,3,8,4,14,9,12,7,0,2,1,13,10,12,6,0,9,5,11,10,5,0,13,14,8,7,10,11,1,10,3,4,15,13,4,1,2,5,11,8,6,12,7,6,12,9,0,3,5,2,14,15,9,10,13,0,7,9,0,14,9,6,3,3,4,15,6,5,10,1,2,13,8,12,5,7,14,11,12,4,11,2,15,8,1,13,1,6,10,4,13,9,0,8,6,15,9,3,8,0,7,11,4,1,15,2,14,12,3,5,11,10,5,14,2,7,12,7,13,13,8,14,11,3,5,0,6,6,15,9,0,10,3,1,4,2,7,8,2,5,12,11,1,12,10,4,14,15,9,10,3,6,15,9,0,0,6,12,10,11,1,7,13,13,8,15,9,1,4,3,5,14,11,5,12,2,7,8,2,4,14,2,14,12,11,4,2,1,12,7,4,10,7,11,13,6,1,8,5,5,0,3,15,15,10,13,3,0,9,14,8,9,6,4,11,2,8,1,12,11,7,10,1,13,14,7,2,8,13,15,6,9,15,12,0,5,9,6,10,3,4,0,5,14,3,12,10,1,15,10,4,15,2,9,7,2,12,6,9,8,5,0,6,13,1,3,13,4,14,14,0,7,11,5,3,11,8,9,4,14,3,15,2,5,12,2,9,8,5,12,15,3,10,7,11,0,14,4,1,10,7,1,6,13,0,11,8,6,13,4,13,11,0,2,11,14,7,15,4,0,9,8,1,13,10,3,14,12,3,9,5,7,12,5,2,10,15,6,8,1,6,1,6,4,11,11,13,13,8,12,1,3,4,7,10,14,7,10,9,15,5,6,0,8,15,0,14,5,2,9,3,2,12,13,1,2,15,8,13,4,8,6,10,15,3,11,7,1,4,10,12,9,5,3,6,14,11,5,0,0,14,12,9,7,2,7,2,11,1,4,14,1,7,9,4,12,10,14,8,2,13,0,15,6,12,10,9,13,0,15,3,3,5,5,6,8,11];n.substitute=function(e,t){for(var n=0,i=0;i<4;i++)n<<=4,n|=a=r[64*i+(o=e>>>18-6*i&63)];for(i=0;i<4;i++){var o=t>>>18-6*i&63,a=r[256+64*i+o];n<<=4,n|=a}return n>>>0};var o=[16,25,12,11,3,20,4,15,31,17,9,6,27,14,1,22,30,24,8,18,0,5,29,23,13,19,2,26,10,21,28,7];n.permute=function(e){for(var t=0,n=0;n>>o[n]&1;return t>>>0},n.padSplit=function(e,t,n){for(var i=e.toString(2);i.lengthe;)n.ishrn(1);if(n.isEven()&&n.iadd(f),n.testn(1)||n.iadd(p),t.cmp(p)){if(!t.cmp(d))for(;n.mod(h).cmp(m);)n.iadd(b)}else for(;n.mod(u).cmp(v);)n.iadd(b);if(i=n.shrn(1),r(i)&&r(n)&&o(i)&&o(n)&&l.test(i)&&l.test(n))return n}}var s=e("randombytes");t.exports=a,a.simpleSieve=r,a.fermatTest=o;var c=e("bn.js"),u=new c(24),l=new(e("miller-rabin")),f=new c(1),p=new c(2),d=new c(5),h=(new c(16),new c(8),new c(10)),m=new c(3),v=(new c(7),new c(11)),b=new c(4),y=(new c(12),null)},{"bn.js":"BN","miller-rabin":105,randombytes:127}],66:[function(e,t,n){t.exports={modp1:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"},modp2:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"},modp5:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"},modp14:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"},modp15:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"},modp16:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"},modp17:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"},modp18:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"}}},{}],67:[function(e,t,n){var i=n;i.version=e("../package.json").version,i.utils=e("./elliptic/utils"),i.rand=e("brorand"),i.curve=e("./elliptic/curve"),i.curves=e("./elliptic/curves"),i.ec=e("./elliptic/ec"),i.eddsa=e("./elliptic/eddsa")},{"../package.json":82,"./elliptic/curve":70,"./elliptic/curves":73,"./elliptic/ec":74,"./elliptic/eddsa":77,"./elliptic/utils":81,brorand:16}],68:[function(e,t,n){function i(e,t){this.type=e,this.p=new o(t.p,16),this.red=t.prime?o.red(t.prime):o.mont(this.p),this.zero=new o(0).toRed(this.red),this.one=new o(1).toRed(this.red),this.two=new o(2).toRed(this.red),this.n=t.n&&new o(t.n,16),this.g=t.g&&this.pointFromJSON(t.g,t.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4);var n=this.n&&this.p.div(this.n);!n||n.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}function r(e,t){this.curve=e,this.type=t,this.precomputed=null}var o=e("bn.js"),a=e("../../elliptic").utils,s=a.getNAF,c=a.getJSF,u=a.assert;t.exports=i,i.prototype.point=function(){throw new Error("Not implemented")},i.prototype.validate=function(){throw new Error("Not implemented")},i.prototype._fixedNafMul=function(e,t){u(e.precomputed);var n=e._getDoubles(),i=s(t,1),r=(1<=a;t--)c=(c<<1)+i[t];o.push(c)}for(var l=this.jpoint(null,null,null),f=this.jpoint(null,null,null),p=r;p>0;p--){for(a=0;a=0;c--){for(var t=0;c>=0&&0===o[c];c--)t++;if(c>=0&&t++,a=a.dblp(t),c<0)break;var l=o[c];u(0!==l),a="affine"===e.type?l>0?a.mixedAdd(r[l-1>>1]):a.mixedAdd(r[-l-1>>1].neg()):l>0?a.add(r[l-1>>1]):a.add(r[-l-1>>1].neg())}return"affine"===e.type?a.toP():a},i.prototype._wnafMulAdd=function(e,t,n,i,r){for(var o=this._wnafT1,a=this._wnafT2,u=this._wnafT3,l=0,f=0;f=1;f-=2){var d=f-1,h=f;if(1===o[d]&&1===o[h]){var m=[t[d],null,null,t[h]];0===t[d].y.cmp(t[h].y)?(m[1]=t[d].add(t[h]),m[2]=t[d].toJ().mixedAdd(t[h].neg())):0===t[d].y.cmp(t[h].y.redNeg())?(m[1]=t[d].toJ().mixedAdd(t[h]),m[2]=t[d].add(t[h].neg())):(m[1]=t[d].toJ().mixedAdd(t[h]),m[2]=t[d].toJ().mixedAdd(t[h].neg()));var v=[-3,-1,-5,-7,0,7,5,1,3],b=c(n[d],n[h]);l=Math.max(b[0].length,l),u[d]=new Array(l),u[h]=new Array(l);for(j=0;j=0;f--){for(var w=0;f>=0;){for(var k=!0,j=0;j=0&&w++,_=_.dblp(w),f<0)break;for(j=0;j0?S=a[j][E-1>>1]:E<0&&(S=a[j][-E-1>>1].neg()),_="affine"===S.type?_.mixedAdd(S):_.add(S))}}for(f=0;f=Math.ceil((e.bitLength()+1)/t.step)},r.prototype._getDoubles=function(e,t){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var n=[this],i=this,r=0;r":""},r.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&0===this.y.cmp(this.z)},r.prototype._extDbl=function(){var e=this.x.redSqr(),t=this.y.redSqr(),n=this.z.redSqr();n=n.redIAdd(n);var i=this.curve._mulA(e),r=this.x.redAdd(this.y).redSqr().redISub(e).redISub(t),o=i.redAdd(t),a=o.redSub(n),s=i.redSub(t),c=r.redMul(a),u=o.redMul(s),l=r.redMul(s),f=a.redMul(o);return this.curve.point(c,u,f,l)},r.prototype._projDbl=function(){var e,t,n,i=this.x.redAdd(this.y).redSqr(),r=this.x.redSqr(),o=this.y.redSqr();if(this.curve.twisted){var a=(u=this.curve._mulA(r)).redAdd(o);if(this.zOne)e=i.redSub(r).redSub(o).redMul(a.redSub(this.curve.two)),t=a.redMul(u.redSub(o)),n=a.redSqr().redSub(a).redSub(a);else{var s=this.z.redSqr(),c=a.redSub(s).redISub(s);e=i.redSub(r).redISub(o).redMul(c),t=a.redMul(u.redSub(o)),n=a.redMul(c)}}else{var u=r.redAdd(o),s=this.curve._mulC(this.c.redMul(this.z)).redSqr(),c=u.redSub(s).redSub(s);e=this.curve._mulC(i.redISub(u)).redMul(c),t=this.curve._mulC(u).redMul(r.redISub(o)),n=u.redMul(c)}return this.curve.point(e,t,n)},r.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},r.prototype._extAdd=function(e){var t=this.y.redSub(this.x).redMul(e.y.redSub(e.x)),n=this.y.redAdd(this.x).redMul(e.y.redAdd(e.x)),i=this.t.redMul(this.curve.dd).redMul(e.t),r=this.z.redMul(e.z.redAdd(e.z)),o=n.redSub(t),a=r.redSub(i),s=r.redAdd(i),c=n.redAdd(t),u=o.redMul(a),l=s.redMul(c),f=o.redMul(c),p=a.redMul(s);return this.curve.point(u,l,p,f)},r.prototype._projAdd=function(e){var t,n,i=this.z.redMul(e.z),r=i.redSqr(),o=this.x.redMul(e.x),a=this.y.redMul(e.y),s=this.curve.d.redMul(o).redMul(a),c=r.redSub(s),u=r.redAdd(s),l=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(o).redISub(a),f=i.redMul(c).redMul(l);return this.curve.twisted?(t=i.redMul(u).redMul(a.redSub(this.curve._mulA(o))),n=c.redMul(u)):(t=i.redMul(u).redMul(a.redSub(o)),n=this.curve._mulC(c).redMul(u)),this.curve.point(f,t,n)},r.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},r.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},r.prototype.mulAdd=function(e,t,n){return this.curve._wnafMulAdd(1,[this,t],[e,n],2,!1)},r.prototype.jmulAdd=function(e,t,n){return this.curve._wnafMulAdd(1,[this,t],[e,n],2,!0)},r.prototype.normalize=function(){if(this.zOne)return this;var e=this.z.redInvm();return this.x=this.x.redMul(e),this.y=this.y.redMul(e),this.t&&(this.t=this.t.redMul(e)),this.z=this.curve.one,this.zOne=!0,this},r.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},r.prototype.getX=function(){return this.normalize(),this.x.fromRed()},r.prototype.getY=function(){return this.normalize(),this.y.fromRed()},r.prototype.eq=function(e){return this===e||0===this.getX().cmp(e.getX())&&0===this.getY().cmp(e.getY())},r.prototype.eqXToP=function(e){var t=e.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(t))return!0;for(var n=e.clone(),i=this.curve.redN.redMul(this.z);;){if(n.iadd(this.curve.n),n.cmp(this.curve.p)>=0)return!1;if(t.redIAdd(i),0===this.x.cmp(t))return!0}return!1},r.prototype.toP=r.prototype.normalize,r.prototype.mixedAdd=r.prototype.add},{"../../elliptic":67,"../curve":70,"bn.js":"BN",inherits:101}],70:[function(e,t,n){var i=n;i.base=e("./base"),i.short=e("./short"),i.mont=e("./mont"),i.edwards=e("./edwards")},{"./base":68,"./edwards":69,"./mont":71,"./short":72}],71:[function(e,t,n){function i(e){c.call(this,"mont",e),this.a=new a(e.a,16).toRed(this.red),this.b=new a(e.b,16).toRed(this.red),this.i4=new a(4).toRed(this.red).redInvm(),this.two=new a(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}function r(e,t,n){c.BasePoint.call(this,e,"projective"),null===t&&null===n?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new a(t,16),this.z=new a(n,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}var o=e("../curve"),a=e("bn.js"),s=e("inherits"),c=o.base,u=e("../../elliptic").utils;s(i,c),t.exports=i,i.prototype.validate=function(e){var t=e.normalize().x,n=t.redSqr(),i=n.redMul(t).redAdd(n.redMul(this.a)).redAdd(t);return 0===i.redSqrt().redSqr().cmp(i)},s(r,c.BasePoint),i.prototype.decodePoint=function(e,t){return this.point(u.toArray(e,t),1)},i.prototype.point=function(e,t){return new r(this,e,t)},i.prototype.pointFromJSON=function(e){return r.fromJSON(this,e)},r.prototype.precompute=function(){},r.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},r.fromJSON=function(e,t){return new r(e,t[0],t[1]||e.one)},r.prototype.inspect=function(){return this.isInfinity()?"":""},r.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},r.prototype.dbl=function(){var e=this.x.redAdd(this.z).redSqr(),t=this.x.redSub(this.z).redSqr(),n=e.redSub(t),i=e.redMul(t),r=n.redMul(t.redAdd(this.curve.a24.redMul(n)));return this.curve.point(i,r)},r.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},r.prototype.diffAdd=function(e,t){var n=this.x.redAdd(this.z),i=this.x.redSub(this.z),r=e.x.redAdd(e.z),o=e.x.redSub(e.z).redMul(n),a=r.redMul(i),s=t.z.redMul(o.redAdd(a).redSqr()),c=t.x.redMul(o.redISub(a).redSqr());return this.curve.point(s,c)},r.prototype.mul=function(e){for(var t=e.clone(),n=this,i=this.curve.point(null,null),r=this,o=[];0!==t.cmpn(0);t.iushrn(1))o.push(t.andln(1));for(var a=o.length-1;a>=0;a--)0===o[a]?(n=n.diffAdd(i,r),i=i.dbl()):(i=n.diffAdd(i,r),n=n.dbl());return i},r.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")},r.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")},r.prototype.eq=function(e){return 0===this.getX().cmp(e.getX())},r.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},r.prototype.getX=function(){return this.normalize(),this.x.fromRed()}},{"../../elliptic":67,"../curve":70,"bn.js":"BN",inherits:101}],72:[function(e,t,n){function i(e){l.call(this,"short",e),this.a=new c(e.a,16).toRed(this.red),this.b=new c(e.b,16).toRed(this.red),this.tinv=this.two.redInvm(),this.zeroA=0===this.a.fromRed().cmpn(0),this.threeA=0===this.a.fromRed().sub(this.p).cmpn(-3),this.endo=this._getEndomorphism(e),this._endoWnafT1=new Array(4),this._endoWnafT2=new Array(4)}function r(e,t,n,i){l.BasePoint.call(this,e,"affine"),null===t&&null===n?(this.x=null,this.y=null,this.inf=!0):(this.x=new c(t,16),this.y=new c(n,16),i&&(this.x.forceRed(this.curve.red),this.y.forceRed(this.curve.red)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.inf=!1)}function o(e,t,n,i){l.BasePoint.call(this,e,"jacobian"),null===t&&null===n&&null===i?(this.x=this.curve.one,this.y=this.curve.one,this.z=new c(0)):(this.x=new c(t,16),this.y=new c(n,16),this.z=new c(i,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}var a=e("../curve"),s=e("../../elliptic"),c=e("bn.js"),u=e("inherits"),l=a.base,f=s.utils.assert;u(i,l),t.exports=i,i.prototype._getEndomorphism=function(e){if(this.zeroA&&this.g&&this.n&&1===this.p.modn(3)){var t,n;if(e.beta)t=new c(e.beta,16).toRed(this.red);else{var i=this._getEndoRoots(this.p);t=(t=i[0].cmp(i[1])<0?i[0]:i[1]).toRed(this.red)}if(e.lambda)n=new c(e.lambda,16);else{var r=this._getEndoRoots(this.n);0===this.g.mul(r[0]).x.cmp(this.g.x.redMul(t))?n=r[0]:(n=r[1],f(0===this.g.mul(n).x.cmp(this.g.x.redMul(t))))}var o;return o=e.basis?e.basis.map(function(e){return{a:new c(e.a,16),b:new c(e.b,16)}}):this._getEndoBasis(n),{beta:t,lambda:n,basis:o}}},i.prototype._getEndoRoots=function(e){var t=e===this.p?this.red:c.mont(e),n=new c(2).toRed(t).redInvm(),i=n.redNeg(),r=new c(3).toRed(t).redNeg().redSqrt().redMul(n);return[i.redAdd(r).fromRed(),i.redSub(r).fromRed()]},i.prototype._getEndoBasis=function(e){for(var t,n,i,r,o,a,s,u,l,f=this.n.ushrn(Math.floor(this.n.bitLength()/2)),p=e,d=this.n.clone(),h=new c(1),m=new c(0),v=new c(0),b=new c(1),y=0;0!==p.cmpn(0);){var g=d.div(p);u=d.sub(g.mul(p)),l=v.sub(g.mul(h));var _=b.sub(g.mul(m));if(!i&&u.cmp(f)<0)t=s.neg(),n=h,i=u.neg(),r=l;else if(i&&2==++y)break;s=u,d=p,p=u,v=h,h=l,b=m,m=_}o=u.neg(),a=l;var x=i.sqr().add(r.sqr());return o.sqr().add(a.sqr()).cmp(x)>=0&&(o=t,a=n),i.negative&&(i=i.neg(),r=r.neg()),o.negative&&(o=o.neg(),a=a.neg()),[{a:i,b:r},{a:o,b:a}]},i.prototype._endoSplit=function(e){var t=this.endo.basis,n=t[0],i=t[1],r=i.b.mul(e).divRound(this.n),o=n.b.neg().mul(e).divRound(this.n),a=r.mul(n.a),s=o.mul(i.a),c=r.mul(n.b),u=o.mul(i.b);return{k1:e.sub(a).sub(s),k2:c.add(u).neg()}},i.prototype.pointFromX=function(e,t){(e=new c(e,16)).red||(e=e.toRed(this.red));var n=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),i=n.redSqrt();if(0!==i.redSqr().redSub(n).cmp(this.zero))throw new Error("invalid point");var r=i.fromRed().isOdd();return(t&&!r||!t&&r)&&(i=i.redNeg()),this.point(e,i)},i.prototype.validate=function(e){if(e.inf)return!0;var t=e.x,n=e.y,i=this.a.redMul(t),r=t.redSqr().redMul(t).redIAdd(i).redIAdd(this.b);return 0===n.redSqr().redISub(r).cmpn(0)},i.prototype._endoWnafMulAdd=function(e,t,n){for(var i=this._endoWnafT1,r=this._endoWnafT2,o=0;o":""},r.prototype.isInfinity=function(){return this.inf},r.prototype.add=function(e){if(this.inf)return e;if(e.inf)return this;if(this.eq(e))return this.dbl();if(this.neg().eq(e))return this.curve.point(null,null);if(0===this.x.cmp(e.x))return this.curve.point(null,null);var t=this.y.redSub(e.y);0!==t.cmpn(0)&&(t=t.redMul(this.x.redSub(e.x).redInvm()));var n=t.redSqr().redISub(this.x).redISub(e.x),i=t.redMul(this.x.redSub(n)).redISub(this.y);return this.curve.point(n,i)},r.prototype.dbl=function(){if(this.inf)return this;var e=this.y.redAdd(this.y);if(0===e.cmpn(0))return this.curve.point(null,null);var t=this.curve.a,n=this.x.redSqr(),i=e.redInvm(),r=n.redAdd(n).redIAdd(n).redIAdd(t).redMul(i),o=r.redSqr().redISub(this.x.redAdd(this.x)),a=r.redMul(this.x.redSub(o)).redISub(this.y);return this.curve.point(o,a)},r.prototype.getX=function(){return this.x.fromRed()},r.prototype.getY=function(){return this.y.fromRed()},r.prototype.mul=function(e){return e=new c(e,16),this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve.endo?this.curve._endoWnafMulAdd([this],[e]):this.curve._wnafMul(this,e)},r.prototype.mulAdd=function(e,t,n){var i=[this,t],r=[e,n];return this.curve.endo?this.curve._endoWnafMulAdd(i,r):this.curve._wnafMulAdd(1,i,r,2)},r.prototype.jmulAdd=function(e,t,n){var i=[this,t],r=[e,n];return this.curve.endo?this.curve._endoWnafMulAdd(i,r,!0):this.curve._wnafMulAdd(1,i,r,2,!0)},r.prototype.eq=function(e){return this===e||this.inf===e.inf&&(this.inf||0===this.x.cmp(e.x)&&0===this.y.cmp(e.y))},r.prototype.neg=function(e){if(this.inf)return this;var t=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var n=this.precomputed,i=function(e){return e.neg()};t.precomputed={naf:n.naf&&{wnd:n.naf.wnd,points:n.naf.points.map(i)},doubles:n.doubles&&{step:n.doubles.step,points:n.doubles.points.map(i)}}}return t},r.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},u(o,l.BasePoint),i.prototype.jpoint=function(e,t,n){return new o(this,e,t,n)},o.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),t=e.redSqr(),n=this.x.redMul(t),i=this.y.redMul(t).redMul(e);return this.curve.point(n,i)},o.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},o.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var t=e.z.redSqr(),n=this.z.redSqr(),i=this.x.redMul(t),r=e.x.redMul(n),o=this.y.redMul(t.redMul(e.z)),a=e.y.redMul(n.redMul(this.z)),s=i.redSub(r),c=o.redSub(a);if(0===s.cmpn(0))return 0!==c.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var u=s.redSqr(),l=u.redMul(s),f=i.redMul(u),p=c.redSqr().redIAdd(l).redISub(f).redISub(f),d=c.redMul(f.redISub(p)).redISub(o.redMul(l)),h=this.z.redMul(e.z).redMul(s);return this.curve.jpoint(p,d,h)},o.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var t=this.z.redSqr(),n=this.x,i=e.x.redMul(t),r=this.y,o=e.y.redMul(t).redMul(this.z),a=n.redSub(i),s=r.redSub(o);if(0===a.cmpn(0))return 0!==s.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var c=a.redSqr(),u=c.redMul(a),l=n.redMul(c),f=s.redSqr().redIAdd(u).redISub(l).redISub(l),p=s.redMul(l.redISub(f)).redISub(r.redMul(u)),d=this.z.redMul(a);return this.curve.jpoint(f,p,d)},o.prototype.dblp=function(e){if(0===e)return this;if(this.isInfinity())return this;if(!e)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var t=this,n=0;n=0)return!1;if(n.redIAdd(r),0===this.x.cmp(n))return!0}return!1},o.prototype.inspect=function(){return this.isInfinity()?"":""},o.prototype.isInfinity=function(){return 0===this.z.cmpn(0)}},{"../../elliptic":67,"../curve":70,"bn.js":"BN",inherits:101}],73:[function(e,t,n){function i(e){"short"===e.type?this.curve=new s.curve.short(e):"edwards"===e.type?this.curve=new s.curve.edwards(e):this.curve=new s.curve.mont(e),this.g=this.curve.g,this.n=this.curve.n,this.hash=e.hash,c(this.g.validate(),"Invalid curve"),c(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}function r(e,t){Object.defineProperty(o,e,{configurable:!0,enumerable:!0,get:function(){var n=new i(t);return Object.defineProperty(o,e,{configurable:!0,enumerable:!0,value:n}),n}})}var o=n,a=e("hash.js"),s=e("../elliptic"),c=s.utils.assert;o.PresetCurve=i,r("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:a.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),r("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:a.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),r("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:a.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),r("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:a.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),r("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:a.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),r("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:a.sha256,gRed:!1,g:["9"]}),r("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:a.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var u;try{u=e("./precomputed/secp256k1")}catch(e){u=void 0}r("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:a.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",u]})},{"../elliptic":67,"./precomputed/secp256k1":80,"hash.js":86}],74:[function(e,t,n){function i(e){if(!(this instanceof i))return new i(e);"string"==typeof e&&(s(a.curves.hasOwnProperty(e),"Unknown curve "+e),e=a.curves[e]),e instanceof a.curves.PresetCurve&&(e={curve:e}),this.curve=e.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=e.curve.g,this.g.precompute(e.curve.n.bitLength()+1),this.hash=e.hash||e.curve.hash}var r=e("bn.js"),o=e("hmac-drbg"),a=e("../../elliptic"),s=a.utils.assert,c=e("./key"),u=e("./signature");t.exports=i,i.prototype.keyPair=function(e){return new c(this,e)},i.prototype.keyFromPrivate=function(e,t){return c.fromPrivate(this,e,t)},i.prototype.keyFromPublic=function(e,t){return c.fromPublic(this,e,t)},i.prototype.genKeyPair=function(e){e||(e={});for(var t=new o({hash:this.hash,pers:e.pers,persEnc:e.persEnc||"utf8",entropy:e.entropy||a.rand(this.hash.hmacStrength),entropyEnc:e.entropy&&e.entropyEnc||"utf8",nonce:this.n.toArray()}),n=this.n.byteLength(),i=this.n.sub(new r(2));;){var s=new r(t.generate(n));if(!(s.cmp(i)>0))return s.iaddn(1),this.keyFromPrivate(s)}},i.prototype._truncateToN=function(e,t){var n=8*e.byteLength()-this.n.bitLength();return n>0&&(e=e.ushrn(n)),!t&&e.cmp(this.n)>=0?e.sub(this.n):e},i.prototype.sign=function(e,t,n,i){"object"===(void 0===n?"undefined":_typeof(n))&&(i=n,n=null),i||(i={}),t=this.keyFromPrivate(t,n),e=this._truncateToN(new r(e,16));for(var a=this.n.byteLength(),s=t.getPrivate().toArray("be",a),c=e.toArray("be",a),l=new o({hash:this.hash,entropy:s,nonce:c,pers:i.pers,persEnc:i.persEnc||"utf8"}),f=this.n.sub(new r(1)),p=0;!0;p++){var d=i.k?i.k(p):new r(l.generate(this.n.byteLength()));if(!((d=this._truncateToN(d,!0)).cmpn(1)<=0||d.cmp(f)>=0)){var h=this.g.mul(d);if(!h.isInfinity()){var m=h.getX(),v=m.umod(this.n);if(0!==v.cmpn(0)){var b=d.invm(this.n).mul(v.mul(t.getPrivate()).iadd(e));if(0!==(b=b.umod(this.n)).cmpn(0)){var y=(h.getY().isOdd()?1:0)|(0!==m.cmp(v)?2:0);return i.canonical&&b.cmp(this.nh)>0&&(b=this.n.sub(b),y^=1),new u({r:v,s:b,recoveryParam:y})}}}}}},i.prototype.verify=function(e,t,n,i){e=this._truncateToN(new r(e,16)),n=this.keyFromPublic(n,i);var o=(t=new u(t,"hex")).r,a=t.s;if(o.cmpn(1)<0||o.cmp(this.n)>=0)return!1;if(a.cmpn(1)<0||a.cmp(this.n)>=0)return!1;var s=a.invm(this.n),c=s.mul(e).umod(this.n),l=s.mul(o).umod(this.n);if(!this.curve._maxwellTrick)return!(f=this.g.mulAdd(c,n.getPublic(),l)).isInfinity()&&0===f.getX().umod(this.n).cmp(o);var f=this.g.jmulAdd(c,n.getPublic(),l);return!f.isInfinity()&&f.eqXToP(o)},i.prototype.recoverPubKey=function(e,t,n,i){s((3&n)===n,"The recovery param is more than two bits"),t=new u(t,i);var o=this.n,a=new r(e),c=t.r,l=t.s,f=1&n,p=n>>1;if(c.cmp(this.curve.p.umod(this.curve.n))>=0&&p)throw new Error("Unable to find sencond key candinate");c=p?this.curve.pointFromX(c.add(this.curve.n),f):this.curve.pointFromX(c,f);var d=t.r.invm(o),h=o.sub(a).mul(d).umod(o),m=l.mul(d).umod(o);return this.g.mulAdd(h,c,m)},i.prototype.getKeyRecoveryParam=function(e,t,n,i){if(null!==(t=new u(t,i)).recoveryParam)return t.recoveryParam;for(var r=0;r<4;r++){var o;try{o=this.recoverPubKey(e,t,r)}catch(e){continue}if(o.eq(n))return r}throw new Error("Unable to find valid recovery factor")}},{"../../elliptic":67,"./key":75,"./signature":76,"bn.js":"BN","hmac-drbg":98}],75:[function(e,t,n){function i(e,t){this.ec=e,this.priv=null,this.pub=null,t.priv&&this._importPrivate(t.priv,t.privEnc),t.pub&&this._importPublic(t.pub,t.pubEnc)}var r=e("bn.js"),o=e("../../elliptic").utils.assert;t.exports=i,i.fromPublic=function(e,t,n){return t instanceof i?t:new i(e,{pub:t,pubEnc:n})},i.fromPrivate=function(e,t,n){return t instanceof i?t:new i(e,{priv:t,privEnc:n})},i.prototype.validate=function(){var e=this.getPublic();return e.isInfinity()?{result:!1,reason:"Invalid public key"}:e.validate()?e.mul(this.ec.curve.n).isInfinity()?{result:!0,reason:null}:{result:!1,reason:"Public key * N != O"}:{result:!1,reason:"Public key is not a point"}},i.prototype.getPublic=function(e,t){return"string"==typeof e&&(t=e,e=null),this.pub||(this.pub=this.ec.g.mul(this.priv)),t?this.pub.encode(t,e):this.pub},i.prototype.getPrivate=function(e){return"hex"===e?this.priv.toString(16,2):this.priv},i.prototype._importPrivate=function(e,t){this.priv=new r(e,t||16),this.priv=this.priv.umod(this.ec.curve.n)},i.prototype._importPublic=function(e,t){if(e.x||e.y)return"mont"===this.ec.curve.type?o(e.x,"Need x coordinate"):"short"!==this.ec.curve.type&&"edwards"!==this.ec.curve.type||o(e.x&&e.y,"Need both x and y coordinate"),void(this.pub=this.ec.curve.point(e.x,e.y));this.pub=this.ec.curve.decodePoint(e,t)},i.prototype.derive=function(e){return e.mul(this.priv).getX()},i.prototype.sign=function(e,t,n){return this.ec.sign(e,this,t,n)},i.prototype.verify=function(e,t){return this.ec.verify(e,t,this)},i.prototype.inspect=function(){return""}},{"../../elliptic":67,"bn.js":"BN"}],76:[function(e,t,n){function i(e,t){if(e instanceof i)return e;this._importDER(e,t)||(l(e.r&&e.s,"Signature without r or s"),this.r=new c(e.r,16),this.s=new c(e.s,16),void 0===e.recoveryParam?this.recoveryParam=null:this.recoveryParam=e.recoveryParam)}function r(){this.place=0}function o(e,t){var n=e[t.place++];if(!(128&n))return n;for(var i=15&n,r=0,o=0,a=t.place;o>>3);for(e.push(128|n);--n;)e.push(t>>>(n<<3)&255);e.push(t)}}var c=e("bn.js"),u=e("../../elliptic").utils,l=u.assert;t.exports=i,i.prototype._importDER=function(e,t){e=u.toArray(e,t);var n=new r;if(48!==e[n.place++])return!1;if(o(e,n)+n.place!==e.length)return!1;if(2!==e[n.place++])return!1;var i=o(e,n),a=e.slice(n.place,i+n.place);if(n.place+=i,2!==e[n.place++])return!1;var s=o(e,n);if(e.length!==s+n.place)return!1;var l=e.slice(n.place,s+n.place);return 0===a[0]&&128&a[1]&&(a=a.slice(1)),0===l[0]&&128&l[1]&&(l=l.slice(1)),this.r=new c(a),this.s=new c(l),this.recoveryParam=null,!0},i.prototype.toDER=function(e){var t=this.r.toArray(),n=this.s.toArray();for(128&t[0]&&(t=[0].concat(t)),128&n[0]&&(n=[0].concat(n)),t=a(t),n=a(n);!(n[0]||128&n[1]);)n=n.slice(1);var i=[2];s(i,t.length),(i=i.concat(t)).push(2),s(i,n.length);var r=i.concat(n),o=[48];return s(o,r.length),o=o.concat(r),u.encode(o,e)}},{"../../elliptic":67,"bn.js":"BN"}],77:[function(e,t,n){function i(e){if(s("ed25519"===e,"only tested with ed25519 so far"),!(this instanceof i))return new i(e);var e=o.curves[e].curve;this.curve=e,this.g=e.g,this.g.precompute(e.n.bitLength()+1),this.pointClass=e.point().constructor,this.encodingLength=Math.ceil(e.n.bitLength()/8),this.hash=r.sha512}var r=e("hash.js"),o=e("../../elliptic"),a=o.utils,s=a.assert,c=a.parseBytes,u=e("./key"),l=e("./signature");t.exports=i,i.prototype.sign=function(e,t){e=c(e);var n=this.keyFromSecret(t),i=this.hashInt(n.messagePrefix(),e),r=this.g.mul(i),o=this.encodePoint(r),a=this.hashInt(o,n.pubBytes(),e).mul(n.priv()),s=i.add(a).umod(this.curve.n);return this.makeSignature({R:r,S:s,Rencoded:o})},i.prototype.verify=function(e,t,n){e=c(e),t=this.makeSignature(t);var i=this.keyFromPublic(n),r=this.hashInt(t.Rencoded(),i.pubBytes(),e),o=this.g.mul(t.S());return t.R().add(i.pub().mul(r)).eq(o)},i.prototype.hashInt=function(){for(var e=this.hash(),t=0;t=0;){var o;if(r.isOdd()){var a=r.andln(i-1);o=a>(i>>1)-1?(i>>1)-a:a,r.isubn(o)}else o=0;n.push(o);for(var s=0!==r.cmpn(0)&&0===r.andln(i-1)?t+1:1,c=1;c0||t.cmpn(-r)>0;){var o=e.andln(3)+i&3,a=t.andln(3)+r&3;3===o&&(o=-1),3===a&&(a=-1);var s;s=0==(1&o)?0:3!=(u=e.andln(7)+i&7)&&5!==u||2!==a?o:-o,n[0].push(s);var c;if(0==(1&a))c=0;else{var u=t.andln(7)+r&7;c=3!==u&&5!==u||2!==o?a:-a}n[1].push(c),2*i===s+1&&(i=1-i),2*r===c+1&&(r=1-r),e.iushrn(1),t.iushrn(1)}return n},i.cachedProperty=function(e,t,n){var i="_"+t;e.prototype[t]=function(){return void 0!==this[i]?this[i]:this[i]=n.call(this)}},i.parseBytes=function(e){return"string"==typeof e?i.toArray(e,"hex"):e},i.intFromLE=function(e){return new r(e,"hex","le")}},{"bn.js":"BN","minimalistic-assert":106,"minimalistic-crypto-utils":107}],82:[function(e,t,n){t.exports={name:"elliptic",version:"6.4.0",description:"EC cryptography",main:"lib/elliptic.js",files:["lib"],scripts:{jscs:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",jshint:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",lint:"npm run jscs && npm run jshint",unit:"istanbul test _mocha --reporter=spec test/index.js",test:"npm run lint && npm run unit",version:"grunt dist && git add dist/"},repository:{type:"git",url:"git@github.com:indutny/elliptic"},keywords:["EC","Elliptic","curve","Cryptography"],author:"Fedor Indutny ",license:"MIT",bugs:{url:"https://github.com/indutny/elliptic/issues"},homepage:"https://github.com/indutny/elliptic",devDependencies:{brfs:"^1.4.3",coveralls:"^2.11.3",grunt:"^0.4.5","grunt-browserify":"^5.0.0","grunt-cli":"^1.2.0","grunt-contrib-connect":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^1.0.1","grunt-mocha-istanbul":"^3.0.1","grunt-saucelabs":"^8.6.2",istanbul:"^0.4.2",jscs:"^2.9.0",jshint:"^2.6.0",mocha:"^2.1.0"},dependencies:{"bn.js":"^4.4.0",brorand:"^1.0.1","hash.js":"^1.0.0","hmac-drbg":"^1.0.0",inherits:"^2.0.1","minimalistic-assert":"^1.0.0","minimalistic-crypto-utils":"^1.0.0"}}},{}],83:[function(e,t,n){function i(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function o(e){return"number"==typeof e}function a(e){return"object"===(void 0===e?"undefined":_typeof(e))&&null!==e}function s(e){return void 0===e}t.exports=i,i.EventEmitter=i,i.prototype._events=void 0,i.prototype._maxListeners=void 0,i.defaultMaxListeners=10,i.prototype.setMaxListeners=function(e){if(!o(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},i.prototype.emit=function(e){var t,n,i,o,c,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||a(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var l=new Error('Uncaught, unspecified "error" event. ('+t+")");throw l.context=t,l}if(n=this._events[e],s(n))return!1;if(r(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:o=Array.prototype.slice.call(arguments,1),n.apply(this,o)}else if(a(n))for(o=Array.prototype.slice.call(arguments,1),i=(u=n.slice()).length,c=0;c0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},i.prototype.on=i.prototype.addListener,i.prototype.once=function(e,t){function n(){this.removeListener(e,n),i||(i=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var i=!1;return n.listener=t,this.on(e,n),this},i.prototype.removeListener=function(e,t){var n,i,o,s;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,i=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(a(n)){for(s=o;s-- >0;)if(n[s]===t||n[s].listener&&n[s].listener===t){i=s;break}if(i<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},i.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],r(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},i.prototype.listeners=function(e){return this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},i.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(r(t))return 1;if(t)return t.length}return 0},i.listenerCount=function(e,t){return e.listenerCount(t)}},{}],84:[function(e,t,n){var i=e("safe-buffer").Buffer,r=e("md5.js");t.exports=function(e,t,n,o){if(i.isBuffer(e)||(e=i.from(e,"binary")),t&&(i.isBuffer(t)||(t=i.from(t,"binary")),8!==t.length))throw new RangeError("salt should be Buffer with 8 byte length");for(var a=n/8,s=i.alloc(a),c=i.alloc(o||0),u=i.alloc(0);a>0||o>0;){var l=new r;l.update(u),l.update(e),t&&l.update(t),u=l.digest();var f=0;if(a>0){var p=s.length-a;f=Math.min(a,u.length),u.copy(s,p,0,f),a-=f}if(f0){var d=c.length-o,h=Math.min(o,u.length-f);u.copy(c,d,f,f+h),o-=h}}return u.fill(0),{key:s,iv:c}}},{"md5.js":103,"safe-buffer":144}],85:[function(e,t,n){(function(n){function i(e){r.call(this),this._block=new n(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}var r=e("stream").Transform;e("inherits")(i,r),i.prototype._transform=function(e,t,i){var r=null;try{"buffer"!==t&&(e=new n(e,t)),this.update(e)}catch(e){r=e}i(r)},i.prototype._flush=function(e){var t=null;try{this.push(this._digest())}catch(e){t=e}e(t)},i.prototype.update=function(e,t){if(!n.isBuffer(e)&&"string"!=typeof e)throw new TypeError("Data must be a string or a buffer");if(this._finalized)throw new Error("Digest already called");n.isBuffer(e)||(e=new n(e,t||"binary"));for(var i=this._block,r=0;this._blockOffset+e.length-r>=this._blockSize;){for(var o=this._blockOffset;o0;++a)this._length[a]+=s,(s=this._length[a]/4294967296|0)>0&&(this._length[a]-=4294967296*s);return this},i.prototype._update=function(e){throw new Error("_update is not implemented")},i.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();return void 0!==e&&(t=t.toString(e)),t},i.prototype._digest=function(){throw new Error("_digest is not implemented")},t.exports=i}).call(this,e("buffer").Buffer)},{buffer:47,inherits:101,stream:155}],86:[function(e,t,n){var i=n;i.utils=e("./hash/utils"),i.common=e("./hash/common"),i.sha=e("./hash/sha"),i.ripemd=e("./hash/ripemd"),i.hmac=e("./hash/hmac"),i.sha1=i.sha.sha1,i.sha256=i.sha.sha256,i.sha224=i.sha.sha224,i.sha384=i.sha.sha384,i.sha512=i.sha.sha512,i.ripemd160=i.ripemd.ripemd160},{"./hash/common":87,"./hash/hmac":88,"./hash/ripemd":89,"./hash/sha":90,"./hash/utils":97}],87:[function(e,t,n){function i(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}var r=e("./utils"),o=e("minimalistic-assert");n.BlockHash=i,i.prototype.update=function(e,t){if(e=r.toArray(e,t),this.pending?this.pending=this.pending.concat(e):this.pending=e,this.pendingTotal+=e.length,this.pending.length>=this._delta8){var n=(e=this.pending).length%this._delta8;this.pending=e.slice(e.length-n,e.length),0===this.pending.length&&(this.pending=null),e=r.join32(e,0,e.length-n,this.endian);for(var i=0;i>>24&255,i[r++]=e>>>16&255,i[r++]=e>>>8&255,i[r++]=255&e}else for(i[r++]=255&e,i[r++]=e>>>8&255,i[r++]=e>>>16&255,i[r++]=e>>>24&255,i[r++]=0,i[r++]=0,i[r++]=0,i[r++]=0,o=8;othis.blockSize&&(e=(new this.Hash).update(e).digest()),o(e.length<=this.blockSize);for(var t=e.length;t>>3},n.g1_256=function(e){return a(e,17)^a(e,19)^e>>>10}},{"../utils":97}],97:[function(e,t,n){function i(e){return(e>>>24|e>>>8&65280|e<<8&16711680|(255&e)<<24)>>>0}function r(e){return 1===e.length?"0"+e:e}function o(e){return 7===e.length?"0"+e:6===e.length?"00"+e:5===e.length?"000"+e:4===e.length?"0000"+e:3===e.length?"00000"+e:2===e.length?"000000"+e:1===e.length?"0000000"+e:e}var a=e("minimalistic-assert"),s=e("inherits");n.inherits=s,n.toArray=function(e,t){if(Array.isArray(e))return e.slice();if(!e)return[];var n=[];if("string"==typeof e)if(t){if("hex"===t)for((e=e.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(e="0"+e),i=0;i>8,a=255&r;o?n.push(o,a):n.push(a)}else for(i=0;i>>0}return o},n.split32=function(e,t){for(var n=new Array(4*e.length),i=0,r=0;i>>24,n[r+1]=o>>>16&255,n[r+2]=o>>>8&255,n[r+3]=255&o):(n[r+3]=o>>>24,n[r+2]=o>>>16&255,n[r+1]=o>>>8&255,n[r]=255&o)}return n},n.rotr32=function(e,t){return e>>>t|e<<32-t},n.rotl32=function(e,t){return e<>>32-t},n.sum32=function(e,t){return e+t>>>0},n.sum32_3=function(e,t,n){return e+t+n>>>0},n.sum32_4=function(e,t,n,i){return e+t+n+i>>>0},n.sum32_5=function(e,t,n,i,r){return e+t+n+i+r>>>0},n.sum64=function(e,t,n,i){var r=e[t],o=i+e[t+1]>>>0,a=(o>>0,e[t+1]=o},n.sum64_hi=function(e,t,n,i){return(t+i>>>0>>0},n.sum64_lo=function(e,t,n,i){return t+i>>>0},n.sum64_4_hi=function(e,t,n,i,r,o,a,s){var c=0,u=t;return c+=(u=u+i>>>0)>>0)>>0)>>0},n.sum64_4_lo=function(e,t,n,i,r,o,a,s){return t+i+o+s>>>0},n.sum64_5_hi=function(e,t,n,i,r,o,a,s,c,u){var l=0,f=t;return l+=(f=f+i>>>0)>>0)>>0)>>0)>>0},n.sum64_5_lo=function(e,t,n,i,r,o,a,s,c,u){return t+i+o+s+u>>>0},n.rotr64_hi=function(e,t,n){return(t<<32-n|e>>>n)>>>0},n.rotr64_lo=function(e,t,n){return(e<<32-n|t>>>n)>>>0},n.shr64_hi=function(e,t,n){return e>>>n},n.shr64_lo=function(e,t,n){return(e<<32-n|t>>>n)>>>0}},{inherits:101,"minimalistic-assert":106}],98:[function(e,t,n){function i(e){if(!(this instanceof i))return new i(e);this.hash=e.hash,this.predResist=!!e.predResist,this.outLen=this.hash.outSize,this.minEntropy=e.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var t=o.toArray(e.entropy,e.entropyEnc||"hex"),n=o.toArray(e.nonce,e.nonceEnc||"hex"),r=o.toArray(e.pers,e.persEnc||"hex");a(t.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(t,n,r)}var r=e("hash.js"),o=e("minimalistic-crypto-utils"),a=e("minimalistic-assert");t.exports=i,i.prototype._init=function(e,t,n){var i=e.concat(t).concat(n);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var r=0;r=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(e.concat(n||[])),this._reseed=1},i.prototype.generate=function(e,t,n,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof t&&(i=n,n=t,t=null),n&&(n=o.toArray(n,i||"hex"),this._update(n));for(var r=[];r.length>1,l=-7,f=n?r-1:0,p=n?-1:1,d=e[t+f];for(f+=p,o=d&(1<<-l)-1,d>>=-l,l+=s;l>0;o=256*o+e[t+f],f+=p,l-=8);for(a=o&(1<<-l)-1,o>>=-l,l+=i;l>0;a=256*a+e[t+f],f+=p,l-=8);if(0===o)o=1-u;else{if(o===c)return a?NaN:1/0*(d?-1:1);a+=Math.pow(2,i),o-=u}return(d?-1:1)*a*Math.pow(2,o-i)},n.write=function(e,t,n,i,r,o){var a,s,c,u=8*o-r-1,l=(1<>1,p=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,d=i?0:o-1,h=i?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,a=l):(a=Math.floor(Math.log(t)/Math.LN2),t*(c=Math.pow(2,-a))<1&&(a--,c*=2),(t+=a+f>=1?p/c:p*Math.pow(2,1-f))*c>=2&&(a++,c/=2),a+f>=l?(s=0,a=l):a+f>=1?(s=(t*c-1)*Math.pow(2,r),a+=f):(s=t*Math.pow(2,f-1)*Math.pow(2,r),a=0));r>=8;e[n+d]=255&s,d+=h,s/=256,r-=8);for(a=a<0;e[n+d]=255&a,d+=h,a/=256,u-=8);e[n+d-h]|=128*m}},{}],100:[function(e,t,n){var i=[].indexOf;t.exports=function(e,t){if(i)return e.indexOf(t);for(var n=0;n>>32-t}function o(e,t,n,i,o,a,s){return r(e+(t&n|~t&i)+o+a|0,s)+t|0}function a(e,t,n,i,o,a,s){return r(e+(t&i|n&~i)+o+a|0,s)+t|0}function s(e,t,n,i,o,a,s){return r(e+(t^n^i)+o+a|0,s)+t|0}function c(e,t,n,i,o,a,s){return r(e+(n^(t|~i))+o+a|0,s)+t|0}var u=e("inherits"),l=e("hash-base"),f=new Array(16);u(i,l),i.prototype._update=function(){for(var e=f,t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);var n=this._a,i=this._b,r=this._c,u=this._d;i=c(i=c(i=c(i=c(i=s(i=s(i=s(i=s(i=a(i=a(i=a(i=a(i=o(i=o(i=o(i=o(i,r=o(r,u=o(u,n=o(n,i,r,u,e[0],3614090360,7),i,r,e[1],3905402710,12),n,i,e[2],606105819,17),u,n,e[3],3250441966,22),r=o(r,u=o(u,n=o(n,i,r,u,e[4],4118548399,7),i,r,e[5],1200080426,12),n,i,e[6],2821735955,17),u,n,e[7],4249261313,22),r=o(r,u=o(u,n=o(n,i,r,u,e[8],1770035416,7),i,r,e[9],2336552879,12),n,i,e[10],4294925233,17),u,n,e[11],2304563134,22),r=o(r,u=o(u,n=o(n,i,r,u,e[12],1804603682,7),i,r,e[13],4254626195,12),n,i,e[14],2792965006,17),u,n,e[15],1236535329,22),r=a(r,u=a(u,n=a(n,i,r,u,e[1],4129170786,5),i,r,e[6],3225465664,9),n,i,e[11],643717713,14),u,n,e[0],3921069994,20),r=a(r,u=a(u,n=a(n,i,r,u,e[5],3593408605,5),i,r,e[10],38016083,9),n,i,e[15],3634488961,14),u,n,e[4],3889429448,20),r=a(r,u=a(u,n=a(n,i,r,u,e[9],568446438,5),i,r,e[14],3275163606,9),n,i,e[3],4107603335,14),u,n,e[8],1163531501,20),r=a(r,u=a(u,n=a(n,i,r,u,e[13],2850285829,5),i,r,e[2],4243563512,9),n,i,e[7],1735328473,14),u,n,e[12],2368359562,20),r=s(r,u=s(u,n=s(n,i,r,u,e[5],4294588738,4),i,r,e[8],2272392833,11),n,i,e[11],1839030562,16),u,n,e[14],4259657740,23),r=s(r,u=s(u,n=s(n,i,r,u,e[1],2763975236,4),i,r,e[4],1272893353,11),n,i,e[7],4139469664,16),u,n,e[10],3200236656,23),r=s(r,u=s(u,n=s(n,i,r,u,e[13],681279174,4),i,r,e[0],3936430074,11),n,i,e[3],3572445317,16),u,n,e[6],76029189,23),r=s(r,u=s(u,n=s(n,i,r,u,e[9],3654602809,4),i,r,e[12],3873151461,11),n,i,e[15],530742520,16),u,n,e[2],3299628645,23),r=c(r,u=c(u,n=c(n,i,r,u,e[0],4096336452,6),i,r,e[7],1126891415,10),n,i,e[14],2878612391,15),u,n,e[5],4237533241,21),r=c(r,u=c(u,n=c(n,i,r,u,e[12],1700485571,6),i,r,e[3],2399980690,10),n,i,e[10],4293915773,15),u,n,e[1],2240044497,21),r=c(r,u=c(u,n=c(n,i,r,u,e[8],1873313359,6),i,r,e[15],4264355552,10),n,i,e[6],2734768916,15),u,n,e[13],1309151649,21),r=c(r,u=c(u,n=c(n,i,r,u,e[4],4149444226,6),i,r,e[11],3174756917,10),n,i,e[2],718787259,15),u,n,e[9],3951481745,21),this._a=this._a+n|0,this._b=this._b+i|0,this._c=this._c+r|0,this._d=this._d+u|0},i.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=new n(16);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e},t.exports=i}).call(this,e("buffer").Buffer)},{buffer:47,"hash-base":104,inherits:101}],104:[function(e,t,n){function i(e,t){if(!o.isBuffer(e)&&"string"!=typeof e)throw new TypeError(t+" must be a string or a buffer")}function r(e){a.call(this),this._block=o.allocUnsafe(e),this._blockSize=e,this._blockOffset=0,this._length=[0,0,0,0],this._finalized=!1}var o=e("safe-buffer").Buffer,a=e("stream").Transform;e("inherits")(r,a),r.prototype._transform=function(e,t,n){var i=null;try{this.update(e,t)}catch(e){i=e}n(i)},r.prototype._flush=function(e){var t=null;try{this.push(this.digest())}catch(e){t=e}e(t)},r.prototype.update=function(e,t){if(i(e,"Data"),this._finalized)throw new Error("Digest already called");o.isBuffer(e)||(e=o.from(e,t));for(var n=this._block,r=0;this._blockOffset+e.length-r>=this._blockSize;){for(var a=this._blockOffset;a0;++s)this._length[s]+=c,(c=this._length[s]/4294967296|0)>0&&(this._length[s]-=4294967296*c);return this},r.prototype._update=function(){throw new Error("_update is not implemented")},r.prototype.digest=function(e){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var t=this._digest();void 0!==e&&(t=t.toString(e)),this._block.fill(0),this._blockOffset=0;for(var n=0;n<4;++n)this._length[n]=0;return t},r.prototype._digest=function(){throw new Error("_digest is not implemented")},t.exports=r},{inherits:101,"safe-buffer":144,stream:155}],105:[function(e,t,n){function i(e){this.rand=e||new o.Rand}var r=e("bn.js"),o=e("brorand");t.exports=i,i.create=function(e){return new i(e)},i.prototype._randbelow=function(e){var t=e.bitLength(),n=Math.ceil(t/8);do{var i=new r(this.rand.generate(n))}while(i.cmp(e)>=0);return i},i.prototype._randrange=function(e,t){var n=t.sub(e);return e.add(this._randbelow(n))},i.prototype.test=function(e,t,n){var i=e.bitLength(),o=r.mont(e),a=new r(1).toRed(o);t||(t=Math.max(1,i/48|0));for(var s=e.subn(1),c=0;!s.testn(c);c++);for(var u=e.shrn(c),l=s.toRed(o);t>0;t--){var f=this._randrange(new r(2),s);n&&n(f);var p=f.toRed(o).redPow(u);if(0!==p.cmp(a)&&0!==p.cmp(l)){for(var d=1;d0;t--){var l=this._randrange(new r(2),a),f=e.gcd(l);if(0!==f.cmpn(1))return f;var p=l.toRed(i).redPow(c);if(0!==p.cmp(o)&&0!==p.cmp(u)){for(var d=1;d>8,a=255&r;o?n.push(o,a):n.push(a)}return n},o.zero2=i,o.toHex=r,o.encode=function(e,t){return"hex"===t?r(e):e}},{}],108:[function(e,t,n){t.exports={"2.16.840.1.101.3.4.1.1":"aes-128-ecb","2.16.840.1.101.3.4.1.2":"aes-128-cbc","2.16.840.1.101.3.4.1.3":"aes-128-ofb","2.16.840.1.101.3.4.1.4":"aes-128-cfb","2.16.840.1.101.3.4.1.21":"aes-192-ecb","2.16.840.1.101.3.4.1.22":"aes-192-cbc","2.16.840.1.101.3.4.1.23":"aes-192-ofb","2.16.840.1.101.3.4.1.24":"aes-192-cfb","2.16.840.1.101.3.4.1.41":"aes-256-ecb","2.16.840.1.101.3.4.1.42":"aes-256-cbc","2.16.840.1.101.3.4.1.43":"aes-256-ofb","2.16.840.1.101.3.4.1.44":"aes-256-cfb"}},{}],109:[function(e,t,n){var i=e("asn1.js");n.certificate=e("./certificate");var r=i.define("RSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("modulus").int(),this.key("publicExponent").int(),this.key("privateExponent").int(),this.key("prime1").int(),this.key("prime2").int(),this.key("exponent1").int(),this.key("exponent2").int(),this.key("coefficient").int())});n.RSAPrivateKey=r;var o=i.define("RSAPublicKey",function(){this.seq().obj(this.key("modulus").int(),this.key("publicExponent").int())});n.RSAPublicKey=o;var a=i.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(s),this.key("subjectPublicKey").bitstr())});n.PublicKey=a;var s=i.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("none").null_().optional(),this.key("curve").objid().optional(),this.key("params").seq().obj(this.key("p").int(),this.key("q").int(),this.key("g").int()).optional())}),c=i.define("PrivateKeyInfo",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").use(s),this.key("subjectPrivateKey").octstr())});n.PrivateKey=c;var u=i.define("EncryptedPrivateKeyInfo",function(){this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(),this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(),this.key("kdeparams").seq().obj(this.key("salt").octstr(),this.key("iters").int())),this.key("cipher").seq().obj(this.key("algo").objid(),this.key("iv").octstr()))),this.key("subjectPrivateKey").octstr())});n.EncryptedPrivateKey=u;var l=i.define("DSAPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("p").int(),this.key("q").int(),this.key("g").int(),this.key("pub_key").int(),this.key("priv_key").int())});n.DSAPrivateKey=l,n.DSAparam=i.define("DSAparam",function(){this.int()});var f=i.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").optional().explicit(0).use(p),this.key("publicKey").optional().explicit(1).bitstr())});n.ECPrivateKey=f;var p=i.define("ECParameters",function(){this.choice({namedCurve:this.objid()})});n.signature=i.define("signature",function(){this.seq().obj(this.key("r").int(),this.key("s").int())})},{"./certificate":110,"asn1.js":1}],110:[function(e,t,n){var i=e("asn1.js"),r=i.define("Time",function(){this.choice({utcTime:this.utctime(),generalTime:this.gentime()})}),o=i.define("AttributeTypeValue",function(){this.seq().obj(this.key("type").objid(),this.key("value").any())}),a=i.define("AlgorithmIdentifier",function(){this.seq().obj(this.key("algorithm").objid(),this.key("parameters").optional())}),s=i.define("SubjectPublicKeyInfo",function(){this.seq().obj(this.key("algorithm").use(a),this.key("subjectPublicKey").bitstr())}),c=i.define("RelativeDistinguishedName",function(){this.setof(o)}),u=i.define("RDNSequence",function(){this.seqof(c)}),l=i.define("Name",function(){this.choice({rdnSequence:this.use(u)})}),f=i.define("Validity",function(){this.seq().obj(this.key("notBefore").use(r),this.key("notAfter").use(r))}),p=i.define("Extension",function(){this.seq().obj(this.key("extnID").objid(),this.key("critical").bool().def(!1),this.key("extnValue").octstr())}),d=i.define("TBSCertificate",function(){this.seq().obj(this.key("version").explicit(0).int(),this.key("serialNumber").int(),this.key("signature").use(a),this.key("issuer").use(l),this.key("validity").use(f),this.key("subject").use(l),this.key("subjectPublicKeyInfo").use(s),this.key("issuerUniqueID").implicit(1).bitstr().optional(),this.key("subjectUniqueID").implicit(2).bitstr().optional(),this.key("extensions").explicit(3).seqof(p).optional())}),h=i.define("X509Certificate",function(){this.seq().obj(this.key("tbsCertificate").use(d),this.key("signatureAlgorithm").use(a),this.key("signatureValue").bitstr())});t.exports=h},{"asn1.js":1}],111:[function(e,t,n){(function(n){var i=/Proc-Type: 4,ENCRYPTED\n\r?DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)\n\r?\n\r?([0-9A-z\n\r\+\/\=]+)\n\r?/m,r=/^-----BEGIN ((?:.* KEY)|CERTIFICATE)-----\n/m,o=/^-----BEGIN ((?:.* KEY)|CERTIFICATE)-----\n\r?([0-9A-z\n\r\+\/\=]+)\n\r?-----END \1-----$/m,a=e("evp_bytestokey"),s=e("browserify-aes");t.exports=function(e,t){var c,u=e.toString(),l=u.match(i);if(l){var f="aes"+l[1],p=new n(l[2],"hex"),d=new n(l[3].replace(/\r?\n/g,""),"base64"),h=a(t,p.slice(0,8),parseInt(l[1],10)).key,m=[],v=s.createDecipheriv(f,h,p);m.push(v.update(d)),m.push(v.final()),c=n.concat(m)}else{var b=u.match(o);c=new n(b[2].replace(/\r?\n/g,""),"base64")}return{tag:u.match(r)[1],data:c}}}).call(this,e("buffer").Buffer)},{"browserify-aes":20,buffer:47,evp_bytestokey:84}],112:[function(e,t,n){(function(n){function i(e){var t;"object"!==(void 0===e?"undefined":_typeof(e))||n.isBuffer(e)||(t=e.passphrase,e=e.key),"string"==typeof e&&(e=new n(e));var i,a,c=s(e,t),u=c.tag,l=c.data;switch(u){case"CERTIFICATE":a=o.certificate.decode(l,"der").tbsCertificate.subjectPublicKeyInfo;case"PUBLIC KEY":switch(a||(a=o.PublicKey.decode(l,"der")),i=a.algorithm.algorithm.join(".")){case"1.2.840.113549.1.1.1":return o.RSAPublicKey.decode(a.subjectPublicKey.data,"der");case"1.2.840.10045.2.1":return a.subjectPrivateKey=a.subjectPublicKey,{type:"ec",data:a};case"1.2.840.10040.4.1":return a.algorithm.params.pub_key=o.DSAparam.decode(a.subjectPublicKey.data,"der"),{type:"dsa",data:a.algorithm.params};default:throw new Error("unknown key id "+i)}throw new Error("unknown key type "+u);case"ENCRYPTED PRIVATE KEY":l=r(l=o.EncryptedPrivateKey.decode(l,"der"),t);case"PRIVATE KEY":switch(a=o.PrivateKey.decode(l,"der"),i=a.algorithm.algorithm.join(".")){case"1.2.840.113549.1.1.1":return o.RSAPrivateKey.decode(a.subjectPrivateKey,"der");case"1.2.840.10045.2.1":return{curve:a.algorithm.curve,privateKey:o.ECPrivateKey.decode(a.subjectPrivateKey,"der").privateKey};case"1.2.840.10040.4.1":return a.algorithm.params.priv_key=o.DSAparam.decode(a.subjectPrivateKey,"der"),{type:"dsa",params:a.algorithm.params};default:throw new Error("unknown key id "+i)}throw new Error("unknown key type "+u);case"RSA PUBLIC KEY":return o.RSAPublicKey.decode(l,"der");case"RSA PRIVATE KEY":return o.RSAPrivateKey.decode(l,"der");case"DSA PRIVATE KEY":return{type:"dsa",params:o.DSAPrivateKey.decode(l,"der")};case"EC PRIVATE KEY":return l=o.ECPrivateKey.decode(l,"der"),{curve:l.parameters.value,privateKey:l.privateKey};default:throw new Error("unknown key type "+u)}}function r(e,t){var i=e.algorithm.decrypt.kde.kdeparams.salt,r=parseInt(e.algorithm.decrypt.kde.kdeparams.iters.toString(),10),o=a[e.algorithm.decrypt.cipher.algo.join(".")],s=e.algorithm.decrypt.cipher.iv,l=e.subjectPrivateKey,f=parseInt(o.split("-")[1],10)/8,p=u.pbkdf2Sync(t,i,r,f),d=c.createDecipheriv(o,p,s),h=[];return h.push(d.update(l)),h.push(d.final()),n.concat(h)}var o=e("./asn1"),a=e("./aesid.json"),s=e("./fixProc"),c=e("browserify-aes"),u=e("pbkdf2");t.exports=i,i.signature=o.signature}).call(this,e("buffer").Buffer)},{"./aesid.json":108,"./asn1":109,"./fixProc":111,"browserify-aes":20,buffer:47,pbkdf2:114}],113:[function(e,t,n){(function(e){function t(e,t){for(var n=0,i=e.length-1;i>=0;i--){var r=e[i];"."===r?e.splice(i,1):".."===r?(e.splice(i,1),n++):n&&(e.splice(i,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}function i(e,t){if(e.filter)return e.filter(t);for(var n=[],i=0;i=-1&&!r;o--){var a=o>=0?arguments[o]:e.cwd();if("string"!=typeof a)throw new TypeError("Arguments to path.resolve must be strings");a&&(n=a+"/"+n,r="/"===a.charAt(0))}return n=t(i(n.split("/"),function(e){return!!e}),!r).join("/"),(r?"/":"")+n||"."},n.normalize=function(e){var r=n.isAbsolute(e),o="/"===a(e,-1);return(e=t(i(e.split("/"),function(e){return!!e}),!r).join("/"))||r||(e="."),e&&o&&(e+="/"),(r?"/":"")+e},n.isAbsolute=function(e){return"/"===e.charAt(0)},n.join=function(){var e=Array.prototype.slice.call(arguments,0);return n.normalize(i(e,function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e}).join("/"))},n.relative=function(e,t){function i(e){for(var t=0;t=0&&""===e[n];n--);return t>n?[]:e.slice(t,n-t+1)}e=n.resolve(e).substr(1),t=n.resolve(t).substr(1);for(var r=i(e.split("/")),o=i(t.split("/")),a=Math.min(r.length,o.length),s=a,c=0;c=6?"utf-8":"binary",t.exports=n}).call(this,e("_process"))},{_process:120}],117:[function(e,t,n){var i=Math.pow(2,30)-1;t.exports=function(e,t){if("number"!=typeof e)throw new TypeError("Iterations not a number");if(e<0)throw new TypeError("Bad iterations");if("number"!=typeof t)throw new TypeError("Key length not a number");if(t<0||t>i||t!==t)throw new TypeError("Bad key length")}},{}],118:[function(e,t,n){function i(e,t,n){var i=r(e),o="sha512"===e||"sha384"===e?128:64;t.length>o?t=i(t):t.length1)for(var n=1;n=t.length){o++;break}var a=t.slice(2,r-1);t.slice(r-1,r);if(("0002"!==i.toString("hex")&&!n||"0001"!==i.toString("hex")&&n)&&o++,a.length<8&&o++,o)throw new Error("decryption error");return t.slice(r)}function o(e,t){e=new n(e),t=new n(t);var i=0,r=e.length;e.length!==t.length&&(i++,r=Math.min(e.length,t.length));for(var o=-1;++of||new u(t).cmp(c.modulus)>=0)throw new Error("decryption error");var d;d=o?p(new u(t),c):l(t,c);var h=new n(f-d.length);if(h.fill(0),d=n.concat([h,d],f),4===s)return i(c,d);if(1===s)return r(0,d,o);if(3===s)return d;throw new Error("unknown padding")}}).call(this,e("buffer").Buffer)},{"./mgf":122,"./withPublic":125,"./xor":126,"bn.js":"BN","browserify-rsa":37,buffer:47,"create-hash":51,"parse-asn1":112}],124:[function(e,t,n){(function(n){function i(e,t){var i=e.modulus.byteLength(),r=t.length,o=c("sha1").update(new n("")).digest(),a=o.length,p=2*a;if(r>i-p-2)throw new Error("message too long");var d=new n(i-r-p-2);d.fill(0);var h=i-a-1,m=s(a),v=l(n.concat([o,d,new n([1]),t],h),u(m,h)),b=l(m,u(v,a));return new f(n.concat([new n([0]),b,v],i))}function r(e,t,i){var r=t.length,a=e.modulus.byteLength();if(r>a-11)throw new Error("message too long");var s;return i?(s=new n(a-r-3)).fill(255):s=o(a-r-3),new f(n.concat([new n([0,i?1:2]),s,new n([0]),t],a))}function o(e,t){for(var i,r=new n(e),o=0,a=s(2*e),c=0;o=0)throw new Error("data too long for modulus")}return n?d(s,c):p(s,c)}}).call(this,e("buffer").Buffer)},{"./mgf":122,"./withPublic":125,"./xor":126,"bn.js":"BN","browserify-rsa":37,buffer:47,"create-hash":51,"parse-asn1":112,randombytes:127}],125:[function(e,t,n){(function(n){var i=e("bn.js");t.exports=function(e,t){return new n(e.toRed(i.mont(t.modulus)).redPow(new i(t.publicExponent)).fromRed().toArray())}}).call(this,e("buffer").Buffer)},{"bn.js":"BN",buffer:47}],126:[function(e,t,n){t.exports=function(e,t){for(var n=e.length,i=-1;++i65536)throw new Error("requested too many random bytes");var a=new i.Uint8Array(e);e>0&&o.getRandomValues(a);var s=r.from(a.buffer);return"function"==typeof t?n.nextTick(function(){t(null,s)}):s}:t.exports=function(){throw new Error("secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11")}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:120,"safe-buffer":144}],128:[function(e,t,n){t.exports=e("./lib/_stream_duplex.js")},{"./lib/_stream_duplex.js":129}],129:[function(e,t,n){function i(e){if(!(this instanceof i))return new i(e);u.call(this,e),l.call(this,e),e&&!1===e.readable&&(this.readable=!1),e&&!1===e.writable&&(this.writable=!1),this.allowHalfOpen=!0,e&&!1===e.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",r)}function r(){this.allowHalfOpen||this._writableState.ended||a(o,this)}function o(e){e.end()}var a=e("process-nextick-args"),s=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};t.exports=i;var c=e("core-util-is");c.inherits=e("inherits");var u=e("./_stream_readable"),l=e("./_stream_writable");c.inherits(i,u);for(var f=s(l.prototype),p=0;p0?("string"==typeof t||a.objectMode||Object.getPrototypeOf(t)===N.prototype||(t=r(t)),i?a.endEmitted?e.emit("error",new Error("stream.unshift() after end event")):l(e,a,t,!0):a.ended?e.emit("error",new Error("stream.push() after EOF")):(a.reading=!1,a.decoder&&!n?(t=a.decoder.write(t),a.objectMode||0!==t.length?l(e,a,t,!1):y(e,a)):l(e,a,t,!1))):i||(a.reading=!1)}return p(a)}function l(e,t,n,i){t.flowing&&0===t.length&&!t.sync?(e.emit("data",n),e.read(0)):(t.length+=t.objectMode?1:n.length,i?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&v(e)),y(e,t)}function f(e,t){var n;return o(t)||"string"==typeof t||void 0===t||e.objectMode||(n=new TypeError("Invalid non-string/buffer chunk")),n}function p(e){return!e.ended&&(e.needReadable||e.length=W?e=W:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function h(e,t){return e<=0||0===t.length&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=d(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function m(e,t){if(!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,v(e)}}function v(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(z("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?F(b,e):b(e))}function b(e){z("emit readable"),e.emit("readable"),j(e)}function y(e,t){t.readingMore||(t.readingMore=!0,F(g,e,t))}function g(e,t){for(var n=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.head.data:t.buffer.concat(t.length),t.buffer.clear()):n=E(e,t.buffer,t.decoder),n}function E(e,t,n){var i;return eo.length?o.length:e;if(a===o.length?r+=o:r+=o.slice(0,e),0===(e-=a)){a===o.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=o.slice(a));break}++i}return t.length-=i,r}function C(e,t){var n=N.allocUnsafe(e),i=t.head,r=1;for(i.data.copy(n),e-=i.data.length;i=i.next;){var o=i.data,a=e>o.length?o.length:e;if(o.copy(n,n.length-e,0,a),0===(e-=a)){a===o.length?(++r,i.next?t.head=i.next:t.head=t.tail=null):(t.head=i,i.data=o.slice(a));break}++r}return t.length-=r,n}function M(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,F(T,t,e))}function T(e,t){e.endEmitted||0!==e.length||(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function P(e,t){for(var n=0,i=e.length;n=t.highWaterMark||t.ended))return z("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?M(this):v(this),null;if(0===(e=h(e,t))&&t.ended)return 0===t.length&&M(this),null;var i=t.needReadable;z("need readable",i),(0===t.length||t.length-e0?S(e,t):null)?(t.needReadable=!0,e=0):t.length-=e,0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&M(this)),null!==r&&this.emit("data",r),r},c.prototype._read=function(e){this.emit("error",new Error("_read() is not implemented"))},c.prototype.pipe=function(e,t){function i(e,t){z("onunpipe"),e===p&&t&&!1===t.hasUnpiped&&(t.hasUnpiped=!0,o())}function r(){z("onend"),e.end()}function o(){z("cleanup"),e.removeListener("close",u),e.removeListener("finish",l),e.removeListener("drain",m),e.removeListener("error",c),e.removeListener("unpipe",i),p.removeListener("end",r),p.removeListener("end",f),p.removeListener("data",s),v=!0,!d.awaitDrain||e._writableState&&!e._writableState.needDrain||m()}function s(t){z("ondata"),b=!1,!1!==e.write(t)||b||((1===d.pipesCount&&d.pipes===e||d.pipesCount>1&&-1!==P(d.pipes,e))&&!v&&(z("false write response, pause",p._readableState.awaitDrain),p._readableState.awaitDrain++,b=!0),p.pause())}function c(t){z("onerror",t),f(),e.removeListener("error",c),0===R(e,"error")&&e.emit("error",t)}function u(){e.removeListener("finish",l),f()}function l(){z("onfinish"),e.removeListener("close",u),f()}function f(){z("unpipe"),p.unpipe(e)}var p=this,d=this._readableState;switch(d.pipesCount){case 0:d.pipes=e;break;case 1:d.pipes=[d.pipes,e];break;default:d.pipes.push(e)}d.pipesCount+=1,z("pipe count=%d opts=%j",d.pipesCount,t);var h=(!t||!1!==t.end)&&e!==n.stdout&&e!==n.stderr?r:f;d.endEmitted?F(h):p.once("end",h),e.on("unpipe",i);var m=_(p);e.on("drain",m);var v=!1,b=!1;return p.on("data",s),a(e,"error",c),e.once("close",u),e.once("finish",l),e.emit("pipe",p),d.flowing||(z("pipe resume"),p.resume()),e},c.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n),this);if(!e){var i=t.pipes,r=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var o=0;o-1?setImmediate:A;u.WritableState=c;var T=e("core-util-is");T.inherits=e("inherits");var P={deprecate:e("util-deprecate")},F=e("./internal/streams/stream"),I=e("safe-buffer").Buffer,B=i.Uint8Array||function(){},R=e("./internal/streams/destroy");T.inherits(u,F),c.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},function(){try{Object.defineProperty(c.prototype,"buffer",{get:P.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(e){}}();var O;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(O=Function.prototype[Symbol.hasInstance],Object.defineProperty(u,Symbol.hasInstance,{value:function(e){return!!O.call(this,e)||e&&e._writableState instanceof c}})):O=function(e){return e instanceof this},u.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},u.prototype.write=function(e,t,n){var i=this._writableState,r=!1,c=a(e)&&!i.objectMode;return c&&!I.isBuffer(e)&&(e=o(e)),"function"==typeof t&&(n=t,t=null),c?t="buffer":t||(t=i.defaultEncoding),"function"!=typeof n&&(n=s),i.ended?l(this,n):(c||f(this,i,e,n))&&(i.pendingcb++,r=d(this,i,c,e,t,n)),r},u.prototype.cork=function(){this._writableState.corked++},u.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,e.writing||e.corked||e.finished||e.bufferProcessing||!e.bufferedRequest||_(this,e))},u.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=e.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((e+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+e);return this._writableState.defaultEncoding=e,this},u.prototype._write=function(e,t,n){n(new Error("_write() is not implemented"))},u.prototype._writev=null,u.prototype.end=function(e,t,n){var i=this._writableState;"function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!==e&&void 0!==e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||i.finished||S(this,i,n)},Object.defineProperty(u.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),u.prototype.destroy=R.destroy,u.prototype._undestroy=R.undestroy,u.prototype._destroy=function(e,t){this.end(),t(e)}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./_stream_duplex":129,"./internal/streams/destroy":135,"./internal/streams/stream":136,_process:120,"core-util-is":49,inherits:101,"process-nextick-args":119,"safe-buffer":144,"util-deprecate":156}],134:[function(e,t,n){function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t,n){e.copy(t,n)}var o=e("safe-buffer").Buffer;t.exports=function(){function e(){i(this,e),this.head=null,this.tail=null,this.length=0}return e.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},e.prototype.unshift=function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length},e.prototype.shift=function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},e.prototype.clear=function(){this.head=this.tail=null,this.length=0},e.prototype.join=function(e){if(0===this.length)return"";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n},e.prototype.concat=function(e){if(0===this.length)return o.alloc(0);if(1===this.length)return this.head.data;for(var t=o.allocUnsafe(e>>>0),n=this.head,i=0;n;)r(n.data,t,i),i+=n.data.length,n=n.next;return t},e}()},{"safe-buffer":144}],135:[function(e,t,n){function i(e,t){e.emit("error",t)}var r=e("process-nextick-args");t.exports={destroy:function(e,t){var n=this,o=this._readableState&&this._readableState.destroyed,a=this._writableState&&this._writableState.destroyed;o||a?t?t(e):!e||this._writableState&&this._writableState.errorEmitted||r(i,this,e):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(e){!t&&e?(r(i,n,e),n._writableState&&(n._writableState.errorEmitted=!0)):t&&t(e)}))},undestroy:function(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}}},{"process-nextick-args":119}],136:[function(e,t,n){t.exports=e("events").EventEmitter},{events:83}],137:[function(e,t,n){var i={}.toString;t.exports=Array.isArray||function(e){return"[object Array]"==i.call(e)}},{}],138:[function(e,t,n){arguments[4][45][0].apply(n,arguments)},{dup:45,"safe-buffer":144}],139:[function(e,t,n){t.exports=e("./readable").PassThrough},{"./readable":140}],140:[function(e,t,n){(n=t.exports=e("./lib/_stream_readable.js")).Stream=n,n.Readable=n,n.Writable=e("./lib/_stream_writable.js"),n.Duplex=e("./lib/_stream_duplex.js"),n.Transform=e("./lib/_stream_transform.js"),n.PassThrough=e("./lib/_stream_passthrough.js")},{"./lib/_stream_duplex.js":129,"./lib/_stream_passthrough.js":130,"./lib/_stream_readable.js":131,"./lib/_stream_transform.js":132,"./lib/_stream_writable.js":133}],141:[function(e,t,n){t.exports=e("./readable").Transform},{"./readable":140}],142:[function(e,t,n){t.exports=e("./lib/_stream_writable.js")},{"./lib/_stream_writable.js":133}],143:[function(e,t,n){(function(n){function i(){f.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520}function r(e,t){return e<>>32-t}function o(e,t,n,i,o,a,s,c){return r(e+(t^n^i)+a+s|0,c)+o|0}function a(e,t,n,i,o,a,s,c){return r(e+(t&n|~t&i)+a+s|0,c)+o|0}function s(e,t,n,i,o,a,s,c){return r(e+((t|~n)^i)+a+s|0,c)+o|0}function c(e,t,n,i,o,a,s,c){return r(e+(t&i|n&~i)+a+s|0,c)+o|0}function u(e,t,n,i,o,a,s,c){return r(e+(t^(n|~i))+a+s|0,c)+o|0}var l=e("inherits"),f=e("hash-base");l(i,f),i.prototype._update=function(){for(var e=new Array(16),t=0;t<16;++t)e[t]=this._block.readInt32LE(4*t);var n=this._a,i=this._b,l=this._c,f=this._d,p=this._e;p=o(p,n=o(n,i,l,f,p,e[0],0,11),i,l=r(l,10),f,e[1],0,14),i=o(i=r(i,10),l=o(l,f=o(f,p,n,i,l,e[2],0,15),p,n=r(n,10),i,e[3],0,12),f,p=r(p,10),n,e[4],0,5),f=o(f=r(f,10),p=o(p,n=o(n,i,l,f,p,e[5],0,8),i,l=r(l,10),f,e[6],0,7),n,i=r(i,10),l,e[7],0,9),n=o(n=r(n,10),i=o(i,l=o(l,f,p,n,i,e[8],0,11),f,p=r(p,10),n,e[9],0,13),l,f=r(f,10),p,e[10],0,14),l=o(l=r(l,10),f=o(f,p=o(p,n,i,l,f,e[11],0,15),n,i=r(i,10),l,e[12],0,6),p,n=r(n,10),i,e[13],0,7),p=a(p=r(p,10),n=o(n,i=o(i,l,f,p,n,e[14],0,9),l,f=r(f,10),p,e[15],0,8),i,l=r(l,10),f,e[7],1518500249,7),i=a(i=r(i,10),l=a(l,f=a(f,p,n,i,l,e[4],1518500249,6),p,n=r(n,10),i,e[13],1518500249,8),f,p=r(p,10),n,e[1],1518500249,13),f=a(f=r(f,10),p=a(p,n=a(n,i,l,f,p,e[10],1518500249,11),i,l=r(l,10),f,e[6],1518500249,9),n,i=r(i,10),l,e[15],1518500249,7),n=a(n=r(n,10),i=a(i,l=a(l,f,p,n,i,e[3],1518500249,15),f,p=r(p,10),n,e[12],1518500249,7),l,f=r(f,10),p,e[0],1518500249,12),l=a(l=r(l,10),f=a(f,p=a(p,n,i,l,f,e[9],1518500249,15),n,i=r(i,10),l,e[5],1518500249,9),p,n=r(n,10),i,e[2],1518500249,11),p=a(p=r(p,10),n=a(n,i=a(i,l,f,p,n,e[14],1518500249,7),l,f=r(f,10),p,e[11],1518500249,13),i,l=r(l,10),f,e[8],1518500249,12),i=s(i=r(i,10),l=s(l,f=s(f,p,n,i,l,e[3],1859775393,11),p,n=r(n,10),i,e[10],1859775393,13),f,p=r(p,10),n,e[14],1859775393,6),f=s(f=r(f,10),p=s(p,n=s(n,i,l,f,p,e[4],1859775393,7),i,l=r(l,10),f,e[9],1859775393,14),n,i=r(i,10),l,e[15],1859775393,9),n=s(n=r(n,10),i=s(i,l=s(l,f,p,n,i,e[8],1859775393,13),f,p=r(p,10),n,e[1],1859775393,15),l,f=r(f,10),p,e[2],1859775393,14),l=s(l=r(l,10),f=s(f,p=s(p,n,i,l,f,e[7],1859775393,8),n,i=r(i,10),l,e[0],1859775393,13),p,n=r(n,10),i,e[6],1859775393,6),p=s(p=r(p,10),n=s(n,i=s(i,l,f,p,n,e[13],1859775393,5),l,f=r(f,10),p,e[11],1859775393,12),i,l=r(l,10),f,e[5],1859775393,7),i=c(i=r(i,10),l=c(l,f=s(f,p,n,i,l,e[12],1859775393,5),p,n=r(n,10),i,e[1],2400959708,11),f,p=r(p,10),n,e[9],2400959708,12),f=c(f=r(f,10),p=c(p,n=c(n,i,l,f,p,e[11],2400959708,14),i,l=r(l,10),f,e[10],2400959708,15),n,i=r(i,10),l,e[0],2400959708,14),n=c(n=r(n,10),i=c(i,l=c(l,f,p,n,i,e[8],2400959708,15),f,p=r(p,10),n,e[12],2400959708,9),l,f=r(f,10),p,e[4],2400959708,8),l=c(l=r(l,10),f=c(f,p=c(p,n,i,l,f,e[13],2400959708,9),n,i=r(i,10),l,e[3],2400959708,14),p,n=r(n,10),i,e[7],2400959708,5),p=c(p=r(p,10),n=c(n,i=c(i,l,f,p,n,e[15],2400959708,6),l,f=r(f,10),p,e[14],2400959708,8),i,l=r(l,10),f,e[5],2400959708,6),i=u(i=r(i,10),l=c(l,f=c(f,p,n,i,l,e[6],2400959708,5),p,n=r(n,10),i,e[2],2400959708,12),f,p=r(p,10),n,e[4],2840853838,9),f=u(f=r(f,10),p=u(p,n=u(n,i,l,f,p,e[0],2840853838,15),i,l=r(l,10),f,e[5],2840853838,5),n,i=r(i,10),l,e[9],2840853838,11),n=u(n=r(n,10),i=u(i,l=u(l,f,p,n,i,e[7],2840853838,6),f,p=r(p,10),n,e[12],2840853838,8),l,f=r(f,10),p,e[2],2840853838,13),l=u(l=r(l,10),f=u(f,p=u(p,n,i,l,f,e[10],2840853838,12),n,i=r(i,10),l,e[14],2840853838,5),p,n=r(n,10),i,e[1],2840853838,12),p=u(p=r(p,10),n=u(n,i=u(i,l,f,p,n,e[3],2840853838,13),l,f=r(f,10),p,e[8],2840853838,14),i,l=r(l,10),f,e[11],2840853838,11),i=u(i=r(i,10),l=u(l,f=u(f,p,n,i,l,e[6],2840853838,8),p,n=r(n,10),i,e[15],2840853838,5),f,p=r(p,10),n,e[13],2840853838,6),f=r(f,10);var d=this._a,h=this._b,m=this._c,v=this._d,b=this._e;b=u(b,d=u(d,h,m,v,b,e[5],1352829926,8),h,m=r(m,10),v,e[14],1352829926,9),h=u(h=r(h,10),m=u(m,v=u(v,b,d,h,m,e[7],1352829926,9),b,d=r(d,10),h,e[0],1352829926,11),v,b=r(b,10),d,e[9],1352829926,13),v=u(v=r(v,10),b=u(b,d=u(d,h,m,v,b,e[2],1352829926,15),h,m=r(m,10),v,e[11],1352829926,15),d,h=r(h,10),m,e[4],1352829926,5),d=u(d=r(d,10),h=u(h,m=u(m,v,b,d,h,e[13],1352829926,7),v,b=r(b,10),d,e[6],1352829926,7),m,v=r(v,10),b,e[15],1352829926,8),m=u(m=r(m,10),v=u(v,b=u(b,d,h,m,v,e[8],1352829926,11),d,h=r(h,10),m,e[1],1352829926,14),b,d=r(d,10),h,e[10],1352829926,14),b=c(b=r(b,10),d=u(d,h=u(h,m,v,b,d,e[3],1352829926,12),m,v=r(v,10),b,e[12],1352829926,6),h,m=r(m,10),v,e[6],1548603684,9),h=c(h=r(h,10),m=c(m,v=c(v,b,d,h,m,e[11],1548603684,13),b,d=r(d,10),h,e[3],1548603684,15),v,b=r(b,10),d,e[7],1548603684,7),v=c(v=r(v,10),b=c(b,d=c(d,h,m,v,b,e[0],1548603684,12),h,m=r(m,10),v,e[13],1548603684,8),d,h=r(h,10),m,e[5],1548603684,9),d=c(d=r(d,10),h=c(h,m=c(m,v,b,d,h,e[10],1548603684,11),v,b=r(b,10),d,e[14],1548603684,7),m,v=r(v,10),b,e[15],1548603684,7),m=c(m=r(m,10),v=c(v,b=c(b,d,h,m,v,e[8],1548603684,12),d,h=r(h,10),m,e[12],1548603684,7),b,d=r(d,10),h,e[4],1548603684,6),b=c(b=r(b,10),d=c(d,h=c(h,m,v,b,d,e[9],1548603684,15),m,v=r(v,10),b,e[1],1548603684,13),h,m=r(m,10),v,e[2],1548603684,11),h=s(h=r(h,10),m=s(m,v=s(v,b,d,h,m,e[15],1836072691,9),b,d=r(d,10),h,e[5],1836072691,7),v,b=r(b,10),d,e[1],1836072691,15),v=s(v=r(v,10),b=s(b,d=s(d,h,m,v,b,e[3],1836072691,11),h,m=r(m,10),v,e[7],1836072691,8),d,h=r(h,10),m,e[14],1836072691,6),d=s(d=r(d,10),h=s(h,m=s(m,v,b,d,h,e[6],1836072691,6),v,b=r(b,10),d,e[9],1836072691,14),m,v=r(v,10),b,e[11],1836072691,12),m=s(m=r(m,10),v=s(v,b=s(b,d,h,m,v,e[8],1836072691,13),d,h=r(h,10),m,e[12],1836072691,5),b,d=r(d,10),h,e[2],1836072691,14),b=s(b=r(b,10),d=s(d,h=s(h,m,v,b,d,e[10],1836072691,13),m,v=r(v,10),b,e[0],1836072691,13),h,m=r(m,10),v,e[4],1836072691,7),h=a(h=r(h,10),m=a(m,v=s(v,b,d,h,m,e[13],1836072691,5),b,d=r(d,10),h,e[8],2053994217,15),v,b=r(b,10),d,e[6],2053994217,5),v=a(v=r(v,10),b=a(b,d=a(d,h,m,v,b,e[4],2053994217,8),h,m=r(m,10),v,e[1],2053994217,11),d,h=r(h,10),m,e[3],2053994217,14),d=a(d=r(d,10),h=a(h,m=a(m,v,b,d,h,e[11],2053994217,14),v,b=r(b,10),d,e[15],2053994217,6),m,v=r(v,10),b,e[0],2053994217,14),m=a(m=r(m,10),v=a(v,b=a(b,d,h,m,v,e[5],2053994217,6),d,h=r(h,10),m,e[12],2053994217,9),b,d=r(d,10),h,e[2],2053994217,12),b=a(b=r(b,10),d=a(d,h=a(h,m,v,b,d,e[13],2053994217,9),m,v=r(v,10),b,e[9],2053994217,12),h,m=r(m,10),v,e[7],2053994217,5),h=o(h=r(h,10),m=a(m,v=a(v,b,d,h,m,e[10],2053994217,15),b,d=r(d,10),h,e[14],2053994217,8),v,b=r(b,10),d,e[12],0,8),v=o(v=r(v,10),b=o(b,d=o(d,h,m,v,b,e[15],0,5),h,m=r(m,10),v,e[10],0,12),d,h=r(h,10),m,e[4],0,9),d=o(d=r(d,10),h=o(h,m=o(m,v,b,d,h,e[1],0,12),v,b=r(b,10),d,e[5],0,5),m,v=r(v,10),b,e[8],0,14),m=o(m=r(m,10),v=o(v,b=o(b,d,h,m,v,e[7],0,6),d,h=r(h,10),m,e[6],0,8),b,d=r(d,10),h,e[2],0,13),b=o(b=r(b,10),d=o(d,h=o(h,m,v,b,d,e[13],0,6),m,v=r(v,10),b,e[14],0,5),h,m=r(m,10),v,e[0],0,15),h=o(h=r(h,10),m=o(m,v=o(v,b,d,h,m,e[3],0,13),b,d=r(d,10),h,e[9],0,11),v,b=r(b,10),d,e[11],0,11),v=r(v,10);var y=this._b+l+v|0;this._b=this._c+f+b|0,this._c=this._d+p+d|0,this._d=this._e+n+h|0,this._e=this._a+i+m|0,this._a=y},i.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var e=new n(20);return e.writeInt32LE(this._a,0),e.writeInt32LE(this._b,4),e.writeInt32LE(this._c,8),e.writeInt32LE(this._d,12),e.writeInt32LE(this._e,16),e},t.exports=i}).call(this,e("buffer").Buffer)},{buffer:47,"hash-base":85,inherits:101}],144:[function(e,t,n){function i(e,t){for(var n in e)t[n]=e[n]}function r(e,t,n){return a(e,t,n)}var o=e("buffer"),a=o.Buffer;a.from&&a.alloc&&a.allocUnsafe&&a.allocUnsafeSlow?t.exports=o:(i(o,n),n.Buffer=r),i(a,r),r.from=function(e,t,n){if("number"==typeof e)throw new TypeError("Argument must not be a number");return a(e,t,n)},r.alloc=function(e,t,n){if("number"!=typeof e)throw new TypeError("Argument must be a number");var i=a(e);return void 0!==t?"string"==typeof n?i.fill(t,n):i.fill(t):i.fill(0),i},r.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return a(e)},r.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return o.SlowBuffer(e)}},{buffer:47}],145:[function(e,t,n){t.exports=e("scryptsy")},{scryptsy:146}],146:[function(e,t,n){(function(n){function i(e,t,i,r,o){if(n.isBuffer(e)&&n.isBuffer(i))e.copy(i,r,t,t+o);else for(;o--;)i[r++]=e[t++]}var r=e("pbkdf2").pbkdf2Sync,o=2147483647;t.exports=function(e,t,a,s,c,u,l){function f(e,t,n,r){var o;for(i(e,t+64*(2*r-1),_,0,64),o=0;o<2*r;o++)h(e,64*o,_,0,64),d(_),i(_,0,e,n+64*o,64);for(o=0;o>>32-t}function d(e){var t;for(t=0;t<16;t++)y[t]=(255&e[4*t+0])<<0,y[t]|=(255&e[4*t+1])<<8,y[t]|=(255&e[4*t+2])<<16,y[t]|=(255&e[4*t+3])<<24;for(i(y,0,g,0,16),t=8;t>0;t-=2)g[4]^=p(g[0]+g[12],7),g[8]^=p(g[4]+g[0],9),g[12]^=p(g[8]+g[4],13),g[0]^=p(g[12]+g[8],18),g[9]^=p(g[5]+g[1],7),g[13]^=p(g[9]+g[5],9),g[1]^=p(g[13]+g[9],13),g[5]^=p(g[1]+g[13],18),g[14]^=p(g[10]+g[6],7),g[2]^=p(g[14]+g[10],9),g[6]^=p(g[2]+g[14],13),g[10]^=p(g[6]+g[2],18),g[3]^=p(g[15]+g[11],7),g[7]^=p(g[3]+g[15],9),g[11]^=p(g[7]+g[3],13),g[15]^=p(g[11]+g[7],18),g[1]^=p(g[0]+g[3],7),g[2]^=p(g[1]+g[0],9),g[3]^=p(g[2]+g[1],13),g[0]^=p(g[3]+g[2],18),g[6]^=p(g[5]+g[4],7),g[7]^=p(g[6]+g[5],9),g[4]^=p(g[7]+g[6],13),g[5]^=p(g[4]+g[7],18),g[11]^=p(g[10]+g[9],7),g[8]^=p(g[11]+g[10],9),g[9]^=p(g[8]+g[11],13),g[10]^=p(g[9]+g[8],18),g[12]^=p(g[15]+g[14],7),g[13]^=p(g[12]+g[15],9),g[14]^=p(g[13]+g[12],13),g[15]^=p(g[14]+g[13],18);for(t=0;t<16;++t)y[t]=g[t]+y[t];for(t=0;t<16;t++){var n=4*t;e[n+0]=y[t]>>0&255,e[n+1]=y[t]>>8&255,e[n+2]=y[t]>>16&255,e[n+3]=y[t]>>24&255}}function h(e,t,n,i,r){for(var o=0;o 0 and a power of 2");if(a>o/128/s)throw Error("Parameter N is too large");if(s>o/128/c)throw Error("Parameter r is too large");var m,v=new n(256*s),b=new n(128*s*a),y=new Int32Array(16),g=new Int32Array(16),_=new n(64),x=r(e,t,1,128*c*s,"sha256");if(l){var w=c*a*2,k=0;m=function(){++k%1e3==0&&l({current:k,total:w,percent:k/w*100})}}for(var j=0;j=this._finalSize&&(this._update(this._block),this._block.fill(0));var n=8*this._len;if(n<=4294967295)this._block.writeUInt32BE(n,this._blockSize-4);else{var i=4294967295&n,r=(n-i)/4294967296;this._block.writeUInt32BE(r,this._blockSize-8),this._block.writeUInt32BE(i,this._blockSize-4)}this._update(this._block);var o=this._hash();return e?o.toString(e):o},i.prototype._update=function(){throw new Error("_update must be implemented by subclass")},t.exports=i},{"safe-buffer":144}],148:[function(e,t,n){(n=t.exports=function(e){e=e.toLowerCase();var t=n[e];if(!t)throw new Error(e+" is not supported (we accept pull requests)");return new t}).sha=e("./sha"),n.sha1=e("./sha1"),n.sha224=e("./sha224"),n.sha256=e("./sha256"),n.sha384=e("./sha384"),n.sha512=e("./sha512")},{"./sha":149,"./sha1":150,"./sha224":151,"./sha256":152,"./sha384":153,"./sha512":154}],149:[function(e,t,n){function i(){this.init(),this._w=f,c.call(this,64,56)}function r(e){return e<<5|e>>>27}function o(e){return e<<30|e>>>2}function a(e,t,n,i){return 0===e?t&n|~t&i:2===e?t&n|t&i|n&i:t^n^i}var s=e("inherits"),c=e("./hash"),u=e("safe-buffer").Buffer,l=[1518500249,1859775393,-1894007588,-899497514],f=new Array(80);s(i,c),i.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},i.prototype._update=function(e){for(var t=this._w,n=0|this._a,i=0|this._b,s=0|this._c,c=0|this._d,u=0|this._e,f=0;f<16;++f)t[f]=e.readInt32BE(4*f);for(;f<80;++f)t[f]=t[f-3]^t[f-8]^t[f-14]^t[f-16];for(var p=0;p<80;++p){var d=~~(p/20),h=r(n)+a(d,i,s,c)+u+t[p]+l[d]|0;u=c,c=s,s=o(i),i=n,n=h}this._a=n+this._a|0,this._b=i+this._b|0,this._c=s+this._c|0,this._d=c+this._d|0,this._e=u+this._e|0},i.prototype._hash=function(){var e=u.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e},t.exports=i},{"./hash":147,inherits:101,"safe-buffer":144}],150:[function(e,t,n){function i(){this.init(),this._w=p,u.call(this,64,56)}function r(e){return e<<1|e>>>31}function o(e){return e<<5|e>>>27}function a(e){return e<<30|e>>>2}function s(e,t,n,i){return 0===e?t&n|~t&i:2===e?t&n|t&i|n&i:t^n^i}var c=e("inherits"),u=e("./hash"),l=e("safe-buffer").Buffer,f=[1518500249,1859775393,-1894007588,-899497514],p=new Array(80);c(i,u),i.prototype.init=function(){return this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520,this},i.prototype._update=function(e){for(var t=this._w,n=0|this._a,i=0|this._b,c=0|this._c,u=0|this._d,l=0|this._e,p=0;p<16;++p)t[p]=e.readInt32BE(4*p);for(;p<80;++p)t[p]=r(t[p-3]^t[p-8]^t[p-14]^t[p-16]);for(var d=0;d<80;++d){var h=~~(d/20),m=o(n)+s(h,i,c,u)+l+t[d]+f[h]|0;l=u,u=c,c=a(i),i=n,n=m}this._a=n+this._a|0,this._b=i+this._b|0,this._c=c+this._c|0,this._d=u+this._d|0,this._e=l+this._e|0},i.prototype._hash=function(){var e=l.allocUnsafe(20);return e.writeInt32BE(0|this._a,0),e.writeInt32BE(0|this._b,4),e.writeInt32BE(0|this._c,8),e.writeInt32BE(0|this._d,12),e.writeInt32BE(0|this._e,16),e},t.exports=i},{"./hash":147,inherits:101,"safe-buffer":144}],151:[function(e,t,n){function i(){this.init(),this._w=c,a.call(this,64,56)}var r=e("inherits"),o=e("./sha256"),a=e("./hash"),s=e("safe-buffer").Buffer,c=new Array(64);r(i,o),i.prototype.init=function(){return this._a=3238371032,this._b=914150663,this._c=812702999,this._d=4144912697,this._e=4290775857,this._f=1750603025,this._g=1694076839,this._h=3204075428,this},i.prototype._hash=function(){var e=s.allocUnsafe(28);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e},t.exports=i},{"./hash":147,"./sha256":152,inherits:101,"safe-buffer":144}],152:[function(e,t,n){function i(){this.init(),this._w=h,f.call(this,64,56)}function r(e,t,n){return n^e&(t^n)}function o(e,t,n){return e&t|n&(e|t)}function a(e){return(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10)}function s(e){return(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7)}function c(e){return(e>>>7|e<<25)^(e>>>18|e<<14)^e>>>3}function u(e){return(e>>>17|e<<15)^(e>>>19|e<<13)^e>>>10}var l=e("inherits"),f=e("./hash"),p=e("safe-buffer").Buffer,d=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],h=new Array(64);l(i,f),i.prototype.init=function(){return this._a=1779033703,this._b=3144134277,this._c=1013904242,this._d=2773480762,this._e=1359893119,this._f=2600822924,this._g=528734635,this._h=1541459225,this},i.prototype._update=function(e){for(var t=this._w,n=0|this._a,i=0|this._b,l=0|this._c,f=0|this._d,p=0|this._e,h=0|this._f,m=0|this._g,v=0|this._h,b=0;b<16;++b)t[b]=e.readInt32BE(4*b);for(;b<64;++b)t[b]=u(t[b-2])+t[b-7]+c(t[b-15])+t[b-16]|0;for(var y=0;y<64;++y){var g=v+s(p)+r(p,h,m)+d[y]+t[y]|0,_=a(n)+o(n,i,l)|0;v=m,m=h,h=p,p=f+g|0,f=l,l=i,i=n,n=g+_|0}this._a=n+this._a|0,this._b=i+this._b|0,this._c=l+this._c|0,this._d=f+this._d|0,this._e=p+this._e|0,this._f=h+this._f|0,this._g=m+this._g|0,this._h=v+this._h|0},i.prototype._hash=function(){var e=p.allocUnsafe(32);return e.writeInt32BE(this._a,0),e.writeInt32BE(this._b,4),e.writeInt32BE(this._c,8),e.writeInt32BE(this._d,12),e.writeInt32BE(this._e,16),e.writeInt32BE(this._f,20),e.writeInt32BE(this._g,24),e.writeInt32BE(this._h,28),e},t.exports=i},{"./hash":147,inherits:101,"safe-buffer":144}],153:[function(e,t,n){function i(){this.init(),this._w=c,a.call(this,128,112)}var r=e("inherits"),o=e("./sha512"),a=e("./hash"),s=e("safe-buffer").Buffer,c=new Array(160);r(i,o),i.prototype.init=function(){return this._ah=3418070365,this._bh=1654270250,this._ch=2438529370,this._dh=355462360,this._eh=1731405415,this._fh=2394180231,this._gh=3675008525,this._hh=1203062813,this._al=3238371032,this._bl=914150663,this._cl=812702999,this._dl=4144912697,this._el=4290775857,this._fl=1750603025,this._gl=1694076839,this._hl=3204075428,this},i.prototype._hash=function(){function e(e,n,i){t.writeInt32BE(e,i),t.writeInt32BE(n,i+4)}var t=s.allocUnsafe(48);return e(this._ah,this._al,0),e(this._bh,this._bl,8),e(this._ch,this._cl,16),e(this._dh,this._dl,24),e(this._eh,this._el,32),e(this._fh,this._fl,40),t},t.exports=i},{"./hash":147,"./sha512":154,inherits:101,"safe-buffer":144}],154:[function(e,t,n){function i(){this.init(),this._w=b,h.call(this,128,112)}function r(e,t,n){return n^e&(t^n)}function o(e,t,n){return e&t|n&(e|t)}function a(e,t){return(e>>>28|t<<4)^(t>>>2|e<<30)^(t>>>7|e<<25)}function s(e,t){return(e>>>14|t<<18)^(e>>>18|t<<14)^(t>>>9|e<<23)}function c(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^e>>>7}function u(e,t){return(e>>>1|t<<31)^(e>>>8|t<<24)^(e>>>7|t<<25)}function l(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^e>>>6}function f(e,t){return(e>>>19|t<<13)^(t>>>29|e<<3)^(e>>>6|t<<26)}function p(e,t){return e>>>0>>0?1:0}var d=e("inherits"),h=e("./hash"),m=e("safe-buffer").Buffer,v=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],b=new Array(160);d(i,h),i.prototype.init=function(){return this._ah=1779033703,this._bh=3144134277,this._ch=1013904242,this._dh=2773480762,this._eh=1359893119,this._fh=2600822924,this._gh=528734635,this._hh=1541459225,this._al=4089235720,this._bl=2227873595,this._cl=4271175723,this._dl=1595750129,this._el=2917565137,this._fl=725511199,this._gl=4215389547,this._hl=327033209,this},i.prototype._update=function(e){for(var t=this._w,n=0|this._ah,i=0|this._bh,d=0|this._ch,h=0|this._dh,m=0|this._eh,b=0|this._fh,y=0|this._gh,g=0|this._hh,_=0|this._al,x=0|this._bl,w=0|this._cl,k=0|this._dl,j=0|this._el,S=0|this._fl,E=0|this._gl,A=0|this._hl,C=0;C<32;C+=2)t[C]=e.readInt32BE(4*C),t[C+1]=e.readInt32BE(4*C+4);for(;C<160;C+=2){var M=t[C-30],T=t[C-30+1],P=c(M,T),F=u(T,M),I=l(M=t[C-4],T=t[C-4+1]),B=f(T,M),R=t[C-14],O=t[C-14+1],N=t[C-32],D=t[C-32+1],L=F+O|0,q=P+R+p(L,F)|0;q=(q=q+I+p(L=L+B|0,B)|0)+N+p(L=L+D|0,D)|0,t[C]=q,t[C+1]=L}for(var z=0;z<160;z+=2){q=t[z],L=t[z+1];var U=o(n,i,d),H=o(_,x,w),V=a(n,_),K=a(_,n),W=s(m,j),X=s(j,m),G=v[z],$=v[z+1],J=r(m,b,y),Q=r(j,S,E),Y=A+X|0,Z=g+W+p(Y,A)|0;Z=(Z=(Z=Z+J+p(Y=Y+Q|0,Q)|0)+G+p(Y=Y+$|0,$)|0)+q+p(Y=Y+L|0,L)|0;var ee=K+H|0,te=V+U+p(ee,K)|0;g=y,A=E,y=b,E=S,b=m,S=j,m=h+Z+p(j=k+Y|0,k)|0,h=d,k=w,d=i,w=x,i=n,x=_,n=Z+te+p(_=Y+ee|0,Y)|0}this._al=this._al+_|0,this._bl=this._bl+x|0,this._cl=this._cl+w|0,this._dl=this._dl+k|0,this._el=this._el+j|0,this._fl=this._fl+S|0,this._gl=this._gl+E|0,this._hl=this._hl+A|0,this._ah=this._ah+n+p(this._al,_)|0,this._bh=this._bh+i+p(this._bl,x)|0,this._ch=this._ch+d+p(this._cl,w)|0,this._dh=this._dh+h+p(this._dl,k)|0,this._eh=this._eh+m+p(this._el,j)|0,this._fh=this._fh+b+p(this._fl,S)|0,this._gh=this._gh+y+p(this._gl,E)|0,this._hh=this._hh+g+p(this._hl,A)|0},i.prototype._hash=function(){function e(e,n,i){t.writeInt32BE(e,i),t.writeInt32BE(n,i+4)}var t=m.allocUnsafe(64);return e(this._ah,this._al,0),e(this._bh,this._bl,8),e(this._ch,this._cl,16),e(this._dh,this._dl,24),e(this._eh,this._el,32),e(this._fh,this._fl,40),e(this._gh,this._gl,48),e(this._hh,this._hl,56),t},t.exports=i},{"./hash":147,inherits:101,"safe-buffer":144}],155:[function(e,t,n){function i(){r.call(this)}t.exports=i;var r=e("events").EventEmitter;e("inherits")(i,r),i.Readable=e("readable-stream/readable.js"),i.Writable=e("readable-stream/writable.js"),i.Duplex=e("readable-stream/duplex.js"),i.Transform=e("readable-stream/transform.js"),i.PassThrough=e("readable-stream/passthrough.js"),i.Stream=i,i.prototype.pipe=function(e,t){function n(t){e.writable&&!1===e.write(t)&&u.pause&&u.pause()}function i(){u.readable&&u.resume&&u.resume()}function o(){l||(l=!0,e.end())}function a(){l||(l=!0,"function"==typeof e.destroy&&e.destroy())}function s(e){if(c(),0===r.listenerCount(this,"error"))throw e}function c(){u.removeListener("data",n),e.removeListener("drain",i),u.removeListener("end",o),u.removeListener("close",a),u.removeListener("error",s),e.removeListener("error",s),u.removeListener("end",c),u.removeListener("close",c),e.removeListener("close",c)}var u=this;u.on("data",n),e.on("drain",i),e._isStdio||t&&!1===t.end||(u.on("end",o),u.on("close",a));var l=!1;return u.on("error",s),e.on("error",s),u.on("end",c),u.on("close",c),e.on("close",c),e.emit("pipe",u),e}},{events:83,inherits:101,"readable-stream/duplex.js":128,"readable-stream/passthrough.js":139,"readable-stream/readable.js":140,"readable-stream/transform.js":141,"readable-stream/writable.js":142}],156:[function(e,t,n){(function(e){function n(t){try{if(!e.localStorage)return!1}catch(e){return!1}var n=e.localStorage[t];return null!=n&&"true"===String(n).toLowerCase()}t.exports=function(e,t){if(n("noDeprecation"))return e;var i=!1;return function(){if(!i){if(n("throwDeprecation"))throw new Error(t);n("traceDeprecation")?console.trace(t):console.warn(t),i=!0}return e.apply(this,arguments)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],157:[function(require,module,exports){function Context(){}var indexOf=require("indexof"),Object_keys=function(e){if(Object.keys)return Object.keys(e);var t=[];for(var n in e)t.push(n);return t},forEach=function(e,t){if(e.forEach)return e.forEach(t);for(var n=0;nl||u===l&&"application/"===t[c].substr(0,12)))continue}t[c]=i}}})}(n.extensions,n.types)},{"mime-db":162,path:113}],164:[function(e,t,n){var i=e("trim"),r=e("for-each"),o=function(e){return"[object Array]"===Object.prototype.toString.call(e)};t.exports=function(e){if(!e)return{};var t={};return r(i(e).split("\n"),function(e){var n=e.indexOf(":"),r=i(e.slice(0,n)).toLowerCase(),a=i(e.slice(n+1));void 0===t[r]?t[r]=a:o(t[r])?t[r].push(a):t[r]=[t[r],a]}),t}},{"for-each":158,trim:171}],165:[function(e,t,n){var i=e("strict-uri-encode");n.extract=function(e){return e.split("?")[1]||""},n.parse=function(e){return"string"!=typeof e?{}:(e=e.trim().replace(/^(\?|#|&)/,""))?e.split("&").reduce(function(e,t){var n=t.replace(/\+/g," ").split("="),i=n.shift(),r=n.length>0?n.join("="):void 0;return i=decodeURIComponent(i),r=void 0===r?null:decodeURIComponent(r),e.hasOwnProperty(i)?Array.isArray(e[i])?e[i].push(r):e[i]=[e[i],r]:e[i]=r,e},{}):{}},n.stringify=function(e){return e?Object.keys(e).sort().map(function(t){var n=e[t];return Array.isArray(n)?n.sort().map(function(e){return i(t)+"="+i(e)}).join("&"):i(t)+"="+i(n)}).filter(function(e){return e.length>0}).join("&"):""}},{"strict-uri-encode":166}],166:[function(e,t,n){t.exports=function(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}},{}],167:[function(e,t,n){t.exports={"windows-amd64":{archive:"swarm-windows-amd64-1.6.7.exe",binaryMD5:"c2d827dc4553d9b91a7d6c1d5a6140fd",archiveMD5:"059196d21548060a18a12e17cc0ee59a"},"linux-amd64":{archive:"swarm-linux-amd64-1.6.7",binaryMD5:"85002d79b8ebc2d2f2f10fb198636a81",archiveMD5:"3e8874299ab8c0e3043d70ebb6673879"},"linux-386":{archive:"swarm-linux-386-1.6.7",binaryMD5:"35bc2ab976f60f96a2cede117e0df19d",archiveMD5:"7868a86c9cbdf8ac7ac2e5682b4ce40f"},"darwin-amd64":{archive:"swarm-darwin-amd64-1.6.7",binaryMD5:"c499b186645229260dd6ab685dd58f07",archiveMD5:"0794d111e5018eac3b657bcb29851121"},"linux-arm5":{archive:"swarm-linux-arm5-1.6.7",binaryMD5:"516fcd85246c905529442cd9b689c12f",archiveMD5:"47312708d417cb196b07ba0af1d3abb4"},"linux-arm6":{archive:"swarm-linux-arm6-1.6.7",binaryMD5:"82ff7bdbe388b4a190f4101c5150d3b4",archiveMD5:"350276de7bb175a15c314cfc4cb7f8fd"},"linux-mips":{archive:"swarm-linux-mips-1.6.7",binaryMD5:"e1e95280441c0ca35633927792ef5317",archiveMD5:"8fb4b64e94cd73aa718db787b9d4c53e"},"linux-arm7":{archive:"swarm-linux-arm7-1.6.7",binaryMD5:"bfc0b4d1c86d8a975af052fc7854bdd3",archiveMD5:"4378641d8e1e1fbb947f941c8fca8613"},"linux-arm64":{archive:"swarm-linux-arm64-1.6.7",binaryMD5:"bbac21a6c6fa8208f67ca4123d3f948a",archiveMD5:"4e503160327c5fbcca0414f17c54e5ee"},"linux-mipsle":{archive:"swarm-linux-mipsle-1.6.7",binaryMD5:"a82f191b2f9d2c470d0273219c820657",archiveMD5:"3016bdb6d237ae654c0cdf36fe85dc7c"},"windows-386":{archive:"swarm-windows-386-1.6.7.exe",binaryMD5:"ce0b34640642e58068ae5a359faef102",archiveMD5:"640aede4da08a3a9d8a6ac0434ba7c0f"},"linux-mips64":{archive:"swarm-linux-mips64-1.6.7",binaryMD5:"9da967664f384817adb5083fd1ffe8f1",archiveMD5:"357a33be470f8f89ba2619957a08deff"},"linux-mips64le":{archive:"swarm-linux-mips64le-1.6.7",binaryMD5:"ec1abcf7b216e87645ec83954d8344cd",archiveMD5:"a81fd0158190d99813c738ffa4f87627"}}},{}],168:[function(e,t,n){var i=function(){throw"This swarm.js function isn't available on the browser."},r={readFile:i},o={download:i,safeDownloadArchived:i,directoryTree:i},a={platform:i,arch:i},s={join:i,slice:i},c={spawn:i},u=e("./swarm");t.exports=u({fsp:r,files:o,os:a,path:s,child_process:c})},{"./swarm":170}],169:[function(e,t,n){(function(e){var n=function(t){return function(){return new Promise(function(n,i){var r=function(i){var r={},o=i.target.files.length,a=0;[].map.call(i.target.files,function(i){var s=new FileReader;s.onload=function(s){var c=new e(s.target.result);if("directory"===t){var u=i.webkitRelativePath;r[u.slice(u.indexOf("/")+1)]={type:"text/plain",data:c},++a===o&&n(r)}else if("file"===t){var l=i.webkitRelativePath;n({type:mimetype.lookup(l),data:c})}else n(c)},s.readAsArrayBuffer(i)})},o=void 0;"directory"===t?((o=document.createElement("input")).addEventListener("change",r),o.type="file",o.webkitdirectory=!0,o.mozdirectory=!0,o.msdirectory=!0,o.odirectory=!0,o.directory=!0):((o=document.createElement("input")).addEventListener("change",r),o.type="file");var a=document.createEvent("MouseEvents");a.initEvent("click",!0,!1),o.dispatchEvent(a)})}};t.exports={data:n("data"),file:n("file"),directory:n("directory")}}).call(this,e("buffer").Buffer)},{buffer:47}],170:[function(e,t,n){var i=e("mime-types"),r=e("./pick.js"),o=e("xhr-request-promise"),a=e("./../archives/archives.json"),s=e("buffer").Buffer;t.exports=function(e){var t=e.fsp,n=e.files,c=e.os,u=e.path,l=e.child_process,f=function(e){return function(t){return function(n){return n[e]=t,n}}},p=function(e){return function(t){for(var n={},i=0,r=e.length;i0){var o=u.join(n,r);i.push(g(e)(t[r])(o))}return Promise.all(i).then(function(){return n})})}}},x=function(e){return function(t){return o(e+"/bzzr:/",{body:"string"==typeof t?new s(t):t,method:"POST"})}},w=function(e){return function(t){return function(n){return function(i){return function r(a){var s="/"===n[0]?n:"/"+n,c=e+"/bzz:/"+t+s,u={method:"PUT",headers:{"Content-Type":i.type},body:i.data};return o(c,u).catch(function(e){return a>0&&r(a-1)})}(3)}}}},k=function(e){return function(t){return S(e)({"":t})}},j=function(e){return function(n){return t.readFile(n).then(function(t){return k(e)({type:i.lookup(n),data:t})})}},S=function(e){return function(t){return x(e)("{}").then(function(n){var i=function(n){return function(i){return w(e)(i)(n)(t[n])}};return Object.keys(t).reduce(function(e,t){return e.then(i(t))},Promise.resolve(n))})}},E=function(e){return function(n){return t.readFile(n).then(x(e))}},A=function(e){return function(r){return function(o){return n.directoryTree(o).then(function(e){return Promise.all(e.map(function(e){return t.readFile(e)})).then(function(t){var n=e.map(function(e){return e.slice(o.length)}),r=e.map(function(e){return i.lookup(e)||"text/plain"});return p(n)(t.map(function(e,t){return{type:r[t],data:e}}))})}).then(function(e){return d(r?{"":e[r]}:{})(e)}).then(S(e))}}},C=function(e){return function(t){if("data"===t.pick)return r.data().then(x(e));if("file"===t.pick)return r.file().then(k(e));if("directory"===t.pick)return r.directory().then(S(e));if(t.path)switch(t.kind){case"data":return E(e)(t.path);case"file":return j(e)(t.path);case"directory":return A(e)(t.defaultFile)(t.path)}else{if("string"==typeof t)return x(e)(new s(t));if(t.length)return x(e)(t);if(t instanceof Object)return S(e)(t)}return Promise.reject(new Error("Bad arguments"))}},M=function(e){return function(t){return function(n){return B(e)(t).then(function(i){return i?n?_(e)(t)(n):y(e)(t):n?g(e)(t)(n):m(e)(t)})}}},T=function(e,t){var i=c.platform().replace("win32","windows")+"-"+("x64"===c.arch()?"amd64":"386"),r=(t||a)[i],o="http://ethereum-mist.s3.amazonaws.com/swarm/"+r.archive+".tar.gz",s=r.archiveMD5,u=r.binaryMD5;return n.safeDownloadArchived(o)(s)(u)(e)},P=function(e){return new Promise(function(t,n){var i=l.spawn,r=function(e){return function(t){return-1!==(""+t).indexOf(e)}},o=e.account,a=e.password,s=e.dataDir,c=e.ensApi,u=e.privateKey,f=0,p=i(e.binPath,["--bzzaccount",o||u,"--datadir",s,"--ens-api",c]),d=function(e){0===f&&r("Passphrase")(e)?setTimeout(function(){f=1,p.stdin.write(a+"\n")},500):r("Swarm http proxy started")(e)&&(f=2,clearTimeout(h),t(p))};p.stdout.on("data",d),p.stderr.on("data",d);var h=setTimeout(function(){return n(new Error("Couldn't start swarm process."))},2e4)})},F=function(e){return new Promise(function(t,n){e.stderr.removeAllListeners("data"),e.stdout.removeAllListeners("data"),e.stdin.removeAllListeners("error"),e.removeAllListeners("error"),e.removeAllListeners("exit"),e.kill("SIGINT");var i=setTimeout(function(){return e.kill("SIGKILL")},8e3);e.once("close",function(){clearTimeout(i),t()})})},I=function(e){return x(e)("test").then(function(e){return"c9a99c7d326dcc6316f32fe2625b311f6dc49a175e6877681ded93137d3569e7"===e}).catch(function(){return!1})},B=function(e){return function(t){return m(e)(t).then(function(e){return!!JSON.parse(e.toString()).entries}).catch(function(){return!1})}},R=function(e){return function(t,n,i,r,o){return void 0!==t&&(e=e(t)),void 0!==n&&(e=e(n)),void 0!==i&&(e=e(i)),void 0!==r&&(e=e(r)),void 0!==o&&(e=e(o)),e}},O=function(e){return{download:function(t,n){return M(e)(t)(n)},downloadData:R(m(e)),downloadDataToDisk:R(g(e)),downloadDirectory:R(y(e)),downloadDirectoryToDisk:R(_(e)),downloadEntries:R(v(e)),downloadRoutes:R(b(e)),isAvailable:function(){return I(e)},upload:function(t){return C(e)(t)},uploadData:R(x(e)),uploadFile:R(k(e)),uploadFileFromDisk:R(k(e)),uploadDataFromDisk:R(E(e)),uploadDirectory:R(S(e)),uploadDirectoryFromDisk:R(A(e)),uploadToManifest:R(w(e)),pick:r}};return{at:O,local:function(e){return function(t){return I("http://localhost:8500").then(function(n){return n?t(O("http://localhost:8500")).then(function(){}):T(e.binPath,e.archives).onData(function(t){return(e.onProgress||function(){})(t.length)}).then(function(){return P(e)}).then(function(e){return t(O("http://localhost:8500")).then(function(){return e})}).then(F)})}},download:M,downloadBinary:T,downloadData:m,downloadDataToDisk:g,downloadDirectory:y,downloadDirectoryToDisk:_,downloadEntries:v,downloadRoutes:b,isAvailable:I,startProcess:P,stopProcess:F,upload:C,uploadData:x,uploadDataFromDisk:E,uploadFile:k,uploadFileFromDisk:j,uploadDirectory:S,uploadDirectoryFromDisk:A,uploadToManifest:w,pick:r}}},{"./../archives/archives.json":167,"./pick.js":169,buffer:47,"mime-types":163,"xhr-request-promise":174}],171:[function(e,t,n){(n=t.exports=function(e){return e.replace(/^\s*|\s*$/g,"")}).left=function(e){return e.replace(/^\s*/,"")},n.right=function(e){return e.replace(/\s*$/,"")}},{}],172:[function(e,t,n){(function(){function e(e){function t(t,n,i,r,o,a){for(;o>=0&&o0?0:s-1;return arguments.length<3&&(r=n[a?a[c]:c],c+=e),t(n,i,r,a,c,s)}}function i(e){return function(t,n,i){n=w(n,i);for(var r=A(t),o=e>0?0:r-1;o>=0&&o0?a=o>=0?o:Math.max(o+s,a):s=o>=0?Math.min(o+1,s):o+s+1;else if(n&&o&&s)return o=n(i,r),i[o]===r?o:-1;if(r!==r)return(o=t(p.call(i,a,s),_.isNaN))>=0?o+a:-1;for(o=e>0?a:s-1;o>=0&&o=0&&t<=E};_.each=_.forEach=function(e,t,n){t=x(t,n);var i,r;if(C(e))for(i=0,r=e.length;i=0},_.invoke=function(e,t){var n=p.call(arguments,2),i=_.isFunction(t);return _.map(e,function(e){var r=i?t:e[t];return null==r?r:r.apply(e,n)})},_.pluck=function(e,t){return _.map(e,_.property(t))},_.where=function(e,t){return _.filter(e,_.matcher(t))},_.findWhere=function(e,t){return _.find(e,_.matcher(t))},_.max=function(e,t,n){var i,r,o=-1/0,a=-1/0;if(null==t&&null!=e)for(var s=0,c=(e=C(e)?e:_.values(e)).length;so&&(o=i);else t=w(t,n),_.each(e,function(e,n,i){((r=t(e,n,i))>a||r===-1/0&&o===-1/0)&&(o=e,a=r)});return o},_.min=function(e,t,n){var i,r,o=1/0,a=1/0;if(null==t&&null!=e)for(var s=0,c=(e=C(e)?e:_.values(e)).length;si||void 0===n)return 1;if(nt?(a&&(clearTimeout(a),a=null),s=u,o=e.apply(i,r),a||(i=r=null)):a||!1===n.trailing||(a=setTimeout(c,l)),o}},_.debounce=function(e,t,n){var i,r,o,a,s,c=function c(){var u=_.now()-a;u=0?i=setTimeout(c,t-u):(i=null,n||(s=e.apply(o,r),i||(o=r=null)))};return function(){o=this,r=arguments,a=_.now();var u=n&&!i;return i||(i=setTimeout(c,t)),u&&(s=e.apply(o,r),o=r=null),s}},_.wrap=function(e,t){return _.partial(t,e)},_.negate=function(e){return function(){return!e.apply(this,arguments)}},_.compose=function(){var e=arguments,t=e.length-1;return function(){for(var n=t,i=e[t].apply(this,arguments);n--;)i=e[n].call(this,i);return i}},_.after=function(e,t){return function(){if(--e<1)return t.apply(this,arguments)}},_.before=function(e,t){var n;return function(){return--e>0&&(n=t.apply(this,arguments)),e<=1&&(t=null),n}},_.once=_.partial(_.before,2);var F=!{toString:null}.propertyIsEnumerable("toString"),I=["valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"];_.keys=function(e){if(!_.isObject(e))return[];if(v)return v(e);var t=[];for(var n in e)_.has(e,n)&&t.push(n);return F&&o(e,t),t},_.allKeys=function(e){if(!_.isObject(e))return[];var t=[];for(var n in e)t.push(n);return F&&o(e,t),t},_.values=function(e){for(var t=_.keys(e),n=t.length,i=Array(n),r=0;r":">",'"':""","'":"'","`":"`"},O=_.invert(R),N=function(e){var t=function(t){return e[t]},n="(?:"+_.keys(e).join("|")+")",i=RegExp(n),r=RegExp(n,"g");return function(e){return e=null==e?"":""+e,i.test(e)?e.replace(r,t):e}};_.escape=N(R),_.unescape=N(O),_.result=function(e,t,n){var i=null==e?void 0:e[t];return void 0===i&&(i=n),_.isFunction(i)?i.call(e):i};var D=0;_.uniqueId=function(e){var t=++D+"";return e?e+t:t},_.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var L=/(.)^/,q={"'":"'","\\":"\\","\r":"r","\n":"n","\u2028":"u2028","\u2029":"u2029"},z=/\\|'|\r|\n|\u2028|\u2029/g,U=function(e){return"\\"+q[e]};_.template=function(e,t,n){!t&&n&&(t=n),t=_.defaults({},t,_.templateSettings);var i=RegExp([(t.escape||L).source,(t.interpolate||L).source,(t.evaluate||L).source].join("|")+"|$","g"),r=0,o="__p+='";e.replace(i,function(t,n,i,a,s){return o+=e.slice(r,s).replace(z,U),r=s+t.length,n?o+="'+\n((__t=("+n+"))==null?'':_.escape(__t))+\n'":i?o+="'+\n((__t=("+i+"))==null?'':__t)+\n'":a&&(o+="';\n"+a+"\n__p+='"),t}),o+="';\n",t.variable||(o="with(obj||{}){\n"+o+"}\n"),o="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+o+"return __p;\n";try{var a=new Function(t.variable||"obj","_",o)}catch(e){throw e.source=o,e}var s=function(e){return a.call(this,e,_)},c=t.variable||"obj";return s.source="function("+c+"){\n"+o+"}",s},_.chain=function(e){var t=_(e);return t._chain=!0,t};var H=function(e,t){return e._chain?_(t).chain():t};_.mixin=function(e){_.each(_.functions(e),function(t){var n=_[t]=e[t];_.prototype[t]=function(){var e=[this._wrapped];return f.apply(e,arguments),H(this,n.apply(_,e))}})},_.mixin(_),_.each(["pop","push","reverse","shift","sort","splice","unshift"],function(e){var t=c[e];_.prototype[e]=function(){var n=this._wrapped;return t.apply(n,arguments),"shift"!==e&&"splice"!==e||0!==n.length||delete n[0],H(this,n)}}),_.each(["concat","join","slice"],function(e){var t=c[e];_.prototype[e]=function(){return H(this,t.apply(this._wrapped,arguments))}}),_.prototype.value=function(){return this._wrapped},_.prototype.valueOf=_.prototype.toJSON=_.prototype.value,_.prototype.toString=function(){return""+this._wrapped},"function"==typeof define&&define.amd&&define("underscore",[],function(){return _})}).call(this)},{}],173:[function(e,t,n){t.exports=function(e,t){if(t){t=(t=t.trim().replace(/^(\?|#|&)/,""))?"?"+t:t;var n=e.split(/[\?\#]/)[0];t&&/\:\/\/[^\/]*$/.test(n)&&(n+="/");var i=e.match(/(\#.*)$/);e=n+t,i&&(e+=i[0])}return e}},{}],174:[function(e,t,n){var i=e("xhr-request");t.exports=function(e,t){return new Promise(function(n,r){i(e,t,function(e,t){e?r(e):n(t)})})}},{"xhr-request":175}],175:[function(e,t,n){var i=e("query-string"),r=e("url-set-query"),o=e("object-assign"),a=e("./lib/ensure-header.js"),s=e("./lib/request.js"),c="application/json",u=function(){};t.exports=function(e,t,n){if(!e||"string"!=typeof e)throw new TypeError("must specify a URL");if("function"==typeof t&&(n=t,t={}),n&&"function"!=typeof n)throw new TypeError("expected cb to be undefined or a function");n=n||u;var l=(t=t||{}).json?"json":"text",f=(t=o({responseType:l},t)).headers||{},p=(t.method||"GET").toUpperCase(),d=t.query;return d&&("string"!=typeof d&&(d=i.stringify(d)),e=r(e,d)),"json"===t.responseType&&a(f,"Accept",c),t.json&&"GET"!==p&&"HEAD"!==p&&(a(f,"Content-Type",c),t.body=JSON.stringify(t.body)),t.method=p,t.url=e,t.headers=f,delete t.query,delete t.json,s(t,n)}},{"./lib/ensure-header.js":176,"./lib/request.js":178,"object-assign":179,"query-string":165,"url-set-query":173}],176:[function(e,t,n){t.exports=function(e,t,n){var i=t.toLowerCase();e[t]||e[i]||(e[t]=n)}},{}],177:[function(e,t,n){t.exports=function(e,t){return t?{statusCode:t.statusCode,headers:t.headers,method:e.method,url:e.url,rawRequest:t.rawRequest?t.rawRequest:t}:null}},{}],178:[function(e,t,n){var i=e("xhr"),r=e("./normalize-response");t.exports=function(e,t){delete e.uri;var n=!1;return"json"===e.responseType&&(e.responseType="text",n=!0),i(e,function(i,o,a){if(n&&!i)try{var s=o.rawRequest.responseText;a=JSON.parse(s)}catch(e){i=e}o=r(e,o),i?t(i,null,o):t(i,a,o)})}},{"./normalize-response":177,xhr:180}],179:[function(e,t,n){function i(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}function r(e){var t=Object.getOwnPropertyNames(e);return Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e))),t.filter(function(t){return o.call(e,t)})}var o=Object.prototype.propertyIsEnumerable;t.exports=Object.assign||function(e,t){for(var n,o,a=i(e),s=1;s0&&(d=setTimeout(function(){if(!p){p=!0,u.abort("timeout");var e=new Error("XMLHttpRequest timeout");e.code="ETIMEDOUT",n(e)}},e.timeout)),u.setRequestHeader)for(f in b)b.hasOwnProperty(f)&&u.setRequestHeader(f,b[f]);else if(e.headers&&!i(e.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in e&&(u.responseType=e.responseType),"beforeSend"in e&&"function"==typeof e.beforeSend&&e.beforeSend(u),u.send(v||null),u}function s(e){if("document"===e.responseType)return e.responseXML;var t=e.responseXML&&"parsererror"===e.responseXML.documentElement.nodeName;return""!==e.responseType||t?null:e.responseXML}var c=e("global/window"),u=e("is-function"),l=e("parse-headers"),f=e("xtend");t.exports=o,o.XMLHttpRequest=c.XMLHttpRequest||function(){},o.XDomainRequest="withCredentials"in new o.XMLHttpRequest?o.XMLHttpRequest:c.XDomainRequest,function(e,t){for(var n=0;n1?(e[n[0]]=e[n[0]]||{},e[n[0]][n[1]]=t):e[n[0]]=t},u.prototype.getCall=function(e){return i.isFunction(this.call)?this.call(e):this.call},u.prototype.extractCallback=function(e){if(i.isFunction(e[e.length-1]))return e.pop()},u.prototype.validateArgs=function(e){if(e.length!==this.params)throw r.InvalidNumberOfParams(e.length,this.params,this.name)},u.prototype.formatInput=function(e){var t=this;return this.inputFormatter?this.inputFormatter.map(function(n,i){return n?n.call(t,e[i]):e[i]}):e},u.prototype.formatOutput=function(e){var t=this;return i.isArray(e)?e.map(function(e){return t.outputFormatter&&e?t.outputFormatter(e):e}):this.outputFormatter&&e?this.outputFormatter(e):e},u.prototype.toPayload=function(e){var t=this.getCall(e),n=this.extractCallback(e),i=this.formatInput(e);this.validateArgs(i);var r={method:t,params:i,callback:n};return this.transformPayload&&(r=this.transformPayload(r)),r},u.prototype._confirmTransaction=function(e,t,n){var r=this,l=!1,f=!0,p=0,d=0,h=null,m=i.isObject(n.params[0])&&n.params[0].gas?n.params[0].gas:null,v=i.isObject(n.params[0])&&n.params[0].data&&n.params[0].from&&!n.params[0].to,b=[new u({name:"getTransactionReceipt",call:"eth_getTransactionReceipt",params:1,inputFormatter:[null],outputFormatter:o.outputTransactionReceiptFormatter}),new u({name:"getCode",call:"eth_getCode",params:2,inputFormatter:[o.inputAddressFormatter,o.inputDefaultBlockNumberFormatter]}),new c({name:"subscribe",type:"eth",subscriptions:{newBlockHeaders:{subscriptionName:"newHeads",params:0,outputFormatter:o.outputBlockFormatter}}})],y={};i.each(b,function(e){e.attachToObject(y),e.requestManager=r.requestManager});var g=function(n,i,o,c){return n?(o.unsubscribe(),l=!0,a._fireError({message:"Failed to subscribe to new newBlockHeaders to confirm the transaction receipts.",data:n},e.eventEmitter,e.reject)):(o||(o={unsubscribe:function(){clearInterval(h)}}),(c?s.resolve(c):y.getTransactionReceipt(t)).catch(function(t){o.unsubscribe(),l=!0,a._fireError({message:"Failed to check for transaction receipt:",data:t},e.eventEmitter,e.reject)}).then(function(t){if(!t||!t.blockHash)throw new Error("Receipt missing or blockHash null");return r.extraFormatters&&r.extraFormatters.receiptFormatter&&(t=r.extraFormatters.receiptFormatter(t)),e.eventEmitter.listeners("confirmation").length>0&&(e.eventEmitter.emit("confirmation",d,t),f=!1,25===++d&&(o.unsubscribe(),e.eventEmitter.removeAllListeners())),t}).then(function(t){if(v&&!l){if(!t.contractAddress)return f&&(o.unsubscribe(),l=!0),a._fireError(new Error("The transaction receipt didn't contain a contract address."),e.eventEmitter,e.reject);y.getCode(t.contractAddress,function(n,i){i&&(i.length>2?(e.eventEmitter.emit("receipt",t),r.extraFormatters&&r.extraFormatters.contractDeployFormatter?e.resolve(r.extraFormatters.contractDeployFormatter(t)):e.resolve(t),f&&e.eventEmitter.removeAllListeners()):a._fireError(new Error("The contract code couldn't be stored, please check your gas limit."),e.eventEmitter,e.reject),f&&o.unsubscribe(),l=!0)})}return t}).then(function(t){v||l||(t.outOfGas||m&&m===t.gasUsed?(t&&(t=JSON.stringify(t,null,2)),a._fireError(new Error("Transaction ran out of gas. Please provide more gas:\n"+t),e.eventEmitter,e.reject)):(e.eventEmitter.emit("receipt",t),e.resolve(t),f&&e.eventEmitter.removeAllListeners()),f&&o.unsubscribe(),l=!0)}).catch(function(){if(++p-1>=50)return o.unsubscribe(),l=!0,a._fireError(new Error("Transaction was not mined within 50 blocks, please make sure your transaction was properly send. Be aware that it might still be mined!"),e.eventEmitter,e.reject)}))},_=function(){i.isFunction(this.requestManager.provider.on)?y.subscribe("newBlockHeaders",g):h=setInterval(g,1e3)}.bind(this);y.getTransactionReceipt(t).then(function(t){if(t&&t.blockHash)return e.eventEmitter.listeners("confirmation").length>0&&setTimeout(function(){l||_()},1e3),g(null,0,null,t);l||_()}).catch(function(){l||_()})};var l=function(e,t){return i.isNumber(e)?t.wallet[e]:i.isObject(e)&&e.address&&e.privateKey?e:t.wallet[e.toLowerCase()]};u.prototype.buildCall=function(){var e=this,t="eth_sendTransaction"===e.call||"eth_sendRawTransaction"===e.call,n=function(){var n=s(!t),r=e.toPayload(Array.prototype.slice.call(arguments)),o=function(i,o){try{o=e.formatOutput(o)}catch(e){i=e}if(o instanceof Error&&(i=o),i)return i.error&&(i=i.error),a._fireError(i,n.eventEmitter,n.reject,r.callback);r.callback&&r.callback(null,o),t?(n.eventEmitter.emit("transactionHash",o),e._confirmTransaction(n,o,r)):i||n.resolve(o)},c=function(t){r.method="eth_sendRawTransaction",r.params=[t.rawTransaction],e.requestManager.send(r,o)},f=function(e,t){if(t&&t.accounts&&t.accounts.wallet&&t.accounts.wallet.length){var r;if("eth_sendTransaction"===e.method){var a=e.params[0];if((r=l(i.isObject(a)?a.from:null,t.accounts))&&r.privateKey){delete a.from;var s=t.accounts.signTransaction(a,r.privateKey);return i.isFunction(s.then)?s.then(c):c(s)}}else if("eth_sign"===e.method){var u=e.params[1];if((r=l(e.params[0],t.accounts))&&r.privateKey){var f=t.accounts.sign(u,r.privateKey);return e.callback&&e.callback(null,f.signature),void n.resolve(f.signature)}}}return t.requestManager.send(e,o)};return t&&i.isObject(r.params[0])&&!r.params[0].gasPrice?new u({name:"getGasPrice",call:"eth_gasPrice",params:0}).createFunction(e.requestManager)(function(t,n){n&&(r.params[0].gasPrice=n),f(r,e)}):f(r,e),n.eventEmitter};return n.method=e,n.request=this.request.bind(this),n},u.prototype.request=function(){var e=this.toPayload(Array.prototype.slice.call(arguments));return e.format=this.formatOutput.bind(this),e},t.exports=u},{underscore:187,"web3-core-helpers":186,"web3-core-promievent":191,"web3-core-subscriptions":199,"web3-utils":273}],189:[function(e,t,n){(function(e,i){!function(e){if("object"==(void 0===n?"undefined":_typeof(n))&&void 0!==t)t.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r;"undefined"!=typeof window?r=window:void 0!==i?r=i:"undefined"!=typeof self&&(r=self),r.Promise=e()}}(function(){var t,n,r;return function e(t,n,i){function r(a,s){if(!n[a]){if(!t[a]){var c="function"==typeof _dereq_&&_dereq_;if(!s&&c)return c(a,!0);if(o)return o(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var l=n[a]={exports:{}};t[a][0].call(l.exports,function(e){var n=t[a][1][e];return r(n||e)},l,l.exports,e,t,n,i)}return n[a].exports}for(var o="function"==typeof _dereq_&&_dereq_,a=0;a0;){var t=e.shift();if("function"==typeof t){var n=e.shift(),i=e.shift();t.call(n,i)}else t._settlePromises()}},r.prototype._drainQueues=function(){this._drainQueue(this._normalQueue),this._reset(),this._haveDrainedQueues=!0,this._drainQueue(this._lateQueue)},r.prototype._queueTick=function(){this._isTickUsed||(this._isTickUsed=!0,this._schedule(this.drainQueues))},r.prototype._reset=function(){this._isTickUsed=!1},n.exports=r,n.exports.firstLineError=c},{"./queue":26,"./schedule":29,"./util":36}],3:[function(e,t,n){t.exports=function(e,t,n,i){var r=!1,o=function(e,t){this._reject(t)},a=function(e,t){t.promiseRejectionQueued=!0,t.bindingPromise._then(o,o,null,this,e)},s=function(e,t){0==(50397184&this._bitField)&&this._resolveCallback(t.target)},c=function(e,t){t.promiseRejectionQueued||this._reject(e)};e.prototype.bind=function(o){r||(r=!0,e.prototype._propagateFrom=i.propagateFromFunction(),e.prototype._boundValue=i.boundValueFunction());var u=n(o),l=new e(t);l._propagateFrom(this,1);var f=this._target();if(l._setBoundTo(u),u instanceof e){var p={promiseRejectionQueued:!1,promise:l,target:f,bindingPromise:u};f._then(t,a,void 0,l,p),u._then(s,c,void 0,l,p),l._setOnCancel(u)}else l._resolveCallback(f);return l},e.prototype._setBoundTo=function(e){void 0!==e?(this._bitField=2097152|this._bitField,this._boundTo=e):this._bitField=-2097153&this._bitField},e.prototype._isBound=function(){return 2097152==(2097152&this._bitField)},e.bind=function(t,n){return e.resolve(n).bind(t)}}},{}],4:[function(e,t,n){var i;"undefined"!=typeof Promise&&(i=Promise);var r=e("./promise")();r.noConflict=function(){try{Promise===r&&(Promise=i)}catch(e){}return r},t.exports=r},{"./promise":22}],5:[function(e,t,n){var i=Object.create;if(i){var r=i(null),o=i(null);r[" size"]=o[" size"]=0}t.exports=function(t){function n(e,n){var i;if(null!=e&&(i=e[n]),"function"!=typeof i){var r="Object "+s.classString(e)+" has no method '"+s.toString(n)+"'";throw new t.TypeError(r)}return i}function i(e){return n(e,this.pop()).apply(e,this)}function r(e){return e[this]}function o(e){var t=+this;return t<0&&(t=Math.max(0,t+e.length)),e[t]}var a,s=e("./util"),c=s.canEvaluate;s.isIdentifier;t.prototype.call=function(e){var t=[].slice.call(arguments,1);return t.push(e),this._then(i,void 0,void 0,t,void 0)},t.prototype.get=function(e){var t;if("number"==typeof e)t=o;else if(c){var n=a(e);t=null!==n?n:r}else t=r;return this._then(t,void 0,void 0,e,void 0)}}},{"./util":36}],6:[function(e,t,n){t.exports=function(t,n,i,r){var o=e("./util"),a=o.tryCatch,s=o.errorObj,c=t._async;t.prototype.break=t.prototype.cancel=function(){if(!r.cancellation())return this._warn("cancellation is disabled");for(var e=this,t=e;e.isCancellable();){if(!e._cancelBy(t)){t._isFollowing()?t._followee().cancel():t._cancelBranched();break}var n=e._cancellationParent;if(null==n||!n.isCancellable()){e._isFollowing()?e._followee().cancel():e._cancelBranched();break}e._isFollowing()&&e._followee().cancel(),t=e,e=n}},t.prototype._branchHasCancelled=function(){this._branchesRemainingToCancel--},t.prototype._enoughBranchesHaveCancelled=function(){return void 0===this._branchesRemainingToCancel||this._branchesRemainingToCancel<=0},t.prototype._cancelBy=function(e){return e===this?(this._branchesRemainingToCancel=0,this._invokeOnCancel(),!0):(this._branchHasCancelled(),!!this._enoughBranchesHaveCancelled()&&(this._invokeOnCancel(),!0))},t.prototype._cancelBranched=function(){this._enoughBranchesHaveCancelled()&&this._cancel()},t.prototype._cancel=function(){this.isCancellable()&&(this._setCancelled(),c.invoke(this._cancelPromises,this,void 0))},t.prototype._cancelPromises=function(){this._length()>0&&this._settlePromises()},t.prototype._unsetOnCancel=function(){this._onCancelField=void 0},t.prototype.isCancellable=function(){return this.isPending()&&!this.isCancelled()},t.prototype._doInvokeOnCancel=function(e,t){if(o.isArray(e))for(var n=0;n=0)return r[e]}var i=!1,r=[];return e.prototype._promiseCreated=function(){},e.prototype._pushContext=function(){},e.prototype._popContext=function(){return null},e._peekContext=e.prototype._peekContext=function(){},t.prototype._pushContext=function(){void 0!==this._trace&&(this._trace._promiseCreated=null,r.push(this._trace))},t.prototype._popContext=function(){if(void 0!==this._trace){var e=r.pop(),t=e._promiseCreated;return e._promiseCreated=null,t}return null},t.CapturedTrace=null,t.create=function(){if(i)return new t},t.deactivateLongStackTraces=function(){},t.activateLongStackTraces=function(){var r=e.prototype._pushContext,o=e.prototype._popContext,a=e._peekContext,s=e.prototype._peekContext,c=e.prototype._promiseCreated;t.deactivateLongStackTraces=function(){e.prototype._pushContext=r,e.prototype._popContext=o,e._peekContext=a,e.prototype._peekContext=s,e.prototype._promiseCreated=c,i=!1},i=!0,e.prototype._pushContext=t.prototype._pushContext,e.prototype._popContext=t.prototype._popContext,e._peekContext=e.prototype._peekContext=n,e.prototype._promiseCreated=function(){var e=this._peekContext();e&&null==e._promiseCreated&&(e._promiseCreated=this)}},t}},{}],9:[function(t,n,i){n.exports=function(n,i){function r(e,t){return{promise:t}}function o(){return!1}function a(e,t,n){var i=this;try{e(t,n,function(e){if("function"!=typeof e)throw new TypeError("onCancel must be a function, got: "+R.toString(e));i._attachCancellationCallback(e)})}catch(e){return e}}function s(e){if(!this.isCancellable())return this;var t=this._onCancel();void 0!==t?R.isArray(t)?t.push(e):this._setOnCancel([t,e]):this._setOnCancel(e)}function c(){return this._onCancelField}function u(e){this._onCancelField=e}function l(){this._cancellationParent=void 0,this._onCancelField=void 0}function f(e,t){if(0!=(1&t)){this._cancellationParent=e;var n=e._branchesRemainingToCancel;void 0===n&&(n=0),e._branchesRemainingToCancel=n+1}0!=(2&t)&&e._isBound()&&this._setBoundTo(e._boundTo)}function p(){var e=this._boundTo;return void 0!==e&&e instanceof n?e.isFulfilled()?e.value():void 0:e}function d(){this._trace=new C(this._peekContext())}function h(e,t){if(O(e)){var n=this._trace;if(void 0!==n&&t&&(n=n._parent),void 0!==n)n.attachExtraTrace(e);else if(!e.__stackCleaned__){var i=x(e);R.notEnumerableProp(e,"stack",i.message+"\n"+i.stack.join("\n")),R.notEnumerableProp(e,"__stackCleaned__",!0)}}}function m(e,t,i){if(ee.warnings){var r,o=new B(e);if(t)i._attachExtraTrace(o);else if(ee.longStackTraces&&(r=n._peekContext()))r.attachExtraTrace(o);else{var a=x(o);o.stack=a.message+"\n"+a.stack.join("\n")}$("warning",o)||w(o,"",!0)}}function v(e,t){for(var n=0;n=0;--s)if(i[s]===o){a=s;break}for(s=a;s>=0;--s){var c=i[s];if(t[r]!==c)break;t.pop(),r--}t=i}}function g(e){for(var t=[],n=0;n0&&(t=t.slice(n)),t}function x(e){var t=e.stack,n=e.toString();return t="string"==typeof t&&t.length>0?_(e):[" (No stack trace)"],{message:n,stack:g(t)}}function w(e,t,n){if("undefined"!=typeof console){var i;if(R.isObject(e)){var r=e.stack;i=t+L(r,e)}else i=t+String(e);"function"==typeof P?P(i,n):"function"!=typeof console.log&&"object"!==_typeof(console.log)||console.log(i)}}function k(e,t,n,i){var r=!1;try{"function"==typeof t&&(r=!0,"rejectionHandled"===e?t(i):t(n,i))}catch(e){I.throwLater(e)}"unhandledRejection"===e?$(e,n,i)||r||w(n,"Unhandled rejection "):$(e,i)}function j(e){var t;if("function"==typeof e)t="[function "+(e.name||"anonymous")+"]";else{if(t=e&&"function"==typeof e.toString?e.toString():R.toString(e),/\[object [a-zA-Z0-9$_]+\]/.test(t))try{t=JSON.stringify(e)}catch(e){}0===t.length&&(t="(empty array)")}return"(<"+S(t)+">, no stack trace)"}function S(e){return e.length<41?e:e.substr(0,38)+"..."}function E(){return"function"==typeof Z}function A(e){var t=e.match(Y);if(t)return{fileName:t[1],line:parseInt(t[2],10)}}function C(e){this._parent=e,this._promisesCreated=0;var t=this._length=1+(void 0===e?0:e._length);Z(this,C),t>32&&this.uncycle()}var M,T,P,F=n._getDomain,I=n._async,B=t("./errors").Warning,R=t("./util"),O=R.canAttachTrace,N=/[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/,D=null,L=null,q=!1,z=!(0==R.env("BLUEBIRD_DEBUG")),U=!(0==R.env("BLUEBIRD_WARNINGS")||!z&&!R.env("BLUEBIRD_WARNINGS")),H=!(0==R.env("BLUEBIRD_LONG_STACK_TRACES")||!z&&!R.env("BLUEBIRD_LONG_STACK_TRACES")),V=0!=R.env("BLUEBIRD_W_FORGOTTEN_RETURN")&&(U||!!R.env("BLUEBIRD_W_FORGOTTEN_RETURN"));n.prototype.suppressUnhandledRejections=function(){var e=this._target();e._bitField=-1048577&e._bitField|524288},n.prototype._ensurePossibleRejectionHandled=function(){0==(524288&this._bitField)&&(this._setRejectionIsUnhandled(),I.invokeLater(this._notifyUnhandledRejection,this,void 0))},n.prototype._notifyUnhandledRejectionIsHandled=function(){k("rejectionHandled",M,void 0,this)},n.prototype._setReturnedNonUndefined=function(){this._bitField=268435456|this._bitField},n.prototype._returnedNonUndefined=function(){return 0!=(268435456&this._bitField)},n.prototype._notifyUnhandledRejection=function(){if(this._isRejectionUnhandled()){var e=this._settledValue();this._setUnhandledRejectionIsNotified(),k("unhandledRejection",T,e,this)}},n.prototype._setUnhandledRejectionIsNotified=function(){this._bitField=262144|this._bitField},n.prototype._unsetUnhandledRejectionIsNotified=function(){this._bitField=-262145&this._bitField},n.prototype._isUnhandledRejectionNotified=function(){return(262144&this._bitField)>0},n.prototype._setRejectionIsUnhandled=function(){this._bitField=1048576|this._bitField},n.prototype._unsetRejectionIsUnhandled=function(){this._bitField=-1048577&this._bitField,this._isUnhandledRejectionNotified()&&(this._unsetUnhandledRejectionIsNotified(),this._notifyUnhandledRejectionIsHandled())},n.prototype._isRejectionUnhandled=function(){return(1048576&this._bitField)>0},n.prototype._warn=function(e,t,n){return m(e,t,n||this)},n.onPossiblyUnhandledRejection=function(e){var t=F();T="function"==typeof e?null===t?e:t.bind(e):void 0},n.onUnhandledRejectionHandled=function(e){var t=F();M="function"==typeof e?null===t?e:t.bind(e):void 0};var K=function(){};n.longStackTraces=function(){if(I.haveItemsQueued()&&!ee.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");if(!ee.longStackTraces&&E()){var e=n.prototype._captureStackTrace,t=n.prototype._attachExtraTrace;ee.longStackTraces=!0,K=function(){if(I.haveItemsQueued()&&!ee.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");n.prototype._captureStackTrace=e,n.prototype._attachExtraTrace=t,i.deactivateLongStackTraces(),I.enableTrampoline(),ee.longStackTraces=!1},n.prototype._captureStackTrace=d,n.prototype._attachExtraTrace=h,i.activateLongStackTraces(),I.disableTrampolineIfNecessary()}},n.hasLongStackTraces=function(){return ee.longStackTraces&&E()};var W=function(){try{var e=document.createEvent("CustomEvent");return e.initCustomEvent("testingtheevent",!1,!0,{}),R.global.dispatchEvent(e),function(e,t){var n=document.createEvent("CustomEvent");return n.initCustomEvent(e.toLowerCase(),!1,!0,t),!R.global.dispatchEvent(n)}}catch(e){}return function(){return!1}}(),X=R.isNode?function(){return e.emit.apply(e,arguments)}:R.global?function(e){var t="on"+e.toLowerCase(),n=R.global[t];return!!n&&(n.apply(R.global,[].slice.call(arguments,1)),!0)}:function(){return!1},G={promiseCreated:r,promiseFulfilled:r,promiseRejected:r,promiseResolved:r,promiseCancelled:r,promiseChained:function(e,t,n){return{promise:t,child:n}},warning:function(e,t){return{warning:t}},unhandledRejection:function(e,t,n){return{reason:t,promise:n}},rejectionHandled:r},$=function(e){var t=!1;try{t=X.apply(null,arguments)}catch(e){I.throwLater(e),t=!0}var n=!1;try{n=W(e,G[e].apply(null,arguments))}catch(e){I.throwLater(e),n=!0}return n||t};n.config=function(e){if("longStackTraces"in(e=Object(e))&&(e.longStackTraces?n.longStackTraces():!e.longStackTraces&&n.hasLongStackTraces()&&K()),"warnings"in e){var t=e.warnings;ee.warnings=!!t,V=ee.warnings,R.isObject(t)&&"wForgottenReturn"in t&&(V=!!t.wForgottenReturn)}if("cancellation"in e&&e.cancellation&&!ee.cancellation){if(I.haveItemsQueued())throw new Error("cannot enable cancellation after promises are in use");n.prototype._clearCancellationData=l,n.prototype._propagateFrom=f,n.prototype._onCancel=c,n.prototype._setOnCancel=u,n.prototype._attachCancellationCallback=s,n.prototype._execute=a,J=f,ee.cancellation=!0}"monitoring"in e&&(e.monitoring&&!ee.monitoring?(ee.monitoring=!0,n.prototype._fireEvent=$):!e.monitoring&&ee.monitoring&&(ee.monitoring=!1,n.prototype._fireEvent=o))},n.prototype._fireEvent=o,n.prototype._execute=function(e,t,n){try{e(t,n)}catch(e){return e}},n.prototype._onCancel=function(){},n.prototype._setOnCancel=function(e){},n.prototype._attachCancellationCallback=function(e){},n.prototype._captureStackTrace=function(){},n.prototype._attachExtraTrace=function(){},n.prototype._clearCancellationData=function(){},n.prototype._propagateFrom=function(e,t){};var J=function(e,t){0!=(2&t)&&e._isBound()&&this._setBoundTo(e._boundTo)},Q=function(){return!1},Y=/[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;R.inherits(C,Error),i.CapturedTrace=C,C.prototype.uncycle=function(){var e=this._length;if(!(e<2)){for(var t=[],n={},i=0,r=this;void 0!==r;++i)t.push(r),r=r._parent;for(i=(e=this._length=i)-1;i>=0;--i){var o=t[i].stack;void 0===n[o]&&(n[o]=i)}for(i=0;i0&&(t[a-1]._parent=void 0,t[a-1]._length=1),t[i]._parent=void 0,t[i]._length=1;var s=i>0?t[i-1]:this;a=0;--u)t[u]._length=c,c++;return}}}},C.prototype.attachExtraTrace=function(e){if(!e.__stackCleaned__){this.uncycle();for(var t=x(e),n=t.message,i=[t.stack],r=this;void 0!==r;)i.push(g(r.stack.split("\n"))),r=r._parent;y(i),b(i),R.notEnumerableProp(e,"stack",v(n,i)),R.notEnumerableProp(e,"__stackCleaned__",!0)}};var Z=function(){var e=/^\s*at\s*/,t=function(e,t){return"string"==typeof e?e:void 0!==t.name&&void 0!==t.message?t.toString():j(t)};if("number"==typeof Error.stackTraceLimit&&"function"==typeof Error.captureStackTrace){Error.stackTraceLimit+=6,D=e,L=t;var n=Error.captureStackTrace;return Q=function(e){return N.test(e)},function(e,t){Error.stackTraceLimit+=6,n(e,t),Error.stackTraceLimit-=6}}var i=new Error;if("string"==typeof i.stack&&i.stack.split("\n")[0].indexOf("stackDetection@")>=0)return D=/@/,L=t,q=!0,function(e){e.stack=(new Error).stack};var r;try{throw new Error}catch(e){r="stack"in e}return"stack"in i||!r||"number"!=typeof Error.stackTraceLimit?(L=function(e,t){return"string"==typeof e?e:"object"!==(void 0===t?"undefined":_typeof(t))&&"function"!=typeof t||void 0===t.name||void 0===t.message?j(t):t.toString()},null):(D=e,L=t,function(e){Error.stackTraceLimit+=6;try{throw new Error}catch(t){e.stack=t.stack}Error.stackTraceLimit-=6})}();"undefined"!=typeof console&&void 0!==console.warn&&(P=function(e){console.warn(e)},R.isNode&&e.stderr.isTTY?P=function(e,t){var n=t?"":"";console.warn(n+e+"\n")}:R.isNode||"string"!=typeof(new Error).stack||(P=function(e,t){console.warn("%c"+e,t?"color: darkorange":"color: red")}));var ee={warnings:U,longStackTraces:!1,cancellation:!1,monitoring:!1};return H&&n.longStackTraces(),{longStackTraces:function(){return ee.longStackTraces},warnings:function(){return ee.warnings},cancellation:function(){return ee.cancellation},monitoring:function(){return ee.monitoring},propagateFromFunction:function(){return J},boundValueFunction:function(){return p},checkForgottenReturns:function(e,t,n,i,r){if(void 0===e&&null!==t&&V){if(void 0!==r&&r._returnedNonUndefined())return;n&&(n+=" ");var o="a promise was created in a "+n+"handler but was not returned from it";i._warn(o,!0,t)}},setBounds:function(e,t){if(E()){for(var n,i,r=e.stack.split("\n"),o=t.stack.split("\n"),a=-1,s=-1,c=0;c=s||(Q=function(e){if(N.test(e))return!0;var t=A(e);return!!(t&&t.fileName===n&&a<=t.line&&t.line<=s)})}},warn:m,deprecated:function(e,t){var n=e+" is deprecated and will be removed in a future version.";return t&&(n+=" Use "+t+" instead."),m(n)},CapturedTrace:C,fireDomEvent:W,fireGlobalEvent:X}}},{"./errors":12,"./util":36}],10:[function(e,t,n){t.exports=function(e){function t(){return this.value}function n(){throw this.reason}e.prototype.return=e.prototype.thenReturn=function(n){return n instanceof e&&n.suppressUnhandledRejections(),this._then(t,void 0,void 0,{value:n},void 0)},e.prototype.throw=e.prototype.thenThrow=function(e){return this._then(n,void 0,void 0,{reason:e},void 0)},e.prototype.catchThrow=function(e){if(arguments.length<=1)return this._then(void 0,n,void 0,{reason:e},void 0);var t=arguments[1];return this.caught(e,function(){throw t})},e.prototype.catchReturn=function(n){if(arguments.length<=1)return n instanceof e&&n.suppressUnhandledRejections(),this._then(void 0,t,void 0,{value:n},void 0);var i=arguments[1];i instanceof e&&i.suppressUnhandledRejections();return this.caught(n,function(){return i})}}},{}],11:[function(e,t,n){t.exports=function(e,t){function n(){return o(this)}function i(e,n){return r(e,n,t,t)}var r=e.reduce,o=e.all;e.prototype.each=function(e){return this.mapSeries(e)._then(n,void 0,void 0,this,void 0)},e.prototype.mapSeries=function(e){return r(this,e,t,t)},e.each=function(e,t){return i(e,t)._then(n,void 0,void 0,e,void 0)},e.mapSeries=i}},{}],12:[function(e,t,n){function i(e,t){function n(i){if(!(this instanceof n))return new n(i);f(this,"message","string"==typeof i?i:t),f(this,"name",e),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):Error.call(this)}return l(n,Error),n}function r(e){if(!(this instanceof r))return new r(e);f(this,"name","OperationalError"),f(this,"message",e),this.cause=e,this.isOperational=!0,e instanceof Error?(f(this,"message",e.message),f(this,"stack",e.stack)):Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}var o,a,s=e("./es5"),c=s.freeze,u=e("./util"),l=u.inherits,f=u.notEnumerableProp,p=i("Warning","warning"),d=i("CancellationError","cancellation error"),h=i("TimeoutError","timeout error"),m=i("AggregateError","aggregate error");try{o=TypeError,a=RangeError}catch(e){o=i("TypeError","type error"),a=i("RangeError","range error")}for(var v="join pop push shift unshift slice filter forEach some every map indexOf lastIndexOf reduce reduceRight sort reverse".split(" "),b=0;b1?e.cancelPromise._reject(t):e.cancelPromise._cancel(),e.cancelPromise=null,!0)}function a(){return c.call(this,this.promise._target()._settledValue())}function s(e){if(!o(this,e))return f.e=e,f}function c(e){var i=this.promise,c=this.handler;if(!this.called){this.called=!0;var u=this.isFinallyHandler()?c.call(i._boundValue()):c.call(i._boundValue(),e);if(void 0!==u){i._setReturnedNonUndefined();var p=n(u,i);if(p instanceof t){if(null!=this.cancelPromise){if(p.isCancelled()){var d=new l("late cancellation observer");return i._attachExtraTrace(d),f.e=d,f}p.isPending()&&p._attachCancellationCallback(new r(this))}return p._then(a,s,void 0,this,void 0)}}}return i.isRejected()?(o(this),f.e=e,f):(o(this),e)}var u=e("./util"),l=t.CancellationError,f=u.errorObj;return i.prototype.isFinallyHandler=function(){return 0===this.type},r.prototype._resultCancelled=function(){o(this.finallyHandler)},t.prototype._passThrough=function(e,t,n,r){return"function"!=typeof e?this.then():this._then(n,r,void 0,new i(this,t,e),void 0)},t.prototype.lastly=t.prototype.finally=function(e){return this._passThrough(e,0,c,c)},t.prototype.tap=function(e){return this._passThrough(e,1,c)},i}},{"./util":36}],16:[function(e,t,n){t.exports=function(t,n,i,r,o,a){function s(e,n,i){for(var o=0;o0&&"function"==typeof arguments[t]){e=arguments[t]}var i=[].slice.call(arguments);e&&i.pop();var r=new n(i).promise();return void 0!==e?r.spread(e):r}}},{"./util":36}],18:[function(e,t,n){t.exports=function(t,n,i,r,o,a){function s(e,t,n,i){this.constructor$(e),this._promise._captureStackTrace();var r=u();this._callback=null===r?t:r.bind(t),this._preservedValues=i===o?new Array(this.length()):null,this._limit=n,this._inFlight=0,this._queue=n>=1?[]:d,this._init$(void 0,-2)}function c(e,t,n,r){if("function"!=typeof t)return i("expecting a function but got "+l.classString(t));var o="object"===(void 0===n?"undefined":_typeof(n))&&null!==n?n.concurrency:0;return o="number"==typeof o&&isFinite(o)&&o>=1?o:0,new s(e,t,o,r).promise()}var u=t._getDomain,l=e("./util"),f=l.tryCatch,p=l.errorObj,d=[];l.inherits(s,n),s.prototype._init=function(){},s.prototype._promiseFulfilled=function(e,n){var i=this._values,o=this.length(),s=this._preservedValues,c=this._limit;if(n<0){if(n=-1*n-1,i[n]=e,c>=1&&(this._inFlight--,this._drainQueue(),this._isResolved()))return!0}else{if(c>=1&&this._inFlight>=c)return i[n]=e,this._queue.push(n),!1;null!==s&&(s[n]=e);var u=this._promise,l=this._callback,d=u._boundValue();u._pushContext();var h=f(l).call(d,e,n,o),m=u._popContext();if(a.checkForgottenReturns(h,m,null!==s?"Promise.filter":"Promise.map",u),h===p)return this._reject(h.e),!0;var v=r(h,this._promise);if(v instanceof t){var b=(v=v._target())._bitField;if(0==(50397184&b))return c>=1&&this._inFlight++,i[n]=v,v._proxy(this,-1*(n+1)),!1;if(0==(33554432&b))return 0!=(16777216&b)?(this._reject(v._reason()),!0):(this._cancel(),!0);h=v._value()}i[n]=h}return++this._totalResolved>=o&&(null!==s?this._filter(i,s):this._resolve(i),!0)},s.prototype._drainQueue=function(){for(var e=this._queue,t=this._limit,n=this._values;e.length>0&&this._inFlight1){o.deprecated("calling Promise.try with more than 1 argument");var u=arguments[1],l=arguments[2];c=a.isArray(u)?s(e).apply(l,u):s(e).call(l,u)}else c=s(e)();var f=i._popContext();return o.checkForgottenReturns(c,f,"Promise.try",i),i._resolveFromSyncValue(c),i},t.prototype._resolveFromSyncValue=function(e){e===a.errorObj?this._rejectCallback(e.e,!1):this._resolveCallback(e,!0)}}},{"./util":36}],20:[function(e,t,n){function i(e){return e instanceof Error&&c.getPrototypeOf(e)===Error.prototype}function r(e){var t;if(i(e)){(t=new s(e)).name=e.name,t.message=e.message,t.stack=e.stack;for(var n=c.keys(e),r=0;r1){var n,i=new Array(t-1),r=0;for(n=0;n0&&"function"!=typeof e&&"function"!=typeof t){var n=".then() only accepts functions but was passed: "+d.classString(e);arguments.length>1&&(n+=", "+d.classString(t)),this._warn(n)}return this._then(e,t,void 0,void 0,void 0)},r.prototype.done=function(e,t){this._then(e,t,void 0,void 0,void 0)._setIsFinal()},r.prototype.spread=function(e){return"function"!=typeof e?f("expecting a function but got "+d.classString(e)):this.all()._then(e,void 0,void 0,x,void 0)},r.prototype.toJSON=function(){var e={isFulfilled:!1,isRejected:!1,fulfillmentValue:void 0,rejectionReason:void 0};return this.isFulfilled()?(e.fulfillmentValue=this.value(),e.isFulfilled=!0):this.isRejected()&&(e.rejectionReason=this.reason(),e.isRejected=!0),e},r.prototype.all=function(){return arguments.length>0&&this._warn(".all() was passed arguments but it does not take any"),new j(this).promise()},r.prototype.error=function(e){return this.caught(d.originatesFromRejection,e)},r.is=function(e){return e instanceof r},r.fromNode=r.fromCallback=function(e){var t=new r(_);t._captureStackTrace();var n=arguments.length>1&&!!Object(arguments[1]).multiArgs,i=F(e)(T(t,n));return i===P&&t._rejectCallback(i.e,!0),t._isFateSealed()||t._setAsyncGuaranteed(),t},r.all=function(e){return new j(e).promise()},r.cast=function(e){var t=k(e);return t instanceof r||((t=new r(_))._captureStackTrace(),t._setFulfilled(),t._rejectionHandler0=e),t},r.resolve=r.fulfilled=r.cast,r.reject=r.rejected=function(e){var t=new r(_);return t._captureStackTrace(),t._rejectCallback(e,!0),t},r.setScheduler=function(e){if("function"!=typeof e)throw new y("expecting a function but got "+d.classString(e));var t=v._schedule;return v._schedule=e,t},r.prototype._then=function(e,t,n,i,o){var a=void 0!==o,s=a?o:new r(_),u=this._target(),l=u._bitField;a||(s._propagateFrom(this,3),s._captureStackTrace(),void 0===i&&0!=(2097152&this._bitField)&&(i=0!=(50397184&l)?this._boundValue():u===this?void 0:this._boundTo),this._fireEvent("promiseChained",this,s));var f=c();if(0!=(50397184&l)){var p,d,h=u._settlePromiseCtx;0!=(33554432&l)?(d=u._rejectionHandler0,p=e):0!=(16777216&l)?(d=u._fulfillmentHandler0,p=t,u._unsetRejectionIsUnhandled()):(h=u._settlePromiseLateCancellationObserver,d=new g("late cancellation observer"),u._attachExtraTrace(d),p=t),v.invoke(h,u,{handler:null===f?p:"function"==typeof p&&f.bind(p),promise:s,receiver:i,value:d})}else u._addCallbacks(e,t,s,i,f);return s},r.prototype._length=function(){return 65535&this._bitField},r.prototype._isFateSealed=function(){return 0!=(117506048&this._bitField)},r.prototype._isFollowing=function(){return 67108864==(67108864&this._bitField)},r.prototype._setLength=function(e){this._bitField=-65536&this._bitField|65535&e},r.prototype._setFulfilled=function(){this._bitField=33554432|this._bitField,this._fireEvent("promiseFulfilled",this)},r.prototype._setRejected=function(){this._bitField=16777216|this._bitField,this._fireEvent("promiseRejected",this)},r.prototype._setFollowing=function(){this._bitField=67108864|this._bitField,this._fireEvent("promiseResolved",this)},r.prototype._setIsFinal=function(){this._bitField=4194304|this._bitField},r.prototype._isFinal=function(){return(4194304&this._bitField)>0},r.prototype._unsetCancelled=function(){this._bitField=-65537&this._bitField},r.prototype._setCancelled=function(){this._bitField=65536|this._bitField,this._fireEvent("promiseCancelled",this)},r.prototype._setAsyncGuaranteed=function(){this._bitField=134217728|this._bitField},r.prototype._receiverAt=function(e){var t=0===e?this._receiver0:this[4*e-4+3];if(t!==p)return void 0===t&&this._isBound()?this._boundValue():t},r.prototype._promiseAt=function(e){return this[4*e-4+2]},r.prototype._fulfillmentHandlerAt=function(e){return this[4*e-4+0]},r.prototype._rejectionHandlerAt=function(e){return this[4*e-4+1]},r.prototype._boundValue=function(){},r.prototype._migrateCallback0=function(e){e._bitField;var t=e._fulfillmentHandler0,n=e._rejectionHandler0,i=e._promise0,r=e._receiverAt(0);void 0===r&&(r=p),this._addCallbacks(t,n,i,r,null)},r.prototype._migrateCallbackAt=function(e,t){var n=e._fulfillmentHandlerAt(t),i=e._rejectionHandlerAt(t),r=e._promiseAt(t),o=e._receiverAt(t);void 0===o&&(o=p),this._addCallbacks(n,i,r,o,null)},r.prototype._addCallbacks=function(e,t,n,i,r){var o=this._length();if(o>=65531&&(o=0,this._setLength(0)),0===o)this._promise0=n,this._receiver0=i,"function"==typeof e&&(this._fulfillmentHandler0=null===r?e:r.bind(e)),"function"==typeof t&&(this._rejectionHandler0=null===r?t:r.bind(t));else{var a=4*o-4;this[a+2]=n,this[a+3]=i,"function"==typeof e&&(this[a+0]=null===r?e:r.bind(e)),"function"==typeof t&&(this[a+1]=null===r?t:r.bind(t))}return this._setLength(o+1),o},r.prototype._proxy=function(e,t){this._addCallbacks(void 0,void 0,t,e,null)},r.prototype._resolveCallback=function(e,t){if(0==(117506048&this._bitField)){if(e===this)return this._rejectCallback(u(),!1);var n=k(e,this);if(!(n instanceof r))return this._fulfill(e);t&&this._propagateFrom(n,2);var i=n._target(),o=i._bitField;if(0==(50397184&o)){var a=this._length();a>0&&i._migrateCallback0(this);for(var s=1;s>>16)){if(e===this){var n=u();return this._attachExtraTrace(n),this._reject(n)}this._setFulfilled(),this._rejectionHandler0=e,(65535&t)>0&&(0!=(134217728&t)?this._settlePromises():v.settlePromises(this))}},r.prototype._reject=function(e){var t=this._bitField;if(!((117506048&t)>>>16)){if(this._setRejected(),this._fulfillmentHandler0=e,this._isFinal())return v.fatalError(e,d.isNode);(65535&t)>0?0!=(134217728&t)?this._settlePromises():v.settlePromises(this):this._ensurePossibleRejectionHandled()}},r.prototype._fulfillPromises=function(e,t){for(var n=1;n0){if(0!=(16842752&e)){var n=this._fulfillmentHandler0;this._settlePromise0(this._rejectionHandler0,n,e),this._rejectPromises(t,n)}else{var i=this._rejectionHandler0;this._settlePromise0(this._fulfillmentHandler0,i,e),this._fulfillPromises(t,i)}this._setLength(0)}this._clearCancellationData()},r.prototype._settledValue=function(){var e=this._bitField;return 0!=(33554432&e)?this._rejectionHandler0:0!=(16777216&e)?this._fulfillmentHandler0:void 0},r.defer=r.pending=function(){return A.deprecated("Promise.defer","new Promise"),{promise:new r(_),resolve:o,reject:a}},d.notEnumerableProp(r,"_makeSelfResolutionError",u),t("./method")(r,_,k,f,A),t("./bind")(r,_,k,A),t("./cancel")(r,j,f,A),t("./direct_resolve")(r),t("./synchronous_inspection")(r),t("./join")(r,j,k,_,A),r.Promise=r,t("./map.js")(r,j,f,k,_,A),t("./using.js")(r,f,k,E,_,A),t("./timers.js")(r,_,A),t("./generators.js")(r,f,_,k,n,A),t("./nodeify.js")(r),t("./call_get.js")(r),t("./props.js")(r,j,k,f),t("./race.js")(r,_,k,f),t("./reduce.js")(r,j,f,k,_,A),t("./settle.js")(r,j,A),t("./some.js")(r,j,f),t("./promisify.js")(r,_),t("./any.js")(r),t("./each.js")(r,_),t("./filter.js")(r,_),d.toFastProperties(r),d.toFastProperties(r.prototype),s({a:1}),s({b:2}),s({c:3}),s(1),s(function(){}),s(void 0),s(!1),s(new r(_)),A.setBounds(m.firstLineError,d.lastLineError),r}},{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(e,t,n){t.exports=function(t,n,i,r,o){function a(e){switch(e){case-2:return[];case-3:return{}}}function s(e){var i=this._promise=new t(n);e instanceof t&&i._propagateFrom(e,3),i._setOnCancel(this),this._values=e,this._length=0,this._totalResolved=0,this._init(void 0,-2)}var c=e("./util");c.isArray;return c.inherits(s,o),s.prototype.length=function(){return this._length},s.prototype.promise=function(){return this._promise},s.prototype._init=function e(n,o){var s=i(this._values,this._promise);if(s instanceof t){var u=(s=s._target())._bitField;if(this._values=s,0==(50397184&u))return this._promise._setAsyncGuaranteed(),s._then(e,this._reject,void 0,this,o);if(0==(33554432&u))return 0!=(16777216&u)?this._reject(s._reason()):this._cancel();s=s._value()}if(null!==(s=c.asArray(s)))0!==s.length?this._iterate(s):-5===o?this._resolveEmptyArray():this._resolve(a(o));else{var l=r("expecting an array or an iterable object but got "+c.classString(s)).reason();this._promise._rejectCallback(l,!1)}},s.prototype._iterate=function(e){var n=this.getActualLength(e.length);this._length=n,this._values=this.shouldCopyValues()?new Array(n):this._values;for(var r=this._promise,o=!1,a=null,s=0;s=this._length&&(this._resolve(this._values),!0)},s.prototype._promiseCancelled=function(){return this._cancel(),!0},s.prototype._promiseRejected=function(e){return this._totalResolved++,this._reject(e),!0},s.prototype._resultCancelled=function(){if(!this._isResolved()){var e=this._values;if(this._cancel(),e instanceof t)e.cancel();else for(var n=0;n=this._length){var n;if(this._isMap)n=p(this._values);else{n={};for(var i=this.length(),r=0,o=this.length();r>1},t.prototype.props=function(){return a(this)},t.props=function(e){return a(e)}}},{"./es5":13,"./util":36}],26:[function(e,t,n){function i(e,t,n,i,r){for(var o=0;o=this._length&&(this._resolve(this._values),!0)},r.prototype._promiseFulfilled=function(e,t){var n=new o;return n._bitField=33554432,n._settledValueField=e,this._promiseResolved(t,n)},r.prototype._promiseRejected=function(e,t){var n=new o;return n._bitField=16777216,n._settledValueField=e,this._promiseResolved(t,n)},t.settle=function(e){return i.deprecated(".settle()",".reflect()"),new r(e).promise()},t.prototype.settle=function(){return t.settle(this)}}},{"./util":36}],31:[function(e,t,n){t.exports=function(t,n,i){function r(e){this.constructor$(e),this._howMany=0,this._unwrap=!1,this._initialized=!1}function o(e,t){if((0|t)!==t||t<0)return i("expecting a positive integer\n\n See http://goo.gl/MqrFmX\n");var n=new r(e),o=n.promise();return n.setHowMany(t),n.init(),o}var a=e("./util"),s=e("./errors").RangeError,c=e("./errors").AggregateError,u=a.isArray,l={};a.inherits(r,n),r.prototype._init=function(){if(this._initialized)if(0!==this._howMany){this._init$(void 0,-5);var e=u(this._values);!this._isResolved()&&e&&this._howMany>this._canPossiblyFulfill()&&this._reject(this._getRangeError(this.length()))}else this._resolve([])},r.prototype.init=function(){this._initialized=!0,this._init()},r.prototype.setUnwrap=function(){this._unwrap=!0},r.prototype.howMany=function(){return this._howMany},r.prototype.setHowMany=function(e){this._howMany=e},r.prototype._promiseFulfilled=function(e){return this._addFulfilled(e),this._fulfilled()===this.howMany()&&(this._values.length=this.howMany(),1===this.howMany()&&this._unwrap?this._resolve(this._values[0]):this._resolve(this._values),!0)},r.prototype._promiseRejected=function(e){return this._addRejected(e),this._checkOutcome()},r.prototype._promiseCancelled=function(){return this._values instanceof t||null==this._values?this._cancel():(this._addRejected(l),this._checkOutcome())},r.prototype._checkOutcome=function(){if(this.howMany()>this._canPossiblyFulfill()){for(var e=new c,t=this.length();t0?this._reject(e):this._cancel(),!0}return!1},r.prototype._fulfilled=function(){return this._totalResolved},r.prototype._rejected=function(){return this._values.length-this.length()},r.prototype._addRejected=function(e){this._values.push(e)},r.prototype._addFulfilled=function(e){this._values[this._totalResolved++]=e},r.prototype._canPossiblyFulfill=function(){return this.length()-this._rejected()},r.prototype._getRangeError=function(e){var t="Input array must contain at least "+this._howMany+" items but contains only "+e+" items";return new s(t)},r.prototype._resolveEmptyArray=function(){this._reject(this._getRangeError(0))},t.some=function(e,t){return o(e,t)},t.prototype.some=function(e){return o(this,e)},t._SomePromiseArray=r}},{"./errors":12,"./util":36}],32:[function(e,t,n){t.exports=function(e){function t(e){void 0!==e?(e=e._target(),this._bitField=e._bitField,this._settledValueField=e._isFateSealed()?e._settledValue():void 0):(this._bitField=0,this._settledValueField=void 0)}t.prototype._settledValue=function(){return this._settledValueField};var n=t.prototype.value=function(){if(!this.isFulfilled())throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},i=t.prototype.error=t.prototype.reason=function(){if(!this.isRejected())throw new TypeError("cannot get rejection reason of a non-rejected promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},r=t.prototype.isFulfilled=function(){return 0!=(33554432&this._bitField)},o=t.prototype.isRejected=function(){return 0!=(16777216&this._bitField)},a=t.prototype.isPending=function(){return 0==(50397184&this._bitField)},s=t.prototype.isResolved=function(){return 0!=(50331648&this._bitField)};t.prototype.isCancelled=e.prototype._isCancelled=function(){return 65536==(65536&this._bitField)},e.prototype.isCancelled=function(){return this._target()._isCancelled()},e.prototype.isPending=function(){return a.call(this._target())},e.prototype.isRejected=function(){return o.call(this._target())},e.prototype.isFulfilled=function(){return r.call(this._target())},e.prototype.isResolved=function(){return s.call(this._target())},e.prototype.value=function(){return n.call(this._target())},e.prototype.reason=function(){var e=this._target();return e._unsetRejectionIsUnhandled(),i.call(e)},e.prototype._value=function(){return this._settledValue()},e.prototype._reason=function(){return this._unsetRejectionIsUnhandled(),this._settledValue()},e.PromiseInspection=t}},{}],33:[function(e,t,n){t.exports=function(t,n){function i(e){return e.then}function r(e){try{return i(e)}catch(e){return c.e=e,c}}function o(e){return l.call(e,"_promise0")}function a(e,i,r){var o=new t(n),a=o;r&&r._pushContext(),o._captureStackTrace(),r&&r._popContext();var u=!0,l=s.tryCatch(i).call(e,function(e){o&&(o._resolveCallback(e),o=null)},function(e){o&&(o._rejectCallback(e,u,!0),o=null)});return u=!1,o&&l===c&&(o._rejectCallback(l.e,!0,!0),o=null),a}var s=e("./util"),c=s.errorObj,u=s.isObject,l={}.hasOwnProperty;return function(e,i){if(u(e)){if(e instanceof t)return e;var s=r(e);if(s===c)return i&&i._pushContext(),l=t.reject(s.e),i&&i._popContext(),l;if("function"==typeof s){if(o(e)){var l=new t(n);return e._then(l._fulfill,l._reject,void 0,l,null),l}return a(e,s,i)}}return e}}},{"./util":36}],34:[function(e,t,n){t.exports=function(t,n,i){function r(e){this.handle=e}function o(e){return clearTimeout(this.handle),e}function a(e){throw clearTimeout(this.handle),e}var s=e("./util"),c=t.TimeoutError;r.prototype._resultCancelled=function(){clearTimeout(this.handle)};var u=function(e){return l(+this).thenReturn(e)},l=t.delay=function(e,o){var a,s;return void 0!==o?(a=t.resolve(o)._then(u,null,null,e,void 0),i.cancellation()&&o instanceof t&&a._setOnCancel(o)):(a=new t(n),s=setTimeout(function(){a._fulfill()},+e),i.cancellation()&&a._setOnCancel(new r(s))),a._setAsyncGuaranteed(),a};t.prototype.delay=function(e){return l(e,this)};var f=function(e,t,n){var i;i="string"!=typeof t?t instanceof Error?t:new c("operation timed out"):new c(t),s.markAsOriginatingFromRejection(i),e._attachExtraTrace(i),e._reject(i),null!=n&&n.cancel()};t.prototype.timeout=function(e,t){e=+e;var n,s,c=new r(setTimeout(function(){n.isPending()&&f(n,t,s)},e));return i.cancellation()?(s=this.then(),(n=s._then(o,a,void 0,c,void 0))._setOnCancel(c)):n=this._then(o,a,void 0,c,void 0),n}}},{"./util":36}],35:[function(e,t,n){t.exports=function(t,n,i,r,o,a){function s(e){setTimeout(function(){throw e},0)}function c(e){var t=i(e);return t!==e&&"function"==typeof e._isDisposable&&"function"==typeof e._getDisposer&&e._isDisposable()&&t._setDisposable(e._getDisposer()),t}function u(e,n){function r(){if(a>=u)return l._fulfill();var o=c(e[a++]);if(o instanceof t&&o._isDisposable()){try{o=i(o._getDisposer().tryDispose(n),e.promise)}catch(e){return s(e)}if(o instanceof t)return o._then(r,s,null,null,null)}r()}var a=0,u=e.length,l=new t(o);return r(),l}function l(e,t,n){this._data=e,this._promise=t,this._context=n}function f(e,t,n){this.constructor$(e,t,n)}function p(e){return l.isDisposer(e)?(this.resources[this.index]._setDisposable(e),e.promise()):e}function d(e){this.length=e,this.promise=null,this[e-1]=null}var h=e("./util"),m=e("./errors").TypeError,v=e("./util").inherits,b=h.errorObj,y=h.tryCatch;l.prototype.data=function(){return this._data},l.prototype.promise=function(){return this._promise},l.prototype.resource=function(){return this.promise().isFulfilled()?this.promise().value():null},l.prototype.tryDispose=function(e){var t=this.resource(),n=this._context;void 0!==n&&n._pushContext();var i=null!==t?this.doDispose(t,e):null;return void 0!==n&&n._popContext(),this._promise._unsetDisposable(),this._data=null,i},l.isDisposer=function(e){return null!=e&&"function"==typeof e.resource&&"function"==typeof e.tryDispose},v(f,l),f.prototype.doDispose=function(e,t){return this.data().call(e,e,t)},d.prototype._resultCancelled=function(){for(var e=this.length,n=0;n0},t.prototype._getDisposer=function(){return this._disposer},t.prototype._unsetDisposable=function(){this._bitField=-131073&this._bitField,this._disposer=void 0},t.prototype.disposer=function(e){if("function"==typeof e)return new f(e,this,r());throw new m}}},{"./errors":12,"./util":36}],36:[function(t,n,r){function o(){try{var e=M;return M=null,e.apply(this,arguments)}catch(e){return C.e=e,C}}function a(e){return M=e,o}function s(e){return null==e||!0===e||!1===e||"string"==typeof e||"number"==typeof e}function c(e){return"function"==typeof e||"object"===(void 0===e?"undefined":_typeof(e))&&null!==e}function u(e){return s(e)?new Error(y(e)):e}function l(e,t){var n,i=e.length,r=new Array(i+1);for(n=0;n1,i=t.length>0&&!(1===t.length&&"constructor"===t[0]),r=I.test(e+"")&&E.names(e).length>0;if(n||i||r)return!0}return!1}catch(e){return!1}}function m(e){function t(){}t.prototype=e;for(var n=8;n--;)new t;return e}function v(e){return B.test(e)}function b(e,t,n){for(var i=new Array(e),r=0;r10||t[0]>0}(),L.isNode&&L.toFastProperties(e);try{throw new Error}catch(e){L.lastLineError=e}n.exports=L},{"./es5":13}]},{},[4])(4)}),"undefined"!=typeof window&&null!==window?window.P=window.Promise:"undefined"!=typeof self&&null!==self&&(self.P=self.Promise)}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:120}],190:[function(e,t,n){function i(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function r(){}var o="function"!=typeof Object.create&&"~";r.prototype._events=void 0,r.prototype.listeners=function(e,t){var n=o?o+e:e,i=this._events&&this._events[n];if(t)return!!i;if(!i)return[];if(i.fn)return[i.fn];for(var r=0,a=i.length,s=new Array(a);r1?(e[n[0]]=e[n[0]]||{},e[n[0]][n[1]]=t):e[n[0]]=t},r.prototype.buildCall=function(){var e=this;return function(){e.subscriptions[arguments[0]]||console.warn("Subscription "+JSON.stringify(arguments[0])+" doesn't exist. Subscribing anyway.");var t=new i({subscription:e.subscriptions[arguments[0]],requestManager:e.requestManager,type:e.type});return t.subscribe.apply(t,arguments)}},t.exports={subscriptions:r,subscription:i}},{"./subscription.js":200}],200:[function(e,t,n){function i(e){a.call(this),this.id=null,this.callback=null,this.arguments=null,this._reconnectIntervalId=null,this.options={subscription:e.subscription,type:e.type,requestManager:e.requestManager}}var r=e("underscore"),o=e("web3-core-helpers").errors,a=e("eventemitter3");(i.prototype=Object.create(a.prototype)).constructor=i,i.prototype._extractCallback=function(e){if(r.isFunction(e[e.length-1]))return e.pop()},i.prototype._validateArgs=function(e){var t=this.options.subscription;if(t||(t={}),t.params||(t.params=0),e.length!==t.params)throw o.InvalidNumberOfParams(e.length,t.params+1,e[0])},i.prototype._formatInput=function(e){var t=this.options.subscription;return t&&t.inputFormatter?t.inputFormatter.map(function(t,n){return t?t(e[n]):e[n]}):e},i.prototype._formatOutput=function(e){var t=this.options.subscription;return t&&t.outputFormatter&&e?t.outputFormatter(e):e},i.prototype._toPayload=function(e){var t=[];if(this.callback=this._extractCallback(e),this.subscriptionMethod||(this.subscriptionMethod=e.shift(),this.options.subscription.subscriptionName&&(this.subscriptionMethod=this.options.subscription.subscriptionName)),this.arguments||(this.arguments=this._formatInput(e),this._validateArgs(this.arguments),e=[]),t.push(this.subscriptionMethod),t=t.concat(this.arguments),e.length)throw new Error("Only a callback is allowed as parameter on an already instantiated subscription.");return{method:this.options.type+"_subscribe",params:t}},i.prototype.unsubscribe=function(e){this.options.requestManager.removeSubscription(this.id,e),this.id=null,this.removeAllListeners(),clearInterval(this._reconnectIntervalId)},i.prototype.subscribe=function(){var e=this,t=Array.prototype.slice.call(arguments),n=this._toPayload(t);if(!n)return this;if(!this.options.requestManager.provider){var i=new Error("No provider set.");return this.callback(i,null,this),this.emit("error",i),this}if(!this.options.requestManager.provider.on){var o=new Error("The current provider doesn't support subscriptions: "+this.options.requestManager.provider.constructor.name);return this.callback(o,null,this),this.emit("error",o),this}return this.id&&this.unsubscribe(),this.options.params=n.params[1],"logs"===n.params[0]&&r.isObject(n.params[1])&&n.params[1].hasOwnProperty("fromBlock")&&isFinite(n.params[1].fromBlock)&&this.options.requestManager.send({method:"eth_getLogs",params:[n.params[1]]},function(t,n){t?(e.callback(t,null,e),e.emit("error",t)):n.forEach(function(t){var n=e._formatOutput(t);e.callback(null,n,e),e.emit("data",n)})}),"object"===_typeof(n.params[1])&&delete n.params[1].fromBlock,this.options.requestManager.send(n,function(t,i){!t&&i?(e.id=i,e.options.requestManager.addSubscription(e.id,n.params[0],e.options.type,function(t,n){r.isArray(n)&&(n=n[0]);var i=e._formatOutput(n);if(t)e.options.requestManager.removeSubscription(e.id),e.options.requestManager.provider.once&&(e._reconnectIntervalId=setInterval(function(){e.options.requestManager.provider.reconnect()},500),e.options.requestManager.provider.once("connect",function(){clearInterval(e._reconnectIntervalId),e.subscribe(e.callback)})),e.emit("error",t);else{if(r.isFunction(e.options.subscription.subscriptionHandler))return e.options.subscription.subscriptionHandler.call(e,i);e.emit("data",i)}r.isFunction(e.callback)&&e.callback(t,i,e)})):r.isFunction(e.callback)&&(e.callback(t,null,e),e.emit("error",t))}),this},t.exports=i},{eventemitter3:197,underscore:198,"web3-core-helpers":186}],201:[function(e,t,n){var i=e("web3-core-helpers").formatters,r=e("web3-core-method"),o=e("web3-utils");t.exports=function(e){var t=function(t){var n;return t.property?(e[t.property]||(e[t.property]={}),n=e[t.property]):n=e,t.methods&&t.methods.forEach(function(t){t instanceof r||(t=new r(t)),t.attachToObject(n),t.setRequestManager(e._requestManager)}),e};return t.formatters=i,t.utils=o,t.Method=r,t}},{"web3-core-helpers":186,"web3-core-method":188,"web3-utils":273}],202:[function(e,t,n){var i=e("web3-core-requestmanager"),r=e("./extend.js");t.exports={packageInit:function(e,t){if(t=Array.prototype.slice.call(t),!e)throw new Error('You need to instantiate using the "new" keyword.');Object.defineProperty(e,"currentProvider",{get:function(){return e._provider},set:function(t){return e.setProvider(t)},enumerable:!0,configurable:!0}),t[0]&&t[0]._requestManager?e._requestManager=new i.Manager(t[0].currentProvider):(e._requestManager=new i.Manager,e._requestManager.setProvider(t[0],t[1])),e.givenProvider=i.Manager.givenProvider,e.providers=i.Manager.providers,e._provider=e._requestManager.provider,e.setProvider||(e.setProvider=function(t,n){return e._requestManager.setProvider(t,n),e._provider=e._requestManager.provider,!0}),e.BatchRequest=i.BatchManager.bind(null,e._requestManager),e.extend=r(e)},addProviders:function(e){e.givenProvider=i.Manager.givenProvider,e.providers=i.Manager.providers}}},{"./extend.js":201,"web3-core-requestmanager":195}],203:[function(e,t,n){arguments[4][172][0].apply(n,arguments)},{dup:172}],204:[function(e,t,n){var i=e("underscore"),r=e("web3-utils"),o=e("bn.js"),a=e("./param"),s=function(e){return i.isNumber(e)&&(e=Math.trunc(e)),new a(r.toTwosComplement(e).replace("0x",""))},c=function(e){return"1"===new o(e.substr(0,1),16).toString(2).substr(0,1)};t.exports={formatInputInt:s,formatInputBytes:function(e){if(!r.isHex(e))throw new Error('Given parameter is not bytes: "'+e+'"');var t=e.replace(/^0x/i,"");if(t.length%2!=0)throw new Error('Given parameter bytes has an invalid length: "'+e+'"');var n=Math.floor((t.length+63)/64);return t=r.padRight(t,64*n),new a(t)},formatInputDynamicBytes:function(e){if(!r.isHex(e))throw new Error('Given parameter is not bytes: "'+e+'"');var t=e.replace(/^0x/i,"");if(t.length%2!=0)throw new Error('Given parameter bytes has an invalid length: "'+e+'"');var n=t.length/2,i=Math.floor((t.length+63)/64);return t=r.padRight(t,64*i),new a(s(n).value+t)},formatInputString:function(e){var t=r.utf8ToHex(e).replace(/^0x/i,""),n=t.length/2,i=Math.floor((t.length+63)/64);return t=r.padRight(t,64*i),new a(s(n).value+t)},formatInputBool:function(e){return new a("000000000000000000000000000000000000000000000000000000000000000"+(e?"1":"0"))},formatOutputInt:function(e){var t=e.staticPart()||"0";return c(t)?new o(t,16).fromTwos(256).toString(10):new o(t,16).toString(10)},formatOutputUInt:function(e,t){var n=e.staticPart();if(!n)throw new Error("Couldn't decode "+t+" from ABI: 0x"+e.rawValue);return new o(n,16).toString(10)},formatOutputBool:function(e,t){var n=e.staticPart();if(!n)throw new Error("Couldn't decode "+t+" from ABI: 0x"+e.rawValue);return"0000000000000000000000000000000000000000000000000000000000000001"===n},formatOutputBytes:function(e,t){var n=t.match(/^bytes([0-9]*)/),i=parseInt(n[1]);if(e.staticPart().slice(0,2*i).length!==2*i)throw new Error("Couldn't decode "+t+" from ABI: 0x"+e.rawValue+" The size doesn't match.");return"0x"+e.staticPart().slice(0,2*i)},formatOutputDynamicBytes:function(e){var t=2*new o(e.dynamicPart().slice(0,64),16).toNumber();return"0x"+e.dynamicPart().substr(64,t)},formatOutputString:function(e){var t=e.dynamicPart().slice(0,64);if(t){var n=2*new o(t,16).toNumber();return n?r.hexToUtf8("0x"+e.dynamicPart().substr(64,n).replace(/^0x/i,"")):""}throw new Error("ERROR: The returned value is not a convertible string:"+t)},formatOutputAddress:function(e){var t=e.staticPart();return r.toChecksumAddress("0x"+t.slice(t.length-40,t.length))},toTwosComplement:r.toTwosComplement}},{"./param":206,"bn.js":"BN",underscore:203,"web3-utils":273}],205:[function(e,t,n){function i(){}var r=e("underscore"),o=e("web3-utils"),a=e("./formatters"),s=e("./types/address"),c=e("./types/bool"),u=e("./types/int"),l=e("./types/uint"),f=e("./types/dynamicbytes"),p=e("./types/string"),d=e("./types/bytes"),h=function(e,t){return e.isDynamicType(t)||e.isDynamicArray(t)},m=function(e){this._types=e};m.prototype._requireType=function(e){var t=this._types.filter(function(t){return t.isType(e)})[0];if(!t)throw Error("Invalid solidity type: "+e);return t},m.prototype._getOffsets=function(e,t){for(var n=t.map(function(t,n){return t.staticPartLength(e[n])}),i=1;i0;){var t=e.shift();if("function"==typeof t){var n=e.shift(),i=e.shift();t.call(n,i)}else t._settlePromises()}},r.prototype._drainQueues=function(){this._drainQueue(this._normalQueue),this._reset(),this._haveDrainedQueues=!0,this._drainQueue(this._lateQueue)},r.prototype._queueTick=function(){this._isTickUsed||(this._isTickUsed=!0,this._schedule(this.drainQueues))},r.prototype._reset=function(){this._isTickUsed=!1},n.exports=r,n.exports.firstLineError=c},{"./queue":26,"./schedule":29,"./util":36}],3:[function(e,t,n){t.exports=function(e,t,n,i){var r=!1,o=function(e,t){this._reject(t)},a=function(e,t){t.promiseRejectionQueued=!0,t.bindingPromise._then(o,o,null,this,e)},s=function(e,t){0==(50397184&this._bitField)&&this._resolveCallback(t.target)},c=function(e,t){t.promiseRejectionQueued||this._reject(e)};e.prototype.bind=function(o){r||(r=!0,e.prototype._propagateFrom=i.propagateFromFunction(),e.prototype._boundValue=i.boundValueFunction());var u=n(o),l=new e(t);l._propagateFrom(this,1);var f=this._target();if(l._setBoundTo(u),u instanceof e){var p={promiseRejectionQueued:!1,promise:l,target:f,bindingPromise:u};f._then(t,a,void 0,l,p),u._then(s,c,void 0,l,p),l._setOnCancel(u)}else l._resolveCallback(f);return l},e.prototype._setBoundTo=function(e){void 0!==e?(this._bitField=2097152|this._bitField,this._boundTo=e):this._bitField=-2097153&this._bitField},e.prototype._isBound=function(){return 2097152==(2097152&this._bitField)},e.bind=function(t,n){return e.resolve(n).bind(t)}}},{}],4:[function(e,t,n){var i;"undefined"!=typeof Promise&&(i=Promise);var r=e("./promise")();r.noConflict=function(){try{Promise===r&&(Promise=i)}catch(e){}return r},t.exports=r},{"./promise":22}],5:[function(e,t,n){var i=Object.create;if(i){var r=i(null),o=i(null);r[" size"]=o[" size"]=0}t.exports=function(t){function n(e,n){var i;if(null!=e&&(i=e[n]),"function"!=typeof i){var r="Object "+s.classString(e)+" has no method '"+s.toString(n)+"'";throw new t.TypeError(r)}return i}function i(e){return n(e,this.pop()).apply(e,this)}function r(e){return e[this]}function o(e){var t=+this;return t<0&&(t=Math.max(0,t+e.length)),e[t]}var a,s=e("./util"),c=s.canEvaluate;s.isIdentifier;t.prototype.call=function(e){var t=[].slice.call(arguments,1);return t.push(e),this._then(i,void 0,void 0,t,void 0)},t.prototype.get=function(e){var t;if("number"==typeof e)t=o;else if(c){var n=a(e);t=null!==n?n:r}else t=r;return this._then(t,void 0,void 0,e,void 0)}}},{"./util":36}],6:[function(e,t,n){t.exports=function(t,n,i,r){var o=e("./util"),a=o.tryCatch,s=o.errorObj,c=t._async;t.prototype.break=t.prototype.cancel=function(){if(!r.cancellation())return this._warn("cancellation is disabled");for(var e=this,t=e;e.isCancellable();){if(!e._cancelBy(t)){t._isFollowing()?t._followee().cancel():t._cancelBranched();break}var n=e._cancellationParent;if(null==n||!n.isCancellable()){e._isFollowing()?e._followee().cancel():e._cancelBranched();break}e._isFollowing()&&e._followee().cancel(),t=e,e=n}},t.prototype._branchHasCancelled=function(){this._branchesRemainingToCancel--},t.prototype._enoughBranchesHaveCancelled=function(){return void 0===this._branchesRemainingToCancel||this._branchesRemainingToCancel<=0},t.prototype._cancelBy=function(e){return e===this?(this._branchesRemainingToCancel=0,this._invokeOnCancel(),!0):(this._branchHasCancelled(),!!this._enoughBranchesHaveCancelled()&&(this._invokeOnCancel(),!0))},t.prototype._cancelBranched=function(){this._enoughBranchesHaveCancelled()&&this._cancel()},t.prototype._cancel=function(){this.isCancellable()&&(this._setCancelled(),c.invoke(this._cancelPromises,this,void 0))},t.prototype._cancelPromises=function(){this._length()>0&&this._settlePromises()},t.prototype._unsetOnCancel=function(){this._onCancelField=void 0},t.prototype.isCancellable=function(){return this.isPending()&&!this.isCancelled()},t.prototype._doInvokeOnCancel=function(e,t){if(o.isArray(e))for(var n=0;n=0)return r[e]}var i=!1,r=[];return e.prototype._promiseCreated=function(){},e.prototype._pushContext=function(){},e.prototype._popContext=function(){return null},e._peekContext=e.prototype._peekContext=function(){},t.prototype._pushContext=function(){void 0!==this._trace&&(this._trace._promiseCreated=null,r.push(this._trace))},t.prototype._popContext=function(){if(void 0!==this._trace){var e=r.pop(),t=e._promiseCreated;return e._promiseCreated=null,t}return null},t.CapturedTrace=null,t.create=function(){if(i)return new t},t.deactivateLongStackTraces=function(){},t.activateLongStackTraces=function(){var r=e.prototype._pushContext,o=e.prototype._popContext,a=e._peekContext,s=e.prototype._peekContext,c=e.prototype._promiseCreated;t.deactivateLongStackTraces=function(){e.prototype._pushContext=r,e.prototype._popContext=o,e._peekContext=a,e.prototype._peekContext=s,e.prototype._promiseCreated=c,i=!1},i=!0,e.prototype._pushContext=t.prototype._pushContext,e.prototype._popContext=t.prototype._popContext,e._peekContext=e.prototype._peekContext=n,e.prototype._promiseCreated=function(){var e=this._peekContext();e&&null==e._promiseCreated&&(e._promiseCreated=this)}},t}},{}],9:[function(t,n,i){n.exports=function(n,i){function r(e,t){return{promise:t}}function o(){return!1}function a(e,t,n){var i=this;try{e(t,n,function(e){if("function"!=typeof e)throw new TypeError("onCancel must be a function, got: "+R.toString(e));i._attachCancellationCallback(e)})}catch(e){return e}}function s(e){if(!this.isCancellable())return this;var t=this._onCancel();void 0!==t?R.isArray(t)?t.push(e):this._setOnCancel([t,e]):this._setOnCancel(e)}function c(){return this._onCancelField}function u(e){this._onCancelField=e}function l(){this._cancellationParent=void 0,this._onCancelField=void 0}function f(e,t){if(0!=(1&t)){this._cancellationParent=e;var n=e._branchesRemainingToCancel;void 0===n&&(n=0),e._branchesRemainingToCancel=n+1}0!=(2&t)&&e._isBound()&&this._setBoundTo(e._boundTo)}function p(){var e=this._boundTo;return void 0!==e&&e instanceof n?e.isFulfilled()?e.value():void 0:e}function d(){this._trace=new C(this._peekContext())}function h(e,t){if(O(e)){var n=this._trace;if(void 0!==n&&t&&(n=n._parent),void 0!==n)n.attachExtraTrace(e);else if(!e.__stackCleaned__){var i=x(e);R.notEnumerableProp(e,"stack",i.message+"\n"+i.stack.join("\n")),R.notEnumerableProp(e,"__stackCleaned__",!0)}}}function m(e,t,i){if(ee.warnings){var r,o=new B(e);if(t)i._attachExtraTrace(o);else if(ee.longStackTraces&&(r=n._peekContext()))r.attachExtraTrace(o);else{var a=x(o);o.stack=a.message+"\n"+a.stack.join("\n")}$("warning",o)||w(o,"",!0)}}function v(e,t){for(var n=0;n=0;--s)if(i[s]===o){a=s;break}for(s=a;s>=0;--s){var c=i[s];if(t[r]!==c)break;t.pop(),r--}t=i}}function g(e){for(var t=[],n=0;n0&&(t=t.slice(n)),t}function x(e){var t=e.stack,n=e.toString();return t="string"==typeof t&&t.length>0?_(e):[" (No stack trace)"],{message:n,stack:g(t)}}function w(e,t,n){if("undefined"!=typeof console){var i;if(R.isObject(e)){var r=e.stack;i=t+L(r,e)}else i=t+String(e);"function"==typeof P?P(i,n):"function"!=typeof console.log&&"object"!==_typeof(console.log)||console.log(i)}}function k(e,t,n,i){var r=!1;try{"function"==typeof t&&(r=!0,"rejectionHandled"===e?t(i):t(n,i))}catch(e){I.throwLater(e)}"unhandledRejection"===e?$(e,n,i)||r||w(n,"Unhandled rejection "):$(e,i)}function j(e){var t;if("function"==typeof e)t="[function "+(e.name||"anonymous")+"]";else{if(t=e&&"function"==typeof e.toString?e.toString():R.toString(e),/\[object [a-zA-Z0-9$_]+\]/.test(t))try{t=JSON.stringify(e)}catch(e){}0===t.length&&(t="(empty array)")}return"(<"+S(t)+">, no stack trace)"}function S(e){return e.length<41?e:e.substr(0,38)+"..."}function E(){return"function"==typeof Z}function A(e){var t=e.match(Y);if(t)return{fileName:t[1],line:parseInt(t[2],10)}}function C(e){this._parent=e,this._promisesCreated=0;var t=this._length=1+(void 0===e?0:e._length);Z(this,C),t>32&&this.uncycle()}var M,T,P,F=n._getDomain,I=n._async,B=t("./errors").Warning,R=t("./util"),O=R.canAttachTrace,N=/[\\\/]bluebird[\\\/]js[\\\/](release|debug|instrumented)/,D=null,L=null,q=!1,z=!(0==R.env("BLUEBIRD_DEBUG")),U=!(0==R.env("BLUEBIRD_WARNINGS")||!z&&!R.env("BLUEBIRD_WARNINGS")),H=!(0==R.env("BLUEBIRD_LONG_STACK_TRACES")||!z&&!R.env("BLUEBIRD_LONG_STACK_TRACES")),V=0!=R.env("BLUEBIRD_W_FORGOTTEN_RETURN")&&(U||!!R.env("BLUEBIRD_W_FORGOTTEN_RETURN"));n.prototype.suppressUnhandledRejections=function(){var e=this._target();e._bitField=-1048577&e._bitField|524288},n.prototype._ensurePossibleRejectionHandled=function(){0==(524288&this._bitField)&&(this._setRejectionIsUnhandled(),I.invokeLater(this._notifyUnhandledRejection,this,void 0))},n.prototype._notifyUnhandledRejectionIsHandled=function(){k("rejectionHandled",M,void 0,this)},n.prototype._setReturnedNonUndefined=function(){this._bitField=268435456|this._bitField},n.prototype._returnedNonUndefined=function(){return 0!=(268435456&this._bitField)},n.prototype._notifyUnhandledRejection=function(){if(this._isRejectionUnhandled()){var e=this._settledValue();this._setUnhandledRejectionIsNotified(),k("unhandledRejection",T,e,this)}},n.prototype._setUnhandledRejectionIsNotified=function(){this._bitField=262144|this._bitField},n.prototype._unsetUnhandledRejectionIsNotified=function(){this._bitField=-262145&this._bitField},n.prototype._isUnhandledRejectionNotified=function(){return(262144&this._bitField)>0},n.prototype._setRejectionIsUnhandled=function(){this._bitField=1048576|this._bitField},n.prototype._unsetRejectionIsUnhandled=function(){this._bitField=-1048577&this._bitField,this._isUnhandledRejectionNotified()&&(this._unsetUnhandledRejectionIsNotified(),this._notifyUnhandledRejectionIsHandled())},n.prototype._isRejectionUnhandled=function(){return(1048576&this._bitField)>0},n.prototype._warn=function(e,t,n){return m(e,t,n||this)},n.onPossiblyUnhandledRejection=function(e){var t=F();T="function"==typeof e?null===t?e:t.bind(e):void 0},n.onUnhandledRejectionHandled=function(e){var t=F();M="function"==typeof e?null===t?e:t.bind(e):void 0};var K=function(){};n.longStackTraces=function(){if(I.haveItemsQueued()&&!ee.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");if(!ee.longStackTraces&&E()){var e=n.prototype._captureStackTrace,t=n.prototype._attachExtraTrace;ee.longStackTraces=!0,K=function(){if(I.haveItemsQueued()&&!ee.longStackTraces)throw new Error("cannot enable long stack traces after promises have been created\n\n See http://goo.gl/MqrFmX\n");n.prototype._captureStackTrace=e,n.prototype._attachExtraTrace=t,i.deactivateLongStackTraces(),I.enableTrampoline(),ee.longStackTraces=!1},n.prototype._captureStackTrace=d,n.prototype._attachExtraTrace=h,i.activateLongStackTraces(),I.disableTrampolineIfNecessary()}},n.hasLongStackTraces=function(){return ee.longStackTraces&&E()};var W=function(){try{var e=document.createEvent("CustomEvent");return e.initCustomEvent("testingtheevent",!1,!0,{}),R.global.dispatchEvent(e),function(e,t){var n=document.createEvent("CustomEvent");return n.initCustomEvent(e.toLowerCase(),!1,!0,t),!R.global.dispatchEvent(n)}}catch(e){}return function(){return!1}}(),X=R.isNode?function(){return e.emit.apply(e,arguments)}:R.global?function(e){var t="on"+e.toLowerCase(),n=R.global[t];return!!n&&(n.apply(R.global,[].slice.call(arguments,1)),!0)}:function(){return!1},G={promiseCreated:r,promiseFulfilled:r,promiseRejected:r,promiseResolved:r,promiseCancelled:r,promiseChained:function(e,t,n){return{promise:t,child:n}},warning:function(e,t){return{warning:t}},unhandledRejection:function(e,t,n){return{reason:t,promise:n}},rejectionHandled:r},$=function(e){var t=!1;try{t=X.apply(null,arguments)}catch(e){I.throwLater(e),t=!0}var n=!1;try{n=W(e,G[e].apply(null,arguments))}catch(e){I.throwLater(e),n=!0}return n||t};n.config=function(e){if("longStackTraces"in(e=Object(e))&&(e.longStackTraces?n.longStackTraces():!e.longStackTraces&&n.hasLongStackTraces()&&K()),"warnings"in e){var t=e.warnings;ee.warnings=!!t,V=ee.warnings,R.isObject(t)&&"wForgottenReturn"in t&&(V=!!t.wForgottenReturn)}if("cancellation"in e&&e.cancellation&&!ee.cancellation){if(I.haveItemsQueued())throw new Error("cannot enable cancellation after promises are in use");n.prototype._clearCancellationData=l,n.prototype._propagateFrom=f,n.prototype._onCancel=c,n.prototype._setOnCancel=u,n.prototype._attachCancellationCallback=s,n.prototype._execute=a,J=f,ee.cancellation=!0}"monitoring"in e&&(e.monitoring&&!ee.monitoring?(ee.monitoring=!0,n.prototype._fireEvent=$):!e.monitoring&&ee.monitoring&&(ee.monitoring=!1,n.prototype._fireEvent=o))},n.prototype._fireEvent=o,n.prototype._execute=function(e,t,n){try{e(t,n)}catch(e){return e}},n.prototype._onCancel=function(){},n.prototype._setOnCancel=function(e){},n.prototype._attachCancellationCallback=function(e){},n.prototype._captureStackTrace=function(){},n.prototype._attachExtraTrace=function(){},n.prototype._clearCancellationData=function(){},n.prototype._propagateFrom=function(e,t){};var J=function(e,t){0!=(2&t)&&e._isBound()&&this._setBoundTo(e._boundTo)},Q=function(){return!1},Y=/[\/<\(]([^:\/]+):(\d+):(?:\d+)\)?\s*$/;R.inherits(C,Error),i.CapturedTrace=C,C.prototype.uncycle=function(){var e=this._length;if(!(e<2)){for(var t=[],n={},i=0,r=this;void 0!==r;++i)t.push(r),r=r._parent;for(i=(e=this._length=i)-1;i>=0;--i){var o=t[i].stack;void 0===n[o]&&(n[o]=i)}for(i=0;i0&&(t[a-1]._parent=void 0,t[a-1]._length=1),t[i]._parent=void 0,t[i]._length=1;var s=i>0?t[i-1]:this;a=0;--u)t[u]._length=c,c++;return}}}},C.prototype.attachExtraTrace=function(e){if(!e.__stackCleaned__){this.uncycle();for(var t=x(e),n=t.message,i=[t.stack],r=this;void 0!==r;)i.push(g(r.stack.split("\n"))),r=r._parent;y(i),b(i),R.notEnumerableProp(e,"stack",v(n,i)),R.notEnumerableProp(e,"__stackCleaned__",!0)}};var Z=function(){var e=/^\s*at\s*/,t=function(e,t){return"string"==typeof e?e:void 0!==t.name&&void 0!==t.message?t.toString():j(t)};if("number"==typeof Error.stackTraceLimit&&"function"==typeof Error.captureStackTrace){Error.stackTraceLimit+=6,D=e,L=t;var n=Error.captureStackTrace;return Q=function(e){return N.test(e)},function(e,t){Error.stackTraceLimit+=6,n(e,t),Error.stackTraceLimit-=6}}var i=new Error;if("string"==typeof i.stack&&i.stack.split("\n")[0].indexOf("stackDetection@")>=0)return D=/@/,L=t,q=!0,function(e){e.stack=(new Error).stack};var r;try{throw new Error}catch(e){r="stack"in e}return"stack"in i||!r||"number"!=typeof Error.stackTraceLimit?(L=function(e,t){return"string"==typeof e?e:"object"!==(void 0===t?"undefined":_typeof(t))&&"function"!=typeof t||void 0===t.name||void 0===t.message?j(t):t.toString()},null):(D=e,L=t,function(e){Error.stackTraceLimit+=6;try{throw new Error}catch(t){e.stack=t.stack}Error.stackTraceLimit-=6})}();"undefined"!=typeof console&&void 0!==console.warn&&(P=function(e){console.warn(e)},R.isNode&&e.stderr.isTTY?P=function(e,t){var n=t?"":"";console.warn(n+e+"\n")}:R.isNode||"string"!=typeof(new Error).stack||(P=function(e,t){console.warn("%c"+e,t?"color: darkorange":"color: red")}));var ee={warnings:U,longStackTraces:!1,cancellation:!1,monitoring:!1};return H&&n.longStackTraces(),{longStackTraces:function(){return ee.longStackTraces},warnings:function(){return ee.warnings},cancellation:function(){return ee.cancellation},monitoring:function(){return ee.monitoring},propagateFromFunction:function(){return J},boundValueFunction:function(){return p},checkForgottenReturns:function(e,t,n,i,r){if(void 0===e&&null!==t&&V){if(void 0!==r&&r._returnedNonUndefined())return;n&&(n+=" ");var o="a promise was created in a "+n+"handler but was not returned from it";i._warn(o,!0,t)}},setBounds:function(e,t){if(E()){for(var n,i,r=e.stack.split("\n"),o=t.stack.split("\n"),a=-1,s=-1,c=0;c=s||(Q=function(e){if(N.test(e))return!0;var t=A(e);return!!(t&&t.fileName===n&&a<=t.line&&t.line<=s)})}},warn:m,deprecated:function(e,t){var n=e+" is deprecated and will be removed in a future version.";return t&&(n+=" Use "+t+" instead."),m(n)},CapturedTrace:C,fireDomEvent:W,fireGlobalEvent:X}}},{"./errors":12,"./util":36}],10:[function(e,t,n){t.exports=function(e){function t(){return this.value}function n(){throw this.reason}e.prototype.return=e.prototype.thenReturn=function(n){return n instanceof e&&n.suppressUnhandledRejections(),this._then(t,void 0,void 0,{value:n},void 0)},e.prototype.throw=e.prototype.thenThrow=function(e){return this._then(n,void 0,void 0,{reason:e},void 0)},e.prototype.catchThrow=function(e){if(arguments.length<=1)return this._then(void 0,n,void 0,{reason:e},void 0);var t=arguments[1];return this.caught(e,function(){throw t})},e.prototype.catchReturn=function(n){if(arguments.length<=1)return n instanceof e&&n.suppressUnhandledRejections(),this._then(void 0,t,void 0,{value:n},void 0);var i=arguments[1];i instanceof e&&i.suppressUnhandledRejections();return this.caught(n,function(){return i})}}},{}],11:[function(e,t,n){t.exports=function(e,t){function n(){return o(this)}function i(e,n){return r(e,n,t,t)}var r=e.reduce,o=e.all;e.prototype.each=function(e){return this.mapSeries(e)._then(n,void 0,void 0,this,void 0)},e.prototype.mapSeries=function(e){return r(this,e,t,t)},e.each=function(e,t){return i(e,t)._then(n,void 0,void 0,e,void 0)},e.mapSeries=i}},{}],12:[function(e,t,n){function i(e,t){function n(i){if(!(this instanceof n))return new n(i);f(this,"message","string"==typeof i?i:t),f(this,"name",e),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):Error.call(this)}return l(n,Error),n}function r(e){if(!(this instanceof r))return new r(e);f(this,"name","OperationalError"),f(this,"message",e),this.cause=e,this.isOperational=!0,e instanceof Error?(f(this,"message",e.message),f(this,"stack",e.stack)):Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}var o,a,s=e("./es5"),c=s.freeze,u=e("./util"),l=u.inherits,f=u.notEnumerableProp,p=i("Warning","warning"),d=i("CancellationError","cancellation error"),h=i("TimeoutError","timeout error"),m=i("AggregateError","aggregate error");try{o=TypeError,a=RangeError}catch(e){o=i("TypeError","type error"),a=i("RangeError","range error")}for(var v="join pop push shift unshift slice filter forEach some every map indexOf lastIndexOf reduce reduceRight sort reverse".split(" "),b=0;b1?e.cancelPromise._reject(t):e.cancelPromise._cancel(),e.cancelPromise=null,!0)}function a(){return c.call(this,this.promise._target()._settledValue())}function s(e){if(!o(this,e))return f.e=e,f}function c(e){var i=this.promise,c=this.handler;if(!this.called){this.called=!0;var u=this.isFinallyHandler()?c.call(i._boundValue()):c.call(i._boundValue(),e);if(void 0!==u){i._setReturnedNonUndefined();var p=n(u,i);if(p instanceof t){if(null!=this.cancelPromise){if(p.isCancelled()){var d=new l("late cancellation observer");return i._attachExtraTrace(d),f.e=d,f}p.isPending()&&p._attachCancellationCallback(new r(this))}return p._then(a,s,void 0,this,void 0)}}}return i.isRejected()?(o(this),f.e=e,f):(o(this),e)}var u=e("./util"),l=t.CancellationError,f=u.errorObj;return i.prototype.isFinallyHandler=function(){return 0===this.type},r.prototype._resultCancelled=function(){o(this.finallyHandler)},t.prototype._passThrough=function(e,t,n,r){return"function"!=typeof e?this.then():this._then(n,r,void 0,new i(this,t,e),void 0)},t.prototype.lastly=t.prototype.finally=function(e){return this._passThrough(e,0,c,c)},t.prototype.tap=function(e){return this._passThrough(e,1,c)},i}},{"./util":36}],16:[function(e,t,n){t.exports=function(t,n,i,r,o,a){function s(e,n,i){for(var o=0;o0&&"function"==typeof arguments[t]){e=arguments[t]}var i=[].slice.call(arguments);e&&i.pop();var r=new n(i).promise();return void 0!==e?r.spread(e):r}}},{"./util":36}],18:[function(e,t,n){t.exports=function(t,n,i,r,o,a){function s(e,t,n,i){this.constructor$(e),this._promise._captureStackTrace();var r=u();this._callback=null===r?t:r.bind(t),this._preservedValues=i===o?new Array(this.length()):null,this._limit=n,this._inFlight=0,this._queue=n>=1?[]:d,this._init$(void 0,-2)}function c(e,t,n,r){if("function"!=typeof t)return i("expecting a function but got "+l.classString(t));var o="object"===(void 0===n?"undefined":_typeof(n))&&null!==n?n.concurrency:0;return o="number"==typeof o&&isFinite(o)&&o>=1?o:0,new s(e,t,o,r).promise()}var u=t._getDomain,l=e("./util"),f=l.tryCatch,p=l.errorObj,d=[];l.inherits(s,n),s.prototype._init=function(){},s.prototype._promiseFulfilled=function(e,n){var i=this._values,o=this.length(),s=this._preservedValues,c=this._limit;if(n<0){if(n=-1*n-1,i[n]=e,c>=1&&(this._inFlight--,this._drainQueue(),this._isResolved()))return!0}else{if(c>=1&&this._inFlight>=c)return i[n]=e,this._queue.push(n),!1;null!==s&&(s[n]=e);var u=this._promise,l=this._callback,d=u._boundValue();u._pushContext();var h=f(l).call(d,e,n,o),m=u._popContext();if(a.checkForgottenReturns(h,m,null!==s?"Promise.filter":"Promise.map",u),h===p)return this._reject(h.e),!0;var v=r(h,this._promise);if(v instanceof t){var b=(v=v._target())._bitField;if(0==(50397184&b))return c>=1&&this._inFlight++,i[n]=v,v._proxy(this,-1*(n+1)),!1;if(0==(33554432&b))return 0!=(16777216&b)?(this._reject(v._reason()),!0):(this._cancel(),!0);h=v._value()}i[n]=h}return++this._totalResolved>=o&&(null!==s?this._filter(i,s):this._resolve(i),!0)},s.prototype._drainQueue=function(){for(var e=this._queue,t=this._limit,n=this._values;e.length>0&&this._inFlight1){o.deprecated("calling Promise.try with more than 1 argument");var u=arguments[1],l=arguments[2];c=a.isArray(u)?s(e).apply(l,u):s(e).call(l,u)}else c=s(e)();var f=i._popContext();return o.checkForgottenReturns(c,f,"Promise.try",i),i._resolveFromSyncValue(c),i},t.prototype._resolveFromSyncValue=function(e){e===a.errorObj?this._rejectCallback(e.e,!1):this._resolveCallback(e,!0)}}},{"./util":36}],20:[function(e,t,n){function i(e){return e instanceof Error&&c.getPrototypeOf(e)===Error.prototype}function r(e){var t;if(i(e)){(t=new s(e)).name=e.name,t.message=e.message,t.stack=e.stack;for(var n=c.keys(e),r=0;r1){var n,i=new Array(t-1),r=0;for(n=0;n0&&"function"!=typeof e&&"function"!=typeof t){var n=".then() only accepts functions but was passed: "+d.classString(e);arguments.length>1&&(n+=", "+d.classString(t)),this._warn(n)}return this._then(e,t,void 0,void 0,void 0)},r.prototype.done=function(e,t){this._then(e,t,void 0,void 0,void 0)._setIsFinal()},r.prototype.spread=function(e){return"function"!=typeof e?f("expecting a function but got "+d.classString(e)):this.all()._then(e,void 0,void 0,x,void 0)},r.prototype.toJSON=function(){var e={isFulfilled:!1,isRejected:!1,fulfillmentValue:void 0,rejectionReason:void 0};return this.isFulfilled()?(e.fulfillmentValue=this.value(),e.isFulfilled=!0):this.isRejected()&&(e.rejectionReason=this.reason(),e.isRejected=!0),e},r.prototype.all=function(){return arguments.length>0&&this._warn(".all() was passed arguments but it does not take any"),new j(this).promise()},r.prototype.error=function(e){return this.caught(d.originatesFromRejection,e)},r.is=function(e){return e instanceof r},r.fromNode=r.fromCallback=function(e){var t=new r(_);t._captureStackTrace();var n=arguments.length>1&&!!Object(arguments[1]).multiArgs,i=F(e)(T(t,n));return i===P&&t._rejectCallback(i.e,!0),t._isFateSealed()||t._setAsyncGuaranteed(),t},r.all=function(e){return new j(e).promise()},r.cast=function(e){var t=k(e);return t instanceof r||((t=new r(_))._captureStackTrace(),t._setFulfilled(),t._rejectionHandler0=e),t},r.resolve=r.fulfilled=r.cast,r.reject=r.rejected=function(e){var t=new r(_);return t._captureStackTrace(),t._rejectCallback(e,!0),t},r.setScheduler=function(e){if("function"!=typeof e)throw new y("expecting a function but got "+d.classString(e));var t=v._schedule;return v._schedule=e,t},r.prototype._then=function(e,t,n,i,o){var a=void 0!==o,s=a?o:new r(_),u=this._target(),l=u._bitField;a||(s._propagateFrom(this,3),s._captureStackTrace(),void 0===i&&0!=(2097152&this._bitField)&&(i=0!=(50397184&l)?this._boundValue():u===this?void 0:this._boundTo),this._fireEvent("promiseChained",this,s));var f=c();if(0!=(50397184&l)){var p,d,h=u._settlePromiseCtx;0!=(33554432&l)?(d=u._rejectionHandler0,p=e):0!=(16777216&l)?(d=u._fulfillmentHandler0,p=t,u._unsetRejectionIsUnhandled()):(h=u._settlePromiseLateCancellationObserver,d=new g("late cancellation observer"),u._attachExtraTrace(d),p=t),v.invoke(h,u,{handler:null===f?p:"function"==typeof p&&f.bind(p),promise:s,receiver:i,value:d})}else u._addCallbacks(e,t,s,i,f);return s},r.prototype._length=function(){return 65535&this._bitField},r.prototype._isFateSealed=function(){return 0!=(117506048&this._bitField)},r.prototype._isFollowing=function(){return 67108864==(67108864&this._bitField)},r.prototype._setLength=function(e){this._bitField=-65536&this._bitField|65535&e},r.prototype._setFulfilled=function(){this._bitField=33554432|this._bitField,this._fireEvent("promiseFulfilled",this)},r.prototype._setRejected=function(){this._bitField=16777216|this._bitField,this._fireEvent("promiseRejected",this)},r.prototype._setFollowing=function(){this._bitField=67108864|this._bitField,this._fireEvent("promiseResolved",this)},r.prototype._setIsFinal=function(){this._bitField=4194304|this._bitField},r.prototype._isFinal=function(){return(4194304&this._bitField)>0},r.prototype._unsetCancelled=function(){this._bitField=-65537&this._bitField},r.prototype._setCancelled=function(){this._bitField=65536|this._bitField,this._fireEvent("promiseCancelled",this)},r.prototype._setAsyncGuaranteed=function(){this._bitField=134217728|this._bitField},r.prototype._receiverAt=function(e){var t=0===e?this._receiver0:this[4*e-4+3];if(t!==p)return void 0===t&&this._isBound()?this._boundValue():t},r.prototype._promiseAt=function(e){return this[4*e-4+2]},r.prototype._fulfillmentHandlerAt=function(e){return this[4*e-4+0]},r.prototype._rejectionHandlerAt=function(e){return this[4*e-4+1]},r.prototype._boundValue=function(){},r.prototype._migrateCallback0=function(e){e._bitField;var t=e._fulfillmentHandler0,n=e._rejectionHandler0,i=e._promise0,r=e._receiverAt(0);void 0===r&&(r=p),this._addCallbacks(t,n,i,r,null)},r.prototype._migrateCallbackAt=function(e,t){var n=e._fulfillmentHandlerAt(t),i=e._rejectionHandlerAt(t),r=e._promiseAt(t),o=e._receiverAt(t);void 0===o&&(o=p),this._addCallbacks(n,i,r,o,null)},r.prototype._addCallbacks=function(e,t,n,i,r){var o=this._length();if(o>=65531&&(o=0,this._setLength(0)),0===o)this._promise0=n,this._receiver0=i,"function"==typeof e&&(this._fulfillmentHandler0=null===r?e:r.bind(e)),"function"==typeof t&&(this._rejectionHandler0=null===r?t:r.bind(t));else{var a=4*o-4;this[a+2]=n,this[a+3]=i,"function"==typeof e&&(this[a+0]=null===r?e:r.bind(e)),"function"==typeof t&&(this[a+1]=null===r?t:r.bind(t))}return this._setLength(o+1),o},r.prototype._proxy=function(e,t){this._addCallbacks(void 0,void 0,t,e,null)},r.prototype._resolveCallback=function(e,t){if(0==(117506048&this._bitField)){if(e===this)return this._rejectCallback(u(),!1);var n=k(e,this);if(!(n instanceof r))return this._fulfill(e);t&&this._propagateFrom(n,2);var i=n._target(),o=i._bitField;if(0==(50397184&o)){var a=this._length();a>0&&i._migrateCallback0(this);for(var s=1;s>>16)){if(e===this){var n=u();return this._attachExtraTrace(n),this._reject(n)}this._setFulfilled(),this._rejectionHandler0=e,(65535&t)>0&&(0!=(134217728&t)?this._settlePromises():v.settlePromises(this))}},r.prototype._reject=function(e){var t=this._bitField;if(!((117506048&t)>>>16)){if(this._setRejected(),this._fulfillmentHandler0=e,this._isFinal())return v.fatalError(e,d.isNode);(65535&t)>0?0!=(134217728&t)?this._settlePromises():v.settlePromises(this):this._ensurePossibleRejectionHandled()}},r.prototype._fulfillPromises=function(e,t){for(var n=1;n0){if(0!=(16842752&e)){var n=this._fulfillmentHandler0;this._settlePromise0(this._rejectionHandler0,n,e),this._rejectPromises(t,n)}else{var i=this._rejectionHandler0;this._settlePromise0(this._fulfillmentHandler0,i,e),this._fulfillPromises(t,i)}this._setLength(0)}this._clearCancellationData()},r.prototype._settledValue=function(){var e=this._bitField;return 0!=(33554432&e)?this._rejectionHandler0:0!=(16777216&e)?this._fulfillmentHandler0:void 0},r.defer=r.pending=function(){return A.deprecated("Promise.defer","new Promise"),{promise:new r(_),resolve:o,reject:a}},d.notEnumerableProp(r,"_makeSelfResolutionError",u),t("./method")(r,_,k,f,A),t("./bind")(r,_,k,A),t("./cancel")(r,j,f,A),t("./direct_resolve")(r),t("./synchronous_inspection")(r),t("./join")(r,j,k,_,A),r.Promise=r,t("./map.js")(r,j,f,k,_,A),t("./using.js")(r,f,k,E,_,A),t("./timers.js")(r,_,A),t("./generators.js")(r,f,_,k,n,A),t("./nodeify.js")(r),t("./call_get.js")(r),t("./props.js")(r,j,k,f),t("./race.js")(r,_,k,f),t("./reduce.js")(r,j,f,k,_,A),t("./settle.js")(r,j,A),t("./some.js")(r,j,f),t("./promisify.js")(r,_),t("./any.js")(r),t("./each.js")(r,_),t("./filter.js")(r,_),d.toFastProperties(r),d.toFastProperties(r.prototype),s({a:1}),s({b:2}),s({c:3}),s(1),s(function(){}),s(void 0),s(!1),s(new r(_)),A.setBounds(m.firstLineError,d.lastLineError),r}},{"./any.js":1,"./async":2,"./bind":3,"./call_get.js":5,"./cancel":6,"./catch_filter":7,"./context":8,"./debuggability":9,"./direct_resolve":10,"./each.js":11,"./errors":12,"./es5":13,"./filter.js":14,"./finally":15,"./generators.js":16,"./join":17,"./map.js":18,"./method":19,"./nodeback":20,"./nodeify.js":21,"./promise_array":23,"./promisify.js":24,"./props.js":25,"./race.js":27,"./reduce.js":28,"./settle.js":30,"./some.js":31,"./synchronous_inspection":32,"./thenables":33,"./timers.js":34,"./using.js":35,"./util":36}],23:[function(e,t,n){t.exports=function(t,n,i,r,o){function a(e){switch(e){case-2:return[];case-3:return{}}}function s(e){var i=this._promise=new t(n);e instanceof t&&i._propagateFrom(e,3),i._setOnCancel(this),this._values=e,this._length=0,this._totalResolved=0,this._init(void 0,-2)}var c=e("./util");c.isArray;return c.inherits(s,o),s.prototype.length=function(){return this._length},s.prototype.promise=function(){return this._promise},s.prototype._init=function e(n,o){var s=i(this._values,this._promise);if(s instanceof t){var u=(s=s._target())._bitField;if(this._values=s,0==(50397184&u))return this._promise._setAsyncGuaranteed(),s._then(e,this._reject,void 0,this,o);if(0==(33554432&u))return 0!=(16777216&u)?this._reject(s._reason()):this._cancel();s=s._value()}if(null!==(s=c.asArray(s)))0!==s.length?this._iterate(s):-5===o?this._resolveEmptyArray():this._resolve(a(o));else{var l=r("expecting an array or an iterable object but got "+c.classString(s)).reason();this._promise._rejectCallback(l,!1)}},s.prototype._iterate=function(e){var n=this.getActualLength(e.length);this._length=n,this._values=this.shouldCopyValues()?new Array(n):this._values;for(var r=this._promise,o=!1,a=null,s=0;s=this._length&&(this._resolve(this._values),!0)},s.prototype._promiseCancelled=function(){return this._cancel(),!0},s.prototype._promiseRejected=function(e){return this._totalResolved++,this._reject(e),!0},s.prototype._resultCancelled=function(){if(!this._isResolved()){var e=this._values;if(this._cancel(),e instanceof t)e.cancel();else for(var n=0;n=this._length){var n;if(this._isMap)n=p(this._values);else{n={};for(var i=this.length(),r=0,o=this.length();r>1},t.prototype.props=function(){return a(this)},t.props=function(e){return a(e)}}},{"./es5":13,"./util":36}],26:[function(e,t,n){function i(e,t,n,i,r){for(var o=0;o=this._length&&(this._resolve(this._values),!0)},r.prototype._promiseFulfilled=function(e,t){var n=new o;return n._bitField=33554432,n._settledValueField=e,this._promiseResolved(t,n)},r.prototype._promiseRejected=function(e,t){var n=new o;return n._bitField=16777216,n._settledValueField=e,this._promiseResolved(t,n)},t.settle=function(e){return i.deprecated(".settle()",".reflect()"),new r(e).promise()},t.prototype.settle=function(){return t.settle(this)}}},{"./util":36}],31:[function(e,t,n){t.exports=function(t,n,i){function r(e){this.constructor$(e),this._howMany=0,this._unwrap=!1,this._initialized=!1}function o(e,t){if((0|t)!==t||t<0)return i("expecting a positive integer\n\n See http://goo.gl/MqrFmX\n");var n=new r(e),o=n.promise();return n.setHowMany(t),n.init(),o}var a=e("./util"),s=e("./errors").RangeError,c=e("./errors").AggregateError,u=a.isArray,l={};a.inherits(r,n),r.prototype._init=function(){if(this._initialized)if(0!==this._howMany){this._init$(void 0,-5);var e=u(this._values);!this._isResolved()&&e&&this._howMany>this._canPossiblyFulfill()&&this._reject(this._getRangeError(this.length()))}else this._resolve([])},r.prototype.init=function(){this._initialized=!0,this._init()},r.prototype.setUnwrap=function(){this._unwrap=!0},r.prototype.howMany=function(){return this._howMany},r.prototype.setHowMany=function(e){this._howMany=e},r.prototype._promiseFulfilled=function(e){return this._addFulfilled(e),this._fulfilled()===this.howMany()&&(this._values.length=this.howMany(),1===this.howMany()&&this._unwrap?this._resolve(this._values[0]):this._resolve(this._values),!0)},r.prototype._promiseRejected=function(e){return this._addRejected(e),this._checkOutcome()},r.prototype._promiseCancelled=function(){return this._values instanceof t||null==this._values?this._cancel():(this._addRejected(l),this._checkOutcome())},r.prototype._checkOutcome=function(){if(this.howMany()>this._canPossiblyFulfill()){for(var e=new c,t=this.length();t0?this._reject(e):this._cancel(),!0}return!1},r.prototype._fulfilled=function(){return this._totalResolved},r.prototype._rejected=function(){return this._values.length-this.length()},r.prototype._addRejected=function(e){this._values.push(e)},r.prototype._addFulfilled=function(e){this._values[this._totalResolved++]=e},r.prototype._canPossiblyFulfill=function(){return this.length()-this._rejected()},r.prototype._getRangeError=function(e){var t="Input array must contain at least "+this._howMany+" items but contains only "+e+" items";return new s(t)},r.prototype._resolveEmptyArray=function(){this._reject(this._getRangeError(0))},t.some=function(e,t){return o(e,t)},t.prototype.some=function(e){return o(this,e)},t._SomePromiseArray=r}},{"./errors":12,"./util":36}],32:[function(e,t,n){t.exports=function(e){function t(e){void 0!==e?(e=e._target(),this._bitField=e._bitField,this._settledValueField=e._isFateSealed()?e._settledValue():void 0):(this._bitField=0,this._settledValueField=void 0)}t.prototype._settledValue=function(){return this._settledValueField};var n=t.prototype.value=function(){if(!this.isFulfilled())throw new TypeError("cannot get fulfillment value of a non-fulfilled promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},i=t.prototype.error=t.prototype.reason=function(){if(!this.isRejected())throw new TypeError("cannot get rejection reason of a non-rejected promise\n\n See http://goo.gl/MqrFmX\n");return this._settledValue()},r=t.prototype.isFulfilled=function(){return 0!=(33554432&this._bitField)},o=t.prototype.isRejected=function(){return 0!=(16777216&this._bitField)},a=t.prototype.isPending=function(){return 0==(50397184&this._bitField)},s=t.prototype.isResolved=function(){return 0!=(50331648&this._bitField)};t.prototype.isCancelled=e.prototype._isCancelled=function(){return 65536==(65536&this._bitField)},e.prototype.isCancelled=function(){return this._target()._isCancelled()},e.prototype.isPending=function(){return a.call(this._target())},e.prototype.isRejected=function(){return o.call(this._target())},e.prototype.isFulfilled=function(){return r.call(this._target())},e.prototype.isResolved=function(){return s.call(this._target())},e.prototype.value=function(){return n.call(this._target())},e.prototype.reason=function(){var e=this._target();return e._unsetRejectionIsUnhandled(),i.call(e)},e.prototype._value=function(){return this._settledValue()},e.prototype._reason=function(){return this._unsetRejectionIsUnhandled(),this._settledValue()},e.PromiseInspection=t}},{}],33:[function(e,t,n){t.exports=function(t,n){function i(e){return e.then}function r(e){try{return i(e)}catch(e){return c.e=e,c}}function o(e){return l.call(e,"_promise0")}function a(e,i,r){var o=new t(n),a=o;r&&r._pushContext(),o._captureStackTrace(),r&&r._popContext();var u=!0,l=s.tryCatch(i).call(e,function(e){o&&(o._resolveCallback(e),o=null)},function(e){o&&(o._rejectCallback(e,u,!0),o=null)});return u=!1,o&&l===c&&(o._rejectCallback(l.e,!0,!0),o=null),a}var s=e("./util"),c=s.errorObj,u=s.isObject,l={}.hasOwnProperty;return function(e,i){if(u(e)){if(e instanceof t)return e;var s=r(e);if(s===c)return i&&i._pushContext(),l=t.reject(s.e),i&&i._popContext(),l;if("function"==typeof s){if(o(e)){var l=new t(n);return e._then(l._fulfill,l._reject,void 0,l,null),l}return a(e,s,i)}}return e}}},{"./util":36}],34:[function(e,t,n){t.exports=function(t,n,i){function r(e){this.handle=e}function o(e){return clearTimeout(this.handle),e}function a(e){throw clearTimeout(this.handle),e}var s=e("./util"),c=t.TimeoutError;r.prototype._resultCancelled=function(){clearTimeout(this.handle)};var u=function(e){return l(+this).thenReturn(e)},l=t.delay=function(e,o){var a,s;return void 0!==o?(a=t.resolve(o)._then(u,null,null,e,void 0),i.cancellation()&&o instanceof t&&a._setOnCancel(o)):(a=new t(n),s=setTimeout(function(){a._fulfill()},+e),i.cancellation()&&a._setOnCancel(new r(s))),a._setAsyncGuaranteed(),a};t.prototype.delay=function(e){return l(e,this)};var f=function(e,t,n){var i;i="string"!=typeof t?t instanceof Error?t:new c("operation timed out"):new c(t),s.markAsOriginatingFromRejection(i),e._attachExtraTrace(i),e._reject(i),null!=n&&n.cancel()};t.prototype.timeout=function(e,t){e=+e;var n,s,c=new r(setTimeout(function(){n.isPending()&&f(n,t,s)},e));return i.cancellation()?(s=this.then(),(n=s._then(o,a,void 0,c,void 0))._setOnCancel(c)):n=this._then(o,a,void 0,c,void 0),n}}},{"./util":36}],35:[function(e,t,n){t.exports=function(t,n,i,r,o,a){function s(e){setTimeout(function(){throw e},0)}function c(e){var t=i(e);return t!==e&&"function"==typeof e._isDisposable&&"function"==typeof e._getDisposer&&e._isDisposable()&&t._setDisposable(e._getDisposer()),t}function u(e,n){function r(){if(a>=u)return l._fulfill();var o=c(e[a++]);if(o instanceof t&&o._isDisposable()){try{o=i(o._getDisposer().tryDispose(n),e.promise)}catch(e){return s(e)}if(o instanceof t)return o._then(r,s,null,null,null)}r()}var a=0,u=e.length,l=new t(o);return r(),l}function l(e,t,n){this._data=e,this._promise=t,this._context=n}function f(e,t,n){this.constructor$(e,t,n)}function p(e){return l.isDisposer(e)?(this.resources[this.index]._setDisposable(e),e.promise()):e}function d(e){this.length=e,this.promise=null,this[e-1]=null}var h=e("./util"),m=e("./errors").TypeError,v=e("./util").inherits,b=h.errorObj,y=h.tryCatch;l.prototype.data=function(){return this._data},l.prototype.promise=function(){return this._promise},l.prototype.resource=function(){return this.promise().isFulfilled()?this.promise().value():null},l.prototype.tryDispose=function(e){var t=this.resource(),n=this._context;void 0!==n&&n._pushContext();var i=null!==t?this.doDispose(t,e):null;return void 0!==n&&n._popContext(),this._promise._unsetDisposable(),this._data=null,i},l.isDisposer=function(e){return null!=e&&"function"==typeof e.resource&&"function"==typeof e.tryDispose},v(f,l),f.prototype.doDispose=function(e,t){return this.data().call(e,e,t)},d.prototype._resultCancelled=function(){for(var e=this.length,n=0;n0},t.prototype._getDisposer=function(){return this._disposer},t.prototype._unsetDisposable=function(){this._bitField=-131073&this._bitField,this._disposer=void 0},t.prototype.disposer=function(e){if("function"==typeof e)return new f(e,this,r());throw new m}}},{"./errors":12,"./util":36}],36:[function(t,n,r){function o(){try{var e=M;return M=null,e.apply(this,arguments)}catch(e){return C.e=e,C}}function a(e){return M=e,o}function s(e){return null==e||!0===e||!1===e||"string"==typeof e||"number"==typeof e}function c(e){return"function"==typeof e||"object"===(void 0===e?"undefined":_typeof(e))&&null!==e}function u(e){return s(e)?new Error(y(e)):e}function l(e,t){var n,i=e.length,r=new Array(i+1);for(n=0;n1,i=t.length>0&&!(1===t.length&&"constructor"===t[0]),r=I.test(e+"")&&E.names(e).length>0;if(n||i||r)return!0}return!1}catch(e){return!1}}function m(e){function t(){}t.prototype=e;for(var n=8;n--;)new t;return e}function v(e){return B.test(e)}function b(e,t,n){for(var i=new Array(e),r=0;r10||t[0]>0}(),L.isNode&&L.toFastProperties(e);try{throw new Error}catch(e){L.lastLineError=e}n.exports=L},{"./es5":13}]},{},[4])(4)}),"undefined"!=typeof window&&null!==window?window.P=window.Promise:"undefined"!=typeof self&&null!==self&&(self.P=self.Promise)}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:120}],216:[function(e,t,n){arguments[4][16][0].apply(n,arguments)},{crypto:17,dup:16}],217:[function(e,t,n){arguments[4][67][0].apply(n,arguments)},{"../package.json":232,"./elliptic/curve":220,"./elliptic/curves":223,"./elliptic/ec":224,"./elliptic/eddsa":227,"./elliptic/utils":231,brorand:216,dup:67}],218:[function(e,t,n){arguments[4][68][0].apply(n,arguments)},{"../../elliptic":217,"bn.js":"BN",dup:68}],219:[function(e,t,n){arguments[4][69][0].apply(n,arguments)},{"../../elliptic":217,"../curve":220,"bn.js":"BN",dup:69,inherits:240}],220:[function(e,t,n){arguments[4][70][0].apply(n,arguments)},{"./base":218,"./edwards":219,"./mont":221,"./short":222,dup:70}],221:[function(e,t,n){arguments[4][71][0].apply(n,arguments)},{"../../elliptic":217,"../curve":220,"bn.js":"BN",dup:71,inherits:240}],222:[function(e,t,n){arguments[4][72][0].apply(n,arguments)},{"../../elliptic":217,"../curve":220,"bn.js":"BN",dup:72,inherits:240}],223:[function(e,t,n){arguments[4][73][0].apply(n,arguments)},{"../elliptic":217,"./precomputed/secp256k1":230,dup:73,"hash.js":86}],224:[function(e,t,n){arguments[4][74][0].apply(n,arguments)},{"../../elliptic":217,"./key":225,"./signature":226,"bn.js":"BN",dup:74,"hmac-drbg":239}],225:[function(e,t,n){arguments[4][75][0].apply(n,arguments)},{"../../elliptic":217,"bn.js":"BN",dup:75}],226:[function(e,t,n){arguments[4][76][0].apply(n,arguments)},{"../../elliptic":217,"bn.js":"BN",dup:76}],227:[function(e,t,n){arguments[4][77][0].apply(n,arguments)},{"../../elliptic":217,"./key":228,"./signature":229,dup:77,"hash.js":86}],228:[function(e,t,n){arguments[4][78][0].apply(n,arguments)},{"../../elliptic":217,dup:78}],229:[function(e,t,n){arguments[4][79][0].apply(n,arguments)},{"../../elliptic":217,"bn.js":"BN",dup:79}],230:[function(e,t,n){arguments[4][80][0].apply(n,arguments)},{dup:80}],231:[function(e,t,n){arguments[4][81][0].apply(n,arguments)},{"bn.js":"BN",dup:81,"minimalistic-assert":241,"minimalistic-crypto-utils":242}],232:[function(e,t,n){t.exports={_args:[[{raw:"elliptic@^6.4.0",scope:null,escapedName:"elliptic",name:"elliptic",rawSpec:"^6.4.0",spec:">=6.4.0 <7.0.0",type:"range"},"/Users/iurimatias/Projects/opensource/web3.js/packages/web3-eth-accounts/node_modules/eth-lib"]],_from:"elliptic@>=6.4.0 <7.0.0",_id:"elliptic@6.4.0",_inCache:!0,_location:"/elliptic",_nodeVersion:"7.0.0",_npmOperationalInternal:{host:"packages-18-east.internal.npmjs.com",tmp:"tmp/elliptic-6.4.0.tgz_1487798866428_0.30510620190761983"},_npmUser:{name:"indutny",email:"fedor@indutny.com"},_npmVersion:"3.10.8",_phantomChildren:{},_requested:{raw:"elliptic@^6.4.0",scope:null,escapedName:"elliptic",name:"elliptic",rawSpec:"^6.4.0",spec:">=6.4.0 <7.0.0",type:"range"},_requiredBy:["/eth-lib"],_resolved:"https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz",_shasum:"cac9af8762c85836187003c8dfe193e5e2eae5df",_shrinkwrap:null,_spec:"elliptic@^6.4.0",_where:"/Users/iurimatias/Projects/opensource/web3.js/packages/web3-eth-accounts/node_modules/eth-lib",author:{name:"Fedor Indutny",email:"fedor@indutny.com"},bugs:{url:"https://github.com/indutny/elliptic/issues"},dependencies:{"bn.js":"^4.4.0",brorand:"^1.0.1","hash.js":"^1.0.0","hmac-drbg":"^1.0.0",inherits:"^2.0.1","minimalistic-assert":"^1.0.0","minimalistic-crypto-utils":"^1.0.0"},description:"EC cryptography",devDependencies:{brfs:"^1.4.3",coveralls:"^2.11.3",grunt:"^0.4.5","grunt-browserify":"^5.0.0","grunt-cli":"^1.2.0","grunt-contrib-connect":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^1.0.1","grunt-mocha-istanbul":"^3.0.1","grunt-saucelabs":"^8.6.2",istanbul:"^0.4.2",jscs:"^2.9.0",jshint:"^2.6.0",mocha:"^2.1.0"},directories:{},dist:{shasum:"cac9af8762c85836187003c8dfe193e5e2eae5df",tarball:"https://registry.npmjs.org/elliptic/-/elliptic-6.4.0.tgz"},files:["lib"],gitHead:"6b0d2b76caae91471649c8e21f0b1d3ba0f96090",homepage:"https://github.com/indutny/elliptic",keywords:["EC","Elliptic","curve","Cryptography"],license:"MIT",main:"lib/elliptic.js",maintainers:[{name:"indutny",email:"fedor@indutny.com"}],name:"elliptic",optionalDependencies:{},readme:"ERROR: No README data found!",repository:{type:"git",url:"git+ssh://git@github.com/indutny/elliptic.git"},scripts:{jscs:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",jshint:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",lint:"npm run jscs && npm run jshint",test:"npm run lint && npm run unit",unit:"istanbul test _mocha --reporter=spec test/index.js",version:"grunt dist && git add dist/"},version:"6.4.0"}},{}],233:[function(e,t,n){(function(n){var i=function(){function e(e,t){var n=[],i=!0,r=!1,o=void 0;try{for(var a,s=e[Symbol.iterator]();!(i=(a=s.next()).done)&&(n.push(a.value),!t||n.length!==t);i=!0);}catch(e){r=!0,o=e}finally{try{!i&&s.return&&s.return()}finally{if(r)throw o}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),r=e("./bytes"),o=e("./nat"),a=e("elliptic"),s=e("./rlp"),c=new a.ec("secp256k1"),u=e("./hash"),l=u.keccak256,f=u.keccak256s,p=function(e){for(var t=f(e.slice(2)),n="0x",i=0;i<40;i++)n+=parseInt(t[i+2],16)>7?e[i+2].toUpperCase():e[i+2];return n},d=function(e){var t=new n(e.slice(2),"hex"),i="0x"+c.keyFromPrivate(t).getPublic(!1,"hex").slice(2),r=l(i);return{address:p("0x"+r.slice(-40)),privateKey:e}},h=function(e){var t=i(e,3),n=t[0],o=t[1],a=t[2];return r.flatten([o,a,n])},m=function(e){return[r.slice(64,65,e),r.slice(0,32,e),r.slice(32,64,e)]},v=function(e){return function(t,i){var o=c.keyFromPrivate(new n(i.slice(2),"hex")).sign(new n(t.slice(2),"hex"),{canonical:!0});return h([r.pad(1,r.fromNumber(e+o.recoveryParam)),r.pad(32,r.fromNat("0x"+o.r.toString(16))),r.pad(32,r.fromNat("0x"+o.s.toString(16)))])}},b=v(27),y=function(e,t){var i=m(t),o={v:r.toNumber(i[0]),r:i[1].slice(2),s:i[2].slice(2)},a="0x"+c.recoverPubKey(new n(e.slice(2),"hex"),o,o.v<2?o.v:1-o.v%2).encode("hex",!1).slice(2),s=l(a);return p("0x"+s.slice(-40))},g=function(e){return s.encode([r.fromNat(e.nonce),r.fromNat(e.gasPrice),r.fromNat(e.gas),e.to.toLowerCase(),r.fromNat(e.value),e.data,r.fromNat(e.chainId||"0x1"),"0x","0x"])};t.exports={create:function(e){var t=l(r.concat(r.random(32),e||r.random(32))),n=r.concat(r.concat(r.random(32),t),r.random(32)),i=l(n);return d(i)},toChecksum:p,fromPrivate:d,sign:b,recover:y,signTransaction:function(e,t){var n=g(e),i=v(2*o.toNumber(e.chainId||"0x1")+35)(l(n),t),r=s.decode(n).slice(0,6).concat(m(i));return s.encode(r)},recoverTransaction:function(e){var t=s.decode(e),n=h(t.slice(6,9)),i=r.toNumber(t[6]),o=i<35?[]:[r.fromNumber(i-35>>1),"0x","0x"],a=t.slice(0,6).concat(o),c=s.encode(a);return y(l(c),n)},transactionSigningData:g,encodeSignature:h,decodeSignature:m}}).call(this,e("buffer").Buffer)},{"./bytes":235,"./hash":236,"./nat":237,"./rlp":238,buffer:47,elliptic:217}],234:[function(e,t,n){var i=function(e,t){for(var n=[],i=0;i>6|192);else{if(r>55295&&r<56320){if(++i==e.length)return null;var o=e.charCodeAt(i);if(o<56320||o>57343)return null;n+=t((r=65536+((1023&r)<<10)+(1023&o))>>18|240),n+=t(r>>12&63|128)}else n+=t(r>>12|224);n+=t(r>>6&63|128)}n+=t(63&r|128)}}return n},toString:function(e){for(var t="",n=0,o=r(e);n127){if(a>191&&a<224){if(n>=o)return null;a=(31&a)<<6|63&i(e,n)}else if(a>223&&a<240){if(n+1>=o)return null;a=(15&a)<<12|(63&i(e,n))<<6|63&i(e,++n)}else{if(!(a>239&&a<248))return null;if(n+2>=o)return null;a=(7&a)<<18|(63&i(e,n))<<12|(63&i(e,++n))<<6|63&i(e,++n)}++n}if(a<=65535)t+=String.fromCharCode(a);else{if(!(a<=1114111))return null;a-=65536,t+=String.fromCharCode(a>>10|55296),t+=String.fromCharCode(1023&a|56320)}}return t},fromNumber:function(e){var t=e.toString(16);return t.length%2==0?"0x"+t:"0x0"+t},toNumber:function(e){return parseInt(e.slice(2),16)},fromNat:function(e){return"0x0"===e?"0x":e.length%2==0?e:"0x0"+e.slice(2)},toNat:function(e){return"0"===e[2]?"0x"+e.slice(3):e},fromArray:a,toArray:o,fromUint8Array:function(e){return a([].slice.call(e,0))},toUint8Array:function(e){return new Uint8Array(o(e))}}},{"./array.js":234}],236:[function(e,t,n){var i="0123456789abcdef".split(""),r=[1,256,65536,16777216],o=[0,8,16,24],a=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],s=function(e){return{blocks:[],reset:!0,block:0,start:0,blockCount:1600-(e<<1)>>5,outputBlocks:e>>5,s:function(e){return[].concat(e,e,e,e,e)}([0,0,0,0,0,0,0,0,0,0])}},c=function(e,t){for(var n,a=t.length,s=e.blocks,c=e.blockCount<<2,l=e.blockCount,f=e.outputBlocks,p=e.s,d=0;d>2]|=t[d]<>2]|=n<>2]|=(192|n>>6)<>2]|=(128|63&n)<=57344?(s[v>>2]|=(224|n>>12)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<>2]|=(240|n>>18)<>2]|=(128|n>>12&63)<>2]|=(128|n>>6&63)<>2]|=(128|63&n)<=c){for(e.start=v-c,e.block=s[l],v=0;v>2]|=r[3&v],e.lastByteIndex===c)for(s[0]=s[l],v=1;v>4&15]+i[15&h]+i[h>>12&15]+i[h>>8&15]+i[h>>20&15]+i[h>>16&15]+i[h>>28&15]+i[h>>24&15];b%l==0&&(u(p),v=0)}return"0x"+m},u=function(e){var t,n,i,r,o,s,c,u,l,f,p,d,h,m,v,b,y,g,_,x,w,k,j,S,E,A,C,M,T,P,F,I,B,R,O,N,D,L,q,z,U,H,V,K,W,X,G,$,J,Q,Y,Z,ee,te,ne,ie,re,oe,ae,se,ce,ue,le;for(i=0;i<48;i+=2)r=e[0]^e[10]^e[20]^e[30]^e[40],o=e[1]^e[11]^e[21]^e[31]^e[41],s=e[2]^e[12]^e[22]^e[32]^e[42],c=e[3]^e[13]^e[23]^e[33]^e[43],u=e[4]^e[14]^e[24]^e[34]^e[44],l=e[5]^e[15]^e[25]^e[35]^e[45],f=e[6]^e[16]^e[26]^e[36]^e[46],p=e[7]^e[17]^e[27]^e[37]^e[47],t=(d=e[8]^e[18]^e[28]^e[38]^e[48])^(s<<1|c>>>31),n=(h=e[9]^e[19]^e[29]^e[39]^e[49])^(c<<1|s>>>31),e[0]^=t,e[1]^=n,e[10]^=t,e[11]^=n,e[20]^=t,e[21]^=n,e[30]^=t,e[31]^=n,e[40]^=t,e[41]^=n,t=r^(u<<1|l>>>31),n=o^(l<<1|u>>>31),e[2]^=t,e[3]^=n,e[12]^=t,e[13]^=n,e[22]^=t,e[23]^=n,e[32]^=t,e[33]^=n,e[42]^=t,e[43]^=n,t=s^(f<<1|p>>>31),n=c^(p<<1|f>>>31),e[4]^=t,e[5]^=n,e[14]^=t,e[15]^=n,e[24]^=t,e[25]^=n,e[34]^=t,e[35]^=n,e[44]^=t,e[45]^=n,t=u^(d<<1|h>>>31),n=l^(h<<1|d>>>31),e[6]^=t,e[7]^=n,e[16]^=t,e[17]^=n,e[26]^=t,e[27]^=n,e[36]^=t,e[37]^=n,e[46]^=t,e[47]^=n,t=f^(r<<1|o>>>31),n=p^(o<<1|r>>>31),e[8]^=t,e[9]^=n,e[18]^=t,e[19]^=n,e[28]^=t,e[29]^=n,e[38]^=t,e[39]^=n,e[48]^=t,e[49]^=n,m=e[0],v=e[1],X=e[11]<<4|e[10]>>>28,G=e[10]<<4|e[11]>>>28,M=e[20]<<3|e[21]>>>29,T=e[21]<<3|e[20]>>>29,se=e[31]<<9|e[30]>>>23,ce=e[30]<<9|e[31]>>>23,H=e[40]<<18|e[41]>>>14,V=e[41]<<18|e[40]>>>14,R=e[2]<<1|e[3]>>>31,O=e[3]<<1|e[2]>>>31,b=e[13]<<12|e[12]>>>20,y=e[12]<<12|e[13]>>>20,$=e[22]<<10|e[23]>>>22,J=e[23]<<10|e[22]>>>22,P=e[33]<<13|e[32]>>>19,F=e[32]<<13|e[33]>>>19,ue=e[42]<<2|e[43]>>>30,le=e[43]<<2|e[42]>>>30,te=e[5]<<30|e[4]>>>2,ne=e[4]<<30|e[5]>>>2,N=e[14]<<6|e[15]>>>26,D=e[15]<<6|e[14]>>>26,g=e[25]<<11|e[24]>>>21,_=e[24]<<11|e[25]>>>21,Q=e[34]<<15|e[35]>>>17,Y=e[35]<<15|e[34]>>>17,I=e[45]<<29|e[44]>>>3,B=e[44]<<29|e[45]>>>3,S=e[6]<<28|e[7]>>>4,E=e[7]<<28|e[6]>>>4,ie=e[17]<<23|e[16]>>>9,re=e[16]<<23|e[17]>>>9,L=e[26]<<25|e[27]>>>7,q=e[27]<<25|e[26]>>>7,x=e[36]<<21|e[37]>>>11,w=e[37]<<21|e[36]>>>11,Z=e[47]<<24|e[46]>>>8,ee=e[46]<<24|e[47]>>>8,K=e[8]<<27|e[9]>>>5,W=e[9]<<27|e[8]>>>5,A=e[18]<<20|e[19]>>>12,C=e[19]<<20|e[18]>>>12,oe=e[29]<<7|e[28]>>>25,ae=e[28]<<7|e[29]>>>25,z=e[38]<<8|e[39]>>>24,U=e[39]<<8|e[38]>>>24,k=e[48]<<14|e[49]>>>18,j=e[49]<<14|e[48]>>>18,e[0]=m^~b&g,e[1]=v^~y&_,e[10]=S^~A&M,e[11]=E^~C&T,e[20]=R^~N&L,e[21]=O^~D&q,e[30]=K^~X&$,e[31]=W^~G&J,e[40]=te^~ie&oe,e[41]=ne^~re&ae,e[2]=b^~g&x,e[3]=y^~_&w,e[12]=A^~M&P,e[13]=C^~T&F,e[22]=N^~L&z,e[23]=D^~q&U,e[32]=X^~$&Q,e[33]=G^~J&Y,e[42]=ie^~oe&se,e[43]=re^~ae&ce,e[4]=g^~x&k,e[5]=_^~w&j,e[14]=M^~P&I,e[15]=T^~F&B,e[24]=L^~z&H,e[25]=q^~U&V,e[34]=$^~Q&Z,e[35]=J^~Y&ee,e[44]=oe^~se&ue,e[45]=ae^~ce&le,e[6]=x^~k&m,e[7]=w^~j&v,e[16]=P^~I&S,e[17]=F^~B&E,e[26]=z^~H&R,e[27]=U^~V&O,e[36]=Q^~Z&K,e[37]=Y^~ee&W,e[46]=se^~ue&te,e[47]=ce^~le&ne,e[8]=k^~m&b,e[9]=j^~v&y,e[18]=I^~S&A,e[19]=B^~E&C,e[28]=H^~R&N,e[29]=V^~O&D,e[38]=Z^~K&X,e[39]=ee^~W&G,e[48]=ue^~te&ie,e[49]=le^~ne&re,e[0]^=a[i],e[1]^=a[i+1]},l=function(e){return function(t){var n;if("0x"===t.slice(0,2)){n=[];for(var i=2,r=t.length;i="80"?i(n.length/2,128):"")+n}var r=t.map(e).join("");return i(r.length/2,192)+r}(e)},decode:function(e){var t=2,n=function(){if(t>=e.length)throw"";var n=e.slice(t,t+2);return n<"80"?(t+=2,"0x"+n):n<"c0"?r():o()},i=function(){var n=parseInt(e.slice(t,t+=2),16)%64;return n<56?n:parseInt(e.slice(t,t+=2*(n-55)),16)},r=function(){var n=i();return"0x"+e.slice(t,t+=2*n)},o=function(){for(var e=2*i()+t,r=[];t>>((3&t)<<3)&255;return r}}t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],245:[function(e,t,n){function i(e,t){var n=t||0,i=a;return i[e[n++]]+i[e[n++]]+i[e[n++]]+i[e[n++]]+"-"+i[e[n++]]+i[e[n++]]+"-"+i[e[n++]]+i[e[n++]]+"-"+i[e[n++]]+i[e[n++]]+"-"+i[e[n++]]+i[e[n++]]+i[e[n++]]+i[e[n++]]+i[e[n++]]+i[e[n++]]}function r(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"==e?new Array(16):null,e=null);var a=(e=e||{}).random||(e.rng||o)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t)for(var s=0;s<16;s++)t[r+s]=a[s];return t||i(a)}for(var o=e("./rng"),a=[],s={},c=0;c<256;c++)a[c]=(c+256).toString(16).substr(1),s[a[c]]=c;var u=o(),l=[1|u[0],u[1],u[2],u[3],u[4],u[5]],f=16383&(u[6]<<8|u[7]),p=0,d=0,h=r;h.v1=function(e,t,n){var r=t&&n||0,o=t||[],a=void 0!==(e=e||{}).clockseq?e.clockseq:f,s=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:d+1,u=s-p+(c-d)/1e4;if(u<0&&void 0===e.clockseq&&(a=a+1&16383),(u<0||s>p)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");p=s,d=c,f=a;var h=(1e4*(268435455&(s+=122192928e5))+c)%4294967296;o[r++]=h>>>24&255,o[r++]=h>>>16&255,o[r++]=h>>>8&255,o[r++]=255&h;var m=s/4294967296*1e4&268435455;o[r++]=m>>>8&255,o[r++]=255&m,o[r++]=m>>>24&15|16,o[r++]=m>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var v=e.node||l,b=0;b<6;b++)o[r+b]=v[b];return t||i(o)},h.v4=r,h.parse=function(e,t,n){var i=t&&n||0,r=0;for(t=t||[],e.toLowerCase().replace(/[0-9a-f]{2}/g,function(e){r<16&&(t[i+r++]=s[e])});r<16;)t[i+r++]=0;return t},h.unparse=i,t.exports=h},{"./rng":244}],246:[function(e,t,n){(function(n){function i(e){this.length=0,this._accounts=e,this.defaultKeyName="web3js_wallet"}var r=e("underscore"),o=e("web3-core"),a=e("web3-core-method"),s=e("bluebird"),c=e("eth-lib/lib/account"),u=e("eth-lib/lib/hash"),l=e("eth-lib/lib/rlp"),f=e("crypto"),p=e("scrypt.js"),d=e("uuid"),h=e("web3-utils"),m=e("web3-core-helpers"),v=function(e){return r.isUndefined(e)||r.isNull(e)},b=function(){var e=this;o.packageInit(this,arguments),delete this.BatchRequest,delete this.extend;var t=[new a({name:"getId",call:"net_version",params:0,outputFormatter:h.hexToNumber}),new a({name:"getGasPrice",call:"eth_gasPrice",params:0}),new a({name:"getTransactionCount",call:"eth_getTransactionCount",params:2,inputFormatter:[function(e){if(h.isAddress(e))return e;throw new Error("Address "+e+' is not a valid address to get the "transactionCount".')},function(){return"latest"}]})];this._ethereumCall={},r.each(t,function(t){t.attachToObject(e._ethereumCall),t.setRequestManager(e._requestManager)}),this.wallet=new i(this)};b.prototype._addAccountFunctions=function(e){var t=this;return e.signTransaction=function(n,i){return t.signTransaction(n,e.privateKey,i)},e.sign=function(n){return t.sign(n,e.privateKey)},e.encrypt=function(n,i){return t.encrypt(e.privateKey,n,i)},e},b.prototype.create=function(e){return this._addAccountFunctions(c.create(e||h.randomHex(32)))},b.prototype.privateKeyToAccount=function(e){return this._addAccountFunctions(c.fromPrivate(e))},b.prototype.signTransaction=function(e,t,n){function i(e){if(!e.gas&&!e.gasLimit)throw new Error('"gas" is missing');var i={nonce:h.numberToHex(e.nonce),to:e.to?m.formatters.inputAddressFormatter(e.to):"0x",data:e.data||"0x",value:e.value?h.numberToHex(e.value):"0x",gas:h.numberToHex(e.gasLimit||e.gas),gasPrice:h.numberToHex(e.gasPrice),chainId:h.numberToHex(e.chainId)},o=u.keccak256(c.transactionSigningData(i)),a=c.signTransaction(i,t),s=l.decode(a),f={messageHash:o,v:s[6],r:s[7],s:s[8],rawTransaction:a};return r.isFunction(n)&&n(null,f),f}var o=this;return void 0!==e.nonce&&void 0!==e.chainId&&void 0!==e.gasPrice?i(e):s.all([v(e.chainId)?o._ethereumCall.getId():e.chainId,v(e.gasPrice)?o._ethereumCall.getGasPrice():e.gasPrice,v(e.nonce)?o._ethereumCall.getTransactionCount(o.privateKeyToAccount(t).address):e.nonce]).then(function(t){if(v(t[0])||v(t[1])||v(t[2]))throw new Error('One of the values "chainId", "gasPrice", or "nonce" couldn\'t be fetched: '+JSON.stringify(t));return i(r.extend(e,{chainId:t[0],gasPrice:t[1],nonce:t[2]}))})},b.prototype.recoverTransaction=function(e){return c.recoverTransaction(e)},b.prototype.hashMessage=function(e){var t=h.isHex(e)?h.hexToUtf8(e):e,n="Ethereum Signed Message:\n"+t.length+t;return u.keccak256s(n)},b.prototype.sign=function(e,t){var n=this.hashMessage(e),i=c.sign(n,t),r=c.decodeSignature(i);return{message:e,messageHash:n,v:r[0],r:r[1],s:r[2],signature:i}},b.prototype.recover=function(e,t){return r.isObject(e)?this.recover(e.messageHash,c.encodeSignature([e.v,e.r,e.s])):(h.isHex(e)||(e=this.hashMessage(e)),4===arguments.length?this.recover(e,c.encodeSignature([].slice.call(arguments,1,4))):c.recover(e,t))},b.prototype.decrypt=function(e,t,i){if(!r.isString(t))throw new Error("No password given.");var o=r.isObject(e)?e:JSON.parse(i?e.toLowerCase():e);if(3!==o.version)throw new Error("Not a valid V3 wallet");var a,s;if("scrypt"===o.crypto.kdf)s=o.crypto.kdfparams,a=p(new n(t),new n(s.salt,"hex"),s.n,s.r,s.p,s.dklen);else{if("pbkdf2"!==o.crypto.kdf)throw new Error("Unsupported key derivation scheme");if("hmac-sha256"!==(s=o.crypto.kdfparams).prf)throw new Error("Unsupported parameters to PBKDF2");a=f.pbkdf2Sync(new n(t),new n(s.salt,"hex"),s.c,s.dklen,"sha256")}var c=new n(o.crypto.ciphertext,"hex");if(h.sha3(n.concat([a.slice(16,32),c])).replace("0x","")!==o.crypto.mac)throw new Error("Key derivation failed - possibly wrong password");var u=f.createDecipheriv(o.crypto.cipher,a.slice(0,16),new n(o.crypto.cipherparams.iv,"hex")),l="0x"+n.concat([u.update(c),u.final()]).toString("hex");return this.privateKeyToAccount(l)},b.prototype.encrypt=function(e,t,i){var r,o=this.privateKeyToAccount(e),a=(i=i||{}).salt||f.randomBytes(32),s=i.iv||f.randomBytes(16),c=i.kdf||"scrypt",u={dklen:i.dklen||32,salt:a.toString("hex")};if("pbkdf2"===c)u.c=i.c||262144,u.prf="hmac-sha256",r=f.pbkdf2Sync(new n(t),a,u.c,u.dklen,"sha256");else{if("scrypt"!==c)throw new Error("Unsupported kdf");u.n=i.n||8192,u.r=i.r||8,u.p=i.p||1,r=p(new n(t),a,u.n,u.r,u.p,u.dklen)}var l=f.createCipheriv(i.cipher||"aes-128-ctr",r.slice(0,16),s);if(!l)throw new Error("Unsupported cipher");var m=n.concat([l.update(new n(o.privateKey.replace("0x",""),"hex")),l.final()]),v=h.sha3(n.concat([r.slice(16,32),new n(m,"hex")])).replace("0x","");return{version:3,id:d.v4({random:i.uuid||f.randomBytes(16)}),address:o.address.toLowerCase().replace("0x",""),crypto:{ciphertext:m.toString("hex"),cipherparams:{iv:s.toString("hex")},cipher:i.cipher||"aes-128-ctr",kdf:c,kdfparams:u,mac:v.toString("hex")}}},i.prototype._findSafeIndex=function(e){return e=e||0,r.has(this,e)?this._findSafeIndex(e+1):e},i.prototype._currentIndexes=function(){return Object.keys(this).map(function(e){return parseInt(e)}).filter(function(e){return e<9e20})},i.prototype.create=function(e,t){for(var n=0;n=2?t.slice(2):t;var n=f.decodeParameters(e,t);return 1===n.__length__?n[0]:(delete n.__length__,n)},p.prototype.deploy=function(e,t){if(e=e||{},e.arguments=e.arguments||[],!(e=this._getOrSetDefaultOptions(e)).data)return a._fireError(new Error('No "data" specified in neither the given options, nor the default options.'),null,null,t);var n=i.find(this.options.jsonInterface,function(e){return"constructor"===e.type})||{};return n.signature="constructor",this._createTxObject.apply({method:n,parent:this,deployData:e.data},e.arguments)},p.prototype._generateEventOptions=function(){var e=Array.prototype.slice.call(arguments),t=this._getCallback(e),n=i.isObject(e[e.length-1])?e.pop():{},r=i.isString(e[0])?e[0]:"allevents";if(!(r="allevents"===r.toLowerCase()?{name:"ALLEVENTS",jsonInterface:this.options.jsonInterface}:this.options.jsonInterface.find(function(e){return"event"===e.type&&(e.name===r||e.signature==="0x"+r.replace("0x",""))})))throw new Error('Event "'+r.name+"\" doesn't exist in this contract.");if(!a.isAddress(this.options.address))throw new Error("This contract object doesn't have address set yet, please set an address first.");return{params:this._encodeEventABI(r,n),event:r,callback:t}},p.prototype.clone=function(){return new p(this.options.jsonInterface,this.options.address,this.options)},p.prototype.once=function(e,t,n){var r=Array.prototype.slice.call(arguments);if(!(n=this._getCallback(r)))throw new Error("Once requires a callback as the second parameter.");t&&delete t.fromBlock,this._on(e,t,function(e,t,r){r.unsubscribe(),i.isFunction(n)&&n(e,t,r)})},p.prototype._on=function(){var e=this._generateEventOptions.apply(this,arguments);this._checkListener("newListener",e.event.name,e.callback),this._checkListener("removeListener",e.event.name,e.callback);var t=new s({subscription:{params:1,inputFormatter:[c.inputLogFormatter],outputFormatter:this._decodeEventABI.bind(e.event),subscriptionHandler:function(e){e.removed?this.emit("changed",e):this.emit("data",e),i.isFunction(this.callback)&&this.callback(null,e,this)}},type:"eth",requestManager:this._requestManager});return t.subscribe("logs",e.params,e.callback||function(){}),t},p.prototype.getPastEvents=function(){var e=this._generateEventOptions.apply(this,arguments),t=new o({name:"getPastLogs",call:"eth_getLogs",params:1,inputFormatter:[c.inputLogFormatter],outputFormatter:this._decodeEventABI.bind(e.event)});t.setRequestManager(this._requestManager);var n=t.buildCall();return t=null,n(e.params,e.callback)},p.prototype._createTxObject=function(){var e=Array.prototype.slice.call(arguments),t={};if("function"===this.method.type&&(t.call=this.parent._executeMethod.bind(t,"call"),t.call.request=this.parent._executeMethod.bind(t,"call",!0)),t.send=this.parent._executeMethod.bind(t,"send"),t.send.request=this.parent._executeMethod.bind(t,"send",!0),t.encodeABI=this.parent._encodeMethodABI.bind(t),t.estimateGas=this.parent._executeMethod.bind(t,"estimate"),e&&this.method.inputs&&e.length!==this.method.inputs.length)throw u.InvalidNumberOfParams(e.length,this.method.inputs.length,this.method.name);return t.arguments=e||[],t._method=this.method,t._parent=this.parent,this.deployData&&(t._deployData=this.deployData),t},p.prototype._processExecuteArguments=function(e,t){var n={};if(n.type=e.shift(),n.callback=this._parent._getCallback(e),"call"===n.type&&!0!==e[e.length-1]&&(i.isString(e[e.length-1])||isFinite(e[e.length-1]))&&(n.defaultBlock=e.pop()),n.options=i.isObject(e[e.length-1])?e.pop():{},n.generateRequest=!0===e[e.length-1]&&e.pop(),n.options=this._parent._getOrSetDefaultOptions(n.options),n.options.data=this.encodeABI(),!this._deployData&&!a.isAddress(this._parent.options.address))throw new Error("This contract object doesn't have address set yet, please set an address first.");return this._deployData||(n.options.to=this._parent.options.address),n.options.data?n:a._fireError(new Error("Couldn't find a matching contract method, or the number of parameters is wrong."),t.eventEmitter,t.reject,n.callback)},p.prototype._executeMethod=function(){var e=this,t=this._parent._processExecuteArguments.call(this,Array.prototype.slice.call(arguments),n),n=l("send"!==t.type);if(t.generateRequest){var r={params:[c.inputCallFormatter.call(this._parent,t.options),c.inputDefaultBlockNumberFormatter.call(this._parent,t.defaultBlock)],callback:t.callback};return"call"===t.type?(r.method="eth_call",r.format=this._parent._decodeMethodReturn.bind(null,this._method.outputs)):r.method="eth_sendTransaction",r}switch(t.type){case"estimate":return new o({name:"estimateGas",call:"eth_estimateGas",params:1,inputFormatter:[c.inputCallFormatter],outputFormatter:a.hexToNumber,requestManager:e._parent._requestManager,accounts:p._ethAccounts,defaultAccount:e._parent.defaultAccount,defaultBlock:e._parent.defaultBlock}).createFunction()(t.options,t.callback);case"call":return new o({name:"call",call:"eth_call",params:2,inputFormatter:[c.inputCallFormatter,c.inputDefaultBlockNumberFormatter],outputFormatter:function(t){return e._parent._decodeMethodReturn(e._method.outputs,t)},requestManager:e._parent._requestManager,accounts:p._ethAccounts,defaultAccount:e._parent.defaultAccount,defaultBlock:e._parent.defaultBlock}).createFunction()(t.options,t.defaultBlock,t.callback);case"send":if(!a.isAddress(t.options.from))return a._fireError(new Error('No "from" address specified in neither the given options, nor the default options.'),n.eventEmitter,n.reject,t.callback);if(i.isBoolean(this._method.payable)&&!this._method.payable&&t.options.value&&t.options.value>0)return a._fireError(new Error("Can not send value to non-payable contract method or constructor"),n.eventEmitter,n.reject,t.callback);var s={receiptFormatter:function(t){if(i.isArray(t.logs)){var n=i.map(t.logs,function(t){return e._parent._decodeEventABI.call({name:"ALLEVENTS",jsonInterface:e._parent.options.jsonInterface},t)});t.events={};var r=0;n.forEach(function(e){e.event?t.events[e.event]?Array.isArray(t.events[e.event])?t.events[e.event].push(e):t.events[e.event]=[t.events[e.event],e]:t.events[e.event]=e:(t.events[r]=e,r++)}),delete t.logs}return t},contractDeployFormatter:function(t){var n=e._parent.clone();return n.options.address=t.contractAddress,n}};return new o({name:"sendTransaction",call:"eth_sendTransaction",params:1,inputFormatter:[c.inputTransactionFormatter],requestManager:e._parent._requestManager,accounts:p._ethAccounts,defaultAccount:e._parent.defaultAccount,defaultBlock:e._parent.defaultBlock,extraFormatters:s}).createFunction()(t.options,t.callback)}},t.exports=p},{underscore:247,"web3-core":202,"web3-core-helpers":186,"web3-core-method":188,"web3-core-promievent":191,"web3-core-subscriptions":199,"web3-eth-abi":205,"web3-utils":273}],249:[function(e,t,n){var i=e("web3-utils"),r=e("bn.js"),o=function(e,t){for(var n=e;n.length<2*t;)n="0"+n;return n},a=function(e){var t="A".charCodeAt(0),n="Z".charCodeAt(0);return e=e.toUpperCase(),(e=e.substr(4)+e.substr(0,4)).split("").map(function(e){var i=e.charCodeAt(0);return i>=t&&i<=n?i-t+10:e}).join("")},s=function(e){for(var t,n=e;n.length>2;)t=n.slice(0,9),n=parseInt(t,10)%97+n.slice(t.length);return parseInt(n,10)%97},c=function(e){this._iban=e};c.toAddress=function(e){if(!(e=new c(e)).isDirect())throw new Error("IBAN is indirect and can't be converted");return e.toAddress()},c.toIban=function(e){return c.fromAddress(e).toString()},c.fromAddress=function(e){if(!i.isAddress(e))throw new Error("Provided address is not a valid address: "+e);e=e.replace("0x","").replace("0X","");var t=new r(e,16).toString(36),n=o(t,15);return c.fromBban(n.toUpperCase())},c.fromBban=function(e){var t=("0"+(98-s(a("XE00"+e)))).slice(-2);return new c("XE"+t+e)},c.createIndirect=function(e){return c.fromBban("ETH"+e.institution+e.identifier)},c.isValid=function(e){return new c(e).isValid()},c.prototype.isValid=function(){return/^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(this._iban)&&1===s(a(this._iban))},c.prototype.isDirect=function(){return 34===this._iban.length||35===this._iban.length},c.prototype.isIndirect=function(){return 20===this._iban.length},c.prototype.checksum=function(){return this._iban.substr(2,2)},c.prototype.institution=function(){return this.isIndirect()?this._iban.substr(7,4):""},c.prototype.client=function(){return this.isIndirect()?this._iban.substr(11):""},c.prototype.toAddress=function(){if(this.isDirect()){var e=this._iban.substr(4),t=new r(e,36);return i.toChecksumAddress(t.toString(16,20))}return""},c.prototype.toString=function(){return this._iban},t.exports=c},{"bn.js":"BN","web3-utils":273}],250:[function(e,t,n){var i=e("web3-core"),r=e("web3-core-method"),o=e("web3-utils"),a=e("web3-net"),s=e("web3-core-helpers").formatters,c=function(){var e=this;i.packageInit(this,arguments),this.net=new a(this.currentProvider);var t=null,n="latest";Object.defineProperty(this,"defaultAccount",{get:function(){return t},set:function(e){return e&&(t=o.toChecksumAddress(s.inputAddressFormatter(e))),c.forEach(function(e){e.defaultAccount=t}),e},enumerable:!0}),Object.defineProperty(this,"defaultBlock",{get:function(){return n},set:function(e){return n=e,c.forEach(function(e){e.defaultBlock=n}),e},enumerable:!0});var c=[new r({name:"getAccounts",call:"personal_listAccounts",params:0,outputFormatter:o.toChecksumAddress}),new r({name:"newAccount",call:"personal_newAccount",params:1,inputFormatter:[null],outputFormatter:o.toChecksumAddress}),new r({name:"unlockAccount",call:"personal_unlockAccount",params:3,inputFormatter:[s.inputAddressFormatter,null,null]}),new r({name:"lockAccount",call:"personal_lockAccount",params:1,inputFormatter:[s.inputAddressFormatter]}),new r({name:"importRawKey",call:"personal_importRawKey",params:2}),new r({name:"sendTransaction",call:"personal_sendTransaction",params:2,inputFormatter:[s.inputTransactionFormatter,null]}),new r({name:"sign",call:"personal_sign",params:3,inputFormatter:[s.inputSignFormatter,s.inputAddressFormatter,null]}),new r({name:"ecRecover",call:"personal_ecRecover",params:2,inputFormatter:[s.inputSignFormatter,null]})];c.forEach(function(t){t.attachToObject(e),t.setRequestManager(e._requestManager),t.defaultBlock=e.defaultBlock,t.defaultAccount=e.defaultAccount})};i.addProviders(c),t.exports=c},{"web3-core":202,"web3-core-helpers":186,"web3-core-method":188,"web3-net":254,"web3-utils":273}],251:[function(e,t,n){arguments[4][172][0].apply(n,arguments)},{dup:172}],252:[function(e,t,n){var i=e("underscore");t.exports=function(e){var t,n=this;return this.net.getId().then(function(e){return t=e,n.getBlock(0)}).then(function(n){var r="private";return"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3"===n.hash&&1===t&&(r="main"),"0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303"===n.hash&&2===t&&(r="morden"),"0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"===n.hash&&3===t&&(r="ropsten"),"0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177"===n.hash&&4===t&&(r="rinkeby"),"0xa3c565fc15c7478862d50ccd6561e3c06b24cc509bf388941c25ea985ce32cb9"===n.hash&&42===t&&(r="kovan"),i.isFunction(e)&&e(null,r),r}).catch(function(t){if(!i.isFunction(e))throw t;e(t)})}},{underscore:251}],253:[function(e,t,n){var i=e("underscore"),r=e("web3-core"),o=e("web3-core-helpers"),a=e("web3-core-subscriptions").subscriptions,s=e("web3-core-method"),c=e("web3-utils"),u=e("web3-net"),l=e("web3-eth-personal"),f=e("web3-eth-contract"),p=e("web3-eth-iban"),d=e("web3-eth-accounts"),h=e("web3-eth-abi"),m=e("./getNetworkType.js"),v=o.formatters,b=function(e){return i.isString(e[0])&&0===e[0].indexOf("0x")?"eth_getBlockByHash":"eth_getBlockByNumber"},y=function(e){return i.isString(e[0])&&0===e[0].indexOf("0x")?"eth_getTransactionByBlockHashAndIndex":"eth_getTransactionByBlockNumberAndIndex"},g=function(e){return i.isString(e[0])&&0===e[0].indexOf("0x")?"eth_getUncleByBlockHashAndIndex":"eth_getUncleByBlockNumberAndIndex"},_=function(e){return i.isString(e[0])&&0===e[0].indexOf("0x")?"eth_getBlockTransactionCountByHash":"eth_getBlockTransactionCountByNumber"},x=function(e){return i.isString(e[0])&&0===e[0].indexOf("0x")?"eth_getUncleCountByBlockHash":"eth_getUncleCountByBlockNumber"},w=function(){var e=this;r.packageInit(this,arguments);var t=this.setProvider;this.setProvider=function(){t.apply(e,arguments),e.net.setProvider.apply(e,arguments),e.personal.setProvider.apply(e,arguments),e.accounts.setProvider.apply(e,arguments),e.Contract.setProvider(e.currentProvider,e.accounts)};var n=null,o="latest";Object.defineProperty(this,"defaultAccount",{get:function(){return n},set:function(t){return t&&(n=c.toChecksumAddress(v.inputAddressFormatter(t))),e.Contract.defaultAccount=n,e.personal.defaultAccount=n,w.forEach(function(e){e.defaultAccount=n}),t},enumerable:!0}),Object.defineProperty(this,"defaultBlock",{get:function(){return o},set:function(t){return o=t,e.Contract.defaultBlock=o,e.personal.defaultBlock=o,w.forEach(function(e){e.defaultBlock=o}),t},enumerable:!0}),this.clearSubscriptions=e._requestManager.clearSubscriptions,this.net=new u(this.currentProvider),this.net.getNetworkType=m.bind(this),this.accounts=new d(this.currentProvider),this.personal=new l(this.currentProvider),this.personal.defaultAccount=this.defaultAccount,this.Contract=f,this.Contract.defaultAccount=this.defaultAccount,this.Contract.defaultBlock=this.defaultBlock,this.Contract.setProvider(this.currentProvider,this.accounts),this.Iban=p,this.abi=h;var w=[new s({name:"getProtocolVersion",call:"eth_protocolVersion",params:0}),new s({name:"getCoinbase",call:"eth_coinbase",params:0}),new s({name:"isMining",call:"eth_mining",params:0}),new s({name:"getHashrate",call:"eth_hashrate",params:0,outputFormatter:c.hexToNumber}),new s({name:"isSyncing",call:"eth_syncing",params:0,outputFormatter:v.outputSyncingFormatter}),new s({name:"getGasPrice",call:"eth_gasPrice",params:0,outputFormatter:v.outputBigNumberFormatter}),new s({name:"getAccounts",call:"eth_accounts",params:0,outputFormatter:c.toChecksumAddress}),new s({name:"getBlockNumber",call:"eth_blockNumber",params:0,outputFormatter:c.hexToNumber}),new s({name:"getBalance",call:"eth_getBalance",params:2,inputFormatter:[v.inputAddressFormatter,v.inputDefaultBlockNumberFormatter],outputFormatter:v.outputBigNumberFormatter}),new s({name:"getStorageAt",call:"eth_getStorageAt",params:3,inputFormatter:[v.inputAddressFormatter,c.numberToHex,v.inputDefaultBlockNumberFormatter]}),new s({name:"getCode",call:"eth_getCode",params:2,inputFormatter:[v.inputAddressFormatter,v.inputDefaultBlockNumberFormatter]}),new s({name:"getBlock",call:b,params:2,inputFormatter:[v.inputBlockNumberFormatter,function(e){return!!e}],outputFormatter:v.outputBlockFormatter}),new s({name:"getUncle",call:g,params:2,inputFormatter:[v.inputBlockNumberFormatter,c.numberToHex],outputFormatter:v.outputBlockFormatter}),new s({name:"getBlockTransactionCount",call:_,params:1,inputFormatter:[v.inputBlockNumberFormatter],outputFormatter:c.hexToNumber}),new s({name:"getBlockUncleCount",call:x,params:1,inputFormatter:[v.inputBlockNumberFormatter],outputFormatter:c.hexToNumber}),new s({name:"getTransaction",call:"eth_getTransactionByHash",params:1,inputFormatter:[null],outputFormatter:v.outputTransactionFormatter}),new s({name:"getTransactionFromBlock",call:y,params:2,inputFormatter:[v.inputBlockNumberFormatter,c.numberToHex],outputFormatter:v.outputTransactionFormatter}),new s({name:"getTransactionReceipt",call:"eth_getTransactionReceipt",params:1,inputFormatter:[null],outputFormatter:v.outputTransactionReceiptFormatter}),new s({name:"getTransactionCount",call:"eth_getTransactionCount",params:2,inputFormatter:[v.inputAddressFormatter,v.inputDefaultBlockNumberFormatter],outputFormatter:c.hexToNumber}),new s({name:"sendSignedTransaction",call:"eth_sendRawTransaction",params:1,inputFormatter:[null]}),new s({name:"signTransaction",call:"eth_signTransaction",params:1,inputFormatter:[v.inputTransactionFormatter]}),new s({name:"sendTransaction",call:"eth_sendTransaction",params:1,inputFormatter:[v.inputTransactionFormatter]}),new s({name:"sign",call:"eth_sign",params:2,inputFormatter:[v.inputSignFormatter,v.inputAddressFormatter],transformPayload:function(e){return e.params.reverse(),e}}),new s({name:"call",call:"eth_call",params:2,inputFormatter:[v.inputCallFormatter,v.inputDefaultBlockNumberFormatter]}),new s({name:"estimateGas",call:"eth_estimateGas",params:1,inputFormatter:[v.inputCallFormatter],outputFormatter:c.hexToNumber}),new s({name:"getCompilers",call:"eth_getCompilers",params:0}),new s({name:"compile.solidity",call:"eth_compileSolidity",params:1}),new s({name:"compile.lll",call:"eth_compileLLL",params:1}),new s({name:"compile.serpent",call:"eth_compileSerpent",params:1}),new s({name:"submitWork",call:"eth_submitWork",params:3}),new s({name:"getWork",call:"eth_getWork",params:0}),new s({name:"getPastLogs",call:"eth_getLogs",params:1,inputFormatter:[v.inputLogFormatter],outputFormatter:v.outputLogFormatter}),new a({name:"subscribe",type:"eth",subscriptions:{newBlockHeaders:{subscriptionName:"newHeads",params:0,outputFormatter:v.outputBlockFormatter},pendingTransactions:{subscriptionName:"newPendingTransactions",params:0},logs:{params:1,inputFormatter:[v.inputLogFormatter],outputFormatter:v.outputLogFormatter,subscriptionHandler:function(e){e.removed?this.emit("changed",e):this.emit("data",e),i.isFunction(this.callback)&&this.callback(null,e,this)}},syncing:{params:0,outputFormatter:v.outputSyncingFormatter,subscriptionHandler:function(e){var t=this;!0!==this._isSyncing?(this._isSyncing=!0,this.emit("changed",t._isSyncing),i.isFunction(this.callback)&&this.callback(null,t._isSyncing,this),setTimeout(function(){t.emit("data",e),i.isFunction(t.callback)&&t.callback(null,e,t)},0)):(this.emit("data",e),i.isFunction(t.callback)&&this.callback(null,e,this),clearTimeout(this._isSyncingTimeout),this._isSyncingTimeout=setTimeout(function(){e.currentBlock>e.highestBlock-200&&(t._isSyncing=!1,t.emit("changed",t._isSyncing),i.isFunction(t.callback)&&t.callback(null,t._isSyncing,t))},500))}}}})];w.forEach(function(t){t.attachToObject(e),t.setRequestManager(e._requestManager,e.accounts),t.defaultBlock=e.defaultBlock,t.defaultAccount=e.defaultAccount})};r.addProviders(w),t.exports=w},{"./getNetworkType.js":252,underscore:251,"web3-core":202,"web3-core-helpers":186,"web3-core-method":188,"web3-core-subscriptions":199,"web3-eth-abi":205,"web3-eth-accounts":246,"web3-eth-contract":248,"web3-eth-iban":249,"web3-eth-personal":250,"web3-net":254,"web3-utils":273}],254:[function(e,t,n){var i=e("web3-core"),r=e("web3-core-method"),o=e("web3-utils"),a=function(){var e=this;i.packageInit(this,arguments),[new r({name:"getId",call:"net_version",params:0,outputFormatter:o.hexToNumber}),new r({name:"isListening",call:"net_listening",params:0}),new r({name:"getPeerCount",call:"net_peerCount",params:0,outputFormatter:o.hexToNumber})].forEach(function(t){t.attachToObject(e),t.setRequestManager(e._requestManager)})};i.addProviders(a),t.exports=a},{"web3-core":202,"web3-core-method":188,"web3-utils":273}],255:[function(e,t,n){t.exports=XMLHttpRequest},{}],256:[function(e,t,n){var i=e("web3-core-helpers").errors,r=e("xhr2"),o=function(e,t){this.host=e||"http://localhost:8545",this.timeout=t||0,this.connected=!1};o.prototype.send=function(e,t){var n=this,o=new r;o.open("POST",this.host,!0),o.setRequestHeader("Content-Type","application/json"),o.onreadystatechange=function(){if(4===o.readyState&&1!==o.timeout){var e=o.responseText,r=null;try{e=JSON.parse(e)}catch(e){r=i.InvalidResponse(o.responseText)}n.connected=!0,t(r,e)}},o.ontimeout=function(){n.connected=!1,t(i.ConnectionTimeout(this.timeout))};try{o.send(JSON.stringify(e))}catch(e){this.connected=!1,t(i.InvalidConnection(this.host))}},t.exports=o},{"web3-core-helpers":186,xhr2:255}],257:[function(e,t,n){!function(e,i,r,o,a,s){function c(e,t){return function(){return e.call(this,t.apply(this,arguments))}}function u(e){return function(t){return t[e]}}function l(e,t){return t.apply(s,e)}function f(e){var t=e.length-1,n=r.prototype.slice;if(0==t)return function(){return e.call(this,n.call(arguments))};if(1==t)return function(){return e.call(this,arguments[0],n.call(arguments,1))};var i=r(e.length);return function(){for(var r=0;rd&&(n("Max buffer length exceeded: textNode"),e=Math.max(e,D.length)),L.length>d&&(n("Max buffer length exceeded: numberNode"),e=Math.max(e,L.length)),N=d-e+G}function n(e){D!==s&&(l(D),f(),D=s),r=o(e+"\nLn: "+J+"\nCol: "+$+"\nChr: "+a),p(z(s,s,r))}function i(e){return"\r"==e||"\n"==e||" "==e||"\t"==e}var r,a,c,u=e(ye).emit,l=e(ge).emit,f=e(_e).emit,p=e(fe).emit,d=65536,h=/[\\"\n]/g,m=0,v=m++,b=m++,y=m++,g=m++,_=m++,x=m++,w=m++,k=m++,j=m++,S=m++,E=m++,A=m++,C=m++,M=m++,T=m++,P=m++,F=m++,I=m++,B=m++,R=m++,O=m,N=d,D=s,L="",q=!1,U=!1,H=v,V=[],K=null,W=0,X=0,G=0,$=0,J=1;e(me).on(function(e){if(!r){if(U)return n("Cannot write after close");var o=0;for(a=e[0];a&&(c=a,a=e[o++]);)switch(G++,"\n"==a?(J++,$=0):$++,H){case v:if("{"===a)H=y;else if("["===a)H=_;else if(!i(a))return n("Non-whitespace before {[.");continue;case k:case y:if(i(a))continue;if(H===k)V.push(j);else{if("}"===a){l({}),f(),H=V.pop()||b;continue}V.push(g)}if('"'!==a)return n('Malformed object key should start with " ');H=w;continue;case j:case g:if(i(a))continue;if(":"===a)H===g?(V.push(g),D!==s&&(l({}),u(D),D=s),X++):D!==s&&(u(D),D=s),H=b;else if("}"===a)D!==s&&(l(D),f(),D=s),f(),X--,H=V.pop()||b;else{if(","!==a)return n("Bad object");H===g&&V.push(g),D!==s&&(l(D),f(),D=s),H=k}continue;case _:case b:if(i(a))continue;if(H===_){if(l([]),X++,H=b,"]"===a){f(),X--,H=V.pop()||b;continue}V.push(x)}if('"'===a)H=w;else if("{"===a)H=y;else if("["===a)H=_;else if("t"===a)H=S;else if("f"===a)H=C;else if("n"===a)H=F;else if("-"===a)L+=a;else if("0"===a)L+=a,H=O;else{if(-1==="123456789".indexOf(a))return n("Bad value");L+=a,H=O}continue;case x:if(","===a)V.push(x),D!==s&&(l(D),f(),D=s),H=b;else{if("]"!==a){if(i(a))continue;return n("Bad array")}D!==s&&(l(D),f(),D=s),f(),X--,H=V.pop()||b}continue;case w:D===s&&(D="");var p=o-1;e:for(;;){for(;W>0;)if(K+=a,a=e.charAt(o++),4===W?(D+=String.fromCharCode(parseInt(K,16)),W=0,p=o-1):W++,!a)break e;if('"'===a&&!q){H=V.pop()||b,D+=e.substring(p,o-1);break}if(!("\\"!==a||q||(q=!0,D+=e.substring(p,o-1),a=e.charAt(o++))))break;if(q){if(q=!1,"n"===a?D+="\n":"r"===a?D+="\r":"t"===a?D+="\t":"f"===a?D+="\f":"b"===a?D+="\b":"u"===a?(W=1,K=""):D+=a,a=e.charAt(o++),p=o-1,a)continue;break}h.lastIndex=o;var d=h.exec(e);if(!d){o=e.length+1,D+=e.substring(p,o-1);break}if(o=d.index+1,!(a=e.charAt(d.index))){D+=e.substring(p,o-1);break}}continue;case S:if(!a)continue;if("r"!==a)return n("Invalid true started with t"+a);H=E;continue;case E:if(!a)continue;if("u"!==a)return n("Invalid true started with tr"+a);H=A;continue;case A:if(!a)continue;if("e"!==a)return n("Invalid true started with tru"+a);l(!0),f(),H=V.pop()||b;continue;case C:if(!a)continue;if("a"!==a)return n("Invalid false started with f"+a);H=M;continue;case M:if(!a)continue;if("l"!==a)return n("Invalid false started with fa"+a);H=T;continue;case T:if(!a)continue;if("s"!==a)return n("Invalid false started with fal"+a);H=P;continue;case P:if(!a)continue;if("e"!==a)return n("Invalid false started with fals"+a);l(!1),f(),H=V.pop()||b;continue;case F:if(!a)continue;if("u"!==a)return n("Invalid null started with n"+a);H=I;continue;case I:if(!a)continue;if("l"!==a)return n("Invalid null started with nu"+a);H=B;continue;case B:if(!a)continue;if("l"!==a)return n("Invalid null started with nul"+a);l(null),f(),H=V.pop()||b;continue;case R:if("."!==a)return n("Leading zero not followed by .");L+=a,H=O;continue;case O:if(-1!=="0123456789".indexOf(a))L+=a;else if("."===a){if(-1!==L.indexOf("."))return n("Invalid number has two dots");L+=a}else if("e"===a||"E"===a){if(-1!==L.indexOf("e")||-1!==L.indexOf("E"))return n("Invalid number has two exponential");L+=a}else if("+"===a||"-"===a){if("e"!==c&&"E"!==c)return n("Invalid symbol in number");L+=a}else L&&(l(parseFloat(L)),f(),L=""),o--,H=V.pop()||b;continue;default:return n("Unknown state: "+H)}G>=N&&t()}}),e(ve).on(function(){if(H==v)return l({}),f(),void(U=!0);H===b&&0===X||n("Unexpected end"),D!==s&&(l(D),f(),D=s),U=!0})}function P(e,t){var n,i={};for(var r in t)e(r).on(function(e){return function(t){n=e(n,t)}}(t[r]),i);e(ue).on(function(e){var t=Y(n),i=ne(t),r=Z(n);r&&(ie(Y(r))[i]=e)}),e(le).on(function(){var e=Y(n),t=ne(e),i=Z(n);i&&delete ie(Y(i))[t]}),e(be).on(function(){for(var n in t)e(n).un(i)})}function F(e){var t={};return e&&e.split("\r\n").forEach(function(e){var n=e.indexOf(": ");t[e.substring(0,n)]=e.substring(n+2)}),t}function I(e,t){function n(e){return{"http:":80,"https:":443}[e]}function i(t){return t.port||n(t.protocol||e.protocol)}return!!(t.protocol&&t.protocol!=e.protocol||t.host&&t.host!=e.host||t.host&&i(t)!=i(e))}function B(e){var t=/(\w+:)?(?:\/\/)([\w.-]+)?(?::(\d+))?\/?/.exec(e)||[];return{protocol:t[1]||"",host:t[2]||"",port:t[3]||""}}function R(){return new XMLHttpRequest}function O(t,n,i,r,o,a,c){function u(){var e=n.responseText,t=e.substr(p);t&&l(t),p=$(e)}var l=t(me).emit,f=t(fe).emit,p=0,d=!0;t(be).on(function(){n.onreadystatechange=null,n.abort()}),"onprogress"in n&&(n.onprogress=u),n.onreadystatechange=function(){function e(){try{d&&t(he).emit(n.status,F(n.getAllResponseHeaders())),d=!1}catch(e){}}switch(n.readyState){case 2:case 3:return e();case 4:e(),2==String(n.status)[0]?(u(),t(ve).emit()):f(z(n.status,n.responseText))}};try{n.open(i,r,!0);for(var h in a)n.setRequestHeader(h,a[h]);I(e.location,B(r))||n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.withCredentials=c,n.send(o)}catch(t){e.setTimeout(X(f,z(s,s,t)),0)}}function N(e,t){return{key:e,node:t}}function D(e){function t(e,t){var n=ie(Y(e));return b(r,n)?i(e,$(n),t):e}function n(e,t,n){ie(Y(e))[t]=n}function i(e,t,i){e&&n(e,t,i);var r=_(N(t,i),e);return o(r),r}var o=e(se).emit,a=e(ce).emit,s=e(de).emit,c=e(pe).emit,u={};return u[ge]=function(e,r){if(!e)return s(r),i(e,re,r);var o=t(e,r),a=Z(o),c=ne(Y(o));return n(a,c,r),_(N(c,r),a)},u[_e]=function(e){return a(e),Z(e)||c(ie(Y(e)))},u[ye]=i,u}function L(e,t,n){function i(e){return function(t){return t.id==e}}var r,o;return{on:function(n,i){var a={listener:n,id:i||n};return t&&t.emit(e,n,a.id),r=_(a,r),o=_(n,o),this},emit:function(){A(o,arguments)},un:function(t){var a;r=S(r,i(t),function(e){a=e}),a&&(o=S(o,function(e){return e==a.listener}),n&&n.emit(e,a.listener,a.id))},listeners:function(){return o},hasListener:function(e){return y(M(e?i(e):m,r))}}}function q(){function e(e){return n[e]=L(e,i,r)}function t(t){return n[t]||e(t)}var n={},i=e("newListener"),r=e("removeListener");return["emit","on","un"].forEach(function(e){t[e]=f(function(n,i){l(i,t(n)[e])})}),t}function z(e,t,n){try{var i=a.parse(t)}catch(e){}return{statusCode:e,body:t,jsonBody:i,thrown:n}}function U(e,t){function n(e,t,n){var i=C(n);e(t,w(Z(k(ne,i))),w(k(ie,i)))}function i(t,i,r){var o=e(t).emit;i.on(function(e){var t=r(e);!1!==t&&n(o,ie(t),e)},t),e("removeListener").on(function(n){n==t&&(e(n).listeners()||i.un(t))})}var r={node:e(ce),path:e(se)};e("newListener").on(function(e){var n=/(node|path):(.*)/.exec(e);if(n){var o=r[n[1]];o.hasListener(e)||i(e,o,t(n[2]))}})}function H(e,t){function n(e,t,n){n=n||t;var r=i(t);return e.on(function(){var t=!1;u.forget=function(){t=!0},l(arguments,r),delete u.forget,t&&e.un(n)},n),u}function i(e){return function(){try{return e.apply(u,arguments)}catch(e){setTimeout(function(){throw e})}}}function r(t,n){return e(t+":"+n)}function o(e){return function(){var t=e.apply(this,arguments);y(t)&&(t==W.drop?m():b(t))}}function a(e,t,i){var a;a="node"==e?o(i):i,n(r(e,t),a,i)}function s(e,t){for(var n in t)a(e,n,t[n])}function c(e,t,n){return J(t)?a(e,t,n):s(e,t),u}var u,p=/^(node|path):./,d=e(pe),m=e(le).emit,b=e(ue).emit,g=f(function(t,i){if(u[t])l(i,u[t]);else{var r=e(t),o=i[0];p.test(t)?n(r,o):r.on(o)}return u});return e(de).on(function(e){u.root=v(e)}),e(he).on(function(e,t){u.header=function(e){return e?t[e]:t}}),u={on:g,addListener:g,removeListener:function(t,n,i){if("done"==t)d.un(n);else if("node"==t||"path"==t)e.un(t+":"+n,i);else{var r=n;e(t).un(r)}return u},emit:e.emit,node:X(c,"node"),path:X(c,"path"),done:X(n,d),start:X(function(t,n){return e(t).on(i(n),n),u},he),fail:e(fe).on,abort:e(be).emit,header:h,root:h,source:t}}function V(e,t,n,i,r){var o=q();return t&&O(o,R(),e,t,n,i,r),T(o),P(o,D(o)),U(o,oe),H(o,t)}function K(e,t,n,i,r,o,s){return r=r?a.parse(a.stringify(r)):{},i?J(i)||(i=a.stringify(i),r["Content-Type"]=r["Content-Type"]||"application/json"):i=null,e(n||"GET",function(e,t){return!1===t&&(-1==e.indexOf("?")?e+="?":e+="&",e+="_="+(new Date).getTime()),e}(t,s),i,r,o||!1)}function W(e){var t=ee("resume","pause","pipe"),n=X(g,t);return e?n(e)||J(e)?K(V,e):K(V,e.url,e.method,e.body,e.headers,e.withCredentials,e.cached):V()}var X=f(function(e,t){var n=t.length;return f(function(i){for(var r=0;r2)throw new Error("[ethjs-unit] while converting number "+e+" to wei, too many decimal points");var p=f[0],d=f[1];if(p||(p="0"),d||(d="0"),d.length>s)throw new Error("[ethjs-unit] while converting number "+e+" to wei, too many decimal places");for(;d.length65536){if(!r)throw new Error("Requested too many random bytes.");n(new Error("Requested too many random bytes."))}if(void 0!==i&&i.randomBytes){if(!r)return"0x"+i.randomBytes(t).toString("hex");i.randomBytes(t,function(e,t){e?n(c):n(null,"0x"+t.toString("hex"))})}else{var o;if(void 0!==i?o=i:"undefined"!=typeof msCrypto&&(o=msCrypto),o&&o.getRandomValues){var a=o.getRandomValues(new Uint8Array(t)),s="0x"+Array.from(a).map(function(e){return e.toString(16)}).join("");if(!r)return s;n(null,s)}else{var c=new Error('No "crypto" object available. This Browser doesn\'t support generating secure random bytes.');if(!r)throw c;n(c)}}}},{"./crypto.js":268}],270:[function(e,t,n){var i=e("is-hex-prefixed");t.exports=function(e){return"string"!=typeof e?e:i(e)?e.slice(2):e}},{"is-hex-prefixed":265}],271:[function(e,t,n){arguments[4][172][0].apply(n,arguments)},{dup:172}],272:[function(e,t,n){(function(e){!function(i){function r(e){for(var t,n,i=[],r=0,o=e.length;r=55296&&t<=56319&&r65535&&(r+=b((t-=65536)>>>10&1023|55296),t=56320|1023&t),r+=b(t);return r}function a(e){if(e>=55296&&e<=57343)throw Error("Lone surrogate U+"+e.toString(16).toUpperCase()+" is not a scalar value")}function s(e,t){return b(e>>t&63|128)}function c(e){if(0==(4294967168&e))return b(e);var t="";return 0==(4294965248&e)?t=b(e>>6&31|192):0==(4294901760&e)?(a(e),t=b(e>>12&15|224),t+=s(e,6)):0==(4292870144&e)&&(t=b(e>>18&7|240),t+=s(e,12),t+=s(e,6)),t+=b(63&e|128)}function u(){if(v>=m)throw Error("Invalid byte index");var e=255&h[v];if(v++,128==(192&e))return 63&e;throw Error("Invalid continuation byte")}function l(){var e,t,n,i,r;if(v>m)throw Error("Invalid byte index");if(v==m)return!1;if(e=255&h[v],v++,0==(128&e))return e;if(192==(224&e)){if((r=(31&e)<<6|(t=u()))>=128)return r;throw Error("Invalid continuation byte")}if(224==(240&e)){if(t=u(),n=u(),(r=(15&e)<<12|t<<6|n)>=2048)return a(r),r;throw Error("Invalid continuation byte")}if(240==(248&e)&&(t=u(),n=u(),i=u(),(r=(15&e)<<18|t<<12|n<<6|i)>=65536&&r<=1114111))return r;throw Error("Invalid UTF-8 detected")}var f="object"==(void 0===n?"undefined":_typeof(n))&&n,p="object"==(void 0===t?"undefined":_typeof(t))&&t&&t.exports==f&&t,d="object"==(void 0===e?"undefined":_typeof(e))&&e;d.global!==d&&d.window!==d||(i=d);var h,m,v,b=String.fromCharCode,y={version:"2.0.0",encode:function(e){for(var t=r(e),n=t.length,i=-1,o="";++i7?n+=e[i].toUpperCase():n+=e[i];return n},toHex:o.toHex,toBN:o.toBN,bytesToHex:o.bytesToHex,hexToBytes:o.hexToBytes,hexToNumberString:o.hexToNumberString,hexToNumber:o.hexToNumber,toDecimal:o.hexToNumber,numberToHex:o.numberToHex,fromDecimal:o.numberToHex,hexToUtf8:o.hexToUtf8,hexToString:o.hexToUtf8,toUtf8:o.hexToUtf8,utf8ToHex:o.utf8ToHex,stringToHex:o.utf8ToHex,fromUtf8:o.utf8ToHex,hexToAscii:c,toAscii:c,asciiToHex:u,fromAscii:u,unitMap:r.unitMap,toWei:function(e,t){return t=l(t),o.isBN(e)?r.toWei(e,t):r.toWei(e,t).toString(10)},fromWei:function(e,t){return t=l(t),o.isBN(e)?r.fromWei(e,t):r.fromWei(e,t).toString(10)},padLeft:o.leftPad,leftPad:o.leftPad,padRight:o.rightPad,rightPad:o.rightPad,toTwosComplement:o.toTwosComplement}},{"./soliditySha3.js":274,"./utils.js":275,"ethjs-unit":264,randomhex:269,underscore:271}],274:[function(e,t,n){var i=e("underscore"),r=e("bn.js"),o=e("./utils.js"),a=function(e){return e.startsWith("int[")?"int256"+e.slice(3):"int"===e?"int256":e.startsWith("uint[")?"uint256"+e.slice(4):"uint"===e?"uint256":e.startsWith("fixed[")?"fixed128x128"+e.slice(5):"fixed"===e?"fixed128x128":e.startsWith("ufixed[")?"ufixed128x128"+e.slice(6):"ufixed"===e?"ufixed128x128":e},s=function(e){var t=/^\D+(\d+).*$/.exec(e);return t?parseInt(t[1],10):null},c=function(e){var t=/^\D+\d*\[(\d+)\]$/.exec(e);return t?parseInt(t[1],10):null},u=function(e){var t=void 0===e?"undefined":_typeof(e);if("string"===t)return o.isHex(e)?new r(e.replace(/0x/i,""),16):new r(e,10);if("number"===t)return new r(e);if(o.isBigNumber(e))return new r(e.toString(10));if(o.isBN(e))return e;throw new Error(e+" is not a number")},l=function(e,t,n){var i,c;if("bytes"===(e=a(e))){if(t.replace(/^0x/i,"").length%2!=0)throw new Error("Invalid bytes characters "+t.length);return t}if("string"===e)return o.utf8ToHex(t);if("bool"===e)return t?"01":"00";if(e.startsWith("address")){if(i=n?64:40,!o.isAddress(t))throw new Error(t+" is not a valid address, or the checksum is invalid.");return o.leftPad(t.toLowerCase(),i)}if(i=s(e),e.startsWith("bytes")){if(!i)throw new Error("bytes[] not yet supported in solidity");if(n&&(i=32),i<1||i>32||i256)throw new Error("Invalid uint"+i+" size");if((c=u(t)).bitLength()>i)throw new Error("Supplied uint exceeds width: "+i+" vs "+c.bitLength());if(c.lt(new r(0)))throw new Error("Supplied uint "+c.toString()+" is negative");return i?o.leftPad(c.toString("hex"),i/8*2):c}if(e.startsWith("int")){if(i%8||i<8||i>256)throw new Error("Invalid int"+i+" size");if((c=u(t)).bitLength()>i)throw new Error("Supplied int exceeds width: "+i+" vs "+c.bitLength());return c.lt(new r(0))?c.toTwos(i).toString("hex"):i?o.leftPad(c.toString("hex"),i/8*2):c}throw new Error("Unsupported or invalid type: "+e)},f=function(e){if(i.isArray(e))throw new Error("Autodetection of array types is not supported.");var t,n,a="";if(i.isObject(e)&&(e.hasOwnProperty("v")||e.hasOwnProperty("t")||e.hasOwnProperty("value")||e.hasOwnProperty("type"))?(t=e.t||e.type,a=e.v||e.value):(t=o.toHex(e,!0),a=o.toHex(e),t.startsWith("int")||t.startsWith("uint")||(t="bytes")),!t.startsWith("int")&&!t.startsWith("uint")||"string"!=typeof a||/^(-)?0x/i.test(a)||(a=new r(a)),i.isArray(a)){if((n=c(t))&&a.length!==n)throw new Error(t+" is not matching the given array "+JSON.stringify(a));n=a.length}return i.isArray(a)?a.map(function(e){return l(t,e,n).toString("hex").replace("0x","")}).join(""):l(t,a,n).toString("hex").replace("0x","")};t.exports=function(){var e=Array.prototype.slice.call(arguments),t=i.map(e,f);return o.sha3("0x"+t.join(""))}},{"./utils.js":275,"bn.js":"BN",underscore:271}],275:[function(e,t,n){var i=e("underscore"),r=e("bn.js"),o=e("number-to-bn"),a=e("utf8"),s=e("eth-lib/lib/hash"),c=function(e){return e instanceof r||e&&e.constructor&&"BN"===e.constructor.name},u=function(e){return e&&e.constructor&&"BigNumber"===e.constructor.name},l=function(e){try{return o.apply(null,arguments)}catch(t){throw new Error(t+' Given value: "'+e+'"')}},f=function(e){return!!/^(0x)?[0-9a-f]{40}$/i.test(e)&&(!(!/^(0x|0X)?[0-9a-f]{40}$/.test(e)&&!/^(0x|0X)?[0-9A-F]{40}$/.test(e))||p(e))},p=function(e){e=e.replace(/^0x/i,"");for(var t=b(e.toLowerCase()).replace(/^0x/i,""),n=0;n<40;n++)if(parseInt(t[n],16)>7&&e[n].toUpperCase()!==e[n]||parseInt(t[n],16)<=7&&e[n].toLowerCase()!==e[n])return!1;return!0},d=function(e){var t="";e=(e=(e=(e=(e=a.encode(e)).replace(/^(?:\u0000)*/,"")).split("").reverse().join("")).replace(/^(?:\u0000)*/,"")).split("").reverse().join("");for(var n=0;n>>4).toString(16)),t.push((15&e[n]).toString(16));return"0x"+t.join("")},isHex:v,leftPad:function(e,t,n){var i=/^0x/i.test(e)||"number"==typeof e,r=t-(e=e.toString(16).replace(/^0x/i,"")).length+1>=0?t-e.length+1:0;return(i?"0x":"")+new Array(r).join(n||"0")+e},rightPad:function(e,t,n){var i=/^0x/i.test(e)||"number"==typeof e,r=t-(e=e.toString(16).replace(/^0x/i,"")).length+1>=0?t-e.length+1:0;return(i?"0x":"")+e+new Array(r).join(n||"0")},toTwosComplement:function(e){return"0x"+l(e).toTwos(256).toString(16,64)},sha3:b}},{"bn.js":"BN","eth-lib/lib/hash":263,"number-to-bn":266,underscore:271,utf8:272}],276:[function(e,t,n){t.exports={name:"web3",namespace:"ethereum",version:"1.0.0-beta.22",description:"Ethereum JavaScript API",repository:"https://github.com/ethereum/web3.js/tree/master/packages/web3",license:"LGPL-3.0",main:"src/index.js",bugs:{url:"https://github.com/ethereum/web3.js/issues"},keywords:["Ethereum","JavaScript","API"],author:"ethereum.org",authors:[{name:"Fabian Vogelsteller",email:"fabian@ethereum.org",homepage:"http://frozeman.de"},{name:"Marek Kotewicz",email:"marek@parity.io",url:"https://github.com/debris"},{name:"Marian Oancea",url:"https://github.com/cubedro"},{name:"Gav Wood",email:"g@parity.io",homepage:"http://gavwood.com"},{name:"Jeffery Wilcke",email:"jeffrey.wilcke@ethereum.org",url:"https://github.com/obscuren"}],dependencies:{"web3-bzz":"^1.0.0-beta.22","web3-core":"^1.0.0-beta.22","web3-eth":"^1.0.0-beta.22","web3-eth-personal":"^1.0.0-beta.22","web3-net":"^1.0.0-beta.22","web3-shh":"^1.0.0-beta.22","web3-utils":"^1.0.0-beta.22"}}},{}],BN:[function(e,t,n){!function(t,n){function i(e,t){if(!e)throw new Error(t||"Assertion failed")}function r(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}function o(e,t,n){if(o.isBN(e))return e;this.negative=0,this.words=null,this.length=0,this.red=null,null!==e&&("le"!==t&&"be"!==t||(n=t,t=10),this._init(e||0,t||10,n||"be"))}function a(e,t,n){for(var i=0,r=Math.min(e.length,n),o=t;o=49&&a<=54?a-49+10:a>=17&&a<=22?a-17+10:15&a}return i}function s(e,t,n,i){for(var r=0,o=Math.min(e.length,n),a=t;a=49?s-49+10:s>=17?s-17+10:s}return r}function c(e){for(var t=new Array(e.bitLength()),n=0;n>>r}return t}function u(e,t,n){n.negative=t.negative^e.negative;var i=e.length+t.length|0;n.length=i,i=i-1|0;var r=0|e.words[0],o=0|t.words[0],a=r*o,s=67108863&a,c=a/67108864|0;n.words[0]=s;for(var u=1;u>>26,f=67108863&c,p=Math.min(u,t.length-1),d=Math.max(0,u-e.length+1);d<=p;d++){var h=u-d|0;l+=(a=(r=0|e.words[h])*(o=0|t.words[d])+f)/67108864|0,f=67108863&a}n.words[u]=0|f,c=0|l}return 0!==c?n.words[u]=0|c:n.length--,n.strip()}function l(e,t,n){n.negative=t.negative^e.negative,n.length=e.length+t.length;for(var i=0,r=0,o=0;o>>26)|0)>>>26,a&=67108863}n.words[o]=s,i=a,a=r}return 0!==i?n.words[o]=i:n.length--,n.strip()}function f(e,t,n){return(new p).mulp(e,t,n)}function p(e,t){this.x=e,this.y=t}function d(e,t){this.name=e,this.p=new o(t,16),this.n=this.p.bitLength(),this.k=new o(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function h(){d.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function m(){d.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function v(){d.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function b(){d.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function y(e){if("string"==typeof e){var t=o._prime(e);this.m=t.p,this.prime=t}else i(e.gtn(1),"modulus must be greater than 1"),this.m=e,this.prime=null}function g(e){y.call(this,e),this.shift=this.m.bitLength(),this.shift%26!=0&&(this.shift+=26-this.shift%26),this.r=new o(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}"object"===(void 0===t?"undefined":_typeof(t))?t.exports=o:n.BN=o,o.BN=o,o.wordSize=26;var _;try{_=e("buffer").Buffer}catch(e){}o.isBN=function(e){return e instanceof o||null!==e&&"object"===(void 0===e?"undefined":_typeof(e))&&e.constructor.wordSize===o.wordSize&&Array.isArray(e.words)},o.max=function(e,t){return e.cmp(t)>0?e:t},o.min=function(e,t){return e.cmp(t)<0?e:t},o.prototype._init=function(e,t,n){if("number"==typeof e)return this._initNumber(e,t,n);if("object"===(void 0===e?"undefined":_typeof(e)))return this._initArray(e,t,n);"hex"===t&&(t=16),i(t===(0|t)&&t>=2&&t<=36);var r=0;"-"===(e=e.toString().replace(/\s+/g,""))[0]&&r++,16===t?this._parseHex(e,r):this._parseBase(e,t,r),"-"===e[0]&&(this.negative=1),this.strip(),"le"===n&&this._initArray(this.toArray(),t,n)},o.prototype._initNumber=function(e,t,n){e<0&&(this.negative=1,e=-e),e<67108864?(this.words=[67108863&e],this.length=1):e<4503599627370496?(this.words=[67108863&e,e/67108864&67108863],this.length=2):(i(e<9007199254740992),this.words=[67108863&e,e/67108864&67108863,1],this.length=3),"le"===n&&this._initArray(this.toArray(),t,n)},o.prototype._initArray=function(e,t,n){if(i("number"==typeof e.length),e.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(e.length/3),this.words=new Array(this.length);for(var r=0;r=0;r-=3)a=e[r]|e[r-1]<<8|e[r-2]<<16,this.words[o]|=a<>>26-s&67108863,(s+=24)>=26&&(s-=26,o++);else if("le"===n)for(r=0,o=0;r>>26-s&67108863,(s+=24)>=26&&(s-=26,o++);return this.strip()},o.prototype._parseHex=function(e,t){this.length=Math.ceil((e.length-t)/6),this.words=new Array(this.length);for(var n=0;n=t;n-=6)r=a(e,n,n+6),this.words[i]|=r<>>26-o&4194303,(o+=24)>=26&&(o-=26,i++);n+6!==t&&(r=a(e,t,n+6),this.words[i]|=r<>>26-o&4194303),this.strip()},o.prototype._parseBase=function(e,t,n){this.words=[0],this.length=1;for(var i=0,r=1;r<=67108863;r*=t)i++;i--,r=r/t|0;for(var o=e.length-n,a=o%i,c=Math.min(o,o-a)+n,u=0,l=n;l1&&0===this.words[this.length-1];)this.length--;return this._normSign()},o.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},o.prototype.inspect=function(){return(this.red?""};var x=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],w=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],k=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];o.prototype.toString=function(e,t){e=e||10,t=0|t||1;var n;if(16===e||"hex"===e){n="";for(var r=0,o=0,a=0;a>>24-r&16777215)||a!==this.length-1?x[6-c.length]+c+n:c+n,(r+=2)>=26&&(r-=26,a--)}for(0!==o&&(n=o.toString(16)+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}if(e===(0|e)&&e>=2&&e<=36){var u=w[e],l=k[e];n="";var f=this.clone();for(f.negative=0;!f.isZero();){var p=f.modn(l).toString(e);n=(f=f.idivn(l)).isZero()?p+n:x[u-p.length]+p+n}for(this.isZero()&&(n="0"+n);n.length%t!=0;)n="0"+n;return 0!==this.negative&&(n="-"+n),n}i(!1,"Base should be between 2 and 36")},o.prototype.toNumber=function(){var e=this.words[0];return 2===this.length?e+=67108864*this.words[1]:3===this.length&&1===this.words[2]?e+=4503599627370496+67108864*this.words[1]:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-e:e},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(e,t){return i(void 0!==_),this.toArrayLike(_,e,t)},o.prototype.toArray=function(e,t){return this.toArrayLike(Array,e,t)},o.prototype.toArrayLike=function(e,t,n){var r=this.byteLength(),o=n||Math.max(1,r);i(r<=o,"byte array longer than desired length"),i(o>0,"Requested array length <= 0"),this.strip();var a,s,c="le"===t,u=new e(o),l=this.clone();if(c){for(s=0;!l.isZero();s++)a=l.andln(255),l.iushrn(8),u[s]=a;for(;s=4096&&(n+=13,t>>>=13),t>=64&&(n+=7,t>>>=7),t>=8&&(n+=4,t>>>=4),t>=2&&(n+=2,t>>>=2),n+t},o.prototype._zeroBits=function(e){if(0===e)return 26;var t=e,n=0;return 0==(8191&t)&&(n+=13,t>>>=13),0==(127&t)&&(n+=7,t>>>=7),0==(15&t)&&(n+=4,t>>>=4),0==(3&t)&&(n+=2,t>>>=2),0==(1&t)&&n++,n},o.prototype.bitLength=function(){var e=this.words[this.length-1],t=this._countBits(e);return 26*(this.length-1)+t},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var e=0,t=0;te.length?this.clone().ior(e):e.clone().ior(this)},o.prototype.uor=function(e){return this.length>e.length?this.clone().iuor(e):e.clone().iuor(this)},o.prototype.iuand=function(e){var t;t=this.length>e.length?e:this;for(var n=0;ne.length?this.clone().iand(e):e.clone().iand(this)},o.prototype.uand=function(e){return this.length>e.length?this.clone().iuand(e):e.clone().iuand(this)},o.prototype.iuxor=function(e){var t,n;this.length>e.length?(t=this,n=e):(t=e,n=this);for(var i=0;ie.length?this.clone().ixor(e):e.clone().ixor(this)},o.prototype.uxor=function(e){return this.length>e.length?this.clone().iuxor(e):e.clone().iuxor(this)},o.prototype.inotn=function(e){i("number"==typeof e&&e>=0);var t=0|Math.ceil(e/26),n=e%26;this._expand(t),n>0&&t--;for(var r=0;r0&&(this.words[r]=~this.words[r]&67108863>>26-n),this.strip()},o.prototype.notn=function(e){return this.clone().inotn(e)},o.prototype.setn=function(e,t){i("number"==typeof e&&e>=0);var n=e/26|0,r=e%26;return this._expand(n+1),this.words[n]=t?this.words[n]|1<e.length?(n=this,i=e):(n=e,i=this);for(var r=0,o=0;o>>26;for(;0!==r&&o>>26;if(this.length=n.length,0!==r)this.words[this.length]=r,this.length++;else if(n!==this)for(;oe.length?this.clone().iadd(e):e.clone().iadd(this)},o.prototype.isub=function(e){if(0!==e.negative){e.negative=0;var t=this.iadd(e);return e.negative=1,t._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(e),this.negative=1,this._normSign();var n=this.cmp(e);if(0===n)return this.negative=0,this.length=1,this.words[0]=0,this;var i,r;n>0?(i=this,r=e):(i=e,r=this);for(var o=0,a=0;a>26,this.words[a]=67108863&t;for(;0!==o&&a>26,this.words[a]=67108863&t;if(0===o&&a>>13,d=0|a[1],h=8191&d,m=d>>>13,v=0|a[2],b=8191&v,y=v>>>13,g=0|a[3],_=8191&g,x=g>>>13,w=0|a[4],k=8191&w,j=w>>>13,S=0|a[5],E=8191&S,A=S>>>13,C=0|a[6],M=8191&C,T=C>>>13,P=0|a[7],F=8191&P,I=P>>>13,B=0|a[8],R=8191&B,O=B>>>13,N=0|a[9],D=8191&N,L=N>>>13,q=0|s[0],z=8191&q,U=q>>>13,H=0|s[1],V=8191&H,K=H>>>13,W=0|s[2],X=8191&W,G=W>>>13,$=0|s[3],J=8191&$,Q=$>>>13,Y=0|s[4],Z=8191&Y,ee=Y>>>13,te=0|s[5],ne=8191&te,ie=te>>>13,re=0|s[6],oe=8191&re,ae=re>>>13,se=0|s[7],ce=8191&se,ue=se>>>13,le=0|s[8],fe=8191&le,pe=le>>>13,de=0|s[9],he=8191&de,me=de>>>13;n.negative=e.negative^t.negative,n.length=19;var ve=(u+(i=Math.imul(f,z))|0)+((8191&(r=(r=Math.imul(f,U))+Math.imul(p,z)|0))<<13)|0;u=((o=Math.imul(p,U))+(r>>>13)|0)+(ve>>>26)|0,ve&=67108863,i=Math.imul(h,z),r=(r=Math.imul(h,U))+Math.imul(m,z)|0,o=Math.imul(m,U);var be=(u+(i=i+Math.imul(f,V)|0)|0)+((8191&(r=(r=r+Math.imul(f,K)|0)+Math.imul(p,V)|0))<<13)|0;u=((o=o+Math.imul(p,K)|0)+(r>>>13)|0)+(be>>>26)|0,be&=67108863,i=Math.imul(b,z),r=(r=Math.imul(b,U))+Math.imul(y,z)|0,o=Math.imul(y,U),i=i+Math.imul(h,V)|0,r=(r=r+Math.imul(h,K)|0)+Math.imul(m,V)|0,o=o+Math.imul(m,K)|0;var ye=(u+(i=i+Math.imul(f,X)|0)|0)+((8191&(r=(r=r+Math.imul(f,G)|0)+Math.imul(p,X)|0))<<13)|0;u=((o=o+Math.imul(p,G)|0)+(r>>>13)|0)+(ye>>>26)|0,ye&=67108863,i=Math.imul(_,z),r=(r=Math.imul(_,U))+Math.imul(x,z)|0,o=Math.imul(x,U),i=i+Math.imul(b,V)|0,r=(r=r+Math.imul(b,K)|0)+Math.imul(y,V)|0,o=o+Math.imul(y,K)|0,i=i+Math.imul(h,X)|0,r=(r=r+Math.imul(h,G)|0)+Math.imul(m,X)|0,o=o+Math.imul(m,G)|0;var ge=(u+(i=i+Math.imul(f,J)|0)|0)+((8191&(r=(r=r+Math.imul(f,Q)|0)+Math.imul(p,J)|0))<<13)|0;u=((o=o+Math.imul(p,Q)|0)+(r>>>13)|0)+(ge>>>26)|0,ge&=67108863,i=Math.imul(k,z),r=(r=Math.imul(k,U))+Math.imul(j,z)|0,o=Math.imul(j,U),i=i+Math.imul(_,V)|0,r=(r=r+Math.imul(_,K)|0)+Math.imul(x,V)|0,o=o+Math.imul(x,K)|0,i=i+Math.imul(b,X)|0,r=(r=r+Math.imul(b,G)|0)+Math.imul(y,X)|0,o=o+Math.imul(y,G)|0,i=i+Math.imul(h,J)|0,r=(r=r+Math.imul(h,Q)|0)+Math.imul(m,J)|0,o=o+Math.imul(m,Q)|0;var _e=(u+(i=i+Math.imul(f,Z)|0)|0)+((8191&(r=(r=r+Math.imul(f,ee)|0)+Math.imul(p,Z)|0))<<13)|0;u=((o=o+Math.imul(p,ee)|0)+(r>>>13)|0)+(_e>>>26)|0,_e&=67108863,i=Math.imul(E,z),r=(r=Math.imul(E,U))+Math.imul(A,z)|0,o=Math.imul(A,U),i=i+Math.imul(k,V)|0,r=(r=r+Math.imul(k,K)|0)+Math.imul(j,V)|0,o=o+Math.imul(j,K)|0,i=i+Math.imul(_,X)|0,r=(r=r+Math.imul(_,G)|0)+Math.imul(x,X)|0,o=o+Math.imul(x,G)|0,i=i+Math.imul(b,J)|0,r=(r=r+Math.imul(b,Q)|0)+Math.imul(y,J)|0,o=o+Math.imul(y,Q)|0,i=i+Math.imul(h,Z)|0,r=(r=r+Math.imul(h,ee)|0)+Math.imul(m,Z)|0,o=o+Math.imul(m,ee)|0;var xe=(u+(i=i+Math.imul(f,ne)|0)|0)+((8191&(r=(r=r+Math.imul(f,ie)|0)+Math.imul(p,ne)|0))<<13)|0;u=((o=o+Math.imul(p,ie)|0)+(r>>>13)|0)+(xe>>>26)|0,xe&=67108863,i=Math.imul(M,z),r=(r=Math.imul(M,U))+Math.imul(T,z)|0,o=Math.imul(T,U),i=i+Math.imul(E,V)|0,r=(r=r+Math.imul(E,K)|0)+Math.imul(A,V)|0,o=o+Math.imul(A,K)|0,i=i+Math.imul(k,X)|0,r=(r=r+Math.imul(k,G)|0)+Math.imul(j,X)|0,o=o+Math.imul(j,G)|0,i=i+Math.imul(_,J)|0,r=(r=r+Math.imul(_,Q)|0)+Math.imul(x,J)|0,o=o+Math.imul(x,Q)|0,i=i+Math.imul(b,Z)|0,r=(r=r+Math.imul(b,ee)|0)+Math.imul(y,Z)|0,o=o+Math.imul(y,ee)|0,i=i+Math.imul(h,ne)|0,r=(r=r+Math.imul(h,ie)|0)+Math.imul(m,ne)|0,o=o+Math.imul(m,ie)|0;var we=(u+(i=i+Math.imul(f,oe)|0)|0)+((8191&(r=(r=r+Math.imul(f,ae)|0)+Math.imul(p,oe)|0))<<13)|0;u=((o=o+Math.imul(p,ae)|0)+(r>>>13)|0)+(we>>>26)|0,we&=67108863,i=Math.imul(F,z),r=(r=Math.imul(F,U))+Math.imul(I,z)|0,o=Math.imul(I,U),i=i+Math.imul(M,V)|0,r=(r=r+Math.imul(M,K)|0)+Math.imul(T,V)|0,o=o+Math.imul(T,K)|0,i=i+Math.imul(E,X)|0,r=(r=r+Math.imul(E,G)|0)+Math.imul(A,X)|0,o=o+Math.imul(A,G)|0,i=i+Math.imul(k,J)|0,r=(r=r+Math.imul(k,Q)|0)+Math.imul(j,J)|0,o=o+Math.imul(j,Q)|0,i=i+Math.imul(_,Z)|0,r=(r=r+Math.imul(_,ee)|0)+Math.imul(x,Z)|0,o=o+Math.imul(x,ee)|0,i=i+Math.imul(b,ne)|0,r=(r=r+Math.imul(b,ie)|0)+Math.imul(y,ne)|0,o=o+Math.imul(y,ie)|0,i=i+Math.imul(h,oe)|0,r=(r=r+Math.imul(h,ae)|0)+Math.imul(m,oe)|0,o=o+Math.imul(m,ae)|0;var ke=(u+(i=i+Math.imul(f,ce)|0)|0)+((8191&(r=(r=r+Math.imul(f,ue)|0)+Math.imul(p,ce)|0))<<13)|0;u=((o=o+Math.imul(p,ue)|0)+(r>>>13)|0)+(ke>>>26)|0,ke&=67108863,i=Math.imul(R,z),r=(r=Math.imul(R,U))+Math.imul(O,z)|0,o=Math.imul(O,U),i=i+Math.imul(F,V)|0,r=(r=r+Math.imul(F,K)|0)+Math.imul(I,V)|0,o=o+Math.imul(I,K)|0,i=i+Math.imul(M,X)|0,r=(r=r+Math.imul(M,G)|0)+Math.imul(T,X)|0,o=o+Math.imul(T,G)|0,i=i+Math.imul(E,J)|0,r=(r=r+Math.imul(E,Q)|0)+Math.imul(A,J)|0,o=o+Math.imul(A,Q)|0,i=i+Math.imul(k,Z)|0,r=(r=r+Math.imul(k,ee)|0)+Math.imul(j,Z)|0,o=o+Math.imul(j,ee)|0,i=i+Math.imul(_,ne)|0,r=(r=r+Math.imul(_,ie)|0)+Math.imul(x,ne)|0,o=o+Math.imul(x,ie)|0,i=i+Math.imul(b,oe)|0,r=(r=r+Math.imul(b,ae)|0)+Math.imul(y,oe)|0,o=o+Math.imul(y,ae)|0,i=i+Math.imul(h,ce)|0,r=(r=r+Math.imul(h,ue)|0)+Math.imul(m,ce)|0,o=o+Math.imul(m,ue)|0;var je=(u+(i=i+Math.imul(f,fe)|0)|0)+((8191&(r=(r=r+Math.imul(f,pe)|0)+Math.imul(p,fe)|0))<<13)|0;u=((o=o+Math.imul(p,pe)|0)+(r>>>13)|0)+(je>>>26)|0,je&=67108863,i=Math.imul(D,z),r=(r=Math.imul(D,U))+Math.imul(L,z)|0,o=Math.imul(L,U),i=i+Math.imul(R,V)|0,r=(r=r+Math.imul(R,K)|0)+Math.imul(O,V)|0,o=o+Math.imul(O,K)|0,i=i+Math.imul(F,X)|0,r=(r=r+Math.imul(F,G)|0)+Math.imul(I,X)|0,o=o+Math.imul(I,G)|0,i=i+Math.imul(M,J)|0,r=(r=r+Math.imul(M,Q)|0)+Math.imul(T,J)|0,o=o+Math.imul(T,Q)|0,i=i+Math.imul(E,Z)|0,r=(r=r+Math.imul(E,ee)|0)+Math.imul(A,Z)|0,o=o+Math.imul(A,ee)|0,i=i+Math.imul(k,ne)|0,r=(r=r+Math.imul(k,ie)|0)+Math.imul(j,ne)|0,o=o+Math.imul(j,ie)|0,i=i+Math.imul(_,oe)|0,r=(r=r+Math.imul(_,ae)|0)+Math.imul(x,oe)|0,o=o+Math.imul(x,ae)|0,i=i+Math.imul(b,ce)|0,r=(r=r+Math.imul(b,ue)|0)+Math.imul(y,ce)|0,o=o+Math.imul(y,ue)|0,i=i+Math.imul(h,fe)|0,r=(r=r+Math.imul(h,pe)|0)+Math.imul(m,fe)|0,o=o+Math.imul(m,pe)|0;var Se=(u+(i=i+Math.imul(f,he)|0)|0)+((8191&(r=(r=r+Math.imul(f,me)|0)+Math.imul(p,he)|0))<<13)|0;u=((o=o+Math.imul(p,me)|0)+(r>>>13)|0)+(Se>>>26)|0,Se&=67108863,i=Math.imul(D,V),r=(r=Math.imul(D,K))+Math.imul(L,V)|0,o=Math.imul(L,K),i=i+Math.imul(R,X)|0,r=(r=r+Math.imul(R,G)|0)+Math.imul(O,X)|0,o=o+Math.imul(O,G)|0,i=i+Math.imul(F,J)|0,r=(r=r+Math.imul(F,Q)|0)+Math.imul(I,J)|0,o=o+Math.imul(I,Q)|0,i=i+Math.imul(M,Z)|0,r=(r=r+Math.imul(M,ee)|0)+Math.imul(T,Z)|0,o=o+Math.imul(T,ee)|0,i=i+Math.imul(E,ne)|0,r=(r=r+Math.imul(E,ie)|0)+Math.imul(A,ne)|0,o=o+Math.imul(A,ie)|0,i=i+Math.imul(k,oe)|0,r=(r=r+Math.imul(k,ae)|0)+Math.imul(j,oe)|0,o=o+Math.imul(j,ae)|0,i=i+Math.imul(_,ce)|0,r=(r=r+Math.imul(_,ue)|0)+Math.imul(x,ce)|0,o=o+Math.imul(x,ue)|0,i=i+Math.imul(b,fe)|0,r=(r=r+Math.imul(b,pe)|0)+Math.imul(y,fe)|0,o=o+Math.imul(y,pe)|0;var Ee=(u+(i=i+Math.imul(h,he)|0)|0)+((8191&(r=(r=r+Math.imul(h,me)|0)+Math.imul(m,he)|0))<<13)|0;u=((o=o+Math.imul(m,me)|0)+(r>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,i=Math.imul(D,X),r=(r=Math.imul(D,G))+Math.imul(L,X)|0,o=Math.imul(L,G),i=i+Math.imul(R,J)|0,r=(r=r+Math.imul(R,Q)|0)+Math.imul(O,J)|0,o=o+Math.imul(O,Q)|0,i=i+Math.imul(F,Z)|0,r=(r=r+Math.imul(F,ee)|0)+Math.imul(I,Z)|0,o=o+Math.imul(I,ee)|0,i=i+Math.imul(M,ne)|0,r=(r=r+Math.imul(M,ie)|0)+Math.imul(T,ne)|0,o=o+Math.imul(T,ie)|0,i=i+Math.imul(E,oe)|0,r=(r=r+Math.imul(E,ae)|0)+Math.imul(A,oe)|0,o=o+Math.imul(A,ae)|0,i=i+Math.imul(k,ce)|0,r=(r=r+Math.imul(k,ue)|0)+Math.imul(j,ce)|0,o=o+Math.imul(j,ue)|0,i=i+Math.imul(_,fe)|0,r=(r=r+Math.imul(_,pe)|0)+Math.imul(x,fe)|0,o=o+Math.imul(x,pe)|0;var Ae=(u+(i=i+Math.imul(b,he)|0)|0)+((8191&(r=(r=r+Math.imul(b,me)|0)+Math.imul(y,he)|0))<<13)|0;u=((o=o+Math.imul(y,me)|0)+(r>>>13)|0)+(Ae>>>26)|0,Ae&=67108863,i=Math.imul(D,J),r=(r=Math.imul(D,Q))+Math.imul(L,J)|0,o=Math.imul(L,Q),i=i+Math.imul(R,Z)|0,r=(r=r+Math.imul(R,ee)|0)+Math.imul(O,Z)|0,o=o+Math.imul(O,ee)|0,i=i+Math.imul(F,ne)|0,r=(r=r+Math.imul(F,ie)|0)+Math.imul(I,ne)|0,o=o+Math.imul(I,ie)|0,i=i+Math.imul(M,oe)|0,r=(r=r+Math.imul(M,ae)|0)+Math.imul(T,oe)|0,o=o+Math.imul(T,ae)|0,i=i+Math.imul(E,ce)|0,r=(r=r+Math.imul(E,ue)|0)+Math.imul(A,ce)|0,o=o+Math.imul(A,ue)|0,i=i+Math.imul(k,fe)|0,r=(r=r+Math.imul(k,pe)|0)+Math.imul(j,fe)|0,o=o+Math.imul(j,pe)|0;var Ce=(u+(i=i+Math.imul(_,he)|0)|0)+((8191&(r=(r=r+Math.imul(_,me)|0)+Math.imul(x,he)|0))<<13)|0;u=((o=o+Math.imul(x,me)|0)+(r>>>13)|0)+(Ce>>>26)|0,Ce&=67108863,i=Math.imul(D,Z),r=(r=Math.imul(D,ee))+Math.imul(L,Z)|0,o=Math.imul(L,ee),i=i+Math.imul(R,ne)|0,r=(r=r+Math.imul(R,ie)|0)+Math.imul(O,ne)|0,o=o+Math.imul(O,ie)|0,i=i+Math.imul(F,oe)|0,r=(r=r+Math.imul(F,ae)|0)+Math.imul(I,oe)|0,o=o+Math.imul(I,ae)|0,i=i+Math.imul(M,ce)|0,r=(r=r+Math.imul(M,ue)|0)+Math.imul(T,ce)|0,o=o+Math.imul(T,ue)|0,i=i+Math.imul(E,fe)|0,r=(r=r+Math.imul(E,pe)|0)+Math.imul(A,fe)|0,o=o+Math.imul(A,pe)|0;var Me=(u+(i=i+Math.imul(k,he)|0)|0)+((8191&(r=(r=r+Math.imul(k,me)|0)+Math.imul(j,he)|0))<<13)|0;u=((o=o+Math.imul(j,me)|0)+(r>>>13)|0)+(Me>>>26)|0,Me&=67108863,i=Math.imul(D,ne),r=(r=Math.imul(D,ie))+Math.imul(L,ne)|0,o=Math.imul(L,ie),i=i+Math.imul(R,oe)|0,r=(r=r+Math.imul(R,ae)|0)+Math.imul(O,oe)|0,o=o+Math.imul(O,ae)|0,i=i+Math.imul(F,ce)|0,r=(r=r+Math.imul(F,ue)|0)+Math.imul(I,ce)|0,o=o+Math.imul(I,ue)|0,i=i+Math.imul(M,fe)|0,r=(r=r+Math.imul(M,pe)|0)+Math.imul(T,fe)|0,o=o+Math.imul(T,pe)|0;var Te=(u+(i=i+Math.imul(E,he)|0)|0)+((8191&(r=(r=r+Math.imul(E,me)|0)+Math.imul(A,he)|0))<<13)|0;u=((o=o+Math.imul(A,me)|0)+(r>>>13)|0)+(Te>>>26)|0,Te&=67108863,i=Math.imul(D,oe),r=(r=Math.imul(D,ae))+Math.imul(L,oe)|0,o=Math.imul(L,ae),i=i+Math.imul(R,ce)|0,r=(r=r+Math.imul(R,ue)|0)+Math.imul(O,ce)|0,o=o+Math.imul(O,ue)|0,i=i+Math.imul(F,fe)|0,r=(r=r+Math.imul(F,pe)|0)+Math.imul(I,fe)|0,o=o+Math.imul(I,pe)|0;var Pe=(u+(i=i+Math.imul(M,he)|0)|0)+((8191&(r=(r=r+Math.imul(M,me)|0)+Math.imul(T,he)|0))<<13)|0;u=((o=o+Math.imul(T,me)|0)+(r>>>13)|0)+(Pe>>>26)|0,Pe&=67108863,i=Math.imul(D,ce),r=(r=Math.imul(D,ue))+Math.imul(L,ce)|0,o=Math.imul(L,ue),i=i+Math.imul(R,fe)|0,r=(r=r+Math.imul(R,pe)|0)+Math.imul(O,fe)|0,o=o+Math.imul(O,pe)|0;var Fe=(u+(i=i+Math.imul(F,he)|0)|0)+((8191&(r=(r=r+Math.imul(F,me)|0)+Math.imul(I,he)|0))<<13)|0;u=((o=o+Math.imul(I,me)|0)+(r>>>13)|0)+(Fe>>>26)|0,Fe&=67108863,i=Math.imul(D,fe),r=(r=Math.imul(D,pe))+Math.imul(L,fe)|0,o=Math.imul(L,pe);var Ie=(u+(i=i+Math.imul(R,he)|0)|0)+((8191&(r=(r=r+Math.imul(R,me)|0)+Math.imul(O,he)|0))<<13)|0;u=((o=o+Math.imul(O,me)|0)+(r>>>13)|0)+(Ie>>>26)|0,Ie&=67108863;var Be=(u+(i=Math.imul(D,he))|0)+((8191&(r=(r=Math.imul(D,me))+Math.imul(L,he)|0))<<13)|0;return u=((o=Math.imul(L,me))+(r>>>13)|0)+(Be>>>26)|0,Be&=67108863,c[0]=ve,c[1]=be,c[2]=ye,c[3]=ge,c[4]=_e,c[5]=xe,c[6]=we,c[7]=ke,c[8]=je,c[9]=Se,c[10]=Ee,c[11]=Ae,c[12]=Ce,c[13]=Me,c[14]=Te,c[15]=Pe,c[16]=Fe,c[17]=Ie,c[18]=Be,0!==u&&(c[19]=u,n.length++),n};Math.imul||(j=u),o.prototype.mulTo=function(e,t){var n=this.length+e.length;return 10===this.length&&10===e.length?j(this,e,t):n<63?u(this,e,t):n<1024?l(this,e,t):f(this,e,t)},p.prototype.makeRBT=function(e){for(var t=new Array(e),n=o.prototype._countBits(e)-1,i=0;i>=1;return i},p.prototype.permute=function(e,t,n,i,r,o){for(var a=0;a>>=1)r++;return 1<>>=13,n[2*a+1]=8191&o,o>>>=13;for(a=2*t;a>=26,t+=r/67108864|0,t+=o>>>26,this.words[n]=67108863&o}return 0!==t&&(this.words[n]=t,this.length++),this},o.prototype.muln=function(e){return this.clone().imuln(e)},o.prototype.sqr=function(){return this.mul(this)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(e){var t=c(e);if(0===t.length)return new o(1);for(var n=this,i=0;i=0);var t,n=e%26,r=(e-n)/26,o=67108863>>>26-n<<26-n;if(0!==n){var a=0;for(t=0;t>>26-n}a&&(this.words[t]=a,this.length++)}if(0!==r){for(t=this.length-1;t>=0;t--)this.words[t+r]=this.words[t];for(t=0;t=0);var r;r=t?(t-t%26)/26:0;var o=e%26,a=Math.min((e-o)/26,this.length),s=67108863^67108863>>>o<a)for(this.length-=a,u=0;u=0&&(0!==l||u>=r);u--){var f=0|this.words[u];this.words[u]=l<<26-o|f>>>o,l=f&s}return c&&0!==l&&(c.words[c.length++]=l),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},o.prototype.ishrn=function(e,t,n){return i(0===this.negative),this.iushrn(e,t,n)},o.prototype.shln=function(e){return this.clone().ishln(e)},o.prototype.ushln=function(e){return this.clone().iushln(e)},o.prototype.shrn=function(e){return this.clone().ishrn(e)},o.prototype.ushrn=function(e){return this.clone().iushrn(e)},o.prototype.testn=function(e){i("number"==typeof e&&e>=0);var t=e%26,n=(e-t)/26,r=1<=0);var t=e%26,n=(e-t)/26;if(i(0===this.negative,"imaskn works only with positive numbers"),this.length<=n)return this;if(0!==t&&n++,this.length=Math.min(n,this.length),0!==t){var r=67108863^67108863>>>t<=67108864;t++)this.words[t]-=67108864,t===this.length-1?this.words[t+1]=1:this.words[t+1]++;return this.length=Math.max(this.length,t+1),this},o.prototype.isubn=function(e){if(i("number"==typeof e),i(e<67108864),e<0)return this.iaddn(-e);if(0!==this.negative)return this.negative=0,this.iaddn(e),this.negative=1,this;if(this.words[0]-=e,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var t=0;t>26)-(c/67108864|0),this.words[r+n]=67108863&a}for(;r>26,this.words[r+n]=67108863&a;if(0===s)return this.strip();for(i(-1===s),s=0,r=0;r>26,this.words[r]=67108863&a;return this.negative=1,this.strip()},o.prototype._wordDiv=function(e,t){var n=this.length-e.length,i=this.clone(),r=e,a=0|r.words[r.length-1];0!==(n=26-this._countBits(a))&&(r=r.ushln(n),i.iushln(n),a=0|r.words[r.length-1]);var s,c=i.length-r.length;if("mod"!==t){(s=new o(null)).length=c+1,s.words=new Array(s.length);for(var u=0;u=0;f--){var p=67108864*(0|i.words[r.length+f])+(0|i.words[r.length+f-1]);for(p=Math.min(p/a|0,67108863),i._ishlnsubmul(r,p,f);0!==i.negative;)p--,i.negative=0,i._ishlnsubmul(r,1,f),i.isZero()||(i.negative^=1);s&&(s.words[f]=p)}return s&&s.strip(),i.strip(),"div"!==t&&0!==n&&i.iushrn(n),{div:s||null,mod:i}},o.prototype.divmod=function(e,t,n){if(i(!e.isZero()),this.isZero())return{div:new o(0),mod:new o(0)};var r,a,s;return 0!==this.negative&&0===e.negative?(s=this.neg().divmod(e,t),"mod"!==t&&(r=s.div.neg()),"div"!==t&&(a=s.mod.neg(),n&&0!==a.negative&&a.iadd(e)),{div:r,mod:a}):0===this.negative&&0!==e.negative?(s=this.divmod(e.neg(),t),"mod"!==t&&(r=s.div.neg()),{div:r,mod:s.mod}):0!=(this.negative&e.negative)?(s=this.neg().divmod(e.neg(),t),"div"!==t&&(a=s.mod.neg(),n&&0!==a.negative&&a.isub(e)),{div:s.div,mod:a}):e.length>this.length||this.cmp(e)<0?{div:new o(0),mod:this}:1===e.length?"div"===t?{div:this.divn(e.words[0]),mod:null}:"mod"===t?{div:null,mod:new o(this.modn(e.words[0]))}:{div:this.divn(e.words[0]),mod:new o(this.modn(e.words[0]))}:this._wordDiv(e,t)},o.prototype.div=function(e){return this.divmod(e,"div",!1).div},o.prototype.mod=function(e){return this.divmod(e,"mod",!1).mod},o.prototype.umod=function(e){return this.divmod(e,"mod",!0).mod},o.prototype.divRound=function(e){var t=this.divmod(e);if(t.mod.isZero())return t.div;var n=0!==t.div.negative?t.mod.isub(e):t.mod,i=e.ushrn(1),r=e.andln(1),o=n.cmp(i);return o<0||1===r&&0===o?t.div:0!==t.div.negative?t.div.isubn(1):t.div.iaddn(1)},o.prototype.modn=function(e){i(e<=67108863);for(var t=(1<<26)%e,n=0,r=this.length-1;r>=0;r--)n=(t*n+(0|this.words[r]))%e;return n},o.prototype.idivn=function(e){i(e<=67108863);for(var t=0,n=this.length-1;n>=0;n--){var r=(0|this.words[n])+67108864*t;this.words[n]=r/e|0,t=r%e}return this.strip()},o.prototype.divn=function(e){return this.clone().idivn(e)},o.prototype.egcd=function(e){i(0===e.negative),i(!e.isZero());var t=this,n=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var r=new o(1),a=new o(0),s=new o(0),c=new o(1),u=0;t.isEven()&&n.isEven();)t.iushrn(1),n.iushrn(1),++u;for(var l=n.clone(),f=t.clone();!t.isZero();){for(var p=0,d=1;0==(t.words[0]&d)&&p<26;++p,d<<=1);if(p>0)for(t.iushrn(p);p-- >0;)(r.isOdd()||a.isOdd())&&(r.iadd(l),a.isub(f)),r.iushrn(1),a.iushrn(1);for(var h=0,m=1;0==(n.words[0]&m)&&h<26;++h,m<<=1);if(h>0)for(n.iushrn(h);h-- >0;)(s.isOdd()||c.isOdd())&&(s.iadd(l),c.isub(f)),s.iushrn(1),c.iushrn(1);t.cmp(n)>=0?(t.isub(n),r.isub(s),a.isub(c)):(n.isub(t),s.isub(r),c.isub(a))}return{a:s,b:c,gcd:n.iushln(u)}},o.prototype._invmp=function(e){i(0===e.negative),i(!e.isZero());var t=this,n=e.clone();t=0!==t.negative?t.umod(e):t.clone();for(var r=new o(1),a=new o(0),s=n.clone();t.cmpn(1)>0&&n.cmpn(1)>0;){for(var c=0,u=1;0==(t.words[0]&u)&&c<26;++c,u<<=1);if(c>0)for(t.iushrn(c);c-- >0;)r.isOdd()&&r.iadd(s),r.iushrn(1);for(var l=0,f=1;0==(n.words[0]&f)&&l<26;++l,f<<=1);if(l>0)for(n.iushrn(l);l-- >0;)a.isOdd()&&a.iadd(s),a.iushrn(1);t.cmp(n)>=0?(t.isub(n),r.isub(a)):(n.isub(t),a.isub(r))}var p;return(p=0===t.cmpn(1)?r:a).cmpn(0)<0&&p.iadd(e),p},o.prototype.gcd=function(e){if(this.isZero())return e.abs();if(e.isZero())return this.abs();var t=this.clone(),n=e.clone();t.negative=0,n.negative=0;for(var i=0;t.isEven()&&n.isEven();i++)t.iushrn(1),n.iushrn(1);for(;;){for(;t.isEven();)t.iushrn(1);for(;n.isEven();)n.iushrn(1);var r=t.cmp(n);if(r<0){var o=t;t=n,n=o}else if(0===r||0===n.cmpn(1))break;t.isub(n)}return n.iushln(i)},o.prototype.invm=function(e){return this.egcd(e).a.umod(e)},o.prototype.isEven=function(){return 0==(1&this.words[0])},o.prototype.isOdd=function(){return 1==(1&this.words[0])},o.prototype.andln=function(e){return this.words[0]&e},o.prototype.bincn=function(e){i("number"==typeof e);var t=e%26,n=(e-t)/26,r=1<>>26,s&=67108863,this.words[a]=s}return 0!==o&&(this.words[a]=o,this.length++),this},o.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},o.prototype.cmpn=function(e){var t=e<0;if(0!==this.negative&&!t)return-1;if(0===this.negative&&t)return 1;this.strip();var n;if(this.length>1)n=1;else{t&&(e=-e),i(e<=67108863,"Number is too big");var r=0|this.words[0];n=r===e?0:re.length)return 1;if(this.length=0;n--){var i=0|this.words[n],r=0|e.words[n];if(i!==r){ir&&(t=1);break}}return t},o.prototype.gtn=function(e){return 1===this.cmpn(e)},o.prototype.gt=function(e){return 1===this.cmp(e)},o.prototype.gten=function(e){return this.cmpn(e)>=0},o.prototype.gte=function(e){return this.cmp(e)>=0},o.prototype.ltn=function(e){return-1===this.cmpn(e)},o.prototype.lt=function(e){return-1===this.cmp(e)},o.prototype.lten=function(e){return this.cmpn(e)<=0},o.prototype.lte=function(e){return this.cmp(e)<=0},o.prototype.eqn=function(e){return 0===this.cmpn(e)},o.prototype.eq=function(e){return 0===this.cmp(e)},o.red=function(e){return new y(e)},o.prototype.toRed=function(e){return i(!this.red,"Already a number in reduction context"),i(0===this.negative,"red works only with positives"),e.convertTo(this)._forceRed(e)},o.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},o.prototype._forceRed=function(e){return this.red=e,this},o.prototype.forceRed=function(e){return i(!this.red,"Already a number in reduction context"),this._forceRed(e)},o.prototype.redAdd=function(e){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,e)},o.prototype.redIAdd=function(e){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,e)},o.prototype.redSub=function(e){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,e)},o.prototype.redISub=function(e){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,e)},o.prototype.redShl=function(e){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,e)},o.prototype.redMul=function(e){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.mul(this,e)},o.prototype.redIMul=function(e){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,e),this.red.imul(this,e)},o.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},o.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},o.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},o.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},o.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},o.prototype.redPow=function(e){return i(this.red&&!e.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,e)};var S={k256:null,p224:null,p192:null,p25519:null};d.prototype._tmp=function(){var e=new o(null);return e.words=new Array(Math.ceil(this.n/13)),e},d.prototype.ireduce=function(e){var t,n=e;do{this.split(n,this.tmp),t=(n=(n=this.imulK(n)).iadd(this.tmp)).bitLength()}while(t>this.n);var i=t0?n.isub(this.p):n.strip(),n},d.prototype.split=function(e,t){e.iushrn(this.n,0,t)},d.prototype.imulK=function(e){return e.imul(this.k)},r(h,d),h.prototype.split=function(e,t){for(var n=Math.min(e.length,9),i=0;i>>22,r=o}r>>>=22,e.words[i-10]=r,0===r&&e.length>10?e.length-=10:e.length-=9},h.prototype.imulK=function(e){e.words[e.length]=0,e.words[e.length+1]=0,e.length+=2;for(var t=0,n=0;n>>=26,e.words[n]=r,t=i}return 0!==t&&(e.words[e.length++]=t),e},o._prime=function(e){if(S[e])return S[e];var t;if("k256"===e)t=new h;else if("p224"===e)t=new m;else if("p192"===e)t=new v;else{if("p25519"!==e)throw new Error("Unknown prime "+e);t=new b}return S[e]=t,t},y.prototype._verify1=function(e){i(0===e.negative,"red works only with positives"),i(e.red,"red works only with red numbers")},y.prototype._verify2=function(e,t){i(0==(e.negative|t.negative),"red works only with positives"),i(e.red&&e.red===t.red,"red works only with red numbers")},y.prototype.imod=function(e){return this.prime?this.prime.ireduce(e)._forceRed(this):e.umod(this.m)._forceRed(this)},y.prototype.neg=function(e){return e.isZero()?e.clone():this.m.sub(e)._forceRed(this)},y.prototype.add=function(e,t){this._verify2(e,t);var n=e.add(t);return n.cmp(this.m)>=0&&n.isub(this.m),n._forceRed(this)},y.prototype.iadd=function(e,t){this._verify2(e,t);var n=e.iadd(t);return n.cmp(this.m)>=0&&n.isub(this.m),n},y.prototype.sub=function(e,t){this._verify2(e,t);var n=e.sub(t);return n.cmpn(0)<0&&n.iadd(this.m),n._forceRed(this)},y.prototype.isub=function(e,t){this._verify2(e,t);var n=e.isub(t);return n.cmpn(0)<0&&n.iadd(this.m),n},y.prototype.shl=function(e,t){return this._verify1(e),this.imod(e.ushln(t))},y.prototype.imul=function(e,t){return this._verify2(e,t),this.imod(e.imul(t))},y.prototype.mul=function(e,t){return this._verify2(e,t),this.imod(e.mul(t))},y.prototype.isqr=function(e){return this.imul(e,e.clone())},y.prototype.sqr=function(e){return this.mul(e,e)},y.prototype.sqrt=function(e){if(e.isZero())return e.clone();var t=this.m.andln(3);if(i(t%2==1),3===t){var n=this.m.add(new o(1)).iushrn(2);return this.pow(e,n)}for(var r=this.m.subn(1),a=0;!r.isZero()&&0===r.andln(1);)a++,r.iushrn(1);i(!r.isZero());var s=new o(1).toRed(this),c=s.redNeg(),u=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new o(2*l*l).toRed(this);0!==this.pow(l,u).cmp(c);)l.redIAdd(c);for(var f=this.pow(l,r),p=this.pow(e,r.addn(1).iushrn(1)),d=this.pow(e,r),h=a;0!==d.cmp(s);){for(var m=d,v=0;0!==m.cmp(s);v++)m=m.redSqr();i(v=0;i--){for(var u=t.words[i],l=c-1;l>=0;l--){var f=u>>l&1;r!==n[0]&&(r=this.sqr(r)),0!==f||0!==a?(a<<=1,a|=f,(4===++s||0===i&&0===l)&&(r=this.mul(r,n[a]),s=0,a=0)):s=0}c=26}return r},y.prototype.convertTo=function(e){var t=e.umod(this.m);return t===e?t.clone():t},y.prototype.convertFrom=function(e){var t=e.clone();return t.red=null,t},o.mont=function(e){return new g(e)},r(g,y),g.prototype.convertTo=function(e){return this.imod(e.ushln(this.shift))},g.prototype.convertFrom=function(e){var t=this.imod(e.mul(this.rinv));return t.red=null,t},g.prototype.imul=function(e,t){if(e.isZero()||t.isZero())return e.words[0]=0,e.length=1,e;var n=e.imul(t),i=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=n.isub(i).iushrn(this.shift),o=r;return r.cmp(this.m)>=0?o=r.isub(this.m):r.cmpn(0)<0&&(o=r.iadd(this.m)),o._forceRed(this)},g.prototype.mul=function(e,t){if(e.isZero()||t.isZero())return new o(0)._forceRed(this);var n=e.mul(t),i=n.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),r=n.isub(i).iushrn(this.shift),a=r;return r.cmp(this.m)>=0?a=r.isub(this.m):r.cmpn(0)<0&&(a=r.iadd(this.m)),a._forceRed(this)},g.prototype.invm=function(e){return this.imod(e._invmp(this.m).mul(this.r2))._forceRed(this)}}(void 0===t||t,this)},{buffer:17}],Web3:[function(e,t,n){var i=e("../package.json").version,r=e("web3-core"),o=e("web3-eth"),a=e("web3-net"),s=e("web3-eth-personal"),c=e("web3-shh"),u=e("web3-bzz"),l=e("web3-utils"),f=function(){var e=this;r.packageInit(this,arguments),this.version=i,this.utils=l,this.eth=new o(this),this.shh=new c(this),this.bzz=new u(this);var t=this.setProvider;this.setProvider=function(n,i){return t.apply(e,arguments),this.eth.setProvider(n,i),this.shh.setProvider(n,i),this.bzz.setProvider(n),!0}};f.version=i,f.utils=l,f.modules={Eth:o,Net:a,Personal:s,Shh:c,Bzz:u},r.addProviders(f),t.exports=f},{"../package.json":276,"web3-bzz":182,"web3-core":202,"web3-eth":253,"web3-eth-personal":250,"web3-net":254,"web3-shh":262,"web3-utils":273}]},{},["Web3"])("Web3")}); \ No newline at end of file diff --git a/lib/cmd.js b/lib/cmd.js index 1f296818..e70f0897 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -1,8 +1,5 @@ -let program = require('commander'); -let colors = require('colors'); -let shelljs = require('shelljs'); -let promptly = require('promptly'); -let path = require('path'); +const program = require('commander'); +const promptly = require('promptly'); const Embark = require('../lib/index'); let embark = new Embark; @@ -30,11 +27,11 @@ class Cmd { program.parse(args); } - newApp(name) { + newApp() { let validateName = function (value) { try { - if (value.match(/^[a-zA-Z\s\-]+$/)) return value; + if (value.match(/^[a-zA-Z\s-]+$/)) return value; } catch (e) { throw new Error('Name must be only letters, spaces, or dashes'); } @@ -45,9 +42,8 @@ class Cmd { .description('new application') .action(function (name) { if (name === undefined) { - let parentDirectory = path.dirname(__dirname).split("/").pop(); - return promptly.prompt("Name your app (default is " + parentDirectory + "):", { - default: parentDirectory, + return promptly.prompt("Name your app (default is embarkDApp):", { + default: "embarkDApp", validator: validateName }, function (err, inputvalue) { if (err) { @@ -80,7 +76,7 @@ class Cmd { program .command('build [environment]') .description('deploy and build dapp at dist/ (default: development)') - .action(function (env, options) { + .action(function (env, _options) { embark.build({env: env || 'development'}); }); } @@ -137,10 +133,13 @@ class Cmd { test() { program - .command('test') + .command('test [file]') .description('run tests') - .action(function () { - shelljs.exec('mocha test'); + .action(function (file) { + embark.initConfig('development', { + embarkConfig: 'embark.json', interceptLogs: false + }); + embark.runTests(file); }); } @@ -148,7 +147,7 @@ class Cmd { program .command('upload [platform] [environment]') .description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)') - .action(function (platform, env, options) { + .action(function (platform, env, _options) { // TODO: get env in cmd line as well embark.initConfig(env || 'development', { embarkConfig: 'embark.json', interceptLogs: false diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index 45daa575..d0b31fb8 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -1,4 +1,3 @@ -var colors = require('colors'); var shelljs = require('shelljs'); var fs = require('../../core/fs.js'); @@ -29,6 +28,10 @@ var Blockchain = function(options) { maxpeers: ((this.blockchainConfig.maxpeers === 0) ? 0 : (this.blockchainConfig.maxpeers || 25)), bootnodes: this.blockchainConfig.bootnodes || "", rpcApi: (this.blockchainConfig.rpcApi || ['eth', 'web3', 'net']), + wsHost: this.blockchainConfig.wsHost || 'localhost', + wsPort: this.blockchainConfig.wsPort || 8546, + wsOrigins: this.blockchainConfig.wsOrigins || false, + wsApi: (this.blockchainConfig.wsApi || ['eth', 'web3', 'net', 'shh']), vmdebug: this.blockchainConfig.vmdebug || false }; diff --git a/lib/cmds/blockchain/geth_commands.js b/lib/cmds/blockchain/geth_commands.js index 8712a30f..5d8104c3 100644 --- a/lib/cmds/blockchain/geth_commands.js +++ b/lib/cmds/blockchain/geth_commands.js @@ -75,6 +75,7 @@ class GethCommands { if (config.rpcCorsDomain) { if (config.rpcCorsDomain === '*') { console.log('=================================='); + console.log('rpcCorsDomain set to *'); console.log('make sure you know what you are doing'); console.log('=================================='); } @@ -88,10 +89,34 @@ class GethCommands { return cmd; } + determineWsOptions(config) { + let cmd = ""; + + cmd += "--ws "; + cmd += "--wsport " + config.wsPort + " "; + cmd += "--wsaddr " + config.wsHost + " "; + if (config.wsOrigins) { + if (config.wsOrigins === '*') { + console.log('=================================='); + console.log('rpcCorsDomain set to *'); + console.log('make sure you know what you are doing'); + console.log('=================================='); + } + cmd += "--wsorigins \"" + config.wsOrigins + "\" "; + } else { + console.log('=================================='); + console.log('warning: cors is not set'); + console.log('=================================='); + } + + return cmd; + } + mainCommand(address, done) { let self = this; let config = this.config; let rpc_api = (this.config.rpcApi || ['eth', 'web3', 'net']); + let ws_api = (this.config.wsApi || ['eth', 'web3', 'net']); async.series([ function commonOptions(callback) { @@ -102,6 +127,10 @@ class GethCommands { let cmd = self.determineRpcOptions(self.config); callback(null, cmd); }, + function wsOptions(callback) { + let cmd = self.determineWsOptions(self.config); + callback(null, cmd); + }, function dontGetPeers(callback) { if (config.nodiscover) { return callback(null, "--nodiscover"); @@ -133,6 +162,9 @@ class GethCommands { function whisper(callback) { if (config.whisper) { rpc_api.push('shh'); + if (ws_api.indexOf('shh') === -1) { + ws_api.push('shh'); + } return callback(null, "--shh "); } callback(""); @@ -140,6 +172,9 @@ class GethCommands { function rpcApi(callback) { callback(null, '--rpcapi "' + rpc_api.join(',') + '"'); }, + function wsApi(callback) { + callback(null, '--wsapi "' + ws_api.join(',') + '"'); + }, function accountToUnlock(callback) { let accountAddress = ""; if(config.hasOwnProperty('address') && config.account.hasOwnProperty('address')) { diff --git a/lib/cmds/template_generator.js b/lib/cmds/template_generator.js index e00ededb..50e922c4 100644 --- a/lib/cmds/template_generator.js +++ b/lib/cmds/template_generator.js @@ -2,7 +2,7 @@ let fs = require('../core/fs.js'); let utils = require('../utils/utils.js'); class TemplateGenerator { - constuctor(templateName) { + constructor(templateName) { this.templateName = templateName; } @@ -15,8 +15,6 @@ class TemplateGenerator { utils.cd(fspath); utils.sed('package.json', '%APP_NAME%', name); - console.log('Installing packages.. this can take a few seconds'.green); - utils.runCmd('npm install'); console.log('Init complete'.green); console.log('\nApp ready at '.green + fspath); diff --git a/lib/contracts/abi.js b/lib/contracts/abi.js deleted file mode 100644 index b8b29016..00000000 --- a/lib/contracts/abi.js +++ /dev/null @@ -1,143 +0,0 @@ -class ABIGenerator { - constructor(options) { - this.blockchainConfig = options.blockchainConfig || {}; - this.storageConfig = options.storageConfig || {}; - this.communicationConfig = options.communicationConfig || {}; - this.contractsManager = options.contractsManager; - this.rpcHost = options.blockchainConfig && options.blockchainConfig.rpcHost; - this.rpcPort = options.blockchainConfig && options.blockchainConfig.rpcPort; - this.plugins = options.plugins; - } - - generateProvider() { - let self = this; - let result = ""; - let providerPlugins; - - if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) { - return ""; - } - - if (this.plugins) { - providerPlugins = this.plugins.getPluginsFor('clientWeb3Provider'); - } - - if (this.plugins && providerPlugins.length > 0) { - providerPlugins.forEach(function (plugin) { - result += plugin.generateProvider(self) + "\n"; - }); - } else { - result += "\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {"; - result += '\n\tweb3 = new Web3(web3.currentProvider);'; - result += "\n} else if (typeof Web3 !== 'undefined') {"; - result += '\n\tweb3 = new Web3(new Web3.providers.HttpProvider("http://' + this.rpcHost + ':' + this.rpcPort + '"));'; - result += '\n}'; - result += "\nweb3.eth.defaultAccount = web3.eth.accounts[0];"; - } - - return result; - } - - generateContracts(useEmbarkJS) { - let self = this; - let result = "\n"; - let contractsPlugins; - - if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) { - return ""; - } - - if (this.plugins) { - contractsPlugins = this.plugins.getPluginsFor('contractGeneration'); - } - - if (this.plugins && contractsPlugins.length > 0) { - contractsPlugins.forEach(function (plugin) { - result += plugin.generateContracts({contracts: self.contractsManager.contracts}); - }); - } else { - for (let className in this.contractsManager.contracts) { - let contract = this.contractsManager.contracts[className]; - - let abi = JSON.stringify(contract.abiDefinition); - let gasEstimates = JSON.stringify(contract.gasEstimates); - - if (useEmbarkJS) { - result += "\n" + className + " = new EmbarkJS.Contract({abi: " + abi + ", address: '" + contract.deployedAddress + "', code: '" + contract.code + "', gasEstimates: " + gasEstimates + "});"; - } else { - result += "\n" + className + "Abi = " + abi + ";"; - result += "\n" + className + "Contract = web3.eth.contract(" + className + "Abi);"; - result += "\n" + className + " = " + className + "Contract.at('" + contract.deployedAddress + "');"; - } - } - } - - return result; - } - - generateStorageInitialization(useEmbarkJS) { - let self = this; - let result = "\n"; - - if (!useEmbarkJS || self.storageConfig === {}) return ""; - - if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) { - result += "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "'});"; - } - - return result; - } - - generateCommunicationInitialization(useEmbarkJS) { - let self = this; - let result = "\n"; - - if (!useEmbarkJS || self.communicationConfig === {}) return ""; - - if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) { - result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');"; - } else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) { - result += "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.host + "', port: '" + self.communicationConfig.port + "'});"; - } - - return result; - } - - generateABI(options) { - let result = ""; - - result += this.generateProvider(); - result += this.generateContracts(options.useEmbarkJS); - result += this.generateStorageInitialization(options.useEmbarkJS); - result += this.generateCommunicationInitialization(options.useEmbarkJS); - - return result; - } - - generateContractsJSON() { - let contracts = {}; - - for (let className in this.contractsManager.contracts) { - let contract = this.contractsManager.contracts[className]; - let contractJSON = {}; - - let abi = JSON.stringify(contract.abiDefinition); - let gasEstimates = JSON.stringify(contract.gasEstimates); - - contractJSON.contract_name = className; - contractJSON.code = contract.code; - contractJSON.runtime_bytecode = contract.runtimeBytecode; - contractJSON.real_runtime_bytecode = contract.realRuntimeBytecode; - contractJSON.swarm_hash = contract.swarmHash; - contractJSON.gas_estimates = contract.gasEstimates; - contractJSON.function_hashes = contract.functionHashes; - contractJSON.abi = contract.abiDefinition; - - contracts[className] = contractJSON; - } - - return contracts; - } -} - -module.exports = ABIGenerator; diff --git a/lib/contracts/code_generator.js b/lib/contracts/code_generator.js new file mode 100644 index 00000000..3b73f4f6 --- /dev/null +++ b/lib/contracts/code_generator.js @@ -0,0 +1,262 @@ +require('ejs'); +const Templates = { + utils: require('./code_templates/utils.js.ejs'), + vanilla_contract: require('./code_templates/vanilla-contract.js.ejs'), + embarkjs_contract: require('./code_templates/embarkjs-contract.js.ejs'), + exec_when_ready: require('./code_templates/exec-when-ready.js.ejs'), + load_manager: require('./code_templates/load-manager.js.ejs'), + define_when_env_loaded: require('./code_templates/define-when-env-loaded.js.ejs'), + main_context: require('./code_templates/main-context.js.ejs'), + define_web3_simple: require('./code_templates/define-web3-simple.js.ejs'), + web3_connector: require('./code_templates/web3-connector.js.ejs'), + do_when_loaded: require('./code_templates/do-when-loaded.js.ejs'), + exec_when_env_loaded: require('./code_templates/exec-when-env-loaded.js.ejs') +}; + +class CodeGenerator { + constructor(options) { + this.blockchainConfig = options.blockchainConfig || {}; + this.contractsConfig = options.contractsConfig || {}; + this.storageConfig = options.storageConfig || {}; + this.communicationConfig = options.communicationConfig || {}; + this.contractsManager = options.contractsManager; + this.plugins = options.plugins; + this.events = options.events; + } + + listenToCommands() { + let self = this; + + // deprecated events; to remove in embark 2.7.0 + this.events.setCommandHandlerOnce('abi-vanila', function(cb) { + let vanillaABI = self.generateABI({useEmbarkJS: false}); + let contractsJSON = self.generateContractsJSON(); + + cb(vanillaABI, contractsJSON); + }); + + this.events.setCommandHandlerOnce('abi', function(cb) { + let embarkJSABI = self.generateABI({useEmbarkJS: true}); + let contractsJSON = self.generateContractsJSON(); + + cb(embarkJSABI, contractsJSON); + }); + + this.events.setCommandHandlerOnce('abi-contracts-vanila', function(cb) { + let vanillaContractsABI = self.generateContracts(false, true, false); + let contractsJSON = self.generateContractsJSON(); + + cb(vanillaContractsABI, contractsJSON); + }); + + this.events.setCommandHandlerOnce('abi-vanila-deployment', function(cb) { + let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true}); + let contractsJSON = self.generateContractsJSON(); + + cb(vanillaABI, contractsJSON); + }); + + // new events + this.events.setCommandHandlerOnce('code-vanila', function(cb) { + let vanillaABI = self.generateABI({useEmbarkJS: false}); + let contractsJSON = self.generateContractsJSON(); + + cb(vanillaABI, contractsJSON); + }); + + this.events.setCommandHandlerOnce('code', function(cb) { + let embarkJSABI = self.generateABI({useEmbarkJS: true}); + let contractsJSON = self.generateContractsJSON(); + + cb(embarkJSABI, contractsJSON); + }); + + this.events.setCommandHandlerOnce('code-contracts-vanila', function(cb) { + let vanillaContractsABI = self.generateContracts(false, true, false); + let contractsJSON = self.generateContractsJSON(); + + cb(vanillaContractsABI, contractsJSON); + }); + + this.events.setCommandHandlerOnce('code-vanila-deployment', function(cb) { + let vanillaABI = self.generateABI({useEmbarkJS: false, deployment: true}); + let contractsJSON = self.generateContractsJSON(); + + cb(vanillaABI, contractsJSON); + }); + + } + + generateProvider(isDeployment) { + let self = this; + let result = ""; + let providerPlugins; + + // TODO: check contractsConfig for enabled + if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) { + return ""; + } + + result += Templates.utils(); + + result += Templates.main_context(); + result += Templates.load_manager(); + result += Templates.define_when_env_loaded(); + + if (this.plugins) { + providerPlugins = this.plugins.getPluginsFor('clientWeb3Provider'); + } + + if (this.plugins && providerPlugins.length > 0) { + providerPlugins.forEach(function(plugin) { + result += plugin.generateProvider(self) + "\n"; + }); + } else { + + let web3Load; + + if (isDeployment) { + let connection = "http://" + this.contractsConfig.deployment.host + ":" + this.contractsConfig.deployment.port; + web3Load = Templates.define_web3_simple({url: connection, done: 'done();'}); + } else { + let connectionList = "[" + this.contractsConfig.dappConnection.map((x) => '"' + x + '"').join(',') + "]"; + web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done();'}); + } + + result += Templates.do_when_loaded({block: web3Load}); + } + + return result; + } + + generateContracts(useEmbarkJS, isDeployment, useLoader) { + let self = this; + let result = "\n"; + let contractsPlugins; + + if (useLoader === false) { + for (let className in this.contractsManager.contracts) { + let contract = this.contractsManager.contracts[className]; + let abi = JSON.stringify(contract.abiDefinition); + result += Templates.vanilla_contract({className: className, abi: abi, contract: contract}); + } + return result; + } + + if (self.blockchainConfig === {} || self.blockchainConfig.enabled === false) { + return ""; + } + + if (this.plugins) { + contractsPlugins = this.plugins.getPluginsFor('contractGeneration'); + } + + if (this.plugins && contractsPlugins.length > 0) { + contractsPlugins.forEach(function (plugin) { + result += plugin.generateContracts({contracts: self.contractsManager.contracts}); + }); + } else { + for (let className in this.contractsManager.contracts) { + let contract = this.contractsManager.contracts[className]; + + let abi = JSON.stringify(contract.abiDefinition); + let gasEstimates = JSON.stringify(contract.gasEstimates); + + let block = ""; + + if (useEmbarkJS) { + let contractAddress = contract.deployedAddress ? ("'" + contract.deployedAddress + "'") : "undefined"; + block += Templates.embarkjs_contract({className: className, abi: abi, contract: contract, contractAddress: contractAddress, gasEstimates: gasEstimates}); + } else { + block += Templates.vanilla_contract({className: className, abi: abi, contract: contract}); + } + result += Templates.exec_when_ready({block: block}); + + } + } + + return result; + } + + generateStorageInitialization(useEmbarkJS) { + let self = this; + let result = "\n"; + + if (!useEmbarkJS || self.storageConfig === {}) return ""; + + result += Templates.define_when_env_loaded(); + + if (self.storageConfig.provider === 'ipfs' && self.storageConfig.enabled === true) { + let block = "\nEmbarkJS.Storage.setProvider('" + self.storageConfig.provider + "', {server: '" + self.storageConfig.host + "', port: '" + self.storageConfig.port + "', getUrl: '" + self.storageConfig.getUrl + "'});"; + result += Templates.exec_when_env_loaded({block: block}); + } + + return result; + } + + generateCommunicationInitialization(useEmbarkJS) { + let self = this; + let result = "\n"; + + if (!useEmbarkJS || self.communicationConfig === {}) return ""; + + // TODO: don't repeat this twice; should have 'requirements' generator first + result += Templates.define_when_env_loaded(); + + let block; + // TODO: refactor this + if (self.communicationConfig.provider === 'whisper' && self.communicationConfig.enabled === true) { + if (self.communicationConfig.connection === undefined) { + block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');"; + } else { + block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.connection.host + "', port: '" + self.communicationConfig.connection.port + "', type: '" + self.communicationConfig.connection.type + "'});"; + } + result += Templates.exec_when_env_loaded({block: block}); + } else if (self.communicationConfig.provider === 'orbit' && self.communicationConfig.enabled === true) { + if (self.communicationConfig.connection === undefined) { + block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "');"; + } else { + block = "\nEmbarkJS.Messages.setProvider('" + self.communicationConfig.provider + "', {server: '" + self.communicationConfig.connection.host + "', port: '" + self.communicationConfig.connection.port + "', type: '" + self.communicationConfig.connection.type + "'});"; + } + result += Templates.exec_when_env_loaded({block: block}); + } + + return result; + } + + generateABI(options) { + let result = ""; + + result += this.generateProvider(options.deployment); + result += this.generateContracts(options.useEmbarkJS, options.deployment, true); + result += this.generateStorageInitialization(options.useEmbarkJS); + result += this.generateCommunicationInitialization(options.useEmbarkJS); + + return result; + } + + generateContractsJSON() { + let contracts = {}; + + for (let className in this.contractsManager.contracts) { + let contract = this.contractsManager.contracts[className]; + let contractJSON = {}; + + contractJSON.contract_name = className; + contractJSON.address = contract.deployedAddress; + contractJSON.code = contract.code; + contractJSON.runtime_bytecode = contract.runtimeBytecode; + contractJSON.real_runtime_bytecode = contract.realRuntimeBytecode; + contractJSON.swarm_hash = contract.swarmHash; + contractJSON.gas_estimates = contract.gasEstimates; + contractJSON.function_hashes = contract.functionHashes; + contractJSON.abi = contract.abiDefinition; + + contracts[className] = contractJSON; + } + + return contracts; + } +} + +module.exports = CodeGenerator; diff --git a/lib/contracts/code_templates/define-web3-simple.js.ejs b/lib/contracts/code_templates/define-web3-simple.js.ejs new file mode 100644 index 00000000..b6177bfa --- /dev/null +++ b/lib/contracts/code_templates/define-web3-simple.js.ejs @@ -0,0 +1,3 @@ +__mainContext.web3 = undefined; +web3 = new Web3(new Web3.providers.HttpProvider("<%- url -%>'")); +<%- done %> diff --git a/lib/contracts/code_templates/define-when-env-loaded.js.ejs b/lib/contracts/code_templates/define-when-env-loaded.js.ejs new file mode 100644 index 00000000..186bd7e0 --- /dev/null +++ b/lib/contracts/code_templates/define-when-env-loaded.js.ejs @@ -0,0 +1,7 @@ +var whenEnvIsLoaded = function(cb) { + if (typeof document !== 'undefined' && document !== null) { + document.addEventListener('DOMContentLoaded', cb); + } else { + cb(); + } +} diff --git a/lib/contracts/code_templates/do-when-loaded.js.ejs b/lib/contracts/code_templates/do-when-loaded.js.ejs new file mode 100644 index 00000000..7a984f07 --- /dev/null +++ b/lib/contracts/code_templates/do-when-loaded.js.ejs @@ -0,0 +1,6 @@ +whenEnvIsLoaded(function(){ + __mainContext.__loadManagerInstance.doFirst(function(done) { + <%- block %> + }) +}); + diff --git a/lib/contracts/code_templates/embarkjs-contract.js.ejs b/lib/contracts/code_templates/embarkjs-contract.js.ejs new file mode 100644 index 00000000..52e0b441 --- /dev/null +++ b/lib/contracts/code_templates/embarkjs-contract.js.ejs @@ -0,0 +1 @@ +__mainContext.<%- className %> = new EmbarkJS.Contract({abi: <%- abi %>, address: <%- contractAddress %>, code: '<%- contract.code %>', gasEstimates: <%- gasEstimates %>}); diff --git a/lib/contracts/code_templates/exec-when-env-loaded.js.ejs b/lib/contracts/code_templates/exec-when-env-loaded.js.ejs new file mode 100644 index 00000000..4fc2b113 --- /dev/null +++ b/lib/contracts/code_templates/exec-when-env-loaded.js.ejs @@ -0,0 +1,3 @@ +whenEnvIsLoaded(function() { + <%- block %> +}); diff --git a/lib/contracts/code_templates/exec-when-ready.js.ejs b/lib/contracts/code_templates/exec-when-ready.js.ejs new file mode 100644 index 00000000..291ee51f --- /dev/null +++ b/lib/contracts/code_templates/exec-when-ready.js.ejs @@ -0,0 +1,3 @@ +__mainContext.__loadManagerInstance.execWhenReady(function() { + <%- block %> +}); diff --git a/lib/contracts/code_templates/load-manager.js.ejs b/lib/contracts/code_templates/load-manager.js.ejs new file mode 100644 index 00000000..ff9b8259 --- /dev/null +++ b/lib/contracts/code_templates/load-manager.js.ejs @@ -0,0 +1,4 @@ +__mainContext.__LoadManager = function() { this.list = []; this.done = false; } +__mainContext.__LoadManager.prototype.execWhenReady = function(cb) { if (this.done) { cb(); } else { this.list.push(cb) } } +__mainContext.__LoadManager.prototype.doFirst = function(todo) { var self = this; todo(function() { self.done = true; self.list.map((x) => x.apply()) }) } +__mainContext.__loadManagerInstance = new __mainContext.__LoadManager(); diff --git a/lib/contracts/code_templates/main-context.js.ejs b/lib/contracts/code_templates/main-context.js.ejs new file mode 100644 index 00000000..557e62b6 --- /dev/null +++ b/lib/contracts/code_templates/main-context.js.ejs @@ -0,0 +1 @@ +var __mainContext = __mainContext || this; diff --git a/lib/contracts/code_templates/utils.js.ejs b/lib/contracts/code_templates/utils.js.ejs new file mode 100644 index 00000000..b88c7b37 --- /dev/null +++ b/lib/contracts/code_templates/utils.js.ejs @@ -0,0 +1,36 @@ +function __reduce(arr, memo, iteratee, cb) { + if (typeof cb !== 'function') { + if (typeof memo === 'function' && typeof iteratee === 'function') { + cb = iteratee; + iteratee = memo; + memo = []; + } else { + throw new TypeError('expected callback to be a function'); + } + } + + if (!Array.isArray(arr)) { + cb(new TypeError('expected an array')); + return; + } + + if (typeof iteratee !== 'function') { + cb(new TypeError('expected iteratee to be a function')); + return; + } + + (function next(i, acc) { + if (i === arr.length) { + cb(null, acc); + return; + } + + iteratee(acc, arr[i], function(err, val) { + if (err) { + cb(err); + return; + } + next(i + 1, val); + }); + })(0, memo); +}; diff --git a/lib/contracts/code_templates/vanilla-contract.js.ejs b/lib/contracts/code_templates/vanilla-contract.js.ejs new file mode 100644 index 00000000..97c2b396 --- /dev/null +++ b/lib/contracts/code_templates/vanilla-contract.js.ejs @@ -0,0 +1,3 @@ +<%- className %>Abi = <%- abi %>; +<%- className %>Contract = web3.eth.contract(<%- className %>Abi); +<%- className %> = <%= className %>Contract.at('<%- contract.deployedAddress %>'); diff --git a/lib/contracts/code_templates/web3-connector.js.ejs b/lib/contracts/code_templates/web3-connector.js.ejs new file mode 100644 index 00000000..ea97f084 --- /dev/null +++ b/lib/contracts/code_templates/web3-connector.js.ejs @@ -0,0 +1,28 @@ +__mainContext.web3 = undefined; +__reduce(<%- connectionList %>,function(prev, value, next) { + if (prev === false) { + return next(null, false); + } + + if (value === '$WEB3' && (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined')) { + web3 = new Web3(web3.currentProvider); + } else if (value !== '$WEB3' && (typeof Web3 !== 'undefined' && ((typeof web3 === 'undefined') || (typeof web3 !== 'undefined' && (!web3.isConnected || (web3.isConnected && !web3.isConnected())))))) { + + web3 = new Web3(new Web3.providers.HttpProvider(value)); + } else if (value === '$WEB3') { + return next(null, ''); + } + + web3.eth.getAccounts(function(err, account) { + if (err) { + next(null, true) + } else { + next(null, false) + } + }); +}, function(err, _result) { + web3.eth.getAccounts(function(err, accounts) { + web3.eth.defaultAccount = accounts[0]; + <%- done %> + }); +}); diff --git a/lib/contracts/compiler.js b/lib/contracts/compiler.js index 4644d4be..450067da 100644 --- a/lib/contracts/compiler.js +++ b/lib/contracts/compiler.js @@ -6,6 +6,7 @@ class Compiler { constructor(options) { this.plugins = options.plugins; this.logger = options.logger; + this.solcVersion = options.solcVersion; } compile_contracts(contractFiles, cb) { @@ -32,7 +33,8 @@ class Compiler { function (extension, compiler, callback) { // TODO: warn about files it doesn't know how to compile let matchingFiles = contractFiles.filter(function (file) { - return (file.filename.match(/\.[0-9a-z]+$/)[0] === extension); + let fileMatch = file.filename.match(/\.[0-9a-z]+$/); + return (fileMatch && (fileMatch[0] === extension)); }); compiler.call(compiler, matchingFiles || [], function (err, compileResult) { @@ -52,16 +54,22 @@ class Compiler { let solcW; async.waterfall([ function prepareInput(callback) { - for (let i = 0; i < contractFiles.length; i++) { - // TODO: this depends on the config - let filename = contractFiles[i].filename.replace('app/contracts/', ''); - input[filename] = contractFiles[i].content.toString(); - } - callback(); + async.each(contractFiles, + function(file, fileCb) { + let filename = file.filename.replace('app/contracts/', ''); + file.content(function(fileContent) { + input[filename] = fileContent; + fileCb(); + }); + }, + function (err) { + callback(err); + } + ); }, function loadCompiler(callback) { // TODO: there ino need to load this twice - solcW = new SolcW(); + solcW = new SolcW({logger: self.logger, solcVersion: self.solcVersion}); if (solcW.isCompilerLoaded()) { return callback(); } @@ -75,7 +83,12 @@ class Compiler { self.logger.info("compiling contracts..."); solcW.compile({sources: input}, 1, function (output) { if (output.errors) { - return callback(new Error("Solidity errors: " + output.errors).message); + for (let i=0; i= 0) { + return callback(new Error("Solidity errors: " + output.errors).message); + } + } + self.logger.warn(output.errors.join('\n')); } callback(null, output); }); @@ -94,6 +107,7 @@ class Compiler { // [2] classname const regex = /(.*):(.*)/; const className = contractName.match(regex)[2]; + const filename = contractName.match(regex)[1]; compiled_object[className] = {}; compiled_object[className].code = contract.bytecode; @@ -103,7 +117,9 @@ class Compiler { compiled_object[className].gasEstimates = contract.gasEstimates; compiled_object[className].functionHashes = contract.functionHashes; compiled_object[className].abiDefinition = JSON.parse(contract.interface); + compiled_object[className].filename = filename; } + callback(null, compiled_object); } ], function (err, result) { diff --git a/lib/contracts/contracts.js b/lib/contracts/contracts.js index 54fb8e89..36ab312b 100644 --- a/lib/contracts/contracts.js +++ b/lib/contracts/contracts.js @@ -12,6 +12,11 @@ class ContractsManager { this.contracts = {}; this.logger = options.logger; this.plugins = options.plugins; + if (!options.contractsConfig.versions) { + this.solcVersion = "0.4.17"; + } else { + this.solcVersion = options.contractsConfig.versions.solc; + } this.contractDependencies = {}; } @@ -20,7 +25,7 @@ class ContractsManager { let self = this; async.waterfall([ function compileContracts(callback) { - let compiler = new Compiler({plugins: self.plugins, logger: self.logger}); + let compiler = new Compiler({plugins: self.plugins, logger: self.logger, solcVersion: self.solcVersion}); compiler.compile_contracts(self.contractFiles, function (err, compiledObject) { self.compiledContracts = compiledObject; callback(err); @@ -61,6 +66,7 @@ class ContractsManager { contract.gasEstimates = compiledContract.gasEstimates; contract.functionHashes = compiledContract.functionHashes; contract.abiDefinition = compiledContract.abiDefinition; + contract.filename = compiledContract.filename; contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto'; self.adjustGas(contract); @@ -136,8 +142,15 @@ class ContractsManager { for (className in self.contracts) { contract = self.contracts[className]; - if (contract.args === []) continue; + // look in code for dependencies + let libMatches = (contract.code.match(/\:(.*?)(?=_)/g) || []); + for (let match of libMatches) { + self.contractDependencies[className] = self.contractDependencies[className] || []; + self.contractDependencies[className].push(match.substr(1)); + } + // look in arguments for dependencies + if (contract.args === []) continue; let ref = contract.args; for (let j = 0; j < ref.length; j++) { let arg = ref[j]; @@ -149,7 +162,7 @@ class ContractsManager { } callback(); } - ], function (err, result) { + ], function (err, _result) { if (err) { self.logger.error("Error Compiling/Building contracts: " + err); } diff --git a/lib/contracts/deploy.js b/lib/contracts/deploy.js index f9b2259b..c9ea7ada 100644 --- a/lib/contracts/deploy.js +++ b/lib/contracts/deploy.js @@ -3,7 +3,7 @@ let async = require('async'); let RunCode = require('../core/runCode.js'); let DeployTracker = require('./deploy_tracker.js'); -let ABIGenerator = require('./abi.js'); +let CodeGenerator = require('./code_generator.js'); class Deploy { constructor(options) { @@ -36,12 +36,7 @@ class Deploy { checkAndDeployContract(contract, params, callback) { let self = this; - let suppliedArgs; let realArgs; - let arg; - let l; - let contractName; - let referedContract; contract.error = false; if (contract.deploy === false) { @@ -81,11 +76,11 @@ class Deploy { if (contract.onDeploy !== undefined) { self.logger.info('executing onDeploy commands'); - let abiGenerator = new ABIGenerator({contractsManager: self.contractsManager}); - let abi = abiGenerator.generateContracts(false); + let codeGenerator = new CodeGenerator({contractsManager: self.contractsManager}); + let code = codeGenerator.generateContracts(false, true, true); let cmds = contract.onDeploy.join(';\n'); - RunCode.doEval(abi + "\n" + cmds, self.web3); + RunCode.doEval(code + "\n" + cmds, self.web3); } callback(); @@ -105,18 +100,32 @@ class Deploy { return callback(new Error(err)); } + let contractCode = contract.code; + let contractsList = self.contractsManager.listContracts(); + for (let contractObj of contractsList) { + let filename = contractObj.filename; + let deployedAddress = contractObj.deployedAddress; + if (deployedAddress) { + deployedAddress = deployedAddress.substr(2); + } + let linkReference = '__' + filename + ":" + contractObj.className; + let toReplace = linkReference + "_".repeat(40 - linkReference.length); + contractCode = contractCode.replace(new RegExp(toReplace, "g"), deployedAddress); + } + // TODO: probably needs to be defaultAccount // TODO: it wouldn't necessary be the first address // use defined blockchain address or first address contractParams.push({ //from: this.web3.eth.coinbase, from: accounts[0], - data: "0x" + contract.code, + data: "0x" + contractCode, gas: contract.gas, gasPrice: contract.gasPrice }); self.logger.info("deploying " + contract.className.bold.cyan + " with ".green + contract.gas + " gas".green); + contractParams.push(function (err, transaction) { self.logger.contractsState(self.contractsManager.contractsState()); @@ -150,7 +159,7 @@ class Deploy { self.logger.trace(arguments); self.checkAndDeployContract(contract, null, callback); }, - function (err, results) { + function (err, _results) { if (err) { self.logger.error("error deploying contracts"); self.logger.error(err.message); diff --git a/lib/contracts/deploy_manager.js b/lib/contracts/deploy_manager.js index 3b3ec750..975abae0 100644 --- a/lib/contracts/deploy_manager.js +++ b/lib/contracts/deploy_manager.js @@ -42,7 +42,7 @@ class DeployManager { return callback(Error("error connecting to blockchain node")); } if (self.web3.currentProvider.isConnected === undefined) { - self.web3.version.getNode(function (err, version) { + self.web3.version.getNode(function (err, _version) { if (err) { return callback(Error("error connecting to blockchain node")); } diff --git a/lib/contracts/solcP.js b/lib/contracts/solcP.js index 4c903fc1..9444f3a8 100644 --- a/lib/contracts/solcP.js +++ b/lib/contracts/solcP.js @@ -2,7 +2,7 @@ let solc; process.on('message', function (msg) { if (msg.action === 'loadCompiler') { - solc = require('solc'); + solc = require(msg.solcLocation); process.send({result: "loadedCompiler"}); } diff --git a/lib/contracts/solcW.js b/lib/contracts/solcW.js index f18407a9..2087a903 100644 --- a/lib/contracts/solcW.js +++ b/lib/contracts/solcW.js @@ -1,9 +1,17 @@ let utils = require('../utils/utils.js'); let solcProcess; let compilerLoaded = false; +var Npm = require('../pipeline/npm.js'); +let path = require('path'); +let currentSolcVersion = require('../../package.json').dependencies.solc; class SolcW { + constructor(options) { + this.solcVersion = options.solcVersion; + this.logger = options.logger; + } + load_compiler(done) { if (compilerLoaded) { done(); @@ -16,7 +24,17 @@ class SolcW { compilerLoaded = true; done(); }); - solcProcess.send({action: 'loadCompiler'}); + + if (this.solcVersion === currentSolcVersion) { + solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'}); + } else { + let npm = new Npm({logger: this.logger}); + npm.getPackageVersion('solc', this.solcVersion, false, false, function(location) { + let requirePath = path.join(process.env.PWD, location); + solcProcess.send({action: 'loadCompiler', solcLocation: requirePath}); + }); + } + } isCompilerLoaded() { diff --git a/lib/core/config.js b/lib/core/config.js index 510a8cfd..6c233234 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -1,6 +1,9 @@ var fs = require('./fs.js'); +var File = require('./file.js'); var Plugins = require('./plugins.js'); var utils = require('../utils/utils.js'); +var Npm = require('../pipeline/npm.js'); +let currentWeb3Version = require('../../package.json').dependencies.web3.replace("^",""); // TODO: add wrapper for fs so it can also work in the browser // can work with both read and save @@ -44,6 +47,7 @@ Config.prototype.loadConfigFiles = function(options) { this.loadStorageConfigFile(); this.loadCommunicationConfigFile(); + this.loadContractsConfigFile(); this.loadPipelineConfigFile(); this.loadContractsConfigFile(); @@ -57,6 +61,7 @@ Config.prototype.reloadConfig = function() { this.loadBlockchainConfigFile(); this.loadStorageConfigFile(); this.loadCommunicationConfigFile(); + this.loadContractsConfigFile(); this.loadPipelineConfigFile(); this.loadContractsConfigFile(); this.loadChainTrackerFile(); @@ -73,7 +78,21 @@ Config.prototype.loadBlockchainConfigFile = function() { Config.prototype.loadContractsConfigFile = function() { - var configObject = {}; + var configObject = { + "versions": { + "web3.js": "0.19.1", + "solc": "0.4.17" + }, + "deployment": { + "host": "localhost", + "port": 8545, + "type": "rpc" + }, + "dappConnection": [ + "$WEB3", + "localhost:8545" + ] + }; var configPlugins = this.plugins.getPluginsFor('contractsConfig'); if (configPlugins.length > 0) { @@ -102,7 +121,8 @@ Config.prototype.loadStorageConfigFile = function() { "ipfs_bin": "ipfs", "provider": "ipfs", "host": "localhost", - "port": 5001 + "port": 5001, + "getUrl": "http://localhost:8080/ipfs/" }, "development": { } @@ -142,7 +162,12 @@ Config.prototype.loadCommunicationConfigFile = function() { "default": { "enabled": true, "provider": "whisper", - "available_providers": ["whisper", "orbit"] + "available_providers": ["whisper", "orbit"], + "connection": { + "host": "localhost", + "port": 8546, + "type": "ws" + } } }; @@ -228,24 +253,46 @@ Config.prototype.loadFiles = function(files) { // get embark.js object first originalFiles.filter(function(file) { - return file.indexOf('.') >= 0; + return (file[0] === '$' || file.indexOf('.') >= 0); }).filter(function(file) { if (file === 'embark.js') { if (self.blockchainConfig.enabled || self.communicationConfig.provider === 'whisper' || self.communicationConfig.available_providers.indexOf('whisper') >= 0) { - readFiles.push({filename: 'web3.js', content: fs.readFileSync(fs.embarkPath("node_modules/web3/dist/web3.min.js")).toString(), path: fs.embarkPath("node_modules/web3/dist/web3.min.js")}); + let web3Version = self.contractsConfig.versions["web3.js"]; + if (web3Version && web3Version != currentWeb3Version) { + //if (false) { + //readFiles.push(new File({filename: 'web3-' + web3Version + '.js', type: 'custom', resolver: function(callback) { + readFiles.push(new File({filename: 'web3.js', type: 'custom', resolver: function(callback) { + if (web3Version === "1.0.0-beta") { + return callback(fs.readFileSync(fs.embarkPath('js/web3-1.0.min.js')).toString()); + } else { + let npm = new Npm({logger: self.logger}); + npm.getPackageVersion('web3', web3Version, 'dist/web3.min.js', true, function(web3Content) { + callback(web3Content); + }); + } + }})); + } else { + readFiles.push(new File({filename: 'web3.js', type: 'embark_internal', path: "js/web3.js"})); + } } if (self.storageConfig.enabled && (self.storageConfig.provider === 'ipfs' || self.storageConfig.available_providers.indexOf('ipfs') >= 0)) { - readFiles.push({filename: 'ipfs.js', content: fs.readFileSync(fs.embarkPath("node_modules/ipfs-api/dist/index.min.js")).toString(), path: fs.embarkPath("node_modules/ipfs-api/dist/index.min.js")}); + readFiles.push(new File({filename: 'ipfs.js', type: 'embark_internal', path: "node_modules/ipfs-api/dist/index.min.js"})); } if (self.communicationConfig.enabled && (self.communicationConfig.provider === 'orbit' || self.communicationConfig.available_providers.indexOf('orbit') >= 0)) { - readFiles.push({filename: 'orbit.js', content: fs.readFileSync(fs.embarkPath("node_modules/orbit-db/dist/orbitdb.min.js")).toString(), path: fs.embarkPath("node_modules/orbit-db/dist/orbitdb.min.js")}); + readFiles.push(new File ({filename: 'orbit.js', type: 'embark_internal', path: "node_modules/orbit-db/dist/orbitdb.min.js"})); } - readFiles.push({filename: 'embark.js', content: fs.readFileSync(fs.embarkPath("js/build/embark.bundle.js")).toString(), path: fs.embarkPath("js/build/embark.bundle.js")}); + readFiles.push(new File ({filename: 'embark.js', type: 'embark_internal', path: "js/build/embark.bundle.js"})); } + if (file === '$EMBARK_JS') { + readFiles.push(new File({filename: '$EMBARK_JS', type: 'embark_internal', path: "js/build/embark.bundle.js"})); + } + //if (file === "web3.js") { + // readFiles.push(new File({filename: 'web3.js', type: 'embark_internal', path: "js/web3.js")); + //} }); // get plugins @@ -280,10 +327,18 @@ Config.prototype.loadFiles = function(files) { }).filter(function(file) { if (file === 'embark.js') { return; - } else if (file === 'abi.js') { - readFiles.push({filename: file, content: "", path: file}); + } else if (file.indexOf("web3-") === 0) { + return; + } else if (file.indexOf("web3") === 0) { + return; + //} else if (file === 'abi.js') { + // readFiles.push({filename: file, content: "", path: file}); } else { - readFiles.push({filename: file, content: fs.readFileSync(file).toString(), path: file}); + if (file.indexOf('.') >= 0) { + readFiles.push(new File({filename: file, type: "dapp_file", path: file})); + } else if (file[0] === '$') { + //readFiles.push(new File({filename: file, type: 'embark_internal', path: file})); + } } }); @@ -298,7 +353,10 @@ Config.prototype.loadPluginContractFiles = function() { contractsPlugins.forEach(function(plugin) { plugin.contractsFiles.forEach(function(file) { var filename = file.replace('./',''); - self.contractsFiles.push({filename: filename, content: plugin.loadPluginFile(file), path: plugin.pathToFile(file)}); + //self.contractsFiles.push({filename: filename, content: plugin.loadPluginFile(file), path: plugin.pathToFile(file)}); + self.contractsFiles.push(new File({filename: filename, type: 'custom', resolver: function(callback) { + callback(plugin.loadPluginFile(file)); + }})); }); }); } diff --git a/lib/core/engine.js b/lib/core/engine.js index aecee563..42d3a387 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -4,7 +4,7 @@ let Events = require('./events.js'); let Logger = require('./logger.js'); let Config = require('./config.js'); let DeployManager = require('../contracts/deploy_manager.js'); -let ABIGenerator = require('../contracts/abi.js'); +let CodeGenerator = require('../contracts/code_generator.js'); let ServicesMonitor = require('./services_monitor.js'); let Pipeline = require('../pipeline/pipeline.js'); let Server = require('../pipeline/server.js'); @@ -22,7 +22,7 @@ class Engine { let self = this; let options = _options || {}; this.events = new Events(); - this.logger = options.logger || new Logger({logLevel: 'debug'}); + this.logger = options.logger || new Logger({logLevel: options.logLevel || 'debug'}); this.config = new Config({env: this.env, logger: this.logger, events: this.events}); this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs}); this.plugins = this.config.plugins; @@ -51,7 +51,7 @@ class Engine { let services = { "pipeline": this.pipelineService, - "abi": this.abiService, + "codeGenerator": this.codeGeneratorService, "deployment": this.deploymentService, "fileWatcher": this.fileWatchService, "webServer": this.webServerService, @@ -70,7 +70,7 @@ class Engine { return service.apply(this, [options]); } - pipelineService(options) { + pipelineService(_options) { let self = this; this.logger.setStatus("Building Assets"); let pipeline = new Pipeline({ @@ -80,11 +80,14 @@ class Engine { logger: this.logger, plugins: this.plugins }); - this.events.on('abi', function (abi, contractsJSON) { - self.currentAbi = abi; - self.contractsJSON = contractsJSON; - pipeline.build(abi, contractsJSON); - self.events.emit('outputDone'); + this.events.on('code-generator-ready', function () { + self.events.request('code', function (abi, contractsJSON) { + self.currentAbi = abi; + self.contractsJSON = contractsJSON; + pipeline.build(abi, contractsJSON, null, function() { + self.events.emit('outputDone'); + }); + }); }); // TODO: still need to redeploy contracts because the original contracts // config is being corrupted @@ -97,27 +100,24 @@ class Engine { //}); } - abiService(options) { + codeGeneratorService(_options) { let self = this; - let generateABICode = function (contractsManager) { - let abiGenerator = new ABIGenerator({ + let generateCode = function (contractsManager) { + let codeGenerator = new CodeGenerator({ blockchainConfig: self.config.blockchainConfig, + contractsConfig: self.config.contractsConfig, contractsManager: contractsManager, plugins: self.plugins, storageConfig: self.config.storageConfig, - communicationConfig: self.config.communicationConfig + communicationConfig: self.config.communicationConfig, + events: self.events }); - let embarkJSABI = abiGenerator.generateABI({useEmbarkJS: true}); - let vanillaABI = abiGenerator.generateABI({useEmbarkJS: false}); - let vanillaContractsABI = abiGenerator.generateContracts(false); - let contractsJSON = abiGenerator.generateContractsJSON(); + codeGenerator.listenToCommands(); - self.events.emit('abi-contracts-vanila', vanillaContractsABI, contractsJSON); - self.events.emit('abi-vanila', vanillaABI, contractsJSON); - self.events.emit('abi', embarkJSABI, contractsJSON); + self.events.emit('code-generator-ready'); }; - this.events.on('contractsDeployed', generateABICode); - this.events.on('blockchainDisabled', generateABICode); + this.events.on('contractsDeployed', generateCode); + this.events.on('blockchainDisabled', generateCode); } deploymentService(options) { @@ -131,7 +131,7 @@ class Engine { events: this.events }); - this.events.on('file-event', function (fileType, path) { + this.events.on('file-event', function (fileType, _path) { // TODO: for now need to deploy on asset chanes as well // because the contractsManager config is corrupted after a deploy //if (fileType === 'contract' || fileType === 'config') { @@ -142,7 +142,7 @@ class Engine { }); } - fileWatchService(options) { + fileWatchService(_options) { this.logger.setStatus("Watching for changes"); let watch = new Watch({logger: this.logger, events: this.events}); watch.start(); @@ -174,7 +174,7 @@ class Engine { }); } - ipfsService(options) { + ipfsService(_options) { let self = this; self.servicesMonitor.addCheck('IPFS', function (cb) { utils.checkIsAvailable('http://localhost:5001', function (available) { @@ -219,8 +219,12 @@ class Engine { this.web3 = options.web3; if (this.web3 === undefined) { this.web3 = new Web3(); - let web3Endpoint = 'http://' + this.config.blockchainConfig.rpcHost + ':' + this.config.blockchainConfig.rpcPort; - this.web3.setProvider(new this.web3.providers.HttpProvider(web3Endpoint)); + if (this.config.contractsConfig.deployment.type === "rpc") { + let web3Endpoint = 'http://' + this.config.contractsConfig.deployment.host + ':' + this.config.contractsConfig.deployment.port; + this.web3.setProvider(new this.web3.providers.HttpProvider(web3Endpoint)); + } else { + throw new Error("contracts config error: unknown deployment type " + this.config.contractsConfig.deployment.type); + } } self.servicesMonitor.addCheck('Ethereum', function (cb) { @@ -235,11 +239,13 @@ class Engine { }); self.servicesMonitor.addCheck('Whisper', function (cb) { - self.web3.version.getWhisper(function (err, res) { + self.web3.version.getWhisper(function (err, version) { if (err) { return cb({name: 'Whisper', status: 'off'}); + } else if (version >= 5) { + return cb({name: 'Whisper (version ' + version + ') - unsupported', status: 'warn'}); } else { - return cb({name: 'Whisper', status: 'on'}); + return cb({name: 'Whisper (version ' + version + ')', status: 'on'}); } }); }); diff --git a/lib/core/events.js b/lib/core/events.js index 69e0177b..f7f055fc 100644 --- a/lib/core/events.js +++ b/lib/core/events.js @@ -1,3 +1,52 @@ var EventEmitter = require('events'); +function warnIfLegacy(eventName) { + const legacyEvents = ['abi-vanila', 'abi', 'abi-contracts-vanila', 'abi-vanila-deployment']; + if (legacyEvents.indexOf(eventName) >= 0) { + console.info("this event is deprecated and will be removed in future versions: " + eventName); + } +} + +function log(eventType, eventName) { + if (['end', 'prefinish', 'error', 'new', 'demo', 'block', 'version'].indexOf(eventName) >= 0) { + return; + } + //console.log(eventType, eventName); +} + +const _on = EventEmitter.prototype.on; +const _setHandler = EventEmitter.prototype.setHandler; + +EventEmitter.prototype.on = function(requestName, cb) { + log("listening to event: ", requestName); + warnIfLegacy(requestName); + return _on.call(this, requestName, cb); +}; + +EventEmitter.prototype.setHandler = function(requestName, cb) { + log("setting handler for: ", requestName); + warnIfLegacy(requestName); + return _setHandler.call(this, requestName, cb); +}; + +EventEmitter.prototype.request = function(requestName, cb) { + log("requesting: ", requestName); + warnIfLegacy(requestName); + return this.emit('request:' + requestName, cb); +}; + +EventEmitter.prototype.setCommandHandler = function(requestName, cb) { + log("setting command handler for: ", requestName); + return this.on('request:' + requestName, function(_cb) { + cb.call(this, _cb); + }); +}; + +EventEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) { + log("setting command handler for: ", requestName); + return this.once('request:' + requestName, function(_cb) { + cb.call(this, _cb); + }); +}; + module.exports = EventEmitter; diff --git a/lib/core/file.js b/lib/core/file.js new file mode 100644 index 00000000..adce6ab0 --- /dev/null +++ b/lib/core/file.js @@ -0,0 +1,26 @@ +let fs = require('./fs.js'); + +class File { + + constructor(options) { + this.filename = options.filename; + this.type = options.type; + this.path = options.path; + this.resolver = options.resolver; + } + + content(callback) { + if (this.type === 'embark_internal') { + return callback(fs.readFileSync(fs.embarkPath(this.path)).toString()); + } else if (this.type === 'dapp_file') { + return callback(fs.readFileSync(this.path).toString()); + } else if (this.type === 'custom') { + return this.resolver(callback); + } else { + throw new Error("unknown file: " + this.filename); + } + } + +} + +module.exports = File; diff --git a/lib/core/fs.js b/lib/core/fs.js index 8b3be66a..d61933fa 100644 --- a/lib/core/fs.js +++ b/lib/core/fs.js @@ -34,6 +34,10 @@ function embarkPath(fileOrDir) { return utils.joinPath(__dirname, '/../../', fileOrDir); } +function dappPath() { + return process.env.PWD; +} + module.exports = { mkdirpSync: mkdirpSync, copySync: copySync, diff --git a/lib/core/runCode.js b/lib/core/runCode.js index 765bd265..3a32606b 100644 --- a/lib/core/runCode.js +++ b/lib/core/runCode.js @@ -1,5 +1,6 @@ let Web3 = require('web3'); let web3; +let __mainContext; // ====================== // the eval is used for evaluating some of the contact calls for different purposes @@ -8,9 +9,14 @@ let web3; // ====================== function doEval(code, _web3) { if (_web3) { - let web3 = _web3; + web3 = _web3; + } + + try { + return eval(code); // jshint ignore:line + } catch(e) { + throw new Error(e + "\n" + code); } - return eval(code); // jshint ignore:line } module.exports = { diff --git a/lib/core/run_tests.js b/lib/core/run_tests.js new file mode 100644 index 00000000..60cf5a8a --- /dev/null +++ b/lib/core/run_tests.js @@ -0,0 +1,76 @@ + +module.exports = { + run: function(filepath) { + var Mocha = require('mocha'), + fs = require('fs'), + path = require('path'); + + var mocha = new Mocha(); + + if (filepath) { + if (filepath.substr(-1) === '/') { + // Add each .js file to the mocha instance + fs.readdirSync(filepath).filter(function(file){ + // Only keep the .js files + // TODO: make this a configuration in embark.json + return file.substr(-3) === '.js'; + }).forEach(function(file){ + mocha.addFile( + path.join(filepath, file) + ); + }); + } else { + mocha.addFile(filepath); + } + } else { + var testDir = 'test/'; + + // Add each .js file to the mocha instance + fs.readdirSync(testDir).filter(function(file){ + // Only keep the .js files + // TODO: make this a configuration in embark.json + return file.substr(-3) === '.js'; + }).forEach(function(file){ + mocha.addFile( + path.join(testDir, file) + ); + }); + } + + let Test = require('./test.js'); + + global.assert = require('assert'); + //global.Embark = require("../index.js"); + //global.EmbarkSpec = global.Embark.initTests(); + + // TODO: check how to pass the options + //global.EmbarkSpec = new Test(options); + global.EmbarkSpec = new Test({}); + global.web3 = global.EmbarkSpec.web3; + + global.contract = function(describeName, callback) { + return Mocha.describe(describeName, callback); + }; + + // Run the tests. + let runner = mocha.run(function(failures){ + process.on('exit', function () { + process.exit(failures); // exit with non-zero status if there were failures + }); + process.exit(); + }); + + runner.on('suite', function() { + global.assert = require('assert'); + //global.Embark = require("../index.js"); + //global.EmbarkSpec = global.Embark.initTests(); + // TODO: check how to pass the options + //global.EmbarkSpec = new Test(options); + global.EmbarkSpec = new Test({}); + global.web3 = global.EmbarkSpec.web3; + //global.contract = Mocha.describe; + }); + + } +}; + diff --git a/lib/core/test.js b/lib/core/test.js index 1c32120d..6173f87b 100644 --- a/lib/core/test.js +++ b/lib/core/test.js @@ -1,6 +1,22 @@ -let getSimulator = function () { +var async = require('async'); +var Web3 = require('web3'); + +var Embark = require('../index.js'); + +var Engine = require('./engine.js'); + +var Deploy = require('../contracts/deploy.js'); + +var Config = require('./config.js'); +var RunCode = require('./runCode.js'); +var TestLogger = require('./test_logger.js'); +var web3; +var __mainContext; + +var getSimulator = function() { try { - return require('ethereumjs-testrpc'); + var sim = require('ethereumjs-testrpc'); + return sim; } catch (e) { if (e.code === 'MODULE_NOT_FOUND') { console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"'); @@ -17,25 +33,74 @@ let getSimulator = function () { } }; +var Test = function(options) { + this.options = options || {}; + var simOptions = this.options.simulatorOptions || {}; -class Test { - constructor(options) { - this.opts = options === undefined ? {} : options; - this.opts.logLevel = this.opts.hasOwnProperty('logLevel') ? this.opts.logLevel : 'debug'; - this.opts.simulatorOptions = this.opts.hasOwnProperty('simulatorOptions') ? this.opts.simulatorOptions : {}; - this.sim = getSimulator(); - } + this.engine = new Engine({ + env: this.options.env || 'test', + // TODO: confi will need to detect if this is a obj + embarkConfig: this.options.embarkConfig || 'embark.json', + interceptLogs: false + }); - newWebThree() { - try { - let Web3 = require('web3'); - let web3 = new Web3(); - web3.setProvider(this.sim.provider(this.opts.simulatorOptions)); - return web3; - } catch (e) { - throw new Error(e); + this.engine.init({ + logger: new TestLogger({logLevel: 'debug'}) + }); + + this.sim = getSimulator(); + this.web3 = new Web3(); + this.web3.setProvider(this.sim.provider(simOptions)); +}; + +Test.prototype.deployAll = function(contractsConfig, cb) { + var self = this; + + async.waterfall([ + function getConfig(callback) { + self.engine.config.contractsConfig = {contracts: contractsConfig}; + callback(); + }, + function startServices(callback) { + //{abiType: 'contracts', embarkJS: false} + self.engine.startService("codeGenerator"); + self.engine.startService("deployment", { + web3: self.web3, + trackContracts: false + }); + callback(); + }, + function deploy(callback) { + self.engine.events.on('code-generator-ready', function () { + self.engine.events.request('code-contracts-vanila', function(vanillaABI) { + callback(null, vanillaABI); + }); + }); + + self.engine.deployManager.deployContracts(function(err, result) { + console.log("deployed contracts"); + if (err) { + console.log(err); + callback(err); + } + }); + } + ], function(err, result) { + if (err) { + console.log("got error"); + process.exit(); } - } -} + // this should be part of the waterfall and not just something done at the + // end + self.web3.eth.getAccounts(function(err, accounts) { + if (err) { + throw new Error(err); + } + self.web3.eth.defaultAccount = accounts[0]; + RunCode.doEval(result, self.web3); // jshint ignore:line + cb(); + }); + }); +}; module.exports = Test; diff --git a/lib/dashboard/console.js b/lib/dashboard/console.js index ca8ccd82..e684bfc6 100644 --- a/lib/dashboard/console.js +++ b/lib/dashboard/console.js @@ -5,6 +5,7 @@ class Console { constructor(options) { this.plugins = options.plugins; this.version = options.version; + this.contractsConfig = options.contractsConfig; } runCode(code) { @@ -17,6 +18,7 @@ class Console { 'Welcome to Embark ' + this.version, '', 'possible commands are:', + 'versions - display versions in use for libraries and tools like web3 and solc', // TODO: only if the blockchain is actually active! // will need to pass te current embark state here 'web3 - instantiated web3.js object configured to the current environment', @@ -25,6 +27,20 @@ class Console { 'The web3 object and the interfaces for the deployed contracts and their methods are also available' ]; return helpText.join('\n'); + } else if (cmd === 'versions') { + //let currentSolcVersion = require('../../package.json').dependencies.solc; + let solcVersionInConfig = this.contractsConfig.versions.solc; + + //let web3Version = require('../../package.json').dependencies["web3.js"].replace("^",""); + let web3VersionInConfig = this.contractsConfig.versions["web3.js"]; + + let text = [ + 'versions in use:', + 'solc: ' + solcVersionInConfig, + 'web3.js: ' + web3VersionInConfig + ]; + + return text.join('\n'); } else if (cmd === 'quit') { utils.exit(); } @@ -32,9 +48,9 @@ class Console { } executeCmd(cmd, callback) { - var plugin, pluginOutput; - var plugins = this.plugins.getPluginsFor('console'); - for (var i = 0; i < plugins.length; i++) { + let plugin, pluginOutput; + let plugins = this.plugins.getPluginsFor('console'); + for (let i = 0; i < plugins.length; i++) { plugin = plugins[i]; pluginOutput = plugin.runCommands(cmd, {}); if (pluginOutput !== false && pluginOutput !== 'false') return callback(pluginOutput); diff --git a/lib/dashboard/dashboard.js b/lib/dashboard/dashboard.js index 9aa48b0c..82a8c136 100644 --- a/lib/dashboard/dashboard.js +++ b/lib/dashboard/dashboard.js @@ -9,6 +9,7 @@ class Dashboard { this.plugins = options.plugins; this.version = options.version; this.env = options.env; + this.contractsConfig = options.contractsConfig; } start(done) { @@ -17,7 +18,7 @@ class Dashboard { async.waterfall([ function startConsole(callback) { - console = new Console({plugins: self.plugins, version: self.version}); + console = new Console({plugins: self.plugins, version: self.version, contractsConfig: self.contractsConfig}); callback(); }, function startMonitor(callback) { diff --git a/lib/dashboard/monitor.js b/lib/dashboard/monitor.js index aaafe736..60be81b8 100644 --- a/lib/dashboard/monitor.js +++ b/lib/dashboard/monitor.js @@ -49,6 +49,8 @@ class Dashboard { services.push(checkObj.name.green); } else if (checkObj.status === 'off') { services.push(checkObj.name.red); + } else if (checkObj.status === 'warn') { + services.push(checkObj.name.grey); } else { services.push(checkObj.name); } diff --git a/lib/index.js b/lib/index.js index cc12a130..c0ca02ad 100644 --- a/lib/index.js +++ b/lib/index.js @@ -76,11 +76,14 @@ class Embark { logger: engine.logger, plugins: engine.plugins, version: self.version, - env: engine.env + env: engine.env, + contractsConfig: engine.config.contractsConfig }); dashboard.start(function () { - engine.events.on('abi-vanila', function (abi) { - dashboard.console.runCode(abi); + engine.events.on('code-generator-ready', function () { + engine.events.request('code-vanila-deployment', function (abi) { + dashboard.console.runCode(abi); + }); }); engine.logger.info('dashboard start'); @@ -100,7 +103,7 @@ class Embark { engine.startMonitor(); engine.startService("web3"); engine.startService("pipeline"); - engine.startService("abi"); + engine.startService("codeGenerator"); engine.startService("deployment"); engine.startService("ipfs"); @@ -155,7 +158,7 @@ class Embark { engine.startService("web3"); engine.startService("pipeline"); - engine.startService("abi"); + engine.startService("codeGenerator"); engine.startService("deployment"); callback(); }, @@ -195,6 +198,17 @@ class Embark { } } + runTests(file) { + let RunTests = require('./core/run_tests.js'); + RunTests.run(file); + } + } +// temporary until next refactor +Embark.initTests = function(options) { + let Test = require('./core/test.js'); + return new Test(options); +}; + module.exports = Embark; diff --git a/lib/pipeline/npm.js b/lib/pipeline/npm.js new file mode 100644 index 00000000..5a393ace --- /dev/null +++ b/lib/pipeline/npm.js @@ -0,0 +1,122 @@ +// TODO: this is horrible and needs to be refactored ASAP +let utils = require('../utils/utils.js'); +let fs = require('../core/fs.js'); +let o_fs = require('fs-extra'); + +let http = require('follow-redirects').http; +let https = require('follow-redirects').https; +var tar = require('tar'); + +class Npm { + + constructor(options) { + this.logger = options.logger; + } + + // TODO: callback should accept an error + getPackageVersion(packageName, version, returnContent, getFromGit, callback) { + let self = this; + let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version; + + utils.httpsGet(npmRegistry, function (res) { + + let body = ''; + res.on('data', function (d) { + body += d; + }); + res.on('end', function () { + let registryJSON = JSON.parse(body); + + let tarball = registryJSON.dist.tarball; + + var download = function(url, dest, cb) { + var file = o_fs.createWriteStream(dest); + var request = (url.substring(0,5) === 'https' ? https : http).get(url, function(response) { + response.pipe(file); + file.on('finish', function() { + file.close(cb); // close() is async, call cb after close completes. + }); + }).on('error', function(err) { // Handle errors + fs.unlink(dest); // Delete the file async. (But we don't check the result) + if (cb) cb(err.message); + }); + }; + + if (getFromGit) { + let repoName = registryJSON.repository.url.replace("git+https://github.com/", "").replace(".git",""); + let gitHead = registryJSON.gitHead; + + if (!gitHead) { + console.error("Could not download " + packageName + " " + version); + return callback("error"); + } + + let fileLocation = "https://raw.githubusercontent.com/" + repoName + "/" + gitHead + "/dist/web3.min.js"; + + let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; + if (fs.existsSync(packageDirectory + "/" + packageName + ".js")) { + if (returnContent) { + let distFile = packageDirectory + packageName + ".js"; + callback(fs.readFileSync(distFile).toString()); + } else { + callback(packageDirectory); + } + } else { + fs.mkdirpSync(packageDirectory); + self.logger.info("downloading " + packageName + " " + version + "...."); + + download(fileLocation, packageDirectory + "/" + packageName + ".js", function() { + o_fs.createReadStream(packageDirectory + "/" + packageName + ".js").pipe( + tar.x({ + strip: 1, + C: packageDirectory + }).on('end', function() { + if (returnContent) { + let distFile = packageDirectory + packageName + ".js"; + callback(fs.readFileSync(distFile).toString()); + } else { + callback(packageDirectory); + } + }) + ); + }); + } + + } else { + + let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; + if (fs.existsSync(packageDirectory + "/downloaded_package.tgz")) { + if (returnContent) { + let distFile = packageDirectory + returnContent; + callback(fs.readFileSync(distFile).toString()); + } else { + callback(packageDirectory); + } + } else { + fs.mkdirpSync(packageDirectory); + self.logger.info("downloading " + packageName + " " + version + "...."); + + download(tarball, packageDirectory + "/downloaded_package.tgz", function() { + o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe( + tar.x({ + strip: 1, + C: packageDirectory + }).on('end', function() { + if (returnContent) { + let distFile = packageDirectory + returnContent; + callback(fs.readFileSync(distFile).toString()); + } else { + callback(packageDirectory); + } + }) + ); + }); + } + } + + }); + }); + } +} + +module.exports = Npm; diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index d5af6cfb..ecc99978 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -1,5 +1,6 @@ /*jshint esversion: 6, loopfunc: true */ let fs = require('../core/fs.js'); +let async = require('async'); class Pipeline { @@ -11,73 +12,105 @@ class Pipeline { this.plugins = options.plugins; } - build(abi, contractsJSON, path) { + build(abi, contractsJSON, path, callback) { let self = this; - for (let targetFile in this.assetFiles) { - - let contentFiles = this.assetFiles[targetFile].map(file => { - self.logger.trace("reading " + file.filename); - - let pipelinePlugins = this.plugins.getPluginsFor('pipeline'); - - if (file.filename === 'embark.js') { - return {content: file.content + "\n" + abi, filename: file.filename, path: file.path, modified: true}; - } else if (file.filename === 'abi.js') { - return {content: abi, filename: file.filename, path: file.path, modified: true}; - } else if (['web3.js', 'ipfs.js', 'ipfs-api.js', 'orbit.js'].indexOf(file.filename) >= 0) { - file.modified = true; - return file; - } else { - - if (pipelinePlugins.length > 0) { - pipelinePlugins.forEach(function (plugin) { - try { - if (file.options && file.options.skipPipeline) { - return; - } - file.content = plugin.runPipeline({targetFile: file.filename, source: file.content}); - file.modified = true; - } - catch (err) { - self.logger.error(err.message); - } - }); - } - - return file; - } - }); - - let dir = targetFile.split('/').slice(0, -1).join('/'); - self.logger.trace("creating dir " + this.buildDir + dir); - fs.mkdirpSync(this.buildDir + dir); - - // if it's a directory - if (targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1) { - let targetDir = targetFile; - - if (targetDir.slice(-1) !== '/') { - targetDir = targetDir + '/'; - } - - contentFiles.map(function (file) { - let filename = file.filename.replace('app/', ''); - filename = filename.replace(targetDir, ''); - self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim); - - fs.copySync(self.buildDir + targetDir + filename, file.path, {overwrite: true}); - }); - } else { - let content = contentFiles.map(function (file) { - return file.content; - }).join("\n"); - - self.logger.info("writing file " + (this.buildDir + targetFile).bold.dim); - fs.writeFileSync(this.buildDir + targetFile, content); - } - } this.buildContracts(contractsJSON); + + // limit:1 due to issues when downloading required files such as web3.js + async.eachOfLimit(this.assetFiles, 1, function (files, targetFile, cb) { + + // limit:1 due to issues when downloading required files such as web3.js + async.mapLimit(files, 1, + function(file, fileCb) { + self.logger.trace("reading " + file.filename); + + let pipelinePlugins = self.plugins.getPluginsFor('pipeline'); + + if (file.filename === "$ALL_CONTRACTS") { + return fileCb(null, {content: abi, filename: file.filename, path: file.path, modified: true}); + } else if (file.filename === "$EMBARK_JS") { + return file.content(function(fileContent) { + return fileCb(null, {content: fileContent, filename: "embark.js", path: file.path, modified: true}); + }); + } else if (file.filename[0] === '$') { + let contractName = file.filename.substr(1); + return fileCb(null, {content: self.buildContractJS(contractName), filename: contractName + ".js", path: file.path, modified: true}); + } else if (file.filename === 'embark.js') { + return file.content(function(fileContent) { + return fileCb(null, {content: fileContent + "\n" + abi, filename: file.filename, path: file.path, modified: true}); + }); + } else if (file.filename === 'abi.js') { + return fileCb(null, {content: abi, filename: file.filename, path: file.path, modified: true}); + } else if (['web3.js', 'ipfs.js', 'ipfs-api.js', 'orbit.js'].indexOf(file.filename) >= 0) { + file.content(function(fileContent) { + return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, modified: true}); + }); + } else { + + if (pipelinePlugins.length > 0) { + file.content(function(fileContent) { + async.eachSeries(pipelinePlugins, function(plugin, pluginCB) { + if (file.options && file.options.skipPipeline) { + return pluginCB(); + } + + fileContent = plugin.runPipeline({targetFile: file.filename, source: fileContent}); + file.modified = true; + pluginCB(); + }, + function (err) { + if (err) { + self.logger.error(err.message); + } + return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, modified: true}); + }); + }); + } else { + file.content(function(fileContent) { + return fileCb(null, {content: fileContent, filename: file.filename, path: file.path, modified: true}); + }); + } + } + }, + function (err, contentFiles) { + let dir = targetFile.split('/').slice(0, -1).join('/'); + self.logger.trace("creating dir " + self.buildDir + dir); + fs.mkdirpSync(self.buildDir + dir); + + // if it's a directory + if (targetFile.slice(-1) === '/' || targetFile.indexOf('.') === -1) { + let targetDir = targetFile; + + if (targetDir.slice(-1) !== '/') { + targetDir = targetDir + '/'; + } + + contentFiles.map(function (file) { + let filename = file.filename.replace('app/', ''); + filename = filename.replace(targetDir, ''); + self.logger.info("writing file " + (self.buildDir + targetDir + filename).bold.dim); + + fs.copySync(self.buildDir + targetDir + filename, file.path, {overwrite: true}); + }); + } else { + let content = contentFiles.map(function (file) { + if (file === undefined) { + return ""; + } + return file.content; + }).join("\n"); + + self.logger.info("writing file " + (self.buildDir + targetFile).bold.dim); + fs.writeFileSync(self.buildDir + targetFile, content); + } + cb(); + } + ); + }, + function (err, results) { + callback(); + }); } buildContracts(contractsJSON) { @@ -88,6 +121,21 @@ class Pipeline { fs.writeJSONSync(this.buildDir + 'contracts/' + className + ".json", contract, {spaces: 2}); } } + + buildContractJS(contractName) { + let contractJSON = fs.readFileSync('dist/contracts/' + contractName + '.json').toString(); + //let EmbarkJSLib = fs.readFileSync(fs.embarkPath("js/embark.js")).toString(); + + let contractCode = ""; + contractCode += "let " + contractName + "JSONConfig = " + contractJSON + ";\n"; + //contractCode += EmbarkJSLib + "\n"; + contractCode += "let " + contractName + " = new EmbarkJS.Contract(" + contractName + "JSONConfig);\n"; + contractCode += "if (typeof module !== 'undefined' && module.exports) {\n"; + contractCode += "module.exports = " + contractName + ";\n"; + contractCode += "}\n"; + + return contractCode; + } } module.exports = Pipeline; diff --git a/lib/utils/utils.js b/lib/utils/utils.js index 3460f181..39d66bee 100644 --- a/lib/utils/utils.js +++ b/lib/utils/utils.js @@ -2,7 +2,8 @@ let path = require('path'); let globule = require('globule'); let merge = require('merge'); -let http = require('http'); +let http = require('follow-redirects').http; +let https = require('follow-redirects').https; let shelljs = require('shelljs'); function joinPath() { @@ -33,6 +34,10 @@ function httpGet(url, callback) { return http.get(url, callback); } +function httpsGet(url, callback) { + return https.get(url, callback); +} + function runCmd(cmd, options) { let result = shelljs.exec(cmd, options || {silent: true}); if (result.code !== 0) { @@ -65,6 +70,7 @@ module.exports = { recursiveMerge: recursiveMerge, checkIsAvailable: checkIsAvailable, httpGet: httpGet, + httpsGet: httpsGet, runCmd: runCmd, cd: cd, sed: sed, diff --git a/logo.png b/logo.png new file mode 100644 index 00000000..889989c3 Binary files /dev/null and b/logo.png differ diff --git a/package.json b/package.json index eeaa61ba..009cdfe6 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "embark", - "version": "2.4.3", + "version": "2.6.0", "description": "Embark is a framework that allows you to easily develop and deploy DApps", "scripts": { - "test": "grunt jshint && mocha test/ --no-timeouts", + "test": "grunt jshint && mocha test/ --no-timeouts && cd test_app/ && npm install && ../bin/embark test", "prepare": "webpack" }, "bin": { @@ -23,20 +23,25 @@ "chokidar": "^1.6.0", "colors": "^1.1.2", "commander": "^2.8.1", + "ejs": "^2.5.7", + "ethereumjs-testrpc": "3.9.2", "finalhandler": "^0.5.0", + "follow-redirects": "^1.2.4", "fs-extra": "^2.0.0", "globule": "^1.1.0", "ipfs-api": "^14.0.3", "merge": "^1.2.0", + "mocha": "^2.2.5", "orbit-db": "^0.17.3", "promptly": "^2.1.0", "serve-static": "^1.11.1", "shelljs": "^0.5.0", - "solc": "0.4.11", + "solc": "0.4.17", + "tar": "^3.1.5", "toposort": "^1.0.0", "underscore": "^1.8.3", "underscore.string": "^3.3.4", - "web3": "^0.18.2" + "web3": "^0.19.1" }, "author": "Iuri Matias ", "contributors": [], diff --git a/script_test.js b/script_test.js new file mode 100644 index 00000000..e68b0d63 --- /dev/null +++ b/script_test.js @@ -0,0 +1,14 @@ +var Web3 = require('web3'); + +web3 = new Web3(); + +web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')) + +EmbarkJS = require('./js/embark.js'); + +MyToken = require('./test_app/dist/js/mytoken.js'); + +console.log(MyToken.address); + +MyToken.balanceOf(web3.eth.accounts[0]).then((x) => console.log(x.toNumber())); + diff --git a/test/abi.js b/test/abi.js deleted file mode 100644 index 64f17741..00000000 --- a/test/abi.js +++ /dev/null @@ -1,59 +0,0 @@ -/*globals describe, it*/ -let ABIGenerator = require('../lib/contracts/abi.js'); -let assert = require('assert'); - -// TODO: instead 'eval' the code with a fake web3 object -// and check the generate code interacts as expected -describe('embark.ABIGenerator', function() { - this.timeout(0); - describe('#generateProvider', function() { - let generator = new ABIGenerator({blockchainConfig: {rpcHost: 'somehost', rpcPort: '1234'}, contractsManager: {}}); - - it('should generate code to connect to a provider', function() { - let providerCode = "\nif (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(web3.currentProvider);\n} else if (typeof Web3 !== 'undefined') {\n\tweb3 = new Web3(new Web3.providers.HttpProvider(\"http://somehost:1234\"));\n}\nweb3.eth.defaultAccount = web3.eth.accounts[0];"; - - assert.equal(generator.generateProvider(), providerCode); - }); - }); - - describe('#generateContracts', function() { - let generator = new ABIGenerator({blockchainConfig: {}, contractsManager: { - contracts: { - SimpleStorage: { - abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}], - gasEstimates: 12000, - deployedAddress: "0x123", - code: '12345' - }, - Foo: { - abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}], - gasEstimates: 12000, - deployedAddress: "0x124", - code: '123456' - } - } - }}); - - describe('with EmbarkJS', function() { - let withEmbarkJS = true; - - it('should generate contract code', function() { - let contractCode = "\n\nSimpleStorage = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x123', code: '12345', gasEstimates: 12000});\nFoo = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x124', code: '123456', gasEstimates: 12000});"; - assert.equal(generator.generateContracts(withEmbarkJS), contractCode); - }); - }); - - describe('with default interface', function() { - let withEmbarkJS = false; - - it('should generate contract code', function() { - let contractCode = "\n\nSimpleStorageAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nSimpleStorageContract = web3.eth.contract(SimpleStorageAbi);\nSimpleStorage = SimpleStorageContract.at('0x123');\nFooAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nFooContract = web3.eth.contract(FooAbi);\nFoo = FooContract.at('0x124');"; - assert.equal(generator.generateContracts(withEmbarkJS), contractCode); - }); - }); - - }); - - //describe('#generateABI', function() { - //}); -}); diff --git a/test/blockchain.js b/test/blockchain.js index b7690b5f..d3d70e76 100644 --- a/test/blockchain.js +++ b/test/blockchain.js @@ -30,7 +30,11 @@ describe('embark.Blockchain', function () { vmdebug: false, whisper: true, account: {}, - bootnodes: "" + bootnodes: "", + wsApi: [ "eth", "web3", "net", "shh" ], + wsHost: "localhost", + wsOrigins: false, + wsPort: 8546 }; let blockchain = new Blockchain(config, 'geth'); @@ -59,7 +63,11 @@ describe('embark.Blockchain', function () { vmdebug: false, whisper: false, account: {}, - bootnodes: "" + bootnodes: "", + wsApi: [ "eth", "web3", "net", "shh" ], + wsHost: "localhost", + wsOrigins: false, + wsPort: 8546 }; let blockchain = new Blockchain(config, 'geth'); diff --git a/test/code_generator.js b/test/code_generator.js new file mode 100644 index 00000000..999d4ca6 --- /dev/null +++ b/test/code_generator.js @@ -0,0 +1,59 @@ +/*globals describe, it*/ +let CodeGenerator = require('../lib/contracts/code_generator.js'); +let assert = require('assert'); + +// TODO: instead 'eval' the code with a fake web3 object +// and check the generate code interacts as expected +describe('embark.CodeGenerator', function() { + this.timeout(0); + describe('#generateProvider', function() { + let generator = new CodeGenerator({contractsConfig: {"dappConnection": [ "$WEB3", "http://somehost:1234" ] }, contractsManager: {}}); + + it('should generate code to connect to a provider', function() { + var providerCode = "function __reduce(arr, memo, iteratee, cb) {\n if (typeof cb !== 'function') {\n if (typeof memo === 'function' && typeof iteratee === 'function') {\n cb = iteratee;\n iteratee = memo;\n memo = [];\n } else {\n throw new TypeError('expected callback to be a function');\n }\n }\n\n if (!Array.isArray(arr)) {\n cb(new TypeError('expected an array'));\n return;\n }\n\n if (typeof iteratee !== 'function') {\n cb(new TypeError('expected iteratee to be a function'));\n return;\n }\n\n (function next(i, acc) {\n if (i === arr.length) {\n cb(null, acc);\n return;\n }\n\n iteratee(acc, arr[i], function(err, val) {\n if (err) {\n cb(err);\n return;\n }\n next(i + 1, val);\n });\n })(0, memo);\n};\nvar __mainContext = __mainContext || this;\n__mainContext.__LoadManager = function() { this.list = []; this.done = false; }\n__mainContext.__LoadManager.prototype.execWhenReady = function(cb) { if (this.done) { cb(); } else { this.list.push(cb) } }\n__mainContext.__LoadManager.prototype.doFirst = function(todo) { var self = this; todo(function() { self.done = true; self.list.map((x) => x.apply()) }) }\n__mainContext.__loadManagerInstance = new __mainContext.__LoadManager();\nvar whenEnvIsLoaded = function(cb) {\n if (typeof document !== 'undefined' && document !== null) {\n document.addEventListener('DOMContentLoaded', cb);\n } else {\n cb();\n }\n}\nwhenEnvIsLoaded(function(){\n __mainContext.__loadManagerInstance.doFirst(function(done) {\n __mainContext.web3 = undefined;\n__reduce([\"$WEB3\",\"http://somehost:1234\"],function(prev, value, next) {\n if (prev === false) {\n return next(null, false);\n }\n\n if (value === '$WEB3' && (typeof web3 !== 'undefined' && typeof Web3 !== 'undefined')) {\n web3 = new Web3(web3.currentProvider);\n } else if (value !== '$WEB3' && (typeof Web3 !== 'undefined' && ((typeof web3 === 'undefined') || (typeof web3 !== 'undefined' && (!web3.isConnected || (web3.isConnected && !web3.isConnected())))))) {\n\n web3 = new Web3(new Web3.providers.HttpProvider(value));\n } else if (value === '$WEB3') {\n return next(null, '');\n }\n\n web3.eth.getAccounts(function(err, account) {\n if (err) {\n next(null, true)\n } else {\n next(null, false)\n }\n });\n}, function(err, _result) {\n web3.eth.getAccounts(function(err, accounts) {\n web3.eth.defaultAccount = accounts[0];\n done();\n });\n});\n\n })\n});\n\n"; + + assert.equal(generator.generateProvider(), providerCode); + }); + }); + + describe('#generateContracts', function() { + let generator = new CodeGenerator({blockchainConfig: {}, contractsManager: { + contracts: { + SimpleStorage: { + abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}], + gasEstimates: 12000, + deployedAddress: "0x123", + code: '12345' + }, + Foo: { + abiDefinition: [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"type":"constructor"}], + gasEstimates: 12000, + deployedAddress: "0x124", + code: '123456' + } + } + }}); + + describe('with EmbarkJS', function() { + let withEmbarkJS = true; + + it('should generate contract code', function() { + var contractCode = "\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n __mainContext.SimpleStorage = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x123', code: '12345', gasEstimates: 12000});\n\n});\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n __mainContext.Foo = new EmbarkJS.Contract({abi: [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}], address: '0x124', code: '123456', gasEstimates: 12000});\n\n});\n"; + assert.equal(generator.generateContracts(withEmbarkJS), contractCode); + }); + }); + + describe('with default interface', function() { + let withEmbarkJS = false; + + it('should generate contract code', function() { + var contractCode = "\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n SimpleStorageAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nSimpleStorageContract = web3.eth.contract(SimpleStorageAbi);\nSimpleStorage = SimpleStorageContract.at('0x123');\n\n});\n__mainContext.__loadManagerInstance.execWhenReady(function() {\n FooAbi = [{\"constant\":true,\"inputs\":[],\"name\":\"storedData\",\"outputs\":[{\"name\":\"\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"x\",\"type\":\"uint256\"}],\"name\":\"set\",\"outputs\":[],\"payable\":false,\"type\":\"function\"},{\"constant\":true,\"inputs\":[],\"name\":\"get\",\"outputs\":[{\"name\":\"retVal\",\"type\":\"uint256\"}],\"payable\":false,\"type\":\"function\"},{\"inputs\":[{\"name\":\"initialValue\",\"type\":\"uint256\"}],\"type\":\"constructor\"}];\nFooContract = web3.eth.contract(FooAbi);\nFoo = FooContract.at('0x124');\n\n});\n"; + assert.equal(generator.generateContracts(withEmbarkJS), contractCode); + }); + }); + + }); + + //describe('#generateABI', function() { + //}); +}); diff --git a/test/compiler.js b/test/compiler.js index c829b09e..e0eb71aa 100644 --- a/test/compiler.js +++ b/test/compiler.js @@ -1,24 +1,25 @@ /*globals describe, it*/ let Compiler = require('../lib/contracts/compiler.js'); let TestLogger = require('../lib/core/test_logger.js'); +let File = require('../lib/core/file.js'); let assert = require('assert'); let fs = require('fs'); let readFile = function(file) { - return {filename: file, content: fs.readFileSync(file).toString()}; + return new File({filename: file, type: 'dapp_file', path: file}); }; describe('embark.Compiler', function() { - let compiler = new Compiler({logger: new TestLogger({})}); + let compiler = new Compiler({logger: new TestLogger({}), solcVersion: '0.4.11'}); describe('#compile_solidity', function() { this.timeout(0); let expectedObject = {}; - expectedObject["SimpleStorage"] = {"code":"6060604052341561000c57fe5b60405160208061011383398101604052515b60008190555b505b60df806100346000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","realRuntimeBytecode": "606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820","runtimeBytecode":"606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","swarmHash": "a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c","gasEstimates":{"creation":[20141,44600],"external":{"get()":400,"set(uint256)":20144,"storedData()":355},"internal":{}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"type":"constructor"}]}; + expectedObject["SimpleStorage"] = {"code":"6060604052341561000c57fe5b60405160208061011383398101604052515b60008190555b505b60df806100346000396000f300606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","filename": "test/contracts/simple_storage.sol","realRuntimeBytecode": "606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820","runtimeBytecode":"606060405263ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416632a1afcd98114604d57806360fe47b114606c5780636d4ce63c14607e575bfe5b3415605457fe5b605a609d565b60408051918252519081900360200190f35b3415607357fe5b607c60043560a3565b005b3415608557fe5b605a60ac565b60408051918252519081900360200190f35b60005481565b60008190555b50565b6000545b905600a165627a7a72305820a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c0029","swarmHash": "a89e7fdce74e002378f275124c03a50f7796db2cf1f0d1ad12dd8bafe6a8892c","gasEstimates":{"creation":[20141,44600],"external":{"get()":400,"set(uint256)":20144,"storedData()":355},"internal":{}},"functionHashes":{"get()":"6d4ce63c","set(uint256)":"60fe47b1","storedData()":"2a1afcd9"},"abiDefinition":[{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initialValue","type":"uint256"}],"payable":false,"type":"constructor"}]}; - expectedObject["Token"] = {"code":"6060604052341561000c57fe5b6040516020806104be83398101604052515b600160a060020a033316600090815260208190526040902081905560028190555b505b61046e806100506000396000f300606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b30029","realRuntimeBytecode": "606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820","runtimeBytecode":"606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b30029","swarmHash": "f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b3","gasEstimates":{"creation":[40472,226800],"external":{"allowance(address,address)":809,"approve(address,uint256)":22334,"balanceOf(address)":673,"totalSupply()":396,"transfer(address,uint256)":43635,"transferFrom(address,address,uint256)":64415},"internal":{"safeToAdd(uint256,uint256)":41}},"functionHashes":{"allowance(address,address)":"dd62ed3e","approve(address,uint256)":"095ea7b3","balanceOf(address)":"70a08231","totalSupply()":"18160ddd","transfer(address,uint256)":"a9059cbb","transferFrom(address,address,uint256)":"23b872dd"},"abiDefinition":[{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"supply","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"value","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"_allowance","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initial_balance","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]} + expectedObject["Token"] = {"code":"6060604052341561000c57fe5b6040516020806104be83398101604052515b600160a060020a033316600090815260208190526040902081905560028190555b505b61046e806100506000396000f300606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b30029","filename": "test/contracts/token.sol","realRuntimeBytecode": "606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820","runtimeBytecode":"606060405236156100755763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663095ea7b3811461007757806318160ddd146100aa57806323b872dd146100cc57806370a0823114610105578063a9059cbb14610133578063dd62ed3e14610166575bfe5b341561007f57fe5b610096600160a060020a036004351660243561019a565b604080519115158252519081900360200190f35b34156100b257fe5b6100ba610205565b60408051918252519081900360200190f35b34156100d457fe5b610096600160a060020a036004358116906024351660443561020c565b604080519115158252519081900360200190f35b341561010d57fe5b6100ba600160a060020a0360043516610323565b60408051918252519081900360200190f35b341561013b57fe5b610096600160a060020a0360043516602435610342565b604080519115158252519081900360200190f35b341561016e57fe5b6100ba600160a060020a0360043581169060243516610407565b60408051918252519081900360200190f35b600160a060020a03338116600081815260016020908152604080832094871680845294825280832086905580518681529051929493927f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925929181900390910190a35060015b92915050565b6002545b90565b600160a060020a038316600090815260208190526040812054829010156102335760006000fd5b600160a060020a0380851660009081526001602090815260408083203390941683529290522054829010156102685760006000fd5b600160a060020a03831660009081526020819052604090205461028b9083610434565b15156102975760006000fd5b600160a060020a038085166000818152600160209081526040808320338616845282528083208054889003905583835282825280832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b9392505050565b600160a060020a0381166000908152602081905260409020545b919050565b600160a060020a033316600090815260208190526040812054829010156103695760006000fd5b600160a060020a03831660009081526020819052604090205461038c9083610434565b15156103985760006000fd5b600160a060020a0333811660008181526020818152604080832080548890039055938716808352918490208054870190558351868152935191937fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef929081900390910190a35060015b92915050565b600160a060020a038083166000908152600160209081526040808320938516835292905220545b92915050565b808201829010155b929150505600a165627a7a72305820f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b30029","swarmHash": "f1e53450d0d5723ba8f341856e7786c43607109cbb25ff3975ce9ccd042506b3","gasEstimates":{"creation":[40472,226800],"external":{"allowance(address,address)":809,"approve(address,uint256)":22334,"balanceOf(address)":673,"totalSupply()":396,"transfer(address,uint256)":43635,"transferFrom(address,address,uint256)":64415},"internal":{"safeToAdd(uint256,uint256)":41}},"functionHashes":{"allowance(address,address)":"dd62ed3e","approve(address,uint256)":"095ea7b3","balanceOf(address)":"70a08231","totalSupply()":"18160ddd","transfer(address,uint256)":"a9059cbb","transferFrom(address,address,uint256)":"23b872dd"},"abiDefinition":[{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"supply","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"value","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"ok","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"_allowance","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initial_balance","type":"uint256"}],"payable":false,"type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"}]} it('should generate compiled code and abi', function(done) { compiler.compile_solidity([ diff --git a/test/contracts.js b/test/contracts.js index 211eabe5..1679e326 100644 --- a/test/contracts.js +++ b/test/contracts.js @@ -1,11 +1,12 @@ /*globals describe, it*/ let ContractsManager = require('../lib/contracts/contracts.js'); let Logger = require('../lib/core/logger.js'); +let File = require('../lib/core/file.js'); let assert = require('assert'); let fs = require('fs'); let readFile = function(file) { - return {filename: file, content: fs.readFileSync(file).toString()}; + return new File({filename: file, type: 'dapp_file', path: file}); }; describe('embark.Contratcs', function() { @@ -17,6 +18,19 @@ describe('embark.Contratcs', function() { readFile('test/contracts/token.sol') ], contractsConfig: { + "versions": { + "web3.js": "0.19.1", + "solc": "0.4.11" + }, + "deployment": { + "host": "localhost", + "port": 8545, + "type": "rpc" + }, + "dappConnection": [ + "$WEB3", + "localhost:8545" + ], "gas": "auto", "contracts": { "Token": { @@ -76,6 +90,19 @@ describe('embark.Contratcs', function() { readFile('test/contracts/token_storage.sol') ], contractsConfig: { + "versions": { + "web3.js": "0.19.1", + "solc": "0.4.11" + }, + "deployment": { + "host": "localhost", + "port": 8545, + "type": "rpc" + }, + "dappConnection": [ + "$WEB3", + "localhost:8545" + ], "gas": "auto", "contracts": { "TokenStorage": { diff --git a/test_app/app/contracts/another_storage.sol b/test_app/app/contracts/another_storage.sol index ba837449..92233769 100644 --- a/test_app/app/contracts/another_storage.sol +++ b/test_app/app/contracts/another_storage.sol @@ -1,8 +1,9 @@ -pragma solidity ^0.4.7; +pragma solidity ^0.4.17; contract AnotherStorage { address public simpleStorageAddress; + address simpleStorageAddress2; - function AnotherStorage(address addr) { + function AnotherStorage(address addr) public { simpleStorageAddress = addr; } diff --git a/test_app/app/contracts/invalid_file.sol__tmp__ b/test_app/app/contracts/invalid_file.sol__tmp__ new file mode 100644 index 00000000..0eff9e71 --- /dev/null +++ b/test_app/app/contracts/invalid_file.sol__tmp__ @@ -0,0 +1,66 @@ +// https://github.com/nexusdev/erc20/blob/master/contracts/base.sol + +pragma solidity ^0.4.2; +contract Token { + + event Transfer(address indexed from, address indexed to, uint value); + event Approval( address indexed owner, address indexed spender, uint value); + + mapping( address => uint ) _balances; + mapping( address => mapping( address => uint ) ) _approvals; + uint public _supply; + //uint public _supply2; + function Token( uint initial_balance ) { + _balances[msg.sender] = initial_balance; + _supply = initial_balance; + } + function totalSupply() constant returns (uint supply) { + return _supply; + } + function balanceOf( address who ) constant returns (uint value) { + return _balances[who]; + } + function transfer( address to, uint value) returns (bool ok) { + if( _balances[msg.sender] < value ) { + throw; + } + if( !safeToAdd(_balances[to], value) ) { + throw; + } + _balances[msg.sender] -= value; + _balances[to] += value; + Transfer( msg.sender, to, value ); + return true; + } + function transferFrom( address from, address to, uint value) returns (bool ok) { + // if you don't have enough balance, throw + if( _balances[from] < value ) { + throw; + } + // if you don't have approval, throw + if( _approvals[from][msg.sender] < value ) { + throw; + } + if( !safeToAdd(_balances[to], value) ) { + throw; + } + // transfer and return true + _approvals[from][msg.sender] -= value; + _balances[from] -= value; + _balances[to] += value; + Transfer( from, to, value ); + return true; + } + function approve(address spender, uint value) returns (bool ok) { + // TODO: should increase instead + _approvals[msg.sender][spender] = value; + Approval( msg.sender, spender, value ); + return true; + } + function allowance(address owner, address spender) constant returns (uint _allowance) { + return _approvals[owner][spender]; + } + function safeToAdd(uint a, uint b) internal returns (bool) { + return (a + b >= a); + } +} diff --git a/test_app/app/contracts/ownable.sol b/test_app/app/contracts/ownable.sol new file mode 100644 index 00000000..af8aa0cf --- /dev/null +++ b/test_app/app/contracts/ownable.sol @@ -0,0 +1,42 @@ +pragma solidity ^0.4.17; + +/** + * @title Ownable + * @dev The Ownable contract has an owner address, and provides basic authorization control + * functions, this simplifies the implementation of "user permissions". + */ +contract Ownable { + address public owner; + + + /** + * @dev The Ownable constructor sets the original `owner` of the contract to the sender + * account. + */ + function Ownable() public { + owner = msg.sender; + } + + + /** + * @dev Throws if called by any account other than the owner. + */ + modifier onlyOwner() { + if (msg.sender != owner) { + revert(); + } + _; + } + + + /** + * @dev Allows the current owner to transfer control of the contract to a newOwner. + * @param newOwner The address to transfer ownership to. + */ + function transferOwnership(address newOwner) public onlyOwner { + if (newOwner != address(0)) { + owner = newOwner; + } + } + +} diff --git a/test_app/app/contracts/simple_storage.sol b/test_app/app/contracts/simple_storage.sol index 1035d12d..58c90a35 100644 --- a/test_app/app/contracts/simple_storage.sol +++ b/test_app/app/contracts/simple_storage.sol @@ -1,22 +1,29 @@ -pragma solidity ^0.4.7; -contract SimpleStorage { +pragma solidity ^0.4.17; + +import "ownable.sol"; + +contract SimpleStorage is Ownable { uint public storedData; - function() payable { } + function() public payable { } - function SimpleStorage(uint initialValue) { + function SimpleStorage(uint initialValue) public { storedData = initialValue; } - function set(uint x) { + function set(uint x) public { storedData = x; } - function get() constant returns (uint retVal) { + function set2(uint x, uint unusedGiveWarning) public onlyOwner { + storedData = x; + } + + function get() public view returns (uint retVal) { return storedData; } - function getS() constant returns (string d) { + function getS() public pure returns (string d) { return "hello"; } diff --git a/test_app/app/contracts/test.sol b/test_app/app/contracts/test.sol new file mode 100644 index 00000000..3d347f3f --- /dev/null +++ b/test_app/app/contracts/test.sol @@ -0,0 +1,17 @@ +pragma solidity ^0.4.17; + +library ZAMyLib { + + function add(uint _a, uint _b) public pure returns (uint _c) { + return _a + _b; + } + +} + +contract Test { + + function testAdd() public pure returns (uint _result) { + return ZAMyLib.add(1, 2); + } + +} diff --git a/test_app/app/contracts/token.sol b/test_app/app/contracts/token.sol index 0eff9e71..32b1dafd 100644 --- a/test_app/app/contracts/token.sol +++ b/test_app/app/contracts/token.sol @@ -1,6 +1,6 @@ // https://github.com/nexusdev/erc20/blob/master/contracts/base.sol -pragma solidity ^0.4.2; +pragma solidity ^0.4.17; contract Token { event Transfer(address indexed from, address indexed to, uint value); @@ -10,39 +10,39 @@ contract Token { mapping( address => mapping( address => uint ) ) _approvals; uint public _supply; //uint public _supply2; - function Token( uint initial_balance ) { + function Token( uint initial_balance ) public { _balances[msg.sender] = initial_balance; _supply = initial_balance; } - function totalSupply() constant returns (uint supply) { + function totalSupply() public constant returns (uint supply) { return _supply; } - function balanceOf( address who ) constant returns (uint value) { + function balanceOf( address who ) public constant returns (uint value) { return _balances[who]; } - function transfer( address to, uint value) returns (bool ok) { + function transfer( address to, uint value) public returns (bool ok) { if( _balances[msg.sender] < value ) { - throw; + revert(); } if( !safeToAdd(_balances[to], value) ) { - throw; + revert(); } _balances[msg.sender] -= value; _balances[to] += value; Transfer( msg.sender, to, value ); return true; } - function transferFrom( address from, address to, uint value) returns (bool ok) { + function transferFrom( address from, address to, uint value) public returns (bool ok) { // if you don't have enough balance, throw if( _balances[from] < value ) { - throw; + revert(); } // if you don't have approval, throw if( _approvals[from][msg.sender] < value ) { - throw; + revert(); } if( !safeToAdd(_balances[to], value) ) { - throw; + revert(); } // transfer and return true _approvals[from][msg.sender] -= value; @@ -51,16 +51,16 @@ contract Token { Transfer( from, to, value ); return true; } - function approve(address spender, uint value) returns (bool ok) { + function approve(address spender, uint value) public returns (bool ok) { // TODO: should increase instead _approvals[msg.sender][spender] = value; Approval( msg.sender, spender, value ); return true; } - function allowance(address owner, address spender) constant returns (uint _allowance) { + function allowance(address owner, address spender) public constant returns (uint _allowance) { return _approvals[owner][spender]; } - function safeToAdd(uint a, uint b) internal returns (bool) { + function safeToAdd(uint a, uint b) internal pure returns (bool) { return (a + b >= a); } } diff --git a/test_app/app/css/main.css b/test_app/app/css/main.css index abfcd67f..bdec3790 100644 --- a/test_app/app/css/main.css +++ b/test_app/app/css/main.css @@ -24,3 +24,27 @@ div { margin-bottom: 0; } +.status-offline { + vertical-align: middle; + margin-left: 5px; + margin-top: 4px; + width: 12px; + height: 12px; + background: red; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; +} + +.status-online { + vertical-align: middle; + margin-left: 5px; + margin-top: 4px; + width: 12px; + height: 12px; + background: mediumseagreen; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + border-radius: 10px; +} + diff --git a/test_app/app/index.html b/test_app/app/index.html index 417f6096..10b27f23 100644 --- a/test_app/app/index.html +++ b/test_app/app/index.html @@ -9,8 +9,8 @@
@@ -37,7 +37,8 @@
- note: You need to have an IPFS node running + +

Save text to IPFS

@@ -72,11 +73,12 @@

EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'})
- +
- The node you are using does not support whisper - + + +

Listen To channel

@@ -97,7 +99,7 @@

EmbarkJS.Messages.setProvider('whisper')
- +
diff --git a/test_app/app/js/index.js b/test_app/app/js/index.js index 27416e49..52104fc6 100644 --- a/test_app/app/js/index.js +++ b/test_app/app/js/index.js @@ -11,15 +11,31 @@ $(document).ready(function() { $("#blockchain button.set").click(function() { var value = parseInt($("#blockchain input.text").val(), 10); - SimpleStorage.set(value); - addToLog("#blockchain", "SimpleStorage.set(" + value + ")"); + + // If web3.js 1.0 is being used + if (EmbarkJS.isNewWeb3()) { + SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount}); + addToLog("#blockchain", "SimpleStorage.methods.set(value).send({from: web3.eth.defaultAccount})"); + } else { + SimpleStorage.set(value); + addToLog("#blockchain", "SimpleStorage.set(" + value + ")"); + } + }); $("#blockchain button.get").click(function() { - SimpleStorage.get().then(function(value) { - $("#blockchain .value").html(value.toNumber()); - }); - addToLog("#blockchain", "SimpleStorage.get()"); + // If web3.js 1.0 is being used + if (EmbarkJS.isNewWeb3()) { + SimpleStorage.methods.get().call(function(err, value) { + $("#blockchain .value").html(value); + }); + addToLog("#blockchain", "SimpleStorage.methods.get(console.log)"); + } else { + SimpleStorage.get().then(function(value) { + $("#blockchain .value").html(value.toNumber()); + }); + addToLog("#blockchain", "SimpleStorage.get()"); + } }); }); @@ -28,23 +44,59 @@ $(document).ready(function() { // Storage (IPFS) example // =========================== $(document).ready(function() { + // automatic set if config/storage.json has "enabled": true and "provider": "ipfs" //EmbarkJS.Storage.setProvider('ipfs',{server: 'localhost', port: '5001'}); + $("#storage .error").hide(); + EmbarkJS.Storage.setProvider('ipfs') + .then(function(){ + console.log('Provider set to IPFS'); + EmbarkJS.Storage.ipfsConnection.ping() + .then(function(){ + $("#status-storage").addClass('status-online'); + $("#storage-controls").show(); + }) + .catch(function(err) { + if(err){ + console.log("IPFS Connection Error => " + err.message); + $("#storage .error").show(); + $("#status-storage").addClass('status-offline'); + $("#storage-controls").hide(); + } + }); + }) + .catch(function(err){ + console.log('Failed to set IPFS as Provider:', err.message); + $("#storage .error").show(); + $("#status-storage").addClass('status-offline'); + $("#storage-controls").hide(); + }); + $("#storage button.setIpfsText").click(function() { var value = $("#storage input.ipfsText").val(); EmbarkJS.Storage.saveText(value).then(function(hash) { $("span.textHash").html(hash); $("input.textHash").val(hash); + addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })"); + }) + .catch(function(err) { + if(err){ + console.log("IPFS saveText Error => " + err.message); + } }); - addToLog("#storage", "EmbarkJS.Storage.saveText('" + value + "').then(function(hash) { })"); }); $("#storage button.loadIpfsHash").click(function() { var value = $("#storage input.textHash").val(); EmbarkJS.Storage.get(value).then(function(content) { $("span.ipfsText").html(content); + addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })"); + }) + .catch(function(err) { + if(err){ + console.log("IPFS get Error => " + err.message); + } }); - addToLog("#storage", "EmbarkJS.Storage.get('" + value + "').then(function(content) { })"); }); $("#storage button.uploadFile").click(function() { @@ -52,8 +104,13 @@ $(document).ready(function() { EmbarkJS.Storage.uploadFile(input).then(function(hash) { $("span.fileIpfsHash").html(hash); $("input.fileIpfsHash").val(hash); + addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })"); + }) + .catch(function(err) { + if(err){ + console.log("IPFS uploadFile Error => " + err.message); + } }); - addToLog("#storage", "EmbarkJS.Storage.uploadFile($('input[type=file]')).then(function(hash) { })"); }); $("#storage button.loadIpfsFile").click(function() { @@ -73,13 +130,19 @@ $(document).ready(function() { $(document).ready(function() { $("#communication .error").hide(); - //web3.version.getWhisper(function(err, res) { - // if (err) { - // $("#communication .error").show(); - // } else { - // EmbarkJS.Messages.setProvider('whisper'); - // } - //}); + $("#communication .errorVersion").hide(); + if (EmbarkJS.Messages.providerName === 'whisper') { + EmbarkJS.Messages.getWhisperVersion(function(err, version) { + if (err) { + $("#communication .error").show(); + $("#communication-controls").hide(); + $("#status-communication").addClass('status-offline'); + } else { + EmbarkJS.Messages.setProvider('whisper'); + $("#status-communication").addClass('status-online'); + } + }); + } $("#communication button.listenToChannel").click(function() { var channel = $("#communication .listen input.channel").val(); @@ -98,4 +161,3 @@ $(document).ready(function() { }); }); - diff --git a/test_app/app/js/test.js b/test_app/app/js/test.js index ad51fa25..a4ba623c 100644 --- a/test_app/app/js/test.js +++ b/test_app/app/js/test.js @@ -1,53 +1,56 @@ $(document).ready(function() { - async.waterfall([ - function test1(callback) { - AnotherStorage.simpleStorageAddress().then(function(simpleStorageAddress) { - $("#tests").append("
test 1: " + (simpleStorageAddress === SimpleStorage.address)); - callback(); - }); - }, - function test2(callback) { - SimpleStorage.storedData().then(function(result) { - $("#tests").append("
test 2 (true first time): " + (result.toNumber() === 100)); - $("#tests").append("
test 2 (true after): " + (result.toNumber() === 150)); - callback(); - }); - }, - function test3(callback) { - SimpleStorage.set(150).then(function() { - SimpleStorage.get().then(function(result) { - $("#tests").append("
test 3: " + (result.toNumber() === 150)); + document.getElementById("runTests").onclick = function() { + async.waterfall([ + function test1(callback) { + AnotherStorage.methods.simpleStorageAddress().call().then(function(simpleStorageAddress) { + $("#tests").append("
test 1: " + (simpleStorageAddress === SimpleStorage._address)); callback(); }); - }); - }, - function test4(callback) { - $("#tests").append("
test 4: " + (Token.address === "undefined")); - $("#tests").append("
test 4: " + (MyToken.address !== undefined)); - $("#tests").append("
test 4: " + (MyToken2.address !== undefined)); - callback(); - }, - function test5(callback) { - MyToken._supply().then(function(result) { - $("#tests").append("
test 5: " + (result.toNumber() === 1000)); + }, + function test2(callback) { + SimpleStorage.methods.storedData().call().then(function(result) { + $("#tests").append("
test 2 (true first time): " + (result === "100")); + $("#tests").append("
test 2 (true after): " + (result === "150")); + callback(); + }); + }, + function test3(callback) { + SimpleStorage.methods.set(150).send({from: web3.eth.defaultAccount}).then(function() { + SimpleStorage.methods.get().call().then(function(result) { + $("#tests").append("
test 3: " + (result === "150")); + callback(); + }); + }); + }, + function test4(callback) { + $("#tests").append("
test 4: " + (Token._address === null)); + $("#tests").append("
test 4: " + (MyToken._address !== undefined)); + $("#tests").append("
test 4: " + (MyToken2._address !== undefined)); callback(); - }); - }, - function test6(callback) { - MyToken2._supply().then(function(result) { - $("#tests").append("
test 6: " + (result.toNumber() === 2000)); + }, + function test5(callback) { + MyToken.methods._supply().call().then(function(result) { + $("#tests").append("
test 5: " + (result === "1000")); + callback(); + }); + }, + function test6(callback) { + MyToken2.methods._supply().call().then(function(result) { + $("#tests").append("
test 6: " + (result === "2000")); + callback(); + }); + }, + function test7(callback) { + $("#tests").append("
test 7: " + (AlreadyDeployedToken._address === "0xeCE374063fE5Cc7EFbACA0a498477CaDA94E5AD6")); callback(); - }); - }, - function test7(callback) { - $("#tests").append("
test 7: " + (AlreadyDeployedToken.address === "0x123")); - callback(); - } - ], function (err, result) { + } + ], function (err, result) { $("#tests").append("
done"); - }); + }); + + }; }); diff --git a/test_app/app/js/token_test.js b/test_app/app/js/token_test.js new file mode 100644 index 00000000..e69de29b diff --git a/test_app/app/test.html b/test_app/app/test.html index 2fcceb29..ee41604a 100644 --- a/test_app/app/test.html +++ b/test_app/app/test.html @@ -6,6 +6,7 @@ +
diff --git a/test_app/config/blockchain.json b/test_app/config/blockchain.json index 1dcf4256..816d82c3 100644 --- a/test_app/config/blockchain.json +++ b/test_app/config/blockchain.json @@ -12,7 +12,8 @@ "rpcCorsDomain": "http://localhost:8000", "account": { "password": "config/development/password" - } + }, + "wsOrigins": "http://localhost:8000" }, "testnet": { "networkType": "testnet", diff --git a/test_app/config/communication.json b/test_app/config/communication.json index 07c7851a..80ec2f80 100644 --- a/test_app/config/communication.json +++ b/test_app/config/communication.json @@ -2,6 +2,11 @@ "default": { "enabled": true, "provider": "whisper", - "available_providers": ["whisper", "orbit"] + "available_providers": ["whisper", "orbit"], + "connection": { + "host": "localhost", + "port": 8546, + "type": "ws" + } } } diff --git a/test_app/config/contracts.json b/test_app/config/contracts.json index 7149a00b..d2a7e2b3 100644 --- a/test_app/config/contracts.json +++ b/test_app/config/contracts.json @@ -1,7 +1,25 @@ { "default": { + "versions": { + "web3.js": "1.0.0-beta", + "solc": "0.4.17" + }, + "deployment": { + "host": "localhost", + "port": 8545, + "type": "rpc" + }, + "dappConnection": [ + "$WEB3", + "http://localhost:8550", + "http://localhost:8545", + "http://localhost:8550" + ], "gas": "auto", "contracts": { + "Ownable": { + "deploy": false + }, "SimpleStorage": { "args": [ 100 @@ -24,7 +42,7 @@ "args": [200] }, "AlreadyDeployedToken": { - "address": "0x123", + "address": "0xece374063fe5cc7efbaca0a498477cada94e5ad6", "instanceOf": "Token" } } diff --git a/test_app/config/development/genesis.json b/test_app/config/development/genesis.json index 9f2d1562..4a50a438 100644 --- a/test_app/config/development/genesis.json +++ b/test_app/config/development/genesis.json @@ -1,4 +1,7 @@ { + "config": { + "homesteadBlock": 1 + }, "nonce": "0x0000000000000042", "difficulty": "0x0", "alloc": { diff --git a/test_app/config/storage.json b/test_app/config/storage.json index 9d686457..6faf0e1a 100644 --- a/test_app/config/storage.json +++ b/test_app/config/storage.json @@ -11,6 +11,7 @@ "enabled": true, "provider": "ipfs", "host": "localhost", - "port": 5001 + "port": 5001, + "getUrl": "http://localhost:8080/ipfs/" } } diff --git a/test_app/embark.json b/test_app/embark.json index 0dd46dd1..2b275be5 100644 --- a/test_app/embark.json +++ b/test_app/embark.json @@ -7,9 +7,14 @@ "js/embark.js": ["embark.js"], "js/abi.js": "abi.js", "js/test.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/async.min.js", "app/js/test.js"], + "js/mytoken.js": ["$MyToken", "app/js/token_test.js"], "index.html": "app/index.html", "test.html": "app/test.html", - "test2.html": "app/test2.html" + "test2.html": "app/test2.html", + "js/myweb3.js": "web3-0.18.js", + "js/web3.js": "web3.js", + "js/all_contracts.js": "$ALL_CONTRACTS", + "js/only_embark.js": "$EMBARK_JS" }, "buildDir": "dist/", "config": "config/", diff --git a/test_app/package.json b/test_app/package.json index d1ea282a..ddf18ab5 100644 --- a/test_app/package.json +++ b/test_app/package.json @@ -9,13 +9,9 @@ "author": "", "license": "ISC", "homepage": "", - "devDependencies": { - "embark": "file:../", - "mocha": "^2.2.5" - }, + "devDependencies": {}, "dependencies": { "embark-babel": "^1.0.0", - "embark-service": "./extensions/embark-service", - "ethereumjs-testrpc": "^3.0.3" + "embark-service": "./extensions/embark-service" } } diff --git a/test_app/test/another_storage_spec.js b/test_app/test/another_storage_spec.js index b60297b5..d9f43e8c 100644 --- a/test_app/test/another_storage_spec.js +++ b/test_app/test/another_storage_spec.js @@ -1,7 +1,4 @@ -var assert = require('assert'); -var EmbarkSpec = require('embark/lib/core/test.js'); - -describe("AnotherStorage", function() { +contract("AnotherStorage", function() { before(function(done) { this.timeout(0); var contractsConfig = { diff --git a/test_app/test/simple_storage_spec.js b/test_app/test/simple_storage_spec.js index b330ced6..f760ae3a 100644 --- a/test_app/test/simple_storage_spec.js +++ b/test_app/test/simple_storage_spec.js @@ -1,6 +1,3 @@ -var assert = require('assert'); -var EmbarkSpec = require('embark/lib/core/test.js'); - describe("SimpleStorage", function() { before(function(done) { this.timeout(0); diff --git a/test_app/test/token_spec.js b/test_app/test/token_spec.js index 93eb28b5..d24dbe58 100644 --- a/test_app/test/token_spec.js +++ b/test_app/test/token_spec.js @@ -1,6 +1,3 @@ -var assert = require('assert'); -var EmbarkSpec = require('embark/lib/core/test.js'); - describe("Token", function() { before(function(done) { this.timeout(0); @@ -31,7 +28,7 @@ describe("Token", function() { }); it("not deploy Token", function(done) { - assert.equal(Token.address, "undefined"); + assert.equal(Token.address, ""); done(); }); diff --git a/webpack.config.js b/webpack.config.js index 9ba511ec..b3c5b11b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,7 @@ module.exports = { entry: './js/embark.js', output: { - libraryTarget: 'var', + libraryTarget: 'umd', library: 'EmbarkJS', path: __dirname + '/js/build', filename: 'embark.bundle.js'