@noeos/verification-engine 0.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/CHANGELOG.md +8 -0
- package/LICENSE +201 -0
- package/NOTICE +11 -0
- package/README.md +7 -0
- package/dist/cjs/api/engine.js +271 -0
- package/dist/cjs/api/types.js +10 -0
- package/dist/cjs/chains/chain-builder.js +541 -0
- package/dist/cjs/chains/duplicate-detector.js +208 -0
- package/dist/cjs/chains/verify-chain.js +656 -0
- package/dist/cjs/contracts/generated.js +512 -0
- package/dist/cjs/contracts/schema-assets.js +6 -0
- package/dist/cjs/contracts/vector-assets.js +6 -0
- package/dist/cjs/domain/algorithm-id.js +5 -0
- package/dist/cjs/domain/byte-view.js +7 -0
- package/dist/cjs/domain/chain.js +3 -0
- package/dist/cjs/domain/diagnostic.js +6 -0
- package/dist/cjs/domain/digest.js +37 -0
- package/dist/cjs/domain/duplicate-policy.js +3 -0
- package/dist/cjs/domain/evidence.js +10 -0
- package/dist/cjs/domain/identifiers.js +52 -0
- package/dist/cjs/domain/json-value.js +3 -0
- package/dist/cjs/domain/limits.js +24 -0
- package/dist/cjs/domain/operation-result.js +19 -0
- package/dist/cjs/domain/position.js +16 -0
- package/dist/cjs/domain/protocol-version.js +5 -0
- package/dist/cjs/domain/rule.js +3 -0
- package/dist/cjs/domain/stream.js +3 -0
- package/dist/cjs/domain/version.js +16 -0
- package/dist/cjs/evidence/digest-evidence.js +22 -0
- package/dist/cjs/evidence/evidence-parser.js +288 -0
- package/dist/cjs/framing/frame-builders.js +124 -0
- package/dist/cjs/framing/frame-encoder.js +238 -0
- package/dist/cjs/framing/frame-parser.js +173 -0
- package/dist/cjs/framing/frame-types.js +3 -0
- package/dist/cjs/hashing/hash-adapter.js +90 -0
- package/dist/cjs/hashing/hash-frame.js +16 -0
- package/dist/cjs/index.js +16 -0
- package/dist/cjs/normalization/byte-sink.js +70 -0
- package/dist/cjs/normalization/jcs-profile.js +154 -0
- package/dist/cjs/normalization/normalize.js +56 -0
- package/dist/cjs/normalization/profile-registry.js +66 -0
- package/dist/cjs/normalization/profile.js +3 -0
- package/dist/cjs/normalization/raw-bytes-profile.js +27 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/profiles.js +9 -0
- package/dist/cjs/records/record-service.js +278 -0
- package/dist/cjs/rules/rule-set.js +211 -0
- package/dist/cjs/schemas.js +6 -0
- package/dist/cjs/validation/algorithm-validation.js +12 -0
- package/dist/cjs/validation/diagnostic-collector.js +159 -0
- package/dist/cjs/validation/digest-validation.js +48 -0
- package/dist/cjs/validation/identifier-validation.js +33 -0
- package/dist/cjs/validation/json-text-parser.js +297 -0
- package/dist/cjs/validation/json-value-validation.js +155 -0
- package/dist/cjs/validation/limit-validation.js +75 -0
- package/dist/cjs/validation/object-inspection.js +60 -0
- package/dist/cjs/validation/position-validation.js +13 -0
- package/dist/cjs/validation/result-helpers.js +9 -0
- package/dist/cjs/validation/utf8-validation.js +69 -0
- package/dist/cjs/validation/version-validation.js +31 -0
- package/dist/cjs/vectors.js +6 -0
- package/dist/esm/api/engine.js +266 -0
- package/dist/esm/api/types.js +4 -0
- package/dist/esm/chains/chain-builder.js +536 -0
- package/dist/esm/chains/duplicate-detector.js +204 -0
- package/dist/esm/chains/verify-chain.js +652 -0
- package/dist/esm/contracts/generated.js +509 -0
- package/dist/esm/contracts/schema-assets.js +2 -0
- package/dist/esm/contracts/vector-assets.js +2 -0
- package/dist/esm/domain/algorithm-id.js +2 -0
- package/dist/esm/domain/byte-view.js +4 -0
- package/dist/esm/domain/chain.js +2 -0
- package/dist/esm/domain/diagnostic.js +3 -0
- package/dist/esm/domain/digest.js +32 -0
- package/dist/esm/domain/duplicate-policy.js +2 -0
- package/dist/esm/domain/evidence.js +7 -0
- package/dist/esm/domain/identifiers.js +45 -0
- package/dist/esm/domain/json-value.js +2 -0
- package/dist/esm/domain/limits.js +21 -0
- package/dist/esm/domain/operation-result.js +15 -0
- package/dist/esm/domain/position.js +12 -0
- package/dist/esm/domain/protocol-version.js +2 -0
- package/dist/esm/domain/rule.js +2 -0
- package/dist/esm/domain/stream.js +2 -0
- package/dist/esm/domain/version.js +12 -0
- package/dist/esm/evidence/digest-evidence.js +19 -0
- package/dist/esm/evidence/evidence-parser.js +281 -0
- package/dist/esm/framing/frame-builders.js +114 -0
- package/dist/esm/framing/frame-encoder.js +234 -0
- package/dist/esm/framing/frame-parser.js +170 -0
- package/dist/esm/framing/frame-types.js +2 -0
- package/dist/esm/hashing/hash-adapter.js +84 -0
- package/dist/esm/hashing/hash-frame.js +12 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/normalization/byte-sink.js +66 -0
- package/dist/esm/normalization/jcs-profile.js +151 -0
- package/dist/esm/normalization/normalize.js +52 -0
- package/dist/esm/normalization/profile-registry.js +62 -0
- package/dist/esm/normalization/profile.js +2 -0
- package/dist/esm/normalization/raw-bytes-profile.js +24 -0
- package/dist/esm/profiles.js +6 -0
- package/dist/esm/records/record-service.js +270 -0
- package/dist/esm/rules/rule-set.js +206 -0
- package/dist/esm/schemas.js +2 -0
- package/dist/esm/validation/algorithm-validation.js +9 -0
- package/dist/esm/validation/diagnostic-collector.js +154 -0
- package/dist/esm/validation/digest-validation.js +43 -0
- package/dist/esm/validation/identifier-validation.js +27 -0
- package/dist/esm/validation/json-text-parser.js +294 -0
- package/dist/esm/validation/json-value-validation.js +152 -0
- package/dist/esm/validation/limit-validation.js +71 -0
- package/dist/esm/validation/object-inspection.js +54 -0
- package/dist/esm/validation/position-validation.js +10 -0
- package/dist/esm/validation/result-helpers.js +6 -0
- package/dist/esm/validation/utf8-validation.js +63 -0
- package/dist/esm/validation/version-validation.js +26 -0
- package/dist/esm/vectors.js +2 -0
- package/dist/types/api/engine.d.ts +8 -0
- package/dist/types/api/types.d.ts +124 -0
- package/dist/types/chains/chain-builder.d.ts +42 -0
- package/dist/types/chains/duplicate-detector.d.ts +18 -0
- package/dist/types/chains/verify-chain.d.ts +9 -0
- package/dist/types/contracts/generated.d.ts +442 -0
- package/dist/types/contracts/schema-assets.d.ts +2 -0
- package/dist/types/contracts/vector-assets.d.ts +2 -0
- package/dist/types/domain/algorithm-id.d.ts +4 -0
- package/dist/types/domain/byte-view.d.ts +1 -0
- package/dist/types/domain/chain.d.ts +43 -0
- package/dist/types/domain/diagnostic.d.ts +23 -0
- package/dist/types/domain/digest.d.ts +12 -0
- package/dist/types/domain/duplicate-policy.d.ts +26 -0
- package/dist/types/domain/evidence.d.ts +100 -0
- package/dist/types/domain/identifiers.d.ts +29 -0
- package/dist/types/domain/json-value.d.ts +6 -0
- package/dist/types/domain/limits.d.ts +13 -0
- package/dist/types/domain/operation-result.d.ts +12 -0
- package/dist/types/domain/position.d.ts +8 -0
- package/dist/types/domain/protocol-version.d.ts +2 -0
- package/dist/types/domain/rule.d.ts +34 -0
- package/dist/types/domain/stream.d.ts +5 -0
- package/dist/types/domain/version.d.ts +8 -0
- package/dist/types/evidence/digest-evidence.d.ts +4 -0
- package/dist/types/evidence/evidence-parser.d.ts +8 -0
- package/dist/types/framing/frame-builders.d.ts +40 -0
- package/dist/types/framing/frame-encoder.d.ts +6 -0
- package/dist/types/framing/frame-parser.d.ts +4 -0
- package/dist/types/framing/frame-types.d.ts +27 -0
- package/dist/types/hashing/hash-adapter.d.ts +12 -0
- package/dist/types/hashing/hash-frame.d.ts +6 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/normalization/byte-sink.d.ts +19 -0
- package/dist/types/normalization/jcs-profile.d.ts +3 -0
- package/dist/types/normalization/normalize.d.ts +11 -0
- package/dist/types/normalization/profile-registry.d.ts +26 -0
- package/dist/types/normalization/profile.d.ts +22 -0
- package/dist/types/normalization/raw-bytes-profile.d.ts +2 -0
- package/dist/types/profiles.d.ts +8 -0
- package/dist/types/records/record-service.d.ts +38 -0
- package/dist/types/rules/rule-set.d.ts +13 -0
- package/dist/types/schemas.d.ts +2 -0
- package/dist/types/validation/algorithm-validation.d.ts +3 -0
- package/dist/types/validation/diagnostic-collector.d.ts +24 -0
- package/dist/types/validation/digest-validation.d.ts +6 -0
- package/dist/types/validation/identifier-validation.d.ts +6 -0
- package/dist/types/validation/json-text-parser.d.ts +4 -0
- package/dist/types/validation/json-value-validation.d.ts +4 -0
- package/dist/types/validation/limit-validation.d.ts +4 -0
- package/dist/types/validation/object-inspection.d.ts +11 -0
- package/dist/types/validation/position-validation.d.ts +3 -0
- package/dist/types/validation/result-helpers.d.ts +3 -0
- package/dist/types/validation/utf8-validation.d.ts +5 -0
- package/dist/types/validation/version-validation.d.ts +9 -0
- package/dist/types/vectors.d.ts +2 -0
- package/package.json +61 -0
- package/schemas/chain-summary.v1.schema.json +156 -0
- package/schemas/diagnostic.v1.schema.json +107 -0
- package/schemas/link-evidence.v1.schema.json +165 -0
- package/schemas/record-evidence.v1.schema.json +91 -0
- package/schemas/vector-set.v1.schema.json +52 -0
- package/vectors/evidence.json +26 -0
- package/vectors/framing.json +136 -0
- package/vectors/hashing.json +58 -0
- package/vectors/invalid.json +56 -0
- package/vectors/manifest.json +46 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.success = success;
|
|
5
|
+
exports.failure = failure;
|
|
6
|
+
const EMPTY_DIAGNOSTICS = Object.freeze([]);
|
|
7
|
+
function success(value, diagnostics = []) {
|
|
8
|
+
return Object.freeze({
|
|
9
|
+
ok: true,
|
|
10
|
+
value,
|
|
11
|
+
diagnostics: diagnostics.length === 0 ? EMPTY_DIAGNOSTICS : Object.freeze([...diagnostics]),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function failure(diagnostics) {
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
ok: false,
|
|
17
|
+
diagnostics: diagnostics.length === 0 ? EMPTY_DIAGNOSTICS : Object.freeze([...diagnostics]),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.Position = void 0;
|
|
5
|
+
const positionBrand = Symbol("Position");
|
|
6
|
+
class Position {
|
|
7
|
+
value;
|
|
8
|
+
[positionBrand] = true;
|
|
9
|
+
constructor(value) {
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
static fromValidated(value) {
|
|
13
|
+
return Object.freeze(new Position(value));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.Position = Position;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ProfileVersion = void 0;
|
|
5
|
+
const profileVersionBrand = Symbol("ProfileVersion");
|
|
6
|
+
class ProfileVersion {
|
|
7
|
+
value;
|
|
8
|
+
[profileVersionBrand] = true;
|
|
9
|
+
constructor(value) {
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
static fromValidated(value) {
|
|
13
|
+
return Object.freeze(new ProfileVersion(value));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.ProfileVersion = ProfileVersion;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.digestEvidence = digestEvidence;
|
|
5
|
+
const frame_builders_js_1 = require("../framing/frame-builders.js");
|
|
6
|
+
const hash_frame_js_1 = require("../hashing/hash-frame.js");
|
|
7
|
+
const jcs_profile_js_1 = require("../normalization/jcs-profile.js");
|
|
8
|
+
const normalize_js_1 = require("../normalization/normalize.js");
|
|
9
|
+
const evidence_parser_js_1 = require("./evidence-parser.js");
|
|
10
|
+
function digestEvidence(value, limits) {
|
|
11
|
+
const evidence = (0, evidence_parser_js_1.parseEvidence)(value, limits);
|
|
12
|
+
if (!evidence.ok)
|
|
13
|
+
return evidence;
|
|
14
|
+
const normalized = (0, normalize_js_1.normalizeToBytes)(jcs_profile_js_1.jcsProfile, evidence.value, limits);
|
|
15
|
+
if (!normalized.ok)
|
|
16
|
+
return normalized;
|
|
17
|
+
return (0, hash_frame_js_1.hashTrustedFrame)(evidence.value.algorithm, (0, frame_builders_js_1.buildTrustedEvidenceFrame)({
|
|
18
|
+
algorithm: evidence.value.algorithm,
|
|
19
|
+
schemaUrn: evidence.value.$schema,
|
|
20
|
+
evidenceJcsBytes: normalized.value.bytes,
|
|
21
|
+
}, limits));
|
|
22
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.parseEvidence = parseEvidence;
|
|
5
|
+
exports.parseEvidenceText = parseEvidenceText;
|
|
6
|
+
exports.parseRecordEvidence = parseRecordEvidence;
|
|
7
|
+
exports.parseLinkEvidence = parseLinkEvidence;
|
|
8
|
+
exports.parseChainSummaryEvidence = parseChainSummaryEvidence;
|
|
9
|
+
const evidence_js_1 = require("../domain/evidence.js");
|
|
10
|
+
const operation_result_js_1 = require("../domain/operation-result.js");
|
|
11
|
+
const algorithm_validation_js_1 = require("../validation/algorithm-validation.js");
|
|
12
|
+
const diagnostic_collector_js_1 = require("../validation/diagnostic-collector.js");
|
|
13
|
+
const digest_validation_js_1 = require("../validation/digest-validation.js");
|
|
14
|
+
const identifier_validation_js_1 = require("../validation/identifier-validation.js");
|
|
15
|
+
const json_text_parser_js_1 = require("../validation/json-text-parser.js");
|
|
16
|
+
const object_inspection_js_1 = require("../validation/object-inspection.js");
|
|
17
|
+
const position_validation_js_1 = require("../validation/position-validation.js");
|
|
18
|
+
const version_validation_js_1 = require("../validation/version-validation.js");
|
|
19
|
+
const record_service_js_1 = require("../records/record-service.js");
|
|
20
|
+
function parseEvidence(value, limits) {
|
|
21
|
+
const entries = (0, object_inspection_js_1.inspectPlainObject)(value);
|
|
22
|
+
if (entries === undefined)
|
|
23
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
24
|
+
const schema = new Map(entries).get("$schema");
|
|
25
|
+
if (schema === evidence_js_1.RECORD_EVIDENCE_SCHEMA)
|
|
26
|
+
return parseRecordEvidence(value, limits);
|
|
27
|
+
if (schema === evidence_js_1.LINK_EVIDENCE_SCHEMA)
|
|
28
|
+
return parseLinkEvidence(value, limits);
|
|
29
|
+
if (schema === evidence_js_1.CHAIN_SUMMARY_EVIDENCE_SCHEMA)
|
|
30
|
+
return parseChainSummaryEvidence(value, limits);
|
|
31
|
+
return evidenceFailure("EVIDENCE_SCHEMA_UNKNOWN", limits);
|
|
32
|
+
}
|
|
33
|
+
function parseEvidenceText(value, limits) {
|
|
34
|
+
const parsed = (0, json_text_parser_js_1.parseJsonText)(value, limits);
|
|
35
|
+
if (!parsed.ok)
|
|
36
|
+
return parsed;
|
|
37
|
+
return parseEvidence(parsed.value, limits);
|
|
38
|
+
}
|
|
39
|
+
function parseRecordEvidence(value, limits) {
|
|
40
|
+
const fields = strictFields(value, [
|
|
41
|
+
"$schema",
|
|
42
|
+
"protocolVersion",
|
|
43
|
+
"contextId",
|
|
44
|
+
"recordId",
|
|
45
|
+
"profile",
|
|
46
|
+
"algorithm",
|
|
47
|
+
"normalizedByteLength",
|
|
48
|
+
"contentDigest",
|
|
49
|
+
"recordDigest",
|
|
50
|
+
]);
|
|
51
|
+
if (fields?.get("$schema") !== evidence_js_1.RECORD_EVIDENCE_SCHEMA) {
|
|
52
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
53
|
+
}
|
|
54
|
+
const common = parseRecordFields(fields, limits);
|
|
55
|
+
if (!common.ok)
|
|
56
|
+
return common;
|
|
57
|
+
return (0, operation_result_js_1.success)(Object.freeze({ $schema: evidence_js_1.RECORD_EVIDENCE_SCHEMA, ...common.value }));
|
|
58
|
+
}
|
|
59
|
+
function parseLinkEvidence(value, limits) {
|
|
60
|
+
const fields = strictFields(value, [
|
|
61
|
+
"$schema",
|
|
62
|
+
"protocolVersion",
|
|
63
|
+
"contextId",
|
|
64
|
+
"sequenceId",
|
|
65
|
+
"position",
|
|
66
|
+
"recordId",
|
|
67
|
+
"profile",
|
|
68
|
+
"algorithm",
|
|
69
|
+
"normalizedByteLength",
|
|
70
|
+
"contentDigest",
|
|
71
|
+
"recordDigest",
|
|
72
|
+
"previous",
|
|
73
|
+
"linkDigest",
|
|
74
|
+
]);
|
|
75
|
+
if (fields?.get("$schema") !== evidence_js_1.LINK_EVIDENCE_SCHEMA) {
|
|
76
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
77
|
+
}
|
|
78
|
+
const common = parseRecordFields(fields, limits);
|
|
79
|
+
const sequenceId = (0, identifier_validation_js_1.validateSequenceId)(fields.get("sequenceId"));
|
|
80
|
+
const position = (0, position_validation_js_1.validatePosition)(fields.get("position"));
|
|
81
|
+
if (!common.ok)
|
|
82
|
+
return common;
|
|
83
|
+
if (!sequenceId.ok)
|
|
84
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
85
|
+
if (!position.ok)
|
|
86
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
87
|
+
const previous = parsePrevious(fields.get("previous"), common.value.algorithm, limits);
|
|
88
|
+
const linkDigest = (0, digest_validation_js_1.validateDigest)(fields.get("linkDigest"), common.value.algorithm);
|
|
89
|
+
if (!previous.ok || !linkDigest.ok)
|
|
90
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
91
|
+
if ((position.value.value === 0) !== (previous.value.kind === "none")) {
|
|
92
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
93
|
+
}
|
|
94
|
+
return (0, operation_result_js_1.success)(Object.freeze({
|
|
95
|
+
$schema: evidence_js_1.LINK_EVIDENCE_SCHEMA,
|
|
96
|
+
...common.value,
|
|
97
|
+
sequenceId: sequenceId.value.value,
|
|
98
|
+
position: position.value.value,
|
|
99
|
+
previous: previous.value,
|
|
100
|
+
linkDigest: linkDigest.value.toHex(),
|
|
101
|
+
}));
|
|
102
|
+
}
|
|
103
|
+
function parseChainSummaryEvidence(value, limits) {
|
|
104
|
+
const fields = strictFields(value, [
|
|
105
|
+
"$schema",
|
|
106
|
+
"protocolVersion",
|
|
107
|
+
"contextId",
|
|
108
|
+
"sequenceId",
|
|
109
|
+
"profile",
|
|
110
|
+
"algorithm",
|
|
111
|
+
"count",
|
|
112
|
+
"firstPosition",
|
|
113
|
+
"lastPosition",
|
|
114
|
+
"firstLinkDigest",
|
|
115
|
+
"finalLinkDigest",
|
|
116
|
+
"boundaries",
|
|
117
|
+
"status",
|
|
118
|
+
"diagnostics",
|
|
119
|
+
], true);
|
|
120
|
+
if (fields?.get("$schema") !== evidence_js_1.CHAIN_SUMMARY_EVIDENCE_SCHEMA) {
|
|
121
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
122
|
+
}
|
|
123
|
+
const protocol = (0, version_validation_js_1.validateProtocolVersion)(fields.get("protocolVersion"));
|
|
124
|
+
const contextId = (0, identifier_validation_js_1.validateContextId)(fields.get("contextId"));
|
|
125
|
+
const sequenceId = (0, identifier_validation_js_1.validateSequenceId)(fields.get("sequenceId"));
|
|
126
|
+
const profile = (0, record_service_js_1.validateProfile)(fields.get("profile"), limits);
|
|
127
|
+
const algorithm = (0, algorithm_validation_js_1.validateAlgorithmId)(fields.get("algorithm"));
|
|
128
|
+
const count = validateNonNegativeSafeInteger(fields.get("count"));
|
|
129
|
+
const boundaries = parseBoundaries(fields.get("boundaries"));
|
|
130
|
+
const status = fields.get("status");
|
|
131
|
+
const diagnostics = parseDiagnosticSummary(fields.get("diagnostics"));
|
|
132
|
+
if (!protocol.ok ||
|
|
133
|
+
!contextId.ok ||
|
|
134
|
+
!sequenceId.ok ||
|
|
135
|
+
!profile.ok ||
|
|
136
|
+
!algorithm.ok ||
|
|
137
|
+
count === undefined ||
|
|
138
|
+
boundaries === undefined ||
|
|
139
|
+
!isStatus(status) ||
|
|
140
|
+
diagnostics === undefined) {
|
|
141
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
142
|
+
}
|
|
143
|
+
if (count === 0) {
|
|
144
|
+
if (fields.has("firstPosition") ||
|
|
145
|
+
fields.has("lastPosition") ||
|
|
146
|
+
fields.has("firstLinkDigest") ||
|
|
147
|
+
fields.has("finalLinkDigest"))
|
|
148
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
149
|
+
return (0, operation_result_js_1.success)(Object.freeze({
|
|
150
|
+
$schema: evidence_js_1.CHAIN_SUMMARY_EVIDENCE_SCHEMA,
|
|
151
|
+
protocolVersion: 1,
|
|
152
|
+
contextId: contextId.value.value,
|
|
153
|
+
sequenceId: sequenceId.value.value,
|
|
154
|
+
profile: profile.value,
|
|
155
|
+
algorithm: algorithm.value,
|
|
156
|
+
count,
|
|
157
|
+
boundaries,
|
|
158
|
+
status,
|
|
159
|
+
diagnostics,
|
|
160
|
+
}));
|
|
161
|
+
}
|
|
162
|
+
if (!fields.has("firstPosition") ||
|
|
163
|
+
!fields.has("lastPosition") ||
|
|
164
|
+
!fields.has("firstLinkDigest") ||
|
|
165
|
+
!fields.has("finalLinkDigest"))
|
|
166
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
167
|
+
const firstPosition = validateNonNegativeSafeInteger(fields.get("firstPosition"));
|
|
168
|
+
const lastPosition = validateNonNegativeSafeInteger(fields.get("lastPosition"));
|
|
169
|
+
const firstDigest = (0, digest_validation_js_1.validateDigest)(fields.get("firstLinkDigest"), algorithm.value);
|
|
170
|
+
const finalDigest = (0, digest_validation_js_1.validateDigest)(fields.get("finalLinkDigest"), algorithm.value);
|
|
171
|
+
if (firstPosition === undefined ||
|
|
172
|
+
lastPosition === undefined ||
|
|
173
|
+
firstPosition > lastPosition ||
|
|
174
|
+
!firstDigest.ok ||
|
|
175
|
+
!finalDigest.ok)
|
|
176
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
177
|
+
return (0, operation_result_js_1.success)(Object.freeze({
|
|
178
|
+
$schema: evidence_js_1.CHAIN_SUMMARY_EVIDENCE_SCHEMA,
|
|
179
|
+
protocolVersion: 1,
|
|
180
|
+
contextId: contextId.value.value,
|
|
181
|
+
sequenceId: sequenceId.value.value,
|
|
182
|
+
profile: profile.value,
|
|
183
|
+
algorithm: algorithm.value,
|
|
184
|
+
count,
|
|
185
|
+
firstPosition,
|
|
186
|
+
lastPosition,
|
|
187
|
+
firstLinkDigest: firstDigest.value.toHex(),
|
|
188
|
+
finalLinkDigest: finalDigest.value.toHex(),
|
|
189
|
+
boundaries,
|
|
190
|
+
status,
|
|
191
|
+
diagnostics,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
function parseRecordFields(fields, limits) {
|
|
195
|
+
const protocol = (0, version_validation_js_1.validateProtocolVersion)(fields.get("protocolVersion"));
|
|
196
|
+
const contextId = (0, identifier_validation_js_1.validateContextId)(fields.get("contextId"));
|
|
197
|
+
const recordId = (0, identifier_validation_js_1.validateRecordId)(fields.get("recordId"));
|
|
198
|
+
const profile = (0, record_service_js_1.validateProfile)(fields.get("profile"), limits);
|
|
199
|
+
const algorithm = (0, algorithm_validation_js_1.validateAlgorithmId)(fields.get("algorithm"));
|
|
200
|
+
const normalizedByteLength = validateNonNegativeSafeInteger(fields.get("normalizedByteLength"));
|
|
201
|
+
if (!protocol.ok ||
|
|
202
|
+
!contextId.ok ||
|
|
203
|
+
!recordId.ok ||
|
|
204
|
+
!profile.ok ||
|
|
205
|
+
!algorithm.ok ||
|
|
206
|
+
normalizedByteLength === undefined)
|
|
207
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
208
|
+
const contentDigest = (0, digest_validation_js_1.validateDigest)(fields.get("contentDigest"), algorithm.value);
|
|
209
|
+
const recordDigest = (0, digest_validation_js_1.validateDigest)(fields.get("recordDigest"), algorithm.value);
|
|
210
|
+
if (!contentDigest.ok || !recordDigest.ok)
|
|
211
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
212
|
+
return (0, operation_result_js_1.success)(Object.freeze({
|
|
213
|
+
protocolVersion: 1,
|
|
214
|
+
contextId: contextId.value.value,
|
|
215
|
+
recordId: recordId.value.value,
|
|
216
|
+
profile: profile.value,
|
|
217
|
+
algorithm: algorithm.value,
|
|
218
|
+
normalizedByteLength,
|
|
219
|
+
contentDigest: contentDigest.value.toHex(),
|
|
220
|
+
recordDigest: recordDigest.value.toHex(),
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
function parsePrevious(value, algorithm, limits) {
|
|
224
|
+
const fields = strictFields(value, ["kind", "value"], true);
|
|
225
|
+
if (fields === undefined)
|
|
226
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
227
|
+
if (fields.get("kind") === "none" && fields.size === 1)
|
|
228
|
+
return (0, operation_result_js_1.success)(Object.freeze({ kind: "none" }));
|
|
229
|
+
if (fields.get("kind") !== "digest" || fields.size !== 2)
|
|
230
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
231
|
+
const digest = (0, digest_validation_js_1.validateDigest)(fields.get("value"), algorithm);
|
|
232
|
+
if (!digest.ok)
|
|
233
|
+
return evidenceFailure("EVIDENCE_INVALID", limits);
|
|
234
|
+
return (0, operation_result_js_1.success)(Object.freeze({ kind: "digest", value: digest.value.toHex() }));
|
|
235
|
+
}
|
|
236
|
+
function parseBoundaries(value) {
|
|
237
|
+
const fields = strictFields(value, ["start", "end"]);
|
|
238
|
+
if (fields === undefined)
|
|
239
|
+
return undefined;
|
|
240
|
+
const start = fields.get("start");
|
|
241
|
+
const end = fields.get("end");
|
|
242
|
+
if (!isBoundary(start) || !isBoundary(end))
|
|
243
|
+
return undefined;
|
|
244
|
+
return Object.freeze({ start, end });
|
|
245
|
+
}
|
|
246
|
+
function parseDiagnosticSummary(value) {
|
|
247
|
+
const fields = strictFields(value, ["errors", "warnings", "info", "truncated"]);
|
|
248
|
+
if (fields === undefined)
|
|
249
|
+
return undefined;
|
|
250
|
+
const errors = validateNonNegativeSafeInteger(fields.get("errors"));
|
|
251
|
+
const warnings = validateNonNegativeSafeInteger(fields.get("warnings"));
|
|
252
|
+
const info = validateNonNegativeSafeInteger(fields.get("info"));
|
|
253
|
+
const truncated = fields.get("truncated");
|
|
254
|
+
if (errors === undefined ||
|
|
255
|
+
warnings === undefined ||
|
|
256
|
+
info === undefined ||
|
|
257
|
+
typeof truncated !== "boolean")
|
|
258
|
+
return undefined;
|
|
259
|
+
return Object.freeze({ errors, warnings, info, truncated });
|
|
260
|
+
}
|
|
261
|
+
function strictFields(value, keys, optional = false) {
|
|
262
|
+
const entries = (0, object_inspection_js_1.inspectPlainObject)(value);
|
|
263
|
+
if (entries === undefined)
|
|
264
|
+
return undefined;
|
|
265
|
+
const fields = new Map(entries);
|
|
266
|
+
for (const key of fields.keys())
|
|
267
|
+
if (!keys.includes(key))
|
|
268
|
+
return undefined;
|
|
269
|
+
if (!optional && fields.size !== keys.length)
|
|
270
|
+
return undefined;
|
|
271
|
+
if (optional && fields.size > keys.length)
|
|
272
|
+
return undefined;
|
|
273
|
+
return fields;
|
|
274
|
+
}
|
|
275
|
+
function validateNonNegativeSafeInteger(value) {
|
|
276
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
|
|
277
|
+
}
|
|
278
|
+
function isBoundary(value) {
|
|
279
|
+
return value === "verified" || value === "unverified" || value === "not-applicable";
|
|
280
|
+
}
|
|
281
|
+
function isStatus(value) {
|
|
282
|
+
return (value === "valid" || value === "invalid" || value === "indeterminate" || value === "aborted");
|
|
283
|
+
}
|
|
284
|
+
function evidenceFailure(code, limits) {
|
|
285
|
+
const collector = new diagnostic_collector_js_1.DiagnosticCollector(limits);
|
|
286
|
+
collector.addCode(code, "input");
|
|
287
|
+
return (0, operation_result_js_1.failure)(collector.finish());
|
|
288
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.buildContentFrame = buildContentFrame;
|
|
5
|
+
exports.buildRecordFrame = buildRecordFrame;
|
|
6
|
+
exports.buildLinkFrame = buildLinkFrame;
|
|
7
|
+
exports.buildEvidenceFrame = buildEvidenceFrame;
|
|
8
|
+
exports.buildTrustedContentFrame = buildTrustedContentFrame;
|
|
9
|
+
exports.buildTrustedRecordFrame = buildTrustedRecordFrame;
|
|
10
|
+
exports.buildTrustedLinkFrame = buildTrustedLinkFrame;
|
|
11
|
+
exports.buildTrustedEvidenceFrame = buildTrustedEvidenceFrame;
|
|
12
|
+
const digest_js_1 = require("../domain/digest.js");
|
|
13
|
+
const frame_encoder_js_1 = require("./frame-encoder.js");
|
|
14
|
+
function buildContentFrame(input, limits) {
|
|
15
|
+
const frame = {
|
|
16
|
+
kind: "content",
|
|
17
|
+
fields: [
|
|
18
|
+
{ tag: 1, type: "utf8", value: input.algorithm },
|
|
19
|
+
{ tag: 2, type: "utf8", value: input.profileId },
|
|
20
|
+
{ tag: 3, type: "utf8", value: input.profileVersion },
|
|
21
|
+
{ tag: 4, type: "bytes", value: input.normalizedBytes },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
return (0, frame_encoder_js_1.encodeFrame)(frame, limits);
|
|
25
|
+
}
|
|
26
|
+
function buildRecordFrame(input, limits) {
|
|
27
|
+
const frame = {
|
|
28
|
+
kind: "record",
|
|
29
|
+
fields: [
|
|
30
|
+
{ tag: 1, type: "utf8", value: input.algorithm },
|
|
31
|
+
{ tag: 2, type: "utf8", value: input.contextId },
|
|
32
|
+
{ tag: 3, type: "utf8", value: input.recordId },
|
|
33
|
+
{ tag: 4, type: "utf8", value: input.profileId },
|
|
34
|
+
{ tag: 5, type: "utf8", value: input.profileVersion },
|
|
35
|
+
{ tag: 6, type: "uint64", value: input.normalizedByteLength },
|
|
36
|
+
{ tag: 7, type: "bytes", value: input.contentDigest.toBytes() },
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
return (0, frame_encoder_js_1.encodeFrame)(frame, limits);
|
|
40
|
+
}
|
|
41
|
+
function buildLinkFrame(input, limits) {
|
|
42
|
+
const previous = input.previousLinkDigest;
|
|
43
|
+
const frame = {
|
|
44
|
+
kind: "link",
|
|
45
|
+
fields: [
|
|
46
|
+
{ tag: 1, type: "utf8", value: input.algorithm },
|
|
47
|
+
{ tag: 2, type: "utf8", value: input.contextId },
|
|
48
|
+
{ tag: 3, type: "utf8", value: input.sequenceId },
|
|
49
|
+
{ tag: 4, type: "uint64", value: input.position },
|
|
50
|
+
{ tag: 5, type: "utf8", value: input.recordId },
|
|
51
|
+
{ tag: 6, type: "bytes", value: input.recordDigest.toBytes() },
|
|
52
|
+
previous === undefined
|
|
53
|
+
? { tag: 7, type: "none" }
|
|
54
|
+
: { tag: 7, type: "bytes", value: previous.toBytes() },
|
|
55
|
+
],
|
|
56
|
+
};
|
|
57
|
+
return (0, frame_encoder_js_1.encodeFrame)(frame, limits);
|
|
58
|
+
}
|
|
59
|
+
function buildEvidenceFrame(input, limits) {
|
|
60
|
+
const frame = {
|
|
61
|
+
kind: "evidence",
|
|
62
|
+
fields: [
|
|
63
|
+
{ tag: 1, type: "utf8", value: input.algorithm },
|
|
64
|
+
{ tag: 2, type: "utf8", value: input.schemaUrn },
|
|
65
|
+
{ tag: 3, type: "bytes", value: input.evidenceJcsBytes },
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
return (0, frame_encoder_js_1.encodeFrame)(frame, limits);
|
|
69
|
+
}
|
|
70
|
+
function buildTrustedContentFrame(input, limits) {
|
|
71
|
+
return (0, frame_encoder_js_1.encodeTrustedFrame)({
|
|
72
|
+
kind: "content",
|
|
73
|
+
fields: [
|
|
74
|
+
{ tag: 1, type: "utf8", value: input.algorithm },
|
|
75
|
+
{ tag: 2, type: "utf8", value: input.profileId },
|
|
76
|
+
{ tag: 3, type: "utf8", value: input.profileVersion },
|
|
77
|
+
{ tag: 4, type: "bytes", value: input.normalizedBytes },
|
|
78
|
+
],
|
|
79
|
+
}, limits);
|
|
80
|
+
}
|
|
81
|
+
function buildTrustedRecordFrame(input, limits) {
|
|
82
|
+
return (0, frame_encoder_js_1.encodeTrustedFrame)({
|
|
83
|
+
kind: "record",
|
|
84
|
+
fields: [
|
|
85
|
+
{ tag: 1, type: "utf8", value: input.algorithm },
|
|
86
|
+
{ tag: 2, type: "utf8", value: input.contextId },
|
|
87
|
+
{ tag: 3, type: "utf8", value: input.recordId },
|
|
88
|
+
{ tag: 4, type: "utf8", value: input.profileId },
|
|
89
|
+
{ tag: 5, type: "utf8", value: input.profileVersion },
|
|
90
|
+
{ tag: 6, type: "uint64", value: input.normalizedByteLength },
|
|
91
|
+
{ tag: 7, type: "bytes", value: (0, digest_js_1.digestBytesForTrustedFrame)(input.contentDigest) },
|
|
92
|
+
],
|
|
93
|
+
}, limits);
|
|
94
|
+
}
|
|
95
|
+
function buildTrustedLinkFrame(input, limits) {
|
|
96
|
+
return (0, frame_encoder_js_1.encodeTrustedFrame)({
|
|
97
|
+
kind: "link",
|
|
98
|
+
fields: [
|
|
99
|
+
{ tag: 1, type: "utf8", value: input.algorithm },
|
|
100
|
+
{ tag: 2, type: "utf8", value: input.contextId },
|
|
101
|
+
{ tag: 3, type: "utf8", value: input.sequenceId },
|
|
102
|
+
{ tag: 4, type: "uint64", value: input.position },
|
|
103
|
+
{ tag: 5, type: "utf8", value: input.recordId },
|
|
104
|
+
{ tag: 6, type: "bytes", value: (0, digest_js_1.digestBytesForTrustedFrame)(input.recordDigest) },
|
|
105
|
+
input.previousLinkDigest === undefined
|
|
106
|
+
? { tag: 7, type: "none" }
|
|
107
|
+
: {
|
|
108
|
+
tag: 7,
|
|
109
|
+
type: "bytes",
|
|
110
|
+
value: (0, digest_js_1.digestBytesForTrustedFrame)(input.previousLinkDigest),
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
}, limits);
|
|
114
|
+
}
|
|
115
|
+
function buildTrustedEvidenceFrame(input, limits) {
|
|
116
|
+
return (0, frame_encoder_js_1.encodeTrustedFrame)({
|
|
117
|
+
kind: "evidence",
|
|
118
|
+
fields: [
|
|
119
|
+
{ tag: 1, type: "utf8", value: input.algorithm },
|
|
120
|
+
{ tag: 2, type: "utf8", value: input.schemaUrn },
|
|
121
|
+
{ tag: 3, type: "bytes", value: input.evidenceJcsBytes },
|
|
122
|
+
],
|
|
123
|
+
}, limits);
|
|
124
|
+
}
|