@ledgerhq/device-transport-kit-react-native-hid 0.0.0-rn-hid-fixed-device-id-20250521115949 → 0.0.0-rn-hid-improvements-20250522140114
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 +25 -1
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/DefaultAndroidUsbTransport.kt +10 -9
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/connection/AndroidUsbApduSender.kt +49 -37
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/internal/transport/Transport.kt +2 -1
- package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js +1 -1
- package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
- package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js +1 -1
- package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
- package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -22,6 +22,7 @@ import com.ledger.devicesdk.shared.internal.connection.InternalConnectedDevice
|
|
|
22
22
|
import com.ledger.devicesdk.shared.internal.connection.InternalConnectionResult
|
|
23
23
|
import com.ledger.devicesdk.shared.internal.event.SdkEventDispatcher
|
|
24
24
|
import com.ledger.devicesdk.shared.internal.service.logger.LoggerService
|
|
25
|
+
import com.ledger.devicesdk.shared.internal.service.logger.buildSimpleDebugLogInfo
|
|
25
26
|
import com.ledger.devicesdk.shared.internal.transport.TransportEvent
|
|
26
27
|
import kotlinx.coroutines.CoroutineScope
|
|
27
28
|
import kotlinx.coroutines.Dispatchers
|
|
@@ -49,7 +50,7 @@ class TransportHidModule(
|
|
|
49
50
|
private val loggerService: LoggerService =
|
|
50
51
|
LoggerService { info ->
|
|
51
52
|
Timber.tag("LDMKTransportHIDModule " + info.tag).d(info.message)
|
|
52
|
-
sendEvent(reactContext, BridgeEvents.TransportLog(info))
|
|
53
|
+
// sendEvent(reactContext, BridgeEvents.TransportLog(info))
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
private val transport: AndroidUsbTransport? by lazy {
|
|
@@ -172,6 +173,10 @@ class TransportHidModule(
|
|
|
172
173
|
@ReactMethod()
|
|
173
174
|
fun connectDevice(uid: String, promise: Promise) {
|
|
174
175
|
val device = discoveryDevices.firstOrNull { it.uid == uid }
|
|
176
|
+
if (device == null) {
|
|
177
|
+
promise.reject(Exception("[TransportHidModule][connectDevice] Device not found"))
|
|
178
|
+
return
|
|
179
|
+
}
|
|
175
180
|
|
|
176
181
|
coroutineScope.launch {
|
|
177
182
|
try {
|
|
@@ -210,6 +215,22 @@ class TransportHidModule(
|
|
|
210
215
|
abortTimeout: Int,
|
|
211
216
|
promise: Promise
|
|
212
217
|
) {
|
|
218
|
+
// Log PERF: "Timestamp of the start of the function"
|
|
219
|
+
loggerService.log(
|
|
220
|
+
buildSimpleDebugLogInfo(
|
|
221
|
+
"AndroidUsbTransport",
|
|
222
|
+
"PERF: [@ReactMethod sendApdu] called at ${System.currentTimeMillis()}",
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
fun logEnd() = run {
|
|
226
|
+
loggerService.log(
|
|
227
|
+
buildSimpleDebugLogInfo(
|
|
228
|
+
"AndroidUsbTransport",
|
|
229
|
+
"PERF: [@ReactMethod sendApdu] finished at ${System.currentTimeMillis()}",
|
|
230
|
+
)
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
213
234
|
try {
|
|
214
235
|
val device = connectedDevices.firstOrNull() { it.id == sessionId }
|
|
215
236
|
if (device == null) {
|
|
@@ -222,14 +243,17 @@ class TransportHidModule(
|
|
|
222
243
|
val abortTimeoutDuration = if (abortTimeout <= 0) Duration.INFINITE else abortTimeout.milliseconds
|
|
223
244
|
val res =
|
|
224
245
|
device.sendApduFn(apdu, triggersDisconnection, abortTimeoutDuration)
|
|
246
|
+
logEnd()
|
|
225
247
|
promise.resolve(res.toWritableMap())
|
|
226
248
|
} catch (e: Exception) {
|
|
227
249
|
Timber.i("$e, ${e.cause}")
|
|
250
|
+
logEnd()
|
|
228
251
|
promise.reject(e)
|
|
229
252
|
}
|
|
230
253
|
}
|
|
231
254
|
} catch (e: Exception) {
|
|
232
255
|
Timber.i("$e, ${e.cause}")
|
|
256
|
+
logEnd()
|
|
233
257
|
promise.reject(e)
|
|
234
258
|
}
|
|
235
259
|
}
|
|
@@ -17,7 +17,6 @@ import com.ledger.devicesdk.shared.androidMain.transport.usb.utils.toLedgerUsbDe
|
|
|
17
17
|
import com.ledger.devicesdk.shared.androidMain.transport.usb.utils.toScannedDevice
|
|
18
18
|
import com.ledger.devicesdk.shared.androidMain.transport.usb.utils.toUsbDevices
|
|
19
19
|
import com.ledger.devicesdk.shared.androidMainInternal.transport.deviceconnection.DeviceConnection
|
|
20
|
-
import com.ledger.devicesdk.shared.api.discovery.ConnectivityType
|
|
21
20
|
import com.ledger.devicesdk.shared.api.discovery.DiscoveryDevice
|
|
22
21
|
import com.ledger.devicesdk.shared.internal.connection.InternalConnectedDevice
|
|
23
22
|
import com.ledger.devicesdk.shared.internal.connection.InternalConnectionResult
|
|
@@ -124,9 +123,10 @@ internal class DefaultAndroidUsbTransport(
|
|
|
124
123
|
"Device disconnected (sessionId=${deviceConnection.sessionId})"
|
|
125
124
|
)
|
|
126
125
|
)
|
|
127
|
-
deviceConnection.handleDeviceDisconnected()
|
|
128
126
|
usbConnections.remove(key)
|
|
129
127
|
usbConnectionsPendingReconnection.add(deviceConnection)
|
|
128
|
+
deviceConnection.handleDeviceDisconnected()
|
|
129
|
+
(deviceConnection.getApduSender() as AndroidUsbApduSender).release()
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
}
|
|
@@ -274,7 +274,7 @@ internal class DefaultAndroidUsbTransport(
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
|
|
277
|
-
override suspend fun connect(discoveryDevice: DiscoveryDevice
|
|
277
|
+
override suspend fun connect(discoveryDevice: DiscoveryDevice): InternalConnectionResult {
|
|
278
278
|
|
|
279
279
|
loggerService.log(
|
|
280
280
|
buildSimpleDebugLogInfo(
|
|
@@ -286,13 +286,13 @@ internal class DefaultAndroidUsbTransport(
|
|
|
286
286
|
val usbDevices = usbManager.deviceList.values
|
|
287
287
|
|
|
288
288
|
var usbDevice: UsbDevice? =
|
|
289
|
-
usbDevices.firstOrNull { it.deviceId == discoveryDevice
|
|
289
|
+
usbDevices.firstOrNull { it.deviceId == discoveryDevice.uid.toInt() }
|
|
290
290
|
|
|
291
291
|
if (usbDevice == null) {
|
|
292
292
|
// This is useful for LL during the OS update
|
|
293
293
|
loggerService.log(buildSimpleDebugLogInfo("AndroidUsbTransport", "[connect] No device found with matching id, looking for device with matching model"))
|
|
294
294
|
usbDevice =
|
|
295
|
-
usbDevices.firstOrNull { it.toLedgerUsbDevice()
|
|
295
|
+
usbDevices.firstOrNull { it.toLedgerUsbDevice()?.ledgerDevice == discoveryDevice.ledgerDevice }
|
|
296
296
|
} else {
|
|
297
297
|
loggerService.log(buildSimpleDebugLogInfo("AndroidUsbTransport", "[connect] Found device with matching id"))
|
|
298
298
|
}
|
|
@@ -326,9 +326,10 @@ internal class DefaultAndroidUsbTransport(
|
|
|
326
326
|
val deviceConnection = DeviceConnection(
|
|
327
327
|
sessionId = sessionId,
|
|
328
328
|
deviceApduSender = apduSender,
|
|
329
|
-
isFatalSendApduFailure = { false },
|
|
329
|
+
isFatalSendApduFailure = { false },
|
|
330
330
|
reconnectionTimeoutDuration = 5.seconds,
|
|
331
331
|
onTerminated = {
|
|
332
|
+
(it.getApduSender() as AndroidUsbApduSender).release()
|
|
332
333
|
usbConnections.remove(sessionId)
|
|
333
334
|
usbConnectionsPendingReconnection.remove(it)
|
|
334
335
|
eventDispatcher.dispatch(TransportEvent.DeviceConnectionLost(sessionId))
|
|
@@ -340,9 +341,9 @@ internal class DefaultAndroidUsbTransport(
|
|
|
340
341
|
val connectedDevice =
|
|
341
342
|
InternalConnectedDevice(
|
|
342
343
|
sessionId,
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
discoveryDevice.name,
|
|
345
|
+
discoveryDevice.ledgerDevice,
|
|
346
|
+
discoveryDevice.connectivityType,
|
|
346
347
|
sendApduFn = { apdu: ByteArray, triggersDisconnection: Boolean, abortTimeoutDuration: Duration ->
|
|
347
348
|
deviceConnection.requestSendApdu(apdu, triggersDisconnection, abortTimeoutDuration)
|
|
348
349
|
}
|
|
@@ -18,11 +18,11 @@ import com.ledger.devicesdk.shared.androidMainInternal.transport.deviceconnectio
|
|
|
18
18
|
import com.ledger.devicesdk.shared.api.apdu.SendApduFailureReason
|
|
19
19
|
import com.ledger.devicesdk.shared.api.apdu.SendApduResult
|
|
20
20
|
import com.ledger.devicesdk.shared.internal.service.logger.LoggerService
|
|
21
|
+
import com.ledger.devicesdk.shared.internal.service.logger.buildSimpleDebugLogInfo
|
|
21
22
|
import com.ledger.devicesdk.shared.internal.service.logger.buildSimpleErrorLogInfo
|
|
22
23
|
import com.ledger.devicesdk.shared.internal.transport.framer.FramerService
|
|
23
24
|
import com.ledger.devicesdk.shared.internal.transport.framer.to2BytesArray
|
|
24
25
|
import kotlinx.coroutines.CoroutineDispatcher
|
|
25
|
-
import kotlinx.coroutines.cancel
|
|
26
26
|
import kotlinx.coroutines.delay
|
|
27
27
|
import kotlinx.coroutines.launch
|
|
28
28
|
import kotlinx.coroutines.withContext
|
|
@@ -36,7 +36,7 @@ private const val DEFAULT_USB_INTERFACE = 0
|
|
|
36
36
|
|
|
37
37
|
internal class AndroidUsbApduSender(
|
|
38
38
|
override val dependencies: Dependencies,
|
|
39
|
-
|
|
39
|
+
usbManager: UsbManager,
|
|
40
40
|
private val framerService: FramerService,
|
|
41
41
|
private val request: UsbRequest,
|
|
42
42
|
private val ioDispatcher: CoroutineDispatcher,
|
|
@@ -47,49 +47,49 @@ internal class AndroidUsbApduSender(
|
|
|
47
47
|
val ledgerUsbDevice: LedgerUsbDevice,
|
|
48
48
|
)
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
private val usbDevice = dependencies.usbDevice
|
|
51
|
+
private val usbInterface = usbDevice.getInterface(DEFAULT_USB_INTERFACE)
|
|
52
|
+
private val androidToUsbEndpoint =
|
|
53
|
+
usbInterface.firstEndpointOrThrow { it == UsbConstants.USB_DIR_OUT }
|
|
54
|
+
private val usbToAndroidEndpoint =
|
|
55
|
+
usbInterface.firstEndpointOrThrow { it == UsbConstants.USB_DIR_IN }
|
|
56
|
+
private val usbConnection = usbManager.openDevice(usbDevice)
|
|
57
|
+
.apply { claimInterface(usbInterface, true) }
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
fun release() {
|
|
61
|
+
usbConnection.releaseInterface(usbInterface)
|
|
62
|
+
usbConnection.close()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
override suspend fun send(apdu: ByteArray, abortTimeoutDuration: Duration): SendApduResult {
|
|
66
|
+
val t1 = System.currentTimeMillis()
|
|
67
|
+
return try {
|
|
53
68
|
withContext(context = ioDispatcher) {
|
|
54
|
-
val usbInterface = usbDevice.getInterface(DEFAULT_USB_INTERFACE)
|
|
55
|
-
val androidToUsbEndpoint =
|
|
56
|
-
usbInterface.firstEndpointOrThrow { it == UsbConstants.USB_DIR_OUT }
|
|
57
|
-
val usbToAndroidEndpoint =
|
|
58
|
-
usbInterface.firstEndpointOrThrow { it == UsbConstants.USB_DIR_IN }
|
|
59
|
-
val usbConnection = usbManager.openDevice(usbDevice)
|
|
60
|
-
.apply { claimInterface(usbInterface, true) }
|
|
61
69
|
|
|
62
70
|
val timeoutJob = launch {
|
|
63
71
|
delay(abortTimeoutDuration)
|
|
64
|
-
usbConnection.releaseInterface(usbInterface)
|
|
65
|
-
usbConnection.close()
|
|
66
72
|
throw SendApduTimeoutException
|
|
67
73
|
}
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
transmitApdu(
|
|
76
|
+
usbConnection = usbConnection,
|
|
77
|
+
androidToUsbEndpoint = androidToUsbEndpoint,
|
|
78
|
+
rawApdu = apdu,
|
|
79
|
+
)
|
|
70
80
|
|
|
71
|
-
|
|
81
|
+
val apduResponse =
|
|
82
|
+
receiveApdu(
|
|
72
83
|
usbConnection = usbConnection,
|
|
73
|
-
|
|
74
|
-
rawApdu = apdu,
|
|
84
|
+
usbToAndroidEndpoint = usbToAndroidEndpoint,
|
|
75
85
|
)
|
|
86
|
+
timeoutJob.cancel()
|
|
76
87
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
usbConnection = usbConnection,
|
|
80
|
-
usbToAndroidEndpoint = usbToAndroidEndpoint,
|
|
81
|
-
)
|
|
82
|
-
timeoutJob.cancel()
|
|
83
|
-
|
|
84
|
-
if (apduResponse.isEmpty()) {
|
|
85
|
-
return@withContext SendApduResult.Failure(reason = SendApduFailureReason.EmptyResponse)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return@withContext SendApduResult.Success(apdu = apduResponse)
|
|
89
|
-
} finally {
|
|
90
|
-
usbConnection.releaseInterface(usbInterface)
|
|
91
|
-
usbConnection.close()
|
|
88
|
+
if (apduResponse.isEmpty()) {
|
|
89
|
+
return@withContext SendApduResult.Failure(reason = SendApduFailureReason.EmptyResponse)
|
|
92
90
|
}
|
|
91
|
+
|
|
92
|
+
return@withContext SendApduResult.Success(apdu = apduResponse)
|
|
93
93
|
}
|
|
94
94
|
} catch (e: SendApduTimeoutException) {
|
|
95
95
|
loggerService.log(
|
|
@@ -110,13 +110,18 @@ internal class AndroidUsbApduSender(
|
|
|
110
110
|
} catch (e: Exception) {
|
|
111
111
|
loggerService.log(buildSimpleErrorLogInfo("AndroidUsbApduSender", "error in send: $e"))
|
|
112
112
|
SendApduResult.Failure(reason = SendApduFailureReason.Unknown)
|
|
113
|
+
} finally {
|
|
114
|
+
val t2 = System.currentTimeMillis()
|
|
115
|
+
loggerService.log(buildSimpleDebugLogInfo("AndroidUsbApduSender", "PERF: [native sendApdu total]: ${t2 - t1}"))
|
|
113
116
|
}
|
|
117
|
+
}
|
|
114
118
|
|
|
115
119
|
private fun transmitApdu(
|
|
116
120
|
usbConnection: UsbDeviceConnection,
|
|
117
121
|
androidToUsbEndpoint: UsbEndpoint,
|
|
118
122
|
rawApdu: ByteArray,
|
|
119
123
|
) {
|
|
124
|
+
val t1 = System.currentTimeMillis()
|
|
120
125
|
framerService.serialize(mtu = USB_MTU, channelId = generateChannelId(), rawApdu = rawApdu)
|
|
121
126
|
.forEach { apduFrame ->
|
|
122
127
|
val buffer = apduFrame.toByteArray()
|
|
@@ -127,16 +132,19 @@ internal class AndroidUsbApduSender(
|
|
|
127
132
|
USB_TIMEOUT
|
|
128
133
|
)
|
|
129
134
|
}
|
|
135
|
+
val t2 = System.currentTimeMillis()
|
|
136
|
+
loggerService.log(buildSimpleDebugLogInfo("AndroidUsbApduSender", "PERF: [transmitApdu]: ${t2 - t1}"))
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
private fun receiveApdu(
|
|
133
140
|
usbConnection: UsbDeviceConnection,
|
|
134
141
|
usbToAndroidEndpoint: UsbEndpoint,
|
|
135
|
-
): ByteArray
|
|
136
|
-
if (!request.initialize(usbConnection, usbToAndroidEndpoint)) {
|
|
142
|
+
): ByteArray {
|
|
143
|
+
return if (!request.initialize(usbConnection, usbToAndroidEndpoint)) {
|
|
137
144
|
request.close()
|
|
138
145
|
byteArrayOf()
|
|
139
146
|
} else {
|
|
147
|
+
val t1 = System.currentTimeMillis()
|
|
140
148
|
val frames = framerService.createApduFrames(mtu = USB_MTU, isUsbTransport = true) {
|
|
141
149
|
val buffer = ByteArray(USB_MTU)
|
|
142
150
|
val responseBuffer = ByteBuffer.allocate(USB_MTU)
|
|
@@ -152,8 +160,12 @@ internal class AndroidUsbApduSender(
|
|
|
152
160
|
buffer
|
|
153
161
|
}
|
|
154
162
|
}
|
|
155
|
-
framerService.deserialize(mtu = USB_MTU, frames)
|
|
163
|
+
val result = framerService.deserialize(mtu = USB_MTU, frames)
|
|
164
|
+
val t2 = System.currentTimeMillis()
|
|
165
|
+
loggerService.log(buildSimpleDebugLogInfo("AndroidUsbApduSender", "PERF: [receiveApdu]: ${t2 - t1}"))
|
|
166
|
+
result
|
|
156
167
|
}
|
|
168
|
+
}
|
|
157
169
|
|
|
158
170
|
private fun UsbInterface.firstEndpointOrThrow(predicate: (Int) -> Boolean): UsbEndpoint {
|
|
159
171
|
for (endp in 0..this.endpointCount) {
|
|
@@ -169,7 +181,7 @@ internal class AndroidUsbApduSender(
|
|
|
169
181
|
private fun generateChannelId(): ByteArray =
|
|
170
182
|
Random.nextInt(0, until = Int.MAX_VALUE).to2BytesArray()
|
|
171
183
|
|
|
172
|
-
private data object SendApduTimeoutException: Exception() {
|
|
184
|
+
private data object SendApduTimeoutException : Exception() {
|
|
173
185
|
private fun readResolve(): Any = SendApduTimeoutException
|
|
174
186
|
}
|
|
175
187
|
}
|
|
@@ -14,7 +14,8 @@ internal interface Transport {
|
|
|
14
14
|
|
|
15
15
|
fun stopScan()
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// TODO change by Flow<ConnectedDeviceState> or add observe device connection for listening device state flow through?
|
|
18
|
+
suspend fun connect(discoveryDevice: DiscoveryDevice): InternalConnectionResult
|
|
18
19
|
|
|
19
20
|
suspend fun disconnect(deviceId: String)
|
|
20
21
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var v=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var S=(i,e)=>{for(var o in e)v(i,o,{get:e[o],enumerable:!0})},A=(i,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of T(e))!y.call(i,t)&&t!==o&&v(i,t,{get:()=>e[t],enumerable:!(n=M(e,t))||n.enumerable});return i};var N=i=>A(v({},"__esModule",{value:!0}),i);var P={};S(P,{DefaultNativeModuleWrapper:()=>R});module.exports=N(P);var c=require("react-native"),d=require("rxjs"),D=require("../helpers/base64Utils"),r=require("./mapper"),s=require("./types");class R{_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 d.Observable(e=>{const n=new c.NativeEventEmitter(this._nativeModule).addListener(s.DISCOVERED_DEVICES_EVENT,t=>{e.next(t.map(a=>(0,r.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(a,this._deviceModelDataSource)).filter(a=>a!==null))});return()=>{n.remove()}})}subscribeToDeviceDisconnectedEvents(){return new d.Observable(e=>{const n=new c.NativeEventEmitter(this._nativeModule).addListener(s.DEVICE_DISCONNECTED_EVENT,t=>{e.next((0,r.mapNativeDeviceConnectionLostToDeviceDisconnected)(t))});return()=>{n.remove()}})}subscribeToTransportLogs(){return new d.Observable(e=>{const n=new c.NativeEventEmitter(this._nativeModule).addListener(s.TRANSPORT_LOG_EVENT,t=>{e.next((0,r.mapNativeTransportLogToLog)(t))});return()=>{n.remove()}})}async connectDevice(e){const o=await this._nativeModule.connectDevice(e);return(0,r.mapNativeConnectionResultToConnectionResult)(o,this._deviceModelDataSource)}async disconnectDevice(e){return this._nativeModule.disconnectDevice(e)}async sendApdu(e,o,n,t){console.log("______ PERF: _____ SEND APDU CALLED _____"),console.log("PERF: sendApdu START at ",Date.now());const a=performance.now(),m=(0,D.uint8ArrayToBase64)(o),l=performance.now();console.log("PERF: sendApdu serialization",l-a,"ms"),console.log("PERF: sendApdu call to nativeModule at",l);const E=await this._nativeModule.sendApdu(e,m,n,t),u=performance.now();console.log("PERF: sendApdu result from nativeModule at",u);const _=(0,r.mapNativeSendApduResultToSendApduResult)(E),p=performance.now();return console.log("PERF: sendApdu deserialization",p-u,"ms"),console.log("PERF: TS sendApdu total",p-a,"ms"),console.log("PERF: sendApdu END at ",Date.now()),_}}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
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gC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,cAAc,iBAAiBA,CAAS,CACtD,CAEA,MAAM,SACJA,EACAC,EACAC,EACAC,EACyB,CACzB,MAAMC,EAAkB,MAAM,KAAK,cAAc,SAC/
|
|
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(\n sessionId: string,\n apdu: Uint8Array,\n triggersDisconnection: boolean,\n abortTimeout: number,\n ): Promise<SendApduResult> {\n console.log(\"______ PERF: _____ SEND APDU CALLED _____\");\n console.log(\"PERF: sendApdu START at \", Date.now());\n const t0 = performance.now();\n const serializedApdu = uint8ArrayToBase64(apdu);\n const t1 = performance.now();\n console.log(\"PERF: sendApdu serialization\", t1 - t0, \"ms\");\n console.log(\"PERF: sendApdu call to nativeModule at\", t1);\n const nSendApduResult = await this._nativeModule.sendApdu(\n sessionId,\n serializedApdu,\n triggersDisconnection,\n abortTimeout,\n );\n const t2 = performance.now();\n console.log(\"PERF: sendApdu result from nativeModule at\", t2);\n const result = mapNativeSendApduResultToSendApduResult(nSendApduResult)\n const t3 = performance.now();\n console.log(\"PERF: sendApdu deserialization\", t3 - t2, \"ms\");\n console.log(\"PERF: TS sendApdu total\", t3 - t0, \"ms\");\n console.log(\"PERF: sendApdu END at \", Date.now());\n return result;\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,qBA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"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", "t0", "serializedApdu", "t1", "nSendApduResult", "t2", "result", "t3"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{NativeEventEmitter as i}from"react-native";import{Observable as a}from"rxjs";import{uint8ArrayToBase64 as
|
|
1
|
+
import{NativeEventEmitter as i}from"react-native";import{Observable as a}from"rxjs";import{uint8ArrayToBase64 as p}from"../helpers/base64Utils";import{mapNativeConnectionResultToConnectionResult as D,mapNativeDeviceConnectionLostToDeviceDisconnected as m,mapNativeDiscoveryDeviceToTransportDiscoveredDevice as E,mapNativeSendApduResultToSendApduResult as _,mapNativeTransportLogToLog as M}from"./mapper";import{DEVICE_DISCONNECTED_EVENT as T,DISCOVERED_DEVICES_EVENT as y,TRANSPORT_LOG_EVENT as S}from"./types";class b{_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 a(e=>{const t=new i(this._nativeModule).addListener(y,o=>{e.next(o.map(r=>E(r,this._deviceModelDataSource)).filter(r=>r!==null))});return()=>{t.remove()}})}subscribeToDeviceDisconnectedEvents(){return new a(e=>{const t=new i(this._nativeModule).addListener(T,o=>{e.next(m(o))});return()=>{t.remove()}})}subscribeToTransportLogs(){return new a(e=>{const t=new i(this._nativeModule).addListener(S,o=>{e.next(M(o))});return()=>{t.remove()}})}async connectDevice(e){const n=await this._nativeModule.connectDevice(e);return D(n,this._deviceModelDataSource)}async disconnectDevice(e){return this._nativeModule.disconnectDevice(e)}async sendApdu(e,n,t,o){console.log("______ PERF: _____ SEND APDU CALLED _____"),console.log("PERF: sendApdu START at ",Date.now());const r=performance.now(),v=p(n),s=performance.now();console.log("PERF: sendApdu serialization",s-r,"ms"),console.log("PERF: sendApdu call to nativeModule at",s);const l=await this._nativeModule.sendApdu(e,v,t,o),c=performance.now();console.log("PERF: sendApdu result from nativeModule at",c);const u=_(l),d=performance.now();return console.log("PERF: sendApdu deserialization",d-c,"ms"),console.log("PERF: TS sendApdu total",d-r,"ms"),console.log("PERF: sendApdu END at ",Date.now()),u}}export{b as 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
|
|
5
|
-
"mappings": "AAAA,OAAS,sBAAAA,MAA0B,eAOnC,OAAS,cAAAC,MAAkB,OAE3B,OAAS,sBAAAC,MAA0B,2BAOnC,OACE,+CAAAC,EACA,qDAAAC,EACA,uDAAAC,EACA,2CAAAC,EACA,8BAAAC,MACK,WACP,OACE,6BAAAC,EAEA,4BAAAC,EAGA,uBAAAC,MACK,UAGA,MAAMC,CAA0D,CACpD,cACA,uBAEjB,YAAYC,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,IAAIX,EAAYY,GAAe,CAEpC,MAAMC,EADe,IAAId,EAAmB,KAAK,aAAa,EAC3B,YACjCS,EACCM,GAAqD,CACpDF,EAAW,KACTE,EACG,IAAKC,GACJX,EACEW,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,IAAIb,EAAYY,GAAe,CAEpC,MAAMC,EADe,IAAId,EAAmB,KAAK,aAAa,EAC3B,YACjCQ,EACCQ,GAA2C,CAC1CH,EAAW,KACTT,EAAkDY,CAAM,CAC1D,CACF,CACF,EAEA,MAAO,IAAM,CACXF,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,0BAAkD,CAChD,OAAO,IAAIb,EAAYY,GAAe,CAEpC,MAAMC,EADe,IAAId,EAAmB,KAAK,aAAa,EAC3B,YACjCU,EACCQ,GAAyB,CACxBL,EAAW,KAAKN,EAA2BW,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,OAAOhB,EACLiB,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/
|
|
6
|
-
"names": ["NativeEventEmitter", "Observable", "uint8ArrayToBase64", "mapNativeConnectionResultToConnectionResult", "mapNativeDeviceConnectionLostToDeviceDisconnected", "mapNativeDiscoveryDeviceToTransportDiscoveredDevice", "mapNativeSendApduResultToSendApduResult", "mapNativeTransportLogToLog", "DEVICE_DISCONNECTED_EVENT", "DISCOVERED_DEVICES_EVENT", "TRANSPORT_LOG_EVENT", "DefaultNativeModuleWrapper", "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(\n sessionId: string,\n apdu: Uint8Array,\n triggersDisconnection: boolean,\n abortTimeout: number,\n ): Promise<SendApduResult> {\n console.log(\"______ PERF: _____ SEND APDU CALLED _____\");\n console.log(\"PERF: sendApdu START at \", Date.now());\n const t0 = performance.now();\n const serializedApdu = uint8ArrayToBase64(apdu);\n const t1 = performance.now();\n console.log(\"PERF: sendApdu serialization\", t1 - t0, \"ms\");\n console.log(\"PERF: sendApdu call to nativeModule at\", t1);\n const nSendApduResult = await this._nativeModule.sendApdu(\n sessionId,\n serializedApdu,\n triggersDisconnection,\n abortTimeout,\n );\n const t2 = performance.now();\n console.log(\"PERF: sendApdu result from nativeModule at\", t2);\n const result = mapNativeSendApduResultToSendApduResult(nSendApduResult)\n const t3 = performance.now();\n console.log(\"PERF: sendApdu deserialization\", t3 - t2, \"ms\");\n console.log(\"PERF: TS sendApdu total\", t3 - t0, \"ms\");\n console.log(\"PERF: sendApdu END at \", Date.now());\n return result;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAS,sBAAAA,MAA0B,eAOnC,OAAS,cAAAC,MAAkB,OAE3B,OAAS,sBAAAC,MAA0B,2BAOnC,OACE,+CAAAC,EACA,qDAAAC,EACA,uDAAAC,EACA,2CAAAC,EACA,8BAAAC,MACK,WACP,OACE,6BAAAC,EAEA,4BAAAC,EAGA,uBAAAC,MACK,UAGA,MAAMC,CAA0D,CACpD,cACA,uBAEjB,YAAYC,EAGT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EAAK,YAAY,IAAI,EACrBC,EAAiBxB,EAAmBoB,CAAI,EACxCK,EAAK,YAAY,IAAI,EAC3B,QAAQ,IAAI,+BAAgCA,EAAKF,EAAI,IAAI,EACzD,QAAQ,IAAI,yCAA0CE,CAAE,EACxD,MAAMC,EAAkB,MAAM,KAAK,cAAc,SAC/CP,EACAK,EACAH,EACAC,CACF,EACMK,EAAK,YAAY,IAAI,EAC3B,QAAQ,IAAI,6CAA8CA,CAAE,EAC5D,MAAMC,EAASxB,EAAwCsB,CAAe,EAChEG,EAAK,YAAY,IAAI,EAC3B,eAAQ,IAAI,iCAAkCA,EAAKF,EAAI,IAAI,EAC3D,QAAQ,IAAI,0BAA2BE,EAAKN,EAAI,IAAI,EACpD,QAAQ,IAAI,2BAA4B,KAAK,IAAI,CAAC,EAC3CK,CACT,CACF",
|
|
6
|
+
"names": ["NativeEventEmitter", "Observable", "uint8ArrayToBase64", "mapNativeConnectionResultToConnectionResult", "mapNativeDeviceConnectionLostToDeviceDisconnected", "mapNativeDiscoveryDeviceToTransportDiscoveredDevice", "mapNativeSendApduResultToSendApduResult", "mapNativeTransportLogToLog", "DEVICE_DISCONNECTED_EVENT", "DISCOVERED_DEVICES_EVENT", "TRANSPORT_LOG_EVENT", "DefaultNativeModuleWrapper", "args", "subscriber", "eventListener", "discoveredDevices", "device", "d", "logParams", "uid", "nConnectionResult", "sessionId", "apdu", "triggersDisconnection", "abortTimeout", "t0", "serializedApdu", "t1", "nSendApduResult", "t2", "result", "t3"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DefaultNativeModuleWrapper.d.ts","sourceRoot":"","sources":["../../../../src/api/bridge/DefaultNativeModuleWrapper.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,yBAAyB,EAC/B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,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