Skip to content

Update hh ledger - #8674

Closed
ChristopherDedominici wants to merge 5 commits into
mainfrom
update-hh-ledger
Closed

ChristopherDedominici wants to merge 5 commits into
mainfrom
update-hh-ledger

Conversation

@ChristopherDedominici

@ChristopherDedominici ChristopherDedominici commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

MVP, closed in favor of: #8706

Copilot AI balanced review requested due to automatic review settings October 5, 2026 06:31
@changeset-bot

changeset-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b9d5914

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@nomicfoundation/hardhat-ignition Patch
@nomicfoundation/hardhat-ledger Major
@nomicfoundation/hardhat-errors Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@socket-security

socket-security Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​ledgerhq/​device-transport-kit-node-hid@​1.0.17310092100100
Added@​ledgerhq/​device-management-kit@​1.10.086100100100100
Added@​ledgerhq/​device-signer-kit-ethereum@​1.18.199100100100100
Added@​ledgerhq/​context-module@​2.6.0100100100100100

View full report

@socket-security

socket-security Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Priority Alert  (click "▶" to expand/collapse) Action
Medium priority
License policy violation: npm node-hid under HIDAPI

License: HIDAPI - The applicable license policy does not permit this license (5) (package/hidapi/LICENSE-orig.txt)

From: pnpm-lock.yaml → npm/@ledgerhq/device-transport-kit-node-hid@1.0.1 → npm/node-hid@3.4.0

ℹ Read more on: This package | This alert | What is a license policy violation?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Find a package that does not violate your license policy or adjust your policy to allow this package's license.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/node-hid@3.4.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn

View full report

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

hardhat

Total size of the bundle: 41M
Total number of dependencies (including transitive): 38

List of dependencies (sorted by size)
33M	total
7.3M	@sentry/core
5.2M	zod
3.8M	micro-eth-signer
2.2M	undici
2.2M	@noble/curves
1.8M	@noble/hashes
1.4M	@nomicfoundation/hardhat-utils
1.1M	@noble/ciphers
884K	@nomicfoundation/hardhat-vendored
792K	@streamparser/json
684K	@nomicfoundation/hardhat-errors
536K	@scure/bip39
508K	ethereum-cryptography
504K	tsx
468K	micro-packed
408K	json-stream-stringify
320K	enquirer
320K	@nomicfoundation/hardhat-zod-utils
292K	semver
216K	adm-zip
208K	@scure/base
204K	ws
188K	@streamparser/json-node
168K	esbuild
156K	@nomicfoundation/edr
152K	fast-equals
108K	@scure/bip32
100K	chokidar
72K	@nomicfoundation/solidity-analyzer
56K	rfdc
48K	ansi-colors
44K	resolve.exports
44K	readdirp
40K	p-map
24K	strip-ansi
24K	is-safe-filename
24K	env-paths
24K	ansi-regex

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.

Copilot review overview

🟡 Changes recommended

Lossy numeric inputs can be signed incorrectly, and in-flight device connections can outlive connection closure.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity · 3 Low severity

Open (6)
What changed in this PR

Migrates hardhat-ledger from deprecated LedgerJS packages to Ledger’s Device Management Kit while preserving existing RPC behavior.

Changes:

  • Adds DMK device discovery, action, error, signing, and cleanup infrastructure.
  • Strengthens typed-data validation and post-signature verification.
  • Closes Ignition and example-script network connections and documents lifecycle/privacy changes.
File Description
.changeset/​ignition-close-network-connection.md Records Ignition connection cleanup.
.changeset/​ledger-device-management-kit.md Records the DMK migration.
.github/​actions/​setup-env/​action.yml Updates the native dependency comment.
MY_DOC.md Documents migration design and impacts.
cspell.dictionary.txt Adds migration-related terms.
packages/​example-project/​scripts/​ledger-2.ts Adds extensive manual Ledger QA scenarios.
packages/​example-project/​scripts/​ledger.ts Closes the example connection.
packages/​hardhat-ignition/​src/​internal/​tasks/​deploy.ts Closes deployment connections.
packages/​hardhat-ignition/​src/​internal/​tasks/​track-tx.ts Closes transaction-tracking connections.
packages/​hardhat-ignition/​src/​internal/​tasks/​verify.ts Closes verification connections.
packages/​hardhat-ledger/​README.md Documents DMK behavior and cleanup.
packages/​hardhat-ledger/​package.json Replaces LedgerJS with DMK dependencies.
packages/​hardhat-ledger/​src/​internal/​cjs-imports.ts Removes the LedgerJS import bridge.
packages/​hardhat-ledger/​src/​internal/​connect-device.ts Manages DMK sessions and transport cleanup.
packages/​hardhat-ledger/​src/​internal/​derivation-path.ts Normalizes paths for DMK.
packages/​hardhat-ledger/​src/​internal/​discover-device.ts Implements polling device discovery.
packages/​hardhat-ledger/​src/​internal/​dmk-errors.ts Normalizes and classifies DMK errors.
packages/​hardhat-ledger/​src/​internal/​dmk-imports.ts Adds the CommonJS DMK import bridge.
packages/​hardhat-ledger/​src/​internal/​get-y-parity.ts Rejects unsafe signature values.
packages/​hardhat-ledger/​src/​internal/​handler.ts Migrates signing and lifecycle handling to DMK.
packages/​hardhat-ledger/​src/​internal/​hook-handlers/​network.ts Cleans up handlers when connections close.
packages/​hardhat-ledger/​src/​internal/​run-device-action.ts Converts DMK observables into promises.
packages/​hardhat-ledger/​src/​internal/​typed-data.ts Parses and validates typed data.
packages/​hardhat-ledger/​src/​internal/​types.ts Defines DMK-facing abstractions.
packages/​hardhat-ledger/​test/​helpers/​dmk-error-classes.ts Exposes real DMK error classes to tests.
packages/​hardhat-ledger/​test/​helpers/​eth-mocked.ts Removes the LedgerJS Ethereum mock.
packages/​hardhat-ledger/​test/​helpers/​ledger-device-mock.ts Adds a DMK device and signer mock.
packages/​hardhat-ledger/​test/​helpers/​tests-cjs-imports.ts Removes obsolete test imports.
packages/​hardhat-ledger/​test/​helpers/​transport-node-hid-mock.ts Removes the old transport mock.
packages/​hardhat-ledger/​test/​internal/​derivation-path.ts Tests path normalization.
packages/​hardhat-ledger/​test/​internal/​discover-device.ts Tests discovery and cleanup behavior.
packages/​hardhat-ledger/​test/​internal/​dmk-errors.ts Tests DMK error handling.
packages/​hardhat-ledger/​test/​internal/​run-device-action.ts Tests observable action handling.
packages/​hardhat-ledger/​test/​internal/​typed-data.ts Tests typed-data validation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +335 to +339
this.#device = await this.#deviceFactory(
reconnecting
? LedgerHandler.RECONNECTION_TIMEOUT
: LedgerHandler.DEFAULT_TIMEOUT,
);
Comment on lines +143 to +147
const parsed = Number(chainId);

if (Number.isSafeInteger(parsed)) {
return parsed;
}
Comment thread MY_DOC.md Resolved
Comment thread packages/hardhat-ledger/README.md Resolved
Copilot AI balanced review requested due to automatic review settings October 5, 2026 06:37

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.

Copilot AI balanced review requested due to automatic review settings October 7, 2026 13:12

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.

Comment on lines +676 to +679
await this.#resetConnection();
await this.#initializationMutex.exclusiveRun(
async () => await this.#initExclusive(0, true),
);
Copilot AI balanced review requested due to automatic review settings October 8, 2026 10:27

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.

Comment on lines +189 to +194
export function closeDeviceManagementKit(): void {
if (deviceManagementKit === undefined) {
return;
}

if (liveDeviceSessions > 0) {
Copilot AI balanced review requested due to automatic review settings October 8, 2026 10:31

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.

🔵 Needs a closer look

Typed-data declarations can bypass malformed-text validation, and closing during path derivation reports the wrong error.

8 open findings
Previously missed (2)

In code that hasn't changed since last review

Medium severity Preserve connection errors during derivation

packages/​hardhat-ledger/​src/​internal/​handler.ts:439

Closing the connection while getAddress is running makes #runOnDevice throw the intended CONNECTION_ERROR, but this catch does not preserve it: it falls through and wraps it as ERROR_WHILE_DERIVING_PATH. This makes close-during-derivation report the wrong failure, unlike close during signing. Re-throw once the handler is closed before applying derivation error classification.

Medium severity Validate EIP-712 field, type, and primary type names

packages/​hardhat-ledger/​src/​internal/​typed-data.ts:50

This validates only domain/message values, but EIP-712 field and type names are also encoded into the digest. A lone surrogate in types[*].name, types[*].type, or primaryType therefore reaches both encoders and can be normalized even though the submitted text has no UTF-8 representation—the exact case this check is intended to reject. Walk the declarations and primary type too.

🧠 Review effort: Balanced


Give feedback about Copilot approvals in this survey to enter a drawing for a $150 gift card.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 12:23

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.

Copilot AI balanced review requested due to automatic review settings October 8, 2026 12:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Copilot AI balanced review requested due to automatic review settings October 12, 2026 11:57

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.

🟡 Changes recommended

Typed-data verification can reuse DMK-mutated input, discovery can leak timers, and several QA assertions contradict the implementation.

17 open findings
1 resolved since last review
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Previously missed (1)

In code that hasn't changed since last review

Medium severity Translate LedgerDeviceError to HardhatError publicly

packages/​hardhat-ledger/​src/​internal/​run-device-action.ts:102

This newly authored LedgerDeviceError is rejected directly to callers (the handler test at lines 611–617 explicitly requires that), but production Hardhat code surfaces failures as HardhatErrors rather than custom Error subclasses. Keep the tagged wrapper for internal classification if needed, then translate it to an appropriate HardhatError at the public boundary; the stopped/no-device paths should follow the same rule.

🧠 Review effort: Balanced

Comment on lines +66 to +75
const listening = listenToAvailableDevices().subscribe(observer);

if (settled) {
// A replayed device settled before `subscription` was assigned.
listening.unsubscribe();

return;
}

subscription = listening;
Comment thread MY_DOC.md Resolved
Copilot AI balanced review requested due to automatic review settings October 12, 2026 13:37

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.

Comment thread packages/hardhat-ledger/package.json Resolved
Comment thread packages/hardhat-ledger/README.md Resolved
Copilot AI balanced review requested due to automatic review settings October 12, 2026 14:10

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.

🔵 Needs a closer look

Typed-data mutation and chain-ID normalization can verify or sign data different from the caller’s original request, alongside dependency and messaging issues.

16 open findings
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Previously missed (2)

In code that hasn't changed since last review

Medium severity Remove outdated instruction to manually open the Ethereum app

packages/​hardhat-errors/​src/​descriptors.ts:3378

This updated connection error still tells users to open the Ethereum app, although the DMK now opens it automatically and the new retry messages intentionally removed that instruction. Keeping it in both the CLI message and website description gives misleading remediation for connection failures.

Low severity Correctly document rxjs as a runtime dependency

MY_DOC.md:103

The statement that rxjs is imported only for types is incorrect: run-device-action.ts imports and executes takeWhile at runtime. Describe its runtime role so this design record matches the implementation.

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 12, 2026 14:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Comment thread MY_DOC.md Resolved
Copilot AI balanced review requested due to automatic review settings October 12, 2026 15:14

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.

🟡 Changes recommended

Typed-data integrity, chain-ID validation, and closed-connection concurrency issues remain unresolved.

18 open findings
Files not reviewed (1)
  • pnpm-lock.yaml: Generated file
Previously missed (2)

In code that hasn't changed since last review

Medium severity Reject requests using cached handlers on closed connections

packages/​hardhat-ledger/​src/​internal/​hook-handlers/​network.ts:67

The closed check only runs when no handler is cached. closeConnection marks the connection closed before awaiting handler.close(), but leaves the existing handler in this map until that await finishes, so a concurrent eth_accounts request can retrieve it and succeed on a closed connection. Check closedConnections before using either a cached or new handler.

Medium severity Convert terminal failures to HardhatErrors

packages/​hardhat-ledger/​src/​internal/​run-device-action.ts:105

These terminal paths reject locally created CustomError instances, and LedgerHandler lets device-action failures escape to callers. Production errors in this repository are required to be HardhatErrors so callers receive a stable descriptor and normal Hardhat formatting; add descriptors and convert these failures before they escape.

🧠 Review effort: Balanced

Comment thread MY_DOC.md Resolved
Copilot AI balanced review requested due to automatic review settings October 13, 2026 09:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Copilot AI balanced review requested due to automatic review settings October 13, 2026 13:39

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.

Comment on lines +386 to +392
async function rejectOnDevice(): Promise<void> {
expected(
"'[hardhat-ledger] Confirmation failure', then the DMK error reaches " +
"the script as is: a tagged error, not a HardhatError, which Hardhat " +
"prints as 'An unexpected error occurred:' with its stack. There was " +
"no retry and no reconnection, and the process exits after the close.",
);
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Hardhat Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants