Skip to main content

Crate r402_casper

Crate r402_casper 

Source
Expand description

Casper chain support for the x402 payment protocol.

This crate implements the x402 “exact” payment scheme for the Casper Network, settling in wCSPR — a CEP-18 token — through the contract’s transfer_with_authorization entry point.

§Features

  • CAIP-2 Addressing: casper:casper (mainnet) and casper:casper-test (testnet)
  • CEP-18 Payments: token transfers authorised by an EIP-712 TransferWithAuthorization signature, relayed and gas-paid by the facilitator
  • Exact Mote Arithmetic: CSPR has 9 decimals; every conversion is integer-only and sub-mote precision is a typed error, never a silent truncation (see Motes)
  • Key Validation: tagged Casper addressable keys (00 account hash, 01 hash) and public keys (01 ed25519, 02 secp256k1)
  • Facilitator Client: /verify, /settle, and /supported against the hosted Casper facilitator, overridable via config or environment

§Architecture

The crate mirrors the layout of the sibling chain crates:

  • chain — Casper chain types (references, addresses, deployments)
  • exact — the Casper “exact” payment scheme
  • motes — exact 9-decimal base-unit arithmetic
  • hex — minimal hex codec for Casper wire values

§Feature Flags

  • server — server-side price tag generation
  • client — client-side authorisation assembly
  • facilitator — facilitator client for verify/settle/supported
  • telemetry — tracing instrumentation

§Example

use r402_casper::chain::Address;
use r402_casper::{CasperExact, WCSPR};

let pay_to: Address = "00fedcba0987654321fedcba0987654321fedcba0987654321fedcba0987654321"
    .parse()
    .unwrap();
// 1.5 wCSPR, expressed exactly in motes.
let tag = CasperExact::price_tag(pay_to, WCSPR::casper_test().amount(1_500_000_000));
assert_eq!(tag.requirements.network.to_string(), "casper:casper-test");

Re-exports§

pub use exact::CasperExact;
pub use exact::facilitator::ReqwestTransport;http-client
pub use exact::facilitator::CasperExactFacilitator;facilitator
pub use exact::facilitator::CasperFacilitatorConfig;facilitator
pub use exact::CasperExactClient;client
pub use exact::CasperSigner;client
pub use exact::Eip712Domain;client
pub use motes::CSPR_DECIMALS;
pub use motes::MOTES_PER_CSPR;
pub use motes::Motes;
pub use motes::MotesParseError;

Modules§

chain
Casper chain support for x402 payments.
exact
Casper “exact” payment scheme implementation.
hex
Minimal, dependency-free hex helpers.
motes
Exact integer arithmetic for CSPR motes.

Structs§

WCSPR
Ergonomic accessors for wCSPR token deployments on well-known Casper chains.

Constants§

CASPER_DOCS_URL
Public JSON-RPC endpoint documentation for the Casper facilitator stack.
WCSPR_NAME
EIP-712 domain name of the wCSPR CEP-18 contract.
WCSPR_VERSION
EIP-712 domain version of the wCSPR CEP-18 contract.

Statics§

CASPER_NETWORKS
Well-known Casper networks with their names and CAIP-2 identifiers.

Functions§

wcspr_casper_deployment
Returns the wCSPR deployment for a specific Casper chain, if known.
wcspr_casper_deployments
Returns all known wCSPR deployments on Casper chains.