Skip to content

Commit f9a6259

Browse files
committed
📝 (transports): Add missing readme.md to transport packages
1 parent 40a001e commit f9a6259

File tree

3 files changed

+184
-31
lines changed

3 files changed

+184
-31
lines changed

packages/device-management-kit/README.md

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- [Installation](#installation)
99
- [Usage](#usage)
1010
- [Compatibility](#compatibility)
11-
- [Pre-requisites](#pre-requisites)
1211
- [Main Features](#main-features)
1312
- [Setting up the SDK](#setting-up-the-sdk)
1413
- [Connecting to a Device](#connecting-to-a-device)
@@ -37,13 +36,9 @@ npm install @ledgerhq/device-management-kit
3736

3837
## Usage
3938

40-
### Compatibility
41-
42-
This library works in [any browser supporting the WebHID API](https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API#browser_compatibility).
43-
4439
### Pre-requisites
4540

46-
Some of the APIs exposed return objects of type `Observable` from RxJS. Ensure you are familiar with the basics of the Observer pattern and RxJS before using this SDK. You can refer to [RxJS documentation](https://rxjs.dev/guide/overview) for more information.
41+
Some of the APIs exposed return objects of type `Observable` from RxJS. Ensure you are familiar with the basics of the Observer pattern and RxJS before using this dmk. You can refer to [RxJS documentation](https://rxjs.dev/guide/overview) for more information.
4742

4843
### Main Features
4944

@@ -60,48 +55,51 @@ Some of the APIs exposed return objects of type `Observable` from RxJS. Ensure y
6055
> [!NOTE]
6156
> At the moment we do not provide the possibility to distinguish two devices of the same model, via USB and to avoid connection to the same device twice.
6257
63-
### Setting up the SDK
58+
### Setting up the DMK
6459

65-
The core package exposes an SDK builder `DeviceSdkBuilder` which will be used to initialise the SDK with your configuration.
60+
The core package exposes a DMK builder `DeviceManagementKitBuilder` which will be used to initialise the DMK with your configuration.
6661

6762
For now it allows you to add one or more custom loggers.
6863

69-
In the following example, we add a console logger (`.addLogger(new ConsoleLogger())`). Then we build the SDK with `.build()`.
64+
In the following example, we add a console logger (`.addLogger(new ConsoleLogger())`) and a WebHID transport. Then we build the DMK with `.build()`.
7065

71-
**The returned object will be the entrypoint for all your interactions with the SDK.**
66+
**The returned object will be the entrypoint for all your interactions with the DMK.**
7267

73-
The SDK should be built only once in your application runtime so keep a reference of this object somewhere.
68+
The DMK should be built only once in your application runtime so keep a reference of this object somewhere.
7469

7570
```ts
7671
import {
7772
ConsoleLogger,
78-
DeviceSdk,
79-
DeviceSdkBuilder,
73+
DeviceManagementKitBuilder,
8074
} from "@ledgerhq/device-management-kit";
75+
import {
76+
webHidTransportFactory
77+
} from "@ledgerhq/device-transport-kit-web-hid"
8178

82-
export const sdk = new DeviceSdkBuilder()
79+
export const sdk = new DeviceManagementKitBuilder()
8380
.addLogger(new ConsoleLogger())
81+
.addTransport(webHidTransportFactory)
8482
.build();
8583
```
8684

8785
### Connecting to a Device
8886

8987
There are two steps to connecting to a device:
9088

91-
- **Discovery**: `sdk.startDiscovering()`
89+
- **Discovery**: `dmk.startDiscovering()`
9290
- Returns an observable which will emit a new `DiscoveredDevice` for every scanned device.
9391
- The `DiscoveredDevice` objects contain information about the device model.
9492
- Use one of these values to connect to a given discovered device.
95-
- **Connection**: `sdk.connect({ deviceId: device.id })`
93+
- **Connection**: `dmk.connect({ deviceId: device.id })`
9694
- Returns a Promise resolving in a device session identifier `DeviceSessionId`.
9795
- **Keep this device session identifier to further interact with the device.**
98-
- Then, `sdk.getConnectedDevice({ sessionId })` returns the `ConnectedDevice`, which contains information about the device model and its name.
96+
- Then, `dmk.getConnectedDevice({ sessionId })` returns the `ConnectedDevice`, which contains information about the device model and its name.
9997

10098
```ts
101-
sdk.startDiscovering().subscribe({
99+
dmk.startDiscovering().subscribe({
102100
next: (device) => {
103-
sdk.connect({ deviceId: device.id }).then((sessionId) => {
104-
const connectedDevice = sdk.getConnectedDevice({ sessionId });
101+
dmk.connect({ deviceId: device.id }).then((sessionId) => {
102+
const connectedDevice = dmk.getConnectedDevice({ sessionId });
105103
});
106104
},
107105
error: (error) => {
@@ -112,8 +110,8 @@ sdk.startDiscovering().subscribe({
112110

113111
Then once a device is connected:
114112

115-
- **Disconnection**: `sdk.disconnect({ sessionId })`
116-
- **Observe the device session state**: `sdk.getDeviceSessionState({ sessionId })`
113+
- **Disconnection**: `dmk.disconnect({ sessionId })`
114+
- **Observe the device session state**: `dmk.getDeviceSessionState({ sessionId })`
117115
- This will return an `Observable<DeviceSessionState>` to listen to the known information about the device:
118116
- device status:
119117
- ready to process a command
@@ -154,7 +152,7 @@ const apdu = new ApduBuilder(openAppApduArgs)
154152

155153
// ### 2. Sending the APDU
156154

157-
const apduResponse = await sdk.sendApdu({ sessionId, apdu });
155+
const apduResponse = await dmk.sendApdu({ sessionId, apdu });
158156

159157
// ### 3. Parsing the result
160158

@@ -178,7 +176,7 @@ The `sendCommand` method will take care of building the APDU, sending it to the
178176
> ### ❗️ Error Responses
179177
>
180178
> Most of the commands will reject with an error if the device is locked.
181-
> Ensure that the device is unlocked before sending commands. You can check the device session state (`sdk.getDeviceSessionState`) to know if the device is locked.
179+
> Ensure that the device is unlocked before sending commands. You can check the device session state (`dmk.getDeviceSessionState`) to know if the device is locked.
182180
>
183181
> Most of the commands will reject with an error if the response status word is not `0x9000` (success response from the device).
184182
@@ -191,7 +189,7 @@ import { OpenAppCommand } from "@ledgerhq/device-management-kit";
191189

192190
const command = new OpenAppCommand("Bitcoin"); // Open the Bitcoin app
193191

194-
await sdk.sendCommand({ sessionId, command });
192+
await dmk.sendCommand({ sessionId, command });
195193
```
196194

197195
#### Close App
@@ -203,36 +201,36 @@ import { CloseAppCommand } from "@ledgerhq/device-management-kit";
203201

204202
const command = new CloseAppCommand();
205203

206-
await sdk.sendCommand({ sessionId, command });
204+
await dmk.sendCommand({ sessionId, command });
207205
```
208206

209207
#### Get OS Version
210208

211209
This command will return information about the currently installed OS on the device.
212210

213-
> ℹ️ If you want this information you can simply get it from the device session state by observing it with `sdk.getDeviceSessionState({ sessionId })`.
211+
> ℹ️ If you want this information you can simply get it from the device session state by observing it with `dmk.getDeviceSessionState({ sessionId })`.
214212
215213
```ts
216214
import { GetOsVersionCommand } from "@ledgerhq/device-management-kit";
217215

218216
const command = new GetOsVersionCommand();
219217

220218
const { seVersion, mcuSephVersion, mcuBootloaderVersion } =
221-
await sdk.sendCommand({ sessionId, command });
219+
await dmk.sendCommand({ sessionId, command });
222220
```
223221

224222
#### Get App and Version
225223

226224
This command will return the name and version of the currently running app on the device.
227225

228-
> ℹ️ If you want this information you can simply get it from the device session state by observing it with `sdk.getDeviceSessionState({ sessionId })`.
226+
> ℹ️ If you want this information you can simply get it from the device session state by observing it with `dmk.getDeviceSessionState({ sessionId })`.
229227
230228
```ts
231229
import { GetAppAndVersionCommand } from "@ledgerhq/device-management-kit";
232230

233231
const command = new GetAppAndVersionCommand();
234232

235-
const { name, version } = await sdk.sendCommand({ sessionId, command });
233+
const { name, version } = await dmk.sendCommand({ sessionId, command });
236234
```
237235

238236
### Building a Custom Command
@@ -264,7 +262,7 @@ import {
264262

265263
const openAppDeviceAction = new OpenAppDeviceAction({ appName: "Bitcoin" });
266264

267-
const { observable, cancel } = await sdk.executeDeviceAction({
265+
const { observable, cancel } = await dmk.executeDeviceAction({
268266
deviceAction: openAppDeviceAction,
269267
command,
270268
});

packages/transport/web-ble/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Transport Device Kit Web BLE
2+
3+
> [!CAUTION]
4+
> This is still under development and we are free to make new interfaces which may lead to breaking changes.
5+
6+
- [Transport Device Kit Web HID Documentation](#transport-device-kit-web-ble)
7+
- [Description](#description)
8+
- [Installation](#installation)
9+
- [Usage](#usage)
10+
- [Compatibility](#compatibility)
11+
- [Pre-requisites](#pre-requisites)
12+
- [Main Features](#main-features)
13+
- [How To](#how-to)
14+
15+
## Description
16+
17+
This transport is used to interact with a Ledger device through the Web BLE (Bluetooth) implementation.
18+
19+
## Installation
20+
21+
To install the core package, run the following command:
22+
23+
```sh
24+
npm install @ledgerhq/device-transport-kit-web-ble
25+
```
26+
27+
## Usage
28+
29+
### Compatibility
30+
31+
This library works in [any browser supporting the Web Bluetooth API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API#browser_compatibility).
32+
33+
### Pre-requisites
34+
35+
To use this transport, you need to have the DMK installed on your project as well.
36+
37+
### Main Features
38+
39+
- Exposing a transport factory to be injected into the DeviceManagementKit
40+
- Exposing the transport directly for a custom configuration
41+
42+
### How To
43+
44+
To use the transport, you need to inject it in the DeviceManagementKitBuilder before the build. This will allow the DMK to find and interact with devices on the Web BLE protocol.
45+
46+
```typescript
47+
import { DeviceManagementKitBuilder } from "@ledgerhq/device-management-kit"
48+
import { webBleTransportFactory, WebBleTransport } from "@ledgerhq/device-transport-kit-web-ble"
49+
50+
// Easy setup with the factory
51+
const dmk = new DeviceManagementKitBuilder()
52+
.addTransport(webBleTransportFactory)
53+
.build();
54+
55+
56+
// With custom config
57+
const dmk = new DeviceManagementKitBuilder()
58+
.addTransport({
59+
deviceModelDataSource: DeviceModelDataSource;
60+
loggerServiceFactory: (tag: string) => LoggerPublisherService;
61+
config: DmkConfig;
62+
apduSenderServiceFactory: ApduSenderServiceFactory;
63+
apduReceiverServiceFactory: ApduReceiverServiceFactory;
64+
}) => {
65+
// custom code
66+
return new WebBleTransport(
67+
deviceModelDataSource,
68+
loggerServiceFactory,
69+
config,
70+
apduSenderServiceFactory,
71+
apduReceiverServiceFactory,
72+
);
73+
})
74+
.build();
75+
76+
// Youn can then make use of the DMK
77+
```

packages/transport/web-hid/README.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Transport Device Kit Web HID
2+
3+
> [!CAUTION]
4+
> This is still under development and we are free to make new interfaces which may lead to breaking changes.
5+
6+
- [Transport Device Kit Web HID Documentation](#transport-device-kit-web-hid)
7+
- [Description](#description)
8+
- [Installation](#installation)
9+
- [Usage](#usage)
10+
- [Compatibility](#compatibility)
11+
- [Pre-requisites](#pre-requisites)
12+
- [Main Features](#main-features)
13+
- [How To](#how-to)
14+
15+
## Description
16+
17+
This transport is used to interact with a Ledger device through the Web HID (usb) implementation.
18+
19+
## Installation
20+
21+
To install the core package, run the following command:
22+
23+
```sh
24+
npm install @ledgerhq/device-transport-kit-web-hid
25+
```
26+
27+
## Usage
28+
29+
### Compatibility
30+
31+
This library works in [any browser supporting the WebHID API](https://developer.mozilla.org/en-US/docs/Web/API/WebHID_API#browser_compatibility).
32+
33+
### Pre-requisites
34+
35+
To use this transport, you need to have the DMK installed on your project as well.
36+
37+
### Main Features
38+
39+
- Exposing a transport factory to be injected into the DeviceManagementKit
40+
- Exposing the transport directly for a custom configuration
41+
42+
### How To
43+
44+
To use the transport, you need to inject it in the DeviceManagementKitBuilder before the build. This will allow the DMK to find and interact with devices on the Web HID protocol.
45+
46+
```typescript
47+
import { DeviceManagementKitBuilder } from "@ledgerhq/device-management-kit"
48+
import { webHidTransportFactory, WebHidTransport } from "@ledgerhq/device-transport-kit-web-hid"
49+
50+
// Easy setup with the factory
51+
const dmk = new DeviceManagementKitBuilder()
52+
.addTransport(webHidTransportFactory)
53+
.build();
54+
55+
56+
// With custom config
57+
const dmk = new DeviceManagementKitBuilder()
58+
.addTransport({
59+
deviceModelDataSource: DeviceModelDataSource;
60+
loggerServiceFactory: (tag: string) => LoggerPublisherService;
61+
config: DmkConfig;
62+
apduSenderServiceFactory: ApduSenderServiceFactory;
63+
apduReceiverServiceFactory: ApduReceiverServiceFactory;
64+
}) => {
65+
// custom code
66+
return new WebHidTransport(
67+
deviceModelDataSource,
68+
loggerServiceFactory,
69+
config,
70+
apduSenderServiceFactory,
71+
apduReceiverServiceFactory,
72+
);
73+
})
74+
.build();
75+
76+
// Youn can then make use of the DMK
77+
```
78+

0 commit comments

Comments
 (0)