@ledgerhq/coin-aptos 1.4.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/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +16 -0
- package/CHANGELOG.md +18 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/__tests__/api/index.test.d.ts +2 -0
- package/lib/__tests__/api/index.test.d.ts.map +1 -0
- package/lib/__tests__/api/index.test.js +447 -0
- package/lib/__tests__/api/index.test.js.map +1 -0
- package/lib/__tests__/bridge/broadcast.test.d.ts +2 -0
- package/lib/__tests__/bridge/broadcast.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/broadcast.test.js +98 -0
- package/lib/__tests__/bridge/broadcast.test.js.map +1 -0
- package/lib/__tests__/bridge/buildTransaction.test.d.ts +2 -0
- package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/buildTransaction.test.js +62 -0
- package/lib/__tests__/bridge/buildTransaction.test.js.map +1 -0
- package/lib/__tests__/bridge/createTransaction.test.d.ts +2 -0
- package/lib/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/createTransaction.test.js +38 -0
- package/lib/__tests__/bridge/createTransaction.test.js.map +1 -0
- package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
- package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/deviceTransactionConfig.test.js +43 -0
- package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
- package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
- package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/estimateMaxSpendable.test.js +84 -0
- package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
- package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
- package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/getFeesForTransaction.test.js +188 -0
- package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
- package/lib/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/getTransactionStatus.test.js +133 -0
- package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib/__tests__/bridge/index.test.d.ts +2 -0
- package/lib/__tests__/bridge/index.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/index.test.js +116 -0
- package/lib/__tests__/bridge/index.test.js.map +1 -0
- package/lib/__tests__/bridge/logic.test.d.ts +2 -0
- package/lib/__tests__/bridge/logic.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/logic.test.js +773 -0
- package/lib/__tests__/bridge/logic.test.js.map +1 -0
- package/lib/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/prepareTransaction.test.js +121 -0
- package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -0
- package/lib/__tests__/bridge/signOperation.test.d.ts +2 -0
- package/lib/__tests__/bridge/signOperation.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/signOperation.test.js +185 -0
- package/lib/__tests__/bridge/signOperation.test.js.map +1 -0
- package/lib/__tests__/bridge/synchronisation.test.d.ts +2 -0
- package/lib/__tests__/bridge/synchronisation.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/synchronisation.test.js +349 -0
- package/lib/__tests__/bridge/synchronisation.test.js.map +1 -0
- package/lib/__tests__/bridge/transaction.test.d.ts +2 -0
- package/lib/__tests__/bridge/transaction.test.d.ts.map +1 -0
- package/lib/__tests__/bridge/transaction.test.js +231 -0
- package/lib/__tests__/bridge/transaction.test.js.map +1 -0
- package/lib/__tests__/errors.test.d.ts +2 -0
- package/lib/__tests__/errors.test.d.ts.map +1 -0
- package/lib/__tests__/errors.test.js +18 -0
- package/lib/__tests__/errors.test.js.map +1 -0
- package/lib/__tests__/index.test.d.ts +2 -0
- package/lib/__tests__/index.test.d.ts.map +1 -0
- package/lib/__tests__/index.test.js +27 -0
- package/lib/__tests__/index.test.js.map +1 -0
- package/lib/__tests__/network/index.test.d.ts +2 -0
- package/lib/__tests__/network/index.test.d.ts.map +1 -0
- package/lib/__tests__/network/index.test.js +57 -0
- package/lib/__tests__/network/index.test.js.map +1 -0
- package/lib/__tests__/signer/index.test.d.ts +2 -0
- package/lib/__tests__/signer/index.test.d.ts.map +1 -0
- package/lib/__tests__/signer/index.test.js +37 -0
- package/lib/__tests__/signer/index.test.js.map +1 -0
- package/lib/api/graphql/queries.d.ts +5 -0
- package/lib/api/graphql/queries.d.ts.map +1 -0
- package/lib/api/graphql/queries.js +56 -0
- package/lib/api/graphql/queries.js.map +1 -0
- package/lib/api/graphql/types.d.ts +79 -0
- package/lib/api/graphql/types.d.ts.map +1 -0
- package/lib/api/graphql/types.js +3 -0
- package/lib/api/graphql/types.js.map +1 -0
- package/lib/api/index.d.ts +31 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +200 -0
- package/lib/api/index.js.map +1 -0
- package/lib/bridge/bridge.fixture.d.ts +4 -0
- package/lib/bridge/bridge.fixture.d.ts.map +1 -0
- package/lib/bridge/bridge.fixture.js +56 -0
- package/lib/bridge/bridge.fixture.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +7 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +20 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildTransaction.d.ts +7 -0
- package/lib/bridge/buildTransaction.d.ts.map +1 -0
- package/lib/bridge/buildTransaction.js +28 -0
- package/lib/bridge/buildTransaction.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 +20 -0
- package/lib/bridge/createTransaction.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 +23 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +10 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +30 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getFeesForTransaction.d.ts +16 -0
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib/bridge/getFeesForTransaction.js +74 -0
- package/lib/bridge/getFeesForTransaction.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 +48 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +8 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +54 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/logic.d.ts +24 -0
- package/lib/bridge/logic.d.ts.map +1 -0
- package/lib/bridge/logic.js +200 -0
- package/lib/bridge/logic.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +5 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +44 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +11 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +77 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/synchronisation.d.ts +3 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -0
- package/lib/bridge/synchronisation.js +53 -0
- package/lib/bridge/synchronisation.js.map +1 -0
- package/lib/bridge/transaction.d.ts +15 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +37 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/constants.d.ts +19 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +33 -0
- package/lib/constants.js.map +1 -0
- package/lib/errors.d.ts +10 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +8 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/network/index.d.ts +6 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +39 -0
- package/lib/network/index.js.map +1 -0
- package/lib/signer/index.d.ts +6 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +23 -0
- package/lib/signer/index.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 +77 -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 +85 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +19 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +59 -0
- package/lib/test/cli.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/speculos-deviceActions.d.ts +5 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib/test/speculos-deviceActions.js +46 -0
- package/lib/test/speculos-deviceActions.js.map +1 -0
- package/lib/types/bridge.d.ts +5 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +9 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/index.d.ts +62 -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 +27 -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/__tests__/api/index.test.d.ts +2 -0
- package/lib-es/__tests__/api/index.test.d.ts.map +1 -0
- package/lib-es/__tests__/api/index.test.js +442 -0
- package/lib-es/__tests__/api/index.test.js.map +1 -0
- package/lib-es/__tests__/bridge/broadcast.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/broadcast.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/broadcast.test.js +93 -0
- package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -0
- package/lib-es/__tests__/bridge/buildTransaction.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/buildTransaction.test.js +57 -0
- package/lib-es/__tests__/bridge/buildTransaction.test.js.map +1 -0
- package/lib-es/__tests__/bridge/createTransaction.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/createTransaction.test.js +33 -0
- package/lib-es/__tests__/bridge/createTransaction.test.js.map +1 -0
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +18 -0
- package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
- package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +79 -0
- package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +160 -0
- package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
- package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js +128 -0
- package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
- package/lib-es/__tests__/bridge/index.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/index.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/index.test.js +111 -0
- package/lib-es/__tests__/bridge/index.test.js.map +1 -0
- package/lib-es/__tests__/bridge/logic.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/logic.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/logic.test.js +768 -0
- package/lib-es/__tests__/bridge/logic.test.js.map +1 -0
- package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/prepareTransaction.test.js +116 -0
- package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -0
- package/lib-es/__tests__/bridge/signOperation.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/signOperation.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/signOperation.test.js +157 -0
- package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -0
- package/lib-es/__tests__/bridge/synchronisation.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/synchronisation.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/synchronisation.test.js +347 -0
- package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -0
- package/lib-es/__tests__/bridge/transaction.test.d.ts +2 -0
- package/lib-es/__tests__/bridge/transaction.test.d.ts.map +1 -0
- package/lib-es/__tests__/bridge/transaction.test.js +226 -0
- package/lib-es/__tests__/bridge/transaction.test.js.map +1 -0
- package/lib-es/__tests__/errors.test.d.ts +2 -0
- package/lib-es/__tests__/errors.test.d.ts.map +1 -0
- package/lib-es/__tests__/errors.test.js +16 -0
- package/lib-es/__tests__/errors.test.js.map +1 -0
- package/lib-es/__tests__/index.test.d.ts +2 -0
- package/lib-es/__tests__/index.test.d.ts.map +1 -0
- package/lib-es/__tests__/index.test.js +25 -0
- package/lib-es/__tests__/index.test.js.map +1 -0
- package/lib-es/__tests__/network/index.test.d.ts +2 -0
- package/lib-es/__tests__/network/index.test.d.ts.map +1 -0
- package/lib-es/__tests__/network/index.test.js +55 -0
- package/lib-es/__tests__/network/index.test.js.map +1 -0
- package/lib-es/__tests__/signer/index.test.d.ts +2 -0
- package/lib-es/__tests__/signer/index.test.d.ts.map +1 -0
- package/lib-es/__tests__/signer/index.test.js +32 -0
- package/lib-es/__tests__/signer/index.test.js.map +1 -0
- package/lib-es/api/graphql/queries.d.ts +5 -0
- package/lib-es/api/graphql/queries.d.ts.map +1 -0
- package/lib-es/api/graphql/queries.js +53 -0
- package/lib-es/api/graphql/queries.js.map +1 -0
- package/lib-es/api/graphql/types.d.ts +79 -0
- package/lib-es/api/graphql/types.d.ts.map +1 -0
- package/lib-es/api/graphql/types.js +2 -0
- package/lib-es/api/graphql/types.js.map +1 -0
- package/lib-es/api/index.d.ts +31 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +193 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/bridge/bridge.fixture.d.ts +4 -0
- package/lib-es/bridge/bridge.fixture.d.ts.map +1 -0
- package/lib-es/bridge/bridge.fixture.js +48 -0
- package/lib-es/bridge/bridge.fixture.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +7 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +18 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildTransaction.d.ts +7 -0
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
- package/lib-es/bridge/buildTransaction.js +26 -0
- package/lib-es/bridge/buildTransaction.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 +15 -0
- package/lib-es/bridge/createTransaction.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 +19 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +10 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +28 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts +16 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.js +66 -0
- package/lib-es/bridge/getFeesForTransaction.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 +46 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +8 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +47 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/logic.d.ts +24 -0
- package/lib-es/bridge/logic.d.ts.map +1 -0
- package/lib-es/bridge/logic.js +183 -0
- package/lib-es/bridge/logic.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +5 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +39 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +11 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +70 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/synchronisation.d.ts +3 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -0
- package/lib-es/bridge/synchronisation.js +49 -0
- package/lib-es/bridge/synchronisation.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +15 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +31 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/constants.d.ts +19 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +30 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/errors.d.ts +10 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +5 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/index.d.ts +3 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +3 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/network/index.d.ts +6 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +35 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/signer/index.d.ts +6 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +21 -0
- package/lib-es/signer/index.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 +72 -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 +79 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +19 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +53 -0
- package/lib-es/test/cli.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/speculos-deviceActions.d.ts +5 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/test/speculos-deviceActions.js +43 -0
- package/lib-es/test/speculos-deviceActions.js.map +1 -0
- package/lib-es/types/bridge.d.ts +5 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +6 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/index.d.ts +62 -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 +27 -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 +124 -0
- package/src/__tests__/api/index.test.ts +499 -0
- package/src/__tests__/bridge/broadcast.test.ts +98 -0
- package/src/__tests__/bridge/buildTransaction.test.ts +61 -0
- package/src/__tests__/bridge/createTransaction.test.ts +27 -0
- package/src/__tests__/bridge/deviceTransactionConfig.test.ts +19 -0
- package/src/__tests__/bridge/estimateMaxSpendable.test.ts +94 -0
- package/src/__tests__/bridge/getFeesForTransaction.test.ts +189 -0
- package/src/__tests__/bridge/getTransactionStatus.test.ts +155 -0
- package/src/__tests__/bridge/index.test.ts +108 -0
- package/src/__tests__/bridge/logic.test.ts +876 -0
- package/src/__tests__/bridge/prepareTransaction.test.ts +118 -0
- package/src/__tests__/bridge/signOperation.test.ts +178 -0
- package/src/__tests__/bridge/synchronisation.test.ts +374 -0
- package/src/__tests__/bridge/transaction.test.ts +261 -0
- package/src/__tests__/errors.test.ts +25 -0
- package/src/__tests__/index.test.ts +26 -0
- package/src/__tests__/network/index.test.ts +95 -0
- package/src/__tests__/signer/index.test.ts +24 -0
- package/src/api/graphql/queries.ts +53 -0
- package/src/api/graphql/types.ts +85 -0
- package/src/api/index.ts +224 -0
- package/src/bridge/bridge.fixture.ts +53 -0
- package/src/bridge/broadcast.ts +17 -0
- package/src/bridge/buildTransaction.ts +29 -0
- package/src/bridge/createTransaction.ts +17 -0
- package/src/bridge/deviceTransactionConfig.ts +30 -0
- package/src/bridge/estimateMaxSpendable.ts +35 -0
- package/src/bridge/getFeesForTransaction.ts +87 -0
- package/src/bridge/getTransactionStatus.ts +54 -0
- package/src/bridge/index.ts +65 -0
- package/src/bridge/logic.ts +265 -0
- package/src/bridge/prepareTransaction.ts +55 -0
- package/src/bridge/signOperation.ts +82 -0
- package/src/bridge/synchronisation.ts +50 -0
- package/src/bridge/transaction.ts +61 -0
- package/src/constants.ts +34 -0
- package/src/errors.ts +7 -0
- package/src/index.ts +3 -0
- package/src/network/index.ts +54 -0
- package/src/signer/index.ts +17 -0
- package/src/test/bot-specs.ts +86 -0
- package/src/test/bridgeDatasetTest.ts +82 -0
- package/src/test/cli.ts +80 -0
- package/src/test/index.ts +3 -0
- package/src/test/speculos-deviceActions.ts +52 -0
- package/src/types/bridge.ts +4 -0
- package/src/types/index.ts +74 -0
- package/src/types/signer.ts +26 -0
- package/tsconfig.json +14 -0
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { ApolloClient, InMemoryCache } from "@apollo/client";
|
|
2
|
+
import {
|
|
3
|
+
AccountData,
|
|
4
|
+
Aptos,
|
|
5
|
+
AptosApiType,
|
|
6
|
+
AptosConfig,
|
|
7
|
+
Ed25519PublicKey,
|
|
8
|
+
GasEstimation,
|
|
9
|
+
InputEntryFunctionData,
|
|
10
|
+
InputGenerateTransactionOptions,
|
|
11
|
+
MimeType,
|
|
12
|
+
post,
|
|
13
|
+
RawTransaction,
|
|
14
|
+
SimpleTransaction,
|
|
15
|
+
TransactionResponse,
|
|
16
|
+
UserTransactionResponse,
|
|
17
|
+
PostRequestOptions,
|
|
18
|
+
Block,
|
|
19
|
+
} from "@aptos-labs/ts-sdk";
|
|
20
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
21
|
+
import network from "@ledgerhq/live-network";
|
|
22
|
+
import BigNumber from "bignumber.js";
|
|
23
|
+
import isUndefined from "lodash/isUndefined";
|
|
24
|
+
import { APTOS_ASSET_ID } from "../constants";
|
|
25
|
+
import { isTestnet } from "../bridge/logic";
|
|
26
|
+
import type { AptosTransaction, TransactionOptions } from "../types";
|
|
27
|
+
import { GetAccountTransactionsData, GetAccountTransactionsDataGt } from "./graphql/queries";
|
|
28
|
+
import {
|
|
29
|
+
GetAccountTransactionsDataQuery,
|
|
30
|
+
GetAccountTransactionsDataGtQueryVariables,
|
|
31
|
+
} from "./graphql/types";
|
|
32
|
+
|
|
33
|
+
const getApiEndpoint = (currencyId: string) =>
|
|
34
|
+
isTestnet(currencyId) ? getEnv("APTOS_TESTNET_API_ENDPOINT") : getEnv("APTOS_API_ENDPOINT");
|
|
35
|
+
const getIndexerEndpoint = (currencyId: string) =>
|
|
36
|
+
isTestnet(currencyId)
|
|
37
|
+
? getEnv("APTOS_TESTNET_INDEXER_ENDPOINT")
|
|
38
|
+
: getEnv("APTOS_INDEXER_ENDPOINT");
|
|
39
|
+
|
|
40
|
+
export class AptosAPI {
|
|
41
|
+
private apiUrl: string;
|
|
42
|
+
private indexerUrl: string;
|
|
43
|
+
private aptosConfig: AptosConfig;
|
|
44
|
+
private aptosClient: Aptos;
|
|
45
|
+
private apolloClient: ApolloClient<object>;
|
|
46
|
+
|
|
47
|
+
constructor(currencyId: string) {
|
|
48
|
+
this.apiUrl = getApiEndpoint(currencyId);
|
|
49
|
+
this.indexerUrl = getIndexerEndpoint(currencyId);
|
|
50
|
+
this.aptosConfig = new AptosConfig({
|
|
51
|
+
fullnode: this.apiUrl,
|
|
52
|
+
indexer: this.indexerUrl,
|
|
53
|
+
});
|
|
54
|
+
this.aptosClient = new Aptos(this.aptosConfig);
|
|
55
|
+
this.apolloClient = new ApolloClient({
|
|
56
|
+
uri: this.indexerUrl,
|
|
57
|
+
cache: new InMemoryCache(),
|
|
58
|
+
headers: {
|
|
59
|
+
"x-client": "ledger-live",
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async getAccount(address: string): Promise<AccountData> {
|
|
65
|
+
return this.aptosClient.getAccountInfo({ accountAddress: address });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getAccountInfo(address: string, startAt: string) {
|
|
69
|
+
const [balance, transactions, blockHeight] = await Promise.all([
|
|
70
|
+
this.getBalance(address),
|
|
71
|
+
this.fetchTransactions(address, startAt),
|
|
72
|
+
this.getHeight(),
|
|
73
|
+
]);
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
balance,
|
|
77
|
+
transactions,
|
|
78
|
+
blockHeight,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async estimateGasPrice(): Promise<GasEstimation> {
|
|
83
|
+
return this.aptosClient.getGasPriceEstimation();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async generateTransaction(
|
|
87
|
+
address: string,
|
|
88
|
+
payload: InputEntryFunctionData,
|
|
89
|
+
options: TransactionOptions,
|
|
90
|
+
): Promise<RawTransaction> {
|
|
91
|
+
const opts: Partial<InputGenerateTransactionOptions> = {};
|
|
92
|
+
if (!isUndefined(options.maxGasAmount)) {
|
|
93
|
+
opts.maxGasAmount = Number(options.maxGasAmount);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!isUndefined(options.gasUnitPrice)) {
|
|
97
|
+
opts.gasUnitPrice = Number(options.gasUnitPrice);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
const { ledger_timestamp } = await this.aptosClient.getLedgerInfo();
|
|
102
|
+
opts.expireTimestamp = Number(Math.ceil(+ledger_timestamp / 1_000_000 + 2 * 60)); // in milliseconds
|
|
103
|
+
} catch {
|
|
104
|
+
// skip
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return this.aptosClient.transaction.build
|
|
108
|
+
.simple({
|
|
109
|
+
sender: address,
|
|
110
|
+
data: payload,
|
|
111
|
+
options: opts,
|
|
112
|
+
})
|
|
113
|
+
.then(t => t.rawTransaction)
|
|
114
|
+
.catch(error => {
|
|
115
|
+
throw error;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async simulateTransaction(
|
|
120
|
+
address: Ed25519PublicKey,
|
|
121
|
+
tx: RawTransaction,
|
|
122
|
+
options = {
|
|
123
|
+
estimateGasUnitPrice: true,
|
|
124
|
+
estimateMaxGasAmount: true,
|
|
125
|
+
estimatePrioritizedGasUnitPrice: false,
|
|
126
|
+
},
|
|
127
|
+
): Promise<UserTransactionResponse[]> {
|
|
128
|
+
return this.aptosClient.transaction.simulate.simple({
|
|
129
|
+
signerPublicKey: address,
|
|
130
|
+
transaction: { rawTransaction: tx } as SimpleTransaction,
|
|
131
|
+
options,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async broadcast(signature: string): Promise<string> {
|
|
136
|
+
const txBytes = Uint8Array.from(Buffer.from(signature, "hex"));
|
|
137
|
+
const pendingTx = await post<PostRequestOptions, TransactionResponse>({
|
|
138
|
+
contentType: MimeType.BCS_SIGNED_TRANSACTION,
|
|
139
|
+
aptosConfig: this.aptosClient.config,
|
|
140
|
+
body: txBytes,
|
|
141
|
+
path: "transactions",
|
|
142
|
+
type: AptosApiType.FULLNODE,
|
|
143
|
+
originMethod: "",
|
|
144
|
+
});
|
|
145
|
+
return pendingTx.data.hash;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private async getBalance(address: string): Promise<BigNumber> {
|
|
149
|
+
try {
|
|
150
|
+
const [balanceStr] = await this.aptosClient.view<[string]>({
|
|
151
|
+
payload: {
|
|
152
|
+
function: "0x1::coin::balance",
|
|
153
|
+
typeArguments: [APTOS_ASSET_ID],
|
|
154
|
+
functionArguments: [address],
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
const balance = parseInt(balanceStr, 10);
|
|
158
|
+
return new BigNumber(balance);
|
|
159
|
+
} catch (_) {
|
|
160
|
+
return new BigNumber(0);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private async fetchTransactions(address: string, gt?: string) {
|
|
165
|
+
if (!address) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let query = GetAccountTransactionsData;
|
|
170
|
+
if (gt) {
|
|
171
|
+
query = GetAccountTransactionsDataGt;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const queryResponse = await this.apolloClient.query<
|
|
175
|
+
GetAccountTransactionsDataQuery,
|
|
176
|
+
GetAccountTransactionsDataGtQueryVariables
|
|
177
|
+
>({
|
|
178
|
+
query,
|
|
179
|
+
variables: {
|
|
180
|
+
address,
|
|
181
|
+
limit: 1000,
|
|
182
|
+
gt,
|
|
183
|
+
},
|
|
184
|
+
fetchPolicy: "network-only",
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
return Promise.all(
|
|
188
|
+
queryResponse.data.address_version_from_move_resources.map(({ transaction_version }) => {
|
|
189
|
+
return this.richItemByVersion(transaction_version);
|
|
190
|
+
}),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private async richItemByVersion(version: number): Promise<AptosTransaction | null> {
|
|
195
|
+
try {
|
|
196
|
+
const tx: TransactionResponse = await this.aptosClient.getTransactionByVersion({
|
|
197
|
+
ledgerVersion: version,
|
|
198
|
+
});
|
|
199
|
+
const block = await this.getBlock(version);
|
|
200
|
+
return {
|
|
201
|
+
...tx,
|
|
202
|
+
block,
|
|
203
|
+
} as AptosTransaction;
|
|
204
|
+
} catch (error) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
private async getHeight(): Promise<number> {
|
|
210
|
+
const { data } = await network<Block>({
|
|
211
|
+
method: "GET",
|
|
212
|
+
url: this.apiUrl,
|
|
213
|
+
});
|
|
214
|
+
return parseInt(data.block_height);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private async getBlock(version: number) {
|
|
218
|
+
const block = await this.aptosClient.getBlockByVersion({ ledgerVersion: version });
|
|
219
|
+
return {
|
|
220
|
+
height: parseInt(block.block_height),
|
|
221
|
+
hash: block.block_hash,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { faker } from "@faker-js/faker";
|
|
3
|
+
import type { AptosAccount, Transaction } from "../types/index";
|
|
4
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
5
|
+
import { emptyHistoryCache } from "@ledgerhq/coin-framework/account/index";
|
|
6
|
+
|
|
7
|
+
const currency = getCryptoCurrencyById("aptos");
|
|
8
|
+
|
|
9
|
+
export function createFixtureAccount(account?: Partial<AptosAccount>): AptosAccount {
|
|
10
|
+
const freshAddress = {
|
|
11
|
+
address: "address",
|
|
12
|
+
derivationPath: "derivation_path",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
type: "Account",
|
|
17
|
+
id: faker.string.uuid(),
|
|
18
|
+
seedIdentifier: faker.string.uuid(),
|
|
19
|
+
derivationMode: "",
|
|
20
|
+
index: faker.number.int(),
|
|
21
|
+
freshAddress: account?.freshAddress || freshAddress.address,
|
|
22
|
+
freshAddressPath: account?.freshAddressPath || freshAddress.derivationPath,
|
|
23
|
+
used: true,
|
|
24
|
+
balance: account?.balance || new BigNumber(0),
|
|
25
|
+
spendableBalance: account?.spendableBalance || new BigNumber(0),
|
|
26
|
+
creationDate: faker.date.past(),
|
|
27
|
+
blockHeight: faker.number.int({ min: 100_000, max: 200_000 }),
|
|
28
|
+
currency,
|
|
29
|
+
operationsCount: account?.operationsCount || 0,
|
|
30
|
+
operations: account?.operations || [],
|
|
31
|
+
pendingOperations: account?.pendingOperations || [],
|
|
32
|
+
lastSyncDate: new Date(),
|
|
33
|
+
balanceHistoryCache: emptyHistoryCache,
|
|
34
|
+
swapHistory: [],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function createFixtureTransaction(tx?: Partial<Transaction>): Transaction {
|
|
39
|
+
const transaction: Transaction = {
|
|
40
|
+
amount: tx?.amount || new BigNumber(0),
|
|
41
|
+
recipient: tx?.recipient || "",
|
|
42
|
+
useAllAmount: tx?.useAllAmount || false,
|
|
43
|
+
family: "aptos",
|
|
44
|
+
mode: tx?.mode || "send",
|
|
45
|
+
fees: tx?.fees || null,
|
|
46
|
+
options: {
|
|
47
|
+
maxGasAmount: BigNumber(0).toString(),
|
|
48
|
+
gasUnitPrice: BigNumber(0).toString(),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return transaction;
|
|
53
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Account, Operation, SignedOperation } from "@ledgerhq/types-live";
|
|
2
|
+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
3
|
+
import { AptosAPI } from "../api";
|
|
4
|
+
|
|
5
|
+
const broadcast = async ({
|
|
6
|
+
signedOperation,
|
|
7
|
+
account,
|
|
8
|
+
}: {
|
|
9
|
+
signedOperation: SignedOperation;
|
|
10
|
+
account: Account;
|
|
11
|
+
}): Promise<Operation> => {
|
|
12
|
+
const { signature, operation } = signedOperation;
|
|
13
|
+
const hash = await new AptosAPI(account.currency.id).broadcast(signature);
|
|
14
|
+
return patchOperationWithHash(operation, hash);
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default broadcast;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { InputEntryFunctionData, RawTransaction } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
|
+
import { AptosAPI } from "../api";
|
|
5
|
+
import { APTOS_ASSET_ID } from "../constants";
|
|
6
|
+
import { normalizeTransactionOptions } from "./logic";
|
|
7
|
+
import type { Transaction } from "../types";
|
|
8
|
+
|
|
9
|
+
const buildTransaction = async (
|
|
10
|
+
account: Account,
|
|
11
|
+
transaction: Transaction,
|
|
12
|
+
aptosClient: AptosAPI,
|
|
13
|
+
): Promise<RawTransaction> => {
|
|
14
|
+
const txPayload = getPayload(transaction.recipient, transaction.amount);
|
|
15
|
+
const txOptions = normalizeTransactionOptions(transaction.options);
|
|
16
|
+
const tx = await aptosClient.generateTransaction(account.freshAddress, txPayload, txOptions);
|
|
17
|
+
|
|
18
|
+
return tx;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getPayload = (sendTo: string, amount: BigNumber): InputEntryFunctionData => {
|
|
22
|
+
return {
|
|
23
|
+
function: "0x1::aptos_account::transfer_coins",
|
|
24
|
+
typeArguments: [APTOS_ASSET_ID],
|
|
25
|
+
functionArguments: [sendTo, amount.toString()],
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default buildTransaction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import type { Transaction } from "../types";
|
|
3
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE } from "./logic";
|
|
4
|
+
|
|
5
|
+
const createTransaction = (): Transaction => ({
|
|
6
|
+
family: "aptos",
|
|
7
|
+
mode: "send",
|
|
8
|
+
amount: BigNumber(0),
|
|
9
|
+
recipient: "",
|
|
10
|
+
useAllAmount: false,
|
|
11
|
+
options: {
|
|
12
|
+
maxGasAmount: DEFAULT_GAS.toString(),
|
|
13
|
+
gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default createTransaction;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
export const methodToString = (method: number): string => {
|
|
5
|
+
switch (method) {
|
|
6
|
+
case 0:
|
|
7
|
+
return "Coin transfer";
|
|
8
|
+
default:
|
|
9
|
+
return "Unknown";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type ExtraDeviceTransactionField = {
|
|
14
|
+
type: "aptos.extendedAmount";
|
|
15
|
+
label: string;
|
|
16
|
+
value: number | BigNumber;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function getDeviceTransactionConfig(): Array<DeviceTransactionField> {
|
|
20
|
+
const fields: Array<DeviceTransactionField> = [];
|
|
21
|
+
fields.push({
|
|
22
|
+
type: "text",
|
|
23
|
+
label: "Type",
|
|
24
|
+
value: methodToString(0),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return fields;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default getDeviceTransactionConfig;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
+
import { AptosAPI } from "../api";
|
|
5
|
+
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
6
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";
|
|
7
|
+
import type { Transaction } from "../types";
|
|
8
|
+
|
|
9
|
+
const estimateMaxSpendable = async ({
|
|
10
|
+
account,
|
|
11
|
+
parentAccount,
|
|
12
|
+
transaction,
|
|
13
|
+
}: {
|
|
14
|
+
account: AccountLike;
|
|
15
|
+
parentAccount?: Account;
|
|
16
|
+
transaction?: Transaction;
|
|
17
|
+
}): Promise<BigNumber> => {
|
|
18
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
19
|
+
|
|
20
|
+
const aptosClient = new AptosAPI(mainAccount.currency.id);
|
|
21
|
+
|
|
22
|
+
let maxGasAmount = new BigNumber(DEFAULT_GAS);
|
|
23
|
+
let gasUnitPrice = new BigNumber(DEFAULT_GAS_PRICE);
|
|
24
|
+
|
|
25
|
+
if (transaction) {
|
|
26
|
+
const { estimate } = await getEstimatedGas(mainAccount, transaction, aptosClient);
|
|
27
|
+
|
|
28
|
+
maxGasAmount = BigNumber(estimate.maxGasAmount);
|
|
29
|
+
gasUnitPrice = BigNumber(estimate.gasUnitPrice);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return getMaxSendBalance(mainAccount.spendableBalance, maxGasAmount, gasUnitPrice);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default estimateMaxSpendable;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Ed25519PublicKey } from "@aptos-labs/ts-sdk";
|
|
2
|
+
import { log } from "@ledgerhq/logs";
|
|
3
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
import { makeLRUCache, seconds } from "@ledgerhq/live-network/cache";
|
|
6
|
+
import { AptosAPI } from "../api";
|
|
7
|
+
import buildTransaction from "./buildTransaction";
|
|
8
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, ESTIMATE_GAS_MUL } from "./logic";
|
|
9
|
+
import type { Transaction, TransactionErrors } from "../types";
|
|
10
|
+
|
|
11
|
+
type IGetEstimatedGasReturnType = {
|
|
12
|
+
fees: BigNumber;
|
|
13
|
+
estimate: {
|
|
14
|
+
maxGasAmount: string;
|
|
15
|
+
gasUnitPrice: string;
|
|
16
|
+
};
|
|
17
|
+
errors: TransactionErrors;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const getFee = async (
|
|
21
|
+
account: Account,
|
|
22
|
+
transaction: Transaction,
|
|
23
|
+
aptosClient: AptosAPI,
|
|
24
|
+
): Promise<IGetEstimatedGasReturnType> => {
|
|
25
|
+
const res = {
|
|
26
|
+
fees: new BigNumber(DEFAULT_GAS).multipliedBy(DEFAULT_GAS_PRICE),
|
|
27
|
+
estimate: {
|
|
28
|
+
maxGasAmount: DEFAULT_GAS.toString(),
|
|
29
|
+
gasUnitPrice: DEFAULT_GAS_PRICE.toString(),
|
|
30
|
+
},
|
|
31
|
+
errors: { ...transaction.errors },
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let gasLimit = DEFAULT_GAS;
|
|
35
|
+
let gasPrice = DEFAULT_GAS_PRICE;
|
|
36
|
+
transaction.options = {
|
|
37
|
+
maxGasAmount: gasLimit.toString(),
|
|
38
|
+
gasUnitPrice: gasPrice.toString(),
|
|
39
|
+
};
|
|
40
|
+
if (account.xpub) {
|
|
41
|
+
try {
|
|
42
|
+
const publicKeyEd = new Ed25519PublicKey(account.xpub as string);
|
|
43
|
+
const tx = await buildTransaction(account, transaction, aptosClient);
|
|
44
|
+
const simulation = await aptosClient.simulateTransaction(publicKeyEd, tx);
|
|
45
|
+
const completedTx = simulation[0];
|
|
46
|
+
|
|
47
|
+
gasLimit = new BigNumber(completedTx.gas_used).multipliedBy(ESTIMATE_GAS_MUL);
|
|
48
|
+
gasPrice = new BigNumber(completedTx.gas_unit_price);
|
|
49
|
+
|
|
50
|
+
const expectedGas = gasPrice.multipliedBy(gasLimit);
|
|
51
|
+
|
|
52
|
+
const isUnderMaxSpendable = transaction.amount
|
|
53
|
+
.plus(expectedGas)
|
|
54
|
+
.isLessThan(account.spendableBalance);
|
|
55
|
+
|
|
56
|
+
if (isUnderMaxSpendable && !completedTx.success) {
|
|
57
|
+
// we want to skip INSUFFICIENT_BALANCE error because it will be processed by getTransactionStatus
|
|
58
|
+
if (!completedTx.vm_status.includes("INSUFFICIENT_BALANCE")) {
|
|
59
|
+
throw Error(`Simulation failed with following error: ${completedTx.vm_status}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
res.fees = expectedGas;
|
|
63
|
+
res.estimate.maxGasAmount = gasLimit.toString();
|
|
64
|
+
res.estimate.gasUnitPrice = completedTx.gas_unit_price;
|
|
65
|
+
} catch (error: any) {
|
|
66
|
+
log(error.message);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return res;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const CACHE = makeLRUCache(
|
|
74
|
+
getFee,
|
|
75
|
+
(_account: Account, transaction: Transaction, _aptosClient: AptosAPI) => {
|
|
76
|
+
return transaction.amount.toString();
|
|
77
|
+
},
|
|
78
|
+
seconds(30),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
export const getEstimatedGas = async (
|
|
82
|
+
account: Account,
|
|
83
|
+
transaction: Transaction,
|
|
84
|
+
aptosClient: AptosAPI,
|
|
85
|
+
): Promise<IGetEstimatedGasReturnType> => {
|
|
86
|
+
return await CACHE(account, transaction, aptosClient);
|
|
87
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import {
|
|
3
|
+
NotEnoughBalance,
|
|
4
|
+
RecipientRequired,
|
|
5
|
+
InvalidAddress,
|
|
6
|
+
FeeNotLoaded,
|
|
7
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
8
|
+
AmountRequired,
|
|
9
|
+
} from "@ledgerhq/errors";
|
|
10
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
11
|
+
import type { Transaction, TransactionStatus } from "../types";
|
|
12
|
+
|
|
13
|
+
import { AccountAddress } from "@aptos-labs/ts-sdk";
|
|
14
|
+
|
|
15
|
+
const getTransactionStatus = async (a: Account, t: Transaction): Promise<TransactionStatus> => {
|
|
16
|
+
const errors: Record<string, Error> = {};
|
|
17
|
+
const warnings = {};
|
|
18
|
+
|
|
19
|
+
if (!t.fees) {
|
|
20
|
+
errors.fees = new FeeNotLoaded();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const estimatedFees = t.fees || BigNumber(0);
|
|
24
|
+
|
|
25
|
+
if (t.amount.eq(0)) {
|
|
26
|
+
errors.amount = new AmountRequired();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const amount = t.amount;
|
|
30
|
+
|
|
31
|
+
const totalSpent = BigNumber(t.amount).plus(estimatedFees);
|
|
32
|
+
|
|
33
|
+
if (totalSpent.gt(a.balance) && !errors.amount) {
|
|
34
|
+
errors.amount = new NotEnoughBalance();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!t.recipient) {
|
|
38
|
+
errors.recipient = new RecipientRequired();
|
|
39
|
+
} else if (AccountAddress.isValid({ input: t.recipient }).valid === false && !errors.recipient) {
|
|
40
|
+
errors.recipient = new InvalidAddress("", { currencyName: a.currency.name });
|
|
41
|
+
} else if (t.recipient === a.freshAddress && !errors.recipient) {
|
|
42
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return Promise.resolve({
|
|
46
|
+
errors,
|
|
47
|
+
warnings,
|
|
48
|
+
estimatedFees,
|
|
49
|
+
amount,
|
|
50
|
+
totalSpent,
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default getTransactionStatus;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeAccountBridgeReceive,
|
|
3
|
+
makeScanAccounts,
|
|
4
|
+
getSerializedAddressParameters,
|
|
5
|
+
makeSync,
|
|
6
|
+
updateTransaction,
|
|
7
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
8
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
9
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
10
|
+
import type { Account, AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
11
|
+
import resolver from "../signer";
|
|
12
|
+
import type { Transaction, TransactionStatus, AptosSigner } from "../types";
|
|
13
|
+
import getTransactionStatus from "./getTransactionStatus";
|
|
14
|
+
import estimateMaxSpendable from "./estimateMaxSpendable";
|
|
15
|
+
import prepareTransaction from "./prepareTransaction";
|
|
16
|
+
import createTransaction from "./createTransaction";
|
|
17
|
+
import { getAccountShape } from "./synchronisation";
|
|
18
|
+
import buildSignOperation from "./signOperation";
|
|
19
|
+
import broadcast from "./broadcast";
|
|
20
|
+
|
|
21
|
+
function buildCurrencyBridge(signerContext: SignerContext<AptosSigner>): CurrencyBridge {
|
|
22
|
+
const getAddress = resolver(signerContext);
|
|
23
|
+
|
|
24
|
+
const scanAccounts = makeScanAccounts({
|
|
25
|
+
getAccountShape,
|
|
26
|
+
getAddressFn: getAddressWrapper(getAddress),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
preload: () => Promise.resolve({}),
|
|
31
|
+
hydrate: () => {},
|
|
32
|
+
scanAccounts,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const sync = makeSync({ getAccountShape });
|
|
37
|
+
|
|
38
|
+
function buildAccountBridge(
|
|
39
|
+
signerContext: SignerContext<AptosSigner>,
|
|
40
|
+
): AccountBridge<Transaction, Account, TransactionStatus> {
|
|
41
|
+
const getAddress = resolver(signerContext);
|
|
42
|
+
|
|
43
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
44
|
+
const signOperation = buildSignOperation(signerContext);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
estimateMaxSpendable,
|
|
48
|
+
createTransaction,
|
|
49
|
+
updateTransaction,
|
|
50
|
+
getTransactionStatus,
|
|
51
|
+
getSerializedAddressParameters,
|
|
52
|
+
prepareTransaction,
|
|
53
|
+
sync,
|
|
54
|
+
receive,
|
|
55
|
+
signOperation,
|
|
56
|
+
broadcast,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function createBridges(signerContext: SignerContext<AptosSigner>) {
|
|
61
|
+
return {
|
|
62
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
63
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
64
|
+
};
|
|
65
|
+
}
|