Skip to content

refactor(key-wallet): move extended_public_key out of Signer into ExtendedPubKeySigner subtrait - #839

Merged
xdustinface merged 2 commits into
devfrom
claude/hopeful-bassi-b8a585
Jul 2, 2026
Merged

xdustinface merged 2 commits into
devfrom
claude/hopeful-bassi-b8a585

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Jul 2, 2026 •

Copy link
Copy Markdown
Member

What changed

Removes extended_public_key as a required method on the Signer trait (added in #817) and moves it, unchanged, into a new ExtendedPubKeySigner: Signer subtrait. Signer is back to its minimal signing surface: supported_methods, sign_ecdsa, public_key.

Why

Exporting a BIP-32 extended public key is a key-export capability, not a signing one. Requiring it on Signer forced every backend to implement xpub export — including pure signing backends (HSMs, remote signing services) whose policy deliberately forbids exporting chain codes, since an xpub plus any non-hardened descendant private key compromises the whole subtree. Those backends had no honest implementation available other than stubbing an error.

The split keeps both use cases first-class:

  • Pure signers implement Signer alone.
  • Callers that need offline descendant derivation (e.g. DashPay contact payment addresses under m/9'/coin'/15'/account'/sender/recipient — the motivation for feat(key-wallet): add Signer::extended_public_key #817) bound on ExtendedPubKeySigner and keep the exact same method.

Making it a subtrait (rather than an independent trait) reuses the single associated Error type, so implementors and callers don't juggle two error types for one device.

Notes for reviewers

  • No production code called Signer::extended_public_key — only a test. The two in-repo InMemorySigner test signers move their impl to the new trait, and the unreachable!() stubs on the NoDigestSigner test signers are deleted outright (they no longer need the method at all, which is the concrete evidence the requirement never belonged on the base trait).
  • The new trait is re-exported from key_wallet root alongside Signer.
  • Downstream backports get simpler, not harder: implementors that can't export xpubs just don't implement the subtrait; implementors that can move one method body.
  • Verified: full workspace cargo check --all-targets, all 536 key-wallet tests pass, clippy (--all-features --all-targets -D warnings) and cargo fmt --check clean.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Made extended public key support available as part of the wallet’s public interface.
  • Documentation
    • Clarified how extended public key export relates to standard signing and key export behavior.
  • Tests
    • Updated internal test signers to cover extended public key handling in wallet workflows.

…endedPubKeySigner

Signer::extended_public_key (added in #817) forced every signer to
implement xpub export, but exporting a chain code is a key-export
capability, not a signing one: pure signing backends (HSMs, remote
signing services whose policy forbids chain-code export) could not
implement Signer without stubbing the method with an error.

Move the method unchanged into a new ExtendedPubKeySigner: Signer
subtrait. Callers that need offline descendant derivation (e.g. DashPay
contact xpubs) bound on the subtrait; everything else keeps the minimal
Signer. Reusing the Signer supertrait keeps a single associated Error
type.

No production code called the method, so only the two InMemorySigner
test signers move their impl to the new trait, and the unreachable
NoDigestSigner stubs are deleted outright — evidence the requirement
never belonged on the base trait.

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@QuantumExplorer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 203cbf51-a0a9-410b-959b-64e03ef35157

📥 Commits

Reviewing files that changed from the base of the PR and between 8489b0a and 39f20ed.

📒 Files selected for processing (1)
  • key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs
📝 Walkthrough

Walkthrough

This PR splits extended public key export into a dedicated ExtendedPubKeySigner trait separate from the core Signer trait, adds it to public re-exports, updates related documentation, and adjusts test signer implementations (InMemorySigner, NoDigestSigner) accordingly.

Changes

ExtendedPubKeySigner Trait Split

Layer / File(s) Summary
Trait definition, docs, and public export
key-wallet/src/signer.rs, key-wallet/src/lib.rs
ExtendedPubKeySigner is defined as a trait separate from Signer, its documentation clarifies extended key export vs. signing capability, and it's added to the public pub use signer::{...} re-export.
Test signer implementations updated for trait split
key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs, key-wallet/src/wallet/managed_wallet_info/transaction_building.rs
InMemorySigner gains a separate ExtendedPubKeySigner impl via #[async_trait::async_trait], while NoDigestSigner has its extended_public_key stub removed from the Signer impl.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • dashpay/rust-dashcore#817: Introduces the original extended_public_key feature as part of Signer, which this PR refactors into a separate ExtendedPubKeySigner trait.

Suggested labels: ready-for-review

Suggested reviewers: xdustinface

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main refactor: moving extended_public_key from Signer into a new ExtendedPubKeySigner subtrait.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/hopeful-bassi-b8a585

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs (1)

474-488: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a correctness test for extended_public_key here too.

transaction_building.rs added in_memory_signer_extended_public_key_matches_wallet_derivation to verify the new ExtendedPubKeySigner impl derives the same xpub as the wallet. This test module defines the identical InMemorySigner::extended_public_key impl but has no equivalent check.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs` around lines
474 - 488, Add a correctness test for InMemorySigner::extended_public_key in the
asset_lock_builder test module, since it defines the same ExtendedPubKeySigner
implementation as transaction_building.rs but currently lacks an equivalent
assertion. Mirror the existing wallet-derivation check by deriving an xpub
through InMemorySigner and comparing it against the wallet-derived extended
public key for the same derivation path, so this implementation stays verified
against the wallet behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs`:
- Around line 474-488: Add a correctness test for
InMemorySigner::extended_public_key in the asset_lock_builder test module, since
it defines the same ExtendedPubKeySigner implementation as
transaction_building.rs but currently lacks an equivalent assertion. Mirror the
existing wallet-derivation check by deriving an xpub through InMemorySigner and
comparing it against the wallet-derived extended public key for the same
derivation path, so this implementation stays verified against the wallet
behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bc80078a-2e3d-4e8b-bb2b-72dcdac7223f

📥 Commits

Reviewing files that changed from the base of the PR and between 788c19d and 8489b0a.

📒 Files selected for processing (4)
  • key-wallet/src/lib.rs
  • key-wallet/src/signer.rs
  • key-wallet/src/wallet/managed_wallet_info/asset_lock_builder.rs
  • key-wallet/src/wallet/managed_wallet_info/transaction_building.rs

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 2, 2026
…allet derivation

The asset_lock_builder test module duplicates the InMemorySigner
ExtendedPubKeySigner impl but had no correctness check, unlike its
twin in transaction_building.rs. Mirror the hardened-path assertion
so both copies stay verified against Wallet::derive_extended_public_key.

Co-Authored-By: Claude Fable 5 <[email protected]>
@QuantumExplorer

Copy link
Copy Markdown
Member Author

Addressed the CodeRabbit nitpick in 39f20ed: added in_memory_signer_extended_public_key_matches_wallet_derivation to the asset_lock_builder.rs test module, mirroring the hardened-path assertion from transaction_building.rs so both InMemorySigner copies stay pinned against Wallet::derive_extended_public_key.

🤖 Addressed by Claude Code

@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 73.46%. Comparing base (788c19d) to head (39f20ed).

Files with missing lines Patch % Lines
...c/wallet/managed_wallet_info/asset_lock_builder.rs 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #839      +/-   ##
==========================================
+ Coverage   73.13%   73.46%   +0.33%     
==========================================
  Files         324      324              
  Lines       72562    72577      +15     
==========================================
+ Hits        53066    53318     +252     
+ Misses      19496    19259     -237     
Flag Coverage Δ
core 76.94% <ø> (ø)
ffi 47.97% <ø> (+2.66%) ⬆️
rpc 20.00% <ø> (ø)
spv 90.34% <ø> (-0.12%) ⬇️
wallet 72.61% <94.73%> (+0.04%) ⬆️
Files with missing lines Coverage Δ
key-wallet/src/signer.rs 100.00% <ø> (ø)
...wallet/managed_wallet_info/transaction_building.rs 87.33% <ø> (+0.38%) ⬆️
...c/wallet/managed_wallet_info/asset_lock_builder.rs 83.24% <94.73%> (+1.60%) ⬆️

... and 19 files with indirect coverage changes

@xdustinface
xdustinface merged commit afcff15 into dev Jul 2, 2026
38 checks passed
@xdustinface
xdustinface deleted the claude/hopeful-bassi-b8a585 branch July 2, 2026 13:24
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