UNPKG

@synet/keys

Version:

Zero-dependency, secure key generation library. Supports ed25519, x25519, secp256k1, RSA, and WireGuard keys.

71 lines (70 loc) 2.13 kB
/** * Key Unit - Public-facing cryptographic key unit * [🔑] Clean unit that holds public key material and can learn signing capabilities * * Design principles: * - Key is the public-facing unit (holds public key only) * - Can learn signing capabilities from Signer units via teach/learn pattern * - Simple getters for public properties (no complex methods) * - Full Unit architecture with execute, learn, teach, capabilities * * @author Synet Team */ import { Unit, type TeachingContract, type UnitProps } from '@synet/unit'; import type { KeyType } from './keys'; /** * Configuration for creating a Key unit */ export interface KeyConfig { publicKeyPEM: string; keyType: KeyType; meta?: Record<string, unknown>; } /** * Props interface for Key unit - follows Unit Architecture Doctrine */ export interface KeyProps extends UnitProps { publicKeyPEM: string; keyType: KeyType; keyId: string; meta: Record<string, unknown>; } export declare class Key extends Unit<KeyProps> { protected constructor(props: KeyProps); get publicKeyPEM(): string; get keyType(): KeyType; get keyId(): string; get meta(): Record<string, unknown>; /** * Create Key unit from config */ static create(config: KeyConfig): Key; private static isValidPublicKey; whoami(): string; capabilities(): string[]; help(): void; teach(): TeachingContract; /** * Verify signature using public key * Must learn verification capability from Signer to use this method */ verify(data: string, signature: string): Promise<boolean>; /** * Sign data - uses learned signing capability if available */ sign(data: string): Promise<string>; /** * Check if this key can sign * Returns true if signing capabilities have been learned */ canSign(): boolean; /** * Get public key (compatibility method) */ getPublicKey(): string; toJSON(): Record<string, unknown>; /** * Override learn method to handle Signer teachings */ learn(teachings: TeachingContract[]): Promise<boolean>; }