@ledgerhq/live-common 24.1.0 → 25.0.0-next.1
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/lib/apps/support.js +1 -1
- package/lib/apps/support.js.map +1 -1
- package/lib/bot/index.d.ts.map +1 -1
- package/lib/bot/index.js +4 -2
- package/lib/bot/index.js.map +1 -1
- package/lib/bot/specs.d.ts +1 -0
- package/lib/bot/specs.d.ts.map +1 -1
- package/lib/bot/specs.js +6 -1
- package/lib/bot/specs.js.map +1 -1
- package/lib/currencies/support.d.ts +1 -1
- package/lib/currencies/support.d.ts.map +1 -1
- package/lib/env.d.ts +15 -5
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +10 -0
- package/lib/env.js.map +1 -1
- package/lib/env.react.d.ts +1 -1
- package/lib/env.react.d.ts.map +1 -1
- package/lib/errors.d.ts +101 -306
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +3 -4
- package/lib/errors.js.map +1 -1
- package/lib/errors.test.d.ts +2 -0
- package/lib/errors.test.d.ts.map +1 -0
- package/lib/errors.test.js +20 -0
- package/lib/errors.test.js.map +1 -0
- package/lib/exchange/swap/utils/index.test.js +2 -2
- package/lib/exchange/swap/utils/index.test.js.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.d.ts.map +1 -1
- package/lib/families/bitcoin/datasets/bitcoin.js +2 -4
- package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
- package/lib/families/bitcoin/descriptor.d.ts.map +1 -1
- package/lib/families/bitcoin/descriptor.js +3 -1
- package/lib/families/bitcoin/descriptor.js.map +1 -1
- package/lib/families/bitcoin/errors.d.ts +1 -3
- package/lib/families/bitcoin/errors.d.ts.map +1 -1
- package/lib/families/bitcoin/exchange.js +1 -1
- package/lib/families/bitcoin/exchange.js.map +1 -1
- package/lib/families/bitcoin/hw-getAddress.d.ts +1 -1
- package/lib/families/bitcoin/hw-getAddress.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
- package/lib/families/bitcoin/js-synchronisation.js +20 -2
- package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/index.d.ts +0 -36
- package/lib/families/bitcoin/wallet-btc/storage/index.d.ts.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/index.js +14 -14
- package/lib/families/bitcoin/wallet-btc/storage/index.js.map +1 -1
- package/lib/families/bitcoin/wallet-btc/storage/types.d.ts +1 -0
- package/lib/families/bitcoin/wallet-btc/storage/types.d.ts.map +1 -1
- package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.d.ts +2 -0
- package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.d.ts.map +1 -0
- package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.js +146 -0
- package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.js.map +1 -0
- package/lib/families/cardano/errors.d.ts +1 -3
- package/lib/families/cardano/errors.d.ts.map +1 -1
- package/lib/families/crypto_org/errors.d.ts +3 -9
- package/lib/families/crypto_org/errors.d.ts.map +1 -1
- package/lib/families/ethereum/exchange.js +1 -1
- package/lib/families/ethereum/exchange.js.map +1 -1
- package/lib/families/ethereum/modules/index.d.ts +1 -1
- package/lib/families/ethereum/modules/index.d.ts.map +1 -1
- package/lib/families/ethereum/signOperation.js +2 -2
- package/lib/families/ethereum/signOperation.js.map +1 -1
- package/lib/families/ethereum/specs.d.ts +1 -1
- package/lib/families/ethereum/specs.js +5 -5
- package/lib/families/ethereum/specs.js.map +1 -1
- package/lib/families/polkadot/errors.d.ts +12 -36
- package/lib/families/polkadot/errors.d.ts.map +1 -1
- package/lib/families/ripple/exchange.js +1 -1
- package/lib/families/ripple/exchange.js.map +1 -1
- package/lib/families/solana/api/chain/instruction/token/types.d.ts +3 -3
- package/lib/families/solana/errors.d.ts +20 -60
- package/lib/families/solana/errors.d.ts.map +1 -1
- package/lib/families/stellar/api/horizon.d.ts +29 -7
- package/lib/families/stellar/api/horizon.d.ts.map +1 -1
- package/lib/families/stellar/api/horizon.js +114 -58
- package/lib/families/stellar/api/horizon.js.map +1 -1
- package/lib/families/stellar/api/index.d.ts +1 -1
- package/lib/families/stellar/api/index.d.ts.map +1 -1
- package/lib/families/stellar/api/index.js +5 -1
- package/lib/families/stellar/api/index.js.map +1 -1
- package/lib/families/stellar/bridge/mock.d.ts.map +1 -1
- package/lib/families/stellar/bridge/mock.js +4 -1
- package/lib/families/stellar/bridge/mock.js.map +1 -1
- package/lib/families/stellar/bridge.integration.test.js +12 -4
- package/lib/families/stellar/bridge.integration.test.js.map +1 -1
- package/lib/families/stellar/cli-transaction.d.ts +3 -1
- package/lib/families/stellar/cli-transaction.d.ts.map +1 -1
- package/lib/families/stellar/cli-transaction.js +48 -2
- package/lib/families/stellar/cli-transaction.js.map +1 -1
- package/lib/families/stellar/deviceTransactionConfig.d.ts +7 -1
- package/lib/families/stellar/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/families/stellar/deviceTransactionConfig.js +12 -1
- package/lib/families/stellar/deviceTransactionConfig.js.map +1 -1
- package/lib/families/stellar/errors.d.ts +12 -0
- package/lib/families/stellar/errors.d.ts.map +1 -0
- package/lib/families/stellar/errors.js +16 -0
- package/lib/families/stellar/errors.js.map +1 -0
- package/lib/families/stellar/exchange.js +1 -1
- package/lib/families/stellar/exchange.js.map +1 -1
- package/lib/families/stellar/js-buildTransaction.d.ts.map +1 -1
- package/lib/families/stellar/js-buildTransaction.js +34 -16
- package/lib/families/stellar/js-buildTransaction.js.map +1 -1
- package/lib/families/stellar/js-createTransaction.d.ts.map +1 -1
- package/lib/families/stellar/js-createTransaction.js +4 -1
- package/lib/families/stellar/js-createTransaction.js.map +1 -1
- package/lib/families/stellar/js-estimateMaxSpendable.js +2 -1
- package/lib/families/stellar/js-estimateMaxSpendable.js.map +1 -1
- package/lib/families/stellar/js-getTransactionStatus.d.ts.map +1 -1
- package/lib/families/stellar/js-getTransactionStatus.js +127 -57
- package/lib/families/stellar/js-getTransactionStatus.js.map +1 -1
- package/lib/families/stellar/js-prepareTransaction.d.ts.map +1 -1
- package/lib/families/stellar/js-prepareTransaction.js +25 -7
- package/lib/families/stellar/js-prepareTransaction.js.map +1 -1
- package/lib/families/stellar/js-signOperation.d.ts.map +1 -1
- package/lib/families/stellar/js-signOperation.js +33 -6
- package/lib/families/stellar/js-signOperation.js.map +1 -1
- package/lib/families/stellar/js-synchronization.d.ts +1 -1
- package/lib/families/stellar/js-synchronization.d.ts.map +1 -1
- package/lib/families/stellar/js-synchronization.js +42 -16
- package/lib/families/stellar/js-synchronization.js.map +1 -1
- package/lib/families/stellar/logic.d.ts +21 -14
- package/lib/families/stellar/logic.d.ts.map +1 -1
- package/lib/families/stellar/logic.js +158 -57
- package/lib/families/stellar/logic.js.map +1 -1
- package/lib/families/stellar/specs.d.ts.map +1 -1
- package/lib/families/stellar/specs.js +182 -7
- package/lib/families/stellar/specs.js.map +1 -1
- package/lib/families/stellar/speculos-deviceActions.d.ts.map +1 -1
- package/lib/families/stellar/speculos-deviceActions.js +60 -28
- package/lib/families/stellar/speculos-deviceActions.js.map +1 -1
- package/lib/families/stellar/tokens.d.ts +11 -0
- package/lib/families/stellar/tokens.d.ts.map +1 -0
- package/lib/families/stellar/tokens.js +82 -0
- package/lib/families/stellar/tokens.js.map +1 -0
- package/lib/families/stellar/transaction.d.ts +2 -2
- package/lib/families/stellar/transaction.d.ts.map +1 -1
- package/lib/families/stellar/transaction.js +32 -6
- package/lib/families/stellar/transaction.js.map +1 -1
- package/lib/families/stellar/types.d.ts +45 -0
- package/lib/families/stellar/types.d.ts.map +1 -1
- package/lib/families/stellar/types.js +7 -1
- package/lib/families/stellar/types.js.map +1 -1
- package/lib/families/tezos/exchange.js +1 -1
- package/lib/families/tezos/exchange.js.map +1 -1
- package/lib/generated/cli-transaction.d.ts +1 -0
- package/lib/generated/cli-transaction.d.ts.map +1 -1
- package/lib/generated/specs.d.ts +1 -1
- package/lib/generated/transaction.d.ts +1 -1
- package/lib/hw/signMessage/index.d.ts +4 -3
- package/lib/hw/signMessage/index.d.ts.map +1 -1
- package/lib/hw/signMessage/index.js +25 -11
- package/lib/hw/signMessage/index.js.map +1 -1
- package/lib/hw/signMessage/index.test.d.ts +2 -0
- package/lib/hw/signMessage/index.test.d.ts.map +1 -0
- package/lib/hw/signMessage/index.test.js +126 -0
- package/lib/hw/signMessage/index.test.js.map +1 -0
- package/lib/load/speculos.d.ts.map +1 -1
- package/lib/load/speculos.js +1 -3
- package/lib/load/speculos.js.map +1 -1
- package/lib/mock/Btc.d.ts +1 -1
- package/lib/mock/Btc.d.ts.map +1 -1
- package/lib/performance.d.ts +10 -0
- package/lib/performance.d.ts.map +1 -0
- package/lib/performance.js +72 -0
- package/lib/performance.js.map +1 -0
- package/lib/performance.test.d.ts +2 -0
- package/lib/performance.test.d.ts.map +1 -0
- package/lib/performance.test.js +28 -0
- package/lib/performance.test.js.map +1 -0
- package/lib/platform/providers/RemoteLiveAppProvider/api/index.d.ts.map +1 -1
- package/lib/platform/providers/RemoteLiveAppProvider/api/index.js +28 -0
- package/lib/platform/providers/RemoteLiveAppProvider/api/index.js.map +1 -1
- package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +0 -31
- package/lib/types/currencies.d.ts +1 -1
- package/lib/types/currencies.d.ts.map +1 -1
- package/lib/walletconnect/Provider.d.ts.map +1 -1
- package/lib/walletconnect/Provider.js +1 -3
- package/lib/walletconnect/Provider.js.map +1 -1
- package/package.json +71 -19
- package/src/apps/support.ts +1 -1
- package/src/bot/index.ts +3 -1
- package/src/bot/specs.ts +7 -1
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +34 -6
- package/src/currencies/support.ts +1 -1
- package/src/env.ts +10 -0
- package/src/errors.test.ts +21 -0
- package/src/errors.ts +1 -6
- package/src/exchange/swap/utils/index.test.ts +1 -1
- package/src/families/bitcoin/datasets/bitcoin.ts +0 -2
- package/src/families/bitcoin/descriptor.ts +4 -1
- package/src/families/bitcoin/exchange.ts +1 -1
- package/src/families/bitcoin/hw-getAddress.ts +1 -1
- package/src/families/bitcoin/js-synchronisation.ts +23 -1
- package/src/families/bitcoin/wallet-btc/storage/index.ts +17 -31
- package/src/families/bitcoin/wallet-btc/storage/types.ts +1 -0
- package/src/families/bitcoin/wallet-btc/wallet.ts +1 -1
- package/src/families/bitcoin/xpub.txs.loadExport.unit.test.ts +101 -0
- package/src/families/ethereum/exchange.ts +1 -1
- package/src/families/ethereum/modules/index.ts +1 -1
- package/src/families/ethereum/signOperation.ts +2 -2
- package/src/families/ethereum/specs.ts +5 -5
- package/src/families/ripple/exchange.ts +1 -1
- package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +765 -339
- package/src/families/stellar/api/horizon.ts +115 -33
- package/src/families/stellar/api/index.ts +4 -0
- package/src/families/stellar/bridge/mock.ts +3 -0
- package/src/families/stellar/bridge.integration.test.ts +10 -2
- package/src/families/stellar/cli-transaction.ts +75 -2
- package/src/families/stellar/deviceTransactionConfig.ts +22 -0
- package/src/families/stellar/errors.ts +34 -0
- package/src/families/stellar/exchange.ts +1 -1
- package/src/families/stellar/js-buildTransaction.ts +56 -16
- package/src/families/stellar/js-createTransaction.ts +3 -0
- package/src/families/stellar/js-estimateMaxSpendable.ts +1 -1
- package/src/families/stellar/js-getTransactionStatus.ts +152 -60
- package/src/families/stellar/js-prepareTransaction.ts +4 -3
- package/src/families/stellar/js-signOperation.ts +37 -6
- package/src/families/stellar/js-synchronization.ts +53 -11
- package/src/families/stellar/logic.ts +198 -62
- package/src/families/stellar/specs.ts +227 -8
- package/src/families/stellar/speculos-deviceActions.ts +66 -22
- package/src/families/stellar/tokens.ts +118 -0
- package/src/families/stellar/transaction.ts +31 -3
- package/src/families/stellar/types.ts +52 -0
- package/src/families/tezos/exchange.ts +1 -1
- package/src/hw/signMessage/index.test.ts +128 -0
- package/src/hw/signMessage/index.ts +37 -15
- package/src/load/speculos.ts +1 -3
- package/src/mock/Btc.ts +1 -1
- package/src/performance.test.ts +26 -0
- package/src/performance.ts +61 -0
- package/src/platform/providers/RemoteLiveAppProvider/api/index.ts +6 -0
- package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +1 -32
- package/src/types/currencies.ts +1 -1
- package/src/walletconnect/Provider.tsx +4 -5
|
@@ -3,26 +3,44 @@ import type { Transaction } from "./types";
|
|
|
3
3
|
import { formatCurrencyUnit } from "../../currencies";
|
|
4
4
|
import { deviceActionFlow } from "../../bot/specs";
|
|
5
5
|
|
|
6
|
-
const expectedAmount = ({ account, status }) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
const expectedAmount = ({ account, status, transaction }) => {
|
|
7
|
+
if (transaction.assetCode && transaction.assetIssuer) {
|
|
8
|
+
const amount = formatCurrencyUnit(account.unit, status.amount, {
|
|
9
|
+
disableRounding: true,
|
|
10
|
+
useGrouping: false,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return `${amount} ${transaction.assetCode}@${truncateAddress(
|
|
14
|
+
transaction.assetIssuer,
|
|
15
|
+
3,
|
|
16
|
+
4
|
|
17
|
+
)}`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
formatCurrencyUnit(account.unit, status.amount, {
|
|
22
|
+
disableRounding: true,
|
|
23
|
+
useGrouping: false,
|
|
24
|
+
}) + " XLM"
|
|
25
|
+
);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const truncateAddress = (stellarAddress: string, start = 6, end = 6) =>
|
|
29
|
+
`${stellarAddress.slice(0, start)}..${stellarAddress.slice(-end)}`;
|
|
11
30
|
|
|
12
31
|
const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
13
32
|
steps: [
|
|
14
33
|
{
|
|
15
|
-
title: "
|
|
34
|
+
title: "Review",
|
|
16
35
|
button: "Rr",
|
|
17
|
-
expectedValue: expectedAmount,
|
|
18
36
|
},
|
|
19
37
|
{
|
|
20
|
-
title: "
|
|
38
|
+
title: "Memo Text",
|
|
21
39
|
button: "Rr",
|
|
22
|
-
expectedValue:
|
|
40
|
+
expectedValue: ({ transaction }) => transaction.memoValue || "",
|
|
23
41
|
},
|
|
24
42
|
{
|
|
25
|
-
title: "Fee",
|
|
43
|
+
title: "Max Fee",
|
|
26
44
|
button: "Rr",
|
|
27
45
|
expectedValue: ({ account, status }) =>
|
|
28
46
|
formatCurrencyUnit(account.unit, status.estimatedFees, {
|
|
@@ -30,42 +48,68 @@ const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
|
30
48
|
}) + " XLM",
|
|
31
49
|
},
|
|
32
50
|
{
|
|
33
|
-
title: "
|
|
51
|
+
title: "Sequence Num",
|
|
34
52
|
button: "Rr",
|
|
35
|
-
expectedValue: ({ transaction }) => transaction.recipient,
|
|
36
53
|
},
|
|
37
54
|
{
|
|
38
|
-
title: "
|
|
55
|
+
title: "Tx Source",
|
|
39
56
|
button: "Rr",
|
|
40
|
-
expectedValue: ({
|
|
57
|
+
expectedValue: ({ account }) => truncateAddress(account.freshAddress),
|
|
41
58
|
},
|
|
42
59
|
{
|
|
43
|
-
title: "
|
|
60
|
+
title: "Operation Type",
|
|
44
61
|
button: "Rr",
|
|
45
|
-
|
|
62
|
+
// Operation type can be Payment (or Create Account) or Change Trust.
|
|
63
|
+
// Create Account type is coming from operation, not transaction.
|
|
64
|
+
// Testing in `specs.ts`.
|
|
46
65
|
},
|
|
47
66
|
{
|
|
48
|
-
title: "
|
|
67
|
+
title: "Change Trust",
|
|
49
68
|
button: "Rr",
|
|
50
|
-
expectedValue: () =>
|
|
69
|
+
expectedValue: ({ transaction }) =>
|
|
70
|
+
`${transaction.assetCode || ""}@${truncateAddress(
|
|
71
|
+
transaction.assetIssuer || "",
|
|
72
|
+
3,
|
|
73
|
+
4
|
|
74
|
+
)}`,
|
|
75
|
+
maxY: 5,
|
|
51
76
|
},
|
|
52
77
|
{
|
|
53
|
-
title: "
|
|
78
|
+
title: "Create Account",
|
|
54
79
|
button: "Rr",
|
|
80
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
81
|
+
maxY: 5,
|
|
55
82
|
},
|
|
56
83
|
{
|
|
57
|
-
title: "
|
|
84
|
+
title: "Send",
|
|
58
85
|
button: "Rr",
|
|
59
|
-
expectedValue:
|
|
86
|
+
expectedValue: expectedAmount,
|
|
60
87
|
},
|
|
61
88
|
{
|
|
62
|
-
title: "
|
|
89
|
+
title: "Destination",
|
|
63
90
|
button: "Rr",
|
|
91
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
64
92
|
},
|
|
65
93
|
{
|
|
66
94
|
title: "Finalize",
|
|
67
95
|
button: "LRlr",
|
|
68
96
|
},
|
|
97
|
+
{
|
|
98
|
+
title: "Starting Balance",
|
|
99
|
+
button: "Rr",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
title: "Network",
|
|
103
|
+
button: "Rr",
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
title: "Valid Before (UTC)",
|
|
107
|
+
button: "Rr",
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
title: "Valid After (UTC)",
|
|
111
|
+
button: "Rr",
|
|
112
|
+
},
|
|
69
113
|
],
|
|
70
114
|
});
|
|
71
115
|
export default {
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { emptyHistoryCache } from "../../account";
|
|
3
|
+
import {
|
|
4
|
+
listTokensForCryptoCurrency,
|
|
5
|
+
findTokenById,
|
|
6
|
+
parseCurrencyUnit,
|
|
7
|
+
} from "../../currencies";
|
|
8
|
+
import type {
|
|
9
|
+
TokenAccount,
|
|
10
|
+
TokenCurrency,
|
|
11
|
+
Operation,
|
|
12
|
+
CryptoCurrency,
|
|
13
|
+
SyncConfig,
|
|
14
|
+
} from "../../types";
|
|
15
|
+
import type { BalanceAsset } from "./types";
|
|
16
|
+
import { encodeOperationId } from "../../operation";
|
|
17
|
+
|
|
18
|
+
export const getAssetIdFromTokenId = (tokenId: string): string =>
|
|
19
|
+
tokenId.split("/")[2];
|
|
20
|
+
|
|
21
|
+
const getAssetIdFromAsset = (asset: BalanceAsset) =>
|
|
22
|
+
`${asset.asset_code}:${asset.asset_issuer}`;
|
|
23
|
+
|
|
24
|
+
const buildStellarTokenAccount = ({
|
|
25
|
+
parentAccountId,
|
|
26
|
+
stellarAsset,
|
|
27
|
+
token,
|
|
28
|
+
operations,
|
|
29
|
+
}: {
|
|
30
|
+
parentAccountId: string;
|
|
31
|
+
stellarAsset: BalanceAsset;
|
|
32
|
+
token: TokenCurrency;
|
|
33
|
+
operations: Operation[];
|
|
34
|
+
}): TokenAccount => {
|
|
35
|
+
const assetId = getAssetIdFromTokenId(token.id);
|
|
36
|
+
const id = `${parentAccountId}+${assetId}`;
|
|
37
|
+
const balance = parseCurrencyUnit(
|
|
38
|
+
token.units[0],
|
|
39
|
+
stellarAsset.balance || "0"
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const reservedBalance = new BigNumber(stellarAsset.balance).minus(
|
|
43
|
+
stellarAsset.buying_liabilities || 0
|
|
44
|
+
);
|
|
45
|
+
const spendableBalance = parseCurrencyUnit(
|
|
46
|
+
token.units[0],
|
|
47
|
+
reservedBalance.toString()
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
type: "TokenAccount",
|
|
52
|
+
id,
|
|
53
|
+
parentId: parentAccountId,
|
|
54
|
+
starred: false,
|
|
55
|
+
token,
|
|
56
|
+
operationsCount: operations.length,
|
|
57
|
+
operations: operations.map((op) => ({
|
|
58
|
+
...op,
|
|
59
|
+
id: encodeOperationId(id, op.hash, op.extra.ledgerOpType),
|
|
60
|
+
accountId: id,
|
|
61
|
+
type: op.extra.ledgerOpType,
|
|
62
|
+
value: new BigNumber(op.extra.assetAmount) ?? op.value,
|
|
63
|
+
})),
|
|
64
|
+
pendingOperations: [],
|
|
65
|
+
balance,
|
|
66
|
+
spendableBalance,
|
|
67
|
+
swapHistory: [],
|
|
68
|
+
creationDate:
|
|
69
|
+
operations.length > 0
|
|
70
|
+
? operations[operations.length - 1].date
|
|
71
|
+
: new Date(),
|
|
72
|
+
balanceHistoryCache: emptyHistoryCache, // calculated in the jsHelpers
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const buildSubAccounts = ({
|
|
77
|
+
currency,
|
|
78
|
+
accountId,
|
|
79
|
+
assets,
|
|
80
|
+
syncConfig,
|
|
81
|
+
operations,
|
|
82
|
+
}: {
|
|
83
|
+
currency: CryptoCurrency;
|
|
84
|
+
accountId: string;
|
|
85
|
+
assets: BalanceAsset[];
|
|
86
|
+
syncConfig: SyncConfig;
|
|
87
|
+
operations: Operation[];
|
|
88
|
+
}): TokenAccount[] | undefined => {
|
|
89
|
+
const { blacklistedTokenIds = [] } = syncConfig;
|
|
90
|
+
const allTokens = listTokensForCryptoCurrency(currency);
|
|
91
|
+
|
|
92
|
+
if (allTokens.length === 0 || assets.length === 0) {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const tokenAccounts: TokenAccount[] = [];
|
|
97
|
+
|
|
98
|
+
assets.map((asset) => {
|
|
99
|
+
const token = findTokenById(`stellar/asset/${getAssetIdFromAsset(asset)}`);
|
|
100
|
+
|
|
101
|
+
if (token && !blacklistedTokenIds.includes(token.id)) {
|
|
102
|
+
tokenAccounts.push(
|
|
103
|
+
buildStellarTokenAccount({
|
|
104
|
+
parentAccountId: accountId,
|
|
105
|
+
stellarAsset: asset,
|
|
106
|
+
token,
|
|
107
|
+
operations: operations.filter(
|
|
108
|
+
(op) =>
|
|
109
|
+
op.extra.assetCode === asset.asset_code &&
|
|
110
|
+
op.extra.assetIssuer === asset.asset_issuer
|
|
111
|
+
),
|
|
112
|
+
})
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return tokenAccounts;
|
|
118
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BigNumber } from "bignumber.js";
|
|
2
2
|
import type { Transaction, TransactionRaw } from "./types";
|
|
3
|
+
import { getAssetCodeIssuer } from "./logic";
|
|
3
4
|
import {
|
|
4
5
|
fromTransactionCommonRaw,
|
|
5
6
|
toTransactionCommonRaw,
|
|
@@ -9,9 +10,22 @@ import { getAccountUnit } from "../../account";
|
|
|
9
10
|
import { formatCurrencyUnit } from "../../currencies";
|
|
10
11
|
|
|
11
12
|
export const formatTransaction = (
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
{
|
|
14
|
+
amount,
|
|
15
|
+
recipient,
|
|
16
|
+
fees,
|
|
17
|
+
memoValue,
|
|
18
|
+
useAllAmount,
|
|
19
|
+
subAccountId,
|
|
20
|
+
}: Transaction,
|
|
21
|
+
mainAccount: Account
|
|
22
|
+
): string => {
|
|
23
|
+
const account =
|
|
24
|
+
(subAccountId &&
|
|
25
|
+
(mainAccount.subAccounts || []).find((a) => a.id === subAccountId)) ||
|
|
26
|
+
mainAccount;
|
|
27
|
+
|
|
28
|
+
return `
|
|
15
29
|
SEND ${
|
|
16
30
|
useAllAmount
|
|
17
31
|
? "MAX"
|
|
@@ -29,10 +43,13 @@ export const formatTransaction = (
|
|
|
29
43
|
disableRounding: true,
|
|
30
44
|
})
|
|
31
45
|
}${memoValue ? "\n memo=" + memoValue : ""}`;
|
|
46
|
+
};
|
|
32
47
|
|
|
33
48
|
const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
34
49
|
const common = fromTransactionCommonRaw(tr);
|
|
35
50
|
const { networkInfo } = tr;
|
|
51
|
+
const [assetCode, assetIssuer] = getAssetCodeIssuer(tr);
|
|
52
|
+
|
|
36
53
|
return {
|
|
37
54
|
...common,
|
|
38
55
|
family: tr.family,
|
|
@@ -43,14 +60,20 @@ const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
|
43
60
|
networkInfo: networkInfo && {
|
|
44
61
|
family: networkInfo.family,
|
|
45
62
|
fees: new BigNumber(networkInfo.fees),
|
|
63
|
+
baseFee: new BigNumber(networkInfo.baseFee),
|
|
46
64
|
baseReserve: new BigNumber(networkInfo.baseReserve),
|
|
65
|
+
networkCongestionLevel: networkInfo.networkCongestionLevel,
|
|
47
66
|
},
|
|
67
|
+
mode: tr.mode,
|
|
68
|
+
assetCode,
|
|
69
|
+
assetIssuer,
|
|
48
70
|
};
|
|
49
71
|
};
|
|
50
72
|
|
|
51
73
|
const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
52
74
|
const common = toTransactionCommonRaw(t);
|
|
53
75
|
const { networkInfo } = t;
|
|
76
|
+
const [assetCode, assetIssuer] = getAssetCodeIssuer(t);
|
|
54
77
|
return {
|
|
55
78
|
...common,
|
|
56
79
|
family: t.family,
|
|
@@ -61,8 +84,13 @@ const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
|
61
84
|
networkInfo: networkInfo && {
|
|
62
85
|
family: networkInfo.family,
|
|
63
86
|
fees: networkInfo.fees.toString(),
|
|
87
|
+
baseFee: networkInfo.baseFee.toString(),
|
|
64
88
|
baseReserve: networkInfo.baseReserve.toString(),
|
|
89
|
+
networkCongestionLevel: networkInfo.networkCongestionLevel,
|
|
65
90
|
},
|
|
91
|
+
mode: t.mode,
|
|
92
|
+
assetCode,
|
|
93
|
+
assetIssuer,
|
|
66
94
|
};
|
|
67
95
|
};
|
|
68
96
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ServerApi } from "stellar-sdk";
|
|
1
2
|
import type { BigNumber } from "bignumber.js";
|
|
2
3
|
import type {
|
|
3
4
|
TransactionCommon,
|
|
@@ -7,14 +8,25 @@ import type {
|
|
|
7
8
|
export type NetworkInfo = {
|
|
8
9
|
family: "stellar";
|
|
9
10
|
fees: BigNumber;
|
|
11
|
+
baseFee: BigNumber;
|
|
10
12
|
baseReserve: BigNumber;
|
|
13
|
+
networkCongestionLevel?: NetworkCongestionLevel;
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
export type NetworkInfoRaw = {
|
|
14
17
|
family: "stellar";
|
|
15
18
|
fees: string;
|
|
19
|
+
baseFee: string;
|
|
16
20
|
baseReserve: string;
|
|
21
|
+
networkCongestionLevel?: NetworkCongestionLevel;
|
|
17
22
|
};
|
|
23
|
+
|
|
24
|
+
export enum NetworkCongestionLevel {
|
|
25
|
+
LOW = "LOW",
|
|
26
|
+
MEDIUM = "MEDIUM",
|
|
27
|
+
HIGH = "HIGH",
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
export const StellarMemoType = [
|
|
19
31
|
"NO_MEMO",
|
|
20
32
|
"MEMO_TEXT",
|
|
@@ -23,6 +35,8 @@ export const StellarMemoType = [
|
|
|
23
35
|
"MEMO_RETURN",
|
|
24
36
|
];
|
|
25
37
|
|
|
38
|
+
export type StellarTransactionMode = "send" | "changeTrust";
|
|
39
|
+
|
|
26
40
|
export type Transaction = TransactionCommon & {
|
|
27
41
|
family: "stellar";
|
|
28
42
|
networkInfo: NetworkInfo | null | undefined;
|
|
@@ -30,7 +44,11 @@ export type Transaction = TransactionCommon & {
|
|
|
30
44
|
baseReserve: BigNumber | null | undefined;
|
|
31
45
|
memoType: string | null | undefined;
|
|
32
46
|
memoValue: string | null | undefined;
|
|
47
|
+
mode: StellarTransactionMode;
|
|
48
|
+
assetCode: string | undefined;
|
|
49
|
+
assetIssuer: string | undefined;
|
|
33
50
|
};
|
|
51
|
+
|
|
34
52
|
export type TransactionRaw = TransactionCommonRaw & {
|
|
35
53
|
family: "stellar";
|
|
36
54
|
networkInfo: NetworkInfoRaw | null | undefined;
|
|
@@ -38,4 +56,38 @@ export type TransactionRaw = TransactionCommonRaw & {
|
|
|
38
56
|
baseReserve: string | null | undefined;
|
|
39
57
|
memoType: string | null | undefined;
|
|
40
58
|
memoValue: string | null | undefined;
|
|
59
|
+
mode: StellarTransactionMode;
|
|
60
|
+
assetCode: string | undefined;
|
|
61
|
+
assetIssuer: string | undefined;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type BalanceAsset = {
|
|
65
|
+
balance: string;
|
|
66
|
+
limit: string;
|
|
67
|
+
buying_liabilities: string;
|
|
68
|
+
selling_liabilities: string;
|
|
69
|
+
last_modified_ledger: number;
|
|
70
|
+
is_authorized: boolean;
|
|
71
|
+
is_authorized_to_maintain_liabilities: boolean;
|
|
72
|
+
asset_type: string;
|
|
73
|
+
asset_code: string;
|
|
74
|
+
asset_issuer: string;
|
|
75
|
+
liquidity_pool_id?: string;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export type RawOperation = ServerApi.OperationRecord & {
|
|
79
|
+
asset_code?: string;
|
|
80
|
+
asset_issuer?: string;
|
|
81
|
+
from?: string;
|
|
82
|
+
to?: string;
|
|
83
|
+
funder?: string;
|
|
84
|
+
trustor?: string;
|
|
85
|
+
account?: string;
|
|
86
|
+
transaction_successful: boolean;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type Signer = {
|
|
90
|
+
weight: number;
|
|
91
|
+
key: string;
|
|
92
|
+
type: string;
|
|
41
93
|
};
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Account, CryptoCurrency } from "../../types";
|
|
3
|
+
import { prepareMessageToSign } from "./index";
|
|
4
|
+
import { MessageData } from "./types";
|
|
5
|
+
|
|
6
|
+
describe("prepareMessageToSign", () => {
|
|
7
|
+
it("returns the prepared data from a simple string", () => {
|
|
8
|
+
// Given
|
|
9
|
+
const crypto = createCryptoCurrency("ethereum");
|
|
10
|
+
const account = createAccount(crypto);
|
|
11
|
+
const message = "Message de test";
|
|
12
|
+
const expectedRawMessage = "0x4d6573736167652064652074657374";
|
|
13
|
+
|
|
14
|
+
// When
|
|
15
|
+
let result: MessageData | null = null;
|
|
16
|
+
let error: unknown = null;
|
|
17
|
+
try {
|
|
18
|
+
result = prepareMessageToSign(account, message);
|
|
19
|
+
} catch (err) {
|
|
20
|
+
error = err;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Then
|
|
24
|
+
expect(error).toBeNull();
|
|
25
|
+
expect(result).toEqual({
|
|
26
|
+
currency: crypto,
|
|
27
|
+
path: "44'/60'/0'/0/0",
|
|
28
|
+
derivationMode: "ethM",
|
|
29
|
+
message: "Message de test",
|
|
30
|
+
rawMessage: expectedRawMessage,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("returns an error if account is not linked to a crypto able to sign a message", () => {
|
|
35
|
+
// Given
|
|
36
|
+
const crypto = createCryptoCurrency("mycoin");
|
|
37
|
+
const account = createAccount(crypto);
|
|
38
|
+
const message = "Message de test";
|
|
39
|
+
|
|
40
|
+
// When
|
|
41
|
+
let result: MessageData | null = null;
|
|
42
|
+
let error: Error | null = null;
|
|
43
|
+
try {
|
|
44
|
+
result = prepareMessageToSign(account, message);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
error = err as Error;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Then
|
|
50
|
+
expect(result).toBeNull();
|
|
51
|
+
expect(error).toEqual(Error("Crypto does not support signMessage"));
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const createCryptoCurrency = (family: string): CryptoCurrency => ({
|
|
56
|
+
type: "CryptoCurrency",
|
|
57
|
+
id: "testCoinId",
|
|
58
|
+
coinType: 8008,
|
|
59
|
+
name: "MyCoin",
|
|
60
|
+
managerAppName: "MyCoin",
|
|
61
|
+
ticker: "MYC",
|
|
62
|
+
countervalueTicker: "MYC",
|
|
63
|
+
scheme: "mycoin",
|
|
64
|
+
color: "#ff0000",
|
|
65
|
+
family,
|
|
66
|
+
units: [
|
|
67
|
+
{
|
|
68
|
+
name: "MYC",
|
|
69
|
+
code: "MYC",
|
|
70
|
+
magnitude: 8,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
name: "SmallestUnit",
|
|
74
|
+
code: "SMALLESTUNIT",
|
|
75
|
+
magnitude: 0,
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
explorerViews: [
|
|
79
|
+
{
|
|
80
|
+
address: "https://mycoinexplorer.com/account/$address",
|
|
81
|
+
tx: "https://mycoinexplorer.com/transaction/$hash",
|
|
82
|
+
token: "https://mycoinexplorer.com/token/$contractAddress/?a=$address",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const createAccount = (crypto: CryptoCurrency): Account => ({
|
|
88
|
+
type: "Account",
|
|
89
|
+
id: "ethereumjs:2:ethereum:0x01:",
|
|
90
|
+
seedIdentifier: "0x01",
|
|
91
|
+
derivationMode: "ethM",
|
|
92
|
+
index: 0,
|
|
93
|
+
freshAddress: "0x01",
|
|
94
|
+
freshAddressPath: "44'/60'/0'/0/0",
|
|
95
|
+
freshAddresses: [],
|
|
96
|
+
name: "Ethereum 1",
|
|
97
|
+
starred: false,
|
|
98
|
+
used: false,
|
|
99
|
+
balance: new BigNumber("51281813126095913"),
|
|
100
|
+
spendableBalance: new BigNumber("51281813126095913"),
|
|
101
|
+
creationDate: new Date(),
|
|
102
|
+
blockHeight: 8168983,
|
|
103
|
+
currency: crypto,
|
|
104
|
+
unit: {
|
|
105
|
+
name: "satoshi",
|
|
106
|
+
code: "BTC",
|
|
107
|
+
magnitude: 5,
|
|
108
|
+
},
|
|
109
|
+
operationsCount: 0,
|
|
110
|
+
operations: [],
|
|
111
|
+
pendingOperations: [],
|
|
112
|
+
lastSyncDate: new Date(),
|
|
113
|
+
balanceHistoryCache: {
|
|
114
|
+
HOUR: {
|
|
115
|
+
balances: [],
|
|
116
|
+
latestDate: undefined,
|
|
117
|
+
},
|
|
118
|
+
DAY: {
|
|
119
|
+
balances: [],
|
|
120
|
+
latestDate: undefined,
|
|
121
|
+
},
|
|
122
|
+
WEEK: {
|
|
123
|
+
balances: [],
|
|
124
|
+
latestDate: undefined,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
swapHistory: [],
|
|
128
|
+
});
|
|
@@ -1,26 +1,42 @@
|
|
|
1
|
-
import invariant from "invariant";
|
|
2
1
|
import {
|
|
3
2
|
DeviceAppVerifyNotSupported,
|
|
4
3
|
UserRefusedAddress,
|
|
5
4
|
} from "@ledgerhq/errors";
|
|
6
5
|
import { log } from "@ledgerhq/logs";
|
|
7
|
-
import
|
|
8
|
-
import
|
|
6
|
+
import invariant from "invariant";
|
|
7
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
8
|
+
import { from, Observable } from "rxjs";
|
|
9
9
|
import perFamily from "../../generated/hw-signMessage";
|
|
10
|
-
import {
|
|
11
|
-
import { from } from "rxjs";
|
|
12
|
-
import { createAction as createAppAction } from "../actions/app";
|
|
10
|
+
import { Account } from "../../types";
|
|
13
11
|
import type { AppRequest, AppState } from "../actions/app";
|
|
12
|
+
import { createAction as createAppAction } from "../actions/app";
|
|
14
13
|
import type { Device } from "../actions/types";
|
|
15
14
|
import type { ConnectAppEvent, Input as ConnectAppInput } from "../connectApp";
|
|
16
15
|
import { withDevice } from "../deviceAccess";
|
|
17
|
-
import type { MessageData, Result } from "./types";
|
|
16
|
+
import type { MessageData, Resolver, Result } from "./types";
|
|
17
|
+
|
|
18
|
+
export const prepareMessageToSign = (
|
|
19
|
+
{ currency, freshAddressPath, derivationMode }: Account,
|
|
20
|
+
message: string
|
|
21
|
+
): MessageData | null => {
|
|
22
|
+
if (!perFamily[currency.family]) {
|
|
23
|
+
throw new Error("Crypto does not support signMessage");
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
currency: currency,
|
|
28
|
+
path: freshAddressPath,
|
|
29
|
+
derivationMode: derivationMode,
|
|
30
|
+
message: message,
|
|
31
|
+
rawMessage: "0x" + Buffer.from(message).toString("hex"),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
18
34
|
|
|
19
35
|
const dispatch: Resolver = (transport, opts) => {
|
|
20
36
|
const { currency, verify } = opts;
|
|
21
|
-
const
|
|
22
|
-
invariant(
|
|
23
|
-
return
|
|
37
|
+
const signMessage = perFamily[currency.family];
|
|
38
|
+
invariant(signMessage, `signMessage is not implemented for ${currency.id}`);
|
|
39
|
+
return signMessage(transport, opts)
|
|
24
40
|
.then((result) => {
|
|
25
41
|
log(
|
|
26
42
|
"hw",
|
|
@@ -59,24 +75,28 @@ export type State = AppState & BaseState;
|
|
|
59
75
|
export type Request = AppRequest & {
|
|
60
76
|
message: MessageData;
|
|
61
77
|
};
|
|
78
|
+
|
|
62
79
|
export type Input = {
|
|
63
80
|
request: Request;
|
|
64
81
|
deviceId: string;
|
|
65
82
|
};
|
|
83
|
+
|
|
66
84
|
export const signMessageExec = ({
|
|
67
85
|
request,
|
|
68
86
|
deviceId,
|
|
69
87
|
}: Input): Observable<Result> => {
|
|
70
|
-
const result: Observable<Result> = withDevice(deviceId)((
|
|
71
|
-
from(dispatch(
|
|
88
|
+
const result: Observable<Result> = withDevice(deviceId)((transport) =>
|
|
89
|
+
from(dispatch(transport, request.message))
|
|
72
90
|
);
|
|
73
91
|
return result;
|
|
74
92
|
};
|
|
93
|
+
|
|
75
94
|
const initialState: BaseState = {
|
|
76
95
|
signMessageRequested: null,
|
|
77
96
|
signMessageError: null,
|
|
78
97
|
signMessageResult: null,
|
|
79
98
|
};
|
|
99
|
+
|
|
80
100
|
export const createAction = (
|
|
81
101
|
connectAppExec: (arg0: ConnectAppInput) => Observable<ConnectAppEvent>,
|
|
82
102
|
signMessage: (arg0: Input) => Observable<Result> = signMessageExec
|
|
@@ -97,6 +117,7 @@ export const createAction = (
|
|
|
97
117
|
signMessageRequested: request.message,
|
|
98
118
|
});
|
|
99
119
|
const signedFired = useRef<boolean>();
|
|
120
|
+
|
|
100
121
|
const sign = useCallback(async () => {
|
|
101
122
|
let result;
|
|
102
123
|
|
|
@@ -124,6 +145,7 @@ export const createAction = (
|
|
|
124
145
|
|
|
125
146
|
setState({ ...initialState, signMessageResult: result?.signature });
|
|
126
147
|
}, [device, request]);
|
|
148
|
+
|
|
127
149
|
useEffect(() => {
|
|
128
150
|
if (!device || !opened || inWrongDeviceForAccount || error) {
|
|
129
151
|
return;
|
|
@@ -146,9 +168,9 @@ export const createAction = (
|
|
|
146
168
|
|
|
147
169
|
return {
|
|
148
170
|
useHook,
|
|
149
|
-
mapResult: (
|
|
150
|
-
signature:
|
|
151
|
-
error:
|
|
171
|
+
mapResult: (state: State) => ({
|
|
172
|
+
signature: state.signMessageResult,
|
|
173
|
+
error: state.signMessageError,
|
|
152
174
|
}),
|
|
153
175
|
};
|
|
154
176
|
};
|
package/src/load/speculos.ts
CHANGED
|
@@ -316,9 +316,7 @@ export function appCandidatesMatches(
|
|
|
316
316
|
hackBadSemver(appCandidate.firmware),
|
|
317
317
|
searchFirmware
|
|
318
318
|
))) &&
|
|
319
|
-
((!search.appVersion &&
|
|
320
|
-
!appCandidate.appVersion.includes("prerelease") &&
|
|
321
|
-
!appCandidate.appVersion.includes("rc")) ||
|
|
319
|
+
((!search.appVersion && !appCandidate.appVersion.includes("-")) ||
|
|
322
320
|
(search.appVersion &&
|
|
323
321
|
semver.satisfies(appCandidate.appVersion, search.appVersion)))
|
|
324
322
|
);
|
package/src/mock/Btc.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Btc, { AddressFormat } from "@ledgerhq/hw-app-btc";
|
|
2
|
-
import { CreateTransactionArg } from "@ledgerhq/hw-app-btc/
|
|
2
|
+
import { CreateTransactionArg } from "@ledgerhq/hw-app-btc/createTransaction";
|
|
3
3
|
import Transport from "@ledgerhq/hw-transport";
|
|
4
4
|
import hash from "object-hash";
|
|
5
5
|
|