mainnet-js 0.5.9 → 1.0.0-rc.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +9 -1
- package/dist/mainnet-1.0.0-rc.3.js +2928 -0
- package/dist/module/chain.d.ts +1 -0
- package/dist/module/chain.d.ts.map +1 -0
- package/dist/module/cli.d.ts +1 -0
- package/dist/module/cli.d.ts.map +1 -0
- package/dist/module/cli.js +2 -2
- package/dist/module/cli.js.map +1 -1
- package/dist/module/constant.d.ts +1 -0
- package/dist/module/constant.d.ts.map +1 -0
- package/dist/module/db/ExchangeRateProvider.d.ts +2 -1
- package/dist/module/db/ExchangeRateProvider.d.ts.map +1 -0
- package/dist/module/db/IndexedDBProvider.d.ts +3 -2
- package/dist/module/db/IndexedDBProvider.d.ts.map +1 -0
- package/dist/module/db/SqlProvider.d.ts +7 -8
- package/dist/module/db/SqlProvider.d.ts.map +1 -0
- package/dist/module/db/SqlProvider.js +10 -8
- package/dist/module/db/SqlProvider.js.map +1 -1
- package/dist/module/db/StorageProvider.d.ts +2 -1
- package/dist/module/db/StorageProvider.d.ts.map +1 -0
- package/dist/module/db/getStorageProvider.d.ts +3 -0
- package/dist/module/db/getStorageProvider.d.ts.map +1 -0
- package/dist/module/db/getStorageProvider.js +19 -0
- package/dist/module/db/getStorageProvider.js.map +1 -0
- package/dist/module/db/index.d.ts +4 -3
- package/dist/module/db/index.d.ts.map +1 -0
- package/dist/module/db/index.js +2 -2
- package/dist/module/db/index.js.map +1 -1
- package/dist/module/db/interface.d.ts +1 -0
- package/dist/module/db/interface.d.ts.map +1 -0
- package/dist/module/db/util.d.ts +2 -3
- package/dist/module/db/util.d.ts.map +1 -0
- package/dist/module/db/util.js +0 -17
- package/dist/module/db/util.js.map +1 -1
- package/dist/module/enum.d.ts +1 -0
- package/dist/module/enum.d.ts.map +1 -0
- package/dist/module/history/electrumTransformer.d.ts +3 -2
- package/dist/module/history/electrumTransformer.d.ts.map +1 -0
- package/dist/module/history/electrumTransformer.js +11 -11
- package/dist/module/history/electrumTransformer.js.map +1 -1
- package/dist/module/history/interface.d.ts +2 -1
- package/dist/module/history/interface.d.ts.map +1 -0
- package/dist/module/index.d.ts +26 -21
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +25 -17
- package/dist/module/index.js.map +1 -1
- package/dist/module/interface.d.ts +14 -0
- package/dist/module/interface.d.ts.map +1 -0
- package/dist/module/interface.js +5 -0
- package/dist/module/interface.js.map +1 -1
- package/dist/module/message/index.d.ts +3 -2
- package/dist/module/message/index.d.ts.map +1 -0
- package/dist/module/message/index.js +2 -2
- package/dist/module/message/index.js.map +1 -1
- package/dist/module/message/interface.d.ts +1 -0
- package/dist/module/message/interface.d.ts.map +1 -0
- package/dist/module/message/signed.d.ts +2 -1
- package/dist/module/message/signed.d.ts.map +1 -0
- package/dist/module/message/signed.js +10 -4
- package/dist/module/message/signed.js.map +1 -1
- package/dist/module/mine/index.d.ts +2 -1
- package/dist/module/mine/index.d.ts.map +1 -0
- package/dist/module/mine/index.js +1 -1
- package/dist/module/mine/index.js.map +1 -1
- package/dist/module/mine/mine.d.ts +1 -0
- package/dist/module/mine/mine.d.ts.map +1 -0
- package/dist/module/mine/mine.js +3 -3
- package/dist/module/mine/mine.js.map +1 -1
- package/dist/module/network/Connection.d.ts +3 -2
- package/dist/module/network/Connection.d.ts.map +1 -0
- package/dist/module/network/Connection.js +3 -3
- package/dist/module/network/Connection.js.map +1 -1
- package/dist/module/network/ElectrumNetworkProvider.d.ts +8 -5
- package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -0
- package/dist/module/network/ElectrumNetworkProvider.js +59 -13
- package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
- package/dist/module/network/NetworkProvider.d.ts +2 -1
- package/dist/module/network/NetworkProvider.d.ts.map +1 -0
- package/dist/module/network/configuration.d.ts +8 -10
- package/dist/module/network/configuration.d.ts.map +1 -0
- package/dist/module/network/configuration.js +29 -17
- package/dist/module/network/configuration.js.map +1 -1
- package/dist/module/network/constant.d.ts +1 -0
- package/dist/module/network/constant.d.ts.map +1 -0
- package/dist/module/network/constant.js +8 -4
- package/dist/module/network/constant.js.map +1 -1
- package/dist/module/network/default.d.ts +4 -3
- package/dist/module/network/default.d.ts.map +1 -0
- package/dist/module/network/default.js +7 -7
- package/dist/module/network/default.js.map +1 -1
- package/dist/module/network/getRelayFeeCache.d.ts +2 -1
- package/dist/module/network/getRelayFeeCache.d.ts.map +1 -0
- package/dist/module/network/getRelayFeeCache.js +2 -2
- package/dist/module/network/getRelayFeeCache.js.map +1 -1
- package/dist/module/network/index.d.ts +3 -2
- package/dist/module/network/index.d.ts.map +1 -0
- package/dist/module/network/index.js +2 -2
- package/dist/module/network/index.js.map +1 -1
- package/dist/module/network/interface.d.ts +1 -0
- package/dist/module/network/interface.d.ts.map +1 -0
- package/dist/module/network/util.d.ts +2 -1
- package/dist/module/network/util.d.ts.map +1 -0
- package/dist/module/qr/Qr.d.ts +2 -1
- package/dist/module/qr/Qr.d.ts.map +1 -0
- package/dist/module/qr/Qr.js +2 -2
- package/dist/module/qr/Qr.js.map +1 -1
- package/dist/module/qr/interface.d.ts +1 -0
- package/dist/module/qr/interface.d.ts.map +1 -0
- package/dist/module/rate/ExchangeRate.d.ts +1 -0
- package/dist/module/rate/ExchangeRate.d.ts.map +1 -0
- package/dist/module/rate/ExchangeRate.js +5 -5
- package/dist/module/rate/ExchangeRate.js.map +1 -1
- package/dist/module/slp/GsppProvider.d.ts +4 -3
- package/dist/module/slp/GsppProvider.d.ts.map +1 -0
- package/dist/module/slp/GsppProvider.js +7 -7
- package/dist/module/slp/GsppProvider.js.map +1 -1
- package/dist/module/slp/SlpDbProvider.d.ts +4 -3
- package/dist/module/slp/SlpDbProvider.d.ts.map +1 -0
- package/dist/module/slp/SlpDbProvider.js +8 -8
- package/dist/module/slp/SlpDbProvider.js.map +1 -1
- package/dist/module/slp/SlpDbTemplates.d.ts +1 -0
- package/dist/module/slp/SlpDbTemplates.d.ts.map +1 -0
- package/dist/module/slp/SlpLibAuth.d.ts +7 -14
- package/dist/module/slp/SlpLibAuth.d.ts.map +1 -0
- package/dist/module/slp/SlpLibAuth.js +48 -39
- package/dist/module/slp/SlpLibAuth.js.map +1 -1
- package/dist/module/slp/SlpProvider.d.ts +2 -1
- package/dist/module/slp/SlpProvider.d.ts.map +1 -0
- package/dist/module/slp/SlpProvider.js.map +1 -1
- package/dist/module/slp/index.d.ts +5 -4
- package/dist/module/slp/index.d.ts.map +1 -0
- package/dist/module/slp/index.js +3 -3
- package/dist/module/slp/index.js.map +1 -1
- package/dist/module/slp/interface.d.ts +2 -1
- package/dist/module/slp/interface.d.ts.map +1 -0
- package/dist/module/test/axios.d.ts +3 -0
- package/dist/module/test/axios.d.ts.map +1 -0
- package/dist/module/test/axios.js +35 -0
- package/dist/module/test/axios.js.map +1 -0
- package/dist/module/test/expect.d.ts +6 -1
- package/dist/module/test/expect.d.ts.map +1 -0
- package/dist/module/test/expect.js +22 -1
- package/dist/module/test/expect.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +19 -16
- package/dist/module/transaction/Wif.d.ts.map +1 -0
- package/dist/module/transaction/Wif.js +152 -55
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/transaction/allocateFee.d.ts +5 -4
- package/dist/module/transaction/allocateFee.d.ts.map +1 -0
- package/dist/module/transaction/allocateFee.js +11 -8
- package/dist/module/transaction/allocateFee.js.map +1 -1
- package/dist/module/util/amountInSatoshi.d.ts +1 -0
- package/dist/module/util/amountInSatoshi.d.ts.map +1 -0
- package/dist/module/util/amountInSatoshi.js +4 -4
- package/dist/module/util/amountInSatoshi.js.map +1 -1
- package/dist/module/util/asSendRequestObject.d.ts +3 -2
- package/dist/module/util/asSendRequestObject.d.ts.map +1 -0
- package/dist/module/util/asSendRequestObject.js +6 -3
- package/dist/module/util/asSendRequestObject.js.map +1 -1
- package/dist/module/util/balanceObjectFromSatoshi.d.ts +1 -0
- package/dist/module/util/balanceObjectFromSatoshi.d.ts.map +1 -0
- package/dist/module/util/balanceObjectFromSatoshi.js +5 -5
- package/dist/module/util/balanceObjectFromSatoshi.js.map +1 -1
- package/dist/module/util/base64.d.ts +2 -1
- package/dist/module/util/base64.d.ts.map +1 -0
- package/dist/module/util/base64.js +5 -25
- package/dist/module/util/base64.js.map +1 -1
- package/dist/module/util/bchaddr.d.ts +1 -0
- package/dist/module/util/bchaddr.d.ts.map +1 -0
- package/dist/module/util/browserNotSupported.d.ts +1 -0
- package/dist/module/util/browserNotSupported.d.ts.map +1 -0
- package/dist/module/util/browserNotSupported.js +1 -1
- package/dist/module/util/browserNotSupported.js.map +1 -1
- package/dist/module/util/checkForEmptySeed.d.ts +1 -0
- package/dist/module/util/checkForEmptySeed.d.ts.map +1 -0
- package/dist/module/util/checkWifNetwork.d.ts +2 -1
- package/dist/module/util/checkWifNetwork.d.ts.map +1 -0
- package/dist/module/util/checkWifNetwork.js +1 -1
- package/dist/module/util/checkWifNetwork.js.map +1 -1
- package/dist/module/util/convert.d.ts +1 -0
- package/dist/module/util/convert.d.ts.map +1 -0
- package/dist/module/util/convert.js +2 -2
- package/dist/module/util/convert.js.map +1 -1
- package/dist/module/util/delay.d.ts +1 -0
- package/dist/module/util/delay.d.ts.map +1 -0
- package/dist/module/util/deriveCashaddr.d.ts +6 -1
- package/dist/module/util/deriveCashaddr.d.ts.map +1 -0
- package/dist/module/util/deriveCashaddr.js +85 -6
- package/dist/module/util/deriveCashaddr.js.map +1 -1
- package/dist/module/util/deriveLockscript.d.ts +1 -0
- package/dist/module/util/deriveLockscript.d.ts.map +1 -0
- package/dist/module/util/deriveNetwork.d.ts +1 -0
- package/dist/module/util/deriveNetwork.d.ts.map +1 -0
- package/dist/module/util/deriveNetwork.js +2 -2
- package/dist/module/util/deriveNetwork.js.map +1 -1
- package/dist/module/util/derivePublicKeyHash.d.ts +3 -1
- package/dist/module/util/derivePublicKeyHash.d.ts.map +1 -0
- package/dist/module/util/derivePublicKeyHash.js +1 -1
- package/dist/module/util/derivePublicKeyHash.js.map +1 -1
- package/dist/module/util/eventsource.d.ts +1 -0
- package/dist/module/util/eventsource.d.ts.map +1 -0
- package/dist/module/util/eventsource.js +3 -2
- package/dist/module/util/eventsource.js.map +1 -1
- package/dist/module/util/floor.d.ts +1 -0
- package/dist/module/util/floor.d.ts.map +1 -0
- package/dist/module/util/getAddrsByXpubKey.d.ts +8 -8
- package/dist/module/util/getAddrsByXpubKey.d.ts.map +1 -0
- package/dist/module/util/getAddrsByXpubKey.js +17 -21
- package/dist/module/util/getAddrsByXpubKey.js.map +1 -1
- package/dist/module/util/getRuntimePlatform.d.ts +1 -0
- package/dist/module/util/getRuntimePlatform.d.ts.map +1 -0
- package/dist/module/util/getUsdRate.d.ts +1 -0
- package/dist/module/util/getUsdRate.d.ts.map +1 -0
- package/dist/module/util/getUsdRate.js +1 -1
- package/dist/module/util/getUsdRate.js.map +1 -1
- package/dist/module/util/getXPubKey.d.ts +2 -1
- package/dist/module/util/getXPubKey.d.ts.map +1 -0
- package/dist/module/util/getXPubKey.js +6 -7
- package/dist/module/util/getXPubKey.js.map +1 -1
- package/dist/module/util/hash160.d.ts +2 -1
- package/dist/module/util/hash160.d.ts.map +1 -0
- package/dist/module/util/hash160.js +2 -4
- package/dist/module/util/hash160.js.map +1 -1
- package/dist/module/util/index.d.ts +21 -20
- package/dist/module/util/index.d.ts.map +1 -0
- package/dist/module/util/index.js +20 -20
- package/dist/module/util/index.js.map +1 -1
- package/dist/module/util/randomBytes.d.ts +3 -1
- package/dist/module/util/randomBytes.d.ts.map +1 -0
- package/dist/module/util/randomBytes.js +2 -3
- package/dist/module/util/randomBytes.js.map +1 -1
- package/dist/module/util/randomInt.d.ts +1 -0
- package/dist/module/util/randomInt.d.ts.map +1 -0
- package/dist/module/util/randomValues.d.ts +1 -0
- package/dist/module/util/randomValues.d.ts.map +1 -0
- package/dist/module/util/randomValues.js +7 -7
- package/dist/module/util/randomValues.js.map +1 -1
- package/dist/module/util/sanitizeAddress.d.ts +1 -0
- package/dist/module/util/sanitizeAddress.d.ts.map +1 -0
- package/dist/module/util/sanitizeAddress.js +1 -1
- package/dist/module/util/sanitizeAddress.js.map +1 -1
- package/dist/module/util/sanitizeUnit.d.ts +2 -1
- package/dist/module/util/sanitizeUnit.d.ts.map +1 -0
- package/dist/module/util/satoshiToAmount.d.ts +1 -0
- package/dist/module/util/satoshiToAmount.d.ts.map +1 -0
- package/dist/module/util/satoshiToAmount.js +4 -4
- package/dist/module/util/satoshiToAmount.js.map +1 -1
- package/dist/module/util/sumSendRequestAmounts.d.ts +3 -2
- package/dist/module/util/sumSendRequestAmounts.d.ts.map +1 -0
- package/dist/module/util/sumSendRequestAmounts.js +5 -2
- package/dist/module/util/sumSendRequestAmounts.js.map +1 -1
- package/dist/module/util/sumUtxoValue.d.ts +4 -2
- package/dist/module/util/sumUtxoValue.d.ts.map +1 -0
- package/dist/module/util/sumUtxoValue.js +17 -3
- package/dist/module/util/sumUtxoValue.js.map +1 -1
- package/dist/module/util/transaction.d.ts +2 -0
- package/dist/module/util/transaction.d.ts.map +1 -0
- package/dist/module/util/transaction.js +7 -0
- package/dist/module/util/transaction.js.map +1 -0
- package/dist/module/wallet/Base.d.ts +8 -7
- package/dist/module/wallet/Base.d.ts.map +1 -0
- package/dist/module/wallet/Base.js +7 -7
- package/dist/module/wallet/Base.js.map +1 -1
- package/dist/module/wallet/Bcmr.d.ts +88 -0
- package/dist/module/wallet/Bcmr.d.ts.map +1 -0
- package/dist/module/wallet/Bcmr.js +281 -0
- package/dist/module/wallet/Bcmr.js.map +1 -0
- package/dist/module/wallet/Slp.d.ts +6 -5
- package/dist/module/wallet/Slp.d.ts.map +1 -0
- package/dist/module/wallet/Slp.js +15 -15
- package/dist/module/wallet/Slp.js.map +1 -1
- package/dist/module/wallet/Util.d.ts +3 -2
- package/dist/module/wallet/Util.d.ts.map +1 -0
- package/dist/module/wallet/Util.js +9 -14
- package/dist/module/wallet/Util.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +124 -20
- package/dist/module/wallet/Wif.d.ts.map +1 -0
- package/dist/module/wallet/Wif.js +406 -74
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/bcmr-v1.schema.d.ts +623 -0
- package/dist/module/wallet/bcmr-v1.schema.d.ts.map +1 -0
- package/dist/module/wallet/bcmr-v1.schema.js +2 -0
- package/dist/module/wallet/bcmr-v1.schema.js.map +1 -0
- package/dist/module/wallet/createWallet.d.ts +3 -2
- package/dist/module/wallet/createWallet.d.ts.map +1 -0
- package/dist/module/wallet/createWallet.js +3 -3
- package/dist/module/wallet/createWallet.js.map +1 -1
- package/dist/module/wallet/enum.d.ts +1 -0
- package/dist/module/wallet/enum.d.ts.map +1 -0
- package/dist/module/wallet/interface.d.ts +10 -6
- package/dist/module/wallet/interface.d.ts.map +1 -0
- package/dist/module/wallet/model.d.ts +81 -5
- package/dist/module/wallet/model.d.ts.map +1 -0
- package/dist/module/wallet/model.js +102 -17
- package/dist/module/wallet/model.js.map +1 -1
- package/dist/module/webhook/Webhook.d.ts +3 -2
- package/dist/module/webhook/Webhook.d.ts.map +1 -0
- package/dist/module/webhook/Webhook.js +4 -1
- package/dist/module/webhook/Webhook.js.map +1 -1
- package/dist/module/webhook/WebhookBch.d.ts +4 -3
- package/dist/module/webhook/WebhookBch.d.ts.map +1 -0
- package/dist/module/webhook/WebhookBch.js +4 -4
- package/dist/module/webhook/WebhookBch.js.map +1 -1
- package/dist/module/webhook/WebhookSlp.d.ts +5 -4
- package/dist/module/webhook/WebhookSlp.d.ts.map +1 -0
- package/dist/module/webhook/WebhookSlp.js +4 -4
- package/dist/module/webhook/WebhookSlp.js.map +1 -1
- package/dist/module/webhook/WebhookWorker.d.ts +3 -2
- package/dist/module/webhook/WebhookWorker.d.ts.map +1 -0
- package/dist/module/webhook/WebhookWorker.js +1 -1
- package/dist/module/webhook/WebhookWorker.js.map +1 -1
- package/dist/module/webhook/index.d.ts +6 -5
- package/dist/module/webhook/index.d.ts.map +1 -0
- package/dist/module/webhook/index.js +5 -5
- package/dist/module/webhook/index.js.map +1 -1
- package/dist/module/webhook/interface.d.ts +1 -0
- package/dist/module/webhook/interface.d.ts.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/polyfill/{bip39.browser.js → bip39.browser.cjs} +1 -0
- package/polyfill/{util.js → util.cjs} +0 -0
- package/src/Wallet.test.headless.js +6 -6
- package/src/cli.ts +3 -3
- package/src/db/ExchangeRateProvider.ts +1 -1
- package/src/db/IndexedDBProvider.test.ts +0 -1
- package/src/db/IndexedDBProvider.ts +2 -2
- package/src/db/SqlProvider.ts +14 -12
- package/src/db/StorageProvider.ts +1 -1
- package/src/db/getStorageProvider.ts +20 -0
- package/src/db/index.ts +3 -3
- package/src/db/util.ts +1 -20
- package/src/history/electrumTransformer.ts +13 -14
- package/src/history/interface.ts +1 -1
- package/src/index.ts +29 -21
- package/src/interface.ts +15 -0
- package/src/message/index.ts +2 -2
- package/src/message/signed.test.ts +4 -4
- package/src/message/signed.ts +23 -6
- package/src/mine/index.ts +1 -1
- package/src/mine/mine.ts +3 -3
- package/src/network/Connection.ts +5 -5
- package/src/network/ElectrumNetworkProvider.ts +85 -20
- package/src/network/NetworkProvider.ts +1 -1
- package/src/network/configuration.test.ts +33 -8
- package/src/network/configuration.ts +33 -18
- package/src/network/constant.ts +9 -4
- package/src/network/default.ts +13 -10
- package/src/network/getRelayFeeCache.ts +3 -3
- package/src/network/index.ts +6 -2
- package/src/network/util.ts +1 -1
- package/src/qr/Qr.ts +3 -3
- package/src/rate/ExchangeRate.ts +14 -15
- package/src/slp/GsppProvider.test.ts +2 -2
- package/src/slp/GsppProvider.ts +11 -8
- package/src/slp/SlpDbProvider.test.ts +1 -1
- package/src/slp/SlpDbProvider.ts +12 -9
- package/src/slp/SlpLibAuth.test.ts +1 -1
- package/src/slp/SlpLibAuth.ts +52 -42
- package/src/slp/SlpProvider.ts +6 -1
- package/src/slp/index.ts +4 -4
- package/src/slp/interface.ts +1 -1
- package/src/test/axios.ts +47 -0
- package/src/test/expect.ts +27 -2
- package/src/transaction/Wif.ts +203 -77
- package/src/transaction/allocateFee.ts +32 -14
- package/src/util/amountInSatoshi.ts +4 -4
- package/src/util/asSendRequestObject.ts +42 -30
- package/src/util/balanceObjectFromSatoshi.ts +5 -5
- package/src/util/base64.ts +5 -24
- package/src/util/browserNotSupported.ts +1 -1
- package/src/util/checkWifNetwork.ts +1 -1
- package/src/util/convert.ts +2 -2
- package/src/util/deriveCashaddr.test.ts +43 -0
- package/src/util/deriveCashaddr.ts +123 -7
- package/src/util/deriveNetwork.ts +2 -2
- package/src/util/derivePublicKeyHash.test.ts +3 -0
- package/src/util/derivePublicKeyHash.ts +18 -5
- package/src/util/eventsource.ts +4 -2
- package/src/util/getAddrsByXpubKey.test.ts +5 -5
- package/src/util/getAddrsByXpubKey.ts +23 -28
- package/src/util/getUsdRate.ts +1 -1
- package/src/util/getXPubKey.ts +5 -7
- package/src/util/hash160.test.ts +2 -2
- package/src/util/hash160.ts +2 -4
- package/src/util/index.ts +26 -20
- package/src/util/randomBytes.ts +2 -3
- package/src/util/randomValues.ts +8 -8
- package/src/util/sanitizeAddress.ts +1 -1
- package/src/util/sanitizeUnit.ts +1 -1
- package/src/util/satoshiToAmount.ts +4 -4
- package/src/util/sumSendRequestAmounts.ts +10 -4
- package/src/util/sumUtxoValue.ts +19 -7
- package/src/util/transaction.ts +10 -0
- package/src/wallet/Base.ts +11 -11
- package/src/wallet/Bcmr.test.headless.js +353 -0
- package/src/wallet/Bcmr.test.ts +610 -0
- package/src/wallet/Bcmr.ts +390 -0
- package/src/wallet/Cashtokens.test.headless.js +467 -0
- package/src/wallet/Cashtokens.test.ts +475 -0
- package/src/wallet/Slp.test.headless.js +6 -8
- package/src/wallet/Slp.test.ts +2 -2
- package/src/wallet/Slp.ts +26 -22
- package/src/wallet/Util.ts +9 -20
- package/src/wallet/Wif.test.ts +20 -21
- package/src/wallet/Wif.ts +534 -99
- package/src/wallet/bcmr-v1.schema.ts +639 -0
- package/src/wallet/createWallet.test.ts +1 -0
- package/src/wallet/createWallet.ts +4 -4
- package/src/wallet/interface.ts +9 -6
- package/src/wallet/model.ts +190 -19
- package/src/webhook/Webhook.ts +7 -3
- package/src/webhook/WebhookBch.ts +7 -7
- package/src/webhook/WebhookSlp.test.ts +2 -2
- package/src/webhook/WebhookSlp.ts +6 -6
- package/src/webhook/WebhookWorker.ts +2 -2
- package/src/webhook/index.ts +5 -5
- package/tsconfig.browser.json +0 -3
- package/tsconfig.json +17 -5
- package/{webpack.config.js → webpack.config.cjs} +46 -14
- package/dist/main/chain.d.ts +0 -3
- package/dist/main/chain.js +0 -7
- package/dist/main/chain.js.map +0 -1
- package/dist/main/cli.d.ts +0 -1
- package/dist/main/cli.js +0 -35
- package/dist/main/cli.js.map +0 -1
- package/dist/main/constant.d.ts +0 -5
- package/dist/main/constant.js +0 -27
- package/dist/main/constant.js.map +0 -1
- package/dist/main/db/ExchangeRateProvider.d.ts +0 -11
- package/dist/main/db/ExchangeRateProvider.js +0 -47
- package/dist/main/db/ExchangeRateProvider.js.map +0 -1
- package/dist/main/db/IndexedDBProvider.d.ts +0 -15
- package/dist/main/db/IndexedDBProvider.js +0 -86
- package/dist/main/db/IndexedDBProvider.js.map +0 -1
- package/dist/main/db/SqlProvider.d.ts +0 -41
- package/dist/main/db/SqlProvider.js +0 -217
- package/dist/main/db/SqlProvider.js.map +0 -1
- package/dist/main/db/StorageProvider.d.ts +0 -52
- package/dist/main/db/StorageProvider.js +0 -3
- package/dist/main/db/StorageProvider.js.map +0 -1
- package/dist/main/db/index.d.ts +0 -3
- package/dist/main/db/index.js +0 -11
- package/dist/main/db/index.js.map +0 -1
- package/dist/main/db/interface.d.ts +0 -22
- package/dist/main/db/interface.js +0 -3
- package/dist/main/db/interface.js.map +0 -1
- package/dist/main/db/util.d.ts +0 -5
- package/dist/main/db/util.js +0 -53
- package/dist/main/db/util.js.map +0 -1
- package/dist/main/enum.d.ts +0 -33
- package/dist/main/enum.js +0 -39
- package/dist/main/enum.js.map +0 -1
- package/dist/main/history/electrumTransformer.d.ts +0 -4
- package/dist/main/history/electrumTransformer.js +0 -216
- package/dist/main/history/electrumTransformer.js.map +0 -1
- package/dist/main/history/interface.d.ts +0 -16
- package/dist/main/history/interface.js +0 -3
- package/dist/main/history/interface.js.map +0 -1
- package/dist/main/index.d.ts +0 -24
- package/dist/main/index.js +0 -62
- package/dist/main/index.js.map +0 -1
- package/dist/main/interface.d.ts +0 -31
- package/dist/main/interface.js +0 -12
- package/dist/main/interface.js.map +0 -1
- package/dist/main/message/index.d.ts +0 -2
- package/dist/main/message/index.js +0 -15
- package/dist/main/message/index.js.map +0 -1
- package/dist/main/message/interface.d.ts +0 -29
- package/dist/main/message/interface.js +0 -6
- package/dist/main/message/interface.js.map +0 -1
- package/dist/main/message/signed.d.ts +0 -33
- package/dist/main/message/signed.js +0 -141
- package/dist/main/message/signed.js.map +0 -1
- package/dist/main/mine/index.d.ts +0 -1
- package/dist/main/mine/index.js +0 -14
- package/dist/main/mine/index.js.map +0 -1
- package/dist/main/mine/mine.d.ts +0 -13
- package/dist/main/mine/mine.js +0 -37
- package/dist/main/mine/mine.js.map +0 -1
- package/dist/main/network/Connection.d.ts +0 -14
- package/dist/main/network/Connection.js +0 -71
- package/dist/main/network/Connection.js.map +0 -1
- package/dist/main/network/ElectrumNetworkProvider.d.ts +0 -49
- package/dist/main/network/ElectrumNetworkProvider.js +0 -338
- package/dist/main/network/ElectrumNetworkProvider.js.map +0 -1
- package/dist/main/network/NetworkProvider.d.ts +0 -107
- package/dist/main/network/NetworkProvider.js +0 -3
- package/dist/main/network/NetworkProvider.js.map +0 -1
- package/dist/main/network/configuration.d.ts +0 -12
- package/dist/main/network/configuration.js +0 -79
- package/dist/main/network/configuration.js.map +0 -1
- package/dist/main/network/constant.d.ts +0 -35
- package/dist/main/network/constant.js +0 -55
- package/dist/main/network/constant.js.map +0 -1
- package/dist/main/network/default.d.ts +0 -7
- package/dist/main/network/default.js +0 -107
- package/dist/main/network/default.js.map +0 -1
- package/dist/main/network/getRelayFeeCache.d.ts +0 -2
- package/dist/main/network/getRelayFeeCache.js +0 -27
- package/dist/main/network/getRelayFeeCache.js.map +0 -1
- package/dist/main/network/index.d.ts +0 -2
- package/dist/main/network/index.js +0 -10
- package/dist/main/network/index.js.map +0 -1
- package/dist/main/network/interface.d.ts +0 -60
- package/dist/main/network/interface.js +0 -3
- package/dist/main/network/interface.js.map +0 -1
- package/dist/main/network/util.d.ts +0 -2
- package/dist/main/network/util.js +0 -32
- package/dist/main/network/util.js.map +0 -1
- package/dist/main/qr/Qr.d.ts +0 -8
- package/dist/main/qr/Qr.js +0 -26
- package/dist/main/qr/Qr.js.map +0 -1
- package/dist/main/qr/interface.d.ts +0 -5
- package/dist/main/qr/interface.js +0 -3
- package/dist/main/qr/interface.js.map +0 -1
- package/dist/main/rate/ExchangeRate.d.ts +0 -19
- package/dist/main/rate/ExchangeRate.js +0 -147
- package/dist/main/rate/ExchangeRate.js.map +0 -1
- package/dist/main/slp/GsppProvider.d.ts +0 -54
- package/dist/main/slp/GsppProvider.js +0 -214
- package/dist/main/slp/GsppProvider.js.map +0 -1
- package/dist/main/slp/SlpDbProvider.d.ts +0 -51
- package/dist/main/slp/SlpDbProvider.js +0 -182
- package/dist/main/slp/SlpDbProvider.js.map +0 -1
- package/dist/main/slp/SlpDbTemplates.d.ts +0 -312
- package/dist/main/slp/SlpDbTemplates.js +0 -387
- package/dist/main/slp/SlpDbTemplates.js.map +0 -1
- package/dist/main/slp/SlpLibAuth.d.ts +0 -217
- package/dist/main/slp/SlpLibAuth.js +0 -452
- package/dist/main/slp/SlpLibAuth.js.map +0 -1
- package/dist/main/slp/SlpProvider.d.ts +0 -23
- package/dist/main/slp/SlpProvider.js +0 -39
- package/dist/main/slp/SlpProvider.js.map +0 -1
- package/dist/main/slp/index.d.ts +0 -5
- package/dist/main/slp/index.js +0 -24
- package/dist/main/slp/index.js.map +0 -1
- package/dist/main/slp/interface.d.ts +0 -113
- package/dist/main/slp/interface.js +0 -10
- package/dist/main/slp/interface.js.map +0 -1
- package/dist/main/test/expect.d.ts +0 -7
- package/dist/main/test/expect.js +0 -31
- package/dist/main/test/expect.js.map +0 -1
- package/dist/main/transaction/Wif.d.ts +0 -42
- package/dist/main/transaction/Wif.js +0 -214
- package/dist/main/transaction/Wif.js.map +0 -1
- package/dist/main/transaction/allocateFee.d.ts +0 -7
- package/dist/main/transaction/allocateFee.js +0 -118
- package/dist/main/transaction/allocateFee.js.map +0 -1
- package/dist/main/util/amountInSatoshi.d.ts +0 -9
- package/dist/main/util/amountInSatoshi.js +0 -38
- package/dist/main/util/amountInSatoshi.js.map +0 -1
- package/dist/main/util/asSendRequestObject.d.ts +0 -2
- package/dist/main/util/asSendRequestObject.js +0 -57
- package/dist/main/util/asSendRequestObject.js.map +0 -1
- package/dist/main/util/balanceObjectFromSatoshi.d.ts +0 -8
- package/dist/main/util/balanceObjectFromSatoshi.js +0 -62
- package/dist/main/util/balanceObjectFromSatoshi.js.map +0 -1
- package/dist/main/util/base64.d.ts +0 -2
- package/dist/main/util/base64.js +0 -36
- package/dist/main/util/base64.js.map +0 -1
- package/dist/main/util/bchaddr.d.ts +0 -1
- package/dist/main/util/bchaddr.js +0 -24
- package/dist/main/util/bchaddr.js.map +0 -1
- package/dist/main/util/browserNotSupported.d.ts +0 -1
- package/dist/main/util/browserNotSupported.js +0 -11
- package/dist/main/util/browserNotSupported.js.map +0 -1
- package/dist/main/util/checkForEmptySeed.d.ts +0 -2
- package/dist/main/util/checkForEmptySeed.js +0 -12
- package/dist/main/util/checkForEmptySeed.js.map +0 -1
- package/dist/main/util/checkWifNetwork.d.ts +0 -2
- package/dist/main/util/checkWifNetwork.js +0 -16
- package/dist/main/util/checkWifNetwork.js.map +0 -1
- package/dist/main/util/convert.d.ts +0 -15
- package/dist/main/util/convert.js +0 -24
- package/dist/main/util/convert.js.map +0 -1
- package/dist/main/util/delay.d.ts +0 -1
- package/dist/main/util/delay.js +0 -8
- package/dist/main/util/delay.js.map +0 -1
- package/dist/main/util/deriveCashaddr.d.ts +0 -2
- package/dist/main/util/deriveCashaddr.js +0 -13
- package/dist/main/util/deriveCashaddr.js.map +0 -1
- package/dist/main/util/deriveLockscript.d.ts +0 -8
- package/dist/main/util/deriveLockscript.js +0 -19
- package/dist/main/util/deriveLockscript.js.map +0 -1
- package/dist/main/util/deriveNetwork.d.ts +0 -1
- package/dist/main/util/deriveNetwork.js +0 -23
- package/dist/main/util/deriveNetwork.js.map +0 -1
- package/dist/main/util/derivePublicKeyHash.d.ts +0 -16
- package/dist/main/util/derivePublicKeyHash.js +0 -49
- package/dist/main/util/derivePublicKeyHash.js.map +0 -1
- package/dist/main/util/eventsource.d.ts +0 -2
- package/dist/main/util/eventsource.js +0 -12
- package/dist/main/util/eventsource.js.map +0 -1
- package/dist/main/util/floor.d.ts +0 -1
- package/dist/main/util/floor.js +0 -9
- package/dist/main/util/floor.js.map +0 -1
- package/dist/main/util/getAddrsByXpubKey.d.ts +0 -22
- package/dist/main/util/getAddrsByXpubKey.js +0 -79
- package/dist/main/util/getAddrsByXpubKey.js.map +0 -1
- package/dist/main/util/getRuntimePlatform.d.ts +0 -6
- package/dist/main/util/getRuntimePlatform.js +0 -34
- package/dist/main/util/getRuntimePlatform.js.map +0 -1
- package/dist/main/util/getUsdRate.d.ts +0 -1
- package/dist/main/util/getUsdRate.js +0 -9
- package/dist/main/util/getUsdRate.js.map +0 -1
- package/dist/main/util/getXPubKey.d.ts +0 -1
- package/dist/main/util/getXPubKey.js +0 -26
- package/dist/main/util/getXPubKey.js.map +0 -1
- package/dist/main/util/hash160.d.ts +0 -8
- package/dist/main/util/hash160.js +0 -18
- package/dist/main/util/hash160.js.map +0 -1
- package/dist/main/util/index.d.ts +0 -21
- package/dist/main/util/index.js +0 -72
- package/dist/main/util/index.js.map +0 -1
- package/dist/main/util/randomBytes.d.ts +0 -1
- package/dist/main/util/randomBytes.js +0 -18
- package/dist/main/util/randomBytes.js.map +0 -1
- package/dist/main/util/randomInt.d.ts +0 -1
- package/dist/main/util/randomInt.js +0 -9
- package/dist/main/util/randomInt.js.map +0 -1
- package/dist/main/util/randomValues.d.ts +0 -1
- package/dist/main/util/randomValues.js +0 -15
- package/dist/main/util/randomValues.js.map +0 -1
- package/dist/main/util/sanitizeAddress.d.ts +0 -1
- package/dist/main/util/sanitizeAddress.js +0 -15
- package/dist/main/util/sanitizeAddress.js.map +0 -1
- package/dist/main/util/sanitizeUnit.d.ts +0 -2
- package/dist/main/util/sanitizeUnit.js +0 -13
- package/dist/main/util/sanitizeUnit.js.map +0 -1
- package/dist/main/util/satoshiToAmount.d.ts +0 -9
- package/dist/main/util/satoshiToAmount.js +0 -41
- package/dist/main/util/satoshiToAmount.js.map +0 -1
- package/dist/main/util/sumSendRequestAmounts.d.ts +0 -2
- package/dist/main/util/sumSendRequestAmounts.js +0 -31
- package/dist/main/util/sumSendRequestAmounts.js.map +0 -1
- package/dist/main/util/sumUtxoValue.d.ts +0 -2
- package/dist/main/util/sumUtxoValue.js +0 -17
- package/dist/main/util/sumUtxoValue.js.map +0 -1
- package/dist/main/wallet/Base.d.ts +0 -202
- package/dist/main/wallet/Base.js +0 -438
- package/dist/main/wallet/Base.js.map +0 -1
- package/dist/main/wallet/Slp.d.ts +0 -430
- package/dist/main/wallet/Slp.js +0 -775
- package/dist/main/wallet/Slp.js.map +0 -1
- package/dist/main/wallet/Util.d.ts +0 -69
- package/dist/main/wallet/Util.js +0 -182
- package/dist/main/wallet/Util.js.map +0 -1
- package/dist/main/wallet/Wif.d.ts +0 -255
- package/dist/main/wallet/Wif.js +0 -1067
- package/dist/main/wallet/Wif.js.map +0 -1
- package/dist/main/wallet/createWallet.d.ts +0 -69
- package/dist/main/wallet/createWallet.js +0 -244
- package/dist/main/wallet/createWallet.js.map +0 -1
- package/dist/main/wallet/enum.d.ts +0 -16
- package/dist/main/wallet/enum.js +0 -22
- package/dist/main/wallet/enum.js.map +0 -1
- package/dist/main/wallet/interface.d.ts +0 -76
- package/dist/main/wallet/interface.js +0 -3
- package/dist/main/wallet/interface.js.map +0 -1
- package/dist/main/wallet/model.d.ts +0 -88
- package/dist/main/wallet/model.js +0 -129
- package/dist/main/wallet/model.js.map +0 -1
- package/dist/main/webhook/Webhook.d.ts +0 -40
- package/dist/main/webhook/Webhook.js +0 -82
- package/dist/main/webhook/Webhook.js.map +0 -1
- package/dist/main/webhook/WebhookBch.d.ts +0 -13
- package/dist/main/webhook/WebhookBch.js +0 -148
- package/dist/main/webhook/WebhookBch.js.map +0 -1
- package/dist/main/webhook/WebhookSlp.d.ts +0 -14
- package/dist/main/webhook/WebhookSlp.js +0 -107
- package/dist/main/webhook/WebhookSlp.js.map +0 -1
- package/dist/main/webhook/WebhookWorker.d.ts +0 -22
- package/dist/main/webhook/WebhookWorker.js +0 -100
- package/dist/main/webhook/WebhookWorker.js.map +0 -1
- package/dist/main/webhook/index.d.ts +0 -5
- package/dist/main/webhook/index.js +0 -23
- package/dist/main/webhook/index.js.map +0 -1
- package/dist/main/webhook/interface.d.ts +0 -8
- package/dist/main/webhook/interface.js +0 -3
- package/dist/main/webhook/interface.js.map +0 -1
- package/dist/mainnet-0.5.9.js +0 -2
- package/dist/mainnet-0.5.9.js.LICENSE.txt +0 -48
- package/dist/tsconfig.browser.tsbuildinfo +0 -1
- package/jest.config.js +0 -23
package/src/transaction/Wif.ts
CHANGED
|
@@ -2,34 +2,41 @@
|
|
|
2
2
|
import {
|
|
3
3
|
authenticationTemplateP2pkhNonHd,
|
|
4
4
|
authenticationTemplateToCompilerBCH,
|
|
5
|
-
bigIntToBinUint64LEClamped,
|
|
6
5
|
cashAddressToLockingBytecode,
|
|
7
6
|
Compiler,
|
|
8
7
|
encodeTransaction,
|
|
9
8
|
generateTransaction,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
importAuthenticationTemplate,
|
|
10
|
+
AnyCompilerConfiguration,
|
|
11
|
+
AuthenticationProgramStateCommon,
|
|
12
|
+
CompilationContextBCH,
|
|
13
|
+
Output,
|
|
14
|
+
hexToBin,
|
|
15
|
+
binToHex,
|
|
14
16
|
} from "@bitauth/libauth";
|
|
15
|
-
import { UtxoI } from "../interface";
|
|
16
|
-
import { allocateFee } from "./allocateFee";
|
|
17
|
+
import { NFTCapability, TokenI, UtxoI } from "../interface.js";
|
|
18
|
+
import { allocateFee } from "./allocateFee.js";
|
|
17
19
|
|
|
18
|
-
import { DUST_UTXO_THRESHOLD } from "../constant";
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
import { DUST_UTXO_THRESHOLD } from "../constant.js";
|
|
21
|
+
import {
|
|
22
|
+
OpReturnData,
|
|
23
|
+
SendRequest,
|
|
24
|
+
SendRequestType,
|
|
25
|
+
TokenSendRequest,
|
|
26
|
+
} from "../wallet/model.js";
|
|
27
|
+
import { amountInSatoshi } from "../util/amountInSatoshi.js";
|
|
28
|
+
import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
|
|
29
|
+
import { sumUtxoValue } from "../util/sumUtxoValue.js";
|
|
30
|
+
import { FeePaidByEnum } from "../wallet/enum.js";
|
|
24
31
|
|
|
25
32
|
// Build a transaction for a p2pkh transaction for a non HD wallet
|
|
26
33
|
export async function buildP2pkhNonHdTransaction(
|
|
27
34
|
inputs: UtxoI[],
|
|
28
|
-
outputs: Array<SendRequest | OpReturnData>,
|
|
35
|
+
outputs: Array<SendRequest | TokenSendRequest | OpReturnData>,
|
|
29
36
|
signingKey: Uint8Array,
|
|
30
37
|
fee: number = 0,
|
|
31
38
|
discardChange = false,
|
|
32
|
-
slpOutputs:
|
|
39
|
+
slpOutputs: Output[] = [],
|
|
33
40
|
feePaidBy: FeePaidByEnum = FeePaidByEnum.change,
|
|
34
41
|
changeAddress: string = ""
|
|
35
42
|
) {
|
|
@@ -37,7 +44,7 @@ export async function buildP2pkhNonHdTransaction(
|
|
|
37
44
|
throw new Error("Missing signing key when building transaction");
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
const template =
|
|
47
|
+
const template = importAuthenticationTemplate(
|
|
41
48
|
authenticationTemplateP2pkhNonHd
|
|
42
49
|
);
|
|
43
50
|
if (typeof template === "string") {
|
|
@@ -49,53 +56,52 @@ export async function buildP2pkhNonHdTransaction(
|
|
|
49
56
|
|
|
50
57
|
const sendAmount = await sumSendRequestAmounts(outputs);
|
|
51
58
|
|
|
52
|
-
|
|
53
|
-
const changeAmount = BigInt(inputAmount) - BigInt(sendAmount) - BigInt(fee);
|
|
59
|
+
const changeAmount = BigInt(inputAmount) - BigInt(sendAmount) - BigInt(fee);
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
outputs = allocateFee(outputs, fee, feePaidBy, changeAmount);
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
let lockedOutputs = await prepareOutputs(outputs, inputs);
|
|
58
64
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if (discardChange !== true) {
|
|
66
|
+
if (changeAmount > DUST_UTXO_THRESHOLD) {
|
|
67
|
+
let changeLockingBytecode;
|
|
68
|
+
if (changeAddress) {
|
|
69
|
+
changeLockingBytecode = cashAddressToLockingBytecode(changeAddress);
|
|
70
|
+
} else {
|
|
71
|
+
// Get the change locking bytecode
|
|
72
|
+
changeLockingBytecode = compiler.generateBytecode({
|
|
73
|
+
scriptId: "lock",
|
|
74
|
+
data: {
|
|
67
75
|
keys: { privateKeys: { key: signingKey } },
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (typeof changeLockingBytecode === "string") {
|
|
71
|
-
throw new Error(changeLockingBytecode);
|
|
72
|
-
}
|
|
73
|
-
lockedOutputs.push({
|
|
74
|
-
lockingBytecode: changeLockingBytecode.bytecode,
|
|
75
|
-
satoshis: bigIntToBinUint64LEClamped(BigInt(changeAmount)),
|
|
76
|
+
},
|
|
76
77
|
});
|
|
77
78
|
}
|
|
79
|
+
if (typeof changeLockingBytecode === "string") {
|
|
80
|
+
throw new Error(changeLockingBytecode);
|
|
81
|
+
}
|
|
82
|
+
lockedOutputs.push({
|
|
83
|
+
lockingBytecode: changeLockingBytecode.bytecode,
|
|
84
|
+
valueSatoshis: BigInt(changeAmount),
|
|
85
|
+
});
|
|
78
86
|
}
|
|
79
|
-
|
|
80
|
-
let signedInputs = prepareInputs(inputs, compiler, signingKey);
|
|
81
|
-
const result = generateTransaction({
|
|
82
|
-
inputs: signedInputs,
|
|
83
|
-
locktime: 0,
|
|
84
|
-
outputs: [...slpOutputs, ...lockedOutputs],
|
|
85
|
-
version: 2,
|
|
86
|
-
});
|
|
87
|
-
return result;
|
|
88
|
-
} catch (error: any) {
|
|
89
|
-
throw Error(error.toString());
|
|
90
87
|
}
|
|
88
|
+
|
|
89
|
+
let signedInputs = prepareInputs(inputs, compiler, signingKey);
|
|
90
|
+
const result = generateTransaction({
|
|
91
|
+
inputs: signedInputs,
|
|
92
|
+
locktime: 0,
|
|
93
|
+
outputs: [...slpOutputs, ...lockedOutputs],
|
|
94
|
+
version: 2,
|
|
95
|
+
});
|
|
96
|
+
return result;
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
export function prepareInputs(
|
|
94
100
|
inputs: UtxoI[],
|
|
95
101
|
compiler: Compiler<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
CompilationContextBCH,
|
|
103
|
+
AnyCompilerConfiguration<CompilationContextBCH>,
|
|
104
|
+
AuthenticationProgramStateCommon
|
|
99
105
|
>,
|
|
100
106
|
signingKey: Uint8Array
|
|
101
107
|
) {
|
|
@@ -112,6 +118,18 @@ export function prepareInputs(
|
|
|
112
118
|
if (!utxoOutpointTransactionHash || utxoIndex === undefined) {
|
|
113
119
|
throw new Error("Missing unspent outpoint when building transaction");
|
|
114
120
|
}
|
|
121
|
+
|
|
122
|
+
const libAuthToken = i.token && {
|
|
123
|
+
amount: BigInt(i.token.amount),
|
|
124
|
+
category: hexToBin(i.token.tokenId),
|
|
125
|
+
nft:
|
|
126
|
+
i.token.capability || i.token.commitment
|
|
127
|
+
? {
|
|
128
|
+
capability: i.token.capability,
|
|
129
|
+
commitment: i.token.commitment && hexToBin(i.token.commitment!),
|
|
130
|
+
}
|
|
131
|
+
: undefined,
|
|
132
|
+
};
|
|
115
133
|
let newInput = {
|
|
116
134
|
outpointIndex: utxoIndex,
|
|
117
135
|
outpointTransactionHash: utxoOutpointTransactionHash,
|
|
@@ -121,8 +139,9 @@ export function prepareInputs(
|
|
|
121
139
|
data: {
|
|
122
140
|
keys: { privateKeys: { key: signingKey } },
|
|
123
141
|
},
|
|
124
|
-
|
|
142
|
+
valueSatoshis: BigInt(utxoTxnValue),
|
|
125
143
|
script: "unlock",
|
|
144
|
+
token: libAuthToken,
|
|
126
145
|
},
|
|
127
146
|
};
|
|
128
147
|
signedInputs.push(newInput);
|
|
@@ -138,37 +157,34 @@ export function prepareInputs(
|
|
|
138
157
|
* @returns A promise to a list of unspent outputs
|
|
139
158
|
*/
|
|
140
159
|
export async function prepareOutputs(
|
|
141
|
-
outputs: Array<SendRequest | OpReturnData
|
|
160
|
+
outputs: Array<SendRequest | TokenSendRequest | OpReturnData>,
|
|
161
|
+
inputs: UtxoI[]
|
|
142
162
|
) {
|
|
143
|
-
let lockedOutputs:
|
|
163
|
+
let lockedOutputs: Output[] = [];
|
|
144
164
|
for (const output of outputs) {
|
|
145
|
-
if (output instanceof
|
|
146
|
-
lockedOutputs.push(
|
|
165
|
+
if (output instanceof TokenSendRequest) {
|
|
166
|
+
lockedOutputs.push(prepareTokenOutputs(output, inputs));
|
|
147
167
|
continue;
|
|
148
168
|
}
|
|
149
169
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
!outputLockingBytecode.hasOwnProperty("prefix")
|
|
154
|
-
) {
|
|
155
|
-
throw new Error(outputLockingBytecode.toString());
|
|
170
|
+
if (output instanceof OpReturnData) {
|
|
171
|
+
lockedOutputs.push(prepareOpReturnOutput(output));
|
|
172
|
+
continue;
|
|
156
173
|
}
|
|
157
174
|
|
|
158
|
-
outputLockingBytecode =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
175
|
+
const outputLockingBytecode = cashAddressToLockingBytecode(output.cashaddr);
|
|
176
|
+
if (typeof outputLockingBytecode === "string")
|
|
177
|
+
throw new Error(outputLockingBytecode);
|
|
162
178
|
|
|
163
|
-
|
|
179
|
+
const sendAmount = await amountInSatoshi(output.value, output.unit);
|
|
164
180
|
if (sendAmount % 1 !== 0) {
|
|
165
181
|
throw Error(
|
|
166
182
|
`Cannot send ${sendAmount} satoshis, (fractional sats do not exist, yet), please use an integer number.`
|
|
167
183
|
);
|
|
168
184
|
}
|
|
169
|
-
|
|
185
|
+
const lockedOutput: Output = {
|
|
170
186
|
lockingBytecode: outputLockingBytecode.bytecode,
|
|
171
|
-
|
|
187
|
+
valueSatoshis: BigInt(sendAmount),
|
|
172
188
|
};
|
|
173
189
|
lockedOutputs.push(lockedOutput);
|
|
174
190
|
}
|
|
@@ -180,11 +196,80 @@ export async function prepareOutputs(
|
|
|
180
196
|
*
|
|
181
197
|
* @returns A promise to a list of unspent outputs
|
|
182
198
|
*/
|
|
183
|
-
export function prepareOpReturnOutput(request: OpReturnData) {
|
|
199
|
+
export function prepareOpReturnOutput(request: OpReturnData): Output {
|
|
184
200
|
return {
|
|
185
201
|
lockingBytecode: request.buffer,
|
|
186
|
-
|
|
202
|
+
valueSatoshis: BigInt(0),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* prepareOpReturnOutput - create an output for token data
|
|
208
|
+
*
|
|
209
|
+
* @returns A libauth Output
|
|
210
|
+
*/
|
|
211
|
+
export function prepareTokenOutputs(
|
|
212
|
+
request: TokenSendRequest,
|
|
213
|
+
inputs: UtxoI[]
|
|
214
|
+
): Output {
|
|
215
|
+
const token: TokenI = request;
|
|
216
|
+
const isGenesis = !request.tokenId || (request as any)._isGenesis;
|
|
217
|
+
let satValue = 0;
|
|
218
|
+
if (isGenesis) {
|
|
219
|
+
const genesisInputs = inputs.filter((val) => val.vout === 0);
|
|
220
|
+
if (genesisInputs.length === 0) {
|
|
221
|
+
throw new Error(
|
|
222
|
+
"No suitable inputs with vout=0 available for new token genesis"
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
token.tokenId = genesisInputs[0].txid;
|
|
226
|
+
satValue = request.value || 1000;
|
|
227
|
+
(request as any)._isGenesis = true;
|
|
228
|
+
} else {
|
|
229
|
+
const tokenInputs = inputs.filter(
|
|
230
|
+
(val) => val.token?.tokenId === request.tokenId
|
|
231
|
+
);
|
|
232
|
+
if (!tokenInputs.length) {
|
|
233
|
+
throw new Error(`No token utxos available to send ${request.tokenId}`);
|
|
234
|
+
}
|
|
235
|
+
if (!token.capability && tokenInputs[0].token?.capability) {
|
|
236
|
+
token.capability = tokenInputs[0].token!.capability;
|
|
237
|
+
}
|
|
238
|
+
if (!token.commitment && tokenInputs[0].token?.commitment) {
|
|
239
|
+
token.commitment = tokenInputs[0].token!.commitment;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (
|
|
243
|
+
token.capability === NFTCapability.none &&
|
|
244
|
+
token.commitment !== tokenInputs[0].token?.commitment
|
|
245
|
+
) {
|
|
246
|
+
throw new Error("Can not change the commitment of an immutable token");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
satValue = request.value || tokenInputs[0].satoshis;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let outputLockingBytecode = cashAddressToLockingBytecode(request.cashaddr);
|
|
253
|
+
if (typeof outputLockingBytecode === "string")
|
|
254
|
+
throw new Error(outputLockingBytecode);
|
|
255
|
+
|
|
256
|
+
const libAuthToken = {
|
|
257
|
+
amount: BigInt(token.amount),
|
|
258
|
+
category: hexToBin(token.tokenId),
|
|
259
|
+
nft:
|
|
260
|
+
token.capability || token.commitment
|
|
261
|
+
? {
|
|
262
|
+
capability: token.capability,
|
|
263
|
+
commitment: token.commitment && hexToBin(token.commitment!),
|
|
264
|
+
}
|
|
265
|
+
: undefined,
|
|
187
266
|
};
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
lockingBytecode: outputLockingBytecode.bytecode,
|
|
270
|
+
valueSatoshis: BigInt(satValue),
|
|
271
|
+
token: libAuthToken,
|
|
272
|
+
} as Output;
|
|
188
273
|
}
|
|
189
274
|
|
|
190
275
|
/**
|
|
@@ -197,14 +282,55 @@ export function prepareOpReturnOutput(request: OpReturnData) {
|
|
|
197
282
|
* @returns A promise to a list of unspent outputs
|
|
198
283
|
*/
|
|
199
284
|
export async function getSuitableUtxos(
|
|
200
|
-
|
|
285
|
+
inputs: UtxoI[],
|
|
201
286
|
amountRequired: BigInt | undefined,
|
|
202
287
|
bestHeight: number,
|
|
203
|
-
feePaidBy: FeePaidByEnum
|
|
288
|
+
feePaidBy: FeePaidByEnum,
|
|
289
|
+
requests: SendRequestType[]
|
|
204
290
|
): Promise<UtxoI[]> {
|
|
205
291
|
let suitableUtxos: UtxoI[] = [];
|
|
206
292
|
let amountAvailable = BigInt(0);
|
|
207
|
-
|
|
293
|
+
const tokenAmountsRequired: any[] = [];
|
|
294
|
+
const tokenRequests = requests.filter(
|
|
295
|
+
(val) => val instanceof TokenSendRequest
|
|
296
|
+
) as TokenSendRequest[];
|
|
297
|
+
const tokenIds = tokenRequests
|
|
298
|
+
.map((val) => val.tokenId)
|
|
299
|
+
.filter((value, index, array) => array.indexOf(value) === index);
|
|
300
|
+
for (let tokenId of tokenIds) {
|
|
301
|
+
const requiredAmount = tokenRequests
|
|
302
|
+
.map((val) => val.amount)
|
|
303
|
+
.reduce((prev, cur) => prev + cur, 0);
|
|
304
|
+
tokenAmountsRequired.push({ tokenId, requiredAmount });
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
let filteredInputs = inputs.slice(0);
|
|
308
|
+
|
|
309
|
+
// find suitable token inputs first
|
|
310
|
+
for (const { tokenId, requiredAmount } of tokenAmountsRequired) {
|
|
311
|
+
let tokenAmountAvailable = 0;
|
|
312
|
+
for (const input of inputs) {
|
|
313
|
+
if (input.token?.tokenId === tokenId) {
|
|
314
|
+
suitableUtxos.push(input);
|
|
315
|
+
const inputIndex = filteredInputs.indexOf(input);
|
|
316
|
+
filteredInputs = filteredInputs.filter(
|
|
317
|
+
(_, index) => inputIndex !== index
|
|
318
|
+
);
|
|
319
|
+
tokenAmountAvailable += input.token!.amount;
|
|
320
|
+
amountAvailable += BigInt(input.satoshis);
|
|
321
|
+
if (tokenAmountAvailable >= requiredAmount) {
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// find plain outputs
|
|
329
|
+
for (const u of filteredInputs) {
|
|
330
|
+
if (u.token) {
|
|
331
|
+
// continue;
|
|
332
|
+
}
|
|
333
|
+
|
|
208
334
|
if (u.coinbase && u.height && bestHeight) {
|
|
209
335
|
let age = bestHeight - u.height;
|
|
210
336
|
if (age > 100) {
|
|
@@ -252,10 +378,10 @@ export async function getFeeAmount({
|
|
|
252
378
|
feePaidBy,
|
|
253
379
|
}: {
|
|
254
380
|
utxos: UtxoI[];
|
|
255
|
-
sendRequests: Array<SendRequest | OpReturnData>;
|
|
381
|
+
sendRequests: Array<SendRequest | TokenSendRequest | OpReturnData>;
|
|
256
382
|
privateKey: Uint8Array;
|
|
257
383
|
relayFeePerByteInSatoshi: number;
|
|
258
|
-
slpOutputs:
|
|
384
|
+
slpOutputs: Output[];
|
|
259
385
|
feePaidBy: FeePaidByEnum;
|
|
260
386
|
}) {
|
|
261
387
|
// build transaction
|
|
@@ -282,11 +408,11 @@ export async function getFeeAmount({
|
|
|
282
408
|
// Build encoded transaction
|
|
283
409
|
export async function buildEncodedTransaction(
|
|
284
410
|
fundingUtxos: UtxoI[],
|
|
285
|
-
sendRequests: Array<SendRequest | OpReturnData>,
|
|
411
|
+
sendRequests: Array<SendRequest | TokenSendRequest | OpReturnData>,
|
|
286
412
|
privateKey: Uint8Array,
|
|
287
413
|
fee: number = 0,
|
|
288
414
|
discardChange = false,
|
|
289
|
-
slpOutputs:
|
|
415
|
+
slpOutputs: Output[] = [],
|
|
290
416
|
feePaidBy: FeePaidByEnum = FeePaidByEnum.change,
|
|
291
417
|
changeAddress: string = ""
|
|
292
418
|
) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import {
|
|
2
|
+
OpReturnData,
|
|
3
|
+
SendRequest,
|
|
4
|
+
TokenSendRequest,
|
|
5
|
+
} from "../wallet/model.js";
|
|
6
|
+
import { FeePaidByEnum } from "../wallet/enum.js";
|
|
7
|
+
import { DUST_UTXO_THRESHOLD } from "../constant.js";
|
|
4
8
|
|
|
5
9
|
export function checkFeeForDust(value: number) {
|
|
6
10
|
if (value < DUST_UTXO_THRESHOLD) {
|
|
@@ -20,12 +24,17 @@ export function checkSatsAvailable(
|
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
export function
|
|
24
|
-
output: SendRequest | OpReturnData
|
|
27
|
+
export function checkForNonStandardSendRequest(
|
|
28
|
+
output: SendRequest | TokenSendRequest | OpReturnData
|
|
25
29
|
): SendRequest {
|
|
30
|
+
if (output instanceof TokenSendRequest) {
|
|
31
|
+
throw Error("Cannot specify fee to be paid by TokenSendRequest");
|
|
32
|
+
}
|
|
33
|
+
|
|
26
34
|
if (output instanceof OpReturnData) {
|
|
27
35
|
throw Error("Cannot specify fee to be paid by OpReturnData");
|
|
28
36
|
}
|
|
37
|
+
|
|
29
38
|
return output;
|
|
30
39
|
}
|
|
31
40
|
|
|
@@ -40,7 +49,7 @@ function distributeFees(requests: Array<SendRequest>, fee: number) {
|
|
|
40
49
|
fee = Number(fee);
|
|
41
50
|
for (let r = 0; r < requests.length; r++) {
|
|
42
51
|
if (fee > 0) {
|
|
43
|
-
|
|
52
|
+
checkForNonStandardSendRequest(requests[r]);
|
|
44
53
|
let perRequestFee = Math.floor(fee / (requests.length - r));
|
|
45
54
|
perRequestFee += fee % (requests.length - r);
|
|
46
55
|
if (requests[r].value - perRequestFee < DUST_UTXO_THRESHOLD) {
|
|
@@ -55,25 +64,34 @@ function distributeFees(requests: Array<SendRequest>, fee: number) {
|
|
|
55
64
|
return requests.filter((r) => r.value >= DUST_UTXO_THRESHOLD);
|
|
56
65
|
}
|
|
57
66
|
|
|
58
|
-
function firstPays(
|
|
67
|
+
function firstPays(
|
|
68
|
+
requests: Array<SendRequest | TokenSendRequest | OpReturnData>,
|
|
69
|
+
fee: number
|
|
70
|
+
) {
|
|
59
71
|
let payer = requests.shift()!;
|
|
60
|
-
payer =
|
|
72
|
+
payer = checkForNonStandardSendRequest(payer);
|
|
61
73
|
payer.value = payer.value! - fee;
|
|
62
74
|
checkFeeForDust(payer.value);
|
|
63
75
|
requests.unshift(payer);
|
|
64
76
|
return requests;
|
|
65
77
|
}
|
|
66
|
-
function lastPays(
|
|
78
|
+
function lastPays(
|
|
79
|
+
requests: Array<SendRequest | TokenSendRequest | OpReturnData>,
|
|
80
|
+
fee: number
|
|
81
|
+
) {
|
|
67
82
|
let payer = requests.pop()!;
|
|
68
|
-
payer =
|
|
83
|
+
payer = checkForNonStandardSendRequest(payer);
|
|
69
84
|
payer.value = payer.value! - fee;
|
|
70
85
|
checkFeeForDust(payer.value);
|
|
71
86
|
requests.push(payer);
|
|
72
87
|
return requests;
|
|
73
88
|
}
|
|
74
|
-
function anyPays(
|
|
89
|
+
function anyPays(
|
|
90
|
+
requests: Array<SendRequest | TokenSendRequest | OpReturnData>,
|
|
91
|
+
fee: number
|
|
92
|
+
) {
|
|
75
93
|
for (let r of requests) {
|
|
76
|
-
|
|
94
|
+
checkForNonStandardSendRequest(r);
|
|
77
95
|
}
|
|
78
96
|
requests = sortSendRequests(requests as Array<SendRequest>);
|
|
79
97
|
requests = distributeFees(requests as Array<SendRequest>, fee);
|
|
@@ -81,7 +99,7 @@ function anyPays(requests: Array<SendRequest | OpReturnData>, fee: number) {
|
|
|
81
99
|
}
|
|
82
100
|
|
|
83
101
|
function changeThenFallback(
|
|
84
|
-
requests: Array<SendRequest | OpReturnData>,
|
|
102
|
+
requests: Array<SendRequest | TokenSendRequest | OpReturnData>,
|
|
85
103
|
fee: number,
|
|
86
104
|
change: bigint,
|
|
87
105
|
fallbackFn: Function
|
|
@@ -94,7 +112,7 @@ function changeThenFallback(
|
|
|
94
112
|
}
|
|
95
113
|
|
|
96
114
|
export function allocateFee(
|
|
97
|
-
requests: Array<SendRequest | OpReturnData>,
|
|
115
|
+
requests: Array<SendRequest | TokenSendRequest | OpReturnData>,
|
|
98
116
|
fee: number,
|
|
99
117
|
feePaidBy: FeePaidByEnum,
|
|
100
118
|
change: bigint
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { bchParam } from "../chain";
|
|
2
|
-
import { UnitEnum } from "../enum";
|
|
3
|
-
import { ExchangeRate } from "../rate/ExchangeRate";
|
|
4
|
-
import { sanitizeUnit } from "../util/sanitizeUnit";
|
|
1
|
+
import { bchParam } from "../chain.js";
|
|
2
|
+
import { UnitEnum } from "../enum.js";
|
|
3
|
+
import { ExchangeRate } from "../rate/ExchangeRate.js";
|
|
4
|
+
import { sanitizeUnit } from "../util/sanitizeUnit.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* converts given value and unit into satoshi
|
|
@@ -1,51 +1,63 @@
|
|
|
1
1
|
import { base64ToBin } from "@bitauth/libauth";
|
|
2
|
-
import { UnitEnum } from "../enum";
|
|
3
|
-
import {
|
|
2
|
+
import { UnitEnum } from "../enum.js";
|
|
3
|
+
import {
|
|
4
|
+
OpReturnData,
|
|
5
|
+
SendRequest,
|
|
6
|
+
SendRequestArray,
|
|
7
|
+
TokenSendRequest,
|
|
8
|
+
} from "../wallet/model.js";
|
|
4
9
|
|
|
5
10
|
export function asSendRequestObject(
|
|
6
11
|
requests:
|
|
7
12
|
| SendRequest
|
|
13
|
+
| TokenSendRequest
|
|
8
14
|
| OpReturnData
|
|
9
|
-
| Array<SendRequest | OpReturnData>
|
|
15
|
+
| Array<SendRequest | TokenSendRequest | OpReturnData>
|
|
10
16
|
| Array<SendRequestArray>
|
|
11
|
-
): Array<SendRequest | OpReturnData> {
|
|
12
|
-
let resp: Array<SendRequest | OpReturnData> = [];
|
|
17
|
+
): Array<SendRequest | TokenSendRequest | OpReturnData> {
|
|
18
|
+
let resp: Array<SendRequest | TokenSendRequest | OpReturnData> = [];
|
|
13
19
|
if (Array.isArray(requests)) {
|
|
14
|
-
requests.forEach(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (r
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
requests.forEach(
|
|
21
|
+
(r: SendRequest | TokenSendRequest | OpReturnData | SendRequestArray) => {
|
|
22
|
+
// the SendRequestArray[] case
|
|
23
|
+
if (Array.isArray(r)) {
|
|
24
|
+
if (r[0] === "OP_RETURN") {
|
|
25
|
+
// ['OP_RETURN', Buffer.new('MEMO\x10')],
|
|
26
|
+
resp.push(OpReturnData.from(r[1] as string | Buffer));
|
|
27
|
+
} else if (r[0] === "OP_RETURNB64") {
|
|
28
|
+
resp.push(
|
|
29
|
+
OpReturnData.fromBuffer(Buffer.from(base64ToBin(r[1] as string)))
|
|
30
|
+
);
|
|
31
|
+
} else {
|
|
32
|
+
// ['cashaddr', 120, 'sats'],
|
|
33
|
+
resp.push(
|
|
34
|
+
new SendRequest({
|
|
35
|
+
cashaddr: r[0] as string,
|
|
36
|
+
value: r[1] as number,
|
|
37
|
+
unit: r[2] as UnitEnum,
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
}
|
|
24
41
|
} else {
|
|
25
|
-
//
|
|
26
|
-
resp.push(
|
|
27
|
-
new SendRequest({
|
|
28
|
-
cashaddr: r[0] as string,
|
|
29
|
-
value: r[1] as number,
|
|
30
|
-
unit: r[2] as UnitEnum,
|
|
31
|
-
})
|
|
32
|
-
);
|
|
42
|
+
// SendRequest | TokenSendRequest | OpReturnRequest case
|
|
43
|
+
resp.push(convertToClass(r));
|
|
33
44
|
}
|
|
34
|
-
} else {
|
|
35
|
-
// SendRequest | OpReturnRequest case
|
|
36
|
-
resp.push(convertToClass(r));
|
|
37
45
|
}
|
|
38
|
-
|
|
46
|
+
);
|
|
39
47
|
} else {
|
|
40
48
|
// the SendRequest | OpReturnData object case
|
|
41
|
-
resp.push(
|
|
49
|
+
resp.push(
|
|
50
|
+
convertToClass(requests as SendRequest | TokenSendRequest | OpReturnData)
|
|
51
|
+
);
|
|
42
52
|
}
|
|
43
53
|
return resp;
|
|
44
54
|
}
|
|
45
55
|
|
|
46
|
-
function convertToClass(object: SendRequest | OpReturnData) {
|
|
47
|
-
if (object.hasOwnProperty("
|
|
56
|
+
function convertToClass(object: SendRequest | TokenSendRequest | OpReturnData) {
|
|
57
|
+
if (object.hasOwnProperty("unit")) {
|
|
48
58
|
return new SendRequest(object as SendRequest);
|
|
59
|
+
} else if (object.hasOwnProperty("tokenId")) {
|
|
60
|
+
return new TokenSendRequest(object as TokenSendRequest);
|
|
49
61
|
} else if (object.hasOwnProperty("buffer")) {
|
|
50
62
|
return OpReturnData.fromBuffer((object as OpReturnData).buffer);
|
|
51
63
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { bchParam } from "../chain";
|
|
2
|
-
import { UnitEnum } from "../enum";
|
|
3
|
-
import { floor } from "./floor";
|
|
4
|
-
import { ExchangeRate } from "../rate/ExchangeRate";
|
|
5
|
-
import { sanitizeUnit } from "./sanitizeUnit";
|
|
1
|
+
import { bchParam } from "../chain.js";
|
|
2
|
+
import { UnitEnum } from "../enum.js";
|
|
3
|
+
import { floor } from "./floor.js";
|
|
4
|
+
import { ExchangeRate } from "../rate/ExchangeRate.js";
|
|
5
|
+
import { sanitizeUnit } from "./sanitizeUnit.js";
|
|
6
6
|
|
|
7
7
|
export class BalanceResponse {
|
|
8
8
|
bch?: number;
|
package/src/util/base64.ts
CHANGED
|
@@ -1,31 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { base64ToBin, binToBase64, isBase64 } from "@bitauth/libauth";
|
|
2
2
|
|
|
3
3
|
export function btoa(data: string) {
|
|
4
|
-
|
|
5
|
-
return globalThis.btoa(data);
|
|
6
|
-
} else {
|
|
7
|
-
const btoa = (str: any) => {
|
|
8
|
-
var buffer;
|
|
9
|
-
|
|
10
|
-
if (str instanceof Buffer) {
|
|
11
|
-
buffer = str;
|
|
12
|
-
} else {
|
|
13
|
-
buffer = Buffer.from(str.toString(), "binary");
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return buffer.toString("base64");
|
|
17
|
-
};
|
|
18
|
-
return btoa(data);
|
|
19
|
-
}
|
|
4
|
+
return binToBase64(new TextEncoder().encode(data));
|
|
20
5
|
}
|
|
21
6
|
|
|
22
7
|
export function atob(data: string) {
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
} else {
|
|
26
|
-
const atob = (str: string) => {
|
|
27
|
-
return Buffer.from(str, "base64").toString("binary");
|
|
28
|
-
};
|
|
29
|
-
return atob(data);
|
|
8
|
+
if (!isBase64(data)) {
|
|
9
|
+
throw new Error("Provided data is not a valid base64");
|
|
30
10
|
}
|
|
11
|
+
return String.fromCharCode(...base64ToBin(data));
|
|
31
12
|
}
|
package/src/util/convert.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { amountInSatoshi } from "./amountInSatoshi";
|
|
2
|
-
import { satoshiToAmount } from "./satoshiToAmount";
|
|
1
|
+
import { amountInSatoshi } from "./amountInSatoshi.js";
|
|
2
|
+
import { satoshiToAmount } from "./satoshiToAmount.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* convert transforms unit of measurement for some monetary value
|