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

Password Key Derivation System

Build a system that derives encryption keys from user passwords using a cryptographic key derivation function. The system must operate asynchronously and provide progress feedback during key generation.

Requirements

Implement a key derivation module that:

  1. Derives 32-byte encryption keys asynchronously from passwords without blocking execution
  2. Uses cryptographic parameters: N=16384, r=8, p=1, dkLen=32
  3. Tracks and reports progress during the key derivation process
  4. Handles multiple derivation requests with different passwords and salts
  5. Returns derived keys as hexadecimal strings

Function Interface

Implement a function deriveKey(password, salt, progressCallback) that:

  • Accepts password as a string
  • Accepts salt as a hexadecimal string
  • Accepts an optional progress callback function
  • Returns a Promise that resolves to a hexadecimal string (64 characters representing 32 bytes)
  • The progress callback receives a number from 0 to 1 indicating completion percentage

Implementation Files

Create the following files:

  • keyDerivation.js - Main implementation with the deriveKey function
  • keyDerivation.test.js - Test file containing the test cases

Test Cases { .tests }

Test Case 1: Basic Async Key Derivation { .test }

Input:

  • Password: "MySecurePassword123"
  • Salt: "1234567890abcdef1234567890abcdef"

Expected behavior:

  • Function returns a Promise
  • Promise resolves to a 64-character hexadecimal string
  • Process completes without errors

Test Case 2: Progress Callback Invocation { .test }

Input:

  • Password: "AnotherPassword456"
  • Salt: "fedcba0987654321fedcba0987654321"
  • Progress callback that tracks all progress values

Expected behavior:

  • Progress callback is invoked at least once during derivation
  • Progress values are numbers between 0 and 1
  • Final progress value reported is 1.0
  • Promise resolves to a 64-character hexadecimal string

Test Case 3: Different Salts Produce Different Keys { .test }

Input:

  • First call: password "TestPassword", salt "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0"
  • Second call: password "TestPassword", salt "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb1"

Expected behavior:

  • Both Promises resolve successfully
  • The two derived keys are different
  • Both keys are 64-character hexadecimal strings

Dependencies { .dependencies }

scrypt-js { .dependency }

Provides password-based key derivation functionality.

Install with Tessl CLI

npx tessl i tessl/npm-scrypt-js

tile.json