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.
- package/LICENSE +21 -0
- package/README.md +17 -325
- package/index.js +8 -64
- 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/vault.js
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.vaultCommand = exports.openVault = exports.vaultFile = exports.vaultUsage = void 0;
|
|
4
|
-
const vault_1 = require("@decryption/vault");
|
|
5
|
-
const appstash_1 = require("appstash");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
|
-
const path_1 = require("path");
|
|
8
|
-
const dispatch_1 = require("../utils/dispatch");
|
|
9
|
-
const errors_1 = require("../utils/errors");
|
|
10
|
-
const io_1 = require("../utils/io");
|
|
11
|
-
const passphrase_1 = require("../utils/passphrase");
|
|
12
|
-
const stash_1 = require("../utils/stash");
|
|
13
|
-
const encrypt_1 = require("./encrypt");
|
|
14
|
-
exports.vaultUsage = `
|
|
15
|
-
Vault Command:
|
|
16
|
-
|
|
17
|
-
dcrypt vault <subcommand> [OPTIONS]
|
|
18
|
-
|
|
19
|
-
The local encrypted vault, shared with the dcrypt desktop app. The whole
|
|
20
|
-
database is one encrypted file; every value inside is additionally encrypted.
|
|
21
|
-
|
|
22
|
-
Subcommands:
|
|
23
|
-
status Show whether a vault exists and where it lives
|
|
24
|
-
item list List items (titles and kinds, never values)
|
|
25
|
-
item get <title> Print an item's fields (values require --reveal)
|
|
26
|
-
item add <title> Add an item; value read from --in or prompted
|
|
27
|
-
item rm <title> Move an item to the trash
|
|
28
|
-
totp <title> Print the current one-time code for an item
|
|
29
|
-
export Export items as JSON ("--format csv" for CSV)
|
|
30
|
-
import Import items from a JSON export ("--from csv|bitwarden")
|
|
31
|
-
|
|
32
|
-
Options:
|
|
33
|
-
--kind <kind> login | note | card | identity | wallet | totp | ssh_key
|
|
34
|
-
--field <name> Field name for "item add" (default depends on kind)
|
|
35
|
-
--reveal Include secret values in "item get" output
|
|
36
|
-
--format <fmt> Export format: json (default) | csv
|
|
37
|
-
--from <fmt> Import format: json (default) | csv | bitwarden
|
|
38
|
-
--in <file> / --out Read/write files ("-" is stdin/stdout)
|
|
39
|
-
--json Machine-readable output
|
|
40
|
-
--passphrase-file <p> Read the master password from a file
|
|
41
|
-
--passphrase-stdin Read the master password from stdin
|
|
42
|
-
--help, -h Show this help message
|
|
43
|
-
|
|
44
|
-
Examples:
|
|
45
|
-
dcrypt vault item add github --kind login --field password
|
|
46
|
-
dcrypt vault item get github --reveal
|
|
47
|
-
dcrypt vault totp work-email
|
|
48
|
-
dcrypt vault export --out backup.json
|
|
49
|
-
`;
|
|
50
|
-
const KINDS = ['login', 'note', 'card', 'identity', 'wallet', 'totp', 'ssh_key'];
|
|
51
|
-
const vaultFile = () => (0, path_1.join)((0, appstash_1.resolve)((0, stash_1.dirs)(), 'data', 'db'), 'vault.dcrypt');
|
|
52
|
-
exports.vaultFile = vaultFile;
|
|
53
|
-
const openVault = async (argv, prompter) => {
|
|
54
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(argv, prompter, {
|
|
55
|
-
message: 'Master password',
|
|
56
|
-
});
|
|
57
|
-
try {
|
|
58
|
-
return await vault_1.Vault.open({
|
|
59
|
-
file: (0, exports.vaultFile)(),
|
|
60
|
-
passphrase,
|
|
61
|
-
modulePath: (0, vault_1.defaultModulePath)(),
|
|
62
|
-
kdf: (0, encrypt_1.resolveKdf)(argv.kdf),
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
if (error instanceof Error && /passphrase/i.test(error.constructor.name)) {
|
|
67
|
-
throw new errors_1.CliError('wrong master password', errors_1.EXIT.auth);
|
|
68
|
-
}
|
|
69
|
-
throw error;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
exports.openVault = openVault;
|
|
73
|
-
const findItem = async (vault, ref) => {
|
|
74
|
-
const items = await vault.listItems();
|
|
75
|
-
const item = items.find((candidate) => candidate.id === ref) ??
|
|
76
|
-
items.find((candidate) => candidate.title === ref) ??
|
|
77
|
-
items.find((candidate) => candidate.title.toLowerCase() === ref.toLowerCase());
|
|
78
|
-
if (!item)
|
|
79
|
-
throw new errors_1.CliError(`no item named "${ref}"`, errors_1.EXIT.notFound);
|
|
80
|
-
return item;
|
|
81
|
-
};
|
|
82
|
-
const status = async (argv) => {
|
|
83
|
-
const file = (0, exports.vaultFile)();
|
|
84
|
-
(0, io_1.emit)(argv, { exists: (0, fs_1.existsSync)(file), file }, () => (0, fs_1.existsSync)(file) ? `vault: ${file}` : `no vault yet (would be created at ${file})`);
|
|
85
|
-
};
|
|
86
|
-
const itemList = async (argv, prompter) => {
|
|
87
|
-
const vault = await (0, exports.openVault)(argv, prompter);
|
|
88
|
-
try {
|
|
89
|
-
const items = await vault.listItems(typeof argv.kind === 'string' ? { kind: argv.kind } : {});
|
|
90
|
-
(0, io_1.emit)(argv, items.map((item) => ({ id: item.id, kind: item.kind, title: item.title })), () => items.map((item) => `${item.kind.padEnd(9)} ${item.title}`).join('\n') || '(empty)');
|
|
91
|
-
}
|
|
92
|
-
finally {
|
|
93
|
-
await vault.lock();
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const itemGet = async (argv, prompter) => {
|
|
97
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
98
|
-
if (!first)
|
|
99
|
-
throw new errors_1.CliError('an item title is required');
|
|
100
|
-
const vault = await (0, exports.openVault)(newArgv, prompter);
|
|
101
|
-
try {
|
|
102
|
-
const item = await findItem(vault, first);
|
|
103
|
-
const fields = await vault.listFields(item.id);
|
|
104
|
-
const reveal = Boolean(newArgv.reveal);
|
|
105
|
-
const values = {};
|
|
106
|
-
for (const field of fields) {
|
|
107
|
-
values[field.name] =
|
|
108
|
-
reveal || !field.concealed ? await vault.revealField(item.id, field.name) : '(concealed)';
|
|
109
|
-
}
|
|
110
|
-
(0, io_1.emit)(newArgv, { id: item.id, kind: item.kind, title: item.title, fields: values }, () => [`${item.title} (${item.kind})`, ...Object.entries(values).map(([k, v]) => ` ${k}: ${v}`)].join('\n'));
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
await vault.lock();
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
const DEFAULT_FIELD = {
|
|
117
|
-
login: { name: 'password', purpose: 'password' },
|
|
118
|
-
totp: { name: 'seed', purpose: 'totp_seed' },
|
|
119
|
-
wallet: { name: 'mnemonic', purpose: 'mnemonic' },
|
|
120
|
-
ssh_key: { name: 'private_key', purpose: 'private_key' },
|
|
121
|
-
};
|
|
122
|
-
const itemAdd = async (argv, prompter) => {
|
|
123
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
124
|
-
if (!first)
|
|
125
|
-
throw new errors_1.CliError('an item title is required');
|
|
126
|
-
const kind = (typeof newArgv.kind === 'string' ? newArgv.kind : 'login');
|
|
127
|
-
if (!KINDS.includes(kind))
|
|
128
|
-
throw new errors_1.CliError(`unknown kind "${kind}"`);
|
|
129
|
-
const preset = DEFAULT_FIELD[kind] ?? { name: 'value', purpose: 'text' };
|
|
130
|
-
const fieldName = typeof newArgv.field === 'string' ? newArgv.field : preset.name;
|
|
131
|
-
const value = (0, io_1.readInput)(newArgv);
|
|
132
|
-
const vault = await (0, exports.openVault)(newArgv, prompter);
|
|
133
|
-
try {
|
|
134
|
-
const item = await vault.createItem(kind, first);
|
|
135
|
-
await vault.setField(item.id, fieldName, preset.purpose, value.trim());
|
|
136
|
-
(0, io_1.emit)(newArgv, { id: item.id, title: item.title }, () => `added "${item.title}" (${item.id})`);
|
|
137
|
-
}
|
|
138
|
-
finally {
|
|
139
|
-
await vault.lock();
|
|
140
|
-
}
|
|
141
|
-
};
|
|
142
|
-
const itemRm = async (argv, prompter) => {
|
|
143
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
144
|
-
if (!first)
|
|
145
|
-
throw new errors_1.CliError('an item title is required');
|
|
146
|
-
const vault = await (0, exports.openVault)(newArgv, prompter);
|
|
147
|
-
try {
|
|
148
|
-
const item = await findItem(vault, first);
|
|
149
|
-
await vault.trashItem(item.id);
|
|
150
|
-
(0, io_1.emit)(newArgv, { id: item.id }, () => `moved "${item.title}" to trash`);
|
|
151
|
-
}
|
|
152
|
-
finally {
|
|
153
|
-
await vault.lock();
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const itemCommand = async (argv, prompter) => (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
157
|
-
name: 'vault item',
|
|
158
|
-
usage: exports.vaultUsage,
|
|
159
|
-
handlers: { list: itemList, get: itemGet, add: itemAdd, rm: itemRm },
|
|
160
|
-
});
|
|
161
|
-
const totp = async (argv, prompter) => {
|
|
162
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
163
|
-
if (!first)
|
|
164
|
-
throw new errors_1.CliError('an item title is required');
|
|
165
|
-
const vault = await (0, exports.openVault)(newArgv, prompter);
|
|
166
|
-
try {
|
|
167
|
-
const item = await findItem(vault, first);
|
|
168
|
-
const fields = await vault.listFields(item.id);
|
|
169
|
-
if (!fields.some((field) => field.purpose === 'totp_seed')) {
|
|
170
|
-
throw new errors_1.CliError(`"${item.title}" has no one-time-code secret`);
|
|
171
|
-
}
|
|
172
|
-
const numeric = async (name, fallback) => {
|
|
173
|
-
if (!fields.some((field) => field.name === name))
|
|
174
|
-
return fallback;
|
|
175
|
-
const value = Number(await vault.revealField(item.id, name));
|
|
176
|
-
return Number.isInteger(value) && value > 0 ? value : fallback;
|
|
177
|
-
};
|
|
178
|
-
const code = await vault.totpCode(item.id, {
|
|
179
|
-
period: await numeric('period', 30),
|
|
180
|
-
digits: await numeric('digits', 6),
|
|
181
|
-
});
|
|
182
|
-
(0, io_1.emit)(newArgv, { code }, () => code);
|
|
183
|
-
}
|
|
184
|
-
finally {
|
|
185
|
-
await vault.lock();
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
const exportItems = async (vault) => {
|
|
189
|
-
const items = await vault.listItems();
|
|
190
|
-
const result = [];
|
|
191
|
-
for (const item of items) {
|
|
192
|
-
const fields = {};
|
|
193
|
-
for (const field of await vault.listFields(item.id)) {
|
|
194
|
-
fields[field.name] = await vault.revealField(item.id, field.name);
|
|
195
|
-
}
|
|
196
|
-
result.push({
|
|
197
|
-
kind: item.kind,
|
|
198
|
-
title: item.title,
|
|
199
|
-
favorite: item.favorite,
|
|
200
|
-
fields,
|
|
201
|
-
urls: await vault.listUrls(item.id),
|
|
202
|
-
tags: (await vault.listTags(item.id)).map((tag) => tag.name),
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
return result;
|
|
206
|
-
};
|
|
207
|
-
const csvEscape = (value) => /[",\n]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value;
|
|
208
|
-
const exportCommand = async (argv, prompter) => {
|
|
209
|
-
const format = typeof argv.format === 'string' ? argv.format : 'json';
|
|
210
|
-
const vault = await (0, exports.openVault)(argv, prompter);
|
|
211
|
-
try {
|
|
212
|
-
const items = await exportItems(vault);
|
|
213
|
-
let output;
|
|
214
|
-
if (format === 'csv') {
|
|
215
|
-
const rows = items.map((item) => [
|
|
216
|
-
item.title,
|
|
217
|
-
item.kind,
|
|
218
|
-
item.fields.username ?? '',
|
|
219
|
-
item.fields.password ?? item.fields.value ?? '',
|
|
220
|
-
item.urls[0] ?? '',
|
|
221
|
-
item.tags.join(';'),
|
|
222
|
-
]
|
|
223
|
-
.map(csvEscape)
|
|
224
|
-
.join(','));
|
|
225
|
-
output = ['title,kind,username,password,url,tags', ...rows].join('\n') + '\n';
|
|
226
|
-
}
|
|
227
|
-
else if (format === 'json') {
|
|
228
|
-
output = JSON.stringify({ version: 1, items }, null, 2) + '\n';
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
throw new errors_1.CliError(`unknown export format "${format}"`);
|
|
232
|
-
}
|
|
233
|
-
(0, io_1.writeOutput)(argv, output);
|
|
234
|
-
if (argv.out && argv.out !== '-') {
|
|
235
|
-
process.stderr.write('warning: the export contains plaintext secrets — handle with care\n');
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
finally {
|
|
239
|
-
await vault.lock();
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
const parseCsvLine = (line) => {
|
|
243
|
-
const cells = [];
|
|
244
|
-
let current = '';
|
|
245
|
-
let quoted = false;
|
|
246
|
-
for (let i = 0; i < line.length; i++) {
|
|
247
|
-
const char = line[i];
|
|
248
|
-
if (quoted) {
|
|
249
|
-
if (char === '"' && line[i + 1] === '"') {
|
|
250
|
-
current += '"';
|
|
251
|
-
i++;
|
|
252
|
-
}
|
|
253
|
-
else if (char === '"') {
|
|
254
|
-
quoted = false;
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
current += char;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
else if (char === '"') {
|
|
261
|
-
quoted = true;
|
|
262
|
-
}
|
|
263
|
-
else if (char === ',') {
|
|
264
|
-
cells.push(current);
|
|
265
|
-
current = '';
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
current += char;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
cells.push(current);
|
|
272
|
-
return cells;
|
|
273
|
-
};
|
|
274
|
-
const parseImport = (raw, from) => {
|
|
275
|
-
if (from === 'json') {
|
|
276
|
-
const parsed = JSON.parse(raw);
|
|
277
|
-
if (!Array.isArray(parsed.items))
|
|
278
|
-
throw new errors_1.CliError('not a dcrypt vault export');
|
|
279
|
-
return parsed.items.map((item) => ({
|
|
280
|
-
kind: KINDS.includes(item.kind) ? item.kind : 'note',
|
|
281
|
-
title: item.title,
|
|
282
|
-
fields: item.fields ?? {},
|
|
283
|
-
urls: item.urls ?? [],
|
|
284
|
-
tags: item.tags ?? [],
|
|
285
|
-
}));
|
|
286
|
-
}
|
|
287
|
-
if (from === 'bitwarden') {
|
|
288
|
-
const parsed = JSON.parse(raw);
|
|
289
|
-
if (!Array.isArray(parsed.items))
|
|
290
|
-
throw new errors_1.CliError('not a bitwarden export');
|
|
291
|
-
return parsed.items.map((entry) => {
|
|
292
|
-
const fields = {};
|
|
293
|
-
if (entry.login?.username)
|
|
294
|
-
fields.username = entry.login.username;
|
|
295
|
-
if (entry.login?.password)
|
|
296
|
-
fields.password = entry.login.password;
|
|
297
|
-
if (entry.login?.totp)
|
|
298
|
-
fields.seed = entry.login.totp;
|
|
299
|
-
if (entry.notes)
|
|
300
|
-
fields.note = entry.notes;
|
|
301
|
-
return {
|
|
302
|
-
kind: entry.type === 1 ? 'login' : 'note',
|
|
303
|
-
title: entry.name,
|
|
304
|
-
fields,
|
|
305
|
-
urls: entry.login?.uris?.map((u) => u.uri) ?? [],
|
|
306
|
-
tags: [],
|
|
307
|
-
};
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
if (from === 'csv') {
|
|
311
|
-
const [header, ...lines] = raw.trim().split(/\r?\n/);
|
|
312
|
-
const columns = parseCsvLine(header).map((c) => c.trim().toLowerCase());
|
|
313
|
-
return lines.filter(Boolean).map((line) => {
|
|
314
|
-
const cells = parseCsvLine(line);
|
|
315
|
-
const get = (...names) => {
|
|
316
|
-
for (const name of names) {
|
|
317
|
-
const index = columns.indexOf(name);
|
|
318
|
-
if (index >= 0 && cells[index])
|
|
319
|
-
return cells[index];
|
|
320
|
-
}
|
|
321
|
-
return '';
|
|
322
|
-
};
|
|
323
|
-
const fields = {};
|
|
324
|
-
const username = get('username', 'login_username', 'user');
|
|
325
|
-
const password = get('password', 'login_password');
|
|
326
|
-
if (username)
|
|
327
|
-
fields.username = username;
|
|
328
|
-
if (password)
|
|
329
|
-
fields.password = password;
|
|
330
|
-
const url = get('url', 'login_uri', 'website');
|
|
331
|
-
return {
|
|
332
|
-
kind: 'login',
|
|
333
|
-
title: get('title', 'name', 'account') || url || 'imported',
|
|
334
|
-
fields,
|
|
335
|
-
urls: url ? [url] : [],
|
|
336
|
-
tags: [],
|
|
337
|
-
};
|
|
338
|
-
});
|
|
339
|
-
}
|
|
340
|
-
throw new errors_1.CliError(`unknown import format "${from}"`);
|
|
341
|
-
};
|
|
342
|
-
const FIELD_PURPOSE = {
|
|
343
|
-
username: 'username',
|
|
344
|
-
password: 'password',
|
|
345
|
-
seed: 'totp_seed',
|
|
346
|
-
mnemonic: 'mnemonic',
|
|
347
|
-
private_key: 'private_key',
|
|
348
|
-
};
|
|
349
|
-
const importCommand = async (argv, prompter) => {
|
|
350
|
-
const from = typeof argv.from === 'string' ? argv.from : 'json';
|
|
351
|
-
const raw = (0, io_1.readInput)(argv);
|
|
352
|
-
const imported = parseImport(raw, from);
|
|
353
|
-
const vault = await (0, exports.openVault)(argv, prompter);
|
|
354
|
-
try {
|
|
355
|
-
for (const entry of imported) {
|
|
356
|
-
const item = await vault.createItem(entry.kind, entry.title);
|
|
357
|
-
for (const [name, value] of Object.entries(entry.fields)) {
|
|
358
|
-
await vault.setField(item.id, name, FIELD_PURPOSE[name] ?? 'text', value, name !== 'username');
|
|
359
|
-
}
|
|
360
|
-
for (const url of entry.urls)
|
|
361
|
-
await vault.addUrl(item.id, url);
|
|
362
|
-
for (const tag of entry.tags)
|
|
363
|
-
await vault.tagItem(item.id, tag);
|
|
364
|
-
}
|
|
365
|
-
(0, io_1.emit)(argv, { imported: imported.length }, () => `imported ${imported.length} item(s)`);
|
|
366
|
-
}
|
|
367
|
-
finally {
|
|
368
|
-
await vault.lock();
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
const vaultCommand = async (argv, prompter) => (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
372
|
-
name: 'vault',
|
|
373
|
-
usage: exports.vaultUsage,
|
|
374
|
-
handlers: {
|
|
375
|
-
status,
|
|
376
|
-
item: itemCommand,
|
|
377
|
-
totp,
|
|
378
|
-
export: exportCommand,
|
|
379
|
-
import: importCommand,
|
|
380
|
-
},
|
|
381
|
-
});
|
|
382
|
-
exports.vaultCommand = vaultCommand;
|
package/commands/wallet.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { ParsedArgs } from 'minimist';
|
|
3
|
-
export declare const walletUsage: string;
|
|
4
|
-
export declare const walletCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|
|
5
|
-
export declare const isMnemonicValid: (mnemonic: string, options?: import("@decryption/wallet").MnemonicOptions) => boolean;
|
package/commands/wallet.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isMnemonicValid = exports.walletCommand = exports.walletUsage = void 0;
|
|
4
|
-
const core_1 = require("@decryption/core");
|
|
5
|
-
const wallet_1 = require("@decryption/wallet");
|
|
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.walletUsage = `
|
|
13
|
-
Wallet Command:
|
|
14
|
-
|
|
15
|
-
dcrypt wallet <subcommand> [OPTIONS]
|
|
16
|
-
|
|
17
|
-
Create BIP39 wallets and derive addresses. Entirely offline: this command never
|
|
18
|
-
contacts a network, signs a transaction, or queries a balance.
|
|
19
|
-
|
|
20
|
-
Subcommands:
|
|
21
|
-
create Generate a mnemonic and show its addresses
|
|
22
|
-
address Derive an address from an existing mnemonic
|
|
23
|
-
validate Check a mnemonic's wordlist and checksum
|
|
24
|
-
|
|
25
|
-
Options:
|
|
26
|
-
--words <n> 12, 15, 18, 21 or 24 (default: 24)
|
|
27
|
-
--network <id> Network id, repeatable (default: bitcoin)
|
|
28
|
-
--account <n> BIP44 account index (default: 0)
|
|
29
|
-
--index <n> BIP44 address index (default: 0)
|
|
30
|
-
--path <path> Explicit derivation path, overrides --account/--index
|
|
31
|
-
--in <file> Read the mnemonic from a file ("-" for stdin)
|
|
32
|
-
--encrypt Encrypt the new mnemonic and print the envelope instead
|
|
33
|
-
--kdf <profile> interactive | moderate | sensitive (default: moderate)
|
|
34
|
-
--out <file> Write output to a file
|
|
35
|
-
--json Machine-readable output
|
|
36
|
-
--help, -h Show this help message
|
|
37
|
-
|
|
38
|
-
Environment:
|
|
39
|
-
MNEMONIC The mnemonic, for "address" and "validate"
|
|
40
|
-
|
|
41
|
-
Networks:
|
|
42
|
-
${Object.keys(wallet_1.NETWORKS).join(', ')}
|
|
43
|
-
|
|
44
|
-
Examples:
|
|
45
|
-
dcrypt wallet create --words 12 --network bitcoin --network ethereum
|
|
46
|
-
dcrypt wallet create --encrypt --out wallet.dcrypt
|
|
47
|
-
dcrypt wallet address --in mnemonic.txt --network bitcoin --index 3
|
|
48
|
-
MNEMONIC="..." dcrypt wallet address --network ethereum
|
|
49
|
-
echo "$MNEMONIC" | dcrypt wallet validate --in -
|
|
50
|
-
`;
|
|
51
|
-
const networksOf = (argv) => {
|
|
52
|
-
const value = argv.network ?? argv.networks ?? wallet_1.DEFAULT_NETWORK;
|
|
53
|
-
return (Array.isArray(value) ? value : [value]).map(String);
|
|
54
|
-
};
|
|
55
|
-
const derivationOptions = (argv) => ({
|
|
56
|
-
account: argv.account === undefined ? 0 : Number(argv.account),
|
|
57
|
-
index: argv.index === undefined ? 0 : Number(argv.index),
|
|
58
|
-
path: typeof argv.path === 'string' ? argv.path : undefined,
|
|
59
|
-
});
|
|
60
|
-
const create = async (argv, prompter) => {
|
|
61
|
-
const words = Number(argv.words ?? 24);
|
|
62
|
-
if (!(words in wallet_1.WORD_COUNTS)) {
|
|
63
|
-
throw new errors_1.CliError(`--words must be one of ${Object.keys(wallet_1.WORD_COUNTS).join(', ')}`);
|
|
64
|
-
}
|
|
65
|
-
const mnemonic = (0, wallet_1.createMnemonic)(words);
|
|
66
|
-
const accounts = networksOf(argv).map((network) => (0, wallet_1.deriveAccount)(mnemonic, network, derivationOptions(argv)));
|
|
67
|
-
if (argv.encrypt) {
|
|
68
|
-
const passphrase = await (0, passphrase_1.resolvePassphrase)(argv, prompter, {
|
|
69
|
-
confirm: true,
|
|
70
|
-
message: 'Passphrase to encrypt the new mnemonic',
|
|
71
|
-
});
|
|
72
|
-
const envelope = (0, core_1.armor)((0, core_1.encrypt)(mnemonic, passphrase, { kdf: (0, encrypt_1.resolveKdf)(argv.kdf) }));
|
|
73
|
-
(0, io_1.emit)(argv, { accounts, mnemonic: envelope }, () => [...accounts.map((account) => `${account.network}\t${account.address}`), '', envelope].join('\n'));
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
(0, io_1.emit)(argv, { mnemonic, accounts }, () => [
|
|
77
|
-
mnemonic,
|
|
78
|
-
'',
|
|
79
|
-
...accounts.map((account) => `${account.network}\t${account.path}\t${account.address}`),
|
|
80
|
-
].join('\n'));
|
|
81
|
-
};
|
|
82
|
-
const address = async (argv, prompter) => {
|
|
83
|
-
const mnemonic = await readMnemonic(argv, prompter);
|
|
84
|
-
const accounts = networksOf(argv).map((network) => (0, wallet_1.deriveAccount)(mnemonic, network, derivationOptions(argv)));
|
|
85
|
-
(0, io_1.emit)(argv, { accounts }, () => accounts.map((account) => `${account.network}\t${account.path}\t${account.address}`).join('\n'));
|
|
86
|
-
};
|
|
87
|
-
const validate = async (argv, prompter) => {
|
|
88
|
-
const mnemonic = await readMnemonic(argv, prompter);
|
|
89
|
-
if (argv.json) {
|
|
90
|
-
let reason = null;
|
|
91
|
-
try {
|
|
92
|
-
(0, wallet_1.assertValidMnemonic)(mnemonic);
|
|
93
|
-
}
|
|
94
|
-
catch (error) {
|
|
95
|
-
reason = error.message;
|
|
96
|
-
}
|
|
97
|
-
(0, io_1.writeOutput)(argv, JSON.stringify({ valid: reason === null, reason }, null, 2));
|
|
98
|
-
if (reason)
|
|
99
|
-
throw new errors_1.CliError(reason);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
(0, wallet_1.assertValidMnemonic)(mnemonic);
|
|
103
|
-
(0, io_1.writeOutput)(argv, `valid (${mnemonic.split(' ').length} words)`);
|
|
104
|
-
};
|
|
105
|
-
const readMnemonic = async (argv, prompter) => {
|
|
106
|
-
const { first, newArgv } = (0, dispatch_1.takeFirst)(argv);
|
|
107
|
-
if (first || newArgv.in)
|
|
108
|
-
return (0, io_1.readInput)(newArgv, first).trim();
|
|
109
|
-
const envMnemonic = (0, env_1.fromEnv)('mnemonic');
|
|
110
|
-
if (envMnemonic !== undefined)
|
|
111
|
-
return envMnemonic.trim();
|
|
112
|
-
if (!process.stdin.isTTY)
|
|
113
|
-
return (0, io_1.readInput)(newArgv, first).trim();
|
|
114
|
-
const { mnemonic } = await prompter.prompt({}, [
|
|
115
|
-
{ type: 'password', name: 'mnemonic', message: 'Mnemonic', required: true },
|
|
116
|
-
]);
|
|
117
|
-
return String(mnemonic).trim();
|
|
118
|
-
};
|
|
119
|
-
const walletCommand = async (argv, prompter) => {
|
|
120
|
-
if ((0, dispatch_1.wantsHelp)(argv, exports.walletUsage) && !argv._.length)
|
|
121
|
-
return;
|
|
122
|
-
await (0, dispatch_1.runSubcommand)(argv, prompter, {
|
|
123
|
-
name: 'wallet',
|
|
124
|
-
usage: exports.walletUsage,
|
|
125
|
-
handlers: { create, address, validate },
|
|
126
|
-
});
|
|
127
|
-
};
|
|
128
|
-
exports.walletCommand = walletCommand;
|
|
129
|
-
exports.isMnemonicValid = wallet_1.isValidMnemonic;
|
package/commands/workspace.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Inquirerer } from 'inquirerer';
|
|
2
|
-
import { ParsedArgs } from 'minimist';
|
|
3
|
-
export declare const encryptSectionUsage = "\nEncrypt Section Command:\n\n dcrypt encrypt-section <name> [OPTIONS]\n\n Encrypt the folder <name> into <name>.tar.dcrypt, for everyone in recipients.txt.\n One section at a time, and only when you ask.\n\n The bundle is a single encrypted file: the names, sizes and number of the files\n inside it are not visible, only its total size. No passphrase is needed, because\n encrypting uses only public keys. Nothing is rewritten when nothing changed, and\n the bundle is replaced only once the new one is complete.\n\nOptions:\n --force Replace a bundle that changed since this machine last read it\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\nExamples:\n dcrypt encrypt-section finance\n dcrypt encrypt-section clients/northwind\n";
|
|
4
|
-
export declare const decryptWorkspaceUsage = "\nDecrypt Workspace Command:\n\n dcrypt decrypt-workspace [name\u2026] [OPTIONS]\n\n Decrypt every section of the workspace (or only the ones named) with your\n identity. You are asked for its passphrase once, and not at all when every\n section is already up to date.\n\n Each bundle is decrypted into a new folder and checked, file by file, against\n the manifest inside it. Only then does it replace the plaintext. A wrong\n passphrase, a damaged or truncated bundle, or an interrupt changes nothing.\n Plaintext you have edited and not yet encrypted is never replaced without --force.\n\nOptions:\n --force Replace plaintext that has changes the bundle does not have\n --passphrase-file <p> Read the identity passphrase from a file\n --passphrase-stdin Read the identity passphrase from stdin\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\nExamples:\n dcrypt decrypt-workspace\n dcrypt decrypt-workspace finance\n";
|
|
5
|
-
export declare const statusUsage = "\nStatus Command:\n\n dcrypt status [OPTIONS]\n\n Show where each section stands: in sync, plaintext changed and not yet\n encrypted, bundle changed and not yet decrypted, and whether a recipient in\n recipients.txt is missing from a bundle. Needs no passphrase.\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";
|
|
6
|
-
export declare const encryptSectionCommand: (argv: ParsedArgs) => Promise<void>;
|
|
7
|
-
export declare const decryptWorkspaceCommand: (argv: ParsedArgs, prompter: Inquirerer) => Promise<void>;
|
|
8
|
-
export declare const statusCommand: (argv: ParsedArgs) => Promise<void>;
|