Verify the audit chain yourself.
Read every row of your project's audit chain and recompute its hashes on your own machine. No secret is involved, so anyone you give the rows to can do the same.
STARCO_KEY it runs as it is. The TypeScript and CLI tabs use the SDK and the command line, which are not published yet.The idea#
Each row's row_hash is the SHA-256 of the text "starco-dev-audit/v1\n" + project_id + "\n" + seq + "\n" + prev_hash + "\n" followed by one line per field, field=<byte length>:<value>, joined with new lines, for the fields seq, actor_type, actor_ref, action, resource_type, resource_id, http_status, detail, created_at (a missing value is written field=~). The first prev_hash is 64 zeros. GET /v1/audit returns the same rule as hash_input.
The whole program#
export API="https://api.starco.dev/v1"
AUTH="Authorization: Bearer $STARCO_KEY"
JSON="Content-Type: application/json"
# The server walks the chain for you; keep the head somewhere of your own and compare it later.
curl -s "$API/audit/verify" -H "$AUTH" | jq -c '{ok, events, head_seq, first_broken_seq}'
# Recomputing every hash needs more than a shell one-liner: see the Python tab (30 lines, standard library plus requests).import hashlib, os, requests
API = "https://api.starco.dev/v1"
H = {"Authorization": f"Bearer {os.environ['STARCO_KEY']}"}
FIELDS = ["seq", "actor_type", "actor_ref", "action", "resource_type", "resource_id", "http_status", "detail", "created_at"]
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 len(page["data"]) < 1000:
return page["project_id"], rows
after = rows[-1]["seq"]
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())}:{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()).hexdigest()
project_id, rows = read_chain()
prev = "0" * 64
for i, r in enumerate(rows, start=1):
assert r["seq"] == i, f"a row is missing before seq {r['seq']}"
assert r["prev_hash"] == prev and row_hash(project_id, r, prev) == r["row_hash"], f"the chain breaks at seq {i}"
prev = r["row_hash"]
print("chain ok:", len(rows), "rows recomputed here")import { Client } from '@starco/sdk';
const c = new Client({ baseUrl: "https://api.starco.dev/v1", apiKey: process.env.STARCO_KEY });
const mine = await c.audit.verifyLocal(); // reads every row and recomputes every hash on this machine
console.log("chain ok:", mine.ok, "·", mine.events, "rows recomputed here");
const theirs = await c.audit.verifyServer(); // the server's own walk, for comparison
console.log("server:", theirs.ok, "· head", theirs.head_seq);export STARCO_BASE_URL="https://api.starco.dev/v1" STARCO_API_KEY="$STARCO_KEY"
starco audit verify # «here» recomputes every hash on this machine; «server» is the API's own walk{"ok":true,"events":14,"head_seq":14,"first_broken_seq":null}The other tabs print the same facts in their own format. Ids, hashes and counts depend on your project.
What just happened
The server walked the chain and found it intact. The Python, TypeScript and CLI tabs go further: they read every row and recompute every hash on your machine, so the rows you were given are proven consistent with each other without trusting the server's answer. The server's walk counts one row more, because the request that read the chain is itself appended after its answer.