@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.
Files changed (235) hide show
  1. package/lib/apps/support.js +1 -1
  2. package/lib/apps/support.js.map +1 -1
  3. package/lib/bot/index.d.ts.map +1 -1
  4. package/lib/bot/index.js +4 -2
  5. package/lib/bot/index.js.map +1 -1
  6. package/lib/bot/specs.d.ts +1 -0
  7. package/lib/bot/specs.d.ts.map +1 -1
  8. package/lib/bot/specs.js +6 -1
  9. package/lib/bot/specs.js.map +1 -1
  10. package/lib/currencies/support.d.ts +1 -1
  11. package/lib/currencies/support.d.ts.map +1 -1
  12. package/lib/env.d.ts +15 -5
  13. package/lib/env.d.ts.map +1 -1
  14. package/lib/env.js +10 -0
  15. package/lib/env.js.map +1 -1
  16. package/lib/env.react.d.ts +1 -1
  17. package/lib/env.react.d.ts.map +1 -1
  18. package/lib/errors.d.ts +101 -306
  19. package/lib/errors.d.ts.map +1 -1
  20. package/lib/errors.js +3 -4
  21. package/lib/errors.js.map +1 -1
  22. package/lib/errors.test.d.ts +2 -0
  23. package/lib/errors.test.d.ts.map +1 -0
  24. package/lib/errors.test.js +20 -0
  25. package/lib/errors.test.js.map +1 -0
  26. package/lib/exchange/swap/utils/index.test.js +2 -2
  27. package/lib/exchange/swap/utils/index.test.js.map +1 -1
  28. package/lib/families/bitcoin/datasets/bitcoin.d.ts.map +1 -1
  29. package/lib/families/bitcoin/datasets/bitcoin.js +2 -4
  30. package/lib/families/bitcoin/datasets/bitcoin.js.map +1 -1
  31. package/lib/families/bitcoin/descriptor.d.ts.map +1 -1
  32. package/lib/families/bitcoin/descriptor.js +3 -1
  33. package/lib/families/bitcoin/descriptor.js.map +1 -1
  34. package/lib/families/bitcoin/errors.d.ts +1 -3
  35. package/lib/families/bitcoin/errors.d.ts.map +1 -1
  36. package/lib/families/bitcoin/exchange.js +1 -1
  37. package/lib/families/bitcoin/exchange.js.map +1 -1
  38. package/lib/families/bitcoin/hw-getAddress.d.ts +1 -1
  39. package/lib/families/bitcoin/hw-getAddress.d.ts.map +1 -1
  40. package/lib/families/bitcoin/js-synchronisation.d.ts.map +1 -1
  41. package/lib/families/bitcoin/js-synchronisation.js +20 -2
  42. package/lib/families/bitcoin/js-synchronisation.js.map +1 -1
  43. package/lib/families/bitcoin/wallet-btc/storage/index.d.ts +0 -36
  44. package/lib/families/bitcoin/wallet-btc/storage/index.d.ts.map +1 -1
  45. package/lib/families/bitcoin/wallet-btc/storage/index.js +14 -14
  46. package/lib/families/bitcoin/wallet-btc/storage/index.js.map +1 -1
  47. package/lib/families/bitcoin/wallet-btc/storage/types.d.ts +1 -0
  48. package/lib/families/bitcoin/wallet-btc/storage/types.d.ts.map +1 -1
  49. package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.d.ts +2 -0
  50. package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.d.ts.map +1 -0
  51. package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.js +146 -0
  52. package/lib/families/bitcoin/xpub.txs.loadExport.unit.test.js.map +1 -0
  53. package/lib/families/cardano/errors.d.ts +1 -3
  54. package/lib/families/cardano/errors.d.ts.map +1 -1
  55. package/lib/families/crypto_org/errors.d.ts +3 -9
  56. package/lib/families/crypto_org/errors.d.ts.map +1 -1
  57. package/lib/families/ethereum/exchange.js +1 -1
  58. package/lib/families/ethereum/exchange.js.map +1 -1
  59. package/lib/families/ethereum/modules/index.d.ts +1 -1
  60. package/lib/families/ethereum/modules/index.d.ts.map +1 -1
  61. package/lib/families/ethereum/signOperation.js +2 -2
  62. package/lib/families/ethereum/signOperation.js.map +1 -1
  63. package/lib/families/ethereum/specs.d.ts +1 -1
  64. package/lib/families/ethereum/specs.js +5 -5
  65. package/lib/families/ethereum/specs.js.map +1 -1
  66. package/lib/families/polkadot/errors.d.ts +12 -36
  67. package/lib/families/polkadot/errors.d.ts.map +1 -1
  68. package/lib/families/ripple/exchange.js +1 -1
  69. package/lib/families/ripple/exchange.js.map +1 -1
  70. package/lib/families/solana/api/chain/instruction/token/types.d.ts +3 -3
  71. package/lib/families/solana/errors.d.ts +20 -60
  72. package/lib/families/solana/errors.d.ts.map +1 -1
  73. package/lib/families/stellar/api/horizon.d.ts +29 -7
  74. package/lib/families/stellar/api/horizon.d.ts.map +1 -1
  75. package/lib/families/stellar/api/horizon.js +114 -58
  76. package/lib/families/stellar/api/horizon.js.map +1 -1
  77. package/lib/families/stellar/api/index.d.ts +1 -1
  78. package/lib/families/stellar/api/index.d.ts.map +1 -1
  79. package/lib/families/stellar/api/index.js +5 -1
  80. package/lib/families/stellar/api/index.js.map +1 -1
  81. package/lib/families/stellar/bridge/mock.d.ts.map +1 -1
  82. package/lib/families/stellar/bridge/mock.js +4 -1
  83. package/lib/families/stellar/bridge/mock.js.map +1 -1
  84. package/lib/families/stellar/bridge.integration.test.js +12 -4
  85. package/lib/families/stellar/bridge.integration.test.js.map +1 -1
  86. package/lib/families/stellar/cli-transaction.d.ts +3 -1
  87. package/lib/families/stellar/cli-transaction.d.ts.map +1 -1
  88. package/lib/families/stellar/cli-transaction.js +48 -2
  89. package/lib/families/stellar/cli-transaction.js.map +1 -1
  90. package/lib/families/stellar/deviceTransactionConfig.d.ts +7 -1
  91. package/lib/families/stellar/deviceTransactionConfig.d.ts.map +1 -1
  92. package/lib/families/stellar/deviceTransactionConfig.js +12 -1
  93. package/lib/families/stellar/deviceTransactionConfig.js.map +1 -1
  94. package/lib/families/stellar/errors.d.ts +12 -0
  95. package/lib/families/stellar/errors.d.ts.map +1 -0
  96. package/lib/families/stellar/errors.js +16 -0
  97. package/lib/families/stellar/errors.js.map +1 -0
  98. package/lib/families/stellar/exchange.js +1 -1
  99. package/lib/families/stellar/exchange.js.map +1 -1
  100. package/lib/families/stellar/js-buildTransaction.d.ts.map +1 -1
  101. package/lib/families/stellar/js-buildTransaction.js +34 -16
  102. package/lib/families/stellar/js-buildTransaction.js.map +1 -1
  103. package/lib/families/stellar/js-createTransaction.d.ts.map +1 -1
  104. package/lib/families/stellar/js-createTransaction.js +4 -1
  105. package/lib/families/stellar/js-createTransaction.js.map +1 -1
  106. package/lib/families/stellar/js-estimateMaxSpendable.js +2 -1
  107. package/lib/families/stellar/js-estimateMaxSpendable.js.map +1 -1
  108. package/lib/families/stellar/js-getTransactionStatus.d.ts.map +1 -1
  109. package/lib/families/stellar/js-getTransactionStatus.js +127 -57
  110. package/lib/families/stellar/js-getTransactionStatus.js.map +1 -1
  111. package/lib/families/stellar/js-prepareTransaction.d.ts.map +1 -1
  112. package/lib/families/stellar/js-prepareTransaction.js +25 -7
  113. package/lib/families/stellar/js-prepareTransaction.js.map +1 -1
  114. package/lib/families/stellar/js-signOperation.d.ts.map +1 -1
  115. package/lib/families/stellar/js-signOperation.js +33 -6
  116. package/lib/families/stellar/js-signOperation.js.map +1 -1
  117. package/lib/families/stellar/js-synchronization.d.ts +1 -1
  118. package/lib/families/stellar/js-synchronization.d.ts.map +1 -1
  119. package/lib/families/stellar/js-synchronization.js +42 -16
  120. package/lib/families/stellar/js-synchronization.js.map +1 -1
  121. package/lib/families/stellar/logic.d.ts +21 -14
  122. package/lib/families/stellar/logic.d.ts.map +1 -1
  123. package/lib/families/stellar/logic.js +158 -57
  124. package/lib/families/stellar/logic.js.map +1 -1
  125. package/lib/families/stellar/specs.d.ts.map +1 -1
  126. package/lib/families/stellar/specs.js +182 -7
  127. package/lib/families/stellar/specs.js.map +1 -1
  128. package/lib/families/stellar/speculos-deviceActions.d.ts.map +1 -1
  129. package/lib/families/stellar/speculos-deviceActions.js +60 -28
  130. package/lib/families/stellar/speculos-deviceActions.js.map +1 -1
  131. package/lib/families/stellar/tokens.d.ts +11 -0
  132. package/lib/families/stellar/tokens.d.ts.map +1 -0
  133. package/lib/families/stellar/tokens.js +82 -0
  134. package/lib/families/stellar/tokens.js.map +1 -0
  135. package/lib/families/stellar/transaction.d.ts +2 -2
  136. package/lib/families/stellar/transaction.d.ts.map +1 -1
  137. package/lib/families/stellar/transaction.js +32 -6
  138. package/lib/families/stellar/transaction.js.map +1 -1
  139. package/lib/families/stellar/types.d.ts +45 -0
  140. package/lib/families/stellar/types.d.ts.map +1 -1
  141. package/lib/families/stellar/types.js +7 -1
  142. package/lib/families/stellar/types.js.map +1 -1
  143. package/lib/families/tezos/exchange.js +1 -1
  144. package/lib/families/tezos/exchange.js.map +1 -1
  145. package/lib/generated/cli-transaction.d.ts +1 -0
  146. package/lib/generated/cli-transaction.d.ts.map +1 -1
  147. package/lib/generated/specs.d.ts +1 -1
  148. package/lib/generated/transaction.d.ts +1 -1
  149. package/lib/hw/signMessage/index.d.ts +4 -3
  150. package/lib/hw/signMessage/index.d.ts.map +1 -1
  151. package/lib/hw/signMessage/index.js +25 -11
  152. package/lib/hw/signMessage/index.js.map +1 -1
  153. package/lib/hw/signMessage/index.test.d.ts +2 -0
  154. package/lib/hw/signMessage/index.test.d.ts.map +1 -0
  155. package/lib/hw/signMessage/index.test.js +126 -0
  156. package/lib/hw/signMessage/index.test.js.map +1 -0
  157. package/lib/load/speculos.d.ts.map +1 -1
  158. package/lib/load/speculos.js +1 -3
  159. package/lib/load/speculos.js.map +1 -1
  160. package/lib/mock/Btc.d.ts +1 -1
  161. package/lib/mock/Btc.d.ts.map +1 -1
  162. package/lib/performance.d.ts +10 -0
  163. package/lib/performance.d.ts.map +1 -0
  164. package/lib/performance.js +72 -0
  165. package/lib/performance.js.map +1 -0
  166. package/lib/performance.test.d.ts +2 -0
  167. package/lib/performance.test.d.ts.map +1 -0
  168. package/lib/performance.test.js +28 -0
  169. package/lib/performance.test.js.map +1 -0
  170. package/lib/platform/providers/RemoteLiveAppProvider/api/index.d.ts.map +1 -1
  171. package/lib/platform/providers/RemoteLiveAppProvider/api/index.js +28 -0
  172. package/lib/platform/providers/RemoteLiveAppProvider/api/index.js.map +1 -1
  173. package/lib/platform/providers/RemoteLiveAppProvider/api/mock.json +0 -31
  174. package/lib/types/currencies.d.ts +1 -1
  175. package/lib/types/currencies.d.ts.map +1 -1
  176. package/lib/walletconnect/Provider.d.ts.map +1 -1
  177. package/lib/walletconnect/Provider.js +1 -3
  178. package/lib/walletconnect/Provider.js.map +1 -1
  179. package/package.json +71 -19
  180. package/src/apps/support.ts +1 -1
  181. package/src/bot/index.ts +3 -1
  182. package/src/bot/specs.ts +7 -1
  183. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +34 -6
  184. package/src/currencies/support.ts +1 -1
  185. package/src/env.ts +10 -0
  186. package/src/errors.test.ts +21 -0
  187. package/src/errors.ts +1 -6
  188. package/src/exchange/swap/utils/index.test.ts +1 -1
  189. package/src/families/bitcoin/datasets/bitcoin.ts +0 -2
  190. package/src/families/bitcoin/descriptor.ts +4 -1
  191. package/src/families/bitcoin/exchange.ts +1 -1
  192. package/src/families/bitcoin/hw-getAddress.ts +1 -1
  193. package/src/families/bitcoin/js-synchronisation.ts +23 -1
  194. package/src/families/bitcoin/wallet-btc/storage/index.ts +17 -31
  195. package/src/families/bitcoin/wallet-btc/storage/types.ts +1 -0
  196. package/src/families/bitcoin/wallet-btc/wallet.ts +1 -1
  197. package/src/families/bitcoin/xpub.txs.loadExport.unit.test.ts +101 -0
  198. package/src/families/ethereum/exchange.ts +1 -1
  199. package/src/families/ethereum/modules/index.ts +1 -1
  200. package/src/families/ethereum/signOperation.ts +2 -2
  201. package/src/families/ethereum/specs.ts +5 -5
  202. package/src/families/ripple/exchange.ts +1 -1
  203. package/src/families/stellar/__snapshots__/bridge.integration.test.ts.snap +765 -339
  204. package/src/families/stellar/api/horizon.ts +115 -33
  205. package/src/families/stellar/api/index.ts +4 -0
  206. package/src/families/stellar/bridge/mock.ts +3 -0
  207. package/src/families/stellar/bridge.integration.test.ts +10 -2
  208. package/src/families/stellar/cli-transaction.ts +75 -2
  209. package/src/families/stellar/deviceTransactionConfig.ts +22 -0
  210. package/src/families/stellar/errors.ts +34 -0
  211. package/src/families/stellar/exchange.ts +1 -1
  212. package/src/families/stellar/js-buildTransaction.ts +56 -16
  213. package/src/families/stellar/js-createTransaction.ts +3 -0
  214. package/src/families/stellar/js-estimateMaxSpendable.ts +1 -1
  215. package/src/families/stellar/js-getTransactionStatus.ts +152 -60
  216. package/src/families/stellar/js-prepareTransaction.ts +4 -3
  217. package/src/families/stellar/js-signOperation.ts +37 -6
  218. package/src/families/stellar/js-synchronization.ts +53 -11
  219. package/src/families/stellar/logic.ts +198 -62
  220. package/src/families/stellar/specs.ts +227 -8
  221. package/src/families/stellar/speculos-deviceActions.ts +66 -22
  222. package/src/families/stellar/tokens.ts +118 -0
  223. package/src/families/stellar/transaction.ts +31 -3
  224. package/src/families/stellar/types.ts +52 -0
  225. package/src/families/tezos/exchange.ts +1 -1
  226. package/src/hw/signMessage/index.test.ts +128 -0
  227. package/src/hw/signMessage/index.ts +37 -15
  228. package/src/load/speculos.ts +1 -3
  229. package/src/mock/Btc.ts +1 -1
  230. package/src/performance.test.ts +26 -0
  231. package/src/performance.ts +61 -0
  232. package/src/platform/providers/RemoteLiveAppProvider/api/index.ts +6 -0
  233. package/src/platform/providers/RemoteLiveAppProvider/api/mock.json +1 -32
  234. package/src/types/currencies.ts +1 -1
  235. 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/lib/tokens";
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 { xpub, derivationMode, seedIdentifier, currency, index } = account;
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/lib/bip32";
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/lib/BtcOld";
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?.xpub;
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, isEmpty } from "lodash";
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: TX[];
208
- primaryIndex: { [key: string]: number };
209
- accountIndex: { [key: string]: number[] };
210
- unspentUtxos: { [key: string]: Output[] };
211
- addressCache: { [key: string]: string };
212
- }) {
213
- this.txs = data.txs;
214
- this.primaryIndex = data.primaryIndex;
215
- this.accountIndex = data.accountIndex;
216
- this.unspentUtxos = data.unspentUtxos;
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
 
@@ -1,5 +1,6 @@
1
1
  export interface TX {
2
2
  id: string;
3
+ hash?: string;
3
4
  account: number;
4
5
  index: number;
5
6
  received_at: string;
@@ -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/lib/types";
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
+ });
@@ -1,4 +1,4 @@
1
- import { bip32asBuffer } from "@ledgerhq/hw-app-btc/lib/bip32";
1
+ import { bip32asBuffer } from "@ledgerhq/hw-app-btc/bip32";
2
2
 
3
3
  const getSerializedAddressParameters = (
4
4
  path: string
@@ -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/lib/services/ledger";
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 ethereumRopsten: AppSpec<Transaction> = {
379
- name: "Ethereum Ropsten",
380
- currency: getCryptoCurrencyById("ethereum_ropsten"),
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("ethereum_ropsten").units[0],
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
- ethereumRopsten,
501
+ ethereumGoerli,
502
502
  };
@@ -1,4 +1,4 @@
1
- import { bip32asBuffer } from "@ledgerhq/hw-app-btc/lib/bip32";
1
+ import { bip32asBuffer } from "@ledgerhq/hw-app-btc/bip32";
2
2
 
3
3
  const getSerializedAddressParameters = (
4
4
  path: string