@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
package/src/env.ts
CHANGED
|
@@ -105,6 +105,11 @@ const envDefinitions = {
|
|
|
105
105
|
def: 200,
|
|
106
106
|
desc: "Limit of operation that Horizon will fetch per page",
|
|
107
107
|
},
|
|
108
|
+
API_STELLAR_HORIZON_STATIC_FEE: {
|
|
109
|
+
def: false,
|
|
110
|
+
parser: boolParser,
|
|
111
|
+
desc: "Static fee for Stellar account",
|
|
112
|
+
},
|
|
108
113
|
API_TEZOS_BAKER: {
|
|
109
114
|
parser: stringParser,
|
|
110
115
|
def: "https://tezos-bakers.api.live.ledger.com",
|
|
@@ -419,6 +424,11 @@ const envDefinitions = {
|
|
|
419
424
|
parser: boolParser,
|
|
420
425
|
desc: "mock the cryptoassets config and test partner (in the context of app-exchange)",
|
|
421
426
|
},
|
|
427
|
+
MOCK_REMOTE_LIVE_MANIFEST: {
|
|
428
|
+
def: "",
|
|
429
|
+
parser: stringParser,
|
|
430
|
+
desc: "mock remote live app manifest",
|
|
431
|
+
},
|
|
422
432
|
NFT_CURRENCIES: {
|
|
423
433
|
def: "ethereum,polygon",
|
|
424
434
|
parser: stringParser,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { AccessDeniedError } from "./errors";
|
|
2
|
+
|
|
3
|
+
function functionA() {
|
|
4
|
+
throw new AccessDeniedError();
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
describe("custom errors", () => {
|
|
8
|
+
test("error instanceof", () => {
|
|
9
|
+
try {
|
|
10
|
+
functionA();
|
|
11
|
+
} catch (e: any) {
|
|
12
|
+
expect(e).toBeInstanceOf(AccessDeniedError);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("promise error instanceof", () => {
|
|
17
|
+
expect(Promise.reject(new AccessDeniedError())).rejects.toBeInstanceOf(
|
|
18
|
+
AccessDeniedError
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
});
|
package/src/errors.ts
CHANGED
|
@@ -60,12 +60,6 @@ export const TronTransactionExpired = createCustomErrorClass(
|
|
|
60
60
|
export const TronNotEnoughEnergy = createCustomErrorClass(
|
|
61
61
|
"TronNotEnoughEnergy"
|
|
62
62
|
);
|
|
63
|
-
export const StellarMemoRecommended = createCustomErrorClass(
|
|
64
|
-
"StellarMemoRecommended"
|
|
65
|
-
);
|
|
66
|
-
export const StellarWrongMemoFormat = createCustomErrorClass(
|
|
67
|
-
"StellarWrongMemoFormat"
|
|
68
|
-
);
|
|
69
63
|
export const AccountAwaitingSendPendingOperations = createCustomErrorClass(
|
|
70
64
|
"AccountAwaitingSendPendingOperations"
|
|
71
65
|
);
|
|
@@ -213,5 +207,6 @@ export const UnsupportedDerivation = createCustomErrorClass(
|
|
|
213
207
|
);
|
|
214
208
|
|
|
215
209
|
export * from "./families/polkadot/errors";
|
|
210
|
+
export * from "./families/stellar/errors";
|
|
216
211
|
export * from "./families/solana/errors";
|
|
217
212
|
export * from "./families/cardano/errors";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getTokenById } from "@ledgerhq/cryptoassets
|
|
1
|
+
import { getTokenById } from "@ledgerhq/cryptoassets";
|
|
2
2
|
import BigNumber from "bignumber.js";
|
|
3
3
|
import { getCryptoCurrencyById } from "../../../currencies";
|
|
4
4
|
import { genAccount } from "../../../mock/account";
|
|
@@ -134,7 +134,6 @@ const dataset: CurrenciesData<Transaction> = {
|
|
|
134
134
|
balance: "2757",
|
|
135
135
|
blockHeight: 0,
|
|
136
136
|
lastSyncDate: "",
|
|
137
|
-
xpub: "xpub6BuPWhjLqutPV8SF4RMrrn8c3t7uBZbz4CBbThpbg9GYjqRMncra9mjgSfWSK7uMDz37hhzJ8wvkbDDQQJt6VgwLoszvmPiSBtLA1bPLLSn",
|
|
138
137
|
},
|
|
139
138
|
},
|
|
140
139
|
{
|
|
@@ -160,7 +159,6 @@ const dataset: CurrenciesData<Transaction> = {
|
|
|
160
159
|
unitMagnitude: 8,
|
|
161
160
|
lastSyncDate: "",
|
|
162
161
|
balance: "2717",
|
|
163
|
-
xpub: "xpub6DEHKg8fgKcb9at2u9Xhjtx4tXGyWqUPQAx2zNCzr41gQRyCqpCn7onSoJU4VS96GXyCtAhhFxErnG2pGVvVexaqF7DEfqGGnGk7Havn7C2",
|
|
164
162
|
},
|
|
165
163
|
},
|
|
166
164
|
],
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
} from "../../derivation";
|
|
14
14
|
import { withDevice } from "../../hw/deviceAccess";
|
|
15
15
|
import getAddress from "../../hw/getAddress";
|
|
16
|
+
import { decodeAccountId } from "../../account/accountId";
|
|
17
|
+
|
|
16
18
|
export type AccountDescriptor = {
|
|
17
19
|
internal: string;
|
|
18
20
|
external: string;
|
|
@@ -57,7 +59,8 @@ export function inferDescriptorFromAccount(
|
|
|
57
59
|
account: Account
|
|
58
60
|
): AccountDescriptor | null | undefined {
|
|
59
61
|
if (account.currency.family !== "bitcoin") return;
|
|
60
|
-
const {
|
|
62
|
+
const { id, derivationMode, seedIdentifier, currency, index } = account;
|
|
63
|
+
const xpub = decodeAccountId(id).xpubOrAddress;
|
|
61
64
|
const fingerprint = makeFingerprint(
|
|
62
65
|
compressPublicKeySECP256(Buffer.from(seedIdentifier, "hex"))
|
|
63
66
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bip32asBuffer } from "@ledgerhq/hw-app-btc/
|
|
1
|
+
import { bip32asBuffer } from "@ledgerhq/hw-app-btc/bip32";
|
|
2
2
|
import type { DerivationMode } from "../../derivation";
|
|
3
3
|
import { getAddressFormatDerivationMode } from "../../derivation";
|
|
4
4
|
import invariant from "invariant";
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
} from "../../hw/getAddress/types";
|
|
11
11
|
import { UnsupportedDerivation } from "../../errors";
|
|
12
12
|
import Transport from "@ledgerhq/hw-transport";
|
|
13
|
-
import BtcOld from "@ledgerhq/hw-app-btc/
|
|
13
|
+
import BtcOld from "@ledgerhq/hw-app-btc/BtcOld";
|
|
14
14
|
|
|
15
15
|
const oldP2SH = {
|
|
16
16
|
digibyte: 5,
|
|
@@ -19,6 +19,8 @@ import { perCoinLogic } from "./logic";
|
|
|
19
19
|
import wallet from "./wallet-btc";
|
|
20
20
|
import { getAddressWithBtcInstance } from "./hw-getAddress";
|
|
21
21
|
import { mapTxToOperations } from "./logic";
|
|
22
|
+
import { decodeAccountId } from "../../account/accountId";
|
|
23
|
+
import { startSpan } from "../../performance";
|
|
22
24
|
|
|
23
25
|
// Map LL's DerivationMode to wallet-btc's
|
|
24
26
|
const toWalletDerivationMode = (
|
|
@@ -79,6 +81,7 @@ const deduplicateOperations = (
|
|
|
79
81
|
};
|
|
80
82
|
|
|
81
83
|
const getAccountShape: GetAccountShape = async (info) => {
|
|
84
|
+
let span;
|
|
82
85
|
const {
|
|
83
86
|
transport,
|
|
84
87
|
currency,
|
|
@@ -93,7 +96,9 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
93
96
|
const rootPath = derivationPath.split("/", 2).join("/");
|
|
94
97
|
const accountPath = `${rootPath}/${index}'`;
|
|
95
98
|
|
|
96
|
-
const paramXpub = initialAccount
|
|
99
|
+
const paramXpub = initialAccount
|
|
100
|
+
? decodeAccountId(initialAccount.id).xpubOrAddress
|
|
101
|
+
: undefined;
|
|
97
102
|
|
|
98
103
|
let generatedXpub;
|
|
99
104
|
if (!paramXpub) {
|
|
@@ -132,6 +137,7 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
132
137
|
throw new Error(`Unsupported explorer version ${explorer.version}`);
|
|
133
138
|
}
|
|
134
139
|
|
|
140
|
+
span = startSpan("sync", "generateAccount");
|
|
135
141
|
const walletAccount =
|
|
136
142
|
initialAccount?.bitcoinResources?.walletAccount ||
|
|
137
143
|
(await wallet.generateAccount({
|
|
@@ -146,6 +152,7 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
146
152
|
storage: "mock",
|
|
147
153
|
storageParams: [],
|
|
148
154
|
}));
|
|
155
|
+
span.finish();
|
|
149
156
|
|
|
150
157
|
const oldOperations = initialAccount?.operations || [];
|
|
151
158
|
await wallet.syncAccount(walletAccount);
|
|
@@ -153,22 +160,29 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
153
160
|
const currentBlock = await walletAccount.xpub.explorer.getCurrentBlock();
|
|
154
161
|
const blockHeight = currentBlock?.height;
|
|
155
162
|
|
|
163
|
+
span = startSpan("sync", "getAccountTransactions");
|
|
156
164
|
// @ts-expect-error return from wallet-btc should be typed
|
|
157
165
|
const { txs: transactions } = await wallet.getAccountTransactions(
|
|
158
166
|
walletAccount
|
|
159
167
|
);
|
|
168
|
+
span.finish();
|
|
160
169
|
|
|
170
|
+
span = startSpan("sync", "getXpubAddresses");
|
|
161
171
|
const accountAddresses: Set<string> = new Set<string>();
|
|
162
172
|
const accountAddressesWithInfo = await walletAccount.xpub.getXpubAddresses();
|
|
163
173
|
accountAddressesWithInfo.forEach((a) => accountAddresses.add(a.address));
|
|
174
|
+
span.finish();
|
|
164
175
|
|
|
176
|
+
span = startSpan("sync", "getUniquesAddresses");
|
|
165
177
|
const changeAddresses: Set<string> = new Set<string>();
|
|
166
178
|
const changeAddressesWithInfo =
|
|
167
179
|
await walletAccount.xpub.storage.getUniquesAddresses({
|
|
168
180
|
account: 1,
|
|
169
181
|
});
|
|
170
182
|
changeAddressesWithInfo.forEach((a) => changeAddresses.add(a.address));
|
|
183
|
+
span.finish();
|
|
171
184
|
|
|
185
|
+
span = startSpan("sync", "mapTxToOperations");
|
|
172
186
|
const newOperations = transactions
|
|
173
187
|
?.map((tx) =>
|
|
174
188
|
mapTxToOperations(
|
|
@@ -180,10 +194,18 @@ const getAccountShape: GetAccountShape = async (info) => {
|
|
|
180
194
|
)
|
|
181
195
|
)
|
|
182
196
|
.flat();
|
|
197
|
+
span.finish();
|
|
198
|
+
|
|
199
|
+
span = startSpan("sync", "unify operations");
|
|
183
200
|
const newUniqueOperations = deduplicateOperations(newOperations);
|
|
184
201
|
const operations = mergeOps(oldOperations, newUniqueOperations);
|
|
202
|
+
span.finish();
|
|
203
|
+
|
|
204
|
+
span = startSpan("sync", "gather utxos");
|
|
185
205
|
const rawUtxos = await wallet.getAccountUnspentUtxos(walletAccount);
|
|
186
206
|
const utxos = rawUtxos.map((utxo) => fromWalletUtxo(utxo, changeAddresses));
|
|
207
|
+
span.finish();
|
|
208
|
+
|
|
187
209
|
return {
|
|
188
210
|
id: accountId,
|
|
189
211
|
xpub,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { findLast, filter, uniqBy, findIndex
|
|
1
|
+
import { findLast, filter, uniqBy, findIndex } from "lodash";
|
|
2
2
|
import Base from "../crypto/base";
|
|
3
3
|
import { Input, IStorage, Output, TX, Address } from "./types";
|
|
4
4
|
|
|
@@ -78,13 +78,10 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
78
78
|
if (this.txs[this.primaryIndex[index]]) {
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
|
-
if (
|
|
82
|
-
typeof this.accountIndex[`${tx.account}-${tx.index}`] === "undefined"
|
|
83
|
-
) {
|
|
84
|
-
this.accountIndex[`${tx.account}-${tx.index}`] = [];
|
|
85
|
-
}
|
|
86
81
|
const idx = this.txs.push(tx) - 1;
|
|
87
82
|
this.primaryIndex[index] = idx;
|
|
83
|
+
this.accountIndex[`${tx.account}-${tx.index}`] =
|
|
84
|
+
this.accountIndex[`${tx.account}-${tx.index}`] || [];
|
|
88
85
|
this.accountIndex[`${tx.account}-${tx.index}`].push(idx);
|
|
89
86
|
this.unspentUtxos[indexAddress] = this.unspentUtxos[indexAddress] || [];
|
|
90
87
|
this.spentUtxos[indexAddress] = this.spentUtxos[indexAddress] || [];
|
|
@@ -196,43 +193,32 @@ class BitcoinLikeStorage implements IStorage {
|
|
|
196
193
|
exportSync() {
|
|
197
194
|
return {
|
|
198
195
|
txs: this.txs,
|
|
199
|
-
primaryIndex: this.primaryIndex,
|
|
200
|
-
accountIndex: this.accountIndex,
|
|
201
|
-
unspentUtxos: this.unspentUtxos,
|
|
202
196
|
addressCache: this.addressCache,
|
|
203
197
|
};
|
|
204
198
|
}
|
|
205
199
|
|
|
206
|
-
loadSync(data: {
|
|
207
|
-
txs
|
|
208
|
-
primaryIndex
|
|
209
|
-
accountIndex
|
|
210
|
-
unspentUtxos
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
200
|
+
loadSync(data: { txs: TX[]; addressCache: { [key: string]: string } }) {
|
|
201
|
+
this.txs = [];
|
|
202
|
+
this.primaryIndex = {};
|
|
203
|
+
this.accountIndex = {};
|
|
204
|
+
this.unspentUtxos = {};
|
|
205
|
+
this.spentUtxos = {};
|
|
206
|
+
data.txs.forEach((tx) => {
|
|
207
|
+
// migration from the field "hash" to "id" to adapt old data format
|
|
208
|
+
if (!tx.id && tx.hash) {
|
|
209
|
+
tx.id = tx.hash;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
this.appendTxs(data.txs);
|
|
217
213
|
this.addressCache = data.addressCache;
|
|
218
214
|
Base.addressCache = { ...Base.addressCache, ...this.addressCache };
|
|
219
|
-
if (!this.accountIndex || isEmpty(this.accountIndex)) {
|
|
220
|
-
this.accountIndex = {};
|
|
221
|
-
this.createAccountIndex();
|
|
222
|
-
}
|
|
223
215
|
}
|
|
224
216
|
|
|
225
217
|
async export() {
|
|
226
218
|
return this.exportSync();
|
|
227
219
|
}
|
|
228
220
|
|
|
229
|
-
async load(data: {
|
|
230
|
-
txs: TX[];
|
|
231
|
-
primaryIndex: { [key: string]: number };
|
|
232
|
-
accountIndex: { [key: string]: number[] };
|
|
233
|
-
unspentUtxos: { [key: string]: Output[] };
|
|
234
|
-
addressCache: { [key: string]: string };
|
|
235
|
-
}) {
|
|
221
|
+
async load(data: { txs: TX[]; addressCache: { [key: string]: string } }) {
|
|
236
222
|
return this.loadSync(data);
|
|
237
223
|
}
|
|
238
224
|
|
|
@@ -4,7 +4,7 @@ import { flatten } from "lodash";
|
|
|
4
4
|
import BigNumber from "bignumber.js";
|
|
5
5
|
import Btc from "@ledgerhq/hw-app-btc";
|
|
6
6
|
import { log } from "@ledgerhq/logs";
|
|
7
|
-
import { Transaction } from "@ledgerhq/hw-app-btc/
|
|
7
|
+
import { Transaction } from "@ledgerhq/hw-app-btc/types";
|
|
8
8
|
import { Currency } from "./crypto/types";
|
|
9
9
|
import { TransactionInfo, DerivationModes } from "./types";
|
|
10
10
|
import { Account, SerializedAccount } from "./account";
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import BitcoinLikeStorage from "./wallet-btc/storage";
|
|
2
|
+
|
|
3
|
+
describe("testing transaction data load and export", () => {
|
|
4
|
+
it("testing transaction data load and export", async () => {
|
|
5
|
+
const storage = new BitcoinLikeStorage();
|
|
6
|
+
storage.appendTxs([
|
|
7
|
+
{
|
|
8
|
+
id: "9e1b337875c21f751e70ee2c2c6ee93d8a6733d0f3ba6d139ae6a0479ebcefb0",
|
|
9
|
+
inputs: [],
|
|
10
|
+
outputs: [
|
|
11
|
+
{
|
|
12
|
+
output_index: 0,
|
|
13
|
+
value: "5000000000",
|
|
14
|
+
address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
|
|
15
|
+
output_hash:
|
|
16
|
+
"9e1b337875c21f751e70ee2c2c6ee93d8a6733d0f3ba6d139ae6a0479ebcefb0",
|
|
17
|
+
block_height: 1,
|
|
18
|
+
rbf: false,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
output_index: 1,
|
|
22
|
+
value: "0",
|
|
23
|
+
address: "<unknown>",
|
|
24
|
+
output_hash:
|
|
25
|
+
"9e1b337875c21f751e70ee2c2c6ee93d8a6733d0f3ba6d139ae6a0479ebcefb0",
|
|
26
|
+
block_height: 1,
|
|
27
|
+
rbf: false,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
block: {
|
|
31
|
+
hash: "73c565a6f226978df23480e440b27eb02f307855f50aa3bc72ebb586938f23e0",
|
|
32
|
+
height: 1,
|
|
33
|
+
time: "2021-07-28T13:34:17Z",
|
|
34
|
+
},
|
|
35
|
+
account: 0,
|
|
36
|
+
index: 0,
|
|
37
|
+
address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
|
|
38
|
+
received_at: "2021-07-28T13:34:17Z",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
id: "0b9f98d07eb418fa20573112d3cba6b871d429a06c724a7888ff0886be5213d1",
|
|
42
|
+
inputs: [
|
|
43
|
+
{
|
|
44
|
+
output_hash:
|
|
45
|
+
"2772f3963856f3eb38cb706ec8c2b62fcdeb2ce10f32cf7160afb3873be6f60d",
|
|
46
|
+
output_index: 0,
|
|
47
|
+
value: "5000000000",
|
|
48
|
+
address: "2NCDBM9DAuMrD1T8XDHMxvbTmLutP7at4AB",
|
|
49
|
+
sequence: 4294967294,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
outputs: [
|
|
53
|
+
{
|
|
54
|
+
output_index: 0,
|
|
55
|
+
value: "300000000",
|
|
56
|
+
address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
|
|
57
|
+
output_hash:
|
|
58
|
+
"0b9f98d07eb418fa20573112d3cba6b871d429a06c724a7888ff0886be5213d1",
|
|
59
|
+
block_height: 120,
|
|
60
|
+
rbf: false,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
output_index: 1,
|
|
64
|
+
value: "4699983200",
|
|
65
|
+
address: "2MynSTpze5SDcuLr1DekSV7RVrFpQCo3LeP",
|
|
66
|
+
output_hash:
|
|
67
|
+
"0b9f98d07eb418fa20573112d3cba6b871d429a06c724a7888ff0886be5213d1",
|
|
68
|
+
block_height: 120,
|
|
69
|
+
rbf: false,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
block: {
|
|
73
|
+
hash: "305d4b8d4a6d6ecca0a3dd0216f8ecd090978ed346d1845883c8aa4529d72fc8",
|
|
74
|
+
height: 120,
|
|
75
|
+
time: "2021-07-28T13:34:38Z",
|
|
76
|
+
},
|
|
77
|
+
account: 0,
|
|
78
|
+
index: 0,
|
|
79
|
+
address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
|
|
80
|
+
received_at: "2021-07-28T13:34:38Z",
|
|
81
|
+
},
|
|
82
|
+
]);
|
|
83
|
+
const primaryIndexCopy = Object.assign({}, storage.primaryIndex);
|
|
84
|
+
const accountIndexCopy = Object.assign({}, storage.accountIndex);
|
|
85
|
+
expect(Object.keys(primaryIndexCopy).length).toEqual(2);
|
|
86
|
+
expect(Object.keys(accountIndexCopy).length).toEqual(1);
|
|
87
|
+
/* primaryIndex:
|
|
88
|
+
{
|
|
89
|
+
'mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb-9e1b337875c21f751e70ee2c2c6ee93d8a6733d0f3ba6d139ae6a0479ebcefb0': 0,
|
|
90
|
+
'mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb-0b9f98d07eb418fa20573112d3cba6b871d429a06c724a7888ff0886be5213d1': 1
|
|
91
|
+
}
|
|
92
|
+
accountIndex:
|
|
93
|
+
{ '0-0': [ 0, 1 ] }
|
|
94
|
+
*/
|
|
95
|
+
expect(Object.keys(accountIndexCopy["0-0"]).length).toEqual(2);
|
|
96
|
+
const txs = (await storage.export()).txs;
|
|
97
|
+
storage.load({ txs: txs, addressCache: {} });
|
|
98
|
+
expect(storage.primaryIndex).toMatchObject(primaryIndexCopy);
|
|
99
|
+
expect(storage.accountIndex).toMatchObject(accountIndexCopy);
|
|
100
|
+
}, 30000);
|
|
101
|
+
});
|
|
@@ -20,7 +20,7 @@ import type { Modes as ERC20Modes } from "./erc20";
|
|
|
20
20
|
import type { Modes as SendModes } from "./send";
|
|
21
21
|
import type { Modes as ERC721Modes } from "./erc721";
|
|
22
22
|
import type { Modes as ERC1155Modes } from "./erc1155";
|
|
23
|
-
import { ResolutionConfig } from "@ledgerhq/hw-app-eth/lib/services/types";
|
|
23
|
+
import type { ResolutionConfig } from "@ledgerhq/hw-app-eth/lib/services/types";
|
|
24
24
|
|
|
25
25
|
const modules = {
|
|
26
26
|
erc20,
|
|
@@ -8,7 +8,7 @@ import { log } from "@ledgerhq/logs";
|
|
|
8
8
|
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
9
9
|
import Eth from "@ledgerhq/hw-app-eth";
|
|
10
10
|
import { byContractAddressAndChainId } from "@ledgerhq/hw-app-eth/erc20";
|
|
11
|
-
import ethLedgerServices from "@ledgerhq/hw-app-eth
|
|
11
|
+
import { ledgerService as ethLedgerServices } from "@ledgerhq/hw-app-eth";
|
|
12
12
|
import type { Transaction } from "./types";
|
|
13
13
|
import type { Operation, Account, SignOperationEvent } from "../../types";
|
|
14
14
|
import { getGasLimit, buildEthereumTx } from "./transaction";
|
|
@@ -17,7 +17,7 @@ import { withDevice } from "../../hw/deviceAccess";
|
|
|
17
17
|
import { modes } from "./modules";
|
|
18
18
|
import { isNFTActive } from "../../nft";
|
|
19
19
|
import { getEnv } from "../../env";
|
|
20
|
-
import { LoadConfig } from "@ledgerhq/hw-app-eth/lib/services/types";
|
|
20
|
+
import type { LoadConfig } from "@ledgerhq/hw-app-eth/lib/services/types";
|
|
21
21
|
import { Transaction as EthereumTx } from "@ethereumjs/tx";
|
|
22
22
|
export const signOperation = ({
|
|
23
23
|
account,
|
|
@@ -375,9 +375,9 @@ const ethereumClassic: AppSpec<Transaction> = {
|
|
|
375
375
|
maxAccount: 4,
|
|
376
376
|
}),
|
|
377
377
|
};
|
|
378
|
-
const
|
|
379
|
-
name: "Ethereum
|
|
380
|
-
currency: getCryptoCurrencyById("
|
|
378
|
+
const ethereumGoerli: AppSpec<Transaction> = {
|
|
379
|
+
name: "Ethereum Goerli",
|
|
380
|
+
currency: getCryptoCurrencyById("ethereum_goerli"),
|
|
381
381
|
appQuery: {
|
|
382
382
|
model: DeviceModelId.nanoS,
|
|
383
383
|
appName: "Ethereum",
|
|
@@ -387,7 +387,7 @@ const ethereumRopsten: AppSpec<Transaction> = {
|
|
|
387
387
|
invariant(
|
|
388
388
|
maxSpendable.gt(
|
|
389
389
|
parseCurrencyUnit(
|
|
390
|
-
getCryptoCurrencyById("
|
|
390
|
+
getCryptoCurrencyById("ethereum_goerli").units[0],
|
|
391
391
|
"0.01"
|
|
392
392
|
)
|
|
393
393
|
),
|
|
@@ -498,5 +498,5 @@ export default {
|
|
|
498
498
|
polygon,
|
|
499
499
|
ethereum,
|
|
500
500
|
ethereumClassic,
|
|
501
|
-
|
|
501
|
+
ethereumGoerli,
|
|
502
502
|
};
|