Skip to content

uriToStatementIdAndDigest

uriToStatementIdAndDigest(statementUri): object

Extracts the statement identifier and digest from a given statement URI.

statementUri: `stmt:cord:${string}`

The statement URI to be parsed. Expected format: ‘stmt:cord::‘.

object

An object containing the extracted identifier and digest from the statement URI.

digest: StatementDigest

identifier: string

This function parses a statement URI and separates it into its constituent identifier and digest components. It expects the URI to conform to a specific format and structure.

const statementUri = 'stmt:cord:1234:abcd';
const { identifier, digest } = uriToStatementIdAndDigest(statementUri);
console.log('Identifier:', identifier, 'Digest:', digest);

If the statementUri does not follow the expected format.

The function splits the statementUri string by the colon (:) delimiter and checks if it conforms to the expected format. If the format is valid, it extracts the identifier and suffix (digest) parts. The digest is then prefixed with ‘0x’ to form the correct statement digest. The function returns an object containing both the identifier and the formatted digest.

identifier/src/Identifier.ts:736