feat(lite): wallet encryption controller layer (encrypt/unlock/lock/decrypt)
Wire the backend passphrase-encryption commands into LiteWalletController:
- encryptWallet / decryptWallet (take passphrase by value, securely wipe it,
save after), unlockWallet / lockWallet (bring spending keys into/out of
memory), and encryptionStatus() -> {encrypted, locked}. All return
failure-safe results; errors arrive as {"error":..} or "Error:" (handled).
- Fold encryptionstatus into refreshModel() (polled every cycle, available even
mid-sync since it reads local wallet state) and apply it in
applyLiteRefreshModelToWalletState, so WalletState.isEncrypted()/isLocked()
track the backend — which gates the existing locked/auto-lock UI.
Backend contracts verified against the SDXL source: encrypt/unlock/decrypt take
the passphrase as the single arg; lock takes none; encryptionstatus returns
{"encrypted","locked"}; ops return {"result":"success"} / {"error":..}.
Tests: testLiteWalletControllerEncryption drives encrypt -> lock -> unlock ->
decrypt via encryptionStatus(), checks empty-passphrase + closed-wallet rejection,
and that the status folds into WalletState. Fake models the state machine.
GUI wiring (encrypt in Settings, unlock prompt / lock action) is the follow-up;
the backend create flow remains unencrypted by default until encrypt is run.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -106,6 +106,21 @@ struct LiteSeedResult {
|
||||
std::string error;
|
||||
};
|
||||
|
||||
// Wallet encryption state (from the backend `encryptionstatus`). `locked` means the spending
|
||||
// keys are not in memory (an encrypted wallet loads locked; unlock to spend).
|
||||
struct LiteEncryptionStatus {
|
||||
bool ok = false;
|
||||
bool encrypted = false;
|
||||
bool locked = false;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
// Result of an encrypt/decrypt operation (the passphrase is wiped by the controller).
|
||||
struct LiteEncryptionResult {
|
||||
bool ok = false;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
class LiteWalletController {
|
||||
public:
|
||||
LiteWalletController(WalletCapabilities capabilities,
|
||||
@@ -182,6 +197,16 @@ public:
|
||||
// Returns false when no wallet is open or the backend save fails.
|
||||
bool saveWallet();
|
||||
|
||||
// --- Wallet encryption (passphrase). All take the passphrase BY VALUE and securely wipe it. ---
|
||||
// encrypt: set a passphrase on an unencrypted wallet. unlock/lock: bring the spending keys
|
||||
// into / out of memory. decrypt: permanently remove encryption. encryptionStatus: query state
|
||||
// (also folded into the periodic refresh so WalletState.isLocked()/isEncrypted() track it).
|
||||
LiteEncryptionResult encryptWallet(std::string passphrase);
|
||||
bool unlockWallet(std::string passphrase);
|
||||
bool lockWallet();
|
||||
LiteEncryptionResult decryptWallet(std::string passphrase);
|
||||
LiteEncryptionStatus encryptionStatus();
|
||||
|
||||
// Poll sync status + fetch balance/addresses/transactions, and apply the result into the
|
||||
// app's WalletState. Returns true if state was updated. Safe no-op when no wallet is open.
|
||||
// Synchronous (blocks on the backend); used by tests and as the worker's unit of work.
|
||||
|
||||
Reference in New Issue
Block a user