v0.2.6-pre.016
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: crates/ksp-wallet-lib/src/view.rs
|
||||
// version: 4
|
||||
// version: 5
|
||||
|
||||
/// Authorized VIEW capability handle.
|
||||
///
|
||||
@@ -7,15 +7,21 @@
|
||||
/// Solana secret, OWNER administration material or metadata-write authority.
|
||||
pub struct WalletView {
|
||||
info: crate::WalletInfo,
|
||||
state: crate::ViewStateV1,
|
||||
state: crate::ViewState,
|
||||
}
|
||||
|
||||
impl WalletView {
|
||||
/// Builds `WalletView` from unlocked.
|
||||
pub(crate) fn from_unlocked(info: crate::WalletInfo, state: crate::ViewStateV1) -> Self {
|
||||
pub(crate) fn from_unlocked(info: crate::WalletInfo, state: crate::ViewState) -> Self {
|
||||
return Self { info, state };
|
||||
}
|
||||
|
||||
/// Returns the native Wallet format version backing this authorized handle.
|
||||
#[must_use]
|
||||
pub const fn format_version(&self) -> u32 {
|
||||
return self.info.format_version();
|
||||
}
|
||||
|
||||
/// Returns the authorization capability represented by this handle.
|
||||
#[must_use]
|
||||
pub const fn capability(&self) -> crate::WalletCapability {
|
||||
@@ -65,15 +71,13 @@ impl WalletView {
|
||||
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::replace_wallet_file_v1(destination.as_ref().to_path_buf(), self.state.envelope().clone(), serialized).await;
|
||||
let persist_result = self.state.persist_staged(destination.as_ref().to_path_buf(), &envelope).await;
|
||||
if let std::result::Result::Err(error) = persist_result {
|
||||
return std::result::Result::Err(error);
|
||||
}
|
||||
self.state.apply_envelope(envelope);
|
||||
if let std::result::Result::Err(error) = self.state.apply_envelope(envelope) {
|
||||
return std::result::Result::Err(error);
|
||||
}
|
||||
ksp_logging_lib::debug!(
|
||||
target: crate::TRACING_TARGET,
|
||||
operation = "wallet_rotate_view_password",
|
||||
@@ -83,9 +87,16 @@ impl WalletView {
|
||||
return std::result::Result::Ok(());
|
||||
}
|
||||
|
||||
/// Serializes the unchanged locked `.kspwallet` V1 document without exposing the metadata content key.
|
||||
/// Serializes the unchanged locked native Wallet in its current V1 or V2 wire format.
|
||||
pub fn to_native_bytes(&self) -> ksp_core_lib::Result<std::vec::Vec<u8>> {
|
||||
return self.state.native_bytes();
|
||||
}
|
||||
|
||||
/// Serializes a V1 handle as its historical JSON document.
|
||||
///
|
||||
/// V2 handles return a format error instead of being converted implicitly.
|
||||
pub fn to_json_bytes(&self) -> ksp_core_lib::Result<std::vec::Vec<u8>> {
|
||||
return self.state.envelope().to_json_bytes();
|
||||
return self.state.json_bytes_v1();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user