@interop/did-cli 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/CHANGELOG.md +341 -0
- package/LICENSE.md +21 -0
- package/README.md +1307 -0
- package/dist/commands/did.d.ts +3 -0
- package/dist/commands/did.d.ts.map +1 -0
- package/dist/commands/did.js +605 -0
- package/dist/commands/did.js.map +1 -0
- package/dist/commands/key.d.ts +3 -0
- package/dist/commands/key.d.ts.map +1 -0
- package/dist/commands/key.js +430 -0
- package/dist/commands/key.js.map +1 -0
- package/dist/commands/vc.d.ts +79 -0
- package/dist/commands/vc.d.ts.map +1 -0
- package/dist/commands/vc.js +528 -0
- package/dist/commands/vc.js.map +1 -0
- package/dist/commands/wallet.d.ts +14 -0
- package/dist/commands/wallet.d.ts.map +1 -0
- package/dist/commands/wallet.js +48 -0
- package/dist/commands/wallet.js.map +1 -0
- package/dist/commands/was.d.ts +500 -0
- package/dist/commands/was.d.ts.map +1 -0
- package/dist/commands/was.js +1833 -0
- package/dist/commands/was.js.map +1 -0
- package/dist/commands/zcap.d.ts +85 -0
- package/dist/commands/zcap.d.ts.map +1 -0
- package/dist/commands/zcap.js +447 -0
- package/dist/commands/zcap.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/keys/ecdsa.d.ts +40 -0
- package/dist/keys/ecdsa.d.ts.map +1 -0
- package/dist/keys/ecdsa.js +73 -0
- package/dist/keys/ecdsa.js.map +1 -0
- package/dist/meta.d.ts +164 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/meta.js +286 -0
- package/dist/meta.js.map +1 -0
- package/dist/storage.d.ts +191 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +307 -0
- package/dist/storage.js.map +1 -0
- package/dist/table.d.ts +43 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +61 -0
- package/dist/table.js.map +1 -0
- package/dist/vc/fixtures/welcomeCredential.d.ts +22 -0
- package/dist/vc/fixtures/welcomeCredential.d.ts.map +1 -0
- package/dist/vc/fixtures/welcomeCredential.js +25 -0
- package/dist/vc/fixtures/welcomeCredential.js.map +1 -0
- package/dist/vc/issue.d.ts +24 -0
- package/dist/vc/issue.d.ts.map +1 -0
- package/dist/vc/issue.js +211 -0
- package/dist/vc/issue.js.map +1 -0
- package/dist/vc/registries.d.ts +30 -0
- package/dist/vc/registries.d.ts.map +1 -0
- package/dist/vc/registries.js +53 -0
- package/dist/vc/registries.js.map +1 -0
- package/dist/vc/registryManager.d.ts +25 -0
- package/dist/vc/registryManager.d.ts.map +1 -0
- package/dist/vc/registryManager.js +29 -0
- package/dist/vc/registryManager.js.map +1 -0
- package/dist/vc/suites/expirationSuite.d.ts +23 -0
- package/dist/vc/suites/expirationSuite.d.ts.map +1 -0
- package/dist/vc/suites/expirationSuite.js +84 -0
- package/dist/vc/suites/expirationSuite.js.map +1 -0
- package/dist/vc/suites/issuerDetailsSuite.d.ts +22 -0
- package/dist/vc/suites/issuerDetailsSuite.d.ts.map +1 -0
- package/dist/vc/suites/issuerDetailsSuite.js +69 -0
- package/dist/vc/suites/issuerDetailsSuite.js.map +1 -0
- package/dist/vc/verify.d.ts +46 -0
- package/dist/vc/verify.d.ts.map +1 -0
- package/dist/vc/verify.js +147 -0
- package/dist/vc/verify.js.map +1 -0
- package/dist/was/address.d.ts +44 -0
- package/dist/was/address.d.ts.map +1 -0
- package/dist/was/address.js +98 -0
- package/dist/was/address.js.map +1 -0
- package/dist/was/capability.d.ts +65 -0
- package/dist/was/capability.d.ts.map +1 -0
- package/dist/was/capability.js +108 -0
- package/dist/was/capability.js.map +1 -0
- package/dist/was/client.d.ts +108 -0
- package/dist/was/client.d.ts.map +1 -0
- package/dist/was/client.js +142 -0
- package/dist/was/client.js.map +1 -0
- package/dist/was/io.d.ts +71 -0
- package/dist/was/io.d.ts.map +1 -0
- package/dist/was/io.js +146 -0
- package/dist/was/io.js.map +1 -0
- package/dist/was/registry.d.ts +79 -0
- package/dist/was/registry.d.ts.map +1 -0
- package/dist/was/registry.js +99 -0
- package/dist/was/registry.js.map +1 -0
- package/dist/zcap/create.d.ts +20 -0
- package/dist/zcap/create.d.ts.map +1 -0
- package/dist/zcap/create.js +29 -0
- package/dist/zcap/create.js.map +1 -0
- package/dist/zcap/delegate.d.ts +44 -0
- package/dist/zcap/delegate.d.ts.map +1 -0
- package/dist/zcap/delegate.js +77 -0
- package/dist/zcap/delegate.js.map +1 -0
- package/dist/zcap/encoding.d.ts +17 -0
- package/dist/zcap/encoding.d.ts.map +1 -0
- package/dist/zcap/encoding.js +37 -0
- package/dist/zcap/encoding.js.map +1 -0
- package/dist/zcap/signer.d.ts +20 -0
- package/dist/zcap/signer.d.ts.map +1 -0
- package/dist/zcap/signer.js +62 -0
- package/dist/zcap/signer.js.map +1 -0
- package/dist/zcap/ttl.d.ts +19 -0
- package/dist/zcap/ttl.d.ts.map +1 -0
- package/dist/zcap/ttl.js +40 -0
- package/dist/zcap/ttl.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { decodeSecretKeySeed, generateSecretKeySeed } from '@digitalcredentials/bnid';
|
|
3
|
+
import { Ed25519VerificationKey } from '@interop/ed25519-verification-key';
|
|
4
|
+
import * as EcdsaMultikey from '@interop/ecdsa-multikey';
|
|
5
|
+
import { listCollection, loadFromCollection, loadMetaFromCollection, removeFromCollection, saveMetaToCollection, saveToCollection } from '../storage.js';
|
|
6
|
+
import { mapFingerprintsToDids, parseKeyStorageId, resolveKeyRef } from '../meta.js';
|
|
7
|
+
import { renderTable, truncateMiddle } from '../table.js';
|
|
8
|
+
import { isEcdsaPublicKeyMultibase, normalizeEcdsaCurve, SUPPORTED_ECDSA_CURVES, warnIfNotVcIssuanceCapable } from '../keys/ecdsa.js';
|
|
9
|
+
/**
|
|
10
|
+
* Build the human-readable key type label shown in list/show output, e.g.
|
|
11
|
+
* `ed25519` or `ecdsa-p256`, from a parsed key storage ID.
|
|
12
|
+
*
|
|
13
|
+
* @param options {object}
|
|
14
|
+
* @param [options.type] {string}
|
|
15
|
+
* @param [options.curve] {string}
|
|
16
|
+
* @returns {string}
|
|
17
|
+
*/
|
|
18
|
+
function keyTypeLabel({ type, curve }) {
|
|
19
|
+
if (!type) {
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
return curve ? `${type}-${curve}` : type;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Render the DIDS cell of the key list table: the first associated DID
|
|
26
|
+
* (middle-truncated), with a `(+N)` suffix when the key appears in more.
|
|
27
|
+
*
|
|
28
|
+
* @param options {object}
|
|
29
|
+
* @param options.dids {string[]}
|
|
30
|
+
* @returns {string}
|
|
31
|
+
*/
|
|
32
|
+
function didsCell({ dids }) {
|
|
33
|
+
if (dids.length === 0) {
|
|
34
|
+
return '';
|
|
35
|
+
}
|
|
36
|
+
const first = truncateMiddle({ value: dids[0], maxWidth: 38 });
|
|
37
|
+
return dids.length > 1 ? `${first} (+${dids.length - 1})` : first;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Write the metadata sidecar of a freshly saved key: the creation timestamp,
|
|
41
|
+
* plus the handle and description when given.
|
|
42
|
+
*
|
|
43
|
+
* @param options {object}
|
|
44
|
+
* @param options.storageId {string}
|
|
45
|
+
* @param options.created {string}
|
|
46
|
+
* @param [options.handle] {string}
|
|
47
|
+
* @param [options.description] {string}
|
|
48
|
+
* @returns {Promise<void>}
|
|
49
|
+
*/
|
|
50
|
+
async function writeCreateMeta({ storageId, created, handle, description }) {
|
|
51
|
+
const meta = { created };
|
|
52
|
+
if (handle) {
|
|
53
|
+
meta.handle = handle;
|
|
54
|
+
}
|
|
55
|
+
if (description) {
|
|
56
|
+
meta.description = description;
|
|
57
|
+
}
|
|
58
|
+
await saveMetaToCollection({ collection: 'keys', storageId, meta });
|
|
59
|
+
}
|
|
60
|
+
export function makeKeyCommand() {
|
|
61
|
+
const key = new Command('key').description('Manage cryptographic keys');
|
|
62
|
+
key
|
|
63
|
+
.command('create')
|
|
64
|
+
.description('Create a new key')
|
|
65
|
+
.option('-t, --type <type>', 'key type (supported: ed25519, ecdsa)', 'ed25519')
|
|
66
|
+
.option('--curve <curve>', `ECDSA curve for --type ecdsa (supported: ${SUPPORTED_ECDSA_CURVES})`, 'p256')
|
|
67
|
+
.option('--save', 'save the key to local wallet storage (~/.config/did-cli-wallet/keys/)')
|
|
68
|
+
.option('--handle <handle>', 'short tag for the saved key (requires --save)')
|
|
69
|
+
.option('--description <description>', 'longer description of the saved key (requires --save)')
|
|
70
|
+
.option('--with-seed', 'include the secret key seed in output (generated if SECRET_KEY_SEED is not set)')
|
|
71
|
+
.action(async (options) => {
|
|
72
|
+
if ((options.handle !== undefined || options.description !== undefined) &&
|
|
73
|
+
!options.save) {
|
|
74
|
+
console.error('--handle and --description require --save');
|
|
75
|
+
process.exit(1);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
switch (options.type) {
|
|
79
|
+
case 'ed25519': {
|
|
80
|
+
const envSeed = process.env.SECRET_KEY_SEED;
|
|
81
|
+
const secretKeySeed = options.withSeed
|
|
82
|
+
? (envSeed ?? (await generateSecretKeySeed()))
|
|
83
|
+
: envSeed;
|
|
84
|
+
const seedBytes = secretKeySeed
|
|
85
|
+
? decodeSecretKeySeed({ secretKeySeed })
|
|
86
|
+
: undefined;
|
|
87
|
+
const keyPair = await Ed25519VerificationKey.generate({
|
|
88
|
+
seed: seedBytes
|
|
89
|
+
});
|
|
90
|
+
const exported = await keyPair.export({
|
|
91
|
+
publicKey: true,
|
|
92
|
+
secretKey: true
|
|
93
|
+
});
|
|
94
|
+
if (options.save) {
|
|
95
|
+
const now = new Date();
|
|
96
|
+
const date = now.toISOString().slice(0, 10);
|
|
97
|
+
const rawId = exported.id ?? keyPair.publicKeyMultibase;
|
|
98
|
+
const storageId = `${date}-${options.type}-${rawId}`.replaceAll(':', '_');
|
|
99
|
+
const filePath = await saveToCollection('keys', storageId, exported);
|
|
100
|
+
await writeCreateMeta({
|
|
101
|
+
storageId,
|
|
102
|
+
created: now.toISOString(),
|
|
103
|
+
handle: options.handle,
|
|
104
|
+
description: options.description
|
|
105
|
+
});
|
|
106
|
+
console.error(`Key saved to ${filePath}`);
|
|
107
|
+
}
|
|
108
|
+
const output = options.withSeed
|
|
109
|
+
? { secretKeySeed, keyPair: exported }
|
|
110
|
+
: exported;
|
|
111
|
+
console.log(JSON.stringify(output, null, 2));
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
case 'ecdsa': {
|
|
115
|
+
if (options.withSeed) {
|
|
116
|
+
console.error('--with-seed is not supported for ecdsa keys; ECDSA key ' +
|
|
117
|
+
'generation is non-deterministic and cannot be derived ' +
|
|
118
|
+
'from a seed.');
|
|
119
|
+
process.exit(1);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const curve = normalizeEcdsaCurve({ curve: options.curve });
|
|
123
|
+
if (!curve) {
|
|
124
|
+
console.error(`Unknown ecdsa curve: ${options.curve}. ` +
|
|
125
|
+
`Supported: ${SUPPORTED_ECDSA_CURVES}`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
warnIfNotVcIssuanceCapable({ curve });
|
|
130
|
+
const keyPair = await EcdsaMultikey.generate({ curve });
|
|
131
|
+
const exported = await keyPair.export({
|
|
132
|
+
publicKey: true,
|
|
133
|
+
secretKey: true
|
|
134
|
+
});
|
|
135
|
+
if (options.save) {
|
|
136
|
+
const now = new Date();
|
|
137
|
+
const date = now.toISOString().slice(0, 10);
|
|
138
|
+
const rawId = exported.id ?? exported.publicKeyMultibase;
|
|
139
|
+
const curveLabel = curve.replace('-', '').toLowerCase();
|
|
140
|
+
const storageId = `${date}-ecdsa-${curveLabel}-${rawId}`.replaceAll(':', '_');
|
|
141
|
+
const filePath = await saveToCollection('keys', storageId, exported);
|
|
142
|
+
await writeCreateMeta({
|
|
143
|
+
storageId,
|
|
144
|
+
created: now.toISOString(),
|
|
145
|
+
handle: options.handle,
|
|
146
|
+
description: options.description
|
|
147
|
+
});
|
|
148
|
+
console.error(`Key saved to ${filePath}`);
|
|
149
|
+
}
|
|
150
|
+
console.log(JSON.stringify(exported, null, 2));
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
default:
|
|
154
|
+
console.error(`Unknown key type: ${options.type}. Supported: ed25519, ecdsa`);
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
key
|
|
159
|
+
.command('list')
|
|
160
|
+
.description('List locally stored keys with their metadata')
|
|
161
|
+
.option('--json', 'output the list as a JSON array of objects with metadata')
|
|
162
|
+
.option('--plain', 'output one fingerprint per line, sorted (no metadata)')
|
|
163
|
+
.action(async (options) => {
|
|
164
|
+
const storageIds = await listCollection('keys');
|
|
165
|
+
if (options.plain) {
|
|
166
|
+
const keyIds = [];
|
|
167
|
+
for (const storageId of storageIds) {
|
|
168
|
+
const key = await loadFromCollection('keys', storageId);
|
|
169
|
+
if (key.publicKeyMultibase) {
|
|
170
|
+
keyIds.push(key.publicKeyMultibase);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
keyIds.sort();
|
|
174
|
+
for (const keyId of keyIds) {
|
|
175
|
+
console.log(keyId);
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const fingerprintDids = await mapFingerprintsToDids();
|
|
180
|
+
const entries = [];
|
|
181
|
+
// Storage IDs carry a YYYY-MM-DD prefix, so this order is chronological.
|
|
182
|
+
for (const storageId of storageIds) {
|
|
183
|
+
const key = await loadFromCollection('keys', storageId);
|
|
184
|
+
if (!key.publicKeyMultibase) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const meta = await loadMetaFromCollection({
|
|
188
|
+
collection: 'keys',
|
|
189
|
+
storageId
|
|
190
|
+
});
|
|
191
|
+
const parsed = parseKeyStorageId({ storageId });
|
|
192
|
+
entries.push({
|
|
193
|
+
fingerprint: key.publicKeyMultibase,
|
|
194
|
+
storageId,
|
|
195
|
+
type: parsed.type,
|
|
196
|
+
curve: parsed.curve,
|
|
197
|
+
created: meta?.created ?? parsed.date,
|
|
198
|
+
handle: meta?.handle,
|
|
199
|
+
description: meta?.description,
|
|
200
|
+
dids: fingerprintDids.get(key.publicKeyMultibase) ?? []
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
if (options.json) {
|
|
204
|
+
const output = entries.map(entry => ({
|
|
205
|
+
fingerprint: entry.fingerprint,
|
|
206
|
+
storageId: entry.storageId,
|
|
207
|
+
...(entry.type && { type: entry.type }),
|
|
208
|
+
...(entry.curve && { curve: entry.curve }),
|
|
209
|
+
...(entry.created && { created: entry.created }),
|
|
210
|
+
...(entry.handle && { handle: entry.handle }),
|
|
211
|
+
...(entry.description && { description: entry.description }),
|
|
212
|
+
dids: entry.dids
|
|
213
|
+
}));
|
|
214
|
+
console.log(JSON.stringify(output, null, 2));
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
if (entries.length === 0) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
const rows = entries.map(entry => [
|
|
221
|
+
entry.handle ?? '',
|
|
222
|
+
keyTypeLabel({ type: entry.type, curve: entry.curve }),
|
|
223
|
+
entry.created?.slice(0, 10) ?? '',
|
|
224
|
+
entry.fingerprint,
|
|
225
|
+
didsCell({ dids: entry.dids }),
|
|
226
|
+
entry.description ?? ''
|
|
227
|
+
]);
|
|
228
|
+
console.log(renderTable({
|
|
229
|
+
columns: [
|
|
230
|
+
{ header: 'HANDLE', maxWidth: 16 },
|
|
231
|
+
{ header: 'TYPE' },
|
|
232
|
+
{ header: 'CREATED' },
|
|
233
|
+
{ header: 'FINGERPRINT', maxWidth: 28 },
|
|
234
|
+
{ header: 'DIDS' },
|
|
235
|
+
{ header: 'DESCRIPTION', maxWidth: 40 }
|
|
236
|
+
],
|
|
237
|
+
rows
|
|
238
|
+
}));
|
|
239
|
+
});
|
|
240
|
+
key
|
|
241
|
+
.command('show <id>')
|
|
242
|
+
.aliases(['view', 'cat'])
|
|
243
|
+
.description('Show a locally stored key (public key object only) by its ' +
|
|
244
|
+
'publicKeyMultibase fingerprint or handle')
|
|
245
|
+
.option('--meta', 'show the key metadata instead of the public key object')
|
|
246
|
+
.option('--json', 'with --meta, output the metadata as JSON')
|
|
247
|
+
.action(async (id, options) => {
|
|
248
|
+
let resolved;
|
|
249
|
+
try {
|
|
250
|
+
resolved = await resolveKeyRef({ ref: id });
|
|
251
|
+
}
|
|
252
|
+
catch (err) {
|
|
253
|
+
console.error(err.message);
|
|
254
|
+
process.exit(1);
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (!resolved?.key.publicKeyMultibase) {
|
|
258
|
+
console.error(`No locally stored key found for ${id}`);
|
|
259
|
+
process.exit(1);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
const storedKey = resolved.key;
|
|
263
|
+
if (options.meta) {
|
|
264
|
+
const fingerprint = storedKey.publicKeyMultibase;
|
|
265
|
+
const parsed = parseKeyStorageId({ storageId: resolved.storageId });
|
|
266
|
+
const created = resolved.meta?.created ?? parsed.date;
|
|
267
|
+
// The displayed DIDs are always derived from the stored DID documents,
|
|
268
|
+
// never the cached meta.dids, so they cannot be stale.
|
|
269
|
+
const dids = (await mapFingerprintsToDids()).get(fingerprint) ?? [];
|
|
270
|
+
if (options.json) {
|
|
271
|
+
const output = {
|
|
272
|
+
fingerprint,
|
|
273
|
+
storageId: resolved.storageId,
|
|
274
|
+
...(parsed.type && { type: parsed.type }),
|
|
275
|
+
...(parsed.curve && { curve: parsed.curve }),
|
|
276
|
+
...(created && { created }),
|
|
277
|
+
...(resolved.meta?.handle && { handle: resolved.meta.handle }),
|
|
278
|
+
...(resolved.meta?.description && {
|
|
279
|
+
description: resolved.meta.description
|
|
280
|
+
}),
|
|
281
|
+
dids
|
|
282
|
+
};
|
|
283
|
+
console.log(JSON.stringify(output, null, 2));
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const rows = [
|
|
287
|
+
['Fingerprint', fingerprint],
|
|
288
|
+
['Type', parsed.type ?? ''],
|
|
289
|
+
...(parsed.curve ? [['Curve', parsed.curve]] : []),
|
|
290
|
+
['Created', created ?? ''],
|
|
291
|
+
['Handle', resolved.meta?.handle ?? ''],
|
|
292
|
+
['Description', resolved.meta?.description ?? ''],
|
|
293
|
+
['DIDs', dids.join(', ')]
|
|
294
|
+
];
|
|
295
|
+
console.log(renderTable({
|
|
296
|
+
columns: [{ header: 'FIELD' }, { header: 'VALUE' }],
|
|
297
|
+
rows
|
|
298
|
+
}));
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
// Re-import the stored key pair and re-export the public half only, so the
|
|
302
|
+
// secret key material never leaves storage in the displayed output.
|
|
303
|
+
const isEcdsa = isEcdsaPublicKeyMultibase({
|
|
304
|
+
publicKeyMultibase: storedKey.publicKeyMultibase
|
|
305
|
+
});
|
|
306
|
+
const publicKey = isEcdsa
|
|
307
|
+
? await (await EcdsaMultikey.from(storedKey)).export({
|
|
308
|
+
publicKey: true,
|
|
309
|
+
secretKey: false
|
|
310
|
+
})
|
|
311
|
+
: await (await Ed25519VerificationKey.from(storedKey)).export({
|
|
312
|
+
publicKey: true,
|
|
313
|
+
secretKey: false
|
|
314
|
+
});
|
|
315
|
+
console.log(JSON.stringify(publicKey, null, 2));
|
|
316
|
+
});
|
|
317
|
+
key
|
|
318
|
+
.command('meta <id>')
|
|
319
|
+
.description('Show or edit the metadata of a locally stored key (by fingerprint or ' +
|
|
320
|
+
'handle); with no options, prints the current metadata')
|
|
321
|
+
.option('--handle <handle>', 'set the handle (an empty string clears it)')
|
|
322
|
+
.option('--description <description>', 'set the description (an empty string clears it)')
|
|
323
|
+
.action(async (id, options) => {
|
|
324
|
+
let resolved;
|
|
325
|
+
try {
|
|
326
|
+
resolved = await resolveKeyRef({ ref: id });
|
|
327
|
+
}
|
|
328
|
+
catch (err) {
|
|
329
|
+
console.error(err.message);
|
|
330
|
+
process.exit(1);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
if (!resolved?.key.publicKeyMultibase) {
|
|
334
|
+
console.error(`No locally stored key found for ${id}`);
|
|
335
|
+
process.exit(1);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const fingerprint = resolved.key.publicKeyMultibase;
|
|
339
|
+
const dids = (await mapFingerprintsToDids()).get(fingerprint) ?? [];
|
|
340
|
+
const hasEdits = options.handle !== undefined || options.description !== undefined;
|
|
341
|
+
if (!hasEdits) {
|
|
342
|
+
const output = { ...(resolved.meta ?? {}) };
|
|
343
|
+
// Show the derived associations, not the cached ones.
|
|
344
|
+
if (dids.length > 0) {
|
|
345
|
+
output.dids = dids;
|
|
346
|
+
}
|
|
347
|
+
else {
|
|
348
|
+
delete output.dids;
|
|
349
|
+
}
|
|
350
|
+
console.log(JSON.stringify(output, null, 2));
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
const meta = { ...(resolved.meta ?? {}) };
|
|
354
|
+
if (!meta.created) {
|
|
355
|
+
// Backfill a date-only created from the storage ID's date prefix.
|
|
356
|
+
const { date } = parseKeyStorageId({ storageId: resolved.storageId });
|
|
357
|
+
if (date) {
|
|
358
|
+
meta.created = date;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (options.handle !== undefined) {
|
|
362
|
+
if (options.handle === '') {
|
|
363
|
+
delete meta.handle;
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
meta.handle = options.handle;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (options.description !== undefined) {
|
|
370
|
+
if (options.description === '') {
|
|
371
|
+
delete meta.description;
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
meta.description = options.description;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
// Every write also refreshes the cached key-to-DID associations.
|
|
378
|
+
if (dids.length > 0) {
|
|
379
|
+
meta.dids = dids;
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
delete meta.dids;
|
|
383
|
+
}
|
|
384
|
+
const filePath = await saveMetaToCollection({
|
|
385
|
+
collection: 'keys',
|
|
386
|
+
storageId: resolved.storageId,
|
|
387
|
+
meta
|
|
388
|
+
});
|
|
389
|
+
console.error(`Metadata saved to ${filePath}`);
|
|
390
|
+
console.log(JSON.stringify(meta, null, 2));
|
|
391
|
+
});
|
|
392
|
+
key
|
|
393
|
+
.command('remove <id>')
|
|
394
|
+
.aliases(['delete', 'rm'])
|
|
395
|
+
.description('Remove a locally stored key and its metadata sidecar (by ' +
|
|
396
|
+
'publicKeyMultibase fingerprint or handle)')
|
|
397
|
+
.action(async (id) => {
|
|
398
|
+
let resolved;
|
|
399
|
+
try {
|
|
400
|
+
resolved = await resolveKeyRef({ ref: id });
|
|
401
|
+
}
|
|
402
|
+
catch (err) {
|
|
403
|
+
console.error(err.message);
|
|
404
|
+
process.exit(1);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (!resolved) {
|
|
408
|
+
console.error(`No locally stored key found for ${id}`);
|
|
409
|
+
process.exit(1);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
const removed = await removeFromCollection({
|
|
413
|
+
collection: 'keys',
|
|
414
|
+
storageId: resolved.storageId
|
|
415
|
+
});
|
|
416
|
+
for (const filePath of removed) {
|
|
417
|
+
console.error(`Removed ${filePath}`);
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
key
|
|
421
|
+
.command('export <id>')
|
|
422
|
+
.description('Export a key by ID')
|
|
423
|
+
.option('-f, --format <format>', 'export format (jwk|multibase)', 'jwk')
|
|
424
|
+
.action((keyId, options) => {
|
|
425
|
+
console.error(`Exporting key ${keyId} (format: ${options.format})`);
|
|
426
|
+
// TODO: implement
|
|
427
|
+
});
|
|
428
|
+
return key;
|
|
429
|
+
}
|
|
430
|
+
//# sourceMappingURL=key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/commands/key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC1E,OAAO,KAAK,aAAa,MAAM,yBAAyB,CAAA;AACxD,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAEjB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,aAAa,EACd,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACzD,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC3B,MAAM,kBAAkB,CAAA;AAEzB;;;;;;;;GAQG;AACH,SAAS,YAAY,CAAC,EACpB,IAAI,EACJ,KAAK,EAIN;IACC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,CAAA;IACX,CAAC;IACD,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAA;AAC1C,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,QAAQ,CAAC,EAAE,IAAI,EAAsB;IAC5C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,EAAE,CAAA;IACX,CAAC;IACD,MAAM,KAAK,GAAG,cAAc,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,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QAC7C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAE,GAAa,CAAC,OAAO,CAAC,CAAA;YACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACf,OAAM;QACR,CAAC;QACD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAA;YACtD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACf,OAAM;QACR,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC;YACzC,UAAU,EAAE,MAAM;YAClB,SAAS,EAAE,QAAQ,CAAC,SAAS;SAC9B,CAAC,CAAA;QACF,KAAK,MAAM,QAAQ,IAAI,OAAO,EAAE,CAAC;YAC/B,OAAO,CAAC,KAAK,CAAC,WAAW,QAAQ,EAAE,CAAC,CAAA;QACtC,CAAC;IACH,CAAC,CAAC,CAAA;IAEJ,GAAG;SACA,OAAO,CAAC,aAAa,CAAC;SACtB,WAAW,CAAC,oBAAoB,CAAC;SACjC,MAAM,CAAC,uBAAuB,EAAE,+BAA+B,EAAE,KAAK,CAAC;SACvE,MAAM,CAAC,CAAC,KAAa,EAAE,OAA2B,EAAE,EAAE;QACrD,OAAO,CAAC,KAAK,CAAC,iBAAiB,KAAK,aAAa,OAAO,CAAC,MAAM,GAAG,CAAC,CAAA;QACnE,kBAAkB;IACpB,CAAC,CAAC,CAAA;IAEJ,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { type StoredCredential } from '../meta.js';
|
|
3
|
+
/**
|
|
4
|
+
* Derives a filesystem-safe storage id for a credential: its `id` when it has
|
|
5
|
+
* one (a credential's `id` property is optional), otherwise a digest of its
|
|
6
|
+
* JSON content -- deterministic, so re-importing the same id-less credential
|
|
7
|
+
* overwrites rather than duplicates.
|
|
8
|
+
*
|
|
9
|
+
* @param options {object}
|
|
10
|
+
* @param options.credential {StoredCredential}
|
|
11
|
+
* @returns {string}
|
|
12
|
+
*/
|
|
13
|
+
export declare function credentialStorageId({ credential }: {
|
|
14
|
+
credential: StoredCredential;
|
|
15
|
+
}): string;
|
|
16
|
+
/**
|
|
17
|
+
* Reads, verifies, and prints a credential, returning the process exit code:
|
|
18
|
+
* `0` when verified, `1` when not verified, and `2` on a read/parse error or a
|
|
19
|
+
* structurally malformed credential. Kept separate from the command action so
|
|
20
|
+
* the exit-code logic is directly testable without stubbing `process.exit`.
|
|
21
|
+
*
|
|
22
|
+
* @param file {string | undefined} Path to read, or undefined for stdin.
|
|
23
|
+
* @param options {object}
|
|
24
|
+
* @param [options.summary] {boolean} Print the compact summary instead of the
|
|
25
|
+
* full verifier-core result.
|
|
26
|
+
* @returns {Promise<number>} The process exit code.
|
|
27
|
+
*/
|
|
28
|
+
export declare function runVerify(file: string | undefined, options: {
|
|
29
|
+
summary?: boolean;
|
|
30
|
+
}): Promise<number>;
|
|
31
|
+
/**
|
|
32
|
+
* Reads, issues (signs), and prints a credential, returning the process exit
|
|
33
|
+
* code: `0` when issued, `1` on an issuance error (an unauthorized key, a
|
|
34
|
+
* missing DID or key file, an unknown suite, an issuer that does not match the
|
|
35
|
+
* signing DID, or a signing failure), and `2` on a read/parse error. Kept
|
|
36
|
+
* separate from the command action so the exit-code logic is directly testable
|
|
37
|
+
* without stubbing `process.exit`.
|
|
38
|
+
*
|
|
39
|
+
* @param file {string | undefined} Path to read, or undefined for stdin.
|
|
40
|
+
* @param options {object}
|
|
41
|
+
* @param options.did {string} The id of the stored DID to issue (sign) with.
|
|
42
|
+
* @param [options.key] {string} The verification method id to use.
|
|
43
|
+
* @param [options.suite] {string} The signature suite to use.
|
|
44
|
+
* @param [options.save] {boolean} Save the issued credential to local
|
|
45
|
+
* wallet storage.
|
|
46
|
+
* @param [options.handle] {string} Short tag stored in the metadata sidecar.
|
|
47
|
+
* @param [options.description] {string} Longer description stored in the
|
|
48
|
+
* metadata sidecar.
|
|
49
|
+
* @returns {Promise<number>} The process exit code.
|
|
50
|
+
*/
|
|
51
|
+
export declare function runIssue(file: string | undefined, options: {
|
|
52
|
+
did: string;
|
|
53
|
+
key?: string;
|
|
54
|
+
suite?: string;
|
|
55
|
+
save?: boolean;
|
|
56
|
+
handle?: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
}): Promise<number>;
|
|
59
|
+
/**
|
|
60
|
+
* Reads a credential and stores it in local wallet storage, returning the
|
|
61
|
+
* process exit code: `0` when imported, `1` when the input is not a
|
|
62
|
+
* Verifiable Credential, and `2` on a fetch/read/parse error. Kept separate
|
|
63
|
+
* from the command action so the exit-code logic is directly testable without
|
|
64
|
+
* stubbing `process.exit`.
|
|
65
|
+
*
|
|
66
|
+
* @param source {string | undefined} An http(s) URL or a path to read, or
|
|
67
|
+
* undefined for stdin.
|
|
68
|
+
* @param options {object}
|
|
69
|
+
* @param [options.handle] {string} Short tag stored in the metadata sidecar.
|
|
70
|
+
* @param [options.description] {string} Longer description stored in the
|
|
71
|
+
* metadata sidecar.
|
|
72
|
+
* @returns {Promise<number>} The process exit code.
|
|
73
|
+
*/
|
|
74
|
+
export declare function runImport(source: string | undefined, options: {
|
|
75
|
+
handle?: string;
|
|
76
|
+
description?: string;
|
|
77
|
+
}): Promise<number>;
|
|
78
|
+
export declare function makeVcCommand(): Command;
|
|
79
|
+
//# sourceMappingURL=vc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vc.d.ts","sourceRoot":"","sources":["../../src/commands/vc.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAkBnC,OAAO,EAAwB,KAAK,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAoDxE;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,UAAU,EACX,EAAE;IACD,UAAU,EAAE,gBAAgB,CAAA;CAC7B,GAAG,MAAM,CAQT;AAiGD;;;;;;;;;;;GAWG;AACH,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,GAC7B,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE;IACP,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GACA,OAAO,CAAC,MAAM,CAAC,CA6BjB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,SAAS,CAC7B,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GACjD,OAAO,CAAC,MAAM,CAAC,CAmBjB;AAED,wBAAgB,aAAa,IAAI,OAAO,CAsVvC"}
|