> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.adid.dev/llms.txt.
> For full documentation content, see https://docs.adid.dev/llms-full.txt.

# Schema Registry Smart Contract

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

## Interface

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

interface ISchemaRegistry {
    struct SchemaRecord {
        string schemaId;
        string name;
        string version;
        address author;
        bytes32 schemaHash;
        string storageUri;
        uint256 created;
        bool active;
    }

    event SchemaCreated(string indexed schemaId, string name, string version, address indexed author);
    event SchemaDeactivated(string indexed schemaId);

    function createSchema(
        string calldata schemaId,
        string calldata name,
        string calldata version,
        bytes32 schemaHash,
        string calldata storageUri
    ) external;

    function getSchema(string calldata schemaId) external view returns (SchemaRecord memory);

    function listSchemas(uint256 offset, uint256 limit) external view returns (SchemaRecord[] memory);

    function deactivateSchema(string calldata schemaId) external;

    function getSchemaCount() external view returns (uint256);
}
```

## Key Functions

### createSchema

Registers a new credential schema.

| Parameter    | Type    | Description                                         |
| ------------ | ------- | --------------------------------------------------- |
| `schemaId`   | string  | DID-based schema ID (e.g., `did:adi:schema:kyc-v1`) |
| `name`       | string  | Human-readable schema name                          |
| `version`    | string  | Semantic version string                             |
| `schemaHash` | bytes32 | SHA-256 hash of the JSON Schema                     |
| `storageUri` | string  | IPFS 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

```javascript
const schemaRegistry = new ethers.Contract(SCHEMA_REGISTRY_ADDRESS, SCHEMA_REGISTRY_ABI, signer);

// Create schema
const tx = await schemaRegistry.createSchema(
  'did:adi:schema:university-degree-v1',
  'UniversityDegree',
  '1.0',
  ethers.keccak256(ethers.toUtf8Bytes(JSON.stringify(jsonSchema))),
  'ipfs://QmSchemaHash...'
);
await tx.wait();

// Get schema
const schema = await schemaRegistry.getSchema('did:adi:schema:university-degree-v1');
console.log('Schema:', schema.name, 'v' + schema.version);
```

## Gas Costs

| Operation        | Estimated Gas |
| ---------------- | ------------- |
| createSchema     | \~200,000     |
| getSchema        | 0 (view)      |
| listSchemas      | 0 (view)      |
| deactivateSchema | \~45,000      |