@xproof/xproof 0.1.6 → 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/dist/{client-DrHsmqL6.d.mts → client-CWrki-T_.d.mts} +19 -1
- package/dist/{client-DrHsmqL6.d.ts → client-CWrki-T_.d.ts} +19 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +43 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -1
- package/dist/index.mjs.map +1 -1
- package/dist/integrations/vercel.d.mts +1 -1
- package/dist/integrations/vercel.d.ts +1 -1
- package/dist/integrations/vercel.js +43 -1
- package/dist/integrations/vercel.js.map +1 -1
- package/dist/integrations/vercel.mjs +43 -1
- package/dist/integrations/vercel.mjs.map +1 -1
- 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
|
|
@@ -112,6 +112,14 @@ interface ConfidenceTrail {
|
|
|
112
112
|
contextDrift: ConfidenceTrailDrift | null;
|
|
113
113
|
stages: ConfidenceTrailStage[];
|
|
114
114
|
}
|
|
115
|
+
interface PolicyCheckResult {
|
|
116
|
+
decisionId: string;
|
|
117
|
+
totalAnchors: number;
|
|
118
|
+
policyCompliant: boolean;
|
|
119
|
+
policyViolations: PolicyViolation[];
|
|
120
|
+
checkedAt: string;
|
|
121
|
+
raw: Record<string, unknown>;
|
|
122
|
+
}
|
|
115
123
|
interface BatchFileEntry {
|
|
116
124
|
fileHash: string;
|
|
117
125
|
fileName?: string;
|
|
@@ -167,8 +175,18 @@ declare class XProofClient {
|
|
|
167
175
|
getContextDrift(decisionId: string): Promise<ContextDrift>;
|
|
168
176
|
getPricing(): Promise<PricingInfo>;
|
|
169
177
|
private requireAuth;
|
|
178
|
+
/**
|
|
179
|
+
* Check policy compliance for a decision chain without fetching the full trail.
|
|
180
|
+
*
|
|
181
|
+
* Calls `GET /api/proofs/policy-check?decision_id=<id>` and returns a lightweight
|
|
182
|
+
* compliance report: whether the chain is policy-compliant and any violations found.
|
|
183
|
+
*
|
|
184
|
+
* @param decisionId - The shared decision chain identifier.
|
|
185
|
+
* @returns A `PolicyCheckResult` with `policyCompliant`, `policyViolations`, and metadata.
|
|
186
|
+
*/
|
|
187
|
+
getPolicyCheck(decisionId: string): Promise<PolicyCheckResult>;
|
|
170
188
|
private request;
|
|
171
189
|
private handleError;
|
|
172
190
|
}
|
|
173
191
|
|
|
174
|
-
export { type BatchFileEntry as B, type Certification as C, type ExecutionContext as E, type FourWOptions as F, type
|
|
192
|
+
export { type BatchFileEntry as B, type Certification as C, type ExecutionContext as E, type FourWOptions as F, type PolicyCheckResult as P, type RegistrationResult as R, type ThresholdStage as T, XProofClient as X, type BatchResult as a, type BatchResultSummary as b, type CertifyHashOptions as c, type ConfidenceOptions as d, type ConfidenceTrail as e, type ConfidenceTrailDrift as f, type ConfidenceTrailStage as g, type ContextDrift as h, type ContextDriftStage as i, type PolicyViolation as j, type PricingInfo as k, type PricingTier as l, type ReversibilityClass as m, type TrialInfo as n, type XProofClientOptions as o };
|
|
@@ -112,6 +112,14 @@ interface ConfidenceTrail {
|
|
|
112
112
|
contextDrift: ConfidenceTrailDrift | null;
|
|
113
113
|
stages: ConfidenceTrailStage[];
|
|
114
114
|
}
|
|
115
|
+
interface PolicyCheckResult {
|
|
116
|
+
decisionId: string;
|
|
117
|
+
totalAnchors: number;
|
|
118
|
+
policyCompliant: boolean;
|
|
119
|
+
policyViolations: PolicyViolation[];
|
|
120
|
+
checkedAt: string;
|
|
121
|
+
raw: Record<string, unknown>;
|
|
122
|
+
}
|
|
115
123
|
interface BatchFileEntry {
|
|
116
124
|
fileHash: string;
|
|
117
125
|
fileName?: string;
|
|
@@ -167,8 +175,18 @@ declare class XProofClient {
|
|
|
167
175
|
getContextDrift(decisionId: string): Promise<ContextDrift>;
|
|
168
176
|
getPricing(): Promise<PricingInfo>;
|
|
169
177
|
private requireAuth;
|
|
178
|
+
/**
|
|
179
|
+
* Check policy compliance for a decision chain without fetching the full trail.
|
|
180
|
+
*
|
|
181
|
+
* Calls `GET /api/proofs/policy-check?decision_id=<id>` and returns a lightweight
|
|
182
|
+
* compliance report: whether the chain is policy-compliant and any violations found.
|
|
183
|
+
*
|
|
184
|
+
* @param decisionId - The shared decision chain identifier.
|
|
185
|
+
* @returns A `PolicyCheckResult` with `policyCompliant`, `policyViolations`, and metadata.
|
|
186
|
+
*/
|
|
187
|
+
getPolicyCheck(decisionId: string): Promise<PolicyCheckResult>;
|
|
170
188
|
private request;
|
|
171
189
|
private handleError;
|
|
172
190
|
}
|
|
173
191
|
|
|
174
|
-
export { type BatchFileEntry as B, type Certification as C, type ExecutionContext as E, type FourWOptions as F, type
|
|
192
|
+
export { type BatchFileEntry as B, type Certification as C, type ExecutionContext as E, type FourWOptions as F, type PolicyCheckResult as P, type RegistrationResult as R, type ThresholdStage as T, XProofClient as X, type BatchResult as a, type BatchResultSummary as b, type CertifyHashOptions as c, type ConfidenceOptions as d, type ConfidenceTrail as e, type ConfidenceTrailDrift as f, type ConfidenceTrailStage as g, type ContextDrift as h, type ContextDriftStage as i, type PolicyViolation as j, type PricingInfo as k, type PricingTier as l, type ReversibilityClass as m, type TrialInfo as n, type XProofClientOptions as o };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BatchFileEntry, a as BatchResult, b as BatchResultSummary, C as Certification, c as CertifyHashOptions, d as ConfidenceOptions, e as ConfidenceTrail, f as ConfidenceTrailDrift, g as ConfidenceTrailStage, h as ContextDrift, i as ContextDriftStage, E as ExecutionContext, F as FourWOptions, P as
|
|
1
|
+
export { B as BatchFileEntry, a as BatchResult, b as BatchResultSummary, C as Certification, c as CertifyHashOptions, d as ConfidenceOptions, e as ConfidenceTrail, f as ConfidenceTrailDrift, g as ConfidenceTrailStage, h as ContextDrift, i as ContextDriftStage, E as ExecutionContext, F as FourWOptions, P as PolicyCheckResult, j as PolicyViolation, k as PricingInfo, l as PricingTier, R as RegistrationResult, m as ReversibilityClass, T as ThresholdStage, n as TrialInfo, X as XProofClient, o as XProofClientOptions } from './client-CWrki-T_.mjs';
|
|
2
2
|
|
|
3
3
|
declare class XProofError extends Error {
|
|
4
4
|
statusCode: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BatchFileEntry, a as BatchResult, b as BatchResultSummary, C as Certification, c as CertifyHashOptions, d as ConfidenceOptions, e as ConfidenceTrail, f as ConfidenceTrailDrift, g as ConfidenceTrailStage, h as ContextDrift, i as ContextDriftStage, E as ExecutionContext, F as FourWOptions, P as
|
|
1
|
+
export { B as BatchFileEntry, a as BatchResult, b as BatchResultSummary, C as Certification, c as CertifyHashOptions, d as ConfidenceOptions, e as ConfidenceTrail, f as ConfidenceTrailDrift, g as ConfidenceTrailStage, h as ContextDrift, i as ContextDriftStage, E as ExecutionContext, F as FourWOptions, P as PolicyCheckResult, j as PolicyViolation, k as PricingInfo, l as PricingTier, R as RegistrationResult, m as ReversibilityClass, T as ThresholdStage, n as TrialInfo, X as XProofClient, o as XProofClientOptions } from './client-CWrki-T_.js';
|
|
2
2
|
|
|
3
3
|
declare class XProofError extends Error {
|
|
4
4
|
statusCode: number;
|
package/dist/index.js
CHANGED
|
@@ -171,7 +171,7 @@ function parseRegistrationResult(data) {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
// src/client.ts
|
|
174
|
-
var VERSION = "0.1.
|
|
174
|
+
var VERSION = "0.1.7";
|
|
175
175
|
var DEFAULT_BASE_URL = "https://xproof.app";
|
|
176
176
|
var DEFAULT_TIMEOUT = 3e4;
|
|
177
177
|
var XProofClient = class _XProofClient {
|
|
@@ -268,6 +268,8 @@ var XProofClient = class _XProofClient {
|
|
|
268
268
|
if (fourW?.what !== void 0) metadata.what = fourW.what;
|
|
269
269
|
if (fourW?.when !== void 0) metadata.when = fourW.when;
|
|
270
270
|
if (fourW?.why !== void 0) metadata.why = fourW.why;
|
|
271
|
+
if (fourW?.reversibilityClass !== void 0)
|
|
272
|
+
metadata.reversibility_class = fourW.reversibilityClass;
|
|
271
273
|
metadata.confidence_level = confidence.confidenceLevel;
|
|
272
274
|
metadata.threshold_stage = confidence.thresholdStage;
|
|
273
275
|
metadata.decision_id = confidence.decisionId;
|
|
@@ -375,6 +377,46 @@ var XProofClient = class _XProofClient {
|
|
|
375
377
|
);
|
|
376
378
|
}
|
|
377
379
|
}
|
|
380
|
+
/**
|
|
381
|
+
* Check policy compliance for a decision chain without fetching the full trail.
|
|
382
|
+
*
|
|
383
|
+
* Calls `GET /api/proofs/policy-check?decision_id=<id>` and returns a lightweight
|
|
384
|
+
* compliance report: whether the chain is policy-compliant and any violations found.
|
|
385
|
+
*
|
|
386
|
+
* @param decisionId - The shared decision chain identifier.
|
|
387
|
+
* @returns A `PolicyCheckResult` with `policyCompliant`, `policyViolations`, and metadata.
|
|
388
|
+
*/
|
|
389
|
+
async getPolicyCheck(decisionId) {
|
|
390
|
+
if (!decisionId || !decisionId.trim()) {
|
|
391
|
+
throw new ValidationError("decisionId is required", {});
|
|
392
|
+
}
|
|
393
|
+
const data = await this.request(
|
|
394
|
+
"GET",
|
|
395
|
+
`/api/proofs/policy-check?decision_id=${encodeURIComponent(decisionId)}`,
|
|
396
|
+
{ authRequired: false }
|
|
397
|
+
);
|
|
398
|
+
const violations = (data.policy_violations ?? []).map(
|
|
399
|
+
(v) => {
|
|
400
|
+
const vv = v;
|
|
401
|
+
return {
|
|
402
|
+
proofId: vv.proof_id ?? "",
|
|
403
|
+
confidenceLevel: vv.confidence_level != null ? vv.confidence_level : null,
|
|
404
|
+
reversibilityClass: vv.reversibility_class ?? "reversible",
|
|
405
|
+
thresholdStage: vv.threshold_stage != null ? vv.threshold_stage : null,
|
|
406
|
+
threshold: vv.threshold ?? 0,
|
|
407
|
+
rule: vv.rule ?? ""
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
);
|
|
411
|
+
return {
|
|
412
|
+
decisionId: data.decision_id ?? decisionId,
|
|
413
|
+
totalAnchors: data.total_anchors ?? 0,
|
|
414
|
+
policyCompliant: data.policy_compliant ?? true,
|
|
415
|
+
policyViolations: violations,
|
|
416
|
+
checkedAt: data.checked_at ?? "",
|
|
417
|
+
raw: data
|
|
418
|
+
};
|
|
419
|
+
}
|
|
378
420
|
async request(method, path, options = {}) {
|
|
379
421
|
const url = `${this.baseUrl}${path}`;
|
|
380
422
|
const { body, authRequired = true } = options;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/errors.ts","../src/hash.ts","../src/parse.ts"],"sourcesContent":["export { XProofClient } from \"./client.js\";\nexport {\n XProofError,\n AuthenticationError,\n ValidationError,\n NotFoundError,\n ConflictError,\n RateLimitError,\n ServerError,\n} from \"./errors.js\";\nexport type {\n Certification,\n BatchResult,\n BatchResultSummary,\n PricingInfo,\n PricingTier,\n RegistrationResult,\n TrialInfo,\n FourWOptions,\n CertifyHashOptions,\n BatchFileEntry,\n XProofClientOptions,\n ThresholdStage,\n ReversibilityClass,\n ConfidenceOptions,\n ConfidenceTrail,\n ConfidenceTrailStage,\n ConfidenceTrailDrift,\n PolicyViolation,\n ExecutionContext,\n ContextDriftStage,\n ContextDrift,\n} from \"./types.js\";\nexport { hashFile, hashBuffer, hashString } from \"./hash.js\";\n","import { basename } from \"path\";\nimport {\n XProofError,\n AuthenticationError,\n ValidationError,\n NotFoundError,\n ConflictError,\n RateLimitError,\n ServerError,\n} from \"./errors.js\";\nimport { hashFile } from \"./hash.js\";\nimport {\n parseCertification,\n parseBatchResult,\n parsePricingInfo,\n parseRegistrationResult,\n} from \"./parse.js\";\nimport type {\n Certification,\n BatchResult,\n PricingInfo,\n RegistrationResult,\n FourWOptions,\n BatchFileEntry,\n XProofClientOptions,\n ConfidenceOptions,\n ConfidenceTrail,\n ConfidenceTrailStage,\n ConfidenceTrailDrift,\n ContextDrift,\n ContextDriftStage,\n ExecutionContext,\n PolicyViolation,\n ReversibilityClass,\n} from \"./types.js\";\n\nconst VERSION = \"0.1.6\";\nconst DEFAULT_BASE_URL = \"https://xproof.app\";\nconst DEFAULT_TIMEOUT = 30_000;\n\nexport class XProofClient {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n\n registration: RegistrationResult | null = null;\n\n constructor(options: XProofClientOptions = {}) {\n this.apiKey = options.apiKey ?? \"\";\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n }\n\n static async register(\n agentName: string,\n options: Omit<XProofClientOptions, \"apiKey\"> = {}\n ): Promise<XProofClient> {\n const temp = new XProofClient(options);\n const data = await temp.request(\"POST\", \"/api/agent/register\", {\n body: { agent_name: agentName },\n authRequired: false,\n });\n const result = parseRegistrationResult(data);\n const client = new XProofClient({\n ...options,\n apiKey: result.apiKey,\n });\n client.registration = result;\n return client;\n }\n\n async certify(\n path: string,\n author: string,\n fileName?: string,\n fourW?: FourWOptions\n ): Promise<Certification> {\n this.requireAuth();\n const fileHash = await hashFile(path);\n const resolvedName = fileName ?? basename(path);\n return this.certifyHash(fileHash, resolvedName, author, fourW);\n }\n\n async certifyHash(\n fileHash: string,\n fileName: string,\n author: string,\n fourW?: FourWOptions\n ): Promise<Certification> {\n this.requireAuth();\n\n const metadata: Record<string, unknown> = fourW?.metadata\n ? { ...fourW.metadata }\n : {};\n if (fourW?.who !== undefined) metadata.who = fourW.who;\n if (fourW?.what !== undefined) metadata.what = fourW.what;\n if (fourW?.when !== undefined) metadata.when = fourW.when;\n if (fourW?.why !== undefined) metadata.why = fourW.why;\n if (fourW?.reversibilityClass !== undefined)\n metadata.reversibility_class = fourW.reversibilityClass;\n\n const payload: Record<string, unknown> = {\n filename: fileName,\n file_hash: fileHash,\n author_name: author,\n };\n if (Object.keys(metadata).length > 0) {\n payload.metadata = metadata;\n }\n\n const data = await this.request(\"POST\", \"/api/proof\", { body: payload });\n return parseCertification(data);\n }\n\n async batchCertify(files: BatchFileEntry[]): Promise<BatchResult> {\n this.requireAuth();\n\n if (files.length > 50) {\n throw new Error(\"Batch certification supports a maximum of 50 files\");\n }\n\n const entries = files.map((f) => {\n const entry: Record<string, unknown> = {\n filename: f.fileName ?? \"unknown\",\n file_hash: f.fileHash,\n };\n if (f.metadata) entry.metadata = f.metadata;\n return entry;\n });\n\n const payload: Record<string, unknown> = { files: entries };\n const author = files.find((f) => f.author)?.author;\n if (author) payload.author_name = author;\n\n const data = await this.request(\"POST\", \"/api/batch\", { body: payload });\n return parseBatchResult(data);\n }\n\n async verify(proofId: string): Promise<Certification> {\n const data = await this.request(\"GET\", `/api/proof/${proofId}`, {\n authRequired: false,\n });\n return parseCertification(data);\n }\n\n async verifyHash(fileHash: string): Promise<Certification> {\n const data = await this.request(\"GET\", `/api/proof/hash/${fileHash}`, {\n authRequired: false,\n });\n return parseCertification(data);\n }\n\n async certifyWithConfidence(\n fileHash: string,\n fileName: string,\n author: string,\n confidence: ConfidenceOptions,\n fourW?: FourWOptions\n ): Promise<Certification> {\n this.requireAuth();\n\n if (confidence.confidenceLevel < 0 || confidence.confidenceLevel > 1) {\n throw new ValidationError(\n \"confidenceLevel must be between 0.0 and 1.0\",\n {}\n );\n }\n if (!confidence.decisionId || confidence.decisionId.trim().length === 0) {\n throw new ValidationError(\"decisionId is required\", {});\n }\n\n const metadata: Record<string, unknown> = fourW?.metadata\n ? { ...fourW.metadata }\n : {};\n if (fourW?.who !== undefined) metadata.who = fourW.who;\n if (fourW?.what !== undefined) metadata.what = fourW.what;\n if (fourW?.when !== undefined) metadata.when = fourW.when;\n if (fourW?.why !== undefined) metadata.why = fourW.why;\n\n metadata.confidence_level = confidence.confidenceLevel;\n metadata.threshold_stage = confidence.thresholdStage;\n metadata.decision_id = confidence.decisionId;\n if (confidence.reversibilityClass !== undefined)\n metadata.reversibility_class = confidence.reversibilityClass;\n\n const payload: Record<string, unknown> = {\n filename: fileName,\n file_hash: fileHash,\n author_name: author,\n metadata,\n };\n\n const data = await this.request(\"POST\", \"/api/proof\", { body: payload });\n return parseCertification(data);\n }\n\n async getConfidenceTrail(decisionId: string): Promise<ConfidenceTrail> {\n const data = await this.request(\n \"GET\",\n `/api/confidence-trail/${encodeURIComponent(decisionId)}`,\n { authRequired: false }\n );\n\n const rawStages = (data.stages as any[]) || [];\n const stages: ConfidenceTrailStage[] = rawStages.map((s: any) => ({\n proofId: s.proof_id || \"\",\n fileName: s.file_name || \"\",\n fileHash: s.file_hash || \"\",\n confidenceLevel: s.confidence_level ?? null,\n thresholdStage: s.threshold_stage ?? null,\n reversibilityClass: (s.metadata?.reversibility_class ?? null) as ReversibilityClass | null,\n author: s.author || \"\",\n blockchain: {\n transactionHash: s.blockchain?.transaction_hash || \"\",\n explorerUrl: s.blockchain?.explorer_url || \"\",\n status: s.blockchain?.status || \"\",\n },\n anchoredAt: s.anchored_at || \"\",\n metadata: s.metadata || {},\n }));\n\n const rawDrift = data.context_drift as any;\n const contextDrift: ConfidenceTrailDrift | null = rawDrift\n ? {\n contextCoherent: rawDrift.context_coherent ?? true,\n driftScore: rawDrift.drift_score ?? 0,\n fieldsMonitored: rawDrift.fields_monitored || [],\n fieldsDrifted: rawDrift.fields_drifted || [],\n fieldsStable: rawDrift.fields_stable || [],\n fieldsAbsent: rawDrift.fields_absent || [],\n }\n : null;\n\n const rawViolations = (data.policy_violations as any[]) || [];\n const policyViolations: PolicyViolation[] = rawViolations.map((v: any) => ({\n proofId: v.proof_id || \"\",\n confidenceLevel: v.confidence_level ?? null,\n reversibilityClass: v.reversibility_class as ReversibilityClass,\n thresholdStage: v.threshold_stage ?? null,\n threshold: v.threshold ?? 0.95,\n rule: v.rule || \"\",\n }));\n\n return {\n decisionId: (data.decision_id as string) || decisionId,\n totalAnchors: (data.total_anchors as number) || stages.length,\n currentConfidence: (data.current_confidence as number) ?? null,\n currentStage: (data.current_stage as string) ?? null,\n isFinalized: (data.is_finalized as boolean) || false,\n policyCompliant: (data.policy_compliant as boolean) ?? true,\n policyViolations,\n contextDrift,\n stages,\n };\n }\n\n async getContextDrift(decisionId: string): Promise<ContextDrift> {\n const data = await this.request(\n \"GET\",\n `/api/context-drift/${encodeURIComponent(decisionId)}`,\n { authRequired: false }\n );\n\n const rawStages = (data.stages as any[]) || [];\n const stages: ContextDriftStage[] = rawStages.map((s: any) => ({\n proofId: s.proof_id || \"\",\n stageIndex: s.stage_index ?? 0,\n anchoredAt: s.anchored_at || \"\",\n executionContext: (s.execution_context || {}) as ExecutionContext,\n contextBreak: s.context_break || false,\n driftedFields: s.drifted_fields || [],\n }));\n\n return {\n decisionId: (data.decision_id as string) || decisionId,\n contextCoherent: (data.context_coherent as boolean) ?? true,\n driftScore: (data.drift_score as number) ?? 0,\n fieldsMonitored: (data.fields_monitored as string[]) || [],\n fieldsDrifted: (data.fields_drifted as string[]) || [],\n fieldsStable: (data.fields_stable as string[]) || [],\n fieldsAbsent: (data.fields_absent as string[]) || [],\n totalAnchors: (data.total_anchors as number) || stages.length,\n stages,\n };\n }\n\n async getPricing(): Promise<PricingInfo> {\n const data = await this.request(\"GET\", \"/api/pricing\", {\n authRequired: false,\n });\n return parsePricingInfo(data);\n }\n\n private requireAuth(): void {\n if (!this.apiKey) {\n throw new Error(\n \"apiKey is required — call XProofClient.register() or pass an apiKey\"\n );\n }\n }\n\n private async request(\n method: string,\n path: string,\n options: {\n body?: Record<string, unknown>;\n authRequired?: boolean;\n } = {}\n ): Promise<Record<string, unknown>> {\n const url = `${this.baseUrl}${path}`;\n const { body, authRequired = true } = options;\n\n const headers: Record<string, string> = {\n \"User-Agent\": `xproof-js/${VERSION}`,\n };\n\n if (authRequired && this.apiKey) {\n headers[\"Authorization\"] = `Bearer ${this.apiKey}`;\n }\n\n if (body) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n let resp: Response;\n try {\n resp = await fetch(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n clearTimeout(timer);\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new XProofError(`Request timed out after ${this.timeout}ms`);\n }\n throw new XProofError(`Request failed: ${(err as Error).message}`);\n } finally {\n clearTimeout(timer);\n }\n\n if (resp.status === 200 || resp.status === 201) {\n let data: Record<string, unknown>;\n try {\n data = (await resp.json()) as Record<string, unknown>;\n } catch {\n const text = await resp.text().catch(() => \"\");\n throw new XProofError(\n `Unexpected non-JSON response from ${method} ${url}: ${text.slice(0, 200)}`\n );\n }\n return data;\n }\n\n await this.handleError(resp);\n return {};\n }\n\n private async handleError(resp: Response): Promise<never> {\n let body: Record<string, unknown>;\n try {\n body = (await resp.json()) as Record<string, unknown>;\n } catch {\n body = { message: await resp.text().catch(() => \"\") };\n }\n\n const message =\n (body.message as string) || (body.error as string) || `HTTP ${resp.status}`;\n const status = resp.status;\n\n if (status === 400) throw new ValidationError(message, body);\n if (status === 401 || status === 403)\n throw new AuthenticationError(message, body);\n if (status === 404) throw new NotFoundError(message, body);\n if (status === 409)\n throw new ConflictError(\n message,\n (body.certificationId as string) || \"\",\n body\n );\n if (status === 429) throw new RateLimitError(message, body);\n if (status >= 500) throw new ServerError(message, status, body);\n throw new XProofError(message, status, body);\n }\n}\n","export class XProofError extends Error {\n statusCode: number;\n response: Record<string, unknown> | null;\n\n constructor(\n message: string,\n statusCode = 0,\n response: Record<string, unknown> | null = null\n ) {\n super(message);\n this.name = \"XProofError\";\n this.statusCode = statusCode;\n this.response = response;\n }\n}\n\nexport class AuthenticationError extends XProofError {\n constructor(\n message = \"Invalid or missing API key\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 401, response);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class ValidationError extends XProofError {\n constructor(\n message = \"Invalid request data\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 400, response);\n this.name = \"ValidationError\";\n }\n}\n\nexport class NotFoundError extends XProofError {\n constructor(\n message = \"Resource not found\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 404, response);\n this.name = \"NotFoundError\";\n }\n}\n\nexport class ConflictError extends XProofError {\n certificationId: string;\n\n constructor(\n message = \"File already certified\",\n certificationId = \"\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 409, response);\n this.name = \"ConflictError\";\n this.certificationId = certificationId;\n }\n}\n\nexport class RateLimitError extends XProofError {\n constructor(\n message = \"Rate limit exceeded\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 429, response);\n this.name = \"RateLimitError\";\n }\n}\n\nexport class ServerError extends XProofError {\n constructor(\n message = \"Internal server error\",\n statusCode = 500,\n response: Record<string, unknown> | null = null\n ) {\n super(message, statusCode, response);\n this.name = \"ServerError\";\n }\n}\n","import { createHash } from \"crypto\";\nimport { readFile } from \"fs/promises\";\n\nexport async function hashFile(path: string): Promise<string> {\n const data = await readFile(path);\n return createHash(\"sha256\").update(data).digest(\"hex\");\n}\n\nexport function hashBuffer(data: Uint8Array): string {\n return createHash(\"sha256\").update(data).digest(\"hex\");\n}\n\nexport function hashString(data: string): string {\n return createHash(\"sha256\").update(data, \"utf8\").digest(\"hex\");\n}\n","import type {\n Certification,\n BatchResult,\n BatchResultSummary,\n PricingInfo,\n PricingTier,\n RegistrationResult,\n TrialInfo,\n} from \"./types.js\";\n\nexport function parseCertification(data: Record<string, unknown>): Certification {\n const blockchain = (data.blockchain as Record<string, unknown>) || {};\n return {\n id: (data.id as string) || (data.proof_id as string) || \"\",\n fileName:\n (data.fileName as string) ||\n (data.filename as string) ||\n (data.file_name as string) ||\n \"\",\n fileHash:\n (data.fileHash as string) || (data.file_hash as string) || \"\",\n transactionHash:\n (data.transactionHash as string) ||\n (blockchain.transaction_hash as string) ||\n \"\",\n transactionUrl:\n (data.transactionUrl as string) ||\n (blockchain.explorer_url as string) ||\n \"\",\n createdAt:\n (data.createdAt as string) ||\n (data.created_at as string) ||\n (data.timestamp as string) ||\n \"\",\n authorName:\n (data.authorName as string) || (data.author_name as string) || \"\",\n blockchainStatus:\n (data.blockchainStatus as string) || (data.status as string) || \"\",\n isPublic: data.isPublic !== undefined ? !!data.isPublic : (data.is_public !== undefined ? !!data.is_public : true),\n certificateUrl:\n (data.certificateUrl as string) ||\n (data.certificate_url as string) ||\n \"\",\n verifyUrl:\n (data.verifyUrl as string) || (data.verify_url as string) || \"\",\n };\n}\n\nexport function parseBatchResult(data: Record<string, unknown>): BatchResult {\n const rawResults = (data.results as Array<Record<string, unknown>>) || [];\n const results = rawResults.map(parseCertification);\n const total = (data.total as number) ?? rawResults.length;\n const created = (data.created as number) ?? 0;\n const existing = (data.existing as number) ?? 0;\n\n const summary: BatchResultSummary = {\n total,\n created,\n existing,\n get certified() { return created; },\n get failed() { return total - created - existing; },\n };\n\n return {\n batchId: (data.batch_id as string) || \"\",\n results,\n summary,\n };\n}\n\nexport function parsePricingInfo(data: Record<string, unknown>): PricingInfo {\n const rawTiers = (data.tiers as Array<Record<string, unknown>>) || [];\n const tiers: PricingTier[] = rawTiers.map((t) => ({\n minCertifications:\n (t.min_certifications as number) ?? (t.min as number) ?? 0,\n maxCertifications:\n (t.max_certifications as number) ?? (t.max as number) ?? null,\n priceUsd: (t.price_usd as number) ?? (t.price as number) ?? 0,\n }));\n\n return {\n protocol: (data.protocol as string) || \"\",\n version: (data.version as string) || \"\",\n priceUsd:\n (data.price_usd as number) ?? (data.current_price as number) ?? 0,\n tiers,\n paymentMethods:\n (data.payment_methods as Array<Record<string, string>>) || [],\n raw: data,\n };\n}\n\nexport function parseRegistrationResult(\n data: Record<string, unknown>\n): RegistrationResult {\n const trialData = (data.trial as Record<string, unknown>) || {};\n const trial: TrialInfo = {\n quota: (trialData.quota as number) ?? 0,\n used: (trialData.used as number) ?? 0,\n remaining: (trialData.remaining as number) ?? 0,\n };\n return {\n apiKey: (data.api_key as string) || \"\",\n agentName: (data.agent_name as string) || \"\",\n trial,\n endpoints: (data.endpoints as Record<string, string>) || {},\n raw: data,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAyB;;;ACAlB,IAAM,cAAN,cAA0B,MAAM;AAAA,EAIrC,YACE,SACA,aAAa,GACb,WAA2C,MAC3C;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,EAClB;AACF;AAEO,IAAM,sBAAN,cAAkC,YAAY;AAAA,EACnD,YACE,UAAU,8BACV,WAA2C,MAC3C;AACA,UAAM,SAAS,KAAK,QAAQ;AAC5B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAA8B,YAAY;AAAA,EAC/C,YACE,UAAU,wBACV,WAA2C,MAC3C;AACA,UAAM,SAAS,KAAK,QAAQ;AAC5B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAC7C,YACE,UAAU,sBACV,WAA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AM,IAAI;AAAA,UACR,qCAAqC,MAAM,IAAI,GAAG,KAAK,KAAK,MAAM,GAAG,GAAG,CAAC;AAAA,QAC3E;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAEA,UAAM,KAAK,YAAY,IAAI;AAC3B,WAAO,CAAC;AAAA,EACV;AAAA,EAEA,MAAc,YAAY,MAAgC;AACxD,QAAI;AACJ,QAAI;AACF,aAAQ,MAAM,KAAK,KAAK;AAAA,IAC1B,QAAQ;AACN,aAAO,EAAE,SAAS,MAAM,KAAK,KAAK,EAAE,MAAM,MAAM,EAAE,EAAE;AAAA,IACtD;AAEA,UAAM,UACH,KAAK,WAAuB,KAAK,SAAoB,QAAQ,KAAK,MAAM;AAC3E,UAAM,SAAS,KAAK;AAEpB,QAAI,WAAW,IAAK,OAAM,IAAI,gBAAgB,SAAS,IAAI;AAC3D,QAAI,WAAW,OAAO,WAAW;AAC/B,YAAM,IAAI,oBAAoB,SAAS,IAAI;AAC7C,QAAI,WAAW,IAAK,OAAM,IAAI,cAAc,SAAS,IAAI;AACzD,QAAI,WAAW;AACb,YAAM,IAAI;AAAA,QACR;AAAA,QACC,KAAK,mBAA8B;AAAA,QACpC;AAAA,MACF;AACF,QAAI,WAAW,IAAK,OAAM,IAAI,eAAe,SAAS,IAAI;AAC1D,QAAI,UAAU,IAAK,OAAM,IAAI,YAAY,SAAS,QAAQ,IAAI;AAC9D,UAAM,IAAI,YAAY,SAAS,QAAQ,IAAI;AAAA,EAC7C;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/client.ts","../src/errors.ts","../src/hash.ts","../src/parse.ts"],"sourcesContent":["export { XProofClient } from \"./client.js\";\nexport {\n XProofError,\n AuthenticationError,\n ValidationError,\n NotFoundError,\n ConflictError,\n RateLimitError,\n ServerError,\n} from \"./errors.js\";\nexport type {\n Certification,\n BatchResult,\n BatchResultSummary,\n PricingInfo,\n PricingTier,\n RegistrationResult,\n TrialInfo,\n FourWOptions,\n CertifyHashOptions,\n BatchFileEntry,\n XProofClientOptions,\n ThresholdStage,\n ReversibilityClass,\n ConfidenceOptions,\n ConfidenceTrail,\n ConfidenceTrailStage,\n ConfidenceTrailDrift,\n PolicyViolation,\n PolicyCheckResult,\n ExecutionContext,\n ContextDriftStage,\n ContextDrift,\n} from \"./types.js\";\nexport { hashFile, hashBuffer, hashString } from \"./hash.js\";\n","import { basename } from \"path\";\nimport {\n XProofError,\n AuthenticationError,\n ValidationError,\n NotFoundError,\n ConflictError,\n RateLimitError,\n ServerError,\n} from \"./errors.js\";\nimport { hashFile } from \"./hash.js\";\nimport {\n parseCertification,\n parseBatchResult,\n parsePricingInfo,\n parseRegistrationResult,\n} from \"./parse.js\";\nimport type {\n Certification,\n BatchResult,\n PricingInfo,\n RegistrationResult,\n FourWOptions,\n BatchFileEntry,\n XProofClientOptions,\n ConfidenceOptions,\n ConfidenceTrail,\n ConfidenceTrailStage,\n ConfidenceTrailDrift,\n ContextDrift,\n ContextDriftStage,\n ExecutionContext,\n PolicyViolation,\n PolicyCheckResult,\n ReversibilityClass,\n} from \"./types.js\";\n\nconst VERSION = \"0.1.7\";\nconst DEFAULT_BASE_URL = \"https://xproof.app\";\nconst DEFAULT_TIMEOUT = 30_000;\n\nexport class XProofClient {\n private apiKey: string;\n private baseUrl: string;\n private timeout: number;\n\n registration: RegistrationResult | null = null;\n\n constructor(options: XProofClientOptions = {}) {\n this.apiKey = options.apiKey ?? \"\";\n this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\");\n this.timeout = options.timeout ?? DEFAULT_TIMEOUT;\n }\n\n static async register(\n agentName: string,\n options: Omit<XProofClientOptions, \"apiKey\"> = {}\n ): Promise<XProofClient> {\n const temp = new XProofClient(options);\n const data = await temp.request(\"POST\", \"/api/agent/register\", {\n body: { agent_name: agentName },\n authRequired: false,\n });\n const result = parseRegistrationResult(data);\n const client = new XProofClient({\n ...options,\n apiKey: result.apiKey,\n });\n client.registration = result;\n return client;\n }\n\n async certify(\n path: string,\n author: string,\n fileName?: string,\n fourW?: FourWOptions\n ): Promise<Certification> {\n this.requireAuth();\n const fileHash = await hashFile(path);\n const resolvedName = fileName ?? basename(path);\n return this.certifyHash(fileHash, resolvedName, author, fourW);\n }\n\n async certifyHash(\n fileHash: string,\n fileName: string,\n author: string,\n fourW?: FourWOptions\n ): Promise<Certification> {\n this.requireAuth();\n\n const metadata: Record<string, unknown> = fourW?.metadata\n ? { ...fourW.metadata }\n : {};\n if (fourW?.who !== undefined) metadata.who = fourW.who;\n if (fourW?.what !== undefined) metadata.what = fourW.what;\n if (fourW?.when !== undefined) metadata.when = fourW.when;\n if (fourW?.why !== undefined) metadata.why = fourW.why;\n if (fourW?.reversibilityClass !== undefined)\n metadata.reversibility_class = fourW.reversibilityClass;\n\n const payload: Record<string, unknown> = {\n filename: fileName,\n file_hash: fileHash,\n author_name: author,\n };\n if (Object.keys(metadata).length > 0) {\n payload.metadata = metadata;\n }\n\n const data = await this.request(\"POST\", \"/api/proof\", { body: payload });\n return parseCertification(data);\n }\n\n async batchCertify(files: BatchFileEntry[]): Promise<BatchResult> {\n this.requireAuth();\n\n if (files.length > 50) {\n throw new Error(\"Batch certification supports a maximum of 50 files\");\n }\n\n const entries = files.map((f) => {\n const entry: Record<string, unknown> = {\n filename: f.fileName ?? \"unknown\",\n file_hash: f.fileHash,\n };\n if (f.metadata) entry.metadata = f.metadata;\n return entry;\n });\n\n const payload: Record<string, unknown> = { files: entries };\n const author = files.find((f) => f.author)?.author;\n if (author) payload.author_name = author;\n\n const data = await this.request(\"POST\", \"/api/batch\", { body: payload });\n return parseBatchResult(data);\n }\n\n async verify(proofId: string): Promise<Certification> {\n const data = await this.request(\"GET\", `/api/proof/${proofId}`, {\n authRequired: false,\n });\n return parseCertification(data);\n }\n\n async verifyHash(fileHash: string): Promise<Certification> {\n const data = await this.request(\"GET\", `/api/proof/hash/${fileHash}`, {\n authRequired: false,\n });\n return parseCertification(data);\n }\n\n async certifyWithConfidence(\n fileHash: string,\n fileName: string,\n author: string,\n confidence: ConfidenceOptions,\n fourW?: FourWOptions\n ): Promise<Certification> {\n this.requireAuth();\n\n if (confidence.confidenceLevel < 0 || confidence.confidenceLevel > 1) {\n throw new ValidationError(\n \"confidenceLevel must be between 0.0 and 1.0\",\n {}\n );\n }\n if (!confidence.decisionId || confidence.decisionId.trim().length === 0) {\n throw new ValidationError(\"decisionId is required\", {});\n }\n\n const metadata: Record<string, unknown> = fourW?.metadata\n ? { ...fourW.metadata }\n : {};\n if (fourW?.who !== undefined) metadata.who = fourW.who;\n if (fourW?.what !== undefined) metadata.what = fourW.what;\n if (fourW?.when !== undefined) metadata.when = fourW.when;\n if (fourW?.why !== undefined) metadata.why = fourW.why;\n if (fourW?.reversibilityClass !== undefined)\n metadata.reversibility_class = fourW.reversibilityClass;\n\n metadata.confidence_level = confidence.confidenceLevel;\n metadata.threshold_stage = confidence.thresholdStage;\n metadata.decision_id = confidence.decisionId;\n // confidence.reversibilityClass takes priority over fourW.reversibilityClass\n if (confidence.reversibilityClass !== undefined)\n metadata.reversibility_class = confidence.reversibilityClass;\n\n const payload: Record<string, unknown> = {\n filename: fileName,\n file_hash: fileHash,\n author_name: author,\n metadata,\n };\n\n const data = await this.request(\"POST\", \"/api/proof\", { body: payload });\n return parseCertification(data);\n }\n\n async getConfidenceTrail(decisionId: string): Promise<ConfidenceTrail> {\n const data = await this.request(\n \"GET\",\n `/api/confidence-trail/${encodeURIComponent(decisionId)}`,\n { authRequired: false }\n );\n\n const rawStages = (data.stages as any[]) || [];\n const stages: ConfidenceTrailStage[] = rawStages.map((s: any) => ({\n proofId: s.proof_id || \"\",\n fileName: s.file_name || \"\",\n fileHash: s.file_hash || \"\",\n confidenceLevel: s.confidence_level ?? null,\n thresholdStage: s.threshold_stage ?? null,\n reversibilityClass: (s.metadata?.reversibility_class ?? null) as ReversibilityClass | null,\n author: s.author || \"\",\n blockchain: {\n transactionHash: s.blockchain?.transaction_hash || \"\",\n explorerUrl: s.blockchain?.explorer_url || \"\",\n status: s.blockchain?.status || \"\",\n },\n anchoredAt: s.anchored_at || \"\",\n metadata: s.metadata || {},\n }));\n\n const rawDrift = data.context_drift as any;\n const contextDrift: ConfidenceTrailDrift | null = rawDrift\n ? {\n contextCoherent: rawDrift.context_coherent ?? true,\n driftScore: rawDrift.drift_score ?? 0,\n fieldsMonitored: rawDrift.fields_monitored || [],\n fieldsDrifted: rawDrift.fields_drifted || [],\n fieldsStable: rawDrift.fields_stable || [],\n fieldsAbsent: rawDrift.fields_absent || [],\n }\n : null;\n\n const rawViolations = (data.policy_violations as any[]) || [];\n const policyViolations: PolicyViolation[] = rawViolations.map((v: any) => ({\n proofId: v.proof_id || \"\",\n confidenceLevel: v.confidence_level ?? null,\n reversibilityClass: v.reversibility_class as ReversibilityClass,\n thresholdStage: v.threshold_stage ?? null,\n threshold: v.threshold ?? 0.95,\n rule: v.rule || \"\",\n }));\n\n return {\n decisionId: (data.decision_id as string) || decisionId,\n totalAnchors: (data.total_anchors as number) || stages.length,\n currentConfidence: (data.current_confidence as number) ?? null,\n currentStage: (data.current_stage as string) ?? null,\n isFinalized: (data.is_finalized as boolean) || false,\n policyCompliant: (data.policy_compliant as boolean) ?? true,\n policyViolations,\n contextDrift,\n stages,\n };\n }\n\n async getContextDrift(decisionId: string): Promise<ContextDrift> {\n const data = await this.request(\n \"GET\",\n `/api/context-drift/${encodeURIComponent(decisionId)}`,\n { authRequired: false }\n );\n\n const rawStages = (data.stages as any[]) || [];\n const stages: ContextDriftStage[] = rawStages.map((s: any) => ({\n proofId: s.proof_id || \"\",\n stageIndex: s.stage_index ?? 0,\n anchoredAt: s.anchored_at || \"\",\n executionContext: (s.execution_context || {}) as ExecutionContext,\n contextBreak: s.context_break || false,\n driftedFields: s.drifted_fields || [],\n }));\n\n return {\n decisionId: (data.decision_id as string) || decisionId,\n contextCoherent: (data.context_coherent as boolean) ?? true,\n driftScore: (data.drift_score as number) ?? 0,\n fieldsMonitored: (data.fields_monitored as string[]) || [],\n fieldsDrifted: (data.fields_drifted as string[]) || [],\n fieldsStable: (data.fields_stable as string[]) || [],\n fieldsAbsent: (data.fields_absent as string[]) || [],\n totalAnchors: (data.total_anchors as number) || stages.length,\n stages,\n };\n }\n\n async getPricing(): Promise<PricingInfo> {\n const data = await this.request(\"GET\", \"/api/pricing\", {\n authRequired: false,\n });\n return parsePricingInfo(data);\n }\n\n private requireAuth(): void {\n if (!this.apiKey) {\n throw new Error(\n \"apiKey is required — call XProofClient.register() or pass an apiKey\"\n );\n }\n }\n\n /**\n * Check policy compliance for a decision chain without fetching the full trail.\n *\n * Calls `GET /api/proofs/policy-check?decision_id=<id>` and returns a lightweight\n * compliance report: whether the chain is policy-compliant and any violations found.\n *\n * @param decisionId - The shared decision chain identifier.\n * @returns A `PolicyCheckResult` with `policyCompliant`, `policyViolations`, and metadata.\n */\n async getPolicyCheck(decisionId: string): Promise<PolicyCheckResult> {\n if (!decisionId || !decisionId.trim()) {\n throw new ValidationError(\"decisionId is required\", {});\n }\n const data = await this.request(\n \"GET\",\n `/api/proofs/policy-check?decision_id=${encodeURIComponent(decisionId)}`,\n { authRequired: false }\n );\n const violations = ((data.policy_violations as unknown[]) ?? []).map(\n (v) => {\n const vv = v as Record<string, unknown>;\n return {\n proofId: (vv.proof_id as string) ?? \"\",\n confidenceLevel:\n vv.confidence_level != null\n ? (vv.confidence_level as number)\n : null,\n reversibilityClass:\n (vv.reversibility_class as ReversibilityClass) ?? \"reversible\",\n thresholdStage:\n vv.threshold_stage != null\n ? (vv.threshold_stage as string)\n : null,\n threshold: (vv.threshold as number) ?? 0,\n rule: (vv.rule as string) ?? \"\",\n } satisfies PolicyViolation;\n }\n );\n return {\n decisionId: (data.decision_id as string) ?? decisionId,\n totalAnchors: (data.total_anchors as number) ?? 0,\n policyCompliant: (data.policy_compliant as boolean) ?? true,\n policyViolations: violations,\n checkedAt: (data.checked_at as string) ?? \"\",\n raw: data,\n };\n }\n\n private async request(\n method: string,\n path: string,\n options: {\n body?: Record<string, unknown>;\n authRequired?: boolean;\n } = {}\n ): Promise<Record<string, unknown>> {\n const url = `${this.baseUrl}${path}`;\n const { body, authRequired = true } = options;\n\n const headers: Record<string, string> = {\n \"User-Agent\": `xproof-js/${VERSION}`,\n };\n\n if (authRequired && this.apiKey) {\n headers[\"Authorization\"] = `Bearer ${this.apiKey}`;\n }\n\n if (body) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), this.timeout);\n\n let resp: Response;\n try {\n resp = await fetch(url, {\n method,\n headers,\n body: body ? JSON.stringify(body) : undefined,\n signal: controller.signal,\n });\n } catch (err) {\n clearTimeout(timer);\n if (err instanceof DOMException && err.name === \"AbortError\") {\n throw new XProofError(`Request timed out after ${this.timeout}ms`);\n }\n throw new XProofError(`Request failed: ${(err as Error).message}`);\n } finally {\n clearTimeout(timer);\n }\n\n if (resp.status === 200 || resp.status === 201) {\n let data: Record<string, unknown>;\n try {\n data = (await resp.json()) as Record<string, unknown>;\n } catch {\n const text = await resp.text().catch(() => \"\");\n throw new XProofError(\n `Unexpected non-JSON response from ${method} ${url}: ${text.slice(0, 200)}`\n );\n }\n return data;\n }\n\n await this.handleError(resp);\n return {};\n }\n\n private async handleError(resp: Response): Promise<never> {\n let body: Record<string, unknown>;\n try {\n body = (await resp.json()) as Record<string, unknown>;\n } catch {\n body = { message: await resp.text().catch(() => \"\") };\n }\n\n const message =\n (body.message as string) || (body.error as string) || `HTTP ${resp.status}`;\n const status = resp.status;\n\n if (status === 400) throw new ValidationError(message, body);\n if (status === 401 || status === 403)\n throw new AuthenticationError(message, body);\n if (status === 404) throw new NotFoundError(message, body);\n if (status === 409)\n throw new ConflictError(\n message,\n (body.certificationId as string) || \"\",\n body\n );\n if (status === 429) throw new RateLimitError(message, body);\n if (status >= 500) throw new ServerError(message, status, body);\n throw new XProofError(message, status, body);\n }\n}\n","export class XProofError extends Error {\n statusCode: number;\n response: Record<string, unknown> | null;\n\n constructor(\n message: string,\n statusCode = 0,\n response: Record<string, unknown> | null = null\n ) {\n super(message);\n this.name = \"XProofError\";\n this.statusCode = statusCode;\n this.response = response;\n }\n}\n\nexport class AuthenticationError extends XProofError {\n constructor(\n message = \"Invalid or missing API key\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 401, response);\n this.name = \"AuthenticationError\";\n }\n}\n\nexport class ValidationError extends XProofError {\n constructor(\n message = \"Invalid request data\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 400, response);\n this.name = \"ValidationError\";\n }\n}\n\nexport class NotFoundError extends XProofError {\n constructor(\n message = \"Resource not found\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 404, response);\n this.name = \"NotFoundError\";\n }\n}\n\nexport class ConflictError extends XProofError {\n certificationId: string;\n\n constructor(\n message = \"File already certified\",\n certificationId = \"\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 409, response);\n this.name = \"ConflictError\";\n this.certificationId = certificationId;\n }\n}\n\nexport class RateLimitError extends XProofError {\n constructor(\n message = \"Rate limit exceeded\",\n response: Record<string, unknown> | null = null\n ) {\n super(message, 429, response);\n this.name = \"RateLimitError\";\n }\n}\n\nexport class ServerError extends XProofError {\n constructor(\n message = \"Internal server error\",\n statusCode = 500,\n response: Record<string, unknown> | null = null\n ) {\n super(message, statusCode, response);\n this.name = \"ServerError\";\n }\n}\n","import { createHash } from \"crypto\";\nimport { readFile } from \"fs/promises\";\n\nexport async function hashFile(path: string): Promise<string> {\n const data = await readFile(path);\n return createHash(\"sha256\").update(data).digest(\"hex\");\n}\n\nexport function hashBuffer(data: Uint8Array): string {\n return createHash(\"sha256\").update(data).digest(\"hex\");\n}\n\nexport function hashString(data: string): string {\n return createHash(\"sha256\").update(data, \"utf8\").digest(\"hex\");\n}\n","import type {\n Certification,\n BatchResult,\n BatchResultSummary,\n PricingInfo,\n PricingTier,\n RegistrationResult,\n TrialInfo,\n} from \"./types.js\";\n\nexport function parseCertification(data: Record<string, unknown>): Certification {\n const blockchain = (data.blockchain as Record<string, unknown>) || {};\n return {\n id: (data.id as string) || (data.proof_id as string) || \"\",\n fileName:\n (data.fileName as string) ||\n (data.filename as string) ||\n (data.file_name as string) ||\n \"\",\n fileHash:\n (data.fileHash as string) || (data.file_hash as string) || \"\",\n transactionHash:\n (data.transactionHash as string) ||\n (blockchain.transaction_hash as string) ||\n \"\",\n transactionUrl:\n (data.transactionUrl as string) ||\n (blockchain.explorer_url as string) ||\n \"\",\n createdAt:\n (data.createdAt as string) ||\n (data.created_at as string) ||\n (data.timestamp as string) ||\n \"\",\n authorName:\n (data.authorName as string) || (data.author_name as string) || \"\",\n blockchainStatus:\n (data.blockchainStatus as string) || (data.status as string) || \"\",\n isPublic: data.isPublic !== undefined ? !!data.isPublic : (data.is_public !== undefined ? !!data.is_public : true),\n certificateUrl:\n (data.certificateUrl as string) ||\n (data.certificate_url as string) ||\n \"\",\n verifyUrl:\n (data.verifyUrl as string) || (data.verify_url as string) || \"\",\n };\n}\n\nexport function parseBatchResult(data: Record<string, unknown>): BatchResult {\n const rawResults = (data.results as Array<Record<string, unknown>>) || [];\n const results = rawResults.map(parseCertification);\n const total = (data.total as number) ?? rawResults.length;\n const created = (data.created as number) ?? 0;\n const existing = (data.existing as number) ?? 0;\n\n const summary: BatchResultSummary = {\n total,\n created,\n existing,\n get certified() { return created; },\n get failed() { return total - created - existing; },\n };\n\n return {\n batchId: (data.batch_id as string) || \"\",\n results,\n summary,\n };\n}\n\nexport function parsePricingInfo(data: Record<string, unknown>): PricingInfo {\n const rawTiers = (data.tiers as Array<Record<string, unknown>>) || [];\n const tiers: PricingTier[] = rawTiers.map((t) => ({\n minCertifications:\n (t.min_certifications as number) ?? (t.min as number) ?? 0,\n maxCertifications:\n (t.max_certifications as number) ?? (t.max as number) ?? null,\n priceUsd: (t.price_usd as number) ?? (t.price as number) ?? 0,\n }));\n\n return {\n protocol: (data.protocol as string) || \"\",\n version: (data.version as string) || \"\",\n priceUsd:\n (data.price_usd as number) ?? (data.current_price as number) ?? 0,\n tiers,\n paymentMethods:\n (data.payment_methods as Array<Record<string, string>>) || [],\n raw: data,\n };\n}\n\nexport function parseRegistrationResult(\n data: Record<string, unknown>\n): RegistrationResult {\n const trialData = (data.trial as Record<string, unknown>) || {};\n const trial: TrialInfo = {\n quota: (trialData.quota as number) ?? 0,\n used: (trialData.used as number) ?? 0,\n remaining: (trialData.remaining as number) ?? 0,\n };\n return {\n apiKey: (data.api_key as string) || \"\",\n agentName: (data.agent_name as string) || \"\",\n trial,\n endpoints: (data.endpoints as Record<string, string>) || {},\n raw: data,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAyB;;;ACAlB,IAAM,cAAN,cAA0B,MAAM;AAAA,EAIrC,YACE,SACA,aAAa,GACb,WAA2C,MAC3C;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,SAAK,WAAW;AAAA,EAClB;AACF;AAEO,IAAM,sBAAN,cAAkC,YAAY;AAAA,EACnD,YACE,UAAU,8BACV,WAA2C,MAC3C;AACA,UAAM,SAAS,KAAK,QAAQ;AAC5B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,kBAAN,cAA8B,YAAY;AAAA,EAC/C,YACE,UAAU,wBACV,WAA2C,MAC3C;AACA,UAAM,SAAS,KAAK,QAAQ;AAC5B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAC7C,YACE,UAAU,sBACV,WAA2C,MAC3C;AACA,UAAM,SAAS,KAAK,QAAQ;AAC5B,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,YAAY;AAAA,EAG7C,YACE,UAAU,0BACV,kBAAkB,IAClB,WAA2C,MAC3C;AACA,UAAM,SAAS,KAAK,QAAQ;A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