Developers

Verify the chain

Recompute every trade hash yourself, with nothing but the public API and SHA-256.

The rule

For each record, in order of seq:

  1. hash = SHA-256 of the payload below, written as lowercase hex.
  2. prevHash = the previous record's hash. For record 1, it is 64 zeros.
  3. seq increases by exactly 1, with no gaps.
payload = [ "trade-chain:v1", seq, prevHash, positionId, market, side, kind, closeSeq,
            price, snapshotId, notional, leverage, realizedPnl ?? "", tsMicros ].join("|")

GET /public/chain/:seq returns exactly these fields.

Script (Node.js 18+ or a browser console)

const API = 'https://app.<domain>/api';
const hex = (buf) => [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, '0')).join('');
const sha256 = async (s) => hex(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(s)));

const payload = (r) => ['trade-chain:v1', r.seq, r.prevHash, r.positionId, r.market, r.side, r.kind, r.closeSeq,
  r.price, r.snapshotId, r.notional, r.leverage, r.realizedPnl ?? '', r.tsMicros].join('|');

const head = await (await fetch(`${API}/public/chain`)).json();
let prev = '0'.repeat(64);
for (let seq = 1; seq <= Number(head.head.seq); seq++) {
  const { record: r } = await (await fetch(`${API}/public/chain/${seq}`)).json();
  if (r.prevHash !== prev) throw new Error(`#${seq}: broken link`);
  if ((await sha256(payload(r))) !== r.hash) throw new Error(`#${seq}: hash mismatch`);
  prev = r.hash;
}
console.log(`verified ${head.head.seq} records, head ${prev}`);

If the final hash matches one you saved earlier, or a published anchor, history up to that point is unchanged.