@twin.org/immutable-proof-service 0.0.1-next.3 → 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.
@@ -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
  /**
@@ -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
  /**
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/immutable-proof-service - Changelog
2
2
 
3
- ## v0.0.1-next.3
3
+ ## v0.0.1-next.4
4
4
 
5
5
  - Initial Release
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/immutable-proof-service",
3
- "version": "0.0.1-next.3",
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.3",
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",