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 sign payload

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

Overview

Concrete tool for signing and verifying Ed25519 payloads with canonical serialization provided by the trust-core package.

Description

The trust-core signing module provides three primitives:

  • createKeyPair() — Generates an Ed25519 key pair (PEM-encoded SPKI public key, PKCS8 private key) and computes the SHA-256 fingerprint of the public key.
  • signPayload<T>(privateKey, fingerprint, payload, fields?) — Signs a payload by canonicalizing the signed fields (deep-sorted keys), including metadata (_meta: signedAt, signedFields, publicKeyFingerprint, algorithm), and producing an Ed25519 signature. Returns a SignedEnvelope<T>.
  • verifySignature<T>(publicKey, envelope) — Verifies a SignedEnvelope by reconstructing the canonical bytes and checking the signature against the public key.

The canonicalization ensures byte-identical signing and verification regardless of key insertion order.

Usage

  • Policy enforcement Step 2: Sign evidence payloads (model decisions, human approvals, delegations) before verification.

Code Reference

Source Location

  • Repository: Babysitter
  • File: packages/trust-core/src/signing.ts:L13-65

Signature

function createKeyPair(): IdentityKeyPair;
// IdentityKeyPair: { publicKey: string (PEM), privateKey: string (PEM), fingerprint: string (sha256) }

function signPayload<T>(
  privateKey: string,
  fingerprint: string,
  payload: T,
  fields?: string[]
): SignedEnvelope<T>;
// SignedEnvelope<T>: { payload, signature, publicKeyFingerprint, signedAt, signedFields, algorithm: 'Ed25519' }

function verifySignature<T>(
  publicKey: string,
  envelope: SignedEnvelope<T>
): boolean;

Import

import { createKeyPair, signPayload, verifySignature } from "@a5c-ai/trust-core";

I/O Contract

Inputs

Name Type Required Description
privateKey string Yes Ed25519 PEM private key
fingerprint string Yes SHA-256 of public key
payload T Yes Evidence payload
fields string[] No Signed field names (default: all keys)

Outputs

Name Type Description
SignedEnvelope object { payload, signature, publicKeyFingerprint, signedAt, signedFields, algorithm }

Usage Examples

Sign and Verify a Payload

import { createKeyPair, signPayload, verifySignature } from "@a5c-ai/trust-core";

// 1. Create an identity key pair
const keyPair = createKeyPair();
console.log("Fingerprint:", keyPair.fingerprint);

// 2. Sign a model decision
const decision = {
  payloadType: "model-decision",
  modelId: "claude-sonnet-4",
  provider: "anthropic",
  inputMessagesHash: "sha256:abc123",
  outputContent: "The answer is 42.",
  timestamp: new Date().toISOString(),
  toolCalls: [],
};
const envelope = signPayload(keyPair.privateKey, keyPair.fingerprint, decision);

// 3. Verify the signature
const isValid = verifySignature(keyPair.publicKey, envelope);
console.log("Valid:", isValid); // true

// 4. Tamper detection
envelope.payload.outputContent = "The answer is 43.";
const isStillValid = verifySignature(keyPair.publicKey, envelope);
console.log("Valid after tamper:", isStillValid); // false

Related Pages

Implements Principle

Requires Environment

Page Connections

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