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