Export a twin, check its fingerprint.
Download a twin as one JSON document and prove that the bytes you stored are the bytes the server sent.
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#
GET /v1/twins/{twin}/export returns the twin, its layers, observations, measures and state as one document. The header X-Content-SHA256 is the SHA-256 of exactly those bytes: hash the file you saved, not a re-serialised copy.
The whole program#
export API="https://api.starco.dev/v1"
AUTH="Authorization: Bearer $STARCO_KEY"
JSON="Content-Type: application/json"
TWIN=$(curl -s "$API/twins?limit=1" -H "$AUTH" | jq -r '.data[0].id') # one of the synthetic twins of the project
curl -s -D headers.txt -o twin.json "$API/twins/$TWIN/export" -H "$AUTH"
SENT=$(grep -i '^x-content-sha256:' headers.txt | tr -d '\r' | sed 's/^.*: //')
MINE=$(sha256sum twin.json | cut -d' ' -f1)
[ "$SENT" = "$MINE" ] && echo "fingerprint ok: $MINE" || { echo "fingerprint MISMATCH"; exit 1; }
jq -r '"\(.format) · \(.observations | length) observations"' twin.jsonimport hashlib, json, 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)
mine = hashlib.sha256(r.content).hexdigest() # the bytes as received, not r.json()
assert mine == r.headers["X-Content-SHA256"], "fingerprint mismatch"
open("twin.json", "wb").write(r.content)
doc = json.loads(r.content)
print("fingerprint ok:", mine)
print(doc["format"], "·", len(doc["observations"]), "observations")import { Client } from '@starco/sdk';import { writeFile } from 'node:fs/promises';
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 exported = await c.twins.export(twin); // throws IntegrityError unless SHA-256(bytes) == X-Content-SHA256
await writeFile("twin.json", exported.raw);
console.log("fingerprint ok:", exported.sha256);
console.log(exported.data.format, "·", exported.data.observations.length, "observations");export STARCO_BASE_URL="https://api.starco.dev/v1" STARCO_API_KEY="$STARCO_KEY"
TWIN=$(starco --json twins list --limit 1 | jq -r '.[0].id')
starco twins export $TWIN -o twin.json
sha256sum twin.jsonfingerprint ok: 6c1f…e2a9
starco-dev-export/v1 · 168 observationsThe other tabs print the same facts in their own format. Ids, hashes and counts depend on your project.
What just happened
The hash of the file equals the header, so what is on disk is what STARCO sent. Keep the fingerprint with the file: the receipt of a later erasure of the twin carries the fingerprint of its last export.