trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
54 lines • 2.45 kB
TypeScript
/**
* Signing Middleware
*
* DESIGN.md §6.2 — Every op can be cryptographically signed by its author.
*
* This module provides:
* - `signOp`: Sign a VcsOp with a local identity's private key.
* - `verifyOp`: Verify the signature on a VcsOp.
* - `SignatureVerificationMiddleware`: Middleware that rejects ops with
* invalid signatures on remote ops.
*/
import type { VcsOp } from '../vcs/types.js';
/**
* Sign a VcsOp in-place using the given private key.
* Sets `vcs.signature`, `vcs.signedBy`, and optionally `vcs.signedWith` (ADR 0020).
*
* The signature is computed over the body with the signature fields excluded
* (`hashVcsOpBody`), then stamped, and `op.hash` is recomputed to *include* the
* signature so a signed op still passes `verifyVcsOpHash` (signing is not an
* out-of-band annotation). `verifyOp`/`verifyOpBatch` reconstruct the same
* body hash to check the signature.
*/
export declare function signOp(op: VcsOp, privateKeyBase64: string, identityEntityId: string, signedWith?: string): Promise<VcsOp>;
/**
* Verify the signature on a VcsOp.
* Returns true if the op has a valid signature, false if invalid.
* Returns null if the op has no signature (unsigned).
*/
export declare function verifyOp(op: VcsOp, publicKeyBase64: string): Promise<boolean | null>;
/**
* Reconstruct the canonical body hash a signature was computed over: the op
* with its signature fields stripped (see `hashVcsOpBody`).
*/
export declare function opBodyHash(op: VcsOp): Promise<string>;
export interface IdentityResolver {
/** Resolve an identity entity ID to its root/bootstrap public key (base64). */
resolvePublicKey(entityId: string): string | null;
/** ADR 0020 — resolve a specific device key under an identity. */
resolveDevicePublicKey?(identityEntityId: string, deviceId: string): string | null;
/** ADR 0020 — all authorized keys (root + devices) for try-all legacy verify. */
resolvePublicKeys?(identityEntityId: string): string[];
}
export interface SignatureVerificationResult {
valid: boolean;
op: VcsOp;
reason?: string;
}
/**
* Verify all signatures on a batch of ops.
* Returns results for ops that have signatures.
* Supports ADR 0020 device keys via signedWith + resolveDevicePublicKey.
*/
export declare function verifyOpBatch(ops: VcsOp[], resolver: IdentityResolver): Promise<SignatureVerificationResult[]>;
//# sourceMappingURL=signing-middleware.d.ts.map