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
|
@@ -1,40 +1,40 @@
|
|
|
1
1
|
//#region Imports
|
|
2
2
|
// Stable
|
|
3
|
-
import { encodeHdPublicKey,
|
|
3
|
+
import { encodeHdPublicKey, secp256k1 } from "@bitauth/libauth";
|
|
4
4
|
// Unstable?
|
|
5
|
-
import { binToHex, CashAddressNetworkPrefix, deriveHdPublicNode, decodePrivateKeyWif, encodePrivateKeyWif, deriveHdPrivateNodeFromSeed, deriveHdPath, generatePrivateKey,
|
|
5
|
+
import { binToHex, CashAddressNetworkPrefix, deriveHdPublicNode, decodePrivateKeyWif, encodePrivateKeyWif, deriveHdPrivateNodeFromSeed, deriveHdPath, generatePrivateKey, } from "@bitauth/libauth";
|
|
6
6
|
import { mnemonicToSeedSync, generateMnemonic } from "bip39";
|
|
7
|
-
import { NetworkType, prefixFromNetworkMap, UnitEnum } from "../enum";
|
|
8
|
-
import { Network } from "../interface";
|
|
9
|
-
import { networkPrefixMap } from "../enum";
|
|
10
|
-
import { BaseWallet } from "./Base";
|
|
11
|
-
import { FeePaidByEnum, WalletTypeEnum } from "./enum";
|
|
12
|
-
import { SendRequest, SendResponse, UtxoItem, UtxoResponse, XPubKey, } from "./model";
|
|
13
|
-
import { buildEncodedTransaction, getSuitableUtxos, getFeeAmount, } from "../transaction/Wif";
|
|
14
|
-
import { asSendRequestObject } from "../util/asSendRequestObject";
|
|
15
|
-
import { balanceFromSatoshi, balanceResponseFromSatoshi, } from "../util/balanceObjectFromSatoshi";
|
|
16
|
-
import { checkWifNetwork } from "../util/checkWifNetwork";
|
|
17
|
-
import { deriveCashaddr } from "../util/deriveCashaddr";
|
|
18
|
-
import { derivePrefix, derivePublicKeyHash } from "../util/derivePublicKeyHash";
|
|
19
|
-
import { checkForEmptySeed } from "../util/checkForEmptySeed";
|
|
20
|
-
import { sanitizeUnit } from "../util/sanitizeUnit";
|
|
21
|
-
import { sumUtxoValue } from "../util/sumUtxoValue";
|
|
22
|
-
import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts";
|
|
23
|
-
import { getRelayFeeCache } from "../network/getRelayFeeCache";
|
|
24
|
-
import { RegTestSlp, RegTestWatchSlp, RegTestWifSlp, Slp, TestNetSlp, TestNetWatchSlp, TestNetWifSlp, WatchSlp, WifSlp, } from "./Slp";
|
|
7
|
+
import { NetworkType, prefixFromNetworkMap, UnitEnum } from "../enum.js";
|
|
8
|
+
import { Network, NFTCapability } from "../interface.js";
|
|
9
|
+
import { networkPrefixMap } from "../enum.js";
|
|
10
|
+
import { BaseWallet } from "./Base.js";
|
|
11
|
+
import { FeePaidByEnum, WalletTypeEnum } from "./enum.js";
|
|
12
|
+
import { OpReturnData, SendRequest, SendResponse, TokenSendRequest, UtxoItem, UtxoResponse, XPubKey, } from "./model.js";
|
|
13
|
+
import { buildEncodedTransaction, getSuitableUtxos, getFeeAmount, } from "../transaction/Wif.js";
|
|
14
|
+
import { asSendRequestObject } from "../util/asSendRequestObject.js";
|
|
15
|
+
import { balanceFromSatoshi, balanceResponseFromSatoshi, } from "../util/balanceObjectFromSatoshi.js";
|
|
16
|
+
import { checkWifNetwork } from "../util/checkWifNetwork.js";
|
|
17
|
+
import { deriveCashaddr, deriveTokenaddr } from "../util/deriveCashaddr.js";
|
|
18
|
+
import { derivePrefix, derivePublicKeyHash, } from "../util/derivePublicKeyHash.js";
|
|
19
|
+
import { checkForEmptySeed } from "../util/checkForEmptySeed.js";
|
|
20
|
+
import { sanitizeUnit } from "../util/sanitizeUnit.js";
|
|
21
|
+
import { sumTokenAmounts, sumUtxoValue } from "../util/sumUtxoValue.js";
|
|
22
|
+
import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
|
|
23
|
+
import { getRelayFeeCache } from "../network/getRelayFeeCache.js";
|
|
24
|
+
import { RegTestSlp, RegTestWatchSlp, RegTestWifSlp, Slp, TestNetSlp, TestNetWatchSlp, TestNetWifSlp, WatchSlp, WifSlp, } from "./Slp.js";
|
|
25
25
|
import axios from "axios";
|
|
26
|
-
import { toCashAddress } from "../util/bchaddr";
|
|
27
|
-
import { RegTestUtil, RegTestWatchUtil, RegTestWifUtil, TestNetUtil, TestNetWatchUtil, TestNetWifUtil, Util, WatchUtil, WifUtil, } from "./Util";
|
|
28
|
-
import { getNetworkProvider } from "../network/index";
|
|
29
|
-
import { generateRandomBytes } from "../util/randomBytes";
|
|
30
|
-
import { SignedMessage } from "../message";
|
|
31
|
-
import { amountInSatoshi } from "../util/amountInSatoshi";
|
|
32
|
-
import { getXPubKey } from "../util/getXPubKey";
|
|
33
|
-
import { DERIVATION_PATHS, DUST_UTXO_THRESHOLD } from "../constant";
|
|
34
|
-
import { getAddressHistory } from "../history/electrumTransformer";
|
|
26
|
+
import { toCashAddress } from "../util/bchaddr.js";
|
|
27
|
+
import { RegTestUtil, RegTestWatchUtil, RegTestWifUtil, TestNetUtil, TestNetWatchUtil, TestNetWifUtil, Util, WatchUtil, WifUtil, } from "./Util.js";
|
|
28
|
+
import { getNetworkProvider } from "../network/index.js";
|
|
29
|
+
import { generateRandomBytes } from "../util/randomBytes.js";
|
|
30
|
+
import { SignedMessage } from "../message/index.js";
|
|
31
|
+
import { amountInSatoshi } from "../util/amountInSatoshi.js";
|
|
32
|
+
import { getXPubKey } from "../util/getXPubKey.js";
|
|
33
|
+
import { DERIVATION_PATHS, DUST_UTXO_THRESHOLD } from "../constant.js";
|
|
34
|
+
import { getAddressHistory } from "../history/electrumTransformer.js";
|
|
35
|
+
import { BCMR } from "./Bcmr.js";
|
|
36
|
+
import { qrAddress } from "../qr/Qr.js";
|
|
35
37
|
//#endregion Imports
|
|
36
|
-
const secp256k1Promise = instantiateSecp256k1();
|
|
37
|
-
const sha256Promise = instantiateSha256();
|
|
38
38
|
/**
|
|
39
39
|
* Class to manage a bitcoin cash wallet.
|
|
40
40
|
*/
|
|
@@ -95,6 +95,22 @@ export class Wallet extends BaseWallet {
|
|
|
95
95
|
getNetworkProvider(network = Network.MAINNET) {
|
|
96
96
|
return getNetworkProvider(network);
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* getTokenDepositAddress - get a cashtoken aware wallet deposit address
|
|
100
|
+
*
|
|
101
|
+
* @returns The cashtoken aware deposit address as a string
|
|
102
|
+
*/
|
|
103
|
+
getTokenDepositAddress() {
|
|
104
|
+
return this.tokenaddr;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* getDepositQr - get an address qrcode, encoded for display on the web
|
|
108
|
+
*
|
|
109
|
+
* @returns The qrcode for the token aware address
|
|
110
|
+
*/
|
|
111
|
+
getTokenDepositQr() {
|
|
112
|
+
return qrAddress(this.getTokenDepositAddress());
|
|
113
|
+
}
|
|
98
114
|
/**
|
|
99
115
|
* explorerUrl Web url to a transaction on a block explorer
|
|
100
116
|
*
|
|
@@ -113,6 +129,7 @@ export class Wallet extends BaseWallet {
|
|
|
113
129
|
getInfo() {
|
|
114
130
|
return {
|
|
115
131
|
cashaddr: this.cashaddr,
|
|
132
|
+
tokenaddr: this.tokenaddr,
|
|
116
133
|
isTestnet: this.isTestnet,
|
|
117
134
|
name: this.name,
|
|
118
135
|
network: this.network,
|
|
@@ -184,6 +201,21 @@ export class Wallet extends BaseWallet {
|
|
|
184
201
|
const networkType = networkPrefixMap[prefix];
|
|
185
202
|
return new this("", networkType, WalletTypeEnum.Watch).watchOnly(address);
|
|
186
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* fromTokenaddr - create a watch-only wallet in the network derived from the address
|
|
206
|
+
*
|
|
207
|
+
* such kind of wallet does not have a private key and is unable to spend any funds
|
|
208
|
+
* however it still allows to use many utility functions such as getting and watching balance, etc.
|
|
209
|
+
*
|
|
210
|
+
* @param address token aware cashaddress of a wallet
|
|
211
|
+
*
|
|
212
|
+
* @returns instantiated wallet
|
|
213
|
+
*/
|
|
214
|
+
static async fromTokenaddr(address) {
|
|
215
|
+
const prefix = derivePrefix(address);
|
|
216
|
+
const networkType = networkPrefixMap[prefix];
|
|
217
|
+
return new this("", networkType, WalletTypeEnum.Watch).watchOnly(address);
|
|
218
|
+
}
|
|
187
219
|
/**
|
|
188
220
|
* fromSlpaddr - create an SLP aware watch-only wallet in the network derived from the address
|
|
189
221
|
*
|
|
@@ -231,12 +263,11 @@ export class Wallet extends BaseWallet {
|
|
|
231
263
|
checkForEmptySeed(seed);
|
|
232
264
|
let network = this.isTestnet ? "testnet" : "mainnet";
|
|
233
265
|
this.parentXPubKey = await getXPubKey(seed, this.parentDerivationPath, network);
|
|
234
|
-
|
|
235
|
-
let hdNode = deriveHdPrivateNodeFromSeed(crypto, seed);
|
|
266
|
+
let hdNode = deriveHdPrivateNodeFromSeed(seed);
|
|
236
267
|
if (!hdNode.valid) {
|
|
237
268
|
throw Error("Invalid private key derived from mnemonic seed");
|
|
238
269
|
}
|
|
239
|
-
let zerothChild = deriveHdPath(
|
|
270
|
+
let zerothChild = deriveHdPath(hdNode, this.derivationPath);
|
|
240
271
|
if (typeof zerothChild === "string") {
|
|
241
272
|
throw Error(zerothChild);
|
|
242
273
|
}
|
|
@@ -261,12 +292,11 @@ export class Wallet extends BaseWallet {
|
|
|
261
292
|
// Initialize wallet from a mnemonic phrase
|
|
262
293
|
async fromSeed(mnemonic, derivationPath) {
|
|
263
294
|
this.mnemonic = mnemonic;
|
|
264
|
-
const crypto = await instantiateBIP32Crypto();
|
|
265
295
|
if (this.mnemonic.length == 0)
|
|
266
296
|
throw Error("refusing to create wallet from empty mnemonic");
|
|
267
297
|
let seed = mnemonicToSeedSync(this.mnemonic);
|
|
268
298
|
checkForEmptySeed(seed);
|
|
269
|
-
let hdNode = deriveHdPrivateNodeFromSeed(
|
|
299
|
+
let hdNode = deriveHdPrivateNodeFromSeed(seed);
|
|
270
300
|
if (!hdNode.valid) {
|
|
271
301
|
throw Error("Invalid private key derived from mnemonic seed");
|
|
272
302
|
}
|
|
@@ -278,7 +308,7 @@ export class Wallet extends BaseWallet {
|
|
|
278
308
|
this.parentDerivationPath = path.slice(0, -2).join("/");
|
|
279
309
|
}
|
|
280
310
|
}
|
|
281
|
-
let zerothChild = deriveHdPath(
|
|
311
|
+
let zerothChild = deriveHdPath(hdNode, this.derivationPath);
|
|
282
312
|
if (typeof zerothChild === "string") {
|
|
283
313
|
throw Error(zerothChild);
|
|
284
314
|
}
|
|
@@ -291,12 +321,11 @@ export class Wallet extends BaseWallet {
|
|
|
291
321
|
}
|
|
292
322
|
// Get common xpub paths from zerothChild privateKey
|
|
293
323
|
async deriveHdPaths(hdPaths) {
|
|
294
|
-
const crypto = await instantiateBIP32Crypto();
|
|
295
324
|
if (!this.mnemonic)
|
|
296
325
|
throw Error("refusing to create wallet from empty mnemonic");
|
|
297
326
|
let seed = mnemonicToSeedSync(this.mnemonic);
|
|
298
327
|
checkForEmptySeed(seed);
|
|
299
|
-
let hdNode = deriveHdPrivateNodeFromSeed(
|
|
328
|
+
let hdNode = deriveHdPrivateNodeFromSeed(seed);
|
|
300
329
|
if (!hdNode.valid) {
|
|
301
330
|
throw Error("Invalid private key derived from mnemonic seed");
|
|
302
331
|
}
|
|
@@ -305,15 +334,15 @@ export class Wallet extends BaseWallet {
|
|
|
305
334
|
if (path === "m") {
|
|
306
335
|
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");
|
|
307
336
|
}
|
|
308
|
-
let childNode = deriveHdPath(
|
|
337
|
+
let childNode = deriveHdPath(hdNode, path);
|
|
309
338
|
if (typeof childNode === "string") {
|
|
310
339
|
throw Error(childNode);
|
|
311
340
|
}
|
|
312
|
-
let node = deriveHdPublicNode(
|
|
341
|
+
let node = deriveHdPublicNode(childNode);
|
|
313
342
|
if (typeof node === "string") {
|
|
314
343
|
throw Error(node);
|
|
315
344
|
}
|
|
316
|
-
let xPubKey = encodeHdPublicKey(
|
|
345
|
+
let xPubKey = encodeHdPublicKey({
|
|
317
346
|
network: this.network,
|
|
318
347
|
node: node,
|
|
319
348
|
});
|
|
@@ -348,13 +377,13 @@ export class Wallet extends BaseWallet {
|
|
|
348
377
|
this.cashaddr = `${addressPrefix}:${addressBase}`;
|
|
349
378
|
this.address = this.cashaddr;
|
|
350
379
|
this.publicKeyHash = derivePublicKeyHash(this.cashaddr);
|
|
380
|
+
this.tokenaddr = deriveTokenaddr(this.publicKeyHash, this.networkPrefix);
|
|
351
381
|
return this;
|
|
352
382
|
}
|
|
353
383
|
// Initialize wallet from Wallet Import Format
|
|
354
384
|
async fromWIF(secret) {
|
|
355
385
|
checkWifNetwork(secret, this.network);
|
|
356
|
-
|
|
357
|
-
let wifResult = decodePrivateKeyWif(sha256, secret);
|
|
386
|
+
let wifResult = decodePrivateKeyWif(secret);
|
|
358
387
|
if (typeof wifResult === "string") {
|
|
359
388
|
throw Error(wifResult);
|
|
360
389
|
}
|
|
@@ -410,8 +439,8 @@ export class Wallet extends BaseWallet {
|
|
|
410
439
|
//#region Funds
|
|
411
440
|
//
|
|
412
441
|
async getAddressUtxos(address) {
|
|
413
|
-
if (!
|
|
414
|
-
|
|
442
|
+
if (!address) {
|
|
443
|
+
address = this.cashaddr;
|
|
415
444
|
}
|
|
416
445
|
if (this._slpAware) {
|
|
417
446
|
const [bchUtxos, slpOutpoints] = await Promise.all([
|
|
@@ -455,18 +484,20 @@ export class Wallet extends BaseWallet {
|
|
|
455
484
|
}
|
|
456
485
|
// Gets balance by summing value in all utxos in stats
|
|
457
486
|
async getBalanceFromUtxos() {
|
|
458
|
-
const utxos = await this.getAddressUtxos(this.cashaddr);
|
|
459
|
-
return
|
|
487
|
+
const utxos = (await this.getAddressUtxos(this.cashaddr)).filter((val) => val.token === undefined);
|
|
488
|
+
return sumUtxoValue(utxos);
|
|
460
489
|
}
|
|
461
490
|
// Gets balance from fulcrum
|
|
462
491
|
async getBalanceFromProvider() {
|
|
463
|
-
//
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
else {
|
|
468
|
-
|
|
469
|
-
}
|
|
492
|
+
// Fulcrum reports balance of all utxos, including tokens, which is undesirable
|
|
493
|
+
// // TODO not sure why getting the balance from a provider doesn't work
|
|
494
|
+
// if (this._slpAware || this._slpSemiAware) {
|
|
495
|
+
// return await this.getBalanceFromUtxos();
|
|
496
|
+
// } else {
|
|
497
|
+
// return await this.provider!.getBalance(this.cashaddr!);
|
|
498
|
+
// }
|
|
499
|
+
// FIXME
|
|
500
|
+
return this.getBalanceFromUtxos();
|
|
470
501
|
}
|
|
471
502
|
// // waiting for any transaction hash of this wallet
|
|
472
503
|
// // commented out until fulcrum supports new method https://github.com/cculianu/Fulcrum/pull/89
|
|
@@ -528,7 +559,34 @@ export class Wallet extends BaseWallet {
|
|
|
528
559
|
});
|
|
529
560
|
});
|
|
530
561
|
}
|
|
531
|
-
|
|
562
|
+
// sets up a callback to be called upon wallet's token balance change
|
|
563
|
+
// can be cancelled by calling the function returned from this one
|
|
564
|
+
watchTokenBalance(tokenId, callback) {
|
|
565
|
+
let previous = undefined;
|
|
566
|
+
return this.provider.watchAddressStatus(this.getDepositAddress(), async (_status) => {
|
|
567
|
+
const balance = await this.getTokenBalance(tokenId);
|
|
568
|
+
if (previous != balance) {
|
|
569
|
+
callback(balance);
|
|
570
|
+
}
|
|
571
|
+
previous = balance;
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
// waits for address token balance to be greater than or equal to the target amount
|
|
575
|
+
// this call halts the execution
|
|
576
|
+
async waitForTokenBalance(tokenId, amount) {
|
|
577
|
+
return new Promise(async (resolve) => {
|
|
578
|
+
const watchCancel = this.watchTokenBalance(tokenId, async (balance) => {
|
|
579
|
+
if (balance >= amount) {
|
|
580
|
+
await watchCancel();
|
|
581
|
+
resolve(balance);
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
async getTokenInfo(tokenId) {
|
|
587
|
+
return BCMR.getTokenInfo(tokenId);
|
|
588
|
+
}
|
|
589
|
+
async _getMaxAmountToSend(params = {
|
|
532
590
|
outputCount: 1,
|
|
533
591
|
options: {},
|
|
534
592
|
}) {
|
|
@@ -557,7 +615,7 @@ export class Wallet extends BaseWallet {
|
|
|
557
615
|
utxos = params.options.utxoIds.map((utxoId) => UtxoItem.fromId(utxoId).asElectrum());
|
|
558
616
|
}
|
|
559
617
|
else {
|
|
560
|
-
utxos = await this.getAddressUtxos(this.cashaddr);
|
|
618
|
+
utxos = (await this.getAddressUtxos(this.cashaddr)).filter((utxo) => !utxo.token);
|
|
561
619
|
}
|
|
562
620
|
// Get current height to assure recently mined coins are not spent.
|
|
563
621
|
const bestHeight = await this.provider.getBlockHeight();
|
|
@@ -570,7 +628,7 @@ export class Wallet extends BaseWallet {
|
|
|
570
628
|
const sendRequests = Array(params.outputCount)
|
|
571
629
|
.fill(0)
|
|
572
630
|
.map(() => sendRequest);
|
|
573
|
-
const fundingUtxos = await getSuitableUtxos(utxos, undefined, bestHeight, feePaidBy);
|
|
631
|
+
const fundingUtxos = await getSuitableUtxos(utxos, undefined, bestHeight, feePaidBy, sendRequests);
|
|
574
632
|
const relayFeePerByteInSatoshi = await getRelayFeeCache(this.provider);
|
|
575
633
|
const fee = await getFeeAmount({
|
|
576
634
|
utxos: fundingUtxos,
|
|
@@ -580,11 +638,18 @@ export class Wallet extends BaseWallet {
|
|
|
580
638
|
slpOutputs: [],
|
|
581
639
|
feePaidBy: feePaidBy,
|
|
582
640
|
});
|
|
583
|
-
const spendableAmount =
|
|
641
|
+
const spendableAmount = sumUtxoValue(fundingUtxos);
|
|
584
642
|
let result = spendableAmount - fee;
|
|
585
643
|
if (result < 0) {
|
|
586
644
|
result = 0;
|
|
587
645
|
}
|
|
646
|
+
return { value: result, utxos: fundingUtxos };
|
|
647
|
+
}
|
|
648
|
+
async getMaxAmountToSend(params = {
|
|
649
|
+
outputCount: 1,
|
|
650
|
+
options: {},
|
|
651
|
+
}) {
|
|
652
|
+
const { value: result } = await this._getMaxAmountToSend(params);
|
|
588
653
|
return await balanceResponseFromSatoshi(result);
|
|
589
654
|
}
|
|
590
655
|
/**
|
|
@@ -596,7 +661,7 @@ export class Wallet extends BaseWallet {
|
|
|
596
661
|
*
|
|
597
662
|
*/
|
|
598
663
|
async send(requests, options) {
|
|
599
|
-
let encodedTransaction = await this.encodeTransaction(requests, undefined, options);
|
|
664
|
+
let { encodedTransaction, tokenIds } = await this.encodeTransaction(requests, undefined, options);
|
|
600
665
|
const awaitTransactionPropagation = !options ||
|
|
601
666
|
options.awaitTransactionPropagation === undefined ||
|
|
602
667
|
options.awaitTransactionPropagation;
|
|
@@ -608,6 +673,7 @@ export class Wallet extends BaseWallet {
|
|
|
608
673
|
resp.balance = (await this.getBalance());
|
|
609
674
|
}
|
|
610
675
|
resp.explorerUrl = this.explorerUrl(resp.txId);
|
|
676
|
+
resp.tokenIds = tokenIds;
|
|
611
677
|
return resp;
|
|
612
678
|
}
|
|
613
679
|
/**
|
|
@@ -638,19 +704,20 @@ export class Wallet extends BaseWallet {
|
|
|
638
704
|
* @returns the transaction id sent to the network
|
|
639
705
|
*/
|
|
640
706
|
async sendMaxRaw(cashaddr, options) {
|
|
641
|
-
let maxSpendableAmount = await this.
|
|
707
|
+
let { value: maxSpendableAmount, utxos } = await this._getMaxAmountToSend({
|
|
642
708
|
outputCount: 1,
|
|
643
709
|
options: options,
|
|
644
710
|
});
|
|
645
|
-
if (
|
|
646
|
-
|
|
711
|
+
if (!options) {
|
|
712
|
+
options = {};
|
|
647
713
|
}
|
|
714
|
+
options.utxoIds = utxos;
|
|
648
715
|
let sendRequest = new SendRequest({
|
|
649
716
|
cashaddr: cashaddr,
|
|
650
|
-
value: maxSpendableAmount
|
|
717
|
+
value: maxSpendableAmount,
|
|
651
718
|
unit: "sat",
|
|
652
719
|
});
|
|
653
|
-
const encodedTransaction = await this.encodeTransaction([sendRequest], true, options);
|
|
720
|
+
const { encodedTransaction } = await this.encodeTransaction([sendRequest], true, options);
|
|
654
721
|
const awaitTransactionPropagation = !options ||
|
|
655
722
|
options.awaitTransactionPropagation === undefined ||
|
|
656
723
|
options.awaitTransactionPropagation;
|
|
@@ -691,14 +758,53 @@ export class Wallet extends BaseWallet {
|
|
|
691
758
|
else {
|
|
692
759
|
changeAddress = "";
|
|
693
760
|
}
|
|
761
|
+
let checkTokenQuantities = true;
|
|
762
|
+
if (options && options.checkTokenQuantities === false) {
|
|
763
|
+
checkTokenQuantities = false;
|
|
764
|
+
}
|
|
694
765
|
// get inputs from options or query all inputs
|
|
695
766
|
let utxos;
|
|
696
767
|
if (options && options.utxoIds) {
|
|
697
|
-
utxos = options.utxoIds.map((utxoId) =>
|
|
768
|
+
utxos = options.utxoIds.map((utxoId) => typeof utxoId === "string"
|
|
769
|
+
? UtxoItem.fromId(utxoId).asElectrum()
|
|
770
|
+
: utxoId);
|
|
698
771
|
}
|
|
699
772
|
else {
|
|
700
773
|
utxos = await this.getAddressUtxos(this.cashaddr);
|
|
701
774
|
}
|
|
775
|
+
const addTokenChangeOutputs = (inputs, outputs) => {
|
|
776
|
+
// allow for implicit token burn if the total amount sent is less than user had
|
|
777
|
+
// allow for token genesis, creating more tokens than we had before (0)
|
|
778
|
+
if (!checkTokenQuantities) {
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
const allTokenInputs = inputs.filter((val) => val.token);
|
|
782
|
+
const allTokenOutputs = outputs.filter((val) => val instanceof TokenSendRequest);
|
|
783
|
+
const tokenIds = allTokenOutputs
|
|
784
|
+
.map((val) => val.tokenId)
|
|
785
|
+
.filter((val, idx, arr) => arr.indexOf(val) === idx);
|
|
786
|
+
for (let tokenId of tokenIds) {
|
|
787
|
+
const tokenInputs = allTokenInputs.filter((val) => val.token?.tokenId === tokenId);
|
|
788
|
+
const inputAmountSum = tokenInputs.reduce((prev, cur) => prev + cur.token.amount, 0);
|
|
789
|
+
const tokenOutputs = allTokenOutputs.filter((val) => val.tokenId === tokenId);
|
|
790
|
+
const outputAmountSum = tokenOutputs.reduce((prev, cur) => prev + cur.amount, 0);
|
|
791
|
+
const change = inputAmountSum - outputAmountSum;
|
|
792
|
+
if (change < 0) {
|
|
793
|
+
throw new Error("Not enough token amount to send");
|
|
794
|
+
}
|
|
795
|
+
if (change > 0) {
|
|
796
|
+
outputs.push(new TokenSendRequest({
|
|
797
|
+
cashaddr: changeAddress || this.cashaddr,
|
|
798
|
+
amount: change,
|
|
799
|
+
tokenId: tokenId,
|
|
800
|
+
commitment: tokenOutputs[0].commitment,
|
|
801
|
+
capability: tokenOutputs[0].capability,
|
|
802
|
+
value: tokenOutputs[0].value,
|
|
803
|
+
}));
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
addTokenChangeOutputs(utxos, sendRequests);
|
|
702
808
|
const bestHeight = await this.provider.getBlockHeight();
|
|
703
809
|
const spendAmount = await sumSendRequestAmounts(sendRequests);
|
|
704
810
|
if (utxos.length === 0) {
|
|
@@ -716,7 +822,7 @@ export class Wallet extends BaseWallet {
|
|
|
716
822
|
slpOutputs: [],
|
|
717
823
|
feePaidBy: feePaidBy,
|
|
718
824
|
});
|
|
719
|
-
const fundingUtxos = await getSuitableUtxos(utxos, BigInt(spendAmount) + BigInt(feeEstimate), bestHeight, feePaidBy);
|
|
825
|
+
const fundingUtxos = await getSuitableUtxos(utxos, BigInt(spendAmount) + BigInt(feeEstimate), bestHeight, feePaidBy, sendRequests);
|
|
720
826
|
if (fundingUtxos.length === 0) {
|
|
721
827
|
throw Error("The available inputs couldn't satisfy the request with fees");
|
|
722
828
|
}
|
|
@@ -729,7 +835,15 @@ export class Wallet extends BaseWallet {
|
|
|
729
835
|
feePaidBy: feePaidBy,
|
|
730
836
|
});
|
|
731
837
|
const encodedTransaction = await buildEncodedTransaction(fundingUtxos, sendRequests, this.privateKey, fee, discardChange, [], feePaidBy, changeAddress);
|
|
732
|
-
|
|
838
|
+
const tokenIds = [
|
|
839
|
+
...fundingUtxos
|
|
840
|
+
.filter((val) => val.token?.tokenId)
|
|
841
|
+
.map((val) => val.token.tokenId),
|
|
842
|
+
...sendRequests
|
|
843
|
+
.filter((val) => val instanceof TokenSendRequest)
|
|
844
|
+
.map((val) => val.tokenId),
|
|
845
|
+
].filter((value, index, array) => array.indexOf(value) === index);
|
|
846
|
+
return { encodedTransaction, tokenIds: tokenIds };
|
|
733
847
|
}
|
|
734
848
|
// Submit a raw transaction
|
|
735
849
|
async submitTransaction(transaction, awaitPropagation = true) {
|
|
@@ -830,14 +944,21 @@ export class Wallet extends BaseWallet {
|
|
|
830
944
|
//#endregion Funds
|
|
831
945
|
//#region Private implementation details
|
|
832
946
|
async deriveInfo() {
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
947
|
+
const publicKey = secp256k1.derivePublicKeyUncompressed(this.privateKey);
|
|
948
|
+
if (typeof publicKey === "string") {
|
|
949
|
+
throw new Error(publicKey);
|
|
950
|
+
}
|
|
951
|
+
this.publicKey = publicKey;
|
|
952
|
+
const publicKeyCompressed = secp256k1.derivePublicKeyCompressed(this.privateKey);
|
|
953
|
+
if (typeof publicKeyCompressed === "string") {
|
|
954
|
+
throw new Error(publicKeyCompressed);
|
|
955
|
+
}
|
|
956
|
+
this.publicKeyCompressed = publicKeyCompressed;
|
|
837
957
|
const networkType = this.network === NetworkType.Regtest ? NetworkType.Testnet : this.network;
|
|
838
|
-
this.privateKeyWif = encodePrivateKeyWif(
|
|
958
|
+
this.privateKeyWif = encodePrivateKeyWif(this.privateKey, networkType);
|
|
839
959
|
checkWifNetwork(this.privateKeyWif, this.network);
|
|
840
|
-
this.cashaddr =
|
|
960
|
+
this.cashaddr = deriveCashaddr(this.privateKey, this.networkPrefix);
|
|
961
|
+
this.tokenaddr = deriveTokenaddr(this.privateKey, this.networkPrefix);
|
|
841
962
|
this.address = this.cashaddr;
|
|
842
963
|
this.publicKeyHash = derivePublicKeyHash(this.cashaddr);
|
|
843
964
|
return this;
|
|
@@ -852,6 +973,217 @@ export class Wallet extends BaseWallet {
|
|
|
852
973
|
async verify(message, sig, publicKey) {
|
|
853
974
|
return await Wallet.signedMessage.verify(message, sig, this.cashaddr, publicKey);
|
|
854
975
|
}
|
|
976
|
+
//#endregion Signing
|
|
977
|
+
//#region Cashtokens
|
|
978
|
+
/**
|
|
979
|
+
* Create new cashtoken, both funglible and/or non-fungible (NFT)
|
|
980
|
+
* Refer to spec https://github.com/bitjson/cashtokens
|
|
981
|
+
* @param {number} genesisRequest.amount amount of *fungible* tokens to create
|
|
982
|
+
* @param {NFTCapability?} genesisRequest.capability capability of new NFT
|
|
983
|
+
* @param {string?} genesisRequest.commitment NFT commitment message
|
|
984
|
+
* @param {string?} genesisRequest.cashaddr cash address to send the created token UTXO to; if undefined will default to your address
|
|
985
|
+
* @param {number?} genesisRequest.value satoshi value to send alongside with tokens; if undefined will default to 1000 satoshi
|
|
986
|
+
*/
|
|
987
|
+
async tokenGenesis(genesisRequest) {
|
|
988
|
+
return this.send(new TokenSendRequest({
|
|
989
|
+
cashaddr: genesisRequest.cashaddr || this.cashaddr,
|
|
990
|
+
amount: genesisRequest.amount,
|
|
991
|
+
value: genesisRequest.value,
|
|
992
|
+
capability: genesisRequest.capability,
|
|
993
|
+
commitment: genesisRequest.commitment,
|
|
994
|
+
tokenId: "",
|
|
995
|
+
}), {
|
|
996
|
+
checkTokenQuantities: false,
|
|
997
|
+
queryBalance: false,
|
|
998
|
+
});
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Mint new NFT cashtokens using an existing minting token
|
|
1002
|
+
* Refer to spec https://github.com/bitjson/cashtokens
|
|
1003
|
+
* @param {string} tokenId tokenId of an NFT to mint
|
|
1004
|
+
* @param {TokenMintRequest | TokenMintRequest[]} mintRequests mint requests with new token properties and recipients
|
|
1005
|
+
* @param {NFTCapability?} mintRequest.capability capability of new NFT
|
|
1006
|
+
* @param {string?} mintRequest.commitment NFT commitment message
|
|
1007
|
+
* @param {string?} mintRequest.cashaddr cash address to send the created token UTXO to; if undefined will default to your address
|
|
1008
|
+
* @param {number?} mintRequest.value satoshi value to send alongside with tokens; if undefined will default to 1000 satoshi
|
|
1009
|
+
* @param {boolean?} deductTokenAmount if minting token contains fungible amount, deduct from it by amount of minted tokens
|
|
1010
|
+
*/
|
|
1011
|
+
async tokenMint(tokenId, mintRequests, deductTokenAmount = false) {
|
|
1012
|
+
if (!Array.isArray(mintRequests)) {
|
|
1013
|
+
mintRequests = [mintRequests];
|
|
1014
|
+
}
|
|
1015
|
+
const utxos = await this.getAddressUtxos(this.cashaddr);
|
|
1016
|
+
const nftUtxos = utxos.filter((val) => val.token?.tokenId === tokenId &&
|
|
1017
|
+
val.token?.capability != NFTCapability.none);
|
|
1018
|
+
if (!nftUtxos.length) {
|
|
1019
|
+
throw new Error("You do not have any token UTXOs with minting capability for specified tokenId");
|
|
1020
|
+
}
|
|
1021
|
+
const newAmount = deductTokenAmount && nftUtxos[0].token.amount > 0
|
|
1022
|
+
? nftUtxos[0].token.amount - mintRequests.length
|
|
1023
|
+
: nftUtxos[0].token.amount;
|
|
1024
|
+
const safeNewAmount = Math.max(0, newAmount);
|
|
1025
|
+
const mintingInput = new TokenSendRequest({
|
|
1026
|
+
cashaddr: this.cashaddr,
|
|
1027
|
+
tokenId: tokenId,
|
|
1028
|
+
capability: nftUtxos[0].token.capability,
|
|
1029
|
+
commitment: nftUtxos[0].token.commitment,
|
|
1030
|
+
amount: safeNewAmount,
|
|
1031
|
+
value: nftUtxos[0].satoshis,
|
|
1032
|
+
});
|
|
1033
|
+
return this.send([
|
|
1034
|
+
mintingInput,
|
|
1035
|
+
...mintRequests.map((val) => new TokenSendRequest({
|
|
1036
|
+
cashaddr: val.cashaddr || this.cashaddr,
|
|
1037
|
+
amount: 0,
|
|
1038
|
+
tokenId: tokenId,
|
|
1039
|
+
value: val.value,
|
|
1040
|
+
capability: val.capability,
|
|
1041
|
+
commitment: val.commitment,
|
|
1042
|
+
})),
|
|
1043
|
+
], {
|
|
1044
|
+
checkTokenQuantities: false,
|
|
1045
|
+
queryBalance: false,
|
|
1046
|
+
});
|
|
1047
|
+
}
|
|
1048
|
+
/**
|
|
1049
|
+
* Perform an explicit token burning by spending a token utxo to an OP_RETURN
|
|
1050
|
+
*
|
|
1051
|
+
* Behaves differently for fungible and non-fungible tokens:
|
|
1052
|
+
* * NFTs are always "destroyed"
|
|
1053
|
+
* * FTs' amount is reduced by the amount specified, if 0 FT amount is left and no NFT present, the token is "destroyed"
|
|
1054
|
+
*
|
|
1055
|
+
* Refer to spec https://github.com/bitjson/cashtokens
|
|
1056
|
+
* @param {string} burnRequest.tokenId tokenId of a token to burn
|
|
1057
|
+
* @param {NFTCapability} burnRequest.capability capability of the NFT token to select, optional
|
|
1058
|
+
* @param {string?} burnRequest.commitment commitment of the NFT token to select, optional
|
|
1059
|
+
* @param {number?} burnRequest.amount amount of fungible tokens to burn, optional
|
|
1060
|
+
* @param {string?} burnRequest.cashaddr address to return token and satoshi change to
|
|
1061
|
+
* @param {string?} message optional message to include in OP_RETURN
|
|
1062
|
+
*/
|
|
1063
|
+
async tokenBurn(burnRequest, message) {
|
|
1064
|
+
const utxos = await this.getAddressUtxos(this.cashaddr);
|
|
1065
|
+
const tokenUtxos = utxos.filter((val) => val.token?.tokenId === burnRequest.tokenId &&
|
|
1066
|
+
val.token?.capability === burnRequest.capability &&
|
|
1067
|
+
val.token?.commitment === burnRequest.commitment &&
|
|
1068
|
+
val.token?.capability === burnRequest.capability);
|
|
1069
|
+
if (!tokenUtxos.length) {
|
|
1070
|
+
throw new Error("You do not have suitable token UTXOs to perform burn");
|
|
1071
|
+
}
|
|
1072
|
+
const totalFungibleAmount = tokenUtxos.reduce((prev, cur) => prev + (cur.token?.amount || 0), 0);
|
|
1073
|
+
const fungibleBurnAmount = burnRequest.amount && burnRequest.amount > 0 ? burnRequest.amount : 0;
|
|
1074
|
+
const hasNFT = burnRequest.capability || burnRequest.commitment;
|
|
1075
|
+
let utxoIds = [];
|
|
1076
|
+
let changeSendRequests;
|
|
1077
|
+
if (hasNFT) {
|
|
1078
|
+
// does not have FT tokens, let us destroy the token completely
|
|
1079
|
+
if (totalFungibleAmount === 0) {
|
|
1080
|
+
changeSendRequests = [];
|
|
1081
|
+
utxoIds.push(tokenUtxos[0]);
|
|
1082
|
+
}
|
|
1083
|
+
else {
|
|
1084
|
+
// if there are FT, reduce their amount
|
|
1085
|
+
const newAmount = totalFungibleAmount - fungibleBurnAmount;
|
|
1086
|
+
const safeNewAmount = Math.max(0, newAmount);
|
|
1087
|
+
changeSendRequests = [
|
|
1088
|
+
new TokenSendRequest({
|
|
1089
|
+
cashaddr: burnRequest.cashaddr || this.cashaddr,
|
|
1090
|
+
tokenId: burnRequest.tokenId,
|
|
1091
|
+
capability: burnRequest.capability,
|
|
1092
|
+
commitment: burnRequest.commitment,
|
|
1093
|
+
amount: safeNewAmount,
|
|
1094
|
+
value: tokenUtxos[0].satoshis,
|
|
1095
|
+
}),
|
|
1096
|
+
];
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
else {
|
|
1100
|
+
// if we are burning last fughible tokens, let us destroy the token completely
|
|
1101
|
+
if (totalFungibleAmount === fungibleBurnAmount) {
|
|
1102
|
+
changeSendRequests = [];
|
|
1103
|
+
utxoIds.push(tokenUtxos[0]);
|
|
1104
|
+
}
|
|
1105
|
+
else {
|
|
1106
|
+
// reduce the FT amount
|
|
1107
|
+
const newAmount = totalFungibleAmount - fungibleBurnAmount;
|
|
1108
|
+
const safeNewAmount = Math.max(0, newAmount);
|
|
1109
|
+
changeSendRequests = [
|
|
1110
|
+
new TokenSendRequest({
|
|
1111
|
+
cashaddr: burnRequest.cashaddr || this.cashaddr,
|
|
1112
|
+
tokenId: burnRequest.tokenId,
|
|
1113
|
+
amount: safeNewAmount,
|
|
1114
|
+
value: tokenUtxos[0].satoshis,
|
|
1115
|
+
}),
|
|
1116
|
+
];
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
const opReturn = OpReturnData.fromString(message || "");
|
|
1120
|
+
return this.send([opReturn, ...changeSendRequests], {
|
|
1121
|
+
checkTokenQuantities: false,
|
|
1122
|
+
queryBalance: false,
|
|
1123
|
+
utxoIds: utxoIds.length > 0 ? utxoIds : undefined,
|
|
1124
|
+
});
|
|
1125
|
+
}
|
|
1126
|
+
/**
|
|
1127
|
+
* getTokenUtxos Get unspent token outputs for the wallet
|
|
1128
|
+
* will return utxos only for the specified token if `tokenId` provided
|
|
1129
|
+
* @param {string?} tokenId tokenId (category) to filter utxos by, if not set will return utxos from all tokens
|
|
1130
|
+
* @returns {UtxoI[]} token utxos
|
|
1131
|
+
*/
|
|
1132
|
+
async getTokenUtxos(tokenId) {
|
|
1133
|
+
const utxos = await this.getAddressUtxos(this.address);
|
|
1134
|
+
return utxos.filter((val) => tokenId ? val.token?.tokenId === tokenId : val.token);
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* getTokenBalance Gets fungible token balance
|
|
1138
|
+
* for NFT token balance see @ref getNftTokenBalance
|
|
1139
|
+
* @param {string} tokenId tokenId to get balance for
|
|
1140
|
+
* @returns {number} fungible token balance
|
|
1141
|
+
*/
|
|
1142
|
+
async getTokenBalance(tokenId) {
|
|
1143
|
+
const utxos = await this.getAddressUtxos(this.cashaddr);
|
|
1144
|
+
return sumTokenAmounts(utxos, tokenId);
|
|
1145
|
+
}
|
|
1146
|
+
/**
|
|
1147
|
+
* getNftTokenBalance Gets non-fungible token (NFT) balance for a particula tokenId
|
|
1148
|
+
* disregards fungible token balances
|
|
1149
|
+
* for fungible token balance see @ref getTokenBalance
|
|
1150
|
+
* @param {string} tokenId tokenId to get balance for
|
|
1151
|
+
* @returns {number} non-fungible token balance
|
|
1152
|
+
*/
|
|
1153
|
+
async getNftTokenBalance(tokenId) {
|
|
1154
|
+
const utxos = await this.getTokenUtxos(tokenId);
|
|
1155
|
+
return utxos.length;
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* getAllTokenBalances Gets all fungible token balances in this wallet
|
|
1159
|
+
* @returns {Object} a map [tokenId => balance] for all tokens in this wallet
|
|
1160
|
+
*/
|
|
1161
|
+
async getAllTokenBalances() {
|
|
1162
|
+
const result = {};
|
|
1163
|
+
const utxos = await this.getTokenUtxos();
|
|
1164
|
+
for (const utxo of utxos) {
|
|
1165
|
+
if (!result[utxo.token.tokenId]) {
|
|
1166
|
+
result[utxo.token.tokenId] = 0;
|
|
1167
|
+
}
|
|
1168
|
+
result[utxo.token.tokenId] += utxo.token.amount;
|
|
1169
|
+
}
|
|
1170
|
+
return result;
|
|
1171
|
+
}
|
|
1172
|
+
/**
|
|
1173
|
+
* getAllNftTokenBalances Gets all non-fungible token (NFT) balances in this wallet
|
|
1174
|
+
* @returns {Object} a map [tokenId => balance] for all NFTs in this wallet
|
|
1175
|
+
*/
|
|
1176
|
+
async getAllNftTokenBalances() {
|
|
1177
|
+
const result = {};
|
|
1178
|
+
const utxos = await this.getTokenUtxos();
|
|
1179
|
+
for (const utxo of utxos) {
|
|
1180
|
+
if (!result[utxo.token.tokenId]) {
|
|
1181
|
+
result[utxo.token.tokenId] = 0;
|
|
1182
|
+
}
|
|
1183
|
+
result[utxo.token.tokenId] += 1;
|
|
1184
|
+
}
|
|
1185
|
+
return result;
|
|
1186
|
+
}
|
|
855
1187
|
}
|
|
856
1188
|
Wallet.signedMessage = new SignedMessage();
|
|
857
1189
|
/**
|