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

Secure Key Exchange System

Overview

Implement a secure key exchange system that allows two parties to establish a shared secret over an insecure channel. The system should support key generation, public key exchange, and shared secret computation using elliptic curve cryptography.

Requirements

Key Exchange Implementation

Create a module that implements the following functionality:

  1. Key Pair Generation: Generate a public-private key pair using elliptic curve cryptography (use the secp256k1 curve)
  2. Public Key Export: Export the public key in both compressed and uncompressed formats
  3. Shared Secret Computation: Given another party's public key, compute a shared secret
  4. Key Persistence: Support exporting and importing private keys for session resumption

Expected Behavior

The implementation should:

  • Generate cryptographically secure key pairs using elliptic curve cryptography
  • Support exporting public keys in compressed format (smaller size for efficient transmission)
  • Compute identical shared secrets when two parties exchange public keys
  • Allow key pairs to be exported and later imported to resume sessions
  • Return shared secrets as hexadecimal strings for easy comparison and use

Implementation File

Create your implementation in src/keyExchange.js with the following exports:

  • createKeyPair() - Creates and returns a new key exchange instance
  • Each instance should support:
    • getPublicKey(format) - Returns public key (format: 'compressed' or 'uncompressed')
    • getPrivateKey() - Returns private key as hex string
    • computeSharedSecret(otherPublicKey) - Computes shared secret from other party's public key, returns hex string
    • importPrivateKey(privateKeyHex) - Imports a previously exported private key

Dependencies { .dependencies }

crypto-browserify { .dependency }

Provides cryptographic operations including elliptic curve key exchange.

Test Cases

Test 1: Basic Key Exchange { .spec-section @test }

Create a test in src/keyExchange.test.js that:

  1. Creates two key exchange instances (representing Alice and Bob)
  2. Exchanges public keys between them
  3. Computes shared secrets on both sides
  4. Verifies that both computed secrets are identical

Expected outcome: Both parties derive the same shared secret value.

Test 2: Compressed Key Format { .spec-section @test }

Create a test that:

  1. Creates a key exchange instance
  2. Exports the public key in compressed format
  3. Creates a second instance and computes a shared secret using the compressed public key
  4. Verifies the shared secret is computed correctly

Expected outcome: Compressed public keys work correctly for secret computation.

Test 3: Key Persistence { .spec-section @test }

Create a test that:

  1. Creates a key exchange instance and generates a key pair
  2. Exports the private key
  3. Creates a new instance and imports the private key
  4. Verifies that public keys from both instances match
  5. Verifies that shared secrets computed with both instances are identical

Expected outcome: Imported keys produce the same cryptographic behavior as the original keys.

Version

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