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), [`transfer`] (move the option ticket to a new owner), [`clawback`] (the
8//! creator reclaims the underlying after expiry), and inspect ([`parse`]/[`parse_child`]) — and
9//! reports the exact signatures a caller must produce ([`required_signatures`]).
10//!
11//! It also [`rehydrate`]s a previously-minted option: [`parse`] recovers only an option's
12//! identity fields, so [`rehydrate`] reconstructs the full operable [`CreatedOption`] from
13//! caller-observed terms + the launcher metadata ([`parse_metadata`]) and VERIFIES it against the
14//! option's on-chain commitments, letting a caller exercise/transfer/claw back an option it did
15//! not mint in the same session.
16//!
17//! ## The custody model (HARD invariants)
18//!
19//! dig-options **never holds a secret key, never signs, and never touches the network.** Every
20//! builder takes only public inputs (an [`Owner`] carrying a public key or a caller-supplied
21//! inner spender, plain [`Bytes32`](chia_protocol::Bytes32) puzzle hashes, coins the caller
22//! already fetched) and appends unsigned coin spends to a caller-owned [`SpendContext`]. The
23//! consumer signs the messages reported by [`required_signatures`], assembles the
24//! `SpendBundle`, and broadcasts. Signing — and the secret key — stay entirely on the caller's
25//! side of the identity boundary (#908).
26//!
27//! ## Scope (v0.1.0)
28//!
29//! The underlying is **XCH**, and the strike is **XCH-only**: [`create`] REJECTS a non-XCH strike
30//! up front so create and [`exercise`] have symmetric support envelopes (no holder can acquire an
31//! option it could never exercise). [`exercise`] builds BOTH settlement legs for an XCH strike —
32//! the underlying is claimed to the holder and the strike is paid to the creator, in one bundle —
33//! and keeps its non-XCH guard as defense-in-depth. [`clawback`] and inspection work for any strike
34//! type curried into an existing option. CAT/revocable-CAT/NFT underlyings and strike are a future
35//! extension. See `SPEC.md` for the normative contract.
36
37#![forbid(unsafe_code)]
38
39mod clawback;
40mod create;
41mod error;
42mod exercise;
43mod hydrate;
44mod rehydrate;
45mod sign;
46mod transfer;
47mod types;
48
49pub use clawback::clawback;
50pub use create::create;
51pub use error::{Error, Result};
52pub use exercise::{exercise, StrikePayment};
53pub use hydrate::{parse, parse_child, ParsedOption};
54pub use rehydrate::{parse_metadata, rehydrate, OptionMetadata, RehydratedTerms};
55pub use sign::required_signatures;
56pub use transfer::transfer;
57pub use types::{CreatedOption, OptionSpend, OptionTerms, Owner};
58
59// Re-exports so a consumer need not depend on the SDK directly for the common surface.
60pub use chia_wallet_sdk::driver::{
61    OptionContract, OptionType, OptionUnderlying, SpendContext, SpendWithConditions,
62};
63pub use chia_wallet_sdk::signer::RequiredSignature;
64
65/// The crate's semantic version, surfaced so a consumer can record which builder version
66/// produced a spend.
67#[must_use]
68pub fn version() -> &'static str {
69    env!("CARGO_PKG_VERSION")
70}
71
72#[cfg(test)]
73mod tests {
74    #[test]
75    fn version_is_reported() {
76        assert!(!super::version().is_empty());
77    }
78}