@arcblock/did
Version:
Javascript lib to work with ArcBlock DID
39 lines (37 loc) • 1.19 kB
JavaScript
import { extractIdentifier } from "./parse.mjs";
//#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 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 = extractIdentifier(a);
const idB = extractIdentifier(b);
if (!idA || !idB) return false;
return idA.toLowerCase() === idB.toLowerCase();
}
//#endregion
export { getEntityId, isSameEntity };