UNPKG

@synet/did

Version:

Secure, minimal, standards-compliant DID library for production environments. Supports did:key and did:web methods with strict validation and cryptographic security.

72 lines (71 loc) 2.09 kB
/** * DID Unit - Minimalistic DID generation unit * Pure Unit Architecture - learns from any unit that can teach key capabilities. * * Design principles: * - Pure Unit Architecture: uses teach/learn pattern only* * - Dynamic capability checking with capableOf() * - Minimal and flexible * * @author Synet Team */ import { Unit, type TeachingContract, type UnitProps } from '@synet/unit'; import { type KeyType } from './create'; /** * Options for creating a DID */ export interface DIDOptions { method?: 'key' | 'web'; domain?: string; path?: string; meta?: Record<string, unknown>; } export interface DIDConfig { publicKeyHex: string; keyType: KeyType | "Ed25519" | "secp256k1" | "X25519"; metadata?: Record<string, unknown>; } export interface DIDProps extends UnitProps { created: Date; metadata: Record<string, unknown>; publicKeyHex: string; keyType: KeyType | "Ed25519" | "secp256k1" | "X25519"; } /** * DID Unit - Minimalistic DID generation using pure Unit Architecture * Learns key capabilities through standard teach/learn pattern */ export declare class DID extends Unit<DIDProps> { private constructor(); /** * Create DID unit with public key and key type */ static create(config: DIDConfig): DID; /** * Generate DID based on options */ generate(options?: DIDOptions): string; /** * Generate did:key from stored public key and key type * Simple, deterministic operation - no learning required */ generateKey(): string; /** * Generate did:web * Uses exceptions for error handling (simple operation pattern) */ generateWeb(domain: string, path?: string): string; /** * Validate if string is valid hex format */ static isHex(str: string): boolean; whoami(): string; capabilities(): string[]; help(): void; teach(): TeachingContract; toJSON(): Record<string, unknown>; get id(): string; get metadata(): Record<string, unknown>; get publicKeyHex(): string; get keyType(): string; }