Skip to main content

Module reasoning

Module reasoning 

Source
Expand description

Reasoned Action Proofs and event-triggered intent recheck.

A standard credential answers who acted and under what authority. It says nothing about why. This module adds the missing “why” layer: before acting, an agent states a structured justification (an intent plus a set of evidence anchors, each a claim tied to a real artifact by that artifact’s hash). The justification is committed by digest, optionally deposited with a neutral escrow that timestamps it, and the executed action credential carries the commitment. Three properties then hold: no fabrication (each reason names an artifact a verifier re-resolves and hashes), no post-hoc rewrite (the credential carries the digest), and, with escrow, committed before execution (the deposit time is not after execution).

This is the canonical port of the Python reference vouch/reasoning.py. The digest algorithm and every stable reason string match byte for byte, so a seal built in one language verifies in another. Everything here is an ordinary eddsa-jcs-2022 Verifiable Credential.

§Intent recheck (event-triggered)

A heartbeat proves the agent is alive across an interval; it does not prove the agent’s intent is current at the moment of a sensitive action. A justification sealed early in an interval still passes for an action executed much later in the same interval, so a sophisticated actor can time a sensitive action to land after a pulse boundary while reusing an intent sealed before it. The intent recheck binds seal freshness to the action: for a sensitive consequence tier the seal must post-date the last pulse boundary and be within a configurable max age, not merely predate execution. See verify_intent_freshness and reseal_intent.

Structs§

FreshnessRequirement
The freshness requirement a consequence tier imposes on an intent seal.
MaxAge
An age limit as a caller wrote it: the limit in nanoseconds the elapsed time is compared with (the floor of the reference’s max_age * 1e9, which compares the same for a whole number of nanoseconds), and its text for the refusal.
PulseWindow
Where an action’s execution time falls relative to the current pulse window [last_pulse, last_pulse + interval).
SignReasonedActionOptions
Options for sign_reasoned_action.

Constants§

ESCROW_RECEIPT_TYPE
JUSTIFICATION_ALGORITHM
REASONED_ACTION_TYPE
REASON_ESCROW_AFTER_EXECUTION
REASON_ESCROW_AGENT_MISMATCH
The receipt names another agent than the credential’s issuer.
REASON_ESCROW_DIGEST_MISMATCH
REASON_ESCROW_INVALID
REASON_EVIDENCE_HASH_MISMATCH
REASON_EVIDENCE_UNRESOLVED
REASON_INTENT_EXECUTION_NOT_CURRENT
Intent recheck: the execution time is not within the verifier’s clock +/- skew (carries :valid_from=<validFrom>).
REASON_INTENT_SEAL_EXPIRED
REASON_INTENT_SEAL_FUTURE
Intent recheck: the witnessed seal is later than the verifier’s clock plus skew (carries :sealed_at=<depositedAt>).
REASON_INTENT_SEAL_MISSING
REASON_INTENT_SEAL_STALE
REASON_INVALID_PROOF
REASON_JUSTIFICATION_DIGEST_MISMATCH
REASON_MALFORMED_TIME
validFrom, sealedAt or depositedAt does not follow the time grammar.
REASON_MISSING_COMMITMENT
REASON_MISSING_ESCROW
REASON_NOT_REASONED_ACTION
REASON_SEAL_AFTER_DEPOSIT
The agent’s own sealedAt is later than the escrow’s depositedAt.
REASON_SEAL_AFTER_EXECUTION
The agent’s own sealedAt is later than the execution time (validFrom).
REASON_SEAL_IN_FUTURE
A seal is later than the verifier’s clock plus skew.
REASON_UNANCHORED_CLAIM
TIER_CRITICAL
TIER_HIGH
TIER_LOW
TIER_MEDIUM
TIER_ROUTINE
Consequence tiers, aligned with PAD-017 commitment levels (0..4) and the trust-entropy stakes bands. Higher tiers demand a fresher seal.
VC_CONTEXT_V2
VOUCH_CONTEXT_V1

Functions§

artifact_digest
Multibase SHA-256 of an evidence artifact (JSON object or string).
artifact_digest_bytes
Multibase SHA-256 of a raw-byte evidence artifact.
build_escrow_receipt
Issue a signed JustificationEscrowReceipt fixing a commitment in time. The escrow sees only the digest, never the plaintext justification.
build_escrow_receipt_with
build_escrow_receipt with the seed optional (without one the receipt comes back unsigned, for a host whose key lives elsewhere to sign) and the proof’s created, the time of signing (None keeps deposited_at).
build_justification
Assemble a justification: the intent plus its evidence anchors. intent must carry at least action and target; at least one anchor is required.
check_reasoned_action
Verify a reasoned-action credential. Returns None on success or a structured reason string on failure. Checks, in order:
check_reasoned_action_at
check_reasoned_action with the verifier’s clock: a sealedAt or a depositedAt later than now_iso plus the skew is refused (seal_in_future). Errors on a malformed now_iso or a skew outside 0..120 seconds (a caller error, not a verdict).
check_seal_freshness
The core intent-recheck rule. Given a seal time, the action’s execution time, the last pulse boundary, and a tier’s freshness requirement, return None if the seal is fresh enough, else a stable reason string.
check_unreadable_reasoned_action
The checks of check_reasoned_action_at; clock is the verifier’s (now, skew) in nanoseconds, or None to skip the clock comparisons. The answer of check_reasoned_action for a credential the host could not hand over as it is (a value with no JSON form): not a reasoned action when its type says so, else invalid_proof, the reference’s answer when it cannot compute the signing input. No signature is checked over the copy.
default_requirement
Reference intent-freshness policy: routine/low/medium tiers inherit the last pulse’s assurance; high and critical tiers require a seal sealed after the last pulse boundary, within a tightening max age. Deployments substitute their own thresholds; these are reference values.
evidence_anchor
Build one evidence anchor: a claim tied to a verifiable artifact. Supply evidence (its hash is computed) OR a precomputed evidence_hash.
justification_digest
Multibase SHA-256 over the JCS-canonical justification.
pulse_window
Classify an action’s execution time against the pulse schedule. last_pulse is the issue time of the most recent heartbeat; interval_seconds is the heartbeat period.
recheck_intent_freshness
The intent recheck a verifier runs at a consequence tier. A tier that requires a fresh seal (high and critical in the reference policy) requires an escrow receipt, because the agent’s own sealedAt is only its word; the seal time is the receipt’s VERIFIED depositedAt. Checks, in order (the first failure is returned):
recheck_intent_freshness_with
recheck_intent_freshness for a host whose receipt had no JSON form (receipt_unreadable): the host sends the credential with those values as null, and the receipt never verifies (escrow_receipt_invalid at its step); its signature is never checked over the changed copy.
reseal_intent
Execution-time reseal helper: seal the intent right now and issue a fresh ReasonedActionCredential whose sealedAt and validFrom are both now, so a sensitive action carries a seal made in the current pulse window. Reuses build_justification and sign_reasoned_action; no new cryptography.
reseal_intent_with
reseal_intent with the seed optional (unsigned without one) and the proof’s created, the time of signing (None keeps now).
seal_timestamp
Read the seal timestamp from a reasoned-action credential: the attached escrow receipt’s depositedAt when there is a receipt (a neutral witness), else the justification’s own sealedAt.
sign_reasoned_action
Issue a ReasonedActionCredential: the action bound to its justification. valid_from is the execution time and also the proof created.
sign_reasoned_action_with
sign_reasoned_action with the seed optional: without one the credential comes back unsigned, for a host whose key lives elsewhere to sign (proof created = valid_from, verificationMethod as given).
verify_escrow_receipt
Verify an escrow receipt’s proof and structure against the escrow’s raw Ed25519 public key. The proof must be bound to the receipt’s issuer (proofPurpose “assertionMethod”, a verificationMethod of the escrow’s DID), the subject must name the agent and carry the committedDigest, and depositedAt must be a protocol time. A proof that carries an @context is refused: an escrow never writes one, and with one the same signed receipt would have a second form with different bytes. Returns (ok, subject).
verify_intent_freshness
Verify intent freshness for a reasoned-action credential at a given tier, without an escrow key or a clock. A tier that requires a fresh seal needs a verified escrow receipt, which this form cannot check, so it refuses (intent_seal_missing:tier=<n> with no receipt, else escrow_receipt_invalid); a tier with no requirement returns None. A verifier calls recheck_intent_freshness.
verify_justification
Check a revealed justification against a verified credential’s commitment: the justification must recompute to the committed digest, and every anchor must resolve (via resolver) to an artifact whose hash matches. Returns (true, None) on success, else (false, Some(reason)).
verify_reasoned_action
Convenience wrapper over check_reasoned_action returning (ok, credentialSubject).