UNPKG

@arcblock/did

Version:

Javascript lib to work with ArcBlock DID

50 lines (48 loc) 1.64 kB
import { DIDMethod } from "./method.cjs"; //#region src/parse.d.ts /** Parsed DID structure */ interface ParsedDID { /** The method component (e.g. 'abt', 'afs', 'name') */ method: DIDMethod; /** The identifier component (everything after did:{method}:) */ identifier: string; /** The full DID string */ full: string; } /** * Parse a full DID string into its components. * * @param did - Full DID string (e.g. 'did:abt:z1abc...') * @returns Parsed DID object * @throws If the input is not a valid DID string */ declare function parse(did: unknown): ParsedDID; /** * Format an identifier and method into a full DID string. * * Handles idempotency: if the identifier already has a `did:{method}:` prefix * matching the target method, returns it as-is. * * @param identifier - The identifier (address or name) * @param method - The DID method (default: 'abt') * @returns Full DID string * @throws If the method is unknown or identifier is empty */ declare function formatDid(identifier: string, method?: DIDMethod): string; /** * Extract the method from a DID string. * * @param did - A DID string or bare address * @returns The method string, or null if no prefix found */ declare function extractMethod(did: unknown): DIDMethod | null; /** * Extract the identifier from a DID string, stripping the `did:{method}:` prefix. * If the input has no prefix, returns it as-is. * * @param did - A DID string or bare address * @returns The identifier portion */ declare function extractIdentifier(did: unknown): string; //#endregion export { ParsedDID, extractIdentifier, extractMethod, formatDid, parse };