zera-sdk 0.1.0

Rust SDK for ZERA transactions, validator APIs, and bridge workflows
Documentation
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum KeyType {
    Ed25519,
    Ed448,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Ord, PartialOrd)]
#[serde(rename_all = "kebab-case")]
pub enum HashType {
    Sha3_256,
    Sha3_512,
    Blake3,
}

pub const VALID_KEY_TYPES: [KeyType; 2] = [KeyType::Ed25519, KeyType::Ed448];
pub const VALID_HASH_TYPES: [HashType; 3] =
    [HashType::Sha3_256, HashType::Sha3_512, HashType::Blake3];

pub const SMART_CONTRACT_PREFIX: &str = "sc_";
pub const GOVERNANCE_PREFIX: &str = "gov_";

impl KeyType {
    pub fn as_str(self) -> &'static str {
        match self {
            KeyType::Ed25519 => "ed25519",
            KeyType::Ed448 => "ed448",
        }
    }

    pub fn prefix(self) -> &'static str {
        match self {
            KeyType::Ed25519 => "A",
            KeyType::Ed448 => "B",
        }
    }
}

impl HashType {
    pub fn as_str(self) -> &'static str {
        match self {
            HashType::Sha3_256 => "sha3-256",
            HashType::Sha3_512 => "sha3-512",
            HashType::Blake3 => "blake3",
        }
    }

    pub fn prefix(self) -> &'static str {
        match self {
            HashType::Sha3_256 => "a",
            HashType::Sha3_512 => "b",
            HashType::Blake3 => "c",
        }
    }
}

pub fn is_valid_key_type(value: &str) -> bool {
    matches!(value, "ed25519" | "ed448")
}

pub fn is_valid_hash_type(value: &str) -> bool {
    matches!(value, "sha3-256" | "sha3-512" | "blake3")
}

pub fn parse_key_type(value: &str) -> Option<KeyType> {
    match value {
        "ed25519" => Some(KeyType::Ed25519),
        "ed448" => Some(KeyType::Ed448),
        _ => None,
    }
}

pub fn parse_hash_type(value: &str) -> Option<HashType> {
    match value {
        "sha3-256" => Some(HashType::Sha3_256),
        "sha3-512" => Some(HashType::Sha3_512),
        "blake3" => Some(HashType::Blake3),
        _ => None,
    }
}