mainnet-js 0.5.9 → 1.0.0-rc.3
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.3.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/src/wallet/Wif.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
//#region Imports
|
|
2
2
|
// Stable
|
|
3
|
-
import {
|
|
4
|
-
deriveHdPublicNodeIdentifier,
|
|
5
|
-
encodeHdPublicKey,
|
|
6
|
-
HdKeyNetwork,
|
|
7
|
-
instantiateSecp256k1,
|
|
8
|
-
instantiateSha256,
|
|
9
|
-
} from "@bitauth/libauth";
|
|
3
|
+
import { encodeHdPublicKey, HdKeyNetwork, secp256k1 } from "@bitauth/libauth";
|
|
10
4
|
|
|
11
5
|
// Unstable?
|
|
12
6
|
import {
|
|
@@ -18,59 +12,65 @@ import {
|
|
|
18
12
|
deriveHdPrivateNodeFromSeed,
|
|
19
13
|
deriveHdPath,
|
|
20
14
|
generatePrivateKey,
|
|
21
|
-
HdPrivateNodeValid,
|
|
22
|
-
instantiateBIP32Crypto,
|
|
23
15
|
} from "@bitauth/libauth";
|
|
24
16
|
|
|
25
17
|
import { mnemonicToSeedSync, generateMnemonic } from "bip39";
|
|
26
|
-
import { NetworkType, prefixFromNetworkMap, UnitEnum } from "../enum";
|
|
18
|
+
import { NetworkType, prefixFromNetworkMap, UnitEnum } from "../enum.js";
|
|
27
19
|
|
|
28
|
-
import { Network, HeaderI, TxI } from "../interface";
|
|
20
|
+
import { Network, HeaderI, TxI, NFTCapability } from "../interface.js";
|
|
29
21
|
|
|
30
|
-
import { networkPrefixMap } from "../enum";
|
|
31
|
-
import { PrivateKeyI, UtxoI } from "../interface";
|
|
22
|
+
import { networkPrefixMap } from "../enum.js";
|
|
23
|
+
import { PrivateKeyI, UtxoI } from "../interface.js";
|
|
32
24
|
|
|
33
|
-
import { BaseWallet } from "./Base";
|
|
34
|
-
import { FeePaidByEnum, WalletTypeEnum } from "./enum";
|
|
25
|
+
import { BaseWallet } from "./Base.js";
|
|
26
|
+
import { FeePaidByEnum, WalletTypeEnum } from "./enum.js";
|
|
35
27
|
import {
|
|
36
28
|
CancelWatchFn,
|
|
37
29
|
SendRequestOptionsI,
|
|
38
30
|
WaitForTransactionOptions,
|
|
39
31
|
WaitForTransactionResponse,
|
|
40
32
|
WalletInfoI,
|
|
41
|
-
} from "./interface";
|
|
33
|
+
} from "./interface.js";
|
|
42
34
|
|
|
43
35
|
import {
|
|
44
36
|
OpReturnData,
|
|
45
37
|
SendRequest,
|
|
46
38
|
SendRequestArray,
|
|
39
|
+
SendRequestType,
|
|
47
40
|
SendResponse,
|
|
41
|
+
TokenBurnRequest,
|
|
42
|
+
TokenGenesisRequest,
|
|
43
|
+
TokenMintRequest,
|
|
44
|
+
TokenSendRequest,
|
|
48
45
|
UtxoItem,
|
|
49
46
|
UtxoResponse,
|
|
50
47
|
XPubKey,
|
|
51
|
-
} from "./model";
|
|
48
|
+
} from "./model.js";
|
|
52
49
|
|
|
53
50
|
import {
|
|
54
51
|
buildEncodedTransaction,
|
|
55
52
|
getSuitableUtxos,
|
|
56
53
|
getFeeAmount,
|
|
57
|
-
} from "../transaction/Wif";
|
|
54
|
+
} from "../transaction/Wif.js";
|
|
58
55
|
|
|
59
|
-
import { asSendRequestObject } from "../util/asSendRequestObject";
|
|
56
|
+
import { asSendRequestObject } from "../util/asSendRequestObject.js";
|
|
60
57
|
import {
|
|
61
58
|
balanceFromSatoshi,
|
|
62
59
|
balanceResponseFromSatoshi,
|
|
63
60
|
BalanceResponse,
|
|
64
|
-
} from "../util/balanceObjectFromSatoshi";
|
|
65
|
-
import { checkWifNetwork } from "../util/checkWifNetwork";
|
|
66
|
-
import { deriveCashaddr } from "../util/deriveCashaddr";
|
|
67
|
-
import {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
import {
|
|
72
|
-
import {
|
|
73
|
-
import {
|
|
61
|
+
} from "../util/balanceObjectFromSatoshi.js";
|
|
62
|
+
import { checkWifNetwork } from "../util/checkWifNetwork.js";
|
|
63
|
+
import { deriveCashaddr, deriveTokenaddr } from "../util/deriveCashaddr.js";
|
|
64
|
+
import {
|
|
65
|
+
derivePrefix,
|
|
66
|
+
derivePublicKeyHash,
|
|
67
|
+
} from "../util/derivePublicKeyHash.js";
|
|
68
|
+
import { checkForEmptySeed } from "../util/checkForEmptySeed.js";
|
|
69
|
+
import { sanitizeUnit } from "../util/sanitizeUnit.js";
|
|
70
|
+
import { sumTokenAmounts, sumUtxoValue } from "../util/sumUtxoValue.js";
|
|
71
|
+
import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
|
|
72
|
+
import { ElectrumRawTransaction } from "../network/interface.js";
|
|
73
|
+
import { getRelayFeeCache } from "../network/getRelayFeeCache.js";
|
|
74
74
|
import {
|
|
75
75
|
RegTestSlp,
|
|
76
76
|
RegTestWatchSlp,
|
|
@@ -81,10 +81,10 @@ import {
|
|
|
81
81
|
TestNetWifSlp,
|
|
82
82
|
WatchSlp,
|
|
83
83
|
WifSlp,
|
|
84
|
-
} from "./Slp";
|
|
84
|
+
} from "./Slp.js";
|
|
85
85
|
import axios from "axios";
|
|
86
|
-
import { SlpSendResponse } from "../slp/interface";
|
|
87
|
-
import { toCashAddress } from "../util/bchaddr";
|
|
86
|
+
import { SlpSendResponse } from "../slp/interface.js";
|
|
87
|
+
import { toCashAddress } from "../util/bchaddr.js";
|
|
88
88
|
import {
|
|
89
89
|
RegTestUtil,
|
|
90
90
|
RegTestWatchUtil,
|
|
@@ -95,28 +95,30 @@ import {
|
|
|
95
95
|
Util,
|
|
96
96
|
WatchUtil,
|
|
97
97
|
WifUtil,
|
|
98
|
-
} from "./Util";
|
|
99
|
-
import { getNetworkProvider } from "../network/index";
|
|
100
|
-
import { generateRandomBytes } from "../util/randomBytes";
|
|
101
|
-
import { SignedMessageI, SignedMessage } from "../message";
|
|
102
|
-
import ElectrumNetworkProvider from "../network/ElectrumNetworkProvider";
|
|
103
|
-
import { amountInSatoshi } from "../util/amountInSatoshi";
|
|
104
|
-
import { getXPubKey } from "../util/getXPubKey";
|
|
105
|
-
import { DERIVATION_PATHS, DUST_UTXO_THRESHOLD } from "../constant";
|
|
106
|
-
|
|
107
|
-
import { TransactionHistoryI } from "../history/interface";
|
|
108
|
-
import { getAddressHistory } from "../history/electrumTransformer";
|
|
98
|
+
} from "./Util.js";
|
|
99
|
+
import { getNetworkProvider } from "../network/index.js";
|
|
100
|
+
import { generateRandomBytes } from "../util/randomBytes.js";
|
|
101
|
+
import { SignedMessageI, SignedMessage } from "../message/index.js";
|
|
102
|
+
import ElectrumNetworkProvider from "../network/ElectrumNetworkProvider.js";
|
|
103
|
+
import { amountInSatoshi } from "../util/amountInSatoshi.js";
|
|
104
|
+
import { getXPubKey } from "../util/getXPubKey.js";
|
|
105
|
+
import { DERIVATION_PATHS, DUST_UTXO_THRESHOLD } from "../constant.js";
|
|
106
|
+
|
|
107
|
+
import { TransactionHistoryI } from "../history/interface.js";
|
|
108
|
+
import { getAddressHistory } from "../history/electrumTransformer.js";
|
|
109
|
+
import { IdentitySnapshot, Registry } from "./bcmr-v1.schema.js";
|
|
110
|
+
import { BCMR } from "./Bcmr.js";
|
|
111
|
+
import { qrAddress } from "../qr/Qr.js";
|
|
112
|
+
import { ImageI } from "../qr/interface.js";
|
|
109
113
|
|
|
110
114
|
//#endregion Imports
|
|
111
115
|
|
|
112
|
-
const secp256k1Promise = instantiateSecp256k1();
|
|
113
|
-
const sha256Promise = instantiateSha256();
|
|
114
|
-
|
|
115
116
|
/**
|
|
116
117
|
* Class to manage a bitcoin cash wallet.
|
|
117
118
|
*/
|
|
118
119
|
export class Wallet extends BaseWallet {
|
|
119
120
|
cashaddr?: string;
|
|
121
|
+
tokenaddr?: string;
|
|
120
122
|
derivationPath: string = "m/44'/0'/0'/0/0";
|
|
121
123
|
parentDerivationPath: string = "m/44'/0'/0'";
|
|
122
124
|
parentXPubKey?: string;
|
|
@@ -176,6 +178,24 @@ export class Wallet extends BaseWallet {
|
|
|
176
178
|
return getNetworkProvider(network);
|
|
177
179
|
}
|
|
178
180
|
|
|
181
|
+
/**
|
|
182
|
+
* getTokenDepositAddress - get a cashtoken aware wallet deposit address
|
|
183
|
+
*
|
|
184
|
+
* @returns The cashtoken aware deposit address as a string
|
|
185
|
+
*/
|
|
186
|
+
public getTokenDepositAddress(): string {
|
|
187
|
+
return this.tokenaddr!;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* getDepositQr - get an address qrcode, encoded for display on the web
|
|
192
|
+
*
|
|
193
|
+
* @returns The qrcode for the token aware address
|
|
194
|
+
*/
|
|
195
|
+
public getTokenDepositQr(): ImageI {
|
|
196
|
+
return qrAddress(this.getTokenDepositAddress());
|
|
197
|
+
}
|
|
198
|
+
|
|
179
199
|
/**
|
|
180
200
|
* explorerUrl Web url to a transaction on a block explorer
|
|
181
201
|
*
|
|
@@ -196,6 +216,7 @@ export class Wallet extends BaseWallet {
|
|
|
196
216
|
public getInfo(): WalletInfoI {
|
|
197
217
|
return {
|
|
198
218
|
cashaddr: this.cashaddr,
|
|
219
|
+
tokenaddr: this.tokenaddr,
|
|
199
220
|
isTestnet: this.isTestnet,
|
|
200
221
|
name: this.name,
|
|
201
222
|
network: this.network as any,
|
|
@@ -296,6 +317,27 @@ export class Wallet extends BaseWallet {
|
|
|
296
317
|
) as InstanceType<T>;
|
|
297
318
|
}
|
|
298
319
|
|
|
320
|
+
/**
|
|
321
|
+
* fromTokenaddr - create a watch-only wallet in the network derived from the address
|
|
322
|
+
*
|
|
323
|
+
* such kind of wallet does not have a private key and is unable to spend any funds
|
|
324
|
+
* however it still allows to use many utility functions such as getting and watching balance, etc.
|
|
325
|
+
*
|
|
326
|
+
* @param address token aware cashaddress of a wallet
|
|
327
|
+
*
|
|
328
|
+
* @returns instantiated wallet
|
|
329
|
+
*/
|
|
330
|
+
public static async fromTokenaddr<T extends typeof Wallet>(
|
|
331
|
+
this: T,
|
|
332
|
+
address: string
|
|
333
|
+
): Promise<InstanceType<T>> {
|
|
334
|
+
const prefix = derivePrefix(address);
|
|
335
|
+
const networkType = networkPrefixMap[prefix] as NetworkType;
|
|
336
|
+
return new this("", networkType, WalletTypeEnum.Watch).watchOnly(
|
|
337
|
+
address
|
|
338
|
+
) as InstanceType<T>;
|
|
339
|
+
}
|
|
340
|
+
|
|
299
341
|
/**
|
|
300
342
|
* fromSlpaddr - create an SLP aware watch-only wallet in the network derived from the address
|
|
301
343
|
*
|
|
@@ -350,13 +392,12 @@ export class Wallet extends BaseWallet {
|
|
|
350
392
|
network
|
|
351
393
|
);
|
|
352
394
|
|
|
353
|
-
|
|
354
|
-
let hdNode = deriveHdPrivateNodeFromSeed(crypto, seed);
|
|
395
|
+
let hdNode = deriveHdPrivateNodeFromSeed(seed);
|
|
355
396
|
if (!hdNode.valid) {
|
|
356
397
|
throw Error("Invalid private key derived from mnemonic seed");
|
|
357
398
|
}
|
|
358
399
|
|
|
359
|
-
let zerothChild = deriveHdPath(
|
|
400
|
+
let zerothChild = deriveHdPath(hdNode, this.derivationPath);
|
|
360
401
|
if (typeof zerothChild === "string") {
|
|
361
402
|
throw Error(zerothChild);
|
|
362
403
|
}
|
|
@@ -400,12 +441,11 @@ export class Wallet extends BaseWallet {
|
|
|
400
441
|
): Promise<this> {
|
|
401
442
|
this.mnemonic = mnemonic;
|
|
402
443
|
|
|
403
|
-
const crypto = await instantiateBIP32Crypto();
|
|
404
444
|
if (this.mnemonic.length == 0)
|
|
405
445
|
throw Error("refusing to create wallet from empty mnemonic");
|
|
406
446
|
let seed = mnemonicToSeedSync(this.mnemonic);
|
|
407
447
|
checkForEmptySeed(seed);
|
|
408
|
-
let hdNode = deriveHdPrivateNodeFromSeed(
|
|
448
|
+
let hdNode = deriveHdPrivateNodeFromSeed(seed);
|
|
409
449
|
if (!hdNode.valid) {
|
|
410
450
|
throw Error("Invalid private key derived from mnemonic seed");
|
|
411
451
|
}
|
|
@@ -419,7 +459,7 @@ export class Wallet extends BaseWallet {
|
|
|
419
459
|
}
|
|
420
460
|
}
|
|
421
461
|
|
|
422
|
-
let zerothChild = deriveHdPath(
|
|
462
|
+
let zerothChild = deriveHdPath(hdNode, this.derivationPath);
|
|
423
463
|
if (typeof zerothChild === "string") {
|
|
424
464
|
throw Error(zerothChild);
|
|
425
465
|
}
|
|
@@ -439,12 +479,11 @@ export class Wallet extends BaseWallet {
|
|
|
439
479
|
|
|
440
480
|
// Get common xpub paths from zerothChild privateKey
|
|
441
481
|
public async deriveHdPaths(hdPaths: string[]): Promise<any[]> {
|
|
442
|
-
const crypto = await instantiateBIP32Crypto();
|
|
443
482
|
if (!this.mnemonic)
|
|
444
483
|
throw Error("refusing to create wallet from empty mnemonic");
|
|
445
484
|
let seed = mnemonicToSeedSync(this.mnemonic!);
|
|
446
485
|
checkForEmptySeed(seed);
|
|
447
|
-
let hdNode = deriveHdPrivateNodeFromSeed(
|
|
486
|
+
let hdNode = deriveHdPrivateNodeFromSeed(seed);
|
|
448
487
|
if (!hdNode.valid) {
|
|
449
488
|
throw Error("Invalid private key derived from mnemonic seed");
|
|
450
489
|
}
|
|
@@ -457,15 +496,15 @@ export class Wallet extends BaseWallet {
|
|
|
457
496
|
"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"
|
|
458
497
|
);
|
|
459
498
|
}
|
|
460
|
-
let childNode = deriveHdPath(
|
|
499
|
+
let childNode = deriveHdPath(hdNode, path);
|
|
461
500
|
if (typeof childNode === "string") {
|
|
462
501
|
throw Error(childNode);
|
|
463
502
|
}
|
|
464
|
-
let node = deriveHdPublicNode(
|
|
503
|
+
let node = deriveHdPublicNode(childNode);
|
|
465
504
|
if (typeof node === "string") {
|
|
466
505
|
throw Error(node);
|
|
467
506
|
}
|
|
468
|
-
let xPubKey = encodeHdPublicKey(
|
|
507
|
+
let xPubKey = encodeHdPublicKey({
|
|
469
508
|
network: this.network as HdKeyNetwork,
|
|
470
509
|
node: node,
|
|
471
510
|
});
|
|
@@ -504,6 +543,7 @@ export class Wallet extends BaseWallet {
|
|
|
504
543
|
this.cashaddr = `${addressPrefix}:${addressBase}`;
|
|
505
544
|
this.address = this.cashaddr;
|
|
506
545
|
this.publicKeyHash = derivePublicKeyHash(this.cashaddr);
|
|
546
|
+
this.tokenaddr = deriveTokenaddr(this.publicKeyHash, this.networkPrefix);
|
|
507
547
|
|
|
508
548
|
return this;
|
|
509
549
|
}
|
|
@@ -512,8 +552,7 @@ export class Wallet extends BaseWallet {
|
|
|
512
552
|
protected async fromWIF(secret: string): Promise<this> {
|
|
513
553
|
checkWifNetwork(secret, this.network);
|
|
514
554
|
|
|
515
|
-
|
|
516
|
-
let wifResult = decodePrivateKeyWif(sha256, secret);
|
|
555
|
+
let wifResult = decodePrivateKeyWif(secret);
|
|
517
556
|
|
|
518
557
|
if (typeof wifResult === "string") {
|
|
519
558
|
throw Error(wifResult as string);
|
|
@@ -586,9 +625,9 @@ export class Wallet extends BaseWallet {
|
|
|
586
625
|
|
|
587
626
|
//#region Funds
|
|
588
627
|
//
|
|
589
|
-
public async getAddressUtxos(address
|
|
590
|
-
if (!
|
|
591
|
-
|
|
628
|
+
public async getAddressUtxos(address?: string): Promise<UtxoI[]> {
|
|
629
|
+
if (!address) {
|
|
630
|
+
address = this.cashaddr!;
|
|
592
631
|
}
|
|
593
632
|
|
|
594
633
|
if (this._slpAware) {
|
|
@@ -652,18 +691,24 @@ export class Wallet extends BaseWallet {
|
|
|
652
691
|
|
|
653
692
|
// Gets balance by summing value in all utxos in stats
|
|
654
693
|
public async getBalanceFromUtxos(): Promise<number> {
|
|
655
|
-
const utxos = await this.getAddressUtxos(this.cashaddr!)
|
|
656
|
-
|
|
694
|
+
const utxos = (await this.getAddressUtxos(this.cashaddr!)).filter(
|
|
695
|
+
(val) => val.token === undefined
|
|
696
|
+
);
|
|
697
|
+
return sumUtxoValue(utxos);
|
|
657
698
|
}
|
|
658
699
|
|
|
659
700
|
// Gets balance from fulcrum
|
|
660
701
|
public async getBalanceFromProvider(): Promise<number> {
|
|
661
|
-
//
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
702
|
+
// Fulcrum reports balance of all utxos, including tokens, which is undesirable
|
|
703
|
+
// // TODO not sure why getting the balance from a provider doesn't work
|
|
704
|
+
// if (this._slpAware || this._slpSemiAware) {
|
|
705
|
+
// return await this.getBalanceFromUtxos();
|
|
706
|
+
// } else {
|
|
707
|
+
// return await this.provider!.getBalance(this.cashaddr!);
|
|
708
|
+
// }
|
|
709
|
+
|
|
710
|
+
// FIXME
|
|
711
|
+
return this.getBalanceFromUtxos();
|
|
667
712
|
}
|
|
668
713
|
|
|
669
714
|
// // waiting for any transaction hash of this wallet
|
|
@@ -752,7 +797,51 @@ export class Wallet extends BaseWallet {
|
|
|
752
797
|
});
|
|
753
798
|
}
|
|
754
799
|
|
|
755
|
-
|
|
800
|
+
// sets up a callback to be called upon wallet's token balance change
|
|
801
|
+
// can be cancelled by calling the function returned from this one
|
|
802
|
+
public watchTokenBalance(
|
|
803
|
+
tokenId: string,
|
|
804
|
+
callback: (balance: number) => void
|
|
805
|
+
): CancelWatchFn {
|
|
806
|
+
let previous: number | undefined = undefined;
|
|
807
|
+
return (this.provider! as ElectrumNetworkProvider).watchAddressStatus(
|
|
808
|
+
this.getDepositAddress(),
|
|
809
|
+
async (_status: string) => {
|
|
810
|
+
const balance = await this.getTokenBalance(tokenId);
|
|
811
|
+
if (previous != balance) {
|
|
812
|
+
callback(balance);
|
|
813
|
+
}
|
|
814
|
+
previous = balance;
|
|
815
|
+
}
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// waits for address token balance to be greater than or equal to the target amount
|
|
820
|
+
// this call halts the execution
|
|
821
|
+
public async waitForTokenBalance(
|
|
822
|
+
tokenId: string,
|
|
823
|
+
amount: number
|
|
824
|
+
): Promise<number> {
|
|
825
|
+
return new Promise(async (resolve) => {
|
|
826
|
+
const watchCancel = this.watchTokenBalance(
|
|
827
|
+
tokenId,
|
|
828
|
+
async (balance: number) => {
|
|
829
|
+
if (balance >= amount) {
|
|
830
|
+
await watchCancel();
|
|
831
|
+
resolve(balance);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
);
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
public async getTokenInfo(
|
|
839
|
+
tokenId: string
|
|
840
|
+
): Promise<IdentitySnapshot | undefined> {
|
|
841
|
+
return BCMR.getTokenInfo(tokenId);
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
private async _getMaxAmountToSend(
|
|
756
845
|
params: {
|
|
757
846
|
outputCount?: number;
|
|
758
847
|
options?: SendRequestOptionsI;
|
|
@@ -760,7 +849,7 @@ export class Wallet extends BaseWallet {
|
|
|
760
849
|
outputCount: 1,
|
|
761
850
|
options: {},
|
|
762
851
|
}
|
|
763
|
-
): Promise<
|
|
852
|
+
): Promise<{ value: number; utxos: UtxoI[] }> {
|
|
764
853
|
if (!this.privateKey) {
|
|
765
854
|
throw Error("Couldn't get network or private key for wallet.");
|
|
766
855
|
}
|
|
@@ -790,7 +879,9 @@ export class Wallet extends BaseWallet {
|
|
|
790
879
|
UtxoItem.fromId(utxoId).asElectrum()
|
|
791
880
|
);
|
|
792
881
|
} else {
|
|
793
|
-
utxos = await this.getAddressUtxos(this.cashaddr)
|
|
882
|
+
utxos = (await this.getAddressUtxos(this.cashaddr)).filter(
|
|
883
|
+
(utxo) => !utxo.token
|
|
884
|
+
);
|
|
794
885
|
}
|
|
795
886
|
|
|
796
887
|
// Get current height to assure recently mined coins are not spent.
|
|
@@ -810,7 +901,8 @@ export class Wallet extends BaseWallet {
|
|
|
810
901
|
utxos,
|
|
811
902
|
undefined,
|
|
812
903
|
bestHeight,
|
|
813
|
-
feePaidBy
|
|
904
|
+
feePaidBy,
|
|
905
|
+
sendRequests
|
|
814
906
|
);
|
|
815
907
|
const relayFeePerByteInSatoshi = await getRelayFeeCache(this.provider!);
|
|
816
908
|
const fee = await getFeeAmount({
|
|
@@ -821,13 +913,27 @@ export class Wallet extends BaseWallet {
|
|
|
821
913
|
slpOutputs: [],
|
|
822
914
|
feePaidBy: feePaidBy,
|
|
823
915
|
});
|
|
824
|
-
const spendableAmount =
|
|
916
|
+
const spendableAmount = sumUtxoValue(fundingUtxos);
|
|
825
917
|
|
|
826
918
|
let result = spendableAmount - fee;
|
|
827
919
|
if (result < 0) {
|
|
828
920
|
result = 0;
|
|
829
921
|
}
|
|
830
922
|
|
|
923
|
+
return { value: result, utxos: fundingUtxos };
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
public async getMaxAmountToSend(
|
|
927
|
+
params: {
|
|
928
|
+
outputCount?: number;
|
|
929
|
+
options?: SendRequestOptionsI;
|
|
930
|
+
} = {
|
|
931
|
+
outputCount: 1,
|
|
932
|
+
options: {},
|
|
933
|
+
}
|
|
934
|
+
): Promise<BalanceResponse> {
|
|
935
|
+
const { value: result } = await this._getMaxAmountToSend(params);
|
|
936
|
+
|
|
831
937
|
return await balanceResponseFromSatoshi(result);
|
|
832
938
|
}
|
|
833
939
|
|
|
@@ -842,12 +948,13 @@ export class Wallet extends BaseWallet {
|
|
|
842
948
|
public async send(
|
|
843
949
|
requests:
|
|
844
950
|
| SendRequest
|
|
951
|
+
| TokenSendRequest
|
|
845
952
|
| OpReturnData
|
|
846
|
-
| Array<SendRequest | OpReturnData>
|
|
953
|
+
| Array<SendRequest | TokenSendRequest | OpReturnData>
|
|
847
954
|
| SendRequestArray[],
|
|
848
955
|
options?: SendRequestOptionsI
|
|
849
956
|
): Promise<SendResponse> {
|
|
850
|
-
let encodedTransaction = await this.encodeTransaction(
|
|
957
|
+
let { encodedTransaction, tokenIds } = await this.encodeTransaction(
|
|
851
958
|
requests,
|
|
852
959
|
undefined,
|
|
853
960
|
options
|
|
@@ -871,6 +978,7 @@ export class Wallet extends BaseWallet {
|
|
|
871
978
|
resp.balance = (await this.getBalance()) as BalanceResponse;
|
|
872
979
|
}
|
|
873
980
|
resp.explorerUrl = this.explorerUrl(resp.txId);
|
|
981
|
+
resp.tokenIds = tokenIds;
|
|
874
982
|
return resp;
|
|
875
983
|
}
|
|
876
984
|
|
|
@@ -910,20 +1018,24 @@ export class Wallet extends BaseWallet {
|
|
|
910
1018
|
cashaddr: string,
|
|
911
1019
|
options?: SendRequestOptionsI
|
|
912
1020
|
): Promise<string> {
|
|
913
|
-
let maxSpendableAmount = await this.
|
|
1021
|
+
let { value: maxSpendableAmount, utxos } = await this._getMaxAmountToSend({
|
|
914
1022
|
outputCount: 1,
|
|
915
1023
|
options: options,
|
|
916
1024
|
});
|
|
917
|
-
|
|
918
|
-
|
|
1025
|
+
|
|
1026
|
+
if (!options) {
|
|
1027
|
+
options = {};
|
|
919
1028
|
}
|
|
1029
|
+
|
|
1030
|
+
options.utxoIds = utxos;
|
|
1031
|
+
|
|
920
1032
|
let sendRequest = new SendRequest({
|
|
921
1033
|
cashaddr: cashaddr,
|
|
922
|
-
value: maxSpendableAmount
|
|
1034
|
+
value: maxSpendableAmount,
|
|
923
1035
|
unit: "sat",
|
|
924
1036
|
});
|
|
925
1037
|
|
|
926
|
-
const encodedTransaction = await this.encodeTransaction(
|
|
1038
|
+
const { encodedTransaction } = await this.encodeTransaction(
|
|
927
1039
|
[sendRequest],
|
|
928
1040
|
true,
|
|
929
1041
|
options
|
|
@@ -950,8 +1062,9 @@ export class Wallet extends BaseWallet {
|
|
|
950
1062
|
public async encodeTransaction(
|
|
951
1063
|
requests:
|
|
952
1064
|
| SendRequest
|
|
1065
|
+
| TokenSendRequest
|
|
953
1066
|
| OpReturnData
|
|
954
|
-
| Array<SendRequest | OpReturnData>
|
|
1067
|
+
| Array<SendRequest | TokenSendRequest | OpReturnData>
|
|
955
1068
|
| SendRequestArray[],
|
|
956
1069
|
discardChange: boolean = false,
|
|
957
1070
|
options?: SendRequestOptionsI
|
|
@@ -989,16 +1102,74 @@ export class Wallet extends BaseWallet {
|
|
|
989
1102
|
changeAddress = "";
|
|
990
1103
|
}
|
|
991
1104
|
|
|
1105
|
+
let checkTokenQuantities: boolean = true;
|
|
1106
|
+
if (options && options.checkTokenQuantities === false) {
|
|
1107
|
+
checkTokenQuantities = false;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
992
1110
|
// get inputs from options or query all inputs
|
|
993
1111
|
let utxos: UtxoI[];
|
|
994
1112
|
if (options && options.utxoIds) {
|
|
995
1113
|
utxos = options.utxoIds.map((utxoId) =>
|
|
996
|
-
|
|
1114
|
+
typeof utxoId === "string"
|
|
1115
|
+
? UtxoItem.fromId(utxoId).asElectrum()
|
|
1116
|
+
: utxoId
|
|
997
1117
|
);
|
|
998
1118
|
} else {
|
|
999
1119
|
utxos = await this.getAddressUtxos(this.cashaddr);
|
|
1000
1120
|
}
|
|
1001
1121
|
|
|
1122
|
+
const addTokenChangeOutputs = (
|
|
1123
|
+
inputs: UtxoI[],
|
|
1124
|
+
outputs: SendRequestType[]
|
|
1125
|
+
) => {
|
|
1126
|
+
// allow for implicit token burn if the total amount sent is less than user had
|
|
1127
|
+
// allow for token genesis, creating more tokens than we had before (0)
|
|
1128
|
+
if (!checkTokenQuantities) {
|
|
1129
|
+
return;
|
|
1130
|
+
}
|
|
1131
|
+
const allTokenInputs = inputs.filter((val) => val.token);
|
|
1132
|
+
const allTokenOutputs = outputs.filter(
|
|
1133
|
+
(val) => val instanceof TokenSendRequest
|
|
1134
|
+
) as TokenSendRequest[];
|
|
1135
|
+
const tokenIds = allTokenOutputs
|
|
1136
|
+
.map((val) => val.tokenId)
|
|
1137
|
+
.filter((val, idx, arr) => arr.indexOf(val) === idx);
|
|
1138
|
+
for (let tokenId of tokenIds) {
|
|
1139
|
+
const tokenInputs = allTokenInputs.filter(
|
|
1140
|
+
(val) => val.token?.tokenId === tokenId
|
|
1141
|
+
);
|
|
1142
|
+
const inputAmountSum = tokenInputs.reduce(
|
|
1143
|
+
(prev, cur) => prev + cur.token!.amount,
|
|
1144
|
+
0
|
|
1145
|
+
);
|
|
1146
|
+
const tokenOutputs = allTokenOutputs.filter(
|
|
1147
|
+
(val) => val.tokenId === tokenId
|
|
1148
|
+
);
|
|
1149
|
+
const outputAmountSum = tokenOutputs.reduce(
|
|
1150
|
+
(prev, cur) => prev + cur.amount,
|
|
1151
|
+
0
|
|
1152
|
+
);
|
|
1153
|
+
const change = inputAmountSum - outputAmountSum;
|
|
1154
|
+
if (change < 0) {
|
|
1155
|
+
throw new Error("Not enough token amount to send");
|
|
1156
|
+
}
|
|
1157
|
+
if (change > 0) {
|
|
1158
|
+
outputs.push(
|
|
1159
|
+
new TokenSendRequest({
|
|
1160
|
+
cashaddr: changeAddress || this.cashaddr,
|
|
1161
|
+
amount: change,
|
|
1162
|
+
tokenId: tokenId,
|
|
1163
|
+
commitment: tokenOutputs[0].commitment,
|
|
1164
|
+
capability: tokenOutputs[0].capability,
|
|
1165
|
+
value: tokenOutputs[0].value,
|
|
1166
|
+
})
|
|
1167
|
+
);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
};
|
|
1171
|
+
addTokenChangeOutputs(utxos, sendRequests);
|
|
1172
|
+
|
|
1002
1173
|
const bestHeight = await this.provider!.getBlockHeight()!;
|
|
1003
1174
|
const spendAmount = await sumSendRequestAmounts(sendRequests);
|
|
1004
1175
|
|
|
@@ -1023,7 +1194,8 @@ export class Wallet extends BaseWallet {
|
|
|
1023
1194
|
utxos,
|
|
1024
1195
|
BigInt(spendAmount) + BigInt(feeEstimate),
|
|
1025
1196
|
bestHeight,
|
|
1026
|
-
feePaidBy
|
|
1197
|
+
feePaidBy,
|
|
1198
|
+
sendRequests
|
|
1027
1199
|
);
|
|
1028
1200
|
if (fundingUtxos.length === 0) {
|
|
1029
1201
|
throw Error(
|
|
@@ -1049,7 +1221,16 @@ export class Wallet extends BaseWallet {
|
|
|
1049
1221
|
changeAddress
|
|
1050
1222
|
);
|
|
1051
1223
|
|
|
1052
|
-
|
|
1224
|
+
const tokenIds = [
|
|
1225
|
+
...fundingUtxos
|
|
1226
|
+
.filter((val) => val.token?.tokenId)
|
|
1227
|
+
.map((val) => val.token!.tokenId),
|
|
1228
|
+
...sendRequests
|
|
1229
|
+
.filter((val) => val instanceof TokenSendRequest)
|
|
1230
|
+
.map((val) => (val as TokenSendRequest).tokenId),
|
|
1231
|
+
].filter((value, index, array) => array.indexOf(value) === index);
|
|
1232
|
+
|
|
1233
|
+
return { encodedTransaction, tokenIds: tokenIds };
|
|
1053
1234
|
}
|
|
1054
1235
|
|
|
1055
1236
|
// Submit a raw transaction
|
|
@@ -1199,25 +1380,25 @@ export class Wallet extends BaseWallet {
|
|
|
1199
1380
|
|
|
1200
1381
|
//#region Private implementation details
|
|
1201
1382
|
private async deriveInfo() {
|
|
1202
|
-
const
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1383
|
+
const publicKey = secp256k1.derivePublicKeyUncompressed(this.privateKey!);
|
|
1384
|
+
if (typeof publicKey === "string") {
|
|
1385
|
+
throw new Error(publicKey);
|
|
1386
|
+
}
|
|
1387
|
+
this.publicKey = publicKey;
|
|
1388
|
+
const publicKeyCompressed = secp256k1.derivePublicKeyCompressed(
|
|
1206
1389
|
this.privateKey!
|
|
1207
1390
|
);
|
|
1391
|
+
if (typeof publicKeyCompressed === "string") {
|
|
1392
|
+
throw new Error(publicKeyCompressed);
|
|
1393
|
+
}
|
|
1394
|
+
this.publicKeyCompressed = publicKeyCompressed;
|
|
1208
1395
|
const networkType =
|
|
1209
1396
|
this.network === NetworkType.Regtest ? NetworkType.Testnet : this.network;
|
|
1210
|
-
this.privateKeyWif = encodePrivateKeyWif(
|
|
1211
|
-
sha256,
|
|
1212
|
-
this.privateKey!,
|
|
1213
|
-
networkType
|
|
1214
|
-
);
|
|
1397
|
+
this.privateKeyWif = encodePrivateKeyWif(this.privateKey!, networkType);
|
|
1215
1398
|
checkWifNetwork(this.privateKeyWif, this.network);
|
|
1216
1399
|
|
|
1217
|
-
this.cashaddr = (
|
|
1218
|
-
|
|
1219
|
-
this.networkPrefix
|
|
1220
|
-
)) as string;
|
|
1400
|
+
this.cashaddr = deriveCashaddr(this.privateKey!, this.networkPrefix);
|
|
1401
|
+
this.tokenaddr = deriveTokenaddr(this.privateKey!, this.networkPrefix);
|
|
1221
1402
|
this.address = this.cashaddr;
|
|
1222
1403
|
this.publicKeyHash = derivePublicKeyHash(this.cashaddr!);
|
|
1223
1404
|
return this;
|
|
@@ -1240,6 +1421,260 @@ export class Wallet extends BaseWallet {
|
|
|
1240
1421
|
);
|
|
1241
1422
|
}
|
|
1242
1423
|
//#endregion Signing
|
|
1424
|
+
|
|
1425
|
+
//#region Cashtokens
|
|
1426
|
+
/**
|
|
1427
|
+
* Create new cashtoken, both funglible and/or non-fungible (NFT)
|
|
1428
|
+
* Refer to spec https://github.com/bitjson/cashtokens
|
|
1429
|
+
* @param {number} genesisRequest.amount amount of *fungible* tokens to create
|
|
1430
|
+
* @param {NFTCapability?} genesisRequest.capability capability of new NFT
|
|
1431
|
+
* @param {string?} genesisRequest.commitment NFT commitment message
|
|
1432
|
+
* @param {string?} genesisRequest.cashaddr cash address to send the created token UTXO to; if undefined will default to your address
|
|
1433
|
+
* @param {number?} genesisRequest.value satoshi value to send alongside with tokens; if undefined will default to 1000 satoshi
|
|
1434
|
+
*/
|
|
1435
|
+
public async tokenGenesis(
|
|
1436
|
+
genesisRequest: TokenGenesisRequest
|
|
1437
|
+
): Promise<SendResponse> {
|
|
1438
|
+
return this.send(
|
|
1439
|
+
new TokenSendRequest({
|
|
1440
|
+
cashaddr: genesisRequest.cashaddr || this.cashaddr!,
|
|
1441
|
+
amount: genesisRequest.amount,
|
|
1442
|
+
value: genesisRequest.value,
|
|
1443
|
+
capability: genesisRequest.capability,
|
|
1444
|
+
commitment: genesisRequest.commitment,
|
|
1445
|
+
tokenId: "",
|
|
1446
|
+
}),
|
|
1447
|
+
{
|
|
1448
|
+
checkTokenQuantities: false,
|
|
1449
|
+
queryBalance: false,
|
|
1450
|
+
}
|
|
1451
|
+
);
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* Mint new NFT cashtokens using an existing minting token
|
|
1456
|
+
* Refer to spec https://github.com/bitjson/cashtokens
|
|
1457
|
+
* @param {string} tokenId tokenId of an NFT to mint
|
|
1458
|
+
* @param {TokenMintRequest | TokenMintRequest[]} mintRequests mint requests with new token properties and recipients
|
|
1459
|
+
* @param {NFTCapability?} mintRequest.capability capability of new NFT
|
|
1460
|
+
* @param {string?} mintRequest.commitment NFT commitment message
|
|
1461
|
+
* @param {string?} mintRequest.cashaddr cash address to send the created token UTXO to; if undefined will default to your address
|
|
1462
|
+
* @param {number?} mintRequest.value satoshi value to send alongside with tokens; if undefined will default to 1000 satoshi
|
|
1463
|
+
* @param {boolean?} deductTokenAmount if minting token contains fungible amount, deduct from it by amount of minted tokens
|
|
1464
|
+
*/
|
|
1465
|
+
public async tokenMint(
|
|
1466
|
+
tokenId: string,
|
|
1467
|
+
mintRequests: TokenMintRequest | Array<TokenMintRequest>,
|
|
1468
|
+
deductTokenAmount: boolean = false
|
|
1469
|
+
): Promise<SendResponse> {
|
|
1470
|
+
if (!Array.isArray(mintRequests)) {
|
|
1471
|
+
mintRequests = [mintRequests];
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
const utxos = await this.getAddressUtxos(this.cashaddr!);
|
|
1475
|
+
const nftUtxos = utxos.filter(
|
|
1476
|
+
(val) =>
|
|
1477
|
+
val.token?.tokenId === tokenId &&
|
|
1478
|
+
val.token?.capability != NFTCapability.none
|
|
1479
|
+
);
|
|
1480
|
+
if (!nftUtxos.length) {
|
|
1481
|
+
throw new Error(
|
|
1482
|
+
"You do not have any token UTXOs with minting capability for specified tokenId"
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
const newAmount =
|
|
1486
|
+
deductTokenAmount && nftUtxos[0].token!.amount > 0
|
|
1487
|
+
? nftUtxos[0].token!.amount - mintRequests.length
|
|
1488
|
+
: nftUtxos[0].token!.amount;
|
|
1489
|
+
const safeNewAmount = Math.max(0, newAmount);
|
|
1490
|
+
const mintingInput = new TokenSendRequest({
|
|
1491
|
+
cashaddr: this.cashaddr!,
|
|
1492
|
+
tokenId: tokenId,
|
|
1493
|
+
capability: nftUtxos[0].token!.capability,
|
|
1494
|
+
commitment: nftUtxos[0].token!.commitment,
|
|
1495
|
+
amount: safeNewAmount,
|
|
1496
|
+
value: nftUtxos[0].satoshis,
|
|
1497
|
+
});
|
|
1498
|
+
return this.send(
|
|
1499
|
+
[
|
|
1500
|
+
mintingInput,
|
|
1501
|
+
...mintRequests.map(
|
|
1502
|
+
(val) =>
|
|
1503
|
+
new TokenSendRequest({
|
|
1504
|
+
cashaddr: val.cashaddr || this.cashaddr!,
|
|
1505
|
+
amount: 0,
|
|
1506
|
+
tokenId: tokenId,
|
|
1507
|
+
value: val.value,
|
|
1508
|
+
capability: val.capability,
|
|
1509
|
+
commitment: val.commitment,
|
|
1510
|
+
})
|
|
1511
|
+
),
|
|
1512
|
+
],
|
|
1513
|
+
{
|
|
1514
|
+
checkTokenQuantities: false,
|
|
1515
|
+
queryBalance: false,
|
|
1516
|
+
}
|
|
1517
|
+
);
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
/**
|
|
1521
|
+
* Perform an explicit token burning by spending a token utxo to an OP_RETURN
|
|
1522
|
+
*
|
|
1523
|
+
* Behaves differently for fungible and non-fungible tokens:
|
|
1524
|
+
* * NFTs are always "destroyed"
|
|
1525
|
+
* * FTs' amount is reduced by the amount specified, if 0 FT amount is left and no NFT present, the token is "destroyed"
|
|
1526
|
+
*
|
|
1527
|
+
* Refer to spec https://github.com/bitjson/cashtokens
|
|
1528
|
+
* @param {string} burnRequest.tokenId tokenId of a token to burn
|
|
1529
|
+
* @param {NFTCapability} burnRequest.capability capability of the NFT token to select, optional
|
|
1530
|
+
* @param {string?} burnRequest.commitment commitment of the NFT token to select, optional
|
|
1531
|
+
* @param {number?} burnRequest.amount amount of fungible tokens to burn, optional
|
|
1532
|
+
* @param {string?} burnRequest.cashaddr address to return token and satoshi change to
|
|
1533
|
+
* @param {string?} message optional message to include in OP_RETURN
|
|
1534
|
+
*/
|
|
1535
|
+
public async tokenBurn(
|
|
1536
|
+
burnRequest: TokenBurnRequest,
|
|
1537
|
+
message?: string
|
|
1538
|
+
): Promise<SendResponse> {
|
|
1539
|
+
const utxos = await this.getAddressUtxos(this.cashaddr!);
|
|
1540
|
+
const tokenUtxos = utxos.filter(
|
|
1541
|
+
(val) =>
|
|
1542
|
+
val.token?.tokenId === burnRequest.tokenId &&
|
|
1543
|
+
val.token?.capability === burnRequest.capability &&
|
|
1544
|
+
val.token?.commitment === burnRequest.commitment &&
|
|
1545
|
+
val.token?.capability === burnRequest.capability
|
|
1546
|
+
);
|
|
1547
|
+
|
|
1548
|
+
if (!tokenUtxos.length) {
|
|
1549
|
+
throw new Error("You do not have suitable token UTXOs to perform burn");
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
const totalFungibleAmount = tokenUtxos.reduce(
|
|
1553
|
+
(prev, cur) => prev + (cur.token?.amount || 0),
|
|
1554
|
+
0
|
|
1555
|
+
);
|
|
1556
|
+
const fungibleBurnAmount =
|
|
1557
|
+
burnRequest.amount && burnRequest.amount > 0 ? burnRequest.amount! : 0;
|
|
1558
|
+
const hasNFT = burnRequest.capability || burnRequest.commitment;
|
|
1559
|
+
|
|
1560
|
+
let utxoIds: UtxoI[] = [];
|
|
1561
|
+
let changeSendRequests: TokenSendRequest[];
|
|
1562
|
+
if (hasNFT) {
|
|
1563
|
+
// does not have FT tokens, let us destroy the token completely
|
|
1564
|
+
if (totalFungibleAmount === 0) {
|
|
1565
|
+
changeSendRequests = [];
|
|
1566
|
+
utxoIds.push(tokenUtxos[0]);
|
|
1567
|
+
} else {
|
|
1568
|
+
// if there are FT, reduce their amount
|
|
1569
|
+
const newAmount = totalFungibleAmount - fungibleBurnAmount;
|
|
1570
|
+
const safeNewAmount = Math.max(0, newAmount);
|
|
1571
|
+
changeSendRequests = [
|
|
1572
|
+
new TokenSendRequest({
|
|
1573
|
+
cashaddr: burnRequest.cashaddr || this.cashaddr!,
|
|
1574
|
+
tokenId: burnRequest.tokenId,
|
|
1575
|
+
capability: burnRequest.capability,
|
|
1576
|
+
commitment: burnRequest.commitment,
|
|
1577
|
+
amount: safeNewAmount,
|
|
1578
|
+
value: tokenUtxos[0].satoshis,
|
|
1579
|
+
}),
|
|
1580
|
+
];
|
|
1581
|
+
}
|
|
1582
|
+
} else {
|
|
1583
|
+
// if we are burning last fughible tokens, let us destroy the token completely
|
|
1584
|
+
if (totalFungibleAmount === fungibleBurnAmount) {
|
|
1585
|
+
changeSendRequests = [];
|
|
1586
|
+
utxoIds.push(tokenUtxos[0]);
|
|
1587
|
+
} else {
|
|
1588
|
+
// reduce the FT amount
|
|
1589
|
+
const newAmount = totalFungibleAmount - fungibleBurnAmount;
|
|
1590
|
+
const safeNewAmount = Math.max(0, newAmount);
|
|
1591
|
+
changeSendRequests = [
|
|
1592
|
+
new TokenSendRequest({
|
|
1593
|
+
cashaddr: burnRequest.cashaddr || this.cashaddr!,
|
|
1594
|
+
tokenId: burnRequest.tokenId,
|
|
1595
|
+
amount: safeNewAmount,
|
|
1596
|
+
value: tokenUtxos[0].satoshis,
|
|
1597
|
+
}),
|
|
1598
|
+
];
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
const opReturn = OpReturnData.fromString(message || "");
|
|
1603
|
+
return this.send([opReturn, ...changeSendRequests], {
|
|
1604
|
+
checkTokenQuantities: false,
|
|
1605
|
+
queryBalance: false,
|
|
1606
|
+
utxoIds: utxoIds.length > 0 ? utxoIds : undefined,
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
/**
|
|
1611
|
+
* getTokenUtxos Get unspent token outputs for the wallet
|
|
1612
|
+
* will return utxos only for the specified token if `tokenId` provided
|
|
1613
|
+
* @param {string?} tokenId tokenId (category) to filter utxos by, if not set will return utxos from all tokens
|
|
1614
|
+
* @returns {UtxoI[]} token utxos
|
|
1615
|
+
*/
|
|
1616
|
+
public async getTokenUtxos(tokenId?: string): Promise<UtxoI[]> {
|
|
1617
|
+
const utxos = await this.getAddressUtxos(this.address!);
|
|
1618
|
+
return utxos.filter((val) =>
|
|
1619
|
+
tokenId ? val.token?.tokenId === tokenId : val.token
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
/**
|
|
1624
|
+
* getTokenBalance Gets fungible token balance
|
|
1625
|
+
* for NFT token balance see @ref getNftTokenBalance
|
|
1626
|
+
* @param {string} tokenId tokenId to get balance for
|
|
1627
|
+
* @returns {number} fungible token balance
|
|
1628
|
+
*/
|
|
1629
|
+
public async getTokenBalance(tokenId: string): Promise<number> {
|
|
1630
|
+
const utxos = await this.getAddressUtxos(this.cashaddr!);
|
|
1631
|
+
return sumTokenAmounts(utxos, tokenId);
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* getNftTokenBalance Gets non-fungible token (NFT) balance for a particula tokenId
|
|
1636
|
+
* disregards fungible token balances
|
|
1637
|
+
* for fungible token balance see @ref getTokenBalance
|
|
1638
|
+
* @param {string} tokenId tokenId to get balance for
|
|
1639
|
+
* @returns {number} non-fungible token balance
|
|
1640
|
+
*/
|
|
1641
|
+
public async getNftTokenBalance(tokenId: string): Promise<number> {
|
|
1642
|
+
const utxos = await this.getTokenUtxos(tokenId);
|
|
1643
|
+
return utxos.length;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* getAllTokenBalances Gets all fungible token balances in this wallet
|
|
1648
|
+
* @returns {Object} a map [tokenId => balance] for all tokens in this wallet
|
|
1649
|
+
*/
|
|
1650
|
+
public async getAllTokenBalances(): Promise<Object> {
|
|
1651
|
+
const result = {};
|
|
1652
|
+
const utxos = await this.getTokenUtxos();
|
|
1653
|
+
for (const utxo of utxos) {
|
|
1654
|
+
if (!result[utxo.token!.tokenId]) {
|
|
1655
|
+
result[utxo.token!.tokenId] = 0;
|
|
1656
|
+
}
|
|
1657
|
+
result[utxo.token!.tokenId] += utxo.token!.amount;
|
|
1658
|
+
}
|
|
1659
|
+
return result;
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
/**
|
|
1663
|
+
* getAllNftTokenBalances Gets all non-fungible token (NFT) balances in this wallet
|
|
1664
|
+
* @returns {Object} a map [tokenId => balance] for all NFTs in this wallet
|
|
1665
|
+
*/
|
|
1666
|
+
public async getAllNftTokenBalances(): Promise<Object> {
|
|
1667
|
+
const result = {};
|
|
1668
|
+
const utxos = await this.getTokenUtxos();
|
|
1669
|
+
for (const utxo of utxos) {
|
|
1670
|
+
if (!result[utxo.token!.tokenId]) {
|
|
1671
|
+
result[utxo.token!.tokenId] = 0;
|
|
1672
|
+
}
|
|
1673
|
+
result[utxo.token!.tokenId] += 1;
|
|
1674
|
+
}
|
|
1675
|
+
return result;
|
|
1676
|
+
}
|
|
1677
|
+
//#endregion Cashtokens
|
|
1243
1678
|
}
|
|
1244
1679
|
|
|
1245
1680
|
/**
|