v0.2.5-pre.002
This commit is contained in:
109
crates/ksp-wallet-lib/src/metadata.rs
Normal file
109
crates/ksp-wallet-lib/src/metadata.rs
Normal file
@@ -0,0 +1,109 @@
|
||||
// file: crates/ksp-wallet-lib/src/metadata.rs
|
||||
// version: 1
|
||||
|
||||
/// One protected Wallet note exposed only after VIEW or OWNER authorization.
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct WalletNote {
|
||||
id: std::string::String,
|
||||
text: std::string::String,
|
||||
}
|
||||
|
||||
impl WalletNote {
|
||||
/// Returns the stable note identifier used by Wallet administration operations.
|
||||
#[must_use]
|
||||
pub fn id(&self) -> &str {
|
||||
return self.id.as_str();
|
||||
}
|
||||
|
||||
/// Returns the protected note text after authorization.
|
||||
#[must_use]
|
||||
pub fn text(&self) -> &str {
|
||||
return self.text.as_str();
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for WalletNote {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
return formatter.debug_struct("WalletNote").field("id", &"<redacted>").field("text", &"<redacted>").finish();
|
||||
}
|
||||
}
|
||||
|
||||
/// Safe metadata projection produced after VIEW or OWNER authorization.
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct WalletInfo {
|
||||
format_version: u32,
|
||||
capability: crate::WalletCapability,
|
||||
pubkey: ksp_core_lib::Pubkey,
|
||||
alias: std::option::Option<std::string::String>,
|
||||
notes: std::vec::Vec<crate::WalletNote>,
|
||||
}
|
||||
|
||||
impl WalletInfo {
|
||||
/// Returns the native Wallet format version parsed for this projection.
|
||||
#[must_use]
|
||||
pub const fn format_version(&self) -> u32 {
|
||||
return self.format_version;
|
||||
}
|
||||
|
||||
/// Returns the authorization capability that produced this projection.
|
||||
#[must_use]
|
||||
pub const fn capability(&self) -> crate::WalletCapability {
|
||||
return self.capability;
|
||||
}
|
||||
|
||||
/// Returns the authorized Solana public key using the KSP Core re-export.
|
||||
#[must_use]
|
||||
pub const fn pubkey(&self) -> &ksp_core_lib::Pubkey {
|
||||
return &self.pubkey;
|
||||
}
|
||||
|
||||
/// Returns the protected internal alias after authorization, when present.
|
||||
#[must_use]
|
||||
pub fn alias(&self) -> std::option::Option<&str> {
|
||||
return self.alias.as_deref();
|
||||
}
|
||||
|
||||
/// Returns the protected Wallet notes after authorization.
|
||||
#[must_use]
|
||||
pub fn notes(&self) -> &[crate::WalletNote] {
|
||||
return self.notes.as_slice();
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for WalletInfo {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
return formatter
|
||||
.debug_struct("WalletInfo")
|
||||
.field("format_version", &self.format_version)
|
||||
.field("capability", &self.capability)
|
||||
.field("pubkey", &self.pubkey)
|
||||
.field("alias", &self.alias.as_ref().map(|_| "<redacted>"))
|
||||
.field("note_count", &self.notes.len())
|
||||
.finish();
|
||||
}
|
||||
}
|
||||
|
||||
/// Minimal non-secret information available while a native Wallet remains locked.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct LockedWalletInfo {
|
||||
format_version: u32,
|
||||
view_enabled: bool,
|
||||
}
|
||||
|
||||
impl LockedWalletInfo {
|
||||
/// Returns the native Wallet format version.
|
||||
#[must_use]
|
||||
pub const fn format_version(&self) -> u32 {
|
||||
return self.format_version;
|
||||
}
|
||||
|
||||
/// Reports whether a VIEW capability slot exists without exposing its protected contents.
|
||||
#[must_use]
|
||||
pub const fn view_enabled(&self) -> bool {
|
||||
return self.view_enabled;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../unit_tests/metadata.rs"]
|
||||
mod tests;
|
||||
Reference in New Issue
Block a user