Specification · v1

Canonicalization v1

A record's hash is a function of 24 named fields, nothing else. This page is the whole rule, plus a published test vector, so you can rebuild the verifier without Aprve's code and without trusting this site.

01

The field set

Exactly these 24 fields are hashed, in this order. Any other column on the record (ids, timestamps assigned by the database, anchor state, statement fields) is deliberately outside the hash, so anchoring and receipts can be added later without breaking a single existing hash.

client_idproject_idseqdecision_iddecided_atagent_idagent_nameaction_toolaction_amount_usdaction_data_classesaction_targetrisk_scoredecisiondecision_sourcematched_rule_idmatched_rule_namepolicy_idpolicy_versionexplanationrecord_typecorrection_ofhandoff_fromtraining_excludedprev_hash

Absent values are null. Two defaults are not null: action_data_classes is an empty array, record_type is "authorization", and training_excluded is false.

02

The serialization

Keys are sorted ascending by UTF-16 code unit, strings are JSON-escaped, there is no whitespace, and arrays keep their stored order. Then SHA-256 over the UTF-8 bytes, lowercase hex, 64 characters. The chain rule is one line: a record's prev_hash equals the previous record's hash for the same client. The first record in a client's chain uses 64 zeros.

03

Test vector

This is the permanent demo record, byte for byte. Feed the preimage below to SHA-256 and you must get the hash underneath it. If you do not, your serializer differs from this spec and nothing else on the page matters.

canonical preimage · 24 fields
{"action_amount_usd":180,"action_data_classes":[],"action_target":"order/4417","action_tool":"refund.create","agent_id":"demo-agent-01","agent_name":"Demo agent","client_id":"6b048d50f944cb895b485f90","correction_of":null,"decided_at":"2026-11-23T19:00:33.315Z","decision":"allow","decision_id":"dec_demo_permanent","decision_source":"policy","explanation":"The refund is under the automated ceiling and touches no restricted data class.","handoff_from":null,"matched_rule_id":"spend-under-250","matched_rule_name":"Refunds up to 250 USD","policy_id":"6b048d51fa85c086cf641ff1","policy_version":1,"prev_hash":"0000000000000000000000000000000000000000000000000000000000000000","project_id":null,"record_type":"authorization","risk_score":null,"seq":1,"training_excluded":false}
sha-256 of the preimage (utf-8)
078506dc868d5413af74db8267801c4bf602dea47d0446ef97ca517d5e8a5948

The same value resolves at the public verification page. A verifier that reproduces this hash agrees with Aprve on every record.

04

Reference implementations

Both are complete: no imports beyond the standard library, no Aprve endpoint.

node.js
import { createHash } from "node:crypto";

const FIELDS = [
  "client_id",
  "project_id",
  "seq",
  "decision_id",
  "decided_at",
  "agent_id",
  "agent_name",
  "action_tool",
  "action_amount_usd",
  "action_data_classes",
  "action_target",
  "risk_score",
  "decision",
  "decision_source",
  "matched_rule_id",
  "matched_rule_name",
  "policy_id",
  "policy_version",
  "explanation",
  "record_type",
  "correction_of",
  "handoff_from",
  "training_excluded",
  "prev_hash"
];

// 1. Take the 24 named fields, in this order, with these defaults.
function canonical(record) {
  const pick = {
    client_id: record.client_id ?? null,
    project_id: record.project_id ?? null,
    seq: record.seq ?? null,
    decision_id: record.decision_id ?? null,
    decided_at: record.decided_at ?? null,
    agent_id: record.agent_id ?? null,
    agent_name: record.agent_name ?? null,
    action_tool: record.action_tool ?? null,
    action_amount_usd: record.action_amount_usd ?? null,
    action_data_classes: record.action_data_classes ?? [],
    action_target: record.action_target ?? null,
    risk_score: record.risk_score ?? null,
    decision: record.decision ?? null,
    decision_source: record.decision_source ?? null,
    matched_rule_id: record.matched_rule_id ?? null,
    matched_rule_name: record.matched_rule_name ?? null,
    policy_id: record.policy_id ?? null,
    policy_version: record.policy_version ?? null,
    explanation: record.explanation ?? null,
    record_type: record.record_type ?? "authorization",
    correction_of: record.correction_of ?? null,
    handoff_from: record.handoff_from ?? null,
    training_excluded: record.training_excluded ?? false,
    prev_hash: record.prev_hash ?? null,
  };
  return pick;
}

// 2. Serialize with keys sorted ascending by UTF-16 code unit, no whitespace.
function stable(value) {
  if (value === null || typeof value !== "object") return JSON.stringify(value);
  if (Array.isArray(value)) return `[${value.map(stable).join(",")}]`;
  const keys = Object.keys(value).sort();
  return `{${keys.map((k) => `${JSON.stringify(k)}:${stable(value[k])}`).join(",")}}`;
}

// 3. SHA-256 over the UTF-8 bytes, lowercase hex.
const hash = (record) => createHash("sha256").update(stable(canonical(record)), "utf8").digest("hex");
python
import json, hashlib

FIELDS = [
  "client_id",
  "project_id",
  "seq",
  "decision_id",
  "decided_at",
  "agent_id",
  "agent_name",
  "action_tool",
  "action_amount_usd",
  "action_data_classes",
  "action_target",
  "risk_score",
  "decision",
  "decision_source",
  "matched_rule_id",
  "matched_rule_name",
  "policy_id",
  "policy_version",
  "explanation",
  "record_type",
  "correction_of",
  "handoff_from",
  "training_excluded",
  "prev_hash"
]

DEFAULTS = {"action_data_classes": [], "record_type": "authorization", "training_excluded": False}

def canonical(record):
    out = {}
    for f in FIELDS:
        if f in record and record[f] is not None:
            out[f] = record[f]
        else:
            out[f] = DEFAULTS.get(f, None)
    return out

def stable(value):
    return json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=False)

def hash_record(record):
    return hashlib.sha256(stable(canonical(record)).encode("utf-8")).hexdigest()
05

Conformance

A verifier conforms when it reproduces the test vector above and rejects a record whose stored hash does not match its recomputation. Run it in CI: the vector is the change detector. Adding, removing, reordering or re-defaulting any field changes every hash in every chain, so a conforming suite fails loudly the moment that happens instead of quietly agreeing with a broken server.

  • Same 24 fields, same order, same defaults.
  • Same stable serialization, no whitespace, sorted keys.
  • Same digest: SHA-256, UTF-8, lowercase hex.
  • Same chain rule, with 64 zeros at genesis.
  • The demo vector reproduces exactly.

A version bump is a new page at a new path, never an edit to this one. Records keep the version they were written under, so an old hash stays checkable after the rule moves.

secured by Aprve · hash-chained, append-only

A decision you can verify right now
permanent demo decisionALLOW
action
refund.create · $180
rule
Refunds up to 250 USD
record
seq 1
sha-256
078506dc86…8a5948
statement
anchored
receipt
moment-j5xx23u1
dec_demo_permanent

Cite: Aprve decision dec_demo_permanent, seq 1, sha-256 078506dc868d5413af74db8267801c4bf602dea47d0446ef97ca517d5e8a5948