pub struct PublicKey { /* private fields */ }Expand description
Public key wrapper with algorithm identification
This structure provides a generic wrapper for public keys from any supported digital signature algorithm (currently Ed25519). The key includes a 1-byte algorithm identifier prefix that enables automatic algorithm detection.
§Structure
- 1 byte: Algorithm identifier (e.g., ‘E’ for Ed25519)
- N bytes: Public key bytes (length depends on algorithm)
§Features
- Algorithm agnostic: Works with any DSA implementation
- Automatic detection: Algorithm is detected from the identifier byte
- Serialization: Supports Base64, Borsh, and Serde JSON serialization
- Verification: Direct signature verification without needing the algorithm type
§Example
use ave_identity::keys::{KeyPair, KeyPairAlgorithm, DSAlgorithm};
// Generate a keypair and extract public key
let keypair = KeyPair::generate(KeyPairAlgorithm::Ed25519).unwrap();
let public_key = keypair.public_key();
// Check the algorithm
assert_eq!(public_key.algorithm(), DSAlgorithm::Ed25519);
// Get raw bytes (32 bytes for Ed25519)
let key_bytes = public_key.as_bytes();
assert_eq!(key_bytes.len(), 32);
// Serialize to string with algorithm identifier
let key_str = public_key.to_string();
println!("Public key: {}", key_str);Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn new(
algorithm: DSAlgorithm,
key_bytes: Vec<u8>,
) -> Result<Self, CryptoError>
pub fn new( algorithm: DSAlgorithm, key_bytes: Vec<u8>, ) -> Result<Self, CryptoError>
Create a new public key
Sourcepub fn algorithm(&self) -> DSAlgorithm
pub fn algorithm(&self) -> DSAlgorithm
Get the algorithm
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, CryptoError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, CryptoError>
Parse from bytes (includes algorithm identifier)
Sourcepub fn verify(
&self,
message: &[u8],
signature: &SignatureIdentifier,
) -> Result<(), CryptoError>
pub fn verify( &self, message: &[u8], signature: &SignatureIdentifier, ) -> Result<(), CryptoError>
Verify a signature with this public key
Trait Implementations§
Source§impl BorshDeserialize for PublicKey
impl BorshDeserialize for PublicKey
fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>
Source§fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
Deserializes this instance from a given slice of bytes.
Updates the buffer to point at the remaining bytes.
Source§fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
Deserialize this instance from a slice of bytes.
fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>where
R: Read,
Source§impl BorshSerialize for PublicKey
impl BorshSerialize for PublicKey
Source§impl<'de> Deserialize<'de> for PublicKey
impl<'de> Deserialize<'de> for PublicKey
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Ord for PublicKey
impl Ord for PublicKey
Source§impl PartialOrd for PublicKey
impl PartialOrd for PublicKey
impl Eq for PublicKey
impl StructuralPartialEq for PublicKey
Auto Trait Implementations§
impl Freeze for PublicKey
impl RefUnwindSafe for PublicKey
impl Send for PublicKey
impl Sync for PublicKey
impl Unpin for PublicKey
impl UnsafeUnpin for PublicKey
impl UnwindSafe for PublicKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more