Export with a fingerprint.
Goal: take a twin out of STARCO as one file and prove, to yourself and to whoever you hand it to, that it is exactly what STARCO exported.
STEP 1 Export the twin Beta#
One request returns the whole twin: its layers as computed now, every observation, its typed measures and its current state, in the format starco-dev-export/v1. The SHA-256 of the exact bytes comes in the X-Content-SHA256 header. Save the body as it arrives: reformatting it changes the bytes.
export API="https://api.starco.dev/v1"
export STARCO_KEY="starco_dk_…"
TWIN=$(curl -s "$API/twins?limit=1" -H "Authorization: Bearer $STARCO_KEY" | jq -r '.data[0].id')
curl -s -D headers.txt -o twin.json "$API/twins/$TWIN/export" -H "Authorization: Bearer $STARCO_KEY"
grep -i x-content-sha256 headers.txtimport hashlib, os, requests
API = "https://api.starco.dev/v1"
H = {"Authorization": f"Bearer {os.environ['STARCO_KEY']}"}
twin = requests.get(f"{API}/twins", headers=H, params={"limit": 1}).json()["data"][0]["id"]
r = requests.get(f"{API}/twins/{twin}/export", headers=H)
open("twin.json", "wb").write(r.content) # the raw bytes
print(r.headers["X-Content-SHA256"])
print(list(r.json().keys()))import { createHash } from 'node:crypto';
import { readFileSync, writeFileSync } from 'node:fs';
import { Client } from '@starco/sdk';
const c = new Client({ baseUrl: "https://api.starco.dev/v1", apiKey: process.env.STARCO_KEY });
const twin = (await c.twins.list({ limit: 1 })).data[0].id;
const exp = await c.twins.export(twin); // throws IntegrityError if the bytes do not match the header
writeFileSync("twin.json", exp.raw); // the raw bytes
console.log(exp.sha256);
console.log(Object.keys(exp.data));starco twins export <twin> -o twin.json # any twin id of the project (starco twins list); the CLI checks the hash too6197cbaab1f53567d1e913a90a73a18e6ade2a2c8a01ae55fc7ec0830c719587
['format', 'operator', 'project_id', 'twin', 'layers', 'observations', 'measures', 'state']STEP 2 Recompute the fingerprint#
sha256sum twin.jsonprint(hashlib.sha256(open("twin.json", "rb").read()).hexdigest() == r.headers["X-Content-SHA256"])console.log(createHash("sha256").update(readFileSync("twin.json")).digest("hex") === exp.sha256);sha256sum twin.json6197cbaab1f53567d1e913a90a73a18e6ade2a2c8a01ae55fc7ec0830c719587 twin.json
TrueSTEP 3 Find the export in the audit chain Beta#
The export is a row of the project's chain with the same fingerprint in detail. Anyone who receives the file can compare its SHA-256 with that row, and verify the chain itself (tutorial 05).
curl -s "$API/audit?limit=1000" -H "Authorization: Bearer $STARCO_KEY" | jq '.data[] | select(.action == "twins.export") | {seq, actor_ref, detail}'rows = requests.get(f"{API}/audit", headers=H, params={"limit": 1000}).json()["data"]
for e in rows:
if e["action"] == "twins.export":
print(e["seq"], e["actor_ref"], e["detail"])for await (const e of c.audit.iter()) {
if (e.action === "twins.export") console.log(e.seq, e.actor_ref, e.detail);
}starco --json audit list --limit 1000 | jq '.data[] | select(.action == "twins.export") | {seq, actor_ref, detail}'29 starco_dk_fb7fa299 {"sha256":"6197cbaab1f53567d1e913a90a73a18e6ade2a2c8a01ae55fc7ec0830c719587","observations":1}If the project has more than 1000 rows, follow next_after_seq as in tutorial 05.
STEP 4 Change one byte#
data = bytearray(open("twin.json", "rb").read())
data[data.index(b'"synthetic"') + 1] ^= 0x20 # "synthetic" → "Synthetic"
print(hashlib.sha256(bytes(data)).hexdigest())const data = Buffer.from(readFileSync("twin.json"));
data[data.indexOf('"synthetic"') + 1] ^= 0x20; // "synthetic" → "Synthetic"
console.log(createHash("sha256").update(data).digest("hex"));a completely different fingerprintOne letter changed and nothing of the fingerprint survives: the file no longer matches the header nor the row of the chain.
What just happened
You hold the twin as a single document whose fingerprint was computed by STARCO, sent with it and written to the audit chain. For reproducible research, cite the fingerprint next to the dataset. Missing values in the export are null, never zero. The export is of synthetic data: the sandbox holds nothing else.