@uvrn/sdk 1.0.1 → 1.0.3
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 +5 -1
- package/dist/builder.d.ts +192 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +264 -0
- package/dist/builder.js.map +1 -0
- package/dist/client.d.ts +140 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +376 -0
- package/dist/client.js.map +1 -0
- package/dist/errors/index.d.ts +45 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +72 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +44 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/sdk.d.ts +150 -0
- package/dist/types/sdk.d.ts.map +1 -0
- package/dist/types/sdk.js +6 -0
- package/dist/types/sdk.js.map +1 -0
- package/dist/validators.d.ts +61 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +219 -0
- package/dist/validators.js.map +1 -0
- package/package.json +6 -3
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK-Specific Types for Delta Engine SDK
|
|
3
|
+
*/
|
|
4
|
+
import type { DeltaReceipt } from '@uvrn/core';
|
|
5
|
+
/**
|
|
6
|
+
* Execution mode for the Delta Engine client
|
|
7
|
+
*/
|
|
8
|
+
export type ClientMode = 'cli' | 'http' | 'local';
|
|
9
|
+
/**
|
|
10
|
+
* Configuration options for DeltaEngineClient
|
|
11
|
+
*/
|
|
12
|
+
export interface ClientOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Execution mode: 'cli' (spawn process), 'http' (API calls), or 'local' (direct import)
|
|
15
|
+
*/
|
|
16
|
+
mode: ClientMode;
|
|
17
|
+
/**
|
|
18
|
+
* Path to CLI executable (required for CLI mode)
|
|
19
|
+
*/
|
|
20
|
+
cliPath?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Base URL for HTTP API (required for HTTP mode)
|
|
23
|
+
* @example 'http://localhost:3000'
|
|
24
|
+
*/
|
|
25
|
+
apiUrl?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Request timeout in milliseconds
|
|
28
|
+
* @default 30000
|
|
29
|
+
*/
|
|
30
|
+
timeout?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Number of retry attempts on failure
|
|
33
|
+
* @default 3
|
|
34
|
+
*/
|
|
35
|
+
retries?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Detailed validation error information
|
|
39
|
+
*/
|
|
40
|
+
export interface ValidationError {
|
|
41
|
+
/**
|
|
42
|
+
* Field or path where validation failed
|
|
43
|
+
*/
|
|
44
|
+
field: string;
|
|
45
|
+
/**
|
|
46
|
+
* Error message describing the validation failure
|
|
47
|
+
*/
|
|
48
|
+
message: string;
|
|
49
|
+
/**
|
|
50
|
+
* Expected value or type
|
|
51
|
+
*/
|
|
52
|
+
expected?: string;
|
|
53
|
+
/**
|
|
54
|
+
* Actual value received
|
|
55
|
+
*/
|
|
56
|
+
actual?: unknown;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Result of bundle or receipt validation
|
|
60
|
+
*/
|
|
61
|
+
export interface ValidationResult {
|
|
62
|
+
/**
|
|
63
|
+
* Whether the validation passed
|
|
64
|
+
*/
|
|
65
|
+
valid: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* List of validation errors (if any)
|
|
68
|
+
*/
|
|
69
|
+
errors?: ValidationError[];
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Result of receipt verification (hash + determinism check)
|
|
73
|
+
*/
|
|
74
|
+
export interface VerificationResult {
|
|
75
|
+
/**
|
|
76
|
+
* Whether the receipt hash is valid
|
|
77
|
+
*/
|
|
78
|
+
verified: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Whether replay produced identical results (determinism check)
|
|
81
|
+
*/
|
|
82
|
+
deterministic: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Original hash from receipt
|
|
85
|
+
*/
|
|
86
|
+
originalHash?: string;
|
|
87
|
+
/**
|
|
88
|
+
* Recomputed hash from replay
|
|
89
|
+
*/
|
|
90
|
+
recomputedHash?: string;
|
|
91
|
+
/**
|
|
92
|
+
* Additional verification details
|
|
93
|
+
*/
|
|
94
|
+
details?: Record<string, unknown>;
|
|
95
|
+
/**
|
|
96
|
+
* Error message if verification failed
|
|
97
|
+
*/
|
|
98
|
+
error?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Result of replaying a receipt's bundle
|
|
102
|
+
*/
|
|
103
|
+
export interface ReplayResult {
|
|
104
|
+
/**
|
|
105
|
+
* Whether replay was successful
|
|
106
|
+
*/
|
|
107
|
+
success: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Original receipt being verified
|
|
110
|
+
*/
|
|
111
|
+
originalReceipt: DeltaReceipt;
|
|
112
|
+
/**
|
|
113
|
+
* New receipt from replay
|
|
114
|
+
*/
|
|
115
|
+
replayedReceipt?: DeltaReceipt;
|
|
116
|
+
/**
|
|
117
|
+
* Whether the results match exactly
|
|
118
|
+
*/
|
|
119
|
+
deterministic: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* Differences found (if any)
|
|
122
|
+
*/
|
|
123
|
+
differences?: string[];
|
|
124
|
+
/**
|
|
125
|
+
* Error message if replay failed
|
|
126
|
+
*/
|
|
127
|
+
error?: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Options for BundleBuilder
|
|
131
|
+
*/
|
|
132
|
+
export interface BundleBuilderOptions {
|
|
133
|
+
/**
|
|
134
|
+
* Bundle ID (generated if not provided)
|
|
135
|
+
*/
|
|
136
|
+
bundleId?: string;
|
|
137
|
+
/**
|
|
138
|
+
* Claim statement
|
|
139
|
+
*/
|
|
140
|
+
claim?: string;
|
|
141
|
+
/**
|
|
142
|
+
* Threshold percentage (0.0 to 1.0)
|
|
143
|
+
*/
|
|
144
|
+
thresholdPct?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Maximum number of rounds
|
|
147
|
+
*/
|
|
148
|
+
maxRounds?: number;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../src/types/sdk.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;IAEjB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf;;OAEG;IACH,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,EAAE,OAAO,CAAC;IAElB;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElC;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,eAAe,EAAE,YAAY,CAAC;IAE9B;;OAEG;IACH,eAAe,CAAC,EAAE,YAAY,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IAEvB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.js","sourceRoot":"","sources":["../../src/types/sdk.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validation and Verification Functions for Delta Engine SDK
|
|
3
|
+
*/
|
|
4
|
+
import type { DeltaBundle, DeltaReceipt } from '@uvrn/core';
|
|
5
|
+
import type { ValidationResult, ReplayResult } from './types/sdk';
|
|
6
|
+
/**
|
|
7
|
+
* Validates a Delta Bundle structure and data
|
|
8
|
+
*
|
|
9
|
+
* @param bundle - The bundle to validate
|
|
10
|
+
* @returns ValidationResult with errors if invalid
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const result = validateBundle(myBundle);
|
|
15
|
+
* if (!result.valid) {
|
|
16
|
+
* console.error('Validation errors:', result.errors);
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateBundle(bundle: unknown): ValidationResult;
|
|
21
|
+
/**
|
|
22
|
+
* Validates a Delta Receipt structure
|
|
23
|
+
*
|
|
24
|
+
* @param receipt - The receipt to validate
|
|
25
|
+
* @returns ValidationResult with errors if invalid
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateReceipt(receipt: unknown): ValidationResult;
|
|
28
|
+
/**
|
|
29
|
+
* Verifies the integrity of a receipt by recomputing its hash
|
|
30
|
+
*
|
|
31
|
+
* @param receipt - The receipt to verify
|
|
32
|
+
* @returns true if hash matches, false otherwise
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* const isValid = verifyReceiptHash(receipt);
|
|
37
|
+
* if (!isValid) {
|
|
38
|
+
* console.error('Receipt has been tampered with!');
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function verifyReceiptHash(receipt: DeltaReceipt): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Replays a receipt's bundle through the engine to verify determinism
|
|
45
|
+
*
|
|
46
|
+
* Note: This requires the engine to be available (local mode recommended)
|
|
47
|
+
*
|
|
48
|
+
* @param receipt - The receipt containing the bundle to replay
|
|
49
|
+
* @param executeFn - Function to execute bundle (provided by client)
|
|
50
|
+
* @returns ReplayResult with determinism check
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const result = await replayReceipt(receipt, (bundle) => client.runEngine(bundle));
|
|
55
|
+
* if (!result.deterministic) {
|
|
56
|
+
* console.error('Non-deterministic execution detected!');
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function replayReceipt(receipt: DeltaReceipt, _executeFn: (bundle: DeltaBundle) => Promise<DeltaReceipt>): Promise<ReplayResult>;
|
|
61
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAY,MAAM,YAAY,CAAC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAmB,YAAY,EAAE,MAAM,aAAa,CAAC;AAEnF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,OAAO,GAAG,gBAAgB,CAwDhE;AA8CD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CA8ClE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAQhE;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,GACzD,OAAO,CAAC,YAAY,CAAC,CAsBvB"}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validation and Verification Functions for Delta Engine SDK
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateBundle = validateBundle;
|
|
7
|
+
exports.validateReceipt = validateReceipt;
|
|
8
|
+
exports.verifyReceiptHash = verifyReceiptHash;
|
|
9
|
+
exports.replayReceipt = replayReceipt;
|
|
10
|
+
const core_1 = require("@uvrn/core");
|
|
11
|
+
/**
|
|
12
|
+
* Validates a Delta Bundle structure and data
|
|
13
|
+
*
|
|
14
|
+
* @param bundle - The bundle to validate
|
|
15
|
+
* @returns ValidationResult with errors if invalid
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const result = validateBundle(myBundle);
|
|
20
|
+
* if (!result.valid) {
|
|
21
|
+
* console.error('Validation errors:', result.errors);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function validateBundle(bundle) {
|
|
26
|
+
const errors = [];
|
|
27
|
+
// Check if bundle is an object
|
|
28
|
+
if (!bundle || typeof bundle !== 'object') {
|
|
29
|
+
return {
|
|
30
|
+
valid: false,
|
|
31
|
+
errors: [{ field: 'bundle', message: 'Bundle must be an object', expected: 'object', actual: typeof bundle }]
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const b = bundle;
|
|
35
|
+
// Validate bundleId
|
|
36
|
+
if (!b.bundleId || typeof b.bundleId !== 'string' || b.bundleId.trim() === '') {
|
|
37
|
+
errors.push({ field: 'bundleId', message: 'bundleId is required and must be a non-empty string', expected: 'string', actual: b.bundleId });
|
|
38
|
+
}
|
|
39
|
+
// Validate claim
|
|
40
|
+
if (!b.claim || typeof b.claim !== 'string' || b.claim.trim() === '') {
|
|
41
|
+
errors.push({ field: 'claim', message: 'claim is required and must be a non-empty string', expected: 'string', actual: b.claim });
|
|
42
|
+
}
|
|
43
|
+
// Validate dataSpecs
|
|
44
|
+
if (!Array.isArray(b.dataSpecs)) {
|
|
45
|
+
errors.push({ field: 'dataSpecs', message: 'dataSpecs must be an array', expected: 'array', actual: typeof b.dataSpecs });
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
if (b.dataSpecs.length === 0) {
|
|
49
|
+
errors.push({ field: 'dataSpecs', message: 'dataSpecs must contain at least one DataSpec', expected: 'non-empty array', actual: 'empty array' });
|
|
50
|
+
}
|
|
51
|
+
// Validate each DataSpec
|
|
52
|
+
b.dataSpecs.forEach((spec, index) => {
|
|
53
|
+
const specErrors = validateDataSpec(spec, `dataSpecs[${index}]`);
|
|
54
|
+
errors.push(...specErrors);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Validate thresholdPct
|
|
58
|
+
if (typeof b.thresholdPct !== 'number') {
|
|
59
|
+
errors.push({ field: 'thresholdPct', message: 'thresholdPct must be a number', expected: 'number', actual: typeof b.thresholdPct });
|
|
60
|
+
}
|
|
61
|
+
else if (b.thresholdPct < 0 || b.thresholdPct > 1) {
|
|
62
|
+
errors.push({ field: 'thresholdPct', message: 'thresholdPct must be between 0.0 and 1.0', expected: '0.0 to 1.0', actual: b.thresholdPct });
|
|
63
|
+
}
|
|
64
|
+
// Validate maxRounds (optional)
|
|
65
|
+
if (b.maxRounds !== undefined) {
|
|
66
|
+
if (typeof b.maxRounds !== 'number' || b.maxRounds < 1 || !Number.isInteger(b.maxRounds)) {
|
|
67
|
+
errors.push({ field: 'maxRounds', message: 'maxRounds must be a positive integer', expected: 'positive integer', actual: b.maxRounds });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
valid: errors.length === 0,
|
|
72
|
+
errors: errors.length > 0 ? errors : undefined
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Validates a DataSpec object
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
function validateDataSpec(spec, fieldPath) {
|
|
80
|
+
const errors = [];
|
|
81
|
+
if (!spec || typeof spec !== 'object') {
|
|
82
|
+
return [{ field: fieldPath, message: 'DataSpec must be an object', expected: 'object', actual: typeof spec }];
|
|
83
|
+
}
|
|
84
|
+
const s = spec;
|
|
85
|
+
// Validate id
|
|
86
|
+
if (!s.id || typeof s.id !== 'string') {
|
|
87
|
+
errors.push({ field: `${fieldPath}.id`, message: 'id is required and must be a string', expected: 'string', actual: s.id });
|
|
88
|
+
}
|
|
89
|
+
// Validate label
|
|
90
|
+
if (!s.label || typeof s.label !== 'string') {
|
|
91
|
+
errors.push({ field: `${fieldPath}.label`, message: 'label is required and must be a string', expected: 'string', actual: s.label });
|
|
92
|
+
}
|
|
93
|
+
// Validate sourceKind
|
|
94
|
+
const validSourceKinds = ['report', 'metric', 'chart', 'meta'];
|
|
95
|
+
if (!s.sourceKind || !validSourceKinds.includes(s.sourceKind)) {
|
|
96
|
+
errors.push({ field: `${fieldPath}.sourceKind`, message: `sourceKind must be one of: ${validSourceKinds.join(', ')}`, expected: validSourceKinds.join('|'), actual: s.sourceKind });
|
|
97
|
+
}
|
|
98
|
+
// Validate originDocIds
|
|
99
|
+
if (!Array.isArray(s.originDocIds)) {
|
|
100
|
+
errors.push({ field: `${fieldPath}.originDocIds`, message: 'originDocIds must be an array', expected: 'array', actual: typeof s.originDocIds });
|
|
101
|
+
}
|
|
102
|
+
// Validate metrics
|
|
103
|
+
if (!Array.isArray(s.metrics)) {
|
|
104
|
+
errors.push({ field: `${fieldPath}.metrics`, message: 'metrics must be an array', expected: 'array', actual: typeof s.metrics });
|
|
105
|
+
}
|
|
106
|
+
else if (s.metrics.length === 0) {
|
|
107
|
+
errors.push({ field: `${fieldPath}.metrics`, message: 'metrics must contain at least one MetricPoint', expected: 'non-empty array', actual: 'empty array' });
|
|
108
|
+
}
|
|
109
|
+
return errors;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Validates a Delta Receipt structure
|
|
113
|
+
*
|
|
114
|
+
* @param receipt - The receipt to validate
|
|
115
|
+
* @returns ValidationResult with errors if invalid
|
|
116
|
+
*/
|
|
117
|
+
function validateReceipt(receipt) {
|
|
118
|
+
const errors = [];
|
|
119
|
+
if (!receipt || typeof receipt !== 'object') {
|
|
120
|
+
return {
|
|
121
|
+
valid: false,
|
|
122
|
+
errors: [{ field: 'receipt', message: 'Receipt must be an object', expected: 'object', actual: typeof receipt }]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
const r = receipt;
|
|
126
|
+
// Validate bundleId
|
|
127
|
+
if (!r.bundleId || typeof r.bundleId !== 'string') {
|
|
128
|
+
errors.push({ field: 'bundleId', message: 'bundleId is required and must be a string', expected: 'string', actual: r.bundleId });
|
|
129
|
+
}
|
|
130
|
+
// Validate deltaFinal
|
|
131
|
+
if (typeof r.deltaFinal !== 'number') {
|
|
132
|
+
errors.push({ field: 'deltaFinal', message: 'deltaFinal must be a number', expected: 'number', actual: typeof r.deltaFinal });
|
|
133
|
+
}
|
|
134
|
+
// Validate sources
|
|
135
|
+
if (!Array.isArray(r.sources)) {
|
|
136
|
+
errors.push({ field: 'sources', message: 'sources must be an array', expected: 'array', actual: typeof r.sources });
|
|
137
|
+
}
|
|
138
|
+
// Validate rounds
|
|
139
|
+
if (!Array.isArray(r.rounds)) {
|
|
140
|
+
errors.push({ field: 'rounds', message: 'rounds must be an array', expected: 'array', actual: typeof r.rounds });
|
|
141
|
+
}
|
|
142
|
+
// Validate outcome
|
|
143
|
+
if (r.outcome !== 'consensus' && r.outcome !== 'indeterminate') {
|
|
144
|
+
errors.push({ field: 'outcome', message: 'outcome must be "consensus" or "indeterminate"', expected: 'consensus|indeterminate', actual: r.outcome });
|
|
145
|
+
}
|
|
146
|
+
// Validate hash
|
|
147
|
+
if (!r.hash || typeof r.hash !== 'string') {
|
|
148
|
+
errors.push({ field: 'hash', message: 'hash is required and must be a string', expected: 'string', actual: r.hash });
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
valid: errors.length === 0,
|
|
152
|
+
errors: errors.length > 0 ? errors : undefined
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Verifies the integrity of a receipt by recomputing its hash
|
|
157
|
+
*
|
|
158
|
+
* @param receipt - The receipt to verify
|
|
159
|
+
* @returns true if hash matches, false otherwise
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```typescript
|
|
163
|
+
* const isValid = verifyReceiptHash(receipt);
|
|
164
|
+
* if (!isValid) {
|
|
165
|
+
* console.error('Receipt has been tampered with!');
|
|
166
|
+
* }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
function verifyReceiptHash(receipt) {
|
|
170
|
+
try {
|
|
171
|
+
const { hash, ...payload } = receipt;
|
|
172
|
+
const computedHash = (0, core_1.hashReceipt)(payload);
|
|
173
|
+
return computedHash === hash;
|
|
174
|
+
}
|
|
175
|
+
catch (error) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Replays a receipt's bundle through the engine to verify determinism
|
|
181
|
+
*
|
|
182
|
+
* Note: This requires the engine to be available (local mode recommended)
|
|
183
|
+
*
|
|
184
|
+
* @param receipt - The receipt containing the bundle to replay
|
|
185
|
+
* @param executeFn - Function to execute bundle (provided by client)
|
|
186
|
+
* @returns ReplayResult with determinism check
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* const result = await replayReceipt(receipt, (bundle) => client.runEngine(bundle));
|
|
191
|
+
* if (!result.deterministic) {
|
|
192
|
+
* console.error('Non-deterministic execution detected!');
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
async function replayReceipt(receipt, _executeFn) {
|
|
197
|
+
try {
|
|
198
|
+
// Note: We would need the original bundle to replay
|
|
199
|
+
// In a real implementation, this might be stored with the receipt
|
|
200
|
+
// or reconstructed from receipt metadata
|
|
201
|
+
// The _executeFn parameter is prefixed with _ to indicate it will be used in future
|
|
202
|
+
// For now, return a structure that indicates we need the bundle
|
|
203
|
+
return {
|
|
204
|
+
success: false,
|
|
205
|
+
originalReceipt: receipt,
|
|
206
|
+
deterministic: false,
|
|
207
|
+
error: 'Replay not yet implemented - requires original bundle or bundle reconstruction'
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
return {
|
|
212
|
+
success: false,
|
|
213
|
+
originalReceipt: receipt,
|
|
214
|
+
deterministic: false,
|
|
215
|
+
error: error instanceof Error ? error.message : 'Unknown error during replay'
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAoBH,wCAwDC;AAoDD,0CA8CC;AAgBD,8CAQC;AAmBD,sCAyBC;AA/OD,qCAAyC;AAGzC;;;;;;;;;;;;;GAaG;AACH,SAAgB,cAAc,CAAC,MAAe;IAC5C,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,+BAA+B;IAC/B,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,0BAA0B,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;SAC9G,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,GAAG,MAA8B,CAAC;IAEzC,oBAAoB;IACpB,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;QAC9E,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,qDAAqD,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7I,CAAC;IAED,iBAAiB;IACjB,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE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;SAC9E,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uvrn/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
4
7
|
"description": "UVRN TypeScript SDK — programmatic access to deterministic verification",
|
|
5
8
|
"main": "dist/index.js",
|
|
6
9
|
"types": "dist/index.d.ts",
|
|
@@ -38,7 +41,7 @@
|
|
|
38
41
|
"jest": "^29.5.0",
|
|
39
42
|
"ts-jest": "^29.1.0",
|
|
40
43
|
"typescript": "^5.3.0",
|
|
41
|
-
"@uvrn/core": "1.0.
|
|
44
|
+
"@uvrn/core": "1.0.3"
|
|
42
45
|
},
|
|
43
46
|
"engines": {
|
|
44
47
|
"node": ">=18.0.0"
|
|
@@ -51,7 +54,7 @@
|
|
|
51
54
|
"scripts": {
|
|
52
55
|
"build": "npm run clean && tsc",
|
|
53
56
|
"build:watch": "tsc --watch",
|
|
54
|
-
"clean": "rm -rf dist dist-esm",
|
|
57
|
+
"clean": "rm -rf dist dist-esm tsconfig.tsbuildinfo",
|
|
55
58
|
"test": "jest",
|
|
56
59
|
"test:watch": "jest --watch",
|
|
57
60
|
"test:coverage": "jest --coverage",
|