@twin.org/identity-cli 0.0.2-next.9 → 0.0.3-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/bin/index.js +1 -1
  2. package/dist/es/cli.js +69 -0
  3. package/dist/es/cli.js.map +1 -0
  4. package/dist/es/commands/identityCreate.js +96 -0
  5. package/dist/es/commands/identityCreate.js.map +1 -0
  6. package/dist/es/commands/identityResolve.js +87 -0
  7. package/dist/es/commands/identityResolve.js.map +1 -0
  8. package/dist/es/commands/proofCreate.js +102 -0
  9. package/dist/es/commands/proofCreate.js.map +1 -0
  10. package/dist/es/commands/proofVerify.js +92 -0
  11. package/dist/es/commands/proofVerify.js.map +1 -0
  12. package/dist/es/commands/serviceAdd.js +112 -0
  13. package/dist/es/commands/serviceAdd.js.map +1 -0
  14. package/dist/es/commands/serviceRemove.js +93 -0
  15. package/dist/es/commands/serviceRemove.js.map +1 -0
  16. package/dist/es/commands/setupCommands.js +66 -0
  17. package/dist/es/commands/setupCommands.js.map +1 -0
  18. package/dist/es/commands/verifiableCredentialCreate.js +113 -0
  19. package/dist/es/commands/verifiableCredentialCreate.js.map +1 -0
  20. package/dist/es/commands/verifiableCredentialRevoke.js +77 -0
  21. package/dist/es/commands/verifiableCredentialRevoke.js.map +1 -0
  22. package/dist/es/commands/verifiableCredentialUnrevoke.js +77 -0
  23. package/dist/es/commands/verifiableCredentialUnrevoke.js.map +1 -0
  24. package/dist/es/commands/verifiableCredentialVerify.js +83 -0
  25. package/dist/es/commands/verifiableCredentialVerify.js.map +1 -0
  26. package/dist/es/commands/verificationMethodAdd.js +140 -0
  27. package/dist/es/commands/verificationMethodAdd.js.map +1 -0
  28. package/dist/es/commands/verificationMethodRemove.js +93 -0
  29. package/dist/es/commands/verificationMethodRemove.js.map +1 -0
  30. package/dist/es/index.js +19 -0
  31. package/dist/es/index.js.map +1 -0
  32. package/dist/es/models/identityConnectorTypes.js +13 -0
  33. package/dist/es/models/identityConnectorTypes.js.map +1 -0
  34. package/dist/es/models/identityResolverConnectorTypes.js +13 -0
  35. package/dist/es/models/identityResolverConnectorTypes.js.map +1 -0
  36. package/dist/locales/en.json +10 -4
  37. package/dist/types/commands/identityCreate.d.ts +1 -1
  38. package/dist/types/commands/identityResolve.d.ts +1 -1
  39. package/dist/types/commands/proofCreate.d.ts +1 -1
  40. package/dist/types/commands/proofVerify.d.ts +1 -1
  41. package/dist/types/commands/serviceAdd.d.ts +1 -1
  42. package/dist/types/commands/serviceRemove.d.ts +1 -1
  43. package/dist/types/commands/setupCommands.d.ts +2 -2
  44. package/dist/types/commands/verifiableCredentialCreate.d.ts +1 -1
  45. package/dist/types/commands/verifiableCredentialRevoke.d.ts +1 -1
  46. package/dist/types/commands/verifiableCredentialUnrevoke.d.ts +1 -1
  47. package/dist/types/commands/verifiableCredentialVerify.d.ts +1 -1
  48. package/dist/types/commands/verificationMethodAdd.d.ts +1 -1
  49. package/dist/types/commands/verificationMethodRemove.d.ts +1 -1
  50. package/dist/types/index.d.ts +16 -16
  51. package/docs/changelog.md +50 -0
  52. package/package.json +8 -10
  53. package/dist/cjs/index.cjs +0 -1248
  54. package/dist/esm/index.mjs +0 -1216
@@ -1,1216 +0,0 @@
1
- import path from 'node:path';
2
- import { fileURLToPath } from 'node:url';
3
- import { CLIOptions, CLIParam, CLIDisplay, CLIUtils, CLIBase } from '@twin.org/cli-core';
4
- import { buildCommandMnemonic, buildCommandAddress } from '@twin.org/crypto-cli';
5
- import { setupWalletConnector, buildCommandFaucet, buildCommandTransfer } from '@twin.org/wallet-cli';
6
- import { I18n, Is, Converter, Urn, StringHelper, GeneralError, Coerce } from '@twin.org/core';
7
- import { VaultConnectorFactory, VaultKeyType } from '@twin.org/vault-models';
8
- import { WalletConnectorFactory } from '@twin.org/wallet-models';
9
- import { Command, Option } from 'commander';
10
- import { MemoryEntityStorageConnector } from '@twin.org/entity-storage-connector-memory';
11
- import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
12
- import { IotaIdentityConnector, IotaIdentityResolverConnector } from '@twin.org/identity-connector-iota';
13
- import { initSchema, EntityStorageVaultConnector } from '@twin.org/vault-connector-entity-storage';
14
- import { DocumentHelper } from '@twin.org/identity-models';
15
- import { ProofTypes, DidVerificationMethodType } from '@twin.org/standards-w3c-did';
16
- import { Jwk } from '@twin.org/web';
17
-
18
- // Copyright 2024 IOTA Stiftung.
19
- // SPDX-License-Identifier: Apache-2.0.
20
- /**
21
- * The identity connector types.
22
- */
23
- // eslint-disable-next-line @typescript-eslint/naming-convention
24
- const IdentityConnectorTypes = {
25
- /**
26
- * IOTA.
27
- */
28
- Iota: "iota"
29
- };
30
-
31
- // Copyright 2024 IOTA Stiftung.
32
- // SPDX-License-Identifier: Apache-2.0.
33
- /**
34
- * The identity resolver connector types.
35
- */
36
- // eslint-disable-next-line @typescript-eslint/naming-convention
37
- const IdentityResolverConnectorTypes = {
38
- /**
39
- * IOTA.
40
- */
41
- Iota: "iota"
42
- };
43
-
44
- // Copyright 2024 IOTA Stiftung.
45
- // SPDX-License-Identifier: Apache-2.0.
46
- /**
47
- * Setup the vault for use in the CLI commands.
48
- */
49
- function setupVault() {
50
- initSchema();
51
- EntityStorageConnectorFactory.register("vault-key", () => new MemoryEntityStorageConnector({
52
- entitySchema: "VaultKey"
53
- }));
54
- EntityStorageConnectorFactory.register("vault-secret", () => new MemoryEntityStorageConnector({
55
- entitySchema: "VaultSecret"
56
- }));
57
- const vaultConnector = new EntityStorageVaultConnector();
58
- VaultConnectorFactory.register("vault", () => vaultConnector);
59
- }
60
- /**
61
- * Setup the identity connector for use in the CLI commands.
62
- * @param options The options for the identity connector.
63
- * @param options.nodeEndpoint The node endpoint.
64
- * @param options.network The network.
65
- * @param options.addressIndex The wallet index.
66
- * @param options.vaultSeedId The vault seed ID.
67
- * @param connector The connector to use.
68
- * @returns The identity connector.
69
- */
70
- function setupIdentityConnector(options, connector) {
71
- connector ??= IdentityConnectorTypes.Iota;
72
- return new IotaIdentityConnector({
73
- config: {
74
- clientOptions: {
75
- url: options.nodeEndpoint
76
- },
77
- network: options.network ?? "",
78
- vaultSeedId: options.vaultSeedId,
79
- walletAddressIndex: options.addressIndex
80
- }
81
- });
82
- }
83
- /**
84
- * Setup the identity resolver connector for use in the CLI commands.
85
- * @param options The options for the identity connector.
86
- * @param options.nodeEndpoint The node endpoint.
87
- * @param options.network The network.
88
- * @param connector The connector to use.
89
- * @returns The identity connector.
90
- */
91
- function setupIdentityResolverConnector(options, connector) {
92
- connector ??= IdentityResolverConnectorTypes.Iota;
93
- return new IotaIdentityResolverConnector({
94
- config: {
95
- clientOptions: {
96
- url: options.nodeEndpoint
97
- },
98
- network: options.network ?? ""
99
- }
100
- });
101
- }
102
-
103
- // Copyright 2024 IOTA Stiftung.
104
- // SPDX-License-Identifier: Apache-2.0.
105
- /**
106
- * Build the identity create command for the CLI.
107
- * @returns The command.
108
- */
109
- function buildCommandIdentityCreate() {
110
- const command = new Command();
111
- command
112
- .name("identity-create")
113
- .summary(I18n.formatMessage("commands.identity-create.summary"))
114
- .description(I18n.formatMessage("commands.identity-create.description"))
115
- .requiredOption(I18n.formatMessage("commands.identity-create.options.seed.param"), I18n.formatMessage("commands.identity-create.options.seed.description"))
116
- .option(I18n.formatMessage("commands.identity-create.options.addressIndex.param"), I18n.formatMessage("commands.identity-create.options.addressIndex.description"), "0");
117
- CLIOptions.output(command, {
118
- noConsole: true,
119
- json: true,
120
- env: true,
121
- mergeJson: true,
122
- mergeEnv: true
123
- });
124
- command
125
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
126
- .choices(Object.values(IdentityConnectorTypes))
127
- .default(IdentityConnectorTypes.Iota))
128
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
129
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
130
- .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
131
- .action(actionCommandIdentityCreate);
132
- return command;
133
- }
134
- /**
135
- * Action the identity create command.
136
- * @param opts The options for the command.
137
- * @param opts.seed The private key for the controller.
138
- * @param opts.connector The connector to perform the operations with.
139
- * @param opts.node The node URL.
140
- * @param opts.network The network to use for connector.
141
- * @param opts.explorer The explorer URL.
142
- */
143
- async function actionCommandIdentityCreate(opts) {
144
- const seed = CLIParam.hexBase64("seed", opts.seed);
145
- const nodeEndpoint = CLIParam.url("node", opts.node);
146
- const network = opts.connector === IdentityConnectorTypes.Iota
147
- ? CLIParam.stringValue("network", opts.network)
148
- : undefined;
149
- const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
150
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
151
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
152
- if (Is.stringValue(network)) {
153
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
154
- }
155
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
156
- CLIDisplay.value(I18n.formatMessage("commands.identity-create.labels.addressIndex"), addressIndex);
157
- CLIDisplay.break();
158
- setupVault();
159
- const vaultSeedId = "local-seed";
160
- const localIdentity = "local";
161
- const vaultConnector = VaultConnectorFactory.get("vault");
162
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
163
- const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
164
- WalletConnectorFactory.register("wallet", () => walletConnector);
165
- const identityConnector = setupIdentityConnector({ nodeEndpoint, vaultSeedId, network, addressIndex }, opts.connector);
166
- CLIDisplay.task(I18n.formatMessage("commands.identity-create.progress.creatingIdentity"));
167
- CLIDisplay.break();
168
- CLIDisplay.spinnerStart();
169
- const document = await identityConnector.createDocument(localIdentity);
170
- CLIDisplay.spinnerStop();
171
- if (opts.console) {
172
- CLIDisplay.value(I18n.formatMessage("commands.identity-create.labels.identity"), document.id);
173
- CLIDisplay.break();
174
- }
175
- if (Is.stringValue(opts?.json)) {
176
- await CLIUtils.writeJsonFile(opts.json, { did: document.id }, opts.mergeJson);
177
- }
178
- if (Is.stringValue(opts?.env)) {
179
- await CLIUtils.writeEnvFile(opts.env, [`DID="${document.id}"`], opts.mergeEnv);
180
- }
181
- if (opts.connector === IdentityConnectorTypes.Iota) {
182
- const didUrn = Urn.fromValidString(document.id);
183
- const didParts = didUrn.parts();
184
- const objectId = didParts[didParts.length - 1];
185
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
186
- }
187
- CLIDisplay.break();
188
- CLIDisplay.done();
189
- }
190
-
191
- // Copyright 2024 IOTA Stiftung.
192
- // SPDX-License-Identifier: Apache-2.0.
193
- /**
194
- * Build the identity resolve command for the CLI.
195
- * @returns The command.
196
- */
197
- function buildCommandIdentityResolve() {
198
- const command = new Command();
199
- command
200
- .name("identity-resolve")
201
- .summary(I18n.formatMessage("commands.identity-resolve.summary"))
202
- .description(I18n.formatMessage("commands.identity-resolve.description"))
203
- .requiredOption(I18n.formatMessage("commands.identity-resolve.options.did.param"), I18n.formatMessage("commands.identity-resolve.options.did.description"));
204
- CLIOptions.output(command, {
205
- noConsole: true,
206
- json: true,
207
- env: false,
208
- mergeJson: true,
209
- mergeEnv: false
210
- });
211
- command
212
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
213
- .choices(Object.values(IdentityConnectorTypes))
214
- .default(IdentityConnectorTypes.Iota))
215
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
216
- .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
217
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
218
- .action(actionCommandIdentityResolve);
219
- return command;
220
- }
221
- /**
222
- * Action the identity resolve command.
223
- * @param opts The options for the command.
224
- * @param opts.did The identity to resolve.
225
- * @param opts.connector The connector to perform the operations with.
226
- * @param opts.node The node URL.
227
- * @param opts.network The network to use for connector.
228
- * @param opts.explorer The explorer URL.
229
- */
230
- async function actionCommandIdentityResolve(opts) {
231
- const did = CLIParam.stringValue("did", opts.did);
232
- const nodeEndpoint = CLIParam.url("node", opts.node);
233
- const network = opts.connector === IdentityConnectorTypes.Iota
234
- ? CLIParam.stringValue("network", opts.network)
235
- : undefined;
236
- const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
237
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
238
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
239
- if (Is.stringValue(network)) {
240
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
241
- }
242
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
243
- CLIDisplay.break();
244
- setupVault();
245
- const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
246
- WalletConnectorFactory.register("wallet", () => walletConnector);
247
- const identityResolverConnector = setupIdentityResolverConnector({ nodeEndpoint, network }, opts.connector);
248
- CLIDisplay.task(I18n.formatMessage("commands.identity-resolve.progress.resolvingIdentity"));
249
- CLIDisplay.break();
250
- CLIDisplay.spinnerStart();
251
- const document = await identityResolverConnector.resolveDocument(did);
252
- CLIDisplay.spinnerStop();
253
- if (opts.console) {
254
- CLIDisplay.section(I18n.formatMessage("commands.identity-resolve.labels.didDocument"));
255
- CLIDisplay.json(document);
256
- CLIDisplay.break();
257
- }
258
- if (Is.stringValue(opts?.json)) {
259
- await CLIUtils.writeJsonFile(opts.json, document, opts.mergeJson);
260
- }
261
- if (opts.connector === IdentityConnectorTypes.Iota) {
262
- const didUrn = Urn.fromValidString(document.id);
263
- const didParts = didUrn.parts();
264
- const objectId = didParts[didParts.length - 1];
265
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
266
- }
267
- CLIDisplay.break();
268
- CLIDisplay.done();
269
- }
270
-
271
- // Copyright 2024 IOTA Stiftung.
272
- // SPDX-License-Identifier: Apache-2.0.
273
- /**
274
- * Build the proof create command for the CLI.
275
- * @returns The command.
276
- */
277
- function buildCommandProofCreate() {
278
- const command = new Command();
279
- command
280
- .name("proof-create")
281
- .summary(I18n.formatMessage("commands.proof-create.summary"))
282
- .description(I18n.formatMessage("commands.proof-create.description"))
283
- .requiredOption(I18n.formatMessage("commands.proof-create.options.id.param"), I18n.formatMessage("commands.proof-create.options.id.description"))
284
- .requiredOption(I18n.formatMessage("commands.proof-create.options.private-key.param"), I18n.formatMessage("commands.proof-create.options.private-key.description"))
285
- .requiredOption(I18n.formatMessage("commands.proof-create.options.document-filename.param"), I18n.formatMessage("commands.proof-create.options.document-filename.description"))
286
- .option(I18n.formatMessage("commands.proof-create.options.addressIndex.param"), I18n.formatMessage("commands.proof-create.options.addressIndex.description"), "0");
287
- CLIOptions.output(command, {
288
- noConsole: true,
289
- json: true,
290
- env: true,
291
- mergeJson: true,
292
- mergeEnv: true
293
- });
294
- command
295
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
296
- .choices(Object.values(IdentityConnectorTypes))
297
- .default(IdentityConnectorTypes.Iota))
298
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
299
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
300
- .action(actionCommandProofCreate);
301
- return command;
302
- }
303
- /**
304
- * Action the proof create command.
305
- * @param opts The options for the command.
306
- * @param opts.id The id of the verification method to use for the credential.
307
- * @param opts.privateKey The private key for the verification method.
308
- * @param opts.documentFilename The filename of the document to create the proof for.
309
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
310
- * @param opts.data The data to create the proof for.
311
- * @param opts.connector The connector to perform the operations with.
312
- * @param opts.node The node URL.
313
- * @param opts.network The network to use for connector.
314
- */
315
- async function actionCommandProofCreate(opts) {
316
- const id = CLIParam.stringValue("id", opts.id);
317
- const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
318
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
319
- const documentFilename = path.resolve(CLIParam.stringValue("document-filename", opts.documentFilename));
320
- const nodeEndpoint = CLIParam.url("node", opts.node);
321
- const network = opts.connector === IdentityConnectorTypes.Iota
322
- ? CLIParam.stringValue("network", opts.network)
323
- : undefined;
324
- CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.verificationMethodId"), id);
325
- CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.documentFilename"), documentFilename);
326
- CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.addressIndex"), addressIndex);
327
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
328
- if (Is.stringValue(network)) {
329
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
330
- }
331
- CLIDisplay.break();
332
- setupVault();
333
- const localIdentity = "local";
334
- const vmParts = DocumentHelper.parseId(id);
335
- const vaultConnector = VaultConnectorFactory.get("vault");
336
- await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
337
- const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
338
- WalletConnectorFactory.register("wallet", () => walletConnector);
339
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex }, opts.connector);
340
- CLIDisplay.task(I18n.formatMessage("commands.proof-create.progress.creatingProof"));
341
- CLIDisplay.break();
342
- CLIDisplay.spinnerStart();
343
- const document = await CLIUtils.readJsonFile(documentFilename);
344
- if (Is.undefined(document)) {
345
- throw new GeneralError("commands", "commands.proof-create.documentJsonFileNotFound");
346
- }
347
- const proof = await identityConnector.createProof(localIdentity, id, ProofTypes.DataIntegrityProof, document);
348
- CLIDisplay.spinnerStop();
349
- if (opts.console) {
350
- CLIDisplay.json(proof);
351
- CLIDisplay.break();
352
- }
353
- if (Is.stringValue(opts?.json)) {
354
- await CLIUtils.writeJsonFile(opts.json, proof, opts.mergeJson);
355
- }
356
- if (Is.stringValue(opts?.env)) {
357
- await CLIUtils.writeEnvFile(opts.env, [`DID_PROOF='${JSON.stringify(proof)}'`], opts.mergeEnv);
358
- }
359
- CLIDisplay.done();
360
- }
361
-
362
- // Copyright 2024 IOTA Stiftung.
363
- // SPDX-License-Identifier: Apache-2.0.
364
- /**
365
- * Build the proof verify command for the CLI.
366
- * @returns The command.
367
- */
368
- function buildCommandProofVerify() {
369
- const command = new Command();
370
- command
371
- .name("proof-verify")
372
- .summary(I18n.formatMessage("commands.proof-verify.summary"))
373
- .description(I18n.formatMessage("commands.proof-verify.description"))
374
- .requiredOption(I18n.formatMessage("commands.proof-verify.options.document-filename.param"), I18n.formatMessage("commands.proof-verify.options.document-filename.description"))
375
- .requiredOption(I18n.formatMessage("commands.proof-verify.options.proof-filename.param"), I18n.formatMessage("commands.proof-verify.options.proof-filename.description"));
376
- CLIOptions.output(command, {
377
- noConsole: true,
378
- json: true,
379
- env: true,
380
- mergeJson: true,
381
- mergeEnv: true
382
- });
383
- command
384
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
385
- .choices(Object.values(IdentityConnectorTypes))
386
- .default(IdentityConnectorTypes.Iota))
387
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
388
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
389
- .action(actionCommandProofVerify);
390
- return command;
391
- }
392
- /**
393
- * Action the proof verify command.
394
- * @param opts The options for the command.
395
- * @param opts.id The id of the verification method to use for the credential.
396
- * @param opts.documentFilename The data to verify the proof for.
397
- * @param opts.proofFilename The proof value.
398
- * @param opts.connector The connector to perform the operations with.
399
- * @param opts.node The node URL.
400
- * @param opts.network The network to use for connector.
401
- */
402
- async function actionCommandProofVerify(opts) {
403
- const documentFilename = path.resolve(CLIParam.stringValue("document-filename", opts.documentFilename));
404
- const proofFilename = path.resolve(CLIParam.stringValue("proof-filename", opts.proofFilename));
405
- const nodeEndpoint = CLIParam.url("node", opts.node);
406
- const network = opts.connector === IdentityConnectorTypes.Iota
407
- ? CLIParam.stringValue("network", opts.network)
408
- : undefined;
409
- CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.documentFilename"), documentFilename);
410
- CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.proofFilename"), proofFilename);
411
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
412
- if (Is.stringValue(network)) {
413
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
414
- }
415
- CLIDisplay.break();
416
- setupVault();
417
- const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
418
- WalletConnectorFactory.register("wallet", () => walletConnector);
419
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
420
- CLIDisplay.task(I18n.formatMessage("commands.proof-verify.progress.verifyingProof"));
421
- CLIDisplay.break();
422
- CLIDisplay.spinnerStart();
423
- const document = await CLIUtils.readJsonFile(documentFilename);
424
- if (Is.undefined(document)) {
425
- throw new GeneralError("commands", "commands.proof-verify.documentJsonFileNotFound");
426
- }
427
- const proof = await CLIUtils.readJsonFile(proofFilename);
428
- if (Is.undefined(proof)) {
429
- throw new GeneralError("commands", "commands.proof-verify.proofJsonFileNotFound");
430
- }
431
- const isVerified = await identityConnector.verifyProof(document, proof);
432
- CLIDisplay.spinnerStop();
433
- if (opts.console) {
434
- CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.isVerified"), isVerified);
435
- CLIDisplay.break();
436
- }
437
- if (Is.stringValue(opts?.json)) {
438
- await CLIUtils.writeJsonFile(opts.json, { isVerified }, opts.mergeJson);
439
- }
440
- if (Is.stringValue(opts?.env)) {
441
- await CLIUtils.writeEnvFile(opts.env, [`DID_PROOF_VERIFIED="${isVerified}"`], opts.mergeEnv);
442
- }
443
- CLIDisplay.done();
444
- }
445
-
446
- // Copyright 2024 IOTA Stiftung.
447
- // SPDX-License-Identifier: Apache-2.0.
448
- /**
449
- * Build the service add command for the CLI.
450
- * @returns The command.
451
- */
452
- function buildCommandServiceAdd() {
453
- const command = new Command();
454
- command
455
- .name("service-add")
456
- .summary(I18n.formatMessage("commands.service-add.summary"))
457
- .description(I18n.formatMessage("commands.service-add.description"))
458
- .requiredOption(I18n.formatMessage("commands.service-add.options.seed.param"), I18n.formatMessage("commands.service-add.options.seed.description"))
459
- .requiredOption(I18n.formatMessage("commands.service-add.options.did.param"), I18n.formatMessage("commands.service-add.options.did.description"))
460
- .requiredOption(I18n.formatMessage("commands.service-add.options.id.param"), I18n.formatMessage("commands.service-add.options.id.description"))
461
- .requiredOption(I18n.formatMessage("commands.service-add.options.type.param"), I18n.formatMessage("commands.service-add.options.type.description"))
462
- .requiredOption(I18n.formatMessage("commands.service-add.options.endpoint.param"), I18n.formatMessage("commands.service-add.options.endpoint.description"))
463
- .option(I18n.formatMessage("commands.service-add.options.addressIndex.param"), I18n.formatMessage("commands.service-add.options.addressIndex.description"), "0");
464
- CLIOptions.output(command, {
465
- noConsole: true,
466
- json: true,
467
- env: true,
468
- mergeJson: true,
469
- mergeEnv: true
470
- });
471
- command
472
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
473
- .choices(Object.values(IdentityConnectorTypes))
474
- .default(IdentityConnectorTypes.Iota))
475
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
476
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
477
- .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
478
- .action(actionCommandServiceAdd);
479
- return command;
480
- }
481
- /**
482
- * Action the service add command.
483
- * @param opts The options for the command.
484
- * @param opts.seed The private key for the controller.
485
- * @param opts.did The identity of the document to add to.
486
- * @param opts.id The id of the service to add.
487
- * @param opts.type The type of the service to add.
488
- * @param opts.endpoint The service endpoint.
489
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
490
- * @param opts.connector The connector to perform the operations with.
491
- * @param opts.node The node URL.
492
- * @param opts.explorer The explorer URL.
493
- */
494
- async function actionCommandServiceAdd(opts) {
495
- const seed = CLIParam.hexBase64("seed", opts.seed);
496
- const did = CLIParam.stringValue("did", opts.did);
497
- const id = CLIParam.stringValue("id", opts.id);
498
- const type = CLIParam.stringValue("type", opts.type);
499
- const endpoint = CLIParam.url("endpoint", opts.endpoint);
500
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
501
- const nodeEndpoint = CLIParam.url("node", opts.node);
502
- const network = opts.connector === IdentityConnectorTypes.Iota
503
- ? CLIParam.stringValue("network", opts.network)
504
- : undefined;
505
- const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
506
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
507
- CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceId"), id);
508
- CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceType"), type);
509
- CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.serviceEndpoint"), endpoint);
510
- CLIDisplay.value(I18n.formatMessage("commands.service-add.labels.addressIndex"), addressIndex);
511
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
512
- if (Is.stringValue(network)) {
513
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
514
- }
515
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
516
- CLIDisplay.break();
517
- setupVault();
518
- const vaultSeedId = "local-seed";
519
- const localIdentity = "local";
520
- const vaultConnector = VaultConnectorFactory.get("vault");
521
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
522
- const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
523
- WalletConnectorFactory.register("wallet", () => walletConnector);
524
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
525
- CLIDisplay.task(I18n.formatMessage("commands.service-add.progress.addingService"));
526
- CLIDisplay.break();
527
- CLIDisplay.spinnerStart();
528
- const service = await identityConnector.addService(localIdentity, did, id, type, endpoint);
529
- CLIDisplay.spinnerStop();
530
- if (Is.stringValue(opts?.json)) {
531
- await CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);
532
- }
533
- if (Is.stringValue(opts?.env)) {
534
- await CLIUtils.writeEnvFile(opts.env, [
535
- `DID_SERVICE_ID="${service.id}"`,
536
- `DID_SERVICE_TYPE="${service.type}"`,
537
- `DID_SERVICE_ENDPOINT="${service.serviceEndpoint}"`
538
- ], opts.mergeEnv);
539
- }
540
- if (opts.connector === IdentityConnectorTypes.Iota) {
541
- const didUrn = Urn.fromValidString(did);
542
- const didParts = didUrn.parts();
543
- const objectId = didParts[didParts.length - 1];
544
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
545
- }
546
- CLIDisplay.break();
547
- CLIDisplay.done();
548
- }
549
-
550
- // Copyright 2024 IOTA Stiftung.
551
- // SPDX-License-Identifier: Apache-2.0.
552
- /**
553
- * Build the service remove command for the CLI.
554
- * @returns The command.
555
- */
556
- function buildCommandServiceRemove() {
557
- const command = new Command();
558
- command
559
- .name("service-remove")
560
- .summary(I18n.formatMessage("commands.service-remove.summary"))
561
- .description(I18n.formatMessage("commands.service-remove.description"))
562
- .requiredOption(I18n.formatMessage("commands.service-remove.options.seed.param"), I18n.formatMessage("commands.service-remove.options.seed.description"))
563
- .requiredOption(I18n.formatMessage("commands.service-remove.options.id.param"), I18n.formatMessage("commands.service-remove.options.id.description"))
564
- .option(I18n.formatMessage("commands.service-remove.options.addressIndex.param"), I18n.formatMessage("commands.service-remove.options.addressIndex.description"), "0");
565
- CLIOptions.output(command, {
566
- noConsole: true,
567
- json: true,
568
- env: true,
569
- mergeJson: true,
570
- mergeEnv: true
571
- });
572
- command
573
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
574
- .choices(Object.values(IdentityConnectorTypes))
575
- .default(IdentityConnectorTypes.Iota))
576
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
577
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
578
- .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
579
- .action(actionCommandServiceRemove);
580
- return command;
581
- }
582
- /**
583
- * Action the service remove command.
584
- * @param opts The options for the command.
585
- * @param opts.seed The private key for the controller.
586
- * @param opts.id The id of the service to remove.
587
- * @param opts.connector The connector to perform the operations with.
588
- * @param opts.node The node URL.
589
- * @param opts.network The network to use for connector.
590
- * @param opts.explorer The explorer URL.
591
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
592
- */
593
- async function actionCommandServiceRemove(opts) {
594
- const seed = CLIParam.hexBase64("seed", opts.seed);
595
- const id = CLIParam.stringValue("id", opts.id);
596
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
597
- const nodeEndpoint = CLIParam.url("node", opts.node);
598
- const network = opts.connector === IdentityConnectorTypes.Iota
599
- ? CLIParam.stringValue("network", opts.network)
600
- : undefined;
601
- const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
602
- CLIDisplay.value(I18n.formatMessage("commands.service-remove.labels.serviceId"), id);
603
- CLIDisplay.value(I18n.formatMessage("commands.service-remove.labels.addressIndex"), addressIndex);
604
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
605
- if (Is.stringValue(network)) {
606
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
607
- }
608
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
609
- CLIDisplay.break();
610
- setupVault();
611
- const vaultSeedId = "local-seed";
612
- const localIdentity = "local";
613
- const vaultConnector = VaultConnectorFactory.get("vault");
614
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
615
- const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
616
- WalletConnectorFactory.register("wallet", () => walletConnector);
617
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
618
- CLIDisplay.task(I18n.formatMessage("commands.service-remove.progress.removingService"));
619
- CLIDisplay.break();
620
- CLIDisplay.spinnerStart();
621
- await identityConnector.removeService(localIdentity, id);
622
- CLIDisplay.spinnerStop();
623
- const did = DocumentHelper.parseId(id).id;
624
- if (opts.connector === IdentityConnectorTypes.Iota) {
625
- const didUrn = Urn.fromValidString(did);
626
- const didParts = didUrn.parts();
627
- const objectId = didParts[didParts.length - 1];
628
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
629
- }
630
- CLIDisplay.break();
631
- CLIDisplay.done();
632
- }
633
-
634
- // Copyright 2024 IOTA Stiftung.
635
- // SPDX-License-Identifier: Apache-2.0.
636
- /**
637
- * Build the verifiable credential create command for the CLI.
638
- * @returns The command.
639
- */
640
- function buildCommandVerifiableCredentialCreate() {
641
- const command = new Command();
642
- command
643
- .name("verifiable-credential-create")
644
- .summary(I18n.formatMessage("commands.verifiable-credential-create.summary"))
645
- .description(I18n.formatMessage("commands.verifiable-credential-create.description"))
646
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.id.description"))
647
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.private-key.param"), I18n.formatMessage("commands.verifiable-credential-create.options.private-key.description"))
648
- .option(I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.description"))
649
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.param"), I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.description"))
650
- .option(I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.description"))
651
- .option(I18n.formatMessage("commands.verifiable-credential-create.options.addressIndex.param"), I18n.formatMessage("commands.verifiable-credential-create.options.addressIndex.description"), "0");
652
- CLIOptions.output(command, {
653
- noConsole: true,
654
- json: true,
655
- env: true,
656
- mergeJson: true,
657
- mergeEnv: true
658
- });
659
- command
660
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
661
- .choices(Object.values(IdentityConnectorTypes))
662
- .default(IdentityConnectorTypes.Iota))
663
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
664
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
665
- .action(actionCommandVerifiableCredentialCreate);
666
- return command;
667
- }
668
- /**
669
- * Action the verifiable credential create command.
670
- * @param opts The options for the command.
671
- * @param opts.id The id of the verification method to use for the credential.
672
- * @param opts.privateKey The private key for the verification method.
673
- * @param opts.credentialId The id of the credential.
674
- * @param opts.subjectJson The JSON data for the subject.
675
- * @param opts.revocationIndex The revocation index for the credential.
676
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
677
- * @param opts.connector The connector to perform the operations with.
678
- * @param opts.node The node URL.
679
- */
680
- async function actionCommandVerifiableCredentialCreate(opts) {
681
- const id = CLIParam.stringValue("id", opts.id);
682
- const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
683
- const credentialId = CLIParam.stringValue("credential-id", opts.credentialId);
684
- const subjectJson = path.resolve(CLIParam.stringValue("subject-json", opts.subjectJson));
685
- const revocationIndex = Coerce.number(opts.revocationIndex);
686
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
687
- const nodeEndpoint = CLIParam.url("node", opts.node);
688
- const network = opts.connector === IdentityConnectorTypes.Iota
689
- ? CLIParam.stringValue("network", opts.network)
690
- : undefined;
691
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.verificationMethodId"), id);
692
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.credentialId"), credentialId);
693
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.subjectJson"), subjectJson);
694
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.revocationIndex"), revocationIndex);
695
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.addressIndex"), addressIndex);
696
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
697
- if (Is.stringValue(network)) {
698
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
699
- }
700
- CLIDisplay.break();
701
- setupVault();
702
- const localIdentity = "local";
703
- const vmParts = DocumentHelper.parseId(id);
704
- const vaultConnector = VaultConnectorFactory.get("vault");
705
- await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
706
- const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
707
- WalletConnectorFactory.register("wallet", () => walletConnector);
708
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex }, opts.connector);
709
- CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.loadingSubjectData"));
710
- CLIDisplay.break();
711
- const jsonData = await CLIUtils.readJsonFile(subjectJson);
712
- if (Is.undefined(jsonData)) {
713
- throw new GeneralError("commands", "commands.verifiable-credential-create.subjectJsonFileNotFound");
714
- }
715
- CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.creatingVerifiableCredential"));
716
- CLIDisplay.break();
717
- CLIDisplay.spinnerStart();
718
- const verifiableCredential = await identityConnector.createVerifiableCredential(localIdentity, id, credentialId, jsonData, {
719
- revocationIndex
720
- });
721
- CLIDisplay.spinnerStop();
722
- if (opts.console) {
723
- CLIDisplay.section(I18n.formatMessage("commands.verifiable-credential-create.labels.verifiableCredential"));
724
- CLIDisplay.write(verifiableCredential.jwt);
725
- CLIDisplay.break();
726
- CLIDisplay.break();
727
- }
728
- if (Is.stringValue(opts?.json)) {
729
- await CLIUtils.writeJsonFile(opts.json, { verifiableCredentialJwt: verifiableCredential.jwt }, opts.mergeJson);
730
- }
731
- if (Is.stringValue(opts?.env)) {
732
- await CLIUtils.writeEnvFile(opts.env, [`DID_VERIFIABLE_CREDENTIAL_JWT="${verifiableCredential.jwt}"`], opts.mergeEnv);
733
- }
734
- CLIDisplay.done();
735
- }
736
-
737
- // Copyright 2024 IOTA Stiftung.
738
- // SPDX-License-Identifier: Apache-2.0.
739
- /**
740
- * Build the verifiable credential revoke command for the CLI.
741
- * @returns The command.
742
- */
743
- function buildCommandVerifiableCredentialRevoke() {
744
- const command = new Command();
745
- command
746
- .name("verifiable-credential-revoke")
747
- .summary(I18n.formatMessage("commands.verifiable-credential-revoke.summary"))
748
- .description(I18n.formatMessage("commands.verifiable-credential-revoke.description"))
749
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.seed.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.seed.description"))
750
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.did.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.did.description"))
751
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.description"))
752
- .option(I18n.formatMessage("commands.verifiable-credential-revoke.options.addressIndex.param"), I18n.formatMessage("commands.verifiable-credential-revoke.options.addressIndex.description"), "0");
753
- command
754
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
755
- .choices(Object.values(IdentityConnectorTypes))
756
- .default(IdentityConnectorTypes.Iota))
757
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
758
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
759
- .action(actionCommandVerifiableCredentialRevoke);
760
- return command;
761
- }
762
- /**
763
- * Action the verifiable credential revoke command.
764
- * @param opts The options for the command.
765
- * @param opts.seed The seed to generate the private key for the controller.
766
- * @param opts.did The id of the document to revoke the index.
767
- * @param opts.revocationIndex The revocation index for the credential.
768
- * @param opts.connector The connector to perform the operations with.
769
- * @param opts.node The node URL.
770
- * @param opts.network The network to use for connector.
771
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
772
- */
773
- async function actionCommandVerifiableCredentialRevoke(opts) {
774
- const seed = CLIParam.hexBase64("seed", opts.seed);
775
- const did = CLIParam.stringValue("did", opts.did);
776
- const revocationIndex = CLIParam.integer("revocation-index", opts.revocationIndex);
777
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
778
- const nodeEndpoint = CLIParam.url("node", opts.node);
779
- const network = opts.connector === IdentityConnectorTypes.Iota
780
- ? CLIParam.stringValue("network", opts.network)
781
- : undefined;
782
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
783
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-revoke.labels.revocationIndex"), revocationIndex);
784
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-revoke.labels.addressIndex"), addressIndex);
785
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
786
- if (Is.stringValue(network)) {
787
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
788
- }
789
- CLIDisplay.break();
790
- setupVault();
791
- const vaultSeedId = "local-seed";
792
- const localIdentity = "local";
793
- const vaultConnector = VaultConnectorFactory.get("vault");
794
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
795
- const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
796
- WalletConnectorFactory.register("wallet", () => walletConnector);
797
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
798
- CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-revoke.progress.revokingCredential"));
799
- CLIDisplay.break();
800
- CLIDisplay.spinnerStart();
801
- await identityConnector.revokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
802
- CLIDisplay.spinnerStop();
803
- CLIDisplay.done();
804
- }
805
-
806
- // Copyright 2024 IOTA Stiftung.
807
- // SPDX-License-Identifier: Apache-2.0.
808
- /**
809
- * Build the verifiable credential unrevoke command for the CLI.
810
- * @returns The command.
811
- */
812
- function buildCommandVerifiableCredentialUnrevoke() {
813
- const command = new Command();
814
- command
815
- .name("verifiable-credential-unrevoke")
816
- .summary(I18n.formatMessage("commands.verifiable-credential-unrevoke.summary"))
817
- .description(I18n.formatMessage("commands.verifiable-credential-unrevoke.description"))
818
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.seed.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.seed.description"))
819
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.description"))
820
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.description"))
821
- .option(I18n.formatMessage("commands.verifiable-credential-unrevoke.options.addressIndex.param"), I18n.formatMessage("commands.verifiable-credential-unrevoke.options.addressIndex.description"), "0");
822
- command
823
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
824
- .choices(Object.values(IdentityConnectorTypes))
825
- .default(IdentityConnectorTypes.Iota))
826
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
827
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
828
- .action(actionCommandVerifiableCredentialUnrevoke);
829
- return command;
830
- }
831
- /**
832
- * Action the verifiable credential unrevoke command.
833
- * @param opts The options for the command.
834
- * @param opts.seed The seed to generate the private key for the controller.
835
- * @param opts.did The id of the document to unrevoke the index.
836
- * @param opts.revocationIndex The revocation index for the credential.
837
- * @param opts.connector The connector to perform the operations with.
838
- * @param opts.node The node URL.
839
- * @param opts.network The network to use for connector.
840
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
841
- */
842
- async function actionCommandVerifiableCredentialUnrevoke(opts) {
843
- const seed = CLIParam.hexBase64("seed", opts.seed);
844
- const did = CLIParam.stringValue("did", opts.did);
845
- const revocationIndex = CLIParam.integer("revocation-index", opts.revocationIndex);
846
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
847
- const nodeEndpoint = CLIParam.url("node", opts.node);
848
- const network = opts.connector === IdentityConnectorTypes.Iota
849
- ? CLIParam.stringValue("network", opts.network)
850
- : undefined;
851
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
852
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-unrevoke.labels.revocationIndex"), revocationIndex);
853
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-unrevoke.labels.addressIndex"), addressIndex);
854
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
855
- if (Is.stringValue(network)) {
856
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
857
- }
858
- CLIDisplay.break();
859
- setupVault();
860
- const vaultSeedId = "local-seed";
861
- const localIdentity = "local";
862
- const vaultConnector = VaultConnectorFactory.get("vault");
863
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
864
- const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
865
- WalletConnectorFactory.register("wallet", () => walletConnector);
866
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
867
- CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-unrevoke.progress.unrevokingCredential"));
868
- CLIDisplay.break();
869
- CLIDisplay.spinnerStart();
870
- await identityConnector.unrevokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
871
- CLIDisplay.spinnerStop();
872
- CLIDisplay.done();
873
- }
874
-
875
- // Copyright 2024 IOTA Stiftung.
876
- // SPDX-License-Identifier: Apache-2.0.
877
- /**
878
- * Build the verifiable credential verify command for the CLI.
879
- * @returns The command.
880
- */
881
- function buildCommandVerifiableCredentialVerify() {
882
- const command = new Command();
883
- command
884
- .name("verifiable-credential-verify")
885
- .summary(I18n.formatMessage("commands.verifiable-credential-verify.summary"))
886
- .description(I18n.formatMessage("commands.verifiable-credential-verify.description"))
887
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.param"), I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.description"));
888
- CLIOptions.output(command, {
889
- noConsole: true,
890
- json: true,
891
- env: true,
892
- mergeJson: true,
893
- mergeEnv: true
894
- });
895
- command
896
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
897
- .choices(Object.values(IdentityConnectorTypes))
898
- .default(IdentityConnectorTypes.Iota))
899
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
900
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
901
- .action(actionCommandVerifiableCredentialVerify);
902
- return command;
903
- }
904
- /**
905
- * Action the verifiable credential verify command.
906
- * @param opts The options for the command.
907
- * @param opts.jwt The JSON web token for the verifiable credential.
908
- * @param opts.connector The connector to perform the operations with.
909
- * @param opts.node The node URL.
910
- */
911
- async function actionCommandVerifiableCredentialVerify(opts) {
912
- const jwt = CLIParam.stringValue("jwt", opts.jwt);
913
- const nodeEndpoint = CLIParam.url("node", opts.node);
914
- const network = opts.connector === IdentityConnectorTypes.Iota
915
- ? CLIParam.stringValue("network", opts.network)
916
- : undefined;
917
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.jwt"), jwt);
918
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
919
- if (Is.stringValue(network)) {
920
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
921
- }
922
- CLIDisplay.break();
923
- setupVault();
924
- const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
925
- WalletConnectorFactory.register("wallet", () => walletConnector);
926
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
927
- CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-verify.progress.verifyingCredential"));
928
- CLIDisplay.break();
929
- CLIDisplay.spinnerStart();
930
- const verification = await identityConnector.checkVerifiableCredential(jwt);
931
- const isVerified = Is.notEmpty(verification.verifiableCredential);
932
- const isRevoked = verification.revoked;
933
- CLIDisplay.spinnerStop();
934
- if (opts.console) {
935
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.isVerified"), isVerified);
936
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.isRevoked"), isRevoked);
937
- CLIDisplay.break();
938
- }
939
- if (Is.stringValue(opts?.json)) {
940
- await CLIUtils.writeJsonFile(opts.json, { isVerified, isRevoked }, opts.mergeJson);
941
- }
942
- if (Is.stringValue(opts?.env)) {
943
- await CLIUtils.writeEnvFile(opts.env, [
944
- `DID_VERIFIABLE_CREDENTIAL_VERIFIED="${isVerified}"`,
945
- `DID_VERIFIABLE_CREDENTIAL_REVOKED="${isRevoked}"`
946
- ], opts.mergeEnv);
947
- }
948
- CLIDisplay.done();
949
- }
950
-
951
- // Copyright 2024 IOTA Stiftung.
952
- // SPDX-License-Identifier: Apache-2.0.
953
- /**
954
- * Build the verification method add command for the CLI.
955
- * @returns The command.
956
- */
957
- function buildCommandVerificationMethodAdd() {
958
- const command = new Command();
959
- command
960
- .name("verification-method-add")
961
- .summary(I18n.formatMessage("commands.verification-method-add.summary"))
962
- .description(I18n.formatMessage("commands.verification-method-add.description"))
963
- .requiredOption(I18n.formatMessage("commands.verification-method-add.options.seed.param"), I18n.formatMessage("commands.verification-method-add.options.seed.description"))
964
- .requiredOption(I18n.formatMessage("commands.verification-method-add.options.did.param"), I18n.formatMessage("commands.verification-method-add.options.did.description"))
965
- .addOption(new Option(I18n.formatMessage("commands.verification-method-add.options.type.param"), I18n.formatMessage("commands.verification-method-add.options.type.description"))
966
- .choices(Object.values(DidVerificationMethodType))
967
- .makeOptionMandatory())
968
- .option(I18n.formatMessage("commands.verification-method-add.options.id.param"), I18n.formatMessage("commands.verification-method-add.options.id.description"))
969
- .option(I18n.formatMessage("commands.verification-method-add.options.addressIndex.param"), I18n.formatMessage("commands.verification-method-add.options.addressIndex.description"), "0");
970
- CLIOptions.output(command, {
971
- noConsole: true,
972
- json: true,
973
- env: true,
974
- mergeJson: true,
975
- mergeEnv: true
976
- });
977
- command
978
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
979
- .choices(Object.values(IdentityConnectorTypes))
980
- .default(IdentityConnectorTypes.Iota))
981
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
982
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
983
- .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
984
- .action(actionCommandVerificationMethodAdd);
985
- return command;
986
- }
987
- /**
988
- * Action the verification method add command.
989
- * @param opts The options for the command.
990
- * @param opts.seed The private key for the controller.
991
- * @param opts.did The identity of the document to add to.
992
- * @param opts.type The type of the verification method to add.
993
- * @param opts.id The id of the verification method to add.
994
- * @param opts.connector The connector to perform the operations with.
995
- * @param opts.node The node URL.
996
- * @param opts.explorer The explorer URL.
997
- * @param opts.network The network to use for connector.
998
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
999
- */
1000
- async function actionCommandVerificationMethodAdd(opts) {
1001
- const seed = CLIParam.hexBase64("seed", opts.seed);
1002
- const did = CLIParam.stringValue("did", opts.did);
1003
- const type = CLIParam.stringValue("type", opts.type);
1004
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
1005
- const nodeEndpoint = CLIParam.url("node", opts.node);
1006
- const network = opts.connector === IdentityConnectorTypes.Iota
1007
- ? CLIParam.stringValue("network", opts.network)
1008
- : undefined;
1009
- const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
1010
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
1011
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodType"), type);
1012
- if (Is.stringValue(opts.id)) {
1013
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), opts?.id);
1014
- }
1015
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.addressIndex"), addressIndex);
1016
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
1017
- if (Is.stringValue(network)) {
1018
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
1019
- }
1020
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
1021
- CLIDisplay.break();
1022
- setupVault();
1023
- const vaultSeedId = "local-seed";
1024
- const localIdentity = "local";
1025
- const vaultConnector = VaultConnectorFactory.get("vault");
1026
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
1027
- const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
1028
- WalletConnectorFactory.register("wallet", () => walletConnector);
1029
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
1030
- CLIDisplay.task(I18n.formatMessage("commands.verification-method-add.progress.addingVerificationMethod"));
1031
- CLIDisplay.break();
1032
- CLIDisplay.spinnerStart();
1033
- const verificationMethod = await identityConnector.addVerificationMethod(localIdentity, did, type, opts?.id);
1034
- CLIDisplay.spinnerStop();
1035
- const keyParts = DocumentHelper.parseId(verificationMethod.id);
1036
- const keyPair = await vaultConnector.getKey(`${localIdentity}/${keyParts.fragment}`);
1037
- const privateKeyBase64 = Converter.bytesToBase64Url(keyPair.privateKey);
1038
- const publicKeyBase64 = Is.uint8Array(keyPair.publicKey)
1039
- ? Converter.bytesToBase64Url(keyPair.publicKey)
1040
- : "";
1041
- const privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);
1042
- const publicKeyHex = Is.uint8Array(keyPair.publicKey)
1043
- ? Converter.bytesToHex(keyPair.publicKey, true)
1044
- : "";
1045
- const jwk = await Jwk.fromEd25519Private(keyPair.privateKey);
1046
- const kid = await Jwk.generateKid(jwk);
1047
- if (opts.console) {
1048
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), verificationMethod.id);
1049
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.kid"), kid);
1050
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyBase64"), privateKeyBase64);
1051
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.publicKeyBase64"), publicKeyBase64);
1052
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.privateKeyHex"), privateKeyHex);
1053
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-add.labels.publicKeyHex"), publicKeyHex);
1054
- CLIDisplay.break();
1055
- }
1056
- if (Is.stringValue(opts?.json)) {
1057
- await CLIUtils.writeJsonFile(opts.json, {
1058
- kid,
1059
- ...jwk
1060
- }, opts.mergeJson);
1061
- }
1062
- if (Is.stringValue(opts?.env)) {
1063
- await CLIUtils.writeEnvFile(opts.env, [
1064
- `DID_VERIFICATION_METHOD_ID="${verificationMethod.id}"`,
1065
- `DID_VERIFICATION_METHOD_KID="${kid}"`,
1066
- `DID_VERIFICATION_METHOD_PRIVATE_KEY="${privateKeyHex}"`,
1067
- `DID_VERIFICATION_METHOD_PUBLIC_KEY="${publicKeyHex}"`
1068
- ], opts.mergeEnv);
1069
- }
1070
- if (opts.connector === IdentityConnectorTypes.Iota) {
1071
- const didUrn = Urn.fromValidString(did);
1072
- const didParts = didUrn.parts();
1073
- const objectId = didParts[didParts.length - 1];
1074
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
1075
- }
1076
- CLIDisplay.break();
1077
- CLIDisplay.done();
1078
- }
1079
-
1080
- // Copyright 2024 IOTA Stiftung.
1081
- // SPDX-License-Identifier: Apache-2.0.
1082
- /**
1083
- * Build the verification method remove command for the CLI.
1084
- * @returns The command.
1085
- */
1086
- function buildCommandVerificationMethodRemove() {
1087
- const command = new Command();
1088
- command
1089
- .name("verification-method-remove")
1090
- .summary(I18n.formatMessage("commands.verification-method-remove.summary"))
1091
- .description(I18n.formatMessage("commands.verification-method-remove.description"))
1092
- .requiredOption(I18n.formatMessage("commands.verification-method-remove.options.seed.param"), I18n.formatMessage("commands.verification-method-remove.options.seed.description"))
1093
- .requiredOption(I18n.formatMessage("commands.verification-method-remove.options.id.param"), I18n.formatMessage("commands.verification-method-remove.options.id.description"))
1094
- .option(I18n.formatMessage("commands.verification-method-remove.options.addressIndex.param"), I18n.formatMessage("commands.verification-method-remove.options.addressIndex.description"), "0");
1095
- CLIOptions.output(command, {
1096
- noConsole: true,
1097
- json: true,
1098
- env: true,
1099
- mergeJson: true,
1100
- mergeEnv: true
1101
- });
1102
- command
1103
- .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
1104
- .choices(Object.values(IdentityConnectorTypes))
1105
- .default(IdentityConnectorTypes.Iota))
1106
- .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
1107
- .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
1108
- .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
1109
- .action(actionCommandVerificationMethodRemove);
1110
- return command;
1111
- }
1112
- /**
1113
- * Action the verification method remove command.
1114
- * @param opts The options for the command.
1115
- * @param opts.seed The private key for the controller.
1116
- * @param opts.id The id of the verification method to remove.
1117
- * @param opts.connector The connector to perform the operations with.
1118
- * @param opts.node The node URL.
1119
- * @param opts.explorer The explorer URL.
1120
- * @param opts.network The network to use for connector.
1121
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
1122
- */
1123
- async function actionCommandVerificationMethodRemove(opts) {
1124
- const seed = CLIParam.hexBase64("seed", opts.seed);
1125
- const id = CLIParam.stringValue("id", opts.id);
1126
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
1127
- const nodeEndpoint = CLIParam.url("node", opts.node);
1128
- const network = opts.connector === IdentityConnectorTypes.Iota
1129
- ? CLIParam.stringValue("network", opts.network)
1130
- : undefined;
1131
- const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
1132
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-remove.labels.verificationMethodId"), id);
1133
- CLIDisplay.value(I18n.formatMessage("commands.verification-method-remove.labels.addressIndex"), addressIndex);
1134
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
1135
- if (Is.stringValue(network)) {
1136
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
1137
- }
1138
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
1139
- CLIDisplay.break();
1140
- setupVault();
1141
- const vaultSeedId = "local-seed";
1142
- const localIdentity = "local";
1143
- const vaultConnector = VaultConnectorFactory.get("vault");
1144
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
1145
- const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
1146
- WalletConnectorFactory.register("wallet", () => walletConnector);
1147
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
1148
- CLIDisplay.task(I18n.formatMessage("commands.verification-method-remove.progress.removingVerificationMethod"));
1149
- CLIDisplay.break();
1150
- CLIDisplay.spinnerStart();
1151
- await identityConnector.removeVerificationMethod(localIdentity, id);
1152
- CLIDisplay.spinnerStop();
1153
- const did = DocumentHelper.parseId(id).id;
1154
- if (opts.connector === IdentityConnectorTypes.Iota) {
1155
- const didUrn = Urn.fromValidString(did);
1156
- const didParts = didUrn.parts();
1157
- const objectId = didParts[didParts.length - 1];
1158
- CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
1159
- }
1160
- CLIDisplay.break();
1161
- CLIDisplay.done();
1162
- }
1163
-
1164
- // Copyright 2024 IOTA Stiftung.
1165
- // SPDX-License-Identifier: Apache-2.0.
1166
- /**
1167
- * The main entry point for the CLI.
1168
- */
1169
- class CLI extends CLIBase {
1170
- /**
1171
- * Run the app.
1172
- * @param argv The process arguments.
1173
- * @param localesDirectory The directory for the locales, default to relative to the script.
1174
- * @param options Additional options for the CLI.
1175
- * @param options.overrideOutputWidth The override output width.
1176
- * @returns The exit code.
1177
- */
1178
- async run(argv, localesDirectory, options) {
1179
- return this.execute({
1180
- title: "TWIN Identity",
1181
- appName: "twin-identity",
1182
- version: "0.0.2-next.9", // x-release-please-version
1183
- icon: "🌍",
1184
- supportsEnvFiles: true,
1185
- overrideOutputWidth: options?.overrideOutputWidth,
1186
- showDevToolWarning: true
1187
- }, localesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), "../locales"), argv);
1188
- }
1189
- /**
1190
- * Get the commands for the CLI.
1191
- * @param program The main program to add the commands to.
1192
- * @internal
1193
- */
1194
- getCommands(program) {
1195
- return [
1196
- buildCommandMnemonic(),
1197
- buildCommandAddress(),
1198
- buildCommandFaucet(),
1199
- buildCommandTransfer(),
1200
- buildCommandIdentityCreate(),
1201
- buildCommandIdentityResolve(),
1202
- buildCommandVerificationMethodAdd(),
1203
- buildCommandVerificationMethodRemove(),
1204
- buildCommandServiceAdd(),
1205
- buildCommandServiceRemove(),
1206
- buildCommandVerifiableCredentialCreate(),
1207
- buildCommandVerifiableCredentialVerify(),
1208
- buildCommandVerifiableCredentialRevoke(),
1209
- buildCommandVerifiableCredentialUnrevoke(),
1210
- buildCommandProofCreate(),
1211
- buildCommandProofVerify()
1212
- ];
1213
- }
1214
- }
1215
-
1216
- export { CLI, IdentityConnectorTypes, IdentityResolverConnectorTypes, actionCommandIdentityCreate, actionCommandIdentityResolve, actionCommandProofCreate, actionCommandProofVerify, actionCommandServiceAdd, actionCommandServiceRemove, actionCommandVerifiableCredentialCreate, actionCommandVerifiableCredentialRevoke, actionCommandVerifiableCredentialUnrevoke, actionCommandVerifiableCredentialVerify, actionCommandVerificationMethodAdd, actionCommandVerificationMethodRemove, buildCommandIdentityCreate, buildCommandIdentityResolve, buildCommandProofCreate, buildCommandProofVerify, buildCommandServiceAdd, buildCommandServiceRemove, buildCommandVerifiableCredentialCreate, buildCommandVerifiableCredentialRevoke, buildCommandVerifiableCredentialUnrevoke, buildCommandVerifiableCredentialVerify, buildCommandVerificationMethodAdd, buildCommandVerificationMethodRemove, setupIdentityConnector, setupIdentityResolverConnector, setupVault };