@twin.org/node-core 0.0.3-next.2 → 0.0.3-next.21

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 (151) hide show
  1. package/dist/es/builders/engineEnvBuilder.js +168 -105
  2. package/dist/es/builders/engineEnvBuilder.js.map +1 -1
  3. package/dist/es/builders/engineServerEnvBuilder.js +49 -25
  4. package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
  5. package/dist/es/cli.js +247 -0
  6. package/dist/es/cli.js.map +1 -0
  7. package/dist/es/commands/bootstrapLegacy.js +183 -0
  8. package/dist/es/commands/bootstrapLegacy.js.map +1 -0
  9. package/dist/es/commands/help.js +85 -0
  10. package/dist/es/commands/help.js.map +1 -0
  11. package/dist/es/commands/identityCreate.js +316 -0
  12. package/dist/es/commands/identityCreate.js.map +1 -0
  13. package/dist/es/commands/identityImports.js +82 -0
  14. package/dist/es/commands/identityImports.js.map +1 -0
  15. package/dist/es/commands/identityVerifiableCredentialCreate.js +146 -0
  16. package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
  17. package/dist/es/commands/identityVerificationMethodCreate.js +214 -0
  18. package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
  19. package/dist/es/commands/identityVerificationMethodImport.js +126 -0
  20. package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
  21. package/dist/es/commands/nodeSetIdentity.js +64 -0
  22. package/dist/es/commands/nodeSetIdentity.js.map +1 -0
  23. package/dist/es/commands/nodeSetTenant.js +68 -0
  24. package/dist/es/commands/nodeSetTenant.js.map +1 -0
  25. package/dist/es/commands/tenantCreate.js +139 -0
  26. package/dist/es/commands/tenantCreate.js.map +1 -0
  27. package/dist/es/commands/tenantImport.js +97 -0
  28. package/dist/es/commands/tenantImport.js.map +1 -0
  29. package/dist/es/commands/tenantUpdate.js +94 -0
  30. package/dist/es/commands/tenantUpdate.js.map +1 -0
  31. package/dist/es/commands/userCreate.js +212 -0
  32. package/dist/es/commands/userCreate.js.map +1 -0
  33. package/dist/es/commands/userUpdate.js +132 -0
  34. package/dist/es/commands/userUpdate.js.map +1 -0
  35. package/dist/es/commands/vaultKeyCreate.js +191 -0
  36. package/dist/es/commands/vaultKeyCreate.js.map +1 -0
  37. package/dist/es/commands/vaultKeyImport.js +104 -0
  38. package/dist/es/commands/vaultKeyImport.js.map +1 -0
  39. package/dist/es/defaults.js +19 -1
  40. package/dist/es/defaults.js.map +1 -1
  41. package/dist/es/index.js +7 -3
  42. package/dist/es/index.js.map +1 -1
  43. package/dist/es/models/ICliArgs.js +4 -0
  44. package/dist/es/models/ICliArgs.js.map +1 -0
  45. package/dist/es/models/ICliCommand.js +2 -0
  46. package/dist/es/models/ICliCommand.js.map +1 -0
  47. package/dist/es/models/ICliCommandDefinition.js +2 -0
  48. package/dist/es/models/ICliCommandDefinition.js.map +1 -0
  49. package/dist/es/models/ICliCommandDefinitionParam.js +2 -0
  50. package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -0
  51. package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
  52. package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
  53. package/dist/es/models/INodeEngineState.js.map +1 -1
  54. package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
  55. package/dist/es/models/INodeOptions.js.map +1 -1
  56. package/dist/es/models/cliCommandParamType.js +4 -0
  57. package/dist/es/models/cliCommandParamType.js.map +1 -0
  58. package/dist/es/node.js +78 -41
  59. package/dist/es/node.js.map +1 -1
  60. package/dist/es/start.js +139 -0
  61. package/dist/es/start.js.map +1 -0
  62. package/dist/es/utils.js +11 -21
  63. package/dist/es/utils.js.map +1 -1
  64. package/dist/types/builders/engineEnvBuilder.d.ts +4 -1
  65. package/dist/types/builders/engineServerEnvBuilder.d.ts +5 -2
  66. package/dist/types/cli.d.ts +56 -0
  67. package/dist/types/commands/bootstrapLegacy.d.ts +66 -0
  68. package/dist/types/commands/help.d.ts +23 -0
  69. package/dist/types/commands/identityCreate.d.ts +39 -0
  70. package/dist/types/commands/identityImports.d.ts +24 -0
  71. package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
  72. package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
  73. package/dist/types/commands/identityVerificationMethodImport.d.ts +31 -0
  74. package/dist/types/commands/nodeSetIdentity.d.ts +22 -0
  75. package/dist/types/commands/nodeSetTenant.d.ts +22 -0
  76. package/dist/types/commands/tenantCreate.d.ts +38 -0
  77. package/dist/types/commands/tenantImport.d.ts +26 -0
  78. package/dist/types/commands/tenantUpdate.d.ts +26 -0
  79. package/dist/types/commands/userCreate.d.ts +49 -0
  80. package/dist/types/commands/userUpdate.d.ts +38 -0
  81. package/dist/types/commands/vaultKeyCreate.d.ts +43 -0
  82. package/dist/types/commands/vaultKeyImport.d.ts +28 -0
  83. package/dist/types/defaults.d.ts +11 -1
  84. package/dist/types/index.d.ts +7 -3
  85. package/dist/types/models/ICliArgs.d.ts +20 -0
  86. package/dist/types/models/ICliCommand.d.ts +17 -0
  87. package/dist/types/models/ICliCommandDefinition.d.ts +46 -0
  88. package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
  89. package/dist/types/models/IEngineEnvironmentVariables.d.ts +62 -53
  90. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
  91. package/dist/types/models/INodeEngineState.d.ts +0 -8
  92. package/dist/types/models/INodeEnvironmentVariables.d.ts +0 -38
  93. package/dist/types/models/INodeOptions.d.ts +6 -2
  94. package/dist/types/models/cliCommandParamType.d.ts +4 -0
  95. package/dist/types/node.d.ts +8 -4
  96. package/dist/types/{server.d.ts → start.d.ts} +7 -2
  97. package/dist/types/utils.d.ts +6 -8
  98. package/docs/changelog.md +136 -0
  99. package/docs/reference/functions/buildConfiguration.md +3 -3
  100. package/docs/reference/functions/buildEngineConfiguration.md +1 -1
  101. package/docs/reference/functions/buildEngineServerConfiguration.md +3 -3
  102. package/docs/reference/functions/constructCliCommand.md +27 -0
  103. package/docs/reference/functions/executeCommand.md +29 -0
  104. package/docs/reference/functions/getEnvDefaults.md +19 -0
  105. package/docs/reference/functions/getScriptDirectory.md +19 -0
  106. package/docs/reference/functions/parseCommandLineArgs.md +19 -0
  107. package/docs/reference/functions/processEnvOptions.md +27 -0
  108. package/docs/reference/functions/registerCommands.md +9 -0
  109. package/docs/reference/functions/run.md +8 -2
  110. package/docs/reference/functions/start.md +10 -4
  111. package/docs/reference/functions/substituteEnvOptions.md +25 -0
  112. package/docs/reference/index.md +16 -13
  113. package/docs/reference/interfaces/ICliArgs.md +35 -0
  114. package/docs/reference/interfaces/ICliCommand.md +23 -0
  115. package/docs/reference/interfaces/ICliCommandDefinition.md +101 -0
  116. package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
  117. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +110 -85
  118. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +166 -117
  119. package/docs/reference/interfaces/INodeEngineState.md +0 -16
  120. package/docs/reference/interfaces/INodeEnvironmentVariables.md +170 -201
  121. package/docs/reference/interfaces/INodeOptions.md +10 -2
  122. package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
  123. package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_DID.md +3 -0
  124. package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_TENANT.md +3 -0
  125. package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +3 -0
  126. package/locales/en.json +589 -30
  127. package/package.json +3 -1
  128. package/dist/es/bootstrap.js +0 -374
  129. package/dist/es/bootstrap.js.map +0 -1
  130. package/dist/es/identity.js +0 -169
  131. package/dist/es/identity.js.map +0 -1
  132. package/dist/es/models/nodeFeatures.js +0 -21
  133. package/dist/es/models/nodeFeatures.js.map +0 -1
  134. package/dist/es/server.js +0 -78
  135. package/dist/es/server.js.map +0 -1
  136. package/dist/types/bootstrap.d.ts +0 -76
  137. package/dist/types/identity.d.ts +0 -14
  138. package/dist/types/models/nodeFeatures.d.ts +0 -21
  139. package/docs/reference/functions/bootstrap.md +0 -29
  140. package/docs/reference/functions/bootstrapAuth.md +0 -35
  141. package/docs/reference/functions/bootstrapBlobEncryption.md +0 -35
  142. package/docs/reference/functions/bootstrapContextIdHandlers.md +0 -35
  143. package/docs/reference/functions/bootstrapImmutableProofMethod.md +0 -35
  144. package/docs/reference/functions/bootstrapNodeAdminUser.md +0 -35
  145. package/docs/reference/functions/bootstrapNodeId.md +0 -35
  146. package/docs/reference/functions/bootstrapSynchronisedStorage.md +0 -35
  147. package/docs/reference/functions/bootstrapTenantId.md +0 -35
  148. package/docs/reference/functions/getFeatures.md +0 -19
  149. package/docs/reference/type-aliases/NodeFeatures.md +0 -5
  150. package/docs/reference/variables/NodeFeatures.md +0 -25
  151. package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityVerifiableCredentialCreate.js","sourceRoot":"","sources":["../../../src/commands/identityVerifiableCredentialCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAGxE,OAAO,EAAE,GAAG,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAO1E,MAAM,YAAY,GAAG,uCAAuC,CAAC;AAE7D;;;GAGG;AACH,MAAM,UAAU,sDAAsD,CAAC,kBAEtE;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,qEAAqE,CACrE;QACD,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,iEAAiE,CAAC;QAC9F,oBAAoB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AAC,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;QACtC,MAAM,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,eAAe,aAAa,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC;QACzE,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9D,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport path from \"node:path\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { Coerce, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did, IdentityConnectorFactory } from \"@twin.org/identity-models\";\nimport type { IDidVerifiableCredential } from \"@twin.org/standards-w3c-did\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"identity-verifiable-credential-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\n\t\t\t\"node.cli.commands.identity-verifiable-credential-create.description\"\n\t\t),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-verifiable-credential-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"controller\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.controller.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.verification-method-id.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did with fragment\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"subject-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.subject-json.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"file\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"credential-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.credential-id.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"url\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"expiration-date\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.expiration-date.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"ISO date-time\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.output-json.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.output-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verifiable-credential-create.params.output-env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) =>\n\t\t\tidentityVerifiableCredentialCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating an identity verifiable credential.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.verificationMethodId The ID of the verification method to create the credential with.\n * @param params.identity The DID of the identity to create the credential for.\n * @param params.controller The controller DID for the identity.\n * @param params.subjectJson The subject JSON file for the verifiable credential.\n * @param params.credentialId The ID of the verifiable credential.\n * @param params.expirationDate The expiration date of the verifiable credential.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created verifiable credential and JWT.\n */\nexport async function identityVerifiableCredentialCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tverificationMethodId?: string;\n\t\tidentity?: string;\n\t\tcontroller?: string;\n\t\tsubjectJson?: string;\n\t\tcredentialId?: string;\n\t\texpirationDate?: string;\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<{\n\tverifiableCredential: IDidVerifiableCredential;\n\tjwt: string;\n}> {\n\tDid.guard(\"identityVerifiableCredentialCreate\", \"identity\", params.identity);\n\tGuards.stringValue(\n\t\t\"identityVerifiableCredentialCreate\",\n\t\t\"verification-method-id\",\n\t\tparams.verificationMethodId\n\t);\n\tGuards.stringValue(\"identityVerifiableCredentialCreate\", \"subject-json\", params.subjectJson);\n\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tconst subjectFilename = path.resolve(params.subjectJson);\n\tconst subject = await CLIUtils.readJsonFile<IJsonLdNodeObject>(subjectFilename);\n\tif (Is.empty(subject)) {\n\t\tthrow new GeneralError(\"identityVerifiableCredentialCreate\", \"subjectJsonLoadFailed\", {\n\t\t\tsubjectFilename\n\t\t});\n\t}\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-verifiable-credential-create.labels.creating\")\n\t);\n\n\tCLIDisplay.spinnerStart();\n\n\tif (!params.verificationMethodId.includes(\"#\")) {\n\t\tparams.verificationMethodId = `${params.identity}#${params.verificationMethodId}`;\n\t}\n\n\tconst credential = await identityConnector.createVerifiableCredential(\n\t\tparams.controller ?? params.identity,\n\t\tparams.verificationMethodId,\n\t\tparams.credentialId,\n\t\tsubject,\n\t\t{\n\t\t\texpirationDate: Coerce.dateTime(params.expirationDate)\n\t\t}\n\t);\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-verifiable-credential-create.labels.created\")\n\t);\n\n\tCLIDisplay.break();\n\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-verifiable-credential-create.labels.jwtToken\"),\n\t\tcredential.jwt\n\t);\n\tCLIDisplay.break();\n\n\tif (Is.stringValue(params.outputJson)) {\n\t\tawait CLIUtils.writeJsonFile(params.outputJson, credential, false);\n\t}\n\n\tif (Is.stringValue(params.outputEnv)) {\n\t\tconst output = [`${params.outputEnvPrefix}VC_TOKEN=\"${credential.jwt}\"`];\n\t\tawait CLIUtils.writeEnvFile(params.outputEnv, output, false);\n\t}\n\n\tCLIDisplay.done();\n\n\treturn credential;\n}\n"]}
@@ -0,0 +1,214 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
4
+ import { ComponentFactory, Converter, GeneralError, Guards, I18n, Is } from "@twin.org/core";
5
+ import { Did, DocumentHelper, IdentityConnectorFactory } from "@twin.org/identity-models";
6
+ import { DidVerificationMethodType } from "@twin.org/standards-w3c-did";
7
+ import { VaultConnectorFactory } from "@twin.org/vault-models";
8
+ import { Jwk } from "@twin.org/web";
9
+ const COMMAND_NAME = "identity-verification-method-create";
10
+ /**
11
+ * Get the command definition parameters.
12
+ * @param commandDefinitions The registered command definitions.
13
+ */
14
+ export function getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions) {
15
+ commandDefinitions[COMMAND_NAME] = {
16
+ command: COMMAND_NAME,
17
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.description"),
18
+ example: I18n.formatMessage("node.cli.commands.identity-verification-method-create.example"),
19
+ requiresNodeIdentity: false,
20
+ requiresTenantId: false,
21
+ params: [
22
+ {
23
+ key: "env-prefix",
24
+ type: "string",
25
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.env-prefix.description"),
26
+ required: false
27
+ },
28
+ {
29
+ key: "identity",
30
+ type: "string",
31
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.identity.description"),
32
+ extendedType: "did"
33
+ },
34
+ {
35
+ key: "controller",
36
+ type: "string",
37
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.controller.description"),
38
+ extendedType: "did",
39
+ required: false
40
+ },
41
+ {
42
+ key: "verification-method-type",
43
+ type: "string",
44
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.verification-method-type.description"),
45
+ options: Object.values(DidVerificationMethodType),
46
+ required: false,
47
+ defaultValue: "assertionMethod"
48
+ },
49
+ {
50
+ key: "verification-method-id",
51
+ type: "string",
52
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.verification-method-id.description"),
53
+ required: false
54
+ },
55
+ {
56
+ key: "overwrite-mode",
57
+ type: "string",
58
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.overwrite-mode.description"),
59
+ options: ["skip", "overwrite", "error"],
60
+ defaultValue: "skip",
61
+ required: false
62
+ },
63
+ {
64
+ key: "load-env",
65
+ type: "string",
66
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.load-env.description"),
67
+ required: false
68
+ },
69
+ {
70
+ key: "output-json",
71
+ type: "string",
72
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.output-json.description"),
73
+ required: false
74
+ },
75
+ {
76
+ key: "output-env",
77
+ type: "string",
78
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.output-env.description"),
79
+ required: false
80
+ },
81
+ {
82
+ key: "output-env-prefix",
83
+ type: "string",
84
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-create.params.output-env-prefix.description"),
85
+ required: false
86
+ }
87
+ ],
88
+ action: async (engineCore, envVars, params) => identityVerificationMethodCreate(engineCore, envVars, params)
89
+ };
90
+ }
91
+ /**
92
+ * Command for creating an identity verification method.
93
+ * @param engineCore The engine core.
94
+ * @param envVars The environment variables for the node.
95
+ * @param params The parameters for the command.
96
+ * @param params.identity The DID of the identity to create.
97
+ * @param params.verificationMethodType The type of verification method to create.
98
+ * @param params.verificationMethodId The ID of the verification method to create.
99
+ * @param params.controller The controller DID for the identity.
100
+ * @param params.overwriteMode The mode to use when a verification method with the same ID already exists.
101
+ * @param params.outputJson The output .json file to store the command output.
102
+ * @param params.outputEnv The output .env file to store the command output.
103
+ * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
104
+ * @returns The created verification method details or undefined if skipped.
105
+ */
106
+ export async function identityVerificationMethodCreate(engineCore, envVars, params) {
107
+ Did.guard("identityVerificationMethodCreate", "identity", params.identity);
108
+ Guards.arrayOneOf("identityVerificationMethodCreate", "verificationMethodType", params.verificationMethodType, Object.values(DidVerificationMethodType));
109
+ Guards.arrayOneOf("identityVerificationMethodCreate", "overwrite-mode", params.overwriteMode, [
110
+ "skip",
111
+ "overwrite",
112
+ "error"
113
+ ]);
114
+ const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
115
+ const identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);
116
+ const defaultIdentityResolverComponentType = engineCore.getRegisteredInstanceType("identityResolverComponent");
117
+ const identityResolverComponent = ComponentFactory.get(defaultIdentityResolverComponentType);
118
+ const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
119
+ const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
120
+ let createMethod = true;
121
+ let verificationMethod;
122
+ // We only need to perform the overwrite check if a verification method ID was provided
123
+ // otherwise a new ID will be generated
124
+ if (Is.stringValue(params.verificationMethodId)) {
125
+ if (params.overwriteMode === "skip" || params.overwriteMode === "error") {
126
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.resolvingIdentity"));
127
+ const identityDoc = await identityResolverComponent.identityResolve(params.identity);
128
+ try {
129
+ verificationMethod = DocumentHelper.getVerificationMethod(identityDoc, DocumentHelper.joinId(params.identity, params.verificationMethodId));
130
+ }
131
+ catch { }
132
+ if (!Is.empty(verificationMethod)) {
133
+ if (params.overwriteMode === "error") {
134
+ throw new GeneralError("identityVerificationMethodCreate", "verificationMethodAlreadyExists");
135
+ }
136
+ createMethod = false;
137
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.skipping"));
138
+ }
139
+ }
140
+ }
141
+ if (createMethod) {
142
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.creatingVerificationMethod"));
143
+ CLIDisplay.spinnerStart();
144
+ verificationMethod = await identityConnector.addVerificationMethod(params.controller ?? params.identity, params.identity, params.verificationMethodType, params.verificationMethodId);
145
+ CLIDisplay.spinnerStop();
146
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.createdVerificationMethod"));
147
+ }
148
+ let json;
149
+ if (!Is.empty(verificationMethod)) {
150
+ const keyParts = DocumentHelper.parseId(verificationMethod.id);
151
+ const keyPair = await vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);
152
+ const privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);
153
+ const publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)
154
+ ? Converter.bytesToBase64Url(keyPair.publicKey)
155
+ : "";
156
+ const privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);
157
+ const publicKeyBase64 = Is.uint8Array(keyPair.publicKey)
158
+ ? Converter.bytesToBase64(keyPair.publicKey)
159
+ : "";
160
+ const privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);
161
+ const publicKeyHex = Is.uint8Array(keyPair.publicKey)
162
+ ? Converter.bytesToHex(keyPair.publicKey, true)
163
+ : "";
164
+ const jwk = await Jwk.fromEd25519Private(keyPair.privateKey);
165
+ const kid = await Jwk.generateKid(jwk);
166
+ CLIDisplay.break();
167
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.verificationMethodId"), verificationMethod.id);
168
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.verificationMethodType"), verificationMethod.type);
169
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.kid"), kid);
170
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.privateKeyBase64Url"), privateKeyBase64Url);
171
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.publicKeyBase64Url"), publicKeyBase64Url);
172
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.privateKeyBase64"), privateKeyBase64);
173
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.publicKeyBase64"), publicKeyBase64);
174
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.privateKeyHex"), privateKeyHex);
175
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.publicKeyHex"), publicKeyHex);
176
+ CLIDisplay.break();
177
+ json = {
178
+ verificationMethodId: verificationMethod.id,
179
+ verificationMethodType: verificationMethod.type,
180
+ privateKeyJwk: {
181
+ kid,
182
+ ...jwk
183
+ },
184
+ privateKeyHex,
185
+ publicKeyHex,
186
+ privateKeyBase64,
187
+ publicKeyBase64
188
+ };
189
+ if (Is.stringValue(params.outputJson)) {
190
+ await CLIUtils.writeJsonFile(params.outputJson, json, false);
191
+ }
192
+ if (Is.stringValue(params.outputEnv)) {
193
+ const output = [
194
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_ID="${verificationMethod.id}"`,
195
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_TYPE="${verificationMethod.type}"`,
196
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KID="${kid}"`,
197
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KTY="${jwk.kty}"`,
198
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_USE="${jwk.use}"`,
199
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_ALG="${jwk.alg}"`,
200
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_CRV="${jwk.crv}"`,
201
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_X="${jwk.x}"`,
202
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_D="${jwk.d}"`,
203
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX="${privateKeyHex}"`,
204
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX="${publicKeyHex}"`,
205
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64="${privateKeyBase64}"`,
206
+ `${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64="${publicKeyBase64}"`
207
+ ];
208
+ await CLIUtils.writeEnvFile(params.outputEnv, output, false);
209
+ }
210
+ }
211
+ CLIDisplay.done();
212
+ return json;
213
+ }
214
+ //# sourceMappingURL=identityVerificationMethodCreate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityVerificationMethodCreate.js","sourceRoot":"","sources":["../../../src/commands/identityVerificationMethodCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EACN,GAAG,EACH,cAAc,EACd,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CAAC,eAAe,iCAAiC,kBAAkB,CAAC,IAAI,GAAG;gBACpF,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,GAAG;gBACnE,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,kCAAkC,GAAG,CAAC,CAAC,GAAG;gBACnE,GAAG,MAAM,CAAC,eAAe,kCAAkC,GAAG,CAAC,CAAC,GAAG;gBACnE,GAAG,MAAM,CAAC,eAAe,4CAA4C,aAAa,GAAG;gBACrF,GAAG,MAAM,CAAC,eAAe,2CAA2C,YAAY,GAAG;gBACnF,GAAG,MAAM,CAAC,eAAe,+CAA+C,gBAAgB,GAAG;gBAC3F,GAAG,MAAM,CAAC,eAAe,8CAA8C,eAAe,GAAG;aACzF,CAAC;YACF,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport {\n\tDid,\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\ttype IIdentityResolverComponent\n} from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { type IJwk, Jwk } from \"@twin.org/web\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"identity-verification-method-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\n\t\t\t\"node.cli.commands.identity-verification-method-create.description\"\n\t\t),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-verification-method-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"controller\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.controller.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: Object.values(DidVerificationMethodType),\n\t\t\t\trequired: false,\n\t\t\t\tdefaultValue: \"assertionMethod\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-json.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) =>\n\t\t\tidentityVerificationMethodCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating an identity verification method.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID of the identity to create.\n * @param params.verificationMethodType The type of verification method to create.\n * @param params.verificationMethodId The ID of the verification method to create.\n * @param params.controller The controller DID for the identity.\n * @param params.overwriteMode The mode to use when a verification method with the same ID already exists.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created verification method details or undefined if skipped.\n */\nexport async function identityVerificationMethodCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tverificationMethodType?: DidVerificationMethodType;\n\t\tverificationMethodId?: string;\n\t\tcontroller?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tverificationMethodId: string;\n\t\t\tverificationMethodType: string;\n\t\t\tprivateKeyJwk: IJwk;\n\t\t\tprivateKeyHex: string;\n\t\t\tpublicKeyHex: string;\n\t\t\tprivateKeyBase64: string;\n\t\t\tpublicKeyBase64: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"identityVerificationMethodCreate\", \"identity\", params.identity);\n\tGuards.arrayOneOf(\n\t\t\"identityVerificationMethodCreate\",\n\t\t\"verificationMethodType\",\n\t\tparams.verificationMethodType,\n\t\tObject.values(DidVerificationMethodType)\n\t);\n\tGuards.arrayOneOf(\"identityVerificationMethodCreate\", \"overwrite-mode\", params.overwriteMode, [\n\t\t\"skip\",\n\t\t\"overwrite\",\n\t\t\"error\"\n\t]);\n\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tconst defaultIdentityResolverComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverComponent\"\n\t);\n\tconst identityResolverComponent = ComponentFactory.get<IIdentityResolverComponent>(\n\t\tdefaultIdentityResolverComponentType\n\t);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createMethod = true;\n\tlet verificationMethod;\n\n\t// We only need to perform the overwrite check if a verification method ID was provided\n\t// otherwise a new ID will be generated\n\tif (Is.stringValue(params.verificationMethodId)) {\n\t\tif (params.overwriteMode === \"skip\" || params.overwriteMode === \"error\") {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.resolvingIdentity\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst identityDoc = await identityResolverComponent.identityResolve(params.identity);\n\t\t\ttry {\n\t\t\t\tverificationMethod = DocumentHelper.getVerificationMethod(\n\t\t\t\t\tidentityDoc,\n\t\t\t\t\tDocumentHelper.joinId(params.identity, params.verificationMethodId)\n\t\t\t\t);\n\t\t\t} catch {}\n\n\t\t\tif (!Is.empty(verificationMethod)) {\n\t\t\t\tif (params.overwriteMode === \"error\") {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\t\"identityVerificationMethodCreate\",\n\t\t\t\t\t\t\"verificationMethodAlreadyExists\"\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcreateMethod = false;\n\t\t\t\tCLIDisplay.task(\n\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.skipping\"\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (createMethod) {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.creatingVerificationMethod\"\n\t\t\t)\n\t\t);\n\t\tCLIDisplay.spinnerStart();\n\n\t\tverificationMethod = await identityConnector.addVerificationMethod(\n\t\t\tparams.controller ?? params.identity,\n\t\t\tparams.identity,\n\t\t\tparams.verificationMethodType as DidVerificationMethodType,\n\t\t\tparams.verificationMethodId\n\t\t);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.createdVerificationMethod\"\n\t\t\t)\n\t\t);\n\t}\n\n\tlet json;\n\n\tif (!Is.empty(verificationMethod)) {\n\t\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\t\tconst keyPair = await vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);\n\t\tconst privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);\n\t\tconst publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t\t: \"\";\n\t\tconst privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);\n\t\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64(keyPair.publicKey)\n\t\t\t: \"\";\n\n\t\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\t\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t\t: \"\";\n\n\t\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\t\tconst kid = await Jwk.generateKid(jwk);\n\n\t\tCLIDisplay.break();\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodId\"\n\t\t\t),\n\t\t\tverificationMethod.id\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodType\"\n\t\t\t),\n\t\t\tverificationMethod.type\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-verification-method-create.labels.kid\"),\n\t\t\tkid\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64Url\"\n\t\t\t),\n\t\t\tprivateKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64Url\"\n\t\t\t),\n\t\t\tpublicKeyBase64Url\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64\"\n\t\t\t),\n\t\t\tprivateKeyBase64\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64\"\n\t\t\t),\n\t\t\tpublicKeyBase64\n\t\t);\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyHex\"\n\t\t\t),\n\t\t\tprivateKeyHex\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyHex\"\n\t\t\t),\n\t\t\tpublicKeyHex\n\t\t);\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tverificationMethodId: verificationMethod.id,\n\t\t\tverificationMethodType: verificationMethod.type,\n\t\t\tprivateKeyJwk: {\n\t\t\t\tkid,\n\t\t\t\t...jwk\n\t\t\t},\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64\n\t\t};\n\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst output = [\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_TYPE=\"${verificationMethod.type}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KID=\"${kid}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KTY=\"${jwk.kty}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_USE=\"${jwk.use}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_ALG=\"${jwk.alg}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_CRV=\"${jwk.crv}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_X=\"${jwk.x}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_D=\"${jwk.d}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX=\"${privateKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX=\"${publicKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`\n\t\t\t];\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, output, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
@@ -0,0 +1,126 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay } from "@twin.org/cli-core";
4
+ import { Converter, GeneralError, Guards, HexHelper, I18n, Is } from "@twin.org/core";
5
+ import { Ed25519 } from "@twin.org/crypto";
6
+ import { Did, DocumentHelper, IdentityConnectorFactory, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
7
+ import { DidVerificationMethodType } from "@twin.org/standards-w3c-did";
8
+ import { VaultConnectorFactory, VaultKeyType } from "@twin.org/vault-models";
9
+ const COMMAND_NAME = "identity-verification-method-import";
10
+ /**
11
+ * Get the command definition parameters.
12
+ * @param commandDefinitions The registered command definitions.
13
+ */
14
+ export function getCommandDefinitionIdentityVerificationMethodImport(commandDefinitions) {
15
+ commandDefinitions[COMMAND_NAME] = {
16
+ command: COMMAND_NAME,
17
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-import.description"),
18
+ example: I18n.formatMessage("node.cli.commands.identity-verification-method-import.example"),
19
+ requiresNodeIdentity: false,
20
+ requiresTenantId: false,
21
+ params: [
22
+ {
23
+ key: "env-prefix",
24
+ type: "string",
25
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-import.params.env-prefix.description"),
26
+ required: false
27
+ },
28
+ {
29
+ key: "identity",
30
+ type: "string",
31
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-import.params.identity.description"),
32
+ extendedType: "did"
33
+ },
34
+ {
35
+ key: "controller",
36
+ type: "string",
37
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-import.params.controller.description"),
38
+ extendedType: "did",
39
+ required: false
40
+ },
41
+ {
42
+ key: "verification-method-type",
43
+ type: "string",
44
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-import.params.verification-method-type.description"),
45
+ options: Object.values(DidVerificationMethodType),
46
+ required: true,
47
+ defaultValue: "assertionMethod"
48
+ },
49
+ {
50
+ key: "verification-method-id",
51
+ type: "string",
52
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-import.params.verification-method-id.description"),
53
+ required: true
54
+ },
55
+ {
56
+ key: "private-key-hex",
57
+ type: "string",
58
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-import.params.private-key-hex.description"),
59
+ required: true
60
+ },
61
+ {
62
+ key: "load-env",
63
+ type: "string",
64
+ description: I18n.formatMessage("node.cli.commands.identity-verification-method-import.params.load-env.description"),
65
+ required: false
66
+ }
67
+ ],
68
+ action: async (engineCore, envVars, params) => identityVerificationMethodImport(engineCore, envVars, params)
69
+ };
70
+ }
71
+ /**
72
+ * Command for creating an identity verification method.
73
+ * @param engineCore The engine core.
74
+ * @param envVars The environment variables for the node.
75
+ * @param params The parameters for the command.
76
+ * @param params.identity The DID of the identity to create.
77
+ * @param params.verificationMethodType The type of verification method to create.
78
+ * @param params.verificationMethodId The ID of the verification method to create.
79
+ * @param params.controller The controller DID for the identity.
80
+ * @param params.privateKeyHex The private key in hex format.
81
+ */
82
+ export async function identityVerificationMethodImport(engineCore, envVars, params) {
83
+ Did.guard("identityVerificationMethodImport", "identity", params.identity);
84
+ Guards.arrayOneOf("identityVerificationMethodImport", "verification-method-type", params.verificationMethodType, Object.values(DidVerificationMethodType));
85
+ Guards.stringValue("identityVerificationMethodImport", "verification-method-id", params.verificationMethodId);
86
+ Guards.stringHex("identityVerificationMethodImport", "private-key-hex", params.privateKeyHex, true);
87
+ const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
88
+ const identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);
89
+ const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
90
+ const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
91
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-import.labels.resolvingIdentity"));
92
+ const identityDocument = await identityResolverConnector.resolveDocument(params.identity);
93
+ if (Is.empty(identityDocument)) {
94
+ throw new GeneralError("identityImport", "identityNotFound", {
95
+ identity: params.identity
96
+ });
97
+ }
98
+ const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
99
+ const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
100
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-import.labels.importing"));
101
+ CLIDisplay.spinnerStart();
102
+ let verificationMethodId = params.verificationMethodId;
103
+ if (verificationMethodId.includes("#")) {
104
+ const parts = DocumentHelper.parseId(verificationMethodId);
105
+ if (Is.stringValue(parts.fragment)) {
106
+ verificationMethodId = parts.fragment;
107
+ }
108
+ }
109
+ let vaultKey;
110
+ const vaultKeyId = `${params.identity}/${verificationMethodId}`;
111
+ try {
112
+ vaultKey = await vaultConnector.getKey(vaultKeyId);
113
+ }
114
+ catch { }
115
+ if (Is.empty(vaultKey)) {
116
+ const privateKeyBytes = Converter.hexToBytes(HexHelper.stripPrefix(params.privateKeyHex));
117
+ const publicKeyBytes = Ed25519.publicKeyFromPrivateKey(privateKeyBytes);
118
+ vaultKey = await vaultConnector.addKey(vaultKeyId, VaultKeyType.Ed25519, privateKeyBytes, publicKeyBytes);
119
+ }
120
+ await identityConnector.addVerificationMethod(params.controller ?? params.identity, params.identity, params.verificationMethodType, verificationMethodId);
121
+ CLIDisplay.spinnerStop();
122
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-import.labels.imported"));
123
+ CLIDisplay.break();
124
+ CLIDisplay.done();
125
+ }
126
+ //# sourceMappingURL=identityVerificationMethodImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityVerificationMethodImport.js","sourceRoot":"","sources":["../../../src/commands/identityVerificationMethodImport.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,u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CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YACpC,oBAAoB,GAAG,KAAK,CAAC,QAAQ,CAAC;QACvC,CAAC;IACF,CAAC;IAED,IAAI,QAAQ,CAAC;IACb,MAAM,UAAU,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,oBAAoB,EAAE,CAAC;IAEhE,IAAI,CAAC;QACJ,QAAQ,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxB,MAAM,eAAe,GAAG,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;QAC1F,MAAM,cAAc,GAAG,OAAO,CAAC,uBAAuB,CAAC,eAAe,CAAC,CAAC;QACxE,QAAQ,GAAG,MAAM,cAAc,CAAC,MAAM,CACrC,UAAU,EACV,YAAY,CAAC,OAAO,EACpB,eAAe,EACf,cAAc,CACd,CAAC;IACH,CAAC;IAED,MAAM,iBAAiB,CAAC,qBAAqB,CAC5C,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,QAAQ,EACpC,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,sBAAmD,EAC1D,oBAAoB,CACpB,CAAC;IAEF,UAAU,CAAC,WAAW,EAAE,CAAC;IACzB,UAAU,CAAC,IAAI,CACd,IAAI,CAAC,aAAa,CAAC,uEAAuE,CAAC,CAC3F,CAAC;IACF,UAAU,CAAC,KAAK,EAAE,CAAC;IAEnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { Converter, GeneralError, Guards, HexHelper, I18n, Is } from \"@twin.org/core\";\nimport { Ed25519 } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport {\n\tDid,\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\tIdentityResolverConnectorFactory\n} from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"identity-verification-method-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityVerificationMethodImport(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\n\t\t\t\"node.cli.commands.identity-verification-method-import.description\"\n\t\t),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-verification-method-import.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-import.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-import.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"controller\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-import.params.controller.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-import.params.verification-method-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: Object.values(DidVerificationMethodType),\n\t\t\t\trequired: true,\n\t\t\t\tdefaultValue: \"assertionMethod\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-import.params.verification-method-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"private-key-hex\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-import.params.private-key-hex.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-import.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) =>\n\t\t\tidentityVerificationMethodImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating an identity verification method.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID of the identity to create.\n * @param params.verificationMethodType The type of verification method to create.\n * @param params.verificationMethodId The ID of the verification method to create.\n * @param params.controller The controller DID for the identity.\n * @param params.privateKeyHex The private key in hex format.\n */\nexport async function identityVerificationMethodImport(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tverificationMethodType?: DidVerificationMethodType;\n\t\tverificationMethodId?: string;\n\t\tcontroller?: string;\n\t\tprivateKeyHex?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"identityVerificationMethodImport\", \"identity\", params.identity);\n\tGuards.arrayOneOf(\n\t\t\"identityVerificationMethodImport\",\n\t\t\"verification-method-type\",\n\t\tparams.verificationMethodType,\n\t\tObject.values(DidVerificationMethodType)\n\t);\n\tGuards.stringValue(\n\t\t\"identityVerificationMethodImport\",\n\t\t\"verification-method-id\",\n\t\tparams.verificationMethodId\n\t);\n\tGuards.stringHex(\n\t\t\"identityVerificationMethodImport\",\n\t\t\"private-key-hex\",\n\t\tparams.privateKeyHex,\n\t\ttrue\n\t);\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tconst defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverConnector\"\n\t);\n\n\tconst identityResolverConnector = IdentityResolverConnectorFactory.get(\n\t\tdefaultIdentityResolverConnectorType\n\t);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\n\t\t\t\"node.cli.commands.identity-verification-method-import.labels.resolvingIdentity\"\n\t\t)\n\t);\n\tconst identityDocument = await identityResolverConnector.resolveDocument(params.identity);\n\n\tif (Is.empty(identityDocument)) {\n\t\tthrow new GeneralError(\"identityImport\", \"identityNotFound\", {\n\t\t\tidentity: params.identity\n\t\t});\n\t}\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-verification-method-import.labels.importing\")\n\t);\n\tCLIDisplay.spinnerStart();\n\n\tlet verificationMethodId = params.verificationMethodId;\n\tif (verificationMethodId.includes(\"#\")) {\n\t\tconst parts = DocumentHelper.parseId(verificationMethodId);\n\t\tif (Is.stringValue(parts.fragment)) {\n\t\t\tverificationMethodId = parts.fragment;\n\t\t}\n\t}\n\n\tlet vaultKey;\n\tconst vaultKeyId = `${params.identity}/${verificationMethodId}`;\n\n\ttry {\n\t\tvaultKey = await vaultConnector.getKey(vaultKeyId);\n\t} catch {}\n\n\tif (Is.empty(vaultKey)) {\n\t\tconst privateKeyBytes = Converter.hexToBytes(HexHelper.stripPrefix(params.privateKeyHex));\n\t\tconst publicKeyBytes = Ed25519.publicKeyFromPrivateKey(privateKeyBytes);\n\t\tvaultKey = await vaultConnector.addKey(\n\t\t\tvaultKeyId,\n\t\t\tVaultKeyType.Ed25519,\n\t\t\tprivateKeyBytes,\n\t\t\tpublicKeyBytes\n\t\t);\n\t}\n\n\tawait identityConnector.addVerificationMethod(\n\t\tparams.controller ?? params.identity,\n\t\tparams.identity,\n\t\tparams.verificationMethodType as DidVerificationMethodType,\n\t\tverificationMethodId\n\t);\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-verification-method-import.labels.imported\")\n\t);\n\tCLIDisplay.break();\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,64 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay } from "@twin.org/cli-core";
4
+ import { I18n, Is, NotFoundError } from "@twin.org/core";
5
+ import { Did, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
6
+ const COMMAND_NAME = "node-set-identity";
7
+ /**
8
+ * Get the command definition parameters.
9
+ * @param commandDefinitions The registered command definitions.
10
+ */
11
+ export function getCommandDefinitionNodeSetIdentity(commandDefinitions) {
12
+ commandDefinitions[COMMAND_NAME] = {
13
+ command: COMMAND_NAME,
14
+ description: I18n.formatMessage("node.cli.commands.node-set-identity.description"),
15
+ example: I18n.formatMessage("node.cli.commands.node-set-identity.example"),
16
+ requiresNodeIdentity: false,
17
+ requiresTenantId: false,
18
+ params: [
19
+ {
20
+ key: "env-prefix",
21
+ type: "string",
22
+ description: I18n.formatMessage("node.cli.commands.node-set-identity.params.env-prefix.description"),
23
+ required: false
24
+ },
25
+ {
26
+ key: "identity",
27
+ type: "string",
28
+ description: I18n.formatMessage("node.cli.commands.node-set-identity.params.identity.description"),
29
+ extendedType: "did",
30
+ required: true
31
+ },
32
+ {
33
+ key: "load-env",
34
+ type: "string",
35
+ description: I18n.formatMessage("node.cli.commands.node-set-identity.params.load-env.description"),
36
+ required: false
37
+ }
38
+ ],
39
+ action: async (engineCore, envVars, params) => nodeSetIdentity(engineCore, envVars, params)
40
+ };
41
+ }
42
+ /**
43
+ * Command for setting a node identity.
44
+ * @param engineCore The engine core.
45
+ * @param envVars The environment variables for the node.
46
+ * @param params The parameters for the command.
47
+ * @param params.identity The DID to set for the node.
48
+ */
49
+ export async function nodeSetIdentity(engineCore, envVars, params) {
50
+ Did.guard("nodeSetIdentity", "identity", params.identity);
51
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-set-identity.labels.resolvingIdentity"));
52
+ const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
53
+ const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
54
+ const identityDocument = await identityResolverConnector.resolveDocument(params.identity);
55
+ if (Is.empty(identityDocument)) {
56
+ throw new NotFoundError("nodeSetIdentity", "identityNotFound", params.identity);
57
+ }
58
+ const state = engineCore.getState();
59
+ state.nodeId = params.identity;
60
+ engineCore.setStateDirty();
61
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-set-identity.labels.stored"));
62
+ CLIDisplay.done();
63
+ }
64
+ //# sourceMappingURL=nodeSetIdentity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeSetIdentity.js","sourceRo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MG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,UAA4D,EAC5D,OAAkC,EAClC,MAEC;IAED,GAAG,CAAC,KAAK,CAAC,iBAAiB,EAAE,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE1D,UAAU,CAAC,IAAI,CACd,IAAI,CAAC,aAAa,CAAC,8DAA8D,CAAC,CAClF,CAAC;IACF,MAAM,oCAAoC,GAAG,UAAU,CAAC,yBAAyB,CAChF,2BAA2B,CAC3B,CAAC;IAEF,MAAM,yBAAyB,GAAG,gCAAgC,CAAC,GAAG,CACrE,oCAAoC,CACpC,CAAC;IAEF,MAAM,gBAAgB,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1F,IAAI,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,aAAa,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IACjF,CAAC;IAED,MAAM,KAAK,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;IACpC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;IAC/B,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mDAAmD,CAAC,CAAC,CAAC;IAEzF,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { I18n, Is, NotFoundError } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did, IdentityResolverConnectorFactory } from \"@twin.org/identity-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"node-set-identity\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionNodeSetIdentity(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.node-set-identity.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.node-set-identity.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-identity.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-identity.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-identity.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => nodeSetIdentity(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting a node identity.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID to set for the node.\n */\nexport async function nodeSetIdentity(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"nodeSetIdentity\", \"identity\", params.identity);\n\n\tCLIDisplay.task(\n\t\tI18n.formatMessage(\"node.cli.commands.node-set-identity.labels.resolvingIdentity\")\n\t);\n\tconst defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverConnector\"\n\t);\n\n\tconst identityResolverConnector = IdentityResolverConnectorFactory.get(\n\t\tdefaultIdentityResolverConnectorType\n\t);\n\n\tconst identityDocument = await identityResolverConnector.resolveDocument(params.identity);\n\tif (Is.empty(identityDocument)) {\n\t\tthrow new NotFoundError(\"nodeSetIdentity\", \"identityNotFound\", params.identity);\n\t}\n\n\tconst state = engineCore.getState();\n\tstate.nodeId = params.identity;\n\tengineCore.setStateDirty();\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.node-set-identity.labels.stored\"));\n\n\tCLIDisplay.done();\n}\n"]}
@@ -0,0 +1,68 @@
1
+ import { CLIDisplay } from "@twin.org/cli-core";
2
+ import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
3
+ const COMMAND_NAME = "node-set-tenant";
4
+ /**
5
+ * Get the command definition parameters.
6
+ * @param commandDefinitions The registered command definitions.
7
+ */
8
+ export function getCommandDefinitionNodeSetTenant(commandDefinitions) {
9
+ commandDefinitions[COMMAND_NAME] = {
10
+ command: COMMAND_NAME,
11
+ description: I18n.formatMessage("node.cli.commands.node-set-tenant.description"),
12
+ example: I18n.formatMessage("node.cli.commands.node-set-tenant.example"),
13
+ requiresTenantId: false,
14
+ params: [
15
+ {
16
+ key: "env-prefix",
17
+ type: "string",
18
+ description: I18n.formatMessage("node.cli.commands.node-set-tenant.params.env-prefix.description"),
19
+ required: false
20
+ },
21
+ {
22
+ key: "tenant-id",
23
+ type: "string",
24
+ extendedType: "hex(32)",
25
+ description: I18n.formatMessage("node.cli.commands.node-set-tenant.params.tenant-id.description"),
26
+ required: true
27
+ },
28
+ {
29
+ key: "load-env",
30
+ type: "string",
31
+ description: I18n.formatMessage("node.cli.commands.node-set-tenant.params.load-env.description"),
32
+ required: false
33
+ }
34
+ ],
35
+ action: async (engineCore, envVars, params) => nodeSetTenant(engineCore, envVars, params)
36
+ };
37
+ }
38
+ /**
39
+ * Command for setting a node tenant.
40
+ * @param engineCore The engine core.
41
+ * @param envVars The environment variables for the node.
42
+ * @param params The parameters for the command.
43
+ * @param params.tenantId The tenant id to set for the node.
44
+ */
45
+ export async function nodeSetTenant(engineCore, envVars, params) {
46
+ Guards.stringHexLength("nodeSetTenant", "tenant-id", params.tenantId, 32);
47
+ const state = engineCore.getState();
48
+ if (state.nodeTenantId !== params.tenantId) {
49
+ const defaultTenantAdminComponentType = engineCore.getRegisteredInstanceType("tenantAdminComponent");
50
+ if (!Is.stringValue(defaultTenantAdminComponentType)) {
51
+ throw new GeneralError("nodeSetTenant", "tenantAdminComponentNotRegistered");
52
+ }
53
+ const tenantAdminComponent = ComponentFactory.get(defaultTenantAdminComponentType);
54
+ const tenant = await tenantAdminComponent.get(params.tenantId);
55
+ const currentNodeTenants = await tenantAdminComponent.query({ isNodeTenant: true });
56
+ for (const currentNodeTenant of currentNodeTenants.tenants) {
57
+ currentNodeTenant.isNodeTenant = false;
58
+ await tenantAdminComponent.update(currentNodeTenant);
59
+ }
60
+ tenant.isNodeTenant = true;
61
+ await tenantAdminComponent.update(tenant);
62
+ state.nodeTenantId = params.tenantId;
63
+ engineCore.setStateDirty();
64
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.node-set-tenant.labels.stored"));
65
+ }
66
+ CLIDisplay.done();
67
+ }
68
+ //# sourceMappingURL=nodeSetTenant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeSetTenant.js","sourceRoot":"","sources":["../../../src/commands/nodeSetTenant.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE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AC;IAEpC,IAAI,KAAK,CAAC,YAAY,KAAK,MAAM,CAAC,QAAQ,EAAE,CAAC;QAC5C,MAAM,+BAA+B,GACpC,UAAU,CAAC,yBAAyB,CAAC,sBAAsB,CAAC,CAAC;QAE9D,IAAI,CAAC,EAAE,CAAC,WAAW,CAAC,+BAA+B,CAAC,EAAE,CAAC;YACtD,MAAM,IAAI,YAAY,CAAC,eAAe,EAAE,mCAAmC,CAAC,CAAC;QAC9E,CAAC;QAED,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,GAAG,CAChD,+BAA+B,CAC/B,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAE/D,MAAM,kBAAkB,GAAG,MAAM,oBAAoB,CAAC,KAAK,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;QACpF,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,CAAC,OAAO,EAAE,CAAC;YAC5D,iBAAiB,CAAC,YAAY,GAAG,KAAK,CAAC;YACvC,MAAM,oBAAoB,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC;QACtD,CAAC;QAED,MAAM,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,MAAM,oBAAoB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1C,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC;QACrC,UAAU,CAAC,aAAa,EAAE,CAAC;QAE3B,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,iDAAiD,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ITenantAdminComponent } from \"@twin.org/api-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"node-set-tenant\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionNodeSetTenant(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.node-set-tenant.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.node-set-tenant.example\"),\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-tenant.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"tenant-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"hex(32)\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-tenant.params.tenant-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.node-set-tenant.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => nodeSetTenant(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for setting a node tenant.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.tenantId The tenant id to set for the node.\n */\nexport async function nodeSetTenant(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\ttenantId?: string;\n\t}\n): Promise<void> {\n\tGuards.stringHexLength(\"nodeSetTenant\", \"tenant-id\", params.tenantId, 32);\n\n\tconst state = engineCore.getState();\n\n\tif (state.nodeTenantId !== params.tenantId) {\n\t\tconst defaultTenantAdminComponentType =\n\t\t\tengineCore.getRegisteredInstanceType(\"tenantAdminComponent\");\n\n\t\tif (!Is.stringValue(defaultTenantAdminComponentType)) {\n\t\t\tthrow new GeneralError(\"nodeSetTenant\", \"tenantAdminComponentNotRegistered\");\n\t\t}\n\n\t\tconst tenantAdminComponent = ComponentFactory.get<ITenantAdminComponent>(\n\t\t\tdefaultTenantAdminComponentType\n\t\t);\n\n\t\tconst tenant = await tenantAdminComponent.get(params.tenantId);\n\n\t\tconst currentNodeTenants = await tenantAdminComponent.query({ isNodeTenant: true });\n\t\tfor (const currentNodeTenant of currentNodeTenants.tenants) {\n\t\t\tcurrentNodeTenant.isNodeTenant = false;\n\t\t\tawait tenantAdminComponent.update(currentNodeTenant);\n\t\t}\n\n\t\ttenant.isNodeTenant = true;\n\t\tawait tenantAdminComponent.update(tenant);\n\t\tstate.nodeTenantId = params.tenantId;\n\t\tengineCore.setStateDirty();\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.node-set-tenant.labels.stored\"));\n\t}\n\n\tCLIDisplay.done();\n}\n"]}