# Verify a receipt

Run the four receipt checks (hash, signature, chain link and on-chain anchor) on the public page, through the API, or by hand without trusting Abazi's database.

<ShortProductTruth>**Don't trust the log. Check the receipt.** Every confirmed payment ends in a receipt that anyone with the link can check, without an account: its hash, its signature, its place in the chain and its anchor on Solana.</ShortProductTruth>

## What you end up with [#what-you-end-up-with]

A verdict you can show an auditor: four checks, each PASS, and an overall PASS, for a receipt you were given. Or, if something was altered, a FAIL on exactly the check that caught it.

## Try the checks [#try-the-checks]

Change one character, break the chain or hold the anchor back, and watch which checks fail.

<ReceiptVerifier />

## Steps [#steps]

<Steps>
<Step>

### Get the receipt id [#get-the-receipt-id]

The agent gets a receipt id with every paid purchase and can fetch the receipt and its public link with `get_receipt`. Owners and finance find every receipt in the Console.

</Step>
<Step>

### Open the public check [#open-the-public-check]

The public verification page runs the four checks on the receipt and shows the result. It needs no account and works on a phone. The same checks are on the public operation <ApiOperation id="getPublicReceipt" path />.

<Screenshot id="public-verify" />

<VerifiedSnippet what="GET /verify/{id} on a confirmed payment receipt, trimmed to the checks and the anchor status" exit="0">

```json
{
  "receipt": {
    "anchor": { "status": "finalized" }
  },
  "checks": { "hash": "PASS", "signature": "PASS", "chain": "PASS", "anchor": "PASS" },
  "result": "PASS"
}
```

</VerifiedSnippet>

</Step>
<Step>

### Check a copy you hold [#check-a-copy-you-hold]

If you kept the receipt document, send it to <ApiOperation id="verifyReceiptDocument" path /> as `{"receipt": <document>}`. The checks run on your copy, not on the stored one, so any change in your copy shows up.

</Step>
<Step>

### Or check it by hand [#or-check-it-by-hand]

You do not need Abazi's word for the first two checks, and the fourth reads a public network:

1. Remove the envelope fields (`hash`, `signature`, `kid`, `anchor`) from the receipt document. Serialize the rest as canonical JSON (RFC 8785) and take its SHA-256. It must equal `hash`.
2. Fetch the published keys from `/.well-known/uapg-receipt-keys.json`, pick the key whose id equals `kid`, and verify the Ed25519 `signature` over the 32 bytes of the hash you computed.
3. The body's `prev_hash` must equal the hash of the organization's previous receipt; the first receipt in a chain has 64 zeros.
4. Look up the anchor transaction on Solana. Once it is finalized, its memo must read `uapg:v1:` followed by the hash.

</Step>
</Steps>

## What each check proves [#what-each-check-proves]

| Check | Proves | Fails when |
| --- | --- | --- |
| Hash | The body is exactly what was hashed. | Any character of the body changed. |
| Signature | Abazi's receipt key signed this body's hash. | The body changed, or the signature or key id is wrong. |
| Chain link | No receipt was removed or rewritten before this one. | The previous receipt was changed or is missing. |
| Anchor | The hash was public on Solana at the anchor's time. | The memo does not match. It reads PENDING until the memo transaction is finalized. |

The overall result is FAIL if any check fails, PASS if all four pass, and PENDING otherwise. A fresh receipt usually reads PENDING for a short while until its anchor is final.

## Failure cases [#failure-cases]

| Situation | What you see |
| --- | --- |
| The amount in a copy was edited | Hash FAIL, signature FAIL, and anchor FAIL once the anchor is final. |
| An earlier receipt in the chain was rewritten | Chain link FAIL on the receipt that follows it. |
| The anchor is not final yet | Anchor PENDING, result PENDING. Check again later. |
| The receipt id does not exist | Not found; there is nothing to check. |

## Next steps [#next-steps]

<Cards>
  <Card title="Receipts and proof" href="/docs/concepts/receipts-and-proof" description="Read what a receipt contains and how the chain and anchor are built." />
  <Card title="Proof" href="/docs/products/proof" description="See the product that issues and anchors receipts." />
  <Card title="Payment lifecycle" href="/docs/architecture/payment-lifecycle" description="See where in a payment the receipt is issued." />
</Cards>

