@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.
68 lines (67 loc) • 2.05 kB
TypeScript
/**
* @synet/did - DID utilities
*
* Core utility functions for DID creation, parsing, and validation.
*/
import type { DIDComponents, DIDParseResult, DIDValidationResult } from "./types";
/**
* Parse a DID URL into its components
*
* @param did - The DID URL to parse
* @returns DID parsing result with components and validation status
*/
export declare function parseDID(did: string): DIDParseResult;
/**
* Validate a DID URL
*
* @param did - The DID URL to validate
* @returns Validation result with error messages and warnings
*/
export declare function validateDID(did: string): DIDValidationResult;
/**
* Create a DID URL from components
*
* @param components - DID components
* @returns Complete DID URL
*/
export declare function createDIDURL(components: DIDComponents): string;
/**
* Check if a string is a valid DID
*
* @param did - String to check
* @returns True if valid DID
*/
export declare function isDID(did: string): boolean;
/**
* Extract the method from a DID
*
* @param did - DID URL
* @returns DID method or null if invalid
*/
export declare function extractMethod(did: string): string | null;
/**
* Extract the identifier from a DID
*
* @param did - DID URL
* @returns DID identifier or null if invalid
*/
export declare function extractIdentifier(did: string): string | null;
/**
* Normalize a DID by removing extra whitespace and ensuring consistent format
*
* @param did - DID URL to normalize
* @returns Normalized DID URL
*/
export declare function normalizeDID(did: string): string;
/**
* Generate a CUID2-like identifier using Node.js crypto
*
* This is a simplified, zero-dependency implementation of CUID2 concepts:
* - Uses native Node.js crypto instead of @noble/hashes
* - Maintains similar structure: letter + hash of (time + entropy + counter)
* - Provides collision-resistant, sortable, URL-safe IDs
*
* @param length - Length of the generated ID (default: 24)
* @returns A CUID2-like identifier string
*/
export declare function createId(length?: number): string;