Skip to content

✨ (signer-polkadot) [LIVE-30995]: Implement APDU commands for the Polkadot signer#1530

Open
cted-ledger wants to merge 4 commits into
developfrom
feat/LIVE-30995-implement-apdu-polkadot-signer
Open

✨ (signer-polkadot) [LIVE-30995]: Implement APDU commands for the Polkadot signer#1530
cted-ledger wants to merge 4 commits into
developfrom
feat/LIVE-30995-implement-apdu-polkadot-signer

Conversation

@cted-ledger

@cted-ledger cted-ledger commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

📝 Description

Implement the full APDU command layer for the signer-polkadot DMK signer kit. The signer is generic across the Polkadot family (Polkadot, Westend, AssetHub, Bittensor, …) — chains differ only by the SS58 prefix parameter and the derivation path. Bittensor is the driving integration.

Commands implemented:

  • GetAddressCommand — derives the address with a configurable SS58 prefix (0 = Polkadot, 42 = Bittensor) and optional on-device confirmation
  • SignTransactionCommand — multi-chunk protocol (INIT/ADD/LAST) for signing transaction blobs, with the derivation path and blob length sent in the initial chunk
  • SignTransactionTask — orchestrates blob+metadata chunking into sequential APDU calls, respecting the 255-byte payload limit

Supporting utilities:

  • EncodeDerivationPath — encodes a hardened BIP44 path into the little-endian binary layout expected by the device app
  • polkadotApplicationErrors — maps device status words to typed error codes
  • Constants module with the app-wide CLA (INS/P2 live in their respective commands)

❓ Context

  • JIRA or GitHub link: LIVE-30995
  • Feature: Polkadot-family signer kit (APDU layer) — driven by the Bittensor integration

Depends on #1501 (scaffold, merged).

✅ Checklist

  • Covered by automatic tests — unit tests across the command, task, use-case and signer layers (GetAddress/SignTransaction commands, SignTransactionTask, EncodeDerivationPath, application errors, GetAddressUseCase, DefaultSignerPolkadot, builder)
  • Changeset is provided
  • Documentation is up-to-date
  • Impact of the changes:
    • New APDU commands in @ledgerhq/device-signer-kit-polkadot
    • No impact on existing packages — all changes scoped to signer-polkadot
    • Multi-chunk signing protocol for large Substrate extrinsics

Copilot AI review requested due to automatic review settings June 2, 2026 16:36
@cted-ledger
cted-ledger requested a review from a team as a code owner June 2, 2026 16:36
@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
device-sdk-ts-sample Ready Ready Preview, Comment Jul 8, 2026 8:27am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
doc-device-management-kit Ignored Ignored Jul 8, 2026 8:27am

Request Review

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Danger Check Results

Messages

Danger: All checks passed successfully! 🎉

Generated by 🚫 dangerJS against df12d8d

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements the Polkadot/Bittensor signer-kit APDU command layer in @ledgerhq/device-signer-kit-polkadot, including address derivation (SS58 prefix) and multi-APDU transaction signing orchestration.

Changes:

  • Added concrete APDU implementations for GetAddressCommand and SignTransactionCommand (INIT/ADD/LAST) plus SignTransactionTask chunking logic.
  • Introduced Polkadot app error mapping + derivation-path binary encoding utility.
  • Wired logger factory into the package DI and app-binder, and added comprehensive Vitest coverage + changeset.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/signer/signer-polkadot/src/internal/externalTypes.ts Adds DI token for DMK logger factory.
packages/signer/signer-polkadot/src/internal/di.ts Binds DmkLoggerFactory to DMK logger factory implementation.
packages/signer/signer-polkadot/src/internal/app-binder/task/SignTransactionTask.ts Implements multi-chunk signing task using APDU_MAX_PAYLOAD and INIT/ADD/LAST phases.
packages/signer/signer-polkadot/src/internal/app-binder/task/SignTransactionTask.test.ts Tests for chunking behavior and error handling in signing task.
packages/signer/signer-polkadot/src/internal/app-binder/PolkadotAppBinder.ts Injects logger factory and forwards loggers to device actions and signing task.
packages/signer/signer-polkadot/src/internal/app-binder/constants.ts Adds P2 constants (curve selection) for APDU headers.
packages/signer/signer-polkadot/src/internal/app-binder/command/utils/polkadotApplicationErrors.ts Introduces Polkadot app status-word mapping and typed command error class.
packages/signer/signer-polkadot/src/internal/app-binder/command/utils/PolkadotApplicationErrors.test.ts Tests Polkadot app error mapping and error class construction.
packages/signer/signer-polkadot/src/internal/app-binder/command/utils/EncodeDerivationPath.ts Adds derivation path encoder (5×u32 LE) for Polkadot app format.
packages/signer/signer-polkadot/src/internal/app-binder/command/utils/EncodeDerivationPath.test.ts Tests derivation path encoding output and validation.
packages/signer/signer-polkadot/src/internal/app-binder/command/SignTransactionCommand.ts Implements APDU building + response parsing for signing protocol.
packages/signer/signer-polkadot/src/internal/app-binder/command/SignTransactionCommand.test.ts Tests APDU construction and status-word error handling for signing command.
packages/signer/signer-polkadot/src/internal/app-binder/command/GetAddressCommand.ts Implements APDU building + response parsing for publicKey+address derivation.
packages/signer/signer-polkadot/src/internal/app-binder/command/GetAddressCommand.test.ts Tests APDU construction and parsing for address command.
.changeset/bittensor-apdu-commands.md Publishes a minor changeset for the new APDU layer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sonarqubecloud

sonarqubecloud Bot commented Jun 2, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
71.6% Coverage on New Code (required ≥ 80%)
6.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@mbertin-ledger mbertin-ledger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please Handle also comment from sonarcloud analysis

SIGN_RAW: 0x03,
} as const;

export const P2 = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[SHOULD] P2 is parameter for a given command, this should be directly in command SignTransactionCommand as it's used there.

Same for INS above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 251691e — moved the command-specific INS and P2 into GetAddressCommand and SignTransactionCommand; constants.ts now keeps only the app-wide LEDGER_CLA (also dropped the unused SIGN_RAW/ECDSA).

@cted-ledger
cted-ledger marked this pull request as draft June 11, 2026 07:54
@cted-ledger
cted-ledger force-pushed the feat/LIVE-30995-implement-apdu-polkadot-signer branch from 1e8eca9 to b533fe9 Compare July 7, 2026 14:04
@cted-ledger cted-ledger changed the title ✨ (signer-polkadot) [LIVE-30995]: Implement APDU commands for Polkadot/Bittensor ✨ (signer-polkadot) [LIVE-30995]: Implement APDU commands for the Polkadot signer Jul 8, 2026
Complete the how-to-create-signer §13.1 test set (DefaultSignerPolkadot,
GetAddressUseCase). Also fix a stale derivation-path example in the
EncodeDerivationPath comment (354, generic Polkadot-family).
…ation)

- Move command-specific INS/P2 into GetAddressCommand and
  SignTransactionCommand; keep only the app-wide CLA in constants
  (removes the unused SIGN_RAW/ECDSA). (mbertin)
- Validate ss58Prefix and blobLength fit in a uint16 before the
  little-endian encoding, instead of silently truncating. (copilot)
- Use the reused Polkadot path (354) in test fixtures and rename
  BITTENSOR_PATH -> POLKADOT_PATH (the signer is generic, not Bittensor-specific).
Rename and reword the changeset so the released changelog describes the
Polkadot-family signer rather than a Bittensor-specific feature (the
signer is generic; chains differ only by SS58 prefix).
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

@cted-ledger
cted-ledger marked this pull request as ready for review July 8, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants