A file arrives with C2PA content credentials: the device that captured it, the software that touched it, the edits, a signing time. Then it goes through an upload path that re-encodes it, or someone converts it, and the manifest is gone. It lived inside the file and the file changed.

A hash recorded outside the file does not go with it. This post builds a small Python pipeline that reads the C2PA manifest while it is still there, hashes the original bytes locally, submits the hash to ProofLedger's API, waits for the Polygon anchor and saves the proof bundle beside the file. Two layers, one script.

What each layer shows

C2PA answers provenance questions: which device or tool produced the file, what edits were applied, and what the signing certificate says about when it was signed. The manifest is a signed block embedded in the file container, and it is only as available as every system the file passes through allows.

A hash anchor answers one narrower question: did a file with this exact SHA-256 exist by the anchor time, and is this still the same file. The hash is computed from the bytes on your machine; only the hash is sent; the record is a public Polygon transaction plus a bundle you keep. It says nothing about who made the file or what it depicts.

One detail worth being precise about: the signing_time in a C2PA manifest is asserted by whoever signed the manifest. It is useful context, not an independent time record. The anchor time comes from a chain no single party sets.

Why the manifest dies and the hash record does not

A C2PA manifest sits in the file's metadata structure. Any process that rewrites the container can drop it: resizing on upload, a HEIC to JPEG conversion, a mail client that regenerates attachments, a tool that strips metadata to save space. None of this is a flaw in the standard. Embedded metadata survives only when every hop preserves it, and most hops were not built with C2PA in mind.

A hash of the original bytes, recorded in a public transaction, is not touched by what happens to copies. The flip side is that it matches only the original bytes. A re-encoded copy has a different hash, so the pipeline below hashes the file as it arrived and keeps that original.

Reading the manifest

pip install c2pa-python requests

c2pa-python wraps the C2PA Rust SDK. Its Reader takes a MIME type and an open binary stream and returns the manifest store as JSON. The constructor has changed between releases, so check the package README for the version you pin and adjust the two lines that build the reader.

import json
import c2pa

MIME = {"jpg": "image/jpeg", "jpeg": "image/jpeg", "png": "image/png",
        "mp4": "video/mp4", "mov": "video/quicktime", "pdf": "application/pdf"}

def read_c2pa(path: str):
    """The manifest store as a dict, or None when the file carries no credentials."""
    mime = MIME.get(path.rsplit(".", 1)[-1].lower(), "application/octet-stream")
    try:
        with open(path, "rb") as f:
            raw = c2pa.Reader(mime, f).json()
        return json.loads(raw) if raw else None
    except Exception:
        return None

def summarize(store: dict) -> dict:
    active = store.get("manifests", {}).get(store.get("active_manifest", ""), {})
    sig = active.get("signature_info", {})
    return {
        "claim_generator": active.get("claim_generator"),
        "signing_time": sig.get("time"),
        "signing_issuer": sig.get("issuer"),
        "assertions": [a.get("label") for a in active.get("assertions", []) if a.get("label")],
    }

No credentials is a normal outcome. The anchor step runs either way.

Hashing and submitting

Only the 64-character digest leaves your machine, with a file name and your own record id. external_id is unique per account: a resend with the same id returns the existing proof (HTTP 200, already_existed: true) instead of creating another, which makes the script safe to re-run.

import hashlib
import os
import time
import requests

BASE = "https://proofledger.io"
HEADERS = {"Authorization": f"Bearer {os.environ['PROOFLEDGER_API_KEY']}"}

def sha256_file(path: str) -> str:
    h = hashlib.sha256()
    with open(path, "rb") as f:
        for chunk in iter(lambda: f.read(1 << 20), b""):
            h.update(chunk)
    return h.hexdigest()

def submit(sha256: str, filename: str, external_id: str) -> dict:
    body = {"sha256": sha256, "filename": filename, "external_id": external_id}
    for _ in range(5):
        r = requests.post(f"{BASE}/api/v1/proof", json=body, headers=HEADERS, timeout=30)
        if r.status_code in (200, 201):
            return r.json()
        if r.status_code == 429 and "Retry-After" in r.headers:
            time.sleep(int(r.headers["Retry-After"]))   # per-key limit: 120 requests a minute
            continue
        r.raise_for_status()   # a 429 without Retry-After: read the body; on Free it reports this month's allowance
    raise RuntimeError("still rate limited after five tries")

A 201 means a new proof. If anyone had submitted the same hash before, the response also carries duplicate_of with that earlier proof's id and created_at; your proof is still recorded on its own. For retries at the HTTP layer you can also send an Idempotency-Key header: the same key and body within 24 hours replays the stored response.

Waiting for the anchor and saving the bundle

The anchor usually lands within a minute. Poll until polygon_status is ANCHORED, then download the bundle, the one document verify-proof reads later.

def wait_for_anchor(proof_id: int, timeout: int = 300) -> dict:
    deadline = time.time() + timeout
    while time.time() < deadline:
        r = requests.get(f"{BASE}/api/v1/proof/{proof_id}", headers=HEADERS, timeout=30)
        r.raise_for_status()
        proof = r.json()
        if proof["polygon_status"] == "ANCHORED":
            return proof
        time.sleep(15)
    raise TimeoutError(f"proof {proof_id} not anchored after {timeout}s")

def save_bundle(proof_id: int, dest: str) -> None:
    r = requests.get(f"{BASE}/api/v1/proof/{proof_id}/bundle",
                     params={"download": "1"}, headers=HEADERS, timeout=30)
    r.raise_for_status()
    with open(dest, "wb") as f:
        f.write(r.content)

If you would rather not poll, register an https endpoint with POST /api/v1/webhooks. The proof.polygon.anchored event carries the proof and its bundle in data.bundle, signed with the ProofLedger-Signature header.

Putting it together

from pathlib import Path

def process_file(path: str) -> dict:
    p = Path(path)
    digest = sha256_file(path)

    store = read_c2pa(path)
    c2pa_summary = summarize(store) if store else None
    Path(f"{path}.c2pa.json").write_text(json.dumps(c2pa_summary, indent=2))

    proof = submit(digest, p.name, external_id=f"intake:{p.name}:{digest[:12]}")
    anchored = wait_for_anchor(proof["id"])
    save_bundle(proof["id"], f"{path}.proof.json")

    return {"file": p.name, "sha256": digest, "proof_id": proof["id"],
            "tx": anchored["chain_tx"], "explorer": anchored["explorer_url"],
            "c2pa": c2pa_summary is not None, "seen_before": proof.get("duplicate_of")}

if __name__ == "__main__":
    import sys
    for arg in sys.argv[1:]:
        print(json.dumps(process_file(arg)))
python c2pa_anchor.py site_photo.jpg inspection_report.pdf walkthrough.mp4

The external_id includes the first twelve characters of the hash, so re-running on an unchanged file returns its existing proof, and an edited file with the same name gets a new one.

What you have afterwards

For each file:

  • the original, unchanged, on your machine;
  • <file>.c2pa.json, the manifest summary (null when none was present);
  • <file>.proof.json, the bundle: hash, chain, transaction id and anchor time.

Strip the C2PA data downstream and the anchor still holds, because it was never in the file. Anyone you hand the file and the bundle to can check them offline:

pip install verify-proof
verify-proof verify site_photo.jpg --proof site_photo.jpg.proof.json

Anyone with just the hash can also ask the public lookup, no key needed, 120 requests an hour per IP:

curl "https://proofledger.io/api/v1/verify?hash=a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2"

It returns found, the proof's status and an explorer_url. It is a convenience; the bundle and the transaction are the record.

Pin c2pa-python in your requirements. The SDK moves quickly and its API has changed between minor releases, so test before upgrading.

To check a proof without ProofLedger, run verify-proof against the file and its bundle, then open the bundle's tx_id on any Polygon block explorer and confirm the transaction and its time. The API is documented at https://proofledger.io/api.html.