pub struct PublicKey(/* private fields */);Expand description
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn from_bytes(key: &[u8]) -> Result<PublicKey, EllipticCurveError>
pub fn from_bytes(key: &[u8]) -> Result<PublicKey, EllipticCurveError>
Parses a compressed (33-byte) or uncompressed (65-byte) SEC1 encoding.
Returns EllipticCurveError::InvalidKey when the encoding is not a
valid point on the P-256 curve.
Sourcepub fn from_x_y(
x_bytes: &[u8; 32],
y_bytes: &[u8; 32],
) -> Result<PublicKey, EllipticCurveError>
pub fn from_x_y( x_bytes: &[u8; 32], y_bytes: &[u8; 32], ) -> Result<PublicKey, EllipticCurveError>
Builds a public key from raw affine x and y coordinates (both
big-endian, 32 bytes each). Returns InvalidKey if the coordinates
are not a valid point on the P-256 curve.
This is useful when importing keys from formats like JWK where x
and y are available directly.
Sourcepub fn verify(
&self,
message: &[u8],
signature: &[u8; 64],
) -> Result<(), EllipticCurveError>
pub fn verify( &self, message: &[u8], signature: &[u8; 64], ) -> Result<(), EllipticCurveError>
Verifies an ECDSA signature over message using SHA-256.
Both canonical low-s and non-canonical high-s signatures are accepted,
matching typical ECDSA interoperability. Use Self::verify_strict to
additionally reject high-s signatures.
Sourcepub fn verify_strict(
&self,
message: &[u8],
signature: &[u8; 64],
) -> Result<(), EllipticCurveError>
pub fn verify_strict( &self, message: &[u8], signature: &[u8; 64], ) -> Result<(), EllipticCurveError>
Verifies an ECDSA signature over message using SHA-256, additionally
rejecting non-canonical high-s signatures (s > n / 2).
Use this when signature malleability must be excluded (Bitcoin/EIP-2
style). Note that some third-party signers emit high-s signatures, which
this method will reject; Self::verify accepts both forms.
Sourcepub fn to_bytes(&self) -> [u8; 65]
pub fn to_bytes(&self) -> [u8; 65]
Returns the 65-byte uncompressed SEC1 encoding (0x04 || x || y).
Sourcepub fn to_compressed_bytes(&self) -> [u8; 33]
pub fn to_compressed_bytes(&self) -> [u8; 33]
Returns the 33-byte compressed SEC1 encoding (0x02/0x03 || x).