UNPKG

@keypo/synapse-storage-sdk

Version:
16 lines (15 loc) 606 B
import { randomBytes } from 'crypto'; import { hashData } from './hash.js'; /** * Generate a unique data identifier based on content and randomness */ export const generateRandomDataIdentifier = (data) => { // Hash the data first const dataHash = hashData(data); // Generate 16 random bytes and convert to hex const randomComponent = randomBytes(16).toString('hex'); // Get current timestamp in milliseconds const timestamp = Date.now().toString(); // Combine data hash, random bytes, and timestamp return hashData(Buffer.from(dataHash + randomComponent + timestamp)); };