sdk: expose the wallet catalogue, the open wallet's keys, and the self profile
The Android wallet/profile screens had nothing to call: the core could list
wallets, switch the child onto one, read its keys and read/write the self
profile, but none of it crossed UniFFI.
Core:
- Wallet::keys() -> WalletKeys { view_key, spend_key: Option<String> }: two
query_key calls against the file the RPC has open. A view-only wallet's -29
is spend_key: None, not an error. WalletKeys' Debug redacts both halves.
- Node::wallet_keys() mirrors wallet_create/wallet_seed; refuses locally when
no wallet is configured.
- Node::active_wallet_filename() -> Option<String>: the file the child is
pointed at, None until wallet-child settings exist, so a client can mark the
open row.
SDK (UniFFI):
- records WalletRow / WalletKeys / SelfProfile, and Wire::{wallets,
open_wallet, active_wallet_filename, wallet_keys, self_profile,
set_self_profile, push_self_profile}.
- The rule the clients must express is in the docs: the seed and the private
keys come from the OPEN wallet, so there is deliberately no accessor that
reads another saved wallet's secrets without opening it.
docs/WALLET.md (catalogue + 'secrets belong to the open wallet'),
docs/THREAT_MODEL.md (the new on-demand-display exposure surface) and the SDK
README are updated in the same commit.
This commit is contained in:
parent
a9117b8991
commit
5f19a56be3
7 changed files with 784 additions and 3 deletions
|
|
@ -349,6 +349,27 @@ impl std::fmt::Debug for Endpoint {
|
|||
}
|
||||
}
|
||||
|
||||
/// The private keys of the wallet file the RPC currently has open.
|
||||
///
|
||||
/// `view_key` is the private view key; `spend_key` is the private spend key and
|
||||
/// is `None` — not an error — for a view-only wallet, which has no spend key to
|
||||
/// hand out. Both are secrets: never log them, never persist them, and never put
|
||||
/// them in an error string.
|
||||
pub struct WalletKeys {
|
||||
pub view_key: String,
|
||||
pub spend_key: Option<String>,
|
||||
}
|
||||
|
||||
/// Hand-written so a stray `{:?}` cannot print a private key.
|
||||
impl std::fmt::Debug for WalletKeys {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("WalletKeys")
|
||||
.field("view_key", &"<redacted>")
|
||||
.field("spend_key", &self.spend_key.as_ref().map(|_| "<redacted>"))
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Wallet {
|
||||
endpoint: Option<Endpoint>,
|
||||
|
|
@ -807,6 +828,45 @@ impl Wallet {
|
|||
json_str(&v, "key")
|
||||
}
|
||||
|
||||
/// The wallet file's private keys, as the RPC reports them: `query_key`
|
||||
/// `view_key` and `query_key` `spend_key`.
|
||||
///
|
||||
/// Both come from the wallet file the child currently has **open** — this is
|
||||
/// not a "read any saved wallet's keys" accessor, and it cannot be: the RPC
|
||||
/// only ever answers for its open file.
|
||||
///
|
||||
/// A view-only wallet has no spend key: its `query_key spend_key` answers
|
||||
/// `WALLET_RPC_ERROR_CODE_WATCH_ONLY` (-29), which maps to
|
||||
/// `spend_key: None` rather than an error, matching the `-29` view-only
|
||||
/// detection the transfer probe already uses. Refuses locally, before any
|
||||
/// dial, when the wallet is not configured.
|
||||
///
|
||||
/// The two values are spend secrets: never log them, never store them, never
|
||||
/// put them in an error string. [`WalletKeys`]'s `Debug` redacts both.
|
||||
pub async fn keys(&self) -> Result<WalletKeys> {
|
||||
if !self.configured() {
|
||||
return Err(Error(NOT_CONFIGURED_MSG.into()));
|
||||
}
|
||||
let v = self
|
||||
.rpc("query_key", serde_json::json!({"key_type": "view_key"}))
|
||||
.await?;
|
||||
let view_key = json_str(&v, "key")?;
|
||||
// Asked second and separately: on a view-only wallet this is the call
|
||||
// that carries the `-29`, and `None` is the honest answer there.
|
||||
let spend_key = match self
|
||||
.rpc("query_key", serde_json::json!({"key_type": "spend_key"}))
|
||||
.await
|
||||
{
|
||||
Ok(v) => Some(json_str(&v, "key")?),
|
||||
Err(e) if e.to_string() == VIEW_ONLY_MSG => None,
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
Ok(WalletKeys {
|
||||
view_key,
|
||||
spend_key,
|
||||
})
|
||||
}
|
||||
|
||||
/// Import an existing wallet from its 25-word seed. This is the only path
|
||||
/// that takes a user-supplied secret.
|
||||
pub async fn restore_wallet(&self, filename: &str, password: &str, seed: &str) -> Result<()> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue