@ledgerhq/device-transport-kit-react-native-hid 0.0.0-rnhid-transport-20250411151739 → 0.0.0-web-ble-29-08---20250829104351
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/TransportHidModule.kt +14 -5
- package/android/src/main/kotlin/com/ledger/androidtransporthid/bridge/serialization.kt +2 -0
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/DefaultAndroidUsbTransport.kt +57 -10
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/connection/AndroidUsbApduSender.kt +75 -33
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/utils/UsbDeviceMapper.kt +3 -0
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceApduSender.kt +2 -1
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnection.kt +5 -4
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionStateMachine.kt +3 -2
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/api/apdu/SendApduResult.kt +4 -0
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/api/device/LedgerDevice.kt +16 -0
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/internal/connection/InternalConnectedDevice.kt +1 -1
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/internal/transport/framer/FramerService.kt +1 -1
- package/android/src/test/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionStateMachineTest.kt +47 -31
- package/android/src/test/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionTest.kt +9 -5
- package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js +1 -1
- package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
- package/lib/cjs/api/bridge/NativeTransportModule.js +1 -1
- package/lib/cjs/api/bridge/NativeTransportModule.js.map +1 -1
- 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 +1 -1
- 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/cjs/package.json +19 -14
- package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js +1 -1
- package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
- package/lib/esm/api/bridge/NativeTransportModule.js +1 -1
- package/lib/esm/api/bridge/NativeTransportModule.js.map +1 -1
- 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.map +1 -1
- 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 +2 -2
- package/lib/esm/package.json +19 -14
- package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts +1 -1
- package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts.map +1 -1
- package/lib/types/api/bridge/NativeTransportModule.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 -2
- package/lib/types/api/bridge/types.d.ts.map +1 -1
- package/lib/types/api/transport/NativeModuleWrapper.d.ts +1 -1
- package/lib/types/api/transport/NativeModuleWrapper.d.ts.map +1 -1
- package/lib/types/api/transport/RNHidTransport.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +21 -16
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -7
- package/android/gradlew +0 -252
- package/android/gradlew.bat +0 -94
|
@@ -25,7 +25,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
25
25
|
var sendApduResult: SendApduResult? = null
|
|
26
26
|
|
|
27
27
|
val stateMachine = DeviceConnectionStateMachine(
|
|
28
|
-
sendApduFn = { apdu -> sendApduCalled = apdu },
|
|
28
|
+
sendApduFn = { apdu, _ -> sendApduCalled = apdu },
|
|
29
29
|
onTerminated = { terminated = true },
|
|
30
30
|
isFatalSendApduFailure = { false },
|
|
31
31
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -38,7 +38,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
38
38
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
39
39
|
apdu = mockedRequestApduA,
|
|
40
40
|
triggersDisconnection = false,
|
|
41
|
-
resultCallback = { result -> sendApduResult = result }
|
|
41
|
+
resultCallback = { result -> sendApduResult = result },
|
|
42
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
42
43
|
))
|
|
43
44
|
assertArrayEquals(mockedRequestApduA, sendApduCalled)
|
|
44
45
|
|
|
@@ -65,7 +66,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
65
66
|
var error: Throwable? = null
|
|
66
67
|
|
|
67
68
|
val stateMachine = DeviceConnectionStateMachine(
|
|
68
|
-
sendApduFn = { },
|
|
69
|
+
sendApduFn = { _, _ -> },
|
|
69
70
|
onTerminated = { terminated = true },
|
|
70
71
|
isFatalSendApduFailure = { true }, // All failures are fatal
|
|
71
72
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -77,7 +78,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
77
78
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
78
79
|
apdu = mockedRequestApduA,
|
|
79
80
|
triggersDisconnection = false,
|
|
80
|
-
resultCallback = { result -> sendApduResult = result }
|
|
81
|
+
resultCallback = { result -> sendApduResult = result },
|
|
82
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
81
83
|
))
|
|
82
84
|
|
|
83
85
|
// Simulate a failure
|
|
@@ -99,7 +101,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
99
101
|
var error: Throwable? = null
|
|
100
102
|
|
|
101
103
|
val stateMachine = DeviceConnectionStateMachine(
|
|
102
|
-
sendApduFn = { },
|
|
104
|
+
sendApduFn = { _, _ -> },
|
|
103
105
|
onTerminated = { terminated = true },
|
|
104
106
|
isFatalSendApduFailure = { false },
|
|
105
107
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -112,7 +114,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
112
114
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
113
115
|
apdu = mockedRequestApduA,
|
|
114
116
|
triggersDisconnection = false,
|
|
115
|
-
resultCallback = { result -> sendApduResult = result }
|
|
117
|
+
resultCallback = { result -> sendApduResult = result },
|
|
118
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
116
119
|
))
|
|
117
120
|
|
|
118
121
|
// Simulate a failure
|
|
@@ -140,7 +143,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
140
143
|
|
|
141
144
|
val dispatcher = StandardTestDispatcher(testScheduler)
|
|
142
145
|
val stateMachine = DeviceConnectionStateMachine(
|
|
143
|
-
sendApduFn = { apdu -> sendApduCalled = apdu },
|
|
146
|
+
sendApduFn = { apdu, _ -> sendApduCalled = apdu },
|
|
144
147
|
onTerminated = { terminated = true },
|
|
145
148
|
isFatalSendApduFailure = { false },
|
|
146
149
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -153,7 +156,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
153
156
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
154
157
|
apdu = mockedRequestApduA,
|
|
155
158
|
triggersDisconnection = true,
|
|
156
|
-
resultCallback = { result -> sendApduResult = result }
|
|
159
|
+
resultCallback = { result -> sendApduResult = result },
|
|
160
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
157
161
|
))
|
|
158
162
|
|
|
159
163
|
// Send APDU should have been called
|
|
@@ -180,7 +184,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
180
184
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
181
185
|
apdu = mockedRequestApduB,
|
|
182
186
|
triggersDisconnection = false,
|
|
183
|
-
resultCallback = { secondSendApduResult = it }
|
|
187
|
+
resultCallback = { secondSendApduResult = it },
|
|
188
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
184
189
|
))
|
|
185
190
|
|
|
186
191
|
// Send APDU should have been called
|
|
@@ -205,7 +210,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
205
210
|
var error: Throwable? = null
|
|
206
211
|
|
|
207
212
|
val stateMachine = DeviceConnectionStateMachine(
|
|
208
|
-
sendApduFn = { apdu -> sendApduCalled += apdu },
|
|
213
|
+
sendApduFn = { apdu, _ -> sendApduCalled += apdu },
|
|
209
214
|
onTerminated = { terminated = true },
|
|
210
215
|
isFatalSendApduFailure = { false },
|
|
211
216
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -218,7 +223,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
218
223
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
219
224
|
apdu = mockedRequestApduA,
|
|
220
225
|
triggersDisconnection = true,
|
|
221
|
-
resultCallback = { }
|
|
226
|
+
resultCallback = { },
|
|
227
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
222
228
|
))
|
|
223
229
|
|
|
224
230
|
// Simulate a successful response
|
|
@@ -239,7 +245,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
239
245
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
240
246
|
apdu = mockedRequestApduB,
|
|
241
247
|
triggersDisconnection = false,
|
|
242
|
-
resultCallback = { secondSendApduResult = it }
|
|
248
|
+
resultCallback = { secondSendApduResult = it },
|
|
249
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
243
250
|
))
|
|
244
251
|
|
|
245
252
|
// Should be in waiting state
|
|
@@ -289,7 +296,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
289
296
|
var error: Throwable? = null
|
|
290
297
|
|
|
291
298
|
val stateMachine = DeviceConnectionStateMachine(
|
|
292
|
-
sendApduFn = { },
|
|
299
|
+
sendApduFn = { _, _ -> },
|
|
293
300
|
onTerminated = { terminated = true },
|
|
294
301
|
isFatalSendApduFailure = { false },
|
|
295
302
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -302,7 +309,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
302
309
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
303
310
|
apdu = mockedRequestApduA,
|
|
304
311
|
triggersDisconnection = false,
|
|
305
|
-
resultCallback = { result -> sendApduResult = result }
|
|
312
|
+
resultCallback = { result -> sendApduResult = result },
|
|
313
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
306
314
|
))
|
|
307
315
|
|
|
308
316
|
// Should be in sending state
|
|
@@ -331,7 +339,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
331
339
|
var error: Throwable? = null
|
|
332
340
|
|
|
333
341
|
val stateMachine = DeviceConnectionStateMachine(
|
|
334
|
-
sendApduFn = { },
|
|
342
|
+
sendApduFn = { _,_ -> },
|
|
335
343
|
onTerminated = { terminated = true },
|
|
336
344
|
isFatalSendApduFailure = { false },
|
|
337
345
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -344,7 +352,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
344
352
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
345
353
|
apdu = mockedRequestApduA,
|
|
346
354
|
triggersDisconnection = false,
|
|
347
|
-
resultCallback = { result -> sendApduResult = result }
|
|
355
|
+
resultCallback = { result -> sendApduResult = result },
|
|
356
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
348
357
|
))
|
|
349
358
|
|
|
350
359
|
// Simulate a disconnection
|
|
@@ -384,7 +393,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
384
393
|
var error: Throwable? = null
|
|
385
394
|
|
|
386
395
|
val stateMachine = DeviceConnectionStateMachine(
|
|
387
|
-
sendApduFn = { },
|
|
396
|
+
sendApduFn = { _,_ -> },
|
|
388
397
|
onTerminated = { terminated = true },
|
|
389
398
|
isFatalSendApduFailure = { false },
|
|
390
399
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -397,7 +406,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
397
406
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
398
407
|
apdu = mockedRequestApduA,
|
|
399
408
|
triggersDisconnection = false,
|
|
400
|
-
resultCallback = { firstSendApduResult = it }
|
|
409
|
+
resultCallback = { firstSendApduResult = it },
|
|
410
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
401
411
|
))
|
|
402
412
|
|
|
403
413
|
// Should be in sending state.
|
|
@@ -410,7 +420,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
410
420
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
411
421
|
apdu = mockedRequestApduB,
|
|
412
422
|
triggersDisconnection = false,
|
|
413
|
-
resultCallback = { secondSendApduResult = it }
|
|
423
|
+
resultCallback = { secondSendApduResult = it },
|
|
424
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
414
425
|
))
|
|
415
426
|
|
|
416
427
|
assertEquals(
|
|
@@ -435,7 +446,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
435
446
|
var terminated = false
|
|
436
447
|
|
|
437
448
|
val stateMachine = DeviceConnectionStateMachine(
|
|
438
|
-
sendApduFn = { },
|
|
449
|
+
sendApduFn = { _,_ -> },
|
|
439
450
|
onTerminated = { terminated = true },
|
|
440
451
|
isFatalSendApduFailure = { false },
|
|
441
452
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -472,7 +483,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
472
483
|
var terminated = false
|
|
473
484
|
|
|
474
485
|
val stateMachine = DeviceConnectionStateMachine(
|
|
475
|
-
sendApduFn = { },
|
|
486
|
+
sendApduFn = { _,_ -> },
|
|
476
487
|
onTerminated = { terminated = true },
|
|
477
488
|
isFatalSendApduFailure = { false },
|
|
478
489
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -507,7 +518,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
507
518
|
var error: Throwable? = null
|
|
508
519
|
|
|
509
520
|
val stateMachine = DeviceConnectionStateMachine(
|
|
510
|
-
sendApduFn = { apdu -> sendApduCalled = apdu },
|
|
521
|
+
sendApduFn = { apdu, _ -> sendApduCalled = apdu },
|
|
511
522
|
onTerminated = { terminated = true },
|
|
512
523
|
isFatalSendApduFailure = { false },
|
|
513
524
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -523,7 +534,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
523
534
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
524
535
|
apdu = mockedRequestApduA,
|
|
525
536
|
triggersDisconnection = false,
|
|
526
|
-
resultCallback = { sendApduResult = it }
|
|
537
|
+
resultCallback = { sendApduResult = it },
|
|
538
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
527
539
|
))
|
|
528
540
|
|
|
529
541
|
// Send APDU should not have been called
|
|
@@ -552,7 +564,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
552
564
|
var error: Throwable? = null
|
|
553
565
|
|
|
554
566
|
val stateMachine = DeviceConnectionStateMachine(
|
|
555
|
-
sendApduFn = { },
|
|
567
|
+
sendApduFn = { _,_ -> },
|
|
556
568
|
onTerminated = { terminated = true },
|
|
557
569
|
isFatalSendApduFailure = { false },
|
|
558
570
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -568,7 +580,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
568
580
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
569
581
|
apdu = mockedRequestApduA,
|
|
570
582
|
triggersDisconnection = false,
|
|
571
|
-
resultCallback = { result -> sendApduResult = result }
|
|
583
|
+
resultCallback = { result -> sendApduResult = result },
|
|
584
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
572
585
|
))
|
|
573
586
|
|
|
574
587
|
// Request closing the connection
|
|
@@ -592,7 +605,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
592
605
|
var error: Throwable? = null
|
|
593
606
|
|
|
594
607
|
val stateMachine = DeviceConnectionStateMachine(
|
|
595
|
-
sendApduFn = { },
|
|
608
|
+
sendApduFn = { _,_ -> },
|
|
596
609
|
onTerminated = { terminated = true },
|
|
597
610
|
isFatalSendApduFailure = { false },
|
|
598
611
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -608,7 +621,8 @@ class DeviceConnectionStateMachineTest {
|
|
|
608
621
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
609
622
|
apdu = byteArrayOf(0x0A),
|
|
610
623
|
triggersDisconnection = false,
|
|
611
|
-
resultCallback = { result -> sendApduResult = result }
|
|
624
|
+
resultCallback = { result -> sendApduResult = result },
|
|
625
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
612
626
|
))
|
|
613
627
|
|
|
614
628
|
// Simulate timeout
|
|
@@ -631,7 +645,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
631
645
|
var error: Throwable? = null
|
|
632
646
|
|
|
633
647
|
val stateMachine = DeviceConnectionStateMachine(
|
|
634
|
-
sendApduFn = { },
|
|
648
|
+
sendApduFn = { _,_ -> },
|
|
635
649
|
onTerminated = { terminated = true },
|
|
636
650
|
isFatalSendApduFailure = { false },
|
|
637
651
|
reconnectionTimeoutDuration = 5.seconds,
|
|
@@ -647,14 +661,16 @@ class DeviceConnectionStateMachineTest {
|
|
|
647
661
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
648
662
|
apdu = byteArrayOf(0x0A),
|
|
649
663
|
triggersDisconnection = false,
|
|
650
|
-
resultCallback = { firstSendApduResult = it }
|
|
664
|
+
resultCallback = { firstSendApduResult = it },
|
|
665
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
651
666
|
))
|
|
652
667
|
|
|
653
668
|
// Second APDU sending request
|
|
654
669
|
stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
|
|
655
670
|
apdu = byteArrayOf(0x0B),
|
|
656
671
|
triggersDisconnection = false,
|
|
657
|
-
resultCallback = { secondSendApduResult = it }
|
|
672
|
+
resultCallback = { secondSendApduResult = it },
|
|
673
|
+
abortTimeoutDuration = Duration.INFINITE
|
|
658
674
|
))
|
|
659
675
|
|
|
660
676
|
// Second request should immediately return busy.
|
|
@@ -683,7 +699,7 @@ class DeviceConnectionStateMachineTest {
|
|
|
683
699
|
var errorCalled: Throwable? = null
|
|
684
700
|
|
|
685
701
|
val stateMachine = DeviceConnectionStateMachine(
|
|
686
|
-
sendApduFn = { },
|
|
702
|
+
sendApduFn = { _,_ -> },
|
|
687
703
|
onTerminated = { },
|
|
688
704
|
isFatalSendApduFailure = { false },
|
|
689
705
|
reconnectionTimeoutDuration = reconnectionTimeout,
|
|
@@ -11,6 +11,7 @@ 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
|
|
14
15
|
import kotlin.time.Duration.Companion.milliseconds
|
|
15
16
|
|
|
16
17
|
/**
|
|
@@ -34,7 +35,7 @@ class DeviceConnectionTest {
|
|
|
34
35
|
)
|
|
35
36
|
|
|
36
37
|
// Request sending an APDU
|
|
37
|
-
deviceConnection.requestSendApdu(mockedApdu)
|
|
38
|
+
deviceConnection.requestSendApdu(apdu=mockedApdu, triggersDisconnection = false, abortTimeoutDuration = Duration.INFINITE)
|
|
38
39
|
|
|
39
40
|
// Send APDU should have been called once with the correct apdu
|
|
40
41
|
assertEquals(1, apduSender.sendCalls.size)
|
|
@@ -59,7 +60,7 @@ class DeviceConnectionTest {
|
|
|
59
60
|
)
|
|
60
61
|
|
|
61
62
|
// Request sending an apdu
|
|
62
|
-
val result1 = deviceConnection.requestSendApdu(apduTriggeringDisconnection)
|
|
63
|
+
val result1 = deviceConnection.requestSendApdu(apdu=apduTriggeringDisconnection, triggersDisconnection = false, abortTimeoutDuration = Duration.INFINITE)
|
|
63
64
|
|
|
64
65
|
// apduSender1.sendApdu should have been called once with the correct apdu
|
|
65
66
|
assertEquals(1, apduSender1.sendCalls.size)
|
|
@@ -70,7 +71,7 @@ class DeviceConnectionTest {
|
|
|
70
71
|
|
|
71
72
|
// Request sending a second apdu
|
|
72
73
|
val result2 = async {
|
|
73
|
-
deviceConnection.requestSendApdu(mockedApdu)
|
|
74
|
+
deviceConnection.requestSendApdu(apdu = mockedApdu, triggersDisconnection = false, abortTimeoutDuration = Duration.INFINITE)
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
// apduSender1.sendApdu shouldn't have been called again
|
|
@@ -139,7 +140,7 @@ class DeviceConnectionTest {
|
|
|
139
140
|
|
|
140
141
|
// Request sending an APDU
|
|
141
142
|
val result = async {
|
|
142
|
-
deviceConnection.requestSendApdu(mockedApdu)
|
|
143
|
+
deviceConnection.requestSendApdu(apdu = mockedApdu, triggersDisconnection = false, abortTimeoutDuration = Duration.INFINITE)
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
// Simulate reconnection
|
|
@@ -202,7 +203,10 @@ class DeviceConnectionTest {
|
|
|
202
203
|
val sendCalls: MutableList<ByteArray>
|
|
203
204
|
get() = _sendCalls
|
|
204
205
|
|
|
205
|
-
override suspend fun send(
|
|
206
|
+
override suspend fun send(
|
|
207
|
+
apdu: ByteArray,
|
|
208
|
+
abortTimeoutDuration: Duration
|
|
209
|
+
): SendApduResult {
|
|
206
210
|
_sendCalls += apdu
|
|
207
211
|
return nextResult
|
|
208
212
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
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
|
|
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 n in e)d(i,n,{get:e[n],enumerable:!0})},E=(i,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of p(e))!D.call(i,t)&&t!==n&&d(i,t,{get:()=>e[t],enumerable:!(o=l(e,t))||o.enumerable});return i};var y=i=>E(d({},"__esModule",{value:!0}),i);var T={};m(T,{DefaultNativeModuleWrapper:()=>M});module.exports=y(T);var c=require("react-native"),v=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 v.Observable(e=>{const o=new c.NativeEventEmitter(this._nativeModule).addListener(a.DISCOVERED_DEVICES_EVENT,t=>{e.next(t.map(s=>(0,r.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(s,this._deviceModelDataSource)).filter(s=>s!==null))});return()=>{o.remove()}})}subscribeToDeviceDisconnectedEvents(){return new v.Observable(e=>{const o=new c.NativeEventEmitter(this._nativeModule).addListener(a.DEVICE_DISCONNECTED_EVENT,t=>{e.next((0,r.mapNativeDeviceConnectionLostToDeviceDisconnected)(t))});return()=>{o.remove()}})}subscribeToTransportLogs(){return new v.Observable(e=>{const o=new c.NativeEventEmitter(this._nativeModule).addListener(a.TRANSPORT_LOG_EVENT,t=>{e.next((0,r.mapNativeTransportLogToLog)(t))});return()=>{o.remove()}})}async connectDevice(e){const n=await this._nativeModule.connectDevice(e);return(0,r.mapNativeConnectionResultToConnectionResult)(n,this._deviceModelDataSource)}async disconnectDevice(e){return this._nativeModule.disconnectDevice(e)}async sendApdu(e,n,o,t){const s=await this._nativeModule.sendApdu(e,(0,u.uint8ArrayToBase64)(n),o,t);return(0,r.mapNativeSendApduResultToSendApduResult)(s)}}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 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
|
|
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,
|
|
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"]
|
|
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(\n sessionId: string,\n apdu: Uint8Array,\n triggersDisconnection: boolean,\n abortTimeout: number,\n ): Promise<SendApduResult> {\n const nSendApduResult = await this._nativeModule.sendApdu(\n sessionId,\n uint8ArrayToBase64(apdu),\n triggersDisconnection,\n abortTimeout,\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,SACJA,EACAC,EACAC,EACAC,EACyB,CACzB,MAAMC,EAAkB,MAAM,KAAK,cAAc,SAC/CJ,KACA,sBAAmBC,CAAI,EACvBC,EACAC,CACF,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", "triggersDisconnection", "abortTimeout", "nSendApduResult"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var p=Object.defineProperty;var
|
|
1
|
+
"use strict";var p=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var d=(e,o)=>{for(var r in o)p(e,r,{get:o[r],enumerable:!0})},l=(e,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of M(o))!T.call(e,t)&&t!==r&&p(e,t,{get:()=>o[t],enumerable:!(a=i(o,t))||a.enumerable});return e};var n=e=>l(p({},"__esModule",{value:!0}),e);var m={};d(m,{NativeTransportModule:()=>u});module.exports=n(m);var s=require("react-native");const u=s.NativeModules.LDMKTransportHIDModule;0&&(module.exports={NativeTransportModule});
|
|
2
2
|
//# sourceMappingURL=NativeTransportModule.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/NativeTransportModule.ts"],
|
|
4
|
-
"sourcesContent": ["import { NativeModules } from \"react-native\";\n\nimport type { NativeTransportModuleType } from \"./types\";\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const NativeTransportModule: NativeTransportModuleType =\n NativeModules[\"
|
|
4
|
+
"sourcesContent": ["import { NativeModules } from \"react-native\";\n\nimport type { NativeTransportModuleType } from \"./types\";\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nexport const NativeTransportModule: NativeTransportModuleType =\n NativeModules[\"LDMKTransportHIDModule\"];\n"],
|
|
5
5
|
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,2BAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAA8B,wBAKvB,MAAMF,EACX,gBAAc",
|
|
6
6
|
"names": ["NativeTransportModule_exports", "__export", "NativeTransportModule", "__toCommonJS", "import_react_native"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var o in t)a(e,o,{get:t[o],enumerable:!0})},f=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of l(t))!m.call(e,i)&&i!==o&&a(e,i,{get:()=>t[i],enumerable:!(s=v(t,i))||s.enumerable});return e};var y=e=>f(a({},"__esModule",{value:!0}),e);var b={};D(b,{mapNativeConnectionResultToConnectionResult:()=>R,mapNativeDeviceConnectionLostToDeviceDisconnected:()=>T,mapNativeDiscoveryDeviceToTransportDiscoveredDevice:()=>N,mapNativeLedgerDeviceToDeviceModel:()=>c,mapNativeSendApduResultToSendApduResult:()=>L,mapNativeTransportLogToLog:()=>g});module.exports=y(b);var r=require("@ledgerhq/device-management-kit"),n=require("purify-ts"),d=require("../helpers/base64Utils"),p=require("../transport/Errors"),u=require("../transport/rnHidTransportIdentifier");function c(e,t){return t.filterDeviceModels({usbProductId:Number.parseInt(e.usbProductIdMask,16)})[0]??null}function N(e,t){const o=c(e.ledgerDevice,t);return o==null?null:{id:e.uid,deviceModel:o,transport:u.TRANSPORT_IDENTIFIER,name:e.name}}function g(e){let t;switch(e.level){case"error":t=r.LogLevel.Error;break;case"warning":t=r.LogLevel.Warning;break;case"info":t=r.LogLevel.Info;break;case"debug":t=r.LogLevel.Debug;break;default:I(e.level),t=r.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 R(e,t){if(e.success){const o=c(e.ledgerDevice,t);return o?(0,n.Right)({sessionId:e.sessionId,transportDeviceModel:o}):(0,n.Left)(new r.OpeningConnectionError(`Could not find device model for the connected device with usbProductIdMask: ${e.ledgerDevice.usbProductIdMask}`))}else return(0,n.Left)(new r.OpeningConnectionError(e.error))}function L(e){if(e.success){const t=(0,d.base64ToUint8Array)(e.apdu),o=r.FramerUtils.getFirstBytesFrom(t,t.length-2),s=r.FramerUtils.getLastBytesFrom(t,2);return(0,n.Right)(new r.ApduResponse({data:o,statusCode:s}))}else return e.error==="SendApduTimeout"?(0,n.Left)(new r.SendApduTimeoutError("Abort timeout")):e.error==="EmptyResponse"?(0,n.Left)(new r.SendApduEmptyResponseError("Empty response")):(0,n.Left)(new p.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 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,
|
|
4
|
+
"sourcesContent": ["import {\n ApduResponse,\n type DeviceModelDataSource,\n FramerUtils,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\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 if (result.error === \"SendApduTimeout\") {\n return Left(new SendApduTimeoutError(\"Abort timeout\"));\n } else if (result.error === \"EmptyResponse\") {\n return Left(new SendApduEmptyResponseError(\"Empty response\"));\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,EAYO,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,KAAO,QAAIJ,EAAO,QAAU,qBACnB,QAAK,IAAI,uBAAqB,eAAe,CAAC,EAC5CA,EAAO,QAAU,mBACnB,QAAK,IAAI,6BAA2B,gBAAgB,CAAC,KAErD,QAAK,IAAI,gBAAcA,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"),n=require("purify-ts"),
|
|
1
|
+
"use strict";var e=require("@ledgerhq/device-management-kit"),n=require("purify-ts"),d=require("../transport/Errors"),c=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:c.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 d.SendApduError("error message"));expect((0,o.mapNativeSendApduResultToSendApduResult)(s)).toEqual(t)}),test("timeout error",()=>{const s={success:!1,error:"SendApduTimeout"},t=(0,n.Left)(new e.SendApduTimeoutError("Abort timeout"));expect((0,o.mapNativeSendApduResultToSendApduResult)(s)).toEqual(t)}),test("empty response error",()=>{const s={success:!1,error:"EmptyResponse"},t=(0,n.Left)(new e.SendApduEmptyResponseError("Empty response"));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 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": "aAAA,IAAAA,
|
|
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 { 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 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": "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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 s=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var o in e)s(t,o,{get:e[o],enumerable:!0})},d=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of a(e))!c.call(t,i)&&i!==o&&s(t,i,{get:()=>e[i],enumerable:!(r=n(e,i))||r.enumerable});return t};var p=t=>d(s({},"__esModule",{value:!0}),t);var N={};v(N,{DEVICE_DISCONNECTED_EVENT:()=>D,DISCOVERED_DEVICES_EVENT:()=>g,TRANSPORT_LOG_EVENT:()=>u});module.exports=p(N);const g="DiscoveredDevices",u="TransportLog",D="DeviceDisconnected";0&&(module.exports={DEVICE_DISCONNECTED_EVENT,DISCOVERED_DEVICES_EVENT,TRANSPORT_LOG_EVENT});
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/types.ts"],
|
|
4
|
-
"sourcesContent": ["import { type NativeModule } from \"react-native\";\n\nexport type NativeLedgerDevice = {\n name: \"NanoS\" | \"NanoSPlus\" | \"NanoX\" | \"Flex\" | \"Stax\";\n usbProductIdMask: string;\n};\n\nexport type NativeDiscoveryDevice = {\n uid: string;\n name: string;\n ledgerDevice: NativeLedgerDevice;\n};\n\ntype NativeLogLevel = \"debug\" | \"info\" | \"warning\" | \"error\";\n\nexport type NativeLog = {\n level: NativeLogLevel;\n tag: string;\n message: string;\n jsonPayload: Record<string, string>;\n timestamp: string;\n};\n\nexport type NativeInternalConnectionResult =\n | {\n success: true;\n sessionId: string;\n ledgerDevice: NativeLedgerDevice;\n deviceName: string;\n }\n | {\n success: false;\n error: string;\n };\n\nexport type NativeSendApduResult =\n | {\n success: true;\n apdu: string;\n }\n | {\n success: false;\n error: string;\n };\n\nexport type NativeDeviceConnectionLost = {\n id: string;\n};\n\n/**\n * Events\n */\n\n/** DiscoveredDevices */\nexport const DISCOVERED_DEVICES_EVENT = \"DiscoveredDevices\";\nexport type DiscoveredDevicesEventPayload = Array<NativeDiscoveryDevice>;\n\n/** TransportLog */\nexport const TRANSPORT_LOG_EVENT = \"TransportLog\";\nexport type LogEventPayload = NativeLog;\n\n/** DeviceDisconnected */\nexport const DEVICE_DISCONNECTED_EVENT = \"DeviceDisconnected\";\nexport type DeviceDisconnectedEventPayload = NativeDeviceConnectionLost;\n\n/**\n * Signature of the native transport module.\n */\nexport type NativeTransportModuleType = {\n startScan: () => Promise<void>;\n stopScan: () => Promise<void>;\n connectDevice: (uid: string) => Promise<NativeInternalConnectionResult>;\n disconnectDevice: (sessionId: string) => Promise<void>;\n sendApdu: (sessionId: string
|
|
4
|
+
"sourcesContent": ["import { type NativeModule } from \"react-native\";\n\nexport type NativeLedgerDevice = {\n name: \"NanoS\" | \"NanoSPlus\" | \"NanoX\" | \"Flex\" | \"Stax\";\n usbProductIdMask: string;\n};\n\nexport type NativeDiscoveryDevice = {\n uid: string;\n name: string;\n ledgerDevice: NativeLedgerDevice;\n};\n\ntype NativeLogLevel = \"debug\" | \"info\" | \"warning\" | \"error\";\n\nexport type NativeLog = {\n level: NativeLogLevel;\n tag: string;\n message: string;\n jsonPayload: Record<string, string>;\n timestamp: string;\n};\n\nexport type NativeInternalConnectionResult =\n | {\n success: true;\n sessionId: string;\n ledgerDevice: NativeLedgerDevice;\n deviceName: string;\n }\n | {\n success: false;\n error: string;\n };\n\nexport type NativeSendApduResult =\n | {\n success: true;\n apdu: string;\n }\n | {\n success: false;\n error: string | \"SendApduTimeout\";\n };\n\nexport type NativeDeviceConnectionLost = {\n id: string;\n};\n\n/**\n * Events\n */\n\n/** DiscoveredDevices */\nexport const DISCOVERED_DEVICES_EVENT = \"DiscoveredDevices\";\nexport type DiscoveredDevicesEventPayload = Array<NativeDiscoveryDevice>;\n\n/** TransportLog */\nexport const TRANSPORT_LOG_EVENT = \"TransportLog\";\nexport type LogEventPayload = NativeLog;\n\n/** DeviceDisconnected */\nexport const DEVICE_DISCONNECTED_EVENT = \"DeviceDisconnected\";\nexport type DeviceDisconnectedEventPayload = NativeDeviceConnectionLost;\n\n/**\n * Signature of the native transport module.\n */\nexport type NativeTransportModuleType = {\n startScan: () => Promise<void>;\n stopScan: () => Promise<void>;\n connectDevice: (uid: string) => Promise<NativeInternalConnectionResult>;\n disconnectDevice: (sessionId: string) => Promise<void>;\n sendApdu: (\n sessionId: string,\n apdu: string,\n triggersDisconnection: boolean,\n abortTimeout: number,\n ) => Promise<NativeSendApduResult>;\n} & NativeModule;\n"],
|
|
5
5
|
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,6BAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAL,GAsDO,MAAMG,EAA2B,oBAI3BC,EAAsB,eAItBF,EAA4B",
|
|
6
6
|
"names": ["types_exports", "__export", "DEVICE_DISCONNECTED_EVENT", "DISCOVERED_DEVICES_EVENT", "TRANSPORT_LOG_EVENT", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var d=(r,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of c(e))!a.call(r,s)&&s!==i&&o(r,s,{get:()=>e[s],enumerable:!(n=t(e,s))||n.enumerable});return r};var v=r=>d(o({},"__esModule",{value:!0}),r);var p={};module.exports=v(p);
|
|
2
2
|
//# sourceMappingURL=NativeModuleWrapper.js.map
|