JavaScript / TypeScript SDK
@proofledger/sdk — Node 18+, ESM + CJS, TypeScript types included, zero runtime dependencies.
Configuration
import { ProofLedger } from "@proofledger/sdk";
ProofLedger.enable({
apiKey: process.env.PROOFLEDGER_API_KEY, // omit → local dev mode (JSONL log)
baseUrl: "https://www.proofledger.dev",
environment: "production", // development | staging | production
// Trust-platform defaults (used by registerAgent + log*)
agentName: "support-agent",
owner: "customer-success",
framework: "langchain",
model: "gpt-4.1",
version: "1.0.0",
// monitor (default): observe only. enforce: block + gate on approvals.
policyMode: "enforce",
approvalIntervalMs: 2000, // poll cadence while waiting on a human
approvalTimeoutMs: 300_000, // fail closed after 5 minutes
});Note
Without an apiKey the SDK runs in local mode: events append to ./.proofledger/events.jsonl, policies always allow, approvals auto-approve. Perfect for tests and CI.
Trust platform methods
// Identity
const { agent, privateKey } = await ProofLedger.registerAgent();
ProofLedger.identifyAgent("support-agent", storedPrivateKey);
// Logging — each returns { event, policy, trust }
await ProofLedger.logDecision({ action, workflowId, inputSummary, outputSummary });
await ProofLedger.logToolCall({ toolName, toolType, mcpServer, workflowId });
await ProofLedger.logApiCall({ apiEndpoint, workflowId });
await ProofLedger.logWorkflowStep({ workflowId, action, status }); // "completed" | "failed"
await ProofLedger.logTrustEvent({ eventType, eventCategory, action, sensitiveAction, metadata });
// Model provenance (0.5.0) — which model actually executed; free-form provider
await ProofLedger.recordModelExecution({
provider, modelName, hostingRegion, inputTokens, outputTokens,
estimatedCostUsd, latencyMs, fallbackUsed, fallbackReason,
});
await ProofLedger.recordAgentVersion({ version, systemPromptVersion, modelRouting });
// Outcomes (0.5.0) — verificationMethod is REQUIRED, never self-declared
await ProofLedger.recordOutcome({
taskType, status, verificationMethod, businessValueEstimate,
});
// Governance
const evaluation = await ProofLedger.evaluatePolicy({ toolName, sensitiveAction });
await ProofLedger.requireApproval({ agentId, title, detail }); // explicit human gate
// Signals
const trust = await ProofLedger.getTrustScore();
// Crypto primitives (offline)
import { createAgentIdentity, signEvent, verifyEvent } from "@proofledger/sdk";
// Lifecycle
await ProofLedger.flush();Errors (enforce mode)
import { PolicyBlockedError, ApprovalDeniedError } from "@proofledger/sdk";
try {
await ProofLedger.logToolCall({ toolName: "wire_transfer", sensitiveAction: true });
} catch (err) {
if (err instanceof PolicyBlockedError) err.evaluation; // why it was blocked
if (err instanceof ApprovalDeniedError) err.status; // "denied" | "pending" (timeout)
}LLM run tracing & adapters
The SDK also captures full LLM runs (latency, tokens, cost) with the same tamper-evident chains:
// Wrap any unit of work as a traced run
await ProofLedger.withRun(
{ agentId: "support-agent", model: "gpt-4.1", provider: "openai" },
async (run) => {
await run.recordToolCall({ toolName: "search", input: { q: "…" } });
await run.recordModelExecution({ provider: "openai", modelName: "gpt-4.1" });
await run.recordOutcome({ status: "success", verificationMethod: "deterministic" });
return await myAgent.run("Resolve ticket #4821");
}
);
// One-line adapters
import { wrapOpenAI, wrapAnthropic, createLangChainHandler } from "@proofledger/sdk";
const openai = wrapOpenAI(new OpenAI(), { agentId: "support-agent" });
const anthropic = wrapAnthropic(new Anthropic(), { agentId: "support-agent" });
// ^ records a model execution per call (provenance by default)
await chain.invoke(input, { callbacks: [createLangChainHandler({ agentId: "support-agent" })] });