What you will do
A BOLT 11 invoice is a signed Lightning payment request. Its text carries a network, an optional amount, a creation time, tagged fields, a 65-byte signature and a six-character Bech32 checksum. A wallet should reject the request when the checksum fails, and it should show the amount and expiry before asking you to pay.
This guide builds a small Python inspector around the official BOLT 11 payment-encoding specification. It runs against the specification's public coffee-invoice vector. The script verifies the Bech32 checksum, reads the Bitcoin mainnet amount, extracts the timestamp, expiry, description, payment hash and payment secret, checks the signature length, and confirms that a one-character corruption is rejected.
The fixture does not pay the invoice. It uses no node, wallet, private key, recovery phrase, credential or funds. The current Core Lightning release was also checked. Core Lightning v26.06.10 is the latest published non-prerelease release as of 24 November 2026, but its binary was not executed for this guide.
Before you start
You need Python 3.10 or later. The fixture uses only the standard library. Create a new empty directory and save the script from this guide as bolt11_inspect.py.
The test invoice is intentionally old and expired. It appears in BOLT 11 as a format example. Never try to pay it. Its expected decoded values are:
- Bitcoin mainnet
- 250,000 satoshis
- timestamp
1496314658 - 60-second expiry
- description
1 cup coffee - 65 signature bytes with recovery flag
1
1. Separate the readable prefix from the payload
Bech32 uses the last 1 as the separator. Everything before it is the human-readable part. For this fixture, lnbc2500u means a Bitcoin mainnet Lightning invoice for 2,500 micro-bitcoin. One micro-bitcoin is 100 satoshis, so the amount is 250,000 satoshis.
The characters after the separator come from the 32-character Bech32 alphabet. Each represents five bits. The last six characters are the checksum. BOLT 11 reuses the checksum rules from BIP 173, while allowing invoices to exceed BIP 173's address-length limit.
The script first rejects mixed case, finds the separator, maps every data character to a five-bit value and calculates the checksum polymod. A valid BOLT 11 invoice must produce the constant 1.
Run:
python3 bolt11_inspect.py
Expected result includes:
{
"amount_sats": 250000,
"checksum_valid": true,
"corrupted_checksum_rejected": true,
"description": "1 cup coffee",
"expiry_seconds": 60,
"signature_bytes": 65
}
The complete output also shows the creation and expiry Unix times, payment hash, payment secret and recovery flag.
2. Read the timestamp and tagged fields
After removing the checksum, the first seven five-bit words encode a 35-bit Unix timestamp. The last 104 words encode the 65-byte recoverable signature. Everything between them is a sequence of tagged fields.
Each field begins with one word identifying its type, followed by two words containing its data length. The fixture reads four fields:
pcontains the 32-byte payment hashscontains the 32-byte payment secretdcontains the UTF-8 descriptionxcontains the expiry in seconds
BOLT 11 permits other fields, including route hints, fallback addresses, description hashes and feature bits. The fixture walks past fields it does not interpret. It still validates their declared boundaries so a truncated field cannot be treated as a complete invoice.
The creation time plus the expiry gives 1496314718. This is long in the past. A production wallet should compare expiry against its current clock and refuse an expired request. The script reports the value but does not make a payment decision because it is inspecting a published test vector.
3. Confirm the negative control
The fixture replaces the invoice's final character and decodes the modified string. The payload is almost identical, but the checksum no longer matches. The script requires this attempt to raise invalid Bech32 checksum.
This matters because readable fields alone do not make an invoice valid. A tool that prints the amount and description before validating the checksum can make corrupted text look trustworthy. Validate the complete encoding first, then present the decoded fields.
Do not automatically correct an invoice. BIP 173 explains that correction can turn invalid input into a different valid string. Ask the recipient for a fresh invoice instead.
4. Apply the same checks to a fresh invoice
Replace the INVOICE value with a newly generated invoice from a disposable test environment. Keep these checks in order:
- Require one case style and valid Bech32 characters
- Verify the checksum before using decoded fields
- Confirm the expected network prefix, such as
lnbcfor Bitcoin mainnet orlntbfor testnet - Check the amount, or treat an amountless invoice as requiring an amount from the payer
- Read the creation time and expiry
- Show the description or description hash
- Require your Lightning implementation to verify the recoverable signature and feature bits before payment
The final step needs a complete Lightning implementation or a reviewed secp256k1 library. This fixture checks that the signature occupies 65 bytes and exposes its recovery flag. It does not recover the payee key or prove the signature valid. It also does not validate route hints, fallback addresses, unknown required feature bits, payment feasibility or whether the recipient will provide what you expect.
Troubleshooting
invalid Bech32 checksum
The invoice changed, was truncated or was copied with an unsupported character. Request a fresh invoice. Do not edit characters until the checksum passes.
mixed case is invalid
All-lowercase and all-uppercase encodings are acceptable to a BOLT 11 reader. A mixture is invalid. QR encoders often use uppercase because it fits a denser QR mode.
The amount is null
BOLT 11 permits an amountless invoice. The payer supplies the amount. The interface should make that choice explicit before payment.
The decoded invoice is already expired
Create a new invoice. Extending the displayed expiry locally does not change the signed request.
Limits
The fixture executed eight expected checks and all eight passed. It used the public BOLT 11 coffee example and a corrupted-copy negative control. It did not run Core Lightning, recover or verify the invoice signature, interpret feature bits, validate routing, connect to a Lightning node or attempt a payment. Use it to inspect encoding boundaries and to understand what a full wallet must verify, not as a payment-authorisation library.
