@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
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EntryFunctionPayloadResponse,
|
|
3
|
+
Event,
|
|
4
|
+
InputEntryFunctionData,
|
|
5
|
+
MoveResource,
|
|
6
|
+
WriteSetChange,
|
|
7
|
+
} from "@aptos-labs/ts-sdk";
|
|
8
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
9
|
+
import type { Operation, OperationType } from "@ledgerhq/types-live";
|
|
10
|
+
import BigNumber from "bignumber.js";
|
|
11
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
12
|
+
import {
|
|
13
|
+
APTOS_COIN_CHANGE,
|
|
14
|
+
BATCH_TRANSFER_TYPES,
|
|
15
|
+
DELEGATION_POOL_TYPES,
|
|
16
|
+
DIRECTION,
|
|
17
|
+
TRANSFER_TYPES,
|
|
18
|
+
WRITE_RESOURCE,
|
|
19
|
+
} from "../constants";
|
|
20
|
+
import type { AptosMoveResource, AptosTransaction, TransactionOptions } from "../types";
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_GAS = new BigNumber(200);
|
|
23
|
+
export const DEFAULT_GAS_PRICE = new BigNumber(100);
|
|
24
|
+
export const ESTIMATE_GAS_MUL = new BigNumber(1.0); // define buffer for gas estimation change here, if needed
|
|
25
|
+
|
|
26
|
+
const CLEAN_HEX_REGEXP = /^0x0*|^0+/;
|
|
27
|
+
|
|
28
|
+
export function isTestnet(currencyId: string): boolean {
|
|
29
|
+
return getCryptoCurrencyById(currencyId).isTestnetFor ? true : false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const getMaxSendBalance = (
|
|
33
|
+
amount: BigNumber,
|
|
34
|
+
gas: BigNumber,
|
|
35
|
+
gasPrice: BigNumber,
|
|
36
|
+
): BigNumber => {
|
|
37
|
+
const totalGas = gas.multipliedBy(gasPrice);
|
|
38
|
+
|
|
39
|
+
return amount.gt(totalGas) ? amount.minus(totalGas) : new BigNumber(0);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export function normalizeTransactionOptions(options: TransactionOptions): TransactionOptions {
|
|
43
|
+
// FIXME: this is wrong. TransactionOptions is
|
|
44
|
+
// {
|
|
45
|
+
// maxGasAmount: string;
|
|
46
|
+
// gasUnitPrice: string;
|
|
47
|
+
// sequenceNumber?: string;
|
|
48
|
+
// expirationTimestampSecs?: string;
|
|
49
|
+
// }
|
|
50
|
+
// meaning we can't return undefined in check method.
|
|
51
|
+
// This method is useless, not deleting as it breaks code and this iteration is coin modularisation.
|
|
52
|
+
const check = (v: any) => ((v ?? "").toString().trim() ? v : undefined);
|
|
53
|
+
return {
|
|
54
|
+
maxGasAmount: check(options.maxGasAmount),
|
|
55
|
+
gasUnitPrice: check(options.gasUnitPrice),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const getBlankOperation = (
|
|
60
|
+
tx: AptosTransaction,
|
|
61
|
+
id: string,
|
|
62
|
+
): Operation<Record<string, string>> => ({
|
|
63
|
+
id: "",
|
|
64
|
+
hash: tx.hash,
|
|
65
|
+
type: "" as OperationType,
|
|
66
|
+
value: new BigNumber(0),
|
|
67
|
+
fee: new BigNumber(0),
|
|
68
|
+
blockHash: tx.block?.hash,
|
|
69
|
+
blockHeight: tx.block?.height,
|
|
70
|
+
senders: [] as string[],
|
|
71
|
+
recipients: [] as string[],
|
|
72
|
+
accountId: id,
|
|
73
|
+
date: new Date(parseInt(tx.timestamp) / 1000),
|
|
74
|
+
extra: { version: tx.version },
|
|
75
|
+
transactionSequenceNumber: parseInt(tx.sequence_number),
|
|
76
|
+
hasFailed: false,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const convertFunctionPayloadResponseToInputEntryFunctionData = (
|
|
80
|
+
payload: EntryFunctionPayloadResponse,
|
|
81
|
+
): InputEntryFunctionData => ({
|
|
82
|
+
function: payload.function,
|
|
83
|
+
typeArguments: payload.type_arguments,
|
|
84
|
+
functionArguments: payload.arguments,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
export const txsToOps = (
|
|
88
|
+
info: { address: string },
|
|
89
|
+
id: string,
|
|
90
|
+
txs: (AptosTransaction | null)[],
|
|
91
|
+
): Operation[] => {
|
|
92
|
+
const { address } = info;
|
|
93
|
+
const ops: Operation[] = [];
|
|
94
|
+
|
|
95
|
+
txs.forEach(tx => {
|
|
96
|
+
if (tx !== null) {
|
|
97
|
+
const op: Operation = getBlankOperation(tx, id);
|
|
98
|
+
op.fee = new BigNumber(tx.gas_used).multipliedBy(new BigNumber(tx.gas_unit_price));
|
|
99
|
+
|
|
100
|
+
const payload = convertFunctionPayloadResponseToInputEntryFunctionData(
|
|
101
|
+
tx.payload as EntryFunctionPayloadResponse,
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
const function_address = getFunctionAddress(payload);
|
|
105
|
+
|
|
106
|
+
if (!function_address) {
|
|
107
|
+
return; // skip transaction without functions in payload
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const { amount_in, amount_out } = getAptosAmounts(tx, address);
|
|
111
|
+
op.value = calculateAmount(tx.sender, address, op.fee, amount_in, amount_out);
|
|
112
|
+
op.type = compareAddress(tx.sender, address) ? DIRECTION.OUT : DIRECTION.IN;
|
|
113
|
+
op.senders.push(tx.sender);
|
|
114
|
+
|
|
115
|
+
processRecipients(payload, address, op, function_address);
|
|
116
|
+
|
|
117
|
+
if (op.value.isZero()) {
|
|
118
|
+
// skip transaction that result no Aptos change
|
|
119
|
+
op.type = DIRECTION.UNKNOWN;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
op.hasFailed = !tx.success;
|
|
123
|
+
op.id = encodeOperationId(id, tx.hash, op.type);
|
|
124
|
+
if (op.type !== DIRECTION.UNKNOWN) ops.push(op);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return ops;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export function compareAddress(addressA: string, addressB: string) {
|
|
132
|
+
return (
|
|
133
|
+
addressA.replace(CLEAN_HEX_REGEXP, "").toLowerCase() ===
|
|
134
|
+
addressB.replace(CLEAN_HEX_REGEXP, "").toLowerCase()
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export function getFunctionAddress(payload: InputEntryFunctionData): string | undefined {
|
|
139
|
+
if (payload.function) {
|
|
140
|
+
const parts = payload.function.split("::");
|
|
141
|
+
return parts.length === 3 && parts[0].length ? parts[0] : undefined;
|
|
142
|
+
}
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function processRecipients(
|
|
147
|
+
payload: InputEntryFunctionData,
|
|
148
|
+
address: string,
|
|
149
|
+
op: Operation,
|
|
150
|
+
function_address: string,
|
|
151
|
+
): void {
|
|
152
|
+
// get recipients buy 3 groups
|
|
153
|
+
if (
|
|
154
|
+
(TRANSFER_TYPES.includes(payload.function) ||
|
|
155
|
+
DELEGATION_POOL_TYPES.includes(payload.function)) &&
|
|
156
|
+
payload.functionArguments &&
|
|
157
|
+
payload.functionArguments.length > 0 &&
|
|
158
|
+
typeof payload.functionArguments[0] === "string"
|
|
159
|
+
) {
|
|
160
|
+
// 1. Transfer like functions (includes some delegation pool functions)
|
|
161
|
+
op.recipients.push(payload.functionArguments[0].toString());
|
|
162
|
+
} else if (
|
|
163
|
+
BATCH_TRANSFER_TYPES.includes(payload.function) &&
|
|
164
|
+
payload.functionArguments &&
|
|
165
|
+
payload.functionArguments.length > 0 &&
|
|
166
|
+
Array.isArray(payload.functionArguments[0])
|
|
167
|
+
) {
|
|
168
|
+
// 2. Batch function, to validate we are in the recipients list
|
|
169
|
+
if (!compareAddress(op.senders[0], address)) {
|
|
170
|
+
for (const recipient of payload.functionArguments[0]) {
|
|
171
|
+
if (recipient && compareAddress(recipient.toString(), address)) {
|
|
172
|
+
op.recipients.push(recipient.toString());
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
// 3. other smart contracts, in this case smart contract will be treated as a recipient
|
|
178
|
+
op.recipients.push(function_address);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function checkWriteSets(tx: AptosTransaction, event: Event, event_name: string): boolean {
|
|
183
|
+
return tx.changes.some(change => {
|
|
184
|
+
return isChangeOfAptos(change, event, event_name);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export function isChangeOfAptos(
|
|
189
|
+
writeSetChange: WriteSetChange,
|
|
190
|
+
event: Event,
|
|
191
|
+
event_name: string,
|
|
192
|
+
): boolean {
|
|
193
|
+
// to validate the event is related to Aptos Tokens we need to find change of type "write_resource"
|
|
194
|
+
// with the same guid as event
|
|
195
|
+
if (writeSetChange.type !== WRITE_RESOURCE) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (!("data" in writeSetChange)) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const change_data = writeSetChange.data;
|
|
204
|
+
|
|
205
|
+
if (!("type" in change_data)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const mr = change_data as MoveResource<AptosMoveResource>;
|
|
210
|
+
|
|
211
|
+
if (mr.type !== APTOS_COIN_CHANGE) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const change_event_data = mr.data[event_name];
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
change_event_data.guid.id.addr === event.guid.account_address &&
|
|
219
|
+
change_event_data.guid.id.creation_num === event.guid.creation_number
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function getAptosAmounts(
|
|
224
|
+
tx: AptosTransaction,
|
|
225
|
+
address: string,
|
|
226
|
+
): { amount_in: BigNumber; amount_out: BigNumber } {
|
|
227
|
+
let amount_in = new BigNumber(0);
|
|
228
|
+
let amount_out = new BigNumber(0);
|
|
229
|
+
// collect all events related to the address and calculate the overall amounts
|
|
230
|
+
tx.events.forEach(event => {
|
|
231
|
+
if (compareAddress(event.guid.account_address, address)) {
|
|
232
|
+
switch (event.type) {
|
|
233
|
+
case "0x1::coin::WithdrawEvent":
|
|
234
|
+
if (checkWriteSets(tx, event, "withdraw_events")) {
|
|
235
|
+
amount_out = amount_out.plus(event.data.amount);
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
case "0x1::coin::DepositEvent":
|
|
239
|
+
if (checkWriteSets(tx, event, "deposit_events")) {
|
|
240
|
+
amount_in = amount_in.plus(event.data.amount);
|
|
241
|
+
}
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
return { amount_in, amount_out };
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function calculateAmount(
|
|
250
|
+
sender: string,
|
|
251
|
+
address: string,
|
|
252
|
+
fee: BigNumber,
|
|
253
|
+
amount_in: BigNumber,
|
|
254
|
+
amount_out: BigNumber,
|
|
255
|
+
): BigNumber {
|
|
256
|
+
const is_sender: boolean = compareAddress(sender, address);
|
|
257
|
+
// Include fees if our address is the sender
|
|
258
|
+
if (is_sender) {
|
|
259
|
+
amount_out = amount_out.plus(fee);
|
|
260
|
+
}
|
|
261
|
+
// LL negates the amount for SEND transactions
|
|
262
|
+
// to show positive amount on the send transaction (ex: in "cancel" tx, when amount will be returned to our account)
|
|
263
|
+
// we need to make it negative
|
|
264
|
+
return is_sender ? amount_out.minus(amount_in) : amount_in.minus(amount_out);
|
|
265
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
|
|
4
|
+
import { AptosAPI } from "../api";
|
|
5
|
+
import { getEstimatedGas } from "./getFeesForTransaction";
|
|
6
|
+
import type { Transaction } from "../types";
|
|
7
|
+
import { DEFAULT_GAS, DEFAULT_GAS_PRICE, getMaxSendBalance } from "./logic";
|
|
8
|
+
|
|
9
|
+
const prepareTransaction = async (
|
|
10
|
+
account: Account,
|
|
11
|
+
transaction: Transaction,
|
|
12
|
+
): Promise<Transaction> => {
|
|
13
|
+
if (!transaction.recipient) {
|
|
14
|
+
return transaction;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// if transaction.useAllAmount is true, then we expect transaction.amount to be 0
|
|
18
|
+
// so to check that actual amount is zero or not, we also need to check if useAllAmount is false
|
|
19
|
+
if (transaction.amount.isZero() && !transaction.useAllAmount) {
|
|
20
|
+
return {
|
|
21
|
+
...transaction,
|
|
22
|
+
fees: BigNumber(0),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const aptosClient = new AptosAPI(account.currency.id);
|
|
27
|
+
|
|
28
|
+
if (transaction.useAllAmount) {
|
|
29
|
+
// we will use this amount in simulation, to estimate gas
|
|
30
|
+
transaction.amount = getMaxSendBalance(
|
|
31
|
+
account.spendableBalance,
|
|
32
|
+
new BigNumber(DEFAULT_GAS),
|
|
33
|
+
new BigNumber(DEFAULT_GAS_PRICE),
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const { fees, estimate, errors } = await getEstimatedGas(account, transaction, aptosClient);
|
|
38
|
+
|
|
39
|
+
if (transaction.useAllAmount) {
|
|
40
|
+
// correct the transaction amount according to estimated fees
|
|
41
|
+
transaction.amount = getMaxSendBalance(
|
|
42
|
+
account.spendableBalance,
|
|
43
|
+
BigNumber(estimate.maxGasAmount),
|
|
44
|
+
BigNumber(estimate.gasUnitPrice),
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
transaction.fees = fees;
|
|
49
|
+
transaction.options = estimate;
|
|
50
|
+
transaction.errors = errors;
|
|
51
|
+
|
|
52
|
+
return transaction;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export default prepareTransaction;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { AptosAccount, Transaction } from "../types";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
4
|
+
import buildTransaction from "./buildTransaction";
|
|
5
|
+
import BigNumber from "bignumber.js";
|
|
6
|
+
import type { Account, AccountBridge, Operation, OperationType } from "@ledgerhq/types-live";
|
|
7
|
+
import { AptosAPI } from "../api";
|
|
8
|
+
|
|
9
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
10
|
+
import { AptosSigner } from "../types";
|
|
11
|
+
import { signTransaction } from "../network";
|
|
12
|
+
|
|
13
|
+
export const getAddress = (a: Account) => ({
|
|
14
|
+
address: a.freshAddress,
|
|
15
|
+
derivationPath: a.freshAddressPath,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const buildSignOperation =
|
|
19
|
+
(
|
|
20
|
+
signerContext: SignerContext<AptosSigner>,
|
|
21
|
+
): AccountBridge<Transaction, AptosAccount>["signOperation"] =>
|
|
22
|
+
({ account, transaction, deviceId }) =>
|
|
23
|
+
new Observable(o => {
|
|
24
|
+
async function main() {
|
|
25
|
+
o.next({ type: "device-signature-requested" });
|
|
26
|
+
|
|
27
|
+
const aptosClient = new AptosAPI(account.currency.id);
|
|
28
|
+
|
|
29
|
+
const rawTx = await buildTransaction(account, transaction, aptosClient);
|
|
30
|
+
const txBytes = await signTransaction(signerContext, account, deviceId, rawTx);
|
|
31
|
+
const signature = Buffer.from(txBytes).toString("hex");
|
|
32
|
+
|
|
33
|
+
o.next({ type: "device-signature-granted" });
|
|
34
|
+
|
|
35
|
+
const accountId = account.id;
|
|
36
|
+
const hash = "";
|
|
37
|
+
const type: OperationType = "OUT";
|
|
38
|
+
const fee = transaction.fees || new BigNumber(0);
|
|
39
|
+
const extra = {};
|
|
40
|
+
const senders: string[] = [];
|
|
41
|
+
const recipients: string[] = [];
|
|
42
|
+
|
|
43
|
+
if (transaction.mode === "send") {
|
|
44
|
+
senders.push(account.freshAddress);
|
|
45
|
+
recipients.push(transaction.recipient);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// build optimistic operation
|
|
49
|
+
const operation: Operation = {
|
|
50
|
+
id: encodeOperationId(accountId, hash, type),
|
|
51
|
+
hash,
|
|
52
|
+
type,
|
|
53
|
+
value: transaction.useAllAmount
|
|
54
|
+
? account.balance.minus(fee)
|
|
55
|
+
: transaction.amount.plus(fee),
|
|
56
|
+
fee,
|
|
57
|
+
extra,
|
|
58
|
+
blockHash: null,
|
|
59
|
+
blockHeight: null,
|
|
60
|
+
senders,
|
|
61
|
+
recipients,
|
|
62
|
+
accountId,
|
|
63
|
+
date: new Date(),
|
|
64
|
+
transactionSequenceNumber: Number(rawTx.sequence_number),
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
o.next({
|
|
68
|
+
type: "signed",
|
|
69
|
+
signedOperation: {
|
|
70
|
+
operation,
|
|
71
|
+
signature,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
main().then(
|
|
77
|
+
() => o.complete(),
|
|
78
|
+
e => o.error(e),
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export default buildSignOperation;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { decodeAccountId, encodeAccountId } from "@ledgerhq/coin-framework/account";
|
|
2
|
+
import type { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
3
|
+
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
|
+
import { AptosAPI } from "../api";
|
|
5
|
+
import { txsToOps } from "./logic";
|
|
6
|
+
import type { AptosAccount } from "../types";
|
|
7
|
+
|
|
8
|
+
export const getAccountShape: GetAccountShape = async info => {
|
|
9
|
+
const { address, initialAccount, currency, derivationMode, rest } = info;
|
|
10
|
+
|
|
11
|
+
const publicKey =
|
|
12
|
+
rest?.publicKey || (initialAccount && decodeAccountId(initialAccount.id).xpubOrAddress);
|
|
13
|
+
|
|
14
|
+
const accountId = encodeAccountId({
|
|
15
|
+
type: "js",
|
|
16
|
+
version: "2",
|
|
17
|
+
currencyId: currency.id,
|
|
18
|
+
xpubOrAddress: publicKey || address,
|
|
19
|
+
derivationMode,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// "xpub" field is used to store publicKey to simulate transaction during sending tokens.
|
|
23
|
+
// We can't get access to the Nano X via bluetooth on the step of simulation
|
|
24
|
+
// but we need public key to simulate transaction.
|
|
25
|
+
// "xpub" field is used because this field exists in ledger operation type
|
|
26
|
+
const xpub = initialAccount?.xpub || publicKey || "";
|
|
27
|
+
|
|
28
|
+
const oldOperations = initialAccount?.operations || [];
|
|
29
|
+
const startAt = (oldOperations[0]?.extra as any)?.version;
|
|
30
|
+
|
|
31
|
+
const aptosClient = new AptosAPI(currency.id);
|
|
32
|
+
const { balance, transactions, blockHeight } = await aptosClient.getAccountInfo(address, startAt);
|
|
33
|
+
|
|
34
|
+
const newOperations = txsToOps(info, accountId, transactions);
|
|
35
|
+
const operations = mergeOps(oldOperations, newOperations);
|
|
36
|
+
|
|
37
|
+
const shape: Partial<AptosAccount> = {
|
|
38
|
+
type: "Account",
|
|
39
|
+
id: accountId,
|
|
40
|
+
xpub,
|
|
41
|
+
balance: balance,
|
|
42
|
+
spendableBalance: balance,
|
|
43
|
+
operations,
|
|
44
|
+
operationsCount: operations.length,
|
|
45
|
+
blockHeight,
|
|
46
|
+
lastSyncDate: new Date(),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return shape;
|
|
50
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import type { Transaction, TransactionRaw } from "../types";
|
|
3
|
+
|
|
4
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
5
|
+
import {
|
|
6
|
+
fromTransactionCommonRaw,
|
|
7
|
+
fromTransactionStatusRawCommon as fromTransactionStatusRaw,
|
|
8
|
+
toTransactionCommonRaw,
|
|
9
|
+
toTransactionStatusRawCommon as toTransactionStatusRaw,
|
|
10
|
+
} from "@ledgerhq/coin-framework/serialization";
|
|
11
|
+
import { Account } from "@ledgerhq/types-live";
|
|
12
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
13
|
+
|
|
14
|
+
export const formatTransaction = (
|
|
15
|
+
{ mode, amount, fees, recipient, useAllAmount }: Transaction,
|
|
16
|
+
account: Account,
|
|
17
|
+
): string => {
|
|
18
|
+
return `
|
|
19
|
+
${mode.toUpperCase()} ${
|
|
20
|
+
useAllAmount
|
|
21
|
+
? "MAX"
|
|
22
|
+
: amount.isZero()
|
|
23
|
+
? ""
|
|
24
|
+
: " " + formatCurrencyUnit(account.currency.units[0], amount)
|
|
25
|
+
}
|
|
26
|
+
TO ${recipient}
|
|
27
|
+
with fees=${fees ? formatCurrencyUnit(account.currency.units[0], fees) : "?"}`;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const fromTransactionRaw = (t: TransactionRaw): Transaction => {
|
|
31
|
+
const common = fromTransactionCommonRaw(t);
|
|
32
|
+
return {
|
|
33
|
+
...common,
|
|
34
|
+
family: t.family,
|
|
35
|
+
mode: t.mode,
|
|
36
|
+
options: JSON.parse(t.options),
|
|
37
|
+
...(t.fees && { fees: new BigNumber(t.fees) }),
|
|
38
|
+
...(t.errors && { errors: JSON.parse(t.errors) }),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
43
|
+
const common = toTransactionCommonRaw(t);
|
|
44
|
+
return {
|
|
45
|
+
...common,
|
|
46
|
+
family: t.family,
|
|
47
|
+
mode: t.mode,
|
|
48
|
+
fees: t.fees ? t.fees.toString() : null,
|
|
49
|
+
options: JSON.stringify(t.options),
|
|
50
|
+
errors: JSON.stringify(t.errors),
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default {
|
|
55
|
+
formatTransaction,
|
|
56
|
+
fromTransactionRaw,
|
|
57
|
+
toTransactionRaw,
|
|
58
|
+
fromTransactionStatusRaw,
|
|
59
|
+
toTransactionStatusRaw,
|
|
60
|
+
formatTransactionStatus,
|
|
61
|
+
};
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MoveStructId } from "@aptos-labs/ts-sdk";
|
|
2
|
+
|
|
3
|
+
export const LOAD_LIMIT = 10;
|
|
4
|
+
|
|
5
|
+
export enum TX_STATUS {
|
|
6
|
+
PENDING = "pending",
|
|
7
|
+
FAIL = "fail",
|
|
8
|
+
SUCCESS = "success",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const WRITE_RESOURCE = "write_resource";
|
|
12
|
+
|
|
13
|
+
export const TRANSFER_TYPES: MoveStructId[] = [
|
|
14
|
+
"0x1::aptos_account::transfer",
|
|
15
|
+
"0x1::aptos_account::transfer_coins",
|
|
16
|
+
"0x1::coin::transfer",
|
|
17
|
+
];
|
|
18
|
+
export const BATCH_TRANSFER_TYPES: MoveStructId[] = [
|
|
19
|
+
"0x1::aptos_account::batch_transfer",
|
|
20
|
+
"0x1::aptos_account::batch_transfer_coins",
|
|
21
|
+
];
|
|
22
|
+
export const DELEGATION_POOL_TYPES: MoveStructId[] = [
|
|
23
|
+
"0x1::delegation_pool::add_stake",
|
|
24
|
+
"0x1::delegation_pool::withdraw",
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
export const APTOS_ASSET_ID: MoveStructId = "0x1::aptos_coin::AptosCoin";
|
|
28
|
+
export const APTOS_COIN_CHANGE: MoveStructId = `0x1::coin::CoinStore<${APTOS_ASSET_ID}>`;
|
|
29
|
+
|
|
30
|
+
export enum DIRECTION {
|
|
31
|
+
IN = "IN",
|
|
32
|
+
OUT = "OUT",
|
|
33
|
+
UNKNOWN = "UNKNOWN",
|
|
34
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createCustomErrorClass } from "@ledgerhq/errors";
|
|
2
|
+
|
|
3
|
+
export const SequenceNumberTooOldError = createCustomErrorClass("SequenceNumberTooOld");
|
|
4
|
+
|
|
5
|
+
export const SequenceNumberTooNewError = createCustomErrorClass("SequenceNumberTooNew");
|
|
6
|
+
|
|
7
|
+
export const TransactionExpiredError = createCustomErrorClass("TransactionExpired");
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccountAddress,
|
|
3
|
+
AccountAuthenticatorEd25519,
|
|
4
|
+
Ed25519PublicKey,
|
|
5
|
+
Ed25519Signature,
|
|
6
|
+
generateSignedTransaction,
|
|
7
|
+
generateSigningMessageForTransaction,
|
|
8
|
+
Hex,
|
|
9
|
+
RawTransaction,
|
|
10
|
+
SimpleTransaction,
|
|
11
|
+
} from "@aptos-labs/ts-sdk";
|
|
12
|
+
import { SignerContext } from "@ledgerhq/coin-framework/lib/signer";
|
|
13
|
+
import { Account } from "@ledgerhq/types-live";
|
|
14
|
+
import { AptosSigner } from "../types";
|
|
15
|
+
import { sha3_256 as sha3Hash } from "@noble/hashes/sha3";
|
|
16
|
+
|
|
17
|
+
export async function signTransaction(
|
|
18
|
+
signerContext: SignerContext<AptosSigner>,
|
|
19
|
+
account: Account,
|
|
20
|
+
deviceId: string,
|
|
21
|
+
rawTxn: RawTransaction,
|
|
22
|
+
): Promise<Uint8Array> {
|
|
23
|
+
const { freshAddressPath: derivationPath } = account;
|
|
24
|
+
|
|
25
|
+
if (!account.xpub) {
|
|
26
|
+
throw Error("Account must have a public signing key");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const publicKey = Buffer.from(AccountAddress.from(account.xpub).toUint8Array());
|
|
30
|
+
const hash = sha3Hash.create();
|
|
31
|
+
hash.update(publicKey.toString("hex"));
|
|
32
|
+
hash.update("\x00");
|
|
33
|
+
|
|
34
|
+
const signingMessage = generateSigningMessageForTransaction({
|
|
35
|
+
rawTransaction: rawTxn,
|
|
36
|
+
} as SimpleTransaction);
|
|
37
|
+
|
|
38
|
+
const response = await signerContext(
|
|
39
|
+
deviceId,
|
|
40
|
+
async signer => await signer.signTransaction(derivationPath, Buffer.from(signingMessage)),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const sigHexStr = Hex.fromHexString(response.signature.toString("hex"));
|
|
44
|
+
const signature = new Ed25519Signature(sigHexStr.toUint8Array());
|
|
45
|
+
const authenticator = new AccountAuthenticatorEd25519(
|
|
46
|
+
new Ed25519PublicKey(publicKey.toString("hex")),
|
|
47
|
+
signature,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return generateSignedTransaction({
|
|
51
|
+
transaction: { rawTransaction: rawTxn } as SimpleTransaction,
|
|
52
|
+
senderAuthenticator: authenticator,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
3
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
4
|
+
import { AptosSigner } from "../types";
|
|
5
|
+
|
|
6
|
+
const resolver = (signerContext: SignerContext<AptosSigner>): GetAddressFn => {
|
|
7
|
+
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
|
|
8
|
+
const r = await signerContext(deviceId, signer => signer.getAddress(path, verify || false));
|
|
9
|
+
return {
|
|
10
|
+
address: r.address,
|
|
11
|
+
publicKey: r.publicKey.toString("hex"),
|
|
12
|
+
path,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default resolver;
|