Quickstart

Create and sign your first Fide Attestation in under 5 minutes.

This guide will walk you through the core loop of the Fide Context Protocol using the JavaScript SDK: Identify → State → Sign.

Prerequisites

  • Node.js 18+ established in your environment.

Implementation

Install the SDK

npm install @fide.work/fcp
pnpm add @fide.work/fcp
yarn add @fide.work/fcp
bun add @fide.work/fcp

Create a Statement

First, we calculate the deterministic Fide IDs for the entities involved (Subject, Predicate, Object) and combine them into a Statement.

index.ts
import { 
  calculateFideId, 
  createStatement,
} from '@fide.work/fcp';

// 1. Define your Entities
// Subject: A person (Alice) identified by her X profile
const aliceId = await calculateFideId('Person', 'Product', 'https://x.com/alice');

// Predicate: The concept of a "name" from Schema.org
// Note: Predicates are usually type 'CreativeWork' (6) with source 'CreativeWork' (6)
const namePredicateId = await calculateFideId('CreativeWork', 'CreativeWork', 'schema:name');

// Object: The literal value "Alice"
const nameValueId = await calculateFideId('CreativeWork', 'CreativeWork', 'Alice');

// 2. Create the Statement
// We provide raw identifiers so the SDK can validate the hashes internally.
const statement = await createStatement({
  subject: { 
    fideId: aliceId, 
    rawIdentifier: 'https://x.com/alice',
    entityType: 'Person', 
    sourceType: 'Product' 
  },
  predicate: { 
    fideId: namePredicateId, 
    rawIdentifier: 'schema:name',
    entityType: 'CreativeWork', 
    sourceType: 'CreativeWork'
  },
  object: { 
    fideId: nameValueId, 
    rawIdentifier: 'Alice',
    entityType: 'CreativeWork', 
    sourceType: 'CreativeWork'
  }
});

console.log('Statement ID:', statement.statementFideId);

Sign an Attestation

Now we wrap that statement in a cryptographic Attestation. This proves you asserted this statement.

index.ts
import { 
  generateEd25519KeyPair, 
  exportEd25519Keys,
  createAttestation, 
  signEd25519 
} from '@fide.work/fcp';

// ... (previous code)

// 3. Setup a Signer (Ed25519)
const keyPair = await generateEd25519KeyPair();
const exported = await exportEd25519Keys(keyPair);
const signerId = `ed25519::${exported.address}`;

// 4. Create the Attestation
// This builds a Merkle tree of statements (just one here) and signs the root.
const attestation = await createAttestation(
  [statement.statementFideId!], 
  {
    method: 'ed25519',
    caip10User: signerId,
    sign: (root) => signEd25519(root, keyPair.privateKey)
  }
);

console.log('Attestation ID:', attestation.attestationFideId);
console.log('Signature:', attestation.attestationData.s);

Format for Publishing

Finally, format the attestation for the Fide Registry format (JSONL).

index.ts
import { formatAttestationForJSONL } from '@fide.work/fcp';

// ... (previous code)

// 5. Format for Registry
const jsonlLine = formatAttestationForJSONL(attestation, [statement]);

console.log(JSON.stringify(jsonlLine, null, 0));

The output is a single line of JSON ready to be appended to a registry file.

Next Steps

On this page