@ledgerhq/device-transport-kit-react-native-hid 0.0.0-rn-hid-improvements-explorations-20250523153215 → 0.0.0-rn-ble-pairing-removed-while-reconnecting-20250731133348
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/android/src/main/kotlin/com/ledger/androidtransporthid/BridgeEvents.kt +0 -3
- package/android/src/main/kotlin/com/ledger/androidtransporthid/TransportHidModule.kt +3 -70
- package/android/src/main/kotlin/com/ledger/androidtransporthid/bridge/serialization.kt +0 -10
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/DefaultAndroidUsbTransport.kt +14 -84
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/connection/AndroidUsbApduSender.kt +31 -85
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceApduSender.kt +1 -2
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnection.kt +4 -5
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionStateMachine.kt +3 -4
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/api/apdu/SendApduResult.kt +0 -4
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/api/discovery/DiscoveryDevice.kt +1 -1
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/internal/connection/InternalConnectedDevice.kt +1 -1
- package/android/src/test/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionStateMachineTest.kt +31 -47
- package/android/src/test/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionTest.kt +5 -9
- package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js +1 -1
- package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
- package/lib/cjs/api/bridge/StubNativeModuleWrapper.js +1 -1
- package/lib/cjs/api/bridge/StubNativeModuleWrapper.js.map +2 -2
- package/lib/cjs/api/bridge/mapper.js +1 -1
- package/lib/cjs/api/bridge/mapper.js.map +2 -2
- package/lib/cjs/api/bridge/mapper.test.js +1 -1
- package/lib/cjs/api/bridge/mapper.test.js.map +2 -2
- package/lib/cjs/api/bridge/types.js +1 -1
- package/lib/cjs/api/bridge/types.js.map +3 -3
- package/lib/cjs/api/transport/Errors.js +1 -1
- package/lib/cjs/api/transport/Errors.js.map +3 -3
- package/lib/cjs/api/transport/NativeModuleWrapper.js +1 -1
- package/lib/cjs/api/transport/NativeModuleWrapper.js.map +1 -1
- package/lib/cjs/api/transport/RNHidTransport.js +1 -1
- package/lib/cjs/api/transport/RNHidTransport.js.map +3 -3
- package/lib/cjs/api/transport/RNHidTransport.test.js +1 -1
- package/lib/cjs/api/transport/RNHidTransport.test.js.map +2 -2
- package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js +1 -1
- package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
- package/lib/esm/api/bridge/StubNativeModuleWrapper.js +1 -1
- package/lib/esm/api/bridge/StubNativeModuleWrapper.js.map +2 -2
- package/lib/esm/api/bridge/mapper.js +1 -1
- package/lib/esm/api/bridge/mapper.js.map +3 -3
- package/lib/esm/api/bridge/mapper.test.js +1 -1
- package/lib/esm/api/bridge/mapper.test.js.map +3 -3
- package/lib/esm/api/bridge/types.js +1 -1
- package/lib/esm/api/bridge/types.js.map +3 -3
- package/lib/esm/api/transport/Errors.js +1 -1
- package/lib/esm/api/transport/Errors.js.map +3 -3
- package/lib/esm/api/transport/RNHidTransport.js +1 -1
- package/lib/esm/api/transport/RNHidTransport.js.map +3 -3
- package/lib/esm/api/transport/RNHidTransport.test.js +1 -1
- package/lib/esm/api/transport/RNHidTransport.test.js.map +3 -3
- package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts +1 -4
- package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts.map +1 -1
- package/lib/types/api/bridge/StubNativeModuleWrapper.d.ts +0 -5
- package/lib/types/api/bridge/StubNativeModuleWrapper.d.ts.map +1 -1
- package/lib/types/api/bridge/mapper.d.ts.map +1 -1
- package/lib/types/api/bridge/types.d.ts +2 -9
- package/lib/types/api/bridge/types.d.ts.map +1 -1
- package/lib/types/api/transport/Errors.d.ts +1 -1
- package/lib/types/api/transport/Errors.d.ts.map +1 -1
- package/lib/types/api/transport/NativeModuleWrapper.d.ts +1 -4
- package/lib/types/api/transport/NativeModuleWrapper.d.ts.map +1 -1
- package/lib/types/api/transport/RNHidTransport.d.ts +0 -2
- package/lib/types/api/transport/RNHidTransport.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -25,7 +25,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
25
25
|
var sendApduResult: SendApduResult? = null
|
|
26
26
|
|
|
27
27
|
val stateMachine = DeviceConnectionStateMachine(
|
|
28
|
-
sendApduFn = { apdu
|
|
28
|
+
sendApduFn = { apdu -> sendApduCalled = apdu },
|
|
29
29
|
onTerminated = { terminated = true },
|
|
30
30
|
isFatalSendApduFailure = { false },
|
|
31
31
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -38,8 +38,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
38
38
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
39
39
|
apdu = mockedRequestApduA,
|
|
40
40
|
triggersDisconnection = false,
|
|
41
|
-
resultCallback = { result -> sendApduResult = result }
|
|
42
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
41
|
+
resultCallback = { result -> sendApduResult = result }
|
|
43
42
|
))
|
|
44
43
|
assertArrayEquals(mockedRequestApduA, sendApduCalled)
|
|
45
44
|
|
|
@@ -66,7 +65,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
66
65
|
var error: Throwable? = null
|
|
67
66
|
|
|
68
67
|
val stateMachine = DeviceConnectionStateMachine(
|
|
69
|
-
sendApduFn = {
|
|
68
|
+
sendApduFn = { },
|
|
70
69
|
onTerminated = { terminated = true },
|
|
71
70
|
isFatalSendApduFailure = { true }, // All failures are fatal
|
|
72
71
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -78,8 +77,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
78
77
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
79
78
|
apdu = mockedRequestApduA,
|
|
80
79
|
triggersDisconnection = false,
|
|
81
|
-
resultCallback = { result -> sendApduResult = result }
|
|
82
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
80
|
+
resultCallback = { result -> sendApduResult = result }
|
|
83
81
|
))
|
|
84
82
|
|
|
85
83
|
// Simulate a failure
|
|
@@ -101,7 +99,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
101
99
|
var error: Throwable? = null
|
|
102
100
|
|
|
103
101
|
val stateMachine = DeviceConnectionStateMachine(
|
|
104
|
-
sendApduFn = {
|
|
102
|
+
sendApduFn = { },
|
|
105
103
|
onTerminated = { terminated = true },
|
|
106
104
|
isFatalSendApduFailure = { false },
|
|
107
105
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -114,8 +112,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
114
112
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
115
113
|
apdu = mockedRequestApduA,
|
|
116
114
|
triggersDisconnection = false,
|
|
117
|
-
resultCallback = { result -> sendApduResult = result }
|
|
118
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
115
|
+
resultCallback = { result -> sendApduResult = result }
|
|
119
116
|
))
|
|
120
117
|
|
|
121
118
|
// Simulate a failure
|
|
@@ -143,7 +140,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
143
140
|
|
|
144
141
|
val dispatcher = StandardTestDispatcher(testScheduler)
|
|
145
142
|
val stateMachine = DeviceConnectionStateMachine(
|
|
146
|
-
sendApduFn = { apdu
|
|
143
|
+
sendApduFn = { apdu -> sendApduCalled = apdu },
|
|
147
144
|
onTerminated = { terminated = true },
|
|
148
145
|
isFatalSendApduFailure = { false },
|
|
149
146
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -156,8 +153,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
156
153
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
157
154
|
apdu = mockedRequestApduA,
|
|
158
155
|
triggersDisconnection = true,
|
|
159
|
-
resultCallback = { result -> sendApduResult = result }
|
|
160
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
156
|
+
resultCallback = { result -> sendApduResult = result }
|
|
161
157
|
))
|
|
162
158
|
|
|
163
159
|
// Send APDU should have been called
|
|
@@ -184,8 +180,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
184
180
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
185
181
|
apdu = mockedRequestApduB,
|
|
186
182
|
triggersDisconnection = false,
|
|
187
|
-
resultCallback = { secondSendApduResult = it }
|
|
188
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
183
|
+
resultCallback = { secondSendApduResult = it }
|
|
189
184
|
))
|
|
190
185
|
|
|
191
186
|
// Send APDU should have been called
|
|
@@ -210,7 +205,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
210
205
|
var error: Throwable? = null
|
|
211
206
|
|
|
212
207
|
val stateMachine = DeviceConnectionStateMachine(
|
|
213
|
-
sendApduFn = { apdu
|
|
208
|
+
sendApduFn = { apdu -> sendApduCalled += apdu },
|
|
214
209
|
onTerminated = { terminated = true },
|
|
215
210
|
isFatalSendApduFailure = { false },
|
|
216
211
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -223,8 +218,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
223
218
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
224
219
|
apdu = mockedRequestApduA,
|
|
225
220
|
triggersDisconnection = true,
|
|
226
|
-
resultCallback = { }
|
|
227
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
221
|
+
resultCallback = { }
|
|
228
222
|
))
|
|
229
223
|
|
|
230
224
|
// Simulate a successful response
|
|
@@ -245,8 +239,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
245
239
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
246
240
|
apdu = mockedRequestApduB,
|
|
247
241
|
triggersDisconnection = false,
|
|
248
|
-
resultCallback = { secondSendApduResult = it }
|
|
249
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
242
|
+
resultCallback = { secondSendApduResult = it }
|
|
250
243
|
))
|
|
251
244
|
|
|
252
245
|
// Should be in waiting state
|
|
@@ -296,7 +289,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
296
289
|
var error: Throwable? = null
|
|
297
290
|
|
|
298
291
|
val stateMachine = DeviceConnectionStateMachine(
|
|
299
|
-
sendApduFn = {
|
|
292
|
+
sendApduFn = { },
|
|
300
293
|
onTerminated = { terminated = true },
|
|
301
294
|
isFatalSendApduFailure = { false },
|
|
302
295
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -309,8 +302,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
309
302
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
310
303
|
apdu = mockedRequestApduA,
|
|
311
304
|
triggersDisconnection = false,
|
|
312
|
-
resultCallback = { result -> sendApduResult = result }
|
|
313
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
305
|
+
resultCallback = { result -> sendApduResult = result }
|
|
314
306
|
))
|
|
315
307
|
|
|
316
308
|
// Should be in sending state
|
|
@@ -339,7 +331,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
339
331
|
var error: Throwable? = null
|
|
340
332
|
|
|
341
333
|
val stateMachine = DeviceConnectionStateMachine(
|
|
342
|
-
sendApduFn = {
|
|
334
|
+
sendApduFn = { },
|
|
343
335
|
onTerminated = { terminated = true },
|
|
344
336
|
isFatalSendApduFailure = { false },
|
|
345
337
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -352,8 +344,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
352
344
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
353
345
|
apdu = mockedRequestApduA,
|
|
354
346
|
triggersDisconnection = false,
|
|
355
|
-
resultCallback = { result -> sendApduResult = result }
|
|
356
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
347
|
+
resultCallback = { result -> sendApduResult = result }
|
|
357
348
|
))
|
|
358
349
|
|
|
359
350
|
// Simulate a disconnection
|
|
@@ -393,7 +384,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
393
384
|
var error: Throwable? = null
|
|
394
385
|
|
|
395
386
|
val stateMachine = DeviceConnectionStateMachine(
|
|
396
|
-
sendApduFn = {
|
|
387
|
+
sendApduFn = { },
|
|
397
388
|
onTerminated = { terminated = true },
|
|
398
389
|
isFatalSendApduFailure = { false },
|
|
399
390
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -406,8 +397,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
406
397
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
407
398
|
apdu = mockedRequestApduA,
|
|
408
399
|
triggersDisconnection = false,
|
|
409
|
-
resultCallback = { firstSendApduResult = it }
|
|
410
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
400
|
+
resultCallback = { firstSendApduResult = it }
|
|
411
401
|
))
|
|
412
402
|
|
|
413
403
|
// Should be in sending state.
|
|
@@ -420,8 +410,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
420
410
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
421
411
|
apdu = mockedRequestApduB,
|
|
422
412
|
triggersDisconnection = false,
|
|
423
|
-
resultCallback = { secondSendApduResult = it }
|
|
424
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
413
|
+
resultCallback = { secondSendApduResult = it }
|
|
425
414
|
))
|
|
426
415
|
|
|
427
416
|
assertEquals(
|
|
@@ -446,7 +435,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
446
435
|
var terminated = false
|
|
447
436
|
|
|
448
437
|
val stateMachine = DeviceConnectionStateMachine(
|
|
449
|
-
sendApduFn = {
|
|
438
|
+
sendApduFn = { },
|
|
450
439
|
onTerminated = { terminated = true },
|
|
451
440
|
isFatalSendApduFailure = { false },
|
|
452
441
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -483,7 +472,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
483
472
|
var terminated = false
|
|
484
473
|
|
|
485
474
|
val stateMachine = DeviceConnectionStateMachine(
|
|
486
|
-
sendApduFn = {
|
|
475
|
+
sendApduFn = { },
|
|
487
476
|
onTerminated = { terminated = true },
|
|
488
477
|
isFatalSendApduFailure = { false },
|
|
489
478
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -518,7 +507,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
518
507
|
var error: Throwable? = null
|
|
519
508
|
|
|
520
509
|
val stateMachine = DeviceConnectionStateMachine(
|
|
521
|
-
sendApduFn = { apdu
|
|
510
|
+
sendApduFn = { apdu -> sendApduCalled = apdu },
|
|
522
511
|
onTerminated = { terminated = true },
|
|
523
512
|
isFatalSendApduFailure = { false },
|
|
524
513
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -534,8 +523,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
534
523
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
535
524
|
apdu = mockedRequestApduA,
|
|
536
525
|
triggersDisconnection = false,
|
|
537
|
-
resultCallback = { sendApduResult = it }
|
|
538
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
526
|
+
resultCallback = { sendApduResult = it }
|
|
539
527
|
))
|
|
540
528
|
|
|
541
529
|
// Send APDU should not have been called
|
|
@@ -564,7 +552,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
564
552
|
var error: Throwable? = null
|
|
565
553
|
|
|
566
554
|
val stateMachine = DeviceConnectionStateMachine(
|
|
567
|
-
sendApduFn = {
|
|
555
|
+
sendApduFn = { },
|
|
568
556
|
onTerminated = { terminated = true },
|
|
569
557
|
isFatalSendApduFailure = { false },
|
|
570
558
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -580,8 +568,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
580
568
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
581
569
|
apdu = mockedRequestApduA,
|
|
582
570
|
triggersDisconnection = false,
|
|
583
|
-
resultCallback = { result -> sendApduResult = result }
|
|
584
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
571
|
+
resultCallback = { result -> sendApduResult = result }
|
|
585
572
|
))
|
|
586
573
|
|
|
587
574
|
// Request closing the connection
|
|
@@ -605,7 +592,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
605
592
|
var error: Throwable? = null
|
|
606
593
|
|
|
607
594
|
val stateMachine = DeviceConnectionStateMachine(
|
|
608
|
-
sendApduFn = {
|
|
595
|
+
sendApduFn = { },
|
|
609
596
|
onTerminated = { terminated = true },
|
|
610
597
|
isFatalSendApduFailure = { false },
|
|
611
598
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -621,8 +608,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
621
608
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
622
609
|
apdu = byteArrayOf(0x0A),
|
|
623
610
|
triggersDisconnection = false,
|
|
624
|
-
resultCallback = { result -> sendApduResult = result }
|
|
625
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
611
|
+
resultCallback = { result -> sendApduResult = result }
|
|
626
612
|
))
|
|
627
613
|
|
|
628
614
|
// Simulate timeout
|
|
@@ -645,7 +631,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
645
631
|
var error: Throwable? = null
|
|
646
632
|
|
|
647
633
|
val stateMachine = DeviceConnectionStateMachine(
|
|
648
|
-
sendApduFn = {
|
|
634
|
+
sendApduFn = { },
|
|
649
635
|
onTerminated = { terminated = true },
|
|
650
636
|
isFatalSendApduFailure = { false },
|
|
651
637
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -661,16 +647,14 @@ class DeviceConnectionStateMachineTest {
|
|
|
661
647
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
662
648
|
apdu = byteArrayOf(0x0A),
|
|
663
649
|
triggersDisconnection = false,
|
|
664
|
-
resultCallback = { firstSendApduResult = it }
|
|
665
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
650
|
+
resultCallback = { firstSendApduResult = it }
|
|
666
651
|
))
|
|
667
652
|
|
|
668
653
|
// Second APDU sending request
|
|
669
654
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
670
655
|
apdu = byteArrayOf(0x0B),
|
|
671
656
|
triggersDisconnection = false,
|
|
672
|
-
resultCallback = { secondSendApduResult = it }
|
|
673
|
-
abortTimeoutDuration = Duration.INFINITE
|
|
657
|
+
resultCallback = { secondSendApduResult = it }
|
|
674
658
|
))
|
|
675
659
|
|
|
676
660
|
// Second request should immediately return busy.
|
|
@@ -699,7 +683,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
699
683
|
var errorCalled: Throwable? = null
|
|
700
684
|
|
|
701
685
|
val stateMachine = DeviceConnectionStateMachine(
|
|
702
|
-
sendApduFn = {
|
|
686
|
+
sendApduFn = { },
|
|
703
687
|
onTerminated = { },
|
|
704
688
|
isFatalSendApduFailure = { false },
|
|
705
689
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -11,7 +11,6 @@ import kotlinx.coroutines.test.runTest
|
|
|
11
11
|
import kotlin.time.Duration.Companion.seconds
|
|
12
12
|
import kotlin.test.Test
|
|
13
13
|
import org.junit.Assert.*
|
|
14
|
-
import kotlin.time.Duration
|
|
15
14
|
import kotlin.time.Duration.Companion.milliseconds
|
|
16
15
|
|
|
17
16
|
/**
|
|
@@ -35,7 +34,7 @@ class DeviceConnectionTest {
|
|
|
35
34
|
)
|
|
36
35
|
|
|
37
36
|
// Request sending an APDU
|
|
38
|
-
deviceConnection.requestSendApdu(
|
|
37
|
+
deviceConnection.requestSendApdu(mockedApdu)
|
|
39
38
|
|
|
40
39
|
// Send APDU should have been called once with the correct apdu
|
|
41
40
|
assertEquals(1, apduSender.sendCalls.size)
|
|
@@ -60,7 +59,7 @@ class DeviceConnectionTest {
|
|
|
60
59
|
)
|
|
61
60
|
|
|
62
61
|
// Request sending an apdu
|
|
63
|
-
val result1 = deviceConnection.requestSendApdu(
|
|
62
|
+
val result1 = deviceConnection.requestSendApdu(apduTriggeringDisconnection)
|
|
64
63
|
|
|
65
64
|
// apduSender1.sendApdu should have been called once with the correct apdu
|
|
66
65
|
assertEquals(1, apduSender1.sendCalls.size)
|
|
@@ -71,7 +70,7 @@ class DeviceConnectionTest {
|
|
|
71
70
|
|
|
72
71
|
// Request sending a second apdu
|
|
73
72
|
val result2 = async {
|
|
74
|
-
deviceConnection.requestSendApdu(
|
|
73
|
+
deviceConnection.requestSendApdu(mockedApdu)
|
|
75
74
|
}
|
|
76
75
|
|
|
77
76
|
// apduSender1.sendApdu shouldn't have been called again
|
|
@@ -140,7 +139,7 @@ class DeviceConnectionTest {
|
|
|
140
139
|
|
|
141
140
|
// Request sending an APDU
|
|
142
141
|
val result = async {
|
|
143
|
-
deviceConnection.requestSendApdu(
|
|
142
|
+
deviceConnection.requestSendApdu(mockedApdu)
|
|
144
143
|
}
|
|
145
144
|
|
|
146
145
|
// Simulate reconnection
|
|
@@ -203,10 +202,7 @@ class DeviceConnectionTest {
|
|
|
203
202
|
val sendCalls: MutableList<ByteArray>
|
|
204
203
|
get() = _sendCalls
|
|
205
204
|
|
|
206
|
-
override suspend fun send(
|
|
207
|
-
apdu: ByteArray,
|
|
208
|
-
abortTimeoutDuration: Duration
|
|
209
|
-
): SendApduResult {
|
|
205
|
+
override suspend fun send(apdu: ByteArray): SendApduResult {
|
|
210
206
|
_sendCalls += apdu
|
|
211
207
|
return nextResult
|
|
212
208
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var m=(i,e)=>{for(var t in e)d(i,t,{get:e[t],enumerable:!0})},E=(i,e,t,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of p(e))!D.call(i,n)&&n!==t&&d(i,n,{get:()=>e[n],enumerable:!(o=l(e,n))||o.enumerable});return i};var y=i=>E(d({},"__esModule",{value:!0}),i);var T={};m(T,{DefaultNativeModuleWrapper:()=>M});module.exports=y(T);var s=require("react-native"),c=require("rxjs"),u=require("../helpers/base64Utils"),r=require("./mapper"),a=require("./types");class M{_nativeModule;_deviceModelDataSource;constructor(e){this._nativeModule=e.nativeModule,this._deviceModelDataSource=e.deviceModelDataSource}startScan(){return this._nativeModule.startScan()}stopScan(){return this._nativeModule.stopScan()}subscribeToDiscoveredDevicesEvents(){return new c.Observable(e=>{const o=new s.NativeEventEmitter(this._nativeModule).addListener(a.DISCOVERED_DEVICES_EVENT,n=>{e.next(n.map(v=>(0,r.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(v,this._deviceModelDataSource)).filter(v=>v!==null))});return()=>{o.remove()}})}subscribeToDeviceDisconnectedEvents(){return new c.Observable(e=>{const o=new s.NativeEventEmitter(this._nativeModule).addListener(a.DEVICE_DISCONNECTED_EVENT,n=>{e.next((0,r.mapNativeDeviceConnectionLostToDeviceDisconnected)(n))});return()=>{o.remove()}})}subscribeToTransportLogs(){return new c.Observable(e=>{const o=new s.NativeEventEmitter(this._nativeModule).addListener(a.TRANSPORT_LOG_EVENT,n=>{e.next((0,r.mapNativeTransportLogToLog)(n))});return()=>{o.remove()}})}async connectDevice(e){const t=await this._nativeModule.connectDevice(e);return(0,r.mapNativeConnectionResultToConnectionResult)(t,this._deviceModelDataSource)}async disconnectDevice(e){return this._nativeModule.disconnectDevice(e)}async sendApdu(e,t){const o=await this._nativeModule.sendApdu(e,(0,u.uint8ArrayToBase64)(t));return(0,r.mapNativeSendApduResultToSendApduResult)(o)}}0&&(module.exports={DefaultNativeModuleWrapper});
|
|
2
2
|
//# sourceMappingURL=DefaultNativeModuleWrapper.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/DefaultNativeModuleWrapper.ts"],
|
|
4
|
-
"sourcesContent": ["import { NativeEventEmitter } from \"react-native\";\nimport {\n type DeviceModelDataSource,\n type LogParams,\n type SendApduResult,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Observable } from \"rxjs\";\n\nimport { uint8ArrayToBase64 } from \"@api/helpers/base64Utils\";\nimport { type NativeModuleWrapper } from \"@api/transport/NativeModuleWrapper\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n DEVICE_DISCONNECTED_EVENT,\n type DeviceDisconnectedEventPayload,\n DISCOVERED_DEVICES_EVENT,\n type DiscoveredDevicesEventPayload,\n
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,wBAOnCC,EAA2B,gBAE3BC,EAAmC,oCAOnCC,EAMO,oBACPC,
|
|
6
|
-
"names": ["DefaultNativeModuleWrapper_exports", "__export", "DefaultNativeModuleWrapper", "__toCommonJS", "import_react_native", "import_rxjs", "import_base64Utils", "import_mapper", "import_types", "args", "subscriber", "eventListener", "discoveredDevices", "device", "d", "logParams", "
|
|
4
|
+
"sourcesContent": ["import { NativeEventEmitter } from \"react-native\";\nimport {\n type DeviceModelDataSource,\n type LogParams,\n type SendApduResult,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Observable } from \"rxjs\";\n\nimport { uint8ArrayToBase64 } from \"@api/helpers/base64Utils\";\nimport { type NativeModuleWrapper } from \"@api/transport/NativeModuleWrapper\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n DEVICE_DISCONNECTED_EVENT,\n type DeviceDisconnectedEventPayload,\n DISCOVERED_DEVICES_EVENT,\n type DiscoveredDevicesEventPayload,\n type NativeLog,\n TRANSPORT_LOG_EVENT,\n} from \"./types\";\nimport { type NativeTransportModuleType } from \"./types\";\n\nexport class DefaultNativeModuleWrapper implements NativeModuleWrapper {\n private readonly _nativeModule: NativeTransportModuleType;\n private readonly _deviceModelDataSource: DeviceModelDataSource;\n\n constructor(args: {\n nativeModule: NativeTransportModuleType;\n deviceModelDataSource: DeviceModelDataSource;\n }) {\n this._nativeModule = args.nativeModule;\n this._deviceModelDataSource = args.deviceModelDataSource;\n }\n\n startScan() {\n return this._nativeModule.startScan();\n }\n\n stopScan() {\n return this._nativeModule.stopScan();\n }\n\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n > {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n DISCOVERED_DEVICES_EVENT,\n (discoveredDevices: DiscoveredDevicesEventPayload) => {\n subscriber.next(\n discoveredDevices\n .map((device) =>\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n device,\n this._deviceModelDataSource,\n ),\n )\n .filter((d) => d !== null),\n );\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected> {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n DEVICE_DISCONNECTED_EVENT,\n (device: DeviceDisconnectedEventPayload) => {\n subscriber.next(\n mapNativeDeviceConnectionLostToDeviceDisconnected(device),\n );\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n subscribeToTransportLogs(): Observable<LogParams> {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n TRANSPORT_LOG_EVENT,\n (logParams: NativeLog) => {\n subscriber.next(mapNativeTransportLogToLog(logParams));\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n async connectDevice(uid: string): Promise<InternalConnectionResult> {\n const nConnectionResult = await this._nativeModule.connectDevice(uid);\n return mapNativeConnectionResultToConnectionResult(\n nConnectionResult,\n this._deviceModelDataSource,\n );\n }\n\n async disconnectDevice(sessionId: string): Promise<void> {\n return this._nativeModule.disconnectDevice(sessionId);\n }\n\n async sendApdu(sessionId: string, apdu: Uint8Array): Promise<SendApduResult> {\n const nSendApduResult = await this._nativeModule.sendApdu(\n sessionId,\n uint8ArrayToBase64(apdu),\n );\n return mapNativeSendApduResultToSendApduResult(nSendApduResult);\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,wBAOnCC,EAA2B,gBAE3BC,EAAmC,oCAOnCC,EAMO,oBACPC,EAOO,mBAGA,MAAMN,CAA0D,CACpD,cACA,uBAEjB,YAAYO,EAGT,CACD,KAAK,cAAgBA,EAAK,aAC1B,KAAK,uBAAyBA,EAAK,qBACrC,CAEA,WAAY,CACV,OAAO,KAAK,cAAc,UAAU,CACtC,CAEA,UAAW,CACT,OAAO,KAAK,cAAc,SAAS,CACrC,CAEA,oCAEE,CACA,OAAO,IAAI,aAAYC,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,2BACCC,GAAqD,CACpDF,EAAW,KACTE,EACG,IAAKC,MACJ,uDACEA,EACA,KAAK,sBACP,CACF,EACC,OAAQC,GAAMA,IAAM,IAAI,CAC7B,CACF,CACF,EAEA,MAAO,IAAM,CACXH,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,qCAA8E,CAC5E,OAAO,IAAI,aAAYD,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,4BACCE,GAA2C,CAC1CH,EAAW,QACT,qDAAkDG,CAAM,CAC1D,CACF,CACF,EAEA,MAAO,IAAM,CACXF,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,0BAAkD,CAChD,OAAO,IAAI,aAAYD,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,sBACCI,GAAyB,CACxBL,EAAW,QAAK,8BAA2BK,CAAS,CAAC,CACvD,CACF,EAEA,MAAO,IAAM,CACXJ,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,MAAM,cAAcK,EAAgD,CAClE,MAAMC,EAAoB,MAAM,KAAK,cAAc,cAAcD,CAAG,EACpE,SAAO,+CACLC,EACA,KAAK,sBACP,CACF,CAEA,MAAM,iBAAiBC,EAAkC,CACvD,OAAO,KAAK,cAAc,iBAAiBA,CAAS,CACtD,CAEA,MAAM,SAASA,EAAmBC,EAA2C,CAC3E,MAAMC,EAAkB,MAAM,KAAK,cAAc,SAC/CF,KACA,sBAAmBC,CAAI,CACzB,EACA,SAAO,2CAAwCC,CAAe,CAChE,CACF",
|
|
6
|
+
"names": ["DefaultNativeModuleWrapper_exports", "__export", "DefaultNativeModuleWrapper", "__toCommonJS", "import_react_native", "import_rxjs", "import_base64Utils", "import_mapper", "import_types", "args", "subscriber", "eventListener", "discoveredDevices", "device", "d", "logParams", "uid", "nConnectionResult", "sessionId", "apdu", "nSendApduResult"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var m=(r,e)=>{for(var o in e)s(r,o,{get:e[o],enumerable:!0})},d=(r,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of c(e))!p.call(r,t)&&t!==o&&s(r,t,{get:()=>e[t],enumerable:!(i=a(e,t))||i.enumerable});return r};var v=r=>d(s({},"__esModule",{value:!0}),r);var u={};m(u,{StubNativeModuleWrapper:()=>l});module.exports=v(u);var n=require("rxjs");class l{startScan(){return Promise.resolve()}stopScan(){return Promise.resolve()}subscribeToDiscoveredDevicesEvents(){return(0,n.from)([])}subscribeToTransportLogs(){return(0,n.from)([])}connectDevice(){throw new Error("Method not implemented.")}disconnectDevice(){throw new Error("Method not implemented.")}sendApdu(){throw new Error("Method not implemented.")}subscribeToDeviceDisconnectedEvents(){return(0,n.from)([])}}0&&(module.exports={StubNativeModuleWrapper});
|
|
2
2
|
//# sourceMappingURL=StubNativeModuleWrapper.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/StubNativeModuleWrapper.ts"],
|
|
4
|
-
"sourcesContent": ["import type {\n LogParams,\n SendApduResult,\n TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { type NativeModuleWrapper } from \"@api/transport/NativeModuleWrapper\";\nimport type {\n InternalConnectionResult,\n InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nexport class StubNativeModuleWrapper implements NativeModuleWrapper {\n startScan() {\n return Promise.resolve();\n }\n\n stopScan() {\n return Promise.resolve();\n }\n\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n > {\n return from([]);\n }\n\n subscribeToTransportLogs(): Observable<LogParams> {\n return from([]);\n }\n\n connectDevice(): Promise<InternalConnectionResult> {\n throw new Error(\"Method not implemented.\");\n }\n\n disconnectDevice(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n sendApdu(): Promise<SendApduResult> {\n throw new Error(\"Method not implemented.\");\n }\n\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected> {\n return from([]);\n }\n
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAsC,gBAQ/B,MAAMF,CAAuD,CAClE,WAAY,CACV,OAAO,QAAQ,QAAQ,CACzB,CAEA,UAAW,CACT,OAAO,QAAQ,QAAQ,CACzB,CAEA,oCAEE,CACA,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,0BAAkD,CAChD,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,eAAmD,CACjD,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,kBAAkC,CAChC,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,UAAoC,CAClC,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,qCAA8E,CAC5E,SAAO,QAAK,CAAC,CAAC,CAChB,
|
|
4
|
+
"sourcesContent": ["import type {\n LogParams,\n SendApduResult,\n TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { type NativeModuleWrapper } from \"@api/transport/NativeModuleWrapper\";\nimport type {\n InternalConnectionResult,\n InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nexport class StubNativeModuleWrapper implements NativeModuleWrapper {\n startScan() {\n return Promise.resolve();\n }\n\n stopScan() {\n return Promise.resolve();\n }\n\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n > {\n return from([]);\n }\n\n subscribeToTransportLogs(): Observable<LogParams> {\n return from([]);\n }\n\n connectDevice(): Promise<InternalConnectionResult> {\n throw new Error(\"Method not implemented.\");\n }\n\n disconnectDevice(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n sendApdu(): Promise<SendApduResult> {\n throw new Error(\"Method not implemented.\");\n }\n\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected> {\n return from([]);\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAsC,gBAQ/B,MAAMF,CAAuD,CAClE,WAAY,CACV,OAAO,QAAQ,QAAQ,CACzB,CAEA,UAAW,CACT,OAAO,QAAQ,QAAQ,CACzB,CAEA,oCAEE,CACA,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,0BAAkD,CAChD,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,eAAmD,CACjD,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,kBAAkC,CAChC,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,UAAoC,CAClC,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,qCAA8E,CAC5E,SAAO,QAAK,CAAC,CAAC,CAChB,CACF",
|
|
6
6
|
"names": ["StubNativeModuleWrapper_exports", "__export", "StubNativeModuleWrapper", "__toCommonJS", "import_rxjs"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var o in t)s(e,o,{get:t[o],enumerable:!0})},f=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of l(t))!D.call(e,i)&&i!==o&&s(e,i,{get:()=>t[i],enumerable:!(a=v(t,i))||a.enumerable});return e};var N=e=>f(s({},"__esModule",{value:!0}),e);var b={};m(b,{mapNativeConnectionResultToConnectionResult:()=>L,mapNativeDeviceConnectionLostToDeviceDisconnected:()=>T,mapNativeDiscoveryDeviceToTransportDiscoveredDevice:()=>g,mapNativeLedgerDeviceToDeviceModel:()=>c,mapNativeSendApduResultToSendApduResult:()=>R,mapNativeTransportLogToLog:()=>y});module.exports=N(b);var n=require("@ledgerhq/device-management-kit"),r=require("purify-ts"),d=require("../helpers/base64Utils"),u=require("../transport/Errors"),p=require("../transport/rnHidTransportIdentifier");function c(e,t){return t.filterDeviceModels({usbProductId:Number.parseInt(e.usbProductIdMask,16)})[0]??null}function g(e,t){const o=c(e.ledgerDevice,t);return o==null?null:{id:e.uid,deviceModel:o,transport:p.TRANSPORT_IDENTIFIER,name:e.name}}function y(e){let t;switch(e.level){case"error":t=n.LogLevel.Error;break;case"warning":t=n.LogLevel.Warning;break;case"info":t=n.LogLevel.Info;break;case"debug":t=n.LogLevel.Debug;break;default:I(e.level),t=n.LogLevel.Info;break}return[t,e.message,{tag:e.tag,data:e.jsonPayload,timestamp:Number.parseInt(e.timestamp,10)}]}function I(e){throw new Error("Unexpected object: "+e)}function L(e,t){if(e.success){const o=c(e.ledgerDevice,t);return o?(0,r.Right)({sessionId:e.sessionId,transportDeviceModel:o}):(0,r.Left)(new n.OpeningConnectionError(`Could not find device model for the connected device with usbProductIdMask: ${e.ledgerDevice.usbProductIdMask}`))}else return(0,r.Left)(new n.OpeningConnectionError(e.error))}function R(e){if(e.success){const t=(0,d.base64ToUint8Array)(e.apdu),o=n.FramerUtils.getFirstBytesFrom(t,t.length-2),a=n.FramerUtils.getLastBytesFrom(t,2);return(0,r.Right)(new n.ApduResponse({data:o,statusCode:a}))}else return(0,r.Left)(new u.SendApduError(e.error))}function T(e){return{sessionId:e.id}}0&&(module.exports={mapNativeConnectionResultToConnectionResult,mapNativeDeviceConnectionLostToDeviceDisconnected,mapNativeDiscoveryDeviceToTransportDiscoveredDevice,mapNativeLedgerDeviceToDeviceModel,mapNativeSendApduResultToSendApduResult,mapNativeTransportLogToLog});
|
|
2
2
|
//# sourceMappingURL=mapper.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/mapper.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ApduResponse,\n
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iDAAAE,EAAA,sDAAAC,EAAA,wDAAAC,EAAA,uCAAAC,EAAA,4CAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAR,GAAA,IAAAS,
|
|
4
|
+
"sourcesContent": ["import {\n ApduResponse,\n type DeviceModelDataSource,\n FramerUtils,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n type SendApduResult,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { base64ToUint8Array } from \"@api/helpers/base64Utils\";\nimport { SendApduError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n type NativeDeviceConnectionLost,\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\nexport function mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice: NativeLedgerDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDeviceModel | null {\n return (\n deviceModelDataSource.filterDeviceModels({\n usbProductId: Number.parseInt(nativeLedgerDevice.usbProductIdMask, 16),\n })[0] ?? null\n );\n}\n\nexport function mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice: NativeDiscoveryDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDiscoveredDevice | null {\n const deviceModel = mapNativeLedgerDeviceToDeviceModel(\n nativeDevice.ledgerDevice,\n deviceModelDataSource,\n );\n if (deviceModel == null) return null;\n\n return {\n id: nativeDevice.uid,\n deviceModel,\n transport: TRANSPORT_IDENTIFIER,\n name: nativeDevice.name,\n };\n}\n\nexport function mapNativeTransportLogToLog(log: NativeLog): LogParams {\n let level: LogLevel;\n switch (log.level) {\n case \"error\":\n level = LogLevel.Error;\n break;\n case \"warning\":\n level = LogLevel.Warning;\n break;\n case \"info\":\n level = LogLevel.Info;\n break;\n case \"debug\":\n level = LogLevel.Debug;\n break;\n default:\n assertNever(log.level);\n level = LogLevel.Info;\n break;\n }\n\n return [\n level,\n log.message,\n {\n tag: log.tag,\n data: log.jsonPayload,\n timestamp: Number.parseInt(log.timestamp, 10),\n },\n ];\n}\n\nfunction assertNever(x: never) {\n throw new Error(\"Unexpected object: \" + x);\n}\n\nexport function mapNativeConnectionResultToConnectionResult(\n result: NativeInternalConnectionResult,\n deviceModelDataSource: DeviceModelDataSource,\n): InternalConnectionResult {\n if (result.success) {\n const transportDeviceModel = mapNativeLedgerDeviceToDeviceModel(\n result.ledgerDevice,\n deviceModelDataSource,\n );\n if (!transportDeviceModel)\n return Left(\n new OpeningConnectionError(\n `Could not find device model for the connected device with usbProductIdMask: ${result.ledgerDevice.usbProductIdMask}`,\n ),\n );\n return Right({ sessionId: result.sessionId, transportDeviceModel });\n } else {\n return Left(new OpeningConnectionError(result.error));\n }\n}\n\nexport function mapNativeSendApduResultToSendApduResult(\n result: NativeSendApduResult,\n): SendApduResult {\n if (result.success) {\n const responseBytes = base64ToUint8Array(result.apdu);\n const data = FramerUtils.getFirstBytesFrom(\n responseBytes,\n responseBytes.length - 2,\n );\n const statusCode = FramerUtils.getLastBytesFrom(responseBytes, 2);\n return Right(new ApduResponse({ data, statusCode }));\n } else {\n return Left(new SendApduError(result.error));\n }\n}\n\nexport function mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost: NativeDeviceConnectionLost,\n): InternalDeviceDisconnected {\n return {\n sessionId: nativeDeviceConnectionLost.id,\n };\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iDAAAE,EAAA,sDAAAC,EAAA,wDAAAC,EAAA,uCAAAC,EAAA,4CAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAR,GAAA,IAAAS,EAUO,2CACPC,EAA4B,qBAE5BC,EAAmC,oCACnCC,EAA8B,iCAC9BC,EAAqC,mDAe9B,SAASR,EACdS,EACAC,EAC6B,CAC7B,OACEA,EAAsB,mBAAmB,CACvC,aAAc,OAAO,SAASD,EAAmB,iBAAkB,EAAE,CACvE,CAAC,EAAE,CAAC,GAAK,IAEb,CAEO,SAASV,EACdY,EACAD,EACkC,CAClC,MAAME,EAAcZ,EAClBW,EAAa,aACbD,CACF,EACA,OAAIE,GAAe,KAAa,KAEzB,CACL,GAAID,EAAa,IACjB,YAAAC,EACA,UAAW,uBACX,KAAMD,EAAa,IACrB,CACF,CAEO,SAAST,EAA2BW,EAA2B,CACpE,IAAIC,EACJ,OAAQD,EAAI,MAAO,CACjB,IAAK,QACHC,EAAQ,WAAS,MACjB,MACF,IAAK,UACHA,EAAQ,WAAS,QACjB,MACF,IAAK,OACHA,EAAQ,WAAS,KACjB,MACF,IAAK,QACHA,EAAQ,WAAS,MACjB,MACF,QACEC,EAAYF,EAAI,KAAK,EACrBC,EAAQ,WAAS,KACjB,KACJ,CAEA,MAAO,CACLA,EACAD,EAAI,QACJ,CACE,IAAKA,EAAI,IACT,KAAMA,EAAI,YACV,UAAW,OAAO,SAASA,EAAI,UAAW,EAAE,CAC9C,CACF,CACF,CAEA,SAASE,EAAYC,EAAU,CAC7B,MAAM,IAAI,MAAM,sBAAwBA,CAAC,CAC3C,CAEO,SAASnB,EACdoB,EACAP,EAC0B,CAC1B,GAAIO,EAAO,QAAS,CAClB,MAAMC,EAAuBlB,EAC3BiB,EAAO,aACPP,CACF,EACA,OAAKQ,KAME,SAAM,CAAE,UAAWD,EAAO,UAAW,qBAAAC,CAAqB,CAAC,KALzD,QACL,IAAI,yBACF,+EAA+ED,EAAO,aAAa,gBAAgB,EACrH,CACF,CAEJ,KACE,UAAO,QAAK,IAAI,yBAAuBA,EAAO,KAAK,CAAC,CAExD,CAEO,SAAShB,EACdgB,EACgB,CAChB,GAAIA,EAAO,QAAS,CAClB,MAAME,KAAgB,sBAAmBF,EAAO,IAAI,EAC9CG,EAAO,cAAY,kBACvBD,EACAA,EAAc,OAAS,CACzB,EACME,EAAa,cAAY,iBAAiBF,EAAe,CAAC,EAChE,SAAO,SAAM,IAAI,eAAa,CAAE,KAAAC,EAAM,WAAAC,CAAW,CAAC,CAAC,CACrD,KACE,UAAO,QAAK,IAAI,gBAAcJ,EAAO,KAAK,CAAC,CAE/C,CAEO,SAASnB,EACdwB,EAC4B,CAC5B,MAAO,CACL,UAAWA,EAA2B,EACxC,CACF",
|
|
6
6
|
"names": ["mapper_exports", "__export", "mapNativeConnectionResultToConnectionResult", "mapNativeDeviceConnectionLostToDeviceDisconnected", "mapNativeDiscoveryDeviceToTransportDiscoveredDevice", "mapNativeLedgerDeviceToDeviceModel", "mapNativeSendApduResultToSendApduResult", "mapNativeTransportLogToLog", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_base64Utils", "import_Errors", "import_rnHidTransportIdentifier", "nativeLedgerDevice", "deviceModelDataSource", "nativeDevice", "deviceModel", "log", "level", "assertNever", "x", "result", "transportDeviceModel", "responseBytes", "data", "statusCode", "nativeDeviceConnectionLost"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("@ledgerhq/device-management-kit"),
|
|
1
|
+
"use strict";var e=require("@ledgerhq/device-management-kit"),n=require("purify-ts"),c=require("../transport/Errors"),d=require("../transport/rnHidTransportIdentifier"),o=require("./mapper");describe("mapper",()=>{const a=new e.StaticDeviceModelDataSource;describe("mapNativeLedgerDeviceToDeviceModel",()=>{[{nativeLedgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_S})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x40"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_X})},{nativeLedgerDevice:{name:"NanoSPlus",usbProductIdMask:"0x50"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_SP})},{nativeLedgerDevice:{name:"Stax",usbProductIdMask:"0x60"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.STAX})},{nativeLedgerDevice:{name:"Flex",usbProductIdMask:"0x70"},deviceModel:a.getDeviceModel({id:e.DeviceModelId.FLEX})},{nativeLedgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceModel:null}].forEach(({nativeLedgerDevice:t,deviceModel:i})=>{it(`should map USB device with usbProductIdMask ${t.usbProductIdMask} to ${i?.productName??"null"}`,()=>{expect((0,o.mapNativeLedgerDeviceToDeviceModel)(t,a)).toEqual(i)})})}),describe("mapNativeDiscoveryDeviceToTransportDiscoveredDevice",()=>{it("should map NativeDiscoveryDevice to TransportDiscoveredDevice",()=>{const s={name:"NanoS",uid:"abcd",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"}},t={id:"abcd",deviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_S}),transport:d.TRANSPORT_IDENTIFIER,name:"NanoS"};expect((0,o.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(s,a)).toEqual(t)}),it("should return null if the device model is not recognized",()=>{const s={name:"NanoX",uid:"efgh",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x4567890"}};expect((0,o.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(s,a)).toEqual(null)})}),describe("mapNativeTransportLogToLog",()=>{[{nativeLog:{level:"debug",tag:"tag",message:"debug message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Debug,"debug message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"info",tag:"tag",message:"info message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Info,"info message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"error",tag:"tag",message:"error message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Error,"error message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]},{nativeLog:{level:"warning",tag:"tag",message:"warning message",jsonPayload:{key:"value"},timestamp:"123456789"},log:[e.LogLevel.Warning,"warning message",{timestamp:123456789,tag:"tag",data:{key:"value"}}]}].forEach(({nativeLog:t,log:i})=>{it(`should map NativeLog with level "${t.level}" to Log`,()=>{expect((0,o.mapNativeTransportLogToLog)(t)).toEqual(i)})})}),describe("mapNativeConnectionResultToConnectionResult",()=>{[{testTitle:"Success",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoS",usbProductIdMask:"0x10"},deviceName:"NanoS"},connectionResult:(0,n.Right)({sessionId:"1234",transportDeviceModel:a.getDeviceModel({id:e.DeviceModelId.NANO_S})})},{testTitle:"Failure",nativeConnectionResult:{success:!1,error:"error message"},connectionResult:(0,n.Left)(new e.OpeningConnectionError("error message"))},{testTitle:"Unknown device model",nativeConnectionResult:{success:!0,sessionId:"1234",ledgerDevice:{name:"NanoX",usbProductIdMask:"0x12345678"},deviceName:"NanoX"},connectionResult:(0,n.Left)(new e.OpeningConnectionError("Could not find device model for the connected device with usbProductIdMask: 0x12345678"))}].forEach(({testTitle:t,nativeConnectionResult:i,connectionResult:r})=>{it(t,()=>{expect((0,o.mapNativeConnectionResultToConnectionResult)(i,a)).toEqual(r)})})}),describe("mapNativeSendApduResultToSendApduResult",()=>{test("success",()=>{const t={success:!0,apdu:"AQIDkAA="},i=(0,n.Right)(new e.ApduResponse({data:new Uint8Array([1,2,3]),statusCode:new Uint8Array([144,0])}));expect((0,o.mapNativeSendApduResultToSendApduResult)(t)).toEqual(i)}),test("failure",()=>{const s={success:!1,error:"error message"},t=(0,n.Left)(new c.SendApduError("error message"));expect((0,o.mapNativeSendApduResultToSendApduResult)(s)).toEqual(t)})}),describe("mapNativeDeviceConnectionLostToDeviceDisconnected",()=>{it("should map NativeDeviceConnectionLost to DeviceDisconnected",()=>{const s={id:"1234"},t={sessionId:"1234"};expect((0,o.mapNativeDeviceConnectionLostToDeviceDisconnected)(s)).toEqual(t)})})});
|
|
2
2
|
//# sourceMappingURL=mapper.test.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/mapper.test.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ApduResponse,\n DeviceModelId,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\n StaticDeviceModelDataSource,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { HidTransportSendApduUnknownError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport { type InternalConnectionResult } from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeLedgerDeviceToDeviceModel,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\ndescribe(\"mapper\", () => {\n const deviceModelDataSource = new StaticDeviceModelDataSource();\n\n describe(\"mapNativeLedgerDeviceToDeviceModel\", () => {\n const testCases: Array<{\n nativeLedgerDevice: NativeLedgerDevice;\n deviceModel: TransportDeviceModel | null;\n }> = [\n {\n nativeLedgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x40\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoSPlus\",\n usbProductIdMask: \"0x50\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_SP,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Stax\",\n usbProductIdMask: \"0x60\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.STAX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Flex\",\n usbProductIdMask: \"0x70\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.FLEX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceModel: null, // because the usbProductIdMask is not recognized\n },\n ];\n testCases.forEach(({ nativeLedgerDevice, deviceModel }) => {\n it(`should map USB device with usbProductIdMask ${nativeLedgerDevice.usbProductIdMask} to ${\n deviceModel?.productName ?? \"null\"\n }`, () => {\n expect(\n mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice,\n deviceModelDataSource,\n ),\n ).toEqual(deviceModel);\n });\n });\n });\n\n describe(\"mapNativeDiscoveryDeviceToTransportDiscoveredDevice\", () => {\n it(\"should map NativeDiscoveryDevice to TransportDiscoveredDevice\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoS\",\n uid: \"abcd\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n };\n const expectedDiscoveredDevice: TransportDiscoveredDevice = {\n id: \"abcd\",\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n transport: TRANSPORT_IDENTIFIER,\n name: \"NanoS\",\n };\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n\n it(\"should return null if the device model is not recognized\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoX\",\n uid: \"efgh\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x4567890\", // some invalid value\n },\n };\n const expectedDiscoveredDevice = null; // because the usbProductIdMask is not recognized\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n });\n\n describe(\"mapNativeTransportLogToLog\", () => {\n const testCases: Array<{\n nativeLog: NativeLog;\n log: LogParams;\n }> = [\n {\n // debug\n nativeLog: {\n level: \"debug\",\n tag: \"tag\",\n message: \"debug message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Debug,\n \"debug message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // info\n {\n nativeLog: {\n level: \"info\",\n tag: \"tag\",\n message: \"info message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Info,\n \"info message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // error\n {\n nativeLog: {\n level: \"error\",\n tag: \"tag\",\n message: \"error message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Error,\n \"error message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // warning\n {\n nativeLog: {\n level: \"warning\",\n tag: \"tag\",\n message: \"warning message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Warning,\n \"warning message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n ];\n\n testCases.forEach(({ nativeLog, log }) => {\n it(`should map NativeLog with level \"${nativeLog.level}\" to Log`, () => {\n expect(mapNativeTransportLogToLog(nativeLog)).toEqual(log);\n });\n });\n });\n\n describe(\"mapNativeConnectionResultToConnectionResult\", () => {\n const testCases: Array<{\n nativeConnectionResult: NativeInternalConnectionResult;\n connectionResult: InternalConnectionResult;\n testTitle: string;\n }> = [\n {\n testTitle: \"Success\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceName: \"NanoS\",\n },\n connectionResult: Right({\n sessionId: \"1234\",\n transportDeviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n }),\n },\n {\n testTitle: \"Failure\",\n nativeConnectionResult: {\n success: false,\n error: \"error message\",\n },\n connectionResult: Left(new OpeningConnectionError(\"error message\")),\n },\n {\n testTitle: \"Unknown device model\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceName: \"NanoX\",\n },\n connectionResult: Left(\n new OpeningConnectionError(\n \"Could not find device model for the connected device with usbProductIdMask: 0x12345678\",\n ),\n ),\n },\n ];\n\n testCases.forEach(\n ({ testTitle, nativeConnectionResult, connectionResult }) => {\n it(testTitle, () => {\n expect(\n mapNativeConnectionResultToConnectionResult(\n nativeConnectionResult,\n deviceModelDataSource,\n ),\n ).toEqual(connectionResult);\n });\n },\n );\n });\n\n describe(\"mapNativeSendApduResultToSendApduResult\", () => {\n test(\"success\", () => {\n const resultApduString = \"AQIDkAA=\";\n const nativeSendApduResult: NativeSendApduResult = {\n success: true,\n apdu: resultApduString,\n };\n const expectedSendApduResult: SendApduResult = Right(\n new ApduResponse({\n data: new Uint8Array([0x01, 0x02, 0x03]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"failure\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"error message\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new HidTransportSendApduUnknownError(\"error message\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"timeout error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"SendApduTimeout\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduTimeoutError(\"Abort timeout\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"empty response error\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"EmptyResponse\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduEmptyResponseError(\"Empty response\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n });\n\n describe(\"mapNativeDeviceConnectionLostToDeviceDisconnected\", () => {\n it(\"should map NativeDeviceConnectionLost to DeviceDisconnected\", () => {\n const nativeDeviceConnectionLost = {\n id: \"1234\",\n };\n const expectedDeviceDisconnected = {\n sessionId: \"1234\",\n };\n expect(\n mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost,\n ),\n ).toEqual(expectedDeviceDisconnected);\n });\n });\n});\n"],
|
|
5
|
-
"mappings": "aAAA,IAAAA,
|
|
4
|
+
"sourcesContent": ["import {\n ApduResponse,\n DeviceModelId,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n type SendApduResult,\n StaticDeviceModelDataSource,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { SendApduError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport { type InternalConnectionResult } from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeLedgerDeviceToDeviceModel,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\ndescribe(\"mapper\", () => {\n const deviceModelDataSource = new StaticDeviceModelDataSource();\n\n describe(\"mapNativeLedgerDeviceToDeviceModel\", () => {\n const testCases: Array<{\n nativeLedgerDevice: NativeLedgerDevice;\n deviceModel: TransportDeviceModel | null;\n }> = [\n {\n nativeLedgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x40\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_X,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoSPlus\",\n usbProductIdMask: \"0x50\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_SP,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Stax\",\n usbProductIdMask: \"0x60\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.STAX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"Flex\",\n usbProductIdMask: \"0x70\",\n },\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.FLEX,\n }),\n },\n {\n nativeLedgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceModel: null, // because the usbProductIdMask is not recognized\n },\n ];\n testCases.forEach(({ nativeLedgerDevice, deviceModel }) => {\n it(`should map USB device with usbProductIdMask ${nativeLedgerDevice.usbProductIdMask} to ${\n deviceModel?.productName ?? \"null\"\n }`, () => {\n expect(\n mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice,\n deviceModelDataSource,\n ),\n ).toEqual(deviceModel);\n });\n });\n });\n\n describe(\"mapNativeDiscoveryDeviceToTransportDiscoveredDevice\", () => {\n it(\"should map NativeDiscoveryDevice to TransportDiscoveredDevice\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoS\",\n uid: \"abcd\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n };\n const expectedDiscoveredDevice: TransportDiscoveredDevice = {\n id: \"abcd\",\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n transport: TRANSPORT_IDENTIFIER,\n name: \"NanoS\",\n };\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n\n it(\"should return null if the device model is not recognized\", () => {\n const nativeDevice: NativeDiscoveryDevice = {\n name: \"NanoX\",\n uid: \"efgh\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x4567890\", // some invalid value\n },\n };\n const expectedDiscoveredDevice = null; // because the usbProductIdMask is not recognized\n expect(\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice,\n deviceModelDataSource,\n ),\n ).toEqual(expectedDiscoveredDevice);\n });\n });\n\n describe(\"mapNativeTransportLogToLog\", () => {\n const testCases: Array<{\n nativeLog: NativeLog;\n log: LogParams;\n }> = [\n {\n // debug\n nativeLog: {\n level: \"debug\",\n tag: \"tag\",\n message: \"debug message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Debug,\n \"debug message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // info\n {\n nativeLog: {\n level: \"info\",\n tag: \"tag\",\n message: \"info message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Info,\n \"info message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // error\n {\n nativeLog: {\n level: \"error\",\n tag: \"tag\",\n message: \"error message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Error,\n \"error message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n // warning\n {\n nativeLog: {\n level: \"warning\",\n tag: \"tag\",\n message: \"warning message\",\n jsonPayload: { key: \"value\" },\n timestamp: \"123456789\",\n },\n log: [\n LogLevel.Warning,\n \"warning message\",\n {\n timestamp: 123456789,\n tag: \"tag\",\n data: { key: \"value\" },\n },\n ],\n },\n ];\n\n testCases.forEach(({ nativeLog, log }) => {\n it(`should map NativeLog with level \"${nativeLog.level}\" to Log`, () => {\n expect(mapNativeTransportLogToLog(nativeLog)).toEqual(log);\n });\n });\n });\n\n describe(\"mapNativeConnectionResultToConnectionResult\", () => {\n const testCases: Array<{\n nativeConnectionResult: NativeInternalConnectionResult;\n connectionResult: InternalConnectionResult;\n testTitle: string;\n }> = [\n {\n testTitle: \"Success\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoS\",\n usbProductIdMask: \"0x10\",\n },\n deviceName: \"NanoS\",\n },\n connectionResult: Right({\n sessionId: \"1234\",\n transportDeviceModel: deviceModelDataSource.getDeviceModel({\n id: DeviceModelId.NANO_S,\n }),\n }),\n },\n {\n testTitle: \"Failure\",\n nativeConnectionResult: {\n success: false,\n error: \"error message\",\n },\n connectionResult: Left(new OpeningConnectionError(\"error message\")),\n },\n {\n testTitle: \"Unknown device model\",\n nativeConnectionResult: {\n success: true,\n sessionId: \"1234\",\n ledgerDevice: {\n name: \"NanoX\",\n usbProductIdMask: \"0x12345678\",\n },\n deviceName: \"NanoX\",\n },\n connectionResult: Left(\n new OpeningConnectionError(\n \"Could not find device model for the connected device with usbProductIdMask: 0x12345678\",\n ),\n ),\n },\n ];\n\n testCases.forEach(\n ({ testTitle, nativeConnectionResult, connectionResult }) => {\n it(testTitle, () => {\n expect(\n mapNativeConnectionResultToConnectionResult(\n nativeConnectionResult,\n deviceModelDataSource,\n ),\n ).toEqual(connectionResult);\n });\n },\n );\n });\n\n describe(\"mapNativeSendApduResultToSendApduResult\", () => {\n test(\"success\", () => {\n const resultApduString = \"AQIDkAA=\";\n const nativeSendApduResult: NativeSendApduResult = {\n success: true,\n apdu: resultApduString,\n };\n const expectedSendApduResult: SendApduResult = Right(\n new ApduResponse({\n data: new Uint8Array([0x01, 0x02, 0x03]),\n statusCode: new Uint8Array([0x90, 0x00]),\n }),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n\n test(\"failure\", () => {\n const nativeSendApduResult: NativeSendApduResult = {\n success: false,\n error: \"error message\",\n };\n const expectedSendApduResult: SendApduResult = Left(\n new SendApduError(\"error message\"),\n );\n expect(\n mapNativeSendApduResultToSendApduResult(nativeSendApduResult),\n ).toEqual(expectedSendApduResult);\n });\n });\n\n describe(\"mapNativeDeviceConnectionLostToDeviceDisconnected\", () => {\n it(\"should map NativeDeviceConnectionLost to DeviceDisconnected\", () => {\n const nativeDeviceConnectionLost = {\n id: \"1234\",\n };\n const expectedDeviceDisconnected = {\n sessionId: \"1234\",\n };\n expect(\n mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost,\n ),\n ).toEqual(expectedDeviceDisconnected);\n });\n });\n});\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["import_device_management_kit", "import_purify_ts", "import_Errors", "import_rnHidTransportIdentifier", "import_mapper", "deviceModelDataSource", "nativeLedgerDevice", "deviceModel", "nativeDevice", "expectedDiscoveredDevice", "nativeLog", "log", "testTitle", "nativeConnectionResult", "connectionResult", "nativeSendApduResult", "expectedSendApduResult", "nativeDeviceConnectionLost", "expectedDeviceDisconnected"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var s in e)o(t,s,{get:e[s],enumerable:!0})},d=(t,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of a(e))!c.call(t,i)&&i!==s&&o(t,i,{get:()=>e[i],enumerable:!(r=n(e,i))||r.enumerable});return t};var p=t=>d(o({},"__esModule",{value:!0}),t);var u={};v(u,{DEVICE_DISCONNECTED_EVENT:()=>D,DISCOVERED_DEVICES_EVENT:()=>g,TRANSPORT_LOG_EVENT:()=>N});module.exports=p(u);const g="DiscoveredDevices",N="TransportLog",D="DeviceDisconnected";0&&(module.exports={DEVICE_DISCONNECTED_EVENT,DISCOVERED_DEVICES_EVENT,TRANSPORT_LOG_EVENT});
|
|
2
2
|
//# sourceMappingURL=types.js.map
|