torvyon-core 0.1.2

Keys, addresses, post-quantum signing and transaction building for the Torvyon blockchain
Documentation
/// Result type for this crate.
pub type Result<T> = std::result::Result<T, Error>;

/// Everything that can go wrong. Messages match the node's error text where
/// the node has an equivalent check.
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
    /// ML-DSA-65 key material has an invalid length or encoding.
    #[error("invalid ML-DSA-65 key")]
    InvalidPQKey,
    /// ML-DSA-65 signature has an invalid length or encoding.
    #[error("invalid ML-DSA-65 signature")]
    InvalidPQSignature,
    /// Not a valid secp256k1 private key.
    #[error("invalid private key")]
    InvalidPrivateKey,
    /// Public key is not 32 bytes or not a valid curve point.
    #[error("invalid public key length")]
    InvalidPublicKey,
    /// Recovery phrase is not a valid 24-word BIP39 phrase for a valid key.
    #[error("invalid recovery phrase")]
    InvalidMnemonic,
    /// Address has the wrong length.
    #[error("invalid address length")]
    AddressLength,
    /// Address does not start with `bt1`.
    #[error("invalid address prefix")]
    AddressPrefix,
    /// Address payload is not hex.
    #[error("invalid address payload")]
    AddressPayload,
    /// Address checksum does not match.
    #[error("invalid address checksum")]
    AddressChecksum,
    /// Signature is malformed or does not verify.
    #[error("invalid signature")]
    InvalidSignature,
    /// Transaction has no chain ID.
    #[error("missing chain id")]
    MissingChainId,
    /// UTXO transaction has no inputs.
    #[error("utxo transaction has no inputs")]
    NoInputs,
    /// UTXO transaction has no outputs.
    #[error("utxo transaction has no outputs")]
    NoOutputs,
    /// Data payload is larger than [`tx::MAX_DATA_SIZE`](crate::tx::MAX_DATA_SIZE).
    #[error("data payload is {0} bytes, max is 512")]
    DataTooLarge(usize),
    /// Output has no script.
    #[error("utxo output {0} missing script_pub_key")]
    MissingScript(usize),
    /// Output script fails canonicalization.
    #[error("utxo output {0} has an invalid script_pub_key")]
    InvalidScript(usize),
    /// Spending condition is malformed or exceeds consensus limits.
    #[error("invalid condition: {0}")]
    InvalidCondition(String),
    /// Atomic swap parameters are unsafe or invalid.
    #[error("invalid atomic swap: {0}")]
    InvalidSwap(String),
    /// Output value is zero.
    #[error("utxo output {0} has zero value")]
    ZeroValue(usize),
    /// `from` is not the address of the public key.
    #[error("from address does not match public key")]
    FromMismatch,
    /// Signature scheme is not supported.
    #[error("unknown signature scheme")]
    UnknownScheme,
    /// Transaction version is not 0, 2 or 3.
    #[error("unsupported transaction version: {0}")]
    UnsupportedVersion(u32),
    /// Spendable UTXOs do not cover amount + fee.
    #[error("insufficient funds: need {need}, have {have}")]
    InsufficientFunds {
        /// Amount + fee in nibbles.
        need: u64,
        /// Total of all spendable UTXOs in nibbles.
        have: u64,
    },
    /// Covering the amount would need more than [`tx::MAX_INPUTS`](crate::tx::MAX_INPUTS) inputs.
    #[error("payment needs more than {0} inputs; consolidate UTXOs first")]
    TooManyInputs(usize),
    /// Arithmetic overflow on amounts.
    #[error("amount overflow")]
    AmountOverflow,
    /// Amount string could not be parsed.
    #[error("invalid amount")]
    InvalidAmount,
    /// Network name is not supported.
    #[error("invalid network")]
    InvalidNetwork,
    /// Wire JSON could not be decoded.
    #[error("invalid transaction json: {0}")]
    Json(String),
}