v0.2.5-pre.007
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
// file: crates/ksp-wallet-lib/src/view.rs
|
||||
// version: 2
|
||||
// version: 3
|
||||
|
||||
/// Authorized VIEW capability handle.
|
||||
///
|
||||
/// VIEW exposes protected metadata and retains only the authenticated metadata capability needed for its future self-service password rotation. It never
|
||||
/// owns the Solana secret or OWNER administration material.
|
||||
/// VIEW exposes protected metadata and retains only the authenticated metadata capability required for self-service password rotation. It never owns the
|
||||
/// Solana secret, OWNER administration material or metadata-write authority.
|
||||
pub struct WalletView {
|
||||
info: crate::WalletInfo,
|
||||
state: crate::wallet::ViewStateV1,
|
||||
@@ -51,6 +51,37 @@ impl WalletView {
|
||||
return &self.info;
|
||||
}
|
||||
|
||||
/// Rotates only this VIEW credential and atomically replaces the existing wallet file.
|
||||
///
|
||||
/// The same metadata content key and OWNER-signed VIEW slot identifier are retained. Alias, notes, Pubkey, OWNER material, activation state and the
|
||||
/// Solana secret remain unchanged.
|
||||
pub async fn rotate_view_password(
|
||||
&mut self,
|
||||
destination: impl std::convert::AsRef<std::path::Path>,
|
||||
new_password: crate::ViewPassword,
|
||||
) -> ksp_core_lib::Result<()> {
|
||||
let envelope = match self.state.stage_view_password_rotation(new_password).await {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let serialized = match envelope.to_json_bytes() {
|
||||
std::result::Result::Ok(value) => value,
|
||||
std::result::Result::Err(error) => return std::result::Result::Err(error),
|
||||
};
|
||||
let persist_result = crate::persistence::replace_wallet_file_v1(destination.as_ref().to_path_buf(), self.state.envelope().clone(), serialized).await;
|
||||
if let std::result::Result::Err(error) = persist_result {
|
||||
return std::result::Result::Err(error);
|
||||
}
|
||||
self.state.apply_envelope(envelope);
|
||||
ksp_logging_lib::debug!(
|
||||
target: crate::TRACING_TARGET,
|
||||
operation = "wallet_rotate_view_password",
|
||||
capability = "view",
|
||||
"wallet VIEW password self-rotated"
|
||||
);
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
/// Serializes the unchanged locked `.kspwallet` V1 document without exposing the metadata content key.
|
||||
pub fn to_json_bytes(&self) -> ksp_core_lib::Result<std::vec::Vec<u8>> {
|
||||
return self.state.envelope().to_json_bytes();
|
||||
|
||||
Reference in New Issue
Block a user