CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-crypto-browserify

tessl install tessl/npm-crypto-browserify@3.12.0

Browser-compatible implementation of Node.js crypto module providing cryptographic operations in web environments.

Agent Success

Agent success rate when using this tile

100%

Improvement

Agent success rate improvement when using this tile compared to baseline

1x

Baseline

Agent success rate without this tile

100%

task.mdevals/scenario-8/

Software License Verification System

Build a license verification system that validates software licenses using digital signatures.

Background

Your company issues software licenses to customers. Each license is a JSON document containing license details (customer name, expiration date, allowed features). To prevent tampering, each license is digitally signed by your company's private key. Customer systems need to verify these licenses are authentic before granting access.

Requirements

Implement a license verification module with two functions:

1. License Verification Function

Create a function verifyLicense(licenseData, signature, publicKey) that:

  • Takes license data (string), a signature (hex-encoded string), and a public key (PEM format)
  • Verifies the signature was created by the corresponding private key
  • Returns true if the signature is valid, false otherwise
  • Uses SHA-256 as the hashing algorithm

2. Batch Verification Function

Create a function verifyMultipleLicenses(licenses, publicKey) that:

  • Takes an array of license objects, each with properties data (string) and signature (hex-encoded string)
  • Takes a public key (PEM format)
  • Verifies all licenses and returns an object with:
    • valid: array of indices of valid licenses
    • invalid: array of indices of invalid licenses
  • Uses SHA-256 as the hashing algorithm

Test Cases { .test-cases }

Test 1: Single license verification { .test-case @test }

Given:

  • License data: "customer:acme-corp,expires:2025-12-31,features:premium"
  • A valid signature created with RSA-SHA256
  • Corresponding public key

When: Verifying the license

Then: Returns true

Test 2: Tampered license detection { .test-case @test }

Given:

  • Modified license data (different from what was signed)
  • Original signature
  • Public key

When: Verifying the modified license

Then: Returns false

Test 3: Batch verification { .test-case @test }

Given:

  • Array of 3 licenses: 2 with valid signatures, 1 with invalid signature
  • Public key

When: Verifying all licenses in batch

Then: Returns object with valid: [0, 2] and invalid: [1]

Implementation Notes

  • Create a module file license-verifier.js that exports both functions
  • Create a test file license-verifier.test.js with test cases
  • Handle edge cases (empty data, null values) appropriately
  • Use appropriate encoding for signature input

Dependencies { .dependencies }

crypto-browserify { .dependency }

Provides cryptographic operations for signature verification in browser and Node.js environments.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/crypto-browserify@3.12.x
tile.json