@twin.org/node-core 0.0.3-next.9 → 0.9.0

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 (230) hide show
  1. package/README.md +3 -1
  2. package/dist/es/builders/engineEnvBuilder.js +470 -174
  3. package/dist/es/builders/engineEnvBuilder.js.map +1 -1
  4. package/dist/es/builders/engineServerEnvBuilder.js +87 -39
  5. package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
  6. package/dist/es/builders/extensionsBuilder.js +3 -3
  7. package/dist/es/builders/extensionsBuilder.js.map +1 -1
  8. package/dist/es/cli.js +254 -0
  9. package/dist/es/cli.js.map +1 -0
  10. package/dist/es/commands/bootstrapLegacy.js +312 -0
  11. package/dist/es/commands/bootstrapLegacy.js.map +1 -0
  12. package/dist/es/commands/help.js +86 -0
  13. package/dist/es/commands/help.js.map +1 -0
  14. package/dist/es/commands/identityCreate.js +377 -0
  15. package/dist/es/commands/identityCreate.js.map +1 -0
  16. package/dist/es/commands/identityImports.js +83 -0
  17. package/dist/es/commands/identityImports.js.map +1 -0
  18. package/dist/es/commands/identityVerifiableCredentialCreate.js +146 -0
  19. package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
  20. package/dist/es/commands/identityVerificationMethodCreate.js +231 -0
  21. package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
  22. package/dist/es/commands/identityVerificationMethodImport.js +127 -0
  23. package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
  24. package/dist/es/commands/nodeSetIdentity.js +69 -0
  25. package/dist/es/commands/nodeSetIdentity.js.map +1 -0
  26. package/dist/es/commands/removeTenantOrgAlias.js +83 -0
  27. package/dist/es/commands/removeTenantOrgAlias.js.map +1 -0
  28. package/dist/es/commands/setNodeOrgId.js +62 -0
  29. package/dist/es/commands/setNodeOrgId.js.map +1 -0
  30. package/dist/es/commands/setTenantOrgId.js +99 -0
  31. package/dist/es/commands/setTenantOrgId.js.map +1 -0
  32. package/dist/es/commands/tenantCreate.js +165 -0
  33. package/dist/es/commands/tenantCreate.js.map +1 -0
  34. package/dist/es/commands/tenantImport.js +108 -0
  35. package/dist/es/commands/tenantImport.js.map +1 -0
  36. package/dist/es/commands/tenantUpdate.js +108 -0
  37. package/dist/es/commands/tenantUpdate.js.map +1 -0
  38. package/dist/es/commands/userCreate.js +239 -0
  39. package/dist/es/commands/userCreate.js.map +1 -0
  40. package/dist/es/commands/userUpdate.js +154 -0
  41. package/dist/es/commands/userUpdate.js.map +1 -0
  42. package/dist/es/commands/vaultKeyCreate.js +191 -0
  43. package/dist/es/commands/vaultKeyCreate.js.map +1 -0
  44. package/dist/es/commands/vaultKeyImport.js +105 -0
  45. package/dist/es/commands/vaultKeyImport.js.map +1 -0
  46. package/dist/es/defaults.js +37 -2
  47. package/dist/es/defaults.js.map +1 -1
  48. package/dist/es/index.js +13 -4
  49. package/dist/es/index.js.map +1 -1
  50. package/dist/es/models/IBootstrapLegacyEnvironmentVariables.js +4 -0
  51. package/dist/es/models/IBootstrapLegacyEnvironmentVariables.js.map +1 -0
  52. package/dist/es/models/ICliArgs.js +4 -0
  53. package/dist/es/models/ICliArgs.js.map +1 -0
  54. package/dist/es/models/ICliCommand.js +2 -0
  55. package/dist/es/models/ICliCommand.js.map +1 -0
  56. package/dist/es/models/ICliCommandDefinition.js +2 -0
  57. package/dist/es/models/ICliCommandDefinition.js.map +1 -0
  58. package/dist/es/models/ICliCommandDefinitionParam.js +2 -0
  59. package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -0
  60. package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
  61. package/dist/es/models/IEngineServerEnvironmentVariables.js +2 -0
  62. package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
  63. package/dist/es/models/IEnvironmentVariables.js +2 -0
  64. package/dist/es/models/IEnvironmentVariables.js.map +1 -0
  65. package/dist/es/models/INodeEngineState.js.map +1 -1
  66. package/dist/es/models/INodeEnvironmentVariables.js +2 -0
  67. package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
  68. package/dist/es/models/INodeOptions.js.map +1 -1
  69. package/dist/es/models/bootstrapLegacyEnvironmentVariableKeys.js +24 -0
  70. package/dist/es/models/bootstrapLegacyEnvironmentVariableKeys.js.map +1 -0
  71. package/dist/es/models/cliCommandParamType.js +4 -0
  72. package/dist/es/models/cliCommandParamType.js.map +1 -0
  73. package/dist/es/models/engineEnvironmentVariableKeys.js +202 -0
  74. package/dist/es/models/engineEnvironmentVariableKeys.js.map +1 -0
  75. package/dist/es/models/engineServerEnvironmentVariableKeys.js +35 -0
  76. package/dist/es/models/engineServerEnvironmentVariableKeys.js.map +1 -0
  77. package/dist/es/models/nodeEnvironmentVariableKeys.js +18 -0
  78. package/dist/es/models/nodeEnvironmentVariableKeys.js.map +1 -0
  79. package/dist/es/models/nodeExtensionInitialiseEngineMethod.js +2 -0
  80. package/dist/es/models/nodeExtensionInitialiseEngineMethod.js.map +1 -0
  81. package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js +2 -0
  82. package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js.map +1 -0
  83. package/dist/es/models/nodeExtensionInitialiseMethod.js +2 -0
  84. package/dist/es/models/nodeExtensionInitialiseMethod.js.map +1 -0
  85. package/dist/es/models/nodeExtensionShutdownMethod.js +4 -0
  86. package/dist/es/models/nodeExtensionShutdownMethod.js.map +1 -0
  87. package/dist/es/node.js +180 -42
  88. package/dist/es/node.js.map +1 -1
  89. package/dist/es/start.js +189 -0
  90. package/dist/es/start.js.map +1 -0
  91. package/dist/es/utils.js +24 -27
  92. package/dist/es/utils.js.map +1 -1
  93. package/dist/types/builders/engineEnvBuilder.d.ts +60 -5
  94. package/dist/types/builders/engineServerEnvBuilder.d.ts +12 -3
  95. package/dist/types/builders/extensionsBuilder.d.ts +8 -8
  96. package/dist/types/cli.d.ts +56 -0
  97. package/dist/types/commands/bootstrapLegacy.d.ts +20 -0
  98. package/dist/types/commands/help.d.ts +24 -0
  99. package/dist/types/commands/identityCreate.d.ts +45 -0
  100. package/dist/types/commands/identityImports.d.ts +25 -0
  101. package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
  102. package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
  103. package/dist/types/commands/identityVerificationMethodImport.d.ts +32 -0
  104. package/dist/types/commands/nodeSetIdentity.d.ts +23 -0
  105. package/dist/types/commands/removeTenantOrgAlias.d.ts +24 -0
  106. package/dist/types/commands/setNodeOrgId.d.ts +24 -0
  107. package/dist/types/commands/setTenantOrgId.d.ts +38 -0
  108. package/dist/types/commands/tenantCreate.d.ts +41 -0
  109. package/dist/types/commands/tenantImport.d.ts +29 -0
  110. package/dist/types/commands/tenantUpdate.d.ts +29 -0
  111. package/dist/types/commands/userCreate.d.ts +51 -0
  112. package/dist/types/commands/userUpdate.d.ts +40 -0
  113. package/dist/types/commands/vaultKeyCreate.d.ts +43 -0
  114. package/dist/types/commands/vaultKeyImport.d.ts +29 -0
  115. package/dist/types/defaults.d.ts +30 -2
  116. package/dist/types/index.d.ts +13 -4
  117. package/dist/types/models/IBootstrapLegacyEnvironmentVariables.d.ts +56 -0
  118. package/dist/types/models/ICliArgs.d.ts +20 -0
  119. package/dist/types/models/ICliCommand.d.ts +17 -0
  120. package/dist/types/models/ICliCommandDefinition.d.ts +46 -0
  121. package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
  122. package/dist/types/models/IEngineEnvironmentVariables.d.ts +199 -96
  123. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +9 -2
  124. package/dist/types/models/IEnvironmentVariables.d.ts +8 -0
  125. package/dist/types/models/INodeEngineState.d.ts +2 -9
  126. package/dist/types/models/INodeEnvironmentVariables.d.ts +1 -40
  127. package/dist/types/models/INodeOptions.d.ts +9 -5
  128. package/dist/types/models/bootstrapLegacyEnvironmentVariableKeys.d.ts +4 -0
  129. package/dist/types/models/cliCommandParamType.d.ts +4 -0
  130. package/dist/types/models/engineEnvironmentVariableKeys.d.ts +4 -0
  131. package/dist/types/models/engineServerEnvironmentVariableKeys.d.ts +7 -0
  132. package/dist/types/models/nodeEnvironmentVariableKeys.d.ts +5 -0
  133. package/dist/types/models/nodeExtensionInitialiseEngineMethod.d.ts +8 -0
  134. package/dist/types/models/nodeExtensionInitialiseEngineServerMethod.d.ts +9 -0
  135. package/dist/types/models/nodeExtensionInitialiseMethod.d.ts +9 -0
  136. package/dist/types/models/nodeExtensionShutdownMethod.d.ts +6 -0
  137. package/dist/types/node.d.ts +8 -7
  138. package/dist/types/{server.d.ts → start.d.ts} +6 -3
  139. package/dist/types/utils.d.ts +9 -10
  140. package/docs/changelog.md +883 -186
  141. package/docs/examples.md +99 -1
  142. package/docs/reference/functions/buildConfiguration.md +3 -3
  143. package/docs/reference/functions/buildEngineConfiguration.md +1 -7
  144. package/docs/reference/functions/buildEngineServerConfiguration.md +1 -1
  145. package/docs/reference/functions/constructCliCommand.md +27 -0
  146. package/docs/reference/functions/executeCommand.md +29 -0
  147. package/docs/reference/functions/extensionsConfiguration.md +1 -1
  148. package/docs/reference/functions/extensionsInitialiseEngine.md +2 -2
  149. package/docs/reference/functions/extensionsInitialiseEngineServer.md +2 -2
  150. package/docs/reference/functions/getEnvDefaults.md +19 -0
  151. package/docs/reference/functions/getScriptDirectory.md +19 -0
  152. package/docs/reference/functions/initialiseLocales.md +2 -0
  153. package/docs/reference/functions/isAuthEntityStorageRequired.md +20 -0
  154. package/docs/reference/functions/isAutomationRequired.md +20 -0
  155. package/docs/reference/functions/isBackgroundTasksRequired.md +20 -0
  156. package/docs/reference/functions/isFederatedCatalogueRequired.md +20 -0
  157. package/docs/reference/functions/isImmutableProofRequired.md +20 -0
  158. package/docs/reference/functions/isRightsManagementRequired.md +23 -0
  159. package/docs/reference/functions/isTaskSchedulerRequired.md +20 -0
  160. package/docs/reference/functions/isTelemetryRequired.md +20 -0
  161. package/docs/reference/functions/isTrustRequired.md +20 -0
  162. package/docs/reference/functions/loadJsonFile.md +1 -1
  163. package/docs/reference/functions/loadTextFile.md +1 -1
  164. package/docs/reference/functions/overrideModuleImport.md +1 -1
  165. package/docs/reference/functions/parseCommandLineArgs.md +19 -0
  166. package/docs/reference/functions/processEnvOptions.md +27 -0
  167. package/docs/reference/functions/registerCommands.md +9 -0
  168. package/docs/reference/functions/resolvePackageEntryPoint.md +2 -2
  169. package/docs/reference/functions/run.md +8 -2
  170. package/docs/reference/functions/shutdownExtensions.md +2 -2
  171. package/docs/reference/functions/start.md +10 -4
  172. package/docs/reference/functions/substituteEnvOptions.md +25 -0
  173. package/docs/reference/index.md +26 -14
  174. package/docs/reference/interfaces/IBootstrapLegacyEnvironmentVariables.md +117 -0
  175. package/docs/reference/interfaces/ICacheMetadata.md +3 -3
  176. package/docs/reference/interfaces/ICliArgs.md +35 -0
  177. package/docs/reference/interfaces/ICliCommand.md +23 -0
  178. package/docs/reference/interfaces/ICliCommandDefinition.md +101 -0
  179. package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
  180. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +553 -365
  181. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +41 -1746
  182. package/docs/reference/interfaces/IModuleProtocol.md +3 -3
  183. package/docs/reference/interfaces/INodeEngineState.md +6 -21
  184. package/docs/reference/interfaces/INodeEnvironmentVariables.md +10 -1967
  185. package/docs/reference/interfaces/INodeOptions.md +46 -38
  186. package/docs/reference/interfaces/IProtocolHandlerResult.md +2 -2
  187. package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
  188. package/docs/reference/type-aliases/IEnvironmentVariables.md +5 -0
  189. package/docs/reference/type-aliases/NodeExtensionInitialiseEngineMethod.md +3 -1
  190. package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +3 -1
  191. package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +4 -2
  192. package/docs/reference/type-aliases/NodeExtensionShutdownMethod.md +3 -1
  193. package/docs/reference/variables/ATTESTATION_VERIFICATION_METHOD_ID.md +2 -0
  194. package/docs/reference/variables/AUTH_SIGNING_KEY_ID.md +2 -0
  195. package/docs/reference/variables/BLOB_STORAGE_ENCRYPTION_KEY_ID.md +2 -0
  196. package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_DID.md +2 -0
  197. package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_TENANT.md +2 -0
  198. package/docs/reference/variables/IMMUTABLE_PROOF_VERIFICATION_METHOD_ID.md +2 -0
  199. package/docs/reference/variables/ModuleProtocol.md +5 -5
  200. package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +5 -0
  201. package/locales/en.json +680 -30
  202. package/package.json +30 -27
  203. package/dist/es/bootstrap.js +0 -383
  204. package/dist/es/bootstrap.js.map +0 -1
  205. package/dist/es/identity.js +0 -182
  206. package/dist/es/identity.js.map +0 -1
  207. package/dist/es/models/nodeExtensionMethods.js +0 -2
  208. package/dist/es/models/nodeExtensionMethods.js.map +0 -1
  209. package/dist/es/models/nodeFeatures.js +0 -21
  210. package/dist/es/models/nodeFeatures.js.map +0 -1
  211. package/dist/es/server.js +0 -81
  212. package/dist/es/server.js.map +0 -1
  213. package/dist/types/bootstrap.d.ts +0 -68
  214. package/dist/types/identity.d.ts +0 -14
  215. package/dist/types/models/nodeExtensionMethods.d.ts +0 -27
  216. package/dist/types/models/nodeFeatures.d.ts +0 -21
  217. package/docs/detailed-guide.md +0 -129
  218. package/docs/reference/functions/bootstrap.md +0 -29
  219. package/docs/reference/functions/bootstrapAuth.md +0 -35
  220. package/docs/reference/functions/bootstrapBlobEncryption.md +0 -35
  221. package/docs/reference/functions/bootstrapImmutableProofMethod.md +0 -35
  222. package/docs/reference/functions/bootstrapNodeAdminUser.md +0 -35
  223. package/docs/reference/functions/bootstrapNodeId.md +0 -35
  224. package/docs/reference/functions/bootstrapSynchronisedStorage.md +0 -35
  225. package/docs/reference/functions/bootstrapTenantId.md +0 -35
  226. package/docs/reference/functions/getFeatures.md +0 -19
  227. package/docs/reference/type-aliases/NodeFeatures.md +0 -5
  228. package/docs/reference/variables/NodeFeatures.md +0 -25
  229. package/docs/reference/variables/SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID.md +0 -3
  230. package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
@@ -0,0 +1,377 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
4
+ import { Coerce, GeneralError, I18n, Is, RandomHelper, StringHelper } from "@twin.org/core";
5
+ import { Bip39 } from "@twin.org/crypto";
6
+ import { IdentityConnectorType, WalletConnectorType } from "@twin.org/engine-types";
7
+ import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
8
+ import { Did, IdentityConnectorFactory, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
9
+ import { VaultConnectorFactory } from "@twin.org/vault-models";
10
+ import { WalletConnectorFactory } from "@twin.org/wallet-models";
11
+ import { nodeSetIdentity } from "./nodeSetIdentity.js";
12
+ import { applyOrganizationIdToTenant } from "./setTenantOrgId.js";
13
+ const COMMAND_NAME = "identity-create";
14
+ /**
15
+ * Get the command definition parameters.
16
+ * @param commandDefinitions The registered command definitions.
17
+ */
18
+ export function getCommandDefinitionIdentityCreate(commandDefinitions) {
19
+ commandDefinitions[COMMAND_NAME] = {
20
+ command: COMMAND_NAME,
21
+ description: I18n.formatMessage("node.cli.commands.identity-create.description"),
22
+ example: I18n.formatMessage("node.cli.commands.identity-create.example"),
23
+ requiresNodeIdentity: false,
24
+ requiresOrgIdentity: false,
25
+ params: [
26
+ {
27
+ key: "env-prefix",
28
+ type: "string",
29
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.env-prefix.description"),
30
+ required: false
31
+ },
32
+ {
33
+ key: "mnemonic",
34
+ type: "string",
35
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.mnemonic.description"),
36
+ extendedType: "24 words",
37
+ required: false
38
+ },
39
+ {
40
+ key: "identity",
41
+ type: "string",
42
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.identity.description"),
43
+ extendedType: "did",
44
+ required: false
45
+ },
46
+ {
47
+ key: "controller",
48
+ type: "string",
49
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.controller.description"),
50
+ extendedType: "did",
51
+ required: false
52
+ },
53
+ {
54
+ key: "fund-wallet",
55
+ type: "boolean",
56
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.fund-wallet.description"),
57
+ required: false,
58
+ defaultValue: false
59
+ },
60
+ {
61
+ key: "load-env",
62
+ type: "string",
63
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.load-env.description"),
64
+ required: false
65
+ },
66
+ {
67
+ key: "output-json",
68
+ type: "string",
69
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.output-json.description"),
70
+ required: false
71
+ },
72
+ {
73
+ key: "output-env",
74
+ type: "string",
75
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.output-env.description"),
76
+ required: false
77
+ },
78
+ {
79
+ key: "output-env-prefix",
80
+ type: "string",
81
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.output-env-prefix.description"),
82
+ required: false
83
+ },
84
+ {
85
+ key: "node-id",
86
+ type: "boolean",
87
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.node-id.description"),
88
+ required: false,
89
+ defaultValue: false
90
+ },
91
+ {
92
+ key: "node-organization-id",
93
+ type: "boolean",
94
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.node-organization-id.description"),
95
+ required: false,
96
+ defaultValue: false
97
+ },
98
+ {
99
+ key: "tenant-organization-id",
100
+ type: "string",
101
+ extendedType: "hex(32)",
102
+ description: I18n.formatMessage("node.cli.commands.identity-create.params.tenant-organization-id.description"),
103
+ required: false
104
+ }
105
+ ],
106
+ action: async (engineCore, envVars, params) => identityCreate(engineCore, envVars, params)
107
+ };
108
+ }
109
+ /**
110
+ * Command for creating an identity.
111
+ * @param engineCore The engine core.
112
+ * @param envVars The environment variables for the node.
113
+ * @param params The parameters for the command.
114
+ * @param params.mnemonic The mnemonic to use for the identity.
115
+ * @param params.identity The DID of the identity to create.
116
+ * @param params.controller The controller DID for the identity.
117
+ * @param params.fundWallet Whether to fund the wallet associated with the identity from a faucet.
118
+ * @param params.nodeId If true, set the created DID as the node identity.
119
+ * @param params.nodeOrganizationId If true, set the created DID as the node organization ID.
120
+ * @param params.tenantOrganizationId The tenant ID to set the created DID as the organization ID for.
121
+ * @param params.outputJson The output .json file to store the command output.
122
+ * @param params.outputEnv The output .env file to store the command output.
123
+ * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
124
+ * @returns The identity details.
125
+ */
126
+ export async function identityCreate(engineCore, envVars, params) {
127
+ const assignmentCount = (params.nodeId ? 1 : 0) +
128
+ (params.nodeOrganizationId ? 1 : 0) +
129
+ (Is.stringValue(params.tenantOrganizationId) ? 1 : 0);
130
+ if (assignmentCount > 1) {
131
+ throw new GeneralError("identityCreate", "onlyOneAssignmentOptionAllowed");
132
+ }
133
+ let workingIdentity = params?.identity;
134
+ let tempIdentity;
135
+ if (!Is.stringValue(workingIdentity)) {
136
+ tempIdentity = `did:temp:${RandomHelper.generateUuidV7()}`;
137
+ workingIdentity = tempIdentity;
138
+ }
139
+ let mnemonicStored = false;
140
+ const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
141
+ const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
142
+ try {
143
+ const mnemonicResult = await mnemonicCreate(vaultConnector, workingIdentity, params.mnemonic);
144
+ mnemonicStored = mnemonicResult.stored;
145
+ const fundWallet = params.fundWallet ?? false;
146
+ let walletAddress;
147
+ if (fundWallet) {
148
+ walletAddress = await generateWallet(engineCore, workingIdentity, Coerce.integer(envVars.identityWalletAddressIndex) ?? 0);
149
+ }
150
+ const workingController = params?.controller ?? workingIdentity;
151
+ workingIdentity = await identityGenerate(engineCore, workingController, workingIdentity);
152
+ if (Is.stringValue(tempIdentity)) {
153
+ // If we were using a temporary identity store the mnemonic using
154
+ // the final identity
155
+ await mnemonicFinalise(vaultConnector, tempIdentity, workingIdentity);
156
+ await walletFinalise(engineCore, workingIdentity, walletAddress);
157
+ }
158
+ if (params.nodeId) {
159
+ await nodeSetIdentity(engineCore, envVars, { identity: workingIdentity });
160
+ }
161
+ if (params.nodeOrganizationId) {
162
+ if (Coerce.boolean(envVars.tenantEnabled)) {
163
+ throw new GeneralError("identityCreate", "nodeOrganizationIdNotAvailableInMultiTenantMode");
164
+ }
165
+ const state = engineCore.getState();
166
+ state.nodeOrganizationId = workingIdentity;
167
+ engineCore.setStateDirty();
168
+ }
169
+ if (Is.stringValue(params.tenantOrganizationId)) {
170
+ await applyOrganizationIdToTenant(engineCore, params.tenantOrganizationId, workingIdentity);
171
+ }
172
+ if (mnemonicStored) {
173
+ CLIDisplay.break();
174
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.mnemonic"), mnemonicResult.mnemonic);
175
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.did"), workingIdentity);
176
+ }
177
+ if (Is.stringValue(envVars.iotaExplorerEndpoint) &&
178
+ envVars.identityConnector === IdentityConnectorType.Iota) {
179
+ const idParts = Did.parse(workingIdentity);
180
+ if (Is.stringValue(walletAddress)) {
181
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.walletAddress"), `${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/address/${walletAddress}?network=${idParts.network ?? envVars.iotaNetwork}`);
182
+ }
183
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.explorer"), `${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/object/${idParts.id}?network=${idParts.network ?? envVars.iotaNetwork}`);
184
+ }
185
+ CLIDisplay.break();
186
+ const json = { mnemonic: mnemonicResult.mnemonic, did: workingIdentity, walletAddress };
187
+ if (Is.stringValue(params.outputJson)) {
188
+ await CLIUtils.writeJsonFile(params.outputJson, { mnemonic: mnemonicResult.mnemonic, did: workingIdentity, walletAddress }, false);
189
+ }
190
+ if (Is.stringValue(params.outputEnv)) {
191
+ const output = [
192
+ `${params.outputEnvPrefix}MNEMONIC="${mnemonicResult.mnemonic}"`,
193
+ `${params.outputEnvPrefix}DID="${workingIdentity}"`
194
+ ];
195
+ if (Is.stringValue(walletAddress)) {
196
+ output.push(`${params.outputEnvPrefix}WALLET_ADDRESS="${walletAddress}"`);
197
+ }
198
+ await CLIUtils.writeEnvFile(params.outputEnv, output, false);
199
+ }
200
+ CLIDisplay.done();
201
+ return json;
202
+ }
203
+ finally {
204
+ // Always remove temporary identity mnemonic if created
205
+ if (Is.stringValue(tempIdentity) && mnemonicStored) {
206
+ await mnemonicRemove(vaultConnector, tempIdentity);
207
+ }
208
+ }
209
+ }
210
+ /**
211
+ * Handle the mnemonic generation or retrieval.
212
+ * @param vaultConnector The vault connector.
213
+ * @param identity The working identity.
214
+ * @param providedMnemonic The mnemonic provided by the user.
215
+ * @returns The mnemonic and the flag to determine if the mnemonic was stored.
216
+ */
217
+ async function mnemonicCreate(vaultConnector, identity, providedMnemonic) {
218
+ if (Is.stringValue(providedMnemonic) && !Bip39.validateMnemonic(providedMnemonic)) {
219
+ throw new GeneralError("identityCreate", "invalidMnemonic");
220
+ }
221
+ let mnemonic = providedMnemonic;
222
+ let storeMnemonic;
223
+ CLIDisplay.section(I18n.formatMessage("node.cli.commands.identity-create.labels.processingMnemonic"));
224
+ const mnemonicKey = `${identity}/mnemonic`;
225
+ try {
226
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.readingMnemonic"));
227
+ const storedMnemonic = await vaultConnector.getSecret(mnemonicKey);
228
+ if (Is.stringValue(storedMnemonic)) {
229
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.existingMnemonic"));
230
+ storeMnemonic = storedMnemonic !== mnemonic && !Is.empty(mnemonic);
231
+ mnemonic = storedMnemonic;
232
+ }
233
+ else {
234
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.noExistingMnemonic"));
235
+ storeMnemonic = true;
236
+ }
237
+ }
238
+ catch {
239
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.noExistingMnemonic"));
240
+ storeMnemonic = true;
241
+ }
242
+ // If there is no mnemonic then we need to generate one
243
+ if (Is.empty(mnemonic)) {
244
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.generatingMnemonic"));
245
+ mnemonic = Bip39.randomMnemonic();
246
+ storeMnemonic = true;
247
+ }
248
+ // If there is no mnemonic stored in the vault then we need to store it
249
+ if (storeMnemonic) {
250
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.storingMnemonic"));
251
+ await vaultConnector.setSecret(mnemonicKey, mnemonic);
252
+ }
253
+ CLIDisplay.break();
254
+ return {
255
+ stored: storeMnemonic,
256
+ mnemonic
257
+ };
258
+ }
259
+ /**
260
+ * Finalise the mnemonic for the node identity.
261
+ * @param vaultConnector The vault connector to use.
262
+ * @param tempIdentity The temporary identity used during creation.
263
+ * @param identity The final resolved identity.
264
+ * @returns A promise that resolves when the mnemonic has been migrated to the final identity key.
265
+ */
266
+ async function mnemonicFinalise(vaultConnector, tempIdentity, identity) {
267
+ // Now that we have an identity we can remove the temporary one
268
+ // and store the mnemonic with the new identity
269
+ if (tempIdentity !== identity) {
270
+ const mnemonic = await vaultConnector.getSecret(`${tempIdentity}/mnemonic`);
271
+ await vaultConnector.setSecret(`${identity}/mnemonic`, mnemonic);
272
+ try {
273
+ // not all accounts have account entries in the vault, so wrap this in a try catch
274
+ const accountChunk = await vaultConnector.getSecret(`${tempIdentity}/account/0/0/0`);
275
+ await vaultConnector.setSecret(`${identity}/account/0/0/0`, accountChunk);
276
+ }
277
+ catch { }
278
+ }
279
+ }
280
+ /**
281
+ * Remove the mnemonic and associated account secret for an identity.
282
+ * @param vaultConnector The vault connector.
283
+ * @param identity The working identity.
284
+ * @returns A promise that resolves when all vault secrets for the identity have been removed.
285
+ */
286
+ async function mnemonicRemove(vaultConnector, identity) {
287
+ try {
288
+ await vaultConnector.removeSecret(`${identity}/mnemonic`);
289
+ }
290
+ catch { }
291
+ try {
292
+ await vaultConnector.removeSecret(`${identity}/account/0/0/0`);
293
+ }
294
+ catch { }
295
+ }
296
+ /**
297
+ * Resolve or create a DID identity document.
298
+ * @param engineCore The engine core for the node.
299
+ * @param controller The controller DID for the new document.
300
+ * @param providedIdentity An existing DID to resolve; if absent or not found a new one is created.
301
+ * @returns The DID string for the resolved or newly created identity.
302
+ */
303
+ async function identityGenerate(engineCore, controller, providedIdentity) {
304
+ CLIDisplay.section(I18n.formatMessage("node.cli.commands.identity-create.labels.processingIdentity"));
305
+ const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
306
+ const identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);
307
+ let identityDocument;
308
+ try {
309
+ if (Is.stringValue(providedIdentity)) {
310
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.resolvingIdentity"));
311
+ const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
312
+ const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
313
+ identityDocument = await identityResolverConnector.resolveDocument(providedIdentity);
314
+ if (Is.objectValue(identityDocument)) {
315
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.existingIdentity"));
316
+ }
317
+ }
318
+ }
319
+ catch { }
320
+ if (Is.empty(identityDocument)) {
321
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.noIdentityFound"));
322
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.creatingIdentity"));
323
+ CLIDisplay.spinnerStart();
324
+ identityDocument = await identityConnector.createDocument(controller);
325
+ CLIDisplay.spinnerStop();
326
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.createdIdentity"));
327
+ }
328
+ return identityDocument.id;
329
+ }
330
+ /**
331
+ * Generate and fund a wallet address for the given identity.
332
+ * @param engineCore The engine core for the node.
333
+ * @param identity The identity to create the wallet for.
334
+ * @param walletAddressIndex The index of the wallet address to use.
335
+ * @returns The primary wallet address for the identity.
336
+ */
337
+ async function generateWallet(engineCore, identity, walletAddressIndex) {
338
+ CLIDisplay.section(I18n.formatMessage("node.cli.commands.identity-create.labels.fundingWallet"));
339
+ CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.addressIndex"), walletAddressIndex.toString());
340
+ const defaultWalletConnectorType = engineCore.getRegisteredInstanceType("walletConnector");
341
+ const walletConnector = WalletConnectorFactory.get(defaultWalletConnectorType);
342
+ const addresses = await walletConnector.getAddresses(identity, 0, walletAddressIndex, 5);
343
+ if (defaultWalletConnectorType.startsWith(WalletConnectorType.Iota)) {
344
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.addingTokens", {
345
+ address: addresses[0]
346
+ }));
347
+ CLIDisplay.break();
348
+ CLIDisplay.spinnerStart();
349
+ // Add some funds to the wallet from the faucet
350
+ await walletConnector.ensureBalance(identity, addresses[0], 1000000000n);
351
+ CLIDisplay.spinnerStop();
352
+ }
353
+ return addresses[0];
354
+ }
355
+ /**
356
+ * Correct the identity association on a wallet address after the final DID is known.
357
+ * @param engineCore The engine core for the node.
358
+ * @param identity The final resolved identity.
359
+ * @param address The wallet address to update.
360
+ * @returns A promise that resolves when the wallet address identity has been updated.
361
+ */
362
+ async function walletFinalise(engineCore, identity, address) {
363
+ if (Is.stringValue(address)) {
364
+ const defaultWalletConnectorType = engineCore.getRegisteredInstanceType("walletConnector");
365
+ // If we are using entity storage for wallet the identity associated with the
366
+ // address will be wrong, so fix it
367
+ if (defaultWalletConnectorType.startsWith(WalletConnectorType.EntityStorage)) {
368
+ const walletAddress = EntityStorageConnectorFactory.get("wallet-address");
369
+ const addr = await walletAddress.get(address);
370
+ if (!Is.empty(addr)) {
371
+ addr.identity = identity;
372
+ await walletAddress.set(addr);
373
+ }
374
+ }
375
+ }
376
+ }
377
+ //# sourceMappingURL=identityCreate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityCreate.js","sourceRoot":"","sources":["../../../src/commands/identityCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACN,GAAG,EACH,wBAAwB,EACxB,gCAAgC,EAChC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAwB,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAErF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAMlE,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,kBAElD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,+CAA+C,CAAC;QAChF,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,2CAA2C,CAAC;QACxE,oBAAoB,EAAE,KAAK;QAC3B,mBAAmB,EAAE,KAAK;QAC1B,MAAM,EAAE;YACP;gBACC,GAAG,E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AAM,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC/B,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { Coerce, GeneralError, I18n, Is, RandomHelper, StringHelper } from \"@twin.org/core\";\nimport { Bip39 } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { IdentityConnectorType, WalletConnectorType } from \"@twin.org/engine-types\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport {\n\tDid,\n\tIdentityConnectorFactory,\n\tIdentityResolverConnectorFactory\n} from \"@twin.org/identity-models\";\nimport { nameofKebabCase } from \"@twin.org/nameof\";\nimport { type IVaultConnector, VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport type { WalletAddress } from \"@twin.org/wallet-connector-entity-storage\";\nimport { WalletConnectorFactory } from \"@twin.org/wallet-models\";\nimport { nodeSetIdentity } from \"./nodeSetIdentity.js\";\nimport { applyOrganizationIdToTenant } from \"./setTenantOrgId.js\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\n\nconst COMMAND_NAME = \"identity-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityCreate(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.identity-create.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: 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-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: \"mnemonic\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-create.params.mnemonic.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"24 words\",\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-create.params.identity.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: \"controller\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-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: \"fund-wallet\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-create.params.fund-wallet.description\"\n\t\t\t\t),\n\t\t\t\trequired: false,\n\t\t\t\tdefaultValue: 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-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-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-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-create.params.output-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: \"node-id\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-create.params.node-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: false,\n\t\t\t\tdefaultValue: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"node-organization-id\",\n\t\t\t\ttype: \"boolean\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-create.params.node-organization-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: false,\n\t\t\t\tdefaultValue: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"tenant-organization-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.identity-create.params.tenant-organization-id.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) => identityCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating an 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.mnemonic The mnemonic to use for the identity.\n * @param params.identity The DID of the identity to create.\n * @param params.controller The controller DID for the identity.\n * @param params.fundWallet Whether to fund the wallet associated with the identity from a faucet.\n * @param params.nodeId If true, set the created DID as the node identity.\n * @param params.nodeOrganizationId If true, set the created DID as the node organization ID.\n * @param params.tenantOrganizationId The tenant ID to set the created DID as the organization ID for.\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 identity details.\n */\nexport async function identityCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\tmnemonic?: string;\n\t\tidentity?: string;\n\t\tcontroller?: string;\n\t\tfundWallet?: boolean;\n\t\tnodeId?: boolean;\n\t\tnodeOrganizationId?: boolean;\n\t\ttenantOrganizationId?: string;\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<{ mnemonic: string; did: string; walletAddress?: string }> {\n\tconst assignmentCount =\n\t\t(params.nodeId ? 1 : 0) +\n\t\t(params.nodeOrganizationId ? 1 : 0) +\n\t\t(Is.stringValue(params.tenantOrganizationId) ? 1 : 0);\n\tif (assignmentCount > 1) {\n\t\tthrow new GeneralError(\"identityCreate\", \"onlyOneAssignmentOptionAllowed\");\n\t}\n\n\tlet workingIdentity = params?.identity;\n\tlet tempIdentity;\n\tif (!Is.stringValue(workingIdentity)) {\n\t\ttempIdentity = `did:temp:${RandomHelper.generateUuidV7()}`;\n\t\tworkingIdentity = tempIdentity;\n\t}\n\tlet mnemonicStored = false;\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\ttry {\n\t\tconst mnemonicResult = await mnemonicCreate(vaultConnector, workingIdentity, params.mnemonic);\n\t\tmnemonicStored = mnemonicResult.stored;\n\n\t\tconst fundWallet = params.fundWallet ?? false;\n\t\tlet walletAddress;\n\t\tif (fundWallet) {\n\t\t\twalletAddress = await generateWallet(\n\t\t\t\tengineCore,\n\t\t\t\tworkingIdentity,\n\t\t\t\tCoerce.integer(envVars.identityWalletAddressIndex) ?? 0\n\t\t\t);\n\t\t}\n\n\t\tconst workingController = params?.controller ?? workingIdentity;\n\t\tworkingIdentity = await identityGenerate(engineCore, workingController, workingIdentity);\n\n\t\tif (Is.stringValue(tempIdentity)) {\n\t\t\t// If we were using a temporary identity store the mnemonic using\n\t\t\t// the final identity\n\t\t\tawait mnemonicFinalise(vaultConnector, tempIdentity, workingIdentity);\n\n\t\t\tawait walletFinalise(engineCore, workingIdentity, walletAddress);\n\t\t}\n\n\t\tif (params.nodeId) {\n\t\t\tawait nodeSetIdentity(engineCore, envVars, { identity: workingIdentity });\n\t\t}\n\n\t\tif (params.nodeOrganizationId) {\n\t\t\tif (Coerce.boolean(envVars.tenantEnabled)) {\n\t\t\t\tthrow new GeneralError(\"identityCreate\", \"nodeOrganizationIdNotAvailableInMultiTenantMode\");\n\t\t\t}\n\t\t\tconst state = engineCore.getState();\n\t\t\tstate.nodeOrganizationId = workingIdentity;\n\t\t\tengineCore.setStateDirty();\n\t\t}\n\n\t\tif (Is.stringValue(params.tenantOrganizationId)) {\n\t\t\tawait applyOrganizationIdToTenant(engineCore, params.tenantOrganizationId, workingIdentity);\n\t\t}\n\n\t\tif (mnemonicStored) {\n\t\t\tCLIDisplay.break();\n\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.mnemonic\"),\n\t\t\t\tmnemonicResult.mnemonic\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.did\"),\n\t\t\t\tworkingIdentity\n\t\t\t);\n\t\t}\n\t\tif (\n\t\t\tIs.stringValue(envVars.iotaExplorerEndpoint) &&\n\t\t\tenvVars.identityConnector === IdentityConnectorType.Iota\n\t\t) {\n\t\t\tconst idParts = Did.parse(workingIdentity);\n\t\t\tif (Is.stringValue(walletAddress)) {\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.walletAddress\"),\n\t\t\t\t\t`${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/address/${walletAddress}?network=${idParts.network ?? envVars.iotaNetwork}`\n\t\t\t\t);\n\t\t\t}\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.explorer\"),\n\t\t\t\t`${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/object/${idParts.id}?network=${idParts.network ?? envVars.iotaNetwork}`\n\t\t\t);\n\t\t}\n\t\tCLIDisplay.break();\n\n\t\tconst json = { mnemonic: mnemonicResult.mnemonic, did: workingIdentity, walletAddress };\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(\n\t\t\t\tparams.outputJson,\n\t\t\t\t{ mnemonic: mnemonicResult.mnemonic, did: workingIdentity, walletAddress },\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst output = [\n\t\t\t\t`${params.outputEnvPrefix}MNEMONIC=\"${mnemonicResult.mnemonic}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID=\"${workingIdentity}\"`\n\t\t\t];\n\t\t\tif (Is.stringValue(walletAddress)) {\n\t\t\t\toutput.push(`${params.outputEnvPrefix}WALLET_ADDRESS=\"${walletAddress}\"`);\n\t\t\t}\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, output, false);\n\t\t}\n\n\t\tCLIDisplay.done();\n\n\t\treturn json;\n\t} finally {\n\t\t// Always remove temporary identity mnemonic if created\n\t\tif (Is.stringValue(tempIdentity) && mnemonicStored) {\n\t\t\tawait mnemonicRemove(vaultConnector, tempIdentity);\n\t\t}\n\t}\n}\n\n/**\n * Handle the mnemonic generation or retrieval.\n * @param vaultConnector The vault connector.\n * @param identity The working identity.\n * @param providedMnemonic The mnemonic provided by the user.\n * @returns The mnemonic and the flag to determine if the mnemonic was stored.\n */\nasync function mnemonicCreate(\n\tvaultConnector: IVaultConnector,\n\tidentity: string,\n\tprovidedMnemonic?: string\n): Promise<{\n\tstored: boolean;\n\tmnemonic: string;\n}> {\n\tif (Is.stringValue(providedMnemonic) && !Bip39.validateMnemonic(providedMnemonic)) {\n\t\tthrow new GeneralError(\"identityCreate\", \"invalidMnemonic\");\n\t}\n\tlet mnemonic = providedMnemonic;\n\tlet storeMnemonic;\n\n\tCLIDisplay.section(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.processingMnemonic\")\n\t);\n\n\tconst mnemonicKey = `${identity}/mnemonic`;\n\n\ttry {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.identity-create.labels.readingMnemonic\"));\n\t\tconst storedMnemonic = await vaultConnector.getSecret<string>(mnemonicKey);\n\t\tif (Is.stringValue(storedMnemonic)) {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.existingMnemonic\")\n\t\t\t);\n\t\t\tstoreMnemonic = storedMnemonic !== mnemonic && !Is.empty(mnemonic);\n\t\t\tmnemonic = storedMnemonic;\n\t\t} else {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.noExistingMnemonic\")\n\t\t\t);\n\t\t\tstoreMnemonic = true;\n\t\t}\n\t} catch {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.noExistingMnemonic\")\n\t\t);\n\t\tstoreMnemonic = true;\n\t}\n\n\t// If there is no mnemonic then we need to generate one\n\tif (Is.empty(mnemonic)) {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.generatingMnemonic\")\n\t\t);\n\t\tmnemonic = Bip39.randomMnemonic();\n\t\tstoreMnemonic = true;\n\t}\n\n\t// If there is no mnemonic stored in the vault then we need to store it\n\tif (storeMnemonic) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.identity-create.labels.storingMnemonic\"));\n\t\tawait vaultConnector.setSecret(mnemonicKey, mnemonic);\n\t}\n\tCLIDisplay.break();\n\n\treturn {\n\t\tstored: storeMnemonic,\n\t\tmnemonic\n\t};\n}\n\n/**\n * Finalise the mnemonic for the node identity.\n * @param vaultConnector The vault connector to use.\n * @param tempIdentity The temporary identity used during creation.\n * @param identity The final resolved identity.\n * @returns A promise that resolves when the mnemonic has been migrated to the final identity key.\n */\nasync function mnemonicFinalise(\n\tvaultConnector: IVaultConnector,\n\ttempIdentity: string,\n\tidentity: string\n): Promise<void> {\n\t// Now that we have an identity we can remove the temporary one\n\t// and store the mnemonic with the new identity\n\tif (tempIdentity !== identity) {\n\t\tconst mnemonic = await vaultConnector.getSecret(`${tempIdentity}/mnemonic`);\n\t\tawait vaultConnector.setSecret(`${identity}/mnemonic`, mnemonic);\n\n\t\ttry {\n\t\t\t// not all accounts have account entries in the vault, so wrap this in a try catch\n\t\t\tconst accountChunk = await vaultConnector.getSecret(`${tempIdentity}/account/0/0/0`);\n\t\t\tawait vaultConnector.setSecret(`${identity}/account/0/0/0`, accountChunk);\n\t\t} catch {}\n\t}\n}\n\n/**\n * Remove the mnemonic and associated account secret for an identity.\n * @param vaultConnector The vault connector.\n * @param identity The working identity.\n * @returns A promise that resolves when all vault secrets for the identity have been removed.\n */\nasync function mnemonicRemove(vaultConnector: IVaultConnector, identity: string): Promise<void> {\n\ttry {\n\t\tawait vaultConnector.removeSecret(`${identity}/mnemonic`);\n\t} catch {}\n\n\ttry {\n\t\tawait vaultConnector.removeSecret(`${identity}/account/0/0/0`);\n\t} catch {}\n}\n\n/**\n * Resolve or create a DID identity document.\n * @param engineCore The engine core for the node.\n * @param controller The controller DID for the new document.\n * @param providedIdentity An existing DID to resolve; if absent or not found a new one is created.\n * @returns The DID string for the resolved or newly created identity.\n */\nasync function identityGenerate(\n\tengineCore: IEngineCore,\n\tcontroller: string,\n\tprovidedIdentity?: string\n): Promise<string> {\n\tCLIDisplay.section(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.processingIdentity\")\n\t);\n\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tlet identityDocument;\n\n\ttry {\n\t\tif (Is.stringValue(providedIdentity)) {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.resolvingIdentity\")\n\t\t\t);\n\t\t\tconst defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\t\t\"identityResolverConnector\"\n\t\t\t);\n\n\t\t\tconst identityResolverConnector = IdentityResolverConnectorFactory.get(\n\t\t\t\tdefaultIdentityResolverConnectorType\n\t\t\t);\n\t\t\tidentityDocument = await identityResolverConnector.resolveDocument(providedIdentity);\n\t\t\tif (Is.objectValue(identityDocument)) {\n\t\t\t\tCLIDisplay.task(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.existingIdentity\")\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t} catch {}\n\n\tif (Is.empty(identityDocument)) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.identity-create.labels.noIdentityFound\"));\n\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.creatingIdentity\")\n\t\t);\n\n\t\tCLIDisplay.spinnerStart();\n\t\tidentityDocument = await identityConnector.createDocument(controller);\n\t\tCLIDisplay.spinnerStop();\n\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.identity-create.labels.createdIdentity\"));\n\t}\n\n\treturn identityDocument.id;\n}\n\n/**\n * Generate and fund a wallet address for the given identity.\n * @param engineCore The engine core for the node.\n * @param identity The identity to create the wallet for.\n * @param walletAddressIndex The index of the wallet address to use.\n * @returns The primary wallet address for the identity.\n */\nasync function generateWallet(\n\tengineCore: IEngineCore,\n\tidentity: string,\n\twalletAddressIndex: number\n): Promise<string> {\n\tCLIDisplay.section(I18n.formatMessage(\"node.cli.commands.identity-create.labels.fundingWallet\"));\n\tCLIDisplay.value(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.addressIndex\"),\n\t\twalletAddressIndex.toString()\n\t);\n\n\tconst defaultWalletConnectorType = engineCore.getRegisteredInstanceType(\"walletConnector\");\n\n\tconst walletConnector = WalletConnectorFactory.get(defaultWalletConnectorType);\n\tconst addresses = await walletConnector.getAddresses(identity, 0, walletAddressIndex, 5);\n\n\tif (defaultWalletConnectorType.startsWith(WalletConnectorType.Iota)) {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.addingTokens\", {\n\t\t\t\taddress: addresses[0]\n\t\t\t})\n\t\t);\n\t\tCLIDisplay.break();\n\n\t\tCLIDisplay.spinnerStart();\n\n\t\t// Add some funds to the wallet from the faucet\n\t\tawait walletConnector.ensureBalance(identity, addresses[0], 1000000000n);\n\n\t\tCLIDisplay.spinnerStop();\n\t}\n\n\treturn addresses[0];\n}\n\n/**\n * Correct the identity association on a wallet address after the final DID is known.\n * @param engineCore The engine core for the node.\n * @param identity The final resolved identity.\n * @param address The wallet address to update.\n * @returns A promise that resolves when the wallet address identity has been updated.\n */\nasync function walletFinalise(\n\tengineCore: IEngineCore,\n\tidentity: string,\n\taddress?: string\n): Promise<void> {\n\tif (Is.stringValue(address)) {\n\t\tconst defaultWalletConnectorType = engineCore.getRegisteredInstanceType(\"walletConnector\");\n\n\t\t// If we are using entity storage for wallet the identity associated with the\n\t\t// address will be wrong, so fix it\n\t\tif (defaultWalletConnectorType.startsWith(WalletConnectorType.EntityStorage)) {\n\t\t\tconst walletAddress =\n\t\t\t\tEntityStorageConnectorFactory.get<IEntityStorageConnector<WalletAddress>>(\n\t\t\t\t\tnameofKebabCase<WalletAddress>()\n\t\t\t\t);\n\t\t\tconst addr = await walletAddress.get(address);\n\t\t\tif (!Is.empty(addr)) {\n\t\t\t\taddr.identity = identity;\n\t\t\t\tawait walletAddress.set(addr);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -0,0 +1,83 @@
1
+ // Copyright 2026 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ import { CLIDisplay } from "@twin.org/cli-core";
4
+ import { GeneralError, Guards, I18n, Is } from "@twin.org/core";
5
+ import { Bip39 } from "@twin.org/crypto";
6
+ import { Did, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
7
+ import { VaultConnectorFactory } from "@twin.org/vault-models";
8
+ const COMMAND_NAME = "identity-import";
9
+ /**
10
+ * Get the command definition parameters.
11
+ * @param commandDefinitions The registered command definitions.
12
+ */
13
+ export function getCommandDefinitionIdentityImport(commandDefinitions) {
14
+ commandDefinitions[COMMAND_NAME] = {
15
+ command: COMMAND_NAME,
16
+ description: I18n.formatMessage("node.cli.commands.identity-import.description"),
17
+ example: I18n.formatMessage("node.cli.commands.identity-import.example"),
18
+ requiresNodeIdentity: false,
19
+ requiresOrgIdentity: false,
20
+ params: [
21
+ {
22
+ key: "env-prefix",
23
+ type: "string",
24
+ description: I18n.formatMessage("node.cli.commands.identity-import.params.env-prefix.description"),
25
+ required: false
26
+ },
27
+ {
28
+ key: "identity",
29
+ type: "string",
30
+ description: I18n.formatMessage("node.cli.commands.identity-import.params.identity.description"),
31
+ extendedType: "did",
32
+ required: true
33
+ },
34
+ {
35
+ key: "mnemonic",
36
+ type: "string",
37
+ description: I18n.formatMessage("node.cli.commands.identity-import.params.mnemonic.description"),
38
+ extendedType: "24 words",
39
+ required: true
40
+ },
41
+ {
42
+ key: "load-env",
43
+ type: "string",
44
+ description: I18n.formatMessage("node.cli.commands.identity-import.params.load-env.description"),
45
+ required: false
46
+ }
47
+ ],
48
+ action: async (engineCore, envVars, params) => identityImport(engineCore, envVars, params)
49
+ };
50
+ }
51
+ /**
52
+ * Command for importing an identity.
53
+ * @param engineCore The engine core.
54
+ * @param envVars The environment variables for the node.
55
+ * @param params The parameters for the command.
56
+ * @param params.identity The DID of the identity to import.
57
+ * @param params.mnemonic The mnemonic to use for the identity.
58
+ * @returns A promise that resolves when the identity mnemonic has been stored in the vault.
59
+ */
60
+ export async function identityImport(engineCore, envVars, params) {
61
+ Did.guard("identityImport", "identity", params.identity);
62
+ Guards.stringValue("identityImport", "mnemonic", params.mnemonic);
63
+ if (!Bip39.validateMnemonic(params.mnemonic)) {
64
+ throw new GeneralError("identityImport", "invalidMnemonic");
65
+ }
66
+ const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
67
+ const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
68
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-import.labels.resolvingIdentity"));
69
+ const identityDocument = await identityResolverConnector.resolveDocument(params.identity);
70
+ if (Is.empty(identityDocument)) {
71
+ throw new GeneralError("identityImport", "identityNotFound", {
72
+ identity: params.identity
73
+ });
74
+ }
75
+ const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
76
+ const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
77
+ CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-import.labels.storingMnemonic"));
78
+ const mnemonicKey = `${params.identity}/mnemonic`;
79
+ await vaultConnector.setSecret(mnemonicKey, params.mnemonic);
80
+ CLIDisplay.break();
81
+ CLIDisplay.done();
82
+ }
83
+ //# sourceMappingURL=identityImports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identityImports.js","sourceRoot":"","sources":["../../../src/commands/identityImports.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,E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,IAAI,CAAC,aAAa,CAAC,0DAA0D,CAAC,CAAC,CAAC;IAChG,MAAM,WAAW,GAAG,GAAG,MAAM,CAAC,QAAQ,WAAW,CAAC;IAClD,MAAM,cAAc,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE7D,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 { GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport { Bip39 } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did, IdentityResolverConnectorFactory } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\n\nconst COMMAND_NAME = \"identity-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityImport(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.identity-import.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-import.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresOrgIdentity: 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-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-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: \"mnemonic\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-import.params.mnemonic.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"24 words\",\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-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) => identityImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for importing an 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 of the identity to import.\n * @param params.mnemonic The mnemonic to use for the identity.\n * @returns A promise that resolves when the identity mnemonic has been stored in the vault.\n */\nexport async function identityImport(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tmnemonic?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"identityImport\", \"identity\", params.identity);\n\tGuards.stringValue(\"identityImport\", \"mnemonic\", params.mnemonic);\n\tif (!Bip39.validateMnemonic(params.mnemonic)) {\n\t\tthrow new GeneralError(\"identityImport\", \"invalidMnemonic\");\n\t}\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(I18n.formatMessage(\"node.cli.commands.identity-import.labels.resolvingIdentity\"));\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(I18n.formatMessage(\"node.cli.commands.identity-import.labels.storingMnemonic\"));\n\tconst mnemonicKey = `${params.identity}/mnemonic`;\n\tawait vaultConnector.setSecret(mnemonicKey, params.mnemonic);\n\n\tCLIDisplay.break();\n\tCLIDisplay.done();\n}\n"]}