@twin.org/immutable-proof-service 0.0.1-next.2 → 0.0.1-next.4

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.
@@ -351,13 +351,13 @@ class ImmutableProofService {
351
351
  * @param options.config The configuration for the connector.
352
352
  * @param options.vaultConnectorType The vault connector type, defaults to "vault".
353
353
  * @param options.immutableProofEntityStorageType The entity storage for proofs, defaults to "immutable-proof".
354
- * @param options.immutableStorageType The immutable storage, defaults to "immutable-proof".
354
+ * @param options.immutableStorageType The immutable storage, defaults to "immutable-storage".
355
355
  * @param options.identityConnectorType The identity connector type, defaults to "identity".
356
356
  */
357
357
  constructor(options) {
358
358
  this._vaultConnector = vaultModels.VaultConnectorFactory.get(options?.vaultConnectorType ?? "vault");
359
359
  this._proofStorage = entityStorageModels.EntityStorageConnectorFactory.get(options?.immutableProofEntityStorageType ?? core.StringHelper.kebabCase("ImmutableProof"));
360
- this._immutableStorage = immutableStorageModels.ImmutableStorageConnectorFactory.get(options?.immutableStorageType ?? "immutable-proof");
360
+ this._immutableStorage = immutableStorageModels.ImmutableStorageConnectorFactory.get(options?.immutableStorageType ?? "immutable-storage");
361
361
  this._identityConnector = identityModels.IdentityConnectorFactory.get(options?.identityConnectorType ?? "identity");
362
362
  this._config = options?.config ?? {};
363
363
  this._assertionMethodId = this._config.assertionMethodId ?? "immutable-proof";
@@ -393,7 +393,7 @@ class ImmutableProofService {
393
393
  proofObjectHash: core.Converter.bytesToBase64(hash)
394
394
  };
395
395
  await this._proofStorage.set(proofEntity);
396
- this.startProcessingProofs();
396
+ this.startProcessingProofs(0);
397
397
  return new core.Urn(ImmutableProofService.NAMESPACE, id).toString();
398
398
  }
399
399
  catch (error) {
@@ -524,14 +524,16 @@ class ImmutableProofService {
524
524
  }
525
525
  /**
526
526
  * Start processing proofs.
527
+ * @param interval The interval to process proofs.
527
528
  * @returns Nothing.
528
529
  * @internal
529
530
  */
530
- startProcessingProofs() {
531
+ startProcessingProofs(interval) {
531
532
  if (!this._processing) {
533
+ this._processing = true;
532
534
  setTimeout(async () => {
533
535
  await this.processProofs();
534
- }, 0);
536
+ }, interval);
535
537
  }
536
538
  }
537
539
  /**
@@ -539,32 +541,40 @@ class ImmutableProofService {
539
541
  * @internal
540
542
  */
541
543
  async processProofs() {
542
- // Get the oldest pending proof, plus one more, we can then determine whether to
543
- // trigger another process after this one
544
- const pendingProofs = await this._proofStorage.query({
545
- property: "immutableStorageId",
546
- comparison: entity.ComparisonOperator.Equals,
547
- value: undefined
548
- }, [
549
- {
550
- property: "dateCreated",
551
- sortDirection: entity.SortDirection.Ascending
544
+ let remainingProofs = 0;
545
+ try {
546
+ // Get the oldest pending proof, plus one more, we can then determine whether to
547
+ // trigger another process after this one
548
+ const pendingProofs = await this._proofStorage.query({
549
+ property: "immutableStorageId",
550
+ comparison: entity.ComparisonOperator.Equals,
551
+ value: undefined
552
+ }, [
553
+ {
554
+ property: "dateCreated",
555
+ sortDirection: entity.SortDirection.Ascending
556
+ }
557
+ ], undefined, undefined, 2);
558
+ remainingProofs = pendingProofs.entities.length;
559
+ if (remainingProofs > 0) {
560
+ const proofEntity = pendingProofs.entities[0];
561
+ const immutableProof = this.proofEntityToModel(proofEntity);
562
+ const hashData = await this.generateHashData(proofEntity.nodeIdentity, immutableProof);
563
+ immutableProof.proof = await this._identityConnector.createProof(proofEntity.nodeIdentity, `${proofEntity.nodeIdentity}#${this._assertionMethodId}`, hashData);
564
+ proofEntity.dateCreated =
565
+ immutableProof.proof.created ?? new Date(Date.now()).toISOString();
566
+ const compacted = await dataJsonLd.JsonLdProcessor.compact(immutableProof, immutableProof["@context"]);
567
+ proofEntity.immutableStorageId = await this._immutableStorage.store(proofEntity.nodeIdentity, core.ObjectHelper.toBytes(compacted));
568
+ await this._proofStorage.set(proofEntity);
569
+ remainingProofs--;
552
570
  }
553
- ], undefined, undefined, 2);
554
- if (pendingProofs.entities.length > 0) {
555
- const proofEntity = pendingProofs.entities[0];
556
- const immutableProof = this.proofEntityToModel(proofEntity);
557
- const hashData = await this.generateHashData(proofEntity.nodeIdentity, immutableProof);
558
- immutableProof.proof = await this._identityConnector.createProof(proofEntity.nodeIdentity, `${proofEntity.nodeIdentity}#${this._assertionMethodId}`, hashData);
559
- proofEntity.dateCreated = immutableProof.proof.created ?? new Date(Date.now()).toISOString();
560
- const compacted = await dataJsonLd.JsonLdProcessor.compact(immutableProof, immutableProof["@context"]);
561
- proofEntity.immutableStorageId = await this._immutableStorage.store(proofEntity.nodeIdentity, core.ObjectHelper.toBytes(compacted));
562
- await this._proofStorage.set(proofEntity);
563
571
  }
564
- // If there are still remaining proofs, start the timer again
565
- this._processing = false;
566
- if (pendingProofs.entities.length > 1) {
567
- this.startProcessingProofs();
572
+ finally {
573
+ // If there are still remaining proofs, start the timer again
574
+ this._processing = false;
575
+ if (remainingProofs > 0) {
576
+ this.startProcessingProofs(100);
577
+ }
568
578
  }
569
579
  }
570
580
  /**
@@ -349,13 +349,13 @@ class ImmutableProofService {
349
349
  * @param options.config The configuration for the connector.
350
350
  * @param options.vaultConnectorType The vault connector type, defaults to "vault".
351
351
  * @param options.immutableProofEntityStorageType The entity storage for proofs, defaults to "immutable-proof".
352
- * @param options.immutableStorageType The immutable storage, defaults to "immutable-proof".
352
+ * @param options.immutableStorageType The immutable storage, defaults to "immutable-storage".
353
353
  * @param options.identityConnectorType The identity connector type, defaults to "identity".
354
354
  */
355
355
  constructor(options) {
356
356
  this._vaultConnector = VaultConnectorFactory.get(options?.vaultConnectorType ?? "vault");
357
357
  this._proofStorage = EntityStorageConnectorFactory.get(options?.immutableProofEntityStorageType ?? StringHelper.kebabCase("ImmutableProof"));
358
- this._immutableStorage = ImmutableStorageConnectorFactory.get(options?.immutableStorageType ?? "immutable-proof");
358
+ this._immutableStorage = ImmutableStorageConnectorFactory.get(options?.immutableStorageType ?? "immutable-storage");
359
359
  this._identityConnector = IdentityConnectorFactory.get(options?.identityConnectorType ?? "identity");
360
360
  this._config = options?.config ?? {};
361
361
  this._assertionMethodId = this._config.assertionMethodId ?? "immutable-proof";
@@ -391,7 +391,7 @@ class ImmutableProofService {
391
391
  proofObjectHash: Converter.bytesToBase64(hash)
392
392
  };
393
393
  await this._proofStorage.set(proofEntity);
394
- this.startProcessingProofs();
394
+ this.startProcessingProofs(0);
395
395
  return new Urn(ImmutableProofService.NAMESPACE, id).toString();
396
396
  }
397
397
  catch (error) {
@@ -522,14 +522,16 @@ class ImmutableProofService {
522
522
  }
523
523
  /**
524
524
  * Start processing proofs.
525
+ * @param interval The interval to process proofs.
525
526
  * @returns Nothing.
526
527
  * @internal
527
528
  */
528
- startProcessingProofs() {
529
+ startProcessingProofs(interval) {
529
530
  if (!this._processing) {
531
+ this._processing = true;
530
532
  setTimeout(async () => {
531
533
  await this.processProofs();
532
- }, 0);
534
+ }, interval);
533
535
  }
534
536
  }
535
537
  /**
@@ -537,32 +539,40 @@ class ImmutableProofService {
537
539
  * @internal
538
540
  */
539
541
  async processProofs() {
540
- // Get the oldest pending proof, plus one more, we can then determine whether to
541
- // trigger another process after this one
542
- const pendingProofs = await this._proofStorage.query({
543
- property: "immutableStorageId",
544
- comparison: ComparisonOperator.Equals,
545
- value: undefined
546
- }, [
547
- {
548
- property: "dateCreated",
549
- sortDirection: SortDirection.Ascending
542
+ let remainingProofs = 0;
543
+ try {
544
+ // Get the oldest pending proof, plus one more, we can then determine whether to
545
+ // trigger another process after this one
546
+ const pendingProofs = await this._proofStorage.query({
547
+ property: "immutableStorageId",
548
+ comparison: ComparisonOperator.Equals,
549
+ value: undefined
550
+ }, [
551
+ {
552
+ property: "dateCreated",
553
+ sortDirection: SortDirection.Ascending
554
+ }
555
+ ], undefined, undefined, 2);
556
+ remainingProofs = pendingProofs.entities.length;
557
+ if (remainingProofs > 0) {
558
+ const proofEntity = pendingProofs.entities[0];
559
+ const immutableProof = this.proofEntityToModel(proofEntity);
560
+ const hashData = await this.generateHashData(proofEntity.nodeIdentity, immutableProof);
561
+ immutableProof.proof = await this._identityConnector.createProof(proofEntity.nodeIdentity, `${proofEntity.nodeIdentity}#${this._assertionMethodId}`, hashData);
562
+ proofEntity.dateCreated =
563
+ immutableProof.proof.created ?? new Date(Date.now()).toISOString();
564
+ const compacted = await JsonLdProcessor.compact(immutableProof, immutableProof["@context"]);
565
+ proofEntity.immutableStorageId = await this._immutableStorage.store(proofEntity.nodeIdentity, ObjectHelper.toBytes(compacted));
566
+ await this._proofStorage.set(proofEntity);
567
+ remainingProofs--;
550
568
  }
551
- ], undefined, undefined, 2);
552
- if (pendingProofs.entities.length > 0) {
553
- const proofEntity = pendingProofs.entities[0];
554
- const immutableProof = this.proofEntityToModel(proofEntity);
555
- const hashData = await this.generateHashData(proofEntity.nodeIdentity, immutableProof);
556
- immutableProof.proof = await this._identityConnector.createProof(proofEntity.nodeIdentity, `${proofEntity.nodeIdentity}#${this._assertionMethodId}`, hashData);
557
- proofEntity.dateCreated = immutableProof.proof.created ?? new Date(Date.now()).toISOString();
558
- const compacted = await JsonLdProcessor.compact(immutableProof, immutableProof["@context"]);
559
- proofEntity.immutableStorageId = await this._immutableStorage.store(proofEntity.nodeIdentity, ObjectHelper.toBytes(compacted));
560
- await this._proofStorage.set(proofEntity);
561
569
  }
562
- // If there are still remaining proofs, start the timer again
563
- this._processing = false;
564
- if (pendingProofs.entities.length > 1) {
565
- this.startProcessingProofs();
570
+ finally {
571
+ // If there are still remaining proofs, start the timer again
572
+ this._processing = false;
573
+ if (remainingProofs > 0) {
574
+ this.startProcessingProofs(100);
575
+ }
566
576
  }
567
577
  }
568
578
  /**
@@ -19,7 +19,7 @@ export declare class ImmutableProofService implements IImmutableProofComponent {
19
19
  * @param options.config The configuration for the connector.
20
20
  * @param options.vaultConnectorType The vault connector type, defaults to "vault".
21
21
  * @param options.immutableProofEntityStorageType The entity storage for proofs, defaults to "immutable-proof".
22
- * @param options.immutableStorageType The immutable storage, defaults to "immutable-proof".
22
+ * @param options.immutableStorageType The immutable storage, defaults to "immutable-storage".
23
23
  * @param options.identityConnectorType The identity connector type, defaults to "identity".
24
24
  */
25
25
  constructor(options?: {
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/immutable-proof-service - Changelog
2
2
 
3
- ## v0.0.1-next.2
3
+ ## v0.0.1-next.4
4
4
 
5
5
  - Initial Release
@@ -30,7 +30,7 @@ The entity storage for proofs, defaults to "immutable-proof".
30
30
 
31
31
  • **options.immutableStorageType?**: `string`
32
32
 
33
- The immutable storage, defaults to "immutable-proof".
33
+ The immutable storage, defaults to "immutable-storage".
34
34
 
35
35
  • **options.config?**: [`IImmutableProofServiceConfig`](../interfaces/IImmutableProofServiceConfig.md)
36
36
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/immutable-proof-service",
3
- "version": "0.0.1-next.2",
3
+ "version": "0.0.1-next.4",
4
4
  "description": "Immutable proof contract implementation and REST endpoint definitions",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,7 +22,7 @@
22
22
  "@twin.org/entity": "next",
23
23
  "@twin.org/entity-storage-models": "next",
24
24
  "@twin.org/identity-models": "next",
25
- "@twin.org/immutable-proof-models": "0.0.1-next.2",
25
+ "@twin.org/immutable-proof-models": "0.0.1-next.4",
26
26
  "@twin.org/immutable-storage-models": "next",
27
27
  "@twin.org/nameof": "next",
28
28
  "@twin.org/standards-w3c-did": "next",