@twin.org/identity-cli 0.0.3-next.2 → 0.0.3-next.20

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 (49) hide show
  1. package/README.md +5 -5
  2. package/dist/es/cli.js +9 -1
  3. package/dist/es/cli.js.map +1 -1
  4. package/dist/es/commands/alsoKnownAsAdd.js +108 -0
  5. package/dist/es/commands/alsoKnownAsAdd.js.map +1 -0
  6. package/dist/es/commands/alsoKnownAsRemove.js +106 -0
  7. package/dist/es/commands/alsoKnownAsRemove.js.map +1 -0
  8. package/dist/es/commands/identityCreate.js +2 -1
  9. package/dist/es/commands/identityCreate.js.map +1 -1
  10. package/dist/es/commands/proofCreate.js +4 -9
  11. package/dist/es/commands/proofCreate.js.map +1 -1
  12. package/dist/es/commands/serviceAdd.js +4 -3
  13. package/dist/es/commands/serviceAdd.js.map +1 -1
  14. package/dist/es/commands/serviceRemove.js +3 -3
  15. package/dist/es/commands/serviceRemove.js.map +1 -1
  16. package/dist/es/commands/verifiableCredentialCreate.js +18 -16
  17. package/dist/es/commands/verifiableCredentialCreate.js.map +1 -1
  18. package/dist/es/commands/verifiableCredentialVerify.js +24 -5
  19. package/dist/es/commands/verifiableCredentialVerify.js.map +1 -1
  20. package/dist/es/commands/verifiablePresentationCreate.js +137 -0
  21. package/dist/es/commands/verifiablePresentationCreate.js.map +1 -0
  22. package/dist/es/commands/verifiablePresentationVerify.js +107 -0
  23. package/dist/es/commands/verifiablePresentationVerify.js.map +1 -0
  24. package/dist/es/commands/verificationMethodAdd.js +31 -10
  25. package/dist/es/commands/verificationMethodAdd.js.map +1 -1
  26. package/dist/es/index.js +2 -0
  27. package/dist/es/index.js.map +1 -1
  28. package/dist/locales/en.json +196 -38
  29. package/dist/types/commands/alsoKnownAsAdd.d.ts +30 -0
  30. package/dist/types/commands/alsoKnownAsRemove.d.ts +30 -0
  31. package/dist/types/commands/identityCreate.d.ts +1 -0
  32. package/dist/types/commands/proofCreate.d.ts +0 -2
  33. package/dist/types/commands/verifiableCredentialCreate.d.ts +4 -4
  34. package/dist/types/commands/verifiableCredentialVerify.d.ts +3 -1
  35. package/dist/types/commands/verifiablePresentationCreate.d.ts +32 -0
  36. package/dist/types/commands/verifiablePresentationVerify.d.ts +24 -0
  37. package/dist/types/index.d.ts +2 -0
  38. package/docs/changelog.md +404 -90
  39. package/docs/reference/classes/CLI.md +1 -1
  40. package/docs/reference/functions/actionCommandVerifiablePresentationCreate.md +17 -0
  41. package/docs/reference/functions/actionCommandVerifiablePresentationVerify.md +17 -0
  42. package/docs/reference/functions/buildCommandVerifiablePresentationCreate.md +11 -0
  43. package/docs/reference/functions/buildCommandVerifiablePresentationVerify.md +11 -0
  44. package/docs/reference/index.md +4 -0
  45. package/docs/reference/variables/IdentityConnectorTypes.md +1 -1
  46. package/docs/reference/variables/IdentityResolverConnectorTypes.md +1 -1
  47. package/docs/{examples.md → usage.md} +23 -27
  48. package/locales/en.json +153 -12
  49. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"serviceAdd.js","sourceRoot":"","sources":["../../../src/commands/serviceAdd.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,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,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAA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,CAAC,GAAG,EACR;YACC,mBAAmB,OAAO,CAAC,EAAE,GAAG;YAChC,qBAAqB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG;YACvF,yBAAyB,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG;SAC5H,EACD,IAAI,CAAC,QAAQ,CACb,CAAC;IACH,CAAC;IAED,IAAI,IAAI,CAAC,SAAS,KAAK,sBAAsB,CAAC,IAAI,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACxC,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;IAED,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 service add command for the CLI.\n * @returns The command.\n */\nexport function buildCommandServiceAdd(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"service-add\")\n\t\t.summary(I18n.formatMessage(\"commands.service-add.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.service-add.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.did.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.type.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.type.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.endpoint.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.endpoint.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.addressIndex.description\"),\n\t\t\t\"0\"\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.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(actionCommandServiceAdd);\n\n\treturn command;\n}\n\n/**\n * Action the service add command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.did The identity of the document to add to.\n * @param opts.id The id of the service to add.\n * @param opts.type The type of the service to add.\n * @param opts.endpoint The service endpoint.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandServiceAdd(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\tid: string;\n\t\ttype: string;\n\t\tendpoint: string;\n\t\taddressIndex?: 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 seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst did: string = CLIParam.stringValue(\"did\", opts.did);\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst type: string = CLIParam.stringValue(\"type\", opts.type);\n\tconst endpoint: string = CLIParam.url(\"endpoint\", opts.endpoint);\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\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.service-add.labels.serviceId\"), id);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.serviceType\"), type);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.serviceEndpoint\"), endpoint);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.addressIndex\"), addressIndex);\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 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, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.service-add.progress.addingService\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst service = await identityConnector.addService(localIdentity, did, id, type, endpoint);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_SERVICE_ID=\"${service.id}\"`,\n\t\t\t\t`DID_SERVICE_TYPE=\"${Is.string(service.type) ? service.type : service.type.join(\",\")}\"`,\n\t\t\t\t`DID_SERVICE_ENDPOINT=\"${Is.string(service.serviceEndpoint) ? service.serviceEndpoint : service.serviceEndpoint.join(\",\")}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(did);\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\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
1
+ {"version":3,"file":"serviceAdd.js","sourceRoot":"","sources":["../../../src/commands/serviceAdd.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,UAAU,EACV,UAAU,EACV,QAAQ,EACR,QAAQ,EAER,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB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ier: 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 { DocumentHelper } from \"@twin.org/identity-models\";\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 service add command for the CLI.\n * @returns The command.\n */\nexport function buildCommandServiceAdd(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"service-add\")\n\t\t.summary(I18n.formatMessage(\"commands.service-add.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.service-add.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.did.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.did.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.type.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.type.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.endpoint.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.endpoint.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.service-add.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-add.options.addressIndex.description\"),\n\t\t\t\"0\"\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.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(actionCommandServiceAdd);\n\n\treturn command;\n}\n\n/**\n * Action the service add command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.did The identity of the document to add to.\n * @param opts.id The id of the service to add.\n * @param opts.type The type of the service to add.\n * @param opts.endpoint The service endpoint.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.explorer The explorer URL.\n */\nexport async function actionCommandServiceAdd(\n\topts: {\n\t\tseed: string;\n\t\tdid: string;\n\t\tid: string;\n\t\ttype: string;\n\t\tendpoint: string;\n\t\taddressIndex?: 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 seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst did: string = CLIParam.stringValue(\"did\", opts.did);\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst type: string = CLIParam.stringValue(\"type\", opts.type);\n\tconst endpoint: string = CLIParam.url(\"endpoint\", opts.endpoint);\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\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.service-add.labels.serviceId\"), id);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.serviceType\"), type);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.serviceEndpoint\"), endpoint);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-add.labels.addressIndex\"), addressIndex);\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 vaultSeedId = \"local-seed\";\n\tconst vmParts = DocumentHelper.parseId(did);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${vmParts.id}/${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, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.service-add.progress.addingService\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst service = await identityConnector.addService(vmParts.id, did, id, type, endpoint);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, service, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_SERVICE_ID=\"${service.id}\"`,\n\t\t\t\t`DID_SERVICE_TYPE=\"${Is.string(service.type) ? service.type : service.type.join(\",\")}\"`,\n\t\t\t\t`DID_SERVICE_ENDPOINT=\"${Is.string(service.serviceEndpoint) ? service.serviceEndpoint : service.serviceEndpoint.join(\",\")}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(did);\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\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -69,16 +69,16 @@ export async function actionCommandServiceRemove(opts) {
69
69
  CLIDisplay.break();
70
70
  setupVault();
71
71
  const vaultSeedId = "local-seed";
72
- const localIdentity = "local";
72
+ const vmParts = DocumentHelper.parseId(id);
73
73
  const vaultConnector = VaultConnectorFactory.get("vault");
74
- await vaultConnector.setSecret(`${localIdentity}/${vaultSeedId}`, Converter.bytesToBase64(seed));
74
+ await vaultConnector.setSecret(`${vmParts.id}/${vaultSeedId}`, Converter.bytesToBase64(seed));
75
75
  const walletConnector = setupWalletConnector({ nodeEndpoint, vaultSeedId, network }, opts.connector);
76
76
  WalletConnectorFactory.register("wallet", () => walletConnector);
77
77
  const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex, vaultSeedId }, opts.connector);
78
78
  CLIDisplay.task(I18n.formatMessage("commands.service-remove.progress.removingService"));
79
79
  CLIDisplay.break();
80
80
  CLIDisplay.spinnerStart();
81
- await identityConnector.removeService(localIdentity, id);
81
+ await identityConnector.removeService(vmParts.id, id);
82
82
  CLIDisplay.spinnerStop();
83
83
  const did = DocumentHelper.parseId(id).id;
84
84
  if (opts.connector === IdentityConnectorTypes.Iota) {
@@ -1 +1 @@
1
- {"version":3,"file":"serviceRemove.js","sourceRoot":"","sources":["../../../src/commands/serviceRemove.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,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,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACxC,MAAM,OAAO,GAAG,IAAI,O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AAsB,CAAC,IAAI,EAAE,CAAC;QACpD,MAAM,MAAM,GAAG,GAAG,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QACxC,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;IAED,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 { CLIDisplay, CLIOptions, CLIParam } from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\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 service remove command for the CLI.\n * @returns The command.\n */\nexport function buildCommandServiceRemove(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"service-remove\")\n\t\t.summary(I18n.formatMessage(\"commands.service-remove.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.service-remove.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.id.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.addressIndex.description\"),\n\t\t\t\"0\"\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.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(actionCommandServiceRemove);\n\n\treturn command;\n}\n\n/**\n * Action the service remove command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.id The id of the service to remove.\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 * @param opts.addressIndex The address index to use for key derivation (if applicable).\n */\nexport async function actionCommandServiceRemove(opts: {\n\tseed: string;\n\tid: string;\n\taddressIndex?: string;\n\tconnector?: IdentityConnectorTypes;\n\tnode: string;\n\tnetwork?: string;\n\texplorer: string;\n}): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\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.service-remove.labels.serviceId\"), id);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-remove.labels.addressIndex\"), addressIndex);\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 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, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.service-remove.progress.removingService\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.removeService(localIdentity, id);\n\n\tCLIDisplay.spinnerStop();\n\n\tconst did = DocumentHelper.parseId(id).id;\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(did);\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\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
1
+ {"version":3,"file":"serviceRemove.js","sourceRoot":"","sources":["../../../src/commands/serviceRemove.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,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,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACxC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,gBAAgB,CAAC;SACtB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,iCAAiC,CAAC,CAAC;SAC9D,WAAW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G,CAAC,CAAC;QACxC,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;IAED,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 { CLIDisplay, CLIOptions, CLIParam } from \"@twin.org/cli-core\";\nimport { Converter, I18n, Is, StringHelper, Urn } from \"@twin.org/core\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\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 service remove command for the CLI.\n * @returns The command.\n */\nexport function buildCommandServiceRemove(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"service-remove\")\n\t\t.summary(I18n.formatMessage(\"commands.service-remove.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.service-remove.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.seed.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.seed.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.id.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.service-remove.options.addressIndex.description\"),\n\t\t\t\"0\"\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.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(actionCommandServiceRemove);\n\n\treturn command;\n}\n\n/**\n * Action the service remove command.\n * @param opts The options for the command.\n * @param opts.seed The private key for the controller.\n * @param opts.id The id of the service to remove.\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 * @param opts.addressIndex The address index to use for key derivation (if applicable).\n */\nexport async function actionCommandServiceRemove(opts: {\n\tseed: string;\n\tid: string;\n\taddressIndex?: string;\n\tconnector?: IdentityConnectorTypes;\n\tnode: string;\n\tnetwork?: string;\n\texplorer: string;\n}): Promise<void> {\n\tconst seed: Uint8Array = CLIParam.hexBase64(\"seed\", opts.seed);\n\tconst id: string = CLIParam.stringValue(\"id\", opts.id);\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\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.service-remove.labels.serviceId\"), id);\n\tCLIDisplay.value(I18n.formatMessage(\"commands.service-remove.labels.addressIndex\"), addressIndex);\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 vaultSeedId = \"local-seed\";\n\tconst vmParts = DocumentHelper.parseId(id);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.setSecret(`${vmParts.id}/${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, network, addressIndex, vaultSeedId },\n\t\topts.connector\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"commands.service-remove.progress.removingService\"));\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tawait identityConnector.removeService(vmParts.id, id);\n\n\tCLIDisplay.spinnerStop();\n\n\tconst did = DocumentHelper.parseId(id).id;\n\tif (opts.connector === IdentityConnectorTypes.Iota) {\n\t\tconst didUrn = Urn.fromValidString(did);\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\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -20,12 +20,12 @@ export function buildCommandVerifiableCredentialCreate() {
20
20
  .name("verifiable-credential-create")
21
21
  .summary(I18n.formatMessage("commands.verifiable-credential-create.summary"))
22
22
  .description(I18n.formatMessage("commands.verifiable-credential-create.description"))
23
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.id.description"))
23
+ .requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.verification-method-id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.verification-method-id.description"))
24
24
  .requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.private-key.param"), I18n.formatMessage("commands.verifiable-credential-create.options.private-key.description"))
25
25
  .option(I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.param"), I18n.formatMessage("commands.verifiable-credential-create.options.credential-id.description"))
26
26
  .requiredOption(I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.param"), I18n.formatMessage("commands.verifiable-credential-create.options.subject-json.description"))
27
- .option(I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.description"))
28
- .option(I18n.formatMessage("commands.verifiable-credential-create.options.addressIndex.param"), I18n.formatMessage("commands.verifiable-credential-create.options.addressIndex.description"), "0");
27
+ .option(I18n.formatMessage("commands.verifiable-credential-create.options.expiration-date.param"), I18n.formatMessage("commands.verifiable-credential-create.options.expiration-date.description"))
28
+ .option(I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.param"), I18n.formatMessage("commands.verifiable-credential-create.options.revocation-index.description"));
29
29
  CLIOptions.output(command, {
30
30
  noConsole: true,
31
31
  json: true,
@@ -45,44 +45,42 @@ export function buildCommandVerifiableCredentialCreate() {
45
45
  /**
46
46
  * Action the verifiable credential create command.
47
47
  * @param opts The options for the command.
48
- * @param opts.id The id of the verification method to use for the credential.
48
+ * @param opts.verificationMethodId The id of the verification method to use for the credential.
49
49
  * @param opts.privateKey The private key for the verification method.
50
50
  * @param opts.credentialId The id of the credential.
51
51
  * @param opts.subjectJson The JSON data for the subject.
52
+ * @param opts.expirationDate The expiration date for the credential.
52
53
  * @param opts.revocationIndex The revocation index for the credential.
53
- * @param opts.addressIndex The address index to use for key derivation (if applicable).
54
54
  * @param opts.connector The connector to perform the operations with.
55
55
  * @param opts.node The node URL.
56
56
  */
57
57
  export async function actionCommandVerifiableCredentialCreate(opts) {
58
- const id = CLIParam.stringValue("id", opts.id);
58
+ const verificationMethodId = CLIParam.stringValue("verification-method-id", opts.verificationMethodId);
59
59
  const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
60
60
  const credentialId = CLIParam.stringValue("credential-id", opts.credentialId);
61
61
  const subjectJson = path.resolve(CLIParam.stringValue("subject-json", opts.subjectJson));
62
62
  const revocationIndex = Coerce.number(opts.revocationIndex);
63
- const addressIndex = CLIParam.integer("addressIndex", opts.addressIndex ?? "0", false, 0);
64
63
  const nodeEndpoint = CLIParam.url("node", opts.node);
65
64
  const network = opts.connector === IdentityConnectorTypes.Iota
66
65
  ? CLIParam.stringValue("network", opts.network)
67
66
  : undefined;
68
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.verificationMethodId"), id);
67
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.verificationMethodId"), verificationMethodId);
69
68
  CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.credentialId"), credentialId);
70
69
  CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.subjectJson"), subjectJson);
71
70
  CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.revocationIndex"), revocationIndex);
72
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.addressIndex"), addressIndex);
71
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-create.labels.expirationDate"), opts.expirationDate);
73
72
  CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
74
73
  if (Is.stringValue(network)) {
75
74
  CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
76
75
  }
77
76
  CLIDisplay.break();
78
77
  setupVault();
79
- const localIdentity = "local";
80
- const vmParts = DocumentHelper.parseId(id);
78
+ const vmParts = DocumentHelper.parseId(verificationMethodId);
81
79
  const vaultConnector = VaultConnectorFactory.get("vault");
82
- await vaultConnector.addKey(`${localIdentity}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
80
+ await vaultConnector.addKey(`${vmParts.id}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
83
81
  const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
84
82
  WalletConnectorFactory.register("wallet", () => walletConnector);
85
- const identityConnector = setupIdentityConnector({ nodeEndpoint, network, addressIndex }, opts.connector);
83
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
86
84
  CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.loadingSubjectData"));
87
85
  CLIDisplay.break();
88
86
  const jsonData = await CLIUtils.readJsonFile(subjectJson);
@@ -92,8 +90,9 @@ export async function actionCommandVerifiableCredentialCreate(opts) {
92
90
  CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-create.progress.creatingVerifiableCredential"));
93
91
  CLIDisplay.break();
94
92
  CLIDisplay.spinnerStart();
95
- const verifiableCredential = await identityConnector.createVerifiableCredential(localIdentity, id, credentialId, jsonData, {
96
- revocationIndex
93
+ const verifiableCredential = await identityConnector.createVerifiableCredential(vmParts.id, verificationMethodId, credentialId, jsonData, {
94
+ revocationIndex,
95
+ expirationDate: Coerce.dateTime(opts.expirationDate)
97
96
  });
98
97
  CLIDisplay.spinnerStop();
99
98
  if (opts.console) {
@@ -103,7 +102,10 @@ export async function actionCommandVerifiableCredentialCreate(opts) {
103
102
  CLIDisplay.break();
104
103
  }
105
104
  if (Is.stringValue(opts?.json)) {
106
- await CLIUtils.writeJsonFile(opts.json, { verifiableCredentialJwt: verifiableCredential.jwt }, opts.mergeJson);
105
+ await CLIUtils.writeJsonFile(opts.json, {
106
+ verifiableCredentialJwt: verifiableCredential.jwt,
107
+ verifiableCredential: verifiableCredential.verifiableCredential
108
+ }, opts.mergeJson);
107
109
  }
108
110
  if (Is.stringValue(opts?.env)) {
109
111
  await CLIUtils.writeEnvFile(opts.env, [`DID_VERIFIABLE_CREDENTIAL_JWT="${verifiableCredential.jwt}"`], opts.mergeEnv);
@@ -1 +1 @@
1
- {"version":3,"file":"verifiableCredentialCreate.js","sourceRoot":"","sources":["../../../src/commands/verifiableCredentialCreate.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,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC7E,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,sBAAsB,EAAE,UAAU,EAAE,M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KAAK,EAAE,CAAC;QACnB,UAAU,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,QAAQ,CAAC,aAAa,CAC3B,IAAI,CAAC,IAAI,EACT,EAAE,uBAAuB,EAAE,oBAAoB,CAAC,GAAG,EAAE,EACrD,IAAI,CAAC,SAAS,CACd,CAAC;IACH,CAAC;IACD,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAC1B,IAAI,CAAC,GAAG,EACR,CAAC,kCAAkC,oBAAoB,CAAC,GAAG,GAAG,CAAC,EAC/D,IAAI,CAAC,QAAQ,CACb,CAAC;IACH,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 { Coerce, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\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 verifiable credential create command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiableCredentialCreate(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-credential-create\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-credential-create.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-credential-create.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.private-key.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.private-key.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.credential-id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.credential-id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.subject-json.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.subject-json.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.revocation-index.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-create.options.revocation-index.description\"\n\t\t\t)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.addressIndex.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.addressIndex.description\"),\n\t\t\t\"0\"\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(actionCommandVerifiableCredentialCreate);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable credential 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.credentialId The id of the credential.\n * @param opts.subjectJson The JSON data for the subject.\n * @param opts.revocationIndex The revocation index for the credential.\n * @param opts.addressIndex The address index to use for key derivation (if applicable).\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n */\nexport async function actionCommandVerifiableCredentialCreate(\n\topts: {\n\t\tid: string;\n\t\tprivateKey: string;\n\t\tcredentialId?: string;\n\t\tsubjectJson: string;\n\t\trevocationIndex?: 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 credentialId: string = CLIParam.stringValue(\"credential-id\", opts.credentialId);\n\tconst subjectJson: string = path.resolve(CLIParam.stringValue(\"subject-json\", opts.subjectJson));\n\tconst revocationIndex: number | undefined = Coerce.number(opts.revocationIndex);\n\tconst addressIndex: number = CLIParam.integer(\"addressIndex\", opts.addressIndex ?? \"0\", false, 0);\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.verifiable-credential-create.labels.verificationMethodId\"),\n\t\tid\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.credentialId\"),\n\t\tcredentialId\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.subjectJson\"),\n\t\tsubjectJson\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.revocationIndex\"),\n\t\trevocationIndex\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.addressIndex\"),\n\t\taddressIndex\n\t);\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(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.progress.loadingSubjectData\")\n\t);\n\tCLIDisplay.break();\n\n\tconst jsonData = await CLIUtils.readJsonFile<IJsonLdNodeObject>(subjectJson);\n\tif (Is.undefined(jsonData)) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.verifiable-credential-create.subjectJsonFileNotFound\"\n\t\t);\n\t}\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\n\t\t\t\"commands.verifiable-credential-create.progress.creatingVerifiableCredential\"\n\t\t)\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verifiableCredential = await identityConnector.createVerifiableCredential(\n\t\tlocalIdentity,\n\t\tid,\n\t\tcredentialId,\n\t\tjsonData,\n\t\t{\n\t\t\trevocationIndex\n\t\t}\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.verifiableCredential\")\n\t\t);\n\n\t\tCLIDisplay.write(verifiableCredential.jwt);\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(\n\t\t\topts.json,\n\t\t\t{ verifiableCredentialJwt: verifiableCredential.jwt },\n\t\t\topts.mergeJson\n\t\t);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[`DID_VERIFIABLE_CREDENTIAL_JWT=\"${verifiableCredential.jwt}\"`],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
1
+ {"version":3,"file":"verifiableCredentialCreate.js","sourceRoot":"","sources":["../../../src/commands/verifiableCredentialCreate.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,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC7E,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jB,IAAI,CAAC,aAAa,CAAC,mEAAmE,CAAC,CACvF,CAAC;QAEF,UAAU,CAAC,KAAK,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAC3C,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,UAAU,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QAChC,MAAM,QAAQ,CAAC,aAAa,CAC3B,IAAI,CAAC,IAAI,EACT;YACC,uBAAuB,EAAE,oBAAoB,CAAC,GAAG;YACjD,oBAAoB,EAAE,oBAAoB,CAAC,oBAAoB;SAC/D,EACD,IAAI,CAAC,SAAS,CACd,CAAC;IACH,CAAC;IACD,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAC1B,IAAI,CAAC,GAAG,EACR,CAAC,kCAAkC,oBAAoB,CAAC,GAAG,GAAG,CAAC,EAC/D,IAAI,CAAC,QAAQ,CACb,CAAC;IACH,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 { Coerce, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\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 verifiable credential create command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiableCredentialCreate(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-credential-create\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-credential-create.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-credential-create.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-create.options.verification-method-id.param\"\n\t\t\t),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-create.options.verification-method-id.description\"\n\t\t\t)\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.private-key.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.private-key.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.credential-id.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.credential-id.description\")\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.subject-json.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.subject-json.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.expiration-date.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-create.options.expiration-date.description\"\n\t\t\t)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.options.revocation-index.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-credential-create.options.revocation-index.description\"\n\t\t\t)\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(actionCommandVerifiableCredentialCreate);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable credential create command.\n * @param opts The options for the command.\n * @param opts.verificationMethodId 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.credentialId The id of the credential.\n * @param opts.subjectJson The JSON data for the subject.\n * @param opts.expirationDate The expiration date for the credential.\n * @param opts.revocationIndex The revocation index for the credential.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n */\nexport async function actionCommandVerifiableCredentialCreate(\n\topts: {\n\t\tverificationMethodId: string;\n\t\tprivateKey: string;\n\t\tcredentialId?: string;\n\t\tsubjectJson: string;\n\t\texpirationDate?: string;\n\t\trevocationIndex?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst verificationMethodId: string = CLIParam.stringValue(\n\t\t\"verification-method-id\",\n\t\topts.verificationMethodId\n\t);\n\tconst privateKey: Uint8Array = CLIParam.hexBase64(\"private-key\", opts.privateKey);\n\tconst credentialId: string = CLIParam.stringValue(\"credential-id\", opts.credentialId);\n\tconst subjectJson: string = path.resolve(CLIParam.stringValue(\"subject-json\", opts.subjectJson));\n\tconst revocationIndex: number | undefined = Coerce.number(opts.revocationIndex);\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.verifiable-credential-create.labels.verificationMethodId\"),\n\t\tverificationMethodId\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.credentialId\"),\n\t\tcredentialId\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.subjectJson\"),\n\t\tsubjectJson\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.revocationIndex\"),\n\t\trevocationIndex\n\t);\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.expirationDate\"),\n\t\topts.expirationDate\n\t);\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 vmParts = DocumentHelper.parseId(verificationMethodId);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.addKey(\n\t\t`${vmParts.id}/${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({ nodeEndpoint, network }, opts.connector);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-create.progress.loadingSubjectData\")\n\t);\n\tCLIDisplay.break();\n\n\tconst jsonData = await CLIUtils.readJsonFile<IJsonLdNodeObject>(subjectJson);\n\tif (Is.undefined(jsonData)) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.verifiable-credential-create.subjectJsonFileNotFound\"\n\t\t);\n\t}\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\n\t\t\t\"commands.verifiable-credential-create.progress.creatingVerifiableCredential\"\n\t\t)\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verifiableCredential = await identityConnector.createVerifiableCredential(\n\t\tvmParts.id,\n\t\tverificationMethodId,\n\t\tcredentialId,\n\t\tjsonData,\n\t\t{\n\t\t\trevocationIndex,\n\t\t\texpirationDate: Coerce.dateTime(opts.expirationDate)\n\t\t}\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-create.labels.verifiableCredential\")\n\t\t);\n\n\t\tCLIDisplay.write(verifiableCredential.jwt);\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(\n\t\t\topts.json,\n\t\t\t{\n\t\t\t\tverifiableCredentialJwt: verifiableCredential.jwt,\n\t\t\t\tverifiableCredential: verifiableCredential.verifiableCredential\n\t\t\t},\n\t\t\topts.mergeJson\n\t\t);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[`DID_VERIFIABLE_CREDENTIAL_JWT=\"${verifiableCredential.jwt}\"`],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  // Copyright 2024 IOTA Stiftung.
2
2
  // SPDX-License-Identifier: Apache-2.0.
3
+ import path from "node:path";
3
4
  import { CLIDisplay, CLIOptions, CLIParam, CLIUtils } from "@twin.org/cli-core";
4
- import { I18n, Is } from "@twin.org/core";
5
+ import { GeneralError, I18n, Is } from "@twin.org/core";
5
6
  import { setupWalletConnector } from "@twin.org/wallet-cli";
6
7
  import { WalletConnectorFactory } from "@twin.org/wallet-models";
7
8
  import { Command, Option } from "commander";
@@ -17,7 +18,8 @@ export function buildCommandVerifiableCredentialVerify() {
17
18
  .name("verifiable-credential-verify")
18
19
  .summary(I18n.formatMessage("commands.verifiable-credential-verify.summary"))
19
20
  .description(I18n.formatMessage("commands.verifiable-credential-verify.description"))
20
- .requiredOption(I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.param"), I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.description"));
21
+ .option(I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.param"), I18n.formatMessage("commands.verifiable-credential-verify.options.jwt.description"))
22
+ .option(I18n.formatMessage("commands.verifiable-credential-verify.options.json-ld.param"), I18n.formatMessage("commands.verifiable-credential-verify.options.json-ld.description"));
21
23
  CLIOptions.output(command, {
22
24
  noConsole: true,
23
25
  json: true,
@@ -38,16 +40,33 @@ export function buildCommandVerifiableCredentialVerify() {
38
40
  * Action the verifiable credential verify command.
39
41
  * @param opts The options for the command.
40
42
  * @param opts.jwt The JSON web token for the verifiable credential.
43
+ * @param opts.jsonLd The filename of a JSON-LD verifiable credential to verify.
41
44
  * @param opts.connector The connector to perform the operations with.
42
45
  * @param opts.node The node URL.
43
46
  */
44
47
  export async function actionCommandVerifiableCredentialVerify(opts) {
45
- const jwt = CLIParam.stringValue("jwt", opts.jwt);
46
48
  const nodeEndpoint = CLIParam.url("node", opts.node);
47
49
  const network = opts.connector === IdentityConnectorTypes.Iota
48
50
  ? CLIParam.stringValue("network", opts.network)
49
51
  : undefined;
50
- CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.jwt"), jwt);
52
+ let credential;
53
+ if (Is.stringValue(opts.jwt)) {
54
+ const jwt = CLIParam.stringValue("jwt", opts.jwt);
55
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.jwt"), jwt);
56
+ credential = jwt;
57
+ }
58
+ else if (Is.stringValue(opts.jsonLd)) {
59
+ const jsonLdPath = path.resolve(CLIParam.stringValue("json-ld", opts.jsonLd));
60
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-credential-verify.labels.jsonLd"), jsonLdPath);
61
+ const jsonData = await CLIUtils.readJsonFile(jsonLdPath);
62
+ if (Is.undefined(jsonData)) {
63
+ throw new GeneralError("commands", "commands.verifiable-credential-verify.jsonLdFileNotFound");
64
+ }
65
+ credential = jsonData;
66
+ }
67
+ else {
68
+ throw new GeneralError("commands", "commands.verifiable-credential-verify.noCredentialProvided");
69
+ }
51
70
  CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
52
71
  if (Is.stringValue(network)) {
53
72
  CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
@@ -60,7 +79,7 @@ export async function actionCommandVerifiableCredentialVerify(opts) {
60
79
  CLIDisplay.task(I18n.formatMessage("commands.verifiable-credential-verify.progress.verifyingCredential"));
61
80
  CLIDisplay.break();
62
81
  CLIDisplay.spinnerStart();
63
- const verification = await identityConnector.checkVerifiableCredential(jwt);
82
+ const verification = await identityConnector.checkVerifiableCredential(credential);
64
83
  const isVerified = Is.notEmpty(verification.verifiableCredential);
65
84
  const isRevoked = verification.revoked;
66
85
  CLIDisplay.spinnerStop();
@@ -1 +1 @@
1
- {"version":3,"file":"verifiableCredentialVerify.js","sourceRoot":"","sources":["../../../src/commands/verifiableCredentialVerify.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,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,sB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CLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { I18n, Is } from \"@twin.org/core\";\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 verifiable credential verify command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiableCredentialVerify(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-credential-verify\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-credential-verify.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-credential-verify.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.options.jwt.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.options.jwt.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(actionCommandVerifiableCredentialVerify);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable credential verify command.\n * @param opts The options for the command.\n * @param opts.jwt The JSON web token for the verifiable credential.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n */\nexport async function actionCommandVerifiableCredentialVerify(\n\topts: {\n\t\tjwt: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst jwt: string = CLIParam.stringValue(\"jwt\", opts.jwt);\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.verifiable-credential-verify.labels.jwt\"), jwt);\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(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.progress.verifyingCredential\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verification = await identityConnector.checkVerifiableCredential(jwt);\n\n\tconst isVerified = Is.notEmpty(verification.verifiableCredential);\n\tconst isRevoked = verification.revoked;\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.labels.isVerified\"),\n\t\t\tisVerified\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.labels.isRevoked\"),\n\t\t\tisRevoked\n\t\t);\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, { isVerified, isRevoked }, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_VERIFIABLE_CREDENTIAL_VERIFIED=\"${isVerified}\"`,\n\t\t\t\t`DID_VERIFIABLE_CREDENTIAL_REVOKED=\"${isRevoked}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
1
+ {"version":3,"file":"verifiableCredentialVerify.js","sourceRoot":"","sources":["../../../src/commands/verifiableCredentialVerify.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,gBAAgB,CAAC;AAExD,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,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,sCAAsC;IACrD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,8BAA8B,CAAC;SACpC,OAAO,CAAC,IAAI,CAAC,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C,MAAM,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACpF,CAAC;IACD,IAAI,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC/B,MAAM,QAAQ,CAAC,YAAY,CAC1B,IAAI,CAAC,GAAG,EACR;YACC,uCAAuC,UAAU,GAAG;YACpD,sCAAsC,SAAS,GAAG;SAClD,EACD,IAAI,CAAC,QAAQ,CACb,CAAC;IACH,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 { IDidVerifiableCredential } 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 verifiable credential verify command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiableCredentialVerify(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-credential-verify\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-credential-verify.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-credential-verify.description\"))\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.options.jwt.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.options.jwt.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.options.json-ld.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.options.json-ld.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(actionCommandVerifiableCredentialVerify);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable credential verify command.\n * @param opts The options for the command.\n * @param opts.jwt The JSON web token for the verifiable credential.\n * @param opts.jsonLd The filename of a JSON-LD verifiable credential to verify.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n */\nexport async function actionCommandVerifiableCredentialVerify(\n\topts: {\n\t\tjwt?: string;\n\t\tjsonLd?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\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\tlet credential: string | IDidVerifiableCredential;\n\n\tif (Is.stringValue(opts.jwt)) {\n\t\tconst jwt = CLIParam.stringValue(\"jwt\", opts.jwt);\n\t\tCLIDisplay.value(I18n.formatMessage(\"commands.verifiable-credential-verify.labels.jwt\"), jwt);\n\t\tcredential = jwt;\n\t} else if (Is.stringValue(opts.jsonLd)) {\n\t\tconst jsonLdPath = path.resolve(CLIParam.stringValue(\"json-ld\", opts.jsonLd));\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.labels.jsonLd\"),\n\t\t\tjsonLdPath\n\t\t);\n\t\tconst jsonData = await CLIUtils.readJsonFile<IDidVerifiableCredential>(jsonLdPath);\n\t\tif (Is.undefined(jsonData)) {\n\t\t\tthrow new GeneralError(\n\t\t\t\t\"commands\",\n\t\t\t\t\"commands.verifiable-credential-verify.jsonLdFileNotFound\"\n\t\t\t);\n\t\t}\n\t\tcredential = jsonData;\n\t} else {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.verifiable-credential-verify.noCredentialProvided\"\n\t\t);\n\t}\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(\n\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.progress.verifyingCredential\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verification = await identityConnector.checkVerifiableCredential(credential);\n\n\tconst isVerified = Is.notEmpty(verification.verifiableCredential);\n\tconst isRevoked = verification.revoked;\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.labels.isVerified\"),\n\t\t\tisVerified\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-credential-verify.labels.isRevoked\"),\n\t\t\tisRevoked\n\t\t);\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(opts.json, { isVerified, isRevoked }, opts.mergeJson);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[\n\t\t\t\t`DID_VERIFIABLE_CREDENTIAL_VERIFIED=\"${isVerified}\"`,\n\t\t\t\t`DID_VERIFIABLE_CREDENTIAL_REVOKED=\"${isRevoked}\"`\n\t\t\t],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,137 @@
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 { Coerce, GeneralError, I18n, Is } from "@twin.org/core";
6
+ import { DocumentHelper } from "@twin.org/identity-models";
7
+ import { VaultConnectorFactory, VaultKeyType } from "@twin.org/vault-models";
8
+ import { setupWalletConnector } from "@twin.org/wallet-cli";
9
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
10
+ import { Command, Option } from "commander";
11
+ import { setupIdentityConnector, setupVault } from "./setupCommands.js";
12
+ import { IdentityConnectorTypes } from "../models/identityConnectorTypes.js";
13
+ /**
14
+ * Build the verifiable presentation create command for the CLI.
15
+ * @returns The command.
16
+ */
17
+ export function buildCommandVerifiablePresentationCreate() {
18
+ const command = new Command();
19
+ command
20
+ .name("verifiable-presentation-create")
21
+ .summary(I18n.formatMessage("commands.verifiable-presentation-create.summary"))
22
+ .description(I18n.formatMessage("commands.verifiable-presentation-create.description"))
23
+ .requiredOption(I18n.formatMessage("commands.verifiable-presentation-create.options.verification-method-id.param"), I18n.formatMessage("commands.verifiable-presentation-create.options.verification-method-id.description"))
24
+ .requiredOption(I18n.formatMessage("commands.verifiable-presentation-create.options.private-key.param"), I18n.formatMessage("commands.verifiable-presentation-create.options.private-key.description"))
25
+ .option(I18n.formatMessage("commands.verifiable-presentation-create.options.presentation-id.param"), I18n.formatMessage("commands.verifiable-presentation-create.options.presentation-id.description"))
26
+ .option(I18n.formatMessage("commands.verifiable-presentation-create.options.jwt.param"), I18n.formatMessage("commands.verifiable-presentation-create.options.jwt.description"))
27
+ .option(I18n.formatMessage("commands.verifiable-presentation-create.options.json-ld.param"), I18n.formatMessage("commands.verifiable-presentation-create.options.json-ld.description"))
28
+ .option(I18n.formatMessage("commands.verifiable-presentation-create.options.expiration-date.param"), I18n.formatMessage("commands.verifiable-presentation-create.options.expiration-date.description"));
29
+ CLIOptions.output(command, {
30
+ noConsole: true,
31
+ json: true,
32
+ env: true,
33
+ mergeJson: true,
34
+ mergeEnv: true
35
+ });
36
+ command
37
+ .addOption(new Option(I18n.formatMessage("commands.common.options.connector.param"), I18n.formatMessage("commands.common.options.connector.description"))
38
+ .choices(Object.values(IdentityConnectorTypes))
39
+ .default(IdentityConnectorTypes.Iota))
40
+ .option(I18n.formatMessage("commands.common.options.node.param"), I18n.formatMessage("commands.common.options.node.description"), "!NODE_URL")
41
+ .option(I18n.formatMessage("commands.common.options.network.param"), I18n.formatMessage("commands.common.options.network.description"), "!NETWORK")
42
+ .action(actionCommandVerifiablePresentationCreate);
43
+ return command;
44
+ }
45
+ /**
46
+ * Action the verifiable presentation create command.
47
+ * @param opts The options for the command.
48
+ * @param opts.verificationMethodId The id of the verification method to use.
49
+ * @param opts.privateKey The private key for the verification method.
50
+ * @param opts.presentationId The optional id of the presentation.
51
+ * @param opts.jwt Comma-separated JWT credential strings to include.
52
+ * @param opts.jsonLd Comma-separated JSON-LD filenames to include.
53
+ * @param opts.expirationDate The expiration date for the presentation.
54
+ * @param opts.connector The connector to perform the operations with.
55
+ * @param opts.node The node URL.
56
+ * @param opts.network The network name.
57
+ */
58
+ export async function actionCommandVerifiablePresentationCreate(opts) {
59
+ const verificationMethodId = CLIParam.stringValue("verification-method-id", opts.verificationMethodId);
60
+ const privateKey = CLIParam.hexBase64("private-key", opts.privateKey);
61
+ const presentationId = Is.stringValue(opts.presentationId)
62
+ ? CLIParam.stringValue("presentation-id", opts.presentationId)
63
+ : undefined;
64
+ const nodeEndpoint = CLIParam.url("node", opts.node);
65
+ const network = opts.connector === IdentityConnectorTypes.Iota
66
+ ? CLIParam.stringValue("network", opts.network)
67
+ : undefined;
68
+ const jwtCredentials = (opts.jwt ?? "")
69
+ .split(",")
70
+ .map(j => j.trim())
71
+ .filter(Boolean);
72
+ const jsonLdFilenames = (opts.jsonLd ?? "")
73
+ .split(",")
74
+ .map(f => f.trim())
75
+ .filter(Boolean);
76
+ if (jwtCredentials.length === 0 && jsonLdFilenames.length === 0) {
77
+ throw new GeneralError("commands", "commands.verifiable-presentation-create.noCredentialsProvided");
78
+ }
79
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-create.labels.verificationMethodId"), verificationMethodId);
80
+ if (Is.stringValue(presentationId)) {
81
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-create.labels.presentationId"), presentationId);
82
+ }
83
+ if (jwtCredentials.length > 0) {
84
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-create.labels.jwt"), jwtCredentials.join(", "));
85
+ }
86
+ if (jsonLdFilenames.length > 0) {
87
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-create.labels.jsonLd"), jsonLdFilenames.join(", "));
88
+ }
89
+ CLIDisplay.value(I18n.formatMessage("commands.verifiable-presentation-create.labels.expirationDate"), opts.expirationDate);
90
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.node"), nodeEndpoint);
91
+ if (Is.stringValue(network)) {
92
+ CLIDisplay.value(I18n.formatMessage("commands.common.labels.network"), network);
93
+ }
94
+ CLIDisplay.break();
95
+ setupVault();
96
+ const vmParts = DocumentHelper.parseId(verificationMethodId);
97
+ const vaultConnector = VaultConnectorFactory.get("vault");
98
+ await vaultConnector.addKey(`${vmParts.id}/${vmParts.fragment}`, VaultKeyType.Ed25519, privateKey, new Uint8Array());
99
+ const walletConnector = setupWalletConnector({ nodeEndpoint, network }, opts.connector);
100
+ WalletConnectorFactory.register("wallet", () => walletConnector);
101
+ const identityConnector = setupIdentityConnector({ nodeEndpoint, network }, opts.connector);
102
+ CLIDisplay.task(I18n.formatMessage("commands.verifiable-presentation-create.progress.loadingCredentialData"));
103
+ CLIDisplay.break();
104
+ const verifiableCredentials = [...jwtCredentials];
105
+ for (const filename of jsonLdFilenames) {
106
+ const resolvedPath = path.resolve(filename);
107
+ const jsonData = await CLIUtils.readJsonFile(resolvedPath);
108
+ if (Is.undefined(jsonData)) {
109
+ throw new GeneralError("commands", "commands.verifiable-presentation-create.jsonLdFileNotFound");
110
+ }
111
+ verifiableCredentials.push(jsonData);
112
+ }
113
+ CLIDisplay.task(I18n.formatMessage("commands.verifiable-presentation-create.progress.creatingVerifiablePresentation"));
114
+ CLIDisplay.break();
115
+ CLIDisplay.spinnerStart();
116
+ const verifiablePresentation = await identityConnector.createVerifiablePresentation(vmParts.id, verificationMethodId, presentationId, undefined, undefined, verifiableCredentials, {
117
+ expirationDate: Coerce.dateTime(opts.expirationDate)
118
+ });
119
+ CLIDisplay.spinnerStop();
120
+ if (opts.console) {
121
+ CLIDisplay.section(I18n.formatMessage("commands.verifiable-presentation-create.labels.verifiablePresentation"));
122
+ CLIDisplay.write(verifiablePresentation.jwt);
123
+ CLIDisplay.break();
124
+ CLIDisplay.break();
125
+ }
126
+ if (Is.stringValue(opts?.json)) {
127
+ await CLIUtils.writeJsonFile(opts.json, {
128
+ verifiablePresentationJwt: verifiablePresentation.jwt,
129
+ verifiablePresentation: verifiablePresentation.verifiablePresentation
130
+ }, opts.mergeJson);
131
+ }
132
+ if (Is.stringValue(opts?.env)) {
133
+ await CLIUtils.writeEnvFile(opts.env, [`DID_VERIFIABLE_PRESENTATION_JWT="${verifiablePresentation.jwt}"`], opts.mergeEnv);
134
+ }
135
+ CLIDisplay.done();
136
+ }
137
+ //# sourceMappingURL=verifiablePresentationCreate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifiablePresentationCreate.js","sourceRoot":"","sources":["../../../src/commands/verifiablePresentationCreate.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,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC7E,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,sBAAsB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,qCAAqC,CAAC;AAE7E;;;GAGG;AACH,MAAM,UAAU,wCAAwC;IACvD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAC9B,OAAO;SACL,IAAI,CAAC,gCAAgC,CAAC;SACtC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC;SAC9E,WAAW,CAAC,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,CAAC;SACtF,cAAc,CACd,I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node:path\";\nimport {\n\tCLIDisplay,\n\tCLIOptions,\n\tCLIParam,\n\tCLIUtils,\n\ttype CliOutputOptions\n} from \"@twin.org/cli-core\";\nimport { Coerce, GeneralError, I18n, Is } from \"@twin.org/core\";\nimport { DocumentHelper } from \"@twin.org/identity-models\";\nimport type { IDidVerifiableCredential } 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 verifiable presentation create command for the CLI.\n * @returns The command.\n */\nexport function buildCommandVerifiablePresentationCreate(): Command {\n\tconst command = new Command();\n\tcommand\n\t\t.name(\"verifiable-presentation-create\")\n\t\t.summary(I18n.formatMessage(\"commands.verifiable-presentation-create.summary\"))\n\t\t.description(I18n.formatMessage(\"commands.verifiable-presentation-create.description\"))\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-presentation-create.options.verification-method-id.param\"\n\t\t\t),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-presentation-create.options.verification-method-id.description\"\n\t\t\t)\n\t\t)\n\t\t.requiredOption(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.options.private-key.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.options.private-key.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.options.presentation-id.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-presentation-create.options.presentation-id.description\"\n\t\t\t)\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.options.jwt.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.options.jwt.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.options.json-ld.param\"),\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.options.json-ld.description\")\n\t\t)\n\t\t.option(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.options.expiration-date.param\"),\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"commands.verifiable-presentation-create.options.expiration-date.description\"\n\t\t\t)\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(actionCommandVerifiablePresentationCreate);\n\n\treturn command;\n}\n\n/**\n * Action the verifiable presentation create command.\n * @param opts The options for the command.\n * @param opts.verificationMethodId The id of the verification method to use.\n * @param opts.privateKey The private key for the verification method.\n * @param opts.presentationId The optional id of the presentation.\n * @param opts.jwt Comma-separated JWT credential strings to include.\n * @param opts.jsonLd Comma-separated JSON-LD filenames to include.\n * @param opts.expirationDate The expiration date for the presentation.\n * @param opts.connector The connector to perform the operations with.\n * @param opts.node The node URL.\n * @param opts.network The network name.\n */\nexport async function actionCommandVerifiablePresentationCreate(\n\topts: {\n\t\tverificationMethodId: string;\n\t\tprivateKey: string;\n\t\tpresentationId?: string;\n\t\tjwt?: string;\n\t\tjsonLd?: string;\n\t\texpirationDate?: string;\n\t\tconnector?: IdentityConnectorTypes;\n\t\tnode: string;\n\t\tnetwork?: string;\n\t} & CliOutputOptions\n): Promise<void> {\n\tconst verificationMethodId: string = CLIParam.stringValue(\n\t\t\"verification-method-id\",\n\t\topts.verificationMethodId\n\t);\n\tconst privateKey: Uint8Array = CLIParam.hexBase64(\"private-key\", opts.privateKey);\n\tconst presentationId: string | undefined = Is.stringValue(opts.presentationId)\n\t\t? CLIParam.stringValue(\"presentation-id\", opts.presentationId)\n\t\t: undefined;\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\tconst jwtCredentials = (opts.jwt ?? \"\")\n\t\t.split(\",\")\n\t\t.map(j => j.trim())\n\t\t.filter(Boolean);\n\tconst jsonLdFilenames = (opts.jsonLd ?? \"\")\n\t\t.split(\",\")\n\t\t.map(f => f.trim())\n\t\t.filter(Boolean);\n\n\tif (jwtCredentials.length === 0 && jsonLdFilenames.length === 0) {\n\t\tthrow new GeneralError(\n\t\t\t\"commands\",\n\t\t\t\"commands.verifiable-presentation-create.noCredentialsProvided\"\n\t\t);\n\t}\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.labels.verificationMethodId\"),\n\t\tverificationMethodId\n\t);\n\tif (Is.stringValue(presentationId)) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.labels.presentationId\"),\n\t\t\tpresentationId\n\t\t);\n\t}\n\tif (jwtCredentials.length > 0) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.labels.jwt\"),\n\t\t\tjwtCredentials.join(\", \")\n\t\t);\n\t}\n\tif (jsonLdFilenames.length > 0) {\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.labels.jsonLd\"),\n\t\t\tjsonLdFilenames.join(\", \")\n\t\t);\n\t}\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.labels.expirationDate\"),\n\t\topts.expirationDate\n\t);\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 vmParts = DocumentHelper.parseId(verificationMethodId);\n\n\tconst vaultConnector = VaultConnectorFactory.get(\"vault\");\n\tawait vaultConnector.addKey(\n\t\t`${vmParts.id}/${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({ nodeEndpoint, network }, opts.connector);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.progress.loadingCredentialData\")\n\t);\n\tCLIDisplay.break();\n\n\tconst verifiableCredentials: (string | IDidVerifiableCredential)[] = [...jwtCredentials];\n\n\tfor (const filename of jsonLdFilenames) {\n\t\tconst resolvedPath = path.resolve(filename);\n\t\tconst jsonData = await CLIUtils.readJsonFile<IDidVerifiableCredential>(resolvedPath);\n\t\tif (Is.undefined(jsonData)) {\n\t\t\tthrow new GeneralError(\n\t\t\t\t\"commands\",\n\t\t\t\t\"commands.verifiable-presentation-create.jsonLdFileNotFound\"\n\t\t\t);\n\t\t}\n\t\tverifiableCredentials.push(jsonData);\n\t}\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\n\t\t\t\"commands.verifiable-presentation-create.progress.creatingVerifiablePresentation\"\n\t\t)\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.spinnerStart();\n\n\tconst verifiablePresentation = await identityConnector.createVerifiablePresentation(\n\t\tvmParts.id,\n\t\tverificationMethodId,\n\t\tpresentationId,\n\t\tundefined,\n\t\tundefined,\n\t\tverifiableCredentials,\n\t\t{\n\t\t\texpirationDate: Coerce.dateTime(opts.expirationDate)\n\t\t}\n\t);\n\n\tCLIDisplay.spinnerStop();\n\n\tif (opts.console) {\n\t\tCLIDisplay.section(\n\t\t\tI18n.formatMessage(\"commands.verifiable-presentation-create.labels.verifiablePresentation\")\n\t\t);\n\t\tCLIDisplay.write(verifiablePresentation.jwt);\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.break();\n\t}\n\n\tif (Is.stringValue(opts?.json)) {\n\t\tawait CLIUtils.writeJsonFile(\n\t\t\topts.json,\n\t\t\t{\n\t\t\t\tverifiablePresentationJwt: verifiablePresentation.jwt,\n\t\t\t\tverifiablePresentation: verifiablePresentation.verifiablePresentation\n\t\t\t},\n\t\t\topts.mergeJson\n\t\t);\n\t}\n\tif (Is.stringValue(opts?.env)) {\n\t\tawait CLIUtils.writeEnvFile(\n\t\t\topts.env,\n\t\t\t[`DID_VERIFIABLE_PRESENTATION_JWT=\"${verifiablePresentation.jwt}\"`],\n\t\t\topts.mergeEnv\n\t\t);\n\t}\n\n\tCLIDisplay.done();\n}\n"]}