# Chain of custody

The chain of custody is the append-only record of who captured, edited, escalated or exported an asset and when, and the evidence export makes it checkable offline.

The chain of custody is the append-only timeline of each attested asset, that records who captured, edited, escalated or exported it and when.

## When to use it

Read the chain when you need to show an investigator or a court how an asset was handled. Export it, with every hash, as an evidence bundle that anyone can re-check offline.

## How it works

1. Attesting an asset writes a `capture` event for the device.
2. Later events append to it: an `edit` by a tool, an `escalation` by an adjuster, an `exported` event when you export evidence.
3. Each verification result returns the chain as `chain`, oldest first, and the escalation PDF prints it.

1. **capture**: device:<id>
2. **edit / escalation**: tool:<name>, adjuster:<id>
3. **exported**: evidence bundle

## Key fields

| Field | Type | Description |
| --- | --- | --- |
| `event_type` | string | `capture`, `edit`, `escalation` or `exported`. |
| `timestamp` | string | When it happened (RFC 3339). |
| `actor` | string | Who: `device:<id>`, `tool:<name>` or `adjuster:<id>`. |
| `summary` | string | A short description. |

## Export the evidence

*Available on Enterprise.*

[`POST /v1/attest/claims/{id}/export`](https://provenanceauth.com/docs/api/exports.md#post-v1-attest-claims-id-export) builds a ZIP for one claim:

| File | Contents |
| --- | --- |
| `attestations/` | Each asset's signed bundle and verification result |
| `custody.json` | The chain-of-custody events |
| `content-hashes.json` | The media hashes; the media bytes stay with you |
| `manifest.json` | Every file with its hash, and a `manifest_hash` over the list |
| `verify-bundle.mjs` | A dependency-free script that re-checks every hash offline |

**curl**

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

curl -s -X POST $PROVENANCE_API/v1/attest/claims/CLM-SANDBOX-FRAUD/export \
  -H "Authorization: Bearer $PROVENANCE_KEY" | tee export.json
```

**Node**

```ts
import { Provenance } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const exported = await prov.attest.claims.export("CLM-SANDBOX-FRAUD");
```

**Python**

```python
import os
from provenanceauth import Provenance

prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
exported = prov.attest.claims.export("CLM-SANDBOX-FRAUD")
```

```json
{
  "id": "exp_01M5Q1PNHR9XVEVR97ZDCFBFXJ",
  "object": "export",
  "claim_id": "CLM-SANDBOX-FRAUD",
  "status": "ready",
  "manifest_hash": "f40f0e0ea6d919c3c8e7d234affbbddbb26772ad7a48e6e834c5a626a4eb9919",
  "timestamp": { "status": "not_configured", "reason": "…" },
  "file_count": 9,
  "download_url": "/v1/exports/exp_01M5Q1PNHR9XVEVR97ZDCFBFXJ/download",
  "expires_at": "2026-10-25T13:30:47.736Z"
}
```

Download the ZIP within 24 hours and run its check:

**curl**

```bash
export EXPORT_ID=$(jq -r .id export.json)
curl -s $PROVENANCE_API/v1/exports/$EXPORT_ID/download -H "Authorization: Bearer $PROVENANCE_KEY" -o evidence.zip
python3 -m zipfile -e evidence.zip evidence && node evidence/verify-bundle.mjs
```

**Node**

```ts
import { writeFileSync } from "node:fs";

const zip = await fetch(`${process.env.PROVENANCE_API}${exported.downloadUrl}`, { headers: { Authorization: `Bearer ${process.env.PROVENANCE_KEY}` } });
writeFileSync("evidence.zip", Buffer.from(await zip.arrayBuffer()));
// unzip, then: node evidence/verify-bundle.mjs
```

**Python**

```python
import httpx, zipfile

zip_bytes = httpx.get(os.environ["PROVENANCE_API"] + exported["download_url"], headers={"Authorization": f"Bearer {os.environ['PROVENANCE_KEY']}"}).content
open("evidence.zip", "wb").write(zip_bytes)
zipfile.ZipFile("evidence.zip").extractall("evidence")  # then: node evidence/verify-bundle.mjs
```

The check prints `BUNDLE VERIFICATION PASSED — every hash matches the manifest.`, and fails with exit code 1 if any file changed. With a timestamp authority configured on the server, the export also carries an RFC 3161 timestamp of the manifest hash, proving the evidence existed at that time; without one, `timestamp.status` is `not_configured`.

**Limitations:** the bundle holds hashes of the media, not the media; keep the originals to show the hashes match.

## Related

- [Insurance claims](https://provenanceauth.com/docs/attest/guides/review-claims.md)
- [Verification](https://provenanceauth.com/docs/attest/concepts/verification.md)
- [Transparency log](https://provenanceauth.com/docs/concepts/transparency-log.md)
