decryption 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +17 -325
- package/index.js +3 -66
- package/package.json +8 -24
- package/commands/account.d.ts +0 -4
- package/commands/account.js +0 -470
- package/commands/cosmology.d.ts +0 -4
- package/commands/cosmology.js +0 -97
- package/commands/doctor.d.ts +0 -3
- package/commands/doctor.js +0 -42
- package/commands/encrypt.d.ts +0 -12
- package/commands/encrypt.js +0 -251
- package/commands/guard.d.ts +0 -3
- package/commands/guard.js +0 -92
- package/commands/keychain.d.ts +0 -4
- package/commands/keychain.js +0 -92
- package/commands/keys.d.ts +0 -4
- package/commands/keys.js +0 -74
- package/commands/passkey.d.ts +0 -4
- package/commands/passkey.js +0 -135
- package/commands/salt.d.ts +0 -4
- package/commands/salt.js +0 -113
- package/commands/secrets.d.ts +0 -4
- package/commands/secrets.js +0 -214
- package/commands/shamir.d.ts +0 -4
- package/commands/shamir.js +0 -62
- package/commands/vault.d.ts +0 -7
- package/commands/vault.js +0 -382
- package/commands/wallet.d.ts +0 -5
- package/commands/wallet.js +0 -129
- package/commands/workspace.d.ts +0 -8
- package/commands/workspace.js +0 -289
- package/commands.d.ts +0 -8
- package/commands.js +0 -126
- package/esm/commands/account.js +0 -466
- package/esm/commands/cosmology.js +0 -93
- package/esm/commands/doctor.js +0 -38
- package/esm/commands/encrypt.js +0 -245
- package/esm/commands/guard.js +0 -88
- package/esm/commands/keychain.js +0 -88
- package/esm/commands/keys.js +0 -70
- package/esm/commands/passkey.js +0 -131
- package/esm/commands/salt.js +0 -109
- package/esm/commands/secrets.js +0 -210
- package/esm/commands/shamir.js +0 -58
- package/esm/commands/vault.js +0 -376
- package/esm/commands/wallet.js +0 -125
- package/esm/commands/workspace.js +0 -283
- package/esm/commands.js +0 -120
- package/esm/index.js +0 -50
- package/esm/utils/bytes.js +0 -286
- package/esm/utils/dispatch.js +0 -52
- package/esm/utils/env.js +0 -44
- package/esm/utils/errors.js +0 -44
- package/esm/utils/header.js +0 -14
- package/esm/utils/io.js +0 -49
- package/esm/utils/passphrase.js +0 -49
- package/esm/utils/recipients.js +0 -74
- package/esm/utils/stash.js +0 -61
- package/esm/utils/temp.js +0 -51
- package/esm/utils/text.js +0 -2
- package/esm/workspace/bundle.js +0 -239
- package/esm/workspace/doctor.js +0 -104
- package/esm/workspace/git.js +0 -72
- package/esm/workspace/guard.js +0 -111
- package/esm/workspace/layout.js +0 -106
- package/esm/workspace/manifest.js +0 -147
- package/esm/workspace/recipients.js +0 -37
- package/esm/workspace/snippets.js +0 -54
- package/esm/workspace/state.js +0 -46
- package/esm/workspace/status.js +0 -93
- package/esm/workspace/tar.js +0 -235
- package/index.d.ts +0 -12
- package/utils/bytes.d.ts +0 -86
- package/utils/bytes.js +0 -301
- package/utils/dispatch.d.ts +0 -24
- package/utils/dispatch.js +0 -58
- package/utils/env.d.ts +0 -26
- package/utils/env.js +0 -49
- package/utils/errors.d.ts +0 -25
- package/utils/errors.js +0 -50
- package/utils/header.d.ts +0 -4
- package/utils/header.js +0 -18
- package/utils/io.d.ts +0 -10
- package/utils/io.js +0 -57
- package/utils/passphrase.d.ts +0 -15
- package/utils/passphrase.js +0 -53
- package/utils/recipients.d.ts +0 -28
- package/utils/recipients.js +0 -80
- package/utils/stash.d.ts +0 -40
- package/utils/stash.js +0 -76
- package/utils/temp.d.ts +0 -10
- package/utils/temp.js +0 -59
- package/utils/text.d.ts +0 -2
- package/utils/text.js +0 -6
- package/workspace/bundle.d.ts +0 -50
- package/workspace/bundle.js +0 -248
- package/workspace/doctor.d.ts +0 -8
- package/workspace/doctor.js +0 -108
- package/workspace/git.d.ts +0 -21
- package/workspace/git.js +0 -83
- package/workspace/guard.d.ts +0 -23
- package/workspace/guard.js +0 -118
- package/workspace/layout.d.ts +0 -47
- package/workspace/layout.js +0 -113
- package/workspace/manifest.d.ts +0 -52
- package/workspace/manifest.js +0 -157
- package/workspace/recipients.d.ts +0 -16
- package/workspace/recipients.js +0 -45
- package/workspace/snippets.d.ts +0 -29
- package/workspace/snippets.js +0 -58
- package/workspace/state.d.ts +0 -13
- package/workspace/state.js +0 -52
- package/workspace/status.d.ts +0 -54
- package/workspace/status.js +0 -99
- package/workspace/tar.d.ts +0 -29
- package/workspace/tar.js +0 -240
package/commands/encrypt.js
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveKdf = exports.decryptCommand = exports.encryptCommand = exports.decryptUsage = exports.encryptUsage = void 0;
|
|
4
|
-
const core_1 = require("@decryption/core");
|
|
5
|
-
const keys_1 = require("@decryption/keys");
|
|
6
|
-
const bytes_1 = require("../utils/bytes");
|
|
7
|
-
const dispatch_1 = require("../utils/dispatch");
|
|
8
|
-
const errors_1 = require("../utils/errors");
|
|
9
|
-
const header_1 = require("../utils/header");
|
|
10
|
-
const passphrase_1 = require("../utils/passphrase");
|
|
11
|
-
const recipients_1 = require("../utils/recipients");
|
|
12
|
-
const stash_1 = require("../utils/stash");
|
|
13
|
-
exports.encryptUsage = `
|
|
14
|
-
Encrypt Command:
|
|
15
|
-
|
|
16
|
-
dcrypt encrypt [text] [OPTIONS]
|
|
17
|
-
|
|
18
|
-
Encrypt data with a passphrase, or to one or more X25519 recipients.
|
|
19
|
-
|
|
20
|
-
With no format options the output is a small armored envelope (Argon2id +
|
|
21
|
-
XChaCha20-Poly1305), held in memory: right for short secrets you paste around.
|
|
22
|
-
|
|
23
|
-
--binary and --recipient select the file format instead: a binary envelope
|
|
24
|
-
whose payload is encrypted in 64 KiB chunks, so files of any size are
|
|
25
|
-
streamed rather than loaded. With --recipient no passphrase is asked for;
|
|
26
|
-
whoever holds a matching identity ("dcrypt keys generate") can decrypt.
|
|
27
|
-
|
|
28
|
-
Options:
|
|
29
|
-
--in <file> Read the plaintext from a file ("-" for stdin)
|
|
30
|
-
--out <file> Write the ciphertext to a file instead of stdout
|
|
31
|
-
--binary Write the binary file format (streamed, for large files)
|
|
32
|
-
--recipient <key> Encrypt to this dcrypt1… public key; repeat for several
|
|
33
|
-
--recipients-file <p> Encrypt to every key in a file (one per line, # comments)
|
|
34
|
-
--kdf <profile> interactive | moderate | sensitive (default: moderate)
|
|
35
|
-
--aad <string> Bind the ciphertext to this associated data
|
|
36
|
-
(armored passphrase envelopes only)
|
|
37
|
-
--passphrase-file <p> Read the passphrase from a file
|
|
38
|
-
--passphrase-stdin Read the passphrase from stdin
|
|
39
|
-
--help, -h Show this help message
|
|
40
|
-
|
|
41
|
-
--recipient without --binary writes the same file format as text
|
|
42
|
-
("dcrypt.v2.…"), buffered in memory: convenient for small values.
|
|
43
|
-
|
|
44
|
-
Examples:
|
|
45
|
-
dcrypt encrypt "attack at dawn"
|
|
46
|
-
dcrypt encrypt --in notes.txt --out notes.dcrypt --kdf sensitive
|
|
47
|
-
cat notes.txt | dcrypt encrypt --in -
|
|
48
|
-
dcrypt encrypt --binary --in backup.tar --out backup.tar.dcrypt
|
|
49
|
-
dcrypt encrypt --binary --recipient dcrypt1… --recipient dcrypt1… \\
|
|
50
|
-
--in backup.tar --out backup.tar.dcrypt
|
|
51
|
-
`;
|
|
52
|
-
exports.decryptUsage = `
|
|
53
|
-
Decrypt Command:
|
|
54
|
-
|
|
55
|
-
dcrypt decrypt [armored] [OPTIONS]
|
|
56
|
-
|
|
57
|
-
Decrypt data produced by "dcrypt encrypt". The format is detected from the
|
|
58
|
-
input. A file encrypted to recipients is opened with your stored identity,
|
|
59
|
-
and the passphrase asked for is the one that protects that identity.
|
|
60
|
-
|
|
61
|
-
Options:
|
|
62
|
-
--in <file> Read the ciphertext from a file ("-" for stdin)
|
|
63
|
-
--out <file> Write the plaintext to a file instead of stdout
|
|
64
|
-
--aad <string> Associated data the ciphertext was bound to
|
|
65
|
-
--passphrase-file <p> Read the passphrase from a file
|
|
66
|
-
--passphrase-stdin Read the passphrase from stdin
|
|
67
|
-
--help, -h Show this help message
|
|
68
|
-
|
|
69
|
-
With --out the plaintext is written to a temporary file and renamed into
|
|
70
|
-
place only after the whole input has authenticated: a wrong passphrase, a
|
|
71
|
-
truncated or modified file, or an interrupt leaves --out untouched. On stdout,
|
|
72
|
-
large files are streamed, so check the exit code before trusting the output.
|
|
73
|
-
|
|
74
|
-
Exit codes:
|
|
75
|
-
2 wrong passphrase or tampered ciphertext
|
|
76
|
-
3 corrupt, truncated or unsupported envelope
|
|
77
|
-
4 no identity on this machine
|
|
78
|
-
5 your identity is not a recipient
|
|
79
|
-
|
|
80
|
-
Examples:
|
|
81
|
-
dcrypt decrypt --in notes.dcrypt --out notes.txt
|
|
82
|
-
dcrypt decrypt --in backup.tar.dcrypt --out backup.tar
|
|
83
|
-
`;
|
|
84
|
-
const aadOf = (argv) => typeof argv.aad === 'string' ? argv.aad : undefined;
|
|
85
|
-
const encryptCommand = async (argv, prompter) => {
|
|
86
|
-
if ((0, dispatch_1.wantsHelp)(argv, exports.encryptUsage))
|
|
87
|
-
return;
|
|
88
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
89
|
-
const recipients = (0, recipients_1.collectRecipients)(newArgv);
|
|
90
|
-
const binary = Boolean(newArgv.binary);
|
|
91
|
-
if (binary || recipients.length) {
|
|
92
|
-
await encryptFileFormat(newArgv, prompter, first, recipients, binary);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
// The original format: one armored envelope, unchanged.
|
|
96
|
-
const input = await (0, bytes_1.openInput)(newArgv, first);
|
|
97
|
-
let plaintext;
|
|
98
|
-
try {
|
|
99
|
-
(0, bytes_1.assertStdinFree)(newArgv, input);
|
|
100
|
-
plaintext = await new bytes_1.ByteReader(input.stream).all();
|
|
101
|
-
}
|
|
102
|
-
finally {
|
|
103
|
-
input.close();
|
|
104
|
-
}
|
|
105
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(newArgv, prompter, { confirm: true });
|
|
106
|
-
const envelope = (0, core_1.encrypt)(plaintext, passphrase, {
|
|
107
|
-
kdf: (0, exports.resolveKdf)(newArgv.kdf),
|
|
108
|
-
aad: aadOf(newArgv),
|
|
109
|
-
});
|
|
110
|
-
await (0, bytes_1.writeText)(newArgv, (0, core_1.armor)(envelope));
|
|
111
|
-
};
|
|
112
|
-
exports.encryptCommand = encryptCommand;
|
|
113
|
-
const encryptFileFormat = async (argv, prompter, inline, recipients, binary) => {
|
|
114
|
-
if (argv.aad !== undefined) {
|
|
115
|
-
throw new errors_1.CliError('--aad is only supported by the armored passphrase envelope; drop --aad, or drop --binary and --recipient');
|
|
116
|
-
}
|
|
117
|
-
(0, bytes_1.assertNotTerminal)(argv, { binary });
|
|
118
|
-
const input = await (0, bytes_1.openInput)(argv, inline);
|
|
119
|
-
try {
|
|
120
|
-
if (!binary) {
|
|
121
|
-
// Text form of the same file, for small values: buffered, because base64 is not streamed.
|
|
122
|
-
const plaintext = await new bytes_1.ByteReader(input.stream).all();
|
|
123
|
-
await (0, bytes_1.writeText)(argv, (0, core_1.armorFile)((0, keys_1.sealFileTo)(plaintext, recipients)));
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (!recipients.length)
|
|
127
|
-
(0, bytes_1.assertStdinFree)(argv, input);
|
|
128
|
-
const { header, stream } = recipients.length
|
|
129
|
-
? (0, keys_1.createRecipientFileEncryptor)(recipients)
|
|
130
|
-
: await passphraseFileEncryptor(argv, prompter);
|
|
131
|
-
try {
|
|
132
|
-
await (0, bytes_1.writeBytes)(argv, (0, bytes_1.chainBytes)([header], (0, bytes_1.transformBytes)(input.stream, stream)), { binary });
|
|
133
|
-
}
|
|
134
|
-
finally {
|
|
135
|
-
stream.destroy();
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
finally {
|
|
139
|
-
input.close();
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
const passphraseFileEncryptor = async (argv, prompter) => {
|
|
143
|
-
const kdf = (0, exports.resolveKdf)(argv.kdf);
|
|
144
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(argv, prompter, { confirm: true });
|
|
145
|
-
const fileKey = (0, core_1.generateFileKey)();
|
|
146
|
-
try {
|
|
147
|
-
return (0, core_1.createFileEncryptor)(fileKey, [(0, core_1.wrapWithPassphrase)(fileKey, passphrase, kdf)]);
|
|
148
|
-
}
|
|
149
|
-
finally {
|
|
150
|
-
fileKey.fill(0);
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const startsWithMagic = (bytes) => bytes.length > core_1.MAGIC.length && core_1.MAGIC.every((byte, index) => bytes[index] === byte);
|
|
154
|
-
const decryptCommand = async (argv, prompter) => {
|
|
155
|
-
if ((0, dispatch_1.wantsHelp)(argv, exports.decryptUsage))
|
|
156
|
-
return;
|
|
157
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
158
|
-
const input = await (0, bytes_1.openInput)(newArgv, first);
|
|
159
|
-
try {
|
|
160
|
-
(0, bytes_1.assertStdinFree)(newArgv, input);
|
|
161
|
-
const reader = new bytes_1.ByteReader(input.stream);
|
|
162
|
-
const head = await reader.fill(core_1.MAGIC.length + 1);
|
|
163
|
-
if (startsWithMagic(head)) {
|
|
164
|
-
if (head[core_1.MAGIC.length] === core_1.FILE_VERSION) {
|
|
165
|
-
await decryptFileFormat(newArgv, prompter, reader);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
// A version 1 envelope that was never armored. Small by construction: read it whole.
|
|
169
|
-
const envelope = await reader.all();
|
|
170
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(newArgv, prompter);
|
|
171
|
-
await (0, bytes_1.writePlaintext)(newArgv, (0, core_1.decrypt)(envelope, passphrase, { aad: aadOf(newArgv) }));
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
const text = (await reader.all()).toString('utf8').trim();
|
|
175
|
-
if (text.startsWith(core_1.FILE_ARMOR_PREFIX)) {
|
|
176
|
-
await decryptFileFormat(newArgv, prompter, new bytes_1.ByteReader([(0, core_1.dearmorFile)(text)]));
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(newArgv, prompter);
|
|
180
|
-
await (0, bytes_1.writePlaintext)(newArgv, (0, core_1.decrypt)((0, core_1.dearmor)(text), passphrase, { aad: aadOf(newArgv) }));
|
|
181
|
-
}
|
|
182
|
-
finally {
|
|
183
|
-
input.close();
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
exports.decryptCommand = decryptCommand;
|
|
187
|
-
/**
|
|
188
|
-
* Recovers the file key. Nothing has been written anywhere yet when this runs, so a wrong
|
|
189
|
-
* passphrase or a missing recipient fails before any output exists.
|
|
190
|
-
*/
|
|
191
|
-
const unlockFileKey = async (argv, prompter, header) => {
|
|
192
|
-
if ((0, core_1.isPassphraseFile)(header)) {
|
|
193
|
-
return (0, core_1.unwrapWithPassphrase)(header, await (0, passphrase_1.resolvePassphrase)(argv, prompter));
|
|
194
|
-
}
|
|
195
|
-
// The stored recipient is public, so "not for you" needs no passphrase to find out.
|
|
196
|
-
const mine = (0, keys_1.fingerprint)((0, keys_1.recipientFromString)((0, stash_1.readStoredIdentity)().recipient));
|
|
197
|
-
const recipients = (0, keys_1.fileRecipients)(header);
|
|
198
|
-
if (!recipients.includes(mine)) {
|
|
199
|
-
throw new keys_1.NotRecipientError(`this identity (${mine}) is not a recipient; recipients are ${recipients.join(', ') || 'none'}`);
|
|
200
|
-
}
|
|
201
|
-
const identity = (0, stash_1.loadIdentity)(await (0, passphrase_1.resolvePassphrase)(argv, prompter, { message: 'Identity passphrase' }));
|
|
202
|
-
try {
|
|
203
|
-
return (0, keys_1.unwrapWithIdentity)(header, identity);
|
|
204
|
-
}
|
|
205
|
-
finally {
|
|
206
|
-
identity.privateKey.fill(0);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
const decryptFileFormat = async (argv, prompter, reader) => {
|
|
210
|
-
if (argv.aad !== undefined) {
|
|
211
|
-
throw new errors_1.CliError('--aad does not apply here: this file format carries no associated data');
|
|
212
|
-
}
|
|
213
|
-
const header = await (0, header_1.readFileHeader)(reader);
|
|
214
|
-
const fileKey = await unlockFileKey(argv, prompter, header);
|
|
215
|
-
let decryptor;
|
|
216
|
-
try {
|
|
217
|
-
// Checks the header MAC: a header that was edited is rejected before any payload is read.
|
|
218
|
-
decryptor = (0, core_1.createFileDecryptor)(header, fileKey);
|
|
219
|
-
}
|
|
220
|
-
finally {
|
|
221
|
-
fileKey.fill(0);
|
|
222
|
-
}
|
|
223
|
-
try {
|
|
224
|
-
await (0, bytes_1.writeBytes)(argv, (0, bytes_1.transformBytes)(reader.rest(), decryptor));
|
|
225
|
-
}
|
|
226
|
-
finally {
|
|
227
|
-
decryptor.destroy();
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* Accepts a profile name, or explicit costs as `t=3,m=262144,p=1` for constrained hardware.
|
|
232
|
-
* Envelopes carry their own parameters, so decryption never needs this flag.
|
|
233
|
-
*/
|
|
234
|
-
const resolveKdf = (value) => {
|
|
235
|
-
if (value === undefined)
|
|
236
|
-
return 'moderate';
|
|
237
|
-
if (typeof value !== 'string')
|
|
238
|
-
throw unknownKdf(value);
|
|
239
|
-
if (value in core_1.KDF_PROFILES)
|
|
240
|
-
return value;
|
|
241
|
-
if (!/^[tmp]=\d+(,[tmp]=\d+)*$/.test(value))
|
|
242
|
-
throw unknownKdf(value);
|
|
243
|
-
const params = { ...core_1.KDF_PROFILES.moderate };
|
|
244
|
-
for (const pair of value.split(',')) {
|
|
245
|
-
const [name, count] = pair.split('=');
|
|
246
|
-
params[name] = Number(count);
|
|
247
|
-
}
|
|
248
|
-
return params;
|
|
249
|
-
};
|
|
250
|
-
exports.resolveKdf = resolveKdf;
|
|
251
|
-
const unknownKdf = (value) => new errors_1.CliError(`unknown --kdf value "${String(value)}"; expected ${Object.keys(core_1.KDF_PROFILES).join(', ')}, or explicit costs like t=3,m=262144,p=1`);
|
package/commands/guard.d.ts
DELETED
package/commands/guard.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.guardCommand = exports.guardUsage = 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 git_1 = require("../workspace/git");
|
|
9
|
-
const guard_1 = require("../workspace/guard");
|
|
10
|
-
const layout_1 = require("../workspace/layout");
|
|
11
|
-
const snippets_1 = require("../workspace/snippets");
|
|
12
|
-
exports.guardUsage = `
|
|
13
|
-
Guard Command:
|
|
14
|
-
|
|
15
|
-
dcrypt guard [--staged | --all] [OPTIONS]
|
|
16
|
-
dcrypt guard install [--force]
|
|
17
|
-
dcrypt guard snippet [name]
|
|
18
|
-
|
|
19
|
-
Refuse to let plaintext into git. The guard looks at what a commit would record
|
|
20
|
-
and stops on:
|
|
21
|
-
|
|
22
|
-
- a file inside the plaintext folder of an encrypted section;
|
|
23
|
-
- a *.dcrypt file whose content is not encrypted;
|
|
24
|
-
- a file .gitignore covers, added by force.
|
|
25
|
-
|
|
26
|
-
"guard install" writes it as this repository's pre-commit hook. "guard snippet"
|
|
27
|
-
prints a file to paste: ${Object.keys(snippets_1.SNIPPETS).join(', ')}.
|
|
28
|
-
|
|
29
|
-
Options:
|
|
30
|
-
--staged Check what is staged for the next commit (default)
|
|
31
|
-
--all Check every tracked file (for CI)
|
|
32
|
-
--force With install: replace a pre-commit hook dcrypt did not write
|
|
33
|
-
--workspace <dir> The workspace root (default: the nearest folder upwards with a
|
|
34
|
-
recipients.txt, otherwise the current folder)
|
|
35
|
-
--json Machine-readable output
|
|
36
|
-
--help, -h Show this help message
|
|
37
|
-
|
|
38
|
-
Examples:
|
|
39
|
-
dcrypt guard install
|
|
40
|
-
dcrypt guard snippet gitignore > .gitignore
|
|
41
|
-
dcrypt guard --all
|
|
42
|
-
`;
|
|
43
|
-
const check = async (argv) => {
|
|
44
|
-
if (argv.staged && argv.all)
|
|
45
|
-
throw new errors_1.CliError('--staged and --all are alternatives');
|
|
46
|
-
const workspace = (0, layout_1.findWorkspace)(argv);
|
|
47
|
-
if (!(0, git_1.isRepository)(workspace.root))
|
|
48
|
-
throw new errors_1.CliError(`${workspace.root} is not in a git repository`);
|
|
49
|
-
const scope = argv.all ? 'all' : 'staged';
|
|
50
|
-
const result = await (0, guard_1.runGuard)(workspace, scope);
|
|
51
|
-
const { violations } = result;
|
|
52
|
-
const subject = (0, text_1.count)(result.checked, scope === 'all' ? 'tracked file' : 'staged file');
|
|
53
|
-
(0, io_1.emit)(argv, { ok: violations.length === 0, ...result }, () => violations.length
|
|
54
|
-
? violations.map(({ path, message }) => `${path}: ${message}`).join('\n')
|
|
55
|
-
: `dcrypt guard: ${subject} checked, nothing to stop`);
|
|
56
|
-
if (violations.length) {
|
|
57
|
-
throw new errors_1.CliError(`${violations.length} of ${subject} must not be committed (to unstage: git restore --staged <path>)`);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const install = (argv) => {
|
|
61
|
-
const path = (0, guard_1.installHook)((0, layout_1.findWorkspace)(argv), Boolean(argv.force));
|
|
62
|
-
(0, io_1.emit)(argv, { installed: path }, () => `pre-commit guard installed at ${path}`);
|
|
63
|
-
};
|
|
64
|
-
const snippet = (argv) => {
|
|
65
|
-
const { first: name } = (0, dispatch_1.takeFirst)(argv);
|
|
66
|
-
if (!name) {
|
|
67
|
-
const width = Math.max(...Object.keys(snippets_1.SNIPPETS).map((key) => key.length));
|
|
68
|
-
const lines = Object.entries(snippets_1.SNIPPETS).map(([key, { file }]) => `${key.padEnd(width)} ${file}`);
|
|
69
|
-
process.stdout.write(`${lines.join('\n')}\n`);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
if (!(0, snippets_1.isSnippetName)(name)) {
|
|
73
|
-
throw new errors_1.CliError(`unknown snippet "${name}"; there are: ${Object.keys(snippets_1.SNIPPETS).join(', ')}`);
|
|
74
|
-
}
|
|
75
|
-
process.stdout.write(snippets_1.SNIPPETS[name].text);
|
|
76
|
-
};
|
|
77
|
-
const guardCommand = async (argv) => {
|
|
78
|
-
if ((0, dispatch_1.wantsHelp)(argv, exports.guardUsage))
|
|
79
|
-
return;
|
|
80
|
-
const { first: subcommand, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
81
|
-
switch (subcommand) {
|
|
82
|
-
case undefined:
|
|
83
|
-
return check(newArgv);
|
|
84
|
-
case 'install':
|
|
85
|
-
return install(newArgv);
|
|
86
|
-
case 'snippet':
|
|
87
|
-
return snippet(newArgv);
|
|
88
|
-
default:
|
|
89
|
-
throw new errors_1.CliError(`unknown guard subcommand: ${subcommand}`);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
exports.guardCommand = guardCommand;
|
package/commands/keychain.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { ParsedArgs } from 'minimist';
|
|
3
|
-
export declare const keychainUsage = "\nKeychain Command:\n\n dcrypt keychain <subcommand> [name] [OPTIONS]\n\n Store named secrets locally, each encrypted under your passphrase. Values are\n always encrypted \u2014 there is no plaintext mode.\n\nSubcommands:\n set <name> Store a value\n get <name> Print a value\n del <name> Remove a value\n list List entry names (no values)\n\nOptions:\n --in <file> Read the value from a file (\"-\" for stdin)\n --out <file> Write the value to a file instead of stdout\n --kdf <profile> interactive | moderate | sensitive (default: moderate)\n --json Machine-readable output\n --passphrase-file <p> Read the passphrase from a file\n --passphrase-stdin Read the passphrase from stdin\n --help, -h Show this help message\n\nEnvironment:\n KEYCHAIN_ACCOUNT Keychain namespace (default: dcrypt)\n DCRYPT_PASSPHRASE The passphrase, for unattended runs\n\nExamples:\n dcrypt keychain set github-token --in token.txt\n dcrypt keychain get github-token --out token.txt\n dcrypt keychain list\n";
|
|
4
|
-
export declare const keychainCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|
package/commands/keychain.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.keychainCommand = exports.keychainUsage = void 0;
|
|
4
|
-
const core_1 = require("@decryption/core");
|
|
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 encrypt_1 = require("./encrypt");
|
|
11
|
-
exports.keychainUsage = `
|
|
12
|
-
Keychain Command:
|
|
13
|
-
|
|
14
|
-
dcrypt keychain <subcommand> [name] [OPTIONS]
|
|
15
|
-
|
|
16
|
-
Store named secrets locally, each encrypted under your passphrase. Values are
|
|
17
|
-
always encrypted — there is no plaintext mode.
|
|
18
|
-
|
|
19
|
-
Subcommands:
|
|
20
|
-
set <name> Store a value
|
|
21
|
-
get <name> Print a value
|
|
22
|
-
del <name> Remove a value
|
|
23
|
-
list List entry names (no values)
|
|
24
|
-
|
|
25
|
-
Options:
|
|
26
|
-
--in <file> Read the value from a file ("-" for stdin)
|
|
27
|
-
--out <file> Write the value to a file instead of stdout
|
|
28
|
-
--kdf <profile> interactive | moderate | sensitive (default: moderate)
|
|
29
|
-
--json Machine-readable output
|
|
30
|
-
--passphrase-file <p> Read the passphrase from a file
|
|
31
|
-
--passphrase-stdin Read the passphrase from stdin
|
|
32
|
-
--help, -h Show this help message
|
|
33
|
-
|
|
34
|
-
Environment:
|
|
35
|
-
KEYCHAIN_ACCOUNT Keychain namespace (default: dcrypt)
|
|
36
|
-
DCRYPT_PASSPHRASE The passphrase, for unattended runs
|
|
37
|
-
|
|
38
|
-
Examples:
|
|
39
|
-
dcrypt keychain set github-token --in token.txt
|
|
40
|
-
dcrypt keychain get github-token --out token.txt
|
|
41
|
-
dcrypt keychain list
|
|
42
|
-
`;
|
|
43
|
-
const nameFrom = (argv) => {
|
|
44
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
45
|
-
const name = first ?? (typeof argv.name === 'string' ? argv.name : undefined);
|
|
46
|
-
if (!name)
|
|
47
|
-
throw new errors_1.CliError('an entry name is required');
|
|
48
|
-
return { name, newArgv };
|
|
49
|
-
};
|
|
50
|
-
const set = async (argv, prompter) => {
|
|
51
|
-
const { name, newArgv } = nameFrom(argv);
|
|
52
|
-
const { first: inline, newArgv: rest } = (0, dispatch_1.takeFirst)(newArgv);
|
|
53
|
-
const value = (0, io_1.readInput)(rest, inline);
|
|
54
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(rest, prompter, { confirm: true });
|
|
55
|
-
const keychain = (0, stash_1.readKeychain)();
|
|
56
|
-
keychain.entries[name] = (0, core_1.encryptToString)(value, passphrase, {
|
|
57
|
-
aad: `dcrypt-keychain:${name}`,
|
|
58
|
-
kdf: (0, encrypt_1.resolveKdf)(rest.kdf),
|
|
59
|
-
});
|
|
60
|
-
(0, stash_1.writeKeychain)(keychain);
|
|
61
|
-
(0, io_1.emit)(rest, { name, path: (0, stash_1.keychainPath)() }, () => `stored ${name} in ${(0, stash_1.keychainPath)()}`);
|
|
62
|
-
};
|
|
63
|
-
const get = async (argv, prompter) => {
|
|
64
|
-
const { name, newArgv } = nameFrom(argv);
|
|
65
|
-
const entry = (0, stash_1.readKeychain)().entries[name];
|
|
66
|
-
if (!entry)
|
|
67
|
-
throw new errors_1.CliError(`no keychain entry named ${name}`, errors_1.EXIT.notFound);
|
|
68
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(newArgv, prompter);
|
|
69
|
-
(0, io_1.writeOutput)(newArgv, (0, core_1.decryptFromString)(entry, passphrase, { aad: `dcrypt-keychain:${name}` }));
|
|
70
|
-
};
|
|
71
|
-
const del = (argv) => {
|
|
72
|
-
const { name, newArgv } = nameFrom(argv);
|
|
73
|
-
const keychain = (0, stash_1.readKeychain)();
|
|
74
|
-
if (!(name in keychain.entries)) {
|
|
75
|
-
throw new errors_1.CliError(`no keychain entry named ${name}`, errors_1.EXIT.notFound);
|
|
76
|
-
}
|
|
77
|
-
delete keychain.entries[name];
|
|
78
|
-
(0, stash_1.writeKeychain)(keychain);
|
|
79
|
-
(0, io_1.emit)(newArgv, { name, deleted: true }, () => `removed ${name}`);
|
|
80
|
-
};
|
|
81
|
-
const list = (argv) => {
|
|
82
|
-
const names = Object.keys((0, stash_1.readKeychain)().entries).sort();
|
|
83
|
-
(0, io_1.emit)(argv, { entries: names }, () => names.join('\n'));
|
|
84
|
-
};
|
|
85
|
-
const keychainCommand = async (argv, prompter) => {
|
|
86
|
-
await (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
87
|
-
name: 'keychain',
|
|
88
|
-
usage: exports.keychainUsage,
|
|
89
|
-
handlers: { set, get, del, list },
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
exports.keychainCommand = keychainCommand;
|
package/commands/keys.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { ParsedArgs } from 'minimist';
|
|
3
|
-
export declare const keysUsage = "\nKeys Command:\n\n dcrypt keys <subcommand> [OPTIONS]\n\n Manage the X25519 identity used to share team secrets. The private key is stored\n encrypted under a passphrase in ~/.dcrypt/config/identity.json and is never printed.\n\nSubcommands:\n generate Create an identity (use --from-mnemonic to derive it from BIP39 words)\n show Print your public recipient string\n verify Check that your passphrase unlocks the stored identity\n\nOptions:\n --from-mnemonic Derive the identity from a mnemonic instead of random bytes\n --identity-index <n> Which identity to derive from the mnemonic (default: 0)\n --in <file> Read the mnemonic from a file (\"-\" for stdin)\n --force Overwrite an existing identity\n --kdf <profile> interactive | moderate | sensitive (default: moderate)\n --json Machine-readable output\n --passphrase-file <p> Read the passphrase from a file\n --passphrase-stdin Read the passphrase from stdin\n --help, -h Show this help message\n\nExamples:\n dcrypt keys generate\n dcrypt keys generate --from-mnemonic --in mnemonic.txt\n dcrypt keys show\n";
|
|
4
|
-
export declare const keysCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|
package/commands/keys.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.keysCommand = exports.keysUsage = void 0;
|
|
4
|
-
const keys_1 = require("@decryption/keys");
|
|
5
|
-
const wallet_1 = require("@decryption/wallet");
|
|
6
|
-
const dispatch_1 = require("../utils/dispatch");
|
|
7
|
-
const errors_1 = require("../utils/errors");
|
|
8
|
-
const io_1 = require("../utils/io");
|
|
9
|
-
const passphrase_1 = require("../utils/passphrase");
|
|
10
|
-
const stash_1 = require("../utils/stash");
|
|
11
|
-
const encrypt_1 = require("./encrypt");
|
|
12
|
-
exports.keysUsage = `
|
|
13
|
-
Keys Command:
|
|
14
|
-
|
|
15
|
-
dcrypt keys <subcommand> [OPTIONS]
|
|
16
|
-
|
|
17
|
-
Manage the X25519 identity used to share team secrets. The private key is stored
|
|
18
|
-
encrypted under a passphrase in ~/.dcrypt/config/identity.json and is never printed.
|
|
19
|
-
|
|
20
|
-
Subcommands:
|
|
21
|
-
generate Create an identity (use --from-mnemonic to derive it from BIP39 words)
|
|
22
|
-
show Print your public recipient string
|
|
23
|
-
verify Check that your passphrase unlocks the stored identity
|
|
24
|
-
|
|
25
|
-
Options:
|
|
26
|
-
--from-mnemonic Derive the identity from a mnemonic instead of random bytes
|
|
27
|
-
--identity-index <n> Which identity to derive from the mnemonic (default: 0)
|
|
28
|
-
--in <file> Read the mnemonic from a file ("-" for stdin)
|
|
29
|
-
--force Overwrite an existing identity
|
|
30
|
-
--kdf <profile> interactive | moderate | sensitive (default: moderate)
|
|
31
|
-
--json Machine-readable output
|
|
32
|
-
--passphrase-file <p> Read the passphrase from a file
|
|
33
|
-
--passphrase-stdin Read the passphrase from stdin
|
|
34
|
-
--help, -h Show this help message
|
|
35
|
-
|
|
36
|
-
Examples:
|
|
37
|
-
dcrypt keys generate
|
|
38
|
-
dcrypt keys generate --from-mnemonic --in mnemonic.txt
|
|
39
|
-
dcrypt keys show
|
|
40
|
-
`;
|
|
41
|
-
const generate = async (argv, prompter) => {
|
|
42
|
-
if ((0, stash_1.hasIdentity)() && !argv.force) {
|
|
43
|
-
throw new errors_1.CliError(`an identity already exists at ${(0, stash_1.identityPath)()}; pass --force to replace it (anything encrypted to the old one becomes unreadable)`);
|
|
44
|
-
}
|
|
45
|
-
const identity = argv['from-mnemonic'] || argv.fromMnemonic
|
|
46
|
-
? (0, keys_1.identityFromSeed)((0, wallet_1.mnemonicToSeed)((0, io_1.readInput)(argv).trim()), Number(argv['identity-index'] ?? argv.identityIndex ?? 0))
|
|
47
|
-
: (0, keys_1.generateIdentity)();
|
|
48
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(argv, prompter, {
|
|
49
|
-
confirm: true,
|
|
50
|
-
message: 'Passphrase to protect the identity',
|
|
51
|
-
});
|
|
52
|
-
const stored = (0, stash_1.saveIdentity)(identity, passphrase, (0, encrypt_1.resolveKdf)(argv.kdf));
|
|
53
|
-
identity.privateKey.fill(0);
|
|
54
|
-
(0, io_1.emit)(argv, { recipient: stored.recipient, path: (0, stash_1.identityPath)() }, () => [`identity written to ${(0, stash_1.identityPath)()}`, `recipient: ${stored.recipient}`].join('\n'));
|
|
55
|
-
};
|
|
56
|
-
const show = (argv) => {
|
|
57
|
-
const stored = (0, stash_1.readStoredIdentity)();
|
|
58
|
-
(0, io_1.emit)(argv, { recipient: stored.recipient }, () => stored.recipient);
|
|
59
|
-
};
|
|
60
|
-
const verify = async (argv, prompter) => {
|
|
61
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(argv, prompter);
|
|
62
|
-
const identity = (0, stash_1.loadIdentity)(passphrase);
|
|
63
|
-
const recipient = (0, keys_1.recipientToString)(identity.publicKey);
|
|
64
|
-
identity.privateKey.fill(0);
|
|
65
|
-
(0, io_1.emit)(argv, { ok: true, recipient }, () => `ok — ${recipient}`);
|
|
66
|
-
};
|
|
67
|
-
const keysCommand = async (argv, prompter) => {
|
|
68
|
-
await (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
69
|
-
name: 'keys',
|
|
70
|
-
usage: exports.keysUsage,
|
|
71
|
-
handlers: { generate, show, verify },
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
exports.keysCommand = keysCommand;
|
package/commands/passkey.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { ParsedArgs } from 'minimist';
|
|
3
|
-
export declare const passkeyUsage = "\nPasskey Command:\n\n dcrypt passkey <subcommand> [OPTIONS]\n\n Passkeys held in the vault. dcrypt is the authenticator: it makes the key,\n keeps the private half encrypted, and signs the challenges a site sends. A\n passkey signs only for the site it was made for, so it cannot be phished.\n\nSubcommands:\n list [site] List stored passkeys, optionally for one site\n register <site> Create a passkey for a site and print the registration\n assert <site> Sign a sign-in challenge with the site's passkey\n forget <site> Delete a passkey from the vault\n\nOptions:\n --challenge <b64url> The challenge the site issued (or --challenge-stdin)\n --challenge-stdin Read the challenge from stdin\n --origin <url> Origin to sign, defaults to https://<site>\n --user <name> Account name to register (default: the site's account)\n --credential <id> Which passkey, when a site has more than one\n --json Machine-readable output \u2014 what a relying party expects\n --passphrase-file <p> Read the master password from a file\n --help, -h Show this help message\n\nThe response is printed as the JSON a WebAuthn relying party expects, so it can\nbe piped straight into one:\n\n dcrypt passkey register auth.example.com --user dev@example.com \\\n --challenge \"$(cnc webauthn begin-registration)\" --json | cnc webauthn finish\n";
|
|
4
|
-
export declare const passkeyCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|
package/commands/passkey.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.passkeyCommand = exports.passkeyUsage = void 0;
|
|
4
|
-
const webauthn_1 = require("@decryption/webauthn");
|
|
5
|
-
const dispatch_1 = require("../utils/dispatch");
|
|
6
|
-
const errors_1 = require("../utils/errors");
|
|
7
|
-
const io_1 = require("../utils/io");
|
|
8
|
-
const vault_1 = require("./vault");
|
|
9
|
-
exports.passkeyUsage = `
|
|
10
|
-
Passkey Command:
|
|
11
|
-
|
|
12
|
-
dcrypt passkey <subcommand> [OPTIONS]
|
|
13
|
-
|
|
14
|
-
Passkeys held in the vault. dcrypt is the authenticator: it makes the key,
|
|
15
|
-
keeps the private half encrypted, and signs the challenges a site sends. A
|
|
16
|
-
passkey signs only for the site it was made for, so it cannot be phished.
|
|
17
|
-
|
|
18
|
-
Subcommands:
|
|
19
|
-
list [site] List stored passkeys, optionally for one site
|
|
20
|
-
register <site> Create a passkey for a site and print the registration
|
|
21
|
-
assert <site> Sign a sign-in challenge with the site's passkey
|
|
22
|
-
forget <site> Delete a passkey from the vault
|
|
23
|
-
|
|
24
|
-
Options:
|
|
25
|
-
--challenge <b64url> The challenge the site issued (or --challenge-stdin)
|
|
26
|
-
--challenge-stdin Read the challenge from stdin
|
|
27
|
-
--origin <url> Origin to sign, defaults to https://<site>
|
|
28
|
-
--user <name> Account name to register (default: the site's account)
|
|
29
|
-
--credential <id> Which passkey, when a site has more than one
|
|
30
|
-
--json Machine-readable output — what a relying party expects
|
|
31
|
-
--passphrase-file <p> Read the master password from a file
|
|
32
|
-
--help, -h Show this help message
|
|
33
|
-
|
|
34
|
-
The response is printed as the JSON a WebAuthn relying party expects, so it can
|
|
35
|
-
be piped straight into one:
|
|
36
|
-
|
|
37
|
-
dcrypt passkey register auth.example.com --user dev@example.com \\
|
|
38
|
-
--challenge "$(cnc webauthn begin-registration)" --json | cnc webauthn finish
|
|
39
|
-
`;
|
|
40
|
-
const withPasskeys = async (argv, prompter, run) => {
|
|
41
|
-
const vault = await (0, vault_1.openVault)(argv, prompter);
|
|
42
|
-
try {
|
|
43
|
-
await run(new webauthn_1.PasskeyStore(vault), vault);
|
|
44
|
-
}
|
|
45
|
-
finally {
|
|
46
|
-
await vault.lock();
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* The challenge is a public nonce, so unlike a password it is fine in argv —
|
|
51
|
-
* but it is required: signing a challenge the caller invented proves nothing.
|
|
52
|
-
*/
|
|
53
|
-
const resolveChallenge = (argv) => {
|
|
54
|
-
if (argv['challenge-stdin'] || argv.challengeStdin) {
|
|
55
|
-
return (0, io_1.readStdin)().trim();
|
|
56
|
-
}
|
|
57
|
-
const challenge = argv.challenge;
|
|
58
|
-
if (typeof challenge !== 'string' || !challenge.length) {
|
|
59
|
-
throw new errors_1.CliError('a --challenge from the site is required');
|
|
60
|
-
}
|
|
61
|
-
return challenge;
|
|
62
|
-
};
|
|
63
|
-
const resolveOrigin = (argv, rpId) => typeof argv.origin === 'string' && argv.origin.length ? argv.origin : `https://${rpId}`;
|
|
64
|
-
const describe = (record) => `${record.userName.padEnd(28)} ${record.rpId.padEnd(28)} used ${record.signCount}×`;
|
|
65
|
-
const find = async (passkeys, site, credentialId) => {
|
|
66
|
-
const matches = await passkeys.list(site);
|
|
67
|
-
if (!matches.length) {
|
|
68
|
-
throw new errors_1.CliError(`no passkey for "${site}" in the vault`, errors_1.EXIT.notFound);
|
|
69
|
-
}
|
|
70
|
-
if (!credentialId) {
|
|
71
|
-
if (matches.length > 1) {
|
|
72
|
-
throw new errors_1.CliError(`${matches.length} passkeys for "${site}" — name one with --credential <id>`);
|
|
73
|
-
}
|
|
74
|
-
return matches[0];
|
|
75
|
-
}
|
|
76
|
-
const match = matches.find((record) => record.credentialId === credentialId);
|
|
77
|
-
if (!match)
|
|
78
|
-
throw new errors_1.CliError(`no passkey ${credentialId} for "${site}"`, errors_1.EXIT.notFound);
|
|
79
|
-
return match;
|
|
80
|
-
};
|
|
81
|
-
const list = async (argv, prompter) => {
|
|
82
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
83
|
-
await withPasskeys(newArgv, prompter, async (passkeys) => {
|
|
84
|
-
const all = await passkeys.list(first);
|
|
85
|
-
(0, io_1.emit)(newArgv, all, () => all.map(describe).join('\n') || '(no passkeys)');
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
const register = async (argv, prompter) => {
|
|
89
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
90
|
-
if (!first)
|
|
91
|
-
throw new errors_1.CliError('a site is required, e.g. auth.example.com');
|
|
92
|
-
const challenge = resolveChallenge(newArgv);
|
|
93
|
-
const userName = typeof newArgv.user === 'string' ? newArgv.user : first;
|
|
94
|
-
await withPasskeys(newArgv, prompter, async (passkeys) => {
|
|
95
|
-
const { record, response } = await passkeys.register({
|
|
96
|
-
rpId: first,
|
|
97
|
-
origin: resolveOrigin(newArgv, first),
|
|
98
|
-
challenge,
|
|
99
|
-
userName,
|
|
100
|
-
});
|
|
101
|
-
(0, io_1.emit)(newArgv, response, () => `registered ${record.userName} at ${record.rpId} (${record.credentialId})`);
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
const assert = async (argv, prompter) => {
|
|
105
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
106
|
-
if (!first)
|
|
107
|
-
throw new errors_1.CliError('a site is required, e.g. auth.example.com');
|
|
108
|
-
const challenge = resolveChallenge(newArgv);
|
|
109
|
-
const credential = typeof newArgv.credential === 'string' ? newArgv.credential : undefined;
|
|
110
|
-
await withPasskeys(newArgv, prompter, async (passkeys) => {
|
|
111
|
-
const record = await find(passkeys, first, credential);
|
|
112
|
-
const response = await passkeys.assert(record.itemId, {
|
|
113
|
-
origin: resolveOrigin(newArgv, first),
|
|
114
|
-
challenge,
|
|
115
|
-
});
|
|
116
|
-
(0, io_1.emit)(newArgv, response, () => `signed ${first}'s challenge as ${record.userName}`);
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
const forget = async (argv, prompter) => {
|
|
120
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
121
|
-
if (!first)
|
|
122
|
-
throw new errors_1.CliError('a site is required');
|
|
123
|
-
const credential = typeof newArgv.credential === 'string' ? newArgv.credential : undefined;
|
|
124
|
-
await withPasskeys(newArgv, prompter, async (passkeys) => {
|
|
125
|
-
const record = await find(passkeys, first, credential);
|
|
126
|
-
await passkeys.forget(record.itemId);
|
|
127
|
-
(0, io_1.emit)(newArgv, { credentialId: record.credentialId }, () => `forgot ${record.userName}'s passkey for ${record.rpId}`);
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
const passkeyCommand = async (argv, prompter) => (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
131
|
-
name: 'passkey',
|
|
132
|
-
usage: exports.passkeyUsage,
|
|
133
|
-
handlers: { list, register, assert, forget },
|
|
134
|
-
});
|
|
135
|
-
exports.passkeyCommand = passkeyCommand;
|