pub struct Secp256k1PublicKey { /* private fields */ }secp256k1 only.Expand description
A Secp256k1 ECDSA public key.
Implementations§
Source§impl Secp256k1PublicKey
impl Secp256k1PublicKey
Sourcepub fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
pub fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
Creates a public key from compressed bytes (33 bytes).
§Errors
Returns AptosError::InvalidPublicKey if the bytes do not represent a valid Secp256k1 compressed 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 do not represent a valid Secp256k1 compressed 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: secp256k1-pub-0x{hex_bytes}
§Errors
Returns an error if the format is invalid or the key bytes are invalid.
Sourcepub fn to_uncompressed_bytes(&self) -> Vec<u8> ⓘ
pub fn to_uncompressed_bytes(&self) -> Vec<u8> ⓘ
Returns the public key as uncompressed bytes (65 bytes).
Sourcepub fn to_aip80(&self) -> String
pub fn to_aip80(&self) -> String
Returns the public key in AIP-80 format (compressed).
AIP-80 format: secp256k1-pub-0x{hex_bytes}
Sourcepub fn verify(
&self,
message: &[u8],
signature: &Secp256k1Signature,
) -> AptosResult<()>
pub fn verify( &self, message: &[u8], signature: &Secp256k1Signature, ) -> AptosResult<()>
Verifies a signature against a message.
§Security
Rejects high-S signatures before verification, matching Aptos on-chain
behavior. This is a defense-in-depth check; signatures created through
this SDK’s from_bytes are already guaranteed to be low-S.
§Errors
Returns AptosError::SignatureVerificationFailed if the signature has
a high-S value, is invalid, or does not match the message.
Sourcepub fn verify_prehashed(
&self,
hash: &[u8; 32],
signature: &Secp256k1Signature,
) -> AptosResult<()>
pub fn verify_prehashed( &self, hash: &[u8; 32], signature: &Secp256k1Signature, ) -> AptosResult<()>
Verifies a signature against a pre-hashed message.
§Security
Rejects high-S signatures before verification, matching Aptos on-chain behavior.
§Errors
Returns AptosError::SignatureVerificationFailed if the signature has
a high-S value, is invalid, or does not match the hash.
Sourcepub fn to_address(&self) -> AccountAddress
pub fn to_address(&self) -> AccountAddress
Derives the account address for this public key.
Uses the SingleKey authentication scheme (scheme_id = 2):
auth_key = SHA3-256(BCS(AnyPublicKey::Secp256k1) || 0x02)
Where BCS(AnyPublicKey::Secp256k1) = 0x01 || ULEB128(65) || uncompressed_public_key
Trait Implementations§
Source§impl Clone for Secp256k1PublicKey
impl Clone for Secp256k1PublicKey
Source§fn clone(&self) -> Secp256k1PublicKey
fn clone(&self) -> Secp256k1PublicKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Secp256k1PublicKey
impl Debug for Secp256k1PublicKey
Source§impl<'de> Deserialize<'de> for Secp256k1PublicKey
impl<'de> Deserialize<'de> for Secp256k1PublicKey
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 Secp256k1PublicKey
impl Display for Secp256k1PublicKey
Source§impl PartialEq for Secp256k1PublicKey
impl PartialEq for Secp256k1PublicKey
Source§impl PublicKey for Secp256k1PublicKey
impl PublicKey for Secp256k1PublicKey
Source§fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
fn from_bytes(bytes: &[u8]) -> AptosResult<Self>
Source§impl Serialize for Secp256k1PublicKey
impl Serialize for Secp256k1PublicKey
Source§impl Verifier for Secp256k1PublicKey
impl Verifier for Secp256k1PublicKey
Source§type Signature = Secp256k1Signature
type Signature = Secp256k1Signature
Source§fn verify(
&self,
message: &[u8],
signature: &Secp256k1Signature,
) -> AptosResult<()>
fn verify( &self, message: &[u8], signature: &Secp256k1Signature, ) -> AptosResult<()>
impl Copy for Secp256k1PublicKey
impl Eq for Secp256k1PublicKey
impl StructuralPartialEq for Secp256k1PublicKey
Auto Trait Implementations§
impl Freeze for Secp256k1PublicKey
impl RefUnwindSafe for Secp256k1PublicKey
impl Send for Secp256k1PublicKey
impl Sync for Secp256k1PublicKey
impl Unpin for Secp256k1PublicKey
impl UnsafeUnpin for Secp256k1PublicKey
impl UnwindSafe for Secp256k1PublicKey
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,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.