#!/usr/bin/env node

/* eslint-disable quotes */
const fs = require('fs');
const crypto = require('crypto');

/**
 * return random human readable string
 * @returns {string}
 */
function getRandomString(len) {
  const chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+<>?:|{}ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  const size = chars.length;
  return crypto.randomBytes(len)
    .toJSON()
    .data
    .map((char) => chars[char % size])
    .join('');
}

const json = {
  "host": "localhost",
  "port": 1080,
  "servers": [],
  "key": getRandomString(16),
  "frame": "origin",
  "frame_params": "",
  "crypto": "",
  "crypto_params": "",
  "protocol": "aead",
  "protocol_params": "aes-256-cbc,sha256",
  "obfs": "",
  "obfs_params": "",
  "log_level": "info"
};

const file = 'blinksocks.json';

const data = JSON.stringify(json, null, '  ');
fs.writeFile(file, data, function (err) {
  if (err) {
    throw err;
  }
});

@@ -121,36 +121,77 @@
 urn 
-random human readable string
+a fixed length random string from array%0A * @param array%0A * @param len
 %0A * 
@@ -225,131 +225,28 @@
 ion 
-getR
+r
 andom
-String(len) %7B%0A  const chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%25%5E&*()_+%3C%3E?:%7C%7B%7DABCDEFGHIJKLMNOPQRSTUVWXYZ';
+(array, len) %7B
 %0A  c
@@ -257,21 +257,21 @@
  size = 
-chars
+array
 .length;
@@ -273,22 +273,37 @@
 ngth;%0A  
-return
+const randomIndexes =
  crypto.
@@ -318,21 +318,16 @@
 tes(len)
-%0A    
 .toJSON(
@@ -331,23 +331,37 @@
 ON()
-%0A    
 .data
+;
 %0A  
-  
+return randomIndexes
 .map
@@ -375,13 +375,13 @@
  =%3E 
-chars
+array
 %5Bcha
@@ -390,21 +390,16 @@
 %25 size%5D)
-%0A    
 .join(''
@@ -488,24 +488,100 @@
 y%22: 
-getR
+r
 andom
-String(
+('abcdefghijklmnopqrstuvwxyz0123456789!@#$%25%5E&*()_+%3C%3E?:%7C%7B%7DABCDEFGHIJKLMNOPQRSTUVWXYZ', 
 16),
@@ -678,16 +678,19 @@
 ocol%22: %22
+ss-
 aead%22,%0A 
@@ -722,18 +722,21 @@
 256-
-cbc,sha256
+gcm,ss-subkey
 %22,%0A 

use ss-aead protocol by default