🍳 Core Concepts
This document provides an in-depth explanation of the core concepts in MoveAS.
Attestation Lifecycle
1. Schema Definition
A schema defines the structure of attestation data. It acts as a contract between the attestor and applications consuming the attestation.
Schema Definition:
field_name: type, field_name2: type2, ...Example:
name: string, age: u64, email: string, verified: bool2. Schema Registration
Schemas must be registered on-chain before creating attestations. Registration returns:
- Schema ID: Unique identifier for the schema
- Admin Capability: Allows schema creator to revoke attestations (if revokable)
3. Attestation Creation
Creating an attestation involves:
- Encoding Data: Using Codec to encode data according to schema
- Storage Decision: Choose on-chain or off-chain storage
- Optional Encryption: Apply Seal encryption for sensitive data
- Transaction Submission: Submit transaction to blockchain
4. Attestation Retrieval
Retrieving attestation data:
- Metadata: Always on-chain (attestor, recipient, timestamps, etc.)
- Data: On-chain or off-chain depending on storage type
- Verification: Check hash for off-chain data integrity
5. Attestation Revocation
If schema is revokable, schema creator can revoke attestations:
- Revocation: Marks attestation as revoked with timestamp
- Immutable: Cannot undo revocation once issued
- Verifiable: Revocation status visible on-chain
Data Encoding
MoveAS uses BCS (Binary Canonical Serialization) for data encoding:
Codec Class
The Codec class provides type-safe encoding/decoding:
const codec = new Codec('name: string, age: u64');
// Encode
const item = { name: "Alice", age: 30n };
const encoded = codec.encodeToBytes(item); // Uint8Array
// Decode
const decoded = codec.decodeFromBytes(encoded); // { name: "Alice", age: 30n }Type Validation
Codec validates data types:
- Automatic Type Normalization:
string→String,address→Address - BigInt Support: Handles
u64,u128,u256types - Vector Support: Arrays and nested structures
- Error Messages: Detailed errors for validation failures
Storage Strategies
On-Chain Storage
When to Use:
- Small data (< 1KB)
- High transparency requirements
- Direct on-chain verification needed
- Low latency requirements
Characteristics:
- Data stored directly in attestation object
- Fully transparent and verifiable
- Higher gas costs
- Limited by block size
Off-Chain Storage (Walrus)
When to Use:
- Large data (> 1KB)
- Cost optimization
- Flexible data formats
- Archive data
Characteristics:
- Data stored in Walrus decentralized storage
- Only metadata and hash on-chain
- Lower gas costs
- Unlimited size
- Requires additional retrieval step
Data Integrity:
- Blake2b-256 hash stored on-chain
- Verify downloaded data matches hash
- Prevents tampering
Privacy Protection
Seal Encryption
Seal provides end-to-end encryption with on-chain access control.
Private Data Pattern:
- Owner: Recipient of attestation
- Key ID:
[attestor][nonce] - Access Control: Only owner can authorize decryption
- Threshold: Configurable key server threshold
Encryption Flow:
- Generate random nonce (16-32 bytes)
- Compute Seal ID:
[attestor][nonce] - Encrypt data using Seal SDK
- Store encrypted data in Walrus
- Store hash of original data on-chain
Decryption Flow:
- Create SessionKey as recipient
- Build transaction calling
seal_approve - Seal key servers verify on-chain access
- Return decryption keys
- Decrypt data using keys
- Verify hash matches
Resolver Pattern
Resolvers provide custom validation logic for attestation creation/revocation.
Resolver Components
- Resolver Module: Move module implementing validation
- Resolver Address: Address of resolver module
- Validation Rules: Logic that approves/rejects requests
Resolver Flow
For Attestation:
- Call
schema::start_attest()→ returnsRequest - Call resolver module's
approve()function - Call
schema::finish_attest()→ validates request - Create attestation with resolver
For Revocation:
- Call
schema::start_revoke()→ returnsRequest - Call resolver module's
approve()function - Call
schema::finish_revoke()→ validates request - Revoke attestation
Example Resolvers
- Whitelist: Only allowlisted addresses can create attestations
- Blacklist: Blocklisted addresses cannot create attestations
- Multi-signature: Require multiple approvals
- Time-based: Restrict attestation creation to specific times
Registry System
Schema Registry
Tracks all registered schemas:
- Schema addresses
- Creator addresses
- Creation timestamps
- Version information
Attestation Registry
Tracks all attestations:
- Attestation addresses
- Schema associations
- Status (active/revoked)
- Timestamps
Benefits:
- Centralized queries
- Efficient lookups
- Version management
- Upgrade support
Error Handling
Common Errors
Schema Errors:
- Invalid schema format
- Unsupported types
- Duplicate field names
Encoding Errors:
- Type mismatch
- Missing required fields
- Invalid BigInt values
Transaction Errors:
- Insufficient gas
- Invalid parameters
- Access denied
Storage Errors:
- Walrus upload failures
- Hash mismatch
- Missing data
Error Recovery
- Retry Logic: Implement retries for network errors
- Validation: Validate data before encoding
- Error Messages: Provide clear error messages
- Logging: Log errors for debugging
Best Practices
Schema Design
- Use Clear Names: Descriptive field names
- Choose Appropriate Types: Use smallest sufficient type
- Avoid Duplicates: Don't duplicate information
- Document Schemas: Provide clear documentation
Data Management
- Validate Early: Validate data before encoding
- Handle Errors: Implement proper error handling
- Cache Results: Cache decoded data when possible
- Verify Integrity: Always verify off-chain data hashes
Security
- Use Encryption: Encrypt sensitive data
- Set Expiration: Always set expiration times
- Implement Resolvers: Use resolvers for access control
- Monitor Revocations: Check revocation status
Performance
- Choose Storage Wisely: Use off-chain for large data
- Batch Operations: Batch multiple attestations
- Optimize Queries: Use registries for efficient lookups
- Cache Data: Cache frequently accessed data
Next: Architecture →