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

Universal Password Hasher

Build a password hashing utility that works seamlessly across Node.js (CommonJS), AMD/RequireJS environments, and directly in browsers via script tags.

Requirements

Your module must:

  1. Export a hashPassword function that:

    • Accepts a password string as input
    • Returns a Promise that resolves to a hex-encoded hash string
    • Uses scrypt parameters: N=1024, r=8, p=1, dkLen=32
    • Uses a fixed salt "staticSalt123" (converted to UTF-8 bytes)
  2. Work correctly in all three environments:

    • Node.js: Exportable via require() (CommonJS pattern)
    • AMD/RequireJS: Loadable via define()
    • Browser: Available as a global variable after <script> tag load
  3. Preserve any pre-existing global variable with the same name when loaded in browsers

Implementation Details

  • Convert password and salt strings to byte arrays using UTF-8 encoding
  • Return the derived key as a hexadecimal string
  • Handle errors appropriately (reject Promise on error)
  • The module should detect its environment and export accordingly

Test Cases

  • hashPassword("test123") resolves to a 64-character hex string @test
  • hashPassword("myPassword") produces consistent output across multiple calls @test
  • The module can be loaded via require() in Node.js @test
  • The module exposes a global variable when loaded via script tag in a browser environment @test

@generates

API

/**
 * Hashes a password using scrypt algorithm.
 *
 * @param {string} password - The password to hash
 * @returns {Promise<string>} Promise resolving to 64-character hex string
 */
function hashPassword(password);

Dependencies { .dependencies }

scrypt-js { .dependency }

Provides password-based key derivation functionality.

Install with Tessl CLI

npx tessl i tessl/npm-scrypt-js

tile.json