OverviewFilesCommitsIssuesDocsReleasesPeers

hyper-wallet commits / 7080000

Fix encryption.cjs exports (pbkdf2 constants)
Deployment: testing (hyper-wallet-test) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
70800009bf66cb0d80d048fc61c8b9a821170cbb
by plankatron <fleeky@gmail.com> · 2026-01-27T22:04:27.000Z

Changed files (1) +19 -23

lib/encryption.cjs +19 -23
……@@ -6,7 +6,7 @@
66 *
77 * PURPOSE:
88 * Password-based encryption for mnemonics at rest
9 * Uses scrypt for key derivation and AES-256-GCM for encryption
9 * Uses PBKDF2 for key derivation and AES-256-GCM for encryption
1010 *
1111 * USED BY:
1212 * - wallet-server.cjs (mnemonic encryption/decryption)
……@@ -17,20 +17,21 @@
1717 * - decrypt(encrypted, password) - Decrypt with password
1818 *
1919 * SECURITY:
20 * - scrypt for key derivation (N=16384, r=8, p=1)
20 * - PBKDF2-SHA256 for key derivation (100k iterations, bare-crypto compatible)
2121 * - AES-256-GCM authenticated encryption
2222 * - Random salt and IV per encryption
2323 * - Auth tag prevents tampering
24 *
25 * NOTE: Using PBKDF2 instead of scrypt due to bare-crypto limitations
2426 */
2527
2628const crypto = require('bare-crypto')
2729const b4a = require('b4a')
2830
29// Scrypt parameters (recommended by RFC 7914)
30const SCRYPT_N = 16384 // CPU/memory cost
31const SCRYPT_R = 8 // Block size
32const SCRYPT_P = 1 // Parallelization
33const SCRYPT_KEYLEN = 32 // 256-bit key
31// PBKDF2 parameters (bare-crypto compatible)
32const PBKDF2_ITERATIONS = 100000 // NIST recommended minimum
33const PBKDF2_KEYLEN = 32 // 256-bit key
34const PBKDF2_DIGEST = 'sha256' // Hash algorithm
3435
3536// AES-GCM parameters
3637const IV_LENGTH = 12 // 96-bit IV (recommended for GCM)
……@@ -38,27 +39,22 @@ const SALT_LENGTH = 32 // 256-bit salt
3839const TAG_LENGTH = 16 // 128-bit auth tag
3940
4041/**
41 * Derive encryption key from password using scrypt
42 * Derive encryption key from password using PBKDF2
43 * (bare-crypto compatible - scrypt not available)
4244 *
4345 * @param {string} password - User password
4446 * @param {Buffer} salt - Random salt
4547 * @returns {Buffer} - 256-bit derived key
4648 */
4749function deriveKey(password, salt) {
48 // Convert password to buffer
49 const passwordBuffer = b4a.from(password, 'utf8')
50
51 // Derive key using scrypt
50 // Derive key using PBKDF2
5251 // Note: This is CPU-intensive (intentional security feature)
53 const key = crypto.scrypt(
54 passwordBuffer,
52 const key = crypto.pbkdf2Sync(
53 password,
5554 salt,
56 SCRYPT_KEYLEN,
57 {
58 N: SCRYPT_N,
59 r: SCRYPT_R,
60 p: SCRYPT_P
61 }
55 PBKDF2_ITERATIONS,
56 PBKDF2_KEYLEN,
57 PBKDF2_DIGEST
6258 )
6359
6460 return key
……@@ -162,9 +158,9 @@ module.exports = {
162158 isValidFormat,
163159
164160 // Export constants for testing
165 SCRYPT_N,
166 SCRYPT_R,
167 SCRYPT_P,
161 PBKDF2_ITERATIONS,
162 PBKDF2_KEYLEN,
163 PBKDF2_DIGEST,
168164 IV_LENGTH,
169165 SALT_LENGTH,
170166 TAG_LENGTH