UNPKG

@arcblock/did

Version:

Javascript lib to work with ArcBlock DID

62 lines 1.75 kB
//#region src/name.d.ts /** * DID Name Hierarchy Parser * * DNS-style right-to-left name resolution for did:name identifiers. * Supports global names, delegated sub-names, and .local domains. */ /** Parsed name hierarchy */ interface NameHierarchy { /** Name segments split by '.' */ segments: string[]; /** Top-level domain (rightmost segment) */ tld: string; /** Whether this is a .local name */ isLocal: boolean; /** Whether this is a global name (single segment, not .local) */ isGlobal: boolean; /** Number of segments */ depth: number; } /** Resolve route types */ type ResolveRoute = { type: 'global'; name: string; } | { type: 'local'; name: string; } | { type: 'delegated'; tld: string; subName: string; }; /** * Parse a name identifier into its hierarchy components. * * @param name - The name to parse (e.g. 'robertmao', 'bob.myorg', 'anything.local') * @returns Parsed hierarchy * @throws If name is invalid */ declare function parseNameHierarchy(name: unknown): NameHierarchy; /** * Determine the resolve route for a name. * * - Single segment (e.g. 'robertmao') → global route * - Ends with '.local' → local route * - Multi-segment (e.g. 'bob.myorg') → delegated route * * @param name - The name to route * @returns The resolve route * @throws If name is invalid */ declare function getResolveRoute(name: string): ResolveRoute; /** * Check if a name is a .local name. */ declare function isLocalName(name: string): boolean; /** * Check if a name is a global name (single segment, not .local). */ declare function isGlobalName(name: string): boolean; //#endregion export { NameHierarchy, ResolveRoute, getResolveRoute, isGlobalName, isLocalName, parseNameHierarchy };