trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
80 lines • 2.92 kB
TypeScript
/**
* Identity Module
*
* Ed25519 key pair generation, DID derivation, and local identity storage.
* DESIGN.md §6.1 — Every actor is an Identity entity with a cryptographic key pair.
*
* Private keys are stored locally in `.trellis/identity.json` (never synced).
* Public keys and DIDs are graph entities that get replicated to peers.
*/
export interface IdentityConfig {
displayName: string;
email?: string;
/** Ed25519 public key, base64-encoded. */
publicKey: string;
/** Ed25519 private key, base64-encoded (local only, never synced). */
privateKey: string;
/** did:key identifier derived from public key. */
did: string;
/** Entity ID for use in the EAV store. */
entityId: string;
/** ISO timestamp of creation. */
createdAt: string;
}
export interface PublicIdentity {
displayName: string;
email?: string;
publicKey: string;
did: string;
entityId: string;
createdAt: string;
}
/**
* Generate a new Ed25519 identity.
*/
export declare function createIdentity(opts: {
displayName: string;
email?: string;
}): IdentityConfig;
/**
* Sign a message (typically an op hash) with a private key.
*/
export declare function signMessage(message: string, privateKeyBase64: string): string;
/**
* Verify a signature against a message and public key.
*/
export declare function verifySignature(message: string, signatureBase64: string, publicKeyBase64: string): boolean;
/**
* Save an identity to the local .trellis directory.
*/
export declare function saveIdentity(trellisDir: string, identity: IdentityConfig): void;
/**
* Load the local identity from .trellis/identity.json.
*/
export declare function loadIdentity(trellisDir: string): IdentityConfig | null;
/**
* Check if a local identity exists.
*/
export declare function hasIdentity(trellisDir: string): boolean;
/**
* Extract the public (safe-to-share) portion of an identity.
*/
export declare function toPublicIdentity(identity: IdentityConfig): PublicIdentity;
export declare function personIdentityDir(): string;
export declare function personIdentityPath(): string;
/** Save an identity to the person-scoped ~/.trellis/identity.json. */
export declare function savePersonIdentity(identity: IdentityConfig): void;
/** Load the person-scoped identity (null when unset). */
export declare function loadPersonIdentity(): IdentityConfig | null;
export declare function hasPersonIdentity(): boolean;
/** Load or create the person identity, persisting it on creation. */
export declare function ensurePersonIdentity(opts?: {
displayName?: string;
email?: string;
}): IdentityConfig;
/**
* Resolve the signing identity for a repo: the person key is authoritative
* (ADR 0032 §3); a legacy per-repo key is the fallback.
*/
export declare function resolveRepoIdentity(trellisDir: string): IdentityConfig | null;
//# sourceMappingURL=identity.d.ts.map