@ledgerhq/device-transport-kit-react-native-hid 0.0.0-rn-ble-logs-20250416162013 → 0.0.0-rn-hid-sync-onboarding-behavior-20250516094633
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 +11 -2
- package/android/src/main/kotlin/com/ledger/androidtransporthid/bridge/serialization.kt +2 -0
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/DefaultAndroidUsbTransport.kt +59 -10
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMain/transport/usb/connection/AndroidUsbApduSender.kt +72 -32
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceApduSender.kt +2 -1
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnection.kt +5 -4
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/androidMainInternal/transport/deviceconnection/DeviceConnectionStateMachine.kt +3 -2
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/api/apdu/SendApduResult.kt +4 -0
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/internal/connection/InternalConnectedDevice.kt +1 -1
- package/android/src/main/kotlin/com/ledger/devicesdk/shared/internal/transport/framer/FramerService.kt +1 -1
- package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js +1 -1
- package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
- package/lib/cjs/api/bridge/mapper.js +1 -1
- package/lib/cjs/api/bridge/mapper.js.map +2 -2
- package/lib/cjs/api/bridge/types.js +1 -1
- package/lib/cjs/api/bridge/types.js.map +1 -1
- package/lib/cjs/api/transport/NativeModuleWrapper.js +1 -1
- package/lib/cjs/api/transport/NativeModuleWrapper.js.map +1 -1
- package/lib/cjs/api/transport/RNHidTransport.js +1 -1
- package/lib/cjs/api/transport/RNHidTransport.js.map +3 -3
- package/lib/cjs/package.json +10 -10
- package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js +1 -1
- package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
- package/lib/esm/api/bridge/mapper.js +1 -1
- package/lib/esm/api/bridge/mapper.js.map +3 -3
- package/lib/esm/api/bridge/types.js.map +1 -1
- package/lib/esm/api/transport/RNHidTransport.js +1 -1
- package/lib/esm/api/transport/RNHidTransport.js.map +3 -3
- package/lib/esm/package.json +10 -10
- package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts +1 -1
- package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts.map +1 -1
- package/lib/types/api/bridge/mapper.d.ts.map +1 -1
- package/lib/types/api/bridge/types.d.ts +2 -2
- package/lib/types/api/bridge/types.d.ts.map +1 -1
- package/lib/types/api/transport/NativeModuleWrapper.d.ts +1 -1
- package/lib/types/api/transport/NativeModuleWrapper.d.ts.map +1 -1
- package/lib/types/api/transport/RNHidTransport.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +14 -14
|
@@ -31,6 +31,7 @@ import kotlinx.coroutines.flow.onEach
|
|
|
31
31
|
import kotlinx.coroutines.launch
|
|
32
32
|
import timber.log.Timber
|
|
33
33
|
import kotlin.random.Random
|
|
34
|
+
import kotlin.time.Duration
|
|
34
35
|
import kotlin.time.Duration.Companion.milliseconds
|
|
35
36
|
|
|
36
37
|
class TransportHidModule(
|
|
@@ -206,7 +207,13 @@ class TransportHidModule(
|
|
|
206
207
|
}
|
|
207
208
|
|
|
208
209
|
@ReactMethod
|
|
209
|
-
fun sendApdu(
|
|
210
|
+
fun sendApdu(
|
|
211
|
+
sessionId: String,
|
|
212
|
+
apduBase64: String,
|
|
213
|
+
triggersDisconnection: Boolean,
|
|
214
|
+
abortTimeout: Int,
|
|
215
|
+
promise: Promise
|
|
216
|
+
) {
|
|
210
217
|
try {
|
|
211
218
|
val device = connectedDevices.firstOrNull() { it.id == sessionId }
|
|
212
219
|
if (device == null) {
|
|
@@ -216,7 +223,9 @@ class TransportHidModule(
|
|
|
216
223
|
coroutineScope.launch {
|
|
217
224
|
try {
|
|
218
225
|
val apdu: ByteArray = Base64.decode(apduBase64, Base64.DEFAULT)
|
|
219
|
-
val
|
|
226
|
+
val abortTimeoutDuration = if (abortTimeout <= 0) Duration.INFINITE else abortTimeout.milliseconds
|
|
227
|
+
val res =
|
|
228
|
+
device.sendApduFn(apdu, triggersDisconnection, abortTimeoutDuration)
|
|
220
229
|
promise.resolve(res.toWritableMap())
|
|
221
230
|
} catch (e: Exception) {
|
|
222
231
|
Timber.i("$e, ${e.cause}")
|
|
@@ -103,6 +103,8 @@ internal fun SendApduResult.toWritableMap(): WritableMap {
|
|
|
103
103
|
SendApduFailureReason.NoUsbEndpointFound -> "NoUsbEndpointFound"
|
|
104
104
|
SendApduFailureReason.DeviceDisconnected -> "DeviceDisconnected"
|
|
105
105
|
SendApduFailureReason.Unknown -> "Unknown"
|
|
106
|
+
SendApduFailureReason.AbortTimeout -> "SendApduTimeout"
|
|
107
|
+
SendApduFailureReason.EmptyResponse -> "EmptyResponse"
|
|
106
108
|
})
|
|
107
109
|
}
|
|
108
110
|
}
|
|
@@ -97,17 +97,33 @@ internal class DefaultAndroidUsbTransport(
|
|
|
97
97
|
override fun updateUsbState(state: UsbState) {
|
|
98
98
|
when (state) {
|
|
99
99
|
is UsbState.Detached -> {
|
|
100
|
-
loggerService.log(
|
|
100
|
+
loggerService.log(
|
|
101
|
+
buildSimpleDebugLogInfo(
|
|
102
|
+
"AndroidUsbTransport",
|
|
103
|
+
"Detached deviceId=${state.ledgerUsbDevice.uid}"
|
|
104
|
+
)
|
|
105
|
+
)
|
|
101
106
|
usbConnections.entries.find {
|
|
102
107
|
it.value.getApduSender().dependencies.ledgerUsbDevice.uid == state.ledgerUsbDevice.uid
|
|
103
108
|
}.let { item ->
|
|
104
109
|
scope.launch {
|
|
105
110
|
if (item == null) {
|
|
106
|
-
loggerService.log(
|
|
111
|
+
loggerService.log(
|
|
112
|
+
buildSimpleWarningLogInfo(
|
|
113
|
+
"AndroidUsbTransport",
|
|
114
|
+
"No connection found"
|
|
115
|
+
)
|
|
116
|
+
)
|
|
107
117
|
return@launch
|
|
108
118
|
}
|
|
109
119
|
val (key, deviceConnection) = item
|
|
110
|
-
|
|
120
|
+
// (deviceConnection.getApduSender() as AndroidUsbApduSender).clear()
|
|
121
|
+
loggerService.log(
|
|
122
|
+
buildSimpleInfoLogInfo(
|
|
123
|
+
"AndroidUsbTransport",
|
|
124
|
+
"Device disconnected (sessionId=${deviceConnection.sessionId})"
|
|
125
|
+
)
|
|
126
|
+
)
|
|
111
127
|
deviceConnection.handleDeviceDisconnected()
|
|
112
128
|
usbConnections.remove(key)
|
|
113
129
|
usbConnectionsPendingReconnection.add(deviceConnection)
|
|
@@ -116,12 +132,22 @@ internal class DefaultAndroidUsbTransport(
|
|
|
116
132
|
}
|
|
117
133
|
|
|
118
134
|
is UsbState.Attached -> {
|
|
119
|
-
loggerService.log(
|
|
135
|
+
loggerService.log(
|
|
136
|
+
buildSimpleDebugLogInfo(
|
|
137
|
+
"AndroidUsbTransport",
|
|
138
|
+
"Attached deviceId=${state.ledgerUsbDevice.uid}, pendingReconnections=${usbConnectionsPendingReconnection}"
|
|
139
|
+
)
|
|
140
|
+
)
|
|
120
141
|
val usbDevice = usbManager.deviceList.values.firstOrNull {
|
|
121
142
|
it.toLedgerUsbDevice()?.uid == state.ledgerUsbDevice.uid
|
|
122
143
|
}
|
|
123
144
|
if (usbDevice == null) {
|
|
124
|
-
loggerService.log(
|
|
145
|
+
loggerService.log(
|
|
146
|
+
buildSimpleWarningLogInfo(
|
|
147
|
+
"AndroidUsbTransport",
|
|
148
|
+
"No UsbDevice found"
|
|
149
|
+
)
|
|
150
|
+
)
|
|
125
151
|
return
|
|
126
152
|
}
|
|
127
153
|
usbConnectionsPendingReconnection.firstOrNull {
|
|
@@ -138,14 +164,29 @@ internal class DefaultAndroidUsbTransport(
|
|
|
138
164
|
)
|
|
139
165
|
return@launch
|
|
140
166
|
}
|
|
141
|
-
loggerService.log(
|
|
167
|
+
loggerService.log(
|
|
168
|
+
buildSimpleDebugLogInfo(
|
|
169
|
+
"AndroidUsbTransport",
|
|
170
|
+
"Found matching device connection $deviceConnection"
|
|
171
|
+
)
|
|
172
|
+
)
|
|
142
173
|
|
|
143
174
|
val permissionResult = checkOrRequestPermission(usbDevice)
|
|
144
175
|
if (permissionResult is PermissionResult.Denied) {
|
|
145
|
-
loggerService.log(
|
|
176
|
+
loggerService.log(
|
|
177
|
+
buildSimpleDebugLogInfo(
|
|
178
|
+
"AndroidUsbTransport",
|
|
179
|
+
"Permission denied"
|
|
180
|
+
)
|
|
181
|
+
)
|
|
146
182
|
return@launch
|
|
147
183
|
}
|
|
148
|
-
loggerService.log(
|
|
184
|
+
loggerService.log(
|
|
185
|
+
buildSimpleInfoLogInfo(
|
|
186
|
+
"AndroidUsbTransport",
|
|
187
|
+
"Reconnecting device (sessionId=${deviceConnection.sessionId})"
|
|
188
|
+
)
|
|
189
|
+
)
|
|
149
190
|
deviceConnection.handleDeviceConnected(
|
|
150
191
|
AndroidUsbApduSender(
|
|
151
192
|
dependencies = AndroidUsbApduSender.Dependencies(
|
|
@@ -195,7 +236,12 @@ internal class DefaultAndroidUsbTransport(
|
|
|
195
236
|
device = usbDevice,
|
|
196
237
|
)
|
|
197
238
|
|
|
198
|
-
loggerService.log(
|
|
239
|
+
loggerService.log(
|
|
240
|
+
buildSimpleDebugLogInfo(
|
|
241
|
+
"AndroidUsbTransport",
|
|
242
|
+
"Waiting for permission result"
|
|
243
|
+
)
|
|
244
|
+
)
|
|
199
245
|
|
|
200
246
|
val result = eventsFlow.first {
|
|
201
247
|
it is UsbPermissionEvent.PermissionGranted ||
|
|
@@ -262,6 +308,7 @@ internal class DefaultAndroidUsbTransport(
|
|
|
262
308
|
isFatalSendApduFailure = { false }, // TODO: refine this
|
|
263
309
|
reconnectionTimeoutDuration = 5.seconds,
|
|
264
310
|
onTerminated = {
|
|
311
|
+
// (it.getApduSender() as AndroidUsbApduSender).clear()
|
|
265
312
|
usbConnections.remove(sessionId)
|
|
266
313
|
usbConnectionsPendingReconnection.remove(it)
|
|
267
314
|
eventDispatcher.dispatch(TransportEvent.DeviceConnectionLost(sessionId))
|
|
@@ -276,7 +323,9 @@ internal class DefaultAndroidUsbTransport(
|
|
|
276
323
|
discoveryDevice.name,
|
|
277
324
|
discoveryDevice.ledgerDevice,
|
|
278
325
|
discoveryDevice.connectivityType,
|
|
279
|
-
sendApduFn = { apdu
|
|
326
|
+
sendApduFn = { apdu: ByteArray, triggersDisconnection: Boolean, abortTimeoutDuration: Duration ->
|
|
327
|
+
deviceConnection.requestSendApdu(apdu, triggersDisconnection, abortTimeoutDuration)
|
|
328
|
+
}
|
|
280
329
|
)
|
|
281
330
|
|
|
282
331
|
usbConnections[sessionId] = deviceConnection
|
|
@@ -13,21 +13,24 @@ import android.hardware.usb.UsbInterface
|
|
|
13
13
|
import android.hardware.usb.UsbManager
|
|
14
14
|
import android.hardware.usb.UsbRequest
|
|
15
15
|
import com.ledger.devicesdk.shared.androidMain.transport.usb.model.LedgerUsbDevice
|
|
16
|
+
import com.ledger.devicesdk.shared.androidMainInternal.transport.USB_MTU
|
|
17
|
+
import com.ledger.devicesdk.shared.androidMainInternal.transport.deviceconnection.DeviceApduSender
|
|
16
18
|
import com.ledger.devicesdk.shared.api.apdu.SendApduFailureReason
|
|
17
19
|
import com.ledger.devicesdk.shared.api.apdu.SendApduResult
|
|
18
|
-
import com.ledger.devicesdk.shared.androidMainInternal.transport.deviceconnection.DeviceApduSender
|
|
19
20
|
import com.ledger.devicesdk.shared.api.utils.toHexadecimalString
|
|
20
|
-
import com.ledger.devicesdk.shared.androidMainInternal.transport.USB_MTU
|
|
21
21
|
import com.ledger.devicesdk.shared.internal.service.logger.LoggerService
|
|
22
|
+
import com.ledger.devicesdk.shared.internal.service.logger.buildSimpleDebugLogInfo
|
|
22
23
|
import com.ledger.devicesdk.shared.internal.service.logger.buildSimpleErrorLogInfo
|
|
23
|
-
import com.ledger.devicesdk.shared.internal.service.logger.buildSimpleInfoLogInfo
|
|
24
24
|
import com.ledger.devicesdk.shared.internal.transport.framer.FramerService
|
|
25
25
|
import com.ledger.devicesdk.shared.internal.transport.framer.to2BytesArray
|
|
26
|
-
import java.nio.ByteBuffer
|
|
27
|
-
import kotlin.random.Random
|
|
28
26
|
import kotlinx.coroutines.CoroutineDispatcher
|
|
27
|
+
import kotlinx.coroutines.TimeoutCancellationException
|
|
29
28
|
import kotlinx.coroutines.withContext
|
|
29
|
+
import kotlinx.coroutines.withTimeout
|
|
30
30
|
import timber.log.Timber
|
|
31
|
+
import java.nio.ByteBuffer
|
|
32
|
+
import kotlin.random.Random
|
|
33
|
+
import kotlin.time.Duration
|
|
31
34
|
|
|
32
35
|
private const val USB_TIMEOUT = 500
|
|
33
36
|
|
|
@@ -41,38 +44,60 @@ internal class AndroidUsbApduSender(
|
|
|
41
44
|
private val ioDispatcher: CoroutineDispatcher,
|
|
42
45
|
private val loggerService: LoggerService,
|
|
43
46
|
) : DeviceApduSender<AndroidUsbApduSender.Dependencies> {
|
|
44
|
-
|
|
45
47
|
data class Dependencies(
|
|
46
48
|
val usbDevice: UsbDevice,
|
|
47
49
|
val ledgerUsbDevice: LedgerUsbDevice,
|
|
48
50
|
)
|
|
49
51
|
|
|
50
|
-
override suspend fun send(apdu: ByteArray): SendApduResult =
|
|
52
|
+
override suspend fun send(apdu: ByteArray, abortTimeoutDuration: Duration): SendApduResult =
|
|
51
53
|
try {
|
|
52
54
|
val usbDevice = dependencies.usbDevice
|
|
53
55
|
withContext(context = ioDispatcher) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
withTimeout(abortTimeoutDuration) {
|
|
57
|
+
val usbInterface = usbDevice.getInterface(DEFAULT_USB_INTERFACE)
|
|
58
|
+
val androidToUsbEndpoint =
|
|
59
|
+
usbInterface.firstEndpointOrThrow { it == UsbConstants.USB_DIR_OUT }
|
|
60
|
+
val usbToAndroidEndpoint =
|
|
61
|
+
usbInterface.firstEndpointOrThrow { it == UsbConstants.USB_DIR_IN }
|
|
62
|
+
val usbConnection = usbManager.openDevice(usbDevice)
|
|
63
|
+
.apply { claimInterface(usbInterface, true) }
|
|
58
64
|
|
|
59
|
-
|
|
60
|
-
usbConnection = usbConnection,
|
|
61
|
-
androidToUsbEndpoint = androidToUsbEndpoint,
|
|
62
|
-
rawApdu = apdu,
|
|
63
|
-
)
|
|
64
|
-
val apduResponse =
|
|
65
|
-
receiveApdu(
|
|
65
|
+
transmitApdu(
|
|
66
66
|
usbConnection = usbConnection,
|
|
67
|
-
|
|
67
|
+
androidToUsbEndpoint = androidToUsbEndpoint,
|
|
68
|
+
rawApdu = apdu,
|
|
68
69
|
)
|
|
70
|
+
val apduResponse =
|
|
71
|
+
receiveApdu(
|
|
72
|
+
usbConnection = usbConnection,
|
|
73
|
+
usbToAndroidEndpoint = usbToAndroidEndpoint,
|
|
74
|
+
)
|
|
69
75
|
|
|
70
|
-
|
|
71
|
-
|
|
76
|
+
if (apduResponse.isEmpty()) {
|
|
77
|
+
return@withTimeout SendApduResult.Failure(reason = SendApduFailureReason.EmptyResponse)
|
|
78
|
+
}
|
|
72
79
|
|
|
73
|
-
|
|
80
|
+
usbConnection.releaseInterface(usbInterface)
|
|
81
|
+
usbConnection.close()
|
|
82
|
+
|
|
83
|
+
return@withTimeout SendApduResult.Success(apdu = apduResponse)
|
|
84
|
+
}
|
|
74
85
|
}
|
|
86
|
+
} catch (e: TimeoutCancellationException) {
|
|
87
|
+
loggerService.log(
|
|
88
|
+
buildSimpleErrorLogInfo(
|
|
89
|
+
"AndroidUsbApduSender",
|
|
90
|
+
"timeout in send: $e"
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
SendApduResult.Failure(reason = SendApduFailureReason.AbortTimeout)
|
|
75
94
|
} catch (e: NoSuchElementException) {
|
|
95
|
+
loggerService.log(
|
|
96
|
+
buildSimpleErrorLogInfo(
|
|
97
|
+
"AndroidUsbApduSender",
|
|
98
|
+
"no endpoint found: $e"
|
|
99
|
+
)
|
|
100
|
+
)
|
|
76
101
|
SendApduResult.Failure(reason = SendApduFailureReason.NoUsbEndpointFound)
|
|
77
102
|
} catch (e: Exception) {
|
|
78
103
|
loggerService.log(buildSimpleErrorLogInfo("AndroidUsbApduSender", "error in send: $e"))
|
|
@@ -84,11 +109,17 @@ internal class AndroidUsbApduSender(
|
|
|
84
109
|
androidToUsbEndpoint: UsbEndpoint,
|
|
85
110
|
rawApdu: ByteArray,
|
|
86
111
|
) {
|
|
87
|
-
framerService.serialize(mtu = USB_MTU, channelId = generateChannelId(), rawApdu = rawApdu)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
112
|
+
framerService.serialize(mtu = USB_MTU, channelId = generateChannelId(), rawApdu = rawApdu)
|
|
113
|
+
.forEach { apduFrame ->
|
|
114
|
+
val buffer = apduFrame.toByteArray()
|
|
115
|
+
Timber.i("APDU sent = ${buffer.toHexadecimalString()}")
|
|
116
|
+
usbConnection.bulkTransfer(
|
|
117
|
+
androidToUsbEndpoint,
|
|
118
|
+
buffer,
|
|
119
|
+
apduFrame.size(),
|
|
120
|
+
USB_TIMEOUT
|
|
121
|
+
)
|
|
122
|
+
}
|
|
92
123
|
}
|
|
93
124
|
|
|
94
125
|
private fun receiveApdu(
|
|
@@ -99,7 +130,7 @@ internal class AndroidUsbApduSender(
|
|
|
99
130
|
request.close()
|
|
100
131
|
byteArrayOf()
|
|
101
132
|
} else {
|
|
102
|
-
val frames = framerService.createApduFrames(mtu = USB_MTU, isUsbTransport = true){
|
|
133
|
+
val frames = framerService.createApduFrames(mtu = USB_MTU, isUsbTransport = true) {
|
|
103
134
|
val buffer = ByteArray(USB_MTU)
|
|
104
135
|
val responseBuffer = ByteBuffer.allocate(USB_MTU)
|
|
105
136
|
|
|
@@ -107,11 +138,19 @@ internal class AndroidUsbApduSender(
|
|
|
107
138
|
if (!queuingResult) {
|
|
108
139
|
request.close()
|
|
109
140
|
byteArrayOf()
|
|
110
|
-
}
|
|
111
|
-
else{
|
|
141
|
+
} else {
|
|
112
142
|
usbConnection.requestWait()
|
|
113
143
|
responseBuffer.rewind()
|
|
114
|
-
|
|
144
|
+
val remaining = responseBuffer.remaining()
|
|
145
|
+
responseBuffer.get(buffer, 0, remaining)
|
|
146
|
+
loggerService.log(
|
|
147
|
+
buildSimpleDebugLogInfo(
|
|
148
|
+
"AndroidUsbApduSender",
|
|
149
|
+
"APDU frame received = ${
|
|
150
|
+
buffer.copyOfRange(0, remaining).toHexadecimalString()
|
|
151
|
+
}"
|
|
152
|
+
)
|
|
153
|
+
)
|
|
115
154
|
buffer
|
|
116
155
|
}
|
|
117
156
|
}
|
|
@@ -129,5 +168,6 @@ internal class AndroidUsbApduSender(
|
|
|
129
168
|
throw NoSuchElementException("No endpoint matching the predicate")
|
|
130
169
|
}
|
|
131
170
|
|
|
132
|
-
private fun generateChannelId(): ByteArray =
|
|
171
|
+
private fun generateChannelId(): ByteArray =
|
|
172
|
+
Random.nextInt(0, until = Int.MAX_VALUE).to2BytesArray()
|
|
133
173
|
}
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
package com.ledger.devicesdk.shared.androidMainInternal.transport.deviceconnection
|
|
7
7
|
|
|
8
8
|
import com.ledger.devicesdk.shared.api.apdu.SendApduResult
|
|
9
|
+
import kotlin.time.Duration
|
|
9
10
|
|
|
10
11
|
internal interface DeviceApduSender<Dependencies> {
|
|
11
|
-
suspend fun send(apdu: ByteArray): SendApduResult
|
|
12
|
+
suspend fun send(apdu: ByteArray, abortTimeoutDuration: Duration): SendApduResult
|
|
12
13
|
val dependencies: Dependencies
|
|
13
14
|
}
|
|
@@ -24,9 +24,9 @@ internal class DeviceConnection<Dependencies>(
|
|
|
24
24
|
|
|
25
25
|
init {
|
|
26
26
|
stateMachine = DeviceConnectionStateMachine(
|
|
27
|
-
sendApduFn = {
|
|
27
|
+
sendApduFn = { apdu, abortTimeoutDuration ->
|
|
28
28
|
coroutineScope.launch {
|
|
29
|
-
val res = deviceApduSender.send(
|
|
29
|
+
val res = deviceApduSender.send(apdu, abortTimeoutDuration)
|
|
30
30
|
handleApduResult(res)
|
|
31
31
|
}
|
|
32
32
|
},
|
|
@@ -66,12 +66,13 @@ internal class DeviceConnection<Dependencies>(
|
|
|
66
66
|
stateMachine.handleDeviceDisconnected()
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
public suspend fun requestSendApdu(apdu: ByteArray): SendApduResult =
|
|
69
|
+
public suspend fun requestSendApdu(apdu: ByteArray, triggersDisconnection: Boolean, abortTimeoutDuration: Duration): SendApduResult =
|
|
70
70
|
suspendCoroutine { cont ->
|
|
71
71
|
stateMachine.requestSendApdu(
|
|
72
72
|
DeviceConnectionStateMachine.SendApduRequestContent(
|
|
73
73
|
apdu = apdu,
|
|
74
|
-
triggersDisconnection = apduTriggersDisconnection(apdu),
|
|
74
|
+
triggersDisconnection = apduTriggersDisconnection(apdu) || triggersDisconnection,
|
|
75
|
+
abortTimeoutDuration = abortTimeoutDuration,
|
|
75
76
|
resultCallback = cont::resume
|
|
76
77
|
)
|
|
77
78
|
)
|
|
@@ -12,7 +12,7 @@ import kotlinx.coroutines.launch
|
|
|
12
12
|
import kotlin.time.Duration
|
|
13
13
|
|
|
14
14
|
internal class DeviceConnectionStateMachine(
|
|
15
|
-
private val sendApduFn: (apdu: ByteArray) -> Unit,
|
|
15
|
+
private val sendApduFn: (apdu: ByteArray, abortTimeoutDuration: Duration) -> Unit,
|
|
16
16
|
private val onTerminated: () -> Unit,
|
|
17
17
|
private val isFatalSendApduFailure: (SendApduResult.Failure) -> Boolean,
|
|
18
18
|
private val reconnectionTimeoutDuration: Duration,
|
|
@@ -29,7 +29,7 @@ internal class DeviceConnectionStateMachine(
|
|
|
29
29
|
when (newState) {
|
|
30
30
|
is State.Connected -> {}
|
|
31
31
|
is State.SendingApdu -> {
|
|
32
|
-
sendApduFn(newState.requestContent.apdu)
|
|
32
|
+
sendApduFn(newState.requestContent.apdu, newState.requestContent.abortTimeoutDuration)
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
is State.WaitingForReconnection -> {
|
|
@@ -280,6 +280,7 @@ internal class DeviceConnectionStateMachine(
|
|
|
280
280
|
data class SendApduRequestContent(
|
|
281
281
|
val apdu: ByteArray,
|
|
282
282
|
val triggersDisconnection: Boolean,
|
|
283
|
+
val abortTimeoutDuration: Duration,
|
|
283
284
|
val resultCallback: (SendApduResult) -> Unit
|
|
284
285
|
)
|
|
285
286
|
|
|
@@ -44,4 +44,8 @@ public sealed class SendApduFailureReason {
|
|
|
44
44
|
public data object DeviceDisconnected : SendApduFailureReason()
|
|
45
45
|
|
|
46
46
|
public data object Unknown : SendApduFailureReason()
|
|
47
|
+
|
|
48
|
+
public data object AbortTimeout : SendApduFailureReason()
|
|
49
|
+
|
|
50
|
+
public data object EmptyResponse : SendApduFailureReason()
|
|
47
51
|
}
|
|
@@ -9,5 +9,5 @@ internal data class InternalConnectedDevice(
|
|
|
9
9
|
val name: String,
|
|
10
10
|
val ledgerDevice: LedgerDevice,
|
|
11
11
|
val connectivity: ConnectivityType,
|
|
12
|
-
val sendApduFn: suspend (ByteArray) -> SendApduResult,
|
|
12
|
+
val sendApduFn: suspend (apdu: ByteArray, triggersDisconnection: Boolean, abortTimeoutDuration: kotlin.time.Duration) -> SendApduResult,
|
|
13
13
|
)
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var m=(i,e)=>{for(var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var D=Object.prototype.hasOwnProperty;var m=(i,e)=>{for(var n in e)d(i,n,{get:e[n],enumerable:!0})},E=(i,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of p(e))!D.call(i,t)&&t!==n&&d(i,t,{get:()=>e[t],enumerable:!(o=l(e,t))||o.enumerable});return i};var y=i=>E(d({},"__esModule",{value:!0}),i);var T={};m(T,{DefaultNativeModuleWrapper:()=>M});module.exports=y(T);var c=require("react-native"),v=require("rxjs"),u=require("../helpers/base64Utils"),r=require("./mapper"),a=require("./types");class M{_nativeModule;_deviceModelDataSource;constructor(e){this._nativeModule=e.nativeModule,this._deviceModelDataSource=e.deviceModelDataSource}startScan(){return this._nativeModule.startScan()}stopScan(){return this._nativeModule.stopScan()}subscribeToDiscoveredDevicesEvents(){return new v.Observable(e=>{const o=new c.NativeEventEmitter(this._nativeModule).addListener(a.DISCOVERED_DEVICES_EVENT,t=>{e.next(t.map(s=>(0,r.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(s,this._deviceModelDataSource)).filter(s=>s!==null))});return()=>{o.remove()}})}subscribeToDeviceDisconnectedEvents(){return new v.Observable(e=>{const o=new c.NativeEventEmitter(this._nativeModule).addListener(a.DEVICE_DISCONNECTED_EVENT,t=>{e.next((0,r.mapNativeDeviceConnectionLostToDeviceDisconnected)(t))});return()=>{o.remove()}})}subscribeToTransportLogs(){return new v.Observable(e=>{const o=new c.NativeEventEmitter(this._nativeModule).addListener(a.TRANSPORT_LOG_EVENT,t=>{e.next((0,r.mapNativeTransportLogToLog)(t))});return()=>{o.remove()}})}async connectDevice(e){const n=await this._nativeModule.connectDevice(e);return(0,r.mapNativeConnectionResultToConnectionResult)(n,this._deviceModelDataSource)}async disconnectDevice(e){return this._nativeModule.disconnectDevice(e)}async sendApdu(e,n,o,t){const s=await this._nativeModule.sendApdu(e,(0,u.uint8ArrayToBase64)(n),o,t);return(0,r.mapNativeSendApduResultToSendApduResult)(s)}}0&&(module.exports={DefaultNativeModuleWrapper});
|
|
2
2
|
//# sourceMappingURL=DefaultNativeModuleWrapper.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/DefaultNativeModuleWrapper.ts"],
|
|
4
|
-
"sourcesContent": ["import { NativeEventEmitter } from \"react-native\";\nimport {\n type DeviceModelDataSource,\n type LogParams,\n type SendApduResult,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Observable } from \"rxjs\";\n\nimport { uint8ArrayToBase64 } from \"@api/helpers/base64Utils\";\nimport { type NativeModuleWrapper } from \"@api/transport/NativeModuleWrapper\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n DEVICE_DISCONNECTED_EVENT,\n type DeviceDisconnectedEventPayload,\n DISCOVERED_DEVICES_EVENT,\n type DiscoveredDevicesEventPayload,\n type NativeLog,\n TRANSPORT_LOG_EVENT,\n} from \"./types\";\nimport { type NativeTransportModuleType } from \"./types\";\n\nexport class DefaultNativeModuleWrapper implements NativeModuleWrapper {\n private readonly _nativeModule: NativeTransportModuleType;\n private readonly _deviceModelDataSource: DeviceModelDataSource;\n\n constructor(args: {\n nativeModule: NativeTransportModuleType;\n deviceModelDataSource: DeviceModelDataSource;\n }) {\n this._nativeModule = args.nativeModule;\n this._deviceModelDataSource = args.deviceModelDataSource;\n }\n\n startScan() {\n return this._nativeModule.startScan();\n }\n\n stopScan() {\n return this._nativeModule.stopScan();\n }\n\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n > {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n DISCOVERED_DEVICES_EVENT,\n (discoveredDevices: DiscoveredDevicesEventPayload) => {\n subscriber.next(\n discoveredDevices\n .map((device) =>\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n device,\n this._deviceModelDataSource,\n ),\n )\n .filter((d) => d !== null),\n );\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected> {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n DEVICE_DISCONNECTED_EVENT,\n (device: DeviceDisconnectedEventPayload) => {\n subscriber.next(\n mapNativeDeviceConnectionLostToDeviceDisconnected(device),\n );\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n subscribeToTransportLogs(): Observable<LogParams> {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n TRANSPORT_LOG_EVENT,\n (logParams: NativeLog) => {\n subscriber.next(mapNativeTransportLogToLog(logParams));\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n async connectDevice(uid: string): Promise<InternalConnectionResult> {\n const nConnectionResult = await this._nativeModule.connectDevice(uid);\n return mapNativeConnectionResultToConnectionResult(\n nConnectionResult,\n this._deviceModelDataSource,\n );\n }\n\n async disconnectDevice(sessionId: string): Promise<void> {\n return this._nativeModule.disconnectDevice(sessionId);\n }\n\n async sendApdu(sessionId: string
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,wBAOnCC,EAA2B,gBAE3BC,EAAmC,oCAOnCC,EAMO,oBACPC,EAOO,mBAGA,MAAMN,CAA0D,CACpD,cACA,uBAEjB,YAAYO,EAGT,CACD,KAAK,cAAgBA,EAAK,aAC1B,KAAK,uBAAyBA,EAAK,qBACrC,CAEA,WAAY,CACV,OAAO,KAAK,cAAc,UAAU,CACtC,CAEA,UAAW,CACT,OAAO,KAAK,cAAc,SAAS,CACrC,CAEA,oCAEE,CACA,OAAO,IAAI,aAAYC,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,2BACCC,GAAqD,CACpDF,EAAW,KACTE,EACG,IAAKC,MACJ,uDACEA,EACA,KAAK,sBACP,CACF,EACC,OAAQC,GAAMA,IAAM,IAAI,CAC7B,CACF,CACF,EAEA,MAAO,IAAM,CACXH,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,qCAA8E,CAC5E,OAAO,IAAI,aAAYD,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,4BACCE,GAA2C,CAC1CH,EAAW,QACT,qDAAkDG,CAAM,CAC1D,CACF,CACF,EAEA,MAAO,IAAM,CACXF,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,0BAAkD,CAChD,OAAO,IAAI,aAAYD,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,sBACCI,GAAyB,CACxBL,EAAW,QAAK,8BAA2BK,CAAS,CAAC,CACvD,CACF,EAEA,MAAO,IAAM,CACXJ,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,MAAM,cAAcK,EAAgD,CAClE,MAAMC,EAAoB,MAAM,KAAK,cAAc,cAAcD,CAAG,EACpE,SAAO,+CACLC,EACA,KAAK,sBACP,CACF,CAEA,MAAM,iBAAiBC,EAAkC,CACvD,OAAO,KAAK,cAAc,iBAAiBA,CAAS,CACtD,CAEA,MAAM,
|
|
6
|
-
"names": ["DefaultNativeModuleWrapper_exports", "__export", "DefaultNativeModuleWrapper", "__toCommonJS", "import_react_native", "import_rxjs", "import_base64Utils", "import_mapper", "import_types", "args", "subscriber", "eventListener", "discoveredDevices", "device", "d", "logParams", "uid", "nConnectionResult", "sessionId", "apdu", "nSendApduResult"]
|
|
4
|
+
"sourcesContent": ["import { NativeEventEmitter } from \"react-native\";\nimport {\n type DeviceModelDataSource,\n type LogParams,\n type SendApduResult,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Observable } from \"rxjs\";\n\nimport { uint8ArrayToBase64 } from \"@api/helpers/base64Utils\";\nimport { type NativeModuleWrapper } from \"@api/transport/NativeModuleWrapper\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n mapNativeConnectionResultToConnectionResult,\n mapNativeDeviceConnectionLostToDeviceDisconnected,\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice,\n mapNativeSendApduResultToSendApduResult,\n mapNativeTransportLogToLog,\n} from \"./mapper\";\nimport {\n DEVICE_DISCONNECTED_EVENT,\n type DeviceDisconnectedEventPayload,\n DISCOVERED_DEVICES_EVENT,\n type DiscoveredDevicesEventPayload,\n type NativeLog,\n TRANSPORT_LOG_EVENT,\n} from \"./types\";\nimport { type NativeTransportModuleType } from \"./types\";\n\nexport class DefaultNativeModuleWrapper implements NativeModuleWrapper {\n private readonly _nativeModule: NativeTransportModuleType;\n private readonly _deviceModelDataSource: DeviceModelDataSource;\n\n constructor(args: {\n nativeModule: NativeTransportModuleType;\n deviceModelDataSource: DeviceModelDataSource;\n }) {\n this._nativeModule = args.nativeModule;\n this._deviceModelDataSource = args.deviceModelDataSource;\n }\n\n startScan() {\n return this._nativeModule.startScan();\n }\n\n stopScan() {\n return this._nativeModule.stopScan();\n }\n\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n > {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n DISCOVERED_DEVICES_EVENT,\n (discoveredDevices: DiscoveredDevicesEventPayload) => {\n subscriber.next(\n discoveredDevices\n .map((device) =>\n mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n device,\n this._deviceModelDataSource,\n ),\n )\n .filter((d) => d !== null),\n );\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected> {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n DEVICE_DISCONNECTED_EVENT,\n (device: DeviceDisconnectedEventPayload) => {\n subscriber.next(\n mapNativeDeviceConnectionLostToDeviceDisconnected(device),\n );\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n subscribeToTransportLogs(): Observable<LogParams> {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n TRANSPORT_LOG_EVENT,\n (logParams: NativeLog) => {\n subscriber.next(mapNativeTransportLogToLog(logParams));\n },\n );\n\n return () => {\n eventListener.remove();\n };\n });\n }\n\n async connectDevice(uid: string): Promise<InternalConnectionResult> {\n const nConnectionResult = await this._nativeModule.connectDevice(uid);\n return mapNativeConnectionResultToConnectionResult(\n nConnectionResult,\n this._deviceModelDataSource,\n );\n }\n\n async disconnectDevice(sessionId: string): Promise<void> {\n return this._nativeModule.disconnectDevice(sessionId);\n }\n\n async sendApdu(\n sessionId: string,\n apdu: Uint8Array,\n triggersDisconnection: boolean,\n abortTimeout: number,\n ): Promise<SendApduResult> {\n const nSendApduResult = await this._nativeModule.sendApdu(\n sessionId,\n uint8ArrayToBase64(apdu),\n triggersDisconnection,\n abortTimeout,\n );\n return mapNativeSendApduResultToSendApduResult(nSendApduResult);\n }\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,gCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAmC,wBAOnCC,EAA2B,gBAE3BC,EAAmC,oCAOnCC,EAMO,oBACPC,EAOO,mBAGA,MAAMN,CAA0D,CACpD,cACA,uBAEjB,YAAYO,EAGT,CACD,KAAK,cAAgBA,EAAK,aAC1B,KAAK,uBAAyBA,EAAK,qBACrC,CAEA,WAAY,CACV,OAAO,KAAK,cAAc,UAAU,CACtC,CAEA,UAAW,CACT,OAAO,KAAK,cAAc,SAAS,CACrC,CAEA,oCAEE,CACA,OAAO,IAAI,aAAYC,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,2BACCC,GAAqD,CACpDF,EAAW,KACTE,EACG,IAAKC,MACJ,uDACEA,EACA,KAAK,sBACP,CACF,EACC,OAAQC,GAAMA,IAAM,IAAI,CAC7B,CACF,CACF,EAEA,MAAO,IAAM,CACXH,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,qCAA8E,CAC5E,OAAO,IAAI,aAAYD,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,4BACCE,GAA2C,CAC1CH,EAAW,QACT,qDAAkDG,CAAM,CAC1D,CACF,CACF,EAEA,MAAO,IAAM,CACXF,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,0BAAkD,CAChD,OAAO,IAAI,aAAYD,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,sBACCI,GAAyB,CACxBL,EAAW,QAAK,8BAA2BK,CAAS,CAAC,CACvD,CACF,EAEA,MAAO,IAAM,CACXJ,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,MAAM,cAAcK,EAAgD,CAClE,MAAMC,EAAoB,MAAM,KAAK,cAAc,cAAcD,CAAG,EACpE,SAAO,+CACLC,EACA,KAAK,sBACP,CACF,CAEA,MAAM,iBAAiBC,EAAkC,CACvD,OAAO,KAAK,cAAc,iBAAiBA,CAAS,CACtD,CAEA,MAAM,SACJA,EACAC,EACAC,EACAC,EACyB,CACzB,MAAMC,EAAkB,MAAM,KAAK,cAAc,SAC/CJ,KACA,sBAAmBC,CAAI,EACvBC,EACAC,CACF,EACA,SAAO,2CAAwCC,CAAe,CAChE,CACF",
|
|
6
|
+
"names": ["DefaultNativeModuleWrapper_exports", "__export", "DefaultNativeModuleWrapper", "__toCommonJS", "import_react_native", "import_rxjs", "import_base64Utils", "import_mapper", "import_types", "args", "subscriber", "eventListener", "discoveredDevices", "device", "d", "logParams", "uid", "nConnectionResult", "sessionId", "apdu", "triggersDisconnection", "abortTimeout", "nSendApduResult"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var o in t)a(e,o,{get:t[o],enumerable:!0})},f=(e,t,o,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of l(t))!m.call(e,i)&&i!==o&&a(e,i,{get:()=>t[i],enumerable:!(s=v(t,i))||s.enumerable});return e};var y=e=>f(a({},"__esModule",{value:!0}),e);var b={};D(b,{mapNativeConnectionResultToConnectionResult:()=>R,mapNativeDeviceConnectionLostToDeviceDisconnected:()=>T,mapNativeDiscoveryDeviceToTransportDiscoveredDevice:()=>N,mapNativeLedgerDeviceToDeviceModel:()=>c,mapNativeSendApduResultToSendApduResult:()=>L,mapNativeTransportLogToLog:()=>g});module.exports=y(b);var r=require("@ledgerhq/device-management-kit"),n=require("purify-ts"),d=require("../helpers/base64Utils"),p=require("../transport/Errors"),u=require("../transport/rnHidTransportIdentifier");function c(e,t){return t.filterDeviceModels({usbProductId:Number.parseInt(e.usbProductIdMask,16)})[0]??null}function N(e,t){const o=c(e.ledgerDevice,t);return o==null?null:{id:e.uid,deviceModel:o,transport:u.TRANSPORT_IDENTIFIER,name:e.name}}function g(e){let t;switch(e.level){case"error":t=r.LogLevel.Error;break;case"warning":t=r.LogLevel.Warning;break;case"info":t=r.LogLevel.Info;break;case"debug":t=r.LogLevel.Debug;break;default:I(e.level),t=r.LogLevel.Info;break}return[t,e.message,{tag:e.tag,data:e.jsonPayload,timestamp:Number.parseInt(e.timestamp,10)}]}function I(e){throw new Error("Unexpected object: "+e)}function R(e,t){if(e.success){const o=c(e.ledgerDevice,t);return o?(0,n.Right)({sessionId:e.sessionId,transportDeviceModel:o}):(0,n.Left)(new r.OpeningConnectionError(`Could not find device model for the connected device with usbProductIdMask: ${e.ledgerDevice.usbProductIdMask}`))}else return(0,n.Left)(new r.OpeningConnectionError(e.error))}function L(e){if(e.success){const t=(0,d.base64ToUint8Array)(e.apdu),o=r.FramerUtils.getFirstBytesFrom(t,t.length-2),s=r.FramerUtils.getLastBytesFrom(t,2);return(0,n.Right)(new r.ApduResponse({data:o,statusCode:s}))}else return e.error==="SendApduTimeout"?(0,n.Left)(new r.SendApduTimeoutError("Abort timeout")):e.error==="EmptyResponseError"?(0,n.Left)(new r.SendApduEmptyResponseError("Empty response")):(0,n.Left)(new p.SendApduError(e.error))}function T(e){return{sessionId:e.id}}0&&(module.exports={mapNativeConnectionResultToConnectionResult,mapNativeDeviceConnectionLostToDeviceDisconnected,mapNativeDiscoveryDeviceToTransportDiscoveredDevice,mapNativeLedgerDeviceToDeviceModel,mapNativeSendApduResultToSendApduResult,mapNativeTransportLogToLog});
|
|
2
2
|
//# sourceMappingURL=mapper.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/mapper.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n ApduResponse,\n type DeviceModelDataSource,\n FramerUtils,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n type SendApduResult,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { base64ToUint8Array } from \"@api/helpers/base64Utils\";\nimport { SendApduError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n type NativeDeviceConnectionLost,\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\nexport function mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice: NativeLedgerDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDeviceModel | null {\n return (\n deviceModelDataSource.filterDeviceModels({\n usbProductId: Number.parseInt(nativeLedgerDevice.usbProductIdMask, 16),\n })[0] ?? null\n );\n}\n\nexport function mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice: NativeDiscoveryDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDiscoveredDevice | null {\n const deviceModel = mapNativeLedgerDeviceToDeviceModel(\n nativeDevice.ledgerDevice,\n deviceModelDataSource,\n );\n if (deviceModel == null) return null;\n\n return {\n id: nativeDevice.uid,\n deviceModel,\n transport: TRANSPORT_IDENTIFIER,\n name: nativeDevice.name,\n };\n}\n\nexport function mapNativeTransportLogToLog(log: NativeLog): LogParams {\n let level: LogLevel;\n switch (log.level) {\n case \"error\":\n level = LogLevel.Error;\n break;\n case \"warning\":\n level = LogLevel.Warning;\n break;\n case \"info\":\n level = LogLevel.Info;\n break;\n case \"debug\":\n level = LogLevel.Debug;\n break;\n default:\n assertNever(log.level);\n level = LogLevel.Info;\n break;\n }\n\n return [\n level,\n log.message,\n {\n tag: log.tag,\n data: log.jsonPayload,\n timestamp: Number.parseInt(log.timestamp, 10),\n },\n ];\n}\n\nfunction assertNever(x: never) {\n throw new Error(\"Unexpected object: \" + x);\n}\n\nexport function mapNativeConnectionResultToConnectionResult(\n result: NativeInternalConnectionResult,\n deviceModelDataSource: DeviceModelDataSource,\n): InternalConnectionResult {\n if (result.success) {\n const transportDeviceModel = mapNativeLedgerDeviceToDeviceModel(\n result.ledgerDevice,\n deviceModelDataSource,\n );\n if (!transportDeviceModel)\n return Left(\n new OpeningConnectionError(\n `Could not find device model for the connected device with usbProductIdMask: ${result.ledgerDevice.usbProductIdMask}`,\n ),\n );\n return Right({ sessionId: result.sessionId, transportDeviceModel });\n } else {\n return Left(new OpeningConnectionError(result.error));\n }\n}\n\nexport function mapNativeSendApduResultToSendApduResult(\n result: NativeSendApduResult,\n): SendApduResult {\n if (result.success) {\n const responseBytes = base64ToUint8Array(result.apdu);\n const data = FramerUtils.getFirstBytesFrom(\n responseBytes,\n responseBytes.length - 2,\n );\n const statusCode = FramerUtils.getLastBytesFrom(responseBytes, 2);\n return Right(new ApduResponse({ data, statusCode }));\n } else {\n return Left(new SendApduError(result.error));\n }\n}\n\nexport function mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost: NativeDeviceConnectionLost,\n): InternalDeviceDisconnected {\n return {\n sessionId: nativeDeviceConnectionLost.id,\n };\n}\n"],
|
|
5
|
-
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iDAAAE,EAAA,sDAAAC,EAAA,wDAAAC,EAAA,uCAAAC,EAAA,4CAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAR,GAAA,IAAAS,
|
|
4
|
+
"sourcesContent": ["import {\n ApduResponse,\n type DeviceModelDataSource,\n FramerUtils,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n SendApduEmptyResponseError,\n type SendApduResult,\n SendApduTimeoutError,\n type TransportDeviceModel,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts\";\n\nimport { base64ToUint8Array } from \"@api/helpers/base64Utils\";\nimport { SendApduError } from \"@api/transport/Errors\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nimport {\n type NativeDeviceConnectionLost,\n type NativeDiscoveryDevice,\n type NativeInternalConnectionResult,\n type NativeLedgerDevice,\n type NativeLog,\n type NativeSendApduResult,\n} from \"./types\";\n\nexport function mapNativeLedgerDeviceToDeviceModel(\n nativeLedgerDevice: NativeLedgerDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDeviceModel | null {\n return (\n deviceModelDataSource.filterDeviceModels({\n usbProductId: Number.parseInt(nativeLedgerDevice.usbProductIdMask, 16),\n })[0] ?? null\n );\n}\n\nexport function mapNativeDiscoveryDeviceToTransportDiscoveredDevice(\n nativeDevice: NativeDiscoveryDevice,\n deviceModelDataSource: DeviceModelDataSource,\n): TransportDiscoveredDevice | null {\n const deviceModel = mapNativeLedgerDeviceToDeviceModel(\n nativeDevice.ledgerDevice,\n deviceModelDataSource,\n );\n if (deviceModel == null) return null;\n\n return {\n id: nativeDevice.uid,\n deviceModel,\n transport: TRANSPORT_IDENTIFIER,\n name: nativeDevice.name,\n };\n}\n\nexport function mapNativeTransportLogToLog(log: NativeLog): LogParams {\n let level: LogLevel;\n switch (log.level) {\n case \"error\":\n level = LogLevel.Error;\n break;\n case \"warning\":\n level = LogLevel.Warning;\n break;\n case \"info\":\n level = LogLevel.Info;\n break;\n case \"debug\":\n level = LogLevel.Debug;\n break;\n default:\n assertNever(log.level);\n level = LogLevel.Info;\n break;\n }\n\n return [\n level,\n log.message,\n {\n tag: log.tag,\n data: log.jsonPayload,\n timestamp: Number.parseInt(log.timestamp, 10),\n },\n ];\n}\n\nfunction assertNever(x: never) {\n throw new Error(\"Unexpected object: \" + x);\n}\n\nexport function mapNativeConnectionResultToConnectionResult(\n result: NativeInternalConnectionResult,\n deviceModelDataSource: DeviceModelDataSource,\n): InternalConnectionResult {\n if (result.success) {\n const transportDeviceModel = mapNativeLedgerDeviceToDeviceModel(\n result.ledgerDevice,\n deviceModelDataSource,\n );\n if (!transportDeviceModel)\n return Left(\n new OpeningConnectionError(\n `Could not find device model for the connected device with usbProductIdMask: ${result.ledgerDevice.usbProductIdMask}`,\n ),\n );\n return Right({ sessionId: result.sessionId, transportDeviceModel });\n } else {\n return Left(new OpeningConnectionError(result.error));\n }\n}\n\nexport function mapNativeSendApduResultToSendApduResult(\n result: NativeSendApduResult,\n): SendApduResult {\n if (result.success) {\n const responseBytes = base64ToUint8Array(result.apdu);\n const data = FramerUtils.getFirstBytesFrom(\n responseBytes,\n responseBytes.length - 2,\n );\n const statusCode = FramerUtils.getLastBytesFrom(responseBytes, 2);\n return Right(new ApduResponse({ data, statusCode }));\n } else if (result.error === \"SendApduTimeout\") {\n return Left(new SendApduTimeoutError(\"Abort timeout\"));\n } else if (result.error === \"EmptyResponseError\") {\n return Left(new SendApduEmptyResponseError(\"Empty response\"));\n } else {\n return Left(new SendApduError(result.error));\n }\n}\n\nexport function mapNativeDeviceConnectionLostToDeviceDisconnected(\n nativeDeviceConnectionLost: NativeDeviceConnectionLost,\n): InternalDeviceDisconnected {\n return {\n sessionId: nativeDeviceConnectionLost.id,\n };\n}\n"],
|
|
5
|
+
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,iDAAAE,EAAA,sDAAAC,EAAA,wDAAAC,EAAA,uCAAAC,EAAA,4CAAAC,EAAA,+BAAAC,IAAA,eAAAC,EAAAR,GAAA,IAAAS,EAYO,2CACPC,EAA4B,qBAE5BC,EAAmC,oCACnCC,EAA8B,iCAC9BC,EAAqC,mDAe9B,SAASR,EACdS,EACAC,EAC6B,CAC7B,OACEA,EAAsB,mBAAmB,CACvC,aAAc,OAAO,SAASD,EAAmB,iBAAkB,EAAE,CACvE,CAAC,EAAE,CAAC,GAAK,IAEb,CAEO,SAASV,EACdY,EACAD,EACkC,CAClC,MAAME,EAAcZ,EAClBW,EAAa,aACbD,CACF,EACA,OAAIE,GAAe,KAAa,KAEzB,CACL,GAAID,EAAa,IACjB,YAAAC,EACA,UAAW,uBACX,KAAMD,EAAa,IACrB,CACF,CAEO,SAAST,EAA2BW,EAA2B,CACpE,IAAIC,EACJ,OAAQD,EAAI,MAAO,CACjB,IAAK,QACHC,EAAQ,WAAS,MACjB,MACF,IAAK,UACHA,EAAQ,WAAS,QACjB,MACF,IAAK,OACHA,EAAQ,WAAS,KACjB,MACF,IAAK,QACHA,EAAQ,WAAS,MACjB,MACF,QACEC,EAAYF,EAAI,KAAK,EACrBC,EAAQ,WAAS,KACjB,KACJ,CAEA,MAAO,CACLA,EACAD,EAAI,QACJ,CACE,IAAKA,EAAI,IACT,KAAMA,EAAI,YACV,UAAW,OAAO,SAASA,EAAI,UAAW,EAAE,CAC9C,CACF,CACF,CAEA,SAASE,EAAYC,EAAU,CAC7B,MAAM,IAAI,MAAM,sBAAwBA,CAAC,CAC3C,CAEO,SAASnB,EACdoB,EACAP,EAC0B,CAC1B,GAAIO,EAAO,QAAS,CAClB,MAAMC,EAAuBlB,EAC3BiB,EAAO,aACPP,CACF,EACA,OAAKQ,KAME,SAAM,CAAE,UAAWD,EAAO,UAAW,qBAAAC,CAAqB,CAAC,KALzD,QACL,IAAI,yBACF,+EAA+ED,EAAO,aAAa,gBAAgB,EACrH,CACF,CAEJ,KACE,UAAO,QAAK,IAAI,yBAAuBA,EAAO,KAAK,CAAC,CAExD,CAEO,SAAShB,EACdgB,EACgB,CAChB,GAAIA,EAAO,QAAS,CAClB,MAAME,KAAgB,sBAAmBF,EAAO,IAAI,EAC9CG,EAAO,cAAY,kBACvBD,EACAA,EAAc,OAAS,CACzB,EACME,EAAa,cAAY,iBAAiBF,EAAe,CAAC,EAChE,SAAO,SAAM,IAAI,eAAa,CAAE,KAAAC,EAAM,WAAAC,CAAW,CAAC,CAAC,CACrD,KAAO,QAAIJ,EAAO,QAAU,qBACnB,QAAK,IAAI,uBAAqB,eAAe,CAAC,EAC5CA,EAAO,QAAU,wBACnB,QAAK,IAAI,6BAA2B,gBAAgB,CAAC,KAErD,QAAK,IAAI,gBAAcA,EAAO,KAAK,CAAC,CAE/C,CAEO,SAASnB,EACdwB,EAC4B,CAC5B,MAAO,CACL,UAAWA,EAA2B,EACxC,CACF",
|
|
6
6
|
"names": ["mapper_exports", "__export", "mapNativeConnectionResultToConnectionResult", "mapNativeDeviceConnectionLostToDeviceDisconnected", "mapNativeDiscoveryDeviceToTransportDiscoveredDevice", "mapNativeLedgerDeviceToDeviceModel", "mapNativeSendApduResultToSendApduResult", "mapNativeTransportLogToLog", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_base64Utils", "import_Errors", "import_rnHidTransportIdentifier", "nativeLedgerDevice", "deviceModelDataSource", "nativeDevice", "deviceModel", "log", "level", "assertNever", "x", "result", "transportDeviceModel", "responseBytes", "data", "statusCode", "nativeDeviceConnectionLost"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var s=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var v=(t,e)=>{for(var o in e)s(t,o,{get:e[o],enumerable:!0})},d=(t,e,o,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of a(e))!c.call(t,i)&&i!==o&&s(t,i,{get:()=>e[i],enumerable:!(r=n(e,i))||r.enumerable});return t};var p=t=>d(s({},"__esModule",{value:!0}),t);var N={};v(N,{DEVICE_DISCONNECTED_EVENT:()=>D,DISCOVERED_DEVICES_EVENT:()=>g,TRANSPORT_LOG_EVENT:()=>u});module.exports=p(N);const g="DiscoveredDevices",u="TransportLog",D="DeviceDisconnected";0&&(module.exports={DEVICE_DISCONNECTED_EVENT,DISCOVERED_DEVICES_EVENT,TRANSPORT_LOG_EVENT});
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/bridge/types.ts"],
|
|
4
|
-
"sourcesContent": ["import { type NativeModule } from \"react-native\";\n\nexport type NativeLedgerDevice = {\n name: \"NanoS\" | \"NanoSPlus\" | \"NanoX\" | \"Flex\" | \"Stax\";\n usbProductIdMask: string;\n};\n\nexport type NativeDiscoveryDevice = {\n uid: string;\n name: string;\n ledgerDevice: NativeLedgerDevice;\n};\n\ntype NativeLogLevel = \"debug\" | \"info\" | \"warning\" | \"error\";\n\nexport type NativeLog = {\n level: NativeLogLevel;\n tag: string;\n message: string;\n jsonPayload: Record<string, string>;\n timestamp: string;\n};\n\nexport type NativeInternalConnectionResult =\n | {\n success: true;\n sessionId: string;\n ledgerDevice: NativeLedgerDevice;\n deviceName: string;\n }\n | {\n success: false;\n error: string;\n };\n\nexport type NativeSendApduResult =\n | {\n success: true;\n apdu: string;\n }\n | {\n success: false;\n error: string;\n };\n\nexport type NativeDeviceConnectionLost = {\n id: string;\n};\n\n/**\n * Events\n */\n\n/** DiscoveredDevices */\nexport const DISCOVERED_DEVICES_EVENT = \"DiscoveredDevices\";\nexport type DiscoveredDevicesEventPayload = Array<NativeDiscoveryDevice>;\n\n/** TransportLog */\nexport const TRANSPORT_LOG_EVENT = \"TransportLog\";\nexport type LogEventPayload = NativeLog;\n\n/** DeviceDisconnected */\nexport const DEVICE_DISCONNECTED_EVENT = \"DeviceDisconnected\";\nexport type DeviceDisconnectedEventPayload = NativeDeviceConnectionLost;\n\n/**\n * Signature of the native transport module.\n */\nexport type NativeTransportModuleType = {\n startScan: () => Promise<void>;\n stopScan: () => Promise<void>;\n connectDevice: (uid: string) => Promise<NativeInternalConnectionResult>;\n disconnectDevice: (sessionId: string) => Promise<void>;\n sendApdu: (sessionId: string
|
|
4
|
+
"sourcesContent": ["import { type NativeModule } from \"react-native\";\n\nexport type NativeLedgerDevice = {\n name: \"NanoS\" | \"NanoSPlus\" | \"NanoX\" | \"Flex\" | \"Stax\";\n usbProductIdMask: string;\n};\n\nexport type NativeDiscoveryDevice = {\n uid: string;\n name: string;\n ledgerDevice: NativeLedgerDevice;\n};\n\ntype NativeLogLevel = \"debug\" | \"info\" | \"warning\" | \"error\";\n\nexport type NativeLog = {\n level: NativeLogLevel;\n tag: string;\n message: string;\n jsonPayload: Record<string, string>;\n timestamp: string;\n};\n\nexport type NativeInternalConnectionResult =\n | {\n success: true;\n sessionId: string;\n ledgerDevice: NativeLedgerDevice;\n deviceName: string;\n }\n | {\n success: false;\n error: string;\n };\n\nexport type NativeSendApduResult =\n | {\n success: true;\n apdu: string;\n }\n | {\n success: false;\n error: string | \"SendApduTimeout\";\n };\n\nexport type NativeDeviceConnectionLost = {\n id: string;\n};\n\n/**\n * Events\n */\n\n/** DiscoveredDevices */\nexport const DISCOVERED_DEVICES_EVENT = \"DiscoveredDevices\";\nexport type DiscoveredDevicesEventPayload = Array<NativeDiscoveryDevice>;\n\n/** TransportLog */\nexport const TRANSPORT_LOG_EVENT = \"TransportLog\";\nexport type LogEventPayload = NativeLog;\n\n/** DeviceDisconnected */\nexport const DEVICE_DISCONNECTED_EVENT = \"DeviceDisconnected\";\nexport type DeviceDisconnectedEventPayload = NativeDeviceConnectionLost;\n\n/**\n * Signature of the native transport module.\n */\nexport type NativeTransportModuleType = {\n startScan: () => Promise<void>;\n stopScan: () => Promise<void>;\n connectDevice: (uid: string) => Promise<NativeInternalConnectionResult>;\n disconnectDevice: (sessionId: string) => Promise<void>;\n sendApdu: (\n sessionId: string,\n apdu: string,\n triggersDisconnection: boolean,\n abortTimeout: number,\n ) => Promise<NativeSendApduResult>;\n} & NativeModule;\n"],
|
|
5
5
|
"mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,6BAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAL,GAsDO,MAAMG,EAA2B,oBAI3BC,EAAsB,eAItBF,EAA4B",
|
|
6
6
|
"names": ["types_exports", "__export", "DEVICE_DISCONNECTED_EVENT", "DISCOVERED_DEVICES_EVENT", "TRANSPORT_LOG_EVENT", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var t=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var d=(r,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of c(e))!a.call(r,s)&&s!==i&&o(r,s,{get:()=>e[s],enumerable:!(n=t(e,s))||n.enumerable});return r};var v=r=>d(o({},"__esModule",{value:!0}),r);var p={};module.exports=v(p);
|
|
2
2
|
//# sourceMappingURL=NativeModuleWrapper.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/api/transport/NativeModuleWrapper.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n type LogParams,\n type SendApduResult,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Observable } from \"rxjs\";\n\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"./types\";\n\n/**\n * Interface for the native module wrapper.\n * This interface is used to abstract the native module implementation & its\n * types, basically the implementation of the \"bridge\".\n * It is useful in case the (future) iOS native module signature is different\n * from the Android one.\n * It allows the RNHidTransport implementation to be platform-agnostic and\n * independent from the native module implementation.\n */\nexport interface NativeModuleWrapper {\n startScan(): Promise<void>;\n stopScan(): Promise<void>;\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n >;\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected>;\n subscribeToTransportLogs(): Observable<LogParams>;\n connectDevice(uid: string): Promise<InternalConnectionResult>;\n disconnectDevice(uid: string): Promise<void>;\n sendApdu(sessionId: string
|
|
4
|
+
"sourcesContent": ["import {\n type LogParams,\n type SendApduResult,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Observable } from \"rxjs\";\n\nimport {\n type InternalConnectionResult,\n type InternalDeviceDisconnected,\n} from \"./types\";\n\n/**\n * Interface for the native module wrapper.\n * This interface is used to abstract the native module implementation & its\n * types, basically the implementation of the \"bridge\".\n * It is useful in case the (future) iOS native module signature is different\n * from the Android one.\n * It allows the RNHidTransport implementation to be platform-agnostic and\n * independent from the native module implementation.\n */\nexport interface NativeModuleWrapper {\n startScan(): Promise<void>;\n stopScan(): Promise<void>;\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n >;\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected>;\n subscribeToTransportLogs(): Observable<LogParams>;\n connectDevice(uid: string): Promise<InternalConnectionResult>;\n disconnectDevice(uid: string): Promise<void>;\n sendApdu(\n sessionId: string,\n apdu: Uint8Array,\n triggersDisconnection: boolean,\n abortTimeout: number,\n ): Promise<SendApduResult>;\n}\n"],
|
|
5
5
|
"mappings": "+WAAA,IAAAA,EAAA,kBAAAC,EAAAD",
|
|
6
6
|
"names": ["NativeModuleWrapper_exports", "__toCommonJS"]
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var T=(n,r)=>{for(var t in r)d(n,t,{get:r[t],enumerable:!0})},m=(n,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of _(r))!S.call(n,e)&&e!==t&&d(n,e,{get:()=>r[e],enumerable:!(i=D(r,e))||i.enumerable});return n};var f=n=>m(d({},"__esModule",{value:!0}),n);var M={};T(M,{RNHidTransport:()=>E});module.exports=f(M);var o=require("@ledgerhq/device-management-kit"),s=require("purify-ts"),g=require("rxjs"),l=require("../helpers/getObservableOfArraysNewItems"),u=require("../transport/rnHidTransportIdentifier"),b=require("./Errors");class E{constructor(r,t,i){this._isSupported=r;this._nativeModuleWrapper=t;this._loggerService=i("RNHidTransport"),this._nativeModuleWrapper.subscribeToTransportLogs().subscribe(e=>{const[a,c,p]=e,v={[o.LogLevel.Fatal]:this._loggerService.error.bind(this._loggerService),[o.LogLevel.Error]:this._loggerService.error.bind(this._loggerService),[o.LogLevel.Warning]:this._loggerService.warn.bind(this._loggerService),[o.LogLevel.Info]:this._loggerService.info.bind(this._loggerService),[o.LogLevel.Debug]:this._loggerService.debug.bind(this._loggerService)}[a];v(c,p)})}_loggerService;getIdentifier(){return u.TRANSPORT_IDENTIFIER}isSupported(){return this._isSupported}startDiscovering(){return new g.Observable(t=>{const i=(0,l.getObservableOfArraysNewItems)(this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),e=>e.id).subscribe(t);return this._nativeModuleWrapper.startScan().catch(e=>{t.error(e),this._loggerService.error("startDiscovering error",e)}),()=>i.unsubscribe()})}stopDiscovering(){this._nativeModuleWrapper.stopScan().catch(r=>{this._loggerService.error("stopDiscovering error",r)})}listenToAvailableDevices(){return new g.Observable(t=>{const i=this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents().subscribe(e=>{t.next(e)});return this._nativeModuleWrapper.startScan().catch(e=>{this._loggerService.error("startDiscovering error",e),t.error(e)}),()=>{i.unsubscribe(),this._nativeModuleWrapper.stopScan().catch(e=>{this._loggerService.error("stopDiscovering error",e)})}})}connect(r){return this._nativeModuleWrapper.connectDevice(r.deviceId).then(t=>t.map(({sessionId:i,transportDeviceModel:e})=>{const a=this._nativeModuleWrapper.subscribeToDeviceDisconnectedEvents().subscribe(c=>{c.sessionId===i&&(r.onDisconnect(i),a.unsubscribe())});return new o.TransportConnectedDevice({id:i,deviceModel:e,sendApdu:async(c,p=!1,v=-1)=>this._nativeModuleWrapper.sendApdu(i,c,p,v).catch(h=>(0,s.Left)(new b.SendApduError(h))),transport:this.getIdentifier(),type:"USB"})})).catch(t=>(0,s.Left)(new o.OpeningConnectionError(t)))}disconnect(r){return this._nativeModuleWrapper.disconnectDevice(r.connectedDevice.id).then(()=>(0,s.Right)(void 0)).catch(t=>(0,s.Left)(new o.DisconnectError(t)))}}0&&(module.exports={RNHidTransport});
|
|
2
2
|
//# sourceMappingURL=RNHidTransport.js.map
|