solana-wasi 0.1.0

Solana primitives that actually compile to wasm32-wasip2: pubkeys, PDAs, JSON-RPC over a swappable transport, SPL Token / Token-2022 account parsing, and unsigned v0 transaction construction. No solana-sdk, no C toolchain, no async runtime.
Documentation
//! One error type for the whole crate.
//!
//! Deliberately hand-rolled rather than `thiserror`-derived: the dependency
//! footprint of a WIT component is the thing an operator audits, and this saves
//! a proc-macro crate for about forty lines of `Display`.

use core::fmt;

/// Everything that can go wrong inside `solana-wasi`.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
    /// A base58 string was not a valid 32-byte public key.
    InvalidPubkey(String),
    /// An account's data did not match the layout it was parsed as.
    InvalidAccountData(String),
    /// The transport refused or failed the request.
    Transport(String),
    /// The node answered with a JSON-RPC `error` member.
    Rpc {
        /// JSON-RPC error code.
        code: i64,
        /// Server-supplied message, truncated to 200 characters.
        message: String,
    },
    /// The node answered with JSON that did not match the expected shape.
    UnexpectedResponse(String),
    /// A requested account does not exist on the cluster.
    AccountNotFound(String),
    /// Seeds could not be turned into a program address.
    InvalidSeeds(&'static str),
    /// A caller-supplied value was rejected before any network call.
    InvalidArgument(String),
    /// A transaction could not be encoded (too many accounts, oversized, ...).
    Encode(String),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::InvalidPubkey(s) => write!(f, "invalid pubkey: {s}"),
            Error::InvalidAccountData(s) => write!(f, "invalid account data: {s}"),
            Error::Transport(s) => write!(f, "transport error: {s}"),
            Error::Rpc { code, message } => write!(f, "rpc error {code}: {message}"),
            Error::UnexpectedResponse(s) => write!(f, "unexpected rpc response: {s}"),
            Error::AccountNotFound(s) => write!(f, "account not found: {s}"),
            Error::InvalidSeeds(s) => write!(f, "invalid seeds: {s}"),
            Error::InvalidArgument(s) => write!(f, "invalid argument: {s}"),
            Error::Encode(s) => write!(f, "encode error: {s}"),
        }
    }
}

impl std::error::Error for Error {}

/// Crate-wide result alias.
pub type Result<T> = core::result::Result<T, Error>;