wallet: create/import in-app (no key paste on create) + opt-in spend
All checks were successful
ci / test (pull_request) Successful in 4m15s
ci / sdk (pull_request) Successful in 1m12s

/ wallet create generates a wallet on the RPC and shows the 25-word seed
once for backup; /wallet import is the only path that takes an existing
seed, and it is collected on a dedicated screen so it never reaches the
composer line or chat history.

Threat model now states the real policy: payments are opt-in, default is
no spend key, spend is a local authority at create/restore, and the chain
source is the user's choice (spawned local monerod or a daemon address
they supply). WALLET.md and README follow.

Tests: canned-RPC create/restore, slash parse, help overlay.
This commit is contained in:
Lance Walters 2026-09-13 23:25:25 -04:00
commit cf0a517cd2
No known key found for this signature in database
12 changed files with 758 additions and 48 deletions

View file

@ -61,6 +61,12 @@ pub struct TransferRow {
pub address: String,
}
/// Wallet file name used for in-app create/import (`--wallet-dir` on the RPC).
pub const DEFAULT_WALLET_FILENAME: &str = "onionwire";
/// Shown before a spend-capable create. Not a tooltip — the user must confirm.
pub const SPEND_AUTHORITY_WARNING: &str = "this wallet file can spend. anyone with its passphrase or the RPC creds can move the balance. write down the seed. do not leave it on a box you do not trust.";
const RPC_TIMEOUT: Duration = Duration::from_secs(5);
impl Wallet {
@ -215,6 +221,65 @@ impl Wallet {
json_str(&v, "balance")
}
/// Create a new spend-capable wallet on the RPC (`create_wallet`). The
/// user does not paste a key — the daemon generates the seed. Returns that
/// seed once (from `query_key mnemonic`) so the UI can show a backup
/// screen. Needs `--wallet-dir` on the RPC.
pub async fn create_wallet(&self, filename: &str, password: &str) -> Result<String> {
let filename = filename.trim();
if filename.is_empty() {
return Err(Error("wallet filename required".into()));
}
if password.is_empty() {
return Err(Error("wallet passphrase required".into()));
}
self.rpc(
"create_wallet",
serde_json::json!({
"filename": filename,
"password": password,
"language": "English"
}),
)
.await?;
let v = self
.rpc("query_key", serde_json::json!({"key_type": "mnemonic"}))
.await
.map_err(|e| {
Error(format!(
"wallet created but seed backup unavailable: {e}"
))
})?;
json_str(&v, "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<()> {
let filename = filename.trim();
if filename.is_empty() {
return Err(Error("wallet filename required".into()));
}
if password.is_empty() {
return Err(Error("wallet passphrase required".into()));
}
let seed = seed.trim();
if seed.is_empty() {
return Err(Error("seed required to import a wallet".into()));
}
self.rpc(
"restore_deterministic_wallet",
serde_json::json!({
"filename": filename,
"password": password,
"seed": seed,
"language": "English"
}),
)
.await?;
Ok(())
}
async fn rpc(&self, method: &str, params: serde_json::Value) -> Result<serde_json::Value> {
let ep = self
.endpoint