@ledgerhq/live-common 21.36.2 → 21.36.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 (35) hide show
  1. package/lib/bridge/jsHelpers.d.ts.map +1 -1
  2. package/lib/bridge/jsHelpers.js +238 -245
  3. package/lib/bridge/jsHelpers.js.map +1 -1
  4. package/lib/families/bitcoin/js-signOperation.d.ts.map +1 -1
  5. package/lib/families/bitcoin/js-signOperation.js +130 -139
  6. package/lib/families/bitcoin/js-signOperation.js.map +1 -1
  7. package/lib/families/crypto_org/js-signOperation.d.ts.map +1 -1
  8. package/lib/families/crypto_org/js-signOperation.js +55 -62
  9. package/lib/families/crypto_org/js-signOperation.js.map +1 -1
  10. package/lib/families/elrond/js-signOperation.d.ts.map +1 -1
  11. package/lib/families/elrond/js-signOperation.js +43 -50
  12. package/lib/families/elrond/js-signOperation.js.map +1 -1
  13. package/lib/families/polkadot/js-signOperation.d.ts.map +1 -1
  14. package/lib/families/polkadot/js-signOperation.js +54 -61
  15. package/lib/families/polkadot/js-signOperation.js.map +1 -1
  16. package/lib/families/ripple/bridge/js.d.ts.map +1 -1
  17. package/lib/families/ripple/bridge/js.js +299 -313
  18. package/lib/families/ripple/bridge/js.js.map +1 -1
  19. package/lib/families/stellar/js-signOperation.d.ts.map +1 -1
  20. package/lib/families/stellar/js-signOperation.js +44 -51
  21. package/lib/families/stellar/js-signOperation.js.map +1 -1
  22. package/lib/families/tron/bridge/js.d.ts.map +1 -1
  23. package/lib/families/tron/bridge/js.js +159 -167
  24. package/lib/families/tron/bridge/js.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/.DS_Store +0 -0
  27. package/src/bridge/jsHelpers.ts +213 -213
  28. package/src/data/flags/.DS_Store +0 -0
  29. package/src/families/bitcoin/js-signOperation.ts +14 -17
  30. package/src/families/crypto_org/js-signOperation.ts +12 -16
  31. package/src/families/elrond/js-signOperation.ts +10 -14
  32. package/src/families/polkadot/js-signOperation.ts +61 -61
  33. package/src/families/ripple/bridge/js.ts +257 -260
  34. package/src/families/stellar/js-signOperation.ts +10 -14
  35. package/src/families/tron/bridge/js.ts +57 -58
@@ -32,7 +32,7 @@ import type {
32
32
  AccountBridge,
33
33
  DeviceId,
34
34
  } from "../../../types/bridge";
35
- import { open, close } from "../../../hw";
35
+ import { withDevice } from "../../../hw/deviceAccess";
36
36
  import signTransaction from "../../../hw/signTransaction";
37
37
  import { makeSync, makeScanAccounts } from "../../../bridge/jsHelpers";
38
38
  import { formatCurrencyUnit } from "../../../currencies";
@@ -99,62 +99,63 @@ const signOperation = ({
99
99
  transaction: Transaction;
100
100
  deviceId: DeviceId;
101
101
  }): Observable<SignOperationEvent> =>
102
- Observable.create((o) => {
103
- async function main() {
104
- const subAccount =
105
- transaction.subAccountId && account.subAccounts
106
- ? account.subAccounts.find((sa) => sa.id === transaction.subAccountId)
107
- : null;
108
- const isContractAddressRecipient =
109
- (await fetchTronContract(transaction.recipient)) !== undefined;
110
- const fee = await getEstimatedFees(
111
- account,
112
- transaction,
113
- isContractAddressRecipient
114
- );
115
- const balance = subAccount
116
- ? subAccount.balance
117
- : BigNumber.max(0, account.spendableBalance.minus(fee));
118
- transaction.amount = transaction.useAllAmount
119
- ? balance
120
- : transaction.amount;
121
-
122
- // send trc20 to a new account is forbidden by us (because it will not activate the account)
123
- if (
124
- transaction.recipient &&
125
- transaction.mode === "send" &&
126
- subAccount &&
127
- subAccount.type === "TokenAccount" &&
128
- subAccount.token.tokenType === "trc20" &&
129
- !isContractAddressRecipient && // send trc20 to a smart contract is allowed
130
- (await fetchTronAccount(transaction.recipient)).length === 0
131
- ) {
132
- throw new TronSendTrc20ToNewAccountForbidden();
133
- }
102
+ withDevice(deviceId)((transport) =>
103
+ Observable.create((o) => {
104
+ async function main() {
105
+ const subAccount =
106
+ transaction.subAccountId && account.subAccounts
107
+ ? account.subAccounts.find(
108
+ (sa) => sa.id === transaction.subAccountId
109
+ )
110
+ : null;
111
+ const isContractAddressRecipient =
112
+ (await fetchTronContract(transaction.recipient)) !== undefined;
113
+ const fee = await getEstimatedFees(
114
+ account,
115
+ transaction,
116
+ isContractAddressRecipient
117
+ );
118
+ const balance = subAccount
119
+ ? subAccount.balance
120
+ : BigNumber.max(0, account.spendableBalance.minus(fee));
121
+ transaction.amount = transaction.useAllAmount
122
+ ? balance
123
+ : transaction.amount;
124
+
125
+ // send trc20 to a new account is forbidden by us (because it will not activate the account)
126
+ if (
127
+ transaction.recipient &&
128
+ transaction.mode === "send" &&
129
+ subAccount &&
130
+ subAccount.type === "TokenAccount" &&
131
+ subAccount.token.tokenType === "trc20" &&
132
+ !isContractAddressRecipient && // send trc20 to a smart contract is allowed
133
+ (await fetchTronAccount(transaction.recipient)).length === 0
134
+ ) {
135
+ throw new TronSendTrc20ToNewAccountForbidden();
136
+ }
134
137
 
135
- const getPreparedTransaction = () => {
136
- switch (transaction.mode) {
137
- case "freeze":
138
- return freezeTronTransaction(account, transaction);
138
+ const getPreparedTransaction = () => {
139
+ switch (transaction.mode) {
140
+ case "freeze":
141
+ return freezeTronTransaction(account, transaction);
139
142
 
140
- case "unfreeze":
141
- return unfreezeTronTransaction(account, transaction);
143
+ case "unfreeze":
144
+ return unfreezeTronTransaction(account, transaction);
142
145
 
143
- case "vote":
144
- return voteTronSuperRepresentatives(account, transaction);
146
+ case "vote":
147
+ return voteTronSuperRepresentatives(account, transaction);
145
148
 
146
- case "claimReward":
147
- return claimRewardTronTransaction(account);
149
+ case "claimReward":
150
+ return claimRewardTronTransaction(account);
148
151
 
149
- default:
150
- return createTronTransaction(account, transaction, subAccount);
151
- }
152
- };
152
+ default:
153
+ return createTronTransaction(account, transaction, subAccount);
154
+ }
155
+ };
153
156
 
154
- const preparedTransaction = await getPreparedTransaction();
155
- const transport = await open(deviceId);
157
+ const preparedTransaction = await getPreparedTransaction();
156
158
 
157
- try {
158
159
  o.next({
159
160
  type: "device-signature-requested",
160
161
  });
@@ -274,16 +275,14 @@ const signOperation = ({
274
275
  expirationDate: null,
275
276
  },
276
277
  });
277
- } finally {
278
- close(transport, deviceId);
279
278
  }
280
- }
281
279
 
282
- main().then(
283
- () => o.complete(),
284
- (e) => o.error(e)
285
- );
286
- });
280
+ main().then(
281
+ () => o.complete(),
282
+ (e) => o.error(e)
283
+ );
284
+ })
285
+ );
287
286
 
288
287
  const broadcast = async ({
289
288
  signedOperation: { signature, operation, signatureRaw },