@twin.org/immutable-proof-task 0.0.1-next.14 → 0.0.1-next.16

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.
@@ -14,21 +14,32 @@ const CLASS_NAME = "ImmutableProofTask";
14
14
  * @returns The proof.
15
15
  */
16
16
  async function processProofTask(engineCloneData, payload) {
17
- core.Guards.objectValue(CLASS_NAME, "engineCloneData", engineCloneData);
18
17
  core.Guards.objectValue(CLASS_NAME, "payload", payload);
19
18
  core.Guards.stringValue(CLASS_NAME, "payload.nodeIdentity", payload.nodeIdentity);
20
19
  core.Guards.stringValue(CLASS_NAME, "payload.identityConnectorType", payload.identityConnectorType);
21
20
  core.Guards.stringHex(CLASS_NAME, "payload.hashData", payload.hashData);
22
21
  core.Guards.stringValue(CLASS_NAME, "payload.assertionMethodId", payload.assertionMethodId);
23
- const engine = new engineCore.EngineCore();
24
- engine.populateClone(engineCloneData, true);
25
- await engine.start();
26
- const identityConnector = identityModels.IdentityConnectorFactory.get(payload.identityConnectorType);
27
- const proof = await identityConnector.createProof(payload.nodeIdentity, `${payload.nodeIdentity}#${payload.assertionMethodId}`, core.Converter.hexToBytes(payload.hashData));
28
- return {
29
- proofId: payload.proofId,
30
- proof
31
- };
22
+ let engine;
23
+ try {
24
+ if (!core.Is.empty(engineCloneData)) {
25
+ // If the clone data is not empty we use it to create a new engine as it's a new thread
26
+ // otherwise we assume the factories are already populated.
27
+ engine = new engineCore.EngineCore();
28
+ engine.populateClone(engineCloneData, true);
29
+ await engine.start();
30
+ }
31
+ const identityConnector = identityModels.IdentityConnectorFactory.get(payload.identityConnectorType);
32
+ const proof = await identityConnector.createProof(payload.nodeIdentity, `${payload.nodeIdentity}#${payload.assertionMethodId}`, core.Converter.hexToBytes(payload.hashData));
33
+ return {
34
+ proofId: payload.proofId,
35
+ proof
36
+ };
37
+ }
38
+ finally {
39
+ if (!core.Is.empty(engine)) {
40
+ await engine.stop();
41
+ }
42
+ }
32
43
  }
33
44
 
34
45
  exports.processProofTask = processProofTask;
@@ -1,4 +1,4 @@
1
- import { Guards, Converter } from '@twin.org/core';
1
+ import { Guards, Is, Converter } from '@twin.org/core';
2
2
  import { EngineCore } from '@twin.org/engine-core';
3
3
  import { IdentityConnectorFactory } from '@twin.org/identity-models';
4
4
 
@@ -12,21 +12,32 @@ const CLASS_NAME = "ImmutableProofTask";
12
12
  * @returns The proof.
13
13
  */
14
14
  async function processProofTask(engineCloneData, payload) {
15
- Guards.objectValue(CLASS_NAME, "engineCloneData", engineCloneData);
16
15
  Guards.objectValue(CLASS_NAME, "payload", payload);
17
16
  Guards.stringValue(CLASS_NAME, "payload.nodeIdentity", payload.nodeIdentity);
18
17
  Guards.stringValue(CLASS_NAME, "payload.identityConnectorType", payload.identityConnectorType);
19
18
  Guards.stringHex(CLASS_NAME, "payload.hashData", payload.hashData);
20
19
  Guards.stringValue(CLASS_NAME, "payload.assertionMethodId", payload.assertionMethodId);
21
- const engine = new EngineCore();
22
- engine.populateClone(engineCloneData, true);
23
- await engine.start();
24
- const identityConnector = IdentityConnectorFactory.get(payload.identityConnectorType);
25
- const proof = await identityConnector.createProof(payload.nodeIdentity, `${payload.nodeIdentity}#${payload.assertionMethodId}`, Converter.hexToBytes(payload.hashData));
26
- return {
27
- proofId: payload.proofId,
28
- proof
29
- };
20
+ let engine;
21
+ try {
22
+ if (!Is.empty(engineCloneData)) {
23
+ // If the clone data is not empty we use it to create a new engine as it's a new thread
24
+ // otherwise we assume the factories are already populated.
25
+ engine = new EngineCore();
26
+ engine.populateClone(engineCloneData, true);
27
+ await engine.start();
28
+ }
29
+ const identityConnector = IdentityConnectorFactory.get(payload.identityConnectorType);
30
+ const proof = await identityConnector.createProof(payload.nodeIdentity, `${payload.nodeIdentity}#${payload.assertionMethodId}`, Converter.hexToBytes(payload.hashData));
31
+ return {
32
+ proofId: payload.proofId,
33
+ proof
34
+ };
35
+ }
36
+ finally {
37
+ if (!Is.empty(engine)) {
38
+ await engine.stop();
39
+ }
40
+ }
30
41
  }
31
42
 
32
43
  export { processProofTask };
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/immutable-proof-task - Changelog
2
2
 
3
- ## v0.0.1-next.14
3
+ ## v0.0.1-next.16
4
4
 
5
5
  - Initial Release
@@ -6,11 +6,15 @@ Process a proof.
6
6
 
7
7
  ## Parameters
8
8
 
9
- **engineCloneData**: `IEngineCoreClone`\<`IEngineCoreConfig`, `IEngineState`\>
9
+ ### engineCloneData
10
+
11
+ `IEngineCoreClone`
10
12
 
11
13
  The engine clone data.
12
14
 
13
- **payload**: [`IImmutableProofTaskPayload`](../interfaces/IImmutableProofTaskPayload.md)
15
+ ### payload
16
+
17
+ [`IImmutableProofTaskPayload`](../interfaces/IImmutableProofTaskPayload.md)
14
18
 
15
19
  The payload to process.
16
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/immutable-proof-task",
3
- "version": "0.0.1-next.14",
3
+ "version": "0.0.1-next.16",
4
4
  "description": "Background task for generating the proof",
5
5
  "repository": {
6
6
  "type": "git",
@@ -26,9 +26,9 @@
26
26
  "types": "./dist/types/index.d.ts",
27
27
  "exports": {
28
28
  ".": {
29
+ "types": "./dist/types/index.d.ts",
29
30
  "require": "./dist/cjs/index.cjs",
30
- "import": "./dist/esm/index.mjs",
31
- "types": "./dist/types/index.d.ts"
31
+ "import": "./dist/esm/index.mjs"
32
32
  },
33
33
  "./locales/*.json": "./locales/*.json"
34
34
  },