SHA-256 cryptographic hash function implementation for TypeScript and JavaScript
91
Build a hash processor that efficiently computes SHA-256 hashes for multiple messages using a shared secret prefix. The processor should optimize performance by reusing the computation of the shared prefix across multiple messages.
Implement a HashProcessor class that:
Uint8Array) during initializationThe processor should efficiently handle multiple messages without recomputing the hash of the prefix each time.
/**
* Hash processor that efficiently computes hashes with a shared secret prefix
*/
export class HashProcessor {
/**
* Creates a new hash processor with the given secret prefix
* @param secretPrefix - Secret data to prepend to all messages
*/
constructor(secretPrefix: Uint8Array);
/**
* Computes SHA-256 hash of (secretPrefix + message)
* @param message - Message data to hash
* @returns SHA-256 hash digest (32 bytes)
*/
hashMessage(message: Uint8Array): Uint8Array;
/**
* Securely cleans up all internal state
*/
cleanup(): void;
}[0x01, 0x02, 0x03] and hashing message [0x04, 0x05], produces the same hash as directly hashing [0x01, 0x02, 0x03, 0x04, 0x05] @test@generates
Provides SHA-256 cryptographic hash functionality with state serialization support.
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