@ledgerhq/coin-ton 0.3.12-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +20 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +19 -0
- package/CHANGELOG.md +15 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +12 -0
- package/lib/__tests__/fixtures/api.fixtures.d.ts +4 -0
- package/lib/__tests__/fixtures/api.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/api.fixtures.js +33 -0
- package/lib/__tests__/fixtures/api.fixtures.js.map +1 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts +29 -0
- package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
- package/lib/__tests__/fixtures/common.fixtures.js +124 -0
- package/lib/__tests__/fixtures/common.fixtures.js.map +1 -0
- package/lib/__tests__/integration/bridge.integration.test.d.ts +14 -0
- package/lib/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
- package/lib/__tests__/integration/bridge.integration.test.js +136 -0
- package/lib/__tests__/integration/bridge.integration.test.js.map +1 -0
- package/lib/__tests__/unit/api.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/api.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/api.unit.test.js +77 -0
- package/lib/__tests__/unit/api.unit.test.js.map +1 -0
- package/lib/__tests__/unit/broadcast.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/broadcast.unit.test.js +40 -0
- package/lib/__tests__/unit/broadcast.unit.test.js.map +1 -0
- package/lib/__tests__/unit/createTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/createTransaction.unit.test.js +34 -0
- package/lib/__tests__/unit/createTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +74 -0
- package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js +31 -0
- package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js +96 -0
- package/lib/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.js +67 -0
- package/lib/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.js +42 -0
- package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
- package/lib/__tests__/unit/signOperation.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/signOperation.unit.test.js +83 -0
- package/lib/__tests__/unit/signOperation.unit.test.js.map +1 -0
- package/lib/__tests__/unit/txn.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/txn.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/txn.unit.test.js +116 -0
- package/lib/__tests__/unit/txn.unit.test.js.map +1 -0
- package/lib/__tests__/unit/utils.unit.test.d.ts +2 -0
- package/lib/__tests__/unit/utils.unit.test.d.ts.map +1 -0
- package/lib/__tests__/unit/utils.unit.test.js +97 -0
- package/lib/__tests__/unit/utils.unit.test.js.map +1 -0
- package/lib/bridge/bridgeHelpers/api.d.ts +10 -0
- package/lib/bridge/bridgeHelpers/api.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/api.js +104 -0
- package/lib/bridge/bridgeHelpers/api.js.map +1 -0
- package/lib/bridge/bridgeHelpers/api.types.d.ts +164 -0
- package/lib/bridge/bridgeHelpers/api.types.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/api.types.js +3 -0
- package/lib/bridge/bridgeHelpers/api.types.js.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts +5 -0
- package/lib/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib/bridge/bridgeHelpers/txn.js +166 -0
- package/lib/bridge/bridgeHelpers/txn.js.map +1 -0
- package/lib/bridge/js.d.ts +12 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +65 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/broadcast.d.ts +5 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +19 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/cli-transaction.d.ts +12 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +21 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/config.d.ts +9 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/createTransaction.d.ts +5 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +16 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +11 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +37 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/errors.d.ts +4 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +9 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +5 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +32 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +5 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +97 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +31 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/hw-signMessage.d.ts +12 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +33 -0
- package/lib/hw-signMessage.js.map +1 -0
- package/lib/prepareTransaction.d.ts +5 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +29 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/signOperation.d.ts +11 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +96 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +27 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +8 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +106 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +4 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +34 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronisation.d.ts +5 -0
- package/lib/synchronisation.d.ts.map +1 -0
- package/lib/synchronisation.js +95 -0
- package/lib/synchronisation.js.map +1 -0
- package/lib/transaction.d.ts +14 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +41 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +65 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +3 -0
- package/lib/types.js.map +1 -0
- package/lib/utils.d.ts +11 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +125 -0
- package/lib/utils.js.map +1 -0
- package/lib-es/__tests__/fixtures/api.fixtures.d.ts +4 -0
- package/lib-es/__tests__/fixtures/api.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/api.fixtures.js +30 -0
- package/lib-es/__tests__/fixtures/api.fixtures.js.map +1 -0
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts +29 -0
- package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -0
- package/lib-es/__tests__/fixtures/common.fixtures.js +118 -0
- package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -0
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts +14 -0
- package/lib-es/__tests__/integration/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/__tests__/integration/bridge.integration.test.js +130 -0
- package/lib-es/__tests__/integration/bridge.integration.test.js.map +1 -0
- package/lib-es/__tests__/unit/api.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/api.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/api.unit.test.js +52 -0
- package/lib-es/__tests__/unit/api.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.js +35 -0
- package/lib-es/__tests__/unit/broadcast.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.js +29 -0
- package/lib-es/__tests__/unit/createTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +69 -0
- package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js +26 -0
- package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js +91 -0
- package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js +62 -0
- package/lib-es/__tests__/unit/hw-getAddress.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +37 -0
- package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.js +78 -0
- package/lib-es/__tests__/unit/signOperation.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/txn.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/txn.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/txn.unit.test.js +111 -0
- package/lib-es/__tests__/unit/txn.unit.test.js.map +1 -0
- package/lib-es/__tests__/unit/utils.unit.test.d.ts +2 -0
- package/lib-es/__tests__/unit/utils.unit.test.d.ts.map +1 -0
- package/lib-es/__tests__/unit/utils.unit.test.js +95 -0
- package/lib-es/__tests__/unit/utils.unit.test.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.d.ts +10 -0
- package/lib-es/bridge/bridgeHelpers/api.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.js +93 -0
- package/lib-es/bridge/bridgeHelpers/api.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.types.d.ts +164 -0
- package/lib-es/bridge/bridgeHelpers/api.types.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/api.types.js +2 -0
- package/lib-es/bridge/bridgeHelpers/api.types.js.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts +5 -0
- package/lib-es/bridge/bridgeHelpers/txn.d.ts.map +1 -0
- package/lib-es/bridge/bridgeHelpers/txn.js +158 -0
- package/lib-es/bridge/bridgeHelpers/txn.js.map +1 -0
- package/lib-es/bridge/js.d.ts +12 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +56 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/broadcast.d.ts +5 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +17 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +12 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +15 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/config.d.ts +9 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/createTransaction.d.ts +5 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +14 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +11 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +35 -0
- package/lib-es/deviceTransactionConfig.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 +6 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +5 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +30 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +5 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +93 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +29 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/hw-signMessage.d.ts +12 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +29 -0
- package/lib-es/hw-signMessage.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +5 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +27 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/signOperation.d.ts +11 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +91 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +27 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +8 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +99 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +4 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +31 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronisation.d.ts +5 -0
- package/lib-es/synchronisation.d.ts.map +1 -0
- package/lib-es/synchronisation.js +88 -0
- package/lib-es/synchronisation.js.map +1 -0
- package/lib-es/transaction.d.ts +14 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +33 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types.d.ts +65 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +2 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/utils.d.ts +11 -0
- package/lib-es/utils.d.ts.map +1 -0
- package/lib-es/utils.js +112 -0
- package/lib-es/utils.js.map +1 -0
- package/package.json +86 -0
- package/src/__tests__/fixtures/api.fixtures.ts +39 -0
- package/src/__tests__/fixtures/common.fixtures.ts +139 -0
- package/src/__tests__/integration/bridge.integration.test.ts +135 -0
- package/src/__tests__/unit/api.unit.test.ts +60 -0
- package/src/__tests__/unit/broadcast.unit.test.ts +36 -0
- package/src/__tests__/unit/createTransaction.unit.test.ts +20 -0
- package/src/__tests__/unit/deviceTransactionConfig.unit.test.ts +69 -0
- package/src/__tests__/unit/estimateMaxSpendable.unit.test.ts +19 -0
- package/src/__tests__/unit/getTransactionStatus.unit.test.ts +119 -0
- package/src/__tests__/unit/hw-getAddress.unit.test.ts +58 -0
- package/src/__tests__/unit/prepareTransaction.unit.test.ts +52 -0
- package/src/__tests__/unit/signOperation.unit.test.ts +90 -0
- package/src/__tests__/unit/txn.unit.test.ts +121 -0
- package/src/__tests__/unit/utils.unit.test.ts +126 -0
- package/src/bridge/bridgeHelpers/api.ts +104 -0
- package/src/bridge/bridgeHelpers/api.types.ts +178 -0
- package/src/bridge/bridgeHelpers/txn.ts +166 -0
- package/src/bridge/js.ts +65 -0
- package/src/broadcast.ts +13 -0
- package/src/cli-transaction.ts +30 -0
- package/src/config.ts +21 -0
- package/src/createTransaction.ts +17 -0
- package/src/deviceTransactionConfig.ts +48 -0
- package/src/errors.ts +6 -0
- package/src/estimateMaxSpendable.ts +40 -0
- package/src/getTransactionStatus.ts +130 -0
- package/src/hw-getAddress.ts +28 -0
- package/src/hw-signMessage.ts +31 -0
- package/src/prepareTransaction.ts +27 -0
- package/src/signOperation.ts +115 -0
- package/src/signer.ts +32 -0
- package/src/specs.ts +122 -0
- package/src/speculos-deviceActions.ts +38 -0
- package/src/synchronisation.ts +91 -0
- package/src/transaction.ts +61 -0
- package/src/types.ts +82 -0
- package/src/utils.ts +120 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
2
|
+
import { Operation } from "@ledgerhq/types-live";
|
|
3
|
+
import { Address } from "@ton/ton";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
import { TonOperation } from "../../types";
|
|
6
|
+
import { isAddressValid } from "../../utils";
|
|
7
|
+
import { fetchTransactions } from "./api";
|
|
8
|
+
import { TonAddressBook, TonTransaction, TonTransactionsList } from "./api.types";
|
|
9
|
+
|
|
10
|
+
export async function getTransactions(
|
|
11
|
+
addr: string,
|
|
12
|
+
startLt?: string,
|
|
13
|
+
): Promise<TonTransactionsList> {
|
|
14
|
+
const txs = await fetchTransactions(addr, { startLt });
|
|
15
|
+
if (txs.transactions.length === 0) return txs;
|
|
16
|
+
let tmpTxs: TonTransactionsList;
|
|
17
|
+
let isUncompletedResult = true;
|
|
18
|
+
|
|
19
|
+
while (isUncompletedResult) {
|
|
20
|
+
const { lt, hash } = txs.transactions[txs.transactions.length - 1];
|
|
21
|
+
tmpTxs = await fetchTransactions(addr, { startLt, endLt: lt });
|
|
22
|
+
// we found the last transaction
|
|
23
|
+
if (tmpTxs.transactions.length === 1) {
|
|
24
|
+
isUncompletedResult = false;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
// it should always match
|
|
28
|
+
if (hash !== tmpTxs.transactions[0].hash) throw Error("[ton] transaction hash does not match");
|
|
29
|
+
tmpTxs.transactions.shift(); // first element is repeated
|
|
30
|
+
txs.transactions.push(...tmpTxs.transactions);
|
|
31
|
+
txs.address_book = { ...txs.address_book, ...tmpTxs.address_book };
|
|
32
|
+
}
|
|
33
|
+
return txs;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getFriendlyAddress(addressBook: TonAddressBook, rawAddr?: string | null): string[] {
|
|
37
|
+
if (!rawAddr) return [];
|
|
38
|
+
if (addressBook[rawAddr]) return [addressBook[rawAddr].user_friendly];
|
|
39
|
+
if (!isAddressValid(rawAddr)) throw new Error("[ton] address is not valid");
|
|
40
|
+
return [Address.parse(rawAddr).toString({ urlSafe: true, bounceable: true })];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function mapTxToOps(
|
|
44
|
+
accountId: string,
|
|
45
|
+
addr: string,
|
|
46
|
+
addressBook: TonAddressBook,
|
|
47
|
+
): (tx: TonTransaction) => TonOperation[] {
|
|
48
|
+
return (tx: TonTransaction): TonOperation[] => {
|
|
49
|
+
const ops: TonOperation[] = [];
|
|
50
|
+
|
|
51
|
+
if (tx.out_msgs.length > 1) throw Error(`[ton] txn with > 1 output not expected ${tx}`);
|
|
52
|
+
|
|
53
|
+
const accountAddr = Address.parse(tx.account).toString({ urlSafe: true, bounceable: false });
|
|
54
|
+
|
|
55
|
+
if (accountAddr !== addr) throw Error(`[ton] unexpected address ${accountAddr} ${addr}`);
|
|
56
|
+
|
|
57
|
+
const isReceiving =
|
|
58
|
+
tx.in_msg &&
|
|
59
|
+
tx.in_msg.source &&
|
|
60
|
+
tx.in_msg.source !== "" &&
|
|
61
|
+
tx.in_msg.value &&
|
|
62
|
+
tx.in_msg.value !== "0" &&
|
|
63
|
+
tx.account === tx.in_msg.destination;
|
|
64
|
+
|
|
65
|
+
const isSending =
|
|
66
|
+
tx.out_msgs.length !== 0 &&
|
|
67
|
+
tx.out_msgs[0].source &&
|
|
68
|
+
tx.out_msgs[0].source !== "" &&
|
|
69
|
+
tx.out_msgs[0].value &&
|
|
70
|
+
tx.out_msgs[0].value !== "0" &&
|
|
71
|
+
tx.account === tx.out_msgs[0].source;
|
|
72
|
+
|
|
73
|
+
const date = new Date(tx.now * 1000); // now is defined in seconds
|
|
74
|
+
const hash = tx.in_msg?.hash ?? tx.hash; // this is the hash we know in signature time
|
|
75
|
+
const hasFailed =
|
|
76
|
+
tx.description.compute_ph.success === false && tx.description.compute_ph.exit_code !== 0;
|
|
77
|
+
|
|
78
|
+
if (isReceiving) {
|
|
79
|
+
let subOperations: Operation[] | undefined;
|
|
80
|
+
if (tx.total_fees !== "0") {
|
|
81
|
+
// these are small amount of fees payed when receiving
|
|
82
|
+
// we don't want to show them in the charts
|
|
83
|
+
subOperations = [
|
|
84
|
+
{
|
|
85
|
+
id: encodeOperationId(accountId, hash, "NONE"),
|
|
86
|
+
hash,
|
|
87
|
+
type: "NONE",
|
|
88
|
+
value: BigNumber(tx.total_fees),
|
|
89
|
+
fee: BigNumber(0),
|
|
90
|
+
blockHeight: tx.mc_block_seqno ?? 1,
|
|
91
|
+
blockHash: null,
|
|
92
|
+
hasFailed,
|
|
93
|
+
accountId,
|
|
94
|
+
senders: [accountAddr],
|
|
95
|
+
recipients: [],
|
|
96
|
+
date,
|
|
97
|
+
extra: {
|
|
98
|
+
lt: tx.lt,
|
|
99
|
+
explorerHash: tx.hash,
|
|
100
|
+
comment: {
|
|
101
|
+
isEncrypted: false,
|
|
102
|
+
text: "",
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
];
|
|
107
|
+
}
|
|
108
|
+
ops.push({
|
|
109
|
+
id: encodeOperationId(accountId, hash, "IN"),
|
|
110
|
+
hash,
|
|
111
|
+
type: "IN",
|
|
112
|
+
value: BigNumber(tx.in_msg?.value ?? 0),
|
|
113
|
+
fee: BigNumber(tx.total_fees),
|
|
114
|
+
blockHeight: tx.mc_block_seqno ?? 1,
|
|
115
|
+
blockHash: null,
|
|
116
|
+
hasFailed,
|
|
117
|
+
accountId,
|
|
118
|
+
senders: getFriendlyAddress(addressBook, tx.in_msg?.source),
|
|
119
|
+
recipients: [accountAddr],
|
|
120
|
+
date,
|
|
121
|
+
extra: {
|
|
122
|
+
lt: tx.lt,
|
|
123
|
+
explorerHash: tx.hash,
|
|
124
|
+
comment: {
|
|
125
|
+
isEncrypted: tx.in_msg?.message_content?.decoded?.type === "binary_comment",
|
|
126
|
+
text:
|
|
127
|
+
tx.in_msg?.message_content?.decoded?.type === "text_comment"
|
|
128
|
+
? tx.in_msg.message_content.decoded.comment
|
|
129
|
+
: "",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
subOperations,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (isSending) {
|
|
137
|
+
ops.push({
|
|
138
|
+
id: encodeOperationId(accountId, hash, "OUT"),
|
|
139
|
+
hash: tx.out_msgs[0].hash, // this hash matches with in_msg.hash of IN transaction
|
|
140
|
+
type: "OUT",
|
|
141
|
+
value: BigNumber(tx.out_msgs[0].value ?? 0),
|
|
142
|
+
fee: BigNumber(tx.total_fees),
|
|
143
|
+
blockHeight: tx.mc_block_seqno ?? 1,
|
|
144
|
+
blockHash: null,
|
|
145
|
+
hasFailed,
|
|
146
|
+
accountId,
|
|
147
|
+
senders: [accountAddr],
|
|
148
|
+
recipients: getFriendlyAddress(addressBook, tx.out_msgs[0].destination),
|
|
149
|
+
date,
|
|
150
|
+
extra: {
|
|
151
|
+
lt: tx.lt,
|
|
152
|
+
explorerHash: tx.hash,
|
|
153
|
+
comment: {
|
|
154
|
+
isEncrypted: tx.out_msgs[0].message_content?.decoded?.type === "binary_comment",
|
|
155
|
+
text:
|
|
156
|
+
tx.out_msgs[0].message_content?.decoded?.type === "text_comment"
|
|
157
|
+
? tx.out_msgs[0].message_content.decoded.comment
|
|
158
|
+
: "",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return ops;
|
|
165
|
+
};
|
|
166
|
+
}
|
package/src/bridge/js.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import {
|
|
3
|
+
defaultUpdateTransaction,
|
|
4
|
+
makeAccountBridgeReceive,
|
|
5
|
+
makeScanAccounts,
|
|
6
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
7
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
8
|
+
|
|
9
|
+
import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
10
|
+
import broadcast from "../broadcast";
|
|
11
|
+
import { TonCoinConfig, setCoinConfig } from "../config";
|
|
12
|
+
import createTransaction from "../createTransaction";
|
|
13
|
+
import estimateMaxSpendable from "../estimateMaxSpendable";
|
|
14
|
+
import getTransactionStatus from "../getTransactionStatus";
|
|
15
|
+
import resolver from "../hw-getAddress";
|
|
16
|
+
import prepareTransaction from "../prepareTransaction";
|
|
17
|
+
import { buildSignOperation } from "../signOperation";
|
|
18
|
+
import { TonSigner } from "../signer";
|
|
19
|
+
import { getAccountShape, sync } from "../synchronisation";
|
|
20
|
+
import type { Transaction } from "../types";
|
|
21
|
+
|
|
22
|
+
export function buildCurrencyBridge(signerContext: SignerContext<TonSigner>): CurrencyBridge {
|
|
23
|
+
const getAddress = resolver(signerContext);
|
|
24
|
+
|
|
25
|
+
const scanAccounts = makeScanAccounts({
|
|
26
|
+
getAccountShape,
|
|
27
|
+
getAddressFn: getAddress,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
preload: async () => Promise.resolve({}),
|
|
32
|
+
hydrate: () => {},
|
|
33
|
+
scanAccounts,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function buildAccountBridge(
|
|
38
|
+
signerContext: SignerContext<TonSigner>,
|
|
39
|
+
): AccountBridge<Transaction> {
|
|
40
|
+
const getAddress = resolver(signerContext);
|
|
41
|
+
|
|
42
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
43
|
+
const signOperation = buildSignOperation(signerContext);
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
estimateMaxSpendable,
|
|
47
|
+
createTransaction,
|
|
48
|
+
updateTransaction: defaultUpdateTransaction,
|
|
49
|
+
getTransactionStatus,
|
|
50
|
+
prepareTransaction,
|
|
51
|
+
sync,
|
|
52
|
+
receive,
|
|
53
|
+
signOperation,
|
|
54
|
+
broadcast,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createBridges(signerContext: SignerContext<TonSigner>, coinConfig: TonCoinConfig) {
|
|
59
|
+
setCoinConfig(coinConfig);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
63
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
64
|
+
};
|
|
65
|
+
}
|
package/src/broadcast.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
2
|
+
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import { broadcastTx } from "./bridge/bridgeHelpers/api";
|
|
4
|
+
import { Transaction } from "./types";
|
|
5
|
+
|
|
6
|
+
const broadcast: AccountBridge<Transaction>["broadcast"] = async ({
|
|
7
|
+
signedOperation: { signature, operation },
|
|
8
|
+
}) => {
|
|
9
|
+
const hash = await broadcastTx(signature);
|
|
10
|
+
return patchOperationWithHash(operation, hash);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default broadcast;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import flatMap from "lodash/flatMap";
|
|
3
|
+
|
|
4
|
+
import type { AccountLike } from "@ledgerhq/types-live";
|
|
5
|
+
import { Transaction } from "./types";
|
|
6
|
+
|
|
7
|
+
function inferTransactions(
|
|
8
|
+
transactions: Array<{
|
|
9
|
+
account: AccountLike;
|
|
10
|
+
transaction: Transaction;
|
|
11
|
+
}>,
|
|
12
|
+
opts: Record<string, string>,
|
|
13
|
+
): Transaction[] {
|
|
14
|
+
return flatMap(transactions, ({ transaction }) => {
|
|
15
|
+
invariant(transaction.family === "ton", "ton family");
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
...transaction,
|
|
19
|
+
family: "ton",
|
|
20
|
+
mode: opts.mode || "send",
|
|
21
|
+
} as Transaction;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function makeCliTools() {
|
|
26
|
+
return {
|
|
27
|
+
options: [],
|
|
28
|
+
inferTransactions,
|
|
29
|
+
};
|
|
30
|
+
}
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CurrencyConfig } from "@ledgerhq/coin-framework/config";
|
|
2
|
+
|
|
3
|
+
export type TonCoinConfig = () => CurrencyConfig & {
|
|
4
|
+
infra: {
|
|
5
|
+
API_TON_ENDPOINT: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
let coinConfig: TonCoinConfig | undefined;
|
|
10
|
+
|
|
11
|
+
export const setCoinConfig = (config: TonCoinConfig): void => {
|
|
12
|
+
coinConfig = config;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const getCoinConfig = (): ReturnType<TonCoinConfig> => {
|
|
16
|
+
if (!coinConfig?.()) {
|
|
17
|
+
throw new Error("Ton module config not set");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return coinConfig();
|
|
21
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import type { Transaction } from "./types";
|
|
4
|
+
|
|
5
|
+
const createTransaction: AccountBridge<Transaction>["createTransaction"] = (): Transaction => ({
|
|
6
|
+
family: "ton",
|
|
7
|
+
amount: new BigNumber(0),
|
|
8
|
+
fees: new BigNumber(0),
|
|
9
|
+
recipient: "",
|
|
10
|
+
useAllAmount: false,
|
|
11
|
+
comment: {
|
|
12
|
+
isEncrypted: false,
|
|
13
|
+
text: "",
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export default createTransaction;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CommonDeviceTransactionField as DeviceTransactionField } from "@ledgerhq/coin-framework/transaction/common";
|
|
2
|
+
import type { Account, AccountLike } from "@ledgerhq/types-live";
|
|
3
|
+
import type { Transaction, TransactionStatus } from "./types";
|
|
4
|
+
|
|
5
|
+
function getDeviceTransactionConfig(input: {
|
|
6
|
+
account: AccountLike;
|
|
7
|
+
parentAccount: Account | null | undefined;
|
|
8
|
+
transaction: Transaction;
|
|
9
|
+
status: TransactionStatus;
|
|
10
|
+
}): Array<DeviceTransactionField> {
|
|
11
|
+
const fields: Array<DeviceTransactionField> = [];
|
|
12
|
+
|
|
13
|
+
fields.push({
|
|
14
|
+
type: "address",
|
|
15
|
+
label: "To",
|
|
16
|
+
address: input.transaction.recipient,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
if (input.transaction.useAllAmount) {
|
|
20
|
+
fields.push({
|
|
21
|
+
type: "text",
|
|
22
|
+
label: "Amount",
|
|
23
|
+
value: "ALL YOUR TONs",
|
|
24
|
+
});
|
|
25
|
+
} else {
|
|
26
|
+
fields.push({
|
|
27
|
+
type: "amount",
|
|
28
|
+
label: "Amount",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fields.push({
|
|
33
|
+
type: "fees",
|
|
34
|
+
label: "Fee",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!input.transaction.comment.isEncrypted && input.transaction.comment.text) {
|
|
38
|
+
fields.push({
|
|
39
|
+
type: "text",
|
|
40
|
+
label: "Comment",
|
|
41
|
+
value: input.transaction.comment.text,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return fields;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default getDeviceTransactionConfig;
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getMainAccount } from "@ledgerhq/coin-framework/account/index";
|
|
2
|
+
import type { Account, AccountBridge, AccountLike } from "@ledgerhq/types-live";
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
import { fetchAccountInfo } from "./bridge/bridgeHelpers/api";
|
|
5
|
+
import type { Transaction } from "./types";
|
|
6
|
+
import { buildTonTransaction, getTonEstimatedFees } from "./utils";
|
|
7
|
+
|
|
8
|
+
const estimateMaxSpendable: AccountBridge<Transaction, Account>["estimateMaxSpendable"] = async ({
|
|
9
|
+
account,
|
|
10
|
+
parentAccount,
|
|
11
|
+
transaction,
|
|
12
|
+
}: {
|
|
13
|
+
account: AccountLike;
|
|
14
|
+
parentAccount?: Account | null | undefined;
|
|
15
|
+
transaction?: Transaction | null | undefined;
|
|
16
|
+
}): Promise<BigNumber> => {
|
|
17
|
+
const mainAccount = getMainAccount(account, parentAccount);
|
|
18
|
+
let balance = mainAccount.spendableBalance;
|
|
19
|
+
|
|
20
|
+
if (balance.eq(0)) return balance;
|
|
21
|
+
|
|
22
|
+
const accountInfo = await fetchAccountInfo(mainAccount.freshAddress);
|
|
23
|
+
|
|
24
|
+
const estimatedFees = transaction
|
|
25
|
+
? transaction.fees ??
|
|
26
|
+
(await getTonEstimatedFees(
|
|
27
|
+
mainAccount,
|
|
28
|
+
accountInfo.status === "uninit",
|
|
29
|
+
buildTonTransaction(transaction, accountInfo.seqno),
|
|
30
|
+
))
|
|
31
|
+
: BigNumber(0);
|
|
32
|
+
|
|
33
|
+
if (balance.lte(estimatedFees)) return new BigNumber(0);
|
|
34
|
+
|
|
35
|
+
balance = balance.minus(estimatedFees);
|
|
36
|
+
|
|
37
|
+
return balance;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default estimateMaxSpendable;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AmountRequired,
|
|
3
|
+
InvalidAddress,
|
|
4
|
+
InvalidAddressBecauseDestinationIsAlsoSource,
|
|
5
|
+
NotEnoughBalance,
|
|
6
|
+
RecipientRequired,
|
|
7
|
+
} from "@ledgerhq/errors";
|
|
8
|
+
import { Account, AccountBridge, SubAccount } from "@ledgerhq/types-live";
|
|
9
|
+
import BigNumber from "bignumber.js";
|
|
10
|
+
import { TonCommentInvalid } from "./errors";
|
|
11
|
+
import { Transaction, TransactionStatus } from "./types";
|
|
12
|
+
import { addressesAreEqual, commentIsValid, isAddressValid } from "./utils";
|
|
13
|
+
|
|
14
|
+
type ValidatedTransactionFields = "recipient" | "sender" | "amount" | "transaction";
|
|
15
|
+
type ValidationIssues = Partial<Record<ValidatedTransactionFields, Error>>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Validate an address for account transaction
|
|
19
|
+
*/
|
|
20
|
+
const validateRecipient = (account: Account, tx: Transaction): Array<ValidationIssues> => {
|
|
21
|
+
const errors: ValidationIssues = {};
|
|
22
|
+
|
|
23
|
+
if (tx.recipient) {
|
|
24
|
+
// Check if recipient is matching the format of account valid eth address or not
|
|
25
|
+
const isRecipientValidate = isAddressValid(tx.recipient);
|
|
26
|
+
|
|
27
|
+
if (!isRecipientValidate) {
|
|
28
|
+
errors.recipient = new InvalidAddress("", {
|
|
29
|
+
currencyName: account.currency.name,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (addressesAreEqual(account.freshAddress, tx.recipient)) {
|
|
33
|
+
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource("", {
|
|
34
|
+
currencyName: account.currency.name,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
errors.recipient = new RecipientRequired(); // ""
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return [errors];
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Validate the sender address for account transaction
|
|
46
|
+
*/
|
|
47
|
+
const validateSender = (account: Account): Array<ValidationIssues> => {
|
|
48
|
+
const errors: ValidationIssues = {};
|
|
49
|
+
|
|
50
|
+
// Check if sender is matching the format of account valid ton address or not
|
|
51
|
+
const isSenderValidate = isAddressValid(account.freshAddress);
|
|
52
|
+
|
|
53
|
+
if (!isSenderValidate) {
|
|
54
|
+
errors.sender = new InvalidAddress("", {
|
|
55
|
+
currencyName: account.currency.name,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return [errors];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const validateAmount = (
|
|
63
|
+
account: Account | SubAccount,
|
|
64
|
+
transaction: Transaction,
|
|
65
|
+
totalSpent: BigNumber,
|
|
66
|
+
): Array<ValidationIssues> => {
|
|
67
|
+
const errors: ValidationIssues = {};
|
|
68
|
+
const warnings: ValidationIssues = {};
|
|
69
|
+
|
|
70
|
+
// if no amount or 0
|
|
71
|
+
if (!transaction.amount || transaction.amount.isZero()) {
|
|
72
|
+
errors.amount = new AmountRequired(); // "Amount required"
|
|
73
|
+
} else if (totalSpent.isGreaterThan(account.balance)) {
|
|
74
|
+
// if not enough to make the transaction
|
|
75
|
+
errors.amount = new NotEnoughBalance(); // "Sorry, insufficient funds"
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return [errors, warnings];
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const validateComment = (transaction: Transaction): Array<ValidationIssues> => {
|
|
82
|
+
const errors: ValidationIssues = {};
|
|
83
|
+
|
|
84
|
+
// if the comment isn'transaction encrypted, it should be valid
|
|
85
|
+
if (transaction.comment.isEncrypted || !commentIsValid(transaction.comment)) {
|
|
86
|
+
errors.transaction = new TonCommentInvalid();
|
|
87
|
+
}
|
|
88
|
+
return [errors];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const getTransactionStatus: AccountBridge<
|
|
92
|
+
Transaction,
|
|
93
|
+
Account,
|
|
94
|
+
TransactionStatus
|
|
95
|
+
>["getTransactionStatus"] = async (
|
|
96
|
+
account: Account,
|
|
97
|
+
transaction: Transaction,
|
|
98
|
+
): Promise<TransactionStatus> => {
|
|
99
|
+
const totalSpent = transaction.amount.plus(transaction.fees);
|
|
100
|
+
|
|
101
|
+
// Recipient related errors and warnings
|
|
102
|
+
const [recipientErr] = validateRecipient(account, transaction);
|
|
103
|
+
// Sender related errors and warnings
|
|
104
|
+
const [senderErr] = validateSender(account);
|
|
105
|
+
// Amount related errors and warnings
|
|
106
|
+
const [amountErr, amountWarn] = validateAmount(account, transaction, totalSpent);
|
|
107
|
+
// Transaction related errors and warnings
|
|
108
|
+
const [transactionErr] = validateComment(transaction);
|
|
109
|
+
|
|
110
|
+
const errors: ValidationIssues = {
|
|
111
|
+
...recipientErr,
|
|
112
|
+
...senderErr,
|
|
113
|
+
...amountErr,
|
|
114
|
+
...transactionErr,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const warnings: ValidationIssues = {
|
|
118
|
+
...amountWarn,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
amount: transaction.amount,
|
|
123
|
+
errors,
|
|
124
|
+
warnings,
|
|
125
|
+
estimatedFees: transaction.fees,
|
|
126
|
+
totalSpent,
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export default getTransactionStatus;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { GetAddressFn } from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import { GetAddressOptions } from "@ledgerhq/coin-framework/derivation";
|
|
3
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
4
|
+
import { TonSigner } from "./signer";
|
|
5
|
+
import { getLedgerTonPath } from "./utils";
|
|
6
|
+
|
|
7
|
+
const resolver = (signerContext: SignerContext<TonSigner>): GetAddressFn => {
|
|
8
|
+
return async (deviceId: string, { path, verify }: GetAddressOptions) => {
|
|
9
|
+
const ledgerPath = getLedgerTonPath(path);
|
|
10
|
+
|
|
11
|
+
const sig = await signerContext(deviceId, async signer => {
|
|
12
|
+
return verify
|
|
13
|
+
? await signer.validateAddress(ledgerPath, { bounceable: false })
|
|
14
|
+
: await signer.getAddress(ledgerPath, { bounceable: false });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
if (!sig.address || !sig.publicKey.length)
|
|
18
|
+
throw Error(`[ton] Response is empty ${sig.address} ${sig.publicKey}`);
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
address: sig.address,
|
|
22
|
+
publicKey: sig.publicKey.toString("hex"),
|
|
23
|
+
path,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export default resolver;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
2
|
+
import { Account, AnyMessage } from "@ledgerhq/types-live";
|
|
3
|
+
import { TonSigner } from "./signer";
|
|
4
|
+
import { TonTransaction } from "./types";
|
|
5
|
+
import { getLedgerTonPath } from "./utils";
|
|
6
|
+
|
|
7
|
+
export const signMessage =
|
|
8
|
+
(signerContext: SignerContext<TonSigner>) =>
|
|
9
|
+
async (deviceId: string, account: Account, { message }: AnyMessage) => {
|
|
10
|
+
if (typeof message !== "string") throw new Error("Invalid message value");
|
|
11
|
+
|
|
12
|
+
const parsedMessage = JSON.parse(message);
|
|
13
|
+
const ledgerPath = getLedgerTonPath(account.freshAddressPath);
|
|
14
|
+
|
|
15
|
+
const sig = await signerContext(deviceId, signer =>
|
|
16
|
+
signer.signTransaction(ledgerPath, parsedMessage as TonTransaction),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
if (!sig) {
|
|
20
|
+
throw new Error("No signature");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
rsv: {
|
|
25
|
+
r: "",
|
|
26
|
+
s: "",
|
|
27
|
+
v: 0,
|
|
28
|
+
},
|
|
29
|
+
signature: sig.toString(),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defaultUpdateTransaction } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
2
|
+
import { Account, AccountBridge } from "@ledgerhq/types-live";
|
|
3
|
+
import { fetchAccountInfo } from "./bridge/bridgeHelpers/api";
|
|
4
|
+
import type { Transaction } from "./types";
|
|
5
|
+
import { buildTonTransaction, getTonEstimatedFees } from "./utils";
|
|
6
|
+
|
|
7
|
+
const prepareTransaction: AccountBridge<Transaction, Account>["prepareTransaction"] = async (
|
|
8
|
+
account: Account,
|
|
9
|
+
transaction: Transaction,
|
|
10
|
+
): Promise<Transaction> => {
|
|
11
|
+
const accountInfo = await fetchAccountInfo(account.freshAddress);
|
|
12
|
+
|
|
13
|
+
const simpleTx = buildTonTransaction(transaction, accountInfo.seqno);
|
|
14
|
+
|
|
15
|
+
const fees = await getTonEstimatedFees(account, accountInfo.status === "uninit", simpleTx);
|
|
16
|
+
|
|
17
|
+
let amount;
|
|
18
|
+
if (transaction.useAllAmount) {
|
|
19
|
+
amount = account.spendableBalance.minus(fees);
|
|
20
|
+
} else {
|
|
21
|
+
amount = transaction.amount;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return defaultUpdateTransaction(transaction, { fees, amount });
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default prepareTransaction;
|