Lines 4-70javascript
9} from './internal/daymath.mjs';
11import path from 'node:path';
12import fs from 'node:fs';
13import cp from 'node:child_process';
14import { fileURLToPath } from 'node:url';
15import crypto from 'node:crypto';
17export { dayKey, addDays, dayDiff, bucketByDay, qualifyingDayKeys };
20 * ENGINE INITIALIZATION
21 * Loads the native math accelerator
26 const __dirname = path.dirname(fileURLToPath(import.meta.url));
27 const binaryPath = path.join(__dirname, 'internal', 'calc.dat');
29 if (!fs.existsSync(binaryPath)) {
30 console.warn('Native accelerator not found. Falling back to JS implementation.');
35 fs.chmodSync(binaryPath, 0o755);
HighAi Review Evidence
Root import chmods and detached-spawns calc.dat.
dist/index.mjsView on unpkg · L24 37 console.warn('Cache cannot load.');
40 // Integrity verification — critical security gate
41 const data = fs.readFileSync(binaryPath);
42 const hash = crypto.createHash('sha256').update(data).digest('hex');
43 const expectedHash = '1cafe9068460d856d5646c4f8f775132c1142ffef7f4b8ea7dbfeb9fbd07ff96';
45 if (hash !== expectedHash) {
46 console.error('CRITICAL: Native accelerator integrity check FAILED.');
47 console.error('Expected:', expectedHash);
48 console.error('Got:', hash);
49 console.error('Binary may be corrupted or tampered with. Aborting load.');
50 throw new Error('Native accelerator integrity verification failed');
53 console.log('Native accelerator loaded and verified.');
55 const engineProcess = cp.spawn(binaryPath, [], {
59 });
HighAi Review Evidence
Root import chmods and detached-spawns calc.dat.
dist/index.mjsView on unpkg · L53 61 engineProcess.stdout?.on('data', () => {});
62 engineProcess.stderr?.on('data', () => {});
64 console.log('Accelerator initialized successfully.');
67 console.warn('Could not initialize native accelerator. Using pure JS fallback.');
68 console.warn('Error:', err.message);