UNPKG

@arcblock/did

Version:

Javascript lib to work with ArcBlock DID

40 lines (38 loc) 1.26 kB
const require_parse = require('./parse.cjs'); //#region src/entity.ts /** * Cross-Method Entity Association * * Functions for comparing DID identity across different methods. * Two DIDs with different methods but the same identifier represent the same entity. */ /** * Get the entity identifier from a DID (strips method prefix). * This is the canonical identity across methods. * * @param did - A full DID or bare address * @returns The entity identifier */ function getEntityId(did) { return require_parse.extractIdentifier(did); } /** * Check if two DIDs represent the same entity. * Compares the identifier portion (case-insensitive), ignoring the method prefix. * * For did:name DIDs, performs exact string comparison (names are case-insensitive). * * @param a - First DID or address * @param b - Second DID or address * @returns true if both DIDs refer to the same entity */ function isSameEntity(a, b) { if (typeof a !== "string" || typeof b !== "string" || !a || !b) return false; const idA = require_parse.extractIdentifier(a); const idB = require_parse.extractIdentifier(b); if (!idA || !idB) return false; return idA.toLowerCase() === idB.toLowerCase(); } //#endregion exports.getEntityId = getEntityId; exports.isSameEntity = isSameEntity;