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
package/utils/dispatch.js DELETED
@@ -1,58 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wantsHelp = exports.runSubcommand = exports.takeFirst = void 0;
4
- const inquirerer_1 = require("inquirerer");
5
- const errors_1 = require("./errors");
6
- /**
7
- * `extractFirst` with the argv type preserved — upstream narrows the rest of argv to
8
- * `{ _: string[] }`, which loses every flag.
9
- */
10
- const takeFirst = (argv) => (0, inquirerer_1.extractFirst)(argv);
11
- exports.takeFirst = takeFirst;
12
- /**
13
- * Dispatches `dcrypt <group> <subcommand>`: extracts the positional subcommand, prints per-command
14
- * help on `--help`, and prompts for the subcommand when running interactively without one.
15
- */
16
- const runSubcommand = async (argv, prompter, { name, usage, handlers }) => {
17
- const { first, newArgv } = (0, exports.takeFirst)(argv);
18
- let subcommand = first;
19
- if (!subcommand && (argv.help || argv.h)) {
20
- process.stdout.write(usage);
21
- return;
22
- }
23
- if (subcommand === 'help') {
24
- process.stdout.write(usage);
25
- return;
26
- }
27
- if (!subcommand) {
28
- const answer = await prompter.prompt(newArgv, [
29
- {
30
- type: 'autocomplete',
31
- name: 'subcommand',
32
- message: `${name} — what do you want to do?`,
33
- options: Object.keys(handlers),
34
- },
35
- ]);
36
- subcommand = answer.subcommand;
37
- }
38
- const handler = handlers[subcommand];
39
- if (!handler) {
40
- process.stdout.write(usage);
41
- throw new errors_1.CliError(`unknown ${name} subcommand: ${subcommand}`);
42
- }
43
- if (newArgv.help || newArgv.h) {
44
- process.stdout.write(usage);
45
- return;
46
- }
47
- await handler(newArgv, prompter);
48
- };
49
- exports.runSubcommand = runSubcommand;
50
- /** Prints `usage` and returns true when the user asked for help. */
51
- const wantsHelp = (argv, usage) => {
52
- if (argv.help || argv.h) {
53
- process.stdout.write(usage);
54
- return true;
55
- }
56
- return false;
57
- };
58
- exports.wantsHelp = wantsHelp;
package/utils/env.d.ts DELETED
@@ -1,26 +0,0 @@
1
- /**
2
- * Environment variable input, kept compatible with the cosmology CLI.
3
- *
4
- * Every name that CLI read still works — `MNEMONIC`, `SALT`, `ENCRYPTED_SALT`,
5
- * `KEYCHAIN_ACCOUNT` — alongside `DCRYPT_`-prefixed aliases for use in
6
- * environments where the bare names would collide.
7
- *
8
- * Resolution order everywhere is: explicit flag, then environment, then stdin,
9
- * then an interactive prompt. Flags always win so a script can override an
10
- * inherited variable, and argv still never carries a secret.
11
- */
12
- export declare const ENV_VARS: {
13
- readonly mnemonic: readonly ["MNEMONIC", "DCRYPT_MNEMONIC"];
14
- readonly salt: readonly ["SALT", "DCRYPT_SALT"];
15
- readonly encryptedSalt: readonly ["ENCRYPTED_SALT", "DCRYPT_ENCRYPTED_SALT"];
16
- readonly keychainAccount: readonly ["KEYCHAIN_ACCOUNT", "DCRYPT_KEYCHAIN_ACCOUNT"];
17
- readonly passphrase: readonly ["DCRYPT_PASSPHRASE"];
18
- readonly accountPassword: readonly ["DCRYPT_ACCOUNT_PASSWORD"];
19
- readonly authEndpoint: readonly ["DCRYPT_AUTH_ENDPOINT"];
20
- };
21
- export type EnvInput = keyof typeof ENV_VARS;
22
- /** First non-empty value among the names for `input`, or undefined. */
23
- export declare const fromEnv: (input: EnvInput, env?: NodeJS.ProcessEnv) => string | undefined;
24
- /** The keychain namespace, matching the cosmology CLI's `KEYCHAIN_ACCOUNT`. */
25
- export declare const keychainAccount: (env?: NodeJS.ProcessEnv) => string;
26
- export declare const envUsage = "\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";
package/utils/env.js DELETED
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.envUsage = exports.keychainAccount = exports.fromEnv = exports.ENV_VARS = void 0;
4
- /**
5
- * Environment variable input, kept compatible with the cosmology CLI.
6
- *
7
- * Every name that CLI read still works — `MNEMONIC`, `SALT`, `ENCRYPTED_SALT`,
8
- * `KEYCHAIN_ACCOUNT` — alongside `DCRYPT_`-prefixed aliases for use in
9
- * environments where the bare names would collide.
10
- *
11
- * Resolution order everywhere is: explicit flag, then environment, then stdin,
12
- * then an interactive prompt. Flags always win so a script can override an
13
- * inherited variable, and argv still never carries a secret.
14
- */
15
- exports.ENV_VARS = {
16
- mnemonic: ['MNEMONIC', 'DCRYPT_MNEMONIC'],
17
- salt: ['SALT', 'DCRYPT_SALT'],
18
- encryptedSalt: ['ENCRYPTED_SALT', 'DCRYPT_ENCRYPTED_SALT'],
19
- keychainAccount: ['KEYCHAIN_ACCOUNT', 'DCRYPT_KEYCHAIN_ACCOUNT'],
20
- passphrase: ['DCRYPT_PASSPHRASE'],
21
- accountPassword: ['DCRYPT_ACCOUNT_PASSWORD'],
22
- authEndpoint: ['DCRYPT_AUTH_ENDPOINT'],
23
- };
24
- /** First non-empty value among the names for `input`, or undefined. */
25
- const fromEnv = (input, env = process.env) => {
26
- for (const name of exports.ENV_VARS[input]) {
27
- const value = env[name];
28
- if (typeof value === 'string' && value.length)
29
- return value;
30
- }
31
- return undefined;
32
- };
33
- exports.fromEnv = fromEnv;
34
- /** The keychain namespace, matching the cosmology CLI's `KEYCHAIN_ACCOUNT`. */
35
- const keychainAccount = (env = process.env) => (0, exports.fromEnv)('keychainAccount', env) ?? 'dcrypt';
36
- exports.keychainAccount = keychainAccount;
37
- exports.envUsage = `
38
- Environment:
39
- MNEMONIC A BIP39 mnemonic, for wallet commands
40
- SALT The salt, for salt and cosmology commands
41
- ENCRYPTED_SALT The encrypted salt, for the two-layer scheme
42
- KEYCHAIN_ACCOUNT Keychain namespace (default: dcrypt)
43
- DCRYPT_PASSPHRASE The passphrase, for unattended runs
44
- DCRYPT_AUTH_ENDPOINT Constructive auth endpoint, for account commands
45
- DCRYPT_ACCOUNT_PASSWORD The account password, for unattended sign-in
46
-
47
- Each also accepts a DCRYPT_-prefixed alias (DCRYPT_MNEMONIC, DCRYPT_SALT, ...).
48
- Flags take precedence over the environment, which takes precedence over stdin.
49
- `;
package/utils/errors.d.ts DELETED
@@ -1,25 +0,0 @@
1
- /**
2
- * Exit codes, so scripts can tell failure modes apart without parsing messages.
3
- *
4
- * | Code | Meaning |
5
- * |------|---------|
6
- * | 1 | Usage error — bad arguments, unknown command |
7
- * | 2 | Wrong passphrase, or authentication failed |
8
- * | 3 | Corrupt or unsupported input |
9
- * | 4 | Not found — no such secret, vault, or keychain entry |
10
- * | 5 | Permission — this identity is not a recipient |
11
- */
12
- export declare const EXIT: {
13
- readonly usage: 1;
14
- readonly auth: 2;
15
- readonly corrupt: 3;
16
- readonly notFound: 4;
17
- readonly permission: 5;
18
- };
19
- export declare class CliError extends Error {
20
- readonly code: number;
21
- constructor(message: string, code?: number);
22
- }
23
- /** Maps library errors onto exit codes; unknown errors keep exit code 1. */
24
- export declare const exitCodeFor: (error: unknown) => number;
25
- export declare const messageFor: (error: unknown) => string;
package/utils/errors.js DELETED
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.messageFor = exports.exitCodeFor = exports.CliError = exports.EXIT = void 0;
4
- const core_1 = require("@decryption/core");
5
- const keys_1 = require("@decryption/keys");
6
- /**
7
- * Exit codes, so scripts can tell failure modes apart without parsing messages.
8
- *
9
- * | Code | Meaning |
10
- * |------|---------|
11
- * | 1 | Usage error — bad arguments, unknown command |
12
- * | 2 | Wrong passphrase, or authentication failed |
13
- * | 3 | Corrupt or unsupported input |
14
- * | 4 | Not found — no such secret, vault, or keychain entry |
15
- * | 5 | Permission — this identity is not a recipient |
16
- */
17
- exports.EXIT = {
18
- usage: 1,
19
- auth: 2,
20
- corrupt: 3,
21
- notFound: 4,
22
- permission: 5,
23
- };
24
- class CliError extends Error {
25
- code;
26
- constructor(message, code = exports.EXIT.usage) {
27
- super(message);
28
- this.name = 'CliError';
29
- this.code = code;
30
- }
31
- }
32
- exports.CliError = CliError;
33
- /** Maps library errors onto exit codes; unknown errors keep exit code 1. */
34
- const exitCodeFor = (error) => {
35
- if (error instanceof CliError)
36
- return error.code;
37
- if (error instanceof core_1.WrongPassphraseError)
38
- return exports.EXIT.auth;
39
- if (error instanceof core_1.CorruptEnvelopeError || error instanceof core_1.UnsupportedEnvelopeError) {
40
- return exports.EXIT.corrupt;
41
- }
42
- if (error instanceof keys_1.NotRecipientError)
43
- return exports.EXIT.permission;
44
- if (error instanceof core_1.InvalidParametersError)
45
- return exports.EXIT.usage;
46
- return exports.EXIT.usage;
47
- };
48
- exports.exitCodeFor = exitCodeFor;
49
- const messageFor = (error) => error instanceof Error ? error.message : String(error);
50
- exports.messageFor = messageFor;
package/utils/header.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { FileHeader } from '@decryption/core';
2
- import { ByteReader } from './bytes';
3
- /** Reads exactly the header off the front of `reader`; the payload stays in the stream. */
4
- export declare const readFileHeader: (reader: ByteReader) => Promise<FileHeader>;
package/utils/header.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readFileHeader = void 0;
4
- const core_1 = require("@decryption/core");
5
- /** Reads exactly the header off the front of `reader`; the payload stays in the stream. */
6
- const readFileHeader = async (reader) => {
7
- for (;;) {
8
- const header = (0, core_1.tryParseFileHeader)(reader.buffered);
9
- if (header) {
10
- reader.skip(header.length);
11
- return header;
12
- }
13
- if (!(await reader.more())) {
14
- throw new core_1.CorruptEnvelopeError('envelope is truncated: the header is incomplete');
15
- }
16
- }
17
- };
18
- exports.readFileHeader = readFileHeader;
package/utils/io.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { ParsedArgs } from 'minimist';
2
- /** Reads `--in <file>`, `-` (stdin), or the given inline value, in that order. */
3
- export declare const readInput: (argv: ParsedArgs, inline?: string) => string;
4
- /** Writes to `--out <file>` when given, otherwise stdout. */
5
- export declare const writeOutput: (argv: ParsedArgs, content: string) => void;
6
- /** Emits `--json` output, or the human-readable rendering. */
7
- export declare const emit: (argv: ParsedArgs, data: unknown, human: () => string) => void;
8
- /** True when the command should avoid printing secrets to a terminal. */
9
- export declare const isTty: () => boolean;
10
- export declare const readStdin: () => string;
package/utils/io.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readStdin = exports.isTty = exports.emit = exports.writeOutput = exports.readInput = void 0;
4
- const fs_1 = require("fs");
5
- const errors_1 = require("./errors");
6
- /** Reads `--in <file>`, `-` (stdin), or the given inline value, in that order. */
7
- const readInput = (argv, inline) => {
8
- if (typeof argv.in === 'string' && argv.in.length) {
9
- if (argv.in === '-')
10
- return (0, exports.readStdin)();
11
- try {
12
- return (0, fs_1.readFileSync)(argv.in, 'utf8');
13
- }
14
- catch {
15
- throw new errors_1.CliError(`cannot read ${argv.in}`, errors_1.EXIT.notFound);
16
- }
17
- }
18
- if (inline === '-' || argv.stdin)
19
- return (0, exports.readStdin)();
20
- if (inline !== undefined && inline !== '')
21
- return inline;
22
- if (!process.stdin.isTTY)
23
- return (0, exports.readStdin)();
24
- throw new errors_1.CliError('no input: pass a value, --in <file>, or pipe on stdin');
25
- };
26
- exports.readInput = readInput;
27
- /** Writes to `--out <file>` when given, otherwise stdout. */
28
- const writeOutput = (argv, content) => {
29
- const text = content.endsWith('\n') ? content : `${content}\n`;
30
- if (typeof argv.out === 'string' && argv.out.length) {
31
- (0, fs_1.writeFileSync)(argv.out, text, { mode: 0o600 });
32
- return;
33
- }
34
- process.stdout.write(text);
35
- };
36
- exports.writeOutput = writeOutput;
37
- /** Emits `--json` output, or the human-readable rendering. */
38
- const emit = (argv, data, human) => {
39
- if (argv.json) {
40
- (0, exports.writeOutput)(argv, JSON.stringify(data, null, 2));
41
- return;
42
- }
43
- (0, exports.writeOutput)(argv, human());
44
- };
45
- exports.emit = emit;
46
- /** True when the command should avoid printing secrets to a terminal. */
47
- const isTty = () => Boolean(process.stdout.isTTY);
48
- exports.isTty = isTty;
49
- const readStdin = () => {
50
- try {
51
- return (0, fs_1.readFileSync)(0, 'utf8');
52
- }
53
- catch {
54
- throw new errors_1.CliError('failed to read stdin');
55
- }
56
- };
57
- exports.readStdin = readStdin;
@@ -1,15 +0,0 @@
1
- import { Inquirerer } from 'inquirerer';
2
- import { ParsedArgs } from 'minimist';
3
- export interface PassphraseOptions {
4
- /** Ask twice and compare — used when creating something new. */
5
- confirm?: boolean;
6
- message?: string;
7
- }
8
- /**
9
- * Resolves a passphrase without ever accepting one on the command line.
10
- *
11
- * Order: `--passphrase-file <path>`, `DCRYPT_PASSPHRASE`, `--passphrase-stdin`, then an
12
- * interactive masked prompt. Passing `--passphrase` is rejected outright: argv is visible
13
- * to every process on the machine.
14
- */
15
- export declare const resolvePassphrase: (argv: ParsedArgs, prompter: Inquirerer, options?: PassphraseOptions) => Promise<string>;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolvePassphrase = void 0;
4
- const fs_1 = require("fs");
5
- const env_1 = require("./env");
6
- const errors_1 = require("./errors");
7
- const io_1 = require("./io");
8
- /**
9
- * Resolves a passphrase without ever accepting one on the command line.
10
- *
11
- * Order: `--passphrase-file <path>`, `DCRYPT_PASSPHRASE`, `--passphrase-stdin`, then an
12
- * interactive masked prompt. Passing `--passphrase` is rejected outright: argv is visible
13
- * to every process on the machine.
14
- */
15
- const resolvePassphrase = async (argv, prompter, options = {}) => {
16
- if (argv.passphrase !== undefined || argv.password !== undefined) {
17
- throw new errors_1.CliError('refusing to read a passphrase from argv (it is visible in `ps`); use --passphrase-file <path> or --passphrase-stdin');
18
- }
19
- const file = argv['passphrase-file'] ?? argv.passphraseFile;
20
- if (typeof file === 'string' && file.length) {
21
- try {
22
- return (0, fs_1.readFileSync)(file, 'utf8').replace(/\r?\n$/, '');
23
- }
24
- catch {
25
- throw new errors_1.CliError(`cannot read passphrase file ${file}`, errors_1.EXIT.notFound);
26
- }
27
- }
28
- const fromEnvironment = (0, env_1.fromEnv)('passphrase');
29
- if (fromEnvironment !== undefined) {
30
- return fromEnvironment.replace(/\r?\n$/, '');
31
- }
32
- if (argv['passphrase-stdin'] || argv.passphraseStdin) {
33
- return (0, io_1.readStdin)().replace(/\r?\n$/, '');
34
- }
35
- if (!process.stdin.isTTY) {
36
- throw new errors_1.CliError('no passphrase: stdin is not a terminal, so there is nothing to prompt on; use --passphrase-file <path>, DCRYPT_PASSPHRASE or --passphrase-stdin');
37
- }
38
- const message = options.message ?? 'Passphrase';
39
- const { passphrase } = await prompter.prompt({}, [
40
- { type: 'password', name: 'passphrase', message, required: true },
41
- ]);
42
- if (!passphrase)
43
- throw new errors_1.CliError('a passphrase is required');
44
- if (options.confirm) {
45
- const { confirmation } = await prompter.prompt({}, [
46
- { type: 'password', name: 'confirmation', message: 'Confirm passphrase', required: true },
47
- ]);
48
- if (confirmation !== passphrase)
49
- throw new errors_1.CliError('passphrases do not match');
50
- }
51
- return passphrase;
52
- };
53
- exports.resolvePassphrase = resolvePassphrase;
@@ -1,28 +0,0 @@
1
- import { ParsedArgs } from 'minimist';
2
- /** One line of a recipients file. */
3
- export interface RecipientEntry {
4
- /** Canonical `dcrypt1…` string. */
5
- recipient: string;
6
- /** Everything after the key on its line; free text, may be empty. */
7
- label: string;
8
- /** 1-based line number, for messages. */
9
- line: number;
10
- }
11
- /**
12
- * Parses a recipients file: one `dcrypt1…` public key per line, optionally followed by a label.
13
- * Blank lines and lines starting with `#` are ignored. Keys are public, so the file is safe to
14
- * commit.
15
- *
16
- * ```text
17
- * # who can open this
18
- * dcrypt1qxy… ada (laptop)
19
- * dcrypt1qab… recovery — printed, in the safe
20
- * ```
21
- */
22
- export declare const parseRecipients: (text: string, origin?: string) => RecipientEntry[];
23
- export declare const readRecipientsFile: (path: string) => RecipientEntry[];
24
- /**
25
- * Recipients named on the command line: every `--recipient <dcrypt1…>` and every line of every
26
- * `--recipients-file <path>`, de-duplicated, in the order given.
27
- */
28
- export declare const collectRecipients: (argv: ParsedArgs) => string[];
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collectRecipients = exports.readRecipientsFile = exports.parseRecipients = void 0;
4
- const keys_1 = require("@decryption/keys");
5
- const fs_1 = require("fs");
6
- const errors_1 = require("./errors");
7
- /**
8
- * Parses a recipients file: one `dcrypt1…` public key per line, optionally followed by a label.
9
- * Blank lines and lines starting with `#` are ignored. Keys are public, so the file is safe to
10
- * commit.
11
- *
12
- * ```text
13
- * # who can open this
14
- * dcrypt1qxy… ada (laptop)
15
- * dcrypt1qab… recovery — printed, in the safe
16
- * ```
17
- */
18
- const parseRecipients = (text, origin = 'recipients') => {
19
- const entries = [];
20
- const seen = new Set();
21
- text.split(/\r?\n/).forEach((raw, index) => {
22
- const line = raw.trim();
23
- if (!line || line.startsWith('#'))
24
- return;
25
- const [key, ...rest] = line.split(/\s+/);
26
- let recipient;
27
- try {
28
- recipient = (0, keys_1.recipientToString)((0, keys_1.recipientFromString)(key));
29
- }
30
- catch (error) {
31
- throw new errors_1.CliError(`${origin}:${index + 1}: ${(0, errors_1.messageFor)(error)}`);
32
- }
33
- if (seen.has(recipient))
34
- return;
35
- seen.add(recipient);
36
- entries.push({ recipient, label: rest.join(' '), line: index + 1 });
37
- });
38
- return entries;
39
- };
40
- exports.parseRecipients = parseRecipients;
41
- const readRecipientsFile = (path) => {
42
- let text;
43
- try {
44
- text = (0, fs_1.readFileSync)(path, 'utf8');
45
- }
46
- catch {
47
- throw new errors_1.CliError(`cannot read recipients file ${path}`, errors_1.EXIT.notFound);
48
- }
49
- return (0, exports.parseRecipients)(text, path);
50
- };
51
- exports.readRecipientsFile = readRecipientsFile;
52
- const values = (value, flag) => {
53
- if (value === undefined)
54
- return [];
55
- const list = Array.isArray(value) ? value : [value];
56
- return list.map((item) => {
57
- if (typeof item !== 'string' || !item.length)
58
- throw new errors_1.CliError(`${flag} needs a value`);
59
- return item;
60
- });
61
- };
62
- /**
63
- * Recipients named on the command line: every `--recipient <dcrypt1…>` and every line of every
64
- * `--recipients-file <path>`, de-duplicated, in the order given.
65
- */
66
- const collectRecipients = (argv) => {
67
- const direct = values(argv.recipient, '--recipient').map((value) => {
68
- try {
69
- return (0, keys_1.recipientToString)((0, keys_1.recipientFromString)(value));
70
- }
71
- catch (error) {
72
- throw new errors_1.CliError(`--recipient ${value}: ${(0, errors_1.messageFor)(error)}`);
73
- }
74
- });
75
- const fromFiles = values(argv['recipients-file'] ?? argv.recipientsFile, '--recipients-file')
76
- .flatMap((path) => (0, exports.readRecipientsFile)(path))
77
- .map((entry) => entry.recipient);
78
- return [...new Set([...direct, ...fromFiles])];
79
- };
80
- exports.collectRecipients = collectRecipients;
package/utils/stash.d.ts DELETED
@@ -1,40 +0,0 @@
1
- import { KdfParams, KdfProfile } from '@decryption/core';
2
- import { Identity } from '@decryption/keys';
3
- /**
4
- * On-disk layout, shared byte-for-byte with the Electron app:
5
- *
6
- * ```text
7
- * ~/.dcrypt/
8
- * config/identity.json the user's X25519 identity, encrypted under a passphrase
9
- * data/keychain.json named secrets, each encrypted under a passphrase
10
- * (KEYCHAIN_ACCOUNT selects keychain-<account>.json instead)
11
- * data/vaults/<name>.json team secrets files
12
- * ```
13
- *
14
- * Nothing here is ever written in plaintext.
15
- */
16
- export declare const APP_NAME = "dcrypt";
17
- export declare const dirs: () => import("appstash").AppStashResult;
18
- export declare const identityPath: () => string;
19
- export declare const keychainPath: () => string;
20
- export declare const vaultPath: (name: string) => string;
21
- export interface StoredIdentity {
22
- version: 1;
23
- /** Public recipient string — safe to store in the clear, and to share. */
24
- recipient: string;
25
- /** Armored envelope holding the private key. */
26
- encrypted: string;
27
- }
28
- export interface Keychain {
29
- version: 1;
30
- entries: Record<string, string>;
31
- }
32
- export declare const hasIdentity: () => boolean;
33
- export declare const saveIdentity: (identity: Identity, passphrase: string, kdf?: KdfProfile | KdfParams) => StoredIdentity;
34
- export declare const readStoredIdentity: () => StoredIdentity;
35
- export declare const loadIdentity: (passphrase: string) => Identity;
36
- export declare const readKeychain: () => Keychain;
37
- export declare const writeKeychain: (keychain: Keychain) => void;
38
- export declare const readJson: <T>(path: string) => T;
39
- /** Writes JSON with owner-only permissions and a trailing newline. */
40
- export declare const writeJson: (path: string, value: unknown) => void;
package/utils/stash.js DELETED
@@ -1,76 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeJson = exports.readJson = exports.writeKeychain = exports.readKeychain = exports.loadIdentity = exports.readStoredIdentity = exports.saveIdentity = exports.hasIdentity = exports.vaultPath = exports.keychainPath = exports.identityPath = exports.dirs = exports.APP_NAME = void 0;
4
- const core_1 = require("@decryption/core");
5
- const keys_1 = require("@decryption/keys");
6
- const appstash_1 = require("appstash");
7
- const fs_1 = require("fs");
8
- const path_1 = require("path");
9
- const env_1 = require("./env");
10
- const errors_1 = require("./errors");
11
- /**
12
- * On-disk layout, shared byte-for-byte with the Electron app:
13
- *
14
- * ```text
15
- * ~/.dcrypt/
16
- * config/identity.json the user's X25519 identity, encrypted under a passphrase
17
- * data/keychain.json named secrets, each encrypted under a passphrase
18
- * (KEYCHAIN_ACCOUNT selects keychain-<account>.json instead)
19
- * data/vaults/<name>.json team secrets files
20
- * ```
21
- *
22
- * Nothing here is ever written in plaintext.
23
- */
24
- exports.APP_NAME = 'dcrypt';
25
- const dirs = () => (0, appstash_1.appstash)(exports.APP_NAME, { ensure: true });
26
- exports.dirs = dirs;
27
- const identityPath = () => (0, appstash_1.resolve)((0, exports.dirs)(), 'config', 'identity.json');
28
- exports.identityPath = identityPath;
29
- const keychainPath = () => {
30
- const account = (0, env_1.keychainAccount)();
31
- const file = account === 'dcrypt' ? 'keychain.json' : `keychain-${account}.json`;
32
- return (0, appstash_1.resolve)((0, exports.dirs)(), 'data', file);
33
- };
34
- exports.keychainPath = keychainPath;
35
- const vaultPath = (name) => (0, path_1.join)((0, appstash_1.resolve)((0, exports.dirs)(), 'data', 'vaults'), `${name}.json`);
36
- exports.vaultPath = vaultPath;
37
- const hasIdentity = () => (0, fs_1.existsSync)((0, exports.identityPath)());
38
- exports.hasIdentity = hasIdentity;
39
- const saveIdentity = (identity, passphrase, kdf = 'moderate') => {
40
- const stored = {
41
- version: 1,
42
- recipient: (0, keys_1.recipientToString)(identity.publicKey),
43
- encrypted: (0, core_1.encryptToString)((0, keys_1.identityToString)(identity), passphrase, { kdf }),
44
- };
45
- (0, exports.writeJson)((0, exports.identityPath)(), stored);
46
- return stored;
47
- };
48
- exports.saveIdentity = saveIdentity;
49
- const readStoredIdentity = () => {
50
- if (!(0, exports.hasIdentity)()) {
51
- throw new errors_1.CliError('no identity yet — run `dcrypt keys generate`', errors_1.EXIT.notFound);
52
- }
53
- return (0, exports.readJson)((0, exports.identityPath)());
54
- };
55
- exports.readStoredIdentity = readStoredIdentity;
56
- const loadIdentity = (passphrase) => (0, keys_1.identityFromString)((0, core_1.decryptFromString)((0, exports.readStoredIdentity)().encrypted, passphrase));
57
- exports.loadIdentity = loadIdentity;
58
- const readKeychain = () => (0, fs_1.existsSync)((0, exports.keychainPath)()) ? (0, exports.readJson)((0, exports.keychainPath)()) : { version: 1, entries: {} };
59
- exports.readKeychain = readKeychain;
60
- const writeKeychain = (keychain) => (0, exports.writeJson)((0, exports.keychainPath)(), keychain);
61
- exports.writeKeychain = writeKeychain;
62
- const readJson = (path) => {
63
- try {
64
- return JSON.parse((0, fs_1.readFileSync)(path, 'utf8'));
65
- }
66
- catch {
67
- throw new errors_1.CliError(`cannot read ${path}`, errors_1.EXIT.corrupt);
68
- }
69
- };
70
- exports.readJson = readJson;
71
- /** Writes JSON with owner-only permissions and a trailing newline. */
72
- const writeJson = (path, value) => {
73
- (0, fs_1.mkdirSync)((0, path_1.dirname)(path), { recursive: true });
74
- (0, fs_1.writeFileSync)(path, JSON.stringify(value, null, 2) + '\n', { mode: 0o600 });
75
- };
76
- exports.writeJson = writeJson;
package/utils/temp.d.ts DELETED
@@ -1,10 +0,0 @@
1
- /** A sibling path of `target`, so that renaming onto `target` never crosses a filesystem. */
2
- export declare const tempPathFor: (target: string) => string;
3
- /** True for names produced by {@link tempPathFor}. */
4
- export declare const isTempName: (name: string) => boolean;
5
- /** Registers `path` for removal if the process is interrupted. */
6
- export declare const trackTemp: (path: string) => void;
7
- /** Forgets `path`: call once it has been renamed into place or removed. */
8
- export declare const untrackTemp: (path: string) => void;
9
- /** Removes a temporary path now and forgets it. */
10
- export declare const discardTemp: (path: string) => void;