zeus-time
Version:
Deterministic, cryptographically verifiable time hashing for Node, browser, and Expo/React Native.
67 lines (59 loc) • 2.93 kB
TypeScript
type ZeusAlgorithm = "blake3" | "sha256";
type ZeusFormat = "hex" | "base64url";
interface ZeusOptions {
algorithm?: ZeusAlgorithm;
format?: ZeusFormat;
}
declare function normalizeTime(input: string | number | Date): string;
declare function zeusHash(input: string | number | Date, options?: ZeusOptions): string;
declare function generateZeusHash(input: string | number | Date, options?: ZeusOptions): Promise<string>;
declare function verifyZeusHash(input: string | number | Date, expectedHash: string, options?: ZeusOptions): boolean;
declare function unixToZeusSync(unix: number, options?: ZeusOptions): string;
declare function unixToZeus(unix: number, options?: ZeusOptions): Promise<string>;
declare function zeusToUnix(_zeusHash?: string): never;
declare function legacyUnixToZeus(unix: number, format?: ZeusOptions["format"]): string;
declare function legacyZeusHash(input: string | number | Date, format?: ZeusOptions["format"]): string;
/**
* v0.1 export: validateZeusTimestamp(timestamp, expectedHash)
* Returns true if the computed hash for the timestamp matches expectedHash.
*/
declare function validateZeusTimestamp(timestamp: string, expectedHash: string): Promise<boolean>;
/**
* v0.1 export: executeAtZeusEpoch(epochTime, callback)
* Polls once per second and triggers callback when current unix seconds hash equals epoch hash.
*/
declare function executeAtZeusEpoch(epochTime: number, callback: () => void): Promise<void>;
declare function legacyZeusToUnix(zeusTime: string): number;
declare function isValidUnixTimestampSeconds(value: unknown): value is number;
declare function isValidZeusHex(hash: unknown): hash is string;
declare function isValidZeusBase64Url(hash: unknown): hash is string;
type CanonMode = "utf8_exact" | "json_sorted_compact" | "bytes_b64";
type HashAlgo = "blake3" | "sha256";
interface PackOptions {
canon: CanonMode;
algo?: HashAlgo;
tag?: string;
}
interface ZPKParsed {
canon: CanonMode;
algo: HashAlgo;
tag?: string;
digest: string;
}
/**
* Pack a payload into a ZPK1 string.
*
* ZPK1 contains no raw data, only metadata and a digest.
* Output is strict and deterministic.
*/
declare function packZPK1(payload: unknown, opts: PackOptions): string;
/**
* Parse and validate a ZPK1 string.
* Throws on any violation.
*/
declare function unpackZPK1(packed: string): ZPKParsed;
/**
* Returns true if packed is valid ZPK1, otherwise false.
*/
declare function isValidZPK1(packed: string): boolean;
export { type CanonMode, type HashAlgo, type PackOptions, type ZPKParsed, type ZeusAlgorithm, type ZeusFormat, type ZeusOptions, executeAtZeusEpoch, generateZeusHash, isValidUnixTimestampSeconds, isValidZPK1, isValidZeusBase64Url, isValidZeusHex, legacyUnixToZeus, legacyZeusHash, legacyZeusToUnix, normalizeTime, packZPK1, unixToZeus, unixToZeusSync, unpackZPK1, validateZeusTimestamp, verifyZeusHash, zeusHash, zeusToUnix };