TruehandsDocs
engine 0.4.0 API Back to site

DocsTruehands Audit

Signed capture

Pixels and sensor logs can both be faked well enough to pass any check that only looks at them: generated video, a screen filmed through the app, a gyro log computed from the picture. A signature made on the phone when the clip was recorded cannot, as long as the key stays in the device's secure hardware. Signed capture is Truehands' answer to footage that was never filmed; Truehands does not try to detect AI-generated video from its pixels.

The contract is called capture-attestation-v1. The engine's half, which verifies, is in truehands/attest.py. The capture app's half is to sign what it records.

How it works#

  1. Enrollment. Each phone generates an Ed25519 key pair, ideally in its secure hardware, and the public key is registered in the program's devices.json.
  2. Recording. When a clip is recorded, the app hashes the video stream and the sensor log, builds a payload with the device id, the times and a nonce issued by your collection server for this upload, signs it, and uploads the signed document next to the clip.
  3. Audit. The manifest names each clip's document. The engine checks the signature against the enrolled key, then ties every signed claim to this submission: the same device, the same video stream, the same sensor log, the same length, inside the collection window, with a nonce not used before.

The document#

JSON
{
  "spec": "capture-attestation-v1",
  "payload": {
    "device_id": "dev-5712",
    "video_stream_sha256": "8ba5e249d6a5cd772e50da38915326e171c1e628bf1048a3be1199f2b9dd8c4a",
    "imu_sha256": "8d9b06c745f9efaa9c8b7cf981baaed30a098d10b1f6db43a8ebe4fd75aad3f4",
    "started_at": "2026-10-01T16:44:30Z",
    "ended_at": "2026-10-01T16:44:45Z",
    "app": "HomeTasks/2.3",
    "nonce": "n-0001"
  },
  "signature": "1s5HJANxhWZd4ldcQBrDVVKGm7dyj+IXFd612Lc3vEGNPswYhlJaS17abiasTbhes5f+XhWBo1ZjtXbsQIxWCg=="
}
FieldRequiredMeaning
specyesExactly capture-attestation-v1.
payload.device_idyesThe enrolled device. Must equal the manifest's device_id for the clip.
payload.video_stream_sha256yesSHA-256 of the coded packets of the first video stream, 64 lowercase hex characters.
payload.imu_sha256with a sensor logSHA-256 of the exact bytes of the sensor-log file uploaded with the clip; null or absent when there is none.
payload.started_at, payload.ended_atyesRecording start and end, ISO 8601 with a time zone.
payload.nonceyesA value your collection server issued for this upload.
payload.appnoThe capture app and version. Signed, not checked.
signatureyesBase64 of the 64-byte Ed25519 signature of the canonical JSON of payload.

The document may be at most 16 KiB.

Canonical JSON#

The signature covers the payload serialised exactly like this:

truehands/attest.py: canonical_json
def canonical_json(payload):
    return json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")

Keys sorted by code point, no whitespace, UTF-8, non-ASCII characters written as they are. In another language, the simplest way to match it byte for byte is to keep every value a string (or null for imu_sha256) made of printable ASCII, and to write the seven keys in sorted order: app, device_id, ended_at, imu_sha256, nonce, started_at, video_stream_sha256.

The video stream hash#

Hash the coded packets of the first video stream, in order, not the file. That hash survives remuxing and retagging, so moving the clip between containers or adding audio does not break the proof. It is the same value the engine uses to find exact copies, and FFmpeg computes it:

Shell
ffmpeg -v error -i clip.mp4 -map 0:v:0 -c copy -f hash -hash sha256 -
# SHA256=8ba5e249d6a5cd772e50da38915326e171c1e628bf1048a3be1199f2b9dd8c4a

Enrolling devices: devices.json#

JSON
{
  "dev-5712": {"public_key": "q1qDPeUV/Q/wJRhCbQ1bHVYbrxhwAzQfAPIp8FEy57M=", "revoked": false},
  "dev-6bf4": {"public_key": "…", "revoked": true}
}

Each key is a device id; public_key is the base64 of the raw 32-byte Ed25519 public key. A device marked "revoked": true, or with a key that is not 32 bytes of valid base64, is left out, so its signatures no longer verify. The file sits in the program folder, is at most 8 MiB, and must exist when signed capture is on: without it the whole run fails rather than accepting unsigned footage silently.

Turning it on#

In program.json:

JSON
"attestation": {"mode": "required", "devices": "devices.json"}
  • mode: required holds every clip without a document for review (attestation_missing); optional checks the documents that are present and says nothing about the rest. Default optional.
  • devices: the device list, relative to the program folder. Default devices.json.
  • Set window_start and window_end in program.json to also check that each clip was recorded inside the collection window.

In manifest.csv, add an attestation_file column with each clip's document, relative to the program folder:

CSV
clip_id,contributor_id,device_id,claimed_task,submitted_at,file,imu_file,attestation_file
s0004,c12,dev-5712,slicing vegetables,2026-10-01T16:45:00+00:00,clips/s0004.mp4,imu/s0004.csv,attestations/s0004.attestation.json

In your own AWS account, the runner fetches the documents and the device list from S3 along with the clips.

What the engine verifies#

In this order; the first failure decides the message:

  1. The document exists inside the program folder, is at most 16 KiB, is JSON, names the spec and has a payload object.
  2. The payload has non-empty device_id, video_stream_sha256, started_at, ended_at and nonce.
  3. The device is enrolled and not revoked.
  4. The signature is valid for the canonical payload under that device's key.
  5. The signed device is the device the manifest names for the clip.
  6. The signed stream hash is 64 lowercase hex characters and equals the hash of the submitted video's stream.
  7. If the clip comes with a sensor log, imu_sha256 equals the hash of that file; if it does not, the payload signs no log.
  8. The recording ends after it starts, and its signed length is within 2 s plus 2% of the video's measured length. Footage slowed down after recording is longer than what was signed.
  9. When the program has a collection window and started_at has a time zone, the recording started inside the window.
  10. The nonce has not been used by another clip in the run.
OutcomeReason codeDefaultA policy may choose
Every check passesnone; the clip's signals.attested is true
A check failsattestation_invalidrejectreject, review
mode: required and no documentattestation_missingreviewreview, reject, ignore
A step fails inside the engineengine_errorreviewreview

A reference signer#

A capture app does this on the device. This Python version does the same on a computer, for tests and as a reference; it produces documents that truehands.attest.verify accepts.

sign_clip.py
"""Sign one clip: python3 sign_clip.py KEY.pem clip.mp4 [imu.csv] --device dev-5712 --nonce N --started 2026-10-01T16:44:30Z"""
import argparse, base64, hashlib, json, subprocess, sys
from datetime import datetime, timedelta, timezone

from cryptography.hazmat.primitives.serialization import load_pem_private_key


def canonical_json(payload):
    return json.dumps(payload, sort_keys=True, separators=(",", ":"), ensure_ascii=False).encode("utf-8")


def video_stream_sha256(path):
    out = subprocess.run(["ffmpeg", "-v", "error", "-i", path, "-map", "0:v:0", "-c", "copy",
                          "-f", "hash", "-hash", "sha256", "-"], check=True, capture_output=True, text=True).stdout
    return out.strip().split("=", 1)[1].lower()


def stream_seconds(path):
    out = subprocess.run(["ffprobe", "-v", "error", "-select_streams", "v:0", "-show_entries", "stream=duration",
                          "-of", "csv=p=0", path], check=True, capture_output=True, text=True).stdout
    return float(out.strip())


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("key"); ap.add_argument("video"); ap.add_argument("imu", nargs="?")
    ap.add_argument("--device", required=True); ap.add_argument("--nonce", required=True)
    ap.add_argument("--started", required=True, help="recording start, ISO 8601 with a time zone")
    ap.add_argument("--app", default="HomeTasks/2.3")
    a = ap.parse_args()
    key = load_pem_private_key(open(a.key, "rb").read(), password=None)
    start = datetime.fromisoformat(a.started.replace("Z", "+00:00"))
    end = start + timedelta(seconds=stream_seconds(a.video))
    fmt = lambda t: t.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
    payload = {"device_id": a.device, "video_stream_sha256": video_stream_sha256(a.video),
               "imu_sha256": hashlib.sha256(open(a.imu, "rb").read()).hexdigest() if a.imu else None,
               "started_at": fmt(start), "ended_at": fmt(end), "app": a.app, "nonce": a.nonce}
    doc = {"spec": "capture-attestation-v1", "payload": payload,
           "signature": base64.b64encode(key.sign(canonical_json(payload))).decode()}
    json.dump(doc, sys.stdout, indent=1)


if __name__ == "__main__":
    main()

To make a test key and its devices.json entry:

enroll.py
import base64, json, sys
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from cryptography.hazmat.primitives.serialization import Encoding, NoEncryption, PrivateFormat, PublicFormat

key = Ed25519PrivateKey.generate()
open(sys.argv[1], "wb").write(key.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption()))
public = base64.b64encode(key.public_key().public_bytes(Encoding.Raw, PublicFormat.Raw)).decode()
print(json.dumps({sys.argv[2]: {"public_key": public, "revoked": False}}, indent=1))
Shell
python3 enroll.py device.pem dev-5712 > devices.json
python3 sign_clip.py device.pem clips/s0004.mp4 imu/s0004.csv --device dev-5712 --nonce n-0001 \
  --started 2026-10-01T16:44:30Z > attestations/s0004.attestation.json

The engine's own reference, used by its tests, is truehands.attest.sign(payload, private_key).

On the device#

  • Keep the private key in secure hardware and never export it. A key in app storage can be copied to a computer, and then a signature proves only that someone had the key. Hardware support for Ed25519 differs by platform and OS version (Apple's Secure Enclave, for example, holds P-256 keys only); check yours before you build, and tell us if your app cannot hold an Ed25519 key in hardware.
  • Enroll with key attestation where the platform offers it, so the collection server registers only keys generated on a genuine device in your app.
  • Issue one nonce per upload from your collection server and refuse a nonce used twice. The engine catches a nonce reused within one run; your server sees every upload.
  • Sign right after recording, over the file you upload. Re-encoding the video on the phone after signing changes the stream hash and fails the check.

What it does not prove#

A valid signature proves that an enrolled key signed this video stream and this sensor log, at this length, with this nonce. It does not prove the key stayed in hardware, that the scene was not staged, or that the claimed task was done: the other checks still run on every signed clip.