Skip to main content

Overview

The Trust Layer SDK provides a flexible framework for creating, managing, and querying attestations. Build custom trust systems, KYC verification, community badges, and more with on-chain or off-chain attestations.

Get Attestations

Retrieve all attestations for an address:
const attestations = await sdk.trustLayer.getAttestations('0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb1');

console.log(attestations);
// [
//   {
//     id: "att_abc123",
//     schema: "kyc-verification",
//     attester: "0x987...",
//     subject: "0x742d35...",
//     data: {
//       verified: true,
//       level: "tier-2",
//       provider: "Synaps"
//     },
//     createdAt: "2024-01-15T10:30:00Z",
//     expiresAt: "2025-01-15T10:30:00Z",
//     revoked: false,
//     onChain: true,
//     txHash: "0xdef456..."
//   },
//   // ... more attestations
// ]

Parameters

address
string
required
Address to query attestations for
options
object
Query options

Create Attestation

Issue a new attestation:
const attestation = await sdk.trustLayer.createAttestation({
  subject: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb1',
  schema: 'community-member',
  data: {
    role: 'contributor',
    joinedAt: new Date().toISOString(),
    reputation: 'trusted',
    contributions: 42,
  },
  expiresAt: new Date('2025-12-31').toISOString(),
  onChain: true,
});

console.log(attestation);
// {
//   id: "att_xyz789",
//   schema: "community-member",
//   attester: "0x123...",
//   subject: "0x742d35...",
//   data: { ... },
//   createdAt: "2024-10-23T14:30:00Z",
//   expiresAt: "2025-12-31T00:00:00Z",
//   revoked: false,
//   onChain: true,
//   txHash: "0xabc123..."
// }

Parameters

params
object
required
Attestation parameters
Creating on-chain attestations requires a wallet signature and gas fees.

Revoke Attestation

Revoke an existing attestation:
await sdk.trustLayer.revokeAttestation('att_abc123', {
  reason: 'User requested removal',
});

console.log('Attestation revoked');

Parameters

attestationId
string
required
ID of the attestation to revoke
options
object
Revocation options

Get Available Modules

List available trust modules and their schemas:
const modules = await sdk.trustLayer.getModules();

console.log(modules);
// [
//   {
//     id: "kyc",
//     name: "KYC Verification",
//     description: "Know Your Customer verification",
//     schema: {
//       verified: "boolean",
//       level: "string",
//       provider: "string",
//       completedAt: "timestamp"
//     },
//     attesters: ["0x123...", "0x456..."],
//     attestationCount: 15234
//   },
//   {
//     id: "dao-member",
//     name: "DAO Membership",
//     description: "DAO participation and role attestation",
//     schema: {
//       daoAddress: "address",
//       role: "string",
//       joinedAt: "timestamp",
//       votingPower: "number"
//     },
//     attesters: ["0x789..."],
//     attestationCount: 8901
//   },
//   // ... more modules
// ]

Evaluate Trust Policy

Check if an address meets specific trust criteria:
const evaluation = await sdk.trustLayer.evaluatePolicy('0x742d35...', {
  rules: [
    {
      schema: 'kyc-verification',
      required: true,
      conditions: {
        'data.verified': true,
        'data.level': ['tier-2', 'tier-3'],
      },
    },
    {
      schema: 'community-member',
      required: false,
      conditions: {
        'data.reputation': ['trusted', 'verified'],
      },
    },
  ],
  minAttestations: 1,
  maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
});

console.log(evaluation);
// {
//   passed: true,
//   score: 95,
//   results: [
//     {
//       schema: "kyc-verification",
//       passed: true,
//       attestations: [{ id: "att_abc123", ... }]
//     },
//     {
//       schema: "community-member",
//       passed: true,
//       attestations: [{ id: "att_def456", ... }]
//     }
//   ],
//   missingSchemas: [],
//   expiredAttestations: []
// }

Parameters

address
string
required
Address to evaluate
policy
object
required
Trust policy configuration

Advanced Examples

KYC Verification System

async function verifyKYC(userAddress: string, kycData: any) {
  // Create KYC attestation
  const attestation = await sdk.trustLayer.createAttestation({
    subject: userAddress,
    schema: 'kyc-verification',
    data: {
      verified: true,
      level: kycData.tier,
      provider: 'Synaps',
      documentType: kycData.documentType,
      country: kycData.country,
      completedAt: new Date().toISOString(),
    },
    expiresAt: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(), // 1 year
    onChain: true,
  });

  console.log('KYC attestation created:', attestation.id);
  return attestation;
}

// Check KYC status
async function checkKYCStatus(userAddress: string) {
  const attestations = await sdk.trustLayer.getAttestations(userAddress, {
    schema: 'kyc-verification',
  });

  if (attestations.length === 0) {
    return { verified: false, message: 'No KYC attestation found' };
  }

  const kycAtt = attestations[0];

  if (kycAtt.revoked) {
    return { verified: false, message: 'KYC attestation revoked' };
  }

  if (new Date(kycAtt.expiresAt!) < new Date()) {
    return { verified: false, message: 'KYC attestation expired' };
  }

  return {
    verified: true,
    level: kycAtt.data.level,
    provider: kycAtt.data.provider,
  };
}

DAO Membership System

async function grantDAOMembership(
  daoAddress: string,
  memberAddress: string,
  role: string
) {
  const attestation = await sdk.trustLayer.createAttestation({
    subject: memberAddress,
    schema: 'dao-member',
    data: {
      daoAddress,
      role,
      joinedAt: new Date().toISOString(),
      votingPower: role === 'core' ? 10 : 1,
    },
    onChain: true,
  });

  return attestation;
}

async function getDAOMembers(daoAddress: string) {
  // This would require a custom API endpoint
  const allAttestations = await sdk.trustLayer.getAttestations(daoAddress, {
    schema: 'dao-member',
  });

  return allAttestations.filter(
    (att) => att.data.daoAddress === daoAddress && !att.revoked
  );
}

Multi-Signature Attestation

async function createMultiSigAttestation(
  subject: string,
  signers: string[],
  data: any
) {
  // First signer creates the attestation
  const baseAttestation = await sdk.trustLayer.createAttestation({
    subject,
    schema: 'multisig-attestation',
    data: {
      ...data,
      signers,
      signatures: 1,
      signedBy: [signers[0]],
    },
    onChain: true,
  });

  // Additional signers reference the base attestation
  const additionalSignatures = await Promise.all(
    signers.slice(1).map((signer) =>
      sdk.trustLayer.createAttestation({
        subject,
        schema: 'multisig-signature',
        data: {
          signer,
          signedAt: new Date().toISOString(),
        },
        refUID: baseAttestation.id,
        onChain: true,
      })
    )
  );

  return {
    baseAttestation,
    signatures: additionalSignatures,
  };
}

Skill Verification

async function attestSkill(
  developerAddress: string,
  skill: string,
  level: number
) {
  return await sdk.trustLayer.createAttestation({
    subject: developerAddress,
    schema: 'skill-verification',
    data: {
      skill,
      level, // 1-10
      verifiedBy: 'code-review',
      projects: ['project1', 'project2'],
      endorsements: 5,
    },
    onChain: false, // Off-chain for lower cost
  });
}

async function getDeveloperSkills(address: string) {
  const skills = await sdk.trustLayer.getAttestations(address, {
    schema: 'skill-verification',
  });

  return skills.map((att) => ({
    skill: att.data.skill,
    level: att.data.level,
    endorsements: att.data.endorsements,
  }));
}

Trust Score Calculator

async function calculateTrustScore(address: string) {
  const attestations = await sdk.trustLayer.getAttestations(address);

  let score = 0;

  // KYC verification: +30 points
  const hasKYC = attestations.some((att) => att.schema === 'kyc-verification');
  if (hasKYC) score += 30;

  // DAO memberships: +10 points each (max 30)
  const daoMemberships = attestations.filter(
    (att) => att.schema === 'dao-member'
  ).length;
  score += Math.min(daoMemberships * 10, 30);

  // Community attestations: +5 points each (max 20)
  const communityAtts = attestations.filter(
    (att) => att.schema === 'community-member'
  ).length;
  score += Math.min(communityAtts * 5, 20);

  // Skills: +2 points per level (max 20)
  const skillPoints = attestations
    .filter((att) => att.schema === 'skill-verification')
    .reduce((sum, att) => sum + (att.data.level || 0), 0);
  score += Math.min(skillPoints * 2, 20);

  return {
    score: Math.min(score, 100),
    breakdown: {
      kyc: hasKYC ? 30 : 0,
      dao: Math.min(daoMemberships * 10, 30),
      community: Math.min(communityAtts * 5, 20),
      skills: Math.min(skillPoints * 2, 20),
    },
  };
}

Attestation Expiry Monitor

async function monitorExpiringAttestations(address: string, daysThreshold: number = 30) {
  const attestations = await sdk.trustLayer.getAttestations(address);

  const now = new Date();
  const thresholdDate = new Date(now.getTime() + daysThreshold * 24 * 60 * 60 * 1000);

  const expiringSoon = attestations.filter((att) => {
    if (!att.expiresAt) return false;
    const expiryDate = new Date(att.expiresAt);
    return expiryDate > now && expiryDate < thresholdDate;
  });

  return expiringSoon.map((att) => ({
    id: att.id,
    schema: att.schema,
    expiresAt: att.expiresAt,
    daysRemaining: Math.floor(
      (new Date(att.expiresAt!).getTime() - now.getTime()) / (24 * 60 * 60 * 1000)
    ),
  }));
}

Schema Examples

Standard Schemas

// KYC Verification
{
  verified: boolean;
  level: 'tier-1' | 'tier-2' | 'tier-3';
  provider: string;
  completedAt: string;
}

// DAO Membership
{
  daoAddress: string;
  role: string;
  joinedAt: string;
  votingPower: number;
}

// Skill Verification
{
  skill: string;
  level: number; // 1-10
  verifiedBy: string;
  projects: string[];
  endorsements: number;
}

// Community Member
{
  role: string;
  reputation: string;
  contributions: number;
  joinedAt: string;
}

// Event Attendance
{
  eventName: string;
  eventDate: string;
  location: string;
  role: 'attendee' | 'speaker' | 'organizer';
}

Error Handling

try {
  const attestation = await sdk.trustLayer.createAttestation({
    subject: '0x742d35...',
    schema: 'kyc',
    data: { verified: true },
  });
} catch (error) {
  if (error.code === 'INVALID_SCHEMA') {
    console.log('Schema not found or invalid');
  } else if (error.code === 'UNAUTHORIZED') {
    console.log('Not authorized to create attestations');
  } else if (error.code === 'INSUFFICIENT_GAS') {
    console.log('Not enough gas for on-chain attestation');
  } else {
    console.error('Error creating attestation:', error);
  }
}

TypeScript Types

interface Attestation {
  id: string;
  schema: string;
  attester: string;
  subject: string;
  data: Record<string, any>;
  createdAt: string;
  expiresAt?: string;
  revoked: boolean;
  onChain: boolean;
  txHash?: string;
  refUID?: string;
}

interface TrustModule {
  id: string;
  name: string;
  description: string;
  schema: Record<string, string>;
  attesters: string[];
  attestationCount: number;
}

interface PolicyEvaluation {
  passed: boolean;
  score: number;
  results: PolicyResult[];
  missingSchemas: string[];
  expiredAttestations: string[];
}

Best Practices

  1. Use On-Chain for Critical Trust: Store important attestations on-chain for immutability
  2. Set Expiration Dates: Most attestations should expire and require renewal
  3. Validate Schema: Ensure data matches the expected schema
  4. Monitor Revocations: Check for revoked attestations before trusting
  5. Multi-Sig for High Value: Require multiple attesters for critical verifications

Next Steps