cf-keys 1.1.0 → 1.1.2

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/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # `cf-keys`
6
6
 
7
- **Security & Utility Suite for Systems Engineering** <i>Modular toolkit for security, credential generation, and token automation in Node.js.</i>
7
+ **Security & Utility Suite for Systems Engineering** <i>Modular toolkit for security, credential generation, and token automation in Node.js</i>
8
8
 
9
9
  <br/>
10
10
 
@@ -80,17 +80,23 @@ npm install cf-keys
80
80
 
81
81
  After global installation, you can access the suite using the `cf-keys` command. If run without arguments, it displays a professional dashboard with the status and version.
82
82
 
83
- ### Common Commands & Examples:
83
+ ### CLI Usage
84
84
 
85
- | Command | Description | Example |
86
- | ---------- | ------------------------- | ------------------------------- |
87
- | `jwt sign` | Interactive JWT signing | `cf-keys jwt sign` |
88
- | `password` | Generate a secure string | `cf-keys password 32` |
89
- | `youtube` | Get YouTube bypass tokens | `cf-keys youtube` |
90
- | `hash` | Calculate file/text hash | `cf-keys hash -a sha256 MyData` |
91
- | `utils` | Base64/URL Encoding | `cf-keys utils encode "hello"` |
85
+ After global installation, you can access the suite using the `cf-keys` command. If run without arguments, it displays a professional dashboard.
92
86
 
93
- **Pro Tip:** Use `cf-keys --help` to see all available flags and options for each module.
87
+ | Command | Description | Example |
88
+ | ---------- | ----------------------------------------- | ------------------------------- |
89
+ | `jwt sign` | **Interactive** or flag-based JWT signing | `cf-keys jwt sign` |
90
+ | `password` | Generate secure string (accepts length) | `cf-keys password 32` |
91
+ | `youtube` | Get YouTube `poToken` & `visitorData` | `cf-keys youtube` |
92
+ | `hash` | Calculate file/text integrity (SHA/MD5) | `cf-keys hash -a sha256 MyData` |
93
+ | `utils` | Instant Base64/URL Encoding & Decoding | `cf-keys utils encode "hello"` |
94
+
95
+ #### 💡 Pro Tips:
96
+
97
+ - **Interactive JWT**: Running `cf-keys jwt sign` without flags triggers a guided wizard to safely collect your payload and secret key.
98
+ - **Direct Arguments**: The `password` command now supports direct numeric values for faster credential generation.
99
+ - **Help Menu**: Use `cf-keys --help` to explore all available flags and options for each specific module.
94
100
 
95
101
  ---
96
102
 
@@ -8,9 +8,9 @@ const commander_1 = require("commander");
8
8
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
9
9
  const node_fs_1 = __importDefault(require("node:fs"));
10
10
  const node_path_1 = __importDefault(require("node:path"));
11
+ const node_readline_1 = __importDefault(require("node:readline"));
11
12
  /**
12
13
  * Core logic to sign JWT tokens.
13
- * Can be imported directly into other projects for bot authentication.
14
14
  */
15
15
  const signJWT = (payload, secret, expires = "24h") => {
16
16
  const options = {
@@ -19,49 +19,74 @@ const signJWT = (payload, secret, expires = "24h") => {
19
19
  return jsonwebtoken_1.default.sign(payload, secret, options);
20
20
  };
21
21
  exports.signJWT = signJWT;
22
+ const askQuestion = (query) => {
23
+ const rl = node_readline_1.default.createInterface({
24
+ input: process.stdin,
25
+ output: process.stdout,
26
+ });
27
+ return new Promise((resolve) => rl.question(query, (ans) => {
28
+ rl.close();
29
+ resolve(ans);
30
+ }));
31
+ };
22
32
  exports.jwtCmd = new commander_1.Command("jwt")
23
33
  .description("Generate and sign a JSON Web Token (JWT)")
24
34
  .option("-p, --payload <json>", "Token payload in JSON string format")
25
35
  .option("-f, --file <path>", "Path to a .json file containing the payload")
26
36
  .option("-a, --args <pairs...>", "Key-value pairs (e.g., user=admin role=dev)")
27
- .requiredOption("-s, --secret <key>", "Secret key to sign")
37
+ .option("-s, --secret <key>", "Secret key to sign") // Cambiado a .option para manejar flujo manual
28
38
  .option("-e, --expires <time>", 'Expiration time (e.g., "1h", "7d")', "24h")
29
- .action((options) => {
39
+ .action(async (options) => {
30
40
  try {
31
41
  let payloadObj = {};
32
- if (options.file) {
33
- const filePath = node_path_1.default.resolve(options.file);
34
- if (!node_fs_1.default.existsSync(filePath)) {
35
- throw new Error(`The file does not exist at: ${filePath}`);
36
- }
37
- payloadObj = JSON.parse(node_fs_1.default.readFileSync(filePath, "utf8"));
38
- }
39
- else if (options.payload) {
40
- payloadObj = JSON.parse(options.payload);
41
- }
42
- else if (options.args) {
43
- options.args.forEach((pair) => {
44
- const [key, value] = pair.split("=");
45
- if (key && value) {
46
- if (value === "true")
47
- payloadObj[key] = true;
48
- else if (value === "false")
49
- payloadObj[key] = false;
50
- else if (!isNaN(Number(value)))
51
- payloadObj[key] = Number(value);
52
- else
53
- payloadObj[key] = value;
54
- }
55
- });
42
+ let secret = options.secret;
43
+ if (!options.payload &&
44
+ !options.file &&
45
+ !options.args &&
46
+ !options.secret) {
47
+ console.log("🛠️ Interactive JWT Signing Mode");
48
+ const rawPayload = await askQuestion('Enter JSON payload (e.g. {"id":1}): ');
49
+ payloadObj = JSON.parse(rawPayload);
50
+ secret = await askQuestion("Enter secret key: ");
51
+ if (!secret)
52
+ throw new Error("Secret is required");
56
53
  }
57
54
  else {
58
- throw new Error("You must provide a payload using -p, -f, or -a");
55
+ if (!secret)
56
+ throw new Error("Required option '-s, --secret <key>' not specified");
57
+ if (options.file) {
58
+ const filePath = node_path_1.default.resolve(options.file);
59
+ if (!node_fs_1.default.existsSync(filePath))
60
+ throw new Error(`File not found: ${filePath}`);
61
+ payloadObj = JSON.parse(node_fs_1.default.readFileSync(filePath, "utf8"));
62
+ }
63
+ else if (options.payload) {
64
+ payloadObj = JSON.parse(options.payload);
65
+ }
66
+ else if (options.args) {
67
+ options.args.forEach((pair) => {
68
+ const [key, value] = pair.split("=");
69
+ if (key && value) {
70
+ if (value === "true")
71
+ payloadObj[key] = true;
72
+ else if (value === "false")
73
+ payloadObj[key] = false;
74
+ else if (!isNaN(Number(value)))
75
+ payloadObj[key] = Number(value);
76
+ else
77
+ payloadObj[key] = value;
78
+ }
79
+ });
80
+ }
81
+ else {
82
+ throw new Error("You must provide a payload using -p, -f, or -a");
83
+ }
59
84
  }
60
- const token = (0, exports.signJWT)(payloadObj, options.secret, options.expires);
85
+ const token = (0, exports.signJWT)(payloadObj, secret, options.expires);
61
86
  console.info(JSON.stringify({
87
+ status: "success",
62
88
  type: "jwt",
63
89
  token,
64
- source: options.args ? "args" : options.file ? "file" : "payload",
65
90
  expiresIn: options.expires,
66
91
  decodedPayload: payloadObj,
67
92
  }, null, 2));
@@ -24,26 +24,42 @@ const generateSecurePassword = (length = 16, includeNumbers = true, includeSymbo
24
24
  return password;
25
25
  };
26
26
  exports.generateSecurePassword = generateSecurePassword;
27
+ /**
28
+ * CLI Command definition for password generation.
29
+ * Supports: cf-keys password [length] OR cf-keys password -l [length]
30
+ */
27
31
  exports.passwordCmd = new commander_1.Command("password")
28
32
  .description("Generates a cryptographically secure password")
29
- .option("-l, --length <numero>", "Password length", "16")
33
+ .argument("[length]", "Password length (default: 16)")
34
+ .option("-l, --length <number>", "Password length (alternative option)")
30
35
  .option("--no-symbols", "Exclude special characters")
31
36
  .option("--no-numbers", "Exclude numbers")
32
- .action((options) => {
37
+ .action((argLength, options) => {
33
38
  try {
34
- const length = parseInt(options.length, 10);
35
- const password = (0, exports.generateSecurePassword)(length, options.numbers, options.symbols);
39
+ const rawLength = argLength || options.length || "16";
40
+ const length = parseInt(rawLength, 10);
41
+ if (isNaN(length) || length <= 0) {
42
+ throw new Error("Invalid length. Please provide a positive number.");
43
+ }
44
+ const useNumbers = options.numbers !== false;
45
+ const useSymbols = options.symbols !== false;
46
+ const password = (0, exports.generateSecurePassword)(length, useNumbers, useSymbols);
36
47
  console.info(JSON.stringify({
48
+ status: "success",
37
49
  type: "password",
38
50
  value: password,
39
51
  length: length,
40
52
  config: {
41
- symbols: options.symbols,
42
- numbers: options.numbers,
53
+ symbols: useSymbols,
54
+ numbers: useNumbers,
43
55
  },
44
56
  }, null, 2));
45
57
  }
46
58
  catch (error) {
47
- console.error(JSON.stringify({ status: "error", details: error.message }, null, 2));
59
+ console.error(JSON.stringify({
60
+ status: "error",
61
+ message: "Failed to generate password",
62
+ details: error.message,
63
+ }, null, 2));
48
64
  }
49
65
  });
package/dist/index.js CHANGED
@@ -59,9 +59,11 @@ program
59
59
  .action(() => {
60
60
  showWelcomeBanner();
61
61
  });
62
+ const jwtGroup = new commander_1.Command("jwt").description("JWT Management & Signing");
63
+ jwtGroup.addCommand(jwt_1.jwtCmd.name("sign"));
62
64
  program.addCommand(password_1.passwordCmd);
63
65
  program.addCommand(youtube_1.youtubeCmd);
64
- program.addCommand(jwt_1.jwtCmd);
66
+ program.addCommand(jwtGroup);
65
67
  program.addCommand(hash_1.hashCmd);
66
68
  program.addCommand(utils_1.utilsCmd);
67
69
  program.parse(node_process_1.default.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cf-keys",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Suite global de generación de claves y credenciales",
5
5
  "main": "dist/lib.js",
6
6
  "types": "dist/lib.d.ts",