├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .prettierrc.js ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── jest.config.js ├── lerna.json ├── package.json ├── packages ├── abi │ ├── CHANGELOG.md │ ├── README.md │ ├── docs │ │ ├── README.md │ │ ├── SUMMARY.md │ │ ├── classes │ │ │ ├── _abi_.abi.md │ │ │ ├── _decoder_bytestaken_.bytestaken.md │ │ │ ├── _decoder_decoder_.decoder.md │ │ │ ├── _decoder_decoderesult_.decoderesult.md │ │ │ ├── _encoder_encoder_.encoder.md │ │ │ ├── _encoder_mediate_.mediate.md │ │ │ ├── _spec_constructor_.constructor.md │ │ │ ├── _spec_event_decodedlog_.decodedlog.md │ │ │ ├── _spec_event_decodedlogparam_.decodedlogparam.md │ │ │ ├── _spec_event_event_.event.md │ │ │ ├── _spec_event_eventparam_.eventparam.md │ │ │ ├── _spec_function_.func.md │ │ │ ├── _spec_interface_.interface.md │ │ │ ├── _spec_param_.param.md │ │ │ ├── _spec_paramtype_paramtype_.paramtype.md │ │ │ └── _token_token_.token.md │ │ ├── interfaces │ │ │ ├── _types_.abiinput.md │ │ │ └── _types_.abiitem.md │ │ └── modules │ │ │ ├── _abi_.md │ │ │ ├── _decoder_bytestaken_.md │ │ │ ├── _decoder_decoder_.md │ │ │ ├── _decoder_decoderesult_.md │ │ │ ├── _encoder_encoder_.md │ │ │ ├── _encoder_mediate_.md │ │ │ ├── _spec_constructor_.md │ │ │ ├── _spec_event_decodedlog_.md │ │ │ ├── _spec_event_decodedlogparam_.md │ │ │ ├── _spec_event_event_.md │ │ │ ├── _spec_event_eventparam_.md │ │ │ ├── _spec_function_.md │ │ │ ├── _spec_interface_.md │ │ │ ├── _spec_param_.md │ │ │ ├── _spec_paramtype_format_.md │ │ │ ├── _spec_paramtype_paramtype_.md │ │ │ ├── _spec_paramtype_types_.md │ │ │ ├── _token_token_.md │ │ │ ├── _types_.md │ │ │ ├── _util_address_.md │ │ │ ├── _util_pad_.md │ │ │ ├── _util_signature_.md │ │ │ ├── _util_slice_.md │ │ │ ├── _util_sliceas_.md │ │ │ └── _util_types_.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── abi.ts │ │ ├── decoder │ │ │ ├── bytesTaken.spec.ts │ │ │ ├── bytesTaken.ts │ │ │ ├── decodeResult.spec.ts │ │ │ ├── decodeResult.ts │ │ │ ├── decoder.spec.ts │ │ │ ├── decoder.ts │ │ │ └── index.ts │ │ ├── encoder │ │ │ ├── encoder.spec.ts │ │ │ ├── encoder.ts │ │ │ ├── index.ts │ │ │ ├── mediate.spec.ts │ │ │ └── mediate.ts │ │ ├── index.ts │ │ ├── spec │ │ │ ├── constructor.spec.ts │ │ │ ├── constructor.ts │ │ │ ├── event │ │ │ │ ├── decodedLog.spec.ts │ │ │ │ ├── decodedLog.ts │ │ │ │ ├── decodedLogParam.spec.ts │ │ │ │ ├── decodedLogParam.ts │ │ │ │ ├── event.spec.ts │ │ │ │ ├── event.ts │ │ │ │ ├── eventParam.spec.ts │ │ │ │ ├── eventParam.ts │ │ │ │ └── index.ts │ │ │ ├── function.spec.ts │ │ │ ├── function.ts │ │ │ ├── index.ts │ │ │ ├── interface.spec.ts │ │ │ ├── interface.ts │ │ │ ├── param.spec.ts │ │ │ ├── param.ts │ │ │ └── paramType │ │ │ │ ├── format.spec.ts │ │ │ │ ├── format.ts │ │ │ │ ├── index.ts │ │ │ │ ├── paramType.spec.ts │ │ │ │ ├── paramType.ts │ │ │ │ └── types.ts │ │ ├── token │ │ │ ├── index.ts │ │ │ ├── token.spec.ts │ │ │ └── token.ts │ │ ├── types.ts │ │ └── util │ │ │ ├── address.spec.ts │ │ │ ├── address.ts │ │ │ ├── pad.spec.ts │ │ │ ├── pad.ts │ │ │ ├── signature.spec.ts │ │ │ ├── signature.ts │ │ │ ├── slice.spec.ts │ │ │ ├── slice.ts │ │ │ ├── sliceAs.spec.ts │ │ │ ├── sliceAs.ts │ │ │ ├── types.spec.ts │ │ │ └── types.ts │ ├── tsconfig.json │ └── typedoc.js ├── api │ ├── CHANGELOG.md │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── api.js │ │ ├── api.spec.js │ │ ├── contract │ │ │ ├── contract.js │ │ │ ├── contract.spec.js │ │ │ └── index.js │ │ ├── format │ │ │ ├── input.spec.ts │ │ │ ├── input.ts │ │ │ ├── output.spec.ts │ │ │ ├── output.ts │ │ │ └── types.serialized.ts │ │ ├── index.js │ │ ├── library.js │ │ ├── polyfill.js │ │ ├── provider │ │ │ ├── current.js │ │ │ ├── current.spec.js │ │ │ ├── http.js │ │ │ ├── http.spec.js │ │ │ ├── index.js │ │ │ ├── ipc.js │ │ │ ├── ipc.spec.js │ │ │ ├── postMessage.js │ │ │ ├── postMessage.spec.js │ │ │ ├── promise.js │ │ │ ├── sendAsync.js │ │ │ ├── sendAsync.spec.js │ │ │ ├── ws.js │ │ │ └── ws.spec.js │ │ ├── pubsub │ │ │ ├── eth │ │ │ │ ├── eth.js │ │ │ │ └── index.js │ │ │ ├── index.js │ │ │ ├── net │ │ │ │ ├── index.js │ │ │ │ └── net.js │ │ │ ├── parity │ │ │ │ ├── index.js │ │ │ │ └── parity.js │ │ │ ├── pubsub.js │ │ │ ├── pubsub.spec.js │ │ │ ├── pubsubBase.js │ │ │ └── signer │ │ │ │ ├── index.js │ │ │ │ └── signer.js │ │ ├── rpc │ │ │ ├── db │ │ │ │ ├── db.js │ │ │ │ ├── db.spec.js │ │ │ │ └── index.js │ │ │ ├── eth │ │ │ │ ├── eth.e2e.js │ │ │ │ ├── eth.js │ │ │ │ ├── eth.spec.js │ │ │ │ └── index.js │ │ │ ├── index.js │ │ │ ├── net │ │ │ │ ├── index.js │ │ │ │ ├── net.e2e.js │ │ │ │ ├── net.js │ │ │ │ └── net.spec.js │ │ │ ├── parity │ │ │ │ ├── index.js │ │ │ │ ├── parity.e2e.js │ │ │ │ ├── parity.js │ │ │ │ └── parity.spec.js │ │ │ ├── personal │ │ │ │ ├── index.js │ │ │ │ ├── personal.e2e.js │ │ │ │ ├── personal.js │ │ │ │ └── personal.spec.js │ │ │ ├── private │ │ │ │ ├── index.js │ │ │ │ └── private.js │ │ │ ├── shell │ │ │ │ ├── index.js │ │ │ │ └── shell.js │ │ │ ├── shh │ │ │ │ ├── index.js │ │ │ │ └── shh.js │ │ │ ├── signer │ │ │ │ ├── index.js │ │ │ │ └── signer.js │ │ │ ├── trace │ │ │ │ ├── index.js │ │ │ │ ├── trace.e2e.js │ │ │ │ ├── trace.js │ │ │ │ └── trace.spec.js │ │ │ └── web3 │ │ │ │ ├── index.js │ │ │ │ ├── web3.e2e.js │ │ │ │ ├── web3.js │ │ │ │ └── web3.spec.js │ │ ├── subscriptions │ │ │ ├── eth.js │ │ │ ├── eth.spec.js │ │ │ ├── index.js │ │ │ ├── logging.js │ │ │ ├── logging.spec.js │ │ │ ├── manager.js │ │ │ ├── manager.spec.js │ │ │ ├── personal.js │ │ │ ├── personal.spec.js │ │ │ └── signer.js │ │ ├── transport │ │ │ ├── error.js │ │ │ ├── error.spec.js │ │ │ ├── http │ │ │ │ ├── http.e2e.js │ │ │ │ ├── http.js │ │ │ │ ├── http.spec.js │ │ │ │ └── index.js │ │ │ ├── index.js │ │ │ ├── jsonRpcBase.js │ │ │ ├── jsonRpcBase.spec.js │ │ │ ├── jsonRpcEncoder.js │ │ │ ├── jsonRpcEncoder.spec.js │ │ │ ├── middleware.js │ │ │ ├── middleware.spec.js │ │ │ └── ws │ │ │ │ ├── index.js │ │ │ │ ├── polyfill.js │ │ │ │ ├── ws.e2e.js │ │ │ │ ├── ws.js │ │ │ │ └── ws.spec.js │ │ ├── types.ts │ │ └── util │ │ │ ├── address.ts │ │ │ ├── decode.spec.ts │ │ │ ├── decode.ts │ │ │ ├── encode.spec.ts │ │ │ ├── encode.ts │ │ │ ├── format.spec.ts │ │ │ ├── format.ts │ │ │ ├── index.ts │ │ │ ├── sha3.spec.ts │ │ │ ├── sha3.ts │ │ │ ├── types.spec.ts │ │ │ ├── types.ts │ │ │ ├── wei.spec.ts │ │ │ └── wei.ts │ ├── test │ │ ├── mocha.config.js │ │ ├── mocha.opts │ │ ├── mockRpc.js │ │ └── types.js │ └── tsconfig.json ├── contracts │ ├── CHANGELOG.md │ ├── README.md │ ├── docs │ │ ├── SUMMARY.md │ │ ├── classes │ │ │ ├── _badgereg_.badgereg.md │ │ │ ├── _contracts_.contracts.md │ │ │ ├── _dappreg_.dappreg.md │ │ │ ├── _githubhint_.githubhint.md │ │ │ ├── _registry_.registry.md │ │ │ ├── _signaturereg_.signaturereg.md │ │ │ └── _tokenreg_.tokenreg.md │ │ ├── interfaces │ │ │ ├── _badgereg_.metadata.md │ │ │ └── _registry_.queueitem.md │ │ └── modules │ │ │ ├── _badgereg_.md │ │ │ ├── _code_wallet_.md │ │ │ ├── _contracts_.md │ │ │ ├── _dappreg_.md │ │ │ ├── _githubhint_.md │ │ │ ├── _registry_.md │ │ │ ├── _signaturereg_.md │ │ │ ├── _tokenreg_.md │ │ │ └── _utils_testhelpers_.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── abi │ │ │ ├── badgereg.json │ │ │ ├── basiccoin.json │ │ │ ├── basiccoinmanager.json │ │ │ ├── certifier.json │ │ │ ├── consensys-multisig-wallet.json │ │ │ ├── dappreg.json │ │ │ ├── eip20.json │ │ │ ├── email-verification.json │ │ │ ├── foundation-multisig-wallet.json │ │ │ ├── gavcoin.json │ │ │ ├── githubhint.json │ │ │ ├── index.ts │ │ │ ├── old-wallet.json │ │ │ ├── owned.json │ │ │ ├── registry.json │ │ │ ├── registry2.json │ │ │ ├── signaturereg.json │ │ │ ├── sms-verification.json │ │ │ ├── tokenreg.json │ │ │ ├── vouchfor.json │ │ │ └── wallet.json │ │ ├── ambient.d.ts │ │ ├── badgereg.ts │ │ ├── code │ │ │ ├── index.ts │ │ │ └── wallet.ts │ │ ├── contracts.ts │ │ ├── dappreg.ts │ │ ├── githubhint.spec.ts │ │ ├── githubhint.ts │ │ ├── index.ts │ │ ├── registry.spec.ts │ │ ├── registry.ts │ │ ├── signaturereg.ts │ │ ├── snippets │ │ │ ├── enhanced-wallet.sol │ │ │ ├── human-standard-token.sol │ │ │ ├── standard-token.sol │ │ │ ├── token.sol │ │ │ └── wallet.sol │ │ ├── tokenreg.ts │ │ ├── types.d.ts │ │ └── utils │ │ │ └── testHelpers.ts │ ├── tsconfig.json │ └── typedoc.js ├── electron │ ├── CHANGELOG.md │ ├── README.md │ ├── docs │ │ ├── README.md │ │ └── interfaces │ │ │ ├── checkclocksyncresult.md │ │ │ ├── fetchparityoptions.md │ │ │ ├── isparityrunningoptions.md │ │ │ ├── parityelectronoptions.md │ │ │ └── runparityoptions.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── README.md │ │ ├── ambient.d.ts │ │ ├── checkClockSync.spec.ts │ │ ├── checkClockSync.ts │ │ ├── fetchParity.ts │ │ ├── getParityPath.ts │ │ ├── index.ts │ │ ├── isParityRunning.ts │ │ ├── runParity.ts │ │ ├── signerNewToken.ts │ │ ├── types.d.ts │ │ └── utils │ │ │ ├── logCommand.spec.ts │ │ │ ├── logCommand.ts │ │ │ ├── logger.spec.ts │ │ │ └── logger.ts │ ├── tsconfig.json │ └── typedoc.js ├── light.js-react │ ├── .npmignore │ ├── CHANGELOG.md │ ├── README.md │ ├── jest.config.js │ ├── package.json │ ├── src │ │ ├── ambient.d.ts │ │ ├── index.spec.tsx │ │ └── index.ts │ └── tsconfig.json └── light.js │ ├── .npmignore │ ├── CHANGELOG.md │ ├── README.md │ ├── docs │ ├── README.md │ ├── SUMMARY.md │ ├── api │ │ ├── README.md │ │ ├── SUMMARY.md │ │ ├── interfaces │ │ │ ├── _rpc_other_makecontract_.makecontract.md │ │ │ ├── _rpc_other_post_.postoptions.md │ │ │ ├── _types_.__global.window.md │ │ │ ├── _types_.frequencyobservable.md │ │ │ ├── _types_.frequencyobservableoptions.md │ │ │ ├── _types_.makecontract.md │ │ │ ├── _types_.metadata.md │ │ │ ├── _types_.rpcobservable.md │ │ │ ├── _types_.rpcobservableoptions.md │ │ │ ├── _types_.txstatus.md │ │ │ └── _utils_operators_switchmappromise_.switchmappromiseoptions.md │ │ └── modules │ │ │ ├── _api_.md │ │ │ ├── _frequency_accounts_.md │ │ │ ├── _frequency_blocks_.md │ │ │ ├── _frequency_frequency_.md │ │ │ ├── _frequency_health_.md │ │ │ ├── _frequency_other_.md │ │ │ ├── _frequency_time_.md │ │ │ ├── _frequency_utils_createpubsubobservable_.md │ │ │ ├── _rpc_eth_.md │ │ │ ├── _rpc_net_.md │ │ │ ├── _rpc_other_makecontract_.md │ │ │ ├── _rpc_other_post_.md │ │ │ ├── _rpc_parity_.md │ │ │ ├── _rpc_rpc_.md │ │ │ ├── _rpc_utils_createrpc_.md │ │ │ ├── _types_.__global.md │ │ │ ├── _types_.md │ │ │ ├── _utils_isobservable_.md │ │ │ ├── _utils_operators_distinctreplayrefcountdelay_.md │ │ │ ├── _utils_operators_distinctvalues_.md │ │ │ ├── _utils_operators_switchmappromise_.md │ │ │ ├── _utils_testhelpers_mockapi_.md │ │ │ ├── _utils_testhelpers_mockrpc_.md │ │ │ └── _utils_testhelpers_sleep_.md │ ├── concepts │ │ ├── light-client-development.md │ │ ├── reactive-programming.md │ │ ├── rpc-observables-properties.md │ │ └── rpc-observables.md │ ├── getting-started │ │ ├── does-it-work-with-a-full-node.md │ │ └── installation.md │ └── guides │ │ ├── tutorial1-set-up-a-light-client.md │ │ ├── tutorial2-our-first-rpcobservable.md │ │ ├── tutorial3-manipulating-rpcobservables.md │ │ ├── tutorial4-send-a-transaction.md │ │ ├── tutorial5-work-with-contracts.md │ │ └── tutorial6-integrate-with-react.md │ ├── example-react │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── public │ │ ├── favicon.ico │ │ ├── index.html │ │ └── manifest.json │ ├── src │ │ ├── App.css │ │ ├── App.js │ │ ├── App.test.js │ │ ├── BalanceOf │ │ │ ├── Balance.js │ │ │ ├── BalanceOfAddress │ │ │ │ ├── BalanceOfAddress.js │ │ │ │ └── index.js │ │ │ ├── gavcoin.js │ │ │ └── index.js │ │ ├── BlockNumber │ │ │ ├── BlockNumber.js │ │ │ └── index.js │ │ ├── PeerCount │ │ │ ├── PeerCount.js │ │ │ └── index.js │ │ ├── index.css │ │ ├── index.js │ │ ├── logo.svg │ │ ├── provider.js │ │ └── serviceWorker.js │ └── yarn.lock │ ├── jest.config.js │ ├── package.json │ ├── src │ ├── ambient.d.ts │ ├── api.spec.ts │ ├── api.ts │ ├── frequency │ │ ├── accounts.ts │ │ ├── blocks.ts │ │ ├── frequency.spec.ts │ │ ├── frequency.ts │ │ ├── health.ts │ │ ├── index.ts │ │ ├── other.ts │ │ ├── time.ts │ │ └── utils │ │ │ ├── createPubsubObservable.spec.ts │ │ │ └── createPubsubObservable.ts │ ├── index.ts │ ├── rpc │ │ ├── README.md │ │ ├── eth.ts │ │ ├── index.ts │ │ ├── net.ts │ │ ├── other │ │ │ ├── index.ts │ │ │ ├── makeContract.ts │ │ │ └── post.ts │ │ ├── parity.ts │ │ ├── rpc.spec.ts │ │ ├── rpc.ts │ │ └── utils │ │ │ ├── createRpc.spec.ts │ │ │ └── createRpc.ts │ ├── types.ts │ └── utils │ │ ├── index.ts │ │ ├── isObservable.spec.ts │ │ ├── isObservable.ts │ │ ├── operators │ │ ├── distinctReplayRefCountDelay.spec.ts │ │ ├── distinctReplayRefCountDelay.ts │ │ ├── distinctValues.spec.ts │ │ ├── distinctValues.ts │ │ ├── index.ts │ │ ├── switchMapPromise.spec.ts │ │ └── switchMapPromise.ts │ │ └── testHelpers │ │ ├── mockApi.ts │ │ ├── mockRpc.ts │ │ └── sleep.ts │ ├── tsconfig.json │ └── typedoc.js ├── scripts ├── lerna-publish.sh ├── lint-files.sh └── update-docs.sh ├── tsconfig.json └── yarn.lock /.eslintignore: -------------------------------------------------------------------------------- 1 | **/node_modules/** 2 | **/lib/** 3 | **/example/** 4 | packages/light.js/example-react 5 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | ecmaVersion: 2018, 5 | sourceType: 'module', 6 | }, 7 | plugins: ['@typescript-eslint'], 8 | extends: [ 9 | 'semistandard', 10 | 'plugin:@typescript-eslint/recommended' 11 | ], 12 | rules: { 13 | '@typescript-eslint/camelcase': ['error', { allow: ['keccak_256'] }], 14 | '@typescript-eslint/no-unused-vars': [1, { argsIgnorePattern: '^_' }], 15 | 16 | // TODO: Remove all of these disabled rules. 17 | '@typescript-eslint/ban-ts-ignore': 'off', 18 | '@typescript-eslint/explicit-function-return-type': 'off', 19 | '@typescript-eslint/no-explicit-any': 'off', 20 | }, 21 | overrides: [ 22 | { 23 | files: ['*.spec.{ts,tsx}', 'testHelpers.ts'], 24 | env: { 25 | jest: true, 26 | }, 27 | plugins: ['jest'], 28 | }, 29 | ], 30 | }; 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | 6 | # testing 7 | coverage 8 | 9 | # production 10 | build 11 | dist 12 | lib 13 | 14 | # logs 15 | *.log* 16 | 17 | # os-generated files 18 | .DS_Store 19 | 20 | # generated docs 21 | _book 22 | gh_pages 23 | 24 | # npm 25 | .npmrc 26 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | printWidth: 80, 3 | semi: true, 4 | singleQuote: true, 5 | tabWidth: 2, 6 | trailingComma: 'es5', 7 | }; 8 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | cache: 2 | yarn: true 3 | directories: 4 | - node_modules 5 | before_install: 6 | - curl -o- -L https://yarnpkg.com/install.sh | bash # Travis's default version is 1.3.2, we need 1.4.2 for nohoist 7 | - export PATH=$HOME/.yarn/bin:$PATH 8 | - yarn global add coveralls 9 | install: 10 | - yarn install 11 | language: node_js 12 | node_js: 13 | - '10' 14 | script: 15 | - yarn lint 16 | - yarn typecheck 17 | - yarn test:api 18 | - yarn test --silent --coverage --coverageReporters=text-lcov | coveralls ; test ${PIPESTATUS[0]} -eq 0 19 | before_deploy: 20 | - echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc 2> /dev/null 21 | - yarn global add gitbook-cli 22 | - yarn update-docs 23 | deploy: 24 | - provider: script 25 | skip_cleanup: true 26 | script: ./scripts/lerna-publish.sh 27 | on: 28 | branch: master 29 | - provider: pages 30 | github-token: $GH_TOKEN 31 | keep-history: true 32 | local-dir: gh_pages # The directory to be pushed to gh-pages branch 33 | skip-cleanup: true 34 | on: 35 | branch: master 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2015-2019 Parity Technologies 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | collectCoverageFrom: [ 3 | '**/*.{ts,tsx}', 4 | '!**/node_modules/**', 5 | '!**/*.d.ts', 6 | '!**/index.ts' 7 | ], 8 | // Adding this because "Cannot use namespace '...' as a type." 9 | globals: { 10 | 'ts-jest': { 11 | diagnostics: { 12 | warnOnly: true 13 | } 14 | } 15 | }, 16 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], 17 | rootDir: '.', 18 | transform: { 19 | '^.+\\.(ts|tsx)$': 'ts-jest' 20 | }, 21 | testRegex: 'spec\\.(ts|tsx)$' 22 | }; 23 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "3.4.3", 3 | "npmClient": "yarn", 4 | "packages": [ 5 | "packages/*" 6 | ], 7 | "useWorkspaces": true, 8 | "version": "5.1.19" 9 | } 10 | -------------------------------------------------------------------------------- /packages/abi/docs/classes/_decoder_bytestaken_.bytestaken.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **BytesTaken** 6 | 7 | # Constructors 8 | 9 | 10 | 11 | ## constructor 12 | 13 | ⊕ **new BytesTaken**(bytes: *`number`[]*, newOffset: *`number`*): [BytesTaken](_decoder_bytestaken_.bytestaken.md) 14 | 15 | *Defined in [decoder/bytesTaken.ts:8](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/decoder/bytesTaken.ts#L8)* 16 | 17 | **Parameters:** 18 | 19 | | Name | Type | 20 | | ------ | ------ | 21 | | bytes | `number`[] | 22 | | newOffset | `number` | 23 | 24 | **Returns:** [BytesTaken](_decoder_bytestaken_.bytestaken.md) 25 | 26 | ___ 27 | 28 | # Accessors 29 | 30 | 31 | 32 | ## bytes 33 | 34 | **get bytes**(): `number`[] 35 | 36 | *Defined in [decoder/bytesTaken.ts:15](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/decoder/bytesTaken.ts#L15)* 37 | 38 | **Returns:** `number`[] 39 | 40 | ___ 41 | 42 | 43 | ## newOffset 44 | 45 | **get newOffset**(): `number` 46 | 47 | *Defined in [decoder/bytesTaken.ts:19](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/decoder/bytesTaken.ts#L19)* 48 | 49 | **Returns:** `number` 50 | 51 | ___ 52 | 53 | -------------------------------------------------------------------------------- /packages/abi/docs/classes/_encoder_encoder_.encoder.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **Encoder** 6 | 7 | # Methods 8 | 9 | 10 | 11 | ## `` encode 12 | 13 | ▸ **encode**(tokens: *[Token](_token_token_.token.md)[]*): `string` 14 | 15 | *Defined in [encoder/encoder.ts:27](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/encoder/encoder.ts#L27)* 16 | 17 | **Parameters:** 18 | 19 | | Name | Type | 20 | | ------ | ------ | 21 | | tokens | [Token](_token_token_.token.md)[] | 22 | 23 | **Returns:** `string` 24 | 25 | ___ 26 | 27 | 28 | ## `` encodeToken 29 | 30 | ▸ **encodeToken**(token: *[Token](_token_token_.token.md)*, index?: *`number`*): [Mediate](_encoder_mediate_.mediate.md) 31 | 32 | *Defined in [encoder/encoder.ts:47](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/encoder/encoder.ts#L47)* 33 | 34 | **Parameters:** 35 | 36 | | Name | Type | Default value | 37 | | ------ | ------ | ------ | 38 | | token | [Token](_token_token_.token.md) | - | 39 | | `Default value` index | `number` | 0 | 40 | 41 | **Returns:** [Mediate](_encoder_mediate_.mediate.md) 42 | 43 | ___ 44 | 45 | -------------------------------------------------------------------------------- /packages/abi/docs/classes/_spec_event_decodedlog_.decodedlog.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **DecodedLog** 6 | 7 | # Constructors 8 | 9 | 10 | 11 | ## constructor 12 | 13 | ⊕ **new DecodedLog**(params: *[DecodedLogParam](_spec_event_decodedlogparam_.decodedlogparam.md)[]*, address: *`string`*): [DecodedLog](_spec_event_decodedlog_.decodedlog.md) 14 | 15 | *Defined in [spec/event/decodedLog.ts:10](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/spec/event/decodedLog.ts#L10)* 16 | 17 | **Parameters:** 18 | 19 | | Name | Type | 20 | | ------ | ------ | 21 | | params | [DecodedLogParam](_spec_event_decodedlogparam_.decodedlogparam.md)[] | 22 | | address | `string` | 23 | 24 | **Returns:** [DecodedLog](_spec_event_decodedlog_.decodedlog.md) 25 | 26 | ___ 27 | 28 | # Accessors 29 | 30 | 31 | 32 | ## address 33 | 34 | **get address**(): `string` 35 | 36 | *Defined in [spec/event/decodedLog.ts:17](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/spec/event/decodedLog.ts#L17)* 37 | 38 | **Returns:** `string` 39 | 40 | ___ 41 | 42 | 43 | ## params 44 | 45 | **get params**(): [DecodedLogParam](_spec_event_decodedlogparam_.decodedlogparam.md)[] 46 | 47 | *Defined in [spec/event/decodedLog.ts:21](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/spec/event/decodedLog.ts#L21)* 48 | 49 | **Returns:** [DecodedLogParam](_spec_event_decodedlogparam_.decodedlogparam.md)[] 50 | 51 | ___ 52 | 53 | -------------------------------------------------------------------------------- /packages/abi/docs/interfaces/_types_.abiinput.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **AbiInput** 6 | 7 | # Properties 8 | 9 | 10 | 11 | ## `` indexed 12 | 13 | **● indexed**: *`undefined` \| `false` \| `true`* 14 | 15 | *Defined in [types.ts:11](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/types.ts#L11)* 16 | 17 | ___ 18 | 19 | 20 | ## `` name 21 | 22 | **● name**: *`undefined` \| `string`* 23 | 24 | *Defined in [types.ts:12](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/types.ts#L12)* 25 | 26 | ___ 27 | 28 | 29 | ## type 30 | 31 | **● type**: *[TokenTypeEnum](../modules/_types_.md#tokentypeenum)* 32 | 33 | *Defined in [types.ts:13](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/types.ts#L13)* 34 | 35 | ___ 36 | 37 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_abi_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Abi](../classes/_abi_.abi.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_decoder_bytestaken_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [BytesTaken](../classes/_decoder_bytestaken_.bytestaken.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_decoder_decoder_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Decoder](../classes/_decoder_decoder_.decoder.md) 8 | 9 | ### Variables 10 | 11 | * [NULL](_decoder_decoder_.md#null) 12 | 13 | --- 14 | 15 | # Variables 16 | 17 | 18 | 19 | ## `` NULL 20 | 21 | **● NULL**: *"0000000000000000000000000000000000000000000000000000000000000000"* = "0000000000000000000000000000000000000000000000000000000000000000" 22 | 23 | *Defined in [decoder/decoder.ts:17](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/decoder/decoder.ts#L17)* 24 | 25 | ___ 26 | 27 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_decoder_decoderesult_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [DecodeResult](../classes/_decoder_decoderesult_.decoderesult.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_encoder_encoder_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Encoder](../classes/_encoder_encoder_.encoder.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_encoder_mediate_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Mediate](../classes/_encoder_mediate_.mediate.md) 8 | 9 | ### Type aliases 10 | 11 | * [MediateValue](_encoder_mediate_.md#mediatevalue) 12 | 13 | ### Variables 14 | 15 | * [TYPES](_encoder_mediate_.md#types) 16 | 17 | --- 18 | 19 | # Type aliases 20 | 21 | 22 | 23 | ## MediateValue 24 | 25 | **Ƭ MediateValue**: *[TokenValue](_types_.md#tokenvalue) \| [Mediate](../classes/_encoder_mediate_.mediate.md)[]* 26 | 27 | *Defined in [encoder/mediate.ts:11](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/encoder/mediate.ts#L11)* 28 | 29 | ___ 30 | 31 | # Variables 32 | 33 | 34 | 35 | ## `` TYPES 36 | 37 | **● TYPES**: *[MediateType](_types_.md#mediatetype)[]* = ['raw', 'prefixed', 'fixedArray', 'array'] 38 | 39 | *Defined in [encoder/mediate.ts:9](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/encoder/mediate.ts#L9)* 40 | 41 | ___ 42 | 43 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_constructor_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Constructor](../classes/_spec_constructor_.constructor.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_event_decodedlog_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [DecodedLog](../classes/_spec_event_decodedlog_.decodedlog.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_event_decodedlogparam_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [DecodedLogParam](../classes/_spec_event_decodedlogparam_.decodedlogparam.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_event_event_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Event](../classes/_spec_event_event_.event.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_event_eventparam_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [EventParam](../classes/_spec_event_eventparam_.eventparam.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_function_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Func](../classes/_spec_function_.func.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_interface_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Interface](../classes/_spec_interface_.interface.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_param_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Param](../classes/_spec_param_.param.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_paramtype_format_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Functions 4 | 5 | 6 | 7 | ## `` fromParamType 8 | 9 | ▸ **fromParamType**(paramType: *[ParamType](../classes/_spec_paramtype_paramtype_.paramtype.md)*): `string` 10 | 11 | *Defined in [spec/paramType/format.ts:72](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/spec/paramType/format.ts#L72)* 12 | 13 | Convert a ParamType to its string representation. 14 | 15 | **Parameters:** 16 | 17 | | Name | Type | Description | 18 | | ------ | ------ | ------ | 19 | | paramType | [ParamType](../classes/_spec_paramtype_paramtype_.paramtype.md) | ParamType instance to convert | 20 | 21 | **Returns:** `string` 22 | 23 | ___ 24 | 25 | 26 | ## `` toParamType 27 | 28 | ▸ **toParamType**(type: *`string`*, indexed?: *`undefined` \| `false` \| `true`*): [ParamType](../classes/_spec_paramtype_paramtype_.paramtype.md) 29 | 30 | *Defined in [spec/paramType/format.ts:15](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/spec/paramType/format.ts#L15)* 31 | 32 | Convert a string to a ParamType. 33 | 34 | **Parameters:** 35 | 36 | | Name | Type | Description | 37 | | ------ | ------ | ------ | 38 | | type | `string` | Type to convert. | 39 | | `Optional` indexed | `undefined` \| `false` \| `true` | Whether the ParamType is indexed or not. | 40 | 41 | **Returns:** [ParamType](../classes/_spec_paramtype_paramtype_.paramtype.md) 42 | 43 | ___ 44 | 45 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_paramtype_paramtype_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [ParamType](../classes/_spec_paramtype_paramtype_.paramtype.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_spec_paramtype_types_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Variables 4 | 5 | 6 | 7 | ## `` TYPES 8 | 9 | **● TYPES**: *[TokenTypeEnum](_types_.md#tokentypeenum)[]* = [ 10 | 'address', 11 | 'bytes', 12 | 'int', 13 | 'uint', 14 | 'bool', 15 | 'string', 16 | 'array', 17 | 'fixedBytes', 18 | 'fixedArray' 19 | ] 20 | 21 | *Defined in [spec/paramType/types.ts:8](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/spec/paramType/types.ts#L8)* 22 | 23 | ___ 24 | 25 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_token_token_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Token](../classes/_token_token_.token.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/abi/docs/modules/_util_slice_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Functions 4 | 5 | 6 | 7 | ## `` sliceData 8 | 9 | ▸ **sliceData**(data?: *`undefined` \| `string`*): `string`[] \| `null` 10 | 11 | *Defined in [util/slice.ts:13](https://github.com/paritytech/js-libs/blob/66e2091/packages/abi/src/util/slice.ts#L13)* 12 | 13 | Slice data. 14 | 15 | **Parameters:** 16 | 17 | | Name | Type | Description | 18 | | ------ | ------ | ------ | 19 | | `Optional` data | `undefined` \| `string` | Data to slice. | 20 | 21 | **Returns:** `string`[] \| `null` 22 | 23 | ___ 24 | 25 | -------------------------------------------------------------------------------- /packages/abi/jest.config.js: -------------------------------------------------------------------------------- 1 | const baseConfig = require('../../jest.config'); 2 | 3 | module.exports = baseConfig; 4 | -------------------------------------------------------------------------------- /packages/abi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@parity/abi", 3 | "description": "Ethereum ABI encoder and decoder", 4 | "version": "5.1.19", 5 | "author": "Parity Team ", 6 | "license": "MIT", 7 | "repository": "https://github.com/paritytech/js-libs/tree/master/packages/abi", 8 | "main": "lib/index.js", 9 | "keywords": [ 10 | "Ethereum", 11 | "ABI", 12 | "Parity" 13 | ], 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "docs": "typedoc", 19 | "prebuild": "rimraf lib", 20 | "typecheck": "tsc --noEmit", 21 | "build": "tsc", 22 | "test": "jest" 23 | }, 24 | "devDependencies": { 25 | "@types/utf8": "^2.1.6", 26 | "typescript": "^3.1.6" 27 | }, 28 | "dependencies": { 29 | "bignumber.js": "^8.0.1", 30 | "js-sha3": "0.8.0", 31 | "utf8": "^3.0.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/abi/src/abi.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Interface from './spec/interface'; 7 | 8 | class Abi extends Interface {} 9 | 10 | export default Abi; 11 | -------------------------------------------------------------------------------- /packages/abi/src/decoder/bytesTaken.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import BytesTaken from './bytesTaken'; 7 | 8 | describe('decoder/BytesTaken', () => { 9 | describe('constructor', () => { 10 | it('sets the bytes of the object', () => { 11 | expect(new BytesTaken([1], 2).bytes).toEqual([1]); 12 | }); 13 | 14 | it('sets the newOffset of the object', () => { 15 | expect(new BytesTaken([1], 4).newOffset).toEqual(4); 16 | }); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/abi/src/decoder/bytesTaken.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | class BytesTaken { 7 | private _bytes: number[]; 8 | private _newOffset: number; 9 | 10 | constructor (bytes: number[], newOffset: number) { 11 | this._bytes = bytes; 12 | this._newOffset = newOffset; 13 | } 14 | 15 | get bytes () { 16 | return this._bytes; 17 | } 18 | 19 | get newOffset () { 20 | return this._newOffset; 21 | } 22 | } 23 | 24 | export default BytesTaken; 25 | -------------------------------------------------------------------------------- /packages/abi/src/decoder/decodeResult.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import DecodeResult from './decodeResult'; 7 | import Token from '../token'; 8 | 9 | describe('decoder/DecodeResult', () => { 10 | describe('constructor', () => { 11 | it('sets the token of the object', () => { 12 | const token = new Token('bool', 1); 13 | expect(new DecodeResult(token, 2).token).toEqual(token); 14 | }); 15 | 16 | it('sets the newOffset of the object', () => { 17 | expect(new DecodeResult(new Token('bool', 1), 4).newOffset).toEqual(4); 18 | }); 19 | }); 20 | }); 21 | -------------------------------------------------------------------------------- /packages/abi/src/decoder/decodeResult.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Token from '../token'; 7 | 8 | class DecodeResult { 9 | _token: Token; 10 | _newOffset: number; 11 | 12 | constructor (token: Token, newOffset: number) { 13 | this._token = token; 14 | this._newOffset = newOffset; 15 | } 16 | 17 | get token () { 18 | return this._token; 19 | } 20 | 21 | get newOffset () { 22 | return this._newOffset; 23 | } 24 | } 25 | 26 | export default DecodeResult; 27 | -------------------------------------------------------------------------------- /packages/abi/src/decoder/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Decoder from './decoder'; 7 | 8 | export default Decoder; 9 | -------------------------------------------------------------------------------- /packages/abi/src/encoder/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Encoder from './encoder'; 7 | 8 | export default Encoder; 9 | -------------------------------------------------------------------------------- /packages/abi/src/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Abi from './abi'; 7 | 8 | export * from './types'; 9 | 10 | export default Abi; 11 | -------------------------------------------------------------------------------- /packages/abi/src/spec/constructor.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { AbiItem } from '../types'; 7 | import Encoder from '../encoder/encoder'; 8 | import Param from './param'; 9 | import Token from '../token'; 10 | 11 | class Constructor { 12 | private _inputs: Param[]; 13 | 14 | constructor (abi: AbiItem) { 15 | this._inputs = Param.toParams(abi.inputs || []); 16 | } 17 | 18 | get inputs () { 19 | return this._inputs; 20 | } 21 | 22 | inputParamTypes () { 23 | return this._inputs.map(input => input.kind); 24 | } 25 | 26 | encodeCall (tokens: Token[]) { 27 | return Encoder.encode(tokens); 28 | } 29 | } 30 | 31 | export default Constructor; 32 | -------------------------------------------------------------------------------- /packages/abi/src/spec/event/decodedLog.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import DecodedLog from './decodedLog'; 7 | import DecodedLogParam from './decodedLogParam'; 8 | import ParamType from '../paramType'; 9 | import Token from '../../token'; 10 | 11 | const decodedLogParam = new DecodedLogParam( 12 | 'someparams', 13 | new ParamType('address'), 14 | new Token('address') 15 | ); 16 | const log = new DecodedLog([decodedLogParam], 'someAddress'); 17 | 18 | describe('spec/event/DecodedLog', () => { 19 | describe('constructor', () => { 20 | it('sets internal state', () => { 21 | expect(log.params).toEqual([decodedLogParam]); 22 | expect(log.address).toEqual('someAddress'); 23 | }); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /packages/abi/src/spec/event/decodedLog.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import DecodedLogParam from './decodedLogParam'; 7 | 8 | class DecodedLog { 9 | private _address: string; 10 | private _params: DecodedLogParam[]; 11 | 12 | constructor (params: DecodedLogParam[], address: string) { 13 | this._params = params; 14 | this._address = address; 15 | } 16 | 17 | get address () { 18 | return this._address; 19 | } 20 | 21 | get params () { 22 | return this._params; 23 | } 24 | } 25 | 26 | export default DecodedLog; 27 | -------------------------------------------------------------------------------- /packages/abi/src/spec/event/decodedLogParam.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import DecodedLogParam from './decodedLogParam'; 7 | import ParamType from '../paramType'; 8 | import Token from '../../token'; 9 | 10 | describe('spec/event/DecodedLogParam', () => { 11 | describe('constructor', () => { 12 | const pt = new ParamType('bool'); 13 | const tk = new Token('bool'); 14 | 15 | it('disallows kind not instanceof ParamType', () => { 16 | expect( 17 | () => new DecodedLogParam('test', 'param' as any, undefined as any) 18 | ).toThrow(/ParamType/); 19 | }); 20 | 21 | it('disallows token not instanceof Token', () => { 22 | expect(() => new DecodedLogParam('test', pt, 'token' as any)).toThrow( 23 | /Token/ 24 | ); 25 | }); 26 | 27 | it('stores all parameters received', () => { 28 | const log = new DecodedLogParam('test', pt, tk); 29 | 30 | expect(log.name).toEqual('test'); 31 | expect(log.kind).toEqual(pt); 32 | expect(log.token).toEqual(tk); 33 | }); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /packages/abi/src/spec/event/decodedLogParam.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { isInstanceOf } from '../../util/types'; 7 | import ParamType from '../paramType'; 8 | import Token from '../../token'; 9 | 10 | class DecodedLogParam { 11 | private _kind: ParamType; 12 | private _name: string | undefined; 13 | private _token: Token; 14 | 15 | constructor (name: string | undefined, kind: ParamType, token: Token) { 16 | if (!isInstanceOf(kind, ParamType)) { 17 | throw new Error('kind not instanceof ParamType'); 18 | } else if (!isInstanceOf(token, Token)) { 19 | throw new Error('token not instanceof Token'); 20 | } 21 | 22 | this._name = name; 23 | this._kind = kind; 24 | this._token = token; 25 | } 26 | 27 | get name () { 28 | return this._name; 29 | } 30 | 31 | get kind () { 32 | return this._kind; 33 | } 34 | 35 | get token () { 36 | return this._token; 37 | } 38 | } 39 | 40 | export default DecodedLogParam; 41 | -------------------------------------------------------------------------------- /packages/abi/src/spec/event/eventParam.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import EventParam from './eventParam'; 7 | 8 | describe('spec/event/EventParam', () => { 9 | describe('constructor', () => { 10 | it('sets the properties', () => { 11 | const param = new EventParam('foo', 'uint', true); 12 | 13 | expect(param.name).toEqual('foo'); 14 | expect(param.kind.type).toEqual('uint'); 15 | expect(param.indexed).toBe(true); 16 | }); 17 | 18 | it('uses defaults for indexed', () => { 19 | expect(new EventParam('foo', 'uint').indexed).toBe(false); 20 | }); 21 | }); 22 | 23 | describe('toEventParams', () => { 24 | it('maps an array of params', () => { 25 | const params = EventParam.toEventParams([{ name: 'foo', type: 'uint' }]); 26 | 27 | expect(params.length).toEqual(1); 28 | expect(params[0].indexed).toBe(false); 29 | expect(params[0].name).toEqual('foo'); 30 | expect(params[0].kind.type).toEqual('uint'); 31 | }); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /packages/abi/src/spec/event/eventParam.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { AbiInput, TokenTypeEnum } from '../../types'; 7 | import Param from '../param'; 8 | import ParamType from '../paramType'; 9 | import { toParamType } from '../paramType/format'; 10 | 11 | class EventParam { 12 | private _indexed: boolean; 13 | private _kind: ParamType; 14 | private _name: string | undefined; 15 | 16 | static toEventParams (params: (Param | AbiInput)[]) { 17 | return params.map( 18 | param => 19 | new EventParam( 20 | param.name, 21 | (param as Param).kind 22 | ? (param as Param).kind.type 23 | : ((param as AbiInput).type as TokenTypeEnum), 24 | (param as AbiInput).indexed 25 | ) 26 | ); 27 | } 28 | 29 | constructor (name: string | undefined, type: TokenTypeEnum, indexed = false) { 30 | this._name = name; 31 | this._indexed = indexed; 32 | this._kind = toParamType(type, indexed); 33 | } 34 | 35 | get name () { 36 | return this._name; 37 | } 38 | 39 | get kind () { 40 | return this._kind; 41 | } 42 | 43 | get indexed () { 44 | return this._indexed; 45 | } 46 | } 47 | 48 | export default EventParam; 49 | -------------------------------------------------------------------------------- /packages/abi/src/spec/event/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Event from './event'; 7 | 8 | export default Event; 9 | -------------------------------------------------------------------------------- /packages/abi/src/spec/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Interface from './interface'; 7 | 8 | export default Interface; 9 | -------------------------------------------------------------------------------- /packages/abi/src/spec/param.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Param from './param'; 7 | 8 | describe('spec/Param', () => { 9 | describe('constructor', () => { 10 | const param = new Param('foo', 'uint'); 11 | 12 | it('sets the properties', () => { 13 | expect(param.name).toEqual('foo'); 14 | expect(param.kind.type).toEqual('uint'); 15 | }); 16 | }); 17 | 18 | describe('toParams', () => { 19 | it('maps an array of params', () => { 20 | const params = Param.toParams([{ name: 'foo', type: 'uint' }]); 21 | 22 | expect(params.length).toEqual(1); 23 | expect(params[0].name).toEqual('foo'); 24 | expect(params[0].kind.type).toEqual('uint'); 25 | }); 26 | 27 | it('converts only if needed', () => { 28 | const _params = Param.toParams([{ name: 'foo', type: 'uint' }]); 29 | const params = Param.toParams(_params); 30 | 31 | expect(params.length).toEqual(1); 32 | expect(params[0].name).toEqual('foo'); 33 | expect(params[0].kind.type).toEqual('uint'); 34 | }); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /packages/abi/src/spec/param.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { AbiInput } from '../types'; 7 | import ParamType from './paramType'; 8 | import { toParamType } from './paramType/format'; 9 | 10 | class Param { 11 | private _kind: ParamType; 12 | private _name: string | undefined; 13 | 14 | constructor (name: string | undefined, type: string) { 15 | this._name = name; 16 | this._kind = toParamType(type); 17 | } 18 | 19 | static toParams (params: (Param | AbiInput)[]) { 20 | return params.map(param => { 21 | if (param instanceof Param) { 22 | return param; 23 | } 24 | 25 | return new Param(param.name, param.type); 26 | }); 27 | } 28 | 29 | get name () { 30 | return this._name; 31 | } 32 | 33 | get kind () { 34 | return this._kind; 35 | } 36 | } 37 | 38 | export default Param; 39 | -------------------------------------------------------------------------------- /packages/abi/src/spec/paramType/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import ParamType from './paramType'; 7 | 8 | export default ParamType; 9 | -------------------------------------------------------------------------------- /packages/abi/src/spec/paramType/paramType.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { TokenTypeEnum } from '../../types'; 7 | import TYPES from './types'; 8 | 9 | class ParamType { 10 | private _indexed?: boolean; 11 | private _length: number; 12 | private _subtype?: ParamType; 13 | private _type: TokenTypeEnum; 14 | 15 | constructor ( 16 | type: TokenTypeEnum, 17 | subtype: ParamType | undefined = undefined, 18 | length = 0, 19 | indexed = false 20 | ) { 21 | ParamType.validateType(type); 22 | 23 | this._type = type; 24 | this._subtype = subtype; 25 | this._length = length; 26 | this._indexed = indexed; 27 | } 28 | 29 | static validateType (type: TokenTypeEnum) { 30 | if (TYPES.some(_type => type === _type)) { 31 | return true; 32 | } 33 | 34 | throw new Error(`Invalid type ${type} received for ParamType`); 35 | } 36 | 37 | get type () { 38 | return this._type; 39 | } 40 | 41 | get subtype () { 42 | return this._subtype; 43 | } 44 | 45 | get length () { 46 | return this._length; 47 | } 48 | 49 | get indexed () { 50 | return this._indexed; 51 | } 52 | } 53 | 54 | export default ParamType; 55 | -------------------------------------------------------------------------------- /packages/abi/src/spec/paramType/types.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { TokenTypeEnum } from '../../types'; 7 | 8 | const TYPES: TokenTypeEnum[] = [ 9 | 'address', 10 | 'bytes', 11 | 'int', 12 | 'uint', 13 | 'bool', 14 | 'string', 15 | 'array', 16 | 'fixedBytes', 17 | 'fixedArray' 18 | ]; 19 | 20 | export default TYPES; 21 | -------------------------------------------------------------------------------- /packages/abi/src/token/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Token from './token'; 7 | 8 | export default Token; 9 | -------------------------------------------------------------------------------- /packages/abi/src/token/token.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { TokenTypeEnum, TokenValue } from '../types'; 7 | import TYPES from '../spec/paramType/types'; 8 | 9 | class Token { 10 | private _type: TokenTypeEnum; 11 | private _value: TokenValue | undefined; 12 | 13 | constructor (type: TokenTypeEnum, value?: TokenValue) { 14 | Token.validateType(type); 15 | 16 | this._type = type; 17 | this._value = value; 18 | } 19 | 20 | static validateType (type: TokenTypeEnum) { 21 | if (TYPES.some(_type => type === _type)) { 22 | return true; 23 | } 24 | 25 | throw new Error(`Invalid type ${type} received for Token`); 26 | } 27 | 28 | get type () { 29 | return this._type; 30 | } 31 | 32 | get value () { 33 | return this._value; 34 | } 35 | } 36 | 37 | export default Token; 38 | -------------------------------------------------------------------------------- /packages/abi/src/util/signature.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { keccak_256 } from 'js-sha3'; 7 | 8 | import { fromParamType } from '../spec/paramType/format'; 9 | import ParamType from '../spec/paramType'; 10 | 11 | /** 12 | * Get event signature. 13 | */ 14 | export const eventSignature = ( 15 | eventName: string | undefined, 16 | params: ParamType[] = [] 17 | ) => { 18 | // eslint-disable-next-line @typescript-eslint/no-use-before-define 19 | const { strName, name } = parseName(eventName); 20 | const types = (params || []).map(fromParamType).join(','); 21 | const id = `${strName}(${types})`; 22 | const signature = strName ? keccak_256(id) : ''; 23 | 24 | return { id, name, signature }; 25 | }; 26 | 27 | /** 28 | * Get method signature. 29 | * 30 | * @param methodName - The method name. 31 | * @param params - The list of params 32 | */ 33 | export const methodSignature = ( 34 | methodName: string | undefined, 35 | params: ParamType[] = [] 36 | ) => { 37 | const { id, name, signature } = eventSignature(methodName, params); 38 | 39 | return { id, name, signature: signature.substr(0, 8) }; 40 | }; 41 | 42 | /** 43 | * Parse name. 44 | * 45 | * @param name - Name to parse. 46 | */ 47 | export const parseName = (name: string | undefined) => { 48 | const strName = `${name || ''}`; 49 | const index = strName.indexOf('('); 50 | 51 | if (index === -1) { 52 | return { strName, name }; 53 | } 54 | 55 | const trimmedName = strName.slice(0, index); 56 | 57 | return { 58 | strName: trimmedName, 59 | name: trimmedName 60 | }; 61 | }; 62 | -------------------------------------------------------------------------------- /packages/abi/src/util/slice.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { sliceData } from './slice'; 7 | 8 | describe('util/slice', () => { 9 | describe('sliceData', () => { 10 | const slice1 = 11 | '131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b'; 12 | const slice2 = 13 | '2124768576358735263578356373526387638357635873563586353756358763'; 14 | 15 | it('returns an empty array when length === 0', () => { 16 | expect(sliceData('')).toEqual([]); 17 | }); 18 | 19 | it('returns array with zero entry when data === 0x', () => { 20 | expect(sliceData('0x')).toEqual([ 21 | '0000000000000000000000000000000000000000000000000000000000000000' 22 | ]); 23 | }); 24 | 25 | it('returns an array with the slices otherwise', () => { 26 | const sliced = sliceData(`${slice1}${slice2}`); 27 | if (!sliced) { 28 | throw new Error('No matches'); 29 | } 30 | 31 | expect(sliced.length).toEqual(2); 32 | expect(sliced[0]).toEqual(slice1); 33 | expect(sliced[1]).toEqual(slice2); 34 | }); 35 | 36 | it('removes leading 0x when passed in', () => { 37 | const sliced = sliceData(`0x${slice1}${slice2}`); 38 | if (!sliced) { 39 | throw new Error('No matches'); 40 | } 41 | 42 | expect(sliced.length).toEqual(2); 43 | expect(sliced[0]).toEqual(slice1); 44 | expect(sliced[1]).toEqual(slice2); 45 | }); 46 | }); 47 | }); 48 | -------------------------------------------------------------------------------- /packages/abi/src/util/slice.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { padAddress } from './pad'; 7 | 8 | /** 9 | * Slice data. 10 | * 11 | * @param data - Data to slice. 12 | */ 13 | export const sliceData = (data?: string): string[] | null => { 14 | if (!data || !data.length) { 15 | return []; 16 | } 17 | 18 | let dataWithout0x = data.substr(0, 2) === '0x' ? data.substr(2) : data; 19 | 20 | if (!dataWithout0x.length) { 21 | dataWithout0x = padAddress(''); 22 | } 23 | 24 | return dataWithout0x.match(/.{1,64}/g); 25 | }; 26 | -------------------------------------------------------------------------------- /packages/abi/src/util/sliceAs.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import BigNumber from 'bignumber.js'; 7 | 8 | import { toChecksumAddress } from './address'; 9 | 10 | /** 11 | * Convert slice to u32. 12 | * 13 | * @param slice - Slice to convert. 14 | */ 15 | export const asU32 = (slice: string) => { 16 | // TODO: validation 17 | 18 | return new BigNumber(slice.toLowerCase(), 16); 19 | }; 20 | 21 | /** 22 | * Convert slice to i32. 23 | * 24 | * @param slice - Slice to convert. 25 | */ 26 | export const asI32 = (slice: string) => { 27 | if (new BigNumber(slice.substr(0, 1), 16).toString(2)[0] === '1') { 28 | return new BigNumber(slice, 16) 29 | .minus( 30 | new BigNumber( 31 | 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 32 | 16 33 | ) 34 | ) 35 | .minus(1); 36 | } 37 | 38 | return new BigNumber(slice, 16); 39 | }; 40 | 41 | /** 42 | * Convert slice to checksum address. 43 | * 44 | * @param slice - Slice to convert. 45 | */ 46 | export const asAddress = (slice: string) => { 47 | // TODO: address validation? 48 | 49 | return toChecksumAddress(`0x${slice.slice(-40)}`); 50 | }; 51 | 52 | /** 53 | * Convert slice to boolean. 54 | * 55 | * @param slice - Slice to convert. 56 | */ 57 | export const asBool = (slice: string) => { 58 | // TODO: everything else should be 0 59 | 60 | return new BigNumber(slice[63]).eq(1); 61 | }; 62 | -------------------------------------------------------------------------------- /packages/abi/src/util/types.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | const HEXDIGITS = [ 7 | '0', 8 | '1', 9 | '2', 10 | '3', 11 | '4', 12 | '5', 13 | '6', 14 | '7', 15 | '8', 16 | '9', 17 | 'a', 18 | 'b', 19 | 'c', 20 | 'd', 21 | 'e', 22 | 'f' 23 | ]; 24 | 25 | export function isArray (input?: any): input is Array { 26 | return Array.isArray(input); 27 | } 28 | 29 | export function isError (input?: any): input is Error { 30 | return input instanceof Error; 31 | } 32 | 33 | export function isFunction (input?: any): input is Function { 34 | return typeof input === 'function'; 35 | } 36 | 37 | export function isHex (input?: any): boolean { 38 | // eslint-disable-next-line @typescript-eslint/no-use-before-define 39 | if (!isString(input)) { 40 | return false; 41 | } 42 | 43 | if (input.substr(0, 2) === '0x') { 44 | return isHex(input.slice(2)); 45 | } 46 | 47 | const lowerCaseInput = input.toLowerCase(); 48 | let hex = true; 49 | 50 | for (let index = 0; hex && index < input.length; index++) { 51 | hex = HEXDIGITS.includes(lowerCaseInput[index]); 52 | } 53 | 54 | return hex; 55 | } 56 | export function isObject (input?: any): input is object { 57 | return Object.prototype.toString.call(input) === '[object Object]'; 58 | } 59 | 60 | export function isString (input?: any): input is string { 61 | return typeof input === 'string'; 62 | } 63 | 64 | export function isInstanceOf (input: any, clazz: any) { 65 | return input instanceof clazz; 66 | } 67 | -------------------------------------------------------------------------------- /packages/abi/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./lib" 4 | }, 5 | "extends": "../../tsconfig.json", 6 | "include": ["./src"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/abi/typedoc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | exclude: ['**/*spec.ts', '**/index.ts'], 3 | excludeExternals: true, 4 | excludePrivate: true, 5 | hideGenerator: true, 6 | includes: './src', 7 | out: 'docs', 8 | module: 'commonjs', 9 | mdEngine: 'gitbook', 10 | stripInternal: 'true', 11 | theme: 'markdown' 12 | }; 13 | -------------------------------------------------------------------------------- /packages/api/jest.config.js: -------------------------------------------------------------------------------- 1 | const baseConfig = require('../../jest.config'); 2 | 3 | module.exports = baseConfig; 4 | -------------------------------------------------------------------------------- /packages/api/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@parity/api", 3 | "description": "The Parity Promise-based API library for interfacing with Ethereum over RPC", 4 | "version": "5.1.19", 5 | "author": "Parity Team ", 6 | "license": "MIT", 7 | "repository": "https://github.com/paritytech/js-libs/tree/master/packages/api", 8 | "main": "lib/index.js", 9 | "keywords": [ 10 | "Ethereum", 11 | "API", 12 | "RPC", 13 | "Parity", 14 | "Promise" 15 | ], 16 | "publishConfig": { 17 | "access": "public" 18 | }, 19 | "scripts": { 20 | "prebuild": "rimraf lib", 21 | "typecheck": "tsc --noEmit", 22 | "build": "tsc", 23 | "test": "cross-env NODE_ENV=test mocha -r ts-node/register 'src/*.spec.js' 'src/**/*.spec.js'" 24 | }, 25 | "devDependencies": { 26 | "chai": "3.5.0", 27 | "chai-as-promised": "7.1.1", 28 | "coveralls": "^3.0.0", 29 | "cross-env": "^5.1.1", 30 | "jsdom": "^13.2.0", 31 | "mocha": "^3.4.2", 32 | "mock-local-storage": "1.1.8", 33 | "mock-socket": "6.0.4", 34 | "nock": "10.0.6", 35 | "rimraf": "^2.6.2", 36 | "sinon": "1.17.7", 37 | "sinon-as-promised": "4.0.3", 38 | "sinon-chai": "3.3.0", 39 | "ts-node": "^8.0.1", 40 | "typescript": "^3.1.6" 41 | }, 42 | "dependencies": { 43 | "@parity/abi": "^5.1.19", 44 | "bignumber.js": "^8.0.1", 45 | "blockies": "0.0.2", 46 | "es6-error": "4.0.2", 47 | "es6-promise": "^4.1.1", 48 | "eventemitter3": "^3.1.0", 49 | "isomorphic-fetch": "^2.2.1", 50 | "js-sha3": "0.8.0", 51 | "lodash": "^4.17.11", 52 | "store": "^2.0.12", 53 | "websocket": "^1.0.25" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /packages/api/src/api.spec.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | /* eslint-disable no-unused-expressions */ 18 | 19 | const sinon = require('sinon'); 20 | 21 | const util = require('./util'); 22 | const Api = require('./api'); 23 | 24 | describe('Api', () => { 25 | describe('constructor', () => { 26 | it('wraps a currentProvider when supplied', () => { 27 | const sendAsync = sinon.stub(); 28 | const currentProvider = { 29 | sendAsync 30 | }; 31 | const api = new Api(currentProvider); 32 | 33 | api.provider.send('method', [], () => {}); 34 | expect(sendAsync).to.have.been.called; 35 | }); 36 | }); 37 | 38 | it('exposes util as static property', () => { 39 | expect(Api.util).to.equal(util); 40 | }); 41 | }); 42 | -------------------------------------------------------------------------------- /packages/api/src/contract/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Contract = require('./contract'); 18 | 19 | module.exports = Contract; 20 | -------------------------------------------------------------------------------- /packages/api/src/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | require('./polyfill'); 18 | 19 | const Api = require('./api'); 20 | 21 | module.exports = Api; 22 | -------------------------------------------------------------------------------- /packages/api/src/library.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const es6Promise = require('es6-promise'); 18 | 19 | es6Promise.polyfill(); 20 | 21 | const isNode = typeof global !== 'undefined' && typeof global !== 'undefined'; 22 | const isBrowser = typeof self !== 'undefined' && typeof self.window !== 'undefined'; 23 | 24 | if (isBrowser) { 25 | require('whatwg-fetch'); 26 | } 27 | 28 | if (isNode) { 29 | global.fetch = require('node-fetch'); 30 | } 31 | 32 | const Abi = require('@parity/abi'); 33 | const Api = require('./index'); 34 | 35 | module.exports = { Api, Abi }; 36 | -------------------------------------------------------------------------------- /packages/api/src/polyfill.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | if (typeof Promise === 'undefined') { 18 | require('es6-promise').polyfill(); 19 | } 20 | 21 | if (typeof fetch === 'undefined') { 22 | require('isomorphic-fetch'); 23 | } 24 | -------------------------------------------------------------------------------- /packages/api/src/provider/current.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const JsonRpcEncoder = require('../transport/jsonRpcEncoder'); 18 | 19 | class Current extends JsonRpcEncoder { 20 | constructor(currentProvider) { 21 | super(); 22 | 23 | this._currentProvider = currentProvider; 24 | } 25 | 26 | send(method, params, callback) { 27 | this._currentProvider.sendAsync( 28 | this.encodeObject(method, params), 29 | (error, result) => { 30 | if (error) { 31 | callback(error); 32 | } else if (result && result.result !== undefined) { 33 | callback(null, result.result); 34 | } else { 35 | callback(null, result); 36 | } 37 | } 38 | ); 39 | } 40 | 41 | get isParity() { 42 | return !!this._currentProvider.isParity; 43 | } 44 | } 45 | 46 | module.exports = Current; 47 | -------------------------------------------------------------------------------- /packages/api/src/provider/http.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Transport = require('../transport').Http; 18 | 19 | class Http extends Transport { 20 | constructor (url, connectTimeout) { 21 | super(url, connectTimeout); 22 | 23 | this.send = this.send.bind(this); 24 | } 25 | 26 | send (method, params, callback) { 27 | this 28 | ._execute(method, params) 29 | .then((result) => callback(null, result)) 30 | .catch((error) => callback(error)); 31 | } 32 | 33 | get isParity () { 34 | return true; 35 | } 36 | } 37 | 38 | module.exports = Http; 39 | -------------------------------------------------------------------------------- /packages/api/src/provider/http.spec.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | /* eslint-disable no-unused-expressions */ 18 | 19 | const Http = require('./http'); 20 | 21 | let provider; 22 | 23 | function createProvider () { 24 | provider = new Http('http://test.com', -1); 25 | } 26 | 27 | describe('provider/Http', () => { 28 | beforeEach(() => { 29 | createProvider(); 30 | }); 31 | 32 | describe('isParity', () => { 33 | it('return true', () => { 34 | expect(provider.isParity).to.be.true; 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/provider/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Current = require('./current'); 18 | const Ipc = require('./ipc'); 19 | const Http = require('./http'); 20 | const PostMessage = require('./postMessage'); 21 | const PromiseProvider = require('./promise'); 22 | const SendAsync = require('./sendAsync'); 23 | const Ws = require('./ws'); 24 | 25 | const WsSecure = Ws; 26 | 27 | module.exports = { 28 | Current, 29 | Ipc, 30 | Http, 31 | PostMessage, 32 | PromiseProvider, 33 | SendAsync, 34 | Ws, 35 | WsSecure 36 | }; 37 | -------------------------------------------------------------------------------- /packages/api/src/provider/ipc.spec.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | /* eslint-disable no-unused-expressions */ 18 | 19 | const IpcProvider = require('./ipc'); 20 | 21 | function createProvider () { 22 | return new IpcProvider('ipc://test.com', '123', false); 23 | } 24 | 25 | describe('provider/IpcProvider', () => { 26 | it('throws error if not Electron', () => { 27 | expect(createProvider).to.throw('IpcProvider must be used in Electron environment.'); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/api/src/provider/sendAsync.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | class SendAsync { 18 | constructor (provider) { 19 | this._provider = provider; 20 | } 21 | 22 | send () { 23 | throw new Error('Provider does not support the sync send(payload) method'); 24 | } 25 | 26 | sendAsync ({ method, params }, callback) { 27 | this._provider.send(method, params, (error, result) => { 28 | callback(error, { result }); 29 | }); 30 | } 31 | 32 | get isParity () { 33 | return !!this._provider.isParity; 34 | } 35 | } 36 | 37 | module.exports = SendAsync; 38 | -------------------------------------------------------------------------------- /packages/api/src/provider/ws.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Transport = require('../transport').Ws; 18 | 19 | class Ws extends Transport { 20 | constructor (url, token, autoconnect) { 21 | super(url, token, autoconnect); 22 | 23 | this.send = this.send.bind(this); 24 | } 25 | 26 | send (method, params, callback) { 27 | this 28 | ._execute(method, params) 29 | .then((result) => callback(null, result)) 30 | .catch((error) => callback(error)); 31 | } 32 | 33 | get isParity () { 34 | return true; 35 | } 36 | } 37 | 38 | module.exports = Ws; 39 | -------------------------------------------------------------------------------- /packages/api/src/provider/ws.spec.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | /* eslint-disable no-unused-expressions */ 18 | 19 | const Ws = require('./ws'); 20 | 21 | let provider; 22 | 23 | function createProvider () { 24 | provider = new Ws('ws://test.com', '123', false); 25 | } 26 | 27 | describe('provider/Ws', () => { 28 | beforeEach(() => { 29 | createProvider(); 30 | }); 31 | 32 | describe('isParity', () => { 33 | it('return true', () => { 34 | expect(provider.isParity).to.be.true; 35 | }); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/api/src/pubsub/eth/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Eth = require('./eth'); 18 | 19 | module.exports = Eth; 20 | -------------------------------------------------------------------------------- /packages/api/src/pubsub/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const PubSub = require('./pubsub'); 18 | 19 | module.exports = PubSub; 20 | -------------------------------------------------------------------------------- /packages/api/src/pubsub/net/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Net = require('./net'); 18 | 19 | module.exports = Net; 20 | -------------------------------------------------------------------------------- /packages/api/src/pubsub/net/net.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const PubsubBase = require('../pubsubBase'); 18 | 19 | const { outNumber } = require('../../format/output'); 20 | 21 | class Net extends PubsubBase { 22 | constructor (provider) { 23 | super(provider); 24 | this._api = 'parity'; 25 | } 26 | 27 | version (callback) { 28 | return this.addListener(this._api, 'net_version', callback); 29 | } 30 | 31 | peerCount (callback) { 32 | return this.addListener(this._api, 'net_peerCount', (error, data) => { 33 | error 34 | ? callback(error) 35 | : callback(null, outNumber(data)); 36 | }); 37 | } 38 | 39 | listening (callback) { 40 | return this.addListener(this._api, 'net_listening', callback); 41 | } 42 | } 43 | 44 | module.exports = Net; 45 | -------------------------------------------------------------------------------- /packages/api/src/pubsub/parity/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Parity = require('./parity'); 18 | 19 | module.exports = Parity; 20 | -------------------------------------------------------------------------------- /packages/api/src/pubsub/pubsubBase.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | class PubSubBase { 18 | // Provider for websocket pubsub transport 19 | constructor (provider) { 20 | this._provider = provider; 21 | } 22 | 23 | addListener (module, eventName, callback, eventParams = []) { 24 | if (eventName) { 25 | const params = eventParams 26 | ? [eventName, eventParams] 27 | : [eventName]; 28 | 29 | return this._provider.subscribe(module, callback, params); 30 | } 31 | 32 | return this._provider.subscribe(module, callback, eventParams); 33 | } 34 | 35 | removeListener (subscriptionIds) { 36 | return this._provider.unsubscribe(subscriptionIds); 37 | } 38 | 39 | unsubscribe (subscriptionIds) { 40 | return this.removeListener(subscriptionIds); 41 | } 42 | } 43 | 44 | module.exports = PubSubBase; 45 | -------------------------------------------------------------------------------- /packages/api/src/pubsub/signer/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Signer = require('./signer'); 18 | 19 | module.exports = Signer; 20 | -------------------------------------------------------------------------------- /packages/api/src/pubsub/signer/signer.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const PubsubBase = require('../pubsubBase'); 18 | const { outSignerRequest } = require('../../format/output'); 19 | 20 | class Signer extends PubsubBase { 21 | constructor (provider) { 22 | super(provider); 23 | 24 | this._api = { 25 | subscribe: 'signer_subscribePending', 26 | unsubscribe: 'signer_unsubscribePending', 27 | subscription: 'signer_pending' 28 | }; 29 | } 30 | 31 | pendingRequests (callback) { 32 | return this.addListener(this._api, null, (error, data) => { 33 | error 34 | ? callback(error) 35 | : callback(null, data.map(outSignerRequest)); 36 | }); 37 | } 38 | 39 | requestsToConfirm (callback) { 40 | return this.pendingRequests(callback); 41 | } 42 | } 43 | 44 | module.exports = Signer; 45 | -------------------------------------------------------------------------------- /packages/api/src/rpc/db/db.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const { inHex } = require('../../format/input'); 18 | 19 | class Db { 20 | constructor (transport) { 21 | this._transport = transport; 22 | } 23 | 24 | getHex (dbName, keyName) { 25 | return this._transport 26 | .send('db_getHex', dbName, keyName); 27 | } 28 | 29 | getString (dbName, keyName) { 30 | return this._transport 31 | .send('db_getString', dbName, keyName); 32 | } 33 | 34 | putHex (dbName, keyName, hexData) { 35 | return this._transport 36 | .send('db_putHex', dbName, keyName, inHex(hexData)); 37 | } 38 | 39 | putString (dbName, keyName, stringData) { 40 | return this._transport 41 | .send('db_putString', dbName, keyName, stringData); 42 | } 43 | } 44 | 45 | module.exports = Db; 46 | -------------------------------------------------------------------------------- /packages/api/src/rpc/db/db.spec.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const { TEST_HTTP_URL, mockHttp } = require('../../../test/mockRpc'); 18 | 19 | const { Http, PromiseProvider } = require('../../provider'); 20 | const Db = require('./db'); 21 | 22 | const instance = new Db(new PromiseProvider(new Http(TEST_HTTP_URL, -1))); 23 | 24 | describe('rpc/Db', () => { 25 | let scope; 26 | 27 | describe('putHex', () => { 28 | beforeEach(() => { 29 | scope = mockHttp([{ method: 'db_putHex', reply: { result: [] } }]); 30 | }); 31 | 32 | it('formats the inputs correctly', () => { 33 | return instance.putHex('db', 'key', '1234').then(() => { 34 | expect(scope.body.db_putHex.params).to.deep.equal(['db', 'key', '0x1234']); 35 | }); 36 | }); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /packages/api/src/rpc/db/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Db = require('./db'); 18 | 19 | module.exports = Db; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/eth/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Eth = require('./eth'); 18 | 19 | module.exports = Eth; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Db = require('./db'); 18 | const Eth = require('./eth'); 19 | const Parity = require('./parity'); 20 | const Net = require('./net'); 21 | const Personal = require('./personal'); 22 | const Private = require('./private'); 23 | const Shell = require('./shell'); 24 | const Shh = require('./shh'); 25 | const Signer = require('./signer'); 26 | const Trace = require('./trace'); 27 | const Web3 = require('./web3'); 28 | 29 | module.exports = { 30 | Db, 31 | Eth, 32 | Parity, 33 | Net, 34 | Personal, 35 | Private, 36 | Shell, 37 | Shh, 38 | Signer, 39 | Trace, 40 | Web3 41 | }; 42 | -------------------------------------------------------------------------------- /packages/api/src/rpc/net/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Net = require('./net'); 18 | 19 | module.exports = Net; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/net/net.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const { outNumber } = require('../../format/output'); 18 | 19 | class Net { 20 | constructor (provider) { 21 | this._provider = provider; 22 | } 23 | 24 | listening () { 25 | return this._provider 26 | .send('net_listening'); 27 | } 28 | 29 | peerCount () { 30 | return this._provider 31 | .send('net_peerCount') 32 | .then(outNumber); 33 | } 34 | 35 | version () { 36 | return this._provider 37 | .send('net_version'); 38 | } 39 | } 40 | module.exports = Net; 41 | -------------------------------------------------------------------------------- /packages/api/src/rpc/net/net.spec.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | /* eslint-disable no-unused-expressions */ 18 | 19 | const { TEST_HTTP_URL, mockHttp } = require('../../../test/mockRpc'); 20 | const { isBigNumber } = require('../../../test/types'); 21 | 22 | const { Http, PromiseProvider } = require('../../provider'); 23 | const Net = require('./net'); 24 | 25 | const instance = new Net(new PromiseProvider(new Http(TEST_HTTP_URL, -1))); 26 | 27 | describe('rpc/Net', () => { 28 | describe('peerCount', () => { 29 | it('returns the connected peers, formatted', () => { 30 | mockHttp([{ method: 'net_peerCount', reply: { result: '0x123456' } }]); 31 | 32 | return instance.peerCount().then((count) => { 33 | expect(isBigNumber(count)).to.be.true; 34 | expect(count.eq(0x123456)).to.be.true; 35 | }); 36 | }); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /packages/api/src/rpc/parity/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Parity = require('./parity'); 18 | 19 | module.exports = Parity; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/personal/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Personal = require('./personal'); 18 | 19 | module.exports = Personal; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/private/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Private = require('./private'); 18 | 19 | module.exports = Private; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/private/private.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const { inData, inOptions, inBlockNumber } = require('../../format/input'); 18 | const { outPrivateReceipt } = require('../../format/output'); 19 | 20 | class Private { 21 | constructor (provider) { 22 | this._provider = provider; 23 | } 24 | 25 | sendTransaction (data) { 26 | return this._provider 27 | .send('private_sendTransaction', inData(data)) 28 | .then(outPrivateReceipt); 29 | } 30 | 31 | call (blockNumber = 'latest', options) { 32 | return this._provider 33 | .send('private_call', inBlockNumber(blockNumber), inOptions(options)); 34 | } 35 | } 36 | 37 | module.exports = Private; 38 | -------------------------------------------------------------------------------- /packages/api/src/rpc/shell/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Shell = require('./shell'); 18 | 19 | module.exports = Shell; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/shh/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Shh = require('./shh'); 18 | 19 | module.exports = Shh; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/signer/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Signer = require('./signer'); 18 | 19 | module.exports = Signer; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/trace/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Trace = require('./trace'); 18 | 19 | module.exports = Trace; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/web3/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Web3 = require('./web3'); 18 | 19 | module.exports = Web3; 20 | -------------------------------------------------------------------------------- /packages/api/src/rpc/web3/web3.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const { inHex } = require('../../format/input'); 18 | 19 | class Web3 { 20 | constructor (provider) { 21 | this._provider = provider; 22 | } 23 | 24 | clientVersion () { 25 | return this._provider 26 | .send('web3_clientVersion'); 27 | } 28 | 29 | sha3 (hexStr) { 30 | return this._provider 31 | .send('web3_sha3', inHex(hexStr)); 32 | } 33 | } 34 | 35 | module.exports = Web3; 36 | -------------------------------------------------------------------------------- /packages/api/src/rpc/web3/web3.spec.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const { TEST_HTTP_URL, mockHttp } = require('../../../test/mockRpc'); 18 | 19 | const { Http, PromiseProvider } = require('../../provider'); 20 | const Web3 = require('./web3'); 21 | 22 | const instance = new Web3(new PromiseProvider(new Http(TEST_HTTP_URL, -1))); 23 | 24 | describe('rpc/Web3', () => { 25 | let scope; 26 | 27 | describe('sha3', () => { 28 | beforeEach(() => { 29 | scope = mockHttp([{ method: 'web3_sha3', reply: { result: [] } }]); 30 | }); 31 | 32 | it('formats the inputs correctly', () => { 33 | return instance.sha3('1234').then(() => { 34 | expect(scope.body.web3_sha3.params).to.deep.equal(['0x1234']); 35 | }); 36 | }); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /packages/api/src/subscriptions/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Logging = require('./logging'); 18 | const Manager = require('./manager'); 19 | 20 | Manager.Logging = Logging; 21 | 22 | module.exports = Manager; 23 | -------------------------------------------------------------------------------- /packages/api/src/subscriptions/logging.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | let instance = null; 18 | 19 | class Logging { 20 | constructor (updateSubscriptions) { 21 | this._updateSubscriptions = updateSubscriptions; 22 | 23 | instance = this; 24 | } 25 | 26 | get isStarted () { 27 | return true; 28 | } 29 | 30 | start () { 31 | } 32 | } 33 | 34 | Logging.send = function (method, params, json) { 35 | if (!instance) { 36 | return; 37 | } 38 | 39 | return instance._updateSubscriptions('logging', null, { 40 | method, 41 | params, 42 | json 43 | }); 44 | }; 45 | 46 | module.exports = Logging; 47 | -------------------------------------------------------------------------------- /packages/api/src/transport/error.spec.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const TransportError = require('./error'); 18 | 19 | describe('transport/Error', () => { 20 | describe('requestRejected', () => { 21 | it('creates a Request Rejected error', () => { 22 | const error = TransportError.requestRejected('method'); 23 | 24 | expect(error.code).to.equal(TransportError.ERROR_CODES.REQUEST_REJECTED); 25 | expect(error.message).to.match(/been rejected/); 26 | expect(error.method).to.equal('method'); 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/api/src/transport/http/http.e2e.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | /* eslint-disable no-unused-expressions */ 18 | 19 | const Http = require('./http'); 20 | 21 | const http = new Http('http://localhost:8545'); 22 | 23 | describe('transport/Http', () => { 24 | it('connects and makes a call to web3_clientVersion', () => { 25 | return http.execute('web3_clientVersion').then((version) => { 26 | const [client] = version.split('/'); 27 | 28 | expect(client === 'Geth' || client === 'Parity').to.be.ok; 29 | }); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /packages/api/src/transport/http/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Http = require('./http'); 18 | 19 | module.exports = Http; 20 | -------------------------------------------------------------------------------- /packages/api/src/transport/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Ws = require('./ws'); 18 | 19 | const Http = require('./http'); 20 | const TransportError = require('./error'); 21 | const Middleware = require('./middleware'); 22 | 23 | const WsSecure = Ws; 24 | 25 | module.exports = { 26 | Http, 27 | Middleware, 28 | TransportError, 29 | Ws, 30 | WsSecure 31 | }; 32 | -------------------------------------------------------------------------------- /packages/api/src/transport/jsonRpcEncoder.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const EventEmitter = require('eventemitter3'); 18 | 19 | class JsonRpcEncoder extends EventEmitter { 20 | constructor () { 21 | super(); 22 | 23 | this._id = 1; 24 | } 25 | 26 | encodeObject (method, params) { 27 | return { 28 | id: this._id++, 29 | jsonrpc: '2.0', 30 | method: method, 31 | params: params 32 | }; 33 | } 34 | 35 | encode (method, params) { 36 | return JSON.stringify(this.encodeObject(method, params)); 37 | } 38 | 39 | get id () { 40 | return this._id; 41 | } 42 | } 43 | 44 | module.exports = JsonRpcEncoder; 45 | -------------------------------------------------------------------------------- /packages/api/src/transport/ws/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | const Ws = require('./ws'); 18 | 19 | module.exports = Ws; 20 | -------------------------------------------------------------------------------- /packages/api/src/transport/ws/polyfill.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | if (typeof WebSocket === 'undefined') { 18 | global.WebSocket = require('websocket').w3cwebsocket; 19 | } 20 | -------------------------------------------------------------------------------- /packages/api/src/transport/ws/ws.e2e.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | 4 | // Parity is free software: you can redistribute it and/or modify 5 | // it under the terms of the GNU General Public License as published by 6 | // the Free Software Foundation, either version 3 of the License, or 7 | // (at your option) any later version. 8 | 9 | // Parity is distributed in the hope that it will be useful, 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | // GNU General Public License for more details. 13 | 14 | // You should have received a copy of the GNU General Public License 15 | // along with Parity. If not, see . 16 | 17 | /* eslint-disable no-unused-expressions */ 18 | 19 | const Ws = require('./ws'); 20 | 21 | const ws = new Ws('ws://localhost:8546/'); 22 | 23 | describe('transport/WsSecure', () => { 24 | it('connects and makes a call to web3_clientVersion', () => { 25 | return ws.execute('web3_clientVersion').then((version) => { 26 | const [client] = version.split('/'); 27 | 28 | expect(client === 'Geth' || client === 'Parity').to.be.ok; 29 | }); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /packages/api/src/util/address.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | export { isAddress, toChecksumAddress } from '@parity/abi/lib/util/address'; 7 | -------------------------------------------------------------------------------- /packages/api/src/util/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | export * from './address'; 7 | export * from './decode'; 8 | export * from './encode'; 9 | export * from './format'; 10 | export * from './sha3'; 11 | export * from './types'; 12 | export * from './wei'; 13 | -------------------------------------------------------------------------------- /packages/api/src/util/sha3.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { keccak_256 } from 'js-sha3'; 7 | 8 | import { hexToBytes } from './format'; 9 | import { isHex } from './types'; 10 | import { Bytes } from '../types'; 11 | 12 | type Encoding = 'hex' | 'raw'; 13 | 14 | /** 15 | * 16 | * @param value - The value to hash 17 | * @param options - Set the encoding in the options, encoding can be `'hex'` 18 | * or `'raw'`. 19 | */ 20 | export const sha3 = ( 21 | value: string | Bytes, 22 | options?: { encoding: Encoding } 23 | ): string => { 24 | const forceHex = options && options.encoding === 'hex'; 25 | 26 | if (forceHex || (!options && isHex(value))) { 27 | const bytes = hexToBytes(value as string); 28 | 29 | return sha3(bytes); 30 | } 31 | 32 | const hash = keccak_256(value); 33 | 34 | return `0x${hash}`; 35 | }; 36 | 37 | export const sha3Text = (val: string) => sha3(val, { encoding: 'raw' }); 38 | -------------------------------------------------------------------------------- /packages/api/src/util/types.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | export * from '@parity/abi/lib/util/types'; 7 | -------------------------------------------------------------------------------- /packages/api/test/mocha.opts: -------------------------------------------------------------------------------- 1 | -r ./test/mocha.config 2 | -------------------------------------------------------------------------------- /packages/api/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.json", 3 | "compilerOptions": { 4 | "allowJs": true, 5 | "declaration": false, 6 | "outDir": "./lib" 7 | }, 8 | "include": ["src/**/*"], 9 | "exclude": ["src/**/*.spec.js"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/contracts/README.md: -------------------------------------------------------------------------------- 1 | # @parity/contracts 2 | 3 | Parity's [contracts](https://github.com/parity-contracts) as ES6 classes. 4 | 5 | [![Build Status](https://travis-ci.org/paritytech/js-libs.svg?branch=master)](https://travis-ci.org/paritytech/js-libs) 6 | [![npm (scoped)](https://img.shields.io/npm/v/@parity/contracts.svg)](https://www.npmjs.com/package/@parity/contracts) 7 | [![npm](https://img.shields.io/npm/dw/@parity/contracts.svg)](https://www.npmjs.com/package/@parity/contracts) 8 | [![dependencies Status](https://david-dm.org/paritytech/js-libs/status.svg?path=packages/contracts)](https://david-dm.org/paritytech/js-libs?path=packages/contracts) 9 | 10 | ## Installation 11 | 12 | ```bash 13 | yarn add @parity/contracts 14 | ``` 15 | 16 | ## Usage 17 | 18 | ### The Contracts object 19 | 20 | ```javascript 21 | import Api from '@parity/api'; 22 | import Contracts from '@parity/contracts'; 23 | 24 | const ethereumProvider = ...; // Put your Ethereum provider here, e.g. from MetaMask 25 | const api = new Api(ethereumProvider); 26 | 27 | const contracts = Contracts.get(api); 28 | 29 | // The contracts object exposes the following contracts: 30 | contracts.badgerefg 31 | contracts.dappref 32 | contracts.githubhint 33 | contracts.registry 34 | contracts.signaturereg 35 | contracts.tokenreg 36 | ``` 37 | 38 | See the [docs/](docs) folder to see the properties of each of those contracts. 39 | 40 | ### Import ABIs 41 | 42 | ```javascript 43 | import { eip20 } from '@parity/contracts/lib/abi'; 44 | ``` 45 | 46 | The list of available ABIs is in the [src/abi/](src/abi) folder. 47 | -------------------------------------------------------------------------------- /packages/contracts/docs/SUMMARY.md: -------------------------------------------------------------------------------- 1 | * ["badgereg"](modules/_badgereg_.md) 2 | * [BadgeReg](classes/_badgereg_.badgereg.md) 3 | * [Metadata](interfaces/_badgereg_.metadata.md) 4 | * ["code/wallet"](modules/_code_wallet_.md) 5 | * ["contracts"](modules/_contracts_.md) 6 | * [Contracts](classes/_contracts_.contracts.md) 7 | * ["dappreg"](modules/_dappreg_.md) 8 | * [DappReg](classes/_dappreg_.dappreg.md) 9 | * ["githubhint"](modules/_githubhint_.md) 10 | * [GithubHint](classes/_githubhint_.githubhint.md) 11 | * ["registry"](modules/_registry_.md) 12 | * [Registry](classes/_registry_.registry.md) 13 | * [QueueItem](interfaces/_registry_.queueitem.md) 14 | * ["signaturereg"](modules/_signaturereg_.md) 15 | * [SignatureReg](classes/_signaturereg_.signaturereg.md) 16 | * ["tokenreg"](modules/_tokenreg_.md) 17 | * [TokenReg](classes/_tokenreg_.tokenreg.md) 18 | * ["utils/testHelpers"](modules/_utils_testhelpers_.md) 19 | -------------------------------------------------------------------------------- /packages/contracts/docs/classes/_githubhint_.githubhint.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **GithubHint** 6 | 7 | # Constructors 8 | 9 | 10 | 11 | ## constructor 12 | 13 | ⊕ **new GithubHint**(api: *`Api`*, registry: *[Registry](_registry_.registry.md)*): [GithubHint](_githubhint_.githubhint.md) 14 | 15 | *Defined in [githubhint.ts:12](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/githubhint.ts#L12)* 16 | 17 | **Parameters:** 18 | 19 | | Param | Type | 20 | | ------ | ------ | 21 | | api | `Api` | 22 | | registry | [Registry](_registry_.registry.md) | 23 | 24 | **Returns:** [GithubHint](_githubhint_.githubhint.md) 25 | 26 | ___ 27 | 28 | # Methods 29 | 30 | 31 | 32 | ## getContract 33 | 34 | ▸ **getContract**(): `any` 35 | 36 | *Defined in [githubhint.ts:21](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/githubhint.ts#L21)* 37 | 38 | **Returns:** `any` 39 | 40 | ___ 41 | 42 | 43 | ## getEntry 44 | 45 | ▸ **getEntry**(entryId: *`string`*): `any` 46 | 47 | *Defined in [githubhint.ts:36](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/githubhint.ts#L36)* 48 | 49 | **Parameters:** 50 | 51 | | Param | Type | 52 | | ------ | ------ | 53 | | entryId | `string` | 54 | 55 | **Returns:** `any` 56 | 57 | ___ 58 | 59 | 60 | ## getInstance 61 | 62 | ▸ **getInstance**(): `any` 63 | 64 | *Defined in [githubhint.ts:25](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/githubhint.ts#L25)* 65 | 66 | **Returns:** `any` 67 | 68 | ___ 69 | 70 | -------------------------------------------------------------------------------- /packages/contracts/docs/classes/_signaturereg_.signaturereg.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **SignatureReg** 6 | 7 | # Constructors 8 | 9 | 10 | 11 | ## constructor 12 | 13 | ⊕ **new SignatureReg**(api: *`Api`*, registry: *[Registry](_registry_.registry.md)*): [SignatureReg](_signaturereg_.signaturereg.md) 14 | 15 | *Defined in [signaturereg.ts:11](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/signaturereg.ts#L11)* 16 | 17 | **Parameters:** 18 | 19 | | Param | Type | 20 | | ------ | ------ | 21 | | api | `Api` | 22 | | registry | [Registry](_registry_.registry.md) | 23 | 24 | **Returns:** [SignatureReg](_signaturereg_.signaturereg.md) 25 | 26 | ___ 27 | 28 | # Methods 29 | 30 | 31 | 32 | ## getInstance 33 | 34 | ▸ **getInstance**(): `any` 35 | 36 | *Defined in [signaturereg.ts:20](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/signaturereg.ts#L20)* 37 | 38 | **Returns:** `any` 39 | 40 | ___ 41 | 42 | 43 | ## lookup 44 | 45 | ▸ **lookup**(signature: *`string`*): `any` 46 | 47 | *Defined in [signaturereg.ts:24](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/signaturereg.ts#L24)* 48 | 49 | **Parameters:** 50 | 51 | | Param | Type | 52 | | ------ | ------ | 53 | | signature | `string` | 54 | 55 | **Returns:** `any` 56 | 57 | ___ 58 | 59 | -------------------------------------------------------------------------------- /packages/contracts/docs/interfaces/_badgereg_.metadata.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **Metadata** 6 | 7 | # Properties 8 | 9 | 10 | 11 | ## address 12 | 13 | **● address**: *`string`* 14 | 15 | *Defined in [badgereg.ts:14](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/badgereg.ts#L14)* 16 | 17 | ___ 18 | 19 | 20 | ## icon 21 | 22 | **● icon**: *`string`* 23 | 24 | *Defined in [badgereg.ts:18](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/badgereg.ts#L18)* 25 | 26 | ___ 27 | 28 | 29 | ## id 30 | 31 | **● id**: *`number`* 32 | 33 | *Defined in [badgereg.ts:15](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/badgereg.ts#L15)* 34 | 35 | ___ 36 | 37 | 38 | ## name 39 | 40 | **● name**: *`string`* 41 | 42 | *Defined in [badgereg.ts:16](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/badgereg.ts#L16)* 43 | 44 | ___ 45 | 46 | 47 | ## title 48 | 49 | **● title**: *`string`* 50 | 51 | *Defined in [badgereg.ts:17](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/badgereg.ts#L17)* 52 | 53 | ___ 54 | 55 | -------------------------------------------------------------------------------- /packages/contracts/docs/interfaces/_registry_.queueitem.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **QueueItem** 6 | 7 | # Methods 8 | 9 | 10 | 11 | ## resolve 12 | 13 | ▸ **resolve**(...args: *`any`[]*): `void` 14 | 15 | *Defined in [registry.ts:10](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/registry.ts#L10)* 16 | 17 | **Parameters:** 18 | 19 | | Param | Type | 20 | | ------ | ------ | 21 | | `Rest` args | `any`[] | 22 | 23 | **Returns:** `void` 24 | 25 | ___ 26 | 27 | -------------------------------------------------------------------------------- /packages/contracts/docs/modules/_badgereg_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [BadgeReg](../classes/_badgereg_.badgereg.md) 8 | 9 | ### Interfaces 10 | 11 | * [Metadata](../interfaces/_badgereg_.metadata.md) 12 | 13 | ### Variables 14 | 15 | * [ZERO20](_badgereg_.md#zero20) 16 | * [ZERO32](_badgereg_.md#zero32) 17 | 18 | --- 19 | 20 | # Variables 21 | 22 | 23 | 24 | ## `` ZERO20 25 | 26 | **● ZERO20**: *"0x0000000000000000000000000000000000000000"* = "0x0000000000000000000000000000000000000000" 27 | 28 | *Defined in [badgereg.ts:21](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/badgereg.ts#L21)* 29 | 30 | ___ 31 | 32 | 33 | ## `` ZERO32 34 | 35 | **● ZERO32**: *"0x0000000000000000000000000000000000000000000000000000000000000000"* = "0x0000000000000000000000000000000000000000000000000000000000000000" 36 | 37 | *Defined in [badgereg.ts:22](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/badgereg.ts#L22)* 38 | 39 | ___ 40 | 41 | -------------------------------------------------------------------------------- /packages/contracts/docs/modules/_contracts_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Contracts](../classes/_contracts_.contracts.md) 8 | 9 | ### Variables 10 | 11 | * [instance](_contracts_.md#instance) 12 | 13 | --- 14 | 15 | # Variables 16 | 17 | 18 | 19 | ## `` instance 20 | 21 | **● instance**: *[Contracts](../classes/_contracts_.contracts.md)* = null 22 | 23 | *Defined in [contracts.ts:14](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/contracts.ts#L14)* 24 | 25 | ___ 26 | 27 | -------------------------------------------------------------------------------- /packages/contracts/docs/modules/_dappreg_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [DappReg](../classes/_dappreg_.dappreg.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/contracts/docs/modules/_githubhint_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [GithubHint](../classes/_githubhint_.githubhint.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/contracts/docs/modules/_registry_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [Registry](../classes/_registry_.registry.md) 8 | 9 | ### Interfaces 10 | 11 | * [QueueItem](../interfaces/_registry_.queueitem.md) 12 | 13 | ### Variables 14 | 15 | * [REGISTRY_V1_HASHES](_registry_.md#registry_v1_hashes) 16 | 17 | --- 18 | 19 | # Variables 20 | 21 | 22 | 23 | ## `` REGISTRY_V1_HASHES 24 | 25 | **● REGISTRY_V1_HASHES**: *`string`[]* = [ 26 | '0x34f7c51bbb1b1902fbdabfdf04811100f5c9f998f26dd535d2f6f977492c748e', // ropsten 27 | '0x64c3ee34851517a9faecd995c102b339f03e564ad6772dc43a26f993238b20ec' // homestead 28 | ] 29 | 30 | *Defined in [registry.ts:13](https://github.com/paritytech/js-libs/blob/9aff8ef/packages/contracts/src/registry.ts#L13)* 31 | 32 | ___ 33 | 34 | -------------------------------------------------------------------------------- /packages/contracts/docs/modules/_signaturereg_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [SignatureReg](../classes/_signaturereg_.signaturereg.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/contracts/docs/modules/_tokenreg_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Classes 6 | 7 | * [TokenReg](../classes/_tokenreg_.tokenreg.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/contracts/docs/modules/_utils_testhelpers_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /packages/contracts/jest.config.js: -------------------------------------------------------------------------------- 1 | const baseConfig = require('../../jest.config'); 2 | 3 | module.exports = baseConfig; 4 | -------------------------------------------------------------------------------- /packages/contracts/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@parity/contracts", 3 | "description": "Parity's contracts as ES6 classes.", 4 | "version": "5.1.19", 5 | "author": "Parity Team ", 6 | "license": "MIT", 7 | "repository": "https://github.com/paritytech/js-libs/tree/master/packages/contracts", 8 | "main": "lib/index.js", 9 | "keywords": [ 10 | "Ethereum", 11 | "Contracts", 12 | "Solidity", 13 | "Parity" 14 | ], 15 | "publishConfig": { 16 | "access": "public" 17 | }, 18 | "scripts": { 19 | "docs": "typedoc && rimraf docs/README.md", 20 | "prebuild": "rimraf lib", 21 | "typecheck": "tsc --noEmit", 22 | "build": "tsc", 23 | "test": "jest" 24 | }, 25 | "dependencies": { 26 | "@parity/abi": "^5.1.19", 27 | "@parity/api": "^5.1.19", 28 | "bignumber.js": "^8.0.1" 29 | }, 30 | "devDependencies": { 31 | "typescript": "^3.1.6" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/contracts/src/abi/certifier.json: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"getAddress","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"getUint","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"}],"name":"certified","outputs":[{"name":"","type":"bool"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"_who","type":"address"},{"name":"_field","type":"string"}],"name":"get","outputs":[{"name":"","type":"bytes32"}],"payable":false,"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"}],"name":"Confirmed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"who","type":"address"}],"name":"Revoked","type":"event"}] -------------------------------------------------------------------------------- /packages/contracts/src/abi/owned.json: -------------------------------------------------------------------------------- 1 | [{"constant":false,"inputs":[{"name":"_new","type":"address"}],"name":"setOwner","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"old","type":"address"},{"indexed":true,"name":"current","type":"address"}],"name":"NewOwner","type":"event"}] 2 | -------------------------------------------------------------------------------- /packages/contracts/src/abi/vouchfor.json: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"certifier","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_what","type":"bytes32"}],"name":"vouch","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_what","type":"bytes32"},{"name":"_index","type":"uint256"}],"name":"vouched","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_what","type":"bytes32"},{"name":"_index","type":"uint256"}],"name":"unvouch","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"","type":"bytes32"},{"name":"","type":"uint256"}],"name":"vouchers","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_certifier","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"who","type":"address"},{"indexed":false,"name":"what","type":"bytes32"}],"name":"Vouched","type":"event"}] 2 | -------------------------------------------------------------------------------- /packages/contracts/src/ambient.d.ts: -------------------------------------------------------------------------------- 1 | // https://hackernoon.com/import-json-into-typescript-8d465beded79 2 | declare module '*.json' { 3 | const value: any; 4 | export default value; 5 | } 6 | 7 | declare module '@parity/abi'; 8 | declare module '@parity/api/lib/util'; 9 | declare module '@parity/api/lib/util/format'; 10 | -------------------------------------------------------------------------------- /packages/contracts/src/code/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | export { wallet } from './wallet'; 7 | -------------------------------------------------------------------------------- /packages/contracts/src/githubhint.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { ContractInstance } from './types'; 7 | import GithubHint from './githubhint'; 8 | import mockApi from './utils/testHelpers'; 9 | import Registry from './registry'; 10 | 11 | let githubHint: GithubHint; 12 | let instance: ContractInstance; 13 | let registry: Registry; 14 | 15 | function create () { 16 | instance = { 17 | __id: 'testInstance', 18 | entries: { 19 | call: jest.fn(() => Promise.resolve('testValue')) 20 | } 21 | }; 22 | 23 | const api = mockApi(instance); 24 | registry = new Registry(api); 25 | registry.getContract = jest.fn(() => Promise.resolve({ instance })); 26 | 27 | githubHint = new GithubHint({}, registry); 28 | 29 | return githubHint; 30 | } 31 | 32 | describe('contracts/GithubHint', () => { 33 | beforeEach(() => { 34 | create(); 35 | 36 | return githubHint.getInstance(); 37 | }); 38 | 39 | it('instantiates successfully', () => { 40 | expect(githubHint).toBeTruthy(); 41 | }); 42 | 43 | it('attaches the instance on create', () => { 44 | // @ts-ignore Access private property 45 | expect(githubHint._instance.__id).toEqual('testInstance'); 46 | }); 47 | 48 | describe('interface', () => { 49 | describe('getEntry', () => { 50 | beforeEach(() => { 51 | return githubHint.getEntry('testId'); 52 | }); 53 | 54 | it('calls entries on the instance', () => { 55 | expect(instance.entries.call).toHaveBeenCalledWith({}, ['testId']); 56 | }); 57 | }); 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /packages/contracts/src/githubhint.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { Api, Contract, ContractInstance } from './types'; 7 | import Registry from './registry'; 8 | 9 | export default class GithubHint { 10 | private _api: Api; 11 | private _instance: ContractInstance = null; 12 | private _registry: Registry; 13 | 14 | constructor (api: Api, registry: Registry) { 15 | this._api = api; 16 | this._registry = registry; 17 | 18 | this.getInstance(); 19 | } 20 | 21 | getContract () { 22 | return this._registry.getContract('githubhint'); 23 | } 24 | 25 | getInstance () { 26 | if (this._instance) { 27 | return Promise.resolve(this._instance); 28 | } 29 | 30 | return this.getContract().then((contract: Contract) => { 31 | this._instance = contract.instance; 32 | return this._instance; 33 | }); 34 | } 35 | 36 | getEntry (entryId: string) { 37 | return this.getInstance().then((instance: ContractInstance) => { 38 | return instance.entries.call({}, [entryId]); 39 | }); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/contracts/src/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import contracts from './contracts'; 7 | 8 | export default contracts; 9 | -------------------------------------------------------------------------------- /packages/contracts/src/signaturereg.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { Api, ContractInstance } from './types'; 7 | import Registry from './registry'; 8 | 9 | export default class SignatureReg { 10 | private _api: Api; 11 | private _registry: Registry; 12 | 13 | constructor (api: Api, registry: Registry) { 14 | this._api = api; 15 | this._registry = registry; 16 | 17 | this.getInstance(); 18 | } 19 | 20 | getInstance () { 21 | return this._registry.getContractInstance('signaturereg'); 22 | } 23 | 24 | lookup (signature: string) { 25 | return this.getInstance().then((instance: ContractInstance) => { 26 | return instance.entries.call({}, [signature]); 27 | }); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/contracts/src/tokenreg.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { Api, Contract, ContractInstance } from './types'; 7 | import Registry from './registry'; 8 | 9 | export default class TokenReg { 10 | private _api: Api; 11 | private _registry: Registry; 12 | 13 | constructor (api: Api, registry: Registry) { 14 | this._api = api; 15 | this._registry = registry; 16 | 17 | this.getInstance(); 18 | } 19 | 20 | getContract () { 21 | return this._registry.getContract('tokenreg'); 22 | } 23 | 24 | getInstance () { 25 | return this.getContract().then((contract: Contract) => contract.instance); 26 | } 27 | 28 | tokenCount () { 29 | return this.getInstance().then((instance: ContractInstance) => { 30 | return instance.tokenCount.call(); 31 | }); 32 | } 33 | 34 | token (index: number) { 35 | return this.getInstance().then((instance: ContractInstance) => { 36 | return instance.token.call({}, [index]); 37 | }); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /packages/contracts/src/types.d.ts: -------------------------------------------------------------------------------- 1 | // TODO Take from @parity/api 2 | export type Api = any; 3 | export type ContractInstance = any; 4 | export interface Contract { 5 | instance: ContractInstance; 6 | } 7 | -------------------------------------------------------------------------------- /packages/contracts/src/utils/testHelpers.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import * as apiutil from '@parity/api/lib/util'; 7 | 8 | import { ContractInstance } from '../types'; 9 | 10 | /** 11 | * @ignore 12 | */ 13 | const mockApi = (instance: ContractInstance) => ({ 14 | eth: { 15 | getCode: jest.fn(() => Promise.resolve('0x123456')) 16 | }, 17 | parity: { 18 | registryAddress: jest.fn(() => Promise.resolve('testRegistryAddress')) 19 | }, 20 | util: apiutil, 21 | newContract: jest.fn(() => ({ instance })) 22 | }); 23 | 24 | export default mockApi; 25 | -------------------------------------------------------------------------------- /packages/contracts/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "resolveJsonModule": true, 4 | "outDir": "./lib" 5 | }, 6 | "extends": "../../tsconfig.json", 7 | "include": ["./src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/contracts/typedoc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | exclude: ['**/*spec.ts', '**/index.ts'], 3 | excludeExternals: true, 4 | excludePrivate: true, 5 | hideGenerator: true, 6 | includes: './src', 7 | out: 'docs', 8 | module: 'commonjs', 9 | mdEngine: 'gitbook', 10 | stripInternal: 'true', 11 | theme: 'markdown' 12 | }; 13 | -------------------------------------------------------------------------------- /packages/electron/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | ## [5.1.13](https://github.com/paritytech/js-libs/tree/master/packages/electron/compare/v5.1.12...v5.1.13) (2019-09-13) 7 | 8 | **Note:** Version bump only for package @parity/electron 9 | 10 | 11 | 12 | 13 | 14 | ## [5.1.6](https://github.com/paritytech/js-libs/tree/master/packages/electron/compare/v5.1.5...v5.1.6) (2019-06-11) 15 | 16 | **Note:** Version bump only for package @parity/electron 17 | 18 | 19 | 20 | 21 | 22 | ## [5.1.5](https://github.com/paritytech/js-libs/tree/master/packages/electron/compare/v5.1.4...v5.1.5) (2019-05-31) 23 | 24 | **Note:** Version bump only for package @parity/electron 25 | 26 | 27 | 28 | 29 | 30 | # [5.1.0](https://github.com/paritytech/js-libs/tree/master/packages/electron/compare/v5.0.1...v5.1.0) (2019-03-12) 31 | 32 | 33 | ### Features 34 | 35 | * add versionInfo$ ([#205](https://github.com/paritytech/js-libs/tree/master/packages/electron/issues/205)) ([e18d839](https://github.com/paritytech/js-libs/tree/master/packages/electron/commit/e18d839)) 36 | 37 | 38 | 39 | 40 | 41 | # [5.0.0](https://github.com/paritytech/js-libs/tree/master/packages/electron/compare/v4.1.1...v5.0.0) (2019-03-05) 42 | 43 | **Note:** Version bump only for package @parity/electron 44 | 45 | 46 | 47 | 48 | 49 | # [4.0.0](https://github.com/paritytech/js-libs/tree/master/packages/electron/compare/v3.0.31...v4.0.0) (2019-01-22) 50 | 51 | **Note:** Version bump only for package @parity/electron 52 | -------------------------------------------------------------------------------- /packages/electron/README.md: -------------------------------------------------------------------------------- 1 | docs/README.md -------------------------------------------------------------------------------- /packages/electron/docs/interfaces/checkclocksyncresult.md: -------------------------------------------------------------------------------- 1 | [@parity/electron](../README.md) > [CheckClockSyncResult](../interfaces/checkclocksyncresult.md) 2 | 3 | # Interface: CheckClockSyncResult 4 | 5 | ## Hierarchy 6 | 7 | **CheckClockSyncResult** 8 | 9 | ## Index 10 | 11 | ### Properties 12 | 13 | * [isClockSync](checkclocksyncresult.md#isclocksync) 14 | * [timeDrift](checkclocksyncresult.md#timedrift) 15 | 16 | --- 17 | 18 | ## Properties 19 | 20 | 21 | 22 | ### isClockSync 23 | 24 | **● isClockSync**: *`boolean`* 25 | 26 | *Defined in [checkClockSync.ts:9](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/checkClockSync.ts#L9)* 27 | 28 | ___ 29 | 30 | 31 | ### timeDrift 32 | 33 | **● timeDrift**: *`number`* 34 | 35 | *Defined in [checkClockSync.ts:10](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/checkClockSync.ts#L10)* 36 | 37 | ___ 38 | 39 | -------------------------------------------------------------------------------- /packages/electron/docs/interfaces/fetchparityoptions.md: -------------------------------------------------------------------------------- 1 | [@parity/electron](../README.md) > [FetchParityOptions](../interfaces/fetchparityoptions.md) 2 | 3 | # Interface: FetchParityOptions 4 | 5 | ## Hierarchy 6 | 7 | **FetchParityOptions** 8 | 9 | ## Index 10 | 11 | ### Properties 12 | 13 | * [onProgress](fetchparityoptions.md#onprogress) 14 | * [parityChannel](fetchparityoptions.md#paritychannel) 15 | 16 | --- 17 | 18 | ## Properties 19 | 20 | 21 | 22 | ### onProgress 23 | 24 | **● onProgress**: *`function`* 25 | 26 | *Defined in [fetchParity.ts:18](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/fetchParity.ts#L18)* 27 | 28 | #### Type declaration 29 | ▸(progress: *`number`*): `void` 30 | 31 | **Parameters:** 32 | 33 | | Param | Type | 34 | | ------ | ------ | 35 | | progress | `number` | 36 | 37 | **Returns:** `void` 38 | 39 | ___ 40 | 41 | 42 | ### parityChannel 43 | 44 | **● parityChannel**: *`string`* 45 | 46 | *Defined in [fetchParity.ts:19](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/fetchParity.ts#L19)* 47 | 48 | ___ 49 | 50 | -------------------------------------------------------------------------------- /packages/electron/docs/interfaces/isparityrunningoptions.md: -------------------------------------------------------------------------------- 1 | [@parity/electron](../README.md) > [IsParityRunningOptions](../interfaces/isparityrunningoptions.md) 2 | 3 | # Interface: IsParityRunningOptions 4 | 5 | ## Hierarchy 6 | 7 | **IsParityRunningOptions** 8 | 9 | ## Index 10 | 11 | ### Properties 12 | 13 | * [wsInterface](isparityrunningoptions.md#wsinterface) 14 | * [wsPort](isparityrunningoptions.md#wsport) 15 | 16 | --- 17 | 18 | ## Properties 19 | 20 | 21 | 22 | ### wsInterface 23 | 24 | **● wsInterface**: *`string`* 25 | 26 | *Defined in [isParityRunning.ts:12](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/isParityRunning.ts#L12)* 27 | 28 | ___ 29 | 30 | 31 | ### wsPort 32 | 33 | **● wsPort**: * `number` | `string` 34 | * 35 | 36 | *Defined in [isParityRunning.ts:13](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/isParityRunning.ts#L13)* 37 | 38 | ___ 39 | 40 | -------------------------------------------------------------------------------- /packages/electron/docs/interfaces/parityelectronoptions.md: -------------------------------------------------------------------------------- 1 | [@parity/electron](../README.md) > [ParityElectronOptions](../interfaces/parityelectronoptions.md) 2 | 3 | # Interface: ParityElectronOptions 4 | 5 | ## Hierarchy 6 | 7 | **ParityElectronOptions** 8 | 9 | ## Index 10 | 11 | ### Properties 12 | 13 | * [logger](parityelectronoptions.md#logger) 14 | 15 | --- 16 | 17 | ## Properties 18 | 19 | 20 | 21 | ### `` logger 22 | 23 | **● logger**: *`LoggerFunction`* 24 | 25 | *Defined in [index.ts:18](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/index.ts#L18)* 26 | 27 | ___ 28 | 29 | -------------------------------------------------------------------------------- /packages/electron/docs/interfaces/runparityoptions.md: -------------------------------------------------------------------------------- 1 | [@parity/electron](../README.md) > [RunParityOptions](../interfaces/runparityoptions.md) 2 | 3 | # Interface: RunParityOptions 4 | 5 | ## Hierarchy 6 | 7 | **RunParityOptions** 8 | 9 | ## Index 10 | 11 | ### Properties 12 | 13 | * [flags](runparityoptions.md#flags) 14 | * [onParityError](runparityoptions.md#onparityerror) 15 | 16 | --- 17 | 18 | ## Properties 19 | 20 | 21 | 22 | ### flags 23 | 24 | **● flags**: *`string`[]* 25 | 26 | *Defined in [runParity.ts:15](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/runParity.ts#L15)* 27 | 28 | ___ 29 | 30 | 31 | ### onParityError 32 | 33 | **● onParityError**: *`function`* 34 | 35 | *Defined in [runParity.ts:16](https://github.com/paritytech/js-libs/blob/6933cc7/packages/electron/src/runParity.ts#L16)* 36 | 37 | #### Type declaration 38 | ▸(error: *`Error`*): `void` 39 | 40 | **Parameters:** 41 | 42 | | Param | Type | 43 | | ------ | ------ | 44 | | error | `Error` | 45 | 46 | **Returns:** `void` 47 | 48 | ___ 49 | 50 | -------------------------------------------------------------------------------- /packages/electron/jest.config.js: -------------------------------------------------------------------------------- 1 | const baseConfig = require('../../jest.config'); 2 | 3 | module.exports = baseConfig; 4 | -------------------------------------------------------------------------------- /packages/electron/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@parity/electron", 3 | "description": "Control the Parity Ethereum node from Electron.", 4 | "version": "5.1.13", 5 | "author": "Parity Team ", 6 | "license": "MIT", 7 | "repository": "https://github.com/paritytech/js-libs/tree/master/packages/electron", 8 | "main": "lib/index.js", 9 | "keywords": [ 10 | "Ethereum", 11 | "Electron", 12 | "Parity" 13 | ], 14 | "publishConfig": { 15 | "access": "public" 16 | }, 17 | "scripts": { 18 | "docs": "typedoc", 19 | "prebuild": "rimraf lib", 20 | "typecheck": "tsc --noEmit", 21 | "build": "tsc", 22 | "test": "jest" 23 | }, 24 | "dependencies": { 25 | "async-retry": "^1.2.3", 26 | "axios": "^0.19.0", 27 | "checksum": "^0.1.1", 28 | "command-exists": "^1.2.8", 29 | "debug": "^4.1.1", 30 | "electron-dl": "^1.12.0", 31 | "promise-any": "^0.2.0", 32 | "sntp": "^3.0.2" 33 | }, 34 | "devDependencies": { 35 | "@types/async-retry": "^1.2.1", 36 | "@types/checksum": "^0.1.30", 37 | "electron": "^4.0.1", 38 | "typescript": "^3.1.6" 39 | }, 40 | "peerDependencies": { 41 | "electron": "^2.0.2 | ^3.1.0 | ^4.0.1" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/electron/src/README.md: -------------------------------------------------------------------------------- 1 | # @parity/electron 2 | 3 | Control the Parity Ethereum client from electron. 4 | 5 | [![Build Status](https://travis-ci.org/paritytech/js-libs.svg?branch=master)](https://travis-ci.org/paritytech/js-libs) 6 | [![npm (scoped)](https://img.shields.io/npm/v/@parity/electron.svg)](https://www.npmjs.com/package/@parity/electron) 7 | [![npm](https://img.shields.io/npm/dw/@parity/electron.svg)](https://www.npmjs.com/package/@parity/electron) 8 | [![dependencies Status](https://david-dm.org/paritytech/js-libs/status.svg?path=packages/electron)](https://david-dm.org/paritytech/js-libs?path=packages/electron) 9 | 10 | ## Description 11 | 12 | With this library, you will be able, from Electron, to: 13 | 14 | - download Parity Ethereum locally in Electron's user data folder. 15 | - run/stop/check if Parity Ethereum is running. 16 | - get a secure token from Parity Ethereum to access secure RPCs. 17 | 18 | ## Getting Started 19 | 20 | ```bash 21 | yarn add @parity/electron 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```javascript 27 | import parityElectron, { isParityRunning } from '@parity/electron'; 28 | 29 | // Optional: override default options 30 | parityElectron({ 31 | logger: myCustomLoggerFunction // How do we want to log @parity/electron logs? Default is `debug` 32 | }) 33 | 34 | isParityRunning() 35 | .then(() => ...); 36 | ``` 37 | -------------------------------------------------------------------------------- /packages/electron/src/ambient.d.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | // Packages that don't have their TS typings yet 7 | declare module 'command-exists'; 8 | declare module 'electron-dl'; 9 | declare module 'promise-any'; 10 | declare module 'sntp'; 11 | -------------------------------------------------------------------------------- /packages/electron/src/checkClockSync.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { checkClockSync } from './checkClockSync'; 7 | 8 | jest.mock('sntp', () => ({ time: () => Promise.resolve({ t: 1234 }) })); 9 | 10 | it('should return the correct syncness', async done => { 11 | expect(await checkClockSync()).toEqual({ 12 | isClockSync: true, 13 | timeDrift: 1234 14 | }); 15 | done(); 16 | }); 17 | -------------------------------------------------------------------------------- /packages/electron/src/checkClockSync.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { time } from 'sntp'; 7 | 8 | interface CheckClockSyncResult { 9 | isClockSync: boolean; 10 | timeDrift: number; 11 | } 12 | 13 | /** 14 | * @ignore 15 | */ 16 | export const MAX_TIME_DRIFT = 10000; // milliseconds 17 | 18 | /** 19 | * Use SNTP to check if the local clock is synchronized; return the time drift. 20 | */ 21 | export async function checkClockSync (): Promise { 22 | const { t: timeDrift }: { t: number } = await time(); 23 | return { 24 | isClockSync: timeDrift < MAX_TIME_DRIFT, 25 | timeDrift 26 | }; 27 | } 28 | -------------------------------------------------------------------------------- /packages/electron/src/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import * as debug from 'debug'; 7 | import { LoggerFunction } from './types'; 8 | import { setLogger } from './utils/logger'; 9 | 10 | export * from './checkClockSync'; 11 | export * from './getParityPath'; 12 | export * from './fetchParity'; 13 | export * from './isParityRunning'; 14 | export * from './runParity'; 15 | export * from './signerNewToken'; 16 | 17 | interface ParityElectronOptions { 18 | logger?: LoggerFunction; 19 | } 20 | 21 | /** 22 | * Set default options for @parity/electron. Can be skipped if we don't want to 23 | * override default options. 24 | */ 25 | function parityElectron (options: ParityElectronOptions = { logger: debug }) { 26 | if (options.logger) { 27 | setLogger(options.logger); 28 | } 29 | } 30 | 31 | export default parityElectron; 32 | -------------------------------------------------------------------------------- /packages/electron/src/isParityRunning.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import axios from 'axios'; 7 | 8 | import logger from './utils/logger'; 9 | 10 | const TIMEOUT_MS = 1000; 11 | 12 | interface IsParityRunningOptions { 13 | wsInterface: string; 14 | wsPort: number | string; 15 | } 16 | 17 | /** 18 | * Detect if another instance of parity is already running or not. To achieve 19 | * that, we just ping on the common hosts. 20 | */ 21 | export async function isParityRunning ( 22 | options: IsParityRunningOptions = { 23 | wsInterface: '127.0.0.1', 24 | wsPort: '8546' 25 | } 26 | ) { 27 | return new Promise(resolve => { 28 | const { wsInterface, wsPort } = { 29 | wsInterface: '127.0.0.1', 30 | wsPort: '8546', 31 | ...options 32 | }; 33 | 34 | /** 35 | * Try to ping these hosts to test if Parity is running. 36 | */ 37 | const hostsToPing = [ 38 | 'http://127.0.0.1:8545', 39 | 'http://127.0.0.1:8546', 40 | `http://${wsInterface}:${wsPort}` 41 | ]; 42 | 43 | setTimeout(() => resolve(false), TIMEOUT_MS); 44 | 45 | hostsToPing.map(host => 46 | axios 47 | .get(host) 48 | .then(_ => { 49 | logger()('@parity/electron:main')( 50 | `Another instance of parity is already running on ${host}, skip running local instance.` 51 | ); 52 | resolve(true); 53 | }) 54 | .catch(() => { 55 | return null; 56 | }) 57 | ); 58 | }); 59 | } 60 | -------------------------------------------------------------------------------- /packages/electron/src/types.d.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | export type LoggerFunction = (namespace: string) => (log: string) => void; 7 | -------------------------------------------------------------------------------- /packages/electron/src/utils/logCommand.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import logCommand from './logCommand'; 7 | 8 | test('should correctly log a command', () => { 9 | expect(logCommand('foo', ['-a', '23'])).toBe('Running "foo -a 23".'); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/electron/src/utils/logCommand.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | /** 7 | * Given a command and its args, returns a nice string to be logged. The 8 | * arguments to this function are the same as the ones you would pass to spawn. 9 | * 10 | * @ignore 11 | */ 12 | const logCommand = (command: string, args: string[]) => 13 | `Running "${command.replace(' ', '\\ ')} ${args.join(' ')}".`; 14 | 15 | export default logCommand; 16 | -------------------------------------------------------------------------------- /packages/electron/src/utils/logger.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import getLogger, { setLogger } from './logger'; 7 | 8 | test('should correctly set logger', () => { 9 | const logger = () => () => { 10 | /* Do nothing. */ 11 | }; 12 | setLogger(logger); 13 | expect(getLogger()).toBe(logger); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/electron/src/utils/logger.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import * as debug from 'debug'; 7 | 8 | import { LoggerFunction } from '../types'; 9 | 10 | /** 11 | * @ignore 12 | */ 13 | let logger: LoggerFunction = debug; 14 | 15 | /** 16 | * @ignore 17 | */ 18 | export const setLogger = (_logger: LoggerFunction) => { 19 | logger = _logger; 20 | }; 21 | 22 | export default () => logger; 23 | -------------------------------------------------------------------------------- /packages/electron/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./lib" 4 | }, 5 | "extends": "../../tsconfig.json", 6 | "include": ["./src"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/electron/typedoc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entryPoint: 'docs', 3 | exclude: ['**/*spec.ts'], 4 | excludeExternals: true, 5 | excludePrivate: true, 6 | hideGenerator: true, 7 | includes: './src', 8 | out: 'docs', 9 | mode: 'file', 10 | module: 'commonjs', 11 | stripInternal: 'true', 12 | theme: 'markdown' 13 | }; 14 | -------------------------------------------------------------------------------- /packages/light.js-react/.npmignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | 4 | # testing 5 | coverage 6 | 7 | # logs 8 | *.log* 9 | 10 | # os-generated files 11 | .DS_Store 12 | -------------------------------------------------------------------------------- /packages/light.js-react/README.md: -------------------------------------------------------------------------------- 1 | # @parity/light.js-react 2 | 3 | A HOC to easily use [@parity/light.js](https://github.com/paritytech/js-libs/packages/light.js) with React. 4 | 5 | [![Build Status](https://travis-ci.org/paritytech/js-libs.svg?branch=master)](https://travis-ci.org/paritytech/js-libs) 6 | [![npm (scoped)](https://img.shields.io/npm/v/@parity/light.js-react.svg)](https://www.npmjs.com/package/@parity/light.js-react) 7 | [![npm](https://img.shields.io/npm/dw/@parity/light.js-react.svg)](https://www.npmjs.com/package/@parity/light.js-react) 8 | [![dependencies Status](https://david-dm.org/paritytech/js-libs/status.svg?path=packages/light.js-react)](https://david-dm.org/paritytech/js-libs?path=packages/light.js-react) 9 | 10 | ## Usage 11 | 12 | The libray provides a higher-order component (HOC) to use `@parity/light.js`'s Observables easily with React apps. 13 | 14 | ```javascript 15 | import light from '@parity/light.js-react'; 16 | import { myBalance$, syncStatus$ } from '@parity/light.js'; 17 | 18 | @light({ 19 | myBalance: myBalance$, // myBalance will be a BigNumber 20 | mySyncVariable: syncStatus$ 21 | }) 22 | class MyClass extends React.Component { 23 | render() { 24 | return ( 25 |
26 | My balance is {this.props.myBalance.toFormat()}.
27 | The sync status is {JSON.stringify(this.props.mySyncVariable)}. 28 |
29 | ); 30 | } 31 | } 32 | ``` 33 | 34 | The UI will automatically update when the sync status changes. 35 | -------------------------------------------------------------------------------- /packages/light.js-react/jest.config.js: -------------------------------------------------------------------------------- 1 | const baseConfig = require('../../jest.config'); 2 | 3 | module.exports = { 4 | ...baseConfig, 5 | setupTestFrameworkScriptFile: '../../node_modules/jest-enzyme/lib/index.js' 6 | }; 7 | -------------------------------------------------------------------------------- /packages/light.js-react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@parity/light.js-react", 3 | "description": "A HOC to easily use @parity/light.js with React.", 4 | "version": "5.1.19", 5 | "author": "Parity Team ", 6 | "license": "MIT", 7 | "repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js-react", 8 | "main": "lib/index.js", 9 | "keywords": [ 10 | "API", 11 | "Ethereum", 12 | "Light", 13 | "Light Client", 14 | "Observable", 15 | "Parity", 16 | "Reactive", 17 | "RxJS", 18 | "React" 19 | ], 20 | "publishConfig": { 21 | "access": "public" 22 | }, 23 | "scripts": { 24 | "prebuild": "rimraf lib", 25 | "typecheck": "tsc --noEmit", 26 | "build": "tsc", 27 | "test": "jest" 28 | }, 29 | "dependencies": { 30 | "recompose": "^0.30.0", 31 | "symbol-observable": "^1.2.0" 32 | }, 33 | "devDependencies": { 34 | "@parity/light.js": "^5.1.19", 35 | "@types/enzyme": "^3.1.13", 36 | "@types/enzyme-adapter-react-16": "^1.0.3", 37 | "@types/recompose": "^0.30.2", 38 | "enzyme": "^3.4.2", 39 | "enzyme-adapter-react-16": "^1.2.0", 40 | "jest-enzyme": "^7.0.1", 41 | "react": "^16.4.2", 42 | "react-dom": "^16.4.2", 43 | "typescript": "^3.1.6" 44 | }, 45 | "peerDependencies": { 46 | "@parity/light.js": "^5.1.1", 47 | "rxjs": "~6.2.2" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/light.js-react/src/ambient.d.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | declare module '@parity/abi'; 7 | declare module '@parity/abi/lib/spec/function'; 8 | declare module '@parity/api'; 9 | declare module '@parity/api/lib/util'; 10 | declare module '@parity/api/lib/util/encode'; 11 | declare module '@parity/api/lib/util/types'; 12 | -------------------------------------------------------------------------------- /packages/light.js-react/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "jsx": "react", 4 | "outDir": "./lib" 5 | }, 6 | "extends": "../../tsconfig.json", 7 | "include": ["./src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/light.js/.npmignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | node_modules 3 | 4 | # testing 5 | coverage 6 | 7 | # logs 8 | *.log* 9 | 10 | # os-generated files 11 | .DS_Store 12 | 13 | # examples 14 | example 15 | -------------------------------------------------------------------------------- /packages/light.js/docs/README.md: -------------------------------------------------------------------------------- 1 | # @parity/light.js 2 | 3 | A high-level reactive JS library optimized for light clients. 4 | 5 | [![Build Status](https://travis-ci.org/paritytech/js-libs.svg?branch=master)](https://travis-ci.org/paritytech/js-libs) 6 | [![npm (scoped)](https://img.shields.io/npm/v/@parity/light.js.svg)](https://www.npmjs.com/package/@parity/light.js) 7 | [![npm](https://img.shields.io/npm/dw/@parity/light.js.svg)](https://www.npmjs.com/package/@parity/light.js) 8 | [![dependencies Status](https://david-dm.org/paritytech/js-libs/status.svg?path=packages/light.js)](https://david-dm.org/paritytech/js-libs?path=packages/light.js) 9 | [![docs](https://img.shields.io/badge/docs-passing-green.svg)](https://parity-js.github.io/light.js/) 10 | 11 | Github: https://github.com/paritytech/js-libs/tree/master/packages/light.js 12 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_rpc_other_makecontract_.makecontract.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **MakeContract** 6 | 7 | # Indexable 8 | 9 | \[index: `string`\]: `any` \| `string` \| `function` 10 | # Properties 11 | 12 | 13 | 14 | ## abi 15 | 16 | **● abi**: *`any`* 17 | 18 | *Defined in [rpc/other/makeContract.ts:18](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/other/makeContract.ts#L18)* 19 | 20 | ___ 21 | 22 | 23 | ## address 24 | 25 | **● address**: *`string`* 26 | 27 | *Defined in [rpc/other/makeContract.ts:19](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/other/makeContract.ts#L19)* 28 | 29 | ___ 30 | 31 | 32 | ## contractObject 33 | 34 | **● contractObject**: *`any`* 35 | 36 | *Defined in [rpc/other/makeContract.ts:20](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/other/makeContract.ts#L20)* 37 | 38 | ___ 39 | 40 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_rpc_other_post_.postoptions.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | [RpcObservableOptions](_types_.rpcobservableoptions.md) 6 | 7 | **↳ PostOptions** 8 | 9 | # Properties 10 | 11 | 12 | 13 | ## `` estimate 14 | 15 | **● estimate**: *`undefined` \| `false` \| `true`* 16 | 17 | *Defined in [rpc/other/post.ts:14](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/other/post.ts#L14)* 18 | 19 | ___ 20 | 21 | 22 | ## passphrase 23 | 24 | **● passphrase**: *`string`* 25 | 26 | *Defined in [rpc/other/post.ts:15](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/other/post.ts#L15)* 27 | 28 | ___ 29 | 30 | 31 | ## `` provider 32 | 33 | **● provider**: *`any`* 34 | 35 | *Inherited from [RpcObservableOptions](_types_.rpcobservableoptions.md).[provider](_types_.rpcobservableoptions.md#provider)* 36 | 37 | *Defined in [types.ts:77](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L77)* 38 | 39 | ___ 40 | 41 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_types_.__global.window.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **Window** 6 | 7 | # Properties 8 | 9 | 10 | 11 | ## parity 12 | 13 | **● parity**: *`any`* 14 | 15 | *Defined in [types.ts:14](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L14)* 16 | 17 | ___ 18 | 19 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_types_.frequencyobservable.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Type parameters 4 | #### T 5 | # Hierarchy 6 | 7 | **FrequencyObservable** 8 | 9 | # Callable 10 | ▸ **__call**(options?: *[FrequencyObservableOptions](_types_.frequencyobservableoptions.md)*): `Observable`<`T`> 11 | 12 | *Defined in [types.ts:51](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L51)* 13 | 14 | **Parameters:** 15 | 16 | | Name | Type | 17 | | ------ | ------ | 18 | | `Optional` options | [FrequencyObservableOptions](_types_.frequencyobservableoptions.md) | 19 | 20 | **Returns:** `Observable`<`T`> 21 | 22 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_types_.frequencyobservableoptions.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **FrequencyObservableOptions** 6 | 7 | # Properties 8 | 9 | 10 | 11 | ## `` provider 12 | 13 | **● provider**: *`any`* 14 | 15 | *Defined in [types.ts:48](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L48)* 16 | 17 | ___ 18 | 19 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_types_.makecontract.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **MakeContract** 6 | 7 | # Indexable 8 | 9 | \[index: `string`\]: `any` \| `string` \| `function` 10 | # Properties 11 | 12 | 13 | 14 | ## abi 15 | 16 | **● abi**: *`any`* 17 | 18 | *Defined in [types.ts:60](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L60)* 19 | 20 | ___ 21 | 22 | 23 | ## address 24 | 25 | **● address**: *`string`* 26 | 27 | *Defined in [types.ts:61](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L61)* 28 | 29 | ___ 30 | 31 | 32 | ## contractObject 33 | 34 | **● contractObject**: *`any`* 35 | 36 | *Defined in [types.ts:62](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L62)* 37 | 38 | ___ 39 | 40 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_types_.rpcobservable.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Type parameters 4 | #### Source 5 | #### Out 6 | # Hierarchy 7 | 8 | **RpcObservable** 9 | 10 | # Callable 11 | ▸ **__call**(...args: *`any`[]*): `Observable`<`Out`> 12 | 13 | *Defined in [types.ts:68](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L68)* 14 | 15 | **Parameters:** 16 | 17 | | Name | Type | 18 | | ------ | ------ | 19 | | `Rest` args | `any`[] | 20 | 21 | **Returns:** `Observable`<`Out`> 22 | 23 | # Properties 24 | 25 | 26 | 27 | ## `` metadata 28 | 29 | **● metadata**: *[Metadata](_types_.metadata.md)<`Source`, `Out`>* 30 | 31 | *Defined in [types.ts:70](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L70)* 32 | 33 | ___ 34 | 35 | # Methods 36 | 37 | 38 | 39 | ## `` setFrequency 40 | 41 | ▸ **setFrequency**(frequency: *[FrequencyObservable](_types_.frequencyobservable.md)<`Source`>[]*): `void` 42 | 43 | *Defined in [types.ts:71](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L71)* 44 | 45 | **Parameters:** 46 | 47 | | Name | Type | 48 | | ------ | ------ | 49 | | frequency | [FrequencyObservable](_types_.frequencyobservable.md)<`Source`>[] | 50 | 51 | **Returns:** `void` 52 | 53 | ___ 54 | 55 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_types_.rpcobservableoptions.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **RpcObservableOptions** 6 | 7 | ↳ [PostOptions](_rpc_other_post_.postoptions.md) 8 | 9 | # Properties 10 | 11 | 12 | 13 | ## `` provider 14 | 15 | **● provider**: *`any`* 16 | 17 | *Defined in [types.ts:77](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L77)* 18 | 19 | ___ 20 | 21 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_types_.txstatus.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **TxStatus** 6 | 7 | # Properties 8 | 9 | 10 | 11 | ## `` confirmed 12 | 13 | **● confirmed**: *`any`* 14 | 15 | *Defined in [types.ts:88](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L88)* 16 | 17 | ___ 18 | 19 | 20 | ## `` estimated 21 | 22 | **● estimated**: *`BigNumber`* 23 | 24 | *Defined in [types.ts:90](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L90)* 25 | 26 | ___ 27 | 28 | 29 | ## `` estimating 30 | 31 | **● estimating**: *`undefined` \| `false` \| `true`* 32 | 33 | *Defined in [types.ts:89](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L89)* 34 | 35 | ___ 36 | 37 | 38 | ## `` failed 39 | 40 | **● failed**: *`Error`* 41 | 42 | *Defined in [types.ts:91](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L91)* 43 | 44 | ___ 45 | 46 | 47 | ## `` sent 48 | 49 | **● sent**: *`undefined` \| `string`* 50 | 51 | *Defined in [types.ts:93](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L93)* 52 | 53 | ___ 54 | 55 | 56 | ## `` signed 57 | 58 | **● signed**: *`undefined` \| `string`* 59 | 60 | *Defined in [types.ts:92](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/types.ts#L92)* 61 | 62 | ___ 63 | 64 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/interfaces/_utils_operators_switchmappromise_.switchmappromiseoptions.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Hierarchy 4 | 5 | **SwitchMapPromiseOptions** 6 | 7 | # Properties 8 | 9 | 10 | 11 | ## emitErrors 12 | 13 | **● emitErrors**: *`boolean`* 14 | 15 | *Defined in [utils/operators/switchMapPromise.ts:10](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/utils/operators/switchMapPromise.ts#L10)* 16 | 17 | ___ 18 | 19 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_frequency_accounts_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Functions 4 | 5 | 6 | 7 | ## onAccountsChanged$ 8 | 9 | ▸ **onAccountsChanged$**(options?: *[FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md)*): `Observable`<`string`[]> 10 | 11 | *Defined in [frequency/accounts.ts:14](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/frequency/accounts.ts#L14)* 12 | 13 | Observable that emits each time the default account changes 14 | 15 | **Parameters:** 16 | 17 | | Name | Type | Description | 18 | | ------ | ------ | ------ | 19 | | `Optional` options | [FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md) | Options to pass to [FrequencyObservable](../interfaces/_types_.frequencyobservable.md). | 20 | 21 | **Returns:** `Observable`<`string`[]> 22 | 23 | ___ 24 | 25 | 26 | ## onAccountsInfoChanged$ 27 | 28 | ▸ **onAccountsInfoChanged$**(options?: *[FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md)*): `Observable`<`object`> 29 | 30 | *Defined in [frequency/accounts.ts:27](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/frequency/accounts.ts#L27)* 31 | 32 | Observable that emits each time the default account changes 33 | 34 | **Parameters:** 35 | 36 | | Name | Type | Description | 37 | | ------ | ------ | ------ | 38 | | `Optional` options | [FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md) | Options to pass to [FrequencyObservable](../interfaces/_types_.frequencyobservable.md). | 39 | 40 | **Returns:** `Observable`<`object`> 41 | 42 | ___ 43 | 44 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_frequency_blocks_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Functions 4 | 5 | 6 | 7 | ## onEveryBlock$ 8 | 9 | ▸ **onEveryBlock$**(options?: *[FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md)*): `Observable`<`object`> 10 | 11 | *Defined in [frequency/blocks.ts:42](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/frequency/blocks.ts#L42)* 12 | 13 | Observable that emits on every new block. Note: this FrequencyObservable won't fire when the light client is syncing. 14 | 15 | **Parameters:** 16 | 17 | | Name | Type | Description | 18 | | ------ | ------ | ------ | 19 | | `Optional` options | [FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md) | Options to pass to [FrequencyObservable](../interfaces/_types_.frequencyobservable.md). | 20 | 21 | **Returns:** `Observable`<`object`> 22 | 23 | ___ 24 | 25 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_frequency_frequency_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Object literals 4 | 5 | 6 | 7 | ## `` frequency 8 | 9 | **frequency**: *`object`* 10 | 11 | *Defined in [frequency/frequency.ts:12](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/frequency/frequency.ts#L12)* 12 | 13 | ___ 14 | 15 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_frequency_health_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Functions 4 | 5 | 6 | 7 | ## onSyncingChanged$ 8 | 9 | ▸ **onSyncingChanged$**(options?: *[FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md)*): `Observable`<`false` \| `object`> 10 | 11 | *Defined in [frequency/health.ts:19](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/frequency/health.ts#L19)* 12 | 13 | Observable that emits when syncing status changes. 14 | 15 | **Parameters:** 16 | 17 | | Name | Type | Description | 18 | | ------ | ------ | ------ | 19 | | `Optional` options | [FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md) | Options to pass to [FrequencyObservable](../interfaces/_types_.frequencyobservable.md). | 20 | 21 | **Returns:** `Observable`<`false` \| `object`> 22 | 23 | ___ 24 | 25 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_frequency_other_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Functions 4 | 5 | 6 | 7 | ## onStartup$ 8 | 9 | ▸ **onStartup$**(options?: *[FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md)*): `Observable`<`number`> 10 | 11 | *Defined in [frequency/other.ts:18](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/frequency/other.ts#L18)* 12 | 13 | Observable that emits only once. 14 | 15 | **Parameters:** 16 | 17 | | Name | Type | Description | 18 | | ------ | ------ | ------ | 19 | | `Optional` options | [FrequencyObservableOptions](../interfaces/_types_.frequencyobservableoptions.md) | Options to pass to [FrequencyObservable](../interfaces/_types_.frequencyobservable.md). | 20 | 21 | **Returns:** `Observable`<`number`> 22 | 23 | ___ 24 | 25 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_frequency_utils_createpubsubobservable_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Variables 4 | 5 | 6 | 7 | ## `` POLL_INTERVAL 8 | 9 | **● POLL_INTERVAL**: *`1000`* = 1000 10 | 11 | *Defined in [frequency/utils/createPubsubObservable.ts:16](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/frequency/utils/createPubsubObservable.ts#L16)* 12 | 13 | ___ 14 | 15 | 16 | ## `` UNSUB_DELAY 17 | 18 | **● UNSUB_DELAY**: *`2000`* = 2000 19 | 20 | *Defined in [frequency/utils/createPubsubObservable.ts:19](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/frequency/utils/createPubsubObservable.ts#L19)* 21 | 22 | ___ 23 | 24 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_rpc_net_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Functions 4 | 5 | 6 | 7 | ## peerCount$ 8 | 9 | ▸ **peerCount$**(options?: *[RpcObservableOptions](../interfaces/_types_.rpcobservableoptions.md)*): `Observable`<`BigNumber`> 10 | 11 | *Defined in [rpc/net.ts:21](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/net.ts#L21)* 12 | 13 | Get the amount of peers. 14 | 15 | Calls `net_peerCount` 16 | 17 | **Parameters:** 18 | 19 | | Name | Type | Description | 20 | | ------ | ------ | ------ | 21 | | `Optional` options | [RpcObservableOptions](../interfaces/_types_.rpcobservableoptions.md) | Options to pass to [RpcObservableOptions](../interfaces/_types_.rpcobservableoptions.md). | 22 | 23 | **Returns:** `Observable`<`BigNumber`> 24 | * An Observable containing the number. 25 | 26 | ___ 27 | 28 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_rpc_other_makecontract_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Interfaces 6 | 7 | * [MakeContract](../interfaces/_rpc_other_makecontract_.makecontract.md) 8 | 9 | ### Functions 10 | 11 | * [makeContract](_rpc_other_makecontract_.md#makecontract-1) 12 | 13 | --- 14 | 15 | # Functions 16 | 17 | 18 | 19 | ## `` makeContract 20 | 21 | ▸ **makeContract**(address: *[Address](_types_.md#address)*, abiJson: *`any`[]*, options?: *`object`*): [MakeContract](../interfaces/_rpc_other_makecontract_.makecontract.md) 22 | 23 | *Defined in [rpc/other/makeContract.ts:124](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/other/makeContract.ts#L124)* 24 | 25 | Create a contract. 26 | 27 | **Parameters:** 28 | 29 | **address: [Address](_types_.md#address)** 30 | 31 | The contract address. 32 | 33 | **abiJson: `any`[]** 34 | 35 | The contract abi. 36 | 37 | **`Default value` options: `object`** 38 | 39 | The options to pass in when creating the contract. 40 | 41 | | Name | Type | 42 | | ------ | ------ | 43 | | `Optional` provider | `any` | 44 | 45 | **Returns:** [MakeContract](../interfaces/_rpc_other_makecontract_.makecontract.md) 46 | * An object whose keys are all the functions of the contract, and each function return an Observable which will fire when the function resolves. 47 | 48 | ___ 49 | 50 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_rpc_rpc_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Object literals 4 | 5 | 6 | 7 | ## `` rpc 8 | 9 | **rpc**: *`object`* 10 | 11 | *Defined in [rpc/rpc.ts:11](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/rpc.ts#L11)* 12 | 13 | 14 | 15 | ### post$ 16 | 17 | **● post$**: *[post$](_rpc_other_post_.md#post_)* 18 | 19 | *Defined in [rpc/rpc.ts:11](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/rpc.ts#L11)* 20 | 21 | ___ 22 | 23 | 24 | ### postRaw$ 25 | 26 | **● postRaw$**: *[postRaw$](_rpc_other_post_.md#postraw_)* 27 | 28 | *Defined in [rpc/rpc.ts:11](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/rpc.ts#L11)* 29 | 30 | ___ 31 | 32 | ___ 33 | 34 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_rpc_utils_createrpc_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Variables 4 | 5 | 6 | 7 | ## `` UNSUB_DELAY 8 | 9 | **● UNSUB_DELAY**: *`2000`* = 2000 10 | 11 | *Defined in [rpc/utils/createRpc.ts:20](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/rpc/utils/createRpc.ts#L20)* 12 | 13 | ___ 14 | 15 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_types_.__global.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Interfaces 6 | 7 | * [Window](../interfaces/_types_.__global.window.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_utils_isobservable_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_utils_operators_distinctreplayrefcountdelay_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Variables 4 | 5 | 6 | 7 | ## refCountDelay 8 | 9 | **● refCountDelay**: *`refCountDelay`* 10 | 11 | *Defined in [utils/operators/distinctReplayRefCountDelay.ts:12](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/utils/operators/distinctReplayRefCountDelay.ts#L12)* 12 | 13 | ___ 14 | 15 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_utils_operators_distinctvalues_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_utils_operators_switchmappromise_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Index 4 | 5 | ### Interfaces 6 | 7 | * [SwitchMapPromiseOptions](../interfaces/_utils_operators_switchmappromise_.switchmappromiseoptions.md) 8 | 9 | --- 10 | 11 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_utils_testhelpers_mockrpc_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Variables 4 | 5 | 6 | 7 | ## `` mockRpc$ 8 | 9 | **● mockRpc$**: *`(Anonymous function)`* = createRpc({ frequency: [() => timer(0, 1000)] })() 10 | 11 | *Defined in [utils/testHelpers/mockRpc.ts:18](https://github.com/paritytech/js-libs/blob/66e2091/packages/light.js/src/utils/testHelpers/mockRpc.ts#L18)* 12 | 13 | ___ 14 | 15 | -------------------------------------------------------------------------------- /packages/light.js/docs/api/modules/_utils_testhelpers_sleep_.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /packages/light.js/docs/getting-started/does-it-work-with-a-full-node.md: -------------------------------------------------------------------------------- 1 | # Does this work with a full node? 2 | 3 | Yes. Despite what its name would suggest. 4 | 5 | ## Building a dapp with a remote full node as the backend (MetaMask, INFURA) 6 | 7 | For most of the JSONRPC calls, a dapp needs to make wait for a network call to fetch the result, which may cause some latency in the response: 8 | 9 | - in the case of a remote full node: the dapp makes a JSONRPC call to the remote full node. 10 | - in the case of a Light Client: the Light Client asks its peers for the result. 11 | 12 | As such, the best development patterns which apply to Light Clients also apply to remote full nodes. Read the chapter on [Light Client Development](/concepts/light-client-development.html) to learn more. 13 | 14 | `@parity/light.js` is merely a library which regroups all these best development patterns in a simple API. 15 | -------------------------------------------------------------------------------- /packages/light.js/docs/guides/tutorial1-set-up-a-light-client.md: -------------------------------------------------------------------------------- 1 | # Tutorial Part 1: Set up a Light Client for Development 2 | 3 | At Parity Technologies, we believe that Light Clients will [play a big role](https://paritytech.io/what-is-a-light-client/) in the Ethereum network in the future. However, today, Light Clients are still mainly experimental. 4 | 5 | For development, there's no big risk in using a Light Client. If anything, it's a small step towards making the network more decentralized. 6 | 7 | ## Download the Light Client 8 | 9 | Please install Parity Ethereum first: https://parity.io. Then run Parity Ethereum with the following flags: 10 | 11 | ```bash 12 | /path/to/parity --chain kovan --light --ws-origins all 13 | ``` 14 | 15 | We are using the Kovan testnet so that we are not testing our dapp with real Ether. To get some fake Kovan ETH to play with, head to the faucet: https://faucet.kovan.network/. 16 | 17 | The Light Client should take a couple of minutes to sync. Head to [our wiki](https://wiki.parity.io/Light-Client) to learn more about the Light Client. 18 | -------------------------------------------------------------------------------- /packages/light.js/example-react/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /packages/light.js/example-react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example-react", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@parity/api": "../../api", 7 | "@parity/light.js": "../", 8 | "@parity/light.js-react": "../../light.js-react", 9 | "react": "^16.7.0", 10 | "react-dom": "^16.7.0", 11 | "react-router-dom": "^4.3.1", 12 | "react-scripts": "^3.3.0", 13 | "rxjs": "~6.2.2" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": "react-app" 23 | }, 24 | "browserslist": [ 25 | ">0.2%", 26 | "not dead", 27 | "not ie <= 11", 28 | "not op_mini all" 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /packages/light.js/example-react/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/openethereum/js-libs/f985750827c3d795710b00708aa1badedd76c88d/packages/light.js/example-react/public/favicon.ico -------------------------------------------------------------------------------- /packages/light.js/example-react/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/App.css: -------------------------------------------------------------------------------- 1 | /* Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | * This file is part of Parity. 3 | * 4 | * SPDX-License-Identifier: MIT */ 5 | 6 | .App { 7 | text-align: center; 8 | } 9 | 10 | .App-logo { 11 | animation: App-logo-spin infinite 20s linear; 12 | height: 80px; 13 | } 14 | 15 | .App-header { 16 | background-color: #222; 17 | height: 150px; 18 | padding: 20px; 19 | color: white; 20 | text-align: center; 21 | } 22 | 23 | .App-link { 24 | color: #61dafb; 25 | } 26 | 27 | @keyframes App-logo-spin { 28 | from { 29 | transform: rotate(0deg); 30 | } 31 | to { 32 | transform: rotate(360deg); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/BalanceOf/BalanceOfAddress/BalanceOfAddress.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import React, { Component } from 'react'; 7 | import { map } from 'rxjs/operators'; 8 | import { balanceOf$ } from '@parity/light.js'; 9 | import light from '@parity/light.js-react'; 10 | 11 | // NOTE: with the right Babel configuration (or TypeScript), 12 | // you can use use `light` as a decorator: 13 | // @light({ 14 | // balance: ownProps => 15 | // balanceOf$(ownProps.address).pipe( 16 | // map(_ => +_) 17 | // ) 18 | // }) 19 | class BalanceOfAddress extends Component { 20 | render() { 21 | const { address, balance } = this.props; 22 | return ( 23 |

24 | Balance of {address}: {balance} wei. 25 |

26 | ); 27 | } 28 | } 29 | 30 | BalanceOfAddress = light({ 31 | balance: ownProps => 32 | balanceOf$(ownProps.address).pipe( 33 | map(_ => +_) 34 | ) 35 | })(BalanceOfAddress); 36 | 37 | export default BalanceOfAddress; 38 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/BalanceOf/BalanceOfAddress/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import BalanceOfAddress from './BalanceOfAddress'; 7 | 8 | export default BalanceOfAddress; 9 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/BalanceOf/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Balance from './Balance'; 7 | 8 | export default Balance; 9 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/BlockNumber/BlockNumber.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import React, { Component } from 'react'; 7 | import { blockNumber$ } from '@parity/light.js'; 8 | import light from '@parity/light.js-react'; 9 | 10 | // NOTE: with the right Babel configuration (or TypeScript), 11 | // you can use use `light` as a decorator: 12 | // @light({ 13 | // blockNumber: blockNumber$ 14 | // }) 15 | class BlockNumber extends Component { 16 | render() { 17 | const { blockNumber } = this.props; 18 | 19 | return ( 20 |
21 |

blockNumber$

22 | 23 |

Current block number

24 | {+blockNumber} 25 |
26 | ); 27 | } 28 | } 29 | 30 | BlockNumber = light({ 31 | blockNumber: blockNumber$ 32 | })(BlockNumber); 33 | 34 | export default BlockNumber; 35 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/BlockNumber/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import BlockNumber from './BlockNumber'; 7 | 8 | export default BlockNumber; 9 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/PeerCount/PeerCount.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import React, { Component } from 'react'; 7 | import { peerCount$ } from '@parity/light.js'; 8 | import light from '@parity/light.js-react'; 9 | 10 | // NOTE: with the right Babel configuration (or TypeScript), 11 | // you can use use `light` as a decorator: 12 | // @light({ 13 | // peerCount: peerCount$ 14 | // }) 15 | class PeerCount extends Component { 16 | render() { 17 | const { peerCount } = this.props; 18 | 19 | return ( 20 |
21 |

peerCount$

22 | 23 |

Current peer count

24 | {+peerCount} 25 |
26 | ); 27 | } 28 | } 29 | 30 | PeerCount = light({ 31 | peerCount: peerCount$ 32 | })(PeerCount); 33 | 34 | export default PeerCount; 35 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/PeerCount/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import PeerCount from './PeerCount'; 7 | 8 | export default PeerCount; 9 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/index.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import 'symbol-observable'; // TODO Remove this once https://github.com/acdlite/recompose/pull/660 is merged 7 | 8 | import React from 'react'; 9 | import ReactDOM from 'react-dom'; 10 | import light from '@parity/light.js'; 11 | 12 | import './index.css'; 13 | import App from './App'; 14 | import provider from './provider'; 15 | 16 | import * as serviceWorker from './serviceWorker'; 17 | 18 | light.setProvider(provider); 19 | 20 | 21 | ReactDOM.render(, document.getElementById('root')); 22 | 23 | // If you want your app to work offline and load faster, you can change 24 | // unregister() to register() below. Note this comes with some pitfalls. 25 | // Learn more about service workers: http://bit.ly/CRA-PWA 26 | serviceWorker.unregister(); 27 | -------------------------------------------------------------------------------- /packages/light.js/example-react/src/provider.js: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import Api from '@parity/api'; 7 | 8 | export const currentProvider = window.web3 && window.web3.currentProvider; 9 | export const localProvider = new Api.Provider.Ws('ws://127.0.0.1:8546'); 10 | export const infuraProvider = new Api.Provider.Ws( 11 | 'wss://mainnet.infura.io/_ws' 12 | ); 13 | 14 | const provider = currentProvider || localProvider; 15 | 16 | export default provider; 17 | -------------------------------------------------------------------------------- /packages/light.js/jest.config.js: -------------------------------------------------------------------------------- 1 | const baseConfig = require('../../jest.config'); 2 | 3 | module.exports = baseConfig; 4 | -------------------------------------------------------------------------------- /packages/light.js/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@parity/light.js", 3 | "description": "A high-level reactive JS library optimized for light clients", 4 | "version": "5.1.19", 5 | "author": "Parity Team ", 6 | "license": "MIT", 7 | "repository": "https://github.com/paritytech/js-libs/tree/master/packages/light.js", 8 | "main": "lib/index.js", 9 | "keywords": [ 10 | "API", 11 | "Ethereum", 12 | "Light", 13 | "Light Client", 14 | "Observable", 15 | "Parity", 16 | "Reactive", 17 | "RxJS" 18 | ], 19 | "publishConfig": { 20 | "access": "public" 21 | }, 22 | "scripts": { 23 | "docs": "typedoc", 24 | "prebuild": "rimraf lib", 25 | "typecheck": "tsc --noEmit", 26 | "build": "tsc", 27 | "test": "jest --runInBand" 28 | }, 29 | "dependencies": { 30 | "@parity/abi": "^5.1.19", 31 | "@parity/api": "^5.1.19", 32 | "async-retry": "^1.2.3", 33 | "bignumber.js": "^8.0.1", 34 | "debug": "^4.1.0", 35 | "memoizee": "^0.4.12", 36 | "rxjs-etc": "^9.4.0" 37 | }, 38 | "devDependencies": { 39 | "@types/debug": "^4.1.0", 40 | "@types/memoizee": "^0.4.2", 41 | "eventemitter3": "^3.1.0", 42 | "rxjs": "~6.2.2", 43 | "typescript": "^3.1.6" 44 | }, 45 | "peerDependencies": { 46 | "rxjs": "~6.2.2" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/light.js/src/ambient.d.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | declare module '@parity/api'; 7 | declare module '@parity/api/lib/util'; 8 | declare module '@parity/api/lib/util/encode'; 9 | declare module '@parity/api/lib/util/types'; 10 | -------------------------------------------------------------------------------- /packages/light.js/src/api.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import * as Api from '@parity/api'; 7 | 8 | import { getApi, setApi, setProvider } from './api'; 9 | import { resolveApi } from './utils/testHelpers/mockApi'; 10 | 11 | it('should return the Null provider', () => { 12 | expect(getApi).toThrow(); 13 | }); 14 | 15 | it('should correctly set a new api', () => { 16 | const api = resolveApi(); 17 | setApi(api); 18 | expect(getApi()).toBe(api); 19 | }); 20 | 21 | it('should correctly set a new provider', () => { 22 | const provider = new Api.Provider.Ws('ws://127.0.0.1:8546'); 23 | setProvider(provider); 24 | expect(getApi().provider).toBe(provider); 25 | }); 26 | -------------------------------------------------------------------------------- /packages/light.js/src/api.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import * as Api from '@parity/api'; 7 | import * as memoizee from 'memoizee'; 8 | 9 | // This is our global api object, to be used if no provider is passed to RpcObservables. 10 | let api: any; // TODO @parity/api 11 | 12 | /** 13 | * Like `return new Api(provider);`, but memoized. 14 | * 15 | * @ignore 16 | */ 17 | export const createApiFromProvider = memoizee( 18 | (provider?: any) => new Api(provider) 19 | ); 20 | 21 | /** 22 | * Sets a new Api object. 23 | * 24 | * @param newApi - An Api object. 25 | */ 26 | export const setApi = (newApi: any) => { 27 | api = newApi; 28 | }; 29 | 30 | /** 31 | * Sets a new Ethereum provider object. 32 | * 33 | * @param provider - An Ethereum provider object. 34 | */ 35 | export const setProvider = (provider?: any) => { 36 | setApi(createApiFromProvider(provider)); 37 | }; 38 | 39 | /** 40 | * We only ever use api() at call-time of functions; this allows the options 41 | * (particularly the transport option) to be changed dynamically and the 42 | * data structure to be reused. 43 | * 44 | * @return - The current Api object. 45 | */ 46 | export const getApi = () => { 47 | if (!api) { 48 | throw new Error('Please define a provider before using any RpcObservable.'); 49 | } 50 | return api; 51 | }; 52 | 53 | export default getApi; 54 | -------------------------------------------------------------------------------- /packages/light.js/src/frequency/accounts.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { AccountsInfo, Address, FrequencyObservableOptions } from '../types'; 7 | import createPubsubObservable from './utils/createPubsubObservable'; 8 | 9 | /** 10 | * Observable that emits each time the default account changes 11 | * 12 | * @param options - Options to pass to {@link FrequencyObservable}. 13 | */ 14 | export function onAccountsChanged$ (options?: FrequencyObservableOptions) { 15 | return createPubsubObservable( 16 | 'eth_accounts', 17 | 'eth_accounts', 18 | options 19 | ); 20 | } 21 | 22 | /** 23 | * Observable that emits each time the default account changes 24 | * 25 | * @param options - Options to pass to {@link FrequencyObservable}. 26 | */ 27 | export function onAccountsInfoChanged$ (options?: FrequencyObservableOptions) { 28 | return createPubsubObservable( 29 | 'parity_accountsInfo', 30 | 'parity_accountsInfo', 31 | options 32 | ); 33 | } 34 | -------------------------------------------------------------------------------- /packages/light.js/src/frequency/frequency.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import * as accounts from './accounts'; 7 | import * as blocks from './blocks'; 8 | import * as health from './health'; 9 | import * as other from './other'; 10 | import * as time from './time'; 11 | 12 | const frequency = { 13 | ...accounts, 14 | ...blocks, 15 | ...health, 16 | ...other, 17 | ...time 18 | }; 19 | 20 | export default frequency; 21 | -------------------------------------------------------------------------------- /packages/light.js/src/frequency/health.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import createPubsubObservable from './utils/createPubsubObservable'; 7 | import { FrequencyObservableOptions } from '../types'; 8 | 9 | /** 10 | * Observable that emits when syncing status changes. 11 | */ 12 | // TODO Pubsub doesn't exist on `net_peerCount` 13 | 14 | /** 15 | * Observable that emits when syncing status changes. 16 | * 17 | * @param options - Options to pass to {@link FrequencyObservable}. 18 | */ 19 | export function onSyncingChanged$ (options?: FrequencyObservableOptions) { 20 | return createPubsubObservable( 21 | 'eth_syncing', 22 | 'eth_syncing', 23 | options 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /packages/light.js/src/frequency/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import frequency from './frequency'; 7 | 8 | export default frequency; 9 | -------------------------------------------------------------------------------- /packages/light.js/src/frequency/other.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | /* eslint-disable @typescript-eslint/no-unused-vars */ 7 | 8 | import { of } from 'rxjs'; 9 | import * as memoizee from 'memoizee'; 10 | 11 | import { FrequencyObservableOptions } from '../types'; 12 | 13 | /** 14 | * Observable that emits only once. 15 | * 16 | * @param options - Options to pass to {@link FrequencyObservable}. 17 | */ 18 | function onStartup$ (options?: FrequencyObservableOptions) { 19 | return of(0); 20 | } 21 | // @ts-ignore 22 | // eslint-disable-next-line no-func-assign 23 | onStartup$ = memoizee(onStartup$); 24 | 25 | export { onStartup$ }; 26 | -------------------------------------------------------------------------------- /packages/light.js/src/frequency/time.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | /* eslint-disable @typescript-eslint/no-unused-vars */ 7 | 8 | import { timer } from 'rxjs'; 9 | import * as memoizee from 'memoizee'; 10 | 11 | import { FrequencyObservableOptions } from '../types'; 12 | 13 | /** 14 | * Observable that emits on every second. 15 | */ 16 | function onEverySecond$ (options?: FrequencyObservableOptions) { 17 | return timer(0, 1000); 18 | } 19 | // @ts-ignore 20 | // eslint-disable-next-line no-func-assign 21 | onEverySecond$ = memoizee(onEverySecond$); 22 | 23 | /** 24 | * Observable that emits on every other second. 25 | */ 26 | function onEvery2Seconds$ (options?: FrequencyObservableOptions) { 27 | return timer(0, 2000); 28 | } 29 | // @ts-ignore 30 | // eslint-disable-next-line no-func-assign 31 | onEvery2Seconds$ = memoizee(onEvery2Seconds$); 32 | 33 | /** 34 | * Observable that emits every five seconds. 35 | */ 36 | function onEvery5Seconds$ (options?: FrequencyObservableOptions) { 37 | return timer(0, 5000); 38 | } 39 | // @ts-ignore 40 | // eslint-disable-next-line no-func-assign 41 | onEvery5Seconds$ = memoizee(onEvery5Seconds$); 42 | 43 | export { onEverySecond$, onEvery2Seconds$, onEvery5Seconds$ }; 44 | -------------------------------------------------------------------------------- /packages/light.js/src/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { setApi, setProvider } from './api'; 7 | import frequency from './frequency'; 8 | import { makeContract } from './rpc/other/makeContract'; 9 | import rpc from './rpc'; 10 | 11 | export * from './types'; 12 | 13 | export { frequency, makeContract }; // makeContract is a bit special, because it's not a RpcObservable 14 | export const { 15 | accounts$, 16 | accountsInfo$, 17 | balanceOf$, 18 | chainId$, 19 | transactionCountOf$, 20 | blockNumber$, 21 | chainName$, 22 | defaultAccount$, 23 | myBalance$, 24 | peerCount$, 25 | post$, 26 | postRaw$, 27 | syncStatus$, 28 | versionInfo$ 29 | } = rpc; 30 | export default { setApi, setProvider }; 31 | -------------------------------------------------------------------------------- /packages/light.js/src/rpc/README.md: -------------------------------------------------------------------------------- 1 | # `rpc/` folder 2 | 3 | This folder hosts all the (RPC Observables)[https://github.com/paritytech/js-libs/blob/master/packages/light.js/src/types.d.ts#L38] that are exposed by `@parity/light.js`. 4 | 5 | ## Folder structure 6 | 7 | The `eth/`, `net/`, `parity/` folders contain all RPC Observables whose underlying API calls start respectively with `eth_`, `net_` and `parity_`. 8 | 9 | The `other` folder contains RPC Observables that are complex (like `post$`) or objects containing RPC Observables (like `makeContract$`). 10 | 11 | The `utils` folder contains utility functions used in the `rpc/` folder. 12 | -------------------------------------------------------------------------------- /packages/light.js/src/rpc/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import rpc from './rpc'; 7 | 8 | export default rpc; 9 | -------------------------------------------------------------------------------- /packages/light.js/src/rpc/net.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import BigNumber from 'bignumber.js'; 7 | 8 | import createRpc$ from './utils/createRpc'; 9 | import frequency from '../frequency'; 10 | import { RpcObservableOptions } from '../types'; 11 | import { switchMapPromise } from '../utils/operators'; 12 | 13 | /** 14 | * Get the amount of peers. 15 | * 16 | * Calls `net_peerCount` 17 | * 18 | * @param options - Options to pass to {@link RpcObservableOptions}. 19 | * @return - An Observable containing the number. 20 | */ 21 | export function peerCount$ (options?: RpcObservableOptions) { 22 | return createRpc$({ 23 | calls: ['net_peerCount'], 24 | frequency: [frequency.onEvery5Seconds$], 25 | name: 'peerCount$', 26 | pipes: api => [switchMapPromise(() => api.net.peerCount())] 27 | })(options)(); 28 | } 29 | -------------------------------------------------------------------------------- /packages/light.js/src/rpc/other/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | export * from './makeContract'; 7 | export * from './post'; 8 | -------------------------------------------------------------------------------- /packages/light.js/src/rpc/rpc.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import * as eth from './eth'; 7 | import * as net from './net'; 8 | import { post$, postRaw$ } from './other'; 9 | import * as parity from './parity'; 10 | 11 | const rpc = { ...eth, ...net, ...parity, post$, postRaw$ }; 12 | 13 | export default rpc; 14 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | // Export for the user all utils in @parity/api 7 | export * from '@parity/api/lib/util'; 8 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/isObservable.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { of } from 'rxjs'; 7 | 8 | import isObservable from './isObservable'; 9 | 10 | /** 11 | * Helper function to test isObservable. 12 | * 13 | * @param {String} name - A friendly name to show what we are testing. 14 | * @param {Any} input - The input to the isObservable function. 15 | * @param {Boolean} expected - The expected output. 16 | */ 17 | const testIsObservable = (name: string, input: any, expected: boolean) => { 18 | it(`should return ${expected} for a ${name}`, () => { 19 | expect(isObservable(input)).toBe(expected); 20 | }); 21 | }; 22 | 23 | testIsObservable('Observable', of(1), true); 24 | testIsObservable('function', (): any => null, false); 25 | testIsObservable('object', {}, false); 26 | testIsObservable('null', null, false); 27 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/isObservable.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { Observable } from 'rxjs'; 7 | 8 | /** 9 | * @ignore 10 | * @param {Any} source$ - The Observable to test. 11 | * @return {Boolean} - Returns true if it's an Observable. 12 | */ 13 | const isObservable = (source$: Observable): source$ is Observable => 14 | source$ instanceof Observable; 15 | 16 | export default isObservable; 17 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/operators/distinctReplayRefCountDelay.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { distinctReplayRefCountDelay } from './distinctReplayRefCountDelay'; 7 | import isObservable from '../isObservable'; 8 | import mockRpc$ from '../testHelpers/mockRpc'; 9 | 10 | it('should return an Observable', () => { 11 | expect(isObservable(mockRpc$().pipe(distinctReplayRefCountDelay(2000)))).toBe( 12 | true 13 | ); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/operators/distinctReplayRefCountDelay.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { publishReplay } from 'rxjs/operators'; 7 | import { Observable } from 'rxjs'; 8 | import { operators } from 'rxjs-etc'; 9 | 10 | import { distinctValues } from './distinctValues'; 11 | 12 | const { refCountDelay } = operators; 13 | 14 | /** 15 | * Shorthand for distinctUntilChanged(), publishReplay(1) and refCountDelay(). 16 | * 17 | * @ignore 18 | */ 19 | export const distinctReplayRefCountDelay = (delay: number) => ( 20 | source$: Observable 21 | ): Observable => 22 | source$.pipe( 23 | distinctValues(), 24 | 25 | // Note: uses a single subject, so the previous value might come from a 26 | // previous dropped subscription to the source observable 27 | publishReplay(1), 28 | 29 | // Unsubscribe to the source observable only after 2 seconds with no subscribers 30 | refCountDelay(delay) 31 | ); 32 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/operators/distinctValues.spec.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import BigNumber from 'bignumber.js'; 7 | import { of } from 'rxjs'; 8 | import { finalize, mapTo } from 'rxjs/operators'; 9 | 10 | import { distinctValues } from './distinctValues'; 11 | 12 | // Observable that fires twice 13 | const fireTwice$ = () => of(0, 1); 14 | 15 | it('should fire twice if values are different', done => { 16 | let numberOfTimesCalled = 0; 17 | fireTwice$() 18 | .pipe( 19 | finalize(() => { 20 | expect(numberOfTimesCalled).toEqual(2); 21 | done(); 22 | }) 23 | ) 24 | .subscribe(() => { 25 | ++numberOfTimesCalled; 26 | }); 27 | }); 28 | 29 | /** 30 | * Test that distinctValues work on a specific value. 31 | * 32 | * @param value - A value to test. 33 | */ 34 | const testValue = (value: any, type: string) => 35 | it(`should only fire once for ${type}`, done => { 36 | let numberOfTimesCalled = 0; 37 | fireTwice$() 38 | .pipe( 39 | mapTo(value), 40 | distinctValues(), 41 | finalize(() => { 42 | expect(numberOfTimesCalled).toEqual(1); 43 | done(); 44 | }) 45 | ) 46 | .subscribe(() => { 47 | ++numberOfTimesCalled; 48 | }); 49 | }); 50 | 51 | testValue(2, 'number'); 52 | testValue('foo', 'string'); 53 | testValue({ foo: 'bar' }, 'object'); 54 | testValue(new BigNumber(2), 'BigNumber'); 55 | testValue({ number: new BigNumber(2) }, 'Block'); 56 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/operators/distinctValues.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import BigNumber from 'bignumber.js'; 7 | import { distinctUntilChanged } from 'rxjs/operators'; 8 | import { isObject } from '@parity/api/lib/util/types'; 9 | 10 | import { Block } from '../../types'; 11 | 12 | /** 13 | * An intelligent distinctUntilChanged(). 14 | * 15 | * @ignore 16 | */ 17 | export const distinctValues = () => 18 | distinctUntilChanged((x, y) => { 19 | // If T == Block 20 | if ( 21 | x && 22 | y && 23 | ((x as unknown) as Block).number && 24 | ((y as unknown) as Block).number 25 | ) { 26 | return ((x as unknown) as Block).number.eq( 27 | ((y as unknown) as Block).number 28 | ); 29 | } 30 | 31 | // If T == BigNumber 32 | if (BigNumber.isBigNumber(x) && BigNumber.isBigNumber(y)) { 33 | return ((x as unknown) as BigNumber).eq((y as unknown) as BigNumber); 34 | } 35 | 36 | // If T == object 37 | if (isObject(x) && isObject(y)) { 38 | return JSON.stringify(x) === JSON.stringify(y); // TODO Do a deep equal instead 39 | } 40 | 41 | // Other cases 42 | return x === y; 43 | }); 44 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/operators/index.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | export * from './distinctReplayRefCountDelay'; 7 | export * from './distinctValues'; 8 | export * from './switchMapPromise'; 9 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/testHelpers/mockRpc.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | import { timer } from 'rxjs'; 7 | 8 | import createRpc from '../../rpc/utils/createRpc'; 9 | import { resolveApi } from '../testHelpers/mockApi'; 10 | import { setApi } from '../../api'; 11 | 12 | /** 13 | * Create a fake RpcObservable. 14 | * 15 | * @ignore 16 | */ 17 | setApi(resolveApi()); 18 | const mockRpc$ = createRpc({ frequency: [() => timer(0, 1000)] })(); 19 | 20 | export default mockRpc$; 21 | -------------------------------------------------------------------------------- /packages/light.js/src/utils/testHelpers/sleep.ts: -------------------------------------------------------------------------------- 1 | // Copyright 2015-2019 Parity Technologies (UK) Ltd. 2 | // This file is part of Parity. 3 | // 4 | // SPDX-License-Identifier: MIT 5 | 6 | // TODO Use fake timers instead 7 | export default (duration: number) => 8 | new Promise(resolve => { 9 | setTimeout(resolve, duration); 10 | }); 11 | -------------------------------------------------------------------------------- /packages/light.js/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "./lib" 4 | }, 5 | "extends": "../../tsconfig.json", 6 | "include": ["./src"] 7 | } 8 | -------------------------------------------------------------------------------- /packages/light.js/typedoc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | exclude: ['**/*spec.ts', '**/index.ts'], 3 | excludeExternals: true, 4 | excludePrivate: true, 5 | hideGenerator: true, 6 | includes: './src', 7 | out: 'docs/api', 8 | module: 'commonjs', 9 | mdEngine: 'gitbook', 10 | stripInternal: 'true', 11 | theme: 'markdown' 12 | }; 13 | -------------------------------------------------------------------------------- /scripts/lerna-publish.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Bump versions of all packages, and publish to npm. 4 | 5 | set -e # Quits if there's an error 6 | 7 | git remote set-url origin https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git > /dev/null 2>&1 8 | 9 | lerna version --conventional-commits --yes -m "chore(release): publish %s [ci skip]" 10 | lerna publish from-git --yes 11 | -------------------------------------------------------------------------------- /scripts/lint-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Apply `prettier` and `eslint` in two steps, because some `semistandard` rules 4 | # aren't supported by `prettier`, e.g. https://github.com/prettier/prettier/issues/3845 5 | 6 | [ $# -eq 0 ] && exit 0; # Exit successfully if no arguments 7 | 8 | set -e # Exit with error if any command fails 9 | 10 | echo 'Linting...' 11 | 12 | yarn prettier --loglevel error --write $@ 13 | yarn eslint --fix $@ 14 | -------------------------------------------------------------------------------- /scripts/update-docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Generate docs for a package, and update the docs on the `gh-pages` branch. 4 | 5 | set -e 6 | 7 | # These docs are generated by TypeDoc+Gitbook 8 | GITBOOK_DOCS=(abi light.js) 9 | # These docs are simple READMEs 10 | README_DOCS=(api contracts electron light.js-react) 11 | 12 | # The directory that will be pushed to gh-pages 13 | GHPAGES_DIR="$(pwd)/gh_pages" 14 | mkdir -p $GHPAGES_DIR 15 | 16 | # Generate GITBOOK_DOCS 17 | for SCOPE in "${GITBOOK_DOCS[@]}" 18 | do 19 | # Generate latest version of docs 20 | echo "Generating docs for $SCOPE" 21 | pushd . # We're in the root folder 22 | cd "packages/$SCOPE" 23 | yarn docs 24 | cd docs 25 | gitbook build # Outputs inside a local `_book` folder 26 | 27 | # Copy these generated html docs temporarily in a temp folder 28 | cp -r "_book" "$GHPAGES_DIR/$SCOPE" 29 | popd # Go back to root folder 30 | done 31 | 32 | # Generate README_DOCS 33 | for SCOPE in "${README_DOCS[@]}" 34 | do 35 | # Copy the README inside $GHPAGES_DIR 36 | echo "Generating docs for $SCOPE" 37 | mkdir -p "$GHPAGES_DIR/$SCOPE" 38 | cp "packages/$SCOPE/README.md" "$GHPAGES_DIR/$SCOPE" 39 | done 40 | 41 | # Finally, copy the main README into $GHPAGES_DIR 42 | cp README.md $GHPAGES_DIR 43 | 44 | # Add a .nojekyll file to bypass Jekyll on Github Pages 45 | # See https://github.com/paritytech/js-libs/issues/146 46 | touch "$GHPAGES_DIR/.nojekyll" 47 | 48 | # Docs are updated on master, we commit back 49 | git checkout master 50 | git add . 51 | git commit -m "docs: update docs [ci skip]" 52 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration": true, 4 | "jsx": "react", 5 | "lib": ["dom", "es2015", "es2017"], 6 | "moduleResolution": "node", 7 | "strict": true, 8 | "target": "es5" 9 | }, 10 | "exclude": ["*.spec.ts"] 11 | } 12 | --------------------------------------------------------------------------------