Skip to content

getDigestFromRawData

getDigestFromRawData(blob): unknown

Computes a Blake2 H256 hash digest from the provided raw data (blob).

This function verifies if the input blob is serialized before hashing it.

Parameters

blob: string

The raw data input for which the digest needs to be calculated. This should be a serialized string.

Returns

unknown

A promise that resolves to the computed digest of the blob, represented as a hexadecimal string.

Throws

Throws an error if the blob is not serialized.

Usage Example:

const rawData = '{"key": "value"}'; // Example raw data
try {
const digest = await getDigestFromRawData(rawData);
console.log(`Computed Digest: ${digest}`); // Logs the computed digest
} catch (error) {
console.error(error.message); // Handles any errors thrown
}

This function first checks whether the provided blob is serialized. If not, it throws an error. Once confirmed, it encodes the blob into a byte array and calculates the Blake2 hash digest, returning the result as a hexadecimal string.

Source

registries/src/Registries.ts:122