Template Revision
Schema specification for Template Revisions in Aqua Protocol v4
Template Revision
A Template Revision defines the structure and validation rules for Object Revisions. Templates use JSON Schema to specify what data fields are required, their types, formats, and constraints. Template revisions are standalone (they don't have a previous_revision field) and are referenced by object revisions via their hash.
Overview
Template revisions serve as the "type system" for Aqua Protocol. They:
- Define schemas using JSON Schema (Draft 2020-12)
- Are immutable once created (identified by their hash)
- Can be reused by multiple object revisions
- Optionally reference code implementations
- Enable validation and type safety
Schema Structure
Fields
| Field | Type | Required | Description |
|---|---|---|---|
revision_type | string | Yes | Always "template" for template revisions |
nonce | string | Yes | Random 16-byte hex string for uniqueness |
local_timestamp | number | Yes | Unix timestamp when the template was created |
version | string | Yes | Protocol version: "https://aqua-protocol.org/docs/v4/schema" |
method | string | Yes | Canonicalization method: "scalar" or "tree" (typically "scalar") |
hash_type | string | Yes | Hash algorithm: "FIPS_202-SHA3-256" |
schema | object | Yes | JSON Schema (Draft 2020-12) that validates object payloads |
code_revision_ref | string | No | Optional hash reference to code that implements this template |
Field Details
revision_type
- Value: Always
"template" - Purpose: Identifies this as a template revision
- Note: Unlike object revisions, this is a string constant, not a hash reference
schema
- Format: Valid JSON Schema (Draft 2020-12 specification)
- Purpose: Defines validation rules for object revision payloads
- Required fields in schema:
$schema: Should be"https://json-schema.org/draft/2020-12/schema"type: Typically"object"properties: Defines the payload structurerequired: Lists mandatory fieldsadditionalProperties: Usuallyfalsefor strict validation
code_revision_ref
- Format: Hex string reference to another revision (optional)
- Purpose: Links to executable code or scripts that work with this template
- Use case: For templates that need associated processing logic
- Example: Reference to smart contract code, validation scripts, or transformation functions
Examples
Example 1: File Template
A template for storing file metadata:
1{2 "revision_type": "template",3 "nonce": "0x2ba6a8b9b987cf8c3567f72871812ae9",4 "local_timestamp": 1762266013,5 "version": "https://aqua-protocol.org/docs/v4/schema",6 "method": "scalar",7 "hash_type": "FIPS_202-SHA3-256",8 "schema": {9 "$schema": "https://json-schema.org/draft/2020-12/schema",10 "type": "object",11 "properties": {12 "payload_type": {13 "type": "string",14 "maxLength": 12815 },16 "hash": {17 "type": "string",18 "pattern": "^0x[0-9a-f]{64,128}$"19 },20 "hash_type": {21 "description": "Hash function identifier",22 "anyOf": [23 {24 "type": "string",25 "const": "FIPS_202-SHA3-256"26 },27 {28 "type": "string",29 "minLength": 1,30 "maxLength": 12831 }32 ]33 },34 "descriptor": {35 "type": "string",36 "maxLength": 14037 }38 },39 "required": [40 "payload_type",41 "hash",42 "hash_type",43 "descriptor"44 ],45 "additionalProperties": false46 }47}Hash of this template: 0x742b74c87ccd7bfc76eaec416027a0bc039b59b9c2d452ea55a5c0e9b0e3f08e
This hash is what object revisions use in their revision_type field to reference this template.
Example 2: Domain Claim Template
A template for domain ownership claims:
1{2 "revision_type": "template",3 "nonce": "0x0da37dc1685f4d78a87c9462b0e87685",4 "local_timestamp": 1762817552,5 "version": "https://aqua-protocol.org/docs/v4/schema",6 "method": "scalar",7 "hash_type": "FIPS_202-SHA3-256",8 "schema": {9 "$schema": "https://json-schema.org/draft/2020-12/schema",10 "type": "object",11 "properties": {12 "domain": {13 "type": "string",14 "format": "idn-hostname"15 },16 "wallet_address": {17 "type": "string",18 "pattern": "^0x[0-9a-fA-F]{40}$"19 }20 },21 "required": [22 "domain",23 "wallet_address"24 ],25 "additionalProperties": false26 }27}Example 3: Email Claim Template
A template for email verification claims:
1{2 "revision_type": "template",3 "nonce": "0x5c8f9a1b2d3e4f5a6b7c8d9e0f1a2b3c",4 "local_timestamp": 1762820000,5 "version": "https://aqua-protocol.org/docs/v4/schema",6 "method": "scalar",7 "hash_type": "FIPS_202-SHA3-256",8 "schema": {9 "$schema": "https://json-schema.org/draft/2020-12/schema",10 "type": "object",11 "properties": {12 "email": {13 "type": "string",14 "format": "email"15 },16 "wallet_address": {17 "type": "string",18 "pattern": "^0x[0-9a-fA-F]{40}$"19 },20 "verified_at": {21 "type": "integer",22 "description": "Unix timestamp of verification"23 }24 },25 "required": [26 "email",27 "wallet_address"28 ],29 "additionalProperties": false30 }31}Example 4: Template with Code Reference
A template that references associated code:
1{2 "revision_type": "template",3 "nonce": "0x7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a",4 "local_timestamp": 1762825000,5 "version": "https://aqua-protocol.org/docs/v4/schema",6 "method": "scalar",7 "hash_type": "FIPS_202-SHA3-256",8 "schema": {9 "$schema": "https://json-schema.org/draft/2020-12/schema",10 "type": "object",11 "properties": {12 "calculation_type": {13 "type": "string",14 "enum": ["sum", "average", "weighted"]15 },16 "values": {17 "type": "array",18 "items": {19 "type": "number"20 }21 }22 },23 "required": ["calculation_type", "values"],24 "additionalProperties": false25 },26 "code_revision_ref": "0x3f8a7b2c9d1e4f5a6b8c0d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a"27}Built-in Templates
The Aqua RS SDK provides several built-in templates with pre-computed hashes:
| Template | Purpose | Hash Reference |
|---|---|---|
| File | File metadata storage | 0x742b74c87ccd7bfc76eaec416027a0bc039b59b9c2d452ea55a5c0e9b0e3f08e |
| Domain | Domain ownership claims | (computed at runtime) |
| Email verification | (computed at runtime) | |
| Name | Name claims | (computed at runtime) |
| Phone | Phone verification | (computed at runtime) |
| Attestation | General attestations | (computed at runtime) |
These templates are defined in the SDK at src/schema/templates/ and can be used directly without creating new template revisions.
JSON Schema Features
Template schemas support all JSON Schema Draft 2020-12 features:
Type Validation
1{2 "type": "string" // or "number", "integer", "boolean", "array", "object", "null"3}Format Validation
1{2 "type": "string",3 "format": "email" // or "date", "date-time", "uri", "hostname", etc.4}Pattern Matching
1{2 "type": "string",3 "pattern": "^0x[0-9a-f]{40}$"4}Length Constraints
1{2 "type": "string",3 "minLength": 1,4 "maxLength": 1005}Numeric Constraints
1{2 "type": "number",3 "minimum": 0,4 "maximum": 100,5 "multipleOf": 0.016}Array Constraints
1{2 "type": "array",3 "items": { "type": "string" },4 "minItems": 1,5 "maxItems": 10,6 "uniqueItems": true7}Enumerations
1{2 "type": "string",3 "enum": ["option1", "option2", "option3"]4}Conditional Schemas
1{2 "anyOf": [3 { "type": "string", "const": "FIPS_202-SHA3-256" },4 { "type": "string", "minLength": 1 }5 ]6}Validation Rules
A Template Revision is valid if:
- Structure: Contains all required fields with correct types
- Revision Type: The
revision_typefield is exactly"template" - Version: Matches
"https://aqua-protocol.org/docs/v4/schema" - Schema: Is a valid JSON Schema (Draft 2020-12)
- Schema Root: The schema should define an object type at the root level
- No Previous Revision: Templates never have a
previous_revisionfield - Code Reference: If present,
code_revision_refmust be a valid hash reference - Hash Verification: The computed hash can be verified
Template Lifecycle
1. Creation
Create JSON Schema � Generate Template Revision � Compute Hash
2. Publication
Template Hash � Used by Object Revisions � Enables Validation
3. Reuse
Multiple Objects � Reference Same Template � Consistent Validation
Best Practices
1. Use Descriptive Property Names
1{2 "properties": {3 "email_address": { "type": "string", "format": "email" },4 "verified_at_timestamp": { "type": "integer" }5 }6}2. Always Set additionalProperties
1{2 "additionalProperties": false // Strict validation3}3. Include Descriptions
1{2 "properties": {3 "status": {4 "type": "string",5 "description": "Current verification status: pending, verified, or rejected"6 }7 }8}4. Use Appropriate Constraints
1{2 "email": {3 "type": "string",4 "format": "email",5 "maxLength": 254 // RFC 5321 limit6 }7}5. Plan for Forward Compatibility
- Avoid overly restrictive patterns
- Use
anyOffor accepting multiple formats - Consider optional fields for future extensions
Relationship with Other Revisions
- Object Revisions: Reference templates via their
revision_typefield - Code Revisions: Can be referenced via
code_revision_ref(optional) - No Chaining: Templates don't form chains; they're standalone definitions
Implementation Notes
Creating a Template
- Design your JSON Schema based on your data requirements
- Validate the schema itself is valid JSON Schema
- Create the template revision structure
- Generate a random nonce
- Compute the template hash
- Store the hash for use in object revisions
Using a Template
- Reference the template hash in the object's
revision_type - Ensure payload conforms to the template schema
- Validate payload against schema before creating object revision
Template Validation
When validating an object against a template:
1. Retrieve template by hash
2. Extract JSON Schema from template
3. Validate object payload against schema
4. Check validation result
Common Use Cases
Document Templates
Define structure for document metadata, file hashes, and descriptors.
Credential Templates
Specify required fields for verifiable credentials (email, domain, phone, etc.).
Data Exchange Templates
Standardize data formats for interoperability between systems.
Smart Contract Templates
Link templates to on-chain contract code for decentralized validation.
See Also
- Object Revision - Use templates to validate objects
- JSON Schema Specification - Full JSON Schema documentation
