node-firebird 1.1.10 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-firebird",
3
- "version": "1.1.10",
3
+ "version": "2.0.0",
4
4
  "description": "Pure JavaScript and Asynchronous Firebird client for Node.js.",
5
5
  "keywords": [
6
6
  "firebird",
@@ -25,7 +25,7 @@
25
25
  "types": "./lib/index.d.ts",
26
26
  "license": "MPL-2.0",
27
27
  "scripts": {
28
- "test": "mocha"
28
+ "test": "vitest run"
29
29
  },
30
30
  "dependencies": {
31
31
  "big-integer": "^1.6.51",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "coveralls-next": "^4.2.0",
36
- "mocha": "^10.2.0",
37
- "nyc": "^15.0.1"
36
+ "nyc": "^15.0.1",
37
+ "vitest": "^4.0.18"
38
38
  }
39
39
  }
package/srp.js ADDED
@@ -0,0 +1,94 @@
1
+ const BigInteger = require('big-integer');
2
+ const crypto = require('crypto');
3
+
4
+ console.log('Preparing benchmark...');
5
+
6
+ // Constants from lib/srp.js
7
+ const HEX_N = 'E67D2E994B2F900C3F41F08F5BB2627ED0D49EE1FE767A52EFCD565CD6E768812C3E1E9CE8F0A8BEA6CB13CD29DDEBF7A96D4A93B55D488DF099A15C89DCB0640738EB2CBDD9A8F7BAB561AB1B0DC1C6CDABF303264A08D1BCA932D1F1EE428B619D970F342ABA9A65793B8B2F041AE5364350C16F735F56ECBCA87BD57B29E7';
8
+ const DEC_K = '1277432915985975349439481660349303019122249719989';
9
+
10
+ // --- Library Setup ---
11
+ const lib_N = BigInteger(HEX_N, 16);
12
+ const lib_g = BigInteger(2);
13
+ const lib_k = BigInteger(DEC_K);
14
+
15
+ // --- Native Setup ---
16
+ const native_N = BigInt('0x' + HEX_N);
17
+ const native_g = 2n;
18
+ const native_k = BigInt(DEC_K);
19
+
20
+ /**
21
+ * Native BigInt Modular Exponentiation
22
+ * Calculates (base ^ exp) % mod
23
+ */
24
+ function nativeModPow(base, exp, mod) {
25
+ let result = 1n;
26
+ base = base % mod;
27
+ while (exp > 0n) {
28
+ if (exp & 1n) result = (result * base) % mod;
29
+ base = (base * base) % mod;
30
+ exp >>= 1n;
31
+ }
32
+ return result;
33
+ }
34
+
35
+ // --- Test Data Generation ---
36
+ const ITERATIONS = 2000;
37
+ const inputs = [];
38
+
39
+ for (let i = 0; i < ITERATIONS; i++) {
40
+ // Generate random 32-byte private key (similar to SRP_KEY_SIZE)
41
+ const hex = crypto.randomBytes(32).toString('hex');
42
+ inputs.push({
43
+ lib: BigInteger(hex, 16),
44
+ native: BigInt('0x' + hex)
45
+ });
46
+ }
47
+
48
+ // --- Verification ---
49
+ console.log('Verifying implementations match...');
50
+ const vLib = lib_g.modPow(inputs[0].lib, lib_N);
51
+ const vNative = nativeModPow(native_g, inputs[0].native, native_N);
52
+
53
+ if (vLib.toString(16) !== vNative.toString(16)) {
54
+ console.error('MISMATCH!');
55
+ console.error('Lib:', vLib.toString(16));
56
+ console.error('Nat:', vNative.toString(16));
57
+ process.exit(1);
58
+ }
59
+ console.log('Verification passed.');
60
+
61
+ // --- Benchmark ---
62
+ console.log(`\nStarting benchmark (${ITERATIONS} iterations)...`);
63
+
64
+ // 1. Library Benchmark
65
+ const startLib = process.hrtime.bigint();
66
+ for (let i = 0; i < ITERATIONS; i++) {
67
+ // Simulate: A = g^a % N
68
+ const A = lib_g.modPow(inputs[i].lib, lib_N);
69
+
70
+ // Simulate part of server calc: B = (k*v + g^b) % N
71
+ // We'll just do (k * A) % N + A to simulate the mix of mult/add/mod
72
+ const term = lib_k.multiply(A).mod(lib_N).add(A).mod(lib_N);
73
+ }
74
+ const endLib = process.hrtime.bigint();
75
+
76
+ // 2. Native Benchmark
77
+ const startNative = process.hrtime.bigint();
78
+ for (let i = 0; i < ITERATIONS; i++) {
79
+ // Simulate: A = g^a % N
80
+ const A = nativeModPow(native_g, inputs[i].native, native_N);
81
+
82
+ // Simulate part of server calc: B = (k*v + g^b) % N
83
+ const term = ((native_k * A) % native_N + A) % native_N;
84
+ }
85
+ const endNative = process.hrtime.bigint();
86
+
87
+ // --- Results ---
88
+ const timeLib = Number(endLib - startLib) / 1e6; // ms
89
+ const timeNative = Number(endNative - startNative) / 1e6; // ms
90
+
91
+ console.log('\nResults:');
92
+ console.log(`big-integer (Lib): ${timeLib.toFixed(2)} ms`);
93
+ console.log(`Native BigInt: ${timeNative.toFixed(2)} ms`);
94
+ console.log(`\nSpeedup: ${(timeLib / timeNative).toFixed(2)}x faster`);
@@ -0,0 +1,13 @@
1
+ const { defineConfig } = require('vitest/config');
2
+
3
+ module.exports = defineConfig({
4
+ test: {
5
+ globals: true,
6
+ testTimeout: 10000,
7
+ hookTimeout: 30000,
8
+ fileParallelism: false,
9
+ maxWorkers: 1,
10
+ isolate: false,
11
+ include: ['test/arc4.js', 'test/protocol.js', 'test/srp.js', 'test/service.js', 'test/utf8-user-identification.js', 'test/index.js', 'test/db-crypt-config.js'],
12
+ },
13
+ });