# Verifiable History

Version history is only as trustworthy as whoever keeps it. Swarmfile's history is built so you don't have to take our word for it: every commit is **hash-chained** to the ones before it, the service **signs checkpoints** of each branch with a published key, and a standalone tool, [`swarmfile-verify-history`](https://swarmfile.com/docs/cli/swarmfile-verify-history), lets you check a repository's history yourself - on an audit host or in CI, with no Desktop App or mount.

This page explains what that gives you and where its limits are. For flags and exit codes, see the [CLI reference](https://swarmfile.com/docs/cli/swarmfile-verify-history).

## Hash-chained commits

Every commit has a **commit hash** computed from its own facts: the content-addressed id of the repository tree it records (which in turn is built from the ids of every file's contents) and the hashes of its parent commits. Because each commit's hash covers its parents' hashes, a commit's hash covers the whole history behind it. Change one file in one old commit, or remove a commit from the middle, and every hash after it stops matching.

Commits get their hash once they're **confirmed**. Swarmfile doesn't compute commit hashes on the server: a client derives the commit (the Desktop App does this after a commit, or `swarmfile git index` on demand), and a second, independent derivation confirms it - a teammate's app, a fetch, or a repository API key used in CI; an owner can also allow their own app to self-confirm.

Commits made where no app runs (a web upload, a revert, a merge) are derived by Swarmfile's server, which counts as one independent derivation: the first matching derivation from a client confirms them.

Commits pushed with git work the other way round: the push derives them, and the hosted hub's own derivation - queued as soon as the push's claim lands, normally confirmed within seconds - confirms them; a community server confirms a member key's push from its own tree derivation at claim time (a claim it cannot reproduce waits for another key's claim; an owner key's own first claim is recorded confirmed directly - the community server has no self-confirm setting).

Self-confirm covers only the owner's own app, so on a self-confirm repository these commits stay provisional until a client derives them (a fetch is enough). Until then a commit is *provisional*: it's in your history and fully usable, it just isn't part of the hash chain yet. `swarmfile git status` reports how many commits on a branch are still unconfirmed.

## Signed checkpoints

Hash chaining proves the history is internally consistent. It doesn't, on its own, stop someone who controls the server from replacing the whole chain with a different, equally consistent one. That's what checkpoints are for.

Periodically (hourly, for every branch that has changed since its last checkpoint) the Swarmfile service signs the branch's latest **confirmed** commit hash with an **Ed25519** key. The verifier requires every checkpoint published for a branch to land on the chain it walks, so a history that has lost or replaced a checkpointed commit fails verification.

The signing key can be rotated; the service publishes its current and retired public keys so older checkpoints stay verifiable. Verifiable history is offered where the service has checkpoint signing enabled, and the verifier reports it as unavailable where it isn't (see [What it proves, and what it doesn't](#what-it-proves-and-what-it-doesnt)).

The [self-hosted server](https://swarmfile.com/docs/guides/self-hosting) ships with its own signing key: it mints one into its data directory on first use and signs the branch's confirmed head when a verifier asks, so the same check works against your own server.

## Checking it yourself

`swarmfile-verify-history` is installed with every Desktop App and runs on its own. The verifier itself is open source - source, releases and conformance checks at [swarmfile-verify-history](https://swarmfile.com/public/swarmfile/swarmfile-verify-history) - so checking the history doesn't require trusting our binary either.

```bash
swarmfile-verify-history \
  --hub-url https://hub.swarmfile.com/orgs/<org-id>/repositories/<repository-id> \
  --org-id <org-id> \
  --repository-id <repository-id> \
  --branch main \
  --header "Authorization: Bearer $SWARMFILE_API_KEY" \
  --pin-key ./swarmfile-history-key.pub
```

It fetches the branch head, then walks back commit by commit to the start of history (or to a commit you name with `--checkpoint-hash`), recomputing every hash and checking every parent link. It then fetches the branch's checkpoints and checks each signature. Any mismatch is a failure with a non-zero exit, so you can gate a release pipeline on it; `--json` gives a machine-readable report.

![swarmfile-verify-history recomputes a branch's commits from the canonical encoding. Then one commit's recorded message is edited directly in the server's database, and the next run names the commit it broke and exits non-zero. The chain is recomputed, not taken on the hub's word.](https://swarmfile.com/demo/oss-tamper-verify.cast)

**Pin the key.** Without `--pin-key`, the verifier checks signatures against the public key the same service is serving you, which proves the checkpoints match *that* key but not that the key is genuine. Pass the key you recorded out-of-band (from an earlier run, or from us directly) with `--pin-key` and the run only accepts signatures from keys you supplied. That's the mode that gives you independent assurance. Repeat `--pin-key` to accept a rotated key alongside the old one.

**Key ↔ origin (self-hosted).** `--check-host-identity` fetches the server's signed `/.well-known/swarmfile.json`, requires its `origin` to match the repository URL and its key to be the active checkpoint key (or a pinned one).

A self-hosted server serves it when `SWARMFILE_SERVER_PUBLIC_URL` is set to its public origin; the hosted hub serves it at the hub origin when its dispatch worker carries the same history-signing secret and `HUB_PUBLIC_ORIGIN` (otherwise it fails closed with 503). It is optional; the chain/checkpoint check above runs either way.

The wire shape and a synthetic conformance fixture ship in the verifier's public-repo template (`docs/host-identity.md`, `fixtures/host-identity.json`) and publish with its next release.

**A portable origin manifest.** `--write-provenance origin.json` records a verified origin: the canonical origin URL, the head's commit facts/tree, the signed checkpoints and the key ring. Later, `--provenance origin.json --hub-url <mirror repository>` verifies the mirror offline - no origin contact - by re-hashing the manifest's commit, checking the head checkpoint signature (and any `--pin-key`), then accepting a matching mirror head **commit** or **tree**.

A plaintext destination written by `swarmfile-mirror --provenance-out` preserves the origin's block CIDs and entry lineage, so its tree and usually its confirmed commit match; an ordinary plaintext mirror copy has a different commit DAG and different entry lineages, so it does not tree-match; only a provenance-mode copy preserves the tree; a managed/E2E **mirror** copy re-seals and will not match; a same-server `swarmfile-server admin copy-repository` copies the key/data without re-sealing and preserves the managed commit DAG.

A manifest is a file, so `--provenance` requires `--pin-key` (the key obtained out-of-band) and should also pass `--origin <URL>` to bind the origin label; when the origin serves `/.well-known/swarmfile.json`, the manifest carries that signed statement and `originAttested` reports it.

Neither mode proves the tree object or any block is served by default; `--verify-blocks` samples file manifest/chunk blocks and re-hashes them, which proves the sampled bytes (not the whole mirror). Treat the manifest as the portable attestation and the mirror as the copy.

**Federated clones.** A clone through a federating server (`swarmfile://<hub>/fed/<peer>/<org>/<repository>`) is verified the same way: write the manifest against the origin, then run `--provenance <manifest> --pin-key <origin-key> --origin <origin-url> --hub-url <fed-url> --verify-blocks N`.

The federator carries the origin's history and blocks unchanged, so the mirror head/tree and sampled blocks match; the manifest, not the federator's own `/.well-known`, is what attests the origin. A live `--check-host-identity` pointed at the fed URL would check the federator (its origin root), not the peer, so use the manifest for federation.

**Checking a mirror.** Pass the mirror's repository URL and ids with `--mirror-hub-url`, `--mirror-repository-id` and `--mirror-org-id` (plus `--mirror-header` for its credential). The verifier verifies the origin exactly as above, fetches the mirror's **confirmed** head, and requires the mirror's confirmed head commit to equal the origin's verified head commit.

The commit hash binds the tree CID, so a matching head cannot substitute a different tree; the verifier does not fetch the mirror's tree/blocks or require the head to be checkpointed. A `swarmfile-mirror` copy does not preserve the commit DAG - use a replica that does. Read this together with the checkpoint signature/pin result.

A mismatch - or a mirror branch with no confirmed head - fails the run and is reported in `--json` as `mirrorHeadMatches: false`. If the **origin** branch has no confirmed head, the comparison cannot run: the run fails with `mirrorHeadMatches: null` and a "not compared" note.

## What it proves, and what it doesn't

- **It proves** that the history the service serves you is internally consistent - no edited commit, no broken link - and, with a pinned key, that the checkpoints on it were signed by the key you trust.
- **It doesn't, by itself, prove** that this is the same history you saw last month. The checks run against the checkpoints the service lists, so keep your own record of a commit hash you care about (a release, a delivery) - or of the checkpoints from an earlier run - and confirm it's still on the branch.
- **Provisional commits aren't covered** until they're confirmed. A branch with no confirmed commits yet reports that, rather than passing.
- **It needs the service to be reachable.** The verifier needs no Desktop App or mount, but it reads the commit objects and checkpoints from the service as it walks; it doesn't verify an exported bundle offline.
- **Checkpoints require checkpoint signing on the service.** Where the service doesn't have it enabled, the verifier reports verifiable history as unavailable - an informational result unless you pinned a key, in which case it's a failure.

## Where you'll see it

- **Releases** of a [public repository](https://swarmfile.com/docs/guides/public-repositories-and-org-profiles) marked **commit-pinned** name the exact commit hash they were published from. The badge is the pointer; `swarmfile-verify-history` is how you check it.
- **`git clone`** of a repository uses the same confirmed commits: each repository commit in the clone carries a `Swarmfile-Commit:` trailer naming the Swarmfile commit it came from (the graft commit that anchors history at the cut, if any, has no trailer). See [Cloning a Repository with Git](https://swarmfile.com/docs/guides/git-clone).
- **Reproducible checkouts** - `swarmfile materialize hash:<commit-hash>` writes exactly that commit's tree, the most precise pin you can give a CI job (tags can be moved; hashes can't).
