Architecture
btx is layered so the cryptographic core can be tested offline, while transaction interpretation and network access remain explicit boundaries.
Layers
Field and curve
Finite-field arithmetic, secp256k1 points, serialization, and pluggable native/libsecp backends.
Encoding
Hex, varints, DER, SEC keys, tagged hashes, and byte-level readers with bounded parsing.
Bitcoin models
Transactions, scripts, sighashes, descriptors, and PSBTs depend on the lower-level primitives.
Signature analysis
Extraction, verification, linearization, deterministic signing, and nonce-reuse analysis compose the models.
Services
HTTP providers and concurrent enrichment live outside the offline core and have explicit timeouts and limits.
CLI
Typer commands are a thin automation boundary over the public library functions and structured health output.
Invariants
- Network I/O is opt-in; importing and using core parsers does not contact a remote service.
- Public transaction models are immutable value objects.
- Backends expose the same curve contract, with pure Python as the compatibility baseline.
- Parsers enforce structural limits before allocating untrusted data.
- Services validate URLs, transaction IDs, response sizes, and timeouts at their boundary.
Backend selection
# Default, works everywhere
BTX_DEFAULT_BACKEND=native python -c "import btx; print(btx.health())"
# Optional C-backed operations
BTX_DEFAULT_BACKEND=libsecp python -c "import btx; print(btx.health())"