@ledgerhq/live-common 21.25.2 → 21.26.3

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 (71) hide show
  1. package/lib/account/support.d.ts.map +1 -1
  2. package/lib/account/support.js +1 -25
  3. package/lib/account/support.js.map +1 -1
  4. package/lib/api/Ethereum.d.ts.map +1 -1
  5. package/lib/api/Ethereum.js +1 -4
  6. package/lib/api/Ethereum.js.map +1 -1
  7. package/lib/api/explorerConfig/index.d.ts.map +1 -1
  8. package/lib/api/explorerConfig/index.js +0 -4
  9. package/lib/api/explorerConfig/index.js.map +1 -1
  10. package/lib/errors.d.ts +3 -0
  11. package/lib/errors.d.ts.map +1 -1
  12. package/lib/errors.js +3 -2
  13. package/lib/errors.js.map +1 -1
  14. package/lib/families/bitcoin/test-dataset.js +1 -1
  15. package/lib/families/bitcoin/test-dataset.js.map +1 -1
  16. package/lib/families/bitcoin/wallet-btc/crypto/base.d.ts.map +1 -1
  17. package/lib/families/bitcoin/wallet-btc/crypto/base.js +19 -20
  18. package/lib/families/bitcoin/wallet-btc/crypto/base.js.map +1 -1
  19. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.d.ts.map +1 -1
  20. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js +4 -5
  21. package/lib/families/bitcoin/wallet-btc/crypto/bitcoin.js.map +1 -1
  22. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.d.ts.map +1 -1
  23. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js +3 -4
  24. package/lib/families/bitcoin/wallet-btc/crypto/bitcoincash.js.map +1 -1
  25. package/lib/families/bitcoin/wallet-btc/crypto/decred.d.ts.map +1 -1
  26. package/lib/families/bitcoin/wallet-btc/crypto/decred.js +3 -4
  27. package/lib/families/bitcoin/wallet-btc/crypto/decred.js.map +1 -1
  28. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.d.ts.map +1 -1
  29. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js +3 -4
  30. package/lib/families/bitcoin/wallet-btc/crypto/litecoin.js.map +1 -1
  31. package/lib/families/bitcoin/wallet-btc/crypto/zec.d.ts.map +1 -1
  32. package/lib/families/bitcoin/wallet-btc/crypto/zec.js +3 -4
  33. package/lib/families/bitcoin/wallet-btc/crypto/zec.js.map +1 -1
  34. package/lib/families/bitcoin/wallet-btc/crypto/zen.d.ts.map +1 -1
  35. package/lib/families/bitcoin/wallet-btc/crypto/zen.js +3 -4
  36. package/lib/families/bitcoin/wallet-btc/crypto/zen.js.map +1 -1
  37. package/lib/families/bitcoin/wallet-btc/xpub.js +1 -1
  38. package/lib/families/bitcoin/wallet-btc/xpub.js.map +1 -1
  39. package/lib/families/ethereum/modules/send.d.ts.map +1 -1
  40. package/lib/families/ethereum/modules/send.js +3 -1
  41. package/lib/families/ethereum/modules/send.js.map +1 -1
  42. package/lib/families/tezos/bridge/js.d.ts.map +1 -1
  43. package/lib/families/tezos/bridge/js.js +19 -20
  44. package/lib/families/tezos/bridge/js.js.map +1 -1
  45. package/lib/families/tezos/hw-getAddress.d.ts.map +1 -1
  46. package/lib/families/tezos/hw-getAddress.js +1 -3
  47. package/lib/families/tezos/hw-getAddress.js.map +1 -1
  48. package/lib/families/tezos/synchronisation.d.ts.map +1 -1
  49. package/lib/families/tezos/synchronisation.js +1 -1
  50. package/lib/families/tezos/synchronisation.js.map +1 -1
  51. package/package.json +3 -3
  52. package/src/account/support.ts +1 -25
  53. package/src/api/Ethereum.ts +1 -4
  54. package/src/api/explorerConfig/index.ts +0 -4
  55. package/src/errors.ts +3 -0
  56. package/src/families/bitcoin/test-dataset.ts +1 -1
  57. package/src/families/bitcoin/wallet-btc/crypto/base.ts +41 -20
  58. package/src/families/bitcoin/wallet-btc/crypto/bitcoin.ts +12 -5
  59. package/src/families/bitcoin/wallet-btc/crypto/bitcoincash.ts +11 -4
  60. package/src/families/bitcoin/wallet-btc/crypto/decred.ts +11 -4
  61. package/src/families/bitcoin/wallet-btc/crypto/litecoin.ts +11 -4
  62. package/src/families/bitcoin/wallet-btc/crypto/zec.ts +11 -4
  63. package/src/families/bitcoin/wallet-btc/crypto/zen.ts +11 -4
  64. package/src/families/bitcoin/wallet-btc/xpub.ts +1 -1
  65. package/src/families/ethereum/modules/send.ts +3 -0
  66. package/src/families/tezos/bridge/js.ts +41 -40
  67. package/src/families/tezos/hw-getAddress.ts +1 -3
  68. package/src/families/tezos/synchronisation.ts +4 -3
  69. package/src/.DS_Store +0 -0
  70. package/src/__tests__/.DS_Store +0 -0
  71. package/src/currencies/__snapshots__/.DS_Store +0 -0
@@ -42,13 +42,13 @@ class Base implements ICrypto {
42
42
  }
43
43
 
44
44
  protected getPubkeyAt(xpub: string, account: number, index: number): Buffer {
45
- if (!Base.bech32Cache[xpub]) {
45
+ if (!Base.bech32Cache[`${this.network.name}-${xpub}`]) {
46
46
  const buffer: Buffer = bs58.decode(xpub);
47
47
  const depth: number = buffer[4];
48
48
  const i: number = buffer.readUInt32BE(9);
49
49
  const chainCode: Buffer = buffer.slice(13, 45);
50
50
  const publicKey: Buffer = buffer.slice(45, 78);
51
- Base.bech32Cache[xpub] = new BIP32(
51
+ Base.bech32Cache[`${this.network.name}-${xpub}`] = new BIP32(
52
52
  publicKey,
53
53
  chainCode,
54
54
  this.network,
@@ -56,20 +56,30 @@ class Base implements ICrypto {
56
56
  i
57
57
  );
58
58
  }
59
- if (Base.publickeyCache[`${xpub}-${account}-${index}`]) {
60
- return Base.publickeyCache[`${xpub}-${account}-${index}`];
59
+ if (
60
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}-${index}`]
61
+ ) {
62
+ return Base.publickeyCache[
63
+ `${this.network.name}-${xpub}-${account}-${index}`
64
+ ];
61
65
  }
62
- if (Base.publickeyCache[`${xpub}-${account}`]) {
66
+ if (Base.publickeyCache[`${this.network.name}-${xpub}-${account}`]) {
63
67
  const publicKey =
64
- Base.publickeyCache[`${xpub}-${account}`].derive(index).publicKey;
65
- Base.publickeyCache[`${xpub}-${account}-${index}`] = publicKey;
68
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}`].derive(
69
+ index
70
+ ).publicKey;
71
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}-${index}`] =
72
+ publicKey;
66
73
  return publicKey;
67
74
  }
68
- Base.publickeyCache[`${xpub}-${account}`] =
69
- Base.bech32Cache[xpub].derive(account);
75
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}`] =
76
+ Base.bech32Cache[`${this.network.name}-${xpub}`].derive(account);
70
77
  const publicKey =
71
- Base.publickeyCache[`${xpub}-${account}`].derive(index).publicKey;
72
- Base.publickeyCache[`${xpub}-${account}-${index}`] = publicKey;
78
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}`].derive(
79
+ index
80
+ ).publicKey;
81
+ Base.publickeyCache[`${this.network.name}-${xpub}-${account}-${index}`] =
82
+ publicKey;
73
83
  return publicKey;
74
84
  }
75
85
 
@@ -110,26 +120,37 @@ class Base implements ICrypto {
110
120
  account: number,
111
121
  index: number
112
122
  ): string {
113
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
114
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
123
+ if (
124
+ Base.addressCache[
125
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
126
+ ]
127
+ ) {
128
+ return Base.addressCache[
129
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
130
+ ];
115
131
  }
116
132
  switch (derivationMode) {
117
133
  case DerivationModes.LEGACY:
118
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
119
- this.getLegacyAddress(xpub, account, index);
134
+ Base.addressCache[
135
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
136
+ ] = this.getLegacyAddress(xpub, account, index);
120
137
  break;
121
138
  case DerivationModes.SEGWIT:
122
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
123
- this.getSegWitAddress(xpub, account, index);
139
+ Base.addressCache[
140
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
141
+ ] = this.getSegWitAddress(xpub, account, index);
124
142
  break;
125
143
  case DerivationModes.NATIVE_SEGWIT:
126
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
127
- this.getNativeSegWitAddress(xpub, account, index);
144
+ Base.addressCache[
145
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
146
+ ] = this.getNativeSegWitAddress(xpub, account, index);
128
147
  break;
129
148
  default:
130
149
  throw new Error(`Invalid derivation Mode: ${derivationMode}`);
131
150
  }
132
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
151
+ return Base.addressCache[
152
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
153
+ ];
133
154
  }
134
155
 
135
156
  // infer address type from its syntax
@@ -125,15 +125,22 @@ class Bitcoin extends Base {
125
125
  account: number,
126
126
  index: number
127
127
  ): string {
128
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
129
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
128
+ if (
129
+ Base.addressCache[
130
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
131
+ ]
132
+ ) {
133
+ return Base.addressCache[
134
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
135
+ ];
130
136
  }
131
137
  switch (derivationMode) {
132
138
  case DerivationModes.TAPROOT:
133
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
134
- this.getTaprootAddress(xpub, account, index);
139
+ Base.addressCache[
140
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
141
+ ] = this.getTaprootAddress(xpub, account, index);
135
142
  return Base.addressCache[
136
- `${derivationMode}-${xpub}-${account}-${index}`
143
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
137
144
  ];
138
145
  default:
139
146
  return super.getAddress(derivationMode, xpub, account, index);
@@ -47,12 +47,19 @@ class BitcoinCash implements ICrypto {
47
47
  account: number,
48
48
  index: number
49
49
  ): string {
50
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
51
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
50
+ if (
51
+ Base.addressCache[
52
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
53
+ ]
54
+ ) {
55
+ return Base.addressCache[
56
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
57
+ ];
52
58
  }
53
59
  const address = this.getLegacyBitcoinCashAddress(xpub, account, index);
54
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
55
- address;
60
+ Base.addressCache[
61
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
62
+ ] = address;
56
63
  return address;
57
64
  }
58
65
 
@@ -74,8 +74,14 @@ class Decred extends Base {
74
74
  account: number,
75
75
  index: number
76
76
  ): string {
77
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
78
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
77
+ if (
78
+ Base.addressCache[
79
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
80
+ ]
81
+ ) {
82
+ return Base.addressCache[
83
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
84
+ ];
79
85
  }
80
86
  let buffer: Buffer;
81
87
  try {
@@ -90,8 +96,9 @@ class Decred extends Base {
90
96
  const hd = new BIP32(X, chainCode, this.network, depth, i);
91
97
  const publicKey = hd.derive(account).derive(index).publicKey;
92
98
  const address = Decred.getAddressFromPk(publicKey);
93
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
94
- address;
99
+ Base.addressCache[
100
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
101
+ ] = address;
95
102
  return address;
96
103
  }
97
104
  }
@@ -59,8 +59,14 @@ class Litecoin extends Base implements ICrypto {
59
59
  account: number,
60
60
  index: number
61
61
  ): string {
62
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
63
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
62
+ if (
63
+ Base.addressCache[
64
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
65
+ ]
66
+ ) {
67
+ return Base.addressCache[
68
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
69
+ ];
64
70
  }
65
71
  let address: string;
66
72
  switch (derivationMode) {
@@ -76,8 +82,9 @@ class Litecoin extends Base implements ICrypto {
76
82
  default:
77
83
  throw new Error("Should not be reachable");
78
84
  }
79
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
80
- address;
85
+ Base.addressCache[
86
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
87
+ ] = address;
81
88
  return address;
82
89
  }
83
90
 
@@ -53,12 +53,19 @@ class ZCash implements ICrypto {
53
53
  account: number,
54
54
  index: number
55
55
  ): string {
56
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
57
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
56
+ if (
57
+ Base.addressCache[
58
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
59
+ ]
60
+ ) {
61
+ return Base.addressCache[
62
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
63
+ ];
58
64
  }
59
65
  const address = this.getLegacyAddress(xpub, account, index);
60
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
61
- address;
66
+ Base.addressCache[
67
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
68
+ ] = address;
62
69
  return address;
63
70
  }
64
71
 
@@ -73,12 +73,19 @@ class Zen implements ICrypto {
73
73
  account: number,
74
74
  index: number
75
75
  ): string {
76
- if (Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`]) {
77
- return Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`];
76
+ if (
77
+ Base.addressCache[
78
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
79
+ ]
80
+ ) {
81
+ return Base.addressCache[
82
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
83
+ ];
78
84
  }
79
85
  const address = this.getLegacyAddress(xpub, account, index);
80
- Base.addressCache[`${derivationMode}-${xpub}-${account}-${index}`] =
81
- address;
86
+ Base.addressCache[
87
+ `${this.network.name}-${derivationMode}-${xpub}-${account}-${index}`
88
+ ] = address;
82
89
  return address;
83
90
  }
84
91
 
@@ -67,7 +67,7 @@ class Xpub extends EventEmitter {
67
67
  );
68
68
 
69
69
  this.storage.addAddress(
70
- `${this.derivationMode}-${this.xpub}-${account}-${index}`,
70
+ `${this.crypto.network.name}-${this.derivationMode}-${this.xpub}-${account}-${index}`,
71
71
  address
72
72
  );
73
73
  await this.whenSynced("address", address);
@@ -189,6 +189,9 @@ const send: ModeModule = {
189
189
  ];
190
190
  }
191
191
  },
192
+
193
+ // This is resolution config is necessary for plugins like Lido and stuff cause they use the send mode
194
+ getResolutionConfig: () => ({ erc20: true, externalPlugins: true }),
192
195
  };
193
196
 
194
197
  function serializeTransactionData(
@@ -30,6 +30,7 @@ import { getEnv } from "../../../env";
30
30
  import { signOperation } from "../signOperation";
31
31
  import { patchOperationWithHash } from "../../../operation";
32
32
  import { log } from "@ledgerhq/logs";
33
+ import { InvalidAddressBecauseAlreadyDelegated } from "../../../errors";
33
34
 
34
35
  const receive = makeAccountBridgeReceive();
35
36
 
@@ -70,54 +71,52 @@ const getTransactionStatus = async (
70
71
  const { tezosResources } = account;
71
72
  if (!tezosResources) throw new Error("tezosResources is missing");
72
73
 
73
- if (!t.taquitoError) {
74
- if (t.mode !== "undelegate") {
75
- if (account.freshAddress === t.recipient) {
76
- errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
77
- } else {
78
- const { recipientError, recipientWarning } = await validateRecipient(
79
- account.currency,
80
- t.recipient
81
- );
74
+ if (t.mode !== "undelegate") {
75
+ if (account.freshAddress === t.recipient) {
76
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
77
+ } else {
78
+ const { recipientError, recipientWarning } = await validateRecipient(
79
+ account.currency,
80
+ t.recipient
81
+ );
82
82
 
83
- if (recipientError) {
84
- errors.recipient = recipientError;
85
- }
83
+ if (recipientError) {
84
+ errors.recipient = recipientError;
85
+ }
86
86
 
87
- if (recipientWarning) {
88
- warnings.recipient = recipientWarning;
89
- }
87
+ if (recipientWarning) {
88
+ warnings.recipient = recipientWarning;
90
89
  }
91
90
  }
91
+ }
92
92
 
93
- if (t.mode === "send") {
94
- if (!errors.amount && t.amount.eq(0)) {
95
- errors.amount = new AmountRequired();
96
- } else if (!errors.amount && t.amount.lt(0)) {
97
- errors.amount = new NotEnoughBalance();
98
- } else if (t.amount.gt(0) && estimatedFees.times(10).gt(t.amount)) {
99
- warnings.feeTooHigh = new FeeTooHigh();
100
- }
93
+ if (t.mode === "send") {
94
+ if (!errors.amount && t.amount.eq(0)) {
95
+ errors.amount = new AmountRequired();
96
+ } else if (!errors.amount && t.amount.lt(0)) {
97
+ errors.amount = new NotEnoughBalance();
98
+ } else if (t.amount.gt(0) && estimatedFees.times(10).gt(t.amount)) {
99
+ warnings.feeTooHigh = new FeeTooHigh();
100
+ }
101
101
 
102
- const thresholdWarning = 0.5 * 10 ** account.currency.units[0].magnitude;
103
-
104
- if (
105
- !errors.amount &&
106
- account.balance
107
- .minus(t.amount)
108
- .minus(estimatedFees)
109
- .lt(thresholdWarning)
110
- ) {
111
- if (isAccountDelegating(account)) {
112
- if (t.useAllAmount) {
113
- errors.amount = new RecommendUndelegation();
114
- } else {
115
- warnings.amount = new RecommendUndelegation();
116
- }
102
+ const thresholdWarning = 0.5 * 10 ** account.currency.units[0].magnitude;
103
+
104
+ if (
105
+ !errors.amount &&
106
+ account.balance.minus(t.amount).minus(estimatedFees).lt(thresholdWarning)
107
+ ) {
108
+ if (isAccountDelegating(account)) {
109
+ if (t.useAllAmount) {
110
+ errors.amount = new RecommendUndelegation();
111
+ } else {
112
+ warnings.amount = new RecommendUndelegation();
117
113
  }
118
114
  }
119
115
  }
120
- } else {
116
+ }
117
+
118
+ // if we also have taquitoError, we interprete them and they override the previously inferred errors
119
+ if (t.taquitoError) {
121
120
  log("taquitoerror", String(t.taquitoError));
122
121
 
123
122
  // remap taquito errors
@@ -127,7 +126,9 @@ const getTransactionStatus = async (
127
126
  } else {
128
127
  errors.amount = new NotEnoughBalanceToDelegate();
129
128
  }
130
- } else {
129
+ } else if (t.taquitoError.endsWith("delegate.unchanged")) {
130
+ errors.recipient = new InvalidAddressBecauseAlreadyDelegated();
131
+ } else if (!errors.amount) {
131
132
  // unidentified error case
132
133
  errors.amount = new Error(t.taquitoError);
133
134
  }
@@ -3,9 +3,7 @@ import type { Resolver } from "../../hw/getAddress/types";
3
3
 
4
4
  const resolver: Resolver = async (transport, { path, verify }) => {
5
5
  const xtz = new Xtz(transport);
6
- const r = await xtz.getAddress(path, {
7
- verify,
8
- });
6
+ const r = await xtz.getAddress(path, { verify });
9
7
  return { ...r, path };
10
8
  };
11
9
 
@@ -48,9 +48,10 @@ export const getAccountShape: GetAccountShape = async (infoInput) => {
48
48
  derivationMode,
49
49
  });
50
50
 
51
- const initialStableOperations = initialAccount
52
- ? initialAccount.operations
53
- : [];
51
+ const initialStableOperations =
52
+ initialAccount && initialAccount.id === accountId
53
+ ? initialAccount.operations
54
+ : [];
54
55
 
55
56
  // fetch transactions, incrementally if possible
56
57
  const mostRecentStableOperation = initialStableOperations[0];
package/src/.DS_Store DELETED
Binary file
Binary file