@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
@@ -1,182 +0,0 @@
1
- // Copyright 2024 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
- import { Converter, I18n, Is, RandomHelper, StringHelper, Urn } from "@twin.org/core";
4
- import { Bip39 } from "@twin.org/crypto";
5
- import { IdentityConnectorType, WalletConnectorType } from "@twin.org/engine-types";
6
- import { EntityStorageConnectorFactory } from "@twin.org/entity-storage-models";
7
- import { IdentityConnectorFactory, IdentityResolverConnectorFactory } from "@twin.org/identity-models";
8
- import { VaultConnectorFactory } from "@twin.org/vault-models";
9
- import { WalletConnectorFactory } from "@twin.org/wallet-models";
10
- /**
11
- * Generate an identity and fund it.
12
- * @param engineCore The engine core for the node.
13
- * @param envVars The environment variables for the node.
14
- * @param configIdentity A identity from config to use.
15
- * @param configMnemonic A mnemonic from config to use.
16
- * @param controller The controller for the identity.
17
- * @param identityType The type of identity.
18
- * @param addWallet Whether to add a wallet for the identity.
19
- * @returns The identity that was generated.
20
- */
21
- export async function createIdentity(engineCore, envVars, configIdentity, configMnemonic, controller, identityType, addWallet) {
22
- engineCore.logInfo(I18n.formatMessage("node.processingIdentity", { identityType }));
23
- // We have a chicken and egg problem in that we can't create the identity
24
- // to store the mnemonic in the vault without an identity. We use a temporary identity
25
- // and then replace it with the new identity later in the process.
26
- const defaultVaultConnectorType = engineCore.getRegisteredInstanceType("vaultConnector");
27
- const vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);
28
- const workingIdentity = configIdentity ?? `bootstrap-temp-${Converter.bytesToHex(RandomHelper.generate(16))}`;
29
- const workingController = controller ?? workingIdentity;
30
- const mnemonicStored = await bootstrapMnemonic(engineCore, vaultConnector, workingIdentity, configMnemonic);
31
- const addresses = addWallet ? await generateWallet(engineCore, envVars, workingIdentity) : [];
32
- const finalIdentity = await generateIdentity(engineCore, envVars, workingController, workingIdentity, identityType);
33
- if (mnemonicStored) {
34
- engineCore.logInfo(I18n.formatMessage("node.finalMnemonic", { vaultKey: `${finalIdentity}/mnemonic` }));
35
- }
36
- await finaliseWallet(engineCore, envVars, finalIdentity, addresses);
37
- await finaliseMnemonic(vaultConnector, workingIdentity, finalIdentity);
38
- return finalIdentity;
39
- }
40
- /**
41
- * Generate a mnemonic for the node identity.
42
- * @param engineCore The engine core for the node.
43
- * @param vaultConnector The vault connector to use.
44
- * @param identity The identity of the node.
45
- * @param existingMnemonic An existing mnemonic to use.
46
- * @returns Whether the mnemonic was stored.
47
- */
48
- async function bootstrapMnemonic(engineCore, vaultConnector, identity, existingMnemonic) {
49
- let mnemonic = existingMnemonic;
50
- let storeMnemonic = false;
51
- const mnemonicKey = `${identity}/mnemonic`;
52
- try {
53
- const storedMnemonic = await vaultConnector.getSecret(mnemonicKey);
54
- if (Is.stringValue(storedMnemonic)) {
55
- storeMnemonic = storedMnemonic !== mnemonic && !Is.empty(mnemonic);
56
- mnemonic = storedMnemonic;
57
- }
58
- else {
59
- storeMnemonic = true;
60
- }
61
- }
62
- catch {
63
- storeMnemonic = true;
64
- }
65
- // If there is no mnemonic then we need to generate one
66
- if (Is.empty(mnemonic)) {
67
- mnemonic = Bip39.randomMnemonic();
68
- storeMnemonic = true;
69
- }
70
- // If there is no mnemonic stored in the vault then we need to store it
71
- if (storeMnemonic) {
72
- engineCore.logInfo(I18n.formatMessage("node.storingMnemonic"));
73
- await vaultConnector.setSecret(mnemonicKey, mnemonic);
74
- }
75
- else {
76
- engineCore.logInfo(I18n.formatMessage("node.existingMnemonic"));
77
- }
78
- return storeMnemonic;
79
- }
80
- /**
81
- * Finalise the mnemonic for the node identity.
82
- * @param vaultConnector The vault connector to use.
83
- * @param workingIdentity The identity of the node.
84
- * @param finalIdentity The final identity for the node.
85
- */
86
- async function finaliseMnemonic(vaultConnector, workingIdentity, finalIdentity) {
87
- // Now that we have an identity we can remove the temporary one
88
- // and store the mnemonic with the new identity
89
- if (workingIdentity.startsWith("bootstrap-temp-") && workingIdentity !== finalIdentity) {
90
- const mnemonic = await vaultConnector.getSecret(`${workingIdentity}/mnemonic`);
91
- await vaultConnector.setSecret(`${finalIdentity}/mnemonic`, mnemonic);
92
- await vaultConnector.removeSecret(`${workingIdentity}/mnemonic`);
93
- }
94
- }
95
- /**
96
- * Bootstrap the identity for the node.
97
- * @param engineCore The engine core for the node.
98
- * @param envVars The environment variables for the node.
99
- * @param finalIdentity The identity of the node.
100
- * @param addresses The addresses for the wallet.
101
- */
102
- async function finaliseWallet(engineCore, envVars, finalIdentity, addresses) {
103
- if (Is.arrayValue(addresses)) {
104
- const defaultWalletConnectorType = engineCore.getRegisteredInstanceType("walletConnector");
105
- // If we are using entity storage for wallet the identity associated with the
106
- // address will be wrong, so fix it
107
- if (defaultWalletConnectorType.startsWith(WalletConnectorType.EntityStorage)) {
108
- const walletAddress = EntityStorageConnectorFactory.get("wallet-address");
109
- const addr = await walletAddress.get(addresses[0]);
110
- if (!Is.empty(addr)) {
111
- addr.identity = finalIdentity;
112
- await walletAddress.set(addr);
113
- }
114
- }
115
- }
116
- }
117
- /**
118
- * Bootstrap the wallet for the node.
119
- * @param engineCore The engine core for the node.
120
- * @param envVars The environment variables for the node.
121
- * @param identity The identity to create the wallet for.
122
- * @returns The addresses for the wallet.
123
- */
124
- async function generateWallet(engineCore, envVars, identity) {
125
- const defaultWalletConnectorType = engineCore.getRegisteredInstanceType("walletConnector");
126
- const walletConnector = WalletConnectorFactory.get(defaultWalletConnectorType);
127
- const addresses = await walletConnector.getAddresses(identity, 0, 0, 5);
128
- const balance = await walletConnector.getBalance(identity, addresses[0]);
129
- if (balance === 0n) {
130
- let address0 = addresses[0];
131
- if (defaultWalletConnectorType.startsWith(WalletConnectorType.Iota) &&
132
- Is.stringValue(envVars.iotaExplorerEndpoint)) {
133
- address0 = `${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/address/${address0}?network=${envVars.iotaNetwork}`;
134
- }
135
- engineCore.logInfo(I18n.formatMessage("node.fundingWallet", { address: address0 }));
136
- // Add some funds to the wallet from the faucet
137
- await walletConnector.ensureBalance(identity, addresses[0], 1000000000n);
138
- }
139
- else {
140
- engineCore.logInfo(I18n.formatMessage("node.fundedWallet"));
141
- }
142
- return addresses;
143
- }
144
- /**
145
- * Bootstrap the identity for the node.
146
- * @param engineCore The engine core for the node.
147
- * @param envVars The environment variables for the node.
148
- * @param controller The controller for the identity.
149
- * @param identity The existing identity if there is one.
150
- * @param identityType The type of identity.
151
- * @returns The addresses for the wallet.
152
- */
153
- async function generateIdentity(engineCore, envVars, controller, identity, identityType) {
154
- const defaultIdentityConnectorType = engineCore.getRegisteredInstanceType("identityConnector");
155
- // Now create an identity for the node controlled by the address we just funded
156
- const identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);
157
- let identityDocument;
158
- try {
159
- const defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType("identityResolverConnector");
160
- const identityResolverConnector = IdentityResolverConnectorFactory.get(defaultIdentityResolverConnectorType);
161
- identityDocument = await identityResolverConnector.resolveDocument(identity);
162
- engineCore.logInfo(I18n.formatMessage("node.existingIdentity", { identity }));
163
- }
164
- catch { }
165
- if (Is.empty(identityDocument)) {
166
- engineCore.logInfo(I18n.formatMessage("node.generatingIdentity", { identityType }));
167
- identityDocument = await identityConnector.createDocument(controller);
168
- engineCore.logInfo(I18n.formatMessage("node.createdIdentity", { identity: identityDocument.id }));
169
- }
170
- if (defaultIdentityConnectorType.startsWith(IdentityConnectorType.Iota)) {
171
- const didUrn = Urn.fromValidString(identityDocument.id);
172
- const didParts = didUrn.parts();
173
- const objectId = didParts[3];
174
- if (Is.stringValue(envVars.iotaExplorerEndpoint)) {
175
- engineCore.logInfo(I18n.formatMessage("node.identityExplorer", {
176
- url: `${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/object/${objectId}?network=${envVars.iotaNetwork}`
177
- }));
178
- }
179
- }
180
- return identityDocument.id;
181
- }
182
- //# sourceMappingURL=identity.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/identity.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AACpF,OAAO,EACN,6BAA6B,EAE7B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACN,wBAAwB,EACxB,gCAAgC,EAChC,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAwB,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAErF,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAG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QAE7B,IAAI,EAAE,CAAC,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAClD,UAAU,CAAC,OAAO,CACjB,IAAI,CAAC,aAAa,CAAC,uBAAuB,EAAE;gBAC3C,GAAG,EAAE,GAAG,YAAY,CAAC,mBAAmB,CAAC,OAAO,CAAC,oBAAoB,CAAC,WAAW,QAAQ,YAAY,OAAO,CAAC,WAAW,EAAE;aAC1H,CAAC,CACF,CAAC;QACH,CAAC;IACF,CAAC;IACD,OAAO,gBAAgB,CAAC,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Converter, I18n, Is, RandomHelper, StringHelper, Urn } from \"@twin.org/core\";\nimport { Bip39 } from \"@twin.org/crypto\";\nimport type { IEngineCore } from \"@twin.org/engine-models\";\nimport { IdentityConnectorType, WalletConnectorType } from \"@twin.org/engine-types\";\nimport {\n\tEntityStorageConnectorFactory,\n\ttype IEntityStorageConnector\n} from \"@twin.org/entity-storage-models\";\nimport {\n\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 { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.js\";\n\n/**\n * Generate an identity and fund it.\n * @param engineCore The engine core for the node.\n * @param envVars The environment variables for the node.\n * @param configIdentity A identity from config to use.\n * @param configMnemonic A mnemonic from config to use.\n * @param controller The controller for the identity.\n * @param identityType The type of identity.\n * @param addWallet Whether to add a wallet for the identity.\n * @returns The identity that was generated.\n */\nexport async function createIdentity(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tconfigIdentity: string | undefined,\n\tconfigMnemonic: string | undefined,\n\tcontroller: string | undefined,\n\tidentityType: \"node\" | \"organization\" | \"user\",\n\taddWallet: boolean\n): Promise<string> {\n\tengineCore.logInfo(I18n.formatMessage(\"node.processingIdentity\", { identityType }));\n\n\t// We have a chicken and egg problem in that we can't create the identity\n\t// to store the mnemonic in the vault without an identity. We use a temporary identity\n\t// and then replace it with the new identity later in the process.\n\tconst defaultVaultConnectorType = engineCore.getRegisteredInstanceType(\"vaultConnector\");\n\tconst vaultConnector = VaultConnectorFactory.get(defaultVaultConnectorType);\n\n\tconst workingIdentity =\n\t\tconfigIdentity ?? `bootstrap-temp-${Converter.bytesToHex(RandomHelper.generate(16))}`;\n\tconst workingController = controller ?? workingIdentity;\n\n\tconst mnemonicStored = await bootstrapMnemonic(\n\t\tengineCore,\n\t\tvaultConnector,\n\t\tworkingIdentity,\n\t\tconfigMnemonic\n\t);\n\n\tconst addresses = addWallet ? await generateWallet(engineCore, envVars, workingIdentity) : [];\n\n\tconst finalIdentity = await generateIdentity(\n\t\tengineCore,\n\t\tenvVars,\n\t\tworkingController,\n\t\tworkingIdentity,\n\t\tidentityType\n\t);\n\n\tif (mnemonicStored) {\n\t\tengineCore.logInfo(\n\t\t\tI18n.formatMessage(\"node.finalMnemonic\", { vaultKey: `${finalIdentity}/mnemonic` })\n\t\t);\n\t}\n\n\tawait finaliseWallet(engineCore, envVars, finalIdentity, addresses);\n\n\tawait finaliseMnemonic(vaultConnector, workingIdentity, finalIdentity);\n\n\treturn finalIdentity;\n}\n\n/**\n * Generate a mnemonic for the node identity.\n * @param engineCore The engine core for the node.\n * @param vaultConnector The vault connector to use.\n * @param identity The identity of the node.\n * @param existingMnemonic An existing mnemonic to use.\n * @returns Whether the mnemonic was stored.\n */\nasync function bootstrapMnemonic(\n\tengineCore: IEngineCore,\n\tvaultConnector: IVaultConnector,\n\tidentity: string,\n\texistingMnemonic?: string\n): Promise<boolean> {\n\tlet mnemonic = existingMnemonic;\n\tlet storeMnemonic = false;\n\n\tconst mnemonicKey = `${identity}/mnemonic`;\n\n\ttry {\n\t\tconst storedMnemonic = await vaultConnector.getSecret<string>(mnemonicKey);\n\t\tif (Is.stringValue(storedMnemonic)) {\n\t\t\tstoreMnemonic = storedMnemonic !== mnemonic && !Is.empty(mnemonic);\n\t\t\tmnemonic = storedMnemonic;\n\t\t} else {\n\t\t\tstoreMnemonic = true;\n\t\t}\n\t} catch {\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\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\tengineCore.logInfo(I18n.formatMessage(\"node.storingMnemonic\"));\n\t\tawait vaultConnector.setSecret(mnemonicKey, mnemonic);\n\t} else {\n\t\tengineCore.logInfo(I18n.formatMessage(\"node.existingMnemonic\"));\n\t}\n\n\treturn storeMnemonic;\n}\n\n/**\n * Finalise the mnemonic for the node identity.\n * @param vaultConnector The vault connector to use.\n * @param workingIdentity The identity of the node.\n * @param finalIdentity The final identity for the node.\n */\nasync function finaliseMnemonic(\n\tvaultConnector: IVaultConnector,\n\tworkingIdentity: string,\n\tfinalIdentity: 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 (workingIdentity.startsWith(\"bootstrap-temp-\") && workingIdentity !== finalIdentity) {\n\t\tconst mnemonic = await vaultConnector.getSecret(`${workingIdentity}/mnemonic`);\n\t\tawait vaultConnector.setSecret(`${finalIdentity}/mnemonic`, mnemonic);\n\t\tawait vaultConnector.removeSecret(`${workingIdentity}/mnemonic`);\n\t}\n}\n\n/**\n * Bootstrap the identity for the node.\n * @param engineCore The engine core for the node.\n * @param envVars The environment variables for the node.\n * @param finalIdentity The identity of the node.\n * @param addresses The addresses for the wallet.\n */\nasync function finaliseWallet(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tfinalIdentity: string,\n\taddresses: string[]\n): Promise<void> {\n\tif (Is.arrayValue(addresses)) {\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(addresses[0]);\n\t\t\tif (!Is.empty(addr)) {\n\t\t\t\taddr.identity = finalIdentity;\n\t\t\t\tawait walletAddress.set(addr);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Bootstrap the wallet for the node.\n * @param engineCore The engine core for the node.\n * @param envVars The environment variables for the node.\n * @param identity The identity to create the wallet for.\n * @returns The addresses for the wallet.\n */\nasync function generateWallet(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tidentity: string\n): Promise<string[]> {\n\tconst defaultWalletConnectorType = engineCore.getRegisteredInstanceType(\"walletConnector\");\n\n\tconst walletConnector = WalletConnectorFactory.get(defaultWalletConnectorType);\n\tconst addresses = await walletConnector.getAddresses(identity, 0, 0, 5);\n\n\tconst balance = await walletConnector.getBalance(identity, addresses[0]);\n\tif (balance === 0n) {\n\t\tlet address0 = addresses[0];\n\n\t\tif (\n\t\t\tdefaultWalletConnectorType.startsWith(WalletConnectorType.Iota) &&\n\t\t\tIs.stringValue(envVars.iotaExplorerEndpoint)\n\t\t) {\n\t\t\taddress0 = `${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/address/${address0}?network=${envVars.iotaNetwork}`;\n\t\t}\n\n\t\tengineCore.logInfo(I18n.formatMessage(\"node.fundingWallet\", { address: address0 }));\n\n\t\t// Add some funds to the wallet from the faucet\n\t\tawait walletConnector.ensureBalance(identity, addresses[0], 1000000000n);\n\t} else {\n\t\tengineCore.logInfo(I18n.formatMessage(\"node.fundedWallet\"));\n\t}\n\treturn addresses;\n}\n\n/**\n * Bootstrap the identity for the node.\n * @param engineCore The engine core for the node.\n * @param envVars The environment variables for the node.\n * @param controller The controller for the identity.\n * @param identity The existing identity if there is one.\n * @param identityType The type of identity.\n * @returns The addresses for the wallet.\n */\nasync function generateIdentity(\n\tengineCore: IEngineCore,\n\tenvVars: INodeEnvironmentVariables,\n\tcontroller: string,\n\tidentity: string,\n\tidentityType: \"node\" | \"organization\" | \"user\"\n): Promise<string> {\n\tconst defaultIdentityConnectorType = engineCore.getRegisteredInstanceType(\"identityConnector\");\n\n\t// Now create an identity for the node controlled by the address we just funded\n\tconst identityConnector = IdentityConnectorFactory.get(defaultIdentityConnectorType);\n\n\tlet identityDocument;\n\n\ttry {\n\t\tconst defaultIdentityResolverConnectorType = engineCore.getRegisteredInstanceType(\n\t\t\t\"identityResolverConnector\"\n\t\t);\n\n\t\tconst identityResolverConnector = IdentityResolverConnectorFactory.get(\n\t\t\tdefaultIdentityResolverConnectorType\n\t\t);\n\t\tidentityDocument = await identityResolverConnector.resolveDocument(identity);\n\t\tengineCore.logInfo(I18n.formatMessage(\"node.existingIdentity\", { identity }));\n\t} catch {}\n\n\tif (Is.empty(identityDocument)) {\n\t\tengineCore.logInfo(I18n.formatMessage(\"node.generatingIdentity\", { identityType }));\n\n\t\tidentityDocument = await identityConnector.createDocument(controller);\n\n\t\tengineCore.logInfo(\n\t\t\tI18n.formatMessage(\"node.createdIdentity\", { identity: identityDocument.id })\n\t\t);\n\t}\n\n\tif (defaultIdentityConnectorType.startsWith(IdentityConnectorType.Iota)) {\n\t\tconst didUrn = Urn.fromValidString(identityDocument.id);\n\t\tconst didParts = didUrn.parts();\n\t\tconst objectId = didParts[3];\n\n\t\tif (Is.stringValue(envVars.iotaExplorerEndpoint)) {\n\t\t\tengineCore.logInfo(\n\t\t\t\tI18n.formatMessage(\"node.identityExplorer\", {\n\t\t\t\t\turl: `${StringHelper.trimTrailingSlashes(envVars.iotaExplorerEndpoint)}/object/${objectId}?network=${envVars.iotaNetwork}`\n\t\t\t\t})\n\t\t\t);\n\t\t}\n\t}\n\treturn identityDocument.id;\n}\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=nodeExtensionMethods.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodeExtensionMethods.js","sourceRoot":"","sources":["../../../src/models/nodeExtensionMethods.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IEngineCore, IEngineServer } from \"@twin.org/engine-models\";\nimport type { INodeEngineConfig } from \"./INodeEngineConfig.js\";\nimport type { INodeEnvironmentVariables } from \"./INodeEnvironmentVariables.js\";\n\n/**\n * The type for the initialise method of an extension module.\n * @param envVars The environment variables for the node.\n * @param nodeEngineConfig The node engine config.\n */\nexport type NodeExtensionInitialiseMethod = (\n\tenvVars: INodeEnvironmentVariables,\n\tnodeEngineConfig: INodeEngineConfig\n) => Promise<void>;\n\n/**\n * The type for the initialise engine method of an extension module.\n * This is called when the engine has been constructed but not yet started.\n * @param engineCore The engine core instance.\n */\nexport type NodeExtensionInitialiseEngineMethod = (engineCore: IEngineCore) => Promise<void>;\n\n/**\n * The type for the initialise engine server method of an extension module.\n * This is called when the engine server has been constructed but not yet started.\n * @param engineCore The engine core instance.\n * @param engineServer The engine server instance.\n */\nexport type NodeExtensionInitialiseEngineServerMethod = (\n\tengineCore: IEngineCore,\n\tengineServer: IEngineServer\n) => Promise<void>;\n\n/**\n * The type for the shutdown method of an extension module.\n * This is called when the engine is shutting down.\n */\nexport type NodeExtensionShutdownMethod = () => Promise<void>;\n"]}
@@ -1,21 +0,0 @@
1
- // Copyright 2024 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
- /**
4
- * The features that can be enabled on the node.
5
- */
6
- // eslint-disable-next-line @typescript-eslint/naming-convention
7
- export const NodeFeatures = {
8
- /**
9
- * NodeId - generates an identity for the node if not provided in config.
10
- */
11
- NodeId: "node-identity",
12
- /**
13
- * NodeAdminUser - generates an admin user for the node if not provided in config.
14
- */
15
- NodeAdminUser: "node-admin-user",
16
- /**
17
- * NodeWallet - generates wallets for any identities that need them.
18
- */
19
- NodeWallet: "node-wallet"
20
- };
21
- //# sourceMappingURL=nodeFeatures.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"nodeFeatures.js","sourceRoot":"","sources":["../../../src/models/nodeFeatures.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,YAAY,GAAG;IAC3B;;OAEG;IACH,MAAM,EAAE,eAAe;IAEvB;;OAEG;IACH,aAAa,EAAE,iBAAiB;IAEhC;;OAEG;IACH,UAAU,EAAE,aAAa;CAChB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The features that can be enabled on the node.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const NodeFeatures = {\n\t/**\n\t * NodeId - generates an identity for the node if not provided in config.\n\t */\n\tNodeId: \"node-identity\",\n\n\t/**\n\t * NodeAdminUser - generates an admin user for the node if not provided in config.\n\t */\n\tNodeAdminUser: \"node-admin-user\",\n\n\t/**\n\t * NodeWallet - generates wallets for any identities that need them.\n\t */\n\tNodeWallet: \"node-wallet\"\n} as const;\n\n/**\n * The features that can be enabled on the node.\n */\nexport type NodeFeatures = (typeof NodeFeatures)[keyof typeof NodeFeatures];\n"]}
package/dist/es/server.js DELETED
@@ -1,81 +0,0 @@
1
- // Copyright 2024 IOTA Stiftung.
2
- // SPDX-License-Identifier: Apache-2.0.
3
- import { GeneralError, I18n, Is } from "@twin.org/core";
4
- import { Engine } from "@twin.org/engine";
5
- import { FileStateStorage } from "@twin.org/engine-core";
6
- import { EngineCoreFactory } from "@twin.org/engine-models";
7
- import { EngineServer } from "@twin.org/engine-server";
8
- import { BlobStorageConnectorType, EntityStorageConnectorType } from "@twin.org/engine-types";
9
- import { bootstrap } from "./bootstrap.js";
10
- import { extensionsInitialiseEngine, extensionsInitialiseEngineServer, shutdownExtensions } from "./builders/extensionsBuilder.js";
11
- let isStarted = false;
12
- /**
13
- * Start the engine server.
14
- * @param nodeOptions Optional run options for the engine server.
15
- * @param nodeEngineConfig The configuration for the engine server.
16
- * @param envVars The environment variables.
17
- * @param availableContextIdKeys The context ID keys available for operation.
18
- * @returns The engine server.
19
- */
20
- export async function start(nodeOptions, nodeEngineConfig, envVars, availableContextIdKeys) {
21
- const entityStorageConnectorType = envVars.entityStorageConnectorType?.split(",") ?? [];
22
- const blobStorageConnectorType = envVars.blobStorageConnectorType?.split(",") ?? [];
23
- // If the blob storage or entity storage is configured with file connectors
24
- // then we need to make sure the storageFileRoot is set
25
- if ((entityStorageConnectorType.includes(EntityStorageConnectorType.File) ||
26
- blobStorageConnectorType.includes(BlobStorageConnectorType.File) ||
27
- Is.empty(nodeOptions?.stateStorage)) &&
28
- !Is.stringValue(envVars.storageFileRoot)) {
29
- throw new GeneralError("node", "storageFileRootNotSet", {
30
- storageFileRoot: `${nodeOptions?.envPrefix ?? ""}STORAGE_FILE_ROOT`
31
- });
32
- }
33
- // Create the engine instance using file state storage unless one is configured in options
34
- const engine = new Engine({
35
- config: nodeEngineConfig,
36
- stateStorage: nodeOptions?.stateStorage ?? new FileStateStorage(envVars.stateFilename ?? ""),
37
- customBootstrap: async (core, engineContext) => bootstrap(core, engineContext, envVars)
38
- });
39
- if (Is.arrayValue(availableContextIdKeys)) {
40
- const added = [];
41
- for (const availableContextIdKey of availableContextIdKeys) {
42
- if (!added.includes(availableContextIdKey.key)) {
43
- engine.addContextIdKey(availableContextIdKey.key, availableContextIdKey.componentFeatures);
44
- added.push(availableContextIdKey.key);
45
- }
46
- }
47
- }
48
- // Construct the server with the engine.
49
- const server = new EngineServer({ engineCore: engine });
50
- // Extend the engine.
51
- if (Is.function(nodeOptions?.extendEngine)) {
52
- await engine.logInfo(I18n.formatMessage("node.extendingEngine"));
53
- await nodeOptions.extendEngine(engine);
54
- }
55
- await extensionsInitialiseEngine(envVars, engine);
56
- // Extend the engine server.
57
- if (Is.function(nodeOptions?.extendEngineServer)) {
58
- await engine.logInfo(I18n.formatMessage("node.extendingEngineServer"));
59
- await nodeOptions?.extendEngineServer(server);
60
- }
61
- await extensionsInitialiseEngineServer(envVars, engine, server);
62
- // Need to register the engine with the factory so that background tasks
63
- // can clone it to spawn new instances.
64
- EngineCoreFactory.register("engine", () => engine);
65
- // Start the server, which also starts the engine.
66
- isStarted = await server.start();
67
- if (isStarted) {
68
- return {
69
- engine,
70
- server,
71
- shutdown: async () => {
72
- if (isStarted) {
73
- isStarted = false;
74
- await shutdownExtensions(envVars, engine);
75
- await server.stop();
76
- }
77
- }
78
- };
79
- }
80
- }
81
- //# sourceMappingURL=server.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,EAAE,wBAAwB,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAC9F,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACN,0BAA0B,EAC1B,gCAAgC,EAChC,kBAAkB,EAClB,MAAM,iCAAiC,CAAC;AAMzC,IAAI,SAAS,G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ACN,QAAQ,EAAE,KAAK,IAAI,EAAE;gBACpB,IAAI,SAAS,EAAE,CAAC;oBACf,SAAS,GAAG,KAAK,CAAC;oBAClB,MAAM,kBAAkB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBAC1C,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBACrB,CAAC;YACF,CAAC;SACD,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, I18n, Is } from \"@twin.org/core\";\nimport { Engine } from \"@twin.org/engine\";\nimport { FileStateStorage } from \"@twin.org/engine-core\";\nimport { EngineCoreFactory } from \"@twin.org/engine-models\";\nimport { EngineServer } from \"@twin.org/engine-server\";\nimport type { IEngineServerConfig } from \"@twin.org/engine-server-types\";\nimport { BlobStorageConnectorType, EntityStorageConnectorType } from \"@twin.org/engine-types\";\nimport { bootstrap } from \"./bootstrap.js\";\nimport {\n\textensionsInitialiseEngine,\n\textensionsInitialiseEngineServer,\n\tshutdownExtensions\n} from \"./builders/extensionsBuilder.js\";\nimport type { INodeEngineConfig } from \"./models/INodeEngineConfig.js\";\nimport type { INodeEngineState } from \"./models/INodeEngineState.js\";\nimport type { INodeEnvironmentVariables } from \"./models/INodeEnvironmentVariables.js\";\nimport type { INodeOptions } from \"./models/INodeOptions.js\";\n\nlet isStarted = false;\n\n/**\n * Start the engine server.\n * @param nodeOptions Optional run options for the engine server.\n * @param nodeEngineConfig The configuration for the engine server.\n * @param envVars The environment variables.\n * @param availableContextIdKeys The context ID keys available for operation.\n * @returns The engine server.\n */\nexport async function start(\n\tnodeOptions: INodeOptions | undefined,\n\tnodeEngineConfig: INodeEngineConfig,\n\tenvVars: INodeEnvironmentVariables,\n\tavailableContextIdKeys?: { key: string; componentFeatures: string[] }[]\n): Promise<\n\t| {\n\t\t\tengine: Engine<IEngineServerConfig, INodeEngineState>;\n\t\t\tserver: EngineServer;\n\t\t\tshutdown: () => Promise<void>;\n\t }\n\t| undefined\n> {\n\tconst entityStorageConnectorType = envVars.entityStorageConnectorType?.split(\",\") ?? [];\n\tconst blobStorageConnectorType = envVars.blobStorageConnectorType?.split(\",\") ?? [];\n\n\t// If the blob storage or entity storage is configured with file connectors\n\t// then we need to make sure the storageFileRoot is set\n\tif (\n\t\t(entityStorageConnectorType.includes(EntityStorageConnectorType.File) ||\n\t\t\tblobStorageConnectorType.includes(BlobStorageConnectorType.File) ||\n\t\t\tIs.empty(nodeOptions?.stateStorage)) &&\n\t\t!Is.stringValue(envVars.storageFileRoot)\n\t) {\n\t\tthrow new GeneralError(\"node\", \"storageFileRootNotSet\", {\n\t\t\tstorageFileRoot: `${nodeOptions?.envPrefix ?? \"\"}STORAGE_FILE_ROOT`\n\t\t});\n\t}\n\n\t// Create the engine instance using file state storage unless one is configured in options\n\tconst engine = new Engine<IEngineServerConfig, INodeEngineState>({\n\t\tconfig: nodeEngineConfig,\n\t\tstateStorage: nodeOptions?.stateStorage ?? new FileStateStorage(envVars.stateFilename ?? \"\"),\n\t\tcustomBootstrap: async (core, engineContext) => bootstrap(core, engineContext, envVars)\n\t});\n\n\tif (Is.arrayValue(availableContextIdKeys)) {\n\t\tconst added: string[] = [];\n\t\tfor (const availableContextIdKey of availableContextIdKeys) {\n\t\t\tif (!added.includes(availableContextIdKey.key)) {\n\t\t\t\tengine.addContextIdKey(availableContextIdKey.key, availableContextIdKey.componentFeatures);\n\t\t\t\tadded.push(availableContextIdKey.key);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Construct the server with the engine.\n\tconst server = new EngineServer({ engineCore: engine });\n\n\t// Extend the engine.\n\tif (Is.function(nodeOptions?.extendEngine)) {\n\t\tawait engine.logInfo(I18n.formatMessage(\"node.extendingEngine\"));\n\t\tawait nodeOptions.extendEngine(engine);\n\t}\n\n\tawait extensionsInitialiseEngine(envVars, engine);\n\n\t// Extend the engine server.\n\tif (Is.function(nodeOptions?.extendEngineServer)) {\n\t\tawait engine.logInfo(I18n.formatMessage(\"node.extendingEngineServer\"));\n\t\tawait nodeOptions?.extendEngineServer(server);\n\t}\n\n\tawait extensionsInitialiseEngineServer(envVars, engine, server);\n\n\t// Need to register the engine with the factory so that background tasks\n\t// can clone it to spawn new instances.\n\tEngineCoreFactory.register(\"engine\", () => engine);\n\n\t// Start the server, which also starts the engine.\n\tisStarted = await server.start();\n\n\tif (isStarted) {\n\t\treturn {\n\t\t\tengine,\n\t\t\tserver,\n\t\t\tshutdown: async () => {\n\t\t\t\tif (isStarted) {\n\t\t\t\t\tisStarted = false;\n\t\t\t\t\tawait shutdownExtensions(envVars, engine);\n\t\t\t\t\tawait server.stop();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n}\n"]}
@@ -1,68 +0,0 @@
1
- import type { IEngineCore, IEngineCoreContext } from "@twin.org/engine-models";
2
- import { type IEngineServerConfig } from "@twin.org/engine-server-types";
3
- import type { INodeEngineState } from "./models/INodeEngineState.js";
4
- import type { INodeEnvironmentVariables } from "./models/INodeEnvironmentVariables.js";
5
- import { NodeFeatures } from "./models/nodeFeatures.js";
6
- /**
7
- * Bootstrap the application.
8
- * @param engineCore The engine core for the node.
9
- * @param context The context for the node.
10
- * @param envVars The environment variables for the node.
11
- */
12
- export declare function bootstrap(engineCore: IEngineCore, context: IEngineCoreContext<IEngineServerConfig, INodeEngineState>, envVars: INodeEnvironmentVariables): Promise<void>;
13
- /**
14
- * Bootstrap the node creating any necessary resources.
15
- * @param engineCore The engine core for the node.
16
- * @param context The context for the node.
17
- * @param envVars The environment variables for the node.
18
- * @param features The features that are enabled on the node. The features that are enabled on the node.
19
- */
20
- export declare function bootstrapNodeId(engineCore: IEngineCore, context: IEngineCoreContext<IEngineServerConfig, INodeEngineState>, envVars: INodeEnvironmentVariables, features: NodeFeatures[]): Promise<void>;
21
- /**
22
- * Bootstrap the node creating any necessary resources.
23
- * @param engineCore The engine core for the node.
24
- * @param context The context for the node.
25
- * @param envVars The environment variables for the node.
26
- * @param features The features that are enabled on the node. The features that are enabled on the node.
27
- */
28
- export declare function bootstrapTenantId(engineCore: IEngineCore, context: IEngineCoreContext<IEngineServerConfig, INodeEngineState>, envVars: INodeEnvironmentVariables, features: NodeFeatures[]): Promise<void>;
29
- /**
30
- * Bootstrap the user.
31
- * @param engineCore The engine core for the node.
32
- * @param context The context for the node.
33
- * @param envVars The environment variables for the node.
34
- * @param features The features that are enabled on the node.
35
- */
36
- export declare function bootstrapNodeAdminUser(engineCore: IEngineCore, context: IEngineCoreContext<IEngineServerConfig, INodeEngineState>, envVars: INodeEnvironmentVariables, features: NodeFeatures[]): Promise<void>;
37
- /**
38
- * Bootstrap the immutable proof verification methods.
39
- * @param engineCore The engine core for the node.
40
- * @param context The context for the node.
41
- * @param envVars The environment variables for the node.
42
- * @param features The features that are enabled on the node.
43
- */
44
- export declare function bootstrapImmutableProofMethod(engineCore: IEngineCore, context: IEngineCoreContext<IEngineServerConfig, INodeEngineState>, envVars: INodeEnvironmentVariables, features: NodeFeatures[]): Promise<void>;
45
- /**
46
- * Bootstrap the keys for blob encryption.
47
- * @param engineCore The engine core for the node.
48
- * @param context The context for the node.
49
- * @param envVars The environment variables for the node.
50
- * @param features The features that are enabled on the node.
51
- */
52
- export declare function bootstrapBlobEncryption(engineCore: IEngineCore, context: IEngineCoreContext<IEngineServerConfig, INodeEngineState>, envVars: INodeEnvironmentVariables, features: NodeFeatures[]): Promise<void>;
53
- /**
54
- * Bootstrap the JWT signing key.
55
- * @param engineCore The engine core for the node.
56
- * @param context The context for the node.
57
- * @param envVars The environment variables for the node.
58
- * @param features The features that are enabled on the node.
59
- */
60
- export declare function bootstrapAuth(engineCore: IEngineCore, context: IEngineCoreContext<IEngineServerConfig, INodeEngineState>, envVars: INodeEnvironmentVariables, features: NodeFeatures[]): Promise<void>;
61
- /**
62
- * Bootstrap the synchronised storage blob encryption and verification methods.
63
- * @param engineCore The engine core for the node.
64
- * @param context The context for the node.
65
- * @param envVars The environment variables for the node.
66
- * @param features The features that are enabled on the node.
67
- */
68
- export declare function bootstrapSynchronisedStorage(engineCore: IEngineCore, context: IEngineCoreContext<IEngineServerConfig, INodeEngineState>, envVars: INodeEnvironmentVariables, features: NodeFeatures[]): Promise<void>;
@@ -1,14 +0,0 @@
1
- import type { IEngineCore } from "@twin.org/engine-models";
2
- import type { INodeEnvironmentVariables } from "./models/INodeEnvironmentVariables.js";
3
- /**
4
- * Generate an identity and fund it.
5
- * @param engineCore The engine core for the node.
6
- * @param envVars The environment variables for the node.
7
- * @param configIdentity A identity from config to use.
8
- * @param configMnemonic A mnemonic from config to use.
9
- * @param controller The controller for the identity.
10
- * @param identityType The type of identity.
11
- * @param addWallet Whether to add a wallet for the identity.
12
- * @returns The identity that was generated.
13
- */
14
- export declare function createIdentity(engineCore: IEngineCore, envVars: INodeEnvironmentVariables, configIdentity: string | undefined, configMnemonic: string | undefined, controller: string | undefined, identityType: "node" | "organization" | "user", addWallet: boolean): Promise<string>;
@@ -1,27 +0,0 @@
1
- import type { IEngineCore, IEngineServer } from "@twin.org/engine-models";
2
- import type { INodeEngineConfig } from "./INodeEngineConfig.js";
3
- import type { INodeEnvironmentVariables } from "./INodeEnvironmentVariables.js";
4
- /**
5
- * The type for the initialise method of an extension module.
6
- * @param envVars The environment variables for the node.
7
- * @param nodeEngineConfig The node engine config.
8
- */
9
- export type NodeExtensionInitialiseMethod = (envVars: INodeEnvironmentVariables, nodeEngineConfig: INodeEngineConfig) => Promise<void>;
10
- /**
11
- * The type for the initialise engine method of an extension module.
12
- * This is called when the engine has been constructed but not yet started.
13
- * @param engineCore The engine core instance.
14
- */
15
- export type NodeExtensionInitialiseEngineMethod = (engineCore: IEngineCore) => Promise<void>;
16
- /**
17
- * The type for the initialise engine server method of an extension module.
18
- * This is called when the engine server has been constructed but not yet started.
19
- * @param engineCore The engine core instance.
20
- * @param engineServer The engine server instance.
21
- */
22
- export type NodeExtensionInitialiseEngineServerMethod = (engineCore: IEngineCore, engineServer: IEngineServer) => Promise<void>;
23
- /**
24
- * The type for the shutdown method of an extension module.
25
- * This is called when the engine is shutting down.
26
- */
27
- export type NodeExtensionShutdownMethod = () => Promise<void>;
@@ -1,21 +0,0 @@
1
- /**
2
- * The features that can be enabled on the node.
3
- */
4
- export declare const NodeFeatures: {
5
- /**
6
- * NodeId - generates an identity for the node if not provided in config.
7
- */
8
- readonly NodeId: "node-identity";
9
- /**
10
- * NodeAdminUser - generates an admin user for the node if not provided in config.
11
- */
12
- readonly NodeAdminUser: "node-admin-user";
13
- /**
14
- * NodeWallet - generates wallets for any identities that need them.
15
- */
16
- readonly NodeWallet: "node-wallet";
17
- };
18
- /**
19
- * The features that can be enabled on the node.
20
- */
21
- export type NodeFeatures = (typeof NodeFeatures)[keyof typeof NodeFeatures];
@@ -1,129 +0,0 @@
1
- # TWIN Node - Detailed Documentation
2
-
3
- ## Overview
4
-
5
- TWIN Node provides the foundational components for running TWIN nodes, including dynamic extension loading, protocol-based module resolution, and lifecycle management.
6
-
7
- ## Protocol-Based Extension Loading
8
-
9
- The TWIN Node supports dynamic extension loading from multiple sources:
10
-
11
- ### Local Files
12
-
13
- Load extensions from your filesystem:
14
-
15
- ```bash
16
- TWIN_EXTENSIONS="./my-extension.mjs"
17
- ```
18
-
19
- ### NPM Packages
20
-
21
- Automatically install and load npm packages:
22
-
23
- ```bash
24
- TWIN_EXTENSIONS="npm:@twin.org/package"
25
- ```
26
-
27
- ### HTTPS URLs
28
-
29
- Download and cache remote extensions:
30
-
31
- ```bash
32
- TWIN_EXTENSIONS="https://example.com/extension.mjs"
33
- ```
34
-
35
- ## Extension Lifecycle Hooks
36
-
37
- Extensions can implement lifecycle hooks to customize node behavior at different stages:
38
-
39
- - **`extensionInitialise`** - Called before engine initialization
40
- - **`extensionInitialiseEngine`** - Called during engine initialization
41
- - **`extensionInitialiseEngineServer`** - Called during server initialization
42
- - **`extensionShutdown`** - Called during graceful shutdown
43
-
44
- ### Example Extension
45
-
46
- ```javascript
47
- // my-extension.mjs
48
- export function extensionInitialise() {
49
- console.log('Extension initializing...');
50
- }
51
-
52
- export function extensionInitialiseEngine(engine) {
53
- console.log('Configuring engine...');
54
- // Add custom components, routes, etc.
55
- }
56
-
57
- export function extensionInitialiseEngineServer(server) {
58
- console.log('Configuring server...');
59
- // Add middleware, routes, etc.
60
- }
61
-
62
- export function extensionShutdown() {
63
- console.log('Extension shutting down...');
64
- // Cleanup resources
65
- }
66
- ```
67
-
68
- ## Configuration Options
69
-
70
- ### Cache Management
71
-
72
- - `TWIN_EXTENSIONS_CACHE_TTL_HOURS` - TTL for HTTPS extensions cache (default: 24)
73
- - `TWIN_EXTENSIONS_FORCE_REFRESH` - Force refresh all cached extensions (default: false)
74
- - `TWIN_EXTENSIONS_CACHE_DIRECTORY` - Custom cache directory (default: ".tmp")
75
-
76
- ### Security
77
-
78
- - `TWIN_EXTENSIONS_MAX_SIZE_MB` - Maximum size for HTTPS downloads (default: 10)
79
- - `TWIN_EXTENSIONS_CLEAR_CACHE` - Clear cache on startup (default: false)
80
-
81
- ## API Reference
82
-
83
- ### Core Functions
84
-
85
- #### `overrideModuleImport(executionDirectory, envVars)`
86
-
87
- Sets up protocol-based module resolution for extensions.
88
-
89
- #### `buildConfiguration(options)`
90
-
91
- Builds node configuration from environment variables and options.
92
-
93
- #### `start(options)`
94
-
95
- Starts the TWIN node with the specified configuration.
96
-
97
- ### Utility Functions
98
-
99
- #### `parseModuleProtocol(moduleName)`
100
-
101
- Parses module name to determine protocol type (npm, https, local, etc.).
102
-
103
- #### `handleNpmProtocol(packageName, executionDirectory, cacheDirectory)`
104
-
105
- Handles installation and resolution of npm packages.
106
-
107
- #### `handleHttpsProtocol(url, executionDirectory, maxSizeMb, cacheDirectory, ttlHours, forceRefresh)`
108
-
109
- Handles download and caching of HTTPS extensions.
110
-
111
- ## Security Considerations
112
-
113
- - **HTTPS Only**: Remote extensions must use HTTPS protocol
114
- - **Size Limits**: Downloads are limited by `TWIN_EXTENSIONS_MAX_SIZE_MB`
115
- - **Cache TTL**: Extensions are automatically refreshed based on TTL
116
- - **Security Warnings**: Warnings are displayed when loading remote extensions
117
-
118
- ## Troubleshooting
119
-
120
- ### Common Issues
121
-
122
- 1. **Extension not found**: Check that the path/URL is correct and accessible
123
- 2. **Cache issues**: Use `TWIN_EXTENSIONS_FORCE_REFRESH=true` to force refresh
124
- 3. **Size limit exceeded**: Increase `TWIN_EXTENSIONS_MAX_SIZE_MB` if needed
125
- 4. **Network issues**: Ensure HTTPS URLs are accessible and not blocked by firewall
126
-
127
- ### Debug Mode
128
-
129
- Set `NODE_ENV=development` for additional debug output during extension loading.
@@ -1,29 +0,0 @@
1
- # Function: bootstrap()
2
-
3
- > **bootstrap**(`engineCore`, `context`, `envVars`): `Promise`\<`void`\>
4
-
5
- Bootstrap the application.
6
-
7
- ## Parameters
8
-
9
- ### engineCore
10
-
11
- `IEngineCore`
12
-
13
- The engine core for the node.
14
-
15
- ### context
16
-
17
- `IEngineCoreContext`\<`IEngineServerConfig`, [`INodeEngineState`](../interfaces/INodeEngineState.md)\>
18
-
19
- The context for the node.
20
-
21
- ### envVars
22
-
23
- [`INodeEnvironmentVariables`](../interfaces/INodeEnvironmentVariables.md)
24
-
25
- The environment variables for the node.
26
-
27
- ## Returns
28
-
29
- `Promise`\<`void`\>