@ledgerhq/coin-celo 1.1.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +22 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +56 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/jest.integ.config.js +8 -0
- package/lib/bridge/broadcast.d.ts +5 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +13 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +49 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/buildTransaction.d.ts +5 -0
- package/lib/bridge/buildTransaction.d.ts.map +1 -0
- package/lib/bridge/buildTransaction.js +142 -0
- package/lib/bridge/buildTransaction.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +5 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +16 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +4 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +16 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +23 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getFeesForTransaction.d.ts +8 -0
- package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib/bridge/getFeesForTransaction.js +93 -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 +98 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +11 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +62 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/preload.d.ts +10 -0
- package/lib/bridge/preload.d.ts.map +1 -0
- package/lib/bridge/preload.js +72 -0
- package/lib/bridge/preload.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 +28 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/serialization.d.ts +9 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +92 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +10 -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 +5 -0
- package/lib/bridge/synchronisation.d.ts.map +1 -0
- package/lib/bridge/synchronisation.js +49 -0
- package/lib/bridge/synchronisation.js.map +1 -0
- package/lib/bridge/transaction.d.ts +14 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +47 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +14 -0
- package/lib/config.js.map +1 -0
- package/lib/datasets/celo.scanAccounts.1.d.ts +5 -0
- package/lib/datasets/celo.scanAccounts.1.d.ts.map +1 -0
- package/lib/datasets/celo.scanAccounts.1.js +364 -0
- package/lib/datasets/celo.scanAccounts.1.js.map +1 -0
- package/lib/errors.d.ts +4 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +6 -0
- package/lib/errors.js.map +1 -0
- package/lib/logic.d.ts +21 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +97 -0
- package/lib/logic.js.map +1 -0
- package/lib/network/hubble.d.ts +12 -0
- package/lib/network/hubble.d.ts.map +1 -0
- package/lib/network/hubble.js +141 -0
- package/lib/network/hubble.js.map +1 -0
- package/lib/network/index.d.ts +4 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +23 -0
- package/lib/network/index.js.map +1 -0
- package/lib/network/sdk.d.ts +27 -0
- package/lib/network/sdk.d.ts.map +1 -0
- package/lib/network/sdk.js +93 -0
- package/lib/network/sdk.js.map +1 -0
- package/lib/network/validators.d.ts +2 -0
- package/lib/network/validators.d.ts.map +1 -0
- package/lib/network/validators.js +6 -0
- package/lib/network/validators.js.map +1 -0
- package/lib/signer/hw-getAddress.d.ts +6 -0
- package/lib/signer/hw-getAddress.d.ts.map +1 -0
- package/lib/signer/hw-getAddress.js +26 -0
- package/lib/signer/hw-getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +2 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +18 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/signer/signer.d.ts +16 -0
- package/lib/signer/signer.d.ts.map +1 -0
- package/lib/signer/signer.js +3 -0
- package/lib/signer/signer.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 +42 -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 +14 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli-transaction.d.ts +25 -0
- package/lib/test/cli-transaction.d.ts.map +1 -0
- package/lib/test/cli-transaction.js +56 -0
- package/lib/test/cli-transaction.js.map +1 -0
- package/lib/test/please-add-coverage.test.d.ts +2 -0
- package/lib/test/please-add-coverage.test.d.ts.map +1 -0
- package/lib/test/please-add-coverage.test.js +6 -0
- package/lib/test/please-add-coverage.test.js.map +1 -0
- package/lib/test/specs/createActivateVoteMutation.d.ts +4 -0
- package/lib/test/specs/createActivateVoteMutation.d.ts.map +1 -0
- package/lib/test/specs/createActivateVoteMutation.js +37 -0
- package/lib/test/specs/createActivateVoteMutation.js.map +1 -0
- package/lib/test/specs/createLockMutation.d.ts +4 -0
- package/lib/test/specs/createLockMutation.d.ts.map +1 -0
- package/lib/test/specs/createLockMutation.js +37 -0
- package/lib/test/specs/createLockMutation.js.map +1 -0
- package/lib/test/specs/createRegisterAccountMutation.d.ts +4 -0
- package/lib/test/specs/createRegisterAccountMutation.d.ts.map +1 -0
- package/lib/test/specs/createRegisterAccountMutation.js +31 -0
- package/lib/test/specs/createRegisterAccountMutation.js.map +1 -0
- package/lib/test/specs/createRevokeVoteMutation.d.ts +4 -0
- package/lib/test/specs/createRevokeVoteMutation.d.ts.map +1 -0
- package/lib/test/specs/createRevokeVoteMutation.js +38 -0
- package/lib/test/specs/createRevokeVoteMutation.js.map +1 -0
- package/lib/test/specs/createSendMutation.d.ts +6 -0
- package/lib/test/specs/createSendMutation.d.ts.map +1 -0
- package/lib/test/specs/createSendMutation.js +45 -0
- package/lib/test/specs/createSendMutation.js.map +1 -0
- package/lib/test/specs/createUnlockMutation.d.ts +4 -0
- package/lib/test/specs/createUnlockMutation.d.ts.map +1 -0
- package/lib/test/specs/createUnlockMutation.js +37 -0
- package/lib/test/specs/createUnlockMutation.js.map +1 -0
- package/lib/test/specs/createVoteMutation.d.ts +4 -0
- package/lib/test/specs/createVoteMutation.d.ts.map +1 -0
- package/lib/test/specs/createVoteMutation.js +48 -0
- package/lib/test/specs/createVoteMutation.js.map +1 -0
- package/lib/test/specs/createWithdrawMutation.d.ts +4 -0
- package/lib/test/specs/createWithdrawMutation.d.ts.map +1 -0
- package/lib/test/specs/createWithdrawMutation.js +37 -0
- package/lib/test/specs/createWithdrawMutation.js.map +1 -0
- package/lib/test/specs/index.d.ts +9 -0
- package/lib/test/specs/index.d.ts.map +1 -0
- package/lib/test/specs/index.js +25 -0
- package/lib/test/specs/index.js.map +1 -0
- package/lib/test/speculos-deviceActions.d.ts +4 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib/test/speculos-deviceActions.js +58 -0
- package/lib/test/speculos-deviceActions.js.map +1 -0
- package/lib/types/index.d.ts +4 -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/types.d.ts +126 -0
- package/lib/types/types.d.ts.map +1 -0
- package/lib/types/types.js +11 -0
- package/lib/types/types.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +5 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +9 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +42 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/buildTransaction.d.ts +5 -0
- package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
- package/lib-es/bridge/buildTransaction.js +140 -0
- package/lib-es/bridge/buildTransaction.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +5 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +12 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +4 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +14 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +16 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts +8 -0
- package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
- package/lib-es/bridge/getFeesForTransaction.js +91 -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 +94 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +11 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +54 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/preload.d.ts +10 -0
- package/lib-es/bridge/preload.d.ts.map +1 -0
- package/lib-es/bridge/preload.js +64 -0
- package/lib-es/bridge/preload.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 +21 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/serialization.d.ts +9 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +84 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +10 -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 +5 -0
- package/lib-es/bridge/synchronisation.d.ts.map +1 -0
- package/lib-es/bridge/synchronisation.js +45 -0
- package/lib-es/bridge/synchronisation.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +14 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +42 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/config.d.ts +3 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/datasets/celo.scanAccounts.1.d.ts +5 -0
- package/lib-es/datasets/celo.scanAccounts.1.d.ts.map +1 -0
- package/lib-es/datasets/celo.scanAccounts.1.js +359 -0
- package/lib-es/datasets/celo.scanAccounts.1.js.map +1 -0
- package/lib-es/errors.d.ts +4 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +3 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/logic.d.ts +21 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +77 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/network/hubble.d.ts +12 -0
- package/lib-es/network/hubble.d.ts.map +1 -0
- package/lib-es/network/hubble.js +133 -0
- package/lib-es/network/hubble.js.map +1 -0
- package/lib-es/network/index.d.ts +4 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +4 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/network/sdk.d.ts +27 -0
- package/lib-es/network/sdk.d.ts.map +1 -0
- package/lib-es/network/sdk.js +85 -0
- package/lib-es/network/sdk.js.map +1 -0
- package/lib-es/network/validators.d.ts +2 -0
- package/lib-es/network/validators.d.ts.map +1 -0
- package/lib-es/network/validators.js +2 -0
- package/lib-es/network/validators.js.map +1 -0
- package/lib-es/signer/hw-getAddress.d.ts +6 -0
- package/lib-es/signer/hw-getAddress.d.ts.map +1 -0
- package/lib-es/signer/hw-getAddress.js +21 -0
- package/lib-es/signer/hw-getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +2 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +2 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/signer/signer.d.ts +16 -0
- package/lib-es/signer/signer.d.ts.map +1 -0
- package/lib-es/signer/signer.js +2 -0
- package/lib-es/signer/signer.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 +40 -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 +8 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli-transaction.d.ts +25 -0
- package/lib-es/test/cli-transaction.d.ts.map +1 -0
- package/lib-es/test/cli-transaction.js +50 -0
- package/lib-es/test/cli-transaction.js.map +1 -0
- package/lib-es/test/please-add-coverage.test.d.ts +1 -0
- package/lib-es/test/please-add-coverage.test.d.ts.map +1 -0
- package/lib-es/test/please-add-coverage.test.js +5 -0
- package/lib-es/test/please-add-coverage.test.js.map +1 -0
- package/lib-es/test/specs/createActivateVoteMutation.d.ts +4 -0
- package/lib-es/test/specs/createActivateVoteMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createActivateVoteMutation.js +30 -0
- package/lib-es/test/specs/createActivateVoteMutation.js.map +1 -0
- package/lib-es/test/specs/createLockMutation.d.ts +4 -0
- package/lib-es/test/specs/createLockMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createLockMutation.js +30 -0
- package/lib-es/test/specs/createLockMutation.js.map +1 -0
- package/lib-es/test/specs/createRegisterAccountMutation.d.ts +4 -0
- package/lib-es/test/specs/createRegisterAccountMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createRegisterAccountMutation.js +24 -0
- package/lib-es/test/specs/createRegisterAccountMutation.js.map +1 -0
- package/lib-es/test/specs/createRevokeVoteMutation.d.ts +4 -0
- package/lib-es/test/specs/createRevokeVoteMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createRevokeVoteMutation.js +31 -0
- package/lib-es/test/specs/createRevokeVoteMutation.js.map +1 -0
- package/lib-es/test/specs/createSendMutation.d.ts +6 -0
- package/lib-es/test/specs/createSendMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createSendMutation.js +37 -0
- package/lib-es/test/specs/createSendMutation.js.map +1 -0
- package/lib-es/test/specs/createUnlockMutation.d.ts +4 -0
- package/lib-es/test/specs/createUnlockMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createUnlockMutation.js +30 -0
- package/lib-es/test/specs/createUnlockMutation.js.map +1 -0
- package/lib-es/test/specs/createVoteMutation.d.ts +4 -0
- package/lib-es/test/specs/createVoteMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createVoteMutation.js +41 -0
- package/lib-es/test/specs/createVoteMutation.js.map +1 -0
- package/lib-es/test/specs/createWithdrawMutation.d.ts +4 -0
- package/lib-es/test/specs/createWithdrawMutation.d.ts.map +1 -0
- package/lib-es/test/specs/createWithdrawMutation.js +30 -0
- package/lib-es/test/specs/createWithdrawMutation.js.map +1 -0
- package/lib-es/test/specs/index.d.ts +9 -0
- package/lib-es/test/specs/index.d.ts.map +1 -0
- package/lib-es/test/specs/index.js +9 -0
- package/lib-es/test/specs/index.js.map +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts +4 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/test/speculos-deviceActions.js +55 -0
- package/lib-es/test/speculos-deviceActions.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -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/types.d.ts +126 -0
- package/lib-es/types/types.d.ts.map +1 -0
- package/lib-es/types/types.js +7 -0
- package/lib-es/types/types.js.map +1 -0
- package/package.json +156 -0
- package/src/bridge/broadcast.ts +14 -0
- package/src/bridge/buildOptimisticOperation.ts +53 -0
- package/src/bridge/buildTransaction.ts +154 -0
- package/src/bridge/createTransaction.ts +15 -0
- package/src/bridge/deviceTransactionConfig.ts +19 -0
- package/src/bridge/estimateMaxSpendable.ts +22 -0
- package/src/bridge/getFeesForTransaction.ts +115 -0
- package/src/bridge/getTransactionStatus.ts +120 -0
- package/src/bridge/index.ts +77 -0
- package/src/bridge/preload.ts +75 -0
- package/src/bridge/prepareTransaction.ts +33 -0
- package/src/bridge/serialization.ts +114 -0
- package/src/bridge/signOperation.ts +121 -0
- package/src/bridge/synchronisation.ts +60 -0
- package/src/bridge/transaction.ts +53 -0
- package/src/config.ts +12 -0
- package/src/datasets/celo.scanAccounts.1.ts +370 -0
- package/src/errors.ts +3 -0
- package/src/logic.ts +146 -0
- package/src/network/hubble.ts +183 -0
- package/src/network/index.ts +3 -0
- package/src/network/sdk.ts +101 -0
- package/src/network/validators.ts +1 -0
- package/src/signer/hw-getAddress.ts +27 -0
- package/src/signer/index.ts +1 -0
- package/src/signer/signer.ts +36 -0
- package/src/test/bot-specs.ts +55 -0
- package/src/test/bridgeDatasetTest.ts +10 -0
- package/src/test/cli-transaction.ts +70 -0
- package/src/test/please-add-coverage.test.ts +3 -0
- package/src/test/specs/createActivateVoteMutation.ts +37 -0
- package/src/test/specs/createLockMutation.ts +38 -0
- package/src/test/specs/createRegisterAccountMutation.ts +35 -0
- package/src/test/specs/createRevokeVoteMutation.ts +38 -0
- package/src/test/specs/createSendMutation.ts +41 -0
- package/src/test/specs/createUnlockMutation.ts +35 -0
- package/src/test/specs/createVoteMutation.ts +55 -0
- package/src/test/specs/createWithdrawMutation.ts +37 -0
- package/src/test/specs/index.ts +8 -0
- package/src/test/speculos-deviceActions.ts +63 -0
- package/src/types/index.ts +3 -0
- package/src/types/types.ts +155 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import {
|
|
3
|
+
getSerializedAddressParameters,
|
|
4
|
+
updateTransaction,
|
|
5
|
+
makeAccountBridgeReceive,
|
|
6
|
+
makeScanAccounts,
|
|
7
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
8
|
+
import { getPreloadStrategy, preload, hydrate } from "./preload";
|
|
9
|
+
import { getTransactionStatus } from "./getTransactionStatus";
|
|
10
|
+
import { estimateMaxSpendable } from "./estimateMaxSpendable";
|
|
11
|
+
import { prepareTransaction } from "./prepareTransaction";
|
|
12
|
+
import { createTransaction } from "./createTransaction";
|
|
13
|
+
import {
|
|
14
|
+
assignFromAccountRaw,
|
|
15
|
+
assignToAccountRaw,
|
|
16
|
+
toOperationExtraRaw,
|
|
17
|
+
fromOperationExtraRaw,
|
|
18
|
+
} from "./serialization";
|
|
19
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
20
|
+
import resolver from "../signer/hw-getAddress";
|
|
21
|
+
import type { CeloAccount, Transaction, TransactionStatus } from "../types";
|
|
22
|
+
import { broadcast } from "./broadcast";
|
|
23
|
+
|
|
24
|
+
import { EvmSigner } from "@ledgerhq/coin-evm/types/signer";
|
|
25
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
26
|
+
import { getAccountShape } from "./synchronisation";
|
|
27
|
+
import { buildSignOperation } from "./signOperation";
|
|
28
|
+
import { sync } from "./synchronisation";
|
|
29
|
+
import { CeloSigner } from "../signer/signer";
|
|
30
|
+
|
|
31
|
+
export function buildCurrencyBridge(signerContext: SignerContext<CeloSigner>): CurrencyBridge {
|
|
32
|
+
const getAddress = resolver(signerContext);
|
|
33
|
+
const scanAccounts = makeScanAccounts({
|
|
34
|
+
getAccountShape,
|
|
35
|
+
getAddressFn: getAddressWrapper(getAddress),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
getPreloadStrategy,
|
|
40
|
+
preload,
|
|
41
|
+
hydrate,
|
|
42
|
+
scanAccounts,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function buildAccountBridge(
|
|
47
|
+
signerContext: SignerContext<CeloSigner>,
|
|
48
|
+
): AccountBridge<Transaction, CeloAccount, TransactionStatus> {
|
|
49
|
+
const getAddress = resolver(signerContext);
|
|
50
|
+
|
|
51
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
52
|
+
const signOperation = buildSignOperation(signerContext);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
estimateMaxSpendable,
|
|
56
|
+
createTransaction,
|
|
57
|
+
updateTransaction,
|
|
58
|
+
getTransactionStatus,
|
|
59
|
+
prepareTransaction,
|
|
60
|
+
sync,
|
|
61
|
+
receive,
|
|
62
|
+
signOperation,
|
|
63
|
+
broadcast,
|
|
64
|
+
getSerializedAddressParameters,
|
|
65
|
+
assignFromAccountRaw,
|
|
66
|
+
assignToAccountRaw,
|
|
67
|
+
toOperationExtraRaw,
|
|
68
|
+
fromOperationExtraRaw,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createBridges(signerContext: SignerContext<CeloSigner>) {
|
|
73
|
+
return {
|
|
74
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
75
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { Observable, Subject } from "rxjs";
|
|
3
|
+
import { log } from "@ledgerhq/logs";
|
|
4
|
+
import { PRELOAD_MAX_AGE } from "../logic";
|
|
5
|
+
import type { CeloPreloadData, CeloValidatorGroup } from "../types";
|
|
6
|
+
import { getValidatorGroups } from "../network/validators";
|
|
7
|
+
|
|
8
|
+
let currentCeloPreloadedData: CeloPreloadData = {
|
|
9
|
+
validatorGroups: [],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function fromHydrateValidator(
|
|
13
|
+
validatorGroupRaw: Record<string, string | number>,
|
|
14
|
+
): CeloValidatorGroup {
|
|
15
|
+
return {
|
|
16
|
+
address: validatorGroupRaw.address.toString(),
|
|
17
|
+
name: validatorGroupRaw.name.toString(),
|
|
18
|
+
votes: new BigNumber(validatorGroupRaw.votes),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function fromHydratePreloadData(data: unknown): CeloPreloadData {
|
|
23
|
+
let validatorGroups: CeloValidatorGroup[] = [];
|
|
24
|
+
if (typeof data === "object" && data && "validatorGroups" in data) {
|
|
25
|
+
if (Array.isArray(data.validatorGroups)) {
|
|
26
|
+
validatorGroups = data.validatorGroups.map(fromHydrateValidator);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
validatorGroups,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const updates = new Subject<CeloPreloadData>();
|
|
36
|
+
export function getCurrentCeloPreloadData(): CeloPreloadData {
|
|
37
|
+
return currentCeloPreloadedData;
|
|
38
|
+
}
|
|
39
|
+
function setCeloPreloadData(data: CeloPreloadData) {
|
|
40
|
+
if (data === currentCeloPreloadedData) return;
|
|
41
|
+
currentCeloPreloadedData = data;
|
|
42
|
+
updates.next(data);
|
|
43
|
+
}
|
|
44
|
+
export function getCeloPreloadDataUpdates(): Observable<CeloPreloadData> {
|
|
45
|
+
return updates.asObservable();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const getPreloadStrategy = () => ({
|
|
49
|
+
preloadMaxAge: PRELOAD_MAX_AGE,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const preload = async (): Promise<CeloPreloadData> => {
|
|
53
|
+
const { validatorGroups: previousValidatorGroups } = currentCeloPreloadedData;
|
|
54
|
+
let validatorGroups = previousValidatorGroups;
|
|
55
|
+
|
|
56
|
+
if (!validatorGroups || !validatorGroups.length) {
|
|
57
|
+
log("celo/preload", "refreshing celo validatorGroups...");
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
validatorGroups = await getValidatorGroups();
|
|
61
|
+
} catch (error) {
|
|
62
|
+
log("celo/preload", "failed to fetch validatorGroups", {
|
|
63
|
+
error,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { validatorGroups };
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const hydrate = (data: unknown) => {
|
|
72
|
+
const hydrated = fromHydratePreloadData(data);
|
|
73
|
+
log("celo/preload", "hydrate " + hydrated.validatorGroups.length + " celo validatorGroups");
|
|
74
|
+
setCeloPreloadData(hydrated);
|
|
75
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import { isValidAddress } from "@celo/utils/lib/address";
|
|
4
|
+
import getFeesForTransaction from "./getFeesForTransaction";
|
|
5
|
+
import { CeloAccount, Transaction } from "../types";
|
|
6
|
+
|
|
7
|
+
const sameFees = (a: BigNumber | null | undefined, b: BigNumber) => (!a || !b ? a === b : a.eq(b));
|
|
8
|
+
|
|
9
|
+
export const prepareTransaction: AccountBridge<
|
|
10
|
+
Transaction,
|
|
11
|
+
CeloAccount
|
|
12
|
+
>["prepareTransaction"] = async (account, transaction) => {
|
|
13
|
+
if (transaction.recipient && !isValidAddress(transaction.recipient)) return transaction;
|
|
14
|
+
|
|
15
|
+
if (["send", "vote"].includes(transaction.mode) && !transaction.recipient) return transaction;
|
|
16
|
+
|
|
17
|
+
if (
|
|
18
|
+
transaction.mode === "vote" &&
|
|
19
|
+
!transaction.useAllAmount &&
|
|
20
|
+
new BigNumber(transaction.amount).lte(0)
|
|
21
|
+
)
|
|
22
|
+
return transaction;
|
|
23
|
+
|
|
24
|
+
const fees = await getFeesForTransaction({ account, transaction });
|
|
25
|
+
|
|
26
|
+
if (!sameFees(transaction.fees, fees)) {
|
|
27
|
+
return { ...transaction, fees };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return transaction;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default prepareTransaction;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isCeloOperationExtra,
|
|
3
|
+
isCeloOperationExtraRaw,
|
|
4
|
+
type CeloAccount,
|
|
5
|
+
type CeloAccountRaw,
|
|
6
|
+
type CeloOperationExtra,
|
|
7
|
+
type CeloOperationExtraRaw,
|
|
8
|
+
type CeloResources,
|
|
9
|
+
type CeloResourcesRaw,
|
|
10
|
+
} from "../types";
|
|
11
|
+
import { BigNumber } from "bignumber.js";
|
|
12
|
+
import { Account, AccountRaw, OperationExtra, OperationExtraRaw } from "@ledgerhq/types-live";
|
|
13
|
+
|
|
14
|
+
export function toCeloResourcesRaw(r: CeloResources): CeloResourcesRaw {
|
|
15
|
+
const {
|
|
16
|
+
registrationStatus,
|
|
17
|
+
lockedBalance,
|
|
18
|
+
nonvotingLockedBalance,
|
|
19
|
+
pendingWithdrawals,
|
|
20
|
+
votes,
|
|
21
|
+
electionAddress,
|
|
22
|
+
lockedGoldAddress,
|
|
23
|
+
maxNumGroupsVotedFor,
|
|
24
|
+
} = r ?? {};
|
|
25
|
+
return {
|
|
26
|
+
registrationStatus,
|
|
27
|
+
lockedBalance: lockedBalance?.toString(),
|
|
28
|
+
nonvotingLockedBalance: nonvotingLockedBalance?.toString(),
|
|
29
|
+
pendingWithdrawals: pendingWithdrawals?.map(withdrawal => ({
|
|
30
|
+
value: withdrawal.value.toString(),
|
|
31
|
+
time: withdrawal.time.toString(),
|
|
32
|
+
index: withdrawal.index.toString(),
|
|
33
|
+
})),
|
|
34
|
+
votes: votes?.map(vote => ({
|
|
35
|
+
validatorGroup: vote.validatorGroup.toString(),
|
|
36
|
+
amount: vote.amount.toString(),
|
|
37
|
+
activatable: vote.activatable,
|
|
38
|
+
revokable: vote.revokable,
|
|
39
|
+
type: vote.type,
|
|
40
|
+
index: vote.index,
|
|
41
|
+
})),
|
|
42
|
+
electionAddress,
|
|
43
|
+
lockedGoldAddress,
|
|
44
|
+
maxNumGroupsVotedFor: maxNumGroupsVotedFor?.toString(),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function fromCeloResourcesRaw(r: CeloResourcesRaw): CeloResources {
|
|
49
|
+
return {
|
|
50
|
+
registrationStatus: r.registrationStatus,
|
|
51
|
+
lockedBalance: new BigNumber(r.lockedBalance),
|
|
52
|
+
nonvotingLockedBalance: new BigNumber(r.nonvotingLockedBalance),
|
|
53
|
+
pendingWithdrawals: r.pendingWithdrawals?.map(u => ({
|
|
54
|
+
value: new BigNumber(u.value),
|
|
55
|
+
time: new BigNumber(u.time),
|
|
56
|
+
index: Number(u.index),
|
|
57
|
+
})),
|
|
58
|
+
votes: r.votes?.map(vote => ({
|
|
59
|
+
validatorGroup: vote.validatorGroup,
|
|
60
|
+
amount: new BigNumber(vote.amount),
|
|
61
|
+
activatable: vote.activatable,
|
|
62
|
+
revokable: vote.revokable,
|
|
63
|
+
type: vote.type,
|
|
64
|
+
index: vote.index,
|
|
65
|
+
})),
|
|
66
|
+
electionAddress: r.electionAddress,
|
|
67
|
+
lockedGoldAddress: r.lockedGoldAddress,
|
|
68
|
+
maxNumGroupsVotedFor: new BigNumber(r.maxNumGroupsVotedFor),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function assignToAccountRaw(account: Account, accountRaw: AccountRaw) {
|
|
73
|
+
const celoAccount = account as CeloAccount;
|
|
74
|
+
if (celoAccount.celoResources)
|
|
75
|
+
(accountRaw as CeloAccountRaw).celoResources = toCeloResourcesRaw(celoAccount.celoResources);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account) {
|
|
79
|
+
const celoResourcesRaw = (accountRaw as CeloAccountRaw).celoResources;
|
|
80
|
+
if (celoResourcesRaw)
|
|
81
|
+
(account as CeloAccount).celoResources = fromCeloResourcesRaw(celoResourcesRaw);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function fromOperationExtraRaw(extraRaw: OperationExtraRaw): OperationExtra {
|
|
85
|
+
if (!isCeloOperationExtraRaw(extraRaw)) {
|
|
86
|
+
throw new Error("Unsupported OperationExtra");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const extra: CeloOperationExtra = {
|
|
90
|
+
celoOperationValue: new BigNumber(extraRaw.celoOperationValue),
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
if (extraRaw.celoSourceValidator) {
|
|
94
|
+
extra.celoSourceValidator = extraRaw.celoSourceValidator;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return extra;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function toOperationExtraRaw(extra: OperationExtra): OperationExtraRaw {
|
|
101
|
+
if (!isCeloOperationExtra(extra)) {
|
|
102
|
+
throw new Error("Unsupported OperationExtra");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const extraRaw: CeloOperationExtraRaw = {
|
|
106
|
+
celoOperationValue: extra.celoOperationValue.toString(),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (extra.celoSourceValidator) {
|
|
110
|
+
extraRaw.celoSourceValidator = extra.celoSourceValidator;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return extraRaw;
|
|
114
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
4
|
+
import type { Account, AccountBridge, DeviceId, SignOperationEvent } from "@ledgerhq/types-live";
|
|
5
|
+
import { encodeTransaction, recoverTransaction } from "@celo/wallet-base";
|
|
6
|
+
|
|
7
|
+
import { buildOptimisticOperation } from "./buildOptimisticOperation";
|
|
8
|
+
import type { Transaction, CeloAccount } from "../types/types";
|
|
9
|
+
import buildTransaction from "./buildTransaction";
|
|
10
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
11
|
+
import { EvmSignature } from "@ledgerhq/coin-evm/types/signer";
|
|
12
|
+
import { determineFees } from "../network/sdk";
|
|
13
|
+
import { CeloSigner } from "../signer";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Sign Transaction with Ledger hardware
|
|
17
|
+
*/
|
|
18
|
+
export const buildSignOperation =
|
|
19
|
+
(signerContext: SignerContext<CeloSigner>): AccountBridge<Transaction>["signOperation"] =>
|
|
20
|
+
({
|
|
21
|
+
account,
|
|
22
|
+
transaction,
|
|
23
|
+
deviceId,
|
|
24
|
+
}: {
|
|
25
|
+
account: Account;
|
|
26
|
+
transaction: Transaction;
|
|
27
|
+
deviceId: DeviceId;
|
|
28
|
+
}): Observable<SignOperationEvent> =>
|
|
29
|
+
new Observable(o => {
|
|
30
|
+
let cancelled: boolean;
|
|
31
|
+
|
|
32
|
+
async function main() {
|
|
33
|
+
const { fees } = transaction;
|
|
34
|
+
if (!fees) throw new FeeNotLoaded();
|
|
35
|
+
const unsignedTransaction = await buildTransaction(account as CeloAccount, transaction);
|
|
36
|
+
const { chainId, to } = unsignedTransaction;
|
|
37
|
+
|
|
38
|
+
await signerContext(deviceId, signer => {
|
|
39
|
+
return signer.verifyTokenInfo(to!, chainId!);
|
|
40
|
+
});
|
|
41
|
+
await determineFees(unsignedTransaction);
|
|
42
|
+
|
|
43
|
+
const rlpEncodedTransaction = await signerContext(deviceId, signer => {
|
|
44
|
+
return signer.rlpEncodedTxForLedger(unsignedTransaction);
|
|
45
|
+
});
|
|
46
|
+
o.next({ type: "device-signature-requested" });
|
|
47
|
+
|
|
48
|
+
const response = (await signerContext(deviceId, signer => {
|
|
49
|
+
return signer.signTransaction(
|
|
50
|
+
account.freshAddressPath,
|
|
51
|
+
trimLeading0x(rlpEncodedTransaction.rlpEncode),
|
|
52
|
+
);
|
|
53
|
+
})) as EvmSignature;
|
|
54
|
+
|
|
55
|
+
const { address } = await signerContext(deviceId, signer => {
|
|
56
|
+
return signer.getAddress(account.freshAddressPath);
|
|
57
|
+
});
|
|
58
|
+
const convertedResponse = { ...response, v: response.v.toString() };
|
|
59
|
+
if (cancelled) return;
|
|
60
|
+
|
|
61
|
+
const signature = parseSigningResponse(convertedResponse, chainId!);
|
|
62
|
+
|
|
63
|
+
o.next({ type: "device-signature-granted" });
|
|
64
|
+
const encodedTransaction = await encodeTransaction(rlpEncodedTransaction, signature);
|
|
65
|
+
const [_, recoveredAddress] = recoverTransaction(encodedTransaction.raw);
|
|
66
|
+
if (recoveredAddress !== address) {
|
|
67
|
+
throw new Error(
|
|
68
|
+
"celo: there was a signing error, the recovered address doesn't match the your ledger address, the operation was cancelled",
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
const operation = buildOptimisticOperation(
|
|
72
|
+
account as CeloAccount,
|
|
73
|
+
transaction,
|
|
74
|
+
transaction.fees ?? new BigNumber(0),
|
|
75
|
+
);
|
|
76
|
+
o.next({
|
|
77
|
+
type: "signed",
|
|
78
|
+
signedOperation: {
|
|
79
|
+
operation,
|
|
80
|
+
signature: encodedTransaction.raw,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
main().then(
|
|
86
|
+
() => o.complete(),
|
|
87
|
+
e => o.error(e),
|
|
88
|
+
);
|
|
89
|
+
return () => {
|
|
90
|
+
cancelled = true;
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const trimLeading0x = (input: string) => (input.startsWith("0x") ? input.slice(2) : input);
|
|
95
|
+
|
|
96
|
+
const parseSigningResponse = (
|
|
97
|
+
response: {
|
|
98
|
+
s: string;
|
|
99
|
+
v: string;
|
|
100
|
+
r: string;
|
|
101
|
+
},
|
|
102
|
+
chainId: number,
|
|
103
|
+
): {
|
|
104
|
+
s: Buffer;
|
|
105
|
+
v: number;
|
|
106
|
+
r: Buffer;
|
|
107
|
+
} => {
|
|
108
|
+
// EIP155
|
|
109
|
+
const sigV = parseInt(response.v, 16);
|
|
110
|
+
let eip155V = chainId * 2 + 35;
|
|
111
|
+
|
|
112
|
+
eip155V = sigV;
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
s: Buffer.from(response.s, "hex"),
|
|
116
|
+
v: eip155V,
|
|
117
|
+
r: Buffer.from(response.r, "hex"),
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export default buildSignOperation;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { getAccountRegistrationStatus, getPendingWithdrawals, getVotes } from "../network/sdk";
|
|
2
|
+
import { makeSync, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
3
|
+
import type { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
4
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account";
|
|
5
|
+
import { getAccountDetails } from "../network";
|
|
6
|
+
import { CeloAccount } from "../types/types";
|
|
7
|
+
import { celoKit } from "../network/sdk";
|
|
8
|
+
|
|
9
|
+
const kit = celoKit();
|
|
10
|
+
|
|
11
|
+
export const getAccountShape: GetAccountShape<CeloAccount> = async info => {
|
|
12
|
+
const { address, currency, initialAccount, derivationMode } = info;
|
|
13
|
+
const oldOperations = initialAccount?.operations || [];
|
|
14
|
+
const election = await kit.contracts.getElection();
|
|
15
|
+
const electionConfig = await election.getConfig();
|
|
16
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
17
|
+
const accountId = encodeAccountId({
|
|
18
|
+
type: "js",
|
|
19
|
+
version: "2",
|
|
20
|
+
currencyId: currency.id,
|
|
21
|
+
xpubOrAddress: address,
|
|
22
|
+
derivationMode,
|
|
23
|
+
});
|
|
24
|
+
const {
|
|
25
|
+
blockHeight,
|
|
26
|
+
balance,
|
|
27
|
+
spendableBalance,
|
|
28
|
+
operations: newOperations,
|
|
29
|
+
lockedBalance,
|
|
30
|
+
nonvotingLockedBalance,
|
|
31
|
+
} = await getAccountDetails(address, accountId);
|
|
32
|
+
|
|
33
|
+
const accountRegistrationStatus = await getAccountRegistrationStatus(address);
|
|
34
|
+
|
|
35
|
+
const pendingWithdrawals = accountRegistrationStatus ? await getPendingWithdrawals(address) : [];
|
|
36
|
+
|
|
37
|
+
const votes = accountRegistrationStatus ? await getVotes(address) : [];
|
|
38
|
+
|
|
39
|
+
const operations = mergeOps(oldOperations, newOperations);
|
|
40
|
+
const shape = {
|
|
41
|
+
id: accountId,
|
|
42
|
+
balance,
|
|
43
|
+
spendableBalance,
|
|
44
|
+
operationsCount: operations.length,
|
|
45
|
+
blockHeight,
|
|
46
|
+
celoResources: {
|
|
47
|
+
registrationStatus: accountRegistrationStatus,
|
|
48
|
+
lockedBalance,
|
|
49
|
+
nonvotingLockedBalance,
|
|
50
|
+
pendingWithdrawals,
|
|
51
|
+
votes,
|
|
52
|
+
electionAddress: election.address,
|
|
53
|
+
lockedGoldAddress: lockedGold.address,
|
|
54
|
+
maxNumGroupsVotedFor: electionConfig.maxNumGroupsVotedFor,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
return { ...shape, operations };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const sync = makeSync({ getAccountShape });
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Transaction, TransactionRaw } from "../types/types";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
4
|
+
import {
|
|
5
|
+
fromTransactionCommonRaw,
|
|
6
|
+
fromTransactionStatusRawCommon as fromTransactionStatusRaw,
|
|
7
|
+
toTransactionCommonRaw,
|
|
8
|
+
toTransactionStatusRawCommon as toTransactionStatusRaw,
|
|
9
|
+
} from "@ledgerhq/coin-framework/serialization";
|
|
10
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
12
|
+
import { Account } from "@ledgerhq/types-live";
|
|
13
|
+
export const formatTransaction = (t: Transaction, account: Account): string => `
|
|
14
|
+
SEND ${
|
|
15
|
+
t.useAllAmount
|
|
16
|
+
? "MAX CELO"
|
|
17
|
+
: formatCurrencyUnit(getAccountCurrency(account).units[0], t.amount, {
|
|
18
|
+
showCode: true,
|
|
19
|
+
disableRounding: true,
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
TO ${t.recipient}`;
|
|
23
|
+
|
|
24
|
+
const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
25
|
+
const common = fromTransactionCommonRaw(tr);
|
|
26
|
+
return {
|
|
27
|
+
...common,
|
|
28
|
+
family: tr.family,
|
|
29
|
+
fees: tr.fees ? new BigNumber(tr.fees) : null,
|
|
30
|
+
mode: tr.mode,
|
|
31
|
+
index: tr.index,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
36
|
+
const common = toTransactionCommonRaw(t);
|
|
37
|
+
return {
|
|
38
|
+
...common,
|
|
39
|
+
family: t.family,
|
|
40
|
+
fees: t.fees?.toString() || null,
|
|
41
|
+
mode: t.mode,
|
|
42
|
+
index: t.index,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export default {
|
|
47
|
+
formatTransaction,
|
|
48
|
+
fromTransactionRaw,
|
|
49
|
+
toTransactionRaw,
|
|
50
|
+
fromTransactionStatusRaw,
|
|
51
|
+
toTransactionStatusRaw,
|
|
52
|
+
formatTransactionStatus,
|
|
53
|
+
};
|
package/src/config.ts
ADDED