@sonate/schemas 2.0.0

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 ADDED
@@ -0,0 +1,93 @@
1
+ # @sonate/schemas
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@sonate/schemas.svg)](https://www.npmjs.com/package/@sonate/schemas)
4
+ [![license](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
5
+
6
+ Shared schema definitions for SONATE Trust Receipts — JSON Schema validation + TypeScript types.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @sonate/schemas
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ### Validate a receipt
17
+
18
+ ```typescript
19
+ import { receiptValidator } from '@sonate/schemas';
20
+
21
+ const result = receiptValidator.validateJSON(receipt);
22
+ if (result.valid) {
23
+ console.log('Receipt is valid');
24
+ } else {
25
+ console.error('Validation errors:', result.errors);
26
+ }
27
+ ```
28
+
29
+ ### TypeScript types
30
+
31
+ ```typescript
32
+ import type {
33
+ TrustReceipt,
34
+ AIInteraction,
35
+ DigitalSignature,
36
+ HashChain,
37
+ CreateReceiptInput,
38
+ VerificationResult,
39
+ } from '@sonate/schemas';
40
+ ```
41
+
42
+ ## What's Included
43
+
44
+ - **JSON Schema** (`receipt.schema.json`) — V2 Trust Receipt schema with AJV validation
45
+ - **TypeScript interfaces** — `TrustReceipt`, `AIInteraction`, `Telemetry`, `PolicyState`, etc.
46
+ - **Validator** — Runtime validation using AJV with detailed error reporting
47
+
48
+ ## Receipt Structure (V2)
49
+
50
+ A Trust Receipt contains:
51
+
52
+ | Field | Description |
53
+ |-------|-------------|
54
+ | `id` | SHA-256 hash of canonical content |
55
+ | `version` | Schema version (`"2.0.0"`) |
56
+ | `timestamp` | ISO 8601 timestamp |
57
+ | `agent_did` | DID of the AI agent |
58
+ | `human_did` | DID of the human user |
59
+ | `interaction` | Prompt/response data (raw or hashed) |
60
+ | `chain` | Hash chain for immutability |
61
+ | `signature` | Ed25519 cryptographic signature |
62
+
63
+ ### Privacy-by-Default
64
+
65
+ The `interaction` object supports both raw content and content hashing:
66
+
67
+ ```typescript
68
+ // Hashes only (privacy-preserving, default)
69
+ interaction: {
70
+ prompt_hash: "a1b2c3...",
71
+ response_hash: "d4e5f6...",
72
+ model: "gpt-4"
73
+ }
74
+
75
+ // Raw content (opt-in)
76
+ interaction: {
77
+ prompt: "What is quantum computing?",
78
+ response: "Quantum computing uses...",
79
+ prompt_hash: "a1b2c3...",
80
+ response_hash: "d4e5f6...",
81
+ model: "gpt-4"
82
+ }
83
+ ```
84
+
85
+ ## Related Packages
86
+
87
+ - [`@sonate/trust-receipts`](https://www.npmjs.com/package/@sonate/trust-receipts) — Generate signed receipts
88
+ - [`@sonate/verify-sdk`](https://www.npmjs.com/package/@sonate/verify-sdk) — Verify receipts (browser + Node.js)
89
+ - [`@sonate/core`](https://www.npmjs.com/package/@sonate/core) — Core trust protocol
90
+
91
+ ## License
92
+
93
+ MIT
@@ -0,0 +1,516 @@
1
+ /**
2
+ * @sonate/schemas
3
+ *
4
+ * Shared schema definitions for SONATE platform
5
+ * - Receipt schema (JSON Schema + TypeScript)
6
+ * - DID schema
7
+ * - Runtime validators
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { TrustReceipt, receiptValidator } from '@sonate/schemas';
12
+ *
13
+ * const receipt: TrustReceipt = { ... };
14
+ * const result = receiptValidator.validateJSON(receipt);
15
+ *
16
+ * if (result.valid) {
17
+ * console.log('Receipt is valid');
18
+ * } else {
19
+ * console.error('Validation errors:', result.errors);
20
+ * }
21
+ * ```
22
+ */
23
+ export type { TrustReceipt, CreateReceiptInput, VerificationResult, AIInteraction, Telemetry, PolicyState, PolicyViolation, HashChain, DigitalSignature, DID, } from './receipt.types';
24
+ export type { InteractionMode, AIProvider, ViolationSeverity, PolicyAction, ResonanceQuality, SignatureAlgorithm, } from './receipt.types';
25
+ export { receiptValidator, validateReceiptJSON, validateReceiptZod, isReceiptProcessable } from './validator';
26
+ export declare const RECEIPT_SCHEMA: {
27
+ $schema: string;
28
+ title: string;
29
+ description: string;
30
+ version: string;
31
+ type: string;
32
+ required: string[];
33
+ properties: {
34
+ id: {
35
+ type: string;
36
+ description: string;
37
+ pattern: string;
38
+ example: string;
39
+ };
40
+ version: {
41
+ type: string;
42
+ description: string;
43
+ enum: string[];
44
+ example: string;
45
+ };
46
+ timestamp: {
47
+ type: string;
48
+ description: string;
49
+ format: string;
50
+ example: string;
51
+ };
52
+ session_id: {
53
+ type: string;
54
+ description: string;
55
+ example: string;
56
+ };
57
+ agent_did: {
58
+ type: string;
59
+ description: string;
60
+ pattern: string;
61
+ example: string;
62
+ };
63
+ human_did: {
64
+ type: string;
65
+ description: string;
66
+ pattern: string;
67
+ example: string;
68
+ };
69
+ policy_version: {
70
+ type: string;
71
+ description: string;
72
+ example: string;
73
+ };
74
+ mode: {
75
+ type: string;
76
+ enum: string[];
77
+ description: string;
78
+ };
79
+ interaction: {
80
+ type: string;
81
+ description: string;
82
+ required: string[];
83
+ properties: {
84
+ prompt: {
85
+ type: string;
86
+ description: string;
87
+ example: string;
88
+ };
89
+ response: {
90
+ type: string;
91
+ description: string;
92
+ example: string;
93
+ };
94
+ prompt_hash: {
95
+ type: string;
96
+ description: string;
97
+ pattern: string;
98
+ };
99
+ response_hash: {
100
+ type: string;
101
+ description: string;
102
+ pattern: string;
103
+ };
104
+ model: {
105
+ type: string;
106
+ description: string;
107
+ example: string;
108
+ };
109
+ provider: {
110
+ type: string;
111
+ description: string;
112
+ enum: string[];
113
+ example: string;
114
+ };
115
+ temperature: {
116
+ type: string;
117
+ description: string;
118
+ minimum: number;
119
+ maximum: number;
120
+ example: number;
121
+ };
122
+ max_tokens: {
123
+ type: string;
124
+ description: string;
125
+ example: number;
126
+ };
127
+ reasoning: {
128
+ type: string;
129
+ description: string;
130
+ properties: {
131
+ thought_process: {
132
+ type: string;
133
+ description: string;
134
+ };
135
+ confidence: {
136
+ type: string;
137
+ description: string;
138
+ minimum: number;
139
+ maximum: number;
140
+ };
141
+ retrieved_context: {
142
+ type: string;
143
+ description: string;
144
+ items: {
145
+ type: string;
146
+ };
147
+ };
148
+ };
149
+ };
150
+ };
151
+ };
152
+ telemetry: {
153
+ type: string;
154
+ description: string;
155
+ properties: {
156
+ resonance_score: {
157
+ type: string;
158
+ description: string;
159
+ minimum: number;
160
+ maximum: number;
161
+ example: number;
162
+ };
163
+ resonance_rm: {
164
+ type: string;
165
+ description: string;
166
+ minimum: number;
167
+ maximum: number;
168
+ example: number;
169
+ };
170
+ trust_resonance_gap: {
171
+ type: string;
172
+ description: string;
173
+ minimum: number;
174
+ maximum: number;
175
+ example: number;
176
+ };
177
+ resonance_input_mode: {
178
+ type: string;
179
+ enum: string[];
180
+ description: string;
181
+ };
182
+ resonance_quality: {
183
+ type: string;
184
+ enum: string[];
185
+ description: string;
186
+ };
187
+ bedau_index: {
188
+ type: string;
189
+ description: string;
190
+ minimum: number;
191
+ maximum: number;
192
+ example: number;
193
+ };
194
+ coherence_score: {
195
+ type: string;
196
+ description: string;
197
+ minimum: number;
198
+ maximum: number;
199
+ example: number;
200
+ };
201
+ truth_debt: {
202
+ type: string;
203
+ description: string;
204
+ minimum: number;
205
+ maximum: number;
206
+ example: number;
207
+ };
208
+ volatility: {
209
+ type: string;
210
+ description: string;
211
+ minimum: number;
212
+ maximum: number;
213
+ example: number;
214
+ };
215
+ ciq_metrics: {
216
+ type: string;
217
+ description: string;
218
+ properties: {
219
+ clarity: {
220
+ type: string;
221
+ description: string;
222
+ minimum: number;
223
+ maximum: number;
224
+ };
225
+ integrity: {
226
+ type: string;
227
+ description: string;
228
+ minimum: number;
229
+ maximum: number;
230
+ };
231
+ quality: {
232
+ type: string;
233
+ description: string;
234
+ minimum: number;
235
+ maximum: number;
236
+ };
237
+ };
238
+ };
239
+ resonance_components: {
240
+ type: string;
241
+ description: string;
242
+ properties: {
243
+ vector_alignment: {
244
+ type: string;
245
+ minimum: number;
246
+ maximum: number;
247
+ };
248
+ context_continuity: {
249
+ type: string;
250
+ minimum: number;
251
+ maximum: number;
252
+ };
253
+ semantic_mirroring: {
254
+ type: string;
255
+ minimum: number;
256
+ maximum: number;
257
+ };
258
+ entropy_delta: {
259
+ type: string;
260
+ minimum: number;
261
+ maximum: number;
262
+ };
263
+ };
264
+ };
265
+ resonance_stakes: {
266
+ type: string;
267
+ description: string;
268
+ properties: {
269
+ level: {
270
+ type: string;
271
+ enum: string[];
272
+ };
273
+ confidence: {
274
+ type: string;
275
+ minimum: number;
276
+ maximum: number;
277
+ };
278
+ };
279
+ };
280
+ resonance_adversarial: {
281
+ type: string;
282
+ description: string;
283
+ properties: {
284
+ detected: {
285
+ type: string;
286
+ };
287
+ penalty: {
288
+ type: string;
289
+ minimum: number;
290
+ maximum: number;
291
+ };
292
+ keyword_density: {
293
+ type: string;
294
+ minimum: number;
295
+ maximum: number;
296
+ };
297
+ ethics_bypass_score: {
298
+ type: string;
299
+ minimum: number;
300
+ maximum: number;
301
+ };
302
+ };
303
+ };
304
+ };
305
+ };
306
+ policy_state: {
307
+ type: string;
308
+ description: string;
309
+ properties: {
310
+ constraints_applied: {
311
+ type: string;
312
+ description: string;
313
+ items: {
314
+ type: string;
315
+ example: string[];
316
+ };
317
+ };
318
+ violations: {
319
+ type: string;
320
+ description: string;
321
+ items: {
322
+ type: string;
323
+ properties: {
324
+ rule: {
325
+ type: string;
326
+ description: string;
327
+ };
328
+ severity: {
329
+ type: string;
330
+ enum: string[];
331
+ description: string;
332
+ };
333
+ action: {
334
+ type: string;
335
+ enum: string[];
336
+ description: string;
337
+ };
338
+ };
339
+ };
340
+ };
341
+ consent_verified: {
342
+ type: string;
343
+ description: string;
344
+ };
345
+ override_available: {
346
+ type: string;
347
+ description: string;
348
+ };
349
+ };
350
+ };
351
+ chain: {
352
+ type: string;
353
+ description: string;
354
+ required: string[];
355
+ properties: {
356
+ previous_hash: {
357
+ type: string;
358
+ description: string;
359
+ pattern: string;
360
+ };
361
+ chain_hash: {
362
+ type: string;
363
+ description: string;
364
+ pattern: string;
365
+ };
366
+ chain_length: {
367
+ type: string;
368
+ description: string;
369
+ minimum: number;
370
+ example: number;
371
+ };
372
+ };
373
+ };
374
+ signature: {
375
+ type: string;
376
+ description: string;
377
+ required: string[];
378
+ properties: {
379
+ algorithm: {
380
+ type: string;
381
+ enum: string[];
382
+ description: string;
383
+ };
384
+ value: {
385
+ type: string;
386
+ description: string;
387
+ example: string;
388
+ };
389
+ key_version: {
390
+ type: string;
391
+ description: string;
392
+ example: string;
393
+ };
394
+ timestamp_signed: {
395
+ type: string;
396
+ format: string;
397
+ description: string;
398
+ };
399
+ };
400
+ };
401
+ metadata: {
402
+ type: string;
403
+ description: string;
404
+ properties: {
405
+ tags: {
406
+ type: string;
407
+ description: string;
408
+ items: {
409
+ type: string;
410
+ };
411
+ };
412
+ context: {
413
+ type: string;
414
+ description: string;
415
+ additionalProperties: boolean;
416
+ };
417
+ user_agent: {
418
+ type: string;
419
+ description: string;
420
+ };
421
+ };
422
+ };
423
+ policy_enforcement: {
424
+ type: string;
425
+ description: string;
426
+ properties: {
427
+ policies_evaluated: {
428
+ type: string;
429
+ description: string;
430
+ items: {
431
+ type: string;
432
+ };
433
+ };
434
+ violations: {
435
+ type: string;
436
+ description: string;
437
+ items: {
438
+ type: string;
439
+ properties: {
440
+ id: {
441
+ type: string;
442
+ description: string;
443
+ };
444
+ constraint_id: {
445
+ type: string;
446
+ description: string;
447
+ };
448
+ constraint_name: {
449
+ type: string;
450
+ description: string;
451
+ };
452
+ violation_type: {
453
+ type: string;
454
+ enum: string[];
455
+ description: string;
456
+ };
457
+ severity: {
458
+ type: string;
459
+ enum: string[];
460
+ description: string;
461
+ };
462
+ message: {
463
+ type: string;
464
+ description: string;
465
+ };
466
+ evidence: {
467
+ type: string;
468
+ description: string;
469
+ additionalProperties: boolean;
470
+ };
471
+ receipt_annotation: {
472
+ type: string;
473
+ description: string;
474
+ };
475
+ detected_at: {
476
+ type: string;
477
+ format: string;
478
+ description: string;
479
+ };
480
+ remediation_suggested: {
481
+ type: string;
482
+ description: string;
483
+ };
484
+ };
485
+ required: string[];
486
+ };
487
+ };
488
+ status: {
489
+ type: string;
490
+ enum: string[];
491
+ description: string;
492
+ };
493
+ human_review_required: {
494
+ type: string;
495
+ description: string;
496
+ };
497
+ enforcement_timestamp: {
498
+ type: string;
499
+ format: string;
500
+ description: string;
501
+ };
502
+ actions_taken: {
503
+ type: string;
504
+ description: string;
505
+ items: {
506
+ type: string;
507
+ enum: string[];
508
+ };
509
+ };
510
+ };
511
+ };
512
+ };
513
+ additionalProperties: boolean;
514
+ };
515
+ export declare const SCHEMA_VERSION = "2.0.0";
516
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,SAAS,EACT,WAAW,EACX,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,GAAG,GACJ,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAK9G,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAAoB,CAAC;AAGhD,eAAO,MAAM,cAAc,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ /**
3
+ * @sonate/schemas
4
+ *
5
+ * Shared schema definitions for SONATE platform
6
+ * - Receipt schema (JSON Schema + TypeScript)
7
+ * - DID schema
8
+ * - Runtime validators
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * import { TrustReceipt, receiptValidator } from '@sonate/schemas';
13
+ *
14
+ * const receipt: TrustReceipt = { ... };
15
+ * const result = receiptValidator.validateJSON(receipt);
16
+ *
17
+ * if (result.valid) {
18
+ * console.log('Receipt is valid');
19
+ * } else {
20
+ * console.error('Validation errors:', result.errors);
21
+ * }
22
+ * ```
23
+ */
24
+ var __importDefault = (this && this.__importDefault) || function (mod) {
25
+ return (mod && mod.__esModule) ? mod : { "default": mod };
26
+ };
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.SCHEMA_VERSION = exports.RECEIPT_SCHEMA = exports.isReceiptProcessable = exports.validateReceiptZod = exports.validateReceiptJSON = exports.receiptValidator = void 0;
29
+ // Export validators
30
+ var validator_1 = require("./validator");
31
+ Object.defineProperty(exports, "receiptValidator", { enumerable: true, get: function () { return validator_1.receiptValidator; } });
32
+ Object.defineProperty(exports, "validateReceiptJSON", { enumerable: true, get: function () { return validator_1.validateReceiptJSON; } });
33
+ Object.defineProperty(exports, "validateReceiptZod", { enumerable: true, get: function () { return validator_1.validateReceiptZod; } });
34
+ Object.defineProperty(exports, "isReceiptProcessable", { enumerable: true, get: function () { return validator_1.isReceiptProcessable; } });
35
+ // Export schema
36
+ const receipt_schema_json_1 = __importDefault(require("./receipt.schema.json"));
37
+ exports.RECEIPT_SCHEMA = receipt_schema_json_1.default;
38
+ // Version
39
+ exports.SCHEMA_VERSION = '2.0.0';
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;;;;AAyBH,oBAAoB;AACpB,yCAA8G;AAArG,6GAAA,gBAAgB,OAAA;AAAE,gHAAA,mBAAmB,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAAE,iHAAA,oBAAoB,OAAA;AAExF,gBAAgB;AAChB,gFAAsD;AAEzC,QAAA,cAAc,GAAG,6BAAiB,CAAC;AAEhD,UAAU;AACG,QAAA,cAAc,GAAG,OAAO,CAAC"}