@twin.org/node-core 0.9.4-next.5 → 0.9.4
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.
- package/dist/es/builders/engineEnvBuilder.js +369 -470
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +2 -5
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/builders/helper/envHelpers.js +0 -39
- package/dist/es/builders/helper/envHelpers.js.map +1 -1
- package/dist/es/cli.js +1 -1
- package/dist/es/cli.js.map +1 -1
- package/dist/es/commands/bootstrapDev.js +3 -3
- package/dist/es/commands/bootstrapDev.js.map +1 -1
- package/dist/es/commands/help.js +1 -1
- package/dist/es/commands/help.js.map +1 -1
- package/dist/es/commands/identityCreate.js +2 -2
- package/dist/es/commands/identityCreate.js.map +1 -1
- package/dist/es/commands/identityVerificationMethodCreate.js +2 -2
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -1
- package/dist/es/commands/userCreate.js +1 -1
- package/dist/es/commands/userCreate.js.map +1 -1
- package/dist/es/commands/vaultKeyCreate.js +1 -1
- package/dist/es/commands/vaultKeyCreate.js.map +1 -1
- package/dist/es/commands/vaultKeyImport.js +1 -1
- package/dist/es/commands/vaultKeyImport.js.map +1 -1
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
- package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
- package/dist/es/models/engineEnvironmentVariableKeys.js +3 -14
- package/dist/es/models/engineEnvironmentVariableKeys.js.map +1 -1
- package/dist/es/models/engineServerEnvironmentVariableKeys.js +0 -1
- package/dist/es/models/engineServerEnvironmentVariableKeys.js.map +1 -1
- package/dist/es/node.js +21 -40
- package/dist/es/node.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +0 -7
- package/dist/types/builders/helper/envHelpers.d.ts +0 -30
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +12 -48
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +0 -4
- package/docs/changelog.md +24 -180
- package/docs/reference/index.md +0 -1
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +21 -93
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +0 -8
- package/locales/en.json +1 -3
- package/package.json +34 -34
- package/dist/es/models/deprecatedEnvironmentVariableKeys.js +0 -16
- package/dist/es/models/deprecatedEnvironmentVariableKeys.js.map +0 -1
- package/dist/types/models/deprecatedEnvironmentVariableKeys.d.ts +0 -7
- package/docs/reference/functions/isMailboxEnabled.md +0 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../../src/commands/help.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAK1C,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,kBAExC;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,oCAAoC,CAAC;QACrE,OAAO,EAAE,EAAE;QACX,MAAM,EAAE,EAAE;QACV,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,CAC7C,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,kBAAkB,CAAC;QACtD,qBAAqB,EAAE,KAAK;KAC5B,CAAC;AACH,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI,CACzB,UAAuB,EACvB,OAA8B,EAC9B,MAA4B,EAC5B,kBAA2D;IAE3D,IAAI,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;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AAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAClE,CAAC;YAED,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAE5D,UAAU,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;YAE3C,UAAU,CAAC,KAAK,EAAE,CAAC;QACpB,CAAC;IACF,CAAC;IAED,IAAI,EAAE,CAAC,UAAU,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9C,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,uCAAuC,CAAC,EAC3D,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CACpC,CAAC;IACH,CAAC;IAED,IAAI,EAAE,CAAC,WAAW,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/C,UAAU,CAAC,KAAK,EAAE,CAAC;QACnB,UAAU,CAAC,KAAK,CACf,IAAI,CAAC,aAAa,CAAC,uCAAuC,CAAC,EAC3D,iBAAiB,CAAC,OAAO,CACzB,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"help\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionHelp(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.help.description\"),\n\t\texample: \"\",\n\t\tparams: [],\n\t\taction: async (engineCore, envVars, params) =>\n\t\t\thelp(engineCore, envVars, params, commandDefinitions),\n\t\trequiresEngineStarted: false\n\t};\n}\n\n/**\n * Command for displaying help information.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The command parameters.\n * @param params.command The command to display help for.\n * @param commandDefinitions The registered command definitions.\n * @returns A promise that resolves when help output has been displayed.\n */\nexport async function help(\n\tengineCore: IEngineCore,\n\tenvVars: IEnvironmentVariables,\n\tparams: { command?: string },\n\tcommandDefinitions: { [id: string]: ICliCommandDefinition }\n): Promise<void> {\n\tif (Is.stringValue(params.command)) {\n\t\tconst commandDefinition = commandDefinitions[params.command];\n\t\tif (commandDefinition) {\n\t\t\tdisplayCommandHelp(commandDefinition);\n\t\t}\n\t} else {\n\t\tCLIDisplay.value(\"\", I18n.formatMessage(\"node.cli.commands.help.labels.commands\"));\n\t\tCLIDisplay.break();\n\n\t\tconst singleTenantOnlyLabel = I18n.formatMessage(\n\t\t\t\"node.cli.commands.help.labels.singleTenantOnly\"\n\t\t);\n\t\tfor (const commandId in commandDefinitions) {\n\t\t\tconst commandDef = commandDefinitions[commandId];\n\t\t\tif (commandId !== \"help\") {\n\t\t\t\tconst description = I18n.formatMessage(\n\t\t\t\t\t`node.cli.commands.${commandDef.command}.description`\n\t\t\t\t);\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tcommandDef.command,\n\t\t\t\t\tcommandDef.singleTenantOnly ? `${description} (${singleTenantOnlyLabel})` : description\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Display help for a specific command.\n * @param commandDefinition The command definition.\n */\nfunction displayCommandHelp(commandDefinition: ICliCommandDefinition): void {\n\tCLIDisplay.value(commandDefinition.command, commandDefinition.description);\n\tif (commandDefinition.singleTenantOnly) {\n\t\tCLIDisplay.value(\"\", I18n.formatMessage(\"node.cli.commands.help.labels.singleTenantOnly\"), 1);\n\t}\n\tCLIDisplay.break();\n\n\tconst defaultLabel = I18n.formatMessage(\"node.cli.commands.help.labels.default\");\n\tconst optionsLabel = I18n.formatMessage(\"node.cli.commands.help.labels.options\");\n\tconst requiredLabel = I18n.formatMessage(\"node.cli.commands.help.labels.required\");\n\tconst optionalLabel = I18n.formatMessage(\"node.cli.commands.help.labels.optional\");\n\n\tif (commandDefinition.params.length > 0) {\n\t\tfor (const param of commandDefinition.params) {\n\t\t\tconst typeParts: string[] = [param.type];\n\t\t\tif (Is.stringValue(param.extendedType)) {\n\t\t\t\ttypeParts.push(param.extendedType);\n\t\t\t}\n\t\t\tif (!Is.empty(param.defaultValue)) {\n\t\t\t\ttypeParts.push(`${defaultLabel}: '${param.defaultValue}'`);\n\t\t\t}\n\t\t\tif (param.required) {\n\t\t\t\ttypeParts.push(requiredLabel);\n\t\t\t} else {\n\t\t\t\ttypeParts.push(optionalLabel);\n\t\t\t}\n\n\t\t\tif (Is.arrayValue(param.options)) {\n\t\t\t\ttypeParts.push(`${optionsLabel}: [${param.options.join(\", \")}]`);\n\t\t\t}\n\n\t\t\tCLIDisplay.value(param.key, `(${typeParts.join(\", \")})`, 1);\n\n\t\t\tCLIDisplay.value(\"\", param.description, 1);\n\n\t\t\tCLIDisplay.break();\n\t\t}\n\t}\n\n\tif (Is.arrayValue(commandDefinition.aliases)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.help.labels.aliases\"),\n\t\t\tcommandDefinition.aliases.join(\", \")\n\t\t);\n\t}\n\n\tif (Is.stringValue(commandDefinition.example)) {\n\t\tCLIDisplay.break();\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.help.labels.example\"),\n\t\t\tcommandDefinition.example\n\t\t);\n\t}\n}\n"]}
|
|
@@ -228,7 +228,7 @@ async function mnemonicCreate(vaultConnector, identity, providedMnemonic) {
|
|
|
228
228
|
const storedMnemonic = await vaultConnector.getSecret(mnemonicKey);
|
|
229
229
|
if (Is.stringValue(storedMnemonic)) {
|
|
230
230
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.existingMnemonic"));
|
|
231
|
-
storeMnemonic = storedMnemonic !== mnemonic && Is.
|
|
231
|
+
storeMnemonic = storedMnemonic !== mnemonic && !Is.empty(mnemonic);
|
|
232
232
|
mnemonic = storedMnemonic;
|
|
233
233
|
}
|
|
234
234
|
else {
|
|
@@ -345,7 +345,7 @@ async function walletFinalise(engineCore, identity, address) {
|
|
|
345
345
|
if (defaultWalletConnectorType.startsWith(WalletConnectorType.EntityStorage)) {
|
|
346
346
|
const walletAddress = EntityStorageConnectorFactory.get("wallet-address");
|
|
347
347
|
const addr = await walletAddress.get(address);
|
|
348
|
-
if (Is.
|
|
348
|
+
if (!Is.empty(addr)) {
|
|
349
349
|
addr.identity = identity;
|
|
350
350
|
await walletAddress.set(addr);
|
|
351
351
|
}
|
|
@@ -1 +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;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,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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,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 { AccountHelper } from \"@twin.org/dlt-account\";\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 { nodeIdentitySet } from \"./nodeIdentitySet.js\";\nimport { applyOrganizationIdToTenant } from \"./tenantOrgIdSet.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 nodeIdentitySet(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 AccountHelper.removeAccountKeys(undefined, 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 = AccountHelper.buildMnemonicKey(identity);\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.notEmpty(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\tawait AccountHelper.renameAccountKeys(undefined, vaultConnector, tempIdentity, identity);\n\t}\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.notEmpty(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"]}
|
|
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,EA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mBAAmB,CAAC,aAAa,CAAC,EAAE,CAAC;YAC9E,MAAM,aAAa,GAClB,6BAA6B,CAAC,GAAG,kBAEhC,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC9C,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;gBACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBACzB,MAAM,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 { AccountHelper } from \"@twin.org/dlt-account\";\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 { nodeIdentitySet } from \"./nodeIdentitySet.js\";\nimport { applyOrganizationIdToTenant } from \"./tenantOrgIdSet.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 nodeIdentitySet(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 AccountHelper.removeAccountKeys(undefined, 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 = AccountHelper.buildMnemonicKey(identity);\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\tawait AccountHelper.renameAccountKeys(undefined, vaultConnector, tempIdentity, identity);\n\t}\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"]}
|
|
@@ -129,7 +129,7 @@ export async function identityVerificationMethodCreate(engineCore, envVars, para
|
|
|
129
129
|
verificationMethod = DocumentHelper.getVerificationMethod(identityDoc, DocumentHelper.joinId(params.identity, params.verificationMethodId), params.verificationMethodType);
|
|
130
130
|
}
|
|
131
131
|
catch { }
|
|
132
|
-
if (Is.
|
|
132
|
+
if (!Is.empty(verificationMethod)) {
|
|
133
133
|
if (params.overwriteMode === "error") {
|
|
134
134
|
throw new GeneralError("identityVerificationMethodCreate", "verificationMethodAlreadyExists");
|
|
135
135
|
}
|
|
@@ -160,7 +160,7 @@ export async function identityVerificationMethodCreate(engineCore, envVars, para
|
|
|
160
160
|
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verification-method-create.labels.createdVerificationMethod"));
|
|
161
161
|
}
|
|
162
162
|
let json;
|
|
163
|
-
if (Is.
|
|
163
|
+
if (!Is.empty(verificationMethod)) {
|
|
164
164
|
const keyParts = DocumentHelper.parseId(verificationMethod.id);
|
|
165
165
|
const keyPair = await vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);
|
|
166
166
|
Guards.uint8Array("identityVerificationMethodCreate", "privateKey", keyPair.privateKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identityVerificationMethodCreate.js","sourceRoot":"","sources":["../../../src/commands/identityVerificationMethodCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EACN,GAAG,EACH,cAAc,EACd,wBAAwB,EAExB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACx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AY,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport {\n\tDid,\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\ttype IIdentityResolverComponent\n} from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { type IJwk, Jwk } from \"@twin.org/web\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\n\nconst COMMAND_NAME = \"identity-verification-method-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\n\t\t\t\"node.cli.commands.identity-verification-method-create.description\"\n\t\t),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-verification-method-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\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-verification-method-create.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"controller\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.controller.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: Object.values(DidVerificationMethodType),\n\t\t\t\trequired: false,\n\t\t\t\tdefaultValue: \"assertionMethod\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-json.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) =>\n\t\t\tidentityVerificationMethodCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating an identity verification method.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID of the identity to create.\n * @param params.verificationMethodType The type of verification method to create.\n * @param params.verificationMethodId The ID of the verification method to create.\n * @param params.controller The controller DID for the identity.\n * @param params.overwriteMode The mode to use when a verification method with the same ID already exists.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created verification method details or undefined if skipped.\n */\nexport async function identityVerificationMethodCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tverificationMethodType?: DidVerificationMethodType;\n\t\tverificationMethodId?: string;\n\t\tcontroller?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tverificationMethodId: string;\n\t\t\tverificationMethodType: string;\n\t\t\tprivateKeyJwk: IJwk;\n\t\t\tprivateKeyHex: string;\n\t\t\tpublicKeyHex: string;\n\t\t\tprivateKeyBase64: string;\n\t\t\tpublicKeyBase64: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"identityVerificationMethodCreate\", \"identity\", params.identity);\n\tGuards.arrayOneOf(\n\t\t\"identityVerificationMethodCreate\",\n\t\t\"verificationMethodType\",\n\t\tparams.verificationMethodType,\n\t\tObject.values(DidVerificationMethodType)\n\t);\n\tGuards.arrayOneOf(\"identityVerificationMethodCreate\", \"overwrite-mode\", params.overwriteMode, [\n\t\t\"skip\",\n\t\t\"overwrite\",\n\t\t\"error\"\n\t]);\n\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tconst defaultIdentityResolverComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverComponent\"\n\t);\n\tconst identityResolverComponent = ComponentFactory.get<IIdentityResolverComponent>(\n\t\tdefaultIdentityResolverComponentType\n\t);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createMethod = true;\n\tlet verificationMethod;\n\n\t// We only need to perform the overwrite check if a verification method ID was provided\n\t// otherwise a new ID will be generated\n\tif (Is.stringValue(params.verificationMethodId)) {\n\t\tif (params.overwriteMode === \"skip\" || params.overwriteMode === \"error\") {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.resolvingIdentity\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst identityDoc = await identityResolverComponent.identityResolve(params.identity);\n\t\t\ttry {\n\t\t\t\tverificationMethod = DocumentHelper.getVerificationMethod(\n\t\t\t\t\tidentityDoc,\n\t\t\t\t\tDocumentHelper.joinId(params.identity, params.verificationMethodId),\n\t\t\t\t\tparams.verificationMethodType\n\t\t\t\t);\n\t\t\t} catch {}\n\n\t\t\tif (Is.notEmpty(verificationMethod)) {\n\t\t\t\tif (params.overwriteMode === \"error\") {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\t\"identityVerificationMethodCreate\",\n\t\t\t\t\t\t\"verificationMethodAlreadyExists\"\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Verify the vault key also exists before skipping.\n\t\t\t\t// The verification method may exist in the identity document while the\n\t\t\t\t// vault key is missing (e.g. database wipe, renameKey partial failure).\n\t\t\t\t// In that case we must NOT skip the addVerificationMethod will re-create\n\t\t\t\t// the vault key and update the method.\n\t\t\t\tlet vaultKeyExists = false;\n\t\t\t\ttry {\n\t\t\t\t\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\t\t\t\t\tawait vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);\n\t\t\t\t\tvaultKeyExists = true;\n\t\t\t\t} catch {}\n\n\t\t\t\tif (vaultKeyExists) {\n\t\t\t\t\tcreateMethod = false;\n\t\t\t\t\tCLIDisplay.task(\n\t\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.skipping\"\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (createMethod) {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.creatingVerificationMethod\"\n\t\t\t)\n\t\t);\n\t\tCLIDisplay.spinnerStart();\n\n\t\tverificationMethod = await identityConnector.addVerificationMethod(\n\t\t\tparams.controller ?? params.identity,\n\t\t\tparams.identity,\n\t\t\tparams.verificationMethodType as DidVerificationMethodType,\n\t\t\tparams.verificationMethodId\n\t\t);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.createdVerificationMethod\"\n\t\t\t)\n\t\t);\n\t}\n\n\tlet json;\n\n\tif (Is.notEmpty(verificationMethod)) {\n\t\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\t\tconst keyPair = await vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);\n\t\tGuards.uint8Array(\"identityVerificationMethodCreate\", \"privateKey\", keyPair.privateKey);\n\n\t\tconst privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);\n\t\tconst publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t\t: \"\";\n\t\tconst privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);\n\t\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64(keyPair.publicKey)\n\t\t\t: \"\";\n\n\t\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\t\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t\t: \"\";\n\n\t\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\t\tconst kid = await Jwk.generateKid(jwk);\n\n\t\tif (createMethod) {\n\t\t\tCLIDisplay.break();\n\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodId\"\n\t\t\t\t),\n\t\t\t\tverificationMethod.id\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodType\"\n\t\t\t\t),\n\t\t\t\tverificationMethod.type\n\t\t\t);\n\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-verification-method-create.labels.kid\"),\n\t\t\t\tkid\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64Url\"\n\t\t\t\t),\n\t\t\t\tprivateKeyBase64Url\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64Url\"\n\t\t\t\t),\n\t\t\t\tpublicKeyBase64Url\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64\"\n\t\t\t\t),\n\t\t\t\tprivateKeyBase64\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64\"\n\t\t\t\t),\n\t\t\t\tpublicKeyBase64\n\t\t\t);\n\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyHex\"\n\t\t\t\t),\n\t\t\t\tprivateKeyHex\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyHex\"\n\t\t\t\t),\n\t\t\t\tpublicKeyHex\n\t\t\t);\n\n\t\t\tCLIDisplay.break();\n\t\t}\n\n\t\tjson = {\n\t\t\tverificationMethodId: verificationMethod.id,\n\t\t\tverificationMethodType: verificationMethod.type,\n\t\t\tprivateKeyJwk: {\n\t\t\t\tkid,\n\t\t\t\t...jwk\n\t\t\t},\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64\n\t\t};\n\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst output = [\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_TYPE=\"${verificationMethod.type}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KID=\"${kid}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KTY=\"${jwk.kty}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_USE=\"${jwk.use}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_ALG=\"${jwk.alg}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_CRV=\"${jwk.crv}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_X=\"${jwk.x}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_D=\"${jwk.d}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX=\"${privateKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX=\"${publicKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`\n\t\t\t];\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, output, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"identityVerificationMethodCreate.js","sourceRoot":"","sources":["../../../src/commands/identityVerificationMethodCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE7F,OAAO,EACN,GAAG,EACH,cAAc,EACd,wBAAwB,EAExB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAa,GAAG,EAAE,MAAM,eAAe,CAAC;AAM/C,MAAM,YAAY,GAAG,qCAAqC,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,oDAAoD,CAAC,kBAEpE;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,mEAAmE,CACnE;QACD,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,+DAA+D,CAAC;QAC5F,oBAAoB,EAAE,KAAK;QAC3B,mBAAmB,EAAE,KAAK;QAC1B,MAAM,EAAE;YACP;gBACC,GAAG,EAAE,YAAY;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,qFAAqF,CACrF;gBACD,QAAQ,EAAE,KAAK;aACf;YACD;gBACC,GAAG,EAAE,UAAU;gBACf,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,IAAI,CAAC,aAAa,CAC9B,mFAAmF,CACnF;gBACD,Y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oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,oCAAoC,GAAG,CAAC,GAAG,GAAG;gBACvE,GAAG,MAAM,CAAC,eAAe,kCAAkC,GAAG,CAAC,CAAC,GAAG;gBACnE,GAAG,MAAM,CAAC,eAAe,kCAAkC,GAAG,CAAC,CAAC,GAAG;gBACnE,GAAG,MAAM,CAAC,eAAe,4CAA4C,aAAa,GAAG;gBACrF,GAAG,MAAM,CAAC,eAAe,2CAA2C,YAAY,GAAG;gBACnF,GAAG,MAAM,CAAC,eAAe,+CAA+C,gBAAgB,GAAG;gBAC3F,GAAG,MAAM,CAAC,eAAe,8CAA8C,eAAe,GAAG;aACzF,CAAC;YACF,MAAM,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;QAC9D,CAAC;IACF,CAAC;IAED,UAAU,CAAC,IAAI,EAAE,CAAC;IAElB,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ComponentFactory, Converter, GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport {\n\tDid,\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\ttype IIdentityResolverComponent\n} from \"@twin.org/identity-models\";\nimport { DidVerificationMethodType } from \"@twin.org/standards-w3c-did\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport { type IJwk, Jwk } from \"@twin.org/web\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\n\nconst COMMAND_NAME = \"identity-verification-method-create\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityVerificationMethodCreate(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\n\t\t\t\"node.cli.commands.identity-verification-method-create.description\"\n\t\t),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-verification-method-create.example\"),\n\t\trequiresNodeIdentity: false,\n\t\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-verification-method-create.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"controller\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.controller.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-type\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-type.description\"\n\t\t\t\t),\n\t\t\t\toptions: Object.values(DidVerificationMethodType),\n\t\t\t\trequired: false,\n\t\t\t\tdefaultValue: \"assertionMethod\"\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"verification-method-id\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.verification-method-id.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"overwrite-mode\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.overwrite-mode.description\"\n\t\t\t\t),\n\t\t\t\toptions: [\"skip\", \"overwrite\", \"error\"],\n\t\t\t\tdefaultValue: \"skip\",\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-json\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-json.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"output-env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.params.output-env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) =>\n\t\t\tidentityVerificationMethodCreate(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for creating an identity verification method.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID of the identity to create.\n * @param params.verificationMethodType The type of verification method to create.\n * @param params.verificationMethodId The ID of the verification method to create.\n * @param params.controller The controller DID for the identity.\n * @param params.overwriteMode The mode to use when a verification method with the same ID already exists.\n * @param params.outputJson The output .json file to store the command output.\n * @param params.outputEnv The output .env file to store the command output.\n * @param params.outputEnvPrefix The prefix to use for variables in the output .env file.\n * @returns The created verification method details or undefined if skipped.\n */\nexport async function identityVerificationMethodCreate(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: IEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tverificationMethodType?: DidVerificationMethodType;\n\t\tverificationMethodId?: string;\n\t\tcontroller?: string;\n\t\toverwriteMode?: \"skip\" | \"overwrite\" | \"error\";\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<\n\t| {\n\t\t\tverificationMethodId: string;\n\t\t\tverificationMethodType: string;\n\t\t\tprivateKeyJwk: IJwk;\n\t\t\tprivateKeyHex: string;\n\t\t\tpublicKeyHex: string;\n\t\t\tprivateKeyBase64: string;\n\t\t\tpublicKeyBase64: string;\n\t }\n\t| undefined\n> {\n\tDid.guard(\"identityVerificationMethodCreate\", \"identity\", params.identity);\n\tGuards.arrayOneOf(\n\t\t\"identityVerificationMethodCreate\",\n\t\t\"verificationMethodType\",\n\t\tparams.verificationMethodType,\n\t\tObject.values(DidVerificationMethodType)\n\t);\n\tGuards.arrayOneOf(\"identityVerificationMethodCreate\", \"overwrite-mode\", params.overwriteMode, [\n\t\t\"skip\",\n\t\t\"overwrite\",\n\t\t\"error\"\n\t]);\n\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tconst defaultIdentityResolverComponentType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverComponent\"\n\t);\n\tconst identityResolverComponent = ComponentFactory.get<IIdentityResolverComponent>(\n\t\tdefaultIdentityResolverComponentType\n\t);\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tlet createMethod = true;\n\tlet verificationMethod;\n\n\t// We only need to perform the overwrite check if a verification method ID was provided\n\t// otherwise a new ID will be generated\n\tif (Is.stringValue(params.verificationMethodId)) {\n\t\tif (params.overwriteMode === \"skip\" || params.overwriteMode === \"error\") {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.resolvingIdentity\"\n\t\t\t\t)\n\t\t\t);\n\n\t\t\tconst identityDoc = await identityResolverComponent.identityResolve(params.identity);\n\t\t\ttry {\n\t\t\t\tverificationMethod = DocumentHelper.getVerificationMethod(\n\t\t\t\t\tidentityDoc,\n\t\t\t\t\tDocumentHelper.joinId(params.identity, params.verificationMethodId),\n\t\t\t\t\tparams.verificationMethodType\n\t\t\t\t);\n\t\t\t} catch {}\n\n\t\t\tif (!Is.empty(verificationMethod)) {\n\t\t\t\tif (params.overwriteMode === \"error\") {\n\t\t\t\t\tthrow new GeneralError(\n\t\t\t\t\t\t\"identityVerificationMethodCreate\",\n\t\t\t\t\t\t\"verificationMethodAlreadyExists\"\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\t// Verify the vault key also exists before skipping.\n\t\t\t\t// The verification method may exist in the identity document while the\n\t\t\t\t// vault key is missing (e.g. database wipe, renameKey partial failure).\n\t\t\t\t// In that case we must NOT skip the addVerificationMethod will re-create\n\t\t\t\t// the vault key and update the method.\n\t\t\t\tlet vaultKeyExists = false;\n\t\t\t\ttry {\n\t\t\t\t\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\t\t\t\t\tawait vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);\n\t\t\t\t\tvaultKeyExists = true;\n\t\t\t\t} catch {}\n\n\t\t\t\tif (vaultKeyExists) {\n\t\t\t\t\tcreateMethod = false;\n\t\t\t\t\tCLIDisplay.task(\n\t\t\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.skipping\"\n\t\t\t\t\t\t)\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (createMethod) {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.creatingVerificationMethod\"\n\t\t\t)\n\t\t);\n\t\tCLIDisplay.spinnerStart();\n\n\t\tverificationMethod = await identityConnector.addVerificationMethod(\n\t\t\tparams.controller ?? params.identity,\n\t\t\tparams.identity,\n\t\t\tparams.verificationMethodType as DidVerificationMethodType,\n\t\t\tparams.verificationMethodId\n\t\t);\n\n\t\tCLIDisplay.spinnerStop();\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\n\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.createdVerificationMethod\"\n\t\t\t)\n\t\t);\n\t}\n\n\tlet json;\n\n\tif (!Is.empty(verificationMethod)) {\n\t\tconst keyParts = DocumentHelper.parseId(verificationMethod.id);\n\n\t\tconst keyPair = await vaultConnector.getKey(`${params.identity}/${keyParts.fragment}`);\n\t\tGuards.uint8Array(\"identityVerificationMethodCreate\", \"privateKey\", keyPair.privateKey);\n\n\t\tconst privateKeyBase64Url = Converter.bytesToBase64Url(keyPair.privateKey);\n\t\tconst publicKeyBase64Url = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64Url(keyPair.publicKey)\n\t\t\t: \"\";\n\t\tconst privateKeyBase64 = Converter.bytesToBase64(keyPair.privateKey);\n\t\tconst publicKeyBase64 = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToBase64(keyPair.publicKey)\n\t\t\t: \"\";\n\n\t\tconst privateKeyHex = Converter.bytesToHex(keyPair.privateKey, true);\n\t\tconst publicKeyHex = Is.uint8Array(keyPair.publicKey)\n\t\t\t? Converter.bytesToHex(keyPair.publicKey, true)\n\t\t\t: \"\";\n\n\t\tconst jwk = await Jwk.fromEd25519Private(keyPair.privateKey);\n\t\tconst kid = await Jwk.generateKid(jwk);\n\n\t\tif (createMethod) {\n\t\t\tCLIDisplay.break();\n\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodId\"\n\t\t\t\t),\n\t\t\t\tverificationMethod.id\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.verificationMethodType\"\n\t\t\t\t),\n\t\t\t\tverificationMethod.type\n\t\t\t);\n\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-verification-method-create.labels.kid\"),\n\t\t\t\tkid\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64Url\"\n\t\t\t\t),\n\t\t\t\tprivateKeyBase64Url\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64Url\"\n\t\t\t\t),\n\t\t\t\tpublicKeyBase64Url\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyBase64\"\n\t\t\t\t),\n\t\t\t\tprivateKeyBase64\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyBase64\"\n\t\t\t\t),\n\t\t\t\tpublicKeyBase64\n\t\t\t);\n\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.privateKeyHex\"\n\t\t\t\t),\n\t\t\t\tprivateKeyHex\n\t\t\t);\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-verification-method-create.labels.publicKeyHex\"\n\t\t\t\t),\n\t\t\t\tpublicKeyHex\n\t\t\t);\n\n\t\t\tCLIDisplay.break();\n\t\t}\n\n\t\tjson = {\n\t\t\tverificationMethodId: verificationMethod.id,\n\t\t\tverificationMethodType: verificationMethod.type,\n\t\t\tprivateKeyJwk: {\n\t\t\t\tkid,\n\t\t\t\t...jwk\n\t\t\t},\n\t\t\tprivateKeyHex,\n\t\t\tpublicKeyHex,\n\t\t\tprivateKeyBase64,\n\t\t\tpublicKeyBase64\n\t\t};\n\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(params.outputJson, json, false);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst output = [\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_ID=\"${verificationMethod.id}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_TYPE=\"${verificationMethod.type}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KID=\"${kid}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_KTY=\"${jwk.kty}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_USE=\"${jwk.use}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_ALG=\"${jwk.alg}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_CRV=\"${jwk.crv}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_X=\"${jwk.x}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_JWK_D=\"${jwk.d}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_HEX=\"${privateKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_HEX=\"${publicKeyHex}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PRIVATE_KEY_BASE64=\"${privateKeyBase64}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID_VERIFICATION_METHOD_PUBLIC_KEY_BASE64=\"${publicKeyBase64}\"`\n\t\t\t];\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, output, false);\n\t\t}\n\t}\n\n\tCLIDisplay.done();\n\n\treturn json;\n}\n"]}
|
|
@@ -152,7 +152,7 @@ export async function userCreate(engineCore, envVars, params) {
|
|
|
152
152
|
existingUser = await authenticationAdminComponent.get(paramsEmail);
|
|
153
153
|
}
|
|
154
154
|
catch { }
|
|
155
|
-
if (Is.
|
|
155
|
+
if (!Is.empty(existingUser)) {
|
|
156
156
|
if (params.overwriteMode === "error") {
|
|
157
157
|
throw new GeneralError("userCreate", "userAlreadyExists");
|
|
158
158
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"userCreate.js","sourceRoot":"","sources":["../../../src/commands/userCreate.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,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026 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 { ScopeHelper } from \"@twin.org/api-models\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, 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 { IEnvironmentVariables } from \"../models/IEnvironmentVariables.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: IEnvironmentVariables,\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 (Coerce.boolean(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.notEmpty(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: ScopeHelper.toArray(params.scope)\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{\n\t\t\t\t\t\t...currentContextIds,\n\t\t\t\t\t\t[ContextIdKeys.Tenant]: params.tenantId,\n\t\t\t\t\t\tscope: ScopeHelper.toString(user.scope)\n\t\t\t\t\t},\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: ScopeHelper.toArray(params.scope),\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"]}
|
|
1
|
+
{"version":3,"file":"userCreate.js","sourceRoot":"","s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AS,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 { ScopeHelper } from \"@twin.org/api-models\";\nimport { CLIDisplay, CLIUtils } from \"@twin.org/cli-core\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, 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 { IEnvironmentVariables } from \"../models/IEnvironmentVariables.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: IEnvironmentVariables,\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 (Coerce.boolean(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: ScopeHelper.toArray(params.scope)\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{\n\t\t\t\t\t\t...currentContextIds,\n\t\t\t\t\t\t[ContextIdKeys.Tenant]: params.tenantId,\n\t\t\t\t\t\tscope: ScopeHelper.toString(user.scope)\n\t\t\t\t\t},\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: ScopeHelper.toArray(params.scope),\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"]}
|
|
@@ -111,7 +111,7 @@ export async function vaultKeyCreate(engineCore, envVars, params) {
|
|
|
111
111
|
existingKey = await vaultConnector.getKey(fullKeyId);
|
|
112
112
|
}
|
|
113
113
|
catch { }
|
|
114
|
-
if (Is.
|
|
114
|
+
if (!Is.empty(existingKey)) {
|
|
115
115
|
if (params.overwriteMode === "error") {
|
|
116
116
|
throw new GeneralError("vaultKeyCreate", "vaultKeyAlreadyExists");
|
|
117
117
|
}
|
|
@@ -1 +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,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,GAAG,MAAM,CAAC,eAAe,oBAAoB,aAAa,GAAG,CAAC,CAAC;YAClF,CAAC;YACD,IAAI,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 { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.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\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.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: IEnvironmentVariables,\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.notEmpty(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"]}
|
|
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,G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WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC;gBACtC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,uBAAuB,gBAAgB,GAAG,CAAC,CAAC;YACxF,CAAC;YAED,IAAI,EAAE,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC;gBACrC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,sBAAsB,eAAe,GAAG,CAAC,CAAC;YACtF,CAAC;YACD,IAAI,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC;gBACnC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,eAAe,oBAAoB,aAAa,GAAG,CAAC,CAAC;YAClF,CAAC;YACD,IAAI,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 { IEnvironmentVariables } from \"../models/IEnvironmentVariables.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.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\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.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: IEnvironmentVariables,\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"]}
|
|
@@ -87,7 +87,7 @@ export async function vaultKeyImport(engineCore, envVars, params) {
|
|
|
87
87
|
let existingKey;
|
|
88
88
|
try {
|
|
89
89
|
existingKey = await vaultConnector.getKey(fullKeyId);
|
|
90
|
-
if (Is.
|
|
90
|
+
if (!Is.empty(existingKey)) {
|
|
91
91
|
await vaultConnector.removeKey(fullKeyId);
|
|
92
92
|
}
|
|
93
93
|
}
|