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
Section titled “Functionality”- Uses CBOR encoding to serialize the schema for efficient processing.
- Cryptographically hashes the serialized schema using
blake2hashing 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
Section titled “Parameters”Parameters
Section titled “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
Section titled “Returns”Returns
Section titled “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.
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
Section titled “Throws”digest
Section titled “digest”digest:
SchemaDigest
uri:
SchemaUri
Throws
Section titled “Throws”If any part of the URI generation process fails, such as issues with schema serialization, etc.
Example
Section titled “Example”const schema = { name: "Example Schema", properties: { id: "string" } };const result = getUriForSchema(schema);console.log(result.uri); // Unique schema URI