@twin.org/identity-cli 0.0.2-next.8 → 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 (55) 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 +40 -98
  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 +65 -0
  52. package/locales/en.json +7 -5
  53. package/package.json +24 -11
  54. package/dist/cjs/index.cjs +0 -1248
  55. package/dist/esm/index.mjs +0 -1216
package/bin/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // SPDX-License-Identifier: Apache-2.0.
4
4
  process.title = 'TWIN Identity';
5
5
 
6
- import { CLI } from '../dist/esm/index.mjs';
6
+ import { CLI } from '../dist/es/index.js';
7
7
 
8
8
  const cli = new CLI();
9
9
  const result = await cli.run(process.argv);
package/dist/es/cli.js ADDED
@@ -0,0 +1,69 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { CLIBase } from "@twin.org/cli-core";
6
+ import { buildCommandAddress, buildCommandMnemonic } from "@twin.org/crypto-cli";
7
+ import { buildCommandFaucet, buildCommandTransfer } from "@twin.org/wallet-cli";
8
+ import { buildCommandIdentityCreate } from "./commands/identityCreate.js";
9
+ import { buildCommandIdentityResolve } from "./commands/identityResolve.js";
10
+ import { buildCommandProofCreate } from "./commands/proofCreate.js";
11
+ import { buildCommandProofVerify } from "./commands/proofVerify.js";
12
+ import { buildCommandServiceAdd } from "./commands/serviceAdd.js";
13
+ import { buildCommandServiceRemove } from "./commands/serviceRemove.js";
14
+ import { buildCommandVerifiableCredentialCreate } from "./commands/verifiableCredentialCreate.js";
15
+ import { buildCommandVerifiableCredentialRevoke } from "./commands/verifiableCredentialRevoke.js";
16
+ import { buildCommandVerifiableCredentialUnrevoke } from "./commands/verifiableCredentialUnrevoke.js";
17
+ import { buildCommandVerifiableCredentialVerify } from "./commands/verifiableCredentialVerify.js";
18
+ import { buildCommandVerificationMethodAdd } from "./commands/verificationMethodAdd.js";
19
+ import { buildCommandVerificationMethodRemove } from "./commands/verificationMethodRemove.js";
20
+ /**
21
+ * The main entry point for the CLI.
22
+ */
23
+ export class CLI extends CLIBase {
24
+ /**
25
+ * Run the app.
26
+ * @param argv The process arguments.
27
+ * @param localesDirectory The directory for the locales, default to relative to the script.
28
+ * @param options Additional options for the CLI.
29
+ * @param options.overrideOutputWidth The override output width.
30
+ * @returns The exit code.
31
+ */
32
+ async run(argv, localesDirectory, options) {
33
+ return this.execute({
34
+ title: "TWIN Identity",
35
+ appName: "twin-identity",
36
+ version: "0.0.3-next.1", // x-release-please-version
37
+ icon: "🌍",
38
+ supportsEnvFiles: true,
39
+ overrideOutputWidth: options?.overrideOutputWidth,
40
+ showDevToolWarning: true
41
+ }, localesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), "../locales"), argv);
42
+ }
43
+ /**
44
+ * Get the commands for the CLI.
45
+ * @param program The main program to add the commands to.
46
+ * @internal
47
+ */
48
+ getCommands(program) {
49
+ return [
50
+ buildCommandMnemonic(),
51
+ buildCommandAddress(),
52
+ buildCommandFaucet(),
53
+ buildCommandTransfer(),
54
+ buildCommandIdentityCreate(),
55
+ buildCommandIdentityResolve(),
56
+ buildCommandVerificationMethodAdd(),
57
+ buildCommandVerificationMethodRemove(),
58
+ buildCommandServiceAdd(),
59
+ buildCommandServiceRemove(),
60
+ buildCommandVerifiableCredentialCreate(),
61
+ buildCommandVerifiableCredentialVerify(),
62
+ buildCommandVerifiableCredentialRevoke(),
63
+ buildCommandVerifiableCredentialUnrevoke(),
64
+ buildCommandProofCreate(),
65
+ buildCommandProofVerify()
66
+ ];
67
+ }
68
+ }
69
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEhF,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,sCAAsC,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,sCAAsC,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,wCAAwC,EAAE,MAAM,4CAA4C,CAAC;AACtG,OAAO,EAAE,sCAAsC,EAAE,MAAM,0CAA0C,CAAC;AAClG,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,oCAAoC,EAAE,MAAM,wCAAwC,CAAC;AAE9F;;GAEG;AACH,MAAM,OAAO,GAAI,SAAQ,OAAO;IAC/B;;;;;;;OAOG;IACI,KAAK,CAAC,GAAG,CACf,IAAc,EACd,gBAAyB,EACzB,OAA0C;QAE1C,OAAO,IAAI,CAAC,OAAO,CAClB;YACC,KAAK,EAAE,eAAe;YACtB,OAAO,EAAE,eAAe;YACxB,OAAO,EAAE,cAAc,EAAE,2BAA2B;YACpD,IAAI,EAAE,IAAI;YACV,gBAAgB,EAAE,IAAI;YACtB,mBAAmB,EAAE,OAAO,EAAE,mBAAmB;YACjD,kBAAkB,EAAE,IAAI;SACxB,EACD,gBAAgB,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,EACzF,IAAI,CACJ,CAAC;IACH,CAAC;IAED;;;;OAIG;IACO,WAAW,CAAC,OAAgB;QACrC,OAAO;YACN,oBAAoB,EAAE;YACtB,mBAAmB,EAAE;YACrB,kBAAkB,EAAE;YACpB,oBAAoB,EAAE;YACtB,0BAA0B,EAAE;YAC5B,2BAA2B,EAAE;YAC7B,iCAAiC,EAAE;YACnC,oCAAoC,EAAE;YACtC,sBAAsB,EAAE;YACxB,yBAAyB,EAAE;YAC3B,sCAAsC,EAAE;YACxC,sCAAsC,EAAE;YACxC,sCAAsC,EAAE;YACxC,wCAAwC,EAAE;YAC1C,uBAAuB,EAAE;YACzB,uBAAuB,EAAE;SACzB,CAAC;IACH,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { CLIBase } from \"@twin.org/cli-core\";\nimport { buildCommandAddress, buildCommandMnemonic } from \"@twin.org/crypto-cli\";\nimport { buildCommandFaucet, buildCommandTransfer } from \"@twin.org/wallet-cli\";\nimport type { Command } from \"commander\";\nimport { buildCommandIdentityCreate } from \"./commands/identityCreate.js\";\nimport { buildCommandIdentityResolve } from \"./commands/identityResolve.js\";\nimport { buildCommandProofCreate } from \"./commands/proofCreate.js\";\nimport { buildCommandProofVerify } from \"./commands/proofVerify.js\";\nimport { buildCommandServiceAdd } from \"./commands/serviceAdd.js\";\nimport { buildCommandServiceRemove } from \"./commands/serviceRemove.js\";\nimport { buildCommandVerifiableCredentialCreate } from \"./commands/verifiableCredentialCreate.js\";\nimport { buildCommandVerifiableCredentialRevoke } from \"./commands/verifiableCredentialRevoke.js\";\nimport { buildCommandVerifiableCredentialUnrevoke } from \"./commands/verifiableCredentialUnrevoke.js\";\nimport { buildCommandVerifiableCredentialVerify } from \"./commands/verifiableCredentialVerify.js\";\nimport { buildCommandVerificationMethodAdd } from \"./commands/verificationMethodAdd.js\";\nimport { buildCommandVerificationMethodRemove } from \"./commands/verificationMethodRemove.js\";\n\n/**\n * The main entry point for the CLI.\n */\nexport class CLI extends CLIBase {\n\t/**\n\t * Run the app.\n\t * @param argv The process arguments.\n\t * @param localesDirectory The directory for the locales, default to relative to the script.\n\t * @param options Additional options for the CLI.\n\t * @param options.overrideOutputWidth The override output width.\n\t * @returns The exit code.\n\t */\n\tpublic async run(\n\t\targv: string[],\n\t\tlocalesDirectory?: string,\n\t\toptions?: { overrideOutputWidth?: number }\n\t): Promise<number> {\n\t\treturn this.execute(\n\t\t\t{\n\t\t\t\ttitle: \"TWIN Identity\",\n\t\t\t\tappName: \"twin-identity\",\n\t\t\t\tversion: \"0.0.3-next.1\", // x-release-please-version\n\t\t\t\ticon: \"🌍\",\n\t\t\t\tsupportsEnvFiles: true,\n\t\t\t\toverrideOutputWidth: options?.overrideOutputWidth,\n\t\t\t\tshowDevToolWarning: true\n\t\t\t},\n\t\t\tlocalesDirectory ?? path.join(path.dirname(fileURLToPath(import.meta.url)), \"../locales\"),\n\t\t\targv\n\t\t);\n\t}\n\n\t/**\n\t * Get the commands for the CLI.\n\t * @param program The main program to add the commands to.\n\t * @internal\n\t */\n\tprotected getCommands(program: Command): Command[] {\n\t\treturn [\n\t\t\tbuildCommandMnemonic(),\n\t\t\tbuildCommandAddress(),\n\t\t\tbuildCommandFaucet(),\n\t\t\tbuildCommandTransfer(),\n\t\t\tbuildCommandIdentityCreate(),\n\t\t\tbuildCommandIdentityResolve(),\n\t\t\tbuildCommandVerificationMethodAdd(),\n\t\t\tbuildCommandVerificationMethodRemove(),\n\t\t\tbuildCommandServiceAdd(),\n\t\t\tbuildCommandServiceRemove(),\n\t\t\tbuildCommandVerifiableCredentialCreate(),\n\t\t\tbuildCommandVerifiableCredentialVerify(),\n\t\t\tbuildCommandVerifiableCredentialRevoke(),\n\t\t\tbuildCommandVerifiableCredentialUnrevoke(),\n\t\t\tbuildCommandProofCreate(),\n\t\t\tbuildCommandProofVerify()\n\t\t];\n\t}\n}\n"]}
@@ -0,0 +1,96 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
4
+ import { Converter, I18n, Is, StringHelper, Urn } from "@twin.org/core";
5
+ import { VaultConnectorFactory } from "@twin.org/vault-models";
6
+ import { setupWalletConnector } from "@twin.org/wallet-cli";
7
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
8
+ import { Command, Option } from "commander";
9
+ import { setupIdentityConnector, setupVault } from "./setupCommands.js";
10
+ import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
11
+ /**
12
+ * Build the identity create command for the CLI.
13
+ * @returns The command.
14
+ */
15
+ export function buildCommandIdentityCreate() {
16
+ const command = new Command();
17
+ command
18
+ .name("identity-create")
19
+ .summary(I18n.formatMessage("commands.identity-create.summary"))
20
+ .description(I18n.formatMessage("commands.identity-create.description"))
21
+ .requiredOption(I18n.formatMessage("commands.identity-create.options.seed.param"), I18n.formatMessage("commands.identity-create.options.seed.description"))
22
+ .option(I18n.formatMessage("commands.identity-create.options.addressIndex.param"), I18n.formatMessage("commands.identity-create.options.addressIndex.description"), "0");
23
+ CLIOptions.output(command, {
24
+ noConsole: true,
25
+ json: true,
26
+ env: true,
27
+ mergeJson: true,
28
+ mergeEnv: true
29
+ });
30
+ command
31
+ .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
32
+ .choices(Object.values(IdentityConnectorTypes))
33
+ .default(IdentityConnectorTypes.Iota))
34
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
35
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
36
+ .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
37
+ .action(actionCommandIdentityCreate);
38
+ return command;
39
+ }
40
+ /**
41
+ * Action the identity create command.
42
+ * @param opts The options for the command.
43
+ * @param opts.seed The private key for the controller.
44
+ * @param opts.connector The connector to perform the operations with.
45
+ * @param opts.node The node URL.
46
+ * @param opts.network The network to use for connector.
47
+ * @param opts.explorer The explorer URL.
48
+ */
49
+ export async function actionCommandIdentityCreate(opts) {
50
+ const seed = CLIParam.hexBase64("seed", opts.seed);
51
+ const nodeEndpoint = CLIParam.url("node", opts.node);
52
+ const network = opts.connector === IdentityConnectorTypes.Iota
53
+ ? CLIParam.stringValue("network", opts.network)
54
+ : undefined;
55
+ const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
56
+ const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
57
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
58
+ if (Is.stringValue(network)) {
59
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
60
+ }
61
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
62
+ CLIDisplay.value(I18n.formatMessage("commands.identity-create.labels.addressIndex"), addressIndex);
63
+ CLIDisplay.break();
64
+ setupVault();
65
+ const vaultSeedId = "local-seed";
66
+ const localIdentity = "local";
67
+ const vaultConnector = VaultConnectorFactory.get("vault");
68
+ await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
69
+ const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
70
+ WalletConnectorFactory.register("wallet", () => walletConnector);
71
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, vaultSeedId, network, addressIndex }, opts.connector);
72
+ CLIDisplay.task(I18n.formatMessage("commands.identity-create.progress.creatingIdentity"));
73
+ CLIDisplay.break();
74
+ CLIDisplay.spinnerStart();
75
+ const document = await identityConnector.createDocument(localIdentity);
76
+ CLIDisplay.spinnerStop();
77
+ if (opts.console) {
78
+ CLIDisplay.value(I18n.formatMessage("commands.identity-create.labels.identity"), document.id);
79
+ CLIDisplay.break();
80
+ }
81
+ if (Is.stringValue(opts?.json)) {
82
+ await CLIUtils.writeJsonFile(opts.json, { did: document.id }, opts.mergeJson);
83
+ }
84
+ if (Is.stringValue(opts?.env)) {
85
+ await CLIUtils.writeEnvFile(opts.env, [`DID="${document.id}"`], opts.mergeEnv);
86
+ }
87
+ if (opts.connector === IdentityConnectorTypes.Iota) {
88
+ const didUrn = Urn.fromValidString(document.id);
89
+ const didParts = didUrn.parts();
90
+ const objectId = didParts[didParts.length - 1];
91
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
92
+ }
93
+ CLIDisplay.break();
94
+ CLIDisplay.done();
95
+ }
96
+ //# sourceMappingURL=identityCreate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,EACpD,GAAG,YAAY,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,WAAW,QAAQ,YAAY,OAAO,EAAE,CAC7F,CAAC;IACH,CAAC;IACD,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the identity create command for the CLI.\n * @returns The command.\n */\nexport function buildCommandIdentityCreate(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"identity-create\")\n\t\t.summary(I18n.formatMessage(\"commands.identity-create.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.identity-create.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.identity-create.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.identity-create.options.seed.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.identity-create.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.identity-create.options.addressIndex.description\"),\n\t\t\t\"0\"\n\t\t);\n\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.action(actionCommandIdentityCreate);\n\n\treturn command;\n}\n\n/**\n * Action the identity create command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.network The network to use for connector.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandIdentityCreate(\n\topts: {\n\t\tseed: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t\texplorer: string;\n\t\taddressIndex?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.explorer\"), explorerEndpoint);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.identity-create.labels.addressIndex\"),\n\t\taddressIndex\n\t);\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst vaultSeedId = \"local-seed\";\n\tconst localIdentity = \"local\";\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));\n\n\tconst walletConnector = setupWalletConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network },\n\t\topts.connector\n\t);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, vaultSeedId, network, addressIndex },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.identity-create.progress.creatingIdentity\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst document = await identityConnector.createDocument(localIdentity);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.identity-create.labels.identity\"), document.id);\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, { did: document.id }, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(opts.env, [`DID=\"${document.id}\"`], opts.mergeEnv);\n\t}\n\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(document.id);\n\t\tconst didParts = didUrn.parts();\n\t\tconst objectId = didParts[didParts.length - 1];\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`\n\t\t);\n\t}\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,87 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
4
+ import { I18n, Is, StringHelper, Urn } from "@twin.org/core";
5
+ import { setupWalletConnector } from "@twin.org/wallet-cli";
6
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
7
+ import { Command, Option } from "commander";
8
+ import { setupIdentityResolverConnector, setupVault } from "./setupCommands.js";
9
+ import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
10
+ /**
11
+ * Build the identity resolve command for the CLI.
12
+ * @returns The command.
13
+ */
14
+ export function buildCommandIdentityResolve() {
15
+ const command = new Command();
16
+ command
17
+ .name("identity-resolve")
18
+ .summary(I18n.formatMessage("commands.identity-resolve.summary"))
19
+ .description(I18n.formatMessage("commands.identity-resolve.description"))
20
+ .requiredOption(I18n.formatMessage("commands.identity-resolve.options.did.param"), I18n.formatMessage("commands.identity-resolve.options.did.description"));
21
+ CLIOptions.output(command, {
22
+ noConsole: true,
23
+ json: true,
24
+ env: false,
25
+ mergeJson: true,
26
+ mergeEnv: false
27
+ });
28
+ command
29
+ .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
30
+ .choices(Object.values(IdentityConnectorTypes))
31
+ .default(IdentityConnectorTypes.Iota))
32
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
33
+ .option(I18n.formatMessage("commands.common.options.explorer.param"), I18n.formatMessage("commands.common.options.explorer.description"), "!EXPLORER_URL")
34
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
35
+ .action(actionCommandIdentityResolve);
36
+ return command;
37
+ }
38
+ /**
39
+ * Action the identity resolve command.
40
+ * @param opts The options for the command.
41
+ * @param opts.did The identity to resolve.
42
+ * @param opts.connector The connector to perform the operations with.
43
+ * @param opts.node The node URL.
44
+ * @param opts.network The network to use for connector.
45
+ * @param opts.explorer The explorer URL.
46
+ */
47
+ export async function actionCommandIdentityResolve(opts) {
48
+ const did = CLIParam.stringValue("did", opts.did);
49
+ const nodeEndpoint = CLIParam.url("node", opts.node);
50
+ const network = opts.connector === IdentityConnectorTypes.Iota
51
+ ? CLIParam.stringValue("network", opts.network)
52
+ : undefined;
53
+ const explorerEndpoint = CLIParam.url("explorer", opts.explorer);
54
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.did"), did);
55
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
56
+ if (Is.stringValue(network)) {
57
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
58
+ }
59
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.explorer"), explorerEndpoint);
60
+ CLIDisplay.break();
61
+ setupVault();
62
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
63
+ WalletConnectorFactory.register("wallet", () => walletConnector);
64
+ const identityResolverConnector = setupIdentityResolverConnector({ nodeEndpoint, network }, opts.connector);
65
+ CLIDisplay.task(I18n.formatMessage("commands.identity-resolve.progress.resolvingIdentity"));
66
+ CLIDisplay.break();
67
+ CLIDisplay.spinnerStart();
68
+ const document = await identityResolverConnector.resolveDocument(did);
69
+ CLIDisplay.spinnerStop();
70
+ if (opts.console) {
71
+ CLIDisplay.section(I18n.formatMessage("commands.identity-resolve.labels.didDocument"));
72
+ CLIDisplay.json(document);
73
+ CLIDisplay.break();
74
+ }
75
+ if (Is.stringValue(opts?.json)) {
76
+ await CLIUtils.writeJsonFile(opts.json, document, opts.mergeJson);
77
+ }
78
+ if (opts.connector === IdentityConnectorTypes.Iota) {
79
+ const didUrn = Urn.fromValidString(document.id);
80
+ const didParts = didUrn.parts();
81
+ const objectId = didParts[didParts.length - 1];
82
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.explore"), `${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`);
83
+ }
84
+ CLIDisplay.break();
85
+ CLIDisplay.done();
86
+ }
87
+ //# sourceMappingURL=identityResolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityResolve.js","sourceRoot":"","sources":["../../../src/commands/identityResolve.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,2BAA2B;IAC1C,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,kBAAkB,CAAC;SACxB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,mCAAmC,CAAC,CAAC;SAChE,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,uCAAuC,CAAC,CAAC;SACxE,cAAc,CACd,IAAI,CAAC,aAAa,CAAC,6CAA6C,CAAC,EACjE,IAAI,CAAC,aAAa,CAAC,mDAAmD,CAAC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AC;IAEzB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,8CAA8C,CAAC,CAAC,CAAC;QAEvF,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,UAAU,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,IAAI,CAAC,SAAS,KAAK,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;QAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAChC,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC/C,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,gCAAgC,CAAC,EACpD,GAAG,YAAY,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,WAAW,QAAQ,YAAY,OAAO,EAAE,CAC7F,CAAC;IACH,CAAC;IACD,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityResolverConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the identity resolve command for the CLI.\n * @returns The command.\n */\nexport function buildCommandIdentityResolve(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"identity-resolve\")\n\t\t.summary(I18n.formatMessage(\"commands.identity-resolve.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.identity-resolve.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.identity-resolve.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.identity-resolve.options.did.description\")\n\t\t);\n\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: false,\n\t\tmergeJson: true,\n\t\tmergeEnv: false\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.explorer.description\"),\n\t\t\t\"!EXPLORER_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.action(actionCommandIdentityResolve);\n\n\treturn command;\n}\n\n/**\n * Action the identity resolve command.\n * @param opts The options for the command.\n * @param opts.did The identity to resolve.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.network The network to use for connector.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandIdentityResolve(\n\topts: {\n\t\tdid: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t\texplorer: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst did: string = CLIParam.stringValue(\"did\", opts.did);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\tconst explorerEndpoint: string = CLIParam.url(\"explorer\", opts.explorer);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.did\"), did);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.explorer\"), explorerEndpoint);\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityResolverConnector = setupIdentityResolverConnector(\n\t\t{ nodeEndpoint, network },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.identity-resolve.progress.resolvingIdentity\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst document = await identityResolverConnector.resolveDocument(did);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.section(I18n.formatMessage(\"commands.identity-resolve.labels.didDocument\"));\n\n\t\tCLIDisplay.json(document);\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, document, opts.mergeJson);\n\t}\n\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(document.id);\n\t\tconst didParts = didUrn.parts();\n\t\tconst objectId = didParts[didParts.length - 1];\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.common.labels.explore\"),\n\t\t\t`${StringHelper.trimTrailingSlashes(explorerEndpoint)}/object/${objectId}?network=${network}`\n\t\t);\n\t}\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,102 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import path from "node:path";
4
+ import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
5
+ import { GeneralError, I18n, Is } from "@twin.org/core";
6
+ import { DocumentHelper } from "@twin.org/identity-models";
7
+ import { ProofTypes } from "@twin.org/standards-w3c-did";
8
+ import { VaultConnectorFactory, VaultKeyType } from "@twin.org/vault-models";
9
+ import { setupWalletConnector } from "@twin.org/wallet-cli";
10
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
11
+ import { Command, Option } from "commander";
12
+ import { setupIdentityConnector, setupVault } from "./setupCommands.js";
13
+ import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
14
+ /**
15
+ * Build the proof create command for the CLI.
16
+ * @returns The command.
17
+ */
18
+ export function buildCommandProofCreate() {
19
+ const command = new Command();
20
+ command
21
+ .name("proof-create")
22
+ .summary(I18n.formatMessage("commands.proof-create.summary"))
23
+ .description(I18n.formatMessage("commands.proof-create.description"))
24
+ .requiredOption(I18n.formatMessage("commands.proof-create.options.id.param"), I18n.formatMessage("commands.proof-create.options.id.description"))
25
+ .requiredOption(I18n.formatMessage("commands.proof-create.options.private-key.param"), I18n.formatMessage("commands.proof-create.options.private-key.description"))
26
+ .requiredOption(I18n.formatMessage("commands.proof-create.options.document-filename.param"), I18n.formatMessage("commands.proof-create.options.document-filename.description"))
27
+ .option(I18n.formatMessage("commands.proof-create.options.addressIndex.param"), I18n.formatMessage("commands.proof-create.options.addressIndex.description"), "0");
28
+ CLIOptions.output(command, {
29
+ noConsole: true,
30
+ json: true,
31
+ env: true,
32
+ mergeJson: true,
33
+ mergeEnv: true
34
+ });
35
+ command
36
+ .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
37
+ .choices(Object.values(IdentityConnectorTypes))
38
+ .default(IdentityConnectorTypes.Iota))
39
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
40
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
41
+ .action(actionCommandProofCreate);
42
+ return command;
43
+ }
44
+ /**
45
+ * Action the proof create command.
46
+ * @param opts The options for the command.
47
+ * @param opts.id The id of the verification method to use for the credential.
48
+ * @param opts.privateKey The private key for the verification method.
49
+ * @param opts.documentFilename The filename of the document to create the proof for.
50
+ * @param opts.addressIndex The address index to use for key derivation (if applicable).
51
+ * @param opts.data The data to create the proof for.
52
+ * @param opts.connector The connector to perform the operations with.
53
+ * @param opts.node The node URL.
54
+ * @param opts.network The network to use for connector.
55
+ */
56
+ export async function actionCommandProofCreate(opts) {
57
+ const id = CLIParam.stringValue("id", opts.id);
58
+ const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
59
+ const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
60
+ const documentFilename = path.resolve(CLIParam.stringValue("document-filename", opts.documentFilename));
61
+ const nodeEndpoint = CLIParam.url("node", opts.node);
62
+ const network = opts.connector === IdentityConnectorTypes.Iota
63
+ ? CLIParam.stringValue("network", opts.network)
64
+ : undefined;
65
+ CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.verificationMethodId"), id);
66
+ CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.documentFilename"), documentFilename);
67
+ CLIDisplay.value(I18n.formatMessage("commands.proof-create.labels.addressIndex"), addressIndex);
68
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
69
+ if (Is.stringValue(network)) {
70
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
71
+ }
72
+ CLIDisplay.break();
73
+ setupVault();
74
+ const localIdentity = "local";
75
+ const vmParts = DocumentHelper.parseId(id);
76
+ const vaultConnector = VaultConnectorFactory.get("vault");
77
+ await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
78
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
79
+ WalletConnectorFactory.register("wallet", () => walletConnector);
80
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex }, opts.connector);
81
+ CLIDisplay.task(I18n.formatMessage("commands.proof-create.progress.creatingProof"));
82
+ CLIDisplay.break();
83
+ CLIDisplay.spinnerStart();
84
+ const document = await CLIUtils.readJsonFile(documentFilename);
85
+ if (Is.undefined(document)) {
86
+ throw new GeneralError("commands", "commands.proof-create.documentJsonFileNotFound");
87
+ }
88
+ const proof = await identityConnector.createProof(localIdentity, id, ProofTypes.DataIntegrityProof, document);
89
+ CLIDisplay.spinnerStop();
90
+ if (opts.console) {
91
+ CLIDisplay.json(proof);
92
+ CLIDisplay.break();
93
+ }
94
+ if (Is.stringValue(opts?.json)) {
95
+ await CLIUtils.writeJsonFile(opts.json, proof, opts.mergeJson);
96
+ }
97
+ if (Is.stringValue(opts?.env)) {
98
+ await CLIUtils.writeEnvFile(opts.env, [`DID_PROOF='${JSON.stringify(proof)}'`], opts.mergeEnv);
99
+ }
100
+ CLIDisplay.done();
101
+ }
102
+ //# sourceMappingURL=proofCreate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proofCreate.js","sourceRoot":"","sources":["../../../src/commands/proofCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,u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AI,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;IACD,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,cAAc,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChG,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\nimport { ProofTypes } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-models\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the proof create command for the CLI.\n * @returns The command.\n */\nexport function buildCommandProofCreate(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"proof-create\")\n\t\t.summary(I18n.formatMessage(\"commands.proof-create.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.proof-create.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.proof-create.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.proof-create.options.id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.proof-create.options.private-key.param\"),\n\t\t\tI18n.formatMessage(\"commands.proof-create.options.private-key.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.proof-create.options.document-filename.param\"),\n\t\t\tI18n.formatMessage(\"commands.proof-create.options.document-filename.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.proof-create.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.proof-create.options.addressIndex.description\"),\n\t\t\t\"0\"\n\t\t);\n\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.action(actionCommandProofCreate);\n\n\treturn command;\n}\n\n/**\n * Action the proof create command.\n * @param opts The options for the command.\n * @param opts.id The id of the verification method to use for the credential.\n * @param opts.privateKey The private key for the verification method.\n * @param opts.documentFilename The filename of the document to create the proof for.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n * @param opts.data The data to create the proof for.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.network The network to use for connector.\n */\nexport async function actionCommandProofCreate(\n\topts: {\n\t\tid: string;\n\t\tprivateKey: string;\n\t\tdocumentFilename: string;\n\t\taddressIndex?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst privateKey: Uint8Array = CLIParam.hexBase64(\"private-key\", opts.privateKey);\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\n\tconst documentFilename: string = path.resolve(\n\t\tCLIParam.stringValue(\"document-filename\", opts.documentFilename)\n\t);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.proof-create.labels.verificationMethodId\"), id);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.proof-create.labels.documentFilename\"),\n\t\tdocumentFilename\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.proof-create.labels.addressIndex\"), addressIndex);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst localIdentity = \"local\";\n\n\tconst vmParts = DocumentHelper.parseId(id);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.addKey(\n\t\t`${localIdentity}/${vmParts.fragment}`,\n\t\tVaultKeyType.Ed25519,\n\t\tprivateKey,\n\t\tnew Uint8Array()\n\t);\n\n\tconst walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector(\n\t\t{ nodeEndpoint, network, addressIndex },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.proof-create.progress.creatingProof\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst document = await CLIUtils.readJsonFile<IJsonLdNodeObject>(documentFilename);\n\tif (Is.undefined(document)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.proof-create.documentJsonFileNotFound\");\n\t}\n\tconst proof = await identityConnector.createProof(\n\t\tlocalIdentity,\n\t\tid,\n\t\tProofTypes.DataIntegrityProof,\n\t\tdocument\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.json(proof);\n\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, proof, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(opts.env, [`DID_PROOF='${JSON.stringify(proof)}'`], opts.mergeEnv);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,92 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import path from "node:path";
4
+ import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
5
+ import { GeneralError, I18n, Is } from "@twin.org/core";
6
+ import { setupWalletConnector } from "@twin.org/wallet-cli";
7
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
8
+ import { Command, Option } from "commander";
9
+ import { setupIdentityConnector, setupVault } from "./setupCommands.js";
10
+ import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
11
+ /**
12
+ * Build the proof verify command for the CLI.
13
+ * @returns The command.
14
+ */
15
+ export function buildCommandProofVerify() {
16
+ const command = new Command();
17
+ command
18
+ .name("proof-verify")
19
+ .summary(I18n.formatMessage("commands.proof-verify.summary"))
20
+ .description(I18n.formatMessage("commands.proof-verify.description"))
21
+ .requiredOption(I18n.formatMessage("commands.proof-verify.options.document-filename.param"), I18n.formatMessage("commands.proof-verify.options.document-filename.description"))
22
+ .requiredOption(I18n.formatMessage("commands.proof-verify.options.proof-filename.param"), I18n.formatMessage("commands.proof-verify.options.proof-filename.description"));
23
+ CLIOptions.output(command, {
24
+ noConsole: true,
25
+ json: true,
26
+ env: true,
27
+ mergeJson: true,
28
+ mergeEnv: true
29
+ });
30
+ command
31
+ .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
32
+ .choices(Object.values(IdentityConnectorTypes))
33
+ .default(IdentityConnectorTypes.Iota))
34
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
35
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
36
+ .action(actionCommandProofVerify);
37
+ return command;
38
+ }
39
+ /**
40
+ * Action the proof verify command.
41
+ * @param opts The options for the command.
42
+ * @param opts.id The id of the verification method to use for the credential.
43
+ * @param opts.documentFilename The data to verify the proof for.
44
+ * @param opts.proofFilename The proof value.
45
+ * @param opts.connector The connector to perform the operations with.
46
+ * @param opts.node The node URL.
47
+ * @param opts.network The network to use for connector.
48
+ */
49
+ export async function actionCommandProofVerify(opts) {
50
+ const documentFilename = path.resolve(CLIParam.stringValue("document-filename", opts.documentFilename));
51
+ const proofFilename = path.resolve(CLIParam.stringValue("proof-filename", opts.proofFilename));
52
+ const nodeEndpoint = CLIParam.url("node", opts.node);
53
+ const network = opts.connector === IdentityConnectorTypes.Iota
54
+ ? CLIParam.stringValue("network", opts.network)
55
+ : undefined;
56
+ CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.documentFilename"), documentFilename);
57
+ CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.proofFilename"), proofFilename);
58
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
59
+ if (Is.stringValue(network)) {
60
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
61
+ }
62
+ CLIDisplay.break();
63
+ setupVault();
64
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
65
+ WalletConnectorFactory.register("wallet", () => walletConnector);
66
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
67
+ CLIDisplay.task(I18n.formatMessage("commands.proof-verify.progress.verifyingProof"));
68
+ CLIDisplay.break();
69
+ CLIDisplay.spinnerStart();
70
+ const document = await CLIUtils.readJsonFile(documentFilename);
71
+ if (Is.undefined(document)) {
72
+ throw new GeneralError("commands", "commands.proof-verify.documentJsonFileNotFound");
73
+ }
74
+ const proof = await CLIUtils.readJsonFile(proofFilename);
75
+ if (Is.undefined(proof)) {
76
+ throw new GeneralError("commands", "commands.proof-verify.proofJsonFileNotFound");
77
+ }
78
+ const isVerified = await identityConnector.verifyProof(document, proof);
79
+ CLIDisplay.spinnerStop();
80
+ if (opts.console) {
81
+ CLIDisplay.value(I18n.formatMessage("commands.proof-verify.labels.isVerified"), isVerified);
82
+ CLIDisplay.break();
83
+ }
84
+ if (Is.stringValue(opts?.json)) {
85
+ await CLIUtils.writeJsonFile(opts.json, { isVerified }, opts.mergeJson);
86
+ }
87
+ if (Is.stringValue(opts?.env)) {
88
+ await CLIUtils.writeEnvFile(opts.env, [`DID_PROOF_VERIFIED="${isVerified}"`], opts.mergeEnv);
89
+ }
90
+ CLIDisplay.done();
91
+ }
92
+ //# sourceMappingURL=proofVerify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proofVerify.js","sourceRoot":"","sources":["../../../src/commands/proofVerify.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAg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AAC,yCAAyC,CAAC,EAAE,UAAU,CAAC,CAAC;QAE5F,UAAU,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,uBAAuB,UAAU,GAAG,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC9F,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IProof } from \"@twin.org/standards-w3c-did\";\nimport { setupWalletConnector } from \"@twin.org/wallet-cli\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { Command, Option } from \"commander\";\nimport { setupIdentityConnector, setupVault } from \"./setupCommands.js\";\nimport { IdentityConnectorTypes } from \"../models/identityConnectorTypes.js\";\n\n/**\n * Build the proof verify command for the CLI.\n * @returns The command.\n */\nexport function buildCommandProofVerify(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"proof-verify\")\n\t\t.summary(I18n.formatMessage(\"commands.proof-verify.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.proof-verify.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.proof-verify.options.document-filename.param\"),\n\t\t\tI18n.formatMessage(\"commands.proof-verify.options.document-filename.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.proof-verify.options.proof-filename.param\"),\n\t\t\tI18n.formatMessage(\"commands.proof-verify.options.proof-filename.description\")\n\t\t);\n\tCLIOptions.output(command, {\n\t\tnoConsole: true,\n\t\tjson: true,\n\t\tenv: true,\n\t\tmergeJson: true,\n\t\tmergeEnv: true\n\t});\n\n\tcommand\n\t\t.addOption(\n\t\t\tnew Option(\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.param\"),\n\t\t\t\tI18n.formatMessage(\"commands.common.options.connector.description\")\n\t\t\t)\n\t\t\t\t.choices(Object.values(IdentityConnectorTypes))\n\t\t\t\t.default(IdentityConnectorTypes.Iota)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.node.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.node.description\"),\n\t\t\t\"!NODE_URL\"\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.common.options.network.param\"),\n\t\t\tI18n.formatMessage(\"commands.common.options.network.description\"),\n\t\t\t\"!NETWORK\"\n\t\t)\n\t\t.action(actionCommandProofVerify);\n\n\treturn command;\n}\n\n/**\n * Action the proof verify command.\n * @param opts The options for the command.\n * @param opts.id The id of the verification method to use for the credential.\n * @param opts.documentFilename The data to verify the proof for.\n * @param opts.proofFilename The proof value.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.network The network to use for connector.\n */\nexport async function actionCommandProofVerify(\n\topts: {\n\t\tdocumentFilename: string;\n\t\tproofFilename: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst documentFilename: string = path.resolve(\n\t\tCLIParam.stringValue(\"document-filename\", opts.documentFilename)\n\t);\n\tconst proofFilename: string = path.resolve(\n\t\tCLIParam.stringValue(\"proof-filename\", opts.proofFilename)\n\t);\n\tconst nodeEndpoint: string = CLIParam.url(\"node\", opts.node);\n\tconst network: string | undefined =\n\t\topts.connector === IdentityConnectorTypes.Iota\n\t\t\t? CLIParam.stringValue(\"network\", opts.network)\n\t\t\t: undefined;\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.proof-verify.labels.documentFilename\"),\n\t\tdocumentFilename\n\t);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.proof-verify.labels.proofFilename\"), proofFilename);\n\n\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.node\"), nodeEndpoint);\n\tif (Is.stringValue(network)) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.common.labels.network\"), network);\n\t}\n\tCLIDisplay.break();\n\n\tsetupVault();\n\n\tconst walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);\n\tWalletConnectorFactory.register(\"wallet\", () => walletConnector);\n\n\tconst identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.proof-verify.progress.verifyingProof\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst document = await CLIUtils.readJsonFile<IJsonLdNodeObject>(documentFilename);\n\tif (Is.undefined(document)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.proof-verify.documentJsonFileNotFound\");\n\t}\n\n\tconst proof = await CLIUtils.readJsonFile<IProof>(proofFilename);\n\tif (Is.undefined(proof)) {\n\t\tthrow new GeneralError(\"commands\", \"commands.proof-verify.proofJsonFileNotFound\");\n\t}\n\n\tconst isVerified = await identityConnector.verifyProof(document, proof);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.proof-verify.labels.isVerified\"), isVerified);\n\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, { isVerified }, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(opts.env, [`DID_PROOF_VERIFIED=\"${isVerified}\"`], opts.mergeEnv);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}