What is a Schema?
A schema is a template that defines what data an attestation contains. Every attestation references a schema, ensuring data consistency and enabling verification.Why Schemas Matter
Data Consistency
Schemas enforce structure. An attestation using a KYC schema will always have the same fields, making it predictable for verifiers.Interoperability
Different applications can issue attestations against the same schema. A “KYC verified” attestation from Provider A is structurally identical to one from Provider B.Discoverability
Schemas are registered on-chain with unique identifiers. Applications can query for all attestations of a specific type.Schema Components
| Component | Description |
|---|---|
| Definition | Field names and types |
| Authority | Who created the schema |
| Resolver | Optional contract for custom validation |
| Revocable | Whether attestations can be revoked |
| UID | Deterministic identifier |
Field Types
Schemas support these primitive types:| Type | Size | Description |
|---|---|---|
bool | 1 bit | True/false |
string | Variable | Text data |
u32 | 32 bits | Unsigned integer |
u64 | 64 bits | Unsigned integer (timestamps) |
i32 | 32 bits | Signed integer |
i64 | 64 bits | Signed integer |
i128 | 128 bits | Large signed integer |
bytes | Variable | Binary data |
address | 56 chars | Stellar wallet address |
symbol | Variable | Soroban symbol type |
timestamp | 64 bits | Unix timestamp |
amount | Variable | Token amounts |
Encoding Formats
The SDK’sSorobanSchemaEncoder supports multiple encoding formats. Your choice of format affects how data is stored and indexed.
These encoding formats determine how your schema and attestation data are stored on-chain and indexed by our explorer. Choose the format that best fits your use case.
Typed Schema (Default)
Native typed schema with validation rules. Best for most use cases.- Type validation at encode time
- Optional field validation (min, max, pattern, enum)
- Auto-conversion for timestamps and addresses
JSON Schema
Standard JSON Schema format for interoperability with external tools.- Integration with JSON Schema validators
- Generating forms from schemas
- API documentation and OpenAPI specs
XDR Format
Stellar’s native binary format for efficient storage and selective disclosure.- Compact storage — Binary format reduces on-chain storage costs
- Selective disclosure — Reveal only specific fields without exposing entire attestation
- Native Soroban compatibility — Direct integration with contract data structures
XDR provides selective disclosure, not encryption. Data is structured so you can reveal individual fields while keeping others private. For true privacy, combine with off-chain encrypted storage.
Format Comparison
| Format | Storage Size | Indexer Support | Use Case |
|---|---|---|---|
| Typed | Medium | Full | General purpose, validation needed |
| JSON | Larger | Full | Interoperability, external tools |
| XDR | Smallest | Full | Compact storage, selective disclosure |
Schema UID
Every schema has a unique identifier derived from:- Same definition by different authorities = different UIDs
- Same authority, different definition = different UIDs
- Identical inputs always produce the same UID
Resolvers
A resolver is an optional smart contract that validates attestations before they’re created. Use cases:- Payment gates: Require fee payment before attestation
- Eligibility checks: Verify the subject meets criteria
- Rate limiting: Prevent spam attestations
- Custom logic: Any business rules
Common Schema Patterns
Identity Verification
Credential
Membership
Reputation
Schema Lifecycle
- Create: Authority registers schema on-chain
- Discover: Others find schema by UID or query
- Use: Attesters create attestations referencing schema
- Verify: Verifiers decode attestation data using schema definition
Best Practices
Keep schemas minimal
Only include fields you need. Smaller schemas = lower costs.
Use appropriate types
u64 for timestamps, bool for flags, string for text.Plan for revocation
Set
revocable: true for credentials that may need invalidation.Version your schemas
Include version in name:
KYC_v2 for breaking changes.