Overview
About the Library
The Transaction library is a low-level component of the client-side SDK. It provides a comprehensive toolkit for building, signing, and broadcasting Bitcoin transactions on the OP_NET network. It implements a hybrid classical and quantum cryptographic model, pairing secp256k1 keys for Taproot and SegWit compatibility with ML-DSA keys for post-quantum resistance. The library handles UTXO management, fee estimation, binary serialization, ABI encoding, and supports multiple address formats including P2TR, P2MR, P2WPKH, P2PKH, P2OP, and P2WDA. Separate builds for Node.js and browser environments ensure seamless integration across platforms.
Key Components
Transaction Building
The TransactionFactory class serves as the primary entry point for creating all transaction types. It manages UTXO selection, fee estimation, and signing. Supported types include BTC transfers, contract deployments, contract interactions, multi-signature transactions, custom scripts, cancellations, and consolidated commitment-based interactions.
Key Pair & Wallet Management
OP_NET employs a hybrid key model where every wallet contains both secp256k1 and ML-DSA key pairs. The Address class wraps quantum-resistant public key hashes. EcKeyPair handles classical key creation, Wallet unifies both key types, MessageSigner provides signing with auto-detection, and AddressVerificator validates addresses.
Mnemonic & HD Derivation
The Mnemonic class generates BIP39 mnemonic phrases with BIP360 quantum key derivation. It enables deriving multiple wallets from a single seed phrase, each containing both classical and quantum keys.
Binary Serialization
The BinaryWriter and BinaryReader classes serialize and deserialize primitives, strings, arrays, maps, and addresses for contract calldata, event decoding, and protocol interactions.
ABI Encoding
The ABICoder class provides Ethereum-style ABI encoding and decoding for OP_NET smart contracts, supporting function selectors, parameter encoding, and return value parsing.
Address Types
OP_NET supports multiple address formats: P2OP for smart contracts, P2WDA for quantum-authenticated witnesses, P2MR for quantum-safe outputs, and standard formats including P2TR, P2WPKH, P2PKH, and P2SH.
Signer Utilities
Advanced signing utilities include TweakedSigner for Taproot key tweaking, address rotation for per-UTXO signing with different keys, and ParallelSigner for concurrent multi-input signing.
Offline Transactions
The offline signing system enables air-gapped workflows by exporting partially-signed transactions, signing on isolated machines, and importing for broadcast. Supports RBF fee bumping and multi-signature coordination.
UTXO Management
The OPNetLimitedProvider class fetches UTXOs and broadcasts transactions. It serves as the default provider for TransactionFactory, handling UTXO selection and spent output tracking.
Browser Integration
The Web3Provider class provides a generic browser wallet interface. Built-in adapters for Unisat and Xverse wallet extensions enable seamless integration with popular Bitcoin wallets.
Epoch & Challenges
The ChallengeSolution class constructs epoch challenge solutions, while EpochValidator validates epochs and verifies proofs for network consensus.
Deterministic Collections
Map and set implementations with guaranteed iteration order for consensus-critical code. Includes AddressMap, AddressSet, DeterministicMap, and FastMap for non-consensus contexts.
Script Generators
Low-level script builders used internally by TransactionFactory for deployment scripts, calldata, custom witnesses, multi-signature scripts, and P2WDA scripts.
Quantum Support (ML-DSA)
OP_NET implements ML-DSA for post-quantum cryptography with security levels LEVEL2, LEVEL3, and LEVEL5. BIP39 combined with BIP360 enables deterministic generation of both classical and quantum keys. P2MR provides quantum-safe outputs via Merkle root commitment.
Utilities
Helper modules including BitcoinUtils for satoshi conversion, BufferHelper for hex and bigint conversions, Compressor for bytecode compression, and type aliases with byte length constants.