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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +3 -1
  2. package/dist/es/builders/engineEnvBuilder.js +443 -126
  3. package/dist/es/builders/engineEnvBuilder.js.map +1 -1
  4. package/dist/es/builders/engineServerEnvBuilder.js +89 -32
  5. package/dist/es/builders/engineServerEnvBuilder.js.map +1 -1
  6. package/dist/es/builders/extensionsBuilder.js.map +1 -1
  7. package/dist/es/cli.js +247 -0
  8. package/dist/es/cli.js.map +1 -0
  9. package/dist/es/commands/bootstrapLegacy.js +199 -0
  10. package/dist/es/commands/bootstrapLegacy.js.map +1 -0
  11. package/dist/es/commands/help.js +85 -0
  12. package/dist/es/commands/help.js.map +1 -0
  13. package/dist/es/commands/identityCreate.js +327 -0
  14. package/dist/es/commands/identityCreate.js.map +1 -0
  15. package/dist/es/commands/identityImports.js +82 -0
  16. package/dist/es/commands/identityImports.js.map +1 -0
  17. package/dist/es/commands/identityVerifiableCredentialCreate.js +146 -0
  18. package/dist/es/commands/identityVerifiableCredentialCreate.js.map +1 -0
  19. package/dist/es/commands/identityVerificationMethodCreate.js +228 -0
  20. package/dist/es/commands/identityVerificationMethodCreate.js.map +1 -0
  21. package/dist/es/commands/identityVerificationMethodImport.js +126 -0
  22. package/dist/es/commands/identityVerificationMethodImport.js.map +1 -0
  23. package/dist/es/commands/nodeSetIdentity.js +64 -0
  24. package/dist/es/commands/nodeSetIdentity.js.map +1 -0
  25. package/dist/es/commands/nodeSetTenant.js +68 -0
  26. package/dist/es/commands/nodeSetTenant.js.map +1 -0
  27. package/dist/es/commands/tenantCreate.js +139 -0
  28. package/dist/es/commands/tenantCreate.js.map +1 -0
  29. package/dist/es/commands/tenantImport.js +97 -0
  30. package/dist/es/commands/tenantImport.js.map +1 -0
  31. package/dist/es/commands/tenantUpdate.js +94 -0
  32. package/dist/es/commands/tenantUpdate.js.map +1 -0
  33. package/dist/es/commands/userCreate.js +239 -0
  34. package/dist/es/commands/userCreate.js.map +1 -0
  35. package/dist/es/commands/userUpdate.js +154 -0
  36. package/dist/es/commands/userUpdate.js.map +1 -0
  37. package/dist/es/commands/vaultKeyCreate.js +191 -0
  38. package/dist/es/commands/vaultKeyCreate.js.map +1 -0
  39. package/dist/es/commands/vaultKeyImport.js +104 -0
  40. package/dist/es/commands/vaultKeyImport.js.map +1 -0
  41. package/dist/es/defaults.js +19 -1
  42. package/dist/es/defaults.js.map +1 -1
  43. package/dist/es/index.js +11 -4
  44. package/dist/es/index.js.map +1 -1
  45. package/dist/es/models/ICliArgs.js +4 -0
  46. package/dist/es/models/ICliArgs.js.map +1 -0
  47. package/dist/es/models/ICliCommand.js +2 -0
  48. package/dist/es/models/ICliCommand.js.map +1 -0
  49. package/dist/es/models/ICliCommandDefinition.js +2 -0
  50. package/dist/es/models/ICliCommandDefinition.js.map +1 -0
  51. package/dist/es/models/ICliCommandDefinitionParam.js +2 -0
  52. package/dist/es/models/ICliCommandDefinitionParam.js.map +1 -0
  53. package/dist/es/models/IEngineEnvironmentVariables.js.map +1 -1
  54. package/dist/es/models/IEngineServerEnvironmentVariables.js.map +1 -1
  55. package/dist/es/models/INodeEngineState.js.map +1 -1
  56. package/dist/es/models/INodeEnvironmentVariables.js.map +1 -1
  57. package/dist/es/models/INodeOptions.js.map +1 -1
  58. package/dist/es/models/cliCommandParamType.js +4 -0
  59. package/dist/es/models/cliCommandParamType.js.map +1 -0
  60. package/dist/es/models/nodeExtensionInitialiseEngineMethod.js +2 -0
  61. package/dist/es/models/nodeExtensionInitialiseEngineMethod.js.map +1 -0
  62. package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js +2 -0
  63. package/dist/es/models/nodeExtensionInitialiseEngineServerMethod.js.map +1 -0
  64. package/dist/es/models/nodeExtensionInitialiseMethod.js +2 -0
  65. package/dist/es/models/nodeExtensionInitialiseMethod.js.map +1 -0
  66. package/dist/es/models/nodeExtensionShutdownMethod.js +4 -0
  67. package/dist/es/models/nodeExtensionShutdownMethod.js.map +1 -0
  68. package/dist/es/node.js +86 -39
  69. package/dist/es/node.js.map +1 -1
  70. package/dist/es/start.js +139 -0
  71. package/dist/es/start.js.map +1 -0
  72. package/dist/es/utils.js +12 -22
  73. package/dist/es/utils.js.map +1 -1
  74. package/dist/types/builders/engineEnvBuilder.d.ts +64 -1
  75. package/dist/types/builders/engineServerEnvBuilder.d.ts +11 -2
  76. package/dist/types/cli.d.ts +56 -0
  77. package/dist/types/commands/bootstrapLegacy.d.ts +66 -0
  78. package/dist/types/commands/help.d.ts +23 -0
  79. package/dist/types/commands/identityCreate.d.ts +39 -0
  80. package/dist/types/commands/identityImports.d.ts +24 -0
  81. package/dist/types/commands/identityVerifiableCredentialCreate.d.ts +43 -0
  82. package/dist/types/commands/identityVerificationMethodCreate.d.ts +47 -0
  83. package/dist/types/commands/identityVerificationMethodImport.d.ts +31 -0
  84. package/dist/types/commands/nodeSetIdentity.d.ts +22 -0
  85. package/dist/types/commands/nodeSetTenant.d.ts +22 -0
  86. package/dist/types/commands/tenantCreate.d.ts +38 -0
  87. package/dist/types/commands/tenantImport.d.ts +26 -0
  88. package/dist/types/commands/tenantUpdate.d.ts +26 -0
  89. package/dist/types/commands/userCreate.d.ts +51 -0
  90. package/dist/types/commands/userUpdate.d.ts +40 -0
  91. package/dist/types/commands/vaultKeyCreate.d.ts +43 -0
  92. package/dist/types/commands/vaultKeyImport.d.ts +28 -0
  93. package/dist/types/defaults.d.ts +10 -1
  94. package/dist/types/index.d.ts +11 -4
  95. package/dist/types/models/ICliArgs.d.ts +20 -0
  96. package/dist/types/models/ICliCommand.d.ts +17 -0
  97. package/dist/types/models/ICliCommandDefinition.d.ts +46 -0
  98. package/dist/types/models/ICliCommandDefinitionParam.d.ts +35 -0
  99. package/dist/types/models/IEngineEnvironmentVariables.d.ts +117 -60
  100. package/dist/types/models/IEngineServerEnvironmentVariables.d.ts +8 -0
  101. package/dist/types/models/INodeEngineState.d.ts +0 -8
  102. package/dist/types/models/INodeEnvironmentVariables.d.ts +0 -38
  103. package/dist/types/models/INodeOptions.d.ts +6 -2
  104. package/dist/types/models/cliCommandParamType.d.ts +4 -0
  105. package/dist/types/models/nodeExtensionInitialiseEngineMethod.d.ts +7 -0
  106. package/dist/types/models/nodeExtensionInitialiseEngineServerMethod.d.ts +8 -0
  107. package/dist/types/models/nodeExtensionInitialiseMethod.d.ts +8 -0
  108. package/dist/types/models/nodeExtensionShutdownMethod.d.ts +5 -0
  109. package/dist/types/node.d.ts +5 -4
  110. package/dist/types/{server.d.ts → start.d.ts} +4 -2
  111. package/dist/types/utils.d.ts +6 -8
  112. package/docs/changelog.md +532 -176
  113. package/docs/examples.md +99 -1
  114. package/docs/reference/functions/buildConfiguration.md +1 -1
  115. package/docs/reference/functions/buildEngineServerConfiguration.md +1 -1
  116. package/docs/reference/functions/constructCliCommand.md +27 -0
  117. package/docs/reference/functions/executeCommand.md +29 -0
  118. package/docs/reference/functions/getEnvDefaults.md +19 -0
  119. package/docs/reference/functions/getScriptDirectory.md +19 -0
  120. package/docs/reference/functions/isAuthEntityStorageRequired.md +20 -0
  121. package/docs/reference/functions/isAutomationRequired.md +20 -0
  122. package/docs/reference/functions/isBackgroundTasksRequired.md +20 -0
  123. package/docs/reference/functions/isFederatedCatalogueRequired.md +20 -0
  124. package/docs/reference/functions/isImmutableProofRequired.md +20 -0
  125. package/docs/reference/functions/isRightsManagementRequired.md +20 -0
  126. package/docs/reference/functions/isTaskSchedulerRequired.md +20 -0
  127. package/docs/reference/functions/isTelemetryRequired.md +20 -0
  128. package/docs/reference/functions/isTrustRequired.md +20 -0
  129. package/docs/reference/functions/isUrlTransformerRequired.md +20 -0
  130. package/docs/reference/functions/parseCommandLineArgs.md +19 -0
  131. package/docs/reference/functions/processEnvOptions.md +27 -0
  132. package/docs/reference/functions/registerCommands.md +9 -0
  133. package/docs/reference/functions/resolvePackageEntryPoint.md +2 -2
  134. package/docs/reference/functions/run.md +8 -2
  135. package/docs/reference/functions/start.md +9 -3
  136. package/docs/reference/functions/substituteEnvOptions.md +25 -0
  137. package/docs/reference/index.md +26 -13
  138. package/docs/reference/interfaces/ICacheMetadata.md +3 -3
  139. package/docs/reference/interfaces/ICliArgs.md +35 -0
  140. package/docs/reference/interfaces/ICliCommand.md +23 -0
  141. package/docs/reference/interfaces/ICliCommandDefinition.md +101 -0
  142. package/docs/reference/interfaces/ICliCommandDefinitionParam.md +65 -0
  143. package/docs/reference/interfaces/IEngineEnvironmentVariables.md +420 -311
  144. package/docs/reference/interfaces/IEngineServerEnvironmentVariables.md +545 -368
  145. package/docs/reference/interfaces/IModuleProtocol.md +3 -3
  146. package/docs/reference/interfaces/INodeEngineState.md +4 -20
  147. package/docs/reference/interfaces/INodeEnvironmentVariables.md +551 -450
  148. package/docs/reference/interfaces/INodeOptions.md +44 -36
  149. package/docs/reference/interfaces/IProtocolHandlerResult.md +2 -2
  150. package/docs/reference/type-aliases/CliCommandParamType.md +5 -0
  151. package/docs/reference/type-aliases/NodeExtensionInitialiseEngineMethod.md +1 -1
  152. package/docs/reference/type-aliases/NodeExtensionInitialiseEngineServerMethod.md +1 -1
  153. package/docs/reference/type-aliases/NodeExtensionInitialiseMethod.md +1 -1
  154. package/docs/reference/type-aliases/NodeExtensionShutdownMethod.md +1 -1
  155. package/docs/reference/variables/ModuleProtocol.md +5 -5
  156. package/docs/reference/variables/TRUST_VERIFICATION_METHOD_ID.md +3 -0
  157. package/docs/reference/variables/URL_TRANSFORMER_ENCRYPTION_KEY_ID.md +3 -0
  158. package/locales/en.json +600 -30
  159. package/package.json +10 -6
  160. package/dist/es/bootstrap.js +0 -366
  161. package/dist/es/bootstrap.js.map +0 -1
  162. package/dist/es/identity.js +0 -182
  163. package/dist/es/identity.js.map +0 -1
  164. package/dist/es/models/nodeExtensionMethods.js +0 -2
  165. package/dist/es/models/nodeExtensionMethods.js.map +0 -1
  166. package/dist/es/models/nodeFeatures.js +0 -21
  167. package/dist/es/models/nodeFeatures.js.map +0 -1
  168. package/dist/es/server.js +0 -81
  169. package/dist/es/server.js.map +0 -1
  170. package/dist/types/bootstrap.d.ts +0 -68
  171. package/dist/types/identity.d.ts +0 -14
  172. package/dist/types/models/nodeExtensionMethods.d.ts +0 -27
  173. package/dist/types/models/nodeFeatures.d.ts +0 -21
  174. package/docs/detailed-guide.md +0 -129
  175. package/docs/reference/functions/bootstrap.md +0 -29
  176. package/docs/reference/functions/bootstrapAuth.md +0 -35
  177. package/docs/reference/functions/bootstrapBlobEncryption.md +0 -35
  178. package/docs/reference/functions/bootstrapImmutableProofMethod.md +0 -35
  179. package/docs/reference/functions/bootstrapNodeAdminUser.md +0 -35
  180. package/docs/reference/functions/bootstrapNodeId.md +0 -35
  181. package/docs/reference/functions/bootstrapSynchronisedStorage.md +0 -35
  182. package/docs/reference/functions/bootstrapTenantId.md +0 -35
  183. package/docs/reference/functions/getFeatures.md +0 -19
  184. package/docs/reference/type-aliases/NodeFeatures.md +0 -5
  185. package/docs/reference/variables/NodeFeatures.md +0 -25
  186. package/docs/reference/variables/VC_AUTHENTICATION_VERIFICATION_METHOD_ID.md +0 -3
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/node-core",
3
- "version": "0.0.3-next.4",
3
+ "version": "0.0.3-next.40",
4
4
  "description": "TWIN Node Core for serving APIs using the specified configuration",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/node.git",
7
+ "url": "git+https://github.com/iotaledger/node.git",
8
8
  "directory": "packages/node-core"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -20,7 +20,7 @@
20
20
  "@twin.org/context": "next",
21
21
  "@twin.org/core": "next",
22
22
  "@twin.org/crypto": "next",
23
- "@twin.org/data-space-connector-models": "next",
23
+ "@twin.org/dataspace-models": "next",
24
24
  "@twin.org/engine": "next",
25
25
  "@twin.org/engine-core": "next",
26
26
  "@twin.org/engine-models": "next",
@@ -32,11 +32,15 @@
32
32
  "@twin.org/identity-models": "next",
33
33
  "@twin.org/modules": "next",
34
34
  "@twin.org/rights-management-rest-client": "next",
35
+ "@twin.org/standards-w3c-did": "next",
35
36
  "@twin.org/standards-w3c-odrl": "next",
37
+ "@twin.org/telemetry-connector-opentelemetry": "next",
38
+ "@twin.org/telemetry-models": "next",
39
+ "@twin.org/trust-models": "next",
36
40
  "@twin.org/vault-models": "next",
37
41
  "@twin.org/wallet-models": "next",
38
- "dotenv": "17.2.3",
39
- "schema-dts": "1.1.5"
42
+ "dotenv": "17.4.2",
43
+ "schema-dts": "2.0.0"
40
44
  },
41
45
  "main": "./dist/es/index.js",
42
46
  "types": "./dist/types/index.d.ts",
@@ -66,7 +70,7 @@
66
70
  "utilities"
67
71
  ],
68
72
  "bugs": {
69
- "url": "git+https://github.com/twinfoundation/node/issues"
73
+ "url": "git+https://github.com/iotaledger/node/issues"
70
74
  },
71
75
  "homepage": "https://twindev.org"
72
76
  }
@@ -1,366 +0,0 @@
1
- // Copyright 2024 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
- import { PasswordHelper } from "@twin.org/api-auth-entity-storage-service";
4
- import { TenantIdHelper } from "@twin.org/api-tenant-processor";
5
- import { ContextIdKeys, ContextIdStore } from "@twin.org/context";
6
- import { Coerce, ComponentFactory, Converter, I18n, Is, RandomHelper } from "@twin.org/core";
7
- import { PasswordGenerator } from "@twin.org/crypto";
8
- import { AuthenticationComponentType } from "@twin.org/engine-server-types";
9
- import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
10
- import { DocumentHelper, IdentityConnectorFactory, IdentityProfileConnectorFactory, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
11
- import { VaultConnectorFactory, VaultKeyType } from "@twin.org/vault-models";
12
- import { ATTESTATION_VERIFICATION_METHOD_ID, AUTH_SIGNING_KEY_ID, BLOB_STORAGE_ENCRYPTION_KEY_ID, IMMUTABLE_PROOF_VERIFICATION_METHOD_ID, SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID, VC_AUTHENTICATION_VERIFICATION_METHOD_ID } from "./defaults.js";
13
- import { createIdentity } from "./identity.js";
14
- import { NodeFeatures } from "./models/nodeFeatures.js";
15
- import { getFeatures } from "./utils.js";
16
- const DEFAULT_NODE_ADMIN_USERNAME = "admin@node";
17
- /**
18
- * Bootstrap the application.
19
- * @param engineCore The engine core for the node.
20
- * @param context The context for the node.
21
- * @param envVars The environment variables for the node.
22
- */
23
- export async function bootstrap(engineCore, context, envVars) {
24
- const features = getFeatures(envVars);
25
- await bootstrapNodeId(engineCore, context, envVars, features);
26
- await ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {
27
- await bootstrapTenantId(engineCore, context, envVars, features);
28
- await bootstrapNodeAdminUser(engineCore, context, envVars, features);
29
- await bootstrapAuth(engineCore, context, envVars, features);
30
- await bootstrapBlobEncryption(engineCore, context, envVars, features);
31
- const defaultAttestationConnectorType = engineCore.getRegisteredInstanceTypeOptional("attestationConnector");
32
- if (!Is.empty(defaultAttestationConnectorType) &&
33
- Is.stringValue(context.state.nodeOrganizationId)) {
34
- await addVerificationMethod(engineCore, context, context.state.nodeOrganizationId, "attestation", envVars.attestationVerificationMethodId ?? ATTESTATION_VERIFICATION_METHOD_ID);
35
- }
36
- const defaultImmutableProofComponentType = engineCore.getRegisteredInstanceTypeOptional("immutableProofComponent");
37
- if (!Is.empty(defaultImmutableProofComponentType) &&
38
- Is.stringValue(context.state.nodeOrganizationId)) {
39
- await addVerificationMethod(engineCore, context, context.state.nodeOrganizationId, "immutable proof", envVars.immutableProofVerificationMethodId ?? IMMUTABLE_PROOF_VERIFICATION_METHOD_ID);
40
- }
41
- if ((Coerce.boolean(envVars.vcAuthenticationEnabled) ?? false) &&
42
- Is.stringValue(context.state.nodeId)) {
43
- await addVerificationMethod(engineCore, context, context.state.nodeId, "verifiable credential authentication", envVars.vcAuthenticationVerificationMethodId ?? VC_AUTHENTICATION_VERIFICATION_METHOD_ID);
44
- }
45
- await bootstrapSynchronisedStorage(engineCore, context, envVars, features);
46
- });
47
- }
48
- /**
49
- * Bootstrap the node creating any necessary resources.
50
- * @param engineCore The engine core for the node.
51
- * @param context The context for the node.
52
- * @param envVars The environment variables for the node.
53
- * @param features The features that are enabled on the node. The features that are enabled on the node.
54
- */
55
- export async function bootstrapNodeId(engineCore, context, envVars, features) {
56
- if (features.includes(NodeFeatures.NodeId)) {
57
- const existingNodeId = envVars.nodeIdentity ?? context.state.nodeId;
58
- context.state.nodeId = await createIdentity(engineCore, envVars, existingNodeId, envVars.nodeMnemonic, existingNodeId, "node", features.includes(NodeFeatures.NodeWallet));
59
- context.stateDirty = true;
60
- engineCore.logInfo(I18n.formatMessage("node.nodeId", {
61
- identity: context.state.nodeId
62
- }));
63
- engineCore.addContextId(ContextIdKeys.Node, context.state.nodeId);
64
- }
65
- }
66
- /**
67
- * Bootstrap the node creating any necessary resources.
68
- * @param engineCore The engine core for the node.
69
- * @param context The context for the node.
70
- * @param envVars The environment variables for the node.
71
- * @param features The features that are enabled on the node. The features that are enabled on the node.
72
- */
73
- export async function bootstrapTenantId(engineCore, context, envVars, features) {
74
- // If tenants are enabled we need to add a context id for the node
75
- // so that services such a logging have a default tenant context id
76
- // this will get overwritten by any incoming API requests with the tenant context id
77
- if (Coerce.boolean(envVars.tenantEnabled) ?? false) {
78
- let tenantId = envVars.tenantId ?? context.state.nodeTenantId;
79
- if (!Is.stringValue(tenantId)) {
80
- const tenantAdminServiceComponentType = engineCore.getRegisteredInstanceType("tenantAdminComponent");
81
- const tenantAdminService = ComponentFactory.get(tenantAdminServiceComponentType);
82
- tenantId = TenantIdHelper.generateTenantId();
83
- const apiKey = envVars.tenantApiKey ?? TenantIdHelper.generateApiKey();
84
- await tenantAdminService.set({
85
- id: tenantId,
86
- apiKey,
87
- dateCreated: new Date(Date.now()).toISOString(),
88
- label: "node-tenant"
89
- });
90
- engineCore.logInfo(I18n.formatMessage("node.createdTenantId", {
91
- identity: tenantId,
92
- apiKey
93
- }));
94
- }
95
- else {
96
- engineCore.logInfo(I18n.formatMessage("node.existingTenantId", {
97
- identity: context.state.nodeTenantId
98
- }));
99
- }
100
- context.state.nodeTenantId = tenantId;
101
- context.stateDirty = true;
102
- engineCore.addContextId(ContextIdKeys.Tenant, context.state.nodeTenantId);
103
- }
104
- }
105
- /**
106
- * Bootstrap the user.
107
- * @param engineCore The engine core for the node.
108
- * @param context The context for the node.
109
- * @param envVars The environment variables for the node.
110
- * @param features The features that are enabled on the node.
111
- */
112
- export async function bootstrapNodeAdminUser(engineCore, context, envVars, features) {
113
- if (features.includes(NodeFeatures.NodeAdminUser)) {
114
- context.state.nodeOrganizationId =
115
- envVars.organizationIdentity ?? context.state.nodeOrganizationId;
116
- context.state.nodeAdminUserId = envVars.adminUserIdentity ?? context.state.nodeAdminUserId;
117
- const defaultAuthenticationComponentType = engineCore.getRegisteredInstanceType("authenticationComponent");
118
- if (defaultAuthenticationComponentType.startsWith(AuthenticationComponentType.EntityStorage) &&
119
- Is.stringValue(context.state.nodeId)) {
120
- const authUserEntityStorage = EntityStorageConnectorFactory.get("authentication-user");
121
- const existingOrganizationId = envVars.organizationIdentity ?? context.state.nodeOrganizationId;
122
- const orgId = await createIdentity(engineCore, envVars, existingOrganizationId, envVars.organizationMnemonic, existingOrganizationId, "organization", features.includes(NodeFeatures.NodeWallet));
123
- if (context.state.nodeOrganizationId !== orgId) {
124
- context.state.nodeOrganizationId = orgId;
125
- context.stateDirty = true;
126
- }
127
- const userId = await createIdentity(engineCore, envVars, context.state.nodeAdminUserId, envVars.adminUserMnemonic, context.state.nodeOrganizationId, "user", false);
128
- if (context.state.nodeAdminUserId !== userId) {
129
- context.state.nodeAdminUserId = userId;
130
- context.stateDirty = true;
131
- }
132
- const adminEmail = envVars.adminUserName ?? DEFAULT_NODE_ADMIN_USERNAME;
133
- let nodeAdminUser = await authUserEntityStorage.get(adminEmail);
134
- // If the node admin user doesn't exist, create it
135
- if (Is.empty(nodeAdminUser)) {
136
- engineCore.logInfo(I18n.formatMessage("node.creatingUser", { email: adminEmail }));
137
- const generatedPassword = envVars.adminUserPassword ?? PasswordGenerator.generate(16);
138
- const passwordBytes = Converter.utf8ToBytes(generatedPassword);
139
- const saltBytes = RandomHelper.generate(16);
140
- const hashedPassword = await PasswordHelper.hashPassword(passwordBytes, saltBytes);
141
- nodeAdminUser = {
142
- email: adminEmail,
143
- password: hashedPassword,
144
- salt: Converter.bytesToBase64(saltBytes),
145
- identity: context.state.nodeAdminUserId,
146
- organization: context.state.nodeOrganizationId
147
- };
148
- engineCore.logInfo(I18n.formatMessage("node.nodeAdminUserEmail", { email: adminEmail }));
149
- const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
150
- const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
151
- const vaultKey = `${context.state.nodeAdminUserId}/admin-password`;
152
- await vaultConnector.setSecret(vaultKey, generatedPassword);
153
- engineCore.logInfo(I18n.formatMessage("node.nodeAdminUserPassword", { vaultKey }));
154
- await authUserEntityStorage.set(nodeAdminUser);
155
- }
156
- else {
157
- engineCore.logInfo(I18n.formatMessage("node.existingUser", { email: adminEmail }));
158
- // The user already exists, so double check the other details match
159
- let needsUpdate = false;
160
- if (nodeAdminUser.identity !== context.state.nodeAdminUserId) {
161
- nodeAdminUser.identity = context.state.nodeAdminUserId;
162
- needsUpdate = true;
163
- }
164
- if (Is.stringValue(envVars.adminUserPassword)) {
165
- const passwordBytes = Converter.utf8ToBytes(envVars.adminUserPassword);
166
- const saltBytes = Converter.base64ToBytes(nodeAdminUser.salt);
167
- const hashedPassword = await PasswordHelper.hashPassword(passwordBytes, saltBytes);
168
- if (nodeAdminUser.password !== hashedPassword) {
169
- nodeAdminUser.password = hashedPassword;
170
- needsUpdate = true;
171
- }
172
- }
173
- if (needsUpdate) {
174
- await authUserEntityStorage.set(nodeAdminUser);
175
- }
176
- }
177
- // We have create a node user, now we need to create a profile for the user
178
- const defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType("identityProfileConnector");
179
- const identityProfileConnector = IdentityProfileConnectorFactory.get(defaultIdentityProfileConnectorType);
180
- if (identityProfileConnector) {
181
- // Add the organization context id when creating the profile
182
- // so that it is partitioned under the organization
183
- const contextIds = (await ContextIdStore.getContextIds()) ?? {};
184
- contextIds[ContextIdKeys.Organization] = context.state.nodeOrganizationId;
185
- await ContextIdStore.run(contextIds, async () => {
186
- let userProfile;
187
- if (Is.stringValue(nodeAdminUser.identity)) {
188
- try {
189
- userProfile = await identityProfileConnector.get(nodeAdminUser.identity);
190
- }
191
- catch { }
192
- }
193
- if (Is.empty(userProfile)) {
194
- engineCore.logInfo(I18n.formatMessage("node.creatingUserProfile", {
195
- identity: nodeAdminUser.identity
196
- }));
197
- const publicProfile = {
198
- "@context": "https://schema.org",
199
- "@type": "Person",
200
- name: "Node Administrator"
201
- };
202
- const privateProfile = {
203
- "@context": "https://schema.org",
204
- "@type": "Person",
205
- givenName: "Node",
206
- familyName: "Administrator",
207
- email: adminEmail
208
- };
209
- await identityProfileConnector.create(nodeAdminUser.identity, publicProfile, privateProfile);
210
- }
211
- else {
212
- engineCore.logInfo(I18n.formatMessage("node.existingUserProfile", {
213
- identity: nodeAdminUser.identity
214
- }));
215
- }
216
- });
217
- }
218
- }
219
- }
220
- }
221
- /**
222
- * Bootstrap the immutable proof verification methods.
223
- * @param engineCore The engine core for the node.
224
- * @param context The context for the node.
225
- * @param envVars The environment variables for the node.
226
- * @param features The features that are enabled on the node.
227
- */
228
- export async function bootstrapImmutableProofMethod(engineCore, context, envVars, features) { }
229
- /**
230
- * Bootstrap the keys for blob encryption.
231
- * @param engineCore The engine core for the node.
232
- * @param context The context for the node.
233
- * @param envVars The environment variables for the node.
234
- * @param features The features that are enabled on the node.
235
- */
236
- export async function bootstrapBlobEncryption(engineCore, context, envVars, features) {
237
- if ((Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) &&
238
- Is.stringValue(context.state.nodeOrganizationId)) {
239
- // Create a new key for encrypting blobs
240
- const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
241
- const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
242
- const keyName = `${context.state.nodeOrganizationId}/${envVars.blobStorageEncryptionKeyId ?? BLOB_STORAGE_ENCRYPTION_KEY_ID}`;
243
- let existingKey;
244
- try {
245
- existingKey = await vaultConnector.getKey(keyName);
246
- }
247
- catch { }
248
- if (Is.empty(existingKey)) {
249
- if (Is.stringBase64(envVars.blobStorageSymmetricEncryptionKey)) {
250
- engineCore.logInfo(I18n.formatMessage("node.addingBlobEncryptionKey", { keyName }));
251
- await vaultConnector.addKey(keyName, VaultKeyType.ChaCha20Poly1305, Converter.base64ToBytes(envVars.blobStorageSymmetricEncryptionKey));
252
- }
253
- else {
254
- engineCore.logInfo(I18n.formatMessage("node.creatingBlobEncryptionKey", { keyName }));
255
- const key = await vaultConnector.createKey(keyName, VaultKeyType.ChaCha20Poly1305);
256
- engineCore.logInfo(I18n.formatMessage("node.createdBlobEncryptionKey", {
257
- keyName,
258
- keyValue: Converter.bytesToBase64(key)
259
- }));
260
- }
261
- }
262
- else {
263
- engineCore.logInfo(I18n.formatMessage("node.existingBlobEncryptionKey", { keyName }));
264
- }
265
- }
266
- }
267
- /**
268
- * Bootstrap the JWT signing key.
269
- * @param engineCore The engine core for the node.
270
- * @param context The context for the node.
271
- * @param envVars The environment variables for the node.
272
- * @param features The features that are enabled on the node.
273
- */
274
- export async function bootstrapAuth(engineCore, context, envVars, features) {
275
- const defaultAuthenticationComponentType = engineCore.getRegisteredInstanceTypeOptional("authenticationComponent");
276
- if (Is.stringValue(defaultAuthenticationComponentType) &&
277
- defaultAuthenticationComponentType.startsWith(AuthenticationComponentType.EntityStorage) &&
278
- Is.stringValue(context.state.nodeId)) {
279
- // Create a new JWT signing key and a user login for the node
280
- const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
281
- const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
282
- const keyName = `${context.state.nodeId}/${envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID}`;
283
- let existingKey;
284
- try {
285
- existingKey = await vaultConnector.getKey(keyName);
286
- }
287
- catch { }
288
- if (Is.empty(existingKey)) {
289
- engineCore.logInfo(I18n.formatMessage("node.creatingAuthKey", { keyName }));
290
- await vaultConnector.createKey(keyName, VaultKeyType.Ed25519);
291
- }
292
- else {
293
- engineCore.logInfo(I18n.formatMessage("node.existingAuthKey", { keyName }));
294
- }
295
- }
296
- }
297
- /**
298
- * Bootstrap the synchronised storage blob encryption and verification methods.
299
- * @param engineCore The engine core for the node.
300
- * @param context The context for the node.
301
- * @param envVars The environment variables for the node.
302
- * @param features The features that are enabled on the node.
303
- */
304
- export async function bootstrapSynchronisedStorage(engineCore, context, envVars, features) {
305
- if (Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) {
306
- // If this is a trusted node we need to add the blob encryption key pair
307
- if (Is.stringBase64(envVars.synchronisedStorageBlobStorageKey)) {
308
- const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
309
- const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
310
- const keyName = envVars.synchronisedStorageBlobStorageEncryptionKeyId ??
311
- SYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID;
312
- let existingKey;
313
- try {
314
- existingKey = await vaultConnector.getKey(keyName);
315
- }
316
- catch { }
317
- if (Is.empty(existingKey)) {
318
- engineCore.logInfo(I18n.formatMessage("node.addingSynchronisedStorageBlobEncryptionKey", { keyName }));
319
- await vaultConnector.addKey(keyName, VaultKeyType.ChaCha20Poly1305, Converter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey));
320
- }
321
- else {
322
- engineCore.logInfo(I18n.formatMessage("node.existingSynchronisedStorageBlobEncryptionKey", { keyName }));
323
- }
324
- }
325
- }
326
- }
327
- /**
328
- * Add a verification method if it doesn't exist.
329
- * @param engineCore The engine core for the node.
330
- * @param context The context for the node.
331
- * @param identity The identity to add the verification method to.
332
- * @param verificationMethodTitle The verification method title.
333
- * @param verificationMethodId The verification method ID.
334
- */
335
- async function addVerificationMethod(engineCore, context, identity, verificationMethodTitle, verificationMethodId) {
336
- if (Is.stringValue(identity) &&
337
- Is.arrayValue(context.config.types.identityConnector) &&
338
- Is.stringValue(verificationMethodId)) {
339
- const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
340
- const identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);
341
- const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
342
- const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
343
- const identityDocument = await identityResolverConnector.resolveDocument(identity);
344
- const fullMethodId = `${identityDocument.id}#${verificationMethodId}`;
345
- let exists = false;
346
- try {
347
- DocumentHelper.getVerificationMethod(identityDocument, fullMethodId, "assertionMethod");
348
- exists = true;
349
- }
350
- catch { }
351
- if (!exists) {
352
- engineCore.logInfo(I18n.formatMessage("node.addingVerificationMethod", {
353
- title: verificationMethodTitle,
354
- methodId: fullMethodId
355
- }));
356
- await identityConnector.addVerificationMethod(identity, identity, "assertionMethod", verificationMethodId);
357
- }
358
- else {
359
- engineCore.logInfo(I18n.formatMessage("node.existingVerificationMethod", {
360
- title: verificationMethodTitle,
361
- methodId: fullMethodId
362
- }));
363
- }
364
- }
365
- }
366
- //# sourceMappingURL=bootstrap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../../src/bootstrap.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,cAAc,EAA2B,MAAM,2CAA2C,CAAC;AACpG,OAAO,EAAE,cAAc,EAA8B,MAAM,gCAAgC,CAAC;AAC5F,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,EAAE,MAA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AC,4BAA4B,CAAC,CAAC;QAErF,MAAM,oCAAoC,GAAG,UAAU,CAAC,yBAAyB,CAChF,2BAA2B,CAC3B,CAAC;QACF,MAAM,yBAAyB,GAAG,gCAAgC,CAAC,GAAG,CACrE,oCAAoC,CACpC,CAAC;QAEF,MAAM,gBAAgB,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAEnF,MAAM,YAAY,GAAG,GAAG,gBAAgB,CAAC,EAAE,IAAI,oBAAoB,EAAE,CAAC;QAEtE,IAAI,MAAM,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC;YACJ,cAAc,CAAC,qBAAqB,CAAC,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC;YACxF,MAAM,GAAG,IAAI,CAAC;QACf,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QAEV,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,+BAA+B,EAAE;gBACnD,KAAK,EAAE,uBAAuB;gBAC9B,QAAQ,EAAE,YAAY;aACtB,CAAC,CACF,CAAC;YACF,MAAM,iBAAiB,CAAC,qBAAqB,CAC5C,QAAQ,EACR,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,CACpB,CAAC;QACH,CAAC;aAAM,CAAC;YACP,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,iCAAiC,EAAE;gBACrD,KAAK,EAAE,uBAAuB;gBAC9B,QAAQ,EAAE,YAAY;aACtB,CAAC,CACF,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { PasswordHelper, type AuthenticationUser } from \"@twin.org/api-auth-entity-storage-service\";\nimport { TenantIdHelper, type ITenantAdminComponent } from \"@twin.org/api-tenant-processor\";\nimport { ContextIdKeys, ContextIdStore } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, Converter, I18n, Is, RandomHelper } from \"@twin.org/core\";\nimport { PasswordGenerator } from \"@twin.org/crypto\";\nimport type { IEngineCore, IEngineCoreContext } from \"@twin.org/engine-models\";\nimport {\n\tAuthenticationComponentType,\n\ttype IEngineServerConfig\n} from \"@twin.org/engine-server-types\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport {\n\tDocumentHelper,\n\tIdentityConnectorFactory,\n\tIdentityProfileConnectorFactory,\n\tIdentityResolverConnectorFactory\n} from \"@twin.org/identity-models\";\nimport { nameofKebabCase } from \"@twin.org/nameof\";\nimport { VaultConnectorFactory, VaultKeyType } from \"@twin.org/vault-models\";\nimport type { Person, WithContext } from \"schema-dts\";\nimport {\n\tATTESTATION_VERIFICATION_METHOD_ID,\n\tAUTH_SIGNING_KEY_ID,\n\tBLOB_STORAGE_ENCRYPTION_KEY_ID,\n\tIMMUTABLE_PROOF_VERIFICATION_METHOD_ID,\n\tSYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID,\n\tVC_AUTHENTICATION_VERIFICATION_METHOD_ID\n} from \"./defaults.js\";\nimport { createIdentity } from \"./identity.js\";\nimport type { INodeEngineState } from \"./models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.js\";\nimport { NodeFeatures } from \"./models/nodeFeatures.js\";\nimport { getFeatures } from \"./utils.js\";\n\nconst DEFAULT_NODE_ADMIN_USERNAME = \"admin@node\";\n\n/**\n * Bootstrap the application.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param envVars The environment variables for the node.\n */\nexport async function bootstrap(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables\n): Promise<void> {\n\tconst features = getFeatures(envVars);\n\n\tawait bootstrapNodeId(engineCore, context, envVars, features);\n\n\tawait ContextIdStore.run(engineCore.getContextIds() ?? {}, async () => {\n\t\tawait bootstrapTenantId(engineCore, context, envVars, features);\n\n\t\tawait bootstrapNodeAdminUser(engineCore, context, envVars, features);\n\t\tawait bootstrapAuth(engineCore, context, envVars, features);\n\t\tawait bootstrapBlobEncryption(engineCore, context, envVars, features);\n\n\t\tconst defaultAttestationConnectorType =\n\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"attestationConnector\");\n\t\tif (\n\t\t\t!Is.empty(defaultAttestationConnectorType) &&\n\t\t\tIs.stringValue(context.state.nodeOrganizationId)\n\t\t) {\n\t\t\tawait addVerificationMethod(\n\t\t\t\tengineCore,\n\t\t\t\tcontext,\n\t\t\t\tcontext.state.nodeOrganizationId,\n\t\t\t\t\"attestation\",\n\t\t\t\tenvVars.attestationVerificationMethodId ?? ATTESTATION_VERIFICATION_METHOD_ID\n\t\t\t);\n\t\t}\n\n\t\tconst defaultImmutableProofComponentType =\n\t\t\tengineCore.getRegisteredInstanceTypeOptional(\"immutableProofComponent\");\n\n\t\tif (\n\t\t\t!Is.empty(defaultImmutableProofComponentType) &&\n\t\t\tIs.stringValue(context.state.nodeOrganizationId)\n\t\t) {\n\t\t\tawait addVerificationMethod(\n\t\t\t\tengineCore,\n\t\t\t\tcontext,\n\t\t\t\tcontext.state.nodeOrganizationId,\n\t\t\t\t\"immutable proof\",\n\t\t\t\tenvVars.immutableProofVerificationMethodId ?? IMMUTABLE_PROOF_VERIFICATION_METHOD_ID\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\t(Coerce.boolean(envVars.vcAuthenticationEnabled) ?? false) &&\n\t\t\tIs.stringValue(context.state.nodeId)\n\t\t) {\n\t\t\tawait addVerificationMethod(\n\t\t\t\tengineCore,\n\t\t\t\tcontext,\n\t\t\t\tcontext.state.nodeId,\n\t\t\t\t\"verifiable credential authentication\",\n\t\t\t\tenvVars.vcAuthenticationVerificationMethodId ?? VC_AUTHENTICATION_VERIFICATION_METHOD_ID\n\t\t\t);\n\t\t}\n\n\t\tawait bootstrapSynchronisedStorage(engineCore, context, envVars, features);\n\t});\n}\n\n/**\n * Bootstrap the node creating any necessary resources.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param envVars The environment variables for the node.\n * @param features The features that are enabled on the node. The features that are enabled on the node.\n */\nexport async function bootstrapNodeId(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tfeatures: NodeFeatures[]\n): Promise<void> {\n\tif (features.includes(NodeFeatures.NodeId)) {\n\t\tconst existingNodeId = envVars.nodeIdentity ?? context.state.nodeId;\n\n\t\tcontext.state.nodeId = await createIdentity(\n\t\t\tengineCore,\n\t\t\tenvVars,\n\t\t\texistingNodeId,\n\t\t\tenvVars.nodeMnemonic,\n\t\t\texistingNodeId,\n\t\t\t\"node\",\n\t\t\tfeatures.includes(NodeFeatures.NodeWallet)\n\t\t);\n\t\tcontext.stateDirty = true;\n\n\t\tengineCore.logInfo(\n\t\t\tI18n.formatMessage(\"node.nodeId\", {\n\t\t\t\tidentity: context.state.nodeId\n\t\t\t})\n\t\t);\n\n\t\tengineCore.addContextId(ContextIdKeys.Node, context.state.nodeId);\n\t}\n}\n\n/**\n * Bootstrap the node creating any necessary resources.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param envVars The environment variables for the node.\n * @param features The features that are enabled on the node. The features that are enabled on the node.\n */\nexport async function bootstrapTenantId(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tfeatures: NodeFeatures[]\n): Promise<void> {\n\t// If tenants are enabled we need to add a context id for the node\n\t// so that services such a logging have a default tenant context id\n\t// this will get overwritten by any incoming API requests with the tenant context id\n\tif (Coerce.boolean(envVars.tenantEnabled) ?? false) {\n\t\tlet tenantId = envVars.tenantId ?? context.state.nodeTenantId;\n\n\t\tif (!Is.stringValue(tenantId)) {\n\t\t\tconst tenantAdminServiceComponentType =\n\t\t\t\tengineCore.getRegisteredInstanceType(\"tenantAdminComponent\");\n\n\t\t\tconst tenantAdminService = ComponentFactory.get<ITenantAdminComponent>(\n\t\t\t\ttenantAdminServiceComponentType\n\t\t\t);\n\n\t\t\ttenantId = TenantIdHelper.generateTenantId();\n\t\t\tconst apiKey = envVars.tenantApiKey ?? TenantIdHelper.generateApiKey();\n\n\t\t\tawait tenantAdminService.set({\n\t\t\t\tid: tenantId,\n\t\t\t\tapiKey,\n\t\t\t\tdateCreated: new Date(Date.now()).toISOString(),\n\t\t\t\tlabel: \"node-tenant\"\n\t\t\t});\n\n\t\t\tengineCore.logInfo(\n\t\t\t\tI18n.formatMessage(\"node.createdTenantId\", {\n\t\t\t\t\tidentity: tenantId,\n\t\t\t\t\tapiKey\n\t\t\t\t})\n\t\t\t);\n\t\t} else {\n\t\t\tengineCore.logInfo(\n\t\t\t\tI18n.formatMessage(\"node.existingTenantId\", {\n\t\t\t\t\tidentity: context.state.nodeTenantId\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\n\t\tcontext.state.nodeTenantId = tenantId;\n\t\tcontext.stateDirty = true;\n\n\t\tengineCore.addContextId(ContextIdKeys.Tenant, context.state.nodeTenantId);\n\t}\n}\n\n/**\n * Bootstrap the user.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param envVars The environment variables for the node.\n * @param features The features that are enabled on the node.\n */\nexport async function bootstrapNodeAdminUser(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tfeatures: NodeFeatures[]\n): Promise<void> {\n\tif (features.includes(NodeFeatures.NodeAdminUser)) {\n\t\tcontext.state.nodeOrganizationId =\n\t\t\tenvVars.organizationIdentity ?? context.state.nodeOrganizationId;\n\t\tcontext.state.nodeAdminUserId = envVars.adminUserIdentity ?? context.state.nodeAdminUserId;\n\n\t\tconst defaultAuthenticationComponentType =\n\t\t\tengineCore.getRegisteredInstanceType(\"authenticationComponent\");\n\t\tif (\n\t\t\tdefaultAuthenticationComponentType.startsWith(AuthenticationComponentType.EntityStorage) &&\n\t\t\tIs.stringValue(context.state.nodeId)\n\t\t) {\n\t\t\tconst authUserEntityStorage =\n\t\t\t\tEntityStorageConnectorFactory.get<IEntityStorageConnector<AuthenticationUser>>(\n\t\t\t\t\tnameofKebabCase<AuthenticationUser>()\n\t\t\t\t);\n\n\t\t\tconst existingOrganizationId =\n\t\t\t\tenvVars.organizationIdentity ?? context.state.nodeOrganizationId;\n\n\t\t\tconst orgId = await createIdentity(\n\t\t\t\tengineCore,\n\t\t\t\tenvVars,\n\t\t\t\texistingOrganizationId,\n\t\t\t\tenvVars.organizationMnemonic,\n\t\t\t\texistingOrganizationId,\n\t\t\t\t\"organization\",\n\t\t\t\tfeatures.includes(NodeFeatures.NodeWallet)\n\t\t\t);\n\t\t\tif (context.state.nodeOrganizationId !== orgId) {\n\t\t\t\tcontext.state.nodeOrganizationId = orgId;\n\t\t\t\tcontext.stateDirty = true;\n\t\t\t}\n\n\t\t\tconst userId = await createIdentity(\n\t\t\t\tengineCore,\n\t\t\t\tenvVars,\n\t\t\t\tcontext.state.nodeAdminUserId,\n\t\t\t\tenvVars.adminUserMnemonic,\n\t\t\t\tcontext.state.nodeOrganizationId,\n\t\t\t\t\"user\",\n\t\t\t\tfalse\n\t\t\t);\n\t\t\tif (context.state.nodeAdminUserId !== userId) {\n\t\t\t\tcontext.state.nodeAdminUserId = userId;\n\t\t\t\tcontext.stateDirty = true;\n\t\t\t}\n\n\t\t\tconst adminEmail = envVars.adminUserName ?? DEFAULT_NODE_ADMIN_USERNAME;\n\n\t\t\tlet nodeAdminUser = await authUserEntityStorage.get(adminEmail);\n\n\t\t\t// If the node admin user doesn't exist, create it\n\t\t\tif (Is.empty(nodeAdminUser)) {\n\t\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.creatingUser\", { email: adminEmail }));\n\n\t\t\t\tconst generatedPassword = envVars.adminUserPassword ?? PasswordGenerator.generate(16);\n\t\t\t\tconst passwordBytes = Converter.utf8ToBytes(generatedPassword);\n\t\t\t\tconst saltBytes = RandomHelper.generate(16);\n\t\t\t\tconst hashedPassword = await PasswordHelper.hashPassword(passwordBytes, saltBytes);\n\n\t\t\t\tnodeAdminUser = {\n\t\t\t\t\temail: adminEmail,\n\t\t\t\t\tpassword: hashedPassword,\n\t\t\t\t\tsalt: Converter.bytesToBase64(saltBytes),\n\t\t\t\t\tidentity: context.state.nodeAdminUserId,\n\t\t\t\t\torganization: context.state.nodeOrganizationId\n\t\t\t\t};\n\n\t\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.nodeAdminUserEmail\", { email: adminEmail }));\n\n\t\t\t\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\t\t\t\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\t\t\t\tconst vaultKey = `${context.state.nodeAdminUserId}/admin-password`;\n\t\t\t\tawait vaultConnector.setSecret<string>(vaultKey, generatedPassword);\n\n\t\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.nodeAdminUserPassword\", { vaultKey }));\n\n\t\t\t\tawait authUserEntityStorage.set(nodeAdminUser);\n\t\t\t} else {\n\t\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.existingUser\", { email: adminEmail }));\n\n\t\t\t\t// The user already exists, so double check the other details match\n\t\t\t\tlet needsUpdate = false;\n\n\t\t\t\tif (nodeAdminUser.identity !== context.state.nodeAdminUserId) {\n\t\t\t\t\tnodeAdminUser.identity = context.state.nodeAdminUserId;\n\t\t\t\t\tneedsUpdate = true;\n\t\t\t\t}\n\n\t\t\t\tif (Is.stringValue(envVars.adminUserPassword)) {\n\t\t\t\t\tconst passwordBytes = Converter.utf8ToBytes(envVars.adminUserPassword);\n\t\t\t\t\tconst saltBytes = Converter.base64ToBytes(nodeAdminUser.salt);\n\t\t\t\t\tconst hashedPassword = await PasswordHelper.hashPassword(passwordBytes, saltBytes);\n\n\t\t\t\t\tif (nodeAdminUser.password !== hashedPassword) {\n\t\t\t\t\t\tnodeAdminUser.password = hashedPassword;\n\t\t\t\t\t\tneedsUpdate = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (needsUpdate) {\n\t\t\t\t\tawait authUserEntityStorage.set(nodeAdminUser);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// We have create a node user, now we need to create a profile for the user\n\t\t\tconst defaultIdentityProfileConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\t\t\"identityProfileConnector\"\n\t\t\t);\n\t\t\tconst identityProfileConnector = IdentityProfileConnectorFactory.get(\n\t\t\t\tdefaultIdentityProfileConnectorType\n\t\t\t);\n\n\t\t\tif (identityProfileConnector) {\n\t\t\t\t// Add the organization context id when creating the profile\n\t\t\t\t// so that it is partitioned under the organization\n\t\t\t\tconst contextIds = (await ContextIdStore.getContextIds()) ?? {};\n\t\t\t\tcontextIds[ContextIdKeys.Organization] = context.state.nodeOrganizationId;\n\t\t\t\tawait ContextIdStore.run(contextIds, async () => {\n\t\t\t\t\tlet userProfile;\n\t\t\t\t\tif (Is.stringValue(nodeAdminUser.identity)) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tuserProfile = await identityProfileConnector.get(nodeAdminUser.identity);\n\t\t\t\t\t\t} catch {}\n\t\t\t\t\t}\n\t\t\t\t\tif (Is.empty(userProfile)) {\n\t\t\t\t\t\tengineCore.logInfo(\n\t\t\t\t\t\t\tI18n.formatMessage(\"node.creatingUserProfile\", {\n\t\t\t\t\t\t\t\tidentity: nodeAdminUser.identity\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tconst publicProfile: WithContext<Person> = {\n\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\tname: \"Node Administrator\"\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst privateProfile: WithContext<Person> = {\n\t\t\t\t\t\t\t\"@context\": \"https://schema.org\",\n\t\t\t\t\t\t\t\"@type\": \"Person\",\n\t\t\t\t\t\t\tgivenName: \"Node\",\n\t\t\t\t\t\t\tfamilyName: \"Administrator\",\n\t\t\t\t\t\t\temail: adminEmail\n\t\t\t\t\t\t};\n\t\t\t\t\t\tawait identityProfileConnector.create(\n\t\t\t\t\t\t\tnodeAdminUser.identity,\n\t\t\t\t\t\t\tpublicProfile,\n\t\t\t\t\t\t\tprivateProfile\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tengineCore.logInfo(\n\t\t\t\t\t\t\tI18n.formatMessage(\"node.existingUserProfile\", {\n\t\t\t\t\t\t\t\tidentity: nodeAdminUser.identity\n\t\t\t\t\t\t\t})\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\n/**\n * Bootstrap the immutable proof verification methods.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param envVars The environment variables for the node.\n * @param features The features that are enabled on the node.\n */\nexport async function bootstrapImmutableProofMethod(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tfeatures: NodeFeatures[]\n): Promise<void> {}\n\n/**\n * Bootstrap the keys for blob encryption.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param envVars The environment variables for the node.\n * @param features The features that are enabled on the node.\n */\nexport async function bootstrapBlobEncryption(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tfeatures: NodeFeatures[]\n): Promise<void> {\n\tif (\n\t\t(Coerce.boolean(envVars.blobStorageEnableEncryption) ?? false) &&\n\t\tIs.stringValue(context.state.nodeOrganizationId)\n\t) {\n\t\t// Create a new key for encrypting blobs\n\t\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\t\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\t\tconst keyName = `${context.state.nodeOrganizationId}/${envVars.blobStorageEncryptionKeyId ?? BLOB_STORAGE_ENCRYPTION_KEY_ID}`;\n\n\t\tlet existingKey;\n\n\t\ttry {\n\t\t\texistingKey = await vaultConnector.getKey(keyName);\n\t\t} catch {}\n\n\t\tif (Is.empty(existingKey)) {\n\t\t\tif (Is.stringBase64(envVars.blobStorageSymmetricEncryptionKey)) {\n\t\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.addingBlobEncryptionKey\", { keyName }));\n\t\t\t\tawait vaultConnector.addKey(\n\t\t\t\t\tkeyName,\n\t\t\t\t\tVaultKeyType.ChaCha20Poly1305,\n\t\t\t\t\tConverter.base64ToBytes(envVars.blobStorageSymmetricEncryptionKey)\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.creatingBlobEncryptionKey\", { keyName }));\n\t\t\t\tconst key = await vaultConnector.createKey(keyName, VaultKeyType.ChaCha20Poly1305);\n\t\t\t\tengineCore.logInfo(\n\t\t\t\t\tI18n.formatMessage(\"node.createdBlobEncryptionKey\", {\n\t\t\t\t\t\tkeyName,\n\t\t\t\t\t\tkeyValue: Converter.bytesToBase64(key)\n\t\t\t\t\t})\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.existingBlobEncryptionKey\", { keyName }));\n\t\t}\n\t}\n}\n\n/**\n * Bootstrap the JWT signing key.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param envVars The environment variables for the node.\n * @param features The features that are enabled on the node.\n */\nexport async function bootstrapAuth(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tfeatures: NodeFeatures[]\n): Promise<void> {\n\tconst defaultAuthenticationComponentType =\n\t\tengineCore.getRegisteredInstanceTypeOptional(\"authenticationComponent\");\n\tif (\n\t\tIs.stringValue(defaultAuthenticationComponentType) &&\n\t\tdefaultAuthenticationComponentType.startsWith(AuthenticationComponentType.EntityStorage) &&\n\t\tIs.stringValue(context.state.nodeId)\n\t) {\n\t\t// Create a new JWT signing key and a user login for the node\n\t\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\t\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\t\tconst keyName = `${context.state.nodeId}/${envVars.authSigningKeyId ?? AUTH_SIGNING_KEY_ID}`;\n\n\t\tlet existingKey;\n\t\ttry {\n\t\t\texistingKey = await vaultConnector.getKey(keyName);\n\t\t} catch {}\n\n\t\tif (Is.empty(existingKey)) {\n\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.creatingAuthKey\", { keyName }));\n\t\t\tawait vaultConnector.createKey(keyName, VaultKeyType.Ed25519);\n\t\t} else {\n\t\t\tengineCore.logInfo(I18n.formatMessage(\"node.existingAuthKey\", { keyName }));\n\t\t}\n\t}\n}\n\n/**\n * Bootstrap the synchronised storage blob encryption and verification methods.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param envVars The environment variables for the node.\n * @param features The features that are enabled on the node.\n */\nexport async function bootstrapSynchronisedStorage(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tenvVars: INodeEnvironmentVariables,\n\tfeatures: NodeFeatures[]\n): Promise<void> {\n\tif (Coerce.boolean(envVars.synchronisedStorageEnabled) ?? false) {\n\t\t// If this is a trusted node we need to add the blob encryption key pair\n\t\tif (Is.stringBase64(envVars.synchronisedStorageBlobStorageKey)) {\n\t\t\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\t\t\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\t\t\tconst keyName =\n\t\t\t\tenvVars.synchronisedStorageBlobStorageEncryptionKeyId ??\n\t\t\t\tSYNCHRONISED_STORAGE_BLOB_STORAGE_ENCRYPTION_KEY_ID;\n\t\t\tlet existingKey;\n\n\t\t\ttry {\n\t\t\t\texistingKey = await vaultConnector.getKey(keyName);\n\t\t\t} catch {}\n\n\t\t\tif (Is.empty(existingKey)) {\n\t\t\t\tengineCore.logInfo(\n\t\t\t\t\tI18n.formatMessage(\"node.addingSynchronisedStorageBlobEncryptionKey\", { keyName })\n\t\t\t\t);\n\t\t\t\tawait vaultConnector.addKey(\n\t\t\t\t\tkeyName,\n\t\t\t\t\tVaultKeyType.ChaCha20Poly1305,\n\t\t\t\t\tConverter.base64ToBytes(envVars.synchronisedStorageBlobStorageKey)\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tengineCore.logInfo(\n\t\t\t\t\tI18n.formatMessage(\"node.existingSynchronisedStorageBlobEncryptionKey\", { keyName })\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Add a verification method if it doesn't exist.\n * @param engineCore The engine core for the node.\n * @param context The context for the node.\n * @param identity The identity to add the verification method to.\n * @param verificationMethodTitle The verification method title.\n * @param verificationMethodId The verification method ID.\n */\nasync function addVerificationMethod(\n\tengineCore: IEngineCore,\n\tcontext: IEngineCoreContext<IEngineServerConfig, INodeEngineState>,\n\tidentity: string,\n\tverificationMethodTitle: string,\n\tverificationMethodId: string | undefined\n): Promise<void> {\n\tif (\n\t\tIs.stringValue(identity) &&\n\t\tIs.arrayValue(context.config.types.identityConnector) &&\n\t\tIs.stringValue(verificationMethodId)\n\t) {\n\t\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\t\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\t\tconst defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\t\"identityResolverConnector\"\n\t\t);\n\t\tconst identityResolverConnector = IdentityResolverConnectorFactory.get(\n\t\t\tdefaultIdentityResolverConnectorType\n\t\t);\n\n\t\tconst identityDocument = await identityResolverConnector.resolveDocument(identity);\n\n\t\tconst fullMethodId = `${identityDocument.id}#${verificationMethodId}`;\n\n\t\tlet exists = false;\n\t\ttry {\n\t\t\tDocumentHelper.getVerificationMethod(identityDocument, fullMethodId, \"assertionMethod\");\n\t\t\texists = true;\n\t\t} catch {}\n\n\t\tif (!exists) {\n\t\t\tengineCore.logInfo(\n\t\t\t\tI18n.formatMessage(\"node.addingVerificationMethod\", {\n\t\t\t\t\ttitle: verificationMethodTitle,\n\t\t\t\t\tmethodId: fullMethodId\n\t\t\t\t})\n\t\t\t);\n\t\t\tawait identityConnector.addVerificationMethod(\n\t\t\t\tidentity,\n\t\t\t\tidentity,\n\t\t\t\t\"assertionMethod\",\n\t\t\t\tverificationMethodId\n\t\t\t);\n\t\t} else {\n\t\t\tengineCore.logInfo(\n\t\t\t\tI18n.formatMessage(\"node.existingVerificationMethod\", {\n\t\t\t\t\ttitle: verificationMethodTitle,\n\t\t\t\t\tmethodId: fullMethodId\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t}\n}\n"]}