Skip to content

feat(key-wallet)!: add the DIP-13 rotation level to application encryption paths - #1250

Merged
xdustinface merged 1 commit into
devfrom
feat/key-wallet-encryption-rotation
Oct 29, 2026
Merged

xdustinface merged 1 commit into
devfrom
feat/key-wallet-encryption-rotation

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Problem

The DIP-13 application encryption key path is about to become permanent on mainnet, and as built in #1049 it cannot express a replacement key. m/9'/coin'/5'/7'/0'/identityId'/contractId'/purpose' gives an identity exactly one encryption key per contract and purpose, so rotating a compromised or retired key would mean abandoning the contract. DIP-13 (dashpay/dips#191, used by App Connect in dashpay/dips#181) fixes this by ending the path with a hardened 31-bit rotation' level, serialised as ser32(rotation + 2^31), with 0' as the first key.

Fix

  • DerivationPath::application_encryption_path now takes rotation: u32 and appends ChildNumber::Hardened { index: rotation }, giving m/9'/coin'/5'/7'/0'/identityId'/contractId'/purpose'/rotation'.
  • It returns Result<Self, Error>. A rotation of 2^31 or more fails with Error::InvalidChildNumber, the same error ChildNumber::from_hardened_idx uses elsewhere in the crate.
  • The old 8-level layout moved to application_encryption_path_without_rotation. Wallets derive it only to recognise encryption keys that pre-DIP wallets registered on testnet and devnet; new keys must use the rotation path. It is documented rather than #[deprecated] because the pinned legacy vectors in the tests call it and the workspace builds with -D warnings.

No other in-repo code calls the function, and key-wallet-ffi does not expose it.

Migration for callers

  • Pass a rotation (use 0 for a first key) and handle the Result.
  • To recognise a pre-DIP key, call application_encryption_path_without_rotation with the old arguments.

dashpay/platform will carry a temporary local append of the rotation level until it bumps to a rev that includes this change, then drop it.

Testing

test_application_key_vectors pins the new rotation keys and keeps the existing legacy pins, now run against the without-rotation function. Mnemonic is abandon ... about, empty passphrase, mainnet coin type 5'. 0x35.. and 0x6b.. are 32 bytes of that value; asc is 00 01 .. 1f and desc is ff fe .. e0.

Path Public key
.../0x35..'/0x6b..'/1'/0' 031a882c119e2b1f8e0349b444d877afa2599efeef49a26930fd25518cb6e9d57a
.../0x35..'/0x6b..'/1'/1' 03d0f6f0f48d968b9554d8e7fe467d7135bacf29d5c4994ca593bd10ebeed696f6
.../asc'/desc'/1'/0' 02dfed57ddaaea8c0758e8da44513520038eb8d6b0b92109953c14d6ab1087259b
.../asc'/desc'/2'/0' 020bcde800f41ad1f924477a9502f111445224cc9ab70114ae4e5099ba02bdd034
.../asc'/desc'/2'/1' 021b97869c21933673076a938337c28848c8bf8094bbe6883e3a4acbf33c639072

Path-string tests cover both builders, the largest valid rotation (2^31 - 1), and rejection of 2^31 and u32::MAX.

Run locally: cargo fmt --all --check, cargo clippy -p key-wallet --all-features --all-targets -- -D warnings, cargo check --workspace --all-targets, and cargo test -p key-wallet application_ (4 passed).

🤖 Generated with Claude Code

PR Hygiene · 9aa9fde

  • Bots — coderabbitai ✓
  • Self-review — post /self-reviewed
  • Build green
  • Approvals
    • key-wallet (key-wallet/src/bip32.rs, key-wallet/src/dip9.rs) — approved by xdustinface

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • New Features
    • Application encryption keys now support rotation-specific derivation paths, allowing distinct paths for different key rotations.
    • Rotations below the hardened-child-number limit are accepted; values at or above the limit are rejected.
    • The pre-rotation path remains available for recognizing existing keys on testnet and devnet.

…ption paths

The application encryption path is about to become permanent on mainnet.
DIP-13 (dashpay/dips#191, used by App Connect in dashpay/dips#181) ends it
with a hardened 31-bit rotation level so an identity can replace the
encryption key for a contract:
m/9'/coin'/5'/7'/0'/identityId'/contractId'/purpose'/rotation',
serialised as ser32(rotation + 2^31), with rotation 0' first.

`DerivationPath::application_encryption_path` now takes `rotation: u32` and
returns `Result`, failing with `Error::InvalidChildNumber` if the rotation
does not fit in 31 bits.

Migration: callers pass the rotation (0 for a first key) and handle the
`Result`. The old 8-level layout moved to
`application_encryption_path_without_rotation`, which wallets derive only to
recognise keys that pre-DIP wallets registered on testnet and devnet.

The pinned vectors now cover the rotation keys and keep the legacy pins
against the renamed function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 28, 2026
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 64b3a3d and 9aa9fde.

Files selected for processing: 2
  • key-wallet/src/bip32.rs
  • key-wallet/src/dip9.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

The application encryption path builder now accepts and validates a rotation value, then appends it to the path. A separate builder retains the pre-DIP layout without a rotation child. Tests cover rotation bounds, path vectors, and parsed-path matching.

Changes: Application encryption paths

Layer / File(s) Summary
Add validated rotation paths
key-wallet/src/dip9.rs
application_encryption_path now accepts a rotation and returns Result<Self, Error>. It rejects values at or above 2^31. application_encryption_path_without_rotation retains the prior path layout.
Test rotation and legacy paths
key-wallet/src/bip32.rs
Tests cover rotation bounds, public-key vectors for rotation-specific and pre-DIP paths, and matching a parsed decryption path with rotation 1.

Priority: Normal

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

Change: Feature

Suggested reviewers: kwvg, xdustinface

Merge Risk: Minimal · up to 9aa9f

Rotation paths are added while the legacy layout remains available. No merge-blocking issue was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: adding the DIP-13 rotation level to application encryption paths in key-wallet. It matches the API and test changes.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 28, 2026
@codecov

codecov Bot commented Oct 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.96%. Comparing base (64b3a3d) to head (9aa9fde).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1250      +/-   ##
==========================================
+ Coverage   78.94%   78.96%   +0.01%     
==========================================
  Files         298      298              
  Lines       79165    79260      +95     
==========================================
+ Hits        62497    62584      +87     
- Misses      16668    16676       +8     
Flag Coverage Δ
core 77.91% <ø> (ø)
ffi 50.99% <ø> (+<0.01%) ⬆️
rpc 52.05% <ø> (ø)
spv 93.60% <ø> (-0.05%) ⬇️
wallet 82.57% <100.00%> (+0.07%) ⬆️
Files with missing lines Coverage Δ
key-wallet/src/bip32.rs 84.45% <100.00%> (+0.82%) ⬆️
key-wallet/src/dip9.rs 77.21% <100.00%> (+1.64%) ⬆️

... and 4 files with indirect coverage changes

@xdustinface
xdustinface merged commit fc46449 into dev Oct 29, 2026
42 of 43 checks passed
@xdustinface
xdustinface deleted the feat/key-wallet-encryption-rotation branch October 29, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants