Receipts commitment chain
receipts_commitment in a voucher is the head of a hash chain over the receipts the buyer has accepted on that channel. It lets the seller check that a voucher pays for exactly the receipts the buyer sent with it, and lets either side prove later which receipts a payment covered.
Definition
C0 = SHA256("IM/EMPTY/1")
Ci = SHA256("IM/APPEND/1" ‖ C(i−1) ‖ SHA256(receipt_bytes_i))
receipt_bytes_i are the full 382 signed receipt bytes. The signature is not hashed. The prefixes are ASCII with no terminator.
Order
Receipts are appended in ascending created_at, then ascending request_id compared as raw bytes (A3). Two receipts cannot share both, because request_id is unique; the libraries reject a batch that repeats an ordering key (DuplicateReceipt).
Continuation across vouchers
Each voucher continues the chain from the last voucher the seller acknowledged on that channel, starting at C0 (A13). The buyer chooses the batch (A25′):
- any bounded set of receipts issued on the channel and not yet acknowledged, in canonical order;
settled_totalrises by exactly the sum of theircharge_micros;receipts_commitmentis the chain continued over that batch.
Receipts the buyer leaves out remain the seller's unvouchered exposure.
import { emptyCommitment, orderedReceiptsCommitment } from "@im/protocol";
// prev is C0 for the first voucher, then the last acknowledged voucher's receipts_commitment.
const next = orderedReceiptsCommitment(prev ?? emptyCommitment(), receiptBytes);
orderedReceiptsCommitment sorts a copy into canonical order and validates each receipt's structure; it does not verify signatures. Rust offers the same functions in im-protocol.
Vectors
The shared fixture chains the five vector receipts in file order:
| Step | Receipt created_at | Receipt request_id | Commitment |
|---|---|---|---|
C0 |
— | — | a982b8b311e6647e5235ee26f1aa4553b8e273d19f3d60d55ab4693ef5ffcbca |
C1 |
1700000005 |
dd3a6b7dfa302bdf… |
09c8faf3b3b5baf1c9de5fef650bbb020b16093d9052386037905c4eb78bbb6d |
C2 |
1700000004 |
0b7672bbbf4eb882… |
f6e9cde3bbc0855e803539a3741a2ffdd73cff0d248ed4b72586868fed8b09fc |
C3 |
1700000005 |
fcb92229430f4264… |
978a447aea1ed9785eb77fa5cc23bf09c682447f7e50eb50d21d123e45b59ec1 |
C4 |
1700000003 |
035473bda6db3ce8… |
410eb07b54ea18141b5300fd35a1966bc2ba83c63bfaaa71a11b935cc3a0b290 |
C5 |
1700000005 |
5c24c0569e87ad1d… |
42557ce286a204b5e46cca73cc13e9ddf2065a1a40ffead5665d083a236133e5 |
The test voucher commits to C5.
<sub>Generated from crates/im-protocol/vectors/v1.json.</sub>
commitment_order and a3_ordering in the same file check the canonical sort.