import type { AtribRecord } from './types.js'; /** §1.11.1 literal version discriminator. */ export declare const DELEGATION_CERT_TYPE = "atrib/delegation-cert/v1"; /** * key_revocation event type URI (§1.9). Not part of the §1.2.4 normative * event-byte vocabulary (it maps to the extension byte in log entries); * exported here for the §1.11.5 revocation builder and its consumers. */ export declare const EVENT_TYPE_KEY_REVOCATION_URI = "https://atrib.dev/v1/types/key_revocation"; /** `"sha256:" + 64 lowercase hex` — the §1.11.3 field wire format. */ export declare const DELEGATION_CERT_HASH_PATTERN: RegExp; /** * §6.7.1 capability envelope schema, reused VERBATIM as the certificate * scope per §1.11.1. One schema, two carriers: directory-published * (per-key, identity-claim cadence) and certificate-carried (per-run, * issuance cadence). When `expires_at` is present the effective expiry is * `min(not_after, scope.expires_at)`. */ export interface DelegationScope { tool_names?: string[]; event_types?: string[]; max_amount?: { currency: string; value: number; }; counterparties?: string[]; expires_at?: number; cost_policy?: DelegationCostPolicy; } export interface DelegationCostPolicy { model_tiers?: string[]; max_tokens?: number; } /** * A delegation certificate per §1.11.1. JCS lexicographic field order: * cert_type < context_id < not_after < not_before < principal_key < * run_pubkey < scope < signature. Optional fields MUST be omitted, not * null, when absent — presence/absence changes the canonical form and * therefore the signature, mirroring the `session_token` rule (§1.3). */ export interface DelegationCertificate { cert_type: typeof DELEGATION_CERT_TYPE; /** OPTIONAL 32-lowercase-hex session binding. */ context_id?: string; /** Unix ms; records after this are out-of-window. */ not_after: number; /** OPTIONAL Unix ms; defaults to 0 when absent. */ not_before?: number; /** base64url 32-byte Ed25519 principal public key. */ principal_key: string; /** base64url 32-byte Ed25519 run public key. MUST differ from principal_key. */ run_pubkey: string; /** OPTIONAL §6.7.1 capability envelope, verbatim. */ scope?: DelegationScope; /** Ed25519 by principal_key over the JCS signing input (§1.11.2). */ signature: string; } /** An unsigned certificate: all fields except signature. */ export type UnsignedDelegationCertificate = Omit; /** A record carrying the OPTIONAL §1.11.3 genesis field. */ export type DelegatedAtribRecord = AtribRecord & { delegation_cert_hash?: string; }; /** * A §1.9.1 key_revocation record extended with the OPTIONAL §1.11.5 * `delegation_cert_hash` field (JCS order when present: * creator_key < delegation_cert_hash < emergency_signed_by < revoked_key). */ export type RunKeyRevocationRecord = AtribRecord & { revoked_key: string; revocation_reason: 'compromise' | 'retirement'; delegation_cert_hash: string; }; export interface IssueDelegationCertificateOptions { /** base64url 32-byte Ed25519 run public key to certify. */ run_pubkey: string; /** Unix ms expiry (MUST). */ not_after: number; /** OPTIONAL Unix ms validity start; omitted (not null) when absent. */ not_before?: number; /** OPTIONAL 32-lowercase-hex session binding; omitted when absent. */ context_id?: string; /** OPTIONAL §6.7.1 capability envelope, carried verbatim. */ scope?: DelegationScope; } export interface BuildRunKeyRevocationRecordOptions { /** The valid certificate proving the principal–run relationship. */ certificate: DelegationCertificate; /** 32-lowercase-hex context the revocation record is committed under. */ context_id: string; /** §1.11.5: 'compromise' for a burned sandbox, 'retirement' for clean early wind-down. */ revocation_reason: 'compromise' | 'retirement'; /** `sha256:<64-hex>` content_id for the record (§1.2.2). */ content_id: string; /** Defaults to `genesisChainRoot(context_id)`; pass a chain tail to append to an existing chain. */ chain_root?: string; /** Defaults to Date.now(). */ timestamp?: number; } /** * The certificate signing input (§1.11.2): UTF-8 bytes of * JCS(cert with signature field omitted). Mirrors `canonicalSigningInput` * for records; the certificate is not a record, but the byte rule is * deliberately identical so no second canonicalization scheme exists. */ export declare function delegationCertSigningInput(cert: DelegationCertificate | UnsignedDelegationCertificate): Uint8Array; /** Canonical form of a SIGNED certificate (for hashing). */ export declare function canonicalDelegationCert(cert: DelegationCertificate): Uint8Array; /** * cert_hash = "sha256:" + hex(SHA-256(UTF-8(JCS(full signed cert)))) — * over the SIGNED bytes, analogous to record_hash (§1.11.2). The stable * identifier used by the §1.11.3 record field, §1.11.5 revocation, * sidecars, and archive evidence keys. */ export declare function delegationCertHash(cert: DelegationCertificate): string; /** * Validity of a certificate AS DELEGATION EVIDENCE per §1.11.2: both keys * well-formed per §1.4.1, `run_pubkey !== principal_key`, and the * signature verifies under `principal_key`. Returns the error list * (empty = valid). Never throws; malformed input degrades to errors. * * Error identifiers: 'principal_key_malformed', 'run_pubkey_malformed', * 'self_certificate', 'principal_signature_invalid'. An invalid * certificate never invalidates any record (the record falls back to * depth 0); this check exists so producers can validate at startup per * §1.11.10 before stamping or provisioning. */ export declare function delegationCertErrors(cert: DelegationCertificate): Promise; /** * Issue a delegation certificate (§1.11.1 / §1.11.2): the principal seed * signs `{run_pubkey, scope, not_after, context_id?}` over the JCS * signing input. The construction is byte-identical to the * spec/conformance/delegation-certificates/ corpus generator: optional * fields are omitted (never null) so absence changes the canonical form. * * Issuance is an explicit operator/host action off the primary tool-call * path, so invalid input throws (with the `atrib:` prefix). In * particular a self-certificate (`run_pubkey === principal_key`) is * refused at issuance because verifiers MUST reject it as evidence. */ export declare function issueDelegationCertificate(principalSeed: Uint8Array, options: IssueDelegationCertificateOptions): Promise; /** * Stamp `delegation_cert_hash` onto a GENESIS record body (§1.11.3 role 1) * before the existing signing flow (`signRecord` / `handleEmit` / * middleware) signs it. This introduces NO new signing path: the caller * stamps the unsigned body, then signs exactly as before; JCS slots the * field between `creator_key` and `event_type` and its presence changes * the signature, exactly like `session_token` (§1.3). * * Degradation (§5.8 / §1.11.10): this function NEVER throws. Every * failure — non-genesis record, malformed hash, a certificate that does * not cover the record's own creator_key, an expired certificate, an * invalid record shape — is logged with the `atrib:` prefix and the * record is returned UNCHANGED so signing proceeds without the field. * Records remain valid; the verifier simply sees an uncertified run key. * * Pass either the full certificate (preferred; enables the coverage and * expiry checks) or a pre-computed `sha256:<64-hex>` cert hash. */ export declare function withDelegationCertHash(record: T, certificate: DelegationCertificate | string): T & { delegation_cert_hash?: string; }; /** * Build and sign a run-key revocation record per §1.11.5 (§1.9.2 signing * rule 3): a `key_revocation` record retiring `certificate.run_pubkey`, * signed by the PRINCIPAL, carrying `delegation_cert_hash` referencing * the certificate that proves the principal–run relationship. Verifiers * resolve that certificate — valid per §1.11.2, `run_pubkey === * revoked_key`, `principal_key === creator_key` — before accepting the * revoker, so this builder enforces the same preconditions at build time. * * Signing goes through the existing `signRecord` primitive; the extra * fields ride the record body and are covered by the signature via JCS * (canonical order: creator_key < delegation_cert_hash < event_type, * with revoked_key / revocation_reason in their alphabetical slots per * §1.9.1). * * This is an explicit principal-side action off the primary tool-call * path, so invalid input throws (with the `atrib:` prefix). */ export declare function buildRunKeyRevocationRecord(principalSeed: Uint8Array, options: BuildRunKeyRevocationRecordOptions): Promise; //# sourceMappingURL=delegation.d.ts.map