@twin.org/node-core 0.0.3-next.4 → 0.0.3-next.40

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 (186) hide show
  1. package/README.md +3 -1
  2. package/dist/es/builders/engineEnvBuilder.js +443 -126
  3. package/dist/es/builders/engineEnvBuilder.js.map +1 -1
  4. package/dist/es/builders/engineServerEnvBuilder.js +89 -32
  5. package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
  6. package/dist/es/builders/extensionsBuilder.js.map +1 -1
  7. package/dist/es/cli.js +247 -0
  8. package/dist/es/cli.js.map +1 -0
  9. package/dist/es/commands/bootstrapLegacy.js +199 -0
  10. package/dist/es/commands/bootstrapLegacy.js.map +1 -0
  11. package/dist/es/commands/help.js +85 -0
  12. package/dist/es/commands/help.js.map +1 -0
  13. package/dist/es/commands/identityCreate.js +327 -0
  14. package/dist/es/commands/identityCreate.js.map +1 -0
  15. package/dist/es/commands/identityImports.js +82 -0
  16. package/dist/es/commands/identityImports.js.map +1 -0
  17. package/dist/es/commands/identityVerifiableCredentialCreate.js +146 -0
  18. package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
  19. package/dist/es/commands/identityVerificationMethodCreate.js +228 -0
  20. package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
  21. package/dist/es/commands/identityVerificationMethodImport.js +126 -0
  22. package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
  23. package/dist/es/commands/nodeSetIdentity.js +64 -0
  24. package/dist/es/commands/nodeSetIdentity.js.map +1 -0
  25. package/dist/es/commands/nodeSetTenant.js +68 -0
  26. package/dist/es/commands/nodeSetTenant.js.map +1 -0
  27. package/dist/es/commands/tenantCreate.js +139 -0
  28. package/dist/es/commands/tenantCreate.js.map +1 -0
  29. package/dist/es/commands/tenantImport.js +97 -0
  30. package/dist/es/commands/tenantImport.js.map +1 -0
  31. package/dist/es/commands/tenantUpdate.js +94 -0
  32. package/dist/es/commands/tenantUpdate.js.map +1 -0
  33. package/dist/es/commands/userCreate.js +239 -0
  34. package/dist/es/commands/userCreate.js.map +1 -0
  35. package/dist/es/commands/userUpdate.js +154 -0
  36. package/dist/es/commands/userUpdate.js.map +1 -0
  37. package/dist/es/commands/vaultKeyCreate.js +191 -0
  38. package/dist/es/commands/vaultKeyCreate.js.map +1 -0
  39. package/dist/es/commands/vaultKeyImport.js +104 -0
  40. package/dist/es/commands/vaultKeyImport.js.map +1 -0
  41. package/dist/es/defaults.js +19 -1
  42. package/dist/es/defaults.js.map +1 -1
  43. package/dist/es/index.js +11 -4
  44. package/dist/es/index.js.map +1 -1
  45. package/dist/es/models/ICliArgs.js +4 -0
  46. package/dist/es/models/ICliArgs.js.map +1 -0
  47. package/dist/es/models/ICliCommand.js +2 -0
  48. package/dist/es/models/ICliCommand.js.map +1 -0
  49. package/dist/es/models/ICliCommandDefinition.js +2 -0
  50. package/dist/es/models/ICliCommandDefinition.js.map +1 -0
  51. package/dist/es/models/ICliCommandDefinitionParam.js +2 -0
  52. package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -0
  53. package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
  54. package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
  55. package/dist/es/models/INodeEngineState.js.map +1 -1
  56. package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
  57. package/dist/es/models/INodeOptions.js.map +1 -1
  58. package/dist/es/models/cliCommandParamType.js +4 -0
  59. package/dist/es/models/cliCommandParamType.js.map +1 -0
  60. package/dist/es/models/nodeExtensionInitialiseEngineMethod.js +2 -0
  61. package/dist/es/models/nodeExtensionInitialiseEngineMethod.js.map +1 -0
  62. package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js +2 -0
  63. package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js.map +1 -0
  64. package/dist/es/models/nodeExtensionInitialiseMethod.js +2 -0
  65. package/dist/es/models/nodeExtensionInitialiseMethod.js.map +1 -0
  66. package/dist/es/models/nodeExtensionShutdownMethod.js +4 -0
  67. package/dist/es/models/nodeExtensionShutdownMethod.js.map +1 -0
  68. package/dist/es/node.js +86 -39
  69. package/dist/es/node.js.map +1 -1
  70. package/dist/es/start.js +139 -0
  71. package/dist/es/start.js.map +1 -0
  72. package/dist/es/utils.js +12 -22
  73. package/dist/es/utils.js.map +1 -1
  74. package/dist/types/builders/engineEnvBuilder.d.ts +64 -1
  75. package/dist/types/builders/engineServerEnvBuilder.d.ts +11 -2
  76. package/dist/types/cli.d.ts +56 -0
  77. package/dist/types/commands/bootstrapLegacy.d.ts +66 -0
  78. package/dist/types/commands/help.d.ts +23 -0
  79. package/dist/types/commands/identityCreate.d.ts +39 -0
  80. package/dist/types/commands/identityImports.d.ts +24 -0
  81. package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
  82. package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
  83. package/dist/types/commands/identityVerificationMethodImport.d.ts +31 -0
  84. package/dist/types/commands/nodeSetIdentity.d.ts +22 -0
  85. package/dist/types/commands/nodeSetTenant.d.ts +22 -0
  86. package/dist/types/commands/tenantCreate.d.ts +38 -0
  87. package/dist/types/commands/tenantImport.d.ts +26 -0
  88. package/dist/types/commands/tenantUpdate.d.ts +26 -0
  89. package/dist/types/commands/userCreate.d.ts +51 -0
  90. package/dist/types/commands/userUpdate.d.ts +40 -0
  91. package/dist/types/commands/vaultKeyCreate.d.ts +43 -0
  92. package/dist/types/commands/vaultKeyImport.d.ts +28 -0
  93. package/dist/types/defaults.d.ts +10 -1
  94. package/dist/types/index.d.ts +11 -4
  95. package/dist/types/models/ICliArgs.d.ts +20 -0
  96. package/dist/types/models/ICliCommand.d.ts +17 -0
  97. package/dist/types/models/ICliCommandDefinition.d.ts +46 -0
  98. package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
  99. package/dist/types/models/IEngineEnvironmentVariables.d.ts +117 -60
  100. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +8 -0
  101. package/dist/types/models/INodeEngineState.d.ts +0 -8
  102. package/dist/types/models/INodeEnvironmentVariables.d.ts +0 -38
  103. package/dist/types/models/INodeOptions.d.ts +6 -2
  104. package/dist/types/models/cliCommandParamType.d.ts +4 -0
  105. package/dist/types/models/nodeExtensionInitialiseEngineMethod.d.ts +7 -0
  106. package/dist/types/models/nodeExtensionInitialiseEngineServerMethod.d.ts +8 -0
  107. package/dist/types/models/nodeExtensionInitialiseMethod.d.ts +8 -0
  108. package/dist/types/models/nodeExtensionShutdownMethod.d.ts +5 -0
  109. package/dist/types/node.d.ts +5 -4
  110. package/dist/types/{server.d.ts → start.d.ts} +4 -2
  111. package/dist/types/utils.d.ts +6 -8
  112. package/docs/changelog.md +532 -176
  113. package/docs/examples.md +99 -1
  114. package/docs/reference/functions/buildConfiguration.md +1 -1
  115. package/docs/reference/functions/buildEngineServerConfiguration.md +1 -1
  116. package/docs/reference/functions/constructCliCommand.md +27 -0
  117. package/docs/reference/functions/executeCommand.md +29 -0
  118. package/docs/reference/functions/getEnvDefaults.md +19 -0
  119. package/docs/reference/functions/getScriptDirectory.md +19 -0
  120. package/docs/reference/functions/isAuthEntityStorageRequired.md +20 -0
  121. package/docs/reference/functions/isAutomationRequired.md +20 -0
  122. package/docs/reference/functions/isBackgroundTasksRequired.md +20 -0
  123. package/docs/reference/functions/isFederatedCatalogueRequired.md +20 -0
  124. package/docs/reference/functions/isImmutableProofRequired.md +20 -0
  125. package/docs/reference/functions/isRightsManagementRequired.md +20 -0
  126. package/docs/reference/functions/isTaskSchedulerRequired.md +20 -0
  127. package/docs/reference/functions/isTelemetryRequired.md +20 -0
  128. package/docs/reference/functions/isTrustRequired.md +20 -0
  129. package/docs/reference/functions/isUrlTransformerRequired.md +20 -0
  130. package/docs/reference/functions/parseCommandLineArgs.md +19 -0
  131. package/docs/reference/functions/processEnvOptions.md +27 -0
  132. package/docs/reference/functions/registerCommands.md +9 -0
  133. package/docs/reference/functions/resolvePackageEntryPoint.md +2 -2
  134. package/docs/reference/functions/run.md +8 -2
  135. package/docs/reference/functions/start.md +9 -3
  136. package/docs/reference/functions/substituteEnvOptions.md +25 -0
  137. package/docs/reference/index.md +26 -13
  138. package/docs/reference/interfaces/ICacheMetadata.md +3 -3
  139. package/docs/reference/interfaces/ICliArgs.md +35 -0
  140. package/docs/reference/interfaces/ICliCommand.md +23 -0
  141. package/docs/reference/interfaces/ICliCommandDefinition.md +101 -0
  142. package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
  143. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +420 -311
  144. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +545 -368
  145. package/docs/reference/interfaces/IModuleProtocol.md +3 -3
  146. package/docs/reference/interfaces/INodeEngineState.md +4 -20
  147. package/docs/reference/interfaces/INodeEnvironmentVariables.md +551 -450
  148. package/docs/reference/interfaces/INodeOptions.md +44 -36
  149. package/docs/reference/interfaces/IProtocolHandlerResult.md +2 -2
  150. package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
  151. package/docs/reference/type-aliases/NodeExtensionInitialiseEngineMethod.md +1 -1
  152. package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +1 -1
  153. package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +1 -1
  154. package/docs/reference/type-aliases/NodeExtensionShutdownMethod.md +1 -1
  155. package/docs/reference/variables/ModuleProtocol.md +5 -5
  156. package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +3 -0
  157. package/docs/reference/variables/URL_TRANSFORMER_ENCRYPTION_KEY_ID.md +3 -0
  158. package/locales/en.json +600 -30
  159. package/package.json +10 -6
  160. package/dist/es/bootstrap.js +0 -366
  161. package/dist/es/bootstrap.js.map +0 -1
  162. package/dist/es/identity.js +0 -182
  163. package/dist/es/identity.js.map +0 -1
  164. package/dist/es/models/nodeExtensionMethods.js +0 -2
  165. package/dist/es/models/nodeExtensionMethods.js.map +0 -1
  166. package/dist/es/models/nodeFeatures.js +0 -21
  167. package/dist/es/models/nodeFeatures.js.map +0 -1
  168. package/dist/es/server.js +0 -81
  169. package/dist/es/server.js.map +0 -1
  170. package/dist/types/bootstrap.d.ts +0 -68
  171. package/dist/types/identity.d.ts +0 -14
  172. package/dist/types/models/nodeExtensionMethods.d.ts +0 -27
  173. package/dist/types/models/nodeFeatures.d.ts +0 -21
  174. package/docs/detailed-guide.md +0 -129
  175. package/docs/reference/functions/bootstrap.md +0 -29
  176. package/docs/reference/functions/bootstrapAuth.md +0 -35
  177. package/docs/reference/functions/bootstrapBlobEncryption.md +0 -35
  178. package/docs/reference/functions/bootstrapImmutableProofMethod.md +0 -35
  179. package/docs/reference/functions/bootstrapNodeAdminUser.md +0 -35
  180. package/docs/reference/functions/bootstrapNodeId.md +0 -35
  181. package/docs/reference/functions/bootstrapSynchronisedStorage.md +0 -35
  182. package/docs/reference/functions/bootstrapTenantId.md +0 -35
  183. package/docs/reference/functions/getFeatures.md +0 -19
  184. package/docs/reference/type-aliases/NodeFeatures.md +0 -5
  185. package/docs/reference/variables/NodeFeatures.md +0 -25
  186. package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userCreate.js","sourceRoot":"","sources":["../../../src/commands/userCreate.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,OAAO,EAAE,GAAG,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAKjF,MAAM,YAAY,GAAG,aAAa,CAAC;AAEnC;;;GAGG;AACH,MAAM,U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BACxD,SAAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE;gBACjC,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,EAAE;aACnC,CAAC;YAEF,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;gBACvC,MAAM,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;YAC9D,CAAC;YAED,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;gBACtC,MAAM,QAAQ,CAAC,YAAY,CAC1B,MAAM,CAAC,SAAS,EAChB;oBACC,GAAG,MAAM,CAAC,eAAe,QAAQ,MAAM,CAAC,YAAY,GAAG;oBACvD,GAAG,MAAM,CAAC,eAAe,qBAAqB,MAAM,CAAC,oBAAoB,GAAG;oBAC5E,GAAG,MAAM,CAAC,eAAe,UAAU,WAAW,GAAG;oBACjD,GAAG,MAAM,CAAC,eAAe,aAAa,IAAI,CAAC,QAAQ,GAAG;oBACtD,GAAG,MAAM,CAAC,eAAe,UAAU,MAAM,CAAC,KAAK,IAAI,EAAE,GAAG;oBACxD,GAAG,MAAM,CAAC,eAAe,eAAe,MAAM,CAAC,SAAS,IAAI,EAAE,GAAG;oBACjE,GAAG,MAAM,CAAC,eAAe,gBAAgB,MAAM,CAAC,UAAU,IAAI,EAAE,GAAG;iBACnE,EACD,KAAK,CACL,CAAC;YACH,CAAC;QACF,CAAC;QAED,UAAU,CAAC,IAAI,EAAE,CAAC;QAElB,OAAO,IAAI,CAAC;IACb,CAAC,CACD,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuthenticationAdminComponent,\n\tIAuthenticationUser\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport { PasswordGenerator } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did, IdentityProfileConnectorFactory } from \"@twin.org/identity-models\";\nimport type { Person, WithContext } from \"schema-dts\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"user-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionUserCreate(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.user-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.user-create.example\"),\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.user-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: \"user-identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"DID\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-create.params.user-identity.description\"\n\t\t\t\t)\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"organization-identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"DID\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-create.params.organization-identity.description\"\n\t\t\t\t)\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.user-create.params.tenant-id.description\"\n\t\t\t\t)\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"email\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"email\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.user-create.params.email.description\")\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"password\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-create.params.password.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: \"scope\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.user-create.params.scope.description\"),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"given-name\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-create.params.given-name.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: \"family-name\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-create.params.family-name.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.user-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.user-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.user-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.user-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.user-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) => userCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a user.\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.userIdentity The DID for the user.\n * @param params.organizationIdentity The organization DID for the user.\n * @param params.tenantId The tenant ID for the user.\n * @param params.email The email for the user.\n * @param params.password The password for the user.\n * @param params.scope The scope for the user.\n * @param params.givenName The given name for the user.\n * @param params.familyName The family name for the user.\n * @param params.overwriteMode The mode to use when a user with the same identity 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 user details or undefined if skipped.\n */\nexport async function userCreate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tuserIdentity?: string;\n\t\torganizationIdentity?: string;\n\t\ttenantId?: string;\n\t\temail?: string;\n\t\tpassword?: string;\n\t\tscope?: string;\n\t\tgivenName?: string;\n\t\tfamilyName?: 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\tdid: string;\n\t\t\torganizationDid: string;\n\t\t\temail: string;\n\t\t\tpassword: string;\n\t\t\tscope: string[];\n\t\t\tgivenName: string;\n\t\t\tfamilyName: string;\n\t }\n\t| undefined\n> {\n\tconst paramsEmail = params.email;\n\tconst paramsUserIdentity = params.userIdentity;\n\tconst paramsOrganizationIdentity = params.organizationIdentity;\n\tGuards.email(\"userCreate\", \"email\", paramsEmail);\n\tDid.guard(\"userCreate\", \"user-identity\", paramsUserIdentity);\n\tDid.guard(\"userCreate\", \"organization-identity\", paramsOrganizationIdentity);\n\tif (Is.stringValue(params.tenantId)) {\n\t\tGuards.stringHexLength(\"userCreate\", \"tenant-id\", params.tenantId, 32);\n\t} else if (envVars.tenantEnabled ?? false) {\n\t\tthrow new GeneralError(\"userCreate\", \"tenantIdRequired\");\n\t}\n\n\tif (Is.stringValue(params.password) && params.password.length < 16) {\n\t\tthrow new GeneralError(\"userCreate\", \"passwordTooShort\", { minLength: 16 });\n\t}\n\n\tconst defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\"identityProfileConnector\"\n\t);\n\tconst identityProfileConnector = IdentityProfileConnectorFactory.get(\n\t\tdefaultIdentityProfileConnectorType\n\t);\n\n\tconst defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"authenticationAdminComponent\"\n\t);\n\tconst authenticationAdminComponent = ComponentFactory.get<IAuthenticationAdminComponent>(\n\t\tdefaultAuthenticationAdminComponentType\n\t);\n\n\tlet createUser = true;\n\n\tconst currentContextIds = (await ContextIdStore.getContextIds()) ?? {};\n\tconst returnJson = await ContextIdStore.run(\n\t\t{ ...currentContextIds, [ContextIdKeys.Tenant]: params.tenantId },\n\t\tasync () => {\n\t\t\tlet existingUser: IAuthenticationUser | undefined;\n\t\t\ttry {\n\t\t\t\texistingUser = await authenticationAdminComponent.get(paramsEmail);\n\t\t\t} catch {}\n\n\t\t\tif (!Is.empty(existingUser)) {\n\t\t\t\tif (params.overwriteMode === \"error\") {\n\t\t\t\t\tthrow new GeneralError(\"userCreate\", \"userAlreadyExists\");\n\t\t\t\t} else if (params.overwriteMode === \"skip\") {\n\t\t\t\t\tcreateUser = false;\n\t\t\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.skipping\"));\n\t\t\t\t} else if (params.overwriteMode === \"overwrite\") {\n\t\t\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.overwriting\"));\n\t\t\t\t\tconst userToRemove = existingUser;\n\t\t\t\t\tawait ContextIdStore.run(\n\t\t\t\t\t\t{ ...currentContextIds, [ContextIdKeys.Tenant]: params.tenantId },\n\t\t\t\t\t\tasync () => {\n\t\t\t\t\t\t\tawait authenticationAdminComponent.remove(userToRemove.email);\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tawait identityProfileConnector.remove(userToRemove.userIdentity);\n\t\t\t\t\texistingUser = undefined;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet json;\n\t\t\tif (createUser) {\n\t\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.creating\"));\n\n\t\t\t\tconst user: IAuthenticationUser & { password: string } = {\n\t\t\t\t\temail: paramsEmail,\n\t\t\t\t\tpassword: params.password ?? PasswordGenerator.generate(16),\n\t\t\t\t\tuserIdentity: paramsUserIdentity,\n\t\t\t\t\torganizationIdentity: paramsOrganizationIdentity,\n\t\t\t\t\tscope: params.scope?.split(\",\").map(s => s.trim()) ?? []\n\t\t\t\t};\n\n\t\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.storingUser\"));\n\n\t\t\t\tawait ContextIdStore.run(\n\t\t\t\t\t{ ...currentContextIds, [ContextIdKeys.Tenant]: params.tenantId },\n\t\t\t\t\tasync () => {\n\t\t\t\t\t\tif (existingUser) {\n\t\t\t\t\t\t\tawait authenticationAdminComponent.update(user);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tawait authenticationAdminComponent.create(user);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t);\n\n\t\t\t\tconst name = `${params.givenName ?? \"\"} ${params.familyName ?? \"\"}`.trim();\n\t\t\t\tconst publicProfile: WithContext<Person> = {\n\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\tname: name.length > 0 ? name : undefined\n\t\t\t\t};\n\t\t\t\tconst privateProfile: WithContext<Person> = {\n\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\tgivenName: params.givenName,\n\t\t\t\t\tfamilyName: params.familyName,\n\t\t\t\t\temail: paramsEmail\n\t\t\t\t};\n\n\t\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.storingProfile\"));\n\t\t\t\tawait identityProfileConnector.create(paramsUserIdentity, publicProfile, privateProfile);\n\n\t\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-create.labels.userCreated\"));\n\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.user-create.labels.email\"),\n\t\t\t\t\tuser.email\n\t\t\t\t);\n\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.user-create.labels.password\"),\n\t\t\t\t\tuser.password\n\t\t\t\t);\n\n\t\t\t\tCLIDisplay.break();\n\n\t\t\t\tjson = {\n\t\t\t\t\tdid: paramsUserIdentity,\n\t\t\t\t\torganizationDid: paramsOrganizationIdentity,\n\t\t\t\t\temail: paramsEmail,\n\t\t\t\t\tpassword: user.password,\n\t\t\t\t\tscope: params.scope?.split(\",\").map(s => s.trim()) ?? [],\n\t\t\t\t\tgivenName: params.givenName ?? \"\",\n\t\t\t\t\tfamilyName: params.familyName ?? \"\"\n\t\t\t\t};\n\n\t\t\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t\t\t}\n\n\t\t\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\t\t\tawait CLIUtils.writeEnvFile(\n\t\t\t\t\t\tparams.outputEnv,\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t`${params.outputEnvPrefix}DID=\"${params.userIdentity}\"`,\n\t\t\t\t\t\t\t`${params.outputEnvPrefix}ORGANIZATION_DID=\"${params.organizationIdentity}\"`,\n\t\t\t\t\t\t\t`${params.outputEnvPrefix}EMAIL=\"${paramsEmail}\"`,\n\t\t\t\t\t\t\t`${params.outputEnvPrefix}PASSWORD=\"${user.password}\"`,\n\t\t\t\t\t\t\t`${params.outputEnvPrefix}SCOPE=\"${params.scope ?? \"\"}\"`,\n\t\t\t\t\t\t\t`${params.outputEnvPrefix}GIVEN_NAME=\"${params.givenName ?? \"\"}\"`,\n\t\t\t\t\t\t\t`${params.outputEnvPrefix}FAMILY_NAME=\"${params.familyName ?? \"\"}\"`\n\t\t\t\t\t\t],\n\t\t\t\t\t\tfalse\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tCLIDisplay.done();\n\n\t\t\treturn json;\n\t\t}\n\t);\n\n\treturn returnJson;\n}\n"]}
@@ -0,0 +1,154 @@
1
+ import { CLIDisplay } from "@twin.org/cli-core";
2
+ import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
3
+ import { ComponentFactory, GeneralError, Guards, I18n, Is } from "@twin.org/core";
4
+ import { Did, IdentityProfileConnectorFactory } from "@twin.org/identity-models";
5
+ const COMMAND_NAME = "user-update";
6
+ /**
7
+ * Get the command definition parameters.
8
+ * @param commandDefinitions The registered command definitions.
9
+ */
10
+ export function getCommandDefinitionUserUpdate(commandDefinitions) {
11
+ commandDefinitions[COMMAND_NAME] = {
12
+ command: COMMAND_NAME,
13
+ description: I18n.formatMessage("node.cli.commands.user-update.description"),
14
+ example: I18n.formatMessage("node.cli.commands.user-update.example"),
15
+ params: [
16
+ {
17
+ key: "env-prefix",
18
+ type: "string",
19
+ description: I18n.formatMessage("node.cli.commands.user-update.params.env-prefix.description"),
20
+ required: false
21
+ },
22
+ {
23
+ key: "user-identity",
24
+ type: "string",
25
+ extendedType: "DID",
26
+ description: I18n.formatMessage("node.cli.commands.user-update.params.user-identity.description"),
27
+ required: false
28
+ },
29
+ {
30
+ key: "organization-identity",
31
+ type: "string",
32
+ extendedType: "DID",
33
+ description: I18n.formatMessage("node.cli.commands.user-update.params.organization-identity.description"),
34
+ required: false
35
+ },
36
+ {
37
+ key: "tenant-id",
38
+ type: "string",
39
+ extendedType: "hex(32)",
40
+ description: I18n.formatMessage("node.cli.commands.user-update.params.tenant-id.description"),
41
+ required: false
42
+ },
43
+ {
44
+ key: "email",
45
+ type: "string",
46
+ extendedType: "email",
47
+ description: I18n.formatMessage("node.cli.commands.user-update.params.email.description")
48
+ },
49
+ {
50
+ key: "scope",
51
+ type: "string",
52
+ description: I18n.formatMessage("node.cli.commands.user-update.params.scope.description"),
53
+ required: false
54
+ },
55
+ {
56
+ key: "given-name",
57
+ type: "string",
58
+ description: I18n.formatMessage("node.cli.commands.user-update.params.given-name.description"),
59
+ required: false
60
+ },
61
+ {
62
+ key: "family-name",
63
+ type: "string",
64
+ description: I18n.formatMessage("node.cli.commands.user-update.params.family-name.description"),
65
+ required: false
66
+ },
67
+ {
68
+ key: "load-env",
69
+ type: "string",
70
+ description: I18n.formatMessage("node.cli.commands.user-update.params.load-env.description"),
71
+ required: false
72
+ }
73
+ ],
74
+ action: async (engineCore, envVars, params) => userUpdate(engineCore, envVars, params)
75
+ };
76
+ }
77
+ /**
78
+ * Command for updating a user.
79
+ * @param engineCore The engine core.
80
+ * @param envVars The environment variables for the node.
81
+ * @param params The parameters for the command.
82
+ * @param params.userIdentity The DID for the user.
83
+ * @param params.organizationIdentity The organization DID for the user.
84
+ * @param params.tenantId The tenant ID for the user.
85
+ * @param params.email The email for the user.
86
+ * @param params.scope The scope for the user.
87
+ * @param params.givenName The given name for the user.
88
+ * @param params.familyName The family name for the user.
89
+ * @returns The updated user details or undefined if skipped.
90
+ */
91
+ export async function userUpdate(engineCore, envVars, params) {
92
+ const paramsEmail = params.email;
93
+ const paramsUserIdentity = params.userIdentity;
94
+ const paramsOrganizationIdentity = params.organizationIdentity;
95
+ Guards.email("userUpdate", "email", paramsEmail);
96
+ if (Is.stringValue(paramsUserIdentity)) {
97
+ Did.guard("userUpdate", "user-identity", paramsUserIdentity);
98
+ }
99
+ if (Is.stringValue(paramsOrganizationIdentity)) {
100
+ Did.guard("userUpdate", "organization-identity", paramsOrganizationIdentity);
101
+ }
102
+ if (Is.stringValue(params.tenantId)) {
103
+ Guards.stringHexLength("userUpdate", "tenant-id", params.tenantId, 32);
104
+ }
105
+ else if (envVars.tenantEnabled ?? false) {
106
+ throw new GeneralError("userUpdate", "tenantIdRequired");
107
+ }
108
+ const defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType("identityProfileConnector");
109
+ const identityProfileConnector = IdentityProfileConnectorFactory.get(defaultIdentityProfileConnectorType);
110
+ const defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType("authenticationAdminComponent");
111
+ const authenticationAdminComponent = ComponentFactory.get(defaultAuthenticationAdminComponentType);
112
+ const currentContextIds = (await ContextIdStore.getContextIds()) ?? {};
113
+ const returnJson = await ContextIdStore.run({ ...currentContextIds, [ContextIdKeys.Tenant]: params.tenantId }, async () => {
114
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-update.labels.updating"));
115
+ const user = {
116
+ email: paramsEmail,
117
+ userIdentity: paramsUserIdentity,
118
+ organizationIdentity: paramsOrganizationIdentity,
119
+ scope: params.scope?.split(",").map(s => s.trim())
120
+ };
121
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-update.labels.storingUser"));
122
+ const existingUser = await authenticationAdminComponent.get(paramsEmail);
123
+ await authenticationAdminComponent.update(user);
124
+ const name = `${params.givenName ?? ""} ${params.familyName ?? ""}`.trim();
125
+ const publicProfile = {
126
+ "@context": "https://schema.org",
127
+ "@type": "Person",
128
+ name: name.length > 0 ? name : undefined
129
+ };
130
+ const privateProfile = {
131
+ "@context": "https://schema.org",
132
+ "@type": "Person",
133
+ givenName: params.givenName,
134
+ familyName: params.familyName,
135
+ email: paramsEmail
136
+ };
137
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-update.labels.storingProfile"));
138
+ await identityProfileConnector.update(existingUser.userIdentity, publicProfile, privateProfile);
139
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.user-update.labels.userUpdated"));
140
+ CLIDisplay.break();
141
+ const json = {
142
+ did: params.userIdentity ?? existingUser.userIdentity,
143
+ organizationDid: params.organizationIdentity ?? existingUser.organizationIdentity,
144
+ email: paramsEmail,
145
+ scope: params.scope?.split(",").map(s => s.trim()) ?? existingUser.scope,
146
+ givenName: params.givenName ?? "",
147
+ familyName: params.familyName ?? ""
148
+ };
149
+ CLIDisplay.done();
150
+ return json;
151
+ });
152
+ return returnJson;
153
+ }
154
+ //# sourceMappingURL=userUpdate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"userUpdate.js","sourceRoot":"","sources":["../../../src/commands/userUpdate.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAElF,OAAO,EAAE,GAAG,EAAE,+BAA+B,EAAE,MAAM,2BAA2B,CAAC;AAKjF,MAAM,YAAY,GAAG,aAAa,CAAC;AAEnC;;;GAGG;AAC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AAS,EAAE,MAAM,CAAC,SAAS,IAAI,EAAE;YACjC,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,EAAE;SACnC,CAAC;QAEF,UAAU,CAAC,IAAI,EAAE,CAAC;QAElB,OAAO,IAAI,CAAC;IACb,CAAC,CACD,CAAC;IAEF,OAAO,UAAU,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIAuthenticationAdminComponent,\n\tIAuthenticationUser\n} from \"@twin.org/api-auth-entity-storage-models\";\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { ComponentFactory, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did, IdentityProfileConnectorFactory } from \"@twin.org/identity-models\";\nimport type { Person, WithContext } from \"schema-dts\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"user-update\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionUserUpdate(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.user-update.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.user-update.example\"),\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.user-update.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: \"user-identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"DID\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-update.params.user-identity.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: \"organization-identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"DID\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-update.params.organization-identity.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.user-update.params.tenant-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: \"email\",\n\t\t\t\ttype: \"string\",\n\t\t\t\textendedType: \"email\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.user-update.params.email.description\")\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"scope\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\"node.cli.commands.user-update.params.scope.description\"),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"given-name\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-update.params.given-name.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: \"family-name\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-update.params.family-name.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: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.user-update.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) => userUpdate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for updating a user.\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.userIdentity The DID for the user.\n * @param params.organizationIdentity The organization DID for the user.\n * @param params.tenantId The tenant ID for the user.\n * @param params.email The email for the user.\n * @param params.scope The scope for the user.\n * @param params.givenName The given name for the user.\n * @param params.familyName The family name for the user.\n * @returns The updated user details or undefined if skipped.\n */\nexport async function userUpdate(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tuserIdentity?: string;\n\t\torganizationIdentity?: string;\n\t\ttenantId?: string;\n\t\temail?: string;\n\t\tscope?: string;\n\t\tgivenName?: string;\n\t\tfamilyName?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tdid: string;\n\t\t\torganizationDid: string;\n\t\t\temail: string;\n\t\t\tscope: string[];\n\t\t\tgivenName: string;\n\t\t\tfamilyName: string;\n\t }\n\t| undefined\n> {\n\tconst paramsEmail = params.email;\n\tconst paramsUserIdentity = params.userIdentity;\n\tconst paramsOrganizationIdentity = params.organizationIdentity;\n\n\tGuards.email(\"userUpdate\", \"email\", paramsEmail);\n\tif (Is.stringValue(paramsUserIdentity)) {\n\t\tDid.guard(\"userUpdate\", \"user-identity\", paramsUserIdentity);\n\t}\n\tif (Is.stringValue(paramsOrganizationIdentity)) {\n\t\tDid.guard(\"userUpdate\", \"organization-identity\", paramsOrganizationIdentity);\n\t}\n\tif (Is.stringValue(params.tenantId)) {\n\t\tGuards.stringHexLength(\"userUpdate\", \"tenant-id\", params.tenantId, 32);\n\t} else if (envVars.tenantEnabled ?? false) {\n\t\tthrow new GeneralError(\"userUpdate\", \"tenantIdRequired\");\n\t}\n\n\tconst defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\"identityProfileConnector\"\n\t);\n\tconst identityProfileConnector = IdentityProfileConnectorFactory.get(\n\t\tdefaultIdentityProfileConnectorType\n\t);\n\n\tconst defaultAuthenticationAdminComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"authenticationAdminComponent\"\n\t);\n\tconst authenticationAdminComponent = ComponentFactory.get<IAuthenticationAdminComponent>(\n\t\tdefaultAuthenticationAdminComponentType\n\t);\n\n\tconst currentContextIds = (await ContextIdStore.getContextIds()) ?? {};\n\tconst returnJson = await ContextIdStore.run(\n\t\t{ ...currentContextIds, [ContextIdKeys.Tenant]: params.tenantId },\n\t\tasync () => {\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-update.labels.updating\"));\n\n\t\t\tconst user: Partial<IAuthenticationUser> = {\n\t\t\t\temail: paramsEmail,\n\t\t\t\tuserIdentity: paramsUserIdentity,\n\t\t\t\torganizationIdentity: paramsOrganizationIdentity,\n\t\t\t\tscope: params.scope?.split(\",\").map(s => s.trim())\n\t\t\t};\n\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-update.labels.storingUser\"));\n\n\t\t\tconst existingUser = await authenticationAdminComponent.get(paramsEmail);\n\t\t\tawait authenticationAdminComponent.update(user);\n\n\t\t\tconst name = `${params.givenName ?? \"\"} ${params.familyName ?? \"\"}`.trim();\n\t\t\tconst publicProfile: WithContext<Person> = {\n\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\"@type\": \"Person\",\n\t\t\t\tname: name.length > 0 ? name : undefined\n\t\t\t};\n\t\t\tconst privateProfile: WithContext<Person> = {\n\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\"@type\": \"Person\",\n\t\t\t\tgivenName: params.givenName,\n\t\t\t\tfamilyName: params.familyName,\n\t\t\t\temail: paramsEmail\n\t\t\t};\n\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-update.labels.storingProfile\"));\n\t\t\tawait identityProfileConnector.update(\n\t\t\t\texistingUser.userIdentity,\n\t\t\t\tpublicProfile,\n\t\t\t\tprivateProfile\n\t\t\t);\n\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.user-update.labels.userUpdated\"));\n\n\t\t\tCLIDisplay.break();\n\n\t\t\tconst json = {\n\t\t\t\tdid: params.userIdentity ?? existingUser.userIdentity,\n\t\t\t\torganizationDid: params.organizationIdentity ?? existingUser.organizationIdentity,\n\t\t\t\temail: paramsEmail,\n\t\t\t\tscope: params.scope?.split(\",\").map(s => s.trim()) ?? existingUser.scope,\n\t\t\t\tgivenName: params.givenName ?? \"\",\n\t\t\t\tfamilyName: params.familyName ?? \"\"\n\t\t\t};\n\n\t\t\tCLIDisplay.done();\n\n\t\t\treturn json;\n\t\t}\n\t);\n\n\treturn returnJson;\n}\n"]}
@@ -0,0 +1,191 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
4
+ import { Converter, GeneralError, Guards, I18n, Is } from "@twin.org/core";
5
+ import { Did } from "@twin.org/identity-models";
6
+ import { VaultConnectorFactory, VaultKeyType } from "@twin.org/vault-models";
7
+ const COMMAND_NAME = "vault-key-create";
8
+ /**
9
+ * Get the command definition parameters.
10
+ * @param commandDefinitions The registered command definitions.
11
+ */
12
+ export function getCommandDefinitionVaultKeyCreate(commandDefinitions) {
13
+ commandDefinitions[COMMAND_NAME] = {
14
+ command: COMMAND_NAME,
15
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.description"),
16
+ example: I18n.formatMessage("node.cli.commands.vault-key-create.example"),
17
+ requiresNodeIdentity: false,
18
+ requiresTenantId: false,
19
+ params: [
20
+ {
21
+ key: "env-prefix",
22
+ type: "string",
23
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.env-prefix.description"),
24
+ required: false
25
+ },
26
+ {
27
+ key: "identity",
28
+ type: "string",
29
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.identity.description"),
30
+ extendedType: "did",
31
+ required: true
32
+ },
33
+ {
34
+ key: "key-id",
35
+ type: "string",
36
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.key-id.description"),
37
+ required: true
38
+ },
39
+ {
40
+ key: "key-type",
41
+ type: "string",
42
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.key-type.description"),
43
+ options: ["Ed25519", "Secp256k1", "ChaCha20Poly1305"],
44
+ defaultValue: "Ed25519",
45
+ required: false
46
+ },
47
+ {
48
+ key: "overwrite-mode",
49
+ type: "string",
50
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.overwrite-mode.description"),
51
+ options: ["skip", "overwrite", "error"],
52
+ defaultValue: "skip",
53
+ required: false
54
+ },
55
+ {
56
+ key: "load-env",
57
+ type: "string",
58
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.load-env.description"),
59
+ required: false
60
+ },
61
+ {
62
+ key: "output-json",
63
+ type: "string",
64
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.output-json.description"),
65
+ required: false
66
+ },
67
+ {
68
+ key: "output-env",
69
+ type: "string",
70
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.output-env.description"),
71
+ required: false
72
+ },
73
+ {
74
+ key: "output-env-prefix",
75
+ type: "string",
76
+ description: I18n.formatMessage("node.cli.commands.vault-key-create.params.output-env-prefix.description"),
77
+ required: false
78
+ }
79
+ ],
80
+ action: async (engineCore, envVars, params) => vaultKeyCreate(engineCore, envVars, params)
81
+ };
82
+ }
83
+ /**
84
+ * Command for creating a vault key.
85
+ * @param engineCore The engine core.
86
+ * @param envVars The environment variables for the node.
87
+ * @param params The parameters for the command.
88
+ * @param params.identity The DID to create the vault key for.
89
+ * @param params.keyId The ID of the key to create.
90
+ * @param params.keyType The type of key to create.
91
+ * @param params.overwriteMode The mode to use when a user with the same identity already exists.
92
+ * @param params.outputJson The output .json file to store the command output.
93
+ * @param params.outputEnv The output .env file to store the command output.
94
+ * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
95
+ * @returns The created vault key details or undefined if skipped.
96
+ */
97
+ export async function vaultKeyCreate(engineCore, envVars, params) {
98
+ Did.guard("vaultKeyCreate", "identity", params.identity);
99
+ Guards.stringValue("vaultKeyCreate", "key-id", params.keyId);
100
+ Guards.arrayOneOf("vaultKeyCreate", "key-type", params.keyType, [
101
+ "Ed25519",
102
+ "Secp256k1",
103
+ "ChaCha20Poly1305"
104
+ ]);
105
+ const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
106
+ const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
107
+ let createVaultKey = true;
108
+ const fullKeyId = `${params.identity}/${params.keyId}`;
109
+ let existingKey;
110
+ try {
111
+ existingKey = await vaultConnector.getKey(fullKeyId);
112
+ }
113
+ catch { }
114
+ if (!Is.empty(existingKey)) {
115
+ if (params.overwriteMode === "error") {
116
+ throw new GeneralError("vaultKeyCreate", "vaultKeyAlreadyExists");
117
+ }
118
+ else if (params.overwriteMode === "skip") {
119
+ createVaultKey = false;
120
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.vault-key-create.labels.skipping"));
121
+ }
122
+ else if (params.overwriteMode === "overwrite") {
123
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.vault-key-create.labels.overwriting"));
124
+ await vaultConnector.removeKey(fullKeyId);
125
+ }
126
+ }
127
+ let json;
128
+ if (createVaultKey) {
129
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.vault-key-create.labels.creating"));
130
+ CLIDisplay.spinnerStart();
131
+ await vaultConnector.createKey(fullKeyId, VaultKeyType[params.keyType]);
132
+ const key = await vaultConnector.getKey(fullKeyId);
133
+ CLIDisplay.spinnerStop();
134
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.vault-key-create.labels.created"));
135
+ const privateKeyBase64 = key.privateKey ? Converter.bytesToBase64(key.privateKey) : undefined;
136
+ const publicKeyBase64 = key.publicKey ? Converter.bytesToBase64(key.publicKey) : undefined;
137
+ const privateKeyHex = key.privateKey ? Converter.bytesToHex(key.privateKey, true) : undefined;
138
+ const publicKeyHex = key.publicKey ? Converter.bytesToHex(key.publicKey, true) : undefined;
139
+ CLIDisplay.break();
140
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.vault-key-create.labels.keyId"), params.keyId);
141
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.vault-key-create.labels.keyType"), params.keyType);
142
+ if (Is.stringValue(privateKeyBase64)) {
143
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.vault-key-create.labels.privateKeyBase64"), privateKeyBase64);
144
+ }
145
+ if (Is.stringValue(publicKeyBase64)) {
146
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.vault-key-create.labels.publicKeyBase64"), publicKeyBase64);
147
+ }
148
+ if (Is.stringValue(privateKeyHex)) {
149
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.vault-key-create.labels.privateKeyHex"), privateKeyHex);
150
+ }
151
+ if (Is.stringValue(publicKeyHex)) {
152
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.vault-key-create.labels.publicKeyHex"), publicKeyHex);
153
+ }
154
+ CLIDisplay.break();
155
+ json = {
156
+ identity: params.identity,
157
+ keyId: params.keyId,
158
+ keyType: params.keyType,
159
+ privateKeyBase64,
160
+ publicKeyBase64,
161
+ privateKeyHex,
162
+ publicKeyHex
163
+ };
164
+ if (Is.stringValue(params.outputJson)) {
165
+ await CLIUtils.writeJsonFile(params.outputJson, json, false);
166
+ }
167
+ if (Is.stringValue(params.outputEnv)) {
168
+ const outputParams = [
169
+ `${params.outputEnvPrefix}IDENTITY="${params.identity}"`,
170
+ `${params.outputEnvPrefix}KEY_ID="${params.keyId}"`,
171
+ `${params.outputEnvPrefix}KEY_TYPE="${params.keyType}"`
172
+ ];
173
+ if (Is.stringValue(privateKeyBase64)) {
174
+ outputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_BASE64="${privateKeyBase64}"`);
175
+ }
176
+ if (Is.stringValue(publicKeyBase64)) {
177
+ outputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_BASE64="${publicKeyBase64}"`);
178
+ }
179
+ if (Is.stringValue(privateKeyHex)) {
180
+ outputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_HEX="${privateKeyHex}"`);
181
+ }
182
+ if (Is.stringValue(publicKeyHex)) {
183
+ outputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_HEX="${publicKeyHex}"`);
184
+ }
185
+ await CLIUtils.writeEnvFile(params.outputEnv, outputParams, false);
186
+ }
187
+ }
188
+ CLIDisplay.done();
189
+ return json;
190
+ }
191
+ //# sourceMappingURL=vaultKeyCreate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vaultKeyCreate.js","sourceRoot":"","sources":["../../../src/commands/vaultKeyCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE3E,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAM7E,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,kBAElD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,gDAAgD,CAAC;QACjF,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,4CAA4C,CAAC;QACzE,oBAAoB,EAAE,KAAK;QAC3B,gBAAgB,EAAE,KAAK;QACvB,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gB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EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;gBAClC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,mBAAmB,YAAY,GAAG,CAAC,CAAC;YAChF,CAAC;YACD,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACpE,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 { Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\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 = \"vault-key-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionVaultKeyCreate(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.vault-key-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.vault-key-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.vault-key-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.vault-key-create.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: \"key-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-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: \"key-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-create.params.key-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"Ed25519\", \"Secp256k1\", \"ChaCha20Poly1305\"],\n\t\t\t\tdefaultValue: \"Ed25519\",\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.vault-key-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.vault-key-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.vault-key-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.vault-key-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.vault-key-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) => vaultKeyCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating a vault key.\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 create the vault key for.\n * @param params.keyId The ID of the key to create.\n * @param params.keyType The type of key to create.\n * @param params.overwriteMode The mode to use when a user with the same identity 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 vault key details or undefined if skipped.\n */\nexport async function vaultKeyCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tkeyType?: string;\n\t\tkeyId?: 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\tidentity: string;\n\t\t\tkeyId: string;\n\t\t\tkeyType?: string;\n\t\t\tprivateKeyBase64?: string;\n\t\t\tpublicKeyBase64?: string;\n\t\t\tprivateKeyHex?: string;\n\t\t\tpublicKeyHex?: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"vaultKeyCreate\", \"identity\", params.identity);\n\tGuards.stringValue(\"vaultKeyCreate\", \"key-id\", params.keyId);\n\tGuards.arrayOneOf(\"vaultKeyCreate\", \"key-type\", params.keyType, [\n\t\t\"Ed25519\",\n\t\t\"Secp256k1\",\n\t\t\"ChaCha20Poly1305\"\n\t]);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createVaultKey = true;\n\tconst fullKeyId = `${params.identity}/${params.keyId}`;\n\n\tlet existingKey;\n\ttry {\n\t\texistingKey = await vaultConnector.getKey(fullKeyId);\n\t} catch {}\n\n\tif (!Is.empty(existingKey)) {\n\t\tif (params.overwriteMode === \"error\") {\n\t\t\tthrow new GeneralError(\"vaultKeyCreate\", \"vaultKeyAlreadyExists\");\n\t\t} else if (params.overwriteMode === \"skip\") {\n\t\t\tcreateVaultKey = false;\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.skipping\"));\n\t\t} else if (params.overwriteMode === \"overwrite\") {\n\t\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.overwriting\"));\n\t\t\tawait vaultConnector.removeKey(fullKeyId);\n\t\t}\n\t}\n\n\tlet json;\n\tif (createVaultKey) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.creating\"));\n\t\tCLIDisplay.spinnerStart();\n\n\t\tawait vaultConnector.createKey(\n\t\t\tfullKeyId,\n\t\t\tVaultKeyType[params.keyType as keyof typeof VaultKeyType]\n\t\t);\n\n\t\tconst key = await vaultConnector.getKey(fullKeyId);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-create.labels.created\"));\n\n\t\tconst privateKeyBase64 = key.privateKey ? Converter.bytesToBase64(key.privateKey) : undefined;\n\t\tconst publicKeyBase64 = key.publicKey ? Converter.bytesToBase64(key.publicKey) : undefined;\n\t\tconst privateKeyHex = key.privateKey ? Converter.bytesToHex(key.privateKey, true) : undefined;\n\t\tconst publicKeyHex = key.publicKey ? Converter.bytesToHex(key.publicKey, true) : undefined;\n\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyId\"),\n\t\t\tparams.keyId\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.keyType\"),\n\t\t\tparams.keyType\n\t\t);\n\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyBase64\"),\n\t\t\t\tprivateKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyBase64\"),\n\t\t\t\tpublicKeyBase64\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.privateKeyHex\"),\n\t\t\t\tprivateKeyHex\n\t\t\t);\n\t\t}\n\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.vault-key-create.labels.publicKeyHex\"),\n\t\t\t\tpublicKeyHex\n\t\t\t);\n\t\t}\n\n\t\tCLIDisplay.break();\n\n\t\tjson = {\n\t\t\tidentity: params.identity,\n\t\t\tkeyId: params.keyId,\n\t\t\tkeyType: params.keyType,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64,\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex\n\t\t};\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 outputParams = [\n\t\t\t\t`${params.outputEnvPrefix}IDENTITY=\"${params.identity}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_ID=\"${params.keyId}\"`,\n\t\t\t\t`${params.outputEnvPrefix}KEY_TYPE=\"${params.keyType}\"`\n\t\t\t];\n\n\t\t\tif (Is.stringValue(privateKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`);\n\t\t\t}\n\n\t\t\tif (Is.stringValue(publicKeyBase64)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(privateKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PRIVATE_KEY_HEX=\"${privateKeyHex}\"`);\n\t\t\t}\n\t\t\tif (Is.stringValue(publicKeyHex)) {\n\t\t\t\toutputParams.push(`${params.outputEnvPrefix}PUBLIC_KEY_HEX=\"${publicKeyHex}\"`);\n\t\t\t}\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, outputParams, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
@@ -0,0 +1,104 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay } from "@twin.org/cli-core";
4
+ import { Converter, Guards, HexHelper, I18n, Is } from "@twin.org/core";
5
+ import { Ed25519 } from "@twin.org/crypto";
6
+ import { Did } from "@twin.org/identity-models";
7
+ import { VaultConnectorFactory, VaultKeyType } from "@twin.org/vault-models";
8
+ const COMMAND_NAME = "vault-key-import";
9
+ /**
10
+ * Get the command definition parameters.
11
+ * @param commandDefinitions The registered command definitions.
12
+ */
13
+ export function getCommandDefinitionVaultKeyImport(commandDefinitions) {
14
+ commandDefinitions[COMMAND_NAME] = {
15
+ command: COMMAND_NAME,
16
+ description: I18n.formatMessage("node.cli.commands.vault-key-import.description"),
17
+ example: I18n.formatMessage("node.cli.commands.vault-key-import.example"),
18
+ requiresNodeIdentity: false,
19
+ requiresTenantId: false,
20
+ params: [
21
+ {
22
+ key: "env-prefix",
23
+ type: "string",
24
+ description: I18n.formatMessage("node.cli.commands.vault-key-import.params.env-prefix.description"),
25
+ required: false
26
+ },
27
+ {
28
+ key: "identity",
29
+ type: "string",
30
+ description: I18n.formatMessage("node.cli.commands.vault-key-import.params.identity.description"),
31
+ extendedType: "did",
32
+ required: true
33
+ },
34
+ {
35
+ key: "key-id",
36
+ type: "string",
37
+ description: I18n.formatMessage("node.cli.commands.vault-key-import.params.key-id.description"),
38
+ required: true
39
+ },
40
+ {
41
+ key: "key-type",
42
+ type: "string",
43
+ description: I18n.formatMessage("node.cli.commands.vault-key-import.params.key-type.description"),
44
+ options: ["Ed25519", "Secp256k1", "ChaCha20Poly1305"],
45
+ defaultValue: "Ed25519",
46
+ required: false
47
+ },
48
+ {
49
+ key: "private-key-hex",
50
+ type: "string",
51
+ description: I18n.formatMessage("node.cli.commands.vault-key-import.params.private-key-hex.description"),
52
+ required: true
53
+ },
54
+ {
55
+ key: "load-env",
56
+ type: "string",
57
+ description: I18n.formatMessage("node.cli.commands.vault-key-import.params.load-env.description"),
58
+ required: false
59
+ }
60
+ ],
61
+ action: async (engineCore, envVars, params) => vaultKeyImport(engineCore, envVars, params)
62
+ };
63
+ }
64
+ /**
65
+ * Command for importing a vault key.
66
+ * @param engineCore The engine core.
67
+ * @param envVars The environment variables for the node.
68
+ * @param params The parameters for the command.
69
+ * @param params.identity The DID to create the vault key for.
70
+ * @param params.keyId The ID of the key to create.
71
+ * @param params.keyType The type of key to create.
72
+ * @param params.privateKeyHex The private key in hexadecimal format.
73
+ */
74
+ export async function vaultKeyImport(engineCore, envVars, params) {
75
+ Did.guard("vaultKeyImport", "identity", params.identity);
76
+ Guards.stringValue("vaultKeyImport", "key-id", params.keyId);
77
+ Guards.arrayOneOf("vaultKeyImport", "key-type", params.keyType, [
78
+ "Ed25519",
79
+ "Secp256k1",
80
+ "ChaCha20Poly1305"
81
+ ]);
82
+ Guards.stringHex("vaultKeyImport", "private-key-hex", params.privateKeyHex, true);
83
+ const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
84
+ const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
85
+ const fullKeyId = `${params.identity}/${params.keyId}`;
86
+ let existingKey;
87
+ try {
88
+ existingKey = await vaultConnector.getKey(fullKeyId);
89
+ if (!Is.empty(existingKey)) {
90
+ await vaultConnector.removeKey(fullKeyId);
91
+ }
92
+ }
93
+ catch { }
94
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.vault-key-import.labels.importing"));
95
+ CLIDisplay.spinnerStart();
96
+ const privateKeyBytes = Converter.hexToBytes(HexHelper.stripPrefix(params.privateKeyHex));
97
+ const publicKeyBytes = params.keyType === "Ed25519" ? Ed25519.publicKeyFromPrivateKey(privateKeyBytes) : undefined;
98
+ await vaultConnector.addKey(fullKeyId, VaultKeyType[params.keyType], privateKeyBytes, publicKeyBytes);
99
+ CLIDisplay.spinnerStop();
100
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.vault-key-import.labels.imported"));
101
+ CLIDisplay.break();
102
+ CLIDisplay.done();
103
+ }
104
+ //# sourceMappingURL=vaultKeyImport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vaultKeyImport.js","sourceRoot":"","sources":["../../../src/commands/vaultKeyImport.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAA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EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;YAC5B,MAAM,cAAc,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QAC3C,CAAC;IACF,CAAC;IAAC,MAAM,CAAC,CAAA,CAAC;IAEV,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,qDAAqD,CAAC,CAAC,CAAC;IAC3F,UAAU,CAAC,YAAY,EAAE,CAAC;IAE1B,MAAM,eAAe,GAAG,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IAC1F,MAAM,cAAc,GACnB,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,uBAAuB,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE7F,MAAM,cAAc,CAAC,MAAM,CAC1B,SAAS,EACT,YAAY,CAAC,MAAM,CAAC,OAAoC,CAAC,EACzD,eAAe,EACf,cAAc,CACd,CAAC;IAEF,UAAU,CAAC,WAAW,EAAE,CAAC;IACzB,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,oDAAoD,CAAC,CAAC,CAAC;IAE1F,UAAU,CAAC,KAAK,EAAE,CAAC;IACnB,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, Guards, HexHelper, I18n, Is } from \"@twin.org/core\";\nimport { Ed25519 } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did } from \"@twin.org/identity-models\";\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 = \"vault-key-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionVaultKeyImport(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.vault-key-import.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.vault-key-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.vault-key-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.vault-key-import.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: \"key-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.key-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: \"key-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.vault-key-import.params.key-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"Ed25519\", \"Secp256k1\", \"ChaCha20Poly1305\"],\n\t\t\t\tdefaultValue: \"Ed25519\",\n\t\t\t\trequired: false\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.vault-key-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.vault-key-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) => vaultKeyImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for importing a vault key.\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 create the vault key for.\n * @param params.keyId The ID of the key to create.\n * @param params.keyType The type of key to create.\n * @param params.privateKeyHex The private key in hexadecimal format.\n */\nexport async function vaultKeyImport(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tkeyType?: string;\n\t\tkeyId?: string;\n\t\tprivateKeyHex?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"vaultKeyImport\", \"identity\", params.identity);\n\tGuards.stringValue(\"vaultKeyImport\", \"key-id\", params.keyId);\n\tGuards.arrayOneOf(\"vaultKeyImport\", \"key-type\", params.keyType, [\n\t\t\"Ed25519\",\n\t\t\"Secp256k1\",\n\t\t\"ChaCha20Poly1305\"\n\t]);\n\tGuards.stringHex(\"vaultKeyImport\", \"private-key-hex\", params.privateKeyHex, true);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tconst fullKeyId = `${params.identity}/${params.keyId}`;\n\n\tlet existingKey;\n\ttry {\n\t\texistingKey = await vaultConnector.getKey(fullKeyId);\n\t\tif (!Is.empty(existingKey)) {\n\t\t\tawait vaultConnector.removeKey(fullKeyId);\n\t\t}\n\t} catch {}\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-import.labels.importing\"));\n\tCLIDisplay.spinnerStart();\n\n\tconst privateKeyBytes = Converter.hexToBytes(HexHelper.stripPrefix(params.privateKeyHex));\n\tconst publicKeyBytes =\n\t\tparams.keyType === \"Ed25519\" ? Ed25519.publicKeyFromPrivateKey(privateKeyBytes) : undefined;\n\n\tawait vaultConnector.addKey(\n\t\tfullKeyId,\n\t\tVaultKeyType[params.keyType as keyof typeof VaultKeyType],\n\t\tprivateKeyBytes,\n\t\tpublicKeyBytes\n\t);\n\n\tCLIDisplay.spinnerStop();\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.vault-key-import.labels.imported\"));\n\n\tCLIDisplay.break();\n\tCLIDisplay.done();\n}\n"]}
@@ -4,8 +4,26 @@ export const ATTESTATION_VERIFICATION_METHOD_ID = "attestation-assertion";
4
4
  export const IMMUTABLE_PROOF_VERIFICATION_METHOD_ID = "immutable-proof-assertion";
5
5
  export const BLOB_STORAGE_ENCRYPTION_KEY_ID = "blob-encryption";
6
6
  export const SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID = "synchronised-storage-blob-encryption";
7
- export const VC_AUTHENTICATION_VERIFICATION_METHOD_ID = "node-authentication-assertion";
7
+ export const TRUST_VERIFICATION_METHOD_ID = "trust-assertion";
8
8
  export const AUTH_SIGNING_KEY_ID = "auth-signing";
9
+ export const URL_TRANSFORMER_ENCRYPTION_KEY_ID = "param-encryption";
9
10
  export const CONTEXT_ID_HANDLER_FEATURE_DID = "did";
10
11
  export const CONTEXT_ID_HANDLER_FEATURE_TENANT = "tenant";
12
+ /**
13
+ * Get the default environment variables for the node.
14
+ * @param envPrefix The environment variable prefix.
15
+ * @returns The default environment variables.
16
+ */
17
+ export function getEnvDefaults(envPrefix) {
18
+ const envVars = {
19
+ [`${envPrefix}ATTESTATION_VERIFICATION_METHOD_ID`]: ATTESTATION_VERIFICATION_METHOD_ID,
20
+ [`${envPrefix}IMMUTABLE_PROOF_VERIFICATION_METHOD_ID`]: IMMUTABLE_PROOF_VERIFICATION_METHOD_ID,
21
+ [`${envPrefix}BLOB_STORAGE_ENCRYPTION_KEY_ID`]: BLOB_STORAGE_ENCRYPTION_KEY_ID,
22
+ [`${envPrefix}SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID`]: SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID,
23
+ [`${envPrefix}TRUST_VERIFICATION_METHOD_ID`]: TRUST_VERIFICATION_METHOD_ID,
24
+ [`${envPrefix}AUTH_SIGNING_KEY_ID`]: AUTH_SIGNING_KEY_ID,
25
+ [`${envPrefix}URL_TRANSFORMER_ENCRYPTION_KEY_ID`]: URL_TRANSFORMER_ENCRYPTION_KEY_ID
26
+ };
27
+ return envVars;
28
+ }
11
29
  //# sourceMappingURL=defaults.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/defaults.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC,MAAM,CAAC,MAAM,kCAAkC,GAAG,uBAAuB,CAAC;AAC1E,MAAM,CAAC,MAAM,sCAAsC,GAAG,2BAA2B,CAAC;AAClF,MAAM,CAAC,MAAM,8BAA8B,GAAG,iBAAiB,CAAC;AAChE,MAAM,CAAC,MAAM,mDAAmD,GAC/D,sCAAsC,CAAC;AACxC,MAAM,CAAC,MAAM,wCAAwC,GAAG,+BAA+B,CAAC;AACxF,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAClD,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AACpD,MAAM,CAAC,MAAM,iCAAiC,GAAG,QAAQ,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\nexport const ATTESTATION_VERIFICATION_METHOD_ID = \"attestation-assertion\";\nexport const IMMUTABLE_PROOF_VERIFICATION_METHOD_ID = \"immutable-proof-assertion\";\nexport const BLOB_STORAGE_ENCRYPTION_KEY_ID = \"blob-encryption\";\nexport const SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID =\n\t\"synchronised-storage-blob-encryption\";\nexport const VC_AUTHENTICATION_VERIFICATION_METHOD_ID = \"node-authentication-assertion\";\nexport const AUTH_SIGNING_KEY_ID = \"auth-signing\";\nexport const CONTEXT_ID_HANDLER_FEATURE_DID = \"did\";\nexport const CONTEXT_ID_HANDLER_FEATURE_TENANT = \"tenant\";\n"]}
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/defaults.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC,MAAM,CAAC,MAAM,kCAAkC,GAAG,uBAAuB,CAAC;AAC1E,MAAM,CAAC,MAAM,sCAAsC,GAAG,2BAA2B,CAAC;AAClF,MAAM,CAAC,MAAM,8BAA8B,GAAG,iBAAiB,CAAC;AAChE,MAAM,CAAC,MAAM,mDAAmD,GAC/D,sCAAsC,CAAC;AACxC,MAAM,CAAC,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AAC9D,MAAM,CAAC,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAClD,MAAM,CAAC,MAAM,iCAAiC,GAAG,kBAAkB,CAAC;AACpE,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,CAAC;AACpD,MAAM,CAAC,MAAM,iCAAiC,GAAG,QAAQ,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,SAAiB;IAC/C,MAAM,OAAO,GAA8B;QAC1C,CAAC,GAAG,SAAS,oCAAoC,CAAC,EAAE,kCAAkC;QACtF,CAAC,GAAG,SAAS,wCAAwC,CAAC,EAAE,sCAAsC;QAC9F,CAAC,GAAG,SAAS,gCAAgC,CAAC,EAAE,8BAA8B;QAC9E,CAAC,GAAG,SAAS,qDAAqD,CAAC,EAClE,mDAAmD;QACpD,CAAC,GAAG,SAAS,8BAA8B,CAAC,EAAE,4BAA4B;QAC1E,CAAC,GAAG,SAAS,qBAAqB,CAAC,EAAE,mBAAmB;QACxD,CAAC,GAAG,SAAS,mCAAmC,CAAC,EAAE,iCAAiC;KACpF,CAAC;IACF,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\nexport const ATTESTATION_VERIFICATION_METHOD_ID = \"attestation-assertion\";\nexport const IMMUTABLE_PROOF_VERIFICATION_METHOD_ID = \"immutable-proof-assertion\";\nexport const BLOB_STORAGE_ENCRYPTION_KEY_ID = \"blob-encryption\";\nexport const SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID =\n\t\"synchronised-storage-blob-encryption\";\nexport const TRUST_VERIFICATION_METHOD_ID = \"trust-assertion\";\nexport const AUTH_SIGNING_KEY_ID = \"auth-signing\";\nexport const URL_TRANSFORMER_ENCRYPTION_KEY_ID = \"param-encryption\";\nexport const CONTEXT_ID_HANDLER_FEATURE_DID = \"did\";\nexport const CONTEXT_ID_HANDLER_FEATURE_TENANT = \"tenant\";\n\n/**\n * Get the default environment variables for the node.\n * @param envPrefix The environment variable prefix.\n * @returns The default environment variables.\n */\nexport function getEnvDefaults(envPrefix: string): { [key: string]: string } {\n\tconst envVars: { [key: string]: string } = {\n\t\t[`${envPrefix}ATTESTATION_VERIFICATION_METHOD_ID`]: ATTESTATION_VERIFICATION_METHOD_ID,\n\t\t[`${envPrefix}IMMUTABLE_PROOF_VERIFICATION_METHOD_ID`]: IMMUTABLE_PROOF_VERIFICATION_METHOD_ID,\n\t\t[`${envPrefix}BLOB_STORAGE_ENCRYPTION_KEY_ID`]: BLOB_STORAGE_ENCRYPTION_KEY_ID,\n\t\t[`${envPrefix}SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID`]:\n\t\t\tSYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID,\n\t\t[`${envPrefix}TRUST_VERIFICATION_METHOD_ID`]: TRUST_VERIFICATION_METHOD_ID,\n\t\t[`${envPrefix}AUTH_SIGNING_KEY_ID`]: AUTH_SIGNING_KEY_ID,\n\t\t[`${envPrefix}URL_TRANSFORMER_ENCRYPTION_KEY_ID`]: URL_TRANSFORMER_ENCRYPTION_KEY_ID\n\t};\n\treturn envVars;\n}\n"]}