@ledgerhq/device-transport-kit-react-native-hid 0.0.0-rn-hid-improvements-20250523090318 → 0.0.0-rn-hid-improvements-explorations-20250523153215

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/android/src/main/kotlin/com/ledger/androidtransporthid/BridgeEvents.kt +3 -0
  2. package/android/src/main/kotlin/com/ledger/androidtransporthid/TransportHidModule.kt +38 -0
  3. package/android/src/main/kotlin/com/ledger/androidtransporthid/bridge/serialization.kt +8 -0
  4. package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js +1 -1
  5. package/lib/cjs/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
  6. package/lib/cjs/api/bridge/StubNativeModuleWrapper.js +1 -1
  7. package/lib/cjs/api/bridge/StubNativeModuleWrapper.js.map +2 -2
  8. package/lib/cjs/api/bridge/types.js +1 -1
  9. package/lib/cjs/api/bridge/types.js.map +3 -3
  10. package/lib/cjs/api/transport/NativeModuleWrapper.js +1 -1
  11. package/lib/cjs/api/transport/NativeModuleWrapper.js.map +1 -1
  12. package/lib/cjs/api/transport/RNHidTransport.js +1 -1
  13. package/lib/cjs/api/transport/RNHidTransport.js.map +3 -3
  14. package/lib/cjs/api/transport/RNHidTransport.test.js +1 -1
  15. package/lib/cjs/api/transport/RNHidTransport.test.js.map +2 -2
  16. package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js +1 -1
  17. package/lib/esm/api/bridge/DefaultNativeModuleWrapper.js.map +3 -3
  18. package/lib/esm/api/bridge/StubNativeModuleWrapper.js +1 -1
  19. package/lib/esm/api/bridge/StubNativeModuleWrapper.js.map +2 -2
  20. package/lib/esm/api/bridge/types.js +1 -1
  21. package/lib/esm/api/bridge/types.js.map +3 -3
  22. package/lib/esm/api/transport/RNHidTransport.js +1 -1
  23. package/lib/esm/api/transport/RNHidTransport.js.map +3 -3
  24. package/lib/esm/api/transport/RNHidTransport.test.js +1 -1
  25. package/lib/esm/api/transport/RNHidTransport.test.js.map +2 -2
  26. package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts +3 -0
  27. package/lib/types/api/bridge/DefaultNativeModuleWrapper.d.ts.map +1 -1
  28. package/lib/types/api/bridge/StubNativeModuleWrapper.d.ts +5 -0
  29. package/lib/types/api/bridge/StubNativeModuleWrapper.d.ts.map +1 -1
  30. package/lib/types/api/bridge/types.d.ts +7 -0
  31. package/lib/types/api/bridge/types.d.ts.map +1 -1
  32. package/lib/types/api/transport/NativeModuleWrapper.d.ts +3 -0
  33. package/lib/types/api/transport/NativeModuleWrapper.d.ts.map +1 -1
  34. package/lib/types/api/transport/RNHidTransport.d.ts +2 -0
  35. package/lib/types/api/transport/RNHidTransport.d.ts.map +1 -1
  36. package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
  37. package/package.json +4 -4
@@ -26,6 +26,9 @@ internal sealed class BridgeEvents(val eventName: String, val params: EventParam
26
26
  data class DeviceDisconnected(
27
27
  val deviceConnectionLost: TransportEvent.DeviceConnectionLost,
28
28
  ): BridgeEvents("DeviceDisconnected", EventParams.WMap(deviceConnectionLost.toWritableMap()))
29
+ data class ExchangeBulkApdusEvent(
30
+ val exchangeBulkProgressEvent: TransportHidModule.ExchangeBulkProgressEvent
31
+ ): BridgeEvents("ExchangeBulkApdus", EventParams.WMap(exchangeBulkProgressEvent.toWritableMap()))
29
32
  }
30
33
 
31
34
  internal fun sendEvent(reactContext: ReactContext, bridgeEvent: BridgeEvents) {
@@ -10,6 +10,7 @@ import com.facebook.react.bridge.Promise
10
10
  import com.facebook.react.bridge.ReactApplicationContext
11
11
  import com.facebook.react.bridge.ReactContextBaseJavaModule
12
12
  import com.facebook.react.bridge.ReactMethod
13
+ import com.facebook.react.bridge.ReadableArray
13
14
  import com.ledger.androidtransporthid.bridge.toWritableMap
14
15
  import com.ledger.devicesdk.shared.androidMain.transport.usb.AndroidUsbTransport
15
16
  import com.ledger.devicesdk.shared.androidMain.transport.usb.DefaultAndroidUsbTransport
@@ -17,6 +18,7 @@ import com.ledger.devicesdk.shared.androidMain.transport.usb.controller.ACTION_U
17
18
  import com.ledger.devicesdk.shared.androidMain.transport.usb.controller.UsbAttachedReceiverController
18
19
  import com.ledger.devicesdk.shared.androidMain.transport.usb.controller.UsbDetachedReceiverController
19
20
  import com.ledger.devicesdk.shared.androidMain.transport.usb.controller.UsbPermissionReceiver
21
+ import com.ledger.devicesdk.shared.api.apdu.SendApduResult
20
22
  import com.ledger.devicesdk.shared.api.discovery.DiscoveryDevice
21
23
  import com.ledger.devicesdk.shared.internal.connection.InternalConnectedDevice
22
24
  import com.ledger.devicesdk.shared.internal.connection.InternalConnectionResult
@@ -258,6 +260,37 @@ class TransportHidModule(
258
260
  }
259
261
  }
260
262
 
263
+ @ReactMethod
264
+ public fun exchangeBulkApdus(
265
+ sessionId: String,
266
+ apdus: ReadableArray,
267
+ requestId: Int,
268
+ promise: Promise,
269
+ ) {
270
+ // find connected device, loop over all apdus and send them to the device, and send back the last result
271
+ val device = connectedDevices.firstOrNull() { it.id == sessionId }
272
+ if (device == null) {
273
+ promise.reject(Exception("[TransportHidModule][exchangeBulkApdus] Device not found"))
274
+ return
275
+ }
276
+ coroutineScope.launch {
277
+ try {
278
+ val apdusList = apdus.toArrayList()
279
+ val apdusByteArray = apdusList.map { Base64.decode(it as String, Base64.DEFAULT) }
280
+ lateinit var lastResult: SendApduResult
281
+ apdusByteArray.forEachIndexed { index, apdu ->
282
+ lastResult = device.sendApduFn(apdu, false, Duration.INFINITE)
283
+ if (index == apdusByteArray.lastIndex || index % 20 == 0) {
284
+ sendEvent(reactContext, BridgeEvents.ExchangeBulkApdusEvent(ExchangeBulkProgressEvent(requestId, index)))
285
+ }
286
+ }
287
+ promise.resolve(lastResult.toWritableMap())
288
+ } catch (e: Exception) {
289
+ promise.reject(e)
290
+ }
291
+ }
292
+ }
293
+
261
294
  @ReactMethod
262
295
  fun addListener(eventName: String) {
263
296
  // Nothing to do in our case, but React Native will issue a warning if this isn't implemented
@@ -267,4 +300,9 @@ class TransportHidModule(
267
300
  fun removeListeners(count: Int) {
268
301
  // Nothing to do in our case, but React Native will issue a warning if this isn't implemented
269
302
  }
303
+
304
+ data class ExchangeBulkProgressEvent(
305
+ val requestId: Int,
306
+ val index: Int,
307
+ )
270
308
  }
@@ -4,6 +4,7 @@ import android.util.Base64
4
4
  import com.facebook.react.bridge.Arguments
5
5
  import com.facebook.react.bridge.WritableArray
6
6
  import com.facebook.react.bridge.WritableMap
7
+ import com.ledger.androidtransporthid.TransportHidModule
7
8
  import com.ledger.devicesdk.shared.api.apdu.SendApduFailureReason
8
9
  import com.ledger.devicesdk.shared.api.apdu.SendApduResult
9
10
  import com.ledger.devicesdk.shared.api.device.LedgerDevice
@@ -116,6 +117,13 @@ internal fun TransportEvent.DeviceConnectionLost.toWritableMap(): WritableMap =
116
117
  putString("id", id)
117
118
  }
118
119
 
120
+ internal fun TransportHidModule.ExchangeBulkProgressEvent.toWritableMap(): WritableMap =
121
+ Arguments.createMap().apply {
122
+ putInt("requestId", requestId)
123
+ putInt("index", index)
124
+ }
125
+
126
+
119
127
  /* lists */
120
128
 
121
129
  fun List<DiscoveryDevice>.toWritableArray(): WritableArray =
@@ -1,2 +1,2 @@
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})},N=(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 A=i=>N(v({},"__esModule",{value:!0}),i);var L={};S(L,{DefaultNativeModuleWrapper:()=>R});module.exports=A(L);var c=require("react-native"),d=require("rxjs"),l=require("../helpers/base64Utils"),r=require("./mapper"),a=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(a.DISCOVERED_DEVICES_EVENT,t=>{e.next(t.map(s=>(0,r.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(s,this._deviceModelDataSource)).filter(s=>s!==null))});return()=>{n.remove()}})}subscribeToDeviceDisconnectedEvents(){return new d.Observable(e=>{const n=new c.NativeEventEmitter(this._nativeModule).addListener(a.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(a.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 s=performance.now(),u=(0,l.uint8ArrayToBase64)(o),p=performance.now();console.log("PERF: sendApdu call to nativeModule at",p);const D=await this._nativeModule.sendApdu(e,u,n,t),m=performance.now();console.log("PERF: sendApdu result from nativeModule at",m);const E=(0,r.mapNativeSendApduResultToSendApduResult)(D),_=performance.now();return console.log("PERF: TS sendApdu total",_-s,"ms"),console.log("PERF: sendApdu END at ",Date.now()),E}}0&&(module.exports={DefaultNativeModuleWrapper});
1
+ "use strict";var u=Object.defineProperty;var p=Object.getOwnPropertyDescriptor;var D=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var E=(a,e)=>{for(var n in e)u(a,n,{get:e[n],enumerable:!0})},y=(a,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of D(e))!m.call(a,t)&&t!==n&&u(a,t,{get:()=>e[t],enumerable:!(r=p(e,t))||r.enumerable});return a};var M=a=>y(u({},"__esModule",{value:!0}),a);var S={};E(S,{DefaultNativeModuleWrapper:()=>T});module.exports=M(S);var c=require("react-native"),d=require("rxjs"),l=require("../helpers/base64Utils"),o=require("./mapper"),s=require("./types");class T{_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 r=new c.NativeEventEmitter(this._nativeModule).addListener(s.DISCOVERED_DEVICES_EVENT,t=>{e.next(t.map(i=>(0,o.mapNativeDiscoveryDeviceToTransportDiscoveredDevice)(i,this._deviceModelDataSource)).filter(i=>i!==null))});return()=>{r.remove()}})}subscribeToDeviceDisconnectedEvents(){return new d.Observable(e=>{const r=new c.NativeEventEmitter(this._nativeModule).addListener(s.DEVICE_DISCONNECTED_EVENT,t=>{e.next((0,o.mapNativeDeviceConnectionLostToDeviceDisconnected)(t))});return()=>{r.remove()}})}subscribeToTransportLogs(){return new d.Observable(e=>{const r=new c.NativeEventEmitter(this._nativeModule).addListener(s.TRANSPORT_LOG_EVENT,t=>{e.next((0,o.mapNativeTransportLogToLog)(t))});return()=>{r.remove()}})}subscribeToExchangeBulkApdusEvents(e){return new d.Observable(n=>{const t=new c.NativeEventEmitter(this._nativeModule).addListener("ExchangeBulkApdus",i=>{i.requestId===e&&n.next(i)});return()=>{t.remove()}})}async connectDevice(e){const n=await this._nativeModule.connectDevice(e);return(0,o.mapNativeConnectionResultToConnectionResult)(n,this._deviceModelDataSource)}async disconnectDevice(e){return this._nativeModule.disconnectDevice(e)}async sendApdu(e,n,r,t){const i=(0,l.uint8ArrayToBase64)(n),v=await this._nativeModule.sendApdu(e,i,r,t);return(0,o.mapNativeSendApduResultToSendApduResult)(v)}async exchangeBulkApdus(e,n,r){const t=n.map(v=>(0,l.uint8ArrayToBase64)(v)),i=await this._nativeModule.exchangeBulkApdus(e,t,r);return(0,o.mapNativeSendApduResultToSendApduResult)(i)}}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 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 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: 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,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,QAAQ,IAAI,2CAA2C,EACvD,QAAQ,IAAI,2BAA4B,KAAK,IAAI,CAAC,EAClD,MAAMC,EAAK,YAAY,IAAI,EACrBC,KAAiB,sBAAmBJ,CAAI,EACxCK,EAAK,YAAY,IAAI,EAC3B,QAAQ,IAAI,yCAA0CA,CAAE,EACxD,MAAMC,EAAkB,MAAM,KAAK,cAAc,SAC/CP,EACAK,EACAH,EACAC,CACF,EACMK,EAAK,YAAY,IAAI,EAC3B,QAAQ,IAAI,6CAA8CA,CAAE,EAC5D,MAAMC,KAAS,2CAAwCF,CAAe,EAChEG,EAAK,YAAY,IAAI,EAC3B,eAAQ,IAAI,0BAA2BA,EAAKN,EAAI,IAAI,EACpD,QAAQ,IAAI,2BAA4B,KAAK,IAAI,CAAC,EAC3CK,CACT,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", "t0", "serializedApdu", "t1", "nSendApduResult", "t2", "result", "t3"]
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 ExchangeBulkApdusEventPayload,\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 subscribeToExchangeBulkApdusEvents(\n requestId: number,\n ): Observable<ExchangeBulkApdusEventPayload> {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n \"ExchangeBulkApdus\",\n (event: ExchangeBulkApdusEventPayload) => {\n if (event.requestId === requestId) {\n subscriber.next(event);\n }\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 serializedApdu = uint8ArrayToBase64(apdu);\n const nSendApduResult = await this._nativeModule.sendApdu(\n sessionId,\n serializedApdu,\n triggersDisconnection,\n abortTimeout,\n );\n const result = mapNativeSendApduResultToSendApduResult(nSendApduResult);\n return result;\n }\n\n async exchangeBulkApdus(\n sessionId: string,\n apdus: Uint8Array[],\n requestId: number,\n ): Promise<SendApduResult> {\n const serializedApdus = apdus.map((apdu) => uint8ArrayToBase64(apdu));\n const nSendApduResult = await this._nativeModule.exchangeBulkApdus(\n sessionId,\n serializedApdus,\n requestId,\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,EAQO,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,mCACEK,EAC2C,CAC3C,OAAO,IAAI,aAAYN,GAAe,CAEpC,MAAMC,EADe,IAAI,qBAAmB,KAAK,aAAa,EAC3B,YACjC,oBACCM,GAAyC,CACpCA,EAAM,YAAcD,GACtBN,EAAW,KAAKO,CAAK,CAEzB,CACF,EAEA,MAAO,IAAM,CACXN,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,MAAM,cAAcO,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,KAAiB,sBAAmBH,CAAI,EACxCI,EAAkB,MAAM,KAAK,cAAc,SAC/CL,EACAI,EACAF,EACAC,CACF,EAEA,SADe,2CAAwCE,CAAe,CAExE,CAEA,MAAM,kBACJL,EACAM,EACAV,EACyB,CACzB,MAAMW,EAAkBD,EAAM,IAAKL,MAAS,sBAAmBA,CAAI,CAAC,EAC9DI,EAAkB,MAAM,KAAK,cAAc,kBAC/CL,EACAO,EACAX,CACF,EACA,SAAO,2CAAwCS,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", "requestId", "event", "uid", "nConnectionResult", "sessionId", "apdu", "triggersDisconnection", "abortTimeout", "serializedApdu", "nSendApduResult", "apdus", "serializedApdus"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var m=(r,e)=>{for(var o in e)s(r,o,{get:e[o],enumerable:!0})},d=(r,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of c(e))!p.call(r,t)&&t!==o&&s(r,t,{get:()=>e[t],enumerable:!(i=a(e,t))||i.enumerable});return r};var v=r=>d(s({},"__esModule",{value:!0}),r);var u={};m(u,{StubNativeModuleWrapper:()=>l});module.exports=v(u);var n=require("rxjs");class l{startScan(){return Promise.resolve()}stopScan(){return Promise.resolve()}subscribeToDiscoveredDevicesEvents(){return(0,n.from)([])}subscribeToTransportLogs(){return(0,n.from)([])}connectDevice(){throw new Error("Method not implemented.")}disconnectDevice(){throw new Error("Method not implemented.")}sendApdu(){throw new Error("Method not implemented.")}subscribeToDeviceDisconnectedEvents(){return(0,n.from)([])}}0&&(module.exports={StubNativeModuleWrapper});
1
+ "use strict";var s=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var p=(r,e)=>{for(var o in e)s(r,o,{get:e[o],enumerable:!0})},m=(r,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of c(e))!d.call(r,t)&&t!==o&&s(r,t,{get:()=>e[t],enumerable:!(i=a(e,t))||i.enumerable});return r};var u=r=>m(s({},"__esModule",{value:!0}),r);var v={};p(v,{StubNativeModuleWrapper:()=>l});module.exports=u(v);var n=require("rxjs");class l{startScan(){return Promise.resolve()}stopScan(){return Promise.resolve()}subscribeToDiscoveredDevicesEvents(){return(0,n.from)([])}subscribeToTransportLogs(){return(0,n.from)([])}connectDevice(){throw new Error("Method not implemented.")}disconnectDevice(){throw new Error("Method not implemented.")}sendApdu(){throw new Error("Method not implemented.")}subscribeToDeviceDisconnectedEvents(){return(0,n.from)([])}subscribeToExchangeBulkApdusEvents(){return(0,n.from)([])}exchangeBulkApdus(){throw new Error("Method not implemented.")}}0&&(module.exports={StubNativeModuleWrapper});
2
2
  //# sourceMappingURL=StubNativeModuleWrapper.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/bridge/StubNativeModuleWrapper.ts"],
4
- "sourcesContent": ["import type {\n LogParams,\n SendApduResult,\n TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { type NativeModuleWrapper } from \"@api/transport/NativeModuleWrapper\";\nimport type {\n InternalConnectionResult,\n InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nexport class StubNativeModuleWrapper implements NativeModuleWrapper {\n startScan() {\n return Promise.resolve();\n }\n\n stopScan() {\n return Promise.resolve();\n }\n\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n > {\n return from([]);\n }\n\n subscribeToTransportLogs(): Observable<LogParams> {\n return from([]);\n }\n\n connectDevice(): Promise<InternalConnectionResult> {\n throw new Error(\"Method not implemented.\");\n }\n\n disconnectDevice(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n sendApdu(): Promise<SendApduResult> {\n throw new Error(\"Method not implemented.\");\n }\n\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected> {\n return from([]);\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAsC,gBAQ/B,MAAMF,CAAuD,CAClE,WAAY,CACV,OAAO,QAAQ,QAAQ,CACzB,CAEA,UAAW,CACT,OAAO,QAAQ,QAAQ,CACzB,CAEA,oCAEE,CACA,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,0BAAkD,CAChD,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,eAAmD,CACjD,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,kBAAkC,CAChC,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,UAAoC,CAClC,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,qCAA8E,CAC5E,SAAO,QAAK,CAAC,CAAC,CAChB,CACF",
4
+ "sourcesContent": ["import type {\n LogParams,\n SendApduResult,\n TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { from, type Observable } from \"rxjs\";\n\nimport { type NativeModuleWrapper } from \"@api/transport/NativeModuleWrapper\";\nimport type {\n InternalConnectionResult,\n InternalDeviceDisconnected,\n} from \"@api/transport/types\";\n\nexport class StubNativeModuleWrapper implements NativeModuleWrapper {\n startScan() {\n return Promise.resolve();\n }\n\n stopScan() {\n return Promise.resolve();\n }\n\n subscribeToDiscoveredDevicesEvents(): Observable<\n Array<TransportDiscoveredDevice>\n > {\n return from([]);\n }\n\n subscribeToTransportLogs(): Observable<LogParams> {\n return from([]);\n }\n\n connectDevice(): Promise<InternalConnectionResult> {\n throw new Error(\"Method not implemented.\");\n }\n\n disconnectDevice(): Promise<void> {\n throw new Error(\"Method not implemented.\");\n }\n\n sendApdu(): Promise<SendApduResult> {\n throw new Error(\"Method not implemented.\");\n }\n\n subscribeToDeviceDisconnectedEvents(): Observable<InternalDeviceDisconnected> {\n return from([]);\n }\n\n subscribeToExchangeBulkApdusEvents() // requestId: number,\n : Observable<{ requestId: number; index: number }> {\n return from([]);\n }\n\n exchangeBulkApdus(): Promise<SendApduResult> {\n throw new Error(\"Method not implemented.\");\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,6BAAAE,IAAA,eAAAC,EAAAH,GAKA,IAAAI,EAAsC,gBAQ/B,MAAMF,CAAuD,CAClE,WAAY,CACV,OAAO,QAAQ,QAAQ,CACzB,CAEA,UAAW,CACT,OAAO,QAAQ,QAAQ,CACzB,CAEA,oCAEE,CACA,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,0BAAkD,CAChD,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,eAAmD,CACjD,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,kBAAkC,CAChC,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,UAAoC,CAClC,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CAEA,qCAA8E,CAC5E,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,oCACmD,CACjD,SAAO,QAAK,CAAC,CAAC,CAChB,CAEA,mBAA6C,CAC3C,MAAM,IAAI,MAAM,yBAAyB,CAC3C,CACF",
6
6
  "names": ["StubNativeModuleWrapper_exports", "__export", "StubNativeModuleWrapper", "__toCommonJS", "import_rxjs"]
7
7
  }
@@ -1,2 +1,2 @@
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});
1
+ "use strict";var n=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var s in e)n(t,s,{get:e[s],enumerable:!0})},v=(t,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of a(e))!c.call(t,i)&&i!==s&&n(t,i,{get:()=>e[i],enumerable:!(o=r(e,i))||o.enumerable});return t};var p=t=>v(n({},"__esModule",{value:!0}),t);var D={};d(D,{DEVICE_DISCONNECTED_EVENT:()=>N,DISCOVERED_DEVICES_EVENT:()=>u,EXCHANGE_BULK_APDUS_EVENT:()=>l,TRANSPORT_LOG_EVENT:()=>g});module.exports=p(D);const u="DiscoveredDevices",g="TransportLog",N="DeviceDisconnected",l="ExchangeBulkApdus";0&&(module.exports={DEVICE_DISCONNECTED_EVENT,DISCOVERED_DEVICES_EVENT,EXCHANGE_BULK_APDUS_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 | \"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
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,6BAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAL,GAsDO,MAAMG,EAA2B,oBAI3BC,EAAsB,eAItBF,EAA4B",
6
- "names": ["types_exports", "__export", "DEVICE_DISCONNECTED_EVENT", "DISCOVERED_DEVICES_EVENT", "TRANSPORT_LOG_EVENT", "__toCommonJS"]
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 * 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/** ExchangeBulkApdus */\nexport const EXCHANGE_BULK_APDUS_EVENT = \"ExchangeBulkApdus\";\nexport type ExchangeBulkApdusEventPayload = {\n requestId: number;\n index: number;\n};\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 exchangeBulkApdus: (\n sessionId: string,\n apdus: string[],\n requestId: number,\n ) => Promise<NativeSendApduResult>;\n} & NativeModule;\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,6BAAAC,EAAA,8BAAAC,EAAA,wBAAAC,IAAA,eAAAC,EAAAN,GAqDO,MAAMG,EAA2B,oBAI3BE,EAAsB,eAItBH,EAA4B,qBAI5BE,EAA4B",
6
+ "names": ["types_exports", "__export", "DEVICE_DISCONNECTED_EVENT", "DISCOVERED_DEVICES_EVENT", "EXCHANGE_BULK_APDUS_EVENT", "TRANSPORT_LOG_EVENT", "__toCommonJS"]
7
7
  }
@@ -1,2 +1,2 @@
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);
1
+ "use strict";var o=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var d=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of a(e))!c.call(s,r)&&r!==t&&o(s,r,{get:()=>e[r],enumerable:!(n=i(e,r))||n.enumerable});return s};var u=s=>d(o({},"__esModule",{value:!0}),s);var p={};module.exports=u(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(\n sessionId: string,\n apdu: Uint8Array,\n triggersDisconnection: boolean,\n abortTimeout: number,\n ): Promise<SendApduResult>;\n}\n"],
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\";\nimport { ExchangeBulkApdusEventPayload } from \"@api/bridge/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 subscribeToExchangeBulkApdusEvents(\n requestId: number,\n ): Observable<ExchangeBulkApdusEventPayload>;\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 exchangeBulkApdus(\n sessionId: string,\n apdus: Uint8Array[],\n requestId: 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 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.HidTransportSendApduUnknownError(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});
1
+ "use strict";var d=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var _=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var T=(s,r)=>{for(var t in r)d(s,t,{get:r[t],enumerable:!0})},m=(s,r,t,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of _(r))!S.call(s,e)&&e!==t&&d(s,e,{get:()=>r[e],enumerable:!(i=D(r,e))||i.enumerable});return s};var f=s=>m(d({},"__esModule",{value:!0}),s);var E={};T(E,{RNHidTransport:()=>y});module.exports=f(E);var o=require("@ledgerhq/device-management-kit"),c=require("purify-ts"),p=require("rxjs"),l=require("../helpers/getObservableOfArraysNewItems"),g=require("../transport/rnHidTransportIdentifier"),h=require("./Errors");class y{constructor(r,t,i){this._isSupported=r;this._nativeModuleWrapper=t;this._loggerService=i("RNHidTransport"),this._nativeModuleWrapper.subscribeToTransportLogs().subscribe(e=>{const[a,n,v]=e,u={[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];u(n,v)})}_loggerService;getIdentifier(){return g.TRANSPORT_IDENTIFIER}isSupported(){return this._isSupported}startDiscovering(){return new p.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 p.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)})}})}exchangeBulkRequestId=0;exchangeBulkApdus(r,t){return new p.Observable(i=>{const e=this.exchangeBulkRequestId;this.exchangeBulkRequestId++;const a=this._nativeModuleWrapper.subscribeToExchangeBulkApdusEvents(e).subscribe(n=>{n.requestId===e&&i.next({currentIndex:n.index})});return this._nativeModuleWrapper.exchangeBulkApdus(r,t,e).then(n=>{i.next({result:n}),i.complete()}).catch(n=>{i.error(n)}),()=>{a.unsubscribe()}})}connect(r){return this._nativeModuleWrapper.connectDevice(r.deviceId).then(t=>t.map(({sessionId:i,transportDeviceModel:e})=>{const a=this._nativeModuleWrapper.subscribeToDeviceDisconnectedEvents().subscribe(n=>{n.sessionId===i&&(r.onDisconnect(i),a.unsubscribe())});return new o.TransportConnectedDevice({id:i,deviceModel:e,sendApdu:async(n,v=!1,u=-1)=>this._nativeModuleWrapper.sendApdu(i,n,v,u).catch(b=>(0,c.Left)(new h.HidTransportSendApduUnknownError(b))),exchangeBulkApdus:async n=>this.exchangeBulkApdus(i,n),transport:this.getIdentifier(),type:"USB"})})).catch(t=>(0,c.Left)(new o.OpeningConnectionError(t)))}disconnect(r){return this._nativeModuleWrapper.disconnectDevice(r.connectedDevice.id).then(()=>(0,c.Right)(void 0)).catch(t=>(0,c.Left)(new o.DisconnectError(t)))}}0&&(module.exports={RNHidTransport});
2
2
  //# sourceMappingURL=RNHidTransport.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/transport/RNHidTransport.ts"],
4
- "sourcesContent": ["import {\n type ConnectError,\n type DeviceId,\n DisconnectError,\n type DisconnectHandler,\n type DmkError,\n type LoggerPublisherService,\n LogLevel,\n OpeningConnectionError,\n type Transport,\n TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportIdentifier,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { getObservableOfArraysNewItems } from \"@api/helpers/getObservableOfArraysNewItems\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\n\nimport { HidTransportSendApduUnknownError } from \"./Errors\";\nimport { type NativeModuleWrapper } from \"./NativeModuleWrapper\";\n\nexport class RNHidTransport implements Transport {\n private _loggerService: LoggerPublisherService;\n\n constructor(\n private readonly _isSupported: boolean,\n private readonly _nativeModuleWrapper: NativeModuleWrapper,\n _loggerServiceFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._loggerService = _loggerServiceFactory(\"RNHidTransport\");\n this._nativeModuleWrapper.subscribeToTransportLogs().subscribe((log) => {\n const [logLevel, message, options] = log;\n const logMethod = {\n [LogLevel.Fatal]: this._loggerService.error.bind(this._loggerService),\n [LogLevel.Error]: this._loggerService.error.bind(this._loggerService),\n [LogLevel.Warning]: this._loggerService.warn.bind(this._loggerService),\n [LogLevel.Info]: this._loggerService.info.bind(this._loggerService),\n [LogLevel.Debug]: this._loggerService.debug.bind(this._loggerService),\n }[logLevel];\n logMethod(message, options);\n });\n }\n\n getIdentifier(): TransportIdentifier {\n return TRANSPORT_IDENTIFIER;\n }\n\n isSupported(): boolean {\n return this._isSupported;\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n const observable = new Observable<TransportDiscoveredDevice>(\n (subscriber) => {\n const subscription = getObservableOfArraysNewItems(\n this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),\n (device) => device.id,\n ).subscribe(subscriber);\n\n this._nativeModuleWrapper.startScan().catch((error) => {\n subscriber.error(error);\n this._loggerService.error(\"startDiscovering error\", error);\n });\n return () => subscription.unsubscribe();\n },\n );\n return observable;\n }\n\n stopDiscovering(): void {\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n /**\n * NB: here we need to define the unsubscribe logic as there is no\n * \"stopListeningToKnownDevices\" method.\n * That's why we create a new observable rather than returning the one\n * returned by subscribeToDiscoveredDevicesEvents.\n */\n const observable = new Observable<TransportDiscoveredDevice[]>(\n (subscriber) => {\n const subscription = this._nativeModuleWrapper\n .subscribeToDiscoveredDevicesEvents()\n .subscribe((devices) => {\n subscriber.next(devices);\n });\n this._nativeModuleWrapper.startScan().catch((error) => {\n this._loggerService.error(\"startDiscovering error\", error);\n subscriber.error(error);\n });\n return () => {\n subscription.unsubscribe();\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n };\n },\n );\n return observable;\n }\n\n connect(_params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n return this._nativeModuleWrapper\n .connectDevice(_params.deviceId)\n .then((result) => {\n return result.map(\n ({ sessionId, transportDeviceModel: deviceModel }) => {\n const sub = this._nativeModuleWrapper\n .subscribeToDeviceDisconnectedEvents()\n .subscribe((device) => {\n if (device.sessionId === sessionId) {\n _params.onDisconnect(sessionId);\n sub.unsubscribe();\n }\n });\n\n return new TransportConnectedDevice({\n id: sessionId,\n deviceModel,\n sendApdu: async (\n apdu,\n triggersDisconnection = false,\n abortTimeout = -1,\n ) => {\n return this._nativeModuleWrapper\n .sendApdu(\n sessionId,\n apdu,\n triggersDisconnection,\n abortTimeout,\n )\n .catch((e) => Left(new HidTransportSendApduUnknownError(e)));\n },\n transport: this.getIdentifier(),\n type: \"USB\",\n });\n },\n );\n })\n .catch((error) => {\n return Left(new OpeningConnectionError(error));\n });\n }\n\n disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n return this._nativeModuleWrapper\n .disconnectDevice(_params.connectedDevice.id)\n .then(() => Right(undefined))\n .catch((error) => {\n return Left(new DisconnectError(error));\n });\n }\n}\n"],
5
- "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAaO,2CACPC,EAAyC,qBACzCC,EAA2B,gBAE3BC,EAA8C,sDAC9CC,EAAqC,mDAErCC,EAAiD,oBAG1C,MAAMP,CAAoC,CAG/C,YACmBQ,EACAC,EACjBC,EACA,CAHiB,kBAAAF,EACA,0BAAAC,EAGjB,KAAK,eAAiBC,EAAsB,gBAAgB,EAC5D,KAAK,qBAAqB,yBAAyB,EAAE,UAAWC,GAAQ,CACtE,KAAM,CAACC,EAAUC,EAASC,CAAO,EAAIH,EAC/BI,EAAY,CAChB,CAAC,WAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,EACpE,CAAC,WAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,EACpE,CAAC,WAAS,OAAO,EAAG,KAAK,eAAe,KAAK,KAAK,KAAK,cAAc,EACrE,CAAC,WAAS,IAAI,EAAG,KAAK,eAAe,KAAK,KAAK,KAAK,cAAc,EAClE,CAAC,WAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,CACtE,EAAEH,CAAQ,EACVG,EAAUF,EAASC,CAAO,CAC5B,CAAC,CACH,CAnBQ,eAqBR,eAAqC,CACnC,OAAO,sBACT,CAEA,aAAuB,CACrB,OAAO,KAAK,YACd,CAEA,kBAA0D,CAexD,OAdmB,IAAI,aACpBE,GAAe,CACd,MAAMC,KAAe,iCACnB,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I,mCAAiCA,CAAC,CAAC,CAAC,EAE/D,UAAW,KAAK,cAAc,EAC9B,KAAM,KACR,CAAC,CACH,CACF,CACD,EACA,MAAOV,MACC,QAAK,IAAI,yBAAuBA,CAAK,CAAC,CAC9C,CACL,CAEA,WAAWE,EAEyB,CAClC,OAAO,KAAK,qBACT,iBAAiBA,EAAQ,gBAAgB,EAAE,EAC3C,KAAK,OAAM,SAAM,MAAS,CAAC,EAC3B,MAAOF,MACC,QAAK,IAAI,kBAAgBA,CAAK,CAAC,CACvC,CACL,CACF",
6
- "names": ["RNHidTransport_exports", "__export", "RNHidTransport", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_rxjs", "import_getObservableOfArraysNewItems", "import_rnHidTransportIdentifier", "import_Errors", "_isSupported", "_nativeModuleWrapper", "_loggerServiceFactory", "log", "logLevel", "message", "options", "logMethod", "subscriber", "subscription", "device", "error", "devices", "_params", "result", "sessionId", "deviceModel", "sub", "apdu", "triggersDisconnection", "abortTimeout", "e"]
4
+ "sourcesContent": ["import {\n type ConnectError,\n type DeviceId,\n DisconnectError,\n type DisconnectHandler,\n type DmkError,\n type LoggerPublisherService,\n LogLevel,\n OpeningConnectionError,\n type Transport,\n TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportIdentifier,\n type SendApduResult,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, Left, Right } from \"purify-ts\";\nimport { Observable } from \"rxjs\";\n\nimport { getObservableOfArraysNewItems } from \"@api/helpers/getObservableOfArraysNewItems\";\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\n\nimport { HidTransportSendApduUnknownError } from \"./Errors\";\nimport { type NativeModuleWrapper } from \"./NativeModuleWrapper\";\n\nexport class RNHidTransport implements Transport {\n private _loggerService: LoggerPublisherService;\n\n constructor(\n private readonly _isSupported: boolean,\n private readonly _nativeModuleWrapper: NativeModuleWrapper,\n _loggerServiceFactory: (tag: string) => LoggerPublisherService,\n ) {\n this._loggerService = _loggerServiceFactory(\"RNHidTransport\");\n this._nativeModuleWrapper.subscribeToTransportLogs().subscribe((log) => {\n const [logLevel, message, options] = log;\n const logMethod = {\n [LogLevel.Fatal]: this._loggerService.error.bind(this._loggerService),\n [LogLevel.Error]: this._loggerService.error.bind(this._loggerService),\n [LogLevel.Warning]: this._loggerService.warn.bind(this._loggerService),\n [LogLevel.Info]: this._loggerService.info.bind(this._loggerService),\n [LogLevel.Debug]: this._loggerService.debug.bind(this._loggerService),\n }[logLevel];\n logMethod(message, options);\n });\n }\n\n getIdentifier(): TransportIdentifier {\n return TRANSPORT_IDENTIFIER;\n }\n\n isSupported(): boolean {\n return this._isSupported;\n }\n\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n const observable = new Observable<TransportDiscoveredDevice>(\n (subscriber) => {\n const subscription = getObservableOfArraysNewItems(\n this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),\n (device) => device.id,\n ).subscribe(subscriber);\n\n this._nativeModuleWrapper.startScan().catch((error) => {\n subscriber.error(error);\n this._loggerService.error(\"startDiscovering error\", error);\n });\n return () => subscription.unsubscribe();\n },\n );\n return observable;\n }\n\n stopDiscovering(): void {\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n /**\n * NB: here we need to define the unsubscribe logic as there is no\n * \"stopListeningToKnownDevices\" method.\n * That's why we create a new observable rather than returning the one\n * returned by subscribeToDiscoveredDevicesEvents.\n */\n const observable = new Observable<TransportDiscoveredDevice[]>(\n (subscriber) => {\n const subscription = this._nativeModuleWrapper\n .subscribeToDiscoveredDevicesEvents()\n .subscribe((devices) => {\n subscriber.next(devices);\n });\n this._nativeModuleWrapper.startScan().catch((error) => {\n this._loggerService.error(\"startDiscovering error\", error);\n subscriber.error(error);\n });\n return () => {\n subscription.unsubscribe();\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n };\n },\n );\n return observable;\n }\n\n private exchangeBulkRequestId = 0;\n\n private exchangeBulkApdus(\n sessionId: string,\n apdus: Uint8Array[],\n ): Observable<{ currentIndex: number } | { result: SendApduResult }> {\n return new Observable((subscriber) => {\n const requestId = this.exchangeBulkRequestId;\n this.exchangeBulkRequestId++;\n\n const subscription = this._nativeModuleWrapper\n .subscribeToExchangeBulkApdusEvents(requestId)\n .subscribe((event) => {\n if (event.requestId === requestId) {\n subscriber.next({ currentIndex: event.index });\n }\n });\n\n this._nativeModuleWrapper\n .exchangeBulkApdus(sessionId, apdus, requestId)\n .then((result) => {\n subscriber.next({ result });\n subscriber.complete();\n })\n .catch((error) => {\n subscriber.error(error);\n });\n\n return () => {\n subscription.unsubscribe();\n };\n });\n }\n\n connect(_params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n return this._nativeModuleWrapper\n .connectDevice(_params.deviceId)\n .then((result) => {\n return result.map(\n ({ sessionId, transportDeviceModel: deviceModel }) => {\n const sub = this._nativeModuleWrapper\n .subscribeToDeviceDisconnectedEvents()\n .subscribe((device) => {\n if (device.sessionId === sessionId) {\n _params.onDisconnect(sessionId);\n sub.unsubscribe();\n }\n });\n\n return new TransportConnectedDevice({\n id: sessionId,\n deviceModel,\n sendApdu: async (\n apdu,\n triggersDisconnection = false,\n abortTimeout = -1,\n ) => {\n return this._nativeModuleWrapper\n .sendApdu(\n sessionId,\n apdu,\n triggersDisconnection,\n abortTimeout,\n )\n .catch((e) => Left(new HidTransportSendApduUnknownError(e)));\n },\n exchangeBulkApdus: async (apdus) => {\n return this.exchangeBulkApdus(sessionId, apdus);\n },\n transport: this.getIdentifier(),\n type: \"USB\",\n });\n },\n );\n })\n .catch((error) => {\n return Left(new OpeningConnectionError(error));\n });\n }\n\n disconnect(_params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n return this._nativeModuleWrapper\n .disconnectDevice(_params.connectedDevice.id)\n .then(() => Right(undefined))\n .catch((error) => {\n return Left(new DisconnectError(error));\n });\n }\n}\n"],
5
+ "mappings": "yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,oBAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAcO,2CACPC,EAAyC,qBACzCC,EAA2B,gBAE3BC,EAA8C,sDAC9CC,EAAqC,mDAErCC,EAAiD,oBAG1C,MAAMP,CAAoC,CAG/C,YACmBQ,EACAC,EACjBC,EACA,CAHiB,kBAAAF,EACA,0BAAAC,EAGjB,KAAK,eAAiBC,EAAsB,gBAAgB,EAC5D,KAAK,qBAAqB,yBAAyB,EAAE,UAAWC,GAAQ,CACtE,KAAM,CAACC,EAAUC,EAASC,CAAO,EAAIH,EAC/BI,EAAY,CAChB,CAAC,WAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,EACpE,CAAC,WAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,EACpE,CAAC,WAAS,OAAO,EAAG,KAAK,eAAe,KAAK,KAAK,KAAK,cAAc,EACrE,CAAC,WAAS,IAAI,EAAG,KAAK,eAAe,KAAK,KAAK,KAAK,cAAc,EAClE,CAAC,WAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,CACtE,EAAEH,CAAQ,EACVG,EAAUF,EAASC,CAAO,CAC5B,CAAC,CACH,CAnBQ,eAqBR,eAAqC,CACnC,OAAO,sBACT,CAEA,aAAuB,CACrB,OAAO,KAAK,YACd,CAEA,kBAA0D,CAexD,OAdmB,IAAI,aACpBE,GAAe,CACd,MAAMC,KAAe,iCACnB,KAAK,qBAAqB,mCAAmC,EAC5DC,GAAWA,EAAO,EACrB,EAAE,UAAUF,CAAU,EAEtB,YAAK,qBAAqB,UAAU,EAAE,MAAOG,GAAU,CACrDH,EAAW,MAAMG,CAAK,EACtB,KAAK,eAAe,MAAM,yBAA0BA,CAAK,C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AAW,qBAAsBM,CAAY,IAAM,CACpD,MAAMC,EAAM,KAAK,qBACd,oCAAoC,EACpC,UAAWV,GAAW,CACjBA,EAAO,YAAcG,IACvBK,EAAQ,aAAaL,CAAS,EAC9BO,EAAI,YAAY,EAEpB,CAAC,EAEH,OAAO,IAAI,2BAAyB,CAClC,GAAIP,EACJ,YAAAM,EACA,SAAU,MACRE,EACAC,EAAwB,GACxBC,EAAe,KAER,KAAK,qBACT,SACCV,EACAQ,EACAC,EACAC,CACF,EACC,MAAOC,MAAM,QAAK,IAAI,mCAAiCA,CAAC,CAAC,CAAC,EAE/D,kBAAmB,MAAOV,GACjB,KAAK,kBAAkBD,EAAWC,CAAK,EAEhD,UAAW,KAAK,cAAc,EAC9B,KAAM,KACR,CAAC,CACH,CACF,CACD,EACA,MAAOH,MACC,QAAK,IAAI,yBAAuBA,CAAK,CAAC,CAC9C,CACL,CAEA,WAAWO,EAEyB,CAClC,OAAO,KAAK,qBACT,iBAAiBA,EAAQ,gBAAgB,EAAE,EAC3C,KAAK,OAAM,SAAM,MAAS,CAAC,EAC3B,MAAOP,MACC,QAAK,IAAI,kBAAgBA,CAAK,CAAC,CACvC,CACL,CACF",
6
+ "names": ["RNHidTransport_exports", "__export", "RNHidTransport", "__toCommonJS", "import_device_management_kit", "import_purify_ts", "import_rxjs", "import_getObservableOfArraysNewItems", "import_rnHidTransportIdentifier", "import_Errors", "_isSupported", "_nativeModuleWrapper", "_loggerServiceFactory", "log", "logLevel", "message", "options", "logMethod", "subscriber", "subscription", "device", "error", "devices", "sessionId", "apdus", "requestId", "event", "result", "_params", "deviceModel", "sub", "apdu", "triggersDisconnection", "abortTimeout", "e"]
7
7
  }
@@ -1,2 +1,2 @@
1
- "use strict";var l=require("@ledgerhq/device-management-kit"),a=require("purify-ts/Either"),x=require("rxjs"),h=require("../transport/rnHidTransportIdentifier"),E=require("./Errors"),s=require("./RNHidTransport");const M=new l.StaticDeviceModelDataSource,y=(p,D)=>({id:p,transport:h.TRANSPORT_IDENTIFIER,name:D,deviceModel:M.getDeviceModel({id:D})}),v=y("1",l.DeviceModelId.NANO_S),g=y("2",l.DeviceModelId.NANO_X),T=y("3",l.DeviceModelId.NANO_S);describe("RNHidTransport",()=>{let p,D,R,n;const S={error:vi.fn(),warn:vi.fn(),info:vi.fn(),debug:vi.fn(),subscribers:[]},c=vi.fn(()=>S),f=vi.fn(),w=vi.fn(),u=vi.fn(),k=vi.fn(),m=vi.fn();beforeEach(()=>{p=new x.Subject,D=new x.Subject,R=new x.Subject,vi.clearAllMocks(),f.mockResolvedValue(void 0),w.mockResolvedValue(void 0),u.mockResolvedValue(void 0),k.mockResolvedValue(void 0),m.mockResolvedValue(void 0),n={startScan:f,stopScan:w,subscribeToDiscoveredDevicesEvents:vi.fn(()=>p.asObservable()),subscribeToDeviceDisconnectedEvents:vi.fn(()=>D.asObservable()),subscribeToTransportLogs:vi.fn(()=>R.asObservable()),connectDevice:u,disconnectDevice:k,sendApdu:m}}),test("getIdentifier returns TRANSPORT_IDENTIFIER",()=>{const t=new s.RNHidTransport(!0,n,c);expect(t.getIdentifier()).toBe(h.TRANSPORT_IDENTIFIER)}),describe("isSupported returns the provided support flag",()=>{test("supported",()=>{const t=new s.RNHidTransport(!0,n,c);expect(t.isSupported()).toBe(!0)}),test("not supported",()=>{const t=new s.RNHidTransport(!1,n,c);expect(t.isSupported()).toBe(!1)})}),test("constructor subscribes to transport logs and calls logger methods",()=>{new s.RNHidTransport(!0,n,c);const t=[l.LogLevel.Info,"Test message",{tag:"TestTag",data:{key:"value"},timestamp:123456789}];R.next(t),expect(S.info).toHaveBeenCalledWith("Test message",{tag:"TestTag",data:{key:"value"},timestamp:123456789})}),describe("startDiscovering",()=>{it("calls startScan",()=>{new s.RNHidTransport(!0,n,c).startDiscovering().subscribe(),expect(f).toHaveBeenCalled()}),it("emits new discovered devices",()=>new Promise((t,e)=>{const r=new s.RNHidTransport(!0,n,c),o=[];r.startDiscovering().subscribe({next:i=>{if(o.push(i),o.length===3)try{expect(o).toEqual([v,g,T]),t()}catch(d){e(d)}},error:e}),p.next([v]),p.next([v,g]),p.next([v,g,T])})),it("propagates startScan error",()=>new Promise((t,e)=>{const r=new s.RNHidTransport(!0,n,c),o=new Error("scan failed");f.mockRejectedValueOnce(o),r.startDiscovering().subscribe({next:()=>{},error:i=>{try{expect(i).toBe(o),t()}catch(d){e(d)}}})}))}),describe("stopDiscovering",()=>{it("calls stopScan",async()=>{await new s.RNHidTransport(!0,n,c).stopDiscovering(),expect(n.stopScan).toHaveBeenCalled()}),it("logs error when stopScan fails",async()=>{const t=new s.RNHidTransport(!0,n,c),e=new Error("stop failed");w.mockRejectedValueOnce(e),await t.stopDiscovering(),expect(S.error).toHaveBeenCalledWith("stopDiscovering error",e)})}),describe("listenToKnownDevices",()=>{it("emits arrays of discovered devices",()=>new Promise((t,e)=>{const r=new s.RNHidTransport(!0,n,c),o=[];r.listenToAvailableDevices().subscribe({next:i=>{if(o.push(i),o.length===2)try{expect(o).toEqual([[v,g],[v,T]]),t()}catch(d){e(d)}},complete:()=>{e("should not complete")},error:e}),p.next([v,g]),p.next([v,T])})),it("propagates startScan error",()=>new Promise((t,e)=>{const r=new s.RNHidTransport(!0,n,c),o=new Error("start scan failed");f.mockRejectedValueOnce(o),r.listenToAvailableDevices().subscribe({error:i=>{try{expect(i).toBe(o),t()}catch(d){e(d)}}})})),it("calls stopScan on unsubscribe",()=>{const t=new s.RNHidTransport(!0,n,c),e=new Error("stop scan failed");w.mockRejectedValueOnce(e),t.listenToAvailableDevices().subscribe({}).unsubscribe(),expect(w).toHaveBeenCalled()})}),describe("connect",()=>{describe("connection successful",()=>{it("should return a Right(TransportConnectedDevice) on successful connection",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const o=await new s.RNHidTransport(!0,n,c).connect({deviceId:e,onDisconnect:vi.fn()});expect(o.isRight()).toBe(!0);const i=o.extract();expect(i).toBeInstanceOf(l.TransportConnectedDevice),expect(i.id).toBe(e),expect(i.deviceModel).toEqual(t),expect(i.transport).toBe(h.TRANSPORT_IDENTIFIER),expect(i.type).toBe("USB")}),test("should trigger onDisconnect when a matching disconnect event is emitted",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const r=new s.RNHidTransport(!0,n,c),o=vi.fn();await r.connect({deviceId:e,onDisconnect:o}),D.next({sessionId:e}),expect(o).toHaveBeenCalledWith(e)}),test("should handle sendApdu success (Right)",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const i=(await new s.RNHidTransport(!0,n,c).connect({deviceId:e,onDisconnect:vi.fn()})).extract();m.mockResolvedValueOnce((0,a.Right)("apduResponse"));const d=new Uint8Array([1,2,3]),b=await i.sendApdu(d,!1,0);expect(n.sendApdu).toHaveBeenCalledWith(e,d,!1,0),expect(b).toEqual((0,a.Right)("apduResponse"))}),test("should handle sendApdu failure (Left)",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const i=(await new s.RNHidTransport(!0,n,c).connect({deviceId:e,onDisconnect:vi.fn()})).extract();m.mockResolvedValueOnce((0,a.Left)("some error"));const d=new Uint8Array([1,2,3]),b=await i.sendApdu(d);expect(b).toEqual((0,a.Left)("some error"))}),test("should handle sendApdu rejection",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const i=(await new s.RNHidTransport(!0,n,c).connect({deviceId:e,onDisconnect:vi.fn()})).extract(),d=new Error("apdu failed");m.mockRejectedValueOnce(d);const b=await i.sendApdu(new Uint8Array([]));expect(b).toEqual((0,a.Left)(new E.HidTransportSendApduUnknownError(d)))})}),describe("connection failure",()=>{test("should return a Left when nativeModuleWrapper.connectDevice resolves a Left",async()=>{const t=new s.RNHidTransport(!0,n,c),e=(0,a.Left)(new l.OpeningConnectionError("connection failed"));u.mockResolvedValueOnce(e);const r=await t.connect({deviceId:"any",onDisconnect:vi.fn()});expect(r).toEqual(e)}),test("should return a Left when nativeModuleWrapper.connectDevice rejects",async()=>{const t=new Error("connection failed"),e=new s.RNHidTransport(!0,n,c);u.mockRejectedValueOnce(t);const r=await e.connect({deviceId:"any",onDisconnect:vi.fn()});expect(r).toEqual((0,a.Left)(new l.OpeningConnectionError(t)))})})}),describe("disconnect",()=>{it("returns Right on successful disconnect",async()=>{const e=await new s.RNHidTransport(!0,n,c).disconnect({connectedDevice:{id:"session789"}});expect(n.disconnectDevice).toHaveBeenCalledWith("session789"),expect(e).toEqual((0,a.Right)(void 0))}),it("returns Left on disconnect failure",async()=>{const t=new s.RNHidTransport(!0,n,c),e=new Error("disconnect failed");k.mockRejectedValueOnce(e);const r=await t.disconnect({connectedDevice:{id:"session000"}});expect(r).toEqual((0,a.Left)(new l.DisconnectError(e)))})})});
1
+ "use strict";var l=require("@ledgerhq/device-management-kit"),a=require("purify-ts/Either"),T=require("rxjs"),h=require("../transport/rnHidTransportIdentifier"),E=require("./Errors"),s=require("./RNHidTransport");const M=new l.StaticDeviceModelDataSource,y=(p,D)=>({id:p,transport:h.TRANSPORT_IDENTIFIER,name:D,deviceModel:M.getDeviceModel({id:D})}),v=y("1",l.DeviceModelId.NANO_S),g=y("2",l.DeviceModelId.NANO_X),x=y("3",l.DeviceModelId.NANO_S);describe("RNHidTransport",()=>{let p,D,R,n;const k={error:vi.fn(),warn:vi.fn(),info:vi.fn(),debug:vi.fn(),subscribers:[]},c=vi.fn(()=>k),f=vi.fn(),w=vi.fn(),u=vi.fn(),S=vi.fn(),m=vi.fn();beforeEach(()=>{p=new T.Subject,D=new T.Subject,R=new T.Subject,vi.clearAllMocks(),f.mockResolvedValue(void 0),w.mockResolvedValue(void 0),u.mockResolvedValue(void 0),S.mockResolvedValue(void 0),m.mockResolvedValue(void 0),n={startScan:f,stopScan:w,subscribeToDiscoveredDevicesEvents:vi.fn(()=>p.asObservable()),subscribeToDeviceDisconnectedEvents:vi.fn(()=>D.asObservable()),subscribeToTransportLogs:vi.fn(()=>R.asObservable()),connectDevice:u,disconnectDevice:S,sendApdu:m,exchangeBulkApdus:vi.fn(),subscribeToExchangeBulkApdusEvents:vi.fn()}}),test("getIdentifier returns TRANSPORT_IDENTIFIER",()=>{const t=new s.RNHidTransport(!0,n,c);expect(t.getIdentifier()).toBe(h.TRANSPORT_IDENTIFIER)}),describe("isSupported returns the provided support flag",()=>{test("supported",()=>{const t=new s.RNHidTransport(!0,n,c);expect(t.isSupported()).toBe(!0)}),test("not supported",()=>{const t=new s.RNHidTransport(!1,n,c);expect(t.isSupported()).toBe(!1)})}),test("constructor subscribes to transport logs and calls logger methods",()=>{new s.RNHidTransport(!0,n,c);const t=[l.LogLevel.Info,"Test message",{tag:"TestTag",data:{key:"value"},timestamp:123456789}];R.next(t),expect(k.info).toHaveBeenCalledWith("Test message",{tag:"TestTag",data:{key:"value"},timestamp:123456789})}),describe("startDiscovering",()=>{it("calls startScan",()=>{new s.RNHidTransport(!0,n,c).startDiscovering().subscribe(),expect(f).toHaveBeenCalled()}),it("emits new discovered devices",()=>new Promise((t,e)=>{const r=new s.RNHidTransport(!0,n,c),o=[];r.startDiscovering().subscribe({next:i=>{if(o.push(i),o.length===3)try{expect(o).toEqual([v,g,x]),t()}catch(d){e(d)}},error:e}),p.next([v]),p.next([v,g]),p.next([v,g,x])})),it("propagates startScan error",()=>new Promise((t,e)=>{const r=new s.RNHidTransport(!0,n,c),o=new Error("scan failed");f.mockRejectedValueOnce(o),r.startDiscovering().subscribe({next:()=>{},error:i=>{try{expect(i).toBe(o),t()}catch(d){e(d)}}})}))}),describe("stopDiscovering",()=>{it("calls stopScan",async()=>{await new s.RNHidTransport(!0,n,c).stopDiscovering(),expect(n.stopScan).toHaveBeenCalled()}),it("logs error when stopScan fails",async()=>{const t=new s.RNHidTransport(!0,n,c),e=new Error("stop failed");w.mockRejectedValueOnce(e),await t.stopDiscovering(),expect(k.error).toHaveBeenCalledWith("stopDiscovering error",e)})}),describe("listenToKnownDevices",()=>{it("emits arrays of discovered devices",()=>new Promise((t,e)=>{const r=new s.RNHidTransport(!0,n,c),o=[];r.listenToAvailableDevices().subscribe({next:i=>{if(o.push(i),o.length===2)try{expect(o).toEqual([[v,g],[v,x]]),t()}catch(d){e(d)}},complete:()=>{e("should not complete")},error:e}),p.next([v,g]),p.next([v,x])})),it("propagates startScan error",()=>new Promise((t,e)=>{const r=new s.RNHidTransport(!0,n,c),o=new Error("start scan failed");f.mockRejectedValueOnce(o),r.listenToAvailableDevices().subscribe({error:i=>{try{expect(i).toBe(o),t()}catch(d){e(d)}}})})),it("calls stopScan on unsubscribe",()=>{const t=new s.RNHidTransport(!0,n,c),e=new Error("stop scan failed");w.mockRejectedValueOnce(e),t.listenToAvailableDevices().subscribe({}).unsubscribe(),expect(w).toHaveBeenCalled()})}),describe("connect",()=>{describe("connection successful",()=>{it("should return a Right(TransportConnectedDevice) on successful connection",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const o=await new s.RNHidTransport(!0,n,c).connect({deviceId:e,onDisconnect:vi.fn()});expect(o.isRight()).toBe(!0);const i=o.extract();expect(i).toBeInstanceOf(l.TransportConnectedDevice),expect(i.id).toBe(e),expect(i.deviceModel).toEqual(t),expect(i.transport).toBe(h.TRANSPORT_IDENTIFIER),expect(i.type).toBe("USB")}),test("should trigger onDisconnect when a matching disconnect event is emitted",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const r=new s.RNHidTransport(!0,n,c),o=vi.fn();await r.connect({deviceId:e,onDisconnect:o}),D.next({sessionId:e}),expect(o).toHaveBeenCalledWith(e)}),test("should handle sendApdu success (Right)",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const i=(await new s.RNHidTransport(!0,n,c).connect({deviceId:e,onDisconnect:vi.fn()})).extract();m.mockResolvedValueOnce((0,a.Right)("apduResponse"));const d=new Uint8Array([1,2,3]),b=await i.sendApdu(d,!1,0);expect(n.sendApdu).toHaveBeenCalledWith(e,d,!1,0),expect(b).toEqual((0,a.Right)("apduResponse"))}),test("should handle sendApdu failure (Left)",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const i=(await new s.RNHidTransport(!0,n,c).connect({deviceId:e,onDisconnect:vi.fn()})).extract();m.mockResolvedValueOnce((0,a.Left)("some error"));const d=new Uint8Array([1,2,3]),b=await i.sendApdu(d);expect(b).toEqual((0,a.Left)("some error"))}),test("should handle sendApdu rejection",async()=>{const t={model:"TestModel"},e="session123";u.mockResolvedValueOnce((0,a.Right)({sessionId:e,transportDeviceModel:t}));const i=(await new s.RNHidTransport(!0,n,c).connect({deviceId:e,onDisconnect:vi.fn()})).extract(),d=new Error("apdu failed");m.mockRejectedValueOnce(d);const b=await i.sendApdu(new Uint8Array([]));expect(b).toEqual((0,a.Left)(new E.HidTransportSendApduUnknownError(d)))})}),describe("connection failure",()=>{test("should return a Left when nativeModuleWrapper.connectDevice resolves a Left",async()=>{const t=new s.RNHidTransport(!0,n,c),e=(0,a.Left)(new l.OpeningConnectionError("connection failed"));u.mockResolvedValueOnce(e);const r=await t.connect({deviceId:"any",onDisconnect:vi.fn()});expect(r).toEqual(e)}),test("should return a Left when nativeModuleWrapper.connectDevice rejects",async()=>{const t=new Error("connection failed"),e=new s.RNHidTransport(!0,n,c);u.mockRejectedValueOnce(t);const r=await e.connect({deviceId:"any",onDisconnect:vi.fn()});expect(r).toEqual((0,a.Left)(new l.OpeningConnectionError(t)))})})}),describe("disconnect",()=>{it("returns Right on successful disconnect",async()=>{const e=await new s.RNHidTransport(!0,n,c).disconnect({connectedDevice:{id:"session789"}});expect(n.disconnectDevice).toHaveBeenCalledWith("session789"),expect(e).toEqual((0,a.Right)(void 0))}),it("returns Left on disconnect failure",async()=>{const t=new s.RNHidTransport(!0,n,c),e=new Error("disconnect failed");S.mockRejectedValueOnce(e);const r=await t.disconnect({connectedDevice:{id:"session000"}});expect(r).toEqual((0,a.Left)(new l.DisconnectError(e)))})})});
2
2
  //# sourceMappingURL=RNHidTransport.test.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/api/transport/RNHidTransport.test.ts"],
4
- "sourcesContent": ["import {\n DeviceModelId,\n DisconnectError,\n type LoggerPublisherService,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n StaticDeviceModelDataSource,\n TransportConnectedDevice,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts/Either\";\nimport { Subject } from \"rxjs\";\n\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\n\nimport { HidTransportSendApduUnknownError } from \"./Errors\";\nimport { type NativeModuleWrapper } from \"./NativeModuleWrapper\";\nimport { RNHidTransport } from \"./RNHidTransport\";\nimport { type InternalDeviceDisconnected } from \"./types\";\n\nconst deviceModelDataSource = new StaticDeviceModelDataSource();\n\nconst makeMockTransportDiscoveredDevice = (\n id: string,\n deviceModelId: DeviceModelId,\n): TransportDiscoveredDevice => ({\n id,\n transport: TRANSPORT_IDENTIFIER,\n name: deviceModelId,\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: deviceModelId,\n }),\n});\n\nconst mockDiscoveredDevice1 = makeMockTransportDiscoveredDevice(\n \"1\",\n DeviceModelId.NANO_S,\n);\nconst mockDiscoveredDevice2 = makeMockTransportDiscoveredDevice(\n \"2\",\n DeviceModelId.NANO_X,\n);\nconst mockDiscoveredDevice3 = makeMockTransportDiscoveredDevice(\n \"3\",\n DeviceModelId.NANO_S,\n);\n\ndescribe(\"RNHidTransport\", () => {\n let discoveredDevicesSubject: Subject<Array<TransportDiscoveredDevice>>;\n let deviceDisconnectedSubject: Subject<InternalDeviceDisconnected>;\n let transportLogsSubject: Subject<LogParams>;\n let nativeModuleWrapper: NativeModuleWrapper;\n const fakeLogger: LoggerPublisherService = {\n error: vi.fn(),\n warn: vi.fn(),\n info: vi.fn(),\n debug: vi.fn(),\n subscribers: [],\n };\n const loggerServiceFactory = vi.fn(() => fakeLogger);\n\n const wrapperStartScan = vi.fn();\n const wrapperStopScan = vi.fn();\n const wrapperConnectDevice = vi.fn();\n const wrapperDisconnectDevice = vi.fn();\n const wrapperSendApdu = vi.fn();\n\n beforeEach(() => {\n discoveredDevicesSubject = new Subject();\n deviceDisconnectedSubject = new Subject();\n transportLogsSubject = new Subject();\n\n vi.clearAllMocks();\n\n wrapperStartScan.mockResolvedValue(undefined);\n wrapperStopScan.mockResolvedValue(undefined);\n wrapperConnectDevice.mockResolvedValue(undefined);\n wrapperDisconnectDevice.mockResolvedValue(undefined);\n wrapperSendApdu.mockResolvedValue(undefined);\n\n nativeModuleWrapper = {\n startScan: wrapperStartScan,\n stopScan: wrapperStopScan,\n subscribeToDiscoveredDevicesEvents: vi.fn(() =>\n discoveredDevicesSubject.asObservable(),\n ),\n subscribeToDeviceDisconnectedEvents: vi.fn(() =>\n deviceDisconnectedSubject.asObservable(),\n ),\n subscribeToTransportLogs: vi.fn(() =>\n transportLogsSubject.asObservable(),\n ),\n connectDevice: wrapperConnectDevice,\n disconnectDevice: wrapperDisconnectDevice,\n sendApdu: wrapperSendApdu,\n };\n });\n\n test(\"getIdentifier returns TRANSPORT_IDENTIFIER\", () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n // then\n expect(transport.getIdentifier()).toBe(TRANSPORT_IDENTIFIER);\n });\n\n describe(\"isSupported returns the provided support flag\", () => {\n test(\"supported\", () => {\n // given\n const transportTrue = new RNHidTransport(\n true, // when\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n // then\n expect(transportTrue.isSupported()).toBe(true);\n });\n\n test(\"not supported\", () => {\n // given\n const transportFalse = new RNHidTransport(\n false, // when\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n // then\n expect(transportFalse.isSupported()).toBe(false);\n });\n });\n\n test(\"constructor subscribes to transport logs and calls logger methods\", () => {\n // given\n new RNHidTransport(true, nativeModuleWrapper, loggerServiceFactory);\n\n // when\n const logEvent: LogParams = [\n LogLevel.Info,\n \"Test message\",\n {\n tag: \"TestTag\",\n data: { key: \"value\" },\n timestamp: 123456789,\n },\n ];\n transportLogsSubject.next(logEvent);\n\n // then\n expect(fakeLogger.info).toHaveBeenCalledWith(\"Test message\", {\n tag: \"TestTag\",\n data: { key: \"value\" },\n timestamp: 123456789,\n });\n });\n\n describe(\"startDiscovering\", () => {\n it(\"calls startScan\", () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n transport.startDiscovering().subscribe();\n\n // then\n expect(wrapperStartScan).toHaveBeenCalled();\n });\n\n it(\"emits new discovered devices\", () => {\n return new Promise<void>((resolve, reject) => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const discoveredDevices: TransportDiscoveredDevice[] = [];\n\n // when\n transport.startDiscovering().subscribe({\n next: (device) => {\n discoveredDevices.push(device);\n if (discoveredDevices.length === 3) {\n try {\n // then\n expect(discoveredDevices).toEqual([\n mockDiscoveredDevice1,\n mockDiscoveredDevice2,\n mockDiscoveredDevice3,\n ]);\n resolve();\n } catch (e) {\n reject(e);\n }\n }\n },\n error: reject,\n });\n // Simulate getObservableOfArraysNewItems behavior:\n // emit first array with one device then the subsequent arrays with a new device.\n discoveredDevicesSubject.next([mockDiscoveredDevice1]);\n discoveredDevicesSubject.next([\n mockDiscoveredDevice1,\n mockDiscoveredDevice2,\n ]);\n discoveredDevicesSubject.next([\n mockDiscoveredDevice1,\n mockDiscoveredDevice2,\n mockDiscoveredDevice3,\n ]);\n });\n });\n\n it(\"propagates startScan error\", () => {\n return new Promise<void>((resolve, reject) => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"scan failed\");\n wrapperStartScan.mockRejectedValueOnce(error);\n transport.startDiscovering().subscribe({\n next: () => {},\n error: (err) => {\n try {\n // then\n expect(err).toBe(error);\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n });\n });\n });\n });\n\n describe(\"stopDiscovering\", () => {\n it(\"calls stopScan\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n await transport.stopDiscovering();\n\n // then\n expect(nativeModuleWrapper.stopScan).toHaveBeenCalled();\n });\n\n it(\"logs error when stopScan fails\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"stop failed\");\n wrapperStopScan.mockRejectedValueOnce(error);\n\n // then\n await transport.stopDiscovering();\n expect(fakeLogger.error).toHaveBeenCalledWith(\n \"stopDiscovering error\",\n error,\n );\n });\n });\n\n describe(\"listenToKnownDevices\", () => {\n it(\"emits arrays of discovered devices\", () => {\n return new Promise<void>((resolve, reject) => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const observedEvents: Array<Array<TransportDiscoveredDevice>> = [];\n\n // when\n transport.listenToAvailableDevices().subscribe({\n next: (devices) => {\n observedEvents.push(devices);\n if (observedEvents.length === 2) {\n try {\n // then\n expect(observedEvents).toEqual([\n [mockDiscoveredDevice1, mockDiscoveredDevice2],\n [mockDiscoveredDevice1, mockDiscoveredDevice3],\n ]);\n resolve();\n } catch (e) {\n reject(e);\n }\n }\n },\n complete: () => {\n reject(\"should not complete\");\n },\n error: reject,\n });\n\n discoveredDevicesSubject.next([\n mockDiscoveredDevice1,\n mockDiscoveredDevice2,\n ]);\n discoveredDevicesSubject.next([\n mockDiscoveredDevice1,\n mockDiscoveredDevice3,\n ]);\n });\n });\n\n it(\"propagates startScan error\", () => {\n return new Promise<void>((resolve, reject) => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"start scan failed\");\n wrapperStartScan.mockRejectedValueOnce(error);\n transport.listenToAvailableDevices().subscribe({\n error: (err) => {\n // then\n try {\n expect(err).toBe(error);\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n });\n });\n });\n\n it(\"calls stopScan on unsubscribe\", () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"stop scan failed\");\n wrapperStopScan.mockRejectedValueOnce(error);\n const subscription = transport.listenToAvailableDevices().subscribe({});\n subscription.unsubscribe();\n\n expect(wrapperStopScan).toHaveBeenCalled();\n });\n });\n\n describe(\"connect\", () => {\n describe(\"connection successful\", () => {\n it(\"should return a Right(TransportConnectedDevice) on successful connection\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const result = await transport.connect({\n deviceId: sessionId,\n onDisconnect: vi.fn(),\n });\n\n // then\n expect(result.isRight()).toBe(true);\n const connectedDevice = result.extract() as TransportConnectedDevice;\n expect(connectedDevice).toBeInstanceOf(TransportConnectedDevice);\n expect(connectedDevice.id).toBe(sessionId);\n expect(connectedDevice.deviceModel).toEqual(fakeDeviceModel);\n expect(connectedDevice.transport).toBe(TRANSPORT_IDENTIFIER);\n expect(connectedDevice.type).toBe(\"USB\");\n });\n\n test(\"should trigger onDisconnect when a matching disconnect event is emitted\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const onDisconnect = vi.fn();\n\n // when\n await transport.connect({\n deviceId: sessionId,\n onDisconnect,\n });\n deviceDisconnectedSubject.next({ sessionId });\n\n // then\n expect(onDisconnect).toHaveBeenCalledWith(sessionId);\n });\n\n test(\"should handle sendApdu success (Right)\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const result = await transport.connect({\n deviceId: sessionId,\n onDisconnect: vi.fn(),\n });\n const connectedDevice = result.extract() as TransportConnectedDevice;\n\n // when\n wrapperSendApdu.mockResolvedValueOnce(Right(\"apduResponse\"));\n const apdu = new Uint8Array([1, 2, 3]);\n const apduResult = await connectedDevice.sendApdu(apdu, false, 0);\n\n // then\n expect(nativeModuleWrapper.sendApdu).toHaveBeenCalledWith(\n sessionId,\n apdu,\n false,\n 0,\n );\n expect(apduResult).toEqual(Right(\"apduResponse\"));\n });\n\n test(\"should handle sendApdu failure (Left)\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const result = await transport.connect({\n deviceId: sessionId,\n onDisconnect: vi.fn(),\n });\n const connectedDevice = result.extract() as TransportConnectedDevice;\n\n // when\n wrapperSendApdu.mockResolvedValueOnce(Left(\"some error\"));\n const apdu = new Uint8Array([1, 2, 3]);\n const apduResult = await connectedDevice.sendApdu(apdu);\n\n // then\n expect(apduResult).toEqual(Left(\"some error\"));\n });\n\n test(\"should handle sendApdu rejection\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const result = await transport.connect({\n deviceId: sessionId,\n onDisconnect: vi.fn(),\n });\n const connectedDevice = result.extract() as TransportConnectedDevice;\n const apduError = new Error(\"apdu failed\");\n\n // when\n wrapperSendApdu.mockRejectedValueOnce(apduError);\n const apduResult = await connectedDevice.sendApdu(new Uint8Array([]));\n\n // then\n expect(apduResult).toEqual(Left(new HidTransportSendApduUnknownError(apduError)));\n });\n });\n\n describe(\"connection failure\", () => {\n test(\"should return a Left when nativeModuleWrapper.connectDevice resolves a Left\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const errorResult = Left(\n new OpeningConnectionError(\"connection failed\"),\n );\n wrapperConnectDevice.mockResolvedValueOnce(errorResult);\n const result = await transport.connect({\n deviceId: \"any\",\n onDisconnect: vi.fn(),\n });\n\n // then\n expect(result).toEqual(errorResult);\n });\n\n test(\"should return a Left when nativeModuleWrapper.connectDevice rejects\", async () => {\n // given\n const error = new Error(\"connection failed\");\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n wrapperConnectDevice.mockRejectedValueOnce(error);\n const result = await transport.connect({\n deviceId: \"any\",\n onDisconnect: vi.fn(),\n });\n\n // then\n expect(result).toEqual(Left(new OpeningConnectionError(error)));\n });\n });\n });\n\n describe(\"disconnect\", () => {\n it(\"returns Right on successful disconnect\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const result = await transport.disconnect({\n connectedDevice: { id: \"session789\" } as TransportConnectedDevice,\n });\n\n // then\n expect(nativeModuleWrapper.disconnectDevice).toHaveBeenCalledWith(\n \"session789\",\n );\n expect(result).toEqual(Right(undefined));\n });\n\n it(\"returns Left on disconnect failure\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"disconnect failed\");\n wrapperDisconnectDevice.mockRejectedValueOnce(error);\n const result = await transport.disconnect({\n connectedDevice: { id: \"session000\" } as TransportConnectedDevice,\n });\n\n // then\n expect(result).toEqual(Left(new DisconnectError(error)));\n });\n });\n});\n"],
5
- "mappings": "aAAA,IAAAA,EAUO,2CACPC,EAA4B,4BAC5BC,EAAwB,gBAExBC,EAAqC,mDAErCC,EAAiD,oBAEjDC,EAA+B,4BAG/B,MAAMC,EAAwB,IAAI,8BAE5BC,EAAoC,CACxCC,EACAC,KAC+B,CAC/B,GAAAD,EACA,UAAW,uBACX,KAAMC,EACN,YAAaH,EAAsB,eAAe,CAChD,GAAIG,CACN,CAAC,CACH,GAEMC,EAAwBH,EAC5B,IACA,gBAAc,MAChB,EACMI,EAAwBJ,EAC5B,IACA,gBAAc,MAChB,EACMK,EAAwBL,EAC5B,IACA,gBAAc,MAChB,EAEA,SAAS,iBAAkB,IAAM,CAC/B,IAAIM,EACAC,EACAC,EACAC,EACJ,MAAMC,EAAqC,CACzC,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,EACMC,EAAuB,GAAG,GAAG,IAAMD,CAAU,EAE7CE,EAAmB,GAAG,GAAG,EACzBC,EAAkB,GAAG,GAAG,EACxBC,EAAuB,GAAG,GAAG,EAC7BC,EAA0B,GAAG,GAAG,EAChCC,EAAkB,GAAG,GAAG,EAE9B,WAAW,IAAM,CACfV,EAA2B,IAAI,UAC/BC,EAA4B,IAAI,UAChCC,EAAuB,IAAI,UAE3B,GAAG,cAAc,EAEjBI,EAAiB,kBAAkB,MAAS,EAC5CC,EAAgB,kBAAkB,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E,qBAC3C,YACF,EACA,OAAOuB,CAAM,EAAE,WAAQ,SAAM,MAAS,CAAC,CACzC,CAAC,EAED,GAAG,qCAAsC,SAAY,CAEnD,MAAMf,EAAY,IAAI,iBACpB,GACAR,EACAE,CACF,EAGMe,EAAQ,IAAI,MAAM,mBAAmB,EAC3CX,EAAwB,sBAAsBW,CAAK,EACnD,MAAMM,EAAS,MAAMf,EAAU,WAAW,CACxC,gBAAiB,CAAE,GAAI,YAAa,CACtC,CAAC,EAGD,OAAOe,CAAM,EAAE,WAAQ,QAAK,IAAI,kBAAgBN,CAAK,CAAC,CAAC,CACzD,CAAC,CACH,CAAC,CACH,CAAC",
4
+ "sourcesContent": ["import {\n DeviceModelId,\n DisconnectError,\n type LoggerPublisherService,\n LogLevel,\n type LogParams,\n OpeningConnectionError,\n StaticDeviceModelDataSource,\n TransportConnectedDevice,\n type TransportDiscoveredDevice,\n} from \"@ledgerhq/device-management-kit\";\nimport { Left, Right } from \"purify-ts/Either\";\nimport { Subject } from \"rxjs\";\n\nimport { TRANSPORT_IDENTIFIER } from \"@api/transport/rnHidTransportIdentifier\";\n\nimport { HidTransportSendApduUnknownError } from \"./Errors\";\nimport { type NativeModuleWrapper } from \"./NativeModuleWrapper\";\nimport { RNHidTransport } from \"./RNHidTransport\";\nimport { type InternalDeviceDisconnected } from \"./types\";\n\nconst deviceModelDataSource = new StaticDeviceModelDataSource();\n\nconst makeMockTransportDiscoveredDevice = (\n id: string,\n deviceModelId: DeviceModelId,\n): TransportDiscoveredDevice => ({\n id,\n transport: TRANSPORT_IDENTIFIER,\n name: deviceModelId,\n deviceModel: deviceModelDataSource.getDeviceModel({\n id: deviceModelId,\n }),\n});\n\nconst mockDiscoveredDevice1 = makeMockTransportDiscoveredDevice(\n \"1\",\n DeviceModelId.NANO_S,\n);\nconst mockDiscoveredDevice2 = makeMockTransportDiscoveredDevice(\n \"2\",\n DeviceModelId.NANO_X,\n);\nconst mockDiscoveredDevice3 = makeMockTransportDiscoveredDevice(\n \"3\",\n DeviceModelId.NANO_S,\n);\n\ndescribe(\"RNHidTransport\", () => {\n let discoveredDevicesSubject: Subject<Array<TransportDiscoveredDevice>>;\n let deviceDisconnectedSubject: Subject<InternalDeviceDisconnected>;\n let transportLogsSubject: Subject<LogParams>;\n let nativeModuleWrapper: NativeModuleWrapper;\n const fakeLogger: LoggerPublisherService = {\n error: vi.fn(),\n warn: vi.fn(),\n info: vi.fn(),\n debug: vi.fn(),\n subscribers: [],\n };\n const loggerServiceFactory = vi.fn(() => fakeLogger);\n\n const wrapperStartScan = vi.fn();\n const wrapperStopScan = vi.fn();\n const wrapperConnectDevice = vi.fn();\n const wrapperDisconnectDevice = vi.fn();\n const wrapperSendApdu = vi.fn();\n\n beforeEach(() => {\n discoveredDevicesSubject = new Subject();\n deviceDisconnectedSubject = new Subject();\n transportLogsSubject = new Subject();\n\n vi.clearAllMocks();\n\n wrapperStartScan.mockResolvedValue(undefined);\n wrapperStopScan.mockResolvedValue(undefined);\n wrapperConnectDevice.mockResolvedValue(undefined);\n wrapperDisconnectDevice.mockResolvedValue(undefined);\n wrapperSendApdu.mockResolvedValue(undefined);\n\n nativeModuleWrapper = {\n startScan: wrapperStartScan,\n stopScan: wrapperStopScan,\n subscribeToDiscoveredDevicesEvents: vi.fn(() =>\n discoveredDevicesSubject.asObservable(),\n ),\n subscribeToDeviceDisconnectedEvents: vi.fn(() =>\n deviceDisconnectedSubject.asObservable(),\n ),\n subscribeToTransportLogs: vi.fn(() =>\n transportLogsSubject.asObservable(),\n ),\n connectDevice: wrapperConnectDevice,\n disconnectDevice: wrapperDisconnectDevice,\n sendApdu: wrapperSendApdu,\n exchangeBulkApdus: vi.fn(),\n subscribeToExchangeBulkApdusEvents: vi.fn(),\n };\n });\n\n test(\"getIdentifier returns TRANSPORT_IDENTIFIER\", () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n // then\n expect(transport.getIdentifier()).toBe(TRANSPORT_IDENTIFIER);\n });\n\n describe(\"isSupported returns the provided support flag\", () => {\n test(\"supported\", () => {\n // given\n const transportTrue = new RNHidTransport(\n true, // when\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n // then\n expect(transportTrue.isSupported()).toBe(true);\n });\n\n test(\"not supported\", () => {\n // given\n const transportFalse = new RNHidTransport(\n false, // when\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n // then\n expect(transportFalse.isSupported()).toBe(false);\n });\n });\n\n test(\"constructor subscribes to transport logs and calls logger methods\", () => {\n // given\n new RNHidTransport(true, nativeModuleWrapper, loggerServiceFactory);\n\n // when\n const logEvent: LogParams = [\n LogLevel.Info,\n \"Test message\",\n {\n tag: \"TestTag\",\n data: { key: \"value\" },\n timestamp: 123456789,\n },\n ];\n transportLogsSubject.next(logEvent);\n\n // then\n expect(fakeLogger.info).toHaveBeenCalledWith(\"Test message\", {\n tag: \"TestTag\",\n data: { key: \"value\" },\n timestamp: 123456789,\n });\n });\n\n describe(\"startDiscovering\", () => {\n it(\"calls startScan\", () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n transport.startDiscovering().subscribe();\n\n // then\n expect(wrapperStartScan).toHaveBeenCalled();\n });\n\n it(\"emits new discovered devices\", () => {\n return new Promise<void>((resolve, reject) => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const discoveredDevices: TransportDiscoveredDevice[] = [];\n\n // when\n transport.startDiscovering().subscribe({\n next: (device) => {\n discoveredDevices.push(device);\n if (discoveredDevices.length === 3) {\n try {\n // then\n expect(discoveredDevices).toEqual([\n mockDiscoveredDevice1,\n mockDiscoveredDevice2,\n mockDiscoveredDevice3,\n ]);\n resolve();\n } catch (e) {\n reject(e);\n }\n }\n },\n error: reject,\n });\n // Simulate getObservableOfArraysNewItems behavior:\n // emit first array with one device then the subsequent arrays with a new device.\n discoveredDevicesSubject.next([mockDiscoveredDevice1]);\n discoveredDevicesSubject.next([\n mockDiscoveredDevice1,\n mockDiscoveredDevice2,\n ]);\n discoveredDevicesSubject.next([\n mockDiscoveredDevice1,\n mockDiscoveredDevice2,\n mockDiscoveredDevice3,\n ]);\n });\n });\n\n it(\"propagates startScan error\", () => {\n return new Promise<void>((resolve, reject) => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"scan failed\");\n wrapperStartScan.mockRejectedValueOnce(error);\n transport.startDiscovering().subscribe({\n next: () => {},\n error: (err) => {\n try {\n // then\n expect(err).toBe(error);\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n });\n });\n });\n });\n\n describe(\"stopDiscovering\", () => {\n it(\"calls stopScan\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n await transport.stopDiscovering();\n\n // then\n expect(nativeModuleWrapper.stopScan).toHaveBeenCalled();\n });\n\n it(\"logs error when stopScan fails\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"stop failed\");\n wrapperStopScan.mockRejectedValueOnce(error);\n\n // then\n await transport.stopDiscovering();\n expect(fakeLogger.error).toHaveBeenCalledWith(\n \"stopDiscovering error\",\n error,\n );\n });\n });\n\n describe(\"listenToKnownDevices\", () => {\n it(\"emits arrays of discovered devices\", () => {\n return new Promise<void>((resolve, reject) => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const observedEvents: Array<Array<TransportDiscoveredDevice>> = [];\n\n // when\n transport.listenToAvailableDevices().subscribe({\n next: (devices) => {\n observedEvents.push(devices);\n if (observedEvents.length === 2) {\n try {\n // then\n expect(observedEvents).toEqual([\n [mockDiscoveredDevice1, mockDiscoveredDevice2],\n [mockDiscoveredDevice1, mockDiscoveredDevice3],\n ]);\n resolve();\n } catch (e) {\n reject(e);\n }\n }\n },\n complete: () => {\n reject(\"should not complete\");\n },\n error: reject,\n });\n\n discoveredDevicesSubject.next([\n mockDiscoveredDevice1,\n mockDiscoveredDevice2,\n ]);\n discoveredDevicesSubject.next([\n mockDiscoveredDevice1,\n mockDiscoveredDevice3,\n ]);\n });\n });\n\n it(\"propagates startScan error\", () => {\n return new Promise<void>((resolve, reject) => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"start scan failed\");\n wrapperStartScan.mockRejectedValueOnce(error);\n transport.listenToAvailableDevices().subscribe({\n error: (err) => {\n // then\n try {\n expect(err).toBe(error);\n resolve();\n } catch (e) {\n reject(e);\n }\n },\n });\n });\n });\n\n it(\"calls stopScan on unsubscribe\", () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"stop scan failed\");\n wrapperStopScan.mockRejectedValueOnce(error);\n const subscription = transport.listenToAvailableDevices().subscribe({});\n subscription.unsubscribe();\n\n expect(wrapperStopScan).toHaveBeenCalled();\n });\n });\n\n describe(\"connect\", () => {\n describe(\"connection successful\", () => {\n it(\"should return a Right(TransportConnectedDevice) on successful connection\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const result = await transport.connect({\n deviceId: sessionId,\n onDisconnect: vi.fn(),\n });\n\n // then\n expect(result.isRight()).toBe(true);\n const connectedDevice = result.extract() as TransportConnectedDevice;\n expect(connectedDevice).toBeInstanceOf(TransportConnectedDevice);\n expect(connectedDevice.id).toBe(sessionId);\n expect(connectedDevice.deviceModel).toEqual(fakeDeviceModel);\n expect(connectedDevice.transport).toBe(TRANSPORT_IDENTIFIER);\n expect(connectedDevice.type).toBe(\"USB\");\n });\n\n test(\"should trigger onDisconnect when a matching disconnect event is emitted\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const onDisconnect = vi.fn();\n\n // when\n await transport.connect({\n deviceId: sessionId,\n onDisconnect,\n });\n deviceDisconnectedSubject.next({ sessionId });\n\n // then\n expect(onDisconnect).toHaveBeenCalledWith(sessionId);\n });\n\n test(\"should handle sendApdu success (Right)\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const result = await transport.connect({\n deviceId: sessionId,\n onDisconnect: vi.fn(),\n });\n const connectedDevice = result.extract() as TransportConnectedDevice;\n\n // when\n wrapperSendApdu.mockResolvedValueOnce(Right(\"apduResponse\"));\n const apdu = new Uint8Array([1, 2, 3]);\n const apduResult = await connectedDevice.sendApdu(apdu, false, 0);\n\n // then\n expect(nativeModuleWrapper.sendApdu).toHaveBeenCalledWith(\n sessionId,\n apdu,\n false,\n 0,\n );\n expect(apduResult).toEqual(Right(\"apduResponse\"));\n });\n\n test(\"should handle sendApdu failure (Left)\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const result = await transport.connect({\n deviceId: sessionId,\n onDisconnect: vi.fn(),\n });\n const connectedDevice = result.extract() as TransportConnectedDevice;\n\n // when\n wrapperSendApdu.mockResolvedValueOnce(Left(\"some error\"));\n const apdu = new Uint8Array([1, 2, 3]);\n const apduResult = await connectedDevice.sendApdu(apdu);\n\n // then\n expect(apduResult).toEqual(Left(\"some error\"));\n });\n\n test(\"should handle sendApdu rejection\", async () => {\n // given\n const fakeDeviceModel = { model: \"TestModel\" };\n const sessionId = \"session123\";\n wrapperConnectDevice.mockResolvedValueOnce(\n Right({ sessionId, transportDeviceModel: fakeDeviceModel }),\n );\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n const result = await transport.connect({\n deviceId: sessionId,\n onDisconnect: vi.fn(),\n });\n const connectedDevice = result.extract() as TransportConnectedDevice;\n const apduError = new Error(\"apdu failed\");\n\n // when\n wrapperSendApdu.mockRejectedValueOnce(apduError);\n const apduResult = await connectedDevice.sendApdu(new Uint8Array([]));\n\n // then\n expect(apduResult).toEqual(\n Left(new HidTransportSendApduUnknownError(apduError)),\n );\n });\n });\n\n describe(\"connection failure\", () => {\n test(\"should return a Left when nativeModuleWrapper.connectDevice resolves a Left\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const errorResult = Left(\n new OpeningConnectionError(\"connection failed\"),\n );\n wrapperConnectDevice.mockResolvedValueOnce(errorResult);\n const result = await transport.connect({\n deviceId: \"any\",\n onDisconnect: vi.fn(),\n });\n\n // then\n expect(result).toEqual(errorResult);\n });\n\n test(\"should return a Left when nativeModuleWrapper.connectDevice rejects\", async () => {\n // given\n const error = new Error(\"connection failed\");\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n wrapperConnectDevice.mockRejectedValueOnce(error);\n const result = await transport.connect({\n deviceId: \"any\",\n onDisconnect: vi.fn(),\n });\n\n // then\n expect(result).toEqual(Left(new OpeningConnectionError(error)));\n });\n });\n });\n\n describe(\"disconnect\", () => {\n it(\"returns Right on successful disconnect\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const result = await transport.disconnect({\n connectedDevice: { id: \"session789\" } as TransportConnectedDevice,\n });\n\n // then\n expect(nativeModuleWrapper.disconnectDevice).toHaveBeenCalledWith(\n \"session789\",\n );\n expect(result).toEqual(Right(undefined));\n });\n\n it(\"returns Left on disconnect failure\", async () => {\n // given\n const transport = new RNHidTransport(\n true,\n nativeModuleWrapper,\n loggerServiceFactory,\n );\n\n // when\n const error = new Error(\"disconnect failed\");\n wrapperDisconnectDevice.mockRejectedValueOnce(error);\n const result = await transport.disconnect({\n connectedDevice: { id: \"session000\" } as TransportConnectedDevice,\n });\n\n // then\n expect(result).toEqual(Left(new DisconnectError(error)));\n });\n });\n});\n"],
5
+ "mappings": "aAAA,IAAAA,EAUO,2CACPC,EAA4B,4BAC5BC,EAAwB,gBAExBC,EAAqC,mDAErCC,EAAiD,oBAEjDC,EAA+B,4BAG/B,MAAMC,EAAwB,IAAI,8BAE5BC,EAAoC,CACxCC,EACAC,KAC+B,CAC/B,GAAAD,EACA,UAAW,uBACX,KAAMC,EACN,YAAaH,EAAsB,eAAe,CAChD,GAAIG,CACN,CAAC,CACH,GAEMC,EAAwBH,EAC5B,IACA,gBAAc,MAChB,EACMI,EAAwBJ,EAC5B,IACA,gBAAc,MAChB,EACMK,EAAwBL,EAC5B,IACA,gBAAc,MAChB,EAEA,SAAS,iBAAkB,IAAM,CAC/B,IAAIM,EACAC,EACAC,EACAC,EACJ,MAAMC,EAAqC,CACzC,MAAO,GAAG,GAAG,EACb,KAAM,GAAG,GAAG,EACZ,KAAM,GAAG,GAAG,EACZ,MAAO,GAAG,GAAG,EACb,YAAa,CAAC,CAChB,EACMC,EAAuB,GAAG,GAAG,IAAMD,CAAU,EAE7CE,EAAmB,GAAG,GAAG,EACzBC,EAAkB,GAAG,GAAG,EACxBC,EAAuB,GAAG,GAAG,EAC7BC,EAA0B,GAAG,GAAG,EAChCC,EAAkB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ACH,CAAC,CACH,CAAC,EAED,SAAS,aAAc,IAAM,CAC3B,GAAG,yCAA0C,SAAY,CASvD,MAAMM,EAAS,MAPG,IAAI,iBACpB,GACAvB,EACAE,CACF,EAG+B,WAAW,CACxC,gBAAiB,CAAE,GAAI,YAAa,CACtC,CAAC,EAGD,OAAOF,EAAoB,gBAAgB,EAAE,qBAC3C,YACF,EACA,OAAOuB,CAAM,EAAE,WAAQ,SAAM,MAAS,CAAC,CACzC,CAAC,EAED,GAAG,qCAAsC,SAAY,CAEnD,MAAMf,EAAY,IAAI,iBACpB,GACAR,EACAE,CACF,EAGMe,EAAQ,IAAI,MAAM,mBAAmB,EAC3CX,EAAwB,sBAAsBW,CAAK,EACnD,MAAMM,EAAS,MAAMf,EAAU,WAAW,CACxC,gBAAiB,CAAE,GAAI,YAAa,CACtC,CAAC,EAGD,OAAOe,CAAM,EAAE,WAAQ,QAAK,IAAI,kBAAgBN,CAAK,CAAC,CAAC,CACzD,CAAC,CACH,CAAC,CACH,CAAC",
6
6
  "names": ["import_device_management_kit", "import_Either", "import_rxjs", "import_rnHidTransportIdentifier", "import_Errors", "import_RNHidTransport", "deviceModelDataSource", "makeMockTransportDiscoveredDevice", "id", "deviceModelId", "mockDiscoveredDevice1", "mockDiscoveredDevice2", "mockDiscoveredDevice3", "discoveredDevicesSubject", "deviceDisconnectedSubject", "transportLogsSubject", "nativeModuleWrapper", "fakeLogger", "loggerServiceFactory", "wrapperStartScan", "wrapperStopScan", "wrapperConnectDevice", "wrapperDisconnectDevice", "wrapperSendApdu", "transport", "transportTrue", "transportFalse", "logEvent", "resolve", "reject", "discoveredDevices", "device", "e", "error", "err", "observedEvents", "devices", "fakeDeviceModel", "sessionId", "result", "connectedDevice", "onDisconnect", "apdu", "apduResult", "apduError", "errorResult"]
7
7
  }
@@ -1,2 +1,2 @@
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 f{_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(),s=p(n),c=performance.now();console.log("PERF: sendApdu call to nativeModule at",c);const d=await this._nativeModule.sendApdu(e,s,t,o),v=performance.now();console.log("PERF: sendApdu result from nativeModule at",v);const l=_(d),u=performance.now();return console.log("PERF: TS sendApdu total",u-r,"ms"),console.log("PERF: sendApdu END at ",Date.now()),l}}export{f as DefaultNativeModuleWrapper};
1
+ import{NativeEventEmitter as i}from"react-native";import{Observable as a}from"rxjs";import{uint8ArrayToBase64 as c}from"../helpers/base64Utils";import{mapNativeConnectionResultToConnectionResult as v,mapNativeDeviceConnectionLostToDeviceDisconnected as u,mapNativeDiscoveryDeviceToTransportDiscoveredDevice as l,mapNativeSendApduResultToSendApduResult as d,mapNativeTransportLogToLog as p}from"./mapper";import{DEVICE_DISCONNECTED_EVENT as D,DISCOVERED_DEVICES_EVENT as m,TRANSPORT_LOG_EVENT as E}from"./types";class N{_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 r=new i(this._nativeModule).addListener(m,t=>{e.next(t.map(o=>l(o,this._deviceModelDataSource)).filter(o=>o!==null))});return()=>{r.remove()}})}subscribeToDeviceDisconnectedEvents(){return new a(e=>{const r=new i(this._nativeModule).addListener(D,t=>{e.next(u(t))});return()=>{r.remove()}})}subscribeToTransportLogs(){return new a(e=>{const r=new i(this._nativeModule).addListener(E,t=>{e.next(p(t))});return()=>{r.remove()}})}subscribeToExchangeBulkApdusEvents(e){return new a(n=>{const t=new i(this._nativeModule).addListener("ExchangeBulkApdus",o=>{o.requestId===e&&n.next(o)});return()=>{t.remove()}})}async connectDevice(e){const n=await this._nativeModule.connectDevice(e);return v(n,this._deviceModelDataSource)}async disconnectDevice(e){return this._nativeModule.disconnectDevice(e)}async sendApdu(e,n,r,t){const o=c(n),s=await this._nativeModule.sendApdu(e,o,r,t);return d(s)}async exchangeBulkApdus(e,n,r){const t=n.map(s=>c(s)),o=await this._nativeModule.exchangeBulkApdus(e,t,r);return d(o)}}export{N 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 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 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: 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,+CAAA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,KAAK,cAAc,iBAAiBA,CAAS,CACtD,CAEA,MAAM,SACJA,EACAC,EACAC,EACAC,EACyB,CACzB,QAAQ,IAAI,2CAA2C,EACvD,QAAQ,IAAI,2BAA4B,KAAK,IAAI,CAAC,EAClD,MAAMC,EAAK,YAAY,IAAI,EACrBC,EAAiBxB,EAAmBoB,CAAI,EACxCK,EAAK,YAAY,IAAI,EAC3B,QAAQ,IAAI,yCAA0CA,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,0BAA2BA,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"]
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 ExchangeBulkApdusEventPayload,\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 subscribeToExchangeBulkApdusEvents(\n requestId: number,\n ): Observable<ExchangeBulkApdusEventPayload> {\n return new Observable((subscriber) => {\n const eventEmitter = new NativeEventEmitter(this._nativeModule);\n const eventListener = eventEmitter.addListener(\n \"ExchangeBulkApdus\",\n (event: ExchangeBulkApdusEventPayload) => {\n if (event.requestId === requestId) {\n subscriber.next(event);\n }\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 serializedApdu = uint8ArrayToBase64(apdu);\n const nSendApduResult = await this._nativeModule.sendApdu(\n sessionId,\n serializedApdu,\n triggersDisconnection,\n abortTimeout,\n );\n const result = mapNativeSendApduResultToSendApduResult(nSendApduResult);\n return result;\n }\n\n async exchangeBulkApdus(\n sessionId: string,\n apdus: Uint8Array[],\n requestId: number,\n ): Promise<SendApduResult> {\n const serializedApdus = apdus.map((apdu) => uint8ArrayToBase64(apdu));\n const nSendApduResult = await this._nativeModule.exchangeBulkApdus(\n sessionId,\n serializedApdus,\n requestId,\n );\n return mapNativeSendApduResultToSendApduResult(nSendApduResult);\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,EAIA,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,mCACEK,EAC2C,CAC3C,OAAO,IAAIlB,EAAYY,GAAe,CAEpC,MAAMC,EADe,IAAId,EAAmB,KAAK,aAAa,EAC3B,YACjC,oBACCoB,GAAyC,CACpCA,EAAM,YAAcD,GACtBN,EAAW,KAAKO,CAAK,CAEzB,CACF,EAEA,MAAO,IAAM,CACXN,EAAc,OAAO,CACvB,CACF,CAAC,CACH,CAEA,MAAM,cAAcO,EAAgD,CAClE,MAAMC,EAAoB,MAAM,KAAK,cAAc,cAAcD,CAAG,EACpE,OAAOlB,EACLmB,EACA,KAAK,sBACP,CACF,CAEA,MAAM,iBAAiBC,EAAkC,CACvD,OAAO,KAAK,cAAc,iBAAiBA,CAAS,CACtD,CAEA,MAAM,SACJA,EACAC,EACAC,EACAC,EACyB,CACzB,MAAMC,EAAiBzB,EAAmBsB,CAAI,EACxCI,EAAkB,MAAM,KAAK,cAAc,SAC/CL,EACAI,EACAF,EACAC,CACF,EAEA,OADepB,EAAwCsB,CAAe,CAExE,CAEA,MAAM,kBACJL,EACAM,EACAV,EACyB,CACzB,MAAMW,EAAkBD,EAAM,IAAKL,GAAStB,EAAmBsB,CAAI,CAAC,EAC9DI,EAAkB,MAAM,KAAK,cAAc,kBAC/CL,EACAO,EACAX,CACF,EACA,OAAOb,EAAwCsB,CAAe,CAChE,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", "requestId", "event", "uid", "nConnectionResult", "sessionId", "apdu", "triggersDisconnection", "abortTimeout", "serializedApdu", "nSendApduResult", "apdus", "serializedApdus"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{from as e}from"rxjs";class o{startScan(){return Promise.resolve()}stopScan(){return Promise.resolve()}subscribeToDiscoveredDevicesEvents(){return e([])}subscribeToTransportLogs(){return e([])}connectDevice(){throw new Error("Method not implemented.")}disconnectDevice(){throw new Error("Method not implemented.")}sendApdu(){throw new Error("Method not implemented.")}subscribeToDeviceDisconnectedEvents(){return e([])}}export{o as StubNativeModuleWrapper};
1
+ import{from as e}from"rxjs";class n{startScan(){return Promise.resolve()}stopScan(){return Promise.resolve()}subscribeToDiscoveredDevicesEvents(){return e([])}subscribeToTransportLogs(){return e([])}connectDevice(){throw new Error("Method not implemented.")}disconnectDevice(){throw new Error("Method not implemented.")}sendApdu(){throw new Error("Method not implemented.")}subscribeToDeviceDisconnectedEvents(){return e([])}subscribeToExchangeBulkApdusEvents(){return e([])}exchangeBulkApdus(){throw new Error("Method not implemented.")}}export{n as StubNativeModuleWrapper};
2
2
  //# sourceMappingURL=StubNativeModuleWrapper.js.map