Skip to content

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.

  • 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.

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.

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.

digest: SchemaDigest

uri: SchemaUri

If any part of the URI generation process fails, such as issues with schema serialization, etc.

const schema = { name: "Example Schema", properties: { id: "string" } };
const result = getUriForSchema(schema);
console.log(result.uri); // Unique schema URI

schema/src/Schema.chain.ts:173