decryption 0.5.1 → 0.6.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 +21 -0
- package/README.md +17 -325
- package/index.js +3 -66
- package/package.json +8 -24
- package/commands/account.d.ts +0 -4
- package/commands/account.js +0 -470
- package/commands/cosmology.d.ts +0 -4
- package/commands/cosmology.js +0 -97
- package/commands/doctor.d.ts +0 -3
- package/commands/doctor.js +0 -42
- package/commands/encrypt.d.ts +0 -12
- package/commands/encrypt.js +0 -251
- package/commands/guard.d.ts +0 -3
- package/commands/guard.js +0 -92
- package/commands/keychain.d.ts +0 -4
- package/commands/keychain.js +0 -92
- package/commands/keys.d.ts +0 -4
- package/commands/keys.js +0 -74
- package/commands/passkey.d.ts +0 -4
- package/commands/passkey.js +0 -135
- package/commands/salt.d.ts +0 -4
- package/commands/salt.js +0 -113
- package/commands/secrets.d.ts +0 -4
- package/commands/secrets.js +0 -214
- package/commands/shamir.d.ts +0 -4
- package/commands/shamir.js +0 -62
- package/commands/vault.d.ts +0 -7
- package/commands/vault.js +0 -382
- package/commands/wallet.d.ts +0 -5
- package/commands/wallet.js +0 -129
- package/commands/workspace.d.ts +0 -8
- package/commands/workspace.js +0 -289
- package/commands.d.ts +0 -8
- package/commands.js +0 -126
- package/esm/commands/account.js +0 -466
- package/esm/commands/cosmology.js +0 -93
- package/esm/commands/doctor.js +0 -38
- package/esm/commands/encrypt.js +0 -245
- package/esm/commands/guard.js +0 -88
- package/esm/commands/keychain.js +0 -88
- package/esm/commands/keys.js +0 -70
- package/esm/commands/passkey.js +0 -131
- package/esm/commands/salt.js +0 -109
- package/esm/commands/secrets.js +0 -210
- package/esm/commands/shamir.js +0 -58
- package/esm/commands/vault.js +0 -376
- package/esm/commands/wallet.js +0 -125
- package/esm/commands/workspace.js +0 -283
- package/esm/commands.js +0 -120
- package/esm/index.js +0 -50
- package/esm/utils/bytes.js +0 -286
- package/esm/utils/dispatch.js +0 -52
- package/esm/utils/env.js +0 -44
- package/esm/utils/errors.js +0 -44
- package/esm/utils/header.js +0 -14
- package/esm/utils/io.js +0 -49
- package/esm/utils/passphrase.js +0 -49
- package/esm/utils/recipients.js +0 -74
- package/esm/utils/stash.js +0 -61
- package/esm/utils/temp.js +0 -51
- package/esm/utils/text.js +0 -2
- package/esm/workspace/bundle.js +0 -239
- package/esm/workspace/doctor.js +0 -104
- package/esm/workspace/git.js +0 -72
- package/esm/workspace/guard.js +0 -111
- package/esm/workspace/layout.js +0 -106
- package/esm/workspace/manifest.js +0 -147
- package/esm/workspace/recipients.js +0 -37
- package/esm/workspace/snippets.js +0 -54
- package/esm/workspace/state.js +0 -46
- package/esm/workspace/status.js +0 -93
- package/esm/workspace/tar.js +0 -235
- package/index.d.ts +0 -12
- package/utils/bytes.d.ts +0 -86
- package/utils/bytes.js +0 -301
- package/utils/dispatch.d.ts +0 -24
- package/utils/dispatch.js +0 -58
- package/utils/env.d.ts +0 -26
- package/utils/env.js +0 -49
- package/utils/errors.d.ts +0 -25
- package/utils/errors.js +0 -50
- package/utils/header.d.ts +0 -4
- package/utils/header.js +0 -18
- package/utils/io.d.ts +0 -10
- package/utils/io.js +0 -57
- package/utils/passphrase.d.ts +0 -15
- package/utils/passphrase.js +0 -53
- package/utils/recipients.d.ts +0 -28
- package/utils/recipients.js +0 -80
- package/utils/stash.d.ts +0 -40
- package/utils/stash.js +0 -76
- package/utils/temp.d.ts +0 -10
- package/utils/temp.js +0 -59
- package/utils/text.d.ts +0 -2
- package/utils/text.js +0 -6
- package/workspace/bundle.d.ts +0 -50
- package/workspace/bundle.js +0 -248
- package/workspace/doctor.d.ts +0 -8
- package/workspace/doctor.js +0 -108
- package/workspace/git.d.ts +0 -21
- package/workspace/git.js +0 -83
- package/workspace/guard.d.ts +0 -23
- package/workspace/guard.js +0 -118
- package/workspace/layout.d.ts +0 -47
- package/workspace/layout.js +0 -113
- package/workspace/manifest.d.ts +0 -52
- package/workspace/manifest.js +0 -157
- package/workspace/recipients.d.ts +0 -16
- package/workspace/recipients.js +0 -45
- package/workspace/snippets.d.ts +0 -29
- package/workspace/snippets.js +0 -58
- package/workspace/state.d.ts +0 -13
- package/workspace/state.js +0 -52
- package/workspace/status.d.ts +0 -54
- package/workspace/status.js +0 -99
- package/workspace/tar.d.ts +0 -29
- package/workspace/tar.js +0 -240
package/commands/salt.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { ParsedArgs } from 'minimist';
|
|
3
|
-
export declare const saltUsage = "\nSalt Command:\n\n dcrypt salt <subcommand> [OPTIONS]\n\n Two-layer encryption, the modern replacement for the old salt-encrypt/salt-decrypt\n flow: a random high-entropy salt encrypts the data, and your passphrase encrypts\n the salt. Rotating the passphrase then only re-encrypts the salt, not the data.\n\nSubcommands:\n generate Print a fresh random salt\n encrypt Encrypt data under a new salt, and the salt under your passphrase\n decrypt Unwrap the salt, then the data\n\nOptions:\n --bytes <n> Salt size for \"generate\" (default: 32)\n --kdf <profile> interactive | moderate | sensitive (default: moderate)\n --in <file> Read the plaintext/ciphertext from a file (\"-\" for stdin)\n --salt-file <file> Where the encrypted salt lives (default: alongside --out)\n --out <file> Write output to a file\n --json Machine-readable output (both layers in one object)\n --passphrase-file <p> Read the passphrase from a file\n --passphrase-stdin Read the passphrase from stdin\n --help, -h Show this help message\n\nExamples:\n dcrypt salt generate\n dcrypt salt encrypt --in secrets.txt --out secrets.dcrypt --salt-file secrets.salt\n dcrypt salt decrypt --in secrets.dcrypt --salt-file secrets.salt\n";
|
|
4
|
-
export declare const saltCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|
package/commands/salt.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.saltCommand = exports.saltUsage = void 0;
|
|
4
|
-
const base_1 = require("@decryption/base");
|
|
5
|
-
const core_1 = require("@decryption/core");
|
|
6
|
-
const utils_1 = require("@decryption/hashes/utils");
|
|
7
|
-
const dispatch_1 = require("../utils/dispatch");
|
|
8
|
-
const errors_1 = require("../utils/errors");
|
|
9
|
-
const io_1 = require("../utils/io");
|
|
10
|
-
const passphrase_1 = require("../utils/passphrase");
|
|
11
|
-
const stash_1 = require("../utils/stash");
|
|
12
|
-
const encrypt_1 = require("./encrypt");
|
|
13
|
-
exports.saltUsage = `
|
|
14
|
-
Salt Command:
|
|
15
|
-
|
|
16
|
-
dcrypt salt <subcommand> [OPTIONS]
|
|
17
|
-
|
|
18
|
-
Two-layer encryption, the modern replacement for the old salt-encrypt/salt-decrypt
|
|
19
|
-
flow: a random high-entropy salt encrypts the data, and your passphrase encrypts
|
|
20
|
-
the salt. Rotating the passphrase then only re-encrypts the salt, not the data.
|
|
21
|
-
|
|
22
|
-
Subcommands:
|
|
23
|
-
generate Print a fresh random salt
|
|
24
|
-
encrypt Encrypt data under a new salt, and the salt under your passphrase
|
|
25
|
-
decrypt Unwrap the salt, then the data
|
|
26
|
-
|
|
27
|
-
Options:
|
|
28
|
-
--bytes <n> Salt size for "generate" (default: 32)
|
|
29
|
-
--kdf <profile> interactive | moderate | sensitive (default: moderate)
|
|
30
|
-
--in <file> Read the plaintext/ciphertext from a file ("-" for stdin)
|
|
31
|
-
--salt-file <file> Where the encrypted salt lives (default: alongside --out)
|
|
32
|
-
--out <file> Write output to a file
|
|
33
|
-
--json Machine-readable output (both layers in one object)
|
|
34
|
-
--passphrase-file <p> Read the passphrase from a file
|
|
35
|
-
--passphrase-stdin Read the passphrase from stdin
|
|
36
|
-
--help, -h Show this help message
|
|
37
|
-
|
|
38
|
-
Examples:
|
|
39
|
-
dcrypt salt generate
|
|
40
|
-
dcrypt salt encrypt --in secrets.txt --out secrets.dcrypt --salt-file secrets.salt
|
|
41
|
-
dcrypt salt decrypt --in secrets.dcrypt --salt-file secrets.salt
|
|
42
|
-
`;
|
|
43
|
-
const generate = (argv) => {
|
|
44
|
-
const bytes = Number(argv.bytes ?? 32);
|
|
45
|
-
if (!Number.isInteger(bytes) || bytes < 16 || bytes > 128) {
|
|
46
|
-
throw new errors_1.CliError('--bytes must be an integer between 16 and 128');
|
|
47
|
-
}
|
|
48
|
-
const salt = base_1.base64.encode((0, utils_1.randomBytes)(bytes));
|
|
49
|
-
(0, io_1.emit)(argv, { salt }, () => salt);
|
|
50
|
-
};
|
|
51
|
-
const encryptCmd = async (argv, prompter) => {
|
|
52
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
53
|
-
const plaintext = (0, io_1.readInput)(newArgv, first);
|
|
54
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(newArgv, prompter, { confirm: true });
|
|
55
|
-
const saltBytes = (0, utils_1.randomBytes)(32);
|
|
56
|
-
const salt = base_1.base64.encode(saltBytes);
|
|
57
|
-
const bundle = {
|
|
58
|
-
dcrypt: 1,
|
|
59
|
-
salt: (0, core_1.encryptToString)(salt, passphrase, { aad: 'dcrypt-salt', kdf: (0, encrypt_1.resolveKdf)(newArgv.kdf) }),
|
|
60
|
-
ciphertext: (0, core_1.encryptToString)(plaintext, salt, {
|
|
61
|
-
aad: 'dcrypt-salt-payload',
|
|
62
|
-
kdf: (0, encrypt_1.resolveKdf)(newArgv.kdf),
|
|
63
|
-
}),
|
|
64
|
-
};
|
|
65
|
-
saltBytes.fill(0);
|
|
66
|
-
const saltFile = saltFileOf(newArgv);
|
|
67
|
-
if (saltFile) {
|
|
68
|
-
(0, stash_1.writeJson)(saltFile, { dcrypt: 1, salt: bundle.salt });
|
|
69
|
-
(0, io_1.writeOutput)(newArgv, bundle.ciphertext);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
(0, io_1.emit)(newArgv, bundle, () => JSON.stringify(bundle, null, 2));
|
|
73
|
-
};
|
|
74
|
-
const decryptCmd = async (argv, prompter) => {
|
|
75
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
76
|
-
const bundle = loadBundle(newArgv, first);
|
|
77
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(newArgv, prompter);
|
|
78
|
-
const salt = (0, core_1.decryptFromString)(bundle.salt, passphrase, { aad: 'dcrypt-salt' });
|
|
79
|
-
(0, io_1.writeOutput)(newArgv, (0, core_1.decryptFromString)(bundle.ciphertext, salt, { aad: 'dcrypt-salt-payload' }));
|
|
80
|
-
};
|
|
81
|
-
const loadBundle = (argv, inline) => {
|
|
82
|
-
const saltFile = saltFileOf(argv);
|
|
83
|
-
const input = (0, io_1.readInput)(argv, inline).trim();
|
|
84
|
-
if (saltFile) {
|
|
85
|
-
const { salt } = (0, stash_1.readJson)(saltFile);
|
|
86
|
-
if (!salt)
|
|
87
|
-
throw new errors_1.CliError(`${saltFile} does not contain an encrypted salt`, errors_1.EXIT.corrupt);
|
|
88
|
-
return { dcrypt: 1, salt, ciphertext: input };
|
|
89
|
-
}
|
|
90
|
-
let parsed;
|
|
91
|
-
try {
|
|
92
|
-
parsed = JSON.parse(input);
|
|
93
|
-
}
|
|
94
|
-
catch {
|
|
95
|
-
throw new errors_1.CliError('expected a salt bundle as JSON, or pass --salt-file', errors_1.EXIT.corrupt);
|
|
96
|
-
}
|
|
97
|
-
if (!parsed.salt || !parsed.ciphertext) {
|
|
98
|
-
throw new errors_1.CliError('salt bundle must have "salt" and "ciphertext"', errors_1.EXIT.corrupt);
|
|
99
|
-
}
|
|
100
|
-
return { dcrypt: 1, salt: parsed.salt, ciphertext: parsed.ciphertext };
|
|
101
|
-
};
|
|
102
|
-
const saltFileOf = (argv) => {
|
|
103
|
-
const value = argv['salt-file'] ?? argv.saltFile;
|
|
104
|
-
return typeof value === 'string' && value.length ? value : undefined;
|
|
105
|
-
};
|
|
106
|
-
const saltCommand = async (argv, prompter) => {
|
|
107
|
-
await (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
108
|
-
name: 'salt',
|
|
109
|
-
usage: exports.saltUsage,
|
|
110
|
-
handlers: { generate, encrypt: encryptCmd, decrypt: decryptCmd },
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
exports.saltCommand = saltCommand;
|
package/commands/secrets.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { ParsedArgs } from 'minimist';
|
|
3
|
-
export declare const secretsUsage = "\nSecrets Command:\n\n dcrypt secrets <subcommand> [OPTIONS]\n\n Team secrets in a file you can commit: every value is encrypted individually, and\n access is granted by adding recipients rather than by sharing a passphrase.\n\nSubcommands:\n init Create a vault with you as its first recipient\n set <NAME> Store a secret\n get <NAME> Print one secret\n list List secret names (no values, no passphrase needed)\n rm <NAME> Remove a secret\n import Load secrets from a .env file\n export Print all secrets as dotenv/json/yaml/shell\n run -- <cmd\u2026> Run a command with the secrets in its environment\n recipients List recipients\n add-recipient Grant access to a teammate (rekeys the vault)\n rm-recipient Revoke access (rekeys the vault)\n rekey Re-encrypt under a fresh file key\n\nOptions:\n --vault <name> Vault stored in ~/.dcrypt/data/vaults (default: default)\n --file <path> Vault file path, overrides --vault\n --format <fmt> dotenv | json | yaml | shell (default: dotenv)\n --label <name> Recipient label, for add-recipient\n --recipient <dcrypt1\u2026> Recipient string, for add-recipient\n --in <file> Read a value or .env file (\"-\" for stdin)\n --out <file> Write output to a file\n --json Machine-readable output\n --passphrase-file <p> Read the passphrase from a file\n --passphrase-stdin Read the passphrase from stdin\n --help, -h Show this help message\n\nExamples:\n dcrypt secrets init --vault production\n dcrypt secrets set DATABASE_URL --in url.txt --vault production\n dcrypt secrets export --vault production --format dotenv --out .env\n dcrypt secrets run --vault production -- npm start\n dcrypt secrets add-recipient --label ada --recipient dcrypt1\u2026\n";
|
|
4
|
-
export declare const secretsCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|
package/commands/secrets.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.secretsCommand = exports.secretsUsage = void 0;
|
|
4
|
-
const secrets_1 = require("@decryption/secrets");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const dispatch_1 = require("../utils/dispatch");
|
|
8
|
-
const errors_1 = require("../utils/errors");
|
|
9
|
-
const io_1 = require("../utils/io");
|
|
10
|
-
const passphrase_1 = require("../utils/passphrase");
|
|
11
|
-
const stash_1 = require("../utils/stash");
|
|
12
|
-
exports.secretsUsage = `
|
|
13
|
-
Secrets Command:
|
|
14
|
-
|
|
15
|
-
dcrypt secrets <subcommand> [OPTIONS]
|
|
16
|
-
|
|
17
|
-
Team secrets in a file you can commit: every value is encrypted individually, and
|
|
18
|
-
access is granted by adding recipients rather than by sharing a passphrase.
|
|
19
|
-
|
|
20
|
-
Subcommands:
|
|
21
|
-
init Create a vault with you as its first recipient
|
|
22
|
-
set <NAME> Store a secret
|
|
23
|
-
get <NAME> Print one secret
|
|
24
|
-
list List secret names (no values, no passphrase needed)
|
|
25
|
-
rm <NAME> Remove a secret
|
|
26
|
-
import Load secrets from a .env file
|
|
27
|
-
export Print all secrets as dotenv/json/yaml/shell
|
|
28
|
-
run -- <cmd…> Run a command with the secrets in its environment
|
|
29
|
-
recipients List recipients
|
|
30
|
-
add-recipient Grant access to a teammate (rekeys the vault)
|
|
31
|
-
rm-recipient Revoke access (rekeys the vault)
|
|
32
|
-
rekey Re-encrypt under a fresh file key
|
|
33
|
-
|
|
34
|
-
Options:
|
|
35
|
-
--vault <name> Vault stored in ~/.dcrypt/data/vaults (default: default)
|
|
36
|
-
--file <path> Vault file path, overrides --vault
|
|
37
|
-
--format <fmt> dotenv | json | yaml | shell (default: dotenv)
|
|
38
|
-
--label <name> Recipient label, for add-recipient
|
|
39
|
-
--recipient <dcrypt1…> Recipient string, for add-recipient
|
|
40
|
-
--in <file> Read a value or .env file ("-" for stdin)
|
|
41
|
-
--out <file> Write output to a file
|
|
42
|
-
--json Machine-readable output
|
|
43
|
-
--passphrase-file <p> Read the passphrase from a file
|
|
44
|
-
--passphrase-stdin Read the passphrase from stdin
|
|
45
|
-
--help, -h Show this help message
|
|
46
|
-
|
|
47
|
-
Examples:
|
|
48
|
-
dcrypt secrets init --vault production
|
|
49
|
-
dcrypt secrets set DATABASE_URL --in url.txt --vault production
|
|
50
|
-
dcrypt secrets export --vault production --format dotenv --out .env
|
|
51
|
-
dcrypt secrets run --vault production -- npm start
|
|
52
|
-
dcrypt secrets add-recipient --label ada --recipient dcrypt1…
|
|
53
|
-
`;
|
|
54
|
-
const fileOf = (argv) => {
|
|
55
|
-
const file = argv.file;
|
|
56
|
-
if (typeof file === 'string' && file.length)
|
|
57
|
-
return file;
|
|
58
|
-
return (0, stash_1.vaultPath)(String(argv.vault ?? 'default'));
|
|
59
|
-
};
|
|
60
|
-
const loadVault = (argv) => {
|
|
61
|
-
const path = fileOf(argv);
|
|
62
|
-
if (!(0, fs_1.existsSync)(path)) {
|
|
63
|
-
throw new errors_1.CliError(`no vault at ${path} — run \`dcrypt secrets init\` first`, errors_1.EXIT.notFound);
|
|
64
|
-
}
|
|
65
|
-
return (0, secrets_1.parseVault)((0, fs_1.readFileSync)(path, 'utf8'));
|
|
66
|
-
};
|
|
67
|
-
const storeVault = (argv, vault) => {
|
|
68
|
-
(0, fs_1.writeFileSync)(fileOf(argv), (0, secrets_1.serializeVault)(vault), { mode: 0o600 });
|
|
69
|
-
};
|
|
70
|
-
const unlockIdentity = async (argv, prompter) => (0, stash_1.loadIdentity)(await (0, passphrase_1.resolvePassphrase)(argv, prompter, { message: 'Identity passphrase' }));
|
|
71
|
-
const nameOf = (argv) => {
|
|
72
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
73
|
-
const name = first ?? (typeof argv.name === 'string' ? argv.name : undefined);
|
|
74
|
-
if (!name)
|
|
75
|
-
throw new errors_1.CliError('a secret name is required');
|
|
76
|
-
return { name, newArgv };
|
|
77
|
-
};
|
|
78
|
-
const init = (argv) => {
|
|
79
|
-
const path = fileOf(argv);
|
|
80
|
-
if ((0, fs_1.existsSync)(path) && !argv.force) {
|
|
81
|
-
throw new errors_1.CliError(`${path} already exists; pass --force to replace it`);
|
|
82
|
-
}
|
|
83
|
-
const stored = (0, stash_1.readStoredIdentity)();
|
|
84
|
-
const vault = (0, secrets_1.createVault)({
|
|
85
|
-
name: String(argv.vault ?? 'default'),
|
|
86
|
-
recipients: [{ label: String(argv.label ?? 'me'), recipient: stored.recipient }],
|
|
87
|
-
});
|
|
88
|
-
storeVault(argv, vault);
|
|
89
|
-
(0, io_1.emit)(argv, { path, recipient: stored.recipient }, () => `created ${path}`);
|
|
90
|
-
};
|
|
91
|
-
const set = async (argv, prompter) => {
|
|
92
|
-
const { name, newArgv } = nameOf(argv);
|
|
93
|
-
const { first: inline, newArgv: rest } = (0, dispatch_1.takeFirst)(newArgv);
|
|
94
|
-
const value = (0, io_1.readInput)(rest, inline).replace(/\r?\n$/, '');
|
|
95
|
-
const identity = await unlockIdentity(rest, prompter);
|
|
96
|
-
storeVault(rest, (0, secrets_1.setValues)(loadVault(rest), identity, { [name]: value }));
|
|
97
|
-
identity.privateKey.fill(0);
|
|
98
|
-
(0, io_1.emit)(rest, { name, saved: true }, () => `set ${name}`);
|
|
99
|
-
};
|
|
100
|
-
const get = async (argv, prompter) => {
|
|
101
|
-
const { name, newArgv } = nameOf(argv);
|
|
102
|
-
const identity = await unlockIdentity(newArgv, prompter);
|
|
103
|
-
try {
|
|
104
|
-
(0, io_1.writeOutput)(newArgv, (0, secrets_1.getValue)(loadVault(newArgv), identity, name));
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
identity.privateKey.fill(0);
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
const list = (argv) => {
|
|
111
|
-
const names = (0, secrets_1.listKeys)(loadVault(argv));
|
|
112
|
-
(0, io_1.emit)(argv, { secrets: names }, () => names.join('\n'));
|
|
113
|
-
};
|
|
114
|
-
const rm = (argv) => {
|
|
115
|
-
const { name, newArgv } = nameOf(argv);
|
|
116
|
-
storeVault(newArgv, (0, secrets_1.deleteValue)(loadVault(newArgv), name));
|
|
117
|
-
(0, io_1.emit)(newArgv, { name, deleted: true }, () => `removed ${name}`);
|
|
118
|
-
};
|
|
119
|
-
const importCmd = async (argv, prompter) => {
|
|
120
|
-
const values = (0, secrets_1.parseDotenv)((0, io_1.readInput)(argv));
|
|
121
|
-
if (Object.keys(values).length === 0)
|
|
122
|
-
throw new errors_1.CliError('no assignments found in the input');
|
|
123
|
-
const identity = await unlockIdentity(argv, prompter);
|
|
124
|
-
storeVault(argv, (0, secrets_1.setValues)(loadVault(argv), identity, values));
|
|
125
|
-
identity.privateKey.fill(0);
|
|
126
|
-
(0, io_1.emit)(argv, { imported: Object.keys(values) }, () => `imported ${Object.keys(values).length} secrets`);
|
|
127
|
-
};
|
|
128
|
-
const exportCmd = async (argv, prompter) => {
|
|
129
|
-
const format = String(argv.format ?? 'dotenv');
|
|
130
|
-
const identity = await unlockIdentity(argv, prompter);
|
|
131
|
-
try {
|
|
132
|
-
(0, io_1.writeOutput)(argv, (0, secrets_1.exportValues)(loadVault(argv), identity, format));
|
|
133
|
-
}
|
|
134
|
-
finally {
|
|
135
|
-
identity.privateKey.fill(0);
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const run = async (argv, prompter) => {
|
|
139
|
-
const command = argv['--'];
|
|
140
|
-
if (!command || command.length === 0) {
|
|
141
|
-
throw new errors_1.CliError('nothing to run: put the command after `--`');
|
|
142
|
-
}
|
|
143
|
-
const identity = await unlockIdentity(argv, prompter);
|
|
144
|
-
let values;
|
|
145
|
-
try {
|
|
146
|
-
values = (0, secrets_1.getValues)(loadVault(argv), identity);
|
|
147
|
-
}
|
|
148
|
-
finally {
|
|
149
|
-
identity.privateKey.fill(0);
|
|
150
|
-
}
|
|
151
|
-
const [bin, ...args] = command;
|
|
152
|
-
const result = (0, child_process_1.spawnSync)(bin, args, {
|
|
153
|
-
stdio: 'inherit',
|
|
154
|
-
env: { ...process.env, ...values },
|
|
155
|
-
});
|
|
156
|
-
if (result.error)
|
|
157
|
-
throw new errors_1.CliError(`failed to run ${bin}: ${result.error.message}`);
|
|
158
|
-
if (result.status !== 0)
|
|
159
|
-
throw new errors_1.CliError(`${bin} exited with ${result.status}`, result.status ?? 1);
|
|
160
|
-
};
|
|
161
|
-
const recipients = (argv) => {
|
|
162
|
-
const vault = loadVault(argv);
|
|
163
|
-
(0, io_1.emit)(argv, { recipients: vault.recipients }, () => vault.recipients.map((r) => `${r.label}\t${r.recipient}`).join('\n'));
|
|
164
|
-
};
|
|
165
|
-
const addRecipientCmd = async (argv, prompter) => {
|
|
166
|
-
const answers = await prompter.prompt(argv, [
|
|
167
|
-
{ type: 'text', name: 'label', message: 'Label for this teammate', required: true },
|
|
168
|
-
{ type: 'text', name: 'recipient', message: 'Their dcrypt1… recipient string', required: true },
|
|
169
|
-
]);
|
|
170
|
-
const identity = await unlockIdentity(argv, prompter);
|
|
171
|
-
storeVault(argv, (0, secrets_1.addRecipient)(loadVault(argv), identity, {
|
|
172
|
-
label: String(answers.label),
|
|
173
|
-
recipient: String(answers.recipient),
|
|
174
|
-
}));
|
|
175
|
-
identity.privateKey.fill(0);
|
|
176
|
-
(0, io_1.emit)(argv, { added: answers.label, rekeyed: true }, () => `added ${answers.label} and rekeyed`);
|
|
177
|
-
};
|
|
178
|
-
const removeRecipientCmd = async (argv, prompter) => {
|
|
179
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
180
|
-
const target = first ?? (typeof argv.label === 'string' ? argv.label : undefined);
|
|
181
|
-
if (!target)
|
|
182
|
-
throw new errors_1.CliError('pass the label or recipient string to remove');
|
|
183
|
-
const identity = await unlockIdentity(newArgv, prompter);
|
|
184
|
-
storeVault(newArgv, (0, secrets_1.removeRecipient)(loadVault(newArgv), identity, target));
|
|
185
|
-
identity.privateKey.fill(0);
|
|
186
|
-
(0, io_1.emit)(newArgv, { removed: target, rekeyed: true }, () => `removed ${target} and rekeyed`);
|
|
187
|
-
};
|
|
188
|
-
const rekey = async (argv, prompter) => {
|
|
189
|
-
const identity = await unlockIdentity(argv, prompter);
|
|
190
|
-
storeVault(argv, (0, secrets_1.rotateFileKey)(loadVault(argv), identity));
|
|
191
|
-
identity.privateKey.fill(0);
|
|
192
|
-
(0, io_1.emit)(argv, { rekeyed: true }, () => 'rekeyed');
|
|
193
|
-
};
|
|
194
|
-
const secretsCommand = async (argv, prompter) => {
|
|
195
|
-
await (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
196
|
-
name: 'secrets',
|
|
197
|
-
usage: exports.secretsUsage,
|
|
198
|
-
handlers: {
|
|
199
|
-
init,
|
|
200
|
-
set,
|
|
201
|
-
get,
|
|
202
|
-
list,
|
|
203
|
-
rm,
|
|
204
|
-
import: importCmd,
|
|
205
|
-
export: exportCmd,
|
|
206
|
-
run,
|
|
207
|
-
recipients,
|
|
208
|
-
'add-recipient': addRecipientCmd,
|
|
209
|
-
'rm-recipient': removeRecipientCmd,
|
|
210
|
-
rekey,
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
};
|
|
214
|
-
exports.secretsCommand = secretsCommand;
|
package/commands/shamir.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { ParsedArgs } from 'minimist';
|
|
3
|
-
export declare const shamirUsage = "\nShamir Command:\n\n dcrypt shamir <subcommand> [OPTIONS]\n\n Split a secret into shares, any threshold of which reconstruct it. Shares are\n authenticated: a corrupt or foreign share fails loudly instead of producing garbage.\n\nSubcommands:\n split Split a secret into shares\n combine Reconstruct a secret from shares\n\nOptions:\n --shares <n> Number of shares to produce (default: 5)\n --threshold <n> Shares required to recover (default: 3)\n --in <file> Read the secret, or newline-separated shares, from a file (\"-\" for stdin)\n --share <value> A share; repeat the flag once per share (combine)\n --out <file> Write output to a file\n --json Machine-readable output\n --help, -h Show this help message\n\nExamples:\n dcrypt shamir split --in mnemonic.txt --shares 5 --threshold 3\n dcrypt shamir combine --share dcrypt-share.v1.\u2026 --share dcrypt-share.v1.\u2026\n cat shares.txt | dcrypt shamir combine --in -\n";
|
|
4
|
-
export declare const shamirCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|
package/commands/shamir.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shamirCommand = exports.shamirUsage = void 0;
|
|
4
|
-
const shamir_1 = require("@decryption/shamir");
|
|
5
|
-
const dispatch_1 = require("../utils/dispatch");
|
|
6
|
-
const errors_1 = require("../utils/errors");
|
|
7
|
-
const io_1 = require("../utils/io");
|
|
8
|
-
exports.shamirUsage = `
|
|
9
|
-
Shamir Command:
|
|
10
|
-
|
|
11
|
-
dcrypt shamir <subcommand> [OPTIONS]
|
|
12
|
-
|
|
13
|
-
Split a secret into shares, any threshold of which reconstruct it. Shares are
|
|
14
|
-
authenticated: a corrupt or foreign share fails loudly instead of producing garbage.
|
|
15
|
-
|
|
16
|
-
Subcommands:
|
|
17
|
-
split Split a secret into shares
|
|
18
|
-
combine Reconstruct a secret from shares
|
|
19
|
-
|
|
20
|
-
Options:
|
|
21
|
-
--shares <n> Number of shares to produce (default: 5)
|
|
22
|
-
--threshold <n> Shares required to recover (default: 3)
|
|
23
|
-
--in <file> Read the secret, or newline-separated shares, from a file ("-" for stdin)
|
|
24
|
-
--share <value> A share; repeat the flag once per share (combine)
|
|
25
|
-
--out <file> Write output to a file
|
|
26
|
-
--json Machine-readable output
|
|
27
|
-
--help, -h Show this help message
|
|
28
|
-
|
|
29
|
-
Examples:
|
|
30
|
-
dcrypt shamir split --in mnemonic.txt --shares 5 --threshold 3
|
|
31
|
-
dcrypt shamir combine --share dcrypt-share.v1.… --share dcrypt-share.v1.…
|
|
32
|
-
cat shares.txt | dcrypt shamir combine --in -
|
|
33
|
-
`;
|
|
34
|
-
const split = (argv) => {
|
|
35
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
36
|
-
const secret = (0, io_1.readInput)(newArgv, first).trim();
|
|
37
|
-
const shares = Number(newArgv.shares ?? 5);
|
|
38
|
-
const threshold = Number(newArgv.threshold ?? 3);
|
|
39
|
-
const produced = (0, shamir_1.splitToStrings)(secret, { shares, threshold });
|
|
40
|
-
(0, io_1.emit)(newArgv, { shares: produced, threshold }, () => produced.join('\n'));
|
|
41
|
-
};
|
|
42
|
-
const combine = (argv) => {
|
|
43
|
-
const flags = argv.share ?? argv.shares;
|
|
44
|
-
const shares = flags
|
|
45
|
-
? (Array.isArray(flags) ? flags : [flags]).map(String)
|
|
46
|
-
: (0, io_1.readInput)(argv)
|
|
47
|
-
.split('\n')
|
|
48
|
-
.map((line) => line.trim())
|
|
49
|
-
.filter(Boolean);
|
|
50
|
-
if (shares.length < 2) {
|
|
51
|
-
throw new errors_1.CliError('at least two shares are required; pass --share once per share');
|
|
52
|
-
}
|
|
53
|
-
(0, io_1.writeOutput)(argv, (0, shamir_1.combineToString)(shares));
|
|
54
|
-
};
|
|
55
|
-
const shamirCommand = async (argv, prompter) => {
|
|
56
|
-
await (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
57
|
-
name: 'shamir',
|
|
58
|
-
usage: exports.shamirUsage,
|
|
59
|
-
handlers: { split, combine },
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
exports.shamirCommand = shamirCommand;
|
package/commands/vault.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Vault } from '@decryption/vault';
|
|
2
|
-
import { Inquirerer } from 'inquirerer';
|
|
3
|
-
import { ParsedArgs } from 'minimist';
|
|
4
|
-
export declare const vaultUsage = "\nVault Command:\n\n dcrypt vault <subcommand> [OPTIONS]\n\n The local encrypted vault, shared with the dcrypt desktop app. The whole\n database is one encrypted file; every value inside is additionally encrypted.\n\nSubcommands:\n status Show whether a vault exists and where it lives\n item list List items (titles and kinds, never values)\n item get <title> Print an item's fields (values require --reveal)\n item add <title> Add an item; value read from --in or prompted\n item rm <title> Move an item to the trash\n totp <title> Print the current one-time code for an item\n export Export items as JSON (\"--format csv\" for CSV)\n import Import items from a JSON export (\"--from csv|bitwarden\")\n\nOptions:\n --kind <kind> login | note | card | identity | wallet | totp | ssh_key\n --field <name> Field name for \"item add\" (default depends on kind)\n --reveal Include secret values in \"item get\" output\n --format <fmt> Export format: json (default) | csv\n --from <fmt> Import format: json (default) | csv | bitwarden\n --in <file> / --out Read/write files (\"-\" is stdin/stdout)\n --json Machine-readable output\n --passphrase-file <p> Read the master password from a file\n --passphrase-stdin Read the master password from stdin\n --help, -h Show this help message\n\nExamples:\n dcrypt vault item add github --kind login --field password\n dcrypt vault item get github --reveal\n dcrypt vault totp work-email\n dcrypt vault export --out backup.json\n";
|
|
5
|
-
export declare const vaultFile: () => string;
|
|
6
|
-
export declare const openVault: (argv: ParsedArgs, prompter: Inquirerer) => Promise<Vault>;
|
|
7
|
-
export declare const vaultCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|