Repository navigation
Description
Problem
The book's rule is that the FFI and mobile SDKs hold no business logic. Several rs-platform-wallet-ffi exports still decide which key source to use. Each one probes the wallet under a short manager read guard, checks is_external_signable() and is_watch_only(), then either uses the resident keys or calls the host's mnemonic resolver to build the master key, and only then calls into platform-wallet to derive.
The files on v5.1-dev that carry this flow (resolve_master_from_resolver or the capability probe):
address_private_key.rsderive_connect_key.rsidentity_discovery.rsidentity_key_preview.rsidentity_keys_from_mnemonic.rsidentity_loading.rsmasternode_update_service.rsprovider_key_at_index.rswallet_startup.rs
#5727 adds one more caller (platform_wallet_bip44_address_private_key) through the shared reveal_address_private_key helper, which it factored out of platform_wallet_address_private_key. It keeps the existing flow rather than moving it, so all of these move together.
Proposed direction
Add a native key-source abstraction in platform-wallet, for example a MasterKeyProvider trait that returns the master ExtendedPrivKey for a wallet id. platform-wallet then owns the whole decision: probe the wallet, pick resident keys or the provider, call the provider with no manager guard held, derive, and clean up. The FFI crate implements the trait over MnemonicResolverHandle and only marshals inputs and results.
Constraints
- Keep releasing the manager guard before the provider is called. The iOS resolver reads the Keychain and can stall on a biometric prompt.
- Keep today's error codes at the C boundary, including
ErrorWalletOperationwhen a resolver is required but missing. - One entry point per commit makes this reviewable.
address_private_key.rsis the smallest place to start.
Stale cleanup doc
The doc of resolve_master_from_resolver in identity_keys_from_mnemonic.rs says ExtendedPrivKey has no Drop or Zeroize, so the caller must zeroize master.private_key. That is untrue at the pinned rust-dashcore rev: Drop calls zeroize, which wipes the private scalar, chain code and derivation metadata. Correct it when this file moves, and say that an explicit wipe is only an optional earlier one.
Activity
xdustinface commentedon Nov 3, 2026
Update
#5727 moves this choice into
platform-walletfor the two address key reveals (derive_core_address_private_keyandbip44_address_private_keytake amaster_keycallback), soaddress_private_key.rsis done and eight files remain. ItsCoreAddressKeyError<E>pattern can be reused for them.One more thing to fix along the way: the FFI entry points call the resolver inside
PLATFORM_WALLET_STORAGE.with_item, which holds the handle-storage read lock while a Keychain or biometric prompt is open. A pending handle insert or remove waits behind it. Moving the callback outsidewith_itemmeans cloning theArc<PlatformWallet>out first.xdustinface commentedon Nov 3, 2026
Update: scope after #5727
#5727 now covers part of this issue:
platform-walletowns the phrase to seed and phrase to master steps (seed_for_mnemonic,master_key_for_mnemonic). The shared FFI helpersresolve_seed_from_resolver*andresolve_master_from_resolver*only call the host's resolver, check its buffer and UTF-8, and hand the phrase over. That holds for every resolver caller.master_keycallback,CoreAddressKeyError<E>).The earlier list of nine files counted every resolver caller. What is left in the FFI:
is_external_signable()/is_watch_only()themselves before resolving:identity_discovery.rs,identity_key_preview.rs,identity_loading.rs,masternode_update_service.rsandprovider_key_at_index.rs. Themaster_keycallback pattern of the address reveals fits them.sign_with_mnemonic_resolver.rsparses the resolved phrase and builds the seed and master itself. It can callmaster_key_for_mnemonic.dash_sdk_derive_identity_keys_from_mnemonicparses a phrase plus passphrase in the FFI.PLATFORM_WALLET_STORAGE.with_item, so a Keychain prompt holds the storage read lock and handle inserts and removals wait behind it.