-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 (docs) [NO-ISSUE]: Update docs to reflect latest change in DMK (#629)
- Loading branch information
Showing
17 changed files
with
207 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default { | ||
transports: "Transports", | ||
}; |
55 changes: 55 additions & 0 deletions
55
apps/docs/pages/docs/explanations/transports/transports.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
apps/docs/pages/docs/migrations/signer-eth/1_1_0_to_1_2_0.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
}; |