mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
refactor(javascript): share semantic fingerprint commitments (#15481)
This commit is contained in:
1 parent
0f372680a3
commit
d9b98366d8
1 file changed
+41
-47
@@ -681,6 +681,40 @@ export const createOwnedJavaScriptSemanticGraphUnknown = (
|
||||
): JavaScriptSemanticGraphUnknown =>
|
||||
sealSemanticUnknown(buildSemanticGraphUnknown(input, evidenceContexts));
|
||||
|
||||
const fingerprintComponentsDigest = (
|
||||
components: JavaScriptSemanticFingerprint["components"],
|
||||
): string => digestCanonicalValue(components, "JavaScript semantic graph");
|
||||
|
||||
const semanticFingerprintId = (
|
||||
fingerprint: Pick<
|
||||
JavaScriptSemanticFingerprint,
|
||||
"function_node_id" | "algorithm"
|
||||
>,
|
||||
componentDigest: string,
|
||||
): string =>
|
||||
`jsrg_fingerprint_${digestCanonicalValue(
|
||||
{
|
||||
function_node_id: fingerprint.function_node_id,
|
||||
algorithm: fingerprint.algorithm,
|
||||
fingerprint_sha256: componentDigest,
|
||||
},
|
||||
"JavaScript semantic graph",
|
||||
)}`;
|
||||
|
||||
const commitSemanticFingerprint = (
|
||||
semantic: Omit<
|
||||
JavaScriptSemanticFingerprint,
|
||||
"fingerprint_sha256" | "fingerprint_id"
|
||||
>,
|
||||
): JavaScriptSemanticFingerprint => {
|
||||
const componentDigest = fingerprintComponentsDigest(semantic.components);
|
||||
return {
|
||||
...semantic,
|
||||
fingerprint_sha256: componentDigest,
|
||||
fingerprint_id: semanticFingerprintId(semantic, componentDigest),
|
||||
};
|
||||
};
|
||||
|
||||
const buildSemanticFingerprint = (
|
||||
input: unknown,
|
||||
evidenceContexts: JavaScriptSemanticEvidenceContextRegistry,
|
||||
@@ -708,22 +742,7 @@ const buildSemanticFingerprint = (
|
||||
: uniqueSorted(parsedRest.data.limitations),
|
||||
evidence: fastEvidence,
|
||||
};
|
||||
const fingerprintSha256 = digestCanonicalValue(
|
||||
semantic.components,
|
||||
"JavaScript semantic graph",
|
||||
);
|
||||
return {
|
||||
...semantic,
|
||||
fingerprint_sha256: fingerprintSha256,
|
||||
fingerprint_id: `jsrg_fingerprint_${digestCanonicalValue(
|
||||
{
|
||||
function_node_id: semantic.function_node_id,
|
||||
algorithm: semantic.algorithm,
|
||||
fingerprint_sha256: fingerprintSha256,
|
||||
},
|
||||
"JavaScript semantic graph",
|
||||
)}`,
|
||||
};
|
||||
return commitSemanticFingerprint(semantic);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -743,22 +762,7 @@ const buildSemanticFingerprint = (
|
||||
rawEvidence,
|
||||
),
|
||||
};
|
||||
const fingerprintSha256 = digestCanonicalValue(
|
||||
semantic.components,
|
||||
"JavaScript semantic graph",
|
||||
);
|
||||
return {
|
||||
...semantic,
|
||||
fingerprint_sha256: fingerprintSha256,
|
||||
fingerprint_id: `jsrg_fingerprint_${digestCanonicalValue(
|
||||
{
|
||||
function_node_id: semantic.function_node_id,
|
||||
algorithm: semantic.algorithm,
|
||||
fingerprint_sha256: fingerprintSha256,
|
||||
},
|
||||
"JavaScript semantic graph",
|
||||
)}`,
|
||||
};
|
||||
return commitSemanticFingerprint(semantic);
|
||||
};
|
||||
|
||||
/** Normalize one function fingerprint and derive its component commitment. */
|
||||
@@ -1215,27 +1219,17 @@ function* checkFingerprintsSteps(
|
||||
if (!validatedSemanticFingerprints.has(fingerprint)) {
|
||||
if (
|
||||
fingerprint.fingerprint_sha256 !==
|
||||
digestCanonicalValue(
|
||||
fingerprint.components,
|
||||
"JavaScript semantic graph",
|
||||
)
|
||||
fingerprintComponentsDigest(fingerprint.components)
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["fingerprints", index, "fingerprint_sha256"],
|
||||
message: "Fingerprint component commitment is stale",
|
||||
});
|
||||
const expectedIdentifier =
|
||||
"jsrg_fingerprint_" +
|
||||
digestCanonicalValue(
|
||||
{
|
||||
function_node_id: fingerprint.function_node_id,
|
||||
algorithm: fingerprint.algorithm,
|
||||
fingerprint_sha256: fingerprint.fingerprint_sha256,
|
||||
},
|
||||
"JavaScript semantic graph",
|
||||
);
|
||||
if (fingerprint.fingerprint_id !== expectedIdentifier)
|
||||
if (
|
||||
fingerprint.fingerprint_id !==
|
||||
semanticFingerprintId(fingerprint, fingerprint.fingerprint_sha256)
|
||||
)
|
||||
context.addIssue({
|
||||
code: "custom",
|
||||
path: ["fingerprints", index, "fingerprint_id"],
|
||||
|
||||
Reference in new issue
Block a user