@keypo/synapse-storage-sdk
Version:
TypeScript SDK for encrypted file storage on Filecoin via Synapse
16 lines (15 loc) • 606 B
JavaScript
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));
};