@ledgerhq/device-transport-kit-react-native-hid 0.0.0-multisig-20250926152730 → 0.0.0-no-issue-rn-hid-scan-20251022121009

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.
@@ -22,6 +22,7 @@ import com.ledger.devicesdk.shared.internal.connection.InternalConnectedDevice
22
22
  import com.ledger.devicesdk.shared.internal.connection.InternalConnectionResult
23
23
  import com.ledger.devicesdk.shared.internal.event.SdkEventDispatcher
24
24
  import com.ledger.devicesdk.shared.internal.service.logger.LoggerService
25
+ import com.ledger.devicesdk.shared.internal.service.logger.buildSimpleDebugLogInfo
25
26
  import com.ledger.devicesdk.shared.internal.transport.TransportEvent
26
27
  import kotlinx.coroutines.CoroutineScope
27
28
  import kotlinx.coroutines.Dispatchers
@@ -34,6 +35,8 @@ import kotlin.random.Random
34
35
  import kotlin.time.Duration
35
36
  import kotlin.time.Duration.Companion.milliseconds
36
37
 
38
+ private val TAG = "TransportHidModule"
39
+
37
40
  class TransportHidModule(
38
41
  private val reactContext: ReactApplicationContext,
39
42
  private val coroutineScope: CoroutineScope
@@ -137,8 +140,14 @@ class TransportHidModule(
137
140
 
138
141
  @ReactMethod
139
142
  fun startScan(promise: Promise) {
143
+ loggerService.log(
144
+ buildSimpleDebugLogInfo(TAG, "[startScan] called")
145
+ )
140
146
  discoveryCount += 1
141
147
  if (discoveryCount > 1) {
148
+ loggerService.log(
149
+ buildSimpleDebugLogInfo(TAG, "[startScan] already scanning")
150
+ )
142
151
  promise.resolve(null)
143
152
  return
144
153
  }
@@ -156,8 +165,14 @@ class TransportHidModule(
156
165
 
157
166
  @ReactMethod
158
167
  fun stopScan(promise: Promise) {
168
+ loggerService.log(
169
+ buildSimpleDebugLogInfo(TAG, "[stopScan] called")
170
+ )
159
171
  discoveryCount -= 1
160
172
  if (discoveryCount > 0) {
173
+ loggerService.log(
174
+ buildSimpleDebugLogInfo(TAG, "[stopScan] still scanning because there are active listeners")
175
+ )
161
176
  promise.resolve(null)
162
177
  return
163
178
  }
@@ -45,6 +45,8 @@ import kotlinx.coroutines.launch
45
45
  import kotlin.time.Duration
46
46
  import kotlin.time.Duration.Companion.seconds
47
47
 
48
+ private val TAG = "DefaultAndroidUsbTransport"
49
+
48
50
  internal class DefaultAndroidUsbTransport(
49
51
  private val application: Application,
50
52
  private val usbManager: UsbManager,
@@ -67,11 +69,13 @@ internal class DefaultAndroidUsbTransport(
67
69
  private var discoveryJob: Job? = null
68
70
 
69
71
  override fun startScan(): Flow<List<DiscoveryDevice>> {
72
+ loggerService.log(buildSimpleDebugLogInfo(TAG, "[startScan] called"))
70
73
  val scanStateFlow = MutableStateFlow<List<DiscoveryDevice>>(emptyList())
71
74
  discoveryJob?.cancel()
72
75
  discoveryJob =
73
76
  scope.launch {
74
77
  while (isActive) {
78
+ loggerService.log(buildSimpleDebugLogInfo(TAG, "[startScan] isActive loop"))
75
79
  val usbDevices = usbManager.deviceList.values.toList()
76
80
  val devices =
77
81
  usbDevices
@@ -82,6 +86,7 @@ internal class DefaultAndroidUsbTransport(
82
86
  }.toUsbDevices()
83
87
 
84
88
  scanStateFlow.value = devices.toScannedDevices()
89
+ loggerService.log(buildSimpleDebugLogInfo(TAG, "[startScan] devices={$devices}"))
85
90
 
86
91
  delay(scanDelay)
87
92
  }
@@ -90,6 +95,7 @@ internal class DefaultAndroidUsbTransport(
90
95
  }
91
96
 
92
97
  override fun stopScan() {
98
+ loggerService.log(buildSimpleDebugLogInfo(TAG, "[stopScan] called"))
93
99
  discoveryJob?.cancel()
94
100
  discoveryJob = null
95
101
  }
@@ -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=(n,r)=>{for(var i in r)d(n,i,{get:r[i],enumerable:!0})},m=(n,r,i,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of _(r))!S.call(n,e)&&e!==i&&d(n,e,{get:()=>r[e],enumerable:!(t=D(r,e))||t.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"),l=require("rxjs"),g=require("../helpers/getObservableOfArraysNewItems"),u=require("../transport/rnHidTransportIdentifier"),b=require("./Errors");class E{constructor(r,i,t){this._isSupported=r;this._nativeModuleWrapper=i;this._loggerService=t("RNHidTransport"),this._nativeModuleWrapper.subscribeToTransportLogs().subscribe(e=>{const[a,c,v]=e,p={[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];p(c,v)})}_loggerService;getIdentifier(){return u.TRANSPORT_IDENTIFIER}isSupported(){return this._isSupported}startDiscovering(){return new l.Observable(i=>{const t=(0,g.getObservableOfArraysNewItems)(this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),e=>e.id).subscribe(i);return this._nativeModuleWrapper.startScan().catch(e=>{i.error(e),this._loggerService.error("startDiscovering error",e)}),()=>t.unsubscribe()})}stopDiscovering(){this._loggerService.debug("[stopDiscovering] called"),this._nativeModuleWrapper.stopScan().catch(r=>{this._loggerService.error("stopDiscovering error",r)})}listenToAvailableDevices(){return this._loggerService.debug("[listenToAvailableDevices] called"),new l.Observable(i=>{const t=this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents().subscribe(e=>{this._loggerService.debug("[listenToAvailableDevices] devices discovered",{data:{devices:e}}),i.next(e)});return this._nativeModuleWrapper.startScan().catch(e=>{this._loggerService.error("startDiscovering error",e),i.error(e)}),()=>{t.unsubscribe(),this._nativeModuleWrapper.stopScan().catch(e=>{this._loggerService.error("stopDiscovering error",e)})}})}connect(r){return this._nativeModuleWrapper.connectDevice(r.deviceId).then(i=>i.map(({sessionId:t,transportDeviceModel:e})=>{const a=this._nativeModuleWrapper.subscribeToDeviceDisconnectedEvents().subscribe(c=>{c.sessionId===t&&(r.onDisconnect(t),a.unsubscribe())});return new o.TransportConnectedDevice({id:t,deviceModel:e,sendApdu:async(c,v=!1,p=-1)=>this._nativeModuleWrapper.sendApdu(t,c,v,p).catch(h=>(0,s.Left)(new b.HidTransportSendApduUnknownError(h))),transport:this.getIdentifier(),type:"USB"})})).catch(i=>(0,s.Left)(new o.OpeningConnectionError(i)))}disconnect(r){return this._nativeModuleWrapper.disconnectDevice(r.connectedDevice.id).then(()=>(0,s.Right)(void 0)).catch(i=>(0,s.Left)(new o.DisconnectError(i)))}}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,KAAK,qBAAqB,mCAAmC,EAC5DC,GAAWA,EAAO,EACrB,EAAE,UAAUF,CAAU,EAEtB,YAAK,qBAAqB,UAAU,EAAE,MAAOG,GAAU,CACrDH,EAAW,MAAMG,CAAK,EAC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AC9C,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",
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._loggerService.debug(\"[stopDiscovering] called\");\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n this._loggerService.debug(\"[listenToAvailableDevices] called\");\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 this._loggerService.debug(\n \"[listenToAvailableDevices] devices discovered\",\n { data: { devices } },\n );\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,K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,CAAE,UAAAC,EAAW,qBAAsBC,CAAY,IAAM,CACpD,MAAMC,EAAM,KAAK,qBACd,oCAAoC,EACpC,UAAWP,GAAW,CACjBA,EAAO,YAAcK,IACvBF,EAAQ,aAAaE,CAAS,EAC9BE,EAAI,YAAY,EAEpB,CAAC,EAEH,OAAO,IAAI,2BAAyB,CAClC,GAAIF,EACJ,YAAAC,EACA,SAAU,MACRE,EACAC,EAAwB,GACxBC,EAAe,KAER,KAAK,qBACT,SACCL,EACAG,EACAC,EACAC,CACF,EACC,MAAOC,MAAM,QAAK,IAAI,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
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"]
7
7
  }
@@ -1,2 +1,2 @@
1
- import{DisconnectError as g,LogLevel as n,OpeningConnectionError as l,TransportConnectedDevice as u}from"@ledgerhq/device-management-kit";import{Left as p,Right as b}from"purify-ts";import{Observable as v}from"rxjs";import{getObservableOfArraysNewItems as h}from"../helpers/getObservableOfArraysNewItems";import{TRANSPORT_IDENTIFIER as D}from"../transport/rnHidTransportIdentifier";import{HidTransportSendApduUnknownError as _}from"./Errors";class W{constructor(i,r,t){this._isSupported=i;this._nativeModuleWrapper=r;this._loggerService=t("RNHidTransport"),this._nativeModuleWrapper.subscribeToTransportLogs().subscribe(e=>{const[s,o,c]=e,a={[n.Fatal]:this._loggerService.error.bind(this._loggerService),[n.Error]:this._loggerService.error.bind(this._loggerService),[n.Warning]:this._loggerService.warn.bind(this._loggerService),[n.Info]:this._loggerService.info.bind(this._loggerService),[n.Debug]:this._loggerService.debug.bind(this._loggerService)}[s];a(o,c)})}_loggerService;getIdentifier(){return D}isSupported(){return this._isSupported}startDiscovering(){return new v(r=>{const t=h(this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),e=>e.id).subscribe(r);return this._nativeModuleWrapper.startScan().catch(e=>{r.error(e),this._loggerService.error("startDiscovering error",e)}),()=>t.unsubscribe()})}stopDiscovering(){this._nativeModuleWrapper.stopScan().catch(i=>{this._loggerService.error("stopDiscovering error",i)})}listenToAvailableDevices(){return new v(r=>{const t=this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents().subscribe(e=>{r.next(e)});return this._nativeModuleWrapper.startScan().catch(e=>{this._loggerService.error("startDiscovering error",e),r.error(e)}),()=>{t.unsubscribe(),this._nativeModuleWrapper.stopScan().catch(e=>{this._loggerService.error("stopDiscovering error",e)})}})}connect(i){return this._nativeModuleWrapper.connectDevice(i.deviceId).then(r=>r.map(({sessionId:t,transportDeviceModel:e})=>{const s=this._nativeModuleWrapper.subscribeToDeviceDisconnectedEvents().subscribe(o=>{o.sessionId===t&&(i.onDisconnect(t),s.unsubscribe())});return new u({id:t,deviceModel:e,sendApdu:async(o,c=!1,a=-1)=>this._nativeModuleWrapper.sendApdu(t,o,c,a).catch(d=>p(new _(d))),transport:this.getIdentifier(),type:"USB"})})).catch(r=>p(new l(r)))}disconnect(i){return this._nativeModuleWrapper.disconnectDevice(i.connectedDevice.id).then(()=>b(void 0)).catch(r=>p(new g(r)))}}export{W as RNHidTransport};
1
+ import{DisconnectError as l,LogLevel as n,OpeningConnectionError as g,TransportConnectedDevice as u}from"@ledgerhq/device-management-kit";import{Left as v,Right as b}from"purify-ts";import{Observable as p}from"rxjs";import{getObservableOfArraysNewItems as h}from"../helpers/getObservableOfArraysNewItems";import{TRANSPORT_IDENTIFIER as D}from"../transport/rnHidTransportIdentifier";import{HidTransportSendApduUnknownError as _}from"./Errors";class W{constructor(t,r,i){this._isSupported=t;this._nativeModuleWrapper=r;this._loggerService=i("RNHidTransport"),this._nativeModuleWrapper.subscribeToTransportLogs().subscribe(e=>{const[s,o,c]=e,a={[n.Fatal]:this._loggerService.error.bind(this._loggerService),[n.Error]:this._loggerService.error.bind(this._loggerService),[n.Warning]:this._loggerService.warn.bind(this._loggerService),[n.Info]:this._loggerService.info.bind(this._loggerService),[n.Debug]:this._loggerService.debug.bind(this._loggerService)}[s];a(o,c)})}_loggerService;getIdentifier(){return D}isSupported(){return this._isSupported}startDiscovering(){return new p(r=>{const i=h(this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents(),e=>e.id).subscribe(r);return this._nativeModuleWrapper.startScan().catch(e=>{r.error(e),this._loggerService.error("startDiscovering error",e)}),()=>i.unsubscribe()})}stopDiscovering(){this._loggerService.debug("[stopDiscovering] called"),this._nativeModuleWrapper.stopScan().catch(t=>{this._loggerService.error("stopDiscovering error",t)})}listenToAvailableDevices(){return this._loggerService.debug("[listenToAvailableDevices] called"),new p(r=>{const i=this._nativeModuleWrapper.subscribeToDiscoveredDevicesEvents().subscribe(e=>{this._loggerService.debug("[listenToAvailableDevices] devices discovered",{data:{devices:e}}),r.next(e)});return this._nativeModuleWrapper.startScan().catch(e=>{this._loggerService.error("startDiscovering error",e),r.error(e)}),()=>{i.unsubscribe(),this._nativeModuleWrapper.stopScan().catch(e=>{this._loggerService.error("stopDiscovering error",e)})}})}connect(t){return this._nativeModuleWrapper.connectDevice(t.deviceId).then(r=>r.map(({sessionId:i,transportDeviceModel:e})=>{const s=this._nativeModuleWrapper.subscribeToDeviceDisconnectedEvents().subscribe(o=>{o.sessionId===i&&(t.onDisconnect(i),s.unsubscribe())});return new u({id:i,deviceModel:e,sendApdu:async(o,c=!1,a=-1)=>this._nativeModuleWrapper.sendApdu(i,o,c,a).catch(d=>v(new _(d))),transport:this.getIdentifier(),type:"USB"})})).catch(r=>v(new g(r)))}disconnect(t){return this._nativeModuleWrapper.disconnectDevice(t.connectedDevice.id).then(()=>b(void 0)).catch(r=>v(new l(r)))}}export{W as 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": "AAAA,OAGE,mBAAAA,EAIA,YAAAC,EACA,0BAAAC,EAEA,4BAAAC,MAGK,kCACP,OAAsB,QAAAC,EAAM,SAAAC,MAAa,YACzC,OAAS,cAAAC,MAAkB,OAE3B,OAAS,iCAAAC,MAAqC,6CAC9C,OAAS,wBAAAC,MAA4B,0CAErC,OAAS,oCAAAC,MAAwC,WAG1C,MAAMC,CAAoC,CAG/C,YACmBC,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,CAACjB,EAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,EACpE,CAACA,EAAS,KAAK,EAAG,KAAK,eAAe,MAAM,KAAK,KAAK,cAAc,EACpE,CAACA,EAAS,OAAO,EAAG,KAAK,eAAe,KAA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,EAAO,IACZ,CAAC,CAAE,UAAAC,EAAW,qBAAsBC,CAAY,IAAM,CACpD,MAAMC,EAAM,KAAK,qBACd,oCAAoC,EACpC,UAAWP,GAAW,CACjBA,EAAO,YAAcK,IACvBF,EAAQ,aAAaE,CAAS,EAC9BE,EAAI,YAAY,EAEpB,CAAC,EAEH,OAAO,IAAIzB,EAAyB,CAClC,GAAIuB,EACJ,YAAAC,EACA,SAAU,MACRE,EACAC,EAAwB,GACxBC,EAAe,KAER,KAAK,qBACT,SACCL,EACAG,EACAC,EACAC,CACF,EACC,MAAOC,GAAM5B,EAAK,IAAIK,EAAiCuB,CAAC,CAAC,CAAC,EAE/D,UAAW,KAAK,cAAc,EAC9B,KAAM,KACR,CAAC,CACH,CACF,CACD,EACA,MAAOV,GACClB,EAAK,IAAIF,EAAuBoB,CAAK,CAAC,CAC9C,CACL,CAEA,WAAWE,EAEyB,CAClC,OAAO,KAAK,qBACT,iBAAiBA,EAAQ,gBAAgB,EAAE,EAC3C,KAAK,IAAMnB,EAAM,MAAS,CAAC,EAC3B,MAAOiB,GACClB,EAAK,IAAIJ,EAAgBsB,CAAK,CAAC,CACvC,CACL,CACF",
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._loggerService.debug(\"[stopDiscovering] called\");\n this._nativeModuleWrapper.stopScan().catch((error) => {\n this._loggerService.error(\"stopDiscovering error\", error);\n });\n }\n\n listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]> {\n this._loggerService.debug(\"[listenToAvailableDevices] called\");\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 this._loggerService.debug(\n \"[listenToAvailableDevices] devices discovered\",\n { data: { devices } },\n );\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": "AAAA,OAGE,mBAAAA,EAIA,YAAAC,EACA,0BAAAC,EAEA,4BAAAC,MAGK,kCACP,OAAsB,QAAAC,EAAM,SAAAC,MAAa,YACzC,OAAS,cAAAC,MAAkB,OAE3B,OAAS,iCAAAC,MAAqC,6CAC9C,OAAS,wBAAAC,MAA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OiB,GACClB,EAAK,IAAIJ,EAAgBsB,CAAK,CAAC,CACvC,CACL,CACF",
6
6
  "names": ["DisconnectError", "LogLevel", "OpeningConnectionError", "TransportConnectedDevice", "Left", "Right", "Observable", "getObservableOfArraysNewItems", "TRANSPORT_IDENTIFIER", "HidTransportSendApduUnknownError", "RNHidTransport", "_isSupported", "_nativeModuleWrapper", "_loggerServiceFactory", "log", "logLevel", "message", "options", "logMethod", "subscriber", "subscription", "device", "error", "devices", "_params", "result", "sessionId", "deviceModel", "sub", "apdu", "triggersDisconnection", "abortTimeout", "e"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RNHidTransport.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/RNHidTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,QAAQ,EAEb,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAG3B,KAAK,SAAS,EACd,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,MAAM,EAAe,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAMlC,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAEjE,qBAAa,cAAe,YAAW,SAAS;IAI5C,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAJvC,OAAO,CAAC,cAAc,CAAyB;gBAG5B,YAAY,EAAE,OAAO,EACrB,oBAAoB,EAAE,mBAAmB,EAC1D,qBAAqB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,sBAAsB;IAgBhE,aAAa,IAAI,mBAAmB;IAIpC,WAAW,IAAI,OAAO;IAItB,gBAAgB,IAAI,UAAU,CAAC,yBAAyB,CAAC;IAkBzD,eAAe,IAAI,IAAI;IAMvB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