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,289 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.statusCommand = exports.decryptWorkspaceCommand = exports.encryptSectionCommand = exports.statusUsage = exports.decryptWorkspaceUsage = exports.encryptSectionUsage = void 0;
4
- const path_1 = require("path");
5
- const dispatch_1 = require("../utils/dispatch");
6
- const errors_1 = require("../utils/errors");
7
- const io_1 = require("../utils/io");
8
- const passphrase_1 = require("../utils/passphrase");
9
- const stash_1 = require("../utils/stash");
10
- const temp_1 = require("../utils/temp");
11
- const text_1 = require("../utils/text");
12
- const bundle_1 = require("../workspace/bundle");
13
- const layout_1 = require("../workspace/layout");
14
- const recipients_1 = require("../workspace/recipients");
15
- const state_1 = require("../workspace/state");
16
- const status_1 = require("../workspace/status");
17
- const WORKSPACE_OPTIONS = ` --workspace <dir> The workspace root (default: the nearest folder upwards with a
18
- recipients.txt, otherwise the current folder)
19
- --json Machine-readable output
20
- --help, -h Show this help message`;
21
- exports.encryptSectionUsage = `
22
- Encrypt Section Command:
23
-
24
- dcrypt encrypt-section <name> [OPTIONS]
25
-
26
- Encrypt the folder <name> into <name>.tar.dcrypt, for everyone in recipients.txt.
27
- One section at a time, and only when you ask.
28
-
29
- The bundle is a single encrypted file: the names, sizes and number of the files
30
- inside it are not visible, only its total size. No passphrase is needed, because
31
- encrypting uses only public keys. Nothing is rewritten when nothing changed, and
32
- the bundle is replaced only once the new one is complete.
33
-
34
- Options:
35
- --force Replace a bundle that changed since this machine last read it
36
- ${WORKSPACE_OPTIONS}
37
-
38
- Examples:
39
- dcrypt encrypt-section finance
40
- dcrypt encrypt-section clients/northwind
41
- `;
42
- exports.decryptWorkspaceUsage = `
43
- Decrypt Workspace Command:
44
-
45
- dcrypt decrypt-workspace [name…] [OPTIONS]
46
-
47
- Decrypt every section of the workspace (or only the ones named) with your
48
- identity. You are asked for its passphrase once, and not at all when every
49
- section is already up to date.
50
-
51
- Each bundle is decrypted into a new folder and checked, file by file, against
52
- the manifest inside it. Only then does it replace the plaintext. A wrong
53
- passphrase, a damaged or truncated bundle, or an interrupt changes nothing.
54
- Plaintext you have edited and not yet encrypted is never replaced without --force.
55
-
56
- Options:
57
- --force Replace plaintext that has changes the bundle does not have
58
- --passphrase-file <p> Read the identity passphrase from a file
59
- --passphrase-stdin Read the identity passphrase from stdin
60
- ${WORKSPACE_OPTIONS}
61
-
62
- Examples:
63
- dcrypt decrypt-workspace
64
- dcrypt decrypt-workspace finance
65
- `;
66
- exports.statusUsage = `
67
- Status Command:
68
-
69
- dcrypt status [OPTIONS]
70
-
71
- Show where each section stands: in sync, plaintext changed and not yet
72
- encrypted, bundle changed and not yet decrypted, and whether a recipient in
73
- recipients.txt is missing from a bundle. Needs no passphrase.
74
-
75
- Options:
76
- ${WORKSPACE_OPTIONS}
77
- `;
78
- const warn = (message) => void process.stderr.write(`warning: ${message}\n`);
79
- /** Finishes whatever a killed run left half-done, and says so when plaintext was put back. */
80
- const recover = (section) => {
81
- if ((0, bundle_1.recoverSection)(section))
82
- warn(`restored ${section.name} after an interrupted run`);
83
- };
84
- const STALE_BUNDLE = {
85
- 'bundle changed': 'its bundle has changed since this machine last decrypted it',
86
- conflict: 'its bundle has changed since this machine last decrypted it',
87
- unknown: 'this machine has never decrypted its bundle, so it may hold changes you do not have',
88
- 'not downloaded': 'its bundle is a Git LFS pointer (run `git lfs pull` first)',
89
- 'bundle unreadable': 'its bundle cannot be read (restore it from git first)',
90
- };
91
- const encryptSectionCommand = async (argv) => {
92
- if ((0, dispatch_1.wantsHelp)(argv, exports.encryptSectionUsage))
93
- return;
94
- const { first: name, newArgv } = (0, dispatch_1.takeFirst)(argv);
95
- if (!name || newArgv._.length) {
96
- throw new errors_1.CliError('name one section: dcrypt encrypt-section <name>');
97
- }
98
- const workspace = (0, layout_1.findWorkspace)(newArgv);
99
- const section = (0, layout_1.resolveSection)(workspace, name);
100
- const recipients = (0, recipients_1.readWorkspaceRecipients)(workspace);
101
- recover(section);
102
- const report = await (0, status_1.inspectSection)(section, (0, state_1.readState)(workspace)[section.name], recipients.map((entry) => (0, recipients_1.fingerprintOf)(entry.recipient)));
103
- const { snapshot } = report;
104
- if (report.state === 'plaintext unreadable')
105
- throw new errors_1.CliError((0, status_1.adviceFor)(report));
106
- if (!snapshot)
107
- throw new errors_1.CliError(`there is no folder ${section.directory} to encrypt`, errors_1.EXIT.notFound);
108
- if (!snapshot.files.length)
109
- throw new errors_1.CliError(`${section.directory} has no files to encrypt`);
110
- const bundle = (0, path_1.relative)(workspace.root, section.bundle);
111
- const summary = { section: section.name, bundle, files: snapshot.files.length, recipients: recipients.length };
112
- if (report.state === 'in sync' && !(0, status_1.recipientsDiffer)(report)) {
113
- (0, io_1.emit)(newArgv, { ...summary, changed: false }, () => `${section.name}: unchanged, ${bundle} is up to date`);
114
- return;
115
- }
116
- const stale = STALE_BUNDLE[report.state];
117
- if (stale && !newArgv.force) {
118
- throw new errors_1.CliError(`${section.name} was not encrypted: ${stale}. Run \`dcrypt decrypt-workspace\`, or pass --force to replace the bundle with what is on this machine.`);
119
- }
120
- const sha256 = await (0, bundle_1.encryptSection)(section, snapshot, recipients.map((entry) => entry.recipient));
121
- await (0, state_1.recordSection)(workspace, section.name, { digest: snapshot.digest, bundle: sha256 });
122
- (0, recipients_1.recipientWarnings)(recipients).forEach(warn);
123
- (0, io_1.emit)(newArgv, { ...summary, changed: true }, () => `${section.name}: encrypted ${(0, text_1.count)(summary.files, 'file')} to ${(0, text_1.count)(summary.recipients, 'recipient')} → ${bundle}`);
124
- };
125
- exports.encryptSectionCommand = encryptSectionCommand;
126
- /** One outcome per section. The first failure decides the command's exit code. */
127
- class Outcomes {
128
- bySection = new Map();
129
- exitCode = 0;
130
- record(section, result, detail = '') {
131
- this.bySection.set(section.name, { section: section.name, result, detail });
132
- }
133
- fail(section, detail, code = errors_1.EXIT.usage) {
134
- this.exitCode ||= code;
135
- this.record(section, 'failed', detail);
136
- }
137
- inOrder(sections) {
138
- return sections.map((section) => this.bySection.get(section.name));
139
- }
140
- }
141
- const FORCE_HINT = 'pass --force to take the bundle, or `dcrypt encrypt-section --force` to keep what is here';
142
- /**
143
- * Settles, without a key, every section that can be settled that way. Returns what a section
144
- * still needs when it needs its bundle decrypted, and undefined when it is done.
145
- */
146
- const settle = (report, force, outcomes) => {
147
- const { section } = report;
148
- const replace = { report, compareOnly: false };
149
- switch (report.state) {
150
- case 'in sync':
151
- return void outcomes.record(section, 'unchanged', 'in sync');
152
- case 'not decrypted':
153
- case 'bundle changed':
154
- return replace;
155
- case 'plaintext changed':
156
- return force ? replace : void outcomes.record(section, 'kept', 'it has changes that are not encrypted yet');
157
- case 'unknown':
158
- return force ? replace : { report, compareOnly: true };
159
- case 'conflict':
160
- return force
161
- ? replace
162
- : void outcomes.fail(section, `the plaintext and the bundle have both changed; ${FORCE_HINT}`);
163
- case 'bundle unreadable':
164
- return void outcomes.fail(section, (0, status_1.adviceFor)(report), errors_1.EXIT.corrupt);
165
- case 'plaintext unreadable':
166
- return void outcomes.fail(section, (0, status_1.adviceFor)(report));
167
- default:
168
- return void outcomes.fail(section, (0, status_1.adviceFor)(report), errors_1.EXIT.notFound);
169
- }
170
- };
171
- /** Keeps the sections this machine's identity can open. Public information: no passphrase yet. */
172
- const openableBy = (mine, pending, outcomes) => pending.filter(({ report }) => {
173
- const isRecipient = Boolean(report.bundle?.recipients.includes(mine));
174
- if (!isRecipient) {
175
- outcomes.fail(report.section, `this machine's identity (${mine}) is not one of its recipients`, errors_1.EXIT.permission);
176
- }
177
- return isRecipient;
178
- });
179
- /** Decrypts one section. Never throws: a failure is that section's outcome, not the command's. */
180
- const decryptSection = async (workspace, { report: { section, snapshot }, compareOnly }, identity, outcomes) => {
181
- try {
182
- const extraction = await (0, bundle_1.extractSection)(section, identity);
183
- const same = snapshot?.digest === extraction.digest;
184
- if (compareOnly && !same) {
185
- (0, temp_1.discardTemp)(extraction.directory);
186
- outcomes.fail(section, `it differs from its bundle, and this machine has no record of which is newer; ${FORCE_HINT}`);
187
- return;
188
- }
189
- // Plaintext that already is what the bundle holds is left alone: there is nothing to swap.
190
- if (same)
191
- (0, temp_1.discardTemp)(extraction.directory);
192
- else
193
- await (0, bundle_1.installExtraction)(section, extraction);
194
- await (0, state_1.recordSection)(workspace, section.name, { digest: extraction.digest, bundle: extraction.bundle });
195
- if (same)
196
- outcomes.record(section, 'unchanged', 'already matches its bundle');
197
- else
198
- outcomes.record(section, snapshot ? 'updated' : 'decrypted', (0, text_1.count)(extraction.manifest.files.length, 'file'));
199
- }
200
- catch (error) {
201
- outcomes.fail(section, (0, errors_1.messageFor)(error), (0, errors_1.exitCodeFor)(error));
202
- }
203
- };
204
- const decryptWorkspaceCommand = async (argv, prompter) => {
205
- if ((0, dispatch_1.wantsHelp)(argv, exports.decryptWorkspaceUsage))
206
- return;
207
- const workspace = (0, layout_1.findWorkspace)(argv);
208
- const sections = argv._.length
209
- ? argv._.map((name) => (0, layout_1.resolveSection)(workspace, String(name)))
210
- : (0, layout_1.discoverSections)(workspace);
211
- if (!sections.length) {
212
- (0, io_1.emit)(argv, { workspace: workspace.root, sections: [] }, () => `no sections in ${workspace.root}`);
213
- return;
214
- }
215
- const state = (0, state_1.readState)(workspace);
216
- const outcomes = new Outcomes();
217
- const pending = [];
218
- for (const section of sections) {
219
- recover(section);
220
- const report = await (0, status_1.inspectSection)(section, state[section.name]);
221
- const next = settle(report, Boolean(argv.force), outcomes);
222
- if (next)
223
- pending.push(next);
224
- }
225
- const openable = pending.length
226
- ? openableBy((0, recipients_1.fingerprintOf)((0, stash_1.readStoredIdentity)().recipient), pending, outcomes)
227
- : [];
228
- if (openable.length) {
229
- // The one prompt. A wrong passphrase fails here, before any bundle is opened.
230
- const identity = (0, stash_1.loadIdentity)(await (0, passphrase_1.resolvePassphrase)(argv, prompter, { message: 'Identity passphrase' }));
231
- try {
232
- for (const item of openable)
233
- await decryptSection(workspace, item, identity, outcomes);
234
- }
235
- finally {
236
- identity.privateKey.fill(0);
237
- }
238
- }
239
- const results = outcomes.inOrder(sections);
240
- const width = Math.max(...results.map((outcome) => outcome.section.length));
241
- (0, io_1.emit)(argv, { workspace: workspace.root, sections: results }, () => results
242
- .map(({ section, result, detail }) => `${section.padEnd(width)} ${result}${detail ? ` (${detail})` : ''}`)
243
- .join('\n'));
244
- const failures = results.filter((outcome) => outcome.result === 'failed').length;
245
- if (failures) {
246
- throw new errors_1.CliError(`${(0, text_1.count)(failures, 'section')} could not be decrypted; ${failures === 1 ? 'its' : 'their'} plaintext was not changed`, outcomes.exitCode);
247
- }
248
- };
249
- exports.decryptWorkspaceCommand = decryptWorkspaceCommand;
250
- const statusCommand = async (argv) => {
251
- if ((0, dispatch_1.wantsHelp)(argv, exports.statusUsage))
252
- return;
253
- const workspace = (0, layout_1.findWorkspace)(argv);
254
- const state = (0, state_1.readState)(workspace);
255
- const recipients = readRecipientFingerprints(workspace);
256
- const reports = [];
257
- for (const section of (0, layout_1.discoverSections)(workspace)) {
258
- reports.push(await (0, status_1.inspectSection)(section, state[section.name], recipients));
259
- }
260
- const sections = reports.map((report) => ({
261
- section: report.section.name,
262
- state: report.state,
263
- files: report.snapshot?.files.length,
264
- missingRecipients: report.missingRecipients,
265
- extraRecipients: report.extraRecipients,
266
- advice: (0, status_1.adviceFor)(report),
267
- }));
268
- const width = Math.max(0, ...sections.map(({ section }) => section.length));
269
- (0, io_1.emit)(argv, { workspace: workspace.root, sections }, () => sections.length
270
- ? sections
271
- .map(({ section, state: current, advice }) => `${section.padEnd(width)} ${current}${advice ? ` — ${advice}` : ''}`)
272
- .join('\n')
273
- : `no sections in ${workspace.root}`);
274
- };
275
- exports.statusCommand = statusCommand;
276
- /**
277
- * Fingerprints from recipients.txt, or undefined when there is none to compare against. One that
278
- * is there and cannot be used is worth a warning, and no reason to say nothing about the sections.
279
- */
280
- const readRecipientFingerprints = (workspace) => {
281
- try {
282
- return (0, recipients_1.readWorkspaceRecipients)(workspace).map((entry) => (0, recipients_1.fingerprintOf)(entry.recipient));
283
- }
284
- catch (error) {
285
- if ((0, errors_1.exitCodeFor)(error) !== errors_1.EXIT.notFound)
286
- warn((0, errors_1.messageFor)(error));
287
- return undefined;
288
- }
289
- };
package/commands.d.ts DELETED
@@ -1,8 +0,0 @@
1
- import { CommandHandler, Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- import { Handler } from './utils/dispatch';
4
- export declare const usageText = "\ndcrypt \u2014 local-first encryption, wallets and team secrets\n\nUsage:\n dcrypt <command> [subcommand] [OPTIONS]\n\nCommands:\n encrypt Encrypt data with a passphrase, or to X25519 recipients\n decrypt Decrypt data with a passphrase, or with your identity\n encrypt-section Encrypt one folder of a workspace into a single bundle\n decrypt-workspace Decrypt a workspace's bundles, with one passphrase prompt\n status Show which sections are in sync, changed or not decrypted\n doctor Check this machine and workspace; warn on a missing recovery key\n guard Keep plaintext out of git: pre-commit check, hook and snippets\n wallet Create BIP39 wallets and derive addresses (offline)\n keys Manage your X25519 identity\n secrets Team secrets files (.env generation, recipients, rekeying)\n vault The local encrypted vault, shared with the desktop app\n account Constructive accounts and API keys, stored in the vault\n passkey Passkeys held in the vault; dcrypt signs for the site\n keychain Store named secrets locally, always encrypted\n shamir Split and recombine a secret into authenticated shares\n salt Two-layer encryption: data under a salt, salt under your passphrase\n cosmology Read and upgrade data written by the cosmology CLI\n\nGlobal options:\n --json Machine-readable output where supported\n --in <file> / --out Read input from, and write output to, files (\"-\" is stdin)\n --passphrase-file <p> Read the passphrase from a file\n --passphrase-stdin Read the passphrase from stdin\n --version, -v Print the version\n --help, -h Show this help; \"dcrypt <command> --help\" for a command\n\nOnly \"dcrypt account\" reaches the network, and only the endpoint you name.\nPassphrases and passwords are never accepted in argv.\n\nEnvironment:\n MNEMONIC A BIP39 mnemonic, for wallet commands\n SALT The salt, for salt and cosmology commands\n ENCRYPTED_SALT The encrypted salt, for the two-layer scheme\n KEYCHAIN_ACCOUNT Keychain namespace (default: dcrypt)\n DCRYPT_PASSPHRASE The passphrase, for unattended runs\n DCRYPT_AUTH_ENDPOINT Constructive auth endpoint, for account commands\n DCRYPT_ACCOUNT_PASSWORD The account password, for unattended sign-in\n\n Each also accepts a DCRYPT_-prefixed alias (DCRYPT_MNEMONIC, DCRYPT_SALT, ...).\n Flags take precedence over the environment, which takes precedence over stdin.\n\nExit codes:\n 1 usage 2 wrong passphrase 3 corrupt input 4 not found 5 not a recipient\n";
5
- export declare const createCommandMap: () => Record<string, Handler>;
6
- /** Runs one command and maps thrown errors onto exit codes; used by the bin and by tests. */
7
- export declare const dispatch: (argv: ParsedArgs, prompter: Inquirerer) => Promise<number>;
8
- export declare const commands: CommandHandler;
package/commands.js DELETED
@@ -1,126 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.commands = exports.dispatch = exports.createCommandMap = exports.usageText = void 0;
4
- const inquirerer_1 = require("inquirerer");
5
- const account_1 = require("./commands/account");
6
- const cosmology_1 = require("./commands/cosmology");
7
- const doctor_1 = require("./commands/doctor");
8
- const encrypt_1 = require("./commands/encrypt");
9
- const guard_1 = require("./commands/guard");
10
- const keychain_1 = require("./commands/keychain");
11
- const keys_1 = require("./commands/keys");
12
- const passkey_1 = require("./commands/passkey");
13
- const salt_1 = require("./commands/salt");
14
- const secrets_1 = require("./commands/secrets");
15
- const shamir_1 = require("./commands/shamir");
16
- const vault_1 = require("./commands/vault");
17
- const wallet_1 = require("./commands/wallet");
18
- const workspace_1 = require("./commands/workspace");
19
- const dispatch_1 = require("./utils/dispatch");
20
- const env_1 = require("./utils/env");
21
- const errors_1 = require("./utils/errors");
22
- exports.usageText = `
23
- dcrypt — local-first encryption, wallets and team secrets
24
-
25
- Usage:
26
- dcrypt <command> [subcommand] [OPTIONS]
27
-
28
- Commands:
29
- encrypt Encrypt data with a passphrase, or to X25519 recipients
30
- decrypt Decrypt data with a passphrase, or with your identity
31
- encrypt-section Encrypt one folder of a workspace into a single bundle
32
- decrypt-workspace Decrypt a workspace's bundles, with one passphrase prompt
33
- status Show which sections are in sync, changed or not decrypted
34
- doctor Check this machine and workspace; warn on a missing recovery key
35
- guard Keep plaintext out of git: pre-commit check, hook and snippets
36
- wallet Create BIP39 wallets and derive addresses (offline)
37
- keys Manage your X25519 identity
38
- secrets Team secrets files (.env generation, recipients, rekeying)
39
- vault The local encrypted vault, shared with the desktop app
40
- account Constructive accounts and API keys, stored in the vault
41
- passkey Passkeys held in the vault; dcrypt signs for the site
42
- keychain Store named secrets locally, always encrypted
43
- shamir Split and recombine a secret into authenticated shares
44
- salt Two-layer encryption: data under a salt, salt under your passphrase
45
- cosmology Read and upgrade data written by the cosmology CLI
46
-
47
- Global options:
48
- --json Machine-readable output where supported
49
- --in <file> / --out Read input from, and write output to, files ("-" is stdin)
50
- --passphrase-file <p> Read the passphrase from a file
51
- --passphrase-stdin Read the passphrase from stdin
52
- --version, -v Print the version
53
- --help, -h Show this help; "dcrypt <command> --help" for a command
54
-
55
- Only "dcrypt account" reaches the network, and only the endpoint you name.
56
- Passphrases and passwords are never accepted in argv.
57
- ${env_1.envUsage}
58
- Exit codes:
59
- 1 usage 2 wrong passphrase 3 corrupt input 4 not found 5 not a recipient
60
- `;
61
- const createCommandMap = () => ({
62
- encrypt: encrypt_1.encryptCommand,
63
- decrypt: encrypt_1.decryptCommand,
64
- 'encrypt-section': workspace_1.encryptSectionCommand,
65
- 'decrypt-workspace': workspace_1.decryptWorkspaceCommand,
66
- status: workspace_1.statusCommand,
67
- doctor: doctor_1.doctorCommand,
68
- guard: guard_1.guardCommand,
69
- wallet: wallet_1.walletCommand,
70
- keys: keys_1.keysCommand,
71
- secrets: secrets_1.secretsCommand,
72
- vault: vault_1.vaultCommand,
73
- account: account_1.accountCommand,
74
- passkey: passkey_1.passkeyCommand,
75
- keychain: keychain_1.keychainCommand,
76
- shamir: shamir_1.shamirCommand,
77
- salt: salt_1.saltCommand,
78
- cosmology: cosmology_1.cosmologyCommand,
79
- });
80
- exports.createCommandMap = createCommandMap;
81
- /** Runs one command and maps thrown errors onto exit codes; used by the bin and by tests. */
82
- const dispatch = async (argv, prompter) => {
83
- const commandMap = (0, exports.createCommandMap)();
84
- let { first: command, newArgv } = (0, dispatch_1.takeFirst)(argv);
85
- if (command === 'help' || (!command && (argv.help || argv.h))) {
86
- process.stdout.write(exports.usageText);
87
- return 0;
88
- }
89
- if (!command) {
90
- const answer = await prompter.prompt(newArgv, [
91
- {
92
- type: 'autocomplete',
93
- name: 'command',
94
- message: 'What do you want to do?',
95
- options: Object.keys(commandMap),
96
- },
97
- ]);
98
- command = answer.command;
99
- }
100
- const handler = commandMap[command];
101
- if (!handler) {
102
- process.stdout.write(exports.usageText);
103
- process.stderr.write(`Error: unknown command: ${command}\n`);
104
- return 1;
105
- }
106
- try {
107
- await handler(newArgv, prompter);
108
- return 0;
109
- }
110
- catch (error) {
111
- process.stderr.write(`Error: ${(0, errors_1.messageFor)(error)}\n`);
112
- return (0, errors_1.exitCodeFor)(error);
113
- }
114
- };
115
- exports.dispatch = dispatch;
116
- const commands = async (argv, prompter, _options) => {
117
- if (argv.version || argv.v) {
118
- process.stdout.write(`${(0, inquirerer_1.getPackageJson)(__dirname).version}\n`);
119
- return;
120
- }
121
- const code = await (0, exports.dispatch)(argv, prompter);
122
- prompter.close();
123
- if (code !== 0)
124
- process.exit(code);
125
- };
126
- exports.commands = commands;