Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A5c ai Babysitter verify envelope trusted

From Leeroopedia
Knowledge Sources
Domains Cryptography, Trust_Chain, Policy_Enforcement
Last Updated 2026-10-23 00:00 GMT

Overview

Concrete tool for verifying signed envelopes against a trusted key store with kind binding, field completeness, and fail-closed semantics.

Description

The policy adapter's verify-envelope-trusted.ts provides three verification entry points:

  • verifyEnvelopeTrusted(envelope, requiredKind, store, allowedFingerprints?) — The ONLY sanctioned entry to the raw verifySignature at a trust boundary. Checks: fingerprint binding to trusted store, kind match, signedFields completeness, payloadType domain separation, revocation/expiry, and signature validity. Every failure returns { valid: false } — fail closed, no fallbacks.
  • verifyCommandAuthorization(envelope, ctx) — Verifies a CommandAuthorization envelope at an execution gate. Checks all 10+ conditions: trusted-store signature, temporal bounds, toolName/toolCallId match, commandHash/argsHash match (TOCTOU), credentialScope, policyDocHash, configEpoch, and evidence step coverage.
  • verifyTrustChainTrusted(chain, store) — Verifies a delegation trust chain with per-link trusted-store resolution, kind enforcement, and delegation linkage (A→B→C with parentSignature binding). Prevents reordering and splicing attacks.

Usage

  • Policy enforcement Step 3: Verify signed evidence against the trusted store.
  • Policy enforcement Step 5: Verify command authorization at the execution gate.

Code Reference

Source Location

  • Repository: Babysitter
  • File: packages/adapters/policy/src/verify-envelope-trusted.ts:L318-329 (verifyEnvelopeTrusted), L355-421 (verifyCommandAuthorization), L500-583 (verifyTrustChainTrusted)

Signature

function verifyEnvelopeTrusted<T>(
  envelope: SignedEnvelope<T>,
  requiredKind: EvidenceKind,
  store: TrustStore,
  allowedFingerprints?: string[]
): TrustedVerification;
// TrustedVerification: { valid: boolean, reason?: string, resolvedKind?, fingerprint? }

function verifyCommandAuthorization(
  envelope: SignedEnvelope<CommandAuthorizationPayload>,
  ctx: CommandAuthorizationGateContext
): CommandAuthorizationVerification;
// CommandAuthorizationVerification: { valid: boolean, reason?: string }

function verifyTrustChainTrusted(
  chain: TrustedChainStep[],
  store: TrustStore
): ChainVerification;
// ChainVerification: { valid: boolean, reason?: string, brokenAt?: number }

Import

import {
  verifyEnvelopeTrusted,
  verifyCommandAuthorization,
  verifyTrustChainTrusted,
} from "@a5c-ai/policy-adapter";

I/O Contract

Inputs

Name Type Required Description
envelope SignedEnvelope<T> Yes Signed evidence
requiredKind EvidenceKind Yes Expected kind (human-approval, model-decision, delegation, etc.)
store TrustStore Yes Trusted key store with trust roots
allowedFingerprints string[] No Permitted key fingerprints
ctx CommandAuthorizationGateContext Yes (CA) Gate context with now, toolName, hashes, epoch

Outputs

Name Type Description
TrustedVerification object { valid, reason?, resolvedKind?, fingerprint? }
CommandAuthorizationVerification object { valid, reason? }
ChainVerification object { valid, reason?, brokenAt? }

Usage Examples

Verify Evidence Envelope

import { verifyEnvelopeTrusted } from "@a5c-ai/policy-adapter";

const store = {
  trustRoots: [
    { fingerprint: "abc123...", kind: "engine", publicKey: "-----BEGIN PUBLIC KEY-----...", label: "proxy-key" },
  ],
};

const result = verifyEnvelopeTrusted(
  signedEnvelope,
  "model-decision",
  store,
  ["abc123..."]
);

if (!result.valid) {
  console.error("Evidence rejected:", result.reason);
  // Fail closed — deny the operation
}

Verify Command Authorization

import { verifyCommandAuthorization } from "@a5c-ai/policy-adapter";

const result = verifyCommandAuthorization(authEnvelope, {
  now: Date.now(),
  toolName: "shell-exec",
  toolCallId: "call-1",
  commandHash: commandHash(["git", "push"]),
  argsHash: argsHash({ repo: "origin" }),
  credentialScope: "write",
  policyDocHash: "sha256:def456",
  currentConfigEpoch: 42,
  minEpochFloor: 40,
  issuerRoots: store.trustRoots,
  requiredStepCount: 2,
});

if (result.valid) {
  // Execute the tool
} else {
  console.error("Authorization denied:", result.reason);
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristics

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment