use anyhow::Result;
pub fn write_node_secret(secret: &str) -> Result<()> {
posemesh_node_registration::state::write_node_secret(secret)
}
pub fn read_node_secret() -> Result<Option<String>> {
posemesh_node_registration::state::read_node_secret()
}
pub fn clear_node_secret() -> Result<()> {
posemesh_node_registration::state::clear_node_secret()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn write_read_cycle() {
clear_node_secret().unwrap();
assert!(read_node_secret().unwrap().is_none());
write_node_secret("test-secret").unwrap();
assert_eq!(read_node_secret().unwrap().as_deref(), Some("test-secret"));
write_node_secret("new-secret").unwrap();
assert_eq!(read_node_secret().unwrap().as_deref(), Some("new-secret"));
clear_node_secret().unwrap();
assert!(read_node_secret().unwrap().is_none());
}
}