favacli 0.0.6 → 0.0.9
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/build/BaseCommand.mjs +3 -3
- package/build/commands/entries/add.d.mts +1 -0
- package/build/commands/entries/add.mjs +19 -0
- package/build/commands/entries/list.d.mts +1 -0
- package/build/commands/entries/list.mjs +13 -0
- package/build/commands/entries/search.d.mts +1 -0
- package/build/commands/entries/search.mjs +17 -0
- package/build/commands/sync/connect.d.mts +1 -0
- package/build/commands/sync/connect.mjs +10 -0
- package/build/commands/sync/setServerUrl.d.mts +1 -0
- package/build/commands/sync/setServerUrl.mjs +12 -0
- package/build/commands/vault/create.d.mts +1 -0
- package/build/commands/vault/create.mjs +13 -2
- package/build/commands/vault/delete.d.mts +14 -0
- package/build/commands/vault/delete.mjs +33 -0
- package/build/main.mjs +13 -5
- package/build/utils/init.d.mts +4 -3
- package/build/utils/init.mjs +17 -5
- package/build/utils/loadVault.d.mts +2 -1
- package/build/utils/loadVault.mjs +3 -3
- package/package.json +7 -3
package/build/BaseCommand.mjs
CHANGED
|
@@ -19,12 +19,12 @@ class BaseCommand extends Command {
|
|
|
19
19
|
async execute() {
|
|
20
20
|
const { lockedRepresentationString, settings } = await init();
|
|
21
21
|
this.settings = settings;
|
|
22
|
-
if (lockedRepresentationString) {
|
|
23
|
-
this.twoFaLib = await loadVault(lockedRepresentationString, this.verbose);
|
|
22
|
+
if (lockedRepresentationString && this.requireTwoFaLib) {
|
|
23
|
+
this.twoFaLib = await loadVault(lockedRepresentationString, settings, this.verbose);
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
26
|
if (this.requireTwoFaLib) {
|
|
27
|
-
throw new Error('
|
|
27
|
+
throw new Error('No vault loaded, was it created?');
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
const json = await this.exec();
|
|
@@ -12,6 +12,25 @@ class EntriesAddCommand extends BaseCommand {
|
|
|
12
12
|
this.algorithm = Option.String('--algorithm', 'SHA-1');
|
|
13
13
|
}
|
|
14
14
|
static { this.paths = [['entries', 'add']]; }
|
|
15
|
+
static { this.usage = BaseCommand.Usage({
|
|
16
|
+
category: 'Entries',
|
|
17
|
+
description: 'Add a new TOTP entry to the vault',
|
|
18
|
+
details: `
|
|
19
|
+
This command adds a new time-based one-time password (TOTP) entry to your vault.
|
|
20
|
+
|
|
21
|
+
The secret must be provided in base32 format.
|
|
22
|
+
`,
|
|
23
|
+
examples: [
|
|
24
|
+
[
|
|
25
|
+
'Add a basic TOTP entry',
|
|
26
|
+
'entries add --name "My Account" --issuer "Example.com" --secret JBSWY3DPEHPK3PXP',
|
|
27
|
+
],
|
|
28
|
+
[
|
|
29
|
+
'Add a TOTP entry with custom period and digits',
|
|
30
|
+
'entries add --name "Custom Account" --issuer "Example.com" --secret AAAAAAAA --period 60 --digits 8',
|
|
31
|
+
],
|
|
32
|
+
],
|
|
33
|
+
}); }
|
|
15
34
|
async exec() {
|
|
16
35
|
await this.twoFaLib.vault.addEntry({
|
|
17
36
|
name: this.name,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BaseCommand from '../../BaseCommand.mjs';
|
|
2
2
|
declare class EntriesListCommand extends BaseCommand {
|
|
3
3
|
static paths: string[][];
|
|
4
|
+
static usage: import("clipanion").Usage;
|
|
4
5
|
requireTwoFaLib: boolean;
|
|
5
6
|
withTokens: boolean | undefined;
|
|
6
7
|
exec(): Promise<0 | readonly import("type-fest").JsonValue[]>;
|
|
@@ -10,6 +10,19 @@ class EntriesListCommand extends BaseCommand {
|
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
12
|
static { this.paths = [['entries', 'list']]; }
|
|
13
|
+
static { this.usage = BaseCommand.Usage({
|
|
14
|
+
category: 'Entries',
|
|
15
|
+
description: 'List all stored 2FA entries',
|
|
16
|
+
details: `
|
|
17
|
+
This command displays a table of all stored two-factor authentication entries.
|
|
18
|
+
|
|
19
|
+
When used with --withTokens, it will also show the current TOTP codes for each entry.
|
|
20
|
+
`,
|
|
21
|
+
examples: [
|
|
22
|
+
['List all entries', 'entries list'],
|
|
23
|
+
['List entries with current TOTP tokens', 'entries list --withTokens'],
|
|
24
|
+
],
|
|
25
|
+
}); }
|
|
13
26
|
async exec() {
|
|
14
27
|
let entries;
|
|
15
28
|
if (this.withTokens) {
|
|
@@ -2,6 +2,7 @@ import type { JsonArray } from 'type-fest';
|
|
|
2
2
|
import BaseCommand from '../../BaseCommand.mjs';
|
|
3
3
|
declare class EntriesSearchCommand extends BaseCommand {
|
|
4
4
|
static paths: string[][];
|
|
5
|
+
static usage: import("clipanion").Usage;
|
|
5
6
|
requireTwoFaLib: boolean;
|
|
6
7
|
withTokens: boolean | undefined;
|
|
7
8
|
query: string;
|
|
@@ -11,6 +11,23 @@ class EntriesSearchCommand extends BaseCommand {
|
|
|
11
11
|
this.query = Option.String({ required: true });
|
|
12
12
|
}
|
|
13
13
|
static { this.paths = [['entries', 'search']]; }
|
|
14
|
+
static { this.usage = BaseCommand.Usage({
|
|
15
|
+
category: 'Entries',
|
|
16
|
+
description: 'Search for stored 2FA entries',
|
|
17
|
+
details: `
|
|
18
|
+
This command searches through all stored two-factor authentication entries.
|
|
19
|
+
|
|
20
|
+
The search query will match against entry names and issuers.
|
|
21
|
+
When used with --withTokens, it will also show the current TOTP codes for matching entries.
|
|
22
|
+
`,
|
|
23
|
+
examples: [
|
|
24
|
+
['Search for entries containing "google"', 'entries search google'],
|
|
25
|
+
[
|
|
26
|
+
'Search and show current TOTP tokens',
|
|
27
|
+
'entries search google --withTokens',
|
|
28
|
+
],
|
|
29
|
+
],
|
|
30
|
+
}); }
|
|
14
31
|
async exec() {
|
|
15
32
|
let filteredEntries;
|
|
16
33
|
if (this.withTokens) {
|
|
@@ -7,6 +7,16 @@ class ConnectCommand extends BaseCommand {
|
|
|
7
7
|
this.requireTwoFaLib = true;
|
|
8
8
|
}
|
|
9
9
|
static { this.paths = [['sync', 'connect']]; }
|
|
10
|
+
static { this.usage = BaseCommand.Usage({
|
|
11
|
+
category: 'Sync',
|
|
12
|
+
description: 'Connect to an existing vault using a connection string',
|
|
13
|
+
details: `
|
|
14
|
+
This command allows you to connect to an existing vault by providing a connection string.
|
|
15
|
+
|
|
16
|
+
The connection string should be obtained from the device that hosts the vault you want to connect to.
|
|
17
|
+
`,
|
|
18
|
+
examples: [['Connect to an existing vault', 'sync connect']],
|
|
19
|
+
}); }
|
|
10
20
|
async exec() {
|
|
11
21
|
if (!this.twoFaLib.sync) {
|
|
12
22
|
throw new Error('No server url set');
|
|
@@ -7,6 +7,18 @@ class SetServerUrlCommand extends BaseCommand {
|
|
|
7
7
|
this.serverUrl = Option.String({ required: true });
|
|
8
8
|
}
|
|
9
9
|
static { this.paths = [['sync', 'setServerUrl']]; }
|
|
10
|
+
static { this.usage = BaseCommand.Usage({
|
|
11
|
+
category: 'Sync',
|
|
12
|
+
description: 'Set the server URL for syncing',
|
|
13
|
+
details: `
|
|
14
|
+
This command sets the URL of the server that will be used for syncing.
|
|
15
|
+
|
|
16
|
+
The server URL must be provided as an argument.
|
|
17
|
+
`,
|
|
18
|
+
examples: [
|
|
19
|
+
['Set sync server URL', 'sync setServerUrl https://example.com'],
|
|
20
|
+
],
|
|
21
|
+
}); }
|
|
10
22
|
async exec() {
|
|
11
23
|
await this.twoFaLib.setSyncServerUrl(this.serverUrl);
|
|
12
24
|
return { success: true };
|
|
@@ -12,6 +12,17 @@ class VaultCreateCommand extends BaseCommand {
|
|
|
12
12
|
this.requireTwoFaLib = false;
|
|
13
13
|
}
|
|
14
14
|
static { this.paths = [['vault', 'create']]; }
|
|
15
|
+
static { this.usage = BaseCommand.Usage({
|
|
16
|
+
category: 'Vault',
|
|
17
|
+
description: 'Create a new encrypted vault',
|
|
18
|
+
details: `
|
|
19
|
+
This command creates a new encrypted vault file to store your 2FA entries.
|
|
20
|
+
|
|
21
|
+
You will be prompted to enter a passphrase that will be used to encrypt the vault.
|
|
22
|
+
The passphrase will be securely stored in your system's keychain.
|
|
23
|
+
`,
|
|
24
|
+
examples: [['Create a new vault', 'vault create']],
|
|
25
|
+
}); }
|
|
15
26
|
async exec() {
|
|
16
27
|
const passphrase = (await password({
|
|
17
28
|
message: 'Enter your vault passphrase:',
|
|
@@ -19,11 +30,11 @@ class VaultCreateCommand extends BaseCommand {
|
|
|
19
30
|
}));
|
|
20
31
|
const { twoFaLib } = await twoFaLibVaultCreationUtils.createNewTwoFaLibVault(passphrase);
|
|
21
32
|
twoFaLib.addEventListener(TwoFaLibEvent.Changed, (ev) => {
|
|
22
|
-
return fs.writeFile(
|
|
33
|
+
return fs.writeFile(this.settings.vaultLocation, ev.detail.newLockedRepresentationString);
|
|
23
34
|
});
|
|
24
35
|
await Promise.all([
|
|
25
36
|
twoFaLib.forceSave(),
|
|
26
|
-
keytar.setPassword('
|
|
37
|
+
keytar.setPassword('favacli', 'vault-passphrase', passphrase),
|
|
27
38
|
]);
|
|
28
39
|
return { success: true };
|
|
29
40
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import BaseCommand from '../../BaseCommand.mjs';
|
|
2
|
+
declare class VaultDeleteCommand extends BaseCommand {
|
|
3
|
+
static paths: string[][];
|
|
4
|
+
requireTwoFaLib: boolean;
|
|
5
|
+
static usage: import("clipanion").Usage;
|
|
6
|
+
exec(): Promise<{
|
|
7
|
+
success: boolean;
|
|
8
|
+
cancelled: boolean;
|
|
9
|
+
} | {
|
|
10
|
+
success: boolean;
|
|
11
|
+
cancelled?: undefined;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export default VaultDeleteCommand;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import { confirm } from '@inquirer/prompts';
|
|
3
|
+
import BaseCommand from '../../BaseCommand.mjs';
|
|
4
|
+
class VaultDeleteCommand extends BaseCommand {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.requireTwoFaLib = false;
|
|
8
|
+
}
|
|
9
|
+
static { this.paths = [['vault', 'delete']]; }
|
|
10
|
+
static { this.usage = BaseCommand.Usage({
|
|
11
|
+
category: 'Vault',
|
|
12
|
+
description: 'Delete the current vault',
|
|
13
|
+
details: `
|
|
14
|
+
This command deletes the current vault file.
|
|
15
|
+
You will be asked to confirm before deletion.
|
|
16
|
+
`,
|
|
17
|
+
examples: [['Delete the current vault', 'vault delete']],
|
|
18
|
+
}); }
|
|
19
|
+
async exec() {
|
|
20
|
+
const shouldDelete = await confirm({
|
|
21
|
+
message: 'Are you sure you want to delete the vault? This action cannot be undone.',
|
|
22
|
+
default: false,
|
|
23
|
+
});
|
|
24
|
+
if (!shouldDelete) {
|
|
25
|
+
this.output('Vault deletion cancelled.\n');
|
|
26
|
+
return { success: false, cancelled: true };
|
|
27
|
+
}
|
|
28
|
+
await fs.rm(this.settings.vaultLocation);
|
|
29
|
+
this.output('Vault deleted successfully.\n');
|
|
30
|
+
return { success: true };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export default VaultDeleteCommand;
|
package/build/main.mjs
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Cli } from 'clipanion';
|
|
2
|
+
import { Cli, Builtins } from 'clipanion';
|
|
3
3
|
import VaultCreateCommand from './commands/vault/create.mjs';
|
|
4
|
+
import VaultDeleteCommand from './commands/vault/delete.mjs';
|
|
4
5
|
import EntriesAddCommand from './commands/entries/add.mjs';
|
|
5
6
|
import EntriesListCommand from './commands/entries/list.mjs';
|
|
6
7
|
import EntriesSearchCommand from './commands/entries/search.mjs';
|
|
7
8
|
import SyncSetServerUrlCommand from './commands/sync/setServerUrl.mjs';
|
|
8
9
|
import SyncConnect from './commands/sync/connect.mjs';
|
|
9
|
-
|
|
10
|
+
// check node version
|
|
11
|
+
const nodeRuntimeMajorVersion = parseInt(process.version.split('.')[0]);
|
|
12
|
+
if (nodeRuntimeMajorVersion < 20) {
|
|
13
|
+
throw new Error('Node.js version must be 20 or higher');
|
|
14
|
+
}
|
|
15
|
+
const [, , ...args] = process.argv;
|
|
10
16
|
const cli = new Cli({
|
|
11
|
-
binaryLabel:
|
|
12
|
-
binaryName:
|
|
13
|
-
binaryVersion:
|
|
17
|
+
binaryLabel: 'FavaCli',
|
|
18
|
+
binaryName: `favacli`,
|
|
19
|
+
binaryVersion: '0.0.8',
|
|
14
20
|
});
|
|
15
21
|
cli.register(VaultCreateCommand);
|
|
22
|
+
cli.register(VaultDeleteCommand);
|
|
16
23
|
cli.register(EntriesAddCommand);
|
|
17
24
|
cli.register(EntriesListCommand);
|
|
18
25
|
cli.register(EntriesSearchCommand);
|
|
19
26
|
cli.register(SyncSetServerUrlCommand);
|
|
20
27
|
cli.register(SyncConnect);
|
|
28
|
+
cli.register(Builtins.HelpCommand);
|
|
21
29
|
void cli.runExit(args);
|
package/build/utils/init.d.mts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { LockedRepresentationString } from 'favalib';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
export interface Settings {
|
|
3
|
+
vaultLocation: string;
|
|
4
|
+
}
|
|
4
5
|
declare const init: () => Promise<{
|
|
5
|
-
settings:
|
|
6
|
+
settings: Settings;
|
|
6
7
|
lockedRepresentationString: LockedRepresentationString;
|
|
7
8
|
}>;
|
|
8
9
|
export default init;
|
package/build/utils/init.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
|
-
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import envPaths from 'env-paths';
|
|
4
|
+
const getDefaultSettings = () => ({
|
|
5
|
+
vaultLocation: path.join(envPaths('favacli').data, 'vault.json'),
|
|
6
|
+
});
|
|
3
7
|
const readFile = async (path) => {
|
|
4
8
|
try {
|
|
5
9
|
return (await fs.readFile(path)).toString();
|
|
@@ -18,13 +22,21 @@ const readJSONFile = async (path) => {
|
|
|
18
22
|
}
|
|
19
23
|
return JSON.parse(contents);
|
|
20
24
|
};
|
|
25
|
+
const ensureDirectoriesExists = async (...paths) => {
|
|
26
|
+
for (const p of paths) {
|
|
27
|
+
const directory = path.dirname(p);
|
|
28
|
+
await fs.mkdir(directory, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
};
|
|
21
31
|
const init = async () => {
|
|
22
|
-
|
|
32
|
+
const settingsLocation = path.join(envPaths('favacli').config, 'settings.json');
|
|
33
|
+
let settings = await readJSONFile(settingsLocation);
|
|
23
34
|
if (!settings) {
|
|
24
|
-
settings =
|
|
25
|
-
await
|
|
35
|
+
settings = getDefaultSettings();
|
|
36
|
+
await ensureDirectoriesExists(settingsLocation, settings.vaultLocation);
|
|
37
|
+
await fs.writeFile(settingsLocation, JSON.stringify(settings, null, 2));
|
|
26
38
|
}
|
|
27
|
-
const lockedRepresentationString = (await readFile(
|
|
39
|
+
const lockedRepresentationString = (await readFile(settings.vaultLocation));
|
|
28
40
|
return { settings, lockedRepresentationString };
|
|
29
41
|
};
|
|
30
42
|
export default init;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type LockedRepresentationString } from 'favalib';
|
|
2
|
-
|
|
2
|
+
import { Settings } from './init.mjs';
|
|
3
|
+
declare const loadVault: (vaultData: LockedRepresentationString, settings: Settings, verbose?: boolean) => Promise<import("favalib").TwoFaLib>;
|
|
3
4
|
export default loadVault;
|
|
@@ -4,11 +4,11 @@ import { getTwoFaLibVaultCreationUtils, TwoFaLibEvent, } from 'favalib';
|
|
|
4
4
|
import NodeCryptoProvider from 'favalib/cryptoProviders/node';
|
|
5
5
|
const cryptoLib = new NodeCryptoProvider();
|
|
6
6
|
const twoFaLibVaultCreationUtils = getTwoFaLibVaultCreationUtils(cryptoLib, 'cli', ['cli']);
|
|
7
|
-
const loadVault = async (vaultData, verbose = false) => {
|
|
8
|
-
const passphrase = (await keytar.getPassword('
|
|
7
|
+
const loadVault = async (vaultData, settings, verbose = false) => {
|
|
8
|
+
const passphrase = (await keytar.getPassword('favacli', 'vault-passphrase'));
|
|
9
9
|
const twoFaLib = await twoFaLibVaultCreationUtils.loadTwoFaLibFromLockedRepesentation(vaultData, passphrase);
|
|
10
10
|
twoFaLib.addEventListener(TwoFaLibEvent.Changed, (ev) => {
|
|
11
|
-
return fs.writeFile(
|
|
11
|
+
return fs.writeFile(settings.vaultLocation, ev.detail.newLockedRepresentationString);
|
|
12
12
|
});
|
|
13
13
|
twoFaLib.addEventListener(TwoFaLibEvent.Log, (ev) => {
|
|
14
14
|
if (ev.detail.severity !== 'info' || verbose) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "favacli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"@inquirer/prompts": "^7.0.1",
|
|
10
10
|
"bufferutil": "^4.0.8",
|
|
11
11
|
"clipanion": "^4.0.0-rc.4",
|
|
12
|
-
"
|
|
12
|
+
"env-paths": "^3.0.0",
|
|
13
|
+
"favalib": "^0.0.2",
|
|
13
14
|
"keytar": "^7.9.0",
|
|
14
15
|
"node-loader": "^2.0.0",
|
|
15
16
|
"ts-loader": "^9.5.1",
|
|
@@ -25,5 +26,8 @@
|
|
|
25
26
|
},
|
|
26
27
|
"files": [
|
|
27
28
|
"/build"
|
|
28
|
-
]
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
}
|
|
29
33
|
}
|