pub struct Ed25519PublicKey { /* private fields */ }ed25519 only.Expand description
An Ed25519 public key.
§Example
use aptos_sdk::crypto::{Ed25519PrivateKey, Ed25519PublicKey, Signer, Verifier};
let private_key = Ed25519PrivateKey::generate();
let public_key = private_key.public_key();
let message = b"hello";
let signature = private_key.sign(message);
assert!(public_key.verify(message, &signature).is_ok());Implementations§
Source§impl Ed25519PublicKey
impl Ed25519PublicKey
Sourcepub fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
pub fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
Creates a public key from raw bytes.
§Errors
Returns AptosError::InvalidPublicKey if:
- The byte slice length is not exactly 32 bytes
- The bytes do not represent a valid Ed25519 public key
Sourcepub fn from_hex(hex_str: &str) -> AptosResult<Self>
pub fn from_hex(hex_str: &str) -> AptosResult<Self>
Creates a public key from a hex string.
§Errors
Returns AptosError::Hex if the hex string is invalid.
Returns AptosError::InvalidPublicKey if the decoded bytes are not exactly 32 bytes or do not represent a valid Ed25519 public key.
Sourcepub fn from_aip80(s: &str) -> AptosResult<Self>
pub fn from_aip80(s: &str) -> AptosResult<Self>
Creates a public key from AIP-80 format string.
AIP-80 format: ed25519-pub-0x{hex_bytes}
§Errors
Returns an error if the format is invalid or the key bytes are invalid.
Sourcepub fn to_aip80(&self) -> String
pub fn to_aip80(&self) -> String
Returns the public key in AIP-80 format.
AIP-80 format: ed25519-pub-0x{hex_bytes}
Sourcepub fn verify(
&self,
message: &[u8],
signature: &Ed25519Signature,
) -> AptosResult<()>
pub fn verify( &self, message: &[u8], signature: &Ed25519Signature, ) -> AptosResult<()>
Verifies a signature against a message.
§Errors
Returns AptosError::SignatureVerificationFailed if the signature is invalid or does not match the message.
Sourcepub fn to_address(&self) -> AccountAddress
pub fn to_address(&self) -> AccountAddress
Derives the account address for this public key.
Uses the Ed25519 single-key scheme (scheme byte 0).
Sourcepub fn to_authentication_key(&self) -> [u8; 32]
pub fn to_authentication_key(&self) -> [u8; 32]
Derives the authentication key for this public key.
Trait Implementations§
Source§impl Clone for Ed25519PublicKey
impl Clone for Ed25519PublicKey
Source§fn clone(&self) -> Ed25519PublicKey
fn clone(&self) -> Ed25519PublicKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Ed25519PublicKey
impl Debug for Ed25519PublicKey
Source§impl<'de> Deserialize<'de> for Ed25519PublicKey
impl<'de> Deserialize<'de> for Ed25519PublicKey
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>,
Source§impl Display for Ed25519PublicKey
impl Display for Ed25519PublicKey
Source§impl PartialEq for Ed25519PublicKey
impl PartialEq for Ed25519PublicKey
Source§impl PublicKey for Ed25519PublicKey
impl PublicKey for Ed25519PublicKey
Source§fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
Source§impl Serialize for Ed25519PublicKey
impl Serialize for Ed25519PublicKey
Source§impl Verifier for Ed25519PublicKey
impl Verifier for Ed25519PublicKey
Source§type Signature = Ed25519Signature
type Signature = Ed25519Signature
Source§fn verify(
&self,
message: &[u8],
signature: &Ed25519Signature,
) -> AptosResult<()>
fn verify( &self, message: &[u8], signature: &Ed25519Signature, ) -> AptosResult<()>
impl Copy for Ed25519PublicKey
impl Eq for Ed25519PublicKey
impl StructuralPartialEq for Ed25519PublicKey
Auto Trait Implementations§
impl Freeze for Ed25519PublicKey
impl RefUnwindSafe for Ed25519PublicKey
impl Send for Ed25519PublicKey
impl Sync for Ed25519PublicKey
impl Unpin for Ed25519PublicKey
impl UnwindSafe for Ed25519PublicKey
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoMoveArg for Twhere
T: Serialize,
impl<T> IntoMoveArg for Twhere
T: Serialize,
Source§fn into_move_arg(self) -> Result<Vec<u8>, AptosError>
fn into_move_arg(self) -> Result<Vec<u8>, AptosError>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.