Crate zescrow_core

Source
Expand description

§Zescrow Core

Core library for Zescrow: zero-knowledge escrows via the RISC Zero zkVM.

§Modules

  • asset — chain-agnostic asset types (coins, tokens, NFTs, LP shares)
  • condition — cryptographic conditions (hashlocks, signatures, threshold)
  • escrow — off-chain escrow state machine with ZK proofs
  • identity — identity parsing and format conversions (hex, Base58, Base64)
  • interface — schemas, I/O helpers
  • error — typed errors
  • bignum — wrapper around BigUint.
  • serde — JSON (de)serialization helpers (json feature)

§Optional dependencies

FeatureDependencies
bincode (default)bincode (derive)
jsonserde, serde_json, serde_bytes, serde_with

§Quickstart

Add the crate as a dependency in your Cargo.toml (enable the json feature if you want serde support):

[dependencies]
zescrow-core = { version = "0.1", features = ["json"] }
use zescrow_core::{
    Asset, BigNumber, Condition, Escrow, EscrowError, ExecutionState, ID, Party, Result
};
use sha2::{Digest, Sha256};

fn execute_escrow() -> Result<()> {
    let sender = Party::new("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")?;
    let recipient = Party::new("0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8")?;

    let asset = Asset::token(
        ID::from("0xdeadbeef".as_bytes()),
        BigNumber::from(1_000u64),
        BigNumber::from(2_000u64),
        18,
    );

    let preimage = b"secret".to_vec();
    let hash = Sha256::digest(&preimage);
    let condition = Condition::hashlock(hash.into(), preimage);

    let mut escrow = Escrow::new(sender, recipient, asset, Some(condition));
    escrow.state = ExecutionState::Funded; // Advance execution state

    let exec_state = escrow.execute()?;
    if exec_state != ExecutionState::ConditionsMet {
        return Err(EscrowError::InvalidState);
    }

    Ok(())
}

§Documentation

https://docs.rs/zescrow-core

§License

Licensed under either Apache License, Version 2.0
or MIT License at your option.

Re-exports§

pub use asset::Asset;
pub use asset::AssetKind;
pub use bignum::BigNumber;
pub use condition::Condition;
pub use error::EscrowError;
pub use escrow::Escrow;
pub use identity::Party;
pub use identity::ID;
pub use interface::Chain;
pub use interface::ChainConfig;
pub use interface::EscrowMetadata;
pub use interface::EscrowParams;
pub use interface::ExecutionState;

Modules§

asset
Chain-agnostic asset representations and utilities.
bignum
Wrapper around BigUint so we can implement bincode traits.
condition
Deterministic cryptographic conditions and fulfillment logic.
error
Error types used throughout the zescrow_core crate.
escrow
Off-chain escrow context for executing/verifying cryptographic conditions in zero-knowledge.
identity
Chain-agnostic identity types (hex/Base58/Base64/raw bytes) for escrow parties.
interface
Types for JSON (de)serialization, parameter/metadata schemas, and chain configurations.

Type Aliases§

Result
Result type for all core operations.