Skip to content

hashToIdentifier

hashToIdentifier(digest, iDPrefix): string

Converts a digest to a unique identifier using a specified identifier prefix.

Parameters

digest: any

The input digest to be encoded, which can be a hex string, Uint8Array, or a regular string.

iDPrefix: number

The identifier prefix, a numerical value used to classify the type of data being encoded.

Returns

string

A string representing the encoded identifier.

Example

const digest = '0x1234...'; // Hex string or Uint8Array or regular string
const identifier = hashToIdentifier(digest, 29);
console.log('Identifier:', identifier);

Throws

Assert error if the digest is invalid.

Source

identifier/src/Identifier.ts:259