Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .changeset/brave-bags-yell.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/cold-garlics-suffer.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/dull-crabs-teach.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/gold-needles-sell.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/grumpy-olives-shave.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/honest-ties-dream.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/quick-timers-sneeze.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/soft-humans-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/device-management-kit": patch
---

Allow to send an apdu with expected disconnection
5 changes: 0 additions & 5 deletions .changeset/violet-llamas-adder.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/violet-llamas-addestest.md

This file was deleted.

6 changes: 3 additions & 3 deletions apps/docs/pages/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ Here you can found a summary of all the libraries that are composing the DMK
| ---------------------- | -------------------------------------------------------------------------------------------------------------- | ------- |
| Device Management Kit | [@LedgerHQ/device-mangement-kit](https://www.npmjs.com/package/@ledgerhq/device-management-kit) | 0.7.0 |
| Device Signer Ethereum | [@LedgerHQ/device-signer-kit-ethereum](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-ethereum) | 1.4.0 |
| Device Signer Bitcoin | [@LedgerHQ/device-signer-kit-bitcoin](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-bitcoin) | 1.0.0 |
| Device Signer Solana | [@LedgerHQ/device-signer-kit-solana](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-solana) | 1.1.0 |
| Context Module | [@ledgerhq/context-module](https://www.npmjs.com/package/@ledgerhq/context-module) | 1.4.0 |
| Device Signer Bitcoin | [@LedgerHQ/device-signer-kit-bitcoin](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-bitcoin) | 1.0.1 |
| Device Signer Solana | [@LedgerHQ/device-signer-kit-solana](https://www.npmjs.com/package/@ledgerhq/device-signer-kit-solana) | 1.1.1 |
| Context Module | [@ledgerhq/context-module](https://www.npmjs.com/package/@ledgerhq/context-module) | 1.5.0 |
| WebHidTransport | [@ledgerhq/device-transport-kit-web-hid](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-hid) | 1.1.0 |
| WebBleTransport | [@ledgerhq/device-transport-kit-web-ble](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-web-ble) | 1.1.0 |
| RnBleTransport | [@ledgerhq/device-transport-kit-rn-ble](https://www.npmjs.com/package/@ledgerhq/device-transport-kit-rn-ble) | 1.0.0 |
53 changes: 53 additions & 0 deletions apps/docs/pages/docs/references/signers/eth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,59 @@ type Signature = {

- `cancel` A function to cancel the action on the Ledger device.

### Use Case 5: Sign Delegation Authorization (EIP-7702)

This method enables users to sign a delegation authorization message following the [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) specification.

```typescript
const { observable, cancel } = signerEth.signDelegationAuthorization(
derivationPath,
chainId,
contractAddress,
nonce,
);
```

#### **Parameters**

- `derivationPath`

- **Required**
- **Type:** `string` (e.g., `"44'/60'/0'/0/0"`)
- The derivation path used by the Ethereum message. See [here](https://www.ledger.com/blog/understanding-crypto-addresses-and-derivation-paths) for more information.

- `chainId`

- **Required**
- **Type:** `number`
- The chain ID of the Ethereum network.

- `contractAddress`

- **Required**
- **Type:** `string`
- The address of the contract to be authorized.

- `nonce`

- **Required**
- **Type:** `number`
- The nonce of the transaction.

#### **Returns**

- `observable` Emits DeviceActionState updates, including the following details:

```typescript
type Signature = {
r: `0x${string}`; // R component of the signature
s: `0x${string}`; // S component of the signature
v: number; // Recovery parameter
};
```

- `cancel` A function to cancel the action on the Ledger device.

## πŸ”Ή Observable Behavior

Each method returns an [Observable](https://rxjs.dev/guide/observable) emitting updates structured as [`DeviceActionState`](https://github.com/LedgerHQ/device-sdk-ts/blob/develop/packages/device-management-kit/src/api/device-action/model/DeviceActionState.ts). These updates reflect the operation’s progress and status:
Expand Down
41 changes: 41 additions & 0 deletions apps/sample/src/components/SignerEthView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import {
type GetAddressDAError,
type GetAddressDAIntermediateValue,
type GetAddressDAOutput,
type SignDelegationAuthorizationDAError,
type SignDelegationAuthorizationDAIntermediateValue,
type SignDelegationAuthorizationDAOutput,
type SignPersonalMessageDAError,
type SignPersonalMessageDAIntermediateValue,
type SignPersonalMessageDAOutput,
Expand Down Expand Up @@ -205,6 +208,44 @@ export const SignerEthView: React.FC<{ sessionId: string }> = ({
SignTypedDataDAError,
SignTypedDataDAIntermediateValue
>,
{
title: "Sign Delegation Authorization",
description:
"Perform all the actions necessary to sign an EIP 7702 Delegation Authorization with the device",
executeDeviceAction: ({
derivationPath,
nonce,
contractAddress,
chainId,
}) => {
if (!signer) {
throw new Error("Signer not initialized");
}
return signer.signDelegationAuthorization(
derivationPath,
chainId,
contractAddress,
nonce,
);
},
initialValues: {
derivationPath: "44'/60'/0'/0/0",
nonce: 0,
contractAddress: "0x",
chainId: 1,
},
deviceModelId,
} satisfies DeviceActionProps<
SignDelegationAuthorizationDAOutput,
{
derivationPath: string;
nonce: number;
contractAddress: string;
chainId: number;
},
SignDelegationAuthorizationDAError,
SignDelegationAuthorizationDAIntermediateValue
>,
],
[deviceModelId, signer],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,35 @@ describe("ByteArrayBuilder", () => {
expect(builder.getErrors()).toEqual([]);
});

it("should serialize with an TLV encoded from an hexastring", () => {
builder.encodeInTLVFromHexa(0x05, "0xA1A2A3");
expect(builder.build()).toEqual(
Uint8Array.from([0x05, 0x03, 0xa1, 0xa2, 0xa3]),
);
expect(builder.getErrors()).toEqual([]);
});

it("should serialize with an TLV encoded from a buffer", () => {
builder.encodeInTLVFromBuffer(
0x06,
Uint8Array.from([0xa1, 0xa2, 0xa3, 0xa4]),
);
expect(builder.build()).toEqual(
Uint8Array.from([0x06, 0x04, 0xa1, 0xa2, 0xa3, 0xa4]),
);
expect(builder.getErrors()).toEqual([]);
});

it("should serialize with an TLV encoded from an uint64", () => {
builder.encodeInTLVFromUInt64(0x06, 0x567890123456);
expect(builder.build()).toEqual(
Uint8Array.from([
0x06, 0x08, 0x00, 0x00, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,
]),
);
expect(builder.getErrors()).toEqual([]);
});

it("should serialize with an complete body of 0xAA", () => {
const myarray = new Uint8Array(255).fill(0xaa, 0, 255);
builder.addBufferToData(myarray);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,54 @@ export class ByteArrayBuilder {
return this;
};

/**
* Add a Tag-Length-Value encoded hexadecimal string to the data field if it has enough remaining space
* Length-Value encoding is a way to encode data in a binary format with the first byte
* being the length of the data and the following bytes being the data itself
* @param tag: number - The tag to add to the data
* @param value: string - The value to add to the data
* @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder
*/
encodeInTLVFromHexa = (tag: number, value: string): ByteArrayBuilder => {
this.add8BitUIntToData(tag);
return this.encodeInLVFromHexa(value);
};

/**
* Add a Tag-Length-Value encoded hexadecimal string to the data field if it has enough remaining space
* Length-Value encoding is a way to encode data in a binary format with the first byte
* being the length of the data and the following bytes being the data itself
* @param tag: number - The tag to add to the data
* @param value: Uint8Array - The buffer to add to the data
* @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder
*/
encodeInTLVFromBuffer = (
tag: number,
value: Uint8Array,
): ByteArrayBuilder => {
this.add8BitUIntToData(tag);
return this.encodeInLVFromBuffer(value);
};

/**
* Add a Tag-Length-Value encoded uint64 to the data field if it has enough remaining space
* Length-Value encoding is a way to encode data in a binary format with the first byte
* being the length of the data and the following bytes being the data itself
* @param tag: number - The tag to add to the data
* @param value: number | bigint - The number to add
* @param bigEndian: boolean - Endianness used to encode the number
* @returns {ByteArrayBuilder} - Returns the current instance of ByteArrayBuilder
*/
encodeInTLVFromUInt64 = (
tag: number,
value: number | bigint,
bigEndian: boolean = true,
): ByteArrayBuilder => {
this.add8BitUIntToData(tag);
this.add8BitUIntToData(8);
return this.add64BitUIntToData(value, bigEndian);
};

/**
* Returns the remaining payload length
* @returns {number}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export enum UserInteractionRequired {
AllowListApps = "allow-list-apps",
VerifyAddress = "verify-address",
SignPersonalMessage = "sign-personal-message",
SignDelegationAuthorization = "sign-delegation-authorization",
Web3ChecksOptIn = "web3-checks-opt-in",
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export type SendApduUseCaseArgs = {
* The time, in milliseconds, to wait before aborting an operation.
*/
abortTimeout?: number;
/**
* Indicates if a device disconnection should be expected after sending the APDU.
*/
triggersDisconnection?: boolean;
};

/**
Expand All @@ -47,14 +51,18 @@ export class SendApduUseCase {
sessionId,
apdu,
abortTimeout,
triggersDisconnection,
}: SendApduUseCaseArgs): Promise<ApduResponse> {
const deviceSessionOrError =
this._sessionService.getDeviceSessionById(sessionId);

return deviceSessionOrError.caseOf({
// Case device session found
Right: async (deviceSession) => {
const response = await deviceSession.sendApdu(apdu, { abortTimeout });
const response = await deviceSession.sendApdu(apdu, {
abortTimeout,
triggersDisconnection,
});
return response.caseOf({
// Case APDU sent and response received successfully
Right: (data) => data,
Expand Down
12 changes: 12 additions & 0 deletions packages/signer/signer-btc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @ledgerhq/device-signer-kit-bitcoin

## 1.0.1

### Patch Changes

- [#828](https://github.com/LedgerHQ/device-sdk-ts/pull/828) [`5395aca`](https://github.com/LedgerHQ/device-sdk-ts/commit/5395acac34dfc7ab5b3223af09e99d6f7989e7cc) Thanks [@paoun-ledger](https://github.com/paoun-ledger)! - Allow to skip opening the application

- [#649](https://github.com/LedgerHQ/device-sdk-ts/pull/649) [`1364525`](https://github.com/LedgerHQ/device-sdk-ts/commit/1364525e1092b69700e83819d00df1222dc32dc1) Thanks [@paoun-ledger](https://github.com/paoun-ledger)! - Factorize device actions calling a task in an app

- [#663](https://github.com/LedgerHQ/device-sdk-ts/pull/663) [`5c4a2d6`](https://github.com/LedgerHQ/device-sdk-ts/commit/5c4a2d624a4196f62051514ec211dca4c618023e) Thanks [@jiyuzhuang](https://github.com/jiyuzhuang)! - Add sendApdu in internal API interface

- [#700](https://github.com/LedgerHQ/device-sdk-ts/pull/700) [`61b17b3`](https://github.com/LedgerHQ/device-sdk-ts/commit/61b17b3df1946b0f3f9370d7bacc243fdfd7880c) Thanks [@valpinkman](https://github.com/valpinkman)! - Update internalApi interface

## 1.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/signer/signer-btc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ledgerhq/device-signer-kit-bitcoin",
"version": "1.0.0",
"version": "1.0.1",
"license": "Apache-2.0",
"main": "lib/cjs/index.js",
"types": "lib/cjs/index.d.ts",
Expand Down
10 changes: 10 additions & 0 deletions packages/signer/signer-eth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @ledgerhq/device-signer-kit-ethereum

## 1.5.0

### Minor Changes

- [#835](https://github.com/LedgerHQ/device-sdk-ts/pull/835) [`a41b9d1`](https://github.com/LedgerHQ/device-sdk-ts/commit/a41b9d1f7f357f55bc21e2951f9d7ef2adb13535) Thanks [@paoun-ledger](https://github.com/paoun-ledger)! - Add new API for EIP7702 in signer kit ETH

### Patch Changes

- [#854](https://github.com/LedgerHQ/device-sdk-ts/pull/854) [`ca84a7e`](https://github.com/LedgerHQ/device-sdk-ts/commit/ca84a7ee07eb3d709058ca92fae60b352b1aa981) Thanks [@paoun-ledger](https://github.com/paoun-ledger)! - GetChallenge is not supported on Nano S

## 1.4.0

### Minor Changes
Expand Down
Loading
Loading