# Transparency log

The transparency log is a public, signed, append-only record of every account's decision-ledger head, so anyone can check that Provenance never rewrote history.

The transparency log is a public, signed, append-only series of checkpoints that commit to every account's [decision ledger](https://provenanceauth.com/docs/mandate/concepts/decision-ledger.md) head, so anyone can check that Provenance never rewrote history. It publishes hashes only: no decisions, and no account identities.

## When to use it

- Show an auditor or counterparty that your decision records weren't altered after the fact.
- Prove your account's ledger head existed by a given checkpoint.
- Monitor the log independently, without an API key.

## How it works

1. **Every hour, Provenance takes a checkpoint.** It builds a Merkle tree over each account's current ledger head, with account IDs hashed, and signs the root with the same published keys as intent tokens.
2. **Checkpoints chain.** Each one names the previous root in `prev_root`, and the series forms its own Merkle log, with consistency proofs between sizes.
3. **Anyone verifies.** Changing any past checkpoint breaks its signature, the `prev_root` chain, or a consistency proof.

1. **Ledger heads**: one per account, hashed
2. **Checkpoint**: Merkle root, signed, chained
3. **Public log**: consistency proofs

When the server has a timestamp authority set up, each root is also stamped by it; otherwise the checkpoint says `witness_status: "not_configured"`.

## Key fields

- `seq` (integer): The checkpoint's position in the log, from 1.
- `root` (string): The Merkle root over the account ledger heads at that hour.
- `tree_size` (integer): How many accounts the root covers.
- `prev_root` (string): The previous checkpoint's root; all zeros for the first.
- `witness_status` (string): Whether an external timestamp authority stamped the root, or `not_configured`.
- `signed_token` (string): An ES256 JWS over the checkpoint, verifiable with the published keys.

## Read and check the log

[`GET /.well-known/provenance-log`](https://provenanceauth.com/docs/api/transparency-log.md#get-well-known-provenance-log) is public and needs no key:

**curl**

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com

curl $PROVENANCE_API/.well-known/provenance-log
```

**Node**

```ts
import { fetchJwks, verifyIntentTokenOffline } from "@provenanceauth/sdk";

const api = process.env.PROVENANCE_API!;
const jwks = await fetchJwks(api);
const log = await (await fetch(`${api}/.well-known/provenance-log`)).json();
for (const checkpoint of log.checkpoints) {
  const result = await verifyIntentTokenOffline(checkpoint.signed_token, jwks);
  console.log(checkpoint.seq, result.valid && result.payload?.root === checkpoint.root);
}
```

**Python**

```python
import os
import httpx
from provenanceauth import fetch_jwks, verify_intent_token_offline

api = os.environ["PROVENANCE_API"]
jwks = fetch_jwks(api)
log = httpx.get(f"{api}/.well-known/provenance-log").json()
for checkpoint in log["checkpoints"]:
    result = verify_intent_token_offline(checkpoint["signed_token"], jwks)
    print(checkpoint["seq"], result.valid and result.payload["root"] == checkpoint["root"])
```

The response, trimmed to the first checkpoint:

```json
{
  "environment": "sandbox",
  "checkpoints": [
    {
      "seq": 1,
      "prev_root": "0000000000000000000000000000000000000000000000000000000000000000",
      "witness_status": "not_configured"
    }
  ],
  "consistency": []
}
```

To check the whole history, verify each `signed_token`, check that each `prev_root` equals the root before it, and check each proof in `consistency` against `log_root`. The proofs follow RFC 6962.

## Prove your account's inclusion

[`GET /v1/log/inclusion`](https://provenanceauth.com/docs/api/transparency-log.md#get-v1-log-inclusion) returns a Merkle proof for your account's ledger head in the latest checkpoint. It answers `404` until a checkpoint has been taken since your account's first decision.

**curl**

```bash norun
curl $PROVENANCE_API/v1/log/inclusion \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const inclusion = await (await fetch(`${api}/v1/log/inclusion`, { headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}` } })).json();
```

**Python**

```python
inclusion = httpx.get(f"{api}/v1/log/inclusion", headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}).json()
```

The response has the checkpoint's `root` and `signed_token`, your `account_hash` and `chain_head`, and the `leaf_index` and audit `proof`. Hash the leaf as SHA-256 of a `0x00` byte followed by `account_hash:chain_head`, combine it with each proof hash as SHA-256 of `0x01`, left and right, and you should arrive at `root`.

## Related

- [Decision ledger](https://provenanceauth.com/docs/mandate/concepts/decision-ledger.md)
- [Verify tokens offline](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md)
- [Verify page](https://provenanceauth.com/docs/integrate/verify-a-proof.md)
