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 bytes in any accepted encoding.
Accepts all of the following:
- 33-byte SEC1 compressed (
0x02/0x03prefix) - 65-byte SEC1 uncompressed (
0x04prefix) - 64-byte raw
X || Yaffine coordinates (the Aptos on-chain encoding, with the leading0x04marker dropped)
§Errors
Returns AptosError::InvalidPublicKey if the bytes do not decode to a
valid Secp256k1 public key in one of the accepted encodings.
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 public key in one of the encodings accepted by Self::from_bytes
(33-byte compressed, 65-byte SEC1 uncompressed, or 64-byte raw X || Y).
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 in SEC1 uncompressed encoding (65 bytes, leading 0x04 marker).
Most Aptos on-chain APIs use the raw 64-byte encoding (the X || Y
coordinates with the 0x04 marker dropped) – see Self::to_raw_bytes.
This method is retained for callers that need the SEC1 form.
Sourcepub fn to_raw_bytes(&self) -> [u8; 64]
pub fn to_raw_bytes(&self) -> [u8; 64]
Returns the public key as the raw 64 bytes of the X || Y affine
coordinates, without the leading SEC1 0x04 uncompressed-point marker.
This is the encoding expected by aptos-stdlib’s
secp256k1::ecdsa_raw_public_key_from_64_bytes and by the
AnyPublicKey::Secp256k1Ecdsa variant on-chain (each variant carries a
vector<u8> of length 64).
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::Secp256k1Ecdsa) || 0x02)
Where BCS(AnyPublicKey::Secp256k1Ecdsa) = 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 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for Secp256k1PublicKey
Source§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
impl Eq for Secp256k1PublicKey
Source§impl PartialEq for Secp256k1PublicKey
impl PartialEq for Secp256k1PublicKey
Source§impl PublicKey for Secp256k1PublicKey
impl PublicKey for Secp256k1PublicKey
Source§impl Serialize for Secp256k1PublicKey
impl Serialize for Secp256k1PublicKey
impl StructuralPartialEq 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<()>
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<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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.