Add SecretsStore methods

This commit is contained in:
Sosthene 2024-11-25 22:27:09 +01:00 committed by Nicolas Cantu
parent 933c579366
commit faf2636680

View File

@ -109,6 +109,31 @@ impl SecretsStore {
self.shared_secrets.get(&address)
}
pub fn get_all_confirmed_secrets(&self) -> HashMap<SilentPaymentAddress, AnkSharedSecretHash> {
self.shared_secrets.clone()
}
pub fn get_all_unconfirmed_secrets(&self) -> Vec<AnkSharedSecretHash> {
self.unconfirmed_secrets.clone()
}
pub fn remove_secret_for_address(&mut self, address: SilentPaymentAddress) -> Result<(SilentPaymentAddress, AnkSharedSecretHash)> {
if let Some(removed_secret) = self.shared_secrets.remove(&address) {
return Ok((address, removed_secret));
} else {
return Err(Error::msg("Secret doesn't exist"));
}
}
pub fn remove_unconfirmed_secret(&mut self, secret: AnkSharedSecretHash) -> Result<()> {
if let Some(i) = self.unconfirmed_secrets.iter().position(|s| *s == secret) {
self.unconfirmed_secrets.swap_remove(i);
Ok(())
} else {
Err(Error::msg("Unknown secret"))
}
}
pub fn try_decrypt(&self, cipher: &[u8]) -> Result<(AnkSharedSecretHash, Vec<u8>)> {
let nonce = Nonce::from_slice(&cipher[..12]);