wallet: create/import in-app (no key paste on create) + opt-in spend
/ 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:
parent
7ad3679b51
commit
cf0a517cd2
12 changed files with 758 additions and 48 deletions
|
|
@ -428,4 +428,16 @@ class WireViewModel(app: Application) : AndroidViewModel(app) {
|
|||
|
||||
suspend fun sendTip(pubkeyHex: String, amountXmr: String, memo: String = ""): Result<Unit> =
|
||||
runCatching { requireWire().sendTip(pubkeyHex, amountXmr, memo) }
|
||||
|
||||
suspend fun createWallet(password: String): Result<String> =
|
||||
runCatching { requireWire().createWallet(password) }
|
||||
|
||||
suspend fun importWallet(password: String, seed: String): Result<Unit> =
|
||||
runCatching { requireWire().importWallet(password, seed) }
|
||||
|
||||
fun spendAuthorityWarning(): String = runCatching {
|
||||
requireWire().spendAuthorityWarning()
|
||||
}.getOrElse {
|
||||
"this wallet file can spend. anyone with its passphrase or the RPC creds can move the balance. write down the seed."
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,11 +47,13 @@ import com.google.zxing.BarcodeFormat
|
|||
import com.google.zxing.EncodeHintType
|
||||
import com.google.zxing.qrcode.QRCodeWriter
|
||||
import com.siriusdevops.onionwire.WireViewModel
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import uniffi.onionwire_sdk.FriendInfo
|
||||
import uniffi.onionwire_sdk.TransferRow
|
||||
|
||||
private enum class PayKind { Invoice, Tip }
|
||||
private enum class SetupKind { Create, Import }
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
|
@ -67,6 +69,8 @@ fun WalletScreen(
|
|||
var transfers by remember { mutableStateOf<List<TransferRow>>(emptyList()) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
var composer by remember { mutableStateOf<PayKind?>(null) }
|
||||
var setup by remember { mutableStateOf<SetupKind?>(null) }
|
||||
var backupSeed by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
suspend fun reload() {
|
||||
runCatching { balance = vm.walletBalance() }
|
||||
|
|
@ -183,6 +187,7 @@ fun WalletScreen(
|
|||
}
|
||||
|
||||
val kind = composer
|
||||
val setupKind = setup
|
||||
if (kind != null) {
|
||||
PayComposer(
|
||||
kind = kind,
|
||||
|
|
@ -205,24 +210,72 @@ fun WalletScreen(
|
|||
}
|
||||
},
|
||||
)
|
||||
} else if (setupKind != null) {
|
||||
WalletSetupCard(
|
||||
kind = setupKind,
|
||||
warning = vm.spendAuthorityWarning(),
|
||||
onCancel = { setup = null },
|
||||
onCreated = { seed ->
|
||||
setup = null
|
||||
backupSeed = seed
|
||||
scope.launch { reload() }
|
||||
},
|
||||
onImported = {
|
||||
setup = null
|
||||
scope.launch { reload() }
|
||||
},
|
||||
onError = { error = it },
|
||||
create = { pw -> vm.createWallet(pw) },
|
||||
importWallet = { pw, seed -> vm.importWallet(pw, seed) },
|
||||
scope = scope,
|
||||
)
|
||||
} else {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(12.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
OutlinedButton(
|
||||
onClick = { composer = PayKind.Invoice },
|
||||
modifier = Modifier.weight(1f),
|
||||
) { Text("Invoice") }
|
||||
OutlinedButton(
|
||||
onClick = { composer = PayKind.Tip },
|
||||
modifier = Modifier.weight(1f),
|
||||
) { Text("Tip") }
|
||||
Column(Modifier.fillMaxWidth().padding(12.dp)) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
OutlinedButton(
|
||||
onClick = { composer = PayKind.Invoice },
|
||||
modifier = Modifier.weight(1f),
|
||||
) { Text("Invoice") }
|
||||
OutlinedButton(
|
||||
onClick = { composer = PayKind.Tip },
|
||||
modifier = Modifier.weight(1f),
|
||||
) { Text("Tip") }
|
||||
}
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
OutlinedButton(
|
||||
onClick = { setup = SetupKind.Create },
|
||||
modifier = Modifier.weight(1f),
|
||||
) { Text("Create") }
|
||||
OutlinedButton(
|
||||
onClick = { setup = SetupKind.Import },
|
||||
modifier = Modifier.weight(1f),
|
||||
) { Text("Import") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
backupSeed?.let { seed ->
|
||||
Text(
|
||||
"write this seed down once. anyone with it can spend.",
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
modifier = Modifier.padding(horizontal = 12.dp),
|
||||
)
|
||||
Text(
|
||||
seed,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
fontFamily = FontFamily.Monospace,
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
|
||||
)
|
||||
TextButton(onClick = { backupSeed = null }) { Text("I wrote it down") }
|
||||
}
|
||||
|
||||
error?.let {
|
||||
Text(
|
||||
it,
|
||||
|
|
@ -347,6 +400,92 @@ private fun PayComposer(
|
|||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun WalletSetupCard(
|
||||
kind: SetupKind,
|
||||
warning: String,
|
||||
onCancel: () -> Unit,
|
||||
onCreated: (String) -> Unit,
|
||||
onImported: () -> Unit,
|
||||
onError: (String) -> Unit,
|
||||
create: suspend (String) -> Result<String>,
|
||||
importWallet: suspend (String, String) -> Result<Unit>,
|
||||
scope: CoroutineScope,
|
||||
) {
|
||||
var accepted by remember { mutableStateOf(kind != SetupKind.Create) }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var seed by remember { mutableStateOf("") }
|
||||
val ready = password.isNotEmpty() && (kind == SetupKind.Create || seed.isNotBlank())
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(12.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||
),
|
||||
) {
|
||||
Column(Modifier.padding(12.dp)) {
|
||||
Text(
|
||||
if (kind == SetupKind.Create) "Create wallet" else "Import wallet",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
if (kind == SetupKind.Create && !accepted) {
|
||||
Text(warning, style = MaterialTheme.typography.bodySmall)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
TextButton(onClick = onCancel) { Text("Cancel") }
|
||||
Button(onClick = { accepted = true }) { Text("I accept spend authority") }
|
||||
}
|
||||
return@Column
|
||||
}
|
||||
if (kind == SetupKind.Import) {
|
||||
Text(
|
||||
"Paste the 25-word seed. Create does not need a key.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
OutlinedTextField(
|
||||
value = seed,
|
||||
onValueChange = { seed = it },
|
||||
label = { Text("seed") },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
}
|
||||
OutlinedTextField(
|
||||
value = password,
|
||||
onValueChange = { password = it },
|
||||
singleLine = true,
|
||||
label = { Text("wallet passphrase") },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) {
|
||||
TextButton(onClick = onCancel) { Text("Cancel") }
|
||||
Button(
|
||||
onClick = {
|
||||
scope.launch {
|
||||
when (kind) {
|
||||
SetupKind.Create -> create(password).fold(
|
||||
onSuccess = onCreated,
|
||||
onFailure = { onError(it.message ?: it.toString()) },
|
||||
)
|
||||
SetupKind.Import -> importWallet(password, seed.trim()).fold(
|
||||
onSuccess = { onImported() },
|
||||
onFailure = { onError(it.message ?: it.toString()) },
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
enabled = ready,
|
||||
) { Text(if (kind == SetupKind.Create) "Create" else "Import") }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Generate a QR bitmap for the given URI string. Returns null on encode failure. */
|
||||
internal fun generateQrBitmap(uri: String): Bitmap? {
|
||||
return try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue