gsigner 2.0.0

Universal cryptographic signer supporting secp256k1 (Ethereum), ed25519, and sr25519 (Substrate)
Documentation
// Copyright (C) Gear Technologies Inc.
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0

//! Cryptographic signature scheme implementations.

#[cfg(any(feature = "secp256k1", feature = "sr25519", feature = "ed25519"))]
use crate::scheme::CryptoScheme;

#[cfg(feature = "secp256k1")]
pub mod secp256k1;

#[cfg(feature = "sr25519")]
pub mod sr25519;

#[cfg(feature = "ed25519")]
pub mod ed25519;

/// Enumeration of supported signature schemes.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SchemeType {
    #[cfg(feature = "secp256k1")]
    /// secp256k1 ECDSA (Ethereum).
    Secp256k1,

    #[cfg(feature = "sr25519")]
    /// sr25519 Schnorrkel (Substrate).
    Sr25519,

    #[cfg(feature = "ed25519")]
    /// ed25519 Edwards-curve digital signatures.
    Ed25519,
}

impl SchemeType {
    /// Get the name of the scheme.
    pub fn name(&self) -> &'static str {
        match self {
            #[cfg(feature = "secp256k1")]
            SchemeType::Secp256k1 => <crate::schemes::secp256k1::Secp256k1 as CryptoScheme>::NAME,
            #[cfg(feature = "sr25519")]
            SchemeType::Sr25519 => <crate::schemes::sr25519::Sr25519 as CryptoScheme>::NAME,
            #[cfg(feature = "ed25519")]
            SchemeType::Ed25519 => <crate::schemes::ed25519::Ed25519 as CryptoScheme>::NAME,
            // If no schemes are compiled in, treat this as unreachable.
            #[allow(unreachable_patterns)]
            _ => unreachable!("unsupported signature scheme"),
        }
    }
}