@twin.org/engine 0.0.1-next.14

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.
@@ -0,0 +1,591 @@
1
+ 'use strict';
2
+
3
+ var engineCore = require('@twin.org/engine-core');
4
+ var path = require('node:path');
5
+ var core = require('@twin.org/core');
6
+ var engineTypes = require('@twin.org/engine-types');
7
+
8
+ // Copyright 2024 IOTA Stiftung.
9
+ // SPDX-License-Identifier: Apache-2.0.
10
+ /**
11
+ * The engine with built in types.
12
+ */
13
+ class Engine extends engineCore.EngineCore {
14
+ /**
15
+ * Runtime name for the class.
16
+ */
17
+ CLASS_NAME = "Engine";
18
+ /**
19
+ * Create a new instance of Engine.
20
+ * @param options The options for the engine.
21
+ */
22
+ constructor(options) {
23
+ super(options);
24
+ this.addCoreTypeInitialisers(this, this._context);
25
+ }
26
+ /**
27
+ * Add the core type initializers.
28
+ * @internal
29
+ */
30
+ addCoreTypeInitialisers(engineCore, context) {
31
+ this.addTypeInitialiser("loggingConnector", context.config.types.loggingConnector, "@twin.org/engine-types", "initialiseLoggingConnector");
32
+ this.addTypeInitialiser("loggingComponent", context.config.types.loggingComponent, "@twin.org/engine-types", "initialiseLoggingComponent");
33
+ this.addTypeInitialiser("backgroundTaskConnector", context.config.types.backgroundTaskConnector, "@twin.org/engine-types", "initialiseBackgroundTaskConnector");
34
+ this.addTypeInitialiser("telemetryConnector", context.config.types.telemetryConnector, "@twin.org/engine-types", "initialiseTelemetryConnector");
35
+ this.addTypeInitialiser("telemetryComponent", context.config.types.telemetryComponent, "@twin.org/engine-types", "initialiseTelemetryComponent");
36
+ this.addTypeInitialiser("entityStorageComponent", context.config.types.entityStorageComponent, "@twin.org/engine-types", "initialiseEntityStorageComponent");
37
+ this.addTypeInitialiser("vaultConnector", context.config.types.vaultConnector, "@twin.org/engine-types", "initialiseVaultConnector");
38
+ this.addTypeInitialiser("blobStorageConnector", context.config.types.blobStorageConnector, "@twin.org/engine-types", "initialiseBlobStorageConnector");
39
+ this.addTypeInitialiser("blobStorageComponent", context.config.types.blobStorageComponent, "@twin.org/engine-types", "initialiseBlobStorageComponent");
40
+ this.addTypeInitialiser("immutableStorageConnector", context.config.types.immutableStorageConnector, "@twin.org/engine-types", "initialiseImmutableStorageConnector");
41
+ this.addTypeInitialiser("walletConnector", context.config.types.walletConnector, "@twin.org/engine-types", "initialiseWalletStorage");
42
+ this.addTypeInitialiser("faucetConnector", context.config.types.faucetConnector, "@twin.org/engine-types", "initialiseFaucetConnector");
43
+ this.addTypeInitialiser("walletConnector", context.config.types.walletConnector, "@twin.org/engine-types", "initialiseWalletConnector");
44
+ this.addTypeInitialiser("identityConnector", context.config.types.identityConnector, "@twin.org/engine-types", "initialiseIdentityConnector");
45
+ this.addTypeInitialiser("identityComponent", context.config.types.identityComponent, "@twin.org/engine-types", "initialiseIdentityComponent");
46
+ this.addTypeInitialiser("identityProfileConnector", context.config.types.identityProfileConnector, "@twin.org/engine-types", "initialiseIdentityProfileConnector");
47
+ this.addTypeInitialiser("identityProfileComponent", context.config.types.identityProfileComponent, "@twin.org/engine-types", "initialiseIdentityProfileComponent");
48
+ this.addTypeInitialiser("nftConnector", context.config.types.nftConnector, "@twin.org/engine-types", "initialiseNftConnector");
49
+ this.addTypeInitialiser("nftComponent", context.config.types.nftComponent, "@twin.org/engine-types", "initialiseNftComponent");
50
+ this.addTypeInitialiser("immutableProofComponent", context.config.types.immutableProofComponent, "@twin.org/engine-types", "initialiseImmutableProofComponent");
51
+ this.addTypeInitialiser("attestationConnector", context.config.types.attestationConnector, "@twin.org/engine-types", "initialiseAttestationConnector");
52
+ this.addTypeInitialiser("attestationComponent", context.config.types.attestationComponent, "@twin.org/engine-types", "initialiseAttestationComponent");
53
+ this.addTypeInitialiser("auditableItemGraphComponent", context.config.types.auditableItemGraphComponent, "@twin.org/engine-types", "initialiseAuditableItemGraphComponent");
54
+ this.addTypeInitialiser("auditableItemStreamComponent", context.config.types.auditableItemStreamComponent, "@twin.org/engine-types", "initialiseAuditableItemStreamComponent");
55
+ }
56
+ }
57
+
58
+ // Copyright 2024 IOTA Stiftung.
59
+ // SPDX-License-Identifier: Apache-2.0.
60
+ /**
61
+ * Build the engine core configuration from environment variables.
62
+ * @param envVars The environment variables.
63
+ * @returns The config for the core.
64
+ */
65
+ function buildEngineConfiguration(envVars) {
66
+ envVars.stateFilename ??= "engine-state.json";
67
+ envVars.storageFileRoot = path.resolve(envVars.storageFileRoot);
68
+ envVars.stateFilename = path.join(envVars.storageFileRoot, envVars.stateFilename);
69
+ envVars.attestationAssertionMethodId ??= "attestation-assertion";
70
+ envVars.immutableProofHashKeyId ??= "immutable-proof-hash";
71
+ envVars.immutableProofAssertionMethodId ??= "immutable-proof-assertion";
72
+ envVars.blobStorageEnableEncryption ??= "false";
73
+ envVars.blobStorageEncryptionKey ??= "blob-encryption";
74
+ const coreConfig = {
75
+ debug: core.Coerce.boolean(envVars.debug) ?? false,
76
+ types: {
77
+ loggingConnector: [],
78
+ loggingComponent: [{ type: engineTypes.LoggingComponentType.Service }],
79
+ entityStorageConnector: [],
80
+ blobStorageConnector: [],
81
+ blobStorageComponent: [
82
+ {
83
+ type: engineTypes.BlobStorageComponentType.Service,
84
+ options: {
85
+ config: {
86
+ vaultKeyId: envVars.blobStorageEncryptionKey
87
+ }
88
+ }
89
+ }
90
+ ],
91
+ backgroundTaskConnector: [],
92
+ telemetryConnector: [],
93
+ telemetryComponent: [{ type: engineTypes.TelemetryComponentType.Service }],
94
+ vaultConnector: [],
95
+ walletConnector: [],
96
+ faucetConnector: [],
97
+ immutableStorageConnector: [],
98
+ nftConnector: [],
99
+ nftComponent: [{ type: engineTypes.NftComponentType.Service }],
100
+ identityConnector: [],
101
+ identityComponent: [{ type: engineTypes.IdentityComponentType.Service }],
102
+ identityProfileConnector: [],
103
+ identityProfileComponent: [{ type: engineTypes.IdentityProfileComponentType.Service }],
104
+ immutableProofComponent: [
105
+ {
106
+ type: engineTypes.ImmutableProofComponentType.Service,
107
+ options: {
108
+ config: {
109
+ assertionMethodId: envVars.immutableProofAssertionMethodId,
110
+ proofHashKeyId: envVars.immutableProofHashKeyId
111
+ }
112
+ }
113
+ }
114
+ ],
115
+ attestationConnector: [],
116
+ attestationComponent: [
117
+ {
118
+ type: engineTypes.AttestationComponentType.Service
119
+ }
120
+ ],
121
+ auditableItemGraphComponent: [{ type: engineTypes.AuditableItemGraphComponentType.Service }],
122
+ auditableItemStreamComponent: [{ type: engineTypes.AuditableItemStreamComponentType.Service }]
123
+ }
124
+ };
125
+ configureEntityStorageConnectors(coreConfig, envVars);
126
+ configureBlobStorageConnectors(coreConfig, envVars);
127
+ configureVaultConnectors(coreConfig, envVars);
128
+ configureLogging(coreConfig, envVars);
129
+ configureBackgroundTaskConnectors(coreConfig, envVars);
130
+ configureTelemetryConnectors(coreConfig, envVars);
131
+ configureFaucetConnectors(coreConfig, envVars);
132
+ configureWalletConnectors(coreConfig, envVars);
133
+ configureNftConnectors(coreConfig, envVars);
134
+ configureImmutableStorageConnectors(coreConfig, envVars);
135
+ configureIdentityConnectors(coreConfig, envVars);
136
+ configureIdentityProfileConnectors(coreConfig, envVars);
137
+ configureAttestationConnectors(coreConfig, envVars);
138
+ return coreConfig;
139
+ }
140
+ /**
141
+ * Configures the entity storage connectors for the core.
142
+ * @param coreConfig The core config.
143
+ * @param envVars The environment variables.
144
+ */
145
+ function configureEntityStorageConnectors(coreConfig, envVars) {
146
+ coreConfig.types ??= {};
147
+ coreConfig.types.entityStorageConnector ??= [];
148
+ if ((core.Coerce.boolean(envVars.entityMemoryEnable) ?? false) ||
149
+ envVars.blobStorageConnectorType === engineTypes.EntityStorageConnectorType.Memory) {
150
+ coreConfig.types.entityStorageConnector.push({
151
+ type: engineTypes.EntityStorageConnectorType.Memory
152
+ });
153
+ }
154
+ if ((core.Coerce.boolean(envVars.entityFileEnable) ?? false) ||
155
+ envVars.entityStorageConnectorType === engineTypes.EntityStorageConnectorType.File) {
156
+ coreConfig.types.entityStorageConnector.push({
157
+ type: engineTypes.EntityStorageConnectorType.File,
158
+ options: {
159
+ config: { directory: envVars.storageFileRoot },
160
+ folderPrefix: envVars.entityStorageTablePrefix
161
+ }
162
+ });
163
+ }
164
+ if (core.Is.stringValue(envVars.awsDynamodbAccessKeyId)) {
165
+ coreConfig.types.entityStorageConnector.push({
166
+ type: engineTypes.EntityStorageConnectorType.AwsDynamoDb,
167
+ options: {
168
+ config: {
169
+ region: envVars.awsDynamodbRegion,
170
+ accessKeyId: envVars.awsDynamodbAccessKeyId,
171
+ secretAccessKey: envVars.awsDynamodbSecretAccessKey,
172
+ endpoint: envVars.awsDynamodbEndpoint
173
+ },
174
+ tablePrefix: envVars.entityStorageTablePrefix
175
+ }
176
+ });
177
+ }
178
+ if (core.Is.stringValue(envVars.azureCosmosdbKey)) {
179
+ coreConfig.types.entityStorageConnector.push({
180
+ type: engineTypes.EntityStorageConnectorType.AzureCosmosDb,
181
+ options: {
182
+ config: {
183
+ endpoint: envVars.azureCosmosdbEndpoint,
184
+ key: envVars.azureCosmosdbKey,
185
+ databaseId: envVars.azureCosmosdbDatabaseId,
186
+ containerId: envVars.azureCosmosdbContainerId
187
+ },
188
+ tablePrefix: envVars.entityStorageTablePrefix
189
+ }
190
+ });
191
+ }
192
+ if (core.Is.stringValue(envVars.gcpFirestoreCredentials)) {
193
+ coreConfig.types.entityStorageConnector.push({
194
+ type: engineTypes.EntityStorageConnectorType.GcpFirestoreDb,
195
+ options: {
196
+ config: {
197
+ projectId: envVars.gcpFirestoreProjectId,
198
+ credentials: envVars.gcpFirestoreCredentials,
199
+ databaseId: envVars.gcpFirestoreDatabaseId,
200
+ collectionName: envVars.gcpFirestoreCollectionName,
201
+ endpoint: envVars.gcpFirestoreApiEndpoint
202
+ },
203
+ tablePrefix: envVars.entityStorageTablePrefix
204
+ }
205
+ });
206
+ }
207
+ if (core.Is.stringValue(envVars.scylladbHosts)) {
208
+ coreConfig.types.entityStorageConnector.push({
209
+ type: engineTypes.EntityStorageConnectorType.ScyllaDb,
210
+ options: {
211
+ config: {
212
+ hosts: envVars.scylladbHosts.split(","),
213
+ localDataCenter: envVars.scylladbLocalDataCenter,
214
+ keyspace: envVars.scylladbKeyspace
215
+ },
216
+ tablePrefix: envVars.entityStorageTablePrefix
217
+ }
218
+ });
219
+ }
220
+ const defaultStorageConnector = envVars.entityStorageConnectorType;
221
+ if (core.Is.stringValue(defaultStorageConnector)) {
222
+ for (const config of coreConfig.types.entityStorageConnector) {
223
+ if (config.type === defaultStorageConnector) {
224
+ config.isDefault = true;
225
+ }
226
+ }
227
+ }
228
+ }
229
+ /**
230
+ * Configures the blob storage connectors for the core.
231
+ * @param coreConfig The core config.
232
+ * @param envVars The environment variables.
233
+ */
234
+ function configureBlobStorageConnectors(coreConfig, envVars) {
235
+ coreConfig.types.blobStorageConnector ??= [];
236
+ if ((core.Coerce.boolean(envVars.blobMemoryEnable) ?? false) ||
237
+ envVars.blobStorageConnectorType === engineTypes.BlobStorageConnectorType.Memory) {
238
+ coreConfig.types.blobStorageConnector.push({
239
+ type: engineTypes.BlobStorageConnectorType.Memory
240
+ });
241
+ }
242
+ if ((core.Coerce.boolean(envVars.blobFileEnable) ?? false) ||
243
+ envVars.blobStorageConnectorType === engineTypes.BlobStorageConnectorType.File) {
244
+ coreConfig.types.blobStorageConnector.push({
245
+ type: engineTypes.BlobStorageConnectorType.File,
246
+ options: {
247
+ config: { directory: path.join(envVars.storageFileRoot, "blob-storage") },
248
+ storagePrefix: envVars.blobStoragePrefix
249
+ }
250
+ });
251
+ }
252
+ if (core.Is.stringValue(envVars.ipfsApiUrl)) {
253
+ coreConfig.types.blobStorageConnector.push({
254
+ type: engineTypes.BlobStorageConnectorType.Ipfs,
255
+ options: {
256
+ config: {
257
+ apiUrl: envVars.ipfsApiUrl,
258
+ bearerToken: envVars.ipfsBearerToken
259
+ }
260
+ }
261
+ });
262
+ }
263
+ if (core.Is.stringValue(envVars.awsS3AccessKeyId)) {
264
+ coreConfig.types.blobStorageConnector.push({
265
+ type: engineTypes.BlobStorageConnectorType.AwsS3,
266
+ options: {
267
+ config: {
268
+ region: envVars.awsS3Region,
269
+ bucketName: envVars.awsS3BucketName,
270
+ accessKeyId: envVars.awsS3AccessKeyId,
271
+ secretAccessKey: envVars.awsS3SecretAccessKey,
272
+ endpoint: envVars.awsS3Endpoint
273
+ },
274
+ storagePrefix: envVars.blobStoragePrefix
275
+ }
276
+ });
277
+ }
278
+ if (core.Is.stringValue(envVars.azureStorageAccountKey)) {
279
+ coreConfig.types.blobStorageConnector.push({
280
+ type: engineTypes.BlobStorageConnectorType.AzureStorage,
281
+ options: {
282
+ config: {
283
+ accountName: envVars.azureStorageAccountName,
284
+ accountKey: envVars.azureStorageAccountKey,
285
+ containerName: envVars.azureStorageContainerName,
286
+ endpoint: envVars.azureStorageEndpoint
287
+ },
288
+ storagePrefix: envVars.blobStoragePrefix
289
+ }
290
+ });
291
+ }
292
+ if (core.Is.stringValue(envVars.gcpStorageCredentials)) {
293
+ coreConfig.types.blobStorageConnector.push({
294
+ type: engineTypes.BlobStorageConnectorType.GcpStorage,
295
+ options: {
296
+ config: {
297
+ projectId: envVars.gcpStorageProjectId,
298
+ credentials: envVars.gcpStorageCredentials,
299
+ bucketName: envVars.gcpStorageBucketName,
300
+ apiEndpoint: envVars.gcpFirestoreApiEndpoint
301
+ },
302
+ storagePrefix: envVars.blobStoragePrefix
303
+ }
304
+ });
305
+ }
306
+ const defaultStorageConnectorType = envVars.blobStorageConnectorType;
307
+ if (core.Is.stringValue(defaultStorageConnectorType)) {
308
+ for (const config of coreConfig.types.blobStorageConnector) {
309
+ if (config.type === defaultStorageConnectorType) {
310
+ config.isDefault = true;
311
+ }
312
+ }
313
+ }
314
+ }
315
+ /**
316
+ * Configures the logging connectors for the core.
317
+ * @param coreConfig The core config.
318
+ * @param envVars The environment variables.
319
+ */
320
+ function configureLogging(coreConfig, envVars) {
321
+ const loggingConnectors = (envVars.loggingConnector ?? "").split(",");
322
+ for (const loggingConnector of loggingConnectors) {
323
+ if (loggingConnector === engineTypes.LoggingConnectorType.Console) {
324
+ coreConfig.types.loggingConnector?.push({
325
+ type: engineTypes.LoggingConnectorType.Console,
326
+ options: {
327
+ config: {
328
+ translateMessages: true,
329
+ hideGroups: true
330
+ }
331
+ }
332
+ });
333
+ }
334
+ else if (loggingConnector === engineTypes.LoggingConnectorType.EntityStorage) {
335
+ coreConfig.types.loggingConnector?.push({
336
+ type: engineTypes.LoggingConnectorType.EntityStorage
337
+ });
338
+ }
339
+ }
340
+ if (loggingConnectors.length > 1) {
341
+ coreConfig.types.loggingConnector?.push({
342
+ type: engineTypes.LoggingConnectorType.Multi,
343
+ isDefault: true,
344
+ options: {
345
+ loggingConnectorTypes: loggingConnectors
346
+ }
347
+ });
348
+ }
349
+ }
350
+ /**
351
+ * Configures the vault connectors for the core.
352
+ * @param coreConfig The core config.
353
+ * @param envVars The environment variables.
354
+ */
355
+ function configureVaultConnectors(coreConfig, envVars) {
356
+ coreConfig.types.vaultConnector ??= [];
357
+ if (envVars.vaultConnector === engineTypes.VaultConnectorType.EntityStorage) {
358
+ coreConfig.types.vaultConnector.push({
359
+ type: engineTypes.VaultConnectorType.EntityStorage
360
+ });
361
+ }
362
+ else if (envVars.vaultConnector === engineTypes.VaultConnectorType.Hashicorp) {
363
+ coreConfig.types.vaultConnector.push({
364
+ type: engineTypes.VaultConnectorType.Hashicorp,
365
+ options: {
366
+ config: { endpoint: envVars.hashicorpVaultEndpoint, token: envVars.hashicorpVaultToken }
367
+ }
368
+ });
369
+ }
370
+ }
371
+ /**
372
+ * Configures the background task connectors for the core.
373
+ * @param coreConfig The core config.
374
+ * @param envVars The environment variables.
375
+ */
376
+ function configureBackgroundTaskConnectors(coreConfig, envVars) {
377
+ coreConfig.types.backgroundTaskConnector ??= [];
378
+ if (envVars.backgroundTaskConnector === engineTypes.BackgroundTaskConnectorType.EntityStorage) {
379
+ coreConfig.types.backgroundTaskConnector.push({
380
+ type: engineTypes.BackgroundTaskConnectorType.EntityStorage
381
+ });
382
+ }
383
+ }
384
+ /**
385
+ * Configures the telemetry connectors for the core.
386
+ * @param coreConfig The core config.
387
+ * @param envVars The environment variables.
388
+ */
389
+ function configureTelemetryConnectors(coreConfig, envVars) {
390
+ coreConfig.types.telemetryConnector ??= [];
391
+ if (envVars.telemetryConnector === engineTypes.TelemetryConnectorType.EntityStorage) {
392
+ coreConfig.types.telemetryConnector.push({
393
+ type: engineTypes.TelemetryConnectorType.EntityStorage
394
+ });
395
+ }
396
+ }
397
+ /**
398
+ * Configures the faucet connectors for the core.
399
+ * @param coreConfig The core config.
400
+ * @param envVars The environment variables.
401
+ */
402
+ function configureFaucetConnectors(coreConfig, envVars) {
403
+ coreConfig.types.faucetConnector ??= [];
404
+ if (envVars.faucetConnector === engineTypes.FaucetConnectorType.EntityStorage) {
405
+ coreConfig.types.faucetConnector.push({
406
+ type: engineTypes.FaucetConnectorType.EntityStorage
407
+ });
408
+ }
409
+ else if (envVars.faucetConnector === engineTypes.FaucetConnectorType.Iota) {
410
+ coreConfig.types.faucetConnector.push({
411
+ type: engineTypes.FaucetConnectorType.Iota,
412
+ options: {
413
+ config: {
414
+ endpoint: envVars.iotaFaucetEndpoint,
415
+ clientOptions: {
416
+ nodes: [envVars.iotaNodeEndpoint]
417
+ },
418
+ bech32Hrp: envVars.iotaBech32Hrp,
419
+ coinType: core.Coerce.number(envVars.iotaCoinType)
420
+ }
421
+ }
422
+ });
423
+ }
424
+ }
425
+ /**
426
+ * Configures the wallet connectors for the core.
427
+ * @param coreConfig The core config.
428
+ * @param envVars The environment variables.
429
+ */
430
+ function configureWalletConnectors(coreConfig, envVars) {
431
+ coreConfig.types.walletConnector ??= [];
432
+ if (envVars.walletConnector === engineTypes.WalletConnectorType.EntityStorage) {
433
+ coreConfig.types.walletConnector.push({
434
+ type: engineTypes.WalletConnectorType.EntityStorage
435
+ });
436
+ }
437
+ else if (envVars.walletConnector === engineTypes.WalletConnectorType.Iota) {
438
+ coreConfig.types.walletConnector.push({
439
+ type: engineTypes.WalletConnectorType.Iota,
440
+ options: {
441
+ config: {
442
+ clientOptions: {
443
+ nodes: [envVars.iotaNodeEndpoint]
444
+ },
445
+ bech32Hrp: envVars.iotaBech32Hrp,
446
+ coinType: core.Coerce.number(envVars.iotaCoinType)
447
+ }
448
+ }
449
+ });
450
+ }
451
+ }
452
+ /**
453
+ * Configures the NFT connectors for the core.
454
+ * @param coreConfig The core config.
455
+ * @param envVars The environment variables.
456
+ */
457
+ function configureNftConnectors(coreConfig, envVars) {
458
+ coreConfig.types.nftConnector ??= [];
459
+ if (envVars.nftConnector === engineTypes.NftConnectorType.EntityStorage) {
460
+ coreConfig.types.nftConnector.push({
461
+ type: engineTypes.NftConnectorType.EntityStorage
462
+ });
463
+ }
464
+ else if (envVars.nftConnector === engineTypes.NftConnectorType.Iota) {
465
+ coreConfig.types.nftConnector.push({
466
+ type: engineTypes.NftConnectorType.Iota,
467
+ options: {
468
+ config: {
469
+ clientOptions: {
470
+ nodes: [envVars.iotaNodeEndpoint]
471
+ },
472
+ bech32Hrp: envVars.iotaBech32Hrp,
473
+ coinType: core.Coerce.number(envVars.iotaCoinType)
474
+ }
475
+ }
476
+ });
477
+ }
478
+ }
479
+ /**
480
+ * Configures the immutable storage connectors for the core.
481
+ * @param coreConfig The core config.
482
+ * @param envVars The environment variables.
483
+ */
484
+ function configureImmutableStorageConnectors(coreConfig, envVars) {
485
+ coreConfig.types.immutableStorageConnector ??= [];
486
+ if (envVars.immutableStorageConnector === engineTypes.ImmutableStorageConnectorType.EntityStorage) {
487
+ coreConfig.types.immutableStorageConnector.push({
488
+ type: engineTypes.ImmutableStorageConnectorType.EntityStorage
489
+ });
490
+ }
491
+ else if (envVars.immutableStorageConnector === engineTypes.ImmutableStorageConnectorType.Iota) {
492
+ coreConfig.types.immutableStorageConnector.push({
493
+ type: engineTypes.ImmutableStorageConnectorType.Iota,
494
+ options: {
495
+ config: {
496
+ clientOptions: {
497
+ nodes: [envVars.iotaNodeEndpoint]
498
+ },
499
+ bech32Hrp: envVars.iotaBech32Hrp,
500
+ coinType: core.Coerce.number(envVars.iotaCoinType)
501
+ }
502
+ }
503
+ });
504
+ }
505
+ }
506
+ /**
507
+ * Configures the identity connectors for the core.
508
+ * @param coreConfig The core config.
509
+ * @param envVars The environment variables.
510
+ */
511
+ function configureIdentityConnectors(coreConfig, envVars) {
512
+ coreConfig.types.identityConnector ??= [];
513
+ if (envVars.identityConnector === engineTypes.IdentityConnectorType.EntityStorage) {
514
+ coreConfig.types.identityConnector.push({
515
+ type: engineTypes.IdentityConnectorType.EntityStorage
516
+ });
517
+ }
518
+ else if (envVars.identityConnector === engineTypes.IdentityConnectorType.Iota) {
519
+ coreConfig.types.identityConnector.push({
520
+ type: engineTypes.IdentityConnectorType.Iota,
521
+ options: {
522
+ config: {
523
+ clientOptions: {
524
+ nodes: [envVars.iotaNodeEndpoint]
525
+ },
526
+ bech32Hrp: envVars.iotaBech32Hrp,
527
+ coinType: core.Coerce.number(envVars.iotaCoinType)
528
+ }
529
+ }
530
+ });
531
+ }
532
+ }
533
+ /**
534
+ * Configures the identity profile connectors for the core.
535
+ * @param coreConfig The core config.
536
+ * @param envVars The environment variables.
537
+ */
538
+ function configureIdentityProfileConnectors(coreConfig, envVars) {
539
+ coreConfig.types.identityProfileConnector ??= [];
540
+ if (envVars.identityProfileConnector === engineTypes.IdentityConnectorType.EntityStorage) {
541
+ coreConfig.types.identityProfileConnector.push({
542
+ type: engineTypes.IdentityProfileConnectorType.EntityStorage
543
+ });
544
+ }
545
+ }
546
+ /**
547
+ * Configures the attestation connectors for the core.
548
+ * @param coreConfig The core config.
549
+ * @param envVars The environment variables.
550
+ */
551
+ function configureAttestationConnectors(coreConfig, envVars) {
552
+ coreConfig.types.attestationConnector ??= [];
553
+ if (envVars.attestationConnector === engineTypes.AttestationConnectorType.EntityStorage) {
554
+ coreConfig.types.attestationConnector.push({
555
+ type: engineTypes.AttestationConnectorType.EntityStorage
556
+ });
557
+ }
558
+ else if (envVars.attestationConnector === engineTypes.AttestationConnectorType.Iota) {
559
+ coreConfig.types.attestationConnector.push({
560
+ type: engineTypes.AttestationConnectorType.Iota
561
+ });
562
+ }
563
+ }
564
+
565
+ // Copyright 2024 IOTA Stiftung.
566
+ // SPDX-License-Identifier: Apache-2.0.
567
+ /**
568
+ * Environment variable helper.
569
+ */
570
+ class EnvHelper {
571
+ /**
572
+ * Get the environment variable as an object with camel cased names.
573
+ * @param envVars The environment variables.
574
+ * @param prefix The prefix of the environment variables.
575
+ * @returns The object with camel cased names.
576
+ */
577
+ static envToJson(envVars, prefix) {
578
+ const result = {};
579
+ for (const envVar in envVars) {
580
+ if (envVar.startsWith(prefix) && core.Is.stringValue(process.env[envVar])) {
581
+ const camelCaseName = core.StringHelper.camelCase(envVar.replace(prefix, "").toLowerCase());
582
+ core.ObjectHelper.propertySet(result, camelCaseName, process.env[envVar]);
583
+ }
584
+ }
585
+ return result;
586
+ }
587
+ }
588
+
589
+ exports.Engine = Engine;
590
+ exports.EnvHelper = EnvHelper;
591
+ exports.buildEngineConfiguration = buildEngineConfiguration;