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/util/sumUtxoValue.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import { UtxoI } from "../interface";
|
|
1
|
+
import { UtxoI } from "../interface.js";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function sumUtxoValue(utxos: UtxoI[]) {
|
|
4
4
|
if (utxos.length > 0) {
|
|
5
|
-
const balanceArray: number[] =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})
|
|
9
|
-
);
|
|
5
|
+
const balanceArray: number[] = utxos.map((o: UtxoI) => {
|
|
6
|
+
return o.satoshis;
|
|
7
|
+
});
|
|
10
8
|
const balance = balanceArray.reduce((a: number, b: number) => a + b, 0);
|
|
11
9
|
return balance;
|
|
12
10
|
} else {
|
|
13
11
|
return 0;
|
|
14
12
|
}
|
|
15
13
|
}
|
|
14
|
+
|
|
15
|
+
export function sumTokenAmounts(utxos: UtxoI[], tokenId: string): number {
|
|
16
|
+
if (utxos.length > 0) {
|
|
17
|
+
const tokenArray: number[] = utxos
|
|
18
|
+
.filter((utxo) => utxo.token?.tokenId === tokenId)
|
|
19
|
+
.map((o: UtxoI) => {
|
|
20
|
+
return o.token?.amount || 0;
|
|
21
|
+
});
|
|
22
|
+
const balance = tokenArray.reduce((a: number, b: number) => a + b, 0);
|
|
23
|
+
return balance;
|
|
24
|
+
} else {
|
|
25
|
+
return 0;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { hexToBin, sha256, binToHex } from "@bitauth/libauth";
|
|
2
|
+
|
|
3
|
+
export async function getTransactionHash(
|
|
4
|
+
rawTransactionHex: string
|
|
5
|
+
): Promise<string> {
|
|
6
|
+
const transactionBin = hexToBin(rawTransactionHex);
|
|
7
|
+
|
|
8
|
+
// transaction hash is a double sha256 of a raw transaction data, reversed byte order
|
|
9
|
+
return binToHex(sha256.hash(sha256.hash(transactionBin)).reverse());
|
|
10
|
+
}
|
package/src/wallet/Base.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { getStorageProvider } from "../db/
|
|
2
|
-
import { MnemonicI, WalletI } from "./interface";
|
|
3
|
-
import { NetworkType } from "../enum";
|
|
4
|
-
import { StorageProvider } from "../db";
|
|
5
|
-
import { getRuntimePlatform } from "../util/getRuntimePlatform";
|
|
6
|
-
import { qrAddress } from "../qr/Qr";
|
|
7
|
-
import { ImageI } from "../qr/interface";
|
|
8
|
-
import { WalletTypeEnum } from "./enum";
|
|
1
|
+
import { getStorageProvider } from "../db/getStorageProvider.js";
|
|
2
|
+
import { MnemonicI, WalletI } from "./interface.js";
|
|
3
|
+
import { NetworkType } from "../enum.js";
|
|
4
|
+
import { StorageProvider } from "../db/index.js";
|
|
5
|
+
import { getRuntimePlatform } from "../util/getRuntimePlatform.js";
|
|
6
|
+
import { qrAddress } from "../qr/Qr.js";
|
|
7
|
+
import { ImageI } from "../qr/interface.js";
|
|
8
|
+
import { WalletTypeEnum } from "./enum.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* A class to hold features used by all wallets
|
|
@@ -54,7 +54,7 @@ export class BaseWallet implements WalletI {
|
|
|
54
54
|
*
|
|
55
55
|
* @see {@link https://rest-unstable.mainnet.cash/api-docs/#/wallet/depositQr|/wallet/deposit_qr} for REST endpoint
|
|
56
56
|
*
|
|
57
|
-
* @returns The qrcode for the
|
|
57
|
+
* @returns The qrcode for the address
|
|
58
58
|
*/
|
|
59
59
|
public getDepositQr(): ImageI {
|
|
60
60
|
return qrAddress(this.getDepositAddress() as string);
|
|
@@ -85,7 +85,7 @@ export class BaseWallet implements WalletI {
|
|
|
85
85
|
* @throws {Error} if called on BaseWallet
|
|
86
86
|
*/
|
|
87
87
|
constructor(
|
|
88
|
-
name = "",
|
|
88
|
+
name: string = "",
|
|
89
89
|
network = NetworkType.Mainnet,
|
|
90
90
|
walletType = WalletTypeEnum.Seed
|
|
91
91
|
) {
|
|
@@ -153,7 +153,7 @@ export class BaseWallet implements WalletI {
|
|
|
153
153
|
* such kind of wallet does not have a private key and is unable to spend any funds
|
|
154
154
|
* however it still allows to use many utility functions such as getting and watching balance, etc.
|
|
155
155
|
*
|
|
156
|
-
* @param address cashaddress or slpaddress of a wallet
|
|
156
|
+
* @param address cashaddress, token aware cashaddress or slpaddress of a wallet
|
|
157
157
|
*
|
|
158
158
|
* @returns instantiated wallet
|
|
159
159
|
*/
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
const playwright = require("playwright");
|
|
2
|
+
const PAGE_URL = "http://localhost:8080";
|
|
3
|
+
|
|
4
|
+
describe(`Wallet should function in the browser`, () => {
|
|
5
|
+
let browser;
|
|
6
|
+
let page;
|
|
7
|
+
|
|
8
|
+
const registry = {
|
|
9
|
+
version: { major: 1, minor: 0, patch: 0 },
|
|
10
|
+
latestRevision: Date.toString(),
|
|
11
|
+
registryIdentity: {
|
|
12
|
+
name: "Test token registry",
|
|
13
|
+
time: { begin: Date.now() },
|
|
14
|
+
token: {
|
|
15
|
+
category:
|
|
16
|
+
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
17
|
+
symbol: "TOK",
|
|
18
|
+
decimals: 8,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create the browser and page context
|
|
25
|
+
*/
|
|
26
|
+
beforeAll(async () => {
|
|
27
|
+
browser = await playwright["chromium"].launch();
|
|
28
|
+
page = await browser.newPage();
|
|
29
|
+
|
|
30
|
+
if (!page) {
|
|
31
|
+
throw new Error("Connection wasn't established");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Open the page
|
|
35
|
+
await page.goto(PAGE_URL, {
|
|
36
|
+
waitUntil: "networkidle0",
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterAll(async () => {
|
|
41
|
+
await browser.close();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("Add metadata registry and get token info", async () => {
|
|
45
|
+
await page.evaluate(
|
|
46
|
+
async ([id, registry]) => {
|
|
47
|
+
expect(
|
|
48
|
+
BCMR.getTokenInfo(
|
|
49
|
+
"0000000000000000000000000000000000000000000000000000000000000000"
|
|
50
|
+
)
|
|
51
|
+
).toBe(undefined);
|
|
52
|
+
BCMR.addMetadataRegistry(registry);
|
|
53
|
+
const tokenInfo = BCMR.getTokenInfo(
|
|
54
|
+
"0000000000000000000000000000000000000000000000000000000000000000"
|
|
55
|
+
);
|
|
56
|
+
expect(tokenInfo?.token?.symbol).toBe("TOK");
|
|
57
|
+
expect(tokenInfo?.token?.decimals).toBe(8);
|
|
58
|
+
|
|
59
|
+
// check adding the same registry does not produce a duplicate
|
|
60
|
+
expect(BCMR.metadataRegistries.length).toBe(1);
|
|
61
|
+
BCMR.addMetadataRegistry(registry);
|
|
62
|
+
expect(BCMR.metadataRegistries.length).toBe(1);
|
|
63
|
+
},
|
|
64
|
+
[process.env.ALICE_ID, registry]
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test(`Add metadata from uri and get token info`, async () => {
|
|
69
|
+
await page.evaluate(
|
|
70
|
+
async ([id, registry]) => {
|
|
71
|
+
BCMR.resetRegistries();
|
|
72
|
+
|
|
73
|
+
setupAxiosMock(
|
|
74
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json",
|
|
75
|
+
registry
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(
|
|
79
|
+
BCMR.getTokenInfo(
|
|
80
|
+
"0000000000000000000000000000000000000000000000000000000000000000"
|
|
81
|
+
)
|
|
82
|
+
).toBe(undefined);
|
|
83
|
+
await BCMR.addMetadataRegistryFromUri(
|
|
84
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
|
|
85
|
+
);
|
|
86
|
+
const tokenInfo = BCMR.getTokenInfo(
|
|
87
|
+
"0000000000000000000000000000000000000000000000000000000000000000"
|
|
88
|
+
);
|
|
89
|
+
expect(tokenInfo?.token?.symbol).toBe("TOK");
|
|
90
|
+
expect(tokenInfo?.token?.decimals).toBe(8);
|
|
91
|
+
|
|
92
|
+
// check adding the same registry does not produce a duplicate
|
|
93
|
+
expect(BCMR.metadataRegistries.length).toBe(1);
|
|
94
|
+
await BCMR.addMetadataRegistryFromUri(
|
|
95
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
|
|
96
|
+
);
|
|
97
|
+
expect(BCMR.metadataRegistries.length).toBe(1);
|
|
98
|
+
|
|
99
|
+
removeAxiosMock(
|
|
100
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
|
|
101
|
+
);
|
|
102
|
+
},
|
|
103
|
+
[process.env.ALICE_ID, registry]
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("Auth chain with 1 element, add resolved registry", async () => {
|
|
108
|
+
await page.evaluate(
|
|
109
|
+
async ([id, registry]) => {
|
|
110
|
+
BCMR.resetRegistries();
|
|
111
|
+
|
|
112
|
+
const alice = await RegTestWallet.fromId(id);
|
|
113
|
+
const bob = await RegTestWallet.newRandom();
|
|
114
|
+
|
|
115
|
+
const registryContent = JSON.stringify(registry, null, 2);
|
|
116
|
+
const registryContentHashBin = sha256.hash(utf8ToBin(registryContent));
|
|
117
|
+
const registryContentHashBinBitcoinByteOrder = registryContentHashBin
|
|
118
|
+
.slice()
|
|
119
|
+
.reverse();
|
|
120
|
+
|
|
121
|
+
let chunks = [
|
|
122
|
+
"BCMR",
|
|
123
|
+
registryContentHashBinBitcoinByteOrder,
|
|
124
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json",
|
|
125
|
+
];
|
|
126
|
+
const opreturnData = OpReturnData.fromArray(chunks);
|
|
127
|
+
const response = await alice.send([
|
|
128
|
+
new SendRequest({
|
|
129
|
+
cashaddr: bob.cashaddr,
|
|
130
|
+
value: 10000,
|
|
131
|
+
unit: "sat",
|
|
132
|
+
}),
|
|
133
|
+
opreturnData,
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
setupAxiosMock(
|
|
137
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json",
|
|
138
|
+
registry
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
expect(
|
|
142
|
+
BCMR.getTokenInfo(
|
|
143
|
+
"0000000000000000000000000000000000000000000000000000000000000000"
|
|
144
|
+
)
|
|
145
|
+
).toBe(undefined);
|
|
146
|
+
const chain = await BCMR.addMetadataRegistryAuthChain({
|
|
147
|
+
transactionHash: response.txId,
|
|
148
|
+
network: Network.REGTEST,
|
|
149
|
+
});
|
|
150
|
+
expect(chain.length).toBe(1);
|
|
151
|
+
expect(chain[0].txHash).toBe(response.txId);
|
|
152
|
+
expect(chain[0].uri).toBe(
|
|
153
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const tokenInfo = BCMR.getTokenInfo(
|
|
157
|
+
"0000000000000000000000000000000000000000000000000000000000000000"
|
|
158
|
+
);
|
|
159
|
+
expect(tokenInfo?.token?.symbol).toBe("TOK");
|
|
160
|
+
expect(tokenInfo?.token?.decimals).toBe(8);
|
|
161
|
+
|
|
162
|
+
// check adding the same registry does not produce a duplicate
|
|
163
|
+
expect(BCMR.metadataRegistries.length).toBe(1);
|
|
164
|
+
const otherChain = await BCMR.addMetadataRegistryAuthChain({
|
|
165
|
+
transactionHash: response.txId,
|
|
166
|
+
network: Network.REGTEST,
|
|
167
|
+
});
|
|
168
|
+
expect(otherChain.length).toBe(1);
|
|
169
|
+
expect(BCMR.metadataRegistries.length).toBe(1);
|
|
170
|
+
|
|
171
|
+
removeAxiosMock(
|
|
172
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry.json"
|
|
173
|
+
);
|
|
174
|
+
},
|
|
175
|
+
[process.env.ALICE_ID, registry]
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test("Authchain tail resolution info in registry acceleration path", async () => {
|
|
180
|
+
await page.evaluate(
|
|
181
|
+
async ([id, registry]) => {
|
|
182
|
+
BCMR.resetRegistries();
|
|
183
|
+
|
|
184
|
+
const alice = await RegTestWallet.fromId(id);
|
|
185
|
+
const bob = await RegTestWallet.newRandom();
|
|
186
|
+
|
|
187
|
+
const registry_v1 = { ...registry };
|
|
188
|
+
registry_v1.extensions = { authchain: [] };
|
|
189
|
+
const contentHash_v1 = sha256
|
|
190
|
+
.hash(utf8ToBin(JSON.stringify(registry_v1, null, 2)))
|
|
191
|
+
.reverse();
|
|
192
|
+
setupAxiosMock(
|
|
193
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json",
|
|
194
|
+
JSON.stringify(registry_v1, null, 2)
|
|
195
|
+
);
|
|
196
|
+
let chunks = [
|
|
197
|
+
"BCMR",
|
|
198
|
+
contentHash_v1,
|
|
199
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json",
|
|
200
|
+
];
|
|
201
|
+
const opreturnData = OpReturnData.fromArray(chunks);
|
|
202
|
+
const response = await alice.send([
|
|
203
|
+
new SendRequest({
|
|
204
|
+
cashaddr: bob.cashaddr,
|
|
205
|
+
value: 10000,
|
|
206
|
+
unit: "sat",
|
|
207
|
+
}),
|
|
208
|
+
opreturnData,
|
|
209
|
+
]);
|
|
210
|
+
|
|
211
|
+
const registry_v2 = { ...registry };
|
|
212
|
+
registry_v2.extensions = {
|
|
213
|
+
authchain: [await bob.provider.getRawTransaction(response.txId)],
|
|
214
|
+
};
|
|
215
|
+
const contentHash_v2 = sha256
|
|
216
|
+
.hash(utf8ToBin(JSON.stringify(registry_v2, null, 2)))
|
|
217
|
+
.reverse();
|
|
218
|
+
setupAxiosMock(
|
|
219
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json",
|
|
220
|
+
JSON.stringify(registry_v2, null, 2)
|
|
221
|
+
);
|
|
222
|
+
chunks = [
|
|
223
|
+
"BCMR",
|
|
224
|
+
contentHash_v2,
|
|
225
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json",
|
|
226
|
+
];
|
|
227
|
+
const opreturnData2 = OpReturnData.fromArray(chunks);
|
|
228
|
+
const response2 = await bob.send([
|
|
229
|
+
new SendRequest({ cashaddr: bob.cashaddr, value: 9500, unit: "sat" }),
|
|
230
|
+
opreturnData2,
|
|
231
|
+
]);
|
|
232
|
+
|
|
233
|
+
const registry_v3 = { ...registry };
|
|
234
|
+
registry_v3.extensions = {
|
|
235
|
+
authchain: [
|
|
236
|
+
await bob.provider.getRawTransaction(response.txId),
|
|
237
|
+
await bob.provider.getRawTransaction(response2.txId),
|
|
238
|
+
],
|
|
239
|
+
};
|
|
240
|
+
const contentHash_v3 = sha256
|
|
241
|
+
.hash(utf8ToBin(JSON.stringify(registry_v3, null, 2)))
|
|
242
|
+
.reverse();
|
|
243
|
+
setupAxiosMock(
|
|
244
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json",
|
|
245
|
+
JSON.stringify(registry_v3, null, 2)
|
|
246
|
+
);
|
|
247
|
+
chunks = [
|
|
248
|
+
"BCMR",
|
|
249
|
+
contentHash_v3,
|
|
250
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json",
|
|
251
|
+
];
|
|
252
|
+
const opreturnData3 = OpReturnData.fromArray(chunks);
|
|
253
|
+
const response3 = await bob.send([
|
|
254
|
+
new SendRequest({ cashaddr: bob.cashaddr, value: 9000, unit: "sat" }),
|
|
255
|
+
opreturnData3,
|
|
256
|
+
]);
|
|
257
|
+
|
|
258
|
+
const registry_v4 = { ...registry };
|
|
259
|
+
registry_v4.extensions = {};
|
|
260
|
+
const contentHash_v4 = sha256
|
|
261
|
+
.hash(utf8ToBin(JSON.stringify(registry_v4, null, 2)))
|
|
262
|
+
.reverse();
|
|
263
|
+
setupAxiosMock(
|
|
264
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json",
|
|
265
|
+
JSON.stringify(registry_v4, null, 2)
|
|
266
|
+
);
|
|
267
|
+
chunks = [
|
|
268
|
+
"BCMR",
|
|
269
|
+
contentHash_v4,
|
|
270
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json",
|
|
271
|
+
];
|
|
272
|
+
const opreturnData4 = OpReturnData.fromArray(chunks);
|
|
273
|
+
const response4 = await bob.send([
|
|
274
|
+
new SendRequest({ cashaddr: bob.cashaddr, value: 8500, unit: "sat" }),
|
|
275
|
+
opreturnData4,
|
|
276
|
+
]);
|
|
277
|
+
|
|
278
|
+
let chain = await BCMR.buildAuthChain({
|
|
279
|
+
transactionHash: response.txId,
|
|
280
|
+
network: Network.REGTEST,
|
|
281
|
+
});
|
|
282
|
+
expect(chain.length).toBe(4);
|
|
283
|
+
|
|
284
|
+
chain = await BCMR.buildAuthChain({
|
|
285
|
+
transactionHash: response.txId,
|
|
286
|
+
network: Network.REGTEST,
|
|
287
|
+
followToHead: false,
|
|
288
|
+
});
|
|
289
|
+
expect(chain.length).toBe(1);
|
|
290
|
+
|
|
291
|
+
// tail acceleration available, do not follow head
|
|
292
|
+
chain = await BCMR.buildAuthChain({
|
|
293
|
+
transactionHash: response3.txId,
|
|
294
|
+
network: Network.REGTEST,
|
|
295
|
+
followToHead: false,
|
|
296
|
+
resolveBase: true,
|
|
297
|
+
});
|
|
298
|
+
expect(chain.length).toBe(3);
|
|
299
|
+
|
|
300
|
+
// resolve single element
|
|
301
|
+
chain = await BCMR.buildAuthChain({
|
|
302
|
+
transactionHash: response3.txId,
|
|
303
|
+
network: Network.REGTEST,
|
|
304
|
+
followToHead: false,
|
|
305
|
+
resolveBase: false,
|
|
306
|
+
});
|
|
307
|
+
expect(chain.length).toBe(1);
|
|
308
|
+
|
|
309
|
+
// no acceleration available, will scan network
|
|
310
|
+
chain = await BCMR.buildAuthChain({
|
|
311
|
+
transactionHash: response4.txId,
|
|
312
|
+
network: Network.REGTEST,
|
|
313
|
+
resolveBase: true,
|
|
314
|
+
});
|
|
315
|
+
expect(chain.length).toBe(4);
|
|
316
|
+
|
|
317
|
+
expect(chain[0].txHash).toBe(response.txId);
|
|
318
|
+
expect(chain[0].uri).toBe(
|
|
319
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json"
|
|
320
|
+
);
|
|
321
|
+
|
|
322
|
+
expect(chain[1].txHash).toBe(response2.txId);
|
|
323
|
+
expect(chain[1].uri).toBe(
|
|
324
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json"
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
expect(chain[2].txHash).toBe(response3.txId);
|
|
328
|
+
expect(chain[2].uri).toBe(
|
|
329
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json"
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
expect(chain[3].txHash).toBe(response4.txId);
|
|
333
|
+
expect(chain[3].uri).toBe(
|
|
334
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json"
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
removeAxiosMock(
|
|
338
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v1.json"
|
|
339
|
+
);
|
|
340
|
+
removeAxiosMock(
|
|
341
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v2.json"
|
|
342
|
+
);
|
|
343
|
+
removeAxiosMock(
|
|
344
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v3.json"
|
|
345
|
+
);
|
|
346
|
+
removeAxiosMock(
|
|
347
|
+
"https://mainnet.cash/.well-known/bitcoin-cash-metadata-registry_v4.json"
|
|
348
|
+
);
|
|
349
|
+
},
|
|
350
|
+
[process.env.ALICE_ID, registry]
|
|
351
|
+
);
|
|
352
|
+
});
|
|
353
|
+
});
|