pub struct SchnorrPublicKey(/* private fields */);
Expand description
A Schnorr (x-only) elliptic curve public key.
A SchnorrPublicKey
is a 32-byte “x-only” public key used with the BIP-340
Schnorr signature scheme. Unlike compressed ECDSA public keys (33 bytes)
that include a prefix byte indicating the parity of the y-coordinate,
Schnorr public keys only contain the x-coordinate of the elliptic curve
point.
Schnorr signatures offer several advantages over traditional ECDSA signatures:
- Linearity: Enables key and signature aggregation (eg., for multisignature schemes)
- Non-malleability: Prevents third parties from modifying signatures
- Smaller size: Signatures are 64 bytes vs 70-72 bytes for ECDSA
- Better privacy: Makes different multisig policies indistinguishable
- Provable security: Requires fewer cryptographic assumptions than ECDSA
Schnorr signatures were introduced to Bitcoin via the Taproot upgrade (BIP-340) and are becoming more widely used in cryptocurrency applications.
§Examples
Verifying a Schnorr signature:
use bc_components::ECPrivateKey;
// Generate a private key
let private_key = ECPrivateKey::new();
// Get the Schnorr public key
let schnorr_public_key = private_key.schnorr_public_key();
// Sign a message
let message = b"Hello, world!";
let signature = private_key.schnorr_sign(message);
// Verify the signature
assert!(schnorr_public_key.schnorr_verify(&signature, message));
Implementations§
Source§impl SchnorrPublicKey
impl SchnorrPublicKey
Source§impl SchnorrPublicKey
impl SchnorrPublicKey
Sourcepub fn schnorr_verify(
&self,
signature: &[u8; 64],
message: impl AsRef<[u8]>,
) -> bool
pub fn schnorr_verify( &self, signature: &[u8; 64], message: impl AsRef<[u8]>, ) -> bool
Verifies a Schnorr 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.
This implementation follows the BIP-340 Schnorr signature verification algorithm.
§Parameters
signature
: A 64-byte Schnorr signaturemessage
: The message that was signed
Trait Implementations§
Source§impl AsRef<[u8]> for SchnorrPublicKey
Provides a reference to the key data as a byte slice.
impl AsRef<[u8]> for SchnorrPublicKey
Provides a reference to the key data as a byte slice.
Source§impl Clone for SchnorrPublicKey
impl Clone for SchnorrPublicKey
Source§fn clone(&self) -> SchnorrPublicKey
fn clone(&self) -> SchnorrPublicKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for SchnorrPublicKey
Formats the key for debugging, showing type name and hexadecimal value.
impl Debug for SchnorrPublicKey
Formats the key for debugging, showing type name and hexadecimal value.
Source§impl Display for SchnorrPublicKey
Formats the key as a hexadecimal string.
impl Display for SchnorrPublicKey
Formats the key as a hexadecimal string.
Source§impl ECKeyBase for SchnorrPublicKey
Implements the ECKeyBase
trait methods for SchnorrPublicKey
.
impl ECKeyBase for SchnorrPublicKey
Implements the ECKeyBase
trait methods for SchnorrPublicKey
.
Source§impl<'a> From<&'a SchnorrPublicKey> for &'a [u8; 32]
Converts a reference to a SchnorrPublicKey
to a reference to a fixed-size
byte array.
impl<'a> From<&'a SchnorrPublicKey> for &'a [u8; 32]
Converts a reference to a SchnorrPublicKey
to a reference to a fixed-size
byte array.
Source§fn from(value: &'a SchnorrPublicKey) -> Self
fn from(value: &'a SchnorrPublicKey) -> Self
Returns a reference to the underlying byte array.
Source§impl From<[u8; 32]> for SchnorrPublicKey
Converts a fixed-size byte array to a SchnorrPublicKey
.
impl From<[u8; 32]> for SchnorrPublicKey
Converts a fixed-size byte array to a SchnorrPublicKey
.
Source§impl Hash for SchnorrPublicKey
impl Hash for SchnorrPublicKey
Source§impl PartialEq for SchnorrPublicKey
impl PartialEq for SchnorrPublicKey
impl Eq for SchnorrPublicKey
impl StructuralPartialEq for SchnorrPublicKey
Auto Trait Implementations§
impl Freeze for SchnorrPublicKey
impl RefUnwindSafe for SchnorrPublicKey
impl Send for SchnorrPublicKey
impl Sync for SchnorrPublicKey
impl Unpin for SchnorrPublicKey
impl UnwindSafe for SchnorrPublicKey
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,
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
)