mainnet-js 0.5.9 → 1.0.0-rc.1
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/dist/index.html +9 -1
- package/dist/mainnet-1.0.0-rc.1.js +2928 -0
- package/dist/module/chain.d.ts +1 -0
- package/dist/module/chain.d.ts.map +1 -0
- package/dist/module/cli.d.ts +1 -0
- package/dist/module/cli.d.ts.map +1 -0
- package/dist/module/cli.js +2 -2
- package/dist/module/cli.js.map +1 -1
- package/dist/module/constant.d.ts +1 -0
- package/dist/module/constant.d.ts.map +1 -0
- package/dist/module/db/ExchangeRateProvider.d.ts +2 -1
- package/dist/module/db/ExchangeRateProvider.d.ts.map +1 -0
- package/dist/module/db/IndexedDBProvider.d.ts +3 -2
- package/dist/module/db/IndexedDBProvider.d.ts.map +1 -0
- package/dist/module/db/SqlProvider.d.ts +7 -8
- package/dist/module/db/SqlProvider.d.ts.map +1 -0
- package/dist/module/db/SqlProvider.js +10 -8
- package/dist/module/db/SqlProvider.js.map +1 -1
- package/dist/module/db/StorageProvider.d.ts +2 -1
- package/dist/module/db/StorageProvider.d.ts.map +1 -0
- package/dist/module/db/getStorageProvider.d.ts +3 -0
- package/dist/module/db/getStorageProvider.d.ts.map +1 -0
- package/dist/module/db/getStorageProvider.js +19 -0
- package/dist/module/db/getStorageProvider.js.map +1 -0
- package/dist/module/db/index.d.ts +4 -3
- package/dist/module/db/index.d.ts.map +1 -0
- package/dist/module/db/index.js +2 -2
- package/dist/module/db/index.js.map +1 -1
- package/dist/module/db/interface.d.ts +1 -0
- package/dist/module/db/interface.d.ts.map +1 -0
- package/dist/module/db/util.d.ts +2 -3
- package/dist/module/db/util.d.ts.map +1 -0
- package/dist/module/db/util.js +0 -17
- package/dist/module/db/util.js.map +1 -1
- package/dist/module/enum.d.ts +1 -0
- package/dist/module/enum.d.ts.map +1 -0
- package/dist/module/history/electrumTransformer.d.ts +3 -2
- package/dist/module/history/electrumTransformer.d.ts.map +1 -0
- package/dist/module/history/electrumTransformer.js +11 -11
- package/dist/module/history/electrumTransformer.js.map +1 -1
- package/dist/module/history/interface.d.ts +2 -1
- package/dist/module/history/interface.d.ts.map +1 -0
- package/dist/module/index.d.ts +26 -21
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +25 -17
- package/dist/module/index.js.map +1 -1
- package/dist/module/interface.d.ts +14 -0
- package/dist/module/interface.d.ts.map +1 -0
- package/dist/module/interface.js +5 -0
- package/dist/module/interface.js.map +1 -1
- package/dist/module/message/index.d.ts +3 -2
- package/dist/module/message/index.d.ts.map +1 -0
- package/dist/module/message/index.js +2 -2
- package/dist/module/message/index.js.map +1 -1
- package/dist/module/message/interface.d.ts +1 -0
- package/dist/module/message/interface.d.ts.map +1 -0
- package/dist/module/message/signed.d.ts +2 -1
- package/dist/module/message/signed.d.ts.map +1 -0
- package/dist/module/message/signed.js +10 -4
- package/dist/module/message/signed.js.map +1 -1
- package/dist/module/mine/index.d.ts +2 -1
- package/dist/module/mine/index.d.ts.map +1 -0
- package/dist/module/mine/index.js +1 -1
- package/dist/module/mine/index.js.map +1 -1
- package/dist/module/mine/mine.d.ts +1 -0
- package/dist/module/mine/mine.d.ts.map +1 -0
- package/dist/module/mine/mine.js +3 -3
- package/dist/module/mine/mine.js.map +1 -1
- package/dist/module/network/Connection.d.ts +3 -2
- package/dist/module/network/Connection.d.ts.map +1 -0
- package/dist/module/network/Connection.js +3 -3
- package/dist/module/network/Connection.js.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.d.ts +8 -5
- package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -0
- package/dist/module/network/ElectrumNetworkProvider.js +59 -13
- package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
- package/dist/module/network/NetworkProvider.d.ts +2 -1
- package/dist/module/network/NetworkProvider.d.ts.map +1 -0
- package/dist/module/network/configuration.d.ts +8 -10
- package/dist/module/network/configuration.d.ts.map +1 -0
- package/dist/module/network/configuration.js +29 -17
- package/dist/module/network/configuration.js.map +1 -1
- package/dist/module/network/constant.d.ts +1 -0
- package/dist/module/network/constant.d.ts.map +1 -0
- package/dist/module/network/constant.js +8 -4
- package/dist/module/network/constant.js.map +1 -1
- package/dist/module/network/default.d.ts +4 -3
- package/dist/module/network/default.d.ts.map +1 -0
- package/dist/module/network/default.js +7 -7
- package/dist/module/network/default.js.map +1 -1
- package/dist/module/network/getRelayFeeCache.d.ts +2 -1
- package/dist/module/network/getRelayFeeCache.d.ts.map +1 -0
- package/dist/module/network/getRelayFeeCache.js +2 -2
- package/dist/module/network/getRelayFeeCache.js.map +1 -1
- package/dist/module/network/index.d.ts +3 -2
- package/dist/module/network/index.d.ts.map +1 -0
- package/dist/module/network/index.js +2 -2
- package/dist/module/network/index.js.map +1 -1
- package/dist/module/network/interface.d.ts +1 -0
- package/dist/module/network/interface.d.ts.map +1 -0
- package/dist/module/network/util.d.ts +2 -1
- package/dist/module/network/util.d.ts.map +1 -0
- package/dist/module/qr/Qr.d.ts +2 -1
- package/dist/module/qr/Qr.d.ts.map +1 -0
- package/dist/module/qr/Qr.js +2 -2
- package/dist/module/qr/Qr.js.map +1 -1
- package/dist/module/qr/interface.d.ts +1 -0
- package/dist/module/qr/interface.d.ts.map +1 -0
- package/dist/module/rate/ExchangeRate.d.ts +1 -0
- package/dist/module/rate/ExchangeRate.d.ts.map +1 -0
- package/dist/module/rate/ExchangeRate.js +5 -5
- package/dist/module/rate/ExchangeRate.js.map +1 -1
- package/dist/module/slp/GsppProvider.d.ts +4 -3
- package/dist/module/slp/GsppProvider.d.ts.map +1 -0
- package/dist/module/slp/GsppProvider.js +7 -7
- package/dist/module/slp/GsppProvider.js.map +1 -1
- package/dist/module/slp/SlpDbProvider.d.ts +4 -3
- package/dist/module/slp/SlpDbProvider.d.ts.map +1 -0
- package/dist/module/slp/SlpDbProvider.js +8 -8
- package/dist/module/slp/SlpDbProvider.js.map +1 -1
- package/dist/module/slp/SlpDbTemplates.d.ts +1 -0
- package/dist/module/slp/SlpDbTemplates.d.ts.map +1 -0
- package/dist/module/slp/SlpLibAuth.d.ts +7 -14
- package/dist/module/slp/SlpLibAuth.d.ts.map +1 -0
- package/dist/module/slp/SlpLibAuth.js +48 -39
- package/dist/module/slp/SlpLibAuth.js.map +1 -1
- package/dist/module/slp/SlpProvider.d.ts +2 -1
- package/dist/module/slp/SlpProvider.d.ts.map +1 -0
- package/dist/module/slp/SlpProvider.js.map +1 -1
- package/dist/module/slp/index.d.ts +5 -4
- package/dist/module/slp/index.d.ts.map +1 -0
- package/dist/module/slp/index.js +3 -3
- package/dist/module/slp/index.js.map +1 -1
- package/dist/module/slp/interface.d.ts +2 -1
- package/dist/module/slp/interface.d.ts.map +1 -0
- package/dist/module/test/axios.d.ts +3 -0
- package/dist/module/test/axios.d.ts.map +1 -0
- package/dist/module/test/axios.js +35 -0
- package/dist/module/test/axios.js.map +1 -0
- package/dist/module/test/expect.d.ts +6 -1
- package/dist/module/test/expect.d.ts.map +1 -0
- package/dist/module/test/expect.js +22 -1
- package/dist/module/test/expect.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +19 -16
- package/dist/module/transaction/Wif.d.ts.map +1 -0
- package/dist/module/transaction/Wif.js +152 -55
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/transaction/allocateFee.d.ts +5 -4
- package/dist/module/transaction/allocateFee.d.ts.map +1 -0
- package/dist/module/transaction/allocateFee.js +11 -8
- package/dist/module/transaction/allocateFee.js.map +1 -1
- package/dist/module/util/amountInSatoshi.d.ts +1 -0
- package/dist/module/util/amountInSatoshi.d.ts.map +1 -0
- package/dist/module/util/amountInSatoshi.js +4 -4
- package/dist/module/util/amountInSatoshi.js.map +1 -1
- package/dist/module/util/asSendRequestObject.d.ts +3 -2
- package/dist/module/util/asSendRequestObject.d.ts.map +1 -0
- package/dist/module/util/asSendRequestObject.js +6 -3
- package/dist/module/util/asSendRequestObject.js.map +1 -1
- package/dist/module/util/balanceObjectFromSatoshi.d.ts +1 -0
- package/dist/module/util/balanceObjectFromSatoshi.d.ts.map +1 -0
- package/dist/module/util/balanceObjectFromSatoshi.js +5 -5
- package/dist/module/util/balanceObjectFromSatoshi.js.map +1 -1
- package/dist/module/util/base64.d.ts +2 -1
- package/dist/module/util/base64.d.ts.map +1 -0
- package/dist/module/util/base64.js +5 -25
- package/dist/module/util/base64.js.map +1 -1
- package/dist/module/util/bchaddr.d.ts +1 -0
- package/dist/module/util/bchaddr.d.ts.map +1 -0
- package/dist/module/util/browserNotSupported.d.ts +1 -0
- package/dist/module/util/browserNotSupported.d.ts.map +1 -0
- package/dist/module/util/browserNotSupported.js +1 -1
- package/dist/module/util/browserNotSupported.js.map +1 -1
- package/dist/module/util/checkForEmptySeed.d.ts +1 -0
- package/dist/module/util/checkForEmptySeed.d.ts.map +1 -0
- package/dist/module/util/checkWifNetwork.d.ts +2 -1
- package/dist/module/util/checkWifNetwork.d.ts.map +1 -0
- package/dist/module/util/checkWifNetwork.js +1 -1
- package/dist/module/util/checkWifNetwork.js.map +1 -1
- package/dist/module/util/convert.d.ts +1 -0
- package/dist/module/util/convert.d.ts.map +1 -0
- package/dist/module/util/convert.js +2 -2
- package/dist/module/util/convert.js.map +1 -1
- package/dist/module/util/delay.d.ts +1 -0
- package/dist/module/util/delay.d.ts.map +1 -0
- package/dist/module/util/deriveCashaddr.d.ts +6 -1
- package/dist/module/util/deriveCashaddr.d.ts.map +1 -0
- package/dist/module/util/deriveCashaddr.js +85 -6
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/util/deriveLockscript.d.ts +1 -0
- package/dist/module/util/deriveLockscript.d.ts.map +1 -0
- package/dist/module/util/deriveNetwork.d.ts +1 -0
- package/dist/module/util/deriveNetwork.d.ts.map +1 -0
- package/dist/module/util/deriveNetwork.js +2 -2
- package/dist/module/util/deriveNetwork.js.map +1 -1
- package/dist/module/util/derivePublicKeyHash.d.ts +3 -1
- package/dist/module/util/derivePublicKeyHash.d.ts.map +1 -0
- package/dist/module/util/derivePublicKeyHash.js +1 -1
- package/dist/module/util/derivePublicKeyHash.js.map +1 -1
- package/dist/module/util/eventsource.d.ts +1 -0
- package/dist/module/util/eventsource.d.ts.map +1 -0
- package/dist/module/util/eventsource.js +3 -2
- package/dist/module/util/eventsource.js.map +1 -1
- package/dist/module/util/floor.d.ts +1 -0
- package/dist/module/util/floor.d.ts.map +1 -0
- package/dist/module/util/getAddrsByXpubKey.d.ts +8 -8
- package/dist/module/util/getAddrsByXpubKey.d.ts.map +1 -0
- package/dist/module/util/getAddrsByXpubKey.js +17 -21
- package/dist/module/util/getAddrsByXpubKey.js.map +1 -1
- package/dist/module/util/getRuntimePlatform.d.ts +1 -0
- package/dist/module/util/getRuntimePlatform.d.ts.map +1 -0
- package/dist/module/util/getUsdRate.d.ts +1 -0
- package/dist/module/util/getUsdRate.d.ts.map +1 -0
- package/dist/module/util/getUsdRate.js +1 -1
- package/dist/module/util/getUsdRate.js.map +1 -1
- package/dist/module/util/getXPubKey.d.ts +2 -1
- package/dist/module/util/getXPubKey.d.ts.map +1 -0
- package/dist/module/util/getXPubKey.js +6 -7
- package/dist/module/util/getXPubKey.js.map +1 -1
- package/dist/module/util/hash160.d.ts +2 -1
- package/dist/module/util/hash160.d.ts.map +1 -0
- package/dist/module/util/hash160.js +2 -4
- package/dist/module/util/hash160.js.map +1 -1
- package/dist/module/util/index.d.ts +21 -20
- package/dist/module/util/index.d.ts.map +1 -0
- package/dist/module/util/index.js +20 -20
- package/dist/module/util/index.js.map +1 -1
- package/dist/module/util/randomBytes.d.ts +3 -1
- package/dist/module/util/randomBytes.d.ts.map +1 -0
- package/dist/module/util/randomBytes.js +2 -3
- package/dist/module/util/randomBytes.js.map +1 -1
- package/dist/module/util/randomInt.d.ts +1 -0
- package/dist/module/util/randomInt.d.ts.map +1 -0
- package/dist/module/util/randomValues.d.ts +1 -0
- package/dist/module/util/randomValues.d.ts.map +1 -0
- package/dist/module/util/randomValues.js +7 -7
- package/dist/module/util/randomValues.js.map +1 -1
- package/dist/module/util/sanitizeAddress.d.ts +1 -0
- package/dist/module/util/sanitizeAddress.d.ts.map +1 -0
- package/dist/module/util/sanitizeAddress.js +1 -1
- package/dist/module/util/sanitizeAddress.js.map +1 -1
- package/dist/module/util/sanitizeUnit.d.ts +2 -1
- package/dist/module/util/sanitizeUnit.d.ts.map +1 -0
- package/dist/module/util/satoshiToAmount.d.ts +1 -0
- package/dist/module/util/satoshiToAmount.d.ts.map +1 -0
- package/dist/module/util/satoshiToAmount.js +4 -4
- package/dist/module/util/satoshiToAmount.js.map +1 -1
- package/dist/module/util/sumSendRequestAmounts.d.ts +3 -2
- package/dist/module/util/sumSendRequestAmounts.d.ts.map +1 -0
- package/dist/module/util/sumSendRequestAmounts.js +5 -2
- package/dist/module/util/sumSendRequestAmounts.js.map +1 -1
- package/dist/module/util/sumUtxoValue.d.ts +4 -2
- package/dist/module/util/sumUtxoValue.d.ts.map +1 -0
- package/dist/module/util/sumUtxoValue.js +17 -3
- package/dist/module/util/sumUtxoValue.js.map +1 -1
- package/dist/module/util/transaction.d.ts +2 -0
- package/dist/module/util/transaction.d.ts.map +1 -0
- package/dist/module/util/transaction.js +7 -0
- package/dist/module/util/transaction.js.map +1 -0
- package/dist/module/wallet/Base.d.ts +8 -7
- package/dist/module/wallet/Base.d.ts.map +1 -0
- package/dist/module/wallet/Base.js +7 -7
- package/dist/module/wallet/Base.js.map +1 -1
- package/dist/module/wallet/Bcmr.d.ts +88 -0
- package/dist/module/wallet/Bcmr.d.ts.map +1 -0
- package/dist/module/wallet/Bcmr.js +281 -0
- package/dist/module/wallet/Bcmr.js.map +1 -0
- package/dist/module/wallet/Slp.d.ts +6 -5
- package/dist/module/wallet/Slp.d.ts.map +1 -0
- package/dist/module/wallet/Slp.js +15 -15
- package/dist/module/wallet/Slp.js.map +1 -1
- package/dist/module/wallet/Util.d.ts +3 -2
- package/dist/module/wallet/Util.d.ts.map +1 -0
- package/dist/module/wallet/Util.js +9 -14
- package/dist/module/wallet/Util.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +124 -20
- package/dist/module/wallet/Wif.d.ts.map +1 -0
- package/dist/module/wallet/Wif.js +406 -74
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/bcmr-v1.schema.d.ts +623 -0
- package/dist/module/wallet/bcmr-v1.schema.d.ts.map +1 -0
- package/dist/module/wallet/bcmr-v1.schema.js +2 -0
- package/dist/module/wallet/bcmr-v1.schema.js.map +1 -0
- package/dist/module/wallet/createWallet.d.ts +3 -2
- package/dist/module/wallet/createWallet.d.ts.map +1 -0
- package/dist/module/wallet/createWallet.js +3 -3
- package/dist/module/wallet/createWallet.js.map +1 -1
- package/dist/module/wallet/enum.d.ts +1 -0
- package/dist/module/wallet/enum.d.ts.map +1 -0
- package/dist/module/wallet/interface.d.ts +10 -6
- package/dist/module/wallet/interface.d.ts.map +1 -0
- package/dist/module/wallet/model.d.ts +81 -5
- package/dist/module/wallet/model.d.ts.map +1 -0
- package/dist/module/wallet/model.js +102 -17
- package/dist/module/wallet/model.js.map +1 -1
- package/dist/module/webhook/Webhook.d.ts +3 -2
- package/dist/module/webhook/Webhook.d.ts.map +1 -0
- package/dist/module/webhook/Webhook.js +4 -1
- package/dist/module/webhook/Webhook.js.map +1 -1
- package/dist/module/webhook/WebhookBch.d.ts +4 -3
- package/dist/module/webhook/WebhookBch.d.ts.map +1 -0
- package/dist/module/webhook/WebhookBch.js +4 -4
- package/dist/module/webhook/WebhookBch.js.map +1 -1
- package/dist/module/webhook/WebhookSlp.d.ts +5 -4
- package/dist/module/webhook/WebhookSlp.d.ts.map +1 -0
- package/dist/module/webhook/WebhookSlp.js +4 -4
- package/dist/module/webhook/WebhookSlp.js.map +1 -1
- package/dist/module/webhook/WebhookWorker.d.ts +3 -2
- package/dist/module/webhook/WebhookWorker.d.ts.map +1 -0
- package/dist/module/webhook/WebhookWorker.js +1 -1
- package/dist/module/webhook/WebhookWorker.js.map +1 -1
- package/dist/module/webhook/index.d.ts +6 -5
- package/dist/module/webhook/index.d.ts.map +1 -0
- package/dist/module/webhook/index.js +5 -5
- package/dist/module/webhook/index.js.map +1 -1
- package/dist/module/webhook/interface.d.ts +1 -0
- package/dist/module/webhook/interface.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/polyfill/{bip39.browser.js → bip39.browser.cjs} +1 -0
- package/polyfill/{util.js → util.cjs} +0 -0
- package/src/Wallet.test.headless.js +6 -6
- package/src/cli.ts +3 -3
- package/src/db/ExchangeRateProvider.ts +1 -1
- package/src/db/IndexedDBProvider.test.ts +0 -1
- package/src/db/IndexedDBProvider.ts +2 -2
- package/src/db/SqlProvider.ts +14 -12
- package/src/db/StorageProvider.ts +1 -1
- package/src/db/getStorageProvider.ts +20 -0
- package/src/db/index.ts +3 -3
- package/src/db/util.ts +1 -20
- package/src/history/electrumTransformer.ts +13 -14
- package/src/history/interface.ts +1 -1
- package/src/index.ts +29 -21
- package/src/interface.ts +15 -0
- package/src/message/index.ts +2 -2
- package/src/message/signed.test.ts +4 -4
- package/src/message/signed.ts +23 -6
- package/src/mine/index.ts +1 -1
- package/src/mine/mine.ts +3 -3
- package/src/network/Connection.ts +5 -5
- package/src/network/ElectrumNetworkProvider.ts +85 -20
- package/src/network/NetworkProvider.ts +1 -1
- package/src/network/configuration.test.ts +33 -8
- package/src/network/configuration.ts +33 -18
- package/src/network/constant.ts +9 -4
- package/src/network/default.ts +13 -10
- package/src/network/getRelayFeeCache.ts +3 -3
- package/src/network/index.ts +6 -2
- package/src/network/util.ts +1 -1
- package/src/qr/Qr.ts +3 -3
- package/src/rate/ExchangeRate.ts +14 -15
- package/src/slp/GsppProvider.test.ts +2 -2
- package/src/slp/GsppProvider.ts +11 -8
- package/src/slp/SlpDbProvider.test.ts +1 -1
- package/src/slp/SlpDbProvider.ts +12 -9
- package/src/slp/SlpLibAuth.test.ts +1 -1
- package/src/slp/SlpLibAuth.ts +52 -42
- package/src/slp/SlpProvider.ts +6 -1
- package/src/slp/index.ts +4 -4
- package/src/slp/interface.ts +1 -1
- package/src/test/axios.ts +47 -0
- package/src/test/expect.ts +27 -2
- package/src/transaction/Wif.ts +203 -77
- package/src/transaction/allocateFee.ts +32 -14
- package/src/util/amountInSatoshi.ts +4 -4
- package/src/util/asSendRequestObject.ts +42 -30
- package/src/util/balanceObjectFromSatoshi.ts +5 -5
- package/src/util/base64.ts +5 -24
- package/src/util/browserNotSupported.ts +1 -1
- package/src/util/checkWifNetwork.ts +1 -1
- package/src/util/convert.ts +2 -2
- package/src/util/deriveCashaddr.test.ts +43 -0
- package/src/util/deriveCashaddr.ts +123 -7
- package/src/util/deriveNetwork.ts +2 -2
- package/src/util/derivePublicKeyHash.test.ts +3 -0
- package/src/util/derivePublicKeyHash.ts +18 -5
- package/src/util/eventsource.ts +4 -2
- package/src/util/getAddrsByXpubKey.test.ts +5 -5
- package/src/util/getAddrsByXpubKey.ts +23 -28
- package/src/util/getUsdRate.ts +1 -1
- package/src/util/getXPubKey.ts +5 -7
- package/src/util/hash160.test.ts +2 -2
- package/src/util/hash160.ts +2 -4
- package/src/util/index.ts +26 -20
- package/src/util/randomBytes.ts +2 -3
- package/src/util/randomValues.ts +8 -8
- package/src/util/sanitizeAddress.ts +1 -1
- package/src/util/sanitizeUnit.ts +1 -1
- package/src/util/satoshiToAmount.ts +4 -4
- package/src/util/sumSendRequestAmounts.ts +10 -4
- package/src/util/sumUtxoValue.ts +19 -7
- package/src/util/transaction.ts +10 -0
- package/src/wallet/Base.ts +11 -11
- package/src/wallet/Bcmr.test.headless.js +353 -0
- package/src/wallet/Bcmr.test.ts +610 -0
- package/src/wallet/Bcmr.ts +390 -0
- package/src/wallet/Cashtokens.test.headless.js +467 -0
- package/src/wallet/Cashtokens.test.ts +475 -0
- package/src/wallet/Slp.test.headless.js +6 -8
- package/src/wallet/Slp.test.ts +2 -2
- package/src/wallet/Slp.ts +26 -22
- package/src/wallet/Util.ts +9 -20
- package/src/wallet/Wif.test.ts +20 -21
- package/src/wallet/Wif.ts +534 -99
- package/src/wallet/bcmr-v1.schema.ts +639 -0
- package/src/wallet/createWallet.test.ts +1 -0
- package/src/wallet/createWallet.ts +4 -4
- package/src/wallet/interface.ts +9 -6
- package/src/wallet/model.ts +190 -19
- package/src/webhook/Webhook.ts +7 -3
- package/src/webhook/WebhookBch.ts +7 -7
- package/src/webhook/WebhookSlp.test.ts +2 -2
- package/src/webhook/WebhookSlp.ts +6 -6
- package/src/webhook/WebhookWorker.ts +2 -2
- package/src/webhook/index.ts +5 -5
- package/tsconfig.browser.json +0 -3
- package/tsconfig.json +17 -5
- package/{webpack.config.js → webpack.config.cjs} +46 -14
- package/dist/main/chain.d.ts +0 -3
- package/dist/main/chain.js +0 -7
- package/dist/main/chain.js.map +0 -1
- package/dist/main/cli.d.ts +0 -1
- package/dist/main/cli.js +0 -35
- package/dist/main/cli.js.map +0 -1
- package/dist/main/constant.d.ts +0 -5
- package/dist/main/constant.js +0 -27
- package/dist/main/constant.js.map +0 -1
- package/dist/main/db/ExchangeRateProvider.d.ts +0 -11
- package/dist/main/db/ExchangeRateProvider.js +0 -47
- package/dist/main/db/ExchangeRateProvider.js.map +0 -1
- package/dist/main/db/IndexedDBProvider.d.ts +0 -15
- package/dist/main/db/IndexedDBProvider.js +0 -86
- package/dist/main/db/IndexedDBProvider.js.map +0 -1
- package/dist/main/db/SqlProvider.d.ts +0 -41
- package/dist/main/db/SqlProvider.js +0 -217
- package/dist/main/db/SqlProvider.js.map +0 -1
- package/dist/main/db/StorageProvider.d.ts +0 -52
- package/dist/main/db/StorageProvider.js +0 -3
- package/dist/main/db/StorageProvider.js.map +0 -1
- package/dist/main/db/index.d.ts +0 -3
- package/dist/main/db/index.js +0 -11
- package/dist/main/db/index.js.map +0 -1
- package/dist/main/db/interface.d.ts +0 -22
- package/dist/main/db/interface.js +0 -3
- package/dist/main/db/interface.js.map +0 -1
- package/dist/main/db/util.d.ts +0 -5
- package/dist/main/db/util.js +0 -53
- package/dist/main/db/util.js.map +0 -1
- package/dist/main/enum.d.ts +0 -33
- package/dist/main/enum.js +0 -39
- package/dist/main/enum.js.map +0 -1
- package/dist/main/history/electrumTransformer.d.ts +0 -4
- package/dist/main/history/electrumTransformer.js +0 -216
- package/dist/main/history/electrumTransformer.js.map +0 -1
- package/dist/main/history/interface.d.ts +0 -16
- package/dist/main/history/interface.js +0 -3
- package/dist/main/history/interface.js.map +0 -1
- package/dist/main/index.d.ts +0 -24
- package/dist/main/index.js +0 -62
- package/dist/main/index.js.map +0 -1
- package/dist/main/interface.d.ts +0 -31
- package/dist/main/interface.js +0 -12
- package/dist/main/interface.js.map +0 -1
- package/dist/main/message/index.d.ts +0 -2
- package/dist/main/message/index.js +0 -15
- package/dist/main/message/index.js.map +0 -1
- package/dist/main/message/interface.d.ts +0 -29
- package/dist/main/message/interface.js +0 -6
- package/dist/main/message/interface.js.map +0 -1
- package/dist/main/message/signed.d.ts +0 -33
- package/dist/main/message/signed.js +0 -141
- package/dist/main/message/signed.js.map +0 -1
- package/dist/main/mine/index.d.ts +0 -1
- package/dist/main/mine/index.js +0 -14
- package/dist/main/mine/index.js.map +0 -1
- package/dist/main/mine/mine.d.ts +0 -13
- package/dist/main/mine/mine.js +0 -37
- package/dist/main/mine/mine.js.map +0 -1
- package/dist/main/network/Connection.d.ts +0 -14
- package/dist/main/network/Connection.js +0 -71
- package/dist/main/network/Connection.js.map +0 -1
- package/dist/main/network/ElectrumNetworkProvider.d.ts +0 -49
- package/dist/main/network/ElectrumNetworkProvider.js +0 -338
- package/dist/main/network/ElectrumNetworkProvider.js.map +0 -1
- package/dist/main/network/NetworkProvider.d.ts +0 -107
- package/dist/main/network/NetworkProvider.js +0 -3
- package/dist/main/network/NetworkProvider.js.map +0 -1
- package/dist/main/network/configuration.d.ts +0 -12
- package/dist/main/network/configuration.js +0 -79
- package/dist/main/network/configuration.js.map +0 -1
- package/dist/main/network/constant.d.ts +0 -35
- package/dist/main/network/constant.js +0 -55
- package/dist/main/network/constant.js.map +0 -1
- package/dist/main/network/default.d.ts +0 -7
- package/dist/main/network/default.js +0 -107
- package/dist/main/network/default.js.map +0 -1
- package/dist/main/network/getRelayFeeCache.d.ts +0 -2
- package/dist/main/network/getRelayFeeCache.js +0 -27
- package/dist/main/network/getRelayFeeCache.js.map +0 -1
- package/dist/main/network/index.d.ts +0 -2
- package/dist/main/network/index.js +0 -10
- package/dist/main/network/index.js.map +0 -1
- package/dist/main/network/interface.d.ts +0 -60
- package/dist/main/network/interface.js +0 -3
- package/dist/main/network/interface.js.map +0 -1
- package/dist/main/network/util.d.ts +0 -2
- package/dist/main/network/util.js +0 -32
- package/dist/main/network/util.js.map +0 -1
- package/dist/main/qr/Qr.d.ts +0 -8
- package/dist/main/qr/Qr.js +0 -26
- package/dist/main/qr/Qr.js.map +0 -1
- package/dist/main/qr/interface.d.ts +0 -5
- package/dist/main/qr/interface.js +0 -3
- package/dist/main/qr/interface.js.map +0 -1
- package/dist/main/rate/ExchangeRate.d.ts +0 -19
- package/dist/main/rate/ExchangeRate.js +0 -147
- package/dist/main/rate/ExchangeRate.js.map +0 -1
- package/dist/main/slp/GsppProvider.d.ts +0 -54
- package/dist/main/slp/GsppProvider.js +0 -214
- package/dist/main/slp/GsppProvider.js.map +0 -1
- package/dist/main/slp/SlpDbProvider.d.ts +0 -51
- package/dist/main/slp/SlpDbProvider.js +0 -182
- package/dist/main/slp/SlpDbProvider.js.map +0 -1
- package/dist/main/slp/SlpDbTemplates.d.ts +0 -312
- package/dist/main/slp/SlpDbTemplates.js +0 -387
- package/dist/main/slp/SlpDbTemplates.js.map +0 -1
- package/dist/main/slp/SlpLibAuth.d.ts +0 -217
- package/dist/main/slp/SlpLibAuth.js +0 -452
- package/dist/main/slp/SlpLibAuth.js.map +0 -1
- package/dist/main/slp/SlpProvider.d.ts +0 -23
- package/dist/main/slp/SlpProvider.js +0 -39
- package/dist/main/slp/SlpProvider.js.map +0 -1
- package/dist/main/slp/index.d.ts +0 -5
- package/dist/main/slp/index.js +0 -24
- package/dist/main/slp/index.js.map +0 -1
- package/dist/main/slp/interface.d.ts +0 -113
- package/dist/main/slp/interface.js +0 -10
- package/dist/main/slp/interface.js.map +0 -1
- package/dist/main/test/expect.d.ts +0 -7
- package/dist/main/test/expect.js +0 -31
- package/dist/main/test/expect.js.map +0 -1
- package/dist/main/transaction/Wif.d.ts +0 -42
- package/dist/main/transaction/Wif.js +0 -214
- package/dist/main/transaction/Wif.js.map +0 -1
- package/dist/main/transaction/allocateFee.d.ts +0 -7
- package/dist/main/transaction/allocateFee.js +0 -118
- package/dist/main/transaction/allocateFee.js.map +0 -1
- package/dist/main/util/amountInSatoshi.d.ts +0 -9
- package/dist/main/util/amountInSatoshi.js +0 -38
- package/dist/main/util/amountInSatoshi.js.map +0 -1
- package/dist/main/util/asSendRequestObject.d.ts +0 -2
- package/dist/main/util/asSendRequestObject.js +0 -57
- package/dist/main/util/asSendRequestObject.js.map +0 -1
- package/dist/main/util/balanceObjectFromSatoshi.d.ts +0 -8
- package/dist/main/util/balanceObjectFromSatoshi.js +0 -62
- package/dist/main/util/balanceObjectFromSatoshi.js.map +0 -1
- package/dist/main/util/base64.d.ts +0 -2
- package/dist/main/util/base64.js +0 -36
- package/dist/main/util/base64.js.map +0 -1
- package/dist/main/util/bchaddr.d.ts +0 -1
- package/dist/main/util/bchaddr.js +0 -24
- package/dist/main/util/bchaddr.js.map +0 -1
- package/dist/main/util/browserNotSupported.d.ts +0 -1
- package/dist/main/util/browserNotSupported.js +0 -11
- package/dist/main/util/browserNotSupported.js.map +0 -1
- package/dist/main/util/checkForEmptySeed.d.ts +0 -2
- package/dist/main/util/checkForEmptySeed.js +0 -12
- package/dist/main/util/checkForEmptySeed.js.map +0 -1
- package/dist/main/util/checkWifNetwork.d.ts +0 -2
- package/dist/main/util/checkWifNetwork.js +0 -16
- package/dist/main/util/checkWifNetwork.js.map +0 -1
- package/dist/main/util/convert.d.ts +0 -15
- package/dist/main/util/convert.js +0 -24
- package/dist/main/util/convert.js.map +0 -1
- package/dist/main/util/delay.d.ts +0 -1
- package/dist/main/util/delay.js +0 -8
- package/dist/main/util/delay.js.map +0 -1
- package/dist/main/util/deriveCashaddr.d.ts +0 -2
- package/dist/main/util/deriveCashaddr.js +0 -13
- package/dist/main/util/deriveCashaddr.js.map +0 -1
- package/dist/main/util/deriveLockscript.d.ts +0 -8
- package/dist/main/util/deriveLockscript.js +0 -19
- package/dist/main/util/deriveLockscript.js.map +0 -1
- package/dist/main/util/deriveNetwork.d.ts +0 -1
- package/dist/main/util/deriveNetwork.js +0 -23
- package/dist/main/util/deriveNetwork.js.map +0 -1
- package/dist/main/util/derivePublicKeyHash.d.ts +0 -16
- package/dist/main/util/derivePublicKeyHash.js +0 -49
- package/dist/main/util/derivePublicKeyHash.js.map +0 -1
- package/dist/main/util/eventsource.d.ts +0 -2
- package/dist/main/util/eventsource.js +0 -12
- package/dist/main/util/eventsource.js.map +0 -1
- package/dist/main/util/floor.d.ts +0 -1
- package/dist/main/util/floor.js +0 -9
- package/dist/main/util/floor.js.map +0 -1
- package/dist/main/util/getAddrsByXpubKey.d.ts +0 -22
- package/dist/main/util/getAddrsByXpubKey.js +0 -79
- package/dist/main/util/getAddrsByXpubKey.js.map +0 -1
- package/dist/main/util/getRuntimePlatform.d.ts +0 -6
- package/dist/main/util/getRuntimePlatform.js +0 -34
- package/dist/main/util/getRuntimePlatform.js.map +0 -1
- package/dist/main/util/getUsdRate.d.ts +0 -1
- package/dist/main/util/getUsdRate.js +0 -9
- package/dist/main/util/getUsdRate.js.map +0 -1
- package/dist/main/util/getXPubKey.d.ts +0 -1
- package/dist/main/util/getXPubKey.js +0 -26
- package/dist/main/util/getXPubKey.js.map +0 -1
- package/dist/main/util/hash160.d.ts +0 -8
- package/dist/main/util/hash160.js +0 -18
- package/dist/main/util/hash160.js.map +0 -1
- package/dist/main/util/index.d.ts +0 -21
- package/dist/main/util/index.js +0 -72
- package/dist/main/util/index.js.map +0 -1
- package/dist/main/util/randomBytes.d.ts +0 -1
- package/dist/main/util/randomBytes.js +0 -18
- package/dist/main/util/randomBytes.js.map +0 -1
- package/dist/main/util/randomInt.d.ts +0 -1
- package/dist/main/util/randomInt.js +0 -9
- package/dist/main/util/randomInt.js.map +0 -1
- package/dist/main/util/randomValues.d.ts +0 -1
- package/dist/main/util/randomValues.js +0 -15
- package/dist/main/util/randomValues.js.map +0 -1
- package/dist/main/util/sanitizeAddress.d.ts +0 -1
- package/dist/main/util/sanitizeAddress.js +0 -15
- package/dist/main/util/sanitizeAddress.js.map +0 -1
- package/dist/main/util/sanitizeUnit.d.ts +0 -2
- package/dist/main/util/sanitizeUnit.js +0 -13
- package/dist/main/util/sanitizeUnit.js.map +0 -1
- package/dist/main/util/satoshiToAmount.d.ts +0 -9
- package/dist/main/util/satoshiToAmount.js +0 -41
- package/dist/main/util/satoshiToAmount.js.map +0 -1
- package/dist/main/util/sumSendRequestAmounts.d.ts +0 -2
- package/dist/main/util/sumSendRequestAmounts.js +0 -31
- package/dist/main/util/sumSendRequestAmounts.js.map +0 -1
- package/dist/main/util/sumUtxoValue.d.ts +0 -2
- package/dist/main/util/sumUtxoValue.js +0 -17
- package/dist/main/util/sumUtxoValue.js.map +0 -1
- package/dist/main/wallet/Base.d.ts +0 -202
- package/dist/main/wallet/Base.js +0 -438
- package/dist/main/wallet/Base.js.map +0 -1
- package/dist/main/wallet/Slp.d.ts +0 -430
- package/dist/main/wallet/Slp.js +0 -775
- package/dist/main/wallet/Slp.js.map +0 -1
- package/dist/main/wallet/Util.d.ts +0 -69
- package/dist/main/wallet/Util.js +0 -182
- package/dist/main/wallet/Util.js.map +0 -1
- package/dist/main/wallet/Wif.d.ts +0 -255
- package/dist/main/wallet/Wif.js +0 -1067
- package/dist/main/wallet/Wif.js.map +0 -1
- package/dist/main/wallet/createWallet.d.ts +0 -69
- package/dist/main/wallet/createWallet.js +0 -244
- package/dist/main/wallet/createWallet.js.map +0 -1
- package/dist/main/wallet/enum.d.ts +0 -16
- package/dist/main/wallet/enum.js +0 -22
- package/dist/main/wallet/enum.js.map +0 -1
- package/dist/main/wallet/interface.d.ts +0 -76
- package/dist/main/wallet/interface.js +0 -3
- package/dist/main/wallet/interface.js.map +0 -1
- package/dist/main/wallet/model.d.ts +0 -88
- package/dist/main/wallet/model.js +0 -129
- package/dist/main/wallet/model.js.map +0 -1
- package/dist/main/webhook/Webhook.d.ts +0 -40
- package/dist/main/webhook/Webhook.js +0 -82
- package/dist/main/webhook/Webhook.js.map +0 -1
- package/dist/main/webhook/WebhookBch.d.ts +0 -13
- package/dist/main/webhook/WebhookBch.js +0 -148
- package/dist/main/webhook/WebhookBch.js.map +0 -1
- package/dist/main/webhook/WebhookSlp.d.ts +0 -14
- package/dist/main/webhook/WebhookSlp.js +0 -107
- package/dist/main/webhook/WebhookSlp.js.map +0 -1
- package/dist/main/webhook/WebhookWorker.d.ts +0 -22
- package/dist/main/webhook/WebhookWorker.js +0 -100
- package/dist/main/webhook/WebhookWorker.js.map +0 -1
- package/dist/main/webhook/index.d.ts +0 -5
- package/dist/main/webhook/index.js +0 -23
- package/dist/main/webhook/index.js.map +0 -1
- package/dist/main/webhook/interface.d.ts +0 -8
- package/dist/main/webhook/interface.js +0 -3
- package/dist/main/webhook/interface.js.map +0 -1
- package/dist/mainnet-0.5.9.js +0 -2
- package/dist/mainnet-0.5.9.js.LICENSE.txt +0 -48
- package/dist/tsconfig.browser.tsbuildinfo +0 -1
- package/jest.config.js +0 -23
package/dist/main/wallet/Wif.js
DELETED
|
@@ -1,1067 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.RegTestWatchWallet = exports.TestNetWatchWallet = exports.WatchWallet = exports.RegTestWifWallet = exports.TestNetWifWallet = exports.WifWallet = exports.RegTestWallet = exports.TestNetWallet = exports.Wallet = void 0;
|
|
7
|
-
//#region Imports
|
|
8
|
-
// Stable
|
|
9
|
-
const libauth_1 = require("@bitauth/libauth");
|
|
10
|
-
// Unstable?
|
|
11
|
-
const libauth_2 = require("@bitauth/libauth");
|
|
12
|
-
const bip39_1 = require("bip39");
|
|
13
|
-
const enum_1 = require("../enum");
|
|
14
|
-
const interface_1 = require("../interface");
|
|
15
|
-
const enum_2 = require("../enum");
|
|
16
|
-
const Base_1 = require("./Base");
|
|
17
|
-
const enum_3 = require("./enum");
|
|
18
|
-
const model_1 = require("./model");
|
|
19
|
-
const Wif_1 = require("../transaction/Wif");
|
|
20
|
-
const asSendRequestObject_1 = require("../util/asSendRequestObject");
|
|
21
|
-
const balanceObjectFromSatoshi_1 = require("../util/balanceObjectFromSatoshi");
|
|
22
|
-
const checkWifNetwork_1 = require("../util/checkWifNetwork");
|
|
23
|
-
const deriveCashaddr_1 = require("../util/deriveCashaddr");
|
|
24
|
-
const derivePublicKeyHash_1 = require("../util/derivePublicKeyHash");
|
|
25
|
-
const checkForEmptySeed_1 = require("../util/checkForEmptySeed");
|
|
26
|
-
const sanitizeUnit_1 = require("../util/sanitizeUnit");
|
|
27
|
-
const sumUtxoValue_1 = require("../util/sumUtxoValue");
|
|
28
|
-
const sumSendRequestAmounts_1 = require("../util/sumSendRequestAmounts");
|
|
29
|
-
const getRelayFeeCache_1 = require("../network/getRelayFeeCache");
|
|
30
|
-
const Slp_1 = require("./Slp");
|
|
31
|
-
const axios_1 = __importDefault(require("axios"));
|
|
32
|
-
const bchaddr_1 = require("../util/bchaddr");
|
|
33
|
-
const Util_1 = require("./Util");
|
|
34
|
-
const index_1 = require("../network/index");
|
|
35
|
-
const randomBytes_1 = require("../util/randomBytes");
|
|
36
|
-
const message_1 = require("../message");
|
|
37
|
-
const amountInSatoshi_1 = require("../util/amountInSatoshi");
|
|
38
|
-
const getXPubKey_1 = require("../util/getXPubKey");
|
|
39
|
-
const constant_1 = require("../constant");
|
|
40
|
-
const electrumTransformer_1 = require("../history/electrumTransformer");
|
|
41
|
-
//#endregion Imports
|
|
42
|
-
const secp256k1Promise = (0, libauth_1.instantiateSecp256k1)();
|
|
43
|
-
const sha256Promise = (0, libauth_1.instantiateSha256)();
|
|
44
|
-
/**
|
|
45
|
-
* Class to manage a bitcoin cash wallet.
|
|
46
|
-
*/
|
|
47
|
-
class Wallet extends Base_1.BaseWallet {
|
|
48
|
-
//#endregion
|
|
49
|
-
//#region Constructors and Statics
|
|
50
|
-
constructor(name = "", network = enum_1.NetworkType.Mainnet, walletType = enum_3.WalletTypeEnum.Seed) {
|
|
51
|
-
super(name, network, walletType);
|
|
52
|
-
this.derivationPath = "m/44'/0'/0'/0/0";
|
|
53
|
-
this.parentDerivationPath = "m/44'/0'/0'";
|
|
54
|
-
this._slpAware = false; // a flag which activates utxo checking against an external slp indexer
|
|
55
|
-
this._slpSemiAware = false; // a flag which requires an utxo to have more than 546 sats to be spendable and counted in the balance
|
|
56
|
-
this.fromId = async (walletId) => {
|
|
57
|
-
let [walletType, networkGiven, arg1] = walletId.split(":");
|
|
58
|
-
if (this.network != networkGiven) {
|
|
59
|
-
throw Error(`Network prefix ${networkGiven} to a ${this.network} wallet`);
|
|
60
|
-
}
|
|
61
|
-
// "wif:regtest:cNfsPtqN2bMRS7vH5qd8tR8GMvgXyL5BjnGAKgZ8DYEiCrCCQcP6"
|
|
62
|
-
if (walletType === "wif") {
|
|
63
|
-
return this.fromWIF(arg1);
|
|
64
|
-
}
|
|
65
|
-
return super.fromId(walletId);
|
|
66
|
-
};
|
|
67
|
-
this.networkPrefix = enum_1.prefixFromNetworkMap[this.network];
|
|
68
|
-
}
|
|
69
|
-
//#region Accessors
|
|
70
|
-
// interface to slp functions. see Slp.ts
|
|
71
|
-
get slp() {
|
|
72
|
-
if (!this._slp) {
|
|
73
|
-
this._slp = new Slp_1.Slp(this);
|
|
74
|
-
this._slpAware = true;
|
|
75
|
-
}
|
|
76
|
-
return this._slp;
|
|
77
|
-
}
|
|
78
|
-
// interface to slp functions. see Slp.ts
|
|
79
|
-
static get slp() {
|
|
80
|
-
return Slp_1.Slp;
|
|
81
|
-
}
|
|
82
|
-
// interface to util functions. see Util.ts
|
|
83
|
-
get util() {
|
|
84
|
-
if (!this._util) {
|
|
85
|
-
this._util = new Util_1.Util(this);
|
|
86
|
-
}
|
|
87
|
-
return this._util;
|
|
88
|
-
}
|
|
89
|
-
// interface to util util. see Util.Util
|
|
90
|
-
static get util() {
|
|
91
|
-
return Util_1.Util;
|
|
92
|
-
}
|
|
93
|
-
slpAware(value = true) {
|
|
94
|
-
this._slpAware = value;
|
|
95
|
-
return this;
|
|
96
|
-
}
|
|
97
|
-
slpSemiAware(value = true) {
|
|
98
|
-
this._slpSemiAware = value;
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
101
|
-
getNetworkProvider(network = interface_1.Network.MAINNET) {
|
|
102
|
-
return (0, index_1.getNetworkProvider)(network);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* explorerUrl Web url to a transaction on a block explorer
|
|
106
|
-
*
|
|
107
|
-
* @param txId transaction Id
|
|
108
|
-
* @returns Url string
|
|
109
|
-
*/
|
|
110
|
-
explorerUrl(txId) {
|
|
111
|
-
const explorerUrlMap = {
|
|
112
|
-
mainnet: "https://blockchair.com/bitcoin-cash/transaction/",
|
|
113
|
-
testnet: "https://www.blockchain.com/bch-testnet/tx/",
|
|
114
|
-
regtest: "",
|
|
115
|
-
};
|
|
116
|
-
return explorerUrlMap[this.network] + txId;
|
|
117
|
-
}
|
|
118
|
-
// Return wallet info
|
|
119
|
-
getInfo() {
|
|
120
|
-
return {
|
|
121
|
-
cashaddr: this.cashaddr,
|
|
122
|
-
isTestnet: this.isTestnet,
|
|
123
|
-
name: this.name,
|
|
124
|
-
network: this.network,
|
|
125
|
-
seed: this.mnemonic ? this.getSeed().seed : undefined,
|
|
126
|
-
derivationPath: this.mnemonic ? this.getSeed().derivationPath : undefined,
|
|
127
|
-
parentDerivationPath: this.mnemonic
|
|
128
|
-
? this.getSeed().parentDerivationPath
|
|
129
|
-
: undefined,
|
|
130
|
-
parentXPubKey: this.parentXPubKey ? this.parentXPubKey : undefined,
|
|
131
|
-
publicKey: this.publicKey ? (0, libauth_2.binToHex)(this.publicKey) : undefined,
|
|
132
|
-
publicKeyHash: (0, libauth_2.binToHex)(this.publicKeyHash),
|
|
133
|
-
privateKey: this.privateKey ? (0, libauth_2.binToHex)(this.privateKey) : undefined,
|
|
134
|
-
privateKeyWif: this.privateKeyWif,
|
|
135
|
-
walletId: this.toString(),
|
|
136
|
-
walletDbEntry: this.toDbString(),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
// returns the public key hash for an address
|
|
140
|
-
getPublicKey(hex = false) {
|
|
141
|
-
if (this.publicKey) {
|
|
142
|
-
return hex ? (0, libauth_2.binToHex)(this.publicKey) : this.publicKey;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
throw Error("The public key for this wallet is not known, perhaps the wallet was created to watch the *hash* of a public key? i.e. a cashaddress.");
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
// returns the public key hash for an address
|
|
149
|
-
getPublicKeyCompressed(hex = false) {
|
|
150
|
-
if (this.publicKeyCompressed) {
|
|
151
|
-
return hex
|
|
152
|
-
? (0, libauth_2.binToHex)(this.publicKeyCompressed)
|
|
153
|
-
: this.publicKeyCompressed;
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
throw Error("The compressed public key for this wallet is not known, perhaps the wallet was created to watch the *hash* of a public key? i.e. a cashaddress.");
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
// returns the public key hash for an address
|
|
160
|
-
getPublicKeyHash(hex = false) {
|
|
161
|
-
if (this.publicKeyHash) {
|
|
162
|
-
return hex ? (0, libauth_2.binToHex)(this.publicKeyHash) : this.publicKeyHash;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
throw Error("The public key hash for this wallet is not known. If this wallet was created from the constructor directly, calling the deriveInfo() function may help. ");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* fromWIF - create a wallet using the private key supplied in `Wallet Import Format`
|
|
170
|
-
*
|
|
171
|
-
* @param wif WIF encoded private key string
|
|
172
|
-
*
|
|
173
|
-
* @returns instantiated wallet
|
|
174
|
-
*/
|
|
175
|
-
static async fromWIF(wif) {
|
|
176
|
-
return new this().fromWIF(wif);
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* fromCashaddr - create a watch-only wallet in the network derived from the address
|
|
180
|
-
*
|
|
181
|
-
* such kind of wallet does not have a private key and is unable to spend any funds
|
|
182
|
-
* however it still allows to use many utility functions such as getting and watching balance, etc.
|
|
183
|
-
*
|
|
184
|
-
* @param address cashaddress of a wallet
|
|
185
|
-
*
|
|
186
|
-
* @returns instantiated wallet
|
|
187
|
-
*/
|
|
188
|
-
static async fromCashaddr(address) {
|
|
189
|
-
const prefix = (0, derivePublicKeyHash_1.derivePrefix)(address);
|
|
190
|
-
const networkType = enum_2.networkPrefixMap[prefix];
|
|
191
|
-
return new this("", networkType, enum_3.WalletTypeEnum.Watch).watchOnly(address);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* fromSlpaddr - create an SLP aware watch-only wallet in the network derived from the address
|
|
195
|
-
*
|
|
196
|
-
* such kind of wallet does not have a private key and is unable to spend any funds
|
|
197
|
-
* however it still allows to use many utility functions such as getting and watching balance, etc.
|
|
198
|
-
*
|
|
199
|
-
* @param address slpaddress of a wallet
|
|
200
|
-
*
|
|
201
|
-
* @returns instantiated wallet
|
|
202
|
-
*/
|
|
203
|
-
static async fromSlpaddr(address) {
|
|
204
|
-
return this.fromCashaddr((0, bchaddr_1.toCashAddress)(address));
|
|
205
|
-
}
|
|
206
|
-
//#endregion Constructors and Statics
|
|
207
|
-
//#region Protected implementations
|
|
208
|
-
async generate() {
|
|
209
|
-
if (this.walletType === enum_3.WalletTypeEnum.Wif) {
|
|
210
|
-
return await this._generateWif();
|
|
211
|
-
}
|
|
212
|
-
else if (this.walletType === enum_3.WalletTypeEnum.Watch) {
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
else if (this.walletType === enum_3.WalletTypeEnum.Hd) {
|
|
216
|
-
throw Error("Not implemented");
|
|
217
|
-
}
|
|
218
|
-
else if (this.walletType === enum_3.WalletTypeEnum.Seed) {
|
|
219
|
-
return await this._generateMnemonic();
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
console.log(this.walletType);
|
|
223
|
-
throw Error(`Could not determine walletType: ${this.walletType}`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
async _generateWif() {
|
|
227
|
-
if (!this.privateKey) {
|
|
228
|
-
this.privateKey = (0, libauth_2.generatePrivateKey)(() => (0, randomBytes_1.generateRandomBytes)(32));
|
|
229
|
-
}
|
|
230
|
-
return this.deriveInfo();
|
|
231
|
-
}
|
|
232
|
-
async _generateMnemonic() {
|
|
233
|
-
this.mnemonic = (0, bip39_1.generateMnemonic)();
|
|
234
|
-
if (this.mnemonic.length == 0)
|
|
235
|
-
throw Error("refusing to create wallet from empty mnemonic");
|
|
236
|
-
let seed = (0, bip39_1.mnemonicToSeedSync)(this.mnemonic);
|
|
237
|
-
(0, checkForEmptySeed_1.checkForEmptySeed)(seed);
|
|
238
|
-
let network = this.isTestnet ? "testnet" : "mainnet";
|
|
239
|
-
this.parentXPubKey = await (0, getXPubKey_1.getXPubKey)(seed, this.parentDerivationPath, network);
|
|
240
|
-
const crypto = await (0, libauth_2.instantiateBIP32Crypto)();
|
|
241
|
-
let hdNode = (0, libauth_2.deriveHdPrivateNodeFromSeed)(crypto, seed);
|
|
242
|
-
if (!hdNode.valid) {
|
|
243
|
-
throw Error("Invalid private key derived from mnemonic seed");
|
|
244
|
-
}
|
|
245
|
-
let zerothChild = (0, libauth_2.deriveHdPath)(crypto, hdNode, this.derivationPath);
|
|
246
|
-
if (typeof zerothChild === "string") {
|
|
247
|
-
throw Error(zerothChild);
|
|
248
|
-
}
|
|
249
|
-
this.privateKey = zerothChild.privateKey;
|
|
250
|
-
this.walletType = enum_3.WalletTypeEnum.Seed;
|
|
251
|
-
return await this.deriveInfo();
|
|
252
|
-
}
|
|
253
|
-
async getXPubKeys(paths) {
|
|
254
|
-
if (this.mnemonic) {
|
|
255
|
-
if (paths) {
|
|
256
|
-
let xPubKeys = await this.deriveHdPaths(paths);
|
|
257
|
-
return [xPubKeys];
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
return await this.deriveHdPaths(constant_1.DERIVATION_PATHS);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
throw Error("xpubkeys can only be derived from seed type wallets.");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
// Initialize wallet from a mnemonic phrase
|
|
268
|
-
async fromSeed(mnemonic, derivationPath) {
|
|
269
|
-
this.mnemonic = mnemonic;
|
|
270
|
-
const crypto = await (0, libauth_2.instantiateBIP32Crypto)();
|
|
271
|
-
if (this.mnemonic.length == 0)
|
|
272
|
-
throw Error("refusing to create wallet from empty mnemonic");
|
|
273
|
-
let seed = (0, bip39_1.mnemonicToSeedSync)(this.mnemonic);
|
|
274
|
-
(0, checkForEmptySeed_1.checkForEmptySeed)(seed);
|
|
275
|
-
let hdNode = (0, libauth_2.deriveHdPrivateNodeFromSeed)(crypto, seed);
|
|
276
|
-
if (!hdNode.valid) {
|
|
277
|
-
throw Error("Invalid private key derived from mnemonic seed");
|
|
278
|
-
}
|
|
279
|
-
if (derivationPath) {
|
|
280
|
-
this.derivationPath = derivationPath;
|
|
281
|
-
// If the derivation path is for the first account child, set the parent derivation path
|
|
282
|
-
let path = derivationPath.split("/");
|
|
283
|
-
if (path.slice(-2).join("/") == "0/0") {
|
|
284
|
-
this.parentDerivationPath = path.slice(0, -2).join("/");
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
let zerothChild = (0, libauth_2.deriveHdPath)(crypto, hdNode, this.derivationPath);
|
|
288
|
-
if (typeof zerothChild === "string") {
|
|
289
|
-
throw Error(zerothChild);
|
|
290
|
-
}
|
|
291
|
-
this.privateKey = zerothChild.privateKey;
|
|
292
|
-
let network = this.isTestnet ? "testnet" : "mainnet";
|
|
293
|
-
this.parentXPubKey = await (0, getXPubKey_1.getXPubKey)(seed, this.parentDerivationPath, network);
|
|
294
|
-
this.walletType = enum_3.WalletTypeEnum.Seed;
|
|
295
|
-
await this.deriveInfo();
|
|
296
|
-
return this;
|
|
297
|
-
}
|
|
298
|
-
// Get common xpub paths from zerothChild privateKey
|
|
299
|
-
async deriveHdPaths(hdPaths) {
|
|
300
|
-
const crypto = await (0, libauth_2.instantiateBIP32Crypto)();
|
|
301
|
-
if (!this.mnemonic)
|
|
302
|
-
throw Error("refusing to create wallet from empty mnemonic");
|
|
303
|
-
let seed = (0, bip39_1.mnemonicToSeedSync)(this.mnemonic);
|
|
304
|
-
(0, checkForEmptySeed_1.checkForEmptySeed)(seed);
|
|
305
|
-
let hdNode = (0, libauth_2.deriveHdPrivateNodeFromSeed)(crypto, seed);
|
|
306
|
-
if (!hdNode.valid) {
|
|
307
|
-
throw Error("Invalid private key derived from mnemonic seed");
|
|
308
|
-
}
|
|
309
|
-
let result = [];
|
|
310
|
-
for (const path of hdPaths) {
|
|
311
|
-
if (path === "m") {
|
|
312
|
-
throw Error("Storing or sharing of parent public key may lead to loss of funds. Storing or sharing *root* parent public keys is strongly discouraged, although all parent keys have risk. See: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#implications");
|
|
313
|
-
}
|
|
314
|
-
let childNode = (0, libauth_2.deriveHdPath)(crypto, hdNode, path);
|
|
315
|
-
if (typeof childNode === "string") {
|
|
316
|
-
throw Error(childNode);
|
|
317
|
-
}
|
|
318
|
-
let node = (0, libauth_2.deriveHdPublicNode)(crypto, childNode);
|
|
319
|
-
if (typeof node === "string") {
|
|
320
|
-
throw Error(node);
|
|
321
|
-
}
|
|
322
|
-
let xPubKey = (0, libauth_1.encodeHdPublicKey)(crypto, {
|
|
323
|
-
network: this.network,
|
|
324
|
-
node: node,
|
|
325
|
-
});
|
|
326
|
-
let key = new model_1.XPubKey({
|
|
327
|
-
path: path,
|
|
328
|
-
xPubKey: xPubKey,
|
|
329
|
-
});
|
|
330
|
-
result.push(await key.ready());
|
|
331
|
-
}
|
|
332
|
-
return await Promise.all(result).then((result) => {
|
|
333
|
-
return result;
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
// Initialize a watch only wallet from a cash addr
|
|
337
|
-
async watchOnly(address) {
|
|
338
|
-
this.walletType = enum_3.WalletTypeEnum.Watch;
|
|
339
|
-
let addressComponents = address.split(":");
|
|
340
|
-
let addressPrefix, addressBase;
|
|
341
|
-
if (addressComponents.length === 1) {
|
|
342
|
-
addressBase = addressComponents.shift();
|
|
343
|
-
addressPrefix = (0, derivePublicKeyHash_1.derivePrefix)(addressBase);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
addressPrefix = addressComponents.shift();
|
|
347
|
-
addressBase = addressComponents.shift();
|
|
348
|
-
if (addressPrefix in enum_2.networkPrefixMap) {
|
|
349
|
-
if (enum_2.networkPrefixMap[addressPrefix] != this.network) {
|
|
350
|
-
throw Error(`a ${addressPrefix} address cannot be watched from a ${this.network} Wallet`);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
this.cashaddr = `${addressPrefix}:${addressBase}`;
|
|
355
|
-
this.address = this.cashaddr;
|
|
356
|
-
this.publicKeyHash = (0, derivePublicKeyHash_1.derivePublicKeyHash)(this.cashaddr);
|
|
357
|
-
return this;
|
|
358
|
-
}
|
|
359
|
-
// Initialize wallet from Wallet Import Format
|
|
360
|
-
async fromWIF(secret) {
|
|
361
|
-
(0, checkWifNetwork_1.checkWifNetwork)(secret, this.network);
|
|
362
|
-
const sha256 = await sha256Promise;
|
|
363
|
-
let wifResult = (0, libauth_2.decodePrivateKeyWif)(sha256, secret);
|
|
364
|
-
if (typeof wifResult === "string") {
|
|
365
|
-
throw Error(wifResult);
|
|
366
|
-
}
|
|
367
|
-
let resultData = wifResult;
|
|
368
|
-
this.privateKey = resultData.privateKey;
|
|
369
|
-
this.privateKeyWif = secret;
|
|
370
|
-
this.walletType = enum_3.WalletTypeEnum.Wif;
|
|
371
|
-
await this.deriveInfo();
|
|
372
|
-
return this;
|
|
373
|
-
}
|
|
374
|
-
async newRandom(name, dbName) {
|
|
375
|
-
dbName = dbName ? dbName : this.networkPrefix;
|
|
376
|
-
return super.newRandom(name, dbName);
|
|
377
|
-
}
|
|
378
|
-
async named(name, dbName, forceNew = false) {
|
|
379
|
-
dbName = dbName ? dbName : this.networkPrefix;
|
|
380
|
-
return super.named(name, dbName, forceNew);
|
|
381
|
-
}
|
|
382
|
-
async replaceNamed(name, walletId, dbName) {
|
|
383
|
-
dbName = dbName ? dbName : this.networkPrefix;
|
|
384
|
-
return super.replaceNamed(name, walletId, dbName);
|
|
385
|
-
}
|
|
386
|
-
async namedExists(name, dbName) {
|
|
387
|
-
dbName = dbName ? dbName : this.networkPrefix;
|
|
388
|
-
return super.namedExists(name, dbName);
|
|
389
|
-
}
|
|
390
|
-
//#endregion Protected Implementations
|
|
391
|
-
//#region Serialization
|
|
392
|
-
// Returns the serialized wallet as a string
|
|
393
|
-
// If storing in a database, set asNamed to false to store secrets
|
|
394
|
-
// In all other cases, the a named wallet is deserialized from the database
|
|
395
|
-
// by the name key
|
|
396
|
-
toString() {
|
|
397
|
-
const result = super.toString();
|
|
398
|
-
if (result)
|
|
399
|
-
return result;
|
|
400
|
-
if (this.walletType === enum_3.WalletTypeEnum.Wif) {
|
|
401
|
-
return `${this.walletType}:${this.network}:${this.privateKeyWif}`;
|
|
402
|
-
}
|
|
403
|
-
throw Error("toString unsupported wallet type");
|
|
404
|
-
}
|
|
405
|
-
//
|
|
406
|
-
toDbString() {
|
|
407
|
-
const result = super.toDbString();
|
|
408
|
-
if (result)
|
|
409
|
-
return result;
|
|
410
|
-
if (this.walletType === enum_3.WalletTypeEnum.Wif) {
|
|
411
|
-
return `${this.walletType}:${this.network}:${this.privateKeyWif}`;
|
|
412
|
-
}
|
|
413
|
-
throw Error("toDbString unsupported wallet type");
|
|
414
|
-
}
|
|
415
|
-
//#endregion Serialization
|
|
416
|
-
//#region Funds
|
|
417
|
-
//
|
|
418
|
-
async getAddressUtxos(address) {
|
|
419
|
-
if (!this.provider) {
|
|
420
|
-
throw Error("Attempting to get utxos from wallet without a client");
|
|
421
|
-
}
|
|
422
|
-
if (this._slpAware) {
|
|
423
|
-
const [bchUtxos, slpOutpoints] = await Promise.all([
|
|
424
|
-
this.provider.getUtxos(address),
|
|
425
|
-
this.slp.getSlpOutpoints(),
|
|
426
|
-
]);
|
|
427
|
-
return bchUtxos.filter((bchutxo) => slpOutpoints.findIndex((slpOutpoint) => `${bchutxo.txid}:${bchutxo.vout}` === slpOutpoint) === -1);
|
|
428
|
-
}
|
|
429
|
-
else if (this._slpSemiAware) {
|
|
430
|
-
const bchUtxos = await this.provider.getUtxos(address);
|
|
431
|
-
return bchUtxos.filter((bchutxo) => bchutxo.satoshis > constant_1.DUST_UTXO_THRESHOLD);
|
|
432
|
-
}
|
|
433
|
-
else {
|
|
434
|
-
return await this.provider.getUtxos(address);
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* utxos Get unspent outputs for the wallet
|
|
439
|
-
*
|
|
440
|
-
*/
|
|
441
|
-
async getUtxos() {
|
|
442
|
-
if (!this.cashaddr) {
|
|
443
|
-
throw Error("Attempted to get utxos without an address");
|
|
444
|
-
}
|
|
445
|
-
let utxos = await this.getAddressUtxos(this.cashaddr);
|
|
446
|
-
let resp = new model_1.UtxoResponse();
|
|
447
|
-
resp.utxos = await Promise.all(utxos.map(async (o) => {
|
|
448
|
-
return model_1.UtxoItem.fromElectrum(o);
|
|
449
|
-
}));
|
|
450
|
-
return resp;
|
|
451
|
-
}
|
|
452
|
-
// gets wallet balance in sats, bch and usd
|
|
453
|
-
async getBalance(rawUnit, usdPriceCache = true) {
|
|
454
|
-
if (rawUnit) {
|
|
455
|
-
const unit = (0, sanitizeUnit_1.sanitizeUnit)(rawUnit);
|
|
456
|
-
return await (0, balanceObjectFromSatoshi_1.balanceFromSatoshi)(await this.getBalanceFromProvider(), unit, usdPriceCache);
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
return await (0, balanceObjectFromSatoshi_1.balanceResponseFromSatoshi)(await this.getBalanceFromProvider(), usdPriceCache);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
// Gets balance by summing value in all utxos in stats
|
|
463
|
-
async getBalanceFromUtxos() {
|
|
464
|
-
const utxos = await this.getAddressUtxos(this.cashaddr);
|
|
465
|
-
return await (0, sumUtxoValue_1.sumUtxoValue)(utxos);
|
|
466
|
-
}
|
|
467
|
-
// Gets balance from fulcrum
|
|
468
|
-
async getBalanceFromProvider() {
|
|
469
|
-
// TODO not sure why getting the balance from a provider doesn't work
|
|
470
|
-
if (this._slpAware || this._slpSemiAware) {
|
|
471
|
-
return await this.getBalanceFromUtxos();
|
|
472
|
-
}
|
|
473
|
-
else {
|
|
474
|
-
return await this.provider.getBalance(this.cashaddr);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
// // waiting for any transaction hash of this wallet
|
|
478
|
-
// // commented out until fulcrum supports new method https://github.com/cculianu/Fulcrum/pull/89
|
|
479
|
-
// public watchAddress(callback: (txHash: string) => void): CancelWatchFn {
|
|
480
|
-
// return (this.provider! as ElectrumNetworkProvider).watchAddress(
|
|
481
|
-
// this.getDepositAddress(),
|
|
482
|
-
// callback
|
|
483
|
-
// );
|
|
484
|
-
// }
|
|
485
|
-
// // waiting for any transaction of this wallet
|
|
486
|
-
// // commented out until fulcrum supports new method https://github.com/cculianu/Fulcrum/pull/89
|
|
487
|
-
// public watchAddressTransactions(
|
|
488
|
-
// callback: (tx: ElectrumRawTransaction) => void
|
|
489
|
-
// ): CancelWatchFn {
|
|
490
|
-
// return (this.provider! as ElectrumNetworkProvider).watchAddressTransactions(
|
|
491
|
-
// this.getDepositAddress(),
|
|
492
|
-
// callback
|
|
493
|
-
// );
|
|
494
|
-
// }
|
|
495
|
-
// sets up a callback to be called upon wallet's balance change
|
|
496
|
-
// can be cancelled by calling the function returned from this one
|
|
497
|
-
watchBalance(callback) {
|
|
498
|
-
return this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {
|
|
499
|
-
const balance = (await this.getBalance());
|
|
500
|
-
callback(balance);
|
|
501
|
-
});
|
|
502
|
-
}
|
|
503
|
-
// sets up a callback to be called upon wallet's BCH or USD balance change
|
|
504
|
-
// if BCH balance does not change, the callback will be triggered every
|
|
505
|
-
// @param `usdPriceRefreshInterval` milliseconds by polling for new BCH USD price
|
|
506
|
-
// Since we want to be most sensitive to usd value change, we do not use the cached exchange rates
|
|
507
|
-
// can be cancelled by calling the function returned from this one
|
|
508
|
-
watchBalanceUsd(callback, usdPriceRefreshInterval = 30000) {
|
|
509
|
-
let usdPrice = -1;
|
|
510
|
-
const _callback = async () => {
|
|
511
|
-
const balance = (await this.getBalance(undefined, false));
|
|
512
|
-
if (usdPrice !== balance.usd) {
|
|
513
|
-
usdPrice = balance.usd;
|
|
514
|
-
callback(balance);
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
const watchCancel = this.provider.watchAddressStatus(this.getDepositAddress(), _callback);
|
|
518
|
-
const interval = setInterval(_callback, usdPriceRefreshInterval);
|
|
519
|
-
return async () => {
|
|
520
|
-
await watchCancel();
|
|
521
|
-
clearInterval(interval);
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
// waits for address balance to be greater than or equal to the target value
|
|
525
|
-
// this call halts the execution
|
|
526
|
-
async waitForBalance(value, rawUnit = enum_1.UnitEnum.BCH) {
|
|
527
|
-
return new Promise(async (resolve) => {
|
|
528
|
-
const watchCancel = this.watchBalance(async (balance) => {
|
|
529
|
-
const satoshiBalance = await (0, amountInSatoshi_1.amountInSatoshi)(value, rawUnit);
|
|
530
|
-
if (balance.sat >= satoshiBalance) {
|
|
531
|
-
await watchCancel();
|
|
532
|
-
resolve(balance);
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
});
|
|
536
|
-
}
|
|
537
|
-
async getMaxAmountToSend(params = {
|
|
538
|
-
outputCount: 1,
|
|
539
|
-
options: {},
|
|
540
|
-
}) {
|
|
541
|
-
if (!this.privateKey) {
|
|
542
|
-
throw Error("Couldn't get network or private key for wallet.");
|
|
543
|
-
}
|
|
544
|
-
if (!this.cashaddr) {
|
|
545
|
-
throw Error("attempted to send without a cashaddr");
|
|
546
|
-
}
|
|
547
|
-
if (params.options && params.options.slpAware) {
|
|
548
|
-
this._slpAware = true;
|
|
549
|
-
}
|
|
550
|
-
if (params.options && params.options.slpSemiAware) {
|
|
551
|
-
this._slpSemiAware = true;
|
|
552
|
-
}
|
|
553
|
-
let feePaidBy;
|
|
554
|
-
if (params.options && params.options.feePaidBy) {
|
|
555
|
-
feePaidBy = params.options.feePaidBy;
|
|
556
|
-
}
|
|
557
|
-
else {
|
|
558
|
-
feePaidBy = enum_3.FeePaidByEnum.change;
|
|
559
|
-
}
|
|
560
|
-
// get inputs
|
|
561
|
-
let utxos;
|
|
562
|
-
if (params.options && params.options.utxoIds) {
|
|
563
|
-
utxos = params.options.utxoIds.map((utxoId) => model_1.UtxoItem.fromId(utxoId).asElectrum());
|
|
564
|
-
}
|
|
565
|
-
else {
|
|
566
|
-
utxos = await this.getAddressUtxos(this.cashaddr);
|
|
567
|
-
}
|
|
568
|
-
// Get current height to assure recently mined coins are not spent.
|
|
569
|
-
const bestHeight = await this.provider.getBlockHeight();
|
|
570
|
-
// simulate outputs using the sender's address
|
|
571
|
-
const sendRequest = new model_1.SendRequest({
|
|
572
|
-
cashaddr: this.cashaddr,
|
|
573
|
-
value: 100,
|
|
574
|
-
unit: "sat",
|
|
575
|
-
});
|
|
576
|
-
const sendRequests = Array(params.outputCount)
|
|
577
|
-
.fill(0)
|
|
578
|
-
.map(() => sendRequest);
|
|
579
|
-
const fundingUtxos = await (0, Wif_1.getSuitableUtxos)(utxos, undefined, bestHeight, feePaidBy);
|
|
580
|
-
const relayFeePerByteInSatoshi = await (0, getRelayFeeCache_1.getRelayFeeCache)(this.provider);
|
|
581
|
-
const fee = await (0, Wif_1.getFeeAmount)({
|
|
582
|
-
utxos: fundingUtxos,
|
|
583
|
-
sendRequests: sendRequests,
|
|
584
|
-
privateKey: this.privateKey,
|
|
585
|
-
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
586
|
-
slpOutputs: [],
|
|
587
|
-
feePaidBy: feePaidBy,
|
|
588
|
-
});
|
|
589
|
-
const spendableAmount = await (0, sumUtxoValue_1.sumUtxoValue)(fundingUtxos);
|
|
590
|
-
let result = spendableAmount - fee;
|
|
591
|
-
if (result < 0) {
|
|
592
|
-
result = 0;
|
|
593
|
-
}
|
|
594
|
-
return await (0, balanceObjectFromSatoshi_1.balanceResponseFromSatoshi)(result);
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* send Send some amount to an address
|
|
598
|
-
* this function processes the send requests, encodes the transaction, sends it to the network
|
|
599
|
-
* @returns (depending on the options parameter) the transaction id, new address balance and a link to the transaction on the blockchain explorer
|
|
600
|
-
*
|
|
601
|
-
* This is a first class function with REST analog, maintainers should strive to keep backward-compatibility
|
|
602
|
-
*
|
|
603
|
-
*/
|
|
604
|
-
async send(requests, options) {
|
|
605
|
-
let encodedTransaction = await this.encodeTransaction(requests, undefined, options);
|
|
606
|
-
const awaitTransactionPropagation = !options ||
|
|
607
|
-
options.awaitTransactionPropagation === undefined ||
|
|
608
|
-
options.awaitTransactionPropagation;
|
|
609
|
-
const txId = await this.submitTransaction(encodedTransaction, awaitTransactionPropagation);
|
|
610
|
-
let resp = new model_1.SendResponse({});
|
|
611
|
-
resp.txId = txId;
|
|
612
|
-
const queryBalance = !options || options.queryBalance === undefined || options.queryBalance;
|
|
613
|
-
if (queryBalance) {
|
|
614
|
-
resp.balance = (await this.getBalance());
|
|
615
|
-
}
|
|
616
|
-
resp.explorerUrl = this.explorerUrl(resp.txId);
|
|
617
|
-
return resp;
|
|
618
|
-
}
|
|
619
|
-
/**
|
|
620
|
-
* sendMax Send all available funds to a destination cash address
|
|
621
|
-
*
|
|
622
|
-
* @param {string} cashaddr destination cash address
|
|
623
|
-
* @param {SendRequestOptionsI} options Options of the send requests
|
|
624
|
-
*
|
|
625
|
-
* @returns (depending on the options parameter) the transaction id, new address balance and a link to the transaction on the blockchain explorer
|
|
626
|
-
*/
|
|
627
|
-
async sendMax(cashaddr, options) {
|
|
628
|
-
const txId = await this.sendMaxRaw(cashaddr, options);
|
|
629
|
-
const queryBalance = !options || options.queryBalance === undefined || options.queryBalance;
|
|
630
|
-
return {
|
|
631
|
-
txId: txId,
|
|
632
|
-
balance: queryBalance
|
|
633
|
-
? (await this.getBalance())
|
|
634
|
-
: undefined,
|
|
635
|
-
explorerUrl: this.explorerUrl(txId),
|
|
636
|
-
};
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* sendMaxRaw (internal) Send all available funds to a destination cash address
|
|
640
|
-
*
|
|
641
|
-
* @param {string} cashaddr destination cash address
|
|
642
|
-
* @param {SendRequestOptionsI} options Options of the send requests
|
|
643
|
-
*
|
|
644
|
-
* @returns the transaction id sent to the network
|
|
645
|
-
*/
|
|
646
|
-
async sendMaxRaw(cashaddr, options) {
|
|
647
|
-
let maxSpendableAmount = await this.getMaxAmountToSend({
|
|
648
|
-
outputCount: 1,
|
|
649
|
-
options: options,
|
|
650
|
-
});
|
|
651
|
-
if (maxSpendableAmount.sat === undefined) {
|
|
652
|
-
throw Error("no Max amount to send");
|
|
653
|
-
}
|
|
654
|
-
let sendRequest = new model_1.SendRequest({
|
|
655
|
-
cashaddr: cashaddr,
|
|
656
|
-
value: maxSpendableAmount.sat,
|
|
657
|
-
unit: "sat",
|
|
658
|
-
});
|
|
659
|
-
const encodedTransaction = await this.encodeTransaction([sendRequest], true, options);
|
|
660
|
-
const awaitTransactionPropagation = !options ||
|
|
661
|
-
options.awaitTransactionPropagation === undefined ||
|
|
662
|
-
options.awaitTransactionPropagation;
|
|
663
|
-
const txId = await this.submitTransaction(encodedTransaction, awaitTransactionPropagation);
|
|
664
|
-
return txId;
|
|
665
|
-
}
|
|
666
|
-
/**
|
|
667
|
-
* encodeTransaction Encode and sign a transaction given a list of sendRequests, options and estimate fees.
|
|
668
|
-
* @param {SendRequest[]} sendRequests SendRequests
|
|
669
|
-
* @param {boolean} discardChange=false
|
|
670
|
-
* @param {SendRequestOptionsI} options Options of the send requests
|
|
671
|
-
*/
|
|
672
|
-
async encodeTransaction(requests, discardChange = false, options) {
|
|
673
|
-
let sendRequests = (0, asSendRequestObject_1.asSendRequestObject)(requests);
|
|
674
|
-
if (!this.privateKey) {
|
|
675
|
-
throw new Error(`Wallet ${this.name} is missing either a network or private key`);
|
|
676
|
-
}
|
|
677
|
-
if (!this.cashaddr) {
|
|
678
|
-
throw Error("attempted to send without a cashaddr");
|
|
679
|
-
}
|
|
680
|
-
if (options && options.slpAware) {
|
|
681
|
-
this._slpAware = true;
|
|
682
|
-
}
|
|
683
|
-
if (options && options.slpSemiAware) {
|
|
684
|
-
this._slpSemiAware = true;
|
|
685
|
-
}
|
|
686
|
-
let feePaidBy;
|
|
687
|
-
if (options && options.feePaidBy) {
|
|
688
|
-
feePaidBy = options.feePaidBy;
|
|
689
|
-
}
|
|
690
|
-
else {
|
|
691
|
-
feePaidBy = enum_3.FeePaidByEnum.change;
|
|
692
|
-
}
|
|
693
|
-
let changeAddress;
|
|
694
|
-
if (options && options.changeAddress) {
|
|
695
|
-
changeAddress = options.changeAddress;
|
|
696
|
-
}
|
|
697
|
-
else {
|
|
698
|
-
changeAddress = "";
|
|
699
|
-
}
|
|
700
|
-
// get inputs from options or query all inputs
|
|
701
|
-
let utxos;
|
|
702
|
-
if (options && options.utxoIds) {
|
|
703
|
-
utxos = options.utxoIds.map((utxoId) => model_1.UtxoItem.fromId(utxoId).asElectrum());
|
|
704
|
-
}
|
|
705
|
-
else {
|
|
706
|
-
utxos = await this.getAddressUtxos(this.cashaddr);
|
|
707
|
-
}
|
|
708
|
-
const bestHeight = await this.provider.getBlockHeight();
|
|
709
|
-
const spendAmount = await (0, sumSendRequestAmounts_1.sumSendRequestAmounts)(sendRequests);
|
|
710
|
-
if (utxos.length === 0) {
|
|
711
|
-
throw Error("There were no Unspent Outputs");
|
|
712
|
-
}
|
|
713
|
-
if (typeof spendAmount !== "bigint") {
|
|
714
|
-
throw Error("Couldn't get spend amount when building transaction");
|
|
715
|
-
}
|
|
716
|
-
const relayFeePerByteInSatoshi = await (0, getRelayFeeCache_1.getRelayFeeCache)(this.provider);
|
|
717
|
-
const feeEstimate = await (0, Wif_1.getFeeAmount)({
|
|
718
|
-
utxos: utxos,
|
|
719
|
-
sendRequests: sendRequests,
|
|
720
|
-
privateKey: this.privateKey,
|
|
721
|
-
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
722
|
-
slpOutputs: [],
|
|
723
|
-
feePaidBy: feePaidBy,
|
|
724
|
-
});
|
|
725
|
-
const fundingUtxos = await (0, Wif_1.getSuitableUtxos)(utxos, BigInt(spendAmount) + BigInt(feeEstimate), bestHeight, feePaidBy);
|
|
726
|
-
if (fundingUtxos.length === 0) {
|
|
727
|
-
throw Error("The available inputs couldn't satisfy the request with fees");
|
|
728
|
-
}
|
|
729
|
-
const fee = await (0, Wif_1.getFeeAmount)({
|
|
730
|
-
utxos: fundingUtxos,
|
|
731
|
-
sendRequests: sendRequests,
|
|
732
|
-
privateKey: this.privateKey,
|
|
733
|
-
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
734
|
-
slpOutputs: [],
|
|
735
|
-
feePaidBy: feePaidBy,
|
|
736
|
-
});
|
|
737
|
-
const encodedTransaction = await (0, Wif_1.buildEncodedTransaction)(fundingUtxos, sendRequests, this.privateKey, fee, discardChange, [], feePaidBy, changeAddress);
|
|
738
|
-
return encodedTransaction;
|
|
739
|
-
}
|
|
740
|
-
// Submit a raw transaction
|
|
741
|
-
async submitTransaction(transaction, awaitPropagation = true) {
|
|
742
|
-
if (!this.provider) {
|
|
743
|
-
throw Error("Wallet network provider was not initialized");
|
|
744
|
-
}
|
|
745
|
-
let rawTransaction = (0, libauth_2.binToHex)(transaction);
|
|
746
|
-
return await this.provider.sendRawTransaction(rawTransaction, awaitPropagation);
|
|
747
|
-
}
|
|
748
|
-
// gets transaction history of this wallet
|
|
749
|
-
async getRawHistory() {
|
|
750
|
-
return await this.provider.getHistory(this.cashaddr);
|
|
751
|
-
}
|
|
752
|
-
// gets transaction history of this wallet
|
|
753
|
-
async getHistory(unit, start, count, collapseChange) {
|
|
754
|
-
return (0, electrumTransformer_1.getAddressHistory)(this.cashaddr, this.provider, unit, start, count, collapseChange);
|
|
755
|
-
}
|
|
756
|
-
// gets last transaction of this wallet
|
|
757
|
-
async getLastTransaction(confirmedOnly = false) {
|
|
758
|
-
let history = await this.getRawHistory();
|
|
759
|
-
if (confirmedOnly) {
|
|
760
|
-
history = history.filter((val) => val.height > 0);
|
|
761
|
-
}
|
|
762
|
-
if (!history.length) {
|
|
763
|
-
return null;
|
|
764
|
-
}
|
|
765
|
-
const [lastTx] = history.slice(-1);
|
|
766
|
-
return this.provider.getRawTransactionObject(lastTx.tx_hash);
|
|
767
|
-
}
|
|
768
|
-
// waits for next transaction, program execution is halted
|
|
769
|
-
async waitForTransaction(options = {
|
|
770
|
-
getTransactionInfo: true,
|
|
771
|
-
getBalance: false,
|
|
772
|
-
txHash: undefined,
|
|
773
|
-
}) {
|
|
774
|
-
if (options.getTransactionInfo === undefined) {
|
|
775
|
-
options.getTransactionInfo = true;
|
|
776
|
-
}
|
|
777
|
-
return new Promise(async (resolve) => {
|
|
778
|
-
let txHashSeen = false;
|
|
779
|
-
const makeResponse = async (txHash) => {
|
|
780
|
-
const response = {};
|
|
781
|
-
const promises = [undefined, undefined];
|
|
782
|
-
if (options.getBalance === true) {
|
|
783
|
-
promises[0] = this.getBalance();
|
|
784
|
-
}
|
|
785
|
-
if (options.getTransactionInfo === true) {
|
|
786
|
-
if (!txHash) {
|
|
787
|
-
promises[1] = this.getLastTransaction();
|
|
788
|
-
}
|
|
789
|
-
else {
|
|
790
|
-
promises[1] = this.provider.getRawTransactionObject(txHash);
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
const result = await Promise.all(promises);
|
|
794
|
-
response.balance = result[0];
|
|
795
|
-
response.transactionInfo = result[1];
|
|
796
|
-
return response;
|
|
797
|
-
};
|
|
798
|
-
// waiting for a specific transaction to propagate
|
|
799
|
-
if (options.txHash) {
|
|
800
|
-
const waitForTransactionCallback = async (data) => {
|
|
801
|
-
if (data && data[0] === options.txHash) {
|
|
802
|
-
txHashSeen = true;
|
|
803
|
-
this.provider.unsubscribeFromTransaction(options.txHash, waitForTransactionCallback);
|
|
804
|
-
resolve(makeResponse(options.txHash));
|
|
805
|
-
}
|
|
806
|
-
};
|
|
807
|
-
this.provider.subscribeToTransaction(options.txHash, waitForTransactionCallback);
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
810
|
-
// waiting for any address transaction
|
|
811
|
-
const watchCancel = this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {
|
|
812
|
-
watchCancel();
|
|
813
|
-
resolve(makeResponse());
|
|
814
|
-
});
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
/**
|
|
818
|
-
* watchBlocks Watch network blocks
|
|
819
|
-
*
|
|
820
|
-
* @param callback callback with a block header object
|
|
821
|
-
*
|
|
822
|
-
* @returns a function which will cancel watching upon evaluation
|
|
823
|
-
*/
|
|
824
|
-
watchBlocks(callback) {
|
|
825
|
-
return this.provider.watchBlocks(callback);
|
|
826
|
-
}
|
|
827
|
-
/**
|
|
828
|
-
* waitForBlock Wait for a network block
|
|
829
|
-
*
|
|
830
|
-
* @param height if specified waits for this exact blockchain height, otherwise resolves with the next block
|
|
831
|
-
*
|
|
832
|
-
*/
|
|
833
|
-
async waitForBlock(height) {
|
|
834
|
-
return this.provider.waitForBlock(height);
|
|
835
|
-
}
|
|
836
|
-
//#endregion Funds
|
|
837
|
-
//#region Private implementation details
|
|
838
|
-
async deriveInfo() {
|
|
839
|
-
const sha256 = await sha256Promise;
|
|
840
|
-
const secp256k1 = await secp256k1Promise;
|
|
841
|
-
this.publicKey = secp256k1.derivePublicKeyUncompressed(this.privateKey);
|
|
842
|
-
this.publicKeyCompressed = secp256k1.derivePublicKeyCompressed(this.privateKey);
|
|
843
|
-
const networkType = this.network === enum_1.NetworkType.Regtest ? enum_1.NetworkType.Testnet : this.network;
|
|
844
|
-
this.privateKeyWif = (0, libauth_2.encodePrivateKeyWif)(sha256, this.privateKey, networkType);
|
|
845
|
-
(0, checkWifNetwork_1.checkWifNetwork)(this.privateKeyWif, this.network);
|
|
846
|
-
this.cashaddr = (await (0, deriveCashaddr_1.deriveCashaddr)(this.privateKey, this.networkPrefix));
|
|
847
|
-
this.address = this.cashaddr;
|
|
848
|
-
this.publicKeyHash = (0, derivePublicKeyHash_1.derivePublicKeyHash)(this.cashaddr);
|
|
849
|
-
return this;
|
|
850
|
-
}
|
|
851
|
-
//#endregion Private implementation details
|
|
852
|
-
//#region Signing
|
|
853
|
-
// Convenience wrapper to sign interface
|
|
854
|
-
async sign(message) {
|
|
855
|
-
return await Wallet.signedMessage.sign(message, this.privateKey);
|
|
856
|
-
}
|
|
857
|
-
// Convenience wrapper to verify interface
|
|
858
|
-
async verify(message, sig, publicKey) {
|
|
859
|
-
return await Wallet.signedMessage.verify(message, sig, this.cashaddr, publicKey);
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
exports.Wallet = Wallet;
|
|
863
|
-
Wallet.signedMessage = new message_1.SignedMessage();
|
|
864
|
-
/**
|
|
865
|
-
* Class to manage a testnet wallet.
|
|
866
|
-
*/
|
|
867
|
-
class TestNetWallet extends Wallet {
|
|
868
|
-
constructor(name = "") {
|
|
869
|
-
super(name, enum_1.NetworkType.Testnet);
|
|
870
|
-
}
|
|
871
|
-
// will receive 10000 testnet satoshi, rate limits apply
|
|
872
|
-
async getTestnetSatoshis() {
|
|
873
|
-
try {
|
|
874
|
-
const response = await axios_1.default.post(`${TestNetWallet.faucetServer}/faucet/get_testnet_bch`, { cashaddr: this.cashaddr });
|
|
875
|
-
const data = response.data;
|
|
876
|
-
return data.txId;
|
|
877
|
-
}
|
|
878
|
-
catch (e) {
|
|
879
|
-
// console.log(e);
|
|
880
|
-
// console.log(e.response ? e.response.data : "");
|
|
881
|
-
throw e;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
// be nice and return them back
|
|
885
|
-
async returnTestnetSatoshis() {
|
|
886
|
-
try {
|
|
887
|
-
const response = await axios_1.default.post(`${TestNetWallet.faucetServer}/faucet/get_addresses`);
|
|
888
|
-
const data = response.data;
|
|
889
|
-
return await this.slpAware().sendMax(data.bchtest);
|
|
890
|
-
}
|
|
891
|
-
catch (e) {
|
|
892
|
-
console.log(e);
|
|
893
|
-
console.log(e.response ? e.response.data : "");
|
|
894
|
-
throw e;
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
// will receive 10 testnet tokens, rate limits apply
|
|
898
|
-
async getTestnetSlp(tokenId) {
|
|
899
|
-
try {
|
|
900
|
-
const response = await axios_1.default.post(`${TestNetWallet.faucetServer}/faucet/get_testnet_slp`, { slpaddr: this.slp.slpaddr, tokenId: tokenId });
|
|
901
|
-
const data = response.data;
|
|
902
|
-
return data.txId;
|
|
903
|
-
}
|
|
904
|
-
catch (e) {
|
|
905
|
-
//console.log(e);
|
|
906
|
-
//console.log(e.response ? e.response.data : "");
|
|
907
|
-
throw e;
|
|
908
|
-
}
|
|
909
|
-
}
|
|
910
|
-
// be nice and return them back
|
|
911
|
-
async returnTestnetSlp(tokenId) {
|
|
912
|
-
try {
|
|
913
|
-
const response = await axios_1.default.post(`${TestNetWallet.faucetServer}/faucet/get_addresses`);
|
|
914
|
-
const data = response.data;
|
|
915
|
-
return await this.slp.sendMax(data.slptest, tokenId);
|
|
916
|
-
}
|
|
917
|
-
catch (e) {
|
|
918
|
-
console.log(e);
|
|
919
|
-
console.log(e.response ? e.response.data : "");
|
|
920
|
-
throw e;
|
|
921
|
-
}
|
|
922
|
-
}
|
|
923
|
-
// interface to static slp functions. see Slp.ts
|
|
924
|
-
static get slp() {
|
|
925
|
-
return Slp_1.TestNetSlp;
|
|
926
|
-
}
|
|
927
|
-
// interface to static util functions. see Util.ts
|
|
928
|
-
static get util() {
|
|
929
|
-
return Util_1.TestNetUtil;
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
exports.TestNetWallet = TestNetWallet;
|
|
933
|
-
TestNetWallet.networkPrefix = libauth_2.CashAddressNetworkPrefix.testnet;
|
|
934
|
-
TestNetWallet.faucetServer = "https://rest-unstable.mainnet.cash";
|
|
935
|
-
/**
|
|
936
|
-
* Class to manage a regtest wallet.
|
|
937
|
-
*/
|
|
938
|
-
class RegTestWallet extends Wallet {
|
|
939
|
-
constructor(name = "") {
|
|
940
|
-
super(name, enum_1.NetworkType.Regtest);
|
|
941
|
-
}
|
|
942
|
-
// interface to static slp functions. see Slp.ts
|
|
943
|
-
static get slp() {
|
|
944
|
-
return Slp_1.RegTestSlp;
|
|
945
|
-
}
|
|
946
|
-
// interface to static util functions. see Util.ts
|
|
947
|
-
static get util() {
|
|
948
|
-
return Util_1.RegTestUtil;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
exports.RegTestWallet = RegTestWallet;
|
|
952
|
-
RegTestWallet.networkPrefix = libauth_2.CashAddressNetworkPrefix.regtest;
|
|
953
|
-
/**
|
|
954
|
-
* Class to manage a bitcoin cash wif wallet.
|
|
955
|
-
*/
|
|
956
|
-
class WifWallet extends Wallet {
|
|
957
|
-
constructor(name = "") {
|
|
958
|
-
super(name, enum_1.NetworkType.Mainnet, enum_3.WalletTypeEnum.Wif);
|
|
959
|
-
}
|
|
960
|
-
// interface to static slp functions. see Slp.ts
|
|
961
|
-
static get slp() {
|
|
962
|
-
return Slp_1.WifSlp;
|
|
963
|
-
}
|
|
964
|
-
// interface to static util functions. see Util.ts
|
|
965
|
-
static get util() {
|
|
966
|
-
return Util_1.WifUtil;
|
|
967
|
-
}
|
|
968
|
-
}
|
|
969
|
-
exports.WifWallet = WifWallet;
|
|
970
|
-
WifWallet.networkPrefix = libauth_2.CashAddressNetworkPrefix.mainnet;
|
|
971
|
-
WifWallet.walletType = enum_3.WalletTypeEnum.Wif;
|
|
972
|
-
/**
|
|
973
|
-
* Class to manage a testnet wif wallet.
|
|
974
|
-
*/
|
|
975
|
-
class TestNetWifWallet extends Wallet {
|
|
976
|
-
constructor(name = "") {
|
|
977
|
-
super(name, enum_1.NetworkType.Testnet, enum_3.WalletTypeEnum.Wif);
|
|
978
|
-
}
|
|
979
|
-
// interface to static slp functions. see Slp.ts
|
|
980
|
-
static get slp() {
|
|
981
|
-
return Slp_1.TestNetWifSlp;
|
|
982
|
-
}
|
|
983
|
-
// interface to static util functions. see Util.ts
|
|
984
|
-
static get util() {
|
|
985
|
-
return Util_1.TestNetWifUtil;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
exports.TestNetWifWallet = TestNetWifWallet;
|
|
989
|
-
TestNetWifWallet.networkPrefix = libauth_2.CashAddressNetworkPrefix.testnet;
|
|
990
|
-
TestNetWifWallet.walletType = enum_3.WalletTypeEnum.Wif;
|
|
991
|
-
/**
|
|
992
|
-
* Class to manage a regtest wif wallet.
|
|
993
|
-
*/
|
|
994
|
-
class RegTestWifWallet extends Wallet {
|
|
995
|
-
constructor(name = "") {
|
|
996
|
-
super(name, enum_1.NetworkType.Regtest, enum_3.WalletTypeEnum.Wif);
|
|
997
|
-
}
|
|
998
|
-
// interface to static slp functions. see Slp.ts
|
|
999
|
-
static get slp() {
|
|
1000
|
-
return Slp_1.RegTestWifSlp;
|
|
1001
|
-
}
|
|
1002
|
-
// interface to static util functions. see Util.ts
|
|
1003
|
-
static get util() {
|
|
1004
|
-
return Util_1.RegTestWifUtil;
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
exports.RegTestWifWallet = RegTestWifWallet;
|
|
1008
|
-
RegTestWifWallet.networkPrefix = libauth_2.CashAddressNetworkPrefix.regtest;
|
|
1009
|
-
RegTestWifWallet.walletType = enum_3.WalletTypeEnum.Wif;
|
|
1010
|
-
/**
|
|
1011
|
-
* Class to manage a bitcoin cash watch wallet.
|
|
1012
|
-
*/
|
|
1013
|
-
class WatchWallet extends Wallet {
|
|
1014
|
-
constructor(name = "") {
|
|
1015
|
-
super(name, enum_1.NetworkType.Mainnet, enum_3.WalletTypeEnum.Watch);
|
|
1016
|
-
}
|
|
1017
|
-
// interface to static slp functions. see Slp.ts
|
|
1018
|
-
static get slp() {
|
|
1019
|
-
return Slp_1.WatchSlp;
|
|
1020
|
-
}
|
|
1021
|
-
// interface to static util functions. see Util.ts
|
|
1022
|
-
static get util() {
|
|
1023
|
-
return Util_1.WatchUtil;
|
|
1024
|
-
}
|
|
1025
|
-
}
|
|
1026
|
-
exports.WatchWallet = WatchWallet;
|
|
1027
|
-
WatchWallet.networkPrefix = libauth_2.CashAddressNetworkPrefix.mainnet;
|
|
1028
|
-
WatchWallet.walletType = enum_3.WalletTypeEnum.Watch;
|
|
1029
|
-
/**
|
|
1030
|
-
* Class to manage a testnet watch wallet.
|
|
1031
|
-
*/
|
|
1032
|
-
class TestNetWatchWallet extends Wallet {
|
|
1033
|
-
constructor(name = "") {
|
|
1034
|
-
super(name, enum_1.NetworkType.Testnet, enum_3.WalletTypeEnum.Watch);
|
|
1035
|
-
}
|
|
1036
|
-
// interface to static slp functions. see Slp.ts
|
|
1037
|
-
static get slp() {
|
|
1038
|
-
return Slp_1.TestNetWatchSlp;
|
|
1039
|
-
}
|
|
1040
|
-
// interface to static util functions. see Util.ts
|
|
1041
|
-
static get util() {
|
|
1042
|
-
return Util_1.TestNetWatchUtil;
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
exports.TestNetWatchWallet = TestNetWatchWallet;
|
|
1046
|
-
TestNetWatchWallet.networkPrefix = libauth_2.CashAddressNetworkPrefix.testnet;
|
|
1047
|
-
TestNetWatchWallet.walletType = enum_3.WalletTypeEnum.Watch;
|
|
1048
|
-
/**
|
|
1049
|
-
* Class to manage a regtest watch wallet.
|
|
1050
|
-
*/
|
|
1051
|
-
class RegTestWatchWallet extends Wallet {
|
|
1052
|
-
constructor(name = "") {
|
|
1053
|
-
super(name, enum_1.NetworkType.Regtest, enum_3.WalletTypeEnum.Watch);
|
|
1054
|
-
}
|
|
1055
|
-
// interface to static slp functions. see Slp.ts
|
|
1056
|
-
static get slp() {
|
|
1057
|
-
return Slp_1.RegTestWatchSlp;
|
|
1058
|
-
}
|
|
1059
|
-
// interface to static util functions. see Util.ts
|
|
1060
|
-
static get util() {
|
|
1061
|
-
return Util_1.RegTestWatchUtil;
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
exports.RegTestWatchWallet = RegTestWatchWallet;
|
|
1065
|
-
RegTestWatchWallet.networkPrefix = libauth_2.CashAddressNetworkPrefix.regtest;
|
|
1066
|
-
RegTestWatchWallet.walletType = enum_3.WalletTypeEnum.Watch;
|
|
1067
|
-
//# sourceMappingURL=Wif.js.map
|