Building Statements

How to map your application data to Fide Statements.

This guide covers how to construct Statements using the SDK.

Protocol Context

Constructing a Statement

Use the createStatement helper. It enforces that you provide all necessary components (the Fide ID and the raw source) so the SDK can validate the hashes.

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

// 1. Calculate IDs for your entities first
const subjectId = await calculateFideId('Person', 'Product', 'https://github.com/alice');
const predicateId = await calculateFideId('CreativeWork', 'CreativeWork', 'schema:follows');
const objectId = await calculateFideId('Person', 'Product', 'https://github.com/bob');

// 2. Build the statement
const statement = await createStatement({
  subject: {
    fideId: subjectId,
    rawIdentifier: 'https://github.com/alice',
    entityType: 'Person',
    sourceType: 'Product'
  },
  predicate: {
    fideId: predicateId,
    rawIdentifier: 'schema:follows',
    entityType: 'CreativeWork', // Predicates are almost always CreativeWorks
    sourceType: 'CreativeWork'
  },
  object: {
    fideId: objectId,
    rawIdentifier: 'https://github.com/bob',
    entityType: 'Person',
    sourceType: 'Product'
  }
});

Batch Processing

If you are processing thousands of items, calculating IDs one-by-one can be tedious. Use buildStatementBatch to handle arrays efficiently.

import { buildStatementBatch } from '@fide.work/fcp';

const users = [
  { id: 'alice', follows: 'bob' },
  { id: 'bob', follows: 'charlie' }
];

const statements = await buildStatementBatch(
    // Map your custom data to the StatementInput format
    users.map(user => ({
        subject: { 
            rawIdentifier: `https://app.com/${user.id}`, 
            entityType: 'Person', 
            sourceType: 'Product' 
        },
        predicate: { 
            rawIdentifier: 'schema:follows', 
            entityType: 'CreativeWork', 
            sourceType: 'CreativeWork' 
        },
        object: { 
            rawIdentifier: `https://app.com/${user.follows}`, 
            entityType: 'Person', 
            sourceType: 'Product' 
        }
    }))
);

// 'statements' is now an array of complete Statement objects with calculated Fide IDs

On this page