@ledgerhq/device-transport-kit-react-native-hid 0.0.0-develop-20250903001157 → 0.0.0-e2e-speculos-20250904104129

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/android/src/main/kotlin/com/ledger/androidtransporthid/TransportHidModule.kt +3 -12
  2. package/android/src/main/kotlin/com/ledger/androidtransporthid/bridge/serialization.kt +0 -2
  3. package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/DefaultAndroidUsbTransport.kt +23 -85
  4. package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/connection/AndroidUsbApduSender.kt +29 -70
  5. package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceApduSender.kt +1 -2
  6. package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnection.kt +4 -5
  7. package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionStateMachine.kt +33 -103
  8. package/android/src/main/kotlin/com/ledger/devicesdk/shared/api/apdu/SendApduResult.kt +0 -4
  9. package/android/src/main/kotlin/com/ledger/devicesdk/shared/internal/connection/InternalConnectedDevice.kt +1 -1
  10. package/android/src/test/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionStateMachineTest.kt +46 -189
  11. package/android/src/test/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionTest.kt +5 -9
  12. package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js +1 -1
  13. package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
  14. package/lib/cjs/api/bridge/mapper.js +1 -1
  15. package/lib/cjs/api/bridge/mapper.js.map +2 -2
  16. package/lib/cjs/api/bridge/mapper.test.js +1 -1
  17. package/lib/cjs/api/bridge/mapper.test.js.map +2 -2
  18. package/lib/cjs/api/bridge/types.js +1 -1
  19. package/lib/cjs/api/bridge/types.js.map +1 -1
  20. package/lib/cjs/api/transport/Errors.js +1 -1
  21. package/lib/cjs/api/transport/Errors.js.map +3 -3
  22. package/lib/cjs/api/transport/NativeModuleWrapper.js +1 -1
  23. package/lib/cjs/api/transport/NativeModuleWrapper.js.map +1 -1
  24. package/lib/cjs/api/transport/RNHidTransport.js +1 -1
  25. package/lib/cjs/api/transport/RNHidTransport.js.map +3 -3
  26. package/lib/cjs/api/transport/RNHidTransport.test.js +1 -1
  27. package/lib/cjs/api/transport/RNHidTransport.test.js.map +2 -2
  28. package/lib/cjs/package.json +1 -1
  29. package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js +1 -1
  30. package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
  31. package/lib/esm/api/bridge/mapper.js +1 -1
  32. package/lib/esm/api/bridge/mapper.js.map +3 -3
  33. package/lib/esm/api/bridge/mapper.test.js +1 -1
  34. package/lib/esm/api/bridge/mapper.test.js.map +3 -3
  35. package/lib/esm/api/bridge/types.js.map +1 -1
  36. package/lib/esm/api/transport/Errors.js +1 -1
  37. package/lib/esm/api/transport/Errors.js.map +3 -3
  38. package/lib/esm/api/transport/RNHidTransport.js +1 -1
  39. package/lib/esm/api/transport/RNHidTransport.js.map +3 -3
  40. package/lib/esm/api/transport/RNHidTransport.test.js +1 -1
  41. package/lib/esm/api/transport/RNHidTransport.test.js.map +3 -3
  42. package/lib/esm/package.json +1 -1
  43. package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts +1 -1
  44. package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts.map +1 -1
  45. package/lib/types/api/bridge/mapper.d.ts.map +1 -1
  46. package/lib/types/api/bridge/types.d.ts +2 -2
  47. package/lib/types/api/bridge/types.d.ts.map +1 -1
  48. package/lib/types/api/transport/Errors.d.ts +1 -1
  49. package/lib/types/api/transport/Errors.d.ts.map +1 -1
  50. package/lib/types/api/transport/NativeModuleWrapper.d.ts +1 -1
  51. package/lib/types/api/transport/NativeModuleWrapper.d.ts.map +1 -1
  52. package/lib/types/api/transport/RNHidTransport.d.ts.map +1 -1
  53. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  54. package/package.json +6 -6
@@ -2,7 +2,6 @@ package com.ledger.devicesdk.shared.androidMainInternal.transport.deviceconnecti
2
2
 
3
3
  import com.ledger.devicesdk.shared.api.apdu.SendApduFailureReason
4
4
  import com.ledger.devicesdk.shared.api.apdu.SendApduResult
5
- import com.ledger.devicesdk.shared.api.utils.fromHexStringToBytesOrThrow
6
5
  import com.ledger.devicesdk.shared.internal.service.logger.LogInfo
7
6
  import com.ledger.devicesdk.shared.internal.service.logger.LoggerService
8
7
  import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -13,7 +12,6 @@ import kotlin.time.Duration
13
12
  import kotlin.time.Duration.Companion.seconds
14
13
  import kotlin.test.Test
15
14
  import org.junit.Assert.*
16
- import kotlin.test.assertIs
17
15
  import kotlin.time.Duration.Companion.milliseconds
18
16
 
19
17
  @OptIn(ExperimentalCoroutinesApi::class)
@@ -27,7 +25,7 @@ class DeviceConnectionStateMachineTest {
27
25
  var sendApduResult: SendApduResult? = null
28
26
 
29
27
  val stateMachine = DeviceConnectionStateMachine(
30
- sendApduFn = { apdu, _ -> sendApduCalled = apdu },
28
+ sendApduFn = { apdu -> sendApduCalled = apdu },
31
29
  onTerminated = { terminated = true },
32
30
  isFatalSendApduFailure = { false },
33
31
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -40,8 +38,7 @@ class DeviceConnectionStateMachineTest {
40
38
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
41
39
  apdu = mockedRequestApduA,
42
40
  triggersDisconnection = false,
43
- resultCallback = { result -> sendApduResult = result },
44
- abortTimeoutDuration = Duration.INFINITE
41
+ resultCallback = { result -> sendApduResult = result }
45
42
  ))
46
43
  assertArrayEquals(mockedRequestApduA, sendApduCalled)
47
44
 
@@ -68,7 +65,7 @@ class DeviceConnectionStateMachineTest {
68
65
  var error: Throwable? = null
69
66
 
70
67
  val stateMachine = DeviceConnectionStateMachine(
71
- sendApduFn = { _, _ -> },
68
+ sendApduFn = { },
72
69
  onTerminated = { terminated = true },
73
70
  isFatalSendApduFailure = { true }, // All failures are fatal
74
71
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -80,8 +77,7 @@ class DeviceConnectionStateMachineTest {
80
77
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
81
78
  apdu = mockedRequestApduA,
82
79
  triggersDisconnection = false,
83
- resultCallback = { result -> sendApduResult = result },
84
- abortTimeoutDuration = Duration.INFINITE
80
+ resultCallback = { result -> sendApduResult = result }
85
81
  ))
86
82
 
87
83
  // Simulate a failure
@@ -90,7 +86,7 @@ class DeviceConnectionStateMachineTest {
90
86
  stateMachine.handleApduResult(mockedFailureResult)
91
87
 
92
88
  // Then
93
- assertEquals(mockedFailureResult, sendApduResult)
89
+ assertEquals(sendApduResult, mockedFailureResult)
94
90
  assertTrue(terminated)
95
91
  assertNull(error)
96
92
  }
@@ -103,7 +99,7 @@ class DeviceConnectionStateMachineTest {
103
99
  var error: Throwable? = null
104
100
 
105
101
  val stateMachine = DeviceConnectionStateMachine(
106
- sendApduFn = { _, _ -> },
102
+ sendApduFn = { },
107
103
  onTerminated = { terminated = true },
108
104
  isFatalSendApduFailure = { false },
109
105
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -116,8 +112,7 @@ class DeviceConnectionStateMachineTest {
116
112
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
117
113
  apdu = mockedRequestApduA,
118
114
  triggersDisconnection = false,
119
- resultCallback = { result -> sendApduResult = result },
120
- abortTimeoutDuration = Duration.INFINITE
115
+ resultCallback = { result -> sendApduResult = result }
121
116
  ))
122
117
 
123
118
  // Simulate a failure
@@ -136,15 +131,16 @@ class DeviceConnectionStateMachineTest {
136
131
  }
137
132
 
138
133
  @Test
139
- fun `GIVEN the device connection state machine WHEN an APDU with triggersDisconnection is sent and triggers a disconnection THEN the machine moves to WaitingForReconnection and recovers when device reconnects`() =
134
+ fun `GIVEN the device connection state machine WHEN an APDU with triggersDisconnection is sent THEN the machine moves to WaitingForReconnection and recovers when device reconnects`() =
140
135
  runTest {
141
136
  var sendApduCalled: ByteArray? = null
142
137
  var sendApduResult: SendApduResult? = null
143
138
  var terminated = false
144
139
  var error: Throwable? = null
145
140
 
141
+ val dispatcher = StandardTestDispatcher(testScheduler)
146
142
  val stateMachine = DeviceConnectionStateMachine(
147
- sendApduFn = { apdu, _ -> sendApduCalled = apdu },
143
+ sendApduFn = { apdu -> sendApduCalled = apdu },
148
144
  onTerminated = { terminated = true },
149
145
  isFatalSendApduFailure = { false },
150
146
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -157,8 +153,7 @@ class DeviceConnectionStateMachineTest {
157
153
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
158
154
  apdu = mockedRequestApduA,
159
155
  triggersDisconnection = true,
160
- resultCallback = { result -> sendApduResult = result },
161
- abortTimeoutDuration = Duration.INFINITE
156
+ resultCallback = { result -> sendApduResult = result }
162
157
  ))
163
158
 
164
159
  // Send APDU should have been called
@@ -168,10 +163,6 @@ class DeviceConnectionStateMachineTest {
168
163
  val mockedSuccessApduResult = SendApduResult.Success(mockedResultApduSuccessA)
169
164
  stateMachine.handleApduResult(mockedSuccessApduResult)
170
165
 
171
- assertNull(sendApduResult)
172
- // Simulate a disconnection
173
- stateMachine.handleDeviceDisconnected()
174
-
175
166
  // Result should have been returned
176
167
  assertEquals(mockedSuccessApduResult, sendApduResult)
177
168
 
@@ -189,8 +180,7 @@ class DeviceConnectionStateMachineTest {
189
180
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
190
181
  apdu = mockedRequestApduB,
191
182
  triggersDisconnection = false,
192
- resultCallback = { secondSendApduResult = it },
193
- abortTimeoutDuration = Duration.INFINITE
183
+ resultCallback = { secondSendApduResult = it }
194
184
  ))
195
185
 
196
186
  // Send APDU should have been called
@@ -208,125 +198,14 @@ class DeviceConnectionStateMachineTest {
208
198
  }
209
199
 
210
200
  @Test
211
- fun `GIVEN the device connection state machine WHEN an APDU with triggersDisconnection is sent and device does not disconnect THEN the machine moves to Connected`() =
212
- runTest {
213
- var sendApduCalled: ByteArray? = null
214
- var sendApduResult: SendApduResult? = null
215
- var terminated = false
216
- var error: Throwable? = null
217
-
218
- val stateMachine = DeviceConnectionStateMachine(
219
- sendApduFn = { apdu, _ -> sendApduCalled = apdu },
220
- onTerminated = { terminated = true },
221
- isFatalSendApduFailure = { false },
222
- reconnectionTimeoutDuration = reconnectionTimeout,
223
- onError = { error = it },
224
- loggerService = FakeLoggerService(),
225
- coroutineDispatcher = StandardTestDispatcher(testScheduler)
226
- )
227
-
228
- // Request sending an APDU (with triggersDisconnection = true)
229
- stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
230
- apdu = mockedRequestApduA,
231
- triggersDisconnection = true,
232
- resultCallback = { result -> sendApduResult = result },
233
- abortTimeoutDuration = Duration.INFINITE
234
- ))
235
-
236
- // Send APDU should have been called
237
- assertArrayEquals(mockedRequestApduA, sendApduCalled)
238
-
239
- // Simulate a successful response
240
- val mockedSuccessApduResult = SendApduResult.Success(mockedResultApduSuccessA)
241
- stateMachine.handleApduResult(mockedSuccessApduResult)
242
-
243
- assertNull(sendApduResult)
244
-
245
- // Simulate Response from GetAppAndVersion
246
- val mockedSuccessApduResultGetAppAndVersion = SendApduResult.Success(mockedGetAppAndVersionSuccessfulResponse)
247
- stateMachine.handleApduResult(mockedSuccessApduResultGetAppAndVersion)
248
-
249
- // Should be in Connected state
250
- assertEquals(
251
- DeviceConnectionStateMachine.State.Connected,
252
- stateMachine.getState()
253
- )
254
-
255
- // Response should have been returned
256
- assertEquals(mockedSuccessApduResult, sendApduResult)
257
- }
258
-
259
- @Test
260
- fun `GIVEN the device connection state machine WHEN an APDU with triggersDisconnection is sent and device does not disconnect but is first busy THEN the machine retries and moves to Connected`() =
261
- runTest {
262
- var sendApduCalled: ByteArray? = null
263
- var sendApduResult: SendApduResult? = null
264
- var terminated = false
265
- var error: Throwable? = null
266
-
267
- val stateMachine = DeviceConnectionStateMachine(
268
- sendApduFn = { apdu, _ -> sendApduCalled = apdu },
269
- onTerminated = { terminated = true },
270
- isFatalSendApduFailure = { false },
271
- reconnectionTimeoutDuration = reconnectionTimeout,
272
- onError = { error = it },
273
- loggerService = FakeLoggerService(),
274
- coroutineDispatcher = StandardTestDispatcher(testScheduler)
275
- )
276
-
277
- // Request sending an APDU (with triggersDisconnection = true)
278
- stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
279
- apdu = mockedRequestApduA,
280
- triggersDisconnection = true,
281
- resultCallback = { result -> sendApduResult = result },
282
- abortTimeoutDuration = Duration.INFINITE
283
- ))
284
-
285
- // Send APDU should have been called
286
- assertArrayEquals(mockedRequestApduA, sendApduCalled)
287
-
288
- // Simulate a successful response
289
- val mockedSuccessApduResult = SendApduResult.Success(mockedResultApduSuccessA)
290
- stateMachine.handleApduResult(mockedSuccessApduResult)
291
-
292
- assertNull(sendApduResult)
293
-
294
- assertIs<DeviceConnectionStateMachine.State.WaitingForDisconnection>(
295
- stateMachine.getState()
296
- )
297
-
298
- // Simulate Busy Response from GetAppAndVersion
299
- val mockedBusyApduResultGetAppAndVersion = SendApduResult.Success(mockedGetAppAndVersionBusyResponse)
300
- stateMachine.handleApduResult(mockedBusyApduResultGetAppAndVersion)
301
-
302
- assertIs<DeviceConnectionStateMachine.State.WaitingForDisconnection>(
303
- stateMachine.getState()
304
- )
305
-
306
- // Simulate Successful Response from GetAppAndVersion
307
- val mockedSuccessApduResultGetAppAndVersion = SendApduResult.Success(mockedGetAppAndVersionSuccessfulResponse)
308
- stateMachine.handleApduResult(mockedSuccessApduResultGetAppAndVersion)
309
-
310
- // Should be in Connected state
311
- assertEquals(
312
- DeviceConnectionStateMachine.State.Connected,
313
- stateMachine.getState()
314
- )
315
-
316
- // Response should have been returned
317
- assertEquals(mockedSuccessApduResult, sendApduResult)
318
- }
319
-
320
-
321
- @Test
322
- fun `GIVEN the device connection state machine WHEN an APDU with triggersDisconnection is sent and triggers a disconnection THEN the machine moves to WaitingForReconnection and the next APDU is queued until reconnection`() =
201
+ fun `GIVEN the device connection state machine WHEN an APDU with triggersDisconnection is sent THEN the machine moves to WaitingForReconnection and the next APDU is queued until reconnection`() =
323
202
  runTest {
324
203
  val sendApduCalled: MutableList<ByteArray> = mutableListOf()
325
204
  var terminated = false
326
205
  var error: Throwable? = null
327
206
 
328
207
  val stateMachine = DeviceConnectionStateMachine(
329
- sendApduFn = { apdu, _ -> sendApduCalled += apdu },
208
+ sendApduFn = { apdu -> sendApduCalled += apdu },
330
209
  onTerminated = { terminated = true },
331
210
  isFatalSendApduFailure = { false },
332
211
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -339,27 +218,17 @@ class DeviceConnectionStateMachineTest {
339
218
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
340
219
  apdu = mockedRequestApduA,
341
220
  triggersDisconnection = true,
342
- resultCallback = { },
343
- abortTimeoutDuration = Duration.INFINITE
221
+ resultCallback = { }
344
222
  ))
345
223
 
346
224
  // Simulate a successful response
347
225
  val mockedSuccessApduResult = SendApduResult.Success(mockedResultApduSuccessA)
348
226
  stateMachine.handleApduResult(mockedSuccessApduResult)
349
227
 
350
- // sendApduFn should have been called twice (for the mockedRequestApduA and an extra call for the getAppAndVersion APDU)
351
- assertEquals(2, sendApduCalled.size)
352
-
353
- // Should be in WaitingForDisconnection state
354
- assertIs<DeviceConnectionStateMachine.State.WaitingForDisconnection>(
355
- stateMachine.getState()
356
- )
357
-
358
- // Simulate disconnection
359
- stateMachine.handleDeviceDisconnected()
360
-
361
- // Should be in WaitingForReconnection state
228
+ // sendApduFn should have been called once
229
+ assertEquals(1, sendApduCalled.size)
362
230
 
231
+ // Should be in waiting state
363
232
  assertEquals(
364
233
  DeviceConnectionStateMachine.State.WaitingForReconnection,
365
234
  stateMachine.getState()
@@ -370,8 +239,7 @@ class DeviceConnectionStateMachineTest {
370
239
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
371
240
  apdu = mockedRequestApduB,
372
241
  triggersDisconnection = false,
373
- resultCallback = { secondSendApduResult = it },
374
- abortTimeoutDuration = Duration.INFINITE
242
+ resultCallback = { secondSendApduResult = it }
375
243
  ))
376
244
 
377
245
  // Should be in waiting state
@@ -381,7 +249,7 @@ class DeviceConnectionStateMachineTest {
381
249
  )
382
250
 
383
251
  // sendApduFn should not have been called one more time
384
- assertEquals(2, sendApduCalled.size)
252
+ assertEquals(1, sendApduCalled.size)
385
253
 
386
254
  // Simulate reconnection
387
255
  stateMachine.handleDeviceConnected()
@@ -392,9 +260,9 @@ class DeviceConnectionStateMachineTest {
392
260
  stateMachine.getState()::class
393
261
  )
394
262
 
395
- // Send APDU should have been called a 3rd time, and the result should have been returned
396
- assertEquals(3, sendApduCalled.size)
397
- assertArrayEquals(mockedRequestApduB, sendApduCalled[2])
263
+ // Send APDU should have been called a second time, and the result should have been returned
264
+ assertEquals(2, sendApduCalled.size)
265
+ assertArrayEquals(mockedRequestApduB, sendApduCalled[1])
398
266
 
399
267
  // Simulate a successful response
400
268
  val mockedSuccessApduResultB = SendApduResult.Success(mockedResultApduSuccessB)
@@ -421,7 +289,7 @@ class DeviceConnectionStateMachineTest {
421
289
  var error: Throwable? = null
422
290
 
423
291
  val stateMachine = DeviceConnectionStateMachine(
424
- sendApduFn = { _, _ -> },
292
+ sendApduFn = { },
425
293
  onTerminated = { terminated = true },
426
294
  isFatalSendApduFailure = { false },
427
295
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -434,8 +302,7 @@ class DeviceConnectionStateMachineTest {
434
302
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
435
303
  apdu = mockedRequestApduA,
436
304
  triggersDisconnection = false,
437
- resultCallback = { result -> sendApduResult = result },
438
- abortTimeoutDuration = Duration.INFINITE
305
+ resultCallback = { result -> sendApduResult = result }
439
306
  ))
440
307
 
441
308
  // Should be in sending state
@@ -464,7 +331,7 @@ class DeviceConnectionStateMachineTest {
464
331
  var error: Throwable? = null
465
332
 
466
333
  val stateMachine = DeviceConnectionStateMachine(
467
- sendApduFn = { _,_ -> },
334
+ sendApduFn = { },
468
335
  onTerminated = { terminated = true },
469
336
  isFatalSendApduFailure = { false },
470
337
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -477,8 +344,7 @@ class DeviceConnectionStateMachineTest {
477
344
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
478
345
  apdu = mockedRequestApduA,
479
346
  triggersDisconnection = false,
480
- resultCallback = { result -> sendApduResult = result },
481
- abortTimeoutDuration = Duration.INFINITE
347
+ resultCallback = { result -> sendApduResult = result }
482
348
  ))
483
349
 
484
350
  // Simulate a disconnection
@@ -518,7 +384,7 @@ class DeviceConnectionStateMachineTest {
518
384
  var error: Throwable? = null
519
385
 
520
386
  val stateMachine = DeviceConnectionStateMachine(
521
- sendApduFn = { _,_ -> },
387
+ sendApduFn = { },
522
388
  onTerminated = { terminated = true },
523
389
  isFatalSendApduFailure = { false },
524
390
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -531,8 +397,7 @@ class DeviceConnectionStateMachineTest {
531
397
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
532
398
  apdu = mockedRequestApduA,
533
399
  triggersDisconnection = false,
534
- resultCallback = { firstSendApduResult = it },
535
- abortTimeoutDuration = Duration.INFINITE
400
+ resultCallback = { firstSendApduResult = it }
536
401
  ))
537
402
 
538
403
  // Should be in sending state.
@@ -545,8 +410,7 @@ class DeviceConnectionStateMachineTest {
545
410
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
546
411
  apdu = mockedRequestApduB,
547
412
  triggersDisconnection = false,
548
- resultCallback = { secondSendApduResult = it },
549
- abortTimeoutDuration = Duration.INFINITE
413
+ resultCallback = { secondSendApduResult = it }
550
414
  ))
551
415
 
552
416
  assertEquals(
@@ -571,7 +435,7 @@ class DeviceConnectionStateMachineTest {
571
435
  var terminated = false
572
436
 
573
437
  val stateMachine = DeviceConnectionStateMachine(
574
- sendApduFn = { _,_ -> },
438
+ sendApduFn = { },
575
439
  onTerminated = { terminated = true },
576
440
  isFatalSendApduFailure = { false },
577
441
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -608,7 +472,7 @@ class DeviceConnectionStateMachineTest {
608
472
  var terminated = false
609
473
 
610
474
  val stateMachine = DeviceConnectionStateMachine(
611
- sendApduFn = { _,_ -> },
475
+ sendApduFn = { },
612
476
  onTerminated = { terminated = true },
613
477
  isFatalSendApduFailure = { false },
614
478
  reconnectionTimeoutDuration = 5.seconds,
@@ -643,7 +507,7 @@ class DeviceConnectionStateMachineTest {
643
507
  var error: Throwable? = null
644
508
 
645
509
  val stateMachine = DeviceConnectionStateMachine(
646
- sendApduFn = { apdu, _ -> sendApduCalled = apdu },
510
+ sendApduFn = { apdu -> sendApduCalled = apdu },
647
511
  onTerminated = { terminated = true },
648
512
  isFatalSendApduFailure = { false },
649
513
  reconnectionTimeoutDuration = 5.seconds,
@@ -659,8 +523,7 @@ class DeviceConnectionStateMachineTest {
659
523
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
660
524
  apdu = mockedRequestApduA,
661
525
  triggersDisconnection = false,
662
- resultCallback = { sendApduResult = it },
663
- abortTimeoutDuration = Duration.INFINITE
526
+ resultCallback = { sendApduResult = it }
664
527
  ))
665
528
 
666
529
  // Send APDU should not have been called
@@ -689,7 +552,7 @@ class DeviceConnectionStateMachineTest {
689
552
  var error: Throwable? = null
690
553
 
691
554
  val stateMachine = DeviceConnectionStateMachine(
692
- sendApduFn = { _,_ -> },
555
+ sendApduFn = { },
693
556
  onTerminated = { terminated = true },
694
557
  isFatalSendApduFailure = { false },
695
558
  reconnectionTimeoutDuration = 5.seconds,
@@ -705,8 +568,7 @@ class DeviceConnectionStateMachineTest {
705
568
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
706
569
  apdu = mockedRequestApduA,
707
570
  triggersDisconnection = false,
708
- resultCallback = { result -> sendApduResult = result },
709
- abortTimeoutDuration = Duration.INFINITE
571
+ resultCallback = { result -> sendApduResult = result }
710
572
  ))
711
573
 
712
574
  // Request closing the connection
@@ -730,7 +592,7 @@ class DeviceConnectionStateMachineTest {
730
592
  var error: Throwable? = null
731
593
 
732
594
  val stateMachine = DeviceConnectionStateMachine(
733
- sendApduFn = { _,_ -> },
595
+ sendApduFn = { },
734
596
  onTerminated = { terminated = true },
735
597
  isFatalSendApduFailure = { false },
736
598
  reconnectionTimeoutDuration = 5.seconds,
@@ -746,8 +608,7 @@ class DeviceConnectionStateMachineTest {
746
608
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
747
609
  apdu = byteArrayOf(0x0A),
748
610
  triggersDisconnection = false,
749
- resultCallback = { result -> sendApduResult = result },
750
- abortTimeoutDuration = Duration.INFINITE
611
+ resultCallback = { result -> sendApduResult = result }
751
612
  ))
752
613
 
753
614
  // Simulate timeout
@@ -770,7 +631,7 @@ class DeviceConnectionStateMachineTest {
770
631
  var error: Throwable? = null
771
632
 
772
633
  val stateMachine = DeviceConnectionStateMachine(
773
- sendApduFn = { _,_ -> },
634
+ sendApduFn = { },
774
635
  onTerminated = { terminated = true },
775
636
  isFatalSendApduFailure = { false },
776
637
  reconnectionTimeoutDuration = 5.seconds,
@@ -786,16 +647,14 @@ class DeviceConnectionStateMachineTest {
786
647
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
787
648
  apdu = byteArrayOf(0x0A),
788
649
  triggersDisconnection = false,
789
- resultCallback = { firstSendApduResult = it },
790
- abortTimeoutDuration = Duration.INFINITE
650
+ resultCallback = { firstSendApduResult = it }
791
651
  ))
792
652
 
793
653
  // Second APDU sending request
794
654
  stateMachine.requestSendApdu(DeviceConnectionStateMachine.SendApduRequestContent(
795
655
  apdu = byteArrayOf(0x0B),
796
656
  triggersDisconnection = false,
797
- resultCallback = { secondSendApduResult = it },
798
- abortTimeoutDuration = Duration.INFINITE
657
+ resultCallback = { secondSendApduResult = it }
799
658
  ))
800
659
 
801
660
  // Second request should immediately return busy.
@@ -824,7 +683,7 @@ class DeviceConnectionStateMachineTest {
824
683
  var errorCalled: Throwable? = null
825
684
 
826
685
  val stateMachine = DeviceConnectionStateMachine(
827
- sendApduFn = { _,_ -> },
686
+ sendApduFn = { },
828
687
  onTerminated = { },
829
688
  isFatalSendApduFailure = { false },
830
689
  reconnectionTimeoutDuration = reconnectionTimeout,
@@ -846,11 +705,9 @@ class DeviceConnectionStateMachineTest {
846
705
  }
847
706
 
848
707
  val reconnectionTimeout: Duration = 5.seconds
849
- val mockedRequestApduA: ByteArray = "1234".fromHexStringToBytesOrThrow()
850
- val mockedRequestApduB: ByteArray = "5678".fromHexStringToBytesOrThrow()
851
- val mockedGetAppAndVersionSuccessfulResponse: ByteArray = "12349000".fromHexStringToBytesOrThrow()
852
- val mockedGetAppAndVersionBusyResponse: ByteArray = "12346601".fromHexStringToBytesOrThrow()
853
- val mockedResultApduSuccessA: ByteArray = "56789000".fromHexStringToBytesOrThrow()
854
- val mockedResultApduSuccessB: ByteArray = "abcd9000".fromHexStringToBytesOrThrow()
708
+ val mockedRequestApduA: ByteArray = byteArrayOf(0x01, 0x02)
709
+ val mockedRequestApduB: ByteArray = byteArrayOf(0x03, 0x04)
710
+ val mockedResultApduSuccessA: ByteArray = byteArrayOf(0x05, 0x06, 0x90.toByte(), 0x00)
711
+ val mockedResultApduSuccessB: ByteArray = byteArrayOf(0x07, 0x08, 0x90.toByte(), 0x00)
855
712
  }
856
713
  }
@@ -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(apdu=mockedApdu, triggersDisconnection = false, abortTimeoutDuration = Duration.INFINITE)
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(apdu=apduTriggeringDisconnection, triggersDisconnection = false, abortTimeoutDuration = Duration.INFINITE)
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(apdu = mockedApdu, triggersDisconnection = false, abortTimeoutDuration = Duration.INFINITE)
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(apdu = mockedApdu, triggersDisconnection = false, abortTimeoutDuration = Duration.INFINITE)
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 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});
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 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"]
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 c=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var m=(e,t)=>{for(var r in t)c(e,r,{get:t[r],enumerable:!0})},f=(e,t,r,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of l(t))!D.call(e,i)&&i!==r&&c(e,i,{get:()=>t[i],enumerable:!(s=v(t,i))||s.enumerable});return e};var y=e=>f(c({},"__esModule",{value:!0}),e);var b={};m(b,{mapNativeConnectionResultToConnectionResult:()=>R,mapNativeDeviceConnectionLostToDeviceDisconnected:()=>L,mapNativeDiscoveryDeviceToTransportDiscoveredDevice:()=>N,mapNativeLedgerDeviceToDeviceModel:()=>a,mapNativeSendApduResultToSendApduResult:()=>T,mapNativeTransportLogToLog:()=>g});module.exports=y(b);var n=require("@ledgerhq/device-management-kit"),o=require("purify-ts"),d=require("../helpers/base64Utils"),p=require("../transport/Errors"),u=require("../transport/rnHidTransportIdentifier");function a(e,t){return t.filterDeviceModels({usbProductId:Number.parseInt(e.usbProductIdMask,16)})[0]??null}function N(e,t){const r=a(e.ledgerDevice,t);return r==null?null:{id:e.uid,deviceModel:r,transport:u.TRANSPORT_IDENTIFIER,name:e.name}}function g(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 R(e,t){if(e.success){const r=a(e.ledgerDevice,t);return r?(0,o.Right)({sessionId:e.sessionId,transportDeviceModel:r}):(0,o.Left)(new n.OpeningConnectionError(`Could not find device model for the connected device with usbProductIdMask: ${e.ledgerDevice.usbProductIdMask}`))}else return(0,o.Left)(new n.OpeningConnectionError(e.error))}function T(e){if(e.success){const t=(0,d.base64ToUint8Array)(e.apdu),r=n.FramerUtils.getFirstBytesFrom(t,t.length-2),s=n.FramerUtils.getLastBytesFrom(t,2);return(0,o.Right)(new n.ApduResponse({data:r,statusCode:s}))}else return e.error==="SendApduTimeout"?(0,o.Left)(new n.SendApduTimeoutError("Abort timeout")):e.error==="EmptyResponse"?(0,o.Left)(new n.SendApduEmptyResponseError("Empty response")):e.error==="DeviceDisconnected"?(0,o.Left)(new n.DeviceDisconnectedWhileSendingError("Device disconnected")):(0,o.Left)(new p.HidTransportSendApduUnknownError(e.error))}function L(e){return{sessionId:e.id}}0&&(module.exports={mapNativeConnectionResultToConnectionResult,mapNativeDeviceConnectionLostToDeviceDisconnected,mapNativeDiscoveryDeviceToTransportDiscoveredDevice,mapNativeLedgerDeviceToDeviceModel,mapNativeSendApduResultToSendApduResult,mapNativeTransportLogToLog});
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