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.
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"def read_chain():
rows, after = [], 0
while True:
page = requests.get(f"{API}/audit", headers=H, params={"after_seq": after, "limit": 1000}).json()
rows += page["data"]
if page["next_after_seq"] is None:
return page["project_id"], rows
after = page["next_after_seq"]
project_id, rows = read_chain()
for e in rows[:6]:
print(e["seq"], e["created_at"], e["actor_type"], e["actor_ref"], e["action"], e["http_status"])import { appendFileSync } from 'node:fs';
import { Client, verifyChain } from '@starco/sdk';
const c = new Client({ baseUrl: "https://api.starco.dev/v1", apiKey: process.env.STARCO_KEY });
const rows = [];
for await (const e of c.audit.iter()) rows.push(e); // follows next_after_seq for you
for (const e of rows.slice(0, 6)) console.log(e.seq, e.created_at, e.actor_type, e.actor_ref, e.action, e.http_status);starco audit list --limit 61 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"print(requests.get(f"{API}/audit/verify", headers=H).json())console.log(await c.audit.verifyServer());starco audit verify # the line "server" is this answer; the line "here" is step 3{ "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))// The SDK carries the same algorithm as the Python tab (rowHash and verifyChain) and runs it on your machine.
const local = await c.audit.verifyLocal();
console.log(local.ok ? `intact · ${local.events} rows · head ${local.head_hash.slice(0, 4)}…${local.head_hash.slice(-4)}`
: `${local.reason} at seq ${local.first_broken_seq}`);starco audit verify # "here": every hash recomputed on your machine; exit status 1 if either line is brokenintact · 9 rows · head c9f2…e810Your 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))const forged = structuredClone(rows);
forged[4].action = "nothing.happened";
const check = await verifyChain(local.project_id, forged);
console.log(`${check.reason} at seq ${check.first_broken_seq}`);content_changed at seq 5STEP 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")const head = await c.audit.verifyServer();
appendFileSync("starco-anchors.txt", `${head.head_seq} ${head.head_hash}\n`);starco --json audit verify | jq -r '.server | "\(.head_seq) \(.head_hash)"' >> starco-anchors.txtWhat 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.