|
| 1 | +# BIP 375 Reference Implementation |
| 2 | + |
| 3 | +This directory contains reference implementation for BIP 375: Sending Silent Payments with PSBTs. |
| 4 | + |
| 5 | +## Core Files |
| 6 | +- **`constants.py`** - PSBT field type definitions |
| 7 | +- **`parser.py`** - PSBT structure parsing |
| 8 | +- **`inputs.py`** - Input validation helpers |
| 9 | +- **`dleq.py`** - DLEQ proof validation |
| 10 | +- **`validator.py`** - Main BIP 375 validator |
| 11 | +- **`test_runner.py`** - Test infrastructure (executable) |
| 12 | + |
| 13 | +## Dependencies |
| 14 | +- **`../bip-0374/reference.py`** - BIP 374 DLEQ proof reference |
| 15 | +- **`../bip-0374/secp256k1.py`** - secp256k1 implementation |
| 16 | + |
| 17 | +## Testing |
| 18 | + |
| 19 | +### Test Vectors |
| 20 | +- **`test_vectors.json`** - 17 test vectors (13 invalid + 4 valid) covering: |
| 21 | + - Invalid input types (P2MS, non-standard scripts) |
| 22 | + - Missing/invalid DLEQ proofs |
| 23 | + - ECDH share validation |
| 24 | + - Output script verification |
| 25 | + - SIGHASH requirements |
| 26 | + - BIP-352 output address matching |
| 27 | + |
| 28 | +### Generating Test Vectors |
| 29 | + |
| 30 | +Test vectors were generated using [test_generator.py](https://github.com/macgyver13/bip375-examples/blob/main/python/tests/test_generator.py) |
| 31 | + |
| 32 | +### Run Tests |
| 33 | + |
| 34 | +```bash |
| 35 | +python test_runner.py # Run all tests |
| 36 | +python test_runner.py -v # Verbose mode with detailed errors |
| 37 | +``` |
| 38 | + |
| 39 | +**Expected output:** All 17 tests should pass validation (4 valid accepted, 13 invalid rejected). |
| 40 | + |
| 41 | +## Validation Layers |
| 42 | + |
| 43 | +The validator implements progressive validation: |
| 44 | +1. **PSBT Structure** - Parse PSBT v2 format |
| 45 | +2. **Input Eligibility** - Validate eligible input types (P2PKH, P2WPKH, P2TR, P2SH-P2WPKH) |
| 46 | +3. **DLEQ Proofs** - Verify ECDH share correctness using BIP-374 |
| 47 | +4. **Output Fields** - Check PSBT_OUT_SCRIPT or PSBT_OUT_SP_V0_INFO requirements |
| 48 | +5. **BIP-352 Outputs** - Validate output scripts match expected silent payment addresses |
| 49 | + |
| 50 | +## Examples |
| 51 | + |
| 52 | +Demo implementations using this reference can be found in [bip375-examples](https://github.com/macgyver13/bip375-examples/) |
0 commit comments