Skip to content

updateStatementUri

updateStatementUri(stmtUri, digest): StatementUri

Updates the digest component of a given statement URI with a new digest.

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

The original statement URI that needs to be updated. It should follow the format ‘stmt:cord::‘.

digest: HexString

The new hexadecimal string digest to be inserted into the statement URI. Must start with ‘0x’.

StatementUri

The updated statement URI, now containing the new digest.

This function modifies an existing statement URI by replacing its digest with a new provided digest. It ensures that the URI retains its original structure and prefix, while only the digest part is updated.

const originalUri = 'stmt:cord:1234:abcd';
const newDigest = '0x5678...';
const updatedUri = updateStatementUri(originalUri, newDigest);
console.log('Updated Statement URI:', updatedUri);

If the stmtUri does not follow the expected format.

If the new digest does not start with ‘0x’.

The function first splits the original stmtUri and verifies its structure, ensuring it has the correct prefix (‘stmt:cord’). If the format is invalid, it throws an InvalidIdentifierError. It then checks if the new digest starts with ‘0x’, throwing an InvalidInputError if it doesn’t. After validation, it constructs the updated URI using the unchanged parts from the original URI and the new digest (with the ‘0x’ prefix removed). This updated URI is then returned.

identifier/src/Identifier.ts:693