@twin.org/node-core 0.0.3-next.2 → 0.0.3-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/builders/engineEnvBuilder.js +168 -105
- package/dist/es/builders/engineEnvBuilder.js.map +1 -1
- package/dist/es/builders/engineServerEnvBuilder.js +49 -25
- package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
- package/dist/es/cli.js +247 -0
- package/dist/es/cli.js.map +1 -0
- package/dist/es/commands/bootstrapLegacy.js +183 -0
- package/dist/es/commands/bootstrapLegacy.js.map +1 -0
- package/dist/es/commands/help.js +85 -0
- package/dist/es/commands/help.js.map +1 -0
- package/dist/es/commands/identityCreate.js +316 -0
- package/dist/es/commands/identityCreate.js.map +1 -0
- package/dist/es/commands/identityImports.js +82 -0
- package/dist/es/commands/identityImports.js.map +1 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js +146 -0
- package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodCreate.js +214 -0
- package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
- package/dist/es/commands/identityVerificationMethodImport.js +126 -0
- package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
- package/dist/es/commands/nodeSetIdentity.js +64 -0
- package/dist/es/commands/nodeSetIdentity.js.map +1 -0
- package/dist/es/commands/nodeSetTenant.js +68 -0
- package/dist/es/commands/nodeSetTenant.js.map +1 -0
- package/dist/es/commands/tenantCreate.js +139 -0
- package/dist/es/commands/tenantCreate.js.map +1 -0
- package/dist/es/commands/tenantImport.js +97 -0
- package/dist/es/commands/tenantImport.js.map +1 -0
- package/dist/es/commands/tenantUpdate.js +94 -0
- package/dist/es/commands/tenantUpdate.js.map +1 -0
- package/dist/es/commands/userCreate.js +212 -0
- package/dist/es/commands/userCreate.js.map +1 -0
- package/dist/es/commands/userUpdate.js +132 -0
- package/dist/es/commands/userUpdate.js.map +1 -0
- package/dist/es/commands/vaultKeyCreate.js +191 -0
- package/dist/es/commands/vaultKeyCreate.js.map +1 -0
- package/dist/es/commands/vaultKeyImport.js +104 -0
- package/dist/es/commands/vaultKeyImport.js.map +1 -0
- package/dist/es/defaults.js +19 -1
- package/dist/es/defaults.js.map +1 -1
- package/dist/es/index.js +7 -3
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ICliArgs.js +4 -0
- package/dist/es/models/ICliArgs.js.map +1 -0
- package/dist/es/models/ICliCommand.js +2 -0
- package/dist/es/models/ICliCommand.js.map +1 -0
- package/dist/es/models/ICliCommandDefinition.js +2 -0
- package/dist/es/models/ICliCommandDefinition.js.map +1 -0
- package/dist/es/models/ICliCommandDefinitionParam.js +2 -0
- package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -0
- package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
- package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
- package/dist/es/models/INodeEngineState.js.map +1 -1
- package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
- package/dist/es/models/INodeOptions.js.map +1 -1
- package/dist/es/models/cliCommandParamType.js +4 -0
- package/dist/es/models/cliCommandParamType.js.map +1 -0
- package/dist/es/node.js +78 -41
- package/dist/es/node.js.map +1 -1
- package/dist/es/start.js +139 -0
- package/dist/es/start.js.map +1 -0
- package/dist/es/utils.js +11 -21
- package/dist/es/utils.js.map +1 -1
- package/dist/types/builders/engineEnvBuilder.d.ts +4 -1
- package/dist/types/builders/engineServerEnvBuilder.d.ts +5 -2
- package/dist/types/cli.d.ts +56 -0
- package/dist/types/commands/bootstrapLegacy.d.ts +66 -0
- package/dist/types/commands/help.d.ts +23 -0
- package/dist/types/commands/identityCreate.d.ts +39 -0
- package/dist/types/commands/identityImports.d.ts +24 -0
- package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
- package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
- package/dist/types/commands/identityVerificationMethodImport.d.ts +31 -0
- package/dist/types/commands/nodeSetIdentity.d.ts +22 -0
- package/dist/types/commands/nodeSetTenant.d.ts +22 -0
- package/dist/types/commands/tenantCreate.d.ts +38 -0
- package/dist/types/commands/tenantImport.d.ts +26 -0
- package/dist/types/commands/tenantUpdate.d.ts +26 -0
- package/dist/types/commands/userCreate.d.ts +49 -0
- package/dist/types/commands/userUpdate.d.ts +38 -0
- package/dist/types/commands/vaultKeyCreate.d.ts +43 -0
- package/dist/types/commands/vaultKeyImport.d.ts +28 -0
- package/dist/types/defaults.d.ts +11 -1
- package/dist/types/index.d.ts +7 -3
- package/dist/types/models/ICliArgs.d.ts +20 -0
- package/dist/types/models/ICliCommand.d.ts +17 -0
- package/dist/types/models/ICliCommandDefinition.d.ts +46 -0
- package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
- package/dist/types/models/IEngineEnvironmentVariables.d.ts +62 -53
- package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +4 -0
- package/dist/types/models/INodeEngineState.d.ts +0 -8
- package/dist/types/models/INodeEnvironmentVariables.d.ts +0 -38
- package/dist/types/models/INodeOptions.d.ts +6 -2
- package/dist/types/models/cliCommandParamType.d.ts +4 -0
- package/dist/types/node.d.ts +8 -4
- package/dist/types/{server.d.ts → start.d.ts} +7 -2
- package/dist/types/utils.d.ts +6 -8
- package/docs/changelog.md +136 -0
- package/docs/reference/functions/buildConfiguration.md +3 -3
- package/docs/reference/functions/buildEngineConfiguration.md +1 -1
- package/docs/reference/functions/buildEngineServerConfiguration.md +3 -3
- package/docs/reference/functions/constructCliCommand.md +27 -0
- package/docs/reference/functions/executeCommand.md +29 -0
- package/docs/reference/functions/getEnvDefaults.md +19 -0
- package/docs/reference/functions/getScriptDirectory.md +19 -0
- package/docs/reference/functions/parseCommandLineArgs.md +19 -0
- package/docs/reference/functions/processEnvOptions.md +27 -0
- package/docs/reference/functions/registerCommands.md +9 -0
- package/docs/reference/functions/run.md +8 -2
- package/docs/reference/functions/start.md +10 -4
- package/docs/reference/functions/substituteEnvOptions.md +25 -0
- package/docs/reference/index.md +16 -13
- package/docs/reference/interfaces/ICliArgs.md +35 -0
- package/docs/reference/interfaces/ICliCommand.md +23 -0
- package/docs/reference/interfaces/ICliCommandDefinition.md +101 -0
- package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
- package/docs/reference/interfaces/IEngineEnvironmentVariables.md +110 -85
- package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +166 -117
- package/docs/reference/interfaces/INodeEngineState.md +0 -16
- package/docs/reference/interfaces/INodeEnvironmentVariables.md +170 -201
- package/docs/reference/interfaces/INodeOptions.md +10 -2
- package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
- package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_DID.md +3 -0
- package/docs/reference/variables/CONTEXT_ID_HANDLER_FEATURE_TENANT.md +3 -0
- package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +3 -0
- package/locales/en.json +589 -30
- package/package.json +3 -1
- package/dist/es/bootstrap.js +0 -374
- package/dist/es/bootstrap.js.map +0 -1
- package/dist/es/identity.js +0 -169
- package/dist/es/identity.js.map +0 -1
- package/dist/es/models/nodeFeatures.js +0 -21
- package/dist/es/models/nodeFeatures.js.map +0 -1
- package/dist/es/server.js +0 -78
- package/dist/es/server.js.map +0 -1
- package/dist/types/bootstrap.d.ts +0 -76
- package/dist/types/identity.d.ts +0 -14
- package/dist/types/models/nodeFeatures.d.ts +0 -21
- package/docs/reference/functions/bootstrap.md +0 -29
- package/docs/reference/functions/bootstrapAuth.md +0 -35
- package/docs/reference/functions/bootstrapBlobEncryption.md +0 -35
- package/docs/reference/functions/bootstrapContextIdHandlers.md +0 -35
- package/docs/reference/functions/bootstrapImmutableProofMethod.md +0 -35
- package/docs/reference/functions/bootstrapNodeAdminUser.md +0 -35
- package/docs/reference/functions/bootstrapNodeId.md +0 -35
- package/docs/reference/functions/bootstrapSynchronisedStorage.md +0 -35
- package/docs/reference/functions/bootstrapTenantId.md +0 -35
- package/docs/reference/functions/getFeatures.md +0 -19
- package/docs/reference/type-aliases/NodeFeatures.md +0 -5
- package/docs/reference/variables/NodeFeatures.md +0 -25
- package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
4
|
+
import { Coerce, GeneralError, I18n, Is, RandomHelper, StringHelper } from "@twin.org/core";
|
|
5
|
+
import { Bip39 } from "@twin.org/crypto";
|
|
6
|
+
import { WalletConnectorType } from "@twin.org/engine-types";
|
|
7
|
+
import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
|
|
8
|
+
import { Did, IdentityConnectorFactory, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
|
|
9
|
+
import { VaultConnectorFactory } from "@twin.org/vault-models";
|
|
10
|
+
import { WalletConnectorFactory } from "@twin.org/wallet-models";
|
|
11
|
+
const COMMAND_NAME = "identity-create";
|
|
12
|
+
/**
|
|
13
|
+
* Get the command definition parameters.
|
|
14
|
+
* @param commandDefinitions The registered command definitions.
|
|
15
|
+
*/
|
|
16
|
+
export function getCommandDefinitionIdentityCreate(commandDefinitions) {
|
|
17
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
18
|
+
command: COMMAND_NAME,
|
|
19
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.description"),
|
|
20
|
+
example: I18n.formatMessage("node.cli.commands.identity-create.example"),
|
|
21
|
+
requiresNodeIdentity: false,
|
|
22
|
+
requiresTenantId: false,
|
|
23
|
+
params: [
|
|
24
|
+
{
|
|
25
|
+
key: "env-prefix",
|
|
26
|
+
type: "string",
|
|
27
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.env-prefix.description"),
|
|
28
|
+
required: false
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
key: "mnemonic",
|
|
32
|
+
type: "string",
|
|
33
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.mnemonic.description"),
|
|
34
|
+
extendedType: "24 words",
|
|
35
|
+
required: false
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "identity",
|
|
39
|
+
type: "string",
|
|
40
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.identity.description"),
|
|
41
|
+
extendedType: "did",
|
|
42
|
+
required: false
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "controller",
|
|
46
|
+
type: "string",
|
|
47
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.controller.description"),
|
|
48
|
+
extendedType: "did",
|
|
49
|
+
required: false
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "fund-wallet",
|
|
53
|
+
type: "boolean",
|
|
54
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.fund-wallet.description"),
|
|
55
|
+
required: false,
|
|
56
|
+
defaultValue: false
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "load-env",
|
|
60
|
+
type: "string",
|
|
61
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.load-env.description"),
|
|
62
|
+
required: false
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: "output-json",
|
|
66
|
+
type: "string",
|
|
67
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.output-json.description"),
|
|
68
|
+
required: false
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
key: "output-env",
|
|
72
|
+
type: "string",
|
|
73
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.output-env.description"),
|
|
74
|
+
required: false
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
key: "output-env-prefix",
|
|
78
|
+
type: "string",
|
|
79
|
+
description: I18n.formatMessage("node.cli.commands.identity-create.params.output-env-prefix.description"),
|
|
80
|
+
required: false
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
action: async (engineCore, envVars, params) => identityCreate(engineCore, envVars, params)
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Command for creating an identity.
|
|
88
|
+
* @param engineCore The engine core.
|
|
89
|
+
* @param envVars The environment variables for the node.
|
|
90
|
+
* @param params The parameters for the command.
|
|
91
|
+
* @param params.mnemonic The mnemonic to use for the identity.
|
|
92
|
+
* @param params.identity The DID of the identity to create.
|
|
93
|
+
* @param params.controller The controller DID for the identity.
|
|
94
|
+
* @param params.fundWallet Whether to fund the wallet associated with the identity from a faucet.
|
|
95
|
+
* @param params.outputJson The output .json file to store the command output.
|
|
96
|
+
* @param params.outputEnv The output .env file to store the command output.
|
|
97
|
+
* @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
|
|
98
|
+
* @returns The identity details.
|
|
99
|
+
*/
|
|
100
|
+
export async function identityCreate(engineCore, envVars, params) {
|
|
101
|
+
let workingIdentity = params?.identity;
|
|
102
|
+
let tempIdentity;
|
|
103
|
+
if (!Is.stringValue(workingIdentity)) {
|
|
104
|
+
tempIdentity = `did:temp:${RandomHelper.generateUuidV7()}`;
|
|
105
|
+
workingIdentity = tempIdentity;
|
|
106
|
+
}
|
|
107
|
+
let mnemonicStored = false;
|
|
108
|
+
const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
|
|
109
|
+
const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
|
|
110
|
+
try {
|
|
111
|
+
const mnemonicResult = await mnemonicCreate(vaultConnector, workingIdentity, params.mnemonic);
|
|
112
|
+
mnemonicStored = mnemonicResult.stored;
|
|
113
|
+
const fundWallet = params.fundWallet ?? false;
|
|
114
|
+
let walletAddress;
|
|
115
|
+
if (fundWallet) {
|
|
116
|
+
walletAddress = await generateWallet(engineCore, workingIdentity, Coerce.integer(envVars.identityWalletAddressIndex) ?? 0);
|
|
117
|
+
}
|
|
118
|
+
const workingController = params?.controller ?? workingIdentity;
|
|
119
|
+
workingIdentity = await identityGenerate(engineCore, workingController, workingIdentity);
|
|
120
|
+
if (Is.stringValue(tempIdentity)) {
|
|
121
|
+
// If we were using a temporary identity store the mnemonic using
|
|
122
|
+
// the final identity
|
|
123
|
+
await mnemonicFinalise(vaultConnector, tempIdentity, workingIdentity);
|
|
124
|
+
await walletFinalise(engineCore, workingIdentity, walletAddress);
|
|
125
|
+
}
|
|
126
|
+
CLIDisplay.break();
|
|
127
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.mnemonic"), mnemonicResult.mnemonic);
|
|
128
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.did"), workingIdentity);
|
|
129
|
+
if (Is.stringValue(envVars.iotaExplorerEndpoint)) {
|
|
130
|
+
const idParts = Did.parse(workingIdentity);
|
|
131
|
+
if (Is.stringValue(walletAddress)) {
|
|
132
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.walletAddress"), `${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/address/${walletAddress}?network=${idParts.network ?? envVars.iotaNetwork}`);
|
|
133
|
+
}
|
|
134
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.explorer"), `${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/object/${idParts.id}?network=${idParts.network ?? envVars.iotaNetwork}`);
|
|
135
|
+
}
|
|
136
|
+
CLIDisplay.break();
|
|
137
|
+
const json = { mnemonic: mnemonicResult.mnemonic, did: workingIdentity, walletAddress };
|
|
138
|
+
if (Is.stringValue(params.outputJson)) {
|
|
139
|
+
await CLIUtils.writeJsonFile(params.outputJson, { mnemonic: mnemonicResult.mnemonic, did: workingIdentity, walletAddress }, false);
|
|
140
|
+
}
|
|
141
|
+
if (Is.stringValue(params.outputEnv)) {
|
|
142
|
+
const output = [
|
|
143
|
+
`${params.outputEnvPrefix}MNEMONIC="${mnemonicResult.mnemonic}"`,
|
|
144
|
+
`${params.outputEnvPrefix}DID="${workingIdentity}"`
|
|
145
|
+
];
|
|
146
|
+
if (Is.stringValue(walletAddress)) {
|
|
147
|
+
output.push(`${params.outputEnvPrefix}WALLET_ADDRESS="${walletAddress}"`);
|
|
148
|
+
}
|
|
149
|
+
await CLIUtils.writeEnvFile(params.outputEnv, output, false);
|
|
150
|
+
}
|
|
151
|
+
CLIDisplay.done();
|
|
152
|
+
return json;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
// Always remove temporary identity mnemonic if created
|
|
156
|
+
if (Is.stringValue(tempIdentity) && mnemonicStored) {
|
|
157
|
+
await mnemonicRemove(vaultConnector, tempIdentity);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Handle the mnemonic generation or retrieval.
|
|
163
|
+
* @param vaultConnector The vault connector.
|
|
164
|
+
* @param identity The working identity.
|
|
165
|
+
* @param providedMnemonic The mnemonic provided by the user.
|
|
166
|
+
* @returns The mnemonic and the flag to determine if the mnemonic was stored.
|
|
167
|
+
*/
|
|
168
|
+
async function mnemonicCreate(vaultConnector, identity, providedMnemonic) {
|
|
169
|
+
if (Is.stringValue(providedMnemonic) && !Bip39.validateMnemonic(providedMnemonic)) {
|
|
170
|
+
throw new GeneralError("identityCreate", "invalidMnemonic");
|
|
171
|
+
}
|
|
172
|
+
let mnemonic = providedMnemonic;
|
|
173
|
+
let storeMnemonic = false;
|
|
174
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.identity-create.labels.processingMnemonic"));
|
|
175
|
+
const mnemonicKey = `${identity}/mnemonic`;
|
|
176
|
+
try {
|
|
177
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.readingMnemonic"));
|
|
178
|
+
const storedMnemonic = await vaultConnector.getSecret(mnemonicKey);
|
|
179
|
+
if (Is.stringValue(storedMnemonic)) {
|
|
180
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.existingMnemonic"));
|
|
181
|
+
storeMnemonic = storedMnemonic !== mnemonic && !Is.empty(mnemonic);
|
|
182
|
+
mnemonic = storedMnemonic;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.noExistingMnemonic"));
|
|
186
|
+
storeMnemonic = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.noExistingMnemonic"));
|
|
191
|
+
storeMnemonic = true;
|
|
192
|
+
}
|
|
193
|
+
// If there is no mnemonic then we need to generate one
|
|
194
|
+
if (Is.empty(mnemonic)) {
|
|
195
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.generatingMnemonic"));
|
|
196
|
+
mnemonic = Bip39.randomMnemonic();
|
|
197
|
+
storeMnemonic = true;
|
|
198
|
+
}
|
|
199
|
+
// If there is no mnemonic stored in the vault then we need to store it
|
|
200
|
+
if (storeMnemonic) {
|
|
201
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.storingMnemonic"));
|
|
202
|
+
await vaultConnector.setSecret(mnemonicKey, mnemonic);
|
|
203
|
+
}
|
|
204
|
+
CLIDisplay.break();
|
|
205
|
+
return {
|
|
206
|
+
stored: storeMnemonic,
|
|
207
|
+
mnemonic
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Finalise the mnemonic for the node identity.
|
|
212
|
+
* @param vaultConnector The vault connector to use.
|
|
213
|
+
* @param tempIdentity The identity of the node.
|
|
214
|
+
* @param identity The final identity for the node.
|
|
215
|
+
*/
|
|
216
|
+
async function mnemonicFinalise(vaultConnector, tempIdentity, identity) {
|
|
217
|
+
// Now that we have an identity we can remove the temporary one
|
|
218
|
+
// and store the mnemonic with the new identity
|
|
219
|
+
if (tempIdentity !== identity) {
|
|
220
|
+
const mnemonic = await vaultConnector.getSecret(`${tempIdentity}/mnemonic`);
|
|
221
|
+
await vaultConnector.setSecret(`${identity}/mnemonic`, mnemonic);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Remove the mnemonic.
|
|
226
|
+
* @param vaultConnector The vault connector.
|
|
227
|
+
* @param identity The working identity.
|
|
228
|
+
* @returns Nothing.
|
|
229
|
+
*/
|
|
230
|
+
async function mnemonicRemove(vaultConnector, identity) {
|
|
231
|
+
try {
|
|
232
|
+
await vaultConnector.removeSecret(`${identity}/mnemonic`);
|
|
233
|
+
}
|
|
234
|
+
catch { }
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Generate an identity.
|
|
238
|
+
* @param engineCore The engine core for the node.
|
|
239
|
+
* @param controller The controller for the identity.
|
|
240
|
+
* @param providedIdentity The existing identity if there is one.
|
|
241
|
+
* @returns The addresses for the wallet.
|
|
242
|
+
*/
|
|
243
|
+
async function identityGenerate(engineCore, controller, providedIdentity) {
|
|
244
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.identity-create.labels.processingIdentity"));
|
|
245
|
+
const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
|
|
246
|
+
const identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);
|
|
247
|
+
let identityDocument;
|
|
248
|
+
try {
|
|
249
|
+
if (Is.stringValue(providedIdentity)) {
|
|
250
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.resolvingIdentity"));
|
|
251
|
+
const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
|
|
252
|
+
const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
|
|
253
|
+
identityDocument = await identityResolverConnector.resolveDocument(providedIdentity);
|
|
254
|
+
if (Is.objectValue(identityDocument)) {
|
|
255
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.existingIdentity"));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch { }
|
|
260
|
+
if (Is.empty(identityDocument)) {
|
|
261
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.noIdentityFound"));
|
|
262
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.creatingIdentity"));
|
|
263
|
+
CLIDisplay.spinnerStart();
|
|
264
|
+
identityDocument = await identityConnector.createDocument(controller);
|
|
265
|
+
CLIDisplay.spinnerStop();
|
|
266
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.createdIdentity"));
|
|
267
|
+
}
|
|
268
|
+
return identityDocument.id;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Bootstrap the wallet for the node.
|
|
272
|
+
* @param engineCore The engine core for the node.
|
|
273
|
+
* @param identity The identity to create the wallet for.
|
|
274
|
+
* @param walletAddressIndex The index of the wallet address to use.
|
|
275
|
+
* @returns The addresses for the wallet.
|
|
276
|
+
*/
|
|
277
|
+
async function generateWallet(engineCore, identity, walletAddressIndex) {
|
|
278
|
+
CLIDisplay.section(I18n.formatMessage("node.cli.commands.identity-create.labels.fundingWallet"));
|
|
279
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-create.labels.addressIndex"), walletAddressIndex.toString());
|
|
280
|
+
const defaultWalletConnectorType = engineCore.getRegisteredInstanceType("walletConnector");
|
|
281
|
+
const walletConnector = WalletConnectorFactory.get(defaultWalletConnectorType);
|
|
282
|
+
const addresses = await walletConnector.getAddresses(identity, 0, walletAddressIndex, 5);
|
|
283
|
+
if (defaultWalletConnectorType.startsWith(WalletConnectorType.Iota)) {
|
|
284
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-create.labels.addingTokens", {
|
|
285
|
+
address: addresses[0]
|
|
286
|
+
}));
|
|
287
|
+
CLIDisplay.break();
|
|
288
|
+
CLIDisplay.spinnerStart();
|
|
289
|
+
// Add some funds to the wallet from the faucet
|
|
290
|
+
await walletConnector.ensureBalance(identity, addresses[0], 1000000000n);
|
|
291
|
+
CLIDisplay.spinnerStop();
|
|
292
|
+
}
|
|
293
|
+
return addresses[0];
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Bootstrap the identity for the node.
|
|
297
|
+
* @param engineCore The engine core for the node.
|
|
298
|
+
* @param identity The identity of the node.
|
|
299
|
+
* @param address The address for the wallet.
|
|
300
|
+
*/
|
|
301
|
+
async function walletFinalise(engineCore, identity, address) {
|
|
302
|
+
if (Is.stringValue(address)) {
|
|
303
|
+
const defaultWalletConnectorType = engineCore.getRegisteredInstanceType("walletConnector");
|
|
304
|
+
// If we are using entity storage for wallet the identity associated with the
|
|
305
|
+
// address will be wrong, so fix it
|
|
306
|
+
if (defaultWalletConnectorType.startsWith(WalletConnectorType.EntityStorage)) {
|
|
307
|
+
const walletAddress = EntityStorageConnectorFactory.get("wallet-address");
|
|
308
|
+
const addr = await walletAddress.get(address);
|
|
309
|
+
if (!Is.empty(addr)) {
|
|
310
|
+
addr.identity = identity;
|
|
311
|
+
await walletAddress.set(addr);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=identityCreate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identityCreate.js","sourceRoot":"","sources":["../../../src/commands/identityCreate.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5F,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACN,6BAA6B,EAE7B,MAAM,i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,CAAC,uDAAuD,EAAE;YAC3E,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;SACrB,CAAC,CACF,CAAC;QACF,UAAU,CAAC,KAAK,EAAE,CAAC;QAEnB,UAAU,CAAC,YAAY,EAAE,CAAC;QAE1B,+CAA+C;QAC/C,MAAM,eAAe,CAAC,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;QAEzE,UAAU,CAAC,WAAW,EAAE,CAAC;IAC1B,CAAC;IAED,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,cAAc,CAC5B,UAAuB,EACvB,QAAgB,EAChB,OAAgB;IAEhB,IAAI,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,0BAA0B,GAAG,UAAU,CAAC,yBAAyB,CAAC,iBAAiB,CAAC,CAAC;QAE3F,6EAA6E;QAC7E,mCAAmC;QACnC,IAAI,0BAA0B,CAAC,UAAU,CAAC,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 type { IEngineCore } from \"@twin.org/engine-models\";\nimport { 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 type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"identity-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\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-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],\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.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: INodeEnvironmentVariables,\n\tparams: {\n\t\tmnemonic?: string;\n\t\tidentity?: string;\n\t\tcontroller?: string;\n\t\tfundWallet?: boolean;\n\t\toutputJson?: string;\n\t\toutputEnv?: string;\n\t\toutputEnvPrefix?: string;\n\t}\n): Promise<{ mnemonic: string; did: string; walletAddress?: string }> {\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\tCLIDisplay.break();\n\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.mnemonic\"),\n\t\t\tmnemonicResult.mnemonic\n\t\t);\n\t\tCLIDisplay.value(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.did\"),\n\t\t\tworkingIdentity\n\t\t);\n\t\tif (Is.stringValue(envVars.iotaExplorerEndpoint)) {\n\t\t\tconst idParts = Did.parse(workingIdentity);\n\t\t\tif (Is.stringValue(walletAddress)) {\n\t\t\t\tCLIDisplay.value(\n\t\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.walletAddress\"),\n\t\t\t\t\t`${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/address/${walletAddress}?network=${idParts.network ?? envVars.iotaNetwork}`\n\t\t\t\t);\n\t\t\t}\n\t\t\tCLIDisplay.value(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.explorer\"),\n\t\t\t\t`${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/object/${idParts.id}?network=${idParts.network ?? envVars.iotaNetwork}`\n\t\t\t);\n\t\t}\n\t\tCLIDisplay.break();\n\n\t\tconst json = { mnemonic: mnemonicResult.mnemonic, did: workingIdentity, walletAddress };\n\t\tif (Is.stringValue(params.outputJson)) {\n\t\t\tawait CLIUtils.writeJsonFile(\n\t\t\t\tparams.outputJson,\n\t\t\t\t{ mnemonic: mnemonicResult.mnemonic, did: workingIdentity, walletAddress },\n\t\t\t\tfalse\n\t\t\t);\n\t\t}\n\n\t\tif (Is.stringValue(params.outputEnv)) {\n\t\t\tconst output = [\n\t\t\t\t`${params.outputEnvPrefix}MNEMONIC=\"${mnemonicResult.mnemonic}\"`,\n\t\t\t\t`${params.outputEnvPrefix}DID=\"${workingIdentity}\"`\n\t\t\t];\n\t\t\tif (Is.stringValue(walletAddress)) {\n\t\t\t\toutput.push(`${params.outputEnvPrefix}WALLET_ADDRESS=\"${walletAddress}\"`);\n\t\t\t}\n\t\t\tawait CLIUtils.writeEnvFile(params.outputEnv, output, false);\n\t\t}\n\n\t\tCLIDisplay.done();\n\n\t\treturn json;\n\t} finally {\n\t\t// Always remove temporary identity mnemonic if created\n\t\tif (Is.stringValue(tempIdentity) && mnemonicStored) {\n\t\t\tawait mnemonicRemove(vaultConnector, tempIdentity);\n\t\t}\n\t}\n}\n\n/**\n * Handle the mnemonic generation or retrieval.\n * @param vaultConnector The vault connector.\n * @param identity The working identity.\n * @param providedMnemonic The mnemonic provided by the user.\n * @returns The mnemonic and the flag to determine if the mnemonic was stored.\n */\nasync function mnemonicCreate(\n\tvaultConnector: IVaultConnector,\n\tidentity: string,\n\tprovidedMnemonic?: string\n): Promise<{\n\tstored: boolean;\n\tmnemonic: string;\n}> {\n\tif (Is.stringValue(providedMnemonic) && !Bip39.validateMnemonic(providedMnemonic)) {\n\t\tthrow new GeneralError(\"identityCreate\", \"invalidMnemonic\");\n\t}\n\tlet mnemonic = providedMnemonic;\n\tlet storeMnemonic = false;\n\n\tCLIDisplay.section(\n\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.processingMnemonic\")\n\t);\n\n\tconst mnemonicKey = `${identity}/mnemonic`;\n\n\ttry {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.identity-create.labels.readingMnemonic\"));\n\t\tconst storedMnemonic = await vaultConnector.getSecret<string>(mnemonicKey);\n\t\tif (Is.stringValue(storedMnemonic)) {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.existingMnemonic\")\n\t\t\t);\n\t\t\tstoreMnemonic = storedMnemonic !== mnemonic && !Is.empty(mnemonic);\n\t\t\tmnemonic = storedMnemonic;\n\t\t} else {\n\t\t\tCLIDisplay.task(\n\t\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.noExistingMnemonic\")\n\t\t\t);\n\t\t\tstoreMnemonic = true;\n\t\t}\n\t} catch {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.noExistingMnemonic\")\n\t\t);\n\t\tstoreMnemonic = true;\n\t}\n\n\t// If there is no mnemonic then we need to generate one\n\tif (Is.empty(mnemonic)) {\n\t\tCLIDisplay.task(\n\t\t\tI18n.formatMessage(\"node.cli.commands.identity-create.labels.generatingMnemonic\")\n\t\t);\n\t\tmnemonic = Bip39.randomMnemonic();\n\t\tstoreMnemonic = true;\n\t}\n\n\t// If there is no mnemonic stored in the vault then we need to store it\n\tif (storeMnemonic) {\n\t\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.identity-create.labels.storingMnemonic\"));\n\t\tawait vaultConnector.setSecret(mnemonicKey, mnemonic);\n\t}\n\tCLIDisplay.break();\n\n\treturn {\n\t\tstored: storeMnemonic,\n\t\tmnemonic\n\t};\n}\n\n/**\n * Finalise the mnemonic for the node identity.\n * @param vaultConnector The vault connector to use.\n * @param tempIdentity The identity of the node.\n * @param identity The final identity for the node.\n */\nasync function mnemonicFinalise(\n\tvaultConnector: IVaultConnector,\n\ttempIdentity: string,\n\tidentity: string\n): Promise<void> {\n\t// Now that we have an identity we can remove the temporary one\n\t// and store the mnemonic with the new identity\n\tif (tempIdentity !== identity) {\n\t\tconst mnemonic = await vaultConnector.getSecret(`${tempIdentity}/mnemonic`);\n\t\tawait vaultConnector.setSecret(`${identity}/mnemonic`, mnemonic);\n\t}\n}\n\n/**\n * Remove the mnemonic.\n * @param vaultConnector The vault connector.\n * @param identity The working identity.\n * @returns Nothing.\n */\nasync function mnemonicRemove(vaultConnector: IVaultConnector, identity: string): Promise<void> {\n\ttry {\n\t\tawait vaultConnector.removeSecret(`${identity}/mnemonic`);\n\t} catch {}\n}\n\n/**\n * Generate an identity.\n * @param engineCore The engine core for the node.\n * @param controller The controller for the identity.\n * @param providedIdentity The existing identity if there is one.\n * @returns The addresses for the wallet.\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 * Bootstrap the wallet for the node.\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 addresses for the wallet.\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 * Bootstrap the identity for the node.\n * @param engineCore The engine core for the node.\n * @param identity The identity of the node.\n * @param address The address for the wallet.\n */\nasync function walletFinalise(\n\tengineCore: IEngineCore,\n\tidentity: string,\n\taddress?: string\n): Promise<void> {\n\tif (Is.stringValue(address)) {\n\t\tconst defaultWalletConnectorType = engineCore.getRegisteredInstanceType(\"walletConnector\");\n\n\t\t// If we are using entity storage for wallet the identity associated with the\n\t\t// address will be wrong, so fix it\n\t\tif (defaultWalletConnectorType.startsWith(WalletConnectorType.EntityStorage)) {\n\t\t\tconst walletAddress =\n\t\t\t\tEntityStorageConnectorFactory.get<IEntityStorageConnector<WalletAddress>>(\n\t\t\t\t\tnameofKebabCase<WalletAddress>()\n\t\t\t\t);\n\t\t\tconst addr = await walletAddress.get(address);\n\t\t\tif (!Is.empty(addr)) {\n\t\t\t\taddr.identity = identity;\n\t\t\t\tawait walletAddress.set(addr);\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { CLIDisplay } from "@twin.org/cli-core";
|
|
4
|
+
import { GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
5
|
+
import { Bip39 } from "@twin.org/crypto";
|
|
6
|
+
import { Did, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
|
|
7
|
+
import { VaultConnectorFactory } from "@twin.org/vault-models";
|
|
8
|
+
const COMMAND_NAME = "identity-import";
|
|
9
|
+
/**
|
|
10
|
+
* Get the command definition parameters.
|
|
11
|
+
* @param commandDefinitions The registered command definitions.
|
|
12
|
+
*/
|
|
13
|
+
export function getCommandDefinitionIdentityImport(commandDefinitions) {
|
|
14
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
15
|
+
command: COMMAND_NAME,
|
|
16
|
+
description: I18n.formatMessage("node.cli.commands.identity-import.description"),
|
|
17
|
+
example: I18n.formatMessage("node.cli.commands.identity-import.example"),
|
|
18
|
+
requiresNodeIdentity: false,
|
|
19
|
+
requiresTenantId: false,
|
|
20
|
+
params: [
|
|
21
|
+
{
|
|
22
|
+
key: "env-prefix",
|
|
23
|
+
type: "string",
|
|
24
|
+
description: I18n.formatMessage("node.cli.commands.identity-import.params.env-prefix.description"),
|
|
25
|
+
required: false
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: "identity",
|
|
29
|
+
type: "string",
|
|
30
|
+
description: I18n.formatMessage("node.cli.commands.identity-import.params.identity.description"),
|
|
31
|
+
extendedType: "did",
|
|
32
|
+
required: true
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
key: "mnemonic",
|
|
36
|
+
type: "string",
|
|
37
|
+
description: I18n.formatMessage("node.cli.commands.identity-import.params.mnemonic.description"),
|
|
38
|
+
extendedType: "24 words",
|
|
39
|
+
required: true
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: "load-env",
|
|
43
|
+
type: "string",
|
|
44
|
+
description: I18n.formatMessage("node.cli.commands.identity-import.params.load-env.description"),
|
|
45
|
+
required: false
|
|
46
|
+
}
|
|
47
|
+
],
|
|
48
|
+
action: async (engineCore, envVars, params) => identityImport(engineCore, envVars, params)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Command for importing an identity.
|
|
53
|
+
* @param engineCore The engine core.
|
|
54
|
+
* @param envVars The environment variables for the node.
|
|
55
|
+
* @param params The parameters for the command.
|
|
56
|
+
* @param params.identity The DID of the identity to import.
|
|
57
|
+
* @param params.mnemonic The mnemonic to use for the identity.
|
|
58
|
+
*/
|
|
59
|
+
export async function identityImport(engineCore, envVars, params) {
|
|
60
|
+
Did.guard("identityImport", "identity", params.identity);
|
|
61
|
+
Guards.stringValue("identityImport", "mnemonic", params.mnemonic);
|
|
62
|
+
if (!Bip39.validateMnemonic(params.mnemonic)) {
|
|
63
|
+
throw new GeneralError("identityImport", "invalidMnemonic");
|
|
64
|
+
}
|
|
65
|
+
const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
|
|
66
|
+
const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
|
|
67
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-import.labels.resolvingIdentity"));
|
|
68
|
+
const identityDocument = await identityResolverConnector.resolveDocument(params.identity);
|
|
69
|
+
if (Is.empty(identityDocument)) {
|
|
70
|
+
throw new GeneralError("identityImport", "identityNotFound", {
|
|
71
|
+
identity: params.identity
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
|
|
75
|
+
const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
|
|
76
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-import.labels.storingMnemonic"));
|
|
77
|
+
const mnemonicKey = `${params.identity}/mnemonic`;
|
|
78
|
+
await vaultConnector.setSecret(mnemonicKey, params.mnemonic);
|
|
79
|
+
CLIDisplay.break();
|
|
80
|
+
CLIDisplay.done();
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=identityImports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identityImports.js","sourceRoot":"","sources":["../../../src/commands/identityImports.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,GAAG,EAAE,gCAAgC,EAAE,MAAM,2BAA2B,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAM/D,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAEvC;;;GAGG;AACH,MAAM,UAAU,kCAAkC,CAAC,kBAElD;IACA,kBAAkB,CAAC,YAAY,CAAC,GAAG;QAClC,OAAO,EAAE,YAAY;QACrB,WAAW,EAAE,IAAI,CAAC,aAAa,CAAC,+CAA+C,CAAC;QAChF,OAAO,EAAE,IAAI,CAAC,aAAa,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IAAI,YAAY,CAAC,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,oCAAoC,GAAG,UAAU,CAAC,yBAAyB,CAChF,2BAA2B,CAC3B,CAAC;IAEF,MAAM,yBAAyB,GAAG,gCAAgC,CAAC,GAAG,CACrE,oCAAoC,CACpC,CAAC;IAEF,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,4DAA4D,CAAC,CAAC,CAAC;IAClG,MAAM,gBAAgB,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE1F,IAAI,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,YAAY,CAAC,gBAAgB,EAAE,kBAAkB,EAAE;YAC5D,QAAQ,EAAE,MAAM,CAAC,QAAQ;SACzB,CAAC,CAAC;IACJ,CAAC;IAED,MAAM,yBAAyB,GAAG,UAAU,CAAC,yBAAyB,CAAC,gBAAgB,CAAC,CAAC;IACzF,MAAM,cAAc,GAAG,qBAAqB,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAE5E,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,0DAA0D,CAAC,CAAC,CAAC;IAChG,MAAM,WAAW,GAAG,GAAG,MAAM,CAAC,QAAQ,WAAW,CAAC;IAClD,MAAM,cAAc,CAAC,SAAS,CAAC,WAAW,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;IAE7D,UAAU,CAAC,KAAK,EAAE,CAAC;IACnB,UAAU,CAAC,IAAI,EAAE,CAAC;AACnB,CAAC","sourcesContent":["// Copyright 2026 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { CLIDisplay } from \"@twin.org/cli-core\";\nimport { GeneralError, Guards, I18n, Is } from \"@twin.org/core\";\nimport { Bip39 } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { Did, IdentityResolverConnectorFactory } from \"@twin.org/identity-models\";\nimport { VaultConnectorFactory } from \"@twin.org/vault-models\";\nimport type { ICliCommandDefinition } from \"../models/ICliCommandDefinition.js\";\nimport type { INodeEngineConfig } from \"../models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"../models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"../models/INodeEnvironmentVariables.js\";\n\nconst COMMAND_NAME = \"identity-import\";\n\n/**\n * Get the command definition parameters.\n * @param commandDefinitions The registered command definitions.\n */\nexport function getCommandDefinitionIdentityImport(commandDefinitions: {\n\t[id: string]: ICliCommandDefinition;\n}): void {\n\tcommandDefinitions[COMMAND_NAME] = {\n\t\tcommand: COMMAND_NAME,\n\t\tdescription: I18n.formatMessage(\"node.cli.commands.identity-import.description\"),\n\t\texample: I18n.formatMessage(\"node.cli.commands.identity-import.example\"),\n\t\trequiresNodeIdentity: false,\n\t\trequiresTenantId: false,\n\t\tparams: [\n\t\t\t{\n\t\t\t\tkey: \"env-prefix\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-import.params.env-prefix.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"identity\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-import.params.identity.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"did\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"mnemonic\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-import.params.mnemonic.description\"\n\t\t\t\t),\n\t\t\t\textendedType: \"24 words\",\n\t\t\t\trequired: true\n\t\t\t},\n\t\t\t{\n\t\t\t\tkey: \"load-env\",\n\t\t\t\ttype: \"string\",\n\t\t\t\tdescription: I18n.formatMessage(\n\t\t\t\t\t\"node.cli.commands.identity-import.params.load-env.description\"\n\t\t\t\t),\n\t\t\t\trequired: false\n\t\t\t}\n\t\t],\n\t\taction: async (engineCore, envVars, params) => identityImport(engineCore, envVars, params)\n\t};\n}\n\n/**\n * Command for importing an identity.\n * @param engineCore The engine core.\n * @param envVars The environment variables for the node.\n * @param params The parameters for the command.\n * @param params.identity The DID of the identity to import.\n * @param params.mnemonic The mnemonic to use for the identity.\n */\nexport async function identityImport(\n\tengineCore: IEngineCore<INodeEngineConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tparams: {\n\t\tidentity?: string;\n\t\tmnemonic?: string;\n\t}\n): Promise<void> {\n\tDid.guard(\"identityImport\", \"identity\", params.identity);\n\tGuards.stringValue(\"identityImport\", \"mnemonic\", params.mnemonic);\n\tif (!Bip39.validateMnemonic(params.mnemonic)) {\n\t\tthrow new GeneralError(\"identityImport\", \"invalidMnemonic\");\n\t}\n\n\tconst defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\"identityResolverConnector\"\n\t);\n\n\tconst identityResolverConnector = IdentityResolverConnectorFactory.get(\n\t\tdefaultIdentityResolverConnectorType\n\t);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.identity-import.labels.resolvingIdentity\"));\n\tconst identityDocument = await identityResolverConnector.resolveDocument(params.identity);\n\n\tif (Is.empty(identityDocument)) {\n\t\tthrow new GeneralError(\"identityImport\", \"identityNotFound\", {\n\t\t\tidentity: params.identity\n\t\t});\n\t}\n\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tCLIDisplay.task(I18n.formatMessage(\"node.cli.commands.identity-import.labels.storingMnemonic\"));\n\tconst mnemonicKey = `${params.identity}/mnemonic`;\n\tawait vaultConnector.setSecret(mnemonicKey, params.mnemonic);\n\n\tCLIDisplay.break();\n\tCLIDisplay.done();\n}\n"]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Copyright 2026 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { CLIDisplay, CLIUtils } from "@twin.org/cli-core";
|
|
5
|
+
import { Coerce, GeneralError, Guards, I18n, Is } from "@twin.org/core";
|
|
6
|
+
import { Did, IdentityConnectorFactory } from "@twin.org/identity-models";
|
|
7
|
+
const COMMAND_NAME = "identity-verifiable-credential-create";
|
|
8
|
+
/**
|
|
9
|
+
* Get the command definition parameters.
|
|
10
|
+
* @param commandDefinitions The registered command definitions.
|
|
11
|
+
*/
|
|
12
|
+
export function getCommandDefinitionIdentityVerifiableCredentialCreate(commandDefinitions) {
|
|
13
|
+
commandDefinitions[COMMAND_NAME] = {
|
|
14
|
+
command: COMMAND_NAME,
|
|
15
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.description"),
|
|
16
|
+
example: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.example"),
|
|
17
|
+
requiresNodeIdentity: false,
|
|
18
|
+
requiresTenantId: false,
|
|
19
|
+
params: [
|
|
20
|
+
{
|
|
21
|
+
key: "env-prefix",
|
|
22
|
+
type: "string",
|
|
23
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.env-prefix.description"),
|
|
24
|
+
required: false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
key: "identity",
|
|
28
|
+
type: "string",
|
|
29
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.identity.description"),
|
|
30
|
+
extendedType: "did"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "controller",
|
|
34
|
+
type: "string",
|
|
35
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.controller.description"),
|
|
36
|
+
extendedType: "did",
|
|
37
|
+
required: false
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: "verification-method-id",
|
|
41
|
+
type: "string",
|
|
42
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.verification-method-id.description"),
|
|
43
|
+
extendedType: "did with fragment"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
key: "subject-json",
|
|
47
|
+
type: "string",
|
|
48
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.subject-json.description"),
|
|
49
|
+
extendedType: "file",
|
|
50
|
+
required: true
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
key: "credential-id",
|
|
54
|
+
type: "string",
|
|
55
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.credential-id.description"),
|
|
56
|
+
extendedType: "url",
|
|
57
|
+
required: false
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
key: "expiration-date",
|
|
61
|
+
type: "string",
|
|
62
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.expiration-date.description"),
|
|
63
|
+
extendedType: "ISO date-time",
|
|
64
|
+
required: false
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
key: "load-env",
|
|
68
|
+
type: "string",
|
|
69
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.load-env.description"),
|
|
70
|
+
required: false
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "output-json",
|
|
74
|
+
type: "string",
|
|
75
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.output-json.description"),
|
|
76
|
+
required: false
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
key: "output-env",
|
|
80
|
+
type: "string",
|
|
81
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.output-env.description"),
|
|
82
|
+
required: false
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: "output-env-prefix",
|
|
86
|
+
type: "string",
|
|
87
|
+
description: I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.params.output-env-prefix.description"),
|
|
88
|
+
required: false
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
action: async (engineCore, envVars, params) => identityVerifiableCredentialCreate(engineCore, envVars, params)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Command for creating an identity verifiable credential.
|
|
96
|
+
* @param engineCore The engine core.
|
|
97
|
+
* @param envVars The environment variables for the node.
|
|
98
|
+
* @param params The parameters for the command.
|
|
99
|
+
* @param params.verificationMethodId The ID of the verification method to create the credential with.
|
|
100
|
+
* @param params.identity The DID of the identity to create the credential for.
|
|
101
|
+
* @param params.controller The controller DID for the identity.
|
|
102
|
+
* @param params.subjectJson The subject JSON file for the verifiable credential.
|
|
103
|
+
* @param params.credentialId The ID of the verifiable credential.
|
|
104
|
+
* @param params.expirationDate The expiration date of the verifiable credential.
|
|
105
|
+
* @param params.outputJson The output .json file to store the command output.
|
|
106
|
+
* @param params.outputEnv The output .env file to store the command output.
|
|
107
|
+
* @param params.outputEnvPrefix The prefix to use for variables in the output .env file.
|
|
108
|
+
* @returns The created verifiable credential and JWT.
|
|
109
|
+
*/
|
|
110
|
+
export async function identityVerifiableCredentialCreate(engineCore, envVars, params) {
|
|
111
|
+
Did.guard("identityVerifiableCredentialCreate", "identity", params.identity);
|
|
112
|
+
Guards.stringValue("identityVerifiableCredentialCreate", "verification-method-id", params.verificationMethodId);
|
|
113
|
+
Guards.stringValue("identityVerifiableCredentialCreate", "subject-json", params.subjectJson);
|
|
114
|
+
const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
|
|
115
|
+
const identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);
|
|
116
|
+
const subjectFilename = path.resolve(params.subjectJson);
|
|
117
|
+
const subject = await CLIUtils.readJsonFile(subjectFilename);
|
|
118
|
+
if (Is.empty(subject)) {
|
|
119
|
+
throw new GeneralError("identityVerifiableCredentialCreate", "subjectJsonLoadFailed", {
|
|
120
|
+
subjectFilename
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.labels.creating"));
|
|
124
|
+
CLIDisplay.spinnerStart();
|
|
125
|
+
if (!params.verificationMethodId.includes("#")) {
|
|
126
|
+
params.verificationMethodId = `${params.identity}#${params.verificationMethodId}`;
|
|
127
|
+
}
|
|
128
|
+
const credential = await identityConnector.createVerifiableCredential(params.controller ?? params.identity, params.verificationMethodId, params.credentialId, subject, {
|
|
129
|
+
expirationDate: Coerce.dateTime(params.expirationDate)
|
|
130
|
+
});
|
|
131
|
+
CLIDisplay.spinnerStop();
|
|
132
|
+
CLIDisplay.task(I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.labels.created"));
|
|
133
|
+
CLIDisplay.break();
|
|
134
|
+
CLIDisplay.value(I18n.formatMessage("node.cli.commands.identity-verifiable-credential-create.labels.jwtToken"), credential.jwt);
|
|
135
|
+
CLIDisplay.break();
|
|
136
|
+
if (Is.stringValue(params.outputJson)) {
|
|
137
|
+
await CLIUtils.writeJsonFile(params.outputJson, credential, false);
|
|
138
|
+
}
|
|
139
|
+
if (Is.stringValue(params.outputEnv)) {
|
|
140
|
+
const output = [`${params.outputEnvPrefix}VC_TOKEN="${credential.jwt}"`];
|
|
141
|
+
await CLIUtils.writeEnvFile(params.outputEnv, output, false);
|
|
142
|
+
}
|
|
143
|
+
CLIDisplay.done();
|
|
144
|
+
return credential;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=identityVerifiableCredentialCreate.js.map
|