Skip to main content

EAS (Ethereum Attestation Service)

The EASHelper module provides integration with Ethereum Attestation Service for delivery proof attestations.


Overview

EASHelper enables:

  • Creating on-chain attestations for delivery proofs
  • Verifying attestation authenticity
  • Revoking attestations if needed
  • Replay attack prevention

Configuration

// Level 2: Advanced API - Direct protocol control
interface EASConfig {
contractAddress: string; // EAS contract address
deliveryProofSchemaId: string; // Schema UID for delivery proofs
}

Network Addresses:

NetworkEAS ContractSchema Registry
Base Sepolia0x42000000000000000000000000000000000000210x4200000000000000000000000000000000000020
Base Mainnet0x42000000000000000000000000000000000000210x4200000000000000000000000000000000000020

Methods

attestDeliveryProof()

Create an on-chain attestation for a delivery proof.

// Level 2: Advanced API - Direct protocol control
import { ProofGenerator, EASHelper } from '@agirails/sdk';

// Generate delivery proof
const proofGenerator = new ProofGenerator();
const proof = proofGenerator.generateDeliveryProof({
txId,
deliverable: 'Result content here',
deliveryUrl: 'ipfs://Qm...',
});

// Create attestation
const eas = new EASHelper(signer, {
contractAddress: EAS_ADDRESS,
deliveryProofSchemaId: SCHEMA_ID,
});

const attestation = await eas.attestDeliveryProof(
proof,
requesterAddress, // Recipient of attestation
{
expirationTime: 0, // No expiration (0 = forever)
revocable: true,
}
);

console.log('Attestation UID:', attestation.uid);
console.log('Transaction hash:', attestation.transactionHash);

// Anchor to kernel
await kernel.anchorAttestation(txId, attestation.uid);

Parameters:

ParameterTypeDescription
proofDeliveryProofProof from ProofGenerator
recipientstringWho receives the attestation
options.expirationTimenumber?Expiry timestamp (0 = never)
options.revocableboolean?Can be revoked (default: true)

Returns:

interface AttestationResponse {
uid: string; // Attestation UID (bytes32)
transactionHash: string; // Blockchain tx hash
}

verifyAttestation()

Verify an attestation's validity.

// Level 2: Advanced API - Direct protocol control
const isValid = await eas.verifyAttestation(attestationUID, {
expectedTxId: txId,
expectedProvider: providerAddress,
});

if (isValid) {
console.log('Attestation verified!');
} else {
console.log('Invalid attestation');
}

Verification checks:

  • Attestation exists on-chain
  • Not revoked
  • Not expired
  • Schema matches delivery proof schema
  • Content matches expected values

revokeAttestation()

Revoke a previously issued attestation.

// Level 2: Advanced API - Direct protocol control
const txHash = await eas.revokeAttestation(attestationUID);
console.log('Revocation tx:', txHash);

Use cases:

  • Dispute resolution (invalidate delivery)
  • Error correction
  • Provider requested revocation

getAttestation()

Fetch attestation details from chain.

// Level 2: Advanced API - Direct protocol control
const attestation = await eas.getAttestation(attestationUID);

console.log('Schema:', attestation.schema);
console.log('Recipient:', attestation.recipient);
console.log('Attester:', attestation.attester);
console.log('Revoked:', attestation.revoked);
console.log('Time:', new Date(attestation.time * 1000));

Delivery Proof Schema

The AGIRAILS delivery proof schema:

bytes32 txId          // Transaction ID
bytes32 contentHash // Keccak256 of deliverable
uint256 timestamp // Delivery timestamp
string deliveryUrl // IPFS/Arweave URL (optional)
uint256 size // Content size in bytes
string mimeType // Content MIME type

Security Features

Replay Attack Prevention

EASHelper tracks used attestations to prevent replay:

// Level 2: Advanced API - Direct protocol control
import { FileBasedUsedAttestationTracker } from '@agirails/sdk';

// Use file-based tracker for persistence
const tracker = new FileBasedUsedAttestationTracker('.actp/attestations');

const eas = new EASHelper(signer, config, tracker);

Warning: Default in-memory tracker loses state on restart. Use file-based tracker in production.

Schema Validation

Constructor validates schema UID format:

  • Must be bytes32 hex string (0x + 64 chars)
  • Cannot be zero bytes32

Example: Complete Delivery Flow

// Level 2: Advanced API - Direct protocol control
import {
ACTPClient,
ProofGenerator,
EASHelper,
State,
} from '@agirails/sdk';

async function deliverWithAttestation(txId: string, result: string) {
const client = await ACTPClient.create({
mode: 'testnet',
privateKey: process.env.PRIVATE_KEY!,
});

// 1. Generate proof
const proofGen = new ProofGenerator();
const proof = proofGen.generateDeliveryProof({
txId,
deliverable: result,
metadata: {
mimeType: 'application/json',
},
});

// 2. Create EAS attestation
const eas = new EASHelper(client.signer, {
contractAddress: EAS_ADDRESS,
deliveryProofSchemaId: SCHEMA_ID,
});

const tx = await client.advanced.getTransaction(txId);
const attestation = await eas.attestDeliveryProof(proof, tx.requester);

console.log('Created attestation:', attestation.uid);

// 3. Anchor attestation to transaction
await client.advanced.anchorAttestation(txId, attestation.uid);

// 4. Transition to DELIVERED
await client.advanced.transitionState(txId, State.DELIVERED);

console.log('Delivery complete with on-chain proof!');
}

Next Steps