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 | The WebHID transport uses the Web HID API (usb) to communicate with a Ledger device. |
WebBle | The WebBLE transport uses the Web BLE API (bluetooth) to communicate with a Ledger device. |
RNBle | The React Native BLE transport uses the react-native-ble-plx (bluetooth) to communicate with a Ledger device. |
Speculos | The Speculos transport is used to communicate with the speculos device simulator. |
How to use a transport
Transports are injected in the DeviceManagementKitBuilder before building the Device Management Kit 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…)
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();
How to use the Speculos transport
The Speculos transport is used to communicate with the speculos device simulator.
The factory function accepts a speculosUrl
parameter that is the url of the speculos server.
const dmk = new DeviceManagementKitBuilder()
.addTransport(speculosTransportFactory("http://localhost:5000"))
.build();