Record a refund

Record a human approval, the agent's refund intent that cites it, and the outcome, then read them back and verify the stream.

A support agent wants to refund a charge, and a person, Alice, approves it first. You will record three entries: Alice's approval, the agent's intent that cites the approval by its entry hash and names the policy and rule it relied on, and the outcome once the refund ran. Then you read them back and verify the stream against its pinned fingerprint. Pick a language once: every tab on the page follows it.

Prerequisites

  • A shell with jq and openssl (for the CLI and REST tabs).
  • The tool for your language:
cargo install tenbri-cli --version 0.1.0-beta.5 --locked

Set these in every terminal you use. Keys live in $TENBRI_KEYS, never inside the stream; this recipe keeps them in ./keys. The digest key keys the HMAC of each input the agent read, so a guessed policy text cannot be confirmed from the log without it.

export TENBRI_KEYS=./keys
export TENBRI_DIGEST_KEY='a 32-byte secret, kept apart....'

Steps

Create the stream, then record the approval, the intent and the outcome

An approval needs a principal (the approver) and an action (what is approved). The intent cites it as {"by": <approver>, "entry": <entry hash>}, where the entry hash is SHA-256 of a zero byte followed by the stored line (canonical JSON), as sha256:<hex>. The intent is durable before the refund runs; the outcome closes it by id.

tenbri init audit/support
created stream tnb1:8c356644867656415b19906e2528f4b2 at audit/support
stream key fingerprint (pin it): sha256:8c356644867656415b19906e2528f4b261e594f9b85164b5e22ff74cbbd12f9d
keys: ./keys/tnb1-8c356644867656415b19906e2528f4b2
pinned in ./keys/pins: tenbri verify audit/support uses it
verify with: tenbri verify audit/support --key sha256:8c356644867656415b19906e2528f4b261e594f9b85164b5e22ff74cbbd12f9d

init writes two key entries (seq 1 and 2): the stream key and the first session key. It also records the fingerprint in ./keys/pins, so tenbri verify on this machine needs no --key. tenbri append reads a draft on stdin and prints the entry as stored.

APPROVAL=$(tenbri append audit/support <<'EOF'
{
  "kind": "approval",
  "principal": {"kind": "person", "id": "alice"},
  "action": {"type": "issue_refund", "target": "stripe:charge/ch_3PqX"}
}
EOF
)
APPROVAL_HASH="sha256:$(printf '\0%s' "$APPROVAL" | shasum -a 256 | cut -d' ' -f1)"
POLICY_DIGEST="hmac-sha256:$(printf '%s' 'refunds under 100 EUR are automatic' \
  | openssl dgst -sha256 -hmac "$TENBRI_DIGEST_KEY" -r | cut -d' ' -f1)"

INTENT=$(tenbri append audit/support <<EOF
{
  "kind": "decision",
  "phase": "intent",
  "source": "sdk",
  "principal": {"kind": "agent", "id": "support-assistant"},
  "action": {"type": "issue_refund", "target": "stripe:charge/ch_3PqX"},
  "inputs": [{"ref": "policy:refund", "version": "14", "digest": "$POLICY_DIGEST"}],
  "rule": {"ref": "rule:refund-under-100", "version": "3", "result": "allow"},
  "approval": {"by": {"kind": "person", "id": "alice"}, "entry": "$APPROVAL_HASH"}
}
EOF
)
echo "$INTENT"
{"action":{"target":"stripe:charge/ch_3PqX","type":"issue_refund"},"approval":{"by":{"id":"alice","kind":"person"},"entry":"sha256:784f5e7a…"},"id":"01M5D3J7EBSK1NCZXDYBVBAVNE","inputs":[{"digest":"hmac-sha256:100d69e9…","ref":"policy:refund","version":"14"}],"kind":"decision","phase":"intent","prev":"sha256:784f5e7a…","principal":{"id":"support-assistant","kind":"agent"},"rule":{"ref":"rule:refund-under-100","result":"allow","version":"3"},"seq":4,"sig":"ed25519:0df9aedf…","signer":"sess:2026-10-20:80abf05d8816","source":"sdk","stream":"tnb1:8c356644867656415b19906e2528f4b2","ts":"2026-10-20T16:50:55.051Z","v":1}

Run the refund, then record the outcome:

INTENT_ID=$(echo "$INTENT" | jq -r .id)
tenbri append audit/support <<EOF
{
  "kind": "decision",
  "phase": "outcome",
  "source": "sdk",
  "intent": "$INTENT_ID",
  "status": "ok",
  "principal": {"kind": "agent", "id": "support-assistant"},
  "action": {"type": "issue_refund", "target": "stripe:charge/ch_3PqX"}
}
EOF
{"action":{"target":"stripe:charge/ch_3PqX","type":"issue_refund"},"id":"01M5D3J7F5YPGC7846E6YYQCEE","intent":"01M5D3J7EBSK1NCZXDYBVBAVNE","kind":"decision","phase":"outcome","prev":"sha256:d66d6353…","principal":{"id":"support-assistant","kind":"agent"},"seq":5,"sig":"ed25519:0fd26589…","signer":"sess:2026-10-20:80abf05d8816","source":"sdk","status":"ok","stream":"tnb1:8c356644867656415b19906e2528f4b2","ts":"2026-10-20T16:50:55.077Z","v":1}

In every tab, the intent's prev equals the approval's entry hash: the approval is the entry just before it, so the hash you computed is the one the chain uses. An approval.entry that does not name an earlier approval entry is refused with bad_approval.

Read the entries back and verify

Pin the fingerprint the stream printed when you created it. Reads then check the stream against it, and each match carries its verification status.

Without a query index, query reads and verifies the whole stream, so each row is verified. With one (tenbri index rebuild), rows are indexed: each is checked against the batch in storage that holds it, and a batch edited on disk fails the query with exit 1. On this machine, init recorded the pin, so neither command needs --key:

tenbri query audit/support --action issue_refund
tenbri verify audit/support
     3  2026-10-20T16:50:54.997Z  approval          person:alice             issue_refund stripe:charge/ch_3PqX -        verified
     4  2026-10-20T16:50:55.051Z  decision intent   agent:support-assistant  issue_refund stripe:charge/ch_3PqX -        verified
     5  2026-10-20T16:50:55.077Z  decision outcome  agent:support-assistant  issue_refund stripe:charge/ch_3PqX ok       verified
verified 5 entries, stream tnb1:8c356644867656415b19906e2528f4b2, pinned to sha256:8c356644867656415b19906e2528f4b261e594f9b85164b5e22ff74cbbd12f9d (the pin recorded in ./keys/pins)

tenbri show prints one entry with the entries it is linked to. For the intent, that is the approval it cites and its outcome:

tenbri show audit/support 4
seq 4  decision intent  01M5D3J7EBSK1NCZXDYBVBAVNE
  ts           2026-10-20T16:50:55.051Z
  hash         sha256:d66d63538a81dee9d3cc34dffc25100546c63d8e537525476fec5329d60c475d
  action       issue_refund stripe:charge/ch_3PqX
  approval     {"by":{"id":"alice","kind":"person"},"entry":"sha256:784f5e7a24affdb7d273f0414034249f194c6a053da0066729025e016390fdf6"}
  inputs       [{"digest":"hmac-sha256:100d69e9c08449fc44312548262ade65ca9aeed0d8e84e32eff2a8a39dbc40ad","ref":"policy:refund","version":"14"}]
  principal    agent:support-assistant
  rule         {"ref":"rule:refund-under-100","result":"allow","version":"3"}
  signer       sess:2026-10-20:80abf05d8816
  source       sdk
  verification verified, pinned to sha256:8c356644867656415b19906e2528f4b261e594f9b85164b5e22ff74cbbd12f9d (recorded in ./keys/pins)

chain:
      3  2026-10-20T16:50:54.997Z  approval          person:alice             issue_refund stripe:charge/ch_3PqX -        verified
>     4  2026-10-20T16:50:55.051Z  decision intent   agent:support-assistant  issue_refund stripe:charge/ch_3PqX -        verified
      5  2026-10-20T16:50:55.077Z  decision outcome  agent:support-assistant  issue_refund stripe:charge/ch_3PqX ok       verified

Piped, query prints JSON for jq. JSON output uses only --key, so scripts pass the pin:

PIN=sha256:8c356644867656415b19906e2528f4b261e594f9b85164b5e22ff74cbbd12f9d
tenbri query audit/support --action issue_refund --key $PIN \
  | jq -c '{verification, seq, kind: .entry.kind, phase: .entry.phase, status: .entry.status, approved_by: .entry.approval.by.id}'
{"verification":"verified","seq":3,"kind":"approval","phase":null,"status":null,"approved_by":null}
{"verification":"verified","seq":4,"kind":"decision","phase":"intent","status":null,"approved_by":"alice"}
{"verification":"verified","seq":5,"kind":"decision","phase":"outcome","status":"ok","approved_by":null}

All four ways write the same format to the same kind of stream. A stream written from Python verifies with tenbri verify, and the reverse.

What happened

You wrote three signed entries that chain to each other. The intent cites the approval by its entry hash and pins the policy version and rule it relied on, so none of them can be swapped or edited without breaking verification. The outcome names its intent by id, which closes it: an intent without an outcome is reconciled with status: unknown by a later writer after an hour.

Edit on GitHub

On this page