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.
Files changed (117) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -325
  3. package/index.js +3 -66
  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,470 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.accountCommand = exports.accountUsage = void 0;
4
- const accounts_1 = require("@decryption/accounts");
5
- const fs_1 = require("fs");
6
- const dispatch_1 = require("../utils/dispatch");
7
- const env_1 = require("../utils/env");
8
- const errors_1 = require("../utils/errors");
9
- const io_1 = require("../utils/io");
10
- const vault_1 = require("./vault");
11
- exports.accountUsage = `
12
- Account Command:
13
-
14
- dcrypt account <subcommand> [OPTIONS]
15
-
16
- Constructive accounts and their API keys, held in the local vault. This is the
17
- one part of dcrypt that talks to a server: the endpoint you name, nothing else.
18
-
19
- Subcommands:
20
- list List the accounts in the vault
21
- signup <email> Create an account on --endpoint, then store the session
22
- signin <email> Sign in and store the session
23
- signout <email> Sign out and drop the stored token
24
- forget <email> Remove the account and its keys from the vault
25
- link-code <email> <code> Answer this account's MFA step-ups with a vault code
26
- unlink-code <email> Stop answering its step-ups from the vault
27
- key list [email] List stored API keys
28
- key create <name> Mint an API key for --account
29
- key reveal <name> Print an API key secret
30
- key revoke <name> Revoke server-side, then delete the local copy
31
- key assign <name> <db> Serve this key as that database's data-plane token
32
- token [email] Print the bearer a harness would be given
33
- principal list [email] Scoped sub-identities, with their scopes and masks
34
- principal create <name> Create one — personal, or scoped to --org
35
- principal delete <id> Remove one server-side
36
-
37
- Options:
38
- --endpoint <url> Auth endpoint (or DCRYPT_AUTH_ENDPOINT)
39
- --account <email> Which account a key command applies to
40
- --expires-days <n> Lifetime for a new key (default: no expiry)
41
- --access-level <level> Access level for a new key
42
- --database <id> Tag a new key as that database's data-plane token
43
- --principal <id> Mint the key as this principal, not as you
44
- --org <id> Scope a principal to this org; omit for a personal one
45
- --read-only The principal may only read
46
- --bypass-step-up The principal may skip MFA step-up (for CI)
47
- --password-file <path> Read the account password from a file
48
- --password-stdin Read the account password from stdin
49
- --json Machine-readable output
50
- --passphrase-file <p> Read the master password from a file
51
- --help, -h Show this help message
52
-
53
- Examples:
54
- dcrypt account signin dev@example.com --endpoint http://auth.localhost:3000/graphql
55
- dcrypt account key create ci --account dev@example.com --expires-days 30
56
- dcrypt account link-code dev@example.com "Constructive dev"
57
- dcrypt account key reveal ci
58
- dcrypt account token dev@example.com
59
- dcrypt account principal create ci-deploy --org <org-id> --read-only
60
- dcrypt account key create ci --principal <principal-id> --org <org-id>
61
- `;
62
- /**
63
- * The account password, never from argv — it would be visible in `ps` to every
64
- * process on the machine, exactly like the master passphrase.
65
- */
66
- const resolveAccountPassword = async (argv, prompter, confirm) => {
67
- if (argv.password !== undefined) {
68
- throw new errors_1.CliError('refusing to read a password from argv (it is visible in `ps`); use --password-file <path> or --password-stdin');
69
- }
70
- const file = argv['password-file'] ?? argv.passwordFile;
71
- if (typeof file === 'string' && file.length) {
72
- try {
73
- return (0, fs_1.readFileSync)(file, 'utf8').replace(/\r?\n$/, '');
74
- }
75
- catch {
76
- throw new errors_1.CliError(`cannot read password file ${file}`, errors_1.EXIT.notFound);
77
- }
78
- }
79
- const fromEnvironment = (0, env_1.fromEnv)('accountPassword');
80
- if (fromEnvironment !== undefined)
81
- return fromEnvironment.replace(/\r?\n$/, '');
82
- if (argv['password-stdin'] || argv.passwordStdin) {
83
- return (0, io_1.readStdin)().replace(/\r?\n$/, '');
84
- }
85
- const { accountPassword } = await prompter.prompt({}, [
86
- {
87
- type: 'password',
88
- name: 'accountPassword',
89
- message: 'Account password',
90
- required: true,
91
- },
92
- ]);
93
- if (!accountPassword)
94
- throw new errors_1.CliError('an account password is required');
95
- if (confirm) {
96
- const { confirmation } = await prompter.prompt({}, [
97
- {
98
- type: 'password',
99
- name: 'confirmation',
100
- message: 'Confirm account password',
101
- required: true,
102
- },
103
- ]);
104
- if (confirmation !== accountPassword) {
105
- throw new errors_1.CliError('the passwords do not match');
106
- }
107
- }
108
- return accountPassword;
109
- };
110
- const resolveEndpoint = (argv) => {
111
- const endpoint = typeof argv.endpoint === 'string' ? argv.endpoint : (0, env_1.fromEnv)('authEndpoint');
112
- if (!endpoint) {
113
- throw new errors_1.CliError('an --endpoint is required (or set DCRYPT_AUTH_ENDPOINT)');
114
- }
115
- return endpoint;
116
- };
117
- const withVault = async (argv, prompter, run) => {
118
- const vault = await (0, vault_1.openVault)(argv, prompter);
119
- try {
120
- await run(new accounts_1.AccountManager(vault), vault);
121
- }
122
- finally {
123
- await vault.lock();
124
- }
125
- };
126
- const findAccount = async (accounts, ref) => {
127
- const all = await accounts.listAccounts();
128
- const match = all.find((account) => account.itemId === ref) ??
129
- all.find((account) => account.email === ref) ??
130
- all.find((account) => account.email.toLowerCase() === ref.toLowerCase());
131
- if (!match)
132
- throw new errors_1.CliError(`no account "${ref}" in the vault`, errors_1.EXIT.notFound);
133
- return match;
134
- };
135
- /**
136
- * The account a command applies to: the one named, or the only one there is.
137
- * Never a guess when the vault holds several.
138
- */
139
- const resolveAccount = async (accounts, ref) => {
140
- if (ref)
141
- return findAccount(accounts, ref);
142
- const all = await accounts.listAccounts();
143
- if (all.length === 0) {
144
- throw new errors_1.CliError('no account in the vault — sign in first', errors_1.EXIT.notFound);
145
- }
146
- if (all.length > 1) {
147
- throw new errors_1.CliError('name an account: the vault holds more than one');
148
- }
149
- return all[0];
150
- };
151
- const findKey = async (accounts, ref) => {
152
- const all = await accounts.listApiKeys();
153
- const match = all.find((key) => key.itemId === ref) ??
154
- all.find((key) => key.keyId === ref) ??
155
- all.find((key) => key.name === ref);
156
- if (!match)
157
- throw new errors_1.CliError(`no API key "${ref}" in the vault`, errors_1.EXIT.notFound);
158
- return match;
159
- };
160
- const describe = (account) => `${account.signedIn ? 'signed in ' : 'signed out'} ${account.email.padEnd(28)} ${account.endpoint}`;
161
- const list = async (argv, prompter) => withVault(argv, prompter, async (accounts) => {
162
- const all = await accounts.listAccounts();
163
- (0, io_1.emit)(argv, all, () => all.map(describe).join('\n') || '(no accounts)');
164
- });
165
- const authenticate = async (argv, prompter, mode) => {
166
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
167
- if (!first)
168
- throw new errors_1.CliError('an email address is required');
169
- const endpoint = resolveEndpoint(newArgv);
170
- const password = await resolveAccountPassword(newArgv, prompter, mode === 'signUp');
171
- await withVault(newArgv, prompter, async (accounts) => {
172
- const account = await accounts[mode]({ endpoint, email: first, password });
173
- (0, io_1.emit)(newArgv, account, () => `${mode === 'signUp' ? 'created' : 'signed in as'} ${account.email} (${account.userId})`);
174
- });
175
- };
176
- const signup = async (argv, prompter) => authenticate(argv, prompter, 'signUp');
177
- const signin = async (argv, prompter) => authenticate(argv, prompter, 'signIn');
178
- const signout = async (argv, prompter) => {
179
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
180
- if (!first)
181
- throw new errors_1.CliError('an account is required');
182
- await withVault(newArgv, prompter, async (accounts) => {
183
- const account = await findAccount(accounts, first);
184
- await accounts.signOut(account.itemId);
185
- (0, io_1.emit)(newArgv, { itemId: account.itemId }, () => `signed out ${account.email}`);
186
- });
187
- };
188
- const forget = async (argv, prompter) => {
189
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
190
- if (!first)
191
- throw new errors_1.CliError('an account is required');
192
- await withVault(newArgv, prompter, async (accounts) => {
193
- const account = await findAccount(accounts, first);
194
- await accounts.forget(account.itemId);
195
- (0, io_1.emit)(newArgv, { itemId: account.itemId }, () => `removed ${account.email} and its keys from the vault`);
196
- });
197
- };
198
- /**
199
- * Point an account at a one-time code already in the vault, so the server's
200
- * MFA step-up is answered without a human reaching for a phone.
201
- */
202
- const linkCode = async (argv, prompter) => {
203
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
204
- const { first: codeRef, newArgv: rest } = (0, dispatch_1.takeFirst)(newArgv);
205
- if (!first)
206
- throw new errors_1.CliError('an account is required');
207
- if (!codeRef)
208
- throw new errors_1.CliError('a one-time code item is required');
209
- await withVault(rest, prompter, async (accounts, vault) => {
210
- const account = await findAccount(accounts, first);
211
- const codes = await vault.listItems({ kind: 'totp' });
212
- const code = codes.find((item) => item.id === codeRef) ??
213
- codes.find((item) => item.title === codeRef) ??
214
- codes.find((item) => item.title.toLowerCase() === codeRef.toLowerCase());
215
- if (!code) {
216
- throw new errors_1.CliError(`no one-time code "${codeRef}" in the vault`, errors_1.EXIT.notFound);
217
- }
218
- await accounts.linkTotp(account.itemId, code.id);
219
- (0, io_1.emit)(rest, { itemId: account.itemId, totpItemId: code.id }, () => `"${code.title}" will answer MFA for ${account.email}`);
220
- });
221
- };
222
- const unlinkCode = async (argv, prompter) => {
223
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
224
- if (!first)
225
- throw new errors_1.CliError('an account is required');
226
- await withVault(newArgv, prompter, async (accounts) => {
227
- const account = await findAccount(accounts, first);
228
- await accounts.unlinkTotp(account.itemId);
229
- (0, io_1.emit)(newArgv, { itemId: account.itemId }, () => `${account.email} will ask for a code again`);
230
- });
231
- };
232
- const keyList = async (argv, prompter) => {
233
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
234
- await withVault(newArgv, prompter, async (accounts) => {
235
- const accountItemId = first
236
- ? (await findAccount(accounts, first)).itemId
237
- : undefined;
238
- const keys = await accounts.listApiKeys(accountItemId);
239
- (0, io_1.emit)(newArgv, keys, () => keys
240
- .map((key) => `${key.name.padEnd(24)} ${key.keyId} ${key.expiresAt ?? 'no expiry'}`)
241
- .join('\n') || '(no API keys)');
242
- });
243
- };
244
- /**
245
- * Run something the server may refuse until a factor is re-proved: ask for the
246
- * factor it named, then run the identical call once more. Not a blanket retry —
247
- * only a `StepUpRequiredError` reaches here, and only one extra attempt is made.
248
- */
249
- const withStepUp = async (prompter, run) => {
250
- try {
251
- return await run();
252
- }
253
- catch (error) {
254
- if (!(error instanceof accounts_1.StepUpRequiredError))
255
- throw error;
256
- const mfa = error.kind === 'mfa';
257
- const { proof } = await prompter.prompt({}, [
258
- {
259
- type: mfa ? 'text' : 'password',
260
- name: 'proof',
261
- message: mfa
262
- ? 'The server wants a fresh one-time code'
263
- : 'The server wants your account password again',
264
- required: true,
265
- },
266
- ]);
267
- if (!proof)
268
- throw error;
269
- return run(mfa ? { totpCode: proof } : { password: proof });
270
- }
271
- };
272
- const text = (value) => typeof value === 'string' && value.length ? value : undefined;
273
- const lifetime = (argv) => {
274
- const raw = argv['expires-days'] ?? argv.expiresDays;
275
- if (raw === undefined)
276
- return undefined;
277
- const days = Number(raw);
278
- if (!Number.isInteger(days) || days <= 0) {
279
- throw new errors_1.CliError('--expires-days must be a positive whole number of days');
280
- }
281
- return { days };
282
- };
283
- const keyCreate = async (argv, prompter) => {
284
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
285
- if (!first)
286
- throw new errors_1.CliError('a key name is required');
287
- const accessLevel = newArgv['access-level'] ?? newArgv.accessLevel;
288
- await withVault(newArgv, prompter, async (accounts) => {
289
- const all = await accounts.listAccounts();
290
- const ref = typeof newArgv.account === 'string' ? newArgv.account : undefined;
291
- if (!ref && all.length === 0) {
292
- throw new errors_1.CliError('no account in the vault — sign in first');
293
- }
294
- if (!ref && all.length > 1) {
295
- throw new errors_1.CliError('--account is required when the vault holds more than one account');
296
- }
297
- const account = ref ? await findAccount(accounts, ref) : all[0];
298
- const request = {
299
- name: first,
300
- expiresIn: lifetime(newArgv),
301
- accessLevel: typeof accessLevel === 'string' ? accessLevel : undefined,
302
- databaseId: text(newArgv.database),
303
- principalId: text(newArgv.principal),
304
- orgId: text(newArgv.org),
305
- };
306
- const key = await withStepUp(prompter, (proof) => accounts.createApiKey(account.itemId, request, proof));
307
- (0, io_1.emit)(newArgv, key, () => `created "${key.name}" (${key.keyId}) — stored in the vault; read it with "dcrypt account key reveal ${key.name}"`);
308
- });
309
- };
310
- const keyReveal = async (argv, prompter) => {
311
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
312
- if (!first)
313
- throw new errors_1.CliError('a key name is required');
314
- await withVault(newArgv, prompter, async (accounts) => {
315
- const key = await findKey(accounts, first);
316
- const secret = await accounts.revealApiKey(key.itemId);
317
- (0, io_1.emit)(newArgv, { apiKey: secret }, () => secret);
318
- });
319
- };
320
- const keyRevoke = async (argv, prompter) => {
321
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
322
- if (!first)
323
- throw new errors_1.CliError('a key name is required');
324
- await withVault(newArgv, prompter, async (accounts) => {
325
- const key = await findKey(accounts, first);
326
- await withStepUp(prompter, (proof) => accounts.revokeApiKey(key.itemId, proof));
327
- (0, io_1.emit)(newArgv, { keyId: key.keyId }, () => `revoked "${key.name}" (${key.keyId})`);
328
- });
329
- };
330
- /**
331
- * Say that an existing key is a database's data-plane token, which is what a
332
- * harness host asks for by database id.
333
- */
334
- const keyAssign = async (argv, prompter) => {
335
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
336
- const { first: databaseId, newArgv: rest } = (0, dispatch_1.takeFirst)(newArgv);
337
- if (!first)
338
- throw new errors_1.CliError('a key name is required');
339
- if (!databaseId)
340
- throw new errors_1.CliError('a database id is required');
341
- await withVault(rest, prompter, async (accounts) => {
342
- const key = await findKey(accounts, first);
343
- await accounts.assignKeyToDatabase(key.itemId, databaseId);
344
- (0, io_1.emit)(rest, { itemId: key.itemId, databaseId }, () => `"${key.name}" is now the data-plane token for ${databaseId}`);
345
- });
346
- };
347
- /**
348
- * The bearer a harness host would be handed. Printing a live token is the
349
- * point of the command, so it goes to stdout alone and nowhere else — but the
350
- * vault stays the only place it is stored.
351
- */
352
- const token = async (argv, prompter) => {
353
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
354
- const databaseRef = newArgv.database;
355
- await withVault(newArgv, prompter, async (accounts) => {
356
- const accountItemId = first
357
- ? (await findAccount(accounts, first)).itemId
358
- : undefined;
359
- const credentials = new accounts_1.VaultCredentials(accounts, { accountItemId });
360
- if (typeof databaseRef === 'string' && databaseRef.length) {
361
- const result = await credentials.dataToken(databaseRef);
362
- if (!result.token) {
363
- throw new errors_1.CliError(`no key in the vault is the data-plane token for ${databaseRef} — tag one with "dcrypt account key assign <name> ${databaseRef}"`, errors_1.EXIT.notFound);
364
- }
365
- (0, io_1.emit)(newArgv, result, () => result.token);
366
- return;
367
- }
368
- const bearer = await credentials.accountBearer();
369
- if (!bearer) {
370
- throw new errors_1.CliError(first
371
- ? `${first} is signed out — sign in again first`
372
- : 'name an account: a bearer is only served when exactly one account is signed in', errors_1.EXIT.notFound);
373
- }
374
- (0, io_1.emit)(newArgv, { accountBearer: bearer }, () => bearer);
375
- });
376
- };
377
- /**
378
- * A principal's reach: the entities it touches, and the per-scope overrides
379
- * that narrow it. No override row means it simply inherits its owner there,
380
- * which is worth saying out loud rather than rendering an empty list.
381
- */
382
- const describePrincipal = (principal) => {
383
- const flags = [
384
- principal.isReadOnly ? 'read-only' : null,
385
- principal.bypassStepUp ? 'skips step-up' : null,
386
- principal.useAdminOwner ? "inherits owner's admin" : null,
387
- ].filter(Boolean);
388
- const scopes = principal.scopes.length
389
- ? principal.scopes
390
- .map((scope) => ` scope ${scope.membershipType}: ${scope.isActive ? 'active' : 'disabled'}${scope.isReadOnly ? ', read-only' : ''}, mask ${scope.allowedMask ?? 'inherited'}`)
391
- .join('\n')
392
- : ' (no overrides — inherits the owner everywhere it is scoped)';
393
- return [
394
- `${principal.name.padEnd(24)} ${principal.principalId}`,
395
- ` ${flags.join(', ') || 'no flags'}`,
396
- ` entities: ${principal.entityIds.join(', ') || '(none)'}`,
397
- scopes,
398
- ].join('\n');
399
- };
400
- const principalList = async (argv, prompter) => {
401
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
402
- await withVault(newArgv, prompter, async (accounts) => {
403
- const account = await resolveAccount(accounts, first);
404
- const principals = await accounts.listPrincipals(account.itemId);
405
- (0, io_1.emit)(newArgv, principals, () => principals.map(describePrincipal).join('\n\n') || '(no principals)');
406
- });
407
- };
408
- const principalCreate = async (argv, prompter) => {
409
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
410
- if (!first)
411
- throw new errors_1.CliError('a principal name is required');
412
- const orgId = text(newArgv.org);
413
- await withVault(newArgv, prompter, async (accounts) => {
414
- const account = await resolveAccount(accounts, text(newArgv.account));
415
- const principalId = await withStepUp(prompter, (proof) => accounts.createPrincipal(account.itemId, {
416
- name: first,
417
- orgId,
418
- isReadOnly: Boolean(newArgv['read-only'] ?? newArgv.readOnly),
419
- bypassStepUp: Boolean(newArgv['bypass-step-up'] ?? newArgv.bypassStepUp),
420
- }, proof));
421
- (0, io_1.emit)(newArgv, { principalId }, () => `created "${first}" (${principalId}) — mint keys as it with --principal ${principalId}`);
422
- });
423
- };
424
- const principalDelete = async (argv, prompter) => {
425
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
426
- if (!first)
427
- throw new errors_1.CliError('a principal id is required');
428
- await withVault(newArgv, prompter, async (accounts) => {
429
- const account = await resolveAccount(accounts, text(newArgv.account));
430
- await withStepUp(prompter, (proof) => accounts.deletePrincipal(account.itemId, first, proof));
431
- (0, io_1.emit)(newArgv, { principalId: first }, () => `removed ${first}`);
432
- });
433
- };
434
- const principalCommand = async (argv, prompter) => (0, dispatch_1.runSubcommand)(argv, prompter, {
435
- name: 'account principal',
436
- usage: exports.accountUsage,
437
- handlers: {
438
- list: principalList,
439
- create: principalCreate,
440
- delete: principalDelete,
441
- },
442
- });
443
- const keyCommand = async (argv, prompter) => (0, dispatch_1.runSubcommand)(argv, prompter, {
444
- name: 'account key',
445
- usage: exports.accountUsage,
446
- handlers: {
447
- list: keyList,
448
- create: keyCreate,
449
- reveal: keyReveal,
450
- revoke: keyRevoke,
451
- assign: keyAssign,
452
- },
453
- });
454
- const accountCommand = async (argv, prompter) => (0, dispatch_1.runSubcommand)(argv, prompter, {
455
- name: 'account',
456
- usage: exports.accountUsage,
457
- handlers: {
458
- list,
459
- signup,
460
- signin,
461
- signout,
462
- forget,
463
- 'link-code': linkCode,
464
- 'unlink-code': unlinkCode,
465
- key: keyCommand,
466
- principal: principalCommand,
467
- token,
468
- },
469
- });
470
- exports.accountCommand = accountCommand;
@@ -1,4 +0,0 @@
1
- import { Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- export declare const cosmologyUsage = "\nCosmology Command:\n\n dcrypt cosmology <subcommand> [OPTIONS]\n\n Read and write data in the cosmology CLI's format (CryptoJS AES). That format\n is unauthenticated and derives its key with a single round of MD5 \u2014 prefer\n \"dcrypt encrypt\" for anything new, and use \"upgrade\" to migrate old data.\n\nSubcommands:\n decrypt Decrypt an old blob and print the plaintext\n encrypt Encrypt in the old format, for tools that still read it\n upgrade Decrypt an old blob and re-encrypt it with a new passphrase\n\nOptions:\n --in <file> Read the ciphertext from a file (\"-\" for stdin)\n --out <file> Write output to a file\n --salt-file <file> Read the old salt from a file (avoids putting it in argv)\n --encrypted-salt <s> The two-layer scheme's encrypted salt\n --passphrase-file <p> New passphrase, for \"upgrade\"\n --passphrase-stdin Read the new passphrase from stdin\n --help, -h Show this help message\n\nEnvironment:\n SALT, ENCRYPTED_SALT The cosmology CLI's own variables, still honoured\n\nExamples:\n dcrypt cosmology decrypt --in old.txt --salt-file salt.txt\n SALT=... dcrypt cosmology decrypt --in old.txt\n dcrypt cosmology encrypt --in plain.txt --salt-file salt.txt --out old.txt\n dcrypt cosmology upgrade --in old.txt --salt-file salt.txt --out new.dcrypt\n";
4
- export declare const cosmologyCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cosmologyCommand = exports.cosmologyUsage = void 0;
4
- const core_1 = require("@decryption/core");
5
- const cosmology_compat_1 = require("@decryption/cosmology-compat");
6
- const dispatch_1 = require("../utils/dispatch");
7
- const env_1 = require("../utils/env");
8
- const errors_1 = require("../utils/errors");
9
- const io_1 = require("../utils/io");
10
- const passphrase_1 = require("../utils/passphrase");
11
- const encrypt_1 = require("./encrypt");
12
- exports.cosmologyUsage = `
13
- Cosmology Command:
14
-
15
- dcrypt cosmology <subcommand> [OPTIONS]
16
-
17
- Read and write data in the cosmology CLI's format (CryptoJS AES). That format
18
- is unauthenticated and derives its key with a single round of MD5 — prefer
19
- "dcrypt encrypt" for anything new, and use "upgrade" to migrate old data.
20
-
21
- Subcommands:
22
- decrypt Decrypt an old blob and print the plaintext
23
- encrypt Encrypt in the old format, for tools that still read it
24
- upgrade Decrypt an old blob and re-encrypt it with a new passphrase
25
-
26
- Options:
27
- --in <file> Read the ciphertext from a file ("-" for stdin)
28
- --out <file> Write output to a file
29
- --salt-file <file> Read the old salt from a file (avoids putting it in argv)
30
- --encrypted-salt <s> The two-layer scheme's encrypted salt
31
- --passphrase-file <p> New passphrase, for "upgrade"
32
- --passphrase-stdin Read the new passphrase from stdin
33
- --help, -h Show this help message
34
-
35
- Environment:
36
- SALT, ENCRYPTED_SALT The cosmology CLI's own variables, still honoured
37
-
38
- Examples:
39
- dcrypt cosmology decrypt --in old.txt --salt-file salt.txt
40
- SALT=... dcrypt cosmology decrypt --in old.txt
41
- dcrypt cosmology encrypt --in plain.txt --salt-file salt.txt --out old.txt
42
- dcrypt cosmology upgrade --in old.txt --salt-file salt.txt --out new.dcrypt
43
- `;
44
- const readSalt = async (argv, prompter) => {
45
- const file = argv['salt-file'] ?? argv.saltFile;
46
- if (typeof file === 'string' && file.length) {
47
- return (0, io_1.readInput)({ ...argv, in: file }).trim();
48
- }
49
- if (argv.salt !== undefined) {
50
- throw new errors_1.CliError('refusing to read the old salt from argv (it is visible in `ps`); use --salt-file <path> or SALT');
51
- }
52
- const envSalt = (0, env_1.fromEnv)('salt');
53
- if (envSalt !== undefined)
54
- return envSalt.trim();
55
- const { salt } = await prompter.prompt({}, [
56
- { type: 'password', name: 'salt', message: 'Legacy salt', required: true },
57
- ]);
58
- return String(salt);
59
- };
60
- const readLegacyPlaintext = async (argv, prompter) => {
61
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
62
- const ciphertext = (0, io_1.readInput)(newArgv, first).trim();
63
- const salt = await readSalt(newArgv, prompter);
64
- const encryptedSalt = newArgv['encrypted-salt'] ?? newArgv.encryptedSalt ?? (0, env_1.fromEnv)('encryptedSalt');
65
- return typeof encryptedSalt === 'string' && encryptedSalt.length
66
- ? (0, cosmology_compat_1.decryptWithEncryptedSalt)(salt, encryptedSalt, ciphertext)
67
- : (0, cosmology_compat_1.decrypt)(salt, ciphertext);
68
- };
69
- const decryptCmd = async (argv, prompter) => {
70
- (0, io_1.writeOutput)(argv, await readLegacyPlaintext(argv, prompter));
71
- };
72
- const encryptCmd = async (argv, prompter) => {
73
- const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
74
- const plaintext = (0, io_1.readInput)(newArgv, first);
75
- const salt = await readSalt(newArgv, prompter);
76
- const encryptedSalt = newArgv['encrypted-salt'] ?? newArgv.encryptedSalt ?? (0, env_1.fromEnv)('encryptedSalt');
77
- const ciphertext = typeof encryptedSalt === 'string' && encryptedSalt.length
78
- ? (0, cosmology_compat_1.encryptWithEncryptedSalt)(salt, encryptedSalt, plaintext)
79
- : (0, cosmology_compat_1.crypt)(salt, plaintext);
80
- (0, io_1.writeOutput)(newArgv, ciphertext);
81
- };
82
- const upgrade = async (argv, prompter) => {
83
- const plaintext = await readLegacyPlaintext(argv, prompter);
84
- const passphrase = await (0, passphrase_1.resolvePassphrase)(argv, prompter, {
85
- confirm: true,
86
- message: 'New passphrase',
87
- });
88
- (0, io_1.writeOutput)(argv, (0, core_1.armor)((0, core_1.encrypt)(plaintext, passphrase, { kdf: (0, encrypt_1.resolveKdf)(argv.kdf) })));
89
- };
90
- const cosmologyCommand = async (argv, prompter) => {
91
- await (0, dispatch_1.runSubcommand)(argv, prompter, {
92
- name: 'cosmology',
93
- usage: exports.cosmologyUsage,
94
- handlers: { decrypt: decryptCmd, encrypt: encryptCmd, upgrade },
95
- });
96
- };
97
- exports.cosmologyCommand = cosmologyCommand;
@@ -1,3 +0,0 @@
1
- import { ParsedArgs } from 'minimist';
2
- export declare const doctorUsage = "\nDoctor Command:\n\n dcrypt doctor [OPTIONS]\n\n Check this machine and this workspace: Node.js, your identity, recipients.txt,\n each section, and what git would let through. Warns when there is no recovery\n recipient. Reads only; asks for no passphrase.\n\n Exits 0 when nothing failed (warnings included), 1 otherwise.\n\nOptions:\n --workspace <dir> The workspace root (default: the nearest folder upwards with a\n recipients.txt, otherwise the current folder)\n --json Machine-readable output\n --help, -h Show this help message\n";
3
- export declare const doctorCommand: (argv: ParsedArgs) => Promise<void>;
@@ -1,42 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.doctorCommand = exports.doctorUsage = void 0;
4
- const dispatch_1 = require("../utils/dispatch");
5
- const errors_1 = require("../utils/errors");
6
- const io_1 = require("../utils/io");
7
- const text_1 = require("../utils/text");
8
- const doctor_1 = require("../workspace/doctor");
9
- const layout_1 = require("../workspace/layout");
10
- exports.doctorUsage = `
11
- Doctor Command:
12
-
13
- dcrypt doctor [OPTIONS]
14
-
15
- Check this machine and this workspace: Node.js, your identity, recipients.txt,
16
- each section, and what git would let through. Warns when there is no recovery
17
- recipient. Reads only; asks for no passphrase.
18
-
19
- Exits 0 when nothing failed (warnings included), 1 otherwise.
20
-
21
- Options:
22
- --workspace <dir> The workspace root (default: the nearest folder upwards with a
23
- recipients.txt, otherwise the current folder)
24
- --json Machine-readable output
25
- --help, -h Show this help message
26
- `;
27
- const doctorCommand = async (argv) => {
28
- if ((0, dispatch_1.wantsHelp)(argv, exports.doctorUsage))
29
- return;
30
- const workspace = (0, layout_1.findWorkspace)(argv);
31
- const checks = await (0, doctor_1.runDoctor)(workspace);
32
- const failed = checks.filter((check) => check.level === 'fail').length;
33
- const warned = checks.filter((check) => check.level === 'warn').length;
34
- (0, io_1.emit)(argv, { workspace: workspace.root, ok: failed === 0, checks }, () => [
35
- `workspace: ${workspace.root}`,
36
- ...checks.map(({ level, name, message }) => `${level.padEnd(4)} ${name}: ${message}`),
37
- `${failed} failed, ${(0, text_1.count)(warned, 'warning')}`,
38
- ].join('\n'));
39
- if (failed)
40
- throw new errors_1.CliError(`doctor found ${(0, text_1.count)(failed, 'problem')}`);
41
- };
42
- exports.doctorCommand = doctorCommand;
@@ -1,12 +0,0 @@
1
- import { KdfParams, KdfProfile } from '@decryption/core';
2
- import { Inquirerer } from 'inquirerer';
3
- import { ParsedArgs } from 'minimist';
4
- export declare const encryptUsage = "\nEncrypt Command:\n\n dcrypt encrypt [text] [OPTIONS]\n\n Encrypt data with a passphrase, or to one or more X25519 recipients.\n\n With no format options the output is a small armored envelope (Argon2id +\n XChaCha20-Poly1305), held in memory: right for short secrets you paste around.\n\n --binary and --recipient select the file format instead: a binary envelope\n whose payload is encrypted in 64 KiB chunks, so files of any size are\n streamed rather than loaded. With --recipient no passphrase is asked for;\n whoever holds a matching identity (\"dcrypt keys generate\") can decrypt.\n\nOptions:\n --in <file> Read the plaintext from a file (\"-\" for stdin)\n --out <file> Write the ciphertext to a file instead of stdout\n --binary Write the binary file format (streamed, for large files)\n --recipient <key> Encrypt to this dcrypt1\u2026 public key; repeat for several\n --recipients-file <p> Encrypt to every key in a file (one per line, # comments)\n --kdf <profile> interactive | moderate | sensitive (default: moderate)\n --aad <string> Bind the ciphertext to this associated data\n (armored passphrase envelopes only)\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\n --recipient without --binary writes the same file format as text\n (\"dcrypt.v2.\u2026\"), buffered in memory: convenient for small values.\n\nExamples:\n dcrypt encrypt \"attack at dawn\"\n dcrypt encrypt --in notes.txt --out notes.dcrypt --kdf sensitive\n cat notes.txt | dcrypt encrypt --in -\n dcrypt encrypt --binary --in backup.tar --out backup.tar.dcrypt\n dcrypt encrypt --binary --recipient dcrypt1\u2026 --recipient dcrypt1\u2026 \\\n --in backup.tar --out backup.tar.dcrypt\n";
5
- export declare const decryptUsage = "\nDecrypt Command:\n\n dcrypt decrypt [armored] [OPTIONS]\n\n Decrypt data produced by \"dcrypt encrypt\". The format is detected from the\n input. A file encrypted to recipients is opened with your stored identity,\n and the passphrase asked for is the one that protects that identity.\n\nOptions:\n --in <file> Read the ciphertext from a file (\"-\" for stdin)\n --out <file> Write the plaintext to a file instead of stdout\n --aad <string> Associated data the ciphertext was bound to\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\n With --out the plaintext is written to a temporary file and renamed into\n place only after the whole input has authenticated: a wrong passphrase, a\n truncated or modified file, or an interrupt leaves --out untouched. On stdout,\n large files are streamed, so check the exit code before trusting the output.\n\nExit codes:\n 2 wrong passphrase or tampered ciphertext\n 3 corrupt, truncated or unsupported envelope\n 4 no identity on this machine\n 5 your identity is not a recipient\n\nExamples:\n dcrypt decrypt --in notes.dcrypt --out notes.txt\n dcrypt decrypt --in backup.tar.dcrypt --out backup.tar\n";
6
- export declare const encryptCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
7
- export declare const decryptCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
8
- /**
9
- * Accepts a profile name, or explicit costs as `t=3,m=262144,p=1` for constrained hardware.
10
- * Envelopes carry their own parameters, so decryption never needs this flag.
11
- */
12
- export declare const resolveKdf: (value: unknown) => KdfProfile | KdfParams;