@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.
package/dist/cjs/index.cjs
CHANGED
|
@@ -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-
|
|
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-
|
|
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
|
-
},
|
|
536
|
+
}, interval);
|
|
535
537
|
}
|
|
536
538
|
}
|
|
537
539
|
/**
|
|
@@ -539,32 +541,40 @@ class ImmutableProofService {
|
|
|
539
541
|
* @internal
|
|
540
542
|
*/
|
|
541
543
|
async processProofs() {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
/**
|
package/dist/esm/index.mjs
CHANGED
|
@@ -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-
|
|
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-
|
|
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
|
-
},
|
|
534
|
+
}, interval);
|
|
533
535
|
}
|
|
534
536
|
}
|
|
535
537
|
/**
|
|
@@ -537,32 +539,40 @@ class ImmutableProofService {
|
|
|
537
539
|
* @internal
|
|
538
540
|
*/
|
|
539
541
|
async processProofs() {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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-
|
|
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
|
@@ -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-
|
|
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.
|
|
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.
|
|
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",
|