refactor(domain): consolidate canonical ordering and digest helpers (#624)

* refactor(domain): consolidate canonical ordering and digest helpers

Single owner for code-point ordering (domain/canonicalOrdering.ts)
and canonical JSON digests (domain/comparisonSemantics.ts). Delete
all local compareCodePoints/compareText/digestCanonical duplicates
and migrate every importer. No re-export shims.

* fix(ci): allow slower real browser startup
This commit is contained in:
morluto
2026-10-06 04:55:26 +08:00
committed by GitHub
parent 38b293329c
commit ba3869c597
74 changed files with 438 additions and 530 deletions
+19 -23
View File
@@ -1,14 +1,11 @@
import { createHash } from "node:crypto";
import canonicalize from "canonicalize";
import { canonicalDigest } from "../domain/comparisonSemantics.js";
import { createEvidence } from "../domain/evidence.js";
import { jsonValueSchema } from "../domain/jsonValue.js";
const inventory = (digit: string) => {
const sha = digit.repeat(64);
const artifactId = `art_${digestCanonical({ sha256: sha })}`;
const occurrenceId = `occ_${digestCanonical({ root: artifactId })}`;
const artifactId = `art_${canonicalDigest({ sha256: sha }, "Artifact example")}`;
const occurrenceId = `occ_${canonicalDigest({ root: artifactId }, "Artifact example")}`;
const nodes = [
{
artifact_id: artifactId,
@@ -39,18 +36,24 @@ const inventory = (digit: string) => {
limitations: [],
},
];
const graphSha256 = digestCanonical({
nodes,
occurrences,
edges: [],
integrity_contradictions: [],
});
const graphSha256 = canonicalDigest(
{
nodes,
occurrences,
edges: [],
integrity_contradictions: [],
},
"Artifact example",
);
return jsonValueSchema.parse({
manifest: {
manifest_id: `agm_${digestCanonical({
root_artifact_id: artifactId,
graph_sha256: graphSha256,
})}`,
manifest_id: `agm_${canonicalDigest(
{
root_artifact_id: artifactId,
graph_sha256: graphSha256,
},
"Artifact example",
)}`,
root_artifact_id: artifactId,
root_sha256: sha,
root_format: "file",
@@ -67,13 +70,6 @@ const inventory = (digit: string) => {
});
};
const digestCanonical = (value: unknown): string => {
const encoded = canonicalize(value);
if (encoded === undefined)
throw new TypeError("Artifact example is not canonical JSON");
return createHash("sha256").update(encoded).digest("hex");
};
const provider = {
id: "rea-artifact",
name: "REA artifact graph",