Beta. STARCO Dev works with synthetic data only: do not send real personal or health data. Every feature shows its real status (Available Beta Beta · in development Coming).

Documentation menu

Tutorial 05

Verify the audit chain.

Goal: read who accessed your project, ask STARCO to verify the chain, then verify it yourself so you do not have to take our word for it.

time 15 minlevel intermediateuses audit chain Beta · key with the read scope Betatabs curl · Python · TypeScript · CLI (the SDK and the command line are not published as packages yet)
  1. 1Read
  2. 2Verify
  3. 3Yourself
  4. 4Tamper
  5. 5Anchor

STEP 1 Read the rows#

Rows come in chain order, up to 1000 per page; follow next_after_seq until it is null. The row of the request that lists them is appended after the answer, so it appears next time.

curl "$API/audit?limit=1000" -H "Authorization: Bearer $STARCO_KEY"
Rows (trimmed)illustrative · synthetic
1 2026-11-19T15:39:40Z console e4a1c7d0-…         project.created     201
2 2026-11-19T15:39:40Z system  None                cohort.generated    None
3 2026-11-19T15:40:02Z console e4a1c7d0-…         key.created         201
4 2026-11-19T15:42:07Z key     starco_dk_51c0e7d2  twins.store         201
5 2026-11-19T15:42:31Z key     starco_dk_51c0e7d2  observations.store  200
6 2026-11-19T15:42:44Z key     starco_dk_51c0e7d2  layers.show         200
…

Each row has exactly the fields the hash covers, plus prev_hash and row_hash. The first row points to the genesis, 64 zeros.

{ "seq": 5, "actor_type": "key", "actor_ref": "starco_dk_51c0e7d2", "action": "observations.store",
  "resource_type": "twin", "resource_id": "3a9d5e2c-8b14-4f7a-a6d1-c2e09f4b7d31", "http_status": 200,
  "detail": "{\"batch_id\":\"c1d2e3f4-…\",\"accepted\":1,\"rejected\":0,\"recomputed_layers\":[\"wellness\"]}",
  "created_at": "2026-11-19T15:42:31Z", "prev_hash": "b3d9…07bd", "row_hash": "e27a…c2e1" }

detail is JSON text, exactly as hashed: counts and ids, never an observation value or a secret.

STEP 2 Ask STARCO to verify#

curl "$API/audit/verify" -H "Authorization: Bearer $STARCO_KEY"
Expected outputillustrative · synthetic
{ "project_id": "0b7e4c1a-5d2f-4e8a-9c3b-7f1e2d6a8b90", "ok": true, "events": 9,
  "head_seq": 9, "head_hash": "c9f2…e810", "first_broken_seq": null, "reason": null }

When the chain is broken, ok is false, first_broken_seq names the first bad row and reason says why: missing_or_reordered_event, broken_link, content_changed or head_mismatch.

STEP 3 Verify it yourself#

The rule, also returned by GET /v1/audit as hash_input: row_hash is the SHA-256 of "starco-dev-audit/v1\n" + project_id + "\n" + seq + "\n" + prev_hash + "\n" followed by one line per field, in the order below, written field=<byte length>:<value> (or field=~ when the value is null) and joined by \n. Each prev_hash must equal the row_hash before it. No secret is involved.

import hashlib

GENESIS = "0" * 64
FIELDS = ["seq", "actor_type", "actor_ref", "action", "resource_type",
          "resource_id", "http_status", "detail", "created_at"]

def row_hash(project_id, row, prev):
    lines = []
    for f in FIELDS:
        v = row[f]
        lines.append(f"{f}=~" if v is None else f"{f}={len(str(v).encode('utf-8'))}:{v}")
    text = f"starco-dev-audit/v1\n{project_id.lower()}\n{row['seq']}\n{prev}\n" + "\n".join(lines)
    return hashlib.sha256(text.encode("utf-8")).hexdigest()

def verify(project_id, rows):
    prev = GENESIS
    for expected, r in enumerate(rows, start=1):
        if r["seq"] != expected:
            return f"missing_or_reordered_event at seq {expected}"
        if r["prev_hash"] != prev:
            return f"broken_link at seq {r['seq']}"
        if row_hash(project_id, r, prev) != r["row_hash"]:
            return f"content_changed at seq {r['seq']}"
        prev = r["row_hash"]
    return f"intact · {len(rows)} rows · head {prev[:4]}…{prev[-4:]}"

print(verify(project_id, rows))
Expected outputillustrative · synthetic
intact · 9 rows · head c9f2…e810

Your own check covers the rows you read; compare its head with head_seq and head_hash from step 2, or with audit_head of GET /v1/projects/{id} in the console.

STEP 4 See what tampering looks like#

Change one field in your local copy and run the check again. The changed row no longer matches its hash; if someone also rewrote that hash, the next row's prev_hash would stop matching.

import copy
forged = copy.deepcopy(rows)
forged[4]["action"] = "nothing.happened"
print(verify(project_id, forged))
Expected outputillustrative · synthetic
content_changed at seq 5

STEP 5 Keep an anchor#

The chain is tamper-evident, not tamper-proof: whoever could write to the database could rebuild a whole chain. STARCO does not yet anchor the heads of project chains outside its database, so write the head down from time to time somewhere you control: a ticket, a commit, an email to yourself. Later, an intact chain that still has that hash at the same seq shows that nothing before it was rewritten.

head = requests.get(f"{API}/audit/verify", headers=H).json()
with open("starco-anchors.txt", "a") as f:
    f.write(f"{head['head_seq']} {head['head_hash']}\n")

What just happened

You read the chain, had STARCO verify it and then verified it yourself with about twenty lines of Python and no secret of ours. Each row is sealed by its own hash and tied to the one before, so a change anywhere shows up immediately.

seq 1…a41e seq 2…07bd seq 3 ✎hash ≠ seq 4prev ? a change anywhere breaks every link after it

Next steps#