silent-payments
A complete BIP 352 Silent Payments library for Rust.
Quick Start
Add the dependency:
[]
= "0.1.1"
For local development against this repository:
[]
= { = "." }
Complete send + receive roundtrip in under 20 lines:
use FromStr;
use *;
// (hidden: bitcoin imports, key construction, transaction building)
let secp = new;
// Receiver: create keys + address
let scan_sk = from_slice?;
let spend_sk = from_slice?;
let = ;
let sp_addr = new;
// Sender: build inputs, create outputs
let sender = new?;
let outputs = sender.create_output_scripts?;
// Receiver: scan transaction, derive spend key
let scanner = new;
let detected = scanner.scan_transaction?;
for d in &detected
See examples/ for complete, runnable examples:
send_to_sp_address.rs-- sending to an SP addressscan_for_payments.rs-- scanning transactions for SP outputsfull_roundtrip.rs-- end-to-end send + receive
Feature Flags
| Feature | Default | Description |
|---|---|---|
experimental-dleq |
off | BIP 374 DLEQ proof support for multi-signer PSBT workflows |
bip392 |
off | BIP 392 sp() descriptor parsing and generation |
electrum |
off | Electrum/Esplora scanner backend |
index-server |
off | BIP0352 index server scanner backend |
cli |
off | CLI binary (sp command) |
Architecture Overview
silent-payments (facade)
+-- silent-payments-core (address, keys, inputs, crypto)
+-- silent-payments-send (sender builder, output scripts)
+-- silent-payments-receive (scanner, labels, detected outputs)
+-- silent-payments-psbt (BIP 375 fields, roles, DLEQ proofs)
+-- silent-payments-scan (ScanBackend trait, electrum, index-server)
+-- silent-payments-descriptor (BIP 392 sp() descriptors)
silent-payments-core -- BIP 352 primitives: address parsing/encoding, key newtypes with zeroization, input classification, and cryptographic wrappers. All EC operations use bitcoin::secp256k1 (SEC-04).
silent-payments-send -- Builder-style API for constructing SP outputs. Validates SIGHASH_ALL, classifies inputs, computes ECDH shared secrets, and generates P2TR output scripts. Supports batch sending and change outputs.
silent-payments-receive -- Block-level transaction scanner with label support. BlockScanner scans transactions for SP outputs and provides spend key derivation for detected payments.
silent-payments-psbt -- BIP 375 PSBT integration with BIP 374 DLEQ proofs. Typestate role machine (Constructor -> Updater -> Signer -> Extractor) enforces correct ordering at compile time.
silent-payments-scan -- Pluggable scanning backends behind the ScanBackend trait. Swap infrastructure (Electrum, index server) without changing application code.
silent-payments-descriptor -- BIP 392 sp() descriptor parsing and generation with BIP 393 annotations (birthday height, gap limit, max labels).
The facade crate re-exports everything via prelude::* -- depend on silent-payments and import the prelude for the full API.
CLI
The sp binary provides command-line access to Silent Payments functionality:
# Generate a new SP address (random keys)
# Generate from specific keys
# Send to an SP address
# Scan via index server (block range)
# Scan via Electrum (individual transactions)
# JSON output for any command
Run sp --help for full flag reference.
Testing
Tests include BIP 352 official test vector validation for both send and receive flows.
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.