pub enum SigningPublicKey {
Schnorr(SchnorrPublicKey),
ECDSA(ECPublicKey),
Ed25519(Ed25519PublicKey),
SSH(PublicKey),
MLDSA(MLDSAPublicKey),
}Expand description
A public key used for verifying digital signatures.
SigningPublicKey is an enum representing different types of signing public
keys, including elliptic curve schemes (ECDSA, Schnorr), Edwards curve
schemes (Ed25519), post-quantum schemes (ML-DSA), and SSH keys.
This type implements the Verifier trait, allowing it to verify signatures
of the appropriate type.
§Examples
Creating and using a signing public key pair:
use bc_components::{SignatureScheme, Signer, Verifier};
// Create a key pair
let (private_key, public_key) = SignatureScheme::Schnorr.keypair();
// Sign a message
let message = b"Hello, world!";
let signature = private_key.sign(&message).unwrap();
// Verify the signature
assert!(public_key.verify(&signature, &message));§CBOR Serialization
SigningPublicKey can be serialized to and from CBOR with appropriate tags:
use bc_components::{SignatureScheme, SigningPublicKey};
use dcbor::prelude::*;
// Create a key pair and get the public key
let (_, public_key) = SignatureScheme::Schnorr.keypair();
// Convert to CBOR
let cbor: CBOR = public_key.clone().into();
let data = cbor.to_cbor_data();
// Convert back from CBOR
let recovered = SigningPublicKey::from_tagged_cbor_data(&data).unwrap();
// The keys should be equal
assert_eq!(public_key, recovered);Variants§
Schnorr(SchnorrPublicKey)
A Schnorr public key (BIP-340, x-only)
ECDSA(ECPublicKey)
An ECDSA public key (compressed, 33 bytes)
Ed25519(Ed25519PublicKey)
An Ed25519 public key
SSH(PublicKey)
An SSH public key
MLDSA(MLDSAPublicKey)
A post-quantum ML-DSA public key
Implementations§
Source§impl SigningPublicKey
impl SigningPublicKey
Sourcepub fn from_schnorr(key: SchnorrPublicKey) -> Self
pub fn from_schnorr(key: SchnorrPublicKey) -> Self
Creates a new signing public key from a Schnorr public key.
§Arguments
key- A BIP-340 Schnorr public key
§Returns
A new signing public key containing the Schnorr key
§Examples
use bc_components::{SchnorrPublicKey, SigningPublicKey};
// Create a Schnorr public key
let schnorr_key = SchnorrPublicKey::from_data([0u8; 32]);
// Create a signing public key from it
let signing_key = SigningPublicKey::from_schnorr(schnorr_key);Sourcepub fn from_ecdsa(key: ECPublicKey) -> Self
pub fn from_ecdsa(key: ECPublicKey) -> Self
Creates a new signing public key from an ECDSA public key.
§Arguments
key- A compressed ECDSA public key
§Returns
A new signing public key containing the ECDSA key
§Examples
use bc_components::{ECKey, ECPrivateKey, SigningPublicKey};
// Create an EC private key and derive its public key
let private_key = ECPrivateKey::new();
let public_key = private_key.public_key();
// Create a signing public key from it
let signing_key = SigningPublicKey::from_ecdsa(public_key);Sourcepub fn from_ed25519(key: Ed25519PublicKey) -> Self
pub fn from_ed25519(key: Ed25519PublicKey) -> Self
Creates a new signing public key from an Ed25519 public key.
§Arguments
key- An Ed25519 public key
§Returns
A new signing public key containing the Ed25519 key
§Examples
use bc_components::{Ed25519PrivateKey, SigningPublicKey};
// Create an Ed25519 private key and get its public key
let private_key = Ed25519PrivateKey::new();
let public_key = private_key.public_key();
// Create a signing public key from it
let signing_key = SigningPublicKey::from_ed25519(public_key);Sourcepub fn from_ssh(key: SSHPublicKey) -> Self
pub fn from_ssh(key: SSHPublicKey) -> Self
Sourcepub fn to_schnorr(&self) -> Option<&SchnorrPublicKey>
pub fn to_schnorr(&self) -> Option<&SchnorrPublicKey>
Returns the underlying Schnorr public key if this is a Schnorr key.
§Returns
Some reference to the Schnorr public key if this is a Schnorr key, or None if it’s a different key type.
§Examples
use bc_components::{SignatureScheme, Signer};
// Create a Schnorr key pair
let (private_key, public_key) = SignatureScheme::Schnorr.keypair();
// We can access the Schnorr public key
assert!(public_key.to_schnorr().is_some());
// Create an ECDSA key pair
let (_, ecdsa_public) = SignatureScheme::Ecdsa.keypair();
// This will return None since it's not a Schnorr key
assert!(ecdsa_public.to_schnorr().is_none());Sourcepub fn to_ecdsa(&self) -> Option<&ECPublicKey>
pub fn to_ecdsa(&self) -> Option<&ECPublicKey>
Returns the underlying ECDSA public key if this is an ECDSA key.
§Returns
Some reference to the ECDSA public key if this is an ECDSA key, or None if it’s a different key type.
Sourcepub fn to_ssh(&self) -> Option<&SSHPublicKey>
pub fn to_ssh(&self) -> Option<&SSHPublicKey>
Returns the underlying SSH public key if this is an SSH key.
§Returns
Some reference to the SSH public key if this is an SSH key, or None if it’s a different key type.
Trait Implementations§
Source§impl AsRef<SigningPublicKey> for PublicKeys
impl AsRef<SigningPublicKey> for PublicKeys
Source§fn as_ref(&self) -> &SigningPublicKey
fn as_ref(&self) -> &SigningPublicKey
Source§impl AsRef<SigningPublicKey> for SigningPublicKey
Implementation of AsRef for SigningPublicKey
impl AsRef<SigningPublicKey> for SigningPublicKey
Implementation of AsRef for SigningPublicKey
Source§fn as_ref(&self) -> &SigningPublicKey
fn as_ref(&self) -> &SigningPublicKey
Returns a reference to self.
Source§impl CBORTagged for SigningPublicKey
Implementation of the CBORTagged trait for SigningPublicKey
impl CBORTagged for SigningPublicKey
Implementation of the CBORTagged trait for SigningPublicKey
Returns the CBOR tags used for this type.
For SigningPublicKey, the tag is 40022.
Source§impl CBORTaggedDecodable for SigningPublicKey
Implementation of the CBORTaggedDecodable trait for SigningPublicKey
impl CBORTaggedDecodable for SigningPublicKey
Implementation of the CBORTaggedDecodable trait for SigningPublicKey
Source§fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
Creates a SigningPublicKey from an untagged CBOR value.
§Arguments
untagged_cbor- The CBOR value to decode
§Returns
A Result containing the decoded SigningPublicKey or an error if decoding fails.
§Format
The CBOR value must be one of:
- A byte string (interpreted as a Schnorr public key)
- An array of length 2, where the first element is a discriminator (1 for ECDSA, 2 for Ed25519) and the second element is a byte string containing the key data
- A tagged value with a tag for ML-DSA or SSH keys
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for SigningPublicKey
Implementation of the CBORTaggedEncodable trait for SigningPublicKey
impl CBORTaggedEncodable for SigningPublicKey
Implementation of the CBORTaggedEncodable trait for SigningPublicKey
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Converts the SigningPublicKey to an untagged CBOR value.
The CBOR encoding depends on the key type:
- Schnorr: A byte string containing the 32-byte x-only public key
- ECDSA: An array containing the discriminator 1 and the 33-byte compressed public key
- Ed25519: An array containing the discriminator 2 and the 32-byte public key
- SSH: A tagged text string containing the OpenSSH-encoded public key
- ML-DSA: Delegates to the MLDSAPublicKey implementation
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Clone for SigningPublicKey
impl Clone for SigningPublicKey
Source§fn clone(&self) -> SigningPublicKey
fn clone(&self) -> SigningPublicKey
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SigningPublicKey
impl Debug for SigningPublicKey
Source§impl From<&SigningPublicKey> for XID
Implements conversion from SigningPublicKey reference to XID.
impl From<&SigningPublicKey> for XID
Implements conversion from SigningPublicKey reference to XID.
Source§fn from(key: &SigningPublicKey) -> Self
fn from(key: &SigningPublicKey) -> Self
Source§impl From<SigningPublicKey> for CBOR
Conversion from SigningPublicKey to CBOR
impl From<SigningPublicKey> for CBOR
Conversion from SigningPublicKey to CBOR
Source§fn from(value: SigningPublicKey) -> Self
fn from(value: SigningPublicKey) -> Self
Converts a SigningPublicKey to a tagged CBOR value.
Source§impl Hash for SigningPublicKey
impl Hash for SigningPublicKey
Source§impl PartialEq for SigningPublicKey
impl PartialEq for SigningPublicKey
Source§impl TryFrom<CBOR> for SigningPublicKey
TryFrom implementation for converting CBOR to SigningPublicKey
impl TryFrom<CBOR> for SigningPublicKey
TryFrom implementation for converting CBOR to SigningPublicKey
Source§impl Verifier for SigningPublicKey
Implementation of the Verifier trait for SigningPublicKey
impl Verifier for SigningPublicKey
Implementation of the Verifier trait for SigningPublicKey
Source§fn verify(&self, signature: &Signature, message: &dyn AsRef<[u8]>) -> bool
fn verify(&self, signature: &Signature, message: &dyn AsRef<[u8]>) -> bool
Verifies a signature against a message.
The type of signature must match the type of this key, and the signature must be valid for the message, or the verification will fail.
§Arguments
signature- The signature to verifymessage- The message that was allegedly signed
§Returns
true if the signature is valid for the message, false otherwise
§Examples
use bc_components::{SignatureScheme, Signer, Verifier};
// Create a key pair
let (private_key, public_key) = SignatureScheme::Schnorr.keypair();
// Sign a message
let message = b"Hello, world!";
let signature = private_key.sign(&message).unwrap();
// Verify the signature with the correct message (should succeed)
assert!(public_key.verify(&signature, &message));
// Verify the signature with an incorrect message (should fail)
assert!(!public_key.verify(&signature, &b"Tampered message"));Source§impl XIDProvider for SigningPublicKey
Implements XIDProvider for SigningPublicKey to generate an XID from the key.
impl XIDProvider for SigningPublicKey
Implements XIDProvider for SigningPublicKey to generate an XID from the key.