UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

20 lines 803 B
import * as crypto from "crypto"; /** * Converts a UUID string to a safe int64 string using the lower 53 bits of SHA-256 hash. * Always returns a string representing a safe integer in the range [0, 2^53-1]. * @param uuid - The UUID string to convert. * @returns A string representation of a safe int64 value. */ export function uuidToSafeInt64String(uuid) { const hash = crypto.createHash("sha256").update(uuid).digest(); // Use the lower 53 bits from the first 7 bytes // 53 bits = 6 full bytes + 5 bits from the 7th byte let value = 0; for (let i = 0; i < 6; i++) { value = (value << 8) | hash[i]; } // Add lower 5 bits of the 7th byte value = (value << 5) | (hash[6] >> 3); return value.toString(); } //# sourceMappingURL=cxOneKnowledgeHubUtils.js.map