@ledgerhq/device-transport-kit-react-native-ble 0.0.0-wip-20250214170223

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 (41) hide show
  1. package/LICENSE.MD +202 -0
  2. package/lib/cjs/api/index.js +2 -0
  3. package/lib/cjs/api/index.js.map +7 -0
  4. package/lib/cjs/api/model/Const.js +2 -0
  5. package/lib/cjs/api/model/Const.js.map +7 -0
  6. package/lib/cjs/api/model/Errors.js +2 -0
  7. package/lib/cjs/api/model/Errors.js.map +7 -0
  8. package/lib/cjs/api/transport/RNBleApduSender.js +2 -0
  9. package/lib/cjs/api/transport/RNBleApduSender.js.map +7 -0
  10. package/lib/cjs/api/transport/RNBleTransport.js +2 -0
  11. package/lib/cjs/api/transport/RNBleTransport.js.map +7 -0
  12. package/lib/cjs/index.js +2 -0
  13. package/lib/cjs/index.js.map +7 -0
  14. package/lib/cjs/package.json +62 -0
  15. package/lib/esm/api/index.js +2 -0
  16. package/lib/esm/api/index.js.map +7 -0
  17. package/lib/esm/api/model/Const.js +2 -0
  18. package/lib/esm/api/model/Const.js.map +7 -0
  19. package/lib/esm/api/model/Errors.js +2 -0
  20. package/lib/esm/api/model/Errors.js.map +7 -0
  21. package/lib/esm/api/transport/RNBleApduSender.js +2 -0
  22. package/lib/esm/api/transport/RNBleApduSender.js.map +7 -0
  23. package/lib/esm/api/transport/RNBleTransport.js +2 -0
  24. package/lib/esm/api/transport/RNBleTransport.js.map +7 -0
  25. package/lib/esm/index.js +2 -0
  26. package/lib/esm/index.js.map +7 -0
  27. package/lib/esm/package.json +62 -0
  28. package/lib/types/api/index.d.ts +3 -0
  29. package/lib/types/api/index.d.ts.map +1 -0
  30. package/lib/types/api/model/Const.d.ts +4 -0
  31. package/lib/types/api/model/Const.d.ts.map +1 -0
  32. package/lib/types/api/model/Errors.d.ts +22 -0
  33. package/lib/types/api/model/Errors.d.ts.map +1 -0
  34. package/lib/types/api/transport/RNBleApduSender.d.ts +41 -0
  35. package/lib/types/api/transport/RNBleApduSender.d.ts.map +1 -0
  36. package/lib/types/api/transport/RNBleTransport.d.ts +154 -0
  37. package/lib/types/api/transport/RNBleTransport.d.ts.map +1 -0
  38. package/lib/types/index.d.ts +2 -0
  39. package/lib/types/index.d.ts.map +1 -0
  40. package/lib/types/tsconfig.prod.tsbuildinfo +1 -0
  41. package/package.json +61 -0
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/api/transport/RNBleTransport.ts"],
4
+ "sourcesContent": ["import { PermissionsAndroid, Platform } from \"react-native\";\nimport { type BleError, BleManager, type Device } from \"react-native-ble-plx\";\nimport {\n type ApduReceiverServiceFactory,\n type ApduSenderServiceFactory,\n type BleDeviceInfos,\n type ConnectError,\n DeviceConnectionStateMachine,\n type DeviceId,\n type DeviceModelDataSource,\n type DisconnectHandler,\n type DmkError,\n type LoggerPublisherService,\n OpeningConnectionError,\n type Transport,\n TransportConnectedDevice,\n type TransportDiscoveredDevice,\n type TransportFactory,\n type TransportIdentifier,\n UnknownDeviceError,\n} from \"@ledgerhq/device-management-kit\";\nimport { type Either, EitherAsync, Maybe, Nothing, Right } from \"purify-ts\";\nimport {\n from,\n merge,\n Observable,\n retry,\n type Subscriber,\n switchMap,\n} from \"rxjs\";\n\nimport {\n BLE_DISCONNECT_TIMEOUT,\n CONNECTION_LOST_DELAY,\n DEFAULT_MTU,\n} from \"@api/model/Const\";\nimport {\n DeviceConnectionNotFound,\n InternalDeviceNotFound,\n} from \"@api/model/Errors\";\nimport {\n RNBleApduSender,\n type RNBleApduSenderDependencies,\n type RNBleInternalDevice,\n} from \"@api/transport/RNBleApduSender\";\n\nexport const rnBleTransportIdentifier = \"RN_BLE\";\n\nexport class RNBleTransport implements Transport {\n private _logger: LoggerPublisherService;\n private _isSupported: Maybe<boolean>;\n private _internalDevicesById: Map<DeviceId, RNBleInternalDevice>;\n private _deviceConnectionsById: Map<\n DeviceId,\n DeviceConnectionStateMachine<RNBleApduSenderDependencies>\n >;\n private readonly _manager: BleManager;\n private readonly identifier: TransportIdentifier = \"RN_BLE\";\n\n constructor(\n private readonly _deviceModelDataSource: DeviceModelDataSource,\n private readonly _loggerServiceFactory: (\n tag: string,\n ) => LoggerPublisherService,\n private readonly _apduSenderFactory: ApduSenderServiceFactory,\n private readonly _apduReceiverFactory: ApduReceiverServiceFactory,\n ) {\n this._logger = _loggerServiceFactory(\"ReactNativeBleTransport\");\n this._manager = new BleManager();\n this._isSupported = Maybe.zero();\n this._internalDevicesById = new Map();\n this._deviceConnectionsById = new Map();\n this.requestPermission();\n }\n\n /**\n * Starts the discovery process to find Bluetooth devices that match specific criteria.\n *\n * This method clears the internal device cache and requests necessary permissions\n * before initiating the discovery of both known and new devices. If the Bluetooth\n * Low Energy (BLE) feature is not supported, an error is thrown.\n *\n * @return {Observable<TransportDiscoveredDevice>} An observable emitting discovered devices\n * that match the specified Bluetooth services.\n */\n startDiscovering(): Observable<TransportDiscoveredDevice> {\n const ledgerUuids = this._deviceModelDataSource.getBluetoothServices();\n this._internalDevicesById.clear();\n return from(this.requestPermission()).pipe(\n switchMap((isSupported) => {\n if (!isSupported) {\n throw new Error(\"BLE not supported\");\n }\n return merge(\n this._discoverKnownDevices(ledgerUuids),\n this._discoverNewDevices(ledgerUuids),\n );\n }),\n );\n }\n\n /**\n * Stops the device scanning operation currently in progress.\n *\n * @return {Promise<void>} A promise that resolves once the device scanning has been successfully stopped.\n */\n async stopDiscovering(): Promise<void> {\n await this._manager.stopDeviceScan();\n }\n\n /**\n * Establishes a connection to a device and configures the necessary parameters for communication.\n *\n * @param {Object} params - An object containing parameters required for the connection.\n * @param {DeviceId} params.deviceId - The unique identifier of the device to connect to.\n * @param {DisconnectHandler} params.onDisconnect - A callback function to handle device disconnection.\n * @returns {Promise<Either<ConnectError, TransportConnectedDevice>>} A promise resolving to either a connection error or a successfully connected device.\n */\n async connect(params: {\n deviceId: DeviceId;\n onDisconnect: DisconnectHandler;\n }): Promise<Either<ConnectError, TransportConnectedDevice>> {\n return EitherAsync<ConnectError, TransportConnectedDevice>(\n async ({ liftEither, throwE }) => {\n const internalDevice = await liftEither(\n Maybe.fromNullable(\n this._internalDevicesById.get(params.deviceId),\n ).toEither(\n new UnknownDeviceError(`Unknown device ${params.deviceId}`),\n ),\n );\n\n let device: Device;\n\n try {\n device = await this._manager.connectToDevice(params.deviceId, {\n requestMTU: DEFAULT_MTU,\n });\n await this._manager.discoverAllServicesAndCharacteristicsForDevice(\n params.deviceId,\n );\n } catch (error) {\n return throwE(new OpeningConnectionError(error));\n }\n\n const deviceApduSender = new RNBleApduSender(\n {\n apduSenderFactory: this._apduSenderFactory,\n apduReceiverFactory: this._apduReceiverFactory,\n dependencies: {\n device,\n internalDevice,\n manager: this._manager,\n },\n },\n this._loggerServiceFactory,\n );\n\n const deviceConnectionStateMachine =\n new DeviceConnectionStateMachine<RNBleApduSenderDependencies>({\n deviceId: params.deviceId,\n deviceApduSender,\n timeoutDuration: BLE_DISCONNECT_TIMEOUT,\n onTerminated: () => {\n params.onDisconnect(params.deviceId);\n this._deviceConnectionsById.delete(params.deviceId);\n const iDevice = this._internalDevicesById.get(params.deviceId);\n\n if (iDevice) {\n iDevice.disconnectionSubscription.remove();\n }\n\n this._internalDevicesById.delete(params.deviceId);\n },\n });\n\n await deviceApduSender.setupConnection();\n\n this._deviceConnectionsById.set(\n internalDevice.id,\n deviceConnectionStateMachine,\n );\n\n internalDevice.disconnectionSubscription =\n this._manager.onDeviceDisconnected(internalDevice.id, (...args) => {\n this._handleDeviceDisconnected(...args);\n });\n\n internalDevice.lastDiscoveredTimeStamp = Maybe.zero();\n\n return new TransportConnectedDevice({\n id: internalDevice.id,\n deviceModel: internalDevice.discoveredDevice.deviceModel,\n type: \"BLE\",\n sendApdu: (...args) => deviceConnectionStateMachine.sendApdu(...args),\n transport: this.identifier,\n });\n },\n ).run();\n }\n\n /**\n * Terminates the connection with the connected device and cleans up related resources.\n *\n * @param {TransportConnectedDevice} params.connectedDevice - The connected device to be disconnected.\n * @return {Promise<Either<DmkError, void>>} A promise resolving to either a success (void) or a failure (DmkError) value.\n */\n async disconnect(params: {\n connectedDevice: TransportConnectedDevice;\n }): Promise<Either<DmkError, void>> {\n const deviceConnection = Maybe.fromNullable(\n this._deviceConnectionsById.get(params.connectedDevice.id),\n );\n\n deviceConnection.map((d) => {\n d.closeConnection();\n });\n\n return Promise.resolve(Right(undefined));\n }\n\n private _isDiscoveredDeviceLost(internalDevice: RNBleInternalDevice) {\n return internalDevice.lastDiscoveredTimeStamp.caseOf({\n Just: (lastDiscoveredTimeStamp) =>\n Date.now() > lastDiscoveredTimeStamp + CONNECTION_LOST_DELAY,\n Nothing: () => {\n internalDevice.lastDiscoveredTimeStamp = Maybe.of(Date.now());\n return true;\n },\n });\n }\n\n /**\n * Listens to known devices and emits updates when new devices are discovered or when properties of existing devices are updated.\n *\n * @return {Observable<TransportDiscoveredDevice[]>} An observable stream of discovered devices, containing device information as an array of TransportDiscoveredDevice objects.\n */\n listenToKnownDevices(): Observable<TransportDiscoveredDevice[]> {\n return from([]);\n }\n\n /**\n * Determines if the feature or permission is supported.\n *\n * This method evaluates the current state of the `_isSupported` property to determine\n * whether the relevant feature is supported or throws an error if its state has\n * not been initialized properly.\n *\n * @return {boolean} Returns `true` if the feature is supported, otherwise `false`.\n * Throws an error if the `_isSupported` property has not been initialized.\n */\n isSupported(): boolean {\n return this._isSupported.caseOf({\n Just: (isSupported) => isSupported,\n Nothing: () => {\n throw new Error(\"Should initialize permission\");\n },\n });\n }\n\n /**\n * Retrieves the transport identifier associated with the object.\n *\n * @return {TransportIdentifier} The transport identifier.\n */\n getIdentifier(): TransportIdentifier {\n return this.identifier;\n }\n\n /**\n * Requests the necessary permissions based on the operating system.\n * For iOS, it automatically sets the permissions as granted.\n * For Android, it checks and requests location, Bluetooth scan, and Bluetooth connect permissions, depending on the API level.\n * If permissions are granted, updates the internal support state and logs the result.\n *\n * @return {Promise<boolean>} A promise that resolves to true if the required permissions are granted, otherwise false.\n */\n async requestPermission(): Promise<boolean> {\n if (Platform.OS === \"ios\") {\n this._isSupported = Maybe.of(true);\n return true;\n }\n\n if (\n Platform.OS === \"android\" &&\n PermissionsAndroid.PERMISSIONS[\"ACCESS_FINE_LOCATION\"]\n ) {\n const apiLevel = parseInt(Platform.Version.toString(), 10);\n\n if (apiLevel < 31) {\n const granted = await PermissionsAndroid.request(\n PermissionsAndroid.PERMISSIONS[\"ACCESS_FINE_LOCATION\"],\n );\n this._isSupported = Maybe.of(\n granted === PermissionsAndroid.RESULTS[\"GRANTED\"],\n );\n }\n if (\n PermissionsAndroid.PERMISSIONS[\"BLUETOOTH_SCAN\"] &&\n PermissionsAndroid.PERMISSIONS[\"BLUETOOTH_CONNECT\"]\n ) {\n const result = await PermissionsAndroid.requestMultiple([\n PermissionsAndroid.PERMISSIONS[\"BLUETOOTH_SCAN\"],\n PermissionsAndroid.PERMISSIONS[\"BLUETOOTH_CONNECT\"],\n PermissionsAndroid.PERMISSIONS[\"ACCESS_FINE_LOCATION\"],\n ]);\n\n this._isSupported = Maybe.of(\n result[\"android.permission.BLUETOOTH_CONNECT\"] ===\n PermissionsAndroid.RESULTS[\"GRANTED\"] &&\n result[\"android.permission.BLUETOOTH_SCAN\"] ===\n PermissionsAndroid.RESULTS[\"GRANTED\"] &&\n result[\"android.permission.ACCESS_FINE_LOCATION\"] ===\n PermissionsAndroid.RESULTS[\"GRANTED\"],\n );\n\n return true;\n }\n }\n\n this._logger.error(\"Permission have not been granted\", {\n data: { isSupported: this.isSupported() },\n });\n\n this._isSupported = Maybe.of(false);\n return false;\n }\n\n /**\n * Retrieves a discovered device and its BLE device information, if available, from the provided input.\n *\n * @param {Device} rnDevice - The Bluetooth device to analyze for discovery.\n * @param {string[]} ledgerUuids - A list of UUIDs associated with the target Ledger devices.\n * @return {Maybe<{ bleDeviceInfos: BleDeviceInfos; discoveredDevice: TransportDiscoveredDevice }>} A Maybe object containing the discovered device and its BLE information, or Nothing if the device or information cannot be determined.\n */\n private _getDiscoveredDeviceFrom(\n rnDevice: Device,\n ledgerUuids: string[],\n ): Maybe<{\n bleDeviceInfos: BleDeviceInfos;\n discoveredDevice: TransportDiscoveredDevice;\n }> {\n const maybeUuid = Maybe.fromNullable(\n rnDevice?.serviceUUIDs?.find((uuid) => ledgerUuids.includes(uuid)),\n );\n\n const existingInternalDevice = Maybe.fromNullable(\n this._internalDevicesById.get(rnDevice.id),\n );\n\n if (existingInternalDevice.isJust()) {\n return Nothing;\n }\n\n return maybeUuid.mapOrDefault((uuid) => {\n const serviceToBleInfos =\n this._deviceModelDataSource.getBluetoothServicesInfos();\n const maybeBleDeviceInfos = Maybe.fromNullable(serviceToBleInfos[uuid]);\n\n return maybeBleDeviceInfos.map((bleDeviceInfos) => {\n const discoveredDevice: TransportDiscoveredDevice = {\n id: rnDevice.id,\n name: rnDevice.localName || bleDeviceInfos.deviceModel.productName,\n deviceModel: bleDeviceInfos.deviceModel,\n transport: this.identifier,\n };\n\n return {\n discoveredDevice,\n bleDeviceInfos,\n };\n });\n }, Nothing);\n }\n\n /**\n * Handles the processing of devices that have been determined to be \"lost\" by iterating\n * through a collection of internal devices, identifying lost devices, updating their status,\n * and notifying a subscriber about the change.\n *\n * @param {Subscriber<TransportDiscoveredDevice>} subscriber - The observer that will be notified\n * when a device is marked as lost, including updated device information with its availability set to false.\n * @return {void} This method does not return a value.\n */\n private _handleLostDiscoveredDevices(\n subscriber: Subscriber<TransportDiscoveredDevice>,\n ) {\n this._internalDevicesById.forEach((internalDevice) => {\n if (this._isDiscoveredDeviceLost(internalDevice)) {\n this._internalDevicesById.delete(internalDevice.id);\n subscriber.next({\n ...internalDevice.discoveredDevice,\n available: false,\n });\n }\n });\n }\n\n /**\n * Emits a discovered device to the provided subscriber and manages internal state\n * for the discovered device, including handling its availability status and disconnection events.\n *\n * @param {Subscriber<TransportDiscoveredDevice>} subscriber The subscriber to emit the discovered device to.\n * @param {BleDeviceInfos} bleDeviceInfos The BLE device information associated with the discovered device.\n * @param {TransportDiscoveredDevice} discoveredDevice The newly discovered device to be emitted.\n * @return {void} Does*/\n private _emitDiscoveredDevice(\n subscriber: Subscriber<TransportDiscoveredDevice>,\n bleDeviceInfos: BleDeviceInfos,\n discoveredDevice: TransportDiscoveredDevice,\n ) {\n subscriber.next(discoveredDevice);\n const internalDevice = {\n id: discoveredDevice.id,\n bleDeviceInfos,\n discoveredDevice,\n available: true,\n lastDiscoveredTimeStamp: Maybe.of(Date.now()),\n };\n this._internalDevicesById.set(discoveredDevice.id, {\n ...internalDevice,\n disconnectionSubscription: this._manager.onDeviceDisconnected(\n discoveredDevice.id,\n () => {\n // this._internalDevicesById.delete(discoveredDevice.id);\n subscriber.next({ ...discoveredDevice, available: false });\n },\n ),\n });\n }\n\n /**\n * Discovers new devices by scanning for BLE devices and filtering them based on the provided ledger UUIDs.\n *\n * @param {string[]} ledgerUuids - An array of UUIDs used to identify relevant ledger devices.\n * @return {Observable<TransportDiscoveredDevice>} An observable that emits discovered devices matching the provided UUIDs.\n */\n private _discoverNewDevices(\n ledgerUuids: string[],\n ): Observable<TransportDiscoveredDevice> {\n return new Observable<TransportDiscoveredDevice>((subscriber) => {\n this._manager.startDeviceScan(null, null, (error, device) => {\n this._handleLostDiscoveredDevices(subscriber);\n\n if (error || !device) {\n subscriber.error(error);\n return;\n }\n\n this._getDiscoveredDeviceFrom(device, ledgerUuids).map(\n ({ discoveredDevice, bleDeviceInfos }) => {\n this._emitDiscoveredDevice(\n subscriber,\n bleDeviceInfos,\n discoveredDevice,\n );\n },\n );\n });\n });\n }\n\n /**\n * Discovers and emits known ledger devices based on the provided UUIDs.\n *\n * @param {string[]} ledgerUuids - An array of UUIDs representing the target ledger devices to discover.\n * @return {Observable<TransportDiscoveredDevice>} An Observable that emits discovered devices matching the provided UUIDs.\n */\n private _discoverKnownDevices(\n ledgerUuids: string[],\n ): Observable<TransportDiscoveredDevice> {\n return from(this._manager.connectedDevices(ledgerUuids)).pipe(\n switchMap(\n (devices) =>\n new Observable<TransportDiscoveredDevice>((subscriber) => {\n devices.forEach((device) => {\n this._getDiscoveredDeviceFrom(device, ledgerUuids).map(\n ({ bleDeviceInfos, discoveredDevice }) => {\n this._emitDiscoveredDevice(\n subscriber,\n bleDeviceInfos,\n discoveredDevice,\n );\n },\n );\n });\n }),\n ),\n );\n }\n\n /**\n * Handles the event when a Bluetooth device gets disconnected. This method attempts\n * to reconnect to the device, retries a certain number of times on failure, and\n * invokes a callback if the reconnection does not succeed.\n *\n * @param {BleError | null} error - The error object representing the reason for the disconnection, or null if no error occurred.\n * @param {Device | null} device - The Bluetooth device that was disconnected, or null if no device is provided.\n * @param {DisconnectHandler} onDisconnect - A callback function to be called if the reconnection attempts fail completely.\n * @return {void}\n */\n private _handleDeviceDisconnected(\n error: BleError | null,\n device: Device | null,\n ) {\n if (error) {\n this._logger.error(\"device disconnected error\", {\n data: { error, device },\n });\n }\n\n if (!device) {\n this._logger.info(\"disconnected handler didn't found device\");\n return;\n }\n\n const errorOrDeviceConnection = Maybe.fromNullable(\n this._deviceConnectionsById.get(device.id),\n );\n\n errorOrDeviceConnection.map((deviceConnection) => {\n deviceConnection.eventDeviceDetached();\n });\n\n let reconnectedDevice: Device;\n\n from([0])\n .pipe(\n switchMap(async () => {\n try {\n reconnectedDevice = await device.connect({\n requestMTU: DEFAULT_MTU,\n });\n reconnectedDevice =\n await device.discoverAllServicesAndCharacteristics();\n await this._handleDeviceReconnected(reconnectedDevice);\n } catch (e) {\n this._logger.error(\n \"[_handleDeviceDisconnected] Reconnecting failed\",\n { data: { e } },\n );\n\n Maybe.fromNullable(this._deviceConnectionsById.get(device.id)).map(\n (deviceConnection) => {\n deviceConnection.closeConnection();\n },\n );\n\n throw e;\n }\n\n return device;\n }),\n retry({\n count: 5,\n delay: BLE_DISCONNECT_TIMEOUT / 5,\n }),\n )\n .subscribe({\n next: (value) =>\n this._logger.info(\n \"[_handleDeviceDisconnected] Got new device after reconnection\",\n { data: { value } },\n ),\n error: (e) => {\n this._logger.error(\n \"[_handleDeviceDisconnected] Reconnection failed after all retries\",\n { data: { e } },\n );\n },\n });\n }\n\n /**\n * Handles the reconnection of a device. Configures the device connection and its corresponding\n * internal device upon reconnection, including updating the connection state, registering\n * callbacks for write and monitor operations, and initiating a reconnect operation.\n *\n * @param {Device} device - The device object that has been reconnected. Contains device details,\n * such as the device ID.\n * @return {Promise<Either<DeviceConnectionNotFound | InternalDeviceNotFound, void>>} A promise that completes when the device reconnection has been fully\n * configured. Resolves with no value or rejects if an error occurs during\n * the reconnection process.\n */\n private async _handleDeviceReconnected(device: Device) {\n const errorOrDeviceConnection = Maybe.fromNullable(\n this._deviceConnectionsById.get(device.id),\n ).toEither(new DeviceConnectionNotFound());\n\n const errorOrInternalDevice = Maybe.fromNullable(\n this._internalDevicesById.get(device.id),\n ).toEither(new InternalDeviceNotFound());\n\n return EitherAsync(async ({ liftEither }) => {\n const deviceConnectionStateMachine = await liftEither(\n errorOrDeviceConnection,\n );\n\n const internalDevice = await liftEither(errorOrInternalDevice);\n\n deviceConnectionStateMachine.setDependencies({\n device,\n manager: this._manager,\n internalDevice,\n });\n\n await deviceConnectionStateMachine.setupConnection();\n\n deviceConnectionStateMachine.eventDeviceAttached();\n }).run();\n }\n}\n\nexport const RNBleTransportFactory: TransportFactory = ({\n deviceModelDataSource,\n loggerServiceFactory,\n apduSenderServiceFactory,\n apduReceiverServiceFactory,\n}) =>\n new RNBleTransport(\n deviceModelDataSource,\n loggerServiceFactory,\n apduSenderServiceFactory,\n apduReceiverServiceFactory,\n );\n"],
5
+ "mappings": "AAAA,OAAS,sBAAAA,EAAoB,YAAAC,MAAgB,eAC7C,OAAwB,cAAAC,MAA+B,uBACvD,OAKE,gCAAAC,EAMA,0BAAAC,EAEA,4BAAAC,EAIA,sBAAAC,MACK,kCACP,OAAsB,eAAAC,EAAa,SAAAC,EAAO,WAAAC,EAAS,SAAAC,MAAa,YAChE,OACE,QAAAC,EACA,SAAAC,EACA,cA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a,KAAK,uBAAuB,IAAI0B,EAAO,EAAE,CAAC,EAAE,IAC5DkB,GAAqB,CACpBA,EAAiB,gBAAgB,CACnC,CACF,EAEME,CACR,CAEA,OAAOpB,CACT,CAAC,EACDpB,EAAM,CACJ,MAAO,EACP,MAAOE,EAAyB,CAClC,CAAC,CACH,EACC,UAAU,CACT,KAAOuC,GACL,KAAK,QAAQ,KACX,gEACA,CAAE,KAAM,CAAE,MAAAA,CAAM,CAAE,CACpB,EACF,MAAQD,GAAM,CACZ,KAAK,QAAQ,MACX,oEACA,CAAE,KAAM,CAAE,EAAAA,CAAE,CAAE,CAChB,CACF,CACF,CAAC,CACL,CAaA,MAAc,yBAAyBpB,EAAgB,CACrD,MAAMsB,EAA0BhD,EAAM,aACpC,KAAK,uBAAuB,IAAI0B,EAAO,EAAE,CAC3C,EAAE,SAAS,IAAIf,CAA0B,EAEnCsC,EAAwBjD,EAAM,aAClC,KAAK,qBAAqB,IAAI0B,EAAO,EAAE,CACzC,EAAE,SAAS,IAAId,CAAwB,EAEvC,OAAOb,EAAY,MAAO,CAAE,WAAAwB,CAAW,IAAM,CAC3C,MAAMM,EAA+B,MAAMN,EACzCyB,CACF,EAEMvB,EAAiB,MAAMF,EAAW0B,CAAqB,EAE7DpB,EAA6B,gBAAgB,CAC3C,OAAAH,EACA,QAAS,KAAK,SACd,eAAAD,CACF,CAAC,EAED,MAAMI,EAA6B,gBAAgB,EAEnDA,EAA6B,oBAAoB,CACnD,CAAC,EAAE,IAAI,CACT,CACF,CAEO,MAAMqB,EAA0C,CAAC,CACtD,sBAAAC,EACA,qBAAAC,EACA,yBAAAC,EACA,2BAAAC,CACF,IACE,IAAIvC,EACFoC,EACAC,EACAC,EACAC,CACF",
6
+ "names": ["PermissionsAndroid", "Platform", "BleManager", "DeviceConnectionStateMachine", "OpeningConnectionError", "TransportConnectedDevice", "UnknownDeviceError", "EitherAsync", "Maybe", "Nothing", "Right", "from", "merge", "Observable", "retry", "switchMap", "BLE_DISCONNECT_TIMEOUT", "CONNECTION_LOST_DELAY", "DEFAULT_MTU", "DeviceConnectionNotFound", "InternalDeviceNotFound", "RNBleApduSender", "rnBleTransportIdentifier", "RNBleTransport", "_deviceModelDataSource", "_loggerServiceFactory", "_apduSenderFactory", "_apduReceiverFactory", "ledgerUuids", "isSupported", "params", "liftEither", "throwE", "internalDevice", "device", "error", "deviceApduSender", "deviceConnectionStateMachine", "iDevice", "args", "d", "lastDiscoveredTimeStamp", "granted", "result", "rnDevice", "maybeUuid", "uuid", "serviceToBleInfos", "bleDeviceInfos", "subscriber", "discoveredDevice", "devices", "deviceConnection", "reconnectedDevice", "e", "value", "errorOrDeviceConnection", "errorOrInternalDevice", "RNBleTransportFactory", "deviceModelDataSource", "loggerServiceFactory", "apduSenderServiceFactory", "apduReceiverServiceFactory"]
7
+ }
@@ -0,0 +1,2 @@
1
+ export*from"./api";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["export * from \"./api\";\n"],
5
+ "mappings": "AAAA,WAAc",
6
+ "names": []
7
+ }
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@ledgerhq/device-transport-kit-react-native-ble",
3
+ "version": "0.0.1",
4
+ "license": "Apache-2.0",
5
+ "private": false,
6
+ "exports": {
7
+ ".": {
8
+ "types": "./lib/types/index.d.ts",
9
+ "import": "./lib/esm/index.js",
10
+ "require": "./lib/cjs/index.js"
11
+ },
12
+ "./*": {
13
+ "types": "./lib/types/*",
14
+ "import": "./lib/esm/*",
15
+ "require": "./lib/cjs/*"
16
+ }
17
+ },
18
+ "files": [
19
+ "./lib"
20
+ ],
21
+ "scripts": {
22
+ "prebuild": "rimraf lib",
23
+ "build": "pnpm lmdk-build --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
24
+ "dev": "concurrently \"pnpm watch:builds\" \"pnpm watch:types\"",
25
+ "watch:builds": "pnpm lmdk-watch --entryPoints src/index.ts,src/**/*.ts --tsconfig tsconfig.prod.json",
26
+ "watch:types": "concurrently \"tsc --watch -p tsconfig.prod.json\" \"tsc-alias --watch -p tsconfig.prod.json\"",
27
+ "lint": "eslint",
28
+ "lint:fix": "pnpm lint --fix",
29
+ "postpack": "find . -name '*.tgz' -exec cp {} ../../../dist/ \\; ",
30
+ "prettier": "prettier . --check",
31
+ "prettier:fix": "prettier . --write",
32
+ "typecheck": "tsc --noEmit",
33
+ "test": "vitest run --passWithNoTests",
34
+ "test:watch": "vitest --passWithNoTests",
35
+ "test:coverage": "vitest run --coverage --passWithNoTests"
36
+ },
37
+ "dependencies": {
38
+ "@sentry/minimal": "^6.19.7",
39
+ "js-base64": "^3.7.7",
40
+ "purify-ts": "^2.1.0",
41
+ "uuid": "^10.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@ledgerhq/device-management-kit": "workspace:*",
45
+ "@ledgerhq/esbuild-tools": "workspace:*",
46
+ "@ledgerhq/eslint-config-dsdk": "workspace:*",
47
+ "@ledgerhq/vitest-config-dmk": "workspace:*",
48
+ "@ledgerhq/prettier-config-dsdk": "workspace:*",
49
+ "@ledgerhq/tsconfig-dsdk": "workspace:*",
50
+ "@types/uuid": "^10.0.0",
51
+ "react-native": "^0.76.3",
52
+ "react-native-ble-plx": "^3.2.1",
53
+ "rxjs": "^7.8.1",
54
+ "ts-node": "^10.9.2"
55
+ },
56
+ "peerDependencies": {
57
+ "@ledgerhq/device-management-kit": "workspace:*",
58
+ "react-native-ble-plx": "^3.2.1",
59
+ "react-native": ">0.70",
60
+ "rxjs": "^7.8.1"
61
+ }
62
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./model/Errors";
2
+ export { RNBleTransport, RNBleTransportFactory, rnBleTransportIdentifier, } from "./transport/RNBleTransport";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const DEFAULT_MTU = 156;
2
+ export declare const CONNECTION_LOST_DELAY = 5000;
3
+ export declare const BLE_DISCONNECT_TIMEOUT = 10000;
4
+ //# sourceMappingURL=Const.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Const.d.ts","sourceRoot":"","sources":["../../../../src/api/model/Const.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,MAAM,CAAC;AAC/B,eAAO,MAAM,qBAAqB,OAAM,CAAC;AACzC,eAAO,MAAM,sBAAsB,QAAO,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { GeneralDmkError } from "@ledgerhq/device-management-kit";
2
+ export declare class BleTransportNotSupportedError extends GeneralDmkError {
3
+ readonly err?: unknown | undefined;
4
+ readonly _tag = "BleTransportNotSupportedError";
5
+ constructor(err?: unknown | undefined);
6
+ }
7
+ export declare class BleDeviceGattServerError extends GeneralDmkError {
8
+ readonly err?: unknown | undefined;
9
+ readonly _tag = "BleDeviceGattServerError";
10
+ constructor(err?: unknown | undefined);
11
+ }
12
+ export declare class DeviceConnectionNotFound extends GeneralDmkError {
13
+ readonly err?: unknown | undefined;
14
+ readonly _tag = "DeviceConnectionNotFound";
15
+ constructor(err?: unknown | undefined);
16
+ }
17
+ export declare class InternalDeviceNotFound extends GeneralDmkError {
18
+ readonly err?: unknown | undefined;
19
+ readonly _tag = "InternalDeviceNotFound";
20
+ constructor(err?: unknown | undefined);
21
+ }
22
+ //# sourceMappingURL=Errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../../../../src/api/model/Errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE,qBAAa,6BAA8B,SAAQ,eAAe;IAEpD,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO;IADlC,SAAkB,IAAI,mCAAmC;gBACpC,GAAG,CAAC,EAAE,OAAO,YAAA;CAGnC;AACD,qBAAa,wBAAyB,SAAQ,eAAe;IAE/C,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO;IADlC,SAAkB,IAAI,8BAA8B;gBAC/B,GAAG,CAAC,EAAE,OAAO,YAAA;CAGnC;AACD,qBAAa,wBAAyB,SAAQ,eAAe;IAE/C,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO;IADlC,SAAkB,IAAI,8BAA8B;gBAC/B,GAAG,CAAC,EAAE,OAAO,YAAA;CAGnC;AACD,qBAAa,sBAAuB,SAAQ,eAAe;IAE7C,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO;IADlC,SAAkB,IAAI,4BAA4B;gBAC7B,GAAG,CAAC,EAAE,OAAO,YAAA;CAGnC"}
@@ -0,0 +1,41 @@
1
+ import { type BleManager, type Device, type Subscription as RNBleSubscription } from "react-native-ble-plx";
2
+ import { type ApduReceiverServiceFactory, type ApduResponse, type ApduSenderServiceFactory, type BleDeviceInfos, type DeviceApduSender, type DeviceId, type DmkError, type LoggerPublisherService, type TransportDiscoveredDevice } from "@ledgerhq/device-management-kit";
3
+ import { type Either, Maybe } from "purify-ts";
4
+ export type RNBleInternalDevice = {
5
+ id: DeviceId;
6
+ bleDeviceInfos: BleDeviceInfos;
7
+ discoveredDevice: TransportDiscoveredDevice;
8
+ disconnectionSubscription: RNBleSubscription;
9
+ lastDiscoveredTimeStamp: Maybe<number>;
10
+ };
11
+ type RNBleApduSenderConstructorArgs = {
12
+ dependencies: RNBleApduSenderDependencies;
13
+ apduSenderFactory: ApduSenderServiceFactory;
14
+ apduReceiverFactory: ApduReceiverServiceFactory;
15
+ };
16
+ export type RNBleApduSenderDependencies = {
17
+ device: Device;
18
+ internalDevice: RNBleInternalDevice;
19
+ manager: BleManager;
20
+ };
21
+ export declare class RNBleApduSender implements DeviceApduSender<RNBleApduSenderDependencies> {
22
+ private _dependencies;
23
+ private _isDeviceReady;
24
+ private _logger;
25
+ private _apduSender;
26
+ private readonly _apduSenderFactory;
27
+ private readonly _apduReceiver;
28
+ private _sendApduPromiseResolver;
29
+ constructor({ apduSenderFactory, apduReceiverFactory, dependencies, }: RNBleApduSenderConstructorArgs, loggerServiceFactory: (tag: string) => LoggerPublisherService);
30
+ private onReceiveSetupApduResponse;
31
+ private receiveApdu;
32
+ private onMonitor;
33
+ private write;
34
+ getDependencies(): RNBleApduSenderDependencies;
35
+ setDependencies(dependencies: RNBleApduSenderDependencies): void;
36
+ setupConnection(): Promise<void>;
37
+ sendApdu(apdu: Uint8Array): Promise<Either<DmkError, ApduResponse>>;
38
+ closeConnection(): void;
39
+ }
40
+ export {};
41
+ //# sourceMappingURL=RNBleApduSender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RNBleApduSender.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/RNBleApduSender.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,MAAM,EACX,KAAK,YAAY,IAAI,iBAAiB,EACvC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EAEjB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EAEb,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC/B,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAE,KAAK,MAAM,EAAQ,KAAK,EAAkB,MAAM,WAAW,CAAC;AAKrE,MAAM,MAAM,mBAAmB,GAAG;IAChC,EAAE,EAAE,QAAQ,CAAC;IACb,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,yBAAyB,CAAC;IAC5C,yBAAyB,EAAE,iBAAiB,CAAC;IAC7C,uBAAuB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF,KAAK,8BAA8B,GAAG;IACpC,YAAY,EAAE,2BAA2B,CAAC;IAC1C,iBAAiB,EAAE,wBAAwB,CAAC;IAC5C,mBAAmB,EAAE,0BAA0B,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,mBAAmB,CAAC;IACpC,OAAO,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,qBAAa,eACX,YAAW,gBAAgB,CAAC,2BAA2B,CAAC;IAExD,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA2B;IAC9D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;IACpD,OAAO,CAAC,wBAAwB,CAE9B;gBAGA,EACE,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,GACb,EAAE,8BAA8B,EACjC,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,sBAAsB;IAW/D,OAAO,CAAC,0BAA0B;IAelC,OAAO,CAAC,WAAW;IAmBnB,OAAO,CAAC,SAAS;IAejB,OAAO,CAAC,KAAK;IASN,eAAe;IAIf,eAAe,CAAC,YAAY,EAAE,2BAA2B;IAInD,eAAe;IAyBtB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IA6BlE,eAAe;CAGvB"}
@@ -0,0 +1,154 @@
1
+ import { type ApduReceiverServiceFactory, type ApduSenderServiceFactory, type ConnectError, type DeviceId, type DeviceModelDataSource, type DisconnectHandler, type DmkError, type LoggerPublisherService, type Transport, TransportConnectedDevice, type TransportDiscoveredDevice, type TransportFactory, type TransportIdentifier } from "@ledgerhq/device-management-kit";
2
+ import { type Either } from "purify-ts";
3
+ import { Observable } from "rxjs";
4
+ export declare const rnBleTransportIdentifier = "RN_BLE";
5
+ export declare class RNBleTransport implements Transport {
6
+ private readonly _deviceModelDataSource;
7
+ private readonly _loggerServiceFactory;
8
+ private readonly _apduSenderFactory;
9
+ private readonly _apduReceiverFactory;
10
+ private _logger;
11
+ private _isSupported;
12
+ private _internalDevicesById;
13
+ private _deviceConnectionsById;
14
+ private readonly _manager;
15
+ private readonly identifier;
16
+ constructor(_deviceModelDataSource: DeviceModelDataSource, _loggerServiceFactory: (tag: string) => LoggerPublisherService, _apduSenderFactory: ApduSenderServiceFactory, _apduReceiverFactory: ApduReceiverServiceFactory);
17
+ /**
18
+ * Starts the discovery process to find Bluetooth devices that match specific criteria.
19
+ *
20
+ * This method clears the internal device cache and requests necessary permissions
21
+ * before initiating the discovery of both known and new devices. If the Bluetooth
22
+ * Low Energy (BLE) feature is not supported, an error is thrown.
23
+ *
24
+ * @return {Observable<TransportDiscoveredDevice>} An observable emitting discovered devices
25
+ * that match the specified Bluetooth services.
26
+ */
27
+ startDiscovering(): Observable<TransportDiscoveredDevice>;
28
+ /**
29
+ * Stops the device scanning operation currently in progress.
30
+ *
31
+ * @return {Promise<void>} A promise that resolves once the device scanning has been successfully stopped.
32
+ */
33
+ stopDiscovering(): Promise<void>;
34
+ /**
35
+ * Establishes a connection to a device and configures the necessary parameters for communication.
36
+ *
37
+ * @param {Object} params - An object containing parameters required for the connection.
38
+ * @param {DeviceId} params.deviceId - The unique identifier of the device to connect to.
39
+ * @param {DisconnectHandler} params.onDisconnect - A callback function to handle device disconnection.
40
+ * @returns {Promise<Either<ConnectError, TransportConnectedDevice>>} A promise resolving to either a connection error or a successfully connected device.
41
+ */
42
+ connect(params: {
43
+ deviceId: DeviceId;
44
+ onDisconnect: DisconnectHandler;
45
+ }): Promise<Either<ConnectError, TransportConnectedDevice>>;
46
+ /**
47
+ * Terminates the connection with the connected device and cleans up related resources.
48
+ *
49
+ * @param {TransportConnectedDevice} params.connectedDevice - The connected device to be disconnected.
50
+ * @return {Promise<Either<DmkError, void>>} A promise resolving to either a success (void) or a failure (DmkError) value.
51
+ */
52
+ disconnect(params: {
53
+ connectedDevice: TransportConnectedDevice;
54
+ }): Promise<Either<DmkError, void>>;
55
+ private _isDiscoveredDeviceLost;
56
+ /**
57
+ * Listens to known devices and emits updates when new devices are discovered or when properties of existing devices are updated.
58
+ *
59
+ * @return {Observable<TransportDiscoveredDevice[]>} An observable stream of discovered devices, containing device information as an array of TransportDiscoveredDevice objects.
60
+ */
61
+ listenToKnownDevices(): Observable<TransportDiscoveredDevice[]>;
62
+ /**
63
+ * Determines if the feature or permission is supported.
64
+ *
65
+ * This method evaluates the current state of the `_isSupported` property to determine
66
+ * whether the relevant feature is supported or throws an error if its state has
67
+ * not been initialized properly.
68
+ *
69
+ * @return {boolean} Returns `true` if the feature is supported, otherwise `false`.
70
+ * Throws an error if the `_isSupported` property has not been initialized.
71
+ */
72
+ isSupported(): boolean;
73
+ /**
74
+ * Retrieves the transport identifier associated with the object.
75
+ *
76
+ * @return {TransportIdentifier} The transport identifier.
77
+ */
78
+ getIdentifier(): TransportIdentifier;
79
+ /**
80
+ * Requests the necessary permissions based on the operating system.
81
+ * For iOS, it automatically sets the permissions as granted.
82
+ * For Android, it checks and requests location, Bluetooth scan, and Bluetooth connect permissions, depending on the API level.
83
+ * If permissions are granted, updates the internal support state and logs the result.
84
+ *
85
+ * @return {Promise<boolean>} A promise that resolves to true if the required permissions are granted, otherwise false.
86
+ */
87
+ requestPermission(): Promise<boolean>;
88
+ /**
89
+ * Retrieves a discovered device and its BLE device information, if available, from the provided input.
90
+ *
91
+ * @param {Device} rnDevice - The Bluetooth device to analyze for discovery.
92
+ * @param {string[]} ledgerUuids - A list of UUIDs associated with the target Ledger devices.
93
+ * @return {Maybe<{ bleDeviceInfos: BleDeviceInfos; discoveredDevice: TransportDiscoveredDevice }>} A Maybe object containing the discovered device and its BLE information, or Nothing if the device or information cannot be determined.
94
+ */
95
+ private _getDiscoveredDeviceFrom;
96
+ /**
97
+ * Handles the processing of devices that have been determined to be "lost" by iterating
98
+ * through a collection of internal devices, identifying lost devices, updating their status,
99
+ * and notifying a subscriber about the change.
100
+ *
101
+ * @param {Subscriber<TransportDiscoveredDevice>} subscriber - The observer that will be notified
102
+ * when a device is marked as lost, including updated device information with its availability set to false.
103
+ * @return {void} This method does not return a value.
104
+ */
105
+ private _handleLostDiscoveredDevices;
106
+ /**
107
+ * Emits a discovered device to the provided subscriber and manages internal state
108
+ * for the discovered device, including handling its availability status and disconnection events.
109
+ *
110
+ * @param {Subscriber<TransportDiscoveredDevice>} subscriber The subscriber to emit the discovered device to.
111
+ * @param {BleDeviceInfos} bleDeviceInfos The BLE device information associated with the discovered device.
112
+ * @param {TransportDiscoveredDevice} discoveredDevice The newly discovered device to be emitted.
113
+ * @return {void} Does*/
114
+ private _emitDiscoveredDevice;
115
+ /**
116
+ * Discovers new devices by scanning for BLE devices and filtering them based on the provided ledger UUIDs.
117
+ *
118
+ * @param {string[]} ledgerUuids - An array of UUIDs used to identify relevant ledger devices.
119
+ * @return {Observable<TransportDiscoveredDevice>} An observable that emits discovered devices matching the provided UUIDs.
120
+ */
121
+ private _discoverNewDevices;
122
+ /**
123
+ * Discovers and emits known ledger devices based on the provided UUIDs.
124
+ *
125
+ * @param {string[]} ledgerUuids - An array of UUIDs representing the target ledger devices to discover.
126
+ * @return {Observable<TransportDiscoveredDevice>} An Observable that emits discovered devices matching the provided UUIDs.
127
+ */
128
+ private _discoverKnownDevices;
129
+ /**
130
+ * Handles the event when a Bluetooth device gets disconnected. This method attempts
131
+ * to reconnect to the device, retries a certain number of times on failure, and
132
+ * invokes a callback if the reconnection does not succeed.
133
+ *
134
+ * @param {BleError | null} error - The error object representing the reason for the disconnection, or null if no error occurred.
135
+ * @param {Device | null} device - The Bluetooth device that was disconnected, or null if no device is provided.
136
+ * @param {DisconnectHandler} onDisconnect - A callback function to be called if the reconnection attempts fail completely.
137
+ * @return {void}
138
+ */
139
+ private _handleDeviceDisconnected;
140
+ /**
141
+ * Handles the reconnection of a device. Configures the device connection and its corresponding
142
+ * internal device upon reconnection, including updating the connection state, registering
143
+ * callbacks for write and monitor operations, and initiating a reconnect operation.
144
+ *
145
+ * @param {Device} device - The device object that has been reconnected. Contains device details,
146
+ * such as the device ID.
147
+ * @return {Promise<Either<DeviceConnectionNotFound | InternalDeviceNotFound, void>>} A promise that completes when the device reconnection has been fully
148
+ * configured. Resolves with no value or rejects if an error occurs during
149
+ * the reconnection process.
150
+ */
151
+ private _handleDeviceReconnected;
152
+ }
153
+ export declare const RNBleTransportFactory: TransportFactory;
154
+ //# sourceMappingURL=RNBleTransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RNBleTransport.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/RNBleTransport.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAE7B,KAAK,YAAY,EAEjB,KAAK,QAAQ,EACb,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAE3B,KAAK,SAAS,EACd,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAEzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,MAAM,EAAsC,MAAM,WAAW,CAAC;AAC5E,OAAO,EAGL,UAAU,EAIX,MAAM,MAAM,CAAC;AAiBd,eAAO,MAAM,wBAAwB,WAAW,CAAC;AAEjD,qBAAa,cAAe,YAAW,SAAS;IAY5C,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IACvC,OAAO,CAAC,QAAQ,CAAC,qBAAqB;IAGtC,OAAO,CAAC,QAAQ,CAAC,kBAAkB;IACnC,OAAO,CAAC,QAAQ,CAAC,oBAAoB;IAhBvC,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,C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H,OAAO,CAAC,qBAAqB;IAuB7B;;;;;;;;;OASG;IACH,OAAO,CAAC,yBAAyB;IAwEjC;;;;;;;;;;OAUG;YACW,wBAAwB;CA2BvC;AAED,eAAO,MAAM,qBAAqB,EAAE,gBAWjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./api";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}