isValidIdentifier
isValidIdentifier(
input
): [boolean
,string
|null
]
Validates the format and structure of an identifier, checking its prefix and overall validity.
Parameters
• input: 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 overall validity of the identifier, and the second element is a string containing an error message if the identifier is invalid.
Remarks
This function assesses whether the provided input is a valid identifier, conforming to specific format and encoding rules.
It checks if the input starts with any known valid prefixes and, if found, strips the prefix before further validation.
The function then employs checkIdentifier
to perform a comprehensive validation of the identifier.
Example
const input = 'prefix1234Base58EncodedString';const [isValid, error] = isValidIdentifier(input);if (isValid) { console.log('Valid identifier');} else { console.error('Invalid identifier:', error);}
Description
The function first checks if the input begins with any known valid prefixes, such as specific string constants
that might denote the type or category of the identifier. If such a prefix is found, it is removed from the input.
The sanitized input (without the prefix) is then passed to checkIdentifier
for detailed validation, including
base58 decoding and checksum verification. The result of this validation process is returned, indicating whether
the input is a valid identifier and providing details about any detected errors.