Skip to main content

Documentation Index

Fetch the complete documentation index at: https://core.anylayer.org/llms.txt

Use this file to discover all available pages before exploring further.

Overview

Attestations are cryptographically signed claims about identities, behaviors, or achievements that enable trust verification across the ZKScore ecosystem.

Attestation Structure

Basic Attestation

const attestation = {
  attester: '0x...', // Address of the attester
  recipient: '0x...', // Address of the recipient
  schema: '0x...', // Schema UID
  data: '0x...', // Encoded attestation data
  expiration: 0, // Expiration timestamp (0 = no expiration)
  revocable: true, // Whether attestation can be revoked
  signature: '0x...' // Cryptographic signature
};

Schema Definition

const schema = {
  name: 'Skill Verification',
  description: 'Verifies a user has specific skills',
  fields: [
    { name: 'skill', type: 'string' },
    { name: 'level', type: 'uint256' },
    { name: 'verifiedBy', type: 'address' }
  ]
};

Creating Attestations

1. Define Attestation Data

// Attestation data
const attestationData = {
  skill: 'Solidity Development',
  level: 5,
  verifiedBy: '0x1234567890123456789012345678901234567890'
};

// Encode data according to schema
const encodedData = ethers.utils.defaultAbiCoder.encode(
  ['string', 'uint256', 'address'],
  [attestationData.skill, attestationData.level, attestationData.verifiedBy]
);

2. Create Attestation

// Create attestation
const tx = await trustRegistry.createAttestation(
  recipientAddress, // recipient
  schemaUID, // schema
  encodedData, // encoded data
  expirationTime, // expiration (0 = no expiration)
  true // revocable
);

await tx.wait();
console.log('Attestation created!', tx.hash);

3. Verify Attestation

// Get attestation
const attestationUID = await trustRegistry.getLatestAttestationUID();
const attestation = await trustRegistry.getAttestation(attestationUID);

console.log('Attestation:', attestation);

// Verify attestation validity
const isValid = await trustRegistry.isValidAttestation(attestationUID);
console.log('Is valid:', isValid);

Attestation Types

Skill Verification

const skillAttestation = {
  schema: 'skill-verification',
  data: {
    skill: 'Smart Contract Development',
    level: 8,
    verifiedBy: '0x...',
    timestamp: Date.now()
  }
};

Identity Verification

const identityAttestation = {
  schema: 'identity-verification',
  data: {
    verificationType: 'KYC',
    level: 'enhanced',
    issuer: '0x...',
    expiration: Date.now() + (365 * 24 * 60 * 60 * 1000) // 1 year
  }
};

Achievement Verification

const achievementAttestation = {
  schema: 'achievement-verification',
  data: {
    achievement: 'DeFi Pioneer',
    protocol: 'uniswap',
    verifiedBy: '0x...',
    timestamp: Date.now()
  }
};

Attestation Verification

On-chain Verification

// Verify attestation exists and is valid
async function verifyAttestation(attestationUID) {
  const attestation = await trustRegistry.getAttestation(attestationUID);
  
  if (!attestation) {
    return { valid: false, reason: 'Attestation not found' };
  }
  
  if (attestation.revoked) {
    return { valid: false, reason: 'Attestation revoked' };
  }
  
  if (attestation.expiration > 0 && Date.now() > attestation.expiration) {
    return { valid: false, reason: 'Attestation expired' };
  }
  
  return { valid: true, attestation };
}

Batch Verification

// Verify multiple attestations
async function verifyAttestations(attestationUIDs) {
  const results = await Promise.all(
    attestationUIDs.map(uid => verifyAttestation(uid))
  );
  
  return results.filter(result => result.valid);
}

Revoking Attestations

Revoke Attestation

// Revoke attestation
const tx = await trustRegistry.revokeAttestation(attestationUID);
await tx.wait();
console.log('Attestation revoked!', tx.hash);

Check Revocation Status

// Check if attestation is revoked
const isRevoked = await trustRegistry.isAttestationRevoked(attestationUID);
console.log('Is revoked:', isRevoked);

Trust Modules

Custom Trust Logic

// Custom trust module
const trustModule = {
  name: 'Skill Trust Module',
  description: 'Evaluates trust based on skill attestations',
  logic: `
    function evaluateTrust(address user) public view returns (uint256) {
      // Custom trust evaluation logic
      uint256 skillScore = getSkillScore(user);
      uint256 verificationScore = getVerificationScore(user);
      return (skillScore + verificationScore) / 2;
    }
  `
};

Register Trust Module

// Register trust module
const tx = await trustRegistry.registerTrustModule(
  trustModule.name,
  trustModule.description,
  trustModuleContractAddress
);

await tx.wait();
console.log('Trust module registered!', tx.hash);

Best Practices

  1. Clear Schemas: Define clear, well-documented schemas
  2. Appropriate Expiration: Set reasonable expiration times
  3. Secure Signing: Use secure key management for signing
  4. Regular Verification: Periodically verify attestation validity
  5. Privacy Considerations: Consider data privacy in attestations