pub struct ECPublicKey(/* private fields */);
Expand description
A compressed elliptic curve digital signature algorithm (ECDSA) public key.
An ECPublicKey
is a 33-byte compressed representation of a public key on
the secp256k1 curve. The first byte is a prefix (0x02 or 0x03) that
indicates the parity of the y-coordinate, followed by the 32-byte
x-coordinate.
These public keys are used to:
- Verify ECDSA signatures
- Identify the owner of a private key without revealing the private key
- Derive shared secrets (when combined with another party’s private key)
Unlike the larger 65-byte uncompressed format (ECUncompressedPublicKey
),
compressed public keys save space while providing the same cryptographic
security.
§Examples
Verifying an ECDSA signature:
use bc_components::{ECKey, ECPrivateKey, ECPublicKey};
// Generate a keypair
let private_key = ECPrivateKey::new();
let public_key = private_key.public_key();
// Sign a message
let message = b"Hello, world!";
let signature = private_key.ecdsa_sign(message);
// Verify the signature
assert!(public_key.verify(&signature, message));
Implementations§
Source§impl ECPublicKey
impl ECPublicKey
Source§impl ECPublicKey
impl ECPublicKey
Sourcepub fn verify(&self, signature: &[u8; 64], message: impl AsRef<[u8]>) -> bool
pub fn verify(&self, signature: &[u8; 64], message: impl AsRef<[u8]>) -> bool
Verifies an ECDSA signature for a message using this public key.
Returns true
if the signature is valid for the given message and this
public key, and false
otherwise.
§Parameters
signature
: A 70-72 byte DER-encoded ECDSA signaturemessage
: The message that was signed
Trait Implementations§
Source§impl AsRef<[u8]> for ECPublicKey
impl AsRef<[u8]> for ECPublicKey
Source§impl CBORTagged for ECPublicKey
Defines CBOR tags for EC keys.
impl CBORTagged for ECPublicKey
Defines CBOR tags for EC keys.
Returns the CBOR tags for EC keys.
Source§impl CBORTaggedEncodable for ECPublicKey
Implements CBOR encoding for EC public keys.
impl CBORTaggedEncodable for ECPublicKey
Implements CBOR encoding for EC public keys.
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Creates the untagged CBOR representation.
The format is a map with:
- Key 3: byte string of the key data (Note the absence of key 2, which would indicate a private key)
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Clone for ECPublicKey
impl Clone for ECPublicKey
Source§fn clone(&self) -> ECPublicKey
fn clone(&self) -> ECPublicKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ECPublicKey
Formats the key for debugging, showing type name and hexadecimal value.
impl Debug for ECPublicKey
Formats the key for debugging, showing type name and hexadecimal value.
Source§impl Display for ECPublicKey
Formats the key as a hexadecimal string.
impl Display for ECPublicKey
Formats the key as a hexadecimal string.
Source§impl ECKey for ECPublicKey
Implements the ECKey
trait for ECPublicKey
.
impl ECKey for ECPublicKey
Implements the ECKey
trait for ECPublicKey
.
Source§fn public_key(&self) -> ECPublicKey
fn public_key(&self) -> ECPublicKey
Returns the public key (self).
Source§impl ECKeyBase for ECPublicKey
Implements the ECKeyBase
trait methods for ECPublicKey
.
impl ECKeyBase for ECPublicKey
Implements the ECKeyBase
trait methods for ECPublicKey
.
Source§impl ECPublicKeyBase for ECPublicKey
Implements the ECPublicKeyBase
trait for converting to uncompressed
format.
impl ECPublicKeyBase for ECPublicKey
Implements the ECPublicKeyBase
trait for converting to uncompressed
format.
Source§fn uncompressed_public_key(&self) -> ECUncompressedPublicKey
fn uncompressed_public_key(&self) -> ECUncompressedPublicKey
Converts this compressed public key to its uncompressed form.
Source§impl<'a> From<&'a ECPublicKey> for &'a [u8]
Converts a reference to an ECPublicKey
to a reference to a byte slice.
impl<'a> From<&'a ECPublicKey> for &'a [u8]
Converts a reference to an ECPublicKey
to a reference to a byte slice.
Source§fn from(value: &'a ECPublicKey) -> Self
fn from(value: &'a ECPublicKey) -> Self
Returns a reference to the key as a byte slice.
Source§impl<'a> From<&'a ECPublicKey> for &'a [u8; 33]
Converts a reference to an ECPublicKey
to a reference to a fixed-size byte
array.
impl<'a> From<&'a ECPublicKey> for &'a [u8; 33]
Converts a reference to an ECPublicKey
to a reference to a fixed-size byte
array.
Source§fn from(value: &'a ECPublicKey) -> Self
fn from(value: &'a ECPublicKey) -> Self
Returns a reference to the underlying byte array.
Source§impl From<ECPublicKey> for CBOR
Converts an ECPublicKey
to CBOR.
impl From<ECPublicKey> for CBOR
Converts an ECPublicKey
to CBOR.
Source§fn from(value: ECPublicKey) -> Self
fn from(value: ECPublicKey) -> Self
Converts to tagged CBOR.
Source§impl Hash for ECPublicKey
impl Hash for ECPublicKey
Source§impl PartialEq for ECPublicKey
impl PartialEq for ECPublicKey
Source§impl Verifier for ECPublicKey
Implements the Verifier
trait for verifying signatures.
impl Verifier for ECPublicKey
Implements the Verifier
trait for verifying signatures.
impl Eq for ECPublicKey
impl StructuralPartialEq for ECPublicKey
Auto Trait Implementations§
impl Freeze for ECPublicKey
impl RefUnwindSafe for ECPublicKey
impl Send for ECPublicKey
impl Sync for ECPublicKey
impl Unpin for ECPublicKey
impl UnwindSafe for ECPublicKey
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> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)