@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
@@ -1,16 +1,16 @@
1
1
  import { BigNumber } from "bignumber.js";
2
2
  import { Observable } from "rxjs";
3
+ import { utils } from "@crypto-com/chain-jslib";
3
4
  import { FeeNotLoaded } from "@ledgerhq/errors";
5
+ import CryptoOrgApp from "@ledgerhq/hw-app-cosmos";
4
6
  import {
5
7
  CryptoOrgWrongSignatureHeader,
6
8
  CryptoOrgSignatureSize,
7
9
  } from "./errors";
8
10
  import type { Transaction } from "./types";
9
11
  import type { Account, Operation, SignOperationEvent } from "../../types";
10
- import { open, close } from "../../hw";
11
12
  import { encodeOperationId } from "../../operation";
12
- import CryptoOrgApp from "@ledgerhq/hw-app-cosmos";
13
- import { utils } from "@crypto-com/chain-jslib";
13
+ import { withDevice } from "../../hw/deviceAccess";
14
14
  import { buildTransaction } from "./js-buildTransaction";
15
15
  import { isTestNet } from "./logic";
16
16
 
@@ -104,11 +104,9 @@ const signOperation = ({
104
104
  deviceId: any;
105
105
  transaction: Transaction;
106
106
  }): Observable<SignOperationEvent> =>
107
- Observable.create((o) => {
108
- async function main() {
109
- const transport = await open(deviceId);
110
-
111
- try {
107
+ withDevice(deviceId)((transport) =>
108
+ Observable.create((o) => {
109
+ async function main() {
112
110
  o.next({
113
111
  type: "device-signature-requested",
114
112
  });
@@ -165,15 +163,13 @@ const signOperation = ({
165
163
  },
166
164
  });
167
165
  }
168
- } finally {
169
- close(transport, deviceId);
170
166
  }
171
- }
172
167
 
173
- main().then(
174
- () => o.complete(),
175
- (e) => o.error(e)
176
- );
177
- });
168
+ main().then(
169
+ () => o.complete(),
170
+ (e) => o.error(e)
171
+ );
172
+ })
173
+ );
178
174
 
179
175
  export default signOperation;
@@ -3,7 +3,7 @@ import { Observable } from "rxjs";
3
3
  import { FeeNotLoaded } from "@ledgerhq/errors";
4
4
  import type { Transaction } from "./types";
5
5
  import type { Account, Operation, SignOperationEvent } from "../../types";
6
- import { open, close } from "../../hw";
6
+ import { withDevice } from "../../hw/deviceAccess";
7
7
  import { encodeOperationId } from "../../operation";
8
8
  import Elrond from "./hw-app-elrond";
9
9
  import { buildTransaction } from "./js-buildTransaction";
@@ -48,11 +48,9 @@ const signOperation = ({
48
48
  deviceId: any;
49
49
  transaction: Transaction;
50
50
  }): Observable<SignOperationEvent> =>
51
- Observable.create((o) => {
52
- async function main() {
53
- const transport = await open(deviceId);
54
-
55
- try {
51
+ withDevice(deviceId)((transport) =>
52
+ Observable.create((o) => {
53
+ async function main() {
56
54
  if (!transaction.fees) {
57
55
  throw new FeeNotLoaded();
58
56
  }
@@ -89,15 +87,13 @@ const signOperation = ({
89
87
  expirationDate: null,
90
88
  },
91
89
  });
92
- } finally {
93
- close(transport, deviceId);
94
90
  }
95
- }
96
91
 
97
- main().then(
98
- () => o.complete(),
99
- (e) => o.error(e)
100
- );
101
- });
92
+ main().then(
93
+ () => o.complete(),
94
+ (e) => o.error(e)
95
+ );
96
+ })
97
+ );
102
98
 
103
99
  export default signOperation;
@@ -11,7 +11,7 @@ import type {
11
11
  OperationType,
12
12
  SignOperationEvent,
13
13
  } from "../../types";
14
- import { open, close } from "../../hw";
14
+ import { withDevice } from "../../hw/deviceAccess";
15
15
  import { encodeOperationId } from "../../operation";
16
16
  import { buildTransaction } from "./js-buildTransaction";
17
17
  import { calculateAmount, getNonce, isFirstBond } from "./logic";
@@ -157,69 +157,69 @@ const signOperation = ({
157
157
  deviceId: any;
158
158
  transaction: Transaction;
159
159
  }): Observable<SignOperationEvent> =>
160
- new Observable((o) => {
161
- async function main() {
162
- const transport = await open(deviceId);
163
-
164
- try {
165
- o.next({
166
- type: "device-signature-requested",
167
- });
160
+ withDevice(deviceId)(
161
+ (transport) =>
162
+ new Observable((o) => {
163
+ async function main() {
164
+ o.next({
165
+ type: "device-signature-requested",
166
+ });
168
167
 
169
- if (!transaction.fees) {
170
- throw new FeeNotLoaded();
168
+ if (!transaction.fees) {
169
+ throw new FeeNotLoaded();
170
+ }
171
+
172
+ // Ensure amount is filled when useAllAmount
173
+ const transactionToSign = {
174
+ ...transaction,
175
+ amount: calculateAmount({
176
+ a: account,
177
+ t: transaction,
178
+ }),
179
+ };
180
+ const { unsigned, registry } = await buildTransaction(
181
+ account,
182
+ transactionToSign,
183
+ true
184
+ );
185
+ const payload = registry
186
+ .createType("ExtrinsicPayload", unsigned, {
187
+ version: unsigned.version,
188
+ })
189
+ .toU8a({
190
+ method: true,
191
+ });
192
+ // Sign by device
193
+ const polkadot = new Polkadot(transport);
194
+ // FIXME: the type of payload Uint8Array is not compatible with the signature of sign which accept a string
195
+ const r = await polkadot.sign(
196
+ account.freshAddressPath,
197
+ payload as any
198
+ );
199
+ const signed = await signExtrinsic(unsigned, r.signature, registry);
200
+ o.next({
201
+ type: "device-signature-granted",
202
+ });
203
+ const operation = buildOptimisticOperation(
204
+ account,
205
+ transactionToSign,
206
+ transactionToSign.fees ?? new BigNumber(0)
207
+ );
208
+ o.next({
209
+ type: "signed",
210
+ signedOperation: {
211
+ operation,
212
+ signature: signed,
213
+ expirationDate: null,
214
+ },
215
+ });
171
216
  }
172
217
 
173
- // Ensure amount is filled when useAllAmount
174
- const transactionToSign = {
175
- ...transaction,
176
- amount: calculateAmount({
177
- a: account,
178
- t: transaction,
179
- }),
180
- };
181
- const { unsigned, registry } = await buildTransaction(
182
- account,
183
- transactionToSign,
184
- true
185
- );
186
- const payload = registry
187
- .createType("ExtrinsicPayload", unsigned, {
188
- version: unsigned.version,
189
- })
190
- .toU8a({
191
- method: true,
192
- });
193
- // Sign by device
194
- const polkadot = new Polkadot(transport);
195
- // FIXME: the type of payload Uint8Array is not compatible with the signature of sign which accept a string
196
- const r = await polkadot.sign(account.freshAddressPath, payload as any);
197
- const signed = await signExtrinsic(unsigned, r.signature, registry);
198
- o.next({
199
- type: "device-signature-granted",
200
- });
201
- const operation = buildOptimisticOperation(
202
- account,
203
- transactionToSign,
204
- transactionToSign.fees ?? new BigNumber(0)
218
+ main().then(
219
+ () => o.complete(),
220
+ (e) => o.error(e)
205
221
  );
206
- o.next({
207
- type: "signed",
208
- signedOperation: {
209
- operation,
210
- signature: signed,
211
- expirationDate: null,
212
- },
213
- });
214
- } finally {
215
- close(transport, deviceId);
216
- }
217
- }
218
-
219
- main().then(
220
- () => o.complete(),
221
- (e) => o.error(e)
222
- );
223
- });
222
+ })
223
+ );
224
224
 
225
225
  export default signOperation;