Skip to content

Commit 40bc660

Browse files
committed
📝 (docs): Update docs to reflect latest change in DMK
1 parent 40a001e commit 40bc660

File tree

11 files changed

+163
-33
lines changed

11 files changed

+163
-33
lines changed

apps/docs/pages/docs/beginners/discover_and_connect.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
There are two steps to connecting to a device:
44

5-
- **Discovery**: `sdk.startDiscovering()`
5+
- **Discovery**: `dmk.startDiscovering()`
66
- Returns an observable which will emit a new `DiscoveredDevice` for every scanned device.
77
- The `DiscoveredDevice` objects contain information about the device model.
88
- Use one of these values to connect to a given discovered device.
9-
- **Connection**: `sdk.connect({ deviceId: device.id })`
9+
- **Connection**: `dmk.connect({ deviceId: device.id })`
1010
- Returns a Promise resolving in a device session identifier `DeviceSessionId`.
1111
- **Keep this device session identifier to further interact with the device.**
12-
- Then, `sdk.getConnectedDevice({ sessionId })` returns the `ConnectedDevice`, which contains information about the device model and its name.
12+
- Then, `dmk.getConnectedDevice({ sessionId })` returns the `ConnectedDevice`, which contains information about the device model and its name.
1313

1414
```ts
15-
sdk.startDiscovering().subscribe({
15+
dmk.startDiscovering().subscribe({
1616
next: (device) => {
17-
sdk.connect({ deviceId: device.id }).then((sessionId) => {
18-
const connectedDevice = sdk.getConnectedDevice({ sessionId });
17+
dmk.connect({ deviceId: device.id }).then((sessionId) => {
18+
const connectedDevice = dmk.getConnectedDevice({ sessionId });
1919
});
2020
},
2121
error: (error) => {
@@ -26,8 +26,8 @@ sdk.startDiscovering().subscribe({
2626

2727
Then once a device is connected:
2828

29-
- **Disconnection**: `sdk.disconnect({ sessionId })`
30-
- **Observe the device session state**: `sdk.getDeviceSessionState({ sessionId })`
29+
- **Disconnection**: `dmk.disconnect({ sessionId })`
30+
- **Observe the device session state**: `dmk.getDeviceSessionState({ sessionId })`
3131
- This will return an `Observable<DeviceSessionState>` to listen to the known information about the device:
3232
- device status:
3333
- ready to process a command

apps/docs/pages/docs/beginners/exchange_data.mdx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const apdu = new ApduBuilder(openAppApduArgs)
2929

3030
// ### 2. Sending the APDU
3131

32-
const apduResponse = await sdk.sendApdu({ sessionId, apdu });
32+
const apduResponse = await dmk.sendApdu({ sessionId, apdu });
3333

3434
// ### 3. Parsing the result
3535

@@ -53,7 +53,7 @@ The `sendCommand` method will take care of building the APDU, sending it to the
5353
> ## ❗️ Error Responses
5454
>
5555
> Most of the commands will reject with an error if the device is locked.
56-
> 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.
56+
> 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.
5757
>
5858
> Most of the commands will reject with an error if the response status word is not `0x9000` (success response from the device).
5959
@@ -66,7 +66,7 @@ import { OpenAppCommand } from "@ledgerhq/device-management-kit";
6666

6767
const command = new OpenAppCommand("Bitcoin"); // Open the Bitcoin app
6868

69-
await sdk.sendCommand({ sessionId, command });
69+
await dmk.sendCommand({ sessionId, command });
7070
```
7171

7272
### Close App
@@ -78,36 +78,36 @@ import { CloseAppCommand } from "@ledgerhq/device-management-kit";
7878

7979
const command = new CloseAppCommand();
8080

81-
await sdk.sendCommand({ sessionId, command });
81+
await dmk.sendCommand({ sessionId, command });
8282
```
8383

8484
### Get OS Version
8585

8686
This command will return information about the currently installed OS on the device.
8787

88-
> ℹ️ If you want this information you can simply get it from the device session state by observing it with `sdk.getDeviceSessionState({ sessionId })`.
88+
> ℹ️ If you want this information you can simply get it from the device session state by observing it with `dmk.getDeviceSessionState({ sessionId })`.
8989
9090
```ts
9191
import { GetOsVersionCommand } from "@ledgerhq/device-management-kit";
9292

9393
const command = new GetOsVersionCommand();
9494

9595
const { seVersion, mcuSephVersion, mcuBootloaderVersion } =
96-
await sdk.sendCommand({ sessionId, command });
96+
await dmk.sendCommand({ sessionId, command });
9797
```
9898

9999
### Get App and Version
100100

101101
This command will return the name and version of the currently running app on the device.
102102

103-
> ℹ️ If you want this information you can simply get it from the device session state by observing it with `sdk.getDeviceSessionState({ sessionId })`.
103+
> ℹ️ If you want this information you can simply get it from the device session state by observing it with `dmk.getDeviceSessionState({ sessionId })`.
104104
105105
```ts
106106
import { GetAppAndVersionCommand } from "@ledgerhq/device-management-kit";
107107

108108
const command = new GetAppAndVersionCommand();
109109

110-
const { name, version } = await sdk.sendCommand({ sessionId, command });
110+
const { name, version } = await dmk.sendCommand({ sessionId, command });
111111
```
112112

113113
## Sending a Pre-defined flow - Device Actions
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
1-
# Setting up the SDK
1+
# Setting up the DMK
22

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

5-
For now it allows you to add one or more custom loggers.
5+
For now it allows you to add one or more custom loggers and transports.
66

7-
In the following example, we add a console logger (`.addLogger(new ConsoleLogger())`). Then we build the SDK with `.build()`.
7+
In the following example, we add a console logger (`.addLogger(new ConsoleLogger())`), then the WebHID transport (`.addTransport(webHidTransportFactory)`).
8+
Then we build the DMK with `.build()`.
89

9-
**The returned object will be the entrypoint for all your interactions with the SDK. You should keep it as a <u>SINGLETON</u>.**
10+
**The returned object will be the entrypoint for all your interactions with the DMK. You should keep it as a <u>SINGLETON</u>.**
1011

11-
The SDK should be built only once in your application runtime so keep a reference of this object somewhere.
12+
The DMK should be built only once in your application runtime so keep a reference of this object somewhere.
1213

1314
```ts
1415
import {
1516
ConsoleLogger,
16-
DeviceSdk,
17-
DeviceSdkBuilder,
17+
DeviceManagementKitBuilder,
1818
} from "@ledgerhq/device-management-kit";
19+
import { webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid";
1920

20-
export const sdk = new DeviceSdkBuilder()
21+
export const dmk = new DeviceManagementKitBuilder()
2122
.addLogger(new ConsoleLogger())
23+
.addTransport(webHidTransportFactory)
2224
.build();
2325
```

apps/docs/pages/docs/beginners/setup.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ This library works in [any browser supporting the WebHID API](https://developer.
2020

2121
### Pre-requisites
2222

23-
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.
23+
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 the DMK. You can refer to [RxJS documentation](https://rxjs.dev/guide/overview) for more information.

apps/docs/pages/docs/docs.mdx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ Throughout all the documentation we will use several acronyms that you can find
2727

2828
Here you can found a summary of all the libraries that are composing the DMK
2929

30-
| Library | NPM | Version |
31-
| ---------------------- | ---------------------------------------------------------------------------------------------------------- | ------- |
32-
| Device Management Kit | [@LedgerHQ/device-mangement-kit](https://www.npmjs.com/package/@ledgerhq/device-management-kit) | 0.4.0 |
33-
| Device Signer Ethereum | [@LedgerHQ/device-signer-kit-ethereum](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-ethereum) | 1.0.0 |
34-
| Context Module | [@LedgerHQ/context-module](https://www.npmjs.com/package/@ledgerhq/context-module) | 1.0.0 |
30+
| Library | NPM | Version |
31+
| ---------------------- | -------------------------------------------------------------------------------------------------------------- | ------- |
32+
| Device Management Kit | [@LedgerHQ/device-mangement-kit](https://www.npmjs.com/package/@ledgerhq/device-management-kit) | 0.6.0 |
33+
| Device Signer Ethereum | [@LedgerHQ/device-signer-kit-ethereum](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-ethereum) | 1.2.0 |
34+
| WebHidTransport | [@ledgerhq/device-transport-kit-web-hid](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-hid) | 1.0.0 |
35+
| WebBleTransport | [@ledgerhq/device-transport-kit-web-ble](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-ble) | 1.0.0 |

apps/docs/pages/docs/explanations/_meta.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ export default {
33
ledgerjs: "Differences with LedgerJS",
44
dmk: "Device Management Kit",
55
signers: "Signer kits",
6+
transports: "Transports",
67
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Transport Kits
2+
3+
Different transports are available to connect to Ledger devices.
4+
5+
Each transport is available in its own package and targets only a specific plaftorm and protocol.
6+
7+
## Available transports
8+
9+
- [WebHID](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-hid)
10+
- [WebBLE](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-ble)
11+
12+
## How to use a transport
13+
14+
- [Transports](./transports/transports)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default {
2+
transports: "Transports",
3+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Transports
2+
3+
The Device Management Kit is offering several transports to communicate with a Ledger device.
4+
Depending on the environment and usecase, you can choose the transport that best suits your needs.
5+
6+
## Available transports
7+
8+
| Transport | Description |
9+
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
10+
| [WebHid](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-hid) | The WebHID transport is a transport that uses the WebHID API (usb) to communicate with a Ledger device. |
11+
| [WebBle](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-ble) | The WebBLE transport is a transport that uses the WebBLE API (bluetooth) to communicate with a Ledger device. |
12+
13+
### WebBLE
14+
15+
The WebBLE transport is a transport that uses the WebBLE API (bluetooth) to communicate with a Ledger device.
16+
17+
## How to use a transport
18+
19+
Transports are injected in the DeviceManagementKitBuilder before building the DeviceManagementKit instance.
20+
This is done by calling the `addTransport` method on the builder.
21+
You can inject the transport in two different ways:
22+
23+
- Using the default transport factory provided by the package
24+
- Using directly the transport creating your own factory (for custom transports or additional configuration...)
25+
26+
```typescript
27+
import { DeviceManagementKitBuilder } from "@ledgerhq/device-management-kit";
28+
import { WebHidTransport, webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid";
29+
30+
// Using the default transport factory
31+
const dmk = new DeviceManagementKitBuilder()
32+
.addTransport(webHidTransportFactory)
33+
.build();
34+
35+
// Using the transport directly
36+
const dmk = new DeviceManagementKitBuilder()
37+
.addTransport(({
38+
deviceModelDataSource: DeviceModelDataSource;
39+
loggerServiceFactory: (tag: string) => LoggerPublisherService;
40+
config: DmkConfig;
41+
apduSenderServiceFactory: ApduSenderServiceFactory;
42+
apduReceiverServiceFactory: ApduReceiverServiceFactory;
43+
}) => {
44+
// Some extra code here to configure the transport
45+
// Then we return the transport instance
46+
return new WebHidTransport({
47+
deviceModelDataSource,
48+
loggerServiceFactory,
49+
config,
50+
apduSenderServiceFactory,
51+
apduReceiverServiceFactory,
52+
});
53+
})
54+
.build();
55+
```

apps/docs/pages/docs/integration_walkthroughs/how_to/how_to_use_a_signer.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ To initialize an Ethereum signer instance, you need a Ledger Device Management K
1919

2020
```typescript
2121
// Initialize an Ethereum signer instance using default context module
22-
const signerEth = new SignerEthBuilder({ sdk, sessionId }).build();
22+
const signerEth = new SignerEthBuilder({ dmk, sessionId }).build();
2323
```
2424

2525
You can also configure the context module yourself:
2626

2727
```typescript
2828
// Initialize an Ethereum signer instance using customized context module
29-
const signerEth = new SignerEthBuilder({ sdk, sessionId })
29+
const signerEth = new SignerEthBuilder({ dmk, sessionId })
3030
.withContextModule(customContextModule)
3131
.build();
3232
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Migration from 0.5.0 to 0.6.0
2+
3+
We made some breaking changes to the Device Management Kit in 0.6 which are detailed below.
4+
5+
## Transports
6+
7+
The transports implementation have been moved to their own packages.
8+
9+
- `@ledgerhq/device-transport-kit-web-hid`
10+
- `@ledgerhq/device-transport-kit-web-ble`
11+
12+
To use a transport, you need to install the corresponding package and inject it in the DeviceManagementKit.
13+
14+
**0.5**
15+
16+
Transports were built-in the DeviceManagementKit.
17+
18+
```typescript
19+
import {
20+
DeviceManagementKitBuilder,
21+
ConsoleLogger,
22+
} from "@ledgerhq/device-management-kit";
23+
24+
const dmk = new DeviceManagementKitBuilder()
25+
.addLogger(new ConsoleLogger())
26+
.build();
27+
```
28+
29+
**0.6**
30+
31+
In 0.6, you need to manually inject the transport you want to use.
32+
33+
```typescript
34+
import {
35+
DeviceManagementKitBuilder,
36+
ConsoleLogger,
37+
} from "@ledgerhq/device-management-kit";
38+
import { webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid";
39+
40+
const dmk = new DeviceManagementKitBuilder()
41+
.addLogger(new ConsoleLogger())
42+
.addTransport(webHidTransportFactory)
43+
.build();
44+
```
45+
46+
```diff
47+
import { DeviceManagementKitBuilder, ConsoleLogger } from "@ledgerhq/device-management-kit";
48+
+ import { webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid";
49+
50+
const dmk = new DeviceManagementKitBuilder()
51+
.addLogger(new ConsoleLogger())
52+
+ .addTransport(webHidTransportFactory)
53+
.build();
54+
```

0 commit comments

Comments
 (0)