@ledgerhq/coin-concordium 0.2.0-nightly.20251209140356
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/.env.integ.test.example +2 -0
- package/.eslintrc.js +37 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +29 -0
- package/CHANGELOG.md +18 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +21 -0
- package/jest.integ.config.js +8 -0
- package/lib/api/index.d.ts +4 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +56 -0
- package/lib/api/index.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +11 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +19 -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 +21 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +26 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +78 -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 +54 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +20 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +5 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +75 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/sync.d.ts +3 -0
- package/lib/bridge/sync.d.ts.map +1 -0
- package/lib/bridge/sync.js +86 -0
- package/lib/bridge/sync.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 +50 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/bridge/updateTransaction.d.ts +4 -0
- package/lib/bridge/updateTransaction.d.ts.map +1 -0
- package/lib/bridge/updateTransaction.js +17 -0
- package/lib/bridge/updateTransaction.js.map +1 -0
- package/lib/common-logic/account/getBalance.d.ts +3 -0
- package/lib/common-logic/account/getBalance.d.ts.map +1 -0
- package/lib/common-logic/account/getBalance.js +10 -0
- package/lib/common-logic/account/getBalance.js.map +1 -0
- package/lib/common-logic/account/getNextSequence.d.ts +2 -0
- package/lib/common-logic/account/getNextSequence.d.ts.map +1 -0
- package/lib/common-logic/account/getNextSequence.js +9 -0
- package/lib/common-logic/account/getNextSequence.js.map +1 -0
- package/lib/common-logic/common.d.ts +3 -0
- package/lib/common-logic/common.d.ts.map +1 -0
- package/lib/common-logic/common.js +11 -0
- package/lib/common-logic/common.js.map +1 -0
- package/lib/common-logic/history/lastBlock.d.ts +3 -0
- package/lib/common-logic/history/lastBlock.d.ts.map +1 -0
- package/lib/common-logic/history/lastBlock.js +13 -0
- package/lib/common-logic/history/lastBlock.js.map +1 -0
- package/lib/common-logic/history/listOperations.d.ts +11 -0
- package/lib/common-logic/history/listOperations.d.ts.map +1 -0
- package/lib/common-logic/history/listOperations.js +53 -0
- package/lib/common-logic/history/listOperations.js.map +1 -0
- package/lib/common-logic/index.d.ts +11 -0
- package/lib/common-logic/index.d.ts.map +1 -0
- package/lib/common-logic/index.js +24 -0
- package/lib/common-logic/index.js.map +1 -0
- package/lib/common-logic/transaction/broadcast.d.ts +2 -0
- package/lib/common-logic/transaction/broadcast.d.ts.map +1 -0
- package/lib/common-logic/transaction/broadcast.js +9 -0
- package/lib/common-logic/transaction/broadcast.js.map +1 -0
- package/lib/common-logic/transaction/combine.d.ts +2 -0
- package/lib/common-logic/transaction/combine.d.ts.map +1 -0
- package/lib/common-logic/transaction/combine.js +9 -0
- package/lib/common-logic/transaction/combine.js.map +1 -0
- package/lib/common-logic/transaction/craftTransaction.d.ts +15 -0
- package/lib/common-logic/transaction/craftTransaction.d.ts.map +1 -0
- package/lib/common-logic/transaction/craftTransaction.js +20 -0
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -0
- package/lib/common-logic/transaction/estimateFees.d.ts +2 -0
- package/lib/common-logic/transaction/estimateFees.d.ts.map +1 -0
- package/lib/common-logic/transaction/estimateFees.js +21 -0
- package/lib/common-logic/transaction/estimateFees.js.map +1 -0
- package/lib/common-logic/utils.d.ts +6 -0
- package/lib/common-logic/utils.d.ts.map +1 -0
- package/lib/common-logic/utils.js +22 -0
- package/lib/common-logic/utils.js.map +1 -0
- package/lib/config.d.ts +12 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +9 -0
- package/lib/config.js.map +1 -0
- package/lib/index.d.ts +4 -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/indexer.d.ts +6 -0
- package/lib/network/indexer.d.ts.map +1 -0
- package/lib/network/indexer.js +19 -0
- package/lib/network/indexer.js.map +1 -0
- package/lib/network/mock-network.d.ts +5 -0
- package/lib/network/mock-network.d.ts.map +1 -0
- package/lib/network/mock-network.js +29 -0
- package/lib/network/mock-network.js.map +1 -0
- package/lib/network/node.d.ts +12 -0
- package/lib/network/node.d.ts.map +1 -0
- package/lib/network/node.js +92 -0
- package/lib/network/node.js.map +1 -0
- package/lib/network/types.d.ts +47 -0
- package/lib/network/types.d.ts.map +1 -0
- package/lib/network/types.js +7 -0
- package/lib/network/types.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +14 -0
- package/lib/signer/getAddress.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 +11 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-deviceActions.d.ts +4 -0
- package/lib/test/bot-deviceActions.d.ts.map +1 -0
- package/lib/test/bot-deviceActions.js +44 -0
- package/lib/test/bot-deviceActions.js.map +1 -0
- package/lib/test/bot-specs.d.ts +2 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +79 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +5 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +148 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +26 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +36 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +5 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/types/assets.d.ts +3 -0
- package/lib/types/assets.d.ts.map +1 -0
- package/lib/types/assets.js +3 -0
- package/lib/types/assets.js.map +1 -0
- package/lib/types/bridge.d.ts +23 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +3 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/errors.d.ts +4 -0
- package/lib/types/errors.d.ts.map +1 -0
- package/lib/types/errors.js +6 -0
- package/lib/types/errors.js.map +1 -0
- package/lib/types/index.d.ts +13 -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 +10 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/api/index.d.ts +4 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +50 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/bridge/broadcast.d.ts +4 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +7 -0
- package/lib-es/bridge/broadcast.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 +12 -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 +4 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +19 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +71 -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 +48 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +13 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +5 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +68 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/sync.d.ts +3 -0
- package/lib-es/bridge/sync.d.ts.map +1 -0
- package/lib-es/bridge/sync.js +79 -0
- package/lib-es/bridge/sync.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 +44 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/bridge/updateTransaction.d.ts +4 -0
- package/lib-es/bridge/updateTransaction.d.ts.map +1 -0
- package/lib-es/bridge/updateTransaction.js +13 -0
- package/lib-es/bridge/updateTransaction.js.map +1 -0
- package/lib-es/common-logic/account/getBalance.d.ts +3 -0
- package/lib-es/common-logic/account/getBalance.d.ts.map +1 -0
- package/lib-es/common-logic/account/getBalance.js +7 -0
- package/lib-es/common-logic/account/getBalance.js.map +1 -0
- package/lib-es/common-logic/account/getNextSequence.d.ts +2 -0
- package/lib-es/common-logic/account/getNextSequence.d.ts.map +1 -0
- package/lib-es/common-logic/account/getNextSequence.js +6 -0
- package/lib-es/common-logic/account/getNextSequence.js.map +1 -0
- package/lib-es/common-logic/common.d.ts +3 -0
- package/lib-es/common-logic/common.d.ts.map +1 -0
- package/lib-es/common-logic/common.js +7 -0
- package/lib-es/common-logic/common.js.map +1 -0
- package/lib-es/common-logic/history/lastBlock.d.ts +3 -0
- package/lib-es/common-logic/history/lastBlock.d.ts.map +1 -0
- package/lib-es/common-logic/history/lastBlock.js +10 -0
- package/lib-es/common-logic/history/lastBlock.js.map +1 -0
- package/lib-es/common-logic/history/listOperations.d.ts +11 -0
- package/lib-es/common-logic/history/listOperations.d.ts.map +1 -0
- package/lib-es/common-logic/history/listOperations.js +50 -0
- package/lib-es/common-logic/history/listOperations.js.map +1 -0
- package/lib-es/common-logic/index.d.ts +11 -0
- package/lib-es/common-logic/index.d.ts.map +1 -0
- package/lib-es/common-logic/index.js +11 -0
- package/lib-es/common-logic/index.js.map +1 -0
- package/lib-es/common-logic/transaction/broadcast.d.ts +2 -0
- package/lib-es/common-logic/transaction/broadcast.d.ts.map +1 -0
- package/lib-es/common-logic/transaction/broadcast.js +6 -0
- package/lib-es/common-logic/transaction/broadcast.js.map +1 -0
- package/lib-es/common-logic/transaction/combine.d.ts +2 -0
- package/lib-es/common-logic/transaction/combine.d.ts.map +1 -0
- package/lib-es/common-logic/transaction/combine.js +6 -0
- package/lib-es/common-logic/transaction/combine.js.map +1 -0
- package/lib-es/common-logic/transaction/craftTransaction.d.ts +15 -0
- package/lib-es/common-logic/transaction/craftTransaction.d.ts.map +1 -0
- package/lib-es/common-logic/transaction/craftTransaction.js +17 -0
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -0
- package/lib-es/common-logic/transaction/estimateFees.d.ts +2 -0
- package/lib-es/common-logic/transaction/estimateFees.d.ts.map +1 -0
- package/lib-es/common-logic/transaction/estimateFees.js +18 -0
- package/lib-es/common-logic/transaction/estimateFees.js.map +1 -0
- package/lib-es/common-logic/utils.d.ts +6 -0
- package/lib-es/common-logic/utils.d.ts.map +1 -0
- package/lib-es/common-logic/utils.js +13 -0
- package/lib-es/common-logic/utils.js.map +1 -0
- package/lib-es/config.d.ts +12 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +4 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/index.d.ts +4 -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/indexer.d.ts +6 -0
- package/lib-es/network/indexer.d.ts.map +1 -0
- package/lib-es/network/indexer.js +12 -0
- package/lib-es/network/indexer.js.map +1 -0
- package/lib-es/network/mock-network.d.ts +5 -0
- package/lib-es/network/mock-network.d.ts.map +1 -0
- package/lib-es/network/mock-network.js +25 -0
- package/lib-es/network/mock-network.js.map +1 -0
- package/lib-es/network/node.d.ts +12 -0
- package/lib-es/network/node.d.ts.map +1 -0
- package/lib-es/network/node.js +80 -0
- package/lib-es/network/node.js.map +1 -0
- package/lib-es/network/types.d.ts +47 -0
- package/lib-es/network/types.d.ts.map +1 -0
- package/lib-es/network/types.js +4 -0
- package/lib-es/network/types.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +12 -0
- package/lib-es/signer/getAddress.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 +6 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-deviceActions.d.ts +4 -0
- package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
- package/lib-es/test/bot-deviceActions.js +41 -0
- package/lib-es/test/bot-deviceActions.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +1 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +78 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +5 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +142 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +26 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +30 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +5 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/types/assets.d.ts +3 -0
- package/lib-es/types/assets.d.ts.map +1 -0
- package/lib-es/types/assets.js +2 -0
- package/lib-es/types/assets.js.map +1 -0
- package/lib-es/types/bridge.d.ts +23 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +2 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/errors.d.ts +4 -0
- package/lib-es/types/errors.d.ts.map +1 -0
- package/lib-es/types/errors.js +3 -0
- package/lib-es/types/errors.js.map +1 -0
- package/lib-es/types/index.d.ts +13 -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 +10 -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 +137 -0
- package/src/api/index.test.ts +22 -0
- package/src/api/index.ts +88 -0
- package/src/bridge/broadcast.test.ts +36 -0
- package/src/bridge/broadcast.ts +11 -0
- package/src/bridge/createTransaction.test.ts +12 -0
- package/src/bridge/createTransaction.ts +14 -0
- package/src/bridge/deviceTransactionConfig.test.ts +20 -0
- package/src/bridge/deviceTransactionConfig.ts +34 -0
- package/src/bridge/estimateMaxSpendable.ts +25 -0
- package/src/bridge/getTransactionStatus.ts +88 -0
- package/src/bridge/index.test.ts +26 -0
- package/src/bridge/index.ts +65 -0
- package/src/bridge/prepareTransaction.test.ts +29 -0
- package/src/bridge/prepareTransaction.ts +25 -0
- package/src/bridge/signOperation.ts +94 -0
- package/src/bridge/sync.ts +106 -0
- package/src/bridge/transaction.ts +61 -0
- package/src/bridge/updateTransaction.ts +17 -0
- package/src/common-logic/account/getBalance.ts +8 -0
- package/src/common-logic/account/getNextSequence.ts +6 -0
- package/src/common-logic/common.ts +8 -0
- package/src/common-logic/history/lastBlock.ts +11 -0
- package/src/common-logic/history/listOperations.ts +65 -0
- package/src/common-logic/index.ts +11 -0
- package/src/common-logic/transaction/broadcast.ts +6 -0
- package/src/common-logic/transaction/combine.ts +6 -0
- package/src/common-logic/transaction/craftTransaction.ts +36 -0
- package/src/common-logic/transaction/estimateFees.ts +16 -0
- package/src/common-logic/utils.ts +18 -0
- package/src/config.ts +12 -0
- package/src/index.ts +4 -0
- package/src/network/indexer.ts +17 -0
- package/src/network/mock-network.ts +25 -0
- package/src/network/node.ts +94 -0
- package/src/network/types.ts +51 -0
- package/src/signer/getAddress.ts +20 -0
- package/src/signer/index.ts +7 -0
- package/src/test/bot-deviceActions.ts +48 -0
- package/src/test/bot-specs.ts +76 -0
- package/src/test/bridgeDatasetTest.ts +147 -0
- package/src/test/cli.ts +44 -0
- package/src/test/index.ts +6 -0
- package/src/types/assets.ts +3 -0
- package/src/types/bridge.ts +33 -0
- package/src/types/errors.ts +3 -0
- package/src/types/index.ts +13 -0
- package/src/types/signer.ts +11 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Operation } from "@ledgerhq/types-live";
|
|
3
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
+
import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
6
|
+
import { getTransactions } from "../network/indexer";
|
|
7
|
+
import { getAccountInfo, getBlockHeight } from "../network/node";
|
|
8
|
+
|
|
9
|
+
import { ConcordiumOperation } from "../network/types";
|
|
10
|
+
import coinConfig from "../config";
|
|
11
|
+
|
|
12
|
+
const operationAdapter =
|
|
13
|
+
(accountId: string, address: string) =>
|
|
14
|
+
({
|
|
15
|
+
meta: { delivered_amount },
|
|
16
|
+
tx: { Fee, hash, inLedger, date, Account, Destination, Sequence },
|
|
17
|
+
}: ConcordiumOperation) => {
|
|
18
|
+
const type = Account === address ? "OUT" : "IN";
|
|
19
|
+
let value =
|
|
20
|
+
delivered_amount && typeof delivered_amount === "string"
|
|
21
|
+
? new BigNumber(delivered_amount)
|
|
22
|
+
: new BigNumber(0);
|
|
23
|
+
const feeValue = new BigNumber(Fee);
|
|
24
|
+
|
|
25
|
+
if (type === "OUT") {
|
|
26
|
+
if (!Number.isNaN(feeValue)) {
|
|
27
|
+
value = value.plus(feeValue);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const op: Operation = {
|
|
32
|
+
id: encodeOperationId(accountId, hash, type),
|
|
33
|
+
hash: hash,
|
|
34
|
+
accountId,
|
|
35
|
+
type,
|
|
36
|
+
value,
|
|
37
|
+
fee: feeValue,
|
|
38
|
+
blockHash: null,
|
|
39
|
+
blockHeight: inLedger,
|
|
40
|
+
senders: [Account],
|
|
41
|
+
recipients: [Destination],
|
|
42
|
+
date: new Date(),
|
|
43
|
+
transactionSequenceNumber: new BigNumber(Sequence),
|
|
44
|
+
extra: {},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return op;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const filterOperations = (
|
|
51
|
+
transactions: ConcordiumOperation[],
|
|
52
|
+
accountId: string,
|
|
53
|
+
address: string,
|
|
54
|
+
) => {
|
|
55
|
+
return transactions
|
|
56
|
+
.filter(
|
|
57
|
+
({ tx, meta }: ConcordiumOperation) =>
|
|
58
|
+
tx.TransactionType === "Payment" && typeof meta.delivered_amount === "string",
|
|
59
|
+
)
|
|
60
|
+
.map(operationAdapter(accountId, address))
|
|
61
|
+
.filter((op): op is Operation => Boolean(op));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getAccountShape: GetAccountShape = async info => {
|
|
65
|
+
const { address, initialAccount, currency, derivationMode } = info;
|
|
66
|
+
|
|
67
|
+
const accountId = encodeAccountId({
|
|
68
|
+
type: "js",
|
|
69
|
+
version: "2",
|
|
70
|
+
currencyId: currency.id,
|
|
71
|
+
xpubOrAddress: address,
|
|
72
|
+
derivationMode,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// blockheight retrieval
|
|
76
|
+
const blockHeight = await getBlockHeight();
|
|
77
|
+
|
|
78
|
+
// Account info retrieval + spendable balance calculation
|
|
79
|
+
const accountInfo = await getAccountInfo(address);
|
|
80
|
+
const balance = new BigNumber(accountInfo.account_data.Balance);
|
|
81
|
+
const reserveMin = coinConfig.getCoinConfig().minReserve;
|
|
82
|
+
const spendableBalance = new BigNumber(accountInfo.account_data.Balance).minus(reserveMin);
|
|
83
|
+
|
|
84
|
+
// Tx history fetching
|
|
85
|
+
const oldOperations = initialAccount?.operations || [];
|
|
86
|
+
const startAt = oldOperations.length ? (oldOperations[0].blockHeight || 0) + 1 : 0;
|
|
87
|
+
const newTransactions = await getTransactions(address, {
|
|
88
|
+
from: startAt,
|
|
89
|
+
size: 100,
|
|
90
|
+
});
|
|
91
|
+
const newOperations = filterOperations(newTransactions, accountId, address);
|
|
92
|
+
const operations = mergeOps(oldOperations, newOperations as Operation[]);
|
|
93
|
+
|
|
94
|
+
// We return the new account shape
|
|
95
|
+
const shape = {
|
|
96
|
+
id: accountId,
|
|
97
|
+
xpub: address,
|
|
98
|
+
blockHeight,
|
|
99
|
+
balance,
|
|
100
|
+
spendableBalance,
|
|
101
|
+
operations,
|
|
102
|
+
operationsCount: operations.length,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
return shape;
|
|
106
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
3
|
+
import {
|
|
4
|
+
fromTransactionCommonRaw,
|
|
5
|
+
fromTransactionStatusRawCommon as fromTransactionStatusRaw,
|
|
6
|
+
toTransactionCommonRaw,
|
|
7
|
+
toTransactionStatusRawCommon as toTransactionStatusRaw,
|
|
8
|
+
} from "@ledgerhq/coin-framework/serialization/transaction";
|
|
9
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
10
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
11
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
12
|
+
import type { Transaction, TransactionRaw } from "../types";
|
|
13
|
+
|
|
14
|
+
export const formatTransaction = (
|
|
15
|
+
{ amount, recipient, fee, useAllAmount }: Transaction,
|
|
16
|
+
account: Account,
|
|
17
|
+
): string => `
|
|
18
|
+
SEND ${
|
|
19
|
+
useAllAmount
|
|
20
|
+
? "MAX"
|
|
21
|
+
: formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
|
|
22
|
+
showCode: true,
|
|
23
|
+
disableRounding: true,
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
TO ${recipient}
|
|
27
|
+
with fee=${
|
|
28
|
+
!fee
|
|
29
|
+
? "?"
|
|
30
|
+
: formatCurrencyUnit(getAccountCurrency(account).units[0], fee, {
|
|
31
|
+
showCode: true,
|
|
32
|
+
disableRounding: true,
|
|
33
|
+
})
|
|
34
|
+
}`;
|
|
35
|
+
|
|
36
|
+
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
37
|
+
const common = fromTransactionCommonRaw(tr);
|
|
38
|
+
return {
|
|
39
|
+
...common,
|
|
40
|
+
family: tr.family,
|
|
41
|
+
fee: tr.fee ? new BigNumber(tr.fee) : null,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
46
|
+
const common = toTransactionCommonRaw(t);
|
|
47
|
+
return {
|
|
48
|
+
...common,
|
|
49
|
+
family: t.family,
|
|
50
|
+
fee: t.fee ? t.fee.toString() : null,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default {
|
|
55
|
+
formatTransaction,
|
|
56
|
+
fromTransactionRaw,
|
|
57
|
+
toTransactionRaw,
|
|
58
|
+
fromTransactionStatusRaw,
|
|
59
|
+
toTransactionStatusRaw,
|
|
60
|
+
formatTransactionStatus,
|
|
61
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { updateTransaction as defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
2
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import type { Transaction } from "../types";
|
|
4
|
+
|
|
5
|
+
// NOTE: this method is optional, use defaultUpdateTransaction
|
|
6
|
+
// acts as a middleware to update the transaction patch object
|
|
7
|
+
|
|
8
|
+
// NOTE: here is an example transaction updater function
|
|
9
|
+
// in this case, it resets fee to null depending on the patch content
|
|
10
|
+
export const updateTransaction: AccountBridge<Transaction>["updateTransaction"] = (tx, patch) => {
|
|
11
|
+
// eslint-disable-next-line no-constant-condition
|
|
12
|
+
if (patch.recipient === "concordium1" || true) {
|
|
13
|
+
patch = { ...patch, fee: null };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return defaultUpdateTransaction(tx, patch);
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Balance } from "@ledgerhq/coin-framework/api/types";
|
|
2
|
+
import { getAccountInfo } from "../../network/node";
|
|
3
|
+
|
|
4
|
+
// Could be getAccountInfo so it is used in both bridge and api
|
|
5
|
+
export async function getBalance(address: string): Promise<Balance[]> {
|
|
6
|
+
const accountInfo = await getAccountInfo(address);
|
|
7
|
+
return [{ asset: { type: "native" }, value: BigInt(accountInfo.account_data.Balance) }];
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { parseCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
|
|
3
|
+
import { getCryptoCurrencyById } from "@ledgerhq/cryptoassets/currencies";
|
|
4
|
+
|
|
5
|
+
// NOTE: replace ripple by your currency id, it should be found in
|
|
6
|
+
// libs/ledgerjs/packages/cryptoassets/src/currencies.ts
|
|
7
|
+
const concordiumUnit = getCryptoCurrencyById("ripple").units[0];
|
|
8
|
+
export const parseAPIValue = (value: string): BigNumber => parseCurrencyUnit(concordiumUnit, value);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BlockInfo } from "@ledgerhq/coin-framework/api/index";
|
|
2
|
+
import { getLastBlock } from "../../network/node";
|
|
3
|
+
|
|
4
|
+
export async function lastBlock(): Promise<BlockInfo> {
|
|
5
|
+
const result = await getLastBlock();
|
|
6
|
+
return {
|
|
7
|
+
height: result.blockHeight,
|
|
8
|
+
hash: result.blockHash,
|
|
9
|
+
time: new Date(result.timestamp),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Operation, Pagination } from "@ledgerhq/coin-framework/api/index";
|
|
2
|
+
import { getTransactions } from "../../network/indexer";
|
|
3
|
+
import { ConcordiumOperation } from "../../network/types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns list of operations associated to an account.
|
|
7
|
+
* @param address Account address
|
|
8
|
+
* @param pagination Pagination options
|
|
9
|
+
* @returns Operations found and the next "id" or "index" to use for pagination (i.e. `start` property).\
|
|
10
|
+
* If `0` is returns, no pagination needed.
|
|
11
|
+
* This "id" or "index" value, thus it has functional meaning, is different for each blockchain.
|
|
12
|
+
*/
|
|
13
|
+
export async function listOperations(
|
|
14
|
+
address: string,
|
|
15
|
+
page: Pagination,
|
|
16
|
+
): Promise<[Operation[], string]> {
|
|
17
|
+
const transactions = await getTransactions(address, { from: page.minHeight });
|
|
18
|
+
return [transactions.map(convertToCoreOperation(address)), ""];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const convertToCoreOperation =
|
|
22
|
+
(address: string) =>
|
|
23
|
+
(operation: ConcordiumOperation): Operation => {
|
|
24
|
+
const {
|
|
25
|
+
meta: { delivered_amount },
|
|
26
|
+
tx: { Fee, hash, inLedger, date, Account, Destination },
|
|
27
|
+
} = operation;
|
|
28
|
+
|
|
29
|
+
const type = Account === address ? "OUT" : "IN";
|
|
30
|
+
let value =
|
|
31
|
+
delivered_amount && typeof delivered_amount === "string"
|
|
32
|
+
? BigInt(delivered_amount)
|
|
33
|
+
: BigInt(0);
|
|
34
|
+
|
|
35
|
+
const feeValue = BigInt(Fee);
|
|
36
|
+
if (type === "OUT") {
|
|
37
|
+
if (!Number.isNaN(feeValue)) {
|
|
38
|
+
value = value + feeValue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
/**
|
|
44
|
+
* Note: The operation ID must be concatenated with another
|
|
45
|
+
* value if the transaction hash is not enough to identify it
|
|
46
|
+
*/
|
|
47
|
+
id: hash,
|
|
48
|
+
asset: { type: "native" },
|
|
49
|
+
tx: {
|
|
50
|
+
hash,
|
|
51
|
+
fees: feeValue,
|
|
52
|
+
date: new Date(date),
|
|
53
|
+
failed: false,
|
|
54
|
+
block: {
|
|
55
|
+
height: inLedger,
|
|
56
|
+
hash,
|
|
57
|
+
time: new Date(date),
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
type,
|
|
61
|
+
value,
|
|
62
|
+
senders: [Account],
|
|
63
|
+
recipients: [Destination],
|
|
64
|
+
};
|
|
65
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { broadcast } from "./transaction/broadcast";
|
|
2
|
+
export { combine } from "./transaction/combine";
|
|
3
|
+
export { craftTransaction } from "./transaction/craftTransaction";
|
|
4
|
+
export { estimateFees } from "./transaction/estimateFees";
|
|
5
|
+
export { getBalance } from "./account/getBalance";
|
|
6
|
+
export { lastBlock } from "./history/lastBlock";
|
|
7
|
+
export { listOperations } from "./history/listOperations";
|
|
8
|
+
export { isRecipientValid } from "./utils";
|
|
9
|
+
export { getNextValidSequence } from "./account/getNextSequence";
|
|
10
|
+
|
|
11
|
+
export { parseAPIValue } from "./common";
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { ConcordiumNativeTransaction } from "../../types";
|
|
3
|
+
|
|
4
|
+
const encodeNativeTx = (nativeTx: ConcordiumNativeTransaction) => JSON.stringify(nativeTx);
|
|
5
|
+
|
|
6
|
+
export async function craftTransaction(
|
|
7
|
+
account: {
|
|
8
|
+
address: string;
|
|
9
|
+
nextSequenceNumber?: number;
|
|
10
|
+
publicKey?: string;
|
|
11
|
+
},
|
|
12
|
+
transaction: {
|
|
13
|
+
recipient?: string;
|
|
14
|
+
amount: BigNumber;
|
|
15
|
+
fee?: BigNumber;
|
|
16
|
+
},
|
|
17
|
+
): Promise<{
|
|
18
|
+
nativeTransaction: ConcordiumNativeTransaction;
|
|
19
|
+
serializedTransaction: string;
|
|
20
|
+
}> {
|
|
21
|
+
const nativeTransaction: ConcordiumNativeTransaction = {
|
|
22
|
+
TransactionType: "Payment",
|
|
23
|
+
Account: account.address,
|
|
24
|
+
Amount: transaction.amount.toString(),
|
|
25
|
+
Destination: transaction.recipient || "",
|
|
26
|
+
Fee: transaction.fee?.toString() || "0",
|
|
27
|
+
Sequence: account.nextSequenceNumber || 0,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const serializedTransaction = encodeNativeTx(nativeTransaction);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
nativeTransaction,
|
|
34
|
+
serializedTransaction,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { simulate } from "../../network/node";
|
|
2
|
+
import { SimulationError } from "../../types/errors";
|
|
3
|
+
|
|
4
|
+
export async function estimateFees(serializedTransaction: string): Promise<bigint> {
|
|
5
|
+
try {
|
|
6
|
+
// We call the node to do a dry run and estimate fees
|
|
7
|
+
return BigInt(await simulate(serializedTransaction));
|
|
8
|
+
} catch (e) {
|
|
9
|
+
// default value is required in case of simulation error, else user will encounter an error in the flow
|
|
10
|
+
if (e instanceof SimulationError) {
|
|
11
|
+
return BigInt(1000);
|
|
12
|
+
} else {
|
|
13
|
+
throw new Error("Unexpected error while estimating fees.");
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
|
|
3
|
+
export const UINT32_MAX = new BigNumber(2).pow(32).minus(1);
|
|
4
|
+
|
|
5
|
+
export const validateTag = (tag: BigNumber) => {
|
|
6
|
+
return (
|
|
7
|
+
!tag.isNaN() && tag.isFinite() && tag.isInteger() && tag.isPositive() && tag.lte(UINT32_MAX)
|
|
8
|
+
);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function isRecipientValid(recipient: string): boolean {
|
|
12
|
+
return recipient.length > 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const encode = (transaction: string, signature: string, publicKey?: string) => {
|
|
16
|
+
// sample encoding
|
|
17
|
+
return `${transaction}${publicKey}${signature}encodedTx`;
|
|
18
|
+
};
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import buildCoinConfig, { type CurrencyConfig } from "@ledgerhq/coin-framework/config";
|
|
2
|
+
|
|
3
|
+
export type ConcordiumConfig = {
|
|
4
|
+
nodeUrl: string;
|
|
5
|
+
minReserve: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type ConcordiumCoinConfig = CurrencyConfig & ConcordiumConfig;
|
|
9
|
+
|
|
10
|
+
const coinConfig = buildCoinConfig<ConcordiumCoinConfig>();
|
|
11
|
+
|
|
12
|
+
export default coinConfig;
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import network from "@ledgerhq/live-network/network";
|
|
2
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
3
|
+
import { AccountTxResponse } from "./types";
|
|
4
|
+
|
|
5
|
+
export const getTransactions = async (
|
|
6
|
+
address: string,
|
|
7
|
+
params: { from: number; size?: number },
|
|
8
|
+
): Promise<AccountTxResponse["transactions"]> => {
|
|
9
|
+
const { data } = await network<AccountTxResponse>({
|
|
10
|
+
// NOTE: add INDEXER_BOILERPLATE to libs/env/src/env.ts
|
|
11
|
+
// @ts-expect-error: add INDEXER_BOILERPLATE to libs/env/src/env.ts
|
|
12
|
+
url: `${getEnv("INDEXER_BOILERPLATE")}/account/${address}/transactions`,
|
|
13
|
+
method: "GET",
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return data.transactions;
|
|
17
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
In a real use case you should use live-network library like this :
|
|
4
|
+
|
|
5
|
+
import network from "@ledgerhq/live-network/network";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
instead of this mocked method
|
|
9
|
+
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const network = (params: { url: string; method: "GET" | "POST" }) => {
|
|
13
|
+
switch (true) {
|
|
14
|
+
case params.url.includes("simulate"):
|
|
15
|
+
break;
|
|
16
|
+
case params.url.includes("submit"):
|
|
17
|
+
break;
|
|
18
|
+
case params.url.includes("account_info"):
|
|
19
|
+
break;
|
|
20
|
+
case params.url.includes("transactions"):
|
|
21
|
+
break;
|
|
22
|
+
default:
|
|
23
|
+
throw new Error("Mock network 404");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import network from "@ledgerhq/live-network/network";
|
|
2
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
3
|
+
import { SimulationError } from "../types/errors";
|
|
4
|
+
import coinConfig from "../config";
|
|
5
|
+
import { AccountInfoResponse, SubmitReponse } from "./types";
|
|
6
|
+
|
|
7
|
+
const getNodeUrl = () => coinConfig.getCoinConfig().nodeUrl;
|
|
8
|
+
|
|
9
|
+
// NOTE: add NODE_BOILERPLATE to libs/env/src/env.ts
|
|
10
|
+
|
|
11
|
+
// txPayload needs to be unsigned
|
|
12
|
+
export const simulate = async (serializedTx: string): Promise<number> => {
|
|
13
|
+
// @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts
|
|
14
|
+
const url = `${getEnv("NODE_BOILERPLATE")}/simulate`;
|
|
15
|
+
const { data } = await network({
|
|
16
|
+
url,
|
|
17
|
+
method: "POST",
|
|
18
|
+
data: {
|
|
19
|
+
txPayload: serializedTx,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
if (data.error) {
|
|
23
|
+
throw new SimulationError();
|
|
24
|
+
}
|
|
25
|
+
return data.fees;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// can be called nonce or sequence
|
|
29
|
+
export const getNextSequence = async (address: string): Promise<number> => {
|
|
30
|
+
// @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts
|
|
31
|
+
const url = `${getEnv("NODE_BOILERPLATE")}/${address}/sequence`;
|
|
32
|
+
try {
|
|
33
|
+
const { data } = await network({
|
|
34
|
+
url,
|
|
35
|
+
method: "GET",
|
|
36
|
+
});
|
|
37
|
+
return data.sequence;
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const getBlockHeight = async (): Promise<number> => {
|
|
44
|
+
// @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts
|
|
45
|
+
const url = `${getEnv("NODE_BOILERPLATE")}/blockheight`;
|
|
46
|
+
const { data } = await network({
|
|
47
|
+
url,
|
|
48
|
+
method: "GET",
|
|
49
|
+
});
|
|
50
|
+
return data.blockHeight;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const getLastBlock = async (): Promise<{
|
|
54
|
+
blockHeight: number;
|
|
55
|
+
blockHash: string;
|
|
56
|
+
timestamp: number;
|
|
57
|
+
}> => {
|
|
58
|
+
// @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts
|
|
59
|
+
const url = `${getEnv("NODE_BOILERPLATE")}/block/current`;
|
|
60
|
+
const { data } = await network({
|
|
61
|
+
url,
|
|
62
|
+
method: "GET",
|
|
63
|
+
});
|
|
64
|
+
return data;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export const submit = async (signedTx: string): Promise<SubmitReponse> => {
|
|
68
|
+
// @ts-expect-error: add NODE_BOILERPLATE to libs/env/src/env.ts
|
|
69
|
+
const url = `${getEnv("NODE_BOILERPLATE")}/submit`;
|
|
70
|
+
const { data } = await network<SubmitReponse>({
|
|
71
|
+
url,
|
|
72
|
+
method: "GET",
|
|
73
|
+
});
|
|
74
|
+
return data;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const getAccountInfo = async (address: string): Promise<AccountInfoResponse> => {
|
|
78
|
+
const {
|
|
79
|
+
data: { result },
|
|
80
|
+
} = await network<{ result: AccountInfoResponse }>({
|
|
81
|
+
method: "POST",
|
|
82
|
+
url: getNodeUrl(),
|
|
83
|
+
data: {
|
|
84
|
+
method: "account_info",
|
|
85
|
+
params: [
|
|
86
|
+
{
|
|
87
|
+
account: address,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return result;
|
|
94
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type ConcordiumOperation = {
|
|
2
|
+
meta: {
|
|
3
|
+
delivered_amount: string;
|
|
4
|
+
};
|
|
5
|
+
tx: {
|
|
6
|
+
Account: string;
|
|
7
|
+
Amount: string;
|
|
8
|
+
Destination: string;
|
|
9
|
+
Fee: string;
|
|
10
|
+
Memo: string;
|
|
11
|
+
Sequence: number;
|
|
12
|
+
SigningPubKey: string;
|
|
13
|
+
TransactionType: string;
|
|
14
|
+
TxnSignature: string;
|
|
15
|
+
date: number;
|
|
16
|
+
hash: string;
|
|
17
|
+
inLedger: number;
|
|
18
|
+
};
|
|
19
|
+
validated: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ResponseStatus =
|
|
23
|
+
| { status: string; error?: never }
|
|
24
|
+
| {
|
|
25
|
+
status?: never;
|
|
26
|
+
error: string;
|
|
27
|
+
};
|
|
28
|
+
export function isResponseStatus(obj: object): obj is ResponseStatus {
|
|
29
|
+
return "status" in obj || "error" in obj;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type NewAccount = "NewAccount";
|
|
33
|
+
export type AccountInfoResponse = {
|
|
34
|
+
account_data: {
|
|
35
|
+
Account: string;
|
|
36
|
+
Balance: string;
|
|
37
|
+
};
|
|
38
|
+
ledger_hash: string;
|
|
39
|
+
ledger_index: number;
|
|
40
|
+
validated: boolean;
|
|
41
|
+
} & ResponseStatus;
|
|
42
|
+
|
|
43
|
+
export type SubmitReponse = {
|
|
44
|
+
accepted: boolean;
|
|
45
|
+
tx_hash: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type AccountTxResponse = {
|
|
49
|
+
account: string;
|
|
50
|
+
transactions: ConcordiumOperation[];
|
|
51
|
+
} & ResponseStatus;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
2
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
3
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
4
|
+
import { ConcordiumAddress, ConcordiumSigner } from "../types";
|
|
5
|
+
|
|
6
|
+
const getAddress = (signerContext: SignerContext<ConcordiumSigner>): GetAddressFn => {
|
|
7
|
+
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
|
|
8
|
+
const { address, publicKey } = (await signerContext(deviceId, signer =>
|
|
9
|
+
signer.getAddress(path),
|
|
10
|
+
)) as ConcordiumAddress;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
path,
|
|
14
|
+
address,
|
|
15
|
+
publicKey,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default getAddress;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
|
|
2
|
+
import {
|
|
3
|
+
deviceActionFlow,
|
|
4
|
+
formatDeviceAmount,
|
|
5
|
+
SpeculosButton,
|
|
6
|
+
} from "@ledgerhq/coin-framework/bot/specs";
|
|
7
|
+
import type { Transaction } from "../types";
|
|
8
|
+
|
|
9
|
+
export const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
10
|
+
steps: [
|
|
11
|
+
{
|
|
12
|
+
title: "Transaction Type",
|
|
13
|
+
button: SpeculosButton.RIGHT,
|
|
14
|
+
expectedValue: () => "Payment",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
title: "Amount",
|
|
18
|
+
button: SpeculosButton.RIGHT,
|
|
19
|
+
expectedValue: ({ account, status }) => formatDeviceAmount(account.currency, status.amount),
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
title: "Fee",
|
|
23
|
+
button: SpeculosButton.RIGHT,
|
|
24
|
+
expectedValue: ({ account, status }) =>
|
|
25
|
+
formatDeviceAmount(account.currency, status.estimatedFees),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
title: "Destination",
|
|
29
|
+
button: SpeculosButton.RIGHT,
|
|
30
|
+
trimValue: true,
|
|
31
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
title: "Account",
|
|
35
|
+
button: SpeculosButton.RIGHT,
|
|
36
|
+
trimValue: true,
|
|
37
|
+
expectedValue: ({ account }) => account.freshAddress,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
title: "Accept",
|
|
41
|
+
button: SpeculosButton.BOTH,
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
title: "Sign transaction",
|
|
45
|
+
button: SpeculosButton.BOTH,
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
});
|