Skip to content

feat(key-wallet): find a provider key by its hash - #1465

Draft
lklimek wants to merge 3 commits into
devfrom
feat/provider-key-lookup-by-hash
Draft

lklimek wants to merge 3 commits into
devfrom
feat/provider-key-lookup-by-hash

Conversation

@lklimek

@lklimek lklimek commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

TL;DR: key-wallet can now tell which of a wallet's masternode owner or voting keys matches a given key hash, so wallet libraries no longer need to re-implement that search.

User story

As a wallet library developer, I want to ask key-wallet which owner or voting key of a wallet has a given hash160, to achieve masternode key handling without my own derivation and search code.

Scenario

Base flow

A wallet application holds a wallet that controls a masternode and receives the owner or voting key hash from a masternode list entry or a provider transaction.

Actual behavior

key-wallet can derive provider keys and recognise them inside transactions, but it cannot say which of the wallet's keys has a given hash. Each wallet library writes that search itself.

Expected behavior

One call returns the matching key's index and derivation path, or nothing when the wallet does not hold that key.

Detailed discussion

What was done

  • Adds ManagedWalletInfo::find_provider_key and ProviderKeyRole { Owner, Voting } (key-wallet/src/wallet/managed_wallet_info/provider_keys.rs).
  • The lookup checks the caller's index hint first, then the account's address pool, then derives keys past the pool up to a caller-supplied window capped at MAX_GAP_LIMIT. DEFAULT_PROVIDER_KEY_WINDOW (20) is the usual window.
  • Every match, including a pool hit, is re-derived from the wallet's account xpub, so the lookup needs no seed, works for watch-only and external-signable wallets, and never trusts a pool belonging to another wallet.
  • Returns the key's index and derivation path, or None.

Not included: operator (BLS) key lookup by public key is left to a follow-up. Platform-node (Ed25519) keys need the seed and are out of scope.

Testing

New cases in key-wallet/src/tests/provider_key_derivation_tests.rs cover pool hits, scanning past the pool, a pool deeper than the window, the index hint (checked first; a hardened hint is rejected), lookup without the seed, a wallet without the account, the window cap, and a pool from another wallet being ignored.

Prior work

  • A stacked follow-up PR (feat/masternode-list-freshness) adds a freshness-checked masternode list read to dash-spv; the two share no code.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WunYYk4eUkHuGstPtj83j4

🤖 Co-authored by Claudius the Magnificent AI Agent

lklimek and others added 3 commits November 21, 2026 00:51
Add `ManagedWalletInfo::find_provider_key`, which returns the index and derivation path of the wallet's owner or voting key whose hash160 is given, or `None` when the wallet does not hold it. Wallet libraries no longer need to re-implement this search.

The key at a caller's index hint is derived and checked first, never trusted. Then the account's address pool is searched, the same entries the provider-key transaction matching uses. Keys past the pool are derived from the account xpub up to the caller's minimum window, so the lookup needs no seed and works for watch-only and external-signable wallets.

Operator (BLS) keys are matched by public key, not hash, and platform-node (Ed25519) keys need the seed; both are out of scope.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYk4eUkHuGstPtj83j4
`find_provider_key` derived a key for every index below the caller's `min_window`, so a large window meant up to 2^31 derivations and then an error at the hardened range. Cap the window at `MAX_GAP_LIMIT`, the ceiling address pools use, and state the remaining error case: a hardened `index_hint` when the wallet has the account.

Tests pin the cap and the hardened-hint error.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYk4eUkHuGstPtj83j4
`find_provider_key` returned a pool entry's index without deriving it from `wallet`, so pairing a `ManagedWalletInfo` with another wallet reported a key that wallet does not hold. Derive the key at the pool index from `wallet` before returning it, as the hint and the scan already do.

Export `DEFAULT_PROVIDER_KEY_WINDOW` (20), the usual `min_window`, so consumers stop keeping their own scan constant. Also cross-check the voting-key lookup against transaction matching, as the owner test does.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYk4eUkHuGstPtj83j4
@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

@codecov

codecov Bot commented Nov 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.91667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.55%. Comparing base (3e55679) to head (31fbba5).
⚠️ Report is 1 commits behind head on dev.

Files with missing lines Patch % Lines
...et/src/wallet/managed_wallet_info/provider_keys.rs 97.91% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1465      +/-   ##
==========================================
+ Coverage   86.48%   86.55%   +0.06%     
==========================================
  Files         270      271       +1     
  Lines       70985    71045      +60     
==========================================
+ Hits        61393    61491      +98     
+ Misses       9592     9554      -38     
Flag Coverage Δ
core 82.99% <ø> (+0.02%) ⬆️
rpc 52.10% <ø> (ø)
spv 94.63% <ø> (+0.04%) ⬆️
wallet 85.40% <97.91%> (+0.13%) ⬆️
Files with missing lines Coverage Δ
key-wallet/src/managed_account/address_pool.rs 90.68% <ø> (ø)
key-wallet/src/wallet/managed_wallet_info/mod.rs 78.86% <ø> (ø)
...et/src/wallet/managed_wallet_info/provider_keys.rs 97.91% <97.91%> (ø)

... and 11 files with indirect coverage changes

This branch has not been deployed

No deployments
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.

1 participant