AI Agent Bitcoin Escrow Library
A Rust library that enables AI agents to create, manage, and execute Bitcoin escrow contracts using multisig. The library supports condition-based fund releases triggered by AI agent decisions or external oracles, with full audit logging for all actions.
Features
- Multisig Support: 2-of-3 (or n-of-m) multisig escrow contracts
- Condition-Based Release: AI decisions, oracle triggers, timelocks
- Audit Logging: Immutable, chained audit log for all operations
- Oracle Integration: HTTP-based oracle support for real-world data
- AI Agent Autonomy: Designed for autonomous AI agent economic activities
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
use Network;
// Create an escrow manager with audit logging
let audit = new.unwrap;
let mut manager = new;
// Create participants (buyer, seller, arbiter)
let = create_participant.unwrap;
let = create_participant.unwrap;
let = create_participant.unwrap;
// Build an escrow contract
let contract = new
.network
.threshold // 2-of-3 multisig
.participant
.participant
.participant
.description
.condition
.build
.unwrap;
// Initialize the multisig wallet
contract.initialize_multisig.unwrap;
let escrow_address = contract.escrow_address.unwrap;
println!;
Architecture
The library is organized into several modules:
escrow - Main escrow contract management
EscrowContract- Represents an escrow contractEscrowManager- Manages multiple contracts with audit loggingEscrowBuilder- Builder pattern for creating contracts
multisig - Multisignature wallet operations
MultisigWallet- Multisig wallet with participant keysMultisigPSBT- Partially signed transaction coordinationcreate_participant()- Helper to create participants with generated keys
conditions - Release condition evaluation
ConditionEvaluator- Trait for evaluating conditionsStandardEvaluator- Built-in evaluator with oracle/AI supportConditionBuilder- Builder for compound conditions
audit - Immutable audit logging
AuditLogger- Append-only log with integrity chainAuditEntry- Individual log entries- Integrity verification for audit trail
oracle - External oracle integration
HTTPOracle- HTTP-based oracle implementationOracleRegistry- Registry of known oracles- Predefined oracle configurations for common use cases
types - Common types and structures
EscrowId,AgentId,OracleId- IdentifiersEscrowRole,EscrowStatus- Enums for contract stateReleaseCondition- Condition types for fund release
Condition Types
AI Decision
Trigger release based on an AI agent's decision:
use ConditionBuilder;
let condition = new
.ai_decision
.build_single
.unwrap;
Oracle Trigger
Release based on external data (e.g., price feeds):
let condition = new
.oracle
.build_single
.unwrap;
Timelock
Release after a specific time:
let condition = new
.timelock
.build_single
.unwrap;
Compound Conditions (AND/OR)
// All conditions must be satisfied (AND)
let condition = new
.ai_decision
.timelock
.build_all;
// Any condition can be satisfied (OR)
let condition = new
.oracle
.timelock
.build_any;
Audit Logging
All operations are logged with an immutable chain for transparency:
// Export audit log
let json = manager.export_audit.unwrap;
println!;
// Verify integrity
let logger = manager.audit;
assert!;
AI Agent Autonomy
This library is designed to support AI agent autonomy:
- Self-Custody: AI agents generate and control their own keys
- Verifiable Actions: All operations are logged in an immutable audit log
- Conditional Releases: Funds can be released based on AI decisions
- Oracle Integration: Real-world data can trigger autonomous actions
Security Considerations
- Private Keys: Store securely (consider HSM integration for production)
- Audit Log: Provides verifiable record of all actions
- Multisig: No single party can unilaterally control funds
- Timelocks: Safety mechanism for dispute resolution
Testing
Run the test suite:
Run with verbose output:
Documentation
Generate documentation:
Examples
See the examples/ directory for more usage examples:
basic_escrow.rs- Basic escrow creation and managementoracle_integration.rs- Using oracles for condition triggersai_decision.rs- AI agent decision-based releases
Roadmap
- Taproot support (MuSig2)
- Lightning Network integration
- Hardware Security Module (HSM) integration
- Zero-knowledge proof conditions
- Cross-chain support
Contributing
Contributions are welcome! Please read our contributing guidelines.
License
Dual-licensed under:
- MIT License (LICENSE-MIT)
- Apache License, Version 2.0 (LICENSE-APACHE)
Acknowledgments
This library is built on:
Built for the AI Union bounty program. Enabling AI agents to participate in the Bitcoin economy autonomously.