Load a keypair for an identity.
(
&self,
id: &IdentityId,
password: Option<&str>,
)
| 588 | |
| 589 | /// Load a keypair for an identity. |
| 590 | pub fn load_keypair( |
| 591 | &self, |
| 592 | id: &IdentityId, |
| 593 | password: Option<&str>, |
| 594 | ) -> Result<KeyPair, IdentityError> { |
| 595 | let identity = self.load(id)?; |
| 596 | let secret = self.load_secret_key(id, password)?; |
| 597 | |
| 598 | // Verify the secret key matches the public key |
| 599 | let derived_public = secret.public_key(); |
| 600 | if derived_public != identity.public_key { |
| 601 | return Err(IdentityError::InvalidKey( |
| 602 | "Secret key does not match public key".to_string(), |
| 603 | )); |
| 604 | } |
| 605 | |
| 606 | Ok(KeyPair::from_secret_key(secret)) |
| 607 | } |
| 608 | |
| 609 | /// Delete an identity from the store. |
| 610 | pub fn delete(&mut self, id: &IdentityId) -> Result<(), IdentityError> { |