diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
deleted file mode 100644
index 1f513b9bb3..0000000000
--- a/.github/FUNDING.yml
+++ /dev/null
@@ -1,2 +0,0 @@
-github: ethers-io
-custom: [ 'https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2', 'https://www.buymeacoffee.com/ricmoo' ]
diff --git a/.github/ISSUE_TEMPLATE/bug-report-legacy.yml b/.github/ISSUE_TEMPLATE/bug-report-legacy.yml
deleted file mode 100644
index 278266740c..0000000000
--- a/.github/ISSUE_TEMPLATE/bug-report-legacy.yml
+++ /dev/null
@@ -1,81 +0,0 @@
-name: "Bug Report v5 (legacy)"
-description: "Open an issue for a bug in Ethers v5 (legacy)"
-title: "Add Bug Title Here"
-labels: [ "investigate", "v5" ]
-assignees:
- - ricmoo
-body:
- - type: markdown
- attributes:
- value: |
- **READ THIS FIRST** and follow all instructions, please. `:)`
-
- Thank you for taking the time to report an issue. This form is for reporting **bugs within ethers**, specifically for the legacy v5 branch.
-
- If you are **new to ethers** or *uncertain* whether this is a bug in ethers, a bug in another framework or a bug in your own code, please [start a discussion](https://github.com/ethers-io/ethers.js/discussions) first.
- - type: input
- id: version
- attributes:
- label: Ethers Version
- description: What version of ethers are you using? Before opening an issue, please make sure you are up to date.
- placeholder: 5.y.z
- validations:
- required: true
- - type: input
- id: search-terms
- attributes:
- label: Search Terms
- description: Have you searched for answers [in the documentation](https://docs.ethers.org), through [the issues](https://github.com/ethers-io/ethers.js/issues) and [on the discusions](https://github.com/ethers-io/ethers.js/discussions)? Please include the search terms you have tried. This helps us add more keywords where needed.
- placeholder: e.g. abi, network, utf8
- - type: textarea
- id: about-the-bug
- attributes:
- label: Describe the Problem
- description: Please describe what you expected to happen vs what did happen?
- placeholder: What happened?
- validations:
- required: true
- - type: textarea
- id: code-snippet
- attributes:
- label: Code Snippet
- description: If possible, please include a **short and concise** code snippets that can reproduce this issue. Ideally code that can be pasted into the [Ethers Playground](https://playground.ethers.org).
- placeholder: e.g. provider.getBlockNumber()
- render: shell
- - type: textarea
- id: contract-abi
- attributes:
- label: Contract ABI
- description: If this involves a contract, please include any **concise and relevant** ABI fragments.
- placeholder: e.g. [ 'function balanceOf(address owner) view returns (uint)' ]
- render: shell
- - type: textarea
- id: errors
- attributes:
- label: Errors
- description: If there is an error, please include the **entire error** (redacting any sensitive information).
- placeholder: "e.g. Error: invalid name (code='INVALID_ARGUMENT, ...)"
- render: shell
- - type: dropdown
- id: environment
- attributes:
- label: Environment
- description: What environment, platforms or frameworks are you using? Select all that apply.
- multiple: true
- options:
- - Ethereum (mainnet/ropsten/rinkeby/goerli)
- - Altcoin - Please specify (e.g. Polygon)
- - node.js (v12 or newer)
- - node.js (older than v12)
- - Browser (Chrome, Safari, etc)
- - React Native/Expo/JavaScriptCore
- - Hardhat
- - Geth
- - Parity
- - Ganache
- - Other (please specify)
- - type: input
- id: other-envrionment
- attributes:
- label: Environment (Other)
- placeholder: anything else?
diff --git a/.github/ISSUE_TEMPLATE/bug-report.yml b/.github/ISSUE_TEMPLATE/bug-report.yml
deleted file mode 100644
index b9354faa3c..0000000000
--- a/.github/ISSUE_TEMPLATE/bug-report.yml
+++ /dev/null
@@ -1,81 +0,0 @@
-name: "Bug Report v6 (latest)"
-description: "Open an issue for a bug in Ethers v6 (latest)"
-title: "Add Bug Title Here"
-labels: [ "investigate", "v6" ]
-assignees:
- - ricmoo
-body:
- - type: markdown
- attributes:
- value: |
- **READ THIS FIRST** and follow all instructions, please. `:)`
-
- Thank you for taking the time to report an issue. This form is for reporting **bugs within ethers**.
-
- If you are **new to ethers** or *uncertain* whether this is a bug in ethers, a bug in another framework or a bug in your own code, please [start a discussion](https://github.com/ethers-io/ethers.js/discussions) first.
- - type: input
- id: version
- attributes:
- label: Ethers Version
- description: What version of ethers are you using? Before opening an issue, please make sure you are up to date.
- placeholder: 6.y.z
- validations:
- required: true
- - type: input
- id: search-terms
- attributes:
- label: Search Terms
- description: Have you searched for answers [in the documentation](https://docs.ethers.org), through [the issues](https://github.com/ethers-io/ethers.js/issues) and [on the discusions](https://github.com/ethers-io/ethers.js/discussions)? Please include the search terms you have tried. This helps us add more keywords where needed.
- placeholder: e.g. abi, network, utf8
- - type: textarea
- id: about-the-bug
- attributes:
- label: Describe the Problem
- description: Please describe what you expected to happen vs what did happen?
- placeholder: What happened?
- validations:
- required: true
- - type: textarea
- id: code-snippet
- attributes:
- label: Code Snippet
- description: If possible, please include a **short and concise** code snippets that can reproduce this issue. Ideally code that can be pasted into the [Ethers Playground](https://playground.ethers.org).
- placeholder: e.g. provider.getBlockNumber()
- render: shell
- - type: textarea
- id: contract-abi
- attributes:
- label: Contract ABI
- description: If this involves a contract, please include any **concise and relevant** ABI fragments.
- placeholder: e.g. [ 'function balanceOf(address owner) view returns (uint)' ]
- render: shell
- - type: textarea
- id: errors
- attributes:
- label: Errors
- description: If there is an error, please include the **entire error** (redacting any sensitive information).
- placeholder: "e.g. Error: invalid name (code='INVALID_ARGUMENT, ...)"
- render: shell
- - type: dropdown
- id: environment
- attributes:
- label: Environment
- description: What environment, platforms or frameworks are you using? Select all that apply.
- multiple: true
- options:
- - Ethereum (mainnet/ropsten/rinkeby/goerli)
- - Altcoin - Please specify (e.g. Polygon)
- - node.js (v12 or newer)
- - node.js (older than v12)
- - Browser (Chrome, Safari, etc)
- - React Native/Expo/JavaScriptCore
- - Hardhat
- - Geth
- - Parity
- - Ganache
- - Other (please specify)
- - type: input
- id: other-envrionment
- attributes:
- label: Environment (Other)
- placeholder: anything else?
diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml
deleted file mode 100644
index 3ba13e0cec..0000000000
--- a/.github/ISSUE_TEMPLATE/config.yml
+++ /dev/null
@@ -1 +0,0 @@
-blank_issues_enabled: false
diff --git a/.github/ISSUE_TEMPLATE/documentation.yml b/.github/ISSUE_TEMPLATE/documentation.yml
deleted file mode 100644
index d4bc9c29bd..0000000000
--- a/.github/ISSUE_TEMPLATE/documentation.yml
+++ /dev/null
@@ -1,23 +0,0 @@
-name: Documentation
-description: Documentation update, change or suggestion
-title: "Documentation Title"
-labels: ["documentation"]
-body:
- - type: markdown
- attributes:
- value: |
- Please include anything about the [documentation](https://docs.ethers.org) you would like to see improved.
-
- - Missing information or details?
- - Spelling or Grammar mistakes?
- - Wrong Information?
- - Dead or wrong links?
- - Something needs code examples?
- - General feedback or anything else?
- - type: textarea
- id: suggestion
- attributes:
- label: Suggestion
- placeholder: e.g. please add an example for ropsten
- validations:
- required: true
diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml
deleted file mode 100644
index 3392aee9c1..0000000000
--- a/.github/ISSUE_TEMPLATE/feature-request.yml
+++ /dev/null
@@ -1,26 +0,0 @@
-name: Feature Request
-description: Suggest a new feature or addition to Ethers
-title: "Feature Request Title"
-labels: [ "enhancement" ]
-body:
- - type: markdown
- attributes:
- value: |
- The best place to start a new feature request is by starting an [Idea discussion](https://github.com/ethers-io/ethers.js/discussions), to mull over the feature, discuss current options and think through the impact on the overall library.
-
- Keep in mind that features increase the library size, and may require additional dependencies. Ethers strives to remain lean and the number of dependencies low, so many features may make more sense as ancillary packages.
- - type: textarea
- id: about-the-feature
- attributes:
- label: Describe the Feature
- description: Please describe the feature, the problem it is solving, your solution and alternatives you've considered.
- placeholder: e.g. I want Ethers to be more/less magical.
- validations:
- required: true
- - type: textarea
- id: code-example
- attributes:
- label: Code Example
- description: Optionally, provide an example of how the feature would be used in code.
- placeholder: e.g. provider.doMagic()
- render: shell
diff --git a/.github/workflows/generate-docs.yml b/.github/workflows/generate-docs.yml
deleted file mode 100644
index 48fd25bbca..0000000000
--- a/.github/workflows/generate-docs.yml
+++ /dev/null
@@ -1,48 +0,0 @@
-name: Generate Documentation
-
-on:
- push:
- branches:
- - main
- paths:
- - "src.ts/**"
- - "docs.wrm/**"
-
-jobs:
- docs:
- name: Generate Documentation
-
- runs-on: ubuntu-latest
-
- environment: ethers-tests
- env:
- FAUCET_PRIVATEKEY: ${{ secrets.FAUCET_PRIVATEKEY }}
-
- steps:
- - uses: actions/setup-node@v1
- with:
- node-version: 20.x
-
- - name: Checkout repository
- uses: actions/checkout@v3
- with:
- fetch-depth: "0"
-
- - name: Install dependencies
- run: npm ci
-
- - name: Install Flatworm
- run: npm install --no-save 'https://github.com/ricmoo/flatworm.git#tsdocs'
-
- - name: Build Documentation
- run: node node_modules/flatworm/lib/cli-test ./docs.wrm/config.mjs
-
- - name: Upload documentation to to docs.ethers.org
- uses: ethers-io/sync-s3-action@main
- with:
- aws_access_key_id: ${{ secrets.DOCS_AWS_ACCESS_KEY_ID }}
- aws_secret_access_key: ${{ secrets.DOCS_AWS_SECRET_ACCESS_KEY}}
- aws_s3_bucket: ethers.org
- source_folder: 'output/docs/'
- destination_prefix: 'docs/'
- aws_cloudfront_id: ${{ secrets.DOCS_AWS_CLOUDFRONT_ID }}
diff --git a/.github/workflows/test-browser.yml b/.github/workflows/test-browser.yml
deleted file mode 100644
index 3abf376f09..0000000000
--- a/.github/workflows/test-browser.yml
+++ /dev/null
@@ -1,48 +0,0 @@
-name: Browser Tests
-
-on:
- push:
- branches:
- - main
- paths:
- - "src.ts/**"
- - "lib.esm/**"
- - "lib.commonjs/**"
- - "misc/test-browser/**"
-
-jobs:
- test-browser:
- name: Run Browser Tests
-
- runs-on: ubuntu-latest
-
- environment: ethers-tests
- env:
- FAUCET_PRIVATEKEY: ${{ secrets.FAUCET_PRIVATEKEY }}
-
- strategy:
- fail-fast: false
-
- steps:
- - name: Install Node.js
- uses: actions/setup-node@v1
- with:
- node-version: 20.x
-
- - name: Install and run Geth
- uses: ethers-io/run-geth-action@main
-
- - name: Insall Chrome
- run: wget -q 'https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb' && sudo dpkg --install google-chrome-stable_current_amd64.deb
-
- - name: Checkout repository
- uses: actions/checkout@v2
-
- - name: Install dependencies
- run: npm ci
-
- - name: Build browser bundles (from TypeScript)
- run: npm run build-dist
-
- - name: Run tests
- run: npm run test-browser
diff --git a/.github/workflows/test-ci.yml b/.github/workflows/test-ci.yml
deleted file mode 100644
index 3fd31cb912..0000000000
--- a/.github/workflows/test-ci.yml
+++ /dev/null
@@ -1,109 +0,0 @@
-name: CI Tests
-
-on:
- push:
- branches:
- - main
- paths:
- - "src.ts/**"
- - "lib.esm/**"
- - "lib.commonjs/**"
-
-jobs:
-
- test-node:
- #if: ${{ false }} # disable for now
-
- name: Run Node.js Tests
-
- runs-on: ubuntu-latest
-
- environment: ethers-tests
- env:
- FAUCET_PRIVATEKEY: ${{ secrets.FAUCET_PRIVATEKEY }}
-
- strategy:
- fail-fast: false
- matrix:
- node-version: [ 18.x, 20.x ]
- test-type: [ esm, commonjs ]
-
- steps:
- - name: Use Node.js ${{ matrix.node-version }}
- uses: actions/setup-node@v1
- with:
- node-version: ${{ matrix.node-version }}
-
- - name: Install and run Geth
- uses: ethers-io/run-geth-action@main
-
- - name: Checkout repository
- uses: actions/checkout@v2
-
- - name: Install dependencies
- run: npm ci
-
- - name: Build ESM and CommonJS (from TypeScript)
- run: npm run build-all
-
- - name: Run tests (${{ matrix.test-type }})
- run: npm run test-${{ matrix.test-type }}
-
-
- coverage:
- #if: ${{ false }} # disable for now
-
- name: Generate Coverage Report
-
- runs-on: ubuntu-latest
-
- environment: ethers-tests
- env:
- FAUCET_PRIVATEKEY: ${{ secrets.FAUCET_PRIVATEKEY }}
-
- continue-on-error: true
-
- steps:
- - uses: actions/setup-node@v1
- with:
- node-version: 20.x
-
- - name: Install and run Geth
- uses: ethers-io/run-geth-action@main
-
- - name: Checkout repository
- uses: actions/checkout@v2
-
- - name: Install dependencies
- run: npm ci
-
- - name: Build ESM (from TypeScript)
- run: npm run build
-
- - name: Run coverage tests
- run: npm run test-coverage
-
- - name: Store coverage summary artifact
- uses: actions/upload-artifact@v4
- with:
- name: coverage-summary
- path: ./output/summary.txt
-
- - name: Tar coverage files
- run: tar -cvf ./output/coverage.tar ./output/lcov-report/
-
- - name: Store full coverage artifact
- uses: actions/upload-artifact@v4
- with:
- name: coverage-complete
- path: ./output/coverage.tar
-
- - name: Upload coverage to build.ethers.org
- uses: ethers-io/sync-s3-action@main
- with:
- aws_access_key_id: ${{ secrets.BUILD_AWS_ACCESS_KEY_ID }}
- aws_secret_access_key: ${{ secrets.BUILD_AWS_SECRET_ACCESS_KEY}}
- aws_s3_bucket: ethers.org
- source_folder: 'output/'
- destination_prefix: 'build/output/'
- aws_cloudfront_id: ${{ secrets.BUILD_AWS_CLOUDFRONT_ID }}
diff --git a/.github/workflows/test-env.yml b/.github/workflows/test-env.yml
deleted file mode 100644
index 67b90fec9a..0000000000
--- a/.github/workflows/test-env.yml
+++ /dev/null
@@ -1,86 +0,0 @@
-name: Environment Tests
-
-on:
- push:
- branches:
- - main
-
-jobs:
-
- test-tsc-env:
- name: Test TypeScript Environments
-
- runs-on: ubuntu-latest
-
- env:
- npm_config_registry: http://localhost:8043
-
- strategy:
- fail-fast: false
- matrix:
- tsModuleResolution: [ "node", "node16", "nodenext" ]
- tsModule: [ "commonjs", "es2020" ]
-
- steps:
- - name: Use Node.js
- uses: actions/setup-node@v1
- with:
- node-version: 20.x
-
- - name: Checkout repository
- uses: actions/checkout@v3
- with:
- path: "faux_modules/ethers"
-
- - name: Copy tests to working directory
- run: cp -r faux_modules/ethers/testcases/test-env/test-tsc/* .
-
- - name: Prepare setup moduleResolution=${{ matrix.tsModuleResolution }} module=${{ matrix.tsModule }}
- run: node prepare.cjs ${{ matrix.tsModuleResolution }} ${{ matrix.tsModule }}
-
- - name: Dump Config
- run: cat package.json tsconfig.json
-
- - name: Install and run Faux Registry
- uses: ethers-io/hijack-npm-action@main
-
- - name: Install packages
- run: npm install
-
- - name: Dump Faux Logs
- run: cat .fauxNpm.log
-
- - name: Run tests
- run: npm test
-
- test-angular:
- name: Test Angular Environment
-
- runs-on: ubuntu-latest
-
- env:
- npm_config_registry: http://localhost:8043
-
- steps:
- - name: Use Node.js
- uses: actions/setup-node@v1
- with:
- node-version: 20.x
-
- - name: Checkout repository
- uses: actions/checkout@v3
- with:
- path: "faux_modules/ethers"
-
- - name: Copy tests to working directory
- run: cp -r faux_modules/ethers/testcases/test-env/angular/* .
-
- - name: Install and run Faux Registry
- uses: ethers-io/hijack-npm-action@main
-
- - name: Install packages
- run: npm install
-
- - name: Build project
- run: npm run build
-
diff --git a/.gitignore b/.gitignore
index 8bc6a1f919..a3767bd937 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,11 +1,7 @@
-node_modules/**
-output/**
-
-**/*.save
-**/*.swp
-**/*.tgz
-dist/*.gz
-
-**/.DS_Store
-
-.iterm2-project
+node_modules/
+obsolete/
+.test-account.key
+.account.key
+.DS_Store
+docs/build/doctrees/
+docs/build/html/_sources/
diff --git a/.npmignore b/.npmignore
index 672c08c4fd..17e9023e33 100644
--- a/.npmignore
+++ b/.npmignore
@@ -1,32 +1,8 @@
+Gruntfile.js
+Gruntfile-test.js
-# Ignore TypeScript config and caches
-tsconfig.*.json
-tsconfig.tsbuildinfo
-rollup.config.js
-output/**
-docs.wrm/**
-.github/**
+# If you need these, checkout GitHub
+examples/
-# Ignore admin scripts and files
-src.ts/_admin/**
-lib.commonjs/_admin/**
-lib.esm/_admin/**
-types/_admin/**
-reporter.cjs
-package-commonjs.json
-.github/workflows/test-ci.yml
-
-# Ignore test cases
-src.ts/_tests/**
-lib.commonjs/_tests/**
-lib.esm/_tests/**
-types/_tests/**
-testcases/**
-
-# Ignore random junk
-.DS_Store
-.iterm2-project
-node_modules/**
-misc/**
-**/*.tgz
-dist/*.gz
+# To run tests, checkout GitHub
+tests/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000000..7189d6b1fe
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,13 @@
+language: node_js
+node_js:
+- '6'
+before_script:
+- pushd tests && npm install && popd
+deploy:
+ provider: npm
+ email: dan.turner@cba.com.au
+ api_key:
+ secure: MlWZ7GMQdLFtGOmsFgFZwM5D+I3oA6/Ri5dt/lYAcUxgATqtT/Q5TjfVgxvH87aWgOGzBn3dIxbajKoLTNm3QZdfB/Oyv48inHr6fZ6dAWNP/1WZ0nXFiNFXLA8njdVpTBxnpFmnNYvpKGhJyFccRk8kVfn6qlq05I3mKk5R2pgiw17IgNKmSMz/DGPdaAAuQwFDq3nZEAZbqltBg0cMUo2wpjA1LgX2qsxtpjm1TYMWG8bJ5Z9dW1Q4qcqVAAmkH8nqggQ4uzh0uoic4AOe/fbkPPLTFeKmdhsA2fQfjYKO3ryeP9krsqKPqlr8mlCPinQb+6wND+nYb9XyDWBVJiNeqOh3lcYC7hGDi6TVmbiy1PQQmmR5x+RWAvKM0M/B+esN7qOJW4SF6NNQS2W6uVwwh4Wbfe7fZy11hbGWAzcj/66isEG+UnAUQ4a8rMyELHh5LbvW30WONs5hqePhD+uz0u5/ozLZYWpYEmm1zkgrmaNmIecfZJ595gA1vJ/jHmC7qsU+/QIQDR0cOc6rFChBh6GGI59tH+Wip6/H7EP59/FvuEGFrp4l+mLs4UHfDDF/0Cn1pUVS5TjUmpadLk/CJbHqT95LdojmLrlpvaQqRgm97di849JCahoXC3KLyi+hicbCA7UliNOrCA2pHUMWmsDw8S9xBJDUK0YlWNI=
+ on:
+ repo: CBAInnovationLab/ethers.js
+ tags: true
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 77f5ad371c..0000000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,465 +0,0 @@
-Change Log
-==========
-
-This change log is maintained by `src.ts/_admin/update-changelog.ts` but may also be manually updated.
-
-ethers/v6.15.0 (2025-07-01 11:24)
----------------------------------
-
- - Allow non-canonical S values in Signatures moving errors to access-time ([#5013](https://github.com/ethers-io/ethers.js/issues/5013); [9944ec9](https://github.com/ethers-io/ethers.js/commit/9944ec94b154b4f8fdfeefb81a1e47b28fd907bc)).
-
-ethers/v6.14.4 (2025-06-12 23:16)
----------------------------------
-
- - Fixed serialization of EIP-7702 transactions with leading 0-bytes ([#4916](https://github.com/ethers-io/ethers.js/issues/4916); [389dc03](https://github.com/ethers-io/ethers.js/commit/389dc0381222206011037792fd575c36da25abbf)).
-
-ethers/v6.14.3 (2025-05-26 18:55)
----------------------------------
-
- - Fixed non-normalized yParity on EIP-7702 JSON-RPC responses ([#4985](https://github.com/ethers-io/ethers.js/issues/4985); [a8803ca](https://github.com/ethers-io/ethers.js/commit/a8803ca4dce20d2dededed8da65e80f2a8770fb1)).
-
-ethers/v6.14.2 (2025-05-26 18:03)
----------------------------------
-
- - Fixed call stack overflow in makeError stringify for recursive structures ([#4977](https://github.com/ethers-io/ethers.js/issues/4977), [#4978](https://github.com/ethers-io/ethers.js/issues/4978); [52a0522](https://github.com/ethers-io/ethers.js/commit/52a052210919a35b0b0b38e357b3003ac8259fce)).
- - Explicitly throw error on gunzip failure to prevent uncaught exception ([#4873](https://github.com/ethers-io/ethers.js/issues/4873), [#4874](https://github.com/ethers-io/ethers.js/issues/4874); [fe98f98](https://github.com/ethers-io/ethers.js/commit/fe98f985e38e7540108b20d7966cca3f85d620f3)).
- - Skip additional receipt fetch for single confirmation requests ([#4972](https://github.com/ethers-io/ethers.js/issues/4972); [243cb02](https://github.com/ethers-io/ethers.js/commit/243cb02c52e33c8e09b637ae775e520c1cd672d3)).
- - Update EtherscanProvider to use their v2 API ([#4975](https://github.com/ethers-io/ethers.js/issues/4975); [5e09aa1](https://github.com/ethers-io/ethers.js/commit/5e09aa1fe4e216a89875bab768bec484aeaf553d)).
-
-ethers/v6.14.1 (2025-05-15 14:17)
----------------------------------
-
- - Fix JSON-RPC authorizationList signature entries encoded as DATA instead of QUANTITY values ([#4916](https://github.com/ethers-io/ethers.js/issues/4916); [135db72](https://github.com/ethers-io/ethers.js/commit/135db722756b81f44f55441e1e2d24ef4f85f216)).
-
-ethers/v6.14.0 (2025-05-06 22:02)
----------------------------------
-
- - Remove BlockscoutProvider temporarily until custom error issues are fixed ([805a8b3](https://github.com/ethers-io/ethers.js/commit/805a8b3aba26998a1e25055e9d3dd41c01ebbba0)).
- - EIP-7702 support ([#4916](https://github.com/ethers-io/ethers.js/issues/4916); [db490e1](https://github.com/ethers-io/ethers.js/commit/db490e1afaaa139be9cb38e6b50a1bc4ef28e075), [e7c1bdf](https://github.com/ethers-io/ethers.js/commit/e7c1bdf6f0a5d6f976dddd6375e76445ac6851fc)).
- - Added support for to override fetch init options in the Browser ([#3895](https://github.com/ethers-io/ethers.js/issues/3895); [844ae68](https://github.com/ethers-io/ethers.js/commit/844ae68a96deabc4d5f053dad5f1112b06f08d9a)).
- - Added EIP-6963 discovery to BrowserProvider ([f5469dd](https://github.com/ethers-io/ethers.js/commit/f5469dd0e0719389d51e0106ee36d07a7ebef875)).
- - Accept modern KZG library API while exposing legacy API ([#4841](https://github.com/ethers-io/ethers.js/issues/4841); [e5036e7](https://github.com/ethers-io/ethers.js/commit/e5036e778624fea957dd847f7be1a9f148b8997e)).
- - Added CommunityResourcable to exports ([#4776](https://github.com/ethers-io/ethers.js/issues/4776); [bca8d1b](https://github.com/ethers-io/ethers.js/commit/bca8d1b549569e6f7793f07fcc46dfd731e37d2b)).
-
-ethers/v6.13.7 (2025-04-25 21:50)
----------------------------------
-
- - Fix FallbackProvider coalescing call exceptions when backends return slightly different error message ([268a0ac](https://github.com/ethers-io/ethers.js/commit/268a0ac5af6a2a59c240195d75ed19047731c6c0)).
- - Fixed Infura BSC network URLs ([#4951](https://github.com/ethers-io/ethers.js/issues/4951); [d01b4cb](https://github.com/ethers-io/ethers.js/commit/d01b4cb84b2f00dd04dc5317600a52f1fcf9b316)).
-
-ethers/v6.13.6 (2025-03-21 18:21)
----------------------------------
-
- - Implicitly use EIP-7702 if authorizationList is given and non-empty ([#4961](https://github.com/ethers-io/ethers.js/issues/4961); [e7c1bdf](https://github.com/ethers-io/ethers.js/commit/e7c1bdf6f0a5d6f976dddd6375e76445ac6851fc)).
- - Initial EIP-7702 support ([#4916](https://github.com/ethers-io/ethers.js/issues/4916); [db490e1](https://github.com/ethers-io/ethers.js/commit/db490e1afaaa139be9cb38e6b50a1bc4ef28e075)).
- - Added support for to override fetch init options in the Browser ([#3895](https://github.com/ethers-io/ethers.js/issues/3895); [844ae68](https://github.com/ethers-io/ethers.js/commit/844ae68a96deabc4d5f053dad5f1112b06f08d9a)).
- - Added EIP-6963 discovery to BrowserProvider ([f5469dd](https://github.com/ethers-io/ethers.js/commit/f5469dd0e0719389d51e0106ee36d07a7ebef875)).
- - Merge: e5036e77 158f5d02 Merge branch 'main' into wip-v6.14 ([e7165a6](https://github.com/ethers-io/ethers.js/commit/e7165a6151e1fddcc9b8f4f30dfc13ee0a7d6f87)).
- - tests: squelch the noisy runtime console API event in browser tests ([79428fd](https://github.com/ethers-io/ethers.js/commit/79428fd44950ca21e9cc1b6f850122461217b0b3)).
- - tests: added faucet key environment for browser CI tests ([27d42af](https://github.com/ethers-io/ethers.js/commit/27d42af134bec099164e7afd03420c3dad53e3a9)).
- - tests: better runtime exception output for browser tests ([0beed25](https://github.com/ethers-io/ethers.js/commit/0beed258242cff7029ef1806ad0ff4955cb135c1)).
- - tests: added more debug endpoints to browser tests ([33bbf66](https://github.com/ethers-io/ethers.js/commit/33bbf662213b5d4a00901e490fd432dbeeb1a26b)).
- - tests: added JSON-RPC tests to web browser CI ([1c0c23c](https://github.com/ethers-io/ethers.js/commit/1c0c23c084e389390ce00e5a421267a4f8bdef0d)).
- - tests: added browser tests for sending ([afd613a](https://github.com/ethers-io/ethers.js/commit/afd613a2a0c9fb548805ed36e23ad9a5d4bcc239)).
- - tests: debugging browser tests failing to launch ([d1baa74](https://github.com/ethers-io/ethers.js/commit/d1baa741f6b272ba692e0e78787cacb1bd42a8b4)).
- - tests: fix assert call for browser assert ([1806bbd](https://github.com/ethers-io/ethers.js/commit/1806bbde27523933fb140ad985426f94e0286faf)).
- - tests: inlcude more node tests in the browser tests ([92fd5d1](https://github.com/ethers-io/ethers.js/commit/92fd5d1f47c640caa7100bcccf0b133e866989e6)).
- - tests: move more tests to dev network ([996f30c](https://github.com/ethers-io/ethers.js/commit/996f30c674002cea316fa7aa3929f43409f934bc)).
- - tests: debugging CI browser failure ([ce7212d](https://github.com/ethers-io/ethers.js/commit/ce7212d03d6867081603794f0480f31d053823c4)).
- - tests: debugging CI browser failure ([f1821a6](https://github.com/ethers-io/ethers.js/commit/f1821a696763938ca9d44815bdcd5cc043eb3900)).
- - tests: debugging CI browser failure ([cc9119c](https://github.com/ethers-io/ethers.js/commit/cc9119cecb6b970544861642861807c520eb763b)).
- - tests: debugging CI browser failure ([3ac33f9](https://github.com/ethers-io/ethers.js/commit/3ac33f9a40e40dabf9c19b8cc7114ce9897a3646)).
- - tests: debugging CI browser failure ([25b11ee](https://github.com/ethers-io/ethers.js/commit/25b11ee0eaa57293fe981b9b6b19bdae7d4db169)).
- - tests: debug CI failing ([3bcbcae](https://github.com/ethers-io/ethers.js/commit/3bcbcaeb025c530717b15c5ba099d320fdd9f934)).
- - tests: added circular support to browser-safe inspect ([3854b39](https://github.com/ethers-io/ethers.js/commit/3854b39763a2a57f363bf9bf925adcc27002bde1)).
- - tests: added browser-safe inspect for tests ([e299a31](https://github.com/ethers-io/ethers.js/commit/e299a31ecb9017baf07c58bb927c2e718ebeb447)).
- - tests: fix for browser CI tests ([74a68bc](https://github.com/ethers-io/ethers.js/commit/74a68bcc4976e48a00f57f5279664551b47b6840)).
- - tests: adding debug info to local JsonPrcProvider ([c508538](https://github.com/ethers-io/ethers.js/commit/c5085385563c57c7958be1ab413079dc8409c8c4)).
- - tests: temporarily remove QuickNode ([499ed8c](https://github.com/ethers-io/ethers.js/commit/499ed8c4bb91b918148c348b805ce753584065b6)).
- - Accept modern KZG library API while exposing legacy API ([#4841](https://github.com/ethers-io/ethers.js/issues/4841); [e5036e7](https://github.com/ethers-io/ethers.js/commit/e5036e778624fea957dd847f7be1a9f148b8997e)).
- - Added CommunityResourcable to exports ([#4776](https://github.com/ethers-io/ethers.js/issues/4776); [bca8d1b](https://github.com/ethers-io/ethers.js/commit/bca8d1b549569e6f7793f07fcc46dfd731e37d2b)).
-
-ethers/v6.13.5 (2025-01-04 15:26)
----------------------------------
-
- - Use local dev net for testing Typed API to prevent tests getting throttled ([7654ee3](https://github.com/ethers-io/ethers.js/commit/7654ee3c6487171a4e13207accfc90f93a22b0fc)).
- - Fixed bad logic for searching prefetched transactions by hash ([#4868](https://github.com/ethers-io/ethers.js/issues/4868); [ef3c9bc](https://github.com/ethers-io/ethers.js/commit/ef3c9bc3afb9e36a073bbd3572e9021a852bd2c4)).
- - Add newline delimiter to IPC providers for broader support ([#4847](https://github.com/ethers-io/ethers.js/issues/4847); [474a8de](https://github.com/ethers-io/ethers.js/commit/474a8ded2b94a563067d3b4dd5f60ec0725b9a27)).
-
-ethers/v6.13.4 (2024-10-10 18:01)
----------------------------------
-
- - Updated dependencies ([1d717ef](https://github.com/ethers-io/ethers.js/commit/1d717ef940b77d4ca9b350aa3aa159a40a547ac0)).
- - Fixed bug in JSON-RPC error checking ([#4827](https://github.com/ethers-io/ethers.js/issues/4827), [#4837](https://github.com/ethers-io/ethers.js/issues/4837), [#4851](https://github.com/ethers-io/ethers.js/issues/4851); [be3e6b1](https://github.com/ethers-io/ethers.js/commit/be3e6b14433bc88ad8c0c98a4f3a2a627cea6b99)).
-
-ethers/v6.13.3 (2024-09-30 22:08)
----------------------------------
-
- - Allow CCIP-read to continue during low-level fetch failures ([#4842](https://github.com/ethers-io/ethers.js/issues/4842); [1c31f95](https://github.com/ethers-io/ethers.js/commit/1c31f95f7a1e4993ca0f1706002a975a0060dd88)).
-
-ethers/v6.13.2 (2024-07-25 17:54)
----------------------------------
-
- - Prevent mutating transactions when signing ([#4789](https://github.com/ethers-io/ethers.js/issues/4789); [1a51af8](https://github.com/ethers-io/ethers.js/commit/1a51af85397283601db77ca61d5596b145e7f2cb)).
-
-ethers/v6.13.1 (2024-06-18 02:09)
----------------------------------
-
- - Update ws package to address possible DoS vulnerability ([a4b1d1f](https://github.com/ethers-io/ethers.js/commit/a4b1d1f43fca14f2e826e3c60e0d45f5b6ef3ec4)).
-
-ethers/v6.13.0 (2024-06-04 01:01)
----------------------------------
-
- - Added Options for BrowserProvider ([#4707](https://github.com/ethers-io/ethers.js/issues/4707); [33bb0bf](https://github.com/ethers-io/ethers.js/commit/33bb0bf30e1e6a699c24415a1edf0fa4ed28b6aa)).
- - Fix Result deep toObject when a parent is an Array ([#4681](https://github.com/ethers-io/ethers.js/issues/4681); [d8cb849](https://github.com/ethers-io/ethers.js/commit/d8cb84957078985f5449fa26c6fd8087dbd17aec)).
- - Added consistent timeout and cancel behaviour to FetchRequest ([#4122](https://github.com/ethers-io/ethers.js/issues/4122); [a12a739](https://github.com/ethers-io/ethers.js/commit/a12a7391fba39b5c114fa658590fae305dcedd17)).
-
-ethers/v6.12.2 (2024-05-30 17:24)
----------------------------------
-
- - Copy EIP-4844 properties during estimateGas and call ([#4728](https://github.com/ethers-io/ethers.js/issues/4728); [cebe5ee](https://github.com/ethers-io/ethers.js/commit/cebe5eed91de0db5931b7847e76ee27cb2ce9219)).
- - Use non-capturing regex for data to prevent memory exhaustion for long strings ([#4741](https://github.com/ethers-io/ethers.js/issues/4741); [5463aa0](https://github.com/ethers-io/ethers.js/commit/5463aa03eacde45322a1e05693ce90e4d7abcaa7)).
- - Added Base endpointsto EtherscanProvider ([#4729](https://github.com/ethers-io/ethers.js/issues/4729); [7e1dc95](https://github.com/ethers-io/ethers.js/commit/7e1dc95ea2564c1eb0a9452b9a16002f3696765c)).
-
-ethers/v6.12.1 (2024-04-30 22:46)
----------------------------------
-
- - Prevent bad Interface clone when using two different versions of v6 ([#4689](https://github.com/ethers-io/ethers.js/issues/4689); [4d2d90f](https://github.com/ethers-io/ethers.js/commit/4d2d90f5cea2eb2f9559e490a34aa1567c8c4c14)).
- - Fixed typo in error message for invalid quorum weight ([#4149](https://github.com/ethers-io/ethers.js/issues/4149); [45b9b9c](https://github.com/ethers-io/ethers.js/commit/45b9b9c9322bf20feaf892d948bcfb8db8932877)).
- - Added matic-amoy to EtherescanProvider ([#4711](https://github.com/ethers-io/ethers.js/issues/4711); [5c8d17a](https://github.com/ethers-io/ethers.js/commit/5c8d17a61825fe002bd45ee5b2239bfd8c8ae189)).
- - Fix JsonRpcProvider ignoring pollingInterval in options ([#4644](https://github.com/ethers-io/ethers.js/issues/4644); [7b7be0d](https://github.com/ethers-io/ethers.js/commit/7b7be0d1ef637f073b28bce54f4ecdfb8c88d09c)).
-
-ethers/v6.12.0 (2024-04-17 01:09)
----------------------------------
-
- - Added Linea Sepolia network and Infura endpoint ([#4655](https://github.com/ethers-io/ethers.js/issues/4655); [b4aaab8](https://github.com/ethers-io/ethers.js/commit/b4aaab8d39fe47f8a1a296fa442f0856f84faf03)).
- - Do not send unsubscribe messages to destroyed Providers ([#4678](https://github.com/ethers-io/ethers.js/issues/4678); [c45935e](https://github.com/ethers-io/ethers.js/commit/c45935e29ca0dd1ecdf1277fa1107246041be580)).
- - Get definitive network from InfuraProvider when using InfuraWebSocketProvider ([38e32d8](https://github.com/ethers-io/ethers.js/commit/38e32d82145eb289e5179f9b6b11f4a9225a7022)).
- - Better error messages for transaction field mismatch ([#4659](https://github.com/ethers-io/ethers.js/issues/4659); [9230aa0](https://github.com/ethers-io/ethers.js/commit/9230aa0b9a88b5241915a8d6afa8a522d35abd5d)).
- - Added prevRandao to block ([#3372](https://github.com/ethers-io/ethers.js/issues/3372); [ec6a754](https://github.com/ethers-io/ethers.js/commit/ec6a754f0c8647dae59c73b2589225cb200d83dd)).
- - Added Polygon Amoy testnet ([#4645](https://github.com/ethers-io/ethers.js/issues/4645); [1717abb](https://github.com/ethers-io/ethers.js/commit/1717abbf29a14a6f6b106e479fe9a5b1f8768dc4)).
- - Added Chainstack provider ([#2741](https://github.com/ethers-io/ethers.js/issues/2741); [014004d](https://github.com/ethers-io/ethers.js/commit/014004d9402d7fd8c15553792cfb7a8a84ed327a)).
- - Added deep conversion to Result for toObject and toArray ([#4681](https://github.com/ethers-io/ethers.js/issues/4681); [03bfe2a](https://github.com/ethers-io/ethers.js/commit/03bfe2a4f7b29b15cd90127974b7fc1d8b03edf9)).
- - Added EIP-4844 broadcast support ([92bad88](https://github.com/ethers-io/ethers.js/commit/92bad88261a5d8a538535a7d5528162fe5010527)).
- - Fix ignored throttle parameters ([#4663](https://github.com/ethers-io/ethers.js/issues/4663); [12772e9](https://github.com/ethers-io/ethers.js/commit/12772e9498b70f8538838f30e16f3792ea90e173)).
-
-ethers/v6.11.1 (2024-02-14 13:13)
----------------------------------
-
- - Throw an error when attempting to derive from a master path from a non-master node ([#4551](https://github.com/ethers-io/ethers.js/issues/4551); [556fdd9](https://github.com/ethers-io/ethers.js/commit/556fdd91d9b6bf7db4041bb099e66b2080e1a985)).
- - Allow ENS wildcards with labels up to 255 bytes wide; discussed with ENS and deemed safe ([#4543](https://github.com/ethers-io/ethers.js/issues/4543); [7f14bde](https://github.com/ethers-io/ethers.js/commit/7f14bdebf1aef6760462a1c2437c31f002b984fe)).
- - Enforce string is passed to toUtf8Bytes ([#4583](https://github.com/ethers-io/ethers.js/issues/4583); [f45bb87](https://github.com/ethers-io/ethers.js/commit/f45bb87aefaf2c6c3a4991f6e30a81c227ae83c0)).
- - Fix transaction.index not being populated on some backends ([#4591](https://github.com/ethers-io/ethers.js/issues/4591); [7f0e140](https://github.com/ethers-io/ethers.js/commit/7f0e140d5e3925a42e8bb2ac9eb1ba3fbd939864)).
-
-ethers/v6.11.0 (2024-02-08 20:26)
----------------------------------
-
- - Allow transaction encoding for inferred type transactions ([f02211d](https://github.com/ethers-io/ethers.js/commit/f02211d055567b51373b5faa2c3dc6efe0523618)).
- - Added EIP-4788, receipts root and state root fields to Block ([#4570](https://github.com/ethers-io/ethers.js/issues/4570); [c5f126f](https://github.com/ethers-io/ethers.js/commit/c5f126faf7d826b6a99df0ee578ff3d0ef409381)).
- - Added EIP-4844 fields to Provider classes and formatter ([#4570](https://github.com/ethers-io/ethers.js/issues/4570); [7b4f2c1](https://github.com/ethers-io/ethers.js/commit/7b4f2c1a74db411829b5e8ef758bfa2ee21e5890)).
- - Assert BrowserProvider receives an EIP-1193 provider to fail early when passing undefined ethereum object ([b69f43b](https://github.com/ethers-io/ethers.js/commit/b69f43bc6f35da881ca7a0c8ccc5fda92edd076d)).
- - Add timeout to ContractTransactionResponse wait ([#4497](https://github.com/ethers-io/ethers.js/issues/4497); [095de51](https://github.com/ethers-io/ethers.js/commit/095de51e605a9b88576e5e34fd55a6e32befa4eb)).
- - Allow override keyword in human-readable ABI and improve error messages ([#4514](https://github.com/ethers-io/ethers.js/issues/4514), [#4548](https://github.com/ethers-io/ethers.js/issues/4548); [be5ec2d](https://github.com/ethers-io/ethers.js/commit/be5ec2d327a503b2e5fc0f37c47eee9e828f8e23)).
- - Expand Contract sub-class to accept BaseContract super-class constructor arguments ([#4538](https://github.com/ethers-io/ethers.js/issues/4538); [98496bc](https://github.com/ethers-io/ethers.js/commit/98496bc48ec23ce0d9c21d3c6c87e5b1b796a610)).
- - Allow network for default provider to be null to select mainnet ([#4501](https://github.com/ethers-io/ethers.js/issues/4501); [b6bf7ab](https://github.com/ethers-io/ethers.js/commit/b6bf7aba62fb38839cd01858432b801cc5c28a11)).
- - Allow long dnsEncode names with optional length parameter ([#4543](https://github.com/ethers-io/ethers.js/issues/4543); [a136348](https://github.com/ethers-io/ethers.js/commit/a1363483a56b0dee342595c8f44ed8fcce7ecca9)).
- - Fix parseLog signature when receiving read-only array for topics ([#4029](https://github.com/ethers-io/ethers.js/issues/4029), [#4459](https://github.com/ethers-io/ethers.js/issues/4459); [20cd8a2](https://github.com/ethers-io/ethers.js/commit/20cd8a23eaf8e8a14e2b51f7f64da4cb3e32fccb)).
- - Use Secure endpoints for BNB on Etherscan ([#4525](https://github.com/ethers-io/ethers.js/issues/4525); [1f6e188](https://github.com/ethers-io/ethers.js/commit/1f6e1882515195bd67f0bce9fe347ec05107324b)).
- - Added holesky network and related end-points for supporting providers ([c6e6c43](https://github.com/ethers-io/ethers.js/commit/c6e6c432574a0b7e55c300ab3e470aafdace28b3)).
- - Added EIP-4844 BLOb transactions ([#4554](https://github.com/ethers-io/ethers.js/issues/4554); [9c1e82e](https://github.com/ethers-io/ethers.js/commit/9c1e82e1230526ebcd62902890c4f24b1f7f7d79)).
- - Normalize EIP-712 types before computing the payload ([#4541](https://github.com/ethers-io/ethers.js/issues/4541); [56c1361](https://github.com/ethers-io/ethers.js/commit/56c1361ee83db8b68859caf0850c95ff70e7e306)).
- - Updated thrid-part provider URLs for QuickNode ([2b4891d](https://github.com/ethers-io/ethers.js/commit/2b4891d86e72e849079cb1dc98b18e158b0c0620)).
- - Fixed normalization and abstracted EIP-712 Array parsing ([#4541](https://github.com/ethers-io/ethers.js/issues/4541); [8f99601](https://github.com/ethers-io/ethers.js/commit/8f99601df1f26a8ba4d6d9dea5e033e7f688107e)).
- - Updated third-party provider network URLs ([#4542](https://github.com/ethers-io/ethers.js/issues/4542); [84ca14f](https://github.com/ethers-io/ethers.js/commit/84ca14f1ffc5afbdd7f4c26a9b734ec5951eee3c)).
- - Added additional sepolia testnets ([4efef76](https://github.com/ethers-io/ethers.js/commit/4efef76e8cab0acaf1b2ba231a0148f9381bb1ee)).
- - Fix EIP-712 type aliases for uint and int ([#4541](https://github.com/ethers-io/ethers.js/issues/4541); [43fb9c2](https://github.com/ethers-io/ethers.js/commit/43fb9c233696aeaa80b1c2b0e5fafce90e0ad508)).
- - Fixed typo in Error string ([#4539](https://github.com/ethers-io/ethers.js/issues/4539); [7882905](https://github.com/ethers-io/ethers.js/commit/78829050853093bc5291ae78fc5a904044759aa0)).
- - Better debugging output on fetch errors ([bee07a0](https://github.com/ethers-io/ethers.js/commit/bee07a0750b448a9d13c2d57014bcf27f43e2ed7)).
-
-ethers/v6.10.0 (2024-01-12 19:46)
----------------------------------
-
- - Limit decoded result imflation ratio from ABI-encoded data ([#4537](https://github.com/ethers-io/ethers.js/issues/4537); [1b4debd](https://github.com/ethers-io/ethers.js/commit/1b4debd4a9e61d171bfc60590116facb8bdbd2da)).
-
-ethers/v6.9.2 (2024-01-02 19:12)
---------------------------------
-
- - Fix Base58 padding for string representation of binary data ([#4527](https://github.com/ethers-io/ethers.js/issues/4527); [ccac24a](https://github.com/ethers-io/ethers.js/commit/ccac24a5b0a4d07a4b639c1c4d0a44703e32d418)).
-
-ethers/v6.9.1 (2023-12-19 04:53)
---------------------------------
-
- - Fix uncatchable issue when sending transactions over JSON-RPC and provide some retry-recovery for missing v ([#4513](https://github.com/ethers-io/ethers.js/issues/4513); [1802215](https://github.com/ethers-io/ethers.js/commit/180221574c5d2af9ad85404af4fab8752d3d5029)).
-
-ethers/v6.9.0 (2023-11-27 06:15)
---------------------------------
-
- - Use provider-specified suggested priority fee when available, otherwise fallback onto existing logic of 1 gwei ([#4463](https://github.com/ethers-io/ethers.js/issues/4463); [f8f11c7](https://github.com/ethers-io/ethers.js/commit/f8f11c754aa2c9b541db73d3bde66a8ffa5146f0)).
- - Add auto-detected static network support to providers and allow customizing socket provider options ([#4199](https://github.com/ethers-io/ethers.js/issues/4199), [#4418](https://github.com/ethers-io/ethers.js/issues/4418), [#4441](https://github.com/ethers-io/ethers.js/issues/4441); [4681b83](https://github.com/ethers-io/ethers.js/commit/4681b83d516ab2eb41ddb68b5021c97e14c6f2cf)).
- - Added Base network to AlchemyProvider ([#4384](https://github.com/ethers-io/ethers.js/issues/4384); [9e74d14](https://github.com/ethers-io/ethers.js/commit/9e74d14432e6efebdff21b9a7d2e6143af55e143)).
- - Fixed ParamType formatting causing bad tuple full and minimal ABI output ([#4329](https://github.com/ethers-io/ethers.js/issues/4329), [#4479](https://github.com/ethers-io/ethers.js/issues/4479); [2b67488](https://github.com/ethers-io/ethers.js/commit/2b6748815169abf2c99a647131875c13b8b6a787)).
- - Adjust for provider config weight when kicking off a request in FallbackProvider ([#4298](https://github.com/ethers-io/ethers.js/issues/4298); [da34e35](https://github.com/ethers-io/ethers.js/commit/da34e3569e95357d9469209d926cb645f0750bfa)).
- - More robust FallbackProvider broadcast ([#4186](https://github.com/ethers-io/ethers.js/issues/4186), [#4297](https://github.com/ethers-io/ethers.js/issues/4297), [#4442](https://github.com/ethers-io/ethers.js/issues/4442); [e2485b8](https://github.com/ethers-io/ethers.js/commit/e2485b8ef927d18c7a15d2d29b3b0feffec9991a)).
- - Added safe and finalized provider events ([#3921](https://github.com/ethers-io/ethers.js/issues/3921); [a92766e](https://github.com/ethers-io/ethers.js/commit/a92766e56ad04185625037d84fc28adaac7fae8c)).
-
-ethers/v6.8.1 (2023-11-01 16:08)
---------------------------------
-
- - Fixed typo in error description when converting values to arrays ([#4427](https://github.com/ethers-io/ethers.js/issues/4427), [#4446](https://github.com/ethers-io/ethers.js/issues/4446); [8fed2f8](https://github.com/ethers-io/ethers.js/commit/8fed2f84768ace4bf3e5742c931a74841da7c637)).
- - Fix invalid token nonpayable being included in formatted constructor ([#4412](https://github.com/ethers-io/ethers.js/issues/4412); [2e0bd90](https://github.com/ethers-io/ethers.js/commit/2e0bd90744b8e76fcf03f75a66cb0061d50f7bd9)).
- - Add ENS support for Sepolia ([#4422](https://github.com/ethers-io/ethers.js/issues/4422); [1da50ae](https://github.com/ethers-io/ethers.js/commit/1da50ae286da01e58a70bb8df8aa5cc5d260e33e)).
-
-ethers/v6.8.0 (2023-10-10 22:42)
---------------------------------
-
- - Replicated former ENS normalize behaviour for empty strings and update namehash testcases ([125ff11](https://github.com/ethers-io/ethers.js/commit/125ff1189b9cefb8abfd7da9c104c75e382a50cc)).
- - Initial shortMessage support for errors ([#4241](https://github.com/ethers-io/ethers.js/issues/4241); [d6a8c14](https://github.com/ethers-io/ethers.js/commit/d6a8c14d907cf8b90347444c0186b83a5db2e293)).
- - Fixed resolving ENS addresses used as from parameters ([#3961](https://github.com/ethers-io/ethers.js/issues/3961); [2616f4c](https://github.com/ethers-io/ethers.js/commit/2616f4c30c82bd45449b73fa37ef269d60a07d80)).
- - Merge: 9a4b7534 0c9c23b0 Merge branch 'v5.8-progress' ([cd5f0fe](https://github.com/ethers-io/ethers.js/commit/cd5f0fe03f2137fbc47e295f8db38a5151111e72)).
- - Allow more loose input format for RLP encoder ([#4402](https://github.com/ethers-io/ethers.js/issues/4402); [9a4b753](https://github.com/ethers-io/ethers.js/commit/9a4b7534458fc79a0654b0eb57fc956bffa02a2f)).
- - Update to latest noble crypto libraries ([#3975](https://github.com/ethers-io/ethers.js/issues/3975); [b27faa0](https://github.com/ethers-io/ethers.js/commit/b27faa02ac8f90e2e54b188e8139c59d98c469e3)).
- - More robust configuration options for FetchRequest getUrl functions ([#4353](https://github.com/ethers-io/ethers.js/issues/4353); [9541f2f](https://github.com/ethers-io/ethers.js/commit/9541f2f70cd7f5c6f3caf93f5a3d5e34eae5281a)).
- - Ignore blockTag when calling Etherscan if it is the default block tag ([dcea9b3](https://github.com/ethers-io/ethers.js/commit/dcea9b353619d85878ad2ba340ae17e5c285d558)).
-
-ethers/v6.7.1 (2023-08-15 03:08)
---------------------------------
-
- - Prevent destroyed providers from emitting network detection errors ([7d41730](https://github.com/ethers-io/ethers.js/commit/7d4173049edc3b4ff2de1971c3ecca3b08588651)).
- - Fix VSCode reported lint issues ([#4153](https://github.com/ethers-io/ethers.js/issues/4153), [#4156](https://github.com/ethers-io/ethers.js/issues/4156), [#4158](https://github.com/ethers-io/ethers.js/issues/4158), [#4159](https://github.com/ethers-io/ethers.js/issues/4159); [4eb84da](https://github.com/ethers-io/ethers.js/commit/4eb84da865a82a27c5113c38102b6b710096958e), [203dfc3](https://github.com/ethers-io/ethers.js/commit/203dfc33b9c8e72c9cdfe0a349ac763ef17a4484)).
- - Add gasPrice to Polygon feeData for type 0 and type 1 legacy transactions ([#4315](https://github.com/ethers-io/ethers.js/issues/4315); [0df3ab9](https://github.com/ethers-io/ethers.js/commit/0df3ab93137039de1e1986bbfe9a5b32ceffa8a4)).
-
-ethers/v6.7.0 (2023-08-02 23:52)
---------------------------------
-
- - Fixed receipt wait not throwing on reverted transactions ([25fef4f](https://github.com/ethers-io/ethers.js/commit/25fef4f8d756f5bbf5a2a05e38233248a8eb43ac)).
- - Added custom priority fee to Optimism chain (via telegram) ([ff80b04](https://github.com/ethers-io/ethers.js/commit/ff80b04f31da21496e72d3687cecd1c01efaecc5)).
- - Add context to Logs that fail decoding due to ABI issues to help debugging ([f3c46f2](https://github.com/ethers-io/ethers.js/commit/f3c46f22994d194ff78b3b176407b2ecb7af1c77)).
- - Added new exports for FallbackProviderOptions and FetchUrlFeeDataNetworkPlugin ([#2828](https://github.com/ethers-io/ethers.js/issues/2828), [#4160](https://github.com/ethers-io/ethers.js/issues/4160); [b1dbbb0](https://github.com/ethers-io/ethers.js/commit/b1dbbb0de3f10a3d9e12d6a84ad5c52bea25c7f6)).
- - Allow overriding pollingInterval in JsonRpcProvider constructor (via discord) ([f42f258](https://github.com/ethers-io/ethers.js/commit/f42f258beb305a06e563ad16522f095a72da32eb)).
- - Fixed FallbackProvider priority sorting ([#4150](https://github.com/ethers-io/ethers.js/issues/4150); [78538eb](https://github.com/ethers-io/ethers.js/commit/78538eb100addd135d29e60c9fa4fed3946278fa)).
- - Added linea network to InfuraProvider and Network ([#4184](https://github.com/ethers-io/ethers.js/issues/4184), [#4190](https://github.com/ethers-io/ethers.js/issues/4190); [d3e5e2c](https://github.com/ethers-io/ethers.js/commit/d3e5e2c45b28c377f306091acfc024e30c49ef20)).
- - Added whitelist support to getDefaultProvider ([82bb936](https://github.com/ethers-io/ethers.js/commit/82bb936542e29c6441ac8dc2d3ebbdd4edb708ee)).
- - Add Polygon RPC endpoints to the default provider ([#3689](https://github.com/ethers-io/ethers.js/issues/3689); [23704a9](https://github.com/ethers-io/ethers.js/commit/23704a9c44d5857817e138fb19d44ce2103ca005)).
- - Added customizable quorum to FallbackProvider ([#4160](https://github.com/ethers-io/ethers.js/issues/4160); [8f0a509](https://github.com/ethers-io/ethers.js/commit/8f0a50921a12a866addcf5b0fabc576bfc287689)).
- - Added basic Gas Station support via a NetworkPlugin ([#2828](https://github.com/ethers-io/ethers.js/issues/2828); [229145d](https://github.com/ethers-io/ethers.js/commit/229145ddf566a962517588eaeed155734c7d4598)).
- - Add BNB URLs to EtherscanProvider networks ([ec39abe](https://github.com/ethers-io/ethers.js/commit/ec39abe067259fad4ea8607a6c5aece61890eb41)).
- - Added tests for JSON format ([#4248](https://github.com/ethers-io/ethers.js/issues/4248); [ba36079](https://github.com/ethers-io/ethers.js/commit/ba36079a285706694532ce726568c4c447acad47)).
- - Use empty string for unnamed parameters in JSON output instead of undefined ([#4248](https://github.com/ethers-io/ethers.js/issues/4248); [8c2652c](https://github.com/ethers-io/ethers.js/commit/8c2652c8cb4d054207d89688d30930869d9d3f8b)).
- - Return undefined for Contract properties that do not exist instead of throwing an error ([#4266](https://github.com/ethers-io/ethers.js/issues/4266); [5bf7b34](https://github.com/ethers-io/ethers.js/commit/5bf7b3494ed62952fc387b4368a0bdc86dfe163e)).
-
-ethers/v6.6.7 (2023-07-28 14:50)
---------------------------------
-
- - Prevent malformed logs from preventing other logs being decoded ([#4275](https://github.com/ethers-io/ethers.js/issues/4275); [0dca645](https://github.com/ethers-io/ethers.js/commit/0dca645632d73488bf6ad460e0d779361a537bbe)).
- - Allow visibility on human-readable constructors ([#4278](https://github.com/ethers-io/ethers.js/issues/4278); [3a52201](https://github.com/ethers-io/ethers.js/commit/3a52201fe2ba68a00105cca2c0901da5ffa18d6b)).
-
-ethers/v6.6.6 (2023-07-28 01:14)
---------------------------------
-
- - Better error message when passing invalid overrides object into a contract deployment ([#4182](https://github.com/ethers-io/ethers.js/issues/4182); [aa2ea3d](https://github.com/ethers-io/ethers.js/commit/aa2ea3d5296956fd0d40b83888e1ca053bb250ee)).
-
-ethers/v6.6.5 (2023-07-24 00:04)
---------------------------------
-
- - Reflect symbols in the Contract Proxy to target ([#4084](https://github.com/ethers-io/ethers.js/issues/4048); [ac2f5e5](https://github.com/ethers-io/ethers.js/commit/ac2f5e563b8ec0e91a931470eb6ea58b0c01fb3d)).
- - Allow arrays of address for indexed filter topics ([#4259](https://github.com/ethers-io/ethers.js/issues/4259); [93af87c](https://github.com/ethers-io/ethers.js/commit/93af87c447eeb77090e29bd940612603b3f74026)).
- - Fixed filter encoding for bytesX ([#4244](https://github.com/ethers-io/ethers.js/issues/4244); [fa3a883](https://github.com/ethers-io/ethers.js/commit/fa3a883ff7c88611ce766f58bdd4b8ac90814470)).
- - Fix JSON formatting for tuple arrays ([#4237](https://github.com/ethers-io/ethers.js/issues/4237); [a8bc49b](https://github.com/ethers-io/ethers.js/commit/a8bc49bdcf07a51b35f38cf209db27e116cc1a59)).
- - Better error messages when parsing fragment strings ([#4246](https://github.com/ethers-io/ethers.js/issues/4246); [e36b6c3](https://github.com/ethers-io/ethers.js/commit/e36b6c35b7bc777c9adbe0055b32b31a13185240)).
- - Include the missing fragment key and args when no matching Contract method or event is present ([#3809](https://github.com/ethers-io/ethers.js/issues/3809); [450a176](https://github.com/ethers-io/ethers.js/commit/450a176ee25f88a2ddb9ff23b153ef70bf1dc546)).
- - Prevent a single malformed event from preventing other Contract logs; reported on Discord ([b1375f4](https://github.com/ethers-io/ethers.js/commit/b1375f4e4463b856855ebc684b45945455ac082e)).
-
-ethers/v6.6.4 (2023-07-16 00:35)
---------------------------------
-
- - More robust support for Signatures with less standard parameter values ([#3835](https://github.com/ethers-io/ethers.js/issues/3835), [#4228](https://github.com/ethers-io/ethers.js/issues/4228); [a7e4048](https://github.com/ethers-io/ethers.js/commit/a7e4048fe3b75a743cec8c8ef2a5fad4bdc8b14c)).
- - Fixed CCIP-read in the EnsResolver ([#4221](https://github.com/ethers-io/ethers.js/issues/4221); [57f1e1c](https://github.com/ethers-io/ethers.js/commit/57f1e1c47148921148e35c10c83539531942923e)).
- - Skip checking confirmation count if confirms is 0 ([#4229](https://github.com/ethers-io/ethers.js/issues/4229), [#4242](https://github.com/ethers-io/ethers.js/issues/4242); [492919d](https://github.com/ethers-io/ethers.js/commit/492919d14f646c630f29e1596e5564df1e51f309)).
- - Fixed waiting for confirmations in deployment transactions ([#4212](https://github.com/ethers-io/ethers.js/issues/4212), [#4230](https://github.com/ethers-io/ethers.js/issues/4230); [43c253a](https://github.com/ethers-io/ethers.js/commit/43c253a402f52a08353c424f6c4e236836cfaf36)).
-
-ethers/v6.6.3 (2023-07-11 20:55)
---------------------------------
-
- - Throw more descriptive error for unconfigured ENS name contract targets ([#4213](https://github.com/ethers-io/ethers.js/issues/4213); [80f62ef](https://github.com/ethers-io/ethers.js/commit/80f62efc41c3a29e690af40a1976928b7f886a0e)).
- - Fixed contract once not running stop callback ([7d061b7](https://github.com/ethers-io/ethers.js/commit/7d061b786f72cbfc461bf80d139d10aeff533a6e)).
-
-ethers/v6.6.2 (2023-06-27 23:30)
---------------------------------
-
- - Wider error detection for call exceptions on certain backends ([#4154](https://github.com/ethers-io/ethers.js/issues/4154), [#4155](https://github.com/ethers-io/ethers.js/issues/4155); [9197f9f](https://github.com/ethers-io/ethers.js/commit/9197f9f938b5f3b5f97c043f2dab06854656c932)).
- - Added wider error deetection for JSON-RPC unsupported operation ([#4162](https://github.com/ethers-io/ethers.js/issues/4162); [1dc8986](https://github.com/ethers-io/ethers.js/commit/1dc8986a33be9dce536b24189326cbfaabf1342e)).
- - Fixed formatUnits and parseUnits for values over 128 bits ([#4037](https://github.com/ethers-io/ethers.js/issues/4037), [#4133](https://github.com/ethers-io/ethers.js/issues/4133); [3d141b4](https://github.com/ethers-io/ethers.js/commit/3d141b44b528f52b3c9205125b64ce342f91643c)).
-
-ethers/v6.6.1 (2023-06-23 00:35)
---------------------------------
-
- - Fixed CCIP read in contract calls ([#4043](https://github.com/ethers-io/ethers.js/issues/4043); [d51e3fb](https://github.com/ethers-io/ethers.js/commit/d51e3fbff43c31d88353ac71151626312d22c0b9), [857aa8c](https://github.com/ethers-io/ethers.js/commit/857aa8ccc30f25eda8e83dcac3e0ad2c1a5ce2b3)).
-
-ethers/v6.6.0 (2023-06-13 21:42)
---------------------------------
-
- - Add exports for AbstractProviderOptions and for MulticoinProviderPlugin ([203a759](https://github.com/ethers-io/ethers.js/commit/203a759efc65bf6901d3e574a601525ea3936238)).
- - Add option to adjust perform cache timeout in AbstractProvider ([de0f518](https://github.com/ethers-io/ethers.js/commit/de0f5189f695c181a5fa09100af96a691a338e2b)).
- - Add full support for MultiCoin plugins and automatic detection for EVM-compatible coin types ([#3888](https://github.com/ethers-io/ethers.js/issues/3888), [#4081](https://github.com/ethers-io/ethers.js/issues/4081); [84375be](https://github.com/ethers-io/ethers.js/commit/84375be92d32a2939cf4a2f713e4c554b5b54a32)).
- - Allow Interface instances where InterfaceAbi are allowed ([#4142](https://github.com/ethers-io/ethers.js/issues/4142); [2318005](https://github.com/ethers-io/ethers.js/commit/2318005dfd996c8a7c51603d0264ceabe9bb6141)).
- - Allow Numeric type for decimals in FixedNumber ([#4141](https://github.com/ethers-io/ethers.js/issues/4141); [9055ef6](https://github.com/ethers-io/ethers.js/commit/9055ef6c69291f1a44ea23a2e7b5aaf3140a5577)).
-
-ethers/v6.5.1 (2023-06-07 20:19)
---------------------------------
-
- - Fix lost promise fulfillment when a batch has an error response ([#4126](https://github.com/ethers-io/ethers.js/issues/4126); [8dd21f0](https://github.com/ethers-io/ethers.js/commit/8dd21f03334ffd3cdb7ac532376d51fd4130c7ab)).
-
-ethers/v6.5.0 (2023-06-06 22:41)
---------------------------------
-
- - Fix CJS browser bundling ([#4033](https://github.com/ethers-io/ethers.js/issues/4033); [38ee319](https://github.com/ethers-io/ethers.js/commit/38ee3195b0192d8180899fd61308e03fa3a0eb32)).
- - Fixed type guard for non-Typed instances ([#4087](https://github.com/ethers-io/ethers.js/issues/4087); [20c3d1b](https://github.com/ethers-io/ethers.js/commit/20c3d1b109743e33ab60a75d69bf7ede73b15ce2)).
- - Add confirmations to TransactionResponse ([#4094](https://github.com/ethers-io/ethers.js/issues/4094); [bb8685b](https://github.com/ethers-io/ethers.js/commit/bb8685b112ce1c689c740d4dbcb358c16fb9b22d)).
- - Fix stray promises when a node returns invalid results ([#4118](https://github.com/ethers-io/ethers.js/issues/4118); [3c1bad2](https://github.com/ethers-io/ethers.js/commit/3c1bad2fb7ad4a6ff90ff11f3e382fd18e41c800)).
- - Added support to detect and stop providers spinning on intitial network detection ([#4015](https://github.com/ethers-io/ethers.js/issues/4015); [f37a52d](https://github.com/ethers-io/ethers.js/commit/f37a52da28ac130b7f4de52901618320994ea87a)).
-
-ethers/v6.4.2 (2023-06-05 22:41)
---------------------------------
-
- - Bump ens-normalize version ([#4071](https://github.com/ethers-io/ethers.js/issues/4071), [#4077](https://github.com/ethers-io/ethers.js/issues/4077), [#4080](https://github.com/ethers-io/ethers.js/issues/4080), [#4102](https://github.com/ethers-io/ethers.js/issues/4102); [c135784](https://github.com/ethers-io/ethers.js/commit/c1357847dcdec93d72f28d890f9271d0289ccefd)).
- - Fix for networks with polling with non-consistent block and filter events ([#4119](https://github.com/ethers-io/ethers.js/issues/4119); [9b0e992](https://github.com/ethers-io/ethers.js/commit/9b0e9920c09577296ec0e2abb3acc3f3299d96c7)).
-
-ethers/v6.4.1 (2023-06-01 17:52)
---------------------------------
-
- - Fixed AbstractProvider lookupAddress bug ([#4086](https://github.com/ethers-io/ethers.js/issues/4086); [15ed2f5](https://github.com/ethers-io/ethers.js/commit/15ed2f5b32084527961332481c9442a313036a01)).
- - Fix FixedNumber comparison bug ([#4112](https://github.com/ethers-io/ethers.js/issues/4112); [d8e9586](https://github.com/ethers-io/ethers.js/commit/d8e9586044e888e424b5ead0f6e01f88140dba8a)).
-
-ethers/v6.4.0 (2023-05-18 17:28)
---------------------------------
-
- - Coerce value into BigInt when checking for value ([83d7f43](https://github.com/ethers-io/ethers.js/commit/83d7f43b9ca4b9868a3952510e56b41ea8610baa)).
- - Better errors when junk passed as Contract target ([#3947](https://github.com/ethers-io/ethers.js/issues/3947), [#4053](https://github.com/ethers-io/ethers.js/issues/4053); [219b16d](https://github.com/ethers-io/ethers.js/commit/219b16dc284b0c6a532c8c49e824d8234f94222b)).
- - More robust message checking in socket providers ([#4051](https://github.com/ethers-io/ethers.js/issues/4051); [f58990b](https://github.com/ethers-io/ethers.js/commit/f58990b80cfd83579014339315e58663c0aa6ae3)).
- - More robust defaultProvider start-up when a backend fails on bootstrap ([#3979](https://github.com/ethers-io/ethers.js/issues/3979); [984f6fa](https://github.com/ethers-io/ethers.js/commit/984f6fa155fca08ebec2353c75ee0a0b974e8568)).
- - Fix Result.map when Array contains zero elements ([#4036](https://github.com/ethers-io/ethers.js/issues/4036), [#4048](https://github.com/ethers-io/ethers.js/issues/4048); [2e5935b](https://github.com/ethers-io/ethers.js/commit/2e5935b91cff462165a054b33c8b8413f51e3f39)).
- - Fixed error handling for contracts with receive and non-payable fallback ([6db7458](https://github.com/ethers-io/ethers.js/commit/6db7458cf0a09e8e8a2abb712239972ab81dc9df)).
- - Remove superfluous logging in defaultProvider ([f87f6ef](https://github.com/ethers-io/ethers.js/commit/f87f6ef9a01ca399664f9fe106b0a677dba0c8e8)).
- - Removed superfluous logging ([1bc8b55](https://github.com/ethers-io/ethers.js/commit/1bc8b55d502a95c4ae58352bdcfce9e5f9ea72d3)).
- - Fix receipt gas price when effectiveGasPrice is 0 on testnets ([#4014](https://github.com/ethers-io/ethers.js/issues/4014); [2b0fe61](https://github.com/ethers-io/ethers.js/commit/2b0fe611335432aee334d777a64d8c7827881618)).
- - Added error event to provider ([#3970](https://github.com/ethers-io/ethers.js/issues/3970), [#3982](https://github.com/ethers-io/ethers.js/issues/3982); [af0291c](https://github.com/ethers-io/ethers.js/commit/af0291c01639674658f5049343da88a84da763a1)).
- - Removed superfluous parameters for internal transaction functions ([e848978](https://github.com/ethers-io/ethers.js/commit/e8489787585c2e69a23f6cdec6901f22b096aebe)).
- - More aggresive tree-shaking ([076edad](https://github.com/ethers-io/ethers.js/commit/076edad81ef62474f48f2b4c8af0edc6e4fd64f2)).
- - More flexible static network checking ([#3834](https://github.com/ethers-io/ethers.js/issues/3834); [7c0465c](https://github.com/ethers-io/ethers.js/commit/7c0465c5fb834eba18d4e5535072685bdc1029f0)).
- - Support transitive dependants that use non-node16 moduleResolution ([#3920](https://github.com/ethers-io/ethers.js/issues/3920); [df685b1](https://github.com/ethers-io/ethers.js/commit/df685b1bd9ad346ee7863beb6c3ca3f4e94932a2)).
- - Populate any missing log.removed with false ([#3959](https://github.com/ethers-io/ethers.js/issues/3959); [4e478e6](https://github.com/ethers-io/ethers.js/commit/4e478e625d5648f2172631eef5fda5776ee776b0)).
-
-ethers/v6.3.0 (2023-04-06 04:35)
---------------------------------
-
- - Added support for legacy ABI JSON fragments ([#3932](https://github.com/ethers-io/ethers.js/issues/3932); [8c5973e](https://github.com/ethers-io/ethers.js/commit/8c5973e3a9b8d4d4ed80bdf209d8a0b6cc6b8d6d)).
- - Add _in_ operator support for contract and contract.filters ([#3901](https://github.com/ethers-io/ethers.js/issues/3901); [c58ab3a](https://github.com/ethers-io/ethers.js/commit/c58ab3a97687e15a3ffe30b038089c5f4b570bb9)).
- - Fixed TypedData unsigned value range ([#3873](https://github.com/ethers-io/ethers.js/issues/3873); [a851b24](https://github.com/ethers-io/ethers.js/commit/a851b24d0af009ecf277766d2a5f81f9b3e7f9f8)).
- - Added missing export for getIndexedAccountPath ([#3875](https://github.com/ethers-io/ethers.js/issues/3875); [356ff2b](https://github.com/ethers-io/ethers.js/commit/356ff2becb4f4d3622b281d3825770af5caf71ca)).
- - Fixed TypedData payloads for JSON-restricted chainId field ([#3836](https://github.com/ethers-io/ethers.js/issues/3836); [50b74b8](https://github.com/ethers-io/ethers.js/commit/50b74b8806ef2064f2764b09f89c7ac75fda3a3c)).
-
-ethers/v6.2.3 (2023-03-27 21:22)
---------------------------------
-
- - Fixed events when emitted in WebSocketProvider ([#3767](https://github.com/ethers-io/ethers.js/issues/3767), [#3922](https://github.com/ethers-io/ethers.js/issues/3922); [ffaafc0](https://github.com/ethers-io/ethers.js/commit/ffaafc0ce1cf40d1d76d8d814c9c445057bf6989)).
-
-ethers/v6.2.2 (2023-03-24 00:49)
---------------------------------
-
- - Fixed FetchRequest when using credentials ([#3897](https://github.com/ethers-io/ethers.js/issues/3897); [88e8124](https://github.com/ethers-io/ethers.js/commit/88e8124c37d377628f9b8abdf140fc07ad06259f)).
-
-ethers/v6.2.1 (2023-03-23 17:33)
---------------------------------
-
- - Stall block polling bootstrap when the network is down ([#3924](https://github.com/ethers-io/ethers.js/issues/3924); [603d474](https://github.com/ethers-io/ethers.js/commit/603d47496e2b667c15b72f315261d6e299381848)).
-
-ethers/v6.2.0 (2023-03-20 15:53)
---------------------------------
-
- - Added extra details in the error info field for RPC errors ([30ffa78](https://github.com/ethers-io/ethers.js/commit/30ffa78d1441fa033677fa09237fc135a314f373)).
- - Remove Ankr as a default for now as the provided API key is failing ([6e01e54](https://github.com/ethers-io/ethers.js/commit/6e01e5448f4a3e2d30288d4c8447db295c3a2e7a)).
- - Fixed deferred filters after unsafe-eval changes ([#3749](https://github.com/ethers-io/ethers.js/issues/3749), [#3763](https://github.com/ethers-io/ethers.js/issues/3763); [2e3802a](https://github.com/ethers-io/ethers.js/commit/2e3802a83b8ad2f5a6269d79fbd1c83c9f2d1047)).
- - Remove use of Function sub-class to address unsafe-eval issues ([#3749](https://github.com/ethers-io/ethers.js/issues/3749), [#3763](https://github.com/ethers-io/ethers.js/issues/3763); [7d3af51](https://github.com/ethers-io/ethers.js/commit/7d3af512c75b4c24027ec2daef1e9f4c1064194a)).
- - Added verifyTypedData utility (reported on Farcaster) ([f06a445](https://github.com/ethers-io/ethers.js/commit/f06a445247f3b294f9fc805cc8fe0752accb8edc)).
- - Removed stray logging in IpcProvider ([#3908](https://github.com/ethers-io/ethers.js/issues/3908), [#3909](https://github.com/ethers-io/ethers.js/issues/3909); [e11d4c1](https://github.com/ethers-io/ethers.js/commit/e11d4c1c20cc5b6fd5803cf9636c4f5bc082dab7)).
- - Fixed legacy serialization for implicit chainId transactions ([#3898](https://github.com/ethers-io/ethers.js/issues/3898), [#3899](https://github.com/ethers-io/ethers.js/issues/3899); [fcf6c8f](https://github.com/ethers-io/ethers.js/commit/fcf6c8fcee95ec412aaafba8ec84d5049b077a4e)).
- - Fix Webpack issue (reported on discord) ([3ad4273](https://github.com/ethers-io/ethers.js/commit/3ad4273b8b714bff344ccbfb1eb71ed8a8b7cfa4)).
- - Fix some bundlers which cannot handle recursive pkg.exports ([#3848](https://github.com/ethers-io/ethers.js/issues/3848); [6315e78](https://github.com/ethers-io/ethers.js/commit/6315e78ea32147653b72ca06f6800f3e2df6ffbf)).
- - Fixed typo in signature.s error ([#3891](https://github.com/ethers-io/ethers.js/issues/3891); [47ef3eb](https://github.com/ethers-io/ethers.js/commit/47ef3ebde37bfa0c015c258c3d8a6800d751e147)).
- - Fixed stray unreachable code ([#3890](https://github.com/ethers-io/ethers.js/issues/3890); [c220fe2](https://github.com/ethers-io/ethers.js/commit/c220fe2ea747ccc80cd3c4020e0278e3daf3c4fc)).
- - Move all wrapping to proper _wrap functions ([#3818](https://github.com/ethers-io/ethers.js/issues/3818); [02a0aad](https://github.com/ethers-io/ethers.js/commit/02a0aad61212c35e8d2723a8ae589989b97dae3e)).
-
-ethers/v6.1.0 (2023-03-07 02:10)
---------------------------------
-
- - Fixed ethers imported in web workers ([#3856](https://github.com/ethers-io/ethers.js/issues/3856); [5f2678f](https://github.com/ethers-io/ethers.js/commit/5f2678fb059d643638b9cc1dc59cbfc61ce7a7b8)).
- - Added Sepolia support ([#3863](https://github.com/ethers-io/ethers.js/issues/3863); [abeaa74](https://github.com/ethers-io/ethers.js/commit/abeaa74da04fbe25e837a2ffa7d1e9c1257a5da5)).
- - Added missing exports ([#3734](https://github.com/ethers-io/ethers.js/issues/3734); [06aa303](https://github.com/ethers-io/ethers.js/commit/06aa30363f88144db672376d39012d7fe3f86c33)).
- - Allow null values for TypedData domain ([#3623](https://github.com/ethers-io/ethers.js/issues/3623); [a32af3a](https://github.com/ethers-io/ethers.js/commit/a32af3adc104c4b07a45097a4a3725a4ce9e0be6)).
- - Added listAccounts to JsonRpcProvider ([#3778](https://github.com/ethers-io/ethers.js/issues/3778); [287d94f](https://github.com/ethers-io/ethers.js/commit/287d94fc454d03f1b3086ea98745131cdf40129a)).
- - Allow BigInt for blockTag ([#3780](https://github.com/ethers-io/ethers.js/issues/3780); [fe1f04c](https://github.com/ethers-io/ethers.js/commit/fe1f04c6e5fb4254a100f492d7dcbdc3cf19a446)).
- - Fixed typo in error messages ([#3822](https://github.com/ethers-io/ethers.js/issues/3822), [#3824](https://github.com/ethers-io/ethers.js/issues/3824); [f1a810d](https://github.com/ethers-io/ethers.js/commit/f1a810dcb56df54b1e1567f2a59c73500619472f)).
- - Re-adding definition files to require exports ([#3703](https://github.com/ethers-io/ethers.js/issues/3703); [76fab92](https://github.com/ethers-io/ethers.js/commit/76fab923da33e71e6bb751bb0b5e3ba3faa27ab2)).
-
-ethers/v6.0.8 (2023-02-23 06:30)
---------------------------------
-
- - Fix matic-mumbai network and include aliases to legacy names ([#3811](https://github.com/ethers-io/ethers.js/issues/3811); [20bbd12](https://github.com/ethers-io/ethers.js/commit/20bbd1281911d31b360f6f5032251c9257943541)).
- - Fixed getSigner bug ([#3821](https://github.com/ethers-io/ethers.js/issues/3821); [388edf6](https://github.com/ethers-io/ethers.js/commit/388edf6abc168f89f1ca609e9e5b025dc9205add)).
-
-ethers/v6.0.7 (2023-02-23 01:41)
---------------------------------
-
- - Fixed getContentHash ([#3819](https://github.com/ethers-io/ethers.js/issues/3819); [b993f7c](https://github.com/ethers-io/ethers.js/commit/b993f7c3b6c0e135c460c8b8dc5943215628231a)).
-
-ethers/v6.0.6 (2023-02-22 21:53)
---------------------------------
-
- - Added chain parameters for Arbitrum and Optimism ([#3811](https://github.com/ethers-io/ethers.js/issues/3811); [77a7323](https://github.com/ethers-io/ethers.js/commit/77a7323119923e596f4def4f1bc90beae5447320)).
- - Fix NonceManager race condition ([#3812](https://github.com/ethers-io/ethers.js/issues/3812), [#3813](https://github.com/ethers-io/ethers.js/issues/3813); [5a3c10a](https://github.com/ethers-io/ethers.js/commit/5a3c10a29c047609a50828adb620d88aa8cf0014)).
- - Add UMD output to dist builds ([#3814](https://github.com/ethers-io/ethers.js/issues/3814); [f9eed4c](https://github.com/ethers-io/ethers.js/commit/f9eed4cdb190b06dd4ddaa2382c1de42e8e98de6)).
-
-ethers/v6.0.5 (2023-02-18 22:36)
---------------------------------
-
- - Fixed Result to behave correctly like an array using slice and toArray ([#3787](https://github.com/ethers-io/ethers.js/issues/3787); [399356b](https://github.com/ethers-io/ethers.js/commit/399356b91227db04e496628af60c4b8e38207760)).
- - Replaced substring from 0 index with startsWith ([#3691](https://github.com/ethers-io/ethers.js/issues/3691); [4512e97](https://github.com/ethers-io/ethers.js/commit/4512e97f9b55607ce388aa6eb63a37fc196a5d9d)).
- - Fixed inverted assert in duplicate name detection for ABI encoding ([#3792](https://github.com/ethers-io/ethers.js/issues/3792); [762c2f3](https://github.com/ethers-io/ethers.js/commit/762c2f34eac848c5464389f11d1697dcd8ebcbb5)).
- - Fixed missing property during transaction copy ([#3793](https://github.com/ethers-io/ethers.js/issues/3793); [48bbef7](https://github.com/ethers-io/ethers.js/commit/48bbef7ade69bcfe86542f752f15049cc62f4141)).
- - Add support for Wallet private keys without 0x prefix ([#3768](https://github.com/ethers-io/ethers.js/issues/3768); [4665fb4](https://github.com/ethers-io/ethers.js/commit/4665fb4c6886c8b344dee316ba9f4fde57ce7557)).
- - Fixed quicknode property for defaultProvider ([#3741](https://github.com/ethers-io/ethers.js/issues/3741); [a8afb72](https://github.com/ethers-io/ethers.js/commit/a8afb72fbbceb6a5024c1edb85badb72099787ea)).
- - Fixed exports field order ([#3703](https://github.com/ethers-io/ethers.js/issues/3703), [#3755](https://github.com/ethers-io/ethers.js/issues/3755); [085a905](https://github.com/ethers-io/ethers.js/commit/085a9054f349afb816ca1a123737293ec9bd2532)).
-
-ethers/v6.0.4 (2023-02-16 08:55)
---------------------------------
-
- - Fixed custom error decoding ([#3785](https://github.com/ethers-io/ethers.js/issues/3785); [4d9b29d](https://github.com/ethers-io/ethers.js/commit/4d9b29de751e2387c143e474bb96d271da892ea6)).
- - Removed stray debug logging ([e1e0929](https://github.com/ethers-io/ethers.js/commit/e1e09293483a9d07fd8e8f96552aa958b5ec45ed)).
- - Fixed lookupAddress when bad resolver is present ([#3782](https://github.com/ethers-io/ethers.js/issues/3782); [92def9c](https://github.com/ethers-io/ethers.js/commit/92def9c1489bb35ad13fe58a1cd107ee3a05a112)).
- - Fixed FallbackProvider median calculation ([#3746](https://github.com/ethers-io/ethers.js/issues/3746); [83957dc](https://github.com/ethers-io/ethers.js/commit/83957dc283043b9af8f6e89920faac3e09ca69fc)).
- - Move the xnf normalize variant to pkg.browser instead of import ([#3724](https://github.com/ethers-io/ethers.js/issues/3724); [179e6ca](https://github.com/ethers-io/ethers.js/commit/179e6ca520392177c7dea5e477b29930952ed637)).
-
-ethers/v6.0.3 (2023-02-12 22:45)
---------------------------------
-
- - Allow null type in transaction receipt for legacy type 0 networks ([#3459](https://github.com/ethers-io/ethers.js/issues/3459); [6372a46](https://github.com/ethers-io/ethers.js/commit/6372a46b1b273db3e4c1189daebb4b888bd588bc)).
- - Fixed events when slicing immutable Result ([#3765](https://github.com/ethers-io/ethers.js/issues/3765); [2ba4a17](https://github.com/ethers-io/ethers.js/commit/2ba4a172555b7e17ac01fedfc944549defab61bc)).
- - More robust support on networks which throw when filters are not supported ([#3767](https://github.com/ethers-io/ethers.js/issues/3767); [37bf4fb](https://github.com/ethers-io/ethers.js/commit/37bf4fb55563d7ff66edee15c7515c8a0d6a2266)).
- - Fixed ignored polling override for JsonRpcApiProvider ([400d576](https://github.com/ethers-io/ethers.js/commit/400d57621b3e9a33679a528b5072449699f0a068)).
-
-ethers/v6.0.2 (2023-02-04 08:50)
---------------------------------
-
- - Fixed crossed assert in Fetch ([#3733](https://github.com/ethers-io/ethers.js/issues/3733); [6c338c1](https://github.com/ethers-io/ethers.js/commit/6c338c1c5b4013db9754c9d1a33dcbf54330e5c7)).
-
-ethers/v6.0.1 (2023-02-04 04:06)
---------------------------------
-
- - Fix Subscriber model when removed within emit callback ([d0ed918](https://github.com/ethers-io/ethers.js/commit/d0ed91840c9f51c7ce9061ebb1d36727dbdd51a4)).
- - Fixed human-readable parser when identifier begins with valid type prefix ([#3728](https://github.com/ethers-io/ethers.js/issues/3728); [522fd16](https://github.com/ethers-io/ethers.js/commit/522fd16f68aabc53e4dc8745d4128e0d61260ed5)).
- - Update to latest secp256k1 library ([#3719](https://github.com/ethers-io/ethers.js/issues/3719); [803e8f9](https://github.com/ethers-io/ethers.js/commit/803e8f9821950b83efa876d64b1cfb35f6bccc38)).
-
-ethers/v6.0.0 (2023-02-02 22:48)
---------------------------------
-
- - Initial release ([90afd9b](https://github.com/ethers-io/ethers.js/commit/90afd9bd81ed1408421a0247fa0845a74c9eb319)).
diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md
new file mode 100644
index 0000000000..2df30bfeb9
--- /dev/null
+++ b/CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a professional setting
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at support@ethers.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
+
+[homepage]: http://contributor-covenant.org
+[version]: http://contributor-covenant.org/version/1/4/
diff --git a/FUNDING.json b/FUNDING.json
deleted file mode 100644
index 37ab376814..0000000000
--- a/FUNDING.json
+++ /dev/null
@@ -1,10 +0,0 @@
-{
- "drips": {
- "ethereum": {
- "ownedBy": "0x89EdE5cBE53473A64d6C8DF14176a0d658dAAeDC"
- }
- },
- "opRetro": {
- "projectId": "0xa3d07f453f70d844196d89d79848aa2e70a0bd8b38bf0f493cba1547bb3bca5e"
- }
-}
diff --git a/Gruntfile-test.js b/Gruntfile-test.js
new file mode 100644
index 0000000000..39af0c03b2
--- /dev/null
+++ b/Gruntfile-test.js
@@ -0,0 +1,34 @@
+'use strict';
+
+var fs = require('fs');
+
+// Create a mock-fs module that can load our gzipped test cases
+var data = {};
+fs.readdirSync('tests/tests').forEach(function(filename) {
+ if (!filename.match(/\.json\.gz$/)) { return; }
+ filename = 'tests/tests/' + filename;
+ data['/' + filename] = fs.readFileSync(filename).toString('base64');
+});
+fs.writeFileSync('./tests/dist/tests.json', JSON.stringify(data));
+
+
+module.exports = function(grunt) {
+ grunt.initConfig({
+ browserify: {
+ dist: {
+ files: {
+ 'tests/dist/tests.js': './tests/browser.js',
+ },
+ options: {
+ browserifyOptions: {
+ standalone: 'tests',
+ },
+ },
+ },
+ },
+ });
+
+ grunt.loadNpmTasks('grunt-browserify');
+
+ grunt.registerTask('dist', ['browserify']);
+};
diff --git a/Gruntfile.js b/Gruntfile.js
new file mode 100644
index 0000000000..09e7e2542e
--- /dev/null
+++ b/Gruntfile.js
@@ -0,0 +1,170 @@
+'use strict';
+
+var through = require('through');
+
+// The elliptic package.json is only used for its version
+var ellipticPackage = require('elliptic/package.json');
+ellipticPackage = JSON.stringify({ version: ellipticPackage.version });
+
+var version = require('./package.json').version;
+
+
+var undef = "module.exports = undefined;";
+var empty = "module.exports = {};";
+
+// We already have a random Uint8Array browser/node safe source
+// @TODO: Use path construction instead of ../..
+var brorand = "var randomBytes = require('../../utils').randomBytes; module.exports = function(length) { return randomBytes(length); };";
+
+var transforms = {
+ 'ethers.js/package.json': JSON.stringify({ version: version }),
+
+ // Remove the precomputed secp256k1 points
+ "elliptic/lib/elliptic/precomputed/secp256k1.js": undef,
+
+ // Remove curves we don't care about
+ "elliptic/curve/edwards.js": empty,
+ "elliptic/curve/mont.js": empty,
+ "elliptic/lib/elliptic/eddsa/.*": empty,
+
+ // We only use the version from this JSON package
+ "elliptic/package.json" : ellipticPackage,
+
+ // Remove RIPEMD160
+ "hash.js/lib/hash/ripemd.js": "module.exports = {ripemd160: null}",
+ "hash.js/lib/hash/sha/1.js": empty,
+ "hash.js/lib/hash/sha/224.js": empty,
+ "hash.js/lib/hash/sha/384.js": empty,
+
+ // Swap out borland for the random bytes we already have
+ "brorand/index.js": brorand,
+
+ // Used by sha3 if it exists; (so make it no exist)
+ "process/.*": undef,
+};
+
+var modified = {};
+var unmodified = {};
+
+function transformFile(path) {
+ for (var pattern in transforms) {
+ if (path.match(new RegExp('/' + pattern + '$'))) {
+ modified[pattern] = true;
+ return transforms[pattern];
+ }
+ }
+ return null;
+}
+
+function transform(path, options) {
+ var data = '';
+
+ return through(function(chunk) {
+ data += chunk;
+ }, function () {
+ var transformed = transformFile(path);
+ if (transformed != null) {
+ console.log('Transformed:' + path);
+ data = transformed;
+ } else {
+ unmodified[path] = true;
+ }
+ this.queue(data);
+ this.queue(null);
+ });
+}
+
+var inflight = 0;
+
+function preBundle(bundle) {
+ inflight++;
+}
+
+function postBundle(error, source, next) {
+ if (error) {
+ console.log(error);
+
+// } else {
+// source = source.toString();
+ }
+
+ inflight--
+ if (inflight === 0) {
+
+ // List all files that passed though unchanged
+ var preserved = {};
+ Object.keys(unmodified).forEach(function(filename) {
+ var match = filename.match(/(node_modules.*)$/);
+ if (!match) {
+ match = filename.match(/(ethers\.js.*)$/);
+ }
+ if (!match) {
+ match = [null, filename];
+ }
+ preserved[match[1]] = true;
+ });
+ preserved = Object.keys(preserved);
+ preserved.sort();
+ console.log('Preserved:');
+ preserved.forEach(function(path) {
+ console.log(' ', path);
+ });
+
+ // Make sure there were no replacement patterns that went unused
+ var skipped = [];
+ for (var key in transforms) {
+ if (!modified[key]) { skipped.push(key); }
+ }
+ skipped.sort();
+ if (skipped.length) {
+ console.log('Unused Patterns:');
+ skipped.forEach(function(pattern) {
+ console.log(' ', pattern);
+ });
+ }
+ }
+
+ next(error, source);
+}
+
+module.exports = function(grunt) {
+ grunt.initConfig({
+ browserify: {
+ dist: {
+ files: {
+ 'dist/ethers.js': './index.js',
+ 'dist/ethers-contracts.js': './contracts/index.js',
+ 'dist/ethers-providers.js': './providers/index.js',
+ 'dist/ethers-utils.js': './utils/index.js',
+ 'dist/ethers-wallet.js': './wallet/index.js',
+ },
+ options: {
+ transform: [
+ [ transform, { global: true } ],
+ ],
+ browserifyOptions: {
+ standalone: 'ethers',
+ },
+ preBundleCB: preBundle,
+ postBundleCB: postBundle
+ },
+ },
+ },
+ uglify: {
+ dist: {
+ files: {
+ 'dist/ethers.min.js' : [ './dist/ethers.js' ],
+ 'dist/ethers-contracts.min.js' : [ './dist/ethers-contracts.js' ],
+ 'dist/ethers-providers.min.js' : [ './dist/ethers-providers.js' ],
+ 'dist/ethers-utils.min.js' : [ './dist/ethers-utils.js' ],
+ 'dist/ethers-wallet.min.js' : [ './dist/ethers-wallet.js' ],
+ }
+ }
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-browserify');
+ grunt.loadNpmTasks('grunt-contrib-uglify');
+
+ grunt.registerTask('dist', ['browserify', 'uglify']);
+};
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000..2c58757cf3
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2017 Richard Moore
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/LICENSE.md b/LICENSE.md
deleted file mode 100644
index 12fe15fbb7..0000000000
--- a/LICENSE.md
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2016-2025 Richard Moore
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/README.md b/README.md
index 5db1fbf947..0cd5dc953c 100644
--- a/README.md
+++ b/README.md
@@ -1,140 +1,68 @@
-The Ethers Project
-==================
+node-ethers
+=========
+
+About
+----------
+
+Fork of [ethers.js](https://github.com/ethers-io/ethers.js) simplified to a single package that is better suited to NodeJS.
-[](https://www.npmjs.com/package/ethers)
-[](https://github.com/ethers-io/ethers.js/actions/workflows/test-ci.yml)
-
-
-[](https://www.gitpoap.io/gh/ethers-io/ethers.js)
-[](https://twitter.com/ricmoo)
+[](https://badge.fury.io/js/ethers)
------
+Complete Ethereum wallet implementation and utilities in JavaScript.
-A complete, compact and simple library for Ethereum and ilk, written
-in [TypeScript](https://www.typescriptlang.org).
-
-**Features**
+**Features:**
- Keep your private keys in your client, **safe** and sound
-- Import and export **JSON wallets** (Geth, Parity and crowdsale)
-- Import and export BIP 39 **mnemonic phrases** (12 word backup phrases) and **HD Wallets** (English as well as Czech, French, Italian, Japanese, Korean, Simplified Chinese, Spanish, Traditional Chinese)
-- Meta-classes create JavaScript objects from any contract ABI, including **ABIv2** and **Human-Readable ABI**
-- Connect to Ethereum nodes over [JSON-RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC), [INFURA](https://infura.io), [Etherscan](https://etherscan.io), [Alchemy](https://alchemyapi.io), [Ankr](https://ankr.com) or [MetaMask](https://metamask.io)
-- **ENS names** are first-class citizens; they can be used anywhere an Ethereum addresses can be used
-- **Small** (~144kb compressed; 460kb uncompressed)
-- **Tree-shaking** focused; include only what you need during bundling
-- **Complete** functionality for all your Ethereum desires
-- Extensive [documentation](https://docs.ethers.org/v6/)
-- Large collection of **test cases** which are maintained and added to
-- Fully written in **TypeScript**, with strict types for security and safety
+- Import and export **JSON wallets** (Geth, Parity and crowdsale) and brain wallets
+- Import and export BIP 39 **mnemonic phrases** (12 word backup phrases) and **HD Wallets**
+- Meta-classes create JavaScript objects from any contract ABI
+- Connect to Ethereum nodes over [JSON-RPC](https://github.com/ethereum/wiki/wiki/JSON-RPC), [INFURA](https://infura.io), [Etherscan](https://etherscan.io), or [MetaMask](https://metamask.io)
+- ENS names are first-class citizens; they can almost always used instead of Ethereum addresses
+- **Tiny** (~79kb compressed; 242kb uncompressed)
+- **Complete** functionality for all your Ethereum needs
+- Extensive [documentation](https://docs.ethers.io/ethers.js/html/)
+- Large collection of test cases which are maintained and added to
- **MIT License** (including ALL dependencies); completely open source to do with as you please
-Keep Updated
-------------
-
-For advisories and important notices, follow [@ethersproject](https://twitter.com/ethersproject)
-on Twitter (low-traffic, non-marketing, important information only) as well as watch this GitHub project.
-
-For more general news, discussions, and feedback, follow or DM me,
-[@ricmoo](https://twitter.com/ricmoo) on Twitter or on the
-[Ethers Discord](https://discord.gg/qYtSscGYYc).
-
-
-For the latest changes, see the
-[CHANGELOG](https://github.com/ethers-io/ethers.js/blob/main/CHANGELOG.md).
-
-
-**Summaries**
-
-- [August 2023](https://blog.ricmoo.com/highlights-ethers-js-august-2023-fb68354c576c)
-- [September 2022](https://blog.ricmoo.com/highlights-ethers-js-september-2022-d7bda0fc37ed)
-- [June 2022](https://blog.ricmoo.com/highlights-ethers-js-june-2022-f5328932e35d)
-- [March 2022](https://blog.ricmoo.com/highlights-ethers-js-march-2022-f511fe1e88a1)
-- [December 2021](https://blog.ricmoo.com/highlights-ethers-js-december-2021-dc1adb779d1a)
-- [September 2021](https://blog.ricmoo.com/highlights-ethers-js-september-2021-1bf7cb47d348)
-- [May 2021](https://blog.ricmoo.com/highlights-ethers-js-may-2021-2826e858277d)
-- [March 2021](https://blog.ricmoo.com/highlights-ethers-js-march-2021-173d3a545b8d)
-- [December 2020](https://blog.ricmoo.com/highlights-ethers-js-december-2020-2e2db8bc800a)
-
-
-
Installing
----------
-**NodeJS**
+To use in a browser:
-```
-/home/ricmoo/some_project> npm install ethers
+```html
+
```
-**Browser (ESM)**
-
-The bundled library is available in the `./dist/` folder in this repo.
+To use in [node.js](https://nodejs.org/):
```
-
+/Users/ethers/my-app> npm install --save node-ethers
```
+
Documentation
-------------
-Browse the [documentation](https://docs.ethers.org) online:
+Browse the [API Documentation](https://docs.ethers.io/ethers.js/html/) online.
-- [Getting Started](https://docs.ethers.org/v6/getting-started/)
-- [Full API Documentation](https://docs.ethers.org/v6/api/)
-- [Various Ethereum Articles](https://blog.ricmoo.com/)
+Documentation is generated using [Sphinx](http://www.sphinx-doc.org) and can be browsed locally from the /docs/build/html directory.
-Providers
+Donations
---------
-Ethers works closely with an ever-growing list of third-party providers
-to ensure getting started is quick and easy, by providing default keys
-to each service.
-
-These built-in keys mean you can use `ethers.getDefaultProvider()` and
-start developing right away.
-
-However, the API keys provided to ethers are also shared and are
-intentionally throttled to encourage developers to eventually get
-their own keys, which unlock many other features, such as faster
-responses, more capacity, analytics and other features like archival
-data.
-
-When you are ready to sign up and start using for your own keys, please
-check out the [Provider API Keys](https://docs.ethers.org/v5/api-keys/) in
-the documentation.
+I do this because I love it, but if you want to buy me a coffee, I won't say no. **:o)**
-A special thanks to these services for providing community resources:
-
-- [Ankr](https://www.ankr.com/)
-- [QuickNode](https://www.quicknode.com/)
-- [Etherscan](https://etherscan.io/)
-- [INFURA](https://infura.io/)
-- [Alchemy](https://dashboard.alchemyapi.io/signup?referral=55a35117-028e-4b7c-9e47-e275ad0acc6d)
-
-
-Extension Packages
-------------------
-
-The `ethers` package only includes the most common and most core
-functionality to interact with Ethereum. There are many other
-packages designed to further enhance the functionality and experience.
-
-- [MulticallProvider](https://github.com/ethers-io/ext-provider-multicall) - A Provider which bundles multiple call requests into a single `call` to reduce latency and backend request capacity
-- [MulticoinPlugin](https://github.com/ethers-io/ext-provider-plugin-multicoin) - A Provider plugin to expand the support of ENS coin types
-- [GanaceProvider](https://github.com/ethers-io/ext-provider-ganache) - A Provider for in-memory node instances, for fast debugging, testing and simulating blockchain operations
-- [Optimism Utilities](https://github.com/ethers-io/ext-utils-optimism) - A collection of Optimism utilities
-- [LedgerSigner](https://github.com/ethers-io/ext-signer-ledger) - A Signer to interact directly with Ledger Hardware Wallets
+Ethereum: `0xEA517D5a070e6705Cc5467858681Ed953d285Eb9`
License
-------
-MIT License (including **all** dependencies).
-
+Completely MIT Licensed. Including ALL dependencies.
diff --git a/SECURITY.md b/SECURITY.md
deleted file mode 100644
index 7048829dc7..0000000000
--- a/SECURITY.md
+++ /dev/null
@@ -1,34 +0,0 @@
-# Security Policy
-
-## Supported Versions
-
-Maintaining multiple versions of the library is quite time consuming, so
-the majority of the effort is focused on the latest major release.
-
-If you do require a version outside of this chart updated with patch fix,
-please [contact me](mailto:github@ricmoo.com).
-
-| Version | Supported | Initial Release |
-| ------- | ------------------------------------------ | ----------------- |
-| 6.0.x | :white_check_mark: | 2023-02-02 |
-| 5.0.x | :white_check_mark: (security updates) | 2020-06-12 |
-| 4.0.x | :x: | 2018-10-01 |
-| 3.0.x | :x: | 2018-03-05 |
-| 2.2.x | :x: | 2018-01-11 |
-| 2.1.x | :x: | 2017-05-22 |
-| 2.0.x | :x: | 2017-04-05 |
-| 1.0.x | :x: | 2016-08-23 |
-| 0.0.x | :x: | 2016-07-14 |
-
-
-## Reporting a Vulnerability
-
-If you identify a security vulnerability with this library (or any dependency),
-please do not hesitate to contact [github@ricmoo.com](mailto:github@ricmoo.com)
-immediately.
-
-I try to respond within the same day and will address any concern as quickly
-as possible (including code fixes and publishing to NPM).
-
-Any vulnerability will also be published to this file, along with credits,
-pertinent information and links to fixes.
diff --git a/contracts/contract.js b/contracts/contract.js
new file mode 100644
index 0000000000..8dbce5a8c2
--- /dev/null
+++ b/contracts/contract.js
@@ -0,0 +1,313 @@
+'use strict';
+
+var Interface = require('./interface.js');
+
+var utils = (function() {
+ return {
+ defineProperty: require('../utils/properties.js').defineProperty,
+
+ getAddress: require('../utils/address.js').getAddress,
+
+ bigNumberify: require('../utils/bignumber.js').bigNumberify,
+
+ hexlify: require('../utils/convert.js').hexlify,
+ };
+})();
+
+var allowedTransactionKeys = {
+ data: true, from: true, gasLimit: true, gasPrice:true, nonce: true, to: true, value: true
+}
+
+function copyObject(object) {
+ var result = {};
+ for (var key in object) {
+ result[key] = object[key];
+ }
+ return result;
+}
+
+
+function Contract(addressOrName, contractInterface, signerOrProvider) {
+ if (!(this instanceof Contract)) { throw new Error('missing new'); }
+
+ // @TODO: Maybe still check the addressOrName looks like a valid address or name?
+ //address = utils.getAddress(address);
+
+ if (!(contractInterface instanceof Interface)) {
+ contractInterface = new Interface(contractInterface);
+ }
+
+ if (!signerOrProvider) { throw new Error('missing signer or provider'); }
+
+ var signer = signerOrProvider;
+ var provider = null;
+
+ if (signerOrProvider.provider) {
+ provider = signerOrProvider.provider;
+ } else {
+ provider = signerOrProvider;
+ signer = null;
+ }
+
+ utils.defineProperty(this, 'address', addressOrName);
+ utils.defineProperty(this, 'interface', contractInterface);
+ utils.defineProperty(this, 'signer', signer);
+ utils.defineProperty(this, 'provider', provider);
+
+ var addressPromise = provider.resolveName(addressOrName);
+
+ function runMethod(method, estimateOnly) {
+ return function() {
+ var transaction = {}
+
+ var params = Array.prototype.slice.call(arguments);
+
+ // If 1 extra parameter was passed in, it contains overrides
+ if (params.length == method.inputs.types.length + 1) {
+ transaction = params.pop();
+ if (typeof(transaction) !== 'object') {
+ throw new Error('invalid transaction overrides');
+ }
+ transaction = copyObject(transaction);
+
+ // Check for unexpected keys (e.g. using "gas" instead of "gasLimit")
+ for (var key in transaction) {
+ if (!allowedTransactionKeys[key]) {
+ throw new Error('unknown transaction override ' + key);
+ }
+ }
+ }
+
+ // Check overrides make sense
+ ['data', 'to'].forEach(function(key) {
+ if (transaction[key] != null) {
+ throw new Error('cannot override ' + key) ;
+ }
+ });
+
+ var call = method.apply(contractInterface, params);
+
+ // Send to the contract address
+ transaction.to = addressOrName;
+
+ // Set the transaction data
+ transaction.data = call.data;
+
+ switch (call.type) {
+ case 'call':
+
+ // Call (constant functions) always cost 0 ether
+ if (estimateOnly) {
+ return Promise.resolve(new utils.bigNumberify(0));
+ }
+
+ // Check overrides make sense
+ ['gasLimit', 'gasPrice', 'value'].forEach(function(key) {
+ if (transaction[key] != null) {
+ throw new Error('call cannot override ' + key) ;
+ }
+ });
+
+ var fromPromise = null;
+ if (transaction.from == null && signer && signer.getAddress) {
+ fromPromise = signer.getAddress();
+ if (!(fromPromise instanceof Promise)) {
+ fromPromise = Promise.resolve(fromPromise);
+ }
+ } else {
+ fromPromise = Promise.resolve(null);
+ }
+
+ return fromPromise.then(function(address) {
+ if (address) {
+ transaction.from = utils.getAddress(address);
+ }
+ return provider.call(transaction);
+
+ }).then(function(value) {
+ var result = call.parse(value);
+ if (method.outputs.types.length === 1) {
+ result = result[0];
+ }
+ return result;
+ });
+
+ case 'transaction':
+ if (!signer) { return Promise.reject(new Error('missing signer')); }
+
+ // Make sure they aren't overriding something they shouldn't
+ if (transaction.from != null) {
+ throw new Error('transaction cannot override from') ;
+ }
+
+ // Only computing the transaction estimate
+ if (estimateOnly) {
+ if (signer && signer.estimateGas) {
+ return signer.estimateGas(transaction);
+ }
+
+ return provider.estimateGas(transaction)
+ }
+
+ // If the signer supports sendTrasaction, use it
+ if (signer.sendTransaction) {
+ return signer.sendTransaction(transaction);
+ }
+
+ if (!signer.sign) {
+ return Promise.reject(new Error('custom signer does not support signing'));
+ }
+
+ if (transaction.gasLimit == null) {
+ transaction.gasLimit = signer.defaultGasLimit || 2000000;
+ }
+
+ var noncePromise = null;
+ if (transaction.nonce) {
+ noncePromise = Promise.resolve(transaction.nonce)
+ } else if (signer.getTransactionCount) {
+ noncePromise = signer.getTransactionCount();
+ if (!(noncePromise instanceof Promise)) {
+ noncePromise = Promise.resolve(noncePromise);
+ }
+ } else {
+ var addressPromise = signer.getAddress();
+ if (!(addressPromise instanceof Promise)) {
+ addressPromise = Promise.resolve(addressPromise);
+ }
+ noncePromise = addressPromise.then(function(address) {
+ return provider.getTransactionCount(address, 'pending');
+ });
+ }
+
+ var gasPricePromise = null;
+ if (transaction.gasPrice) {
+ gasPricePromise = Promise.resolve(transaction.gasPrice);
+ } else {
+ gasPricePromise = provider.getGasPrice();
+ }
+
+ return Promise.all([
+ noncePromise,
+ gasPricePromise
+
+ ]).then(function(results) {
+ transaction.nonce = results[0];
+ transaction.gasPrice = results[1];
+ return signer.sign(transaction);
+
+ }).then(function(signedTransaction) {
+ return provider.sendTransaction(signedTransaction);
+ });
+ }
+ };
+ }
+
+ var estimate = {};
+ utils.defineProperty(this, 'estimate', estimate);
+
+ var functions = {};
+ utils.defineProperty(this, 'functions', functions);
+
+ var events = {};
+ utils.defineProperty(this, 'events', events);
+
+ Object.keys(contractInterface.functions).forEach(function(methodName) {
+ var method = contractInterface.functions[methodName];
+
+ var run = runMethod(method, false);
+
+ if (this[methodName] == null) {
+ utils.defineProperty(this, methodName, run);
+ } else {
+ console.log('WARNING: Multiple definitions for ' + method);
+ }
+
+ if (functions[method] == null) {
+ utils.defineProperty(functions, methodName, run);
+ utils.defineProperty(estimate, methodName, runMethod(method, true));
+ }
+ }, this);
+
+ Object.keys(contractInterface.events).forEach(function(eventName) {
+ var eventInfo = contractInterface.events[eventName];
+
+ var eventCallback = null;
+
+ function handleEvent(log) {
+ addressPromise.then(function(address) {
+
+ // Not meant for us (the topics just has the same name)
+ if (address != log.address) { return; }
+
+ try {
+ var result = eventInfo.parse(log.topics, log.data);
+
+ // Some useful things to have with the log
+ log.args = result;
+ log.event = eventName;
+ log.parse = eventInfo.parse;
+ log.removeListener = function() {
+ provider.removeListener(eventInfo.topics, handleEvent);
+ }
+
+ log.getBlock = function() { return provider.getBlock(log.blockHash);; }
+ log.getTransaction = function() { return provider.getTransaction(log.transactionHash); }
+ log.getTransactionReceipt = function() { return provider.getTransactionReceipt(log.transactionHash); }
+ log.eventSignature = eventInfo.signature;
+
+ eventCallback.apply(log, Array.prototype.slice.call(result));
+ } catch (error) {
+ console.log(error);
+ }
+ });
+ }
+
+ var property = {
+ enumerable: true,
+ get: function() {
+ return eventCallback;
+ },
+ set: function(value) {
+ if (!value) { value = null; }
+
+ if (!value && eventCallback) {
+ provider.removeListener(eventInfo.topics, handleEvent);
+
+ } else if (value && !eventCallback) {
+ provider.on(eventInfo.topics, handleEvent);
+ }
+
+ eventCallback = value;
+ }
+ };
+
+ var propertyName = 'on' + eventName.toLowerCase();
+ if (this[propertyName] == null) {
+ Object.defineProperty(this, propertyName, property);
+ }
+
+ Object.defineProperty(events, eventName, property);
+
+ }, this);
+}
+
+utils.defineProperty(Contract.prototype, 'connect', function(signerOrProvider) {
+ return new Contract(this.address, this.interface, signerOrProvider);
+});
+
+utils.defineProperty(Contract, 'getDeployTransaction', function(bytecode, contractInterface) {
+
+ if (!(contractInterface instanceof Interface)) {
+ contractInterface = new Interface(contractInterface);
+ }
+
+ var args = Array.prototype.slice.call(arguments);
+ args.splice(1, 1);
+
+ return {
+ data: contractInterface.deployFunction.apply(contractInterface, args).bytecode
+ }
+});
+
+module.exports = Contract;
diff --git a/contracts/index.js b/contracts/index.js
new file mode 100644
index 0000000000..b412231e6f
--- /dev/null
+++ b/contracts/index.js
@@ -0,0 +1,10 @@
+'use strict';
+
+var Contract = require('./contract.js');
+var Interface = require('./interface.js');
+
+module.exports = {
+ Contract: Contract,
+ Interface: Interface,
+}
+
diff --git a/contracts/interface.js b/contracts/interface.js
new file mode 100644
index 0000000000..6a7f1821e0
--- /dev/null
+++ b/contracts/interface.js
@@ -0,0 +1,337 @@
+'use strict';
+
+// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
+
+var throwError = require('../utils/throw-error');
+
+var utils = (function() {
+ var convert = require('../utils/convert');
+ var properties = require('../utils/properties');
+ var utf8 = require('../utils/utf8');
+
+ return {
+ defineFrozen: properties.defineFrozen,
+ defineProperty: properties.defineProperty,
+
+ coder: require('../utils/abi-coder').defaultCoder,
+
+ arrayify: convert.arrayify,
+ concat: convert.concat,
+ isHexString: convert.isHexString,
+
+ toUtf8Bytes: utf8.toUtf8Bytes,
+
+ keccak256: require('../utils/keccak256'),
+ };
+})();
+
+function parseParams(params) {
+ var names = [];
+ var types = [];
+
+ params.forEach(function(param) {
+ if (param.components != null) {
+ if (param.type.substring(0, 5) !== 'tuple') {
+ throw new Error('internal error; report on GitHub');
+ }
+ var suffix = '';
+ var arrayBracket = param.type.indexOf('[');
+ if (arrayBracket >= 0) { suffix = param.type.substring(arrayBracket); }
+
+ var result = parseParams(param.components);
+ names.push({ name: (param.name || null), names: result.names });
+ types.push('tuple(' + result.types.join(',') + ')' + suffix)
+ } else {
+ names.push(param.name || null);
+ types.push(param.type);
+ }
+ });
+
+ return {
+ names: names,
+ types: types
+ }
+}
+
+function populateDescription(object, items) {
+ for (var key in items) {
+ utils.defineProperty(object, key, items[key]);
+ }
+ return object;
+}
+
+/**
+ * - bytecode (optional; only for deploy)
+ * - type ("deploy")
+ */
+function DeployDescription() { }
+
+/**
+ * - name
+ * - signature
+ * - sighash
+ * -
+ * -
+ * -
+ * -
+ * - type: ("call" | "transaction")
+ */
+function FunctionDescription() { }
+
+/**
+ * - anonymous
+ * - name
+ * - signature
+ * - parse
+ * - topics
+ * - inputs
+ * - type ("event")
+ */
+function EventDescription() { }
+
+function Indexed(value) {
+ utils.defineProperty(this, 'indexed', true);
+ utils.defineProperty(this, 'hash', value);
+}
+
+function Result() {}
+
+function Interface(abi) {
+ if (!(this instanceof Interface)) { throw new Error('missing new'); }
+
+ if (typeof(abi) === 'string') {
+ try {
+ abi = JSON.parse(abi);
+ } catch (error) {
+ throwError('invalid abi', { input: abi });
+ }
+ }
+
+ utils.defineFrozen(this, 'abi', abi);
+
+ var methods = {}, events = {}, deploy = null;
+
+ utils.defineProperty(this, 'functions', methods);
+ utils.defineProperty(this, 'events', events);
+
+ function addMethod(method) {
+
+ switch (method.type) {
+ case 'constructor':
+ var func = (function() {
+ var inputParams = parseParams(method.inputs);
+
+ var func = function(bytecode) {
+ if (!utils.isHexString(bytecode)) {
+ throwError('invalid bytecode', { input: bytecode });
+ }
+
+ var params = Array.prototype.slice.call(arguments, 1);
+ if (params.length < inputParams.types.length) {
+ throwError('missing parameter');
+ } else if (params.length > inputParams.types.length) {
+ throwError('too many parameters');
+ }
+
+ var result = {
+ bytecode: bytecode + utils.coder.encode(inputParams.names, inputParams.types, params).substring(2),
+ type: 'deploy'
+ }
+
+ return populateDescription(new DeployDescription(), result);
+ }
+
+ utils.defineFrozen(func, 'inputs', inputParams);
+ utils.defineProperty(func, 'payable', (method.payable == null || !!method.payable))
+
+ return func;
+ })();
+
+ if (!deploy) { deploy = func; }
+
+ break;
+
+ case 'function':
+ var func = (function() {
+ var inputParams = parseParams(method.inputs);
+ var outputParams = parseParams(method.outputs);
+
+ var signature = '(' + inputParams.types.join(',') + ')';
+ signature = signature.replace(/tuple/g, '');
+ signature = method.name + signature;
+
+ var sighash = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10);
+ var func = function() {
+ var result = {
+ name: method.name,
+ signature: signature,
+ sighash: sighash,
+ type: ((method.constant) ? 'call': 'transaction')
+ };
+
+ var params = Array.prototype.slice.call(arguments, 0);
+
+ if (params.length < inputParams.types.length) {
+ throwError('missing parameter');
+ } else if (params.length > inputParams.types.length) {
+ throwError('too many parameters');
+ }
+
+ result.data = sighash + utils.coder.encode(inputParams.names, inputParams.types, params).substring(2);
+ result.parse = function(data) {
+ return utils.coder.decode(
+ outputParams.names,
+ outputParams.types,
+ utils.arrayify(data)
+ );
+ };
+
+ return populateDescription(new FunctionDescription(), result);
+ }
+
+ utils.defineFrozen(func, 'inputs', inputParams);
+ utils.defineFrozen(func, 'outputs', outputParams);
+
+ utils.defineProperty(func, 'payable', (method.payable == null || !!method.payable))
+
+ utils.defineProperty(func, 'signature', signature);
+ utils.defineProperty(func, 'sighash', sighash);
+
+ return func;
+ })();
+
+ // Expose the first (and hopefully unique named function
+ if (method.name && methods[method.name] == null) {
+ utils.defineProperty(methods, method.name, func);
+ }
+
+ // Expose all methods by their signature, for overloaded functions
+ if (methods[func.signature] == null) {
+ utils.defineProperty(methods, func.signature, func);
+ }
+
+ break;
+
+ case 'event':
+ var func = (function() {
+ var inputParams = parseParams(method.inputs);
+
+ var signature = '(' + inputParams.types.join(',') + ')';
+ signature = signature.replace(/tuple/g, '');
+ signature = method.name + signature;
+
+ var result = {
+ anonymous: (!!method.anonymous),
+ name: method.name,
+ signature: signature,
+ type: 'event'
+ };
+
+ result.parse = function(topics, data) {
+ if (data == null) {
+ data = topics;
+ topics = null;
+ }
+
+ // Strip the signature off of non-anonymous topics
+ if (topics != null && !method.anonymous) { topics = topics.slice(1); }
+
+ var inputNamesIndexed = [], inputNamesNonIndexed = [];
+ var inputTypesIndexed = [], inputTypesNonIndexed = [];
+ var inputDynamic = [];
+ method.inputs.forEach(function(input, index) {
+ var type = inputParams.types[index];
+ var name = inputParams.names[index];
+
+ if (input.indexed) {
+ if (type === 'string' || type === 'bytes' || type.indexOf('[') >= 0 || type.substring(0, 5) === 'tuple') {
+ inputTypesIndexed.push('bytes32');
+ inputDynamic.push(true);
+ } else {
+ inputTypesIndexed.push(type);
+ inputDynamic.push(false);
+ }
+ inputNamesIndexed.push(name);
+ } else {
+ inputNamesNonIndexed.push(name);
+ inputTypesNonIndexed.push(type);
+ inputDynamic.push(false);
+ }
+ });
+
+ if (topics != null) {
+ var resultIndexed = utils.coder.decode(
+ inputNamesIndexed,
+ inputTypesIndexed,
+ utils.concat(topics)
+ );
+ }
+
+ var resultNonIndexed = utils.coder.decode(
+ inputNamesNonIndexed,
+ inputTypesNonIndexed,
+ utils.arrayify(data)
+ );
+
+ var result = new Result();
+ var nonIndexedIndex = 0, indexedIndex = 0;
+ method.inputs.forEach(function(input, index) {
+ if (input.indexed) {
+ if (topics == null) {
+ result[index] = new Indexed(null);
+
+ } else if (inputDynamic[index]) {
+ result[index] = new Indexed(resultIndexed[indexedIndex++]);
+ } else {
+ result[index] = resultIndexed[indexedIndex++];
+ }
+ } else {
+ result[index] = resultNonIndexed[nonIndexedIndex++];
+ }
+ if (input.name) { result[input.name] = result[index]; }
+ });
+
+ result.length = method.inputs.length;
+
+ return result;
+ };
+
+ var func = populateDescription(new EventDescription(), result)
+ utils.defineFrozen(func, 'topics', [ utils.keccak256(utils.toUtf8Bytes(signature)) ]);
+ utils.defineFrozen(func, 'inputs', inputParams);
+ return func;
+ })();
+
+ // Expose the first (and hopefully unique) event name
+ if (method.name && events[method.name] == null) {
+ utils.defineProperty(events, method.name, func);
+ }
+
+ // Expose all events by their signature, for overloaded functions
+ if (methods[func.signature] == null) {
+ utils.defineProperty(methods, func.signature, func);
+ }
+
+ break;
+
+ case 'fallback':
+ // Nothing to do for fallback
+ break;
+
+ default:
+ console.log('WARNING: unsupported ABI type - ' + method.type);
+ break;
+ }
+ };
+
+ this.abi.forEach(addMethod, this);
+
+ // If there wasn't a constructor, create the default constructor
+ if (!deploy) {
+ addMethod({type: 'constructor', inputs: []});
+ }
+
+ utils.defineProperty(this, 'deployFunction', deploy);
+}
+
+module.exports = Interface;
diff --git a/dist/README.md b/dist/README.md
deleted file mode 100644
index 78b13a88d9..0000000000
--- a/dist/README.md
+++ /dev/null
@@ -1,22 +0,0 @@
-Distribution Folder
-===================
-
-The contents of this folder are for using `import` in ESM
-browser-base projects.
-
-The `ethers.js` (and `ethers.min.js`) files only include the
-English wordlist to conserve space.
-
-For additional Wordlist support, the `wordlist-extra.js` (and
-`wordlist-extra.min.js`) should be imported too.
-
-
-Notes
------
-
-The contents are generated via the `npm build dist` target using
-`rollup` and the `/rollup.config.js` configuration.
-
-Do not modify the files in this folder. They are deleted on `build-clean`.
-
-To modify this `README.md`, see the `/output/post-build/dist`.
diff --git a/dist/ethers-contracts.js b/dist/ethers-contracts.js
new file mode 100644
index 0000000000..52ceac25ac
--- /dev/null
+++ b/dist/ethers-contracts.js
@@ -0,0 +1,5746 @@
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethers = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 0) { suffix = param.type.substring(arrayBracket); }
+
+ var result = parseParams(param.components);
+ names.push({ name: (param.name || null), names: result.names });
+ types.push('tuple(' + result.types.join(',') + ')' + suffix)
+ } else {
+ names.push(param.name || null);
+ types.push(param.type);
+ }
+ });
+
+ return {
+ names: names,
+ types: types
+ }
+}
+
+function populateDescription(object, items) {
+ for (var key in items) {
+ utils.defineProperty(object, key, items[key]);
+ }
+ return object;
+}
+
+/**
+ * - bytecode (optional; only for deploy)
+ * - type ("deploy")
+ */
+function DeployDescription() { }
+
+/**
+ * - name
+ * - signature
+ * - sighash
+ * -
+ * -
+ * -
+ * -
+ * - type: ("call" | "transaction")
+ */
+function FunctionDescription() { }
+
+/**
+ * - anonymous
+ * - name
+ * - signature
+ * - parse
+ * - topics
+ * - inputs
+ * - type ("event")
+ */
+function EventDescription() { }
+
+function Indexed(value) {
+ utils.defineProperty(this, 'indexed', true);
+ utils.defineProperty(this, 'hash', value);
+}
+
+function Result() {}
+
+function Interface(abi) {
+ if (!(this instanceof Interface)) { throw new Error('missing new'); }
+
+ if (typeof(abi) === 'string') {
+ try {
+ abi = JSON.parse(abi);
+ } catch (error) {
+ throwError('invalid abi', { input: abi });
+ }
+ }
+
+ utils.defineFrozen(this, 'abi', abi);
+
+ var methods = {}, events = {}, deploy = null;
+
+ utils.defineProperty(this, 'functions', methods);
+ utils.defineProperty(this, 'events', events);
+
+ function addMethod(method) {
+
+ switch (method.type) {
+ case 'constructor':
+ var func = (function() {
+ var inputParams = parseParams(method.inputs);
+
+ var func = function(bytecode) {
+ if (!utils.isHexString(bytecode)) {
+ throwError('invalid bytecode', { input: bytecode });
+ }
+
+ var params = Array.prototype.slice.call(arguments, 1);
+ if (params.length < inputParams.types.length) {
+ throwError('missing parameter');
+ } else if (params.length > inputParams.types.length) {
+ throwError('too many parameters');
+ }
+
+ var result = {
+ bytecode: bytecode + utils.coder.encode(inputParams.names, inputParams.types, params).substring(2),
+ type: 'deploy'
+ }
+
+ return populateDescription(new DeployDescription(), result);
+ }
+
+ utils.defineFrozen(func, 'inputs', inputParams);
+ utils.defineProperty(func, 'payable', (method.payable == null || !!method.payable))
+
+ return func;
+ })();
+
+ if (!deploy) { deploy = func; }
+
+ break;
+
+ case 'function':
+ var func = (function() {
+ var inputParams = parseParams(method.inputs);
+ var outputParams = parseParams(method.outputs);
+
+ var signature = '(' + inputParams.types.join(',') + ')';
+ signature = signature.replace(/tuple/g, '');
+ signature = method.name + signature;
+
+ var sighash = utils.keccak256(utils.toUtf8Bytes(signature)).substring(0, 10);
+ var func = function() {
+ var result = {
+ name: method.name,
+ signature: signature,
+ sighash: sighash,
+ type: ((method.constant) ? 'call': 'transaction')
+ };
+
+ var params = Array.prototype.slice.call(arguments, 0);
+
+ if (params.length < inputParams.types.length) {
+ throwError('missing parameter');
+ } else if (params.length > inputParams.types.length) {
+ throwError('too many parameters');
+ }
+
+ result.data = sighash + utils.coder.encode(inputParams.names, inputParams.types, params).substring(2);
+ result.parse = function(data) {
+ return utils.coder.decode(
+ outputParams.names,
+ outputParams.types,
+ utils.arrayify(data)
+ );
+ };
+
+ return populateDescription(new FunctionDescription(), result);
+ }
+
+ utils.defineFrozen(func, 'inputs', inputParams);
+ utils.defineFrozen(func, 'outputs', outputParams);
+
+ utils.defineProperty(func, 'payable', (method.payable == null || !!method.payable))
+
+ utils.defineProperty(func, 'signature', signature);
+ utils.defineProperty(func, 'sighash', sighash);
+
+ return func;
+ })();
+
+ // Expose the first (and hopefully unique named function
+ if (method.name && methods[method.name] == null) {
+ utils.defineProperty(methods, method.name, func);
+ }
+
+ // Expose all methods by their signature, for overloaded functions
+ if (methods[func.signature] == null) {
+ utils.defineProperty(methods, func.signature, func);
+ }
+
+ break;
+
+ case 'event':
+ var func = (function() {
+ var inputParams = parseParams(method.inputs);
+
+ var signature = '(' + inputParams.types.join(',') + ')';
+ signature = signature.replace(/tuple/g, '');
+ signature = method.name + signature;
+
+ var result = {
+ anonymous: (!!method.anonymous),
+ name: method.name,
+ signature: signature,
+ type: 'event'
+ };
+
+ result.parse = function(topics, data) {
+ if (data == null) {
+ data = topics;
+ topics = null;
+ }
+
+ // Strip the signature off of non-anonymous topics
+ if (topics != null && !method.anonymous) { topics = topics.slice(1); }
+
+ var inputNamesIndexed = [], inputNamesNonIndexed = [];
+ var inputTypesIndexed = [], inputTypesNonIndexed = [];
+ var inputDynamic = [];
+ method.inputs.forEach(function(input, index) {
+ var type = inputParams.types[index];
+ var name = inputParams.names[index];
+
+ if (input.indexed) {
+ if (type === 'string' || type === 'bytes' || type.indexOf('[') >= 0 || type.substring(0, 5) === 'tuple') {
+ inputTypesIndexed.push('bytes32');
+ inputDynamic.push(true);
+ } else {
+ inputTypesIndexed.push(type);
+ inputDynamic.push(false);
+ }
+ inputNamesIndexed.push(name);
+ } else {
+ inputNamesNonIndexed.push(name);
+ inputTypesNonIndexed.push(type);
+ inputDynamic.push(false);
+ }
+ });
+
+ if (topics != null) {
+ var resultIndexed = utils.coder.decode(
+ inputNamesIndexed,
+ inputTypesIndexed,
+ utils.concat(topics)
+ );
+ }
+
+ var resultNonIndexed = utils.coder.decode(
+ inputNamesNonIndexed,
+ inputTypesNonIndexed,
+ utils.arrayify(data)
+ );
+
+ var result = new Result();
+ var nonIndexedIndex = 0, indexedIndex = 0;
+ method.inputs.forEach(function(input, index) {
+ if (input.indexed) {
+ if (topics == null) {
+ result[index] = new Indexed(null);
+
+ } else if (inputDynamic[index]) {
+ result[index] = new Indexed(resultIndexed[indexedIndex++]);
+ } else {
+ result[index] = resultIndexed[indexedIndex++];
+ }
+ } else {
+ result[index] = resultNonIndexed[nonIndexedIndex++];
+ }
+ if (input.name) { result[input.name] = result[index]; }
+ });
+
+ result.length = method.inputs.length;
+
+ return result;
+ };
+
+ var func = populateDescription(new EventDescription(), result)
+ utils.defineFrozen(func, 'topics', [ utils.keccak256(utils.toUtf8Bytes(signature)) ]);
+ utils.defineFrozen(func, 'inputs', inputParams);
+ return func;
+ })();
+
+ // Expose the first (and hopefully unique) event name
+ if (method.name && events[method.name] == null) {
+ utils.defineProperty(events, method.name, func);
+ }
+
+ // Expose all events by their signature, for overloaded functions
+ if (methods[func.signature] == null) {
+ utils.defineProperty(methods, func.signature, func);
+ }
+
+ break;
+
+ case 'fallback':
+ // Nothing to do for fallback
+ break;
+
+ default:
+ console.log('WARNING: unsupported ABI type - ' + method.type);
+ break;
+ }
+ };
+
+ this.abi.forEach(addMethod, this);
+
+ // If there wasn't a constructor, create the default constructor
+ if (!deploy) {
+ addMethod({type: 'constructor', inputs: []});
+ }
+
+ utils.defineProperty(this, 'deployFunction', deploy);
+}
+
+module.exports = Interface;
+
+},{"../utils/abi-coder":8,"../utils/convert":11,"../utils/keccak256":12,"../utils/properties":13,"../utils/throw-error":14,"../utils/utf8":15}],4:[function(require,module,exports){
+(function (module, exports) {
+ 'use strict';
+
+ // Utils
+ function assert (val, msg) {
+ if (!val) throw new Error(msg || 'Assertion failed');
+ }
+
+ // Could use `inherits` module, but don't want to move from single file
+ // architecture yet.
+ function inherits (ctor, superCtor) {
+ ctor.super_ = superCtor;
+ var TempCtor = function () {};
+ TempCtor.prototype = superCtor.prototype;
+ ctor.prototype = new TempCtor();
+ ctor.prototype.constructor = ctor;
+ }
+
+ // BN
+
+ function BN (number, base, endian) {
+ if (BN.isBN(number)) {
+ return number;
+ }
+
+ this.negative = 0;
+ this.words = null;
+ this.length = 0;
+
+ // Reduction context
+ this.red = null;
+
+ if (number !== null) {
+ if (base === 'le' || base === 'be') {
+ endian = base;
+ base = 10;
+ }
+
+ this._init(number || 0, base || 10, endian || 'be');
+ }
+ }
+ if (typeof module === 'object') {
+ module.exports = BN;
+ } else {
+ exports.BN = BN;
+ }
+
+ BN.BN = BN;
+ BN.wordSize = 26;
+
+ var Buffer;
+ try {
+ Buffer = require('buffer').Buffer;
+ } catch (e) {
+ }
+
+ BN.isBN = function isBN (num) {
+ if (num instanceof BN) {
+ return true;
+ }
+
+ return num !== null && typeof num === 'object' &&
+ num.constructor.wordSize === BN.wordSize && Array.isArray(num.words);
+ };
+
+ BN.max = function max (left, right) {
+ if (left.cmp(right) > 0) return left;
+ return right;
+ };
+
+ BN.min = function min (left, right) {
+ if (left.cmp(right) < 0) return left;
+ return right;
+ };
+
+ BN.prototype._init = function init (number, base, endian) {
+ if (typeof number === 'number') {
+ return this._initNumber(number, base, endian);
+ }
+
+ if (typeof number === 'object') {
+ return this._initArray(number, base, endian);
+ }
+
+ if (base === 'hex') {
+ base = 16;
+ }
+ assert(base === (base | 0) && base >= 2 && base <= 36);
+
+ number = number.toString().replace(/\s+/g, '');
+ var start = 0;
+ if (number[0] === '-') {
+ start++;
+ }
+
+ if (base === 16) {
+ this._parseHex(number, start);
+ } else {
+ this._parseBase(number, base, start);
+ }
+
+ if (number[0] === '-') {
+ this.negative = 1;
+ }
+
+ this.strip();
+
+ if (endian !== 'le') return;
+
+ this._initArray(this.toArray(), base, endian);
+ };
+
+ BN.prototype._initNumber = function _initNumber (number, base, endian) {
+ if (number < 0) {
+ this.negative = 1;
+ number = -number;
+ }
+ if (number < 0x4000000) {
+ this.words = [ number & 0x3ffffff ];
+ this.length = 1;
+ } else if (number < 0x10000000000000) {
+ this.words = [
+ number & 0x3ffffff,
+ (number / 0x4000000) & 0x3ffffff
+ ];
+ this.length = 2;
+ } else {
+ assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
+ this.words = [
+ number & 0x3ffffff,
+ (number / 0x4000000) & 0x3ffffff,
+ 1
+ ];
+ this.length = 3;
+ }
+
+ if (endian !== 'le') return;
+
+ // Reverse the bytes
+ this._initArray(this.toArray(), base, endian);
+ };
+
+ BN.prototype._initArray = function _initArray (number, base, endian) {
+ // Perhaps a Uint8Array
+ assert(typeof number.length === 'number');
+ if (number.length <= 0) {
+ this.words = [ 0 ];
+ this.length = 1;
+ return this;
+ }
+
+ this.length = Math.ceil(number.length / 3);
+ this.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ this.words[i] = 0;
+ }
+
+ var j, w;
+ var off = 0;
+ if (endian === 'be') {
+ for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
+ w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ } else if (endian === 'le') {
+ for (i = 0, j = 0; i < number.length; i += 3) {
+ w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ }
+ return this.strip();
+ };
+
+ function parseHex (str, start, end) {
+ var r = 0;
+ var len = Math.min(str.length, end);
+ for (var i = start; i < len; i++) {
+ var c = str.charCodeAt(i) - 48;
+
+ r <<= 4;
+
+ // 'a' - 'f'
+ if (c >= 49 && c <= 54) {
+ r |= c - 49 + 0xa;
+
+ // 'A' - 'F'
+ } else if (c >= 17 && c <= 22) {
+ r |= c - 17 + 0xa;
+
+ // '0' - '9'
+ } else {
+ r |= c & 0xf;
+ }
+ }
+ return r;
+ }
+
+ BN.prototype._parseHex = function _parseHex (number, start) {
+ // Create possibly bigger array to ensure that it fits the number
+ this.length = Math.ceil((number.length - start) / 6);
+ this.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ this.words[i] = 0;
+ }
+
+ var j, w;
+ // Scan 24-bit chunks and add them to the number
+ var off = 0;
+ for (i = number.length - 6, j = 0; i >= start; i -= 6) {
+ w = parseHex(number, i, i + 6);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
+ this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ if (i + 6 !== start) {
+ w = parseHex(number, start, i + 6);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
+ }
+ this.strip();
+ };
+
+ function parseBase (str, start, end, mul) {
+ var r = 0;
+ var len = Math.min(str.length, end);
+ for (var i = start; i < len; i++) {
+ var c = str.charCodeAt(i) - 48;
+
+ r *= mul;
+
+ // 'a'
+ if (c >= 49) {
+ r += c - 49 + 0xa;
+
+ // 'A'
+ } else if (c >= 17) {
+ r += c - 17 + 0xa;
+
+ // '0' - '9'
+ } else {
+ r += c;
+ }
+ }
+ return r;
+ }
+
+ BN.prototype._parseBase = function _parseBase (number, base, start) {
+ // Initialize as zero
+ this.words = [ 0 ];
+ this.length = 1;
+
+ // Find length of limb in base
+ for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
+ limbLen++;
+ }
+ limbLen--;
+ limbPow = (limbPow / base) | 0;
+
+ var total = number.length - start;
+ var mod = total % limbLen;
+ var end = Math.min(total, total - mod) + start;
+
+ var word = 0;
+ for (var i = start; i < end; i += limbLen) {
+ word = parseBase(number, i, i + limbLen, base);
+
+ this.imuln(limbPow);
+ if (this.words[0] + word < 0x4000000) {
+ this.words[0] += word;
+ } else {
+ this._iaddn(word);
+ }
+ }
+
+ if (mod !== 0) {
+ var pow = 1;
+ word = parseBase(number, i, number.length, base);
+
+ for (i = 0; i < mod; i++) {
+ pow *= base;
+ }
+
+ this.imuln(pow);
+ if (this.words[0] + word < 0x4000000) {
+ this.words[0] += word;
+ } else {
+ this._iaddn(word);
+ }
+ }
+ };
+
+ BN.prototype.copy = function copy (dest) {
+ dest.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ dest.words[i] = this.words[i];
+ }
+ dest.length = this.length;
+ dest.negative = this.negative;
+ dest.red = this.red;
+ };
+
+ BN.prototype.clone = function clone () {
+ var r = new BN(null);
+ this.copy(r);
+ return r;
+ };
+
+ BN.prototype._expand = function _expand (size) {
+ while (this.length < size) {
+ this.words[this.length++] = 0;
+ }
+ return this;
+ };
+
+ // Remove leading `0` from `this`
+ BN.prototype.strip = function strip () {
+ while (this.length > 1 && this.words[this.length - 1] === 0) {
+ this.length--;
+ }
+ return this._normSign();
+ };
+
+ BN.prototype._normSign = function _normSign () {
+ // -0 = 0
+ if (this.length === 1 && this.words[0] === 0) {
+ this.negative = 0;
+ }
+ return this;
+ };
+
+ BN.prototype.inspect = function inspect () {
+ return (this.red ? '';
+ };
+
+ /*
+
+ var zeros = [];
+ var groupSizes = [];
+ var groupBases = [];
+
+ var s = '';
+ var i = -1;
+ while (++i < BN.wordSize) {
+ zeros[i] = s;
+ s += '0';
+ }
+ groupSizes[0] = 0;
+ groupSizes[1] = 0;
+ groupBases[0] = 0;
+ groupBases[1] = 0;
+ var base = 2 - 1;
+ while (++base < 36 + 1) {
+ var groupSize = 0;
+ var groupBase = 1;
+ while (groupBase < (1 << BN.wordSize) / base) {
+ groupBase *= base;
+ groupSize += 1;
+ }
+ groupSizes[base] = groupSize;
+ groupBases[base] = groupBase;
+ }
+
+ */
+
+ var zeros = [
+ '',
+ '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'
+ ];
+
+ var groupSizes = [
+ 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
+ ];
+
+ var groupBases = [
+ 0, 0,
+ 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
+ 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
+ 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
+ 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
+ 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
+ ];
+
+ BN.prototype.toString = function toString (base, padding) {
+ base = base || 10;
+ padding = padding | 0 || 1;
+
+ var out;
+ if (base === 16 || base === 'hex') {
+ out = '';
+ var off = 0;
+ var carry = 0;
+ for (var i = 0; i < this.length; i++) {
+ var w = this.words[i];
+ var word = (((w << off) | carry) & 0xffffff).toString(16);
+ carry = (w >>> (24 - off)) & 0xffffff;
+ if (carry !== 0 || i !== this.length - 1) {
+ out = zeros[6 - word.length] + word + out;
+ } else {
+ out = word + out;
+ }
+ off += 2;
+ if (off >= 26) {
+ off -= 26;
+ i--;
+ }
+ }
+ if (carry !== 0) {
+ out = carry.toString(16) + out;
+ }
+ while (out.length % padding !== 0) {
+ out = '0' + out;
+ }
+ if (this.negative !== 0) {
+ out = '-' + out;
+ }
+ return out;
+ }
+
+ if (base === (base | 0) && base >= 2 && base <= 36) {
+ // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
+ var groupSize = groupSizes[base];
+ // var groupBase = Math.pow(base, groupSize);
+ var groupBase = groupBases[base];
+ out = '';
+ var c = this.clone();
+ c.negative = 0;
+ while (!c.isZero()) {
+ var r = c.modn(groupBase).toString(base);
+ c = c.idivn(groupBase);
+
+ if (!c.isZero()) {
+ out = zeros[groupSize - r.length] + r + out;
+ } else {
+ out = r + out;
+ }
+ }
+ if (this.isZero()) {
+ out = '0' + out;
+ }
+ while (out.length % padding !== 0) {
+ out = '0' + out;
+ }
+ if (this.negative !== 0) {
+ out = '-' + out;
+ }
+ return out;
+ }
+
+ assert(false, 'Base should be between 2 and 36');
+ };
+
+ BN.prototype.toNumber = function toNumber () {
+ var ret = this.words[0];
+ if (this.length === 2) {
+ ret += this.words[1] * 0x4000000;
+ } else if (this.length === 3 && this.words[2] === 0x01) {
+ // NOTE: at this stage it is known that the top bit is set
+ ret += 0x10000000000000 + (this.words[1] * 0x4000000);
+ } else if (this.length > 2) {
+ assert(false, 'Number can only safely store up to 53 bits');
+ }
+ return (this.negative !== 0) ? -ret : ret;
+ };
+
+ BN.prototype.toJSON = function toJSON () {
+ return this.toString(16);
+ };
+
+ BN.prototype.toBuffer = function toBuffer (endian, length) {
+ assert(typeof Buffer !== 'undefined');
+ return this.toArrayLike(Buffer, endian, length);
+ };
+
+ BN.prototype.toArray = function toArray (endian, length) {
+ return this.toArrayLike(Array, endian, length);
+ };
+
+ BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
+ var byteLength = this.byteLength();
+ var reqLength = length || Math.max(1, byteLength);
+ assert(byteLength <= reqLength, 'byte array longer than desired length');
+ assert(reqLength > 0, 'Requested array length <= 0');
+
+ this.strip();
+ var littleEndian = endian === 'le';
+ var res = new ArrayType(reqLength);
+
+ var b, i;
+ var q = this.clone();
+ if (!littleEndian) {
+ // Assume big-endian
+ for (i = 0; i < reqLength - byteLength; i++) {
+ res[i] = 0;
+ }
+
+ for (i = 0; !q.isZero(); i++) {
+ b = q.andln(0xff);
+ q.iushrn(8);
+
+ res[reqLength - i - 1] = b;
+ }
+ } else {
+ for (i = 0; !q.isZero(); i++) {
+ b = q.andln(0xff);
+ q.iushrn(8);
+
+ res[i] = b;
+ }
+
+ for (; i < reqLength; i++) {
+ res[i] = 0;
+ }
+ }
+
+ return res;
+ };
+
+ if (Math.clz32) {
+ BN.prototype._countBits = function _countBits (w) {
+ return 32 - Math.clz32(w);
+ };
+ } else {
+ BN.prototype._countBits = function _countBits (w) {
+ var t = w;
+ var r = 0;
+ if (t >= 0x1000) {
+ r += 13;
+ t >>>= 13;
+ }
+ if (t >= 0x40) {
+ r += 7;
+ t >>>= 7;
+ }
+ if (t >= 0x8) {
+ r += 4;
+ t >>>= 4;
+ }
+ if (t >= 0x02) {
+ r += 2;
+ t >>>= 2;
+ }
+ return r + t;
+ };
+ }
+
+ BN.prototype._zeroBits = function _zeroBits (w) {
+ // Short-cut
+ if (w === 0) return 26;
+
+ var t = w;
+ var r = 0;
+ if ((t & 0x1fff) === 0) {
+ r += 13;
+ t >>>= 13;
+ }
+ if ((t & 0x7f) === 0) {
+ r += 7;
+ t >>>= 7;
+ }
+ if ((t & 0xf) === 0) {
+ r += 4;
+ t >>>= 4;
+ }
+ if ((t & 0x3) === 0) {
+ r += 2;
+ t >>>= 2;
+ }
+ if ((t & 0x1) === 0) {
+ r++;
+ }
+ return r;
+ };
+
+ // Return number of used bits in a BN
+ BN.prototype.bitLength = function bitLength () {
+ var w = this.words[this.length - 1];
+ var hi = this._countBits(w);
+ return (this.length - 1) * 26 + hi;
+ };
+
+ function toBitArray (num) {
+ var w = new Array(num.bitLength());
+
+ for (var bit = 0; bit < w.length; bit++) {
+ var off = (bit / 26) | 0;
+ var wbit = bit % 26;
+
+ w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
+ }
+
+ return w;
+ }
+
+ // Number of trailing zero bits
+ BN.prototype.zeroBits = function zeroBits () {
+ if (this.isZero()) return 0;
+
+ var r = 0;
+ for (var i = 0; i < this.length; i++) {
+ var b = this._zeroBits(this.words[i]);
+ r += b;
+ if (b !== 26) break;
+ }
+ return r;
+ };
+
+ BN.prototype.byteLength = function byteLength () {
+ return Math.ceil(this.bitLength() / 8);
+ };
+
+ BN.prototype.toTwos = function toTwos (width) {
+ if (this.negative !== 0) {
+ return this.abs().inotn(width).iaddn(1);
+ }
+ return this.clone();
+ };
+
+ BN.prototype.fromTwos = function fromTwos (width) {
+ if (this.testn(width - 1)) {
+ return this.notn(width).iaddn(1).ineg();
+ }
+ return this.clone();
+ };
+
+ BN.prototype.isNeg = function isNeg () {
+ return this.negative !== 0;
+ };
+
+ // Return negative clone of `this`
+ BN.prototype.neg = function neg () {
+ return this.clone().ineg();
+ };
+
+ BN.prototype.ineg = function ineg () {
+ if (!this.isZero()) {
+ this.negative ^= 1;
+ }
+
+ return this;
+ };
+
+ // Or `num` with `this` in-place
+ BN.prototype.iuor = function iuor (num) {
+ while (this.length < num.length) {
+ this.words[this.length++] = 0;
+ }
+
+ for (var i = 0; i < num.length; i++) {
+ this.words[i] = this.words[i] | num.words[i];
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ior = function ior (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuor(num);
+ };
+
+ // Or `num` with `this`
+ BN.prototype.or = function or (num) {
+ if (this.length > num.length) return this.clone().ior(num);
+ return num.clone().ior(this);
+ };
+
+ BN.prototype.uor = function uor (num) {
+ if (this.length > num.length) return this.clone().iuor(num);
+ return num.clone().iuor(this);
+ };
+
+ // And `num` with `this` in-place
+ BN.prototype.iuand = function iuand (num) {
+ // b = min-length(num, this)
+ var b;
+ if (this.length > num.length) {
+ b = num;
+ } else {
+ b = this;
+ }
+
+ for (var i = 0; i < b.length; i++) {
+ this.words[i] = this.words[i] & num.words[i];
+ }
+
+ this.length = b.length;
+
+ return this.strip();
+ };
+
+ BN.prototype.iand = function iand (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuand(num);
+ };
+
+ // And `num` with `this`
+ BN.prototype.and = function and (num) {
+ if (this.length > num.length) return this.clone().iand(num);
+ return num.clone().iand(this);
+ };
+
+ BN.prototype.uand = function uand (num) {
+ if (this.length > num.length) return this.clone().iuand(num);
+ return num.clone().iuand(this);
+ };
+
+ // Xor `num` with `this` in-place
+ BN.prototype.iuxor = function iuxor (num) {
+ // a.length > b.length
+ var a;
+ var b;
+ if (this.length > num.length) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ for (var i = 0; i < b.length; i++) {
+ this.words[i] = a.words[i] ^ b.words[i];
+ }
+
+ if (this !== a) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ this.length = a.length;
+
+ return this.strip();
+ };
+
+ BN.prototype.ixor = function ixor (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuxor(num);
+ };
+
+ // Xor `num` with `this`
+ BN.prototype.xor = function xor (num) {
+ if (this.length > num.length) return this.clone().ixor(num);
+ return num.clone().ixor(this);
+ };
+
+ BN.prototype.uxor = function uxor (num) {
+ if (this.length > num.length) return this.clone().iuxor(num);
+ return num.clone().iuxor(this);
+ };
+
+ // Not ``this`` with ``width`` bitwidth
+ BN.prototype.inotn = function inotn (width) {
+ assert(typeof width === 'number' && width >= 0);
+
+ var bytesNeeded = Math.ceil(width / 26) | 0;
+ var bitsLeft = width % 26;
+
+ // Extend the buffer with leading zeroes
+ this._expand(bytesNeeded);
+
+ if (bitsLeft > 0) {
+ bytesNeeded--;
+ }
+
+ // Handle complete words
+ for (var i = 0; i < bytesNeeded; i++) {
+ this.words[i] = ~this.words[i] & 0x3ffffff;
+ }
+
+ // Handle the residue
+ if (bitsLeft > 0) {
+ this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
+ }
+
+ // And remove leading zeroes
+ return this.strip();
+ };
+
+ BN.prototype.notn = function notn (width) {
+ return this.clone().inotn(width);
+ };
+
+ // Set `bit` of `this`
+ BN.prototype.setn = function setn (bit, val) {
+ assert(typeof bit === 'number' && bit >= 0);
+
+ var off = (bit / 26) | 0;
+ var wbit = bit % 26;
+
+ this._expand(off + 1);
+
+ if (val) {
+ this.words[off] = this.words[off] | (1 << wbit);
+ } else {
+ this.words[off] = this.words[off] & ~(1 << wbit);
+ }
+
+ return this.strip();
+ };
+
+ // Add `num` to `this` in-place
+ BN.prototype.iadd = function iadd (num) {
+ var r;
+
+ // negative + positive
+ if (this.negative !== 0 && num.negative === 0) {
+ this.negative = 0;
+ r = this.isub(num);
+ this.negative ^= 1;
+ return this._normSign();
+
+ // positive + negative
+ } else if (this.negative === 0 && num.negative !== 0) {
+ num.negative = 0;
+ r = this.isub(num);
+ num.negative = 1;
+ return r._normSign();
+ }
+
+ // a.length > b.length
+ var a, b;
+ if (this.length > num.length) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ var carry = 0;
+ for (var i = 0; i < b.length; i++) {
+ r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
+ this.words[i] = r & 0x3ffffff;
+ carry = r >>> 26;
+ }
+ for (; carry !== 0 && i < a.length; i++) {
+ r = (a.words[i] | 0) + carry;
+ this.words[i] = r & 0x3ffffff;
+ carry = r >>> 26;
+ }
+
+ this.length = a.length;
+ if (carry !== 0) {
+ this.words[this.length] = carry;
+ this.length++;
+ // Copy the rest of the words
+ } else if (a !== this) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ return this;
+ };
+
+ // Add `num` to `this`
+ BN.prototype.add = function add (num) {
+ var res;
+ if (num.negative !== 0 && this.negative === 0) {
+ num.negative = 0;
+ res = this.sub(num);
+ num.negative ^= 1;
+ return res;
+ } else if (num.negative === 0 && this.negative !== 0) {
+ this.negative = 0;
+ res = num.sub(this);
+ this.negative = 1;
+ return res;
+ }
+
+ if (this.length > num.length) return this.clone().iadd(num);
+
+ return num.clone().iadd(this);
+ };
+
+ // Subtract `num` from `this` in-place
+ BN.prototype.isub = function isub (num) {
+ // this - (-num) = this + num
+ if (num.negative !== 0) {
+ num.negative = 0;
+ var r = this.iadd(num);
+ num.negative = 1;
+ return r._normSign();
+
+ // -this - num = -(this + num)
+ } else if (this.negative !== 0) {
+ this.negative = 0;
+ this.iadd(num);
+ this.negative = 1;
+ return this._normSign();
+ }
+
+ // At this point both numbers are positive
+ var cmp = this.cmp(num);
+
+ // Optimization - zeroify
+ if (cmp === 0) {
+ this.negative = 0;
+ this.length = 1;
+ this.words[0] = 0;
+ return this;
+ }
+
+ // a > b
+ var a, b;
+ if (cmp > 0) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ var carry = 0;
+ for (var i = 0; i < b.length; i++) {
+ r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
+ carry = r >> 26;
+ this.words[i] = r & 0x3ffffff;
+ }
+ for (; carry !== 0 && i < a.length; i++) {
+ r = (a.words[i] | 0) + carry;
+ carry = r >> 26;
+ this.words[i] = r & 0x3ffffff;
+ }
+
+ // Copy rest of the words
+ if (carry === 0 && i < a.length && a !== this) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ this.length = Math.max(this.length, i);
+
+ if (a !== this) {
+ this.negative = 1;
+ }
+
+ return this.strip();
+ };
+
+ // Subtract `num` from `this`
+ BN.prototype.sub = function sub (num) {
+ return this.clone().isub(num);
+ };
+
+ function smallMulTo (self, num, out) {
+ out.negative = num.negative ^ self.negative;
+ var len = (self.length + num.length) | 0;
+ out.length = len;
+ len = (len - 1) | 0;
+
+ // Peel one iteration (compiler can't do it, because of code complexity)
+ var a = self.words[0] | 0;
+ var b = num.words[0] | 0;
+ var r = a * b;
+
+ var lo = r & 0x3ffffff;
+ var carry = (r / 0x4000000) | 0;
+ out.words[0] = lo;
+
+ for (var k = 1; k < len; k++) {
+ // Sum all words with the same `i + j = k` and accumulate `ncarry`,
+ // note that ncarry could be >= 0x3ffffff
+ var ncarry = carry >>> 26;
+ var rword = carry & 0x3ffffff;
+ var maxJ = Math.min(k, num.length - 1);
+ for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
+ var i = (k - j) | 0;
+ a = self.words[i] | 0;
+ b = num.words[j] | 0;
+ r = a * b + rword;
+ ncarry += (r / 0x4000000) | 0;
+ rword = r & 0x3ffffff;
+ }
+ out.words[k] = rword | 0;
+ carry = ncarry | 0;
+ }
+ if (carry !== 0) {
+ out.words[k] = carry | 0;
+ } else {
+ out.length--;
+ }
+
+ return out.strip();
+ }
+
+ // TODO(indutny): it may be reasonable to omit it for users who don't need
+ // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
+ // multiplication (like elliptic secp256k1).
+ var comb10MulTo = function comb10MulTo (self, num, out) {
+ var a = self.words;
+ var b = num.words;
+ var o = out.words;
+ var c = 0;
+ var lo;
+ var mid;
+ var hi;
+ var a0 = a[0] | 0;
+ var al0 = a0 & 0x1fff;
+ var ah0 = a0 >>> 13;
+ var a1 = a[1] | 0;
+ var al1 = a1 & 0x1fff;
+ var ah1 = a1 >>> 13;
+ var a2 = a[2] | 0;
+ var al2 = a2 & 0x1fff;
+ var ah2 = a2 >>> 13;
+ var a3 = a[3] | 0;
+ var al3 = a3 & 0x1fff;
+ var ah3 = a3 >>> 13;
+ var a4 = a[4] | 0;
+ var al4 = a4 & 0x1fff;
+ var ah4 = a4 >>> 13;
+ var a5 = a[5] | 0;
+ var al5 = a5 & 0x1fff;
+ var ah5 = a5 >>> 13;
+ var a6 = a[6] | 0;
+ var al6 = a6 & 0x1fff;
+ var ah6 = a6 >>> 13;
+ var a7 = a[7] | 0;
+ var al7 = a7 & 0x1fff;
+ var ah7 = a7 >>> 13;
+ var a8 = a[8] | 0;
+ var al8 = a8 & 0x1fff;
+ var ah8 = a8 >>> 13;
+ var a9 = a[9] | 0;
+ var al9 = a9 & 0x1fff;
+ var ah9 = a9 >>> 13;
+ var b0 = b[0] | 0;
+ var bl0 = b0 & 0x1fff;
+ var bh0 = b0 >>> 13;
+ var b1 = b[1] | 0;
+ var bl1 = b1 & 0x1fff;
+ var bh1 = b1 >>> 13;
+ var b2 = b[2] | 0;
+ var bl2 = b2 & 0x1fff;
+ var bh2 = b2 >>> 13;
+ var b3 = b[3] | 0;
+ var bl3 = b3 & 0x1fff;
+ var bh3 = b3 >>> 13;
+ var b4 = b[4] | 0;
+ var bl4 = b4 & 0x1fff;
+ var bh4 = b4 >>> 13;
+ var b5 = b[5] | 0;
+ var bl5 = b5 & 0x1fff;
+ var bh5 = b5 >>> 13;
+ var b6 = b[6] | 0;
+ var bl6 = b6 & 0x1fff;
+ var bh6 = b6 >>> 13;
+ var b7 = b[7] | 0;
+ var bl7 = b7 & 0x1fff;
+ var bh7 = b7 >>> 13;
+ var b8 = b[8] | 0;
+ var bl8 = b8 & 0x1fff;
+ var bh8 = b8 >>> 13;
+ var b9 = b[9] | 0;
+ var bl9 = b9 & 0x1fff;
+ var bh9 = b9 >>> 13;
+
+ out.negative = self.negative ^ num.negative;
+ out.length = 19;
+ /* k = 0 */
+ lo = Math.imul(al0, bl0);
+ mid = Math.imul(al0, bh0);
+ mid = (mid + Math.imul(ah0, bl0)) | 0;
+ hi = Math.imul(ah0, bh0);
+ var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
+ w0 &= 0x3ffffff;
+ /* k = 1 */
+ lo = Math.imul(al1, bl0);
+ mid = Math.imul(al1, bh0);
+ mid = (mid + Math.imul(ah1, bl0)) | 0;
+ hi = Math.imul(ah1, bh0);
+ lo = (lo + Math.imul(al0, bl1)) | 0;
+ mid = (mid + Math.imul(al0, bh1)) | 0;
+ mid = (mid + Math.imul(ah0, bl1)) | 0;
+ hi = (hi + Math.imul(ah0, bh1)) | 0;
+ var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
+ w1 &= 0x3ffffff;
+ /* k = 2 */
+ lo = Math.imul(al2, bl0);
+ mid = Math.imul(al2, bh0);
+ mid = (mid + Math.imul(ah2, bl0)) | 0;
+ hi = Math.imul(ah2, bh0);
+ lo = (lo + Math.imul(al1, bl1)) | 0;
+ mid = (mid + Math.imul(al1, bh1)) | 0;
+ mid = (mid + Math.imul(ah1, bl1)) | 0;
+ hi = (hi + Math.imul(ah1, bh1)) | 0;
+ lo = (lo + Math.imul(al0, bl2)) | 0;
+ mid = (mid + Math.imul(al0, bh2)) | 0;
+ mid = (mid + Math.imul(ah0, bl2)) | 0;
+ hi = (hi + Math.imul(ah0, bh2)) | 0;
+ var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
+ w2 &= 0x3ffffff;
+ /* k = 3 */
+ lo = Math.imul(al3, bl0);
+ mid = Math.imul(al3, bh0);
+ mid = (mid + Math.imul(ah3, bl0)) | 0;
+ hi = Math.imul(ah3, bh0);
+ lo = (lo + Math.imul(al2, bl1)) | 0;
+ mid = (mid + Math.imul(al2, bh1)) | 0;
+ mid = (mid + Math.imul(ah2, bl1)) | 0;
+ hi = (hi + Math.imul(ah2, bh1)) | 0;
+ lo = (lo + Math.imul(al1, bl2)) | 0;
+ mid = (mid + Math.imul(al1, bh2)) | 0;
+ mid = (mid + Math.imul(ah1, bl2)) | 0;
+ hi = (hi + Math.imul(ah1, bh2)) | 0;
+ lo = (lo + Math.imul(al0, bl3)) | 0;
+ mid = (mid + Math.imul(al0, bh3)) | 0;
+ mid = (mid + Math.imul(ah0, bl3)) | 0;
+ hi = (hi + Math.imul(ah0, bh3)) | 0;
+ var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
+ w3 &= 0x3ffffff;
+ /* k = 4 */
+ lo = Math.imul(al4, bl0);
+ mid = Math.imul(al4, bh0);
+ mid = (mid + Math.imul(ah4, bl0)) | 0;
+ hi = Math.imul(ah4, bh0);
+ lo = (lo + Math.imul(al3, bl1)) | 0;
+ mid = (mid + Math.imul(al3, bh1)) | 0;
+ mid = (mid + Math.imul(ah3, bl1)) | 0;
+ hi = (hi + Math.imul(ah3, bh1)) | 0;
+ lo = (lo + Math.imul(al2, bl2)) | 0;
+ mid = (mid + Math.imul(al2, bh2)) | 0;
+ mid = (mid + Math.imul(ah2, bl2)) | 0;
+ hi = (hi + Math.imul(ah2, bh2)) | 0;
+ lo = (lo + Math.imul(al1, bl3)) | 0;
+ mid = (mid + Math.imul(al1, bh3)) | 0;
+ mid = (mid + Math.imul(ah1, bl3)) | 0;
+ hi = (hi + Math.imul(ah1, bh3)) | 0;
+ lo = (lo + Math.imul(al0, bl4)) | 0;
+ mid = (mid + Math.imul(al0, bh4)) | 0;
+ mid = (mid + Math.imul(ah0, bl4)) | 0;
+ hi = (hi + Math.imul(ah0, bh4)) | 0;
+ var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
+ w4 &= 0x3ffffff;
+ /* k = 5 */
+ lo = Math.imul(al5, bl0);
+ mid = Math.imul(al5, bh0);
+ mid = (mid + Math.imul(ah5, bl0)) | 0;
+ hi = Math.imul(ah5, bh0);
+ lo = (lo + Math.imul(al4, bl1)) | 0;
+ mid = (mid + Math.imul(al4, bh1)) | 0;
+ mid = (mid + Math.imul(ah4, bl1)) | 0;
+ hi = (hi + Math.imul(ah4, bh1)) | 0;
+ lo = (lo + Math.imul(al3, bl2)) | 0;
+ mid = (mid + Math.imul(al3, bh2)) | 0;
+ mid = (mid + Math.imul(ah3, bl2)) | 0;
+ hi = (hi + Math.imul(ah3, bh2)) | 0;
+ lo = (lo + Math.imul(al2, bl3)) | 0;
+ mid = (mid + Math.imul(al2, bh3)) | 0;
+ mid = (mid + Math.imul(ah2, bl3)) | 0;
+ hi = (hi + Math.imul(ah2, bh3)) | 0;
+ lo = (lo + Math.imul(al1, bl4)) | 0;
+ mid = (mid + Math.imul(al1, bh4)) | 0;
+ mid = (mid + Math.imul(ah1, bl4)) | 0;
+ hi = (hi + Math.imul(ah1, bh4)) | 0;
+ lo = (lo + Math.imul(al0, bl5)) | 0;
+ mid = (mid + Math.imul(al0, bh5)) | 0;
+ mid = (mid + Math.imul(ah0, bl5)) | 0;
+ hi = (hi + Math.imul(ah0, bh5)) | 0;
+ var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
+ w5 &= 0x3ffffff;
+ /* k = 6 */
+ lo = Math.imul(al6, bl0);
+ mid = Math.imul(al6, bh0);
+ mid = (mid + Math.imul(ah6, bl0)) | 0;
+ hi = Math.imul(ah6, bh0);
+ lo = (lo + Math.imul(al5, bl1)) | 0;
+ mid = (mid + Math.imul(al5, bh1)) | 0;
+ mid = (mid + Math.imul(ah5, bl1)) | 0;
+ hi = (hi + Math.imul(ah5, bh1)) | 0;
+ lo = (lo + Math.imul(al4, bl2)) | 0;
+ mid = (mid + Math.imul(al4, bh2)) | 0;
+ mid = (mid + Math.imul(ah4, bl2)) | 0;
+ hi = (hi + Math.imul(ah4, bh2)) | 0;
+ lo = (lo + Math.imul(al3, bl3)) | 0;
+ mid = (mid + Math.imul(al3, bh3)) | 0;
+ mid = (mid + Math.imul(ah3, bl3)) | 0;
+ hi = (hi + Math.imul(ah3, bh3)) | 0;
+ lo = (lo + Math.imul(al2, bl4)) | 0;
+ mid = (mid + Math.imul(al2, bh4)) | 0;
+ mid = (mid + Math.imul(ah2, bl4)) | 0;
+ hi = (hi + Math.imul(ah2, bh4)) | 0;
+ lo = (lo + Math.imul(al1, bl5)) | 0;
+ mid = (mid + Math.imul(al1, bh5)) | 0;
+ mid = (mid + Math.imul(ah1, bl5)) | 0;
+ hi = (hi + Math.imul(ah1, bh5)) | 0;
+ lo = (lo + Math.imul(al0, bl6)) | 0;
+ mid = (mid + Math.imul(al0, bh6)) | 0;
+ mid = (mid + Math.imul(ah0, bl6)) | 0;
+ hi = (hi + Math.imul(ah0, bh6)) | 0;
+ var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
+ w6 &= 0x3ffffff;
+ /* k = 7 */
+ lo = Math.imul(al7, bl0);
+ mid = Math.imul(al7, bh0);
+ mid = (mid + Math.imul(ah7, bl0)) | 0;
+ hi = Math.imul(ah7, bh0);
+ lo = (lo + Math.imul(al6, bl1)) | 0;
+ mid = (mid + Math.imul(al6, bh1)) | 0;
+ mid = (mid + Math.imul(ah6, bl1)) | 0;
+ hi = (hi + Math.imul(ah6, bh1)) | 0;
+ lo = (lo + Math.imul(al5, bl2)) | 0;
+ mid = (mid + Math.imul(al5, bh2)) | 0;
+ mid = (mid + Math.imul(ah5, bl2)) | 0;
+ hi = (hi + Math.imul(ah5, bh2)) | 0;
+ lo = (lo + Math.imul(al4, bl3)) | 0;
+ mid = (mid + Math.imul(al4, bh3)) | 0;
+ mid = (mid + Math.imul(ah4, bl3)) | 0;
+ hi = (hi + Math.imul(ah4, bh3)) | 0;
+ lo = (lo + Math.imul(al3, bl4)) | 0;
+ mid = (mid + Math.imul(al3, bh4)) | 0;
+ mid = (mid + Math.imul(ah3, bl4)) | 0;
+ hi = (hi + Math.imul(ah3, bh4)) | 0;
+ lo = (lo + Math.imul(al2, bl5)) | 0;
+ mid = (mid + Math.imul(al2, bh5)) | 0;
+ mid = (mid + Math.imul(ah2, bl5)) | 0;
+ hi = (hi + Math.imul(ah2, bh5)) | 0;
+ lo = (lo + Math.imul(al1, bl6)) | 0;
+ mid = (mid + Math.imul(al1, bh6)) | 0;
+ mid = (mid + Math.imul(ah1, bl6)) | 0;
+ hi = (hi + Math.imul(ah1, bh6)) | 0;
+ lo = (lo + Math.imul(al0, bl7)) | 0;
+ mid = (mid + Math.imul(al0, bh7)) | 0;
+ mid = (mid + Math.imul(ah0, bl7)) | 0;
+ hi = (hi + Math.imul(ah0, bh7)) | 0;
+ var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
+ w7 &= 0x3ffffff;
+ /* k = 8 */
+ lo = Math.imul(al8, bl0);
+ mid = Math.imul(al8, bh0);
+ mid = (mid + Math.imul(ah8, bl0)) | 0;
+ hi = Math.imul(ah8, bh0);
+ lo = (lo + Math.imul(al7, bl1)) | 0;
+ mid = (mid + Math.imul(al7, bh1)) | 0;
+ mid = (mid + Math.imul(ah7, bl1)) | 0;
+ hi = (hi + Math.imul(ah7, bh1)) | 0;
+ lo = (lo + Math.imul(al6, bl2)) | 0;
+ mid = (mid + Math.imul(al6, bh2)) | 0;
+ mid = (mid + Math.imul(ah6, bl2)) | 0;
+ hi = (hi + Math.imul(ah6, bh2)) | 0;
+ lo = (lo + Math.imul(al5, bl3)) | 0;
+ mid = (mid + Math.imul(al5, bh3)) | 0;
+ mid = (mid + Math.imul(ah5, bl3)) | 0;
+ hi = (hi + Math.imul(ah5, bh3)) | 0;
+ lo = (lo + Math.imul(al4, bl4)) | 0;
+ mid = (mid + Math.imul(al4, bh4)) | 0;
+ mid = (mid + Math.imul(ah4, bl4)) | 0;
+ hi = (hi + Math.imul(ah4, bh4)) | 0;
+ lo = (lo + Math.imul(al3, bl5)) | 0;
+ mid = (mid + Math.imul(al3, bh5)) | 0;
+ mid = (mid + Math.imul(ah3, bl5)) | 0;
+ hi = (hi + Math.imul(ah3, bh5)) | 0;
+ lo = (lo + Math.imul(al2, bl6)) | 0;
+ mid = (mid + Math.imul(al2, bh6)) | 0;
+ mid = (mid + Math.imul(ah2, bl6)) | 0;
+ hi = (hi + Math.imul(ah2, bh6)) | 0;
+ lo = (lo + Math.imul(al1, bl7)) | 0;
+ mid = (mid + Math.imul(al1, bh7)) | 0;
+ mid = (mid + Math.imul(ah1, bl7)) | 0;
+ hi = (hi + Math.imul(ah1, bh7)) | 0;
+ lo = (lo + Math.imul(al0, bl8)) | 0;
+ mid = (mid + Math.imul(al0, bh8)) | 0;
+ mid = (mid + Math.imul(ah0, bl8)) | 0;
+ hi = (hi + Math.imul(ah0, bh8)) | 0;
+ var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
+ w8 &= 0x3ffffff;
+ /* k = 9 */
+ lo = Math.imul(al9, bl0);
+ mid = Math.imul(al9, bh0);
+ mid = (mid + Math.imul(ah9, bl0)) | 0;
+ hi = Math.imul(ah9, bh0);
+ lo = (lo + Math.imul(al8, bl1)) | 0;
+ mid = (mid + Math.imul(al8, bh1)) | 0;
+ mid = (mid + Math.imul(ah8, bl1)) | 0;
+ hi = (hi + Math.imul(ah8, bh1)) | 0;
+ lo = (lo + Math.imul(al7, bl2)) | 0;
+ mid = (mid + Math.imul(al7, bh2)) | 0;
+ mid = (mid + Math.imul(ah7, bl2)) | 0;
+ hi = (hi + Math.imul(ah7, bh2)) | 0;
+ lo = (lo + Math.imul(al6, bl3)) | 0;
+ mid = (mid + Math.imul(al6, bh3)) | 0;
+ mid = (mid + Math.imul(ah6, bl3)) | 0;
+ hi = (hi + Math.imul(ah6, bh3)) | 0;
+ lo = (lo + Math.imul(al5, bl4)) | 0;
+ mid = (mid + Math.imul(al5, bh4)) | 0;
+ mid = (mid + Math.imul(ah5, bl4)) | 0;
+ hi = (hi + Math.imul(ah5, bh4)) | 0;
+ lo = (lo + Math.imul(al4, bl5)) | 0;
+ mid = (mid + Math.imul(al4, bh5)) | 0;
+ mid = (mid + Math.imul(ah4, bl5)) | 0;
+ hi = (hi + Math.imul(ah4, bh5)) | 0;
+ lo = (lo + Math.imul(al3, bl6)) | 0;
+ mid = (mid + Math.imul(al3, bh6)) | 0;
+ mid = (mid + Math.imul(ah3, bl6)) | 0;
+ hi = (hi + Math.imul(ah3, bh6)) | 0;
+ lo = (lo + Math.imul(al2, bl7)) | 0;
+ mid = (mid + Math.imul(al2, bh7)) | 0;
+ mid = (mid + Math.imul(ah2, bl7)) | 0;
+ hi = (hi + Math.imul(ah2, bh7)) | 0;
+ lo = (lo + Math.imul(al1, bl8)) | 0;
+ mid = (mid + Math.imul(al1, bh8)) | 0;
+ mid = (mid + Math.imul(ah1, bl8)) | 0;
+ hi = (hi + Math.imul(ah1, bh8)) | 0;
+ lo = (lo + Math.imul(al0, bl9)) | 0;
+ mid = (mid + Math.imul(al0, bh9)) | 0;
+ mid = (mid + Math.imul(ah0, bl9)) | 0;
+ hi = (hi + Math.imul(ah0, bh9)) | 0;
+ var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
+ w9 &= 0x3ffffff;
+ /* k = 10 */
+ lo = Math.imul(al9, bl1);
+ mid = Math.imul(al9, bh1);
+ mid = (mid + Math.imul(ah9, bl1)) | 0;
+ hi = Math.imul(ah9, bh1);
+ lo = (lo + Math.imul(al8, bl2)) | 0;
+ mid = (mid + Math.imul(al8, bh2)) | 0;
+ mid = (mid + Math.imul(ah8, bl2)) | 0;
+ hi = (hi + Math.imul(ah8, bh2)) | 0;
+ lo = (lo + Math.imul(al7, bl3)) | 0;
+ mid = (mid + Math.imul(al7, bh3)) | 0;
+ mid = (mid + Math.imul(ah7, bl3)) | 0;
+ hi = (hi + Math.imul(ah7, bh3)) | 0;
+ lo = (lo + Math.imul(al6, bl4)) | 0;
+ mid = (mid + Math.imul(al6, bh4)) | 0;
+ mid = (mid + Math.imul(ah6, bl4)) | 0;
+ hi = (hi + Math.imul(ah6, bh4)) | 0;
+ lo = (lo + Math.imul(al5, bl5)) | 0;
+ mid = (mid + Math.imul(al5, bh5)) | 0;
+ mid = (mid + Math.imul(ah5, bl5)) | 0;
+ hi = (hi + Math.imul(ah5, bh5)) | 0;
+ lo = (lo + Math.imul(al4, bl6)) | 0;
+ mid = (mid + Math.imul(al4, bh6)) | 0;
+ mid = (mid + Math.imul(ah4, bl6)) | 0;
+ hi = (hi + Math.imul(ah4, bh6)) | 0;
+ lo = (lo + Math.imul(al3, bl7)) | 0;
+ mid = (mid + Math.imul(al3, bh7)) | 0;
+ mid = (mid + Math.imul(ah3, bl7)) | 0;
+ hi = (hi + Math.imul(ah3, bh7)) | 0;
+ lo = (lo + Math.imul(al2, bl8)) | 0;
+ mid = (mid + Math.imul(al2, bh8)) | 0;
+ mid = (mid + Math.imul(ah2, bl8)) | 0;
+ hi = (hi + Math.imul(ah2, bh8)) | 0;
+ lo = (lo + Math.imul(al1, bl9)) | 0;
+ mid = (mid + Math.imul(al1, bh9)) | 0;
+ mid = (mid + Math.imul(ah1, bl9)) | 0;
+ hi = (hi + Math.imul(ah1, bh9)) | 0;
+ var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
+ w10 &= 0x3ffffff;
+ /* k = 11 */
+ lo = Math.imul(al9, bl2);
+ mid = Math.imul(al9, bh2);
+ mid = (mid + Math.imul(ah9, bl2)) | 0;
+ hi = Math.imul(ah9, bh2);
+ lo = (lo + Math.imul(al8, bl3)) | 0;
+ mid = (mid + Math.imul(al8, bh3)) | 0;
+ mid = (mid + Math.imul(ah8, bl3)) | 0;
+ hi = (hi + Math.imul(ah8, bh3)) | 0;
+ lo = (lo + Math.imul(al7, bl4)) | 0;
+ mid = (mid + Math.imul(al7, bh4)) | 0;
+ mid = (mid + Math.imul(ah7, bl4)) | 0;
+ hi = (hi + Math.imul(ah7, bh4)) | 0;
+ lo = (lo + Math.imul(al6, bl5)) | 0;
+ mid = (mid + Math.imul(al6, bh5)) | 0;
+ mid = (mid + Math.imul(ah6, bl5)) | 0;
+ hi = (hi + Math.imul(ah6, bh5)) | 0;
+ lo = (lo + Math.imul(al5, bl6)) | 0;
+ mid = (mid + Math.imul(al5, bh6)) | 0;
+ mid = (mid + Math.imul(ah5, bl6)) | 0;
+ hi = (hi + Math.imul(ah5, bh6)) | 0;
+ lo = (lo + Math.imul(al4, bl7)) | 0;
+ mid = (mid + Math.imul(al4, bh7)) | 0;
+ mid = (mid + Math.imul(ah4, bl7)) | 0;
+ hi = (hi + Math.imul(ah4, bh7)) | 0;
+ lo = (lo + Math.imul(al3, bl8)) | 0;
+ mid = (mid + Math.imul(al3, bh8)) | 0;
+ mid = (mid + Math.imul(ah3, bl8)) | 0;
+ hi = (hi + Math.imul(ah3, bh8)) | 0;
+ lo = (lo + Math.imul(al2, bl9)) | 0;
+ mid = (mid + Math.imul(al2, bh9)) | 0;
+ mid = (mid + Math.imul(ah2, bl9)) | 0;
+ hi = (hi + Math.imul(ah2, bh9)) | 0;
+ var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
+ w11 &= 0x3ffffff;
+ /* k = 12 */
+ lo = Math.imul(al9, bl3);
+ mid = Math.imul(al9, bh3);
+ mid = (mid + Math.imul(ah9, bl3)) | 0;
+ hi = Math.imul(ah9, bh3);
+ lo = (lo + Math.imul(al8, bl4)) | 0;
+ mid = (mid + Math.imul(al8, bh4)) | 0;
+ mid = (mid + Math.imul(ah8, bl4)) | 0;
+ hi = (hi + Math.imul(ah8, bh4)) | 0;
+ lo = (lo + Math.imul(al7, bl5)) | 0;
+ mid = (mid + Math.imul(al7, bh5)) | 0;
+ mid = (mid + Math.imul(ah7, bl5)) | 0;
+ hi = (hi + Math.imul(ah7, bh5)) | 0;
+ lo = (lo + Math.imul(al6, bl6)) | 0;
+ mid = (mid + Math.imul(al6, bh6)) | 0;
+ mid = (mid + Math.imul(ah6, bl6)) | 0;
+ hi = (hi + Math.imul(ah6, bh6)) | 0;
+ lo = (lo + Math.imul(al5, bl7)) | 0;
+ mid = (mid + Math.imul(al5, bh7)) | 0;
+ mid = (mid + Math.imul(ah5, bl7)) | 0;
+ hi = (hi + Math.imul(ah5, bh7)) | 0;
+ lo = (lo + Math.imul(al4, bl8)) | 0;
+ mid = (mid + Math.imul(al4, bh8)) | 0;
+ mid = (mid + Math.imul(ah4, bl8)) | 0;
+ hi = (hi + Math.imul(ah4, bh8)) | 0;
+ lo = (lo + Math.imul(al3, bl9)) | 0;
+ mid = (mid + Math.imul(al3, bh9)) | 0;
+ mid = (mid + Math.imul(ah3, bl9)) | 0;
+ hi = (hi + Math.imul(ah3, bh9)) | 0;
+ var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
+ w12 &= 0x3ffffff;
+ /* k = 13 */
+ lo = Math.imul(al9, bl4);
+ mid = Math.imul(al9, bh4);
+ mid = (mid + Math.imul(ah9, bl4)) | 0;
+ hi = Math.imul(ah9, bh4);
+ lo = (lo + Math.imul(al8, bl5)) | 0;
+ mid = (mid + Math.imul(al8, bh5)) | 0;
+ mid = (mid + Math.imul(ah8, bl5)) | 0;
+ hi = (hi + Math.imul(ah8, bh5)) | 0;
+ lo = (lo + Math.imul(al7, bl6)) | 0;
+ mid = (mid + Math.imul(al7, bh6)) | 0;
+ mid = (mid + Math.imul(ah7, bl6)) | 0;
+ hi = (hi + Math.imul(ah7, bh6)) | 0;
+ lo = (lo + Math.imul(al6, bl7)) | 0;
+ mid = (mid + Math.imul(al6, bh7)) | 0;
+ mid = (mid + Math.imul(ah6, bl7)) | 0;
+ hi = (hi + Math.imul(ah6, bh7)) | 0;
+ lo = (lo + Math.imul(al5, bl8)) | 0;
+ mid = (mid + Math.imul(al5, bh8)) | 0;
+ mid = (mid + Math.imul(ah5, bl8)) | 0;
+ hi = (hi + Math.imul(ah5, bh8)) | 0;
+ lo = (lo + Math.imul(al4, bl9)) | 0;
+ mid = (mid + Math.imul(al4, bh9)) | 0;
+ mid = (mid + Math.imul(ah4, bl9)) | 0;
+ hi = (hi + Math.imul(ah4, bh9)) | 0;
+ var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
+ w13 &= 0x3ffffff;
+ /* k = 14 */
+ lo = Math.imul(al9, bl5);
+ mid = Math.imul(al9, bh5);
+ mid = (mid + Math.imul(ah9, bl5)) | 0;
+ hi = Math.imul(ah9, bh5);
+ lo = (lo + Math.imul(al8, bl6)) | 0;
+ mid = (mid + Math.imul(al8, bh6)) | 0;
+ mid = (mid + Math.imul(ah8, bl6)) | 0;
+ hi = (hi + Math.imul(ah8, bh6)) | 0;
+ lo = (lo + Math.imul(al7, bl7)) | 0;
+ mid = (mid + Math.imul(al7, bh7)) | 0;
+ mid = (mid + Math.imul(ah7, bl7)) | 0;
+ hi = (hi + Math.imul(ah7, bh7)) | 0;
+ lo = (lo + Math.imul(al6, bl8)) | 0;
+ mid = (mid + Math.imul(al6, bh8)) | 0;
+ mid = (mid + Math.imul(ah6, bl8)) | 0;
+ hi = (hi + Math.imul(ah6, bh8)) | 0;
+ lo = (lo + Math.imul(al5, bl9)) | 0;
+ mid = (mid + Math.imul(al5, bh9)) | 0;
+ mid = (mid + Math.imul(ah5, bl9)) | 0;
+ hi = (hi + Math.imul(ah5, bh9)) | 0;
+ var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
+ w14 &= 0x3ffffff;
+ /* k = 15 */
+ lo = Math.imul(al9, bl6);
+ mid = Math.imul(al9, bh6);
+ mid = (mid + Math.imul(ah9, bl6)) | 0;
+ hi = Math.imul(ah9, bh6);
+ lo = (lo + Math.imul(al8, bl7)) | 0;
+ mid = (mid + Math.imul(al8, bh7)) | 0;
+ mid = (mid + Math.imul(ah8, bl7)) | 0;
+ hi = (hi + Math.imul(ah8, bh7)) | 0;
+ lo = (lo + Math.imul(al7, bl8)) | 0;
+ mid = (mid + Math.imul(al7, bh8)) | 0;
+ mid = (mid + Math.imul(ah7, bl8)) | 0;
+ hi = (hi + Math.imul(ah7, bh8)) | 0;
+ lo = (lo + Math.imul(al6, bl9)) | 0;
+ mid = (mid + Math.imul(al6, bh9)) | 0;
+ mid = (mid + Math.imul(ah6, bl9)) | 0;
+ hi = (hi + Math.imul(ah6, bh9)) | 0;
+ var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
+ w15 &= 0x3ffffff;
+ /* k = 16 */
+ lo = Math.imul(al9, bl7);
+ mid = Math.imul(al9, bh7);
+ mid = (mid + Math.imul(ah9, bl7)) | 0;
+ hi = Math.imul(ah9, bh7);
+ lo = (lo + Math.imul(al8, bl8)) | 0;
+ mid = (mid + Math.imul(al8, bh8)) | 0;
+ mid = (mid + Math.imul(ah8, bl8)) | 0;
+ hi = (hi + Math.imul(ah8, bh8)) | 0;
+ lo = (lo + Math.imul(al7, bl9)) | 0;
+ mid = (mid + Math.imul(al7, bh9)) | 0;
+ mid = (mid + Math.imul(ah7, bl9)) | 0;
+ hi = (hi + Math.imul(ah7, bh9)) | 0;
+ var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
+ w16 &= 0x3ffffff;
+ /* k = 17 */
+ lo = Math.imul(al9, bl8);
+ mid = Math.imul(al9, bh8);
+ mid = (mid + Math.imul(ah9, bl8)) | 0;
+ hi = Math.imul(ah9, bh8);
+ lo = (lo + Math.imul(al8, bl9)) | 0;
+ mid = (mid + Math.imul(al8, bh9)) | 0;
+ mid = (mid + Math.imul(ah8, bl9)) | 0;
+ hi = (hi + Math.imul(ah8, bh9)) | 0;
+ var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
+ w17 &= 0x3ffffff;
+ /* k = 18 */
+ lo = Math.imul(al9, bl9);
+ mid = Math.imul(al9, bh9);
+ mid = (mid + Math.imul(ah9, bl9)) | 0;
+ hi = Math.imul(ah9, bh9);
+ var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
+ w18 &= 0x3ffffff;
+ o[0] = w0;
+ o[1] = w1;
+ o[2] = w2;
+ o[3] = w3;
+ o[4] = w4;
+ o[5] = w5;
+ o[6] = w6;
+ o[7] = w7;
+ o[8] = w8;
+ o[9] = w9;
+ o[10] = w10;
+ o[11] = w11;
+ o[12] = w12;
+ o[13] = w13;
+ o[14] = w14;
+ o[15] = w15;
+ o[16] = w16;
+ o[17] = w17;
+ o[18] = w18;
+ if (c !== 0) {
+ o[19] = c;
+ out.length++;
+ }
+ return out;
+ };
+
+ // Polyfill comb
+ if (!Math.imul) {
+ comb10MulTo = smallMulTo;
+ }
+
+ function bigMulTo (self, num, out) {
+ out.negative = num.negative ^ self.negative;
+ out.length = self.length + num.length;
+
+ var carry = 0;
+ var hncarry = 0;
+ for (var k = 0; k < out.length - 1; k++) {
+ // Sum all words with the same `i + j = k` and accumulate `ncarry`,
+ // note that ncarry could be >= 0x3ffffff
+ var ncarry = hncarry;
+ hncarry = 0;
+ var rword = carry & 0x3ffffff;
+ var maxJ = Math.min(k, num.length - 1);
+ for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
+ var i = k - j;
+ var a = self.words[i] | 0;
+ var b = num.words[j] | 0;
+ var r = a * b;
+
+ var lo = r & 0x3ffffff;
+ ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
+ lo = (lo + rword) | 0;
+ rword = lo & 0x3ffffff;
+ ncarry = (ncarry + (lo >>> 26)) | 0;
+
+ hncarry += ncarry >>> 26;
+ ncarry &= 0x3ffffff;
+ }
+ out.words[k] = rword;
+ carry = ncarry;
+ ncarry = hncarry;
+ }
+ if (carry !== 0) {
+ out.words[k] = carry;
+ } else {
+ out.length--;
+ }
+
+ return out.strip();
+ }
+
+ function jumboMulTo (self, num, out) {
+ var fftm = new FFTM();
+ return fftm.mulp(self, num, out);
+ }
+
+ BN.prototype.mulTo = function mulTo (num, out) {
+ var res;
+ var len = this.length + num.length;
+ if (this.length === 10 && num.length === 10) {
+ res = comb10MulTo(this, num, out);
+ } else if (len < 63) {
+ res = smallMulTo(this, num, out);
+ } else if (len < 1024) {
+ res = bigMulTo(this, num, out);
+ } else {
+ res = jumboMulTo(this, num, out);
+ }
+
+ return res;
+ };
+
+ // Cooley-Tukey algorithm for FFT
+ // slightly revisited to rely on looping instead of recursion
+
+ function FFTM (x, y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ FFTM.prototype.makeRBT = function makeRBT (N) {
+ var t = new Array(N);
+ var l = BN.prototype._countBits(N) - 1;
+ for (var i = 0; i < N; i++) {
+ t[i] = this.revBin(i, l, N);
+ }
+
+ return t;
+ };
+
+ // Returns binary-reversed representation of `x`
+ FFTM.prototype.revBin = function revBin (x, l, N) {
+ if (x === 0 || x === N - 1) return x;
+
+ var rb = 0;
+ for (var i = 0; i < l; i++) {
+ rb |= (x & 1) << (l - i - 1);
+ x >>= 1;
+ }
+
+ return rb;
+ };
+
+ // Performs "tweedling" phase, therefore 'emulating'
+ // behaviour of the recursive algorithm
+ FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
+ for (var i = 0; i < N; i++) {
+ rtws[i] = rws[rbt[i]];
+ itws[i] = iws[rbt[i]];
+ }
+ };
+
+ FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
+ this.permute(rbt, rws, iws, rtws, itws, N);
+
+ for (var s = 1; s < N; s <<= 1) {
+ var l = s << 1;
+
+ var rtwdf = Math.cos(2 * Math.PI / l);
+ var itwdf = Math.sin(2 * Math.PI / l);
+
+ for (var p = 0; p < N; p += l) {
+ var rtwdf_ = rtwdf;
+ var itwdf_ = itwdf;
+
+ for (var j = 0; j < s; j++) {
+ var re = rtws[p + j];
+ var ie = itws[p + j];
+
+ var ro = rtws[p + j + s];
+ var io = itws[p + j + s];
+
+ var rx = rtwdf_ * ro - itwdf_ * io;
+
+ io = rtwdf_ * io + itwdf_ * ro;
+ ro = rx;
+
+ rtws[p + j] = re + ro;
+ itws[p + j] = ie + io;
+
+ rtws[p + j + s] = re - ro;
+ itws[p + j + s] = ie - io;
+
+ /* jshint maxdepth : false */
+ if (j !== l) {
+ rx = rtwdf * rtwdf_ - itwdf * itwdf_;
+
+ itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
+ rtwdf_ = rx;
+ }
+ }
+ }
+ }
+ };
+
+ FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
+ var N = Math.max(m, n) | 1;
+ var odd = N & 1;
+ var i = 0;
+ for (N = N / 2 | 0; N; N = N >>> 1) {
+ i++;
+ }
+
+ return 1 << i + 1 + odd;
+ };
+
+ FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
+ if (N <= 1) return;
+
+ for (var i = 0; i < N / 2; i++) {
+ var t = rws[i];
+
+ rws[i] = rws[N - i - 1];
+ rws[N - i - 1] = t;
+
+ t = iws[i];
+
+ iws[i] = -iws[N - i - 1];
+ iws[N - i - 1] = -t;
+ }
+ };
+
+ FFTM.prototype.normalize13b = function normalize13b (ws, N) {
+ var carry = 0;
+ for (var i = 0; i < N / 2; i++) {
+ var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
+ Math.round(ws[2 * i] / N) +
+ carry;
+
+ ws[i] = w & 0x3ffffff;
+
+ if (w < 0x4000000) {
+ carry = 0;
+ } else {
+ carry = w / 0x4000000 | 0;
+ }
+ }
+
+ return ws;
+ };
+
+ FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
+ var carry = 0;
+ for (var i = 0; i < len; i++) {
+ carry = carry + (ws[i] | 0);
+
+ rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
+ rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
+ }
+
+ // Pad with zeroes
+ for (i = 2 * len; i < N; ++i) {
+ rws[i] = 0;
+ }
+
+ assert(carry === 0);
+ assert((carry & ~0x1fff) === 0);
+ };
+
+ FFTM.prototype.stub = function stub (N) {
+ var ph = new Array(N);
+ for (var i = 0; i < N; i++) {
+ ph[i] = 0;
+ }
+
+ return ph;
+ };
+
+ FFTM.prototype.mulp = function mulp (x, y, out) {
+ var N = 2 * this.guessLen13b(x.length, y.length);
+
+ var rbt = this.makeRBT(N);
+
+ var _ = this.stub(N);
+
+ var rws = new Array(N);
+ var rwst = new Array(N);
+ var iwst = new Array(N);
+
+ var nrws = new Array(N);
+ var nrwst = new Array(N);
+ var niwst = new Array(N);
+
+ var rmws = out.words;
+ rmws.length = N;
+
+ this.convert13b(x.words, x.length, rws, N);
+ this.convert13b(y.words, y.length, nrws, N);
+
+ this.transform(rws, _, rwst, iwst, N, rbt);
+ this.transform(nrws, _, nrwst, niwst, N, rbt);
+
+ for (var i = 0; i < N; i++) {
+ var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
+ iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
+ rwst[i] = rx;
+ }
+
+ this.conjugate(rwst, iwst, N);
+ this.transform(rwst, iwst, rmws, _, N, rbt);
+ this.conjugate(rmws, _, N);
+ this.normalize13b(rmws, N);
+
+ out.negative = x.negative ^ y.negative;
+ out.length = x.length + y.length;
+ return out.strip();
+ };
+
+ // Multiply `this` by `num`
+ BN.prototype.mul = function mul (num) {
+ var out = new BN(null);
+ out.words = new Array(this.length + num.length);
+ return this.mulTo(num, out);
+ };
+
+ // Multiply employing FFT
+ BN.prototype.mulf = function mulf (num) {
+ var out = new BN(null);
+ out.words = new Array(this.length + num.length);
+ return jumboMulTo(this, num, out);
+ };
+
+ // In-place Multiplication
+ BN.prototype.imul = function imul (num) {
+ return this.clone().mulTo(num, this);
+ };
+
+ BN.prototype.imuln = function imuln (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+
+ // Carry
+ var carry = 0;
+ for (var i = 0; i < this.length; i++) {
+ var w = (this.words[i] | 0) * num;
+ var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
+ carry >>= 26;
+ carry += (w / 0x4000000) | 0;
+ // NOTE: lo is 27bit maximum
+ carry += lo >>> 26;
+ this.words[i] = lo & 0x3ffffff;
+ }
+
+ if (carry !== 0) {
+ this.words[i] = carry;
+ this.length++;
+ }
+
+ return this;
+ };
+
+ BN.prototype.muln = function muln (num) {
+ return this.clone().imuln(num);
+ };
+
+ // `this` * `this`
+ BN.prototype.sqr = function sqr () {
+ return this.mul(this);
+ };
+
+ // `this` * `this` in-place
+ BN.prototype.isqr = function isqr () {
+ return this.imul(this.clone());
+ };
+
+ // Math.pow(`this`, `num`)
+ BN.prototype.pow = function pow (num) {
+ var w = toBitArray(num);
+ if (w.length === 0) return new BN(1);
+
+ // Skip leading zeroes
+ var res = this;
+ for (var i = 0; i < w.length; i++, res = res.sqr()) {
+ if (w[i] !== 0) break;
+ }
+
+ if (++i < w.length) {
+ for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
+ if (w[i] === 0) continue;
+
+ res = res.mul(q);
+ }
+ }
+
+ return res;
+ };
+
+ // Shift-left in-place
+ BN.prototype.iushln = function iushln (bits) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var r = bits % 26;
+ var s = (bits - r) / 26;
+ var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
+ var i;
+
+ if (r !== 0) {
+ var carry = 0;
+
+ for (i = 0; i < this.length; i++) {
+ var newCarry = this.words[i] & carryMask;
+ var c = ((this.words[i] | 0) - newCarry) << r;
+ this.words[i] = c | carry;
+ carry = newCarry >>> (26 - r);
+ }
+
+ if (carry) {
+ this.words[i] = carry;
+ this.length++;
+ }
+ }
+
+ if (s !== 0) {
+ for (i = this.length - 1; i >= 0; i--) {
+ this.words[i + s] = this.words[i];
+ }
+
+ for (i = 0; i < s; i++) {
+ this.words[i] = 0;
+ }
+
+ this.length += s;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ishln = function ishln (bits) {
+ // TODO(indutny): implement me
+ assert(this.negative === 0);
+ return this.iushln(bits);
+ };
+
+ // Shift-right in-place
+ // NOTE: `hint` is a lowest bit before trailing zeroes
+ // NOTE: if `extended` is present - it will be filled with destroyed bits
+ BN.prototype.iushrn = function iushrn (bits, hint, extended) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var h;
+ if (hint) {
+ h = (hint - (hint % 26)) / 26;
+ } else {
+ h = 0;
+ }
+
+ var r = bits % 26;
+ var s = Math.min((bits - r) / 26, this.length);
+ var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
+ var maskedWords = extended;
+
+ h -= s;
+ h = Math.max(0, h);
+
+ // Extended mode, copy masked part
+ if (maskedWords) {
+ for (var i = 0; i < s; i++) {
+ maskedWords.words[i] = this.words[i];
+ }
+ maskedWords.length = s;
+ }
+
+ if (s === 0) {
+ // No-op, we should not move anything at all
+ } else if (this.length > s) {
+ this.length -= s;
+ for (i = 0; i < this.length; i++) {
+ this.words[i] = this.words[i + s];
+ }
+ } else {
+ this.words[0] = 0;
+ this.length = 1;
+ }
+
+ var carry = 0;
+ for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
+ var word = this.words[i] | 0;
+ this.words[i] = (carry << (26 - r)) | (word >>> r);
+ carry = word & mask;
+ }
+
+ // Push carried bits as a mask
+ if (maskedWords && carry !== 0) {
+ maskedWords.words[maskedWords.length++] = carry;
+ }
+
+ if (this.length === 0) {
+ this.words[0] = 0;
+ this.length = 1;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ishrn = function ishrn (bits, hint, extended) {
+ // TODO(indutny): implement me
+ assert(this.negative === 0);
+ return this.iushrn(bits, hint, extended);
+ };
+
+ // Shift-left
+ BN.prototype.shln = function shln (bits) {
+ return this.clone().ishln(bits);
+ };
+
+ BN.prototype.ushln = function ushln (bits) {
+ return this.clone().iushln(bits);
+ };
+
+ // Shift-right
+ BN.prototype.shrn = function shrn (bits) {
+ return this.clone().ishrn(bits);
+ };
+
+ BN.prototype.ushrn = function ushrn (bits) {
+ return this.clone().iushrn(bits);
+ };
+
+ // Test if n bit is set
+ BN.prototype.testn = function testn (bit) {
+ assert(typeof bit === 'number' && bit >= 0);
+ var r = bit % 26;
+ var s = (bit - r) / 26;
+ var q = 1 << r;
+
+ // Fast case: bit is much higher than all existing words
+ if (this.length <= s) return false;
+
+ // Check bit and return
+ var w = this.words[s];
+
+ return !!(w & q);
+ };
+
+ // Return only lowers bits of number (in-place)
+ BN.prototype.imaskn = function imaskn (bits) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var r = bits % 26;
+ var s = (bits - r) / 26;
+
+ assert(this.negative === 0, 'imaskn works only with positive numbers');
+
+ if (this.length <= s) {
+ return this;
+ }
+
+ if (r !== 0) {
+ s++;
+ }
+ this.length = Math.min(s, this.length);
+
+ if (r !== 0) {
+ var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
+ this.words[this.length - 1] &= mask;
+ }
+
+ return this.strip();
+ };
+
+ // Return only lowers bits of number
+ BN.prototype.maskn = function maskn (bits) {
+ return this.clone().imaskn(bits);
+ };
+
+ // Add plain number `num` to `this`
+ BN.prototype.iaddn = function iaddn (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+ if (num < 0) return this.isubn(-num);
+
+ // Possible sign change
+ if (this.negative !== 0) {
+ if (this.length === 1 && (this.words[0] | 0) < num) {
+ this.words[0] = num - (this.words[0] | 0);
+ this.negative = 0;
+ return this;
+ }
+
+ this.negative = 0;
+ this.isubn(num);
+ this.negative = 1;
+ return this;
+ }
+
+ // Add without checks
+ return this._iaddn(num);
+ };
+
+ BN.prototype._iaddn = function _iaddn (num) {
+ this.words[0] += num;
+
+ // Carry
+ for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
+ this.words[i] -= 0x4000000;
+ if (i === this.length - 1) {
+ this.words[i + 1] = 1;
+ } else {
+ this.words[i + 1]++;
+ }
+ }
+ this.length = Math.max(this.length, i + 1);
+
+ return this;
+ };
+
+ // Subtract plain number `num` from `this`
+ BN.prototype.isubn = function isubn (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+ if (num < 0) return this.iaddn(-num);
+
+ if (this.negative !== 0) {
+ this.negative = 0;
+ this.iaddn(num);
+ this.negative = 1;
+ return this;
+ }
+
+ this.words[0] -= num;
+
+ if (this.length === 1 && this.words[0] < 0) {
+ this.words[0] = -this.words[0];
+ this.negative = 1;
+ } else {
+ // Carry
+ for (var i = 0; i < this.length && this.words[i] < 0; i++) {
+ this.words[i] += 0x4000000;
+ this.words[i + 1] -= 1;
+ }
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.addn = function addn (num) {
+ return this.clone().iaddn(num);
+ };
+
+ BN.prototype.subn = function subn (num) {
+ return this.clone().isubn(num);
+ };
+
+ BN.prototype.iabs = function iabs () {
+ this.negative = 0;
+
+ return this;
+ };
+
+ BN.prototype.abs = function abs () {
+ return this.clone().iabs();
+ };
+
+ BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
+ var len = num.length + shift;
+ var i;
+
+ this._expand(len);
+
+ var w;
+ var carry = 0;
+ for (i = 0; i < num.length; i++) {
+ w = (this.words[i + shift] | 0) + carry;
+ var right = (num.words[i] | 0) * mul;
+ w -= right & 0x3ffffff;
+ carry = (w >> 26) - ((right / 0x4000000) | 0);
+ this.words[i + shift] = w & 0x3ffffff;
+ }
+ for (; i < this.length - shift; i++) {
+ w = (this.words[i + shift] | 0) + carry;
+ carry = w >> 26;
+ this.words[i + shift] = w & 0x3ffffff;
+ }
+
+ if (carry === 0) return this.strip();
+
+ // Subtraction overflow
+ assert(carry === -1);
+ carry = 0;
+ for (i = 0; i < this.length; i++) {
+ w = -(this.words[i] | 0) + carry;
+ carry = w >> 26;
+ this.words[i] = w & 0x3ffffff;
+ }
+ this.negative = 1;
+
+ return this.strip();
+ };
+
+ BN.prototype._wordDiv = function _wordDiv (num, mode) {
+ var shift = this.length - num.length;
+
+ var a = this.clone();
+ var b = num;
+
+ // Normalize
+ var bhi = b.words[b.length - 1] | 0;
+ var bhiBits = this._countBits(bhi);
+ shift = 26 - bhiBits;
+ if (shift !== 0) {
+ b = b.ushln(shift);
+ a.iushln(shift);
+ bhi = b.words[b.length - 1] | 0;
+ }
+
+ // Initialize quotient
+ var m = a.length - b.length;
+ var q;
+
+ if (mode !== 'mod') {
+ q = new BN(null);
+ q.length = m + 1;
+ q.words = new Array(q.length);
+ for (var i = 0; i < q.length; i++) {
+ q.words[i] = 0;
+ }
+ }
+
+ var diff = a.clone()._ishlnsubmul(b, 1, m);
+ if (diff.negative === 0) {
+ a = diff;
+ if (q) {
+ q.words[m] = 1;
+ }
+ }
+
+ for (var j = m - 1; j >= 0; j--) {
+ var qj = (a.words[b.length + j] | 0) * 0x4000000 +
+ (a.words[b.length + j - 1] | 0);
+
+ // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
+ // (0x7ffffff)
+ qj = Math.min((qj / bhi) | 0, 0x3ffffff);
+
+ a._ishlnsubmul(b, qj, j);
+ while (a.negative !== 0) {
+ qj--;
+ a.negative = 0;
+ a._ishlnsubmul(b, 1, j);
+ if (!a.isZero()) {
+ a.negative ^= 1;
+ }
+ }
+ if (q) {
+ q.words[j] = qj;
+ }
+ }
+ if (q) {
+ q.strip();
+ }
+ a.strip();
+
+ // Denormalize
+ if (mode !== 'div' && shift !== 0) {
+ a.iushrn(shift);
+ }
+
+ return {
+ div: q || null,
+ mod: a
+ };
+ };
+
+ // NOTE: 1) `mode` can be set to `mod` to request mod only,
+ // to `div` to request div only, or be absent to
+ // request both div & mod
+ // 2) `positive` is true if unsigned mod is requested
+ BN.prototype.divmod = function divmod (num, mode, positive) {
+ assert(!num.isZero());
+
+ if (this.isZero()) {
+ return {
+ div: new BN(0),
+ mod: new BN(0)
+ };
+ }
+
+ var div, mod, res;
+ if (this.negative !== 0 && num.negative === 0) {
+ res = this.neg().divmod(num, mode);
+
+ if (mode !== 'mod') {
+ div = res.div.neg();
+ }
+
+ if (mode !== 'div') {
+ mod = res.mod.neg();
+ if (positive && mod.negative !== 0) {
+ mod.iadd(num);
+ }
+ }
+
+ return {
+ div: div,
+ mod: mod
+ };
+ }
+
+ if (this.negative === 0 && num.negative !== 0) {
+ res = this.divmod(num.neg(), mode);
+
+ if (mode !== 'mod') {
+ div = res.div.neg();
+ }
+
+ return {
+ div: div,
+ mod: res.mod
+ };
+ }
+
+ if ((this.negative & num.negative) !== 0) {
+ res = this.neg().divmod(num.neg(), mode);
+
+ if (mode !== 'div') {
+ mod = res.mod.neg();
+ if (positive && mod.negative !== 0) {
+ mod.isub(num);
+ }
+ }
+
+ return {
+ div: res.div,
+ mod: mod
+ };
+ }
+
+ // Both numbers are positive at this point
+
+ // Strip both numbers to approximate shift value
+ if (num.length > this.length || this.cmp(num) < 0) {
+ return {
+ div: new BN(0),
+ mod: this
+ };
+ }
+
+ // Very short reduction
+ if (num.length === 1) {
+ if (mode === 'div') {
+ return {
+ div: this.divn(num.words[0]),
+ mod: null
+ };
+ }
+
+ if (mode === 'mod') {
+ return {
+ div: null,
+ mod: new BN(this.modn(num.words[0]))
+ };
+ }
+
+ return {
+ div: this.divn(num.words[0]),
+ mod: new BN(this.modn(num.words[0]))
+ };
+ }
+
+ return this._wordDiv(num, mode);
+ };
+
+ // Find `this` / `num`
+ BN.prototype.div = function div (num) {
+ return this.divmod(num, 'div', false).div;
+ };
+
+ // Find `this` % `num`
+ BN.prototype.mod = function mod (num) {
+ return this.divmod(num, 'mod', false).mod;
+ };
+
+ BN.prototype.umod = function umod (num) {
+ return this.divmod(num, 'mod', true).mod;
+ };
+
+ // Find Round(`this` / `num`)
+ BN.prototype.divRound = function divRound (num) {
+ var dm = this.divmod(num);
+
+ // Fast case - exact division
+ if (dm.mod.isZero()) return dm.div;
+
+ var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
+
+ var half = num.ushrn(1);
+ var r2 = num.andln(1);
+ var cmp = mod.cmp(half);
+
+ // Round down
+ if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
+
+ // Round up
+ return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
+ };
+
+ BN.prototype.modn = function modn (num) {
+ assert(num <= 0x3ffffff);
+ var p = (1 << 26) % num;
+
+ var acc = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ acc = (p * acc + (this.words[i] | 0)) % num;
+ }
+
+ return acc;
+ };
+
+ // In-place division by number
+ BN.prototype.idivn = function idivn (num) {
+ assert(num <= 0x3ffffff);
+
+ var carry = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ var w = (this.words[i] | 0) + carry * 0x4000000;
+ this.words[i] = (w / num) | 0;
+ carry = w % num;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.divn = function divn (num) {
+ return this.clone().idivn(num);
+ };
+
+ BN.prototype.egcd = function egcd (p) {
+ assert(p.negative === 0);
+ assert(!p.isZero());
+
+ var x = this;
+ var y = p.clone();
+
+ if (x.negative !== 0) {
+ x = x.umod(p);
+ } else {
+ x = x.clone();
+ }
+
+ // A * x + B * y = x
+ var A = new BN(1);
+ var B = new BN(0);
+
+ // C * x + D * y = y
+ var C = new BN(0);
+ var D = new BN(1);
+
+ var g = 0;
+
+ while (x.isEven() && y.isEven()) {
+ x.iushrn(1);
+ y.iushrn(1);
+ ++g;
+ }
+
+ var yp = y.clone();
+ var xp = x.clone();
+
+ while (!x.isZero()) {
+ for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
+ if (i > 0) {
+ x.iushrn(i);
+ while (i-- > 0) {
+ if (A.isOdd() || B.isOdd()) {
+ A.iadd(yp);
+ B.isub(xp);
+ }
+
+ A.iushrn(1);
+ B.iushrn(1);
+ }
+ }
+
+ for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
+ if (j > 0) {
+ y.iushrn(j);
+ while (j-- > 0) {
+ if (C.isOdd() || D.isOdd()) {
+ C.iadd(yp);
+ D.isub(xp);
+ }
+
+ C.iushrn(1);
+ D.iushrn(1);
+ }
+ }
+
+ if (x.cmp(y) >= 0) {
+ x.isub(y);
+ A.isub(C);
+ B.isub(D);
+ } else {
+ y.isub(x);
+ C.isub(A);
+ D.isub(B);
+ }
+ }
+
+ return {
+ a: C,
+ b: D,
+ gcd: y.iushln(g)
+ };
+ };
+
+ // This is reduced incarnation of the binary EEA
+ // above, designated to invert members of the
+ // _prime_ fields F(p) at a maximal speed
+ BN.prototype._invmp = function _invmp (p) {
+ assert(p.negative === 0);
+ assert(!p.isZero());
+
+ var a = this;
+ var b = p.clone();
+
+ if (a.negative !== 0) {
+ a = a.umod(p);
+ } else {
+ a = a.clone();
+ }
+
+ var x1 = new BN(1);
+ var x2 = new BN(0);
+
+ var delta = b.clone();
+
+ while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
+ for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
+ if (i > 0) {
+ a.iushrn(i);
+ while (i-- > 0) {
+ if (x1.isOdd()) {
+ x1.iadd(delta);
+ }
+
+ x1.iushrn(1);
+ }
+ }
+
+ for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
+ if (j > 0) {
+ b.iushrn(j);
+ while (j-- > 0) {
+ if (x2.isOdd()) {
+ x2.iadd(delta);
+ }
+
+ x2.iushrn(1);
+ }
+ }
+
+ if (a.cmp(b) >= 0) {
+ a.isub(b);
+ x1.isub(x2);
+ } else {
+ b.isub(a);
+ x2.isub(x1);
+ }
+ }
+
+ var res;
+ if (a.cmpn(1) === 0) {
+ res = x1;
+ } else {
+ res = x2;
+ }
+
+ if (res.cmpn(0) < 0) {
+ res.iadd(p);
+ }
+
+ return res;
+ };
+
+ BN.prototype.gcd = function gcd (num) {
+ if (this.isZero()) return num.abs();
+ if (num.isZero()) return this.abs();
+
+ var a = this.clone();
+ var b = num.clone();
+ a.negative = 0;
+ b.negative = 0;
+
+ // Remove common factor of two
+ for (var shift = 0; a.isEven() && b.isEven(); shift++) {
+ a.iushrn(1);
+ b.iushrn(1);
+ }
+
+ do {
+ while (a.isEven()) {
+ a.iushrn(1);
+ }
+ while (b.isEven()) {
+ b.iushrn(1);
+ }
+
+ var r = a.cmp(b);
+ if (r < 0) {
+ // Swap `a` and `b` to make `a` always bigger than `b`
+ var t = a;
+ a = b;
+ b = t;
+ } else if (r === 0 || b.cmpn(1) === 0) {
+ break;
+ }
+
+ a.isub(b);
+ } while (true);
+
+ return b.iushln(shift);
+ };
+
+ // Invert number in the field F(num)
+ BN.prototype.invm = function invm (num) {
+ return this.egcd(num).a.umod(num);
+ };
+
+ BN.prototype.isEven = function isEven () {
+ return (this.words[0] & 1) === 0;
+ };
+
+ BN.prototype.isOdd = function isOdd () {
+ return (this.words[0] & 1) === 1;
+ };
+
+ // And first word and num
+ BN.prototype.andln = function andln (num) {
+ return this.words[0] & num;
+ };
+
+ // Increment at the bit position in-line
+ BN.prototype.bincn = function bincn (bit) {
+ assert(typeof bit === 'number');
+ var r = bit % 26;
+ var s = (bit - r) / 26;
+ var q = 1 << r;
+
+ // Fast case: bit is much higher than all existing words
+ if (this.length <= s) {
+ this._expand(s + 1);
+ this.words[s] |= q;
+ return this;
+ }
+
+ // Add bit and propagate, if needed
+ var carry = q;
+ for (var i = s; carry !== 0 && i < this.length; i++) {
+ var w = this.words[i] | 0;
+ w += carry;
+ carry = w >>> 26;
+ w &= 0x3ffffff;
+ this.words[i] = w;
+ }
+ if (carry !== 0) {
+ this.words[i] = carry;
+ this.length++;
+ }
+ return this;
+ };
+
+ BN.prototype.isZero = function isZero () {
+ return this.length === 1 && this.words[0] === 0;
+ };
+
+ BN.prototype.cmpn = function cmpn (num) {
+ var negative = num < 0;
+
+ if (this.negative !== 0 && !negative) return -1;
+ if (this.negative === 0 && negative) return 1;
+
+ this.strip();
+
+ var res;
+ if (this.length > 1) {
+ res = 1;
+ } else {
+ if (negative) {
+ num = -num;
+ }
+
+ assert(num <= 0x3ffffff, 'Number is too big');
+
+ var w = this.words[0] | 0;
+ res = w === num ? 0 : w < num ? -1 : 1;
+ }
+ if (this.negative !== 0) return -res | 0;
+ return res;
+ };
+
+ // Compare two numbers and return:
+ // 1 - if `this` > `num`
+ // 0 - if `this` == `num`
+ // -1 - if `this` < `num`
+ BN.prototype.cmp = function cmp (num) {
+ if (this.negative !== 0 && num.negative === 0) return -1;
+ if (this.negative === 0 && num.negative !== 0) return 1;
+
+ var res = this.ucmp(num);
+ if (this.negative !== 0) return -res | 0;
+ return res;
+ };
+
+ // Unsigned comparison
+ BN.prototype.ucmp = function ucmp (num) {
+ // At this point both numbers have the same sign
+ if (this.length > num.length) return 1;
+ if (this.length < num.length) return -1;
+
+ var res = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ var a = this.words[i] | 0;
+ var b = num.words[i] | 0;
+
+ if (a === b) continue;
+ if (a < b) {
+ res = -1;
+ } else if (a > b) {
+ res = 1;
+ }
+ break;
+ }
+ return res;
+ };
+
+ BN.prototype.gtn = function gtn (num) {
+ return this.cmpn(num) === 1;
+ };
+
+ BN.prototype.gt = function gt (num) {
+ return this.cmp(num) === 1;
+ };
+
+ BN.prototype.gten = function gten (num) {
+ return this.cmpn(num) >= 0;
+ };
+
+ BN.prototype.gte = function gte (num) {
+ return this.cmp(num) >= 0;
+ };
+
+ BN.prototype.ltn = function ltn (num) {
+ return this.cmpn(num) === -1;
+ };
+
+ BN.prototype.lt = function lt (num) {
+ return this.cmp(num) === -1;
+ };
+
+ BN.prototype.lten = function lten (num) {
+ return this.cmpn(num) <= 0;
+ };
+
+ BN.prototype.lte = function lte (num) {
+ return this.cmp(num) <= 0;
+ };
+
+ BN.prototype.eqn = function eqn (num) {
+ return this.cmpn(num) === 0;
+ };
+
+ BN.prototype.eq = function eq (num) {
+ return this.cmp(num) === 0;
+ };
+
+ //
+ // A reduce context, could be using montgomery or something better, depending
+ // on the `m` itself.
+ //
+ BN.red = function red (num) {
+ return new Red(num);
+ };
+
+ BN.prototype.toRed = function toRed (ctx) {
+ assert(!this.red, 'Already a number in reduction context');
+ assert(this.negative === 0, 'red works only with positives');
+ return ctx.convertTo(this)._forceRed(ctx);
+ };
+
+ BN.prototype.fromRed = function fromRed () {
+ assert(this.red, 'fromRed works only with numbers in reduction context');
+ return this.red.convertFrom(this);
+ };
+
+ BN.prototype._forceRed = function _forceRed (ctx) {
+ this.red = ctx;
+ return this;
+ };
+
+ BN.prototype.forceRed = function forceRed (ctx) {
+ assert(!this.red, 'Already a number in reduction context');
+ return this._forceRed(ctx);
+ };
+
+ BN.prototype.redAdd = function redAdd (num) {
+ assert(this.red, 'redAdd works only with red numbers');
+ return this.red.add(this, num);
+ };
+
+ BN.prototype.redIAdd = function redIAdd (num) {
+ assert(this.red, 'redIAdd works only with red numbers');
+ return this.red.iadd(this, num);
+ };
+
+ BN.prototype.redSub = function redSub (num) {
+ assert(this.red, 'redSub works only with red numbers');
+ return this.red.sub(this, num);
+ };
+
+ BN.prototype.redISub = function redISub (num) {
+ assert(this.red, 'redISub works only with red numbers');
+ return this.red.isub(this, num);
+ };
+
+ BN.prototype.redShl = function redShl (num) {
+ assert(this.red, 'redShl works only with red numbers');
+ return this.red.shl(this, num);
+ };
+
+ BN.prototype.redMul = function redMul (num) {
+ assert(this.red, 'redMul works only with red numbers');
+ this.red._verify2(this, num);
+ return this.red.mul(this, num);
+ };
+
+ BN.prototype.redIMul = function redIMul (num) {
+ assert(this.red, 'redMul works only with red numbers');
+ this.red._verify2(this, num);
+ return this.red.imul(this, num);
+ };
+
+ BN.prototype.redSqr = function redSqr () {
+ assert(this.red, 'redSqr works only with red numbers');
+ this.red._verify1(this);
+ return this.red.sqr(this);
+ };
+
+ BN.prototype.redISqr = function redISqr () {
+ assert(this.red, 'redISqr works only with red numbers');
+ this.red._verify1(this);
+ return this.red.isqr(this);
+ };
+
+ // Square root over p
+ BN.prototype.redSqrt = function redSqrt () {
+ assert(this.red, 'redSqrt works only with red numbers');
+ this.red._verify1(this);
+ return this.red.sqrt(this);
+ };
+
+ BN.prototype.redInvm = function redInvm () {
+ assert(this.red, 'redInvm works only with red numbers');
+ this.red._verify1(this);
+ return this.red.invm(this);
+ };
+
+ // Return negative clone of `this` % `red modulo`
+ BN.prototype.redNeg = function redNeg () {
+ assert(this.red, 'redNeg works only with red numbers');
+ this.red._verify1(this);
+ return this.red.neg(this);
+ };
+
+ BN.prototype.redPow = function redPow (num) {
+ assert(this.red && !num.red, 'redPow(normalNum)');
+ this.red._verify1(this);
+ return this.red.pow(this, num);
+ };
+
+ // Prime numbers with efficient reduction
+ var primes = {
+ k256: null,
+ p224: null,
+ p192: null,
+ p25519: null
+ };
+
+ // Pseudo-Mersenne prime
+ function MPrime (name, p) {
+ // P = 2 ^ N - K
+ this.name = name;
+ this.p = new BN(p, 16);
+ this.n = this.p.bitLength();
+ this.k = new BN(1).iushln(this.n).isub(this.p);
+
+ this.tmp = this._tmp();
+ }
+
+ MPrime.prototype._tmp = function _tmp () {
+ var tmp = new BN(null);
+ tmp.words = new Array(Math.ceil(this.n / 13));
+ return tmp;
+ };
+
+ MPrime.prototype.ireduce = function ireduce (num) {
+ // Assumes that `num` is less than `P^2`
+ // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
+ var r = num;
+ var rlen;
+
+ do {
+ this.split(r, this.tmp);
+ r = this.imulK(r);
+ r = r.iadd(this.tmp);
+ rlen = r.bitLength();
+ } while (rlen > this.n);
+
+ var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
+ if (cmp === 0) {
+ r.words[0] = 0;
+ r.length = 1;
+ } else if (cmp > 0) {
+ r.isub(this.p);
+ } else {
+ r.strip();
+ }
+
+ return r;
+ };
+
+ MPrime.prototype.split = function split (input, out) {
+ input.iushrn(this.n, 0, out);
+ };
+
+ MPrime.prototype.imulK = function imulK (num) {
+ return num.imul(this.k);
+ };
+
+ function K256 () {
+ MPrime.call(
+ this,
+ 'k256',
+ 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
+ }
+ inherits(K256, MPrime);
+
+ K256.prototype.split = function split (input, output) {
+ // 256 = 9 * 26 + 22
+ var mask = 0x3fffff;
+
+ var outLen = Math.min(input.length, 9);
+ for (var i = 0; i < outLen; i++) {
+ output.words[i] = input.words[i];
+ }
+ output.length = outLen;
+
+ if (input.length <= 9) {
+ input.words[0] = 0;
+ input.length = 1;
+ return;
+ }
+
+ // Shift by 9 limbs
+ var prev = input.words[9];
+ output.words[output.length++] = prev & mask;
+
+ for (i = 10; i < input.length; i++) {
+ var next = input.words[i] | 0;
+ input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
+ prev = next;
+ }
+ prev >>>= 22;
+ input.words[i - 10] = prev;
+ if (prev === 0 && input.length > 10) {
+ input.length -= 10;
+ } else {
+ input.length -= 9;
+ }
+ };
+
+ K256.prototype.imulK = function imulK (num) {
+ // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
+ num.words[num.length] = 0;
+ num.words[num.length + 1] = 0;
+ num.length += 2;
+
+ // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
+ var lo = 0;
+ for (var i = 0; i < num.length; i++) {
+ var w = num.words[i] | 0;
+ lo += w * 0x3d1;
+ num.words[i] = lo & 0x3ffffff;
+ lo = w * 0x40 + ((lo / 0x4000000) | 0);
+ }
+
+ // Fast length reduction
+ if (num.words[num.length - 1] === 0) {
+ num.length--;
+ if (num.words[num.length - 1] === 0) {
+ num.length--;
+ }
+ }
+ return num;
+ };
+
+ function P224 () {
+ MPrime.call(
+ this,
+ 'p224',
+ 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
+ }
+ inherits(P224, MPrime);
+
+ function P192 () {
+ MPrime.call(
+ this,
+ 'p192',
+ 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
+ }
+ inherits(P192, MPrime);
+
+ function P25519 () {
+ // 2 ^ 255 - 19
+ MPrime.call(
+ this,
+ '25519',
+ '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
+ }
+ inherits(P25519, MPrime);
+
+ P25519.prototype.imulK = function imulK (num) {
+ // K = 0x13
+ var carry = 0;
+ for (var i = 0; i < num.length; i++) {
+ var hi = (num.words[i] | 0) * 0x13 + carry;
+ var lo = hi & 0x3ffffff;
+ hi >>>= 26;
+
+ num.words[i] = lo;
+ carry = hi;
+ }
+ if (carry !== 0) {
+ num.words[num.length++] = carry;
+ }
+ return num;
+ };
+
+ // Exported mostly for testing purposes, use plain name instead
+ BN._prime = function prime (name) {
+ // Cached version of prime
+ if (primes[name]) return primes[name];
+
+ var prime;
+ if (name === 'k256') {
+ prime = new K256();
+ } else if (name === 'p224') {
+ prime = new P224();
+ } else if (name === 'p192') {
+ prime = new P192();
+ } else if (name === 'p25519') {
+ prime = new P25519();
+ } else {
+ throw new Error('Unknown prime ' + name);
+ }
+ primes[name] = prime;
+
+ return prime;
+ };
+
+ //
+ // Base reduction engine
+ //
+ function Red (m) {
+ if (typeof m === 'string') {
+ var prime = BN._prime(m);
+ this.m = prime.p;
+ this.prime = prime;
+ } else {
+ assert(m.gtn(1), 'modulus must be greater than 1');
+ this.m = m;
+ this.prime = null;
+ }
+ }
+
+ Red.prototype._verify1 = function _verify1 (a) {
+ assert(a.negative === 0, 'red works only with positives');
+ assert(a.red, 'red works only with red numbers');
+ };
+
+ Red.prototype._verify2 = function _verify2 (a, b) {
+ assert((a.negative | b.negative) === 0, 'red works only with positives');
+ assert(a.red && a.red === b.red,
+ 'red works only with red numbers');
+ };
+
+ Red.prototype.imod = function imod (a) {
+ if (this.prime) return this.prime.ireduce(a)._forceRed(this);
+ return a.umod(this.m)._forceRed(this);
+ };
+
+ Red.prototype.neg = function neg (a) {
+ if (a.isZero()) {
+ return a.clone();
+ }
+
+ return this.m.sub(a)._forceRed(this);
+ };
+
+ Red.prototype.add = function add (a, b) {
+ this._verify2(a, b);
+
+ var res = a.add(b);
+ if (res.cmp(this.m) >= 0) {
+ res.isub(this.m);
+ }
+ return res._forceRed(this);
+ };
+
+ Red.prototype.iadd = function iadd (a, b) {
+ this._verify2(a, b);
+
+ var res = a.iadd(b);
+ if (res.cmp(this.m) >= 0) {
+ res.isub(this.m);
+ }
+ return res;
+ };
+
+ Red.prototype.sub = function sub (a, b) {
+ this._verify2(a, b);
+
+ var res = a.sub(b);
+ if (res.cmpn(0) < 0) {
+ res.iadd(this.m);
+ }
+ return res._forceRed(this);
+ };
+
+ Red.prototype.isub = function isub (a, b) {
+ this._verify2(a, b);
+
+ var res = a.isub(b);
+ if (res.cmpn(0) < 0) {
+ res.iadd(this.m);
+ }
+ return res;
+ };
+
+ Red.prototype.shl = function shl (a, num) {
+ this._verify1(a);
+ return this.imod(a.ushln(num));
+ };
+
+ Red.prototype.imul = function imul (a, b) {
+ this._verify2(a, b);
+ return this.imod(a.imul(b));
+ };
+
+ Red.prototype.mul = function mul (a, b) {
+ this._verify2(a, b);
+ return this.imod(a.mul(b));
+ };
+
+ Red.prototype.isqr = function isqr (a) {
+ return this.imul(a, a.clone());
+ };
+
+ Red.prototype.sqr = function sqr (a) {
+ return this.mul(a, a);
+ };
+
+ Red.prototype.sqrt = function sqrt (a) {
+ if (a.isZero()) return a.clone();
+
+ var mod3 = this.m.andln(3);
+ assert(mod3 % 2 === 1);
+
+ // Fast case
+ if (mod3 === 3) {
+ var pow = this.m.add(new BN(1)).iushrn(2);
+ return this.pow(a, pow);
+ }
+
+ // Tonelli-Shanks algorithm (Totally unoptimized and slow)
+ //
+ // Find Q and S, that Q * 2 ^ S = (P - 1)
+ var q = this.m.subn(1);
+ var s = 0;
+ while (!q.isZero() && q.andln(1) === 0) {
+ s++;
+ q.iushrn(1);
+ }
+ assert(!q.isZero());
+
+ var one = new BN(1).toRed(this);
+ var nOne = one.redNeg();
+
+ // Find quadratic non-residue
+ // NOTE: Max is such because of generalized Riemann hypothesis.
+ var lpow = this.m.subn(1).iushrn(1);
+ var z = this.m.bitLength();
+ z = new BN(2 * z * z).toRed(this);
+
+ while (this.pow(z, lpow).cmp(nOne) !== 0) {
+ z.redIAdd(nOne);
+ }
+
+ var c = this.pow(z, q);
+ var r = this.pow(a, q.addn(1).iushrn(1));
+ var t = this.pow(a, q);
+ var m = s;
+ while (t.cmp(one) !== 0) {
+ var tmp = t;
+ for (var i = 0; tmp.cmp(one) !== 0; i++) {
+ tmp = tmp.redSqr();
+ }
+ assert(i < m);
+ var b = this.pow(c, new BN(1).iushln(m - i - 1));
+
+ r = r.redMul(b);
+ c = b.redSqr();
+ t = t.redMul(c);
+ m = i;
+ }
+
+ return r;
+ };
+
+ Red.prototype.invm = function invm (a) {
+ var inv = a._invmp(this.m);
+ if (inv.negative !== 0) {
+ inv.negative = 0;
+ return this.imod(inv).redNeg();
+ } else {
+ return this.imod(inv);
+ }
+ };
+
+ Red.prototype.pow = function pow (a, num) {
+ if (num.isZero()) return new BN(1).toRed(this);
+ if (num.cmpn(1) === 0) return a.clone();
+
+ var windowSize = 4;
+ var wnd = new Array(1 << windowSize);
+ wnd[0] = new BN(1).toRed(this);
+ wnd[1] = a;
+ for (var i = 2; i < wnd.length; i++) {
+ wnd[i] = this.mul(wnd[i - 1], a);
+ }
+
+ var res = wnd[0];
+ var current = 0;
+ var currentLen = 0;
+ var start = num.bitLength() % 26;
+ if (start === 0) {
+ start = 26;
+ }
+
+ for (i = num.length - 1; i >= 0; i--) {
+ var word = num.words[i];
+ for (var j = start - 1; j >= 0; j--) {
+ var bit = (word >> j) & 1;
+ if (res !== wnd[0]) {
+ res = this.sqr(res);
+ }
+
+ if (bit === 0 && current === 0) {
+ currentLen = 0;
+ continue;
+ }
+
+ current <<= 1;
+ current |= bit;
+ currentLen++;
+ if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
+
+ res = this.mul(res, wnd[current]);
+ currentLen = 0;
+ current = 0;
+ }
+ start = 26;
+ }
+
+ return res;
+ };
+
+ Red.prototype.convertTo = function convertTo (num) {
+ var r = num.umod(this.m);
+
+ return r === num ? r.clone() : r;
+ };
+
+ Red.prototype.convertFrom = function convertFrom (num) {
+ var res = num.clone();
+ res.red = null;
+ return res;
+ };
+
+ //
+ // Montgomery method engine
+ //
+
+ BN.mont = function mont (num) {
+ return new Mont(num);
+ };
+
+ function Mont (m) {
+ Red.call(this, m);
+
+ this.shift = this.m.bitLength();
+ if (this.shift % 26 !== 0) {
+ this.shift += 26 - (this.shift % 26);
+ }
+
+ this.r = new BN(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);
+ }
+ inherits(Mont, Red);
+
+ Mont.prototype.convertTo = function convertTo (num) {
+ return this.imod(num.ushln(this.shift));
+ };
+
+ Mont.prototype.convertFrom = function convertFrom (num) {
+ var r = this.imod(num.mul(this.rinv));
+ r.red = null;
+ return r;
+ };
+
+ Mont.prototype.imul = function imul (a, b) {
+ if (a.isZero() || b.isZero()) {
+ a.words[0] = 0;
+ a.length = 1;
+ return a;
+ }
+
+ var t = a.imul(b);
+ var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
+ var u = t.isub(c).iushrn(this.shift);
+ var res = u;
+
+ if (u.cmp(this.m) >= 0) {
+ res = u.isub(this.m);
+ } else if (u.cmpn(0) < 0) {
+ res = u.iadd(this.m);
+ }
+
+ return res._forceRed(this);
+ };
+
+ Mont.prototype.mul = function mul (a, b) {
+ if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
+
+ var t = a.mul(b);
+ var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
+ var u = t.isub(c).iushrn(this.shift);
+ var res = u;
+ if (u.cmp(this.m) >= 0) {
+ res = u.isub(this.m);
+ } else if (u.cmpn(0) < 0) {
+ res = u.iadd(this.m);
+ }
+
+ return res._forceRed(this);
+ };
+
+ Mont.prototype.invm = function invm (a) {
+ // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
+ var res = this.imod(a._invmp(this.m).mul(this.r2));
+ return res._forceRed(this);
+ };
+})(typeof module === 'undefined' || module, this);
+
+},{"buffer":5}],5:[function(require,module,exports){
+
+},{}],6:[function(require,module,exports){
+(function (process,global){
+/**
+ * [js-sha3]{@link https://github.com/emn178/js-sha3}
+ *
+ * @version 0.5.7
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
+ * @copyright Chen, Yi-Cyuan 2015-2016
+ * @license MIT
+ */
+/*jslint bitwise: true */
+(function () {
+ 'use strict';
+
+ var root = typeof window === 'object' ? window : {};
+ var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
+ if (NODE_JS) {
+ root = global;
+ }
+ var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
+ var HEX_CHARS = '0123456789abcdef'.split('');
+ var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
+ var KECCAK_PADDING = [1, 256, 65536, 16777216];
+ var PADDING = [6, 1536, 393216, 100663296];
+ var SHIFT = [0, 8, 16, 24];
+ var RC = [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];
+ var BITS = [224, 256, 384, 512];
+ var SHAKE_BITS = [128, 256];
+ var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array'];
+
+ var createOutputMethod = function (bits, padding, outputType) {
+ return function (message) {
+ return new Keccak(bits, padding, bits).update(message)[outputType]();
+ };
+ };
+
+ var createShakeOutputMethod = function (bits, padding, outputType) {
+ return function (message, outputBits) {
+ return new Keccak(bits, padding, outputBits).update(message)[outputType]();
+ };
+ };
+
+ var createMethod = function (bits, padding) {
+ var method = createOutputMethod(bits, padding, 'hex');
+ method.create = function () {
+ return new Keccak(bits, padding, bits);
+ };
+ method.update = function (message) {
+ return method.create().update(message);
+ };
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
+ var type = OUTPUT_TYPES[i];
+ method[type] = createOutputMethod(bits, padding, type);
+ }
+ return method;
+ };
+
+ var createShakeMethod = function (bits, padding) {
+ var method = createShakeOutputMethod(bits, padding, 'hex');
+ method.create = function (outputBits) {
+ return new Keccak(bits, padding, outputBits);
+ };
+ method.update = function (message, outputBits) {
+ return method.create(outputBits).update(message);
+ };
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
+ var type = OUTPUT_TYPES[i];
+ method[type] = createShakeOutputMethod(bits, padding, type);
+ }
+ return method;
+ };
+
+ var algorithms = [
+ {name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod},
+ {name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod},
+ {name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod}
+ ];
+
+ var methods = {}, methodNames = [];
+
+ for (var i = 0; i < algorithms.length; ++i) {
+ var algorithm = algorithms[i];
+ var bits = algorithm.bits;
+ for (var j = 0; j < bits.length; ++j) {
+ var methodName = algorithm.name +'_' + bits[j];
+ methodNames.push(methodName);
+ methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
+ }
+ }
+
+ function Keccak(bits, padding, outputBits) {
+ this.blocks = [];
+ this.s = [];
+ this.padding = padding;
+ this.outputBits = outputBits;
+ this.reset = true;
+ this.block = 0;
+ this.start = 0;
+ this.blockCount = (1600 - (bits << 1)) >> 5;
+ this.byteCount = this.blockCount << 2;
+ this.outputBlocks = outputBits >> 5;
+ this.extraBytes = (outputBits & 31) >> 3;
+
+ for (var i = 0; i < 50; ++i) {
+ this.s[i] = 0;
+ }
+ }
+
+ Keccak.prototype.update = function (message) {
+ var notString = typeof message !== 'string';
+ if (notString && message.constructor === ArrayBuffer) {
+ message = new Uint8Array(message);
+ }
+ var length = message.length, blocks = this.blocks, byteCount = this.byteCount,
+ blockCount = this.blockCount, index = 0, s = this.s, i, code;
+
+ while (index < length) {
+ if (this.reset) {
+ this.reset = false;
+ blocks[0] = this.block;
+ for (i = 1; i < blockCount + 1; ++i) {
+ blocks[i] = 0;
+ }
+ }
+ if (notString) {
+ for (i = this.start; index < length && i < byteCount; ++index) {
+ blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
+ }
+ } else {
+ for (i = this.start; index < length && i < byteCount; ++index) {
+ code = message.charCodeAt(index);
+ if (code < 0x80) {
+ blocks[i >> 2] |= code << SHIFT[i++ & 3];
+ } else if (code < 0x800) {
+ blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ } else if (code < 0xd800 || code >= 0xe000) {
+ blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ } else {
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
+ blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ }
+ }
+ }
+ this.lastByteIndex = i;
+ if (i >= byteCount) {
+ this.start = i - byteCount;
+ this.block = blocks[blockCount];
+ for (i = 0; i < blockCount; ++i) {
+ s[i] ^= blocks[i];
+ }
+ f(s);
+ this.reset = true;
+ } else {
+ this.start = i;
+ }
+ }
+ return this;
+ };
+
+ Keccak.prototype.finalize = function () {
+ var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
+ blocks[i >> 2] |= this.padding[i & 3];
+ if (this.lastByteIndex === this.byteCount) {
+ blocks[0] = blocks[blockCount];
+ for (i = 1; i < blockCount + 1; ++i) {
+ blocks[i] = 0;
+ }
+ }
+ blocks[blockCount - 1] |= 0x80000000;
+ for (i = 0; i < blockCount; ++i) {
+ s[i] ^= blocks[i];
+ }
+ f(s);
+ };
+
+ Keccak.prototype.toString = Keccak.prototype.hex = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var hex = '', block;
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ block = s[i];
+ hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
+ HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
+ HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
+ HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ i = 0;
+ }
+ }
+ if (extraBytes) {
+ block = s[i];
+ if (extraBytes > 0) {
+ hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
+ }
+ if (extraBytes > 1) {
+ hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
+ }
+ if (extraBytes > 2) {
+ hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
+ }
+ }
+ return hex;
+ };
+
+ Keccak.prototype.arrayBuffer = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var bytes = this.outputBits >> 3;
+ var buffer;
+ if (extraBytes) {
+ buffer = new ArrayBuffer((outputBlocks + 1) << 2);
+ } else {
+ buffer = new ArrayBuffer(bytes);
+ }
+ var array = new Uint32Array(buffer);
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ array[j] = s[i];
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ }
+ }
+ if (extraBytes) {
+ array[i] = s[i];
+ buffer = buffer.slice(0, bytes);
+ }
+ return buffer;
+ };
+
+ Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
+
+ Keccak.prototype.digest = Keccak.prototype.array = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var array = [], offset, block;
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ offset = j << 2;
+ block = s[i];
+ array[offset] = block & 0xFF;
+ array[offset + 1] = (block >> 8) & 0xFF;
+ array[offset + 2] = (block >> 16) & 0xFF;
+ array[offset + 3] = (block >> 24) & 0xFF;
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ }
+ }
+ if (extraBytes) {
+ offset = j << 2;
+ block = s[i];
+ if (extraBytes > 0) {
+ array[offset] = block & 0xFF;
+ }
+ if (extraBytes > 1) {
+ array[offset + 1] = (block >> 8) & 0xFF;
+ }
+ if (extraBytes > 2) {
+ array[offset + 2] = (block >> 16) & 0xFF;
+ }
+ }
+ return array;
+ };
+
+ var f = function (s) {
+ var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
+ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
+ b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
+ b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
+ for (n = 0; n < 48; n += 2) {
+ c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
+ c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
+ c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
+ c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
+ c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
+ c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
+ c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
+ c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
+ c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
+ c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
+
+ h = c8 ^ ((c2 << 1) | (c3 >>> 31));
+ l = c9 ^ ((c3 << 1) | (c2 >>> 31));
+ s[0] ^= h;
+ s[1] ^= l;
+ s[10] ^= h;
+ s[11] ^= l;
+ s[20] ^= h;
+ s[21] ^= l;
+ s[30] ^= h;
+ s[31] ^= l;
+ s[40] ^= h;
+ s[41] ^= l;
+ h = c0 ^ ((c4 << 1) | (c5 >>> 31));
+ l = c1 ^ ((c5 << 1) | (c4 >>> 31));
+ s[2] ^= h;
+ s[3] ^= l;
+ s[12] ^= h;
+ s[13] ^= l;
+ s[22] ^= h;
+ s[23] ^= l;
+ s[32] ^= h;
+ s[33] ^= l;
+ s[42] ^= h;
+ s[43] ^= l;
+ h = c2 ^ ((c6 << 1) | (c7 >>> 31));
+ l = c3 ^ ((c7 << 1) | (c6 >>> 31));
+ s[4] ^= h;
+ s[5] ^= l;
+ s[14] ^= h;
+ s[15] ^= l;
+ s[24] ^= h;
+ s[25] ^= l;
+ s[34] ^= h;
+ s[35] ^= l;
+ s[44] ^= h;
+ s[45] ^= l;
+ h = c4 ^ ((c8 << 1) | (c9 >>> 31));
+ l = c5 ^ ((c9 << 1) | (c8 >>> 31));
+ s[6] ^= h;
+ s[7] ^= l;
+ s[16] ^= h;
+ s[17] ^= l;
+ s[26] ^= h;
+ s[27] ^= l;
+ s[36] ^= h;
+ s[37] ^= l;
+ s[46] ^= h;
+ s[47] ^= l;
+ h = c6 ^ ((c0 << 1) | (c1 >>> 31));
+ l = c7 ^ ((c1 << 1) | (c0 >>> 31));
+ s[8] ^= h;
+ s[9] ^= l;
+ s[18] ^= h;
+ s[19] ^= l;
+ s[28] ^= h;
+ s[29] ^= l;
+ s[38] ^= h;
+ s[39] ^= l;
+ s[48] ^= h;
+ s[49] ^= l;
+
+ b0 = s[0];
+ b1 = s[1];
+ b32 = (s[11] << 4) | (s[10] >>> 28);
+ b33 = (s[10] << 4) | (s[11] >>> 28);
+ b14 = (s[20] << 3) | (s[21] >>> 29);
+ b15 = (s[21] << 3) | (s[20] >>> 29);
+ b46 = (s[31] << 9) | (s[30] >>> 23);
+ b47 = (s[30] << 9) | (s[31] >>> 23);
+ b28 = (s[40] << 18) | (s[41] >>> 14);
+ b29 = (s[41] << 18) | (s[40] >>> 14);
+ b20 = (s[2] << 1) | (s[3] >>> 31);
+ b21 = (s[3] << 1) | (s[2] >>> 31);
+ b2 = (s[13] << 12) | (s[12] >>> 20);
+ b3 = (s[12] << 12) | (s[13] >>> 20);
+ b34 = (s[22] << 10) | (s[23] >>> 22);
+ b35 = (s[23] << 10) | (s[22] >>> 22);
+ b16 = (s[33] << 13) | (s[32] >>> 19);
+ b17 = (s[32] << 13) | (s[33] >>> 19);
+ b48 = (s[42] << 2) | (s[43] >>> 30);
+ b49 = (s[43] << 2) | (s[42] >>> 30);
+ b40 = (s[5] << 30) | (s[4] >>> 2);
+ b41 = (s[4] << 30) | (s[5] >>> 2);
+ b22 = (s[14] << 6) | (s[15] >>> 26);
+ b23 = (s[15] << 6) | (s[14] >>> 26);
+ b4 = (s[25] << 11) | (s[24] >>> 21);
+ b5 = (s[24] << 11) | (s[25] >>> 21);
+ b36 = (s[34] << 15) | (s[35] >>> 17);
+ b37 = (s[35] << 15) | (s[34] >>> 17);
+ b18 = (s[45] << 29) | (s[44] >>> 3);
+ b19 = (s[44] << 29) | (s[45] >>> 3);
+ b10 = (s[6] << 28) | (s[7] >>> 4);
+ b11 = (s[7] << 28) | (s[6] >>> 4);
+ b42 = (s[17] << 23) | (s[16] >>> 9);
+ b43 = (s[16] << 23) | (s[17] >>> 9);
+ b24 = (s[26] << 25) | (s[27] >>> 7);
+ b25 = (s[27] << 25) | (s[26] >>> 7);
+ b6 = (s[36] << 21) | (s[37] >>> 11);
+ b7 = (s[37] << 21) | (s[36] >>> 11);
+ b38 = (s[47] << 24) | (s[46] >>> 8);
+ b39 = (s[46] << 24) | (s[47] >>> 8);
+ b30 = (s[8] << 27) | (s[9] >>> 5);
+ b31 = (s[9] << 27) | (s[8] >>> 5);
+ b12 = (s[18] << 20) | (s[19] >>> 12);
+ b13 = (s[19] << 20) | (s[18] >>> 12);
+ b44 = (s[29] << 7) | (s[28] >>> 25);
+ b45 = (s[28] << 7) | (s[29] >>> 25);
+ b26 = (s[38] << 8) | (s[39] >>> 24);
+ b27 = (s[39] << 8) | (s[38] >>> 24);
+ b8 = (s[48] << 14) | (s[49] >>> 18);
+ b9 = (s[49] << 14) | (s[48] >>> 18);
+
+ s[0] = b0 ^ (~b2 & b4);
+ s[1] = b1 ^ (~b3 & b5);
+ s[10] = b10 ^ (~b12 & b14);
+ s[11] = b11 ^ (~b13 & b15);
+ s[20] = b20 ^ (~b22 & b24);
+ s[21] = b21 ^ (~b23 & b25);
+ s[30] = b30 ^ (~b32 & b34);
+ s[31] = b31 ^ (~b33 & b35);
+ s[40] = b40 ^ (~b42 & b44);
+ s[41] = b41 ^ (~b43 & b45);
+ s[2] = b2 ^ (~b4 & b6);
+ s[3] = b3 ^ (~b5 & b7);
+ s[12] = b12 ^ (~b14 & b16);
+ s[13] = b13 ^ (~b15 & b17);
+ s[22] = b22 ^ (~b24 & b26);
+ s[23] = b23 ^ (~b25 & b27);
+ s[32] = b32 ^ (~b34 & b36);
+ s[33] = b33 ^ (~b35 & b37);
+ s[42] = b42 ^ (~b44 & b46);
+ s[43] = b43 ^ (~b45 & b47);
+ s[4] = b4 ^ (~b6 & b8);
+ s[5] = b5 ^ (~b7 & b9);
+ s[14] = b14 ^ (~b16 & b18);
+ s[15] = b15 ^ (~b17 & b19);
+ s[24] = b24 ^ (~b26 & b28);
+ s[25] = b25 ^ (~b27 & b29);
+ s[34] = b34 ^ (~b36 & b38);
+ s[35] = b35 ^ (~b37 & b39);
+ s[44] = b44 ^ (~b46 & b48);
+ s[45] = b45 ^ (~b47 & b49);
+ s[6] = b6 ^ (~b8 & b0);
+ s[7] = b7 ^ (~b9 & b1);
+ s[16] = b16 ^ (~b18 & b10);
+ s[17] = b17 ^ (~b19 & b11);
+ s[26] = b26 ^ (~b28 & b20);
+ s[27] = b27 ^ (~b29 & b21);
+ s[36] = b36 ^ (~b38 & b30);
+ s[37] = b37 ^ (~b39 & b31);
+ s[46] = b46 ^ (~b48 & b40);
+ s[47] = b47 ^ (~b49 & b41);
+ s[8] = b8 ^ (~b0 & b2);
+ s[9] = b9 ^ (~b1 & b3);
+ s[18] = b18 ^ (~b10 & b12);
+ s[19] = b19 ^ (~b11 & b13);
+ s[28] = b28 ^ (~b20 & b22);
+ s[29] = b29 ^ (~b21 & b23);
+ s[38] = b38 ^ (~b30 & b32);
+ s[39] = b39 ^ (~b31 & b33);
+ s[48] = b48 ^ (~b40 & b42);
+ s[49] = b49 ^ (~b41 & b43);
+
+ s[0] ^= RC[n];
+ s[1] ^= RC[n + 1];
+ }
+ };
+
+ if (COMMON_JS) {
+ module.exports = methods;
+ } else {
+ for (var i = 0; i < methodNames.length; ++i) {
+ root[methodNames[i]] = methods[methodNames[i]];
+ }
+ }
+})();
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"_process":7}],7:[function(require,module,exports){
+module.exports = undefined;
+},{}],8:[function(require,module,exports){
+'use strict';
+
+// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
+
+var throwError = require('../utils/throw-error');
+
+var utils = (function() {
+ var convert = require('../utils/convert.js');
+ var utf8 = require('../utils/utf8.js');
+
+ return {
+ defineProperty: require('../utils/properties.js').defineProperty,
+
+ arrayify: convert.arrayify,
+ padZeros: convert.padZeros,
+
+ bigNumberify: require('../utils/bignumber.js').bigNumberify,
+
+ getAddress: require('../utils/address').getAddress,
+
+ concat: convert.concat,
+
+ toUtf8Bytes: utf8.toUtf8Bytes,
+ toUtf8String: utf8.toUtf8String,
+
+ hexlify: convert.hexlify,
+ };
+})();
+
+var paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
+var paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
+var paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
+
+var defaultCoerceFunc = function(type, value) {
+ var match = type.match(paramTypeNumber)
+ if (match && parseInt(match[2]) <= 48) { return value.toNumber(); }
+ return value;
+}
+
+var coderNull = function(coerceFunc) {
+ return {
+ name: 'null',
+ type: '',
+ encode: function(value) {
+ return utils.arrayify([]);
+ },
+ decode: function(data, offset) {
+ if (offset > data.length) { throw new Error('invalid null'); }
+ return {
+ consumed: 0,
+ value: coerceFunc('null', undefined)
+ }
+ },
+ dynamic: false
+ };
+}
+
+var coderNumber = function(coerceFunc, size, signed, localName) {
+ var name = ((signed ? 'int': 'uint') + (size * 8));
+ return {
+ localName: localName,
+ name: name,
+ type: name,
+ encode: function(value) {
+ value = utils.bigNumberify(value).toTwos(size * 8).maskn(size * 8);
+ //value = value.toTwos(size * 8).maskn(size * 8);
+ if (signed) {
+ value = value.fromTwos(size * 8).toTwos(256);
+ }
+ return utils.padZeros(utils.arrayify(value), 32);
+ },
+ decode: function(data, offset) {
+ var junkLength = 32 - size;
+ var value = utils.bigNumberify(data.slice(offset + junkLength, offset + 32));
+ if (signed) {
+ value = value.fromTwos(size * 8);
+ } else {
+ value = value.maskn(size * 8);
+ }
+
+ //if (size <= 6) { value = value.toNumber(); }
+
+ return {
+ consumed: 32,
+ value: coerceFunc(name, value),
+ }
+ }
+ };
+}
+var uint256Coder = coderNumber(function(type, value) { return value; }, 32, false);
+
+var coderBoolean = function(coerceFunc, localName) {
+ return {
+ localName: localName,
+ name: 'boolean',
+ type: 'boolean',
+ encode: function(value) {
+ return uint256Coder.encode(value ? 1: 0);
+ },
+ decode: function(data, offset) {
+ var result = uint256Coder.decode(data, offset);
+ return {
+ consumed: result.consumed,
+ value: coerceFunc('boolean', !result.value.isZero())
+ }
+ }
+ }
+}
+
+var coderFixedBytes = function(coerceFunc, length, localName) {
+ var name = ('bytes' + length);
+ return {
+ localName: localName,
+ name: name,
+ type: name,
+ encode: function(value) {
+ value = utils.arrayify(value);
+ if (length === 32) { return value; }
+
+ var result = new Uint8Array(32);
+ result.set(value);
+ return result;
+ },
+ decode: function(data, offset) {
+ if (data.length < offset + 32) { throwError('invalid bytes' + length); }
+
+ return {
+ consumed: 32,
+ value: coerceFunc(name, utils.hexlify(data.slice(offset, offset + length)))
+ }
+ }
+ };
+}
+
+var coderAddress = function(coerceFunc, localName) {
+ return {
+ localName: localName,
+ name: 'address',
+ type: 'address',
+ encode: function(value) {
+ value = utils.arrayify(utils.getAddress(value));
+ var result = new Uint8Array(32);
+ result.set(value, 12);
+ return result;
+ },
+ decode: function(data, offset) {
+ if (data.length < offset + 32) { throwError('invalid address'); }
+ return {
+ consumed: 32,
+ value: coerceFunc('address', utils.getAddress(utils.hexlify(data.slice(offset + 12, offset + 32))))
+ }
+ }
+ }
+}
+
+function _encodeDynamicBytes(value) {
+ var dataLength = parseInt(32 * Math.ceil(value.length / 32));
+ var padding = new Uint8Array(dataLength - value.length);
+
+ return utils.concat([
+ uint256Coder.encode(value.length),
+ value,
+ padding
+ ]);
+}
+
+function _decodeDynamicBytes(data, offset) {
+ if (data.length < offset + 32) { throwError('invalid bytes'); }
+
+ var length = uint256Coder.decode(data, offset).value;
+ length = length.toNumber();
+ if (data.length < offset + 32 + length) { throwError('invalid bytes'); }
+
+ return {
+ consumed: parseInt(32 + 32 * Math.ceil(length / 32)),
+ value: data.slice(offset + 32, offset + 32 + length),
+ }
+}
+
+var coderDynamicBytes = function(coerceFunc, localName) {
+ return {
+ localName: localName,
+ name: 'bytes',
+ type: 'bytes',
+ encode: function(value) {
+ return _encodeDynamicBytes(utils.arrayify(value));
+ },
+ decode: function(data, offset) {
+ var result = _decodeDynamicBytes(data, offset);
+ result.value = coerceFunc('bytes', utils.hexlify(result.value));
+ return result;
+ },
+ dynamic: true
+ };
+}
+
+var coderString = function(coerceFunc, localName) {
+ return {
+ localName: localName,
+ name: 'string',
+ type: 'string',
+ encode: function(value) {
+ return _encodeDynamicBytes(utils.toUtf8Bytes(value));
+ },
+ decode: function(data, offset) {
+ var result = _decodeDynamicBytes(data, offset);
+ result.value = coerceFunc('string', utils.toUtf8String(result.value));
+ return result;
+ },
+ dynamic: true
+ };
+}
+
+function alignSize(size) {
+ return parseInt(32 * Math.ceil(size / 32));
+}
+
+function pack(coders, values) {
+ if (Array.isArray(values)) {
+ if (coders.length !== values.length) {
+ throwError('types/values mismatch', { type: type, values: values });
+ }
+
+ } else if (values && typeof(values) === 'object') {
+ var arrayValues = [];
+ coders.forEach(function(coder) {
+ arrayValues.push(values[coder.localName]);
+ });
+ values = arrayValues;
+
+ } else {
+ throwError('invalid value', { type: 'tuple', values: values });
+ }
+
+ var parts = [];
+
+ coders.forEach(function(coder, index) {
+ parts.push({ dynamic: coder.dynamic, value: coder.encode(values[index]) });
+ });
+
+ var staticSize = 0, dynamicSize = 0;
+ parts.forEach(function(part, index) {
+ if (part.dynamic) {
+ staticSize += 32;
+ dynamicSize += alignSize(part.value.length);
+ } else {
+ staticSize += alignSize(part.value.length);
+ }
+ });
+
+ var offset = 0, dynamicOffset = staticSize;
+ var data = new Uint8Array(staticSize + dynamicSize);
+
+ parts.forEach(function(part, index) {
+ if (part.dynamic) {
+ //uint256Coder.encode(dynamicOffset).copy(data, offset);
+ data.set(uint256Coder.encode(dynamicOffset), offset);
+ offset += 32;
+
+ //part.value.copy(data, dynamicOffset); @TODO
+ data.set(part.value, dynamicOffset);
+ dynamicOffset += alignSize(part.value.length);
+ } else {
+ //part.value.copy(data, offset); @TODO
+ data.set(part.value, offset);
+ offset += alignSize(part.value.length);
+ }
+ });
+
+ return data;
+}
+
+function unpack(coders, data, offset) {
+ var baseOffset = offset;
+ var consumed = 0;
+ var value = [];
+ coders.forEach(function(coder) {
+ if (coder.dynamic) {
+ var dynamicOffset = uint256Coder.decode(data, offset);
+ var result = coder.decode(data, baseOffset + dynamicOffset.value.toNumber());
+ // The dynamic part is leap-frogged somewhere else; doesn't count towards size
+ result.consumed = dynamicOffset.consumed;
+ } else {
+ var result = coder.decode(data, offset);
+ }
+
+ if (result.value != undefined) {
+ value.push(result.value);
+ }
+
+ offset += result.consumed;
+ consumed += result.consumed;
+ });
+
+ coders.forEach(function(coder, index) {
+ var name = coder.localName;
+ if (!name) { return; }
+
+ if (typeof(name) === 'object') { name = name.name; }
+ if (!name) { return; }
+
+ if (name === 'length') { name = '_length'; }
+
+ if (value[name] != null) { return; }
+
+ value[name] = value[index];
+ });
+
+ return {
+ value: value,
+ consumed: consumed
+ }
+
+ return result;
+}
+
+function coderArray(coerceFunc, coder, length, localName) {
+ var type = (coder.type + '[' + (length >= 0 ? length: '') + ']');
+
+ return {
+ coder: coder,
+ localName: localName,
+ length: length,
+ name: 'array',
+ type: type,
+ encode: function(value) {
+ if (!Array.isArray(value)) { throwError('invalid array'); }
+
+ var count = length;
+
+ var result = new Uint8Array(0);
+ if (count === -1) {
+ count = value.length;
+ result = uint256Coder.encode(count);
+ }
+
+ if (count !== value.length) { throwError('size mismatch'); }
+
+ var coders = [];
+ value.forEach(function(value) { coders.push(coder); });
+
+ return utils.concat([result, pack(coders, value)]);
+ },
+ decode: function(data, offset) {
+ // @TODO:
+ //if (data.length < offset + length * 32) { throw new Error('invalid array'); }
+
+ var consumed = 0;
+
+ var count = length;
+
+ if (count === -1) {
+ var decodedLength = uint256Coder.decode(data, offset);
+ count = decodedLength.value.toNumber();
+ consumed += decodedLength.consumed;
+ offset += decodedLength.consumed;
+ }
+
+ var coders = [];
+ for (var i = 0; i < count; i++) { coders.push(coder); }
+
+ var result = unpack(coders, data, offset);
+ result.consumed += consumed;
+ result.value = coerceFunc(type, result.value);
+ return result;
+ },
+ dynamic: (length === -1 || coder.dynamic)
+ }
+}
+
+
+function coderTuple(coerceFunc, coders, localName) {
+ var dynamic = false;
+ var types = [];
+ coders.forEach(function(coder) {
+ if (coder.dynamic) { dynamic = true; }
+ types.push(coder.type);
+ });
+
+ var type = ('tuple(' + types.join(',') + ')');
+
+ return {
+ coders: coders,
+ localName: localName,
+ name: 'tuple',
+ type: type,
+ encode: function(value) {
+ return pack(coders, value);
+ },
+ decode: function(data, offset) {
+ var result = unpack(coders, data, offset);
+ result.value = coerceFunc(type, result.value);
+ return result;
+ },
+ dynamic: dynamic
+ };
+}
+/*
+function getTypes(coders) {
+ var type = coderTuple(coders).type;
+ return type.substring(6, type.length - 1);
+}
+*/
+function splitNesting(value) {
+ var result = [];
+ var accum = '';
+ var depth = 0;
+ for (var offset = 0; offset < value.length; offset++) {
+ var c = value[offset];
+ if (c === ',' && depth === 0) {
+ result.push(accum);
+ accum = '';
+ } else {
+ accum += c;
+ if (c === '(') {
+ depth++;
+ } else if (c === ')') {
+ depth--;
+ if (depth === -1) {
+ throw new Error('unbalanced parenthsis');
+ }
+ }
+ }
+ }
+ result.push(accum);
+
+ return result;
+}
+
+var paramTypeSimple = {
+ address: coderAddress,
+ bool: coderBoolean,
+ string: coderString,
+ bytes: coderDynamicBytes,
+};
+
+function getParamCoder(coerceFunc, type, localName) {
+ var coder = paramTypeSimple[type];
+ if (coder) { return coder(coerceFunc, localName); }
+
+ var match = type.match(paramTypeNumber);
+ if (match) {
+ var size = parseInt(match[2] || 256);
+ if (size === 0 || size > 256 || (size % 8) !== 0) {
+ throwError('invalid type', { type: type });
+ }
+ return coderNumber(coerceFunc, size / 8, (match[1] === 'int'), localName);
+ }
+
+ var match = type.match(paramTypeBytes);
+ if (match) {
+ var size = parseInt(match[1]);
+ if (size === 0 || size > 32) {
+ throwError('invalid type ' + type);
+ }
+ return coderFixedBytes(coerceFunc, size, localName);
+ }
+
+ var match = type.match(paramTypeArray);
+ if (match) {
+ var size = parseInt(match[2] || -1);
+ return coderArray(coerceFunc, getParamCoder(coerceFunc, match[1], localName), size, localName);
+ }
+
+ if (type.substring(0, 6) === 'tuple(' && type.substring(type.length - 1) === ')') {
+ var coders = [];
+ var names = [];
+ if (localName && typeof(localName) === 'object') {
+ if (Array.isArray(localName.names)) { names = localName.names; }
+ if (typeof(localName.name) === 'string') { localName = localName.name; }
+ }
+ splitNesting(type.substring(6, type.length - 1)).forEach(function(type, index) {
+ coders.push(getParamCoder(coerceFunc, type, names[index]));
+ });
+ return coderTuple(coerceFunc, coders, localName);
+ }
+
+ if (type === '') {
+ return coderNull(coerceFunc);
+ }
+
+ throwError('invalid type', { type: type });
+}
+
+function Coder(coerceFunc) {
+ if (!(this instanceof Coder)) { throw new Error('missing new'); }
+ if (!coerceFunc) { coerceFunc = defaultCoerceFunc; }
+ utils.defineProperty(this, 'coerceFunc', coerceFunc);
+}
+
+utils.defineProperty(Coder.prototype, 'encode', function(names, types, values) {
+
+ // Names is optional, so shift over all the parameters if not provided
+ if (arguments.length < 3) {
+ values = types;
+ types = names;
+ names = null;
+ }
+
+ if (types.length !== values.length) { throwError('types/values mismatch', {types: types, values: values}); }
+
+ var coders = [];
+ types.forEach(function(type, index) {
+ coders.push(getParamCoder(this.coerceFunc, type, (names ? names[index]: undefined)));
+ }, this);
+
+ return utils.hexlify(coderTuple(this.coerceFunc, coders).encode(values));
+});
+
+utils.defineProperty(Coder.prototype, 'decode', function(names, types, data) {
+
+ // Names is optional, so shift over all the parameters if not provided
+ if (arguments.length < 3) {
+ data = types;
+ types = names;
+ names = null;
+ }
+
+ data = utils.arrayify(data);
+
+ var coders = [];
+ types.forEach(function(type, index) {
+ coders.push(getParamCoder(this.coerceFunc, type, (names ? names[index]: undefined)));
+ }, this);
+
+ return coderTuple(this.coerceFunc, coders).decode(data, 0).value;
+
+});
+
+utils.defineProperty(Coder, 'defaultCoder', new Coder());
+
+module.exports = Coder
+
+},{"../utils/address":9,"../utils/bignumber.js":10,"../utils/convert.js":11,"../utils/properties.js":13,"../utils/throw-error":14,"../utils/utf8.js":15}],9:[function(require,module,exports){
+
+var BN = require('bn.js');
+
+var convert = require('./convert');
+var throwError = require('./throw-error');
+var keccak256 = require('./keccak256');
+
+function getChecksumAddress(address) {
+ if (typeof(address) !== 'string' || !address.match(/^0x[0-9A-Fa-f]{40}$/)) {
+ throwError('invalid address', {input: address});
+ }
+
+ address = address.toLowerCase();
+
+ var hashed = address.substring(2).split('');
+ for (var i = 0; i < hashed.length; i++) {
+ hashed[i] = hashed[i].charCodeAt(0);
+ }
+ hashed = convert.arrayify(keccak256(hashed));
+
+ address = address.substring(2).split('');
+ for (var i = 0; i < 40; i += 2) {
+ if ((hashed[i >> 1] >> 4) >= 8) {
+ address[i] = address[i].toUpperCase();
+ }
+ if ((hashed[i >> 1] & 0x0f) >= 8) {
+ address[i + 1] = address[i + 1].toUpperCase();
+ }
+ }
+
+ return '0x' + address.join('');
+}
+
+// Shims for environments that are missing some required constants and functions
+var MAX_SAFE_INTEGER = 0x1fffffffffffff;
+
+function log10(x) {
+ if (Math.log10) { return Math.log10(x); }
+ return Math.log(x) / Math.LN10;
+}
+
+
+// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
+var ibanChecksum = (function() {
+
+ // Create lookup table
+ var ibanLookup = {};
+ for (var i = 0; i < 10; i++) { ibanLookup[String(i)] = String(i); }
+ for (var i = 0; i < 26; i++) { ibanLookup[String.fromCharCode(65 + i)] = String(10 + i); }
+
+ // How many decimal digits can we process? (for 64-bit float, this is 15)
+ var safeDigits = Math.floor(log10(MAX_SAFE_INTEGER));
+
+ return function(address) {
+ address = address.toUpperCase();
+ address = address.substring(4) + address.substring(0, 2) + '00';
+
+ var expanded = address.split('');
+ for (var i = 0; i < expanded.length; i++) {
+ expanded[i] = ibanLookup[expanded[i]];
+ }
+ expanded = expanded.join('');
+
+ // Javascript can handle integers safely up to 15 (decimal) digits
+ while (expanded.length >= safeDigits){
+ var block = expanded.substring(0, safeDigits);
+ expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
+ }
+
+ var checksum = String(98 - (parseInt(expanded, 10) % 97));
+ while (checksum.length < 2) { checksum = '0' + checksum; }
+
+ return checksum;
+ };
+})();
+
+function getAddress(address, icapFormat) {
+ var result = null;
+
+ if (typeof(address) !== 'string') {
+ throwError('invalid address', {input: address});
+ }
+
+ if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
+
+ // Missing the 0x prefix
+ if (address.substring(0, 2) !== '0x') { address = '0x' + address; }
+
+ result = getChecksumAddress(address);
+
+ // It is a checksummed address with a bad checksum
+ if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
+ throwError('invalid address checksum', { input: address, expected: result });
+ }
+
+ // Maybe ICAP? (we only support direct mode)
+ } else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
+
+ // It is an ICAP address with a bad checksum
+ if (address.substring(2, 4) !== ibanChecksum(address)) {
+ throwError('invalid address icap checksum', { input: address });
+ }
+
+ result = (new BN(address.substring(4), 36)).toString(16);
+ while (result.length < 40) { result = '0' + result; }
+ result = getChecksumAddress('0x' + result);
+
+ } else {
+ throwError('invalid address', { input: address });
+ }
+
+ if (icapFormat) {
+ var base36 = (new BN(result.substring(2), 16)).toString(36).toUpperCase();
+ while (base36.length < 30) { base36 = '0' + base36; }
+ return 'XE' + ibanChecksum('XE00' + base36) + base36;
+ }
+
+ return result;
+}
+
+
+module.exports = {
+ getAddress: getAddress,
+}
+
+},{"./convert":11,"./keccak256":12,"./throw-error":14,"bn.js":4}],10:[function(require,module,exports){
+/**
+ * BigNumber
+ *
+ * A wrapper around the BN.js object. In the future we can swap out
+ * the underlying BN.js library for something smaller.
+ */
+
+var BN = require('bn.js');
+
+var defineProperty = require('./properties').defineProperty;
+var convert = require('./convert');
+var throwError = require('./throw-error');
+
+function BigNumber(value) {
+ if (!(this instanceof BigNumber)) { throw new Error('missing new'); }
+
+ if (convert.isHexString(value)) {
+ if (value == '0x') { value = '0x0'; }
+ value = new BN(value.substring(2), 16);
+ } else if (typeof(value) === 'string' && value[0] === '-' && convert.isHexString(value.substring(1))) {
+ value = (new BN(value.substring(3), 16)).mul(BigNumber.constantNegativeOne._bn);
+
+ } else if (typeof(value) === 'string' && value.match(/^-?[0-9]*$/)) {
+ if (value == '') { value = '0'; }
+ value = new BN(value);
+
+ } else if (typeof(value) === 'number' && parseInt(value) == value) {
+ value = new BN(value);
+
+ } else if (BN.isBN(value)) {
+ //value = value
+
+ } else if (isBigNumber(value)) {
+ value = value._bn;
+
+ } else if (convert.isArrayish(value)) {
+ value = new BN(convert.hexlify(value).substring(2), 16);
+
+ } else {
+ throwError('invalid BigNumber value', { input: value });
+ }
+
+ defineProperty(this, '_bn', value);
+}
+
+defineProperty(BigNumber, 'constantNegativeOne', bigNumberify(-1));
+defineProperty(BigNumber, 'constantZero', bigNumberify(0));
+defineProperty(BigNumber, 'constantOne', bigNumberify(1));
+defineProperty(BigNumber, 'constantTwo', bigNumberify(2));
+defineProperty(BigNumber, 'constantWeiPerEther', bigNumberify(new BN('1000000000000000000')));
+
+
+defineProperty(BigNumber.prototype, 'fromTwos', function(value) {
+ return new BigNumber(this._bn.fromTwos(value));
+});
+
+defineProperty(BigNumber.prototype, 'toTwos', function(value) {
+ return new BigNumber(this._bn.toTwos(value));
+});
+
+
+defineProperty(BigNumber.prototype, 'add', function(other) {
+ return new BigNumber(this._bn.add(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'sub', function(other) {
+ return new BigNumber(this._bn.sub(bigNumberify(other)._bn));
+});
+
+
+defineProperty(BigNumber.prototype, 'div', function(other) {
+ return new BigNumber(this._bn.div(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'mul', function(other) {
+ return new BigNumber(this._bn.mul(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'mod', function(other) {
+ return new BigNumber(this._bn.mod(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'pow', function(other) {
+ return new BigNumber(this._bn.pow(bigNumberify(other)._bn));
+});
+
+
+defineProperty(BigNumber.prototype, 'maskn', function(value) {
+ return new BigNumber(this._bn.maskn(value));
+});
+
+
+
+defineProperty(BigNumber.prototype, 'eq', function(other) {
+ return this._bn.eq(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'lt', function(other) {
+ return this._bn.lt(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'lte', function(other) {
+ return this._bn.lte(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'gt', function(other) {
+ return this._bn.gt(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'gte', function(other) {
+ return this._bn.gte(bigNumberify(other)._bn);
+});
+
+
+defineProperty(BigNumber.prototype, 'isZero', function() {
+ return this._bn.isZero();
+});
+
+
+defineProperty(BigNumber.prototype, 'toNumber', function(base) {
+ return this._bn.toNumber();
+});
+
+defineProperty(BigNumber.prototype, 'toString', function() {
+ //return this._bn.toString(base || 10);
+ return this._bn.toString(10);
+});
+
+defineProperty(BigNumber.prototype, 'toHexString', function() {
+ var hex = this._bn.toString(16);
+ if (hex.length % 2) { hex = '0' + hex; }
+ return '0x' + hex;
+});
+
+
+function isBigNumber(value) {
+ return (value._bn && value._bn.mod);
+}
+
+function bigNumberify(value) {
+ if (isBigNumber(value)) { return value; }
+ return new BigNumber(value);
+}
+
+module.exports = {
+ isBigNumber: isBigNumber,
+ bigNumberify: bigNumberify,
+ BigNumber: BigNumber
+};
+
+},{"./convert":11,"./properties":13,"./throw-error":14,"bn.js":4}],11:[function(require,module,exports){
+/**
+ * Conversion Utilities
+ *
+ */
+
+var defineProperty = require('./properties.js').defineProperty;
+var throwError = require('./throw-error');
+
+function addSlice(array) {
+ if (array.slice) { return array; }
+
+ array.slice = function() {
+ var args = Array.prototype.slice.call(arguments);
+ return new Uint8Array(Array.prototype.slice.apply(array, args));
+ }
+
+ return array;
+}
+
+function isArrayish(value) {
+ if (!value || parseInt(value.length) != value.length || typeof(value) === 'string') {
+ return false;
+ }
+
+ for (var i = 0; i < value.length; i++) {
+ var v = value[i];
+ if (v < 0 || v >= 256 || parseInt(v) != v) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function arrayify(value, name) {
+
+ if (value && value.toHexString) {
+ value = value.toHexString();
+ }
+
+ if (isHexString(value)) {
+ value = value.substring(2);
+ if (value.length % 2) { value = '0' + value; }
+
+ var result = [];
+ for (var i = 0; i < value.length; i += 2) {
+ result.push(parseInt(value.substr(i, 2), 16));
+ }
+
+ return addSlice(new Uint8Array(result));
+ }
+
+ if (isArrayish(value)) {
+ return addSlice(new Uint8Array(value));
+ }
+
+ throwError('invalid arrayify value', { name: name, input: value });
+}
+
+function concat(objects) {
+ var arrays = [];
+ var length = 0;
+ for (var i = 0; i < objects.length; i++) {
+ var object = arrayify(objects[i])
+ arrays.push(object);
+ length += object.length;
+ }
+
+ var result = new Uint8Array(length);
+ var offset = 0;
+ for (var i = 0; i < arrays.length; i++) {
+ result.set(arrays[i], offset);
+ offset += arrays[i].length;
+ }
+
+ return addSlice(result);
+}
+function stripZeros(value) {
+ value = arrayify(value);
+
+ if (value.length === 0) { return value; }
+
+ // Find the first non-zero entry
+ var start = 0;
+ while (value[start] === 0) { start++ }
+
+ // If we started with zeros, strip them
+ if (start) {
+ value = value.slice(start);
+ }
+
+ return value;
+}
+
+function padZeros(value, length) {
+ value = arrayify(value);
+
+ if (length < value.length) { throw new Error('cannot pad'); }
+
+ var result = new Uint8Array(length);
+ result.set(value, length - value.length);
+ return addSlice(result);
+}
+
+
+function isHexString(value, length) {
+ if (typeof(value) !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
+ return false
+ }
+ if (length && value.length !== 2 + 2 * length) { return false; }
+ return true;
+}
+
+var HexCharacters = '0123456789abcdef';
+
+function hexlify(value, name) {
+
+ if (value && value.toHexString) {
+ return value.toHexString();
+ }
+
+ if (typeof(value) === 'number') {
+ if (value < 0) {
+ throwError('cannot hexlify negative value', { name: name, input: value });
+ }
+
+ var hex = '';
+ while (value) {
+ hex = HexCharacters[value & 0x0f] + hex;
+ value = parseInt(value / 16);
+ }
+
+ if (hex.length) {
+ if (hex.length % 2) { hex = '0' + hex; }
+ return '0x' + hex;
+ }
+
+ return '0x00';
+ }
+
+ if (isHexString(value)) {
+ if (value.length % 2) {
+ value = '0x0' + value.substring(2);
+ }
+ return value;
+ }
+
+ if (isArrayish(value)) {
+ var result = [];
+ for (var i = 0; i < value.length; i++) {
+ var v = value[i];
+ result.push(HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f]);
+ }
+ return '0x' + result.join('');
+ }
+
+ throwError('invalid hexlify value', { name: name, input: value });
+}
+
+function hexStripZeros(value) {
+ while (value.length > 3 && value.substring(0, 3) === '0x0') {
+ value = '0x' + value.substring(3);
+ }
+ return value;
+}
+
+function hexZeroPad(value, length) {
+ while (value.length < 2 * length + 2) {
+ value = '0x0' + value.substring(2);
+ }
+ return value;
+}
+
+module.exports = {
+ arrayify: arrayify,
+ isArrayish: isArrayish,
+
+ concat: concat,
+
+ padZeros: padZeros,
+ stripZeros: stripZeros,
+
+ hexlify: hexlify,
+ isHexString: isHexString,
+ hexStripZeros: hexStripZeros,
+ hexZeroPad: hexZeroPad,
+};
+
+},{"./properties.js":13,"./throw-error":14}],12:[function(require,module,exports){
+'use strict';
+
+var sha3 = require('js-sha3');
+
+var convert = require('./convert.js');
+
+function keccak256(data) {
+ data = convert.arrayify(data);
+ return '0x' + sha3.keccak_256(data);
+}
+
+module.exports = keccak256;
+
+},{"./convert.js":11,"js-sha3":6}],13:[function(require,module,exports){
+'use strict';
+
+function defineProperty(object, name, value) {
+ Object.defineProperty(object, name, {
+ enumerable: true,
+ value: value,
+ writable: false,
+ });
+}
+
+function defineFrozen(object, name, value) {
+ var frozen = JSON.stringify(value);
+ Object.defineProperty(object, name, {
+ enumerable: true,
+ get: function() { return JSON.parse(frozen); }
+ });
+}
+
+module.exports = {
+ defineFrozen: defineFrozen,
+ defineProperty: defineProperty,
+};
+
+},{}],14:[function(require,module,exports){
+'use strict';
+
+function throwError(message, params) {
+ var error = new Error(message);
+ for (var key in params) {
+ error[key] = params[key];
+ }
+ throw error;
+}
+
+module.exports = throwError;
+
+},{}],15:[function(require,module,exports){
+
+var convert = require('./convert.js');
+
+// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
+function utf8ToBytes(str) {
+ var result = [];
+ var offset = 0;
+ for (var i = 0; i < str.length; i++) {
+ var c = str.charCodeAt(i);
+ if (c < 128) {
+ result[offset++] = c;
+ } else if (c < 2048) {
+ result[offset++] = (c >> 6) | 192;
+ result[offset++] = (c & 63) | 128;
+ } else if (((c & 0xFC00) == 0xD800) && (i + 1) < str.length && ((str.charCodeAt(i + 1) & 0xFC00) == 0xDC00)) {
+ // Surrogate Pair
+ c = 0x10000 + ((c & 0x03FF) << 10) + (str.charCodeAt(++i) & 0x03FF);
+ result[offset++] = (c >> 18) | 240;
+ result[offset++] = ((c >> 12) & 63) | 128;
+ result[offset++] = ((c >> 6) & 63) | 128;
+ result[offset++] = (c & 63) | 128;
+ } else {
+ result[offset++] = (c >> 12) | 224;
+ result[offset++] = ((c >> 6) & 63) | 128;
+ result[offset++] = (c & 63) | 128;
+ }
+ }
+
+ return convert.arrayify(result);
+};
+
+
+// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
+function bytesToUtf8(bytes) {
+ bytes = convert.arrayify(bytes);
+
+ var result = '';
+ var i = 0;
+
+ // Invalid bytes are ignored
+ while(i < bytes.length) {
+ var c = bytes[i++];
+ if (c >> 7 == 0) {
+ // 0xxx xxxx
+ result += String.fromCharCode(c);
+ continue;
+ }
+
+ // Invalid starting byte
+ if (c >> 6 == 0x02) { continue; }
+
+ // Multibyte; how many bytes left for thus character?
+ var extraLength = null;
+ if (c >> 5 == 0x06) {
+ extraLength = 1;
+ } else if (c >> 4 == 0x0e) {
+ extraLength = 2;
+ } else if (c >> 3 == 0x1e) {
+ extraLength = 3;
+ } else if (c >> 2 == 0x3e) {
+ extraLength = 4;
+ } else if (c >> 1 == 0x7e) {
+ extraLength = 5;
+ } else {
+ continue;
+ }
+
+ // Do we have enough bytes in our data?
+ if (i + extraLength > bytes.length) {
+
+ // If there is an invalid unprocessed byte, try to continue
+ for (; i < bytes.length; i++) {
+ if (bytes[i] >> 6 != 0x02) { break; }
+ }
+ if (i != bytes.length) continue;
+
+ // All leftover bytes are valid.
+ return result;
+ }
+
+ // Remove the UTF-8 prefix from the char (res)
+ var res = c & ((1 << (8 - extraLength - 1)) - 1);
+
+ var count;
+ for (count = 0; count < extraLength; count++) {
+ var nextChar = bytes[i++];
+
+ // Is the char valid multibyte part?
+ if (nextChar >> 6 != 0x02) {break;};
+ res = (res << 6) | (nextChar & 0x3f);
+ }
+
+ if (count != extraLength) {
+ i--;
+ continue;
+ }
+
+ if (res <= 0xffff) {
+ result += String.fromCharCode(res);
+ continue;
+ }
+
+ res -= 0x10000;
+ result += String.fromCharCode(((res >> 10) & 0x3ff) + 0xd800, (res & 0x3ff) + 0xdc00);
+ }
+
+ return result;
+}
+
+module.exports = {
+ toUtf8Bytes: utf8ToBytes,
+ toUtf8String: bytesToUtf8,
+};
+
+},{"./convert.js":11}]},{},[2])(2)
+});
\ No newline at end of file
diff --git a/dist/ethers-contracts.min.js b/dist/ethers-contracts.min.js
new file mode 100644
index 0000000000..fe31912523
--- /dev/null
+++ b/dist/ethers-contracts.min.js
@@ -0,0 +1,3 @@
+!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.ethers=a()}}(function(){return function(){function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g=0&&(e=a.type.substring(f));var g=d(a.components);b.push({name:a.name||null,names:g.names}),c.push("tuple("+g.types.join(",")+")"+e)}else b.push(a.name||null),c.push(a.type)}),{names:b,types:c}}function e(a,b){for(var c in b)m.defineProperty(a,c,b[c]);return a}function f(){}function g(){}function h(){}function i(a){m.defineProperty(this,"indexed",!0),m.defineProperty(this,"hash",a)}function j(){}function k(a){function b(a){switch(a.type){case"constructor":var b=function(){var b=d(a.inputs),c=function(a){m.isHexString(a)||l("invalid bytecode",{input:a});var c=Array.prototype.slice.call(arguments,1);c.lengthb.types.length&&l("too many parameters");var d={bytecode:a+m.coder.encode(b.names,b.types,c).substring(2),type:"deploy"};return e(new f,d)};return m.defineFrozen(c,"inputs",b),m.defineProperty(c,"payable",null==a.payable||!!a.payable),c}();p||(p=b);break;case"function":var b=function(){var b=d(a.inputs),c=d(a.outputs),f="("+b.types.join(",")+")";f=f.replace(/tuple/g,""),f=a.name+f;var h=m.keccak256(m.toUtf8Bytes(f)).substring(0,10),i=function(){var d={name:a.name,signature:f,sighash:h,type:a.constant?"call":"transaction"},i=Array.prototype.slice.call(arguments,0);return i.lengthb.types.length&&l("too many parameters"),d.data=h+m.coder.encode(b.names,b.types,i).substring(2),d.parse=function(a){return m.coder.decode(c.names,c.types,m.arrayify(a))},e(new g,d)};return m.defineFrozen(i,"inputs",b),m.defineFrozen(i,"outputs",c),m.defineProperty(i,"payable",null==a.payable||!!a.payable),m.defineProperty(i,"signature",f),m.defineProperty(i,"sighash",h),i}();a.name&&null==n[a.name]&&m.defineProperty(n,a.name,b),null==n[b.signature]&&m.defineProperty(n,b.signature,b);break;case"event":var b=function(){var b=d(a.inputs),c="("+b.types.join(",")+")";c=c.replace(/tuple/g,""),c=a.name+c;var f={anonymous:!!a.anonymous,name:a.name,signature:c,type:"event"};f.parse=function(c,d){null==d&&(d=c,c=null),null==c||a.anonymous||(c=c.slice(1));var e=[],f=[],g=[],h=[],k=[];if(a.inputs.forEach(function(a,c){var d=b.types[c],i=b.names[c];a.indexed?("string"===d||"bytes"===d||d.indexOf("[")>=0||"tuple"===d.substring(0,5)?(g.push("bytes32"),k.push(!0)):(g.push(d),k.push(!1)),e.push(i)):(f.push(i),h.push(d),k.push(!1))}),null!=c)var l=m.coder.decode(e,g,m.concat(c));var n=m.coder.decode(f,h,m.arrayify(d)),o=new j,p=0,q=0;return a.inputs.forEach(function(a,b){a.indexed?null==c?o[b]=new i(null):k[b]?o[b]=new i(l[q++]):o[b]=l[q++]:o[b]=n[p++],a.name&&(o[a.name]=o[b])}),o.length=a.inputs.length,o};var g=e(new h,f);return m.defineFrozen(g,"topics",[m.keccak256(m.toUtf8Bytes(c))]),m.defineFrozen(g,"inputs",b),g}();a.name&&null==o[a.name]&&m.defineProperty(o,a.name,b),null==n[b.signature]&&m.defineProperty(n,b.signature,b);break;case"fallback":break;default:console.log("WARNING: unsupported ABI type - "+a.type)}}if(!(this instanceof k))throw new Error("missing new");if("string"==typeof a)try{a=JSON.parse(a)}catch(c){l("invalid abi",{input:a})}m.defineFrozen(this,"abi",a);var n={},o={},p=null;m.defineProperty(this,"functions",n),m.defineProperty(this,"events",o),this.abi.forEach(b,this),p||b({type:"constructor",inputs:[]}),m.defineProperty(this,"deployFunction",p)}var l=a("../utils/throw-error"),m=function(){var b=a("../utils/convert"),c=a("../utils/properties"),d=a("../utils/utf8");return{defineFrozen:c.defineFrozen,defineProperty:c.defineProperty,coder:a("../utils/abi-coder").defaultCoder,arrayify:b.arrayify,concat:b.concat,isHexString:b.isHexString,toUtf8Bytes:d.toUtf8Bytes,keccak256:a("../utils/keccak256")}}();b.exports=k},{"../utils/abi-coder":8,"../utils/convert":11,"../utils/keccak256":12,"../utils/properties":13,"../utils/throw-error":14,"../utils/utf8":15}],4:[function(a,b,c){!function(b,c){"use strict";function d(a,b){if(!a)throw new Error(b||"Assertion failed")}function e(a,b){a.super_=b;var c=function(){};c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a}function f(a,b,c){return f.isBN(a)?a:(this.negative=0,this.words=null,this.length=0,this.red=null,void(null!==a&&("le"!==b&&"be"!==b||(c=b,b=10),this._init(a||0,b||10,c||"be"))))}function g(a,b,c){for(var d=0,e=Math.min(a.length,c),f=b;f=49&&g<=54?g-49+10:g>=17&&g<=22?g-17+10:15&g}return d}function h(a,b,c,d){for(var e=0,f=Math.min(a.length,c),g=b;g=49?h-49+10:h>=17?h-17+10:h}return e}function i(a){for(var b=new Array(a.bitLength()),c=0;c>>e}return b}function j(a,b,c){c.negative=b.negative^a.negative;var d=a.length+b.length|0;c.length=d,d=d-1|0;var e=0|a.words[0],f=0|b.words[0],g=e*f,h=67108863&g,i=g/67108864|0;c.words[0]=h;for(var j=1;j>>26,l=67108863&i,m=Math.min(j,b.length-1),n=Math.max(0,j-a.length+1);n<=m;n++){var o=j-n|0;e=0|a.words[o],f=0|b.words[n],g=e*f+l,k+=g/67108864|0,l=67108863&g}c.words[j]=0|l,i=0|k}return 0!==i?c.words[j]=0|i:c.length--,c.strip()}function k(a,b,c){c.negative=b.negative^a.negative,c.length=a.length+b.length;for(var d=0,e=0,f=0;f>>26)|0,e+=g>>>26,g&=67108863}c.words[f]=h,d=g,g=e}return 0!==d?c.words[f]=d:c.length--,c.strip()}function l(a,b,c){var d=new m;return d.mulp(a,b,c)}function m(a,b){this.x=a,this.y=b}function n(a,b){this.name=a,this.p=new f(b,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function o(){n.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function p(){n.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function q(){n.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function r(){n.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function s(a){if("string"==typeof a){var b=f._prime(a);this.m=b.p,this.prime=b}else d(a.gtn(1),"modulus must be greater than 1"),this.m=a,this.prime=null}function t(a){s.call(this,a),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(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"==typeof b?b.exports=f:c.BN=f,f.BN=f,f.wordSize=26;var u;try{u=a("buffer").Buffer}catch(v){}f.isBN=function(a){return a instanceof f||null!==a&&"object"==typeof a&&a.constructor.wordSize===f.wordSize&&Array.isArray(a.words)},f.max=function(a,b){return a.cmp(b)>0?a:b},f.min=function(a,b){return a.cmp(b)<0?a:b},f.prototype._init=function(a,b,c){if("number"==typeof a)return this._initNumber(a,b,c);if("object"==typeof a)return this._initArray(a,b,c);"hex"===b&&(b=16),d(b===(0|b)&&b>=2&&b<=36),a=a.toString().replace(/\s+/g,"");var e=0;"-"===a[0]&&e++,16===b?this._parseHex(a,e):this._parseBase(a,b,e),"-"===a[0]&&(this.negative=1),this.strip(),"le"===c&&this._initArray(this.toArray(),b,c)},f.prototype._initNumber=function(a,b,c){a<0&&(this.negative=1,a=-a),a<67108864?(this.words=[67108863&a],this.length=1):a<4503599627370496?(this.words=[67108863&a,a/67108864&67108863],this.length=2):(d(a<9007199254740992),this.words=[67108863&a,a/67108864&67108863,1],this.length=3),"le"===c&&this._initArray(this.toArray(),b,c)},f.prototype._initArray=function(a,b,c){if(d("number"==typeof a.length),a.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(a.length/3),this.words=new Array(this.length);for(var e=0;e=0;e-=3)g=a[e]|a[e-1]<<8|a[e-2]<<16,this.words[f]|=g<>>26-h&67108863,h+=24,h>=26&&(h-=26,f++);else if("le"===c)for(e=0,f=0;e>>26-h&67108863,h+=24,h>=26&&(h-=26,f++);return this.strip()},f.prototype._parseHex=function(a,b){this.length=Math.ceil((a.length-b)/6),this.words=new Array(this.length);for(var c=0;c=b;c-=6)e=g(a,c,c+6),this.words[d]|=e<>>26-f&4194303,f+=24,f>=26&&(f-=26,d++);c+6!==b&&(e=g(a,b,c+6),this.words[d]|=e<>>26-f&4194303),this.strip()},f.prototype._parseBase=function(a,b,c){this.words=[0],this.length=1;for(var d=0,e=1;e<=67108863;e*=b)d++;d--,e=e/b|0;for(var f=a.length-c,g=f%d,i=Math.min(f,f-g)+c,j=0,k=c;k1&&0===this.words[this.length-1];)this.length--;return this._normSign()},f.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},f.prototype.inspect=function(){return(this.red?""};var w=["","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"],x=[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],y=[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];f.prototype.toString=function(a,b){a=a||10,b=0|b||1;var c;if(16===a||"hex"===a){c="";for(var e=0,f=0,g=0;g>>24-e&16777215,c=0!==f||g!==this.length-1?w[6-i.length]+i+c:i+c,e+=2,e>=26&&(e-=26,g--)}for(0!==f&&(c=f.toString(16)+c);c.length%b!==0;)c="0"+c;return 0!==this.negative&&(c="-"+c),c}if(a===(0|a)&&a>=2&&a<=36){var j=x[a],k=y[a];c="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modn(k).toString(a);l=l.idivn(k),c=l.isZero()?m+c:w[j-m.length]+m+c}for(this.isZero()&&(c="0"+c);c.length%b!==0;)c="0"+c;return 0!==this.negative&&(c="-"+c),c}d(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var a=this.words[0];return 2===this.length?a+=67108864*this.words[1]:3===this.length&&1===this.words[2]?a+=4503599627370496+67108864*this.words[1]:this.length>2&&d(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-a:a},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(a,b){return d("undefined"!=typeof u),this.toArrayLike(u,a,b)},f.prototype.toArray=function(a,b){return this.toArrayLike(Array,a,b)},f.prototype.toArrayLike=function(a,b,c){var e=this.byteLength(),f=c||Math.max(1,e);d(e<=f,"byte array longer than desired length"),d(f>0,"Requested array length <= 0"),this.strip();var g,h,i="le"===b,j=new a(f),k=this.clone();if(i){for(h=0;!k.isZero();h++)g=k.andln(255),k.iushrn(8),j[h]=g;for(;h=4096&&(c+=13,b>>>=13),b>=64&&(c+=7,b>>>=7),b>=8&&(c+=4,b>>>=4),b>=2&&(c+=2,b>>>=2),c+b},f.prototype._zeroBits=function(a){if(0===a)return 26;var b=a,c=0;return 0===(8191&b)&&(c+=13,b>>>=13),0===(127&b)&&(c+=7,b>>>=7),0===(15&b)&&(c+=4,b>>>=4),0===(3&b)&&(c+=2,b>>>=2),0===(1&b)&&c++,c},f.prototype.bitLength=function(){var a=this.words[this.length-1],b=this._countBits(a);return 26*(this.length-1)+b},f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var a=0,b=0;ba.length?this.clone().ior(a):a.clone().ior(this)},f.prototype.uor=function(a){return this.length>a.length?this.clone().iuor(a):a.clone().iuor(this)},f.prototype.iuand=function(a){var b;b=this.length>a.length?a:this;for(var c=0;ca.length?this.clone().iand(a):a.clone().iand(this)},f.prototype.uand=function(a){return this.length>a.length?this.clone().iuand(a):a.clone().iuand(this)},f.prototype.iuxor=function(a){var b,c;this.length>a.length?(b=this,c=a):(b=a,c=this);for(var d=0;da.length?this.clone().ixor(a):a.clone().ixor(this)},f.prototype.uxor=function(a){return this.length>a.length?this.clone().iuxor(a):a.clone().iuxor(this)},f.prototype.inotn=function(a){d("number"==typeof a&&a>=0);var b=0|Math.ceil(a/26),c=a%26;this._expand(b),c>0&&b--;for(var e=0;e0&&(this.words[e]=~this.words[e]&67108863>>26-c),this.strip()},f.prototype.notn=function(a){return this.clone().inotn(a)},f.prototype.setn=function(a,b){d("number"==typeof a&&a>=0);var c=a/26|0,e=a%26;return this._expand(c+1),b?this.words[c]=this.words[c]|1<a.length?(c=this,d=a):(c=a,d=this);for(var e=0,f=0;f>>26;for(;0!==e&&f>>26;if(this.length=c.length,0!==e)this.words[this.length]=e,this.length++;else if(c!==this)for(;fa.length?this.clone().iadd(a):a.clone().iadd(this)},f.prototype.isub=function(a){if(0!==a.negative){a.negative=0;var b=this.iadd(a);return a.negative=1,b._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(a),this.negative=1,this._normSign();var c=this.cmp(a);if(0===c)return this.negative=0,this.length=1,this.words[0]=0,this;var d,e;c>0?(d=this,e=a):(d=a,e=this);for(var f=0,g=0;g>26,this.words[g]=67108863&b;for(;0!==f&&g>26,this.words[g]=67108863&b;if(0===f&&g>>13,n=0|g[1],o=8191&n,p=n>>>13,q=0|g[2],r=8191&q,s=q>>>13,t=0|g[3],u=8191&t,v=t>>>13,w=0|g[4],x=8191&w,y=w>>>13,z=0|g[5],A=8191&z,B=z>>>13,C=0|g[6],D=8191&C,E=C>>>13,F=0|g[7],G=8191&F,H=F>>>13,I=0|g[8],J=8191&I,K=I>>>13,L=0|g[9],M=8191&L,N=L>>>13,O=0|h[0],P=8191&O,Q=O>>>13,R=0|h[1],S=8191&R,T=R>>>13,U=0|h[2],V=8191&U,W=U>>>13,X=0|h[3],Y=8191&X,Z=X>>>13,$=0|h[4],_=8191&$,aa=$>>>13,ba=0|h[5],ca=8191&ba,da=ba>>>13,ea=0|h[6],fa=8191&ea,ga=ea>>>13,ha=0|h[7],ia=8191&ha,ja=ha>>>13,ka=0|h[8],la=8191&ka,ma=ka>>>13,na=0|h[9],oa=8191&na,pa=na>>>13;c.negative=a.negative^b.negative,c.length=19,d=Math.imul(l,P),e=Math.imul(l,Q),e=e+Math.imul(m,P)|0,f=Math.imul(m,Q);var qa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(qa>>>26)|0,qa&=67108863,d=Math.imul(o,P),e=Math.imul(o,Q),e=e+Math.imul(p,P)|0,f=Math.imul(p,Q),d=d+Math.imul(l,S)|0,e=e+Math.imul(l,T)|0,e=e+Math.imul(m,S)|0,f=f+Math.imul(m,T)|0;var ra=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ra>>>26)|0,ra&=67108863,d=Math.imul(r,P),e=Math.imul(r,Q),e=e+Math.imul(s,P)|0,f=Math.imul(s,Q),d=d+Math.imul(o,S)|0,e=e+Math.imul(o,T)|0,e=e+Math.imul(p,S)|0,f=f+Math.imul(p,T)|0,d=d+Math.imul(l,V)|0,e=e+Math.imul(l,W)|0,e=e+Math.imul(m,V)|0,f=f+Math.imul(m,W)|0;var sa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(sa>>>26)|0,sa&=67108863,d=Math.imul(u,P),e=Math.imul(u,Q),e=e+Math.imul(v,P)|0,f=Math.imul(v,Q),d=d+Math.imul(r,S)|0,e=e+Math.imul(r,T)|0,e=e+Math.imul(s,S)|0,f=f+Math.imul(s,T)|0,d=d+Math.imul(o,V)|0,e=e+Math.imul(o,W)|0,e=e+Math.imul(p,V)|0,f=f+Math.imul(p,W)|0,d=d+Math.imul(l,Y)|0,e=e+Math.imul(l,Z)|0,e=e+Math.imul(m,Y)|0,f=f+Math.imul(m,Z)|0;var ta=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ta>>>26)|0,ta&=67108863,d=Math.imul(x,P),e=Math.imul(x,Q),e=e+Math.imul(y,P)|0,f=Math.imul(y,Q),d=d+Math.imul(u,S)|0,e=e+Math.imul(u,T)|0,e=e+Math.imul(v,S)|0,f=f+Math.imul(v,T)|0,d=d+Math.imul(r,V)|0,e=e+Math.imul(r,W)|0,e=e+Math.imul(s,V)|0,f=f+Math.imul(s,W)|0,d=d+Math.imul(o,Y)|0,e=e+Math.imul(o,Z)|0,e=e+Math.imul(p,Y)|0,f=f+Math.imul(p,Z)|0,d=d+Math.imul(l,_)|0,e=e+Math.imul(l,aa)|0,e=e+Math.imul(m,_)|0,f=f+Math.imul(m,aa)|0;var ua=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ua>>>26)|0,ua&=67108863,d=Math.imul(A,P),e=Math.imul(A,Q),e=e+Math.imul(B,P)|0,f=Math.imul(B,Q),d=d+Math.imul(x,S)|0,e=e+Math.imul(x,T)|0,e=e+Math.imul(y,S)|0,f=f+Math.imul(y,T)|0,d=d+Math.imul(u,V)|0,e=e+Math.imul(u,W)|0,e=e+Math.imul(v,V)|0,f=f+Math.imul(v,W)|0,d=d+Math.imul(r,Y)|0,e=e+Math.imul(r,Z)|0,e=e+Math.imul(s,Y)|0,f=f+Math.imul(s,Z)|0,d=d+Math.imul(o,_)|0,e=e+Math.imul(o,aa)|0,e=e+Math.imul(p,_)|0,f=f+Math.imul(p,aa)|0,d=d+Math.imul(l,ca)|0,e=e+Math.imul(l,da)|0,e=e+Math.imul(m,ca)|0,f=f+Math.imul(m,da)|0;var va=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(va>>>26)|0,va&=67108863,d=Math.imul(D,P),e=Math.imul(D,Q),e=e+Math.imul(E,P)|0,f=Math.imul(E,Q),d=d+Math.imul(A,S)|0,e=e+Math.imul(A,T)|0,e=e+Math.imul(B,S)|0,f=f+Math.imul(B,T)|0,d=d+Math.imul(x,V)|0,e=e+Math.imul(x,W)|0,e=e+Math.imul(y,V)|0,f=f+Math.imul(y,W)|0,d=d+Math.imul(u,Y)|0,e=e+Math.imul(u,Z)|0,e=e+Math.imul(v,Y)|0,f=f+Math.imul(v,Z)|0,d=d+Math.imul(r,_)|0,e=e+Math.imul(r,aa)|0,e=e+Math.imul(s,_)|0,f=f+Math.imul(s,aa)|0,d=d+Math.imul(o,ca)|0,e=e+Math.imul(o,da)|0,e=e+Math.imul(p,ca)|0,f=f+Math.imul(p,da)|0,d=d+Math.imul(l,fa)|0,e=e+Math.imul(l,ga)|0,e=e+Math.imul(m,fa)|0,f=f+Math.imul(m,ga)|0;var wa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(wa>>>26)|0,wa&=67108863,d=Math.imul(G,P),e=Math.imul(G,Q),e=e+Math.imul(H,P)|0,f=Math.imul(H,Q),d=d+Math.imul(D,S)|0,e=e+Math.imul(D,T)|0,e=e+Math.imul(E,S)|0,f=f+Math.imul(E,T)|0,d=d+Math.imul(A,V)|0,e=e+Math.imul(A,W)|0,e=e+Math.imul(B,V)|0,f=f+Math.imul(B,W)|0,d=d+Math.imul(x,Y)|0,e=e+Math.imul(x,Z)|0,e=e+Math.imul(y,Y)|0,f=f+Math.imul(y,Z)|0,d=d+Math.imul(u,_)|0,e=e+Math.imul(u,aa)|0,e=e+Math.imul(v,_)|0,f=f+Math.imul(v,aa)|0,d=d+Math.imul(r,ca)|0,e=e+Math.imul(r,da)|0,e=e+Math.imul(s,ca)|0,f=f+Math.imul(s,da)|0,d=d+Math.imul(o,fa)|0,e=e+Math.imul(o,ga)|0,e=e+Math.imul(p,fa)|0,f=f+Math.imul(p,ga)|0,d=d+Math.imul(l,ia)|0,e=e+Math.imul(l,ja)|0,e=e+Math.imul(m,ia)|0,f=f+Math.imul(m,ja)|0;var xa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(xa>>>26)|0,xa&=67108863,d=Math.imul(J,P),e=Math.imul(J,Q),e=e+Math.imul(K,P)|0,f=Math.imul(K,Q),d=d+Math.imul(G,S)|0,e=e+Math.imul(G,T)|0,e=e+Math.imul(H,S)|0,f=f+Math.imul(H,T)|0,d=d+Math.imul(D,V)|0,e=e+Math.imul(D,W)|0,e=e+Math.imul(E,V)|0,f=f+Math.imul(E,W)|0,d=d+Math.imul(A,Y)|0,e=e+Math.imul(A,Z)|0,e=e+Math.imul(B,Y)|0,f=f+Math.imul(B,Z)|0,d=d+Math.imul(x,_)|0,e=e+Math.imul(x,aa)|0,e=e+Math.imul(y,_)|0,f=f+Math.imul(y,aa)|0,d=d+Math.imul(u,ca)|0,e=e+Math.imul(u,da)|0,e=e+Math.imul(v,ca)|0,f=f+Math.imul(v,da)|0,d=d+Math.imul(r,fa)|0,e=e+Math.imul(r,ga)|0,e=e+Math.imul(s,fa)|0,f=f+Math.imul(s,ga)|0,d=d+Math.imul(o,ia)|0,e=e+Math.imul(o,ja)|0,e=e+Math.imul(p,ia)|0,f=f+Math.imul(p,ja)|0,d=d+Math.imul(l,la)|0,e=e+Math.imul(l,ma)|0,e=e+Math.imul(m,la)|0,f=f+Math.imul(m,ma)|0;var ya=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ya>>>26)|0,ya&=67108863,d=Math.imul(M,P),e=Math.imul(M,Q),e=e+Math.imul(N,P)|0,f=Math.imul(N,Q),d=d+Math.imul(J,S)|0,e=e+Math.imul(J,T)|0,e=e+Math.imul(K,S)|0,f=f+Math.imul(K,T)|0,d=d+Math.imul(G,V)|0,e=e+Math.imul(G,W)|0,e=e+Math.imul(H,V)|0,f=f+Math.imul(H,W)|0,d=d+Math.imul(D,Y)|0,e=e+Math.imul(D,Z)|0,e=e+Math.imul(E,Y)|0,f=f+Math.imul(E,Z)|0,d=d+Math.imul(A,_)|0,e=e+Math.imul(A,aa)|0,e=e+Math.imul(B,_)|0,f=f+Math.imul(B,aa)|0,d=d+Math.imul(x,ca)|0,e=e+Math.imul(x,da)|0,e=e+Math.imul(y,ca)|0,f=f+Math.imul(y,da)|0,d=d+Math.imul(u,fa)|0,e=e+Math.imul(u,ga)|0,e=e+Math.imul(v,fa)|0,f=f+Math.imul(v,ga)|0,d=d+Math.imul(r,ia)|0,e=e+Math.imul(r,ja)|0,e=e+Math.imul(s,ia)|0,f=f+Math.imul(s,ja)|0,d=d+Math.imul(o,la)|0,e=e+Math.imul(o,ma)|0,e=e+Math.imul(p,la)|0,f=f+Math.imul(p,ma)|0,d=d+Math.imul(l,oa)|0,e=e+Math.imul(l,pa)|0,e=e+Math.imul(m,oa)|0,f=f+Math.imul(m,pa)|0;var za=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(za>>>26)|0,za&=67108863,d=Math.imul(M,S),e=Math.imul(M,T),e=e+Math.imul(N,S)|0,f=Math.imul(N,T),d=d+Math.imul(J,V)|0,e=e+Math.imul(J,W)|0,e=e+Math.imul(K,V)|0,f=f+Math.imul(K,W)|0,d=d+Math.imul(G,Y)|0,e=e+Math.imul(G,Z)|0,e=e+Math.imul(H,Y)|0,f=f+Math.imul(H,Z)|0,d=d+Math.imul(D,_)|0,e=e+Math.imul(D,aa)|0,e=e+Math.imul(E,_)|0,f=f+Math.imul(E,aa)|0,d=d+Math.imul(A,ca)|0,e=e+Math.imul(A,da)|0,e=e+Math.imul(B,ca)|0,f=f+Math.imul(B,da)|0,d=d+Math.imul(x,fa)|0,e=e+Math.imul(x,ga)|0,e=e+Math.imul(y,fa)|0,f=f+Math.imul(y,ga)|0,d=d+Math.imul(u,ia)|0,e=e+Math.imul(u,ja)|0,e=e+Math.imul(v,ia)|0,f=f+Math.imul(v,ja)|0,d=d+Math.imul(r,la)|0,e=e+Math.imul(r,ma)|0,e=e+Math.imul(s,la)|0,f=f+Math.imul(s,ma)|0,d=d+Math.imul(o,oa)|0,e=e+Math.imul(o,pa)|0,e=e+Math.imul(p,oa)|0,f=f+Math.imul(p,pa)|0;var Aa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Aa>>>26)|0,Aa&=67108863,d=Math.imul(M,V),e=Math.imul(M,W),e=e+Math.imul(N,V)|0,f=Math.imul(N,W),d=d+Math.imul(J,Y)|0,e=e+Math.imul(J,Z)|0,e=e+Math.imul(K,Y)|0,f=f+Math.imul(K,Z)|0,d=d+Math.imul(G,_)|0,e=e+Math.imul(G,aa)|0,e=e+Math.imul(H,_)|0,f=f+Math.imul(H,aa)|0,d=d+Math.imul(D,ca)|0,e=e+Math.imul(D,da)|0,e=e+Math.imul(E,ca)|0,f=f+Math.imul(E,da)|0,d=d+Math.imul(A,fa)|0,e=e+Math.imul(A,ga)|0,e=e+Math.imul(B,fa)|0,f=f+Math.imul(B,ga)|0,d=d+Math.imul(x,ia)|0,e=e+Math.imul(x,ja)|0,e=e+Math.imul(y,ia)|0,f=f+Math.imul(y,ja)|0,d=d+Math.imul(u,la)|0,e=e+Math.imul(u,ma)|0,e=e+Math.imul(v,la)|0,f=f+Math.imul(v,ma)|0,d=d+Math.imul(r,oa)|0,e=e+Math.imul(r,pa)|0,e=e+Math.imul(s,oa)|0,f=f+Math.imul(s,pa)|0;var Ba=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ba>>>26)|0,Ba&=67108863,d=Math.imul(M,Y),e=Math.imul(M,Z),e=e+Math.imul(N,Y)|0,f=Math.imul(N,Z),d=d+Math.imul(J,_)|0,e=e+Math.imul(J,aa)|0,e=e+Math.imul(K,_)|0,f=f+Math.imul(K,aa)|0,d=d+Math.imul(G,ca)|0,e=e+Math.imul(G,da)|0,e=e+Math.imul(H,ca)|0,f=f+Math.imul(H,da)|0,d=d+Math.imul(D,fa)|0,e=e+Math.imul(D,ga)|0,e=e+Math.imul(E,fa)|0,f=f+Math.imul(E,ga)|0,d=d+Math.imul(A,ia)|0,e=e+Math.imul(A,ja)|0,e=e+Math.imul(B,ia)|0,f=f+Math.imul(B,ja)|0,d=d+Math.imul(x,la)|0,e=e+Math.imul(x,ma)|0,e=e+Math.imul(y,la)|0,f=f+Math.imul(y,ma)|0,d=d+Math.imul(u,oa)|0,e=e+Math.imul(u,pa)|0,e=e+Math.imul(v,oa)|0,f=f+Math.imul(v,pa)|0;var Ca=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ca>>>26)|0,Ca&=67108863,d=Math.imul(M,_),e=Math.imul(M,aa),e=e+Math.imul(N,_)|0,f=Math.imul(N,aa),d=d+Math.imul(J,ca)|0,e=e+Math.imul(J,da)|0,e=e+Math.imul(K,ca)|0,f=f+Math.imul(K,da)|0,d=d+Math.imul(G,fa)|0,e=e+Math.imul(G,ga)|0,e=e+Math.imul(H,fa)|0,f=f+Math.imul(H,ga)|0,d=d+Math.imul(D,ia)|0,e=e+Math.imul(D,ja)|0,e=e+Math.imul(E,ia)|0,f=f+Math.imul(E,ja)|0,d=d+Math.imul(A,la)|0,e=e+Math.imul(A,ma)|0,e=e+Math.imul(B,la)|0,f=f+Math.imul(B,ma)|0,d=d+Math.imul(x,oa)|0,e=e+Math.imul(x,pa)|0,e=e+Math.imul(y,oa)|0,f=f+Math.imul(y,pa)|0;var Da=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Da>>>26)|0,Da&=67108863,d=Math.imul(M,ca),e=Math.imul(M,da),e=e+Math.imul(N,ca)|0,f=Math.imul(N,da),d=d+Math.imul(J,fa)|0,e=e+Math.imul(J,ga)|0,e=e+Math.imul(K,fa)|0,f=f+Math.imul(K,ga)|0,d=d+Math.imul(G,ia)|0,e=e+Math.imul(G,ja)|0,e=e+Math.imul(H,ia)|0,f=f+Math.imul(H,ja)|0,d=d+Math.imul(D,la)|0,e=e+Math.imul(D,ma)|0,e=e+Math.imul(E,la)|0,f=f+Math.imul(E,ma)|0,d=d+Math.imul(A,oa)|0,e=e+Math.imul(A,pa)|0,e=e+Math.imul(B,oa)|0,f=f+Math.imul(B,pa)|0;var Ea=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ea>>>26)|0,Ea&=67108863,d=Math.imul(M,fa),e=Math.imul(M,ga),e=e+Math.imul(N,fa)|0,f=Math.imul(N,ga),d=d+Math.imul(J,ia)|0,e=e+Math.imul(J,ja)|0,e=e+Math.imul(K,ia)|0,f=f+Math.imul(K,ja)|0,d=d+Math.imul(G,la)|0,e=e+Math.imul(G,ma)|0,e=e+Math.imul(H,la)|0,f=f+Math.imul(H,ma)|0,d=d+Math.imul(D,oa)|0,e=e+Math.imul(D,pa)|0,e=e+Math.imul(E,oa)|0,f=f+Math.imul(E,pa)|0;var Fa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Fa>>>26)|0,Fa&=67108863,d=Math.imul(M,ia),e=Math.imul(M,ja),e=e+Math.imul(N,ia)|0,f=Math.imul(N,ja),d=d+Math.imul(J,la)|0,e=e+Math.imul(J,ma)|0,e=e+Math.imul(K,la)|0,f=f+Math.imul(K,ma)|0,d=d+Math.imul(G,oa)|0,e=e+Math.imul(G,pa)|0,e=e+Math.imul(H,oa)|0,f=f+Math.imul(H,pa)|0;
+var Ga=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ga>>>26)|0,Ga&=67108863,d=Math.imul(M,la),e=Math.imul(M,ma),e=e+Math.imul(N,la)|0,f=Math.imul(N,ma),d=d+Math.imul(J,oa)|0,e=e+Math.imul(J,pa)|0,e=e+Math.imul(K,oa)|0,f=f+Math.imul(K,pa)|0;var Ha=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ha>>>26)|0,Ha&=67108863,d=Math.imul(M,oa),e=Math.imul(M,pa),e=e+Math.imul(N,oa)|0,f=Math.imul(N,pa);var Ia=(j+d|0)+((8191&e)<<13)|0;return j=(f+(e>>>13)|0)+(Ia>>>26)|0,Ia&=67108863,i[0]=qa,i[1]=ra,i[2]=sa,i[3]=ta,i[4]=ua,i[5]=va,i[6]=wa,i[7]=xa,i[8]=ya,i[9]=za,i[10]=Aa,i[11]=Ba,i[12]=Ca,i[13]=Da,i[14]=Ea,i[15]=Fa,i[16]=Ga,i[17]=Ha,i[18]=Ia,0!==j&&(i[19]=j,c.length++),c};Math.imul||(z=j),f.prototype.mulTo=function(a,b){var c,d=this.length+a.length;return c=10===this.length&&10===a.length?z(this,a,b):d<63?j(this,a,b):d<1024?k(this,a,b):l(this,a,b)},m.prototype.makeRBT=function(a){for(var b=new Array(a),c=f.prototype._countBits(a)-1,d=0;d>=1;return d},m.prototype.permute=function(a,b,c,d,e,f){for(var g=0;g>>=1)e++;return 1<>>=13,c[2*g+1]=8191&f,f>>>=13;for(g=2*b;g>=26,b+=e/67108864|0,b+=f>>>26,this.words[c]=67108863&f}return 0!==b&&(this.words[c]=b,this.length++),this},f.prototype.muln=function(a){return this.clone().imuln(a)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(a){var b=i(a);if(0===b.length)return new f(1);for(var c=this,d=0;d=0);var b,c=a%26,e=(a-c)/26,f=67108863>>>26-c<<26-c;if(0!==c){var g=0;for(b=0;b>>26-c}g&&(this.words[b]=g,this.length++)}if(0!==e){for(b=this.length-1;b>=0;b--)this.words[b+e]=this.words[b];for(b=0;b=0);var e;e=b?(b-b%26)/26:0;var f=a%26,g=Math.min((a-f)/26,this.length),h=67108863^67108863>>>f<g)for(this.length-=g,j=0;j=0&&(0!==k||j>=e);j--){var l=0|this.words[j];this.words[j]=k<<26-f|l>>>f,k=l&h}return i&&0!==k&&(i.words[i.length++]=k),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},f.prototype.ishrn=function(a,b,c){return d(0===this.negative),this.iushrn(a,b,c)},f.prototype.shln=function(a){return this.clone().ishln(a)},f.prototype.ushln=function(a){return this.clone().iushln(a)},f.prototype.shrn=function(a){return this.clone().ishrn(a)},f.prototype.ushrn=function(a){return this.clone().iushrn(a)},f.prototype.testn=function(a){d("number"==typeof a&&a>=0);var b=a%26,c=(a-b)/26,e=1<=0);var b=a%26,c=(a-b)/26;if(d(0===this.negative,"imaskn works only with positive numbers"),this.length<=c)return this;if(0!==b&&c++,this.length=Math.min(c,this.length),0!==b){var e=67108863^67108863>>>b<=67108864;b++)this.words[b]-=67108864,b===this.length-1?this.words[b+1]=1:this.words[b+1]++;return this.length=Math.max(this.length,b+1),this},f.prototype.isubn=function(a){if(d("number"==typeof a),d(a<67108864),a<0)return this.iaddn(-a);if(0!==this.negative)return this.negative=0,this.iaddn(a),this.negative=1,this;if(this.words[0]-=a,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var b=0;b>26)-(i/67108864|0),this.words[e+c]=67108863&g}for(;e>26,this.words[e+c]=67108863&g;if(0===h)return this.strip();for(d(h===-1),h=0,e=0;e>26,this.words[e]=67108863&g;return this.negative=1,this.strip()},f.prototype._wordDiv=function(a,b){var c=this.length-a.length,d=this.clone(),e=a,g=0|e.words[e.length-1],h=this._countBits(g);c=26-h,0!==c&&(e=e.ushln(c),d.iushln(c),g=0|e.words[e.length-1]);var i,j=d.length-e.length;if("mod"!==b){i=new f(null),i.length=j+1,i.words=new Array(i.length);for(var k=0;k=0;m--){var n=67108864*(0|d.words[e.length+m])+(0|d.words[e.length+m-1]);for(n=Math.min(n/g|0,67108863),d._ishlnsubmul(e,n,m);0!==d.negative;)n--,d.negative=0,d._ishlnsubmul(e,1,m),d.isZero()||(d.negative^=1);i&&(i.words[m]=n)}return i&&i.strip(),d.strip(),"div"!==b&&0!==c&&d.iushrn(c),{div:i||null,mod:d}},f.prototype.divmod=function(a,b,c){if(d(!a.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var e,g,h;return 0!==this.negative&&0===a.negative?(h=this.neg().divmod(a,b),"mod"!==b&&(e=h.div.neg()),"div"!==b&&(g=h.mod.neg(),c&&0!==g.negative&&g.iadd(a)),{div:e,mod:g}):0===this.negative&&0!==a.negative?(h=this.divmod(a.neg(),b),"mod"!==b&&(e=h.div.neg()),{div:e,mod:h.mod}):0!==(this.negative&a.negative)?(h=this.neg().divmod(a.neg(),b),"div"!==b&&(g=h.mod.neg(),c&&0!==g.negative&&g.isub(a)),{div:h.div,mod:g}):a.length>this.length||this.cmp(a)<0?{div:new f(0),mod:this}:1===a.length?"div"===b?{div:this.divn(a.words[0]),mod:null}:"mod"===b?{div:null,mod:new f(this.modn(a.words[0]))}:{div:this.divn(a.words[0]),mod:new f(this.modn(a.words[0]))}:this._wordDiv(a,b)},f.prototype.div=function(a){return this.divmod(a,"div",!1).div},f.prototype.mod=function(a){return this.divmod(a,"mod",!1).mod},f.prototype.umod=function(a){return this.divmod(a,"mod",!0).mod},f.prototype.divRound=function(a){var b=this.divmod(a);if(b.mod.isZero())return b.div;var c=0!==b.div.negative?b.mod.isub(a):b.mod,d=a.ushrn(1),e=a.andln(1),f=c.cmp(d);return f<0||1===e&&0===f?b.div:0!==b.div.negative?b.div.isubn(1):b.div.iaddn(1)},f.prototype.modn=function(a){d(a<=67108863);for(var b=(1<<26)%a,c=0,e=this.length-1;e>=0;e--)c=(b*c+(0|this.words[e]))%a;return c},f.prototype.idivn=function(a){d(a<=67108863);for(var b=0,c=this.length-1;c>=0;c--){var e=(0|this.words[c])+67108864*b;this.words[c]=e/a|0,b=e%a}return this.strip()},f.prototype.divn=function(a){return this.clone().idivn(a)},f.prototype.egcd=function(a){d(0===a.negative),d(!a.isZero());var b=this,c=a.clone();b=0!==b.negative?b.umod(a):b.clone();for(var e=new f(1),g=new f(0),h=new f(0),i=new f(1),j=0;b.isEven()&&c.isEven();)b.iushrn(1),c.iushrn(1),++j;for(var k=c.clone(),l=b.clone();!b.isZero();){for(var m=0,n=1;0===(b.words[0]&n)&&m<26;++m,n<<=1);if(m>0)for(b.iushrn(m);m-- >0;)(e.isOdd()||g.isOdd())&&(e.iadd(k),g.isub(l)),e.iushrn(1),g.iushrn(1);for(var o=0,p=1;0===(c.words[0]&p)&&o<26;++o,p<<=1);if(o>0)for(c.iushrn(o);o-- >0;)(h.isOdd()||i.isOdd())&&(h.iadd(k),i.isub(l)),h.iushrn(1),i.iushrn(1);b.cmp(c)>=0?(b.isub(c),e.isub(h),g.isub(i)):(c.isub(b),h.isub(e),i.isub(g))}return{a:h,b:i,gcd:c.iushln(j)}},f.prototype._invmp=function(a){d(0===a.negative),d(!a.isZero());var b=this,c=a.clone();b=0!==b.negative?b.umod(a):b.clone();for(var e=new f(1),g=new f(0),h=c.clone();b.cmpn(1)>0&&c.cmpn(1)>0;){for(var i=0,j=1;0===(b.words[0]&j)&&i<26;++i,j<<=1);if(i>0)for(b.iushrn(i);i-- >0;)e.isOdd()&&e.iadd(h),e.iushrn(1);for(var k=0,l=1;0===(c.words[0]&l)&&k<26;++k,l<<=1);if(k>0)for(c.iushrn(k);k-- >0;)g.isOdd()&&g.iadd(h),g.iushrn(1);b.cmp(c)>=0?(b.isub(c),e.isub(g)):(c.isub(b),g.isub(e))}var m;return m=0===b.cmpn(1)?e:g,m.cmpn(0)<0&&m.iadd(a),m},f.prototype.gcd=function(a){if(this.isZero())return a.abs();if(a.isZero())return this.abs();var b=this.clone(),c=a.clone();b.negative=0,c.negative=0;for(var d=0;b.isEven()&&c.isEven();d++)b.iushrn(1),c.iushrn(1);for(;;){for(;b.isEven();)b.iushrn(1);for(;c.isEven();)c.iushrn(1);var e=b.cmp(c);if(e<0){var f=b;b=c,c=f}else if(0===e||0===c.cmpn(1))break;b.isub(c)}return c.iushln(d)},f.prototype.invm=function(a){return this.egcd(a).a.umod(a)},f.prototype.isEven=function(){return 0===(1&this.words[0])},f.prototype.isOdd=function(){return 1===(1&this.words[0])},f.prototype.andln=function(a){return this.words[0]&a},f.prototype.bincn=function(a){d("number"==typeof a);var b=a%26,c=(a-b)/26,e=1<>>26,h&=67108863,this.words[g]=h}return 0!==f&&(this.words[g]=f,this.length++),this},f.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},f.prototype.cmpn=function(a){var b=a<0;if(0!==this.negative&&!b)return-1;if(0===this.negative&&b)return 1;this.strip();var c;if(this.length>1)c=1;else{b&&(a=-a),d(a<=67108863,"Number is too big");var e=0|this.words[0];c=e===a?0:ea.length)return 1;if(this.length=0;c--){var d=0|this.words[c],e=0|a.words[c];if(d!==e){de&&(b=1);break}}return b},f.prototype.gtn=function(a){return 1===this.cmpn(a)},f.prototype.gt=function(a){return 1===this.cmp(a)},f.prototype.gten=function(a){return this.cmpn(a)>=0},f.prototype.gte=function(a){return this.cmp(a)>=0},f.prototype.ltn=function(a){return this.cmpn(a)===-1},f.prototype.lt=function(a){return this.cmp(a)===-1},f.prototype.lten=function(a){return this.cmpn(a)<=0},f.prototype.lte=function(a){return this.cmp(a)<=0},f.prototype.eqn=function(a){return 0===this.cmpn(a)},f.prototype.eq=function(a){return 0===this.cmp(a)},f.red=function(a){return new s(a)},f.prototype.toRed=function(a){return d(!this.red,"Already a number in reduction context"),d(0===this.negative,"red works only with positives"),a.convertTo(this)._forceRed(a)},f.prototype.fromRed=function(){return d(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(a){return this.red=a,this},f.prototype.forceRed=function(a){return d(!this.red,"Already a number in reduction context"),this._forceRed(a)},f.prototype.redAdd=function(a){return d(this.red,"redAdd works only with red numbers"),this.red.add(this,a)},f.prototype.redIAdd=function(a){return d(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,a)},f.prototype.redSub=function(a){return d(this.red,"redSub works only with red numbers"),this.red.sub(this,a)},f.prototype.redISub=function(a){return d(this.red,"redISub works only with red numbers"),this.red.isub(this,a)},f.prototype.redShl=function(a){return d(this.red,"redShl works only with red numbers"),this.red.shl(this,a)},f.prototype.redMul=function(a){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.mul(this,a)},f.prototype.redIMul=function(a){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.imul(this,a)},f.prototype.redSqr=function(){return d(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return d(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return d(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return d(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return d(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(a){return d(this.red&&!a.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,a)};var A={k256:null,p224:null,p192:null,p25519:null};n.prototype._tmp=function(){var a=new f(null);return a.words=new Array(Math.ceil(this.n/13)),a},n.prototype.ireduce=function(a){var b,c=a;do this.split(c,this.tmp),c=this.imulK(c),c=c.iadd(this.tmp),b=c.bitLength();while(b>this.n);var d=b0?c.isub(this.p):c.strip(),c},n.prototype.split=function(a,b){a.iushrn(this.n,0,b)},n.prototype.imulK=function(a){return a.imul(this.k)},e(o,n),o.prototype.split=function(a,b){for(var c=4194303,d=Math.min(a.length,9),e=0;e>>22,f=g}f>>>=22,a.words[e-10]=f,0===f&&a.length>10?a.length-=10:a.length-=9},o.prototype.imulK=function(a){a.words[a.length]=0,a.words[a.length+1]=0,a.length+=2;for(var b=0,c=0;c>>=26,a.words[c]=e,b=d}return 0!==b&&(a.words[a.length++]=b),a},f._prime=function B(a){if(A[a])return A[a];var B;if("k256"===a)B=new o;else if("p224"===a)B=new p;else if("p192"===a)B=new q;else{if("p25519"!==a)throw new Error("Unknown prime "+a);B=new r}return A[a]=B,B},s.prototype._verify1=function(a){d(0===a.negative,"red works only with positives"),d(a.red,"red works only with red numbers")},s.prototype._verify2=function(a,b){d(0===(a.negative|b.negative),"red works only with positives"),d(a.red&&a.red===b.red,"red works only with red numbers")},s.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):a.umod(this.m)._forceRed(this)},s.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},s.prototype.add=function(a,b){this._verify2(a,b);var c=a.add(b);return c.cmp(this.m)>=0&&c.isub(this.m),c._forceRed(this)},s.prototype.iadd=function(a,b){this._verify2(a,b);var c=a.iadd(b);return c.cmp(this.m)>=0&&c.isub(this.m),c},s.prototype.sub=function(a,b){this._verify2(a,b);var c=a.sub(b);return c.cmpn(0)<0&&c.iadd(this.m),c._forceRed(this)},s.prototype.isub=function(a,b){this._verify2(a,b);var c=a.isub(b);return c.cmpn(0)<0&&c.iadd(this.m),c},s.prototype.shl=function(a,b){return this._verify1(a),this.imod(a.ushln(b))},s.prototype.imul=function(a,b){return this._verify2(a,b),this.imod(a.imul(b))},s.prototype.mul=function(a,b){return this._verify2(a,b),this.imod(a.mul(b))},s.prototype.isqr=function(a){return this.imul(a,a.clone())},s.prototype.sqr=function(a){return this.mul(a,a)},s.prototype.sqrt=function(a){if(a.isZero())return a.clone();var b=this.m.andln(3);if(d(b%2===1),3===b){var c=this.m.add(new f(1)).iushrn(2);return this.pow(a,c)}for(var e=this.m.subn(1),g=0;!e.isZero()&&0===e.andln(1);)g++,e.iushrn(1);d(!e.isZero());var h=new f(1).toRed(this),i=h.redNeg(),j=this.m.subn(1).iushrn(1),k=this.m.bitLength();for(k=new f(2*k*k).toRed(this);0!==this.pow(k,j).cmp(i);)k.redIAdd(i);for(var l=this.pow(k,e),m=this.pow(a,e.addn(1).iushrn(1)),n=this.pow(a,e),o=g;0!==n.cmp(h);){for(var p=n,q=0;0!==p.cmp(h);q++)p=p.redSqr();d(q=0;e--){for(var k=b.words[e],l=j-1;l>=0;l--){var m=k>>l&1;g!==d[0]&&(g=this.sqr(g)),0!==m||0!==h?(h<<=1,h|=m,i++,(i===c||0===e&&0===l)&&(g=this.mul(g,d[h]),i=0,h=0)):i=0}j=26}return g},s.prototype.convertTo=function(a){var b=a.umod(this.m);return b===a?b.clone():b},s.prototype.convertFrom=function(a){var b=a.clone();return b.red=null,b},f.mont=function(a){return new t(a)},e(t,s),t.prototype.convertTo=function(a){return this.imod(a.ushln(this.shift))},t.prototype.convertFrom=function(a){var b=this.imod(a.mul(this.rinv));return b.red=null,b},t.prototype.imul=function(a,b){if(a.isZero()||b.isZero())return a.words[0]=0,a.length=1,a;var c=a.imul(b),d=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),e=c.isub(d).iushrn(this.shift),f=e;return e.cmp(this.m)>=0?f=e.isub(this.m):e.cmpn(0)<0&&(f=e.iadd(this.m)),f._forceRed(this)},t.prototype.mul=function(a,b){if(a.isZero()||b.isZero())return new f(0)._forceRed(this);var c=a.mul(b),d=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),e=c.isub(d).iushrn(this.shift),g=e;return e.cmp(this.m)>=0?g=e.isub(this.m):e.cmpn(0)<0&&(g=e.iadd(this.m)),g._forceRed(this)},t.prototype.invm=function(a){var b=this.imod(a._invmp(this.m).mul(this.r2));return b._forceRed(this)}}("undefined"==typeof b||b,this)},{buffer:5}],5:[function(a,b,c){},{}],6:[function(a,b,c){(function(a,c){!function(){"use strict";function d(a,b,c){this.blocks=[],this.s=[],this.padding=b,this.outputBits=c,this.reset=!0,this.block=0,this.start=0,this.blockCount=1600-(a<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=c>>5,this.extraBytes=(31&c)>>3;for(var d=0;d<50;++d)this.s[d]=0}var e="object"==typeof window?window:{},f=!e.JS_SHA3_NO_NODE_JS&&"object"==typeof a&&a.versions&&a.versions.node;f&&(e=c);for(var g=!e.JS_SHA3_NO_COMMON_JS&&"object"==typeof b&&b.exports,h="0123456789abcdef".split(""),i=[31,7936,2031616,520093696],j=[1,256,65536,16777216],k=[6,1536,393216,100663296],l=[0,8,16,24],m=[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],n=[224,256,384,512],o=[128,256],p=["hex","buffer","arrayBuffer","array"],q=function(a,b,c){return function(e){return new d(a,b,a).update(e)[c]()}},r=function(a,b,c){return function(e,f){return new d(a,b,f).update(e)[c]()}},s=function(a,b){var c=q(a,b,"hex");c.create=function(){return new d(a,b,a)},c.update=function(a){return c.create().update(a)};for(var e=0;e>2]|=a[i]<>2]|=d<>2]|=(192|d>>6)<>2]|=(128|63&d)<=57344?(f[c>>2]|=(224|d>>12)<>2]|=(128|d>>6&63)<>2]|=(128|63&d)<>2]|=(240|d>>18)<>2]|=(128|d>>12&63)<>2]|=(128|d>>6&63)<>2]|=(128|63&d)<=g){for(this.start=c-g,this.block=f[h],c=0;c>2]|=this.padding[3&b],this.lastByteIndex===this.byteCount)for(a[0]=a[c],b=1;b>4&15]+h[15&a]+h[a>>12&15]+h[a>>8&15]+h[a>>20&15]+h[a>>16&15]+h[a>>28&15]+h[a>>24&15];g%b===0&&(C(c),f=0)}return e&&(a=c[f],e>0&&(i+=h[a>>4&15]+h[15&a]),e>1&&(i+=h[a>>12&15]+h[a>>8&15]),e>2&&(i+=h[a>>20&15]+h[a>>16&15])),i},d.prototype.arrayBuffer=function(){this.finalize();var a,b=this.blockCount,c=this.s,d=this.outputBlocks,e=this.extraBytes,f=0,g=0,h=this.outputBits>>3;a=e?new ArrayBuffer(d+1<<2):new ArrayBuffer(h);for(var i=new Uint32Array(a);g>8&255,i[a+2]=b>>16&255,i[a+3]=b>>24&255;h%c===0&&C(d)}return f&&(a=h<<2,b=d[g],f>0&&(i[a]=255&b),f>1&&(i[a+1]=b>>8&255),f>2&&(i[a+2]=b>>16&255)),i};var C=function(a){var b,c,d,e,f,g,h,i,j,k,l,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,aa,ba,ca,da,ea,fa,ga,ha,ia,ja,ka;for(d=0;d<48;d+=2)e=a[0]^a[10]^a[20]^a[30]^a[40],f=a[1]^a[11]^a[21]^a[31]^a[41],g=a[2]^a[12]^a[22]^a[32]^a[42],h=a[3]^a[13]^a[23]^a[33]^a[43],i=a[4]^a[14]^a[24]^a[34]^a[44],j=a[5]^a[15]^a[25]^a[35]^a[45],k=a[6]^a[16]^a[26]^a[36]^a[46],l=a[7]^a[17]^a[27]^a[37]^a[47],n=a[8]^a[18]^a[28]^a[38]^a[48],o=a[9]^a[19]^a[29]^a[39]^a[49],b=n^(g<<1|h>>>31),c=o^(h<<1|g>>>31),a[0]^=b,a[1]^=c,a[10]^=b,a[11]^=c,a[20]^=b,a[21]^=c,a[30]^=b,a[31]^=c,a[40]^=b,a[41]^=c,b=e^(i<<1|j>>>31),c=f^(j<<1|i>>>31),a[2]^=b,a[3]^=c,a[12]^=b,a[13]^=c,a[22]^=b,a[23]^=c,a[32]^=b,a[33]^=c,a[42]^=b,a[43]^=c,b=g^(k<<1|l>>>31),c=h^(l<<1|k>>>31),a[4]^=b,a[5]^=c,a[14]^=b,a[15]^=c,a[24]^=b,a[25]^=c,a[34]^=b,a[35]^=c,a[44]^=b,a[45]^=c,b=i^(n<<1|o>>>31),c=j^(o<<1|n>>>31),a[6]^=b,a[7]^=c,a[16]^=b,a[17]^=c,a[26]^=b,a[27]^=c,a[36]^=b,a[37]^=c,a[46]^=b,a[47]^=c,b=k^(e<<1|f>>>31),c=l^(f<<1|e>>>31),a[8]^=b,a[9]^=c,a[18]^=b,a[19]^=c,a[28]^=b,a[29]^=c,a[38]^=b,a[39]^=c,a[48]^=b,a[49]^=c,p=a[0],q=a[1],V=a[11]<<4|a[10]>>>28,W=a[10]<<4|a[11]>>>28,D=a[20]<<3|a[21]>>>29,E=a[21]<<3|a[20]>>>29,ha=a[31]<<9|a[30]>>>23,ia=a[30]<<9|a[31]>>>23,R=a[40]<<18|a[41]>>>14,S=a[41]<<18|a[40]>>>14,J=a[2]<<1|a[3]>>>31,K=a[3]<<1|a[2]>>>31,r=a[13]<<12|a[12]>>>20,s=a[12]<<12|a[13]>>>20,X=a[22]<<10|a[23]>>>22,Y=a[23]<<10|a[22]>>>22,F=a[33]<<13|a[32]>>>19,G=a[32]<<13|a[33]>>>19,ja=a[42]<<2|a[43]>>>30,ka=a[43]<<2|a[42]>>>30,ba=a[5]<<30|a[4]>>>2,ca=a[4]<<30|a[5]>>>2,L=a[14]<<6|a[15]>>>26,M=a[15]<<6|a[14]>>>26,t=a[25]<<11|a[24]>>>21,u=a[24]<<11|a[25]>>>21,Z=a[34]<<15|a[35]>>>17,$=a[35]<<15|a[34]>>>17,H=a[45]<<29|a[44]>>>3,I=a[44]<<29|a[45]>>>3,z=a[6]<<28|a[7]>>>4,A=a[7]<<28|a[6]>>>4,da=a[17]<<23|a[16]>>>9,ea=a[16]<<23|a[17]>>>9,N=a[26]<<25|a[27]>>>7,O=a[27]<<25|a[26]>>>7,v=a[36]<<21|a[37]>>>11,w=a[37]<<21|a[36]>>>11,_=a[47]<<24|a[46]>>>8,aa=a[46]<<24|a[47]>>>8,T=a[8]<<27|a[9]>>>5,U=a[9]<<27|a[8]>>>5,B=a[18]<<20|a[19]>>>12,C=a[19]<<20|a[18]>>>12,fa=a[29]<<7|a[28]>>>25,ga=a[28]<<7|a[29]>>>25,P=a[38]<<8|a[39]>>>24,Q=a[39]<<8|a[38]>>>24,x=a[48]<<14|a[49]>>>18,y=a[49]<<14|a[48]>>>18,a[0]=p^~r&t,a[1]=q^~s&u,a[10]=z^~B&D,a[11]=A^~C&E,a[20]=J^~L&N,a[21]=K^~M&O,a[30]=T^~V&X,a[31]=U^~W&Y,a[40]=ba^~da&fa,a[41]=ca^~ea&ga,a[2]=r^~t&v,a[3]=s^~u&w,a[12]=B^~D&F,a[13]=C^~E&G,a[22]=L^~N&P,a[23]=M^~O&Q,a[32]=V^~X&Z,a[33]=W^~Y&$,a[42]=da^~fa&ha,a[43]=ea^~ga&ia,a[4]=t^~v&x,a[5]=u^~w&y,a[14]=D^~F&H,a[15]=E^~G&I,a[24]=N^~P&R,a[25]=O^~Q&S,a[34]=X^~Z&_,a[35]=Y^~$&aa,a[44]=fa^~ha&ja,a[45]=ga^~ia&ka,a[6]=v^~x&p,a[7]=w^~y&q,a[16]=F^~H&z,a[17]=G^~I&A,a[26]=P^~R&J,a[27]=Q^~S&K,a[36]=Z^~_&T,a[37]=$^~aa&U,a[46]=ha^~ja&ba,a[47]=ia^~ka&ca,a[8]=x^~p&r,a[9]=y^~q&s,a[18]=H^~z&B,a[19]=I^~A&C,a[28]=R^~J&L,a[29]=S^~K&M,a[38]=_^~T&V,a[39]=aa^~U&W,a[48]=ja^~ba&da,a[49]=ka^~ca&ea,a[0]^=m[d],a[1]^=m[d+1]};if(g)b.exports=v;else for(var x=0;x=0?c:"")+"]";return{coder:b,localName:d,length:c,name:"array",type:e,encode:function(a){Array.isArray(a)||n("invalid array");var d=c,e=new Uint8Array(0);d===-1&&(d=a.length,e=v.encode(d)),d!==a.length&&n("size mismatch");var f=[];return a.forEach(function(a){f.push(b)}),o.concat([e,g(f,a)])},decode:function(d,f){var g=0,i=c;if(i===-1){var j=v.decode(d,f);i=j.value.toNumber(),g+=j.consumed,f+=j.consumed}for(var k=[],l=0;l256||f%8!==0)&&n("invalid type",{type:b}),u(a,f/8,"int"===e[1],c)}var e=b.match(p);if(e){var f=parseInt(e[1]);return(0===f||f>32)&&n("invalid type "+b),x(a,f,c)}var e=b.match(r);if(e){var f=parseInt(e[2]||-1);return i(a,l(a,e[1],c),f,c)}if("tuple("===b.substring(0,6)&&")"===b.substring(b.length-1)){var g=[],h=[];return c&&"object"==typeof c&&(Array.isArray(c.names)&&(h=c.names),"string"==typeof c.name&&(c=c.name)),k(b.substring(6,b.length-1)).forEach(function(b,c){g.push(l(a,b,h[c]))}),j(a,g,c)}return""===b?t(a):void n("invalid type",{type:b})}function m(a){if(!(this instanceof m))throw new Error("missing new");a||(a=s),o.defineProperty(this,"coerceFunc",a)}var n=a("../utils/throw-error"),o=function(){var b=a("../utils/convert.js"),c=a("../utils/utf8.js");return{defineProperty:a("../utils/properties.js").defineProperty,arrayify:b.arrayify,padZeros:b.padZeros,bigNumberify:a("../utils/bignumber.js").bigNumberify,getAddress:a("../utils/address").getAddress,concat:b.concat,toUtf8Bytes:c.toUtf8Bytes,toUtf8String:c.toUtf8String,hexlify:b.hexlify}}(),p=new RegExp(/^bytes([0-9]*)$/),q=new RegExp(/^(u?int)([0-9]*)$/),r=new RegExp(/^(.*)\[([0-9]*)\]$/),s=function(a,b){var c=a.match(q);return c&&parseInt(c[2])<=48?b.toNumber():b},t=function(a){return{name:"null",type:"",encode:function(a){return o.arrayify([])},decode:function(b,c){if(c>b.length)throw new Error("invalid null");return{consumed:0,value:a("null",void 0)}},dynamic:!1}},u=function(a,b,c,d){var e=(c?"int":"uint")+8*b;return{localName:d,name:e,type:e,encode:function(a){return a=o.bigNumberify(a).toTwos(8*b).maskn(8*b),c&&(a=a.fromTwos(8*b).toTwos(256)),o.padZeros(o.arrayify(a),32)},decode:function(d,f){var g=32-b,h=o.bigNumberify(d.slice(f+g,f+32));return h=c?h.fromTwos(8*b):h.maskn(8*b),{consumed:32,value:a(e,h)}}}},v=u(function(a,b){
+return b},32,!1),w=function(a,b){return{localName:b,name:"boolean",type:"boolean",encode:function(a){return v.encode(a?1:0)},decode:function(b,c){var d=v.decode(b,c);return{consumed:d.consumed,value:a("boolean",!d.value.isZero())}}}},x=function(a,b,c){var d="bytes"+b;return{localName:c,name:d,type:d,encode:function(a){if(a=o.arrayify(a),32===b)return a;var c=new Uint8Array(32);return c.set(a),c},decode:function(c,e){return c.length>1]>>4>=8&&(a[c]=a[c].toUpperCase()),(15&b[c>>1])>=8&&(a[c+1]=a[c+1].toUpperCase());return"0x"+a.join("")}function e(a){return Math.log10?Math.log10(a):Math.log(a)/Math.LN10}function f(a,b){var c=null;if("string"!=typeof a&&i("invalid address",{input:a}),a.match(/^(0x)?[0-9a-fA-F]{40}$/))"0x"!==a.substring(0,2)&&(a="0x"+a),c=d(a),a.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&c!==a&&i("invalid address checksum",{input:a,expected:c});else if(a.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(a.substring(2,4)!==l(a)&&i("invalid address icap checksum",{input:a}),c=new g(a.substring(4),36).toString(16);c.length<40;)c="0"+c;c=d("0x"+c)}else i("invalid address",{input:a});if(b){for(var e=new g(c.substring(2),16).toString(36).toUpperCase();e.length<30;)e="0"+e;return"XE"+l("XE00"+e)+e}return c}var g=a("bn.js"),h=a("./convert"),i=a("./throw-error"),j=a("./keccak256"),k=9007199254740991,l=function(){for(var a={},b=0;b<10;b++)a[String(b)]=String(b);for(var b=0;b<26;b++)a[String.fromCharCode(65+b)]=String(10+b);var c=Math.floor(e(k));return function(b){b=b.toUpperCase(),b=b.substring(4)+b.substring(0,2)+"00";for(var d=b.split(""),e=0;e=c;){var f=d.substring(0,c);d=parseInt(f,10)%97+d.substring(f.length)}for(var g=String(98-parseInt(d,10)%97);g.length<2;)g="0"+g;return g}}();b.exports={getAddress:f}},{"./convert":11,"./keccak256":12,"./throw-error":14,"bn.js":4}],10:[function(a,b,c){function d(a){if(!(this instanceof d))throw new Error("missing new");i.isHexString(a)?("0x"==a&&(a="0x0"),a=new g(a.substring(2),16)):"string"==typeof a&&"-"===a[0]&&i.isHexString(a.substring(1))?a=new g(a.substring(3),16).mul(d.constantNegativeOne._bn):"string"==typeof a&&a.match(/^-?[0-9]*$/)?(""==a&&(a="0"),a=new g(a)):"number"==typeof a&&parseInt(a)==a?a=new g(a):g.isBN(a)||(e(a)?a=a._bn:i.isArrayish(a)?a=new g(i.hexlify(a).substring(2),16):j("invalid BigNumber value",{input:a})),h(this,"_bn",a)}function e(a){return a._bn&&a._bn.mod}function f(a){return e(a)?a:new d(a)}var g=a("bn.js"),h=a("./properties").defineProperty,i=a("./convert"),j=a("./throw-error");h(d,"constantNegativeOne",f(-1)),h(d,"constantZero",f(0)),h(d,"constantOne",f(1)),h(d,"constantTwo",f(2)),h(d,"constantWeiPerEther",f(new g("1000000000000000000"))),h(d.prototype,"fromTwos",function(a){return new d(this._bn.fromTwos(a))}),h(d.prototype,"toTwos",function(a){return new d(this._bn.toTwos(a))}),h(d.prototype,"add",function(a){return new d(this._bn.add(f(a)._bn))}),h(d.prototype,"sub",function(a){return new d(this._bn.sub(f(a)._bn))}),h(d.prototype,"div",function(a){return new d(this._bn.div(f(a)._bn))}),h(d.prototype,"mul",function(a){return new d(this._bn.mul(f(a)._bn))}),h(d.prototype,"mod",function(a){return new d(this._bn.mod(f(a)._bn))}),h(d.prototype,"pow",function(a){return new d(this._bn.pow(f(a)._bn))}),h(d.prototype,"maskn",function(a){return new d(this._bn.maskn(a))}),h(d.prototype,"eq",function(a){return this._bn.eq(f(a)._bn)}),h(d.prototype,"lt",function(a){return this._bn.lt(f(a)._bn)}),h(d.prototype,"lte",function(a){return this._bn.lte(f(a)._bn)}),h(d.prototype,"gt",function(a){return this._bn.gt(f(a)._bn)}),h(d.prototype,"gte",function(a){return this._bn.gte(f(a)._bn)}),h(d.prototype,"isZero",function(){return this._bn.isZero()}),h(d.prototype,"toNumber",function(a){return this._bn.toNumber()}),h(d.prototype,"toString",function(){return this._bn.toString(10)}),h(d.prototype,"toHexString",function(){var a=this._bn.toString(16);return a.length%2&&(a="0"+a),"0x"+a}),b.exports={isBigNumber:e,bigNumberify:f,BigNumber:d}},{"./convert":11,"./properties":13,"./throw-error":14,"bn.js":4}],11:[function(a,b,c){function d(a){return a.slice?a:(a.slice=function(){var b=Array.prototype.slice.call(arguments);return new Uint8Array(Array.prototype.slice.apply(a,b))},a)}function e(a){if(!a||parseInt(a.length)!=a.length||"string"==typeof a)return!1;for(var b=0;b=256||parseInt(c)!=c)return!1}return!0}function f(a,b){if(a&&a.toHexString&&(a=a.toHexString()),j(a)){a=a.substring(2),a.length%2&&(a="0"+a);for(var c=[],f=0;f>4]+o[15&g])}return"0x"+d.join("")}n("invalid hexlify value",{name:b,input:a})}function l(a){for(;a.length>3&&"0x0"===a.substring(0,3);)a="0x"+a.substring(3);return a}function m(a,b){for(;a.length<2*b+2;)a="0x0"+a.substring(2);return a}var n=(a("./properties.js").defineProperty,a("./throw-error")),o="0123456789abcdef";b.exports={arrayify:f,isArrayish:e,concat:g,padZeros:i,stripZeros:h,hexlify:k,isHexString:j,hexStripZeros:l,hexZeroPad:m}},{"./properties.js":13,"./throw-error":14}],12:[function(a,b,c){"use strict";function d(a){return a=f.arrayify(a),"0x"+e.keccak_256(a)}var e=a("js-sha3"),f=a("./convert.js");b.exports=d},{"./convert.js":11,"js-sha3":6}],13:[function(a,b,c){"use strict";function d(a,b,c){Object.defineProperty(a,b,{enumerable:!0,value:c,writable:!1})}function e(a,b,c){var d=JSON.stringify(c);Object.defineProperty(a,b,{enumerable:!0,get:function(){return JSON.parse(d)}})}b.exports={defineFrozen:e,defineProperty:d}},{}],14:[function(a,b,c){"use strict";function d(a,b){var c=new Error(a);for(var d in b)c[d]=b[d];throw c}b.exports=d},{}],15:[function(a,b,c){function d(a){for(var b=[],c=0,d=0;d>6|192,b[c++]=63&e|128):55296==(64512&e)&&d+1>18|240,b[c++]=e>>12&63|128,b[c++]=e>>6&63|128,b[c++]=63&e|128):(b[c++]=e>>12|224,b[c++]=e>>6&63|128,b[c++]=63&e|128)}return f.arrayify(b)}function e(a){a=f.arrayify(a);for(var b="",c=0;c>7!=0){if(d>>6!=2){var e=null;if(d>>5==6)e=1;else if(d>>4==14)e=2;else if(d>>3==30)e=3;else if(d>>2==62)e=4;else{if(d>>1!=126)continue;e=5}if(c+e>a.length){for(;c>6==2;c++);if(c!=a.length)continue;return b}var g,h=d&(1<<8-e-1)-1;for(g=0;g>6!=2)break;h=h<<6|63&i}g==e?h<=65535?b+=String.fromCharCode(h):(h-=65536,b+=String.fromCharCode((h>>10&1023)+55296,(1023&h)+56320)):c--}}else b+=String.fromCharCode(d)}return b}var f=a("./convert.js");b.exports={toUtf8Bytes:d,toUtf8String:e}},{"./convert.js":11}]},{},[2])(2)});
\ No newline at end of file
diff --git a/dist/ethers-providers.js b/dist/ethers-providers.js
new file mode 100644
index 0000000000..bc28a756df
--- /dev/null
+++ b/dist/ethers-providers.js
@@ -0,0 +1,6740 @@
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethers = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) return left;
+ return right;
+ };
+
+ BN.min = function min (left, right) {
+ if (left.cmp(right) < 0) return left;
+ return right;
+ };
+
+ BN.prototype._init = function init (number, base, endian) {
+ if (typeof number === 'number') {
+ return this._initNumber(number, base, endian);
+ }
+
+ if (typeof number === 'object') {
+ return this._initArray(number, base, endian);
+ }
+
+ if (base === 'hex') {
+ base = 16;
+ }
+ assert(base === (base | 0) && base >= 2 && base <= 36);
+
+ number = number.toString().replace(/\s+/g, '');
+ var start = 0;
+ if (number[0] === '-') {
+ start++;
+ }
+
+ if (base === 16) {
+ this._parseHex(number, start);
+ } else {
+ this._parseBase(number, base, start);
+ }
+
+ if (number[0] === '-') {
+ this.negative = 1;
+ }
+
+ this.strip();
+
+ if (endian !== 'le') return;
+
+ this._initArray(this.toArray(), base, endian);
+ };
+
+ BN.prototype._initNumber = function _initNumber (number, base, endian) {
+ if (number < 0) {
+ this.negative = 1;
+ number = -number;
+ }
+ if (number < 0x4000000) {
+ this.words = [ number & 0x3ffffff ];
+ this.length = 1;
+ } else if (number < 0x10000000000000) {
+ this.words = [
+ number & 0x3ffffff,
+ (number / 0x4000000) & 0x3ffffff
+ ];
+ this.length = 2;
+ } else {
+ assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
+ this.words = [
+ number & 0x3ffffff,
+ (number / 0x4000000) & 0x3ffffff,
+ 1
+ ];
+ this.length = 3;
+ }
+
+ if (endian !== 'le') return;
+
+ // Reverse the bytes
+ this._initArray(this.toArray(), base, endian);
+ };
+
+ BN.prototype._initArray = function _initArray (number, base, endian) {
+ // Perhaps a Uint8Array
+ assert(typeof number.length === 'number');
+ if (number.length <= 0) {
+ this.words = [ 0 ];
+ this.length = 1;
+ return this;
+ }
+
+ this.length = Math.ceil(number.length / 3);
+ this.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ this.words[i] = 0;
+ }
+
+ var j, w;
+ var off = 0;
+ if (endian === 'be') {
+ for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
+ w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ } else if (endian === 'le') {
+ for (i = 0, j = 0; i < number.length; i += 3) {
+ w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ }
+ return this.strip();
+ };
+
+ function parseHex (str, start, end) {
+ var r = 0;
+ var len = Math.min(str.length, end);
+ for (var i = start; i < len; i++) {
+ var c = str.charCodeAt(i) - 48;
+
+ r <<= 4;
+
+ // 'a' - 'f'
+ if (c >= 49 && c <= 54) {
+ r |= c - 49 + 0xa;
+
+ // 'A' - 'F'
+ } else if (c >= 17 && c <= 22) {
+ r |= c - 17 + 0xa;
+
+ // '0' - '9'
+ } else {
+ r |= c & 0xf;
+ }
+ }
+ return r;
+ }
+
+ BN.prototype._parseHex = function _parseHex (number, start) {
+ // Create possibly bigger array to ensure that it fits the number
+ this.length = Math.ceil((number.length - start) / 6);
+ this.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ this.words[i] = 0;
+ }
+
+ var j, w;
+ // Scan 24-bit chunks and add them to the number
+ var off = 0;
+ for (i = number.length - 6, j = 0; i >= start; i -= 6) {
+ w = parseHex(number, i, i + 6);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
+ this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ if (i + 6 !== start) {
+ w = parseHex(number, start, i + 6);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
+ }
+ this.strip();
+ };
+
+ function parseBase (str, start, end, mul) {
+ var r = 0;
+ var len = Math.min(str.length, end);
+ for (var i = start; i < len; i++) {
+ var c = str.charCodeAt(i) - 48;
+
+ r *= mul;
+
+ // 'a'
+ if (c >= 49) {
+ r += c - 49 + 0xa;
+
+ // 'A'
+ } else if (c >= 17) {
+ r += c - 17 + 0xa;
+
+ // '0' - '9'
+ } else {
+ r += c;
+ }
+ }
+ return r;
+ }
+
+ BN.prototype._parseBase = function _parseBase (number, base, start) {
+ // Initialize as zero
+ this.words = [ 0 ];
+ this.length = 1;
+
+ // Find length of limb in base
+ for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
+ limbLen++;
+ }
+ limbLen--;
+ limbPow = (limbPow / base) | 0;
+
+ var total = number.length - start;
+ var mod = total % limbLen;
+ var end = Math.min(total, total - mod) + start;
+
+ var word = 0;
+ for (var i = start; i < end; i += limbLen) {
+ word = parseBase(number, i, i + limbLen, base);
+
+ this.imuln(limbPow);
+ if (this.words[0] + word < 0x4000000) {
+ this.words[0] += word;
+ } else {
+ this._iaddn(word);
+ }
+ }
+
+ if (mod !== 0) {
+ var pow = 1;
+ word = parseBase(number, i, number.length, base);
+
+ for (i = 0; i < mod; i++) {
+ pow *= base;
+ }
+
+ this.imuln(pow);
+ if (this.words[0] + word < 0x4000000) {
+ this.words[0] += word;
+ } else {
+ this._iaddn(word);
+ }
+ }
+ };
+
+ BN.prototype.copy = function copy (dest) {
+ dest.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ dest.words[i] = this.words[i];
+ }
+ dest.length = this.length;
+ dest.negative = this.negative;
+ dest.red = this.red;
+ };
+
+ BN.prototype.clone = function clone () {
+ var r = new BN(null);
+ this.copy(r);
+ return r;
+ };
+
+ BN.prototype._expand = function _expand (size) {
+ while (this.length < size) {
+ this.words[this.length++] = 0;
+ }
+ return this;
+ };
+
+ // Remove leading `0` from `this`
+ BN.prototype.strip = function strip () {
+ while (this.length > 1 && this.words[this.length - 1] === 0) {
+ this.length--;
+ }
+ return this._normSign();
+ };
+
+ BN.prototype._normSign = function _normSign () {
+ // -0 = 0
+ if (this.length === 1 && this.words[0] === 0) {
+ this.negative = 0;
+ }
+ return this;
+ };
+
+ BN.prototype.inspect = function inspect () {
+ return (this.red ? '';
+ };
+
+ /*
+
+ var zeros = [];
+ var groupSizes = [];
+ var groupBases = [];
+
+ var s = '';
+ var i = -1;
+ while (++i < BN.wordSize) {
+ zeros[i] = s;
+ s += '0';
+ }
+ groupSizes[0] = 0;
+ groupSizes[1] = 0;
+ groupBases[0] = 0;
+ groupBases[1] = 0;
+ var base = 2 - 1;
+ while (++base < 36 + 1) {
+ var groupSize = 0;
+ var groupBase = 1;
+ while (groupBase < (1 << BN.wordSize) / base) {
+ groupBase *= base;
+ groupSize += 1;
+ }
+ groupSizes[base] = groupSize;
+ groupBases[base] = groupBase;
+ }
+
+ */
+
+ var zeros = [
+ '',
+ '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'
+ ];
+
+ var groupSizes = [
+ 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
+ ];
+
+ var groupBases = [
+ 0, 0,
+ 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
+ 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
+ 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
+ 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
+ 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
+ ];
+
+ BN.prototype.toString = function toString (base, padding) {
+ base = base || 10;
+ padding = padding | 0 || 1;
+
+ var out;
+ if (base === 16 || base === 'hex') {
+ out = '';
+ var off = 0;
+ var carry = 0;
+ for (var i = 0; i < this.length; i++) {
+ var w = this.words[i];
+ var word = (((w << off) | carry) & 0xffffff).toString(16);
+ carry = (w >>> (24 - off)) & 0xffffff;
+ if (carry !== 0 || i !== this.length - 1) {
+ out = zeros[6 - word.length] + word + out;
+ } else {
+ out = word + out;
+ }
+ off += 2;
+ if (off >= 26) {
+ off -= 26;
+ i--;
+ }
+ }
+ if (carry !== 0) {
+ out = carry.toString(16) + out;
+ }
+ while (out.length % padding !== 0) {
+ out = '0' + out;
+ }
+ if (this.negative !== 0) {
+ out = '-' + out;
+ }
+ return out;
+ }
+
+ if (base === (base | 0) && base >= 2 && base <= 36) {
+ // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
+ var groupSize = groupSizes[base];
+ // var groupBase = Math.pow(base, groupSize);
+ var groupBase = groupBases[base];
+ out = '';
+ var c = this.clone();
+ c.negative = 0;
+ while (!c.isZero()) {
+ var r = c.modn(groupBase).toString(base);
+ c = c.idivn(groupBase);
+
+ if (!c.isZero()) {
+ out = zeros[groupSize - r.length] + r + out;
+ } else {
+ out = r + out;
+ }
+ }
+ if (this.isZero()) {
+ out = '0' + out;
+ }
+ while (out.length % padding !== 0) {
+ out = '0' + out;
+ }
+ if (this.negative !== 0) {
+ out = '-' + out;
+ }
+ return out;
+ }
+
+ assert(false, 'Base should be between 2 and 36');
+ };
+
+ BN.prototype.toNumber = function toNumber () {
+ var ret = this.words[0];
+ if (this.length === 2) {
+ ret += this.words[1] * 0x4000000;
+ } else if (this.length === 3 && this.words[2] === 0x01) {
+ // NOTE: at this stage it is known that the top bit is set
+ ret += 0x10000000000000 + (this.words[1] * 0x4000000);
+ } else if (this.length > 2) {
+ assert(false, 'Number can only safely store up to 53 bits');
+ }
+ return (this.negative !== 0) ? -ret : ret;
+ };
+
+ BN.prototype.toJSON = function toJSON () {
+ return this.toString(16);
+ };
+
+ BN.prototype.toBuffer = function toBuffer (endian, length) {
+ assert(typeof Buffer !== 'undefined');
+ return this.toArrayLike(Buffer, endian, length);
+ };
+
+ BN.prototype.toArray = function toArray (endian, length) {
+ return this.toArrayLike(Array, endian, length);
+ };
+
+ BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
+ var byteLength = this.byteLength();
+ var reqLength = length || Math.max(1, byteLength);
+ assert(byteLength <= reqLength, 'byte array longer than desired length');
+ assert(reqLength > 0, 'Requested array length <= 0');
+
+ this.strip();
+ var littleEndian = endian === 'le';
+ var res = new ArrayType(reqLength);
+
+ var b, i;
+ var q = this.clone();
+ if (!littleEndian) {
+ // Assume big-endian
+ for (i = 0; i < reqLength - byteLength; i++) {
+ res[i] = 0;
+ }
+
+ for (i = 0; !q.isZero(); i++) {
+ b = q.andln(0xff);
+ q.iushrn(8);
+
+ res[reqLength - i - 1] = b;
+ }
+ } else {
+ for (i = 0; !q.isZero(); i++) {
+ b = q.andln(0xff);
+ q.iushrn(8);
+
+ res[i] = b;
+ }
+
+ for (; i < reqLength; i++) {
+ res[i] = 0;
+ }
+ }
+
+ return res;
+ };
+
+ if (Math.clz32) {
+ BN.prototype._countBits = function _countBits (w) {
+ return 32 - Math.clz32(w);
+ };
+ } else {
+ BN.prototype._countBits = function _countBits (w) {
+ var t = w;
+ var r = 0;
+ if (t >= 0x1000) {
+ r += 13;
+ t >>>= 13;
+ }
+ if (t >= 0x40) {
+ r += 7;
+ t >>>= 7;
+ }
+ if (t >= 0x8) {
+ r += 4;
+ t >>>= 4;
+ }
+ if (t >= 0x02) {
+ r += 2;
+ t >>>= 2;
+ }
+ return r + t;
+ };
+ }
+
+ BN.prototype._zeroBits = function _zeroBits (w) {
+ // Short-cut
+ if (w === 0) return 26;
+
+ var t = w;
+ var r = 0;
+ if ((t & 0x1fff) === 0) {
+ r += 13;
+ t >>>= 13;
+ }
+ if ((t & 0x7f) === 0) {
+ r += 7;
+ t >>>= 7;
+ }
+ if ((t & 0xf) === 0) {
+ r += 4;
+ t >>>= 4;
+ }
+ if ((t & 0x3) === 0) {
+ r += 2;
+ t >>>= 2;
+ }
+ if ((t & 0x1) === 0) {
+ r++;
+ }
+ return r;
+ };
+
+ // Return number of used bits in a BN
+ BN.prototype.bitLength = function bitLength () {
+ var w = this.words[this.length - 1];
+ var hi = this._countBits(w);
+ return (this.length - 1) * 26 + hi;
+ };
+
+ function toBitArray (num) {
+ var w = new Array(num.bitLength());
+
+ for (var bit = 0; bit < w.length; bit++) {
+ var off = (bit / 26) | 0;
+ var wbit = bit % 26;
+
+ w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
+ }
+
+ return w;
+ }
+
+ // Number of trailing zero bits
+ BN.prototype.zeroBits = function zeroBits () {
+ if (this.isZero()) return 0;
+
+ var r = 0;
+ for (var i = 0; i < this.length; i++) {
+ var b = this._zeroBits(this.words[i]);
+ r += b;
+ if (b !== 26) break;
+ }
+ return r;
+ };
+
+ BN.prototype.byteLength = function byteLength () {
+ return Math.ceil(this.bitLength() / 8);
+ };
+
+ BN.prototype.toTwos = function toTwos (width) {
+ if (this.negative !== 0) {
+ return this.abs().inotn(width).iaddn(1);
+ }
+ return this.clone();
+ };
+
+ BN.prototype.fromTwos = function fromTwos (width) {
+ if (this.testn(width - 1)) {
+ return this.notn(width).iaddn(1).ineg();
+ }
+ return this.clone();
+ };
+
+ BN.prototype.isNeg = function isNeg () {
+ return this.negative !== 0;
+ };
+
+ // Return negative clone of `this`
+ BN.prototype.neg = function neg () {
+ return this.clone().ineg();
+ };
+
+ BN.prototype.ineg = function ineg () {
+ if (!this.isZero()) {
+ this.negative ^= 1;
+ }
+
+ return this;
+ };
+
+ // Or `num` with `this` in-place
+ BN.prototype.iuor = function iuor (num) {
+ while (this.length < num.length) {
+ this.words[this.length++] = 0;
+ }
+
+ for (var i = 0; i < num.length; i++) {
+ this.words[i] = this.words[i] | num.words[i];
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ior = function ior (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuor(num);
+ };
+
+ // Or `num` with `this`
+ BN.prototype.or = function or (num) {
+ if (this.length > num.length) return this.clone().ior(num);
+ return num.clone().ior(this);
+ };
+
+ BN.prototype.uor = function uor (num) {
+ if (this.length > num.length) return this.clone().iuor(num);
+ return num.clone().iuor(this);
+ };
+
+ // And `num` with `this` in-place
+ BN.prototype.iuand = function iuand (num) {
+ // b = min-length(num, this)
+ var b;
+ if (this.length > num.length) {
+ b = num;
+ } else {
+ b = this;
+ }
+
+ for (var i = 0; i < b.length; i++) {
+ this.words[i] = this.words[i] & num.words[i];
+ }
+
+ this.length = b.length;
+
+ return this.strip();
+ };
+
+ BN.prototype.iand = function iand (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuand(num);
+ };
+
+ // And `num` with `this`
+ BN.prototype.and = function and (num) {
+ if (this.length > num.length) return this.clone().iand(num);
+ return num.clone().iand(this);
+ };
+
+ BN.prototype.uand = function uand (num) {
+ if (this.length > num.length) return this.clone().iuand(num);
+ return num.clone().iuand(this);
+ };
+
+ // Xor `num` with `this` in-place
+ BN.prototype.iuxor = function iuxor (num) {
+ // a.length > b.length
+ var a;
+ var b;
+ if (this.length > num.length) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ for (var i = 0; i < b.length; i++) {
+ this.words[i] = a.words[i] ^ b.words[i];
+ }
+
+ if (this !== a) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ this.length = a.length;
+
+ return this.strip();
+ };
+
+ BN.prototype.ixor = function ixor (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuxor(num);
+ };
+
+ // Xor `num` with `this`
+ BN.prototype.xor = function xor (num) {
+ if (this.length > num.length) return this.clone().ixor(num);
+ return num.clone().ixor(this);
+ };
+
+ BN.prototype.uxor = function uxor (num) {
+ if (this.length > num.length) return this.clone().iuxor(num);
+ return num.clone().iuxor(this);
+ };
+
+ // Not ``this`` with ``width`` bitwidth
+ BN.prototype.inotn = function inotn (width) {
+ assert(typeof width === 'number' && width >= 0);
+
+ var bytesNeeded = Math.ceil(width / 26) | 0;
+ var bitsLeft = width % 26;
+
+ // Extend the buffer with leading zeroes
+ this._expand(bytesNeeded);
+
+ if (bitsLeft > 0) {
+ bytesNeeded--;
+ }
+
+ // Handle complete words
+ for (var i = 0; i < bytesNeeded; i++) {
+ this.words[i] = ~this.words[i] & 0x3ffffff;
+ }
+
+ // Handle the residue
+ if (bitsLeft > 0) {
+ this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
+ }
+
+ // And remove leading zeroes
+ return this.strip();
+ };
+
+ BN.prototype.notn = function notn (width) {
+ return this.clone().inotn(width);
+ };
+
+ // Set `bit` of `this`
+ BN.prototype.setn = function setn (bit, val) {
+ assert(typeof bit === 'number' && bit >= 0);
+
+ var off = (bit / 26) | 0;
+ var wbit = bit % 26;
+
+ this._expand(off + 1);
+
+ if (val) {
+ this.words[off] = this.words[off] | (1 << wbit);
+ } else {
+ this.words[off] = this.words[off] & ~(1 << wbit);
+ }
+
+ return this.strip();
+ };
+
+ // Add `num` to `this` in-place
+ BN.prototype.iadd = function iadd (num) {
+ var r;
+
+ // negative + positive
+ if (this.negative !== 0 && num.negative === 0) {
+ this.negative = 0;
+ r = this.isub(num);
+ this.negative ^= 1;
+ return this._normSign();
+
+ // positive + negative
+ } else if (this.negative === 0 && num.negative !== 0) {
+ num.negative = 0;
+ r = this.isub(num);
+ num.negative = 1;
+ return r._normSign();
+ }
+
+ // a.length > b.length
+ var a, b;
+ if (this.length > num.length) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ var carry = 0;
+ for (var i = 0; i < b.length; i++) {
+ r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
+ this.words[i] = r & 0x3ffffff;
+ carry = r >>> 26;
+ }
+ for (; carry !== 0 && i < a.length; i++) {
+ r = (a.words[i] | 0) + carry;
+ this.words[i] = r & 0x3ffffff;
+ carry = r >>> 26;
+ }
+
+ this.length = a.length;
+ if (carry !== 0) {
+ this.words[this.length] = carry;
+ this.length++;
+ // Copy the rest of the words
+ } else if (a !== this) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ return this;
+ };
+
+ // Add `num` to `this`
+ BN.prototype.add = function add (num) {
+ var res;
+ if (num.negative !== 0 && this.negative === 0) {
+ num.negative = 0;
+ res = this.sub(num);
+ num.negative ^= 1;
+ return res;
+ } else if (num.negative === 0 && this.negative !== 0) {
+ this.negative = 0;
+ res = num.sub(this);
+ this.negative = 1;
+ return res;
+ }
+
+ if (this.length > num.length) return this.clone().iadd(num);
+
+ return num.clone().iadd(this);
+ };
+
+ // Subtract `num` from `this` in-place
+ BN.prototype.isub = function isub (num) {
+ // this - (-num) = this + num
+ if (num.negative !== 0) {
+ num.negative = 0;
+ var r = this.iadd(num);
+ num.negative = 1;
+ return r._normSign();
+
+ // -this - num = -(this + num)
+ } else if (this.negative !== 0) {
+ this.negative = 0;
+ this.iadd(num);
+ this.negative = 1;
+ return this._normSign();
+ }
+
+ // At this point both numbers are positive
+ var cmp = this.cmp(num);
+
+ // Optimization - zeroify
+ if (cmp === 0) {
+ this.negative = 0;
+ this.length = 1;
+ this.words[0] = 0;
+ return this;
+ }
+
+ // a > b
+ var a, b;
+ if (cmp > 0) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ var carry = 0;
+ for (var i = 0; i < b.length; i++) {
+ r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
+ carry = r >> 26;
+ this.words[i] = r & 0x3ffffff;
+ }
+ for (; carry !== 0 && i < a.length; i++) {
+ r = (a.words[i] | 0) + carry;
+ carry = r >> 26;
+ this.words[i] = r & 0x3ffffff;
+ }
+
+ // Copy rest of the words
+ if (carry === 0 && i < a.length && a !== this) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ this.length = Math.max(this.length, i);
+
+ if (a !== this) {
+ this.negative = 1;
+ }
+
+ return this.strip();
+ };
+
+ // Subtract `num` from `this`
+ BN.prototype.sub = function sub (num) {
+ return this.clone().isub(num);
+ };
+
+ function smallMulTo (self, num, out) {
+ out.negative = num.negative ^ self.negative;
+ var len = (self.length + num.length) | 0;
+ out.length = len;
+ len = (len - 1) | 0;
+
+ // Peel one iteration (compiler can't do it, because of code complexity)
+ var a = self.words[0] | 0;
+ var b = num.words[0] | 0;
+ var r = a * b;
+
+ var lo = r & 0x3ffffff;
+ var carry = (r / 0x4000000) | 0;
+ out.words[0] = lo;
+
+ for (var k = 1; k < len; k++) {
+ // Sum all words with the same `i + j = k` and accumulate `ncarry`,
+ // note that ncarry could be >= 0x3ffffff
+ var ncarry = carry >>> 26;
+ var rword = carry & 0x3ffffff;
+ var maxJ = Math.min(k, num.length - 1);
+ for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
+ var i = (k - j) | 0;
+ a = self.words[i] | 0;
+ b = num.words[j] | 0;
+ r = a * b + rword;
+ ncarry += (r / 0x4000000) | 0;
+ rword = r & 0x3ffffff;
+ }
+ out.words[k] = rword | 0;
+ carry = ncarry | 0;
+ }
+ if (carry !== 0) {
+ out.words[k] = carry | 0;
+ } else {
+ out.length--;
+ }
+
+ return out.strip();
+ }
+
+ // TODO(indutny): it may be reasonable to omit it for users who don't need
+ // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
+ // multiplication (like elliptic secp256k1).
+ var comb10MulTo = function comb10MulTo (self, num, out) {
+ var a = self.words;
+ var b = num.words;
+ var o = out.words;
+ var c = 0;
+ var lo;
+ var mid;
+ var hi;
+ var a0 = a[0] | 0;
+ var al0 = a0 & 0x1fff;
+ var ah0 = a0 >>> 13;
+ var a1 = a[1] | 0;
+ var al1 = a1 & 0x1fff;
+ var ah1 = a1 >>> 13;
+ var a2 = a[2] | 0;
+ var al2 = a2 & 0x1fff;
+ var ah2 = a2 >>> 13;
+ var a3 = a[3] | 0;
+ var al3 = a3 & 0x1fff;
+ var ah3 = a3 >>> 13;
+ var a4 = a[4] | 0;
+ var al4 = a4 & 0x1fff;
+ var ah4 = a4 >>> 13;
+ var a5 = a[5] | 0;
+ var al5 = a5 & 0x1fff;
+ var ah5 = a5 >>> 13;
+ var a6 = a[6] | 0;
+ var al6 = a6 & 0x1fff;
+ var ah6 = a6 >>> 13;
+ var a7 = a[7] | 0;
+ var al7 = a7 & 0x1fff;
+ var ah7 = a7 >>> 13;
+ var a8 = a[8] | 0;
+ var al8 = a8 & 0x1fff;
+ var ah8 = a8 >>> 13;
+ var a9 = a[9] | 0;
+ var al9 = a9 & 0x1fff;
+ var ah9 = a9 >>> 13;
+ var b0 = b[0] | 0;
+ var bl0 = b0 & 0x1fff;
+ var bh0 = b0 >>> 13;
+ var b1 = b[1] | 0;
+ var bl1 = b1 & 0x1fff;
+ var bh1 = b1 >>> 13;
+ var b2 = b[2] | 0;
+ var bl2 = b2 & 0x1fff;
+ var bh2 = b2 >>> 13;
+ var b3 = b[3] | 0;
+ var bl3 = b3 & 0x1fff;
+ var bh3 = b3 >>> 13;
+ var b4 = b[4] | 0;
+ var bl4 = b4 & 0x1fff;
+ var bh4 = b4 >>> 13;
+ var b5 = b[5] | 0;
+ var bl5 = b5 & 0x1fff;
+ var bh5 = b5 >>> 13;
+ var b6 = b[6] | 0;
+ var bl6 = b6 & 0x1fff;
+ var bh6 = b6 >>> 13;
+ var b7 = b[7] | 0;
+ var bl7 = b7 & 0x1fff;
+ var bh7 = b7 >>> 13;
+ var b8 = b[8] | 0;
+ var bl8 = b8 & 0x1fff;
+ var bh8 = b8 >>> 13;
+ var b9 = b[9] | 0;
+ var bl9 = b9 & 0x1fff;
+ var bh9 = b9 >>> 13;
+
+ out.negative = self.negative ^ num.negative;
+ out.length = 19;
+ /* k = 0 */
+ lo = Math.imul(al0, bl0);
+ mid = Math.imul(al0, bh0);
+ mid = (mid + Math.imul(ah0, bl0)) | 0;
+ hi = Math.imul(ah0, bh0);
+ var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
+ w0 &= 0x3ffffff;
+ /* k = 1 */
+ lo = Math.imul(al1, bl0);
+ mid = Math.imul(al1, bh0);
+ mid = (mid + Math.imul(ah1, bl0)) | 0;
+ hi = Math.imul(ah1, bh0);
+ lo = (lo + Math.imul(al0, bl1)) | 0;
+ mid = (mid + Math.imul(al0, bh1)) | 0;
+ mid = (mid + Math.imul(ah0, bl1)) | 0;
+ hi = (hi + Math.imul(ah0, bh1)) | 0;
+ var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
+ w1 &= 0x3ffffff;
+ /* k = 2 */
+ lo = Math.imul(al2, bl0);
+ mid = Math.imul(al2, bh0);
+ mid = (mid + Math.imul(ah2, bl0)) | 0;
+ hi = Math.imul(ah2, bh0);
+ lo = (lo + Math.imul(al1, bl1)) | 0;
+ mid = (mid + Math.imul(al1, bh1)) | 0;
+ mid = (mid + Math.imul(ah1, bl1)) | 0;
+ hi = (hi + Math.imul(ah1, bh1)) | 0;
+ lo = (lo + Math.imul(al0, bl2)) | 0;
+ mid = (mid + Math.imul(al0, bh2)) | 0;
+ mid = (mid + Math.imul(ah0, bl2)) | 0;
+ hi = (hi + Math.imul(ah0, bh2)) | 0;
+ var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
+ w2 &= 0x3ffffff;
+ /* k = 3 */
+ lo = Math.imul(al3, bl0);
+ mid = Math.imul(al3, bh0);
+ mid = (mid + Math.imul(ah3, bl0)) | 0;
+ hi = Math.imul(ah3, bh0);
+ lo = (lo + Math.imul(al2, bl1)) | 0;
+ mid = (mid + Math.imul(al2, bh1)) | 0;
+ mid = (mid + Math.imul(ah2, bl1)) | 0;
+ hi = (hi + Math.imul(ah2, bh1)) | 0;
+ lo = (lo + Math.imul(al1, bl2)) | 0;
+ mid = (mid + Math.imul(al1, bh2)) | 0;
+ mid = (mid + Math.imul(ah1, bl2)) | 0;
+ hi = (hi + Math.imul(ah1, bh2)) | 0;
+ lo = (lo + Math.imul(al0, bl3)) | 0;
+ mid = (mid + Math.imul(al0, bh3)) | 0;
+ mid = (mid + Math.imul(ah0, bl3)) | 0;
+ hi = (hi + Math.imul(ah0, bh3)) | 0;
+ var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
+ w3 &= 0x3ffffff;
+ /* k = 4 */
+ lo = Math.imul(al4, bl0);
+ mid = Math.imul(al4, bh0);
+ mid = (mid + Math.imul(ah4, bl0)) | 0;
+ hi = Math.imul(ah4, bh0);
+ lo = (lo + Math.imul(al3, bl1)) | 0;
+ mid = (mid + Math.imul(al3, bh1)) | 0;
+ mid = (mid + Math.imul(ah3, bl1)) | 0;
+ hi = (hi + Math.imul(ah3, bh1)) | 0;
+ lo = (lo + Math.imul(al2, bl2)) | 0;
+ mid = (mid + Math.imul(al2, bh2)) | 0;
+ mid = (mid + Math.imul(ah2, bl2)) | 0;
+ hi = (hi + Math.imul(ah2, bh2)) | 0;
+ lo = (lo + Math.imul(al1, bl3)) | 0;
+ mid = (mid + Math.imul(al1, bh3)) | 0;
+ mid = (mid + Math.imul(ah1, bl3)) | 0;
+ hi = (hi + Math.imul(ah1, bh3)) | 0;
+ lo = (lo + Math.imul(al0, bl4)) | 0;
+ mid = (mid + Math.imul(al0, bh4)) | 0;
+ mid = (mid + Math.imul(ah0, bl4)) | 0;
+ hi = (hi + Math.imul(ah0, bh4)) | 0;
+ var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
+ w4 &= 0x3ffffff;
+ /* k = 5 */
+ lo = Math.imul(al5, bl0);
+ mid = Math.imul(al5, bh0);
+ mid = (mid + Math.imul(ah5, bl0)) | 0;
+ hi = Math.imul(ah5, bh0);
+ lo = (lo + Math.imul(al4, bl1)) | 0;
+ mid = (mid + Math.imul(al4, bh1)) | 0;
+ mid = (mid + Math.imul(ah4, bl1)) | 0;
+ hi = (hi + Math.imul(ah4, bh1)) | 0;
+ lo = (lo + Math.imul(al3, bl2)) | 0;
+ mid = (mid + Math.imul(al3, bh2)) | 0;
+ mid = (mid + Math.imul(ah3, bl2)) | 0;
+ hi = (hi + Math.imul(ah3, bh2)) | 0;
+ lo = (lo + Math.imul(al2, bl3)) | 0;
+ mid = (mid + Math.imul(al2, bh3)) | 0;
+ mid = (mid + Math.imul(ah2, bl3)) | 0;
+ hi = (hi + Math.imul(ah2, bh3)) | 0;
+ lo = (lo + Math.imul(al1, bl4)) | 0;
+ mid = (mid + Math.imul(al1, bh4)) | 0;
+ mid = (mid + Math.imul(ah1, bl4)) | 0;
+ hi = (hi + Math.imul(ah1, bh4)) | 0;
+ lo = (lo + Math.imul(al0, bl5)) | 0;
+ mid = (mid + Math.imul(al0, bh5)) | 0;
+ mid = (mid + Math.imul(ah0, bl5)) | 0;
+ hi = (hi + Math.imul(ah0, bh5)) | 0;
+ var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
+ w5 &= 0x3ffffff;
+ /* k = 6 */
+ lo = Math.imul(al6, bl0);
+ mid = Math.imul(al6, bh0);
+ mid = (mid + Math.imul(ah6, bl0)) | 0;
+ hi = Math.imul(ah6, bh0);
+ lo = (lo + Math.imul(al5, bl1)) | 0;
+ mid = (mid + Math.imul(al5, bh1)) | 0;
+ mid = (mid + Math.imul(ah5, bl1)) | 0;
+ hi = (hi + Math.imul(ah5, bh1)) | 0;
+ lo = (lo + Math.imul(al4, bl2)) | 0;
+ mid = (mid + Math.imul(al4, bh2)) | 0;
+ mid = (mid + Math.imul(ah4, bl2)) | 0;
+ hi = (hi + Math.imul(ah4, bh2)) | 0;
+ lo = (lo + Math.imul(al3, bl3)) | 0;
+ mid = (mid + Math.imul(al3, bh3)) | 0;
+ mid = (mid + Math.imul(ah3, bl3)) | 0;
+ hi = (hi + Math.imul(ah3, bh3)) | 0;
+ lo = (lo + Math.imul(al2, bl4)) | 0;
+ mid = (mid + Math.imul(al2, bh4)) | 0;
+ mid = (mid + Math.imul(ah2, bl4)) | 0;
+ hi = (hi + Math.imul(ah2, bh4)) | 0;
+ lo = (lo + Math.imul(al1, bl5)) | 0;
+ mid = (mid + Math.imul(al1, bh5)) | 0;
+ mid = (mid + Math.imul(ah1, bl5)) | 0;
+ hi = (hi + Math.imul(ah1, bh5)) | 0;
+ lo = (lo + Math.imul(al0, bl6)) | 0;
+ mid = (mid + Math.imul(al0, bh6)) | 0;
+ mid = (mid + Math.imul(ah0, bl6)) | 0;
+ hi = (hi + Math.imul(ah0, bh6)) | 0;
+ var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
+ w6 &= 0x3ffffff;
+ /* k = 7 */
+ lo = Math.imul(al7, bl0);
+ mid = Math.imul(al7, bh0);
+ mid = (mid + Math.imul(ah7, bl0)) | 0;
+ hi = Math.imul(ah7, bh0);
+ lo = (lo + Math.imul(al6, bl1)) | 0;
+ mid = (mid + Math.imul(al6, bh1)) | 0;
+ mid = (mid + Math.imul(ah6, bl1)) | 0;
+ hi = (hi + Math.imul(ah6, bh1)) | 0;
+ lo = (lo + Math.imul(al5, bl2)) | 0;
+ mid = (mid + Math.imul(al5, bh2)) | 0;
+ mid = (mid + Math.imul(ah5, bl2)) | 0;
+ hi = (hi + Math.imul(ah5, bh2)) | 0;
+ lo = (lo + Math.imul(al4, bl3)) | 0;
+ mid = (mid + Math.imul(al4, bh3)) | 0;
+ mid = (mid + Math.imul(ah4, bl3)) | 0;
+ hi = (hi + Math.imul(ah4, bh3)) | 0;
+ lo = (lo + Math.imul(al3, bl4)) | 0;
+ mid = (mid + Math.imul(al3, bh4)) | 0;
+ mid = (mid + Math.imul(ah3, bl4)) | 0;
+ hi = (hi + Math.imul(ah3, bh4)) | 0;
+ lo = (lo + Math.imul(al2, bl5)) | 0;
+ mid = (mid + Math.imul(al2, bh5)) | 0;
+ mid = (mid + Math.imul(ah2, bl5)) | 0;
+ hi = (hi + Math.imul(ah2, bh5)) | 0;
+ lo = (lo + Math.imul(al1, bl6)) | 0;
+ mid = (mid + Math.imul(al1, bh6)) | 0;
+ mid = (mid + Math.imul(ah1, bl6)) | 0;
+ hi = (hi + Math.imul(ah1, bh6)) | 0;
+ lo = (lo + Math.imul(al0, bl7)) | 0;
+ mid = (mid + Math.imul(al0, bh7)) | 0;
+ mid = (mid + Math.imul(ah0, bl7)) | 0;
+ hi = (hi + Math.imul(ah0, bh7)) | 0;
+ var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
+ w7 &= 0x3ffffff;
+ /* k = 8 */
+ lo = Math.imul(al8, bl0);
+ mid = Math.imul(al8, bh0);
+ mid = (mid + Math.imul(ah8, bl0)) | 0;
+ hi = Math.imul(ah8, bh0);
+ lo = (lo + Math.imul(al7, bl1)) | 0;
+ mid = (mid + Math.imul(al7, bh1)) | 0;
+ mid = (mid + Math.imul(ah7, bl1)) | 0;
+ hi = (hi + Math.imul(ah7, bh1)) | 0;
+ lo = (lo + Math.imul(al6, bl2)) | 0;
+ mid = (mid + Math.imul(al6, bh2)) | 0;
+ mid = (mid + Math.imul(ah6, bl2)) | 0;
+ hi = (hi + Math.imul(ah6, bh2)) | 0;
+ lo = (lo + Math.imul(al5, bl3)) | 0;
+ mid = (mid + Math.imul(al5, bh3)) | 0;
+ mid = (mid + Math.imul(ah5, bl3)) | 0;
+ hi = (hi + Math.imul(ah5, bh3)) | 0;
+ lo = (lo + Math.imul(al4, bl4)) | 0;
+ mid = (mid + Math.imul(al4, bh4)) | 0;
+ mid = (mid + Math.imul(ah4, bl4)) | 0;
+ hi = (hi + Math.imul(ah4, bh4)) | 0;
+ lo = (lo + Math.imul(al3, bl5)) | 0;
+ mid = (mid + Math.imul(al3, bh5)) | 0;
+ mid = (mid + Math.imul(ah3, bl5)) | 0;
+ hi = (hi + Math.imul(ah3, bh5)) | 0;
+ lo = (lo + Math.imul(al2, bl6)) | 0;
+ mid = (mid + Math.imul(al2, bh6)) | 0;
+ mid = (mid + Math.imul(ah2, bl6)) | 0;
+ hi = (hi + Math.imul(ah2, bh6)) | 0;
+ lo = (lo + Math.imul(al1, bl7)) | 0;
+ mid = (mid + Math.imul(al1, bh7)) | 0;
+ mid = (mid + Math.imul(ah1, bl7)) | 0;
+ hi = (hi + Math.imul(ah1, bh7)) | 0;
+ lo = (lo + Math.imul(al0, bl8)) | 0;
+ mid = (mid + Math.imul(al0, bh8)) | 0;
+ mid = (mid + Math.imul(ah0, bl8)) | 0;
+ hi = (hi + Math.imul(ah0, bh8)) | 0;
+ var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
+ w8 &= 0x3ffffff;
+ /* k = 9 */
+ lo = Math.imul(al9, bl0);
+ mid = Math.imul(al9, bh0);
+ mid = (mid + Math.imul(ah9, bl0)) | 0;
+ hi = Math.imul(ah9, bh0);
+ lo = (lo + Math.imul(al8, bl1)) | 0;
+ mid = (mid + Math.imul(al8, bh1)) | 0;
+ mid = (mid + Math.imul(ah8, bl1)) | 0;
+ hi = (hi + Math.imul(ah8, bh1)) | 0;
+ lo = (lo + Math.imul(al7, bl2)) | 0;
+ mid = (mid + Math.imul(al7, bh2)) | 0;
+ mid = (mid + Math.imul(ah7, bl2)) | 0;
+ hi = (hi + Math.imul(ah7, bh2)) | 0;
+ lo = (lo + Math.imul(al6, bl3)) | 0;
+ mid = (mid + Math.imul(al6, bh3)) | 0;
+ mid = (mid + Math.imul(ah6, bl3)) | 0;
+ hi = (hi + Math.imul(ah6, bh3)) | 0;
+ lo = (lo + Math.imul(al5, bl4)) | 0;
+ mid = (mid + Math.imul(al5, bh4)) | 0;
+ mid = (mid + Math.imul(ah5, bl4)) | 0;
+ hi = (hi + Math.imul(ah5, bh4)) | 0;
+ lo = (lo + Math.imul(al4, bl5)) | 0;
+ mid = (mid + Math.imul(al4, bh5)) | 0;
+ mid = (mid + Math.imul(ah4, bl5)) | 0;
+ hi = (hi + Math.imul(ah4, bh5)) | 0;
+ lo = (lo + Math.imul(al3, bl6)) | 0;
+ mid = (mid + Math.imul(al3, bh6)) | 0;
+ mid = (mid + Math.imul(ah3, bl6)) | 0;
+ hi = (hi + Math.imul(ah3, bh6)) | 0;
+ lo = (lo + Math.imul(al2, bl7)) | 0;
+ mid = (mid + Math.imul(al2, bh7)) | 0;
+ mid = (mid + Math.imul(ah2, bl7)) | 0;
+ hi = (hi + Math.imul(ah2, bh7)) | 0;
+ lo = (lo + Math.imul(al1, bl8)) | 0;
+ mid = (mid + Math.imul(al1, bh8)) | 0;
+ mid = (mid + Math.imul(ah1, bl8)) | 0;
+ hi = (hi + Math.imul(ah1, bh8)) | 0;
+ lo = (lo + Math.imul(al0, bl9)) | 0;
+ mid = (mid + Math.imul(al0, bh9)) | 0;
+ mid = (mid + Math.imul(ah0, bl9)) | 0;
+ hi = (hi + Math.imul(ah0, bh9)) | 0;
+ var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
+ w9 &= 0x3ffffff;
+ /* k = 10 */
+ lo = Math.imul(al9, bl1);
+ mid = Math.imul(al9, bh1);
+ mid = (mid + Math.imul(ah9, bl1)) | 0;
+ hi = Math.imul(ah9, bh1);
+ lo = (lo + Math.imul(al8, bl2)) | 0;
+ mid = (mid + Math.imul(al8, bh2)) | 0;
+ mid = (mid + Math.imul(ah8, bl2)) | 0;
+ hi = (hi + Math.imul(ah8, bh2)) | 0;
+ lo = (lo + Math.imul(al7, bl3)) | 0;
+ mid = (mid + Math.imul(al7, bh3)) | 0;
+ mid = (mid + Math.imul(ah7, bl3)) | 0;
+ hi = (hi + Math.imul(ah7, bh3)) | 0;
+ lo = (lo + Math.imul(al6, bl4)) | 0;
+ mid = (mid + Math.imul(al6, bh4)) | 0;
+ mid = (mid + Math.imul(ah6, bl4)) | 0;
+ hi = (hi + Math.imul(ah6, bh4)) | 0;
+ lo = (lo + Math.imul(al5, bl5)) | 0;
+ mid = (mid + Math.imul(al5, bh5)) | 0;
+ mid = (mid + Math.imul(ah5, bl5)) | 0;
+ hi = (hi + Math.imul(ah5, bh5)) | 0;
+ lo = (lo + Math.imul(al4, bl6)) | 0;
+ mid = (mid + Math.imul(al4, bh6)) | 0;
+ mid = (mid + Math.imul(ah4, bl6)) | 0;
+ hi = (hi + Math.imul(ah4, bh6)) | 0;
+ lo = (lo + Math.imul(al3, bl7)) | 0;
+ mid = (mid + Math.imul(al3, bh7)) | 0;
+ mid = (mid + Math.imul(ah3, bl7)) | 0;
+ hi = (hi + Math.imul(ah3, bh7)) | 0;
+ lo = (lo + Math.imul(al2, bl8)) | 0;
+ mid = (mid + Math.imul(al2, bh8)) | 0;
+ mid = (mid + Math.imul(ah2, bl8)) | 0;
+ hi = (hi + Math.imul(ah2, bh8)) | 0;
+ lo = (lo + Math.imul(al1, bl9)) | 0;
+ mid = (mid + Math.imul(al1, bh9)) | 0;
+ mid = (mid + Math.imul(ah1, bl9)) | 0;
+ hi = (hi + Math.imul(ah1, bh9)) | 0;
+ var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
+ w10 &= 0x3ffffff;
+ /* k = 11 */
+ lo = Math.imul(al9, bl2);
+ mid = Math.imul(al9, bh2);
+ mid = (mid + Math.imul(ah9, bl2)) | 0;
+ hi = Math.imul(ah9, bh2);
+ lo = (lo + Math.imul(al8, bl3)) | 0;
+ mid = (mid + Math.imul(al8, bh3)) | 0;
+ mid = (mid + Math.imul(ah8, bl3)) | 0;
+ hi = (hi + Math.imul(ah8, bh3)) | 0;
+ lo = (lo + Math.imul(al7, bl4)) | 0;
+ mid = (mid + Math.imul(al7, bh4)) | 0;
+ mid = (mid + Math.imul(ah7, bl4)) | 0;
+ hi = (hi + Math.imul(ah7, bh4)) | 0;
+ lo = (lo + Math.imul(al6, bl5)) | 0;
+ mid = (mid + Math.imul(al6, bh5)) | 0;
+ mid = (mid + Math.imul(ah6, bl5)) | 0;
+ hi = (hi + Math.imul(ah6, bh5)) | 0;
+ lo = (lo + Math.imul(al5, bl6)) | 0;
+ mid = (mid + Math.imul(al5, bh6)) | 0;
+ mid = (mid + Math.imul(ah5, bl6)) | 0;
+ hi = (hi + Math.imul(ah5, bh6)) | 0;
+ lo = (lo + Math.imul(al4, bl7)) | 0;
+ mid = (mid + Math.imul(al4, bh7)) | 0;
+ mid = (mid + Math.imul(ah4, bl7)) | 0;
+ hi = (hi + Math.imul(ah4, bh7)) | 0;
+ lo = (lo + Math.imul(al3, bl8)) | 0;
+ mid = (mid + Math.imul(al3, bh8)) | 0;
+ mid = (mid + Math.imul(ah3, bl8)) | 0;
+ hi = (hi + Math.imul(ah3, bh8)) | 0;
+ lo = (lo + Math.imul(al2, bl9)) | 0;
+ mid = (mid + Math.imul(al2, bh9)) | 0;
+ mid = (mid + Math.imul(ah2, bl9)) | 0;
+ hi = (hi + Math.imul(ah2, bh9)) | 0;
+ var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
+ w11 &= 0x3ffffff;
+ /* k = 12 */
+ lo = Math.imul(al9, bl3);
+ mid = Math.imul(al9, bh3);
+ mid = (mid + Math.imul(ah9, bl3)) | 0;
+ hi = Math.imul(ah9, bh3);
+ lo = (lo + Math.imul(al8, bl4)) | 0;
+ mid = (mid + Math.imul(al8, bh4)) | 0;
+ mid = (mid + Math.imul(ah8, bl4)) | 0;
+ hi = (hi + Math.imul(ah8, bh4)) | 0;
+ lo = (lo + Math.imul(al7, bl5)) | 0;
+ mid = (mid + Math.imul(al7, bh5)) | 0;
+ mid = (mid + Math.imul(ah7, bl5)) | 0;
+ hi = (hi + Math.imul(ah7, bh5)) | 0;
+ lo = (lo + Math.imul(al6, bl6)) | 0;
+ mid = (mid + Math.imul(al6, bh6)) | 0;
+ mid = (mid + Math.imul(ah6, bl6)) | 0;
+ hi = (hi + Math.imul(ah6, bh6)) | 0;
+ lo = (lo + Math.imul(al5, bl7)) | 0;
+ mid = (mid + Math.imul(al5, bh7)) | 0;
+ mid = (mid + Math.imul(ah5, bl7)) | 0;
+ hi = (hi + Math.imul(ah5, bh7)) | 0;
+ lo = (lo + Math.imul(al4, bl8)) | 0;
+ mid = (mid + Math.imul(al4, bh8)) | 0;
+ mid = (mid + Math.imul(ah4, bl8)) | 0;
+ hi = (hi + Math.imul(ah4, bh8)) | 0;
+ lo = (lo + Math.imul(al3, bl9)) | 0;
+ mid = (mid + Math.imul(al3, bh9)) | 0;
+ mid = (mid + Math.imul(ah3, bl9)) | 0;
+ hi = (hi + Math.imul(ah3, bh9)) | 0;
+ var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
+ w12 &= 0x3ffffff;
+ /* k = 13 */
+ lo = Math.imul(al9, bl4);
+ mid = Math.imul(al9, bh4);
+ mid = (mid + Math.imul(ah9, bl4)) | 0;
+ hi = Math.imul(ah9, bh4);
+ lo = (lo + Math.imul(al8, bl5)) | 0;
+ mid = (mid + Math.imul(al8, bh5)) | 0;
+ mid = (mid + Math.imul(ah8, bl5)) | 0;
+ hi = (hi + Math.imul(ah8, bh5)) | 0;
+ lo = (lo + Math.imul(al7, bl6)) | 0;
+ mid = (mid + Math.imul(al7, bh6)) | 0;
+ mid = (mid + Math.imul(ah7, bl6)) | 0;
+ hi = (hi + Math.imul(ah7, bh6)) | 0;
+ lo = (lo + Math.imul(al6, bl7)) | 0;
+ mid = (mid + Math.imul(al6, bh7)) | 0;
+ mid = (mid + Math.imul(ah6, bl7)) | 0;
+ hi = (hi + Math.imul(ah6, bh7)) | 0;
+ lo = (lo + Math.imul(al5, bl8)) | 0;
+ mid = (mid + Math.imul(al5, bh8)) | 0;
+ mid = (mid + Math.imul(ah5, bl8)) | 0;
+ hi = (hi + Math.imul(ah5, bh8)) | 0;
+ lo = (lo + Math.imul(al4, bl9)) | 0;
+ mid = (mid + Math.imul(al4, bh9)) | 0;
+ mid = (mid + Math.imul(ah4, bl9)) | 0;
+ hi = (hi + Math.imul(ah4, bh9)) | 0;
+ var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
+ w13 &= 0x3ffffff;
+ /* k = 14 */
+ lo = Math.imul(al9, bl5);
+ mid = Math.imul(al9, bh5);
+ mid = (mid + Math.imul(ah9, bl5)) | 0;
+ hi = Math.imul(ah9, bh5);
+ lo = (lo + Math.imul(al8, bl6)) | 0;
+ mid = (mid + Math.imul(al8, bh6)) | 0;
+ mid = (mid + Math.imul(ah8, bl6)) | 0;
+ hi = (hi + Math.imul(ah8, bh6)) | 0;
+ lo = (lo + Math.imul(al7, bl7)) | 0;
+ mid = (mid + Math.imul(al7, bh7)) | 0;
+ mid = (mid + Math.imul(ah7, bl7)) | 0;
+ hi = (hi + Math.imul(ah7, bh7)) | 0;
+ lo = (lo + Math.imul(al6, bl8)) | 0;
+ mid = (mid + Math.imul(al6, bh8)) | 0;
+ mid = (mid + Math.imul(ah6, bl8)) | 0;
+ hi = (hi + Math.imul(ah6, bh8)) | 0;
+ lo = (lo + Math.imul(al5, bl9)) | 0;
+ mid = (mid + Math.imul(al5, bh9)) | 0;
+ mid = (mid + Math.imul(ah5, bl9)) | 0;
+ hi = (hi + Math.imul(ah5, bh9)) | 0;
+ var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
+ w14 &= 0x3ffffff;
+ /* k = 15 */
+ lo = Math.imul(al9, bl6);
+ mid = Math.imul(al9, bh6);
+ mid = (mid + Math.imul(ah9, bl6)) | 0;
+ hi = Math.imul(ah9, bh6);
+ lo = (lo + Math.imul(al8, bl7)) | 0;
+ mid = (mid + Math.imul(al8, bh7)) | 0;
+ mid = (mid + Math.imul(ah8, bl7)) | 0;
+ hi = (hi + Math.imul(ah8, bh7)) | 0;
+ lo = (lo + Math.imul(al7, bl8)) | 0;
+ mid = (mid + Math.imul(al7, bh8)) | 0;
+ mid = (mid + Math.imul(ah7, bl8)) | 0;
+ hi = (hi + Math.imul(ah7, bh8)) | 0;
+ lo = (lo + Math.imul(al6, bl9)) | 0;
+ mid = (mid + Math.imul(al6, bh9)) | 0;
+ mid = (mid + Math.imul(ah6, bl9)) | 0;
+ hi = (hi + Math.imul(ah6, bh9)) | 0;
+ var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
+ w15 &= 0x3ffffff;
+ /* k = 16 */
+ lo = Math.imul(al9, bl7);
+ mid = Math.imul(al9, bh7);
+ mid = (mid + Math.imul(ah9, bl7)) | 0;
+ hi = Math.imul(ah9, bh7);
+ lo = (lo + Math.imul(al8, bl8)) | 0;
+ mid = (mid + Math.imul(al8, bh8)) | 0;
+ mid = (mid + Math.imul(ah8, bl8)) | 0;
+ hi = (hi + Math.imul(ah8, bh8)) | 0;
+ lo = (lo + Math.imul(al7, bl9)) | 0;
+ mid = (mid + Math.imul(al7, bh9)) | 0;
+ mid = (mid + Math.imul(ah7, bl9)) | 0;
+ hi = (hi + Math.imul(ah7, bh9)) | 0;
+ var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
+ w16 &= 0x3ffffff;
+ /* k = 17 */
+ lo = Math.imul(al9, bl8);
+ mid = Math.imul(al9, bh8);
+ mid = (mid + Math.imul(ah9, bl8)) | 0;
+ hi = Math.imul(ah9, bh8);
+ lo = (lo + Math.imul(al8, bl9)) | 0;
+ mid = (mid + Math.imul(al8, bh9)) | 0;
+ mid = (mid + Math.imul(ah8, bl9)) | 0;
+ hi = (hi + Math.imul(ah8, bh9)) | 0;
+ var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
+ w17 &= 0x3ffffff;
+ /* k = 18 */
+ lo = Math.imul(al9, bl9);
+ mid = Math.imul(al9, bh9);
+ mid = (mid + Math.imul(ah9, bl9)) | 0;
+ hi = Math.imul(ah9, bh9);
+ var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
+ w18 &= 0x3ffffff;
+ o[0] = w0;
+ o[1] = w1;
+ o[2] = w2;
+ o[3] = w3;
+ o[4] = w4;
+ o[5] = w5;
+ o[6] = w6;
+ o[7] = w7;
+ o[8] = w8;
+ o[9] = w9;
+ o[10] = w10;
+ o[11] = w11;
+ o[12] = w12;
+ o[13] = w13;
+ o[14] = w14;
+ o[15] = w15;
+ o[16] = w16;
+ o[17] = w17;
+ o[18] = w18;
+ if (c !== 0) {
+ o[19] = c;
+ out.length++;
+ }
+ return out;
+ };
+
+ // Polyfill comb
+ if (!Math.imul) {
+ comb10MulTo = smallMulTo;
+ }
+
+ function bigMulTo (self, num, out) {
+ out.negative = num.negative ^ self.negative;
+ out.length = self.length + num.length;
+
+ var carry = 0;
+ var hncarry = 0;
+ for (var k = 0; k < out.length - 1; k++) {
+ // Sum all words with the same `i + j = k` and accumulate `ncarry`,
+ // note that ncarry could be >= 0x3ffffff
+ var ncarry = hncarry;
+ hncarry = 0;
+ var rword = carry & 0x3ffffff;
+ var maxJ = Math.min(k, num.length - 1);
+ for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
+ var i = k - j;
+ var a = self.words[i] | 0;
+ var b = num.words[j] | 0;
+ var r = a * b;
+
+ var lo = r & 0x3ffffff;
+ ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
+ lo = (lo + rword) | 0;
+ rword = lo & 0x3ffffff;
+ ncarry = (ncarry + (lo >>> 26)) | 0;
+
+ hncarry += ncarry >>> 26;
+ ncarry &= 0x3ffffff;
+ }
+ out.words[k] = rword;
+ carry = ncarry;
+ ncarry = hncarry;
+ }
+ if (carry !== 0) {
+ out.words[k] = carry;
+ } else {
+ out.length--;
+ }
+
+ return out.strip();
+ }
+
+ function jumboMulTo (self, num, out) {
+ var fftm = new FFTM();
+ return fftm.mulp(self, num, out);
+ }
+
+ BN.prototype.mulTo = function mulTo (num, out) {
+ var res;
+ var len = this.length + num.length;
+ if (this.length === 10 && num.length === 10) {
+ res = comb10MulTo(this, num, out);
+ } else if (len < 63) {
+ res = smallMulTo(this, num, out);
+ } else if (len < 1024) {
+ res = bigMulTo(this, num, out);
+ } else {
+ res = jumboMulTo(this, num, out);
+ }
+
+ return res;
+ };
+
+ // Cooley-Tukey algorithm for FFT
+ // slightly revisited to rely on looping instead of recursion
+
+ function FFTM (x, y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ FFTM.prototype.makeRBT = function makeRBT (N) {
+ var t = new Array(N);
+ var l = BN.prototype._countBits(N) - 1;
+ for (var i = 0; i < N; i++) {
+ t[i] = this.revBin(i, l, N);
+ }
+
+ return t;
+ };
+
+ // Returns binary-reversed representation of `x`
+ FFTM.prototype.revBin = function revBin (x, l, N) {
+ if (x === 0 || x === N - 1) return x;
+
+ var rb = 0;
+ for (var i = 0; i < l; i++) {
+ rb |= (x & 1) << (l - i - 1);
+ x >>= 1;
+ }
+
+ return rb;
+ };
+
+ // Performs "tweedling" phase, therefore 'emulating'
+ // behaviour of the recursive algorithm
+ FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
+ for (var i = 0; i < N; i++) {
+ rtws[i] = rws[rbt[i]];
+ itws[i] = iws[rbt[i]];
+ }
+ };
+
+ FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
+ this.permute(rbt, rws, iws, rtws, itws, N);
+
+ for (var s = 1; s < N; s <<= 1) {
+ var l = s << 1;
+
+ var rtwdf = Math.cos(2 * Math.PI / l);
+ var itwdf = Math.sin(2 * Math.PI / l);
+
+ for (var p = 0; p < N; p += l) {
+ var rtwdf_ = rtwdf;
+ var itwdf_ = itwdf;
+
+ for (var j = 0; j < s; j++) {
+ var re = rtws[p + j];
+ var ie = itws[p + j];
+
+ var ro = rtws[p + j + s];
+ var io = itws[p + j + s];
+
+ var rx = rtwdf_ * ro - itwdf_ * io;
+
+ io = rtwdf_ * io + itwdf_ * ro;
+ ro = rx;
+
+ rtws[p + j] = re + ro;
+ itws[p + j] = ie + io;
+
+ rtws[p + j + s] = re - ro;
+ itws[p + j + s] = ie - io;
+
+ /* jshint maxdepth : false */
+ if (j !== l) {
+ rx = rtwdf * rtwdf_ - itwdf * itwdf_;
+
+ itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
+ rtwdf_ = rx;
+ }
+ }
+ }
+ }
+ };
+
+ FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
+ var N = Math.max(m, n) | 1;
+ var odd = N & 1;
+ var i = 0;
+ for (N = N / 2 | 0; N; N = N >>> 1) {
+ i++;
+ }
+
+ return 1 << i + 1 + odd;
+ };
+
+ FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
+ if (N <= 1) return;
+
+ for (var i = 0; i < N / 2; i++) {
+ var t = rws[i];
+
+ rws[i] = rws[N - i - 1];
+ rws[N - i - 1] = t;
+
+ t = iws[i];
+
+ iws[i] = -iws[N - i - 1];
+ iws[N - i - 1] = -t;
+ }
+ };
+
+ FFTM.prototype.normalize13b = function normalize13b (ws, N) {
+ var carry = 0;
+ for (var i = 0; i < N / 2; i++) {
+ var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
+ Math.round(ws[2 * i] / N) +
+ carry;
+
+ ws[i] = w & 0x3ffffff;
+
+ if (w < 0x4000000) {
+ carry = 0;
+ } else {
+ carry = w / 0x4000000 | 0;
+ }
+ }
+
+ return ws;
+ };
+
+ FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
+ var carry = 0;
+ for (var i = 0; i < len; i++) {
+ carry = carry + (ws[i] | 0);
+
+ rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
+ rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
+ }
+
+ // Pad with zeroes
+ for (i = 2 * len; i < N; ++i) {
+ rws[i] = 0;
+ }
+
+ assert(carry === 0);
+ assert((carry & ~0x1fff) === 0);
+ };
+
+ FFTM.prototype.stub = function stub (N) {
+ var ph = new Array(N);
+ for (var i = 0; i < N; i++) {
+ ph[i] = 0;
+ }
+
+ return ph;
+ };
+
+ FFTM.prototype.mulp = function mulp (x, y, out) {
+ var N = 2 * this.guessLen13b(x.length, y.length);
+
+ var rbt = this.makeRBT(N);
+
+ var _ = this.stub(N);
+
+ var rws = new Array(N);
+ var rwst = new Array(N);
+ var iwst = new Array(N);
+
+ var nrws = new Array(N);
+ var nrwst = new Array(N);
+ var niwst = new Array(N);
+
+ var rmws = out.words;
+ rmws.length = N;
+
+ this.convert13b(x.words, x.length, rws, N);
+ this.convert13b(y.words, y.length, nrws, N);
+
+ this.transform(rws, _, rwst, iwst, N, rbt);
+ this.transform(nrws, _, nrwst, niwst, N, rbt);
+
+ for (var i = 0; i < N; i++) {
+ var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
+ iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
+ rwst[i] = rx;
+ }
+
+ this.conjugate(rwst, iwst, N);
+ this.transform(rwst, iwst, rmws, _, N, rbt);
+ this.conjugate(rmws, _, N);
+ this.normalize13b(rmws, N);
+
+ out.negative = x.negative ^ y.negative;
+ out.length = x.length + y.length;
+ return out.strip();
+ };
+
+ // Multiply `this` by `num`
+ BN.prototype.mul = function mul (num) {
+ var out = new BN(null);
+ out.words = new Array(this.length + num.length);
+ return this.mulTo(num, out);
+ };
+
+ // Multiply employing FFT
+ BN.prototype.mulf = function mulf (num) {
+ var out = new BN(null);
+ out.words = new Array(this.length + num.length);
+ return jumboMulTo(this, num, out);
+ };
+
+ // In-place Multiplication
+ BN.prototype.imul = function imul (num) {
+ return this.clone().mulTo(num, this);
+ };
+
+ BN.prototype.imuln = function imuln (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+
+ // Carry
+ var carry = 0;
+ for (var i = 0; i < this.length; i++) {
+ var w = (this.words[i] | 0) * num;
+ var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
+ carry >>= 26;
+ carry += (w / 0x4000000) | 0;
+ // NOTE: lo is 27bit maximum
+ carry += lo >>> 26;
+ this.words[i] = lo & 0x3ffffff;
+ }
+
+ if (carry !== 0) {
+ this.words[i] = carry;
+ this.length++;
+ }
+
+ return this;
+ };
+
+ BN.prototype.muln = function muln (num) {
+ return this.clone().imuln(num);
+ };
+
+ // `this` * `this`
+ BN.prototype.sqr = function sqr () {
+ return this.mul(this);
+ };
+
+ // `this` * `this` in-place
+ BN.prototype.isqr = function isqr () {
+ return this.imul(this.clone());
+ };
+
+ // Math.pow(`this`, `num`)
+ BN.prototype.pow = function pow (num) {
+ var w = toBitArray(num);
+ if (w.length === 0) return new BN(1);
+
+ // Skip leading zeroes
+ var res = this;
+ for (var i = 0; i < w.length; i++, res = res.sqr()) {
+ if (w[i] !== 0) break;
+ }
+
+ if (++i < w.length) {
+ for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
+ if (w[i] === 0) continue;
+
+ res = res.mul(q);
+ }
+ }
+
+ return res;
+ };
+
+ // Shift-left in-place
+ BN.prototype.iushln = function iushln (bits) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var r = bits % 26;
+ var s = (bits - r) / 26;
+ var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
+ var i;
+
+ if (r !== 0) {
+ var carry = 0;
+
+ for (i = 0; i < this.length; i++) {
+ var newCarry = this.words[i] & carryMask;
+ var c = ((this.words[i] | 0) - newCarry) << r;
+ this.words[i] = c | carry;
+ carry = newCarry >>> (26 - r);
+ }
+
+ if (carry) {
+ this.words[i] = carry;
+ this.length++;
+ }
+ }
+
+ if (s !== 0) {
+ for (i = this.length - 1; i >= 0; i--) {
+ this.words[i + s] = this.words[i];
+ }
+
+ for (i = 0; i < s; i++) {
+ this.words[i] = 0;
+ }
+
+ this.length += s;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ishln = function ishln (bits) {
+ // TODO(indutny): implement me
+ assert(this.negative === 0);
+ return this.iushln(bits);
+ };
+
+ // Shift-right in-place
+ // NOTE: `hint` is a lowest bit before trailing zeroes
+ // NOTE: if `extended` is present - it will be filled with destroyed bits
+ BN.prototype.iushrn = function iushrn (bits, hint, extended) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var h;
+ if (hint) {
+ h = (hint - (hint % 26)) / 26;
+ } else {
+ h = 0;
+ }
+
+ var r = bits % 26;
+ var s = Math.min((bits - r) / 26, this.length);
+ var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
+ var maskedWords = extended;
+
+ h -= s;
+ h = Math.max(0, h);
+
+ // Extended mode, copy masked part
+ if (maskedWords) {
+ for (var i = 0; i < s; i++) {
+ maskedWords.words[i] = this.words[i];
+ }
+ maskedWords.length = s;
+ }
+
+ if (s === 0) {
+ // No-op, we should not move anything at all
+ } else if (this.length > s) {
+ this.length -= s;
+ for (i = 0; i < this.length; i++) {
+ this.words[i] = this.words[i + s];
+ }
+ } else {
+ this.words[0] = 0;
+ this.length = 1;
+ }
+
+ var carry = 0;
+ for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
+ var word = this.words[i] | 0;
+ this.words[i] = (carry << (26 - r)) | (word >>> r);
+ carry = word & mask;
+ }
+
+ // Push carried bits as a mask
+ if (maskedWords && carry !== 0) {
+ maskedWords.words[maskedWords.length++] = carry;
+ }
+
+ if (this.length === 0) {
+ this.words[0] = 0;
+ this.length = 1;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ishrn = function ishrn (bits, hint, extended) {
+ // TODO(indutny): implement me
+ assert(this.negative === 0);
+ return this.iushrn(bits, hint, extended);
+ };
+
+ // Shift-left
+ BN.prototype.shln = function shln (bits) {
+ return this.clone().ishln(bits);
+ };
+
+ BN.prototype.ushln = function ushln (bits) {
+ return this.clone().iushln(bits);
+ };
+
+ // Shift-right
+ BN.prototype.shrn = function shrn (bits) {
+ return this.clone().ishrn(bits);
+ };
+
+ BN.prototype.ushrn = function ushrn (bits) {
+ return this.clone().iushrn(bits);
+ };
+
+ // Test if n bit is set
+ BN.prototype.testn = function testn (bit) {
+ assert(typeof bit === 'number' && bit >= 0);
+ var r = bit % 26;
+ var s = (bit - r) / 26;
+ var q = 1 << r;
+
+ // Fast case: bit is much higher than all existing words
+ if (this.length <= s) return false;
+
+ // Check bit and return
+ var w = this.words[s];
+
+ return !!(w & q);
+ };
+
+ // Return only lowers bits of number (in-place)
+ BN.prototype.imaskn = function imaskn (bits) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var r = bits % 26;
+ var s = (bits - r) / 26;
+
+ assert(this.negative === 0, 'imaskn works only with positive numbers');
+
+ if (this.length <= s) {
+ return this;
+ }
+
+ if (r !== 0) {
+ s++;
+ }
+ this.length = Math.min(s, this.length);
+
+ if (r !== 0) {
+ var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
+ this.words[this.length - 1] &= mask;
+ }
+
+ return this.strip();
+ };
+
+ // Return only lowers bits of number
+ BN.prototype.maskn = function maskn (bits) {
+ return this.clone().imaskn(bits);
+ };
+
+ // Add plain number `num` to `this`
+ BN.prototype.iaddn = function iaddn (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+ if (num < 0) return this.isubn(-num);
+
+ // Possible sign change
+ if (this.negative !== 0) {
+ if (this.length === 1 && (this.words[0] | 0) < num) {
+ this.words[0] = num - (this.words[0] | 0);
+ this.negative = 0;
+ return this;
+ }
+
+ this.negative = 0;
+ this.isubn(num);
+ this.negative = 1;
+ return this;
+ }
+
+ // Add without checks
+ return this._iaddn(num);
+ };
+
+ BN.prototype._iaddn = function _iaddn (num) {
+ this.words[0] += num;
+
+ // Carry
+ for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
+ this.words[i] -= 0x4000000;
+ if (i === this.length - 1) {
+ this.words[i + 1] = 1;
+ } else {
+ this.words[i + 1]++;
+ }
+ }
+ this.length = Math.max(this.length, i + 1);
+
+ return this;
+ };
+
+ // Subtract plain number `num` from `this`
+ BN.prototype.isubn = function isubn (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+ if (num < 0) return this.iaddn(-num);
+
+ if (this.negative !== 0) {
+ this.negative = 0;
+ this.iaddn(num);
+ this.negative = 1;
+ return this;
+ }
+
+ this.words[0] -= num;
+
+ if (this.length === 1 && this.words[0] < 0) {
+ this.words[0] = -this.words[0];
+ this.negative = 1;
+ } else {
+ // Carry
+ for (var i = 0; i < this.length && this.words[i] < 0; i++) {
+ this.words[i] += 0x4000000;
+ this.words[i + 1] -= 1;
+ }
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.addn = function addn (num) {
+ return this.clone().iaddn(num);
+ };
+
+ BN.prototype.subn = function subn (num) {
+ return this.clone().isubn(num);
+ };
+
+ BN.prototype.iabs = function iabs () {
+ this.negative = 0;
+
+ return this;
+ };
+
+ BN.prototype.abs = function abs () {
+ return this.clone().iabs();
+ };
+
+ BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
+ var len = num.length + shift;
+ var i;
+
+ this._expand(len);
+
+ var w;
+ var carry = 0;
+ for (i = 0; i < num.length; i++) {
+ w = (this.words[i + shift] | 0) + carry;
+ var right = (num.words[i] | 0) * mul;
+ w -= right & 0x3ffffff;
+ carry = (w >> 26) - ((right / 0x4000000) | 0);
+ this.words[i + shift] = w & 0x3ffffff;
+ }
+ for (; i < this.length - shift; i++) {
+ w = (this.words[i + shift] | 0) + carry;
+ carry = w >> 26;
+ this.words[i + shift] = w & 0x3ffffff;
+ }
+
+ if (carry === 0) return this.strip();
+
+ // Subtraction overflow
+ assert(carry === -1);
+ carry = 0;
+ for (i = 0; i < this.length; i++) {
+ w = -(this.words[i] | 0) + carry;
+ carry = w >> 26;
+ this.words[i] = w & 0x3ffffff;
+ }
+ this.negative = 1;
+
+ return this.strip();
+ };
+
+ BN.prototype._wordDiv = function _wordDiv (num, mode) {
+ var shift = this.length - num.length;
+
+ var a = this.clone();
+ var b = num;
+
+ // Normalize
+ var bhi = b.words[b.length - 1] | 0;
+ var bhiBits = this._countBits(bhi);
+ shift = 26 - bhiBits;
+ if (shift !== 0) {
+ b = b.ushln(shift);
+ a.iushln(shift);
+ bhi = b.words[b.length - 1] | 0;
+ }
+
+ // Initialize quotient
+ var m = a.length - b.length;
+ var q;
+
+ if (mode !== 'mod') {
+ q = new BN(null);
+ q.length = m + 1;
+ q.words = new Array(q.length);
+ for (var i = 0; i < q.length; i++) {
+ q.words[i] = 0;
+ }
+ }
+
+ var diff = a.clone()._ishlnsubmul(b, 1, m);
+ if (diff.negative === 0) {
+ a = diff;
+ if (q) {
+ q.words[m] = 1;
+ }
+ }
+
+ for (var j = m - 1; j >= 0; j--) {
+ var qj = (a.words[b.length + j] | 0) * 0x4000000 +
+ (a.words[b.length + j - 1] | 0);
+
+ // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
+ // (0x7ffffff)
+ qj = Math.min((qj / bhi) | 0, 0x3ffffff);
+
+ a._ishlnsubmul(b, qj, j);
+ while (a.negative !== 0) {
+ qj--;
+ a.negative = 0;
+ a._ishlnsubmul(b, 1, j);
+ if (!a.isZero()) {
+ a.negative ^= 1;
+ }
+ }
+ if (q) {
+ q.words[j] = qj;
+ }
+ }
+ if (q) {
+ q.strip();
+ }
+ a.strip();
+
+ // Denormalize
+ if (mode !== 'div' && shift !== 0) {
+ a.iushrn(shift);
+ }
+
+ return {
+ div: q || null,
+ mod: a
+ };
+ };
+
+ // NOTE: 1) `mode` can be set to `mod` to request mod only,
+ // to `div` to request div only, or be absent to
+ // request both div & mod
+ // 2) `positive` is true if unsigned mod is requested
+ BN.prototype.divmod = function divmod (num, mode, positive) {
+ assert(!num.isZero());
+
+ if (this.isZero()) {
+ return {
+ div: new BN(0),
+ mod: new BN(0)
+ };
+ }
+
+ var div, mod, res;
+ if (this.negative !== 0 && num.negative === 0) {
+ res = this.neg().divmod(num, mode);
+
+ if (mode !== 'mod') {
+ div = res.div.neg();
+ }
+
+ if (mode !== 'div') {
+ mod = res.mod.neg();
+ if (positive && mod.negative !== 0) {
+ mod.iadd(num);
+ }
+ }
+
+ return {
+ div: div,
+ mod: mod
+ };
+ }
+
+ if (this.negative === 0 && num.negative !== 0) {
+ res = this.divmod(num.neg(), mode);
+
+ if (mode !== 'mod') {
+ div = res.div.neg();
+ }
+
+ return {
+ div: div,
+ mod: res.mod
+ };
+ }
+
+ if ((this.negative & num.negative) !== 0) {
+ res = this.neg().divmod(num.neg(), mode);
+
+ if (mode !== 'div') {
+ mod = res.mod.neg();
+ if (positive && mod.negative !== 0) {
+ mod.isub(num);
+ }
+ }
+
+ return {
+ div: res.div,
+ mod: mod
+ };
+ }
+
+ // Both numbers are positive at this point
+
+ // Strip both numbers to approximate shift value
+ if (num.length > this.length || this.cmp(num) < 0) {
+ return {
+ div: new BN(0),
+ mod: this
+ };
+ }
+
+ // Very short reduction
+ if (num.length === 1) {
+ if (mode === 'div') {
+ return {
+ div: this.divn(num.words[0]),
+ mod: null
+ };
+ }
+
+ if (mode === 'mod') {
+ return {
+ div: null,
+ mod: new BN(this.modn(num.words[0]))
+ };
+ }
+
+ return {
+ div: this.divn(num.words[0]),
+ mod: new BN(this.modn(num.words[0]))
+ };
+ }
+
+ return this._wordDiv(num, mode);
+ };
+
+ // Find `this` / `num`
+ BN.prototype.div = function div (num) {
+ return this.divmod(num, 'div', false).div;
+ };
+
+ // Find `this` % `num`
+ BN.prototype.mod = function mod (num) {
+ return this.divmod(num, 'mod', false).mod;
+ };
+
+ BN.prototype.umod = function umod (num) {
+ return this.divmod(num, 'mod', true).mod;
+ };
+
+ // Find Round(`this` / `num`)
+ BN.prototype.divRound = function divRound (num) {
+ var dm = this.divmod(num);
+
+ // Fast case - exact division
+ if (dm.mod.isZero()) return dm.div;
+
+ var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
+
+ var half = num.ushrn(1);
+ var r2 = num.andln(1);
+ var cmp = mod.cmp(half);
+
+ // Round down
+ if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
+
+ // Round up
+ return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
+ };
+
+ BN.prototype.modn = function modn (num) {
+ assert(num <= 0x3ffffff);
+ var p = (1 << 26) % num;
+
+ var acc = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ acc = (p * acc + (this.words[i] | 0)) % num;
+ }
+
+ return acc;
+ };
+
+ // In-place division by number
+ BN.prototype.idivn = function idivn (num) {
+ assert(num <= 0x3ffffff);
+
+ var carry = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ var w = (this.words[i] | 0) + carry * 0x4000000;
+ this.words[i] = (w / num) | 0;
+ carry = w % num;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.divn = function divn (num) {
+ return this.clone().idivn(num);
+ };
+
+ BN.prototype.egcd = function egcd (p) {
+ assert(p.negative === 0);
+ assert(!p.isZero());
+
+ var x = this;
+ var y = p.clone();
+
+ if (x.negative !== 0) {
+ x = x.umod(p);
+ } else {
+ x = x.clone();
+ }
+
+ // A * x + B * y = x
+ var A = new BN(1);
+ var B = new BN(0);
+
+ // C * x + D * y = y
+ var C = new BN(0);
+ var D = new BN(1);
+
+ var g = 0;
+
+ while (x.isEven() && y.isEven()) {
+ x.iushrn(1);
+ y.iushrn(1);
+ ++g;
+ }
+
+ var yp = y.clone();
+ var xp = x.clone();
+
+ while (!x.isZero()) {
+ for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
+ if (i > 0) {
+ x.iushrn(i);
+ while (i-- > 0) {
+ if (A.isOdd() || B.isOdd()) {
+ A.iadd(yp);
+ B.isub(xp);
+ }
+
+ A.iushrn(1);
+ B.iushrn(1);
+ }
+ }
+
+ for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
+ if (j > 0) {
+ y.iushrn(j);
+ while (j-- > 0) {
+ if (C.isOdd() || D.isOdd()) {
+ C.iadd(yp);
+ D.isub(xp);
+ }
+
+ C.iushrn(1);
+ D.iushrn(1);
+ }
+ }
+
+ if (x.cmp(y) >= 0) {
+ x.isub(y);
+ A.isub(C);
+ B.isub(D);
+ } else {
+ y.isub(x);
+ C.isub(A);
+ D.isub(B);
+ }
+ }
+
+ return {
+ a: C,
+ b: D,
+ gcd: y.iushln(g)
+ };
+ };
+
+ // This is reduced incarnation of the binary EEA
+ // above, designated to invert members of the
+ // _prime_ fields F(p) at a maximal speed
+ BN.prototype._invmp = function _invmp (p) {
+ assert(p.negative === 0);
+ assert(!p.isZero());
+
+ var a = this;
+ var b = p.clone();
+
+ if (a.negative !== 0) {
+ a = a.umod(p);
+ } else {
+ a = a.clone();
+ }
+
+ var x1 = new BN(1);
+ var x2 = new BN(0);
+
+ var delta = b.clone();
+
+ while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
+ for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
+ if (i > 0) {
+ a.iushrn(i);
+ while (i-- > 0) {
+ if (x1.isOdd()) {
+ x1.iadd(delta);
+ }
+
+ x1.iushrn(1);
+ }
+ }
+
+ for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
+ if (j > 0) {
+ b.iushrn(j);
+ while (j-- > 0) {
+ if (x2.isOdd()) {
+ x2.iadd(delta);
+ }
+
+ x2.iushrn(1);
+ }
+ }
+
+ if (a.cmp(b) >= 0) {
+ a.isub(b);
+ x1.isub(x2);
+ } else {
+ b.isub(a);
+ x2.isub(x1);
+ }
+ }
+
+ var res;
+ if (a.cmpn(1) === 0) {
+ res = x1;
+ } else {
+ res = x2;
+ }
+
+ if (res.cmpn(0) < 0) {
+ res.iadd(p);
+ }
+
+ return res;
+ };
+
+ BN.prototype.gcd = function gcd (num) {
+ if (this.isZero()) return num.abs();
+ if (num.isZero()) return this.abs();
+
+ var a = this.clone();
+ var b = num.clone();
+ a.negative = 0;
+ b.negative = 0;
+
+ // Remove common factor of two
+ for (var shift = 0; a.isEven() && b.isEven(); shift++) {
+ a.iushrn(1);
+ b.iushrn(1);
+ }
+
+ do {
+ while (a.isEven()) {
+ a.iushrn(1);
+ }
+ while (b.isEven()) {
+ b.iushrn(1);
+ }
+
+ var r = a.cmp(b);
+ if (r < 0) {
+ // Swap `a` and `b` to make `a` always bigger than `b`
+ var t = a;
+ a = b;
+ b = t;
+ } else if (r === 0 || b.cmpn(1) === 0) {
+ break;
+ }
+
+ a.isub(b);
+ } while (true);
+
+ return b.iushln(shift);
+ };
+
+ // Invert number in the field F(num)
+ BN.prototype.invm = function invm (num) {
+ return this.egcd(num).a.umod(num);
+ };
+
+ BN.prototype.isEven = function isEven () {
+ return (this.words[0] & 1) === 0;
+ };
+
+ BN.prototype.isOdd = function isOdd () {
+ return (this.words[0] & 1) === 1;
+ };
+
+ // And first word and num
+ BN.prototype.andln = function andln (num) {
+ return this.words[0] & num;
+ };
+
+ // Increment at the bit position in-line
+ BN.prototype.bincn = function bincn (bit) {
+ assert(typeof bit === 'number');
+ var r = bit % 26;
+ var s = (bit - r) / 26;
+ var q = 1 << r;
+
+ // Fast case: bit is much higher than all existing words
+ if (this.length <= s) {
+ this._expand(s + 1);
+ this.words[s] |= q;
+ return this;
+ }
+
+ // Add bit and propagate, if needed
+ var carry = q;
+ for (var i = s; carry !== 0 && i < this.length; i++) {
+ var w = this.words[i] | 0;
+ w += carry;
+ carry = w >>> 26;
+ w &= 0x3ffffff;
+ this.words[i] = w;
+ }
+ if (carry !== 0) {
+ this.words[i] = carry;
+ this.length++;
+ }
+ return this;
+ };
+
+ BN.prototype.isZero = function isZero () {
+ return this.length === 1 && this.words[0] === 0;
+ };
+
+ BN.prototype.cmpn = function cmpn (num) {
+ var negative = num < 0;
+
+ if (this.negative !== 0 && !negative) return -1;
+ if (this.negative === 0 && negative) return 1;
+
+ this.strip();
+
+ var res;
+ if (this.length > 1) {
+ res = 1;
+ } else {
+ if (negative) {
+ num = -num;
+ }
+
+ assert(num <= 0x3ffffff, 'Number is too big');
+
+ var w = this.words[0] | 0;
+ res = w === num ? 0 : w < num ? -1 : 1;
+ }
+ if (this.negative !== 0) return -res | 0;
+ return res;
+ };
+
+ // Compare two numbers and return:
+ // 1 - if `this` > `num`
+ // 0 - if `this` == `num`
+ // -1 - if `this` < `num`
+ BN.prototype.cmp = function cmp (num) {
+ if (this.negative !== 0 && num.negative === 0) return -1;
+ if (this.negative === 0 && num.negative !== 0) return 1;
+
+ var res = this.ucmp(num);
+ if (this.negative !== 0) return -res | 0;
+ return res;
+ };
+
+ // Unsigned comparison
+ BN.prototype.ucmp = function ucmp (num) {
+ // At this point both numbers have the same sign
+ if (this.length > num.length) return 1;
+ if (this.length < num.length) return -1;
+
+ var res = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ var a = this.words[i] | 0;
+ var b = num.words[i] | 0;
+
+ if (a === b) continue;
+ if (a < b) {
+ res = -1;
+ } else if (a > b) {
+ res = 1;
+ }
+ break;
+ }
+ return res;
+ };
+
+ BN.prototype.gtn = function gtn (num) {
+ return this.cmpn(num) === 1;
+ };
+
+ BN.prototype.gt = function gt (num) {
+ return this.cmp(num) === 1;
+ };
+
+ BN.prototype.gten = function gten (num) {
+ return this.cmpn(num) >= 0;
+ };
+
+ BN.prototype.gte = function gte (num) {
+ return this.cmp(num) >= 0;
+ };
+
+ BN.prototype.ltn = function ltn (num) {
+ return this.cmpn(num) === -1;
+ };
+
+ BN.prototype.lt = function lt (num) {
+ return this.cmp(num) === -1;
+ };
+
+ BN.prototype.lten = function lten (num) {
+ return this.cmpn(num) <= 0;
+ };
+
+ BN.prototype.lte = function lte (num) {
+ return this.cmp(num) <= 0;
+ };
+
+ BN.prototype.eqn = function eqn (num) {
+ return this.cmpn(num) === 0;
+ };
+
+ BN.prototype.eq = function eq (num) {
+ return this.cmp(num) === 0;
+ };
+
+ //
+ // A reduce context, could be using montgomery or something better, depending
+ // on the `m` itself.
+ //
+ BN.red = function red (num) {
+ return new Red(num);
+ };
+
+ BN.prototype.toRed = function toRed (ctx) {
+ assert(!this.red, 'Already a number in reduction context');
+ assert(this.negative === 0, 'red works only with positives');
+ return ctx.convertTo(this)._forceRed(ctx);
+ };
+
+ BN.prototype.fromRed = function fromRed () {
+ assert(this.red, 'fromRed works only with numbers in reduction context');
+ return this.red.convertFrom(this);
+ };
+
+ BN.prototype._forceRed = function _forceRed (ctx) {
+ this.red = ctx;
+ return this;
+ };
+
+ BN.prototype.forceRed = function forceRed (ctx) {
+ assert(!this.red, 'Already a number in reduction context');
+ return this._forceRed(ctx);
+ };
+
+ BN.prototype.redAdd = function redAdd (num) {
+ assert(this.red, 'redAdd works only with red numbers');
+ return this.red.add(this, num);
+ };
+
+ BN.prototype.redIAdd = function redIAdd (num) {
+ assert(this.red, 'redIAdd works only with red numbers');
+ return this.red.iadd(this, num);
+ };
+
+ BN.prototype.redSub = function redSub (num) {
+ assert(this.red, 'redSub works only with red numbers');
+ return this.red.sub(this, num);
+ };
+
+ BN.prototype.redISub = function redISub (num) {
+ assert(this.red, 'redISub works only with red numbers');
+ return this.red.isub(this, num);
+ };
+
+ BN.prototype.redShl = function redShl (num) {
+ assert(this.red, 'redShl works only with red numbers');
+ return this.red.shl(this, num);
+ };
+
+ BN.prototype.redMul = function redMul (num) {
+ assert(this.red, 'redMul works only with red numbers');
+ this.red._verify2(this, num);
+ return this.red.mul(this, num);
+ };
+
+ BN.prototype.redIMul = function redIMul (num) {
+ assert(this.red, 'redMul works only with red numbers');
+ this.red._verify2(this, num);
+ return this.red.imul(this, num);
+ };
+
+ BN.prototype.redSqr = function redSqr () {
+ assert(this.red, 'redSqr works only with red numbers');
+ this.red._verify1(this);
+ return this.red.sqr(this);
+ };
+
+ BN.prototype.redISqr = function redISqr () {
+ assert(this.red, 'redISqr works only with red numbers');
+ this.red._verify1(this);
+ return this.red.isqr(this);
+ };
+
+ // Square root over p
+ BN.prototype.redSqrt = function redSqrt () {
+ assert(this.red, 'redSqrt works only with red numbers');
+ this.red._verify1(this);
+ return this.red.sqrt(this);
+ };
+
+ BN.prototype.redInvm = function redInvm () {
+ assert(this.red, 'redInvm works only with red numbers');
+ this.red._verify1(this);
+ return this.red.invm(this);
+ };
+
+ // Return negative clone of `this` % `red modulo`
+ BN.prototype.redNeg = function redNeg () {
+ assert(this.red, 'redNeg works only with red numbers');
+ this.red._verify1(this);
+ return this.red.neg(this);
+ };
+
+ BN.prototype.redPow = function redPow (num) {
+ assert(this.red && !num.red, 'redPow(normalNum)');
+ this.red._verify1(this);
+ return this.red.pow(this, num);
+ };
+
+ // Prime numbers with efficient reduction
+ var primes = {
+ k256: null,
+ p224: null,
+ p192: null,
+ p25519: null
+ };
+
+ // Pseudo-Mersenne prime
+ function MPrime (name, p) {
+ // P = 2 ^ N - K
+ this.name = name;
+ this.p = new BN(p, 16);
+ this.n = this.p.bitLength();
+ this.k = new BN(1).iushln(this.n).isub(this.p);
+
+ this.tmp = this._tmp();
+ }
+
+ MPrime.prototype._tmp = function _tmp () {
+ var tmp = new BN(null);
+ tmp.words = new Array(Math.ceil(this.n / 13));
+ return tmp;
+ };
+
+ MPrime.prototype.ireduce = function ireduce (num) {
+ // Assumes that `num` is less than `P^2`
+ // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
+ var r = num;
+ var rlen;
+
+ do {
+ this.split(r, this.tmp);
+ r = this.imulK(r);
+ r = r.iadd(this.tmp);
+ rlen = r.bitLength();
+ } while (rlen > this.n);
+
+ var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
+ if (cmp === 0) {
+ r.words[0] = 0;
+ r.length = 1;
+ } else if (cmp > 0) {
+ r.isub(this.p);
+ } else {
+ r.strip();
+ }
+
+ return r;
+ };
+
+ MPrime.prototype.split = function split (input, out) {
+ input.iushrn(this.n, 0, out);
+ };
+
+ MPrime.prototype.imulK = function imulK (num) {
+ return num.imul(this.k);
+ };
+
+ function K256 () {
+ MPrime.call(
+ this,
+ 'k256',
+ 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
+ }
+ inherits(K256, MPrime);
+
+ K256.prototype.split = function split (input, output) {
+ // 256 = 9 * 26 + 22
+ var mask = 0x3fffff;
+
+ var outLen = Math.min(input.length, 9);
+ for (var i = 0; i < outLen; i++) {
+ output.words[i] = input.words[i];
+ }
+ output.length = outLen;
+
+ if (input.length <= 9) {
+ input.words[0] = 0;
+ input.length = 1;
+ return;
+ }
+
+ // Shift by 9 limbs
+ var prev = input.words[9];
+ output.words[output.length++] = prev & mask;
+
+ for (i = 10; i < input.length; i++) {
+ var next = input.words[i] | 0;
+ input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
+ prev = next;
+ }
+ prev >>>= 22;
+ input.words[i - 10] = prev;
+ if (prev === 0 && input.length > 10) {
+ input.length -= 10;
+ } else {
+ input.length -= 9;
+ }
+ };
+
+ K256.prototype.imulK = function imulK (num) {
+ // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
+ num.words[num.length] = 0;
+ num.words[num.length + 1] = 0;
+ num.length += 2;
+
+ // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
+ var lo = 0;
+ for (var i = 0; i < num.length; i++) {
+ var w = num.words[i] | 0;
+ lo += w * 0x3d1;
+ num.words[i] = lo & 0x3ffffff;
+ lo = w * 0x40 + ((lo / 0x4000000) | 0);
+ }
+
+ // Fast length reduction
+ if (num.words[num.length - 1] === 0) {
+ num.length--;
+ if (num.words[num.length - 1] === 0) {
+ num.length--;
+ }
+ }
+ return num;
+ };
+
+ function P224 () {
+ MPrime.call(
+ this,
+ 'p224',
+ 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
+ }
+ inherits(P224, MPrime);
+
+ function P192 () {
+ MPrime.call(
+ this,
+ 'p192',
+ 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
+ }
+ inherits(P192, MPrime);
+
+ function P25519 () {
+ // 2 ^ 255 - 19
+ MPrime.call(
+ this,
+ '25519',
+ '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
+ }
+ inherits(P25519, MPrime);
+
+ P25519.prototype.imulK = function imulK (num) {
+ // K = 0x13
+ var carry = 0;
+ for (var i = 0; i < num.length; i++) {
+ var hi = (num.words[i] | 0) * 0x13 + carry;
+ var lo = hi & 0x3ffffff;
+ hi >>>= 26;
+
+ num.words[i] = lo;
+ carry = hi;
+ }
+ if (carry !== 0) {
+ num.words[num.length++] = carry;
+ }
+ return num;
+ };
+
+ // Exported mostly for testing purposes, use plain name instead
+ BN._prime = function prime (name) {
+ // Cached version of prime
+ if (primes[name]) return primes[name];
+
+ var prime;
+ if (name === 'k256') {
+ prime = new K256();
+ } else if (name === 'p224') {
+ prime = new P224();
+ } else if (name === 'p192') {
+ prime = new P192();
+ } else if (name === 'p25519') {
+ prime = new P25519();
+ } else {
+ throw new Error('Unknown prime ' + name);
+ }
+ primes[name] = prime;
+
+ return prime;
+ };
+
+ //
+ // Base reduction engine
+ //
+ function Red (m) {
+ if (typeof m === 'string') {
+ var prime = BN._prime(m);
+ this.m = prime.p;
+ this.prime = prime;
+ } else {
+ assert(m.gtn(1), 'modulus must be greater than 1');
+ this.m = m;
+ this.prime = null;
+ }
+ }
+
+ Red.prototype._verify1 = function _verify1 (a) {
+ assert(a.negative === 0, 'red works only with positives');
+ assert(a.red, 'red works only with red numbers');
+ };
+
+ Red.prototype._verify2 = function _verify2 (a, b) {
+ assert((a.negative | b.negative) === 0, 'red works only with positives');
+ assert(a.red && a.red === b.red,
+ 'red works only with red numbers');
+ };
+
+ Red.prototype.imod = function imod (a) {
+ if (this.prime) return this.prime.ireduce(a)._forceRed(this);
+ return a.umod(this.m)._forceRed(this);
+ };
+
+ Red.prototype.neg = function neg (a) {
+ if (a.isZero()) {
+ return a.clone();
+ }
+
+ return this.m.sub(a)._forceRed(this);
+ };
+
+ Red.prototype.add = function add (a, b) {
+ this._verify2(a, b);
+
+ var res = a.add(b);
+ if (res.cmp(this.m) >= 0) {
+ res.isub(this.m);
+ }
+ return res._forceRed(this);
+ };
+
+ Red.prototype.iadd = function iadd (a, b) {
+ this._verify2(a, b);
+
+ var res = a.iadd(b);
+ if (res.cmp(this.m) >= 0) {
+ res.isub(this.m);
+ }
+ return res;
+ };
+
+ Red.prototype.sub = function sub (a, b) {
+ this._verify2(a, b);
+
+ var res = a.sub(b);
+ if (res.cmpn(0) < 0) {
+ res.iadd(this.m);
+ }
+ return res._forceRed(this);
+ };
+
+ Red.prototype.isub = function isub (a, b) {
+ this._verify2(a, b);
+
+ var res = a.isub(b);
+ if (res.cmpn(0) < 0) {
+ res.iadd(this.m);
+ }
+ return res;
+ };
+
+ Red.prototype.shl = function shl (a, num) {
+ this._verify1(a);
+ return this.imod(a.ushln(num));
+ };
+
+ Red.prototype.imul = function imul (a, b) {
+ this._verify2(a, b);
+ return this.imod(a.imul(b));
+ };
+
+ Red.prototype.mul = function mul (a, b) {
+ this._verify2(a, b);
+ return this.imod(a.mul(b));
+ };
+
+ Red.prototype.isqr = function isqr (a) {
+ return this.imul(a, a.clone());
+ };
+
+ Red.prototype.sqr = function sqr (a) {
+ return this.mul(a, a);
+ };
+
+ Red.prototype.sqrt = function sqrt (a) {
+ if (a.isZero()) return a.clone();
+
+ var mod3 = this.m.andln(3);
+ assert(mod3 % 2 === 1);
+
+ // Fast case
+ if (mod3 === 3) {
+ var pow = this.m.add(new BN(1)).iushrn(2);
+ return this.pow(a, pow);
+ }
+
+ // Tonelli-Shanks algorithm (Totally unoptimized and slow)
+ //
+ // Find Q and S, that Q * 2 ^ S = (P - 1)
+ var q = this.m.subn(1);
+ var s = 0;
+ while (!q.isZero() && q.andln(1) === 0) {
+ s++;
+ q.iushrn(1);
+ }
+ assert(!q.isZero());
+
+ var one = new BN(1).toRed(this);
+ var nOne = one.redNeg();
+
+ // Find quadratic non-residue
+ // NOTE: Max is such because of generalized Riemann hypothesis.
+ var lpow = this.m.subn(1).iushrn(1);
+ var z = this.m.bitLength();
+ z = new BN(2 * z * z).toRed(this);
+
+ while (this.pow(z, lpow).cmp(nOne) !== 0) {
+ z.redIAdd(nOne);
+ }
+
+ var c = this.pow(z, q);
+ var r = this.pow(a, q.addn(1).iushrn(1));
+ var t = this.pow(a, q);
+ var m = s;
+ while (t.cmp(one) !== 0) {
+ var tmp = t;
+ for (var i = 0; tmp.cmp(one) !== 0; i++) {
+ tmp = tmp.redSqr();
+ }
+ assert(i < m);
+ var b = this.pow(c, new BN(1).iushln(m - i - 1));
+
+ r = r.redMul(b);
+ c = b.redSqr();
+ t = t.redMul(c);
+ m = i;
+ }
+
+ return r;
+ };
+
+ Red.prototype.invm = function invm (a) {
+ var inv = a._invmp(this.m);
+ if (inv.negative !== 0) {
+ inv.negative = 0;
+ return this.imod(inv).redNeg();
+ } else {
+ return this.imod(inv);
+ }
+ };
+
+ Red.prototype.pow = function pow (a, num) {
+ if (num.isZero()) return new BN(1).toRed(this);
+ if (num.cmpn(1) === 0) return a.clone();
+
+ var windowSize = 4;
+ var wnd = new Array(1 << windowSize);
+ wnd[0] = new BN(1).toRed(this);
+ wnd[1] = a;
+ for (var i = 2; i < wnd.length; i++) {
+ wnd[i] = this.mul(wnd[i - 1], a);
+ }
+
+ var res = wnd[0];
+ var current = 0;
+ var currentLen = 0;
+ var start = num.bitLength() % 26;
+ if (start === 0) {
+ start = 26;
+ }
+
+ for (i = num.length - 1; i >= 0; i--) {
+ var word = num.words[i];
+ for (var j = start - 1; j >= 0; j--) {
+ var bit = (word >> j) & 1;
+ if (res !== wnd[0]) {
+ res = this.sqr(res);
+ }
+
+ if (bit === 0 && current === 0) {
+ currentLen = 0;
+ continue;
+ }
+
+ current <<= 1;
+ current |= bit;
+ currentLen++;
+ if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
+
+ res = this.mul(res, wnd[current]);
+ currentLen = 0;
+ current = 0;
+ }
+ start = 26;
+ }
+
+ return res;
+ };
+
+ Red.prototype.convertTo = function convertTo (num) {
+ var r = num.umod(this.m);
+
+ return r === num ? r.clone() : r;
+ };
+
+ Red.prototype.convertFrom = function convertFrom (num) {
+ var res = num.clone();
+ res.red = null;
+ return res;
+ };
+
+ //
+ // Montgomery method engine
+ //
+
+ BN.mont = function mont (num) {
+ return new Mont(num);
+ };
+
+ function Mont (m) {
+ Red.call(this, m);
+
+ this.shift = this.m.bitLength();
+ if (this.shift % 26 !== 0) {
+ this.shift += 26 - (this.shift % 26);
+ }
+
+ this.r = new BN(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);
+ }
+ inherits(Mont, Red);
+
+ Mont.prototype.convertTo = function convertTo (num) {
+ return this.imod(num.ushln(this.shift));
+ };
+
+ Mont.prototype.convertFrom = function convertFrom (num) {
+ var r = this.imod(num.mul(this.rinv));
+ r.red = null;
+ return r;
+ };
+
+ Mont.prototype.imul = function imul (a, b) {
+ if (a.isZero() || b.isZero()) {
+ a.words[0] = 0;
+ a.length = 1;
+ return a;
+ }
+
+ var t = a.imul(b);
+ var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
+ var u = t.isub(c).iushrn(this.shift);
+ var res = u;
+
+ if (u.cmp(this.m) >= 0) {
+ res = u.isub(this.m);
+ } else if (u.cmpn(0) < 0) {
+ res = u.iadd(this.m);
+ }
+
+ return res._forceRed(this);
+ };
+
+ Mont.prototype.mul = function mul (a, b) {
+ if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
+
+ var t = a.mul(b);
+ var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
+ var u = t.isub(c).iushrn(this.shift);
+ var res = u;
+ if (u.cmp(this.m) >= 0) {
+ res = u.isub(this.m);
+ } else if (u.cmpn(0) < 0) {
+ res = u.iadd(this.m);
+ }
+
+ return res._forceRed(this);
+ };
+
+ Mont.prototype.invm = function invm (a) {
+ // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
+ var res = this.imod(a._invmp(this.m).mul(this.r2));
+ return res._forceRed(this);
+ };
+})(typeof module === 'undefined' || module, this);
+
+},{"buffer":2}],2:[function(require,module,exports){
+
+},{}],3:[function(require,module,exports){
+if (typeof Object.create === 'function') {
+ // implementation from standard node.js 'util' module
+ module.exports = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor
+ ctor.prototype = Object.create(superCtor.prototype, {
+ constructor: {
+ value: ctor,
+ enumerable: false,
+ writable: true,
+ configurable: true
+ }
+ });
+ };
+} else {
+ // old school shim for old browsers
+ module.exports = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor
+ var TempCtor = function () {}
+ TempCtor.prototype = superCtor.prototype
+ ctor.prototype = new TempCtor()
+ ctor.prototype.constructor = ctor
+ }
+}
+
+},{}],4:[function(require,module,exports){
+(function (process,global){
+/**
+ * [js-sha3]{@link https://github.com/emn178/js-sha3}
+ *
+ * @version 0.5.7
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
+ * @copyright Chen, Yi-Cyuan 2015-2016
+ * @license MIT
+ */
+/*jslint bitwise: true */
+(function () {
+ 'use strict';
+
+ var root = typeof window === 'object' ? window : {};
+ var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
+ if (NODE_JS) {
+ root = global;
+ }
+ var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
+ var HEX_CHARS = '0123456789abcdef'.split('');
+ var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
+ var KECCAK_PADDING = [1, 256, 65536, 16777216];
+ var PADDING = [6, 1536, 393216, 100663296];
+ var SHIFT = [0, 8, 16, 24];
+ var RC = [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];
+ var BITS = [224, 256, 384, 512];
+ var SHAKE_BITS = [128, 256];
+ var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array'];
+
+ var createOutputMethod = function (bits, padding, outputType) {
+ return function (message) {
+ return new Keccak(bits, padding, bits).update(message)[outputType]();
+ };
+ };
+
+ var createShakeOutputMethod = function (bits, padding, outputType) {
+ return function (message, outputBits) {
+ return new Keccak(bits, padding, outputBits).update(message)[outputType]();
+ };
+ };
+
+ var createMethod = function (bits, padding) {
+ var method = createOutputMethod(bits, padding, 'hex');
+ method.create = function () {
+ return new Keccak(bits, padding, bits);
+ };
+ method.update = function (message) {
+ return method.create().update(message);
+ };
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
+ var type = OUTPUT_TYPES[i];
+ method[type] = createOutputMethod(bits, padding, type);
+ }
+ return method;
+ };
+
+ var createShakeMethod = function (bits, padding) {
+ var method = createShakeOutputMethod(bits, padding, 'hex');
+ method.create = function (outputBits) {
+ return new Keccak(bits, padding, outputBits);
+ };
+ method.update = function (message, outputBits) {
+ return method.create(outputBits).update(message);
+ };
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
+ var type = OUTPUT_TYPES[i];
+ method[type] = createShakeOutputMethod(bits, padding, type);
+ }
+ return method;
+ };
+
+ var algorithms = [
+ {name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod},
+ {name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod},
+ {name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod}
+ ];
+
+ var methods = {}, methodNames = [];
+
+ for (var i = 0; i < algorithms.length; ++i) {
+ var algorithm = algorithms[i];
+ var bits = algorithm.bits;
+ for (var j = 0; j < bits.length; ++j) {
+ var methodName = algorithm.name +'_' + bits[j];
+ methodNames.push(methodName);
+ methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
+ }
+ }
+
+ function Keccak(bits, padding, outputBits) {
+ this.blocks = [];
+ this.s = [];
+ this.padding = padding;
+ this.outputBits = outputBits;
+ this.reset = true;
+ this.block = 0;
+ this.start = 0;
+ this.blockCount = (1600 - (bits << 1)) >> 5;
+ this.byteCount = this.blockCount << 2;
+ this.outputBlocks = outputBits >> 5;
+ this.extraBytes = (outputBits & 31) >> 3;
+
+ for (var i = 0; i < 50; ++i) {
+ this.s[i] = 0;
+ }
+ }
+
+ Keccak.prototype.update = function (message) {
+ var notString = typeof message !== 'string';
+ if (notString && message.constructor === ArrayBuffer) {
+ message = new Uint8Array(message);
+ }
+ var length = message.length, blocks = this.blocks, byteCount = this.byteCount,
+ blockCount = this.blockCount, index = 0, s = this.s, i, code;
+
+ while (index < length) {
+ if (this.reset) {
+ this.reset = false;
+ blocks[0] = this.block;
+ for (i = 1; i < blockCount + 1; ++i) {
+ blocks[i] = 0;
+ }
+ }
+ if (notString) {
+ for (i = this.start; index < length && i < byteCount; ++index) {
+ blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
+ }
+ } else {
+ for (i = this.start; index < length && i < byteCount; ++index) {
+ code = message.charCodeAt(index);
+ if (code < 0x80) {
+ blocks[i >> 2] |= code << SHIFT[i++ & 3];
+ } else if (code < 0x800) {
+ blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ } else if (code < 0xd800 || code >= 0xe000) {
+ blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ } else {
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
+ blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ }
+ }
+ }
+ this.lastByteIndex = i;
+ if (i >= byteCount) {
+ this.start = i - byteCount;
+ this.block = blocks[blockCount];
+ for (i = 0; i < blockCount; ++i) {
+ s[i] ^= blocks[i];
+ }
+ f(s);
+ this.reset = true;
+ } else {
+ this.start = i;
+ }
+ }
+ return this;
+ };
+
+ Keccak.prototype.finalize = function () {
+ var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
+ blocks[i >> 2] |= this.padding[i & 3];
+ if (this.lastByteIndex === this.byteCount) {
+ blocks[0] = blocks[blockCount];
+ for (i = 1; i < blockCount + 1; ++i) {
+ blocks[i] = 0;
+ }
+ }
+ blocks[blockCount - 1] |= 0x80000000;
+ for (i = 0; i < blockCount; ++i) {
+ s[i] ^= blocks[i];
+ }
+ f(s);
+ };
+
+ Keccak.prototype.toString = Keccak.prototype.hex = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var hex = '', block;
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ block = s[i];
+ hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
+ HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
+ HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
+ HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ i = 0;
+ }
+ }
+ if (extraBytes) {
+ block = s[i];
+ if (extraBytes > 0) {
+ hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
+ }
+ if (extraBytes > 1) {
+ hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
+ }
+ if (extraBytes > 2) {
+ hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
+ }
+ }
+ return hex;
+ };
+
+ Keccak.prototype.arrayBuffer = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var bytes = this.outputBits >> 3;
+ var buffer;
+ if (extraBytes) {
+ buffer = new ArrayBuffer((outputBlocks + 1) << 2);
+ } else {
+ buffer = new ArrayBuffer(bytes);
+ }
+ var array = new Uint32Array(buffer);
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ array[j] = s[i];
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ }
+ }
+ if (extraBytes) {
+ array[i] = s[i];
+ buffer = buffer.slice(0, bytes);
+ }
+ return buffer;
+ };
+
+ Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
+
+ Keccak.prototype.digest = Keccak.prototype.array = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var array = [], offset, block;
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ offset = j << 2;
+ block = s[i];
+ array[offset] = block & 0xFF;
+ array[offset + 1] = (block >> 8) & 0xFF;
+ array[offset + 2] = (block >> 16) & 0xFF;
+ array[offset + 3] = (block >> 24) & 0xFF;
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ }
+ }
+ if (extraBytes) {
+ offset = j << 2;
+ block = s[i];
+ if (extraBytes > 0) {
+ array[offset] = block & 0xFF;
+ }
+ if (extraBytes > 1) {
+ array[offset + 1] = (block >> 8) & 0xFF;
+ }
+ if (extraBytes > 2) {
+ array[offset + 2] = (block >> 16) & 0xFF;
+ }
+ }
+ return array;
+ };
+
+ var f = function (s) {
+ var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
+ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
+ b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
+ b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
+ for (n = 0; n < 48; n += 2) {
+ c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
+ c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
+ c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
+ c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
+ c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
+ c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
+ c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
+ c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
+ c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
+ c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
+
+ h = c8 ^ ((c2 << 1) | (c3 >>> 31));
+ l = c9 ^ ((c3 << 1) | (c2 >>> 31));
+ s[0] ^= h;
+ s[1] ^= l;
+ s[10] ^= h;
+ s[11] ^= l;
+ s[20] ^= h;
+ s[21] ^= l;
+ s[30] ^= h;
+ s[31] ^= l;
+ s[40] ^= h;
+ s[41] ^= l;
+ h = c0 ^ ((c4 << 1) | (c5 >>> 31));
+ l = c1 ^ ((c5 << 1) | (c4 >>> 31));
+ s[2] ^= h;
+ s[3] ^= l;
+ s[12] ^= h;
+ s[13] ^= l;
+ s[22] ^= h;
+ s[23] ^= l;
+ s[32] ^= h;
+ s[33] ^= l;
+ s[42] ^= h;
+ s[43] ^= l;
+ h = c2 ^ ((c6 << 1) | (c7 >>> 31));
+ l = c3 ^ ((c7 << 1) | (c6 >>> 31));
+ s[4] ^= h;
+ s[5] ^= l;
+ s[14] ^= h;
+ s[15] ^= l;
+ s[24] ^= h;
+ s[25] ^= l;
+ s[34] ^= h;
+ s[35] ^= l;
+ s[44] ^= h;
+ s[45] ^= l;
+ h = c4 ^ ((c8 << 1) | (c9 >>> 31));
+ l = c5 ^ ((c9 << 1) | (c8 >>> 31));
+ s[6] ^= h;
+ s[7] ^= l;
+ s[16] ^= h;
+ s[17] ^= l;
+ s[26] ^= h;
+ s[27] ^= l;
+ s[36] ^= h;
+ s[37] ^= l;
+ s[46] ^= h;
+ s[47] ^= l;
+ h = c6 ^ ((c0 << 1) | (c1 >>> 31));
+ l = c7 ^ ((c1 << 1) | (c0 >>> 31));
+ s[8] ^= h;
+ s[9] ^= l;
+ s[18] ^= h;
+ s[19] ^= l;
+ s[28] ^= h;
+ s[29] ^= l;
+ s[38] ^= h;
+ s[39] ^= l;
+ s[48] ^= h;
+ s[49] ^= l;
+
+ b0 = s[0];
+ b1 = s[1];
+ b32 = (s[11] << 4) | (s[10] >>> 28);
+ b33 = (s[10] << 4) | (s[11] >>> 28);
+ b14 = (s[20] << 3) | (s[21] >>> 29);
+ b15 = (s[21] << 3) | (s[20] >>> 29);
+ b46 = (s[31] << 9) | (s[30] >>> 23);
+ b47 = (s[30] << 9) | (s[31] >>> 23);
+ b28 = (s[40] << 18) | (s[41] >>> 14);
+ b29 = (s[41] << 18) | (s[40] >>> 14);
+ b20 = (s[2] << 1) | (s[3] >>> 31);
+ b21 = (s[3] << 1) | (s[2] >>> 31);
+ b2 = (s[13] << 12) | (s[12] >>> 20);
+ b3 = (s[12] << 12) | (s[13] >>> 20);
+ b34 = (s[22] << 10) | (s[23] >>> 22);
+ b35 = (s[23] << 10) | (s[22] >>> 22);
+ b16 = (s[33] << 13) | (s[32] >>> 19);
+ b17 = (s[32] << 13) | (s[33] >>> 19);
+ b48 = (s[42] << 2) | (s[43] >>> 30);
+ b49 = (s[43] << 2) | (s[42] >>> 30);
+ b40 = (s[5] << 30) | (s[4] >>> 2);
+ b41 = (s[4] << 30) | (s[5] >>> 2);
+ b22 = (s[14] << 6) | (s[15] >>> 26);
+ b23 = (s[15] << 6) | (s[14] >>> 26);
+ b4 = (s[25] << 11) | (s[24] >>> 21);
+ b5 = (s[24] << 11) | (s[25] >>> 21);
+ b36 = (s[34] << 15) | (s[35] >>> 17);
+ b37 = (s[35] << 15) | (s[34] >>> 17);
+ b18 = (s[45] << 29) | (s[44] >>> 3);
+ b19 = (s[44] << 29) | (s[45] >>> 3);
+ b10 = (s[6] << 28) | (s[7] >>> 4);
+ b11 = (s[7] << 28) | (s[6] >>> 4);
+ b42 = (s[17] << 23) | (s[16] >>> 9);
+ b43 = (s[16] << 23) | (s[17] >>> 9);
+ b24 = (s[26] << 25) | (s[27] >>> 7);
+ b25 = (s[27] << 25) | (s[26] >>> 7);
+ b6 = (s[36] << 21) | (s[37] >>> 11);
+ b7 = (s[37] << 21) | (s[36] >>> 11);
+ b38 = (s[47] << 24) | (s[46] >>> 8);
+ b39 = (s[46] << 24) | (s[47] >>> 8);
+ b30 = (s[8] << 27) | (s[9] >>> 5);
+ b31 = (s[9] << 27) | (s[8] >>> 5);
+ b12 = (s[18] << 20) | (s[19] >>> 12);
+ b13 = (s[19] << 20) | (s[18] >>> 12);
+ b44 = (s[29] << 7) | (s[28] >>> 25);
+ b45 = (s[28] << 7) | (s[29] >>> 25);
+ b26 = (s[38] << 8) | (s[39] >>> 24);
+ b27 = (s[39] << 8) | (s[38] >>> 24);
+ b8 = (s[48] << 14) | (s[49] >>> 18);
+ b9 = (s[49] << 14) | (s[48] >>> 18);
+
+ s[0] = b0 ^ (~b2 & b4);
+ s[1] = b1 ^ (~b3 & b5);
+ s[10] = b10 ^ (~b12 & b14);
+ s[11] = b11 ^ (~b13 & b15);
+ s[20] = b20 ^ (~b22 & b24);
+ s[21] = b21 ^ (~b23 & b25);
+ s[30] = b30 ^ (~b32 & b34);
+ s[31] = b31 ^ (~b33 & b35);
+ s[40] = b40 ^ (~b42 & b44);
+ s[41] = b41 ^ (~b43 & b45);
+ s[2] = b2 ^ (~b4 & b6);
+ s[3] = b3 ^ (~b5 & b7);
+ s[12] = b12 ^ (~b14 & b16);
+ s[13] = b13 ^ (~b15 & b17);
+ s[22] = b22 ^ (~b24 & b26);
+ s[23] = b23 ^ (~b25 & b27);
+ s[32] = b32 ^ (~b34 & b36);
+ s[33] = b33 ^ (~b35 & b37);
+ s[42] = b42 ^ (~b44 & b46);
+ s[43] = b43 ^ (~b45 & b47);
+ s[4] = b4 ^ (~b6 & b8);
+ s[5] = b5 ^ (~b7 & b9);
+ s[14] = b14 ^ (~b16 & b18);
+ s[15] = b15 ^ (~b17 & b19);
+ s[24] = b24 ^ (~b26 & b28);
+ s[25] = b25 ^ (~b27 & b29);
+ s[34] = b34 ^ (~b36 & b38);
+ s[35] = b35 ^ (~b37 & b39);
+ s[44] = b44 ^ (~b46 & b48);
+ s[45] = b45 ^ (~b47 & b49);
+ s[6] = b6 ^ (~b8 & b0);
+ s[7] = b7 ^ (~b9 & b1);
+ s[16] = b16 ^ (~b18 & b10);
+ s[17] = b17 ^ (~b19 & b11);
+ s[26] = b26 ^ (~b28 & b20);
+ s[27] = b27 ^ (~b29 & b21);
+ s[36] = b36 ^ (~b38 & b30);
+ s[37] = b37 ^ (~b39 & b31);
+ s[46] = b46 ^ (~b48 & b40);
+ s[47] = b47 ^ (~b49 & b41);
+ s[8] = b8 ^ (~b0 & b2);
+ s[9] = b9 ^ (~b1 & b3);
+ s[18] = b18 ^ (~b10 & b12);
+ s[19] = b19 ^ (~b11 & b13);
+ s[28] = b28 ^ (~b20 & b22);
+ s[29] = b29 ^ (~b21 & b23);
+ s[38] = b38 ^ (~b30 & b32);
+ s[39] = b39 ^ (~b31 & b33);
+ s[48] = b48 ^ (~b40 & b42);
+ s[49] = b49 ^ (~b41 & b43);
+
+ s[0] ^= RC[n];
+ s[1] ^= RC[n + 1];
+ }
+ };
+
+ if (COMMON_JS) {
+ module.exports = methods;
+ } else {
+ for (var i = 0; i < methodNames.length; ++i) {
+ root[methodNames[i]] = methods[methodNames[i]];
+ }
+ }
+})();
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"_process":5}],5:[function(require,module,exports){
+module.exports = undefined;
+},{}],6:[function(require,module,exports){
+'use strict';
+
+try {
+ module.exports.XMLHttpRequest = XMLHttpRequest;
+} catch(error) {
+ console.log('Warning: XMLHttpRequest is not defined');
+ module.exports.XMLHttpRequest = null;
+}
+
+},{}],7:[function(require,module,exports){
+'use strict';
+
+var Provider = require('./provider.js');
+
+var utils = (function() {
+ var convert = require('../utils/convert.js');
+ return {
+ defineProperty: require('../utils/properties.js').defineProperty,
+
+ hexlify: convert.hexlify,
+ hexStripZeros: convert.hexStripZeros,
+ };
+})();
+
+
+function getTransactionString(transaction) {
+ var result = [];
+ for (var key in transaction) {
+ if (transaction[key] == null) { continue; }
+ var value = utils.hexlify(transaction[key]);
+ if ({ gasLimit: true, gasPrice: true, nonce: true, value: true }[key]) {
+ value = utils.hexStripZeros(value);
+ }
+ result.push(key + '=' + value);
+ }
+ return result.join('&');
+}
+
+function EtherscanProvider(network, apiKey) {
+ Provider.call(this, network);
+
+ var baseUrl = null;
+ switch(this.name) {
+ case 'homestead':
+ baseUrl = 'https://api.etherscan.io';
+ break;
+ case 'ropsten':
+ baseUrl = 'https://ropsten.etherscan.io';
+ break;
+ case 'rinkeby':
+ baseUrl = 'https://rinkeby.etherscan.io';
+ break;
+ case 'kovan':
+ baseUrl = 'https://kovan.etherscan.io';
+ break;
+ default:
+ throw new Error('unsupported network');
+ }
+ utils.defineProperty(this, 'baseUrl', baseUrl);
+
+ utils.defineProperty(this, 'apiKey', apiKey || null);
+}
+Provider.inherits(EtherscanProvider);
+
+utils.defineProperty(EtherscanProvider.prototype, '_call', function() {
+});
+
+utils.defineProperty(EtherscanProvider.prototype, '_callProxy', function() {
+});
+
+function getResult(result) {
+ // getLogs has weird success responses
+ if (result.status == 0 && result.message === 'No records found') {
+ return result.result;
+ }
+
+ if (result.status != 1 || result.message != 'OK') {
+ var error = new Error('invalid response');
+ error.result = JSON.stringify(result);
+ throw error;
+ }
+
+ return result.result;
+}
+
+function getJsonResult(result) {
+ if (result.jsonrpc != '2.0') {
+ var error = new Error('invalid response');
+ error.result = JSON.stringify(result);
+ throw error;
+ }
+
+ if (result.error) {
+ var error = new Error(result.error.message || 'unknown error');
+ if (result.error.code) { error.code = result.error.code; }
+ if (result.error.data) { error.data = result.error.data; }
+ throw error;
+ }
+
+ return result.result;
+}
+
+function checkLogTag(blockTag) {
+ if (blockTag === 'pending') { throw new Error('pending not supported'); }
+ if (blockTag === 'latest') { return blockTag; }
+
+ return parseInt(blockTag.substring(2), 16);
+}
+
+
+utils.defineProperty(EtherscanProvider.prototype, 'perform', function(method, params) {
+ if (!params) { params = {}; }
+
+ var url = this.baseUrl;
+
+ var apiKey = '';
+ if (this.apiKey) { apiKey += '&apikey=' + this.apiKey; }
+
+ switch (method) {
+ case 'getBlockNumber':
+ url += '/api?module=proxy&action=eth_blockNumber' + apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+ case 'getGasPrice':
+ url += '/api?module=proxy&action=eth_gasPrice' + apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+
+ case 'getBalance':
+ // Returns base-10 result
+ url += '/api?module=account&action=balance&address=' + params.address;
+ url += '&tag=' + params.blockTag + apiKey;
+ return Provider.fetchJSON(url, null, getResult);
+
+ case 'getTransactionCount':
+ url += '/api?module=proxy&action=eth_getTransactionCount&address=' + params.address;
+ url += '&tag=' + params.blockTag + apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+ case 'getCode':
+ url += '/api?module=proxy&action=eth_getCode&address=' + params.address;
+ url += '&tag=' + params.blockTag + apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+ case 'getStorageAt':
+ url += '/api?module=proxy&action=eth_getStorageAt&address=' + params.address;
+ url += '&position=' + params.position;
+ url += '&tag=' + params.blockTag + apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+ case 'sendTransaction':
+ url += '/api?module=proxy&action=eth_sendRawTransaction&hex=' + params.signedTransaction;
+ url += apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+
+ case 'getBlock':
+ if (params.blockTag) {
+ url += '/api?module=proxy&action=eth_getBlockByNumber&tag=' + params.blockTag;
+ url += '&boolean=false';
+ url += apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+ }
+ throw new Error('getBlock by blockHash not implmeneted');
+
+ case 'getTransaction':
+ url += '/api?module=proxy&action=eth_getTransactionByHash&txhash=' + params.transactionHash;
+ url += apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+ case 'getTransactionReceipt':
+ url += '/api?module=proxy&action=eth_getTransactionReceipt&txhash=' + params.transactionHash;
+ url += apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+
+ case 'call':
+ var transaction = getTransactionString(params.transaction);
+ if (transaction) { transaction = '&' + transaction; }
+ url += '/api?module=proxy&action=eth_call' + transaction;
+ url += apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+ case 'estimateGas':
+ var transaction = getTransactionString(params.transaction);
+ if (transaction) { transaction = '&' + transaction; }
+ url += '/api?module=proxy&action=eth_estimateGas&' + transaction;
+ url += apiKey;
+ return Provider.fetchJSON(url, null, getJsonResult);
+
+ case 'getLogs':
+ url += '/api?module=logs&action=getLogs';
+ try {
+ if (params.filter.fromBlock) {
+ url += '&fromBlock=' + checkLogTag(params.filter.fromBlock);
+ }
+
+ if (params.filter.toBlock) {
+ url += '&toBlock=' + checkLogTag(params.filter.toBlock);
+ }
+
+ if (params.filter.address) {
+ url += '&address=' + params.filter.address;
+ }
+
+ // @TODO: We can handle slightly more complicated logs using the logs API
+ if (params.filter.topics && params.filter.topics.length > 0) {
+ if (params.filter.topics.length > 1) {
+ throw new Error('unsupported topic format');
+ }
+ var topic0 = params.filter.topics[0];
+ if (typeof(topic0) !== 'string' || topic0.length !== 66) {
+ throw new Error('unsupported topic0 format');
+ }
+ url += '&topic0=' + topic0;
+ }
+ } catch (error) {
+ return Promise.reject(error);
+ }
+
+
+ url += apiKey;
+ return Provider.fetchJSON(url, null, getResult);
+
+ case 'getEtherPrice':
+ if (this.name !== 'homestead') { return Promise.resolve(0.0); }
+ url += '/api?module=stats&action=ethprice';
+ url += apiKey;
+ return Provider.fetchJSON(url, null, getResult).then(function(result) {
+ return parseFloat(result.ethusd);
+ });
+
+ default:
+ break;
+ }
+
+ return Promise.reject(new Error('not implemented - ' + method));
+});
+
+utils.defineProperty(EtherscanProvider.prototype, 'getHistory', function(addressOrName, startBlock, endBlock) {
+
+ var url = this.baseUrl;
+
+ var apiKey = '';
+ if (this.apiKey) { apiKey += '&apikey=' + this.apiKey; }
+
+ if (startBlock == null) { startBlock = 0; }
+ if (endBlock == null) { endBlock = 99999999; }
+
+ return this.resolveName(addressOrName).then(function(address) {
+ url += '/api?module=account&action=txlist&address=' + address;
+ url += '&fromBlock=' + startBlock;
+ url += '&endBlock=' + endBlock;
+ url += '&sort=asc';
+
+ return Provider.fetchJSON(url, null, getResult).then(function(result) {
+ var output = [];
+ result.forEach(function(tx) {
+ ['contractAddress', 'to'].forEach(function(key) {
+ if (tx[key] == '') { delete tx[key]; }
+ });
+ if (tx.creates == null && tx.contractAddress != null) {
+ tx.creates = tx.contractAddress;
+ }
+ output.push(Provider._formatters.checkTransactionResponse(tx));
+ });
+ return output;
+ });
+ });
+});
+
+module.exports = EtherscanProvider;;
+
+},{"../utils/convert.js":18,"../utils/properties.js":21,"./provider.js":13}],8:[function(require,module,exports){
+'use strict';
+
+var inherits = require('inherits');
+
+var Provider = require('./provider.js');
+
+var utils = (function() {
+ return {
+ defineProperty: require('../utils/properties.js').defineProperty,
+ };
+})();
+
+
+function FallbackProvider(providers) {
+ if (providers.length === 0) { throw new Error('no providers'); }
+
+ var network = {};
+ ['chainId', 'ensAddress', 'name', 'testnet'].forEach(function(key) {
+ for (var i = 1; i < providers.length; i++) {
+ if (providers[0][key] !== providers[i][key]) {
+ throw new Error('incompatible providers - ' + key + ' mismatch');
+ }
+ }
+ network[key] = providers[0][key];
+ });
+
+ if (!(this instanceof FallbackProvider)) { throw new Error('missing new'); }
+ Provider.call(this, network);
+
+ providers = providers.slice(0);
+ Object.defineProperty(this, 'providers', {
+ get: function() {
+ return providers.slice(0);
+ }
+ });
+}
+inherits(FallbackProvider, Provider);
+
+
+utils.defineProperty(FallbackProvider.prototype, 'perform', function(method, params) {
+ var providers = this.providers;
+ return new Promise(function(resolve, reject) {
+ var firstError = null;
+ function next() {
+ if (!providers.length) {
+ reject(firstError);
+ return;
+ }
+
+ var provider = providers.shift();
+ provider.perform(method, params).then(function(result) {
+ resolve(result);
+ }, function (error) {
+ if (!firstError) { firstError = error; }
+ next();
+ });
+ }
+ next();
+ });
+});
+
+module.exports = FallbackProvider;
+
+},{"../utils/properties.js":21,"./provider.js":13,"inherits":3}],9:[function(require,module,exports){
+'use strict';
+
+var Provider = require('./provider.js');
+
+var EtherscanProvider = require('./etherscan-provider.js');
+var FallbackProvider = require('./fallback-provider.js');
+var InfuraProvider = require('./infura-provider.js');
+var JsonRpcProvider = require('./json-rpc-provider.js');
+var Web3Provider = require('./web3-provider.js');
+
+function getDefaultProvider(network) {
+ return new FallbackProvider([
+ new InfuraProvider(network),
+ new EtherscanProvider(network),
+ ]);
+}
+
+module.exports = {
+ EtherscanProvider: EtherscanProvider,
+ FallbackProvider: FallbackProvider,
+ InfuraProvider: InfuraProvider,
+ JsonRpcProvider: JsonRpcProvider,
+ Web3Provider: Web3Provider,
+
+ isProvider: Provider.isProvider,
+
+ networks: Provider.networks,
+
+ getDefaultProvider:getDefaultProvider,
+
+ Provider: Provider,
+}
+
+},{"./etherscan-provider.js":7,"./fallback-provider.js":8,"./infura-provider.js":10,"./json-rpc-provider.js":11,"./provider.js":13,"./web3-provider.js":14}],10:[function(require,module,exports){
+'use strict';
+
+var Provider = require('./provider');
+var JsonRpcProvider = require('./json-rpc-provider');
+
+var utils = (function() {
+ return {
+ defineProperty: require('../utils/properties.js').defineProperty
+ }
+})();
+
+function InfuraProvider(network, apiAccessToken) {
+ if (!(this instanceof InfuraProvider)) { throw new Error('missing new'); }
+
+ network = Provider.getNetwork(network);
+
+ var host = null;
+ switch(network.name) {
+ case 'homestead':
+ host = 'mainnet.infura.io';
+ break;
+ case 'ropsten':
+ host = 'ropsten.infura.io';
+ break;
+ case 'rinkeby':
+ host = 'rinkeby.infura.io';
+ break;
+ case 'kovan':
+ host = 'kovan.infura.io';
+ break;
+ default:
+ throw new Error('unsupported network');
+ }
+
+ var url = 'https://' + host + '/' + (apiAccessToken || '');
+
+ JsonRpcProvider.call(this, url, network);
+
+ utils.defineProperty(this, 'apiAccessToken', apiAccessToken || null);
+}
+JsonRpcProvider.inherits(InfuraProvider);
+
+utils.defineProperty(InfuraProvider.prototype, '_startPending', function() {
+ console.log('WARNING: INFURA does not support pending filters');
+});
+
+utils.defineProperty(InfuraProvider.prototype, '_stopPending', function() {
+});
+
+module.exports = InfuraProvider;
+
+},{"../utils/properties.js":21,"./json-rpc-provider":11,"./provider":13}],11:[function(require,module,exports){
+'use strict';
+
+// See: https://github.com/ethereum/wiki/wiki/JSON-RPC
+
+var Provider = require('./provider.js');
+
+var utils = (function() {
+ var convert = require('../utils/convert');
+ return {
+ defineProperty: require('../utils/properties').defineProperty,
+
+ hexlify: convert.hexlify,
+ isHexString: convert.isHexString,
+ hexStripZeros: convert.hexStripZeros,
+ }
+})();
+
+function timer(timeout) {
+ return new Promise(function(resolve) {
+ setTimeout(function() {
+ resolve();
+ }, timeout);
+ });
+}
+
+function getResult(payload) {
+ if (payload.error) {
+ var error = new Error(payload.error.message);
+ error.code = payload.error.code;
+ error.data = payload.error.data;
+ throw error;
+ }
+
+ return payload.result;
+}
+
+function getTransaction(transaction) {
+ var result = {};
+
+ for (var key in transaction) {
+ result[key] = utils.hexlify(transaction[key]);
+ }
+
+ // Some nodes (INFURA ropsten; INFURA mainnet is fine) don't like extra zeros.
+ ['gasLimit', 'gasPrice', 'nonce', 'value'].forEach(function(key) {
+ if (!result[key]) { return; }
+ result[key] = utils.hexStripZeros(result[key]);
+ });
+
+ // Transform "gasLimit" to "gas"
+ if (result.gasLimit != null && result.gas == null) {
+ result.gas = result.gasLimit;
+ delete result.gasLimit;
+ }
+
+ return result;
+}
+
+function JsonRpcProvider(url, network) {
+ if (!(this instanceof JsonRpcProvider)) { throw new Error('missing new'); }
+
+ if (arguments.length == 1) {
+ if (typeof(url) === 'string') {
+ try {
+ network = Provider.getNetwork(url);
+ url = null;
+ } catch (error) { }
+ } else {
+ network = url;
+ url = null;
+ }
+ }
+
+ Provider.call(this, network);
+
+ if (!url) { url = 'http://localhost:8545'; }
+
+ utils.defineProperty(this, 'url', url);
+}
+Provider.inherits(JsonRpcProvider);
+
+utils.defineProperty(JsonRpcProvider.prototype, 'send', function(method, params) {
+ var request = {
+ method: method,
+ params: params,
+ id: 42,
+ jsonrpc: "2.0"
+ };
+ return Provider.fetchJSON(this.url, JSON.stringify(request), getResult);
+});
+
+utils.defineProperty(JsonRpcProvider.prototype, 'perform', function(method, params) {
+ switch (method) {
+ case 'getBlockNumber':
+ return this.send('eth_blockNumber', []);
+
+ case 'getGasPrice':
+ return this.send('eth_gasPrice', []);
+
+ case 'getBalance':
+ return this.send('eth_getBalance', [params.address, params.blockTag]);
+
+ case 'getTransactionCount':
+ return this.send('eth_getTransactionCount', [params.address, params.blockTag]);
+
+ case 'getCode':
+ return this.send('eth_getCode', [params.address, params.blockTag]);
+
+ case 'getStorageAt':
+ return this.send('eth_getStorageAt', [params.address, params.position, params.blockTag]);
+
+ case 'sendTransaction':
+ return this.send('eth_sendRawTransaction', [params.signedTransaction]);
+
+ case 'getBlock':
+ if (params.blockTag) {
+ return this.send('eth_getBlockByNumber', [params.blockTag, false]);
+ } else if (params.blockHash) {
+ return this.send('eth_getBlockByHash', [params.blockHash, false]);
+ }
+ return Promise.reject(new Error('invalid block tag or block hash'));
+
+ case 'getTransaction':
+ return this.send('eth_getTransactionByHash', [params.transactionHash]);
+
+ case 'getTransactionReceipt':
+ return this.send('eth_getTransactionReceipt', [params.transactionHash]);
+
+ case 'call':
+ return this.send('eth_call', [getTransaction(params.transaction), 'latest']);
+
+ case 'estimateGas':
+ return this.send('eth_estimateGas', [getTransaction(params.transaction)]);
+
+ case 'getLogs':
+ return this.send('eth_getLogs', [params.filter]);
+
+ default:
+ break;
+ }
+
+ return Promise.reject(new Error('not implemented - ' + method));
+});
+
+utils.defineProperty(JsonRpcProvider.prototype, '_startPending', function() {
+ if (this._pendingFilter != null) { return; }
+ var self = this;
+
+ var pendingFilter = this.send('eth_newPendingTransactionFilter', []);
+ this._pendingFilter = pendingFilter;
+
+ pendingFilter.then(function(filterId) {
+ function poll() {
+ self.send('eth_getFilterChanges', [ filterId ]).then(function(hashes) {
+ if (self._pendingFilter != pendingFilter) { return; }
+
+ var seq = Promise.resolve();
+ hashes.forEach(function(hash) {
+ seq = seq.then(function() {
+ return self.getTransaction(hash).then(function(tx) {
+ self.emit('pending', tx);
+ });
+ });
+ });
+
+ return seq.then(function() {
+ return timer(1000);
+ });
+ }).then(function() {
+ if (self._pendingFilter != pendingFilter) {
+ self.send('eth_uninstallFilter', [ filterIf ]);
+ return;
+ }
+ setTimeout(function() { poll(); }, 0);
+ });
+ }
+ poll();
+
+ return filterId;
+ });
+});
+
+utils.defineProperty(JsonRpcProvider.prototype, '_stopPending', function() {
+ this._pendingFilter = null;
+});
+
+utils.defineProperty(JsonRpcProvider, '_hexlifyTransaction', function(transaction) {
+ return getTransaction(transaction);
+});
+
+module.exports = JsonRpcProvider;
+
+},{"../utils/convert":18,"../utils/properties":21,"./provider.js":13}],12:[function(require,module,exports){
+module.exports={
+ "unspecified": {
+ "chainId": 0,
+ "name": "unspecified"
+ },
+
+ "homestead": {
+ "chainId": 1,
+ "ensAddress": "0x314159265dd8dbb310642f98f50c066173c1259b",
+ "name": "homestead"
+ },
+ "mainnet": {
+ "chainId": 1,
+ "ensAddress": "0x314159265dd8dbb310642f98f50c066173c1259b",
+ "name": "homestead"
+ },
+
+ "morden": {
+ "chainId": 2,
+ "name": "morden"
+ },
+
+ "ropsten": {
+ "chainId": 3,
+ "ensAddress": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
+ "name": "ropsten"
+ },
+ "testnet": {
+ "chainId": 3,
+ "ensAddress": "0x112234455c3a32fd11230c42e7bccd4a84e02010",
+ "name": "ropsten"
+ },
+
+ "rinkeby": {
+ "chainId": 4,
+ "name": "rinkeby"
+ },
+
+ "kovan": {
+ "chainId": 42,
+ "name": "kovan"
+ },
+
+ "classic": {
+ "chainId": 61,
+ "name": "classic"
+ }
+}
+
+},{}],13:[function(require,module,exports){
+'use strict';
+
+var inherits = require('inherits');
+
+var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
+
+var networks = require('./networks.json');
+
+var utils = (function() {
+ var convert = require('../utils/convert');
+ return {
+ defineProperty: require('../utils/properties').defineProperty,
+
+ getAddress: require('../utils/address').getAddress,
+ getContractAddress: require('../utils/contract-address').getContractAddress,
+
+ bigNumberify: require('../utils/bignumber').bigNumberify,
+ arrayify: convert.arrayify,
+
+ hexlify: convert.hexlify,
+ isHexString: convert.isHexString,
+
+ concat: convert.concat,
+ hexStripZeros: convert.hexStripZeros,
+ stripZeros: convert.stripZeros,
+
+ namehash: require('../utils/namehash'),
+
+ toUtf8String: require('../utils/utf8').toUtf8String,
+
+ RLP: require('../utils/rlp'),
+ }
+})();
+
+function copyObject(obj) {
+ var result = {};
+ for (var key in obj) { result[key] = obj[key]; }
+ return result;
+}
+
+function check(format, object) {
+ var result = {};
+ for (var key in format) {
+ try {
+ var value = format[key](object[key]);
+ if (value !== undefined) { result[key] = value; }
+ } catch (error) {
+ error.checkKey = key;
+ error.checkValue = object[key];
+ throw error;
+ }
+ }
+ return result;
+}
+
+function allowNull(check, nullValue) {
+ return (function(value) {
+ if (value == null) { return nullValue; }
+ return check(value);
+ });
+}
+
+function allowFalsish(check, replaceValue) {
+ return (function(value) {
+ if (!value) { return replaceValue; }
+ return check(value);
+ });
+}
+
+function arrayOf(check) {
+ return (function(array) {
+ if (!Array.isArray(array)) { throw new Error('not an array'); }
+
+ var result = [];
+
+ array.forEach(function(value) {
+ result.push(check(value));
+ });
+
+ return result;
+ });
+}
+
+function checkHash(hash) {
+ if (!utils.isHexString(hash) || hash.length !== 66) {
+ throw new Error('invalid hash - ' + hash);
+ }
+ return hash;
+}
+
+function checkNumber(number) {
+ return utils.bigNumberify(number).toNumber();
+}
+
+function checkBoolean(value) {
+ if (typeof(value) === 'boolean') { return value; }
+ if (typeof(value) === 'string') {
+ if (value === 'true') { return true; }
+ if (value === 'false') { return false; }
+ }
+ throw new Error('invaid boolean - ' + value);
+}
+
+function checkUint256(uint256) {
+ if (!utils.isHexString(uint256)) {
+ throw new Error('invalid uint256');
+ }
+ while (uint256.length < 66) {
+ uint256 = '0x0' + uint256.substring(2);
+ }
+ return uint256;
+}
+
+function checkString(string) {
+ if (typeof(string) !== 'string') { throw new Error('invalid string'); }
+ return string;
+}
+
+function checkBlockTag(blockTag) {
+ if (blockTag == null) { return 'latest'; }
+
+ if (blockTag === 'earliest') { return '0x0'; }
+
+ if (blockTag === 'latest' || blockTag === 'pending') {
+ return blockTag;
+ }
+
+ if (typeof(blockTag) === 'number') {
+ return utils.hexStripZeros(utils.hexlify(blockTag));
+ }
+
+ if (utils.isHexString(blockTag)) { return utils.hexStripZeros(blockTag); }
+
+ throw new Error('invalid blockTag');
+}
+
+var formatBlock = {
+ hash: checkHash,
+ parentHash: checkHash,
+ number: checkNumber,
+
+ timestamp: checkNumber,
+ nonce: allowNull(utils.hexlify),
+ difficulty: allowNull(checkNumber),
+
+ gasLimit: utils.bigNumberify,
+ gasUsed: utils.bigNumberify,
+
+ miner: utils.getAddress,
+ extraData: utils.hexlify,
+
+ //transactions: allowNull(arrayOf(checkTransaction)),
+ transactions: allowNull(arrayOf(checkHash)),
+
+ //transactionRoot: checkHash,
+ //stateRoot: checkHash,
+ //sha3Uncles: checkHash,
+
+ //logsBloom: utils.hexlify,
+};
+
+function checkBlock(block) {
+ if (block.author != null && block.miner == null) {
+ block.miner = block.author;
+ }
+ return check(formatBlock, block);
+}
+
+
+var formatTransaction = {
+ hash: checkHash,
+
+ blockHash: allowNull(checkHash, null),
+ blockNumber: allowNull(checkNumber, null),
+ transactionIndex: allowNull(checkNumber, null),
+
+ from: utils.getAddress,
+
+ gasPrice: utils.bigNumberify,
+ gasLimit: utils.bigNumberify,
+ to: allowNull(utils.getAddress, null),
+ value: utils.bigNumberify,
+ nonce: checkNumber,
+ data: utils.hexlify,
+
+ r: allowNull(checkUint256),
+ s: allowNull(checkUint256),
+ v: allowNull(checkNumber),
+
+ creates: allowNull(utils.getAddress, null),
+
+ raw: allowNull(utils.hexlify),
+};
+
+function checkTransaction(transaction) {
+
+ // Rename gas to gasLimit
+ if (transaction.gas != null && transaction.gasLimit == null) {
+ transaction.gasLimit = transaction.gas;
+ }
+
+ // Some clients (TestRPC) do strange things like return 0x0 for the
+ // 0 address; correct this to be a real address
+ if (transaction.to && utils.bigNumberify(transaction.to).isZero()) {
+ transaction.to = '0x0000000000000000000000000000000000000000';
+ }
+
+ // Rename input to data
+ if (transaction.input != null && transaction.data == null) {
+ transaction.data = transaction.input;
+ }
+
+ // If to and creates are empty, populate the creates from the transaction
+ if (transaction.to == null && transaction.creates == null) {
+ transaction.creates = utils.getContractAddress(transaction);
+ }
+
+ if (!transaction.raw) {
+ // Very loose providers (e.g. TestRPC) don't provide a signature or raw
+ if (transaction.v && transaction.r && transaction.s) {
+ var raw = [
+ utils.stripZeros(utils.hexlify(transaction.nonce)),
+ utils.stripZeros(utils.hexlify(transaction.gasPrice)),
+ utils.stripZeros(utils.hexlify(transaction.gasLimit)),
+ (transaction.to || "0x"),
+ utils.stripZeros(utils.hexlify(transaction.value || '0x')),
+ utils.hexlify(transaction.data || '0x'),
+ utils.stripZeros(utils.hexlify(transaction.v || '0x')),
+ utils.stripZeros(utils.hexlify(transaction.r)),
+ utils.stripZeros(utils.hexlify(transaction.s)),
+ ];
+
+ transaction.raw = utils.RLP.encode(raw);
+ }
+ }
+
+
+ var result = check(formatTransaction, transaction);
+
+ var networkId = transaction.networkId;
+
+ if (utils.isHexString(networkId)) {
+ networkId = utils.bigNumberify(networkId).toNumber();
+ }
+
+ if (typeof(networkId) !== 'number' && result.v != null) {
+ networkId = (result.v - 35) / 2;
+ if (networkId < 0) { networkId = 0; }
+ networkId = parseInt(networkId);
+ }
+
+ if (typeof(networkId) !== 'number') { networkId = 0; }
+
+ result.networkId = networkId;
+
+ // 0x0000... should actually be null
+ if (result.blockHash && result.blockHash.replace(/0/g, '') === 'x') {
+ result.blockHash = null;
+ }
+
+ return result;
+}
+
+var formatTransactionRequest = {
+ from: allowNull(utils.getAddress),
+ nonce: allowNull(checkNumber),
+ gasLimit: allowNull(utils.bigNumberify),
+ gasPrice: allowNull(utils.bigNumberify),
+ to: allowNull(utils.getAddress),
+ value: allowNull(utils.bigNumberify),
+ data: allowNull(utils.hexlify),
+};
+
+function checkTransactionRequest(transaction) {
+ return check(formatTransactionRequest, transaction);
+}
+
+var formatTransactionReceiptLog = {
+ transactionLogIndex: allowNull(checkNumber),
+ transactionIndex: checkNumber,
+ blockNumber: checkNumber,
+ transactionHash: checkHash,
+ address: utils.getAddress,
+ topics: arrayOf(checkHash),
+ data: utils.hexlify,
+ logIndex: checkNumber,
+ blockHash: checkHash,
+};
+
+function checkTransactionReceiptLog(log) {
+ return check(formatTransactionReceiptLog, log);
+}
+
+var formatTransactionReceipt = {
+ contractAddress: allowNull(utils.getAddress, null),
+ transactionIndex: checkNumber,
+ root: allowNull(checkHash),
+ gasUsed: utils.bigNumberify,
+ logsBloom: utils.hexlify,
+ blockHash: checkHash,
+ transactionHash: checkHash,
+ logs: arrayOf(checkTransactionReceiptLog),
+ blockNumber: checkNumber,
+ cumulativeGasUsed: utils.bigNumberify,
+ status: allowNull(checkNumber)
+};
+
+function checkTransactionReceipt(transactionReceipt) {
+ var status = transactionReceipt.status;
+ var root = transactionReceipt.root;
+
+ var result = check(formatTransactionReceipt, transactionReceipt);
+ result.logs.forEach(function(entry, index) {
+ if (entry.transactionLogIndex == null) {
+ entry.transactionLogIndex = index;
+ }
+ });
+ if (transactionReceipt.status != null) {
+ result.byzantium = true;
+ }
+ return result;
+}
+
+function checkTopics(topics) {
+ if (Array.isArray(topics)) {
+ topics.forEach(function(topic) {
+ checkTopics(topic);
+ });
+
+ } else if (topics != null) {
+ checkHash(topics);
+ }
+
+ return topics;
+}
+
+var formatFilter = {
+ fromBlock: allowNull(checkBlockTag, undefined),
+ toBlock: allowNull(checkBlockTag, undefined),
+ address: allowNull(utils.getAddress, undefined),
+ topics: allowNull(checkTopics, undefined),
+};
+
+function checkFilter(filter) {
+ return check(formatFilter, filter);
+}
+
+var formatLog = {
+ blockNumber: allowNull(checkNumber),
+ blockHash: allowNull(checkHash),
+ transactionIndex: checkNumber,
+
+ removed: allowNull(checkBoolean),
+
+ address: utils.getAddress,
+ data: allowFalsish(utils.hexlify, '0x'),
+
+ topics: arrayOf(checkHash),
+
+ transactionHash: checkHash,
+ logIndex: checkNumber,
+}
+
+function checkLog(log) {
+ return check(formatLog, log);
+}
+
+function Provider(network) {
+ if (!(this instanceof Provider)) { throw new Error('missing new'); }
+
+ network = Provider.getNetwork(network);
+
+ // Check the ensAddress (if any)
+ var ensAddress = null;
+ if (network.ensAddress) {
+ ensAddress = utils.getAddress(network.ensAddress);
+ }
+
+ // Setup our network properties
+ utils.defineProperty(this, 'chainId', network.chainId);
+ utils.defineProperty(this, 'ensAddress', ensAddress);
+ utils.defineProperty(this, 'name', network.name);
+
+ var events = {};
+ utils.defineProperty(this, '_events', events);
+
+ // We use this to track recent emitted events; for example, if we emit a "block" of 100
+ // and we get a `getBlock(100)` request which would result in null, we should retry
+ // until we get a response. This provides devs with a consistent view. Similarly for
+ // transaction hashes.
+ utils.defineProperty(this, '_emitted', { block: -1 });
+
+ var self = this;
+
+ var lastBlockNumber = null;
+
+ var balances = {};
+
+ function doPoll() {
+ self.getBlockNumber().then(function(blockNumber) {
+
+ // If the block hasn't changed, meh.
+ if (blockNumber === lastBlockNumber) { return; }
+
+ if (lastBlockNumber === null) { lastBlockNumber = blockNumber - 1; }
+
+ // Notify all listener for each block that has passed
+ for (var i = lastBlockNumber + 1; i <= blockNumber; i++) {
+ if (self._emitted.block < i) {
+ self._emitted.block = i;
+
+ // Evict any transaction hashes or block hashes over 12 blocks
+ // old, since they should not return null anyways
+ Object.keys(self._emitted).forEach(function(key) {
+ if (key === 'block') { return; }
+
+ if (self._emitted[key] > i + 12) {
+ delete self._emitted[key];
+ }
+ });
+ }
+ self.emit('block', i);
+ }
+
+ // Sweep balances and remove addresses we no longer have events for
+ var newBalances = {};
+
+ // Find all transaction hashes we are waiting on
+ Object.keys(events).forEach(function(eventName) {
+ var event = parseEventString(eventName);
+
+ if (event.type === 'transaction') {
+ self.getTransaction(event.hash).then(function(transaction) {
+ if (!transaction || transaction.blockNumber == null) { return; }
+ self._emitted['t:' + transaction.hash.toLowerCase()] = transaction.blockNumber;
+ self.emit(event.hash, transaction);
+ });
+
+ } else if (event.type === 'address') {
+ if (balances[event.address]) {
+ newBalances[event.address] = balances[event.address];
+ }
+ self.getBalance(event.address, 'latest').then(function(balance) {
+ var lastBalance = balances[event.address];
+ if (lastBalance && balance.eq(lastBalance)) { return; }
+ balances[event.address] = balance;
+ self.emit(event.address, balance);
+ });
+
+ } else if (event.type === 'topic') {
+ self.getLogs({
+ fromBlock: lastBlockNumber + 1,
+ toBlock: blockNumber,
+ topics: event.topic
+ }).then(function(logs) {
+ if (logs.length === 0) { return; }
+ logs.forEach(function(log) {
+ self._emitted['b:' + log.blockHash.toLowerCase()] = log.blockNumber;
+ self._emitted['t:' + log.transactionHash.toLowerCase()] = log.blockNumber;
+ self.emit(event.topic, log);
+ });
+ });
+ }
+ });
+
+ lastBlockNumber = blockNumber;
+
+ balances = newBalances;
+ });
+
+ self.doPoll();
+ }
+
+ utils.defineProperty(this, 'resetEventsBlock', function(blockNumber) {
+ lastBlockNumber = blockNumber;
+ self.doPoll();
+ });
+
+ var poller = null;
+ Object.defineProperty(this, 'polling', {
+ get: function() { return (poller != null); },
+ set: function(value) {
+ setTimeout(function() {
+ if (value && !poller) {
+ poller = setInterval(doPoll, 4000);
+
+ } else if (!value && poller) {
+ clearInterval(poller);
+ poller = null;
+ }
+ }, 0);
+ }
+ });
+}
+
+function inheritable(parent) {
+ return function(child) {
+ inherits(child, parent);
+ utils.defineProperty(child, 'inherits', inheritable(child));
+ }
+}
+
+utils.defineProperty(Provider, 'inherits', inheritable(Provider));
+/*
+function(child) {
+ inherits(child, Provider);
+ child.inherits = function(grandchild) {
+ inherits(grandchild, child)
+ }
+});
+*/
+
+utils.defineProperty(Provider, 'getNetwork', function(network) {
+
+ if (typeof(network) === 'string') {
+ network = networks[network];
+ if (!network) { throw new Error('unknown network'); }
+
+ } else if (network == null) {
+ network = networks['homestead'];
+ }
+
+ if (typeof(network.chainId) !== 'number') { throw new Error('invalid chainId'); }
+
+ return network;
+});
+
+utils.defineProperty(Provider, 'networks', networks);
+
+utils.defineProperty(Provider, 'fetchJSON', function(url, json, processFunc) {
+
+ return new Promise(function(resolve, reject) {
+ var request = new XMLHttpRequest();
+
+ if (json) {
+ request.open('POST', url, true);
+ request.setRequestHeader('Content-Type','application/json');
+ } else {
+ request.open('GET', url, true);
+ }
+
+ request.onreadystatechange = function() {
+ if (request.readyState !== 4) { return; }
+
+ try {
+ var result = JSON.parse(request.responseText);
+ } catch (error) {
+ var jsonError = new Error('invalid json response');
+ jsonError.orginialError = error;
+ jsonError.responseText = request.responseText;
+ reject(jsonError);
+ return;
+ }
+
+ if (processFunc) {
+ try {
+ result = processFunc(result);
+ } catch (error) {
+ error.url = url;
+ error.body = json;
+ error.responseText = request.responseText;
+ reject(error);
+ return;
+ }
+ }
+
+ if (request.status != 200) {
+ var error = new Error('invalid response - ' + request.status);
+ error.statusCode = request.statusCode;
+ reject(error);
+ return;
+ }
+
+ resolve(result);
+ };
+
+ request.onerror = function(error) {
+ reject(error);
+ }
+
+ try {
+ if (json) {
+ request.send(json);
+ } else {
+ request.send();
+ }
+
+ } catch (error) {
+ var connectionError = new Error('connection error');
+ connectionError.error = error;
+ reject(connectionError);
+ }
+ });
+});
+
+
+utils.defineProperty(Provider.prototype, 'waitForTransaction', function(transactionHash, timeout) {
+ var self = this;
+ return new Promise(function(resolve, reject) {
+ var timer = null;
+
+ function complete(transaction) {
+ if (timer) { clearTimeout(timer); }
+ resolve(transaction);
+ }
+
+ self.once(transactionHash, complete);
+
+ if (typeof(timeout) === 'number' && timeout > 0) {
+ timer = setTimeout(function() {
+ self.removeListener(transactionHash, complete);
+ reject(new Error('timeout'));
+ }, timeout);
+ }
+
+ });
+});
+
+
+utils.defineProperty(Provider.prototype, 'getBlockNumber', function() {
+ try {
+ return this.perform('getBlockNumber').then(function(result) {
+ var value = parseInt(result);
+ if (value != result) { throw new Error('invalid response - getBlockNumber'); }
+ return value;
+ });
+ } catch (error) {
+ return Promise.reject(error);
+ }
+});
+
+utils.defineProperty(Provider.prototype, 'getGasPrice', function() {
+ try {
+ return this.perform('getGasPrice').then(function(result) {
+ return utils.bigNumberify(result);
+ });
+ } catch (error) {
+ return Promise.reject(error);
+ }
+});
+
+
+utils.defineProperty(Provider.prototype, 'getBalance', function(addressOrName, blockTag) {
+ var self = this;
+ return this.resolveName(addressOrName).then(function(address) {
+ var params = { address: address, blockTag: checkBlockTag(blockTag) };
+ return self.perform('getBalance', params).then(function(result) {
+ return utils.bigNumberify(result);
+ });
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'getTransactionCount', function(addressOrName, blockTag) {
+ var self = this;
+ return this.resolveName(addressOrName).then(function(address) {
+ var params = { address: address, blockTag: checkBlockTag(blockTag) };
+ return self.perform('getTransactionCount', params).then(function(result) {
+ var value = parseInt(result);
+ if (value != result) { throw new Error('invalid response - getTransactionCount'); }
+ return value;
+ });
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'getCode', function(addressOrName, blockTag) {
+ var self = this;
+ return this.resolveName(addressOrName).then(function(address) {
+ var params = {address: address, blockTag: checkBlockTag(blockTag)};
+ return self.perform('getCode', params).then(function(result) {
+ return utils.hexlify(result);
+ });
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'getStorageAt', function(addressOrName, position, blockTag) {
+ var self = this;
+ return this.resolveName(addressOrName).then(function(address) {
+ var params = {
+ address: address,
+ blockTag: checkBlockTag(blockTag),
+ position: utils.hexStripZeros(utils.hexlify(position)),
+ };
+ return self.perform('getStorageAt', params).then(function(result) {
+ return utils.hexlify(result);
+ });
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'sendTransaction', function(signedTransaction) {
+ try {
+ var params = {signedTransaction: utils.hexlify(signedTransaction)};
+ return this.perform('sendTransaction', params).then(function(result) {
+ result = utils.hexlify(result);
+ if (result.length !== 66) { throw new Error('invalid response - sendTransaction'); }
+ return result;
+ });
+ } catch (error) {
+ return Promise.reject(error);
+ }
+});
+
+
+utils.defineProperty(Provider.prototype, 'call', function(transaction) {
+ var self = this;
+ return this._resolveNames(transaction, [ 'to', 'from' ]).then(function(transaction) {
+ var params = { transaction: checkTransactionRequest(transaction) };
+ return self.perform('call', params).then(function(result) {
+ return utils.hexlify(result);
+ });
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'estimateGas', function(transaction) {
+ var self = this;
+ return this._resolveNames(transaction, [ 'to', 'from' ]).then(function(transaction) {
+ var params = {transaction: checkTransactionRequest(transaction)};
+ return self.perform('estimateGas', params).then(function(result) {
+ return utils.bigNumberify(result);
+ });
+ });
+});
+
+function stallPromise(allowNullFunc, executeFunc) {
+ return new Promise(function(resolve, reject) {
+ var attempt = 0;
+ function check() {
+ executeFunc().then(function(result) {
+ // If we have a result, or are allowed null then we're done
+ if (result || allowNullFunc()) {
+ resolve(result);
+
+ // Otherwise, exponential back-off (up to 10s) our next request
+ } else {
+ attempt++;
+ var timeout = 500 + 250 * parseInt(Math.random() * (1 << attempt));
+ if (timeout > 10000) { timeout = 10000; }
+ setTimeout(check, timeout);
+ }
+ }, function(error) {
+ reject(error);
+ });
+ }
+ check();
+ });
+}
+
+utils.defineProperty(Provider.prototype, 'getBlock', function(blockHashOrBlockTag) {
+ var self = this;
+ try {
+ var blockHash = utils.hexlify(blockHashOrBlockTag);
+ if (blockHash.length === 66) {
+ return stallPromise(function() {
+ return (self._emitted['b:' + blockHash.toLowerCase()] == null);
+ }, function() {
+ return self.perform('getBlock', {blockHash: blockHash}).then(function(block) {
+ if (block == null) { return null; }
+ return checkBlock(block);
+ });
+ });
+ }
+ } catch (error) { }
+
+ try {
+ var blockTag = checkBlockTag(blockHashOrBlockTag);
+ return stallPromise(function() {
+ if (utils.isHexString(blockTag)) {
+ var blockNumber = parseInt(blockTag.substring(2), 16);
+ return blockNumber > self._emitted.block;
+ }
+ return true;
+ }, function() {
+ return self.perform('getBlock', { blockTag: blockTag }).then(function(block) {
+ if (block == null) { return null; }
+ return checkBlock(block);
+ });
+ });
+ } catch (error) { }
+
+ return Promise.reject(new Error('invalid block hash or block tag'));
+});
+
+utils.defineProperty(Provider.prototype, 'getTransaction', function(transactionHash) {
+ var self = this;
+ try {
+ var params = { transactionHash: checkHash(transactionHash) };
+ return stallPromise(function() {
+ return (self._emitted['t:' + transactionHash.toLowerCase()] == null);
+ }, function() {
+ return self.perform('getTransaction', params).then(function(result) {
+ if (result != null) { result = checkTransaction(result); }
+ return result;
+ });
+ });
+ } catch (error) {
+ return Promise.reject(error);
+ }
+});
+
+utils.defineProperty(Provider.prototype, 'getTransactionReceipt', function(transactionHash) {
+ var self = this;
+
+ try {
+ var params = { transactionHash: checkHash(transactionHash) };
+ return stallPromise(function() {
+ return (self._emitted['t:' + transactionHash.toLowerCase()] == null);
+ }, function() {
+ return self.perform('getTransactionReceipt', params).then(function(result) {
+ if (result != null) { result = checkTransactionReceipt(result); }
+ return result;
+ });
+ });
+ } catch (error) {
+ return Promise.reject(error);
+ }
+});
+
+utils.defineProperty(Provider.prototype, 'getLogs', function(filter) {
+ var self = this;
+ return this._resolveNames(filter, ['address']).then(function(filter) {
+ var params = { filter: checkFilter(filter) };
+ return self.perform('getLogs', params).then(function(result) {
+ return arrayOf(checkLog)(result);
+ });
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'getEtherPrice', function() {
+ try {
+ return this.perform('getEtherPrice', {}).then(function(result) {
+ // @TODO: Check valid float
+ return result;
+ });
+ } catch (error) {
+ return Promise.reject(error);
+ }
+});
+
+
+utils.defineProperty(Provider.prototype, '_resolveNames', function(object, keys) {
+ var promises = [];
+
+ var result = copyObject(object);
+
+ keys.forEach(function(key) {
+ if (result[key] === undefined) { return; }
+ promises.push(this.resolveName(result[key]).then(function(address) {
+ result[key] = address;
+ }));
+ }, this);
+
+ return Promise.all(promises).then(function() { return result; });
+});
+
+utils.defineProperty(Provider.prototype, '_getResolver', function(name) {
+ var nodeHash = utils.namehash(name);
+
+ // keccak256('resolver(bytes32)')
+ var data = '0x0178b8bf' + nodeHash.substring(2);
+ var transaction = { to: this.ensAddress, data: data };
+
+ // Get the resolver from the blockchain
+ return this.call(transaction).then(function(data) {
+
+ // extract the address from the data
+ if (data.length != 66) { return null; }
+ return utils.getAddress('0x' + data.substring(26));
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'resolveName', function(name) {
+ // If it is already an address, nothing to resolve
+ try {
+ return Promise.resolve(utils.getAddress(name));
+ } catch (error) { }
+
+ if (!this.ensAddress) { throw new Error('network does not have ENS deployed'); }
+
+ var self = this;
+
+ var nodeHash = utils.namehash(name);
+
+ // Get the addr from the resovler
+ return this._getResolver(name).then(function(resolverAddress) {
+
+ // keccak256('addr(bytes32)')
+ var data = '0x3b3b57de' + nodeHash.substring(2);
+ var transaction = { to: resolverAddress, data: data };
+ return self.call(transaction);
+
+ // extract the address from the data
+ }).then(function(data) {
+ if (data.length != 66) { return null; }
+ var address = utils.getAddress('0x' + data.substring(26));
+ if (address === '0x0000000000000000000000000000000000000000') { return null; }
+ return address;
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'lookupAddress', function(address) {
+ if (!this.ensAddress) { throw new Error('network does not have ENS deployed'); }
+
+ address = utils.getAddress(address);
+
+ var name = address.substring(2) + '.addr.reverse'
+ var nodehash = utils.namehash(name);
+
+ var self = this;
+
+ return this._getResolver(name).then(function(resolverAddress) {
+ if (!resolverAddress) { return null; }
+
+ // keccak('name(bytes32)')
+ var data = '0x691f3431' + nodehash.substring(2);
+ var transaction = { to: resolverAddress, data: data };
+ return self.call(transaction);
+
+ }).then(function(data) {
+ // Strip off the "0x"
+ data = data.substring(2);
+
+ // Strip off the dynamic string pointer (0x20)
+ if (data.length < 64) { return null; }
+ data = data.substring(64);
+
+ if (data.length < 64) { return null; }
+ var length = utils.bigNumberify('0x' + data.substring(0, 64)).toNumber();
+ data = data.substring(64);
+
+ if (2 * length > data.length) { return null; }
+
+ var name = utils.toUtf8String('0x' + data.substring(0, 2 * length));
+
+ // Make sure the reverse record matches the foward record
+ return self.resolveName(name).then(function(addr) {
+ if (addr != address) { return null; }
+ return name;
+ });
+
+ });
+});
+
+utils.defineProperty(Provider.prototype, 'doPoll', function() {
+});
+
+utils.defineProperty(Provider.prototype, 'perform', function(method, params) {
+ return Promise.reject(new Error('not implemented - ' + method));
+});
+
+function recurse(object, convertFunc) {
+ if (Array.isArray(object)) {
+ var result = [];
+ object.forEach(function(object) {
+ result.push(recurse(object, convertFunc));
+ });
+ return result;
+ }
+ return convertFunc(object);
+}
+
+function getEventString(object) {
+ try {
+ return 'address:' + utils.getAddress(object);
+ } catch (error) { }
+
+ if (object === 'block') {
+ return 'block';
+
+ } else if (object === 'pending') {
+ return 'pending';
+
+ } else if (utils.isHexString(object)) {
+ if (object.length === 66) {
+ return 'tx:' + object;
+ }
+ } else if (Array.isArray(object)) {
+ object = recurse(object, function(object) {
+ if (object == null) { object = '0x'; }
+ return object;
+ });
+
+ try {
+ return 'topic:' + utils.RLP.encode(object);
+ } catch (error) {
+ console.log(error);
+ }
+ }
+
+ throw new Error('invalid event - ' + object);
+}
+
+function parseEventString(string) {
+ if (string.substring(0, 3) === 'tx:') {
+ return {type: 'transaction', hash: string.substring(3)};
+
+ } else if (string === 'block') {
+ return {type: 'block'};
+
+ } else if (string === 'pending') {
+ return {type: 'pending'};
+
+ } else if (string.substring(0, 8) === 'address:') {
+ return {type: 'address', address: string.substring(8)};
+
+ } else if (string.substring(0, 6) === 'topic:') {
+ try {
+ var object = utils.RLP.decode(string.substring(6));
+ object = recurse(object, function(object) {
+ if (object === '0x') { object = null; }
+ return object;
+ });
+ return {type: 'topic', topic: object};
+ } catch (error) {
+ console.log(error);
+ }
+ }
+
+ throw new Error('invalid event string');
+}
+
+utils.defineProperty(Provider.prototype, '_startPending', function() {
+ console.log('WARNING: this provider does not support pending events');
+});
+
+utils.defineProperty(Provider.prototype, '_stopPending', function() {
+});
+
+utils.defineProperty(Provider.prototype, 'on', function(eventName, listener) {
+ var key = getEventString(eventName);
+ if (!this._events[key]) { this._events[key] = []; }
+ this._events[key].push({eventName: eventName, listener: listener, type: 'on'});
+ if (key === 'pending') { this._startPending(); }
+ this.polling = true;
+});
+
+utils.defineProperty(Provider.prototype, 'once', function(eventName, listener) {
+ var key = getEventString(eventName);
+ if (!this._events[key]) { this._events[key] = []; }
+ this._events[key].push({eventName: eventName, listener: listener, type: 'once'});
+ if (key === 'pending') { this._startPending(); }
+ this.polling = true;
+});
+
+utils.defineProperty(Provider.prototype, 'emit', function(eventName) {
+ var key = getEventString(eventName);
+
+ var args = Array.prototype.slice.call(arguments, 1);
+ var listeners = this._events[key];
+ if (!listeners) { return; }
+
+ for (var i = 0; i < listeners.length; i++) {
+ var listener = listeners[i];
+ if (listener.type === 'once') {
+ listeners.splice(i, 1);
+ i--;
+ }
+
+ try {
+ listener.listener.apply(this, args);
+ } catch (error) {
+ console.log('Event Listener Error: ' + error.message);
+ }
+ }
+
+ if (listeners.length === 0) {
+ delete this._events[key];
+ if (key === 'pending') { this._stopPending(); }
+ }
+
+ if (this.listenerCount() === 0) { this.polling = false; }
+});
+
+utils.defineProperty(Provider.prototype, 'listenerCount', function(eventName) {
+ if (!eventName) {
+ var result = 0;
+ for (var key in this._events) {
+ result += this._events[key].length;
+ }
+ return result;
+ }
+
+ var listeners = this._events[getEventString(eventName)];
+ if (!listeners) { return 0; }
+ return listeners.length;
+});
+
+utils.defineProperty(Provider.prototype, 'listeners', function(eventName) {
+ var listeners = this._events[getEventString(eventName)];
+ if (!listeners) { return 0; }
+ var result = [];
+ for (var i = 0; i < listeners.length; i++) {
+ result.push(listeners[i].listener);
+ }
+ return result;
+});
+
+utils.defineProperty(Provider.prototype, 'removeAllListeners', function(eventName) {
+ delete this._events[getEventString(eventName)];
+ if (this.listenerCount() === 0) { this.polling = false; }
+});
+
+utils.defineProperty(Provider.prototype, 'removeListener', function(eventName, listener) {
+ var eventNameString = getEventString(eventName);
+ var listeners = this._events[eventNameString];
+ if (!listeners) { return 0; }
+ for (var i = 0; i < listeners.length; i++) {
+ if (listeners[i].listener === listener) {
+ listeners.splice(i, 1);
+ break;
+ }
+ }
+
+ if (listeners.length === 0) {
+ this.removeAllListeners(eventName);
+ }
+});
+
+utils.defineProperty(Provider, '_formatters', {
+ checkTransactionResponse: checkTransaction
+});
+
+module.exports = Provider;
+
+},{"../utils/address":15,"../utils/bignumber":16,"../utils/contract-address":17,"../utils/convert":18,"../utils/namehash":20,"../utils/properties":21,"../utils/rlp":22,"../utils/utf8":24,"./networks.json":12,"inherits":3,"xmlhttprequest":6}],14:[function(require,module,exports){
+'use strict';
+
+var Provider = require('./provider');
+var JsonRpcProvider = require('./json-rpc-provider');
+
+var utils = (function() {
+ return {
+ defineProperty: require('../utils/properties').defineProperty,
+
+ getAddress: require('../utils/address').getAddress,
+
+ toUtf8Bytes: require('../utils/utf8').toUtf8Bytes,
+
+ hexlify: require('../utils/convert').hexlify
+ }
+})();
+
+function Web3Signer(provider, address) {
+ if (!(this instanceof Web3Signer)) { throw new Error('missing new'); }
+ utils.defineProperty(this, 'provider', provider);
+
+ // Statically attach to a given address
+ if (address) {
+ utils.defineProperty(this, 'address', address);
+ utils.defineProperty(this, '_syncAddress', true);
+
+ } else {
+ Object.defineProperty(this, 'address', {
+ enumerable: true,
+ get: function() {
+ throw new Error('unsupported sync operation; use getAddress');
+ }
+ });
+ utils.defineProperty(this, '_syncAddress', false);
+ }
+}
+
+utils.defineProperty(Web3Signer.prototype, 'getAddress', function() {
+ if (this._syncAddress) { return Promise.resolve(this.address); }
+
+ return this.provider.send('eth_accounts', []).then(function(accounts) {
+ if (accounts.length === 0) {
+ throw new Error('no account');
+ }
+ return utils.getAddress(accounts[0]);
+ });
+});
+
+utils.defineProperty(Web3Signer.prototype, 'getBalance', function(blockTag) {
+ var provider = this.provider;
+ return this.getAddress().then(function(address) {
+ return provider.getBalance(address, blockTag);
+ });
+});
+
+utils.defineProperty(Web3Signer.prototype, 'getTransactionCount', function(blockTag) {
+ var provider = this.provider;
+ return this.getAddress().then(function(address) {
+ return provider.getTransactionCount(address, blockTag);
+ });
+});
+
+utils.defineProperty(Web3Signer.prototype, 'sendTransaction', function(transaction) {
+ var provider = this.provider;
+ transaction = JsonRpcProvider._hexlifyTransaction(transaction);
+ return this.getAddress().then(function(address) {
+ transaction.from = address.toLowerCase();
+ return provider.send('eth_sendTransaction', [ transaction ]).then(function(hash) {
+ return new Promise(function(resolve, reject) {
+ function check() {
+ provider.getTransaction(hash).then(function(transaction) {
+ if (!transaction) {
+ setTimeout(check, 1000);
+ return;
+ }
+ resolve(transaction);
+ });
+ }
+ check();
+ });
+ });
+ });
+});
+
+utils.defineProperty(Web3Signer.prototype, 'signMessage', function(message) {
+ var provider = this.provider;
+
+ var data = ((typeof(message) === 'string') ? utils.toUtf8Bytes(message): message);
+ return this.getAddress().then(function(address) {
+
+ // https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_sign
+ var method = 'eth_sign';
+ var params = [ address.toLowerCase(), utils.hexlify(data) ];
+
+ // Metamask complains about eth_sign (and on some versions hangs)
+ if (provider._web3Provider.isMetaMask) {
+ // https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_sign
+ method = 'personal_sign';
+ params = [ utils.hexlify(data), address.toLowerCase() ];
+ }
+
+ return provider.send(method, params);
+ });
+});
+
+utils.defineProperty(Web3Signer.prototype, 'unlock', function(password) {
+ var provider = this.provider;
+
+ return this.getAddress().then(function(address) {
+ return provider.send('personal_unlockAccount', [ address.toLowerCase(), password, null ]);
+ });
+});
+
+/*
+@TODO
+utils.defineProperty(Web3Signer, 'onchange', {
+
+});
+*/
+
+function Web3Provider(web3Provider, network) {
+ if (!(this instanceof Web3Provider)) { throw new Error('missing new'); }
+
+ // HTTP has a host; IPC has a path.
+ var url = web3Provider.host || web3Provider.path || 'unknown';
+
+ JsonRpcProvider.call(this, url, network);
+ utils.defineProperty(this, '_web3Provider', web3Provider);
+}
+JsonRpcProvider.inherits(Web3Provider);
+
+utils.defineProperty(Web3Provider.prototype, 'getSigner', function(address) {
+ return new Web3Signer(this, address);
+});
+
+utils.defineProperty(Web3Provider.prototype, 'listAccounts', function() {
+ return this.send('eth_accounts', []).then(function(accounts) {
+ accounts.forEach(function(address, index) {
+ accounts[index] = utils.getAddress(address);
+ });
+ return accounts;
+ });
+});
+
+utils.defineProperty(Web3Provider.prototype, 'send', function(method, params) {
+ var provider = this._web3Provider;
+ return new Promise(function(resolve, reject) {
+ var request = {
+ method: method,
+ params: params,
+ id: 42,
+ jsonrpc: "2.0"
+ };
+ provider.sendAsync(request, function(error, result) {
+ if (error) {
+ reject(error);
+ return;
+ }
+ if (result.error) {
+ var error = new Error(result.error.message);
+ error.code = result.error.code;
+ error.data = result.error.data;
+ reject(error);
+ return;
+ }
+ resolve(result.result);
+ });
+ });
+});
+
+module.exports = Web3Provider;
+
+},{"../utils/address":15,"../utils/convert":18,"../utils/properties":21,"../utils/utf8":24,"./json-rpc-provider":11,"./provider":13}],15:[function(require,module,exports){
+
+var BN = require('bn.js');
+
+var convert = require('./convert');
+var throwError = require('./throw-error');
+var keccak256 = require('./keccak256');
+
+function getChecksumAddress(address) {
+ if (typeof(address) !== 'string' || !address.match(/^0x[0-9A-Fa-f]{40}$/)) {
+ throwError('invalid address', {input: address});
+ }
+
+ address = address.toLowerCase();
+
+ var hashed = address.substring(2).split('');
+ for (var i = 0; i < hashed.length; i++) {
+ hashed[i] = hashed[i].charCodeAt(0);
+ }
+ hashed = convert.arrayify(keccak256(hashed));
+
+ address = address.substring(2).split('');
+ for (var i = 0; i < 40; i += 2) {
+ if ((hashed[i >> 1] >> 4) >= 8) {
+ address[i] = address[i].toUpperCase();
+ }
+ if ((hashed[i >> 1] & 0x0f) >= 8) {
+ address[i + 1] = address[i + 1].toUpperCase();
+ }
+ }
+
+ return '0x' + address.join('');
+}
+
+// Shims for environments that are missing some required constants and functions
+var MAX_SAFE_INTEGER = 0x1fffffffffffff;
+
+function log10(x) {
+ if (Math.log10) { return Math.log10(x); }
+ return Math.log(x) / Math.LN10;
+}
+
+
+// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
+var ibanChecksum = (function() {
+
+ // Create lookup table
+ var ibanLookup = {};
+ for (var i = 0; i < 10; i++) { ibanLookup[String(i)] = String(i); }
+ for (var i = 0; i < 26; i++) { ibanLookup[String.fromCharCode(65 + i)] = String(10 + i); }
+
+ // How many decimal digits can we process? (for 64-bit float, this is 15)
+ var safeDigits = Math.floor(log10(MAX_SAFE_INTEGER));
+
+ return function(address) {
+ address = address.toUpperCase();
+ address = address.substring(4) + address.substring(0, 2) + '00';
+
+ var expanded = address.split('');
+ for (var i = 0; i < expanded.length; i++) {
+ expanded[i] = ibanLookup[expanded[i]];
+ }
+ expanded = expanded.join('');
+
+ // Javascript can handle integers safely up to 15 (decimal) digits
+ while (expanded.length >= safeDigits){
+ var block = expanded.substring(0, safeDigits);
+ expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
+ }
+
+ var checksum = String(98 - (parseInt(expanded, 10) % 97));
+ while (checksum.length < 2) { checksum = '0' + checksum; }
+
+ return checksum;
+ };
+})();
+
+function getAddress(address, icapFormat) {
+ var result = null;
+
+ if (typeof(address) !== 'string') {
+ throwError('invalid address', {input: address});
+ }
+
+ if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
+
+ // Missing the 0x prefix
+ if (address.substring(0, 2) !== '0x') { address = '0x' + address; }
+
+ result = getChecksumAddress(address);
+
+ // It is a checksummed address with a bad checksum
+ if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
+ throwError('invalid address checksum', { input: address, expected: result });
+ }
+
+ // Maybe ICAP? (we only support direct mode)
+ } else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
+
+ // It is an ICAP address with a bad checksum
+ if (address.substring(2, 4) !== ibanChecksum(address)) {
+ throwError('invalid address icap checksum', { input: address });
+ }
+
+ result = (new BN(address.substring(4), 36)).toString(16);
+ while (result.length < 40) { result = '0' + result; }
+ result = getChecksumAddress('0x' + result);
+
+ } else {
+ throwError('invalid address', { input: address });
+ }
+
+ if (icapFormat) {
+ var base36 = (new BN(result.substring(2), 16)).toString(36).toUpperCase();
+ while (base36.length < 30) { base36 = '0' + base36; }
+ return 'XE' + ibanChecksum('XE00' + base36) + base36;
+ }
+
+ return result;
+}
+
+
+module.exports = {
+ getAddress: getAddress,
+}
+
+},{"./convert":18,"./keccak256":19,"./throw-error":23,"bn.js":1}],16:[function(require,module,exports){
+/**
+ * BigNumber
+ *
+ * A wrapper around the BN.js object. In the future we can swap out
+ * the underlying BN.js library for something smaller.
+ */
+
+var BN = require('bn.js');
+
+var defineProperty = require('./properties').defineProperty;
+var convert = require('./convert');
+var throwError = require('./throw-error');
+
+function BigNumber(value) {
+ if (!(this instanceof BigNumber)) { throw new Error('missing new'); }
+
+ if (convert.isHexString(value)) {
+ if (value == '0x') { value = '0x0'; }
+ value = new BN(value.substring(2), 16);
+ } else if (typeof(value) === 'string' && value[0] === '-' && convert.isHexString(value.substring(1))) {
+ value = (new BN(value.substring(3), 16)).mul(BigNumber.constantNegativeOne._bn);
+
+ } else if (typeof(value) === 'string' && value.match(/^-?[0-9]*$/)) {
+ if (value == '') { value = '0'; }
+ value = new BN(value);
+
+ } else if (typeof(value) === 'number' && parseInt(value) == value) {
+ value = new BN(value);
+
+ } else if (BN.isBN(value)) {
+ //value = value
+
+ } else if (isBigNumber(value)) {
+ value = value._bn;
+
+ } else if (convert.isArrayish(value)) {
+ value = new BN(convert.hexlify(value).substring(2), 16);
+
+ } else {
+ throwError('invalid BigNumber value', { input: value });
+ }
+
+ defineProperty(this, '_bn', value);
+}
+
+defineProperty(BigNumber, 'constantNegativeOne', bigNumberify(-1));
+defineProperty(BigNumber, 'constantZero', bigNumberify(0));
+defineProperty(BigNumber, 'constantOne', bigNumberify(1));
+defineProperty(BigNumber, 'constantTwo', bigNumberify(2));
+defineProperty(BigNumber, 'constantWeiPerEther', bigNumberify(new BN('1000000000000000000')));
+
+
+defineProperty(BigNumber.prototype, 'fromTwos', function(value) {
+ return new BigNumber(this._bn.fromTwos(value));
+});
+
+defineProperty(BigNumber.prototype, 'toTwos', function(value) {
+ return new BigNumber(this._bn.toTwos(value));
+});
+
+
+defineProperty(BigNumber.prototype, 'add', function(other) {
+ return new BigNumber(this._bn.add(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'sub', function(other) {
+ return new BigNumber(this._bn.sub(bigNumberify(other)._bn));
+});
+
+
+defineProperty(BigNumber.prototype, 'div', function(other) {
+ return new BigNumber(this._bn.div(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'mul', function(other) {
+ return new BigNumber(this._bn.mul(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'mod', function(other) {
+ return new BigNumber(this._bn.mod(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'pow', function(other) {
+ return new BigNumber(this._bn.pow(bigNumberify(other)._bn));
+});
+
+
+defineProperty(BigNumber.prototype, 'maskn', function(value) {
+ return new BigNumber(this._bn.maskn(value));
+});
+
+
+
+defineProperty(BigNumber.prototype, 'eq', function(other) {
+ return this._bn.eq(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'lt', function(other) {
+ return this._bn.lt(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'lte', function(other) {
+ return this._bn.lte(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'gt', function(other) {
+ return this._bn.gt(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'gte', function(other) {
+ return this._bn.gte(bigNumberify(other)._bn);
+});
+
+
+defineProperty(BigNumber.prototype, 'isZero', function() {
+ return this._bn.isZero();
+});
+
+
+defineProperty(BigNumber.prototype, 'toNumber', function(base) {
+ return this._bn.toNumber();
+});
+
+defineProperty(BigNumber.prototype, 'toString', function() {
+ //return this._bn.toString(base || 10);
+ return this._bn.toString(10);
+});
+
+defineProperty(BigNumber.prototype, 'toHexString', function() {
+ var hex = this._bn.toString(16);
+ if (hex.length % 2) { hex = '0' + hex; }
+ return '0x' + hex;
+});
+
+
+function isBigNumber(value) {
+ return (value._bn && value._bn.mod);
+}
+
+function bigNumberify(value) {
+ if (isBigNumber(value)) { return value; }
+ return new BigNumber(value);
+}
+
+module.exports = {
+ isBigNumber: isBigNumber,
+ bigNumberify: bigNumberify,
+ BigNumber: BigNumber
+};
+
+},{"./convert":18,"./properties":21,"./throw-error":23,"bn.js":1}],17:[function(require,module,exports){
+
+var getAddress = require('./address').getAddress;
+var convert = require('./convert');
+var keccak256 = require('./keccak256');
+var RLP = require('./rlp');
+
+// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
+function getContractAddress(transaction) {
+ if (!transaction.from) { throw new Error('missing from address'); }
+ var nonce = transaction.nonce;
+
+ return getAddress('0x' + keccak256(RLP.encode([
+ getAddress(transaction.from),
+ convert.stripZeros(convert.hexlify(nonce, 'nonce'))
+ ])).substring(26));
+}
+
+module.exports = {
+ getContractAddress: getContractAddress,
+}
+
+},{"./address":15,"./convert":18,"./keccak256":19,"./rlp":22}],18:[function(require,module,exports){
+/**
+ * Conversion Utilities
+ *
+ */
+
+var defineProperty = require('./properties.js').defineProperty;
+var throwError = require('./throw-error');
+
+function addSlice(array) {
+ if (array.slice) { return array; }
+
+ array.slice = function() {
+ var args = Array.prototype.slice.call(arguments);
+ return new Uint8Array(Array.prototype.slice.apply(array, args));
+ }
+
+ return array;
+}
+
+function isArrayish(value) {
+ if (!value || parseInt(value.length) != value.length || typeof(value) === 'string') {
+ return false;
+ }
+
+ for (var i = 0; i < value.length; i++) {
+ var v = value[i];
+ if (v < 0 || v >= 256 || parseInt(v) != v) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function arrayify(value, name) {
+
+ if (value && value.toHexString) {
+ value = value.toHexString();
+ }
+
+ if (isHexString(value)) {
+ value = value.substring(2);
+ if (value.length % 2) { value = '0' + value; }
+
+ var result = [];
+ for (var i = 0; i < value.length; i += 2) {
+ result.push(parseInt(value.substr(i, 2), 16));
+ }
+
+ return addSlice(new Uint8Array(result));
+ }
+
+ if (isArrayish(value)) {
+ return addSlice(new Uint8Array(value));
+ }
+
+ throwError('invalid arrayify value', { name: name, input: value });
+}
+
+function concat(objects) {
+ var arrays = [];
+ var length = 0;
+ for (var i = 0; i < objects.length; i++) {
+ var object = arrayify(objects[i])
+ arrays.push(object);
+ length += object.length;
+ }
+
+ var result = new Uint8Array(length);
+ var offset = 0;
+ for (var i = 0; i < arrays.length; i++) {
+ result.set(arrays[i], offset);
+ offset += arrays[i].length;
+ }
+
+ return addSlice(result);
+}
+function stripZeros(value) {
+ value = arrayify(value);
+
+ if (value.length === 0) { return value; }
+
+ // Find the first non-zero entry
+ var start = 0;
+ while (value[start] === 0) { start++ }
+
+ // If we started with zeros, strip them
+ if (start) {
+ value = value.slice(start);
+ }
+
+ return value;
+}
+
+function padZeros(value, length) {
+ value = arrayify(value);
+
+ if (length < value.length) { throw new Error('cannot pad'); }
+
+ var result = new Uint8Array(length);
+ result.set(value, length - value.length);
+ return addSlice(result);
+}
+
+
+function isHexString(value, length) {
+ if (typeof(value) !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
+ return false
+ }
+ if (length && value.length !== 2 + 2 * length) { return false; }
+ return true;
+}
+
+var HexCharacters = '0123456789abcdef';
+
+function hexlify(value, name) {
+
+ if (value && value.toHexString) {
+ return value.toHexString();
+ }
+
+ if (typeof(value) === 'number') {
+ if (value < 0) {
+ throwError('cannot hexlify negative value', { name: name, input: value });
+ }
+
+ var hex = '';
+ while (value) {
+ hex = HexCharacters[value & 0x0f] + hex;
+ value = parseInt(value / 16);
+ }
+
+ if (hex.length) {
+ if (hex.length % 2) { hex = '0' + hex; }
+ return '0x' + hex;
+ }
+
+ return '0x00';
+ }
+
+ if (isHexString(value)) {
+ if (value.length % 2) {
+ value = '0x0' + value.substring(2);
+ }
+ return value;
+ }
+
+ if (isArrayish(value)) {
+ var result = [];
+ for (var i = 0; i < value.length; i++) {
+ var v = value[i];
+ result.push(HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f]);
+ }
+ return '0x' + result.join('');
+ }
+
+ throwError('invalid hexlify value', { name: name, input: value });
+}
+
+function hexStripZeros(value) {
+ while (value.length > 3 && value.substring(0, 3) === '0x0') {
+ value = '0x' + value.substring(3);
+ }
+ return value;
+}
+
+function hexZeroPad(value, length) {
+ while (value.length < 2 * length + 2) {
+ value = '0x0' + value.substring(2);
+ }
+ return value;
+}
+
+module.exports = {
+ arrayify: arrayify,
+ isArrayish: isArrayish,
+
+ concat: concat,
+
+ padZeros: padZeros,
+ stripZeros: stripZeros,
+
+ hexlify: hexlify,
+ isHexString: isHexString,
+ hexStripZeros: hexStripZeros,
+ hexZeroPad: hexZeroPad,
+};
+
+},{"./properties.js":21,"./throw-error":23}],19:[function(require,module,exports){
+'use strict';
+
+var sha3 = require('js-sha3');
+
+var convert = require('./convert.js');
+
+function keccak256(data) {
+ data = convert.arrayify(data);
+ return '0x' + sha3.keccak_256(data);
+}
+
+module.exports = keccak256;
+
+},{"./convert.js":18,"js-sha3":4}],20:[function(require,module,exports){
+'use strict';
+
+var convert = require('./convert');
+var utf8 = require('./utf8');
+var keccak256 = require('./keccak256');
+
+var Zeros = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+var Partition = new RegExp("^((.*)\\.)?([^.]+)$");
+var UseSTD3ASCIIRules = new RegExp("^[a-z0-9.-]*$");
+
+function namehash(name, depth) {
+ name = name.toLowerCase();
+
+ // Supporting the full UTF-8 space requires additional (and large)
+ // libraries, so for now we simply do not support them.
+ // It should be fairly easy in the future to support systems with
+ // String.normalize, but that is future work.
+ if (!name.match(UseSTD3ASCIIRules)) {
+ throw new Error('contains invalid UseSTD3ASCIIRules characters');
+ }
+
+ var result = Zeros;
+ var processed = 0;
+ while (name.length && (!depth || processed < depth)) {
+ var partition = name.match(Partition);
+ var label = utf8.toUtf8Bytes(partition[3]);
+ result = keccak256(convert.concat([result, keccak256(label)]));
+
+ name = partition[2] || '';
+
+ processed++;
+ }
+
+ return convert.hexlify(result);
+}
+
+module.exports = namehash;
+
+
+},{"./convert":18,"./keccak256":19,"./utf8":24}],21:[function(require,module,exports){
+'use strict';
+
+function defineProperty(object, name, value) {
+ Object.defineProperty(object, name, {
+ enumerable: true,
+ value: value,
+ writable: false,
+ });
+}
+
+function defineFrozen(object, name, value) {
+ var frozen = JSON.stringify(value);
+ Object.defineProperty(object, name, {
+ enumerable: true,
+ get: function() { return JSON.parse(frozen); }
+ });
+}
+
+module.exports = {
+ defineFrozen: defineFrozen,
+ defineProperty: defineProperty,
+};
+
+},{}],22:[function(require,module,exports){
+//See: https://github.com/ethereum/wiki/wiki/RLP
+
+var convert = require('./convert.js');
+
+function arrayifyInteger(value) {
+ var result = [];
+ while (value) {
+ result.unshift(value & 0xff);
+ value >>= 8;
+ }
+ return result;
+}
+
+function unarrayifyInteger(data, offset, length) {
+ var result = 0;
+ for (var i = 0; i < length; i++) {
+ result = (result * 256) + data[offset + i];
+ }
+ return result;
+}
+
+function _encode(object) {
+ if (Array.isArray(object)) {
+ var payload = [];
+ object.forEach(function(child) {
+ payload = payload.concat(_encode(child));
+ });
+
+ if (payload.length <= 55) {
+ payload.unshift(0xc0 + payload.length)
+ return payload;
+ }
+
+ var length = arrayifyInteger(payload.length);
+ length.unshift(0xf7 + length.length);
+
+ return length.concat(payload);
+
+ } else {
+ object = [].slice.call(convert.arrayify(object));
+
+ if (object.length === 1 && object[0] <= 0x7f) {
+ return object;
+
+ } else if (object.length <= 55) {
+ object.unshift(0x80 + object.length);
+ return object
+ }
+
+ var length = arrayifyInteger(object.length);
+ length.unshift(0xb7 + length.length);
+
+ return length.concat(object);
+ }
+}
+
+function encode(object) {
+ return convert.hexlify(_encode(object));
+}
+
+function _decodeChildren(data, offset, childOffset, length) {
+ var result = [];
+
+ while (childOffset < offset + 1 + length) {
+ var decoded = _decode(data, childOffset);
+
+ result.push(decoded.result);
+
+ childOffset += decoded.consumed;
+ if (childOffset > offset + 1 + length) {
+ throw new Error('invalid rlp');
+ }
+ }
+
+ return {consumed: (1 + length), result: result};
+}
+
+// returns { consumed: number, result: Object }
+function _decode(data, offset) {
+ if (data.length === 0) { throw new Error('invalid rlp data'); }
+
+ // Array with extra length prefix
+ if (data[offset] >= 0xf8) {
+ var lengthLength = data[offset] - 0xf7;
+ if (offset + 1 + lengthLength > data.length) {
+ throw new Error('too short');
+ }
+
+ var length = unarrayifyInteger(data, offset + 1, lengthLength);
+ if (offset + 1 + lengthLength + length > data.length) {
+ throw new Error('to short');
+ }
+
+ return _decodeChildren(data, offset, offset + 1 + lengthLength, lengthLength + length);
+
+ } else if (data[offset] >= 0xc0) {
+ var length = data[offset] - 0xc0;
+ if (offset + 1 + length > data.length) {
+ throw new Error('invalid rlp data');
+ }
+
+ return _decodeChildren(data, offset, offset + 1, length);
+
+ } else if (data[offset] >= 0xb8) {
+ var lengthLength = data[offset] - 0xb7;
+ if (offset + 1 + lengthLength > data.length) {
+ throw new Error('invalid rlp data');
+ }
+
+ var length = unarrayifyInteger(data, offset + 1, lengthLength);
+ if (offset + 1 + lengthLength + length > data.length) {
+ throw new Error('invalid rlp data');
+ }
+
+ var result = convert.hexlify(data.slice(offset + 1 + lengthLength, offset + 1 + lengthLength + length));
+ return { consumed: (1 + lengthLength + length), result: result }
+
+ } else if (data[offset] >= 0x80) {
+ var length = data[offset] - 0x80;
+ if (offset + 1 + length > data.offset) {
+ throw new Error('invlaid rlp data');
+ }
+
+ var result = convert.hexlify(data.slice(offset + 1, offset + 1 + length));
+ return { consumed: (1 + length), result: result }
+ }
+ return { consumed: 1, result: convert.hexlify(data[offset]) };
+}
+
+function decode(data) {
+ data = convert.arrayify(data);
+ var decoded = _decode(data, 0);
+ if (decoded.consumed !== data.length) {
+ throw new Error('invalid rlp data');
+ }
+ return decoded.result;
+}
+
+module.exports = {
+ encode: encode,
+ decode: decode,
+}
+
+},{"./convert.js":18}],23:[function(require,module,exports){
+'use strict';
+
+function throwError(message, params) {
+ var error = new Error(message);
+ for (var key in params) {
+ error[key] = params[key];
+ }
+ throw error;
+}
+
+module.exports = throwError;
+
+},{}],24:[function(require,module,exports){
+
+var convert = require('./convert.js');
+
+// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
+function utf8ToBytes(str) {
+ var result = [];
+ var offset = 0;
+ for (var i = 0; i < str.length; i++) {
+ var c = str.charCodeAt(i);
+ if (c < 128) {
+ result[offset++] = c;
+ } else if (c < 2048) {
+ result[offset++] = (c >> 6) | 192;
+ result[offset++] = (c & 63) | 128;
+ } else if (((c & 0xFC00) == 0xD800) && (i + 1) < str.length && ((str.charCodeAt(i + 1) & 0xFC00) == 0xDC00)) {
+ // Surrogate Pair
+ c = 0x10000 + ((c & 0x03FF) << 10) + (str.charCodeAt(++i) & 0x03FF);
+ result[offset++] = (c >> 18) | 240;
+ result[offset++] = ((c >> 12) & 63) | 128;
+ result[offset++] = ((c >> 6) & 63) | 128;
+ result[offset++] = (c & 63) | 128;
+ } else {
+ result[offset++] = (c >> 12) | 224;
+ result[offset++] = ((c >> 6) & 63) | 128;
+ result[offset++] = (c & 63) | 128;
+ }
+ }
+
+ return convert.arrayify(result);
+};
+
+
+// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
+function bytesToUtf8(bytes) {
+ bytes = convert.arrayify(bytes);
+
+ var result = '';
+ var i = 0;
+
+ // Invalid bytes are ignored
+ while(i < bytes.length) {
+ var c = bytes[i++];
+ if (c >> 7 == 0) {
+ // 0xxx xxxx
+ result += String.fromCharCode(c);
+ continue;
+ }
+
+ // Invalid starting byte
+ if (c >> 6 == 0x02) { continue; }
+
+ // Multibyte; how many bytes left for thus character?
+ var extraLength = null;
+ if (c >> 5 == 0x06) {
+ extraLength = 1;
+ } else if (c >> 4 == 0x0e) {
+ extraLength = 2;
+ } else if (c >> 3 == 0x1e) {
+ extraLength = 3;
+ } else if (c >> 2 == 0x3e) {
+ extraLength = 4;
+ } else if (c >> 1 == 0x7e) {
+ extraLength = 5;
+ } else {
+ continue;
+ }
+
+ // Do we have enough bytes in our data?
+ if (i + extraLength > bytes.length) {
+
+ // If there is an invalid unprocessed byte, try to continue
+ for (; i < bytes.length; i++) {
+ if (bytes[i] >> 6 != 0x02) { break; }
+ }
+ if (i != bytes.length) continue;
+
+ // All leftover bytes are valid.
+ return result;
+ }
+
+ // Remove the UTF-8 prefix from the char (res)
+ var res = c & ((1 << (8 - extraLength - 1)) - 1);
+
+ var count;
+ for (count = 0; count < extraLength; count++) {
+ var nextChar = bytes[i++];
+
+ // Is the char valid multibyte part?
+ if (nextChar >> 6 != 0x02) {break;};
+ res = (res << 6) | (nextChar & 0x3f);
+ }
+
+ if (count != extraLength) {
+ i--;
+ continue;
+ }
+
+ if (res <= 0xffff) {
+ result += String.fromCharCode(res);
+ continue;
+ }
+
+ res -= 0x10000;
+ result += String.fromCharCode(((res >> 10) & 0x3ff) + 0xd800, (res & 0x3ff) + 0xdc00);
+ }
+
+ return result;
+}
+
+module.exports = {
+ toUtf8Bytes: utf8ToBytes,
+ toUtf8String: bytesToUtf8,
+};
+
+},{"./convert.js":18}]},{},[9])(9)
+});
\ No newline at end of file
diff --git a/dist/ethers-providers.min.js b/dist/ethers-providers.min.js
new file mode 100644
index 0000000000..7fc9188530
--- /dev/null
+++ b/dist/ethers-providers.min.js
@@ -0,0 +1,3 @@
+!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.ethers=a()}}(function(){return function(){function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g=49&&g<=54?g-49+10:g>=17&&g<=22?g-17+10:15&g}return d}function h(a,b,c,d){for(var e=0,f=Math.min(a.length,c),g=b;g=49?h-49+10:h>=17?h-17+10:h}return e}function i(a){for(var b=new Array(a.bitLength()),c=0;c>>e}return b}function j(a,b,c){c.negative=b.negative^a.negative;var d=a.length+b.length|0;c.length=d,d=d-1|0;var e=0|a.words[0],f=0|b.words[0],g=e*f,h=67108863&g,i=g/67108864|0;c.words[0]=h;for(var j=1;j>>26,l=67108863&i,m=Math.min(j,b.length-1),n=Math.max(0,j-a.length+1);n<=m;n++){var o=j-n|0;e=0|a.words[o],f=0|b.words[n],g=e*f+l,k+=g/67108864|0,l=67108863&g}c.words[j]=0|l,i=0|k}return 0!==i?c.words[j]=0|i:c.length--,c.strip()}function k(a,b,c){c.negative=b.negative^a.negative,c.length=a.length+b.length;for(var d=0,e=0,f=0;f>>26)|0,e+=g>>>26,g&=67108863}c.words[f]=h,d=g,g=e}return 0!==d?c.words[f]=d:c.length--,c.strip()}function l(a,b,c){var d=new m;return d.mulp(a,b,c)}function m(a,b){this.x=a,this.y=b}function n(a,b){this.name=a,this.p=new f(b,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function o(){n.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function p(){n.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function q(){n.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function r(){n.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function s(a){if("string"==typeof a){var b=f._prime(a);this.m=b.p,this.prime=b}else d(a.gtn(1),"modulus must be greater than 1"),this.m=a,this.prime=null}function t(a){s.call(this,a),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(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"==typeof b?b.exports=f:c.BN=f,f.BN=f,f.wordSize=26;var u;try{u=a("buffer").Buffer}catch(v){}f.isBN=function(a){return a instanceof f||null!==a&&"object"==typeof a&&a.constructor.wordSize===f.wordSize&&Array.isArray(a.words)},f.max=function(a,b){return a.cmp(b)>0?a:b},f.min=function(a,b){return a.cmp(b)<0?a:b},f.prototype._init=function(a,b,c){if("number"==typeof a)return this._initNumber(a,b,c);if("object"==typeof a)return this._initArray(a,b,c);"hex"===b&&(b=16),d(b===(0|b)&&b>=2&&b<=36),a=a.toString().replace(/\s+/g,"");var e=0;"-"===a[0]&&e++,16===b?this._parseHex(a,e):this._parseBase(a,b,e),"-"===a[0]&&(this.negative=1),this.strip(),"le"===c&&this._initArray(this.toArray(),b,c)},f.prototype._initNumber=function(a,b,c){a<0&&(this.negative=1,a=-a),a<67108864?(this.words=[67108863&a],this.length=1):a<4503599627370496?(this.words=[67108863&a,a/67108864&67108863],this.length=2):(d(a<9007199254740992),this.words=[67108863&a,a/67108864&67108863,1],this.length=3),"le"===c&&this._initArray(this.toArray(),b,c)},f.prototype._initArray=function(a,b,c){if(d("number"==typeof a.length),a.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(a.length/3),this.words=new Array(this.length);for(var e=0;e=0;e-=3)g=a[e]|a[e-1]<<8|a[e-2]<<16,this.words[f]|=g<>>26-h&67108863,h+=24,h>=26&&(h-=26,f++);else if("le"===c)for(e=0,f=0;e>>26-h&67108863,h+=24,h>=26&&(h-=26,f++);return this.strip()},f.prototype._parseHex=function(a,b){this.length=Math.ceil((a.length-b)/6),this.words=new Array(this.length);for(var c=0;c=b;c-=6)e=g(a,c,c+6),this.words[d]|=e<>>26-f&4194303,f+=24,f>=26&&(f-=26,d++);c+6!==b&&(e=g(a,b,c+6),this.words[d]|=e<>>26-f&4194303),this.strip()},f.prototype._parseBase=function(a,b,c){this.words=[0],this.length=1;for(var d=0,e=1;e<=67108863;e*=b)d++;d--,e=e/b|0;for(var f=a.length-c,g=f%d,i=Math.min(f,f-g)+c,j=0,k=c;k1&&0===this.words[this.length-1];)this.length--;return this._normSign()},f.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},f.prototype.inspect=function(){return(this.red?""};var w=["","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"],x=[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],y=[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];f.prototype.toString=function(a,b){a=a||10,b=0|b||1;var c;if(16===a||"hex"===a){c="";for(var e=0,f=0,g=0;g>>24-e&16777215,c=0!==f||g!==this.length-1?w[6-i.length]+i+c:i+c,e+=2,e>=26&&(e-=26,g--)}for(0!==f&&(c=f.toString(16)+c);c.length%b!==0;)c="0"+c;return 0!==this.negative&&(c="-"+c),c}if(a===(0|a)&&a>=2&&a<=36){var j=x[a],k=y[a];c="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modn(k).toString(a);l=l.idivn(k),c=l.isZero()?m+c:w[j-m.length]+m+c}for(this.isZero()&&(c="0"+c);c.length%b!==0;)c="0"+c;return 0!==this.negative&&(c="-"+c),c}d(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var a=this.words[0];return 2===this.length?a+=67108864*this.words[1]:3===this.length&&1===this.words[2]?a+=4503599627370496+67108864*this.words[1]:this.length>2&&d(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-a:a},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(a,b){return d("undefined"!=typeof u),this.toArrayLike(u,a,b)},f.prototype.toArray=function(a,b){return this.toArrayLike(Array,a,b)},f.prototype.toArrayLike=function(a,b,c){var e=this.byteLength(),f=c||Math.max(1,e);d(e<=f,"byte array longer than desired length"),d(f>0,"Requested array length <= 0"),this.strip();var g,h,i="le"===b,j=new a(f),k=this.clone();if(i){for(h=0;!k.isZero();h++)g=k.andln(255),k.iushrn(8),j[h]=g;for(;h=4096&&(c+=13,b>>>=13),b>=64&&(c+=7,b>>>=7),b>=8&&(c+=4,b>>>=4),b>=2&&(c+=2,b>>>=2),c+b},f.prototype._zeroBits=function(a){if(0===a)return 26;var b=a,c=0;return 0===(8191&b)&&(c+=13,b>>>=13),0===(127&b)&&(c+=7,b>>>=7),0===(15&b)&&(c+=4,b>>>=4),0===(3&b)&&(c+=2,b>>>=2),0===(1&b)&&c++,c},f.prototype.bitLength=function(){var a=this.words[this.length-1],b=this._countBits(a);return 26*(this.length-1)+b},f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var a=0,b=0;ba.length?this.clone().ior(a):a.clone().ior(this)},f.prototype.uor=function(a){return this.length>a.length?this.clone().iuor(a):a.clone().iuor(this)},f.prototype.iuand=function(a){var b;b=this.length>a.length?a:this;for(var c=0;ca.length?this.clone().iand(a):a.clone().iand(this)},f.prototype.uand=function(a){return this.length>a.length?this.clone().iuand(a):a.clone().iuand(this)},f.prototype.iuxor=function(a){var b,c;this.length>a.length?(b=this,c=a):(b=a,c=this);for(var d=0;da.length?this.clone().ixor(a):a.clone().ixor(this)},f.prototype.uxor=function(a){return this.length>a.length?this.clone().iuxor(a):a.clone().iuxor(this)},f.prototype.inotn=function(a){d("number"==typeof a&&a>=0);var b=0|Math.ceil(a/26),c=a%26;this._expand(b),c>0&&b--;for(var e=0;e0&&(this.words[e]=~this.words[e]&67108863>>26-c),this.strip()},f.prototype.notn=function(a){return this.clone().inotn(a)},f.prototype.setn=function(a,b){d("number"==typeof a&&a>=0);var c=a/26|0,e=a%26;return this._expand(c+1),b?this.words[c]=this.words[c]|1<a.length?(c=this,d=a):(c=a,d=this);for(var e=0,f=0;f>>26;for(;0!==e&&f>>26;if(this.length=c.length,0!==e)this.words[this.length]=e,this.length++;else if(c!==this)for(;fa.length?this.clone().iadd(a):a.clone().iadd(this)},f.prototype.isub=function(a){if(0!==a.negative){a.negative=0;var b=this.iadd(a);return a.negative=1,b._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(a),this.negative=1,this._normSign();var c=this.cmp(a);if(0===c)return this.negative=0,this.length=1,this.words[0]=0,this;var d,e;c>0?(d=this,e=a):(d=a,e=this);for(var f=0,g=0;g>26,this.words[g]=67108863&b;for(;0!==f&&g>26,this.words[g]=67108863&b;if(0===f&&g>>13,n=0|g[1],o=8191&n,p=n>>>13,q=0|g[2],r=8191&q,s=q>>>13,t=0|g[3],u=8191&t,v=t>>>13,w=0|g[4],x=8191&w,y=w>>>13,z=0|g[5],A=8191&z,B=z>>>13,C=0|g[6],D=8191&C,E=C>>>13,F=0|g[7],G=8191&F,H=F>>>13,I=0|g[8],J=8191&I,K=I>>>13,L=0|g[9],M=8191&L,N=L>>>13,O=0|h[0],P=8191&O,Q=O>>>13,R=0|h[1],S=8191&R,T=R>>>13,U=0|h[2],V=8191&U,W=U>>>13,X=0|h[3],Y=8191&X,Z=X>>>13,$=0|h[4],_=8191&$,aa=$>>>13,ba=0|h[5],ca=8191&ba,da=ba>>>13,ea=0|h[6],fa=8191&ea,ga=ea>>>13,ha=0|h[7],ia=8191&ha,ja=ha>>>13,ka=0|h[8],la=8191&ka,ma=ka>>>13,na=0|h[9],oa=8191&na,pa=na>>>13;c.negative=a.negative^b.negative,c.length=19,d=Math.imul(l,P),e=Math.imul(l,Q),e=e+Math.imul(m,P)|0,f=Math.imul(m,Q);var qa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(qa>>>26)|0,qa&=67108863,d=Math.imul(o,P),e=Math.imul(o,Q),e=e+Math.imul(p,P)|0,f=Math.imul(p,Q),d=d+Math.imul(l,S)|0,e=e+Math.imul(l,T)|0,e=e+Math.imul(m,S)|0,f=f+Math.imul(m,T)|0;var ra=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ra>>>26)|0,ra&=67108863,d=Math.imul(r,P),e=Math.imul(r,Q),e=e+Math.imul(s,P)|0,f=Math.imul(s,Q),d=d+Math.imul(o,S)|0,e=e+Math.imul(o,T)|0,e=e+Math.imul(p,S)|0,f=f+Math.imul(p,T)|0,d=d+Math.imul(l,V)|0,e=e+Math.imul(l,W)|0,e=e+Math.imul(m,V)|0,f=f+Math.imul(m,W)|0;var sa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(sa>>>26)|0,sa&=67108863,d=Math.imul(u,P),e=Math.imul(u,Q),e=e+Math.imul(v,P)|0,f=Math.imul(v,Q),d=d+Math.imul(r,S)|0,e=e+Math.imul(r,T)|0,e=e+Math.imul(s,S)|0,f=f+Math.imul(s,T)|0,d=d+Math.imul(o,V)|0,e=e+Math.imul(o,W)|0,e=e+Math.imul(p,V)|0,f=f+Math.imul(p,W)|0,d=d+Math.imul(l,Y)|0,e=e+Math.imul(l,Z)|0,e=e+Math.imul(m,Y)|0,f=f+Math.imul(m,Z)|0;var ta=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ta>>>26)|0,ta&=67108863,d=Math.imul(x,P),e=Math.imul(x,Q),e=e+Math.imul(y,P)|0,f=Math.imul(y,Q),d=d+Math.imul(u,S)|0,e=e+Math.imul(u,T)|0,e=e+Math.imul(v,S)|0,f=f+Math.imul(v,T)|0,d=d+Math.imul(r,V)|0,e=e+Math.imul(r,W)|0,e=e+Math.imul(s,V)|0,f=f+Math.imul(s,W)|0,d=d+Math.imul(o,Y)|0,e=e+Math.imul(o,Z)|0,e=e+Math.imul(p,Y)|0,f=f+Math.imul(p,Z)|0,d=d+Math.imul(l,_)|0,e=e+Math.imul(l,aa)|0,e=e+Math.imul(m,_)|0,f=f+Math.imul(m,aa)|0;var ua=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ua>>>26)|0,ua&=67108863,d=Math.imul(A,P),e=Math.imul(A,Q),e=e+Math.imul(B,P)|0,f=Math.imul(B,Q),d=d+Math.imul(x,S)|0,e=e+Math.imul(x,T)|0,e=e+Math.imul(y,S)|0,f=f+Math.imul(y,T)|0,d=d+Math.imul(u,V)|0,e=e+Math.imul(u,W)|0,e=e+Math.imul(v,V)|0,f=f+Math.imul(v,W)|0,d=d+Math.imul(r,Y)|0,e=e+Math.imul(r,Z)|0,e=e+Math.imul(s,Y)|0,f=f+Math.imul(s,Z)|0,d=d+Math.imul(o,_)|0,e=e+Math.imul(o,aa)|0,e=e+Math.imul(p,_)|0,f=f+Math.imul(p,aa)|0,d=d+Math.imul(l,ca)|0,e=e+Math.imul(l,da)|0,e=e+Math.imul(m,ca)|0,f=f+Math.imul(m,da)|0;var va=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(va>>>26)|0,va&=67108863,d=Math.imul(D,P),e=Math.imul(D,Q),e=e+Math.imul(E,P)|0,f=Math.imul(E,Q),d=d+Math.imul(A,S)|0,e=e+Math.imul(A,T)|0,e=e+Math.imul(B,S)|0,f=f+Math.imul(B,T)|0,d=d+Math.imul(x,V)|0,e=e+Math.imul(x,W)|0,e=e+Math.imul(y,V)|0,f=f+Math.imul(y,W)|0,d=d+Math.imul(u,Y)|0,e=e+Math.imul(u,Z)|0,e=e+Math.imul(v,Y)|0,f=f+Math.imul(v,Z)|0,d=d+Math.imul(r,_)|0,e=e+Math.imul(r,aa)|0,e=e+Math.imul(s,_)|0,f=f+Math.imul(s,aa)|0,d=d+Math.imul(o,ca)|0,e=e+Math.imul(o,da)|0,e=e+Math.imul(p,ca)|0,f=f+Math.imul(p,da)|0,d=d+Math.imul(l,fa)|0,e=e+Math.imul(l,ga)|0,e=e+Math.imul(m,fa)|0,f=f+Math.imul(m,ga)|0;var wa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(wa>>>26)|0,wa&=67108863,d=Math.imul(G,P),e=Math.imul(G,Q),e=e+Math.imul(H,P)|0,f=Math.imul(H,Q),d=d+Math.imul(D,S)|0,e=e+Math.imul(D,T)|0,e=e+Math.imul(E,S)|0,f=f+Math.imul(E,T)|0,d=d+Math.imul(A,V)|0,e=e+Math.imul(A,W)|0,e=e+Math.imul(B,V)|0,f=f+Math.imul(B,W)|0,d=d+Math.imul(x,Y)|0,e=e+Math.imul(x,Z)|0,e=e+Math.imul(y,Y)|0,f=f+Math.imul(y,Z)|0,d=d+Math.imul(u,_)|0,e=e+Math.imul(u,aa)|0,e=e+Math.imul(v,_)|0,f=f+Math.imul(v,aa)|0,d=d+Math.imul(r,ca)|0,e=e+Math.imul(r,da)|0,e=e+Math.imul(s,ca)|0,f=f+Math.imul(s,da)|0,d=d+Math.imul(o,fa)|0,e=e+Math.imul(o,ga)|0,e=e+Math.imul(p,fa)|0,f=f+Math.imul(p,ga)|0,d=d+Math.imul(l,ia)|0,e=e+Math.imul(l,ja)|0,e=e+Math.imul(m,ia)|0,f=f+Math.imul(m,ja)|0;var xa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(xa>>>26)|0,xa&=67108863,d=Math.imul(J,P),e=Math.imul(J,Q),e=e+Math.imul(K,P)|0,f=Math.imul(K,Q),d=d+Math.imul(G,S)|0,e=e+Math.imul(G,T)|0,e=e+Math.imul(H,S)|0,f=f+Math.imul(H,T)|0,d=d+Math.imul(D,V)|0,e=e+Math.imul(D,W)|0,e=e+Math.imul(E,V)|0,f=f+Math.imul(E,W)|0,d=d+Math.imul(A,Y)|0,e=e+Math.imul(A,Z)|0,e=e+Math.imul(B,Y)|0,f=f+Math.imul(B,Z)|0,d=d+Math.imul(x,_)|0,e=e+Math.imul(x,aa)|0,e=e+Math.imul(y,_)|0,f=f+Math.imul(y,aa)|0,d=d+Math.imul(u,ca)|0,e=e+Math.imul(u,da)|0,e=e+Math.imul(v,ca)|0,f=f+Math.imul(v,da)|0,d=d+Math.imul(r,fa)|0,e=e+Math.imul(r,ga)|0,e=e+Math.imul(s,fa)|0,f=f+Math.imul(s,ga)|0,d=d+Math.imul(o,ia)|0,e=e+Math.imul(o,ja)|0,e=e+Math.imul(p,ia)|0,f=f+Math.imul(p,ja)|0,d=d+Math.imul(l,la)|0,e=e+Math.imul(l,ma)|0,e=e+Math.imul(m,la)|0,f=f+Math.imul(m,ma)|0;var ya=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ya>>>26)|0,ya&=67108863,d=Math.imul(M,P),e=Math.imul(M,Q),e=e+Math.imul(N,P)|0,f=Math.imul(N,Q),d=d+Math.imul(J,S)|0,e=e+Math.imul(J,T)|0,e=e+Math.imul(K,S)|0,f=f+Math.imul(K,T)|0,d=d+Math.imul(G,V)|0,e=e+Math.imul(G,W)|0,e=e+Math.imul(H,V)|0,f=f+Math.imul(H,W)|0,d=d+Math.imul(D,Y)|0,e=e+Math.imul(D,Z)|0,e=e+Math.imul(E,Y)|0,f=f+Math.imul(E,Z)|0,d=d+Math.imul(A,_)|0,e=e+Math.imul(A,aa)|0,e=e+Math.imul(B,_)|0,f=f+Math.imul(B,aa)|0,d=d+Math.imul(x,ca)|0,e=e+Math.imul(x,da)|0,e=e+Math.imul(y,ca)|0,f=f+Math.imul(y,da)|0,d=d+Math.imul(u,fa)|0,e=e+Math.imul(u,ga)|0,e=e+Math.imul(v,fa)|0,f=f+Math.imul(v,ga)|0,d=d+Math.imul(r,ia)|0,e=e+Math.imul(r,ja)|0,e=e+Math.imul(s,ia)|0,f=f+Math.imul(s,ja)|0,d=d+Math.imul(o,la)|0,e=e+Math.imul(o,ma)|0,e=e+Math.imul(p,la)|0,f=f+Math.imul(p,ma)|0,d=d+Math.imul(l,oa)|0,e=e+Math.imul(l,pa)|0,e=e+Math.imul(m,oa)|0,f=f+Math.imul(m,pa)|0;var za=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(za>>>26)|0,za&=67108863,d=Math.imul(M,S),e=Math.imul(M,T),e=e+Math.imul(N,S)|0,f=Math.imul(N,T),d=d+Math.imul(J,V)|0,e=e+Math.imul(J,W)|0,e=e+Math.imul(K,V)|0,f=f+Math.imul(K,W)|0,d=d+Math.imul(G,Y)|0,e=e+Math.imul(G,Z)|0,e=e+Math.imul(H,Y)|0,f=f+Math.imul(H,Z)|0,d=d+Math.imul(D,_)|0,e=e+Math.imul(D,aa)|0,e=e+Math.imul(E,_)|0,f=f+Math.imul(E,aa)|0,d=d+Math.imul(A,ca)|0,e=e+Math.imul(A,da)|0,e=e+Math.imul(B,ca)|0,f=f+Math.imul(B,da)|0,d=d+Math.imul(x,fa)|0,e=e+Math.imul(x,ga)|0,e=e+Math.imul(y,fa)|0,f=f+Math.imul(y,ga)|0,d=d+Math.imul(u,ia)|0,e=e+Math.imul(u,ja)|0,e=e+Math.imul(v,ia)|0,f=f+Math.imul(v,ja)|0,d=d+Math.imul(r,la)|0,e=e+Math.imul(r,ma)|0,e=e+Math.imul(s,la)|0,f=f+Math.imul(s,ma)|0,d=d+Math.imul(o,oa)|0,e=e+Math.imul(o,pa)|0,e=e+Math.imul(p,oa)|0,f=f+Math.imul(p,pa)|0;var Aa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Aa>>>26)|0,Aa&=67108863,d=Math.imul(M,V),e=Math.imul(M,W),e=e+Math.imul(N,V)|0,f=Math.imul(N,W),d=d+Math.imul(J,Y)|0,e=e+Math.imul(J,Z)|0,e=e+Math.imul(K,Y)|0,f=f+Math.imul(K,Z)|0,d=d+Math.imul(G,_)|0,e=e+Math.imul(G,aa)|0,e=e+Math.imul(H,_)|0,f=f+Math.imul(H,aa)|0,d=d+Math.imul(D,ca)|0,e=e+Math.imul(D,da)|0,e=e+Math.imul(E,ca)|0,f=f+Math.imul(E,da)|0,d=d+Math.imul(A,fa)|0,e=e+Math.imul(A,ga)|0,e=e+Math.imul(B,fa)|0,f=f+Math.imul(B,ga)|0,d=d+Math.imul(x,ia)|0,e=e+Math.imul(x,ja)|0,e=e+Math.imul(y,ia)|0,f=f+Math.imul(y,ja)|0,d=d+Math.imul(u,la)|0,e=e+Math.imul(u,ma)|0,e=e+Math.imul(v,la)|0,f=f+Math.imul(v,ma)|0,d=d+Math.imul(r,oa)|0,e=e+Math.imul(r,pa)|0,e=e+Math.imul(s,oa)|0,f=f+Math.imul(s,pa)|0;var Ba=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ba>>>26)|0,Ba&=67108863,d=Math.imul(M,Y),e=Math.imul(M,Z),e=e+Math.imul(N,Y)|0,f=Math.imul(N,Z),d=d+Math.imul(J,_)|0,e=e+Math.imul(J,aa)|0,e=e+Math.imul(K,_)|0,f=f+Math.imul(K,aa)|0,d=d+Math.imul(G,ca)|0,e=e+Math.imul(G,da)|0,e=e+Math.imul(H,ca)|0,f=f+Math.imul(H,da)|0,d=d+Math.imul(D,fa)|0,e=e+Math.imul(D,ga)|0,e=e+Math.imul(E,fa)|0,f=f+Math.imul(E,ga)|0,d=d+Math.imul(A,ia)|0,e=e+Math.imul(A,ja)|0,e=e+Math.imul(B,ia)|0,f=f+Math.imul(B,ja)|0,d=d+Math.imul(x,la)|0,e=e+Math.imul(x,ma)|0,e=e+Math.imul(y,la)|0,f=f+Math.imul(y,ma)|0,d=d+Math.imul(u,oa)|0,e=e+Math.imul(u,pa)|0,e=e+Math.imul(v,oa)|0,f=f+Math.imul(v,pa)|0;var Ca=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ca>>>26)|0,Ca&=67108863,d=Math.imul(M,_),e=Math.imul(M,aa),e=e+Math.imul(N,_)|0,f=Math.imul(N,aa),d=d+Math.imul(J,ca)|0,e=e+Math.imul(J,da)|0,e=e+Math.imul(K,ca)|0,f=f+Math.imul(K,da)|0,d=d+Math.imul(G,fa)|0,e=e+Math.imul(G,ga)|0,e=e+Math.imul(H,fa)|0,f=f+Math.imul(H,ga)|0,d=d+Math.imul(D,ia)|0,e=e+Math.imul(D,ja)|0,e=e+Math.imul(E,ia)|0,f=f+Math.imul(E,ja)|0,d=d+Math.imul(A,la)|0,e=e+Math.imul(A,ma)|0,e=e+Math.imul(B,la)|0,f=f+Math.imul(B,ma)|0,d=d+Math.imul(x,oa)|0,e=e+Math.imul(x,pa)|0,e=e+Math.imul(y,oa)|0,f=f+Math.imul(y,pa)|0;var Da=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Da>>>26)|0,Da&=67108863,d=Math.imul(M,ca),e=Math.imul(M,da),e=e+Math.imul(N,ca)|0,f=Math.imul(N,da),d=d+Math.imul(J,fa)|0,e=e+Math.imul(J,ga)|0,e=e+Math.imul(K,fa)|0,f=f+Math.imul(K,ga)|0,d=d+Math.imul(G,ia)|0,e=e+Math.imul(G,ja)|0,e=e+Math.imul(H,ia)|0,f=f+Math.imul(H,ja)|0,d=d+Math.imul(D,la)|0,e=e+Math.imul(D,ma)|0,e=e+Math.imul(E,la)|0,f=f+Math.imul(E,ma)|0,d=d+Math.imul(A,oa)|0,e=e+Math.imul(A,pa)|0,e=e+Math.imul(B,oa)|0,f=f+Math.imul(B,pa)|0;var Ea=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ea>>>26)|0,Ea&=67108863,d=Math.imul(M,fa),e=Math.imul(M,ga),e=e+Math.imul(N,fa)|0,f=Math.imul(N,ga),d=d+Math.imul(J,ia)|0,e=e+Math.imul(J,ja)|0,e=e+Math.imul(K,ia)|0,f=f+Math.imul(K,ja)|0,d=d+Math.imul(G,la)|0,e=e+Math.imul(G,ma)|0,e=e+Math.imul(H,la)|0,f=f+Math.imul(H,ma)|0,d=d+Math.imul(D,oa)|0,e=e+Math.imul(D,pa)|0,e=e+Math.imul(E,oa)|0,f=f+Math.imul(E,pa)|0;var Fa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Fa>>>26)|0,Fa&=67108863,d=Math.imul(M,ia),e=Math.imul(M,ja),e=e+Math.imul(N,ia)|0,f=Math.imul(N,ja),d=d+Math.imul(J,la)|0,e=e+Math.imul(J,ma)|0,e=e+Math.imul(K,la)|0,f=f+Math.imul(K,ma)|0,d=d+Math.imul(G,oa)|0,e=e+Math.imul(G,pa)|0,e=e+Math.imul(H,oa)|0,f=f+Math.imul(H,pa)|0;var Ga=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ga>>>26)|0,Ga&=67108863,d=Math.imul(M,la),e=Math.imul(M,ma),e=e+Math.imul(N,la)|0,f=Math.imul(N,ma),d=d+Math.imul(J,oa)|0,e=e+Math.imul(J,pa)|0,e=e+Math.imul(K,oa)|0,f=f+Math.imul(K,pa)|0;var Ha=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ha>>>26)|0,Ha&=67108863,d=Math.imul(M,oa),e=Math.imul(M,pa),e=e+Math.imul(N,oa)|0,f=Math.imul(N,pa);var Ia=(j+d|0)+((8191&e)<<13)|0;return j=(f+(e>>>13)|0)+(Ia>>>26)|0,Ia&=67108863,i[0]=qa,i[1]=ra,i[2]=sa,i[3]=ta,i[4]=ua,i[5]=va,i[6]=wa,i[7]=xa,i[8]=ya,i[9]=za,i[10]=Aa,i[11]=Ba,i[12]=Ca,i[13]=Da,i[14]=Ea,i[15]=Fa,i[16]=Ga,i[17]=Ha,i[18]=Ia,0!==j&&(i[19]=j,c.length++),c};Math.imul||(z=j),f.prototype.mulTo=function(a,b){var c,d=this.length+a.length;return c=10===this.length&&10===a.length?z(this,a,b):d<63?j(this,a,b):d<1024?k(this,a,b):l(this,a,b)},m.prototype.makeRBT=function(a){for(var b=new Array(a),c=f.prototype._countBits(a)-1,d=0;d>=1;return d},m.prototype.permute=function(a,b,c,d,e,f){for(var g=0;g>>=1)e++;return 1<>>=13,c[2*g+1]=8191&f,f>>>=13;for(g=2*b;g>=26,b+=e/67108864|0,b+=f>>>26,this.words[c]=67108863&f}return 0!==b&&(this.words[c]=b,this.length++),this},f.prototype.muln=function(a){return this.clone().imuln(a)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(a){var b=i(a);if(0===b.length)return new f(1);for(var c=this,d=0;d=0);var b,c=a%26,e=(a-c)/26,f=67108863>>>26-c<<26-c;if(0!==c){var g=0;for(b=0;b>>26-c}g&&(this.words[b]=g,this.length++)}if(0!==e){for(b=this.length-1;b>=0;b--)this.words[b+e]=this.words[b];for(b=0;b=0);var e;e=b?(b-b%26)/26:0;var f=a%26,g=Math.min((a-f)/26,this.length),h=67108863^67108863>>>f<g)for(this.length-=g,j=0;j=0&&(0!==k||j>=e);j--){var l=0|this.words[j];this.words[j]=k<<26-f|l>>>f,k=l&h}return i&&0!==k&&(i.words[i.length++]=k),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},f.prototype.ishrn=function(a,b,c){return d(0===this.negative),this.iushrn(a,b,c)},f.prototype.shln=function(a){return this.clone().ishln(a)},f.prototype.ushln=function(a){return this.clone().iushln(a)},f.prototype.shrn=function(a){return this.clone().ishrn(a)},f.prototype.ushrn=function(a){return this.clone().iushrn(a)},f.prototype.testn=function(a){d("number"==typeof a&&a>=0);var b=a%26,c=(a-b)/26,e=1<=0);var b=a%26,c=(a-b)/26;if(d(0===this.negative,"imaskn works only with positive numbers"),this.length<=c)return this;if(0!==b&&c++,this.length=Math.min(c,this.length),0!==b){var e=67108863^67108863>>>b<=67108864;b++)this.words[b]-=67108864,b===this.length-1?this.words[b+1]=1:this.words[b+1]++;return this.length=Math.max(this.length,b+1),this},f.prototype.isubn=function(a){if(d("number"==typeof a),d(a<67108864),a<0)return this.iaddn(-a);if(0!==this.negative)return this.negative=0,this.iaddn(a),this.negative=1,this;if(this.words[0]-=a,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var b=0;b>26)-(i/67108864|0),this.words[e+c]=67108863&g}for(;e>26,this.words[e+c]=67108863&g;if(0===h)return this.strip();for(d(h===-1),h=0,e=0;e>26,this.words[e]=67108863&g;return this.negative=1,this.strip()},f.prototype._wordDiv=function(a,b){var c=this.length-a.length,d=this.clone(),e=a,g=0|e.words[e.length-1],h=this._countBits(g);c=26-h,0!==c&&(e=e.ushln(c),d.iushln(c),g=0|e.words[e.length-1]);var i,j=d.length-e.length;if("mod"!==b){i=new f(null),i.length=j+1,i.words=new Array(i.length);for(var k=0;k=0;m--){var n=67108864*(0|d.words[e.length+m])+(0|d.words[e.length+m-1]);for(n=Math.min(n/g|0,67108863),d._ishlnsubmul(e,n,m);0!==d.negative;)n--,d.negative=0,d._ishlnsubmul(e,1,m),d.isZero()||(d.negative^=1);i&&(i.words[m]=n)}return i&&i.strip(),d.strip(),"div"!==b&&0!==c&&d.iushrn(c),{div:i||null,mod:d}},f.prototype.divmod=function(a,b,c){if(d(!a.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var e,g,h;return 0!==this.negative&&0===a.negative?(h=this.neg().divmod(a,b),"mod"!==b&&(e=h.div.neg()),"div"!==b&&(g=h.mod.neg(),c&&0!==g.negative&&g.iadd(a)),{div:e,mod:g}):0===this.negative&&0!==a.negative?(h=this.divmod(a.neg(),b),"mod"!==b&&(e=h.div.neg()),
+{div:e,mod:h.mod}):0!==(this.negative&a.negative)?(h=this.neg().divmod(a.neg(),b),"div"!==b&&(g=h.mod.neg(),c&&0!==g.negative&&g.isub(a)),{div:h.div,mod:g}):a.length>this.length||this.cmp(a)<0?{div:new f(0),mod:this}:1===a.length?"div"===b?{div:this.divn(a.words[0]),mod:null}:"mod"===b?{div:null,mod:new f(this.modn(a.words[0]))}:{div:this.divn(a.words[0]),mod:new f(this.modn(a.words[0]))}:this._wordDiv(a,b)},f.prototype.div=function(a){return this.divmod(a,"div",!1).div},f.prototype.mod=function(a){return this.divmod(a,"mod",!1).mod},f.prototype.umod=function(a){return this.divmod(a,"mod",!0).mod},f.prototype.divRound=function(a){var b=this.divmod(a);if(b.mod.isZero())return b.div;var c=0!==b.div.negative?b.mod.isub(a):b.mod,d=a.ushrn(1),e=a.andln(1),f=c.cmp(d);return f<0||1===e&&0===f?b.div:0!==b.div.negative?b.div.isubn(1):b.div.iaddn(1)},f.prototype.modn=function(a){d(a<=67108863);for(var b=(1<<26)%a,c=0,e=this.length-1;e>=0;e--)c=(b*c+(0|this.words[e]))%a;return c},f.prototype.idivn=function(a){d(a<=67108863);for(var b=0,c=this.length-1;c>=0;c--){var e=(0|this.words[c])+67108864*b;this.words[c]=e/a|0,b=e%a}return this.strip()},f.prototype.divn=function(a){return this.clone().idivn(a)},f.prototype.egcd=function(a){d(0===a.negative),d(!a.isZero());var b=this,c=a.clone();b=0!==b.negative?b.umod(a):b.clone();for(var e=new f(1),g=new f(0),h=new f(0),i=new f(1),j=0;b.isEven()&&c.isEven();)b.iushrn(1),c.iushrn(1),++j;for(var k=c.clone(),l=b.clone();!b.isZero();){for(var m=0,n=1;0===(b.words[0]&n)&&m<26;++m,n<<=1);if(m>0)for(b.iushrn(m);m-- >0;)(e.isOdd()||g.isOdd())&&(e.iadd(k),g.isub(l)),e.iushrn(1),g.iushrn(1);for(var o=0,p=1;0===(c.words[0]&p)&&o<26;++o,p<<=1);if(o>0)for(c.iushrn(o);o-- >0;)(h.isOdd()||i.isOdd())&&(h.iadd(k),i.isub(l)),h.iushrn(1),i.iushrn(1);b.cmp(c)>=0?(b.isub(c),e.isub(h),g.isub(i)):(c.isub(b),h.isub(e),i.isub(g))}return{a:h,b:i,gcd:c.iushln(j)}},f.prototype._invmp=function(a){d(0===a.negative),d(!a.isZero());var b=this,c=a.clone();b=0!==b.negative?b.umod(a):b.clone();for(var e=new f(1),g=new f(0),h=c.clone();b.cmpn(1)>0&&c.cmpn(1)>0;){for(var i=0,j=1;0===(b.words[0]&j)&&i<26;++i,j<<=1);if(i>0)for(b.iushrn(i);i-- >0;)e.isOdd()&&e.iadd(h),e.iushrn(1);for(var k=0,l=1;0===(c.words[0]&l)&&k<26;++k,l<<=1);if(k>0)for(c.iushrn(k);k-- >0;)g.isOdd()&&g.iadd(h),g.iushrn(1);b.cmp(c)>=0?(b.isub(c),e.isub(g)):(c.isub(b),g.isub(e))}var m;return m=0===b.cmpn(1)?e:g,m.cmpn(0)<0&&m.iadd(a),m},f.prototype.gcd=function(a){if(this.isZero())return a.abs();if(a.isZero())return this.abs();var b=this.clone(),c=a.clone();b.negative=0,c.negative=0;for(var d=0;b.isEven()&&c.isEven();d++)b.iushrn(1),c.iushrn(1);for(;;){for(;b.isEven();)b.iushrn(1);for(;c.isEven();)c.iushrn(1);var e=b.cmp(c);if(e<0){var f=b;b=c,c=f}else if(0===e||0===c.cmpn(1))break;b.isub(c)}return c.iushln(d)},f.prototype.invm=function(a){return this.egcd(a).a.umod(a)},f.prototype.isEven=function(){return 0===(1&this.words[0])},f.prototype.isOdd=function(){return 1===(1&this.words[0])},f.prototype.andln=function(a){return this.words[0]&a},f.prototype.bincn=function(a){d("number"==typeof a);var b=a%26,c=(a-b)/26,e=1<>>26,h&=67108863,this.words[g]=h}return 0!==f&&(this.words[g]=f,this.length++),this},f.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},f.prototype.cmpn=function(a){var b=a<0;if(0!==this.negative&&!b)return-1;if(0===this.negative&&b)return 1;this.strip();var c;if(this.length>1)c=1;else{b&&(a=-a),d(a<=67108863,"Number is too big");var e=0|this.words[0];c=e===a?0:ea.length)return 1;if(this.length=0;c--){var d=0|this.words[c],e=0|a.words[c];if(d!==e){de&&(b=1);break}}return b},f.prototype.gtn=function(a){return 1===this.cmpn(a)},f.prototype.gt=function(a){return 1===this.cmp(a)},f.prototype.gten=function(a){return this.cmpn(a)>=0},f.prototype.gte=function(a){return this.cmp(a)>=0},f.prototype.ltn=function(a){return this.cmpn(a)===-1},f.prototype.lt=function(a){return this.cmp(a)===-1},f.prototype.lten=function(a){return this.cmpn(a)<=0},f.prototype.lte=function(a){return this.cmp(a)<=0},f.prototype.eqn=function(a){return 0===this.cmpn(a)},f.prototype.eq=function(a){return 0===this.cmp(a)},f.red=function(a){return new s(a)},f.prototype.toRed=function(a){return d(!this.red,"Already a number in reduction context"),d(0===this.negative,"red works only with positives"),a.convertTo(this)._forceRed(a)},f.prototype.fromRed=function(){return d(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(a){return this.red=a,this},f.prototype.forceRed=function(a){return d(!this.red,"Already a number in reduction context"),this._forceRed(a)},f.prototype.redAdd=function(a){return d(this.red,"redAdd works only with red numbers"),this.red.add(this,a)},f.prototype.redIAdd=function(a){return d(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,a)},f.prototype.redSub=function(a){return d(this.red,"redSub works only with red numbers"),this.red.sub(this,a)},f.prototype.redISub=function(a){return d(this.red,"redISub works only with red numbers"),this.red.isub(this,a)},f.prototype.redShl=function(a){return d(this.red,"redShl works only with red numbers"),this.red.shl(this,a)},f.prototype.redMul=function(a){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.mul(this,a)},f.prototype.redIMul=function(a){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.imul(this,a)},f.prototype.redSqr=function(){return d(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return d(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return d(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return d(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return d(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(a){return d(this.red&&!a.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,a)};var A={k256:null,p224:null,p192:null,p25519:null};n.prototype._tmp=function(){var a=new f(null);return a.words=new Array(Math.ceil(this.n/13)),a},n.prototype.ireduce=function(a){var b,c=a;do this.split(c,this.tmp),c=this.imulK(c),c=c.iadd(this.tmp),b=c.bitLength();while(b>this.n);var d=b0?c.isub(this.p):c.strip(),c},n.prototype.split=function(a,b){a.iushrn(this.n,0,b)},n.prototype.imulK=function(a){return a.imul(this.k)},e(o,n),o.prototype.split=function(a,b){for(var c=4194303,d=Math.min(a.length,9),e=0;e>>22,f=g}f>>>=22,a.words[e-10]=f,0===f&&a.length>10?a.length-=10:a.length-=9},o.prototype.imulK=function(a){a.words[a.length]=0,a.words[a.length+1]=0,a.length+=2;for(var b=0,c=0;c>>=26,a.words[c]=e,b=d}return 0!==b&&(a.words[a.length++]=b),a},f._prime=function B(a){if(A[a])return A[a];var B;if("k256"===a)B=new o;else if("p224"===a)B=new p;else if("p192"===a)B=new q;else{if("p25519"!==a)throw new Error("Unknown prime "+a);B=new r}return A[a]=B,B},s.prototype._verify1=function(a){d(0===a.negative,"red works only with positives"),d(a.red,"red works only with red numbers")},s.prototype._verify2=function(a,b){d(0===(a.negative|b.negative),"red works only with positives"),d(a.red&&a.red===b.red,"red works only with red numbers")},s.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):a.umod(this.m)._forceRed(this)},s.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},s.prototype.add=function(a,b){this._verify2(a,b);var c=a.add(b);return c.cmp(this.m)>=0&&c.isub(this.m),c._forceRed(this)},s.prototype.iadd=function(a,b){this._verify2(a,b);var c=a.iadd(b);return c.cmp(this.m)>=0&&c.isub(this.m),c},s.prototype.sub=function(a,b){this._verify2(a,b);var c=a.sub(b);return c.cmpn(0)<0&&c.iadd(this.m),c._forceRed(this)},s.prototype.isub=function(a,b){this._verify2(a,b);var c=a.isub(b);return c.cmpn(0)<0&&c.iadd(this.m),c},s.prototype.shl=function(a,b){return this._verify1(a),this.imod(a.ushln(b))},s.prototype.imul=function(a,b){return this._verify2(a,b),this.imod(a.imul(b))},s.prototype.mul=function(a,b){return this._verify2(a,b),this.imod(a.mul(b))},s.prototype.isqr=function(a){return this.imul(a,a.clone())},s.prototype.sqr=function(a){return this.mul(a,a)},s.prototype.sqrt=function(a){if(a.isZero())return a.clone();var b=this.m.andln(3);if(d(b%2===1),3===b){var c=this.m.add(new f(1)).iushrn(2);return this.pow(a,c)}for(var e=this.m.subn(1),g=0;!e.isZero()&&0===e.andln(1);)g++,e.iushrn(1);d(!e.isZero());var h=new f(1).toRed(this),i=h.redNeg(),j=this.m.subn(1).iushrn(1),k=this.m.bitLength();for(k=new f(2*k*k).toRed(this);0!==this.pow(k,j).cmp(i);)k.redIAdd(i);for(var l=this.pow(k,e),m=this.pow(a,e.addn(1).iushrn(1)),n=this.pow(a,e),o=g;0!==n.cmp(h);){for(var p=n,q=0;0!==p.cmp(h);q++)p=p.redSqr();d(q=0;e--){for(var k=b.words[e],l=j-1;l>=0;l--){var m=k>>l&1;g!==d[0]&&(g=this.sqr(g)),0!==m||0!==h?(h<<=1,h|=m,i++,(i===c||0===e&&0===l)&&(g=this.mul(g,d[h]),i=0,h=0)):i=0}j=26}return g},s.prototype.convertTo=function(a){var b=a.umod(this.m);return b===a?b.clone():b},s.prototype.convertFrom=function(a){var b=a.clone();return b.red=null,b},f.mont=function(a){return new t(a)},e(t,s),t.prototype.convertTo=function(a){return this.imod(a.ushln(this.shift))},t.prototype.convertFrom=function(a){var b=this.imod(a.mul(this.rinv));return b.red=null,b},t.prototype.imul=function(a,b){if(a.isZero()||b.isZero())return a.words[0]=0,a.length=1,a;var c=a.imul(b),d=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),e=c.isub(d).iushrn(this.shift),f=e;return e.cmp(this.m)>=0?f=e.isub(this.m):e.cmpn(0)<0&&(f=e.iadd(this.m)),f._forceRed(this)},t.prototype.mul=function(a,b){if(a.isZero()||b.isZero())return new f(0)._forceRed(this);var c=a.mul(b),d=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),e=c.isub(d).iushrn(this.shift),g=e;return e.cmp(this.m)>=0?g=e.isub(this.m):e.cmpn(0)<0&&(g=e.iadd(this.m)),g._forceRed(this)},t.prototype.invm=function(a){var b=this.imod(a._invmp(this.m).mul(this.r2));return b._forceRed(this)}}("undefined"==typeof b||b,this)},{buffer:2}],2:[function(a,b,c){},{}],3:[function(a,b,c){"function"==typeof Object.create?b.exports=function(a,b){a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})}:b.exports=function(a,b){a.super_=b;var c=function(){};c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a}},{}],4:[function(a,b,c){(function(a,c){!function(){"use strict";function d(a,b,c){this.blocks=[],this.s=[],this.padding=b,this.outputBits=c,this.reset=!0,this.block=0,this.start=0,this.blockCount=1600-(a<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=c>>5,this.extraBytes=(31&c)>>3;for(var d=0;d<50;++d)this.s[d]=0}var e="object"==typeof window?window:{},f=!e.JS_SHA3_NO_NODE_JS&&"object"==typeof a&&a.versions&&a.versions.node;f&&(e=c);for(var g=!e.JS_SHA3_NO_COMMON_JS&&"object"==typeof b&&b.exports,h="0123456789abcdef".split(""),i=[31,7936,2031616,520093696],j=[1,256,65536,16777216],k=[6,1536,393216,100663296],l=[0,8,16,24],m=[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],n=[224,256,384,512],o=[128,256],p=["hex","buffer","arrayBuffer","array"],q=function(a,b,c){return function(e){return new d(a,b,a).update(e)[c]()}},r=function(a,b,c){return function(e,f){return new d(a,b,f).update(e)[c]()}},s=function(a,b){var c=q(a,b,"hex");c.create=function(){return new d(a,b,a)},c.update=function(a){return c.create().update(a)};for(var e=0;e>2]|=a[i]<>2]|=d<>2]|=(192|d>>6)<>2]|=(128|63&d)<=57344?(f[c>>2]|=(224|d>>12)<>2]|=(128|d>>6&63)<>2]|=(128|63&d)<>2]|=(240|d>>18)<>2]|=(128|d>>12&63)<>2]|=(128|d>>6&63)<>2]|=(128|63&d)<=g){for(this.start=c-g,this.block=f[h],c=0;c>2]|=this.padding[3&b],this.lastByteIndex===this.byteCount)for(a[0]=a[c],b=1;b>4&15]+h[15&a]+h[a>>12&15]+h[a>>8&15]+h[a>>20&15]+h[a>>16&15]+h[a>>28&15]+h[a>>24&15];g%b===0&&(C(c),f=0)}return e&&(a=c[f],e>0&&(i+=h[a>>4&15]+h[15&a]),e>1&&(i+=h[a>>12&15]+h[a>>8&15]),e>2&&(i+=h[a>>20&15]+h[a>>16&15])),i},d.prototype.arrayBuffer=function(){this.finalize();var a,b=this.blockCount,c=this.s,d=this.outputBlocks,e=this.extraBytes,f=0,g=0,h=this.outputBits>>3;a=e?new ArrayBuffer(d+1<<2):new ArrayBuffer(h);for(var i=new Uint32Array(a);g>8&255,i[a+2]=b>>16&255,i[a+3]=b>>24&255;h%c===0&&C(d)}return f&&(a=h<<2,b=d[g],f>0&&(i[a]=255&b),f>1&&(i[a+1]=b>>8&255),f>2&&(i[a+2]=b>>16&255)),i};var C=function(a){var b,c,d,e,f,g,h,i,j,k,l,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,aa,ba,ca,da,ea,fa,ga,ha,ia,ja,ka;for(d=0;d<48;d+=2)e=a[0]^a[10]^a[20]^a[30]^a[40],f=a[1]^a[11]^a[21]^a[31]^a[41],g=a[2]^a[12]^a[22]^a[32]^a[42],h=a[3]^a[13]^a[23]^a[33]^a[43],i=a[4]^a[14]^a[24]^a[34]^a[44],j=a[5]^a[15]^a[25]^a[35]^a[45],k=a[6]^a[16]^a[26]^a[36]^a[46],l=a[7]^a[17]^a[27]^a[37]^a[47],n=a[8]^a[18]^a[28]^a[38]^a[48],o=a[9]^a[19]^a[29]^a[39]^a[49],b=n^(g<<1|h>>>31),c=o^(h<<1|g>>>31),a[0]^=b,a[1]^=c,a[10]^=b,a[11]^=c,a[20]^=b,a[21]^=c,a[30]^=b,a[31]^=c,a[40]^=b,a[41]^=c,b=e^(i<<1|j>>>31),c=f^(j<<1|i>>>31),a[2]^=b,a[3]^=c,a[12]^=b,a[13]^=c,a[22]^=b,a[23]^=c,a[32]^=b,a[33]^=c,a[42]^=b,a[43]^=c,b=g^(k<<1|l>>>31),c=h^(l<<1|k>>>31),a[4]^=b,a[5]^=c,a[14]^=b,a[15]^=c,a[24]^=b,a[25]^=c,a[34]^=b,a[35]^=c,a[44]^=b,a[45]^=c,b=i^(n<<1|o>>>31),c=j^(o<<1|n>>>31),a[6]^=b,a[7]^=c,a[16]^=b,a[17]^=c,a[26]^=b,a[27]^=c,a[36]^=b,a[37]^=c,a[46]^=b,a[47]^=c,b=k^(e<<1|f>>>31),c=l^(f<<1|e>>>31),a[8]^=b,a[9]^=c,a[18]^=b,a[19]^=c,a[28]^=b,a[29]^=c,a[38]^=b,a[39]^=c,a[48]^=b,a[49]^=c,p=a[0],q=a[1],V=a[11]<<4|a[10]>>>28,W=a[10]<<4|a[11]>>>28,D=a[20]<<3|a[21]>>>29,E=a[21]<<3|a[20]>>>29,ha=a[31]<<9|a[30]>>>23,ia=a[30]<<9|a[31]>>>23,R=a[40]<<18|a[41]>>>14,S=a[41]<<18|a[40]>>>14,J=a[2]<<1|a[3]>>>31,K=a[3]<<1|a[2]>>>31,r=a[13]<<12|a[12]>>>20,s=a[12]<<12|a[13]>>>20,X=a[22]<<10|a[23]>>>22,Y=a[23]<<10|a[22]>>>22,F=a[33]<<13|a[32]>>>19,G=a[32]<<13|a[33]>>>19,ja=a[42]<<2|a[43]>>>30,ka=a[43]<<2|a[42]>>>30,ba=a[5]<<30|a[4]>>>2,ca=a[4]<<30|a[5]>>>2,L=a[14]<<6|a[15]>>>26,M=a[15]<<6|a[14]>>>26,t=a[25]<<11|a[24]>>>21,u=a[24]<<11|a[25]>>>21,Z=a[34]<<15|a[35]>>>17,$=a[35]<<15|a[34]>>>17,H=a[45]<<29|a[44]>>>3,I=a[44]<<29|a[45]>>>3,z=a[6]<<28|a[7]>>>4,A=a[7]<<28|a[6]>>>4,da=a[17]<<23|a[16]>>>9,ea=a[16]<<23|a[17]>>>9,N=a[26]<<25|a[27]>>>7,O=a[27]<<25|a[26]>>>7,v=a[36]<<21|a[37]>>>11,w=a[37]<<21|a[36]>>>11,_=a[47]<<24|a[46]>>>8,aa=a[46]<<24|a[47]>>>8,T=a[8]<<27|a[9]>>>5,U=a[9]<<27|a[8]>>>5,B=a[18]<<20|a[19]>>>12,C=a[19]<<20|a[18]>>>12,fa=a[29]<<7|a[28]>>>25,ga=a[28]<<7|a[29]>>>25,P=a[38]<<8|a[39]>>>24,Q=a[39]<<8|a[38]>>>24,x=a[48]<<14|a[49]>>>18,y=a[49]<<14|a[48]>>>18,a[0]=p^~r&t,a[1]=q^~s&u,a[10]=z^~B&D,a[11]=A^~C&E,a[20]=J^~L&N,a[21]=K^~M&O,a[30]=T^~V&X,a[31]=U^~W&Y,a[40]=ba^~da&fa,a[41]=ca^~ea&ga,a[2]=r^~t&v,a[3]=s^~u&w,a[12]=B^~D&F,a[13]=C^~E&G,a[22]=L^~N&P,a[23]=M^~O&Q,a[32]=V^~X&Z,a[33]=W^~Y&$,a[42]=da^~fa&ha,a[43]=ea^~ga&ia,a[4]=t^~v&x,a[5]=u^~w&y,a[14]=D^~F&H,a[15]=E^~G&I,a[24]=N^~P&R,a[25]=O^~Q&S,a[34]=X^~Z&_,a[35]=Y^~$&aa,a[44]=fa^~ha&ja,a[45]=ga^~ia&ka,a[6]=v^~x&p,a[7]=w^~y&q,a[16]=F^~H&z,a[17]=G^~I&A,a[26]=P^~R&J,a[27]=Q^~S&K,a[36]=Z^~_&T,a[37]=$^~aa&U,a[46]=ha^~ja&ba,a[47]=ia^~ka&ca,a[8]=x^~p&r,a[9]=y^~q&s,a[18]=H^~z&B,a[19]=I^~A&C,a[28]=R^~J&L,a[29]=S^~K&M,a[38]=_^~T&V,a[39]=aa^~U&W,a[48]=ja^~ba&da,a[49]=ka^~ca&ea,a[0]^=m[d],a[1]^=m[d+1]};if(g)b.exports=v;else for(var x=0;x0){if(b.filter.topics.length>1)throw new Error("unsupported topic format");var k=b.filter.topics[0];if("string"!=typeof k||66!==k.length)throw new Error("unsupported topic0 format");c+="&topic0="+k}}catch(l){return Promise.reject(l)}return c+=e,i.fetchJSON(c,null,f);case"getEtherPrice":return"homestead"!==this.name?Promise.resolve(0):(c+="/api?module=stats&action=ethprice",c+=e,i.fetchJSON(c,null,f).then(function(a){return parseFloat(a.ethusd)}))}return Promise.reject(new Error("not implemented - "+a))}),j.defineProperty(e.prototype,"getHistory",function(a,b,c){var d=this.baseUrl,e="";return this.apiKey&&(e+="&apikey="+this.apiKey),null==b&&(b=0),null==c&&(c=99999999),this.resolveName(a).then(function(a){return d+="/api?module=account&action=txlist&address="+a,d+="&fromBlock="+b,d+="&endBlock="+c,d+="&sort=asc",i.fetchJSON(d,null,f).then(function(a){var b=[];return a.forEach(function(a){["contractAddress","to"].forEach(function(b){""==a[b]&&delete a[b]}),null==a.creates&&null!=a.contractAddress&&(a.creates=a.contractAddress),b.push(i._formatters.checkTransactionResponse(a))}),b})})}),b.exports=e},{"../utils/convert.js":18,"../utils/properties.js":21,"./provider.js":13}],8:[function(a,b,c){"use strict";function d(a){if(0===a.length)throw new Error("no providers");var b={};if(["chainId","ensAddress","name","testnet"].forEach(function(c){for(var d=1;db+12&&delete e._emitted[a]})),e.emit("block",b);var c={};Object.keys(d).forEach(function(b){var d=A(b);"transaction"===d.type?e.getTransaction(d.hash).then(function(a){a&&null!=a.blockNumber&&(e._emitted["t:"+a.hash.toLowerCase()]=a.blockNumber,e.emit(d.hash,a))}):"address"===d.type?(g[d.address]&&(c[d.address]=g[d.address]),e.getBalance(d.address,"latest").then(function(a){var b=g[d.address];b&&a.eq(b)||(g[d.address]=a,e.emit(d.address,a))})):"topic"===d.type&&e.getLogs({fromBlock:f+1,toBlock:a,topics:d.topic}).then(function(a){0!==a.length&&a.forEach(function(a){e._emitted["b:"+a.blockHash.toLowerCase()]=a.blockNumber,e._emitted["t:"+a.transactionHash.toLowerCase()]=a.blockNumber,e.emit(d.topic,a)})})}),f=a,g=c}}),e.doPoll()}if(!(this instanceof v))throw new Error("missing new");a=v.getNetwork(a);var c=null;a.ensAddress&&(c=E.getAddress(a.ensAddress)),E.defineProperty(this,"chainId",a.chainId),E.defineProperty(this,"ensAddress",c),E.defineProperty(this,"name",a.name);var d={};E.defineProperty(this,"_events",d),E.defineProperty(this,"_emitted",{block:-1});var e=this,f=null,g={};E.defineProperty(this,"resetEventsBlock",function(a){f=a,e.doPoll()});var h=null;Object.defineProperty(this,"polling",{get:function(){return null!=h},set:function(a){setTimeout(function(){a&&!h?h=setInterval(b,4e3):!a&&h&&(clearInterval(h),h=null)},0)}})}function w(a){return function(b){B(b,a),E.defineProperty(b,"inherits",w(b))}}function x(a,b){return new Promise(function(c,d){function e(){b().then(function(b){if(b||a())c(b);else{f++;var d=500+250*parseInt(Math.random()*(1<1e4&&(d=1e4),setTimeout(e,d)}},function(a){d(a)})}var f=0;e()})}function y(a,b){if(Array.isArray(a)){var c=[];return a.forEach(function(a){c.push(y(a,b))}),c}return b(a)}function z(a){try{return"address:"+E.getAddress(a)}catch(b){}if("block"===a)return"block";if("pending"===a)return"pending";if(E.isHexString(a)){if(66===a.length)return"tx:"+a}else if(Array.isArray(a)){a=y(a,function(a){return null==a&&(a="0x"),a});try{return"topic:"+E.RLP.encode(a)}catch(b){console.log(b)}}throw new Error("invalid event - "+a)}function A(a){if("tx:"===a.substring(0,3))return{type:"transaction",hash:a.substring(3)};if("block"===a)return{type:"block"};if("pending"===a)return{type:"pending"};if("address:"===a.substring(0,8))return{type:"address",address:a.substring(8)};if("topic:"===a.substring(0,6))try{var b=E.RLP.decode(a.substring(6));return b=y(b,function(a){return"0x"===a&&(a=null),a}),{type:"topic",topic:b}}catch(c){console.log(c)}throw new Error("invalid event string")}var B=a("inherits"),C=a("xmlhttprequest").XMLHttpRequest,D=a("./networks.json"),E=function(){var b=a("../utils/convert");return{defineProperty:a("../utils/properties").defineProperty,getAddress:a("../utils/address").getAddress,getContractAddress:a("../utils/contract-address").getContractAddress,bigNumberify:a("../utils/bignumber").bigNumberify,arrayify:b.arrayify,hexlify:b.hexlify,isHexString:b.isHexString,concat:b.concat,hexStripZeros:b.hexStripZeros,stripZeros:b.stripZeros,namehash:a("../utils/namehash"),toUtf8String:a("../utils/utf8").toUtf8String,RLP:a("../utils/rlp")}}(),F={hash:i,parentHash:i,number:j,timestamp:j,nonce:f(E.hexlify),difficulty:f(j),gasLimit:E.bigNumberify,gasUsed:E.bigNumberify,miner:E.getAddress,extraData:E.hexlify,transactions:f(h(i))},G={hash:i,blockHash:f(i,null),blockNumber:f(j,null),transactionIndex:f(j,null),from:E.getAddress,gasPrice:E.bigNumberify,gasLimit:E.bigNumberify,to:f(E.getAddress,null),value:E.bigNumberify,nonce:j,data:E.hexlify,r:f(l),s:f(l),v:f(j),creates:f(E.getAddress,null),raw:f(E.hexlify)},H={from:f(E.getAddress),nonce:f(j),gasLimit:f(E.bigNumberify),gasPrice:f(E.bigNumberify),to:f(E.getAddress),value:f(E.bigNumberify),data:f(E.hexlify)},I={transactionLogIndex:f(j),transactionIndex:j,blockNumber:j,transactionHash:i,address:E.getAddress,topics:h(i),data:E.hexlify,logIndex:j,blockHash:i},J={contractAddress:f(E.getAddress,null),transactionIndex:j,root:f(i),gasUsed:E.bigNumberify,logsBloom:E.hexlify,blockHash:i,transactionHash:i,logs:h(q),blockNumber:j,cumulativeGasUsed:E.bigNumberify,status:f(j)},K={fromBlock:f(m,void 0),toBlock:f(m,void 0),address:f(E.getAddress,void 0),topics:f(s,void 0)},L={blockNumber:f(j),blockHash:f(i),transactionIndex:j,removed:f(k),address:E.getAddress,data:g(E.hexlify,"0x"),topics:h(i),transactionHash:i,logIndex:j};E.defineProperty(v,"inherits",w(v)),E.defineProperty(v,"getNetwork",function(a){if("string"==typeof a){if(a=D[a],!a)throw new Error("unknown network")}else null==a&&(a=D.homestead);if("number"!=typeof a.chainId)throw new Error("invalid chainId");return a}),E.defineProperty(v,"networks",D),E.defineProperty(v,"fetchJSON",function(a,b,c){return new Promise(function(d,e){var f=new C;b?(f.open("POST",a,!0),f.setRequestHeader("Content-Type","application/json")):f.open("GET",a,!0),f.onreadystatechange=function(){if(4===f.readyState){try{var g=JSON.parse(f.responseText)}catch(h){var i=new Error("invalid json response");return i.orginialError=h,i.responseText=f.responseText,void e(i)}if(c)try{g=c(g)}catch(h){return h.url=a,h.body=b,h.responseText=f.responseText,void e(h)}if(200!=f.status){var h=new Error("invalid response - "+f.status);return h.statusCode=f.statusCode,void e(h)}d(g)}},f.onerror=function(a){e(a)};try{b?f.send(b):f.send()}catch(g){var h=new Error("connection error");h.error=g,e(h)}})}),E.defineProperty(v.prototype,"waitForTransaction",function(a,b){var c=this;return new Promise(function(d,e){function f(a){g&&clearTimeout(g),d(a)}var g=null;c.once(a,f),"number"==typeof b&&b>0&&(g=setTimeout(function(){c.removeListener(a,f),e(new Error("timeout"))},b))})}),E.defineProperty(v.prototype,"getBlockNumber",function(){try{return this.perform("getBlockNumber").then(function(a){var b=parseInt(a);if(b!=a)throw new Error("invalid response - getBlockNumber");return b})}catch(a){return Promise.reject(a)}}),E.defineProperty(v.prototype,"getGasPrice",function(){try{return this.perform("getGasPrice").then(function(a){return E.bigNumberify(a)})}catch(a){return Promise.reject(a)}}),E.defineProperty(v.prototype,"getBalance",function(a,b){var c=this;return this.resolveName(a).then(function(a){var d={address:a,blockTag:m(b)};return c.perform("getBalance",d).then(function(a){return E.bigNumberify(a)})})}),E.defineProperty(v.prototype,"getTransactionCount",function(a,b){var c=this;return this.resolveName(a).then(function(a){var d={address:a,blockTag:m(b)};return c.perform("getTransactionCount",d).then(function(a){var b=parseInt(a);if(b!=a)throw new Error("invalid response - getTransactionCount");return b})})}),E.defineProperty(v.prototype,"getCode",function(a,b){var c=this;return this.resolveName(a).then(function(a){var d={address:a,blockTag:m(b)};return c.perform("getCode",d).then(function(a){return E.hexlify(a)})})}),E.defineProperty(v.prototype,"getStorageAt",function(a,b,c){var d=this;return this.resolveName(a).then(function(a){var e={address:a,blockTag:m(c),position:E.hexStripZeros(E.hexlify(b))};return d.perform("getStorageAt",e).then(function(a){return E.hexlify(a)})})}),E.defineProperty(v.prototype,"sendTransaction",function(a){try{var b={signedTransaction:E.hexlify(a)};return this.perform("sendTransaction",b).then(function(a){if(a=E.hexlify(a),66!==a.length)throw new Error("invalid response - sendTransaction");return a})}catch(c){return Promise.reject(c)}}),E.defineProperty(v.prototype,"call",function(a){var b=this;return this._resolveNames(a,["to","from"]).then(function(a){var c={transaction:p(a)};return b.perform("call",c).then(function(a){return E.hexlify(a)})})}),E.defineProperty(v.prototype,"estimateGas",function(a){var b=this;return this._resolveNames(a,["to","from"]).then(function(a){var c={transaction:p(a)};return b.perform("estimateGas",c).then(function(a){return E.bigNumberify(a)})})}),E.defineProperty(v.prototype,"getBlock",function(a){var b=this;try{var c=E.hexlify(a);if(66===c.length)return x(function(){return null==b._emitted["b:"+c.toLowerCase()]},function(){return b.perform("getBlock",{blockHash:c}).then(function(a){return null==a?null:n(a)})})}catch(d){}try{var e=m(a);return x(function(){if(E.isHexString(e)){var a=parseInt(e.substring(2),16);return a>b._emitted.block}return!0},function(){return b.perform("getBlock",{blockTag:e}).then(function(a){return null==a?null:n(a)})})}catch(d){}return Promise.reject(new Error("invalid block hash or block tag"))}),E.defineProperty(v.prototype,"getTransaction",function(a){var b=this;try{var c={transactionHash:i(a)};return x(function(){return null==b._emitted["t:"+a.toLowerCase()]},function(){return b.perform("getTransaction",c).then(function(a){return null!=a&&(a=o(a)),a})})}catch(d){return Promise.reject(d)}}),E.defineProperty(v.prototype,"getTransactionReceipt",function(a){var b=this;try{var c={transactionHash:i(a)};return x(function(){return null==b._emitted["t:"+a.toLowerCase()]},function(){return b.perform("getTransactionReceipt",c).then(function(a){return null!=a&&(a=r(a)),a})})}catch(d){return Promise.reject(d)}}),E.defineProperty(v.prototype,"getLogs",function(a){var b=this;return this._resolveNames(a,["address"]).then(function(a){var c={filter:t(a)};return b.perform("getLogs",c).then(function(a){return h(u)(a)})})}),E.defineProperty(v.prototype,"getEtherPrice",function(){try{return this.perform("getEtherPrice",{}).then(function(a){return a})}catch(a){return Promise.reject(a)}}),E.defineProperty(v.prototype,"_resolveNames",function(a,b){var c=[],e=d(a);return b.forEach(function(a){void 0!==e[a]&&c.push(this.resolveName(e[a]).then(function(b){e[a]=b}))},this),Promise.all(c).then(function(){return e})}),E.defineProperty(v.prototype,"_getResolver",function(a){var b=E.namehash(a),c="0x0178b8bf"+b.substring(2),d={to:this.ensAddress,data:c};return this.call(d).then(function(a){return 66!=a.length?null:E.getAddress("0x"+a.substring(26))})}),E.defineProperty(v.prototype,"resolveName",function(a){try{return Promise.resolve(E.getAddress(a))}catch(b){}if(!this.ensAddress)throw new Error("network does not have ENS deployed");var c=this,d=E.namehash(a);return this._getResolver(a).then(function(a){var b="0x3b3b57de"+d.substring(2),e={to:a,data:b};return c.call(e)}).then(function(a){if(66!=a.length)return null;var b=E.getAddress("0x"+a.substring(26));return"0x0000000000000000000000000000000000000000"===b?null:b})}),E.defineProperty(v.prototype,"lookupAddress",function(a){if(!this.ensAddress)throw new Error("network does not have ENS deployed");a=E.getAddress(a);var b=a.substring(2)+".addr.reverse",c=E.namehash(b),d=this;return this._getResolver(b).then(function(a){if(!a)return null;var b="0x691f3431"+c.substring(2),e={to:a,data:b};return d.call(e)}).then(function(b){if(b=b.substring(2),b.length<64)return null;if(b=b.substring(64),b.length<64)return null;var c=E.bigNumberify("0x"+b.substring(0,64)).toNumber();if(b=b.substring(64),2*c>b.length)return null;var e=E.toUtf8String("0x"+b.substring(0,2*c));return d.resolveName(e).then(function(b){return b!=a?null:e})})}),E.defineProperty(v.prototype,"doPoll",function(){}),E.defineProperty(v.prototype,"perform",function(a,b){return Promise.reject(new Error("not implemented - "+a))}),E.defineProperty(v.prototype,"_startPending",function(){console.log("WARNING: this provider does not support pending events")}),E.defineProperty(v.prototype,"_stopPending",function(){}),E.defineProperty(v.prototype,"on",function(a,b){var c=z(a);this._events[c]||(this._events[c]=[]),this._events[c].push({eventName:a,listener:b,type:"on"}),"pending"===c&&this._startPending(),this.polling=!0}),E.defineProperty(v.prototype,"once",function(a,b){var c=z(a);this._events[c]||(this._events[c]=[]),this._events[c].push({eventName:a,listener:b,type:"once"}),"pending"===c&&this._startPending(),this.polling=!0}),E.defineProperty(v.prototype,"emit",function(a){var b=z(a),c=Array.prototype.slice.call(arguments,1),d=this._events[b];if(d){for(var e=0;e>1]>>4>=8&&(a[c]=a[c].toUpperCase()),(15&b[c>>1])>=8&&(a[c+1]=a[c+1].toUpperCase());return"0x"+a.join("")}function e(a){return Math.log10?Math.log10(a):Math.log(a)/Math.LN10}function f(a,b){var c=null;if("string"!=typeof a&&i("invalid address",{input:a}),a.match(/^(0x)?[0-9a-fA-F]{40}$/))"0x"!==a.substring(0,2)&&(a="0x"+a),c=d(a),a.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&c!==a&&i("invalid address checksum",{input:a,expected:c});else if(a.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(a.substring(2,4)!==l(a)&&i("invalid address icap checksum",{input:a}),c=new g(a.substring(4),36).toString(16);c.length<40;)c="0"+c;c=d("0x"+c)}else i("invalid address",{input:a});if(b){for(var e=new g(c.substring(2),16).toString(36).toUpperCase();e.length<30;)e="0"+e;return"XE"+l("XE00"+e)+e}return c}var g=a("bn.js"),h=a("./convert"),i=a("./throw-error"),j=a("./keccak256"),k=9007199254740991,l=function(){for(var a={},b=0;b<10;b++)a[String(b)]=String(b);for(var b=0;b<26;b++)a[String.fromCharCode(65+b)]=String(10+b);var c=Math.floor(e(k));return function(b){b=b.toUpperCase(),b=b.substring(4)+b.substring(0,2)+"00";for(var d=b.split(""),e=0;e=c;){var f=d.substring(0,c);d=parseInt(f,10)%97+d.substring(f.length)}for(var g=String(98-parseInt(d,10)%97);g.length<2;)g="0"+g;return g}}();b.exports={getAddress:f}},{"./convert":18,"./keccak256":19,"./throw-error":23,"bn.js":1}],16:[function(a,b,c){function d(a){if(!(this instanceof d))throw new Error("missing new");i.isHexString(a)?("0x"==a&&(a="0x0"),a=new g(a.substring(2),16)):"string"==typeof a&&"-"===a[0]&&i.isHexString(a.substring(1))?a=new g(a.substring(3),16).mul(d.constantNegativeOne._bn):"string"==typeof a&&a.match(/^-?[0-9]*$/)?(""==a&&(a="0"),a=new g(a)):"number"==typeof a&&parseInt(a)==a?a=new g(a):g.isBN(a)||(e(a)?a=a._bn:i.isArrayish(a)?a=new g(i.hexlify(a).substring(2),16):j("invalid BigNumber value",{input:a})),h(this,"_bn",a)}function e(a){return a._bn&&a._bn.mod}function f(a){return e(a)?a:new d(a)}var g=a("bn.js"),h=a("./properties").defineProperty,i=a("./convert"),j=a("./throw-error");h(d,"constantNegativeOne",f(-1)),h(d,"constantZero",f(0)),h(d,"constantOne",f(1)),h(d,"constantTwo",f(2)),h(d,"constantWeiPerEther",f(new g("1000000000000000000"))),h(d.prototype,"fromTwos",function(a){return new d(this._bn.fromTwos(a))}),h(d.prototype,"toTwos",function(a){return new d(this._bn.toTwos(a))}),h(d.prototype,"add",function(a){return new d(this._bn.add(f(a)._bn))}),h(d.prototype,"sub",function(a){return new d(this._bn.sub(f(a)._bn))}),h(d.prototype,"div",function(a){return new d(this._bn.div(f(a)._bn))}),h(d.prototype,"mul",function(a){return new d(this._bn.mul(f(a)._bn))}),h(d.prototype,"mod",function(a){return new d(this._bn.mod(f(a)._bn))}),h(d.prototype,"pow",function(a){return new d(this._bn.pow(f(a)._bn))}),h(d.prototype,"maskn",function(a){return new d(this._bn.maskn(a))}),h(d.prototype,"eq",function(a){return this._bn.eq(f(a)._bn)}),h(d.prototype,"lt",function(a){return this._bn.lt(f(a)._bn)}),h(d.prototype,"lte",function(a){return this._bn.lte(f(a)._bn)}),h(d.prototype,"gt",function(a){return this._bn.gt(f(a)._bn)}),h(d.prototype,"gte",function(a){return this._bn.gte(f(a)._bn)}),h(d.prototype,"isZero",function(){return this._bn.isZero()}),h(d.prototype,"toNumber",function(a){return this._bn.toNumber()}),h(d.prototype,"toString",function(){return this._bn.toString(10)}),h(d.prototype,"toHexString",function(){var a=this._bn.toString(16);return a.length%2&&(a="0"+a),"0x"+a}),b.exports={isBigNumber:e,bigNumberify:f,BigNumber:d}},{"./convert":18,"./properties":21,"./throw-error":23,"bn.js":1}],17:[function(a,b,c){function d(a){if(!a.from)throw new Error("missing from address");var b=a.nonce;return e("0x"+g(h.encode([e(a.from),f.stripZeros(f.hexlify(b,"nonce"))])).substring(26))}var e=a("./address").getAddress,f=a("./convert"),g=a("./keccak256"),h=a("./rlp");b.exports={getContractAddress:d}},{"./address":15,"./convert":18,"./keccak256":19,"./rlp":22}],18:[function(a,b,c){function d(a){return a.slice?a:(a.slice=function(){var b=Array.prototype.slice.call(arguments);return new Uint8Array(Array.prototype.slice.apply(a,b))},a)}function e(a){if(!a||parseInt(a.length)!=a.length||"string"==typeof a)return!1;for(var b=0;b=256||parseInt(c)!=c)return!1}return!0}function f(a,b){if(a&&a.toHexString&&(a=a.toHexString()),j(a)){a=a.substring(2),a.length%2&&(a="0"+a);for(var c=[],f=0;f>4]+o[15&g])}return"0x"+d.join("")}n("invalid hexlify value",{name:b,input:a})}function l(a){for(;a.length>3&&"0x0"===a.substring(0,3);)a="0x"+a.substring(3);return a}function m(a,b){for(;a.length<2*b+2;)a="0x0"+a.substring(2);return a}var n=(a("./properties.js").defineProperty,a("./throw-error")),o="0123456789abcdef";b.exports={arrayify:f,isArrayish:e,concat:g,padZeros:i,stripZeros:h,hexlify:k,isHexString:j,hexStripZeros:l,hexZeroPad:m}},{"./properties.js":21,"./throw-error":23}],19:[function(a,b,c){"use strict";function d(a){return a=f.arrayify(a),"0x"+e.keccak_256(a)}var e=a("js-sha3"),f=a("./convert.js");b.exports=d},{"./convert.js":18,"js-sha3":4}],20:[function(a,b,c){"use strict";function d(a,b){if(a=a.toLowerCase(),!a.match(j))throw new Error("contains invalid UseSTD3ASCIIRules characters");for(var c=h,d=0;a.length&&(!b||d>=8;return b}function e(a,b,c){for(var d=0,e=0;eb+1+d)throw new Error("invalid rlp")}return{consumed:1+d,result:e}}function i(a,b){if(0===a.length)throw new Error("invalid rlp data");if(a[b]>=248){var c=a[b]-247;if(b+1+c>a.length)throw new Error("too short");var d=e(a,b+1,c);if(b+1+c+d>a.length)throw new Error("to short");return h(a,b,b+1+c,c+d)}if(a[b]>=192){var d=a[b]-192;if(b+1+d>a.length)throw new Error("invalid rlp data");return h(a,b,b+1,d)}if(a[b]>=184){var c=a[b]-183;if(b+1+c>a.length)throw new Error("invalid rlp data");var d=e(a,b+1,c);if(b+1+c+d>a.length)throw new Error("invalid rlp data");var f=k.hexlify(a.slice(b+1+c,b+1+c+d));return{consumed:1+c+d,result:f}}if(a[b]>=128){var d=a[b]-128;if(b+1+d>a.offset)throw new Error("invlaid rlp data");var f=k.hexlify(a.slice(b+1,b+1+d));return{consumed:1+d,result:f}}return{consumed:1,result:k.hexlify(a[b])}}function j(a){a=k.arrayify(a);var b=i(a,0);if(b.consumed!==a.length)throw new Error("invalid rlp data");return b.result}var k=a("./convert.js");b.exports={encode:g,decode:j}},{"./convert.js":18}],23:[function(a,b,c){"use strict";function d(a,b){var c=new Error(a);for(var d in b)c[d]=b[d];throw c}b.exports=d},{}],24:[function(a,b,c){function d(a){for(var b=[],c=0,d=0;d>6|192,b[c++]=63&e|128):55296==(64512&e)&&d+1>18|240,b[c++]=e>>12&63|128,b[c++]=e>>6&63|128,b[c++]=63&e|128):(b[c++]=e>>12|224,b[c++]=e>>6&63|128,b[c++]=63&e|128)}return f.arrayify(b)}function e(a){a=f.arrayify(a);for(var b="",c=0;c>7!=0){if(d>>6!=2){var e=null;if(d>>5==6)e=1;else if(d>>4==14)e=2;else if(d>>3==30)e=3;else if(d>>2==62)e=4;else{if(d>>1!=126)continue;e=5}if(c+e>a.length){for(;c>6==2;c++);if(c!=a.length)continue;return b}var g,h=d&(1<<8-e-1)-1;for(g=0;g>6!=2)break;h=h<<6|63&i}g==e?h<=65535?b+=String.fromCharCode(h):(h-=65536,b+=String.fromCharCode((h>>10&1023)+55296,(1023&h)+56320)):c--}}else b+=String.fromCharCode(d)}return b}var f=a("./convert.js");b.exports={toUtf8Bytes:d,toUtf8String:e}},{"./convert.js":18}]},{},[9])(9)});
\ No newline at end of file
diff --git a/dist/ethers-utils.js b/dist/ethers-utils.js
new file mode 100644
index 0000000000..d3eb6345dc
--- /dev/null
+++ b/dist/ethers-utils.js
@@ -0,0 +1,6635 @@
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethers = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) return left;
+ return right;
+ };
+
+ BN.min = function min (left, right) {
+ if (left.cmp(right) < 0) return left;
+ return right;
+ };
+
+ BN.prototype._init = function init (number, base, endian) {
+ if (typeof number === 'number') {
+ return this._initNumber(number, base, endian);
+ }
+
+ if (typeof number === 'object') {
+ return this._initArray(number, base, endian);
+ }
+
+ if (base === 'hex') {
+ base = 16;
+ }
+ assert(base === (base | 0) && base >= 2 && base <= 36);
+
+ number = number.toString().replace(/\s+/g, '');
+ var start = 0;
+ if (number[0] === '-') {
+ start++;
+ }
+
+ if (base === 16) {
+ this._parseHex(number, start);
+ } else {
+ this._parseBase(number, base, start);
+ }
+
+ if (number[0] === '-') {
+ this.negative = 1;
+ }
+
+ this.strip();
+
+ if (endian !== 'le') return;
+
+ this._initArray(this.toArray(), base, endian);
+ };
+
+ BN.prototype._initNumber = function _initNumber (number, base, endian) {
+ if (number < 0) {
+ this.negative = 1;
+ number = -number;
+ }
+ if (number < 0x4000000) {
+ this.words = [ number & 0x3ffffff ];
+ this.length = 1;
+ } else if (number < 0x10000000000000) {
+ this.words = [
+ number & 0x3ffffff,
+ (number / 0x4000000) & 0x3ffffff
+ ];
+ this.length = 2;
+ } else {
+ assert(number < 0x20000000000000); // 2 ^ 53 (unsafe)
+ this.words = [
+ number & 0x3ffffff,
+ (number / 0x4000000) & 0x3ffffff,
+ 1
+ ];
+ this.length = 3;
+ }
+
+ if (endian !== 'le') return;
+
+ // Reverse the bytes
+ this._initArray(this.toArray(), base, endian);
+ };
+
+ BN.prototype._initArray = function _initArray (number, base, endian) {
+ // Perhaps a Uint8Array
+ assert(typeof number.length === 'number');
+ if (number.length <= 0) {
+ this.words = [ 0 ];
+ this.length = 1;
+ return this;
+ }
+
+ this.length = Math.ceil(number.length / 3);
+ this.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ this.words[i] = 0;
+ }
+
+ var j, w;
+ var off = 0;
+ if (endian === 'be') {
+ for (i = number.length - 1, j = 0; i >= 0; i -= 3) {
+ w = number[i] | (number[i - 1] << 8) | (number[i - 2] << 16);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ } else if (endian === 'le') {
+ for (i = 0, j = 0; i < number.length; i += 3) {
+ w = number[i] | (number[i + 1] << 8) | (number[i + 2] << 16);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] = (w >>> (26 - off)) & 0x3ffffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ }
+ return this.strip();
+ };
+
+ function parseHex (str, start, end) {
+ var r = 0;
+ var len = Math.min(str.length, end);
+ for (var i = start; i < len; i++) {
+ var c = str.charCodeAt(i) - 48;
+
+ r <<= 4;
+
+ // 'a' - 'f'
+ if (c >= 49 && c <= 54) {
+ r |= c - 49 + 0xa;
+
+ // 'A' - 'F'
+ } else if (c >= 17 && c <= 22) {
+ r |= c - 17 + 0xa;
+
+ // '0' - '9'
+ } else {
+ r |= c & 0xf;
+ }
+ }
+ return r;
+ }
+
+ BN.prototype._parseHex = function _parseHex (number, start) {
+ // Create possibly bigger array to ensure that it fits the number
+ this.length = Math.ceil((number.length - start) / 6);
+ this.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ this.words[i] = 0;
+ }
+
+ var j, w;
+ // Scan 24-bit chunks and add them to the number
+ var off = 0;
+ for (i = number.length - 6, j = 0; i >= start; i -= 6) {
+ w = parseHex(number, i, i + 6);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ // NOTE: `0x3fffff` is intentional here, 26bits max shift + 24bit hex limb
+ this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
+ off += 24;
+ if (off >= 26) {
+ off -= 26;
+ j++;
+ }
+ }
+ if (i + 6 !== start) {
+ w = parseHex(number, start, i + 6);
+ this.words[j] |= (w << off) & 0x3ffffff;
+ this.words[j + 1] |= w >>> (26 - off) & 0x3fffff;
+ }
+ this.strip();
+ };
+
+ function parseBase (str, start, end, mul) {
+ var r = 0;
+ var len = Math.min(str.length, end);
+ for (var i = start; i < len; i++) {
+ var c = str.charCodeAt(i) - 48;
+
+ r *= mul;
+
+ // 'a'
+ if (c >= 49) {
+ r += c - 49 + 0xa;
+
+ // 'A'
+ } else if (c >= 17) {
+ r += c - 17 + 0xa;
+
+ // '0' - '9'
+ } else {
+ r += c;
+ }
+ }
+ return r;
+ }
+
+ BN.prototype._parseBase = function _parseBase (number, base, start) {
+ // Initialize as zero
+ this.words = [ 0 ];
+ this.length = 1;
+
+ // Find length of limb in base
+ for (var limbLen = 0, limbPow = 1; limbPow <= 0x3ffffff; limbPow *= base) {
+ limbLen++;
+ }
+ limbLen--;
+ limbPow = (limbPow / base) | 0;
+
+ var total = number.length - start;
+ var mod = total % limbLen;
+ var end = Math.min(total, total - mod) + start;
+
+ var word = 0;
+ for (var i = start; i < end; i += limbLen) {
+ word = parseBase(number, i, i + limbLen, base);
+
+ this.imuln(limbPow);
+ if (this.words[0] + word < 0x4000000) {
+ this.words[0] += word;
+ } else {
+ this._iaddn(word);
+ }
+ }
+
+ if (mod !== 0) {
+ var pow = 1;
+ word = parseBase(number, i, number.length, base);
+
+ for (i = 0; i < mod; i++) {
+ pow *= base;
+ }
+
+ this.imuln(pow);
+ if (this.words[0] + word < 0x4000000) {
+ this.words[0] += word;
+ } else {
+ this._iaddn(word);
+ }
+ }
+ };
+
+ BN.prototype.copy = function copy (dest) {
+ dest.words = new Array(this.length);
+ for (var i = 0; i < this.length; i++) {
+ dest.words[i] = this.words[i];
+ }
+ dest.length = this.length;
+ dest.negative = this.negative;
+ dest.red = this.red;
+ };
+
+ BN.prototype.clone = function clone () {
+ var r = new BN(null);
+ this.copy(r);
+ return r;
+ };
+
+ BN.prototype._expand = function _expand (size) {
+ while (this.length < size) {
+ this.words[this.length++] = 0;
+ }
+ return this;
+ };
+
+ // Remove leading `0` from `this`
+ BN.prototype.strip = function strip () {
+ while (this.length > 1 && this.words[this.length - 1] === 0) {
+ this.length--;
+ }
+ return this._normSign();
+ };
+
+ BN.prototype._normSign = function _normSign () {
+ // -0 = 0
+ if (this.length === 1 && this.words[0] === 0) {
+ this.negative = 0;
+ }
+ return this;
+ };
+
+ BN.prototype.inspect = function inspect () {
+ return (this.red ? '';
+ };
+
+ /*
+
+ var zeros = [];
+ var groupSizes = [];
+ var groupBases = [];
+
+ var s = '';
+ var i = -1;
+ while (++i < BN.wordSize) {
+ zeros[i] = s;
+ s += '0';
+ }
+ groupSizes[0] = 0;
+ groupSizes[1] = 0;
+ groupBases[0] = 0;
+ groupBases[1] = 0;
+ var base = 2 - 1;
+ while (++base < 36 + 1) {
+ var groupSize = 0;
+ var groupBase = 1;
+ while (groupBase < (1 << BN.wordSize) / base) {
+ groupBase *= base;
+ groupSize += 1;
+ }
+ groupSizes[base] = groupSize;
+ groupBases[base] = groupBase;
+ }
+
+ */
+
+ var zeros = [
+ '',
+ '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'
+ ];
+
+ var groupSizes = [
+ 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
+ ];
+
+ var groupBases = [
+ 0, 0,
+ 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216,
+ 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625,
+ 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632,
+ 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149,
+ 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176
+ ];
+
+ BN.prototype.toString = function toString (base, padding) {
+ base = base || 10;
+ padding = padding | 0 || 1;
+
+ var out;
+ if (base === 16 || base === 'hex') {
+ out = '';
+ var off = 0;
+ var carry = 0;
+ for (var i = 0; i < this.length; i++) {
+ var w = this.words[i];
+ var word = (((w << off) | carry) & 0xffffff).toString(16);
+ carry = (w >>> (24 - off)) & 0xffffff;
+ if (carry !== 0 || i !== this.length - 1) {
+ out = zeros[6 - word.length] + word + out;
+ } else {
+ out = word + out;
+ }
+ off += 2;
+ if (off >= 26) {
+ off -= 26;
+ i--;
+ }
+ }
+ if (carry !== 0) {
+ out = carry.toString(16) + out;
+ }
+ while (out.length % padding !== 0) {
+ out = '0' + out;
+ }
+ if (this.negative !== 0) {
+ out = '-' + out;
+ }
+ return out;
+ }
+
+ if (base === (base | 0) && base >= 2 && base <= 36) {
+ // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base));
+ var groupSize = groupSizes[base];
+ // var groupBase = Math.pow(base, groupSize);
+ var groupBase = groupBases[base];
+ out = '';
+ var c = this.clone();
+ c.negative = 0;
+ while (!c.isZero()) {
+ var r = c.modn(groupBase).toString(base);
+ c = c.idivn(groupBase);
+
+ if (!c.isZero()) {
+ out = zeros[groupSize - r.length] + r + out;
+ } else {
+ out = r + out;
+ }
+ }
+ if (this.isZero()) {
+ out = '0' + out;
+ }
+ while (out.length % padding !== 0) {
+ out = '0' + out;
+ }
+ if (this.negative !== 0) {
+ out = '-' + out;
+ }
+ return out;
+ }
+
+ assert(false, 'Base should be between 2 and 36');
+ };
+
+ BN.prototype.toNumber = function toNumber () {
+ var ret = this.words[0];
+ if (this.length === 2) {
+ ret += this.words[1] * 0x4000000;
+ } else if (this.length === 3 && this.words[2] === 0x01) {
+ // NOTE: at this stage it is known that the top bit is set
+ ret += 0x10000000000000 + (this.words[1] * 0x4000000);
+ } else if (this.length > 2) {
+ assert(false, 'Number can only safely store up to 53 bits');
+ }
+ return (this.negative !== 0) ? -ret : ret;
+ };
+
+ BN.prototype.toJSON = function toJSON () {
+ return this.toString(16);
+ };
+
+ BN.prototype.toBuffer = function toBuffer (endian, length) {
+ assert(typeof Buffer !== 'undefined');
+ return this.toArrayLike(Buffer, endian, length);
+ };
+
+ BN.prototype.toArray = function toArray (endian, length) {
+ return this.toArrayLike(Array, endian, length);
+ };
+
+ BN.prototype.toArrayLike = function toArrayLike (ArrayType, endian, length) {
+ var byteLength = this.byteLength();
+ var reqLength = length || Math.max(1, byteLength);
+ assert(byteLength <= reqLength, 'byte array longer than desired length');
+ assert(reqLength > 0, 'Requested array length <= 0');
+
+ this.strip();
+ var littleEndian = endian === 'le';
+ var res = new ArrayType(reqLength);
+
+ var b, i;
+ var q = this.clone();
+ if (!littleEndian) {
+ // Assume big-endian
+ for (i = 0; i < reqLength - byteLength; i++) {
+ res[i] = 0;
+ }
+
+ for (i = 0; !q.isZero(); i++) {
+ b = q.andln(0xff);
+ q.iushrn(8);
+
+ res[reqLength - i - 1] = b;
+ }
+ } else {
+ for (i = 0; !q.isZero(); i++) {
+ b = q.andln(0xff);
+ q.iushrn(8);
+
+ res[i] = b;
+ }
+
+ for (; i < reqLength; i++) {
+ res[i] = 0;
+ }
+ }
+
+ return res;
+ };
+
+ if (Math.clz32) {
+ BN.prototype._countBits = function _countBits (w) {
+ return 32 - Math.clz32(w);
+ };
+ } else {
+ BN.prototype._countBits = function _countBits (w) {
+ var t = w;
+ var r = 0;
+ if (t >= 0x1000) {
+ r += 13;
+ t >>>= 13;
+ }
+ if (t >= 0x40) {
+ r += 7;
+ t >>>= 7;
+ }
+ if (t >= 0x8) {
+ r += 4;
+ t >>>= 4;
+ }
+ if (t >= 0x02) {
+ r += 2;
+ t >>>= 2;
+ }
+ return r + t;
+ };
+ }
+
+ BN.prototype._zeroBits = function _zeroBits (w) {
+ // Short-cut
+ if (w === 0) return 26;
+
+ var t = w;
+ var r = 0;
+ if ((t & 0x1fff) === 0) {
+ r += 13;
+ t >>>= 13;
+ }
+ if ((t & 0x7f) === 0) {
+ r += 7;
+ t >>>= 7;
+ }
+ if ((t & 0xf) === 0) {
+ r += 4;
+ t >>>= 4;
+ }
+ if ((t & 0x3) === 0) {
+ r += 2;
+ t >>>= 2;
+ }
+ if ((t & 0x1) === 0) {
+ r++;
+ }
+ return r;
+ };
+
+ // Return number of used bits in a BN
+ BN.prototype.bitLength = function bitLength () {
+ var w = this.words[this.length - 1];
+ var hi = this._countBits(w);
+ return (this.length - 1) * 26 + hi;
+ };
+
+ function toBitArray (num) {
+ var w = new Array(num.bitLength());
+
+ for (var bit = 0; bit < w.length; bit++) {
+ var off = (bit / 26) | 0;
+ var wbit = bit % 26;
+
+ w[bit] = (num.words[off] & (1 << wbit)) >>> wbit;
+ }
+
+ return w;
+ }
+
+ // Number of trailing zero bits
+ BN.prototype.zeroBits = function zeroBits () {
+ if (this.isZero()) return 0;
+
+ var r = 0;
+ for (var i = 0; i < this.length; i++) {
+ var b = this._zeroBits(this.words[i]);
+ r += b;
+ if (b !== 26) break;
+ }
+ return r;
+ };
+
+ BN.prototype.byteLength = function byteLength () {
+ return Math.ceil(this.bitLength() / 8);
+ };
+
+ BN.prototype.toTwos = function toTwos (width) {
+ if (this.negative !== 0) {
+ return this.abs().inotn(width).iaddn(1);
+ }
+ return this.clone();
+ };
+
+ BN.prototype.fromTwos = function fromTwos (width) {
+ if (this.testn(width - 1)) {
+ return this.notn(width).iaddn(1).ineg();
+ }
+ return this.clone();
+ };
+
+ BN.prototype.isNeg = function isNeg () {
+ return this.negative !== 0;
+ };
+
+ // Return negative clone of `this`
+ BN.prototype.neg = function neg () {
+ return this.clone().ineg();
+ };
+
+ BN.prototype.ineg = function ineg () {
+ if (!this.isZero()) {
+ this.negative ^= 1;
+ }
+
+ return this;
+ };
+
+ // Or `num` with `this` in-place
+ BN.prototype.iuor = function iuor (num) {
+ while (this.length < num.length) {
+ this.words[this.length++] = 0;
+ }
+
+ for (var i = 0; i < num.length; i++) {
+ this.words[i] = this.words[i] | num.words[i];
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ior = function ior (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuor(num);
+ };
+
+ // Or `num` with `this`
+ BN.prototype.or = function or (num) {
+ if (this.length > num.length) return this.clone().ior(num);
+ return num.clone().ior(this);
+ };
+
+ BN.prototype.uor = function uor (num) {
+ if (this.length > num.length) return this.clone().iuor(num);
+ return num.clone().iuor(this);
+ };
+
+ // And `num` with `this` in-place
+ BN.prototype.iuand = function iuand (num) {
+ // b = min-length(num, this)
+ var b;
+ if (this.length > num.length) {
+ b = num;
+ } else {
+ b = this;
+ }
+
+ for (var i = 0; i < b.length; i++) {
+ this.words[i] = this.words[i] & num.words[i];
+ }
+
+ this.length = b.length;
+
+ return this.strip();
+ };
+
+ BN.prototype.iand = function iand (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuand(num);
+ };
+
+ // And `num` with `this`
+ BN.prototype.and = function and (num) {
+ if (this.length > num.length) return this.clone().iand(num);
+ return num.clone().iand(this);
+ };
+
+ BN.prototype.uand = function uand (num) {
+ if (this.length > num.length) return this.clone().iuand(num);
+ return num.clone().iuand(this);
+ };
+
+ // Xor `num` with `this` in-place
+ BN.prototype.iuxor = function iuxor (num) {
+ // a.length > b.length
+ var a;
+ var b;
+ if (this.length > num.length) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ for (var i = 0; i < b.length; i++) {
+ this.words[i] = a.words[i] ^ b.words[i];
+ }
+
+ if (this !== a) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ this.length = a.length;
+
+ return this.strip();
+ };
+
+ BN.prototype.ixor = function ixor (num) {
+ assert((this.negative | num.negative) === 0);
+ return this.iuxor(num);
+ };
+
+ // Xor `num` with `this`
+ BN.prototype.xor = function xor (num) {
+ if (this.length > num.length) return this.clone().ixor(num);
+ return num.clone().ixor(this);
+ };
+
+ BN.prototype.uxor = function uxor (num) {
+ if (this.length > num.length) return this.clone().iuxor(num);
+ return num.clone().iuxor(this);
+ };
+
+ // Not ``this`` with ``width`` bitwidth
+ BN.prototype.inotn = function inotn (width) {
+ assert(typeof width === 'number' && width >= 0);
+
+ var bytesNeeded = Math.ceil(width / 26) | 0;
+ var bitsLeft = width % 26;
+
+ // Extend the buffer with leading zeroes
+ this._expand(bytesNeeded);
+
+ if (bitsLeft > 0) {
+ bytesNeeded--;
+ }
+
+ // Handle complete words
+ for (var i = 0; i < bytesNeeded; i++) {
+ this.words[i] = ~this.words[i] & 0x3ffffff;
+ }
+
+ // Handle the residue
+ if (bitsLeft > 0) {
+ this.words[i] = ~this.words[i] & (0x3ffffff >> (26 - bitsLeft));
+ }
+
+ // And remove leading zeroes
+ return this.strip();
+ };
+
+ BN.prototype.notn = function notn (width) {
+ return this.clone().inotn(width);
+ };
+
+ // Set `bit` of `this`
+ BN.prototype.setn = function setn (bit, val) {
+ assert(typeof bit === 'number' && bit >= 0);
+
+ var off = (bit / 26) | 0;
+ var wbit = bit % 26;
+
+ this._expand(off + 1);
+
+ if (val) {
+ this.words[off] = this.words[off] | (1 << wbit);
+ } else {
+ this.words[off] = this.words[off] & ~(1 << wbit);
+ }
+
+ return this.strip();
+ };
+
+ // Add `num` to `this` in-place
+ BN.prototype.iadd = function iadd (num) {
+ var r;
+
+ // negative + positive
+ if (this.negative !== 0 && num.negative === 0) {
+ this.negative = 0;
+ r = this.isub(num);
+ this.negative ^= 1;
+ return this._normSign();
+
+ // positive + negative
+ } else if (this.negative === 0 && num.negative !== 0) {
+ num.negative = 0;
+ r = this.isub(num);
+ num.negative = 1;
+ return r._normSign();
+ }
+
+ // a.length > b.length
+ var a, b;
+ if (this.length > num.length) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ var carry = 0;
+ for (var i = 0; i < b.length; i++) {
+ r = (a.words[i] | 0) + (b.words[i] | 0) + carry;
+ this.words[i] = r & 0x3ffffff;
+ carry = r >>> 26;
+ }
+ for (; carry !== 0 && i < a.length; i++) {
+ r = (a.words[i] | 0) + carry;
+ this.words[i] = r & 0x3ffffff;
+ carry = r >>> 26;
+ }
+
+ this.length = a.length;
+ if (carry !== 0) {
+ this.words[this.length] = carry;
+ this.length++;
+ // Copy the rest of the words
+ } else if (a !== this) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ return this;
+ };
+
+ // Add `num` to `this`
+ BN.prototype.add = function add (num) {
+ var res;
+ if (num.negative !== 0 && this.negative === 0) {
+ num.negative = 0;
+ res = this.sub(num);
+ num.negative ^= 1;
+ return res;
+ } else if (num.negative === 0 && this.negative !== 0) {
+ this.negative = 0;
+ res = num.sub(this);
+ this.negative = 1;
+ return res;
+ }
+
+ if (this.length > num.length) return this.clone().iadd(num);
+
+ return num.clone().iadd(this);
+ };
+
+ // Subtract `num` from `this` in-place
+ BN.prototype.isub = function isub (num) {
+ // this - (-num) = this + num
+ if (num.negative !== 0) {
+ num.negative = 0;
+ var r = this.iadd(num);
+ num.negative = 1;
+ return r._normSign();
+
+ // -this - num = -(this + num)
+ } else if (this.negative !== 0) {
+ this.negative = 0;
+ this.iadd(num);
+ this.negative = 1;
+ return this._normSign();
+ }
+
+ // At this point both numbers are positive
+ var cmp = this.cmp(num);
+
+ // Optimization - zeroify
+ if (cmp === 0) {
+ this.negative = 0;
+ this.length = 1;
+ this.words[0] = 0;
+ return this;
+ }
+
+ // a > b
+ var a, b;
+ if (cmp > 0) {
+ a = this;
+ b = num;
+ } else {
+ a = num;
+ b = this;
+ }
+
+ var carry = 0;
+ for (var i = 0; i < b.length; i++) {
+ r = (a.words[i] | 0) - (b.words[i] | 0) + carry;
+ carry = r >> 26;
+ this.words[i] = r & 0x3ffffff;
+ }
+ for (; carry !== 0 && i < a.length; i++) {
+ r = (a.words[i] | 0) + carry;
+ carry = r >> 26;
+ this.words[i] = r & 0x3ffffff;
+ }
+
+ // Copy rest of the words
+ if (carry === 0 && i < a.length && a !== this) {
+ for (; i < a.length; i++) {
+ this.words[i] = a.words[i];
+ }
+ }
+
+ this.length = Math.max(this.length, i);
+
+ if (a !== this) {
+ this.negative = 1;
+ }
+
+ return this.strip();
+ };
+
+ // Subtract `num` from `this`
+ BN.prototype.sub = function sub (num) {
+ return this.clone().isub(num);
+ };
+
+ function smallMulTo (self, num, out) {
+ out.negative = num.negative ^ self.negative;
+ var len = (self.length + num.length) | 0;
+ out.length = len;
+ len = (len - 1) | 0;
+
+ // Peel one iteration (compiler can't do it, because of code complexity)
+ var a = self.words[0] | 0;
+ var b = num.words[0] | 0;
+ var r = a * b;
+
+ var lo = r & 0x3ffffff;
+ var carry = (r / 0x4000000) | 0;
+ out.words[0] = lo;
+
+ for (var k = 1; k < len; k++) {
+ // Sum all words with the same `i + j = k` and accumulate `ncarry`,
+ // note that ncarry could be >= 0x3ffffff
+ var ncarry = carry >>> 26;
+ var rword = carry & 0x3ffffff;
+ var maxJ = Math.min(k, num.length - 1);
+ for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
+ var i = (k - j) | 0;
+ a = self.words[i] | 0;
+ b = num.words[j] | 0;
+ r = a * b + rword;
+ ncarry += (r / 0x4000000) | 0;
+ rword = r & 0x3ffffff;
+ }
+ out.words[k] = rword | 0;
+ carry = ncarry | 0;
+ }
+ if (carry !== 0) {
+ out.words[k] = carry | 0;
+ } else {
+ out.length--;
+ }
+
+ return out.strip();
+ }
+
+ // TODO(indutny): it may be reasonable to omit it for users who don't need
+ // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit
+ // multiplication (like elliptic secp256k1).
+ var comb10MulTo = function comb10MulTo (self, num, out) {
+ var a = self.words;
+ var b = num.words;
+ var o = out.words;
+ var c = 0;
+ var lo;
+ var mid;
+ var hi;
+ var a0 = a[0] | 0;
+ var al0 = a0 & 0x1fff;
+ var ah0 = a0 >>> 13;
+ var a1 = a[1] | 0;
+ var al1 = a1 & 0x1fff;
+ var ah1 = a1 >>> 13;
+ var a2 = a[2] | 0;
+ var al2 = a2 & 0x1fff;
+ var ah2 = a2 >>> 13;
+ var a3 = a[3] | 0;
+ var al3 = a3 & 0x1fff;
+ var ah3 = a3 >>> 13;
+ var a4 = a[4] | 0;
+ var al4 = a4 & 0x1fff;
+ var ah4 = a4 >>> 13;
+ var a5 = a[5] | 0;
+ var al5 = a5 & 0x1fff;
+ var ah5 = a5 >>> 13;
+ var a6 = a[6] | 0;
+ var al6 = a6 & 0x1fff;
+ var ah6 = a6 >>> 13;
+ var a7 = a[7] | 0;
+ var al7 = a7 & 0x1fff;
+ var ah7 = a7 >>> 13;
+ var a8 = a[8] | 0;
+ var al8 = a8 & 0x1fff;
+ var ah8 = a8 >>> 13;
+ var a9 = a[9] | 0;
+ var al9 = a9 & 0x1fff;
+ var ah9 = a9 >>> 13;
+ var b0 = b[0] | 0;
+ var bl0 = b0 & 0x1fff;
+ var bh0 = b0 >>> 13;
+ var b1 = b[1] | 0;
+ var bl1 = b1 & 0x1fff;
+ var bh1 = b1 >>> 13;
+ var b2 = b[2] | 0;
+ var bl2 = b2 & 0x1fff;
+ var bh2 = b2 >>> 13;
+ var b3 = b[3] | 0;
+ var bl3 = b3 & 0x1fff;
+ var bh3 = b3 >>> 13;
+ var b4 = b[4] | 0;
+ var bl4 = b4 & 0x1fff;
+ var bh4 = b4 >>> 13;
+ var b5 = b[5] | 0;
+ var bl5 = b5 & 0x1fff;
+ var bh5 = b5 >>> 13;
+ var b6 = b[6] | 0;
+ var bl6 = b6 & 0x1fff;
+ var bh6 = b6 >>> 13;
+ var b7 = b[7] | 0;
+ var bl7 = b7 & 0x1fff;
+ var bh7 = b7 >>> 13;
+ var b8 = b[8] | 0;
+ var bl8 = b8 & 0x1fff;
+ var bh8 = b8 >>> 13;
+ var b9 = b[9] | 0;
+ var bl9 = b9 & 0x1fff;
+ var bh9 = b9 >>> 13;
+
+ out.negative = self.negative ^ num.negative;
+ out.length = 19;
+ /* k = 0 */
+ lo = Math.imul(al0, bl0);
+ mid = Math.imul(al0, bh0);
+ mid = (mid + Math.imul(ah0, bl0)) | 0;
+ hi = Math.imul(ah0, bh0);
+ var w0 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w0 >>> 26)) | 0;
+ w0 &= 0x3ffffff;
+ /* k = 1 */
+ lo = Math.imul(al1, bl0);
+ mid = Math.imul(al1, bh0);
+ mid = (mid + Math.imul(ah1, bl0)) | 0;
+ hi = Math.imul(ah1, bh0);
+ lo = (lo + Math.imul(al0, bl1)) | 0;
+ mid = (mid + Math.imul(al0, bh1)) | 0;
+ mid = (mid + Math.imul(ah0, bl1)) | 0;
+ hi = (hi + Math.imul(ah0, bh1)) | 0;
+ var w1 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w1 >>> 26)) | 0;
+ w1 &= 0x3ffffff;
+ /* k = 2 */
+ lo = Math.imul(al2, bl0);
+ mid = Math.imul(al2, bh0);
+ mid = (mid + Math.imul(ah2, bl0)) | 0;
+ hi = Math.imul(ah2, bh0);
+ lo = (lo + Math.imul(al1, bl1)) | 0;
+ mid = (mid + Math.imul(al1, bh1)) | 0;
+ mid = (mid + Math.imul(ah1, bl1)) | 0;
+ hi = (hi + Math.imul(ah1, bh1)) | 0;
+ lo = (lo + Math.imul(al0, bl2)) | 0;
+ mid = (mid + Math.imul(al0, bh2)) | 0;
+ mid = (mid + Math.imul(ah0, bl2)) | 0;
+ hi = (hi + Math.imul(ah0, bh2)) | 0;
+ var w2 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w2 >>> 26)) | 0;
+ w2 &= 0x3ffffff;
+ /* k = 3 */
+ lo = Math.imul(al3, bl0);
+ mid = Math.imul(al3, bh0);
+ mid = (mid + Math.imul(ah3, bl0)) | 0;
+ hi = Math.imul(ah3, bh0);
+ lo = (lo + Math.imul(al2, bl1)) | 0;
+ mid = (mid + Math.imul(al2, bh1)) | 0;
+ mid = (mid + Math.imul(ah2, bl1)) | 0;
+ hi = (hi + Math.imul(ah2, bh1)) | 0;
+ lo = (lo + Math.imul(al1, bl2)) | 0;
+ mid = (mid + Math.imul(al1, bh2)) | 0;
+ mid = (mid + Math.imul(ah1, bl2)) | 0;
+ hi = (hi + Math.imul(ah1, bh2)) | 0;
+ lo = (lo + Math.imul(al0, bl3)) | 0;
+ mid = (mid + Math.imul(al0, bh3)) | 0;
+ mid = (mid + Math.imul(ah0, bl3)) | 0;
+ hi = (hi + Math.imul(ah0, bh3)) | 0;
+ var w3 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w3 >>> 26)) | 0;
+ w3 &= 0x3ffffff;
+ /* k = 4 */
+ lo = Math.imul(al4, bl0);
+ mid = Math.imul(al4, bh0);
+ mid = (mid + Math.imul(ah4, bl0)) | 0;
+ hi = Math.imul(ah4, bh0);
+ lo = (lo + Math.imul(al3, bl1)) | 0;
+ mid = (mid + Math.imul(al3, bh1)) | 0;
+ mid = (mid + Math.imul(ah3, bl1)) | 0;
+ hi = (hi + Math.imul(ah3, bh1)) | 0;
+ lo = (lo + Math.imul(al2, bl2)) | 0;
+ mid = (mid + Math.imul(al2, bh2)) | 0;
+ mid = (mid + Math.imul(ah2, bl2)) | 0;
+ hi = (hi + Math.imul(ah2, bh2)) | 0;
+ lo = (lo + Math.imul(al1, bl3)) | 0;
+ mid = (mid + Math.imul(al1, bh3)) | 0;
+ mid = (mid + Math.imul(ah1, bl3)) | 0;
+ hi = (hi + Math.imul(ah1, bh3)) | 0;
+ lo = (lo + Math.imul(al0, bl4)) | 0;
+ mid = (mid + Math.imul(al0, bh4)) | 0;
+ mid = (mid + Math.imul(ah0, bl4)) | 0;
+ hi = (hi + Math.imul(ah0, bh4)) | 0;
+ var w4 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w4 >>> 26)) | 0;
+ w4 &= 0x3ffffff;
+ /* k = 5 */
+ lo = Math.imul(al5, bl0);
+ mid = Math.imul(al5, bh0);
+ mid = (mid + Math.imul(ah5, bl0)) | 0;
+ hi = Math.imul(ah5, bh0);
+ lo = (lo + Math.imul(al4, bl1)) | 0;
+ mid = (mid + Math.imul(al4, bh1)) | 0;
+ mid = (mid + Math.imul(ah4, bl1)) | 0;
+ hi = (hi + Math.imul(ah4, bh1)) | 0;
+ lo = (lo + Math.imul(al3, bl2)) | 0;
+ mid = (mid + Math.imul(al3, bh2)) | 0;
+ mid = (mid + Math.imul(ah3, bl2)) | 0;
+ hi = (hi + Math.imul(ah3, bh2)) | 0;
+ lo = (lo + Math.imul(al2, bl3)) | 0;
+ mid = (mid + Math.imul(al2, bh3)) | 0;
+ mid = (mid + Math.imul(ah2, bl3)) | 0;
+ hi = (hi + Math.imul(ah2, bh3)) | 0;
+ lo = (lo + Math.imul(al1, bl4)) | 0;
+ mid = (mid + Math.imul(al1, bh4)) | 0;
+ mid = (mid + Math.imul(ah1, bl4)) | 0;
+ hi = (hi + Math.imul(ah1, bh4)) | 0;
+ lo = (lo + Math.imul(al0, bl5)) | 0;
+ mid = (mid + Math.imul(al0, bh5)) | 0;
+ mid = (mid + Math.imul(ah0, bl5)) | 0;
+ hi = (hi + Math.imul(ah0, bh5)) | 0;
+ var w5 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w5 >>> 26)) | 0;
+ w5 &= 0x3ffffff;
+ /* k = 6 */
+ lo = Math.imul(al6, bl0);
+ mid = Math.imul(al6, bh0);
+ mid = (mid + Math.imul(ah6, bl0)) | 0;
+ hi = Math.imul(ah6, bh0);
+ lo = (lo + Math.imul(al5, bl1)) | 0;
+ mid = (mid + Math.imul(al5, bh1)) | 0;
+ mid = (mid + Math.imul(ah5, bl1)) | 0;
+ hi = (hi + Math.imul(ah5, bh1)) | 0;
+ lo = (lo + Math.imul(al4, bl2)) | 0;
+ mid = (mid + Math.imul(al4, bh2)) | 0;
+ mid = (mid + Math.imul(ah4, bl2)) | 0;
+ hi = (hi + Math.imul(ah4, bh2)) | 0;
+ lo = (lo + Math.imul(al3, bl3)) | 0;
+ mid = (mid + Math.imul(al3, bh3)) | 0;
+ mid = (mid + Math.imul(ah3, bl3)) | 0;
+ hi = (hi + Math.imul(ah3, bh3)) | 0;
+ lo = (lo + Math.imul(al2, bl4)) | 0;
+ mid = (mid + Math.imul(al2, bh4)) | 0;
+ mid = (mid + Math.imul(ah2, bl4)) | 0;
+ hi = (hi + Math.imul(ah2, bh4)) | 0;
+ lo = (lo + Math.imul(al1, bl5)) | 0;
+ mid = (mid + Math.imul(al1, bh5)) | 0;
+ mid = (mid + Math.imul(ah1, bl5)) | 0;
+ hi = (hi + Math.imul(ah1, bh5)) | 0;
+ lo = (lo + Math.imul(al0, bl6)) | 0;
+ mid = (mid + Math.imul(al0, bh6)) | 0;
+ mid = (mid + Math.imul(ah0, bl6)) | 0;
+ hi = (hi + Math.imul(ah0, bh6)) | 0;
+ var w6 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w6 >>> 26)) | 0;
+ w6 &= 0x3ffffff;
+ /* k = 7 */
+ lo = Math.imul(al7, bl0);
+ mid = Math.imul(al7, bh0);
+ mid = (mid + Math.imul(ah7, bl0)) | 0;
+ hi = Math.imul(ah7, bh0);
+ lo = (lo + Math.imul(al6, bl1)) | 0;
+ mid = (mid + Math.imul(al6, bh1)) | 0;
+ mid = (mid + Math.imul(ah6, bl1)) | 0;
+ hi = (hi + Math.imul(ah6, bh1)) | 0;
+ lo = (lo + Math.imul(al5, bl2)) | 0;
+ mid = (mid + Math.imul(al5, bh2)) | 0;
+ mid = (mid + Math.imul(ah5, bl2)) | 0;
+ hi = (hi + Math.imul(ah5, bh2)) | 0;
+ lo = (lo + Math.imul(al4, bl3)) | 0;
+ mid = (mid + Math.imul(al4, bh3)) | 0;
+ mid = (mid + Math.imul(ah4, bl3)) | 0;
+ hi = (hi + Math.imul(ah4, bh3)) | 0;
+ lo = (lo + Math.imul(al3, bl4)) | 0;
+ mid = (mid + Math.imul(al3, bh4)) | 0;
+ mid = (mid + Math.imul(ah3, bl4)) | 0;
+ hi = (hi + Math.imul(ah3, bh4)) | 0;
+ lo = (lo + Math.imul(al2, bl5)) | 0;
+ mid = (mid + Math.imul(al2, bh5)) | 0;
+ mid = (mid + Math.imul(ah2, bl5)) | 0;
+ hi = (hi + Math.imul(ah2, bh5)) | 0;
+ lo = (lo + Math.imul(al1, bl6)) | 0;
+ mid = (mid + Math.imul(al1, bh6)) | 0;
+ mid = (mid + Math.imul(ah1, bl6)) | 0;
+ hi = (hi + Math.imul(ah1, bh6)) | 0;
+ lo = (lo + Math.imul(al0, bl7)) | 0;
+ mid = (mid + Math.imul(al0, bh7)) | 0;
+ mid = (mid + Math.imul(ah0, bl7)) | 0;
+ hi = (hi + Math.imul(ah0, bh7)) | 0;
+ var w7 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w7 >>> 26)) | 0;
+ w7 &= 0x3ffffff;
+ /* k = 8 */
+ lo = Math.imul(al8, bl0);
+ mid = Math.imul(al8, bh0);
+ mid = (mid + Math.imul(ah8, bl0)) | 0;
+ hi = Math.imul(ah8, bh0);
+ lo = (lo + Math.imul(al7, bl1)) | 0;
+ mid = (mid + Math.imul(al7, bh1)) | 0;
+ mid = (mid + Math.imul(ah7, bl1)) | 0;
+ hi = (hi + Math.imul(ah7, bh1)) | 0;
+ lo = (lo + Math.imul(al6, bl2)) | 0;
+ mid = (mid + Math.imul(al6, bh2)) | 0;
+ mid = (mid + Math.imul(ah6, bl2)) | 0;
+ hi = (hi + Math.imul(ah6, bh2)) | 0;
+ lo = (lo + Math.imul(al5, bl3)) | 0;
+ mid = (mid + Math.imul(al5, bh3)) | 0;
+ mid = (mid + Math.imul(ah5, bl3)) | 0;
+ hi = (hi + Math.imul(ah5, bh3)) | 0;
+ lo = (lo + Math.imul(al4, bl4)) | 0;
+ mid = (mid + Math.imul(al4, bh4)) | 0;
+ mid = (mid + Math.imul(ah4, bl4)) | 0;
+ hi = (hi + Math.imul(ah4, bh4)) | 0;
+ lo = (lo + Math.imul(al3, bl5)) | 0;
+ mid = (mid + Math.imul(al3, bh5)) | 0;
+ mid = (mid + Math.imul(ah3, bl5)) | 0;
+ hi = (hi + Math.imul(ah3, bh5)) | 0;
+ lo = (lo + Math.imul(al2, bl6)) | 0;
+ mid = (mid + Math.imul(al2, bh6)) | 0;
+ mid = (mid + Math.imul(ah2, bl6)) | 0;
+ hi = (hi + Math.imul(ah2, bh6)) | 0;
+ lo = (lo + Math.imul(al1, bl7)) | 0;
+ mid = (mid + Math.imul(al1, bh7)) | 0;
+ mid = (mid + Math.imul(ah1, bl7)) | 0;
+ hi = (hi + Math.imul(ah1, bh7)) | 0;
+ lo = (lo + Math.imul(al0, bl8)) | 0;
+ mid = (mid + Math.imul(al0, bh8)) | 0;
+ mid = (mid + Math.imul(ah0, bl8)) | 0;
+ hi = (hi + Math.imul(ah0, bh8)) | 0;
+ var w8 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w8 >>> 26)) | 0;
+ w8 &= 0x3ffffff;
+ /* k = 9 */
+ lo = Math.imul(al9, bl0);
+ mid = Math.imul(al9, bh0);
+ mid = (mid + Math.imul(ah9, bl0)) | 0;
+ hi = Math.imul(ah9, bh0);
+ lo = (lo + Math.imul(al8, bl1)) | 0;
+ mid = (mid + Math.imul(al8, bh1)) | 0;
+ mid = (mid + Math.imul(ah8, bl1)) | 0;
+ hi = (hi + Math.imul(ah8, bh1)) | 0;
+ lo = (lo + Math.imul(al7, bl2)) | 0;
+ mid = (mid + Math.imul(al7, bh2)) | 0;
+ mid = (mid + Math.imul(ah7, bl2)) | 0;
+ hi = (hi + Math.imul(ah7, bh2)) | 0;
+ lo = (lo + Math.imul(al6, bl3)) | 0;
+ mid = (mid + Math.imul(al6, bh3)) | 0;
+ mid = (mid + Math.imul(ah6, bl3)) | 0;
+ hi = (hi + Math.imul(ah6, bh3)) | 0;
+ lo = (lo + Math.imul(al5, bl4)) | 0;
+ mid = (mid + Math.imul(al5, bh4)) | 0;
+ mid = (mid + Math.imul(ah5, bl4)) | 0;
+ hi = (hi + Math.imul(ah5, bh4)) | 0;
+ lo = (lo + Math.imul(al4, bl5)) | 0;
+ mid = (mid + Math.imul(al4, bh5)) | 0;
+ mid = (mid + Math.imul(ah4, bl5)) | 0;
+ hi = (hi + Math.imul(ah4, bh5)) | 0;
+ lo = (lo + Math.imul(al3, bl6)) | 0;
+ mid = (mid + Math.imul(al3, bh6)) | 0;
+ mid = (mid + Math.imul(ah3, bl6)) | 0;
+ hi = (hi + Math.imul(ah3, bh6)) | 0;
+ lo = (lo + Math.imul(al2, bl7)) | 0;
+ mid = (mid + Math.imul(al2, bh7)) | 0;
+ mid = (mid + Math.imul(ah2, bl7)) | 0;
+ hi = (hi + Math.imul(ah2, bh7)) | 0;
+ lo = (lo + Math.imul(al1, bl8)) | 0;
+ mid = (mid + Math.imul(al1, bh8)) | 0;
+ mid = (mid + Math.imul(ah1, bl8)) | 0;
+ hi = (hi + Math.imul(ah1, bh8)) | 0;
+ lo = (lo + Math.imul(al0, bl9)) | 0;
+ mid = (mid + Math.imul(al0, bh9)) | 0;
+ mid = (mid + Math.imul(ah0, bl9)) | 0;
+ hi = (hi + Math.imul(ah0, bh9)) | 0;
+ var w9 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w9 >>> 26)) | 0;
+ w9 &= 0x3ffffff;
+ /* k = 10 */
+ lo = Math.imul(al9, bl1);
+ mid = Math.imul(al9, bh1);
+ mid = (mid + Math.imul(ah9, bl1)) | 0;
+ hi = Math.imul(ah9, bh1);
+ lo = (lo + Math.imul(al8, bl2)) | 0;
+ mid = (mid + Math.imul(al8, bh2)) | 0;
+ mid = (mid + Math.imul(ah8, bl2)) | 0;
+ hi = (hi + Math.imul(ah8, bh2)) | 0;
+ lo = (lo + Math.imul(al7, bl3)) | 0;
+ mid = (mid + Math.imul(al7, bh3)) | 0;
+ mid = (mid + Math.imul(ah7, bl3)) | 0;
+ hi = (hi + Math.imul(ah7, bh3)) | 0;
+ lo = (lo + Math.imul(al6, bl4)) | 0;
+ mid = (mid + Math.imul(al6, bh4)) | 0;
+ mid = (mid + Math.imul(ah6, bl4)) | 0;
+ hi = (hi + Math.imul(ah6, bh4)) | 0;
+ lo = (lo + Math.imul(al5, bl5)) | 0;
+ mid = (mid + Math.imul(al5, bh5)) | 0;
+ mid = (mid + Math.imul(ah5, bl5)) | 0;
+ hi = (hi + Math.imul(ah5, bh5)) | 0;
+ lo = (lo + Math.imul(al4, bl6)) | 0;
+ mid = (mid + Math.imul(al4, bh6)) | 0;
+ mid = (mid + Math.imul(ah4, bl6)) | 0;
+ hi = (hi + Math.imul(ah4, bh6)) | 0;
+ lo = (lo + Math.imul(al3, bl7)) | 0;
+ mid = (mid + Math.imul(al3, bh7)) | 0;
+ mid = (mid + Math.imul(ah3, bl7)) | 0;
+ hi = (hi + Math.imul(ah3, bh7)) | 0;
+ lo = (lo + Math.imul(al2, bl8)) | 0;
+ mid = (mid + Math.imul(al2, bh8)) | 0;
+ mid = (mid + Math.imul(ah2, bl8)) | 0;
+ hi = (hi + Math.imul(ah2, bh8)) | 0;
+ lo = (lo + Math.imul(al1, bl9)) | 0;
+ mid = (mid + Math.imul(al1, bh9)) | 0;
+ mid = (mid + Math.imul(ah1, bl9)) | 0;
+ hi = (hi + Math.imul(ah1, bh9)) | 0;
+ var w10 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w10 >>> 26)) | 0;
+ w10 &= 0x3ffffff;
+ /* k = 11 */
+ lo = Math.imul(al9, bl2);
+ mid = Math.imul(al9, bh2);
+ mid = (mid + Math.imul(ah9, bl2)) | 0;
+ hi = Math.imul(ah9, bh2);
+ lo = (lo + Math.imul(al8, bl3)) | 0;
+ mid = (mid + Math.imul(al8, bh3)) | 0;
+ mid = (mid + Math.imul(ah8, bl3)) | 0;
+ hi = (hi + Math.imul(ah8, bh3)) | 0;
+ lo = (lo + Math.imul(al7, bl4)) | 0;
+ mid = (mid + Math.imul(al7, bh4)) | 0;
+ mid = (mid + Math.imul(ah7, bl4)) | 0;
+ hi = (hi + Math.imul(ah7, bh4)) | 0;
+ lo = (lo + Math.imul(al6, bl5)) | 0;
+ mid = (mid + Math.imul(al6, bh5)) | 0;
+ mid = (mid + Math.imul(ah6, bl5)) | 0;
+ hi = (hi + Math.imul(ah6, bh5)) | 0;
+ lo = (lo + Math.imul(al5, bl6)) | 0;
+ mid = (mid + Math.imul(al5, bh6)) | 0;
+ mid = (mid + Math.imul(ah5, bl6)) | 0;
+ hi = (hi + Math.imul(ah5, bh6)) | 0;
+ lo = (lo + Math.imul(al4, bl7)) | 0;
+ mid = (mid + Math.imul(al4, bh7)) | 0;
+ mid = (mid + Math.imul(ah4, bl7)) | 0;
+ hi = (hi + Math.imul(ah4, bh7)) | 0;
+ lo = (lo + Math.imul(al3, bl8)) | 0;
+ mid = (mid + Math.imul(al3, bh8)) | 0;
+ mid = (mid + Math.imul(ah3, bl8)) | 0;
+ hi = (hi + Math.imul(ah3, bh8)) | 0;
+ lo = (lo + Math.imul(al2, bl9)) | 0;
+ mid = (mid + Math.imul(al2, bh9)) | 0;
+ mid = (mid + Math.imul(ah2, bl9)) | 0;
+ hi = (hi + Math.imul(ah2, bh9)) | 0;
+ var w11 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w11 >>> 26)) | 0;
+ w11 &= 0x3ffffff;
+ /* k = 12 */
+ lo = Math.imul(al9, bl3);
+ mid = Math.imul(al9, bh3);
+ mid = (mid + Math.imul(ah9, bl3)) | 0;
+ hi = Math.imul(ah9, bh3);
+ lo = (lo + Math.imul(al8, bl4)) | 0;
+ mid = (mid + Math.imul(al8, bh4)) | 0;
+ mid = (mid + Math.imul(ah8, bl4)) | 0;
+ hi = (hi + Math.imul(ah8, bh4)) | 0;
+ lo = (lo + Math.imul(al7, bl5)) | 0;
+ mid = (mid + Math.imul(al7, bh5)) | 0;
+ mid = (mid + Math.imul(ah7, bl5)) | 0;
+ hi = (hi + Math.imul(ah7, bh5)) | 0;
+ lo = (lo + Math.imul(al6, bl6)) | 0;
+ mid = (mid + Math.imul(al6, bh6)) | 0;
+ mid = (mid + Math.imul(ah6, bl6)) | 0;
+ hi = (hi + Math.imul(ah6, bh6)) | 0;
+ lo = (lo + Math.imul(al5, bl7)) | 0;
+ mid = (mid + Math.imul(al5, bh7)) | 0;
+ mid = (mid + Math.imul(ah5, bl7)) | 0;
+ hi = (hi + Math.imul(ah5, bh7)) | 0;
+ lo = (lo + Math.imul(al4, bl8)) | 0;
+ mid = (mid + Math.imul(al4, bh8)) | 0;
+ mid = (mid + Math.imul(ah4, bl8)) | 0;
+ hi = (hi + Math.imul(ah4, bh8)) | 0;
+ lo = (lo + Math.imul(al3, bl9)) | 0;
+ mid = (mid + Math.imul(al3, bh9)) | 0;
+ mid = (mid + Math.imul(ah3, bl9)) | 0;
+ hi = (hi + Math.imul(ah3, bh9)) | 0;
+ var w12 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w12 >>> 26)) | 0;
+ w12 &= 0x3ffffff;
+ /* k = 13 */
+ lo = Math.imul(al9, bl4);
+ mid = Math.imul(al9, bh4);
+ mid = (mid + Math.imul(ah9, bl4)) | 0;
+ hi = Math.imul(ah9, bh4);
+ lo = (lo + Math.imul(al8, bl5)) | 0;
+ mid = (mid + Math.imul(al8, bh5)) | 0;
+ mid = (mid + Math.imul(ah8, bl5)) | 0;
+ hi = (hi + Math.imul(ah8, bh5)) | 0;
+ lo = (lo + Math.imul(al7, bl6)) | 0;
+ mid = (mid + Math.imul(al7, bh6)) | 0;
+ mid = (mid + Math.imul(ah7, bl6)) | 0;
+ hi = (hi + Math.imul(ah7, bh6)) | 0;
+ lo = (lo + Math.imul(al6, bl7)) | 0;
+ mid = (mid + Math.imul(al6, bh7)) | 0;
+ mid = (mid + Math.imul(ah6, bl7)) | 0;
+ hi = (hi + Math.imul(ah6, bh7)) | 0;
+ lo = (lo + Math.imul(al5, bl8)) | 0;
+ mid = (mid + Math.imul(al5, bh8)) | 0;
+ mid = (mid + Math.imul(ah5, bl8)) | 0;
+ hi = (hi + Math.imul(ah5, bh8)) | 0;
+ lo = (lo + Math.imul(al4, bl9)) | 0;
+ mid = (mid + Math.imul(al4, bh9)) | 0;
+ mid = (mid + Math.imul(ah4, bl9)) | 0;
+ hi = (hi + Math.imul(ah4, bh9)) | 0;
+ var w13 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w13 >>> 26)) | 0;
+ w13 &= 0x3ffffff;
+ /* k = 14 */
+ lo = Math.imul(al9, bl5);
+ mid = Math.imul(al9, bh5);
+ mid = (mid + Math.imul(ah9, bl5)) | 0;
+ hi = Math.imul(ah9, bh5);
+ lo = (lo + Math.imul(al8, bl6)) | 0;
+ mid = (mid + Math.imul(al8, bh6)) | 0;
+ mid = (mid + Math.imul(ah8, bl6)) | 0;
+ hi = (hi + Math.imul(ah8, bh6)) | 0;
+ lo = (lo + Math.imul(al7, bl7)) | 0;
+ mid = (mid + Math.imul(al7, bh7)) | 0;
+ mid = (mid + Math.imul(ah7, bl7)) | 0;
+ hi = (hi + Math.imul(ah7, bh7)) | 0;
+ lo = (lo + Math.imul(al6, bl8)) | 0;
+ mid = (mid + Math.imul(al6, bh8)) | 0;
+ mid = (mid + Math.imul(ah6, bl8)) | 0;
+ hi = (hi + Math.imul(ah6, bh8)) | 0;
+ lo = (lo + Math.imul(al5, bl9)) | 0;
+ mid = (mid + Math.imul(al5, bh9)) | 0;
+ mid = (mid + Math.imul(ah5, bl9)) | 0;
+ hi = (hi + Math.imul(ah5, bh9)) | 0;
+ var w14 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w14 >>> 26)) | 0;
+ w14 &= 0x3ffffff;
+ /* k = 15 */
+ lo = Math.imul(al9, bl6);
+ mid = Math.imul(al9, bh6);
+ mid = (mid + Math.imul(ah9, bl6)) | 0;
+ hi = Math.imul(ah9, bh6);
+ lo = (lo + Math.imul(al8, bl7)) | 0;
+ mid = (mid + Math.imul(al8, bh7)) | 0;
+ mid = (mid + Math.imul(ah8, bl7)) | 0;
+ hi = (hi + Math.imul(ah8, bh7)) | 0;
+ lo = (lo + Math.imul(al7, bl8)) | 0;
+ mid = (mid + Math.imul(al7, bh8)) | 0;
+ mid = (mid + Math.imul(ah7, bl8)) | 0;
+ hi = (hi + Math.imul(ah7, bh8)) | 0;
+ lo = (lo + Math.imul(al6, bl9)) | 0;
+ mid = (mid + Math.imul(al6, bh9)) | 0;
+ mid = (mid + Math.imul(ah6, bl9)) | 0;
+ hi = (hi + Math.imul(ah6, bh9)) | 0;
+ var w15 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w15 >>> 26)) | 0;
+ w15 &= 0x3ffffff;
+ /* k = 16 */
+ lo = Math.imul(al9, bl7);
+ mid = Math.imul(al9, bh7);
+ mid = (mid + Math.imul(ah9, bl7)) | 0;
+ hi = Math.imul(ah9, bh7);
+ lo = (lo + Math.imul(al8, bl8)) | 0;
+ mid = (mid + Math.imul(al8, bh8)) | 0;
+ mid = (mid + Math.imul(ah8, bl8)) | 0;
+ hi = (hi + Math.imul(ah8, bh8)) | 0;
+ lo = (lo + Math.imul(al7, bl9)) | 0;
+ mid = (mid + Math.imul(al7, bh9)) | 0;
+ mid = (mid + Math.imul(ah7, bl9)) | 0;
+ hi = (hi + Math.imul(ah7, bh9)) | 0;
+ var w16 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w16 >>> 26)) | 0;
+ w16 &= 0x3ffffff;
+ /* k = 17 */
+ lo = Math.imul(al9, bl8);
+ mid = Math.imul(al9, bh8);
+ mid = (mid + Math.imul(ah9, bl8)) | 0;
+ hi = Math.imul(ah9, bh8);
+ lo = (lo + Math.imul(al8, bl9)) | 0;
+ mid = (mid + Math.imul(al8, bh9)) | 0;
+ mid = (mid + Math.imul(ah8, bl9)) | 0;
+ hi = (hi + Math.imul(ah8, bh9)) | 0;
+ var w17 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w17 >>> 26)) | 0;
+ w17 &= 0x3ffffff;
+ /* k = 18 */
+ lo = Math.imul(al9, bl9);
+ mid = Math.imul(al9, bh9);
+ mid = (mid + Math.imul(ah9, bl9)) | 0;
+ hi = Math.imul(ah9, bh9);
+ var w18 = (((c + lo) | 0) + ((mid & 0x1fff) << 13)) | 0;
+ c = (((hi + (mid >>> 13)) | 0) + (w18 >>> 26)) | 0;
+ w18 &= 0x3ffffff;
+ o[0] = w0;
+ o[1] = w1;
+ o[2] = w2;
+ o[3] = w3;
+ o[4] = w4;
+ o[5] = w5;
+ o[6] = w6;
+ o[7] = w7;
+ o[8] = w8;
+ o[9] = w9;
+ o[10] = w10;
+ o[11] = w11;
+ o[12] = w12;
+ o[13] = w13;
+ o[14] = w14;
+ o[15] = w15;
+ o[16] = w16;
+ o[17] = w17;
+ o[18] = w18;
+ if (c !== 0) {
+ o[19] = c;
+ out.length++;
+ }
+ return out;
+ };
+
+ // Polyfill comb
+ if (!Math.imul) {
+ comb10MulTo = smallMulTo;
+ }
+
+ function bigMulTo (self, num, out) {
+ out.negative = num.negative ^ self.negative;
+ out.length = self.length + num.length;
+
+ var carry = 0;
+ var hncarry = 0;
+ for (var k = 0; k < out.length - 1; k++) {
+ // Sum all words with the same `i + j = k` and accumulate `ncarry`,
+ // note that ncarry could be >= 0x3ffffff
+ var ncarry = hncarry;
+ hncarry = 0;
+ var rword = carry & 0x3ffffff;
+ var maxJ = Math.min(k, num.length - 1);
+ for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) {
+ var i = k - j;
+ var a = self.words[i] | 0;
+ var b = num.words[j] | 0;
+ var r = a * b;
+
+ var lo = r & 0x3ffffff;
+ ncarry = (ncarry + ((r / 0x4000000) | 0)) | 0;
+ lo = (lo + rword) | 0;
+ rword = lo & 0x3ffffff;
+ ncarry = (ncarry + (lo >>> 26)) | 0;
+
+ hncarry += ncarry >>> 26;
+ ncarry &= 0x3ffffff;
+ }
+ out.words[k] = rword;
+ carry = ncarry;
+ ncarry = hncarry;
+ }
+ if (carry !== 0) {
+ out.words[k] = carry;
+ } else {
+ out.length--;
+ }
+
+ return out.strip();
+ }
+
+ function jumboMulTo (self, num, out) {
+ var fftm = new FFTM();
+ return fftm.mulp(self, num, out);
+ }
+
+ BN.prototype.mulTo = function mulTo (num, out) {
+ var res;
+ var len = this.length + num.length;
+ if (this.length === 10 && num.length === 10) {
+ res = comb10MulTo(this, num, out);
+ } else if (len < 63) {
+ res = smallMulTo(this, num, out);
+ } else if (len < 1024) {
+ res = bigMulTo(this, num, out);
+ } else {
+ res = jumboMulTo(this, num, out);
+ }
+
+ return res;
+ };
+
+ // Cooley-Tukey algorithm for FFT
+ // slightly revisited to rely on looping instead of recursion
+
+ function FFTM (x, y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ FFTM.prototype.makeRBT = function makeRBT (N) {
+ var t = new Array(N);
+ var l = BN.prototype._countBits(N) - 1;
+ for (var i = 0; i < N; i++) {
+ t[i] = this.revBin(i, l, N);
+ }
+
+ return t;
+ };
+
+ // Returns binary-reversed representation of `x`
+ FFTM.prototype.revBin = function revBin (x, l, N) {
+ if (x === 0 || x === N - 1) return x;
+
+ var rb = 0;
+ for (var i = 0; i < l; i++) {
+ rb |= (x & 1) << (l - i - 1);
+ x >>= 1;
+ }
+
+ return rb;
+ };
+
+ // Performs "tweedling" phase, therefore 'emulating'
+ // behaviour of the recursive algorithm
+ FFTM.prototype.permute = function permute (rbt, rws, iws, rtws, itws, N) {
+ for (var i = 0; i < N; i++) {
+ rtws[i] = rws[rbt[i]];
+ itws[i] = iws[rbt[i]];
+ }
+ };
+
+ FFTM.prototype.transform = function transform (rws, iws, rtws, itws, N, rbt) {
+ this.permute(rbt, rws, iws, rtws, itws, N);
+
+ for (var s = 1; s < N; s <<= 1) {
+ var l = s << 1;
+
+ var rtwdf = Math.cos(2 * Math.PI / l);
+ var itwdf = Math.sin(2 * Math.PI / l);
+
+ for (var p = 0; p < N; p += l) {
+ var rtwdf_ = rtwdf;
+ var itwdf_ = itwdf;
+
+ for (var j = 0; j < s; j++) {
+ var re = rtws[p + j];
+ var ie = itws[p + j];
+
+ var ro = rtws[p + j + s];
+ var io = itws[p + j + s];
+
+ var rx = rtwdf_ * ro - itwdf_ * io;
+
+ io = rtwdf_ * io + itwdf_ * ro;
+ ro = rx;
+
+ rtws[p + j] = re + ro;
+ itws[p + j] = ie + io;
+
+ rtws[p + j + s] = re - ro;
+ itws[p + j + s] = ie - io;
+
+ /* jshint maxdepth : false */
+ if (j !== l) {
+ rx = rtwdf * rtwdf_ - itwdf * itwdf_;
+
+ itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_;
+ rtwdf_ = rx;
+ }
+ }
+ }
+ }
+ };
+
+ FFTM.prototype.guessLen13b = function guessLen13b (n, m) {
+ var N = Math.max(m, n) | 1;
+ var odd = N & 1;
+ var i = 0;
+ for (N = N / 2 | 0; N; N = N >>> 1) {
+ i++;
+ }
+
+ return 1 << i + 1 + odd;
+ };
+
+ FFTM.prototype.conjugate = function conjugate (rws, iws, N) {
+ if (N <= 1) return;
+
+ for (var i = 0; i < N / 2; i++) {
+ var t = rws[i];
+
+ rws[i] = rws[N - i - 1];
+ rws[N - i - 1] = t;
+
+ t = iws[i];
+
+ iws[i] = -iws[N - i - 1];
+ iws[N - i - 1] = -t;
+ }
+ };
+
+ FFTM.prototype.normalize13b = function normalize13b (ws, N) {
+ var carry = 0;
+ for (var i = 0; i < N / 2; i++) {
+ var w = Math.round(ws[2 * i + 1] / N) * 0x2000 +
+ Math.round(ws[2 * i] / N) +
+ carry;
+
+ ws[i] = w & 0x3ffffff;
+
+ if (w < 0x4000000) {
+ carry = 0;
+ } else {
+ carry = w / 0x4000000 | 0;
+ }
+ }
+
+ return ws;
+ };
+
+ FFTM.prototype.convert13b = function convert13b (ws, len, rws, N) {
+ var carry = 0;
+ for (var i = 0; i < len; i++) {
+ carry = carry + (ws[i] | 0);
+
+ rws[2 * i] = carry & 0x1fff; carry = carry >>> 13;
+ rws[2 * i + 1] = carry & 0x1fff; carry = carry >>> 13;
+ }
+
+ // Pad with zeroes
+ for (i = 2 * len; i < N; ++i) {
+ rws[i] = 0;
+ }
+
+ assert(carry === 0);
+ assert((carry & ~0x1fff) === 0);
+ };
+
+ FFTM.prototype.stub = function stub (N) {
+ var ph = new Array(N);
+ for (var i = 0; i < N; i++) {
+ ph[i] = 0;
+ }
+
+ return ph;
+ };
+
+ FFTM.prototype.mulp = function mulp (x, y, out) {
+ var N = 2 * this.guessLen13b(x.length, y.length);
+
+ var rbt = this.makeRBT(N);
+
+ var _ = this.stub(N);
+
+ var rws = new Array(N);
+ var rwst = new Array(N);
+ var iwst = new Array(N);
+
+ var nrws = new Array(N);
+ var nrwst = new Array(N);
+ var niwst = new Array(N);
+
+ var rmws = out.words;
+ rmws.length = N;
+
+ this.convert13b(x.words, x.length, rws, N);
+ this.convert13b(y.words, y.length, nrws, N);
+
+ this.transform(rws, _, rwst, iwst, N, rbt);
+ this.transform(nrws, _, nrwst, niwst, N, rbt);
+
+ for (var i = 0; i < N; i++) {
+ var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i];
+ iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i];
+ rwst[i] = rx;
+ }
+
+ this.conjugate(rwst, iwst, N);
+ this.transform(rwst, iwst, rmws, _, N, rbt);
+ this.conjugate(rmws, _, N);
+ this.normalize13b(rmws, N);
+
+ out.negative = x.negative ^ y.negative;
+ out.length = x.length + y.length;
+ return out.strip();
+ };
+
+ // Multiply `this` by `num`
+ BN.prototype.mul = function mul (num) {
+ var out = new BN(null);
+ out.words = new Array(this.length + num.length);
+ return this.mulTo(num, out);
+ };
+
+ // Multiply employing FFT
+ BN.prototype.mulf = function mulf (num) {
+ var out = new BN(null);
+ out.words = new Array(this.length + num.length);
+ return jumboMulTo(this, num, out);
+ };
+
+ // In-place Multiplication
+ BN.prototype.imul = function imul (num) {
+ return this.clone().mulTo(num, this);
+ };
+
+ BN.prototype.imuln = function imuln (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+
+ // Carry
+ var carry = 0;
+ for (var i = 0; i < this.length; i++) {
+ var w = (this.words[i] | 0) * num;
+ var lo = (w & 0x3ffffff) + (carry & 0x3ffffff);
+ carry >>= 26;
+ carry += (w / 0x4000000) | 0;
+ // NOTE: lo is 27bit maximum
+ carry += lo >>> 26;
+ this.words[i] = lo & 0x3ffffff;
+ }
+
+ if (carry !== 0) {
+ this.words[i] = carry;
+ this.length++;
+ }
+
+ return this;
+ };
+
+ BN.prototype.muln = function muln (num) {
+ return this.clone().imuln(num);
+ };
+
+ // `this` * `this`
+ BN.prototype.sqr = function sqr () {
+ return this.mul(this);
+ };
+
+ // `this` * `this` in-place
+ BN.prototype.isqr = function isqr () {
+ return this.imul(this.clone());
+ };
+
+ // Math.pow(`this`, `num`)
+ BN.prototype.pow = function pow (num) {
+ var w = toBitArray(num);
+ if (w.length === 0) return new BN(1);
+
+ // Skip leading zeroes
+ var res = this;
+ for (var i = 0; i < w.length; i++, res = res.sqr()) {
+ if (w[i] !== 0) break;
+ }
+
+ if (++i < w.length) {
+ for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) {
+ if (w[i] === 0) continue;
+
+ res = res.mul(q);
+ }
+ }
+
+ return res;
+ };
+
+ // Shift-left in-place
+ BN.prototype.iushln = function iushln (bits) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var r = bits % 26;
+ var s = (bits - r) / 26;
+ var carryMask = (0x3ffffff >>> (26 - r)) << (26 - r);
+ var i;
+
+ if (r !== 0) {
+ var carry = 0;
+
+ for (i = 0; i < this.length; i++) {
+ var newCarry = this.words[i] & carryMask;
+ var c = ((this.words[i] | 0) - newCarry) << r;
+ this.words[i] = c | carry;
+ carry = newCarry >>> (26 - r);
+ }
+
+ if (carry) {
+ this.words[i] = carry;
+ this.length++;
+ }
+ }
+
+ if (s !== 0) {
+ for (i = this.length - 1; i >= 0; i--) {
+ this.words[i + s] = this.words[i];
+ }
+
+ for (i = 0; i < s; i++) {
+ this.words[i] = 0;
+ }
+
+ this.length += s;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ishln = function ishln (bits) {
+ // TODO(indutny): implement me
+ assert(this.negative === 0);
+ return this.iushln(bits);
+ };
+
+ // Shift-right in-place
+ // NOTE: `hint` is a lowest bit before trailing zeroes
+ // NOTE: if `extended` is present - it will be filled with destroyed bits
+ BN.prototype.iushrn = function iushrn (bits, hint, extended) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var h;
+ if (hint) {
+ h = (hint - (hint % 26)) / 26;
+ } else {
+ h = 0;
+ }
+
+ var r = bits % 26;
+ var s = Math.min((bits - r) / 26, this.length);
+ var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
+ var maskedWords = extended;
+
+ h -= s;
+ h = Math.max(0, h);
+
+ // Extended mode, copy masked part
+ if (maskedWords) {
+ for (var i = 0; i < s; i++) {
+ maskedWords.words[i] = this.words[i];
+ }
+ maskedWords.length = s;
+ }
+
+ if (s === 0) {
+ // No-op, we should not move anything at all
+ } else if (this.length > s) {
+ this.length -= s;
+ for (i = 0; i < this.length; i++) {
+ this.words[i] = this.words[i + s];
+ }
+ } else {
+ this.words[0] = 0;
+ this.length = 1;
+ }
+
+ var carry = 0;
+ for (i = this.length - 1; i >= 0 && (carry !== 0 || i >= h); i--) {
+ var word = this.words[i] | 0;
+ this.words[i] = (carry << (26 - r)) | (word >>> r);
+ carry = word & mask;
+ }
+
+ // Push carried bits as a mask
+ if (maskedWords && carry !== 0) {
+ maskedWords.words[maskedWords.length++] = carry;
+ }
+
+ if (this.length === 0) {
+ this.words[0] = 0;
+ this.length = 1;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.ishrn = function ishrn (bits, hint, extended) {
+ // TODO(indutny): implement me
+ assert(this.negative === 0);
+ return this.iushrn(bits, hint, extended);
+ };
+
+ // Shift-left
+ BN.prototype.shln = function shln (bits) {
+ return this.clone().ishln(bits);
+ };
+
+ BN.prototype.ushln = function ushln (bits) {
+ return this.clone().iushln(bits);
+ };
+
+ // Shift-right
+ BN.prototype.shrn = function shrn (bits) {
+ return this.clone().ishrn(bits);
+ };
+
+ BN.prototype.ushrn = function ushrn (bits) {
+ return this.clone().iushrn(bits);
+ };
+
+ // Test if n bit is set
+ BN.prototype.testn = function testn (bit) {
+ assert(typeof bit === 'number' && bit >= 0);
+ var r = bit % 26;
+ var s = (bit - r) / 26;
+ var q = 1 << r;
+
+ // Fast case: bit is much higher than all existing words
+ if (this.length <= s) return false;
+
+ // Check bit and return
+ var w = this.words[s];
+
+ return !!(w & q);
+ };
+
+ // Return only lowers bits of number (in-place)
+ BN.prototype.imaskn = function imaskn (bits) {
+ assert(typeof bits === 'number' && bits >= 0);
+ var r = bits % 26;
+ var s = (bits - r) / 26;
+
+ assert(this.negative === 0, 'imaskn works only with positive numbers');
+
+ if (this.length <= s) {
+ return this;
+ }
+
+ if (r !== 0) {
+ s++;
+ }
+ this.length = Math.min(s, this.length);
+
+ if (r !== 0) {
+ var mask = 0x3ffffff ^ ((0x3ffffff >>> r) << r);
+ this.words[this.length - 1] &= mask;
+ }
+
+ return this.strip();
+ };
+
+ // Return only lowers bits of number
+ BN.prototype.maskn = function maskn (bits) {
+ return this.clone().imaskn(bits);
+ };
+
+ // Add plain number `num` to `this`
+ BN.prototype.iaddn = function iaddn (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+ if (num < 0) return this.isubn(-num);
+
+ // Possible sign change
+ if (this.negative !== 0) {
+ if (this.length === 1 && (this.words[0] | 0) < num) {
+ this.words[0] = num - (this.words[0] | 0);
+ this.negative = 0;
+ return this;
+ }
+
+ this.negative = 0;
+ this.isubn(num);
+ this.negative = 1;
+ return this;
+ }
+
+ // Add without checks
+ return this._iaddn(num);
+ };
+
+ BN.prototype._iaddn = function _iaddn (num) {
+ this.words[0] += num;
+
+ // Carry
+ for (var i = 0; i < this.length && this.words[i] >= 0x4000000; i++) {
+ this.words[i] -= 0x4000000;
+ if (i === this.length - 1) {
+ this.words[i + 1] = 1;
+ } else {
+ this.words[i + 1]++;
+ }
+ }
+ this.length = Math.max(this.length, i + 1);
+
+ return this;
+ };
+
+ // Subtract plain number `num` from `this`
+ BN.prototype.isubn = function isubn (num) {
+ assert(typeof num === 'number');
+ assert(num < 0x4000000);
+ if (num < 0) return this.iaddn(-num);
+
+ if (this.negative !== 0) {
+ this.negative = 0;
+ this.iaddn(num);
+ this.negative = 1;
+ return this;
+ }
+
+ this.words[0] -= num;
+
+ if (this.length === 1 && this.words[0] < 0) {
+ this.words[0] = -this.words[0];
+ this.negative = 1;
+ } else {
+ // Carry
+ for (var i = 0; i < this.length && this.words[i] < 0; i++) {
+ this.words[i] += 0x4000000;
+ this.words[i + 1] -= 1;
+ }
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.addn = function addn (num) {
+ return this.clone().iaddn(num);
+ };
+
+ BN.prototype.subn = function subn (num) {
+ return this.clone().isubn(num);
+ };
+
+ BN.prototype.iabs = function iabs () {
+ this.negative = 0;
+
+ return this;
+ };
+
+ BN.prototype.abs = function abs () {
+ return this.clone().iabs();
+ };
+
+ BN.prototype._ishlnsubmul = function _ishlnsubmul (num, mul, shift) {
+ var len = num.length + shift;
+ var i;
+
+ this._expand(len);
+
+ var w;
+ var carry = 0;
+ for (i = 0; i < num.length; i++) {
+ w = (this.words[i + shift] | 0) + carry;
+ var right = (num.words[i] | 0) * mul;
+ w -= right & 0x3ffffff;
+ carry = (w >> 26) - ((right / 0x4000000) | 0);
+ this.words[i + shift] = w & 0x3ffffff;
+ }
+ for (; i < this.length - shift; i++) {
+ w = (this.words[i + shift] | 0) + carry;
+ carry = w >> 26;
+ this.words[i + shift] = w & 0x3ffffff;
+ }
+
+ if (carry === 0) return this.strip();
+
+ // Subtraction overflow
+ assert(carry === -1);
+ carry = 0;
+ for (i = 0; i < this.length; i++) {
+ w = -(this.words[i] | 0) + carry;
+ carry = w >> 26;
+ this.words[i] = w & 0x3ffffff;
+ }
+ this.negative = 1;
+
+ return this.strip();
+ };
+
+ BN.prototype._wordDiv = function _wordDiv (num, mode) {
+ var shift = this.length - num.length;
+
+ var a = this.clone();
+ var b = num;
+
+ // Normalize
+ var bhi = b.words[b.length - 1] | 0;
+ var bhiBits = this._countBits(bhi);
+ shift = 26 - bhiBits;
+ if (shift !== 0) {
+ b = b.ushln(shift);
+ a.iushln(shift);
+ bhi = b.words[b.length - 1] | 0;
+ }
+
+ // Initialize quotient
+ var m = a.length - b.length;
+ var q;
+
+ if (mode !== 'mod') {
+ q = new BN(null);
+ q.length = m + 1;
+ q.words = new Array(q.length);
+ for (var i = 0; i < q.length; i++) {
+ q.words[i] = 0;
+ }
+ }
+
+ var diff = a.clone()._ishlnsubmul(b, 1, m);
+ if (diff.negative === 0) {
+ a = diff;
+ if (q) {
+ q.words[m] = 1;
+ }
+ }
+
+ for (var j = m - 1; j >= 0; j--) {
+ var qj = (a.words[b.length + j] | 0) * 0x4000000 +
+ (a.words[b.length + j - 1] | 0);
+
+ // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max
+ // (0x7ffffff)
+ qj = Math.min((qj / bhi) | 0, 0x3ffffff);
+
+ a._ishlnsubmul(b, qj, j);
+ while (a.negative !== 0) {
+ qj--;
+ a.negative = 0;
+ a._ishlnsubmul(b, 1, j);
+ if (!a.isZero()) {
+ a.negative ^= 1;
+ }
+ }
+ if (q) {
+ q.words[j] = qj;
+ }
+ }
+ if (q) {
+ q.strip();
+ }
+ a.strip();
+
+ // Denormalize
+ if (mode !== 'div' && shift !== 0) {
+ a.iushrn(shift);
+ }
+
+ return {
+ div: q || null,
+ mod: a
+ };
+ };
+
+ // NOTE: 1) `mode` can be set to `mod` to request mod only,
+ // to `div` to request div only, or be absent to
+ // request both div & mod
+ // 2) `positive` is true if unsigned mod is requested
+ BN.prototype.divmod = function divmod (num, mode, positive) {
+ assert(!num.isZero());
+
+ if (this.isZero()) {
+ return {
+ div: new BN(0),
+ mod: new BN(0)
+ };
+ }
+
+ var div, mod, res;
+ if (this.negative !== 0 && num.negative === 0) {
+ res = this.neg().divmod(num, mode);
+
+ if (mode !== 'mod') {
+ div = res.div.neg();
+ }
+
+ if (mode !== 'div') {
+ mod = res.mod.neg();
+ if (positive && mod.negative !== 0) {
+ mod.iadd(num);
+ }
+ }
+
+ return {
+ div: div,
+ mod: mod
+ };
+ }
+
+ if (this.negative === 0 && num.negative !== 0) {
+ res = this.divmod(num.neg(), mode);
+
+ if (mode !== 'mod') {
+ div = res.div.neg();
+ }
+
+ return {
+ div: div,
+ mod: res.mod
+ };
+ }
+
+ if ((this.negative & num.negative) !== 0) {
+ res = this.neg().divmod(num.neg(), mode);
+
+ if (mode !== 'div') {
+ mod = res.mod.neg();
+ if (positive && mod.negative !== 0) {
+ mod.isub(num);
+ }
+ }
+
+ return {
+ div: res.div,
+ mod: mod
+ };
+ }
+
+ // Both numbers are positive at this point
+
+ // Strip both numbers to approximate shift value
+ if (num.length > this.length || this.cmp(num) < 0) {
+ return {
+ div: new BN(0),
+ mod: this
+ };
+ }
+
+ // Very short reduction
+ if (num.length === 1) {
+ if (mode === 'div') {
+ return {
+ div: this.divn(num.words[0]),
+ mod: null
+ };
+ }
+
+ if (mode === 'mod') {
+ return {
+ div: null,
+ mod: new BN(this.modn(num.words[0]))
+ };
+ }
+
+ return {
+ div: this.divn(num.words[0]),
+ mod: new BN(this.modn(num.words[0]))
+ };
+ }
+
+ return this._wordDiv(num, mode);
+ };
+
+ // Find `this` / `num`
+ BN.prototype.div = function div (num) {
+ return this.divmod(num, 'div', false).div;
+ };
+
+ // Find `this` % `num`
+ BN.prototype.mod = function mod (num) {
+ return this.divmod(num, 'mod', false).mod;
+ };
+
+ BN.prototype.umod = function umod (num) {
+ return this.divmod(num, 'mod', true).mod;
+ };
+
+ // Find Round(`this` / `num`)
+ BN.prototype.divRound = function divRound (num) {
+ var dm = this.divmod(num);
+
+ // Fast case - exact division
+ if (dm.mod.isZero()) return dm.div;
+
+ var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod;
+
+ var half = num.ushrn(1);
+ var r2 = num.andln(1);
+ var cmp = mod.cmp(half);
+
+ // Round down
+ if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div;
+
+ // Round up
+ return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1);
+ };
+
+ BN.prototype.modn = function modn (num) {
+ assert(num <= 0x3ffffff);
+ var p = (1 << 26) % num;
+
+ var acc = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ acc = (p * acc + (this.words[i] | 0)) % num;
+ }
+
+ return acc;
+ };
+
+ // In-place division by number
+ BN.prototype.idivn = function idivn (num) {
+ assert(num <= 0x3ffffff);
+
+ var carry = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ var w = (this.words[i] | 0) + carry * 0x4000000;
+ this.words[i] = (w / num) | 0;
+ carry = w % num;
+ }
+
+ return this.strip();
+ };
+
+ BN.prototype.divn = function divn (num) {
+ return this.clone().idivn(num);
+ };
+
+ BN.prototype.egcd = function egcd (p) {
+ assert(p.negative === 0);
+ assert(!p.isZero());
+
+ var x = this;
+ var y = p.clone();
+
+ if (x.negative !== 0) {
+ x = x.umod(p);
+ } else {
+ x = x.clone();
+ }
+
+ // A * x + B * y = x
+ var A = new BN(1);
+ var B = new BN(0);
+
+ // C * x + D * y = y
+ var C = new BN(0);
+ var D = new BN(1);
+
+ var g = 0;
+
+ while (x.isEven() && y.isEven()) {
+ x.iushrn(1);
+ y.iushrn(1);
+ ++g;
+ }
+
+ var yp = y.clone();
+ var xp = x.clone();
+
+ while (!x.isZero()) {
+ for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
+ if (i > 0) {
+ x.iushrn(i);
+ while (i-- > 0) {
+ if (A.isOdd() || B.isOdd()) {
+ A.iadd(yp);
+ B.isub(xp);
+ }
+
+ A.iushrn(1);
+ B.iushrn(1);
+ }
+ }
+
+ for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
+ if (j > 0) {
+ y.iushrn(j);
+ while (j-- > 0) {
+ if (C.isOdd() || D.isOdd()) {
+ C.iadd(yp);
+ D.isub(xp);
+ }
+
+ C.iushrn(1);
+ D.iushrn(1);
+ }
+ }
+
+ if (x.cmp(y) >= 0) {
+ x.isub(y);
+ A.isub(C);
+ B.isub(D);
+ } else {
+ y.isub(x);
+ C.isub(A);
+ D.isub(B);
+ }
+ }
+
+ return {
+ a: C,
+ b: D,
+ gcd: y.iushln(g)
+ };
+ };
+
+ // This is reduced incarnation of the binary EEA
+ // above, designated to invert members of the
+ // _prime_ fields F(p) at a maximal speed
+ BN.prototype._invmp = function _invmp (p) {
+ assert(p.negative === 0);
+ assert(!p.isZero());
+
+ var a = this;
+ var b = p.clone();
+
+ if (a.negative !== 0) {
+ a = a.umod(p);
+ } else {
+ a = a.clone();
+ }
+
+ var x1 = new BN(1);
+ var x2 = new BN(0);
+
+ var delta = b.clone();
+
+ while (a.cmpn(1) > 0 && b.cmpn(1) > 0) {
+ for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1);
+ if (i > 0) {
+ a.iushrn(i);
+ while (i-- > 0) {
+ if (x1.isOdd()) {
+ x1.iadd(delta);
+ }
+
+ x1.iushrn(1);
+ }
+ }
+
+ for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1);
+ if (j > 0) {
+ b.iushrn(j);
+ while (j-- > 0) {
+ if (x2.isOdd()) {
+ x2.iadd(delta);
+ }
+
+ x2.iushrn(1);
+ }
+ }
+
+ if (a.cmp(b) >= 0) {
+ a.isub(b);
+ x1.isub(x2);
+ } else {
+ b.isub(a);
+ x2.isub(x1);
+ }
+ }
+
+ var res;
+ if (a.cmpn(1) === 0) {
+ res = x1;
+ } else {
+ res = x2;
+ }
+
+ if (res.cmpn(0) < 0) {
+ res.iadd(p);
+ }
+
+ return res;
+ };
+
+ BN.prototype.gcd = function gcd (num) {
+ if (this.isZero()) return num.abs();
+ if (num.isZero()) return this.abs();
+
+ var a = this.clone();
+ var b = num.clone();
+ a.negative = 0;
+ b.negative = 0;
+
+ // Remove common factor of two
+ for (var shift = 0; a.isEven() && b.isEven(); shift++) {
+ a.iushrn(1);
+ b.iushrn(1);
+ }
+
+ do {
+ while (a.isEven()) {
+ a.iushrn(1);
+ }
+ while (b.isEven()) {
+ b.iushrn(1);
+ }
+
+ var r = a.cmp(b);
+ if (r < 0) {
+ // Swap `a` and `b` to make `a` always bigger than `b`
+ var t = a;
+ a = b;
+ b = t;
+ } else if (r === 0 || b.cmpn(1) === 0) {
+ break;
+ }
+
+ a.isub(b);
+ } while (true);
+
+ return b.iushln(shift);
+ };
+
+ // Invert number in the field F(num)
+ BN.prototype.invm = function invm (num) {
+ return this.egcd(num).a.umod(num);
+ };
+
+ BN.prototype.isEven = function isEven () {
+ return (this.words[0] & 1) === 0;
+ };
+
+ BN.prototype.isOdd = function isOdd () {
+ return (this.words[0] & 1) === 1;
+ };
+
+ // And first word and num
+ BN.prototype.andln = function andln (num) {
+ return this.words[0] & num;
+ };
+
+ // Increment at the bit position in-line
+ BN.prototype.bincn = function bincn (bit) {
+ assert(typeof bit === 'number');
+ var r = bit % 26;
+ var s = (bit - r) / 26;
+ var q = 1 << r;
+
+ // Fast case: bit is much higher than all existing words
+ if (this.length <= s) {
+ this._expand(s + 1);
+ this.words[s] |= q;
+ return this;
+ }
+
+ // Add bit and propagate, if needed
+ var carry = q;
+ for (var i = s; carry !== 0 && i < this.length; i++) {
+ var w = this.words[i] | 0;
+ w += carry;
+ carry = w >>> 26;
+ w &= 0x3ffffff;
+ this.words[i] = w;
+ }
+ if (carry !== 0) {
+ this.words[i] = carry;
+ this.length++;
+ }
+ return this;
+ };
+
+ BN.prototype.isZero = function isZero () {
+ return this.length === 1 && this.words[0] === 0;
+ };
+
+ BN.prototype.cmpn = function cmpn (num) {
+ var negative = num < 0;
+
+ if (this.negative !== 0 && !negative) return -1;
+ if (this.negative === 0 && negative) return 1;
+
+ this.strip();
+
+ var res;
+ if (this.length > 1) {
+ res = 1;
+ } else {
+ if (negative) {
+ num = -num;
+ }
+
+ assert(num <= 0x3ffffff, 'Number is too big');
+
+ var w = this.words[0] | 0;
+ res = w === num ? 0 : w < num ? -1 : 1;
+ }
+ if (this.negative !== 0) return -res | 0;
+ return res;
+ };
+
+ // Compare two numbers and return:
+ // 1 - if `this` > `num`
+ // 0 - if `this` == `num`
+ // -1 - if `this` < `num`
+ BN.prototype.cmp = function cmp (num) {
+ if (this.negative !== 0 && num.negative === 0) return -1;
+ if (this.negative === 0 && num.negative !== 0) return 1;
+
+ var res = this.ucmp(num);
+ if (this.negative !== 0) return -res | 0;
+ return res;
+ };
+
+ // Unsigned comparison
+ BN.prototype.ucmp = function ucmp (num) {
+ // At this point both numbers have the same sign
+ if (this.length > num.length) return 1;
+ if (this.length < num.length) return -1;
+
+ var res = 0;
+ for (var i = this.length - 1; i >= 0; i--) {
+ var a = this.words[i] | 0;
+ var b = num.words[i] | 0;
+
+ if (a === b) continue;
+ if (a < b) {
+ res = -1;
+ } else if (a > b) {
+ res = 1;
+ }
+ break;
+ }
+ return res;
+ };
+
+ BN.prototype.gtn = function gtn (num) {
+ return this.cmpn(num) === 1;
+ };
+
+ BN.prototype.gt = function gt (num) {
+ return this.cmp(num) === 1;
+ };
+
+ BN.prototype.gten = function gten (num) {
+ return this.cmpn(num) >= 0;
+ };
+
+ BN.prototype.gte = function gte (num) {
+ return this.cmp(num) >= 0;
+ };
+
+ BN.prototype.ltn = function ltn (num) {
+ return this.cmpn(num) === -1;
+ };
+
+ BN.prototype.lt = function lt (num) {
+ return this.cmp(num) === -1;
+ };
+
+ BN.prototype.lten = function lten (num) {
+ return this.cmpn(num) <= 0;
+ };
+
+ BN.prototype.lte = function lte (num) {
+ return this.cmp(num) <= 0;
+ };
+
+ BN.prototype.eqn = function eqn (num) {
+ return this.cmpn(num) === 0;
+ };
+
+ BN.prototype.eq = function eq (num) {
+ return this.cmp(num) === 0;
+ };
+
+ //
+ // A reduce context, could be using montgomery or something better, depending
+ // on the `m` itself.
+ //
+ BN.red = function red (num) {
+ return new Red(num);
+ };
+
+ BN.prototype.toRed = function toRed (ctx) {
+ assert(!this.red, 'Already a number in reduction context');
+ assert(this.negative === 0, 'red works only with positives');
+ return ctx.convertTo(this)._forceRed(ctx);
+ };
+
+ BN.prototype.fromRed = function fromRed () {
+ assert(this.red, 'fromRed works only with numbers in reduction context');
+ return this.red.convertFrom(this);
+ };
+
+ BN.prototype._forceRed = function _forceRed (ctx) {
+ this.red = ctx;
+ return this;
+ };
+
+ BN.prototype.forceRed = function forceRed (ctx) {
+ assert(!this.red, 'Already a number in reduction context');
+ return this._forceRed(ctx);
+ };
+
+ BN.prototype.redAdd = function redAdd (num) {
+ assert(this.red, 'redAdd works only with red numbers');
+ return this.red.add(this, num);
+ };
+
+ BN.prototype.redIAdd = function redIAdd (num) {
+ assert(this.red, 'redIAdd works only with red numbers');
+ return this.red.iadd(this, num);
+ };
+
+ BN.prototype.redSub = function redSub (num) {
+ assert(this.red, 'redSub works only with red numbers');
+ return this.red.sub(this, num);
+ };
+
+ BN.prototype.redISub = function redISub (num) {
+ assert(this.red, 'redISub works only with red numbers');
+ return this.red.isub(this, num);
+ };
+
+ BN.prototype.redShl = function redShl (num) {
+ assert(this.red, 'redShl works only with red numbers');
+ return this.red.shl(this, num);
+ };
+
+ BN.prototype.redMul = function redMul (num) {
+ assert(this.red, 'redMul works only with red numbers');
+ this.red._verify2(this, num);
+ return this.red.mul(this, num);
+ };
+
+ BN.prototype.redIMul = function redIMul (num) {
+ assert(this.red, 'redMul works only with red numbers');
+ this.red._verify2(this, num);
+ return this.red.imul(this, num);
+ };
+
+ BN.prototype.redSqr = function redSqr () {
+ assert(this.red, 'redSqr works only with red numbers');
+ this.red._verify1(this);
+ return this.red.sqr(this);
+ };
+
+ BN.prototype.redISqr = function redISqr () {
+ assert(this.red, 'redISqr works only with red numbers');
+ this.red._verify1(this);
+ return this.red.isqr(this);
+ };
+
+ // Square root over p
+ BN.prototype.redSqrt = function redSqrt () {
+ assert(this.red, 'redSqrt works only with red numbers');
+ this.red._verify1(this);
+ return this.red.sqrt(this);
+ };
+
+ BN.prototype.redInvm = function redInvm () {
+ assert(this.red, 'redInvm works only with red numbers');
+ this.red._verify1(this);
+ return this.red.invm(this);
+ };
+
+ // Return negative clone of `this` % `red modulo`
+ BN.prototype.redNeg = function redNeg () {
+ assert(this.red, 'redNeg works only with red numbers');
+ this.red._verify1(this);
+ return this.red.neg(this);
+ };
+
+ BN.prototype.redPow = function redPow (num) {
+ assert(this.red && !num.red, 'redPow(normalNum)');
+ this.red._verify1(this);
+ return this.red.pow(this, num);
+ };
+
+ // Prime numbers with efficient reduction
+ var primes = {
+ k256: null,
+ p224: null,
+ p192: null,
+ p25519: null
+ };
+
+ // Pseudo-Mersenne prime
+ function MPrime (name, p) {
+ // P = 2 ^ N - K
+ this.name = name;
+ this.p = new BN(p, 16);
+ this.n = this.p.bitLength();
+ this.k = new BN(1).iushln(this.n).isub(this.p);
+
+ this.tmp = this._tmp();
+ }
+
+ MPrime.prototype._tmp = function _tmp () {
+ var tmp = new BN(null);
+ tmp.words = new Array(Math.ceil(this.n / 13));
+ return tmp;
+ };
+
+ MPrime.prototype.ireduce = function ireduce (num) {
+ // Assumes that `num` is less than `P^2`
+ // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P)
+ var r = num;
+ var rlen;
+
+ do {
+ this.split(r, this.tmp);
+ r = this.imulK(r);
+ r = r.iadd(this.tmp);
+ rlen = r.bitLength();
+ } while (rlen > this.n);
+
+ var cmp = rlen < this.n ? -1 : r.ucmp(this.p);
+ if (cmp === 0) {
+ r.words[0] = 0;
+ r.length = 1;
+ } else if (cmp > 0) {
+ r.isub(this.p);
+ } else {
+ r.strip();
+ }
+
+ return r;
+ };
+
+ MPrime.prototype.split = function split (input, out) {
+ input.iushrn(this.n, 0, out);
+ };
+
+ MPrime.prototype.imulK = function imulK (num) {
+ return num.imul(this.k);
+ };
+
+ function K256 () {
+ MPrime.call(
+ this,
+ 'k256',
+ 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f');
+ }
+ inherits(K256, MPrime);
+
+ K256.prototype.split = function split (input, output) {
+ // 256 = 9 * 26 + 22
+ var mask = 0x3fffff;
+
+ var outLen = Math.min(input.length, 9);
+ for (var i = 0; i < outLen; i++) {
+ output.words[i] = input.words[i];
+ }
+ output.length = outLen;
+
+ if (input.length <= 9) {
+ input.words[0] = 0;
+ input.length = 1;
+ return;
+ }
+
+ // Shift by 9 limbs
+ var prev = input.words[9];
+ output.words[output.length++] = prev & mask;
+
+ for (i = 10; i < input.length; i++) {
+ var next = input.words[i] | 0;
+ input.words[i - 10] = ((next & mask) << 4) | (prev >>> 22);
+ prev = next;
+ }
+ prev >>>= 22;
+ input.words[i - 10] = prev;
+ if (prev === 0 && input.length > 10) {
+ input.length -= 10;
+ } else {
+ input.length -= 9;
+ }
+ };
+
+ K256.prototype.imulK = function imulK (num) {
+ // K = 0x1000003d1 = [ 0x40, 0x3d1 ]
+ num.words[num.length] = 0;
+ num.words[num.length + 1] = 0;
+ num.length += 2;
+
+ // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390
+ var lo = 0;
+ for (var i = 0; i < num.length; i++) {
+ var w = num.words[i] | 0;
+ lo += w * 0x3d1;
+ num.words[i] = lo & 0x3ffffff;
+ lo = w * 0x40 + ((lo / 0x4000000) | 0);
+ }
+
+ // Fast length reduction
+ if (num.words[num.length - 1] === 0) {
+ num.length--;
+ if (num.words[num.length - 1] === 0) {
+ num.length--;
+ }
+ }
+ return num;
+ };
+
+ function P224 () {
+ MPrime.call(
+ this,
+ 'p224',
+ 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001');
+ }
+ inherits(P224, MPrime);
+
+ function P192 () {
+ MPrime.call(
+ this,
+ 'p192',
+ 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff');
+ }
+ inherits(P192, MPrime);
+
+ function P25519 () {
+ // 2 ^ 255 - 19
+ MPrime.call(
+ this,
+ '25519',
+ '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed');
+ }
+ inherits(P25519, MPrime);
+
+ P25519.prototype.imulK = function imulK (num) {
+ // K = 0x13
+ var carry = 0;
+ for (var i = 0; i < num.length; i++) {
+ var hi = (num.words[i] | 0) * 0x13 + carry;
+ var lo = hi & 0x3ffffff;
+ hi >>>= 26;
+
+ num.words[i] = lo;
+ carry = hi;
+ }
+ if (carry !== 0) {
+ num.words[num.length++] = carry;
+ }
+ return num;
+ };
+
+ // Exported mostly for testing purposes, use plain name instead
+ BN._prime = function prime (name) {
+ // Cached version of prime
+ if (primes[name]) return primes[name];
+
+ var prime;
+ if (name === 'k256') {
+ prime = new K256();
+ } else if (name === 'p224') {
+ prime = new P224();
+ } else if (name === 'p192') {
+ prime = new P192();
+ } else if (name === 'p25519') {
+ prime = new P25519();
+ } else {
+ throw new Error('Unknown prime ' + name);
+ }
+ primes[name] = prime;
+
+ return prime;
+ };
+
+ //
+ // Base reduction engine
+ //
+ function Red (m) {
+ if (typeof m === 'string') {
+ var prime = BN._prime(m);
+ this.m = prime.p;
+ this.prime = prime;
+ } else {
+ assert(m.gtn(1), 'modulus must be greater than 1');
+ this.m = m;
+ this.prime = null;
+ }
+ }
+
+ Red.prototype._verify1 = function _verify1 (a) {
+ assert(a.negative === 0, 'red works only with positives');
+ assert(a.red, 'red works only with red numbers');
+ };
+
+ Red.prototype._verify2 = function _verify2 (a, b) {
+ assert((a.negative | b.negative) === 0, 'red works only with positives');
+ assert(a.red && a.red === b.red,
+ 'red works only with red numbers');
+ };
+
+ Red.prototype.imod = function imod (a) {
+ if (this.prime) return this.prime.ireduce(a)._forceRed(this);
+ return a.umod(this.m)._forceRed(this);
+ };
+
+ Red.prototype.neg = function neg (a) {
+ if (a.isZero()) {
+ return a.clone();
+ }
+
+ return this.m.sub(a)._forceRed(this);
+ };
+
+ Red.prototype.add = function add (a, b) {
+ this._verify2(a, b);
+
+ var res = a.add(b);
+ if (res.cmp(this.m) >= 0) {
+ res.isub(this.m);
+ }
+ return res._forceRed(this);
+ };
+
+ Red.prototype.iadd = function iadd (a, b) {
+ this._verify2(a, b);
+
+ var res = a.iadd(b);
+ if (res.cmp(this.m) >= 0) {
+ res.isub(this.m);
+ }
+ return res;
+ };
+
+ Red.prototype.sub = function sub (a, b) {
+ this._verify2(a, b);
+
+ var res = a.sub(b);
+ if (res.cmpn(0) < 0) {
+ res.iadd(this.m);
+ }
+ return res._forceRed(this);
+ };
+
+ Red.prototype.isub = function isub (a, b) {
+ this._verify2(a, b);
+
+ var res = a.isub(b);
+ if (res.cmpn(0) < 0) {
+ res.iadd(this.m);
+ }
+ return res;
+ };
+
+ Red.prototype.shl = function shl (a, num) {
+ this._verify1(a);
+ return this.imod(a.ushln(num));
+ };
+
+ Red.prototype.imul = function imul (a, b) {
+ this._verify2(a, b);
+ return this.imod(a.imul(b));
+ };
+
+ Red.prototype.mul = function mul (a, b) {
+ this._verify2(a, b);
+ return this.imod(a.mul(b));
+ };
+
+ Red.prototype.isqr = function isqr (a) {
+ return this.imul(a, a.clone());
+ };
+
+ Red.prototype.sqr = function sqr (a) {
+ return this.mul(a, a);
+ };
+
+ Red.prototype.sqrt = function sqrt (a) {
+ if (a.isZero()) return a.clone();
+
+ var mod3 = this.m.andln(3);
+ assert(mod3 % 2 === 1);
+
+ // Fast case
+ if (mod3 === 3) {
+ var pow = this.m.add(new BN(1)).iushrn(2);
+ return this.pow(a, pow);
+ }
+
+ // Tonelli-Shanks algorithm (Totally unoptimized and slow)
+ //
+ // Find Q and S, that Q * 2 ^ S = (P - 1)
+ var q = this.m.subn(1);
+ var s = 0;
+ while (!q.isZero() && q.andln(1) === 0) {
+ s++;
+ q.iushrn(1);
+ }
+ assert(!q.isZero());
+
+ var one = new BN(1).toRed(this);
+ var nOne = one.redNeg();
+
+ // Find quadratic non-residue
+ // NOTE: Max is such because of generalized Riemann hypothesis.
+ var lpow = this.m.subn(1).iushrn(1);
+ var z = this.m.bitLength();
+ z = new BN(2 * z * z).toRed(this);
+
+ while (this.pow(z, lpow).cmp(nOne) !== 0) {
+ z.redIAdd(nOne);
+ }
+
+ var c = this.pow(z, q);
+ var r = this.pow(a, q.addn(1).iushrn(1));
+ var t = this.pow(a, q);
+ var m = s;
+ while (t.cmp(one) !== 0) {
+ var tmp = t;
+ for (var i = 0; tmp.cmp(one) !== 0; i++) {
+ tmp = tmp.redSqr();
+ }
+ assert(i < m);
+ var b = this.pow(c, new BN(1).iushln(m - i - 1));
+
+ r = r.redMul(b);
+ c = b.redSqr();
+ t = t.redMul(c);
+ m = i;
+ }
+
+ return r;
+ };
+
+ Red.prototype.invm = function invm (a) {
+ var inv = a._invmp(this.m);
+ if (inv.negative !== 0) {
+ inv.negative = 0;
+ return this.imod(inv).redNeg();
+ } else {
+ return this.imod(inv);
+ }
+ };
+
+ Red.prototype.pow = function pow (a, num) {
+ if (num.isZero()) return new BN(1).toRed(this);
+ if (num.cmpn(1) === 0) return a.clone();
+
+ var windowSize = 4;
+ var wnd = new Array(1 << windowSize);
+ wnd[0] = new BN(1).toRed(this);
+ wnd[1] = a;
+ for (var i = 2; i < wnd.length; i++) {
+ wnd[i] = this.mul(wnd[i - 1], a);
+ }
+
+ var res = wnd[0];
+ var current = 0;
+ var currentLen = 0;
+ var start = num.bitLength() % 26;
+ if (start === 0) {
+ start = 26;
+ }
+
+ for (i = num.length - 1; i >= 0; i--) {
+ var word = num.words[i];
+ for (var j = start - 1; j >= 0; j--) {
+ var bit = (word >> j) & 1;
+ if (res !== wnd[0]) {
+ res = this.sqr(res);
+ }
+
+ if (bit === 0 && current === 0) {
+ currentLen = 0;
+ continue;
+ }
+
+ current <<= 1;
+ current |= bit;
+ currentLen++;
+ if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue;
+
+ res = this.mul(res, wnd[current]);
+ currentLen = 0;
+ current = 0;
+ }
+ start = 26;
+ }
+
+ return res;
+ };
+
+ Red.prototype.convertTo = function convertTo (num) {
+ var r = num.umod(this.m);
+
+ return r === num ? r.clone() : r;
+ };
+
+ Red.prototype.convertFrom = function convertFrom (num) {
+ var res = num.clone();
+ res.red = null;
+ return res;
+ };
+
+ //
+ // Montgomery method engine
+ //
+
+ BN.mont = function mont (num) {
+ return new Mont(num);
+ };
+
+ function Mont (m) {
+ Red.call(this, m);
+
+ this.shift = this.m.bitLength();
+ if (this.shift % 26 !== 0) {
+ this.shift += 26 - (this.shift % 26);
+ }
+
+ this.r = new BN(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);
+ }
+ inherits(Mont, Red);
+
+ Mont.prototype.convertTo = function convertTo (num) {
+ return this.imod(num.ushln(this.shift));
+ };
+
+ Mont.prototype.convertFrom = function convertFrom (num) {
+ var r = this.imod(num.mul(this.rinv));
+ r.red = null;
+ return r;
+ };
+
+ Mont.prototype.imul = function imul (a, b) {
+ if (a.isZero() || b.isZero()) {
+ a.words[0] = 0;
+ a.length = 1;
+ return a;
+ }
+
+ var t = a.imul(b);
+ var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
+ var u = t.isub(c).iushrn(this.shift);
+ var res = u;
+
+ if (u.cmp(this.m) >= 0) {
+ res = u.isub(this.m);
+ } else if (u.cmpn(0) < 0) {
+ res = u.iadd(this.m);
+ }
+
+ return res._forceRed(this);
+ };
+
+ Mont.prototype.mul = function mul (a, b) {
+ if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this);
+
+ var t = a.mul(b);
+ var c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);
+ var u = t.isub(c).iushrn(this.shift);
+ var res = u;
+ if (u.cmp(this.m) >= 0) {
+ res = u.isub(this.m);
+ } else if (u.cmpn(0) < 0) {
+ res = u.iadd(this.m);
+ }
+
+ return res._forceRed(this);
+ };
+
+ Mont.prototype.invm = function invm (a) {
+ // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
+ var res = this.imod(a._invmp(this.m).mul(this.r2));
+ return res._forceRed(this);
+ };
+})(typeof module === 'undefined' || module, this);
+
+},{"buffer":2}],2:[function(require,module,exports){
+
+},{}],3:[function(require,module,exports){
+var hash = exports;
+
+hash.utils = require('./hash/utils');
+hash.common = require('./hash/common');
+hash.sha = require('./hash/sha');
+hash.ripemd = require('./hash/ripemd');
+hash.hmac = require('./hash/hmac');
+
+// Proxy hash functions to the main object
+hash.sha1 = hash.sha.sha1;
+hash.sha256 = hash.sha.sha256;
+hash.sha224 = hash.sha.sha224;
+hash.sha384 = hash.sha.sha384;
+hash.sha512 = hash.sha.sha512;
+hash.ripemd160 = hash.ripemd.ripemd160;
+
+},{"./hash/common":4,"./hash/hmac":5,"./hash/ripemd":6,"./hash/sha":7,"./hash/utils":14}],4:[function(require,module,exports){
+'use strict';
+
+var utils = require('./utils');
+var assert = require('minimalistic-assert');
+
+function BlockHash() {
+ 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;
+}
+exports.BlockHash = BlockHash;
+
+BlockHash.prototype.update = function update(msg, enc) {
+ // Convert message to array, pad it, and join into 32bit blocks
+ msg = utils.toArray(msg, enc);
+ if (!this.pending)
+ this.pending = msg;
+ else
+ this.pending = this.pending.concat(msg);
+ this.pendingTotal += msg.length;
+
+ // Enough data, try updating
+ if (this.pending.length >= this._delta8) {
+ msg = this.pending;
+
+ // Process pending data in blocks
+ var r = msg.length % this._delta8;
+ this.pending = msg.slice(msg.length - r, msg.length);
+ if (this.pending.length === 0)
+ this.pending = null;
+
+ msg = utils.join32(msg, 0, msg.length - r, this.endian);
+ for (var i = 0; i < msg.length; i += this._delta32)
+ this._update(msg, i, i + this._delta32);
+ }
+
+ return this;
+};
+
+BlockHash.prototype.digest = function digest(enc) {
+ this.update(this._pad());
+ assert(this.pending === null);
+
+ return this._digest(enc);
+};
+
+BlockHash.prototype._pad = function pad() {
+ var len = this.pendingTotal;
+ var bytes = this._delta8;
+ var k = bytes - ((len + this.padLength) % bytes);
+ var res = new Array(k + this.padLength);
+ res[0] = 0x80;
+ for (var i = 1; i < k; i++)
+ res[i] = 0;
+
+ // Append length
+ len <<= 3;
+ if (this.endian === 'big') {
+ for (var t = 8; t < this.padLength; t++)
+ res[i++] = 0;
+
+ res[i++] = 0;
+ res[i++] = 0;
+ res[i++] = 0;
+ res[i++] = 0;
+ res[i++] = (len >>> 24) & 0xff;
+ res[i++] = (len >>> 16) & 0xff;
+ res[i++] = (len >>> 8) & 0xff;
+ res[i++] = len & 0xff;
+ } else {
+ res[i++] = len & 0xff;
+ res[i++] = (len >>> 8) & 0xff;
+ res[i++] = (len >>> 16) & 0xff;
+ res[i++] = (len >>> 24) & 0xff;
+ res[i++] = 0;
+ res[i++] = 0;
+ res[i++] = 0;
+ res[i++] = 0;
+
+ for (t = 8; t < this.padLength; t++)
+ res[i++] = 0;
+ }
+
+ return res;
+};
+
+},{"./utils":14,"minimalistic-assert":17}],5:[function(require,module,exports){
+'use strict';
+
+var utils = require('./utils');
+var assert = require('minimalistic-assert');
+
+function Hmac(hash, key, enc) {
+ if (!(this instanceof Hmac))
+ return new Hmac(hash, key, enc);
+ this.Hash = hash;
+ this.blockSize = hash.blockSize / 8;
+ this.outSize = hash.outSize / 8;
+ this.inner = null;
+ this.outer = null;
+
+ this._init(utils.toArray(key, enc));
+}
+module.exports = Hmac;
+
+Hmac.prototype._init = function init(key) {
+ // Shorten key, if needed
+ if (key.length > this.blockSize)
+ key = new this.Hash().update(key).digest();
+ assert(key.length <= this.blockSize);
+
+ // Add padding to key
+ for (var i = key.length; i < this.blockSize; i++)
+ key.push(0);
+
+ for (i = 0; i < key.length; i++)
+ key[i] ^= 0x36;
+ this.inner = new this.Hash().update(key);
+
+ // 0x36 ^ 0x5c = 0x6a
+ for (i = 0; i < key.length; i++)
+ key[i] ^= 0x6a;
+ this.outer = new this.Hash().update(key);
+};
+
+Hmac.prototype.update = function update(msg, enc) {
+ this.inner.update(msg, enc);
+ return this;
+};
+
+Hmac.prototype.digest = function digest(enc) {
+ this.outer.update(this.inner.digest());
+ return this.outer.digest(enc);
+};
+
+},{"./utils":14,"minimalistic-assert":17}],6:[function(require,module,exports){
+module.exports = {ripemd160: null}
+},{}],7:[function(require,module,exports){
+'use strict';
+
+exports.sha1 = require('./sha/1');
+exports.sha224 = require('./sha/224');
+exports.sha256 = require('./sha/256');
+exports.sha384 = require('./sha/384');
+exports.sha512 = require('./sha/512');
+
+},{"./sha/1":8,"./sha/224":9,"./sha/256":10,"./sha/384":11,"./sha/512":12}],8:[function(require,module,exports){
+module.exports = {};
+},{}],9:[function(require,module,exports){
+arguments[4][8][0].apply(exports,arguments)
+},{"dup":8}],10:[function(require,module,exports){
+'use strict';
+
+var utils = require('../utils');
+var common = require('../common');
+var shaCommon = require('./common');
+var assert = require('minimalistic-assert');
+
+var sum32 = utils.sum32;
+var sum32_4 = utils.sum32_4;
+var sum32_5 = utils.sum32_5;
+var ch32 = shaCommon.ch32;
+var maj32 = shaCommon.maj32;
+var s0_256 = shaCommon.s0_256;
+var s1_256 = shaCommon.s1_256;
+var g0_256 = shaCommon.g0_256;
+var g1_256 = shaCommon.g1_256;
+
+var BlockHash = common.BlockHash;
+
+var sha256_K = [
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
+ 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
+ 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
+ 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
+ 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
+ 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
+ 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
+ 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
+ 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
+];
+
+function SHA256() {
+ if (!(this instanceof SHA256))
+ return new SHA256();
+
+ BlockHash.call(this);
+ this.h = [
+ 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
+ 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
+ ];
+ this.k = sha256_K;
+ this.W = new Array(64);
+}
+utils.inherits(SHA256, BlockHash);
+module.exports = SHA256;
+
+SHA256.blockSize = 512;
+SHA256.outSize = 256;
+SHA256.hmacStrength = 192;
+SHA256.padLength = 64;
+
+SHA256.prototype._update = function _update(msg, start) {
+ var W = this.W;
+
+ for (var i = 0; i < 16; i++)
+ W[i] = msg[start + i];
+ for (; i < W.length; i++)
+ W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
+
+ var a = this.h[0];
+ var b = this.h[1];
+ var c = this.h[2];
+ var d = this.h[3];
+ var e = this.h[4];
+ var f = this.h[5];
+ var g = this.h[6];
+ var h = this.h[7];
+
+ assert(this.k.length === W.length);
+ for (i = 0; i < W.length; i++) {
+ var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]);
+ var T2 = sum32(s0_256(a), maj32(a, b, c));
+ h = g;
+ g = f;
+ f = e;
+ e = sum32(d, T1);
+ d = c;
+ c = b;
+ b = a;
+ a = sum32(T1, T2);
+ }
+
+ this.h[0] = sum32(this.h[0], a);
+ this.h[1] = sum32(this.h[1], b);
+ this.h[2] = sum32(this.h[2], c);
+ this.h[3] = sum32(this.h[3], d);
+ this.h[4] = sum32(this.h[4], e);
+ this.h[5] = sum32(this.h[5], f);
+ this.h[6] = sum32(this.h[6], g);
+ this.h[7] = sum32(this.h[7], h);
+};
+
+SHA256.prototype._digest = function digest(enc) {
+ if (enc === 'hex')
+ return utils.toHex32(this.h, 'big');
+ else
+ return utils.split32(this.h, 'big');
+};
+
+},{"../common":4,"../utils":14,"./common":13,"minimalistic-assert":17}],11:[function(require,module,exports){
+arguments[4][8][0].apply(exports,arguments)
+},{"dup":8}],12:[function(require,module,exports){
+'use strict';
+
+var utils = require('../utils');
+var common = require('../common');
+var assert = require('minimalistic-assert');
+
+var rotr64_hi = utils.rotr64_hi;
+var rotr64_lo = utils.rotr64_lo;
+var shr64_hi = utils.shr64_hi;
+var shr64_lo = utils.shr64_lo;
+var sum64 = utils.sum64;
+var sum64_hi = utils.sum64_hi;
+var sum64_lo = utils.sum64_lo;
+var sum64_4_hi = utils.sum64_4_hi;
+var sum64_4_lo = utils.sum64_4_lo;
+var sum64_5_hi = utils.sum64_5_hi;
+var sum64_5_lo = utils.sum64_5_lo;
+
+var BlockHash = common.BlockHash;
+
+var sha512_K = [
+ 0x428a2f98, 0xd728ae22, 0x71374491, 0x23ef65cd,
+ 0xb5c0fbcf, 0xec4d3b2f, 0xe9b5dba5, 0x8189dbbc,
+ 0x3956c25b, 0xf348b538, 0x59f111f1, 0xb605d019,
+ 0x923f82a4, 0xaf194f9b, 0xab1c5ed5, 0xda6d8118,
+ 0xd807aa98, 0xa3030242, 0x12835b01, 0x45706fbe,
+ 0x243185be, 0x4ee4b28c, 0x550c7dc3, 0xd5ffb4e2,
+ 0x72be5d74, 0xf27b896f, 0x80deb1fe, 0x3b1696b1,
+ 0x9bdc06a7, 0x25c71235, 0xc19bf174, 0xcf692694,
+ 0xe49b69c1, 0x9ef14ad2, 0xefbe4786, 0x384f25e3,
+ 0x0fc19dc6, 0x8b8cd5b5, 0x240ca1cc, 0x77ac9c65,
+ 0x2de92c6f, 0x592b0275, 0x4a7484aa, 0x6ea6e483,
+ 0x5cb0a9dc, 0xbd41fbd4, 0x76f988da, 0x831153b5,
+ 0x983e5152, 0xee66dfab, 0xa831c66d, 0x2db43210,
+ 0xb00327c8, 0x98fb213f, 0xbf597fc7, 0xbeef0ee4,
+ 0xc6e00bf3, 0x3da88fc2, 0xd5a79147, 0x930aa725,
+ 0x06ca6351, 0xe003826f, 0x14292967, 0x0a0e6e70,
+ 0x27b70a85, 0x46d22ffc, 0x2e1b2138, 0x5c26c926,
+ 0x4d2c6dfc, 0x5ac42aed, 0x53380d13, 0x9d95b3df,
+ 0x650a7354, 0x8baf63de, 0x766a0abb, 0x3c77b2a8,
+ 0x81c2c92e, 0x47edaee6, 0x92722c85, 0x1482353b,
+ 0xa2bfe8a1, 0x4cf10364, 0xa81a664b, 0xbc423001,
+ 0xc24b8b70, 0xd0f89791, 0xc76c51a3, 0x0654be30,
+ 0xd192e819, 0xd6ef5218, 0xd6990624, 0x5565a910,
+ 0xf40e3585, 0x5771202a, 0x106aa070, 0x32bbd1b8,
+ 0x19a4c116, 0xb8d2d0c8, 0x1e376c08, 0x5141ab53,
+ 0x2748774c, 0xdf8eeb99, 0x34b0bcb5, 0xe19b48a8,
+ 0x391c0cb3, 0xc5c95a63, 0x4ed8aa4a, 0xe3418acb,
+ 0x5b9cca4f, 0x7763e373, 0x682e6ff3, 0xd6b2b8a3,
+ 0x748f82ee, 0x5defb2fc, 0x78a5636f, 0x43172f60,
+ 0x84c87814, 0xa1f0ab72, 0x8cc70208, 0x1a6439ec,
+ 0x90befffa, 0x23631e28, 0xa4506ceb, 0xde82bde9,
+ 0xbef9a3f7, 0xb2c67915, 0xc67178f2, 0xe372532b,
+ 0xca273ece, 0xea26619c, 0xd186b8c7, 0x21c0c207,
+ 0xeada7dd6, 0xcde0eb1e, 0xf57d4f7f, 0xee6ed178,
+ 0x06f067aa, 0x72176fba, 0x0a637dc5, 0xa2c898a6,
+ 0x113f9804, 0xbef90dae, 0x1b710b35, 0x131c471b,
+ 0x28db77f5, 0x23047d84, 0x32caab7b, 0x40c72493,
+ 0x3c9ebe0a, 0x15c9bebc, 0x431d67c4, 0x9c100d4c,
+ 0x4cc5d4be, 0xcb3e42b6, 0x597f299c, 0xfc657e2a,
+ 0x5fcb6fab, 0x3ad6faec, 0x6c44198c, 0x4a475817
+];
+
+function SHA512() {
+ if (!(this instanceof SHA512))
+ return new SHA512();
+
+ BlockHash.call(this);
+ this.h = [
+ 0x6a09e667, 0xf3bcc908,
+ 0xbb67ae85, 0x84caa73b,
+ 0x3c6ef372, 0xfe94f82b,
+ 0xa54ff53a, 0x5f1d36f1,
+ 0x510e527f, 0xade682d1,
+ 0x9b05688c, 0x2b3e6c1f,
+ 0x1f83d9ab, 0xfb41bd6b,
+ 0x5be0cd19, 0x137e2179 ];
+ this.k = sha512_K;
+ this.W = new Array(160);
+}
+utils.inherits(SHA512, BlockHash);
+module.exports = SHA512;
+
+SHA512.blockSize = 1024;
+SHA512.outSize = 512;
+SHA512.hmacStrength = 192;
+SHA512.padLength = 128;
+
+SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
+ var W = this.W;
+
+ // 32 x 32bit words
+ for (var i = 0; i < 32; i++)
+ W[i] = msg[start + i];
+ for (; i < W.length; i += 2) {
+ var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2
+ var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
+ var c1_hi = W[i - 14]; // i - 7
+ var c1_lo = W[i - 13];
+ var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15
+ var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
+ var c3_hi = W[i - 32]; // i - 16
+ var c3_lo = W[i - 31];
+
+ W[i] = sum64_4_hi(
+ c0_hi, c0_lo,
+ c1_hi, c1_lo,
+ c2_hi, c2_lo,
+ c3_hi, c3_lo);
+ W[i + 1] = sum64_4_lo(
+ c0_hi, c0_lo,
+ c1_hi, c1_lo,
+ c2_hi, c2_lo,
+ c3_hi, c3_lo);
+ }
+};
+
+SHA512.prototype._update = function _update(msg, start) {
+ this._prepareBlock(msg, start);
+
+ var W = this.W;
+
+ var ah = this.h[0];
+ var al = this.h[1];
+ var bh = this.h[2];
+ var bl = this.h[3];
+ var ch = this.h[4];
+ var cl = this.h[5];
+ var dh = this.h[6];
+ var dl = this.h[7];
+ var eh = this.h[8];
+ var el = this.h[9];
+ var fh = this.h[10];
+ var fl = this.h[11];
+ var gh = this.h[12];
+ var gl = this.h[13];
+ var hh = this.h[14];
+ var hl = this.h[15];
+
+ assert(this.k.length === W.length);
+ for (var i = 0; i < W.length; i += 2) {
+ var c0_hi = hh;
+ var c0_lo = hl;
+ var c1_hi = s1_512_hi(eh, el);
+ var c1_lo = s1_512_lo(eh, el);
+ var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
+ var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
+ var c3_hi = this.k[i];
+ var c3_lo = this.k[i + 1];
+ var c4_hi = W[i];
+ var c4_lo = W[i + 1];
+
+ var T1_hi = sum64_5_hi(
+ c0_hi, c0_lo,
+ c1_hi, c1_lo,
+ c2_hi, c2_lo,
+ c3_hi, c3_lo,
+ c4_hi, c4_lo);
+ var T1_lo = sum64_5_lo(
+ c0_hi, c0_lo,
+ c1_hi, c1_lo,
+ c2_hi, c2_lo,
+ c3_hi, c3_lo,
+ c4_hi, c4_lo);
+
+ c0_hi = s0_512_hi(ah, al);
+ c0_lo = s0_512_lo(ah, al);
+ c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
+ c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
+
+ var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
+ var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
+
+ hh = gh;
+ hl = gl;
+
+ gh = fh;
+ gl = fl;
+
+ fh = eh;
+ fl = el;
+
+ eh = sum64_hi(dh, dl, T1_hi, T1_lo);
+ el = sum64_lo(dl, dl, T1_hi, T1_lo);
+
+ dh = ch;
+ dl = cl;
+
+ ch = bh;
+ cl = bl;
+
+ bh = ah;
+ bl = al;
+
+ ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
+ al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
+ }
+
+ sum64(this.h, 0, ah, al);
+ sum64(this.h, 2, bh, bl);
+ sum64(this.h, 4, ch, cl);
+ sum64(this.h, 6, dh, dl);
+ sum64(this.h, 8, eh, el);
+ sum64(this.h, 10, fh, fl);
+ sum64(this.h, 12, gh, gl);
+ sum64(this.h, 14, hh, hl);
+};
+
+SHA512.prototype._digest = function digest(enc) {
+ if (enc === 'hex')
+ return utils.toHex32(this.h, 'big');
+ else
+ return utils.split32(this.h, 'big');
+};
+
+function ch64_hi(xh, xl, yh, yl, zh) {
+ var r = (xh & yh) ^ ((~xh) & zh);
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function ch64_lo(xh, xl, yh, yl, zh, zl) {
+ var r = (xl & yl) ^ ((~xl) & zl);
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function maj64_hi(xh, xl, yh, yl, zh) {
+ var r = (xh & yh) ^ (xh & zh) ^ (yh & zh);
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function maj64_lo(xh, xl, yh, yl, zh, zl) {
+ var r = (xl & yl) ^ (xl & zl) ^ (yl & zl);
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function s0_512_hi(xh, xl) {
+ var c0_hi = rotr64_hi(xh, xl, 28);
+ var c1_hi = rotr64_hi(xl, xh, 2); // 34
+ var c2_hi = rotr64_hi(xl, xh, 7); // 39
+
+ var r = c0_hi ^ c1_hi ^ c2_hi;
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function s0_512_lo(xh, xl) {
+ var c0_lo = rotr64_lo(xh, xl, 28);
+ var c1_lo = rotr64_lo(xl, xh, 2); // 34
+ var c2_lo = rotr64_lo(xl, xh, 7); // 39
+
+ var r = c0_lo ^ c1_lo ^ c2_lo;
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function s1_512_hi(xh, xl) {
+ var c0_hi = rotr64_hi(xh, xl, 14);
+ var c1_hi = rotr64_hi(xh, xl, 18);
+ var c2_hi = rotr64_hi(xl, xh, 9); // 41
+
+ var r = c0_hi ^ c1_hi ^ c2_hi;
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function s1_512_lo(xh, xl) {
+ var c0_lo = rotr64_lo(xh, xl, 14);
+ var c1_lo = rotr64_lo(xh, xl, 18);
+ var c2_lo = rotr64_lo(xl, xh, 9); // 41
+
+ var r = c0_lo ^ c1_lo ^ c2_lo;
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function g0_512_hi(xh, xl) {
+ var c0_hi = rotr64_hi(xh, xl, 1);
+ var c1_hi = rotr64_hi(xh, xl, 8);
+ var c2_hi = shr64_hi(xh, xl, 7);
+
+ var r = c0_hi ^ c1_hi ^ c2_hi;
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function g0_512_lo(xh, xl) {
+ var c0_lo = rotr64_lo(xh, xl, 1);
+ var c1_lo = rotr64_lo(xh, xl, 8);
+ var c2_lo = shr64_lo(xh, xl, 7);
+
+ var r = c0_lo ^ c1_lo ^ c2_lo;
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function g1_512_hi(xh, xl) {
+ var c0_hi = rotr64_hi(xh, xl, 19);
+ var c1_hi = rotr64_hi(xl, xh, 29); // 61
+ var c2_hi = shr64_hi(xh, xl, 6);
+
+ var r = c0_hi ^ c1_hi ^ c2_hi;
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+function g1_512_lo(xh, xl) {
+ var c0_lo = rotr64_lo(xh, xl, 19);
+ var c1_lo = rotr64_lo(xl, xh, 29); // 61
+ var c2_lo = shr64_lo(xh, xl, 6);
+
+ var r = c0_lo ^ c1_lo ^ c2_lo;
+ if (r < 0)
+ r += 0x100000000;
+ return r;
+}
+
+},{"../common":4,"../utils":14,"minimalistic-assert":17}],13:[function(require,module,exports){
+'use strict';
+
+var utils = require('../utils');
+var rotr32 = utils.rotr32;
+
+function ft_1(s, x, y, z) {
+ if (s === 0)
+ return ch32(x, y, z);
+ if (s === 1 || s === 3)
+ return p32(x, y, z);
+ if (s === 2)
+ return maj32(x, y, z);
+}
+exports.ft_1 = ft_1;
+
+function ch32(x, y, z) {
+ return (x & y) ^ ((~x) & z);
+}
+exports.ch32 = ch32;
+
+function maj32(x, y, z) {
+ return (x & y) ^ (x & z) ^ (y & z);
+}
+exports.maj32 = maj32;
+
+function p32(x, y, z) {
+ return x ^ y ^ z;
+}
+exports.p32 = p32;
+
+function s0_256(x) {
+ return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
+}
+exports.s0_256 = s0_256;
+
+function s1_256(x) {
+ return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
+}
+exports.s1_256 = s1_256;
+
+function g0_256(x) {
+ return rotr32(x, 7) ^ rotr32(x, 18) ^ (x >>> 3);
+}
+exports.g0_256 = g0_256;
+
+function g1_256(x) {
+ return rotr32(x, 17) ^ rotr32(x, 19) ^ (x >>> 10);
+}
+exports.g1_256 = g1_256;
+
+},{"../utils":14}],14:[function(require,module,exports){
+'use strict';
+
+var assert = require('minimalistic-assert');
+var inherits = require('inherits');
+
+exports.inherits = inherits;
+
+function toArray(msg, enc) {
+ if (Array.isArray(msg))
+ return msg.slice();
+ if (!msg)
+ return [];
+ var res = [];
+ if (typeof msg === 'string') {
+ if (!enc) {
+ for (var i = 0; i < msg.length; i++) {
+ var c = msg.charCodeAt(i);
+ var hi = c >> 8;
+ var lo = c & 0xff;
+ if (hi)
+ res.push(hi, lo);
+ else
+ res.push(lo);
+ }
+ } else if (enc === 'hex') {
+ msg = msg.replace(/[^a-z0-9]+/ig, '');
+ if (msg.length % 2 !== 0)
+ msg = '0' + msg;
+ for (i = 0; i < msg.length; i += 2)
+ res.push(parseInt(msg[i] + msg[i + 1], 16));
+ }
+ } else {
+ for (i = 0; i < msg.length; i++)
+ res[i] = msg[i] | 0;
+ }
+ return res;
+}
+exports.toArray = toArray;
+
+function toHex(msg) {
+ var res = '';
+ for (var i = 0; i < msg.length; i++)
+ res += zero2(msg[i].toString(16));
+ return res;
+}
+exports.toHex = toHex;
+
+function htonl(w) {
+ var res = (w >>> 24) |
+ ((w >>> 8) & 0xff00) |
+ ((w << 8) & 0xff0000) |
+ ((w & 0xff) << 24);
+ return res >>> 0;
+}
+exports.htonl = htonl;
+
+function toHex32(msg, endian) {
+ var res = '';
+ for (var i = 0; i < msg.length; i++) {
+ var w = msg[i];
+ if (endian === 'little')
+ w = htonl(w);
+ res += zero8(w.toString(16));
+ }
+ return res;
+}
+exports.toHex32 = toHex32;
+
+function zero2(word) {
+ if (word.length === 1)
+ return '0' + word;
+ else
+ return word;
+}
+exports.zero2 = zero2;
+
+function zero8(word) {
+ if (word.length === 7)
+ return '0' + word;
+ else if (word.length === 6)
+ return '00' + word;
+ else if (word.length === 5)
+ return '000' + word;
+ else if (word.length === 4)
+ return '0000' + word;
+ else if (word.length === 3)
+ return '00000' + word;
+ else if (word.length === 2)
+ return '000000' + word;
+ else if (word.length === 1)
+ return '0000000' + word;
+ else
+ return word;
+}
+exports.zero8 = zero8;
+
+function join32(msg, start, end, endian) {
+ var len = end - start;
+ assert(len % 4 === 0);
+ var res = new Array(len / 4);
+ for (var i = 0, k = start; i < res.length; i++, k += 4) {
+ var w;
+ if (endian === 'big')
+ w = (msg[k] << 24) | (msg[k + 1] << 16) | (msg[k + 2] << 8) | msg[k + 3];
+ else
+ w = (msg[k + 3] << 24) | (msg[k + 2] << 16) | (msg[k + 1] << 8) | msg[k];
+ res[i] = w >>> 0;
+ }
+ return res;
+}
+exports.join32 = join32;
+
+function split32(msg, endian) {
+ var res = new Array(msg.length * 4);
+ for (var i = 0, k = 0; i < msg.length; i++, k += 4) {
+ var m = msg[i];
+ if (endian === 'big') {
+ res[k] = m >>> 24;
+ res[k + 1] = (m >>> 16) & 0xff;
+ res[k + 2] = (m >>> 8) & 0xff;
+ res[k + 3] = m & 0xff;
+ } else {
+ res[k + 3] = m >>> 24;
+ res[k + 2] = (m >>> 16) & 0xff;
+ res[k + 1] = (m >>> 8) & 0xff;
+ res[k] = m & 0xff;
+ }
+ }
+ return res;
+}
+exports.split32 = split32;
+
+function rotr32(w, b) {
+ return (w >>> b) | (w << (32 - b));
+}
+exports.rotr32 = rotr32;
+
+function rotl32(w, b) {
+ return (w << b) | (w >>> (32 - b));
+}
+exports.rotl32 = rotl32;
+
+function sum32(a, b) {
+ return (a + b) >>> 0;
+}
+exports.sum32 = sum32;
+
+function sum32_3(a, b, c) {
+ return (a + b + c) >>> 0;
+}
+exports.sum32_3 = sum32_3;
+
+function sum32_4(a, b, c, d) {
+ return (a + b + c + d) >>> 0;
+}
+exports.sum32_4 = sum32_4;
+
+function sum32_5(a, b, c, d, e) {
+ return (a + b + c + d + e) >>> 0;
+}
+exports.sum32_5 = sum32_5;
+
+function sum64(buf, pos, ah, al) {
+ var bh = buf[pos];
+ var bl = buf[pos + 1];
+
+ var lo = (al + bl) >>> 0;
+ var hi = (lo < al ? 1 : 0) + ah + bh;
+ buf[pos] = hi >>> 0;
+ buf[pos + 1] = lo;
+}
+exports.sum64 = sum64;
+
+function sum64_hi(ah, al, bh, bl) {
+ var lo = (al + bl) >>> 0;
+ var hi = (lo < al ? 1 : 0) + ah + bh;
+ return hi >>> 0;
+}
+exports.sum64_hi = sum64_hi;
+
+function sum64_lo(ah, al, bh, bl) {
+ var lo = al + bl;
+ return lo >>> 0;
+}
+exports.sum64_lo = sum64_lo;
+
+function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
+ var carry = 0;
+ var lo = al;
+ lo = (lo + bl) >>> 0;
+ carry += lo < al ? 1 : 0;
+ lo = (lo + cl) >>> 0;
+ carry += lo < cl ? 1 : 0;
+ lo = (lo + dl) >>> 0;
+ carry += lo < dl ? 1 : 0;
+
+ var hi = ah + bh + ch + dh + carry;
+ return hi >>> 0;
+}
+exports.sum64_4_hi = sum64_4_hi;
+
+function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
+ var lo = al + bl + cl + dl;
+ return lo >>> 0;
+}
+exports.sum64_4_lo = sum64_4_lo;
+
+function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
+ var carry = 0;
+ var lo = al;
+ lo = (lo + bl) >>> 0;
+ carry += lo < al ? 1 : 0;
+ lo = (lo + cl) >>> 0;
+ carry += lo < cl ? 1 : 0;
+ lo = (lo + dl) >>> 0;
+ carry += lo < dl ? 1 : 0;
+ lo = (lo + el) >>> 0;
+ carry += lo < el ? 1 : 0;
+
+ var hi = ah + bh + ch + dh + eh + carry;
+ return hi >>> 0;
+}
+exports.sum64_5_hi = sum64_5_hi;
+
+function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
+ var lo = al + bl + cl + dl + el;
+
+ return lo >>> 0;
+}
+exports.sum64_5_lo = sum64_5_lo;
+
+function rotr64_hi(ah, al, num) {
+ var r = (al << (32 - num)) | (ah >>> num);
+ return r >>> 0;
+}
+exports.rotr64_hi = rotr64_hi;
+
+function rotr64_lo(ah, al, num) {
+ var r = (ah << (32 - num)) | (al >>> num);
+ return r >>> 0;
+}
+exports.rotr64_lo = rotr64_lo;
+
+function shr64_hi(ah, al, num) {
+ return ah >>> num;
+}
+exports.shr64_hi = shr64_hi;
+
+function shr64_lo(ah, al, num) {
+ var r = (ah << (32 - num)) | (al >>> num);
+ return r >>> 0;
+}
+exports.shr64_lo = shr64_lo;
+
+},{"inherits":15,"minimalistic-assert":17}],15:[function(require,module,exports){
+if (typeof Object.create === 'function') {
+ // implementation from standard node.js 'util' module
+ module.exports = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor
+ ctor.prototype = Object.create(superCtor.prototype, {
+ constructor: {
+ value: ctor,
+ enumerable: false,
+ writable: true,
+ configurable: true
+ }
+ });
+ };
+} else {
+ // old school shim for old browsers
+ module.exports = function inherits(ctor, superCtor) {
+ ctor.super_ = superCtor
+ var TempCtor = function () {}
+ TempCtor.prototype = superCtor.prototype
+ ctor.prototype = new TempCtor()
+ ctor.prototype.constructor = ctor
+ }
+}
+
+},{}],16:[function(require,module,exports){
+(function (process,global){
+/**
+ * [js-sha3]{@link https://github.com/emn178/js-sha3}
+ *
+ * @version 0.5.7
+ * @author Chen, Yi-Cyuan [emn178@gmail.com]
+ * @copyright Chen, Yi-Cyuan 2015-2016
+ * @license MIT
+ */
+/*jslint bitwise: true */
+(function () {
+ 'use strict';
+
+ var root = typeof window === 'object' ? window : {};
+ var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
+ if (NODE_JS) {
+ root = global;
+ }
+ var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
+ var HEX_CHARS = '0123456789abcdef'.split('');
+ var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
+ var KECCAK_PADDING = [1, 256, 65536, 16777216];
+ var PADDING = [6, 1536, 393216, 100663296];
+ var SHIFT = [0, 8, 16, 24];
+ var RC = [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];
+ var BITS = [224, 256, 384, 512];
+ var SHAKE_BITS = [128, 256];
+ var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array'];
+
+ var createOutputMethod = function (bits, padding, outputType) {
+ return function (message) {
+ return new Keccak(bits, padding, bits).update(message)[outputType]();
+ };
+ };
+
+ var createShakeOutputMethod = function (bits, padding, outputType) {
+ return function (message, outputBits) {
+ return new Keccak(bits, padding, outputBits).update(message)[outputType]();
+ };
+ };
+
+ var createMethod = function (bits, padding) {
+ var method = createOutputMethod(bits, padding, 'hex');
+ method.create = function () {
+ return new Keccak(bits, padding, bits);
+ };
+ method.update = function (message) {
+ return method.create().update(message);
+ };
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
+ var type = OUTPUT_TYPES[i];
+ method[type] = createOutputMethod(bits, padding, type);
+ }
+ return method;
+ };
+
+ var createShakeMethod = function (bits, padding) {
+ var method = createShakeOutputMethod(bits, padding, 'hex');
+ method.create = function (outputBits) {
+ return new Keccak(bits, padding, outputBits);
+ };
+ method.update = function (message, outputBits) {
+ return method.create(outputBits).update(message);
+ };
+ for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
+ var type = OUTPUT_TYPES[i];
+ method[type] = createShakeOutputMethod(bits, padding, type);
+ }
+ return method;
+ };
+
+ var algorithms = [
+ {name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod},
+ {name: 'sha3', padding: PADDING, bits: BITS, createMethod: createMethod},
+ {name: 'shake', padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod}
+ ];
+
+ var methods = {}, methodNames = [];
+
+ for (var i = 0; i < algorithms.length; ++i) {
+ var algorithm = algorithms[i];
+ var bits = algorithm.bits;
+ for (var j = 0; j < bits.length; ++j) {
+ var methodName = algorithm.name +'_' + bits[j];
+ methodNames.push(methodName);
+ methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding);
+ }
+ }
+
+ function Keccak(bits, padding, outputBits) {
+ this.blocks = [];
+ this.s = [];
+ this.padding = padding;
+ this.outputBits = outputBits;
+ this.reset = true;
+ this.block = 0;
+ this.start = 0;
+ this.blockCount = (1600 - (bits << 1)) >> 5;
+ this.byteCount = this.blockCount << 2;
+ this.outputBlocks = outputBits >> 5;
+ this.extraBytes = (outputBits & 31) >> 3;
+
+ for (var i = 0; i < 50; ++i) {
+ this.s[i] = 0;
+ }
+ }
+
+ Keccak.prototype.update = function (message) {
+ var notString = typeof message !== 'string';
+ if (notString && message.constructor === ArrayBuffer) {
+ message = new Uint8Array(message);
+ }
+ var length = message.length, blocks = this.blocks, byteCount = this.byteCount,
+ blockCount = this.blockCount, index = 0, s = this.s, i, code;
+
+ while (index < length) {
+ if (this.reset) {
+ this.reset = false;
+ blocks[0] = this.block;
+ for (i = 1; i < blockCount + 1; ++i) {
+ blocks[i] = 0;
+ }
+ }
+ if (notString) {
+ for (i = this.start; index < length && i < byteCount; ++index) {
+ blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
+ }
+ } else {
+ for (i = this.start; index < length && i < byteCount; ++index) {
+ code = message.charCodeAt(index);
+ if (code < 0x80) {
+ blocks[i >> 2] |= code << SHIFT[i++ & 3];
+ } else if (code < 0x800) {
+ blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ } else if (code < 0xd800 || code >= 0xe000) {
+ blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ } else {
+ code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
+ blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
+ blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
+ }
+ }
+ }
+ this.lastByteIndex = i;
+ if (i >= byteCount) {
+ this.start = i - byteCount;
+ this.block = blocks[blockCount];
+ for (i = 0; i < blockCount; ++i) {
+ s[i] ^= blocks[i];
+ }
+ f(s);
+ this.reset = true;
+ } else {
+ this.start = i;
+ }
+ }
+ return this;
+ };
+
+ Keccak.prototype.finalize = function () {
+ var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
+ blocks[i >> 2] |= this.padding[i & 3];
+ if (this.lastByteIndex === this.byteCount) {
+ blocks[0] = blocks[blockCount];
+ for (i = 1; i < blockCount + 1; ++i) {
+ blocks[i] = 0;
+ }
+ }
+ blocks[blockCount - 1] |= 0x80000000;
+ for (i = 0; i < blockCount; ++i) {
+ s[i] ^= blocks[i];
+ }
+ f(s);
+ };
+
+ Keccak.prototype.toString = Keccak.prototype.hex = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var hex = '', block;
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ block = s[i];
+ hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] +
+ HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] +
+ HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] +
+ HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ i = 0;
+ }
+ }
+ if (extraBytes) {
+ block = s[i];
+ if (extraBytes > 0) {
+ hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
+ }
+ if (extraBytes > 1) {
+ hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
+ }
+ if (extraBytes > 2) {
+ hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
+ }
+ }
+ return hex;
+ };
+
+ Keccak.prototype.arrayBuffer = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var bytes = this.outputBits >> 3;
+ var buffer;
+ if (extraBytes) {
+ buffer = new ArrayBuffer((outputBlocks + 1) << 2);
+ } else {
+ buffer = new ArrayBuffer(bytes);
+ }
+ var array = new Uint32Array(buffer);
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ array[j] = s[i];
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ }
+ }
+ if (extraBytes) {
+ array[i] = s[i];
+ buffer = buffer.slice(0, bytes);
+ }
+ return buffer;
+ };
+
+ Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
+
+ Keccak.prototype.digest = Keccak.prototype.array = function () {
+ this.finalize();
+
+ var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks,
+ extraBytes = this.extraBytes, i = 0, j = 0;
+ var array = [], offset, block;
+ while (j < outputBlocks) {
+ for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
+ offset = j << 2;
+ block = s[i];
+ array[offset] = block & 0xFF;
+ array[offset + 1] = (block >> 8) & 0xFF;
+ array[offset + 2] = (block >> 16) & 0xFF;
+ array[offset + 3] = (block >> 24) & 0xFF;
+ }
+ if (j % blockCount === 0) {
+ f(s);
+ }
+ }
+ if (extraBytes) {
+ offset = j << 2;
+ block = s[i];
+ if (extraBytes > 0) {
+ array[offset] = block & 0xFF;
+ }
+ if (extraBytes > 1) {
+ array[offset + 1] = (block >> 8) & 0xFF;
+ }
+ if (extraBytes > 2) {
+ array[offset + 2] = (block >> 16) & 0xFF;
+ }
+ }
+ return array;
+ };
+
+ var f = function (s) {
+ var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
+ b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
+ b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
+ b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
+ for (n = 0; n < 48; n += 2) {
+ c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
+ c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
+ c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
+ c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
+ c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
+ c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
+ c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
+ c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
+ c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
+ c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
+
+ h = c8 ^ ((c2 << 1) | (c3 >>> 31));
+ l = c9 ^ ((c3 << 1) | (c2 >>> 31));
+ s[0] ^= h;
+ s[1] ^= l;
+ s[10] ^= h;
+ s[11] ^= l;
+ s[20] ^= h;
+ s[21] ^= l;
+ s[30] ^= h;
+ s[31] ^= l;
+ s[40] ^= h;
+ s[41] ^= l;
+ h = c0 ^ ((c4 << 1) | (c5 >>> 31));
+ l = c1 ^ ((c5 << 1) | (c4 >>> 31));
+ s[2] ^= h;
+ s[3] ^= l;
+ s[12] ^= h;
+ s[13] ^= l;
+ s[22] ^= h;
+ s[23] ^= l;
+ s[32] ^= h;
+ s[33] ^= l;
+ s[42] ^= h;
+ s[43] ^= l;
+ h = c2 ^ ((c6 << 1) | (c7 >>> 31));
+ l = c3 ^ ((c7 << 1) | (c6 >>> 31));
+ s[4] ^= h;
+ s[5] ^= l;
+ s[14] ^= h;
+ s[15] ^= l;
+ s[24] ^= h;
+ s[25] ^= l;
+ s[34] ^= h;
+ s[35] ^= l;
+ s[44] ^= h;
+ s[45] ^= l;
+ h = c4 ^ ((c8 << 1) | (c9 >>> 31));
+ l = c5 ^ ((c9 << 1) | (c8 >>> 31));
+ s[6] ^= h;
+ s[7] ^= l;
+ s[16] ^= h;
+ s[17] ^= l;
+ s[26] ^= h;
+ s[27] ^= l;
+ s[36] ^= h;
+ s[37] ^= l;
+ s[46] ^= h;
+ s[47] ^= l;
+ h = c6 ^ ((c0 << 1) | (c1 >>> 31));
+ l = c7 ^ ((c1 << 1) | (c0 >>> 31));
+ s[8] ^= h;
+ s[9] ^= l;
+ s[18] ^= h;
+ s[19] ^= l;
+ s[28] ^= h;
+ s[29] ^= l;
+ s[38] ^= h;
+ s[39] ^= l;
+ s[48] ^= h;
+ s[49] ^= l;
+
+ b0 = s[0];
+ b1 = s[1];
+ b32 = (s[11] << 4) | (s[10] >>> 28);
+ b33 = (s[10] << 4) | (s[11] >>> 28);
+ b14 = (s[20] << 3) | (s[21] >>> 29);
+ b15 = (s[21] << 3) | (s[20] >>> 29);
+ b46 = (s[31] << 9) | (s[30] >>> 23);
+ b47 = (s[30] << 9) | (s[31] >>> 23);
+ b28 = (s[40] << 18) | (s[41] >>> 14);
+ b29 = (s[41] << 18) | (s[40] >>> 14);
+ b20 = (s[2] << 1) | (s[3] >>> 31);
+ b21 = (s[3] << 1) | (s[2] >>> 31);
+ b2 = (s[13] << 12) | (s[12] >>> 20);
+ b3 = (s[12] << 12) | (s[13] >>> 20);
+ b34 = (s[22] << 10) | (s[23] >>> 22);
+ b35 = (s[23] << 10) | (s[22] >>> 22);
+ b16 = (s[33] << 13) | (s[32] >>> 19);
+ b17 = (s[32] << 13) | (s[33] >>> 19);
+ b48 = (s[42] << 2) | (s[43] >>> 30);
+ b49 = (s[43] << 2) | (s[42] >>> 30);
+ b40 = (s[5] << 30) | (s[4] >>> 2);
+ b41 = (s[4] << 30) | (s[5] >>> 2);
+ b22 = (s[14] << 6) | (s[15] >>> 26);
+ b23 = (s[15] << 6) | (s[14] >>> 26);
+ b4 = (s[25] << 11) | (s[24] >>> 21);
+ b5 = (s[24] << 11) | (s[25] >>> 21);
+ b36 = (s[34] << 15) | (s[35] >>> 17);
+ b37 = (s[35] << 15) | (s[34] >>> 17);
+ b18 = (s[45] << 29) | (s[44] >>> 3);
+ b19 = (s[44] << 29) | (s[45] >>> 3);
+ b10 = (s[6] << 28) | (s[7] >>> 4);
+ b11 = (s[7] << 28) | (s[6] >>> 4);
+ b42 = (s[17] << 23) | (s[16] >>> 9);
+ b43 = (s[16] << 23) | (s[17] >>> 9);
+ b24 = (s[26] << 25) | (s[27] >>> 7);
+ b25 = (s[27] << 25) | (s[26] >>> 7);
+ b6 = (s[36] << 21) | (s[37] >>> 11);
+ b7 = (s[37] << 21) | (s[36] >>> 11);
+ b38 = (s[47] << 24) | (s[46] >>> 8);
+ b39 = (s[46] << 24) | (s[47] >>> 8);
+ b30 = (s[8] << 27) | (s[9] >>> 5);
+ b31 = (s[9] << 27) | (s[8] >>> 5);
+ b12 = (s[18] << 20) | (s[19] >>> 12);
+ b13 = (s[19] << 20) | (s[18] >>> 12);
+ b44 = (s[29] << 7) | (s[28] >>> 25);
+ b45 = (s[28] << 7) | (s[29] >>> 25);
+ b26 = (s[38] << 8) | (s[39] >>> 24);
+ b27 = (s[39] << 8) | (s[38] >>> 24);
+ b8 = (s[48] << 14) | (s[49] >>> 18);
+ b9 = (s[49] << 14) | (s[48] >>> 18);
+
+ s[0] = b0 ^ (~b2 & b4);
+ s[1] = b1 ^ (~b3 & b5);
+ s[10] = b10 ^ (~b12 & b14);
+ s[11] = b11 ^ (~b13 & b15);
+ s[20] = b20 ^ (~b22 & b24);
+ s[21] = b21 ^ (~b23 & b25);
+ s[30] = b30 ^ (~b32 & b34);
+ s[31] = b31 ^ (~b33 & b35);
+ s[40] = b40 ^ (~b42 & b44);
+ s[41] = b41 ^ (~b43 & b45);
+ s[2] = b2 ^ (~b4 & b6);
+ s[3] = b3 ^ (~b5 & b7);
+ s[12] = b12 ^ (~b14 & b16);
+ s[13] = b13 ^ (~b15 & b17);
+ s[22] = b22 ^ (~b24 & b26);
+ s[23] = b23 ^ (~b25 & b27);
+ s[32] = b32 ^ (~b34 & b36);
+ s[33] = b33 ^ (~b35 & b37);
+ s[42] = b42 ^ (~b44 & b46);
+ s[43] = b43 ^ (~b45 & b47);
+ s[4] = b4 ^ (~b6 & b8);
+ s[5] = b5 ^ (~b7 & b9);
+ s[14] = b14 ^ (~b16 & b18);
+ s[15] = b15 ^ (~b17 & b19);
+ s[24] = b24 ^ (~b26 & b28);
+ s[25] = b25 ^ (~b27 & b29);
+ s[34] = b34 ^ (~b36 & b38);
+ s[35] = b35 ^ (~b37 & b39);
+ s[44] = b44 ^ (~b46 & b48);
+ s[45] = b45 ^ (~b47 & b49);
+ s[6] = b6 ^ (~b8 & b0);
+ s[7] = b7 ^ (~b9 & b1);
+ s[16] = b16 ^ (~b18 & b10);
+ s[17] = b17 ^ (~b19 & b11);
+ s[26] = b26 ^ (~b28 & b20);
+ s[27] = b27 ^ (~b29 & b21);
+ s[36] = b36 ^ (~b38 & b30);
+ s[37] = b37 ^ (~b39 & b31);
+ s[46] = b46 ^ (~b48 & b40);
+ s[47] = b47 ^ (~b49 & b41);
+ s[8] = b8 ^ (~b0 & b2);
+ s[9] = b9 ^ (~b1 & b3);
+ s[18] = b18 ^ (~b10 & b12);
+ s[19] = b19 ^ (~b11 & b13);
+ s[28] = b28 ^ (~b20 & b22);
+ s[29] = b29 ^ (~b21 & b23);
+ s[38] = b38 ^ (~b30 & b32);
+ s[39] = b39 ^ (~b31 & b33);
+ s[48] = b48 ^ (~b40 & b42);
+ s[49] = b49 ^ (~b41 & b43);
+
+ s[0] ^= RC[n];
+ s[1] ^= RC[n + 1];
+ }
+ };
+
+ if (COMMON_JS) {
+ module.exports = methods;
+ } else {
+ for (var i = 0; i < methodNames.length; ++i) {
+ root[methodNames[i]] = methods[methodNames[i]];
+ }
+ }
+})();
+
+}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"_process":18}],17:[function(require,module,exports){
+module.exports = assert;
+
+function assert(val, msg) {
+ if (!val)
+ throw new Error(msg || 'Assertion failed');
+}
+
+assert.equal = function assertEqual(l, r, msg) {
+ if (l != r)
+ throw new Error(msg || ('Assertion failed: ' + l + ' != ' + r));
+};
+
+},{}],18:[function(require,module,exports){
+module.exports = undefined;
+},{}],19:[function(require,module,exports){
+'use strict';
+
+// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
+
+var throwError = require('../utils/throw-error');
+
+var utils = (function() {
+ var convert = require('../utils/convert.js');
+ var utf8 = require('../utils/utf8.js');
+
+ return {
+ defineProperty: require('../utils/properties.js').defineProperty,
+
+ arrayify: convert.arrayify,
+ padZeros: convert.padZeros,
+
+ bigNumberify: require('../utils/bignumber.js').bigNumberify,
+
+ getAddress: require('../utils/address').getAddress,
+
+ concat: convert.concat,
+
+ toUtf8Bytes: utf8.toUtf8Bytes,
+ toUtf8String: utf8.toUtf8String,
+
+ hexlify: convert.hexlify,
+ };
+})();
+
+var paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
+var paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
+var paramTypeArray = new RegExp(/^(.*)\[([0-9]*)\]$/);
+
+var defaultCoerceFunc = function(type, value) {
+ var match = type.match(paramTypeNumber)
+ if (match && parseInt(match[2]) <= 48) { return value.toNumber(); }
+ return value;
+}
+
+var coderNull = function(coerceFunc) {
+ return {
+ name: 'null',
+ type: '',
+ encode: function(value) {
+ return utils.arrayify([]);
+ },
+ decode: function(data, offset) {
+ if (offset > data.length) { throw new Error('invalid null'); }
+ return {
+ consumed: 0,
+ value: coerceFunc('null', undefined)
+ }
+ },
+ dynamic: false
+ };
+}
+
+var coderNumber = function(coerceFunc, size, signed, localName) {
+ var name = ((signed ? 'int': 'uint') + (size * 8));
+ return {
+ localName: localName,
+ name: name,
+ type: name,
+ encode: function(value) {
+ value = utils.bigNumberify(value).toTwos(size * 8).maskn(size * 8);
+ //value = value.toTwos(size * 8).maskn(size * 8);
+ if (signed) {
+ value = value.fromTwos(size * 8).toTwos(256);
+ }
+ return utils.padZeros(utils.arrayify(value), 32);
+ },
+ decode: function(data, offset) {
+ var junkLength = 32 - size;
+ var value = utils.bigNumberify(data.slice(offset + junkLength, offset + 32));
+ if (signed) {
+ value = value.fromTwos(size * 8);
+ } else {
+ value = value.maskn(size * 8);
+ }
+
+ //if (size <= 6) { value = value.toNumber(); }
+
+ return {
+ consumed: 32,
+ value: coerceFunc(name, value),
+ }
+ }
+ };
+}
+var uint256Coder = coderNumber(function(type, value) { return value; }, 32, false);
+
+var coderBoolean = function(coerceFunc, localName) {
+ return {
+ localName: localName,
+ name: 'boolean',
+ type: 'boolean',
+ encode: function(value) {
+ return uint256Coder.encode(value ? 1: 0);
+ },
+ decode: function(data, offset) {
+ var result = uint256Coder.decode(data, offset);
+ return {
+ consumed: result.consumed,
+ value: coerceFunc('boolean', !result.value.isZero())
+ }
+ }
+ }
+}
+
+var coderFixedBytes = function(coerceFunc, length, localName) {
+ var name = ('bytes' + length);
+ return {
+ localName: localName,
+ name: name,
+ type: name,
+ encode: function(value) {
+ value = utils.arrayify(value);
+ if (length === 32) { return value; }
+
+ var result = new Uint8Array(32);
+ result.set(value);
+ return result;
+ },
+ decode: function(data, offset) {
+ if (data.length < offset + 32) { throwError('invalid bytes' + length); }
+
+ return {
+ consumed: 32,
+ value: coerceFunc(name, utils.hexlify(data.slice(offset, offset + length)))
+ }
+ }
+ };
+}
+
+var coderAddress = function(coerceFunc, localName) {
+ return {
+ localName: localName,
+ name: 'address',
+ type: 'address',
+ encode: function(value) {
+ value = utils.arrayify(utils.getAddress(value));
+ var result = new Uint8Array(32);
+ result.set(value, 12);
+ return result;
+ },
+ decode: function(data, offset) {
+ if (data.length < offset + 32) { throwError('invalid address'); }
+ return {
+ consumed: 32,
+ value: coerceFunc('address', utils.getAddress(utils.hexlify(data.slice(offset + 12, offset + 32))))
+ }
+ }
+ }
+}
+
+function _encodeDynamicBytes(value) {
+ var dataLength = parseInt(32 * Math.ceil(value.length / 32));
+ var padding = new Uint8Array(dataLength - value.length);
+
+ return utils.concat([
+ uint256Coder.encode(value.length),
+ value,
+ padding
+ ]);
+}
+
+function _decodeDynamicBytes(data, offset) {
+ if (data.length < offset + 32) { throwError('invalid bytes'); }
+
+ var length = uint256Coder.decode(data, offset).value;
+ length = length.toNumber();
+ if (data.length < offset + 32 + length) { throwError('invalid bytes'); }
+
+ return {
+ consumed: parseInt(32 + 32 * Math.ceil(length / 32)),
+ value: data.slice(offset + 32, offset + 32 + length),
+ }
+}
+
+var coderDynamicBytes = function(coerceFunc, localName) {
+ return {
+ localName: localName,
+ name: 'bytes',
+ type: 'bytes',
+ encode: function(value) {
+ return _encodeDynamicBytes(utils.arrayify(value));
+ },
+ decode: function(data, offset) {
+ var result = _decodeDynamicBytes(data, offset);
+ result.value = coerceFunc('bytes', utils.hexlify(result.value));
+ return result;
+ },
+ dynamic: true
+ };
+}
+
+var coderString = function(coerceFunc, localName) {
+ return {
+ localName: localName,
+ name: 'string',
+ type: 'string',
+ encode: function(value) {
+ return _encodeDynamicBytes(utils.toUtf8Bytes(value));
+ },
+ decode: function(data, offset) {
+ var result = _decodeDynamicBytes(data, offset);
+ result.value = coerceFunc('string', utils.toUtf8String(result.value));
+ return result;
+ },
+ dynamic: true
+ };
+}
+
+function alignSize(size) {
+ return parseInt(32 * Math.ceil(size / 32));
+}
+
+function pack(coders, values) {
+ if (Array.isArray(values)) {
+ if (coders.length !== values.length) {
+ throwError('types/values mismatch', { type: type, values: values });
+ }
+
+ } else if (values && typeof(values) === 'object') {
+ var arrayValues = [];
+ coders.forEach(function(coder) {
+ arrayValues.push(values[coder.localName]);
+ });
+ values = arrayValues;
+
+ } else {
+ throwError('invalid value', { type: 'tuple', values: values });
+ }
+
+ var parts = [];
+
+ coders.forEach(function(coder, index) {
+ parts.push({ dynamic: coder.dynamic, value: coder.encode(values[index]) });
+ });
+
+ var staticSize = 0, dynamicSize = 0;
+ parts.forEach(function(part, index) {
+ if (part.dynamic) {
+ staticSize += 32;
+ dynamicSize += alignSize(part.value.length);
+ } else {
+ staticSize += alignSize(part.value.length);
+ }
+ });
+
+ var offset = 0, dynamicOffset = staticSize;
+ var data = new Uint8Array(staticSize + dynamicSize);
+
+ parts.forEach(function(part, index) {
+ if (part.dynamic) {
+ //uint256Coder.encode(dynamicOffset).copy(data, offset);
+ data.set(uint256Coder.encode(dynamicOffset), offset);
+ offset += 32;
+
+ //part.value.copy(data, dynamicOffset); @TODO
+ data.set(part.value, dynamicOffset);
+ dynamicOffset += alignSize(part.value.length);
+ } else {
+ //part.value.copy(data, offset); @TODO
+ data.set(part.value, offset);
+ offset += alignSize(part.value.length);
+ }
+ });
+
+ return data;
+}
+
+function unpack(coders, data, offset) {
+ var baseOffset = offset;
+ var consumed = 0;
+ var value = [];
+ coders.forEach(function(coder) {
+ if (coder.dynamic) {
+ var dynamicOffset = uint256Coder.decode(data, offset);
+ var result = coder.decode(data, baseOffset + dynamicOffset.value.toNumber());
+ // The dynamic part is leap-frogged somewhere else; doesn't count towards size
+ result.consumed = dynamicOffset.consumed;
+ } else {
+ var result = coder.decode(data, offset);
+ }
+
+ if (result.value != undefined) {
+ value.push(result.value);
+ }
+
+ offset += result.consumed;
+ consumed += result.consumed;
+ });
+
+ coders.forEach(function(coder, index) {
+ var name = coder.localName;
+ if (!name) { return; }
+
+ if (typeof(name) === 'object') { name = name.name; }
+ if (!name) { return; }
+
+ if (name === 'length') { name = '_length'; }
+
+ if (value[name] != null) { return; }
+
+ value[name] = value[index];
+ });
+
+ return {
+ value: value,
+ consumed: consumed
+ }
+
+ return result;
+}
+
+function coderArray(coerceFunc, coder, length, localName) {
+ var type = (coder.type + '[' + (length >= 0 ? length: '') + ']');
+
+ return {
+ coder: coder,
+ localName: localName,
+ length: length,
+ name: 'array',
+ type: type,
+ encode: function(value) {
+ if (!Array.isArray(value)) { throwError('invalid array'); }
+
+ var count = length;
+
+ var result = new Uint8Array(0);
+ if (count === -1) {
+ count = value.length;
+ result = uint256Coder.encode(count);
+ }
+
+ if (count !== value.length) { throwError('size mismatch'); }
+
+ var coders = [];
+ value.forEach(function(value) { coders.push(coder); });
+
+ return utils.concat([result, pack(coders, value)]);
+ },
+ decode: function(data, offset) {
+ // @TODO:
+ //if (data.length < offset + length * 32) { throw new Error('invalid array'); }
+
+ var consumed = 0;
+
+ var count = length;
+
+ if (count === -1) {
+ var decodedLength = uint256Coder.decode(data, offset);
+ count = decodedLength.value.toNumber();
+ consumed += decodedLength.consumed;
+ offset += decodedLength.consumed;
+ }
+
+ var coders = [];
+ for (var i = 0; i < count; i++) { coders.push(coder); }
+
+ var result = unpack(coders, data, offset);
+ result.consumed += consumed;
+ result.value = coerceFunc(type, result.value);
+ return result;
+ },
+ dynamic: (length === -1 || coder.dynamic)
+ }
+}
+
+
+function coderTuple(coerceFunc, coders, localName) {
+ var dynamic = false;
+ var types = [];
+ coders.forEach(function(coder) {
+ if (coder.dynamic) { dynamic = true; }
+ types.push(coder.type);
+ });
+
+ var type = ('tuple(' + types.join(',') + ')');
+
+ return {
+ coders: coders,
+ localName: localName,
+ name: 'tuple',
+ type: type,
+ encode: function(value) {
+ return pack(coders, value);
+ },
+ decode: function(data, offset) {
+ var result = unpack(coders, data, offset);
+ result.value = coerceFunc(type, result.value);
+ return result;
+ },
+ dynamic: dynamic
+ };
+}
+/*
+function getTypes(coders) {
+ var type = coderTuple(coders).type;
+ return type.substring(6, type.length - 1);
+}
+*/
+function splitNesting(value) {
+ var result = [];
+ var accum = '';
+ var depth = 0;
+ for (var offset = 0; offset < value.length; offset++) {
+ var c = value[offset];
+ if (c === ',' && depth === 0) {
+ result.push(accum);
+ accum = '';
+ } else {
+ accum += c;
+ if (c === '(') {
+ depth++;
+ } else if (c === ')') {
+ depth--;
+ if (depth === -1) {
+ throw new Error('unbalanced parenthsis');
+ }
+ }
+ }
+ }
+ result.push(accum);
+
+ return result;
+}
+
+var paramTypeSimple = {
+ address: coderAddress,
+ bool: coderBoolean,
+ string: coderString,
+ bytes: coderDynamicBytes,
+};
+
+function getParamCoder(coerceFunc, type, localName) {
+ var coder = paramTypeSimple[type];
+ if (coder) { return coder(coerceFunc, localName); }
+
+ var match = type.match(paramTypeNumber);
+ if (match) {
+ var size = parseInt(match[2] || 256);
+ if (size === 0 || size > 256 || (size % 8) !== 0) {
+ throwError('invalid type', { type: type });
+ }
+ return coderNumber(coerceFunc, size / 8, (match[1] === 'int'), localName);
+ }
+
+ var match = type.match(paramTypeBytes);
+ if (match) {
+ var size = parseInt(match[1]);
+ if (size === 0 || size > 32) {
+ throwError('invalid type ' + type);
+ }
+ return coderFixedBytes(coerceFunc, size, localName);
+ }
+
+ var match = type.match(paramTypeArray);
+ if (match) {
+ var size = parseInt(match[2] || -1);
+ return coderArray(coerceFunc, getParamCoder(coerceFunc, match[1], localName), size, localName);
+ }
+
+ if (type.substring(0, 6) === 'tuple(' && type.substring(type.length - 1) === ')') {
+ var coders = [];
+ var names = [];
+ if (localName && typeof(localName) === 'object') {
+ if (Array.isArray(localName.names)) { names = localName.names; }
+ if (typeof(localName.name) === 'string') { localName = localName.name; }
+ }
+ splitNesting(type.substring(6, type.length - 1)).forEach(function(type, index) {
+ coders.push(getParamCoder(coerceFunc, type, names[index]));
+ });
+ return coderTuple(coerceFunc, coders, localName);
+ }
+
+ if (type === '') {
+ return coderNull(coerceFunc);
+ }
+
+ throwError('invalid type', { type: type });
+}
+
+function Coder(coerceFunc) {
+ if (!(this instanceof Coder)) { throw new Error('missing new'); }
+ if (!coerceFunc) { coerceFunc = defaultCoerceFunc; }
+ utils.defineProperty(this, 'coerceFunc', coerceFunc);
+}
+
+utils.defineProperty(Coder.prototype, 'encode', function(names, types, values) {
+
+ // Names is optional, so shift over all the parameters if not provided
+ if (arguments.length < 3) {
+ values = types;
+ types = names;
+ names = null;
+ }
+
+ if (types.length !== values.length) { throwError('types/values mismatch', {types: types, values: values}); }
+
+ var coders = [];
+ types.forEach(function(type, index) {
+ coders.push(getParamCoder(this.coerceFunc, type, (names ? names[index]: undefined)));
+ }, this);
+
+ return utils.hexlify(coderTuple(this.coerceFunc, coders).encode(values));
+});
+
+utils.defineProperty(Coder.prototype, 'decode', function(names, types, data) {
+
+ // Names is optional, so shift over all the parameters if not provided
+ if (arguments.length < 3) {
+ data = types;
+ types = names;
+ names = null;
+ }
+
+ data = utils.arrayify(data);
+
+ var coders = [];
+ types.forEach(function(type, index) {
+ coders.push(getParamCoder(this.coerceFunc, type, (names ? names[index]: undefined)));
+ }, this);
+
+ return coderTuple(this.coerceFunc, coders).decode(data, 0).value;
+
+});
+
+utils.defineProperty(Coder, 'defaultCoder', new Coder());
+
+module.exports = Coder
+
+},{"../utils/address":20,"../utils/bignumber.js":21,"../utils/convert.js":24,"../utils/properties.js":29,"../utils/throw-error":33,"../utils/utf8.js":35}],20:[function(require,module,exports){
+
+var BN = require('bn.js');
+
+var convert = require('./convert');
+var throwError = require('./throw-error');
+var keccak256 = require('./keccak256');
+
+function getChecksumAddress(address) {
+ if (typeof(address) !== 'string' || !address.match(/^0x[0-9A-Fa-f]{40}$/)) {
+ throwError('invalid address', {input: address});
+ }
+
+ address = address.toLowerCase();
+
+ var hashed = address.substring(2).split('');
+ for (var i = 0; i < hashed.length; i++) {
+ hashed[i] = hashed[i].charCodeAt(0);
+ }
+ hashed = convert.arrayify(keccak256(hashed));
+
+ address = address.substring(2).split('');
+ for (var i = 0; i < 40; i += 2) {
+ if ((hashed[i >> 1] >> 4) >= 8) {
+ address[i] = address[i].toUpperCase();
+ }
+ if ((hashed[i >> 1] & 0x0f) >= 8) {
+ address[i + 1] = address[i + 1].toUpperCase();
+ }
+ }
+
+ return '0x' + address.join('');
+}
+
+// Shims for environments that are missing some required constants and functions
+var MAX_SAFE_INTEGER = 0x1fffffffffffff;
+
+function log10(x) {
+ if (Math.log10) { return Math.log10(x); }
+ return Math.log(x) / Math.LN10;
+}
+
+
+// See: https://en.wikipedia.org/wiki/International_Bank_Account_Number
+var ibanChecksum = (function() {
+
+ // Create lookup table
+ var ibanLookup = {};
+ for (var i = 0; i < 10; i++) { ibanLookup[String(i)] = String(i); }
+ for (var i = 0; i < 26; i++) { ibanLookup[String.fromCharCode(65 + i)] = String(10 + i); }
+
+ // How many decimal digits can we process? (for 64-bit float, this is 15)
+ var safeDigits = Math.floor(log10(MAX_SAFE_INTEGER));
+
+ return function(address) {
+ address = address.toUpperCase();
+ address = address.substring(4) + address.substring(0, 2) + '00';
+
+ var expanded = address.split('');
+ for (var i = 0; i < expanded.length; i++) {
+ expanded[i] = ibanLookup[expanded[i]];
+ }
+ expanded = expanded.join('');
+
+ // Javascript can handle integers safely up to 15 (decimal) digits
+ while (expanded.length >= safeDigits){
+ var block = expanded.substring(0, safeDigits);
+ expanded = parseInt(block, 10) % 97 + expanded.substring(block.length);
+ }
+
+ var checksum = String(98 - (parseInt(expanded, 10) % 97));
+ while (checksum.length < 2) { checksum = '0' + checksum; }
+
+ return checksum;
+ };
+})();
+
+function getAddress(address, icapFormat) {
+ var result = null;
+
+ if (typeof(address) !== 'string') {
+ throwError('invalid address', {input: address});
+ }
+
+ if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
+
+ // Missing the 0x prefix
+ if (address.substring(0, 2) !== '0x') { address = '0x' + address; }
+
+ result = getChecksumAddress(address);
+
+ // It is a checksummed address with a bad checksum
+ if (address.match(/([A-F].*[a-f])|([a-f].*[A-F])/) && result !== address) {
+ throwError('invalid address checksum', { input: address, expected: result });
+ }
+
+ // Maybe ICAP? (we only support direct mode)
+ } else if (address.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
+
+ // It is an ICAP address with a bad checksum
+ if (address.substring(2, 4) !== ibanChecksum(address)) {
+ throwError('invalid address icap checksum', { input: address });
+ }
+
+ result = (new BN(address.substring(4), 36)).toString(16);
+ while (result.length < 40) { result = '0' + result; }
+ result = getChecksumAddress('0x' + result);
+
+ } else {
+ throwError('invalid address', { input: address });
+ }
+
+ if (icapFormat) {
+ var base36 = (new BN(result.substring(2), 16)).toString(36).toUpperCase();
+ while (base36.length < 30) { base36 = '0' + base36; }
+ return 'XE' + ibanChecksum('XE00' + base36) + base36;
+ }
+
+ return result;
+}
+
+
+module.exports = {
+ getAddress: getAddress,
+}
+
+},{"./convert":24,"./keccak256":27,"./throw-error":33,"bn.js":1}],21:[function(require,module,exports){
+/**
+ * BigNumber
+ *
+ * A wrapper around the BN.js object. In the future we can swap out
+ * the underlying BN.js library for something smaller.
+ */
+
+var BN = require('bn.js');
+
+var defineProperty = require('./properties').defineProperty;
+var convert = require('./convert');
+var throwError = require('./throw-error');
+
+function BigNumber(value) {
+ if (!(this instanceof BigNumber)) { throw new Error('missing new'); }
+
+ if (convert.isHexString(value)) {
+ if (value == '0x') { value = '0x0'; }
+ value = new BN(value.substring(2), 16);
+ } else if (typeof(value) === 'string' && value[0] === '-' && convert.isHexString(value.substring(1))) {
+ value = (new BN(value.substring(3), 16)).mul(BigNumber.constantNegativeOne._bn);
+
+ } else if (typeof(value) === 'string' && value.match(/^-?[0-9]*$/)) {
+ if (value == '') { value = '0'; }
+ value = new BN(value);
+
+ } else if (typeof(value) === 'number' && parseInt(value) == value) {
+ value = new BN(value);
+
+ } else if (BN.isBN(value)) {
+ //value = value
+
+ } else if (isBigNumber(value)) {
+ value = value._bn;
+
+ } else if (convert.isArrayish(value)) {
+ value = new BN(convert.hexlify(value).substring(2), 16);
+
+ } else {
+ throwError('invalid BigNumber value', { input: value });
+ }
+
+ defineProperty(this, '_bn', value);
+}
+
+defineProperty(BigNumber, 'constantNegativeOne', bigNumberify(-1));
+defineProperty(BigNumber, 'constantZero', bigNumberify(0));
+defineProperty(BigNumber, 'constantOne', bigNumberify(1));
+defineProperty(BigNumber, 'constantTwo', bigNumberify(2));
+defineProperty(BigNumber, 'constantWeiPerEther', bigNumberify(new BN('1000000000000000000')));
+
+
+defineProperty(BigNumber.prototype, 'fromTwos', function(value) {
+ return new BigNumber(this._bn.fromTwos(value));
+});
+
+defineProperty(BigNumber.prototype, 'toTwos', function(value) {
+ return new BigNumber(this._bn.toTwos(value));
+});
+
+
+defineProperty(BigNumber.prototype, 'add', function(other) {
+ return new BigNumber(this._bn.add(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'sub', function(other) {
+ return new BigNumber(this._bn.sub(bigNumberify(other)._bn));
+});
+
+
+defineProperty(BigNumber.prototype, 'div', function(other) {
+ return new BigNumber(this._bn.div(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'mul', function(other) {
+ return new BigNumber(this._bn.mul(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'mod', function(other) {
+ return new BigNumber(this._bn.mod(bigNumberify(other)._bn));
+});
+
+defineProperty(BigNumber.prototype, 'pow', function(other) {
+ return new BigNumber(this._bn.pow(bigNumberify(other)._bn));
+});
+
+
+defineProperty(BigNumber.prototype, 'maskn', function(value) {
+ return new BigNumber(this._bn.maskn(value));
+});
+
+
+
+defineProperty(BigNumber.prototype, 'eq', function(other) {
+ return this._bn.eq(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'lt', function(other) {
+ return this._bn.lt(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'lte', function(other) {
+ return this._bn.lte(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'gt', function(other) {
+ return this._bn.gt(bigNumberify(other)._bn);
+});
+
+defineProperty(BigNumber.prototype, 'gte', function(other) {
+ return this._bn.gte(bigNumberify(other)._bn);
+});
+
+
+defineProperty(BigNumber.prototype, 'isZero', function() {
+ return this._bn.isZero();
+});
+
+
+defineProperty(BigNumber.prototype, 'toNumber', function(base) {
+ return this._bn.toNumber();
+});
+
+defineProperty(BigNumber.prototype, 'toString', function() {
+ //return this._bn.toString(base || 10);
+ return this._bn.toString(10);
+});
+
+defineProperty(BigNumber.prototype, 'toHexString', function() {
+ var hex = this._bn.toString(16);
+ if (hex.length % 2) { hex = '0' + hex; }
+ return '0x' + hex;
+});
+
+
+function isBigNumber(value) {
+ return (value._bn && value._bn.mod);
+}
+
+function bigNumberify(value) {
+ if (isBigNumber(value)) { return value; }
+ return new BigNumber(value);
+}
+
+module.exports = {
+ isBigNumber: isBigNumber,
+ bigNumberify: bigNumberify,
+ BigNumber: BigNumber
+};
+
+},{"./convert":24,"./properties":29,"./throw-error":33,"bn.js":1}],22:[function(require,module,exports){
+(function (global){
+'use strict';
+
+var convert = require('./convert');
+var defineProperty = require('./properties').defineProperty;
+
+var crypto = global.crypto || global.msCrypto;
+if (!crypto || !crypto.getRandomValues) {
+
+ console.log('WARNING: Missing strong random number source; using weak randomBytes');
+
+ crypto = {
+ getRandomValues: function(buffer) {
+ for (var round = 0; round < 20; round++) {
+ for (var i = 0; i < buffer.length; i++) {
+ if (round) {
+ buffer[i] ^= parseInt(256 * Math.random());
+ } else {
+ buffer[i] = parseInt(256 * Math.random());
+ }
+ }
+ }
+
+ return buffer;
+ },
+ _weakCrypto: true
+ };
+}
+
+function randomBytes(length) {
+ if (length <= 0 || length > 1024 || parseInt(length) != length) {
+ throw new Error('invalid length');
+ }
+
+ var result = new Uint8Array(length);
+ crypto.getRandomValues(result);
+ return convert.arrayify(result);
+};
+
+if (crypto._weakCrypto === true) {
+ defineProperty(randomBytes, '_weakCrypto', true);
+}
+
+module.exports = randomBytes;
+
+}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
+},{"./convert":24,"./properties":29}],23:[function(require,module,exports){
+
+var getAddress = require('./address').getAddress;
+var convert = require('./convert');
+var keccak256 = require('./keccak256');
+var RLP = require('./rlp');
+
+// http://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed
+function getContractAddress(transaction) {
+ if (!transaction.from) { throw new Error('missing from address'); }
+ var nonce = transaction.nonce;
+
+ return getAddress('0x' + keccak256(RLP.encode([
+ getAddress(transaction.from),
+ convert.stripZeros(convert.hexlify(nonce, 'nonce'))
+ ])).substring(26));
+}
+
+module.exports = {
+ getContractAddress: getContractAddress,
+}
+
+},{"./address":20,"./convert":24,"./keccak256":27,"./rlp":30}],24:[function(require,module,exports){
+/**
+ * Conversion Utilities
+ *
+ */
+
+var defineProperty = require('./properties.js').defineProperty;
+var throwError = require('./throw-error');
+
+function addSlice(array) {
+ if (array.slice) { return array; }
+
+ array.slice = function() {
+ var args = Array.prototype.slice.call(arguments);
+ return new Uint8Array(Array.prototype.slice.apply(array, args));
+ }
+
+ return array;
+}
+
+function isArrayish(value) {
+ if (!value || parseInt(value.length) != value.length || typeof(value) === 'string') {
+ return false;
+ }
+
+ for (var i = 0; i < value.length; i++) {
+ var v = value[i];
+ if (v < 0 || v >= 256 || parseInt(v) != v) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+function arrayify(value, name) {
+
+ if (value && value.toHexString) {
+ value = value.toHexString();
+ }
+
+ if (isHexString(value)) {
+ value = value.substring(2);
+ if (value.length % 2) { value = '0' + value; }
+
+ var result = [];
+ for (var i = 0; i < value.length; i += 2) {
+ result.push(parseInt(value.substr(i, 2), 16));
+ }
+
+ return addSlice(new Uint8Array(result));
+ }
+
+ if (isArrayish(value)) {
+ return addSlice(new Uint8Array(value));
+ }
+
+ throwError('invalid arrayify value', { name: name, input: value });
+}
+
+function concat(objects) {
+ var arrays = [];
+ var length = 0;
+ for (var i = 0; i < objects.length; i++) {
+ var object = arrayify(objects[i])
+ arrays.push(object);
+ length += object.length;
+ }
+
+ var result = new Uint8Array(length);
+ var offset = 0;
+ for (var i = 0; i < arrays.length; i++) {
+ result.set(arrays[i], offset);
+ offset += arrays[i].length;
+ }
+
+ return addSlice(result);
+}
+function stripZeros(value) {
+ value = arrayify(value);
+
+ if (value.length === 0) { return value; }
+
+ // Find the first non-zero entry
+ var start = 0;
+ while (value[start] === 0) { start++ }
+
+ // If we started with zeros, strip them
+ if (start) {
+ value = value.slice(start);
+ }
+
+ return value;
+}
+
+function padZeros(value, length) {
+ value = arrayify(value);
+
+ if (length < value.length) { throw new Error('cannot pad'); }
+
+ var result = new Uint8Array(length);
+ result.set(value, length - value.length);
+ return addSlice(result);
+}
+
+
+function isHexString(value, length) {
+ if (typeof(value) !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/)) {
+ return false
+ }
+ if (length && value.length !== 2 + 2 * length) { return false; }
+ return true;
+}
+
+var HexCharacters = '0123456789abcdef';
+
+function hexlify(value, name) {
+
+ if (value && value.toHexString) {
+ return value.toHexString();
+ }
+
+ if (typeof(value) === 'number') {
+ if (value < 0) {
+ throwError('cannot hexlify negative value', { name: name, input: value });
+ }
+
+ var hex = '';
+ while (value) {
+ hex = HexCharacters[value & 0x0f] + hex;
+ value = parseInt(value / 16);
+ }
+
+ if (hex.length) {
+ if (hex.length % 2) { hex = '0' + hex; }
+ return '0x' + hex;
+ }
+
+ return '0x00';
+ }
+
+ if (isHexString(value)) {
+ if (value.length % 2) {
+ value = '0x0' + value.substring(2);
+ }
+ return value;
+ }
+
+ if (isArrayish(value)) {
+ var result = [];
+ for (var i = 0; i < value.length; i++) {
+ var v = value[i];
+ result.push(HexCharacters[(v & 0xf0) >> 4] + HexCharacters[v & 0x0f]);
+ }
+ return '0x' + result.join('');
+ }
+
+ throwError('invalid hexlify value', { name: name, input: value });
+}
+
+function hexStripZeros(value) {
+ while (value.length > 3 && value.substring(0, 3) === '0x0') {
+ value = '0x' + value.substring(3);
+ }
+ return value;
+}
+
+function hexZeroPad(value, length) {
+ while (value.length < 2 * length + 2) {
+ value = '0x0' + value.substring(2);
+ }
+ return value;
+}
+
+module.exports = {
+ arrayify: arrayify,
+ isArrayish: isArrayish,
+
+ concat: concat,
+
+ padZeros: padZeros,
+ stripZeros: stripZeros,
+
+ hexlify: hexlify,
+ isHexString: isHexString,
+ hexStripZeros: hexStripZeros,
+ hexZeroPad: hexZeroPad,
+};
+
+},{"./properties.js":29,"./throw-error":33}],25:[function(require,module,exports){
+'use strict';
+
+var keccak256 = require('./keccak256');
+var utf8 = require('./utf8');
+
+function id(text) {
+ return keccak256(utf8.toUtf8Bytes(text));
+}
+
+module.exports = id;
+
+},{"./keccak256":27,"./utf8":35}],26:[function(require,module,exports){
+'use strict';
+
+// This is SUPER useful, but adds 140kb (even zipped, adds 40kb)
+//var unorm = require('unorm');
+
+var address = require('./address');
+var AbiCoder = require('./abi-coder');
+var bigNumber = require('./bignumber');
+var contractAddress = require('./contract-address');
+var convert = require('./convert');
+var id = require('./id');
+var keccak256 = require('./keccak256');
+var namehash = require('./namehash');
+var sha256 = require('./sha2').sha256;
+var solidity = require('./solidity');
+var randomBytes = require('./random-bytes');
+var properties = require('./properties');
+var RLP = require('./rlp');
+var utf8 = require('./utf8');
+var units = require('./units');
+
+
+module.exports = {
+ AbiCoder: AbiCoder,
+
+ RLP: RLP,
+
+ defineProperty: properties.defineProperty,
+
+ // NFKD (decomposed)
+ //etherSymbol: '\uD835\uDF63',
+
+ // NFKC (composed)
+ etherSymbol: '\u039e',
+
+ arrayify: convert.arrayify,
+
+ concat: convert.concat,
+ padZeros: convert.padZeros,
+ stripZeros: convert.stripZeros,
+
+ bigNumberify: bigNumber.bigNumberify,
+ BigNumber: bigNumber.BigNumber,
+
+ hexlify: convert.hexlify,
+
+ toUtf8Bytes: utf8.toUtf8Bytes,
+ toUtf8String: utf8.toUtf8String,
+
+ namehash: namehash,
+ id: id,
+
+ getAddress: address.getAddress,
+ getContractAddress: contractAddress.getContractAddress,
+
+ formatEther: units.formatEther,
+ parseEther: units.parseEther,
+
+ formatUnits: units.formatUnits,
+ parseUnits: units.parseUnits,
+
+ keccak256: keccak256,
+ sha256: sha256,
+
+ randomBytes: randomBytes,
+
+ solidityPack: solidity.pack,
+ solidityKeccak256: solidity.keccak256,
+ soliditySha256: solidity.sha256,
+}
+
+},{"./abi-coder":19,"./address":20,"./bignumber":21,"./contract-address":23,"./convert":24,"./id":25,"./keccak256":27,"./namehash":28,"./properties":29,"./random-bytes":22,"./rlp":30,"./sha2":31,"./solidity":32,"./units":34,"./utf8":35}],27:[function(require,module,exports){
+'use strict';
+
+var sha3 = require('js-sha3');
+
+var convert = require('./convert.js');
+
+function keccak256(data) {
+ data = convert.arrayify(data);
+ return '0x' + sha3.keccak_256(data);
+}
+
+module.exports = keccak256;
+
+},{"./convert.js":24,"js-sha3":16}],28:[function(require,module,exports){
+'use strict';
+
+var convert = require('./convert');
+var utf8 = require('./utf8');
+var keccak256 = require('./keccak256');
+
+var Zeros = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
+var Partition = new RegExp("^((.*)\\.)?([^.]+)$");
+var UseSTD3ASCIIRules = new RegExp("^[a-z0-9.-]*$");
+
+function namehash(name, depth) {
+ name = name.toLowerCase();
+
+ // Supporting the full UTF-8 space requires additional (and large)
+ // libraries, so for now we simply do not support them.
+ // It should be fairly easy in the future to support systems with
+ // String.normalize, but that is future work.
+ if (!name.match(UseSTD3ASCIIRules)) {
+ throw new Error('contains invalid UseSTD3ASCIIRules characters');
+ }
+
+ var result = Zeros;
+ var processed = 0;
+ while (name.length && (!depth || processed < depth)) {
+ var partition = name.match(Partition);
+ var label = utf8.toUtf8Bytes(partition[3]);
+ result = keccak256(convert.concat([result, keccak256(label)]));
+
+ name = partition[2] || '';
+
+ processed++;
+ }
+
+ return convert.hexlify(result);
+}
+
+module.exports = namehash;
+
+
+},{"./convert":24,"./keccak256":27,"./utf8":35}],29:[function(require,module,exports){
+'use strict';
+
+function defineProperty(object, name, value) {
+ Object.defineProperty(object, name, {
+ enumerable: true,
+ value: value,
+ writable: false,
+ });
+}
+
+function defineFrozen(object, name, value) {
+ var frozen = JSON.stringify(value);
+ Object.defineProperty(object, name, {
+ enumerable: true,
+ get: function() { return JSON.parse(frozen); }
+ });
+}
+
+module.exports = {
+ defineFrozen: defineFrozen,
+ defineProperty: defineProperty,
+};
+
+},{}],30:[function(require,module,exports){
+//See: https://github.com/ethereum/wiki/wiki/RLP
+
+var convert = require('./convert.js');
+
+function arrayifyInteger(value) {
+ var result = [];
+ while (value) {
+ result.unshift(value & 0xff);
+ value >>= 8;
+ }
+ return result;
+}
+
+function unarrayifyInteger(data, offset, length) {
+ var result = 0;
+ for (var i = 0; i < length; i++) {
+ result = (result * 256) + data[offset + i];
+ }
+ return result;
+}
+
+function _encode(object) {
+ if (Array.isArray(object)) {
+ var payload = [];
+ object.forEach(function(child) {
+ payload = payload.concat(_encode(child));
+ });
+
+ if (payload.length <= 55) {
+ payload.unshift(0xc0 + payload.length)
+ return payload;
+ }
+
+ var length = arrayifyInteger(payload.length);
+ length.unshift(0xf7 + length.length);
+
+ return length.concat(payload);
+
+ } else {
+ object = [].slice.call(convert.arrayify(object));
+
+ if (object.length === 1 && object[0] <= 0x7f) {
+ return object;
+
+ } else if (object.length <= 55) {
+ object.unshift(0x80 + object.length);
+ return object
+ }
+
+ var length = arrayifyInteger(object.length);
+ length.unshift(0xb7 + length.length);
+
+ return length.concat(object);
+ }
+}
+
+function encode(object) {
+ return convert.hexlify(_encode(object));
+}
+
+function _decodeChildren(data, offset, childOffset, length) {
+ var result = [];
+
+ while (childOffset < offset + 1 + length) {
+ var decoded = _decode(data, childOffset);
+
+ result.push(decoded.result);
+
+ childOffset += decoded.consumed;
+ if (childOffset > offset + 1 + length) {
+ throw new Error('invalid rlp');
+ }
+ }
+
+ return {consumed: (1 + length), result: result};
+}
+
+// returns { consumed: number, result: Object }
+function _decode(data, offset) {
+ if (data.length === 0) { throw new Error('invalid rlp data'); }
+
+ // Array with extra length prefix
+ if (data[offset] >= 0xf8) {
+ var lengthLength = data[offset] - 0xf7;
+ if (offset + 1 + lengthLength > data.length) {
+ throw new Error('too short');
+ }
+
+ var length = unarrayifyInteger(data, offset + 1, lengthLength);
+ if (offset + 1 + lengthLength + length > data.length) {
+ throw new Error('to short');
+ }
+
+ return _decodeChildren(data, offset, offset + 1 + lengthLength, lengthLength + length);
+
+ } else if (data[offset] >= 0xc0) {
+ var length = data[offset] - 0xc0;
+ if (offset + 1 + length > data.length) {
+ throw new Error('invalid rlp data');
+ }
+
+ return _decodeChildren(data, offset, offset + 1, length);
+
+ } else if (data[offset] >= 0xb8) {
+ var lengthLength = data[offset] - 0xb7;
+ if (offset + 1 + lengthLength > data.length) {
+ throw new Error('invalid rlp data');
+ }
+
+ var length = unarrayifyInteger(data, offset + 1, lengthLength);
+ if (offset + 1 + lengthLength + length > data.length) {
+ throw new Error('invalid rlp data');
+ }
+
+ var result = convert.hexlify(data.slice(offset + 1 + lengthLength, offset + 1 + lengthLength + length));
+ return { consumed: (1 + lengthLength + length), result: result }
+
+ } else if (data[offset] >= 0x80) {
+ var length = data[offset] - 0x80;
+ if (offset + 1 + length > data.offset) {
+ throw new Error('invlaid rlp data');
+ }
+
+ var result = convert.hexlify(data.slice(offset + 1, offset + 1 + length));
+ return { consumed: (1 + length), result: result }
+ }
+ return { consumed: 1, result: convert.hexlify(data[offset]) };
+}
+
+function decode(data) {
+ data = convert.arrayify(data);
+ var decoded = _decode(data, 0);
+ if (decoded.consumed !== data.length) {
+ throw new Error('invalid rlp data');
+ }
+ return decoded.result;
+}
+
+module.exports = {
+ encode: encode,
+ decode: decode,
+}
+
+},{"./convert.js":24}],31:[function(require,module,exports){
+'use strict';
+
+var hash = require('hash.js');
+
+var convert = require('./convert.js');
+
+function sha256(data) {
+ data = convert.arrayify(data);
+ return '0x' + (hash.sha256().update(data).digest('hex'));
+}
+
+function sha512(data) {
+ data = convert.arrayify(data);
+ return '0x' + (hash.sha512().update(data).digest('hex'));
+}
+
+module.exports = {
+ sha256: sha256,
+ sha512: sha512,
+
+ createSha256: hash.sha256,
+ createSha512: hash.sha512,
+}
+
+},{"./convert.js":24,"hash.js":3}],32:[function(require,module,exports){
+'use strict';
+
+var bigNumberify = require('./bignumber').bigNumberify;
+var convert = require('./convert');
+var getAddress = require('./address').getAddress;
+var utf8 = require('./utf8');
+
+var hashKeccak256 = require('./keccak256');
+var hashSha256 = require('./sha2').sha256;
+
+var regexBytes = new RegExp("^bytes([0-9]+)$");
+var regexNumber = new RegExp("^(u?int)([0-9]*)$");
+var regexArray = new RegExp("^(.*)\\[([0-9]*)\\]$");
+
+var Zeros = '0000000000000000000000000000000000000000000000000000000000000000';
+
+function _pack(type, value, isArray) {
+ switch(type) {
+ case 'address':
+ if (isArray) { return convert.padZeros(value, 32); }
+ return convert.arrayify(value);
+ case 'string':
+ return utf8.toUtf8Bytes(value);
+ case 'bytes':
+ return convert.arrayify(value);
+ case 'bool':
+ value = (value ? '0x01': '0x00');
+ if (isArray) { return convert.padZeros(value, 32); }
+ return convert.arrayify(value);
+ }
+
+ var match = type.match(regexNumber);
+ if (match) {
+ var signed = (match[1] === 'int')
+ var size = parseInt(match[2] || "256")
+ if ((size % 8 != 0) || size === 0 || size > 256) {
+ throw new Error('invalid number type - ' + type);
+ }
+
+ if (isArray) { size = 256; }
+
+ value = bigNumberify(value).toTwos(size);
+
+ return convert.padZeros(value, size / 8);
+ }
+
+ match = type.match(regexBytes);
+ if (match) {
+ var size = match[1];
+ if (size != parseInt(size) || size === 0 || size > 32) {
+ throw new Error('invalid number type - ' + type);
+ }
+ size = parseInt(size);
+ if (convert.arrayify(value).byteLength !== size) { throw new Error('invalid value for ' + type); }
+ if (isArray) { return (value + Zeros).substring(0, 66); }
+ return value;
+ }
+
+ match = type.match(regexArray);
+ if (match) {
+ var baseType = match[1];
+ var count = parseInt(match[2] || value.length);
+ if (count != value.length) { throw new Error('invalid value for ' + type); }
+ var result = [];
+ value.forEach(function(value) {
+ value = _pack(baseType, value, true);
+ result.push(value);
+ });
+ return convert.concat(result);
+ }
+
+ throw new Error('unknown type - ' + type);
+}
+
+function pack(types, values) {
+ if (types.length != values.length) { throw new Error('type/value count mismatch'); }
+ var tight = [];
+ types.forEach(function(type, index) {
+ tight.push(_pack(type, values[index]));
+ });
+ return convert.hexlify(convert.concat(tight));
+}
+
+function keccak256(types, values) {
+ return hashKeccak256(pack(types, values));
+}
+
+function sha256(types, values) {
+ return hashSha256(pack(types, values));
+}
+
+module.exports = {
+ pack: pack,
+
+ keccak256: keccak256,
+ sha256: sha256,
+}
+
+},{"./address":20,"./bignumber":21,"./convert":24,"./keccak256":27,"./sha2":31,"./utf8":35}],33:[function(require,module,exports){
+'use strict';
+
+function throwError(message, params) {
+ var error = new Error(message);
+ for (var key in params) {
+ error[key] = params[key];
+ }
+ throw error;
+}
+
+module.exports = throwError;
+
+},{}],34:[function(require,module,exports){
+var bigNumberify = require('./bignumber.js').bigNumberify;
+var throwError = require('./throw-error');
+
+var zero = new bigNumberify(0);
+var negative1 = new bigNumberify(-1);
+
+var names = [
+ 'wei',
+ 'kwei',
+ 'Mwei',
+ 'Gwei',
+ 'szabo',
+ 'finny',
+ 'ether',
+];
+
+var getUnitInfo = (function() {
+ var unitInfos = {};
+
+ var value = '1';
+ names.forEach(function(name) {
+ var info = {
+ decimals: value.length - 1,
+ tenPower: bigNumberify(value),
+ name: name
+ };
+ unitInfos[name.toLowerCase()] = info;
+ unitInfos[String(info.decimals)] = info;
+ value += '000';
+ });
+
+ return function(name) {
+ return unitInfos[String(name).toLowerCase()];
+ }
+})();
+
+function formatUnits(value, unitType, options) {
+ if (typeof(unitType) === 'object' && !options) {
+ options = unitType;
+ unitType = undefined;
+ }
+ if (unitType == null) { unitType = 18; }
+
+ var unitInfo = getUnitInfo(unitType);
+
+ // Make sure wei is a big number (convert as necessary)
+ value = bigNumberify(value);
+
+ if (!options) { options = {}; }
+
+ var negative = value.lt(zero);
+ if (negative) { value = value.mul(negative1); }
+
+ var fraction = value.mod(unitInfo.tenPower).toString(10);
+ while (fraction.length < unitInfo.decimals) { fraction = '0' + fraction; }
+
+ // Strip off trailing zeros (but keep one if would otherwise be bare decimal point)
+ if (!options.pad) {
+ fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1];
+ }
+
+ var whole = value.div(unitInfo.tenPower).toString(10);
+
+ if (options.commify) {
+ whole = whole.replace(/\B(?=(\d{3})+(?!\d))/g, ",")
+ }
+
+ var value = whole + '.' + fraction;
+
+ if (negative) { value = '-' + value; }
+
+ return value;
+}
+
+function parseUnits(value, unitType) {
+ var unitInfo = getUnitInfo(unitType || 18);
+ if (!unitInfo) { throwError('invalid unitType', { unitType: unitType }); }
+
+ if (typeof(value) !== 'string' || !value.match(/^-?[0-9.,]+$/)) {
+ throwError('invalid value', { input: value });
+ }
+
+ // Remove commas
+ var value = value.replace(/,/g,'');
+
+ // Is it negative?
+ var negative = (value.substring(0, 1) === '-');
+ if (negative) { value = value.substring(1); }
+
+ if (value === '.') { throwError('invalid value', { input: value }); }
+
+ // Split it into a whole and fractional part
+ var comps = value.split('.');
+ if (comps.length > 2) { throwError('too many decimal points', { input: value }); }
+
+ var whole = comps[0], fraction = comps[1];
+ if (!whole) { whole = '0'; }
+ if (!fraction) { fraction = '0'; }
+
+ // Prevent underflow
+ if (fraction.length > unitInfo.decimals) {
+ throwError('too many decimal places', { input: value, decimals: fraction.length });
+ }
+
+ // Fully pad the string with zeros to get to wei
+ while (fraction.length < unitInfo.decimals) { fraction += '0'; }
+
+ whole = bigNumberify(whole);
+ fraction = bigNumberify(fraction);
+
+ var wei = (whole.mul(unitInfo.tenPower)).add(fraction);
+
+ if (negative) { wei = wei.mul(negative1); }
+
+ return wei;
+}
+
+function formatEther(wei, options) {
+ return formatUnits(wei, 18, options);
+}
+
+function parseEther(ether) {
+ return parseUnits(ether, 18);
+}
+
+module.exports = {
+ formatEther: formatEther,
+ parseEther: parseEther,
+
+ formatUnits: formatUnits,
+ parseUnits: parseUnits,
+}
+
+},{"./bignumber.js":21,"./throw-error":33}],35:[function(require,module,exports){
+
+var convert = require('./convert.js');
+
+// http://stackoverflow.com/questions/18729405/how-to-convert-utf8-string-to-byte-array
+function utf8ToBytes(str) {
+ var result = [];
+ var offset = 0;
+ for (var i = 0; i < str.length; i++) {
+ var c = str.charCodeAt(i);
+ if (c < 128) {
+ result[offset++] = c;
+ } else if (c < 2048) {
+ result[offset++] = (c >> 6) | 192;
+ result[offset++] = (c & 63) | 128;
+ } else if (((c & 0xFC00) == 0xD800) && (i + 1) < str.length && ((str.charCodeAt(i + 1) & 0xFC00) == 0xDC00)) {
+ // Surrogate Pair
+ c = 0x10000 + ((c & 0x03FF) << 10) + (str.charCodeAt(++i) & 0x03FF);
+ result[offset++] = (c >> 18) | 240;
+ result[offset++] = ((c >> 12) & 63) | 128;
+ result[offset++] = ((c >> 6) & 63) | 128;
+ result[offset++] = (c & 63) | 128;
+ } else {
+ result[offset++] = (c >> 12) | 224;
+ result[offset++] = ((c >> 6) & 63) | 128;
+ result[offset++] = (c & 63) | 128;
+ }
+ }
+
+ return convert.arrayify(result);
+};
+
+
+// http://stackoverflow.com/questions/13356493/decode-utf-8-with-javascript#13691499
+function bytesToUtf8(bytes) {
+ bytes = convert.arrayify(bytes);
+
+ var result = '';
+ var i = 0;
+
+ // Invalid bytes are ignored
+ while(i < bytes.length) {
+ var c = bytes[i++];
+ if (c >> 7 == 0) {
+ // 0xxx xxxx
+ result += String.fromCharCode(c);
+ continue;
+ }
+
+ // Invalid starting byte
+ if (c >> 6 == 0x02) { continue; }
+
+ // Multibyte; how many bytes left for thus character?
+ var extraLength = null;
+ if (c >> 5 == 0x06) {
+ extraLength = 1;
+ } else if (c >> 4 == 0x0e) {
+ extraLength = 2;
+ } else if (c >> 3 == 0x1e) {
+ extraLength = 3;
+ } else if (c >> 2 == 0x3e) {
+ extraLength = 4;
+ } else if (c >> 1 == 0x7e) {
+ extraLength = 5;
+ } else {
+ continue;
+ }
+
+ // Do we have enough bytes in our data?
+ if (i + extraLength > bytes.length) {
+
+ // If there is an invalid unprocessed byte, try to continue
+ for (; i < bytes.length; i++) {
+ if (bytes[i] >> 6 != 0x02) { break; }
+ }
+ if (i != bytes.length) continue;
+
+ // All leftover bytes are valid.
+ return result;
+ }
+
+ // Remove the UTF-8 prefix from the char (res)
+ var res = c & ((1 << (8 - extraLength - 1)) - 1);
+
+ var count;
+ for (count = 0; count < extraLength; count++) {
+ var nextChar = bytes[i++];
+
+ // Is the char valid multibyte part?
+ if (nextChar >> 6 != 0x02) {break;};
+ res = (res << 6) | (nextChar & 0x3f);
+ }
+
+ if (count != extraLength) {
+ i--;
+ continue;
+ }
+
+ if (res <= 0xffff) {
+ result += String.fromCharCode(res);
+ continue;
+ }
+
+ res -= 0x10000;
+ result += String.fromCharCode(((res >> 10) & 0x3ff) + 0xd800, (res & 0x3ff) + 0xdc00);
+ }
+
+ return result;
+}
+
+module.exports = {
+ toUtf8Bytes: utf8ToBytes,
+ toUtf8String: bytesToUtf8,
+};
+
+},{"./convert.js":24}]},{},[26])(26)
+});
\ No newline at end of file
diff --git a/dist/ethers-utils.min.js b/dist/ethers-utils.min.js
new file mode 100644
index 0000000000..4ba9a12d1e
--- /dev/null
+++ b/dist/ethers-utils.min.js
@@ -0,0 +1,3 @@
+!function(a){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=a();else if("function"==typeof define&&define.amd)define([],a);else{var b;b="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,b.ethers=a()}}(function(){return function(){function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);var j=new Error("Cannot find module '"+g+"'");throw j.code="MODULE_NOT_FOUND",j}var k=c[g]={exports:{}};b[g][0].call(k.exports,function(a){var c=b[g][1][a];return e(c?c:a)},k,k.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g=49&&g<=54?g-49+10:g>=17&&g<=22?g-17+10:15&g}return d}function h(a,b,c,d){for(var e=0,f=Math.min(a.length,c),g=b;g=49?h-49+10:h>=17?h-17+10:h}return e}function i(a){for(var b=new Array(a.bitLength()),c=0;c>>e}return b}function j(a,b,c){c.negative=b.negative^a.negative;var d=a.length+b.length|0;c.length=d,d=d-1|0;var e=0|a.words[0],f=0|b.words[0],g=e*f,h=67108863&g,i=g/67108864|0;c.words[0]=h;for(var j=1;j>>26,l=67108863&i,m=Math.min(j,b.length-1),n=Math.max(0,j-a.length+1);n<=m;n++){var o=j-n|0;e=0|a.words[o],f=0|b.words[n],g=e*f+l,k+=g/67108864|0,l=67108863&g}c.words[j]=0|l,i=0|k}return 0!==i?c.words[j]=0|i:c.length--,c.strip()}function k(a,b,c){c.negative=b.negative^a.negative,c.length=a.length+b.length;for(var d=0,e=0,f=0;f>>26)|0,e+=g>>>26,g&=67108863}c.words[f]=h,d=g,g=e}return 0!==d?c.words[f]=d:c.length--,c.strip()}function l(a,b,c){var d=new m;return d.mulp(a,b,c)}function m(a,b){this.x=a,this.y=b}function n(a,b){this.name=a,this.p=new f(b,16),this.n=this.p.bitLength(),this.k=new f(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}function o(){n.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}function p(){n.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}function q(){n.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}function r(){n.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}function s(a){if("string"==typeof a){var b=f._prime(a);this.m=b.p,this.prime=b}else d(a.gtn(1),"modulus must be greater than 1"),this.m=a,this.prime=null}function t(a){s.call(this,a),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new f(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"==typeof b?b.exports=f:c.BN=f,f.BN=f,f.wordSize=26;var u;try{u=a("buffer").Buffer}catch(v){}f.isBN=function(a){return a instanceof f||null!==a&&"object"==typeof a&&a.constructor.wordSize===f.wordSize&&Array.isArray(a.words)},f.max=function(a,b){return a.cmp(b)>0?a:b},f.min=function(a,b){return a.cmp(b)<0?a:b},f.prototype._init=function(a,b,c){if("number"==typeof a)return this._initNumber(a,b,c);if("object"==typeof a)return this._initArray(a,b,c);"hex"===b&&(b=16),d(b===(0|b)&&b>=2&&b<=36),a=a.toString().replace(/\s+/g,"");var e=0;"-"===a[0]&&e++,16===b?this._parseHex(a,e):this._parseBase(a,b,e),"-"===a[0]&&(this.negative=1),this.strip(),"le"===c&&this._initArray(this.toArray(),b,c)},f.prototype._initNumber=function(a,b,c){a<0&&(this.negative=1,a=-a),a<67108864?(this.words=[67108863&a],this.length=1):a<4503599627370496?(this.words=[67108863&a,a/67108864&67108863],this.length=2):(d(a<9007199254740992),this.words=[67108863&a,a/67108864&67108863,1],this.length=3),"le"===c&&this._initArray(this.toArray(),b,c)},f.prototype._initArray=function(a,b,c){if(d("number"==typeof a.length),a.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(a.length/3),this.words=new Array(this.length);for(var e=0;e=0;e-=3)g=a[e]|a[e-1]<<8|a[e-2]<<16,this.words[f]|=g<>>26-h&67108863,h+=24,h>=26&&(h-=26,f++);else if("le"===c)for(e=0,f=0;e>>26-h&67108863,h+=24,h>=26&&(h-=26,f++);return this.strip()},f.prototype._parseHex=function(a,b){this.length=Math.ceil((a.length-b)/6),this.words=new Array(this.length);for(var c=0;c=b;c-=6)e=g(a,c,c+6),this.words[d]|=e<>>26-f&4194303,f+=24,f>=26&&(f-=26,d++);c+6!==b&&(e=g(a,b,c+6),this.words[d]|=e<>>26-f&4194303),this.strip()},f.prototype._parseBase=function(a,b,c){this.words=[0],this.length=1;for(var d=0,e=1;e<=67108863;e*=b)d++;d--,e=e/b|0;for(var f=a.length-c,g=f%d,i=Math.min(f,f-g)+c,j=0,k=c;k1&&0===this.words[this.length-1];)this.length--;return this._normSign()},f.prototype._normSign=function(){return 1===this.length&&0===this.words[0]&&(this.negative=0),this},f.prototype.inspect=function(){return(this.red?""};var w=["","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"],x=[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],y=[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];f.prototype.toString=function(a,b){a=a||10,b=0|b||1;var c;if(16===a||"hex"===a){c="";for(var e=0,f=0,g=0;g>>24-e&16777215,c=0!==f||g!==this.length-1?w[6-i.length]+i+c:i+c,e+=2,e>=26&&(e-=26,g--)}for(0!==f&&(c=f.toString(16)+c);c.length%b!==0;)c="0"+c;return 0!==this.negative&&(c="-"+c),c}if(a===(0|a)&&a>=2&&a<=36){var j=x[a],k=y[a];c="";var l=this.clone();for(l.negative=0;!l.isZero();){var m=l.modn(k).toString(a);l=l.idivn(k),c=l.isZero()?m+c:w[j-m.length]+m+c}for(this.isZero()&&(c="0"+c);c.length%b!==0;)c="0"+c;return 0!==this.negative&&(c="-"+c),c}d(!1,"Base should be between 2 and 36")},f.prototype.toNumber=function(){var a=this.words[0];return 2===this.length?a+=67108864*this.words[1]:3===this.length&&1===this.words[2]?a+=4503599627370496+67108864*this.words[1]:this.length>2&&d(!1,"Number can only safely store up to 53 bits"),0!==this.negative?-a:a},f.prototype.toJSON=function(){return this.toString(16)},f.prototype.toBuffer=function(a,b){return d("undefined"!=typeof u),this.toArrayLike(u,a,b)},f.prototype.toArray=function(a,b){return this.toArrayLike(Array,a,b)},f.prototype.toArrayLike=function(a,b,c){var e=this.byteLength(),f=c||Math.max(1,e);d(e<=f,"byte array longer than desired length"),d(f>0,"Requested array length <= 0"),this.strip();var g,h,i="le"===b,j=new a(f),k=this.clone();if(i){for(h=0;!k.isZero();h++)g=k.andln(255),k.iushrn(8),j[h]=g;for(;h=4096&&(c+=13,b>>>=13),b>=64&&(c+=7,b>>>=7),b>=8&&(c+=4,b>>>=4),b>=2&&(c+=2,b>>>=2),c+b},f.prototype._zeroBits=function(a){if(0===a)return 26;var b=a,c=0;return 0===(8191&b)&&(c+=13,b>>>=13),0===(127&b)&&(c+=7,b>>>=7),0===(15&b)&&(c+=4,b>>>=4),0===(3&b)&&(c+=2,b>>>=2),0===(1&b)&&c++,c},f.prototype.bitLength=function(){var a=this.words[this.length-1],b=this._countBits(a);return 26*(this.length-1)+b},f.prototype.zeroBits=function(){if(this.isZero())return 0;for(var a=0,b=0;ba.length?this.clone().ior(a):a.clone().ior(this)},f.prototype.uor=function(a){return this.length>a.length?this.clone().iuor(a):a.clone().iuor(this)},f.prototype.iuand=function(a){var b;b=this.length>a.length?a:this;for(var c=0;ca.length?this.clone().iand(a):a.clone().iand(this)},f.prototype.uand=function(a){return this.length>a.length?this.clone().iuand(a):a.clone().iuand(this)},f.prototype.iuxor=function(a){var b,c;this.length>a.length?(b=this,c=a):(b=a,c=this);for(var d=0;da.length?this.clone().ixor(a):a.clone().ixor(this)},f.prototype.uxor=function(a){return this.length>a.length?this.clone().iuxor(a):a.clone().iuxor(this)},f.prototype.inotn=function(a){d("number"==typeof a&&a>=0);var b=0|Math.ceil(a/26),c=a%26;this._expand(b),c>0&&b--;for(var e=0;e0&&(this.words[e]=~this.words[e]&67108863>>26-c),this.strip()},f.prototype.notn=function(a){return this.clone().inotn(a)},f.prototype.setn=function(a,b){d("number"==typeof a&&a>=0);var c=a/26|0,e=a%26;return this._expand(c+1),b?this.words[c]=this.words[c]|1<a.length?(c=this,d=a):(c=a,d=this);for(var e=0,f=0;f>>26;for(;0!==e&&f>>26;if(this.length=c.length,0!==e)this.words[this.length]=e,this.length++;else if(c!==this)for(;fa.length?this.clone().iadd(a):a.clone().iadd(this)},f.prototype.isub=function(a){if(0!==a.negative){a.negative=0;var b=this.iadd(a);return a.negative=1,b._normSign()}if(0!==this.negative)return this.negative=0,this.iadd(a),this.negative=1,this._normSign();var c=this.cmp(a);if(0===c)return this.negative=0,this.length=1,this.words[0]=0,this;var d,e;c>0?(d=this,e=a):(d=a,e=this);for(var f=0,g=0;g>26,this.words[g]=67108863&b;for(;0!==f&&g>26,this.words[g]=67108863&b;if(0===f&&g>>13,n=0|g[1],o=8191&n,p=n>>>13,q=0|g[2],r=8191&q,s=q>>>13,t=0|g[3],u=8191&t,v=t>>>13,w=0|g[4],x=8191&w,y=w>>>13,z=0|g[5],A=8191&z,B=z>>>13,C=0|g[6],D=8191&C,E=C>>>13,F=0|g[7],G=8191&F,H=F>>>13,I=0|g[8],J=8191&I,K=I>>>13,L=0|g[9],M=8191&L,N=L>>>13,O=0|h[0],P=8191&O,Q=O>>>13,R=0|h[1],S=8191&R,T=R>>>13,U=0|h[2],V=8191&U,W=U>>>13,X=0|h[3],Y=8191&X,Z=X>>>13,$=0|h[4],_=8191&$,aa=$>>>13,ba=0|h[5],ca=8191&ba,da=ba>>>13,ea=0|h[6],fa=8191&ea,ga=ea>>>13,ha=0|h[7],ia=8191&ha,ja=ha>>>13,ka=0|h[8],la=8191&ka,ma=ka>>>13,na=0|h[9],oa=8191&na,pa=na>>>13;c.negative=a.negative^b.negative,c.length=19,d=Math.imul(l,P),e=Math.imul(l,Q),e=e+Math.imul(m,P)|0,f=Math.imul(m,Q);var qa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(qa>>>26)|0,qa&=67108863,d=Math.imul(o,P),e=Math.imul(o,Q),e=e+Math.imul(p,P)|0,f=Math.imul(p,Q),d=d+Math.imul(l,S)|0,e=e+Math.imul(l,T)|0,e=e+Math.imul(m,S)|0,f=f+Math.imul(m,T)|0;var ra=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ra>>>26)|0,ra&=67108863,d=Math.imul(r,P),e=Math.imul(r,Q),e=e+Math.imul(s,P)|0,f=Math.imul(s,Q),d=d+Math.imul(o,S)|0,e=e+Math.imul(o,T)|0,e=e+Math.imul(p,S)|0,f=f+Math.imul(p,T)|0,d=d+Math.imul(l,V)|0,e=e+Math.imul(l,W)|0,e=e+Math.imul(m,V)|0,f=f+Math.imul(m,W)|0;var sa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(sa>>>26)|0,sa&=67108863,d=Math.imul(u,P),e=Math.imul(u,Q),e=e+Math.imul(v,P)|0,f=Math.imul(v,Q),d=d+Math.imul(r,S)|0,e=e+Math.imul(r,T)|0,e=e+Math.imul(s,S)|0,f=f+Math.imul(s,T)|0,d=d+Math.imul(o,V)|0,e=e+Math.imul(o,W)|0,e=e+Math.imul(p,V)|0,f=f+Math.imul(p,W)|0,d=d+Math.imul(l,Y)|0,e=e+Math.imul(l,Z)|0,e=e+Math.imul(m,Y)|0,f=f+Math.imul(m,Z)|0;var ta=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ta>>>26)|0,ta&=67108863,d=Math.imul(x,P),e=Math.imul(x,Q),e=e+Math.imul(y,P)|0,f=Math.imul(y,Q),d=d+Math.imul(u,S)|0,e=e+Math.imul(u,T)|0,e=e+Math.imul(v,S)|0,f=f+Math.imul(v,T)|0,d=d+Math.imul(r,V)|0,e=e+Math.imul(r,W)|0,e=e+Math.imul(s,V)|0,f=f+Math.imul(s,W)|0,d=d+Math.imul(o,Y)|0,e=e+Math.imul(o,Z)|0,e=e+Math.imul(p,Y)|0,f=f+Math.imul(p,Z)|0,d=d+Math.imul(l,_)|0,e=e+Math.imul(l,aa)|0,e=e+Math.imul(m,_)|0,f=f+Math.imul(m,aa)|0;var ua=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ua>>>26)|0,ua&=67108863,d=Math.imul(A,P),e=Math.imul(A,Q),e=e+Math.imul(B,P)|0,f=Math.imul(B,Q),d=d+Math.imul(x,S)|0,e=e+Math.imul(x,T)|0,e=e+Math.imul(y,S)|0,f=f+Math.imul(y,T)|0,d=d+Math.imul(u,V)|0,e=e+Math.imul(u,W)|0,e=e+Math.imul(v,V)|0,f=f+Math.imul(v,W)|0,d=d+Math.imul(r,Y)|0,e=e+Math.imul(r,Z)|0,e=e+Math.imul(s,Y)|0,f=f+Math.imul(s,Z)|0,d=d+Math.imul(o,_)|0,e=e+Math.imul(o,aa)|0,e=e+Math.imul(p,_)|0,f=f+Math.imul(p,aa)|0,d=d+Math.imul(l,ca)|0,e=e+Math.imul(l,da)|0,e=e+Math.imul(m,ca)|0,f=f+Math.imul(m,da)|0;var va=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(va>>>26)|0,va&=67108863,d=Math.imul(D,P),e=Math.imul(D,Q),e=e+Math.imul(E,P)|0,f=Math.imul(E,Q),d=d+Math.imul(A,S)|0,e=e+Math.imul(A,T)|0,e=e+Math.imul(B,S)|0,f=f+Math.imul(B,T)|0,d=d+Math.imul(x,V)|0,e=e+Math.imul(x,W)|0,e=e+Math.imul(y,V)|0,f=f+Math.imul(y,W)|0,d=d+Math.imul(u,Y)|0,e=e+Math.imul(u,Z)|0,e=e+Math.imul(v,Y)|0,f=f+Math.imul(v,Z)|0,d=d+Math.imul(r,_)|0,e=e+Math.imul(r,aa)|0,e=e+Math.imul(s,_)|0,f=f+Math.imul(s,aa)|0,d=d+Math.imul(o,ca)|0,e=e+Math.imul(o,da)|0,e=e+Math.imul(p,ca)|0,f=f+Math.imul(p,da)|0,d=d+Math.imul(l,fa)|0,e=e+Math.imul(l,ga)|0,e=e+Math.imul(m,fa)|0,f=f+Math.imul(m,ga)|0;var wa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(wa>>>26)|0,wa&=67108863,d=Math.imul(G,P),e=Math.imul(G,Q),e=e+Math.imul(H,P)|0,f=Math.imul(H,Q),d=d+Math.imul(D,S)|0,e=e+Math.imul(D,T)|0,e=e+Math.imul(E,S)|0,f=f+Math.imul(E,T)|0,d=d+Math.imul(A,V)|0,e=e+Math.imul(A,W)|0,e=e+Math.imul(B,V)|0,f=f+Math.imul(B,W)|0,d=d+Math.imul(x,Y)|0,e=e+Math.imul(x,Z)|0,e=e+Math.imul(y,Y)|0,f=f+Math.imul(y,Z)|0,d=d+Math.imul(u,_)|0,e=e+Math.imul(u,aa)|0,e=e+Math.imul(v,_)|0,f=f+Math.imul(v,aa)|0,d=d+Math.imul(r,ca)|0,e=e+Math.imul(r,da)|0,e=e+Math.imul(s,ca)|0,f=f+Math.imul(s,da)|0,d=d+Math.imul(o,fa)|0,e=e+Math.imul(o,ga)|0,e=e+Math.imul(p,fa)|0,f=f+Math.imul(p,ga)|0,d=d+Math.imul(l,ia)|0,e=e+Math.imul(l,ja)|0,e=e+Math.imul(m,ia)|0,f=f+Math.imul(m,ja)|0;var xa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(xa>>>26)|0,xa&=67108863,d=Math.imul(J,P),e=Math.imul(J,Q),e=e+Math.imul(K,P)|0,f=Math.imul(K,Q),d=d+Math.imul(G,S)|0,e=e+Math.imul(G,T)|0,e=e+Math.imul(H,S)|0,f=f+Math.imul(H,T)|0,d=d+Math.imul(D,V)|0,e=e+Math.imul(D,W)|0,e=e+Math.imul(E,V)|0,f=f+Math.imul(E,W)|0,d=d+Math.imul(A,Y)|0,e=e+Math.imul(A,Z)|0,e=e+Math.imul(B,Y)|0,f=f+Math.imul(B,Z)|0,d=d+Math.imul(x,_)|0,e=e+Math.imul(x,aa)|0,e=e+Math.imul(y,_)|0,f=f+Math.imul(y,aa)|0,d=d+Math.imul(u,ca)|0,e=e+Math.imul(u,da)|0,e=e+Math.imul(v,ca)|0,f=f+Math.imul(v,da)|0,d=d+Math.imul(r,fa)|0,e=e+Math.imul(r,ga)|0,e=e+Math.imul(s,fa)|0,f=f+Math.imul(s,ga)|0,d=d+Math.imul(o,ia)|0,e=e+Math.imul(o,ja)|0,e=e+Math.imul(p,ia)|0,f=f+Math.imul(p,ja)|0,d=d+Math.imul(l,la)|0,e=e+Math.imul(l,ma)|0,e=e+Math.imul(m,la)|0,f=f+Math.imul(m,ma)|0;var ya=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(ya>>>26)|0,ya&=67108863,d=Math.imul(M,P),e=Math.imul(M,Q),e=e+Math.imul(N,P)|0,f=Math.imul(N,Q),d=d+Math.imul(J,S)|0,e=e+Math.imul(J,T)|0,e=e+Math.imul(K,S)|0,f=f+Math.imul(K,T)|0,d=d+Math.imul(G,V)|0,e=e+Math.imul(G,W)|0,e=e+Math.imul(H,V)|0,f=f+Math.imul(H,W)|0,d=d+Math.imul(D,Y)|0,e=e+Math.imul(D,Z)|0,e=e+Math.imul(E,Y)|0,f=f+Math.imul(E,Z)|0,d=d+Math.imul(A,_)|0,e=e+Math.imul(A,aa)|0,e=e+Math.imul(B,_)|0,f=f+Math.imul(B,aa)|0,d=d+Math.imul(x,ca)|0,e=e+Math.imul(x,da)|0,e=e+Math.imul(y,ca)|0,f=f+Math.imul(y,da)|0,d=d+Math.imul(u,fa)|0,e=e+Math.imul(u,ga)|0,e=e+Math.imul(v,fa)|0,f=f+Math.imul(v,ga)|0,d=d+Math.imul(r,ia)|0,e=e+Math.imul(r,ja)|0,e=e+Math.imul(s,ia)|0,f=f+Math.imul(s,ja)|0,d=d+Math.imul(o,la)|0,e=e+Math.imul(o,ma)|0,e=e+Math.imul(p,la)|0,f=f+Math.imul(p,ma)|0,d=d+Math.imul(l,oa)|0,e=e+Math.imul(l,pa)|0,e=e+Math.imul(m,oa)|0,f=f+Math.imul(m,pa)|0;var za=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(za>>>26)|0,za&=67108863,d=Math.imul(M,S),e=Math.imul(M,T),e=e+Math.imul(N,S)|0,f=Math.imul(N,T),d=d+Math.imul(J,V)|0,e=e+Math.imul(J,W)|0,e=e+Math.imul(K,V)|0,f=f+Math.imul(K,W)|0,d=d+Math.imul(G,Y)|0,e=e+Math.imul(G,Z)|0,e=e+Math.imul(H,Y)|0,f=f+Math.imul(H,Z)|0,d=d+Math.imul(D,_)|0,e=e+Math.imul(D,aa)|0,e=e+Math.imul(E,_)|0,f=f+Math.imul(E,aa)|0,d=d+Math.imul(A,ca)|0,e=e+Math.imul(A,da)|0,e=e+Math.imul(B,ca)|0,f=f+Math.imul(B,da)|0,d=d+Math.imul(x,fa)|0,e=e+Math.imul(x,ga)|0,e=e+Math.imul(y,fa)|0,f=f+Math.imul(y,ga)|0,d=d+Math.imul(u,ia)|0,e=e+Math.imul(u,ja)|0,e=e+Math.imul(v,ia)|0,f=f+Math.imul(v,ja)|0,d=d+Math.imul(r,la)|0,e=e+Math.imul(r,ma)|0,e=e+Math.imul(s,la)|0,f=f+Math.imul(s,ma)|0,d=d+Math.imul(o,oa)|0,e=e+Math.imul(o,pa)|0,e=e+Math.imul(p,oa)|0,f=f+Math.imul(p,pa)|0;var Aa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Aa>>>26)|0,Aa&=67108863,d=Math.imul(M,V),e=Math.imul(M,W),e=e+Math.imul(N,V)|0,f=Math.imul(N,W),d=d+Math.imul(J,Y)|0,e=e+Math.imul(J,Z)|0,e=e+Math.imul(K,Y)|0,f=f+Math.imul(K,Z)|0,d=d+Math.imul(G,_)|0,e=e+Math.imul(G,aa)|0,e=e+Math.imul(H,_)|0,f=f+Math.imul(H,aa)|0,d=d+Math.imul(D,ca)|0,e=e+Math.imul(D,da)|0,e=e+Math.imul(E,ca)|0,f=f+Math.imul(E,da)|0,d=d+Math.imul(A,fa)|0,e=e+Math.imul(A,ga)|0,e=e+Math.imul(B,fa)|0,f=f+Math.imul(B,ga)|0,d=d+Math.imul(x,ia)|0,e=e+Math.imul(x,ja)|0,e=e+Math.imul(y,ia)|0,f=f+Math.imul(y,ja)|0,d=d+Math.imul(u,la)|0,e=e+Math.imul(u,ma)|0,e=e+Math.imul(v,la)|0,f=f+Math.imul(v,ma)|0,d=d+Math.imul(r,oa)|0,e=e+Math.imul(r,pa)|0,e=e+Math.imul(s,oa)|0,f=f+Math.imul(s,pa)|0;var Ba=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ba>>>26)|0,Ba&=67108863,d=Math.imul(M,Y),e=Math.imul(M,Z),e=e+Math.imul(N,Y)|0,f=Math.imul(N,Z),d=d+Math.imul(J,_)|0,e=e+Math.imul(J,aa)|0,e=e+Math.imul(K,_)|0,f=f+Math.imul(K,aa)|0,d=d+Math.imul(G,ca)|0,e=e+Math.imul(G,da)|0,e=e+Math.imul(H,ca)|0,f=f+Math.imul(H,da)|0,d=d+Math.imul(D,fa)|0,e=e+Math.imul(D,ga)|0,e=e+Math.imul(E,fa)|0,f=f+Math.imul(E,ga)|0,d=d+Math.imul(A,ia)|0,e=e+Math.imul(A,ja)|0,e=e+Math.imul(B,ia)|0,f=f+Math.imul(B,ja)|0,d=d+Math.imul(x,la)|0,e=e+Math.imul(x,ma)|0,e=e+Math.imul(y,la)|0,f=f+Math.imul(y,ma)|0,d=d+Math.imul(u,oa)|0,e=e+Math.imul(u,pa)|0,e=e+Math.imul(v,oa)|0,f=f+Math.imul(v,pa)|0;var Ca=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ca>>>26)|0,Ca&=67108863,d=Math.imul(M,_),e=Math.imul(M,aa),e=e+Math.imul(N,_)|0,f=Math.imul(N,aa),d=d+Math.imul(J,ca)|0,e=e+Math.imul(J,da)|0,e=e+Math.imul(K,ca)|0,f=f+Math.imul(K,da)|0,d=d+Math.imul(G,fa)|0,e=e+Math.imul(G,ga)|0,e=e+Math.imul(H,fa)|0,f=f+Math.imul(H,ga)|0,d=d+Math.imul(D,ia)|0,e=e+Math.imul(D,ja)|0,e=e+Math.imul(E,ia)|0,f=f+Math.imul(E,ja)|0,d=d+Math.imul(A,la)|0,e=e+Math.imul(A,ma)|0,e=e+Math.imul(B,la)|0,f=f+Math.imul(B,ma)|0,d=d+Math.imul(x,oa)|0,e=e+Math.imul(x,pa)|0,e=e+Math.imul(y,oa)|0,f=f+Math.imul(y,pa)|0;var Da=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Da>>>26)|0,Da&=67108863,d=Math.imul(M,ca),e=Math.imul(M,da),e=e+Math.imul(N,ca)|0,f=Math.imul(N,da),d=d+Math.imul(J,fa)|0,e=e+Math.imul(J,ga)|0,e=e+Math.imul(K,fa)|0,f=f+Math.imul(K,ga)|0,d=d+Math.imul(G,ia)|0,e=e+Math.imul(G,ja)|0,e=e+Math.imul(H,ia)|0,f=f+Math.imul(H,ja)|0,d=d+Math.imul(D,la)|0,e=e+Math.imul(D,ma)|0,e=e+Math.imul(E,la)|0,f=f+Math.imul(E,ma)|0,d=d+Math.imul(A,oa)|0,e=e+Math.imul(A,pa)|0,e=e+Math.imul(B,oa)|0,f=f+Math.imul(B,pa)|0;var Ea=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ea>>>26)|0,Ea&=67108863,d=Math.imul(M,fa),e=Math.imul(M,ga),e=e+Math.imul(N,fa)|0,f=Math.imul(N,ga),d=d+Math.imul(J,ia)|0,e=e+Math.imul(J,ja)|0,e=e+Math.imul(K,ia)|0,f=f+Math.imul(K,ja)|0,d=d+Math.imul(G,la)|0,e=e+Math.imul(G,ma)|0,e=e+Math.imul(H,la)|0,f=f+Math.imul(H,ma)|0,d=d+Math.imul(D,oa)|0,e=e+Math.imul(D,pa)|0,e=e+Math.imul(E,oa)|0,f=f+Math.imul(E,pa)|0;var Fa=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Fa>>>26)|0,Fa&=67108863,d=Math.imul(M,ia),e=Math.imul(M,ja),e=e+Math.imul(N,ia)|0,f=Math.imul(N,ja),d=d+Math.imul(J,la)|0,e=e+Math.imul(J,ma)|0,e=e+Math.imul(K,la)|0,f=f+Math.imul(K,ma)|0,d=d+Math.imul(G,oa)|0,e=e+Math.imul(G,pa)|0,e=e+Math.imul(H,oa)|0,f=f+Math.imul(H,pa)|0;var Ga=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ga>>>26)|0,Ga&=67108863,d=Math.imul(M,la),e=Math.imul(M,ma),e=e+Math.imul(N,la)|0,f=Math.imul(N,ma),d=d+Math.imul(J,oa)|0,e=e+Math.imul(J,pa)|0,e=e+Math.imul(K,oa)|0,f=f+Math.imul(K,pa)|0;var Ha=(j+d|0)+((8191&e)<<13)|0;j=(f+(e>>>13)|0)+(Ha>>>26)|0,Ha&=67108863,d=Math.imul(M,oa),e=Math.imul(M,pa),e=e+Math.imul(N,oa)|0,f=Math.imul(N,pa);var Ia=(j+d|0)+((8191&e)<<13)|0;return j=(f+(e>>>13)|0)+(Ia>>>26)|0,Ia&=67108863,i[0]=qa,i[1]=ra,i[2]=sa,i[3]=ta,i[4]=ua,i[5]=va,i[6]=wa,i[7]=xa,i[8]=ya,i[9]=za,i[10]=Aa,i[11]=Ba,i[12]=Ca,i[13]=Da,i[14]=Ea,i[15]=Fa,i[16]=Ga,i[17]=Ha,i[18]=Ia,0!==j&&(i[19]=j,c.length++),c};Math.imul||(z=j),f.prototype.mulTo=function(a,b){var c,d=this.length+a.length;return c=10===this.length&&10===a.length?z(this,a,b):d<63?j(this,a,b):d<1024?k(this,a,b):l(this,a,b)},m.prototype.makeRBT=function(a){for(var b=new Array(a),c=f.prototype._countBits(a)-1,d=0;d>=1;return d},m.prototype.permute=function(a,b,c,d,e,f){for(var g=0;g>>=1)e++;return 1<>>=13,c[2*g+1]=8191&f,f>>>=13;for(g=2*b;g>=26,b+=e/67108864|0,b+=f>>>26,this.words[c]=67108863&f}return 0!==b&&(this.words[c]=b,this.length++),this},f.prototype.muln=function(a){return this.clone().imuln(a)},f.prototype.sqr=function(){return this.mul(this)},f.prototype.isqr=function(){return this.imul(this.clone())},f.prototype.pow=function(a){var b=i(a);if(0===b.length)return new f(1);for(var c=this,d=0;d=0);var b,c=a%26,e=(a-c)/26,f=67108863>>>26-c<<26-c;if(0!==c){var g=0;for(b=0;b>>26-c}g&&(this.words[b]=g,this.length++)}if(0!==e){for(b=this.length-1;b>=0;b--)this.words[b+e]=this.words[b];for(b=0;b=0);var e;e=b?(b-b%26)/26:0;var f=a%26,g=Math.min((a-f)/26,this.length),h=67108863^67108863>>>f<g)for(this.length-=g,j=0;j=0&&(0!==k||j>=e);j--){var l=0|this.words[j];this.words[j]=k<<26-f|l>>>f,k=l&h}return i&&0!==k&&(i.words[i.length++]=k),0===this.length&&(this.words[0]=0,this.length=1),this.strip()},f.prototype.ishrn=function(a,b,c){return d(0===this.negative),this.iushrn(a,b,c)},f.prototype.shln=function(a){return this.clone().ishln(a)},f.prototype.ushln=function(a){return this.clone().iushln(a)},f.prototype.shrn=function(a){return this.clone().ishrn(a)},f.prototype.ushrn=function(a){return this.clone().iushrn(a)},f.prototype.testn=function(a){d("number"==typeof a&&a>=0);var b=a%26,c=(a-b)/26,e=1<=0);var b=a%26,c=(a-b)/26;if(d(0===this.negative,"imaskn works only with positive numbers"),this.length<=c)return this;if(0!==b&&c++,this.length=Math.min(c,this.length),0!==b){var e=67108863^67108863>>>b<=67108864;b++)this.words[b]-=67108864,b===this.length-1?this.words[b+1]=1:this.words[b+1]++;return this.length=Math.max(this.length,b+1),this},f.prototype.isubn=function(a){if(d("number"==typeof a),d(a<67108864),a<0)return this.iaddn(-a);if(0!==this.negative)return this.negative=0,this.iaddn(a),this.negative=1,this;if(this.words[0]-=a,1===this.length&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var b=0;b>26)-(i/67108864|0),this.words[e+c]=67108863&g}for(;e>26,this.words[e+c]=67108863&g;if(0===h)return this.strip();for(d(h===-1),h=0,e=0;e>26,this.words[e]=67108863&g;return this.negative=1,this.strip()},f.prototype._wordDiv=function(a,b){var c=this.length-a.length,d=this.clone(),e=a,g=0|e.words[e.length-1],h=this._countBits(g);c=26-h,0!==c&&(e=e.ushln(c),d.iushln(c),g=0|e.words[e.length-1]);var i,j=d.length-e.length;if("mod"!==b){i=new f(null),i.length=j+1,i.words=new Array(i.length);for(var k=0;k=0;m--){var n=67108864*(0|d.words[e.length+m])+(0|d.words[e.length+m-1]);for(n=Math.min(n/g|0,67108863),d._ishlnsubmul(e,n,m);0!==d.negative;)n--,d.negative=0,d._ishlnsubmul(e,1,m),d.isZero()||(d.negative^=1);i&&(i.words[m]=n)}return i&&i.strip(),d.strip(),"div"!==b&&0!==c&&d.iushrn(c),{div:i||null,mod:d}},f.prototype.divmod=function(a,b,c){if(d(!a.isZero()),this.isZero())return{div:new f(0),mod:new f(0)};var e,g,h;return 0!==this.negative&&0===a.negative?(h=this.neg().divmod(a,b),"mod"!==b&&(e=h.div.neg()),"div"!==b&&(g=h.mod.neg(),c&&0!==g.negative&&g.iadd(a)),{div:e,mod:g}):0===this.negative&&0!==a.negative?(h=this.divmod(a.neg(),b),"mod"!==b&&(e=h.div.neg()),
+{div:e,mod:h.mod}):0!==(this.negative&a.negative)?(h=this.neg().divmod(a.neg(),b),"div"!==b&&(g=h.mod.neg(),c&&0!==g.negative&&g.isub(a)),{div:h.div,mod:g}):a.length>this.length||this.cmp(a)<0?{div:new f(0),mod:this}:1===a.length?"div"===b?{div:this.divn(a.words[0]),mod:null}:"mod"===b?{div:null,mod:new f(this.modn(a.words[0]))}:{div:this.divn(a.words[0]),mod:new f(this.modn(a.words[0]))}:this._wordDiv(a,b)},f.prototype.div=function(a){return this.divmod(a,"div",!1).div},f.prototype.mod=function(a){return this.divmod(a,"mod",!1).mod},f.prototype.umod=function(a){return this.divmod(a,"mod",!0).mod},f.prototype.divRound=function(a){var b=this.divmod(a);if(b.mod.isZero())return b.div;var c=0!==b.div.negative?b.mod.isub(a):b.mod,d=a.ushrn(1),e=a.andln(1),f=c.cmp(d);return f<0||1===e&&0===f?b.div:0!==b.div.negative?b.div.isubn(1):b.div.iaddn(1)},f.prototype.modn=function(a){d(a<=67108863);for(var b=(1<<26)%a,c=0,e=this.length-1;e>=0;e--)c=(b*c+(0|this.words[e]))%a;return c},f.prototype.idivn=function(a){d(a<=67108863);for(var b=0,c=this.length-1;c>=0;c--){var e=(0|this.words[c])+67108864*b;this.words[c]=e/a|0,b=e%a}return this.strip()},f.prototype.divn=function(a){return this.clone().idivn(a)},f.prototype.egcd=function(a){d(0===a.negative),d(!a.isZero());var b=this,c=a.clone();b=0!==b.negative?b.umod(a):b.clone();for(var e=new f(1),g=new f(0),h=new f(0),i=new f(1),j=0;b.isEven()&&c.isEven();)b.iushrn(1),c.iushrn(1),++j;for(var k=c.clone(),l=b.clone();!b.isZero();){for(var m=0,n=1;0===(b.words[0]&n)&&m<26;++m,n<<=1);if(m>0)for(b.iushrn(m);m-- >0;)(e.isOdd()||g.isOdd())&&(e.iadd(k),g.isub(l)),e.iushrn(1),g.iushrn(1);for(var o=0,p=1;0===(c.words[0]&p)&&o<26;++o,p<<=1);if(o>0)for(c.iushrn(o);o-- >0;)(h.isOdd()||i.isOdd())&&(h.iadd(k),i.isub(l)),h.iushrn(1),i.iushrn(1);b.cmp(c)>=0?(b.isub(c),e.isub(h),g.isub(i)):(c.isub(b),h.isub(e),i.isub(g))}return{a:h,b:i,gcd:c.iushln(j)}},f.prototype._invmp=function(a){d(0===a.negative),d(!a.isZero());var b=this,c=a.clone();b=0!==b.negative?b.umod(a):b.clone();for(var e=new f(1),g=new f(0),h=c.clone();b.cmpn(1)>0&&c.cmpn(1)>0;){for(var i=0,j=1;0===(b.words[0]&j)&&i<26;++i,j<<=1);if(i>0)for(b.iushrn(i);i-- >0;)e.isOdd()&&e.iadd(h),e.iushrn(1);for(var k=0,l=1;0===(c.words[0]&l)&&k<26;++k,l<<=1);if(k>0)for(c.iushrn(k);k-- >0;)g.isOdd()&&g.iadd(h),g.iushrn(1);b.cmp(c)>=0?(b.isub(c),e.isub(g)):(c.isub(b),g.isub(e))}var m;return m=0===b.cmpn(1)?e:g,m.cmpn(0)<0&&m.iadd(a),m},f.prototype.gcd=function(a){if(this.isZero())return a.abs();if(a.isZero())return this.abs();var b=this.clone(),c=a.clone();b.negative=0,c.negative=0;for(var d=0;b.isEven()&&c.isEven();d++)b.iushrn(1),c.iushrn(1);for(;;){for(;b.isEven();)b.iushrn(1);for(;c.isEven();)c.iushrn(1);var e=b.cmp(c);if(e<0){var f=b;b=c,c=f}else if(0===e||0===c.cmpn(1))break;b.isub(c)}return c.iushln(d)},f.prototype.invm=function(a){return this.egcd(a).a.umod(a)},f.prototype.isEven=function(){return 0===(1&this.words[0])},f.prototype.isOdd=function(){return 1===(1&this.words[0])},f.prototype.andln=function(a){return this.words[0]&a},f.prototype.bincn=function(a){d("number"==typeof a);var b=a%26,c=(a-b)/26,e=1<>>26,h&=67108863,this.words[g]=h}return 0!==f&&(this.words[g]=f,this.length++),this},f.prototype.isZero=function(){return 1===this.length&&0===this.words[0]},f.prototype.cmpn=function(a){var b=a<0;if(0!==this.negative&&!b)return-1;if(0===this.negative&&b)return 1;this.strip();var c;if(this.length>1)c=1;else{b&&(a=-a),d(a<=67108863,"Number is too big");var e=0|this.words[0];c=e===a?0:ea.length)return 1;if(this.length=0;c--){var d=0|this.words[c],e=0|a.words[c];if(d!==e){de&&(b=1);break}}return b},f.prototype.gtn=function(a){return 1===this.cmpn(a)},f.prototype.gt=function(a){return 1===this.cmp(a)},f.prototype.gten=function(a){return this.cmpn(a)>=0},f.prototype.gte=function(a){return this.cmp(a)>=0},f.prototype.ltn=function(a){return this.cmpn(a)===-1},f.prototype.lt=function(a){return this.cmp(a)===-1},f.prototype.lten=function(a){return this.cmpn(a)<=0},f.prototype.lte=function(a){return this.cmp(a)<=0},f.prototype.eqn=function(a){return 0===this.cmpn(a)},f.prototype.eq=function(a){return 0===this.cmp(a)},f.red=function(a){return new s(a)},f.prototype.toRed=function(a){return d(!this.red,"Already a number in reduction context"),d(0===this.negative,"red works only with positives"),a.convertTo(this)._forceRed(a)},f.prototype.fromRed=function(){return d(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},f.prototype._forceRed=function(a){return this.red=a,this},f.prototype.forceRed=function(a){return d(!this.red,"Already a number in reduction context"),this._forceRed(a)},f.prototype.redAdd=function(a){return d(this.red,"redAdd works only with red numbers"),this.red.add(this,a)},f.prototype.redIAdd=function(a){return d(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,a)},f.prototype.redSub=function(a){return d(this.red,"redSub works only with red numbers"),this.red.sub(this,a)},f.prototype.redISub=function(a){return d(this.red,"redISub works only with red numbers"),this.red.isub(this,a)},f.prototype.redShl=function(a){return d(this.red,"redShl works only with red numbers"),this.red.shl(this,a)},f.prototype.redMul=function(a){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.mul(this,a)},f.prototype.redIMul=function(a){return d(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.imul(this,a)},f.prototype.redSqr=function(){return d(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},f.prototype.redISqr=function(){return d(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},f.prototype.redSqrt=function(){return d(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},f.prototype.redInvm=function(){return d(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},f.prototype.redNeg=function(){return d(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},f.prototype.redPow=function(a){return d(this.red&&!a.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,a)};var A={k256:null,p224:null,p192:null,p25519:null};n.prototype._tmp=function(){var a=new f(null);return a.words=new Array(Math.ceil(this.n/13)),a},n.prototype.ireduce=function(a){var b,c=a;do this.split(c,this.tmp),c=this.imulK(c),c=c.iadd(this.tmp),b=c.bitLength();while(b>this.n);var d=b0?c.isub(this.p):c.strip(),c},n.prototype.split=function(a,b){a.iushrn(this.n,0,b)},n.prototype.imulK=function(a){return a.imul(this.k)},e(o,n),o.prototype.split=function(a,b){for(var c=4194303,d=Math.min(a.length,9),e=0;e>>22,f=g}f>>>=22,a.words[e-10]=f,0===f&&a.length>10?a.length-=10:a.length-=9},o.prototype.imulK=function(a){a.words[a.length]=0,a.words[a.length+1]=0,a.length+=2;for(var b=0,c=0;c>>=26,a.words[c]=e,b=d}return 0!==b&&(a.words[a.length++]=b),a},f._prime=function B(a){if(A[a])return A[a];var B;if("k256"===a)B=new o;else if("p224"===a)B=new p;else if("p192"===a)B=new q;else{if("p25519"!==a)throw new Error("Unknown prime "+a);B=new r}return A[a]=B,B},s.prototype._verify1=function(a){d(0===a.negative,"red works only with positives"),d(a.red,"red works only with red numbers")},s.prototype._verify2=function(a,b){d(0===(a.negative|b.negative),"red works only with positives"),d(a.red&&a.red===b.red,"red works only with red numbers")},s.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):a.umod(this.m)._forceRed(this)},s.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},s.prototype.add=function(a,b){this._verify2(a,b);var c=a.add(b);return c.cmp(this.m)>=0&&c.isub(this.m),c._forceRed(this)},s.prototype.iadd=function(a,b){this._verify2(a,b);var c=a.iadd(b);return c.cmp(this.m)>=0&&c.isub(this.m),c},s.prototype.sub=function(a,b){this._verify2(a,b);var c=a.sub(b);return c.cmpn(0)<0&&c.iadd(this.m),c._forceRed(this)},s.prototype.isub=function(a,b){this._verify2(a,b);var c=a.isub(b);return c.cmpn(0)<0&&c.iadd(this.m),c},s.prototype.shl=function(a,b){return this._verify1(a),this.imod(a.ushln(b))},s.prototype.imul=function(a,b){return this._verify2(a,b),this.imod(a.imul(b))},s.prototype.mul=function(a,b){return this._verify2(a,b),this.imod(a.mul(b))},s.prototype.isqr=function(a){return this.imul(a,a.clone())},s.prototype.sqr=function(a){return this.mul(a,a)},s.prototype.sqrt=function(a){if(a.isZero())return a.clone();var b=this.m.andln(3);if(d(b%2===1),3===b){var c=this.m.add(new f(1)).iushrn(2);return this.pow(a,c)}for(var e=this.m.subn(1),g=0;!e.isZero()&&0===e.andln(1);)g++,e.iushrn(1);d(!e.isZero());var h=new f(1).toRed(this),i=h.redNeg(),j=this.m.subn(1).iushrn(1),k=this.m.bitLength();for(k=new f(2*k*k).toRed(this);0!==this.pow(k,j).cmp(i);)k.redIAdd(i);for(var l=this.pow(k,e),m=this.pow(a,e.addn(1).iushrn(1)),n=this.pow(a,e),o=g;0!==n.cmp(h);){for(var p=n,q=0;0!==p.cmp(h);q++)p=p.redSqr();d(q=0;e--){for(var k=b.words[e],l=j-1;l>=0;l--){var m=k>>l&1;g!==d[0]&&(g=this.sqr(g)),0!==m||0!==h?(h<<=1,h|=m,i++,(i===c||0===e&&0===l)&&(g=this.mul(g,d[h]),i=0,h=0)):i=0}j=26}return g},s.prototype.convertTo=function(a){var b=a.umod(this.m);return b===a?b.clone():b},s.prototype.convertFrom=function(a){var b=a.clone();return b.red=null,b},f.mont=function(a){return new t(a)},e(t,s),t.prototype.convertTo=function(a){return this.imod(a.ushln(this.shift))},t.prototype.convertFrom=function(a){var b=this.imod(a.mul(this.rinv));return b.red=null,b},t.prototype.imul=function(a,b){if(a.isZero()||b.isZero())return a.words[0]=0,a.length=1,a;var c=a.imul(b),d=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),e=c.isub(d).iushrn(this.shift),f=e;return e.cmp(this.m)>=0?f=e.isub(this.m):e.cmpn(0)<0&&(f=e.iadd(this.m)),f._forceRed(this)},t.prototype.mul=function(a,b){if(a.isZero()||b.isZero())return new f(0)._forceRed(this);var c=a.mul(b),d=c.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),e=c.isub(d).iushrn(this.shift),g=e;return e.cmp(this.m)>=0?g=e.isub(this.m):e.cmpn(0)<0&&(g=e.iadd(this.m)),g._forceRed(this)},t.prototype.invm=function(a){var b=this.imod(a._invmp(this.m).mul(this.r2));return b._forceRed(this)}}("undefined"==typeof b||b,this)},{buffer:2}],2:[function(a,b,c){},{}],3:[function(a,b,c){var d=c;d.utils=a("./hash/utils"),d.common=a("./hash/common"),d.sha=a("./hash/sha"),d.ripemd=a("./hash/ripemd"),d.hmac=a("./hash/hmac"),d.sha1=d.sha.sha1,d.sha256=d.sha.sha256,d.sha224=d.sha.sha224,d.sha384=d.sha.sha384,d.sha512=d.sha.sha512,d.ripemd160=d.ripemd.ripemd160},{"./hash/common":4,"./hash/hmac":5,"./hash/ripemd":6,"./hash/sha":7,"./hash/utils":14}],4:[function(a,b,c){"use strict";function d(){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 e=a("./utils"),f=a("minimalistic-assert");c.BlockHash=d,d.prototype.update=function(a,b){if(a=e.toArray(a,b),this.pending?this.pending=this.pending.concat(a):this.pending=a,this.pendingTotal+=a.length,this.pending.length>=this._delta8){a=this.pending;var c=a.length%this._delta8;this.pending=a.slice(a.length-c,a.length),0===this.pending.length&&(this.pending=null),a=e.join32(a,0,a.length-c,this.endian);for(var d=0;d>>24&255,d[e++]=a>>>16&255,d[e++]=a>>>8&255,d[e++]=255&a}else for(d[e++]=255&a,d[e++]=a>>>8&255,d[e++]=a>>>16&255,d[e++]=a>>>24&255,d[e++]=0,d[e++]=0,d[e++]=0,d[e++]=0,f=8;fthis.blockSize&&(a=(new this.Hash).update(a).digest()),f(a.length<=this.blockSize);for(var b=a.length;b>>3}function k(a){return m(a,17)^m(a,19)^a>>>10}var l=a("../utils"),m=l.rotr32;c.ft_1=d,c.ch32=e,c.maj32=f,c.p32=g,c.s0_256=h,c.s1_256=i,c.g0_256=j,c.g1_256=k},{"../utils":14}],14:[function(a,b,c){"use strict";function d(a,b){if(Array.isArray(a))return a.slice();if(!a)return[];var c=[];if("string"==typeof a)if(b){if("hex"===b)for(a=a.replace(/[^a-z0-9]+/gi,""),a.length%2!==0&&(a="0"+a),d=0;d>8,g=255&e;f?c.push(f,g):c.push(g)}else for(d=0;d>>24|a>>>8&65280|a<<8&16711680|(255&a)<<24;return b>>>0}function g(a,b){for(var c="",d=0;d>>0}return f}function k(a,b){for(var c=new Array(4*a.length),d=0,e=0;d>>24,c[e+1]=f>>>16&255,c[e+2]=f>>>8&255,c[e+3]=255&f):(c[e+3]=f>>>24,c[e+2]=f>>>16&255,c[e+1]=f>>>8&255,c[e]=255&f)}return c}function l(a,b){return a>>>b|a<<32-b}function m(a,b){return a<>>32-b}function n(a,b){return a+b>>>0}function o(a,b,c){return a+b+c>>>0}function p(a,b,c,d){return a+b+c+d>>>0}function q(a,b,c,d,e){return a+b+c+d+e>>>0}function r(a,b,c,d){var e=a[b],f=a[b+1],g=d+f>>>0,h=(g>>0,a[b+1]=g}function s(a,b,c,d){var e=b+d>>>0,f=(e>>0}function t(a,b,c,d){var e=b+d;return e>>>0}function u(a,b,c,d,e,f,g,h){var i=0,j=b;j=j+d>>>0,i+=j>>0,i+=j>>0,i+=j>>0}function v(a,b,c,d,e,f,g,h){var i=b+d+f+h;return i>>>0}function w(a,b,c,d,e,f,g,h,i,j){var k=0,l=b;l=l+d>>>0,k+=l>>0,k+=l>>0,k+=l>>0,k+=l>>0}function x(a,b,c,d,e,f,g,h,i,j){var k=b+d+f+h+j;return k>>>0}function y(a,b,c){var d=b<<32-c|a>>>c;return d>>>0}function z(a,b,c){var d=a<<32-c|b>>>c;return d>>>0}function A(a,b,c){return a>>>c}function B(a,b,c){var d=a<<32-c|b>>>c;return d>>>0}var C=a("minimalistic-assert"),D=a("inherits");c.inherits=D,c.toArray=d,c.toHex=e,c.htonl=f,c.toHex32=g,c.zero2=h,c.zero8=i,c.join32=j,c.split32=k,c.rotr32=l,c.rotl32=m,c.sum32=n,c.sum32_3=o,c.sum32_4=p,c.sum32_5=q,c.sum64=r,c.sum64_hi=s,c.sum64_lo=t,c.sum64_4_hi=u,c.sum64_4_lo=v,c.sum64_5_hi=w,c.sum64_5_lo=x,c.rotr64_hi=y,c.rotr64_lo=z,c.shr64_hi=A,c.shr64_lo=B},{inherits:15,"minimalistic-assert":17}],15:[function(a,b,c){"function"==typeof Object.create?b.exports=function(a,b){a.super_=b,a.prototype=Object.create(b.prototype,{constructor:{value:a,enumerable:!1,writable:!0,configurable:!0}})}:b.exports=function(a,b){a.super_=b;var c=function(){};c.prototype=b.prototype,a.prototype=new c,a.prototype.constructor=a}},{}],16:[function(a,b,c){(function(a,c){!function(){"use strict";function d(a,b,c){this.blocks=[],this.s=[],this.padding=b,this.outputBits=c,this.reset=!0,this.block=0,this.start=0,this.blockCount=1600-(a<<1)>>5,this.byteCount=this.blockCount<<2,this.outputBlocks=c>>5,this.extraBytes=(31&c)>>3;for(var d=0;d<50;++d)this.s[d]=0}var e="object"==typeof window?window:{},f=!e.JS_SHA3_NO_NODE_JS&&"object"==typeof a&&a.versions&&a.versions.node;f&&(e=c);for(var g=!e.JS_SHA3_NO_COMMON_JS&&"object"==typeof b&&b.exports,h="0123456789abcdef".split(""),i=[31,7936,2031616,520093696],j=[1,256,65536,16777216],k=[6,1536,393216,100663296],l=[0,8,16,24],m=[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],n=[224,256,384,512],o=[128,256],p=["hex","buffer","arrayBuffer","array"],q=function(a,b,c){return function(e){return new d(a,b,a).update(e)[c]()}},r=function(a,b,c){return function(e,f){return new d(a,b,f).update(e)[c]()}},s=function(a,b){var c=q(a,b,"hex");c.create=function(){return new d(a,b,a)},c.update=function(a){return c.create().update(a)};for(var e=0;e>2]|=a[i]<>2]|=d<>2]|=(192|d>>6)<>2]|=(128|63&d)<=57344?(f[c>>2]|=(224|d>>12)<>2]|=(128|d>>6&63)<>2]|=(128|63&d)<>2]|=(240|d>>18)<>2]|=(128|d>>12&63)<>2]|=(128|d>>6&63)<>2]|=(128|63&d)<=g){for(this.start=c-g,this.block=f[h],c=0;c>2]|=this.padding[3&b],this.lastByteIndex===this.byteCount)for(a[0]=a[c],b=1;b>4&15]+h[15&a]+h[a>>12&15]+h[a>>8&15]+h[a>>20&15]+h[a>>16&15]+h[a>>28&15]+h[a>>24&15];g%b===0&&(C(c),f=0)}return e&&(a=c[f],e>0&&(i+=h[a>>4&15]+h[15&a]),e>1&&(i+=h[a>>12&15]+h[a>>8&15]),e>2&&(i+=h[a>>20&15]+h[a>>16&15])),i},d.prototype.arrayBuffer=function(){this.finalize();var a,b=this.blockCount,c=this.s,d=this.outputBlocks,e=this.extraBytes,f=0,g=0,h=this.outputBits>>3;a=e?new ArrayBuffer(d+1<<2):new ArrayBuffer(h);for(var i=new Uint32Array(a);g>8&255,i[a+2]=b>>16&255,i[a+3]=b>>24&255;h%c===0&&C(d)}return f&&(a=h<<2,b=d[g],f>0&&(i[a]=255&b),f>1&&(i[a+1]=b>>8&255),f>2&&(i[a+2]=b>>16&255)),i};var C=function(a){var b,c,d,e,f,g,h,i,j,k,l,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,$,_,aa,ba,ca,da,ea,fa,ga,ha,ia,ja,ka;for(d=0;d<48;d+=2)e=a[0]^a[10]^a[20]^a[30]^a[40],f=a[1]^a[11]^a[21]^a[31]^a[41],g=a[2]^a[12]^a[22]^a[32]^a[42],h=a[3]^a[13]^a[23]^a[33]^a[43],i=a[4]^a[14]^a[24]^a[34]^a[44],j=a[5]^a[15]^a[25]^a[35]^a[45],k=a[6]^a[16]^a[26]^a[36]^a[46],l=a[7]^a[17]^a[27]^a[37]^a[47],n=a[8]^a[18]^a[28]^a[38]^a[48],o=a[9]^a[19]^a[29]^a[39]^a[49],b=n^(g<<1|h>>>31),c=o^(h<<1|g>>>31),a[0]^=b,a[1]^=c,a[10]^=b,a[11]^=c,a[20]^=b,a[21]^=c,a[30]^=b,a[31]^=c,a[40]^=b,a[41]^=c,b=e^(i<<1|j>>>31),c=f^(j<<1|i>>>31),a[2]^=b,a[3]^=c,a[12]^=b,a[13]^=c,a[22]^=b,a[23]^=c,a[32]^=b,a[33]^=c,a[42]^=b,a[43]^=c,b=g^(k<<1|l>>>31),c=h^(l<<1|k>>>31),a[4]^=b,a[5]^=c,a[14]^=b,a[15]^=c,a[24]^=b,a[25]^=c,a[34]^=b,a[35]^=c,a[44]^=b,a[45]^=c,b=i^(n<<1|o>>>31),c=j^(o<<1|n>>>31),a[6]^=b,a[7]^=c,a[16]^=b,a[17]^=c,a[26]^=b,a[27]^=c,a[36]^=b,a[37]^=c,a[46]^=b,a[47]^=c,b=k^(e<<1|f>>>31),c=l^(f<<1|e>>>31),a[8]^=b,a[9]^=c,a[18]^=b,a[19]^=c,a[28]^=b,a[29]^=c,a[38]^=b,a[39]^=c,a[48]^=b,a[49]^=c,p=a[0],q=a[1],V=a[11]<<4|a[10]>>>28,W=a[10]<<4|a[11]>>>28,D=a[20]<<3|a[21]>>>29,E=a[21]<<3|a[20]>>>29,ha=a[31]<<9|a[30]>>>23,ia=a[30]<<9|a[31]>>>23,R=a[40]<<18|a[41]>>>14,S=a[41]<<18|a[40]>>>14,J=a[2]<<1|a[3]>>>31,K=a[3]<<1|a[2]>>>31,r=a[13]<<12|a[12]>>>20,s=a[12]<<12|a[13]>>>20,X=a[22]<<10|a[23]>>>22,Y=a[23]<<10|a[22]>>>22,F=a[33]<<13|a[32]>>>19,G=a[32]<<13|a[33]>>>19,ja=a[42]<<2|a[43]>>>30,ka=a[43]<<2|a[42]>>>30,ba=a[5]<<30|a[4]>>>2,ca=a[4]<<30|a[5]>>>2,L=a[14]<<6|a[15]>>>26,M=a[15]<<6|a[14]>>>26,t=a[25]<<11|a[24]>>>21,u=a[24]<<11|a[25]>>>21,Z=a[34]<<15|a[35]>>>17,$=a[35]<<15|a[34]>>>17,H=a[45]<<29|a[44]>>>3,I=a[44]<<29|a[45]>>>3,z=a[6]<<28|a[7]>>>4,A=a[7]<<28|a[6]>>>4,da=a[17]<<23|a[16]>>>9,ea=a[16]<<23|a[17]>>>9,N=a[26]<<25|a[27]>>>7,O=a[27]<<25|a[26]>>>7,v=a[36]<<21|a[37]>>>11,w=a[37]<<21|a[36]>>>11,_=a[47]<<24|a[46]>>>8,aa=a[46]<<24|a[47]>>>8,T=a[8]<<27|a[9]>>>5,U=a[9]<<27|a[8]>>>5,B=a[18]<<20|a[19]>>>12,C=a[19]<<20|a[18]>>>12,fa=a[29]<<7|a[28]>>>25,ga=a[28]<<7|a[29]>>>25,P=a[38]<<8|a[39]>>>24,Q=a[39]<<8|a[38]>>>24,x=a[48]<<14|a[49]>>>18,y=a[49]<<14|a[48]>>>18,a[0]=p^~r&t,a[1]=q^~s&u,a[10]=z^~B&D,a[11]=A^~C&E,a[20]=J^~L&N,a[21]=K^~M&O,a[30]=T^~V&X,a[31]=U^~W&Y,a[40]=ba^~da&fa,a[41]=ca^~ea&ga,a[2]=r^~t&v,a[3]=s^~u&w,a[12]=B^~D&F,a[13]=C^~E&G,a[22]=L^~N&P,a[23]=M^~O&Q,a[32]=V^~X&Z,a[33]=W^~Y&$,a[42]=da^~fa&ha,a[43]=ea^~ga&ia,a[4]=t^~v&x,a[5]=u^~w&y,a[14]=D^~F&H,a[15]=E^~G&I,a[24]=N^~P&R,a[25]=O^~Q&S,a[34]=X^~Z&_,a[35]=Y^~$&aa,a[44]=fa^~ha&ja,a[45]=ga^~ia&ka,a[6]=v^~x&p,a[7]=w^~y&q,a[16]=F^~H&z,a[17]=G^~I&A,
+a[26]=P^~R&J,a[27]=Q^~S&K,a[36]=Z^~_&T,a[37]=$^~aa&U,a[46]=ha^~ja&ba,a[47]=ia^~ka&ca,a[8]=x^~p&r,a[9]=y^~q&s,a[18]=H^~z&B,a[19]=I^~A&C,a[28]=R^~J&L,a[29]=S^~K&M,a[38]=_^~T&V,a[39]=aa^~U&W,a[48]=ja^~ba&da,a[49]=ka^~ca&ea,a[0]^=m[d],a[1]^=m[d+1]};if(g)b.exports=v;else for(var x=0;x=0?c:"")+"]";return{coder:b,localName:d,length:c,name:"array",type:e,encode:function(a){Array.isArray(a)||n("invalid array");var d=c,e=new Uint8Array(0);d===-1&&(d=a.length,e=v.encode(d)),d!==a.length&&n("size mismatch");var f=[];return a.forEach(function(a){f.push(b)}),o.concat([e,g(f,a)])},decode:function(d,f){var g=0,i=c;if(i===-1){var j=v.decode(d,f);i=j.value.toNumber(),g+=j.consumed,f+=j.consumed}for(var k=[],l=0;l256||f%8!==0)&&n("invalid type",{type:b}),u(a,f/8,"int"===e[1],c)}var e=b.match(p);if(e){var f=parseInt(e[1]);return(0===f||f>32)&&n("invalid type "+b),x(a,f,c)}var e=b.match(r);if(e){var f=parseInt(e[2]||-1);return i(a,l(a,e[1],c),f,c)}if("tuple("===b.substring(0,6)&&")"===b.substring(b.length-1)){var g=[],h=[];return c&&"object"==typeof c&&(Array.isArray(c.names)&&(h=c.names),"string"==typeof c.name&&(c=c.name)),k(b.substring(6,b.length-1)).forEach(function(b,c){g.push(l(a,b,h[c]))}),j(a,g,c)}return""===b?t(a):void n("invalid type",{type:b})}function m(a){if(!(this instanceof m))throw new Error("missing new");a||(a=s),o.defineProperty(this,"coerceFunc",a)}var n=a("../utils/throw-error"),o=function(){var b=a("../utils/convert.js"),c=a("../utils/utf8.js");return{defineProperty:a("../utils/properties.js").defineProperty,arrayify:b.arrayify,padZeros:b.padZeros,bigNumberify:a("../utils/bignumber.js").bigNumberify,getAddress:a("../utils/address").getAddress,concat:b.concat,toUtf8Bytes:c.toUtf8Bytes,toUtf8String:c.toUtf8String,hexlify:b.hexlify}}(),p=new RegExp(/^bytes([0-9]*)$/),q=new RegExp(/^(u?int)([0-9]*)$/),r=new RegExp(/^(.*)\[([0-9]*)\]$/),s=function(a,b){var c=a.match(q);return c&&parseInt(c[2])<=48?b.toNumber():b},t=function(a){return{name:"null",type:"",encode:function(a){return o.arrayify([])},decode:function(b,c){if(c>b.length)throw new Error("invalid null");return{consumed:0,value:a("null",void 0)}},dynamic:!1}},u=function(a,b,c,d){var e=(c?"int":"uint")+8*b;return{localName:d,name:e,type:e,encode:function(a){return a=o.bigNumberify(a).toTwos(8*b).maskn(8*b),c&&(a=a.fromTwos(8*b).toTwos(256)),o.padZeros(o.arrayify(a),32)},decode:function(d,f){var g=32-b,h=o.bigNumberify(d.slice(f+g,f+32));return h=c?h.fromTwos(8*b):h.maskn(8*b),{consumed:32,value:a(e,h)}}}},v=u(function(a,b){return b},32,!1),w=function(a,b){return{localName:b,name:"boolean",type:"boolean",encode:function(a){return v.encode(a?1:0)},decode:function(b,c){var d=v.decode(b,c);return{consumed:d.consumed,value:a("boolean",!d.value.isZero())}}}},x=function(a,b,c){var d="bytes"+b;return{localName:c,name:d,type:d,encode:function(a){if(a=o.arrayify(a),32===b)return a;var c=new Uint8Array(32);return c.set(a),c},decode:function(c,e){return c.length>1]>>4>=8&&(a[c]=a[c].toUpperCase()),(15&b[c>>1])>=8&&(a[c+1]=a[c+1].toUpperCase());return"0x"+a.join("")}function e(a){return Math.log10?Math.log10(a):Math.log(a)/Math.LN10}function f(a,b){var c=null;if("string"!=typeof a&&i("invalid address",{input:a}),a.match(/^(0x)?[0-9a-fA-F]{40}$/))"0x"!==a.substring(0,2)&&(a="0x"+a),c=d(a),a.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&c!==a&&i("invalid address checksum",{input:a,expected:c});else if(a.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(a.substring(2,4)!==l(a)&&i("invalid address icap checksum",{input:a}),c=new g(a.substring(4),36).toString(16);c.length<40;)c="0"+c;c=d("0x"+c)}else i("invalid address",{input:a});if(b){for(var e=new g(c.substring(2),16).toString(36).toUpperCase();e.length<30;)e="0"+e;return"XE"+l("XE00"+e)+e}return c}var g=a("bn.js"),h=a("./convert"),i=a("./throw-error"),j=a("./keccak256"),k=9007199254740991,l=function(){for(var a={},b=0;b<10;b++)a[String(b)]=String(b);for(var b=0;b<26;b++)a[String.fromCharCode(65+b)]=String(10+b);var c=Math.floor(e(k));return function(b){b=b.toUpperCase(),b=b.substring(4)+b.substring(0,2)+"00";for(var d=b.split(""),e=0;e=c;){var f=d.substring(0,c);d=parseInt(f,10)%97+d.substring(f.length)}for(var g=String(98-parseInt(d,10)%97);g.length<2;)g="0"+g;return g}}();b.exports={getAddress:f}},{"./convert":24,"./keccak256":27,"./throw-error":33,"bn.js":1}],21:[function(a,b,c){function d(a){if(!(this instanceof d))throw new Error("missing new");i.isHexString(a)?("0x"==a&&(a="0x0"),a=new g(a.substring(2),16)):"string"==typeof a&&"-"===a[0]&&i.isHexString(a.substring(1))?a=new g(a.substring(3),16).mul(d.constantNegativeOne._bn):"string"==typeof a&&a.match(/^-?[0-9]*$/)?(""==a&&(a="0"),a=new g(a)):"number"==typeof a&&parseInt(a)==a?a=new g(a):g.isBN(a)||(e(a)?a=a._bn:i.isArrayish(a)?a=new g(i.hexlify(a).substring(2),16):j("invalid BigNumber value",{input:a})),h(this,"_bn",a)}function e(a){return a._bn&&a._bn.mod}function f(a){return e(a)?a:new d(a)}var g=a("bn.js"),h=a("./properties").defineProperty,i=a("./convert"),j=a("./throw-error");h(d,"constantNegativeOne",f(-1)),h(d,"constantZero",f(0)),h(d,"constantOne",f(1)),h(d,"constantTwo",f(2)),h(d,"constantWeiPerEther",f(new g("1000000000000000000"))),h(d.prototype,"fromTwos",function(a){return new d(this._bn.fromTwos(a))}),h(d.prototype,"toTwos",function(a){return new d(this._bn.toTwos(a))}),h(d.prototype,"add",function(a){return new d(this._bn.add(f(a)._bn))}),h(d.prototype,"sub",function(a){return new d(this._bn.sub(f(a)._bn))}),h(d.prototype,"div",function(a){return new d(this._bn.div(f(a)._bn))}),h(d.prototype,"mul",function(a){return new d(this._bn.mul(f(a)._bn))}),h(d.prototype,"mod",function(a){return new d(this._bn.mod(f(a)._bn))}),h(d.prototype,"pow",function(a){return new d(this._bn.pow(f(a)._bn))}),h(d.prototype,"maskn",function(a){return new d(this._bn.maskn(a))}),h(d.prototype,"eq",function(a){return this._bn.eq(f(a)._bn)}),h(d.prototype,"lt",function(a){return this._bn.lt(f(a)._bn)}),h(d.prototype,"lte",function(a){return this._bn.lte(f(a)._bn)}),h(d.prototype,"gt",function(a){return this._bn.gt(f(a)._bn)}),h(d.prototype,"gte",function(a){return this._bn.gte(f(a)._bn)}),h(d.prototype,"isZero",function(){return this._bn.isZero()}),h(d.prototype,"toNumber",function(a){return this._bn.toNumber()}),h(d.prototype,"toString",function(){return this._bn.toString(10)}),h(d.prototype,"toHexString",function(){var a=this._bn.toString(16);return a.length%2&&(a="0"+a),"0x"+a}),b.exports={isBigNumber:e,bigNumberify:f,BigNumber:d}},{"./convert":24,"./properties":29,"./throw-error":33,"bn.js":1}],22:[function(a,b,c){(function(c){"use strict";function d(a){if(a<=0||a>1024||parseInt(a)!=a)throw new Error("invalid length");var b=new Uint8Array(a);return g.getRandomValues(b),e.arrayify(b)}var e=a("./convert"),f=a("./properties").defineProperty,g=c.crypto||c.msCrypto;g&&g.getRandomValues||(console.log("WARNING: Missing strong random number source; using weak randomBytes"),g={getRandomValues:function(a){for(var b=0;b<20;b++)for(var c=0;c=256||parseInt(c)!=c)return!1}return!0}function f(a,b){if(a&&a.toHexString&&(a=a.toHexString()),j(a)){a=a.substring(2),a.length%2&&(a="0"+a);for(var c=[],f=0;f>4]+o[15&g])}return"0x"+d.join("")}n("invalid hexlify value",{name:b,input:a})}function l(a){for(;a.length>3&&"0x0"===a.substring(0,3);)a="0x"+a.substring(3);return a}function m(a,b){for(;a.length<2*b+2;)a="0x0"+a.substring(2);return a}var n=(a("./properties.js").defineProperty,a("./throw-error")),o="0123456789abcdef";b.exports={arrayify:f,isArrayish:e,concat:g,padZeros:i,stripZeros:h,hexlify:k,isHexString:j,hexStripZeros:l,hexZeroPad:m}},{"./properties.js":29,"./throw-error":33}],25:[function(a,b,c){"use strict";function d(a){return e(f.toUtf8Bytes(a))}var e=a("./keccak256"),f=a("./utf8");b.exports=d},{"./keccak256":27,"./utf8":35}],26:[function(a,b,c){"use strict";var d=a("./address"),e=a("./abi-coder"),f=a("./bignumber"),g=a("./contract-address"),h=a("./convert"),i=a("./id"),j=a("./keccak256"),k=a("./namehash"),l=a("./sha2").sha256,m=a("./solidity"),n=a("./random-bytes"),o=a("./properties"),p=a("./rlp"),q=a("./utf8"),r=a("./units");b.exports={AbiCoder:e,RLP:p,defineProperty:o.defineProperty,etherSymbol:"Ξ",arrayify:h.arrayify,concat:h.concat,padZeros:h.padZeros,stripZeros:h.stripZeros,bigNumberify:f.bigNumberify,BigNumber:f.BigNumber,hexlify:h.hexlify,toUtf8Bytes:q.toUtf8Bytes,toUtf8String:q.toUtf8String,namehash:k,id:i,getAddress:d.getAddress,getContractAddress:g.getContractAddress,formatEther:r.formatEther,parseEther:r.parseEther,formatUnits:r.formatUnits,parseUnits:r.parseUnits,keccak256:j,sha256:l,randomBytes:n,solidityPack:m.pack,solidityKeccak256:m.keccak256,soliditySha256:m.sha256}},{"./abi-coder":19,"./address":20,"./bignumber":21,"./contract-address":23,"./convert":24,"./id":25,"./keccak256":27,"./namehash":28,"./properties":29,"./random-bytes":22,"./rlp":30,"./sha2":31,"./solidity":32,"./units":34,"./utf8":35}],27:[function(a,b,c){"use strict";function d(a){return a=f.arrayify(a),"0x"+e.keccak_256(a)}var e=a("js-sha3"),f=a("./convert.js");b.exports=d},{"./convert.js":24,"js-sha3":16}],28:[function(a,b,c){"use strict";function d(a,b){if(a=a.toLowerCase(),!a.match(j))throw new Error("contains invalid UseSTD3ASCIIRules characters");for(var c=h,d=0;a.length&&(!b||d>=8;return b}function e(a,b,c){for(var d=0,e=0;eb+1+d)throw new Error("invalid rlp")}return{consumed:1+d,result:e}}function i(a,b){if(0===a.length)throw new Error("invalid rlp data");if(a[b]>=248){var c=a[b]-247;if(b+1+c>a.length)throw new Error("too short");var d=e(a,b+1,c);if(b+1+c+d>a.length)throw new Error("to short");return h(a,b,b+1+c,c+d)}if(a[b]>=192){var d=a[b]-192;if(b+1+d>a.length)throw new Error("invalid rlp data");return h(a,b,b+1,d)}if(a[b]>=184){var c=a[b]-183;if(b+1+c>a.length)throw new Error("invalid rlp data");var d=e(a,b+1,c);if(b+1+c+d>a.length)throw new Error("invalid rlp data");var f=k.hexlify(a.slice(b+1+c,b+1+c+d));return{consumed:1+c+d,result:f}}if(a[b]>=128){var d=a[b]-128;if(b+1+d>a.offset)throw new Error("invlaid rlp data");var f=k.hexlify(a.slice(b+1,b+1+d));return{consumed:1+d,result:f}}return{consumed:1,result:k.hexlify(a[b])}}function j(a){a=k.arrayify(a);var b=i(a,0);if(b.consumed!==a.length)throw new Error("invalid rlp data");return b.result}var k=a("./convert.js");b.exports={encode:g,decode:j}},{"./convert.js":24}],31:[function(a,b,c){"use strict";function d(a){return a=g.arrayify(a),"0x"+f.sha256().update(a).digest("hex")}function e(a){return a=g.arrayify(a),"0x"+f.sha512().update(a).digest("hex")}var f=a("hash.js"),g=a("./convert.js");b.exports={sha256:d,sha512:e,createSha256:f.sha256,createSha512:f.sha512}},{"./convert.js":24,"hash.js":3}],32:[function(a,b,c){"use strict";function d(a,b,c){switch(a){case"address":return c?i.padZeros(b,32):i.arrayify(b);case"string":return j.toUtf8Bytes(b);case"bytes":return i.arrayify(b);case"bool":return b=b?"0x01":"0x00",c?i.padZeros(b,32):i.arrayify(b)}var e=a.match(n);if(e){var f=("int"===e[1],parseInt(e[2]||"256"));if(f%8!=0||0===f||f>256)throw new Error("invalid number type - "+a);return c&&(f=256),b=h(b).toTwos(f),i.padZeros(b,f/8)}if(e=a.match(m)){var f=e[1];if(f!=parseInt(f)||0===f||f>32)throw new Error("invalid number type - "+a);if(f=parseInt(f),i.arrayify(b).byteLength!==f)throw new Error("invalid value for "+a);return c?(b+p).substring(0,66):b}if(e=a.match(o)){var g=e[1],k=parseInt(e[2]||b.length);if(k!=b.length)throw new Error("invalid value for "+a);var l=[];return b.forEach(function(a){a=d(g,a,!0),l.push(a)}),i.concat(l)}throw new Error("unknown type - "+a)}function e(a,b){if(a.length!=b.length)throw new Error("type/value count mismatch");var c=[];return a.forEach(function(a,e){c.push(d(a,b[e]))}),i.hexlify(i.concat(c))}function f(a,b){return k(e(a,b))}function g(a,b){return l(e(a,b))}var h=a("./bignumber").bigNumberify,i=a("./convert"),j=(a("./address").getAddress,a("./utf8")),k=a("./keccak256"),l=a("./sha2").sha256,m=new RegExp("^bytes([0-9]+)$"),n=new RegExp("^(u?int)([0-9]*)$"),o=new RegExp("^(.*)\\[([0-9]*)\\]$"),p="0000000000000000000000000000000000000000000000000000000000000000";b.exports={pack:e,keccak256:f,sha256:g}},{"./address":20,"./bignumber":21,"./convert":24,"./keccak256":27,"./sha2":31,"./utf8":35}],33:[function(a,b,c){"use strict";function d(a,b){var c=new Error(a);for(var d in b)c[d]=b[d];throw c}b.exports=d},{}],34:[function(a,b,c){function d(a,b,c){"object"!=typeof b||c||(c=b,b=void 0),null==b&&(b=18);var d=m(b);a=h(a),c||(c={});var e=a.lt(j);e&&(a=a.mul(k));for(var f=a.mod(d.tenPower).toString(10);f.length2&&i("too many decimal points",{input:a});var f=e[0],g=e[1];for(f||(f="0"),g||(g="0"),g.length>c.decimals&&i("too many decimal places",{input:a,decimals:g.length});g.length>6|192,b[c++]=63&e|128):55296==(64512&e)&&d+1>18|240,b[c++]=e>>12&63|128,b[c++]=e>>6&63|128,b[c++]=63&e|128):(b[c++]=e>>12|224,b[c++]=e>>6&63|128,b[c++]=63&e|128)}return f.arrayify(b)}function e(a){a=f.arrayify(a);for(var b="",c=0;c>7!=0){if(d>>6!=2){var e=null;if(d>>5==6)e=1;else if(d>>4==14)e=2;else if(d>>3==30)e=3;else if(d>>2==62)e=4;else{if(d>>1!=126)continue;e=5}if(c+e>a.length){for(;c>6==2;c++);if(c!=a.length)continue;return b}var g,h=d&(1<<8-e-1)-1;for(g=0;g>6!=2)break;h=h<<6|63&i}g==e?h<=65535?b+=String.fromCharCode(h):(h-=65536,b+=String.fromCharCode((h>>10&1023)+55296,(1023&h)+56320)):c--}}else b+=String.fromCharCode(d)}return b}var f=a("./convert.js");b.exports={toUtf8Bytes:d,toUtf8String:e}},{"./convert.js":24}]},{},[26])(26)});
\ No newline at end of file
diff --git a/dist/ethers-wallet.js b/dist/ethers-wallet.js
new file mode 100644
index 0000000000..12dd2e4bcb
--- /dev/null
+++ b/dist/ethers-wallet.js
@@ -0,0 +1,12012 @@
+(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ethers = f()}})(function(){var define,module,exports;return (function(){function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o