Skip to content

Commit

Permalink
📝 (docs) [NO-ISSUE]: Update docs to reflect latest change in DMK (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
valpinkman authored Jan 27, 2025
2 parents ffaae72 + 778ee57 commit c433523
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 41 deletions.
16 changes: 8 additions & 8 deletions apps/docs/pages/docs/beginners/discover_and_connect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

There are two steps to connecting to a device:

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

```ts
sdk.startDiscovering().subscribe({
dmk.startDiscovering().subscribe({
next: (device) => {
sdk.connect({ deviceId: device.id }).then((sessionId) => {
const connectedDevice = sdk.getConnectedDevice({ sessionId });
dmk.connect({ deviceId: device.id }).then((sessionId) => {
const connectedDevice = dmk.getConnectedDevice({ sessionId });
});
},
error: (error) => {
Expand All @@ -26,8 +26,8 @@ sdk.startDiscovering().subscribe({

Then once a device is connected:

- **Disconnection**: `sdk.disconnect({ sessionId })`
- **Observe the device session state**: `sdk.getDeviceSessionState({ sessionId })`
- **Disconnection**: `dmk.disconnect({ sessionId })`
- **Observe the device session state**: `dmk.getDeviceSessionState({ sessionId })`
- This will return an `Observable<DeviceSessionState>` to listen to the known information about the device:
- device status:
- ready to process a command
Expand Down
16 changes: 8 additions & 8 deletions apps/docs/pages/docs/beginners/exchange_data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const apdu = new ApduBuilder(openAppApduArgs)

// ### 2. Sending the APDU

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

// ### 3. Parsing the result

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

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

await sdk.sendCommand({ sessionId, command });
await dmk.sendCommand({ sessionId, command });
```

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

const command = new CloseAppCommand();

await sdk.sendCommand({ sessionId, command });
await dmk.sendCommand({ sessionId, command });
```

### Get OS Version

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

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

const command = new GetOsVersionCommand();

const { seVersion, mcuSephVersion, mcuBootloaderVersion } =
await sdk.sendCommand({ sessionId, command });
await dmk.sendCommand({ sessionId, command });
```

### Get App and Version

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

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

const command = new GetAppAndVersionCommand();

const { name, version } = await sdk.sendCommand({ sessionId, command });
const { name, version } = await dmk.sendCommand({ sessionId, command });
```

## Sending a Pre-defined flow - Device Actions
Expand Down
20 changes: 11 additions & 9 deletions apps/docs/pages/docs/beginners/init_dmk.mdx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# Setting up the SDK
# Setting up the DMK

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

For now it allows you to add one or more custom loggers.
For now it allows you to add one or more custom loggers and transports.

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

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

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

```ts
import {
ConsoleLogger,
DeviceSdk,
DeviceSdkBuilder,
DeviceManagementKitBuilder,
} from "@ledgerhq/device-management-kit";
import { webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid";

export const sdk = new DeviceSdkBuilder()
export const dmk = new DeviceManagementKitBuilder()
.addLogger(new ConsoleLogger())
.addTransport(webHidTransportFactory)
.build();
```
2 changes: 1 addition & 1 deletion apps/docs/pages/docs/beginners/setup.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ This library works in [any browser supporting the WebHID API](https://developer.

### Pre-requisites

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.
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.
11 changes: 6 additions & 5 deletions apps/docs/pages/docs/docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ Throughout all the documentation we will use several acronyms that you can find

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

| Library | NPM | Version |
| ---------------------- | ---------------------------------------------------------------------------------------------------------- | ------- |
| Device Management Kit | [@LedgerHQ/device-mangement-kit](https://www.npmjs.com/package/@ledgerhq/device-management-kit) | 0.4.0 |
| Device Signer Ethereum | [@LedgerHQ/device-signer-kit-ethereum](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-ethereum) | 1.0.0 |
| Context Module | [@LedgerHQ/context-module](https://www.npmjs.com/package/@ledgerhq/context-module) | 1.0.0 |
| Library | NPM | Version |
| ---------------------- | -------------------------------------------------------------------------------------------------------------- | ------- |
| Device Management Kit | [@LedgerHQ/device-mangement-kit](https://www.npmjs.com/package/@ledgerhq/device-management-kit) | 0.6.0 |
| Device Signer Ethereum | [@LedgerHQ/device-signer-kit-ethereum](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-ethereum) | 1.2.0 |
| WebHidTransport | [@ledgerhq/device-transport-kit-web-hid](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-hid) | 1.0.0 |
| WebBleTransport | [@ledgerhq/device-transport-kit-web-ble](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-ble) | 1.0.0 |
1 change: 1 addition & 0 deletions apps/docs/pages/docs/explanations/_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export default {
ledgerjs: "Differences with LedgerJS",
dmk: "Device Management Kit",
signers: "Signer kits",
transports: "Transports",
};
14 changes: 14 additions & 0 deletions apps/docs/pages/docs/explanations/transports.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Transport Kits

Different transports are available to connect to Ledger devices.

Each transport is available in its own package and targets only a specific plaftorm and protocol.

## Available transports

- [WebHID](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-hid)
- [WebBLE](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-ble)

## How to use a transport

- [Transports](./transports/transports)
3 changes: 3 additions & 0 deletions apps/docs/pages/docs/explanations/transports/_meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
transports: "Transports",
};
55 changes: 55 additions & 0 deletions apps/docs/pages/docs/explanations/transports/transports.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Transports

The Device Management Kit is offering several transports to communicate with a Ledger device.
Depending on the environment and usecase, you can choose the transport that best suits your needs.

## Available transports

| Transport | Description |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
| [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. |
| [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. |

### WebBLE

The WebBLE transport is a transport that uses the WebBLE API (bluetooth) to communicate with a Ledger device.

## How to use a transport

Transports are injected in the DeviceManagementKitBuilder before building the DeviceManagementKit instance.
This is done by calling the `addTransport` method on the builder.
You can inject the transport in two different ways:

- Using the default transport factory provided by the package
- Using directly the transport creating your own factory (for custom transports or additional configuration...)

```typescript
import { DeviceManagementKitBuilder } from "@ledgerhq/device-management-kit";
import { WebHidTransport, webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid";

// Using the default transport factory
const dmk = new DeviceManagementKitBuilder()
.addTransport(webHidTransportFactory)
.build();

// Using the transport directly
const dmk = new DeviceManagementKitBuilder()
.addTransport(({
deviceModelDataSource: DeviceModelDataSource;
loggerServiceFactory: (tag: string) => LoggerPublisherService;
config: DmkConfig;
apduSenderServiceFactory: ApduSenderServiceFactory;
apduReceiverServiceFactory: ApduReceiverServiceFactory;
}) => {
// Some extra code here to configure the transport
// Then we return the transport instance
return new WebHidTransport(
deviceModelDataSource,
loggerServiceFactory,
config,
apduSenderServiceFactory,
apduReceiverServiceFactory,
);
})
.build();
```
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ To initialize an Ethereum signer instance, you need a Ledger Device Management K

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

You can also configure the context module yourself:

```typescript
// Initialize an Ethereum signer instance using customized context module
const signerEth = new SignerEthBuilder({ sdk, sessionId })
const signerEth = new SignerEthBuilder({ dmk, sessionId })
.withContextModule(customContextModule)
.build();
```
4 changes: 2 additions & 2 deletions apps/docs/pages/docs/migrations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Find below all the migrations guide available:

## Device Management Kit

- migration from [v0.4.0 to v0.5.0](./migrations/04_to_05/)
- migration from [v0.4.0 to v0.5.0](./migrations/dmk/04_to_05/)

## Device Signer Kit - Ethereum

_coming soon_
- migration from [v1.1.0 to v1.2.0](./migrations/signer-eth/1_1_0_to_1_2_0/)
3 changes: 0 additions & 3 deletions apps/docs/pages/docs/migrations/04_to_05.mdx

This file was deleted.

3 changes: 0 additions & 3 deletions apps/docs/pages/docs/migrations/_meta.js

This file was deleted.

54 changes: 54 additions & 0 deletions apps/docs/pages/docs/migrations/dmk/05_to_06.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Migration from 0.5.0 to 0.6.0

We made some breaking changes to the Device Management Kit in 0.6 which are detailed below.

## Transports

The transports implementation have been moved to their own packages.

- `@ledgerhq/device-transport-kit-web-hid`
- `@ledgerhq/device-transport-kit-web-ble`

To use a transport, you need to install the corresponding package and inject it in the DeviceManagementKit.

**0.5**

Transports were built-in the DeviceManagementKit.

```typescript
import {
DeviceManagementKitBuilder,
ConsoleLogger,
} from "@ledgerhq/device-management-kit";

const dmk = new DeviceManagementKitBuilder()
.addLogger(new ConsoleLogger())
.build();
```

**0.6**

In 0.6, you need to manually inject the transport you want to use.

```typescript
import {
DeviceManagementKitBuilder,
ConsoleLogger,
} from "@ledgerhq/device-management-kit";
import { webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid";

const dmk = new DeviceManagementKitBuilder()
.addLogger(new ConsoleLogger())
.addTransport(webHidTransportFactory)
.build();
```

```diff
import { DeviceManagementKitBuilder, ConsoleLogger } from "@ledgerhq/device-management-kit";
+ import { webHidTransportFactory } from "@ledgerhq/device-transport-kit-web-hid";

const dmk = new DeviceManagementKitBuilder()
.addLogger(new ConsoleLogger())
+ .addTransport(webHidTransportFactory)
.build();
```
3 changes: 3 additions & 0 deletions apps/docs/pages/docs/migrations/dmk/_meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
"05_to_06": "DMK: Migrate from v0.5.0 to 0.6.0",
};
36 changes: 36 additions & 0 deletions apps/docs/pages/docs/migrations/signer-eth/1_1_0_to_1_2_0.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Migration from 0.5.0 to 0.6.0

We made some breaking changes to the Ethereum Signer in 1.2.0 which are detailed below.

## signTransaction

The transaction type has been changed to `Uint8Array` instead of `Transaction` from ethers `v5` or `v6`.

To sign a transaction, you need to serialize it to a `Uint8Array` before calling `signTransaction`.

### From a `string`

You can use the `hexaStringToBuffer` utility from the DeviceManagementKit to convert a hexa string to a `Uint8Array`.

```typescript
const rawTx = hexaStringToBuffer(tx);
if (!rawTx) {
throw new Error("Invalid transaction format");
}

signer.signTransaction(derivationPath, rawTx, { domain });
```

### From a `Transaction` object from ethers `v6`

You can use the `unsignedSerialized` property from the `Transaction` object
combined with the `hexaStringToBuffer` utility from the DeviceManagementKit to convert a hexa string to a `Uint8Array`.

```typescript
const rawTx = hexaStringToBuffer(tx.unsignedSerialized);
if (!rawTx) {
throw new Error("Invalid transaction format");
}

signer.signTransaction(derivationPath, rawTx, { domain });
```
3 changes: 3 additions & 0 deletions apps/docs/pages/docs/migrations/signer-eth/_meta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
"1_1_0_to_1_2_0": "Signer ETH: Migrate from v1.1.0 to 1.2.0",
};

0 comments on commit c433523

Please sign in to comment.