> ## 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.

# Attestations

> Create, verify, and manage attestations in the Trust Registry

## Overview

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

## Attestation Structure

### Basic Attestation

```javascript theme={null}
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

```javascript theme={null}
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

<CodeGroup>
  ```javascript JavaScript theme={null}
  // 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]
  );
  ```
</CodeGroup>

### 2. Create Attestation

<CodeGroup>
  ```javascript JavaScript theme={null}
  // 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);
  ```

  ```solidity Solidity theme={null}
  // Create attestation in contract
  trustRegistry.createAttestation(
    recipient,
    schemaUID,
    encodedData,
    expirationTime,
    true
  );
  ```
</CodeGroup>

### 3. Verify Attestation

<CodeGroup>
  ```javascript JavaScript theme={null}
  // 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);
  ```
</CodeGroup>

## Attestation Types

### Skill Verification

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

### Identity Verification

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

### Achievement Verification

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

## Attestation Verification

### On-chain Verification

<CodeGroup>
  ```javascript JavaScript theme={null}
  // 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 };
  }
  ```
</CodeGroup>

### Batch Verification

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

## Revoking Attestations

### Revoke Attestation

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Revoke attestation
  const tx = await trustRegistry.revokeAttestation(attestationUID);
  await tx.wait();
  console.log('Attestation revoked!', tx.hash);
  ```

  ```solidity Solidity theme={null}
  // Revoke in contract
  trustRegistry.revokeAttestation(attestationUID);
  ```
</CodeGroup>

### Check Revocation Status

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Check if attestation is revoked
  const isRevoked = await trustRegistry.isAttestationRevoked(attestationUID);
  console.log('Is revoked:', isRevoked);
  ```
</CodeGroup>

## Trust Modules

### Custom Trust Logic

```javascript theme={null}
// 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

<CodeGroup>
  ```javascript JavaScript theme={null}
  // Register trust module
  const tx = await trustRegistry.registerTrustModule(
    trustModule.name,
    trustModule.description,
    trustModuleContractAddress
  );

  await tx.wait();
  console.log('Trust module registered!', tx.hash);
  ```
</CodeGroup>

## 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

## Related Documentation

* [Trust Registry Overview](/contracts/trust-registry/overview)
* [Create Attestation API](/api-reference/trust-layer/create-attestation)
* [Trust Modules](/contracts/trust-registry/modules)
