Skip to content

checkIdentifier

checkIdentifier(identifier): [boolean, string | null]

Validates an identifier by decoding and checking its integrity.

Parameters

identifier: any

The identifier to be validated, provided as a HexString or a regular string.

Returns

[boolean, string | null]

A tuple where the first element is a boolean indicating the validity of the identifier, and the second element is a string containing an error message if the identifier is invalid.

Remarks

This function takes an identifier, typically encoded in base58 format, and performs a series of checks to validate it. These checks include decoding the identifier, verifying its checksum, length, and prefix against predefined standards.

Example

const identifier = 'base58EncodedIdentifier';
const [isValid, error] = checkIdentifier(identifier);
if (isValid) {
console.log('Identifier is valid');
} else {
console.error('Invalid identifier:', error);
}

Description

The function attempts to decode the given identifier from its base58 format. If the decoding fails, it returns false along with the error message. It then checks the identifier’s checksum, length, and prefix. If these checks pass, the function confirms the identifier’s validity. Otherwise, it returns false with an appropriate error message describing the failure reason.

Source

identifier/src/Identifier.ts:350