mainnet-js 0.5.9 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +9 -1
- package/dist/mainnet-1.0.0-rc.1.js +2928 -0
- package/dist/module/chain.d.ts +1 -0
- package/dist/module/chain.d.ts.map +1 -0
- package/dist/module/cli.d.ts +1 -0
- package/dist/module/cli.d.ts.map +1 -0
- package/dist/module/cli.js +2 -2
- package/dist/module/cli.js.map +1 -1
- package/dist/module/constant.d.ts +1 -0
- package/dist/module/constant.d.ts.map +1 -0
- package/dist/module/db/ExchangeRateProvider.d.ts +2 -1
- package/dist/module/db/ExchangeRateProvider.d.ts.map +1 -0
- package/dist/module/db/IndexedDBProvider.d.ts +3 -2
- package/dist/module/db/IndexedDBProvider.d.ts.map +1 -0
- package/dist/module/db/SqlProvider.d.ts +7 -8
- package/dist/module/db/SqlProvider.d.ts.map +1 -0
- package/dist/module/db/SqlProvider.js +10 -8
- package/dist/module/db/SqlProvider.js.map +1 -1
- package/dist/module/db/StorageProvider.d.ts +2 -1
- package/dist/module/db/StorageProvider.d.ts.map +1 -0
- package/dist/module/db/getStorageProvider.d.ts +3 -0
- package/dist/module/db/getStorageProvider.d.ts.map +1 -0
- package/dist/module/db/getStorageProvider.js +19 -0
- package/dist/module/db/getStorageProvider.js.map +1 -0
- package/dist/module/db/index.d.ts +4 -3
- package/dist/module/db/index.d.ts.map +1 -0
- package/dist/module/db/index.js +2 -2
- package/dist/module/db/index.js.map +1 -1
- package/dist/module/db/interface.d.ts +1 -0
- package/dist/module/db/interface.d.ts.map +1 -0
- package/dist/module/db/util.d.ts +2 -3
- package/dist/module/db/util.d.ts.map +1 -0
- package/dist/module/db/util.js +0 -17
- package/dist/module/db/util.js.map +1 -1
- package/dist/module/enum.d.ts +1 -0
- package/dist/module/enum.d.ts.map +1 -0
- package/dist/module/history/electrumTransformer.d.ts +3 -2
- package/dist/module/history/electrumTransformer.d.ts.map +1 -0
- package/dist/module/history/electrumTransformer.js +11 -11
- package/dist/module/history/electrumTransformer.js.map +1 -1
- package/dist/module/history/interface.d.ts +2 -1
- package/dist/module/history/interface.d.ts.map +1 -0
- package/dist/module/index.d.ts +26 -21
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +25 -17
- package/dist/module/index.js.map +1 -1
- package/dist/module/interface.d.ts +14 -0
- package/dist/module/interface.d.ts.map +1 -0
- package/dist/module/interface.js +5 -0
- package/dist/module/interface.js.map +1 -1
- package/dist/module/message/index.d.ts +3 -2
- package/dist/module/message/index.d.ts.map +1 -0
- package/dist/module/message/index.js +2 -2
- package/dist/module/message/index.js.map +1 -1
- package/dist/module/message/interface.d.ts +1 -0
- package/dist/module/message/interface.d.ts.map +1 -0
- package/dist/module/message/signed.d.ts +2 -1
- package/dist/module/message/signed.d.ts.map +1 -0
- package/dist/module/message/signed.js +10 -4
- package/dist/module/message/signed.js.map +1 -1
- package/dist/module/mine/index.d.ts +2 -1
- package/dist/module/mine/index.d.ts.map +1 -0
- package/dist/module/mine/index.js +1 -1
- package/dist/module/mine/index.js.map +1 -1
- package/dist/module/mine/mine.d.ts +1 -0
- package/dist/module/mine/mine.d.ts.map +1 -0
- package/dist/module/mine/mine.js +3 -3
- package/dist/module/mine/mine.js.map +1 -1
- package/dist/module/network/Connection.d.ts +3 -2
- package/dist/module/network/Connection.d.ts.map +1 -0
- package/dist/module/network/Connection.js +3 -3
- package/dist/module/network/Connection.js.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.d.ts +8 -5
- package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -0
- package/dist/module/network/ElectrumNetworkProvider.js +59 -13
- package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
- package/dist/module/network/NetworkProvider.d.ts +2 -1
- package/dist/module/network/NetworkProvider.d.ts.map +1 -0
- package/dist/module/network/configuration.d.ts +8 -10
- package/dist/module/network/configuration.d.ts.map +1 -0
- package/dist/module/network/configuration.js +29 -17
- package/dist/module/network/configuration.js.map +1 -1
- package/dist/module/network/constant.d.ts +1 -0
- package/dist/module/network/constant.d.ts.map +1 -0
- package/dist/module/network/constant.js +8 -4
- package/dist/module/network/constant.js.map +1 -1
- package/dist/module/network/default.d.ts +4 -3
- package/dist/module/network/default.d.ts.map +1 -0
- package/dist/module/network/default.js +7 -7
- package/dist/module/network/default.js.map +1 -1
- package/dist/module/network/getRelayFeeCache.d.ts +2 -1
- package/dist/module/network/getRelayFeeCache.d.ts.map +1 -0
- package/dist/module/network/getRelayFeeCache.js +2 -2
- package/dist/module/network/getRelayFeeCache.js.map +1 -1
- package/dist/module/network/index.d.ts +3 -2
- package/dist/module/network/index.d.ts.map +1 -0
- package/dist/module/network/index.js +2 -2
- package/dist/module/network/index.js.map +1 -1
- package/dist/module/network/interface.d.ts +1 -0
- package/dist/module/network/interface.d.ts.map +1 -0
- package/dist/module/network/util.d.ts +2 -1
- package/dist/module/network/util.d.ts.map +1 -0
- package/dist/module/qr/Qr.d.ts +2 -1
- package/dist/module/qr/Qr.d.ts.map +1 -0
- package/dist/module/qr/Qr.js +2 -2
- package/dist/module/qr/Qr.js.map +1 -1
- package/dist/module/qr/interface.d.ts +1 -0
- package/dist/module/qr/interface.d.ts.map +1 -0
- package/dist/module/rate/ExchangeRate.d.ts +1 -0
- package/dist/module/rate/ExchangeRate.d.ts.map +1 -0
- package/dist/module/rate/ExchangeRate.js +5 -5
- package/dist/module/rate/ExchangeRate.js.map +1 -1
- package/dist/module/slp/GsppProvider.d.ts +4 -3
- package/dist/module/slp/GsppProvider.d.ts.map +1 -0
- package/dist/module/slp/GsppProvider.js +7 -7
- package/dist/module/slp/GsppProvider.js.map +1 -1
- package/dist/module/slp/SlpDbProvider.d.ts +4 -3
- package/dist/module/slp/SlpDbProvider.d.ts.map +1 -0
- package/dist/module/slp/SlpDbProvider.js +8 -8
- package/dist/module/slp/SlpDbProvider.js.map +1 -1
- package/dist/module/slp/SlpDbTemplates.d.ts +1 -0
- package/dist/module/slp/SlpDbTemplates.d.ts.map +1 -0
- package/dist/module/slp/SlpLibAuth.d.ts +7 -14
- package/dist/module/slp/SlpLibAuth.d.ts.map +1 -0
- package/dist/module/slp/SlpLibAuth.js +48 -39
- package/dist/module/slp/SlpLibAuth.js.map +1 -1
- package/dist/module/slp/SlpProvider.d.ts +2 -1
- package/dist/module/slp/SlpProvider.d.ts.map +1 -0
- package/dist/module/slp/SlpProvider.js.map +1 -1
- package/dist/module/slp/index.d.ts +5 -4
- package/dist/module/slp/index.d.ts.map +1 -0
- package/dist/module/slp/index.js +3 -3
- package/dist/module/slp/index.js.map +1 -1
- package/dist/module/slp/interface.d.ts +2 -1
- package/dist/module/slp/interface.d.ts.map +1 -0
- package/dist/module/test/axios.d.ts +3 -0
- package/dist/module/test/axios.d.ts.map +1 -0
- package/dist/module/test/axios.js +35 -0
- package/dist/module/test/axios.js.map +1 -0
- package/dist/module/test/expect.d.ts +6 -1
- package/dist/module/test/expect.d.ts.map +1 -0
- package/dist/module/test/expect.js +22 -1
- package/dist/module/test/expect.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +19 -16
- package/dist/module/transaction/Wif.d.ts.map +1 -0
- package/dist/module/transaction/Wif.js +152 -55
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/transaction/allocateFee.d.ts +5 -4
- package/dist/module/transaction/allocateFee.d.ts.map +1 -0
- package/dist/module/transaction/allocateFee.js +11 -8
- package/dist/module/transaction/allocateFee.js.map +1 -1
- package/dist/module/util/amountInSatoshi.d.ts +1 -0
- package/dist/module/util/amountInSatoshi.d.ts.map +1 -0
- package/dist/module/util/amountInSatoshi.js +4 -4
- package/dist/module/util/amountInSatoshi.js.map +1 -1
- package/dist/module/util/asSendRequestObject.d.ts +3 -2
- package/dist/module/util/asSendRequestObject.d.ts.map +1 -0
- package/dist/module/util/asSendRequestObject.js +6 -3
- package/dist/module/util/asSendRequestObject.js.map +1 -1
- package/dist/module/util/balanceObjectFromSatoshi.d.ts +1 -0
- package/dist/module/util/balanceObjectFromSatoshi.d.ts.map +1 -0
- package/dist/module/util/balanceObjectFromSatoshi.js +5 -5
- package/dist/module/util/balanceObjectFromSatoshi.js.map +1 -1
- package/dist/module/util/base64.d.ts +2 -1
- package/dist/module/util/base64.d.ts.map +1 -0
- package/dist/module/util/base64.js +5 -25
- package/dist/module/util/base64.js.map +1 -1
- package/dist/module/util/bchaddr.d.ts +1 -0
- package/dist/module/util/bchaddr.d.ts.map +1 -0
- package/dist/module/util/browserNotSupported.d.ts +1 -0
- package/dist/module/util/browserNotSupported.d.ts.map +1 -0
- package/dist/module/util/browserNotSupported.js +1 -1
- package/dist/module/util/browserNotSupported.js.map +1 -1
- package/dist/module/util/checkForEmptySeed.d.ts +1 -0
- package/dist/module/util/checkForEmptySeed.d.ts.map +1 -0
- package/dist/module/util/checkWifNetwork.d.ts +2 -1
- package/dist/module/util/checkWifNetwork.d.ts.map +1 -0
- package/dist/module/util/checkWifNetwork.js +1 -1
- package/dist/module/util/checkWifNetwork.js.map +1 -1
- package/dist/module/util/convert.d.ts +1 -0
- package/dist/module/util/convert.d.ts.map +1 -0
- package/dist/module/util/convert.js +2 -2
- package/dist/module/util/convert.js.map +1 -1
- package/dist/module/util/delay.d.ts +1 -0
- package/dist/module/util/delay.d.ts.map +1 -0
- package/dist/module/util/deriveCashaddr.d.ts +6 -1
- package/dist/module/util/deriveCashaddr.d.ts.map +1 -0
- package/dist/module/util/deriveCashaddr.js +85 -6
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/util/deriveLockscript.d.ts +1 -0
- package/dist/module/util/deriveLockscript.d.ts.map +1 -0
- package/dist/module/util/deriveNetwork.d.ts +1 -0
- package/dist/module/util/deriveNetwork.d.ts.map +1 -0
- package/dist/module/util/deriveNetwork.js +2 -2
- package/dist/module/util/deriveNetwork.js.map +1 -1
- package/dist/module/util/derivePublicKeyHash.d.ts +3 -1
- package/dist/module/util/derivePublicKeyHash.d.ts.map +1 -0
- package/dist/module/util/derivePublicKeyHash.js +1 -1
- package/dist/module/util/derivePublicKeyHash.js.map +1 -1
- package/dist/module/util/eventsource.d.ts +1 -0
- package/dist/module/util/eventsource.d.ts.map +1 -0
- package/dist/module/util/eventsource.js +3 -2
- package/dist/module/util/eventsource.js.map +1 -1
- package/dist/module/util/floor.d.ts +1 -0
- package/dist/module/util/floor.d.ts.map +1 -0
- package/dist/module/util/getAddrsByXpubKey.d.ts +8 -8
- package/dist/module/util/getAddrsByXpubKey.d.ts.map +1 -0
- package/dist/module/util/getAddrsByXpubKey.js +17 -21
- package/dist/module/util/getAddrsByXpubKey.js.map +1 -1
- package/dist/module/util/getRuntimePlatform.d.ts +1 -0
- package/dist/module/util/getRuntimePlatform.d.ts.map +1 -0
- package/dist/module/util/getUsdRate.d.ts +1 -0
- package/dist/module/util/getUsdRate.d.ts.map +1 -0
- package/dist/module/util/getUsdRate.js +1 -1
- package/dist/module/util/getUsdRate.js.map +1 -1
- package/dist/module/util/getXPubKey.d.ts +2 -1
- package/dist/module/util/getXPubKey.d.ts.map +1 -0
- package/dist/module/util/getXPubKey.js +6 -7
- package/dist/module/util/getXPubKey.js.map +1 -1
- package/dist/module/util/hash160.d.ts +2 -1
- package/dist/module/util/hash160.d.ts.map +1 -0
- package/dist/module/util/hash160.js +2 -4
- package/dist/module/util/hash160.js.map +1 -1
- package/dist/module/util/index.d.ts +21 -20
- package/dist/module/util/index.d.ts.map +1 -0
- package/dist/module/util/index.js +20 -20
- package/dist/module/util/index.js.map +1 -1
- package/dist/module/util/randomBytes.d.ts +3 -1
- package/dist/module/util/randomBytes.d.ts.map +1 -0
- package/dist/module/util/randomBytes.js +2 -3
- package/dist/module/util/randomBytes.js.map +1 -1
- package/dist/module/util/randomInt.d.ts +1 -0
- package/dist/module/util/randomInt.d.ts.map +1 -0
- package/dist/module/util/randomValues.d.ts +1 -0
- package/dist/module/util/randomValues.d.ts.map +1 -0
- package/dist/module/util/randomValues.js +7 -7
- package/dist/module/util/randomValues.js.map +1 -1
- package/dist/module/util/sanitizeAddress.d.ts +1 -0
- package/dist/module/util/sanitizeAddress.d.ts.map +1 -0
- package/dist/module/util/sanitizeAddress.js +1 -1
- package/dist/module/util/sanitizeAddress.js.map +1 -1
- package/dist/module/util/sanitizeUnit.d.ts +2 -1
- package/dist/module/util/sanitizeUnit.d.ts.map +1 -0
- package/dist/module/util/satoshiToAmount.d.ts +1 -0
- package/dist/module/util/satoshiToAmount.d.ts.map +1 -0
- package/dist/module/util/satoshiToAmount.js +4 -4
- package/dist/module/util/satoshiToAmount.js.map +1 -1
- package/dist/module/util/sumSendRequestAmounts.d.ts +3 -2
- package/dist/module/util/sumSendRequestAmounts.d.ts.map +1 -0
- package/dist/module/util/sumSendRequestAmounts.js +5 -2
- package/dist/module/util/sumSendRequestAmounts.js.map +1 -1
- package/dist/module/util/sumUtxoValue.d.ts +4 -2
- package/dist/module/util/sumUtxoValue.d.ts.map +1 -0
- package/dist/module/util/sumUtxoValue.js +17 -3
- package/dist/module/util/sumUtxoValue.js.map +1 -1
- package/dist/module/util/transaction.d.ts +2 -0
- package/dist/module/util/transaction.d.ts.map +1 -0
- package/dist/module/util/transaction.js +7 -0
- package/dist/module/util/transaction.js.map +1 -0
- package/dist/module/wallet/Base.d.ts +8 -7
- package/dist/module/wallet/Base.d.ts.map +1 -0
- package/dist/module/wallet/Base.js +7 -7
- package/dist/module/wallet/Base.js.map +1 -1
- package/dist/module/wallet/Bcmr.d.ts +88 -0
- package/dist/module/wallet/Bcmr.d.ts.map +1 -0
- package/dist/module/wallet/Bcmr.js +281 -0
- package/dist/module/wallet/Bcmr.js.map +1 -0
- package/dist/module/wallet/Slp.d.ts +6 -5
- package/dist/module/wallet/Slp.d.ts.map +1 -0
- package/dist/module/wallet/Slp.js +15 -15
- package/dist/module/wallet/Slp.js.map +1 -1
- package/dist/module/wallet/Util.d.ts +3 -2
- package/dist/module/wallet/Util.d.ts.map +1 -0
- package/dist/module/wallet/Util.js +9 -14
- package/dist/module/wallet/Util.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +124 -20
- package/dist/module/wallet/Wif.d.ts.map +1 -0
- package/dist/module/wallet/Wif.js +406 -74
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/bcmr-v1.schema.d.ts +623 -0
- package/dist/module/wallet/bcmr-v1.schema.d.ts.map +1 -0
- package/dist/module/wallet/bcmr-v1.schema.js +2 -0
- package/dist/module/wallet/bcmr-v1.schema.js.map +1 -0
- package/dist/module/wallet/createWallet.d.ts +3 -2
- package/dist/module/wallet/createWallet.d.ts.map +1 -0
- package/dist/module/wallet/createWallet.js +3 -3
- package/dist/module/wallet/createWallet.js.map +1 -1
- package/dist/module/wallet/enum.d.ts +1 -0
- package/dist/module/wallet/enum.d.ts.map +1 -0
- package/dist/module/wallet/interface.d.ts +10 -6
- package/dist/module/wallet/interface.d.ts.map +1 -0
- package/dist/module/wallet/model.d.ts +81 -5
- package/dist/module/wallet/model.d.ts.map +1 -0
- package/dist/module/wallet/model.js +102 -17
- package/dist/module/wallet/model.js.map +1 -1
- package/dist/module/webhook/Webhook.d.ts +3 -2
- package/dist/module/webhook/Webhook.d.ts.map +1 -0
- package/dist/module/webhook/Webhook.js +4 -1
- package/dist/module/webhook/Webhook.js.map +1 -1
- package/dist/module/webhook/WebhookBch.d.ts +4 -3
- package/dist/module/webhook/WebhookBch.d.ts.map +1 -0
- package/dist/module/webhook/WebhookBch.js +4 -4
- package/dist/module/webhook/WebhookBch.js.map +1 -1
- package/dist/module/webhook/WebhookSlp.d.ts +5 -4
- package/dist/module/webhook/WebhookSlp.d.ts.map +1 -0
- package/dist/module/webhook/WebhookSlp.js +4 -4
- package/dist/module/webhook/WebhookSlp.js.map +1 -1
- package/dist/module/webhook/WebhookWorker.d.ts +3 -2
- package/dist/module/webhook/WebhookWorker.d.ts.map +1 -0
- package/dist/module/webhook/WebhookWorker.js +1 -1
- package/dist/module/webhook/WebhookWorker.js.map +1 -1
- package/dist/module/webhook/index.d.ts +6 -5
- package/dist/module/webhook/index.d.ts.map +1 -0
- package/dist/module/webhook/index.js +5 -5
- package/dist/module/webhook/index.js.map +1 -1
- package/dist/module/webhook/interface.d.ts +1 -0
- package/dist/module/webhook/interface.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/polyfill/{bip39.browser.js → bip39.browser.cjs} +1 -0
- package/polyfill/{util.js → util.cjs} +0 -0
- package/src/Wallet.test.headless.js +6 -6
- package/src/cli.ts +3 -3
- package/src/db/ExchangeRateProvider.ts +1 -1
- package/src/db/IndexedDBProvider.test.ts +0 -1
- package/src/db/IndexedDBProvider.ts +2 -2
- package/src/db/SqlProvider.ts +14 -12
- package/src/db/StorageProvider.ts +1 -1
- package/src/db/getStorageProvider.ts +20 -0
- package/src/db/index.ts +3 -3
- package/src/db/util.ts +1 -20
- package/src/history/electrumTransformer.ts +13 -14
- package/src/history/interface.ts +1 -1
- package/src/index.ts +29 -21
- package/src/interface.ts +15 -0
- package/src/message/index.ts +2 -2
- package/src/message/signed.test.ts +4 -4
- package/src/message/signed.ts +23 -6
- package/src/mine/index.ts +1 -1
- package/src/mine/mine.ts +3 -3
- package/src/network/Connection.ts +5 -5
- package/src/network/ElectrumNetworkProvider.ts +85 -20
- package/src/network/NetworkProvider.ts +1 -1
- package/src/network/configuration.test.ts +33 -8
- package/src/network/configuration.ts +33 -18
- package/src/network/constant.ts +9 -4
- package/src/network/default.ts +13 -10
- package/src/network/getRelayFeeCache.ts +3 -3
- package/src/network/index.ts +6 -2
- package/src/network/util.ts +1 -1
- package/src/qr/Qr.ts +3 -3
- package/src/rate/ExchangeRate.ts +14 -15
- package/src/slp/GsppProvider.test.ts +2 -2
- package/src/slp/GsppProvider.ts +11 -8
- package/src/slp/SlpDbProvider.test.ts +1 -1
- package/src/slp/SlpDbProvider.ts +12 -9
- package/src/slp/SlpLibAuth.test.ts +1 -1
- package/src/slp/SlpLibAuth.ts +52 -42
- package/src/slp/SlpProvider.ts +6 -1
- package/src/slp/index.ts +4 -4
- package/src/slp/interface.ts +1 -1
- package/src/test/axios.ts +47 -0
- package/src/test/expect.ts +27 -2
- package/src/transaction/Wif.ts +203 -77
- package/src/transaction/allocateFee.ts +32 -14
- package/src/util/amountInSatoshi.ts +4 -4
- package/src/util/asSendRequestObject.ts +42 -30
- package/src/util/balanceObjectFromSatoshi.ts +5 -5
- package/src/util/base64.ts +5 -24
- package/src/util/browserNotSupported.ts +1 -1
- package/src/util/checkWifNetwork.ts +1 -1
- package/src/util/convert.ts +2 -2
- package/src/util/deriveCashaddr.test.ts +43 -0
- package/src/util/deriveCashaddr.ts +123 -7
- package/src/util/deriveNetwork.ts +2 -2
- package/src/util/derivePublicKeyHash.test.ts +3 -0
- package/src/util/derivePublicKeyHash.ts +18 -5
- package/src/util/eventsource.ts +4 -2
- package/src/util/getAddrsByXpubKey.test.ts +5 -5
- package/src/util/getAddrsByXpubKey.ts +23 -28
- package/src/util/getUsdRate.ts +1 -1
- package/src/util/getXPubKey.ts +5 -7
- package/src/util/hash160.test.ts +2 -2
- package/src/util/hash160.ts +2 -4
- package/src/util/index.ts +26 -20
- package/src/util/randomBytes.ts +2 -3
- package/src/util/randomValues.ts +8 -8
- package/src/util/sanitizeAddress.ts +1 -1
- package/src/util/sanitizeUnit.ts +1 -1
- package/src/util/satoshiToAmount.ts +4 -4
- package/src/util/sumSendRequestAmounts.ts +10 -4
- package/src/util/sumUtxoValue.ts +19 -7
- package/src/util/transaction.ts +10 -0
- package/src/wallet/Base.ts +11 -11
- package/src/wallet/Bcmr.test.headless.js +353 -0
- package/src/wallet/Bcmr.test.ts +610 -0
- package/src/wallet/Bcmr.ts +390 -0
- package/src/wallet/Cashtokens.test.headless.js +467 -0
- package/src/wallet/Cashtokens.test.ts +475 -0
- package/src/wallet/Slp.test.headless.js +6 -8
- package/src/wallet/Slp.test.ts +2 -2
- package/src/wallet/Slp.ts +26 -22
- package/src/wallet/Util.ts +9 -20
- package/src/wallet/Wif.test.ts +20 -21
- package/src/wallet/Wif.ts +534 -99
- package/src/wallet/bcmr-v1.schema.ts +639 -0
- package/src/wallet/createWallet.test.ts +1 -0
- package/src/wallet/createWallet.ts +4 -4
- package/src/wallet/interface.ts +9 -6
- package/src/wallet/model.ts +190 -19
- package/src/webhook/Webhook.ts +7 -3
- package/src/webhook/WebhookBch.ts +7 -7
- package/src/webhook/WebhookSlp.test.ts +2 -2
- package/src/webhook/WebhookSlp.ts +6 -6
- package/src/webhook/WebhookWorker.ts +2 -2
- package/src/webhook/index.ts +5 -5
- package/tsconfig.browser.json +0 -3
- package/tsconfig.json +17 -5
- package/{webpack.config.js → webpack.config.cjs} +46 -14
- package/dist/main/chain.d.ts +0 -3
- package/dist/main/chain.js +0 -7
- package/dist/main/chain.js.map +0 -1
- package/dist/main/cli.d.ts +0 -1
- package/dist/main/cli.js +0 -35
- package/dist/main/cli.js.map +0 -1
- package/dist/main/constant.d.ts +0 -5
- package/dist/main/constant.js +0 -27
- package/dist/main/constant.js.map +0 -1
- package/dist/main/db/ExchangeRateProvider.d.ts +0 -11
- package/dist/main/db/ExchangeRateProvider.js +0 -47
- package/dist/main/db/ExchangeRateProvider.js.map +0 -1
- package/dist/main/db/IndexedDBProvider.d.ts +0 -15
- package/dist/main/db/IndexedDBProvider.js +0 -86
- package/dist/main/db/IndexedDBProvider.js.map +0 -1
- package/dist/main/db/SqlProvider.d.ts +0 -41
- package/dist/main/db/SqlProvider.js +0 -217
- package/dist/main/db/SqlProvider.js.map +0 -1
- package/dist/main/db/StorageProvider.d.ts +0 -52
- package/dist/main/db/StorageProvider.js +0 -3
- package/dist/main/db/StorageProvider.js.map +0 -1
- package/dist/main/db/index.d.ts +0 -3
- package/dist/main/db/index.js +0 -11
- package/dist/main/db/index.js.map +0 -1
- package/dist/main/db/interface.d.ts +0 -22
- package/dist/main/db/interface.js +0 -3
- package/dist/main/db/interface.js.map +0 -1
- package/dist/main/db/util.d.ts +0 -5
- package/dist/main/db/util.js +0 -53
- package/dist/main/db/util.js.map +0 -1
- package/dist/main/enum.d.ts +0 -33
- package/dist/main/enum.js +0 -39
- package/dist/main/enum.js.map +0 -1
- package/dist/main/history/electrumTransformer.d.ts +0 -4
- package/dist/main/history/electrumTransformer.js +0 -216
- package/dist/main/history/electrumTransformer.js.map +0 -1
- package/dist/main/history/interface.d.ts +0 -16
- package/dist/main/history/interface.js +0 -3
- package/dist/main/history/interface.js.map +0 -1
- package/dist/main/index.d.ts +0 -24
- package/dist/main/index.js +0 -62
- package/dist/main/index.js.map +0 -1
- package/dist/main/interface.d.ts +0 -31
- package/dist/main/interface.js +0 -12
- package/dist/main/interface.js.map +0 -1
- package/dist/main/message/index.d.ts +0 -2
- package/dist/main/message/index.js +0 -15
- package/dist/main/message/index.js.map +0 -1
- package/dist/main/message/interface.d.ts +0 -29
- package/dist/main/message/interface.js +0 -6
- package/dist/main/message/interface.js.map +0 -1
- package/dist/main/message/signed.d.ts +0 -33
- package/dist/main/message/signed.js +0 -141
- package/dist/main/message/signed.js.map +0 -1
- package/dist/main/mine/index.d.ts +0 -1
- package/dist/main/mine/index.js +0 -14
- package/dist/main/mine/index.js.map +0 -1
- package/dist/main/mine/mine.d.ts +0 -13
- package/dist/main/mine/mine.js +0 -37
- package/dist/main/mine/mine.js.map +0 -1
- package/dist/main/network/Connection.d.ts +0 -14
- package/dist/main/network/Connection.js +0 -71
- package/dist/main/network/Connection.js.map +0 -1
- package/dist/main/network/ElectrumNetworkProvider.d.ts +0 -49
- package/dist/main/network/ElectrumNetworkProvider.js +0 -338
- package/dist/main/network/ElectrumNetworkProvider.js.map +0 -1
- package/dist/main/network/NetworkProvider.d.ts +0 -107
- package/dist/main/network/NetworkProvider.js +0 -3
- package/dist/main/network/NetworkProvider.js.map +0 -1
- package/dist/main/network/configuration.d.ts +0 -12
- package/dist/main/network/configuration.js +0 -79
- package/dist/main/network/configuration.js.map +0 -1
- package/dist/main/network/constant.d.ts +0 -35
- package/dist/main/network/constant.js +0 -55
- package/dist/main/network/constant.js.map +0 -1
- package/dist/main/network/default.d.ts +0 -7
- package/dist/main/network/default.js +0 -107
- package/dist/main/network/default.js.map +0 -1
- package/dist/main/network/getRelayFeeCache.d.ts +0 -2
- package/dist/main/network/getRelayFeeCache.js +0 -27
- package/dist/main/network/getRelayFeeCache.js.map +0 -1
- package/dist/main/network/index.d.ts +0 -2
- package/dist/main/network/index.js +0 -10
- package/dist/main/network/index.js.map +0 -1
- package/dist/main/network/interface.d.ts +0 -60
- package/dist/main/network/interface.js +0 -3
- package/dist/main/network/interface.js.map +0 -1
- package/dist/main/network/util.d.ts +0 -2
- package/dist/main/network/util.js +0 -32
- package/dist/main/network/util.js.map +0 -1
- package/dist/main/qr/Qr.d.ts +0 -8
- package/dist/main/qr/Qr.js +0 -26
- package/dist/main/qr/Qr.js.map +0 -1
- package/dist/main/qr/interface.d.ts +0 -5
- package/dist/main/qr/interface.js +0 -3
- package/dist/main/qr/interface.js.map +0 -1
- package/dist/main/rate/ExchangeRate.d.ts +0 -19
- package/dist/main/rate/ExchangeRate.js +0 -147
- package/dist/main/rate/ExchangeRate.js.map +0 -1
- package/dist/main/slp/GsppProvider.d.ts +0 -54
- package/dist/main/slp/GsppProvider.js +0 -214
- package/dist/main/slp/GsppProvider.js.map +0 -1
- package/dist/main/slp/SlpDbProvider.d.ts +0 -51
- package/dist/main/slp/SlpDbProvider.js +0 -182
- package/dist/main/slp/SlpDbProvider.js.map +0 -1
- package/dist/main/slp/SlpDbTemplates.d.ts +0 -312
- package/dist/main/slp/SlpDbTemplates.js +0 -387
- package/dist/main/slp/SlpDbTemplates.js.map +0 -1
- package/dist/main/slp/SlpLibAuth.d.ts +0 -217
- package/dist/main/slp/SlpLibAuth.js +0 -452
- package/dist/main/slp/SlpLibAuth.js.map +0 -1
- package/dist/main/slp/SlpProvider.d.ts +0 -23
- package/dist/main/slp/SlpProvider.js +0 -39
- package/dist/main/slp/SlpProvider.js.map +0 -1
- package/dist/main/slp/index.d.ts +0 -5
- package/dist/main/slp/index.js +0 -24
- package/dist/main/slp/index.js.map +0 -1
- package/dist/main/slp/interface.d.ts +0 -113
- package/dist/main/slp/interface.js +0 -10
- package/dist/main/slp/interface.js.map +0 -1
- package/dist/main/test/expect.d.ts +0 -7
- package/dist/main/test/expect.js +0 -31
- package/dist/main/test/expect.js.map +0 -1
- package/dist/main/transaction/Wif.d.ts +0 -42
- package/dist/main/transaction/Wif.js +0 -214
- package/dist/main/transaction/Wif.js.map +0 -1
- package/dist/main/transaction/allocateFee.d.ts +0 -7
- package/dist/main/transaction/allocateFee.js +0 -118
- package/dist/main/transaction/allocateFee.js.map +0 -1
- package/dist/main/util/amountInSatoshi.d.ts +0 -9
- package/dist/main/util/amountInSatoshi.js +0 -38
- package/dist/main/util/amountInSatoshi.js.map +0 -1
- package/dist/main/util/asSendRequestObject.d.ts +0 -2
- package/dist/main/util/asSendRequestObject.js +0 -57
- package/dist/main/util/asSendRequestObject.js.map +0 -1
- package/dist/main/util/balanceObjectFromSatoshi.d.ts +0 -8
- package/dist/main/util/balanceObjectFromSatoshi.js +0 -62
- package/dist/main/util/balanceObjectFromSatoshi.js.map +0 -1
- package/dist/main/util/base64.d.ts +0 -2
- package/dist/main/util/base64.js +0 -36
- package/dist/main/util/base64.js.map +0 -1
- package/dist/main/util/bchaddr.d.ts +0 -1
- package/dist/main/util/bchaddr.js +0 -24
- package/dist/main/util/bchaddr.js.map +0 -1
- package/dist/main/util/browserNotSupported.d.ts +0 -1
- package/dist/main/util/browserNotSupported.js +0 -11
- package/dist/main/util/browserNotSupported.js.map +0 -1
- package/dist/main/util/checkForEmptySeed.d.ts +0 -2
- package/dist/main/util/checkForEmptySeed.js +0 -12
- package/dist/main/util/checkForEmptySeed.js.map +0 -1
- package/dist/main/util/checkWifNetwork.d.ts +0 -2
- package/dist/main/util/checkWifNetwork.js +0 -16
- package/dist/main/util/checkWifNetwork.js.map +0 -1
- package/dist/main/util/convert.d.ts +0 -15
- package/dist/main/util/convert.js +0 -24
- package/dist/main/util/convert.js.map +0 -1
- package/dist/main/util/delay.d.ts +0 -1
- package/dist/main/util/delay.js +0 -8
- package/dist/main/util/delay.js.map +0 -1
- package/dist/main/util/deriveCashaddr.d.ts +0 -2
- package/dist/main/util/deriveCashaddr.js +0 -13
- package/dist/main/util/deriveCashaddr.js.map +0 -1
- package/dist/main/util/deriveLockscript.d.ts +0 -8
- package/dist/main/util/deriveLockscript.js +0 -19
- package/dist/main/util/deriveLockscript.js.map +0 -1
- package/dist/main/util/deriveNetwork.d.ts +0 -1
- package/dist/main/util/deriveNetwork.js +0 -23
- package/dist/main/util/deriveNetwork.js.map +0 -1
- package/dist/main/util/derivePublicKeyHash.d.ts +0 -16
- package/dist/main/util/derivePublicKeyHash.js +0 -49
- package/dist/main/util/derivePublicKeyHash.js.map +0 -1
- package/dist/main/util/eventsource.d.ts +0 -2
- package/dist/main/util/eventsource.js +0 -12
- package/dist/main/util/eventsource.js.map +0 -1
- package/dist/main/util/floor.d.ts +0 -1
- package/dist/main/util/floor.js +0 -9
- package/dist/main/util/floor.js.map +0 -1
- package/dist/main/util/getAddrsByXpubKey.d.ts +0 -22
- package/dist/main/util/getAddrsByXpubKey.js +0 -79
- package/dist/main/util/getAddrsByXpubKey.js.map +0 -1
- package/dist/main/util/getRuntimePlatform.d.ts +0 -6
- package/dist/main/util/getRuntimePlatform.js +0 -34
- package/dist/main/util/getRuntimePlatform.js.map +0 -1
- package/dist/main/util/getUsdRate.d.ts +0 -1
- package/dist/main/util/getUsdRate.js +0 -9
- package/dist/main/util/getUsdRate.js.map +0 -1
- package/dist/main/util/getXPubKey.d.ts +0 -1
- package/dist/main/util/getXPubKey.js +0 -26
- package/dist/main/util/getXPubKey.js.map +0 -1
- package/dist/main/util/hash160.d.ts +0 -8
- package/dist/main/util/hash160.js +0 -18
- package/dist/main/util/hash160.js.map +0 -1
- package/dist/main/util/index.d.ts +0 -21
- package/dist/main/util/index.js +0 -72
- package/dist/main/util/index.js.map +0 -1
- package/dist/main/util/randomBytes.d.ts +0 -1
- package/dist/main/util/randomBytes.js +0 -18
- package/dist/main/util/randomBytes.js.map +0 -1
- package/dist/main/util/randomInt.d.ts +0 -1
- package/dist/main/util/randomInt.js +0 -9
- package/dist/main/util/randomInt.js.map +0 -1
- package/dist/main/util/randomValues.d.ts +0 -1
- package/dist/main/util/randomValues.js +0 -15
- package/dist/main/util/randomValues.js.map +0 -1
- package/dist/main/util/sanitizeAddress.d.ts +0 -1
- package/dist/main/util/sanitizeAddress.js +0 -15
- package/dist/main/util/sanitizeAddress.js.map +0 -1
- package/dist/main/util/sanitizeUnit.d.ts +0 -2
- package/dist/main/util/sanitizeUnit.js +0 -13
- package/dist/main/util/sanitizeUnit.js.map +0 -1
- package/dist/main/util/satoshiToAmount.d.ts +0 -9
- package/dist/main/util/satoshiToAmount.js +0 -41
- package/dist/main/util/satoshiToAmount.js.map +0 -1
- package/dist/main/util/sumSendRequestAmounts.d.ts +0 -2
- package/dist/main/util/sumSendRequestAmounts.js +0 -31
- package/dist/main/util/sumSendRequestAmounts.js.map +0 -1
- package/dist/main/util/sumUtxoValue.d.ts +0 -2
- package/dist/main/util/sumUtxoValue.js +0 -17
- package/dist/main/util/sumUtxoValue.js.map +0 -1
- package/dist/main/wallet/Base.d.ts +0 -202
- package/dist/main/wallet/Base.js +0 -438
- package/dist/main/wallet/Base.js.map +0 -1
- package/dist/main/wallet/Slp.d.ts +0 -430
- package/dist/main/wallet/Slp.js +0 -775
- package/dist/main/wallet/Slp.js.map +0 -1
- package/dist/main/wallet/Util.d.ts +0 -69
- package/dist/main/wallet/Util.js +0 -182
- package/dist/main/wallet/Util.js.map +0 -1
- package/dist/main/wallet/Wif.d.ts +0 -255
- package/dist/main/wallet/Wif.js +0 -1067
- package/dist/main/wallet/Wif.js.map +0 -1
- package/dist/main/wallet/createWallet.d.ts +0 -69
- package/dist/main/wallet/createWallet.js +0 -244
- package/dist/main/wallet/createWallet.js.map +0 -1
- package/dist/main/wallet/enum.d.ts +0 -16
- package/dist/main/wallet/enum.js +0 -22
- package/dist/main/wallet/enum.js.map +0 -1
- package/dist/main/wallet/interface.d.ts +0 -76
- package/dist/main/wallet/interface.js +0 -3
- package/dist/main/wallet/interface.js.map +0 -1
- package/dist/main/wallet/model.d.ts +0 -88
- package/dist/main/wallet/model.js +0 -129
- package/dist/main/wallet/model.js.map +0 -1
- package/dist/main/webhook/Webhook.d.ts +0 -40
- package/dist/main/webhook/Webhook.js +0 -82
- package/dist/main/webhook/Webhook.js.map +0 -1
- package/dist/main/webhook/WebhookBch.d.ts +0 -13
- package/dist/main/webhook/WebhookBch.js +0 -148
- package/dist/main/webhook/WebhookBch.js.map +0 -1
- package/dist/main/webhook/WebhookSlp.d.ts +0 -14
- package/dist/main/webhook/WebhookSlp.js +0 -107
- package/dist/main/webhook/WebhookSlp.js.map +0 -1
- package/dist/main/webhook/WebhookWorker.d.ts +0 -22
- package/dist/main/webhook/WebhookWorker.js +0 -100
- package/dist/main/webhook/WebhookWorker.js.map +0 -1
- package/dist/main/webhook/index.d.ts +0 -5
- package/dist/main/webhook/index.js +0 -23
- package/dist/main/webhook/index.js.map +0 -1
- package/dist/main/webhook/interface.d.ts +0 -8
- package/dist/main/webhook/interface.js +0 -3
- package/dist/main/webhook/interface.js.map +0 -1
- package/dist/mainnet-0.5.9.js +0 -2
- package/dist/mainnet-0.5.9.js.LICENSE.txt +0 -48
- package/dist/tsconfig.browser.tsbuildinfo +0 -1
- package/jest.config.js +0 -23
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
import { RegTestWallet, TestNetWallet, Wallet } from "./Wif";
|
|
2
|
+
import { initProviders, disconnectProviders } from "../network/Connection";
|
|
3
|
+
import { SendRequest, TokenMintRequest, TokenSendRequest } from "./model";
|
|
4
|
+
import { Network, NFTCapability } from "../interface";
|
|
5
|
+
import { binToHex, utf8ToBin } from "@bitauth/libauth";
|
|
6
|
+
import { delay } from "../util";
|
|
7
|
+
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
await initProviders([Network.REGTEST]);
|
|
10
|
+
});
|
|
11
|
+
afterAll(async () => {
|
|
12
|
+
await disconnectProviders([Network.REGTEST]);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
describe(`Test cashtokens`, () => {
|
|
16
|
+
test("Test tokens will not be burned when sending bch value", async () => {
|
|
17
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
18
|
+
const bob = await RegTestWallet.newRandom();
|
|
19
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
20
|
+
amount: 100,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
24
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
25
|
+
expect(tokenBalance).toBe(100);
|
|
26
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
27
|
+
expect(tokenUtxos.length).toBe(1);
|
|
28
|
+
await alice.send([
|
|
29
|
+
new SendRequest({
|
|
30
|
+
cashaddr: bob.cashaddr!,
|
|
31
|
+
value: 5000,
|
|
32
|
+
unit: "sat",
|
|
33
|
+
}),
|
|
34
|
+
new TokenSendRequest({
|
|
35
|
+
cashaddr: bob.cashaddr!,
|
|
36
|
+
amount: 25,
|
|
37
|
+
tokenId: tokenId,
|
|
38
|
+
}),
|
|
39
|
+
]);
|
|
40
|
+
expect(await bob.getTokenBalance(tokenId)).toBe(25);
|
|
41
|
+
expect(await bob.getBalance("sat")).toBe(5000);
|
|
42
|
+
|
|
43
|
+
await bob.send(
|
|
44
|
+
new SendRequest({
|
|
45
|
+
cashaddr: alice.cashaddr!,
|
|
46
|
+
value: 1000,
|
|
47
|
+
unit: "sat",
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
expect(await bob.getTokenBalance(tokenId)).toBe(25);
|
|
51
|
+
expect(await bob.getBalance("sat")).toBe(3780);
|
|
52
|
+
|
|
53
|
+
await bob.sendMax(alice.cashaddr!);
|
|
54
|
+
expect(await bob.getTokenBalance(tokenId)).toBe(25);
|
|
55
|
+
expect(await bob.getBalance("sat")).toBe(0);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test("Test fungible cashtoken genesis and sending", async () => {
|
|
59
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
60
|
+
const bob = await RegTestWallet.newRandom();
|
|
61
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
62
|
+
amount: 100,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
66
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
67
|
+
expect(tokenBalance).toBe(100);
|
|
68
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
69
|
+
expect(tokenUtxos.length).toBe(1);
|
|
70
|
+
const response = await alice.send([
|
|
71
|
+
new TokenSendRequest({
|
|
72
|
+
cashaddr: bob.cashaddr!,
|
|
73
|
+
amount: 25,
|
|
74
|
+
tokenId: tokenId,
|
|
75
|
+
}),
|
|
76
|
+
new TokenSendRequest({
|
|
77
|
+
cashaddr: alice.cashaddr!,
|
|
78
|
+
amount: 25,
|
|
79
|
+
tokenId: tokenId,
|
|
80
|
+
}),
|
|
81
|
+
]);
|
|
82
|
+
const newTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
83
|
+
expect(newTokenUtxos.length).toBe(2);
|
|
84
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(75);
|
|
85
|
+
expect(await bob.getTokenBalance(tokenId)).toBe(25);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("Test NFT cashtoken genesis and sending", async () => {
|
|
89
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
90
|
+
const bob = await RegTestWallet.newRandom();
|
|
91
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
92
|
+
cashaddr: alice.cashaddr!,
|
|
93
|
+
capability: NFTCapability.mutable,
|
|
94
|
+
commitment: "abcd",
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
98
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
99
|
+
expect(tokenBalance).toBe(0);
|
|
100
|
+
const nftTokenBalance = await alice.getNftTokenBalance(tokenId);
|
|
101
|
+
expect(nftTokenBalance).toBe(1);
|
|
102
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
103
|
+
expect(tokenUtxos.length).toBe(1);
|
|
104
|
+
const response = await alice.send([
|
|
105
|
+
{
|
|
106
|
+
cashaddr: bob.cashaddr!,
|
|
107
|
+
tokenId: tokenId,
|
|
108
|
+
} as any,
|
|
109
|
+
]);
|
|
110
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
111
|
+
expect(await alice.getNftTokenBalance(tokenId)).toBe(0);
|
|
112
|
+
const newTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
113
|
+
expect(newTokenUtxos.length).toBe(0);
|
|
114
|
+
|
|
115
|
+
expect(await bob.getTokenBalance(tokenId)).toBe(0);
|
|
116
|
+
const bobTokenUtxos = await bob.getTokenUtxos(tokenId);
|
|
117
|
+
expect(bobTokenUtxos.length).toBe(1);
|
|
118
|
+
expect(tokenId).toEqual(response.tokenIds![0]);
|
|
119
|
+
expect(bobTokenUtxos[0].token?.commitment).toEqual("abcd");
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("Test immutable NFT cashtoken genesis and sending, error on mutation", async () => {
|
|
123
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
124
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
125
|
+
cashaddr: alice.cashaddr!,
|
|
126
|
+
capability: NFTCapability.none,
|
|
127
|
+
commitment: "abcd",
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
131
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
132
|
+
expect(tokenBalance).toBe(0);
|
|
133
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
134
|
+
expect(tokenUtxos.length).toBe(1);
|
|
135
|
+
await expect(
|
|
136
|
+
alice.send([
|
|
137
|
+
new TokenSendRequest({
|
|
138
|
+
cashaddr: alice.cashaddr!,
|
|
139
|
+
tokenId: tokenId,
|
|
140
|
+
commitment: "abcd02",
|
|
141
|
+
}),
|
|
142
|
+
])
|
|
143
|
+
).rejects.toThrow("Can not change the commitment of an immutable token");
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("Test mutable NFT cashtoken genesis and mutation", async () => {
|
|
147
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
148
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
149
|
+
cashaddr: alice.cashaddr!,
|
|
150
|
+
capability: NFTCapability.mutable,
|
|
151
|
+
commitment: "abcd",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
155
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
156
|
+
expect(tokenBalance).toBe(0);
|
|
157
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
158
|
+
expect(tokenUtxos.length).toBe(1);
|
|
159
|
+
const response = await alice.send([
|
|
160
|
+
new TokenSendRequest({
|
|
161
|
+
cashaddr: alice.cashaddr!,
|
|
162
|
+
tokenId: tokenId,
|
|
163
|
+
commitment: "abcd02",
|
|
164
|
+
}),
|
|
165
|
+
]);
|
|
166
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
167
|
+
const newTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
168
|
+
expect(newTokenUtxos.length).toBe(1);
|
|
169
|
+
expect(tokenId).toEqual(response.tokenIds![0]);
|
|
170
|
+
expect(newTokenUtxos[0].token?.commitment).toEqual("abcd02");
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("Test minting NFT cashtoken genesis and minting", async () => {
|
|
174
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
175
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
176
|
+
cashaddr: alice.cashaddr!,
|
|
177
|
+
capability: NFTCapability.minting,
|
|
178
|
+
commitment: "abcd",
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
182
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
183
|
+
expect(tokenBalance).toBe(0);
|
|
184
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
185
|
+
expect(tokenUtxos.length).toBe(1);
|
|
186
|
+
const response = await alice.tokenMint(tokenId, [
|
|
187
|
+
new TokenMintRequest({
|
|
188
|
+
cashaddr: alice.cashaddr!,
|
|
189
|
+
}),
|
|
190
|
+
new TokenMintRequest({
|
|
191
|
+
cashaddr: alice.cashaddr!,
|
|
192
|
+
}),
|
|
193
|
+
]);
|
|
194
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
195
|
+
const newTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
196
|
+
expect(newTokenUtxos.length).toBe(3);
|
|
197
|
+
expect(tokenId).toEqual(response.tokenIds![0]);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("Test minting NFT and optionally burning FT cashtoken", async () => {
|
|
201
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
202
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
203
|
+
cashaddr: alice.cashaddr!,
|
|
204
|
+
amount: 4,
|
|
205
|
+
capability: NFTCapability.minting,
|
|
206
|
+
commitment: "abcd",
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
210
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
211
|
+
expect(tokenBalance).toBe(4);
|
|
212
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
213
|
+
expect(tokenUtxos.length).toBe(1);
|
|
214
|
+
|
|
215
|
+
// mint 2 NFTs, amount reducing
|
|
216
|
+
const response = await alice.tokenMint(
|
|
217
|
+
tokenId,
|
|
218
|
+
[
|
|
219
|
+
new TokenMintRequest({
|
|
220
|
+
cashaddr: alice.cashaddr!,
|
|
221
|
+
}),
|
|
222
|
+
new TokenMintRequest({
|
|
223
|
+
cashaddr: alice.cashaddr!,
|
|
224
|
+
}),
|
|
225
|
+
],
|
|
226
|
+
true
|
|
227
|
+
);
|
|
228
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(2);
|
|
229
|
+
const newTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
230
|
+
expect(newTokenUtxos.length).toBe(3);
|
|
231
|
+
expect(tokenId).toEqual(response.tokenIds![0]);
|
|
232
|
+
|
|
233
|
+
// mint 2 more NFTs without amount reducing
|
|
234
|
+
const ftResponse = await alice.tokenMint(
|
|
235
|
+
tokenId,
|
|
236
|
+
[
|
|
237
|
+
new TokenMintRequest({
|
|
238
|
+
cashaddr: alice.cashaddr!,
|
|
239
|
+
}),
|
|
240
|
+
new TokenMintRequest({
|
|
241
|
+
cashaddr: alice.cashaddr!,
|
|
242
|
+
}),
|
|
243
|
+
],
|
|
244
|
+
false
|
|
245
|
+
);
|
|
246
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(2);
|
|
247
|
+
const ftTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
248
|
+
expect(ftTokenUtxos.length).toBe(5);
|
|
249
|
+
expect(tokenId).toEqual(ftResponse.tokenIds![0]);
|
|
250
|
+
|
|
251
|
+
// we are going to hit amount -1, when minting 3 more NFTs
|
|
252
|
+
// check that it will stop at 0
|
|
253
|
+
const ft2Response = await alice.tokenMint(
|
|
254
|
+
tokenId,
|
|
255
|
+
[
|
|
256
|
+
new TokenMintRequest({
|
|
257
|
+
cashaddr: alice.cashaddr!,
|
|
258
|
+
}),
|
|
259
|
+
new TokenMintRequest({
|
|
260
|
+
cashaddr: alice.cashaddr!,
|
|
261
|
+
}),
|
|
262
|
+
new TokenMintRequest({
|
|
263
|
+
cashaddr: alice.cashaddr!,
|
|
264
|
+
}),
|
|
265
|
+
],
|
|
266
|
+
true
|
|
267
|
+
);
|
|
268
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
269
|
+
const ft2TokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
270
|
+
expect(ft2TokenUtxos.length).toBe(8);
|
|
271
|
+
expect(tokenId).toEqual(ft2Response.tokenIds![0]);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("Test explicit burning of FT", async () => {
|
|
275
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
276
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
277
|
+
cashaddr: alice.cashaddr!,
|
|
278
|
+
amount: 4,
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
282
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
283
|
+
expect(tokenBalance).toBe(4);
|
|
284
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
285
|
+
expect(tokenUtxos.length).toBe(1);
|
|
286
|
+
|
|
287
|
+
// burn 5 FT
|
|
288
|
+
const response = await alice.tokenBurn(
|
|
289
|
+
{
|
|
290
|
+
tokenId: tokenId,
|
|
291
|
+
amount: 5,
|
|
292
|
+
},
|
|
293
|
+
"burn"
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
const rawTx = await alice.provider!.getRawTransaction(response.txId, true);
|
|
297
|
+
expect(rawTx!.vout.length).toEqual(3);
|
|
298
|
+
expect(rawTx!.vout[0].scriptPubKey.type).toEqual("nulldata");
|
|
299
|
+
expect(rawTx!.vout[0].scriptPubKey.hex).toContain(
|
|
300
|
+
binToHex(utf8ToBin("burn"))
|
|
301
|
+
);
|
|
302
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
303
|
+
const newTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
304
|
+
expect(newTokenUtxos.length).toBe(0);
|
|
305
|
+
expect(tokenId).toEqual(response.tokenIds![0]);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test("Test explicit burning of FT+NFT", async () => {
|
|
309
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
310
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
311
|
+
cashaddr: alice.cashaddr!,
|
|
312
|
+
amount: 4,
|
|
313
|
+
capability: NFTCapability.minting,
|
|
314
|
+
commitment: "abcd",
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
318
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
319
|
+
expect(tokenBalance).toBe(4);
|
|
320
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
321
|
+
expect(tokenUtxos.length).toBe(1);
|
|
322
|
+
|
|
323
|
+
// burn 1 FT
|
|
324
|
+
const response = await alice.tokenBurn(
|
|
325
|
+
{
|
|
326
|
+
tokenId: tokenId,
|
|
327
|
+
amount: 1,
|
|
328
|
+
capability: NFTCapability.minting,
|
|
329
|
+
commitment: "abcd",
|
|
330
|
+
},
|
|
331
|
+
"burn"
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
const rawTx = await alice.provider!.getRawTransaction(response.txId, true);
|
|
335
|
+
expect(rawTx!.vout.length).toEqual(3);
|
|
336
|
+
expect(rawTx!.vout[0].scriptPubKey.type).toEqual("nulldata");
|
|
337
|
+
expect(rawTx!.vout[0].scriptPubKey.hex).toContain(
|
|
338
|
+
binToHex(utf8ToBin("burn"))
|
|
339
|
+
);
|
|
340
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(3);
|
|
341
|
+
expect((await alice.getAllTokenBalances())[tokenId]).toBe(3);
|
|
342
|
+
const newTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
343
|
+
expect(newTokenUtxos.length).toBe(1);
|
|
344
|
+
expect(await alice.getNftTokenBalance(tokenId)).toBe(1);
|
|
345
|
+
expect((await alice.getAllNftTokenBalances())[tokenId || 0]).toBe(1);
|
|
346
|
+
expect(tokenId).toEqual(response.tokenIds![0]);
|
|
347
|
+
|
|
348
|
+
// burn the rest FTs
|
|
349
|
+
const ftResponse = await alice.tokenBurn(
|
|
350
|
+
{
|
|
351
|
+
tokenId: tokenId,
|
|
352
|
+
amount: 5,
|
|
353
|
+
capability: NFTCapability.minting,
|
|
354
|
+
commitment: "abcd",
|
|
355
|
+
},
|
|
356
|
+
"burn"
|
|
357
|
+
);
|
|
358
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
359
|
+
const ftTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
360
|
+
expect(ftTokenUtxos.length).toBe(1);
|
|
361
|
+
expect(tokenId).toEqual(ftResponse.tokenIds![0]);
|
|
362
|
+
|
|
363
|
+
// burn the NFT too
|
|
364
|
+
const nftResponse = await alice.tokenBurn(
|
|
365
|
+
{
|
|
366
|
+
tokenId: tokenId,
|
|
367
|
+
capability: NFTCapability.minting,
|
|
368
|
+
commitment: "abcd",
|
|
369
|
+
},
|
|
370
|
+
"burn"
|
|
371
|
+
);
|
|
372
|
+
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
373
|
+
expect((await alice.getAllTokenBalances())[tokenId] || 0).toBe(0);
|
|
374
|
+
const nftTokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
375
|
+
expect(nftTokenUtxos.length).toBe(0);
|
|
376
|
+
expect(tokenId).toEqual(nftResponse.tokenIds![0]);
|
|
377
|
+
expect(await alice.getNftTokenBalance(tokenId)).toBe(0);
|
|
378
|
+
expect((await alice.getAllNftTokenBalances())[tokenId] || 0).toBe(0);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
test("Test cashtoken satoshi values and fee calculations", async () => {
|
|
382
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
383
|
+
const bob = await RegTestWallet.newRandom();
|
|
384
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
385
|
+
amount: 100,
|
|
386
|
+
value: 7000,
|
|
387
|
+
cashaddr: bob.cashaddr!,
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
391
|
+
const tokenBalance = await bob.getTokenBalance(tokenId);
|
|
392
|
+
expect(tokenBalance).toBe(100);
|
|
393
|
+
const tokenUtxos = await bob.getTokenUtxos(tokenId);
|
|
394
|
+
expect(tokenUtxos.length).toBe(1);
|
|
395
|
+
expect(tokenUtxos[0].satoshis).toBe(7000);
|
|
396
|
+
|
|
397
|
+
// lower the token satoshi value
|
|
398
|
+
const response = await bob.send([
|
|
399
|
+
new TokenSendRequest({
|
|
400
|
+
cashaddr: bob.cashaddr!,
|
|
401
|
+
amount: 100,
|
|
402
|
+
tokenId: tokenId,
|
|
403
|
+
value: 1500,
|
|
404
|
+
}),
|
|
405
|
+
]);
|
|
406
|
+
let newTokenUtxos = await bob.getTokenUtxos(tokenId);
|
|
407
|
+
expect(newTokenUtxos.length).toBe(1);
|
|
408
|
+
expect(await bob.getTokenBalance(tokenId)).toBe(100);
|
|
409
|
+
|
|
410
|
+
let bobUtxos = await bob.getAddressUtxos(bob.cashaddr!);
|
|
411
|
+
expect(bobUtxos.length).toBe(2);
|
|
412
|
+
expect(bobUtxos[0].satoshis).toBe(1500);
|
|
413
|
+
expect(bobUtxos[1].satoshis).toBe(5245);
|
|
414
|
+
|
|
415
|
+
// raise the token satoshi value
|
|
416
|
+
await bob.send([
|
|
417
|
+
new TokenSendRequest({
|
|
418
|
+
cashaddr: bob.cashaddr!,
|
|
419
|
+
amount: 100,
|
|
420
|
+
tokenId: tokenId,
|
|
421
|
+
value: 3000,
|
|
422
|
+
}),
|
|
423
|
+
]);
|
|
424
|
+
newTokenUtxos = await bob.getTokenUtxos(tokenId);
|
|
425
|
+
expect(newTokenUtxos.length).toBe(1);
|
|
426
|
+
expect(await bob.getTokenBalance(tokenId)).toBe(100);
|
|
427
|
+
|
|
428
|
+
bobUtxos = await bob.getAddressUtxos(bob.cashaddr!);
|
|
429
|
+
expect(bobUtxos.length).toBe(2);
|
|
430
|
+
expect(bobUtxos[0].satoshis).toBe(3000);
|
|
431
|
+
expect(bobUtxos[1].satoshis).toBe(3349);
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
test("Test cashtoken waiting and watching balance", async () => {
|
|
435
|
+
const alice = await RegTestWallet.fromId(process.env.ALICE_ID!);
|
|
436
|
+
const bob = await RegTestWallet.newRandom();
|
|
437
|
+
|
|
438
|
+
const genesisResponse = await alice.tokenGenesis({
|
|
439
|
+
amount: 100,
|
|
440
|
+
value: 5000,
|
|
441
|
+
cashaddr: alice.cashaddr!,
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
445
|
+
const tokenBalance = await alice.getTokenBalance(tokenId);
|
|
446
|
+
expect(tokenBalance).toBe(100);
|
|
447
|
+
const tokenUtxos = await alice.getTokenUtxos(tokenId);
|
|
448
|
+
expect(tokenUtxos.length).toBe(1);
|
|
449
|
+
expect(tokenUtxos[0].satoshis).toBe(5000);
|
|
450
|
+
|
|
451
|
+
let seenBalance = 0;
|
|
452
|
+
setTimeout(
|
|
453
|
+
() =>
|
|
454
|
+
alice.send([
|
|
455
|
+
new TokenSendRequest({
|
|
456
|
+
cashaddr: bob.cashaddr!,
|
|
457
|
+
amount: 100,
|
|
458
|
+
tokenId: tokenId,
|
|
459
|
+
value: 1500,
|
|
460
|
+
}),
|
|
461
|
+
]),
|
|
462
|
+
0
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
const cancel = bob.watchTokenBalance(tokenId, (balance) => {
|
|
466
|
+
seenBalance = balance;
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
const balance = await bob.waitForTokenBalance(tokenId, 100);
|
|
470
|
+
expect(balance).toBe(100);
|
|
471
|
+
expect(seenBalance).toBe(100);
|
|
472
|
+
await cancel();
|
|
473
|
+
await delay(500);
|
|
474
|
+
});
|
|
475
|
+
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
const { default: BigNumber } = require("bignumber.js");
|
|
2
1
|
const playwright = require("playwright");
|
|
3
|
-
|
|
2
|
+
|
|
4
3
|
const PAGE_URL = "http://localhost:8080";
|
|
5
4
|
|
|
6
|
-
describe(`Wallet should function in the browser`, () => {
|
|
5
|
+
describe.skip(`Wallet should function in the browser`, () => {
|
|
7
6
|
let browser = null;
|
|
8
7
|
let page = null;
|
|
9
8
|
|
|
@@ -93,11 +92,10 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
93
92
|
async ([wif, tokenId]) => {
|
|
94
93
|
const wallet = await TestNetWallet.fromId(`wif:testnet:${wif}`);
|
|
95
94
|
|
|
96
|
-
// FIXME: we do not have gspp testnet yet
|
|
97
|
-
if (wallet.slp.provider instanceof GsppProvider) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
95
|
+
// // FIXME: we do not have gspp testnet yet
|
|
96
|
+
// if (wallet.slp.provider instanceof GsppProvider) {
|
|
97
|
+
// console.warn("we do not have gspp testnet yet");
|
|
98
|
+
// }
|
|
101
99
|
|
|
102
100
|
const bobWallet = await TestNetWallet.newRandom();
|
|
103
101
|
|
package/src/wallet/Slp.test.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RegTestWallet, TestNetWallet, Wallet } from "
|
|
1
|
+
import { RegTestWallet, TestNetWallet, Wallet } from "./Wif";
|
|
2
2
|
|
|
3
3
|
import { Network } from "..";
|
|
4
4
|
import { disconnectProviders, initProviders } from "../network";
|
|
@@ -15,7 +15,7 @@ import { GsppProvider } from "../slp/GsppProvider";
|
|
|
15
15
|
import { createSlpWallet, walletFromId } from "./createWallet";
|
|
16
16
|
import { WalletTypeEnum } from "./enum";
|
|
17
17
|
|
|
18
|
-
describe("Slp wallet tests", () => {
|
|
18
|
+
describe.skip("Slp wallet tests", () => {
|
|
19
19
|
beforeAll(async () => {
|
|
20
20
|
await initProviders([Network.MAINNET, Network.REGTEST]);
|
|
21
21
|
});
|
package/src/wallet/Slp.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
WatchWallet,
|
|
9
9
|
TestNetWatchWallet,
|
|
10
10
|
RegTestWatchWallet,
|
|
11
|
-
} from "../wallet/Wif";
|
|
11
|
+
} from "../wallet/Wif.js";
|
|
12
12
|
import {
|
|
13
13
|
SlpFormattedUtxo,
|
|
14
14
|
SlpGenesisOptions,
|
|
@@ -22,38 +22,41 @@ import {
|
|
|
22
22
|
SlpTokenType,
|
|
23
23
|
SlpTxI,
|
|
24
24
|
SlpUtxoI,
|
|
25
|
-
} from "../slp/interface";
|
|
26
|
-
import { SlpDbProvider } from "../slp/SlpDbProvider";
|
|
27
|
-
import { ImageI } from "../qr/interface";
|
|
28
|
-
import { qrAddress } from "../qr/Qr";
|
|
29
|
-
import { TxI, UtxoI } from "../interface";
|
|
30
|
-
import { ElectrumRawTransaction } from "../network/interface";
|
|
25
|
+
} from "../slp/interface.js";
|
|
26
|
+
import { SlpDbProvider } from "../slp/SlpDbProvider.js";
|
|
27
|
+
import { ImageI } from "../qr/interface.js";
|
|
28
|
+
import { qrAddress } from "../qr/Qr.js";
|
|
29
|
+
import { TxI, UtxoI } from "../interface.js";
|
|
30
|
+
import { ElectrumRawTransaction } from "../network/interface.js";
|
|
31
31
|
import BigNumber from "bignumber.js";
|
|
32
|
-
import { getRelayFeeCache } from "../network/getRelayFeeCache";
|
|
32
|
+
import { getRelayFeeCache } from "../network/getRelayFeeCache.js";
|
|
33
33
|
import {
|
|
34
34
|
buildEncodedTransaction,
|
|
35
35
|
getFeeAmount,
|
|
36
36
|
getSuitableUtxos,
|
|
37
|
-
} from "../transaction/Wif";
|
|
37
|
+
} from "../transaction/Wif.js";
|
|
38
38
|
import {
|
|
39
39
|
SlpGetGenesisOutputs,
|
|
40
40
|
SlpGetMintOutputs,
|
|
41
41
|
SlpGetSendOutputs,
|
|
42
|
-
} from "../slp/SlpLibAuth";
|
|
43
|
-
import { binToHex } from "@bitauth/libauth";
|
|
44
|
-
import { SendRequest } from "./model";
|
|
42
|
+
} from "../slp/SlpLibAuth.js";
|
|
43
|
+
import { binToHex, Output } from "@bitauth/libauth";
|
|
44
|
+
import { SendRequest } from "./model.js";
|
|
45
45
|
import {
|
|
46
46
|
SlpCancelWatchFn,
|
|
47
47
|
SlpProvider,
|
|
48
48
|
SlpWatchBalanceCallback,
|
|
49
49
|
SlpWatchTransactionCallback,
|
|
50
|
-
} from "../slp/SlpProvider";
|
|
51
|
-
import { toCashAddress, toSlpAddress } from "../util/bchaddr";
|
|
52
|
-
import { GsppProvider } from "../slp/GsppProvider";
|
|
53
|
-
import { delay } from "../util/delay";
|
|
54
|
-
import { Util } from "./Util";
|
|
55
|
-
import {
|
|
56
|
-
import {
|
|
50
|
+
} from "../slp/SlpProvider.js";
|
|
51
|
+
import { toCashAddress, toSlpAddress } from "../util/bchaddr.js";
|
|
52
|
+
import { GsppProvider } from "../slp/GsppProvider.js";
|
|
53
|
+
import { delay } from "../util/delay.js";
|
|
54
|
+
import { Util } from "./Util.js";
|
|
55
|
+
import { FeePaidByEnum } from "./enum.js";
|
|
56
|
+
import {
|
|
57
|
+
getRuntimePlatform,
|
|
58
|
+
RuntimePlatform,
|
|
59
|
+
} from "../util/getRuntimePlatform.js";
|
|
57
60
|
|
|
58
61
|
/**
|
|
59
62
|
* Class to manage an slp enabled wallet.
|
|
@@ -82,7 +85,7 @@ export class Slp {
|
|
|
82
85
|
|
|
83
86
|
let provider = Slp.defaultProvider;
|
|
84
87
|
if (
|
|
85
|
-
|
|
88
|
+
getRuntimePlatform() === RuntimePlatform.node &&
|
|
86
89
|
process.env.SLP_PROVIDER
|
|
87
90
|
)
|
|
88
91
|
provider = process.env.SLP_PROVIDER!;
|
|
@@ -653,7 +656,7 @@ export class Slp {
|
|
|
653
656
|
private async processSlpTransaction(
|
|
654
657
|
fundingBchUtxos: UtxoI[],
|
|
655
658
|
slpOutputsResult: {
|
|
656
|
-
SlpOutputs:
|
|
659
|
+
SlpOutputs: Output[];
|
|
657
660
|
FundingSlpUtxos: SlpUtxoI[];
|
|
658
661
|
BchSendRequests: SendRequest[];
|
|
659
662
|
},
|
|
@@ -692,7 +695,8 @@ export class Slp {
|
|
|
692
695
|
fundingBchUtxos,
|
|
693
696
|
BigInt(bchSpendAmount) + BigInt(feeEstimate),
|
|
694
697
|
bestHeight,
|
|
695
|
-
FeePaidByEnum.change
|
|
698
|
+
FeePaidByEnum.change,
|
|
699
|
+
slpOutputsResult.BchSendRequests
|
|
696
700
|
);
|
|
697
701
|
|
|
698
702
|
if (fundingUtxos.length === 0) {
|
package/src/wallet/Util.ts
CHANGED
|
@@ -8,16 +8,13 @@ import {
|
|
|
8
8
|
Wallet,
|
|
9
9
|
WatchWallet,
|
|
10
10
|
WifWallet,
|
|
11
|
-
} from "../wallet/Wif";
|
|
11
|
+
} from "../wallet/Wif.js";
|
|
12
12
|
import {
|
|
13
|
-
binToBigIntUint64LE,
|
|
14
13
|
binToHex,
|
|
15
14
|
decodeTransaction as decodeTransactionLibAuth,
|
|
16
15
|
hexToBin,
|
|
17
|
-
instantiateSha256,
|
|
18
16
|
lockingBytecodeToCashAddress,
|
|
19
17
|
Transaction as LibAuthTransaction,
|
|
20
|
-
TransactionDecodingError,
|
|
21
18
|
} from "@bitauth/libauth";
|
|
22
19
|
import {
|
|
23
20
|
ElectrumRawTransaction,
|
|
@@ -25,10 +22,9 @@ import {
|
|
|
25
22
|
ElectrumRawTransactionVinScriptSig,
|
|
26
23
|
ElectrumRawTransactionVout,
|
|
27
24
|
ElectrumRawTransactionVoutScriptPubKey,
|
|
28
|
-
} from "../network/interface";
|
|
29
|
-
import { bchParam } from "../chain";
|
|
30
|
-
|
|
31
|
-
let sha256;
|
|
25
|
+
} from "../network/interface.js";
|
|
26
|
+
import { bchParam } from "../chain.js";
|
|
27
|
+
import { getTransactionHash } from "../util/transaction.js";
|
|
32
28
|
|
|
33
29
|
/**
|
|
34
30
|
* Class with various wallet utilities.
|
|
@@ -49,19 +45,13 @@ export class Util {
|
|
|
49
45
|
}
|
|
50
46
|
|
|
51
47
|
public async getTransactionHash(rawTransactionHex: string): Promise<string> {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!sha256) {
|
|
55
|
-
sha256 = await instantiateSha256();
|
|
56
|
-
}
|
|
57
|
-
// transaction hash is a double sha256 of a raw transaction data, reversed byte order
|
|
58
|
-
return binToHex(sha256.hash(sha256.hash(transactionBin)).reverse());
|
|
48
|
+
return getTransactionHash(rawTransactionHex);
|
|
59
49
|
}
|
|
60
50
|
|
|
61
51
|
public static async getTransactionHash(
|
|
62
52
|
rawTransactionHex: string
|
|
63
53
|
): Promise<string> {
|
|
64
|
-
return
|
|
54
|
+
return getTransactionHash(rawTransactionHex);
|
|
65
55
|
}
|
|
66
56
|
|
|
67
57
|
public async decodeTransaction(
|
|
@@ -85,8 +75,8 @@ export class Util {
|
|
|
85
75
|
}
|
|
86
76
|
|
|
87
77
|
const result = decodeTransactionLibAuth(transactionBin);
|
|
88
|
-
if (result ===
|
|
89
|
-
throw Error(
|
|
78
|
+
if (typeof result === "string") {
|
|
79
|
+
throw Error(result);
|
|
90
80
|
}
|
|
91
81
|
|
|
92
82
|
const transaction = this.mapToElectrumRawTransaction(
|
|
@@ -147,8 +137,7 @@ export class Util {
|
|
|
147
137
|
],
|
|
148
138
|
hex: binToHex(output.lockingBytecode),
|
|
149
139
|
} as ElectrumRawTransactionVoutScriptPubKey,
|
|
150
|
-
value:
|
|
151
|
-
Number(binToBigIntUint64LE(output.satoshis)) / bchParam.subUnits,
|
|
140
|
+
value: Number(output.valueSatoshis) / bchParam.subUnits,
|
|
152
141
|
};
|
|
153
142
|
}
|
|
154
143
|
);
|