@bitpay-labs/bitcore-wallet-service 11.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.coveralls.yml +1 -0
- package/.travis.yml +27 -0
- package/DKG-flow.png +0 -0
- package/DSG-flow.png +0 -0
- package/Dockerfile +18 -0
- package/Installation.md +138 -0
- package/LICENCE +22 -0
- package/Makefile +5 -0
- package/README.md +429 -0
- package/TSS.md +136 -0
- package/bws.example.config.js +451 -0
- package/package.json +119 -0
- package/scripts/checkCopayerIds.js +118 -0
- package/scripts/clean_db.mongodb +5 -0
- package/scripts/deleteDupAddresses.mongo +6 -0
- package/scripts/deleteWallet.mongo +18 -0
- package/scripts/delme.ts +468 -0
- package/scripts/findEmail.js +32 -0
- package/scripts/fixAddressType.js +98 -0
- package/scripts/getSolStats2.js +81 -0
- package/scripts/migrateToNamedTestnets.js +191 -0
- package/scripts/migrateWalletsNetwork.js +204 -0
- package/scripts/preview-email.js +359 -0
- package/scripts/purgeNotifications.js +107 -0
- package/scripts/resetV8registration.mongo +21 -0
- package/scripts/v8tool-list.ts +93 -0
- package/scripts/v8tool.ts +82 -0
- package/scripts/walletStats.js +290 -0
- package/src/app.ts +28 -0
- package/src/bcmonitor/bcmonitor.ts +11 -0
- package/src/bws.ts +85 -0
- package/src/cleanfiatrates/cleanfiatrates.ts +9 -0
- package/src/config.ts +540 -0
- package/src/db/.empty +0 -0
- package/src/deprecated-serverMessages.ts +15 -0
- package/src/emailservice/emailservice.ts +11 -0
- package/src/externalservices/banxa.ts +261 -0
- package/src/externalservices/changelly.ts +371 -0
- package/src/externalservices/coingecko.ts +453 -0
- package/src/externalservices/moonpay.ts +435 -0
- package/src/externalservices/oneInch.ts +169 -0
- package/src/externalservices/ramp.ts +259 -0
- package/src/externalservices/sardine.ts +237 -0
- package/src/externalservices/simplex.ts +281 -0
- package/src/externalservices/thorswap.ts +197 -0
- package/src/externalservices/transak.ts +320 -0
- package/src/externalservices/wyre.ts +131 -0
- package/src/fiatrateservice/fiatrateservice.ts +15 -0
- package/src/index.ts +9 -0
- package/src/lib/bchaddresstranslator.ts +59 -0
- package/src/lib/blockchainexplorer.ts +84 -0
- package/src/lib/blockchainexplorers/v8/client.ts +177 -0
- package/src/lib/blockchainexplorers/v8.ts +730 -0
- package/src/lib/blockchainmonitor.ts +423 -0
- package/src/lib/chain/arb/index.ts +8 -0
- package/src/lib/chain/base/index.ts +8 -0
- package/src/lib/chain/bch/index.ts +40 -0
- package/src/lib/chain/btc/index.ts +991 -0
- package/src/lib/chain/doge/index.ts +387 -0
- package/src/lib/chain/eth/abi-erc20.ts +222 -0
- package/src/lib/chain/eth/abi-invoice.ts +277 -0
- package/src/lib/chain/eth/index.ts +657 -0
- package/src/lib/chain/index.ts +178 -0
- package/src/lib/chain/ltc/index.ts +9 -0
- package/src/lib/chain/matic/index.ts +8 -0
- package/src/lib/chain/op/index.ts +8 -0
- package/src/lib/chain/sol/index.ts +349 -0
- package/src/lib/chain/xrp/index.ts +338 -0
- package/src/lib/cleanfiatrates.ts +160 -0
- package/src/lib/common/constants.ts +231 -0
- package/src/lib/common/defaults.ts +436 -0
- package/src/lib/common/index.ts +11 -0
- package/src/lib/common/services.ts +43 -0
- package/src/lib/common/utils.ts +506 -0
- package/src/lib/emailservice.ts +741 -0
- package/src/lib/errors/clienterror.ts +44 -0
- package/src/lib/errors/errordefinitions.ts +158 -0
- package/src/lib/expressapp.ts +2415 -0
- package/src/lib/fiatrateproviders/bitpay.ts +20 -0
- package/src/lib/fiatrateproviders/bitstamp.ts +16 -0
- package/src/lib/fiatrateproviders/index.ts +8 -0
- package/src/lib/fiatrateproviders/provider.d.ts +10 -0
- package/src/lib/fiatrateservice.ts +338 -0
- package/src/lib/iconsconfig.ts +31 -0
- package/src/lib/index.ts +0 -0
- package/src/lib/lock.ts +112 -0
- package/src/lib/logger.ts +77 -0
- package/src/lib/messagebroker.ts +42 -0
- package/src/lib/model/address.ts +226 -0
- package/src/lib/model/addressmanager.ts +138 -0
- package/src/lib/model/advertisement.ts +84 -0
- package/src/lib/model/copayer.ts +162 -0
- package/src/lib/model/email.ts +103 -0
- package/src/lib/model/index.ts +12 -0
- package/src/lib/model/notification.ts +77 -0
- package/src/lib/model/preferences.ts +79 -0
- package/src/lib/model/pushnotificationsub.ts +50 -0
- package/src/lib/model/session.ts +65 -0
- package/src/lib/model/tsskeygen.ts +154 -0
- package/src/lib/model/tsssign.ts +136 -0
- package/src/lib/model/txconfirmationsub.ts +50 -0
- package/src/lib/model/txnote.ts +60 -0
- package/src/lib/model/txproposal.ts +561 -0
- package/src/lib/model/txproposal_legacy.ts +236 -0
- package/src/lib/model/txproposalaction.ts +48 -0
- package/src/lib/model/wallet.ts +359 -0
- package/src/lib/notificationbroadcaster.ts +17 -0
- package/src/lib/pushnotificationsservice.ts +802 -0
- package/src/lib/routes/helpers/error.ts +51 -0
- package/src/lib/routes/helpers/index.ts +1 -0
- package/src/lib/routes/middleware/authRequest.ts +117 -0
- package/src/lib/routes/middleware/authTssRequest.ts +66 -0
- package/src/lib/routes/middleware/createWalletLimiter.ts +21 -0
- package/src/lib/routes/middleware/log.ts +63 -0
- package/src/lib/routes/middleware/verifyTssMessage.ts +37 -0
- package/src/lib/routes/tss.ts +123 -0
- package/src/lib/server.ts +5342 -0
- package/src/lib/stats.ts +174 -0
- package/src/lib/storage.ts +1919 -0
- package/src/lib/tss.ts +446 -0
- package/src/lib/updatestats.ts +291 -0
- package/src/messagebroker/messagebroker.ts +18 -0
- package/src/pushnotificationsservice/pushnotificationsservice.ts +11 -0
- package/src/serverMessages.ts +30 -0
- package/src/types/chain.d.ts +62 -0
- package/src/types/emailservice.d.ts +11 -0
- package/src/types/expressapp.d.ts +15 -0
- package/src/types/externalservices.d.ts +41 -0
- package/src/types/notifications.d.ts +8 -0
- package/src/types/pushnotificationservice.d.ts +51 -0
- package/src/types/server.d.ts +24 -0
- package/src/updatestats/updatestats.ts +10 -0
- package/start-docker.sh +18 -0
- package/start.sh +38 -0
- package/static/images/down-arrow-green.png +0 -0
- package/static/images/failed-icon.png +0 -0
- package/static/images/green-check.png +0 -0
- package/static/images/person-plus.png +0 -0
- package/static/images/up-arrow-gray.png +0 -0
- package/static/images/writing-gray.png +0 -0
- package/stop.sh +19 -0
- package/templates/en/new_copayer.html +13 -0
- package/templates/en/new_copayer.plain +2 -0
- package/templates/en/new_incoming_tx.html +11 -0
- package/templates/en/new_incoming_tx.plain +2 -0
- package/templates/en/new_incoming_tx_testnet.html +13 -0
- package/templates/en/new_incoming_tx_testnet.plain +2 -0
- package/templates/en/new_outgoing_tx.html +11 -0
- package/templates/en/new_outgoing_tx.plain +2 -0
- package/templates/en/new_tx_proposal.html +13 -0
- package/templates/en/new_tx_proposal.plain +2 -0
- package/templates/en/new_zero_outgoing_tx.html +13 -0
- package/templates/en/new_zero_outgoing_tx.plain +2 -0
- package/templates/en/tx_confirmation.html +13 -0
- package/templates/en/tx_confirmation.plain +2 -0
- package/templates/en/tx_confirmation_receiver.html +13 -0
- package/templates/en/tx_confirmation_receiver.plain +2 -0
- package/templates/en/tx_confirmation_sender.html +13 -0
- package/templates/en/tx_confirmation_sender.plain +2 -0
- package/templates/en/txp_finally_rejected.html +13 -0
- package/templates/en/txp_finally_rejected.plain +2 -0
- package/templates/en/wallet_complete.html +13 -0
- package/templates/en/wallet_complete.plain +2 -0
- package/templates/es/new_copayer.html +13 -0
- package/templates/es/new_copayer.plain +2 -0
- package/templates/es/new_incoming_tx.html +11 -0
- package/templates/es/new_incoming_tx.plain +2 -0
- package/templates/es/new_incoming_tx_testnet.html +13 -0
- package/templates/es/new_incoming_tx_testnet.plain +2 -0
- package/templates/es/new_outgoing_tx.html +11 -0
- package/templates/es/new_outgoing_tx.plain +2 -0
- package/templates/es/new_tx_proposal.html +13 -0
- package/templates/es/new_tx_proposal.plain +2 -0
- package/templates/es/new_zero_outgoing_tx.html +13 -0
- package/templates/es/new_zero_outgoing_tx.plain +2 -0
- package/templates/es/tx_confirmation.html +13 -0
- package/templates/es/tx_confirmation.plain +2 -0
- package/templates/es/tx_confirmation_receiver.html +13 -0
- package/templates/es/tx_confirmation_receiver.plain +2 -0
- package/templates/es/tx_confirmation_sender.html +13 -0
- package/templates/es/tx_confirmation_sender.plain +2 -0
- package/templates/es/txp_finally_rejected.html +13 -0
- package/templates/es/txp_finally_rejected.plain +2 -0
- package/templates/es/wallet_complete.html +13 -0
- package/templates/es/wallet_complete.plain +2 -0
- package/templates/fr/new_copayer.html +13 -0
- package/templates/fr/new_copayer.plain +2 -0
- package/templates/fr/new_incoming_tx.html +11 -0
- package/templates/fr/new_incoming_tx.plain +2 -0
- package/templates/fr/new_incoming_tx_testnet.html +13 -0
- package/templates/fr/new_incoming_tx_testnet.plain +2 -0
- package/templates/fr/new_outgoing_tx.html +11 -0
- package/templates/fr/new_outgoing_tx.plain +2 -0
- package/templates/fr/new_tx_proposal.html +13 -0
- package/templates/fr/new_tx_proposal.plain +2 -0
- package/templates/fr/new_zero_outgoing_tx.html +13 -0
- package/templates/fr/new_zero_outgoing_tx.plain +2 -0
- package/templates/fr/tx_confirmation.html +13 -0
- package/templates/fr/tx_confirmation.plain +2 -0
- package/templates/fr/tx_confirmation_receiver.html +13 -0
- package/templates/fr/tx_confirmation_receiver.plain +2 -0
- package/templates/fr/tx_confirmation_sender.html +13 -0
- package/templates/fr/tx_confirmation_sender.plain +2 -0
- package/templates/fr/txp_finally_rejected.html +13 -0
- package/templates/fr/txp_finally_rejected.plain +2 -0
- package/templates/fr/wallet_complete.html +13 -0
- package/templates/fr/wallet_complete.plain +2 -0
- package/templates/ja/new_copayer.html +13 -0
- package/templates/ja/new_copayer.plain +2 -0
- package/templates/ja/new_incoming_tx.html +11 -0
- package/templates/ja/new_incoming_tx.plain +2 -0
- package/templates/ja/new_incoming_tx_testnet.html +13 -0
- package/templates/ja/new_incoming_tx_testnet.plain +2 -0
- package/templates/ja/new_outgoing_tx.html +11 -0
- package/templates/ja/new_outgoing_tx.plain +2 -0
- package/templates/ja/new_tx_proposal.html +13 -0
- package/templates/ja/new_tx_proposal.plain +2 -0
- package/templates/ja/new_zero_outgoing_tx.html +13 -0
- package/templates/ja/new_zero_outgoing_tx.plain +2 -0
- package/templates/ja/tx_confirmation.html +13 -0
- package/templates/ja/tx_confirmation.plain +2 -0
- package/templates/ja/tx_confirmation_receiver.html +13 -0
- package/templates/ja/tx_confirmation_receiver.plain +2 -0
- package/templates/ja/tx_confirmation_sender.html +13 -0
- package/templates/ja/tx_confirmation_sender.plain +2 -0
- package/templates/ja/txp_finally_rejected.html +13 -0
- package/templates/ja/txp_finally_rejected.plain +2 -0
- package/templates/ja/wallet_complete.html +13 -0
- package/templates/ja/wallet_complete.plain +2 -0
- package/templates/master-template.html +494 -0
- package/test/bchaddresstranslator.test.ts +50 -0
- package/test/blockchainexplorer.test.ts +66 -0
- package/test/chain/bch.test.ts +115 -0
- package/test/chain/btc.test.ts +331 -0
- package/test/chain/doge.test.ts +347 -0
- package/test/chain/eth.test.ts +21 -0
- package/test/chain/ltc.test.ts +328 -0
- package/test/chain/matic.test.ts +21 -0
- package/test/chain/xrp.test.ts +206 -0
- package/test/expressapp.test.ts +513 -0
- package/test/integration/bcmonitor.test.ts +381 -0
- package/test/integration/cashAddrMigration.test.ts +127 -0
- package/test/integration/data/tss/2of3/index.ts +3 -0
- package/test/integration/data/tss/2of3/party0.key.ts +5 -0
- package/test/integration/data/tss/2of3/party1.key.ts +5 -0
- package/test/integration/data/tss/2of3/party2.key.ts +5 -0
- package/test/integration/emailnotifications.test.ts +864 -0
- package/test/integration/externalservices/banxa.test.ts +373 -0
- package/test/integration/externalservices/changelly.test.ts +515 -0
- package/test/integration/externalservices/coinGecko.test.ts +284 -0
- package/test/integration/externalservices/moonpay.test.ts +569 -0
- package/test/integration/externalservices/oneInch.test.ts +162 -0
- package/test/integration/externalservices/ramp.test.ts +475 -0
- package/test/integration/externalservices/sardine.test.ts +352 -0
- package/test/integration/externalservices/simplex.test.ts +384 -0
- package/test/integration/externalservices/thorswap.test.ts +309 -0
- package/test/integration/externalservices/transak.test.ts +410 -0
- package/test/integration/externalservices/wyre.test.ts +270 -0
- package/test/integration/fiatrateservice.test.ts +979 -0
- package/test/integration/helpers.ts +694 -0
- package/test/integration/history.test.ts +1142 -0
- package/test/integration/hugetx.ts +6986 -0
- package/test/integration/pushNotifications.test.ts +1523 -0
- package/test/integration/server.test.ts +10740 -0
- package/test/integration/tss.test.ts +340 -0
- package/test/lock.test.ts +224 -0
- package/test/model/address.test.ts +187 -0
- package/test/model/addressmanager.test.ts +146 -0
- package/test/model/advertisement.test.ts +31 -0
- package/test/model/copayer.test.ts +131 -0
- package/test/model/txproposal.test.ts +185 -0
- package/test/model/wallet.test.ts +191 -0
- package/test/storage.test.ts +430 -0
- package/test/test-config.ts +12 -0
- package/test/testdata.ts +388 -0
- package/test/utils.test.ts +457 -0
- package/test/v8.test.ts +332 -0
- package/ts_build/package.json +119 -0
- package/ts_build/scripts/delme.d.ts +2 -0
- package/ts_build/scripts/delme.d.ts.map +1 -0
- package/ts_build/scripts/delme.js +453 -0
- package/ts_build/scripts/delme.js.map +1 -0
- package/ts_build/scripts/v8tool-list.d.ts +3 -0
- package/ts_build/scripts/v8tool-list.d.ts.map +1 -0
- package/ts_build/scripts/v8tool-list.js +80 -0
- package/ts_build/scripts/v8tool-list.js.map +1 -0
- package/ts_build/scripts/v8tool.d.ts +3 -0
- package/ts_build/scripts/v8tool.d.ts.map +1 -0
- package/ts_build/scripts/v8tool.js +69 -0
- package/ts_build/scripts/v8tool.js.map +1 -0
- package/ts_build/src/app.d.ts +3 -0
- package/ts_build/src/app.d.ts.map +1 -0
- package/ts_build/src/app.js +29 -0
- package/ts_build/src/app.js.map +1 -0
- package/ts_build/src/bcmonitor/bcmonitor.d.ts +3 -0
- package/ts_build/src/bcmonitor/bcmonitor.d.ts.map +1 -0
- package/ts_build/src/bcmonitor/bcmonitor.js +16 -0
- package/ts_build/src/bcmonitor/bcmonitor.js.map +1 -0
- package/ts_build/src/bws.d.ts +3 -0
- package/ts_build/src/bws.d.ts.map +1 -0
- package/ts_build/src/bws.js +98 -0
- package/ts_build/src/bws.js.map +1 -0
- package/ts_build/src/cleanfiatrates/cleanfiatrates.d.ts +3 -0
- package/ts_build/src/cleanfiatrates/cleanfiatrates.d.ts.map +1 -0
- package/ts_build/src/cleanfiatrates/cleanfiatrates.js +11 -0
- package/ts_build/src/cleanfiatrates/cleanfiatrates.js.map +1 -0
- package/ts_build/src/config.d.ts +3 -0
- package/ts_build/src/config.d.ts.map +1 -0
- package/ts_build/src/config.js +256 -0
- package/ts_build/src/config.js.map +1 -0
- package/ts_build/src/deprecated-serverMessages.d.ts +10 -0
- package/ts_build/src/deprecated-serverMessages.d.ts.map +1 -0
- package/ts_build/src/deprecated-serverMessages.js +20 -0
- package/ts_build/src/deprecated-serverMessages.js.map +1 -0
- package/ts_build/src/emailservice/emailservice.d.ts +3 -0
- package/ts_build/src/emailservice/emailservice.d.ts.map +1 -0
- package/ts_build/src/emailservice/emailservice.js +16 -0
- package/ts_build/src/emailservice/emailservice.js.map +1 -0
- package/ts_build/src/externalservices/banxa.d.ts +11 -0
- package/ts_build/src/externalservices/banxa.d.ts.map +1 -0
- package/ts_build/src/externalservices/banxa.js +254 -0
- package/ts_build/src/externalservices/banxa.js.map +1 -0
- package/ts_build/src/externalservices/changelly.d.ts +18 -0
- package/ts_build/src/externalservices/changelly.d.ts.map +1 -0
- package/ts_build/src/externalservices/changelly.js +356 -0
- package/ts_build/src/externalservices/changelly.js.map +1 -0
- package/ts_build/src/externalservices/coingecko.d.ts +43 -0
- package/ts_build/src/externalservices/coingecko.d.ts.map +1 -0
- package/ts_build/src/externalservices/coingecko.js +416 -0
- package/ts_build/src/externalservices/coingecko.js.map +1 -0
- package/ts_build/src/externalservices/moonpay.d.ts +19 -0
- package/ts_build/src/externalservices/moonpay.d.ts.map +1 -0
- package/ts_build/src/externalservices/moonpay.js +397 -0
- package/ts_build/src/externalservices/moonpay.js.map +1 -0
- package/ts_build/src/externalservices/oneInch.d.ts +11 -0
- package/ts_build/src/externalservices/oneInch.d.ts.map +1 -0
- package/ts_build/src/externalservices/oneInch.js +179 -0
- package/ts_build/src/externalservices/oneInch.js.map +1 -0
- package/ts_build/src/externalservices/ramp.d.ts +12 -0
- package/ts_build/src/externalservices/ramp.d.ts.map +1 -0
- package/ts_build/src/externalservices/ramp.js +256 -0
- package/ts_build/src/externalservices/ramp.js.map +1 -0
- package/ts_build/src/externalservices/sardine.d.ts +10 -0
- package/ts_build/src/externalservices/sardine.d.ts.map +1 -0
- package/ts_build/src/externalservices/sardine.js +232 -0
- package/ts_build/src/externalservices/sardine.js.map +1 -0
- package/ts_build/src/externalservices/simplex.d.ts +11 -0
- package/ts_build/src/externalservices/simplex.d.ts.map +1 -0
- package/ts_build/src/externalservices/simplex.js +261 -0
- package/ts_build/src/externalservices/simplex.js.map +1 -0
- package/ts_build/src/externalservices/thorswap.d.ts +9 -0
- package/ts_build/src/externalservices/thorswap.d.ts.map +1 -0
- package/ts_build/src/externalservices/thorswap.js +206 -0
- package/ts_build/src/externalservices/thorswap.js.map +1 -0
- package/ts_build/src/externalservices/transak.d.ts +13 -0
- package/ts_build/src/externalservices/transak.d.ts.map +1 -0
- package/ts_build/src/externalservices/transak.js +311 -0
- package/ts_build/src/externalservices/transak.js.map +1 -0
- package/ts_build/src/externalservices/wyre.d.ts +7 -0
- package/ts_build/src/externalservices/wyre.d.ts.map +1 -0
- package/ts_build/src/externalservices/wyre.js +144 -0
- package/ts_build/src/externalservices/wyre.js.map +1 -0
- package/ts_build/src/fiatrateservice/fiatrateservice.d.ts +3 -0
- package/ts_build/src/fiatrateservice/fiatrateservice.d.ts.map +1 -0
- package/ts_build/src/fiatrateservice/fiatrateservice.js +20 -0
- package/ts_build/src/fiatrateservice/fiatrateservice.js.map +1 -0
- package/ts_build/src/index.d.ts +8 -0
- package/ts_build/src/index.d.ts.map +1 -0
- package/ts_build/src/index.js +11 -0
- package/ts_build/src/index.js.map +1 -0
- package/ts_build/src/lib/bchaddresstranslator.d.ts +5 -0
- package/ts_build/src/lib/bchaddresstranslator.d.ts.map +1 -0
- package/ts_build/src/lib/bchaddresstranslator.js +66 -0
- package/ts_build/src/lib/bchaddresstranslator.js.map +1 -0
- package/ts_build/src/lib/blockchainexplorer.d.ts +3 -0
- package/ts_build/src/lib/blockchainexplorer.d.ts.map +1 -0
- package/ts_build/src/lib/blockchainexplorer.js +87 -0
- package/ts_build/src/lib/blockchainexplorer.js.map +1 -0
- package/ts_build/src/lib/blockchainexplorers/v8/client.d.ts +31 -0
- package/ts_build/src/lib/blockchainexplorers/v8/client.d.ts.map +1 -0
- package/ts_build/src/lib/blockchainexplorers/v8/client.js +191 -0
- package/ts_build/src/lib/blockchainexplorers/v8/client.js.map +1 -0
- package/ts_build/src/lib/blockchainexplorers/v8.d.ts +91 -0
- package/ts_build/src/lib/blockchainexplorers/v8.d.ts.map +1 -0
- package/ts_build/src/lib/blockchainexplorers/v8.js +662 -0
- package/ts_build/src/lib/blockchainexplorers/v8.js.map +1 -0
- package/ts_build/src/lib/blockchainmonitor.d.ts +32 -0
- package/ts_build/src/lib/blockchainmonitor.d.ts.map +1 -0
- package/ts_build/src/lib/blockchainmonitor.js +413 -0
- package/ts_build/src/lib/blockchainmonitor.js.map +1 -0
- package/ts_build/src/lib/chain/arb/index.d.ts +5 -0
- package/ts_build/src/lib/chain/arb/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/arb/index.js +12 -0
- package/ts_build/src/lib/chain/arb/index.js.map +1 -0
- package/ts_build/src/lib/chain/base/index.d.ts +5 -0
- package/ts_build/src/lib/chain/base/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/base/index.js +12 -0
- package/ts_build/src/lib/chain/base/index.js.map +1 -0
- package/ts_build/src/lib/chain/bch/index.d.ts +9 -0
- package/ts_build/src/lib/chain/bch/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/bch/index.js +43 -0
- package/ts_build/src/lib/chain/bch/index.js.map +1 -0
- package/ts_build/src/lib/chain/btc/index.d.ts +65 -0
- package/ts_build/src/lib/chain/btc/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/btc/index.js +829 -0
- package/ts_build/src/lib/chain/btc/index.js.map +1 -0
- package/ts_build/src/lib/chain/doge/index.d.ts +9 -0
- package/ts_build/src/lib/chain/doge/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/doge/index.js +338 -0
- package/ts_build/src/lib/chain/doge/index.js.map +1 -0
- package/ts_build/src/lib/chain/eth/abi-erc20.d.ts +39 -0
- package/ts_build/src/lib/chain/eth/abi-erc20.d.ts.map +1 -0
- package/ts_build/src/lib/chain/eth/abi-erc20.js +226 -0
- package/ts_build/src/lib/chain/eth/abi-erc20.js.map +1 -0
- package/ts_build/src/lib/chain/eth/abi-invoice.d.ts +42 -0
- package/ts_build/src/lib/chain/eth/abi-invoice.d.ts.map +1 -0
- package/ts_build/src/lib/chain/eth/abi-invoice.js +281 -0
- package/ts_build/src/lib/chain/eth/abi-invoice.js.map +1 -0
- package/ts_build/src/lib/chain/eth/index.d.ts +66 -0
- package/ts_build/src/lib/chain/eth/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/eth/index.js +516 -0
- package/ts_build/src/lib/chain/eth/index.js.map +1 -0
- package/ts_build/src/lib/chain/index.d.ts +40 -0
- package/ts_build/src/lib/chain/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/index.js +143 -0
- package/ts_build/src/lib/chain/index.js.map +1 -0
- package/ts_build/src/lib/chain/ltc/index.d.ts +6 -0
- package/ts_build/src/lib/chain/ltc/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/ltc/index.js +12 -0
- package/ts_build/src/lib/chain/ltc/index.js.map +1 -0
- package/ts_build/src/lib/chain/matic/index.d.ts +5 -0
- package/ts_build/src/lib/chain/matic/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/matic/index.js +12 -0
- package/ts_build/src/lib/chain/matic/index.js.map +1 -0
- package/ts_build/src/lib/chain/op/index.d.ts +5 -0
- package/ts_build/src/lib/chain/op/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/op/index.js +12 -0
- package/ts_build/src/lib/chain/op/index.js.map +1 -0
- package/ts_build/src/lib/chain/sol/index.d.ts +52 -0
- package/ts_build/src/lib/chain/sol/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/sol/index.js +305 -0
- package/ts_build/src/lib/chain/sol/index.js.map +1 -0
- package/ts_build/src/lib/chain/xrp/index.d.ts +46 -0
- package/ts_build/src/lib/chain/xrp/index.d.ts.map +1 -0
- package/ts_build/src/lib/chain/xrp/index.js +300 -0
- package/ts_build/src/lib/chain/xrp/index.js.map +1 -0
- package/ts_build/src/lib/cleanfiatrates.d.ts +13 -0
- package/ts_build/src/lib/cleanfiatrates.d.ts.map +1 -0
- package/ts_build/src/lib/cleanfiatrates.js +176 -0
- package/ts_build/src/lib/cleanfiatrates.js.map +1 -0
- package/ts_build/src/lib/common/constants.d.ts +387 -0
- package/ts_build/src/lib/common/constants.d.ts.map +1 -0
- package/ts_build/src/lib/common/constants.js +234 -0
- package/ts_build/src/lib/common/constants.js.map +1 -0
- package/ts_build/src/lib/common/defaults.d.ts +326 -0
- package/ts_build/src/lib/common/defaults.d.ts.map +1 -0
- package/ts_build/src/lib/common/defaults.js +356 -0
- package/ts_build/src/lib/common/defaults.js.map +1 -0
- package/ts_build/src/lib/common/index.d.ts +793 -0
- package/ts_build/src/lib/common/index.d.ts.map +1 -0
- package/ts_build/src/lib/common/index.js +14 -0
- package/ts_build/src/lib/common/index.js.map +1 -0
- package/ts_build/src/lib/common/services.d.ts +34 -0
- package/ts_build/src/lib/common/services.d.ts.map +1 -0
- package/ts_build/src/lib/common/services.js +44 -0
- package/ts_build/src/lib/common/services.js.map +1 -0
- package/ts_build/src/lib/common/utils.d.ts +47 -0
- package/ts_build/src/lib/common/utils.d.ts.map +1 -0
- package/ts_build/src/lib/common/utils.js +385 -0
- package/ts_build/src/lib/common/utils.js.map +1 -0
- package/ts_build/src/lib/emailservice.d.ts +62 -0
- package/ts_build/src/lib/emailservice.d.ts.map +1 -0
- package/ts_build/src/lib/emailservice.js +727 -0
- package/ts_build/src/lib/emailservice.js.map +1 -0
- package/ts_build/src/lib/errors/clienterror.d.ts +11 -0
- package/ts_build/src/lib/errors/clienterror.d.ts.map +1 -0
- package/ts_build/src/lib/errors/clienterror.js +46 -0
- package/ts_build/src/lib/errors/clienterror.js.map +1 -0
- package/ts_build/src/lib/errors/errordefinitions.d.ts +76 -0
- package/ts_build/src/lib/errors/errordefinitions.d.ts.map +1 -0
- package/ts_build/src/lib/errors/errordefinitions.js +82 -0
- package/ts_build/src/lib/errors/errordefinitions.js.map +1 -0
- package/ts_build/src/lib/expressapp.d.ts +8 -0
- package/ts_build/src/lib/expressapp.d.ts.map +1 -0
- package/ts_build/src/lib/expressapp.js +2221 -0
- package/ts_build/src/lib/expressapp.js.map +1 -0
- package/ts_build/src/lib/fiatrateproviders/bitpay.d.ts +3 -0
- package/ts_build/src/lib/fiatrateproviders/bitpay.d.ts.map +1 -0
- package/ts_build/src/lib/fiatrateproviders/bitpay.js +22 -0
- package/ts_build/src/lib/fiatrateproviders/bitpay.js.map +1 -0
- package/ts_build/src/lib/fiatrateproviders/bitstamp.d.ts +3 -0
- package/ts_build/src/lib/fiatrateproviders/bitstamp.d.ts.map +1 -0
- package/ts_build/src/lib/fiatrateproviders/bitstamp.js +18 -0
- package/ts_build/src/lib/fiatrateproviders/bitstamp.js.map +1 -0
- package/ts_build/src/lib/fiatrateproviders/index.d.ts +3 -0
- package/ts_build/src/lib/fiatrateproviders/index.d.ts.map +1 -0
- package/ts_build/src/lib/fiatrateproviders/index.js +8 -0
- package/ts_build/src/lib/fiatrateproviders/index.js.map +1 -0
- package/ts_build/src/lib/fiatrateservice.d.ts +18 -0
- package/ts_build/src/lib/fiatrateservice.d.ts.map +1 -0
- package/ts_build/src/lib/fiatrateservice.js +313 -0
- package/ts_build/src/lib/fiatrateservice.js.map +1 -0
- package/ts_build/src/lib/iconsconfig.d.ts +2 -0
- package/ts_build/src/lib/iconsconfig.d.ts.map +1 -0
- package/ts_build/src/lib/iconsconfig.js +31 -0
- package/ts_build/src/lib/iconsconfig.js.map +1 -0
- package/ts_build/src/lib/index.d.ts +1 -0
- package/ts_build/src/lib/index.d.ts.map +1 -0
- package/ts_build/src/lib/index.js +1 -0
- package/ts_build/src/lib/index.js.map +1 -0
- package/ts_build/src/lib/lock.d.ts +14 -0
- package/ts_build/src/lib/lock.d.ts.map +1 -0
- package/ts_build/src/lib/lock.js +55 -0
- package/ts_build/src/lib/lock.js.map +1 -0
- package/ts_build/src/lib/logger.d.ts +7 -0
- package/ts_build/src/lib/logger.d.ts.map +1 -0
- package/ts_build/src/lib/logger.js +95 -0
- package/ts_build/src/lib/logger.js.map +1 -0
- package/ts_build/src/lib/messagebroker.d.ts +11 -0
- package/ts_build/src/lib/messagebroker.d.ts.map +1 -0
- package/ts_build/src/lib/messagebroker.js +77 -0
- package/ts_build/src/lib/messagebroker.js.map +1 -0
- package/ts_build/src/lib/model/address.d.ts +47 -0
- package/ts_build/src/lib/model/address.d.ts.map +1 -0
- package/ts_build/src/lib/model/address.js +158 -0
- package/ts_build/src/lib/model/address.js.map +1 -0
- package/ts_build/src/lib/model/addressmanager.d.ts +41 -0
- package/ts_build/src/lib/model/addressmanager.d.ts.map +1 -0
- package/ts_build/src/lib/model/addressmanager.js +103 -0
- package/ts_build/src/lib/model/addressmanager.js.map +1 -0
- package/ts_build/src/lib/model/advertisement.d.ts +38 -0
- package/ts_build/src/lib/model/advertisement.d.ts.map +1 -0
- package/ts_build/src/lib/model/advertisement.js +68 -0
- package/ts_build/src/lib/model/advertisement.js.map +1 -0
- package/ts_build/src/lib/model/copayer.d.ts +48 -0
- package/ts_build/src/lib/model/copayer.d.ts.map +1 -0
- package/ts_build/src/lib/model/copayer.js +116 -0
- package/ts_build/src/lib/model/copayer.js.map +1 -0
- package/ts_build/src/lib/model/email.d.ts +23 -0
- package/ts_build/src/lib/model/email.d.ts.map +1 -0
- package/ts_build/src/lib/model/email.js +84 -0
- package/ts_build/src/lib/model/email.js.map +1 -0
- package/ts_build/src/lib/model/index.d.ts +13 -0
- package/ts_build/src/lib/model/index.d.ts.map +1 -0
- package/ts_build/src/lib/model/index.js +28 -0
- package/ts_build/src/lib/model/index.js.map +1 -0
- package/ts_build/src/lib/model/notification.d.ts +23 -0
- package/ts_build/src/lib/model/notification.d.ts.map +1 -0
- package/ts_build/src/lib/model/notification.js +40 -0
- package/ts_build/src/lib/model/notification.js.map +1 -0
- package/ts_build/src/lib/model/preferences.d.ts +37 -0
- package/ts_build/src/lib/model/preferences.d.ts.map +1 -0
- package/ts_build/src/lib/model/preferences.js +61 -0
- package/ts_build/src/lib/model/preferences.js.map +1 -0
- package/ts_build/src/lib/model/pushnotificationsub.d.ts +23 -0
- package/ts_build/src/lib/model/pushnotificationsub.d.ts.map +1 -0
- package/ts_build/src/lib/model/pushnotificationsub.js +40 -0
- package/ts_build/src/lib/model/pushnotificationsub.js.map +1 -0
- package/ts_build/src/lib/model/session.d.ts +22 -0
- package/ts_build/src/lib/model/session.d.ts.map +1 -0
- package/ts_build/src/lib/model/session.js +52 -0
- package/ts_build/src/lib/model/session.js.map +1 -0
- package/ts_build/src/lib/model/tsskeygen.d.ts +67 -0
- package/ts_build/src/lib/model/tsskeygen.d.ts.map +1 -0
- package/ts_build/src/lib/model/tsskeygen.js +69 -0
- package/ts_build/src/lib/model/tsskeygen.js.map +1 -0
- package/ts_build/src/lib/model/tsssign.d.ts +70 -0
- package/ts_build/src/lib/model/tsssign.d.ts.map +1 -0
- package/ts_build/src/lib/model/tsssign.js +54 -0
- package/ts_build/src/lib/model/tsssign.js.map +1 -0
- package/ts_build/src/lib/model/txconfirmationsub.d.ts +23 -0
- package/ts_build/src/lib/model/txconfirmationsub.d.ts.map +1 -0
- package/ts_build/src/lib/model/txconfirmationsub.js +40 -0
- package/ts_build/src/lib/model/txconfirmationsub.js.map +1 -0
- package/ts_build/src/lib/model/txnote.d.ts +23 -0
- package/ts_build/src/lib/model/txnote.d.ts.map +1 -0
- package/ts_build/src/lib/model/txnote.js +46 -0
- package/ts_build/src/lib/model/txnote.js.map +1 -0
- package/ts_build/src/lib/model/txproposal.d.ts +196 -0
- package/ts_build/src/lib/model/txproposal.d.ts.map +1 -0
- package/ts_build/src/lib/model/txproposal.js +382 -0
- package/ts_build/src/lib/model/txproposal.js.map +1 -0
- package/ts_build/src/lib/model/txproposal_legacy.d.ts +93 -0
- package/ts_build/src/lib/model/txproposal_legacy.d.ts.map +1 -0
- package/ts_build/src/lib/model/txproposal_legacy.js +185 -0
- package/ts_build/src/lib/model/txproposal_legacy.js.map +1 -0
- package/ts_build/src/lib/model/txproposalaction.d.ts +21 -0
- package/ts_build/src/lib/model/txproposalaction.d.ts.map +1 -0
- package/ts_build/src/lib/model/txproposalaction.js +37 -0
- package/ts_build/src/lib/model/txproposalaction.js.map +1 -0
- package/ts_build/src/lib/model/wallet.d.ts +110 -0
- package/ts_build/src/lib/model/wallet.d.ts.map +1 -0
- package/ts_build/src/lib/model/wallet.js +224 -0
- package/ts_build/src/lib/model/wallet.js.map +1 -0
- package/ts_build/src/lib/notificationbroadcaster.d.ts +6 -0
- package/ts_build/src/lib/notificationbroadcaster.d.ts.map +1 -0
- package/ts_build/src/lib/notificationbroadcaster.js +19 -0
- package/ts_build/src/lib/notificationbroadcaster.js.map +1 -0
- package/ts_build/src/lib/pushnotificationsservice.d.ts +56 -0
- package/ts_build/src/lib/pushnotificationsservice.d.ts.map +1 -0
- package/ts_build/src/lib/pushnotificationsservice.js +721 -0
- package/ts_build/src/lib/pushnotificationsservice.js.map +1 -0
- package/ts_build/src/lib/routes/helpers/error.d.ts +10 -0
- package/ts_build/src/lib/routes/helpers/error.d.ts.map +1 -0
- package/ts_build/src/lib/routes/helpers/error.js +54 -0
- package/ts_build/src/lib/routes/helpers/error.js.map +1 -0
- package/ts_build/src/lib/routes/helpers/index.d.ts +2 -0
- package/ts_build/src/lib/routes/helpers/index.d.ts.map +1 -0
- package/ts_build/src/lib/routes/helpers/index.js +18 -0
- package/ts_build/src/lib/routes/helpers/index.js.map +1 -0
- package/ts_build/src/lib/routes/middleware/authRequest.d.ts +6 -0
- package/ts_build/src/lib/routes/middleware/authRequest.d.ts.map +1 -0
- package/ts_build/src/lib/routes/middleware/authRequest.js +106 -0
- package/ts_build/src/lib/routes/middleware/authRequest.js.map +1 -0
- package/ts_build/src/lib/routes/middleware/authTssRequest.d.ts +3 -0
- package/ts_build/src/lib/routes/middleware/authTssRequest.d.ts.map +1 -0
- package/ts_build/src/lib/routes/middleware/authTssRequest.js +56 -0
- package/ts_build/src/lib/routes/middleware/authTssRequest.js.map +1 -0
- package/ts_build/src/lib/routes/middleware/createWalletLimiter.d.ts +4 -0
- package/ts_build/src/lib/routes/middleware/createWalletLimiter.d.ts.map +1 -0
- package/ts_build/src/lib/routes/middleware/createWalletLimiter.js +28 -0
- package/ts_build/src/lib/routes/middleware/createWalletLimiter.js.map +1 -0
- package/ts_build/src/lib/routes/middleware/log.d.ts +9 -0
- package/ts_build/src/lib/routes/middleware/log.d.ts.map +1 -0
- package/ts_build/src/lib/routes/middleware/log.js +52 -0
- package/ts_build/src/lib/routes/middleware/log.js.map +1 -0
- package/ts_build/src/lib/routes/middleware/verifyTssMessage.d.ts +2 -0
- package/ts_build/src/lib/routes/middleware/verifyTssMessage.d.ts.map +1 -0
- package/ts_build/src/lib/routes/middleware/verifyTssMessage.js +34 -0
- package/ts_build/src/lib/routes/middleware/verifyTssMessage.js.map +1 -0
- package/ts_build/src/lib/routes/tss.d.ts +14 -0
- package/ts_build/src/lib/routes/tss.d.ts.map +1 -0
- package/ts_build/src/lib/routes/tss.js +120 -0
- package/ts_build/src/lib/routes/tss.js.map +1 -0
- package/ts_build/src/lib/server.d.ts +250 -0
- package/ts_build/src/lib/server.d.ts.map +1 -0
- package/ts_build/src/lib/server.js +4115 -0
- package/ts_build/src/lib/server.js.map +1 -0
- package/ts_build/src/lib/stats.d.ts +17 -0
- package/ts_build/src/lib/stats.d.ts.map +1 -0
- package/ts_build/src/lib/stats.js +203 -0
- package/ts_build/src/lib/stats.js.map +1 -0
- package/ts_build/src/lib/storage.d.ts +163 -0
- package/ts_build/src/lib/storage.d.ts.map +1 -0
- package/ts_build/src/lib/storage.js +1513 -0
- package/ts_build/src/lib/storage.js.map +1 -0
- package/ts_build/src/lib/tss.d.ts +70 -0
- package/ts_build/src/lib/tss.d.ts.map +1 -0
- package/ts_build/src/lib/tss.js +379 -0
- package/ts_build/src/lib/tss.js.map +1 -0
- package/ts_build/src/lib/updatestats.d.ts +16 -0
- package/ts_build/src/lib/updatestats.d.ts.map +1 -0
- package/ts_build/src/lib/updatestats.js +308 -0
- package/ts_build/src/lib/updatestats.js.map +1 -0
- package/ts_build/src/messagebroker/messagebroker.d.ts +3 -0
- package/ts_build/src/messagebroker/messagebroker.d.ts.map +1 -0
- package/ts_build/src/messagebroker/messagebroker.js +20 -0
- package/ts_build/src/messagebroker/messagebroker.js.map +1 -0
- package/ts_build/src/pushnotificationsservice/pushnotificationsservice.d.ts +3 -0
- package/ts_build/src/pushnotificationsservice/pushnotificationsservice.d.ts.map +1 -0
- package/ts_build/src/pushnotificationsservice/pushnotificationsservice.js +16 -0
- package/ts_build/src/pushnotificationsservice/pushnotificationsservice.js.map +1 -0
- package/ts_build/src/serverMessages.d.ts +2 -0
- package/ts_build/src/serverMessages.d.ts.map +1 -0
- package/ts_build/src/serverMessages.js +35 -0
- package/ts_build/src/serverMessages.js.map +1 -0
- package/ts_build/src/updatestats/updatestats.d.ts +3 -0
- package/ts_build/src/updatestats/updatestats.d.ts.map +1 -0
- package/ts_build/src/updatestats/updatestats.js +15 -0
- package/ts_build/src/updatestats/updatestats.js.map +1 -0
- package/ts_build/templates/en/new_copayer.html +13 -0
- package/ts_build/templates/en/new_copayer.plain +2 -0
- package/ts_build/templates/en/new_incoming_tx.html +11 -0
- package/ts_build/templates/en/new_incoming_tx.plain +2 -0
- package/ts_build/templates/en/new_incoming_tx_testnet.html +13 -0
- package/ts_build/templates/en/new_incoming_tx_testnet.plain +2 -0
- package/ts_build/templates/en/new_outgoing_tx.html +11 -0
- package/ts_build/templates/en/new_outgoing_tx.plain +2 -0
- package/ts_build/templates/en/new_tx_proposal.html +13 -0
- package/ts_build/templates/en/new_tx_proposal.plain +2 -0
- package/ts_build/templates/en/new_zero_outgoing_tx.html +13 -0
- package/ts_build/templates/en/new_zero_outgoing_tx.plain +2 -0
- package/ts_build/templates/en/tx_confirmation.html +13 -0
- package/ts_build/templates/en/tx_confirmation.plain +2 -0
- package/ts_build/templates/en/tx_confirmation_receiver.html +13 -0
- package/ts_build/templates/en/tx_confirmation_receiver.plain +2 -0
- package/ts_build/templates/en/tx_confirmation_sender.html +13 -0
- package/ts_build/templates/en/tx_confirmation_sender.plain +2 -0
- package/ts_build/templates/en/txp_finally_rejected.html +13 -0
- package/ts_build/templates/en/txp_finally_rejected.plain +2 -0
- package/ts_build/templates/en/wallet_complete.html +13 -0
- package/ts_build/templates/en/wallet_complete.plain +2 -0
- package/ts_build/templates/es/new_copayer.html +13 -0
- package/ts_build/templates/es/new_copayer.plain +2 -0
- package/ts_build/templates/es/new_incoming_tx.html +11 -0
- package/ts_build/templates/es/new_incoming_tx.plain +2 -0
- package/ts_build/templates/es/new_incoming_tx_testnet.html +13 -0
- package/ts_build/templates/es/new_incoming_tx_testnet.plain +2 -0
- package/ts_build/templates/es/new_outgoing_tx.html +11 -0
- package/ts_build/templates/es/new_outgoing_tx.plain +2 -0
- package/ts_build/templates/es/new_tx_proposal.html +13 -0
- package/ts_build/templates/es/new_tx_proposal.plain +2 -0
- package/ts_build/templates/es/new_zero_outgoing_tx.html +13 -0
- package/ts_build/templates/es/new_zero_outgoing_tx.plain +2 -0
- package/ts_build/templates/es/tx_confirmation.html +13 -0
- package/ts_build/templates/es/tx_confirmation.plain +2 -0
- package/ts_build/templates/es/tx_confirmation_receiver.html +13 -0
- package/ts_build/templates/es/tx_confirmation_receiver.plain +2 -0
- package/ts_build/templates/es/tx_confirmation_sender.html +13 -0
- package/ts_build/templates/es/tx_confirmation_sender.plain +2 -0
- package/ts_build/templates/es/txp_finally_rejected.html +13 -0
- package/ts_build/templates/es/txp_finally_rejected.plain +2 -0
- package/ts_build/templates/es/wallet_complete.html +13 -0
- package/ts_build/templates/es/wallet_complete.plain +2 -0
- package/ts_build/templates/fr/new_copayer.html +13 -0
- package/ts_build/templates/fr/new_copayer.plain +2 -0
- package/ts_build/templates/fr/new_incoming_tx.html +11 -0
- package/ts_build/templates/fr/new_incoming_tx.plain +2 -0
- package/ts_build/templates/fr/new_incoming_tx_testnet.html +13 -0
- package/ts_build/templates/fr/new_incoming_tx_testnet.plain +2 -0
- package/ts_build/templates/fr/new_outgoing_tx.html +11 -0
- package/ts_build/templates/fr/new_outgoing_tx.plain +2 -0
- package/ts_build/templates/fr/new_tx_proposal.html +13 -0
- package/ts_build/templates/fr/new_tx_proposal.plain +2 -0
- package/ts_build/templates/fr/new_zero_outgoing_tx.html +13 -0
- package/ts_build/templates/fr/new_zero_outgoing_tx.plain +2 -0
- package/ts_build/templates/fr/tx_confirmation.html +13 -0
- package/ts_build/templates/fr/tx_confirmation.plain +2 -0
- package/ts_build/templates/fr/tx_confirmation_receiver.html +13 -0
- package/ts_build/templates/fr/tx_confirmation_receiver.plain +2 -0
- package/ts_build/templates/fr/tx_confirmation_sender.html +13 -0
- package/ts_build/templates/fr/tx_confirmation_sender.plain +2 -0
- package/ts_build/templates/fr/txp_finally_rejected.html +13 -0
- package/ts_build/templates/fr/txp_finally_rejected.plain +2 -0
- package/ts_build/templates/fr/wallet_complete.html +13 -0
- package/ts_build/templates/fr/wallet_complete.plain +2 -0
- package/ts_build/templates/ja/new_copayer.html +13 -0
- package/ts_build/templates/ja/new_copayer.plain +2 -0
- package/ts_build/templates/ja/new_incoming_tx.html +11 -0
- package/ts_build/templates/ja/new_incoming_tx.plain +2 -0
- package/ts_build/templates/ja/new_incoming_tx_testnet.html +13 -0
- package/ts_build/templates/ja/new_incoming_tx_testnet.plain +2 -0
- package/ts_build/templates/ja/new_outgoing_tx.html +11 -0
- package/ts_build/templates/ja/new_outgoing_tx.plain +2 -0
- package/ts_build/templates/ja/new_tx_proposal.html +13 -0
- package/ts_build/templates/ja/new_tx_proposal.plain +2 -0
- package/ts_build/templates/ja/new_zero_outgoing_tx.html +13 -0
- package/ts_build/templates/ja/new_zero_outgoing_tx.plain +2 -0
- package/ts_build/templates/ja/tx_confirmation.html +13 -0
- package/ts_build/templates/ja/tx_confirmation.plain +2 -0
- package/ts_build/templates/ja/tx_confirmation_receiver.html +13 -0
- package/ts_build/templates/ja/tx_confirmation_receiver.plain +2 -0
- package/ts_build/templates/ja/tx_confirmation_sender.html +13 -0
- package/ts_build/templates/ja/tx_confirmation_sender.plain +2 -0
- package/ts_build/templates/ja/txp_finally_rejected.html +13 -0
- package/ts_build/templates/ja/txp_finally_rejected.plain +2 -0
- package/ts_build/templates/ja/wallet_complete.html +13 -0
- package/ts_build/templates/ja/wallet_complete.plain +2 -0
- package/ts_build/templates/master-template.html +494 -0
- package/ts_build/test/bchaddresstranslator.test.d.ts +2 -0
- package/ts_build/test/bchaddresstranslator.test.d.ts.map +1 -0
- package/ts_build/test/bchaddresstranslator.test.js +76 -0
- package/ts_build/test/bchaddresstranslator.test.js.map +1 -0
- package/ts_build/test/blockchainexplorer.test.d.ts +2 -0
- package/ts_build/test/blockchainexplorer.test.d.ts.map +1 -0
- package/ts_build/test/blockchainexplorer.test.js +98 -0
- package/ts_build/test/blockchainexplorer.test.js.map +1 -0
- package/ts_build/test/chain/bch.test.d.ts +2 -0
- package/ts_build/test/chain/bch.test.d.ts.map +1 -0
- package/ts_build/test/chain/bch.test.js +135 -0
- package/ts_build/test/chain/bch.test.js.map +1 -0
- package/ts_build/test/chain/btc.test.d.ts +2 -0
- package/ts_build/test/chain/btc.test.d.ts.map +1 -0
- package/ts_build/test/chain/btc.test.js +310 -0
- package/ts_build/test/chain/btc.test.js.map +1 -0
- package/ts_build/test/chain/doge.test.d.ts +2 -0
- package/ts_build/test/chain/doge.test.d.ts.map +1 -0
- package/ts_build/test/chain/doge.test.js +343 -0
- package/ts_build/test/chain/doge.test.js.map +1 -0
- package/ts_build/test/chain/eth.test.d.ts +2 -0
- package/ts_build/test/chain/eth.test.d.ts.map +1 -0
- package/ts_build/test/chain/eth.test.js +51 -0
- package/ts_build/test/chain/eth.test.js.map +1 -0
- package/ts_build/test/chain/ltc.test.d.ts +2 -0
- package/ts_build/test/chain/ltc.test.d.ts.map +1 -0
- package/ts_build/test/chain/ltc.test.js +323 -0
- package/ts_build/test/chain/ltc.test.js.map +1 -0
- package/ts_build/test/chain/matic.test.d.ts +2 -0
- package/ts_build/test/chain/matic.test.d.ts.map +1 -0
- package/ts_build/test/chain/matic.test.js +51 -0
- package/ts_build/test/chain/matic.test.js.map +1 -0
- package/ts_build/test/chain/xrp.test.d.ts +2 -0
- package/ts_build/test/chain/xrp.test.d.ts.map +1 -0
- package/ts_build/test/chain/xrp.test.js +228 -0
- package/ts_build/test/chain/xrp.test.js.map +1 -0
- package/ts_build/test/expressapp.test.d.ts +2 -0
- package/ts_build/test/expressapp.test.d.ts.map +1 -0
- package/ts_build/test/expressapp.test.js +523 -0
- package/ts_build/test/expressapp.test.js.map +1 -0
- package/ts_build/test/integration/bcmonitor.test.d.ts +2 -0
- package/ts_build/test/integration/bcmonitor.test.d.ts.map +1 -0
- package/ts_build/test/integration/bcmonitor.test.js +375 -0
- package/ts_build/test/integration/bcmonitor.test.js.map +1 -0
- package/ts_build/test/integration/cashAddrMigration.test.d.ts +2 -0
- package/ts_build/test/integration/cashAddrMigration.test.d.ts.map +1 -0
- package/ts_build/test/integration/cashAddrMigration.test.js +147 -0
- package/ts_build/test/integration/cashAddrMigration.test.js.map +1 -0
- package/ts_build/test/integration/data/tss/2of3/index.d.ts +4 -0
- package/ts_build/test/integration/data/tss/2of3/index.d.ts.map +1 -0
- package/ts_build/test/integration/data/tss/2of3/index.js +20 -0
- package/ts_build/test/integration/data/tss/2of3/index.js.map +1 -0
- package/ts_build/test/integration/data/tss/2of3/party0.key.d.ts +6 -0
- package/ts_build/test/integration/data/tss/2of3/party0.key.d.ts.map +1 -0
- package/ts_build/test/integration/data/tss/2of3/party0.key.js +9 -0
- package/ts_build/test/integration/data/tss/2of3/party0.key.js.map +1 -0
- package/ts_build/test/integration/data/tss/2of3/party1.key.d.ts +6 -0
- package/ts_build/test/integration/data/tss/2of3/party1.key.d.ts.map +1 -0
- package/ts_build/test/integration/data/tss/2of3/party1.key.js +9 -0
- package/ts_build/test/integration/data/tss/2of3/party1.key.js.map +1 -0
- package/ts_build/test/integration/data/tss/2of3/party2.key.d.ts +6 -0
- package/ts_build/test/integration/data/tss/2of3/party2.key.d.ts.map +1 -0
- package/ts_build/test/integration/data/tss/2of3/party2.key.js +9 -0
- package/ts_build/test/integration/data/tss/2of3/party2.key.js.map +1 -0
- package/ts_build/test/integration/emailnotifications.test.d.ts +2 -0
- package/ts_build/test/integration/emailnotifications.test.d.ts.map +1 -0
- package/ts_build/test/integration/emailnotifications.test.js +805 -0
- package/ts_build/test/integration/emailnotifications.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/banxa.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/banxa.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/banxa.test.js +382 -0
- package/ts_build/test/integration/externalservices/banxa.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/changelly.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/changelly.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/changelly.test.js +509 -0
- package/ts_build/test/integration/externalservices/changelly.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/coinGecko.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/coinGecko.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/coinGecko.test.js +295 -0
- package/ts_build/test/integration/externalservices/coinGecko.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/moonpay.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/moonpay.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/moonpay.test.js +567 -0
- package/ts_build/test/integration/externalservices/moonpay.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/oneInch.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/oneInch.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/oneInch.test.js +182 -0
- package/ts_build/test/integration/externalservices/oneInch.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/ramp.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/ramp.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/ramp.test.js +459 -0
- package/ts_build/test/integration/externalservices/ramp.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/sardine.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/sardine.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/sardine.test.js +364 -0
- package/ts_build/test/integration/externalservices/sardine.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/simplex.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/simplex.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/simplex.test.js +383 -0
- package/ts_build/test/integration/externalservices/simplex.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/thorswap.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/thorswap.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/thorswap.test.js +316 -0
- package/ts_build/test/integration/externalservices/thorswap.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/transak.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/transak.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/transak.test.js +409 -0
- package/ts_build/test/integration/externalservices/transak.test.js.map +1 -0
- package/ts_build/test/integration/externalservices/wyre.test.d.ts +2 -0
- package/ts_build/test/integration/externalservices/wyre.test.d.ts.map +1 -0
- package/ts_build/test/integration/externalservices/wyre.test.js +281 -0
- package/ts_build/test/integration/externalservices/wyre.test.js.map +1 -0
- package/ts_build/test/integration/fiatrateservice.test.d.ts +2 -0
- package/ts_build/test/integration/fiatrateservice.test.d.ts.map +1 -0
- package/ts_build/test/integration/fiatrateservice.test.js +838 -0
- package/ts_build/test/integration/fiatrateservice.test.js.map +1 -0
- package/ts_build/test/integration/helpers.d.ts +57 -0
- package/ts_build/test/integration/helpers.d.ts.map +1 -0
- package/ts_build/test/integration/helpers.js +633 -0
- package/ts_build/test/integration/helpers.js.map +1 -0
- package/ts_build/test/integration/history.test.d.ts +2 -0
- package/ts_build/test/integration/history.test.d.ts.map +1 -0
- package/ts_build/test/integration/history.test.js +1064 -0
- package/ts_build/test/integration/history.test.js.map +1 -0
- package/ts_build/test/integration/hugetx.d.ts +46 -0
- package/ts_build/test/integration/hugetx.d.ts.map +1 -0
- package/ts_build/test/integration/hugetx.js +6459 -0
- package/ts_build/test/integration/hugetx.js.map +1 -0
- package/ts_build/test/integration/pushNotifications.test.d.ts +2 -0
- package/ts_build/test/integration/pushNotifications.test.d.ts.map +1 -0
- package/ts_build/test/integration/pushNotifications.test.js +1379 -0
- package/ts_build/test/integration/pushNotifications.test.js.map +1 -0
- package/ts_build/test/integration/server.test.d.ts +2 -0
- package/ts_build/test/integration/server.test.d.ts.map +1 -0
- package/ts_build/test/integration/server.test.js +9980 -0
- package/ts_build/test/integration/server.test.js.map +1 -0
- package/ts_build/test/integration/tss.test.d.ts +2 -0
- package/ts_build/test/integration/tss.test.d.ts.map +1 -0
- package/ts_build/test/integration/tss.test.js +360 -0
- package/ts_build/test/integration/tss.test.js.map +1 -0
- package/ts_build/test/lock.test.d.ts +2 -0
- package/ts_build/test/lock.test.d.ts.map +1 -0
- package/ts_build/test/lock.test.js +226 -0
- package/ts_build/test/lock.test.js.map +1 -0
- package/ts_build/test/model/address.test.d.ts +2 -0
- package/ts_build/test/model/address.test.d.ts.map +1 -0
- package/ts_build/test/model/address.test.js +209 -0
- package/ts_build/test/model/address.test.js.map +1 -0
- package/ts_build/test/model/addressmanager.test.d.ts +2 -0
- package/ts_build/test/model/addressmanager.test.d.ts.map +1 -0
- package/ts_build/test/model/addressmanager.test.js +178 -0
- package/ts_build/test/model/addressmanager.test.js.map +1 -0
- package/ts_build/test/model/advertisement.test.d.ts +2 -0
- package/ts_build/test/model/advertisement.test.d.ts.map +1 -0
- package/ts_build/test/model/advertisement.test.js +61 -0
- package/ts_build/test/model/advertisement.test.js.map +1 -0
- package/ts_build/test/model/copayer.test.d.ts +2 -0
- package/ts_build/test/model/copayer.test.d.ts.map +1 -0
- package/ts_build/test/model/copayer.test.js +161 -0
- package/ts_build/test/model/copayer.test.js.map +1 -0
- package/ts_build/test/model/txproposal.test.d.ts +2 -0
- package/ts_build/test/model/txproposal.test.d.ts.map +1 -0
- package/ts_build/test/model/txproposal.test.js +198 -0
- package/ts_build/test/model/txproposal.test.js.map +1 -0
- package/ts_build/test/model/wallet.test.d.ts +2 -0
- package/ts_build/test/model/wallet.test.d.ts.map +1 -0
- package/ts_build/test/model/wallet.test.js +215 -0
- package/ts_build/test/model/wallet.test.js.map +1 -0
- package/ts_build/test/storage.test.d.ts +2 -0
- package/ts_build/test/storage.test.d.ts.map +1 -0
- package/ts_build/test/storage.test.js +433 -0
- package/ts_build/test/storage.test.js.map +1 -0
- package/ts_build/test/test-config.d.ts +8 -0
- package/ts_build/test/test-config.d.ts.map +1 -0
- package/ts_build/test/test-config.js +14 -0
- package/ts_build/test/test-config.js.map +1 -0
- package/ts_build/test/testdata.d.ts +91 -0
- package/ts_build/test/testdata.d.ts.map +1 -0
- package/ts_build/test/testdata.js +304 -0
- package/ts_build/test/testdata.js.map +1 -0
- package/ts_build/test/utils.test.d.ts +2 -0
- package/ts_build/test/utils.test.d.ts.map +1 -0
- package/ts_build/test/utils.test.js +450 -0
- package/ts_build/test/utils.test.js.map +1 -0
- package/ts_build/test/v8.test.d.ts +2 -0
- package/ts_build/test/v8.test.d.ts.map +1 -0
- package/ts_build/test/v8.test.js +341 -0
- package/ts_build/test/v8.test.js.map +1 -0
- package/tsconfig.json +43 -0
- package/tsconfig.prod.json +6 -0
|
@@ -0,0 +1,991 @@
|
|
|
1
|
+
import { BitcoreLib } from '@bitpay-labs/crypto-wallet-core';
|
|
2
|
+
import * as async from 'async';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import { singleton } from 'preconditions';
|
|
5
|
+
import config from '../../../config';
|
|
6
|
+
import { IChain } from '../../../types/chain';
|
|
7
|
+
import { Common } from '../../common';
|
|
8
|
+
import { ClientError } from '../../errors/clienterror';
|
|
9
|
+
import { Errors } from '../../errors/errordefinitions';
|
|
10
|
+
import logger from '../../logger';
|
|
11
|
+
import { IWallet, TxProposal } from '../../model';
|
|
12
|
+
import { WalletService } from '../../server';
|
|
13
|
+
|
|
14
|
+
const $ = singleton();
|
|
15
|
+
const { Constants, Utils, Defaults } = Common;
|
|
16
|
+
|
|
17
|
+
export class BtcChain implements IChain {
|
|
18
|
+
protected sizeEstimationMargin: number;
|
|
19
|
+
protected inputSizeEstimationMargin: number;
|
|
20
|
+
|
|
21
|
+
constructor(private bitcoreLib = BitcoreLib) {
|
|
22
|
+
this.sizeEstimationMargin = config.btc?.sizeEstimationMargin ?? 0.01;
|
|
23
|
+
this.inputSizeEstimationMargin = config.btc?.inputSizeEstimationMargin ?? 2;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getSizeSafetyMargin(opts: any = {}): number {
|
|
27
|
+
if (opts.conservativeEstimation) {
|
|
28
|
+
return this.sizeEstimationMargin;
|
|
29
|
+
}
|
|
30
|
+
return 0;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
getInputSizeSafetyMargin(opts: any = {}): number {
|
|
34
|
+
if (opts.conservativeEstimation) {
|
|
35
|
+
return this.inputSizeEstimationMargin;
|
|
36
|
+
}
|
|
37
|
+
return 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getWalletBalance(server: WalletService, wallet, opts, cb) {
|
|
41
|
+
server.getUtxosForCurrentWallet(
|
|
42
|
+
{
|
|
43
|
+
coin: opts.coin,
|
|
44
|
+
addresses: opts.addresses
|
|
45
|
+
},
|
|
46
|
+
(err, utxos) => {
|
|
47
|
+
if (err) return cb(err);
|
|
48
|
+
|
|
49
|
+
const balance = {
|
|
50
|
+
...this.totalizeUtxos(utxos),
|
|
51
|
+
byAddress: []
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
// Compute balance by address
|
|
55
|
+
const byAddress = {};
|
|
56
|
+
for (const utxo of utxos) {
|
|
57
|
+
if (!byAddress[utxo.address]) {
|
|
58
|
+
byAddress[utxo.address] = {
|
|
59
|
+
address: utxo.address,
|
|
60
|
+
path: utxo.path,
|
|
61
|
+
amount: 0
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
byAddress[utxo.address].amount += utxo.satoshis;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
balance.byAddress = Object.values(byAddress);
|
|
68
|
+
|
|
69
|
+
return cb(null, balance);
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// opts.payProUrl => only to use different safety margin or not
|
|
75
|
+
getWalletSendMaxInfo(server: WalletService, wallet, opts, cb) {
|
|
76
|
+
server.getUtxosForCurrentWallet({}, (err, utxos) => {
|
|
77
|
+
if (err) return cb(err);
|
|
78
|
+
|
|
79
|
+
const MAX_TX_SIZE_IN_KB = Defaults.MAX_TX_SIZE_IN_KB_BTC;
|
|
80
|
+
|
|
81
|
+
const info = {
|
|
82
|
+
size: 0,
|
|
83
|
+
amount: 0,
|
|
84
|
+
fee: 0,
|
|
85
|
+
feePerKb: 0,
|
|
86
|
+
inputs: [],
|
|
87
|
+
utxosBelowFee: 0,
|
|
88
|
+
amountBelowFee: 0,
|
|
89
|
+
utxosAboveMaxSize: 0,
|
|
90
|
+
amountAboveMaxSize: 0
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
let inputs = utxos.filter(utxo => !utxo.locked);
|
|
94
|
+
if (opts.excludeUnconfirmedUtxos) {
|
|
95
|
+
inputs = inputs.filter(utxo => utxo.confirmations);
|
|
96
|
+
}
|
|
97
|
+
if (!inputs.length) return cb(null, info);
|
|
98
|
+
|
|
99
|
+
inputs = Utils.sortDesc(inputs, 'satoshis');
|
|
100
|
+
|
|
101
|
+
server._getFeePerKb(wallet, opts, (err, feePerKb) => {
|
|
102
|
+
if (err) return cb(err);
|
|
103
|
+
|
|
104
|
+
info.feePerKb = feePerKb;
|
|
105
|
+
|
|
106
|
+
const txp = TxProposal.create({
|
|
107
|
+
walletId: server.walletId,
|
|
108
|
+
coin: wallet.coin,
|
|
109
|
+
addressType: wallet.addressType,
|
|
110
|
+
network: wallet.network,
|
|
111
|
+
walletM: wallet.m,
|
|
112
|
+
walletN: wallet.n,
|
|
113
|
+
feePerKb
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const baseTxpSize = this.getEstimatedSize(txp, { conservativeEstimation: true });
|
|
117
|
+
const sizePerInput = this.getEstimatedSizeForSingleInput(txp, { conservativeEstimation: true });
|
|
118
|
+
const feePerInput = (sizePerInput * txp.feePerKb) / 1000;
|
|
119
|
+
|
|
120
|
+
const partitionedByAmount = [[], []];
|
|
121
|
+
for (const input of inputs) {
|
|
122
|
+
if (input.satoshis > feePerInput) {
|
|
123
|
+
partitionedByAmount[0].push(input);
|
|
124
|
+
} else {
|
|
125
|
+
partitionedByAmount[1].push(input);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
info.utxosBelowFee = partitionedByAmount[1].length;
|
|
130
|
+
info.amountBelowFee = partitionedByAmount[1].reduce((sum, x) => sum + x.satoshis, 0);
|
|
131
|
+
inputs = partitionedByAmount[0];
|
|
132
|
+
|
|
133
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
134
|
+
const input = inputs[i];
|
|
135
|
+
const sizeInKb = (baseTxpSize + (i + 1) * sizePerInput) / 1000;
|
|
136
|
+
if (sizeInKb > MAX_TX_SIZE_IN_KB) {
|
|
137
|
+
info.utxosAboveMaxSize = inputs.length - i;
|
|
138
|
+
info.amountAboveMaxSize = inputs.slice(i).reduce((sum, x) => sum + x.satoshis, 0);
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
txp.inputs.push(input);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!txp.inputs?.length) return cb(null, info);
|
|
145
|
+
|
|
146
|
+
const fee = this.getEstimatedFee(txp, { conservativeEstimation: true });
|
|
147
|
+
const amount = txp.inputs.reduce((sum, x) => sum + x.satoshis, 0) - fee;
|
|
148
|
+
|
|
149
|
+
if (amount < Defaults.MIN_OUTPUT_AMOUNT) return cb(null, info);
|
|
150
|
+
|
|
151
|
+
info.size = this.getEstimatedSize(txp, { conservativeEstimation: true });
|
|
152
|
+
info.fee = fee;
|
|
153
|
+
info.amount = amount;
|
|
154
|
+
|
|
155
|
+
if (opts.returnInputs) {
|
|
156
|
+
info.inputs = _.shuffle(txp.inputs);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return cb(null, info);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
getDustAmountValue() {
|
|
165
|
+
return this.bitcoreLib.Transaction.DUST_AMOUNT;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
getTransactionCount() {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
getChangeAddress(server: WalletService, wallet, opts) {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
const getChangeAddress = (wallet, cb) => {
|
|
175
|
+
if (wallet.singleAddress) {
|
|
176
|
+
server.storage.fetchAddresses(server.walletId, (err, addresses) => {
|
|
177
|
+
if (err) return cb(err);
|
|
178
|
+
if (!addresses?.length) return cb(new ClientError('The wallet has no addresses'));
|
|
179
|
+
return cb(null, addresses[0]);
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
if (opts.changeAddress) {
|
|
183
|
+
try {
|
|
184
|
+
this.validateAddress(wallet, opts.changeAddress, opts);
|
|
185
|
+
} catch (addrErr) {
|
|
186
|
+
return cb(addrErr);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
server.storage.fetchAddressByWalletId(wallet.id, opts.changeAddress, (err, address) => {
|
|
190
|
+
if (err || !address) return cb(Errors.INVALID_CHANGE_ADDRESS);
|
|
191
|
+
return cb(null, address);
|
|
192
|
+
});
|
|
193
|
+
} else {
|
|
194
|
+
const escrowInputs = opts.instantAcceptanceEscrow ? opts.inputs : undefined;
|
|
195
|
+
return cb(null, wallet.createAddress(true, undefined, escrowInputs), true);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
getChangeAddress(wallet, (err, address, _isNew) => {
|
|
201
|
+
if (err) return reject(err);
|
|
202
|
+
return resolve(address);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
checkDust(output) {
|
|
208
|
+
const dustThreshold = Math.max(Defaults.MIN_OUTPUT_AMOUNT, this.bitcoreLib.Transaction.DUST_AMOUNT);
|
|
209
|
+
|
|
210
|
+
if (output.amount < dustThreshold) {
|
|
211
|
+
return Errors.DUST_AMOUNT;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
checkScriptOutput(output) {
|
|
216
|
+
if (output.script) {
|
|
217
|
+
if (typeof output.script !== 'string') {
|
|
218
|
+
return Errors.SCRIPT_TYPE;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// check OP_RETURN
|
|
222
|
+
if (!output.script.startsWith('6a')) {
|
|
223
|
+
return Errors.SCRIPT_OP_RETURN;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// check OP_RETURN amount
|
|
227
|
+
if (output.script.startsWith('6a') && output.amount != 0) {
|
|
228
|
+
return Errors.SCRIPT_OP_RETURN_AMOUNT;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// https://bitcoin.stackexchange.com/questions/88226/how-to-calculate-the-size-of-multisig-transaction
|
|
234
|
+
getEstimatedSizeForSingleInput(txp, opts = { conservativeEstimation: false }) {
|
|
235
|
+
const SIGNATURE_SIZE = 72 + 1; // 73 is for non standanrd, not our wallet. +1 OP_DATA
|
|
236
|
+
const PUBKEY_SIZE = 33 + 1; // +1 OP_DATA
|
|
237
|
+
const inputSafetyMargin = this.getInputSizeSafetyMargin({ conservativeEstimation: opts.conservativeEstimation });
|
|
238
|
+
|
|
239
|
+
switch (txp.addressType) {
|
|
240
|
+
case Constants.SCRIPT_TYPES.P2PKH:
|
|
241
|
+
// https://bitcoin.stackexchange.com/questions/48279/how-big-is-the-input-of-a-p2pkh-transaction
|
|
242
|
+
return 148 + inputSafetyMargin;
|
|
243
|
+
|
|
244
|
+
case Constants.SCRIPT_TYPES.P2WPKH:
|
|
245
|
+
return 69 + inputSafetyMargin; // vsize
|
|
246
|
+
|
|
247
|
+
case Constants.SCRIPT_TYPES.P2TR:
|
|
248
|
+
return 58 + inputSafetyMargin; // vsize
|
|
249
|
+
|
|
250
|
+
case Constants.SCRIPT_TYPES.P2WSH:
|
|
251
|
+
return Math.ceil(32 + 4 + 1 + (5 + txp.requiredSignatures * 74 + txp.walletN * 34) / 4 + 4) + inputSafetyMargin; // vsize
|
|
252
|
+
|
|
253
|
+
case Constants.SCRIPT_TYPES.P2SH:
|
|
254
|
+
return 46 + txp.requiredSignatures * SIGNATURE_SIZE + txp.walletN * PUBKEY_SIZE + inputSafetyMargin;
|
|
255
|
+
|
|
256
|
+
default:
|
|
257
|
+
logger.warn('Unknown address type at getEstimatedSizeForSingleInput: %o', txp.addressType);
|
|
258
|
+
return 46 + txp.requiredSignatures * SIGNATURE_SIZE + txp.walletN * PUBKEY_SIZE + inputSafetyMargin;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Data from:
|
|
263
|
+
// https://bitcoin.stackexchange.com/questions/88226/how-to-calculate-the-size-of-multisig-transaction
|
|
264
|
+
getEstimatedSizeForSingleOutput(address?: string) {
|
|
265
|
+
let addressType = '';
|
|
266
|
+
if (address) {
|
|
267
|
+
const a = this.bitcoreLib.Address(address);
|
|
268
|
+
addressType = a.type;
|
|
269
|
+
}
|
|
270
|
+
return this.getEstimatedSizeForAddressType(addressType);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
getEstimatedSizeForAddressType(addressType?: string) {
|
|
274
|
+
let scriptSize;
|
|
275
|
+
switch (addressType) {
|
|
276
|
+
case 'pubkeyhash':
|
|
277
|
+
scriptSize = 25;
|
|
278
|
+
break;
|
|
279
|
+
case 'scripthash':
|
|
280
|
+
scriptSize = 23;
|
|
281
|
+
break;
|
|
282
|
+
case 'witnesspubkeyhash':
|
|
283
|
+
scriptSize = 22;
|
|
284
|
+
break;
|
|
285
|
+
case 'witnessscripthash':
|
|
286
|
+
scriptSize = 34;
|
|
287
|
+
break;
|
|
288
|
+
default:
|
|
289
|
+
scriptSize = 34;
|
|
290
|
+
// logger.warn('Unknown address type at getEstimatedSizeForSingleOutput: %o', addressType);
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
return scriptSize + 8 + 1; // value + script length
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
getEstimatedSize(txp, opts?) {
|
|
297
|
+
const overhead = 4 + 4 + 1 + 1; // version, locktime, ninputs, noutputs
|
|
298
|
+
// This assumed ALL inputs of the wallet are the same time
|
|
299
|
+
const inputSize = this.getEstimatedSizeForSingleInput(txp, opts);
|
|
300
|
+
const nbInputs = txp.inputs.length;
|
|
301
|
+
let outputsSize = 0;
|
|
302
|
+
const outputs = Array.isArray(txp.outputs) ? txp.outputs : [txp.toAddress];
|
|
303
|
+
const addresses = outputs.map(x => x.toAddress);
|
|
304
|
+
if (txp.changeAddress) {
|
|
305
|
+
addresses.push(txp.changeAddress.address);
|
|
306
|
+
}
|
|
307
|
+
for (const x of addresses) {
|
|
308
|
+
outputsSize += this.getEstimatedSizeForSingleOutput(x);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
if (opts && opts.instantAcceptanceEscrow) {
|
|
312
|
+
outputsSize += this.getEstimatedSizeForAddressType('scripthash');
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// If there is no *output* yet defined, (eg: get sendmax info), add a single, default, output);
|
|
316
|
+
if (!outputsSize) {
|
|
317
|
+
outputsSize = this.getEstimatedSizeForSingleOutput();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
const size = overhead + inputSize * nbInputs + outputsSize;
|
|
321
|
+
return Math.ceil(size * 1 + this.getSizeSafetyMargin(opts));
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
getEstimatedFee(txp, opts) {
|
|
325
|
+
$.checkState(Utils.isNumber(txp.feePerKb), 'Failed state: txp.feePerKb is not a number at <getEstimatedFee()>');
|
|
326
|
+
let fee;
|
|
327
|
+
|
|
328
|
+
// if TX is ready? no estimation is needed.
|
|
329
|
+
if (txp.inputs.length && !txp.changeAddress && txp.outputs.length) {
|
|
330
|
+
const totalInputs = txp.inputs.reduce((sum, x) => sum + x.satoshis, 0);
|
|
331
|
+
const totalOutputs = txp.outputs.reduce((sum, x) => sum + x.amount, 0);
|
|
332
|
+
if (totalInputs && totalOutputs) {
|
|
333
|
+
fee = totalInputs - totalOutputs;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (!fee) {
|
|
338
|
+
fee = (txp.feePerKb * this.getEstimatedSize(txp, opts)) / 1000;
|
|
339
|
+
fee = Math.max(fee, this.bitcoreLib.Transaction.DUST_AMOUNT);
|
|
340
|
+
}
|
|
341
|
+
return parseInt(fee.toFixed(0));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
getFee(server: WalletService, wallet, opts) {
|
|
345
|
+
return new Promise(resolve => {
|
|
346
|
+
server._getFeePerKb(wallet, opts, (err, feePerKb) => {
|
|
347
|
+
return resolve({ feePerKb });
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
getBitcoreTx(txp, opts = { signed: true }) {
|
|
353
|
+
const t = new this.bitcoreLib.Transaction();
|
|
354
|
+
|
|
355
|
+
// BTC tx version
|
|
356
|
+
if (txp.version <= 3) {
|
|
357
|
+
t.setVersion(1);
|
|
358
|
+
} else {
|
|
359
|
+
t.setVersion(2);
|
|
360
|
+
|
|
361
|
+
// set nLockTime (only txp.version>=4)
|
|
362
|
+
if (txp.lockUntilBlockHeight) t.lockUntilBlockHeight(txp.lockUntilBlockHeight);
|
|
363
|
+
}
|
|
364
|
+
if (txp.multiTx) {
|
|
365
|
+
throw Errors.MULTI_TX_UNSUPPORTED;
|
|
366
|
+
}
|
|
367
|
+
/*
|
|
368
|
+
* txp.inputs clean txp.input
|
|
369
|
+
* removes possible nSequence number (BIP68)
|
|
370
|
+
*/
|
|
371
|
+
const inputs = txp.inputs.map(x => {
|
|
372
|
+
return {
|
|
373
|
+
address: x.address,
|
|
374
|
+
txid: x.txid,
|
|
375
|
+
vout: x.vout,
|
|
376
|
+
outputIndex: x.outputIndex,
|
|
377
|
+
scriptPubKey: x.scriptPubKey,
|
|
378
|
+
satoshis: parseInt(x.satoshis),
|
|
379
|
+
publicKeys: x.publicKeys
|
|
380
|
+
};
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
switch (txp.addressType) {
|
|
384
|
+
case Constants.SCRIPT_TYPES.P2WSH:
|
|
385
|
+
case Constants.SCRIPT_TYPES.P2SH:
|
|
386
|
+
for (const i of inputs) {
|
|
387
|
+
$.checkState(i.publicKeys, 'Failed state: Inputs should include public keys at <getBitcoreTx()>');
|
|
388
|
+
t.from(i, i.publicKeys, txp.requiredSignatures);
|
|
389
|
+
}
|
|
390
|
+
break;
|
|
391
|
+
case Constants.SCRIPT_TYPES.P2WPKH:
|
|
392
|
+
case Constants.SCRIPT_TYPES.P2PKH:
|
|
393
|
+
case Constants.SCRIPT_TYPES.P2TR:
|
|
394
|
+
t.from(inputs);
|
|
395
|
+
break;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
for (const o of txp.outputs || []) {
|
|
399
|
+
o.amount = parseInt(o.amount);
|
|
400
|
+
$.checkState(o.script || o.toAddress, 'Failed state: Output should have either toAddress or script specified at <getBitcoreTx()>');
|
|
401
|
+
if (o.script) {
|
|
402
|
+
t.addOutput(
|
|
403
|
+
new this.bitcoreLib.Transaction.Output({
|
|
404
|
+
script: o.script,
|
|
405
|
+
satoshis: o.amount
|
|
406
|
+
})
|
|
407
|
+
);
|
|
408
|
+
} else {
|
|
409
|
+
t.to(o.toAddress, o.amount);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
t.fee(parseInt(txp.fee));
|
|
414
|
+
|
|
415
|
+
if (txp.instantAcceptanceEscrow && txp.escrowAddress) {
|
|
416
|
+
t.escrow(txp.escrowAddress.address, txp.instantAcceptanceEscrow + txp.fee);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (txp.enableRBF) t.enableRBF();
|
|
420
|
+
|
|
421
|
+
if (txp.changeAddress) {
|
|
422
|
+
t.change(txp.changeAddress.address);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Shuffle outputs for improved privacy
|
|
426
|
+
if (t.outputs.length > 1) {
|
|
427
|
+
const outputOrder = (txp.outputOrder || []).filter((order: number) => order < t.outputs.length);
|
|
428
|
+
$.checkState(t.outputs.length == outputOrder.length, 'Failed state: t.outputs.length not equal to outputOrder.length at <getBitcoreTx()>');
|
|
429
|
+
t.sortOutputs(outputs => outputOrder.map(i => outputs[i]));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Validate actual inputs vs outputs independently of Bitcore
|
|
433
|
+
const totalInputs = (t.inputs || []).reduce((sum, x) => sum + (x.output?.satoshis ?? 0), 0);
|
|
434
|
+
const totalOutputs = (t.outputs || []).reduce((sum, x) => sum + (x.satoshis ?? 0), 0);
|
|
435
|
+
|
|
436
|
+
$.checkState(totalInputs > 0 && totalOutputs > 0 && totalInputs >= totalOutputs, 'Failed state: not-enough-inputs at <getBitcoreTx()>');
|
|
437
|
+
$.checkState(totalInputs - totalOutputs <= Defaults.MAX_TX_FEE[txp.coin], 'Failed state: fee-too-high at <getBitcoreTx()>');
|
|
438
|
+
|
|
439
|
+
if (opts.signed) {
|
|
440
|
+
const sigs = txp.getCurrentSignatures();
|
|
441
|
+
for (const x of sigs) {
|
|
442
|
+
this.addSignaturesToBitcoreTx(t, txp.inputs, txp.inputPaths, x.signatures, x.xpub, txp.signingMethod);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return t;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
convertFeePerKb(p, feePerKb) {
|
|
449
|
+
return [p, Utils.strip(feePerKb * 1e8)];
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
checkTx(txp) {
|
|
453
|
+
let bitcoreError;
|
|
454
|
+
const MAX_TX_SIZE_IN_KB = Defaults.MAX_TX_SIZE_IN_KB_BTC;
|
|
455
|
+
|
|
456
|
+
if (this.getEstimatedSize(txp, { conservativeEstimation: true }) / 1000 > MAX_TX_SIZE_IN_KB)
|
|
457
|
+
return Errors.TX_MAX_SIZE_EXCEEDED;
|
|
458
|
+
|
|
459
|
+
const serializationOpts = {
|
|
460
|
+
disableIsFullySigned: true,
|
|
461
|
+
disableSmallFees: true,
|
|
462
|
+
disableLargeFees: true,
|
|
463
|
+
disableDustOutputs: false
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
if (txp.outputs && Array.isArray(txp.outputs)) {
|
|
467
|
+
for (const output of txp.outputs) {
|
|
468
|
+
if (output.script && output.script.startsWith('6a')) { // check OP_RETURN
|
|
469
|
+
serializationOpts.disableDustOutputs = true;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (!txp.inputPaths?.length) return Errors.NO_INPUT_PATHS;
|
|
475
|
+
|
|
476
|
+
try {
|
|
477
|
+
const bitcoreTx = this.getBitcoreTx(txp);
|
|
478
|
+
bitcoreError = bitcoreTx.getSerializationError(serializationOpts);
|
|
479
|
+
if (!bitcoreError) {
|
|
480
|
+
txp.fee = bitcoreTx.getFee();
|
|
481
|
+
}
|
|
482
|
+
} catch (ex) {
|
|
483
|
+
logger.warn('Error building Bitcore transaction: %o', ex);
|
|
484
|
+
return ex;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (bitcoreError instanceof this.bitcoreLib.errors.Transaction.FeeError) {
|
|
488
|
+
return new ClientError(
|
|
489
|
+
Errors.codes.INSUFFICIENT_FUNDS_FOR_FEE,
|
|
490
|
+
`${Errors.INSUFFICIENT_FUNDS_FOR_FEE.message}. RequiredFee: ${txp.fee} Coin: ${txp.coin} feePerKb: ${txp.feePerKb} Err1`,
|
|
491
|
+
{
|
|
492
|
+
coin: txp.coin,
|
|
493
|
+
feePerKb: txp.feePerKb,
|
|
494
|
+
requiredFee: txp.fee
|
|
495
|
+
}
|
|
496
|
+
);
|
|
497
|
+
}
|
|
498
|
+
if (bitcoreError instanceof this.bitcoreLib.errors.Transaction.DustOutputs) return Errors.DUST_AMOUNT;
|
|
499
|
+
return bitcoreError;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
checkTxUTXOs(server: WalletService, txp, opts, cb) {
|
|
503
|
+
logger.debug('Rechecking UTXOs availability for publishTx');
|
|
504
|
+
|
|
505
|
+
if (txp.replaceTxByFee) {
|
|
506
|
+
logger.debug('Ignoring spend utxos check (Replacing tx designated as RBF)');
|
|
507
|
+
return cb();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
const utxoKey = utxo => {
|
|
511
|
+
return utxo.txid + '|' + utxo.vout;
|
|
512
|
+
};
|
|
513
|
+
|
|
514
|
+
server.getUtxosForCurrentWallet(
|
|
515
|
+
{
|
|
516
|
+
addresses: txp.inputs
|
|
517
|
+
},
|
|
518
|
+
(err, utxos) => {
|
|
519
|
+
if (err) return cb(err);
|
|
520
|
+
|
|
521
|
+
const txpInputs = (txp.inputs || []).map(utxoKey);
|
|
522
|
+
const utxosIndex = (utxos || []).reduce((acc, u) => {
|
|
523
|
+
acc[utxoKey(u)] = u;
|
|
524
|
+
return acc;
|
|
525
|
+
}, {});
|
|
526
|
+
const unavailable = txpInputs.some(i => {
|
|
527
|
+
const utxo = utxosIndex[i];
|
|
528
|
+
return !utxo || utxo.locked;
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
if (unavailable) return cb(Errors.UNAVAILABLE_UTXOS);
|
|
532
|
+
return cb();
|
|
533
|
+
}
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
totalizeUtxos(utxos) {
|
|
538
|
+
utxos = utxos || [];
|
|
539
|
+
const balance = {
|
|
540
|
+
totalAmount: utxos.reduce((sum, x) => sum + (x.satoshis ?? 0), 0),
|
|
541
|
+
lockedAmount: utxos.filter(u => u.locked).reduce((sum, x) => sum + (x.satoshis ?? 0), 0),
|
|
542
|
+
totalConfirmedAmount: utxos.filter(u => u.confirmations).reduce((sum, x) => sum + (x.satoshis ?? 0), 0),
|
|
543
|
+
lockedConfirmedAmount: utxos.filter(u => u.locked && u.confirmations).reduce((sum, x) => sum + (x.satoshis ?? 0), 0),
|
|
544
|
+
availableAmount: undefined,
|
|
545
|
+
availableConfirmedAmount: undefined
|
|
546
|
+
};
|
|
547
|
+
balance.availableAmount = balance.totalAmount - balance.lockedAmount;
|
|
548
|
+
balance.availableConfirmedAmount = balance.totalConfirmedAmount - balance.lockedConfirmedAmount;
|
|
549
|
+
|
|
550
|
+
return balance;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
selectTxInputs(server: WalletService, txp, wallet, opts, cb) {
|
|
554
|
+
const MAX_TX_SIZE_IN_KB = Defaults.MAX_TX_SIZE_IN_KB_BTC;
|
|
555
|
+
|
|
556
|
+
// todo: check inputs are ours and have enough value
|
|
557
|
+
if (txp.inputs && txp.inputs.length && !txp.replaceTxByFee) {
|
|
558
|
+
if (!Utils.isNumber(txp.fee)) txp.fee = this.getEstimatedFee(txp, { conservativeEstimation: true });
|
|
559
|
+
return cb(this.checkTx(txp));
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const feeOpts = {
|
|
563
|
+
conservativeEstimation: opts.payProUrl ? true : false,
|
|
564
|
+
instantAcceptanceEscrow: opts.instantAcceptanceEscrow
|
|
565
|
+
};
|
|
566
|
+
const escrowAmount = opts.instantAcceptanceEscrow || 0;
|
|
567
|
+
const txpAmount = txp.getTotalAmount() + escrowAmount;
|
|
568
|
+
const baseTxpSize = this.getEstimatedSize(txp, feeOpts);
|
|
569
|
+
const baseTxpFee = (baseTxpSize * txp.feePerKb) / 1000;
|
|
570
|
+
const sizePerInput = this.getEstimatedSizeForSingleInput(txp, feeOpts);
|
|
571
|
+
const feePerInput = (sizePerInput * txp.feePerKb) / 1000;
|
|
572
|
+
|
|
573
|
+
logger.debug(`Amount ${Utils.formatAmountInBtc(txpAmount)} baseSize ${baseTxpSize} baseTxpFee ${baseTxpFee} sizePerInput ${sizePerInput} feePerInput ${feePerInput}`);
|
|
574
|
+
|
|
575
|
+
const sanitizeUtxos = utxos => {
|
|
576
|
+
const excludeIndex = (opts.utxosToExclude || []).reduce(
|
|
577
|
+
(res, val) => {
|
|
578
|
+
res[val] = val;
|
|
579
|
+
return res;
|
|
580
|
+
},
|
|
581
|
+
{}
|
|
582
|
+
);
|
|
583
|
+
|
|
584
|
+
return (utxos || []).filter(utxo => {
|
|
585
|
+
if (utxo.locked) return false;
|
|
586
|
+
if (txp.excludeUnconfirmedUtxos && !txp.replaceTxByFee && !utxo.confirmations) return false;
|
|
587
|
+
if (excludeIndex[utxo.txid + ':' + utxo.vout]) return false;
|
|
588
|
+
return true;
|
|
589
|
+
});
|
|
590
|
+
};
|
|
591
|
+
|
|
592
|
+
const select = (utxos, requiredInputs, cb) => {
|
|
593
|
+
let requiredTxids = [];
|
|
594
|
+
if (requiredInputs.length > 0 && txp.replaceTxByFee) {
|
|
595
|
+
requiredTxids = requiredInputs.map(x => x.txid);
|
|
596
|
+
}
|
|
597
|
+
let totalValueInUtxos = (utxos || []).reduce((sum, x) => sum + (x.satoshis ?? 0), 0);
|
|
598
|
+
if (totalValueInUtxos < txpAmount) {
|
|
599
|
+
logger.debug(`Total value in all utxos (${Utils.formatAmountInBtc(totalValueInUtxos)}) is insufficient to cover for txp amount (${Utils.formatAmountInBtc(txpAmount)})`);
|
|
600
|
+
return cb(Errors.INSUFFICIENT_FUNDS);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// remove utxos not economically worth to send
|
|
604
|
+
utxos = (utxos || []).filter(utxo => {
|
|
605
|
+
if (requiredTxids.includes(utxo.txid)) return true;
|
|
606
|
+
if (utxo.satoshis <= feePerInput) return false;
|
|
607
|
+
return true;
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
totalValueInUtxos = utxos.reduce((sum, x) => sum + x.satoshis, 0);
|
|
611
|
+
|
|
612
|
+
const netValueInUtxos = totalValueInUtxos - (baseTxpFee - utxos.length * feePerInput);
|
|
613
|
+
|
|
614
|
+
if (netValueInUtxos < txpAmount) {
|
|
615
|
+
logger.debug(`Value after fees in all utxos (${Utils.formatAmountInBtc(netValueInUtxos)}) is insufficient to cover for txp amount (${Utils.formatAmountInBtc(txpAmount)})`);
|
|
616
|
+
|
|
617
|
+
return cb(
|
|
618
|
+
new ClientError(
|
|
619
|
+
Errors.codes.INSUFFICIENT_FUNDS_FOR_FEE,
|
|
620
|
+
`${Errors.INSUFFICIENT_FUNDS_FOR_FEE.message}. RequiredFee: ${baseTxpFee} Coin: ${txp.coin} feePerKb: ${txp.feePerKb} Err2`,
|
|
621
|
+
{
|
|
622
|
+
coin: txp.coin,
|
|
623
|
+
feePerKb: txp.feePerKb,
|
|
624
|
+
requiredFee: baseTxpFee
|
|
625
|
+
}
|
|
626
|
+
)
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const bigInputThreshold = txpAmount * Defaults.UTXO_SELECTION_MAX_SINGLE_UTXO_FACTOR + (baseTxpFee + feePerInput);
|
|
631
|
+
logger.debug(`Big input threshold ${Utils.formatAmountInBtc(bigInputThreshold)}`);
|
|
632
|
+
|
|
633
|
+
const partitions = [[], []];
|
|
634
|
+
for (const utxo of utxos) {
|
|
635
|
+
if (utxo.satoshis > bigInputThreshold) {
|
|
636
|
+
partitions[0].push(utxo);
|
|
637
|
+
} else {
|
|
638
|
+
partitions[1].push(utxo);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
const bigInputs = _.sortBy(partitions[0], [
|
|
643
|
+
utxo => !requiredTxids.includes(utxo.txid),
|
|
644
|
+
'satoshis'
|
|
645
|
+
]);
|
|
646
|
+
const smallInputs = _.sortBy(partitions[1], [
|
|
647
|
+
utxo => !requiredTxids.includes(utxo.txid),
|
|
648
|
+
utxo => -utxo.satoshis
|
|
649
|
+
]);
|
|
650
|
+
|
|
651
|
+
logger.debug(`Considering ${bigInputs.length} big inputs (${Utils.formatUtxos(bigInputs)})`);
|
|
652
|
+
logger.debug(`Considering ${smallInputs.length} small inputs (${Utils.formatUtxos(smallInputs)})`);
|
|
653
|
+
|
|
654
|
+
let total = 0;
|
|
655
|
+
let netTotal = -baseTxpFee;
|
|
656
|
+
let selected = [];
|
|
657
|
+
let fullTxpAmount = txpAmount;
|
|
658
|
+
let fee;
|
|
659
|
+
let error;
|
|
660
|
+
|
|
661
|
+
for (let i = 0; i < smallInputs.length; i++) {
|
|
662
|
+
const input = smallInputs[i];
|
|
663
|
+
logger.debug('Input #' + i + ': ' + Utils.formatUtxos(input));
|
|
664
|
+
|
|
665
|
+
const netInputAmount = input.satoshis - feePerInput;
|
|
666
|
+
|
|
667
|
+
logger.debug('The input contributes ' + Utils.formatAmountInBtc(netInputAmount));
|
|
668
|
+
|
|
669
|
+
selected.push(input);
|
|
670
|
+
|
|
671
|
+
total += input.satoshis;
|
|
672
|
+
netTotal += netInputAmount;
|
|
673
|
+
|
|
674
|
+
const txpSize = baseTxpSize + selected.length * sizePerInput;
|
|
675
|
+
fee = Math.round(baseTxpFee + selected.length * feePerInput);
|
|
676
|
+
|
|
677
|
+
// The escrow address must contain the instantAcceptanceEscrow satoshis specified
|
|
678
|
+
// by the merchant plus the miner fee on the ZCE-secured payment.
|
|
679
|
+
// Rationale: https://github.com/bitjson/bch-zce#zce-extension-to-json-payment-protocol
|
|
680
|
+
fullTxpAmount = escrowAmount ? txpAmount + fee : txpAmount;
|
|
681
|
+
|
|
682
|
+
logger.debug('Tx size: ' + Utils.formatSize(txpSize) + ', Tx fee: ' + Utils.formatAmountInBtc(fee));
|
|
683
|
+
|
|
684
|
+
const feeVsAmountRatio = fee / fullTxpAmount;
|
|
685
|
+
const amountVsUtxoRatio = netInputAmount / fullTxpAmount;
|
|
686
|
+
|
|
687
|
+
// logger.debug('Fee/Tx amount: ' + Utils.formatRatio(feeVsAmountRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) + ')');
|
|
688
|
+
// logger.debug('Tx amount/Input amount:' + Utils.formatRatio(amountVsUtxoRatio) + ' (min: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) + ')');
|
|
689
|
+
|
|
690
|
+
if (txpSize / 1000 > MAX_TX_SIZE_IN_KB) {
|
|
691
|
+
// logger.debug('Breaking because tx size (' + Utils.formatSize(txpSize) + ') is too big (max: ' + Utils.formatSize(this.MAX_TX_SIZE_IN_KB * 1000.) + ')');
|
|
692
|
+
error = Errors.TX_MAX_SIZE_EXCEEDED;
|
|
693
|
+
break;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
if (bigInputs?.length) {
|
|
697
|
+
if (amountVsUtxoRatio < Defaults.UTXO_SELECTION_MIN_TX_AMOUNT_VS_UTXO_FACTOR) {
|
|
698
|
+
// logger.debug('Breaking because utxo is too small compared to tx amount');
|
|
699
|
+
break;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
if (feeVsAmountRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_TX_AMOUNT_FACTOR) {
|
|
703
|
+
const feeVsSingleInputFeeRatio = fee / (baseTxpFee + feePerInput);
|
|
704
|
+
// logger.debug('Fee/Single-input fee: ' + Utils.formatRatio(feeVsSingleInputFeeRatio) + ' (max: ' + Utils.formatRatio(Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) + ')' + ' loses wrt single-input tx: ' + Utils.formatAmountInBtc((selected.length - 1) * feePerInput));
|
|
705
|
+
if (feeVsSingleInputFeeRatio > Defaults.UTXO_SELECTION_MAX_FEE_VS_SINGLE_UTXO_FEE_FACTOR) {
|
|
706
|
+
// logger.debug('Breaking because fee is too significant compared to tx amount and it is too expensive compared to using single input');
|
|
707
|
+
break;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
logger.debug(`Cumuled total so far: ${Utils.formatAmountInBtc(total)}, Net total so far: ${Utils.formatAmountInBtc(netTotal)}`);
|
|
713
|
+
|
|
714
|
+
if (netTotal >= fullTxpAmount) {
|
|
715
|
+
const changeAmount = Math.round(total - fullTxpAmount - fee);
|
|
716
|
+
logger.debug('Tx change: %o', Utils.formatAmountInBtc(changeAmount));
|
|
717
|
+
|
|
718
|
+
const dustThreshold = Math.max(Defaults.MIN_OUTPUT_AMOUNT, this.bitcoreLib.Transaction.DUST_AMOUNT);
|
|
719
|
+
if (changeAmount > 0 && changeAmount <= dustThreshold) {
|
|
720
|
+
logger.debug(`Change below dust threshold (${Utils.formatAmountInBtc(dustThreshold)}). Incrementing fee to remove change.`);
|
|
721
|
+
// Remove dust change by incrementing fee
|
|
722
|
+
fee += changeAmount;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
break;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
if (netTotal < fullTxpAmount) {
|
|
730
|
+
logger.debug(`Could not reach Txp total (${Utils.formatAmountInBtc(fullTxpAmount)}), still missing: ${Utils.formatAmountInBtc(fullTxpAmount - netTotal)}`);
|
|
731
|
+
|
|
732
|
+
selected = [];
|
|
733
|
+
if (bigInputs?.length) {
|
|
734
|
+
const input = bigInputs[0];
|
|
735
|
+
logger.debug(`Using big input: ${Utils.formatUtxos(input)}`);
|
|
736
|
+
total = input.satoshis;
|
|
737
|
+
fee = Math.round(baseTxpFee + feePerInput);
|
|
738
|
+
netTotal = total - fee;
|
|
739
|
+
selected = [input];
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
if (!selected.length) {
|
|
744
|
+
// logger.debug('Could not find enough funds within this utxo subset');
|
|
745
|
+
return cb(
|
|
746
|
+
error ||
|
|
747
|
+
new ClientError(
|
|
748
|
+
Errors.codes.INSUFFICIENT_FUNDS_FOR_FEE,
|
|
749
|
+
`${Errors.INSUFFICIENT_FUNDS_FOR_FEE.message}. RequiredFee: ${fee} Coin: ${txp.coin} feePerKb: ${txp.feePerKb} Err3`,
|
|
750
|
+
{
|
|
751
|
+
coin: txp.coin,
|
|
752
|
+
feePerKb: txp.feePerKb,
|
|
753
|
+
requiredFee: fee
|
|
754
|
+
}
|
|
755
|
+
)
|
|
756
|
+
);
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
return cb(null, selected, fee);
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
// logger.debug('Selecting inputs for a ' + Utils.formatAmountInBtc(txp.getTotalAmount()) + ' txp');
|
|
763
|
+
|
|
764
|
+
server.getUtxosForCurrentWallet(
|
|
765
|
+
{
|
|
766
|
+
instantAcceptanceEscrow: txp.instantAcceptanceEscrow,
|
|
767
|
+
replaceTxByFee: txp.replaceTxByFee,
|
|
768
|
+
inputs: txp.inputs
|
|
769
|
+
},
|
|
770
|
+
(err, utxos) => {
|
|
771
|
+
if (err) return cb(err);
|
|
772
|
+
|
|
773
|
+
let totalAmount;
|
|
774
|
+
let availableAmount;
|
|
775
|
+
|
|
776
|
+
const balance = this.totalizeUtxos(utxos);
|
|
777
|
+
if (txp.excludeUnconfirmedUtxos && !txp.replaceTxByFee) {
|
|
778
|
+
totalAmount = balance.totalConfirmedAmount;
|
|
779
|
+
availableAmount = balance.availableConfirmedAmount;
|
|
780
|
+
} else {
|
|
781
|
+
totalAmount = balance.totalAmount;
|
|
782
|
+
availableAmount = balance.availableAmount;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
if (totalAmount < txp.getTotalAmount()) return cb(Errors.INSUFFICIENT_FUNDS);
|
|
786
|
+
if (availableAmount < txp.getTotalAmount()) return cb(Errors.LOCKED_FUNDS);
|
|
787
|
+
|
|
788
|
+
utxos = sanitizeUtxos(utxos);
|
|
789
|
+
|
|
790
|
+
// logger.debug('Considering ' + utxos.length + ' utxos (' + Utils.formatUtxos(utxos) + ')');
|
|
791
|
+
|
|
792
|
+
const groups = [6, 1];
|
|
793
|
+
if (!txp.excludeUnconfirmedUtxos) groups.push(0);
|
|
794
|
+
|
|
795
|
+
let inputs = [];
|
|
796
|
+
let fee;
|
|
797
|
+
let selectionError;
|
|
798
|
+
let i = 0;
|
|
799
|
+
let lastGroupLength;
|
|
800
|
+
async.whilst(
|
|
801
|
+
() => {
|
|
802
|
+
return i < groups.length && !inputs?.length;
|
|
803
|
+
},
|
|
804
|
+
next => {
|
|
805
|
+
const group = groups[i++];
|
|
806
|
+
|
|
807
|
+
let candidateUtxos = utxos.filter(utxo => {
|
|
808
|
+
return utxo.confirmations >= group;
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
if (opts.instantAcceptanceEscrow && wallet.isZceCompatible()) {
|
|
812
|
+
const utxosSortedByDescendingAmount = candidateUtxos.sort((a, b) => b.amount - a.amount);
|
|
813
|
+
const utxosWithUniqueAddresses = _.uniqBy(utxosSortedByDescendingAmount, 'address');
|
|
814
|
+
candidateUtxos = utxosWithUniqueAddresses;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
if (txp.replaceTxByFee) {
|
|
818
|
+
// make sure we are using at least one input from the transaction that we are replacing
|
|
819
|
+
const txIdArray: any[] = (opts.inputs || []).map(input => input.txid);
|
|
820
|
+
candidateUtxos = candidateUtxos.sort((a, b) => {
|
|
821
|
+
return txIdArray.indexOf(b.txid) - txIdArray.indexOf(a.txid);
|
|
822
|
+
});
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// logger.debug('Group >= ' + group);
|
|
826
|
+
|
|
827
|
+
// If this group does not have any new elements, skip it
|
|
828
|
+
if (lastGroupLength === candidateUtxos.length) {
|
|
829
|
+
// logger.debug('This group is identical to the one already explored');
|
|
830
|
+
return next();
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
// logger.debug('Candidate utxos: ' + Utils.formatUtxos(candidateUtxos));
|
|
834
|
+
|
|
835
|
+
lastGroupLength = candidateUtxos.length;
|
|
836
|
+
|
|
837
|
+
select(candidateUtxos, txp.inputs, (err, selectedInputs, selectedFee) => {
|
|
838
|
+
if (err) {
|
|
839
|
+
// logger.debug('No inputs selected on this group: ', err);
|
|
840
|
+
selectionError = err;
|
|
841
|
+
return next();
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
selectionError = null;
|
|
845
|
+
inputs = selectedInputs;
|
|
846
|
+
fee = selectedFee;
|
|
847
|
+
|
|
848
|
+
logger.debug('Selected inputs from this group: ' + Utils.formatUtxos(inputs));
|
|
849
|
+
logger.debug('Fee for this selection: ' + Utils.formatAmountInBtc(fee));
|
|
850
|
+
|
|
851
|
+
return next();
|
|
852
|
+
});
|
|
853
|
+
},
|
|
854
|
+
err => {
|
|
855
|
+
if (err) return cb(err);
|
|
856
|
+
if (selectionError || !inputs?.length)
|
|
857
|
+
return cb(selectionError || new Error('Could not select tx inputs'));
|
|
858
|
+
|
|
859
|
+
txp.setInputs(_.shuffle(inputs));
|
|
860
|
+
txp.fee = fee;
|
|
861
|
+
|
|
862
|
+
err = this.checkTx(txp);
|
|
863
|
+
if (!err) {
|
|
864
|
+
const sumInputs = txp.inputs.reduce((sum, input) => sum + input.satoshis, 0);
|
|
865
|
+
const sumOutputs = txp.outputs.reduce((sum, output) => sum + output.amount, 0);
|
|
866
|
+
const change = sumInputs - sumOutputs - txp.fee;
|
|
867
|
+
logger.debug(`Successfully built transaction. Total fees: ${Utils.formatAmountInBtc(txp.fee)}, total change: ${Utils.formatAmountInBtc(change)}`);
|
|
868
|
+
} else {
|
|
869
|
+
logger.warn('Error building transaction: %o', err);
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
return cb(err);
|
|
873
|
+
}
|
|
874
|
+
);
|
|
875
|
+
}
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
checkUtxos(opts) {
|
|
880
|
+
if (Utils.isNumber(opts.fee) && !opts.inputs?.length) return true;
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
checkValidTxAmount(output): boolean {
|
|
884
|
+
return Utils.isNumber(output.amount) && output.amount > 0;
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
supportsMultisig() {
|
|
888
|
+
return true;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
supportsThresholdsig() {
|
|
892
|
+
return true;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
notifyConfirmations(network: string) {
|
|
896
|
+
if (network != 'livenet') return false;
|
|
897
|
+
|
|
898
|
+
return true;
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
isUTXOChain() {
|
|
902
|
+
return true;
|
|
903
|
+
}
|
|
904
|
+
isSingleAddress() {
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
addressFromStorageTransform(_network, _address) {}
|
|
909
|
+
|
|
910
|
+
addressToStorageTransform(_network, _address) {}
|
|
911
|
+
|
|
912
|
+
addSignaturesToBitcoreTx(tx, inputs, inputPaths, signatures, xpub, signingMethod) {
|
|
913
|
+
signingMethod = signingMethod || 'ecdsa';
|
|
914
|
+
if (signatures.length != inputs.length) throw new Error('Number of signatures does not match number of inputs');
|
|
915
|
+
|
|
916
|
+
let i = 0;
|
|
917
|
+
const x = new this.bitcoreLib.HDPublicKey(xpub);
|
|
918
|
+
|
|
919
|
+
for (const signatureHex of signatures) {
|
|
920
|
+
try {
|
|
921
|
+
const signature = this.bitcoreLib.crypto.Signature.fromString(signatureHex);
|
|
922
|
+
const pub = x.deriveChild(inputPaths[i]).publicKey;
|
|
923
|
+
// eslint-disable-next-line no-bitwise
|
|
924
|
+
const SIGHASH_TYPE = this.bitcoreLib.crypto.Signature.SIGHASH_ALL | this.bitcoreLib.crypto.Signature.SIGHASH_FORKID;
|
|
925
|
+
const s = {
|
|
926
|
+
inputIndex: i,
|
|
927
|
+
signature,
|
|
928
|
+
sigtype: SIGHASH_TYPE,
|
|
929
|
+
publicKey: pub
|
|
930
|
+
};
|
|
931
|
+
tx.inputs[i].addSignature(tx, s, signingMethod);
|
|
932
|
+
i++;
|
|
933
|
+
} catch { /* ignore error */ }
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
if (i != tx.inputs.length) throw new Error('Wrong signatures');
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
validateAddress(wallet, inaddr, _opts) {
|
|
940
|
+
const A = this.bitcoreLib.Address;
|
|
941
|
+
let addr: {
|
|
942
|
+
network?: string;
|
|
943
|
+
toString?: (cashAddr: boolean) => string;
|
|
944
|
+
} = {};
|
|
945
|
+
try {
|
|
946
|
+
addr = new A(inaddr);
|
|
947
|
+
} catch {
|
|
948
|
+
throw Errors.INVALID_ADDRESS;
|
|
949
|
+
}
|
|
950
|
+
if (!this._isCorrectNetwork(wallet, addr)) {
|
|
951
|
+
throw Errors.INCORRECT_ADDRESS_NETWORK;
|
|
952
|
+
}
|
|
953
|
+
return;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
protected _isCorrectNetwork(wallet, addr) {
|
|
957
|
+
const addrNetwork = Utils.getNetworkName(wallet.chain, addr.network.toString());
|
|
958
|
+
const walNetwork = wallet.network;
|
|
959
|
+
if (Utils.getNetworkType(addrNetwork) === 'testnet' && walNetwork === 'regtest') {
|
|
960
|
+
return !!config.allowRegtest;
|
|
961
|
+
}
|
|
962
|
+
return addrNetwork === walNetwork;
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
// Push notification handling
|
|
966
|
+
onCoin(coin) {
|
|
967
|
+
// script output, or similar.
|
|
968
|
+
if (!coin || !coin.address) return;
|
|
969
|
+
|
|
970
|
+
return {
|
|
971
|
+
out: {
|
|
972
|
+
address: coin.address,
|
|
973
|
+
amount: coin.value
|
|
974
|
+
},
|
|
975
|
+
txid: coin.mintTxid
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
// Push notification handling
|
|
980
|
+
onTx(_tx) {
|
|
981
|
+
return null;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
getReserve(server: WalletService, wallet: IWallet, cb: (err?, reserve?: number) => void) {
|
|
985
|
+
return cb(null, 0);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
refreshTxData(_server: WalletService, txp, _opts, cb) {
|
|
989
|
+
return cb(null, txp);
|
|
990
|
+
}
|
|
991
|
+
}
|