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

Password Key Derivation Validator

Build a password key derivation utility that validates input parameters and derives cryptographic keys from passwords using the scrypt algorithm.

Capabilities

Parameter Validation

  • When N parameter is not a power of 2 (e.g., N=1000), it throws an error @test
  • When N parameter is 0, it throws an error @test
  • When r parameter is 3.5 (not an integer), it throws an error @test
  • When p parameter is 2.7 (not an integer), it throws an error @test
  • When dkLen parameter is -10 (negative), it throws an error @test

Password and Salt Validation

  • When password is null, it throws an error @test
  • When password is a plain string "mypassword" (not array-like), it throws an error @test
  • When salt is undefined, it throws an error @test
  • When salt is a plain number 12345, it throws an error @test

Valid Input Handling

  • When all parameters are valid, it successfully derives a key with the specified length @test
  • When password and salt are Buffers with valid parameters N=1024, r=8, p=1, dkLen=32, it returns a 32-byte Uint8Array @test

Implementation

@generates

API

/**
 * Derives a cryptographic key from a password using scrypt algorithm.
 * Validates all input parameters before derivation.
 *
 * @param {ArrayLike<number>|Buffer} password - The password to derive a key from
 * @param {ArrayLike<number>|Buffer} salt - The cryptographic salt
 * @param {number} N - CPU/memory cost parameter (must be a power of 2)
 * @param {number} r - Block size parameter (must be a positive integer)
 * @param {number} p - Parallelization parameter (must be a positive integer)
 * @param {number} dkLen - Desired key length in bytes (must be positive)
 * @returns {Promise<Uint8Array>} A promise that resolves to the derived key
 * @throws {Error} Throws descriptive errors for invalid parameters
 */
async function deriveKey(password, salt, N, r, p, dkLen) {
  // IMPLEMENTATION HERE
}

module.exports = { deriveKey };

Dependencies { .dependencies }

scrypt-js { .dependency }

Provides scrypt password-based key derivation functionality with input validation.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-scrypt-js

tile.json