/** * Cryptographic signing for .bug artifacts (Phase 2.2). * * Uses Ed25519 (RFC 8032) — fast, deterministic, 64-byte signatures, * 32-byte keys, native to Node's built-in crypto (no external deps). * * Threat model: detect tampering of a shared .bug artifact. We sign the * canonical SHA-256 of the artifact's logical state (manifest + failure * fingerprint + per-file checksums) so that any change to source files, * captured output, or metadata invalidates the signature. * * Out of scope: identity/PKI. Trust is established by the recipient * comparing the embedded public key against a known one (or via gist * pinning, key servers, etc.). */ import type { ArtifactManifest } from '../types/artifact.js'; import type { FailureRecord } from '../types/failure.js'; import type { FileEntry } from '../capture/packager.js'; export declare const SIGNATURE_FILE = "signature.json"; export declare const KEY_DIR: string; export declare const DEFAULT_KEY_NAME = "default"; export interface SignatureRecord { /** Always 'ed25519' for now — bump when we add new schemes */ algorithm: 'ed25519'; /** Schema version of this record */ version: 1; /** Hex-encoded SPKI DER public key (32 bytes raw, plus DER wrapper) */ public_key: string; /** Hex SHA-256 hash of the canonical signed payload */ payload_hash: string; /** Hex Ed25519 signature (128 hex chars / 64 bytes) */ signature: string; /** ISO timestamp of when the signature was created */ signed_at: string; /** Optional human-readable signer identity (e.g. email, gist URL) */ signer?: string; } export interface KeyPair { /** Hex-encoded SPKI DER public key */ publicKey: string; /** Hex-encoded PKCS8 DER private key — keep secret */ privateKey: string; } /** * Generate a new Ed25519 keypair encoded as hex DER. */ export declare function generateKeyPair(): KeyPair; /** * Save a keypair to disk with permissive-but-correct permissions. * * Stores: * ~/.bugproof/keys/.pub (public key, hex DER) * ~/.bugproof/keys/.key (private key, hex DER, mode 0600) */ export declare function saveKeyPair(name: string, keyPair: KeyPair): { pubPath: string; privPath: string; }; /** * Load a keypair previously saved with saveKeyPair. */ export declare function loadKeyPair(name?: string): KeyPair; /** * Resolve a private key from a path that may point to either a `.key` file * or the bare name of a key under `~/.bugproof/keys/`. */ export declare function resolvePrivateKey(keyArg: string): KeyPair; /** * Build the canonical payload that gets signed. * * The payload is a JSON-serialized object with sorted keys, covering every * security-relevant field. Any change to the manifest, failure fingerprint, * or per-file checksum will invalidate the signature. * * IMPORTANT: file ordering is by path (alphabetical), so the same logical * artifact produces the same signed bytes regardless of FS enumeration order. */ export declare function buildSignedPayload(opts: { manifest: ArtifactManifest; failure: FailureRecord; fileEntries: FileEntry[]; }): { payload: string; payloadHash: string; }; /** * Sign a canonical payload with an Ed25519 private key. */ export declare function signPayload(payload: string, keyPair: KeyPair, signer?: string): SignatureRecord; export interface VerifyResult { valid: boolean; reason?: string; signature?: SignatureRecord; expectedHash?: string; actualHash?: string; } /** * Verify a signature against a freshly-recomputed payload. * * Returns { valid: true } only if: * 1. signature record is well-formed, * 2. payload hash in record matches the recomputed hash, * 3. signature verifies against the embedded public key. */ export declare function verifySignature(signature: SignatureRecord, payload: string): VerifyResult; /** * Short fingerprint of a public key (first 16 hex chars of SHA-256). * Useful for compact display. */ export declare function publicKeyFingerprint(publicKeyHex: string): string; //# sourceMappingURL=signing.d.ts.map