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