Skip to main content

ainra — Python verifier (independent implementation #4)

A verify-only, offline, fail-closed, zero-telemetry Python implementation of the AINRA agent-passport verifier. It is written independently from the AINRA specification (docs/AINRA_I_The_Standard.md, docs/AINRA_Master_Technical_Specification_v1.md) and the CC0 conformance vectors — not transliterated from the Rust core or the TypeScript SDK. It joins the conformance differential (make diff) beside them: core ↔ sdk ↔ py, agreeing byte-for-byte on every vector's verdict and reason. The Node reference CLI is held to them on canonical encoding only.

Why a fourth brain? If an independent reimplementation, built to the same spec + vector reference, reaches the same verdict on every vector, that is independent confirmation the standard is unambiguous and the reference is correct. If it disagreed, we would have found something. It agrees on every passport, delta and directory vector in the corpus.

Install

pip install ainra                  # from PyPI
pip install -e packages/sdk-py     # or editable, from a checkout

Published to PyPI by trusted publishing — no API token is involved at any point. Each release carries PEP 740 attestations binding the artifact to the GitHub Actions workflow that built it, so you can check where it came from before you trust it.

Requires Python ≥ 3.10 and cryptography ≥ 48, which ships Ed25519 and ML-DSA-65. The floor is measured: 46 has no ML-DSA module, and 47's wheels refuse ML-DSA-65. SLH-DSA-SHA2-128s, SHA-256, and zlib need no extra dependency (see below).

Quickstart

import json
from ainra import Verifier

S = "kits/verifier/sample-artifacts/"
load = lambda f: json.load(open(S + f))
directory, roots, now = load("directory.json"), load("roots.json"), load("meta.json")["now"]

# 1) Build a verifier from a directory that verifies against both ceremony roots (None if it does not).
verifier = Verifier.from_directory(directory, roots["root_ed25519"], roots["root_slh"])

# 2) Verify a bundle. The caller supplies `now`; there is no I/O.
verdict = verifier.verify(load("bundle-valid.json"), now)
print("valid :", verdict.valid, "| reason:", verdict.reason)
print("event :", json.dumps(verdict.event()))

# 3) A revoked lineage fails closed with a named reason.
rv = verifier.verify(load("bundle-revoked.json"), now)
print("revoked ->", rv.valid, "| reason:", rv.reason)

# 4) The verifier owns the clock and the status. An hour later the same bundle is stale; and a status list the
#    registrar did not sign is no status, so a revoked passport cannot bring its own all-clear.
print("an hour later ->", verifier.verify(load("bundle-valid.json"), now + 3600).reason)
forged = dict(load("bundle-revoked.json"), status_list=load("bundle-valid.json")["status_list"], status_issued_at=now)
print("forged status ->", verifier.verify(forged, now).reason)

Real output (run from the repo root):

valid : True | reason: None
event : {"status": "valid", "reason": null, "name": "ainra:registrar-07:acme:invoicing@1.0.0", "number": "did:ainra:registrar-07:acme:invoicing", "tier": "L3", "freshness_age_s": 1}
revoked -> False | reason: revoked
an hour later -> stale_status
forged status -> stale_status

The verdict event is the M16 shape every AINRA surface emits (docs/PRESENTATION.md): status, reason, name, number (the permanent version-less AINRA Number), tier, freshness_age_s.

ASGI middleware — gate a route, fail closed

Framework-agnostic (Starlette, FastAPI, Quart, any ASGI app). Every gated request must carry a valid passport or it is denied 403 + x-ainra-reason; on allow, the response carries the verdict event in x-ainra-verdict.

from ainra import Verifier, ainra_gate

verifier = Verifier.from_directory(directory, root_ed25519, root_slh)  # None if not authentic
app.add_middleware(ainra_gate(verifier))   # or: AinraGate(app, verifier)

The bundle is read from the x-ainra-passport header (base64url of canonical JSON, or raw JSON for local testing), falling back to the JSON body field ainra_passport. Verification never needs the body, so the header form is streaming-safe.

What it verifies

The frozen nine-step verify, then step 10 when a running copy's credential is presented, first-failure-wins, mapping to the frozen reasons in docs/reasons.json in the repository (all but denied_by_policy, which only a gate with its own policy returns; make reasons-check fails the build if that list and this package's ainra.reasons.ALL ever differ): AINRA name grammar; canonical JSON (sorted keys, no spaces, rejecting floats / non-ASCII keys / integers beyond 2⁵³); the strict base64url decode gateway (D-029 — every external decode is a canonical round-trip, fail closed); hybrid Ed25519 + ML-DSA-65 (both signatures or alg_downgrade/sig_invalid); the exact validity window (nbf inclusive, exp exclusive — no skew, no grace); scope-ceiling and delegation narrowing; revocation-status freshness classes (F1 ≤ 30 s · F2 ≤ 5 min · F3 ≤ 24 h, fail closed); logged-before-valid RFC 6962 inclusion to a signed checkpoint (root SLH-DSA-SHA2-128s or a scope-limited, in-window, unrevoked delegate); the signed status delta / fresh-head classes; and the dual-root-signed directory. Fail closed everywhere; .verify never raises.

Never go back to an older directory

Both ceremony roots signed every old directory too, so a signature check alone cannot refuse a replayed one. If you refresh the directory, keep a DirectoryHolder: it remembers the highest epoch it accepted and refuses anything older (refusal: "rollback"), and a forged directory claiming a higher epoch is refused as unauthentic without raising the floor.

from ainra.directory import DirectoryHolder
holder = DirectoryHolder(root_ed25519, root_slh, min_epoch=saved_floor)
v = holder.verifier(fetched_directory)   # a Verifier, or {"ok": False, "refusal": ...}
save_floor(holder.floor)                 # persisting it across restarts is yours to do

Currency mode — a revoked snapshot stops working once you have seen the revocation

A status list is a signed snapshot, so by default a genuine pre-revocation one keeps verifying until it is older than your freshness class. Verifier.from_directory(..., currency=True) requires the registrar's fresh head on every bundle, F1-fresh and bound to the exact list presented, and refuses a head older than one it has already seen — the same rule as @ainra/sdk and the edge gate, held to vectors/v1-currency. Keep one verifier per process: the memory is the point. A verifier that never sees a newer head cannot know one exists; F1 (30 s) still bounds that.

Cryptography — shared primitives, independent logic (state precisely, D-041)

The verification logic is independent; the cryptographic primitives are shared, audited libraries — reimplementing a signature scheme would be less safe, not more independent:

Primitive Sizes (confirmed) Source
Ed25519 32 B key / 64 B sig cryptography (pyca, wraps OpenSSL 3.5+)
ML-DSA-65 (FIPS 204) 1952 B key / 3309 B sig cryptography (pyca / OpenSSL 3.5+)
SLH-DSA-SHA2-128s (FIPS 205) 32 B key / 7856 B sig OpenSSL libcrypto via ctypes (EVP raw-public-key verify) — that primitive only
SHA-256 (RFC 6962 prefixes) — Python stdlib hashlib

The claim, precisely: shared cryptographic primitives (pyca cryptography / OpenSSL 3.5+ for Ed25519 + ML-DSA-65; OpenSSL libcrypto via ctypes for SLH-DSA-SHA2-128s; stdlib for SHA-256), with an independent verification logic — the differential exercises the logic, not the primitives. cryptography 49 does not yet surface SLH-DSA, so it is reached from the same underlying OpenSSL directly; if the OpenSSL SLH-DSA verify path is unavailable, that primitive fails closed (returns False).

Differential — the fourth column

make diff (or node tools/diff-harness/run.mjs) runs the Python verifier over the whole corpus and asserts it agrees with the Rust core's recorded verdict on every vector, including the alg-downgrade-*, noncanon-*, boundary-*, renewal-* classes, plus delta and directory:

(A) verdict diff  core↔sdk : 1153/1153 agree
(B) canon 3-way  core↔sdk↔P0 : 10/10 byte-identical
(C) canon reject core↔sdk : 4/4 both refuse
(D) delta diff   core↔sdk : 17/17 agree
(E) directory diff core↔sdk : 9/9 agree
(F) verdict diff  core↔py : 1153/1153 agree
(F) delta diff   core↔py : 17/17 agree
(F) directory diff core↔py : 9/9 agree

DIFF OK: all implementations agree (core ↔ sdk ↔ P0 ↔ py)

Replaying the test vectors is a different import

ainra.conformance holds the corpus runners (run_vector, run_gate_vector, run_link_vector, …). run_vector believes a vector's own clock, class and status list, so it must never decide trust: use Verifier for that (D-075). Since 0.7.0 the package root no longer exports the fixture-semantics verify (0.6.0 kept it, for compatibility).

Tests

cd packages/sdk-py && PYTHONPATH=. python3 -m unittest discover -s tests

Covers the whole-corpus agreement (every frozen reason reached: the verifier's by the passport corpus, the gate's denied_by_policy by the gate corpus), the ~5-line Verifier surface (valid / revoked / verifier-owns-the-clock), the ASGI gate (allow on VALID, deny 403 fail-closed on missing/revoked), and the strict base64url / canonical-JSON gateways. Zero telemetry, no network.

License

Apache-2.0 OR MIT (dual). The conformance vectors are CC0 (vectors/LICENSE).

Build it the documented way

v = Verifier.from_directory(directory, roots["root_ed25519"], roots["root_slh"],
                            audience="https://api.example", freshness="F2")

from_directory authenticates the directory against both ceremony roots and carries the registrar's status key, its status URI, and any graduated-distrust cutoff into the verifier — so revocations are authenticated (D-020) and a distrusted registrar is refused (D-044).

The plain Verifier(anchors, …) constructor is for anchors you pin yourself. Since 0.5.0 it fails closed (D-075): give each registrar's anchor its status_ed25519, status_mldsa65 and status_uri and revocations are authenticated as above; leave them out and every passport is stale_status. Through 0.4.x it silently believed the bundle's status list in that case. To replay a conformance vector, whose status is an unsigned input by design, say so: Verifier(vec["anchors"], unauthenticated_status=True) — never for anything that decides access.

Verify a running copy (ADR-019)

Same call; supply your audience when you build the verifier:

v = Verifier.from_directory(directory, roots["root_ed25519"], roots["root_slh"],
                            audience="https://api.example")   # never taken from the bundle
v.verify(bundle, now)     # the instance layer is checked automatically when present

The default empty audience is fail-closed — a service that has not said who it is accepts no instance credential.

Minting lives on the operator's side and takes a signing callback, so no key material enters this package: mint_instance_credential, prove_instance_possession (see "Be the agent" below).

Signed requests and send-once (D-062, D-065)

AinraGate matches @ainra/middleware. Every option is off by default, so existing integrations behave as before:

from ainra import AinraGate, PresentationStore
app = AinraGate(app, verifier, require_signature=True, seen_nonce=cache.seen, store=PresentationStore())
  • require_signature=True: the request must be signed by the running copy's instance key (RFC 9421). Otherwise it is refused as presentation_unsigned, presentation_sig_invalid, presentation_stale or presentation_replayed.
  • store=: a running copy POSTs its bundle once to /.well-known/ainra-presentation (201 {"ref"}) and names it by digest after that. A digest the gate doesn't hold is 428 presentation_unknown.
  • The request-signature profile is the one ainra-core generates vectors/v1-presentation from, and this package agrees with it on every vector (make diff).

Be the agent (D-071)

An agent written in Python can make the whole journey with this package. Keys stay with you: every function that signs takes a callback, bytes -> {"ed25519": <b64url>, "mldsa65": <b64url>}.

from ainra import mint_instance_credential, prove_instance_possession, sign_presentation, presentation_ref

# where the passport key lives (never in the container): a credential for one running copy
ic = mint_instance_credential(passport_claims_b64=bundle["claims"], instance_public=instance_public,
                              capabilities=["read:invoices"], audience="https://api.example",
                              now=now, iid="i-0f3a2b71", control_sign=passport_key_sign)

# inside the running copy: send the bundle once, then sign each request
pop = prove_instance_possession(audience="https://api.example", credential=ic, nonce=fresh(), now=now,
                                instance_sign=instance_key_sign)
full = {**bundle, "instance": {**ic, "pop": pop}}        # POST once to /.well-known/ainra-presentation
headers = [("x-ainra-passport", presentation_ref(full)), ("x-ainra-pop", b64url_json(pop))]
headers += sign_presentation(method="POST", authority="api.example", path="/orders", headers=headers, body=body,
                             keyid=ic["iid"], nonce=fresh(), created=now, instance_sign=instance_key_sign)
  • sign_presentation returns the headers to set: content-digest when there is a body, signature-input, signature. It appends to another signer's fields (a signature agent's, D-070) and never overwrites them.
  • A runnable agent, start to finish: examples/agent.py. make python-agent-e2e runs it against the Node gate and the edge gate on the live network.
  • make sign-diff holds this signer to the other implementations: what it signs, ainra-core and @ainra/sdk accept.

Metadata

Release files for ainra 0.8.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ainra 0.8.1
File Size Uploaded Provenance Actions
ainra-0.8.1.tar.gz 79.5 kB With provenance Details for ainra-0.8.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ainra 0.8.1
File Interpreter ABI Platform Actions
ainra-0.8.1-py3-none-any.whl Python 3 none any Details for ainra-0.8.1-py3-none-any.whl

Total release size: 146.6 kB

Release files / ainra-0.8.1.tar.gz

Download URL ainra-0.8.1.tar.gz
Size 79.5 kB
Tags Source
SHA-256 checksum
How to use checksums
947972028b5b031870a773f0586fdfab87f5faa3dbe10990ab113f0c94d4ce4f
BLAKE2b-256 checksum
How to use checksums
5348d9e99eb0b1c41c845518aac03e9007f1f5759252b0925da3655815db1cdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / ainra-0.8.1-py3-none-any.whl

Download URL ainra-0.8.1-py3-none-any.whl
Size 67.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2e1e0b7ec487232cd87f0af3db6b1b5d7aaef7a7a101eab7d2beb197d32153dc
BLAKE2b-256 checksum
How to use checksums
87e64389c13c5a9732c0f8512516ce39ec2c3d5e7d821bdf6ebd1f3851ed9179
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for ainra 0.8.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ainra-0.8.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page