@ledgerhq/coin-mina 1.1.0-next.0
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/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +24 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/jest.integ.config.js +8 -0
- package/lib/api/index.d.ts +13 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.integ.test.d.ts +2 -0
- package/lib/api/index.integ.test.d.ts.map +1 -0
- package/lib/api/index.integ.test.js +57 -0
- package/lib/api/index.integ.test.js.map +1 -0
- package/lib/api/index.js +91 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/rosetta/index.d.ts +9 -0
- package/lib/api/rosetta/index.d.ts.map +1 -0
- package/lib/api/rosetta/index.js +90 -0
- package/lib/api/rosetta/index.js.map +1 -0
- package/lib/api/rosetta/types.d.ts +143 -0
- package/lib/api/rosetta/types.d.ts.map +1 -0
- package/lib/api/rosetta/types.js +3 -0
- package/lib/api/rosetta/types.js.map +1 -0
- package/lib/api/rosetta/utils.d.ts +43 -0
- package/lib/api/rosetta/utils.d.ts.map +1 -0
- package/lib/api/rosetta/utils.js +60 -0
- package/lib/api/rosetta/utils.js.map +1 -0
- package/lib/api/rosetta/utils.test.d.ts +2 -0
- package/lib/api/rosetta/utils.test.d.ts.map +1 -0
- package/lib/api/rosetta/utils.test.js +82 -0
- package/lib/api/rosetta/utils.test.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +6 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +11 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/broadcast.test.d.ts +2 -0
- package/lib/bridge/broadcast.test.d.ts.map +1 -0
- package/lib/bridge/broadcast.test.js +36 -0
- package/lib/bridge/broadcast.test.js.map +1 -0
- package/lib/bridge/buildTransaction.d.ts +4 -0
- package/lib/bridge/buildTransaction.d.ts.map +1 -0
- package/lib/bridge/buildTransaction.js +37 -0
- package/lib/bridge/buildTransaction.js.map +1 -0
- package/lib/bridge/buildTransaction.test.d.ts +2 -0
- package/lib/bridge/buildTransaction.test.d.ts.map +1 -0
- package/lib/bridge/buildTransaction.test.js +57 -0
- package/lib/bridge/buildTransaction.test.js.map +1 -0
- package/lib/bridge/cli-transaction.d.ts +18 -0
- package/lib/bridge/cli-transaction.d.ts.map +1 -0
- package/lib/bridge/cli-transaction.js +37 -0
- package/lib/bridge/cli-transaction.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +21 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/createTransaction.test.d.ts +2 -0
- package/lib/bridge/createTransaction.test.d.ts.map +1 -0
- package/lib/bridge/createTransaction.test.js +24 -0
- package/lib/bridge/createTransaction.test.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +11 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +8 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/errors.d.ts +10 -0
- package/lib/bridge/errors.d.ts.map +1 -0
- package/lib/bridge/errors.js +17 -0
- package/lib/bridge/errors.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +26 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getEstimatedFees.d.ts +8 -0
- package/lib/bridge/getEstimatedFees.d.ts.map +1 -0
- package/lib/bridge/getEstimatedFees.js +9 -0
- package/lib/bridge/getEstimatedFees.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +5 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +62 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.test.js +138 -0
- package/lib/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib/bridge/index.d.ts +14 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +59 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/index.test.d.ts +2 -0
- package/lib/bridge/index.test.d.ts.map +1 -0
- package/lib/bridge/index.test.js +32 -0
- package/lib/bridge/index.test.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +23 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.test.js +43 -0
- package/lib/bridge/prepareTransaction.test.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +12 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +72 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/signOperation.test.d.ts +2 -0
- package/lib/bridge/signOperation.test.d.ts.map +1 -0
- package/lib/bridge/signOperation.test.js +129 -0
- package/lib/bridge/signOperation.test.js.map +1 -0
- package/lib/bridge/synchronisation.d.ts +7 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -0
- package/lib/bridge/synchronisation.js +155 -0
- package/lib/bridge/synchronisation.js.map +1 -0
- package/lib/bridge/synchronisation.test.d.ts +2 -0
- package/lib/bridge/synchronisation.test.d.ts.map +1 -0
- package/lib/bridge/synchronisation.test.js +164 -0
- package/lib/bridge/synchronisation.test.js.map +1 -0
- package/lib/bridge/transaction.d.ts +14 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +61 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/common-logic/index.d.ts +9 -0
- package/lib/common-logic/index.d.ts.map +1 -0
- package/lib/common-logic/index.js +96 -0
- package/lib/common-logic/index.js.map +1 -0
- package/lib/common-logic/index.test.d.ts +2 -0
- package/lib/common-logic/index.test.d.ts.map +1 -0
- package/lib/common-logic/index.test.js +181 -0
- package/lib/common-logic/index.test.js.map +1 -0
- package/lib/config.d.ts +9 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/consts.d.ts +16 -0
- package/lib/consts.d.ts.map +1 -0
- package/lib/consts.js +19 -0
- package/lib/consts.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +22 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/getAddress.test.d.ts +2 -0
- package/lib/signer/getAddress.test.d.ts.map +1 -0
- package/lib/signer/getAddress.test.js +106 -0
- package/lib/signer/getAddress.test.js.map +1 -0
- package/lib/signer/index.d.ts +3 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +8 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-deviceActions.d.ts +4 -0
- package/lib/test/bot-deviceActions.d.ts.map +1 -0
- package/lib/test/bot-deviceActions.js +67 -0
- package/lib/test/bot-deviceActions.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +107 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +174 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/fixtures.d.ts +55 -0
- package/lib/test/fixtures.d.ts.map +1 -0
- package/lib/test/fixtures.js +194 -0
- package/lib/test/fixtures.js.map +1 -0
- package/lib/test/index.d.ts +4 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +20 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/testUtils.d.ts +2 -0
- package/lib/test/testUtils.d.ts.map +1 -0
- package/lib/test/testUtils.js +8 -0
- package/lib/test/testUtils.js.map +1 -0
- package/lib/test/testUtils.test.d.ts +2 -0
- package/lib/test/testUtils.test.d.ts.map +1 -0
- package/lib/test/testUtils.test.js +11 -0
- package/lib/test/testUtils.test.js.map +1 -0
- package/lib/types/common.d.ts +55 -0
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +3 -0
- package/lib/types/common.js.map +1 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +19 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +32 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/api/index.d.ts +13 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.integ.test.d.ts +2 -0
- package/lib-es/api/index.integ.test.d.ts.map +1 -0
- package/lib-es/api/index.integ.test.js +55 -0
- package/lib-es/api/index.integ.test.js.map +1 -0
- package/lib-es/api/index.js +79 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/rosetta/index.d.ts +8 -0
- package/lib-es/api/rosetta/index.d.ts.map +1 -0
- package/lib-es/api/rosetta/index.js +78 -0
- package/lib-es/api/rosetta/index.js.map +1 -0
- package/lib-es/api/rosetta/types.d.ts +143 -0
- package/lib-es/api/rosetta/types.d.ts.map +1 -0
- package/lib-es/api/rosetta/types.js +2 -0
- package/lib-es/api/rosetta/types.js.map +1 -0
- package/lib-es/api/rosetta/utils.d.ts +43 -0
- package/lib-es/api/rosetta/utils.d.ts.map +1 -0
- package/lib-es/api/rosetta/utils.js +54 -0
- package/lib-es/api/rosetta/utils.js.map +1 -0
- package/lib-es/api/rosetta/utils.test.d.ts +2 -0
- package/lib-es/api/rosetta/utils.test.d.ts.map +1 -0
- package/lib-es/api/rosetta/utils.test.js +80 -0
- package/lib-es/api/rosetta/utils.test.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +6 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +9 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/broadcast.test.d.ts +2 -0
- package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.test.js +31 -0
- package/lib-es/bridge/broadcast.test.js.map +1 -0
- package/lib-es/bridge/buildTransaction.d.ts +4 -0
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
- package/lib-es/bridge/buildTransaction.js +30 -0
- package/lib-es/bridge/buildTransaction.js.map +1 -0
- package/lib-es/bridge/buildTransaction.test.d.ts +2 -0
- package/lib-es/bridge/buildTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/buildTransaction.test.js +55 -0
- package/lib-es/bridge/buildTransaction.test.js.map +1 -0
- package/lib-es/bridge/cli-transaction.d.ts +18 -0
- package/lib-es/bridge/cli-transaction.d.ts.map +1 -0
- package/lib-es/bridge/cli-transaction.js +31 -0
- package/lib-es/bridge/cli-transaction.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +14 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/createTransaction.test.d.ts +2 -0
- package/lib-es/bridge/createTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.test.js +19 -0
- package/lib-es/bridge/createTransaction.test.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +11 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +6 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/errors.d.ts +10 -0
- package/lib-es/bridge/errors.d.ts.map +1 -0
- package/lib-es/bridge/errors.js +14 -0
- package/lib-es/bridge/errors.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +21 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getEstimatedFees.d.ts +8 -0
- package/lib-es/bridge/getEstimatedFees.d.ts.map +1 -0
- package/lib-es/bridge/getEstimatedFees.js +7 -0
- package/lib-es/bridge/getEstimatedFees.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +5 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +60 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.test.js +133 -0
- package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib-es/bridge/index.d.ts +14 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +50 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/index.test.d.ts +2 -0
- package/lib-es/bridge/index.test.d.ts.map +1 -0
- package/lib-es/bridge/index.test.js +30 -0
- package/lib-es/bridge/index.test.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +16 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.test.js +38 -0
- package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +12 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +64 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/signOperation.test.d.ts +2 -0
- package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.test.js +127 -0
- package/lib-es/bridge/signOperation.test.js.map +1 -0
- package/lib-es/bridge/synchronisation.d.ts +7 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -0
- package/lib-es/bridge/synchronisation.js +147 -0
- package/lib-es/bridge/synchronisation.js.map +1 -0
- package/lib-es/bridge/synchronisation.test.d.ts +2 -0
- package/lib-es/bridge/synchronisation.test.d.ts.map +1 -0
- package/lib-es/bridge/synchronisation.test.js +159 -0
- package/lib-es/bridge/synchronisation.test.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +14 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +53 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/common-logic/index.d.ts +9 -0
- package/lib-es/common-logic/index.d.ts.map +1 -0
- package/lib-es/common-logic/index.js +84 -0
- package/lib-es/common-logic/index.js.map +1 -0
- package/lib-es/common-logic/index.test.d.ts +2 -0
- package/lib-es/common-logic/index.test.d.ts.map +1 -0
- package/lib-es/common-logic/index.test.js +179 -0
- package/lib-es/common-logic/index.test.js.map +1 -0
- package/lib-es/config.d.ts +9 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/consts.d.ts +16 -0
- package/lib-es/consts.d.ts.map +1 -0
- package/lib-es/consts.js +16 -0
- package/lib-es/consts.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +17 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/getAddress.test.d.ts +2 -0
- package/lib-es/signer/getAddress.test.d.ts.map +1 -0
- package/lib-es/signer/getAddress.test.js +101 -0
- package/lib-es/signer/getAddress.test.js.map +1 -0
- package/lib-es/signer/index.d.ts +3 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +3 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-deviceActions.d.ts +4 -0
- package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
- package/lib-es/test/bot-deviceActions.js +64 -0
- package/lib-es/test/bot-deviceActions.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +102 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +171 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/fixtures.d.ts +55 -0
- package/lib-es/test/fixtures.d.ts.map +1 -0
- package/lib-es/test/fixtures.js +182 -0
- package/lib-es/test/fixtures.js.map +1 -0
- package/lib-es/test/index.d.ts +4 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +4 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/test/testUtils.d.ts +2 -0
- package/lib-es/test/testUtils.d.ts.map +1 -0
- package/lib-es/test/testUtils.js +4 -0
- package/lib-es/test/testUtils.js.map +1 -0
- package/lib-es/test/testUtils.test.d.ts +2 -0
- package/lib-es/test/testUtils.test.d.ts.map +1 -0
- package/lib-es/test/testUtils.test.js +9 -0
- package/lib-es/test/testUtils.test.js.map +1 -0
- package/lib-es/types/common.d.ts +55 -0
- package/lib-es/types/common.d.ts.map +1 -0
- package/lib-es/types/common.js +2 -0
- package/lib-es/types/common.js.map +1 -0
- package/lib-es/types/index.d.ts +3 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +3 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +32 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +143 -0
- package/src/api/index.integ.test.ts +62 -0
- package/src/api/index.ts +120 -0
- package/src/api/rosetta/index.ts +110 -0
- package/src/api/rosetta/types.ts +156 -0
- package/src/api/rosetta/utils.test.ts +100 -0
- package/src/api/rosetta/utils.ts +71 -0
- package/src/bridge/broadcast.test.ts +35 -0
- package/src/bridge/broadcast.ts +17 -0
- package/src/bridge/buildTransaction.test.ts +68 -0
- package/src/bridge/buildTransaction.ts +34 -0
- package/src/bridge/cli-transaction.ts +43 -0
- package/src/bridge/createTransaction.test.ts +21 -0
- package/src/bridge/createTransaction.ts +19 -0
- package/src/bridge/deviceTransactionConfig.ts +15 -0
- package/src/bridge/errors.ts +16 -0
- package/src/bridge/estimateMaxSpendable.ts +31 -0
- package/src/bridge/getEstimatedFees.ts +17 -0
- package/src/bridge/getTransactionStatus.test.ts +175 -0
- package/src/bridge/getTransactionStatus.ts +87 -0
- package/src/bridge/index.test.ts +39 -0
- package/src/bridge/index.ts +72 -0
- package/src/bridge/prepareTransaction.test.ts +43 -0
- package/src/bridge/prepareTransaction.ts +24 -0
- package/src/bridge/signOperation.test.ts +158 -0
- package/src/bridge/signOperation.ts +112 -0
- package/src/bridge/synchronisation.test.ts +184 -0
- package/src/bridge/synchronisation.ts +168 -0
- package/src/bridge/transaction.ts +69 -0
- package/src/common-logic/index.test.ts +225 -0
- package/src/common-logic/index.ts +97 -0
- package/src/config.ts +21 -0
- package/src/consts.ts +18 -0
- package/src/signer/getAddress.test.ts +131 -0
- package/src/signer/getAddress.ts +24 -0
- package/src/signer/index.ts +3 -0
- package/src/test/bot-deviceActions.ts +73 -0
- package/src/test/bot-specs.ts +130 -0
- package/src/test/bridgeDatasetTest.ts +180 -0
- package/src/test/fixtures.ts +226 -0
- package/src/test/index.ts +3 -0
- package/src/test/testUtils.test.ts +9 -0
- package/src/test/testUtils.ts +3 -0
- package/src/types/common.ts +70 -0
- package/src/types/index.ts +2 -0
- package/src/types/signer.ts +29 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
4
|
+
import type { MinaOperation, MinaSignedTransaction, Transaction } from "../types/common";
|
|
5
|
+
import type {
|
|
6
|
+
Account,
|
|
7
|
+
DeviceId,
|
|
8
|
+
SignOperationEvent,
|
|
9
|
+
OperationType,
|
|
10
|
+
AccountBridge,
|
|
11
|
+
} from "@ledgerhq/types-live";
|
|
12
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
13
|
+
import { MinaSignature, MinaSigner } from "../types/signer";
|
|
14
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
15
|
+
import { buildTransaction } from "./buildTransaction";
|
|
16
|
+
import { reEncodeRawSignature } from "../common-logic";
|
|
17
|
+
import invariant from "invariant";
|
|
18
|
+
|
|
19
|
+
export const buildOptimisticOperation = (
|
|
20
|
+
account: Account,
|
|
21
|
+
transaction: Transaction,
|
|
22
|
+
fee: BigNumber,
|
|
23
|
+
): MinaOperation => {
|
|
24
|
+
let value = new BigNumber(transaction.amount).plus(fee);
|
|
25
|
+
|
|
26
|
+
if (transaction.fees?.accountCreationFee.gt(0)) {
|
|
27
|
+
value = value.minus(transaction.fees.accountCreationFee);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const type: OperationType = "OUT";
|
|
31
|
+
|
|
32
|
+
const operation: MinaOperation = {
|
|
33
|
+
id: encodeOperationId(account.id, "", type),
|
|
34
|
+
hash: "",
|
|
35
|
+
type,
|
|
36
|
+
value,
|
|
37
|
+
fee,
|
|
38
|
+
blockHash: null,
|
|
39
|
+
blockHeight: null,
|
|
40
|
+
senders: [account.freshAddress],
|
|
41
|
+
recipients: [transaction.recipient].filter(Boolean),
|
|
42
|
+
accountId: account.id,
|
|
43
|
+
date: new Date(),
|
|
44
|
+
extra: {
|
|
45
|
+
memo: transaction.memo,
|
|
46
|
+
accountCreationFee: transaction.fees.accountCreationFee.toString(),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return operation;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Sign Transaction with Ledger hardware
|
|
55
|
+
*/
|
|
56
|
+
export const buildSignOperation =
|
|
57
|
+
(signerContext: SignerContext<MinaSigner>): AccountBridge<Transaction>["signOperation"] =>
|
|
58
|
+
({
|
|
59
|
+
account,
|
|
60
|
+
transaction,
|
|
61
|
+
deviceId,
|
|
62
|
+
}: {
|
|
63
|
+
account: Account;
|
|
64
|
+
transaction: Transaction;
|
|
65
|
+
deviceId: DeviceId;
|
|
66
|
+
}): Observable<SignOperationEvent> =>
|
|
67
|
+
new Observable(o => {
|
|
68
|
+
async function main() {
|
|
69
|
+
o.next({ type: "device-signature-requested" });
|
|
70
|
+
|
|
71
|
+
if (!transaction.fees) {
|
|
72
|
+
throw new FeeNotLoaded();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const unsigned = await buildTransaction(account, transaction);
|
|
76
|
+
|
|
77
|
+
const { signature } = (await signerContext(deviceId, signer =>
|
|
78
|
+
signer.signTransaction(unsigned),
|
|
79
|
+
)) as MinaSignature;
|
|
80
|
+
invariant(signature, "signature should be defined if user accepted");
|
|
81
|
+
const encodedSignature = reEncodeRawSignature(signature);
|
|
82
|
+
|
|
83
|
+
const signedTransaction: MinaSignedTransaction = {
|
|
84
|
+
transaction: unsigned,
|
|
85
|
+
signature: encodedSignature,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
o.next({ type: "device-signature-granted" });
|
|
89
|
+
|
|
90
|
+
const operation = buildOptimisticOperation(
|
|
91
|
+
account,
|
|
92
|
+
transaction,
|
|
93
|
+
transaction.fees.fee ?? new BigNumber(0),
|
|
94
|
+
);
|
|
95
|
+
const signedSerializedTx = JSON.stringify(signedTransaction);
|
|
96
|
+
|
|
97
|
+
o.next({
|
|
98
|
+
type: "signed",
|
|
99
|
+
signedOperation: {
|
|
100
|
+
operation,
|
|
101
|
+
signature: signedSerializedTx,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
main().then(
|
|
107
|
+
() => o.complete(),
|
|
108
|
+
e => o.error(e),
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
export default buildSignOperation;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { getAccountShape, mapRosettaTxnToOperation } from "./synchronisation";
|
|
2
|
+
jest.mock("@ledgerhq/coin-framework/account/accountId");
|
|
3
|
+
jest.mock("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
4
|
+
jest.mock("@ledgerhq/coin-framework/operation");
|
|
5
|
+
jest.mock("../api");
|
|
6
|
+
|
|
7
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account/accountId";
|
|
8
|
+
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
9
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
10
|
+
import { getAccount, getTransactions, getBlockInfo } from "../api";
|
|
11
|
+
import BigNumber from "bignumber.js";
|
|
12
|
+
import {
|
|
13
|
+
createMockTxn,
|
|
14
|
+
createMockAccountInfo,
|
|
15
|
+
mockBlockInfo,
|
|
16
|
+
mockAccountData,
|
|
17
|
+
} from "../test/fixtures";
|
|
18
|
+
|
|
19
|
+
describe("synchronisation", () => {
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
jest.clearAllMocks();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe("mapRosettaTxnToOperation", () => {
|
|
25
|
+
const mockAccountId = "account_id";
|
|
26
|
+
const mockAddress = "sender_address";
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
jest.spyOn({ getBlockInfo }, "getBlockInfo").mockResolvedValue(mockBlockInfo);
|
|
30
|
+
jest
|
|
31
|
+
.spyOn({ encodeOperationId }, "encodeOperationId")
|
|
32
|
+
.mockReturnValue("encoded_operation_id");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should map payment transaction (OUT)", async () => {
|
|
36
|
+
const mockTxn = createMockTxn({
|
|
37
|
+
type: "OUT",
|
|
38
|
+
senderAddress: mockAddress,
|
|
39
|
+
receiverAddress: "receiver_address",
|
|
40
|
+
status: "Success",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const result = await mapRosettaTxnToOperation(mockAccountId, mockAddress, mockTxn);
|
|
44
|
+
|
|
45
|
+
expect(result).toHaveLength(1);
|
|
46
|
+
expect(result[0]).toEqual({
|
|
47
|
+
id: "encoded_operation_id",
|
|
48
|
+
type: "OUT",
|
|
49
|
+
hash: "tx_hash",
|
|
50
|
+
value: new BigNumber(900),
|
|
51
|
+
fee: new BigNumber(-100),
|
|
52
|
+
blockHeight: 123,
|
|
53
|
+
hasFailed: false,
|
|
54
|
+
blockHash: "block_hash",
|
|
55
|
+
accountId: mockAccountId,
|
|
56
|
+
senders: [mockAddress],
|
|
57
|
+
recipients: ["receiver_address"],
|
|
58
|
+
date: new Date(1672531200000),
|
|
59
|
+
extra: {
|
|
60
|
+
memo: "test memo",
|
|
61
|
+
accountCreationFee: "0",
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should map payment transaction (IN)", async () => {
|
|
67
|
+
const mockTxn = createMockTxn({
|
|
68
|
+
type: "IN",
|
|
69
|
+
senderAddress: "sender_other",
|
|
70
|
+
receiverAddress: mockAddress,
|
|
71
|
+
status: "Success",
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const result = await mapRosettaTxnToOperation(mockAccountId, mockAddress, mockTxn);
|
|
75
|
+
|
|
76
|
+
expect(result).toHaveLength(1);
|
|
77
|
+
expect(result[0]).toEqual({
|
|
78
|
+
id: "encoded_operation_id",
|
|
79
|
+
type: "IN",
|
|
80
|
+
hash: "tx_hash",
|
|
81
|
+
value: new BigNumber(1000),
|
|
82
|
+
fee: new BigNumber(-100),
|
|
83
|
+
blockHeight: 123,
|
|
84
|
+
hasFailed: false,
|
|
85
|
+
blockHash: "block_hash",
|
|
86
|
+
accountId: mockAccountId,
|
|
87
|
+
senders: ["sender_other"],
|
|
88
|
+
recipients: [mockAddress],
|
|
89
|
+
date: new Date(1672531200000),
|
|
90
|
+
extra: {
|
|
91
|
+
memo: "test memo",
|
|
92
|
+
accountCreationFee: "0",
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("should map redelegate transaction", async () => {
|
|
98
|
+
const mockTxn = createMockTxn({
|
|
99
|
+
type: "REDELEGATE",
|
|
100
|
+
senderAddress: mockAddress,
|
|
101
|
+
receiverAddress: "not_used",
|
|
102
|
+
memo: "redelegate",
|
|
103
|
+
status: "Success",
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const result = await mapRosettaTxnToOperation(mockAccountId, mockAddress, mockTxn);
|
|
107
|
+
|
|
108
|
+
expect(result).toHaveLength(1);
|
|
109
|
+
expect(result[0]).toEqual({
|
|
110
|
+
id: "encoded_operation_id",
|
|
111
|
+
type: "REDELEGATE",
|
|
112
|
+
hash: "tx_hash",
|
|
113
|
+
value: new BigNumber(0),
|
|
114
|
+
fee: new BigNumber(0),
|
|
115
|
+
blockHeight: 123,
|
|
116
|
+
hasFailed: false,
|
|
117
|
+
blockHash: "block_hash",
|
|
118
|
+
accountId: mockAccountId,
|
|
119
|
+
senders: [mockAddress],
|
|
120
|
+
recipients: ["unknown"],
|
|
121
|
+
date: new Date(1672531200000),
|
|
122
|
+
extra: {
|
|
123
|
+
memo: "redelegate",
|
|
124
|
+
accountCreationFee: "0",
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("should handle failed transactions", async () => {
|
|
130
|
+
const mockTxn = createMockTxn({
|
|
131
|
+
type: "OUT",
|
|
132
|
+
senderAddress: mockAddress,
|
|
133
|
+
receiverAddress: "receiver_address",
|
|
134
|
+
status: "Failed",
|
|
135
|
+
memo: "failed",
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const result = await mapRosettaTxnToOperation(mockAccountId, mockAddress, mockTxn);
|
|
139
|
+
|
|
140
|
+
expect(result).toHaveLength(1);
|
|
141
|
+
expect(result[0].hasFailed).toBe(true);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("getAccountShape", () => {
|
|
146
|
+
beforeEach(() => {
|
|
147
|
+
jest.spyOn({ encodeAccountId }, "encodeAccountId").mockReturnValue("account_id");
|
|
148
|
+
jest.spyOn({ getAccount }, "getAccount").mockResolvedValue(mockAccountData);
|
|
149
|
+
jest.spyOn({ getTransactions }, "getTransactions").mockResolvedValue([]);
|
|
150
|
+
jest.spyOn({ mergeOps }, "mergeOps").mockReturnValue([]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("should get account shape with correct data", async () => {
|
|
154
|
+
const mockInfo = createMockAccountInfo();
|
|
155
|
+
const result = await getAccountShape(mockInfo, {
|
|
156
|
+
paginationConfig: {
|
|
157
|
+
operationsPerAccountId: {
|
|
158
|
+
account_id: 10,
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
expect(encodeAccountId).toHaveBeenCalledWith({
|
|
164
|
+
type: "js",
|
|
165
|
+
version: "2",
|
|
166
|
+
currencyId: "mina",
|
|
167
|
+
xpubOrAddress: "test_address",
|
|
168
|
+
derivationMode: "minabip44",
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
expect(getAccount).toHaveBeenCalledWith("test_address");
|
|
172
|
+
expect(getTransactions).toHaveBeenCalledWith("test_address", 0);
|
|
173
|
+
|
|
174
|
+
expect(result).toEqual({
|
|
175
|
+
id: "account_id",
|
|
176
|
+
balance: mockAccountData.balance,
|
|
177
|
+
spendableBalance: mockAccountData.spendableBalance,
|
|
178
|
+
blockHeight: mockAccountData.blockHeight,
|
|
179
|
+
operationsCount: 0,
|
|
180
|
+
operations: [],
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account/accountId";
|
|
2
|
+
import type { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
3
|
+
import { makeSync, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
|
+
import { getAccount, getBlockInfo, getTransactions } from "../api";
|
|
5
|
+
import { MinaAccount, MinaOperation } from "../types/common";
|
|
6
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
7
|
+
import BigNumber from "bignumber.js";
|
|
8
|
+
import { log } from "@ledgerhq/logs";
|
|
9
|
+
import invariant from "invariant";
|
|
10
|
+
import { RosettaTransaction } from "../api/rosetta/types";
|
|
11
|
+
|
|
12
|
+
export const mapRosettaTxnToOperation = async (
|
|
13
|
+
accountId: string,
|
|
14
|
+
address: string,
|
|
15
|
+
txn: RosettaTransaction,
|
|
16
|
+
): Promise<MinaOperation[]> => {
|
|
17
|
+
try {
|
|
18
|
+
const hash = txn.transaction.transaction_identifier.hash;
|
|
19
|
+
const blockHeight = txn.block_identifier.index;
|
|
20
|
+
const blockHash = txn.block_identifier.hash;
|
|
21
|
+
const date = new Date(txn.timestamp ?? (await getBlockInfo(blockHeight)).block.timestamp);
|
|
22
|
+
const memo = txn.transaction.metadata?.memo || "";
|
|
23
|
+
|
|
24
|
+
let value = new BigNumber(0);
|
|
25
|
+
let fee = new BigNumber(0);
|
|
26
|
+
let accountCreationFee = new BigNumber(0);
|
|
27
|
+
|
|
28
|
+
let fromAccount: string = "";
|
|
29
|
+
let toAccount: string = "";
|
|
30
|
+
let isSending = false;
|
|
31
|
+
let failed = false;
|
|
32
|
+
let redelegateTransaction = false;
|
|
33
|
+
|
|
34
|
+
for (const op of txn.transaction.operations) {
|
|
35
|
+
failed = failed || op.status === "Failed";
|
|
36
|
+
const opValue = failed ? new BigNumber(0) : new BigNumber(op.amount?.value ?? 0);
|
|
37
|
+
switch (op.type) {
|
|
38
|
+
case "fee_payment": {
|
|
39
|
+
fee = fee.plus(opValue.times(-1));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
case "payment_receiver_inc": {
|
|
43
|
+
toAccount = op.account.address;
|
|
44
|
+
value = value.plus(opValue);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
case "payment_source_dec": {
|
|
48
|
+
fromAccount = op.account.address;
|
|
49
|
+
if (fromAccount === address) {
|
|
50
|
+
isSending = true;
|
|
51
|
+
}
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
case "zkapp_fee_payer_dec": {
|
|
55
|
+
fromAccount = op.account.address;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
case "zkapp_balance_update": {
|
|
59
|
+
toAccount = op.account.address;
|
|
60
|
+
value = value.plus(opValue);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
case "delegate_change": {
|
|
64
|
+
fromAccount = op.account.address;
|
|
65
|
+
toAccount = op.metadata?.delegate_change_target || toAccount || "unknown";
|
|
66
|
+
redelegateTransaction = true;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
case "account_creation_fee_via_payment": {
|
|
70
|
+
accountCreationFee = opValue.times(-1);
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
invariant(fromAccount, "mina: missing fromAccount");
|
|
77
|
+
invariant(toAccount, "mina: missing toAccount");
|
|
78
|
+
|
|
79
|
+
const op: MinaOperation = {
|
|
80
|
+
id: "",
|
|
81
|
+
type: "NONE",
|
|
82
|
+
hash,
|
|
83
|
+
value,
|
|
84
|
+
fee,
|
|
85
|
+
blockHeight,
|
|
86
|
+
hasFailed: failed,
|
|
87
|
+
blockHash,
|
|
88
|
+
accountId,
|
|
89
|
+
senders: [fromAccount],
|
|
90
|
+
recipients: [toAccount],
|
|
91
|
+
date,
|
|
92
|
+
extra: {
|
|
93
|
+
memo,
|
|
94
|
+
accountCreationFee: accountCreationFee.toString(),
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const ops: MinaOperation[] = [];
|
|
99
|
+
if (isSending) {
|
|
100
|
+
const type = "OUT";
|
|
101
|
+
ops.push({
|
|
102
|
+
...op,
|
|
103
|
+
value: value.minus(accountCreationFee).plus(fee),
|
|
104
|
+
type,
|
|
105
|
+
id: encodeOperationId(accountId, hash, type),
|
|
106
|
+
});
|
|
107
|
+
} else if (redelegateTransaction) {
|
|
108
|
+
// delegate change
|
|
109
|
+
const type = "REDELEGATE";
|
|
110
|
+
ops.push({
|
|
111
|
+
...op,
|
|
112
|
+
value: new BigNumber(0),
|
|
113
|
+
type,
|
|
114
|
+
id: encodeOperationId(accountId, hash, type),
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
const type = "IN";
|
|
118
|
+
ops.push({
|
|
119
|
+
...op,
|
|
120
|
+
value: value.minus(accountCreationFee),
|
|
121
|
+
type,
|
|
122
|
+
id: encodeOperationId(accountId, hash, type),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return ops;
|
|
127
|
+
} catch (e) {
|
|
128
|
+
log("error", "mina: failed to convert txn to operation", {
|
|
129
|
+
error: e,
|
|
130
|
+
transaction: txn,
|
|
131
|
+
});
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const getAccountShape: GetAccountShape<MinaAccount> = async info => {
|
|
137
|
+
const { address, initialAccount, currency, derivationMode } = info;
|
|
138
|
+
const oldOperations = initialAccount?.operations || [];
|
|
139
|
+
|
|
140
|
+
const accountId = encodeAccountId({
|
|
141
|
+
type: "js",
|
|
142
|
+
version: "2",
|
|
143
|
+
currencyId: currency.id,
|
|
144
|
+
xpubOrAddress: address,
|
|
145
|
+
derivationMode,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const { blockHeight, balance, spendableBalance } = await getAccount(address);
|
|
149
|
+
|
|
150
|
+
const rosettaTxns = await getTransactions(address, initialAccount?.operations.length);
|
|
151
|
+
const newOperations = await Promise.all(
|
|
152
|
+
rosettaTxns.flatMap(t => mapRosettaTxnToOperation(accountId, address, t)),
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
const operations = mergeOps(oldOperations, newOperations.flat());
|
|
156
|
+
|
|
157
|
+
const shape: Partial<MinaAccount> = {
|
|
158
|
+
id: accountId,
|
|
159
|
+
balance,
|
|
160
|
+
spendableBalance,
|
|
161
|
+
operationsCount: operations.length,
|
|
162
|
+
blockHeight,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return { ...shape, operations };
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const sync = makeSync({ getAccountShape });
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Transaction, TransactionRaw } from "../types/common";
|
|
2
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
3
|
+
import {
|
|
4
|
+
fromTransactionCommonRaw,
|
|
5
|
+
fromTransactionStatusRawCommon as fromTransactionStatusRaw,
|
|
6
|
+
toTransactionCommonRaw,
|
|
7
|
+
toTransactionStatusRawCommon as toTransactionStatusRaw,
|
|
8
|
+
} from "@ledgerhq/coin-framework/serialization";
|
|
9
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
10
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
12
|
+
import BigNumber from "bignumber.js";
|
|
13
|
+
|
|
14
|
+
export const formatTransaction = (
|
|
15
|
+
{ recipient, useAllAmount, amount }: Transaction,
|
|
16
|
+
account: Account,
|
|
17
|
+
): string => `
|
|
18
|
+
SEND ${
|
|
19
|
+
useAllAmount
|
|
20
|
+
? "MAX"
|
|
21
|
+
: amount.isZero()
|
|
22
|
+
? ""
|
|
23
|
+
: " " +
|
|
24
|
+
formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
|
|
25
|
+
showCode: true,
|
|
26
|
+
disableRounding: true,
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
TO ${recipient}`;
|
|
30
|
+
|
|
31
|
+
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
32
|
+
const common = fromTransactionCommonRaw(tr);
|
|
33
|
+
return {
|
|
34
|
+
...common,
|
|
35
|
+
family: tr.family,
|
|
36
|
+
fees: {
|
|
37
|
+
fee: new BigNumber(tr.fees.fee),
|
|
38
|
+
accountCreationFee: new BigNumber(tr.fees.accountCreationFee),
|
|
39
|
+
},
|
|
40
|
+
amount: new BigNumber(tr.amount),
|
|
41
|
+
memo: tr.memo,
|
|
42
|
+
nonce: tr.nonce,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
47
|
+
const common = toTransactionCommonRaw(t);
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
...common,
|
|
51
|
+
family: t.family,
|
|
52
|
+
amount: t.amount.toFixed(),
|
|
53
|
+
fees: {
|
|
54
|
+
fee: t.fees.fee.toString(),
|
|
55
|
+
accountCreationFee: t.fees.accountCreationFee.toString(),
|
|
56
|
+
},
|
|
57
|
+
memo: t.memo ?? undefined,
|
|
58
|
+
nonce: t.nonce,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export default {
|
|
63
|
+
formatTransaction,
|
|
64
|
+
fromTransactionRaw,
|
|
65
|
+
toTransactionRaw,
|
|
66
|
+
fromTransactionStatusRaw,
|
|
67
|
+
toTransactionStatusRaw,
|
|
68
|
+
formatTransactionStatus,
|
|
69
|
+
};
|