@twin.org/identity-cli 0.0.1-next.20 → 0.0.1-next.22

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 (31) hide show
  1. package/dist/cjs/index.cjs +249 -226
  2. package/dist/esm/index.mjs +250 -230
  3. package/dist/locales/en.json +73 -9
  4. package/dist/types/commands/identityCreate.d.ts +6 -0
  5. package/dist/types/commands/identityResolve.d.ts +5 -0
  6. package/dist/types/commands/proofCreate.d.ts +5 -0
  7. package/dist/types/commands/proofVerify.d.ts +5 -0
  8. package/dist/types/commands/serviceAdd.d.ts +4 -0
  9. package/dist/types/commands/serviceRemove.d.ts +5 -0
  10. package/dist/types/commands/setupCommands.d.ts +18 -0
  11. package/dist/types/commands/verifiableCredentialCreate.d.ts +4 -0
  12. package/dist/types/commands/verifiableCredentialRevoke.d.ts +5 -0
  13. package/dist/types/commands/verifiableCredentialUnrevoke.d.ts +5 -0
  14. package/dist/types/commands/verifiableCredentialVerify.d.ts +4 -0
  15. package/dist/types/commands/verificationMethodAdd.d.ts +4 -0
  16. package/dist/types/commands/verificationMethodRemove.d.ts +5 -0
  17. package/dist/types/index.d.ts +2 -0
  18. package/dist/types/models/identityConnectorTypes.d.ts +17 -0
  19. package/docs/changelog.md +1 -1
  20. package/docs/examples.md +5 -5
  21. package/docs/reference/functions/actionCommandServiceRemove.md +12 -0
  22. package/docs/reference/functions/actionCommandVerifiableCredentialRevoke.md +12 -0
  23. package/docs/reference/functions/actionCommandVerifiableCredentialUnrevoke.md +12 -0
  24. package/docs/reference/functions/actionCommandVerificationMethodRemove.md +12 -0
  25. package/docs/reference/functions/setupIdentityConnector.md +47 -0
  26. package/docs/reference/functions/setupVault.md +9 -0
  27. package/docs/reference/index.md +10 -0
  28. package/docs/reference/type-aliases/IdentityConnectorTypes.md +5 -0
  29. package/docs/reference/variables/IdentityConnectorTypes.md +19 -0
  30. package/locales/en.json +17 -2
  31. package/package.json +7 -5
@@ -8,16 +8,33 @@ var walletCli = require('@twin.org/wallet-cli');
8
8
  var core = require('@twin.org/core');
9
9
  var identityConnectorIota = require('@twin.org/identity-connector-iota');
10
10
  var vaultModels = require('@twin.org/vault-models');
11
- var walletConnectorIota = require('@twin.org/wallet-connector-iota');
12
11
  var walletModels = require('@twin.org/wallet-models');
13
12
  var commander = require('commander');
14
13
  var entityStorageConnectorMemory = require('@twin.org/entity-storage-connector-memory');
15
14
  var entityStorageModels = require('@twin.org/entity-storage-models');
15
+ var identityConnectorIotaRebased = require('@twin.org/identity-connector-iota-rebased');
16
16
  var vaultConnectorEntityStorage = require('@twin.org/vault-connector-entity-storage');
17
17
  var standardsW3cDid = require('@twin.org/standards-w3c-did');
18
18
  var identityModels = require('@twin.org/identity-models');
19
19
 
20
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
+ * IOTA Rebased.
34
+ */
35
+ IotaRebased: "iota-rebased"
36
+ };
37
+
21
38
  // Copyright 2024 IOTA Stiftung.
22
39
  // SPDX-License-Identifier: Apache-2.0.
23
40
  /**
@@ -34,6 +51,41 @@ function setupVault() {
34
51
  const vaultConnector = new vaultConnectorEntityStorage.EntityStorageVaultConnector();
35
52
  vaultModels.VaultConnectorFactory.register("vault", () => vaultConnector);
36
53
  }
54
+ /**
55
+ * Setup the identity connector for use in the CLI commands.
56
+ * @param options The options for the identity connector.
57
+ * @param options.nodeEndpoint The node endpoint.
58
+ * @param options.network The network.
59
+ * @param options.addressIndex The wallet index.
60
+ * @param options.vaultSeedId The vault seed ID.
61
+ * @param connector The connector to use.
62
+ * @returns The identity connector.
63
+ */
64
+ function setupIdentityConnector(options, connector) {
65
+ connector ??= IdentityConnectorTypes.Iota;
66
+ if (connector === IdentityConnectorTypes.IotaRebased) {
67
+ return new identityConnectorIotaRebased.IotaRebasedIdentityConnector({
68
+ config: {
69
+ clientOptions: {
70
+ url: options.nodeEndpoint
71
+ },
72
+ network: options.network ?? "",
73
+ vaultSeedId: options.vaultSeedId,
74
+ walletAddressIndex: options.addressIndex
75
+ }
76
+ });
77
+ }
78
+ return new identityConnectorIota.IotaIdentityConnector({
79
+ config: {
80
+ clientOptions: {
81
+ nodes: [options.nodeEndpoint],
82
+ localPow: true
83
+ },
84
+ vaultSeedId: options.vaultSeedId,
85
+ walletAddressIndex: options.addressIndex
86
+ }
87
+ });
88
+ }
37
89
 
38
90
  // Copyright 2024 IOTA Stiftung.
39
91
  // SPDX-License-Identifier: Apache-2.0.
@@ -47,7 +99,8 @@ function buildCommandIdentityCreate() {
47
99
  .name("identity-create")
48
100
  .summary(core.I18n.formatMessage("commands.identity-create.summary"))
49
101
  .description(core.I18n.formatMessage("commands.identity-create.description"))
50
- .requiredOption(core.I18n.formatMessage("commands.identity-create.options.seed.param"), core.I18n.formatMessage("commands.identity-create.options.seed.description"));
102
+ .requiredOption(core.I18n.formatMessage("commands.identity-create.options.seed.param"), core.I18n.formatMessage("commands.identity-create.options.seed.description"))
103
+ .option(core.I18n.formatMessage("commands.identity-create.options.addressIndex.param"), core.I18n.formatMessage("commands.identity-create.options.addressIndex.description"), "0");
51
104
  cliCore.CLIOptions.output(command, {
52
105
  noConsole: true,
53
106
  json: true,
@@ -56,7 +109,11 @@ function buildCommandIdentityCreate() {
56
109
  mergeEnv: true
57
110
  });
58
111
  command
112
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
113
+ .choices(Object.values(IdentityConnectorTypes))
114
+ .default(IdentityConnectorTypes.Iota))
59
115
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
116
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
60
117
  .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
61
118
  .action(actionCommandIdentityCreate);
62
119
  return command;
@@ -65,44 +122,38 @@ function buildCommandIdentityCreate() {
65
122
  * Action the identity create command.
66
123
  * @param opts The options for the command.
67
124
  * @param opts.seed The private key for the controller.
125
+ * @param opts.connector The connector to perform the operations with.
68
126
  * @param opts.node The node URL.
127
+ * @param opts.network The network to use for rebased connector.
69
128
  * @param opts.explorer The explorer URL.
70
129
  */
71
130
  async function actionCommandIdentityCreate(opts) {
72
131
  const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
73
132
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
133
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
134
+ ? cliCore.CLIParam.stringValue("network", opts.network)
135
+ : undefined;
74
136
  const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
137
+ const addressIndex = cliCore.CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
75
138
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
139
+ if (core.Is.stringValue(network)) {
140
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
141
+ }
76
142
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
143
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.identity-create.labels.addressIndex"), addressIndex);
77
144
  cliCore.CLIDisplay.break();
78
145
  setupVault();
79
146
  const vaultSeedId = "local-seed";
80
147
  const localIdentity = "local";
81
148
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
82
149
  await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
83
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
84
- config: {
85
- clientOptions: {
86
- nodes: [nodeEndpoint],
87
- localPow: true
88
- },
89
- vaultSeedId
90
- }
91
- });
92
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
93
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
94
- config: {
95
- clientOptions: {
96
- nodes: [nodeEndpoint],
97
- localPow: true
98
- },
99
- vaultSeedId
100
- }
101
- });
150
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
151
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
152
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, vaultSeedId, network, addressIndex }, opts.connector);
102
153
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.identity-create.progress.creatingIdentity"));
103
154
  cliCore.CLIDisplay.break();
104
155
  cliCore.CLIDisplay.spinnerStart();
105
- const document = await iotaIdentityConnector.createDocument(localIdentity);
156
+ const document = await identityConnector.createDocument(localIdentity);
106
157
  cliCore.CLIDisplay.spinnerStop();
107
158
  if (opts.console) {
108
159
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.identity-create.labels.identity"), document.id);
@@ -140,8 +191,12 @@ function buildCommandIdentityResolve() {
140
191
  mergeEnv: false
141
192
  });
142
193
  command
194
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
195
+ .choices(Object.values(IdentityConnectorTypes))
196
+ .default(IdentityConnectorTypes.Iota))
143
197
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
144
198
  .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
199
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
145
200
  .action(actionCommandIdentityResolve);
146
201
  return command;
147
202
  }
@@ -149,28 +204,29 @@ function buildCommandIdentityResolve() {
149
204
  * Action the identity resolve command.
150
205
  * @param opts The options for the command.
151
206
  * @param opts.did The identity to resolve.
207
+ * @param opts.connector The connector to perform the operations with.
152
208
  * @param opts.node The node URL.
209
+ * @param opts.network The network to use for rebased connector.
153
210
  * @param opts.explorer The explorer URL.
154
211
  */
155
212
  async function actionCommandIdentityResolve(opts) {
156
213
  const did = cliCore.CLIParam.stringValue("did", opts.did);
157
214
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
215
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
216
+ ? cliCore.CLIParam.stringValue("network", opts.network)
217
+ : undefined;
158
218
  const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
159
219
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
160
220
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
221
+ if (core.Is.stringValue(network)) {
222
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
223
+ }
161
224
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
162
225
  cliCore.CLIDisplay.break();
163
226
  setupVault();
164
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
165
- config: {
166
- clientOptions: {
167
- nodes: [nodeEndpoint],
168
- localPow: true
169
- }
170
- }
171
- });
172
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
173
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
227
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network }, opts.connector);
228
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
229
+ const iotaIdentityResolverConnector = new identityConnectorIota.IotaIdentityResolverConnector({
174
230
  config: {
175
231
  clientOptions: {
176
232
  nodes: [nodeEndpoint],
@@ -181,7 +237,7 @@ async function actionCommandIdentityResolve(opts) {
181
237
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.identity-resolve.progress.resolvingIdentity"));
182
238
  cliCore.CLIDisplay.break();
183
239
  cliCore.CLIDisplay.spinnerStart();
184
- const document = await iotaIdentityConnector.resolveDocument(did);
240
+ const document = await iotaIdentityResolverConnector.resolveDocument(did);
185
241
  cliCore.CLIDisplay.spinnerStop();
186
242
  if (opts.console) {
187
243
  cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.identity-resolve.labels.didDocument"));
@@ -219,7 +275,11 @@ function buildCommandProofCreate() {
219
275
  mergeEnv: true
220
276
  });
221
277
  command
278
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
279
+ .choices(Object.values(IdentityConnectorTypes))
280
+ .default(IdentityConnectorTypes.Iota))
222
281
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
282
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
223
283
  .action(actionCommandProofCreate);
224
284
  return command;
225
285
  }
@@ -229,41 +289,35 @@ function buildCommandProofCreate() {
229
289
  * @param opts.id The id of the verification method to use for the credential.
230
290
  * @param opts.privateKey The private key for the verification method.
231
291
  * @param opts.data The data to create the proof for.
292
+ * @param opts.connector The connector to perform the operations with.
232
293
  * @param opts.node The node URL.
294
+ * @param opts.network The network to use for rebased connector.
233
295
  */
234
296
  async function actionCommandProofCreate(opts) {
235
297
  const id = cliCore.CLIParam.stringValue("id", opts.id);
236
298
  const privateKey = cliCore.CLIParam.hexBase64("private-key", opts.privateKey);
237
299
  const data = cliCore.CLIParam.hexBase64("data", opts.data);
238
300
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
301
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
302
+ ? cliCore.CLIParam.stringValue("network", opts.network)
303
+ : undefined;
239
304
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-create.labels.verificationMethodId"), id);
240
305
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
306
+ if (core.Is.stringValue(network)) {
307
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
308
+ }
241
309
  cliCore.CLIDisplay.break();
242
310
  setupVault();
243
311
  const localIdentity = "local";
244
312
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
245
313
  await vaultConnector.addKey(`${localIdentity}/${id}`, vaultModels.VaultKeyType.Ed25519, privateKey, new Uint8Array());
246
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
247
- config: {
248
- clientOptions: {
249
- nodes: [nodeEndpoint],
250
- localPow: true
251
- }
252
- }
253
- });
254
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
255
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
256
- config: {
257
- clientOptions: {
258
- nodes: [nodeEndpoint],
259
- localPow: true
260
- }
261
- }
262
- });
314
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network }, opts.connector);
315
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
316
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
263
317
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.proof-create.progress.creatingProof"));
264
318
  cliCore.CLIDisplay.break();
265
319
  cliCore.CLIDisplay.spinnerStart();
266
- const proof = await iotaIdentityConnector.createProof(localIdentity, id, data);
320
+ const proof = await identityConnector.createProof(localIdentity, id, data);
267
321
  cliCore.CLIDisplay.spinnerStop();
268
322
  if (opts.console) {
269
323
  cliCore.CLIDisplay.json(proof);
@@ -302,7 +356,11 @@ function buildCommandProofVerify() {
302
356
  mergeEnv: true
303
357
  });
304
358
  command
359
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
360
+ .choices(Object.values(IdentityConnectorTypes))
361
+ .default(IdentityConnectorTypes.Iota))
305
362
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
363
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
306
364
  .action(actionCommandProofVerify);
307
365
  return command;
308
366
  }
@@ -313,7 +371,9 @@ function buildCommandProofVerify() {
313
371
  * @param opts.data The data to verify the proof for.
314
372
  * @param opts.cryptosuite The cryptosuite of the proof.
315
373
  * @param opts.value The proof value.
374
+ * @param opts.connector The connector to perform the operations with.
316
375
  * @param opts.node The node URL.
376
+ * @param opts.network The network to use for rebased connector.
317
377
  */
318
378
  async function actionCommandProofVerify(opts) {
319
379
  const id = cliCore.CLIParam.stringValue("id", opts.id);
@@ -321,29 +381,21 @@ async function actionCommandProofVerify(opts) {
321
381
  const cryptosuite = cliCore.CLIParam.stringValue("cryptosuite", opts.cryptosuite);
322
382
  const value = cliCore.CLIParam.stringValue("value", opts.value);
323
383
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
384
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
385
+ ? cliCore.CLIParam.stringValue("network", opts.network)
386
+ : undefined;
324
387
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-verify.labels.verificationMethodId"), id);
325
388
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-verify.labels.cryptosuite"), cryptosuite);
326
389
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-verify.labels.value"), value);
327
390
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
391
+ if (core.Is.stringValue(network)) {
392
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
393
+ }
328
394
  cliCore.CLIDisplay.break();
329
395
  setupVault();
330
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
331
- config: {
332
- clientOptions: {
333
- nodes: [nodeEndpoint],
334
- localPow: true
335
- }
336
- }
337
- });
338
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
339
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
340
- config: {
341
- clientOptions: {
342
- nodes: [nodeEndpoint],
343
- localPow: true
344
- }
345
- }
346
- });
396
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network }, opts.connector);
397
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
398
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
347
399
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.proof-verify.progress.verifyingProof"));
348
400
  cliCore.CLIDisplay.break();
349
401
  cliCore.CLIDisplay.spinnerStart();
@@ -355,7 +407,7 @@ async function actionCommandProofVerify(opts) {
355
407
  proofPurpose: "assertionMethod",
356
408
  proofValue: value
357
409
  };
358
- const isVerified = await iotaIdentityConnector.verifyProof(data, proof);
410
+ const isVerified = await identityConnector.verifyProof(data, proof);
359
411
  cliCore.CLIDisplay.spinnerStop();
360
412
  if (opts.console) {
361
413
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.proof-verify.labels.isVerified"), isVerified);
@@ -395,7 +447,11 @@ function buildCommandServiceAdd() {
395
447
  mergeEnv: true
396
448
  });
397
449
  command
450
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
451
+ .choices(Object.values(IdentityConnectorTypes))
452
+ .default(IdentityConnectorTypes.Iota))
398
453
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
454
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
399
455
  .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
400
456
  .action(actionCommandServiceAdd);
401
457
  return command;
@@ -408,6 +464,7 @@ function buildCommandServiceAdd() {
408
464
  * @param opts.id The id of the service to add.
409
465
  * @param opts.type The type of the service to add.
410
466
  * @param opts.endpoint The service endpoint.
467
+ * @param opts.connector The connector to perform the operations with.
411
468
  * @param opts.node The node URL.
412
469
  * @param opts.explorer The explorer URL.
413
470
  */
@@ -418,12 +475,18 @@ async function actionCommandServiceAdd(opts) {
418
475
  const type = cliCore.CLIParam.stringValue("type", opts.type);
419
476
  const endpoint = cliCore.CLIParam.url("endpoint", opts.endpoint);
420
477
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
478
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
479
+ ? cliCore.CLIParam.stringValue("network", opts.network)
480
+ : undefined;
421
481
  const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
422
482
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
423
483
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.service-add.labels.serviceId"), id);
424
484
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.service-add.labels.serviceType"), type);
425
485
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.service-add.labels.serviceEndpoint"), endpoint);
426
486
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
487
+ if (core.Is.stringValue(network)) {
488
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
489
+ }
427
490
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
428
491
  cliCore.CLIDisplay.break();
429
492
  setupVault();
@@ -431,29 +494,13 @@ async function actionCommandServiceAdd(opts) {
431
494
  const localIdentity = "local";
432
495
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
433
496
  await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
434
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
435
- config: {
436
- clientOptions: {
437
- nodes: [nodeEndpoint],
438
- localPow: true
439
- },
440
- vaultSeedId
441
- }
442
- });
443
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
444
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
445
- config: {
446
- clientOptions: {
447
- nodes: [nodeEndpoint],
448
- localPow: true
449
- },
450
- vaultSeedId
451
- }
452
- });
497
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
498
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
499
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
453
500
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.service-add.progress.addingService"));
454
501
  cliCore.CLIDisplay.break();
455
502
  cliCore.CLIDisplay.spinnerStart();
456
- const service = await iotaIdentityConnector.addService(localIdentity, did, id, type, endpoint);
503
+ const service = await identityConnector.addService(localIdentity, did, id, type, endpoint);
457
504
  cliCore.CLIDisplay.spinnerStop();
458
505
  if (core.Is.stringValue(opts?.json)) {
459
506
  await cliCore.CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);
@@ -492,7 +539,11 @@ function buildCommandServiceRemove() {
492
539
  mergeEnv: true
493
540
  });
494
541
  command
542
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
543
+ .choices(Object.values(IdentityConnectorTypes))
544
+ .default(IdentityConnectorTypes.Iota))
495
545
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
546
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
496
547
  .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
497
548
  .action(actionCommandServiceRemove);
498
549
  return command;
@@ -502,16 +553,24 @@ function buildCommandServiceRemove() {
502
553
  * @param opts The options for the command.
503
554
  * @param opts.seed The private key for the controller.
504
555
  * @param opts.id The id of the service to remove.
556
+ * @param opts.connector The connector to perform the operations with.
505
557
  * @param opts.node The node URL.
558
+ * @param opts.network The network to use for rebased connector.
506
559
  * @param opts.explorer The explorer URL.
507
560
  */
508
561
  async function actionCommandServiceRemove(opts) {
509
562
  const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
510
563
  const id = cliCore.CLIParam.stringValue("id", opts.id);
511
564
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
565
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
566
+ ? cliCore.CLIParam.stringValue("network", opts.network)
567
+ : undefined;
512
568
  const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
513
569
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.service-remove.labels.serviceId"), id);
514
570
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
571
+ if (core.Is.stringValue(network)) {
572
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
573
+ }
515
574
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
516
575
  cliCore.CLIDisplay.break();
517
576
  setupVault();
@@ -519,29 +578,13 @@ async function actionCommandServiceRemove(opts) {
519
578
  const localIdentity = "local";
520
579
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
521
580
  await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
522
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
523
- config: {
524
- clientOptions: {
525
- nodes: [nodeEndpoint],
526
- localPow: true
527
- },
528
- vaultSeedId
529
- }
530
- });
531
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
532
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
533
- config: {
534
- clientOptions: {
535
- nodes: [nodeEndpoint],
536
- localPow: true
537
- },
538
- vaultSeedId
539
- }
540
- });
581
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
582
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
583
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
541
584
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.service-remove.progress.removingService"));
542
585
  cliCore.CLIDisplay.break();
543
586
  cliCore.CLIDisplay.spinnerStart();
544
- await iotaIdentityConnector.removeService(localIdentity, id);
587
+ await identityConnector.removeService(localIdentity, id);
545
588
  cliCore.CLIDisplay.spinnerStop();
546
589
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${identityConnectorIota.IotaIdentityUtils.didToAddress(identityModels.DocumentHelper.parse(id).id)}?tab=DID`);
547
590
  cliCore.CLIDisplay.break();
@@ -573,7 +616,11 @@ function buildCommandVerifiableCredentialCreate() {
573
616
  mergeEnv: true
574
617
  });
575
618
  command
619
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
620
+ .choices(Object.values(IdentityConnectorTypes))
621
+ .default(IdentityConnectorTypes.Iota))
576
622
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
623
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
577
624
  .action(actionCommandVerifiableCredentialCreate);
578
625
  return command;
579
626
  }
@@ -585,6 +632,7 @@ function buildCommandVerifiableCredentialCreate() {
585
632
  * @param opts.credentialId The id of the credential.
586
633
  * @param opts.subjectJson The JSON data for the subject.
587
634
  * @param opts.revocationIndex The revocation index for the credential.
635
+ * @param opts.connector The connector to perform the operations with.
588
636
  * @param opts.node The node URL.
589
637
  */
590
638
  async function actionCommandVerifiableCredentialCreate(opts) {
@@ -594,33 +642,25 @@ async function actionCommandVerifiableCredentialCreate(opts) {
594
642
  const subjectJson = path.resolve(cliCore.CLIParam.stringValue("subject-json", opts.subjectJson));
595
643
  const revocationIndex = core.Coerce.number(opts.revocationIndex);
596
644
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
645
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
646
+ ? cliCore.CLIParam.stringValue("network", opts.network)
647
+ : undefined;
597
648
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-create.labels.verificationMethodId"), id);
598
649
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-create.labels.credentialId"), credentialId);
599
650
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-create.labels.subjectJson"), subjectJson);
600
651
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-create.labels.revocationIndex"), revocationIndex);
601
652
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
653
+ if (core.Is.stringValue(network)) {
654
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
655
+ }
602
656
  cliCore.CLIDisplay.break();
603
657
  setupVault();
604
658
  const localIdentity = "local";
605
659
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
606
660
  await vaultConnector.addKey(`${localIdentity}/${id}`, vaultModels.VaultKeyType.Ed25519, privateKey, new Uint8Array());
607
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
608
- config: {
609
- clientOptions: {
610
- nodes: [nodeEndpoint],
611
- localPow: true
612
- }
613
- }
614
- });
615
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
616
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
617
- config: {
618
- clientOptions: {
619
- nodes: [nodeEndpoint],
620
- localPow: true
621
- }
622
- }
623
- });
661
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network }, opts.connector);
662
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
663
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
624
664
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-create.progress.loadingSubjectData"));
625
665
  cliCore.CLIDisplay.break();
626
666
  const jsonData = await cliCore.CLIUtils.readJsonFile(subjectJson);
@@ -630,7 +670,7 @@ async function actionCommandVerifiableCredentialCreate(opts) {
630
670
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-create.progress.creatingVerifiableCredential"));
631
671
  cliCore.CLIDisplay.break();
632
672
  cliCore.CLIDisplay.spinnerStart();
633
- const verifiableCredential = await iotaIdentityConnector.createVerifiableCredential(localIdentity, id, credentialId, jsonData, revocationIndex);
673
+ const verifiableCredential = await identityConnector.createVerifiableCredential(localIdentity, id, credentialId, jsonData, revocationIndex);
634
674
  cliCore.CLIDisplay.spinnerStop();
635
675
  if (opts.console) {
636
676
  cliCore.CLIDisplay.section(core.I18n.formatMessage("commands.verifiable-credential-create.labels.verifiableCredential"));
@@ -663,7 +703,11 @@ function buildCommandVerifiableCredentialRevoke() {
663
703
  .requiredOption(core.I18n.formatMessage("commands.verifiable-credential-revoke.options.did.param"), core.I18n.formatMessage("commands.verifiable-credential-revoke.options.did.description"))
664
704
  .requiredOption(core.I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.param"), core.I18n.formatMessage("commands.verifiable-credential-revoke.options.revocation-index.description"));
665
705
  command
706
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
707
+ .choices(Object.values(IdentityConnectorTypes))
708
+ .default(IdentityConnectorTypes.Iota))
666
709
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
710
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
667
711
  .action(actionCommandVerifiableCredentialRevoke);
668
712
  return command;
669
713
  }
@@ -673,45 +717,37 @@ function buildCommandVerifiableCredentialRevoke() {
673
717
  * @param opts.seed The seed to generate the private key for the controller.
674
718
  * @param opts.did The id of the document to revoke the index.
675
719
  * @param opts.revocationIndex The revocation index for the credential.
720
+ * @param opts.connector The connector to perform the operations with.
676
721
  * @param opts.node The node URL.
722
+ * @param opts.network The network to use for rebased connector.
677
723
  */
678
724
  async function actionCommandVerifiableCredentialRevoke(opts) {
679
725
  const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
680
726
  const did = cliCore.CLIParam.stringValue("did", opts.did);
681
727
  const revocationIndex = cliCore.CLIParam.integer("revocation-index", opts.revocationIndex);
682
728
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
729
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
730
+ ? cliCore.CLIParam.stringValue("network", opts.network)
731
+ : undefined;
683
732
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
684
733
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-revoke.labels.revocationIndex"), revocationIndex);
685
734
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
735
+ if (core.Is.stringValue(network)) {
736
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
737
+ }
686
738
  cliCore.CLIDisplay.break();
687
739
  setupVault();
688
740
  const vaultSeedId = "local-seed";
689
741
  const localIdentity = "local";
690
742
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
691
743
  await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
692
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
693
- config: {
694
- clientOptions: {
695
- nodes: [nodeEndpoint],
696
- localPow: true
697
- },
698
- vaultSeedId
699
- }
700
- });
701
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
702
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
703
- config: {
704
- clientOptions: {
705
- nodes: [nodeEndpoint],
706
- localPow: true
707
- },
708
- vaultSeedId
709
- }
710
- });
744
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
745
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
746
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
711
747
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-revoke.progress.revokingCredential"));
712
748
  cliCore.CLIDisplay.break();
713
749
  cliCore.CLIDisplay.spinnerStart();
714
- await iotaIdentityConnector.revokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
750
+ await identityConnector.revokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
715
751
  cliCore.CLIDisplay.spinnerStop();
716
752
  cliCore.CLIDisplay.done();
717
753
  }
@@ -732,7 +768,11 @@ function buildCommandVerifiableCredentialUnrevoke() {
732
768
  .requiredOption(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.param"), core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.did.description"))
733
769
  .requiredOption(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.param"), core.I18n.formatMessage("commands.verifiable-credential-unrevoke.options.revocation-index.description"));
734
770
  command
771
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
772
+ .choices(Object.values(IdentityConnectorTypes))
773
+ .default(IdentityConnectorTypes.Iota))
735
774
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
775
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
736
776
  .action(actionCommandVerifiableCredentialUnrevoke);
737
777
  return command;
738
778
  }
@@ -742,45 +782,37 @@ function buildCommandVerifiableCredentialUnrevoke() {
742
782
  * @param opts.seed The seed to generate the private key for the controller.
743
783
  * @param opts.did The id of the document to unrevoke the index.
744
784
  * @param opts.revocationIndex The revocation index for the credential.
785
+ * @param opts.connector The connector to perform the operations with.
745
786
  * @param opts.node The node URL.
787
+ * @param opts.network The network to use for rebased connector.
746
788
  */
747
789
  async function actionCommandVerifiableCredentialUnrevoke(opts) {
748
790
  const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
749
791
  const did = cliCore.CLIParam.stringValue("did", opts.did);
750
792
  const revocationIndex = cliCore.CLIParam.integer("revocation-index", opts.revocationIndex);
751
793
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
794
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
795
+ ? cliCore.CLIParam.stringValue("network", opts.network)
796
+ : undefined;
752
797
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
753
798
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.labels.revocationIndex"), revocationIndex);
754
799
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
800
+ if (core.Is.stringValue(network)) {
801
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
802
+ }
755
803
  cliCore.CLIDisplay.break();
756
804
  setupVault();
757
805
  const vaultSeedId = "local-seed";
758
806
  const localIdentity = "local";
759
807
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
760
808
  await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
761
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
762
- config: {
763
- clientOptions: {
764
- nodes: [nodeEndpoint],
765
- localPow: true
766
- },
767
- vaultSeedId
768
- }
769
- });
770
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
771
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
772
- config: {
773
- clientOptions: {
774
- nodes: [nodeEndpoint],
775
- localPow: true
776
- },
777
- vaultSeedId
778
- }
779
- });
809
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
810
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
811
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
780
812
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-unrevoke.progress.unrevokingCredential"));
781
813
  cliCore.CLIDisplay.break();
782
814
  cliCore.CLIDisplay.spinnerStart();
783
- await iotaIdentityConnector.unrevokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
815
+ await identityConnector.unrevokeVerifiableCredentials(localIdentity, did, [revocationIndex]);
784
816
  cliCore.CLIDisplay.spinnerStop();
785
817
  cliCore.CLIDisplay.done();
786
818
  }
@@ -806,7 +838,11 @@ function buildCommandVerifiableCredentialVerify() {
806
838
  mergeEnv: true
807
839
  });
808
840
  command
841
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
842
+ .choices(Object.values(IdentityConnectorTypes))
843
+ .default(IdentityConnectorTypes.Iota))
809
844
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
845
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
810
846
  .action(actionCommandVerifiableCredentialVerify);
811
847
  return command;
812
848
  }
@@ -814,36 +850,29 @@ function buildCommandVerifiableCredentialVerify() {
814
850
  * Action the verifiable credential verify command.
815
851
  * @param opts The options for the command.
816
852
  * @param opts.jwt The JSON web token for the verifiable credential.
853
+ * @param opts.connector The connector to perform the operations with.
817
854
  * @param opts.node The node URL.
818
855
  */
819
856
  async function actionCommandVerifiableCredentialVerify(opts) {
820
857
  const jwt = cliCore.CLIParam.stringValue("jwt", opts.jwt);
821
858
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
859
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
860
+ ? cliCore.CLIParam.stringValue("network", opts.network)
861
+ : undefined;
822
862
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verifiable-credential-verify.labels.jwt"), jwt);
823
863
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
864
+ if (core.Is.stringValue(network)) {
865
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
866
+ }
824
867
  cliCore.CLIDisplay.break();
825
868
  setupVault();
826
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
827
- config: {
828
- clientOptions: {
829
- nodes: [nodeEndpoint],
830
- localPow: true
831
- }
832
- }
833
- });
834
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
835
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
836
- config: {
837
- clientOptions: {
838
- nodes: [nodeEndpoint],
839
- localPow: true
840
- }
841
- }
842
- });
869
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, network }, opts.connector);
870
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
871
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
843
872
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verifiable-credential-verify.progress.verifyingCredential"));
844
873
  cliCore.CLIDisplay.break();
845
874
  cliCore.CLIDisplay.spinnerStart();
846
- const verification = await iotaIdentityConnector.checkVerifiableCredential(jwt);
875
+ const verification = await identityConnector.checkVerifiableCredential(jwt);
847
876
  const isVerified = core.Is.notEmpty(verification.verifiableCredential);
848
877
  const isRevoked = verification.revoked;
849
878
  cliCore.CLIDisplay.spinnerStop();
@@ -890,7 +919,11 @@ function buildCommandVerificationMethodAdd() {
890
919
  mergeEnv: true
891
920
  });
892
921
  command
922
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
923
+ .choices(Object.values(IdentityConnectorTypes))
924
+ .default(IdentityConnectorTypes.Iota))
893
925
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
926
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
894
927
  .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
895
928
  .action(actionCommandVerificationMethodAdd);
896
929
  return command;
@@ -902,6 +935,7 @@ function buildCommandVerificationMethodAdd() {
902
935
  * @param opts.did The identity of the document to add to.
903
936
  * @param opts.type The type of the verification method to add.
904
937
  * @param opts.id The id of the verification method to add.
938
+ * @param opts.connector The connector to perform the operations with.
905
939
  * @param opts.node The node URL.
906
940
  * @param opts.explorer The explorer URL.
907
941
  */
@@ -910,6 +944,9 @@ async function actionCommandVerificationMethodAdd(opts) {
910
944
  const did = cliCore.CLIParam.stringValue("did", opts.did);
911
945
  const type = cliCore.CLIParam.stringValue("type", opts.type);
912
946
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
947
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
948
+ ? cliCore.CLIParam.stringValue("network", opts.network)
949
+ : undefined;
913
950
  const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
914
951
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.did"), did);
915
952
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.verificationMethodType"), type);
@@ -917,6 +954,9 @@ async function actionCommandVerificationMethodAdd(opts) {
917
954
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), opts?.id);
918
955
  }
919
956
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
957
+ if (core.Is.stringValue(network)) {
958
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
959
+ }
920
960
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
921
961
  cliCore.CLIDisplay.break();
922
962
  setupVault();
@@ -924,29 +964,13 @@ async function actionCommandVerificationMethodAdd(opts) {
924
964
  const localIdentity = "local";
925
965
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
926
966
  await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
927
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
928
- config: {
929
- clientOptions: {
930
- nodes: [nodeEndpoint],
931
- localPow: true
932
- },
933
- vaultSeedId
934
- }
935
- });
936
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
937
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
938
- config: {
939
- clientOptions: {
940
- nodes: [nodeEndpoint],
941
- localPow: true
942
- },
943
- vaultSeedId
944
- }
945
- });
967
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
968
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
969
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
946
970
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verification-method-add.progress.addingVerificationMethod"));
947
971
  cliCore.CLIDisplay.break();
948
972
  cliCore.CLIDisplay.spinnerStart();
949
- const verificationMethod = await iotaIdentityConnector.addVerificationMethod(localIdentity, did, type, opts?.id);
973
+ const verificationMethod = await identityConnector.addVerificationMethod(localIdentity, did, type, opts?.id);
950
974
  cliCore.CLIDisplay.spinnerStop();
951
975
  const keyPair = await vaultConnector.getKey(`${localIdentity}/${verificationMethod.id}`);
952
976
  const privateKey = core.Converter.bytesToBase64(keyPair.privateKey);
@@ -996,7 +1020,11 @@ function buildCommandVerificationMethodRemove() {
996
1020
  mergeEnv: true
997
1021
  });
998
1022
  command
1023
+ .addOption(new commander.Option(core.I18n.formatMessage("commands.common.options.connector.param"), core.I18n.formatMessage("commands.common.options.connector.description"))
1024
+ .choices(Object.values(IdentityConnectorTypes))
1025
+ .default(IdentityConnectorTypes.Iota))
999
1026
  .option(core.I18n.formatMessage("commands.common.options.node.param"), core.I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
1027
+ .option(core.I18n.formatMessage("commands.common.options.network.param"), core.I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
1000
1028
  .option(core.I18n.formatMessage("commands.common.options.explorer.param"), core.I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
1001
1029
  .action(actionCommandVerificationMethodRemove);
1002
1030
  return command;
@@ -1006,16 +1034,24 @@ function buildCommandVerificationMethodRemove() {
1006
1034
  * @param opts The options for the command.
1007
1035
  * @param opts.seed The private key for the controller.
1008
1036
  * @param opts.id The id of the verification method to remove.
1037
+ * @param opts.connector The connector to perform the operations with.
1009
1038
  * @param opts.node The node URL.
1010
1039
  * @param opts.explorer The explorer URL.
1040
+ * @param opts.network The network to use for rebased connector.
1011
1041
  */
1012
1042
  async function actionCommandVerificationMethodRemove(opts) {
1013
1043
  const seed = cliCore.CLIParam.hexBase64("seed", opts.seed);
1014
1044
  const id = cliCore.CLIParam.stringValue("id", opts.id);
1015
1045
  const nodeEndpoint = cliCore.CLIParam.url("node", opts.node);
1046
+ const network = opts.connector === IdentityConnectorTypes.IotaRebased
1047
+ ? cliCore.CLIParam.stringValue("network", opts.network)
1048
+ : undefined;
1016
1049
  const explorerEndpoint = cliCore.CLIParam.url("explorer", opts.explorer);
1017
1050
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.verification-method-add.labels.verificationMethodId"), id);
1018
1051
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
1052
+ if (core.Is.stringValue(network)) {
1053
+ cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.network"), network);
1054
+ }
1019
1055
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
1020
1056
  cliCore.CLIDisplay.break();
1021
1057
  setupVault();
@@ -1023,29 +1059,13 @@ async function actionCommandVerificationMethodRemove(opts) {
1023
1059
  const localIdentity = "local";
1024
1060
  const vaultConnector = vaultModels.VaultConnectorFactory.get("vault");
1025
1061
  await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, core.Converter.bytesToBase64(seed));
1026
- const iotaWalletConnector = new walletConnectorIota.IotaWalletConnector({
1027
- config: {
1028
- clientOptions: {
1029
- nodes: [nodeEndpoint],
1030
- localPow: true
1031
- },
1032
- vaultSeedId
1033
- }
1034
- });
1035
- walletModels.WalletConnectorFactory.register("wallet", () => iotaWalletConnector);
1036
- const iotaIdentityConnector = new identityConnectorIota.IotaIdentityConnector({
1037
- config: {
1038
- clientOptions: {
1039
- nodes: [nodeEndpoint],
1040
- localPow: true
1041
- },
1042
- vaultSeedId
1043
- }
1044
- });
1062
+ const walletConnector = walletCli.setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
1063
+ walletModels.WalletConnectorFactory.register("wallet", () => walletConnector);
1064
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network, vaultSeedId }, opts.connector);
1045
1065
  cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.verification-method-remove.progress.removingVerificationMethod"));
1046
1066
  cliCore.CLIDisplay.break();
1047
1067
  cliCore.CLIDisplay.spinnerStart();
1048
- await iotaIdentityConnector.removeVerificationMethod(localIdentity, id);
1068
+ await identityConnector.removeVerificationMethod(localIdentity, id);
1049
1069
  cliCore.CLIDisplay.spinnerStop();
1050
1070
  cliCore.CLIDisplay.value(core.I18n.formatMessage("commands.common.labels.explore"), `${core.StringHelper.trimTrailingSlashes(explorerEndpoint)}/addr/${identityConnectorIota.IotaIdentityUtils.didToAddress(identityModels.DocumentHelper.parse(id).id)}?tab=DID`);
1051
1071
  cliCore.CLIDisplay.break();
@@ -1070,7 +1090,7 @@ class CLI extends cliCore.CLIBase {
1070
1090
  return this.execute({
1071
1091
  title: "TWIN Identity",
1072
1092
  appName: "twin-identity",
1073
- version: "0.0.3-next.18",
1093
+ version: "0.0.1-next.22",
1074
1094
  icon: "🌍",
1075
1095
  supportsEnvFiles: true,
1076
1096
  overrideOutputWidth: options?.overrideOutputWidth
@@ -1104,6 +1124,7 @@ class CLI extends cliCore.CLIBase {
1104
1124
  }
1105
1125
 
1106
1126
  exports.CLI = CLI;
1127
+ exports.IdentityConnectorTypes = IdentityConnectorTypes;
1107
1128
  exports.actionCommandIdentityCreate = actionCommandIdentityCreate;
1108
1129
  exports.actionCommandIdentityResolve = actionCommandIdentityResolve;
1109
1130
  exports.actionCommandProofCreate = actionCommandProofCreate;
@@ -1128,3 +1149,5 @@ exports.buildCommandVerifiableCredentialUnrevoke = buildCommandVerifiableCredent
1128
1149
  exports.buildCommandVerifiableCredentialVerify = buildCommandVerifiableCredentialVerify;
1129
1150
  exports.buildCommandVerificationMethodAdd = buildCommandVerificationMethodAdd;
1130
1151
  exports.buildCommandVerificationMethodRemove = buildCommandVerificationMethodRemove;
1152
+ exports.setupIdentityConnector = setupIdentityConnector;
1153
+ exports.setupVault = setupVault;