Skip to main content

dig_options/
lib.rs

1//! # dig-options — the DIG Network canonical Chia option-contract expert crate
2//!
3//! `dig-options` is a **pure, key-free, network-free** CoinSpend-builder for Chia covered
4//! options (the CHIP-0042 option primitive). It constructs the exact
5//! [`CoinSpend`](chia_protocol::CoinSpend)s for the option lifecycle — [`create`] (lock an XCH
6//! underlying, mint the option singleton), [`exercise`] (pay the strike, unlock the underlying
7//! to the holder), [`clawback`] (the creator reclaims the underlying after expiry), and
8//! inspect ([`parse`]/[`parse_child`]) — and reports the exact signatures a caller must
9//! produce ([`required_signatures`]).
10//!
11//! ## The custody model (HARD invariants)
12//!
13//! dig-options **never holds a secret key, never signs, and never touches the network.** Every
14//! builder takes only public inputs (an [`Owner`] carrying a public key or a caller-supplied
15//! inner spender, plain [`Bytes32`](chia_protocol::Bytes32) puzzle hashes, coins the caller
16//! already fetched) and appends unsigned coin spends to a caller-owned [`SpendContext`]. The
17//! consumer signs the messages reported by [`required_signatures`], assembles the
18//! `SpendBundle`, and broadcasts. Signing — and the secret key — stay entirely on the caller's
19//! side of the identity boundary (#908).
20//!
21//! ## Scope (v0.1.0)
22//!
23//! The underlying is **XCH**, and the strike is **XCH-only**: [`create`] REJECTS a non-XCH strike
24//! up front so create and [`exercise`] have symmetric support envelopes (no holder can acquire an
25//! option it could never exercise). [`exercise`] builds BOTH settlement legs for an XCH strike —
26//! the underlying is claimed to the holder and the strike is paid to the creator, in one bundle —
27//! and keeps its non-XCH guard as defense-in-depth. [`clawback`] and inspection work for any strike
28//! type curried into an existing option. CAT/revocable-CAT/NFT underlyings and strike are a future
29//! extension. See `SPEC.md` for the normative contract.
30
31#![forbid(unsafe_code)]
32
33mod clawback;
34mod create;
35mod error;
36mod exercise;
37mod hydrate;
38mod sign;
39mod types;
40
41pub use clawback::clawback;
42pub use create::create;
43pub use error::{Error, Result};
44pub use exercise::{exercise, StrikePayment};
45pub use hydrate::{parse, parse_child, ParsedOption};
46pub use sign::required_signatures;
47pub use types::{CreatedOption, OptionSpend, OptionTerms, Owner};
48
49// Re-exports so a consumer need not depend on the SDK directly for the common surface.
50pub use chia_wallet_sdk::driver::{
51    OptionContract, OptionType, OptionUnderlying, SpendContext, SpendWithConditions,
52};
53pub use chia_wallet_sdk::signer::RequiredSignature;
54
55/// The crate's semantic version, surfaced so a consumer can record which builder version
56/// produced a spend.
57#[must_use]
58pub fn version() -> &'static str {
59    env!("CARGO_PKG_VERSION")
60}
61
62#[cfg(test)]
63mod tests {
64    #[test]
65    fn version_is_reported() {
66        assert!(!super::version().is_empty());
67    }
68}