mirror of
https://github.com/morluto/rea
synced 2026-10-26 22:28:27 -04:00
refactor(javascript): group domain semantics and contracts (#907)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
import canonicalize from "canonicalize";
|
||||
|
||||
/** Canonically encode one export-shape comparison value. */
|
||||
export const canonicalExportShapeValue = (value: unknown): string => {
|
||||
const encoded = canonicalize(value);
|
||||
if (encoded === undefined)
|
||||
throw new TypeError(
|
||||
"JavaScript export shape comparison could not canonicalize data",
|
||||
);
|
||||
return encoded;
|
||||
};
|
||||
|
||||
/** Derive one deterministic SHA-256 comparison identifier component. */
|
||||
export const digestExportShapeValue = (value: unknown): string =>
|
||||
createHash("sha256").update(canonicalExportShapeValue(value)).digest("hex");
|
||||
Reference in New Issue
Block a user