getUriForSchema
getUriForSchema(
schema
):object
(Internal Function) - Generates a unique URI for a given schema based on its serialized content.
This function ensures each schema is uniquely identified and reliably retrievable using the generated URI.
Functionality
- Uses CBOR encoding to serialize the schema for efficient processing.
- Cryptographically hashes the serialized schema using
blake2
hashing to ensure uniqueness. - Encodes the schema with SCALE encoding for compatibility with Substrate-based systems.
- Generates a URI from the schema’s digest using network-specific identifiers and prefixes.
Parameters
Parameters
• schema: any
The schema object or a version of it without the $id
property.
It must conform to the ISchema
interface used in the Cord network.
Returns
Returns
object
An object containing:
uri
: A string representing the unique URI of the schema within the Cord network.digest
: A cryptographic hash of the schema’s serialized content.
Usage
This function is used internally to register and manage schemas, ensuring that each one is uniquely identifiable within the Cord network using its URI.
Throws
digest
digest:
SchemaDigest
uri
uri:
SchemaUri
Throws
If any part of the URI generation process fails, such as issues with schema serialization, etc.
Example
const schema = { name: "Example Schema", properties: { id: "string" } };const result = getUriForSchema(schema);console.log(result.uri); // Unique schema URI