├── .nvmrc ├── mise.toml ├── packages ├── coinlib-ethereum │ ├── .nvmrc │ ├── jest.config.js │ ├── prettier.config.js │ ├── tsconfig.exec.json │ ├── test │ │ ├── index.test.ts │ │ ├── tslint.json │ │ └── fixtures │ │ │ ├── types.ts │ │ │ └── TestWeb3Provider.ts │ ├── bin │ │ ├── build.sh │ │ └── docs.sh │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── rollup.config.js │ ├── README.md │ ├── src │ │ ├── erc20 │ │ │ ├── mixins.ts │ │ │ ├── constants.ts │ │ │ ├── KeyPairErc20Payments.ts │ │ │ └── UHdErc20Payments.ts │ │ ├── @types │ │ │ └── ethereum-input-data-decoder │ │ │ │ └── index.d.ts │ │ ├── index.ts │ │ ├── EthereumConnectionManager.ts │ │ ├── UHdEthereumPayments.ts │ │ ├── helpers.ts │ │ ├── bip44.ts │ │ └── UnitConvertersUtil.ts │ ├── .npmignore │ ├── LICENCE │ └── package.json ├── coinlib-doge │ ├── test │ │ ├── fixtures │ │ │ ├── common.ts │ │ │ ├── index.ts │ │ │ ├── multisigMainnet.ts │ │ │ └── bip44.ts │ │ ├── helpers.test.ts │ │ └── utils.ts │ ├── jest.config.js │ ├── prettier.config.js │ ├── tsconfig.exec.json │ ├── bin │ │ ├── ts-node.sh │ │ ├── build.sh │ │ └── docs.sh │ ├── .gitignore │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── README.md │ ├── rollup.config.js │ ├── src │ │ ├── DogeBalanceMonitor.ts │ │ ├── index.ts │ │ ├── UHdDogePayments.ts │ │ ├── bip44.ts │ │ ├── SinglesigDogePayments.ts │ │ ├── utils.ts │ │ └── DogePaymentsFactory.ts │ ├── LICENCE │ └── package.json ├── coinlib-bitcoin │ ├── test │ │ ├── fixtures │ │ │ ├── common.ts │ │ │ ├── index.ts │ │ │ ├── multisigTestnet.ts │ │ │ ├── bip44.ts │ │ │ └── singlesigTestnet.ts │ │ └── HdBitcoinPayments.test.ts │ ├── jest.config.js │ ├── prettier.config.js │ ├── tsconfig.exec.json │ ├── bin │ │ ├── ts-node.sh │ │ ├── build.sh │ │ └── docs.sh │ ├── .gitignore │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── README.md │ ├── rollup.config.js │ ├── src │ │ ├── bitcoinish │ │ │ ├── index.ts │ │ │ ├── constants.ts │ │ │ └── BlockbookConnected.ts │ │ ├── index.ts │ │ ├── BitcoinBalanceMonitor.ts │ │ ├── UHdBitcoinPayments.ts │ │ ├── bip44.ts │ │ ├── utils.ts │ │ └── SinglesigBitcoinPayments.ts │ ├── LICENCE │ └── package.json ├── coinlib-litecoin │ ├── test │ │ ├── fixtures │ │ │ ├── common.ts │ │ │ ├── index.ts │ │ │ ├── multisigTestnet.ts │ │ │ ├── bip44.ts │ │ │ └── singlesigMainnet.ts │ │ ├── utils.ts │ │ └── HdLitecoinPayments.test.ts │ ├── jest.config.js │ ├── prettier.config.js │ ├── tsconfig.exec.json │ ├── bin │ │ ├── ts-node.sh │ │ ├── build.sh │ │ └── docs.sh │ ├── tsconfig.build.json │ ├── .gitignore │ ├── tsconfig.json │ ├── README.md │ ├── rollup.config.js │ ├── src │ │ ├── LitecoinBalanceMonitor.ts │ │ ├── index.ts │ │ ├── UHdLitecoinPayments.ts │ │ ├── utils.ts │ │ ├── SinglesigLitecoinPayments.ts │ │ └── bip44.ts │ ├── LICENCE │ └── package.json ├── coinlib │ ├── jest.config.js │ ├── prettier.config.js │ ├── test │ │ ├── index.test.ts │ │ ├── tslint.json │ │ ├── fixtures │ │ │ └── utils.ts │ │ └── utils.test.ts │ ├── bin │ │ ├── build.sh │ │ └── docs.sh │ ├── tsconfig.build.json │ ├── rollup.config.js │ ├── tsconfig.json │ ├── src │ │ ├── utils.ts │ │ ├── index.ts │ │ └── constants.ts │ ├── LICENCE │ ├── package.json │ └── README.md ├── coinlib-common │ ├── src │ │ ├── @types │ │ │ └── bs58check │ │ │ │ └── index.d.ts │ │ ├── index.ts │ │ ├── SharedDependencies.ts │ │ └── StandardConnectionManager.ts │ ├── jest.config.js │ ├── prettier.config.js │ ├── test │ │ ├── index.test.ts │ │ ├── tslint.json │ │ └── HdKeyUtils.test.ts │ ├── bin │ │ ├── docs.sh │ │ └── build.sh │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── rollup.config.js │ ├── LICENCE │ └── package.json ├── coinlib-tron │ ├── jest.config.js │ ├── prettier.config.js │ ├── bin │ │ ├── build.sh │ │ └── docs.sh │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── rollup.config.js │ ├── README.md │ ├── test │ │ ├── tslint.json │ │ ├── utils.ts │ │ ├── fixtures │ │ │ └── accounts.ts │ │ ├── bip44.test.ts │ │ ├── helpers.test.ts │ │ └── TronPaymentsFactory.test.ts │ ├── src │ │ ├── index.ts │ │ ├── UHdTronPayments.ts │ │ ├── utils.ts │ │ ├── constants.ts │ │ ├── TronPaymentsFactory.ts │ │ ├── base58.ts │ │ └── HdTronPayments.ts │ ├── LICENCE │ └── package.json ├── coinlib-ripple │ ├── jest.config.js │ ├── prettier.config.js │ ├── src │ │ ├── utils.ts │ │ ├── index.ts │ │ ├── UHdRipplePayments.ts │ │ ├── HdRipplePayments.ts │ │ └── constants.ts │ ├── test │ │ ├── index.test.ts │ │ ├── tslint.json │ │ ├── fixtures │ │ │ └── accounts.ts │ │ └── bip44.test.ts │ ├── bin │ │ ├── docs.sh │ │ └── build.sh │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── rollup.config.js │ ├── README.md │ ├── .npmignore │ ├── LICENCE │ └── package.json ├── coinlib-stellar │ ├── jest.config.js │ ├── prettier.config.js │ ├── tsconfig.exec.json │ ├── test │ │ ├── index.test.ts │ │ ├── tslint.json │ │ ├── sandbox.ts │ │ ├── fixtures │ │ │ └── accounts.ts │ │ ├── bip44.test.ts │ │ ├── helper.ts │ │ └── HdStellarPayments.test.ts │ ├── bin │ │ ├── ts-node.sh │ │ ├── build.sh │ │ └── docs.sh │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── rollup.config.js │ ├── README.md │ ├── src │ │ ├── index.ts │ │ ├── HdStellarPayments.ts │ │ ├── UHdStellarPayments.ts │ │ ├── constants.ts │ │ └── bip44.ts │ ├── .npmignore │ ├── LICENCE │ └── package.json ├── coinlib-types │ ├── jest.config.js │ ├── prettier.config.js │ ├── test │ │ ├── index.test.ts │ │ ├── tslint.json │ │ └── errors.test.ts │ ├── bin │ │ ├── docs.sh │ │ └── build.sh │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── rollup.config.js │ ├── src │ │ ├── index.ts │ │ ├── constants.ts │ │ ├── PaymentsConnectionManager.ts │ │ └── errors.ts │ ├── LICENCE │ └── package.json └── coinlib-bitcoin-cash │ ├── jest.config.js │ ├── test │ ├── fixtures │ │ ├── index.ts │ │ ├── common.ts │ │ ├── multisigTestnet.ts │ │ └── bip44.ts │ ├── utils.ts │ └── HdBitcoinCashPayments.test.ts │ ├── prettier.config.js │ ├── tsconfig.exec.json │ ├── bin │ ├── ts-node.sh │ ├── build.sh │ └── docs.sh │ ├── .gitignore │ ├── tsconfig.build.json │ ├── tsconfig.json │ ├── README.md │ ├── rollup.config.js │ ├── src │ ├── BitcoinCashBalanceMonitor.ts │ ├── index.ts │ ├── UHdBitcoinCashPayments.ts │ ├── bip44.ts │ └── utils.ts │ └── LICENCE ├── pull_request_template.md ├── .huskyrc.js ├── tsconfig.eslint.json ├── bin ├── preversion.sh ├── extract-version.sh ├── find-bad-imports.sh ├── docs.sh ├── build.sh ├── coinlib-buildall.sh ├── publish.sh ├── pr.sh └── version.sh ├── lint-staged.config.js ├── prettier.config.js ├── .eslintignore ├── .envrc ├── .editorconfig ├── .gitignore ├── tsconfig.json ├── .npmignore ├── tsconfig.build.json ├── lerna.json ├── jest.config.js ├── LICENCE ├── .gitmessage ├── flake.nix ├── flake.lock └── .eslintrc.js /.nvmrc: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /mise.toml: -------------------------------------------------------------------------------- 1 | [tools] 2 | node = "14" 3 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/.nvmrc: -------------------------------------------------------------------------------- 1 | 12 2 | -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | # Description of the change 2 | 3 | (Description here) 4 | -------------------------------------------------------------------------------- /.huskyrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | hooks: { 3 | precommit: 'lint-staged' 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /packages/coinlib-doge/test/fixtures/common.ts: -------------------------------------------------------------------------------- 1 | export const EXTERNAL_ADDRESS = 'DB15Lt7u8hxkbT8s1JAKHA9Xbxr8SbxnC8' 2 | -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": ["src/**/*.ts", "test/**/*.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/test/fixtures/common.ts: -------------------------------------------------------------------------------- 1 | export const EXTERNAL_ADDRESS = '14Z2k3tU19TSzBfT8s4QFAcYsbECUJnxiK' 2 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/test/fixtures/common.ts: -------------------------------------------------------------------------------- 1 | export const EXTERNAL_ADDRESS = 'MCTwS16sNbKENcr7qs5drkZTtSfaJLw8tB' 2 | -------------------------------------------------------------------------------- /bin/preversion.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | DIR=$(dirname $0) 3 | $DIR/../node_modules/@bitaccess/ts-config/library/bin/preversion.sh 4 | -------------------------------------------------------------------------------- /lint-staged.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'packages/*/{src,test}/**/*.ts': [ 3 | 'prettier --write', 4 | 'git add' 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /bin/extract-version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Extracts the "version" field from a JSON file 3 | exec node -e "console.log(require('$1').version)" 4 | -------------------------------------------------------------------------------- /packages/coinlib/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-common/src/@types/bs58check/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'bs58check' { 2 | import * as base58 from 'bs58check' 3 | export default base58 4 | } 5 | -------------------------------------------------------------------------------- /packages/coinlib-doge/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-doge/test/fixtures/index.ts: -------------------------------------------------------------------------------- 1 | export * from './accounts' 2 | export * from './transactions' 3 | export * from './bip44' 4 | export * from './common' 5 | -------------------------------------------------------------------------------- /packages/coinlib-tron/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/test/fixtures/index.ts: -------------------------------------------------------------------------------- 1 | export * from './accounts' 2 | export * from './transactions' 3 | export * from './bip44' 4 | export * from './common' 5 | -------------------------------------------------------------------------------- /packages/coinlib-common/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/test/fixtures/index.ts: -------------------------------------------------------------------------------- 1 | export * from './accounts' 2 | export * from './transactions' 3 | export * from './bip44' 4 | export * from './common' 5 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-types/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // Overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/test/fixtures/index.ts: -------------------------------------------------------------------------------- 1 | export * from './accounts' 2 | export * from './transactions' 3 | export * from './bip44' 4 | export * from './common' 5 | -------------------------------------------------------------------------------- /packages/coinlib-common/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-doge/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-doge/tsconfig.exec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "target": "es5" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-tron/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-types/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/tsconfig.exec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "target": "es5" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/tsconfig.exec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "target": "es5" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/tsconfig.exec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "target": "es5" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/tsconfig.exec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "target": "es5" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib/test/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as src from '../src' 2 | 3 | describe('module', () => { 4 | it('exists', () => { 5 | expect(src).toBeDefined() 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/prettier.config.js: -------------------------------------------------------------------------------- 1 | const base = require('../../prettier.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | // overrides here 5 | }) 6 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/tsconfig.exec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "target": "es5" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/src/utils.ts: -------------------------------------------------------------------------------- 1 | export function padLeft(x: string, n: number, v: string): string { 2 | while (x.length < n) { 3 | x = `${v}${x}` 4 | } 5 | return x 6 | } 7 | -------------------------------------------------------------------------------- /packages/coinlib-types/test/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as src from '../src' 2 | 3 | describe('module', () => { 4 | it('exists', () => { 5 | expect(src).toBeDefined() 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /packages/coinlib-common/test/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as src from '../src' 2 | 3 | describe('module', () => { 4 | it('exists', () => { 5 | expect(src).toBeDefined() 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /packages/coinlib-doge/bin/ts-node.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ROOT=$(dirname $0)/.. 3 | "$ROOT/node_modules/.bin/ts-node" -P "$ROOT/tsconfig.exec.json" --files -r tsconfig-paths/register $@ 4 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/test/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as src from '../src' 2 | 3 | describe('module', () => { 4 | it('exists', () => { 5 | expect(src).toBeDefined() 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/test/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as src from '../src' 2 | 3 | describe('module', () => { 4 | it('exists', () => { 5 | expect(src).toBeDefined() 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/test/index.test.ts: -------------------------------------------------------------------------------- 1 | import * as src from '../src' 2 | 3 | describe('module', () => { 4 | it('exists', () => { 5 | expect(src).toBeDefined() 6 | }) 7 | }) 8 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/bin/ts-node.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ROOT=$(dirname $0)/.. 3 | "$ROOT/node_modules/.bin/ts-node" -P "$ROOT/tsconfig.exec.json" --files -r tsconfig-paths/register $@ 4 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/bin/ts-node.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ROOT=$(dirname $0)/.. 3 | "$ROOT/node_modules/.bin/ts-node" -P "$ROOT/tsconfig.exec.json" --files -r tsconfig-paths/register $@ 4 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/bin/ts-node.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ROOT=$(dirname $0)/.. 3 | "$ROOT/node_modules/.bin/ts-node" -P "$ROOT/tsconfig.exec.json" --files -r tsconfig-paths/register $@ 4 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/bin/ts-node.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | ROOT=$(dirname $0)/.. 3 | "$ROOT/node_modules/.bin/ts-node" -P "$ROOT/tsconfig.exec.json" --files -r tsconfig-paths/register $@ 4 | -------------------------------------------------------------------------------- /packages/coinlib/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # don't ever lint node_modules 2 | node_modules 3 | # don't lint build output (make sure it's set to your correct build folder name) 4 | dist 5 | # don't lint nyc coverage output 6 | coverage -------------------------------------------------------------------------------- /packages/coinlib-common/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-doge/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | npm-debug.log 4 | newrelic_agent.log 5 | reports/* 6 | Session.vim 7 | dumps 8 | /.gtm/ 9 | tools/logstash-forwarder.crt 10 | dump 11 | -------------------------------------------------------------------------------- /packages/coinlib-doge/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-doge/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-tron/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-tron/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-types/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | npm-debug.log 4 | newrelic_agent.log 5 | reports/* 6 | Session.vim 7 | dumps 8 | /.gtm/ 9 | tools/logstash-forwarder.crt 10 | dump 11 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-common/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-types/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | npm-debug.log 4 | newrelic_agent.log 5 | reports/* 6 | Session.vim 7 | dumps 8 | /.gtm/ 9 | tools/logstash-forwarder.crt 10 | dump 11 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/build.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | PACKAGE_ROOT="`cd $(dirname $0)/..; echo $PWD`" 3 | REPO_ROOT="`cd $PACKAGE_ROOT/../..; echo $PWD`" 4 | "$REPO_ROOT/bin/docs.sh" "$PACKAGE_ROOT" 5 | -------------------------------------------------------------------------------- /packages/coinlib-common/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-doge/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-tron/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-types/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-common/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-doge/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-tron/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-types/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.build.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | }, 7 | "include": ["src"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | npm-debug.log 4 | newrelic_agent.log 5 | reports/* 6 | Session.vim 7 | dumps 8 | /.gtm/ 9 | tools/logstash-forwarder.crt 10 | dump 11 | test/keys 12 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib" 6 | }, 7 | "exclude": ["node_modules", "dist"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/coinlib/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | module.exports = { 5 | ...base(pkg), 6 | // overrides here 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-common/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | module.exports = { 5 | ...base(pkg), 6 | // overrides here 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | module.exports = { 5 | ...base(pkg), 6 | // overrides here 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | module.exports = { 5 | ...base(pkg), 6 | // overrides here 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | module.exports = { 5 | ...base(pkg), 6 | // overrides here 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-tron/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | module.exports = { 5 | ...base(pkg), 6 | // overrides here 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-types/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | module.exports = { 5 | ...base(pkg), 6 | // overrides here 7 | } 8 | -------------------------------------------------------------------------------- /packages/coinlib-doge/README.md: -------------------------------------------------------------------------------- 1 | coinlib-doge 2 | ================= 3 | 4 | Please refer to the [@bitaccess/coinlib README](https://github.com/bitaccess/coinlib/blob/master/packages/coinlib/README.md) for more detailed information. 5 | -------------------------------------------------------------------------------- /packages/coinlib-tron/README.md: -------------------------------------------------------------------------------- 1 | coinlib-tron 2 | ================= 3 | 4 | Please refer to the [@bitaccess/coinlib README](https://github.com/bitaccess/coinlib/blob/master/packages/coinlib/README.md) for more detailed information. 5 | -------------------------------------------------------------------------------- /packages/coinlib/test/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tslint.json" 4 | ], 5 | "rules": { 6 | "max-line-length": false, 7 | "no-console": false, 8 | "no-constant-condition": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/test/fixtures/common.ts: -------------------------------------------------------------------------------- 1 | export const EXTERNAL_ADDRESS = 'bitcoincash:qqq50km70cjgpla3tnkt8nxgdt09wp0m7y9ctca8f6' 2 | export const TESTNET_EXTERNAL_ADDRESS = 'bchtest:qze8g4gx3z428jjcxzpycpxl7ke7d947gca2a7n2la' 3 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/README.md: -------------------------------------------------------------------------------- 1 | coinlib-bitcoin 2 | ================= 3 | 4 | Please refer to the [@bitaccess/coinlib README](https://github.com/bitaccess/coinlib/blob/master/packages/coinlib/README.md) for more detailed information. 5 | -------------------------------------------------------------------------------- /packages/coinlib-common/test/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tslint.json" 4 | ], 5 | "rules": { 6 | "max-line-length": false, 7 | "no-console": false, 8 | "no-constant-condition": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/README.md: -------------------------------------------------------------------------------- 1 | coinlib-ethereum 2 | ================= 3 | 4 | Please refer to the [@bitaccess/coinlib README](https://github.com/bitaccess/coinlib/blob/master/packages/coinlib/README.md) for more detailed information. 5 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/README.md: -------------------------------------------------------------------------------- 1 | coinlib-litecoin 2 | ================= 3 | 4 | Please refer to the [@bitaccess/coinlib README](https://github.com/bitaccess/coinlib/blob/master/packages/coinlib/README.md) for more detailed information. 5 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/README.md: -------------------------------------------------------------------------------- 1 | coinlib-ripple 2 | ================= 3 | 4 | Please refer to the [@bitaccess/coinlib README](https://github.com/bitaccess/coinlib/blob/master/packages/coinlib/README.md) for more detailed information. 5 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/test/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tslint.json" 4 | ], 5 | "rules": { 6 | "max-line-length": false, 7 | "no-console": false, 8 | "no-constant-condition": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/README.md: -------------------------------------------------------------------------------- 1 | stellar-payments 2 | ================= 3 | 4 | Please refer to the [@bitaccess/coinlib README](https://github.com/bitaccess/coinlib/blob/master/packages/coinlib/README.md) for more detailed information. 5 | -------------------------------------------------------------------------------- /packages/coinlib-tron/test/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tslint.json" 4 | ], 5 | "rules": { 6 | "max-line-length": false, 7 | "no-console": false, 8 | "no-constant-condition": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/coinlib-types/test/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tslint.json" 4 | ], 5 | "rules": { 6 | "max-line-length": false, 7 | "no-console": false, 8 | "no-constant-condition": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then 2 | source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4=" 3 | fi 4 | use flake 5 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/test/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tslint.json" 4 | ], 5 | "rules": { 6 | "max-line-length": false, 7 | "no-console": false, 8 | "no-constant-condition": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/test/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "../tslint.json" 4 | ], 5 | "rules": { 6 | "max-line-length": false, 7 | "no-console": false, 8 | "no-constant-condition": false 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/README.md: -------------------------------------------------------------------------------- 1 | coinlib-bitcoin-cash 2 | ================= 3 | 4 | Please refer to the [@bitaccess/coinlib README](https://github.com/bitaccess/coinlib/blob/master/packages/coinlib/README.md) for more detailed information. 5 | -------------------------------------------------------------------------------- /packages/coinlib-tron/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { PACKAGE_NAME } from '../src/constants' 2 | import { TestLogger } from '../../../common/testUtils' 3 | 4 | export * from '../../../common/testUtils' 5 | export const logger = new TestLogger(PACKAGE_NAME) 6 | -------------------------------------------------------------------------------- /packages/coinlib-common/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './utils' 2 | export * from './PaymentsFactory' 3 | export * from './SharedDependencies' 4 | export * from './HdKeyUtils' 5 | export * from './StandardConnectionManager' 6 | export * from '@bitaccess/coinlib-types' 7 | -------------------------------------------------------------------------------- /packages/coinlib-types/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './types' 2 | export * from './BasePayments' 3 | export * from './PaymentsUtils' 4 | export * from './BalanceMonitor' 5 | export * from './errors' 6 | export * from './PaymentsConnectionManager' 7 | export * from './constants' 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | #root = true 2 | 3 | [*] 4 | indent_style = space 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | max_line_length = 120 10 | indent_size = 2 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /packages/coinlib-ethereum/test/fixtures/types.ts: -------------------------------------------------------------------------------- 1 | 2 | export type MockReq = { 3 | method: string, 4 | params: any[], 5 | } 6 | 7 | export type MockRes = { 8 | result: R 9 | } 10 | 11 | export type Mock = { 12 | req: MockReq, 13 | res: MockRes, 14 | } 15 | -------------------------------------------------------------------------------- /bin/find-bad-imports.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Finds problematic relative path imports of local packages 3 | if grep -rnw -e '\.\./coinlib' packages/*/src packages/*/test; then 4 | echo "Found relative imports of local packages that should be replaced with '@bitaccess/'" 5 | exit 1 6 | fi 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.key 2 | *.log 3 | *.password 4 | *.wallet 5 | *bitaccess-*.tgz 6 | .DS_Store 7 | .awcache 8 | .env* 9 | !.envrc 10 | .idea 11 | .nyc_output 12 | .rpt2_cache/ 13 | .vscode 14 | compiled/ 15 | coverage/ 16 | dist/ 17 | docs/ 18 | node_modules/ 19 | simple.ts 20 | vendor/ 21 | logs/ 22 | tmp/ 23 | .direnv 24 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.build.json", 3 | "compilerOptions": { 4 | "strict": true, 5 | "lib": ["es2020"], 6 | "paths": { 7 | "@bitaccess/ts-common": ["./node_modules/@bitaccess/ts-common"], 8 | "@bitaccess/coinlib-*": ["../coinlib-*/src", "./node_modules/@bitaccess/coinlib-*"] 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/coinlib/test/fixtures/utils.ts: -------------------------------------------------------------------------------- 1 | export const MNEMONIC = 'actual opera siren spoon castle purchase crash throw female curve company fluid elevator snow wage' 2 | export const SEED_HEX = 'abce0a9bcf3cf1744cb9bedf4a73ddcf4d91e532f48954e384c81b477bade106c53cbb170e0a5f5e88853ece1b3dbe60ab5083ef1d433cec1ec3448ecbabfddd' 3 | export const FINGERPRINT = '51c8274a' -------------------------------------------------------------------------------- /packages/coinlib-doge/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | const baseConfig = base(pkg) 5 | module.exports = { 6 | ...baseConfig, 7 | external: [ 8 | ...baseConfig.external, 9 | 'bip174/src/lib/interfaces', 10 | ] 11 | // overrides here 12 | } 13 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | const baseConfig = base(pkg) 5 | module.exports = { 6 | ...baseConfig, 7 | external: [ 8 | ...baseConfig.external, 9 | 'bip174/src/lib/interfaces', 10 | ] 11 | // overrides here 12 | } 13 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | const baseConfig = base(pkg) 5 | module.exports = { 6 | ...baseConfig, 7 | external: [ 8 | ...baseConfig.external, 9 | 'bip174/src/lib/interfaces', 10 | ] 11 | // overrides here 12 | } 13 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/rollup.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/rollup.config') 2 | const pkg = require('./package.json') 3 | 4 | const baseConfig = base(pkg) 5 | module.exports = { 6 | ...baseConfig, 7 | external: [ 8 | ...baseConfig.external, 9 | 'bip174/src/lib/interfaces', 10 | ] 11 | // overrides here 12 | } 13 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BaseStellarPayments' 2 | export * from './HdStellarPayments' 3 | export * from './UHdStellarPayments' 4 | export * from './AccountStellarPayments' 5 | export * from './StellarPaymentsUtil' 6 | export * from './StellarBalanceMonitor' 7 | export * from './StellarPaymentsFactory' 8 | export * from './types' 9 | export * from './helpers' 10 | -------------------------------------------------------------------------------- /bin/docs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Builds the docs for a specified package. Designed to be run within that package dir. 4 | # Usage: docs.sh [...args] 5 | 6 | REPO_ROOT="`cd $(dirname $0)/..; echo $PWD`" 7 | PACKAGE_ROOT=$1 8 | shift 9 | "$REPO_ROOT/node_modules/@bitaccess/ts-config/library/bin/docs.sh" "$PACKAGE_ROOT" --tsconfig "$PACKAGE_ROOT/tsconfig.build.json" "$@" 10 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BaseRipplePayments' 2 | export * from './HdRipplePayments' 3 | export * from './UHdRipplePayments' 4 | export * from './AccountRipplePayments' 5 | export * from './RipplePaymentsUtils' 6 | export * from './RippleBalanceMonitor' 7 | export * from './RipplePaymentsFactory' 8 | export * from './types' 9 | export * from './helpers' 10 | export * from './constants' 11 | -------------------------------------------------------------------------------- /packages/coinlib-tron/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BaseTronPayments' 2 | export * from './HdTronPayments' 3 | export * from './UHdTronPayments' 4 | export * from './KeyPairTronPayments' 5 | export * from './TronPaymentsFactory' 6 | export * from './TronPaymentsUtils' 7 | export * from './types' 8 | export * from './helpers' 9 | export * from './bip44' 10 | export * from './base58' 11 | export * from './constants' 12 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | .env* 4 | coverage/ 5 | .nyc_output 6 | *.log 7 | .vscode 8 | .idea 9 | compiled/ 10 | .awcache 11 | .rpt2_cache 12 | *.password 13 | *.wallet 14 | *.key 15 | 16 | bin/ 17 | test/ 18 | .editorconfig 19 | .huskyrc.js 20 | jest.config.js 21 | lint-staged.config.js 22 | prettier.config.js 23 | rollup.config.js 24 | tslint.json 25 | typedoc.js 26 | tsconfig.json 27 | tsconfig.build.json 28 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/bitcoinish/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BitcoinishPayments' 2 | export * from './BitcoinishPaymentsUtils' 3 | export * from './BlockbookConnected' 4 | export * from './types' 5 | export * from './constants' 6 | export * from './helpers' 7 | export * from './utils' 8 | export * from './BitcoinishBalanceMonitor' 9 | export * from './multisigPaymentHelper' 10 | export * from './singlesigPaymentHelper' 11 | -------------------------------------------------------------------------------- /packages/coinlib-types/src/constants.ts: -------------------------------------------------------------------------------- 1 | export const DEFAULT_MAX_FEE_PERCENT = 50 2 | export const BIP39_SEED_REGEX = /^[0-9a-f]{128}$/ 3 | export const BIP39_SEED_BYTES = 64 4 | export const DERIVATION_PATH_REGEX = /^(m\/)?[0-9]+'?(\/[0-9]+'?)*$/ 5 | 6 | export const SUPPORTED_NETWORK_SYMBOLS = [ 7 | "BCH", 8 | "BTC", 9 | "DOGE", 10 | "ETH", 11 | "LTC", 12 | "TRX", 13 | "XLM", 14 | "XRP", 15 | ] as const 16 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/erc20/mixins.ts: -------------------------------------------------------------------------------- 1 | export function applyMixins(derivedCtor: any, baseCtors: any[]) { 2 | baseCtors.forEach(baseCtor => { 3 | Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => { 4 | Object.defineProperty( 5 | derivedCtor.prototype, 6 | name, 7 | Object.getOwnPropertyDescriptor(baseCtor.prototype, name) as PropertyDescriptor 8 | ); 9 | }); 10 | }); 11 | } 12 | 13 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | .env* 4 | coverage/ 5 | .nyc_output 6 | *.log 7 | .vscode 8 | .idea 9 | compiled/ 10 | .awcache 11 | .rpt2_cache 12 | *.password 13 | *.wallet 14 | *.key 15 | 16 | bin/ 17 | test/ 18 | .editorconfig 19 | .huskyrc.js 20 | jest.config.js 21 | lint-staged.config.js 22 | prettier.config.js 23 | rollup.config.js 24 | tslint.json 25 | typedoc.js 26 | tsconfig.json 27 | tsconfig.build.json 28 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | .env* 4 | coverage/ 5 | .nyc_output 6 | *.log 7 | .vscode 8 | .idea 9 | compiled/ 10 | .awcache 11 | .rpt2_cache 12 | *.password 13 | *.wallet 14 | *.key 15 | 16 | bin/ 17 | test/ 18 | .editorconfig 19 | .huskyrc.js 20 | jest.config.js 21 | lint-staged.config.js 22 | prettier.config.js 23 | rollup.config.js 24 | tslint.json 25 | typedoc.js 26 | tsconfig.json 27 | tsconfig.build.json 28 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/.npmignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | .env* 4 | coverage/ 5 | .nyc_output 6 | *.log 7 | .vscode 8 | .idea 9 | compiled/ 10 | .awcache 11 | .rpt2_cache 12 | *.password 13 | *.wallet 14 | *.key 15 | 16 | bin/ 17 | test/ 18 | .editorconfig 19 | .huskyrc.js 20 | jest.config.js 21 | lint-staged.config.js 22 | prettier.config.js 23 | rollup.config.js 24 | tslint.json 25 | typedoc.js 26 | tsconfig.json 27 | tsconfig.build.json 28 | -------------------------------------------------------------------------------- /bin/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # Builds the specified package. Designed to be run within that package dir. 5 | # Usage: build.sh [...args] 6 | 7 | NM_BIN="$1/node_modules/.bin" 8 | TSCONFIG="$1/tsconfig.build.json" 9 | ROLLUP_CONFIG="$1/rollup.config.js" 10 | 11 | echo ">> cd $1" 12 | cd "$1" 13 | 14 | echo ">> tsc" 15 | "$NM_BIN/tsc" -b "$TSCONFIG" 16 | 17 | echo ">> rollup" 18 | "$NM_BIN/rollup" -c "$ROLLUP_CONFIG" 19 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/erc20/constants.ts: -------------------------------------------------------------------------------- 1 | export const ERC20_TRANSFER = '0xa9059cbb' 2 | export const ERC20_SWEEP_LEGACY = '0xb8dc491b' 3 | export const ERC20_SWEEP = '0x2c8f55de' 4 | export const ERC20_SWEEP_CONTRACT_DEPLOY = '0x60806040' 5 | export const ERC20_SWEEP_CONTRACT_DEPLOY_LEGACY = '0x60606040' 6 | export const ERC20_PROXY = '0x3d602d806' 7 | export const LOG_TOPIC_ERC20_TRANSFER = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef' 8 | -------------------------------------------------------------------------------- /packages/coinlib-types/src/PaymentsConnectionManager.ts: -------------------------------------------------------------------------------- 1 | import { BaseConfig } from './types' 2 | 3 | export interface PaymentsConnectionManager< 4 | Connection, // connection type 5 | Config extends BaseConfig, // config for the connection and url 6 | > { 7 | connections: { [url: string]: Connection } 8 | getConnection(x: any): Connection 9 | getConnectionUrl(c: Config): string | string[] | null 10 | setConnection(c: Config, t: Connection): void 11 | } 12 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/@types/ethereum-input-data-decoder/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'ethereum-input-data-decoder' { 2 | interface DecodeResult { 3 | method: string 4 | types: string[] 5 | inputs: any[] 6 | names: any[] 7 | } 8 | export default class InputDataDecoder { 9 | constructor(abi: string | object) 10 | 11 | decodeConstructor(data: string | Buffer): DecodeResult 12 | decodeData(data: string | Buffer): DecodeResult 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/@bitaccess/ts-config/library/tsconfig.json", 3 | "compilerOptions": { 4 | "module": "ES6", 5 | "target": "ES2019", 6 | "lib": ["ES2019", "ES2020"], 7 | "strict": true, 8 | "useUnknownInCatchVariables": false, 9 | "paths": { 10 | "@bitaccess/ts-common": ["./node_modules/@bitaccess/ts-common"], 11 | "@bitaccess/coinlib-*": ["./node_modules/@bitaccess/coinlib-*"] 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /packages/coinlib/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./../../tsconfig.json", 3 | "compilerOptions": { 4 | "baseUrl": ".", 5 | "outDir": "dist/lib", 6 | "typeRoots": [ 7 | "./node_modules/@types", 8 | "../../node_modules/@types", 9 | "../coinlib-tron/src/@types", 10 | "../coinlib-stellar/src/@types", 11 | "../coinlib-ethereum/src/@types", 12 | "../coinlib-litecoin/src/@types", 13 | ] 14 | }, 15 | "exclude": ["node_modules", "dist"] 16 | } 17 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": [ 3 | "packages/*" 4 | ], 5 | "version": "8.0.1", 6 | "command": { 7 | "publish": { 8 | "ignoreChanges": [ 9 | "test/**/*", 10 | "bin/**/*", 11 | "prettier.config.js", 12 | "rollup.config.js", 13 | "*.md", 14 | "lint-staged.config.js", 15 | ".huskyrc.js", 16 | "jest.config.js", 17 | "typedoc.js", 18 | "tslint.json", 19 | ".editorconfig" 20 | ] 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/test/sandbox.ts: -------------------------------------------------------------------------------- 1 | import * as Stellar from 'stellar-sdk' 2 | import StellarHD from 'stellar-hd-wallet' 3 | 4 | import { setupTestnetPayments } from './utils' 5 | 6 | async function main() { 7 | const payments = await setupTestnetPayments() 8 | const address = StellarHD.fromSeed('0').getPublicKey(123) 9 | return payments.getApi().loadAccount(address) 10 | } 11 | 12 | main() 13 | .then((result: any) => { 14 | if (result) console.log(result) 15 | }) 16 | .catch(console.error) 17 | -------------------------------------------------------------------------------- /packages/coinlib-doge/src/DogeBalanceMonitor.ts: -------------------------------------------------------------------------------- 1 | import { DogePaymentsUtils } from './DogePaymentsUtils' 2 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 3 | import { DogeBalanceMonitorConfig } from './types' 4 | import { toBitcoinishConfig } from './utils' 5 | 6 | export class DogeBalanceMonitor extends bitcoinish.BitcoinishBalanceMonitor { 7 | constructor(config: DogeBalanceMonitorConfig) { 8 | super({ 9 | ...toBitcoinishConfig(config), 10 | utils: new DogePaymentsUtils(config), 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/coinlib-doge/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BaseDogePayments' 2 | export * from './types' 3 | export * from './constants' 4 | export * from './helpers' 5 | export * from './HdDogePayments' 6 | export * from './UHdDogePayments' 7 | export * from './DogePaymentsUtils' 8 | export * from './DogePaymentsFactory' 9 | export * from './SinglesigDogePayments' 10 | export * from './KeyPairDogePayments' 11 | export * from './MultisigDogePayments' 12 | export * from './DogeBalanceMonitor' 13 | export { bitcoinish } from '@bitaccess/coinlib-bitcoin' 14 | -------------------------------------------------------------------------------- /packages/coinlib/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { bip32, bip39 } from '@bitaccess/coinlib-common' 2 | 3 | /** Used to generate root xpub fingerprint when establishing signer */ 4 | export function getSeedHexFromMnemonic(mnemonic: string): string { 5 | const seed = bip39.mnemonicToSeedSync(mnemonic) 6 | return seed.toString("hex") 7 | } 8 | 9 | export function getFingerprintFromSeedHex(seedHex: string): string { 10 | const seed = Buffer.from(seedHex, 'hex') 11 | const root = bip32.fromSeed(seed) 12 | return root.fingerprint.toString('hex') 13 | } 14 | -------------------------------------------------------------------------------- /bin/coinlib-buildall.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | # Builds all of the packages 5 | 6 | npx lerna run --stream --scope=@bitaccess/coinlib-types build 7 | npx lerna run --stream --scope=@bitaccess/coinlib-common build 8 | npx lerna run --stream --scope=@bitaccess/coinlib-bitcoin build 9 | npx lerna run --stream --scope=@bitaccess/coinlib-* --ignore=@bitaccess/coinlib --ignore=@bitaccess/coinlib-bitcoin --ignore=@bitaccess/coinlib-common --ignore=@bitaccess/coinlib-types --parallel build 10 | npx lerna run --stream --scope=@bitaccess/coinlib build 11 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BaseBitcoinPayments' 2 | export * from './types' 3 | export * from './constants' 4 | export * from './helpers' 5 | export * from './HdBitcoinPayments' 6 | export * from './UHdBitcoinPayments' 7 | export * from './BitcoinPaymentsUtils' 8 | export * from './BitcoinPaymentsFactory' 9 | export * as bitcoinish from './bitcoinish' 10 | export * from './MultisigBitcoinPayments' 11 | export * from './SinglesigBitcoinPayments' 12 | export * from './KeyPairBitcoinPayments' 13 | export * from './BitcoinBalanceMonitor' 14 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BaseEthereumPayments' 2 | export * from './HdEthereumPayments' 3 | export * from './UHdEthereumPayments' 4 | export * from './KeyPairEthereumPayments' 5 | export * from './EthereumPaymentsFactory' 6 | export * from './EthereumPaymentsUtils' 7 | export * from './types' 8 | export * from './bip44' 9 | export * from './constants' 10 | export * from './erc20/BaseErc20Payments' 11 | export * from './erc20/HdErc20Payments' 12 | export * from './erc20/UHdErc20Payments' 13 | export * from './erc20/KeyPairErc20Payments' 14 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/src/LitecoinBalanceMonitor.ts: -------------------------------------------------------------------------------- 1 | import { LitecoinPaymentsUtils } from './LitecoinPaymentsUtils' 2 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 3 | import { LitecoinBalanceMonitorConfig } from './types' 4 | import { toBitcoinishConfig } from './utils' 5 | 6 | export class LitecoinBalanceMonitor extends bitcoinish.BitcoinishBalanceMonitor { 7 | constructor(config: LitecoinBalanceMonitorConfig) { 8 | super({ 9 | ...toBitcoinishConfig(config), 10 | utils: new LitecoinPaymentsUtils(config), 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/BitcoinBalanceMonitor.ts: -------------------------------------------------------------------------------- 1 | import { BitcoinPaymentsUtils } from './BitcoinPaymentsUtils' 2 | import { BitcoinishBalanceMonitor } from './bitcoinish/BitcoinishBalanceMonitor' 3 | import { BitcoinBalanceMonitorConfig } from './types' 4 | import { toBitcoinishConfig } from './utils' 5 | 6 | export class BitcoinBalanceMonitor extends BitcoinishBalanceMonitor { 7 | constructor(config: BitcoinBalanceMonitorConfig) { 8 | super({ 9 | ...toBitcoinishConfig(config), 10 | utils: new BitcoinPaymentsUtils(config), 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /bin/publish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | ROOT=$(cd $(dirname $0)/..; pwd) 5 | 6 | LERNA_V="v$($ROOT/bin/extract-version.sh $ROOT/lerna.json)" 7 | echo "Publishing $LERNA_V" 8 | 9 | ./node_modules/.bin/lerna run --stream build 10 | 11 | TAGGED_COMMIT=$(git rev-list -n 1 $LERNA_V 2>/dev/null || true) 12 | if [ -z "$TAGGED_COMMIT" ]; then 13 | echo "Tagging current commit as $LERNA_V" 14 | git tag $LERNA_V 15 | git push --tags 16 | else 17 | echo "Checking out $LERNA_V" 18 | git checkout "$LERNA_V" 19 | fi 20 | 21 | ./node_modules/.bin/lerna publish from-package 22 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BaseLitecoinPayments' 2 | export * from './types' 3 | export * from './constants' 4 | export * from './helpers' 5 | export * from './HdLitecoinPayments' 6 | export * from './UHdLitecoinPayments' 7 | export * from './LitecoinPaymentsUtils' 8 | export * from './LitecoinPaymentsFactory' 9 | export * from './SinglesigLitecoinPayments' 10 | export * from './MultisigLitecoinPayments' 11 | export * from './KeyPairLitecoinPayments' 12 | export * from './LitecoinBalanceMonitor' 13 | export { bitcoinish } from '@bitaccess/coinlib-bitcoin' 14 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/src/BitcoinCashBalanceMonitor.ts: -------------------------------------------------------------------------------- 1 | import { BitcoinCashPaymentsUtils } from './BitcoinCashPaymentsUtils' 2 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 3 | import { BitcoinCashBalanceMonitorConfig } from './types' 4 | import { toBitcoinishConfig } from './utils' 5 | 6 | export class BitcoinCashBalanceMonitor extends bitcoinish.BitcoinishBalanceMonitor { 7 | constructor(config: BitcoinCashBalanceMonitorConfig) { 8 | super({ 9 | ...toBitcoinishConfig(config), 10 | utils: new BitcoinCashPaymentsUtils(config), 11 | }) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/erc20/KeyPairErc20Payments.ts: -------------------------------------------------------------------------------- 1 | import { KeyPairEthereumPayments } from '..' 2 | import { KeyPairErc20PaymentsConfig } from '../types' 3 | import { BaseErc20Payments } from './BaseErc20Payments' 4 | import { applyMixins } from './mixins' 5 | 6 | export class KeyPairErc20Payments {// } extends BaseErc20Payments { 7 | // constructor(config: KeyPairErc20PaymentsConfig) { 8 | // super(config) 9 | // } 10 | } 11 | applyMixins(KeyPairErc20Payments, [BaseErc20Payments, KeyPairEthereumPayments]); 12 | 13 | export default KeyPairErc20Payments 14 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | const base = require('@bitaccess/ts-config/library/jest.config.js') 2 | 3 | module.exports = Object.assign({}, base, { 4 | 'testRunner': 'jest-circus/runner', 5 | 'moduleFileExtensions': [ 6 | 'js', 7 | 'json', 8 | 'ts' 9 | ], 10 | 'transformIgnorePatterns': [ 11 | '/node_modules/', 12 | '/dist/', 13 | ], 14 | 'moduleNameMapper': { 15 | '^#/(.*)': '/src/$1', 16 | '^@bitaccess/coinlib-([a-z-]+)(\.ts)?$': '/../coinlib-$1/src', 17 | '^@bitaccess/coinlib-([a-z-]+)/test/utils': '/../coinlib-$1/test/utils', 18 | }, 19 | }) 20 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './BaseBitcoinCashPayments' 2 | export * from './types' 3 | export * from './constants' 4 | export * from './helpers' 5 | export * from './HdBitcoinCashPayments' 6 | export * from './UHdBitcoinCashPayments' 7 | export * from './BitcoinCashPaymentsUtils' 8 | export * from './BitcoinCashPaymentsFactory' 9 | export * from './SinglesigBitcoinCashPayments' 10 | export * from './MultisigBitcoinCashPayments' 11 | export * from './KeyPairBitcoinCashPayments' 12 | export * from './BitcoinCashBalanceMonitor' 13 | export { bitcoinish, AddressType } from '@bitaccess/coinlib-bitcoin' 14 | -------------------------------------------------------------------------------- /packages/coinlib/test/utils.test.ts: -------------------------------------------------------------------------------- 1 | import { getSeedHexFromMnemonic, getFingerprintFromSeedHex } from '../src/utils' 2 | import { MNEMONIC, SEED_HEX, FINGERPRINT } from './fixtures/utils' 3 | 4 | describe('utils', () => { 5 | describe('getSeedHexFromMnemonic', () => { 6 | it('works', () => { 7 | const seedHex = getSeedHexFromMnemonic(MNEMONIC) 8 | expect(seedHex).toBe(SEED_HEX) 9 | }) 10 | }) 11 | 12 | describe('getFingerprintFromSeedHex', () => { 13 | it('works', () => { 14 | const fingerprint = getFingerprintFromSeedHex(SEED_HEX) 15 | expect(fingerprint).toBe(FINGERPRINT) 16 | }) 17 | }) 18 | }) 19 | -------------------------------------------------------------------------------- /packages/coinlib-common/src/SharedDependencies.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * This files includes all shared dependencies across packages 3 | * Centralized dependencies can guarante the version consistency 4 | */ 5 | import { BIP32Interface as HDNode, BIP32Factory, BIP32API } from 'bip32' 6 | import { ECPairFactory, ECPairAPI } from 'ecpair' 7 | import * as ecc from 'tiny-secp256k1' 8 | import { BigNumber } from '@bitaccess/ts-common' 9 | import bs58 from 'bs58check' 10 | import * as bip39 from 'bip39' 11 | 12 | export { BigNumber } 13 | const bip32: BIP32API = BIP32Factory(ecc) 14 | const ecpair: ECPairAPI = ECPairFactory(ecc) 15 | export { bip32, HDNode, ecpair, ecc, bs58, bs58 as bs58check, bip39 } 16 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/bitcoinish/constants.ts: -------------------------------------------------------------------------------- 1 | import { FeeLevel } from '@bitaccess/coinlib-common' 2 | import { FeeLevelBlockTargets, AddressType } from './types' 3 | 4 | export const MIN_P2PKH_SWEEP_BYTES = 191 5 | 6 | export const DEFAULT_FEE_LEVEL_BLOCK_TARGETS: FeeLevelBlockTargets = { 7 | [FeeLevel.High]: 1, 8 | [FeeLevel.Medium]: 24, 9 | [FeeLevel.Low]: 144, 10 | } 11 | 12 | export const BITCOINISH_ADDRESS_PURPOSE = { 13 | [AddressType.Legacy]: '44', 14 | [AddressType.SegwitP2SH]: '49', 15 | [AddressType.SegwitNative]: '84', 16 | [AddressType.MultisigLegacy]: '87', 17 | [AddressType.MultisigSegwitNative]: '87', 18 | [AddressType.MultisigSegwitP2SH]: '87' 19 | } 20 | -------------------------------------------------------------------------------- /packages/coinlib-common/src/StandardConnectionManager.ts: -------------------------------------------------------------------------------- 1 | import { BaseConfig, PaymentsConnectionManager } from '@bitaccess/coinlib-types' 2 | 3 | export class StandardConnectionManager< 4 | Connection, 5 | Config extends { api?: Connection, server?: string | string[] | null } & BaseConfig, 6 | > implements PaymentsConnectionManager { 7 | 8 | connections: { [url: string]: Connection } = {} 9 | 10 | getConnection(connected: any) { 11 | return connected.api 12 | } 13 | 14 | getConnectionUrl(config: Config) { 15 | return config.server || null 16 | } 17 | 18 | setConnection(config: Config, connection: Connection) { 19 | config.api = connection 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/coinlib/src/index.ts: -------------------------------------------------------------------------------- 1 | import * as Tron from '@bitaccess/coinlib-tron' 2 | import * as Ripple from '@bitaccess/coinlib-ripple' 3 | import * as Stellar from '@bitaccess/coinlib-stellar' 4 | import * as Ethereum from '@bitaccess/coinlib-ethereum' 5 | import * as Bitcoin from '@bitaccess/coinlib-bitcoin' 6 | import * as Litecoin from '@bitaccess/coinlib-litecoin' 7 | import * as BitcoinCash from '@bitaccess/coinlib-bitcoin-cash' 8 | import * as Dogecoin from '@bitaccess/coinlib-doge' 9 | export { Tron, Ripple, Stellar, Ethereum, Bitcoin, Litecoin, BitcoinCash, Dogecoin } 10 | export * from './types' 11 | export * from './constants' 12 | export * from './utils' 13 | export * from './CoinPayments' 14 | export * from '@bitaccess/coinlib-common' 15 | -------------------------------------------------------------------------------- /packages/coinlib-doge/test/fixtures/multisigMainnet.ts: -------------------------------------------------------------------------------- 1 | import { AddressType } from '../../src' 2 | 3 | export const DERIVATION_PATH = "m/1234'/1'/0'" 4 | export const M = 2 5 | 6 | export const TESTNET_ADDRESSES: { [addressType: string]: { [i: number]: string } } = { 7 | [AddressType.MultisigLegacy]: { 8 | 0: '2ND2FaP69VUERphXimTjwWqtghnxHGdTujX', 9 | 1: '2N85r7PStKV3YSvZ1KVwtb673gYhFnnjHFN', 10 | 2: '2N9ck6QANBWqspwCHr8d3QxXJfxp4bBBpou', 11 | } 12 | } 13 | 14 | export const MAINNET_ADDRESSES: { [addressType: string]: { [i: number]: string } } = { 15 | [AddressType.MultisigLegacy]: { 16 | 0: '9xYuY7Y8mGA9KxBj5ZaCT7A4ox1TjsENix', 17 | 1: 'AErT8fwUALLC2suqQ5wRvELLWG8PFdfHhP', 18 | 2: 'A12xRLDj7WrkGm4wX5279JRC9XLuuJbnub', 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/coinlib-types/src/errors.ts: -------------------------------------------------------------------------------- 1 | export enum PaymentsErrorCode { 2 | TxExpired = 'PAYMENTS_TX_EXPIRED', 3 | TxSequenceTooHigh = 'PAYMENTS_TX_SEQUENCE_TOO_HIGH', 4 | TxSequenceCollision = 'PAYMENTS_TX_SEQUENCE_COLLISION', 5 | /** Sender doesn't have enough balance for the output amount + fee */ 6 | TxInsufficientBalance = 'PAYMENTS_TX_INSUFFICIENT_BALANCE', 7 | /** Fee exceeds the maximum acceptable percent relative to output amount */ 8 | TxFeeTooHigh = 'PAYMENTS_TX_FEE_TOO_HIGH', 9 | } 10 | 11 | export class PaymentsError extends Error { 12 | name = PaymentsError.name 13 | 14 | constructor(public code: PaymentsErrorCode, message?: string | Error) { 15 | super(typeof message === 'undefined' ? code : `${code} - ${message.toString()}`) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /bin/pr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | ROOT=$(dirname $0)/.. 5 | 6 | GIT_CHANGES=$(git status --porcelain) 7 | if [ "$GIT_CHANGES" ]; then 8 | echo "Working directory is not clean. Stash or commit your changes and try again." 9 | exit 1 10 | fi 11 | 12 | BRANCH=$(git branch -q --show-current) 13 | if [ "$BRANCH" = "master" ]; then 14 | echo "Cannot create pull request while on master" 15 | exit 1 16 | fi 17 | 18 | git push -u origin "$BRANCH" 19 | 20 | # Fetch master for accurate summary 21 | git fetch origin master 22 | 23 | # Summarize commits relative to origin/master 24 | SUMMARY=$(git log --pretty="- %s" $(git merge-base origin/master HEAD)..HEAD) 25 | 26 | gh pr create -r @bitaccess/coinlib-devs -t $BRANCH -b "$SUMMARY$(tail -n +6 $ROOT/pull_request_template.md)" 27 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/test/fixtures/multisigTestnet.ts: -------------------------------------------------------------------------------- 1 | import { AddressType } from '../../src' 2 | 3 | export const DERIVATION_PATH = "m/1234'/1'/0'" 4 | export const M = 2 5 | 6 | export const TESTNET_ADDRESSES: { [addressType: string]: { [i: number]: string } } = { 7 | [AddressType.MultisigLegacy]: { 8 | 0: 'bchtest:ppchx9q09qyvelcug83ek78yxrssuxtu8ynngvtw6f', // 2N3b6CkAy5CVycCVP6hf8QRVuaJk32yCGjg 9 | 1: 'bchtest:pplnyps4v5ugvf039hrw9lhghz7hwtzlhq0cx8ttmn', // 2N4qmjMk9LqzUvyYo4dwyRuSUvFHMgXGnuC 10 | 2: 'bchtest:pza3w9e2jtl99wrzttqegxa02aud6yvysu2taka26h', // 2NAJU1We7Ay74uNhEvLebLfAh7Zb3yzBHY6 11 | } 12 | } 13 | 14 | export const MAINNET_ADDRESSES: { [addressType: string]: { [i: number]: string } } = { 15 | [AddressType.MultisigLegacy]: { 16 | 0: '37oeoGUEhCHFRapFfRunCyXh7NdRfj5EKF', 17 | 1: '3Q7CPpsa6GTJ8WYMyxH1g6hxogkMCxRcvD', 18 | 2: '3AHhgV9q3SyrNPhU6wMguAnpSwxsqvaR9A', 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/test/fixtures/accounts.ts: -------------------------------------------------------------------------------- 1 | export const hdAccount = { 2 | SEED: 'parent solid gentle select carpet dolphin lunar pass half bleak siege puzzle', 3 | XPRV: 4 | 'xprv9s21ZrQH143K3AVAFiWZgcBVo4CYcuyaLwXNQvefrNjqdUF6WwpXVYrHhmGYJXD5hzuTpvvyRxCfUxEUeRkTBgj1CzsvHBdtheNnBXpuu8p', 5 | XPUB: 6 | 'xpub6DHpNsZTAkcwRCrenjwn8VHV9gc9ThM9PevD9mDzi5f5Nk28HtPxF4D1MABfYeFgnPCE3QWtbPtdVCxjPcZtjm5av4UWBFHfsKtyNChxM4Z', 7 | 8 | PRIVATE_KEYS: { 9 | 0: '4E8D35E8DE989D3B81F20FB9AFBE1CF480443CF01FCA5726836791DCCA74B192', 10 | 1: '145135510E063432E8B14608CDA8845722A822D3183C507FA38A864066C4490C', 11 | }, 12 | PUBLIC_KEYS: { 13 | 0: '026418037FEC34C86A10DB240F48A3F057E86A235276AE4CC32FDC3FCBBC589A49', 14 | 1: '030DE112C88FD2849376A33089BE658EDE917E9ADCDF4E65E4CF39D2983971349F', 15 | }, 16 | ADDRESSES: { 17 | 0: 'rsZr2habBVcxx6vEZEcFgiqoorwtqg2mcP', 18 | 1: 'rwJ3r5WDyVcLrnk5QAr2La2v8ViK6u6fw8', 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /packages/coinlib-tron/src/UHdTronPayments.ts: -------------------------------------------------------------------------------- 1 | import { HdTronPayments } from './HdTronPayments' 2 | import { UHdTronPaymentsConfig, SeedPaymentConfig } from './types' 3 | import { determineHdNode } from '@bitaccess/coinlib-common' 4 | import { omit } from 'lodash' 5 | import { UHD_PAYMENTS_CONFIG_OMIT_FIELDS } from './constants' 6 | 7 | export class UHdTronPayments extends HdTronPayments { 8 | readonly seed: string | null 9 | 10 | constructor(config: UHdTronPaymentsConfig) { 11 | let hdKey: string 12 | let seed: string | null = null 13 | if (SeedPaymentConfig.is(config)) { 14 | seed = config.seed 15 | const rootNode = determineHdNode(seed) 16 | hdKey = rootNode.toBase58() 17 | } else { 18 | hdKey = config.uniPubKey 19 | } 20 | super({ 21 | ...omit(config, UHD_PAYMENTS_CONFIG_OMIT_FIELDS), 22 | hdKey, 23 | }) 24 | this.seed = seed 25 | } 26 | } 27 | 28 | export default UHdTronPayments 29 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/src/UHdRipplePayments.ts: -------------------------------------------------------------------------------- 1 | import { omit } from 'lodash' 2 | import { UHdRipplePaymentsConfig, SeedRipplePaymentsConfig, RippleSignatory } from './types' 3 | import { determineHdNode } from '@bitaccess/coinlib-common' 4 | import { HdRipplePayments } from './HdRipplePayments' 5 | import { UHD_PAYMENTS_CONFIG_OMIT_FIELDS } from './constants' 6 | 7 | export class UHdRipplePayments extends HdRipplePayments { 8 | readonly seed: string | null 9 | 10 | constructor(config: UHdRipplePaymentsConfig) { 11 | let hdKey: string 12 | let seed: string | null = null 13 | if (SeedRipplePaymentsConfig.is(config)) { 14 | seed = config.seed 15 | const rootNode = determineHdNode(seed) 16 | hdKey = rootNode.toBase58() 17 | } else { 18 | hdKey = config.uniPubKey 19 | } 20 | super({ 21 | ...omit(config, UHD_PAYMENTS_CONFIG_OMIT_FIELDS), 22 | hdKey, 23 | }) 24 | this.seed = seed 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/test/fixtures/multisigTestnet.ts: -------------------------------------------------------------------------------- 1 | import { AddressType } from '../../src' 2 | 3 | 4 | export const DERIVATION_PATH = "m/1234'/1'/0'" 5 | export const M = 2 6 | 7 | export const ADDRESSES: { [addressType: string]: { [i: number]: string } } = { 8 | [AddressType.MultisigLegacy]: { 9 | 0: 'QWwrKm3D6JZ4kPFRioh9V7wLihBrri6hEw', 10 | 1: 'QYCXrNcPMx3a5AJqgjyzWbsv4djBdKSgWc', 11 | 2: 'QdfE8XWMC5AA3ZTHYSgcRMc8Fx2sr6Yfr5', 12 | }, 13 | [AddressType.MultisigSegwitP2SH]: { 14 | 0: 'QbUV5DubYM1VRZiMhG3cGDBUuiRt9aHHMV', 15 | 1: 'QTGpkUGtzRTuZuEGanQ2uqTi2dZzCurjd6', 16 | 2: 'QcnzawrPeFkhsBXQNoLZPYCPetESetRQso', 17 | }, 18 | [AddressType.MultisigSegwitNative]: { 19 | 0: 'tltc1qs3ym3gltz2uaw8ttrhg779w6k39x2yn5yytnttvhvkpzcxmh6vuqeswq3q', 20 | 1: 'tltc1q93kp525h5mkzhfjm74d7rpja0egnw67ntn2uc8huft6g2q7cy98qcfjgdr', 21 | 2: 'tltc1qcx5u374mjdc745q7nlscdve74szdgsz85sgxmyaszsr6nkum308qv8qhzy', 22 | }, 23 | } 24 | -------------------------------------------------------------------------------- /bin/version.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | ROOT=$(cd $(dirname $0)/..; pwd) 5 | 6 | GIT_CHANGES=$(git status --porcelain) 7 | if [ "$GIT_CHANGES" ]; then 8 | echo "Working directory is not clean. Stash or commit your changes and try again." 9 | exit 1 10 | fi 11 | 12 | git checkout master 13 | git fetch origin --tags 14 | git pull origin master 15 | 16 | CURRENT_TAG=$(git tag --points-at HEAD) 17 | if [ "$CURRENT_TAG" ]; then 18 | echo "HEAD has already been tagged as version $CURRENT_TAG" 19 | exit 1 20 | fi 21 | 22 | ./node_modules/.bin/lerna version $1 --no-push --no-git-tag-version 23 | NEW_TAG="v$($ROOT/bin/extract-version.sh $ROOT/lerna.json)" 24 | if [ "$NEW_TAG" = "$CURRENT_TAG" ]; then 25 | echo "NEW_TAG is the same as CURRENT_TAG, this shouldn't happen" 26 | exit 1 27 | fi 28 | echo "Creating rc version $LERNA_V" 29 | git checkout -b rc/$NEW_TAG 30 | git add . 31 | git commit -s -m "$NEW_TAG" 32 | git push -u origin rc/$NEW_TAG 33 | "$ROOT/bin/pr.sh" 34 | git checkout master 35 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/src/HdStellarPayments.ts: -------------------------------------------------------------------------------- 1 | import { HdStellarPaymentsConfig } from './types' 2 | import { generateMnemonic, deriveSignatory, deriveSignatoryByPath } from './bip44' 3 | import { AccountStellarPayments } from './AccountStellarPayments' 4 | 5 | export class HdStellarPayments extends AccountStellarPayments { 6 | readonly seed: string | null 7 | 8 | constructor({ seed, derivationPath, ...config }: HdStellarPaymentsConfig) { 9 | let { hotAccount, depositAccount } = config 10 | if (!hotAccount) { 11 | hotAccount = derivationPath ? deriveSignatoryByPath(seed, derivationPath, 0) : deriveSignatory(seed, 0) 12 | } 13 | if (!depositAccount) { 14 | depositAccount = derivationPath ? deriveSignatoryByPath(seed, derivationPath, 1) : deriveSignatory(seed, 1) 15 | } 16 | super({ 17 | ...config, 18 | hotAccount, 19 | depositAccount, 20 | }) 21 | this.seed = seed?.length > 0 ? seed : null 22 | } 23 | 24 | static generateMnemonic = generateMnemonic 25 | } 26 | -------------------------------------------------------------------------------- /packages/coinlib-tron/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { isMatchingError, Logger } from '@bitaccess/ts-common' 2 | import promiseRetry from 'promise-retry' 3 | 4 | /** Converts strings to Error */ 5 | export function toError(e: any): any { 6 | if (typeof e === 'string') { 7 | return new Error(e) 8 | } 9 | return e 10 | } 11 | 12 | const RETRYABLE_ERRORS = [ 13 | 'Request failed', 14 | ] 15 | const MAX_RETRIES = 2 16 | 17 | export function retryIfDisconnected(fn: () => Promise, logger: Logger): Promise { 18 | return promiseRetry( 19 | (retry, attempt) => { 20 | return fn().catch(async e => { 21 | e = toError(e) 22 | if (isMatchingError(e, RETRYABLE_ERRORS)) { 23 | logger.log( 24 | `Retryable error during tron-payments call, retrying ${MAX_RETRIES - attempt} more times`, 25 | e.toString(), 26 | ) 27 | retry(e) 28 | } 29 | throw e 30 | }) 31 | }, 32 | { 33 | retries: MAX_RETRIES, 34 | }, 35 | ) 36 | } 37 | -------------------------------------------------------------------------------- /packages/coinlib-doge/src/UHdDogePayments.ts: -------------------------------------------------------------------------------- 1 | import { omit } from 'lodash' 2 | import { assertType } from '@bitaccess/ts-common' 3 | import { UHD_PAYMENTS_CONFIG_OMIT_FIELDS } from '@bitaccess/coinlib-bitcoin' 4 | import { determineHdNode } from '@bitaccess/coinlib-common' 5 | import { HdDogePayments } from './HdDogePayments' 6 | import { SeedDogePaymentsConfig, UHdDogePaymentsConfig } from './types' 7 | 8 | 9 | export class UHdDogePayments extends HdDogePayments { 10 | readonly seed: string | null = null 11 | 12 | constructor(config: UHdDogePaymentsConfig) { 13 | assertType(UHdDogePaymentsConfig, config) 14 | let hdKey: string 15 | let seed: string | null = null 16 | if (SeedDogePaymentsConfig.is(config)) { 17 | seed = config.seed 18 | const rootNode = determineHdNode(seed) 19 | hdKey = rootNode.toBase58() 20 | } else { 21 | hdKey = config.uniPubKey 22 | } 23 | super({ 24 | ...omit(config, UHD_PAYMENTS_CONFIG_OMIT_FIELDS), 25 | hdKey, 26 | }) 27 | this.seed = seed 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/coinlib/src/constants.ts: -------------------------------------------------------------------------------- 1 | import { TronPaymentsFactory } from '@bitaccess/coinlib-tron' 2 | import { RipplePaymentsFactory } from '@bitaccess/coinlib-ripple' 3 | import { StellarPaymentsFactory } from '@bitaccess/coinlib-stellar' 4 | import { BitcoinPaymentsFactory } from '@bitaccess/coinlib-bitcoin' 5 | import { EthereumPaymentsFactory } from '@bitaccess/coinlib-ethereum' 6 | import { LitecoinPaymentsFactory } from '@bitaccess/coinlib-litecoin' 7 | import { BitcoinCashPaymentsFactory } from '@bitaccess/coinlib-bitcoin-cash' 8 | import { DogePaymentsFactory } from '@bitaccess/coinlib-doge' 9 | 10 | export { SUPPORTED_NETWORK_SYMBOLS } from '@bitaccess/coinlib-common' 11 | 12 | export const PAYMENTS_FACTORIES = { 13 | TRX: new TronPaymentsFactory(), 14 | XRP: new RipplePaymentsFactory(), 15 | XLM: new StellarPaymentsFactory(), 16 | BTC: new BitcoinPaymentsFactory(), 17 | ETH: new EthereumPaymentsFactory(), 18 | LTC: new LitecoinPaymentsFactory(), 19 | BCH: new BitcoinCashPaymentsFactory(), 20 | DOGE: new DogePaymentsFactory(), 21 | } 22 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/test/fixtures/accounts.ts: -------------------------------------------------------------------------------- 1 | export const hdAccount = { 2 | MNEMONIC: 'parent solid gentle select carpet dolphin lunar pass half bleak siege puzzle', 3 | SEED: 4 | 'cb52ea7a2e7f7c087af5842cdf4cd4e063df4e50345eeeadbf288b0c9e31c6c41dccaf34f6004ef124c2d66984ed5328532432580be7b4c4a1b44d3fb6c5563a', 5 | NEW_DERIVATION_PATH: `m/44'/148'/4'`, 6 | 7 | SECRETS: { 8 | 0: 'SBNOGRP36BCW4EPH6T6GA6PGDDBRTHW6KZMVTQRRBPZOTAVAKOTVIQM6', 9 | 1: 'SCRJMAXXCUK6I5GOEMJZCSV2NULDKH6MLGDDWVF7FZGCAYBY6V6QU5G4', 10 | }, 11 | ADDRESSES: { 12 | 0: 'GB6NPF4YDMGKDOOOIJXTDGYZGTXBF5DBENSR44QTHYT7IVEF7BYYYOCS', 13 | 1: 'GCKZUPOR6PEMW553RGEG23KNSZY6QZUU6I4LAOFGIWGI2RJWVCR5FYC7', 14 | }, 15 | NEW_SECRETS: { 16 | 0: 'SB7ONPYGQHDU6V6KQJUEYIAHHS2MHUJ4NT3ZEA462G7MTHXXV5H736IP', 17 | 1: 'SAB277VSGWFVBEDXK2JOZQZMOEA27HR65WG6SIXSOPLCMTBUAPJRMF2Q', 18 | }, 19 | NEW_ADDRESSES: { 20 | 0: 'GCQYRSJ5JXTHS6ZHADLNNL2GOSWCDOLCNTO4OYWUKEBUJE43EFFXZZGP', 21 | 1: 'GCP4ANBCOTCI2OEEOYVBT7HZHUXSR2WRF73D6OJ3QIPVPAKDHZI6IXLI', 22 | }, 23 | } 24 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/UHdBitcoinPayments.ts: -------------------------------------------------------------------------------- 1 | import { omit } from 'lodash' 2 | import { assertType } from '@bitaccess/ts-common' 3 | import { determineHdNode } from '@bitaccess/coinlib-common' 4 | import { UHdBitcoinPaymentsConfig, SeedBitcoinPaymentsConfig } from './types' 5 | import { HdBitcoinPayments } from './HdBitcoinPayments' 6 | import { UHD_PAYMENTS_CONFIG_OMIT_FIELDS } from './constants' 7 | 8 | export class UHdBitcoinPayments extends HdBitcoinPayments { 9 | readonly seed: string | null 10 | 11 | constructor(config: UHdBitcoinPaymentsConfig) { 12 | assertType(UHdBitcoinPaymentsConfig, config) 13 | let hdKey: string 14 | let seed: string | null = null 15 | if (SeedBitcoinPaymentsConfig.is(config)) { 16 | seed = config.seed 17 | const rootNode = determineHdNode(seed) 18 | hdKey = rootNode.toBase58() 19 | } else { 20 | hdKey = config.uniPubKey 21 | } 22 | super({ 23 | ...omit(config, UHD_PAYMENTS_CONFIG_OMIT_FIELDS), 24 | hdKey, 25 | }) 26 | this.seed = seed 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/src/UHdLitecoinPayments.ts: -------------------------------------------------------------------------------- 1 | import { omit } from 'lodash' 2 | import { assertType } from '@bitaccess/ts-common' 3 | import { UHD_PAYMENTS_CONFIG_OMIT_FIELDS } from '@bitaccess/coinlib-bitcoin' 4 | import { determineHdNode } from '@bitaccess/coinlib-common' 5 | import { UHdLitecoinPaymentsConfig, SeedLitecoinPaymentsConfig } from './types' 6 | import { HdLitecoinPayments } from './HdLitecoinPayments' 7 | 8 | export class UHdLitecoinPayments extends HdLitecoinPayments { 9 | readonly seed: string | null 10 | 11 | constructor(config: UHdLitecoinPaymentsConfig) { 12 | assertType(UHdLitecoinPaymentsConfig, config) 13 | let hdKey: string 14 | let seed: string | null = null 15 | if (SeedLitecoinPaymentsConfig.is(config)) { 16 | seed = config.seed 17 | const rootNode = determineHdNode(seed) 18 | hdKey = rootNode.toBase58() 19 | } else { 20 | hdKey = config.uniPubKey 21 | } 22 | super({ 23 | ...omit(config, UHD_PAYMENTS_CONFIG_OMIT_FIELDS), 24 | hdKey, 25 | }) 26 | this.seed = seed 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/EthereumConnectionManager.ts: -------------------------------------------------------------------------------- 1 | import { PaymentsConnectionManager } from '@bitaccess/coinlib-common' 2 | 3 | import { EthereumNodesConnection, EthereumPaymentsUtilsConfig } from './types' 4 | import { EthereumPaymentsUtils } from './EthereumPaymentsUtils' 5 | 6 | export class EthereumConnectionManager 7 | implements PaymentsConnectionManager { 8 | connections = {} 9 | 10 | getConnection(connected: EthereumPaymentsUtils) { 11 | return { web3: connected.web3, blockbookApi: connected.blockBookApi } 12 | } 13 | 14 | getConnectionUrl(config: EthereumPaymentsUtilsConfig) { 15 | const { fullNode, blockbookNode } = config 16 | 17 | if (fullNode && blockbookNode) { 18 | return `${fullNode}-${blockbookNode}` 19 | } 20 | 21 | return config.fullNode ?? config.blockbookNode ?? null 22 | } 23 | 24 | setConnection(config: EthereumPaymentsUtilsConfig, ethereumConnection: EthereumNodesConnection) { 25 | config.web3 = ethereumConnection.web3 26 | config.blockbookApi = ethereumConnection.blockbookApi 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/src/UHdBitcoinCashPayments.ts: -------------------------------------------------------------------------------- 1 | import { omit } from 'lodash' 2 | import { assertType } from '@bitaccess/ts-common' 3 | import { UHD_PAYMENTS_CONFIG_OMIT_FIELDS } from '@bitaccess/coinlib-bitcoin' 4 | import { determineHdNode } from '@bitaccess/coinlib-common' 5 | 6 | import { 7 | SeedBitcoinCashPaymentsConfig, 8 | UHdBitcoinCashPaymentsConfig, 9 | } from './types' 10 | import { HdBitcoinCashPayments } from './HdBitcoinCashPayments' 11 | 12 | export class UHdBitcoinCashPayments extends HdBitcoinCashPayments { 13 | readonly seed: string | null 14 | constructor(config: UHdBitcoinCashPaymentsConfig) { 15 | assertType(UHdBitcoinCashPaymentsConfig, config) 16 | let hdKey: string 17 | let seed: string | null = null 18 | if (SeedBitcoinCashPaymentsConfig.is(config)) { 19 | seed = config.seed 20 | const rootNode = determineHdNode(seed) 21 | hdKey = rootNode.toBase58() 22 | } else { 23 | hdKey = config.uniPubKey 24 | } 25 | super({ 26 | ...omit(config, UHD_PAYMENTS_CONFIG_OMIT_FIELDS), 27 | hdKey, 28 | }) 29 | this.seed = seed 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/test/fixtures/multisigTestnet.ts: -------------------------------------------------------------------------------- 1 | import { AddressType } from '../../src' 2 | import singlesigFixtures from './singlesigTestnet' 3 | 4 | export const DERIVATION_PATH = "m/1234'/1'/0'" 5 | 6 | export const ADDRESSES: { [addressType: string]: { [i: number]: string } } = { 7 | [AddressType.MultisigLegacy]: { 8 | 0: '2N3b6CkAy5CVycCVP6hf8QRVuaJk32yCGjg', 9 | 1: '2N4qmjMk9LqzUvyYo4dwyRuSUvFHMgXGnuC', 10 | 2: '2NAJU1We7Ay74uNhEvLebLfAh7Zb3yzBHY6', 11 | }, 12 | [AddressType.MultisigSegwitP2SH]: { 13 | 0: '2N87ixD3MXExQHNxK5A1bBWk3mKz4FAXYRp', 14 | 1: '2Myv4dTQeyKQpRiUDxgN1q92GtF8AFvbCPS', 15 | 2: '2N9SETvz9d9hcizmMkhJYJqkxWVncmuRxQC', 16 | }, 17 | [AddressType.MultisigSegwitNative]: { 18 | 0: 'tb1qs3ym3gltz2uaw8ttrhg779w6k39x2yn5yytnttvhvkpzcxmh6vuqxnjpwl', 19 | 1: 'tb1q93kp525h5mkzhfjm74d7rpja0egnw67ntn2uc8huft6g2q7cy98q82wfju', 20 | 2: 'tb1qcx5u374mjdc745q7nlscdve74szdgsz85sgxmyaszsr6nkum308qnyukam', 21 | }, 22 | } 23 | 24 | export const M = 2 25 | 26 | // Send all our test funds to another address we control 27 | export const EXTERNAL_ADDRESS = singlesigFixtures[AddressType.SegwitNative].addresses[0] 28 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/UHdEthereumPayments.ts: -------------------------------------------------------------------------------- 1 | import { HdEthereumPayments } from './HdEthereumPayments' 2 | import { EthereumBIP44 } from './bip44' 3 | import { UHdEthereumPaymentsConfig, SeedEthereumPaymentsConfig } from './types' 4 | import { omit } from 'lodash' 5 | import { UHD_PAYMENTS_CONFIG_OMIT_FIELDS } from './constants' 6 | 7 | export class UHdEthereumPayments extends HdEthereumPayments { 8 | readonly seed: string | null 9 | 10 | constructor(config: UHdEthereumPaymentsConfig) { 11 | let hdKey: string 12 | let seed: string | null = null 13 | if (SeedEthereumPaymentsConfig.is(config)) { 14 | seed = config.seed 15 | const bip44: EthereumBIP44 = EthereumBIP44.fromSeed(seed, config.derivationPath) 16 | const xprv: string | null = bip44.getXPrivateKey() 17 | if (!xprv) { 18 | throw new Error('Cannot derive xprv from given seed') 19 | } 20 | hdKey= xprv 21 | } else { 22 | hdKey = config.uniPubKey 23 | } 24 | super({ 25 | ...omit(config, UHD_PAYMENTS_CONFIG_OMIT_FIELDS), 26 | hdKey, 27 | }) 28 | this.seed = seed 29 | } 30 | } 31 | 32 | export default UHdEthereumPayments 33 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/helpers.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType, bip32, hexToBuff } from '@bitaccess/coinlib-common' 2 | import { ETHEREUM_COINTYPES, ETHEREUM_SUPPORTED_ADDRESS_TYPES } from './constants' 3 | 4 | export function isSupportedAddressType(addressType: string): boolean { 5 | return ETHEREUM_SUPPORTED_ADDRESS_TYPES.map(at => at.toString()).includes(addressType) 6 | } 7 | 8 | export function getSupportedAddressTypes(): string[] { 9 | return ETHEREUM_SUPPORTED_ADDRESS_TYPES 10 | } 11 | 12 | export function determinePathForIndex(accountIndex: number, addressType?: any, networkType?: NetworkType): string { 13 | const purpose: string = '44' 14 | const cointype = ETHEREUM_COINTYPES[networkType ?? NetworkType.Mainnet] 15 | const derivationPath = `m/${purpose}'/${cointype}'/${accountIndex}'` 16 | return derivationPath 17 | } 18 | 19 | export function hexSeedToBuffer(seedHex: string): Buffer { 20 | return hexToBuff(seedHex) 21 | } 22 | 23 | export function deriveUniPubKeyForPath(seed: Buffer, derivationPath: string): string { 24 | const root = bip32.fromSeed(seed) 25 | const account = root.derivePath(derivationPath) 26 | return account.neutered().toBase58() 27 | } 28 | -------------------------------------------------------------------------------- /packages/coinlib-tron/test/fixtures/accounts.ts: -------------------------------------------------------------------------------- 1 | export const hdAccount = { 2 | SEED: 'parent solid gentle select carpet dolphin lunar pass half bleak siege puzzle', 3 | XPRV: 4 | 'xprv9s21ZrQH143K3AVAFiWZgcBVo4CYcuyaLwXNQvefrNjqdUF6WwpXVYrHhmGYJXD5hzuTpvvyRxCfUxEUeRkTBgj1CzsvHBdtheNnBXpuu8p', 5 | XPUB: 6 | 'xpub6BfusYhSxkNBEVoXKgecUo69gdz3ghgpa1oHBxpB18Q8rGGQSEfPpfEGYFGg5x6sS8oRu1mMmb3PhDLekpCoLY5bSwJqDAnrq4pzFVSzH3m', 7 | 8 | PRIVATE_KEYS: { 9 | 0: 'AB30732D4BA401129C7A70BD66A9BE8583D4A979A31C026B319FBC208AF68101', 10 | 1: '1BA17E50D36BE2C8A094786684C0ABEE02325375222ABD3D588BCE3213F81D9B', 11 | 2: '00F4D4C97207AB2F875F826849BC6ACD3902B8CF26807D610D0CFA361714DDA5', 12 | }, 13 | ADDRESSES: { 14 | 0: 'TXw3bBhMwZgCvNWJG4oGB5Z96YkPLGu5ju', 15 | 1: 'TBJhvDc8pCZkbEi1iWy4RD5VHYAS94XgWg', 16 | 2: 'TTC1WfyFtswjkY4gjFmhw2QLURkGAfdEaX', 17 | 3: 'TNRP8h1vVZFTKKJReobU4fpHhSAVh2hJab', 18 | 5: 'TQmBbYtAu3GjexTRJFvQaEW2sRB5pdMcZ3', 19 | 6: 'TPZfLDAWoVBZL3EfN5C96E7JzrsRpLsN1k', 20 | 10: 'TF543gR2jUN1S2rxf68397wDCMEePnF7rQ', 21 | 10000: 'TKJFqBYXJxrvbHKqEkn2s3T9f3EAeZ5aEV', 22 | 20000: 'TLf5ZsPT3qxUAR2VZ3JZHHcHeB4xN7CRLL', 23 | }, 24 | } 25 | -------------------------------------------------------------------------------- /packages/coinlib-tron/test/bip44.test.ts: -------------------------------------------------------------------------------- 1 | import { xprvToXpub, deriveAddress, derivePrivateKey } from '../src' 2 | import { hdAccount } from './fixtures/accounts' 3 | 4 | const { XPRV, XPUB, PRIVATE_KEYS, ADDRESSES } = hdAccount 5 | 6 | describe('bip44', () => { 7 | test('xprvToXpub', () => { 8 | expect(xprvToXpub(XPRV)).toBe(XPUB) 9 | }) 10 | test('deriveAddress', () => { 11 | expect(deriveAddress(XPUB, 1)).toBe(ADDRESSES[1]) 12 | }) 13 | test('derivePrivateKey', () => { 14 | expect(derivePrivateKey(XPRV, 1)).toBe(PRIVATE_KEYS[1]) 15 | }) 16 | 17 | // This test takes a long time. It really just makes sure we don't have padding 18 | // issues in a brute force way. 19 | it.skip('generate 1000 addresses and private keys, make sure they match', async () => { 20 | const tasks = [] 21 | for (let i = 4000; i < 5000; i++) { 22 | const address = deriveAddress(XPUB, i) 23 | const privateKey = derivePrivateKey(XPRV, i) 24 | const addressFromPkey = xprvToXpub(privateKey) 25 | if (address !== addressFromPkey) { 26 | throw new Error(`key mismatch: ${address}, ${privateKey}, ${addressFromPkey}`) 27 | } 28 | } 29 | }) 30 | }) 31 | -------------------------------------------------------------------------------- /packages/coinlib/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-common/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-doge/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-tron/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-types/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/LICENCE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2022 Bitaccess Inc. http://bitaccess.co 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 13 | all 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 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/src/UHdStellarPayments.ts: -------------------------------------------------------------------------------- 1 | import { UHdStellarPaymentsConfig, SeedStellarPaymentsConfig, StellarAccountConfig } from './types' 2 | import { generateMnemonic } from './bip44' 3 | import { isValidAddress } from './helpers' 4 | import { HdStellarPayments } from './HdStellarPayments' 5 | 6 | export class UHdStellarPayments extends HdStellarPayments { 7 | constructor(config: UHdStellarPaymentsConfig) { 8 | let hotAccount: StellarAccountConfig 9 | let depositAccount: StellarAccountConfig 10 | if (SeedStellarPaymentsConfig.is(config)) { 11 | super(config) 12 | } else { 13 | const { uniPubKey, derivationPath, ...restConfig } = config 14 | const [sendingAddress, receivingAddress] = uniPubKey.split(':') 15 | if (!isValidAddress(sendingAddress) || !isValidAddress(receivingAddress)) { 16 | throw new Error(`Invalid stellar uniPubKey ${uniPubKey}`) 17 | } 18 | hotAccount = { address: sendingAddress } 19 | depositAccount = { address: receivingAddress } 20 | super({ 21 | seed: '', 22 | ...restConfig, 23 | hotAccount, 24 | depositAccount, 25 | }) 26 | } 27 | } 28 | 29 | static generateMnemonic = generateMnemonic 30 | } 31 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/src/bip44.ts: -------------------------------------------------------------------------------- 1 | import { BitcoinCashAddressFormat, BitcoinjsKeyPair } from './types' 2 | import { BitcoinjsNetwork } from '@bitaccess/coinlib-bitcoin' 3 | import { publicKeyToAddress } from './helpers' 4 | import { HDNode, NetworkType, deriveHDNode, validateHdKey, isValidXprv, isValidXpub } from '@bitaccess/coinlib-common' 5 | 6 | export { HDNode, deriveHDNode, validateHdKey, isValidXprv, isValidXpub } 7 | 8 | export function deriveKeyPair(baseNode: HDNode, index: number): BitcoinjsKeyPair { 9 | return baseNode.derive(0).derive(index) 10 | } 11 | 12 | export function deriveAddress( 13 | baseNode: HDNode, 14 | index: number, 15 | networkType: NetworkType, 16 | format: BitcoinCashAddressFormat, 17 | ): string { 18 | const keyPair = deriveKeyPair(baseNode, index) 19 | return publicKeyToAddress(keyPair.publicKey, networkType, format) 20 | } 21 | 22 | export function derivePrivateKey(baseNode: HDNode, index: number) { 23 | const keyPair = deriveKeyPair(baseNode, index) 24 | return keyPair.toWIF() 25 | } 26 | 27 | export function xprvToXpub(xprv: string, derivationPath: string, network: BitcoinjsNetwork) { 28 | const node = deriveHDNode(xprv, derivationPath, network) 29 | return node.neutered().toBase58() 30 | } 31 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/test/bip44.test.ts: -------------------------------------------------------------------------------- 1 | import { generateMnemonic, deriveSignatory, mnemonicToSeed } from '../src/bip44' 2 | 3 | import { hdAccount } from './fixtures/accounts' 4 | const { MNEMONIC, SEED, ADDRESSES, SECRETS } = hdAccount 5 | 6 | describe('bip44', () => { 7 | test('generateMnemonic', () => { 8 | expect(generateMnemonic()).toBeTruthy() 9 | }) 10 | 11 | test('deriveSignatory 0 from seed', () => { 12 | expect(deriveSignatory(SEED, 0)).toEqual({ 13 | address: ADDRESSES[0], 14 | secret: SECRETS[0], 15 | }) 16 | }) 17 | 18 | test('deriveSignatory 1 from seed', () => { 19 | expect(deriveSignatory(SEED, 1)).toEqual({ 20 | address: ADDRESSES[1], 21 | secret: SECRETS[1], 22 | }) 23 | }) 24 | 25 | test('deriveKeyPair 0 from mnemonic', () => { 26 | expect(deriveSignatory(MNEMONIC, 0)).toEqual({ 27 | address: ADDRESSES[0], 28 | secret: SECRETS[0], 29 | }) 30 | }) 31 | 32 | test('deriveKeyPair 1 from mnemonic', () => { 33 | expect(deriveSignatory(MNEMONIC, 1)).toEqual({ 34 | address: ADDRESSES[1], 35 | secret: SECRETS[1], 36 | }) 37 | }) 38 | 39 | test('mnemonicToSeed', () => { 40 | expect(mnemonicToSeed(MNEMONIC)).toBe(SEED) 41 | }) 42 | }) 43 | -------------------------------------------------------------------------------- /.gitmessage: -------------------------------------------------------------------------------- 1 | # [] () (Max 72 char) 2 | # |<---- Preferably using up to 50 chars --->|<------------------->| 3 | # Example: 4 | # [feat] (bitcoin) Add support for new address scheme 5 | 6 | # (Optional) Explain why this change is being made 7 | # |<---- Try To Limit Each Line to a Maximum Of 72 Characters ---->| 8 | 9 | # (Optional) Provide links or keys to any relevant tickets, articles or other resources 10 | # Example: Github issue #23 11 | 12 | # --- COMMIT END --- 13 | # Tag can be 14 | # feat (new feature) 15 | # fix (bug fix) 16 | # refactor (refactoring code) 17 | # style (formatting, missing semi colons, etc; no code change) 18 | # doc (changes to documentation) 19 | # test (adding or refactoring tests; no production code change) 20 | # version (version bump/new release; no production code change) 21 | # dbg (Changes in debugging code/frameworks; no production code change) 22 | # license (Edits regarding licensing; no production code change) 23 | # hack (Temporary fix to make things move forward; please avoid it) 24 | # tool (Changes to development tooling including builds/linting; no production code change) 25 | # package (Changes to package dependencies) 26 | -------------------------------------------------------------------------------- /packages/coinlib-doge/test/helpers.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | toMainDenominationString, toBaseDenominationString, isValidAddress, 3 | } from '../src' 4 | import { 5 | ADDRESS_VALID, NETWORK_TYPE, 6 | } from './fixtures' 7 | 8 | describe('helpers', () => { 9 | describe('toMainDenomination', () => { 10 | test('toMainDenomination from string', () => { 11 | expect(toMainDenominationString('123456789')).toBe('1.23456789') 12 | }) 13 | test('toMainDenomination from number', () => { 14 | expect(toMainDenominationString(123456789)).toBe('1.23456789') 15 | }) 16 | }) 17 | 18 | describe('toBaseDenomination', () => { 19 | test('from string', () => { 20 | expect(toBaseDenominationString('1.23456789')).toBe('123456789') 21 | }) 22 | test('from number', () => { 23 | expect(toBaseDenominationString(1.23456789)).toBe('123456789') 24 | }) 25 | }) 26 | 27 | describe('isValidAddress', () => { 28 | test('isValidAddress should return true for valid address', async () => { 29 | expect(isValidAddress(ADDRESS_VALID, NETWORK_TYPE)).toBe(true) 30 | }) 31 | test('isValidAddress should return false for invalid', async () => { 32 | expect(isValidAddress('fake', NETWORK_TYPE)).toBe(false) 33 | }) 34 | }) 35 | 36 | }) 37 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/erc20/UHdErc20Payments.ts: -------------------------------------------------------------------------------- 1 | import { Payport } from '@bitaccess/coinlib-common' 2 | import { omit } from 'lodash' 3 | 4 | import { UHD_PAYMENTS_CONFIG_OMIT_FIELDS } from '../constants' 5 | import { HdErc20Payments } from './HdErc20Payments' 6 | import { EthereumBIP44 } from '../bip44' 7 | import { UHdErc20PaymentsConfig, SeedErc20PaymentsConfig } from '../types' 8 | 9 | export class UHdErc20Payments extends HdErc20Payments { 10 | readonly seed: string | null 11 | 12 | constructor(config: UHdErc20PaymentsConfig) { 13 | let hdKey: string 14 | let seed: string | null = null 15 | if (SeedErc20PaymentsConfig.is(config)) { 16 | seed = config.seed 17 | const bip44: EthereumBIP44 = EthereumBIP44.fromSeed(seed, config.derivationPath) 18 | const xprv: string | null = bip44.getXPrivateKey() 19 | if (!xprv) { 20 | throw new Error('Cannot derive xprv from given seed') 21 | } 22 | hdKey= xprv 23 | } else { 24 | hdKey = config.uniPubKey 25 | } 26 | super({ 27 | tokenAddress: config.tokenAddress, 28 | ...omit(config, UHD_PAYMENTS_CONFIG_OMIT_FIELDS), 29 | hdKey, 30 | }) 31 | this.seed = seed 32 | } 33 | 34 | 35 | } 36 | 37 | export default UHdErc20Payments 38 | -------------------------------------------------------------------------------- /packages/coinlib-doge/src/bip44.ts: -------------------------------------------------------------------------------- 1 | import { BitcoinjsKeyPair } from './types' 2 | import { BitcoinjsNetwork } from '@bitaccess/coinlib-bitcoin' 3 | import { HDNode, deriveHDNode, isValidXpub, isValidXprv, validateHdKey } from '@bitaccess/coinlib-common' 4 | import { publicKeyToAddress } from './helpers' 5 | import { SINGLESIG_ADDRESS_TYPE } from './constants' 6 | 7 | export { HDNode, deriveHDNode, isValidXprv, isValidXpub, validateHdKey } 8 | 9 | export function deriveKeyPair(baseNode: HDNode, index: number, network: BitcoinjsNetwork): BitcoinjsKeyPair { 10 | return baseNode.derive(0).derive(index) 11 | } 12 | 13 | export function deriveAddress(baseNode: HDNode, index: number, network: BitcoinjsNetwork): string { 14 | const keyPair = deriveKeyPair(baseNode, index, network) 15 | return publicKeyToAddress(keyPair.publicKey, network, SINGLESIG_ADDRESS_TYPE) 16 | } 17 | 18 | export function derivePrivateKey(baseNode: HDNode, index: number, network: BitcoinjsNetwork) { 19 | const keyPair = deriveKeyPair(baseNode, index, network) 20 | return keyPair.toWIF() 21 | } 22 | 23 | export function xprvToXpub(xprv: string, derivationPath: string, network: BitcoinjsNetwork) { 24 | const node = deriveHDNode(xprv, derivationPath, network) 25 | return node.neutered().toBase58() 26 | } 27 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/src/constants.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType, FeeLevel } from '@bitaccess/coinlib-common' 2 | import { StellarCreateTransactionOptions } from './types' 3 | 4 | export const PACKAGE_NAME = 'stellar-payments' 5 | 6 | export const COIN_SYMBOL = 'XLM' 7 | export const COIN_NAME = 'Stellar' 8 | export const DECIMAL_PLACES = 7 9 | export const BASE_UNITS = 1e7 10 | export const MIN_BALANCE = 1 11 | export const DEFAULT_CREATE_TRANSACTION_OPTIONS: StellarCreateTransactionOptions = {} 12 | export const DEFAULT_TX_TIMEOUT_SECONDS = 60 * 60 13 | export const DEFAULT_FEE_LEVEL = FeeLevel.Low 14 | 15 | export const NOT_FOUND_ERRORS = ['MissingLedgerHistoryError', 'NotFoundError', 'Not Found'] 16 | 17 | export const DEFAULT_NETWORK = NetworkType.Mainnet 18 | export const DEFAULT_MAINNET_SERVER = 'https://horizon.stellar.org' 19 | export const DEFAULT_TESTNET_SERVER = 'https://horizon-testnet.stellar.org' 20 | 21 | export const PUBLIC_CONFIG_OMIT_FIELDS = ['logger', 'server', 'api', 'seed', 'depositAccount', 'hotAccount', 'hdKey'] 22 | 23 | export const STELLAR_COINTYPES = { 24 | [NetworkType.Mainnet]: '148', 25 | [NetworkType.Testnet]: '148', 26 | } 27 | 28 | export const STELLAR_SUPPORTED_ADDRESS_TYPES: string[] = [] 29 | 30 | export const STELLAR_UNIPUBKEY_REGEX = /^[0-9A-Za-z]{56}:[0-9A-Za-z]{56}$/ 31 | -------------------------------------------------------------------------------- /packages/coinlib-doge/test/fixtures/bip44.ts: -------------------------------------------------------------------------------- 1 | import { NETWORK_MAINNET } from '../../src' 2 | import { NetworkType } from '@bitaccess/coinlib-common' 3 | 4 | export const NETWORK_TYPE = NetworkType.Mainnet 5 | export const NETWORK = NETWORK_MAINNET 6 | export const DERIVATION_PATH = "m/44'/3'/0'" 7 | export const MNEMONIC = 'parent solid gentle select carpet dolphin lunar pass half bleak siege puzzle' 8 | export const ROOT_XPRV = 'xprv9s21ZrQH143K3AVAFiWZgcBVo4CYcuyaLwXNQvefrNjqdUF6WwpXVYrHhmGYJXD5hzuTpvvyRxCfUxEUeRkTBgj1CzsvHBdtheNnBXpuu8p' 9 | 10 | /** ROOT_XPRV derived to m/44' */ 11 | export const PARTIALLY_DERIVED_XPRV = 'xprv9v7wn2VmtqCdLLAnGnAM2WYig5DSfRDs4qQj7NmmsRsHbLnYy6kLEr2WTYK3rb1sANpZSwG7WbxXaoBjwUD64LteLgFDQtmNNsWcdqbCKgZ' 12 | 13 | /** ROOT_XPRV derived to DERIVATION_PATH */ 14 | export const DERIVED_XPRV = 'xprv9z6PcB7K7hYFdyDJ69Xzoxs5kZ2ujB7y2E3QpF8dbbgZWcv6fo8XfbtWzQ9WFN8uzfcwYKhKKRFgN3fEicwu2TC1nLFCoFgKiHAsE8PGAmL' 15 | 16 | /** XPUB of DERIVED_XPRV */ 17 | export const DERIVED_XPUB = 'xpub6D5k1geCx56YrTHmCB51B6opJasQ8dqpPSy1cdYF9wDYPRFFDLSnDQCzqfXEHSYsCS4LJerruc5Rdd5uL8gPEkHu4UxCVtoa7xjgzWhRgkf' 18 | 19 | // All of the following are derived from m/44'/3'/0'/0/2 20 | export const PRIVATE_KEY = 'QRaq8CwiNvLzYSXJjbWqd3CCpiML2J5VeAPMeozPixbG5QNDpYi1' 21 | export const ADDRESS_VALID = 'DRizV6jMk714avw1xcAxNGwwZsRnNfuRuY' 22 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/bip44.ts: -------------------------------------------------------------------------------- 1 | import { SinglesigAddressType, BitcoinjsKeyPair } from './types' 2 | import { BitcoinjsNetwork, bip32MagicNumberToPrefix } from './bitcoinish' 3 | import { publicKeyToAddress } from './helpers' 4 | import { deriveHDNode, HDNode, validateHdKey, isValidXprv, isValidXpub } from '@bitaccess/coinlib-common' 5 | 6 | export { bip32MagicNumberToPrefix, HDNode, deriveHDNode, isValidXprv, isValidXpub, validateHdKey } 7 | 8 | export function deriveKeyPair(baseNode: HDNode, index: number, network: BitcoinjsNetwork): BitcoinjsKeyPair { 9 | return baseNode.derive(0).derive(index) 10 | } 11 | 12 | export function deriveAddress( 13 | baseNode: HDNode, 14 | index: number, 15 | network: BitcoinjsNetwork, 16 | addressType: SinglesigAddressType, 17 | ): string { 18 | const keyPair = deriveKeyPair(baseNode, index, network) 19 | return publicKeyToAddress(keyPair.publicKey, network, addressType) 20 | } 21 | 22 | export function derivePrivateKey(baseNode: HDNode, index: number, network: BitcoinjsNetwork) { 23 | const keyPair = deriveKeyPair(baseNode, index, network) 24 | return keyPair.toWIF() 25 | } 26 | 27 | export function xprvToXpub(xprv: string, derivationPath: string, network: BitcoinjsNetwork) { 28 | const node = deriveHDNode(xprv, derivationPath, network) 29 | return node.neutered().toBase58() 30 | } 31 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/test/bip44.test.ts: -------------------------------------------------------------------------------- 1 | import { RippleAPI } from 'ripple-lib' 2 | 3 | import { publicKeyToAddress, xprvToXpub, deriveSignatory } from '../src/bip44' 4 | import { hdAccount } from './fixtures/accounts' 5 | 6 | const { XPRV, XPUB, PRIVATE_KEYS, PUBLIC_KEYS, ADDRESSES } = hdAccount 7 | 8 | describe('bip44', () => { 9 | test('publicKeyToAddress is correct', () => { 10 | expect(publicKeyToAddress('ED9434799226374926EDA3B54B1B461B4ABF7237962EAE18528FEA67595397FA32')).toBe( 11 | 'rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN', 12 | ) 13 | }) 14 | 15 | test('xprvToXpub', () => { 16 | expect(xprvToXpub(XPRV)).toBe(XPUB) 17 | }) 18 | 19 | test('ripple api address derivation consistent with fixtures', () => { 20 | expect(new RippleAPI().deriveAddress(PUBLIC_KEYS[0])).toBe(ADDRESSES[0]) 21 | }) 22 | 23 | test('deriveKeyPair 0 from xprv', () => { 24 | expect(deriveSignatory(XPRV, 0)).toEqual({ 25 | address: ADDRESSES[0], 26 | secret: { 27 | privateKey: PRIVATE_KEYS[0], 28 | publicKey: PUBLIC_KEYS[0], 29 | }, 30 | }) 31 | }) 32 | 33 | test('deriveKeyPair 0 from xpub', () => { 34 | expect(deriveSignatory(XPUB, 0)).toEqual({ 35 | address: ADDRESSES[0], 36 | secret: { 37 | privateKey: '', 38 | publicKey: PUBLIC_KEYS[0], 39 | }, 40 | }) 41 | }) 42 | }) 43 | -------------------------------------------------------------------------------- /packages/coinlib-doge/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { UtxoInfo } from '@bitaccess/coinlib-common' 2 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 3 | import { toBaseDenominationNumber } from '../src' 4 | 5 | export * from '../../../common/testUtils' 6 | 7 | export function makeUtxos(confirmedValues: string[], unconfirmedValues: string[] = []): UtxoInfo[] { 8 | return [ 9 | ...confirmedValues.map((value, i) => ({ 10 | txid: `utxo-confirmed-${i}`, 11 | vout: i, 12 | value: value, 13 | satoshis: toBaseDenominationNumber(value), 14 | confirmations: 10, 15 | height: '1234', 16 | })), 17 | ...unconfirmedValues.map((value, i) => ({ 18 | txid: `utxo-unconfirmed-${i}`, 19 | vout: i, 20 | value: value, 21 | satoshis: toBaseDenominationNumber(value), 22 | })) 23 | ] 24 | } 25 | 26 | export function makeOutputs(address: string, ...values: string[]): bitcoinish.BitcoinishTxOutput[] { 27 | return values.map((value) => ({ 28 | address, 29 | value: String(value), 30 | })) 31 | } 32 | 33 | export function sortUtxosByTxid(utxos: UtxoInfo[]): UtxoInfo[] { 34 | return [...utxos].sort((a, b) => a.txid.localeCompare(b.txid)) 35 | } 36 | 37 | export function expectUtxosEqual(expectedUtxos: UtxoInfo[], actualUtxos: UtxoInfo[]) { 38 | expect(sortUtxosByTxid(expectedUtxos)).toEqual(sortUtxosByTxid(actualUtxos)) 39 | } 40 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/src/bip44.ts: -------------------------------------------------------------------------------- 1 | import { StellarSignatory } from './types' 2 | import { deriveKeyPairForAnyPath, removeTrailingSlash } from './helpers' 3 | import StellarHDWallet from 'stellar-hd-wallet' 4 | import { bip39 } from '@bitaccess/coinlib-common' 5 | 6 | export function deriveSignatory(seed: string, index: number): StellarSignatory { 7 | const wallet = seed.includes(' ') ? StellarHDWallet.fromMnemonic(seed) : StellarHDWallet.fromSeed(seed) 8 | const keypair = wallet.getKeypair(index) 9 | const secret = keypair.secret() 10 | const address = keypair.publicKey() 11 | return { 12 | address, 13 | secret, 14 | } 15 | } 16 | 17 | export function deriveSignatoryByPath(seed: string, derivationPath: string, index: number): StellarSignatory { 18 | const wallet = seed.includes(' ') ? StellarHDWallet.fromMnemonic(seed) : StellarHDWallet.fromSeed(seed) 19 | const fullPath = `${removeTrailingSlash(derivationPath)}/${index}'` 20 | const keypair = deriveKeyPairForAnyPath(wallet, fullPath) 21 | const secret = keypair.secret() 22 | const address = keypair.publicKey() 23 | return { 24 | address, 25 | secret, 26 | } 27 | } 28 | 29 | export function generateMnemonic(): string { 30 | return StellarHDWallet.generateMnemonic() 31 | } 32 | 33 | export function mnemonicToSeed(mnemonic: string): string { 34 | return bip39.mnemonicToSeedSync(mnemonic).toString('hex') 35 | } 36 | -------------------------------------------------------------------------------- /packages/coinlib-common/test/HdKeyUtils.test.ts: -------------------------------------------------------------------------------- 1 | import { deriveHDNode } from '@bitaccess/coinlib-common'; 2 | import { splitDerivationPath } from '../src/HdKeyUtils' 3 | 4 | 5 | describe('HdKeyUtils', () => { 6 | 7 | describe('splitDerivationPath', () => { 8 | it('returns correct value', () => { 9 | const derivationPath = "m/44'/1337'/1'" 10 | expect(splitDerivationPath(derivationPath)).toEqual(["44'", "1337'", "1'"]) 11 | }) 12 | }) 13 | describe('deriveHDNode', () => { 14 | it('does nothing if path depth matches xpub depth', () => { 15 | const pathWithDepth5 = "m/44'/60'/0'/0/0" 16 | const xpubWithDepth5 = 'xpub6G7izREAqiUx62vvYbecBHWZVg99BDx3YtPq37BGCHrWt1EzrDsxd6fZUyZo2SjyXybknctAU7uh13RPWFfabBnsGGwV5danYtWTxxynsXi' 17 | expect(deriveHDNode( 18 | xpubWithDepth5, 19 | pathWithDepth5, 20 | ).toBase58()).toBe(xpubWithDepth5) 21 | }) 22 | it('throws error if deriving to path shallower than key depth', () => { 23 | const pathWithDepth4 = "m/44'/60'/0'/0" 24 | const xpubWithDepth5 = 'xpub6G7izREAqiUx62vvYbecBHWZVg99BDx3YtPq37BGCHrWt1EzrDsxd6fZUyZo2SjyXybknctAU7uh13RPWFfabBnsGGwV5danYtWTxxynsXi' 25 | expect(() => deriveHDNode( 26 | xpubWithDepth5, 27 | pathWithDepth4, 28 | )).toThrow(`Cannot deriveHDNode to path ${pathWithDepth4} because hdKey depth (5) is already deeper`) 29 | }) 30 | }) 31 | }) 32 | -------------------------------------------------------------------------------- /packages/coinlib-tron/src/constants.ts: -------------------------------------------------------------------------------- 1 | import { FeeLevel, NetworkType } from '@bitaccess/coinlib-common' 2 | 3 | export const PACKAGE_NAME = 'tron-payments' 4 | export const COIN_SYMBOL = 'TRX' 5 | export const COIN_NAME = 'Tron' 6 | export const DECIMAL_PLACES = 6 7 | 8 | // Note: Tron doesn't actually have a minimum balance, but 0.1 trx could be burned when sending to 9 | // a new address so we need to keep at least this much around to cover those cases. 10 | export const MIN_BALANCE_SUN = 100000 11 | export const MIN_BALANCE_TRX = 0.1 12 | 13 | export const DEFAULT_FULL_NODE = process.env.TRX_FULL_NODE_URL || 'https://api.trongrid.io' 14 | export const DEFAULT_SOLIDITY_NODE = process.env.TRX_SOLIDITY_NODE_URL || 'https://api.trongrid.io' 15 | export const DEFAULT_EVENT_SERVER = process.env.TRX_EVENT_SERVER_URL || 'https://api.trongrid.io' 16 | export const DEFAULT_FEE_LEVEL = FeeLevel.Medium 17 | 18 | export const TX_EXPIRATION_EXTENSION_SECONDS = 59 * 60 // + 1 = 60 mins 19 | 20 | /** Milliseconds to wait past tx expiration before recognizing it as expired. */ 21 | export const EXPIRATION_FUDGE_MS = 10 * 1000 22 | 23 | export const PUBLIC_CONFIG_OMIT_FIELDS = ['logger', 'fullNode', 'solidityNode', 'eventServer', 'hdKey', 'keyPairs'] 24 | export const UHD_PAYMENTS_CONFIG_OMIT_FIELDS = ['seed', 'uniPubKey'] 25 | 26 | export const TRON_COINTYPES = { 27 | [NetworkType.Mainnet]: '195', 28 | [NetworkType.Testnet]: '195', 29 | } 30 | 31 | export const TRON_SUPPORTED_ADDRESS_TYPES: string[] = [] 32 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/test/fixtures/bip44.ts: -------------------------------------------------------------------------------- 1 | import { NETWORK_MAINNET } from '../../src' 2 | import { NetworkType } from '@bitaccess/coinlib-common' 3 | 4 | export const NETWORK_TYPE = NetworkType.Mainnet 5 | export const NETWORK = NETWORK_MAINNET 6 | export const DERIVATION_PATH = "m/44'/145'/0'" 7 | export const MNEMONIC = 'parent solid gentle select carpet dolphin lunar pass half bleak siege puzzle' 8 | export const ROOT_XPRV = 'xprv9s21ZrQH143K3AVAFiWZgcBVo4CYcuyaLwXNQvefrNjqdUF6WwpXVYrHhmGYJXD5hzuTpvvyRxCfUxEUeRkTBgj1CzsvHBdtheNnBXpuu8p' 9 | 10 | /** ROOT_XPRV derived to m/44' */ 11 | export const PARTIALLY_DERIVED_XPRV = 'xprv9v7wn2VmtqCdLLAnGnAM2WYig5DSfRDs4qQj7NmmsRsHbLnYy6kLEr2WTYK3rb1sANpZSwG7WbxXaoBjwUD64LteLgFDQtmNNsWcdqbCKgZ' 12 | 13 | /** ROOT_XPRV derived to DERIVATION_PATH */ 14 | export const DERIVED_XPRV = 'xprv9zQiTo8GrLL7QdFTrE5uMHyfRHX5MnMRrYd4jLdcngW5MEofTU8e6gEj2PuifWqS9ZPyzWEm3KjMf2eMZjEpYbM6vRWeKJEfqc5MvsiRfQY' 15 | 16 | /** XPUB of DERIVED_XPRV */ 17 | export const DERIVED_XPUB = 'xpub6DQ4sJfAghtQd7KvxFcuiRvPyKMZmF5HDmYfXj3EM234E38p11SteUZCsiAzhQJ8BQzyPC93yRdkmD42MnCHSW5oUWZeHaMiJPCrApczkwD' 18 | 19 | // All of the following are derived from m/44'/145'/0'/0/2 20 | export const PRIVATE_KEY = 'L4kA1HDcMV6mfJhuXVErhJkCKHYFbQx796rrLxJ1hzZyrdshX1o8' 21 | export const ADDRESS_CASH = 'bitcoincash:qq60dskvul43sl4xgp202ccwkzc8ytk6wgl5wzlhk2' 22 | export const ADDRESS_BITPAY = 'CMHwKGSgk5NGi2ZxUwetE11aiKSMmX5L8Q' 23 | export const ADDRESS_LEGACY = '15q3kE6cs2PjotfXoCKxeVPZ6CDwrsvMR8' 24 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/bitcoinish/BlockbookConnected.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType } from '@bitaccess/coinlib-common' 2 | import { Logger, assertType, DelegateLogger } from '@bitaccess/ts-common' 3 | import { BlockbookBitcoin } from 'blockbook-client' 4 | 5 | import { BlockbookConnectedConfig, BlockbookServerAPI } from './types' 6 | import { resolveServer, retryIfDisconnected } from './utils' 7 | 8 | export abstract class BlockbookConnected { 9 | networkType: NetworkType 10 | logger: Logger 11 | api: BlockbookServerAPI 12 | server: string[] | null 13 | 14 | constructor(config: BlockbookConnectedConfig) { 15 | assertType(BlockbookConnectedConfig, config) 16 | this.networkType = config.network 17 | this.logger = new DelegateLogger(config.logger, config.packageName) 18 | const { api, server } = resolveServer(config, this.logger) 19 | this.api = api 20 | this.server = server 21 | } 22 | 23 | getApi(): BlockbookBitcoin { 24 | if (this.server === null) { 25 | throw new Error('Cannot access blockbook network when configured with null server') 26 | } 27 | return this.api 28 | } 29 | 30 | async init(): Promise { 31 | await this.api.connect() 32 | } 33 | 34 | async destroy(): Promise { 35 | await this.api.disconnect() 36 | } 37 | 38 | async _retryDced(fn: () => Promise, additionalRetryableErrors?: string[]): Promise { 39 | return retryIfDisconnected(fn, this.getApi(), this.logger, additionalRetryableErrors) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { PACKAGE_NAME } from '../src/constants' 2 | import { UtxoInfo } from '@bitaccess/coinlib-common' 3 | import { TestLogger } from '../../../common/testUtils' 4 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 5 | import { toBaseDenominationNumber } from '../src' 6 | 7 | export * from '../../../common/testUtils' 8 | export const logger = new TestLogger(PACKAGE_NAME) 9 | 10 | export function makeUtxos(confirmedValues: string[], unconfirmedValues: string[] = []): UtxoInfo[] { 11 | return [ 12 | ...confirmedValues.map((value, i) => ({ 13 | txid: `utxo-confirmed-${i}`, 14 | vout: i, 15 | value: value, 16 | satoshis: toBaseDenominationNumber(value), 17 | confirmations: 10, 18 | height: '1234', 19 | })), 20 | ...unconfirmedValues.map((value, i) => ({ 21 | txid: `utxo-unconfirmed-${i}`, 22 | vout: i, 23 | value: value, 24 | satoshis: toBaseDenominationNumber(value), 25 | })), 26 | ] 27 | } 28 | 29 | export function makeOutputs(address: string, ...values: string[]): bitcoinish.BitcoinishTxOutput[] { 30 | return values.map(value => ({ 31 | address, 32 | value: String(value), 33 | })) 34 | } 35 | 36 | export function sortUtxosByTxid(utxos: UtxoInfo[]): UtxoInfo[] { 37 | return [...utxos].sort((a, b) => a.txid.localeCompare(b.txid)) 38 | } 39 | 40 | export function expectUtxosEqual(expectedUtxos: UtxoInfo[], actualUtxos: UtxoInfo[]) { 41 | expect(sortUtxosByTxid(expectedUtxos)).toEqual(sortUtxosByTxid(actualUtxos)) 42 | } 43 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/test/utils.ts: -------------------------------------------------------------------------------- 1 | import { PACKAGE_NAME } from '../src/constants' 2 | import { UtxoInfo } from '@bitaccess/coinlib-common' 3 | import { TestLogger } from '../../../common/testUtils' 4 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 5 | import { toBaseDenominationNumber } from '../src' 6 | 7 | export * from '../../../common/testUtils' 8 | export const logger = new TestLogger(PACKAGE_NAME) 9 | 10 | export function makeUtxos(confirmedValues: string[], unconfirmedValues: string[] = []): UtxoInfo[] { 11 | return [ 12 | ...confirmedValues.map((value, i) => ({ 13 | txid: `utxo-confirmed-${i}`, 14 | vout: i, 15 | value: value, 16 | satoshis: toBaseDenominationNumber(value), 17 | confirmations: 10, 18 | height: '1234', 19 | })), 20 | ...unconfirmedValues.map((value, i) => ({ 21 | txid: `utxo-unconfirmed-${i}`, 22 | vout: i, 23 | value: value, 24 | satoshis: toBaseDenominationNumber(value), 25 | })) 26 | ] 27 | } 28 | 29 | export function makeOutputs(address: string, ...values: string[]): bitcoinish.BitcoinishTxOutput[] { 30 | return values.map((value) => ({ 31 | address, 32 | value: String(value), 33 | })) 34 | } 35 | 36 | export function sortUtxosByTxid(utxos: UtxoInfo[]): UtxoInfo[] { 37 | return [...utxos].sort((a, b) => a.txid.localeCompare(b.txid)) 38 | } 39 | 40 | export function expectUtxosEqual(expectedUtxos: UtxoInfo[], actualUtxos: UtxoInfo[]) { 41 | expect(sortUtxosByTxid(expectedUtxos)).toEqual(sortUtxosByTxid(actualUtxos)) 42 | } 43 | -------------------------------------------------------------------------------- /packages/coinlib-types/test/errors.test.ts: -------------------------------------------------------------------------------- 1 | import { PaymentsErrorCode, PaymentsError } from '../src' 2 | 3 | describe('errors', () => { 4 | describe('PaymentsError', () => { 5 | const code = PaymentsErrorCode.TxExpired 6 | const testMessage = 'test message' 7 | const basic = new PaymentsError(code) 8 | const basicMessage = new PaymentsError(code, testMessage) 9 | const cause = new Error(testMessage) 10 | const basicCause = new PaymentsError(code, cause) 11 | 12 | it('is instanceof Error', () => { 13 | expect(basic).toBeInstanceOf(Error) 14 | }) 15 | it('has name', () => { 16 | expect(basic.name).toBe('PaymentsError') 17 | }) 18 | it('has no message when not provided', () => { 19 | expect(basic.message).toBe(code) 20 | }) 21 | it('has correct message when string provided', () => { 22 | expect(basicMessage.message).toBe(`${code} - ${testMessage}`) 23 | }) 24 | it('has correct message when error provided', () => { 25 | expect(basicCause.message).toBe(`${code} - ${cause}`) 26 | }) 27 | it('returns correct string representation without message', () => { 28 | expect(basic.toString()).toBe(`PaymentsError: ${code}`) 29 | }) 30 | it('returns correct string representation with message', () => { 31 | expect(basicMessage.toString()).toBe(`PaymentsError: ${code} - ${testMessage}`) 32 | }) 33 | it('returns correct string representation with cause', () => { 34 | expect(basicCause.toString()).toBe(`PaymentsError: ${code} - ${cause}`) 35 | }) 36 | }) 37 | }) 38 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "This Nix flake creates a development shell for Coinlib that provides the 3 | required versions of dependencies such as NodeJS 14 and npm 6"; 4 | inputs = { 5 | flake-utils.url = "github:numtide/flake-utils"; 6 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 7 | # nixpkgs-nodejs-14.url = "github:nixos/nixpkgs/a71323f68d4377d12c04a5410e214495ec598d4c"; 8 | # nixpkgs-lerna-4.url = "github:nixos/nixpkgs/41cc1d5d9584103be4108c1815c350e07c807036"; 9 | }; 10 | 11 | outputs = 12 | { flake-utils 13 | , nixpkgs 14 | # , nixpkgs-nodejs-14 15 | , # nixpkgs-lerna-4, 16 | ... 17 | }: 18 | flake-utils.lib.eachDefaultSystem (system: 19 | let 20 | pkgs = nixpkgs.legacyPackages.${system}; 21 | # pkgs-nodejs-14 = nixpkgs-nodejs-14.legacyPackages.${system}; 22 | # pkgs-lerna-4 = nixpkgs-lerna-4.legacyPackages.${system}; 23 | in 24 | { 25 | devShells.default = pkgs.mkShell { 26 | packages = [ 27 | pkgs.autoconf 28 | pkgs.automake 29 | pkgs.gcc 30 | pkgs.libtool 31 | # pkgs-nodejs-14.nodejs_14 32 | # pkgs-lerna-4.nodePackages.lerna 33 | pkgs.python310 34 | ]; 35 | shellHook = '' 36 | # if .env exists, then source it 37 | if [ -f .env ]; then 38 | echo ".env file found, sourcing file" 39 | source .env 40 | else 41 | echo "========= No .env file found =========" 42 | fi 43 | ''; 44 | }; 45 | }); 46 | } 47 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/test/fixtures/bip44.ts: -------------------------------------------------------------------------------- 1 | import { NETWORK_MAINNET } from '../../src' 2 | import { NetworkType } from '@bitaccess/coinlib-common' 3 | 4 | export const NETWORK_TYPE = NetworkType.Mainnet 5 | export const NETWORK = NETWORK_MAINNET 6 | export const DERIVATION_PATH = "m/44'/2'/0'" 7 | export const MNEMONIC = 'width wide indicate decade slush hip repeat patient submit poem defense rally liberty wrap crucial' 8 | export const ROOT_XPRV = 'xprv9s21ZrQH143K4A6W8rtYYfpLg55uou88DM343N43V9fEG1miFbLT7dBKzdTi4G88HvHCB3gJLC3c6m7qW28vbL5TvZQSHCJmuBMaPBGZi1U' 9 | 10 | /** ROOT_XPRV derived to m/44' */ 11 | export const PARTIALLY_DERIVED_XPRV = 'xprv9v6MXqn85Q6T6ERxjjLmtV8qGtyY9cgr8zbjj7722o1C6ETD24s2u76uuA7tb7b6S3HYjhGaJqqjgXCepSz3KbbvbQYy69Zr69qtkXqE8kH' 12 | 13 | /** ROOT_XPRV derived to DERIVATION_PATH */ 14 | export const DERIVED_XPRV = 'xprv9xwPhx2SH3yStSGvL23TWs17X5w3rn4faD65zQy6fht8LAbGwZ4abZtDTgEtcF3pjjgB1Zi22c8aA3m3bUu7qNVnHNyK4cmAZq5A34mUiZH' 15 | 16 | /** XPUB of DERIVED_XPRV */ 17 | export const DERIVED_XPUB = 'xpub6Bvk7TZL7RXk6vMPS3aTszwr57mYGEnWwS1gnoNiE3R7CxvRV6Nq9NChJwoztJG3rwNfyi1G368cfbgjpHyTYQWHqJSMZH4Nb7x7b92oeUF' 18 | 19 | // All of the following are derived from m/44'/2'/0'/0/2 20 | export const PRIVATE_KEY = 'T8tNFyw2AcnAJDCPNZusp6KJzSczaaQrawtbWsM2foVLoYMPAPq1' 21 | export const ADDRESS_LEGACY = 'LPHRhQyZ4pfUzbT4L7NmAHU51B66QfsPQm' 22 | export const ADDRESS_SEGWIT_P2SH = 'MSdUteBz8jBva5WK9rhXytoCkstyvWRQDF' 23 | export const ADDRESS_SEGWIT_P2SH_DEPRECATED = '3LRLakn2BcLVmaER3yiCAFYoSBJXsfYwuV' 24 | export const ADDRESS_SEGWIT_NATIVE = 'ltc1q9jy2da00sx99t7euhg5f3r3ju875elyafuvkhe' 25 | -------------------------------------------------------------------------------- /packages/coinlib-types/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-types", 3 | "version": "8.0.0", 4 | "description": "Shared types used by coinlib libraries", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-types", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-types#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "common", 20 | "bitaccess" 21 | ], 22 | "author": "Dylan Seago ", 23 | "license": "MIT", 24 | "files": [ 25 | "dist/", 26 | "src/" 27 | ], 28 | "engines": { 29 | "node": ">=12.0.0" 30 | }, 31 | "publishConfig": { 32 | "access": "public" 33 | }, 34 | "scripts": { 35 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 36 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 37 | "docs": "bin/docs.sh", 38 | "prebuild": "rimraf dist && rimraf docs", 39 | "build": "bin/build.sh", 40 | "start": "rollup -c rollup.config.js -w", 41 | "test": "jest --runInBand", 42 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 43 | "version": "npm run build" 44 | }, 45 | "dependencies": { 46 | "@bitaccess/ts-common": "^1.0.2", 47 | "io-ts": "^1.10.4" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/coinlib-tron/test/helpers.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | toMainDenominationString, toBaseDenominationString, isValidXpub, isValidXprv, isValidAddress, 3 | } from '../src' 4 | import { hdAccount } from './fixtures/accounts' 5 | 6 | const { XPRV, XPUB, ADDRESSES } = hdAccount 7 | 8 | describe('helpers', () => { 9 | test('toMainDenomination from string', () => { 10 | expect(toMainDenominationString('123456789')).toBe('123.456789') 11 | }) 12 | test('toMainDenomination from number', () => { 13 | expect(toMainDenominationString(123456789)).toBe('123.456789') 14 | }) 15 | test('toBaseDenomination from string', () => { 16 | expect(toBaseDenominationString('123.456789')).toBe('123456789') 17 | }) 18 | test('toBaseDenomination from number', () => { 19 | expect(toBaseDenominationString(123.456789)).toBe('123456789') 20 | }) 21 | test('isValidXpub should return true for valid', () => { 22 | expect(isValidXpub(XPUB)).toBe(true) 23 | }) 24 | test('isValidXpub should return false for invalid', () => { 25 | expect(isValidXpub('xpat1234')).toBe(false) 26 | }) 27 | test('isValidXprv should return true for valid', () => { 28 | expect(isValidXprv(XPRV)).toBe(true) 29 | }) 30 | test('isValidXprv should return false for invalid', () => { 31 | expect(isValidXprv('xpat1234')).toBe(false) 32 | }) 33 | test('isValidAddress should return true for valid', async () => { 34 | expect(isValidAddress(ADDRESSES[0])).toBe(true) 35 | }) 36 | test('isValidAddress should return false for invalid', async () => { 37 | expect(isValidAddress('fake')).toBe(false) 38 | }) 39 | }) 40 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/test/fixtures/singlesigMainnet.ts: -------------------------------------------------------------------------------- 1 | import { AddressType } from '../../src' 2 | export default { 3 | [AddressType.Legacy]: { 4 | xpub: 'xpub6BvtsVTfEJWNuwLGduLMBYK9oBBpYmteSoayxvXMMjNMqWsbhX4xNJeTL83BLoLNZoqAdJhr86JHqEJA16ZSBfQG9cEkx3d1MyHrZSSV8X3', 5 | sweepTxSize: 192, 6 | addresses: { 7 | 0: 'Lb2JxhU6gEXZWuKSzDa8KmrbJuCq5Zp3WM', 8 | 5: 'LYo7yxSz3fYRntwSigRXfnvxSgJkMXfnrk', 9 | 6: 'LeBPwcea5y4PSD9eb4mgXQaxG9XfZgqgCb', 10 | 7: 'LgAp5DNiqb9FdTKbGZT7UF2m959iYbSQWz', 11 | 8: 'LbLsqrRe9o8edvHiPxgmbDF57CbUuXcPre', 12 | }, 13 | }, 14 | [AddressType.SegwitP2SH]: { 15 | xpub: 'xpub6CrM2pH5CVqaBb4eDGBd1c3bVVgHb9PXzJXqKqjrmyaPR8Jbv7QeCsSzH1pRVNhfdx24V9AKYD1g9ze6KhMjXoLY1qT8g1DSL4bEyEnUsiR', 16 | sweepTxSize: 133, 17 | addresses: { 18 | 0: 'MS4UPbL5FBbWtzLb4QB6SyeS96MbnpJpus', 19 | 5: 'MHrZeWbuYk9FyxNSv1xWPi1HJghQwsQZ3Z', 20 | 6: 'MWqbvRkZH1nV31ToqMHxKaB51rs97qZetK', 21 | 7: 'MViazG1Uf29ymt2X3fLrvZCziVPinyj7wg', 22 | 8: 'MCMcRqdaXXMpYmea5PRKZH2xZia7FYHV13', 23 | }, 24 | }, 25 | [AddressType.SegwitNative]: { 26 | xpub: 'xpub6CrMcKhbvSyc3ciFxZ4TYkdexCsKCA3hQVCYzn6UJHUA5GHkEzUt3w72kGrQGpXdwR4LHc5JGGoqEyq6FX3MD18oujhe4AAqXh6veaLF8XZ', 27 | sweepTxSize: 109, 28 | addresses: { 29 | 0: 'ltc1q9ek9srkxa69l8p9qdk8v2ntzs9vetxnr6xhvf4', 30 | 5: 'ltc1q46zmg3v87rr942cad3hlv5ghusz79pdtzpazzh', 31 | 6: 'ltc1qrx0dulccq3w44jr8q4m9492s2jju7vl65wdmaa', 32 | 7: 'ltc1qn2788flds3hay5w7a2cj3z9ce2p4du4vn5aedp', 33 | 8: 'ltc1qn862r8z2dkez0m8nl5zaw0t7uvq448p78m7cwr', 34 | }, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/coinlib-doge/src/SinglesigDogePayments.ts: -------------------------------------------------------------------------------- 1 | import * as bitcoin from 'bitcoinjs-lib-bigint' 2 | import { 3 | BitcoinjsKeyPair, 4 | DogeSignedTransaction, 5 | SinglesigDogePaymentsConfig, 6 | DogeUnsignedTransaction, 7 | SinglesigAddressType, 8 | } from './types' 9 | import { bitcoinish, AddressType } from '@bitaccess/coinlib-bitcoin' 10 | import { BaseDogePayments } from './BaseDogePayments' 11 | import { SINGLESIG_ADDRESS_TYPE } from './constants' 12 | 13 | export abstract class SinglesigDogePayments extends BaseDogePayments< 14 | Config 15 | > { 16 | addressType: SinglesigAddressType 17 | abstract getKeyPair(index: number): BitcoinjsKeyPair 18 | 19 | constructor(config: SinglesigDogePaymentsConfig) { 20 | super(config) 21 | this.addressType = config.addressType || SINGLESIG_ADDRESS_TYPE 22 | } 23 | 24 | getPaymentScript(index: number): bitcoin.payments.Payment { 25 | return bitcoinish.getSinglesigPaymentScript( 26 | this.bitcoinjsNetwork, 27 | this.addressType, 28 | this.getKeyPair(index).publicKey, 29 | ) 30 | } 31 | 32 | signMultisigTransaction(tx: DogeUnsignedTransaction): DogeSignedTransaction { 33 | return bitcoinish.signMultisigTransaction(tx, this) 34 | } 35 | 36 | async signTransaction(tx: DogeUnsignedTransaction): Promise { 37 | return bitcoinish.signTransaction(tx, this) 38 | } 39 | 40 | getSupportedAddressTypes(): AddressType[] { 41 | return [AddressType.Legacy] 42 | } 43 | 44 | getRequiredSignatureCounts(): { m: number; n: number; } { 45 | return { m: 1, n: 1 } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/src/HdRipplePayments.ts: -------------------------------------------------------------------------------- 1 | import { HdRipplePaymentsConfig, RippleSignatory } from './types' 2 | import { BaseRipplePayments } from './BaseRipplePayments' 3 | import { xprvToXpub, generateNewKeys, deriveSignatory } from './bip44' 4 | import { isValidXprv, isValidXpub } from './helpers' 5 | 6 | export class HdRipplePayments extends BaseRipplePayments { 7 | readonly xprv: string | null 8 | readonly xpub: string 9 | readonly hotSignatory: RippleSignatory 10 | readonly depositSignatory: RippleSignatory 11 | 12 | constructor(config: HdRipplePaymentsConfig) { 13 | super(config) 14 | if (isValidXprv(config.hdKey)) { 15 | this.xprv = config.hdKey 16 | this.xpub = xprvToXpub(this.xprv) 17 | } else if (isValidXpub(config.hdKey)) { 18 | this.xprv = null 19 | this.xpub = config.hdKey 20 | } else { 21 | throw new Error('Account must be a valid xprv or xpub') 22 | } 23 | this.hotSignatory = deriveSignatory(config.hdKey, 0) 24 | this.depositSignatory = deriveSignatory(config.hdKey, 1) 25 | } 26 | 27 | static generateNewKeys = generateNewKeys 28 | 29 | isReadOnly() { 30 | return this.xprv === null 31 | } 32 | 33 | getPublicAccountConfig() { 34 | return { 35 | hdKey: xprvToXpub(this.config.hdKey), 36 | } 37 | } 38 | 39 | getAccountIds(): string[] { 40 | return [this.xpub] 41 | } 42 | 43 | getAccountId(index: number): string { 44 | return this.xpub 45 | } 46 | 47 | getHotSignatory() { 48 | return this.hotSignatory 49 | } 50 | 51 | getDepositSignatory() { 52 | return this.depositSignatory 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/test/helper.ts: -------------------------------------------------------------------------------- 1 | import { HdStellarPayments, UHdStellarPayments } from '../src' 2 | 3 | export function commonTests( 4 | payments: HdStellarPayments | UHdStellarPayments, 5 | addresses: { [key: number]: string }, 6 | secrets: { [key: number]: string }, 7 | ) { 8 | it('should not be readonly', () => { 9 | expect(payments.isReadOnly()).toBe(false) 10 | }) 11 | it('getHotSignatory should return correct key pair', () => { 12 | const hotSignatory = payments.getHotSignatory() 13 | expect(hotSignatory.address).toBe(addresses[0]) 14 | expect(hotSignatory.secret).toEqual(secrets[0]) 15 | }) 16 | it('getDepositSignatory should return correct key pair', () => { 17 | const hotSignatory = payments.getDepositSignatory() 18 | expect(hotSignatory.address).toBe(addresses[1]) 19 | expect(hotSignatory.secret).toEqual(secrets[1]) 20 | }) 21 | it('getPublicConfig should return signatories', () => { 22 | const publicConfig = payments.getPublicConfig() 23 | expect(publicConfig).toEqual({ 24 | hotAccount: addresses[0], 25 | depositAccount: addresses[1], 26 | }) 27 | }) 28 | it('getAccountIds should return addresses', () => { 29 | expect(payments.getAccountIds()).toEqual([addresses[0], addresses[1]]) 30 | }) 31 | describe('getAccountId', () => { 32 | it('should return address 0 for index 0', () => { 33 | expect(payments.getAccountId(0)).toBe(addresses[0]) 34 | }) 35 | for (let i = 1; i < 5; i++) { 36 | it(`should return address 1 for index ${i}`, () => { 37 | expect(payments.getAccountId(i)).toBe(addresses[1]) 38 | }) 39 | } 40 | }) 41 | } 42 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/bip44.ts: -------------------------------------------------------------------------------- 1 | import { EthereumSignatory } from './types' 2 | import { pubToAddress } from 'ethereumjs-util' 3 | import { generateNewSeed, HdKeyUtils, isValidHdKey, isValidXprv, isValidXpub } from "@bitaccess/coinlib-common" 4 | 5 | import { DEFAULT_DERIVATION_PATH } from './constants' 6 | import { buffToHex } from './utils' 7 | 8 | export { isValidHdKey, isValidXprv, isValidXpub } 9 | 10 | export class EthereumBIP44 extends HdKeyUtils { 11 | static fromXKey(xkey: string, derivationPath: string = DEFAULT_DERIVATION_PATH) { 12 | return new EthereumBIP44(xkey, derivationPath) 13 | } 14 | 15 | static fromSeed(seed: string | Buffer, derivationPath: string = DEFAULT_DERIVATION_PATH) { 16 | return new EthereumBIP44(seed, derivationPath) 17 | } 18 | 19 | static generateNewKeys(derivationPath: string = DEFAULT_DERIVATION_PATH) { 20 | return new EthereumBIP44(generateNewSeed(), derivationPath) 21 | } 22 | 23 | publicKeyToAddress(pubKeyBuffer: Buffer): string { 24 | return buffToHex(pubToAddress(pubKeyBuffer, true)) 25 | } 26 | 27 | publicKeyToString(pubKeyBuffer: Buffer): string { 28 | return buffToHex(pubKeyBuffer) 29 | } 30 | 31 | privateKeyToString(privateKeyBuffer: Buffer): string { 32 | return buffToHex(privateKeyBuffer) 33 | } 34 | 35 | getSignatory(index: number): EthereumSignatory { 36 | return { 37 | address: this.getAddress(index), 38 | keys: { 39 | pub: this.getPublicKey(index), 40 | prv: this.getPrivateKey(index) ?? '', 41 | }, 42 | xkeys: { 43 | xprv: this.getXPrivateKey() ?? '', 44 | xpub: this.getXPublicKey(), 45 | }, 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /packages/coinlib-doge/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType, FeeRateType, AutoFeeLevels } from '@bitaccess/coinlib-common' 2 | import { DogeBaseConfig } from './types' 3 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 4 | import { 5 | DEFAULT_NETWORK, 6 | NETWORK_TESTNET, 7 | NETWORK_MAINNET, 8 | DEFAULT_TESTNET_SERVER, 9 | DEFAULT_MAINNET_SERVER, 10 | COIN_SYMBOL, 11 | COIN_NAME, 12 | DECIMAL_PLACES, 13 | DEFAULT_DUST_THRESHOLD, 14 | DEFAULT_NETWORK_MIN_RELAY_FEE, 15 | DEFAULT_MIN_TX_FEE, 16 | DEFAULT_FEE_LEVEL, 17 | PACKAGE_NAME, 18 | } from './constants' 19 | 20 | const DEFAULT_BITCOINISH_CONFIG = { 21 | coinSymbol: COIN_SYMBOL, 22 | coinName: COIN_NAME, 23 | coinDecimals: DECIMAL_PLACES, 24 | dustThreshold: DEFAULT_DUST_THRESHOLD, 25 | networkMinRelayFee: DEFAULT_NETWORK_MIN_RELAY_FEE, 26 | minTxFee: { 27 | feeRate: DEFAULT_MIN_TX_FEE.toString(), 28 | feeRateType: FeeRateType.BasePerWeight, 29 | }, 30 | defaultFeeLevel: DEFAULT_FEE_LEVEL as AutoFeeLevels, 31 | } 32 | 33 | export function toBitcoinishConfig(config: T): bitcoinish.BitcoinishPaymentsConfig { 34 | const configWithDefaults = { 35 | ...DEFAULT_BITCOINISH_CONFIG, 36 | ...config, 37 | network: config.network || DEFAULT_NETWORK, 38 | } 39 | const { network, server } = configWithDefaults 40 | return { 41 | ...configWithDefaults, 42 | packageName: PACKAGE_NAME, 43 | bitcoinjsNetwork: network === NetworkType.Testnet ? NETWORK_TESTNET : NETWORK_MAINNET, 44 | server: 45 | config?.api?.nodes ?? 46 | server ?? 47 | (network === NetworkType.Testnet ? DEFAULT_TESTNET_SERVER : DEFAULT_MAINNET_SERVER), 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/test/fixtures/bip44.ts: -------------------------------------------------------------------------------- 1 | import { NETWORK_MAINNET } from '../../src' 2 | import { NetworkType } from '@bitaccess/coinlib-common' 3 | 4 | export const NETWORK_TYPE = NetworkType.Mainnet 5 | export const NETWORK = NETWORK_MAINNET 6 | export const DERIVATION_PATH = "m/44'/0'/0'" 7 | export const MNEMONIC = 'parent solid gentle select carpet dolphin lunar pass half bleak siege puzzle' 8 | export const ROOT_XPRV = 'xprv9s21ZrQH143K3AVAFiWZgcBVo4CYcuyaLwXNQvefrNjqdUF6WwpXVYrHhmGYJXD5hzuTpvvyRxCfUxEUeRkTBgj1CzsvHBdtheNnBXpuu8p' 9 | 10 | /** ROOT_XPRV derived to m/44' */ 11 | export const PARTIALLY_DERIVED_XPRV = 'xprv9v7wn2VmtqCdLLAnGnAM2WYig5DSfRDs4qQj7NmmsRsHbLnYy6kLEr2WTYK3rb1sANpZSwG7WbxXaoBjwUD64LteLgFDQtmNNsWcdqbCKgZ' 12 | 13 | /** ROOT_XPRV derived to DERIVATION_PATH */ 14 | export const DERIVED_XPRV = 'xprv9xvhR1R7yi6TkvbgezfRQdxB3mMLodu3JWvxF2Xggqn9CRJjG4X8qBwGraNDamfCahFTCoGeMrDHB54ndJsqAHY3yvXVK763P2TDyr6Zuqw' 15 | 16 | /** XPUB of DERIVED_XPRV */ 17 | export const DERIVED_XPUB = 'xpub6Bv3pWx1p5ekyQg9m2CRmmtuboBqD6ctfjrZ3QwJFBK85DdsobqPNzFkhrGTU4eDmZ8abVqkFGRn8RHoQ5n56QVbopdjVUEaA4KeZyAyL7a' 18 | 19 | // All of the following are derived from m/44'/0'/0'/0/2 20 | export const PRIVATE_KEY = 'KwkUrkVNsnnPJBkY2BYUi8NXgEemCVBNRYNoD5d3cY8W9UrCJqfH' 21 | export const ADDRESS_LEGACY = '1DbGmkAU9myqs8WkeSVYMN3z7AQWT6o5Fk' 22 | export const ADDRESS_SEGWIT_P2SH = '34AqiNyJqVHwvzzuoyPbE6s3dDDqKb5sr6' 23 | export const ADDRESS_SEGWIT_NATIVE = 'bc1q3gwdz3rhj5dyz60wtc2wdvs7qwver2q6vmy4gp' 24 | export const ADDRESS_SEGWIT_NATIVE_UPPER = 'BC1Q3GWDZ3RHJ5DYZ60WTC2WDVS7QWVER2Q6VMY4GP' 25 | 26 | export const ADDRESS_BECH32M = "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y" 27 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType, FeeRateType, AutoFeeLevels } from '@bitaccess/coinlib-common' 2 | import { LitecoinBaseConfig } from './types' 3 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 4 | import { 5 | DEFAULT_NETWORK, 6 | NETWORK_TESTNET, 7 | NETWORK_MAINNET, 8 | DEFAULT_TESTNET_SERVER, 9 | DEFAULT_MAINNET_SERVER, 10 | COIN_SYMBOL, 11 | COIN_NAME, 12 | DECIMAL_PLACES, 13 | DEFAULT_DUST_THRESHOLD, 14 | DEFAULT_NETWORK_MIN_RELAY_FEE, 15 | DEFAULT_MIN_TX_FEE, 16 | DEFAULT_FEE_LEVEL, 17 | PACKAGE_NAME, 18 | } from './constants' 19 | 20 | const DEFAULT_BITCOINISH_CONFIG = { 21 | coinSymbol: COIN_SYMBOL, 22 | coinName: COIN_NAME, 23 | coinDecimals: DECIMAL_PLACES, 24 | dustThreshold: DEFAULT_DUST_THRESHOLD, 25 | networkMinRelayFee: DEFAULT_NETWORK_MIN_RELAY_FEE, 26 | minTxFee: { 27 | feeRate: DEFAULT_MIN_TX_FEE.toString(), 28 | feeRateType: FeeRateType.BasePerWeight, 29 | }, 30 | defaultFeeLevel: DEFAULT_FEE_LEVEL as AutoFeeLevels, 31 | } 32 | 33 | export function toBitcoinishConfig(config: T): bitcoinish.BitcoinishPaymentsConfig { 34 | const configWithDefaults = { 35 | ...DEFAULT_BITCOINISH_CONFIG, 36 | ...config, 37 | network: config.network || DEFAULT_NETWORK, 38 | } 39 | const { network, server } = configWithDefaults 40 | return { 41 | ...configWithDefaults, 42 | packageName: PACKAGE_NAME, 43 | bitcoinjsNetwork: network === NetworkType.Testnet ? NETWORK_TESTNET : NETWORK_MAINNET, 44 | server: 45 | config?.api?.nodes ?? 46 | server ?? 47 | (network === NetworkType.Testnet ? DEFAULT_TESTNET_SERVER : DEFAULT_MAINNET_SERVER), 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType, FeeRateType, AutoFeeLevels } from '@bitaccess/coinlib-common' 2 | import { BitcoinCashBaseConfig } from './types' 3 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 4 | import { 5 | DEFAULT_NETWORK, 6 | NETWORK_TESTNET, 7 | NETWORK_MAINNET, 8 | DEFAULT_TESTNET_SERVER, 9 | DEFAULT_MAINNET_SERVER, 10 | COIN_SYMBOL, 11 | COIN_NAME, 12 | DECIMAL_PLACES, 13 | DEFAULT_DUST_THRESHOLD, 14 | DEFAULT_NETWORK_MIN_RELAY_FEE, 15 | DEFAULT_MIN_TX_FEE, 16 | DEFAULT_FEE_LEVEL, 17 | PACKAGE_NAME, 18 | } from './constants' 19 | 20 | const DEFAULT_BITCOINISH_CONFIG = { 21 | coinSymbol: COIN_SYMBOL, 22 | coinName: COIN_NAME, 23 | coinDecimals: DECIMAL_PLACES, 24 | dustThreshold: DEFAULT_DUST_THRESHOLD, 25 | networkMinRelayFee: DEFAULT_NETWORK_MIN_RELAY_FEE, 26 | minTxFee: { 27 | feeRate: DEFAULT_MIN_TX_FEE.toString(), 28 | feeRateType: FeeRateType.BasePerWeight, 29 | }, 30 | defaultFeeLevel: DEFAULT_FEE_LEVEL as AutoFeeLevels, 31 | } 32 | 33 | export function toBitcoinishConfig(config: T): bitcoinish.BitcoinishPaymentsConfig { 34 | const configWithDefaults = { 35 | ...DEFAULT_BITCOINISH_CONFIG, 36 | ...config, 37 | network: config.network || DEFAULT_NETWORK, 38 | } 39 | const { network, server } = configWithDefaults 40 | return { 41 | ...configWithDefaults, 42 | packageName: PACKAGE_NAME, 43 | bitcoinjsNetwork: network === NetworkType.Testnet ? NETWORK_TESTNET : NETWORK_MAINNET, 44 | server: 45 | config?.api?.nodes ?? 46 | server ?? 47 | (network === NetworkType.Testnet ? DEFAULT_TESTNET_SERVER : DEFAULT_MAINNET_SERVER), 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/coinlib-tron/src/TronPaymentsFactory.ts: -------------------------------------------------------------------------------- 1 | import { PaymentsFactory } from '@bitaccess/coinlib-common' 2 | import { assertType } from '@bitaccess/ts-common' 3 | 4 | import { TronPaymentsConfig, HdTronPaymentsConfig,UHdTronPaymentsConfig, KeyPairTronPaymentsConfig, BaseTronPaymentsConfig } from './types' 5 | import { PACKAGE_NAME } from './constants' 6 | import { BaseTronPayments } from './BaseTronPayments' 7 | import { HdTronPayments } from './HdTronPayments' 8 | import { UHdTronPayments } from './UHdTronPayments' 9 | import { KeyPairTronPayments } from './KeyPairTronPayments' 10 | import { TronPaymentsUtils } from './TronPaymentsUtils' 11 | 12 | export class TronPaymentsFactory extends PaymentsFactory< 13 | BaseTronPaymentsConfig, 14 | TronPaymentsUtils, 15 | BaseTronPayments 16 | > { 17 | readonly packageName = PACKAGE_NAME 18 | 19 | newPayments(config: HdTronPaymentsConfig): HdTronPayments 20 | newPayments(config: UHdTronPaymentsConfig): UHdTronPayments 21 | newPayments(config: KeyPairTronPaymentsConfig): KeyPairTronPayments 22 | newPayments(config: TronPaymentsConfig) { 23 | if (HdTronPaymentsConfig.is(config)) { 24 | return new HdTronPayments(config) 25 | } 26 | if (UHdTronPaymentsConfig.is(config)) { 27 | return new UHdTronPayments(config) 28 | } 29 | if (KeyPairTronPaymentsConfig.is(config)) { 30 | return new KeyPairTronPayments(config) 31 | } 32 | throw new Error(`Cannot instantiate ${this.packageName} for unsupported config`) 33 | } 34 | 35 | newUtils(config: BaseTronPaymentsConfig): TronPaymentsUtils { 36 | return new TronPaymentsUtils(assertType(BaseTronPaymentsConfig, config, 'config')) 37 | } 38 | } 39 | 40 | export default TronPaymentsFactory 41 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1710146030, 9 | "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1713805509, 24 | "narHash": "sha256-YgSEan4CcrjivCNO5ZNzhg7/8ViLkZ4CB/GrGBVSudo=", 25 | "owner": "NixOS", 26 | "repo": "nixpkgs", 27 | "rev": "1e1dc66fe68972a76679644a5577828b6a7e8be4", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "NixOS", 32 | "ref": "nixpkgs-unstable", 33 | "repo": "nixpkgs", 34 | "type": "github" 35 | } 36 | }, 37 | "root": { 38 | "inputs": { 39 | "flake-utils": "flake-utils", 40 | "nixpkgs": "nixpkgs" 41 | } 42 | }, 43 | "systems": { 44 | "locked": { 45 | "lastModified": 1681028828, 46 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 47 | "owner": "nix-systems", 48 | "repo": "default", 49 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 50 | "type": "github" 51 | }, 52 | "original": { 53 | "owner": "nix-systems", 54 | "repo": "default", 55 | "type": "github" 56 | } 57 | } 58 | }, 59 | "root": "root", 60 | "version": 7 61 | } 62 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/src/SinglesigLitecoinPayments.ts: -------------------------------------------------------------------------------- 1 | import * as bitcoin from 'bitcoinjs-lib-bigint' 2 | import { 3 | LitecoinjsKeyPair, 4 | LitecoinUnsignedTransaction, 5 | LitecoinSignedTransaction, 6 | SinglesigLitecoinPaymentsConfig, 7 | SinglesigAddressType, 8 | AddressType, 9 | } from './types' 10 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 11 | import { BaseLitecoinPayments } from './BaseLitecoinPayments' 12 | import { DEFAULT_SINGLESIG_ADDRESS_TYPE } from './constants' 13 | 14 | export abstract class SinglesigLitecoinPayments< 15 | Config extends SinglesigLitecoinPaymentsConfig 16 | > extends BaseLitecoinPayments { 17 | addressType: SinglesigAddressType 18 | 19 | constructor(config: SinglesigLitecoinPaymentsConfig) { 20 | super(config) 21 | this.addressType = config.addressType || DEFAULT_SINGLESIG_ADDRESS_TYPE 22 | } 23 | 24 | abstract getKeyPair(index: number): LitecoinjsKeyPair 25 | 26 | getPaymentScript(index: number): bitcoin.payments.Payment { 27 | return bitcoinish.getSinglesigPaymentScript( 28 | this.bitcoinjsNetwork, 29 | this.addressType, 30 | this.getKeyPair(index).publicKey, 31 | ) 32 | } 33 | 34 | signMultisigTransaction(tx: LitecoinUnsignedTransaction): LitecoinSignedTransaction { 35 | return bitcoinish.signMultisigTransaction(tx, this) 36 | } 37 | 38 | async signTransaction(tx: LitecoinUnsignedTransaction): Promise { 39 | return bitcoinish.signTransaction(tx, this) 40 | } 41 | 42 | getSupportedAddressTypes(): AddressType[] { 43 | return [AddressType.Legacy, AddressType.SegwitNative, AddressType.SegwitP2SH] 44 | } 45 | 46 | getRequiredSignatureCounts(): { m: number; n: number; } { 47 | return { m: 1, n: 1 } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/test/fixtures/singlesigTestnet.ts: -------------------------------------------------------------------------------- 1 | import { AddressType } from '../../src' 2 | export default { 3 | [AddressType.Legacy]: { 4 | xpub: 'tpubDCrzzVkDPs78zng37gt74vUce2hkxLrHTBdpFkSmYBAdn6sJ3y6KhipwqU1z6pNaSiRsvrZ7srFuEKV6cVVxms3nhQaD3sBtJegZXqHwYqz', 5 | sweepTxSize: 192, 6 | addresses: { 7 | 0: 'mu1khxE9EW9vFXJybnZtbfU9p4S1cmiEFi', 8 | 1: 'n4Rk4fqGfY9HqZ41K6KNo44eG3MXA4YPMg', 9 | 2: 'mhFduWNyuHrWYwPhyGZNnuDYtPVgCshGg6', 10 | 3: 'mrv2DZTNQeqhj9rqDJvb8YqCEJ1Lqbwgd5', 11 | 4: 'n12JSAoPSsMvUrAvReGMvZeHcrxiYhvGBx', 12 | 5: 'mvTG97w8GMEt7h23NDe93oAyMr3wTMVwKS', 13 | 6: 'mmEo6fYtR8MJvSiEPwEs5tQhArfXMqKgkq', 14 | 7: 'n3TcPTNgyUQnLGi36nAZMcsLwpe2G9jZrn', 15 | 8: 'mhqCdYjjtEV3QrnsntXKsNRmJicDMSmdQg', 16 | }, 17 | }, 18 | [AddressType.SegwitP2SH]: { 19 | xpub: 'tpubDCWCSpZSKfHb9B2ufCHBfDAVpr5S7K2XFKV53knzUrLmXuwi3HjTqkd1VGfSevwWRCDoYCuvVF3UkQAx53NQysVy3Tbd1vxTwKhHqDzJhws', 20 | sweepTxSize: 133, 21 | addresses: { 22 | 0: '2N9nHkMzaH6tm1oUDL6FvgwAKvMcKfa3AeY', 23 | 5: '2MwHhRHoFNo8fMee6tFMafRQavFVnKgkm6v', 24 | 6: '2NERxBtWd5BR5AH79ZVreAqroiTPoFzuZBA', 25 | 7: '2NBfrpZpsEQmTFiivBJFA81CbqqiXBk5v6R', 26 | 8: '2NFVvCdsMWjjsqJmXJ3wBPME6WzA8kvyFmj', 27 | }, 28 | }, 29 | [AddressType.SegwitNative]: { 30 | xpub: 'tpubDDCCjNA9Xw1Fpp3xAb3yjBBCui6wZ7idJxwcgj48Z7q3yTjEpay9cc2A1bjsr344ZTNGKv5j1djvU8bgzVTwoXaAXpX8cAEYVYG1Ch7fvVu', 31 | sweepTxSize: 109, 32 | addresses: { 33 | 0: 'tb1qq9y3rxsw0r8wl9907yg3uaq5qtyqdwrxw0hezn', 34 | 5: 'tb1qma62jv65u4r5n5p6r3p2rmv44ae6purw3pej8f', 35 | 6: 'tb1qxp967rdhl5422v0400vuv94525pqzf2f7e3j0g', 36 | 7: 'tb1qmzcsklj78rltn22gqhu0yzzwfrdv97z3hs3ruu', 37 | 8: 'tb1qaqz4hycamykjndvppru2p6j3j6gfnnft9ecf8q', 38 | }, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/coinlib-common/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-common", 3 | "version": "8.0.0", 4 | "description": "Common module used by coinlib", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-common", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-common#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "common", 20 | "bitaccess" 21 | ], 22 | "author": "Dylan Seago ", 23 | "license": "MIT", 24 | "files": [ 25 | "dist/", 26 | "src/" 27 | ], 28 | "engines": { 29 | "node": ">=12.0.0" 30 | }, 31 | "publishConfig": { 32 | "access": "public" 33 | }, 34 | "scripts": { 35 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 36 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 37 | "docs": "bin/docs.sh", 38 | "prebuild": "rimraf dist && rimraf docs", 39 | "build": "bin/build.sh", 40 | "start": "rollup -c rollup.config.js -w", 41 | "test": "jest --runInBand", 42 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 43 | "version": "npm run build" 44 | }, 45 | "dependencies": { 46 | "@bitaccess/coinlib-types": "file:../coinlib-types", 47 | "@bitaccess/ts-common": "^1.0.2", 48 | "bip32": "^3.0.1", 49 | "bip39": "^3.0.4", 50 | "bs58check": "^2.1.2", 51 | "ecpair": "^2.0.1", 52 | "io-ts": "^1.10.4", 53 | "tiny-secp256k1": "^2.2.1" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /packages/coinlib-tron/test/TronPaymentsFactory.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | TronPaymentsFactory, 3 | HdTronPayments, 4 | UHdTronPayments, 5 | KeyPairTronPayments, 6 | TronPaymentsConfig, 7 | HdTronPaymentsConfig, 8 | UHdTronPaymentsConfig, 9 | KeyPairTronPaymentsConfig, 10 | TronPaymentsUtils, 11 | } from '../src' 12 | 13 | import { hdAccount } from './fixtures/accounts' 14 | 15 | const { SEED, XPRV, PRIVATE_KEYS, ADDRESSES } = hdAccount 16 | 17 | describe('TronPaymentsFactory', () => { 18 | const factory = new TronPaymentsFactory() 19 | 20 | describe('newPayments', () => { 21 | it('should instantiate HdTronPayments', () => { 22 | const config: HdTronPaymentsConfig = { 23 | hdKey: XPRV, 24 | } 25 | expect(factory.newPayments(config)).toBeInstanceOf(HdTronPayments) 26 | }) 27 | it('should instantiate UHdTronPayments', () => { 28 | const config: UHdTronPaymentsConfig = { 29 | seed: SEED, 30 | } 31 | expect(factory.newPayments(config)).toBeInstanceOf(UHdTronPayments) 32 | }) 33 | it('should instantiate KeyPairTronPayments', () => { 34 | const config: KeyPairTronPaymentsConfig = { 35 | keyPairs: [PRIVATE_KEYS[0], ADDRESSES[0]], 36 | } 37 | expect(factory.newPayments(config)).toBeInstanceOf(KeyPairTronPayments) 38 | }) 39 | it('should fail to instantiate unrecognized config', () => { 40 | expect(() => factory.newPayments({} as any)).toThrow() 41 | }) 42 | }) 43 | 44 | describe('newUtils', () => { 45 | it('should instantiate TronPaymentsUtils', () => { 46 | expect(factory.newUtils({})).toBeInstanceOf(TronPaymentsUtils) 47 | }) 48 | 49 | it('should fail to instantiate null config', () => { 50 | expect(() => factory.newUtils(null as any)).toThrow('Invalid config') 51 | }) 52 | }) 53 | }) 54 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/utils.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType, FeeRateType, AutoFeeLevels, FeeRate, FeeLevel, NetworkTypeT } from '@bitaccess/coinlib-common' 2 | import { BitcoinBaseConfig } from './types' 3 | import { BitcoinishPaymentsConfig } from './bitcoinish' 4 | import { 5 | DEFAULT_NETWORK, 6 | NETWORK_TESTNET, 7 | NETWORK_MAINNET, 8 | DEFAULT_TESTNET_SERVER, 9 | DEFAULT_MAINNET_SERVER, 10 | COIN_SYMBOL, 11 | COIN_NAME, 12 | DECIMAL_PLACES, 13 | DEFAULT_DUST_THRESHOLD, 14 | DEFAULT_NETWORK_MIN_RELAY_FEE_RATE, 15 | DEFAULT_MIN_TX_FEE_RATE, 16 | DEFAULT_FEE_LEVEL, 17 | PACKAGE_NAME, 18 | } from './constants' 19 | import { Logger } from '@bitaccess/ts-common' 20 | // import request from 'request-promise-native' 21 | 22 | const DEFAULT_BITCOINISH_CONFIG = { 23 | coinSymbol: COIN_SYMBOL, 24 | coinName: COIN_NAME, 25 | coinDecimals: DECIMAL_PLACES, 26 | dustThreshold: DEFAULT_DUST_THRESHOLD, 27 | networkMinRelayFee: DEFAULT_NETWORK_MIN_RELAY_FEE_RATE, 28 | minTxFee: { 29 | feeRate: DEFAULT_MIN_TX_FEE_RATE.toString(), 30 | feeRateType: FeeRateType.BasePerWeight, 31 | }, 32 | defaultFeeLevel: DEFAULT_FEE_LEVEL as AutoFeeLevels, 33 | } 34 | 35 | export function toBitcoinishConfig(config: T): BitcoinishPaymentsConfig { 36 | const configWithDefaults = { 37 | ...DEFAULT_BITCOINISH_CONFIG, 38 | ...config, 39 | network: config.network || DEFAULT_NETWORK, 40 | } 41 | const { network, server } = configWithDefaults 42 | return { 43 | ...configWithDefaults, 44 | packageName: PACKAGE_NAME, 45 | bitcoinjsNetwork: network === NetworkType.Testnet ? NETWORK_TESTNET : NETWORK_MAINNET, 46 | server: 47 | config?.api?.nodes ?? 48 | server ?? 49 | (network === NetworkType.Testnet ? DEFAULT_TESTNET_SERVER : DEFAULT_MAINNET_SERVER), 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/src/SinglesigBitcoinPayments.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BitcoinjsKeyPair, 3 | BitcoinUnsignedTransaction, 4 | BitcoinSignedTransaction, 5 | SinglesigBitcoinPaymentsConfig, 6 | SinglesigAddressType, 7 | AddressType, 8 | } from './types' 9 | import { getSinglesigPaymentScript } from './helpers' 10 | import { BaseBitcoinPayments } from './BaseBitcoinPayments' 11 | import { DEFAULT_SINGLESIG_ADDRESS_TYPE } from './constants' 12 | import { SinglesigBitcoinishPayments, signMultisigTransaction, signTransaction } from './bitcoinish' 13 | 14 | export abstract class SinglesigBitcoinPayments 15 | extends BaseBitcoinPayments 16 | implements SinglesigBitcoinishPayments { 17 | addressType: SinglesigAddressType 18 | 19 | constructor(config: SinglesigBitcoinPaymentsConfig) { 20 | super(config) 21 | this.addressType = config.addressType || DEFAULT_SINGLESIG_ADDRESS_TYPE 22 | } 23 | 24 | abstract getKeyPair(index: number): BitcoinjsKeyPair 25 | 26 | getPaymentScript(index: number, addressType?: SinglesigAddressType) { 27 | return getSinglesigPaymentScript( 28 | this.bitcoinjsNetwork, 29 | addressType || this.addressType, 30 | this.getKeyPair(index).publicKey, 31 | ) 32 | } 33 | 34 | signMultisigTransaction(tx: BitcoinUnsignedTransaction): BitcoinSignedTransaction { 35 | return signMultisigTransaction(tx, this) 36 | } 37 | 38 | async signTransaction(tx: BitcoinUnsignedTransaction): Promise { 39 | return signTransaction(tx, this) 40 | } 41 | 42 | getSupportedAddressTypes(): AddressType[] { 43 | return [AddressType.Legacy, AddressType.SegwitNative, AddressType.SegwitP2SH] 44 | } 45 | 46 | getRequiredSignatureCounts(): { m: number; n: number; } { 47 | return { m: 1, n: 1 } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/src/bip44.ts: -------------------------------------------------------------------------------- 1 | import { SinglesigAddressType, LitecoinjsKeyPair, LitecoinAddressFormat } from './types' 2 | import { publicKeyToAddress } from './helpers' 3 | import { 4 | NetworkType, 5 | HDNode, 6 | deriveHDNode as commonDerive, 7 | isValidXprv, 8 | isValidXpub, 9 | validateHdKey, 10 | convertXPrefixHdKeys, 11 | } from '@bitaccess/coinlib-common' 12 | import { NETWORKS } from './constants' 13 | 14 | export { HDNode, isValidXprv, isValidXpub, validateHdKey, convertXPrefixHdKeys } 15 | 16 | /** 17 | * Derive the base HDNode required for deriveKeyPair, deriveAddress, and derivePrivateKey functions 18 | * 19 | * This partially applies the derivation path starting at the already derived depth of the provided key. 20 | */ 21 | export function deriveHDNode(hdKey: string, derivationPath: string, networkType: NetworkType): HDNode { 22 | const network = NETWORKS[networkType] 23 | return commonDerive(hdKey, derivationPath, network) 24 | } 25 | 26 | export function deriveKeyPair(baseNode: HDNode, index: number): LitecoinjsKeyPair { 27 | return baseNode.derive(0).derive(index) 28 | } 29 | 30 | export function deriveAddress( 31 | baseNode: HDNode, 32 | index: number, 33 | networkType: NetworkType, 34 | addressType: SinglesigAddressType, 35 | format: LitecoinAddressFormat, 36 | ): string { 37 | const keyPair = deriveKeyPair(baseNode, index) 38 | return publicKeyToAddress(keyPair.publicKey, networkType, addressType, format) 39 | } 40 | 41 | export function derivePrivateKey(baseNode: HDNode, index: number) { 42 | const keyPair = deriveKeyPair(baseNode, index) 43 | return keyPair.toWIF() 44 | } 45 | 46 | export function xprvToXpub(xprv: string, derivationPath: string, networkType: NetworkType) { 47 | const node = deriveHDNode(xprv, derivationPath, networkType) 48 | return node.neutered().toBase58() 49 | } 50 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/test/HdStellarPayments.test.ts: -------------------------------------------------------------------------------- 1 | import { HdStellarPayments } from '../src' 2 | import { commonTests } from './helper' 3 | import { hdAccount } from './fixtures/accounts' 4 | import * as bip39 from 'bip39' 5 | 6 | const { MNEMONIC, SEED, NEW_DERIVATION_PATH, ADDRESSES, SECRETS, NEW_ADDRESSES, NEW_SECRETS } = hdAccount 7 | 8 | describe('HdStellarPayments', () => { 9 | describe('static', () => { 10 | it('generateMnemonic should return valid mnemonic', async () => { 11 | const mnemonic = HdStellarPayments.generateMnemonic() 12 | expect(bip39.validateMnemonic(mnemonic)).toBe(true) 13 | }) 14 | it('should throw on invalid seed', () => { 15 | expect(() => new HdStellarPayments({ seed: 123 as any })).toThrow() 16 | }) 17 | it('should instantiate with valid mnemonic', () => { 18 | const rp = new HdStellarPayments({ seed: MNEMONIC }) 19 | expect(rp).toBeInstanceOf(HdStellarPayments) 20 | }) 21 | it('should instantiate with valid xpub', () => { 22 | const rp = new HdStellarPayments({ seed: SEED }) 23 | expect(rp).toBeInstanceOf(HdStellarPayments) 24 | }) 25 | }) 26 | describe('mnemonic', () => { 27 | const rp = new HdStellarPayments({ seed: MNEMONIC }) 28 | commonTests(rp, ADDRESSES, SECRETS) 29 | }) 30 | describe('mnemonic with derivation path', () => { 31 | const rp = new HdStellarPayments({ seed: MNEMONIC, derivationPath: NEW_DERIVATION_PATH }) 32 | commonTests(rp, NEW_ADDRESSES, NEW_SECRETS) 33 | }) 34 | describe('seed', () => { 35 | const rp = new HdStellarPayments({ seed: SEED }) 36 | commonTests(rp, ADDRESSES, SECRETS) 37 | }) 38 | describe('seed with derivation path', () => { 39 | const rp = new HdStellarPayments({ seed: SEED, derivationPath: NEW_DERIVATION_PATH }) 40 | commonTests(rp, NEW_ADDRESSES, NEW_SECRETS) 41 | }) 42 | }) 43 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-ripple", 3 | "version": "8.0.0", 4 | "description": "Library to assist in processing ripple payments, such as deriving addresses and sweeping funds", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-ripple", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-ripple#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "ripple", 20 | "xrp", 21 | "bitaccess" 22 | ], 23 | "author": "Dylan Seago ", 24 | "license": "MIT", 25 | "files": [ 26 | "dist/", 27 | "src/" 28 | ], 29 | "engines": { 30 | "node": ">=12.0.0" 31 | }, 32 | "publishConfig": { 33 | "access": "public" 34 | }, 35 | "scripts": { 36 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 37 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 38 | "docs": "bin/docs.sh", 39 | "prebuild": "rimraf dist && rimraf docs", 40 | "build": "bin/build.sh", 41 | "start": "rollup -c rollup.config.ts -w", 42 | "test": "jest --runInBand --bail", 43 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 44 | "version": "npm run build" 45 | }, 46 | "dependencies": { 47 | "@bitaccess/coinlib-common": "file:../coinlib-common", 48 | "@bitaccess/ts-common": "^1.0.2", 49 | "base-x": "^3.0.6", 50 | "io-ts": "^1.10.4", 51 | "lodash": "^4.17.21", 52 | "promise-retry": "^1.1.1", 53 | "ripple-lib": "^1.9.0" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/src/UnitConvertersUtil.ts: -------------------------------------------------------------------------------- 1 | import { createUnitConverters } from '@bitaccess/coinlib-common' 2 | import { UnitConverters } from './types' 3 | 4 | export class UnitConvertersUtil { 5 | toMainDenominationBigNumber: UnitConverters['toMainDenominationBigNumber'] 6 | toBaseDenominationBigNumber: UnitConverters['toMainDenominationBigNumber'] 7 | toMainDenomination: UnitConverters['toMainDenominationString'] 8 | toBaseDenomination: UnitConverters['toBaseDenominationString'] 9 | 10 | toMainDenominationBigNumberNative: UnitConverters['toMainDenominationBigNumber'] 11 | toBaseDenominationBigNumberNative: UnitConverters['toMainDenominationBigNumber'] 12 | toMainDenominationNative: UnitConverters['toMainDenominationString'] 13 | toBaseDenominationNative: UnitConverters['toBaseDenominationString'] 14 | 15 | constructor(config: { coinDecimals?: number, nativeDecimals: number }) { 16 | const coinDecimals = config.coinDecimals ?? config.nativeDecimals 17 | 18 | const unitConverters = createUnitConverters(coinDecimals) 19 | this.toMainDenominationBigNumber = unitConverters.toMainDenominationBigNumber 20 | this.toBaseDenominationBigNumber = unitConverters.toBaseDenominationBigNumber 21 | this.toMainDenomination = unitConverters.toMainDenominationString 22 | this.toBaseDenomination = unitConverters.toBaseDenominationString 23 | 24 | const nativeUnitConverters = createUnitConverters(config.nativeDecimals) 25 | this.toMainDenominationBigNumberNative = nativeUnitConverters.toMainDenominationBigNumber 26 | this.toBaseDenominationBigNumberNative = nativeUnitConverters.toBaseDenominationBigNumber 27 | this.toMainDenominationNative = nativeUnitConverters.toMainDenominationString 28 | this.toBaseDenominationNative = nativeUnitConverters.toBaseDenominationString 29 | } 30 | 31 | getCustomUnitConverter(decimals: number) { 32 | return createUnitConverters(decimals) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/coinlib-tron/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-tron", 3 | "version": "8.0.0", 4 | "description": "Library to assist in processing tron payments, such as deriving addresses and sweeping funds", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-tron", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-tron#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "tron", 20 | "bip44", 21 | "trx", 22 | "bitaccess" 23 | ], 24 | "contributors": [ 25 | "Moe Adham ", 26 | "Dylan Seago " 27 | ], 28 | "license": "MIT", 29 | "files": [ 30 | "dist/", 31 | "src/" 32 | ], 33 | "engines": { 34 | "node": ">=12.0.0" 35 | }, 36 | "publishConfig": { 37 | "access": "public" 38 | }, 39 | "scripts": { 40 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 41 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 42 | "docs": "bin/docs.sh", 43 | "prebuild": "rimraf dist && rimraf docs", 44 | "build": "bin/build.sh", 45 | "start": "rollup -c rollup.config.js -w", 46 | "test": "jest --runInBand --bail", 47 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 48 | "version": "npm run build" 49 | }, 50 | "dependencies": { 51 | "@bitaccess/coinlib-common": "file:../coinlib-common", 52 | "@bitaccess/ts-common": "^1.0.2", 53 | "elliptic": "^6.4.1", 54 | "io-ts": "^1.10.4", 55 | "js-sha3": "^0.8.0", 56 | "jssha": "^2.3.1", 57 | "lodash": "^4.17.15", 58 | "promise-retry": "^1.1.1", 59 | "tronweb": "^4.0.0" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/coinlib-stellar/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-stellar", 3 | "version": "8.0.1", 4 | "description": "Library to assist in processing stellar payments, such as deriving addresses and sweeping funds", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-stellar", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-stellar#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "ripple", 20 | "xrp", 21 | "bitaccess" 22 | ], 23 | "author": "Dylan Seago ", 24 | "license": "MIT", 25 | "files": [ 26 | "dist/", 27 | "src/" 28 | ], 29 | "engines": { 30 | "node": ">=12.0.0" 31 | }, 32 | "publishConfig": { 33 | "access": "public" 34 | }, 35 | "scripts": { 36 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 37 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 38 | "docs": "bin/docs.sh", 39 | "prebuild": "rimraf dist && rimraf docs", 40 | "build": "bin/build.sh", 41 | "start": "rollup -c rollup.config.ts -w", 42 | "test": "jest --runInBand --bail", 43 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 44 | "version": "npm run build", 45 | "sandbox": "bin/ts-node.sh test/sandbox.ts" 46 | }, 47 | "dependencies": { 48 | "@bitaccess/coinlib-common": "file:../coinlib-common", 49 | "@bitaccess/ts-common": "^1.0.2", 50 | "base-x": "^3.0.6", 51 | "events": "^3.3.0", 52 | "io-ts": "^1.10.4", 53 | "lodash": "^4.17.15", 54 | "node-fetch": "^2.7.0", 55 | "promise-retry": "^1.1.1", 56 | "stellar-hd-wallet": "0.0.10", 57 | "stellar-sdk": "10.0.1" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-bitcoin", 3 | "version": "8.0.1", 4 | "description": "Library to assist in processing bitcoin payments, such as deriving addresses and sweeping funds", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-bitcoin", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-bitcoin#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "bitcoin", 20 | "segwit", 21 | "btc", 22 | "bitaccess" 23 | ], 24 | "contributors": [ 25 | "Moe Adham ", 26 | "Dylan Seago " 27 | ], 28 | "license": "MIT", 29 | "files": [ 30 | "dist/", 31 | "src/" 32 | ], 33 | "engines": { 34 | "node": ">=12.0.0" 35 | }, 36 | "publishConfig": { 37 | "access": "public" 38 | }, 39 | "scripts": { 40 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 41 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 42 | "docs": "bin/docs.sh", 43 | "prebuild": "rimraf dist && rimraf docs", 44 | "build": "bin/build.sh", 45 | "start": "rollup -c rollup.config.ts -w", 46 | "test": "jest", 47 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 48 | "version": "npm run build" 49 | }, 50 | "dependencies": { 51 | "@bitaccess/coinlib-common": "file:../coinlib-common", 52 | "@bitaccess/ts-common": "^1.0.2", 53 | "bip174-bigint": "github:bitaccess/bip174#bigint", 54 | "bitcoinjs-lib-bigint": "github:bitaccess/bitcoinjs-lib#bigintv6", 55 | "blockbook-client": "^0.7.8", 56 | "io-ts": "^1.10.4", 57 | "lodash": "^4.17.15", 58 | "node-fetch": "2.7.0", 59 | "promise-retry": "^1.1.1" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin/test/HdBitcoinPayments.test.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType } from '@bitaccess/coinlib-common' 2 | import { HdBitcoinPayments, HdBitcoinPaymentsConfig, AddressType, SinglesigAddressType } from '../src' 3 | import { accountsByAddressType } from './fixtures' 4 | import { logger } from './utils' 5 | import { runBuildPaymentTxTests, runHardcodedPublicKeyTests } from './helper' 6 | 7 | jest.setTimeout(30 * 1000) 8 | 9 | describe('HdBitcoinPayments', () => { 10 | describe('static', () => { 11 | it('should throw on invalid hdKey', () => { 12 | expect(() => new HdBitcoinPayments({ hdKey: 'invalid' })).toThrow() 13 | }) 14 | }) 15 | 16 | describe('buildPaymentTx', () => { 17 | const account = accountsByAddressType.p2wpkh 18 | const minChange = '0.01' 19 | const targetUtxoPoolSize = 4 20 | const payments = new HdBitcoinPayments({ 21 | hdKey: account.xpub, 22 | addressType: AddressType.SegwitNative, 23 | logger, 24 | minChange, 25 | targetUtxoPoolSize, 26 | }) 27 | runBuildPaymentTxTests(payments, account) 28 | }) 29 | 30 | for (const k in accountsByAddressType) { 31 | const addressType = k as SinglesigAddressType 32 | const accountFixture = accountsByAddressType[addressType] 33 | 34 | describe(addressType, () => { 35 | describe('hardcoded xpub', () => { 36 | const config: HdBitcoinPaymentsConfig = { 37 | hdKey: accountFixture.xpub, 38 | network: NetworkType.Mainnet, 39 | addressType, 40 | logger, 41 | } 42 | const payments = new HdBitcoinPayments(config) 43 | runHardcodedPublicKeyTests(payments, config, accountFixture) 44 | }) 45 | 46 | describe('hardcoded xprv', () => { 47 | const config: HdBitcoinPaymentsConfig = { 48 | hdKey: accountFixture.xprv, 49 | network: NetworkType.Mainnet, 50 | addressType, 51 | logger, 52 | } 53 | const payments = new HdBitcoinPayments(config) 54 | runHardcodedPublicKeyTests(payments, config, accountFixture) 55 | }) 56 | }) 57 | } 58 | 59 | }) 60 | -------------------------------------------------------------------------------- /packages/coinlib-doge/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-doge", 3 | "version": "8.0.1", 4 | "description": "Library to assist in processing doge payments, such as deriving addresses and sweeping funds", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-doge", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-doge#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "doge", 20 | "bitaccess" 21 | ], 22 | "contributors": [ 23 | "Moe Adham ", 24 | "Dylan Seago ", 25 | "Dan Wolfgram " 26 | ], 27 | "license": "MIT", 28 | "files": [ 29 | "dist/", 30 | "src/" 31 | ], 32 | "engines": { 33 | "node": ">=8.0.0" 34 | }, 35 | "publishConfig": { 36 | "access": "public" 37 | }, 38 | "scripts": { 39 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 40 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 41 | "docs": "bin/docs.sh", 42 | "prebuild": "rimraf dist && rimraf docs", 43 | "build": "bin/build.sh", 44 | "start": "rollup -c rollup.config.ts -w", 45 | "test": "jest --runInBand --bail", 46 | "testMultisig": "jest test/e2e.mainnet.multisig.test.ts ", 47 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 48 | "version": "npm run build" 49 | }, 50 | "dependencies": { 51 | "@bitaccess/coinlib-bitcoin": "file:../coinlib-bitcoin", 52 | "@bitaccess/coinlib-common": "file:../coinlib-common", 53 | "@bitaccess/ts-common": "^1.0.2", 54 | "bip174-bigint": "github:bitaccess/bip174#bigint", 55 | "bitcoinjs-lib-bigint": "github:bitaccess/bitcoinjs-lib#bigintv6", 56 | "io-ts": "^1.10.4", 57 | "lodash": "^4.17.21", 58 | "promise-retry": "^1.1.1" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/coinlib-bitcoin-cash/test/HdBitcoinCashPayments.test.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs' 2 | import path from 'path' 3 | import { NetworkType } from '@bitaccess/coinlib-common' 4 | import { BitcoinCashAddressFormat, HdBitcoinCashPayments, HdBitcoinCashPaymentsConfig } from '../src' 5 | 6 | import { hdAccount as accountFixture } from './fixtures' 7 | import { logger } from './utils' 8 | import { runHardcodedPublicKeyTests } from './helper' 9 | 10 | jest.setTimeout(30 * 1000) 11 | 12 | const SECRET_XPRV_FILE = 'test/keys/mainnet.key' 13 | 14 | const rootDir = path.resolve(__dirname, '..') 15 | const secretXprvFilePath = path.resolve(rootDir, SECRET_XPRV_FILE) 16 | let secretXprv = '' 17 | if (fs.existsSync(secretXprvFilePath)) { 18 | secretXprv = fs 19 | .readFileSync(secretXprvFilePath) 20 | .toString('utf8') 21 | .trim() 22 | logger.log(`Loaded ${SECRET_XPRV_FILE}. Send and sweep tests enabled.`) 23 | } else { 24 | logger.log( 25 | `File ${SECRET_XPRV_FILE} missing. Send and sweep e2e mainnet tests will be skipped. To enable them ask Dylan to share the file with you.`, 26 | ) 27 | } 28 | 29 | describe('HdBitcoinCashPayments', () => { 30 | describe('static', () => { 31 | it('should throw on invalid hdKey', () => { 32 | expect(() => new HdBitcoinCashPayments({ logger, hdKey: 'invalid' })).toThrow() 33 | }) 34 | }) 35 | 36 | describe('hardcoded xpub', () => { 37 | const config: HdBitcoinCashPaymentsConfig = { 38 | hdKey: accountFixture.xpub, 39 | network: NetworkType.Mainnet, 40 | logger, 41 | validAddressFormat: BitcoinCashAddressFormat.Cash, 42 | } 43 | const payments = new HdBitcoinCashPayments(config) 44 | 45 | runHardcodedPublicKeyTests(payments, config, accountFixture) 46 | }) 47 | 48 | describe('hardcoded xprv', () => { 49 | const config: HdBitcoinCashPaymentsConfig = { 50 | hdKey: secretXprv, 51 | network: NetworkType.Mainnet, 52 | logger, 53 | validAddressFormat: BitcoinCashAddressFormat.Cash, 54 | } 55 | const payments = new HdBitcoinCashPayments(config) 56 | 57 | runHardcodedPublicKeyTests(payments, config, accountFixture) 58 | }) 59 | }) 60 | 61 | 62 | -------------------------------------------------------------------------------- /packages/coinlib-tron/src/base58.ts: -------------------------------------------------------------------------------- 1 | // Borrowed from tronWeb 2 | // https://github.com/tronprotocol/tron-web/blob/master/src/utils/base58.js 3 | 4 | const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' 5 | const ALPHABET_MAP: { [c: string]: number } = {} 6 | 7 | for (let i = 0; i < ALPHABET.length; i++) { 8 | ALPHABET_MAP[ALPHABET.charAt(i)] = i 9 | } 10 | 11 | const BASE = 58 12 | 13 | export function encode58(buffer: Buffer | number[]) { 14 | if (buffer.length === 0) { 15 | return '' 16 | } 17 | 18 | let i 19 | let j 20 | 21 | const digits = [0] 22 | 23 | for (i = 0; i < buffer.length; i++) { 24 | for (j = 0; j < digits.length; j++) { 25 | digits[j] <<= 8 26 | } 27 | 28 | digits[0] += buffer[i] 29 | let carry = 0 30 | 31 | for (j = 0; j < digits.length; ++j) { 32 | digits[j] += carry 33 | carry = (digits[j] / BASE) | 0 34 | digits[j] %= BASE 35 | } 36 | 37 | while (carry) { 38 | digits.push(carry % BASE) 39 | carry = (carry / BASE) | 0 40 | } 41 | } 42 | 43 | for (i = 0; buffer[i] === 0 && i < buffer.length - 1; i++) { 44 | digits.push(0) 45 | } 46 | 47 | return digits 48 | .reverse() 49 | .map(digit => ALPHABET[digit]) 50 | .join('') 51 | } 52 | 53 | export function decode58(s: string): number[] { 54 | if (s.length === 0) { 55 | return [] 56 | } 57 | 58 | let i 59 | let j 60 | 61 | const bytes = [0] 62 | 63 | for (i = 0; i < s.length; i++) { 64 | const c: string = s[i] 65 | 66 | if (!(c in ALPHABET_MAP)) { 67 | throw new Error('Non-base58 character') 68 | } 69 | 70 | for (j = 0; j < bytes.length; j++) { 71 | bytes[j] *= BASE 72 | } 73 | 74 | bytes[0] += ALPHABET_MAP[c] 75 | let carry = 0 76 | 77 | for (j = 0; j < bytes.length; ++j) { 78 | bytes[j] += carry 79 | carry = bytes[j] >> 8 80 | bytes[j] &= 0xff 81 | } 82 | 83 | while (carry) { 84 | bytes.push(carry & 0xff) 85 | carry >>= 8 86 | } 87 | } 88 | 89 | for (i = 0; s[i] === '1' && i < s.length - 1; i++) { 90 | bytes.push(0) 91 | } 92 | 93 | return bytes.reverse() 94 | } 95 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/test/fixtures/TestWeb3Provider.ts: -------------------------------------------------------------------------------- 1 | import { DelegateLogger, Logger } from '@bitaccess/ts-common' 2 | import { AbstractProvider } from 'web3-core' 3 | import { JsonRpcPayload, JsonRpcResponse } from 'web3-core-helpers' 4 | import { isEqual } from 'lodash' 5 | import { Mock } from './types' 6 | 7 | export class TestWeb3Provider implements AbstractProvider { 8 | 9 | logger: Logger 10 | 11 | constructor(logger: Logger) { 12 | this.logger = new DelegateLogger(logger, this.constructor.name) 13 | } 14 | 15 | connected = true 16 | rpcId: number = 1 17 | mocks: { [index: number]: { req: JsonRpcPayload, res: JsonRpcResponse} } = {} 18 | 19 | addMock(mock: Mock) { 20 | const mockId = this.rpcId++ 21 | this.mocks[mockId] = { 22 | req: { 23 | ...mock.req, 24 | id: mockId, 25 | jsonrpc: '2.0', 26 | }, 27 | res: { 28 | ...mock.res, 29 | id: mockId, 30 | jsonrpc: '2.0', 31 | } 32 | } 33 | this.logger.log(`Added mock req for id ${mockId}`, mock.req) 34 | } 35 | 36 | send(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void { 37 | const id = payload.id as number 38 | const mock = this.mocks[id] 39 | if (!mock) { 40 | this.logger.log(`Unexpected payload without mock at ${id}`, payload) 41 | this.rpcId = id + 1 42 | return callback(new Error(`No mock at id ${id} for ${payload.method}, check logs for details`)) 43 | } 44 | const expectedRequest = mock.req 45 | if (!isEqual(payload, expectedRequest)) { 46 | this.logger.log(`Mock payload mismatch at ${id}\nexpected =`, expectedRequest, '\nactual = ', payload) 47 | return callback(new Error(`Mock payload mismatch at id ${id} for ${payload.method}, check logs for details`)) 48 | } 49 | // Add a super small delay so that event handlers can have time to be added before the send resolves 50 | setTimeout(() => callback(null, mock.res), 10) 51 | } 52 | 53 | sendAsync(payload: JsonRpcPayload, callback: (error: Error | null, result?: JsonRpcResponse) => void): void { 54 | return this.send(payload, callback) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/test/HdLitecoinPayments.test.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType } from '@bitaccess/coinlib-common' 2 | import { HdLitecoinPayments, HdLitecoinPaymentsConfig, SinglesigAddressType, LitecoinAddressFormat } from '../src' 3 | import { accountsByAddressType } from './fixtures' 4 | import { logger } from './utils' 5 | import { runHardcodedPublicKeyTests } from './helpers' 6 | 7 | jest.setTimeout(30 * 1000) 8 | 9 | const validAddressFormat = LitecoinAddressFormat.Modern 10 | 11 | describe('HdLitecoinPayments', () => { 12 | describe('static', () => { 13 | it('should throw on invalid hdKey', () => { 14 | expect(() => new HdLitecoinPayments({ hdKey: 'invalid' })).toThrow() 15 | }) 16 | it('should accept valid xprv as hdKey for testnet', () => { 17 | expect( 18 | new HdLitecoinPayments({ 19 | network: NetworkType.Testnet, 20 | hdKey: 21 | 'xprv9z7JUNTvAbwNTCJyuqz6rR9dCykBa5krATdkLD8VbXPSgxPSY3jLEqd422aDQiYW9irybEjAwusd9kb7TD7Uckjht9T6GQv7Akee6S6Mtmg', 22 | }), 23 | ) 24 | }) 25 | }) 26 | 27 | for (const k in accountsByAddressType) { 28 | const addressType = k as SinglesigAddressType 29 | const accountFixture = accountsByAddressType[addressType] 30 | 31 | describe(addressType, () => { 32 | describe('hardcoded xpub', () => { 33 | const config: HdLitecoinPaymentsConfig = { 34 | hdKey: accountFixture.xpub, 35 | network: NetworkType.Mainnet, 36 | addressType, 37 | logger, 38 | validAddressFormat, 39 | } 40 | const payments = new HdLitecoinPayments(config) 41 | 42 | runHardcodedPublicKeyTests(payments, config, accountFixture) 43 | }) 44 | 45 | describe('hardcoded xprv', () => { 46 | const config: HdLitecoinPaymentsConfig = { 47 | hdKey: accountFixture.xprv, 48 | network: NetworkType.Mainnet, 49 | addressType, 50 | logger, 51 | validAddressFormat, 52 | } 53 | const payments = new HdLitecoinPayments(config) 54 | 55 | runHardcodedPublicKeyTests(payments, config, accountFixture) 56 | }) 57 | }) 58 | } 59 | }) 60 | -------------------------------------------------------------------------------- /packages/coinlib-litecoin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-litecoin", 3 | "version": "8.0.1", 4 | "description": "Library to assist in processing litecoin payments, such as deriving addresses and sweeping funds", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-litecoin", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-litecoin#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "litecoin", 20 | "segwit", 21 | "ltc", 22 | "bitaccess" 23 | ], 24 | "contributors": [ 25 | "Moe Adham ", 26 | "Dylan Seago ", 27 | "Dan Wolfgram " 28 | ], 29 | "license": "MIT", 30 | "files": [ 31 | "dist/", 32 | "src/" 33 | ], 34 | "engines": { 35 | "node": ">=12.0.0" 36 | }, 37 | "publishConfig": { 38 | "access": "public" 39 | }, 40 | "scripts": { 41 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 42 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 43 | "docs": "bin/docs.sh", 44 | "prebuild": "rimraf dist && rimraf docs", 45 | "build": "bin/build.sh", 46 | "start": "rollup -c rollup.config.ts -w", 47 | "test": "jest --runInBand --bail", 48 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 49 | "version": "npm run build" 50 | }, 51 | "dependencies": { 52 | "@bitaccess/coinlib-bitcoin": "file:../coinlib-bitcoin", 53 | "@bitaccess/coinlib-common": "file:../coinlib-common", 54 | "@bitaccess/ts-common": "^1.0.2", 55 | "@types/lodash": "^4.14.150", 56 | "bip174-bigint": "github:bitaccess/bip174#bigint", 57 | "bitcoinjs-lib-bigint": "github:bitaccess/bitcoinjs-lib#bigintv6", 58 | "io-ts": "^1.10.4", 59 | "lodash": "^4.17.15", 60 | "promise-retry": "^1.1.1" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /packages/coinlib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib", 3 | "version": "8.0.1", 4 | "description": "Library to assist in processing cryptocurrency payments, such as deriving addresses and sweeping funds", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "common", 20 | "bitaccess" 21 | ], 22 | "author": "Dylan Seago ", 23 | "license": "MIT", 24 | "files": [ 25 | "dist/", 26 | "src/" 27 | ], 28 | "engines": { 29 | "node": ">=12.0.0" 30 | }, 31 | "publishConfig": { 32 | "access": "public" 33 | }, 34 | "scripts": { 35 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 36 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 37 | "docs": "bin/docs.sh", 38 | "prebuild": "rimraf dist && rimraf docs", 39 | "build": "bin/build.sh", 40 | "start": "rollup -c rollup.config.js -w", 41 | "test": "jest --runInBand", 42 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 43 | "version": "npm run build" 44 | }, 45 | "dependencies": { 46 | "@bitaccess/coinlib-bitcoin": "file:../coinlib-bitcoin", 47 | "@bitaccess/coinlib-bitcoin-cash": "file:../coinlib-bitcoin-cash", 48 | "@bitaccess/coinlib-common": "file:../coinlib-common", 49 | "@bitaccess/coinlib-doge": "file:../coinlib-doge", 50 | "@bitaccess/coinlib-ethereum": "file:../coinlib-ethereum", 51 | "@bitaccess/coinlib-litecoin": "file:../coinlib-litecoin", 52 | "@bitaccess/coinlib-ripple": "file:../coinlib-ripple", 53 | "@bitaccess/coinlib-stellar": "file:../coinlib-stellar", 54 | "@bitaccess/coinlib-tron": "file:../coinlib-tron", 55 | "@bitaccess/ts-common": "^1.0.2", 56 | "io-ts": "^1.10.4", 57 | "lodash": "^4.17.21" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | plugins: [ 4 | '@typescript-eslint', 5 | 'jest', 6 | 'implicit-dependencies', 7 | ], 8 | ignorePatterns: ['.eslintrc.js'], 9 | env: { 10 | 'jest/globals': true, 11 | node: true, 12 | jest: true, 13 | }, 14 | extends: [ 15 | 'eslint:recommended', 16 | 'plugin:@typescript-eslint/recommended', 17 | 'plugin:@typescript-eslint/recommended-requiring-type-checking', 18 | 'standard', 19 | 'prettier', 20 | ], 21 | overrides: [ 22 | { 23 | parser: '@typescript-eslint/parser', 24 | files: ['*.{ts,tsx}'], 25 | parserOptions: { 26 | tsconfigRootDir: __dirname, 27 | sourceType: 'module', 28 | ecmaFeatures: { 29 | jsx: false, 30 | }, 31 | project: ['./tsconfig.eslint.json', './packages/*/tsconfig.json'], 32 | }, 33 | rules: { 34 | '@typescript-eslint/restrict-template-expressions': 'off', 35 | '@typescript-eslint/no-explicit-any': 'off', 36 | '@typescript-eslint/require-await': 'off', 37 | '@typescript-eslint/ban-types': 'off', 38 | '@typescript-eslint/no-unsafe-assignment': 'off', 39 | '@typescript-eslint/no-unsafe-member-access': 'off', 40 | '@typescript-eslint/no-unsafe-call': 'off', 41 | '@typescript-eslint/no-empty-function': 'off', 42 | '@typescript-eslint/no-unsafe-return': 'off', 43 | '@typescript-eslint/no-unsafe-argument': 'off', 44 | '@typescript-eslint/no-unused-vars': 'off', 45 | '@typescript-eslint/no-inferrable-types': 'off', 46 | '@typescript-eslint/no-non-null-assertion': 'off', 47 | }, 48 | }, 49 | { 50 | files: ['packages/*/src/**/*.ts'], 51 | rules: { 52 | 'implicit-dependencies/no-implicit': [ 53 | 'error', 54 | { peer: true, dev: false, optional: true } 55 | ] 56 | } 57 | }, 58 | { 59 | files: ['packages/*/test/**/*.ts'], 60 | rules: { 61 | 'camelcase': 'off', 62 | 'no-unmodified-loop-condition': 'off', 63 | } 64 | }, 65 | ], 66 | rules: { 67 | 'no-redeclare': 'off', 68 | 'no-dupe-class-members': 'off', 69 | 'no-unused-vars': 'off', 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /packages/coinlib-tron/src/HdTronPayments.ts: -------------------------------------------------------------------------------- 1 | import { BaseTronPayments } from './BaseTronPayments' 2 | import { HdTronPaymentsConfig } from './types' 3 | import { deriveAddress, derivePrivateKey, xprvToXpub, generateNewKeys } from './bip44' 4 | import { Payport } from '@bitaccess/coinlib-common' 5 | import { isValidXprv, isValidXpub, isValidAddress } from './helpers' 6 | import { omit } from 'lodash' 7 | import { PUBLIC_CONFIG_OMIT_FIELDS } from './constants' 8 | 9 | export class HdTronPayments extends BaseTronPayments { 10 | readonly xprv: string | null 11 | readonly xpub: string 12 | 13 | constructor(private readonly config: HdTronPaymentsConfig) { 14 | super(config) 15 | if (isValidXprv(config.hdKey)) { 16 | this.xprv = config.hdKey 17 | this.xpub = xprvToXpub(this.xprv) 18 | } else if (isValidXpub(config.hdKey)) { 19 | this.xprv = null 20 | this.xpub = config.hdKey 21 | } else { 22 | throw new Error('Account must be a valid xprv or xpub') 23 | } 24 | } 25 | 26 | static generateNewKeys = generateNewKeys 27 | 28 | getXpub(): string { 29 | return this.xpub 30 | } 31 | 32 | getFullConfig(): HdTronPaymentsConfig { 33 | return this.config 34 | } 35 | 36 | getPublicConfig(): HdTronPaymentsConfig { 37 | return { 38 | ...omit(this.config, PUBLIC_CONFIG_OMIT_FIELDS), 39 | hdKey: this.getXpub(), 40 | } 41 | } 42 | 43 | getAccountId(index: number): string { 44 | return this.getXpub() 45 | } 46 | 47 | getAccountIds(): string[] { 48 | return [this.getXpub()] 49 | } 50 | 51 | async getPayport(index: number): Promise { 52 | const xpub = this.getXpub() 53 | const address = deriveAddress(xpub, index) 54 | if (!isValidAddress(address)) { 55 | // This should never happen 56 | throw new Error(`Cannot get address ${index} - validation failed for derived address`) 57 | } 58 | return { address } 59 | } 60 | 61 | async getPrivateKey(index: number): Promise { 62 | if (!this.xprv) { 63 | throw new Error(`Cannot get private key ${index} - HdTronPayments was created with an xpub`) 64 | } 65 | return derivePrivateKey(this.xprv, index) 66 | } 67 | } 68 | 69 | export default HdTronPayments 70 | -------------------------------------------------------------------------------- /packages/coinlib-ethereum/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@bitaccess/coinlib-ethereum", 3 | "version": "8.0.0", 4 | "description": "Library to assist in processing ethereum payments, such as deriving addresses and sweeping funds", 5 | "main": "dist/index.cjs.js", 6 | "module": "dist/index.es.js", 7 | "browser": "dist/index.umd.js", 8 | "types": "dist/lib/index.d.ts", 9 | "esnext": "dist/lib/index.js", 10 | "repository": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-ethereum", 11 | "homepage": "https://github.com/bitaccess/coinlib/tree/master/packages/coinlib-ethereum#readme", 12 | "bugs": { 13 | "url": "https://github.com/bitaccess/coinlib/issues" 14 | }, 15 | "keywords": [ 16 | "coin", 17 | "payments", 18 | "crypto", 19 | "ripple", 20 | "xrp", 21 | "bitaccess" 22 | ], 23 | "author": "Denys Zaliskyi ", 24 | "license": "MIT", 25 | "files": [ 26 | "dist/", 27 | "src/" 28 | ], 29 | "engines": { 30 | "node": ">=12.0.0" 31 | }, 32 | "publishConfig": { 33 | "access": "public" 34 | }, 35 | "scripts": { 36 | "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'", 37 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 38 | "docs": "bin/docs.sh", 39 | "prebuild": "rimraf dist && rimraf docs", 40 | "build": "bin/build.sh", 41 | "start": "rollup -c rollup.config.ts -w", 42 | "test": "jest --runInBand", 43 | "report-coverage": "cat ./coverage/lcov.info | coveralls", 44 | "version": "npm run build", 45 | "sandbox": "bin/ts-node.sh test/sandbox.ts" 46 | }, 47 | "dependencies": { 48 | "@bitaccess/coinlib-common": "file:../coinlib-common", 49 | "@bitaccess/ts-common": "^1.0.2", 50 | "@ethereumjs/common": "^2.6.5", 51 | "@ethereumjs/tx": "^3.5.2", 52 | "blockbook-client": "^0.7.8", 53 | "elliptic": "^6.5.4", 54 | "ethereum-input-data-decoder": "^0.3.5", 55 | "ethereumjs-util": "^7.1.5", 56 | "io-ts": "^1.10.4", 57 | "lodash": "^4.17.21", 58 | "node-fetch": "^2.7.0", 59 | "promise-retry": "^1.1.1", 60 | "web3": "^1.7.1", 61 | "web3-core": "^1.7.4", 62 | "web3-eth": "^1.7.4", 63 | "web3-eth-contract": "^1.7.1", 64 | "web3-utils": "^1.7.4" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /packages/coinlib-ripple/src/constants.ts: -------------------------------------------------------------------------------- 1 | import { NetworkType, FeeLevel, AutoFeeLevels } from '@bitaccess/coinlib-common' 2 | import { RippleCreateTransactionOptions } from './types' 3 | 4 | export const PACKAGE_NAME = 'ripple-payments' 5 | 6 | export const COIN_SYMBOL = 'XRP' 7 | export const COIN_NAME = 'Ripple' // Yes, I know 'XRP' is the coin name too, but that's just confusing 8 | export const DECIMAL_PLACES = 6 9 | export const MIN_BALANCE = 20 10 | export const DEFAULT_CREATE_TRANSACTION_OPTIONS: RippleCreateTransactionOptions = {} 11 | export const DEFAULT_MAX_LEDGER_VERSION_OFFSET = 1000 // ~60min 12 | 13 | /** 14 | * Source: https://github.com/ripple/ripple-lib/blob/develop/src/common/schemas/objects/address.json 15 | */ 16 | export const ADDRESS_REGEX = /^r[1-9A-HJ-NP-Za-km-z]{25,34}$/ 17 | 18 | export const EXTRA_ID_REGEX = /^[0-9]+$/ 19 | 20 | /** 21 | * Source: crypto-regex 22 | */ 23 | export const XPUB_REGEX = /^xpub[a-km-zA-HJ-NP-Z1-9]{100,108}$/ 24 | export const XPRV_REGEX = /^xprv[a-km-zA-HJ-NP-Z1-9]{100,108}$/ 25 | 26 | export const NOT_FOUND_ERRORS = ['MissingLedgerHistoryError', 'NotFoundError', 'Account not found.', 'actNotFound'] 27 | export const CONNECTION_ERRORS = ['ConnectionError', 'NotConnectedError', 'DisconnectedError', 'disconnected', 'code: 1000', 'connection never cleaned up'] 28 | export const RETRYABLE_ERRORS = [...CONNECTION_ERRORS, 'TimeoutError', 'The server is too busy to help you now'] 29 | export const MAX_API_CALL_RETRIES = 2 30 | 31 | export const DEFAULT_NETWORK = NetworkType.Mainnet 32 | export const DEFAULT_MAINNET_SERVER = 'wss://s1.ripple.com' 33 | export const DEFAULT_TESTNET_SERVER = 'wss://s.altnet.rippletest.net:51233' 34 | 35 | export const DEFAULT_FEE_LEVEL: AutoFeeLevels = FeeLevel.Medium 36 | 37 | export const PUBLIC_CONFIG_OMIT_FIELDS = ['logger', 'server', 'api', 'hdKey', 'hotAccount', 'depositAccount'] 38 | export const UHD_PAYMENTS_CONFIG_OMIT_FIELDS = [ 39 | 'seed', 40 | 'uniPubKey', 41 | ] 42 | 43 | export const FEE_LEVEL_CUSHIONS = { 44 | [FeeLevel.Low]: 1, 45 | [FeeLevel.Medium]: 1.2, 46 | [FeeLevel.High]: 1.5, 47 | } 48 | 49 | export const RIPPLE_COINTYPES = { 50 | [NetworkType.Mainnet]: '144', 51 | [NetworkType.Testnet]: '144', 52 | } 53 | 54 | // TODO: design address type for Ripple 55 | export const RIPPLE_SUPPORTED_ADDRESS_TYPES: string[] = [] -------------------------------------------------------------------------------- /packages/coinlib/README.md: -------------------------------------------------------------------------------- 1 | # coinlib 2 | 3 | Library to assist in processing cryptocurrency payments. 4 | 5 | ## Getting Started 6 | 7 | ```bash 8 | npm i @bitaccess/coinlib 9 | ``` 10 | 11 | ```typescript 12 | import { CoinPayments } from '@bitaccess/coinlib' 13 | 14 | const coinPayments = new CoinPayments({ 15 | seed: '5cf2d4a8b0...ca676651f' 16 | }) 17 | ``` 18 | 19 | To begin processing payments, select your asset 20 | 21 | ```typescript 22 | const xrpPayments = coinPayments.forNetwork('XRP') 23 | await xrpPayments.init() 24 | ``` 25 | 26 | Generate a deposit address. 27 | This is useful if you are a hot wallet and don't store the private key. You will need 28 | to keep track of which path node you are on (increasing `int`): 29 | 30 | ```js 31 | let { address, extraId } = xrpPayments.getPayport(1234) 32 | // Customer sends deposit to `address` with destination tag `extraId` 33 | ``` 34 | 35 | Validate an address: 36 | 37 | ```js 38 | if (xrpPayments.isValidAddress(depositAddress)) { 39 | // do something 40 | } 41 | ``` 42 | 43 | Get the balance of an address: 44 | 45 | ```js 46 | let { confirmedBalance, unconfirmedBalance } = await xrpPayments.getBalance(1234) 47 | ``` 48 | 49 | Generate a sweep transaction for an address, then broadcast it: 50 | 51 | ```js 52 | let unsignedTx = await xrpPayments.createSweepTransaction(1234, to) 53 | let signedTx = await xrpPayments.signTransaction(unsignedTx) 54 | let { id: txHash } = await xrpPayments.broadcastTransaction(signedtx) 55 | ``` 56 | 57 | Generate a simple send transaction 58 | 59 | ```js 60 | let unsignedTx = await xrpPayments.createTransaction(1234, to, '1.234') 61 | // Then sign and broadcast the transaction 62 | ``` 63 | 64 | Get a transaction and check if it is confirmed: 65 | 66 | ```js 67 | let txInfo = await xrpPayments.getTransactionInfo(txHash) 68 | if (txInfo.isConfirmed) { 69 | // txInfo.confirmations > 0 70 | } 71 | ``` 72 | 73 | In some circumstances, you may want a read-only copy that can do everything but sign. First create it with your seed as usual, then get the public config to use for read only version. 74 | 75 | ```typescript 76 | const readOnlyConfig = coinPayments.getPublicConfig() 77 | const readOnlyCoinPayments = new CoinPayments(readOnlyConfig) 78 | ``` 79 | 80 | *See tests or types for more utilities* 81 | 82 | ## License 83 | 84 | MIT 85 | -------------------------------------------------------------------------------- /packages/coinlib-doge/src/DogePaymentsFactory.ts: -------------------------------------------------------------------------------- 1 | import { PaymentsFactory, StandardConnectionManager } from '@bitaccess/coinlib-common' 2 | import { assertType } from '@bitaccess/ts-common' 3 | import { bitcoinish } from '@bitaccess/coinlib-bitcoin' 4 | 5 | import { 6 | DogePaymentsConfig, 7 | HdDogePaymentsConfig, 8 | UHdDogePaymentsConfig, 9 | KeyPairDogePaymentsConfig, 10 | MultisigDogePaymentsConfig, 11 | DogePaymentsUtilsConfig, 12 | BaseDogePaymentsConfig, 13 | DogeBalanceMonitorConfig, 14 | DogeBaseConfig, 15 | } from './types' 16 | import { PACKAGE_NAME } from './constants' 17 | import { BaseDogePayments } from './BaseDogePayments' 18 | import { DogePaymentsUtils } from './DogePaymentsUtils' 19 | import { HdDogePayments } from './HdDogePayments' 20 | import { UHdDogePayments } from './UHdDogePayments' 21 | import { KeyPairDogePayments } from './KeyPairDogePayments' 22 | import { MultisigDogePayments } from './MultisigDogePayments' 23 | import { DogeBalanceMonitor } from './DogeBalanceMonitor' 24 | 25 | export class DogePaymentsFactory extends PaymentsFactory< 26 | DogePaymentsUtilsConfig, 27 | DogePaymentsUtils, 28 | BaseDogePayments, 29 | DogeBalanceMonitor 30 | > { 31 | readonly packageName = PACKAGE_NAME 32 | 33 | newPayments(config: DogePaymentsConfig) { 34 | if (HdDogePaymentsConfig.is(config)) { 35 | return new HdDogePayments(config) 36 | } 37 | if (UHdDogePaymentsConfig.is(config)) { 38 | return new UHdDogePayments(config) 39 | } 40 | if (KeyPairDogePaymentsConfig.is(config)) { 41 | return new KeyPairDogePayments(config) 42 | } 43 | if (MultisigDogePaymentsConfig.is(config)) { 44 | return new MultisigDogePayments(config) 45 | } 46 | throw new Error(`Cannot instantiate ${this.packageName} for unsupported config`) 47 | } 48 | 49 | newUtils(config: DogePaymentsUtilsConfig) { 50 | return new DogePaymentsUtils(assertType(DogePaymentsUtilsConfig, config, 'config')) 51 | } 52 | 53 | hasBalanceMonitor = true 54 | newBalanceMonitor(config: DogeBalanceMonitorConfig) { 55 | return new DogeBalanceMonitor(assertType(DogeBalanceMonitorConfig, config, 'config')) 56 | } 57 | 58 | connectionManager = new StandardConnectionManager() 59 | } 60 | 61 | export default DogePaymentsFactory 62 | --------------------------------------------------------------------------------