Schema Registry Smart Contract

View as Markdown

The Schema Registry stores credential schema definitions on the ADI blockchain, enabling verifiers to validate credential structure.

Interface

1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.24;
3
4interface ISchemaRegistry {
5 struct SchemaRecord {
6 string schemaId;
7 string name;
8 string version;
9 address author;
10 bytes32 schemaHash;
11 string storageUri;
12 uint256 created;
13 bool active;
14 }
15
16 event SchemaCreated(string indexed schemaId, string name, string version, address indexed author);
17 event SchemaDeactivated(string indexed schemaId);
18
19 function createSchema(
20 string calldata schemaId,
21 string calldata name,
22 string calldata version,
23 bytes32 schemaHash,
24 string calldata storageUri
25 ) external;
26
27 function getSchema(string calldata schemaId) external view returns (SchemaRecord memory);
28
29 function listSchemas(uint256 offset, uint256 limit) external view returns (SchemaRecord[] memory);
30
31 function deactivateSchema(string calldata schemaId) external;
32
33 function getSchemaCount() external view returns (uint256);
34}

Key Functions

createSchema

Registers a new credential schema.

ParameterTypeDescription
schemaIdstringDID-based schema ID (e.g., did:adi:schema:kyc-v1)
namestringHuman-readable schema name
versionstringSemantic version string
schemaHashbytes32SHA-256 hash of the JSON Schema
storageUristringIPFS URI for the full schema definition

getSchema

Returns the schema record by ID. View function (no gas cost).

listSchemas

Paginated listing of all registered schemas.

Interaction Example

1const schemaRegistry = new ethers.Contract(SCHEMA_REGISTRY_ADDRESS, SCHEMA_REGISTRY_ABI, signer);
2
3// Create schema
4const tx = await schemaRegistry.createSchema(
5 'did:adi:schema:university-degree-v1',
6 'UniversityDegree',
7 '1.0',
8 ethers.keccak256(ethers.toUtf8Bytes(JSON.stringify(jsonSchema))),
9 'ipfs://QmSchemaHash...'
10);
11await tx.wait();
12
13// Get schema
14const schema = await schemaRegistry.getSchema('did:adi:schema:university-degree-v1');
15console.log('Schema:', schema.name, 'v' + schema.version);

Gas Costs

OperationEstimated Gas
createSchema~200,000
getSchema0 (view)
listSchemas0 (view)
deactivateSchema~45,000