Skip to main content

Crate paralock

Crate paralock 

Source
Expand description

§paralock

The Rust SDK of Paralock: trustless swaps between ZEC and stablecoins on EVM chains (Tempo, Base, Ethereum, Arbitrum, Robinhood Chain, HyperEVM). A lock on each chain and one secret open both: either both sides settle or both refund. No bridge, custodian or wrapped token.

Embed a market maker (Maker, served with maker_router) or a taker (Taker) in a Rust server without a Node process. The engines are a port of the TypeScript @paralock/sdk (protocol v1.1) and interoperate with it on the wire: a Rust taker swaps with a TypeScript maker and the other way around. All protocol logic (scripts, transactions, signatures, adaptor signatures, ids, digests, wire messages and the safety checks) comes from paralock_core; this crate adds I/O: node clients, stores, HTTP, and the persisted state machines.

Status: experimental and not formally audited. The Zcash leg is transparent in both modes.

Trust model. The protocol protects each party from the other, but each one trusts its own nodes: the taker reveals its secret after checking the maker’s lock through its EVM RPC endpoint (see TakerChain::verifier for a quorum of two), and the maker locks its stablecoins on what its Zcash backend reports about the funding (a lightwalletd / Zaino server does no proof-of-work verification). Run your own nodes for real funds; builder’s module docs (feature evm) have the details.

Re-exports§

pub use api::MakerApi;
pub use builder::create_maker;evm
pub use builder::create_taker;evm
pub use error::Error;
pub use error::Result;
pub use evm::AdaptorEvmClient;
pub use evm::AdaptorOutcome;
pub use evm::ChainClients;
pub use evm::ChainInfo;
pub use evm::EvmClient;
pub use evm::EvmError;
pub use evm::EvmLock;
pub use evm::HtlcOutcome;
pub use evm::RelayerClients;
pub use evm::SentTx;
pub use evm::TakerChain;
pub use evm::TxHash;
pub use evm::TxStatus;
pub use evm::VerifierClients;
pub use http::ClientAddress;server
pub use http::CorsOrigins;server
pub use http::RateLimit;server
pub use http::ServerOptions;server
pub use http::maker_router;server
pub use http::serve;server
pub use http::serve_with_shutdown;server
pub use http::HttpMakerApi;client
pub use http::HttpMakerApiOptions;client
pub use lightwalletd::Lightwalletd;lightwalletd
pub use lightwalletd::LightwalletdOptions;lightwalletd
pub use maker::AfterClaim;
pub use maker::Inventory;
pub use maker::Maker;
pub use maker::MakerConfig;
pub use maker::MakerStage;
pub use maker::MakerSwapRecord;
pub use maker::MakerUpdateHook;
pub use maker::public_view;
pub use price::CoinGecko;price-feed
pub use price::CoinGeckoOptions;price-feed
pub use price::FixedPrice;
pub use price::PriceFn;
pub use price::PriceSource;
pub use runtime::Clock;
pub use runtime::DEFAULT_USER_AGENT;
pub use runtime::Entropy;
pub use runtime::OsEntropy;
pub use runtime::SystemClock;
pub use store::FileStore;
pub use store::MemoryStore;
pub use store::StoreError;
pub use store::SwapStore;
pub use taker::DEFAULT_MAKER_FEE_ZAT;
pub use taker::DEFAULT_TAKER_LIMITS;
pub use taker::DEFAULT_TAKER_TIMEOUTS;
pub use taker::ResumeOptions;
pub use taker::SwapOptions;
pub use taker::Taker;
pub use taker::TakerConfig;
pub use taker::TakerLimits;
pub use taker::TakerPriceCheck;
pub use taker::TakerStage;
pub use taker::TakerSwapRecord;
pub use taker::TakerTimeouts;
pub use zcash::NodeError;
pub use zcash::ZcashNode;
pub use zcash::ZcashRpc;
pub use zcash::ZcashRpcOptions;
pub use paralock_core;
pub use paralock_evm;evm

Modules§

api
How a taker talks to a maker: in-process (crate::Maker) or over HTTP (HttpMakerApi, feature client).
builderevm
Plain configuration → engines: create_taker and create_maker (the TypeScript createTaker / createMaker). They connect a Zcash backend, the EVM escrow clients of paralock-evm (feature evm), the maker client and a store. For other EVM client libraries or custody APIs, build a TakerConfig / MakerConfig with your own trait objects instead.
error
The SDK’s error type.
evm
What the swap engines need from an EVM chain: EvmClient (ParalockHTLC, htlc mode) and AdaptorEvmClient (ParalockAdaptorEscrow, private mode), mirroring @paralock/sdk’s evm-client.ts. With the evm feature, crate::evm_adapter implements them over paralock-evm (alloy); implement them yourself to plug in another client library, a custody API or a KMS.
evm_adapterevm
The engine traits (EvmClient, AdaptorEvmClient) over paralock-evm’s alloy clients for both escrows (feature evm). Tempo fee tokens, nonce management, transaction simulation, receipts, fee bumps and event scans are paralock-evm’s; this module only converts types.
http
The maker HTTP API: the axum server (feature server) and the reqwest client (feature client).
lightwalletdlightwalletd
A ZcashNode over a lightwalletd-compatible gRPC server (lightwalletd or Zaino), so swaps don’t need a full node. The protos are vendored from packages/lightwalletd/proto (see proto/).
maker
The market-maker engine: quotes, commitments (htlc accepts and adaptor proposals), and a persisted settlement state machine per swap (watch the funding, lock the stablecoins, claim the ZEC or refund), resumed by Maker::start after a restart. A port of @paralock/sdk’s Maker (protocol v1.1).
price
USD/ZEC prices: what the maker quotes from and what the taker checks quotes against.
records
Serde building blocks shared by the taker’s and the maker’s persisted records, and their versioning.
runtime
Time and randomness, injectable so the engines can be tested deterministically, plus the retry backoff they share.
store
Durable storage for swap state.
taker
The taker engine: validates quotes, prepares and persists the funding, has the maker commit before any ZEC moves (protocol v1.1), broadcasts, verifies the maker’s lock and claims; resumes and refunds from the store after a restart. A port of @paralock/sdk’s Taker.
zcash
The Zcash backend the engines need (ZcashNode) and its implementations: ZcashRpc (Zebra / Zakura JSON-RPC) and, with the lightwalletd feature, crate::lightwalletd::Lightwalletd (lightwalletd / Zaino gRPC).

Structs§

ClaimLimits
The taker’s floors on the time left to claim and on the EVM lock’s confirmations (spec §7.3, §7.4, §7.6). Constructed with ClaimLimits::new, which refuses values below MIN_CLAIM_WINDOW_SECONDS and MIN_EVM_CONFIRMATIONS; going below them takes the explicit ClaimLimits::new_below_floor.
Hex
0x-prefixed hex with an even number of digits (the TypeScript Hex). The original letter case is preserved, so re-serializing a parsed message reproduces it exactly.
MakerLimits
Per-swap and capacity limits of a maker (MakerLimits).
ParalockError
An expected failure with a stable ParalockErrorCode. Messages are safe to show to a counterparty: they never include keys, secrets or internal details.
PrivacyOptions
Level-1 privacy options. None of them hides the link between the two legs of one swap (adaptor mode does that); they keep a swap from linking to the rest of your activity.
Quote
A maker’s offer. Deserialize runs super::parse_quote (shape only); check a quote with super::validate_quote before acting on it.
QuoteLimits
Bounds a taker enforces on every quote before locking anything.
Swap
Public view of a swap. Never contains secrets or private keys. Fields serialize in the order the engines build them (id, quote, mode, status, zcash, evm, events, then the optional ones).
TimeoutPolicy
Timeout policy. Safety rule: the EVM lock (the maker’s money) must expire well before the Zcash refund height (the taker’s money), so whoever learns the secret always has time to use it on the other chain.
TimeoutPolicyParams
The values of a TimeoutPolicy, before validation.

Enums§

EvmChain
The EVM chains a swap can settle on (each name works with any chain id where the escrows are deployed).
Network
A Zcash network. Regtest shares address prefixes with Testnet.
ParalockErrorCode
Machine-readable error codes. Each maps to an HTTP status (ParalockErrorCode::status).
SwapMode
htlc (shared sha256 hashlock) or adaptor (private mode: adaptor signatures, no shared value on-chain).
SwapStatus
Public progress of a swap, as both parties report it.

Constants§

DEVNET_POLICY
Short windows so refunds can be demoed; the devnet mines a Zcash block every few seconds.
MAINNET_POLICY
Production defaults: ~3 h Zcash window at 75 s blocks, 1 h EVM lock, 2 confirmations.

Traits§

SwapStatusExt
as_str for SwapStatus: its wire name (quoted, zcash_locked, evm_locked, evm_claimed, completed, refunded_zcash, refunded_evm, failed).