Load a keypair for an identity.
(
&self,
id: &IdentityId,
password: Option<&str>,
)
| 609 | |
| 610 | /// Load a keypair for an identity. |
| 611 | pub fn load_keypair( |
| 612 | &self, |
| 613 | id: &IdentityId, |
| 614 | password: Option<&str>, |
| 615 | ) -> Result<KeyPair, IdentityError> { |
| 616 | let identity = self.load(id)?; |
| 617 | let secret = self.load_secret_key(id, password)?; |
| 618 | |
| 619 | // Verify the secret key matches the public key |
| 620 | let derived_public = secret.public_key(); |
| 621 | if derived_public != identity.public_key { |
| 622 | return Err(IdentityError::InvalidKey( |
| 623 | "Secret key does not match public key".to_string(), |
| 624 | )); |
| 625 | } |
| 626 | |
| 627 | Ok(KeyPair::from_secret_key(secret)) |
| 628 | } |
| 629 | |
| 630 | /// Delete an identity from the store. |
| 631 | pub fn delete(&mut self, id: &IdentityId) -> Result<(), IdentityError> { |