API reference
Types and functions exported by ATL-Core.
Prelude
Import common types with a single statement:
use atl_core::prelude::*;Core types
Receipt
The main structure representing an ATL receipt (.atl file).
pub struct Receipt {
pub spec_version: String,
pub upgrade_url: Option<String>,
pub entry: ReceiptEntry,
pub proof: ReceiptProof,
pub super_proof: Option<SuperProof>,
pub anchors: Vec<ReceiptAnchor>,
}Methods:
Receipt::from_json(&str)— parse receipt from JSON stringreceipt.to_json()— serialize to JSON stringreceipt.tier()— get receipt tier (Full,Tsa,Lite)
ReceiptEntry
pub struct ReceiptEntry {
pub id: Uuid,
pub payload_hash: String,
pub metadata_hash: String,
pub metadata: serde_json::Value,
}ReceiptProof
pub struct ReceiptProof {
pub tree_size: u64,
pub root_hash: String,
pub inclusion_path: Vec<String>,
pub leaf_index: u64,
pub checkpoint: CheckpointJson,
pub consistency_proof: Option<ReceiptConsistencyProof>,
}SuperProof
pub struct SuperProof {
pub genesis_super_root: String,
pub data_tree_index: u64,
pub super_tree_size: u64,
pub super_root: String,
pub inclusion: Vec<String>,
pub consistency_to_origin: Vec<String>,
}ReceiptTier
Receipt completeness levels as defined in the protocol specification:
Lite— nosuper_proof, ORsuper_proofpresent but missing RFC 3161 anchor (internal consistency only)Tsa— hassuper_proof+ RFC 3161 anchor (but no Bitcoin OTS) (Receipt-TSA per spec)Full— hassuper_proof+ RFC 3161 + Bitcoin OTS anchors (Receipt-Full per spec)
For maximum trust, receipts should have both RFC 3161 and Bitcoin OTS anchors (tier Full).
Verification
ReceiptVerifier
// Anchor-only verification (recommended)
let verifier = ReceiptVerifier::anchor_only();
// With optional signature integrity check
let verifier = ReceiptVerifier::with_key(checkpoint_verifier);
// Verify a receipt
let result: VerificationResult = verifier.verify(&receipt);VerificationResult
pub struct VerificationResult {
pub is_valid: bool,
pub leaf_hash: [u8; 32],
pub root_hash: [u8; 32],
pub tree_size: u64,
pub timestamp: u64,
pub signature_valid: bool,
pub signature_status: SignatureStatus,
pub inclusion_valid: bool,
pub consistency_valid: Option<bool>,
pub super_inclusion_valid: bool,
pub super_consistency_valid: bool,
pub genesis_super_root: [u8; 32],
pub super_root: [u8; 32],
pub data_tree_index: u64,
pub super_tree_size: u64,
pub anchor_results: Vec<AnchorVerificationResult>,
pub errors: Vec<VerificationError>,
}Notes:
signature_validis deprecated; prefersignature_statusfor detailed outcome.
Methods:
result.has_valid_anchor()— at least one anchor verified
SignatureMode
Require— signature MUST verify successfullyOptional— verify if key provided, skip otherwise (default)Skip— never verify signature, rely only on anchors
SignatureStatus
Verified— signature checked and validFailed— signature checked and invalidSkipped— signature not checkedKeyMismatch— provided key doesn’t match checkpoint
Verification functions
Anchor-only (recommended):
let result = verify_receipt_anchor_only(&receipt)?;
let result = verify_receipt_json_anchor_only(json_str)?;With public key:
let result = verify_receipt_with_key(&receipt, &public_key_bytes)?;
let result = verify_receipt_json_with_key(json_str, &public_key_bytes)?;Checkpoint
CheckpointVerifier
let verifier = CheckpointVerifier::from_bytes(&public_key_bytes)?;
let checkpoint = Checkpoint::from_json(&checkpoint_json)?;
checkpoint.verify(&verifier)?;Merkle tree
Hash
pub type Hash = [u8; 32];Functions
compute_leaf_hash(payload_hash, metadata_hash)— compute leaf hashcompute_root(leaves)— compute Merkle root from leavesverify_inclusion(...)— verify inclusion proofverify_consistency(...)— verify consistency proof
JCS
let canonical = canonicalize(&json_value);
let hash: Hash = canonicalize_and_hash(&json_value);Error types
AtlError
Main error enum (selected variants):
InvalidHash— invalid hash format or lengthSignatureInvalid— signature verification failedInvalidSignature— invalid signature formatInvalidPublicKey— invalid public key bytesInclusionProofInvalid— inclusion proof verification failedConsistencyProofInvalid— consistency proof verification failedInvalidProofPath— wrong number of hashes in proofInvalidReceipt— receipt JSON parsing failed / missing required fieldsUnsupportedReceiptVersion— unsupportedspec_version
AtlResult<T>
Type alias for Result<T, AtlError>.
Last updated on