decryption 0.5.1 → 0.6.1

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