pub struct PublicKey {
pub point: Point,
}Expand description
A secp256k1 public key simply wraps around a curve point.
Fields§
§point: PointImplementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn decode(buf: &[u8]) -> Option<Self>
pub fn decode(buf: &[u8]) -> Option<Self>
Decodes a public key from bytes.
This function accepts both compressed (33 bytes) and uncompressed (65 bytes) formats. The point is always verified to be a valid curve point. Note that the neutral point (the “point-at-infinity”) is explicitly rejected.
Sourcepub fn encode_compressed(self) -> [u8; 33]
pub fn encode_compressed(self) -> [u8; 33]
Encodes this public key into the compressed format (33 bytes).
The first byte of the encoding always has value 0x02 or 0x03.
Sourcepub fn encode_uncompressed(self) -> [u8; 65]
pub fn encode_uncompressed(self) -> [u8; 65]
Encodes this public key into the compressed format (65 bytes).
The first byte of the encoding always has value 0x04.
Sourcepub fn verify_hash(self, sig: &[u8], hv: &[u8]) -> bool
pub fn verify_hash(self, sig: &[u8], hv: &[u8]) -> bool
Verifies a signature on a given hashed message.
The signature (sig) MUST have an even length; the first half of
the signature is interpreted as the “r” integer, while the second
half is “s” (both use unsigned big-endian convention).
Out-of-range values are rejected. The hashed message is provided
as hv; it is nominally the output of a suitable hash function
(often SHA-256) computed over the actual message. This function
can tolerate arbitrary hash output lengths; however, for proper
security, the hash output must not be too short, and it must be
an actual hash function output, not raw structured data.
Note: this function is not constant-time; it assumes that the public key and signature value are public data.