SDK Guide
The official TypeScript/JavaScript SDK for the OP Protocol API. Works in Node.js 18+ and modern browsers.
Installation
npm install @op-protocol/sdkThe SDK includes TypeScript definitions out of the box. Types are also available separately via @op-protocol/types.
Configuration
import { createClient } from '@op-protocol/sdk';
const op = createClient({
baseUrl: 'https://originalpictures.cc',
apiKey: 'op_beta_...', // optional
timeout: 30000 // default: 30s
});| Option | Type | Required | Description |
|---|---|---|---|
| baseUrl | string | Yes | API base URL |
| apiKey | string | No | API key for higher rate limits |
| timeout | number | No | Request timeout in ms (default: 30000) |
Methods
signMedia(file, options?)→ Promise<SignResult>Sign a file with C2PA Content Credentials. Accepts File, Blob, or Buffer.
verifyMedia(file, options?)→ Promise<VerifyResult>Verify a file's C2PA provenance. Returns trust tier, confidence, and manifest.
getTrust(verifyId)→ Promise<TrustState>Look up a cached verification result by its verifyId.
getBadgeUrl(verifyId, options?)→ stringGenerate a badge URL for embedding. Supports svg, html, json formats.
batchSign(files)→ Promise<BatchStatus>Sign multiple files asynchronously. Returns a batchId for polling.
batchVerify(files)→ Promise<BatchStatus>Verify multiple files asynchronously. Returns a batchId for polling.
getBatchStatus(batchId)→ Promise<BatchStatus>Poll the status of a batch operation.
webhooks.create(config)→ Promise<{ id: string }>Register a webhook URL for event notifications.
webhooks.list()→ Promise<WebhookConfig[]>List all registered webhooks.
webhooks.update(id, config)→ Promise<void>Update a webhook's URL or events.
webhooks.delete(id)→ Promise<void>Delete a webhook registration.
webhooks.deliveries(id)→ Promise<WebhookDelivery[]>View delivery history for a webhook.
TypeScript Types
TrustTier"verified" | "signed" | "recovered" | "unknown" | "unsigned" | "broken"
TrustConfidence"high" | "medium" | "low" | "none"
TrustState{ tier: TrustTier; label: string; description: string; confidence: TrustConfidence; edgeCase: string | null }SignResult{ signedFileUrl: string; original: FileInfo; signed: FileInfo; manifest: ManifestSummary; meta: Meta }VerifyResult{ verifyId: string; trust: TrustState; manifest: ManifestSummary; meta: Meta }BatchStatus{ batchId: string; type: string; fileCount: number; completedCount: number; status: string; results?: any[] }BadgeOptions{ format?: 'svg' | 'html' | 'json'; theme?: 'light' | 'dark'; size?: 'sm' | 'md' | 'lg' }Error Handling
All SDK methods throw OpError on failure.
import { OpError } from '@op-protocol/sdk';
try {
const result = await op.verifyMedia(file);
} catch (err) {
if (err instanceof OpError) {
console.error(err.code); // 'rate_limited'
console.error(err.statusCode); // 429
console.error(err.message); // 'Rate limit exceeded'
console.error(err.details); // { retryAfter: 60 }
}
}Browser Usage
The SDK works in modern browsers using the native Fetch API and FormData. Use it directly with file inputs.
const input = document.querySelector<HTMLInputElement>('#file-input');
const file = input.files[0];
const result = await op.verifyMedia(file);
document.getElementById('result').textContent = result.trust.tier;Node.js Usage
Requires Node.js 18+ (native fetch). Pass Buffer objects directly for file content.
import { createClient } from '@op-protocol/sdk';
import { readFileSync } from 'fs';
const op = createClient({ baseUrl: 'https://originalpictures.cc' });
const buffer = readFileSync('./photo.jpg');
const blob = new Blob([buffer], { type: 'image/jpeg' });
const result = await op.verifyMedia(blob);
console.log(result.trust);