@xproof/xproof 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +315 -0
- package/package.json +8 -3
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# xproof
|
|
2
2
|
|
|
3
|
+
[](https://github.com/jasonxkensei/xproof/actions/workflows/npm-sdk.yml) [](https://www.npmjs.com/package/@xproof/xproof) [](https://www.typescriptlang.org/)
|
|
4
|
+
|
|
3
5
|
On-chain decision provenance for autonomous agents. **WHY before acting. WHAT after.** Timestamps written by the chain, not your agent.
|
|
4
6
|
|
|
5
7
|
```bash
|
|
@@ -161,6 +163,312 @@ const proof = await client.verifyHash(fileHash);
|
|
|
161
163
|
console.log(proof.blockchainStatus); // "confirmed" | "pending"
|
|
162
164
|
```
|
|
163
165
|
|
|
166
|
+
## Policy Compliance
|
|
167
|
+
|
|
168
|
+
Check whether a decision meets governance requirements — without fetching the full confidence trail:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { XProofClient } from "@xproof/xproof";
|
|
172
|
+
import type { PolicyCheckResult } from "@xproof/xproof";
|
|
173
|
+
|
|
174
|
+
const client = new XProofClient({ apiKey: "pm_your_key" });
|
|
175
|
+
|
|
176
|
+
const result: PolicyCheckResult = await client.getPolicyCheck("trade-xyz-2026");
|
|
177
|
+
|
|
178
|
+
if (result.policyCompliant) {
|
|
179
|
+
console.log("Decision is compliant.");
|
|
180
|
+
} else {
|
|
181
|
+
for (const v of result.policyViolations) {
|
|
182
|
+
console.log(`VIOLATION — ${v.rule}`);
|
|
183
|
+
console.log(` proof: ${v.proofId}`);
|
|
184
|
+
console.log(` confidence: ${v.confidenceLevel} (required: ${v.threshold})`);
|
|
185
|
+
console.log(` class: ${v.reversibilityClass}`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
`getPolicyCheck()` is a lightweight yes/no compliance check. It returns `result.policyCompliant` (boolean) and `result.policyViolations` (array). For the full audit trail including timestamps and intermediate confidence checkpoints, use `getConfidenceTrail()` instead.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Timing Breakdown
|
|
195
|
+
|
|
196
|
+
Anchor the full decision chronology on-chain alongside the confidence anchor. Three ISO8601 timestamps mark **when the instruction arrived**, **when reasoning began**, and **when the action fired**. A `jurisdictionType` field records who was accountable for the decision.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { XProofClient, hashString, JURISDICTION_TYPES } from "@xproof/xproof";
|
|
200
|
+
import type { TimingBreakdown } from "@xproof/xproof";
|
|
201
|
+
|
|
202
|
+
const client = new XProofClient({ apiKey: "pm_your_key" });
|
|
203
|
+
|
|
204
|
+
const instructionReceivedAt = new Date().toISOString();
|
|
205
|
+
// ... agent reasons ...
|
|
206
|
+
const reasoningStartedAt = new Date().toISOString();
|
|
207
|
+
// ... reasoning completes, agent executes ...
|
|
208
|
+
const actionTakenAt = new Date().toISOString();
|
|
209
|
+
|
|
210
|
+
const timing: TimingBreakdown = {
|
|
211
|
+
instructionReceivedAt,
|
|
212
|
+
reasoningStartedAt,
|
|
213
|
+
actionTakenAt,
|
|
214
|
+
jurisdictionType: "autonomous_inference", // agent reached its own conclusion
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const cert = await client.certifyWithConfidence(
|
|
218
|
+
hashString(JSON.stringify({ action: "approve_transfer", amount: 50_000 })),
|
|
219
|
+
"transfer-decision.json",
|
|
220
|
+
"treasury-agent",
|
|
221
|
+
{
|
|
222
|
+
confidenceLevel: 0.97,
|
|
223
|
+
thresholdStage: "final",
|
|
224
|
+
decisionId: "transfer-xyz-2026",
|
|
225
|
+
reversibilityClass: "irreversible",
|
|
226
|
+
timing,
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
// cert.timingBreakdown is populated in the API response:
|
|
231
|
+
console.log(cert.timingBreakdown?.reasoningDurationMs); // ms between reasoning_started_at and action_taken_at
|
|
232
|
+
console.log(cert.timingBreakdown?.totalDurationMs); // ms between instruction_received_at and action_taken_at
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### `jurisdictionType` values
|
|
236
|
+
|
|
237
|
+
| Value | Meaning | Who bears accountability |
|
|
238
|
+
|---|---|---|
|
|
239
|
+
| `"instruction_following"` | Agent executed an explicit human instruction | Principal (human) |
|
|
240
|
+
| `"autonomous_inference"` | Agent reached its own conclusion | Agent and its operator |
|
|
241
|
+
| `"human_approved"` | Agent recommended, human approved before action | Shared |
|
|
242
|
+
|
|
243
|
+
All valid values are exported as the `JURISDICTION_TYPES` constant for runtime validation:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
import { JURISDICTION_TYPES } from "@xproof/xproof";
|
|
247
|
+
|
|
248
|
+
// ["instruction_following", "autonomous_inference", "human_approved"]
|
|
249
|
+
console.log(JURISDICTION_TYPES);
|
|
250
|
+
|
|
251
|
+
// Runtime guard
|
|
252
|
+
function isValidJurisdiction(s: string): boolean {
|
|
253
|
+
return (JURISDICTION_TYPES as readonly string[]).includes(s);
|
|
254
|
+
}
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### Reading timing data back
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
const cert = await client.verify("certification-uuid");
|
|
261
|
+
|
|
262
|
+
if (cert.timingBreakdown) {
|
|
263
|
+
const { instructionReceivedAt, reasoningDurationMs, totalDurationMs } = cert.timingBreakdown;
|
|
264
|
+
console.log(`Instruction at: ${instructionReceivedAt}`);
|
|
265
|
+
console.log(`Reasoning took: ${reasoningDurationMs}ms`);
|
|
266
|
+
console.log(`Total latency: ${totalDurationMs}ms`);
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
> All four fields (`instructionReceivedAt`, `reasoningStartedAt`, `actionTakenAt`, `jurisdictionType`) are optional — you can anchor whichever timestamps are available. `reasoningDurationMs` and `totalDurationMs` are computed server-side and appear only in responses, never in requests.
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Governance & Policy Enforcement
|
|
275
|
+
|
|
276
|
+
xProof detects automatically when an agent acted with insufficient confidence on an irreversible action — and writes the evidence on-chain before you ever open an incident report.
|
|
277
|
+
|
|
278
|
+
### Mark decisions as reversible, costly, or irreversible
|
|
279
|
+
|
|
280
|
+
Add `reversibilityClass` to any certified action. The server enforces a policy: **irreversible actions require `confidenceLevel >= 0.95`**. Anything below that threshold generates a policy violation anchored to the chain.
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import { XProofClient, hashString } from "@xproof/xproof";
|
|
284
|
+
|
|
285
|
+
const client = new XProofClient({ apiKey: "pm_..." });
|
|
286
|
+
|
|
287
|
+
// An agent is about to execute a trade it cannot undo.
|
|
288
|
+
// It certifies its reasoning at 0.72 confidence — below the 0.95 threshold.
|
|
289
|
+
const cert = await client.certifyWithConfidence(
|
|
290
|
+
hashString(JSON.stringify({ action: "sell", ticker: "AAPL", qty: 500 })),
|
|
291
|
+
"trade-decision.json",
|
|
292
|
+
"trading-agent",
|
|
293
|
+
{
|
|
294
|
+
confidenceLevel: 0.72, // Agent's self-assessed confidence
|
|
295
|
+
thresholdStage: "pre-commitment",
|
|
296
|
+
decisionId: "trade-xyz-2026",
|
|
297
|
+
reversibilityClass: "irreversible", // This action cannot be undone
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
// cert.reversibilityClass === "irreversible"
|
|
302
|
+
// The server has recorded a policy violation: 0.72 < 0.95 required
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### Check compliance — without fetching the full trail
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
import type { PolicyCheckResult } from "@xproof/xproof";
|
|
309
|
+
|
|
310
|
+
const check: PolicyCheckResult = await client.getPolicyCheck("trade-xyz-2026");
|
|
311
|
+
|
|
312
|
+
if (!check.policyCompliant) {
|
|
313
|
+
for (const v of check.policyViolations) {
|
|
314
|
+
console.log(`VIOLATION — ${v.rule}`);
|
|
315
|
+
console.log(` proof: ${v.proofId}`);
|
|
316
|
+
console.log(` confidence: ${v.confidenceLevel} (required: ${v.threshold})`);
|
|
317
|
+
console.log(` class: ${v.reversibilityClass}`);
|
|
318
|
+
// → VIOLATION — irreversible actions require confidence_level >= 0.95
|
|
319
|
+
// → proof: abc-uuid
|
|
320
|
+
// → confidence: 0.72 (required: 0.95)
|
|
321
|
+
// → class: irreversible
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### Full confidence trail with policy result
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
const trail = await client.getConfidenceTrail("trade-xyz-2026");
|
|
330
|
+
|
|
331
|
+
console.log(trail.policyCompliant); // false
|
|
332
|
+
console.log(trail.policyViolations.length); // 1
|
|
333
|
+
console.log(trail.currentConfidence); // 0.72
|
|
334
|
+
console.log(trail.isFinalized); // false — decision still open
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Observability — surfacing violations in dashboards
|
|
338
|
+
|
|
339
|
+
Throwing an error is enough to halt execution, but it gives your observability
|
|
340
|
+
stack nothing structured to alert on. The pattern below emits a
|
|
341
|
+
machine-readable JSON log line for each violation and optionally fires a
|
|
342
|
+
webhook, so Datadog / Grafana / CloudWatch log-based alerts can pick up
|
|
343
|
+
violations without grepping free-form text.
|
|
344
|
+
|
|
345
|
+
```typescript
|
|
346
|
+
import { XProofClient } from "@xproof/xproof";
|
|
347
|
+
import type { PolicyViolation } from "@xproof/xproof";
|
|
348
|
+
|
|
349
|
+
const client = new XProofClient({ apiKey: "pm_..." });
|
|
350
|
+
const decisionId = "trade-xyz-2026"; // the decision ID passed to certifyWithConfidence()
|
|
351
|
+
|
|
352
|
+
// Optional: set a webhook URL to receive violation payloads
|
|
353
|
+
const VIOLATION_WEBHOOK_URL: string | null = null; // e.g. "https://hooks.example.com/compliance"
|
|
354
|
+
|
|
355
|
+
async function emitViolation(decisionId: string, violation: PolicyViolation): Promise<void> {
|
|
356
|
+
const payload = {
|
|
357
|
+
event: "policy_violation",
|
|
358
|
+
decision_id: decisionId,
|
|
359
|
+
rule: violation.rule,
|
|
360
|
+
proof_id: violation.proofId,
|
|
361
|
+
confidence_level: violation.confidenceLevel,
|
|
362
|
+
threshold: violation.threshold,
|
|
363
|
+
reversibility_class: violation.reversibilityClass,
|
|
364
|
+
threshold_stage: violation.thresholdStage,
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// ── Structured JSON log (ingested by Datadog / CloudWatch / Loki) ─────────
|
|
368
|
+
// console.error writes to stderr, which log shippers (Fluentd, the Datadog
|
|
369
|
+
// Agent, the CloudWatch agent) forward verbatim.
|
|
370
|
+
// Drop-in replacements: pino.error(payload) emits NDJSON with no extra
|
|
371
|
+
// config; for winston, configure a JSON transport first (e.g.
|
|
372
|
+
// `winston.createLogger({ format: winston.format.json(), ... })`), then
|
|
373
|
+
// call logger.error(payload) to get the same single-line JSON output.
|
|
374
|
+
console.error(JSON.stringify(payload));
|
|
375
|
+
|
|
376
|
+
// ── Optional webhook / alerting callback (best-effort) ───────────────────
|
|
377
|
+
if (VIOLATION_WEBHOOK_URL) {
|
|
378
|
+
try {
|
|
379
|
+
await fetch(VIOLATION_WEBHOOK_URL, {
|
|
380
|
+
method: "POST",
|
|
381
|
+
headers: { "Content-Type": "application/json" },
|
|
382
|
+
body: JSON.stringify(payload),
|
|
383
|
+
signal: AbortSignal.timeout(5000), // fire-and-forget; add retry logic as needed
|
|
384
|
+
});
|
|
385
|
+
} catch (exc) {
|
|
386
|
+
// Best-effort delivery — a webhook failure must NOT swallow the
|
|
387
|
+
// compliance violation itself. Log and continue to the throw below.
|
|
388
|
+
console.warn(JSON.stringify({ event: "webhook_error", detail: String(exc) }));
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const check = await client.getPolicyCheck(decisionId);
|
|
394
|
+
|
|
395
|
+
if (!check.policyCompliant) {
|
|
396
|
+
for (const v of check.policyViolations) {
|
|
397
|
+
await emitViolation(decisionId, v);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// ── Full audit trail for post-mortem / SIEM export ────────────────────────
|
|
401
|
+
// getConfidenceTrail() returns a ConfidenceTrail object containing every
|
|
402
|
+
// certification event — confidence levels, timestamps, transaction hashes —
|
|
403
|
+
// so you can attach the complete chain-of-evidence to an incident ticket or
|
|
404
|
+
// ship it to your SIEM without a separate lookup.
|
|
405
|
+
// Note: redact sensitive fields from trail.stages before logging or
|
|
406
|
+
// exporting to centralised logs / SIEM in production environments.
|
|
407
|
+
const trail = await client.getConfidenceTrail(decisionId);
|
|
408
|
+
console.error(JSON.stringify({
|
|
409
|
+
event: "audit_trail",
|
|
410
|
+
decision_id: decisionId,
|
|
411
|
+
current_confidence: trail.currentConfidence,
|
|
412
|
+
is_finalized: trail.isFinalized,
|
|
413
|
+
total_anchors: trail.totalAnchors,
|
|
414
|
+
stages: trail.stages,
|
|
415
|
+
}));
|
|
416
|
+
|
|
417
|
+
throw new Error("Action aborted: policy compliance check failed.");
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
Each `console.error(JSON.stringify(...))` call writes a single-line JSON object
|
|
422
|
+
that log shippers (Fluentd, the Datadog Agent, the CloudWatch agent) forward
|
|
423
|
+
verbatim. Create a log-based metric or alert on `event = "policy_violation"` to
|
|
424
|
+
get dashboard counts and threshold alerts with no extra instrumentation.
|
|
425
|
+
|
|
426
|
+
#### Drop-in: pino
|
|
427
|
+
|
|
428
|
+
Replace `console.error(JSON.stringify(payload))` with a single `pino` call — no extra config needed, pino emits NDJSON by default:
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
import pino from "pino";
|
|
432
|
+
|
|
433
|
+
const logger = pino();
|
|
434
|
+
|
|
435
|
+
// inside emitViolation():
|
|
436
|
+
logger.error(payload); // emits: {"level":50,"time":...,"rule":"...","event":"policy_violation",...}
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
#### Drop-in: winston
|
|
440
|
+
|
|
441
|
+
Configure a JSON transport once, then call `logger.error(payload)` to get the same single-line JSON output:
|
|
442
|
+
|
|
443
|
+
```typescript
|
|
444
|
+
import winston from "winston";
|
|
445
|
+
|
|
446
|
+
const logger = winston.createLogger({
|
|
447
|
+
level: "error",
|
|
448
|
+
format: winston.format.json(),
|
|
449
|
+
transports: [new winston.transports.Console({ stderrLevels: ["error"] })],
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// inside emitViolation():
|
|
453
|
+
logger.error("policy_violation", payload);
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Both emit a single JSON line per violation — identical in structure to the `console.error` version above.
|
|
457
|
+
|
|
458
|
+
> **Runnable example** — `examples/observability.ts` in this repo demonstrates the full pattern (violation detection, structured logging, webhook delivery, audit trail) with a mock client. Run it with `npx tsx examples/observability.ts`.
|
|
459
|
+
|
|
460
|
+
### Three classes, one parameter
|
|
461
|
+
|
|
462
|
+
| `reversibilityClass` | What it means | Policy threshold |
|
|
463
|
+
|---|---|---|
|
|
464
|
+
| `"reversible"` | Action can be undone (e.g. draft, preview) | None — any confidence accepted |
|
|
465
|
+
| `"costly"` | Undoable but expensive (e.g. API call, DB write) | None — any confidence accepted |
|
|
466
|
+
| `"irreversible"` | Cannot be undone (e.g. trade, deletion, send) | `confidenceLevel >= 0.95` required |
|
|
467
|
+
|
|
468
|
+
> The threshold is configured server-side (`IRREVERSIBLE_CONFIDENCE_THRESHOLD=0.95`). All violations are written on-chain and cannot be amended.
|
|
469
|
+
|
|
470
|
+
---
|
|
471
|
+
|
|
164
472
|
## Pricing
|
|
165
473
|
|
|
166
474
|
```typescript
|
|
@@ -208,11 +516,18 @@ try {
|
|
|
208
516
|
| `XProofClient.register(agentName)` | Register agent, get trial key |
|
|
209
517
|
| `certify(path, author, fileName?, fourW?)` | Certify file (hashes locally) |
|
|
210
518
|
| `certifyHash(hash, name, author, fourW?)` | Certify by pre-computed hash |
|
|
519
|
+
| `certifyWithConfidence(hash, name, author, opts)` | Certify with confidence + governance class |
|
|
211
520
|
| `batchCertify(files)` | Batch certify (up to 50) |
|
|
212
521
|
| `verify(proofId)` | Look up by proof ID |
|
|
213
522
|
| `verifyHash(fileHash)` | Look up by file hash |
|
|
523
|
+
| `getConfidenceTrail(decisionId)` | Full trail with `policyCompliant` + violations |
|
|
524
|
+
| `getPolicyCheck(decisionId)` | Lightweight compliance check — no full trail |
|
|
214
525
|
| `getPricing()` | Get current pricing |
|
|
215
526
|
|
|
527
|
+
## Contributing
|
|
528
|
+
|
|
529
|
+
If you use VS Code, install the [ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) (`dbaeumer.vscode-eslint`). The repo includes `.vscode/settings.json` that configures ESLint as the default formatter and runs `eslint --fix`, organise-imports, and remove-unused-imports automatically on every save. VS Code will prompt you to install the recommended extension when you open the folder.
|
|
530
|
+
|
|
216
531
|
## Links
|
|
217
532
|
|
|
218
533
|
- [xproof.app](https://xproof.app) — dashboard & docs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xproof/xproof",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Official SDK for the xProof blockchain certification API — proof and accountability layer for autonomous agents",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -34,10 +34,12 @@
|
|
|
34
34
|
],
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsup",
|
|
37
|
+
"typecheck": "tsc --noEmit",
|
|
38
|
+
"lint": "eslint src",
|
|
39
|
+
"lint:fix": "eslint src --fix",
|
|
37
40
|
"test": "vitest run",
|
|
38
41
|
"test:watch": "vitest",
|
|
39
|
-
"prepublishOnly": "npm run build"
|
|
40
|
-
"release": "npm publish --access public"
|
|
42
|
+
"prepublishOnly": "npm run build"
|
|
41
43
|
},
|
|
42
44
|
"keywords": [
|
|
43
45
|
"xproof",
|
|
@@ -60,6 +62,9 @@
|
|
|
60
62
|
"node": ">=18.0.0"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
65
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
66
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
67
|
+
"eslint": "^9.0.0",
|
|
63
68
|
"tsup": "^8.0.0",
|
|
64
69
|
"typescript": "^5.0.0",
|
|
65
70
|
"vitest": "^2.0.0"
|