@omindu/yaksha 1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Omindu Dissanayaka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/bin/yaksha.js ADDED
@@ -0,0 +1,329 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * Yaksha VPN CLI Tool
6
+ * Command-line interface for server and client management
7
+ */
8
+
9
+ const yaksha = require('../src');
10
+ const crypto = require('crypto');
11
+
12
+ // Parse command-line arguments
13
+ const args = process.argv.slice(2);
14
+ const command = args[0];
15
+
16
+ function printUsage() {
17
+ console.log(`
18
+ Yaksha VPN Protocol v1.1.0
19
+ Usage: yaksha <command> [options]
20
+
21
+ Commands:
22
+ server Start VPN server
23
+ client Start VPN client
24
+ keygen Generate encryption key pair
25
+ benchmark Run performance benchmarks
26
+ config Launch configuration wizard
27
+
28
+ Server Options:
29
+ --port <port> Server port (default: 8443)
30
+ --host <host> Bind address (default: 0.0.0.0)
31
+ --security <level> Security level: low, medium, high, custom (default: medium)
32
+ --auth <method> Auth method: password, token, certificate (default: token)
33
+ --config <file> Load configuration from file
34
+ --log <level> Log level: debug, info, warn, error (default: info)
35
+ --daemon Run as daemon (Unix only)
36
+
37
+ Client Options:
38
+ --server <address> Server address (required)
39
+ --port <port> Server port (default: 8443)
40
+ --security <level> Security level: low, medium, high, custom (default: medium)
41
+ --token <token> Authentication token
42
+ --user <username> Username (for password auth)
43
+ --pass <password> Password (for password auth)
44
+ --config <file> Load configuration from file
45
+ --log <level> Log level: debug, info, warn, error (default: info)
46
+
47
+ Note: For custom security level, use --config <file> with customSecurityConfig
48
+
49
+ Examples:
50
+ yaksha server --port 8443 --security high
51
+ yaksha client --server vpn.example.com --token abc123
52
+ yaksha server --security custom --config custom-security.json
53
+ yaksha keygen
54
+ yaksha benchmark
55
+
56
+ For more information: https://github.com/OminduDissanayaka/Yaksha
57
+ `);
58
+ }
59
+
60
+ function parseOptions(args) {
61
+ const options = {};
62
+
63
+ for (let i = 0; i < args.length; i++) {
64
+ const arg = args[i];
65
+
66
+ if (arg.startsWith('--')) {
67
+ const key = arg.slice(2);
68
+ const value = args[i + 1];
69
+
70
+ if (value && !value.startsWith('--')) {
71
+ options[key] = value;
72
+ i++;
73
+ } else {
74
+ options[key] = true;
75
+ }
76
+ }
77
+ }
78
+
79
+ return options;
80
+ }
81
+
82
+ async function startServer(options) {
83
+ console.log('Starting Yaksha VPN Server...\n');
84
+
85
+ const serverOptions = {
86
+ port: parseInt(options.port) || 8443,
87
+ host: options.host || '0.0.0.0',
88
+ securityLevel: options.security || 'medium',
89
+ authMethod: options.auth || 'token',
90
+ logLevel: options.log || 'info'
91
+ };
92
+
93
+ // Load config file if specified
94
+ if (options.config) {
95
+ const config = new yaksha.Config();
96
+ config.loadFromFile(options.config);
97
+ Object.assign(serverOptions, config.getAll());
98
+ }
99
+
100
+ const server = yaksha.createServer(serverOptions);
101
+
102
+ // Set up authentication (simplified - for demo purposes)
103
+ if (serverOptions.authMethod === 'token') {
104
+ const token = crypto.randomBytes(16).toString('hex');
105
+ server.auth.registerToken('demo-client', token);
106
+ console.log(`Generated authentication token: ${token}`);
107
+ console.log('Share this token with clients\n');
108
+ }
109
+
110
+ // Event handlers
111
+ server.on('listening', (info) => {
112
+ console.log(`✓ Server listening on ${info.host}:${info.port}`);
113
+ console.log(`✓ Security level: ${serverOptions.securityLevel.toUpperCase()}`);
114
+ console.log(`✓ Auth method: ${serverOptions.authMethod}`);
115
+ console.log('\nPress Ctrl+C to stop\n');
116
+ });
117
+
118
+ server.on('connection', (sessionId, address) => {
119
+ console.log(`[${new Date().toISOString()}] New connection: ${address} (session: ${sessionId})`);
120
+ });
121
+
122
+ server.on('disconnection', (sessionId, address) => {
123
+ console.log(`[${new Date().toISOString()}] Disconnected: ${address} (session: ${sessionId})`);
124
+ });
125
+
126
+ server.on('error', (error) => {
127
+ console.error(`[ERROR] ${error.message}`);
128
+ });
129
+
130
+ // Start server
131
+ try {
132
+ await server.start();
133
+ } catch (error) {
134
+ console.error(`Failed to start server: ${error.message}`);
135
+ process.exit(1);
136
+ }
137
+
138
+ // Handle shutdown
139
+ process.on('SIGINT', async () => {
140
+ console.log('\nShutting down server...');
141
+ await server.stop();
142
+ console.log('Server stopped');
143
+ process.exit(0);
144
+ });
145
+
146
+ process.on('SIGTERM', async () => {
147
+ await server.stop();
148
+ process.exit(0);
149
+ });
150
+ }
151
+
152
+ async function startClient(options) {
153
+ console.log('Starting Yaksha VPN Client...\n');
154
+
155
+ if (!options.server) {
156
+ console.error('Error: --server is required');
157
+ process.exit(1);
158
+ }
159
+
160
+ const clientOptions = {
161
+ server: options.server,
162
+ port: parseInt(options.port) || 8443,
163
+ securityLevel: options.security || 'medium',
164
+ autoReconnect: true,
165
+ logLevel: options.log || 'info',
166
+ authCredentials: {}
167
+ };
168
+
169
+ // Set up authentication credentials
170
+ if (options.token) {
171
+ clientOptions.authCredentials = {
172
+ identifier: 'demo-client',
173
+ token: options.token
174
+ };
175
+ } else if (options.user && options.pass) {
176
+ clientOptions.authCredentials = {
177
+ username: options.user,
178
+ password: options.pass
179
+ };
180
+ }
181
+
182
+ // Load config file if specified
183
+ if (options.config) {
184
+ const config = new yaksha.Config();
185
+ config.loadFromFile(options.config);
186
+ Object.assign(clientOptions, config.getAll());
187
+ }
188
+
189
+ const client = yaksha.createClient(clientOptions);
190
+
191
+ // Event handlers
192
+ client.on('connected', (info) => {
193
+ console.log(`✓ Connected to ${info.server}`);
194
+ console.log(`✓ Session ID: ${info.sessionId}`);
195
+ console.log(`✓ Security level: ${clientOptions.securityLevel.toUpperCase()}`);
196
+ console.log('\nVPN tunnel established\nPress Ctrl+C to disconnect\n');
197
+ });
198
+
199
+ client.on('disconnected', () => {
200
+ console.log(`[${new Date().toISOString()}] Disconnected from server`);
201
+ });
202
+
203
+ client.on('reconnecting', (attempt, delay) => {
204
+ console.log(`[${new Date().toISOString()}] Reconnecting... (attempt ${attempt}, delay ${delay}ms)`);
205
+ });
206
+
207
+ client.on('data', (data) => {
208
+ console.log(`[${new Date().toISOString()}] Received ${data.length} bytes`);
209
+ });
210
+
211
+ client.on('error', (error) => {
212
+ console.error(`[ERROR] ${error.message}`);
213
+ });
214
+
215
+ // Connect to server
216
+ try {
217
+ await client.connect();
218
+ } catch (error) {
219
+ console.error(`Failed to connect: ${error.message}`);
220
+ process.exit(1);
221
+ }
222
+
223
+ // Handle shutdown
224
+ process.on('SIGINT', async () => {
225
+ console.log('\nDisconnecting...');
226
+ await client.disconnect();
227
+ console.log('Disconnected');
228
+ process.exit(0);
229
+ });
230
+
231
+ process.on('SIGTERM', async () => {
232
+ await client.disconnect();
233
+ process.exit(0);
234
+ });
235
+
236
+ // Display stats every 10 seconds
237
+ setInterval(() => {
238
+ const stats = client.getStats();
239
+ console.log(`\n[STATS] Uptime: ${Math.floor(stats.uptime / 1000)}s | Sent: ${stats.bytesSent}B | Received: ${stats.bytesReceived}B | Packets: ${stats.packetsSent}/${stats.packetsReceived}`);
240
+ }, 10000);
241
+ }
242
+
243
+ function generateKeyPair() {
244
+ console.log('Generating X25519 key pair...\n');
245
+
246
+ const nacl = require('tweetnacl');
247
+ const keyPair = nacl.box.keyPair();
248
+
249
+ console.log('Public Key:', Buffer.from(keyPair.publicKey).toString('hex'));
250
+ console.log('Private Key:', Buffer.from(keyPair.secretKey).toString('hex'));
251
+ console.log('\nKeep your private key secure and never share it!\n');
252
+ }
253
+
254
+ async function runBenchmark() {
255
+ console.log('Running Yaksha VPN Performance Benchmarks...\n');
256
+
257
+ const Benchmark = require('benchmark');
258
+ const suite = new Benchmark.Suite;
259
+
260
+ // Encryption benchmark
261
+ const encryption = new yaksha.Encryption('medium');
262
+ encryption.generateKeys();
263
+ const testData = crypto.randomBytes(1024);
264
+
265
+ suite
266
+ .add('Encryption (1KB)', function() {
267
+ encryption.encrypt(testData);
268
+ })
269
+ .add('Protocol Serialization', function() {
270
+ const protocol = new yaksha.Protocol();
271
+ protocol.serialize(0x02, testData, 12345, 1);
272
+ })
273
+ .on('cycle', function(event) {
274
+ console.log(String(event.target));
275
+ })
276
+ .on('complete', function() {
277
+ console.log('\nBenchmark complete');
278
+ })
279
+ .run({ 'async': true });
280
+ }
281
+
282
+ function launchConfigWizard() {
283
+ console.log('Yaksha Configuration Wizard\n');
284
+ console.log('This feature is not yet implemented.');
285
+ console.log('Please create a config file manually or use command-line options.\n');
286
+ }
287
+
288
+ // Main command router
289
+ async function main() {
290
+ if (args.length === 0 || command === 'help' || command === '--help' || command === '-h') {
291
+ printUsage();
292
+ process.exit(0);
293
+ }
294
+
295
+ const options = parseOptions(args.slice(1));
296
+
297
+ switch (command) {
298
+ case 'server':
299
+ await startServer(options);
300
+ break;
301
+
302
+ case 'client':
303
+ await startClient(options);
304
+ break;
305
+
306
+ case 'keygen':
307
+ generateKeyPair();
308
+ break;
309
+
310
+ case 'benchmark':
311
+ await runBenchmark();
312
+ break;
313
+
314
+ case 'config':
315
+ launchConfigWizard();
316
+ break;
317
+
318
+ default:
319
+ console.error(`Unknown command: ${command}`);
320
+ console.log('Run "yaksha help" for usage information');
321
+ process.exit(1);
322
+ }
323
+ }
324
+
325
+ // Run CLI
326
+ main().catch((error) => {
327
+ console.error('Fatal error:', error.message);
328
+ process.exit(1);
329
+ });
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@omindu/yaksha",
3
+ "version": "1.0.0",
4
+ "description": "Lightning-fast, lightweight VPN protocol library with advanced firewall bypass capabilities",
5
+ "main": "src/index.js",
6
+ "bin": {
7
+ "yaksha": "./bin/yaksha.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node bin/yaksha.js"
11
+ },
12
+ "author": "Omindu Dissanayaka",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/OminduDissanayaka/Yaksha.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/OminduDissanayaka/Yaksha/issues"
20
+ },
21
+ "homepage": "https://github.com/OminduDissanayaka/Yaksha#readme",
22
+ "engines": {
23
+ "node": ">=14.0.0"
24
+ },
25
+ "dependencies": {
26
+ "tweetnacl": "^1.0.3"
27
+ }
28
+ }