UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

24 lines 968 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.uuidToSafeInt64String = void 0; const crypto = require("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. */ 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(); } exports.uuidToSafeInt64String = uuidToSafeInt64String; //# sourceMappingURL=cxOneKnowledgeHubUtils.js.map