Repository navigation
feat(platform-wallet): withdraw masternode credits with a wallet master-key provider or a host signer - #6028
Draft
Claudius-Maginificent wants to merge 22 commits into
Draft
Claudius-Maginificent wants to merge 22 commits into
Claudius-Maginificent wants to merge 22 commits into
Conversation
… secret Add verify_masternode_key_id: compares a key's 20-byte id (hash160 for the secp256k1 roles, the Tenderdash node id for PlatformNode) against a MasternodeKeyReference. Operator has no 20-byte id and stays Unverifiable. verify_masternode_key now maps each role to its reference id and compares through the same rule, so the secret and the hash paths cannot disagree. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…ternodeListUnavailable SpvRuntime::current_masternode_list returns Err(PlatformWalletError::MasternodeListUnavailable) instead of None while the list does not follow the chain or SPV restarted during the read, the error #5889's callers already map that case to. The crate-private current_masternode_list_summaries keeps returning None in that case. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…ts of masternode key checks Co-Authored-By: Claude Opus 5.5 <[email protected]>
…order proTxHash only Co-Authored-By: Claude Opus 5.5 <[email protected]>
…entity disables it Reproduction tests: they fail until learn_owner_identity and learn_operator_identity stop keeping a previously learned key when the fetched identity has no enabled key of that purpose. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a known operator key KeyVerification::Unverifiable also covers a role that cannot be checked by its 20-byte id: verify_masternode_key_id returns it for an operator key, whose reference is the whole BLS key. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…e and describe its dash-spv follow-up in words CurrentMasternodeList is exported from `masternode` only, like MasternodeListSummary and MasternodeKeyReference. The TODO on current_masternode_list names the dependency in words, as no upstream issue exists yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…m the list and its Platform identities Add PlatformWalletManager::fetch_masternode_key_reference: the current masternode list's fields joined with the owner and payout key hashes of the node's owner identity and the operator payout key hash of its operator identity, for any node, tracked or not. Nothing is persisted. It fails with MasternodeListUnavailable while the list does not follow the chain; a node absent from the list but with an owner identity (retired, credits still claimable) gets its list fields None; Ok(None) when neither the list nor Platform knows the node. Fix the tracked-node refresh with the same rule: it took any key of the purpose, so after a payout address change it could keep a disabled TRANSFER key depending on key-id order. One helper now picks the enabled ECDSA_HASH160 key. The refresh also reads the list only while it follows the chain, so a stale list no longer overwrites the cached entry. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…ched identity disables it The tracked-node refresh kept the last known owner and operator payout key hashes when the freshly fetched identity had no enabled key for them. Drive disables every owner TRANSFER key when the payout is no sole P2PKH output, and the operator TRANSFER key when the operator payout is removed, so the kept key was stale. A fetched identity now sets the key hashes to its enabled keys; a failed or empty fetch still leaves the snapshot as it was. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…the key provider, and Send withdrawals Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eep no stray copy of the derived key - A withdrawal key the owner identity does not hold, enabled, for the withdrawal's purpose is refused with PlatformWalletError::MasternodeWithdrawalKeyMismatch, for the tracked path and the Host arm alike. The FFI maps it to ErrorInvalidParameter, the code mobile hosts got for a wrong tracked key before. - MasternodeKeySource::host builds a Host source without naming the provider type. - The withdrawal key derivation returns only the zeroized scalar; the WIF is rendered only for a key reveal, and the intermediate secret keys are wiped. - Drop an orphaned doc line in tracked.rs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…and default payout destination Against a mocked Platform: a host payout-key withdrawal without a destination pays the enabled TRANSFER key's P2PKH address, never the disabled key it replaced; a host key the identity has disabled is refused as a key mismatch before anything is signed; an owner-key withdrawal signs no payout output script. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ut of tracked reads Once the owner identity has been read, its keys are the current ones: TrackedMasternode::key_reference and record no longer fall back to the registered payout script (or owner key) when the identity holds no enabled key for it, so a retired payout key no longer comes back. Before that read, the registration is still used. Add CurrentMasternodeList::entry and use it for the per-node lookups in key_reference and the tracked refresh. Fold the learn tests that re-asserted the enabled-key ordering into the learn regression tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…record Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…al's remaining balance
Add WithdrawalOutcome { remaining_credits, proved_at: BlockTime }, built
from the result proof's response metadata, so a host can tell a
withdrawal's proved balance from an older balance read.
PlatformWallet::masternode_withdraw, TrackedMasternodes::withdraw and
IdentityWallet::withdraw_credits_with_signer return it instead of the bare
balance; the masternode path waits with
wait_for_affected_state_with_metadata, the identity path uses
withdraw_with_metadata. When an outcome is unconfirmed is unchanged.
These public Rust signatures change (not consensus). The FFI keeps its
balance out-parameter and reads remaining_credits.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…or identity withdrawals Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…er-key provider or a host signer Add PlatformWalletManager::masternode_withdraw_with, which takes the signing key from a MasternodeKeySource: - Wallet: the wallet's key at the path MasternodeWithdrawalKeys resolved, from its resident keys or from the master key an async MasterKeyProvider (#5740) supplies. The provider runs with no wallet-manager guard held, and the derived key must hash to the key the request names, so another wallet's master key or a wrong path is refused before anything is signed. - Host: a host-held identity signer, used for the owner identity's key it reports it can sign with; with none, nothing is broadcast. Both arms select only enabled OWNER / TRANSFER keys (the rule the key reference lookup uses) and share the sign, broadcast and settle path. Errors are typed: MasternodeWithdrawalError::{Wallet, KeySource}. masternode_withdrawal_keys takes a payout_path_hint, used when the funding pools miss the payout address and checked against the payout key hash when the key is derived. PlatformWallet::masternode_withdraw and TrackedMasternodes::withdraw are thin wrappers over the same path. The tracked path checks the host key against the live identity instead of the cached snapshot. The FFI passes no payout path hint. RawSecretCoreSigner wipes its key on drop. Public Rust API changes (not consensus): masternode_withdrawal_keys gains a parameter; MasterKeyProvider, MasternodeKeySource and MasternodeWithdrawalError are new. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…rnode withdrawal key - The Wallet key source fetches the owner identity, selects its key and takes the nonce before asking the MasterKeyProvider, and drops the derived key once it has signed, before the broadcast and the wait. - An explicit destination for another network than the SDK's is refused before anything is fetched, on every withdrawal path. - Key refusals name the owner key or payout key. An identity with no current key of the requested kind gets MasternodeWithdrawalKeyAbsent, which says which key to use instead; the FFI maps it, like MasternodeWithdrawalKeyMismatch, to ErrorInvalidParameter. - select_withdrawal_key uses the shared AvailableSigningKey selector. - One p2pkh_address helper; MasternodeKeySource implements Debug without printing keys; transfer_key and payout_path_hint docs cover the unverified hint. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
…rce takes no identity nonce Fails on purpose: the wallet key source now takes the owner identity's nonce before asking the master-key provider, so a declined keychain prompt consumes one. The SDK nonce cache never gives a bumped nonce back, and Platform refuses a nonce more than 24 past the identity's. Passes on a425fdf, where the provider ran before any network call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…signing The SDK caches identity nonces, so one taken before the key source runs was used up whenever the key source then failed (provider error, wrong key, removed wallet, cancelled future). Enough such failures left every withdrawal of the node failing until restart. prepare_withdrawal now only fetches the identity and selects its key; UnsignedWithdrawal::sign takes the nonce right before signing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
Collaborator
|
🕓 Review not started yet because this PR is a draft.
Commit 573207d. Normal review starts when eligible; priority review starts as soon as a slot is available. |
This was referenced Nov 21, 2026
6 of 18 tasks
Check both ECDSA encodings with independent public-key ids and distinct role fields. Cover operator exclusion with populated references, direct curve mismatches, and zero scalars. Specify public id encodings in rustdoc. Co-Authored-By: Codex <[email protected]> <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>
…its height Add SpvRuntime::current_masternode_list, returning a CurrentMasternodeList (the list's known height and its summaries from one snapshot) only while the list follows the chain, through the existing while_following_the_chain gate. CurrentMasternodeList::key_reference gives the list-known keys of a node, or None when the node is not on the list. The crate-private current_masternode_list_summaries is now a projection of it; its callers see the same results. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
lklimek
force-pushed
the
feat/mn-withdrawal-key-source
branch
from
November 24, 2026 11:15
6e833fb to
573207d
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: Masternode credit withdrawals can now be signed either with a key the wallet derives on demand from its master key or with a key held by the host app, and every key is checked against the node's current owner identity before anything is signed.
User story
As a wallet app developer, I want to withdraw a masternode's credits with a key my app holds or one the wallet derives from a master key it asks me for, to achieve withdrawals from wallets that do not keep their seed resident, without signing with a wrong or disabled key.
Scenario
Base flow
The user withdraws credits from a masternode whose owner or payout key lives in the wallet (behind a keychain prompt) or in the host app.
Actual behavior
Expected behavior
Detailed discussion
Issue being fixed or feature implemented
Stacked atop #6027 (
feat/mn-withdrawal-height), last PR of the stack over #5889.What was done?
PlatformWalletManager::masternode_withdraw_withtaking aMasternodeKeySource(wallet/masternode_withdrawal.rs):MasternodeWithdrawalKeysresolved, from the wallet's resident keys or from the master key an asyncMasterKeyProvidersupplies (ahead of refactor(platform-wallet): own the key-source choice natively #5740). The provider runs with no wallet-manager guard held. The derived key must hash to the key the request names, so another wallet's master key or a wrong path is refused before signing. The derived key is dropped right after signing, before broadcast and wait; intermediate secrets are wiped.MasternodeKeySource::host(signer)): a host-held identity signer, used for the owner identity key it reports it can sign with; with none, nothing is broadcast.prepare_withdrawalfetches the owner identity and selects the key;UnsignedWithdrawal::signtakes the nonce right before signing, so a failed key source never consumes a nonce.masternode_withdrawal_keystakes apayout_path_hint, used when the funding pools miss the payout address and checked against the payout key hash at derivation. The FFI passes no hint.PlatformWallet::masternode_withdrawandTrackedMasternodes::withdraware thin wrappers over the same path; the tracked path checks the host key against the live identity instead of the cached snapshot.MasternodeWithdrawalError::{Wallet, KeySource},PlatformWalletError::MasternodeWithdrawalKeyMismatchandMasternodeWithdrawalKeyAbsent(the latter says which key to use instead). Messages say "owner key" / "payout key".MasternodeKeySourceimplementsDebugwithout printing keys;RawSecretCoreSignerwipes its key on drop.FFI / mobile behaviour changes
masternode_withdraw(wallet path): a key the owner identity does not carry now returnsErrorInvalidParameter(key mismatch / key absent) instead ofErrorUnknown.tracked_masternode_withdraw: a wrong secret used to be refused locally (ErrorInvalidParameter); it is now refused after fetching the identity (a network round trip), still asErrorInvalidParameter. A missing identity givesErrorIdentityNotFound; offline gives a network error. The "refresh the node first" refusals are removed.ErrorMasternodeWithdrawalUnconfirmedafter a broadcast; it is now refused before broadcast (ErrorInvalidParameter).How Has This Been Tested?
masternode_withdrawal.rsandcore_address_key.rs: key-type selection, wallet removal while the key provider runs,Sendwithdrawals, key mismatch and key absent.tests/masternode_withdraw_host_source.rs(a host payout-key withdrawal without a destination pays the enabled TRANSFER key's P2PKH address, never the disabled key it replaced; a disabled host key is refused before signing; an owner-key withdrawal signs no payout script) andtests/masternode_withdraw_nonce.rs(a withdrawal stopped by its key source takes no identity nonce).Breaking Changes
Public Rust API (not consensus):
masternode_withdrawal_keysgains apayout_path_hintparameter. New:MasterKeyProvider,MasternodeKeySource,MasternodeWithdrawalError,PlatformWalletManager::masternode_withdraw_with,PlatformWalletError::{MasternodeWithdrawalKeyMismatch, MasternodeWithdrawalKeyAbsent}(FFIErrorInvalidParameter). FFI behaviour changes are listed above.Deferred
PlatformWalletManagerTrackedMasternodes.swift,PlatformWalletManagerMasternodes.swift); Swift is out of scope here.credit_signing_keyselector can still pick disabled keys, unlike the masternode path.MasterKeyProviderand the closure-based reveal path); to be unified with refactor(platform-wallet): own the key-source choice natively #5740.SignerRefexists in several copies; the root fix is a blanket&Ssigner impl in rs-dpp.Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
https://claude.ai/code/session_01WunYYk4eUkHuGstPtj83j4
🤖 Co-authored by Claudius the Magnificent AI Agent