mirror of
https://github.com/morluto/rea.git
synced 2026-10-29 19:05:45 +00:00
18 lines
629 B
TypeScript
18 lines
629 B
TypeScript
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");
|