CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-stablelib--sha256

SHA-256 cryptographic hash function implementation for TypeScript and JavaScript

91

0.98x
Overview
Eval results
Files

task.mdevals/scenario-8/

HMAC-like Hash Processor

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.

Requirements

Implement a HashProcessor class that:

  1. Accepts a secret prefix (as Uint8Array) during initialization
  2. Provides a method to hash messages that automatically prepends the secret prefix
  3. Optimizes performance by avoiding recomputation of the prefix for each message
  4. Provides a cleanup method to securely wipe all internal state

The processor should efficiently handle multiple messages without recomputing the hash of the prefix each time.

API

/**
 * 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;
}

Test Cases

  • When initialized with prefix [0x01, 0x02, 0x03] and hashing message [0x04, 0x05], produces the same hash as directly hashing [0x01, 0x02, 0x03, 0x04, 0x05] @test
  • When hashing two different messages with the same processor, both produce correct hashes without recomputing the prefix @test
  • When cleanup is called, internal state is securely wiped @test

Implementation

@generates

Dependencies { .dependencies }

@stablelib/sha256 { .dependency }

Provides SHA-256 cryptographic hash functionality with state serialization support.

Install with Tessl CLI

npx tessl i tessl/npm-stablelib--sha256

tile.json