Skip to content

uriToStatementIdAndDigest

uriToStatementIdAndDigest(statementUri): object

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

Parameters

statementUri: stmt:cord:${string}

The statement URI to be parsed. Expected format: ‘stmt:cord:<identifier>:<digest>‘.

Returns

object

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

digest

digest: StatementDigest

identifier

identifier: string

Remarks

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.

Example

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

Throws

If the statementUri does not follow the expected format.

Description

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.

Source

identifier/src/Identifier.ts:699