SHA-256 cryptographic hash function implementation for TypeScript and JavaScript
91
Build a file integrity verification system that computes cryptographic checksums for files and verifies them later.
Create a module that provides two main functions:
computeChecksum(filePath): Reads a file in chunks and computes its SHA-256 hash
verifyChecksum(filePath, expectedHash): Verifies if a file matches an expected hash
The implementation should handle files of any size efficiently by processing them in chunks rather than loading them entirely into memory.
Provides SHA-256 cryptographic hashing functionality.
Provides hexadecimal encoding/decoding utilities.
@generates
/**
* Computes the SHA-256 checksum of a file by reading it in chunks.
*
* @param filePath - Path to the file to hash
* @returns Promise that resolves to hex-encoded SHA-256 hash
* @throws Error if file cannot be read
*/
export function computeChecksum(filePath: string): Promise<string>;
/**
* Verifies if a file matches an expected SHA-256 checksum.
*
* @param filePath - Path to the file to verify
* @param expectedHash - Expected hex-encoded SHA-256 hash
* @returns Promise that resolves to true if hash matches, false otherwise
* @throws Error if file cannot be read
*/
export function verifyChecksum(filePath: string, expectedHash: string): Promise<boolean>;Install with Tessl CLI
npx tessl i tessl/npm-stablelib--sha256docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10