mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
utf8HeadExcerpt and utf8TailExcerpt now return ExcerptText, a branded string. compactStringIdentityKey takes NotExcerpt<T>, so passing a display excerpt where an identity key is expected is a compile error (covered by an @ts-expect-error test). Two consumers that re-derived truncation by comparing an excerpt with its source (environment replay metadata, rizin frame history) read the helper's truncated fact instead.
17 lines
589 B
TypeScript
17 lines
589 B
TypeScript
import { digestCanonicalValue } from "./canonicalDigest.js";
|
|
import type { NotExcerpt } from "./excerpt.js";
|
|
|
|
/**
|
|
* Retain short exact string keys or commit their value in a reserved digest
|
|
* namespace. A display excerpt is not the value, so it is refused.
|
|
*/
|
|
export const compactStringIdentityKey = <Value extends string>(
|
|
value: NotExcerpt<Value>,
|
|
): string => {
|
|
const prefix = "value-sha256:";
|
|
const digestKey = `${prefix}${digestCanonicalValue(value, "String identity")}`;
|
|
return value.length <= digestKey.length && !value.startsWith(prefix)
|
|
? value
|
|
: digestKey;
|
|
};
|