updateStatementUri
updateStatementUri(
stmtUri
,digest
):StatementUri
Updates the digest component of a given statement URI with a new digest.
Parameters
• stmtUri: stmt:cord:${string}
The original statement URI that needs to be updated. It should follow the format ‘stmt:cord:<identifier>
:<digest>
‘.
• digest: HexString
The new hexadecimal string digest to be inserted into the statement URI. Must start with ‘0x’.
Returns
StatementUri
The updated statement URI, now containing the new digest.
Remarks
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.
Example
const originalUri = 'stmt:cord:1234:abcd';const newDigest = '0x5678...';const updatedUri = updateStatementUri(originalUri, newDigest);console.log('Updated Statement URI:', updatedUri);
Throws
If the stmtUri
does not follow the expected format.
Throws
If the new digest
does not start with ‘0x’.
Description
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.