docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
A utility for verifying the integrity of packages in a content-addressable file store.
Build a tool that can verify package integrity in a content-addressable storage system where files are stored by their cryptographic hash. The system should be able to check that stored files match their expected content hashes and detect any corrupted or missing files.
Calculate cryptographic hashes for file content to verify integrity.
Generate storage paths based on content hashes following the pattern used in content-addressable file systems.
Verify that files in storage match their expected content hashes.
Check integrity of multiple files in a content-addressable store directory.
/**
* Computes SHA-512 hash of the given buffer content.
*
* @param {Buffer} content - The content to hash
* @returns {string} The SHA-512 hash as a hexadecimal string
*/
function computeHash(content) {
// IMPLEMENTATION HERE
}
/**
* Generates a content-addressable storage path from a hash.
* Uses first 2 characters as prefix directory.
*
* @param {string} hash - The content hash
* @param {boolean} isExecutable - Whether the file is executable
* @returns {string} The storage path (e.g., "ab/abc123" or "ab/abc123-exec")
*/
function generateStoragePath(hash, isExecutable = false) {
// IMPLEMENTATION HERE
}
/**
* Verifies that a file's content matches its expected hash.
*
* @param {string} filePath - Path to the file to verify
* @param {string} expectedHash - The expected SHA-512 hash
* @returns {Promise<boolean>} True if hash matches, false otherwise
* @throws {Error} If file cannot be read
*/
async function verifyFileIntegrity(filePath, expectedHash) {
// IMPLEMENTATION HERE
}
/**
* Checks integrity of all files in a content-addressable store.
*
* @param {string} storeDir - Root directory of the store
* @param {Object.<string, string>} expectedFiles - Map of relative paths to expected hashes
* @returns {Promise<Object>} Report with { valid: string[], corrupted: string[], missing: string[] }
*/
async function checkStoreIntegrity(storeDir, expectedFiles) {
// IMPLEMENTATION HERE
}
module.exports = {
computeHash,
generateStoragePath,
verifyFileIntegrity,
checkStoreIntegrity
};Provides reference implementation of content-addressable storage patterns and integrity verification.