CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-scrypt-js

The scrypt password-based key derivation function with sync and cancellable async.

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-4/

Password-Based Key Storage System

Build a secure key storage system that derives cryptographic keys from user passwords and stores them in a standardized binary format.

Requirements

The system should provide functionality to:

  1. Derive a cryptographic key from a password and salt
  2. Store the derived key as binary data (byte array format)
  3. Support different key lengths (16, 32, or 64 bytes)
  4. Convert keys to hexadecimal strings for display
  5. Validate that derived keys are in the correct binary format

Implementation Details

Create a module that exports the following functions:

  • deriveKey(password, salt, keyLength) - Derives a cryptographic key from the given password and salt, returning it as a byte array. The keyLength parameter specifies the desired key length in bytes (16, 32, or 64).
  • keyToHex(keyBytes) - Converts a byte array key to a hexadecimal string representation.
  • isValidKeyFormat(key) - Checks if a key is in valid byte array format (should be a Uint8Array).

Use standard scrypt parameters for key derivation:

  • N (CPU/memory cost): 1024
  • r (block size): 8
  • p (parallelization): 1

Test Cases

  • Deriving a key from password "testpass" and salt "testsalt" with length 32 returns a Uint8Array of length 32 @test
  • Converting a Uint8Array key to hex produces a valid hexadecimal string @test
  • The isValidKeyFormat function returns true for Uint8Array and false for regular arrays @test
  • Deriving keys with different lengths (16, 32, 64) produces Uint8Array outputs of the correct size @test

@generates

/**
 * Derives a cryptographic key from a password and salt
 * @param {string} password - The password string
 * @param {string} salt - The salt string
 * @param {number} keyLength - Desired key length in bytes (16, 32, or 64)
 * @returns {Promise<Uint8Array>} The derived key as a Uint8Array
 */
async function deriveKey(password, salt, keyLength) {
  // Implementation here
}

/**
 * Converts a Uint8Array key to hexadecimal string
 * @param {Uint8Array} keyBytes - The key as byte array
 * @returns {string} Hexadecimal representation
 */
function keyToHex(keyBytes) {
  // Implementation here
}

/**
 * Validates that a key is in correct Uint8Array format
 * @param {*} key - The key to validate
 * @returns {boolean} True if key is a Uint8Array
 */
function isValidKeyFormat(key) {
  // Implementation here
}

module.exports = {
  deriveKey,
  keyToHex,
  isValidKeyFormat
};

Dependencies { .dependencies }

scrypt-js { .dependency }

Provides password-based key derivation functionality.

Install with Tessl CLI

npx tessl i tessl/npm-scrypt-js

tile.json