# NIP-XX: Receipt-Bound Review (RBR)

`draft` `optional`

This document is released under [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/).

## Abstract

Receipt-Bound Review (RBR) is an open, neutral protocol layer on Nostr + Lightning: **one review per settled payment; no receipt, no review**. Product layers on top are out of scope. The protocol must not give the seller a veto over negative reviews and must not leak payment linkage to third parties.

Working name: **rbr**. Implementers verify reviews against order attestations and status events. Nothing in this protocol is ever edited or deleted; every change of state is a new status event.

## Motivation

Public reviews without proof of purchase are cheap to forge. Lightning payments produce a cryptographic preimage, but publishing that preimage by default links the buyer's Nostr identity to a payment path. RBR binds a review to a seller-signed order attestation that commits to `SHA-256(payment_hash || order_nonce)` without putting the invoice or nonce on a relay. Settlement proof (preimage disclosure) remains a **buyer choice for disputes only**.

## Core model

Order flow is **order → invoice → payment**, never invoice → order. The buyer pubkey must be known before the invoice exists.

1. Buyer selects a NIP-99 listing (kind `30402`) and presents their pubkey.
2. Seller creates an order: generates `order_nonce` (32 random bytes), creates a BOLT-11 invoice, computes `commitment = SHA-256(payment_hash || order_nonce)`.
3. Seller signs and publishes the **order attestation** before payment. It contains: `p` tag = buyer pubkey, `a` tag = listing address, `e` tag = listing event id at order time, `commitment`, amount, `created_at`. Invoice and `order_nonce` go to the buyer privately (out of band or NIP-17 DM), never on a relay.
4. Buyer pays. Buyer now holds the preimage; seller holds the payment record.
5. Buyer signs and publishes one **review** referencing the attestation event id and the same `commitment`.
6. Seller may sign and publish a **purchase certificate** referencing the same attestation — only with buyer consent (see privacy under event kinds).

Settlement proof is the buyer's, not the seller's. Normal case: the preimage stays private; the verifier trusts attestation + review. Dispute case: the buyer publishes preimage and nonce in a status event; anyone can check `SHA-256(preimage) == payment_hash` and `SHA-256(payment_hash || order_nonce) == commitment`. **Preimage disclosure is a buyer choice for disputes only.**

## Event kinds

All four RBR kinds are **regular** (non-replaceable, range `1000–9999`). Exact numbers below are **PROVISIONAL** — reserved for Thomas; they MUST be re-checked against the NIPs kind registry before final registration. Nothing is edited or deleted; every change of state is a new status event.

| Kind | Name | Signer | When | Notes |
| --- | --- | --- | --- | --- |
| `3881` | Order attestation | seller | before payment | **PROVISIONAL** |
| `3882` | Review | buyer | after payment | **PROVISIONAL** |
| `3883` | Purchase certificate | seller | after delivery, with buyer consent | **PROVISIONAL** |
| `3884` | Status | buyer or seller | any time | **PROVISIONAL** |

Listing events remain NIP-99 kind `30402` (addressable).

### Kind 3881 — Order attestation (PROVISIONAL)

Signed by the **seller**. Published **before** payment.

Tags:

- `["p", <buyer-pubkey>]` — required
- `["a", "30402:<seller-pubkey>:<d-identifier>", <relay-url?>]` — required listing address
- `["e", <listing-event-id>, <relay-url?>]` — required listing event id at order time
- `["commitment", <64-hex>]` — required; `hex(SHA-256(payment_hash || order_nonce))`
- `["amount", <millisats-as-decimal-string>]` — required
- `["alt", "RBR order attestation"]` — optional

`content` MAY be empty or a short human note. `created_at` MUST be before any review that references this attestation.

**Never** include `order_nonce`, payment preimage, BOLT-11 invoice, or payment hash on the attestation (or any public RBR event except settlement-proof status).

### Kind 3882 — Review (PROVISIONAL)

Signed by the **buyer**. Published after payment.

Tags:

- `["e", <attestation-event-id>, <relay-url?>]` — required
- `["p", <seller-pubkey>]` — required
- `["commitment", <64-hex>]` — required; MUST equal attestation commitment
- `["rating", <1-5 as decimal string>]` — required
- `["alt", "RBR review"]` — optional

`content` is free-form review text.

### Kind 3883 — Purchase certificate (PROVISIONAL)

Signed by the **seller**, only with buyer consent.

Tags (public variant):

- `["e", <attestation-event-id>]` — required
- `["p", <buyer-pubkey>]` — present in the public variant

Private variant: no `p` tag; gift-wrapped to the buyer (NIP-17 / NIP-59). Whether the private variant ships in a given product is an implementer choice; this spec defines both.

### Kind 3884 — Status (PROVISIONAL)

Signed by **buyer or seller**. Tags:

- `["type", <status-type>]` — required; one of:
  - `dispute`
  - `refund`
  - `resale`
  - `withdrawn`
  - `settlement-proof`
- `["e", <target-event-id>]` — required; the event this status refers to (review, attestation, or certificate as appropriate)

For `settlement-proof` (buyer only):

- `["preimage", <64-hex>]` — 32-byte payment preimage
- `["order_nonce", <64-hex>]` — 32-byte order nonce
- `["e", <attestation-event-id>]` — the attestation whose commitment is proven

`content` MAY carry a short reason string.

## Commitment and settlement proof

Let:

- `preimage` be 32 random bytes (Lightning payment preimage)
- `payment_hash = SHA-256(preimage)`
- `order_nonce` be 32 random bytes
- `commitment = SHA-256(payment_hash || order_nonce)` (64-byte concatenation of the two 32-byte digests/values, then hashed)

All hex encodings on tags are lowercase 64-character hex of the raw 32 bytes.

A settlement-proof status is valid when:

1. `SHA-256(preimage) == payment_hash` (derived), and
2. `SHA-256(payment_hash || order_nonce) == commitment` on the referenced attestation.

Clients MUST treat preimage disclosure as exceptional dispute evidence, not as a normal receipt.

## Verification rule

A client MUST check all of the following to display a review as **receipt-bound**:

1. **Review signature valid.**
2. **Referenced attestation exists**, seller signature valid, and attestation `created_at` < review `created_at`.
3. **Attestation `p` == review author pubkey.**
4. **Attestation `commitment` == review `commitment`.**
5. **Listing** referenced by attestation `a` / `e` exists on at least one queried relay.
6. **Duplicate rule:** among all reviews by the same author referencing the same attestation, the earliest `created_at` is valid; later ones return `reason: "duplicate"`.
7. **Withdrawal:** a `withdrawn` status by the review author hides the review if rating ≥ 4; if rating ≤ 3 the review stays visible, marked withdrawn by author. Relays MAY honour NIP-09 deletions; **the verifier ignores NIP-09 entirely** and works only from status events. Persistence depends on relays, not on this protocol.
8. **Refund** status by seller → review remains visible, badge `refunded`.
9. **Settlement-proof** status by buyer → verify preimage and nonce against `commitment`; flag `settlement-proven` if valid.

Suggested machine result shape (library convention, not a wire format):

```json
{ "valid": true, "reason": null, "flags": ["refunded", "settlement-proven"] }
```

`flags` members are drawn from: `withdrawn`, `refunded`, `disputed`, `settlement-proven`.

### Withdrawal threshold (default)

Default threshold (reserved decision; default used here): rating ≥ 4 → hide (`valid: false`, `reason: "withdrawn"`, flag `withdrawn`); rating ≤ 3 → keep visible (`valid: true`, flag `withdrawn`).

## Relays and persistence

This protocol does **not** operate its own relay. Clients query a configurable list of relays (implementations SHOULD default to well-known public relays). Event persistence is a property of those relays; RBR does not guarantee storage, archival, or censorship resistance beyond what the chosen relays provide.

NIP-09 deletion requests are **ignored** by RBR verifiers. Authors who wish to retract use a `withdrawn` status event.

## Explicitly not covered

The protocol does **not** attest:

- Authenticity of goods or services
- Ownership over time (including after resale)
- Attention, advertising, or qualified-view metrics
- Self-purchase and sybil resistance (weighting is a client concern)
- Relay persistence or availability guarantees
- KYC of any kind
- Seller-side fulfilment / delivery confirmation (completion is buyer-side: publishing a review)
- Transfer of a purchase certificate on resale (resale is a status event only)

## Privacy

- Invoice and `order_nonce` are never published on relays in the happy path.
- Preimage is published only optionally by the buyer in a `settlement-proof` status for disputes.
- Purchase certificates require buyer consent; a private gift-wrapped variant avoids public `p` linkage.

## Test vectors

Canonical JSON test vectors live in `test-vectors/` in this repository and cover:

- valid review
- invalid review signature
- missing attestation
- attestation `p` mismatch
- commitment mismatch
- duplicate review (earliest valid)
- withdrawn positive (rating ≥ 4)
- withdrawn negative (rating ≤ 3)
- refund status
- settlement-proof with valid preimage
- settlement-proof with invalid preimage
- attestation `created_at` after review

## References

- NIP-01 — Basic protocol
- NIP-09 — Event deletion request (ignored by RBR verifiers)
- NIP-17 / NIP-59 — Private DMs / gift wrap (nonce delivery; private certificate)
- NIP-99 — Classified listings (kind `30402`)
- BOLT-11 — Lightning invoices
