SigningPublicKey

Enum SigningPublicKey 

Source
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

Source

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);
Source

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);
Source

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);
Source

pub fn from_ssh(key: SSHPublicKey) -> Self

Creates a new signing public key from an SSH public key.

§Arguments
  • key - An SSH public key
§Returns

A new signing public key containing the SSH key

Source

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());
Source

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.

Source

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

Source§

fn as_ref(&self) -> &SigningPublicKey

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<SigningPublicKey> for SigningPublicKey

Implementation of AsRef for SigningPublicKey

Source§

fn as_ref(&self) -> &SigningPublicKey

Returns a reference to self.

Source§

impl CBORTagged for SigningPublicKey

Implementation of the CBORTagged trait for SigningPublicKey

Source§

fn cbor_tags() -> Vec<Tag>

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

Source§

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,

Creates an instance of this type by decoding it from tagged CBOR. Read more
Source§

fn from_tagged_cbor_data(data: impl AsRef<[u8]>) -> Result<Self, Error>
where Self: Sized,

Creates an instance of this type by decoding it from binary encoded tagged CBOR. Read more
Source§

fn from_untagged_cbor_data(data: impl AsRef<[u8]>) -> Result<Self, Error>
where Self: Sized,

Creates an instance of this type by decoding it from binary encoded untagged CBOR. Read more
Source§

impl CBORTaggedEncodable for SigningPublicKey

Implementation of the CBORTaggedEncodable trait for SigningPublicKey

Source§

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

Returns the tagged CBOR encoding of this instance. Read more
Source§

fn tagged_cbor_data(&self) -> Vec<u8>

Returns the tagged value in CBOR binary representation. Read more
Source§

impl Clone for SigningPublicKey

Source§

fn clone(&self) -> SigningPublicKey

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SigningPublicKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SigningPublicKey

Source§

fn fmt(&self, _f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&SigningPublicKey> for XID

Implements conversion from SigningPublicKey reference to XID.

Source§

fn from(key: &SigningPublicKey) -> Self

Converts to this type from the input type.
Source§

impl From<SigningPublicKey> for CBOR

Conversion from SigningPublicKey to CBOR

Source§

fn from(value: SigningPublicKey) -> Self

Converts a SigningPublicKey to a tagged CBOR value.

Source§

impl Hash for SigningPublicKey

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SigningPublicKey

Source§

fn eq(&self, other: &SigningPublicKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl ReferenceProvider for SigningPublicKey

Source§

fn reference(&self) -> Reference

Returns a cryptographic reference that uniquely identifies this object. Read more
Source§

fn ref_hex(&self) -> String

Returns the reference data as a hexadecimal string. Read more
Source§

fn ref_data_short(&self) -> [u8; 4]

Returns the first four bytes of the reference. Read more
Source§

fn ref_hex_short(&self) -> String

Returns the first four bytes of the reference as a hexadecimal string. Read more
Source§

fn ref_bytewords(&self, prefix: Option<&str>) -> String

Returns the first four bytes of the reference as upper-case ByteWords. Read more
Source§

fn ref_bytemoji(&self, prefix: Option<&str>) -> String

Returns the first four bytes of the reference as Bytemoji. Read more
Source§

impl TryFrom<CBOR> for SigningPublicKey

TryFrom implementation for converting CBOR to SigningPublicKey

Source§

fn try_from(cbor: CBOR) -> Result<Self>

Tries to convert a CBOR value to a SigningPublicKey.

This is a convenience method that calls from_tagged_cbor.

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl Verifier for SigningPublicKey

Implementation of the Verifier trait for SigningPublicKey

Source§

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 verify
  • message - 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.

Source§

fn xid(&self) -> XID

Returns the XID for this object.
Source§

impl Eq for SigningPublicKey

Source§

impl StructuralPartialEq for SigningPublicKey

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CBORDecodable for T
where T: TryFrom<CBOR, Error = Error>,

Source§

fn try_from_cbor(cbor: &CBOR) -> Result<Self, Error>

Source§

impl<T> CBOREncodable for T
where T: Into<CBOR> + Clone,

Source§

fn to_cbor(&self) -> CBOR

Converts this value to a CBOR object. Read more
Source§

fn to_cbor_data(&self) -> Vec<u8>

Converts this value directly to binary CBOR data. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> URDecodable for T

Source§

fn from_ur(ur: impl AsRef<UR>) -> Result<Self, Error>
where Self: Sized,

Source§

fn from_ur_string(ur_string: impl Into<String>) -> Result<Self, Error>
where Self: Sized,

Source§

impl<T> UREncodable for T

Source§

fn ur(&self) -> UR

Returns the UR representation of the object.
Source§

fn ur_string(&self) -> String

Returns the UR string representation of the object.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> CBORCodable for T

Source§

impl<T> CBORTaggedCodable for T

Source§

impl<T> URCodable for T