@ledgerhq/device-transport-kit-web-ble 0.0.0-legacy-speculos-datasource-20250821095840 → 0.0.0-multisig-20250821134850
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/api/data/WebBleConfig.js +1 -1
- package/lib/esm/api/data/WebBleConfig.js.map +3 -3
- package/lib/esm/api/transport/BleDeviceConnection.js +2 -0
- package/lib/esm/api/transport/BleDeviceConnection.js.map +7 -0
- package/lib/esm/api/transport/BleDeviceConnection.test.js +2 -0
- package/lib/esm/api/transport/BleDeviceConnection.test.js.map +7 -0
- package/lib/esm/api/transport/WebBleTransport.js +1 -1
- package/lib/esm/api/transport/WebBleTransport.js.map +3 -3
- package/lib/esm/api/transport/WebBleTransport.test.js +1 -1
- package/lib/esm/api/transport/WebBleTransport.test.js.map +3 -3
- package/lib/types/api/data/WebBleConfig.d.ts +1 -3
- package/lib/types/api/data/WebBleConfig.d.ts.map +1 -1
- package/lib/types/api/transport/BleDeviceConnection.d.ts +98 -0
- package/lib/types/api/transport/BleDeviceConnection.d.ts.map +1 -0
- package/lib/types/api/transport/BleDeviceConnection.test.d.ts +2 -0
- package/lib/types/api/transport/BleDeviceConnection.test.d.ts.map +1 -0
- package/lib/types/api/transport/WebBleTransport.d.ts +76 -21
- package/lib/types/api/transport/WebBleTransport.d.ts.map +1 -1
- package/lib/types/tsconfig.prod.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/lib/esm/api/transport/WebBleApduSender.js +0 -2
- package/lib/esm/api/transport/WebBleApduSender.js.map +0 -7
- package/lib/esm/api/transport/WebBleApduSender.test.js +0 -2
- package/lib/esm/api/transport/WebBleApduSender.test.js.map +0 -7
- package/lib/types/api/transport/WebBleApduSender.d.ts +0 -34
- package/lib/types/api/transport/WebBleApduSender.d.ts.map +0 -1
- package/lib/types/api/transport/WebBleApduSender.test.d.ts +0 -2
- package/lib/types/api/transport/WebBleApduSender.test.d.ts.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type ApduReceiverServiceFactory, type ApduResponse, type ApduSenderServiceFactory, type DeviceConnection, type DmkError, type LoggerPublisherService } from "@ledgerhq/device-management-kit";
|
|
2
|
+
import { type Either } from "purify-ts";
|
|
3
|
+
type BleDeviceConnectionConstructorArgs = {
|
|
4
|
+
writeCharacteristic: BluetoothRemoteGATTCharacteristic;
|
|
5
|
+
notifyCharacteristic: BluetoothRemoteGATTCharacteristic;
|
|
6
|
+
apduSenderFactory: ApduSenderServiceFactory;
|
|
7
|
+
apduReceiverFactory: ApduReceiverServiceFactory;
|
|
8
|
+
};
|
|
9
|
+
export type DataViewEvent = Event & {
|
|
10
|
+
target: {
|
|
11
|
+
value: DataView;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare class BleDeviceConnection implements DeviceConnection {
|
|
15
|
+
private _writeCharacteristic;
|
|
16
|
+
private _notifyCharacteristic;
|
|
17
|
+
private readonly _logger;
|
|
18
|
+
private _apduSender;
|
|
19
|
+
private readonly _apduSenderFactory;
|
|
20
|
+
private readonly _apduReceiver;
|
|
21
|
+
private _isDeviceReady;
|
|
22
|
+
private _sendApduPromiseResolver;
|
|
23
|
+
private _settleReconnectionPromiseResolvers;
|
|
24
|
+
constructor({ writeCharacteristic, notifyCharacteristic, apduSenderFactory, apduReceiverFactory, }: BleDeviceConnectionConstructorArgs, loggerServiceFactory: (tag: string) => LoggerPublisherService);
|
|
25
|
+
/**
|
|
26
|
+
* NotifyCharacteristic setter
|
|
27
|
+
* Register a listener on characteristic value change
|
|
28
|
+
* @param notifyCharacteristic
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
private set notifyCharacteristic(value);
|
|
32
|
+
/**
|
|
33
|
+
* WriteCharacteristic setter
|
|
34
|
+
* @param writeCharacteristic
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
private set writeCharacteristic(value);
|
|
38
|
+
/**
|
|
39
|
+
* Event handler to setup the mtu size in response of 0x0800000000 APDU
|
|
40
|
+
* @param value
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private onReceiveSetupApduResponse;
|
|
44
|
+
/**
|
|
45
|
+
* Main event handler for BLE notify characteristic
|
|
46
|
+
* Call _onReceiveSetupApduResponse if device mtu is not set
|
|
47
|
+
* Call receiveApdu otherwise
|
|
48
|
+
* @param event
|
|
49
|
+
*/
|
|
50
|
+
private onNotifyCharacteristicValueChanged;
|
|
51
|
+
/**
|
|
52
|
+
* Setup BleDeviceConnection
|
|
53
|
+
*
|
|
54
|
+
* The device is considered as ready once the mtu had been set
|
|
55
|
+
* APDU 0x0800000000 is used to get this mtu size
|
|
56
|
+
*/
|
|
57
|
+
setup(): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Receive APDU response
|
|
60
|
+
* Resolve sendApdu promise once the framer receives all the frames of the response
|
|
61
|
+
* @param data
|
|
62
|
+
*/
|
|
63
|
+
receiveApdu(data: ArrayBuffer): void;
|
|
64
|
+
/**
|
|
65
|
+
* Send apdu if the mtu had been set
|
|
66
|
+
*
|
|
67
|
+
* Get all frames for a given APDU
|
|
68
|
+
* Save a promise that would be completed once the response had been received
|
|
69
|
+
* @param apdu
|
|
70
|
+
* @param triggersDisconnection
|
|
71
|
+
*/
|
|
72
|
+
sendApdu(apdu: Uint8Array, triggersDisconnection?: boolean): Promise<Either<DmkError, ApduResponse>>;
|
|
73
|
+
/**
|
|
74
|
+
* Typeguard to check if an event contains target value of type DataView
|
|
75
|
+
*
|
|
76
|
+
* @param event
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
private isDataViewEvent;
|
|
80
|
+
/**
|
|
81
|
+
* Setup a promise that would be resolved once the device is reconnected
|
|
82
|
+
*
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
private setupWaitForReconnection;
|
|
86
|
+
/**
|
|
87
|
+
* Reconnect to the device by resetting new ble characteristics
|
|
88
|
+
* @param writeCharacteristic
|
|
89
|
+
* @param notifyCharacteristic
|
|
90
|
+
*/
|
|
91
|
+
reconnect(writeCharacteristic: BluetoothRemoteGATTCharacteristic, notifyCharacteristic: BluetoothRemoteGATTCharacteristic): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Disconnect from the device
|
|
94
|
+
*/
|
|
95
|
+
disconnect(): void;
|
|
96
|
+
}
|
|
97
|
+
export {};
|
|
98
|
+
//# sourceMappingURL=BleDeviceConnection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BleDeviceConnection.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/BleDeviceConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,0BAA0B,EAC/B,KAAK,YAAY,EAEjB,KAAK,wBAAwB,EAE7B,KAAK,gBAAgB,EAErB,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAE5B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,MAAM,EAA+B,MAAM,WAAW,CAAC;AAErE,KAAK,kCAAkC,GAAG;IACxC,mBAAmB,EAAE,iCAAiC,CAAC;IACvD,oBAAoB,EAAE,iCAAiC,CAAC;IACxD,iBAAiB,EAAE,wBAAwB,CAAC;IAC5C,mBAAmB,EAAE,0BAA0B,CAAC;CACjD,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG;IAClC,MAAM,EAAE;QACN,KAAK,EAAE,QAAQ,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,qBAAa,mBAAoB,YAAW,gBAAgB;IAC1D,OAAO,CAAC,oBAAoB,CAAoC;IAChE,OAAO,CAAC,qBAAqB,CAAoC;IACjE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,WAAW,CAA2B;IAC9C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA2B;IAC9D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;IACpD,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,wBAAwB,CAE7B;IACH,OAAO,CAAC,mCAAmC,CAGxC;gBAGD,EACE,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,GACpB,EAAE,kCAAkC,EACrC,oBAAoB,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,sBAAsB;IAe/D;;;;;OAKG;IACH,OAAO,KAAK,oBAAoB,QAM/B;IAED;;;;OAIG;IACH,OAAO,KAAK,mBAAmB,QAI9B;IAED;;;;OAIG;IACH,OAAO,CAAC,0BAA0B;IAclC;;;;;OAKG;IACH,OAAO,CAAC,kCAAkC,CAgBxC;IAEF;;;;;OAKG;IACU,KAAK;IAOlB;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,WAAW;IAqB7B;;;;;;;OAOG;IACG,QAAQ,CACZ,IAAI,EAAE,UAAU,EAChB,qBAAqB,CAAC,EAAE,OAAO,GAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;IAiD1C;;;;;OAKG;IACH,OAAO,CAAC,eAAe;IAQvB;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAShC;;;;OAIG;IACU,SAAS,CACpB,mBAAmB,EAAE,iCAAiC,EACtD,oBAAoB,EAAE,iCAAiC;IAQzD;;OAEG;IACI,UAAU;CAQlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BleDeviceConnection.test.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/BleDeviceConnection.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,36 +1,91 @@
|
|
|
1
|
-
import { type ApduReceiverServiceFactory, type ApduSenderServiceFactory, type ConnectError, type DeviceModelDataSource, type LoggerPublisherService, type Transport, TransportConnectedDevice, type TransportDiscoveredDevice, type TransportFactory, type TransportIdentifier
|
|
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
2
|
import { type Either } from "purify-ts";
|
|
3
3
|
import { type Observable } from "rxjs";
|
|
4
4
|
export declare const webBleIdentifier: TransportIdentifier;
|
|
5
5
|
export declare class WebBleTransport implements Transport {
|
|
6
|
-
private
|
|
6
|
+
private readonly _deviceModelDataSource;
|
|
7
|
+
private readonly _loggerServiceFactory;
|
|
8
|
+
private readonly _apduSenderFactory;
|
|
9
|
+
private readonly _apduReceiverFactory;
|
|
10
|
+
private readonly _connectedDevices;
|
|
11
|
+
private readonly _internalDevicesById;
|
|
12
|
+
private _deviceConnectionById;
|
|
13
|
+
private _disconnectionHandlersById;
|
|
7
14
|
private _logger;
|
|
8
|
-
private
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
constructor(deviceModelDataSource: DeviceModelDataSource, loggerFactory: (tag: string) => LoggerPublisherService, apduSenderFactory: ApduSenderServiceFactory, apduReceiverFactory: ApduReceiverServiceFactory);
|
|
15
|
+
private readonly connectionType;
|
|
16
|
+
private readonly identifier;
|
|
17
|
+
constructor(_deviceModelDataSource: DeviceModelDataSource, _loggerServiceFactory: (tag: string) => LoggerPublisherService, _apduSenderFactory: ApduSenderServiceFactory, _apduReceiverFactory: ApduReceiverServiceFactory);
|
|
18
|
+
/**
|
|
19
|
+
* Get the Bluetooth API if supported or error
|
|
20
|
+
* @returns `Either<BleTransportNotSupportedError, Bluetooth>`
|
|
21
|
+
*/
|
|
22
|
+
private getBluetoothApi;
|
|
17
23
|
isSupported(): boolean;
|
|
18
24
|
getIdentifier(): TransportIdentifier;
|
|
19
|
-
startDiscovering(): Observable<TransportDiscoveredDevice>;
|
|
20
25
|
listenToAvailableDevices(): Observable<TransportDiscoveredDevice[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Get Bluetooth GATT Primary service that is used to get writeCharacteristic and notifyCharacteristic
|
|
28
|
+
* @param bleDevice
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
private getBleGattService;
|
|
32
|
+
/**
|
|
33
|
+
* BleDeviceInfos to map primary service uuid to device model & characteristics uuid
|
|
34
|
+
* @param bleGattService
|
|
35
|
+
* @private
|
|
36
|
+
*/
|
|
37
|
+
private getBleDeviceInfos;
|
|
38
|
+
/**
|
|
39
|
+
* Prompt device selection in navigator
|
|
40
|
+
*
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private promptDeviceAccess;
|
|
44
|
+
/**
|
|
45
|
+
* Generate a discovered device from BluetoothDevice, BleGATT primary service and BLE device infos
|
|
46
|
+
* @param bleDeviceInfos
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
private getDiscoveredDeviceFrom;
|
|
50
|
+
/**
|
|
51
|
+
* Generate an InternalDevice from a unique id, a BluetoothDevice, BleGATT primary service and BLE device infos
|
|
52
|
+
* @param discoveredDevice
|
|
53
|
+
* @param bleDevice
|
|
54
|
+
* @param bleDeviceInfos
|
|
55
|
+
* @param bleGattService
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
private setInternalDeviceFrom;
|
|
59
|
+
/**
|
|
60
|
+
* Main method to get a device from a button click handler
|
|
61
|
+
* The GATT connection is done here in order to populate TransportDiscoveredDevice with deviceModel
|
|
62
|
+
*/
|
|
63
|
+
startDiscovering(): Observable<TransportDiscoveredDevice>;
|
|
21
64
|
stopDiscovering(): void;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Connect to a BLE device and update the internal state of the associated device
|
|
67
|
+
* Handle ondisconnect event on the device in order to try a reconnection
|
|
68
|
+
*/
|
|
69
|
+
connect({ deviceId, onDisconnect, }: {
|
|
70
|
+
deviceId: DeviceId;
|
|
71
|
+
onDisconnect: DisconnectHandler;
|
|
26
72
|
}): Promise<Either<ConnectError, TransportConnectedDevice>>;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Get the device disconnected handler
|
|
75
|
+
* @param internalDevice WebBleInternalDevice
|
|
76
|
+
* @param deviceConnection BleDeviceConnection
|
|
77
|
+
* @returns async () => void
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
private _getDeviceDisconnectedHandler;
|
|
81
|
+
/**
|
|
82
|
+
* Disconnect from a BLE device and delete its handlers
|
|
83
|
+
*
|
|
84
|
+
* @param params { connectedDevice: TransportConnectedDevice }
|
|
85
|
+
*/
|
|
31
86
|
disconnect(params: {
|
|
32
87
|
connectedDevice: TransportConnectedDevice;
|
|
33
|
-
}): Promise<Either<
|
|
88
|
+
}): Promise<Either<DmkError, void>>;
|
|
34
89
|
}
|
|
35
90
|
export declare const webBleTransportFactory: TransportFactory;
|
|
36
91
|
//# sourceMappingURL=WebBleTransport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebBleTransport.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebBleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,
|
|
1
|
+
{"version":3,"file":"WebBleTransport.d.ts","sourceRoot":"","sources":["../../../../src/api/transport/WebBleTransport.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,0BAA0B,EAC/B,KAAK,wBAAwB,EAE7B,KAAK,YAAY,EAGjB,KAAK,QAAQ,EACb,KAAK,qBAAqB,EAE1B,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,sBAAsB,EAG3B,KAAK,SAAS,EACd,wBAAwB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,mBAAmB,EAEzB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,KAAK,MAAM,EAAmC,MAAM,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