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,43 @@
|
|
|
1
|
+
import { RegTestWallet, Wallet } from "../wallet/Wif";
|
|
2
|
+
import {
|
|
3
|
+
deriveCashaddr,
|
|
4
|
+
deriveTokenaddr,
|
|
5
|
+
isTokenaddr,
|
|
6
|
+
toCashaddr,
|
|
7
|
+
toTokenaddr,
|
|
8
|
+
} from "./deriveCashaddr";
|
|
9
|
+
|
|
10
|
+
test("Should derive cashaddr", async () => {
|
|
11
|
+
const wallet = await Wallet.newRandom();
|
|
12
|
+
expect(deriveCashaddr(wallet.privateKey!, wallet.networkPrefix)).toBe(
|
|
13
|
+
wallet.cashaddr!
|
|
14
|
+
);
|
|
15
|
+
expect(deriveTokenaddr(wallet.privateKey!, wallet.networkPrefix)).toBe(
|
|
16
|
+
wallet.tokenaddr!
|
|
17
|
+
);
|
|
18
|
+
expect(deriveTokenaddr(wallet.publicKey!, wallet.networkPrefix)).toBe(
|
|
19
|
+
wallet.tokenaddr!
|
|
20
|
+
);
|
|
21
|
+
expect(
|
|
22
|
+
deriveTokenaddr(wallet.publicKeyCompressed!, wallet.networkPrefix)
|
|
23
|
+
).toBe(wallet.tokenaddr!);
|
|
24
|
+
expect(deriveTokenaddr(wallet.publicKeyHash!, wallet.networkPrefix)).toBe(
|
|
25
|
+
wallet.tokenaddr!
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("Test address conversion", async () => {
|
|
30
|
+
const wallet = await RegTestWallet.watchOnly(process.env.ADDRESS!);
|
|
31
|
+
expect(toTokenaddr(wallet.cashaddr!)).toBe(wallet.tokenaddr);
|
|
32
|
+
expect(toCashaddr(wallet.tokenaddr!)).toBe(wallet.cashaddr);
|
|
33
|
+
|
|
34
|
+
expect(toCashaddr(wallet.tokenaddr!)).toBe(
|
|
35
|
+
"bchreg:qpttdv3qg2usm4nm7talhxhl05mlhms3ys43u76rn0"
|
|
36
|
+
);
|
|
37
|
+
expect(toTokenaddr(wallet.cashaddr!)).toBe(
|
|
38
|
+
"bchreg:zpttdv3qg2usm4nm7talhxhl05mlhms3ysjm0q59vu"
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(isTokenaddr(wallet.cashaddr!)).toBe(false);
|
|
42
|
+
expect(isTokenaddr(wallet.tokenaddr!)).toBe(true);
|
|
43
|
+
});
|
|
@@ -1,17 +1,133 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CashAddressNetworkPrefix,
|
|
3
|
-
instantiateSecp256k1,
|
|
4
3
|
encodeCashAddress,
|
|
4
|
+
CashAddressType,
|
|
5
|
+
secp256k1,
|
|
6
|
+
decodeCashAddressFormat,
|
|
7
|
+
decodeCashAddressFormatWithoutPrefix,
|
|
8
|
+
CashAddressVersionByte,
|
|
5
9
|
} from "@bitauth/libauth";
|
|
6
10
|
|
|
7
|
-
import { hash160 } from "./hash160";
|
|
11
|
+
import { hash160 } from "./hash160.js";
|
|
8
12
|
|
|
9
|
-
export
|
|
13
|
+
export function deriveCashaddr(
|
|
10
14
|
privateKey: Uint8Array,
|
|
11
15
|
networkPrefix: CashAddressNetworkPrefix
|
|
12
|
-
) {
|
|
13
|
-
const secp256k1 = await instantiateSecp256k1();
|
|
16
|
+
): string {
|
|
14
17
|
let publicKey = secp256k1.derivePublicKeyCompressed(privateKey);
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
if (typeof publicKey === "string") {
|
|
19
|
+
throw new Error(publicKey);
|
|
20
|
+
}
|
|
21
|
+
let pkh = hash160(publicKey);
|
|
22
|
+
return encodeCashAddress(networkPrefix, CashAddressType.p2pkh, pkh);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function deriveTokenaddr(
|
|
26
|
+
key: Uint8Array,
|
|
27
|
+
networkPrefix: CashAddressNetworkPrefix
|
|
28
|
+
): string {
|
|
29
|
+
let publicKeyHash: Uint8Array;
|
|
30
|
+
// private key
|
|
31
|
+
if (key.length === 32) {
|
|
32
|
+
let publicKeyCompressed = secp256k1.derivePublicKeyCompressed(key);
|
|
33
|
+
if (typeof publicKeyCompressed === "string") {
|
|
34
|
+
throw new Error(publicKeyCompressed);
|
|
35
|
+
}
|
|
36
|
+
publicKeyHash = hash160(publicKeyCompressed);
|
|
37
|
+
} else if (key.length === 65) {
|
|
38
|
+
// uncompressed public key
|
|
39
|
+
let publicKeyCompressed = secp256k1.compressPublicKey(key);
|
|
40
|
+
if (typeof publicKeyCompressed === "string") {
|
|
41
|
+
throw new Error(publicKeyCompressed);
|
|
42
|
+
}
|
|
43
|
+
publicKeyHash = hash160(publicKeyCompressed);
|
|
44
|
+
} else if (key.length === 33) {
|
|
45
|
+
// compressed public key
|
|
46
|
+
publicKeyHash = hash160(key);
|
|
47
|
+
} else if (key.length === 20) {
|
|
48
|
+
// public key hash
|
|
49
|
+
publicKeyHash = key;
|
|
50
|
+
} else {
|
|
51
|
+
throw new Error("Unsupported type of key");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return encodeCashAddress(
|
|
55
|
+
networkPrefix,
|
|
56
|
+
CashAddressType.p2pkhWithTokens,
|
|
57
|
+
publicKeyHash
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function toCashaddr(tokenaddr: string): string {
|
|
62
|
+
let result:
|
|
63
|
+
| string
|
|
64
|
+
| { payload: Uint8Array; prefix: string; version: number }
|
|
65
|
+
| undefined;
|
|
66
|
+
|
|
67
|
+
// If the address has a prefix decode it as is
|
|
68
|
+
if (tokenaddr.includes(":")) {
|
|
69
|
+
result = decodeCashAddressFormat(tokenaddr);
|
|
70
|
+
}
|
|
71
|
+
// otherwise, derive the network from the tokenaddr without prefix
|
|
72
|
+
else {
|
|
73
|
+
result = decodeCashAddressFormatWithoutPrefix(tokenaddr);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof result === "string") throw new Error(result);
|
|
77
|
+
|
|
78
|
+
return encodeCashAddress(
|
|
79
|
+
result.prefix as CashAddressNetworkPrefix,
|
|
80
|
+
CashAddressType.p2pkh,
|
|
81
|
+
result.payload
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function toTokenaddr(cashaddr: string): string {
|
|
86
|
+
let result:
|
|
87
|
+
| string
|
|
88
|
+
| { payload: Uint8Array; prefix: string; version: number }
|
|
89
|
+
| undefined;
|
|
90
|
+
|
|
91
|
+
// If the address has a prefix decode it as is
|
|
92
|
+
if (cashaddr.includes(":")) {
|
|
93
|
+
result = decodeCashAddressFormat(cashaddr);
|
|
94
|
+
}
|
|
95
|
+
// otherwise, derive the network from the cashaddr without prefix
|
|
96
|
+
else {
|
|
97
|
+
result = decodeCashAddressFormatWithoutPrefix(cashaddr);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (typeof result === "string") throw new Error(result);
|
|
101
|
+
|
|
102
|
+
return encodeCashAddress(
|
|
103
|
+
result.prefix as CashAddressNetworkPrefix,
|
|
104
|
+
CashAddressType.p2pkhWithTokens,
|
|
105
|
+
result.payload
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function isTokenaddr(address: string): boolean {
|
|
110
|
+
let result:
|
|
111
|
+
| string
|
|
112
|
+
| { payload: Uint8Array; prefix: string; version: number }
|
|
113
|
+
| undefined;
|
|
114
|
+
|
|
115
|
+
// If the address has a prefix decode it as is
|
|
116
|
+
if (address.includes(":")) {
|
|
117
|
+
result = decodeCashAddressFormat(address);
|
|
118
|
+
}
|
|
119
|
+
// otherwise, derive the network from the address without prefix
|
|
120
|
+
else {
|
|
121
|
+
result = decodeCashAddressFormatWithoutPrefix(address);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (typeof result === "string") throw new Error(result);
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
[
|
|
128
|
+
CashAddressVersionByte.p2pkhWithTokens,
|
|
129
|
+
CashAddressVersionByte.p2sh20WithTokens,
|
|
130
|
+
CashAddressVersionByte.p2sh32WithTokens,
|
|
131
|
+
].indexOf(result.version) !== -1
|
|
132
|
+
);
|
|
17
133
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { derivePrefix } from "./derivePublicKeyHash";
|
|
2
|
-
import { networkPrefixMap } from "../enum";
|
|
1
|
+
import { derivePrefix } from "./derivePublicKeyHash.js";
|
|
2
|
+
import { networkPrefixMap } from "../enum.js";
|
|
3
3
|
|
|
4
4
|
// This function if for assuring that a list of addresses are on the name network
|
|
5
5
|
// for a single address use: networkPrefixMap[derivePrefix(address)]
|
|
@@ -43,6 +43,9 @@ test("Should calculate public key hash consistent with hash160", async () => {
|
|
|
43
43
|
let pkh = derivePublicKeyHash(w.getDepositAddress());
|
|
44
44
|
// manually from compressed public key
|
|
45
45
|
let publicKeyCompressed = secp256k1.derivePublicKeyCompressed(w.privateKey!);
|
|
46
|
+
if (typeof publicKeyCompressed === "string") {
|
|
47
|
+
throw new Error(publicKeyCompressed);
|
|
48
|
+
}
|
|
46
49
|
let pkh2 = ripemd160.hash(sha256.hash(publicKeyCompressed));
|
|
47
50
|
let pkh3 = w.publicKeyHash!;
|
|
48
51
|
expect(pkh2.length).toBe(20);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CashAddressNetworkPrefix,
|
|
2
3
|
decodeCashAddressFormat,
|
|
3
4
|
decodeCashAddressFormatWithoutPrefix,
|
|
4
5
|
} from "@bitauth/libauth";
|
|
@@ -11,7 +12,13 @@ import {
|
|
|
11
12
|
* @returns a public key hash corresponding to the passed address
|
|
12
13
|
*/
|
|
13
14
|
export function derivePublicKeyHash(address: string): Uint8Array {
|
|
14
|
-
let result
|
|
15
|
+
let result:
|
|
16
|
+
| string
|
|
17
|
+
| {
|
|
18
|
+
payload: Uint8Array;
|
|
19
|
+
prefix: string;
|
|
20
|
+
version: number;
|
|
21
|
+
};
|
|
15
22
|
|
|
16
23
|
// If the address has a prefix decode it as is
|
|
17
24
|
if (address.includes(":")) {
|
|
@@ -25,7 +32,7 @@ export function derivePublicKeyHash(address: string): Uint8Array {
|
|
|
25
32
|
if (typeof result === "string") throw new Error(result);
|
|
26
33
|
|
|
27
34
|
// return the public key hash
|
|
28
|
-
return result.
|
|
35
|
+
return result.payload;
|
|
29
36
|
}
|
|
30
37
|
|
|
31
38
|
/**
|
|
@@ -35,8 +42,14 @@ export function derivePublicKeyHash(address: string): Uint8Array {
|
|
|
35
42
|
*
|
|
36
43
|
* @returns the address prefix
|
|
37
44
|
*/
|
|
38
|
-
export function derivePrefix(address: string):
|
|
39
|
-
let result
|
|
45
|
+
export function derivePrefix(address: string): CashAddressNetworkPrefix {
|
|
46
|
+
let result:
|
|
47
|
+
| string
|
|
48
|
+
| {
|
|
49
|
+
payload: Uint8Array;
|
|
50
|
+
prefix: string;
|
|
51
|
+
version: number;
|
|
52
|
+
};
|
|
40
53
|
|
|
41
54
|
if (address.includes(":")) {
|
|
42
55
|
result = decodeCashAddressFormat(address);
|
|
@@ -47,5 +60,5 @@ export function derivePrefix(address: string): string {
|
|
|
47
60
|
if (typeof result === "string") throw new Error(result);
|
|
48
61
|
|
|
49
62
|
// TODO pass the network in and check it or raise Error
|
|
50
|
-
return result.prefix;
|
|
63
|
+
return result.prefix as CashAddressNetworkPrefix;
|
|
51
64
|
}
|
package/src/util/eventsource.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { getRuntimePlatform } from "./getRuntimePlatform";
|
|
1
|
+
import { getRuntimePlatform } from "./getRuntimePlatform.js";
|
|
2
|
+
|
|
3
|
+
import { default as ES } from "eventsource";
|
|
2
4
|
|
|
3
5
|
let EventSource;
|
|
4
6
|
if (getRuntimePlatform() != "node") {
|
|
5
7
|
EventSource = globalThis.EventSource;
|
|
6
8
|
} else {
|
|
7
|
-
EventSource =
|
|
9
|
+
EventSource = ES;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export default EventSource;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
test("Should decode xpubInfo", async () => {
|
|
8
8
|
let xpub =
|
|
9
9
|
"xpub6BosfCnifzxcFwrSzQiqu2DBVTshkCXacvNsWGYJVVhhawA7d4R5WSWGFNbi8Aw6ZRc1brxMyWMzG3DSSSSoekkudhUd9yLb6qx39T9nMdj";
|
|
10
|
-
let xpubInfo =
|
|
10
|
+
let xpubInfo = getXpubKeyInfo(xpub);
|
|
11
11
|
expect(xpubInfo.version).toBe("mainnet");
|
|
12
12
|
expect(xpubInfo.depth).toBe(3);
|
|
13
13
|
expect(xpubInfo.parentFingerprint).toBe("155bca59");
|
|
@@ -57,7 +57,7 @@ test("Should derive list of cashaddrs from m/44'/0'/0' given xpub path, & limit"
|
|
|
57
57
|
];
|
|
58
58
|
|
|
59
59
|
// M/44'/0'/0'/0/i
|
|
60
|
-
const cashaddrs =
|
|
60
|
+
const cashaddrs = getAddrsByXpubKey(xpub, "0/0", 3);
|
|
61
61
|
expect(cashaddrs).toStrictEqual(vectors);
|
|
62
62
|
});
|
|
63
63
|
|
|
@@ -76,7 +76,7 @@ test("Should derive list of change cashaddrs from m/44'/0'/0' given xpub path, &
|
|
|
76
76
|
];
|
|
77
77
|
|
|
78
78
|
// M/44'/0'/0'/0/i
|
|
79
|
-
const cashaddrs =
|
|
79
|
+
const cashaddrs = getAddrsByXpubKey(xpub, "1/0", 3);
|
|
80
80
|
expect(cashaddrs).toStrictEqual(vectors);
|
|
81
81
|
});
|
|
82
82
|
|
|
@@ -94,7 +94,7 @@ test("Should derive list of cashaddrs from M/44'/145'/0' given xpub, path and li
|
|
|
94
94
|
"bitcoincash:qqkuy34ntrye9a2h4xpdstcu4aq5wfrwscjtaphenr",
|
|
95
95
|
];
|
|
96
96
|
|
|
97
|
-
const cashaddrs =
|
|
97
|
+
const cashaddrs = getAddrsByXpubKey(xpub, "0/0", 3);
|
|
98
98
|
expect(cashaddrs).toStrictEqual(vectors);
|
|
99
99
|
});
|
|
100
100
|
test("Should derive list of change cashaddrs from M/44'/145'/0' given xpub, path and limit", async () => {
|
|
@@ -110,6 +110,6 @@ test("Should derive list of change cashaddrs from M/44'/145'/0' given xpub, path
|
|
|
110
110
|
// M/44'/145'/0'/1/2
|
|
111
111
|
"bitcoincash:qp57cex47jtyhedphe2c63gpzsx3zs0ryvejxly47d",
|
|
112
112
|
];
|
|
113
|
-
const cashaddrs =
|
|
113
|
+
const cashaddrs = getAddrsByXpubKey(xpub, "1/0", 3);
|
|
114
114
|
expect(cashaddrs).toStrictEqual(vectors);
|
|
115
115
|
});
|
|
@@ -1,23 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
deriveHdPublicNodeChild,
|
|
3
3
|
decodeHdPublicKey,
|
|
4
|
-
encodeHdPublicKey,
|
|
5
4
|
encodeCashAddress,
|
|
6
|
-
instantiateBIP32Crypto,
|
|
7
5
|
deriveHdPath,
|
|
8
|
-
HdPublicNode,
|
|
9
|
-
HdKeyNetwork,
|
|
10
6
|
binToHex,
|
|
7
|
+
CashAddressNetworkPrefix,
|
|
8
|
+
CashAddressType,
|
|
11
9
|
} from "@bitauth/libauth";
|
|
12
|
-
import path from "path";
|
|
13
10
|
|
|
14
|
-
import { hash160 } from "./hash160";
|
|
11
|
+
import { hash160 } from "./hash160.js";
|
|
15
12
|
|
|
16
|
-
export
|
|
13
|
+
export function getAddrsByXpubKey(
|
|
17
14
|
xpub: string,
|
|
18
15
|
path: string,
|
|
19
16
|
count: number
|
|
20
|
-
) {
|
|
17
|
+
): Array<string> {
|
|
21
18
|
let pathComponents = path.split("/");
|
|
22
19
|
let rootStr = pathComponents.shift()!;
|
|
23
20
|
let root: number;
|
|
@@ -25,7 +22,7 @@ export async function getAddrsByXpubKey(
|
|
|
25
22
|
rootStr = pathComponents.shift()!;
|
|
26
23
|
}
|
|
27
24
|
root = parseInt(rootStr);
|
|
28
|
-
let result:
|
|
25
|
+
let result: Array<string> = [];
|
|
29
26
|
|
|
30
27
|
const start = parseInt(pathComponents.pop()!);
|
|
31
28
|
const end = start + count;
|
|
@@ -33,29 +30,28 @@ export async function getAddrsByXpubKey(
|
|
|
33
30
|
let childPath = ["M", root, ...pathComponents, curr].join("/");
|
|
34
31
|
result.push(derivePublicNodeCashaddr(xpub, root, childPath));
|
|
35
32
|
}
|
|
36
|
-
return
|
|
37
|
-
return result;
|
|
38
|
-
});
|
|
33
|
+
return result;
|
|
39
34
|
}
|
|
40
35
|
|
|
41
|
-
export
|
|
42
|
-
return
|
|
36
|
+
export function getAddrsByXpubKeyObject(obj): Array<string> {
|
|
37
|
+
return getAddrsByXpubKey(obj.xpubkey, obj.path, obj.count);
|
|
43
38
|
}
|
|
44
39
|
|
|
45
|
-
export
|
|
40
|
+
export function derivePublicNodeCashaddr(
|
|
46
41
|
xpub,
|
|
47
42
|
index: number,
|
|
48
43
|
path?: string
|
|
49
|
-
) {
|
|
50
|
-
const
|
|
51
|
-
const publicParent = await decodeHdPublicKey(crypto, xpub);
|
|
44
|
+
): string {
|
|
45
|
+
const publicParent = decodeHdPublicKey(xpub);
|
|
52
46
|
|
|
53
47
|
if (typeof publicParent === "string") {
|
|
54
48
|
throw new Error(publicParent);
|
|
55
49
|
}
|
|
56
|
-
let prefix =
|
|
50
|
+
let prefix = (
|
|
51
|
+
publicParent.network === "mainnet" ? "bitcoincash" : "bchtest"
|
|
52
|
+
) as CashAddressNetworkPrefix;
|
|
57
53
|
|
|
58
|
-
let node =
|
|
54
|
+
let node = deriveHdPublicNodeChild(publicParent.node, index);
|
|
59
55
|
if (typeof node === "string") {
|
|
60
56
|
throw new Error(node);
|
|
61
57
|
}
|
|
@@ -65,20 +61,19 @@ export async function derivePublicNodeCashaddr(
|
|
|
65
61
|
if (path[0] !== "M") {
|
|
66
62
|
throw Error("use M for public path derivation");
|
|
67
63
|
}
|
|
68
|
-
let childNode = deriveHdPath(
|
|
64
|
+
let childNode = deriveHdPath(publicParent.node, path);
|
|
69
65
|
if (typeof childNode === "string") {
|
|
70
66
|
throw new Error(childNode);
|
|
71
67
|
} else {
|
|
72
|
-
let childPkh =
|
|
73
|
-
cashaddr = encodeCashAddress(prefix,
|
|
68
|
+
let childPkh = hash160(childNode.publicKey);
|
|
69
|
+
cashaddr = encodeCashAddress(prefix, CashAddressType.p2pkh, childPkh);
|
|
74
70
|
}
|
|
75
71
|
}
|
|
76
72
|
return cashaddr;
|
|
77
73
|
}
|
|
78
74
|
|
|
79
|
-
export
|
|
80
|
-
|
|
81
|
-
let node = decodeHdPublicKey(crypto, hdPublicKey);
|
|
75
|
+
export function getXpubKeyInfo(hdPublicKey: string) {
|
|
76
|
+
let node = decodeHdPublicKey(hdPublicKey);
|
|
82
77
|
if (typeof node === "string") {
|
|
83
78
|
throw new Error(node);
|
|
84
79
|
}
|
|
@@ -89,10 +84,10 @@ export async function getXpubKeyInfo(hdPublicKey) {
|
|
|
89
84
|
childNumber: node.node.childIndex,
|
|
90
85
|
chain: binToHex(node.node.chainCode),
|
|
91
86
|
data: binToHex(node.node.publicKey),
|
|
92
|
-
fingerprint: binToHex(
|
|
87
|
+
fingerprint: binToHex(hash160(node.node.publicKey).slice(0, 4)),
|
|
93
88
|
};
|
|
94
89
|
}
|
|
95
90
|
|
|
96
91
|
export async function getXpubKeyInfoObject(obj) {
|
|
97
|
-
return
|
|
92
|
+
return getXpubKeyInfo(obj.xpubkey);
|
|
98
93
|
}
|
package/src/util/getUsdRate.ts
CHANGED
package/src/util/getXPubKey.ts
CHANGED
|
@@ -4,11 +4,10 @@ import {
|
|
|
4
4
|
deriveHdPublicNode,
|
|
5
5
|
encodeHdPublicKey,
|
|
6
6
|
HdKeyNetwork,
|
|
7
|
-
instantiateBIP32Crypto,
|
|
8
7
|
hexToBin,
|
|
9
8
|
} from "@bitauth/libauth";
|
|
10
9
|
|
|
11
|
-
export
|
|
10
|
+
export function getXPubKey(
|
|
12
11
|
seed: Uint8Array | string,
|
|
13
12
|
derivationPath: string,
|
|
14
13
|
network: string
|
|
@@ -16,19 +15,18 @@ export async function getXPubKey(
|
|
|
16
15
|
if (typeof seed === "string") {
|
|
17
16
|
seed = hexToBin(seed);
|
|
18
17
|
}
|
|
19
|
-
|
|
20
|
-
let hdNode = deriveHdPrivateNodeFromSeed(crypto, seed);
|
|
18
|
+
let hdNode = deriveHdPrivateNodeFromSeed(seed);
|
|
21
19
|
if (!hdNode.valid) {
|
|
22
20
|
throw Error("Invalid private key derived from mnemonic seed");
|
|
23
21
|
}
|
|
24
22
|
|
|
25
|
-
let node = deriveHdPath(
|
|
23
|
+
let node = deriveHdPath(hdNode, derivationPath);
|
|
26
24
|
if (typeof node === "string") {
|
|
27
25
|
throw node;
|
|
28
26
|
}
|
|
29
|
-
let parentPublicNode = deriveHdPublicNode(
|
|
27
|
+
let parentPublicNode = deriveHdPublicNode(node);
|
|
30
28
|
|
|
31
|
-
let xPubKey = encodeHdPublicKey(
|
|
29
|
+
let xPubKey = encodeHdPublicKey({
|
|
32
30
|
network: network as HdKeyNetwork,
|
|
33
31
|
node: parentPublicNode,
|
|
34
32
|
});
|
package/src/util/hash160.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { hexToBin } from "@bitauth/libauth";
|
|
|
3
3
|
|
|
4
4
|
test("Should calculate the correct hash from a publicKey", async () => {
|
|
5
5
|
let pk = "02d531ce83a065cdc342b1e709106741bb070ea7aaec29d012f2dba956b9027675";
|
|
6
|
-
let pkh =
|
|
6
|
+
let pkh = hash160(hexToBin(pk));
|
|
7
7
|
expect(pkh).toStrictEqual(
|
|
8
8
|
hexToBin("e8f538181a07625fc5b2194ea9fa3815f42900a2")
|
|
9
9
|
);
|
|
@@ -11,7 +11,7 @@ test("Should calculate the correct hash from a publicKey", async () => {
|
|
|
11
11
|
|
|
12
12
|
test("Should calculate the correct hash from a publicKey", async () => {
|
|
13
13
|
let pk = "02b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a8737";
|
|
14
|
-
let pkh =
|
|
14
|
+
let pkh = hash160(hexToBin(pk));
|
|
15
15
|
expect(pkh).toStrictEqual(
|
|
16
16
|
hexToBin("93ce48570b55c42c2af816aeaba06cfee1224fae")
|
|
17
17
|
);
|
package/src/util/hash160.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ripemd160, sha256 } from "@bitauth/libauth";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* hash160 - Calculate the sha256, ripemd160 hash of a value
|
|
@@ -7,8 +7,6 @@ import { instantiateSha256, instantiateRipemd160 } from "@bitauth/libauth";
|
|
|
7
7
|
*
|
|
8
8
|
* @returns a promise to the hash160 value of the input
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
11
|
-
const ripemd160 = await instantiateRipemd160();
|
|
12
|
-
const sha256 = await instantiateSha256();
|
|
10
|
+
export function hash160(message: Uint8Array) {
|
|
13
11
|
return ripemd160.hash(sha256.hash(message));
|
|
14
12
|
}
|
package/src/util/index.ts
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
export { amountInSatoshi } from "./amountInSatoshi";
|
|
2
|
-
export { asSendRequestObject } from "./asSendRequestObject";
|
|
3
|
-
export { atob, btoa } from "./base64";
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export { amountInSatoshi } from "./amountInSatoshi.js";
|
|
2
|
+
export { asSendRequestObject } from "./asSendRequestObject.js";
|
|
3
|
+
export { atob, btoa } from "./base64.js";
|
|
4
|
+
export {
|
|
5
|
+
binToHex,
|
|
6
|
+
hexToBin,
|
|
7
|
+
utf8ToBin,
|
|
8
|
+
binToBase64,
|
|
9
|
+
sha256,
|
|
10
|
+
} from "@bitauth/libauth";
|
|
11
|
+
export { convert, convertObject } from "./convert.js";
|
|
12
|
+
export { delay } from "./delay.js";
|
|
13
|
+
export { derivedNetwork } from "./deriveNetwork.js";
|
|
14
|
+
export { derivePublicKeyHash } from "./derivePublicKeyHash.js";
|
|
9
15
|
export {
|
|
10
16
|
getAddrsByXpubKey,
|
|
11
17
|
getAddrsByXpubKeyObject,
|
|
12
18
|
getXpubKeyInfo,
|
|
13
19
|
getXpubKeyInfoObject,
|
|
14
|
-
} from "../util/getAddrsByXpubKey";
|
|
15
|
-
export { getRuntimePlatform, RuntimePlatform } from "./getRuntimePlatform";
|
|
16
|
-
export { getUsdRate } from "./getUsdRate";
|
|
17
|
-
export { hash160 } from "./hash160";
|
|
18
|
-
export { ExchangeRate } from "../rate/ExchangeRate";
|
|
19
|
-
export { sanitizeAddress } from "./sanitizeAddress";
|
|
20
|
-
export { sanitizeUnit } from "./sanitizeUnit";
|
|
21
|
-
export { getRandomInt } from "./randomInt";
|
|
22
|
-
export { getXPubKey } from "../util/getXPubKey";
|
|
23
|
-
import * as randomValues from "./randomValues";
|
|
20
|
+
} from "../util/getAddrsByXpubKey.js";
|
|
21
|
+
export { getRuntimePlatform, RuntimePlatform } from "./getRuntimePlatform.js";
|
|
22
|
+
export { getUsdRate } from "./getUsdRate.js";
|
|
23
|
+
export { hash160 } from "./hash160.js";
|
|
24
|
+
export { ExchangeRate } from "../rate/ExchangeRate.js";
|
|
25
|
+
export { sanitizeAddress } from "./sanitizeAddress.js";
|
|
26
|
+
export { sanitizeUnit } from "./sanitizeUnit.js";
|
|
27
|
+
export { getRandomInt } from "./randomInt.js";
|
|
28
|
+
export { getXPubKey } from "../util/getXPubKey.js";
|
|
29
|
+
import * as randomValues from "./randomValues.js";
|
|
24
30
|
export { randomValues };
|
|
25
|
-
export { sumUtxoValue } from "./sumUtxoValue";
|
|
31
|
+
export { sumUtxoValue } from "./sumUtxoValue.js";
|
|
26
32
|
export {
|
|
27
33
|
BalanceResponse,
|
|
28
34
|
balanceFromSatoshi,
|
|
29
35
|
balanceResponseFromSatoshi,
|
|
30
|
-
} from "./balanceObjectFromSatoshi";
|
|
36
|
+
} from "./balanceObjectFromSatoshi.js";
|
package/src/util/randomBytes.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { getRuntimePlatform } from "./getRuntimePlatform";
|
|
1
|
+
import { getRuntimePlatform } from "./getRuntimePlatform.js";
|
|
2
|
+
import crypto from "crypto";
|
|
2
3
|
|
|
3
4
|
export function generateRandomBytes(len = 32) {
|
|
4
5
|
// nodejs
|
|
5
6
|
if (getRuntimePlatform() === "node") {
|
|
6
|
-
//
|
|
7
|
-
const crypto = eval("require")("crypto");
|
|
8
7
|
return crypto.randomBytes(len);
|
|
9
8
|
}
|
|
10
9
|
// window, webworkers, service workers
|
package/src/util/randomValues.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { getRuntimePlatform } from "./getRuntimePlatform";
|
|
1
|
+
import { getRuntimePlatform } from "./getRuntimePlatform.js";
|
|
2
|
+
import crypto from "crypto";
|
|
2
3
|
|
|
3
4
|
if (getRuntimePlatform() === "node") {
|
|
4
5
|
if (!globalThis.crypto || !globalThis.crypto.getRandomValues) {
|
|
5
|
-
|
|
6
|
-
globalThis.crypto =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
6
|
+
(globalThis as any).crypto = crypto;
|
|
7
|
+
// (globalThis.crypto as any).getRandomValues = (buf: Uint8Array) => {
|
|
8
|
+
// const bytes = crypto.randomBytes(buf.length);
|
|
9
|
+
// buf.set(bytes);
|
|
10
|
+
// return buf;
|
|
11
|
+
// };
|
|
12
12
|
}
|
|
13
13
|
}
|
package/src/util/sanitizeUnit.ts
CHANGED
|
@@ -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 from satoshi
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
OpReturnData,
|
|
3
|
+
SendRequest,
|
|
4
|
+
TokenSendRequest,
|
|
5
|
+
} from "../wallet/model.js";
|
|
6
|
+
import { amountInSatoshi } from "./amountInSatoshi.js";
|
|
3
7
|
|
|
4
8
|
// This function sums a list of send request objects
|
|
5
9
|
export async function sumSendRequestAmounts(
|
|
6
|
-
requests: Array<SendRequest | OpReturnData>
|
|
10
|
+
requests: Array<SendRequest | TokenSendRequest | OpReturnData>
|
|
7
11
|
) {
|
|
8
12
|
if (requests) {
|
|
9
13
|
const balanceArray: (BigInt | Error)[] = await Promise.all(
|
|
10
|
-
requests.map(async (r: SendRequest | OpReturnData) => {
|
|
14
|
+
requests.map(async (r: SendRequest | TokenSendRequest | OpReturnData) => {
|
|
11
15
|
if (r instanceof SendRequest) {
|
|
12
16
|
return BigInt(await amountInSatoshi(r.value, r.unit));
|
|
17
|
+
} else if (r instanceof TokenSendRequest) {
|
|
18
|
+
return BigInt(r.value || 1000);
|
|
13
19
|
} else return BigInt(0);
|
|
14
20
|
})
|
|
15
21
|
);
|