@ledgerhq/live-common 21.20.0 → 21.21.0-rc.2
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/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js +4 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/utils.test.js.map +1 -1
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js +12 -0
- package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js.map +1 -1
- package/lib/__tests__/test-helpers/setup.js +1 -0
- package/lib/__tests__/test-helpers/setup.js.map +1 -1
- package/lib/account/pending.d.ts +1 -1
- package/lib/api/Ledger.d.ts.map +1 -1
- package/lib/api/Ledger.js +12 -2
- package/lib/api/Ledger.js.map +1 -1
- package/lib/api/explorerConfig/index.d.ts.map +1 -1
- package/lib/api/explorerConfig/index.js +5 -1
- package/lib/api/explorerConfig/index.js.map +1 -1
- package/lib/data/icons/react/cro.d.ts +8 -0
- package/lib/data/icons/react/cro.d.ts.map +1 -0
- package/lib/data/icons/react/cro.js +33 -0
- package/lib/data/icons/react/cro.js.map +1 -0
- package/lib/data/icons/react/index.d.ts +2 -0
- package/lib/data/icons/react/index.d.ts.map +1 -1
- package/lib/data/icons/react/index.js +12 -8
- package/lib/data/icons/react/index.js.map +1 -1
- package/lib/data/icons/react/sol.d.ts +8 -0
- package/lib/data/icons/react/sol.d.ts.map +1 -0
- package/lib/data/icons/react/sol.js +30 -0
- package/lib/data/icons/react/sol.js.map +1 -0
- package/lib/data/icons/reactNative/cro.d.ts +8 -0
- package/lib/data/icons/reactNative/cro.d.ts.map +1 -0
- package/lib/data/icons/reactNative/cro.js +34 -0
- package/lib/data/icons/reactNative/cro.js.map +1 -0
- package/lib/data/icons/reactNative/index.d.ts +2 -0
- package/lib/data/icons/reactNative/index.d.ts.map +1 -1
- package/lib/data/icons/reactNative/index.js +12 -8
- package/lib/data/icons/reactNative/index.js.map +1 -1
- package/lib/data/icons/reactNative/sol.d.ts +8 -0
- package/lib/data/icons/reactNative/sol.d.ts.map +1 -0
- package/lib/data/icons/reactNative/sol.js +31 -0
- package/lib/data/icons/reactNative/sol.js.map +1 -0
- package/lib/derivation.d.ts +7 -0
- package/lib/derivation.d.ts.map +1 -1
- package/lib/derivation.js +16 -1
- package/lib/derivation.js.map +1 -1
- package/lib/errors.d.ts +1 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +1 -0
- package/lib/errors.js.map +1 -1
- package/lib/families/bitcoin/exchange.d.ts +1 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.d.ts.map +1 -1
- package/lib/families/bitcoin/getAccountNetworkInfo.js +3 -2
- package/lib/families/bitcoin/getAccountNetworkInfo.js.map +1 -1
- package/lib/families/bitcoin/js-signOperation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-signOperation.js +7 -2
- package/lib/families/bitcoin/js-signOperation.js.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts +2 -2
- package/lib/families/bitcoin/specs.d.ts +1 -0
- package/lib/families/bitcoin/specs.d.ts.map +1 -1
- package/lib/families/bitcoin/specs.js +14 -1
- package/lib/families/bitcoin/specs.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +8 -1
- package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts +16 -0
- package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts.map +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/decred.js +248 -0
- package/lib/families/bitcoin/wallet-btc/crypto/decred.js.map +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/factory.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/factory.js +5 -0
- package/lib/families/bitcoin/wallet-btc/crypto/factory.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/index.d.ts +1 -0
- package/lib/families/bitcoin/wallet-btc/crypto/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/index.js +3 -1
- package/lib/families/bitcoin/wallet-btc/crypto/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +13 -3
- package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/types.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js +8 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js +8 -1
- package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/utils.js +6 -1
- package/lib/families/bitcoin/wallet-btc/utils.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts +2 -0
- package/lib/families/bitcoin/wallet-btc/wallet.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/wallet.js +15 -7
- package/lib/families/bitcoin/wallet-btc/wallet.js.map +1 -1
- package/lib/families/crypto_org/js-synchronisation.d.ts +2 -2
- package/lib/families/elrond/js-synchronisation.d.ts +2 -2
- package/lib/families/ethereum/synchronisation.d.ts.map +1 -1
- package/lib/families/ethereum/synchronisation.js +2 -2
- package/lib/families/ethereum/synchronisation.js.map +1 -1
- package/lib/families/polkadot/api/sidecar.js +4 -2
- package/lib/families/polkadot/api/sidecar.js.map +1 -1
- package/lib/families/polkadot/js-synchronisation.d.ts +2 -2
- package/lib/families/solana/api/cached.d.ts +5 -0
- package/lib/families/solana/api/cached.d.ts.map +1 -0
- package/lib/families/solana/api/cached.js +80 -0
- package/lib/families/solana/api/cached.js.map +1 -0
- package/lib/families/solana/api/chain/account/index.d.ts +2 -0
- package/lib/families/solana/api/chain/account/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/account/index.js +14 -0
- package/lib/families/solana/api/chain/account/index.js.map +1 -0
- package/lib/families/solana/api/chain/account/parser.d.ts +5 -0
- package/lib/families/solana/api/chain/account/parser.d.ts.map +1 -0
- package/lib/families/solana/api/chain/account/parser.js +33 -0
- package/lib/families/solana/api/chain/account/parser.js.map +1 -0
- package/lib/families/solana/api/chain/account/stake.d.ts +237 -0
- package/lib/families/solana/api/chain/account/stake.d.ts.map +1 -0
- package/lib/families/solana/api/chain/account/stake.js +43 -0
- package/lib/families/solana/api/chain/account/stake.js.map +1 -0
- package/lib/families/solana/api/chain/account/token.d.ts +116 -0
- package/lib/families/solana/api/chain/account/token.d.ts.map +1 -0
- package/lib/families/solana/api/chain/account/token.js +42 -0
- package/lib/families/solana/api/chain/account/token.js.map +1 -0
- package/lib/families/solana/api/chain/index.d.ts +22 -0
- package/lib/families/solana/api/chain/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/index.js +54 -0
- package/lib/families/solana/api/chain/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/index.d.ts +15 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/index.js +21 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/types.d.ts +30 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/types.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/types.js +19 -0
- package/lib/families/solana/api/chain/instruction/associated-token-account/types.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/memo/index.d.ts +15 -0
- package/lib/families/solana/api/chain/instruction/memo/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/memo/index.js +14 -0
- package/lib/families/solana/api/chain/instruction/memo/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/memo/types.d.ts +21 -0
- package/lib/families/solana/api/chain/instruction/memo/types.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/memo/types.js +16 -0
- package/lib/families/solana/api/chain/instruction/memo/types.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/stake/index.d.ts +15 -0
- package/lib/families/solana/api/chain/instruction/stake/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/stake/index.js +20 -0
- package/lib/families/solana/api/chain/instruction/stake/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/stake/types.d.ts +215 -0
- package/lib/families/solana/api/chain/instruction/stake/types.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/stake/types.js +80 -0
- package/lib/families/solana/api/chain/instruction/stake/types.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/index.d.ts +15 -0
- package/lib/families/solana/api/chain/instruction/token/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/index.js +20 -0
- package/lib/families/solana/api/chain/instruction/token/index.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/types.d.ts +497 -0
- package/lib/families/solana/api/chain/instruction/token/types.d.ts.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/types.js +205 -0
- package/lib/families/solana/api/chain/instruction/token/types.js.map +1 -0
- package/lib/families/solana/api/chain/program/constants.d.ts +11 -0
- package/lib/families/solana/api/chain/program/constants.d.ts.map +1 -0
- package/lib/families/solana/api/chain/program/constants.js +14 -0
- package/lib/families/solana/api/chain/program/constants.js.map +1 -0
- package/lib/families/solana/api/chain/program/index.d.ts +2 -0
- package/lib/families/solana/api/chain/program/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/program/index.js +14 -0
- package/lib/families/solana/api/chain/program/index.js.map +1 -0
- package/lib/families/solana/api/chain/program/parser.d.ts +30 -0
- package/lib/families/solana/api/chain/program/parser.d.ts.map +1 -0
- package/lib/families/solana/api/chain/program/parser.js +70 -0
- package/lib/families/solana/api/chain/program/parser.js.map +1 -0
- package/lib/families/solana/api/chain/validators/bignum.d.ts +3 -0
- package/lib/families/solana/api/chain/validators/bignum.d.ts.map +1 -0
- package/lib/families/solana/api/chain/validators/bignum.js +11 -0
- package/lib/families/solana/api/chain/validators/bignum.js.map +1 -0
- package/lib/families/solana/api/chain/validators/index.d.ts +10 -0
- package/lib/families/solana/api/chain/validators/index.d.ts.map +1 -0
- package/lib/families/solana/api/chain/validators/index.js +10 -0
- package/lib/families/solana/api/chain/validators/index.js.map +1 -0
- package/lib/families/solana/api/chain/validators/pubkey.d.ts +3 -0
- package/lib/families/solana/api/chain/validators/pubkey.d.ts.map +1 -0
- package/lib/families/solana/api/chain/validators/pubkey.js +7 -0
- package/lib/families/solana/api/chain/validators/pubkey.js.map +1 -0
- package/lib/families/solana/api/chain/web3.d.ts +29 -0
- package/lib/families/solana/api/chain/web3.d.ts.map +1 -0
- package/lib/families/solana/api/chain/web3.js +287 -0
- package/lib/families/solana/api/chain/web3.js.map +1 -0
- package/lib/families/solana/api/index.d.ts +5 -0
- package/lib/families/solana/api/index.d.ts.map +1 -0
- package/lib/families/solana/api/index.js +21 -0
- package/lib/families/solana/api/index.js.map +1 -0
- package/lib/families/solana/api/logged.d.ts +3 -0
- package/lib/families/solana/api/logged.d.ts.map +1 -0
- package/lib/families/solana/api/logged.js +53 -0
- package/lib/families/solana/api/logged.js.map +1 -0
- package/lib/families/solana/api/queued.d.ts +3 -0
- package/lib/families/solana/api/queued.d.ts.map +1 -0
- package/lib/families/solana/api/queued.js +31 -0
- package/lib/families/solana/api/queued.js.map +1 -0
- package/lib/families/solana/bridge/bridge.d.ts +12 -0
- package/lib/families/solana/bridge/bridge.d.ts.map +1 -0
- package/lib/families/solana/bridge/bridge.js +218 -0
- package/lib/families/solana/bridge/bridge.js.map +1 -0
- package/lib/families/solana/bridge/js.d.ts +6 -0
- package/lib/families/solana/bridge/js.d.ts.map +1 -0
- package/lib/families/solana/bridge/js.js +15 -0
- package/lib/families/solana/bridge/js.js.map +1 -0
- package/lib/families/solana/bridge/mock-data.d.ts +186 -0
- package/lib/families/solana/bridge/mock-data.d.ts.map +1 -0
- package/lib/families/solana/bridge/mock-data.js +23 -0
- package/lib/families/solana/bridge/mock-data.js.map +1 -0
- package/lib/families/solana/bridge/mock.d.ts +6 -0
- package/lib/families/solana/bridge/mock.d.ts.map +1 -0
- package/lib/families/solana/bridge/mock.js +75 -0
- package/lib/families/solana/bridge/mock.js.map +1 -0
- package/lib/families/solana/cli-transaction.d.ts +14 -0
- package/lib/families/solana/cli-transaction.d.ts.map +1 -0
- package/lib/families/solana/cli-transaction.js +137 -0
- package/lib/families/solana/cli-transaction.js.map +1 -0
- package/lib/families/solana/datasets/solana.scanAccounts.1.d.ts +6 -0
- package/lib/families/solana/datasets/solana.scanAccounts.1.d.ts.map +1 -0
- package/lib/families/solana/datasets/solana.scanAccounts.1.js +7 -0
- package/lib/families/solana/datasets/solana.scanAccounts.1.js.map +1 -0
- package/lib/families/solana/deviceTransactionConfig.d.ts +10 -0
- package/lib/families/solana/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/families/solana/deviceTransactionConfig.js +121 -0
- package/lib/families/solana/deviceTransactionConfig.js.map +1 -0
- package/lib/families/solana/errors.d.ts +25 -0
- package/lib/families/solana/errors.d.ts.map +1 -0
- package/lib/families/solana/errors.js +13 -0
- package/lib/families/solana/errors.js.map +1 -0
- package/lib/families/solana/hw-getAddress.d.ts +4 -0
- package/lib/families/solana/hw-getAddress.d.ts.map +1 -0
- package/lib/families/solana/hw-getAddress.js +66 -0
- package/lib/families/solana/hw-getAddress.js.map +1 -0
- package/lib/families/solana/js-broadcast.d.ts +7 -0
- package/lib/families/solana/js-broadcast.d.ts.map +1 -0
- package/lib/families/solana/js-broadcast.js +59 -0
- package/lib/families/solana/js-broadcast.js.map +1 -0
- package/lib/families/solana/js-buildTransaction.d.ts +6 -0
- package/lib/families/solana/js-buildTransaction.d.ts.map +1 -0
- package/lib/families/solana/js-buildTransaction.js +123 -0
- package/lib/families/solana/js-buildTransaction.js.map +1 -0
- package/lib/families/solana/js-createTransaction.d.ts +6 -0
- package/lib/families/solana/js-createTransaction.d.ts.map +1 -0
- package/lib/families/solana/js-createTransaction.js +35 -0
- package/lib/families/solana/js-createTransaction.js.map +1 -0
- package/lib/families/solana/js-estimateMaxSpendable.d.ts +7 -0
- package/lib/families/solana/js-estimateMaxSpendable.d.ts.map +1 -0
- package/lib/families/solana/js-estimateMaxSpendable.js +72 -0
- package/lib/families/solana/js-estimateMaxSpendable.js.map +1 -0
- package/lib/families/solana/js-getTransactionStatus.d.ts +5 -0
- package/lib/families/solana/js-getTransactionStatus.d.ts.map +1 -0
- package/lib/families/solana/js-getTransactionStatus.js +106 -0
- package/lib/families/solana/js-getTransactionStatus.js.map +1 -0
- package/lib/families/solana/js-prepareTransaction.d.ts +6 -0
- package/lib/families/solana/js-prepareTransaction.d.ts.map +1 -0
- package/lib/families/solana/js-prepareTransaction.js +380 -0
- package/lib/families/solana/js-prepareTransaction.js.map +1 -0
- package/lib/families/solana/js-signOperation.d.ts +10 -0
- package/lib/families/solana/js-signOperation.d.ts.map +1 -0
- package/lib/families/solana/js-signOperation.js +193 -0
- package/lib/families/solana/js-signOperation.js.map +1 -0
- package/lib/families/solana/js-synchronization.d.ts +5 -0
- package/lib/families/solana/js-synchronization.d.ts.map +1 -0
- package/lib/families/solana/js-synchronization.js +464 -0
- package/lib/families/solana/js-synchronization.js.map +1 -0
- package/lib/families/solana/logic.d.ts +15 -0
- package/lib/families/solana/logic.d.ts.map +1 -0
- package/lib/families/solana/logic.js +49 -0
- package/lib/families/solana/logic.js.map +1 -0
- package/lib/families/solana/specs.d.ts +7 -0
- package/lib/families/solana/specs.d.ts.map +1 -0
- package/lib/families/solana/specs.js +100 -0
- package/lib/families/solana/specs.js.map +1 -0
- package/lib/families/solana/speculos-deviceActions.d.ts +8 -0
- package/lib/families/solana/speculos-deviceActions.d.ts.map +1 -0
- package/lib/families/solana/speculos-deviceActions.js +60 -0
- package/lib/families/solana/speculos-deviceActions.js.map +1 -0
- package/lib/families/solana/test-dataset.d.ts +5 -0
- package/lib/families/solana/test-dataset.d.ts.map +1 -0
- package/lib/families/solana/test-dataset.js +396 -0
- package/lib/families/solana/test-dataset.js.map +1 -0
- package/lib/families/solana/transaction.d.ts +12 -0
- package/lib/families/solana/transaction.d.ts.map +1 -0
- package/lib/families/solana/transaction.js +109 -0
- package/lib/families/solana/transaction.js.map +1 -0
- package/lib/families/solana/types.d.ts +84 -0
- package/lib/families/solana/types.d.ts.map +1 -0
- package/lib/families/solana/types.js +6 -0
- package/lib/families/solana/types.js.map +1 -0
- package/lib/families/solana/utils.d.ts +10 -0
- package/lib/families/solana/utils.d.ts.map +1 -0
- package/lib/families/solana/utils.js +194 -0
- package/lib/families/solana/utils.js.map +1 -0
- package/lib/families/stellar/js-synchronization.d.ts +2 -2
- package/lib/generated/bridge/js.d.ts +4 -0
- package/lib/generated/bridge/js.d.ts.map +1 -1
- package/lib/generated/bridge/js.js +8 -6
- package/lib/generated/bridge/js.js.map +1 -1
- package/lib/generated/bridge/mock.d.ts +4 -0
- package/lib/generated/bridge/mock.d.ts.map +1 -1
- package/lib/generated/bridge/mock.js +6 -4
- package/lib/generated/bridge/mock.js.map +1 -1
- package/lib/generated/cli-transaction.d.ts +9 -0
- package/lib/generated/cli-transaction.d.ts.map +1 -1
- package/lib/generated/cli-transaction.js +8 -6
- package/lib/generated/cli-transaction.js.map +1 -1
- package/lib/generated/deviceTransactionConfig.d.ts +2 -0
- package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/generated/deviceTransactionConfig.js +8 -6
- package/lib/generated/deviceTransactionConfig.js.map +1 -1
- package/lib/generated/exchange.d.ts +1 -1
- package/lib/generated/hw-getAddress.d.ts +1 -0
- package/lib/generated/hw-getAddress.d.ts.map +1 -1
- package/lib/generated/hw-getAddress.js +8 -6
- package/lib/generated/hw-getAddress.js.map +1 -1
- package/lib/generated/specs.d.ts +4 -0
- package/lib/generated/specs.d.ts.map +1 -1
- package/lib/generated/specs.js +8 -6
- package/lib/generated/specs.js.map +1 -1
- package/lib/generated/speculos-deviceActions.d.ts +3 -0
- package/lib/generated/speculos-deviceActions.d.ts.map +1 -1
- package/lib/generated/speculos-deviceActions.js +8 -6
- package/lib/generated/speculos-deviceActions.js.map +1 -1
- package/lib/generated/test-dataset.d.ts +1 -0
- package/lib/generated/test-dataset.d.ts.map +1 -1
- package/lib/generated/test-dataset.js +8 -6
- package/lib/generated/test-dataset.js.map +1 -1
- package/lib/generated/transaction.d.ts +5 -0
- package/lib/generated/transaction.d.ts.map +1 -1
- package/lib/generated/transaction.js +8 -6
- package/lib/generated/transaction.js.map +1 -1
- package/lib/generated/types.d.ts +12 -6
- package/lib/generated/types.d.ts.map +1 -1
- package/lib/generated/types.js +5 -3
- package/lib/generated/types.js.map +1 -1
- package/lib/nft/helpers.js +1 -1
- package/lib/nft/helpers.js.map +1 -1
- package/package.json +8 -4
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +113 -0
- package/src/__tests__/families/bitcoin/wallet-btc/utils.test.ts +4 -0
- package/src/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.ts +12 -0
- package/src/__tests__/test-helpers/setup.ts +1 -0
- package/src/api/Ledger.ts +11 -1
- package/src/api/explorerConfig/index.ts +1 -3
- package/src/data/icons/react/cro.tsx +12 -0
- package/src/data/icons/react/index.tsx +2 -0
- package/src/data/icons/react/sol.tsx +12 -0
- package/src/data/icons/reactNative/cro.tsx +13 -0
- package/src/data/icons/reactNative/index.tsx +2 -0
- package/src/data/icons/reactNative/sol.tsx +13 -0
- package/src/data/icons/svg/CRO.svg +6 -0
- package/src/data/icons/svg/SOL.svg +3 -0
- package/src/derivation.ts +13 -0
- package/src/errors.ts +1 -0
- package/src/families/bitcoin/getAccountNetworkInfo.ts +5 -2
- package/src/families/bitcoin/js-signOperation.ts +4 -7
- package/src/families/bitcoin/specs.ts +16 -0
- package/src/families/bitcoin/wallet-btc/crypto/base.ts +1 -1
- package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +8 -1
- package/src/families/bitcoin/wallet-btc/crypto/decred.ts +251 -0
- package/src/families/bitcoin/wallet-btc/crypto/factory.ts +5 -0
- package/src/families/bitcoin/wallet-btc/crypto/index.ts +1 -0
- package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +13 -3
- package/src/families/bitcoin/wallet-btc/crypto/types.ts +1 -0
- package/src/families/bitcoin/wallet-btc/crypto/zec.ts +8 -1
- package/src/families/bitcoin/wallet-btc/crypto/zen.ts +8 -1
- package/src/families/bitcoin/wallet-btc/utils.ts +6 -1
- package/src/families/bitcoin/wallet-btc/wallet.ts +18 -5
- package/src/families/ethereum/synchronisation.ts +5 -2
- package/src/families/polkadot/api/sidecar.ts +2 -2
- package/src/families/solana/api/cached.ts +89 -0
- package/src/families/solana/api/chain/account/index.ts +1 -0
- package/src/families/solana/api/chain/account/parser.ts +35 -0
- package/src/families/solana/api/chain/account/stake.ts +50 -0
- package/src/families/solana/api/chain/account/token.ts +63 -0
- package/src/families/solana/api/chain/index.ts +115 -0
- package/src/families/solana/api/chain/instruction/associated-token-account/index.ts +37 -0
- package/src/families/solana/api/chain/instruction/associated-token-account/types.ts +23 -0
- package/src/families/solana/api/chain/instruction/memo/index.ts +24 -0
- package/src/families/solana/api/chain/instruction/memo/types.ts +18 -0
- package/src/families/solana/api/chain/instruction/stake/index.ts +29 -0
- package/src/families/solana/api/chain/instruction/stake/types.ts +95 -0
- package/src/families/solana/api/chain/instruction/token/index.ts +30 -0
- package/src/families/solana/api/chain/instruction/token/types.ts +237 -0
- package/src/families/solana/api/chain/program/constants.ts +10 -0
- package/src/families/solana/api/chain/program/index.ts +1 -0
- package/src/families/solana/api/chain/program/parser.ts +122 -0
- package/src/families/solana/api/chain/validators/bignum.ts +11 -0
- package/src/families/solana/api/chain/validators/index.ts +9 -0
- package/src/families/solana/api/chain/validators/pubkey.ts +8 -0
- package/src/families/solana/api/chain/web3.ts +258 -0
- package/src/families/solana/api/index.ts +4 -0
- package/src/families/solana/api/logged.ts +50 -0
- package/src/families/solana/api/queued.ts +23 -0
- package/src/families/solana/bridge/bridge.ts +169 -0
- package/src/families/solana/bridge/js.ts +28 -0
- package/src/families/solana/bridge/mock-data.ts +22 -0
- package/src/families/solana/bridge/mock.ts +80 -0
- package/src/families/solana/cli-transaction.ts +175 -0
- package/src/families/solana/datasets/solana.scanAccounts.1.ts +9 -0
- package/src/families/solana/deviceTransactionConfig.ts +160 -0
- package/src/families/solana/errors.ts +32 -0
- package/src/families/solana/hw-getAddress.ts +20 -0
- package/src/families/solana/js-broadcast.ts +20 -0
- package/src/families/solana/js-buildTransaction.ts +75 -0
- package/src/families/solana/js-createTransaction.ts +27 -0
- package/src/families/solana/js-estimateMaxSpendable.ts +29 -0
- package/src/families/solana/js-getTransactionStatus.ts +78 -0
- package/src/families/solana/js-prepareTransaction.ts +423 -0
- package/src/families/solana/js-signOperation.ts +230 -0
- package/src/families/solana/js-synchronization.ts +544 -0
- package/src/families/solana/logic.ts +52 -0
- package/src/families/solana/specs.ts +100 -0
- package/src/families/solana/speculos-deviceActions.ts +59 -0
- package/src/families/solana/test-dataset.ts +572 -0
- package/src/families/solana/transaction.ts +146 -0
- package/src/families/solana/types.ts +110 -0
- package/src/families/solana/utils.ts +80 -0
- package/src/generated/bridge/js.ts +3 -0
- package/src/generated/bridge/mock.ts +3 -0
- package/src/generated/cli-transaction.ts +3 -0
- package/src/generated/deviceTransactionConfig.ts +3 -0
- package/src/generated/hw-getAddress.ts +3 -0
- package/src/generated/specs.ts +3 -0
- package/src/generated/speculos-deviceActions.ts +3 -0
- package/src/generated/test-dataset.ts +3 -0
- package/src/generated/transaction.ts +3 -0
- package/src/generated/types.ts +14 -0
- package/src/nft/helpers.ts +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ParsedInstruction,
|
|
3
|
+
PartiallyDecodedInstruction,
|
|
4
|
+
} from "@solana/web3.js";
|
|
5
|
+
import {
|
|
6
|
+
parseSplTokenInstruction,
|
|
7
|
+
TokenInstructionDescriptor,
|
|
8
|
+
} from "../instruction/token";
|
|
9
|
+
import { PARSED_PROGRAMS } from "./constants";
|
|
10
|
+
import {
|
|
11
|
+
AssociatedTokenAccountInstructionDescriptor,
|
|
12
|
+
parseAssociatedTokenAccountInstruction,
|
|
13
|
+
} from "../instruction/associated-token-account";
|
|
14
|
+
import {
|
|
15
|
+
MemoInstructionDescriptor,
|
|
16
|
+
parseSplMemoInstruction,
|
|
17
|
+
} from "../instruction/memo";
|
|
18
|
+
import {
|
|
19
|
+
parseStakeInstruction,
|
|
20
|
+
StakeInstructionDescriptor,
|
|
21
|
+
} from "../instruction/stake";
|
|
22
|
+
|
|
23
|
+
type ParsedProgram =
|
|
24
|
+
| {
|
|
25
|
+
program: "spl-associated-token-account";
|
|
26
|
+
title: string;
|
|
27
|
+
instruction: AssociatedTokenAccountInstructionDescriptor;
|
|
28
|
+
}
|
|
29
|
+
| {
|
|
30
|
+
program: "spl-memo";
|
|
31
|
+
title: string;
|
|
32
|
+
instruction: MemoInstructionDescriptor;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
program: "stake";
|
|
36
|
+
title: string;
|
|
37
|
+
instruction: StakeInstructionDescriptor;
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
program: "spl-token";
|
|
41
|
+
title: string;
|
|
42
|
+
instruction: TokenInstructionDescriptor;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
program: "unknown";
|
|
46
|
+
title: "Unknown";
|
|
47
|
+
instruction: undefined;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const parse = (
|
|
51
|
+
ix: ParsedInstruction | PartiallyDecodedInstruction
|
|
52
|
+
): ParsedProgram => {
|
|
53
|
+
if ("parsed" in ix) {
|
|
54
|
+
const program: typeof PARSED_PROGRAMS[keyof typeof PARSED_PROGRAMS] =
|
|
55
|
+
ix.program as any;
|
|
56
|
+
|
|
57
|
+
switch (program) {
|
|
58
|
+
case "spl-associated-token-account":
|
|
59
|
+
return {
|
|
60
|
+
program,
|
|
61
|
+
title: "Associated Token Account",
|
|
62
|
+
instruction: parseAssociatedTokenAccountInstruction({
|
|
63
|
+
...ix,
|
|
64
|
+
program,
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
case "spl-memo":
|
|
68
|
+
return {
|
|
69
|
+
program,
|
|
70
|
+
title: "Memo",
|
|
71
|
+
instruction: parseSplMemoInstruction({
|
|
72
|
+
...ix,
|
|
73
|
+
program,
|
|
74
|
+
}),
|
|
75
|
+
};
|
|
76
|
+
case "stake":
|
|
77
|
+
return {
|
|
78
|
+
program,
|
|
79
|
+
title: "Stake",
|
|
80
|
+
instruction: parseStakeInstruction({
|
|
81
|
+
...ix,
|
|
82
|
+
program,
|
|
83
|
+
}),
|
|
84
|
+
};
|
|
85
|
+
case "spl-token":
|
|
86
|
+
return {
|
|
87
|
+
program,
|
|
88
|
+
title: "Token",
|
|
89
|
+
instruction: parseSplTokenInstruction({
|
|
90
|
+
...ix,
|
|
91
|
+
program,
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
default:
|
|
95
|
+
return unknown();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return unknown();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export const parseQuiet = (
|
|
103
|
+
ix: ParsedInstruction | PartiallyDecodedInstruction
|
|
104
|
+
): ParsedProgram => {
|
|
105
|
+
try {
|
|
106
|
+
return parse(ix);
|
|
107
|
+
} catch (_) {
|
|
108
|
+
return unknown();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
function unknown(): {
|
|
113
|
+
program: "unknown";
|
|
114
|
+
title: "Unknown";
|
|
115
|
+
instruction: undefined;
|
|
116
|
+
} {
|
|
117
|
+
return {
|
|
118
|
+
program: "unknown",
|
|
119
|
+
title: "Unknown",
|
|
120
|
+
instruction: undefined,
|
|
121
|
+
} as const;
|
|
122
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { coerce, instance, string } from "superstruct";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
export const BigNumFromString = coerce(
|
|
5
|
+
instance(BigNumber),
|
|
6
|
+
string(),
|
|
7
|
+
(value) => {
|
|
8
|
+
if (typeof value === "string") return new BigNumber(value, 10);
|
|
9
|
+
throw new Error("invalid big num");
|
|
10
|
+
}
|
|
11
|
+
);
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Connection,
|
|
3
|
+
PublicKey,
|
|
4
|
+
SystemProgram,
|
|
5
|
+
Transaction,
|
|
6
|
+
ConfirmedSignatureInfo,
|
|
7
|
+
ParsedConfirmedTransaction,
|
|
8
|
+
TransactionInstruction,
|
|
9
|
+
} from "@solana/web3.js";
|
|
10
|
+
import { chunk } from "lodash";
|
|
11
|
+
import {
|
|
12
|
+
TokenCreateATACommand,
|
|
13
|
+
TokenTransferCommand,
|
|
14
|
+
TransferCommand,
|
|
15
|
+
} from "../../types";
|
|
16
|
+
import {
|
|
17
|
+
TOKEN_PROGRAM_ID,
|
|
18
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
19
|
+
Token,
|
|
20
|
+
} from "@solana/spl-token";
|
|
21
|
+
import { tryParseAsTokenAccount, parseTokenAccountInfo } from "./account";
|
|
22
|
+
import { TokenAccountInfo } from "./account/token";
|
|
23
|
+
import { drainSeqAsyncGen } from "../../utils";
|
|
24
|
+
import { Awaited } from "../../logic";
|
|
25
|
+
import { ChainAPI } from ".";
|
|
26
|
+
|
|
27
|
+
const MEMO_PROGRAM_ID = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
|
|
28
|
+
|
|
29
|
+
type ParsedOnChainTokenAccount = Awaited<
|
|
30
|
+
ReturnType<Connection["getParsedTokenAccountsByOwner"]>
|
|
31
|
+
>["value"][number];
|
|
32
|
+
|
|
33
|
+
export type ParsedOnChainTokenAccountWithInfo = {
|
|
34
|
+
onChainAcc: ParsedOnChainTokenAccount;
|
|
35
|
+
info: TokenAccountInfo;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export function toTokenAccountWithInfo(
|
|
39
|
+
onChainAcc: ParsedOnChainTokenAccount
|
|
40
|
+
): ParsedOnChainTokenAccountWithInfo {
|
|
41
|
+
const parsedInfo = onChainAcc.account.data.parsed.info;
|
|
42
|
+
const info = parseTokenAccountInfo(parsedInfo);
|
|
43
|
+
return { onChainAcc, info };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type TransactionDescriptor = {
|
|
47
|
+
parsed: ParsedConfirmedTransaction;
|
|
48
|
+
info: ConfirmedSignatureInfo;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
async function* getTransactionsBatched(
|
|
52
|
+
address: string,
|
|
53
|
+
untilTxSignature: string | undefined,
|
|
54
|
+
api: ChainAPI
|
|
55
|
+
): AsyncGenerator<TransactionDescriptor[], void, unknown> {
|
|
56
|
+
// as per Ledger team - last 100 operations is a sane limit to begin with
|
|
57
|
+
const signatures = await api.getSignaturesForAddress(address, {
|
|
58
|
+
until: untilTxSignature,
|
|
59
|
+
limit: 100,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// max req payload is 50K, around 200 transactions atm
|
|
63
|
+
// requesting 100 at a time to give some space for payload to change in future
|
|
64
|
+
const batchSize = 100;
|
|
65
|
+
|
|
66
|
+
for (const signaturesInfoBatch of chunk(signatures, batchSize)) {
|
|
67
|
+
const transactions = await api.getParsedConfirmedTransactions(
|
|
68
|
+
signaturesInfoBatch.map((tx) => tx.signature)
|
|
69
|
+
);
|
|
70
|
+
const txsDetails = transactions.reduce((acc, tx, index) => {
|
|
71
|
+
if (tx && !tx.meta?.err && tx.blockTime) {
|
|
72
|
+
acc.push({
|
|
73
|
+
info: signaturesInfoBatch[index],
|
|
74
|
+
parsed: tx,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return acc;
|
|
78
|
+
}, [] as TransactionDescriptor[]);
|
|
79
|
+
|
|
80
|
+
yield txsDetails;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async function* getTransactionsGen(
|
|
85
|
+
address: string,
|
|
86
|
+
untilTxSignature: string | undefined,
|
|
87
|
+
api: ChainAPI
|
|
88
|
+
): AsyncGenerator<TransactionDescriptor, void, undefined> {
|
|
89
|
+
for await (const txDetailsBatch of getTransactionsBatched(
|
|
90
|
+
address,
|
|
91
|
+
untilTxSignature,
|
|
92
|
+
api
|
|
93
|
+
)) {
|
|
94
|
+
yield* txDetailsBatch;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function getTransactions(
|
|
99
|
+
address: string,
|
|
100
|
+
untilTxSignature: string | undefined,
|
|
101
|
+
api: ChainAPI
|
|
102
|
+
): Promise<TransactionDescriptor[]> {
|
|
103
|
+
return drainSeqAsyncGen(getTransactionsGen(address, untilTxSignature, api));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export const buildTransferInstructions = ({
|
|
107
|
+
sender,
|
|
108
|
+
recipient,
|
|
109
|
+
amount,
|
|
110
|
+
memo,
|
|
111
|
+
}: TransferCommand): TransactionInstruction[] => {
|
|
112
|
+
const fromPublicKey = new PublicKey(sender);
|
|
113
|
+
const toPublicKey = new PublicKey(recipient);
|
|
114
|
+
|
|
115
|
+
const instructions: TransactionInstruction[] = [
|
|
116
|
+
SystemProgram.transfer({
|
|
117
|
+
fromPubkey: fromPublicKey,
|
|
118
|
+
toPubkey: toPublicKey,
|
|
119
|
+
lamports: amount,
|
|
120
|
+
}),
|
|
121
|
+
];
|
|
122
|
+
|
|
123
|
+
if (memo) {
|
|
124
|
+
const memoIx = new TransactionInstruction({
|
|
125
|
+
keys: [],
|
|
126
|
+
programId: new PublicKey(MEMO_PROGRAM_ID),
|
|
127
|
+
data: Buffer.from(memo),
|
|
128
|
+
});
|
|
129
|
+
instructions.push(memoIx);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return instructions;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const buildTokenTransferInstructions = (
|
|
136
|
+
command: TokenTransferCommand
|
|
137
|
+
): TransactionInstruction[] => {
|
|
138
|
+
const {
|
|
139
|
+
ownerAddress,
|
|
140
|
+
ownerAssociatedTokenAccountAddress,
|
|
141
|
+
amount,
|
|
142
|
+
recipientDescriptor,
|
|
143
|
+
mintAddress,
|
|
144
|
+
mintDecimals,
|
|
145
|
+
memo,
|
|
146
|
+
} = command;
|
|
147
|
+
const ownerPubkey = new PublicKey(ownerAddress);
|
|
148
|
+
|
|
149
|
+
const destinationPubkey = new PublicKey(recipientDescriptor.tokenAccAddress);
|
|
150
|
+
|
|
151
|
+
const instructions: TransactionInstruction[] = [];
|
|
152
|
+
|
|
153
|
+
const mintPubkey = new PublicKey(mintAddress);
|
|
154
|
+
|
|
155
|
+
if (recipientDescriptor.shouldCreateAsAssociatedTokenAccount) {
|
|
156
|
+
instructions.push(
|
|
157
|
+
Token.createAssociatedTokenAccountInstruction(
|
|
158
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
159
|
+
TOKEN_PROGRAM_ID,
|
|
160
|
+
mintPubkey,
|
|
161
|
+
destinationPubkey,
|
|
162
|
+
new PublicKey(recipientDescriptor.walletAddress),
|
|
163
|
+
ownerPubkey
|
|
164
|
+
)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
instructions.push(
|
|
169
|
+
Token.createTransferCheckedInstruction(
|
|
170
|
+
TOKEN_PROGRAM_ID,
|
|
171
|
+
new PublicKey(ownerAssociatedTokenAccountAddress),
|
|
172
|
+
mintPubkey,
|
|
173
|
+
destinationPubkey,
|
|
174
|
+
ownerPubkey,
|
|
175
|
+
[],
|
|
176
|
+
amount,
|
|
177
|
+
mintDecimals
|
|
178
|
+
)
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
if (memo) {
|
|
182
|
+
instructions.push(
|
|
183
|
+
new TransactionInstruction({
|
|
184
|
+
keys: [],
|
|
185
|
+
programId: new PublicKey(MEMO_PROGRAM_ID),
|
|
186
|
+
data: Buffer.from(memo),
|
|
187
|
+
})
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return instructions;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export const addSignatureToTransaction = ({
|
|
195
|
+
tx,
|
|
196
|
+
address,
|
|
197
|
+
signature,
|
|
198
|
+
}: {
|
|
199
|
+
tx: Transaction;
|
|
200
|
+
address: string;
|
|
201
|
+
signature: Buffer;
|
|
202
|
+
}): Transaction => {
|
|
203
|
+
tx.addSignature(new PublicKey(address), signature);
|
|
204
|
+
|
|
205
|
+
return tx;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export async function findAssociatedTokenAccountPubkey(
|
|
209
|
+
ownerAddress: string,
|
|
210
|
+
mintAddress: string
|
|
211
|
+
): Promise<PublicKey> {
|
|
212
|
+
const ownerPubKey = new PublicKey(ownerAddress);
|
|
213
|
+
const mintPubkey = new PublicKey(mintAddress);
|
|
214
|
+
|
|
215
|
+
return Token.getAssociatedTokenAddress(
|
|
216
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
217
|
+
TOKEN_PROGRAM_ID,
|
|
218
|
+
mintPubkey,
|
|
219
|
+
ownerPubKey
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export const getMaybeTokenAccount = async (
|
|
224
|
+
address: string,
|
|
225
|
+
api: ChainAPI
|
|
226
|
+
): Promise<TokenAccountInfo | undefined | Error> => {
|
|
227
|
+
const accInfo = await api.getAccountInfo(address);
|
|
228
|
+
|
|
229
|
+
const tokenAccount =
|
|
230
|
+
accInfo !== null && "parsed" in accInfo.data
|
|
231
|
+
? tryParseAsTokenAccount(accInfo.data)
|
|
232
|
+
: undefined;
|
|
233
|
+
|
|
234
|
+
return tokenAccount;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export function buildCreateAssociatedTokenAccountInstruction({
|
|
238
|
+
mint,
|
|
239
|
+
owner,
|
|
240
|
+
associatedTokenAccountAddress,
|
|
241
|
+
}: TokenCreateATACommand): TransactionInstruction[] {
|
|
242
|
+
const ownerPubKey = new PublicKey(owner);
|
|
243
|
+
const mintPubkey = new PublicKey(mint);
|
|
244
|
+
const associatedTokenAccPubkey = new PublicKey(associatedTokenAccountAddress);
|
|
245
|
+
|
|
246
|
+
const instructions: TransactionInstruction[] = [
|
|
247
|
+
Token.createAssociatedTokenAccountInstruction(
|
|
248
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
249
|
+
TOKEN_PROGRAM_ID,
|
|
250
|
+
mintPubkey,
|
|
251
|
+
associatedTokenAccPubkey,
|
|
252
|
+
ownerPubKey,
|
|
253
|
+
ownerPubKey
|
|
254
|
+
),
|
|
255
|
+
];
|
|
256
|
+
|
|
257
|
+
return instructions;
|
|
258
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ChainAPI } from "./chain";
|
|
2
|
+
|
|
3
|
+
//import fs from "fs";
|
|
4
|
+
|
|
5
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
6
|
+
function write(file: string, str: string) {
|
|
7
|
+
// fs is not available on mobile
|
|
8
|
+
//fs.appendFileSync(file, str);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function logged(api: ChainAPI, file: string): ChainAPI {
|
|
12
|
+
const proxy: ChainAPI = new Proxy(api, {
|
|
13
|
+
get(target, propKey, receiver) {
|
|
14
|
+
if (typeof propKey === "symbol") {
|
|
15
|
+
throw new Error("symbols not supported");
|
|
16
|
+
}
|
|
17
|
+
const targetValue = Reflect.get(target, propKey, receiver);
|
|
18
|
+
if (typeof targetValue === "function") {
|
|
19
|
+
return function (...args: unknown[]) {
|
|
20
|
+
const result = targetValue.apply(this, args);
|
|
21
|
+
const log = (answer: unknown) => {
|
|
22
|
+
const summary = {
|
|
23
|
+
method: propKey,
|
|
24
|
+
params: args,
|
|
25
|
+
answer,
|
|
26
|
+
};
|
|
27
|
+
const summaryJson = JSON.stringify(summary).replace(
|
|
28
|
+
/{"_bn":(".*?")}/g,
|
|
29
|
+
"new PublicKey(Buffer.from($1, 'hex'))"
|
|
30
|
+
);
|
|
31
|
+
write(file, summaryJson + ",\n");
|
|
32
|
+
};
|
|
33
|
+
if (result instanceof Promise) {
|
|
34
|
+
return result.then((answer) => {
|
|
35
|
+
log(answer);
|
|
36
|
+
return answer;
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
log(result);
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
return targetValue;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
return proxy;
|
|
50
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { asyncQueue } from "../utils";
|
|
2
|
+
import { ChainAPI } from "./chain";
|
|
3
|
+
|
|
4
|
+
export function queued(api: ChainAPI, delayBetweenRuns = 100): ChainAPI {
|
|
5
|
+
const q = asyncQueue({
|
|
6
|
+
delayBetweenRuns,
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const proxy: ChainAPI = new Proxy(api, {
|
|
10
|
+
get(target, propKey, receiver) {
|
|
11
|
+
const targetValue = Reflect.get(target, propKey, receiver);
|
|
12
|
+
if (typeof targetValue === "function") {
|
|
13
|
+
return function (...args: unknown[]) {
|
|
14
|
+
return q.submit(() => targetValue.apply(this, args));
|
|
15
|
+
};
|
|
16
|
+
} else {
|
|
17
|
+
return targetValue;
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return proxy;
|
|
23
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GetAccountShape,
|
|
3
|
+
makeAccountBridgeReceive,
|
|
4
|
+
makeSync as makeSyncHelper,
|
|
5
|
+
makeScanAccounts as makeScanHelper,
|
|
6
|
+
} from "../../../bridge/jsHelpers";
|
|
7
|
+
import type {
|
|
8
|
+
Account,
|
|
9
|
+
AccountBridge,
|
|
10
|
+
AccountLike,
|
|
11
|
+
BroadcastFnSignature,
|
|
12
|
+
CurrencyBridge,
|
|
13
|
+
SignOperationFnSignature,
|
|
14
|
+
} from "../../../types";
|
|
15
|
+
import type { Transaction } from "../types";
|
|
16
|
+
import { getAccountShapeWithAPI } from "../js-synchronization";
|
|
17
|
+
import getTransactionStatus from "../js-getTransactionStatus";
|
|
18
|
+
import estimateMaxSpendableWithAPI from "../js-estimateMaxSpendable";
|
|
19
|
+
import createTransaction, { updateTransaction } from "../js-createTransaction";
|
|
20
|
+
import { signOperationWithAPI } from "../js-signOperation";
|
|
21
|
+
import { broadcastWithAPI } from "../js-broadcast";
|
|
22
|
+
import { prepareTransaction as prepareTransactionWithAPI } from "../js-prepareTransaction";
|
|
23
|
+
import { ChainAPI, Config } from "../api";
|
|
24
|
+
import { makeLRUCache } from "../../../cache";
|
|
25
|
+
import { clusterByCurrencyId } from "../utils";
|
|
26
|
+
import { minutes, seconds } from "../api/cached";
|
|
27
|
+
import hash from "object-hash";
|
|
28
|
+
import BigNumber from "bignumber.js";
|
|
29
|
+
|
|
30
|
+
function makePrepare(getChainAPI: (config: Config) => Promise<ChainAPI>) {
|
|
31
|
+
async function prepareTransaction(
|
|
32
|
+
mainAccount: Account,
|
|
33
|
+
transaction: Transaction
|
|
34
|
+
) {
|
|
35
|
+
const config = {
|
|
36
|
+
cluster: clusterByCurrencyId(mainAccount.currency.id),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const chainAPI = await getChainAPI(config);
|
|
40
|
+
return prepareTransactionWithAPI(mainAccount, transaction, chainAPI);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const cacheKeyByAccTx = (account: Account, tx: Transaction) =>
|
|
44
|
+
hash({
|
|
45
|
+
account: {
|
|
46
|
+
id: account.id,
|
|
47
|
+
address: account.freshAddress,
|
|
48
|
+
syncDate: account.lastSyncDate.toISOString(),
|
|
49
|
+
},
|
|
50
|
+
tx: {
|
|
51
|
+
recipient: tx.recipient,
|
|
52
|
+
amount: tx.amount.toNumber(),
|
|
53
|
+
useAllAmount: tx.useAllAmount,
|
|
54
|
+
subAccountId: tx.subAccountId,
|
|
55
|
+
model: tx.model,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return makeLRUCache(prepareTransaction, cacheKeyByAccTx, seconds(30));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function makeSyncAndScan(getChainAPI: (config: Config) => Promise<ChainAPI>) {
|
|
63
|
+
const getAccountShape: GetAccountShape = async (info) => {
|
|
64
|
+
const config = {
|
|
65
|
+
cluster: clusterByCurrencyId(info.currency.id),
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const chainAPI = await getChainAPI(config);
|
|
69
|
+
return getAccountShapeWithAPI(info, chainAPI);
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
sync: makeSyncHelper(getAccountShape),
|
|
73
|
+
scan: makeScanHelper(getAccountShape),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function makeEstimateMaxSpendable(
|
|
78
|
+
getChainAPI: (config: Config) => Promise<ChainAPI>
|
|
79
|
+
) {
|
|
80
|
+
async function estimateMaxSpendable(
|
|
81
|
+
arg: Parameters<AccountBridge<Transaction>["estimateMaxSpendable"]>[0]
|
|
82
|
+
): Promise<BigNumber> {
|
|
83
|
+
const { account, parentAccount } = arg;
|
|
84
|
+
|
|
85
|
+
const currencyId =
|
|
86
|
+
account.type === "Account"
|
|
87
|
+
? account.currency.id
|
|
88
|
+
: parentAccount?.currency.id;
|
|
89
|
+
|
|
90
|
+
if (currencyId === undefined) {
|
|
91
|
+
throw new Error("currency not found");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const config = {
|
|
95
|
+
cluster: clusterByCurrencyId(currencyId),
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const api = await getChainAPI(config);
|
|
99
|
+
|
|
100
|
+
return estimateMaxSpendableWithAPI(arg, api);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const cacheKeyByAccBalance = ({ account }: { account: AccountLike }) =>
|
|
104
|
+
`${account.id}:${account.balance.toString()}`;
|
|
105
|
+
|
|
106
|
+
return makeLRUCache(estimateMaxSpendable, cacheKeyByAccBalance, minutes(5));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function makeBroadcast(
|
|
110
|
+
getChainAPI: (config: Config) => Promise<ChainAPI>
|
|
111
|
+
): BroadcastFnSignature {
|
|
112
|
+
return async (info) => {
|
|
113
|
+
const config = {
|
|
114
|
+
cluster: clusterByCurrencyId(info.account.currency.id),
|
|
115
|
+
};
|
|
116
|
+
const api = await getChainAPI(config);
|
|
117
|
+
return broadcastWithAPI(info, api);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function makeSign(
|
|
122
|
+
getChainAPI: (config: Config) => Promise<ChainAPI>
|
|
123
|
+
): SignOperationFnSignature<Transaction> {
|
|
124
|
+
return (info) => {
|
|
125
|
+
const config = {
|
|
126
|
+
cluster: clusterByCurrencyId(info.account.currency.id),
|
|
127
|
+
};
|
|
128
|
+
const api = () => getChainAPI(config);
|
|
129
|
+
return signOperationWithAPI(info, api);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function makeBridges({
|
|
134
|
+
getAPI,
|
|
135
|
+
getQueuedAPI,
|
|
136
|
+
getQueuedAndCachedAPI,
|
|
137
|
+
}: {
|
|
138
|
+
getAPI: (config: Config) => Promise<ChainAPI>;
|
|
139
|
+
getQueuedAPI: (config: Config) => Promise<ChainAPI>;
|
|
140
|
+
getQueuedAndCachedAPI: (config: Config) => Promise<ChainAPI>;
|
|
141
|
+
}): {
|
|
142
|
+
currencyBridge: CurrencyBridge;
|
|
143
|
+
accountBridge: AccountBridge<Transaction>;
|
|
144
|
+
} {
|
|
145
|
+
const { sync, scan } = makeSyncAndScan(getQueuedAPI);
|
|
146
|
+
|
|
147
|
+
const accountBridge: AccountBridge<Transaction> = {
|
|
148
|
+
createTransaction,
|
|
149
|
+
updateTransaction,
|
|
150
|
+
estimateMaxSpendable: makeEstimateMaxSpendable(getQueuedAndCachedAPI),
|
|
151
|
+
getTransactionStatus,
|
|
152
|
+
sync,
|
|
153
|
+
receive: makeAccountBridgeReceive(),
|
|
154
|
+
prepareTransaction: makePrepare(getQueuedAndCachedAPI),
|
|
155
|
+
broadcast: makeBroadcast(getAPI),
|
|
156
|
+
signOperation: makeSign(getAPI),
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const currencyBridge: CurrencyBridge = {
|
|
160
|
+
preload: async (): Promise<any> => {},
|
|
161
|
+
hydrate: (): void => {},
|
|
162
|
+
scanAccounts: scan,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
currencyBridge,
|
|
167
|
+
accountBridge,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cached, Config, getChainAPI, queued } from "../api";
|
|
2
|
+
import { makeLRUCache } from "../../../cache";
|
|
3
|
+
import { makeBridges } from "./bridge";
|
|
4
|
+
import { minutes } from "../api/cached";
|
|
5
|
+
|
|
6
|
+
const getAPI = makeLRUCache(
|
|
7
|
+
(config: Config) => Promise.resolve(getChainAPI(config)),
|
|
8
|
+
(config) => config.cluster,
|
|
9
|
+
minutes(1000)
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const getQueuedAPI = makeLRUCache(
|
|
13
|
+
(config: Config) => getAPI(config).then((api) => queued(api, 100)),
|
|
14
|
+
(config) => config.cluster,
|
|
15
|
+
minutes(1000)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const getQueuedAndCachedAPI = makeLRUCache(
|
|
19
|
+
(config: Config) => getQueuedAPI(config).then(cached),
|
|
20
|
+
(config) => config.cluster,
|
|
21
|
+
minutes(1000)
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export default makeBridges({
|
|
25
|
+
getAPI,
|
|
26
|
+
getQueuedAPI,
|
|
27
|
+
getQueuedAndCachedAPI,
|
|
28
|
+
});
|