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-5/

Batch Password Derivation Utility

Build a utility that efficiently derives cryptographic keys from multiple passwords using memory-efficient array operations.

Requirements

Your utility should process a list of passwords and derive keys for each one, handling the array-based inputs and outputs efficiently to minimize memory overhead.

Core Functionality

Implement a function deriveKeys that:

  • Accepts an array of password strings
  • Accepts a salt string
  • Returns an array of derived keys in hexadecimal format

Each derived key should be 32 bytes long and use the following scrypt parameters:

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

Input Handling

  • Convert password and salt strings to appropriate byte array formats
  • Handle the conversion between JavaScript strings and typed arrays efficiently
  • Ensure proper encoding of Unicode characters

Output Format

  • Return derived keys as hexadecimal strings
  • Convert the typed array output to hexadecimal format
  • Each hex string should represent the full 32-byte key

Test Cases

  • Given passwords ["password1", "password2"] and salt "salt123", the function returns an array of two 64-character hexadecimal strings (32 bytes = 64 hex chars). @test
  • Given an empty password array [] and any salt, the function returns an empty array. @test
  • Given passwords ["test"] and salt "sea", the derived key has exactly 64 hexadecimal characters. @test

Implementation

@generates

API

/**
 * Derives cryptographic keys from multiple passwords using scrypt.
 * Uses memory-efficient array operations for conversion and processing.
 *
 * @param {string[]} passwords - Array of password strings to derive keys from
 * @param {string} salt - Salt string used for all derivations
 * @returns {Promise<string[]>} Promise resolving to array of derived keys in hexadecimal format
 */
async function deriveKeys(passwords, salt) {
  // Implementation
}

module.exports = { deriveKeys };

Dependencies { .dependencies }

scrypt-js { .dependency }

Provides password-based key derivation functionality.

Install with Tessl CLI

npx tessl i tessl/npm-scrypt-js

tile.json