@twin.org/immutable-proof-service 0.0.1-next.2 → 0.0.1-next.20
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 +159 -161
- package/dist/esm/index.mjs +163 -165
- package/dist/types/immutableProofService.d.ts +4 -16
- package/dist/types/index.d.ts +2 -1
- package/dist/types/models/IImmutableProofServiceConfig.d.ts +6 -6
- package/dist/types/models/IImmutableProofServiceConstructorOptions.d.ts +39 -0
- package/docs/changelog.md +1 -1
- package/docs/open-api/spec.json +697 -732
- package/docs/reference/classes/ImmutableProofService.md +25 -33
- package/docs/reference/functions/generateRestRoutesImmutableProof.md +8 -4
- package/docs/reference/functions/immutableProofCreate.md +9 -3
- package/docs/reference/functions/immutableProofGet.md +9 -3
- package/docs/reference/functions/immutableProofVerify.md +9 -3
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/IImmutableProofServiceConfig.md +8 -8
- package/docs/reference/interfaces/IImmutableProofServiceConstructorOptions.md +89 -0
- package/package.json +9 -7
package/dist/esm/index.mjs
CHANGED
|
@@ -1,16 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { property, SortDirection, entity, EntitySchemaFactory, EntitySchemaHelper } from '@twin.org/entity';
|
|
2
|
+
import { Guards, ComponentFactory, StringHelper, Is, Validation, Converter, RandomHelper, ObjectHelper, Urn, GeneralError, NotFoundError, JsonHelper } from '@twin.org/core';
|
|
3
|
+
import { ImmutableProofTypes, ImmutableProofFailure, ImmutableProofTopics } from '@twin.org/immutable-proof-models';
|
|
4
|
+
import { DidCryptoSuites, DidTypes, DidContexts } from '@twin.org/standards-w3c-did';
|
|
4
5
|
import { HttpStatusCode, HeaderTypes, MimeTypes } from '@twin.org/web';
|
|
6
|
+
import { BackgroundTaskConnectorFactory, TaskStatus } from '@twin.org/background-task-models';
|
|
5
7
|
import { Blake2b, Sha256 } from '@twin.org/crypto';
|
|
6
8
|
import { JsonLdHelper, JsonLdProcessor } from '@twin.org/data-json-ld';
|
|
7
|
-
import { SchemaOrgDataTypes, SchemaOrgTypes } from '@twin.org/data-schema-org';
|
|
8
|
-
import { ComparisonOperator, SortDirection, property, entity, EntitySchemaFactory, EntitySchemaHelper } from '@twin.org/entity';
|
|
9
9
|
import { EntityStorageConnectorFactory } from '@twin.org/entity-storage-models';
|
|
10
10
|
import { IdentityConnectorFactory } from '@twin.org/identity-models';
|
|
11
|
-
import { ImmutableStorageConnectorFactory } from '@twin.org/immutable-storage-models';
|
|
11
|
+
import { ImmutableStorageConnectorFactory, ImmutableStorageTypes } from '@twin.org/immutable-storage-models';
|
|
12
12
|
import { VaultConnectorFactory } from '@twin.org/vault-models';
|
|
13
13
|
|
|
14
|
+
// Copyright 2024 IOTA Stiftung.
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
16
|
+
/**
|
|
17
|
+
* Class describing the immutable proof.
|
|
18
|
+
*/
|
|
19
|
+
let ImmutableProof = class ImmutableProof {
|
|
20
|
+
/**
|
|
21
|
+
* The id of the proof.
|
|
22
|
+
*/
|
|
23
|
+
id;
|
|
24
|
+
/**
|
|
25
|
+
* The identity of the node which controls the proof.
|
|
26
|
+
*/
|
|
27
|
+
nodeIdentity;
|
|
28
|
+
/**
|
|
29
|
+
* The identity of the user which created the proof.
|
|
30
|
+
*/
|
|
31
|
+
userIdentity;
|
|
32
|
+
/**
|
|
33
|
+
* The date/time of when the proof was created.
|
|
34
|
+
*/
|
|
35
|
+
dateCreated;
|
|
36
|
+
/**
|
|
37
|
+
* The associated id for the item.
|
|
38
|
+
*/
|
|
39
|
+
proofObjectId;
|
|
40
|
+
/**
|
|
41
|
+
* The associated hash for the item.
|
|
42
|
+
*/
|
|
43
|
+
proofObjectHash;
|
|
44
|
+
/**
|
|
45
|
+
* The immutable storage id.
|
|
46
|
+
*/
|
|
47
|
+
immutableStorageId;
|
|
48
|
+
};
|
|
49
|
+
__decorate([
|
|
50
|
+
property({ type: "string", isPrimary: true }),
|
|
51
|
+
__metadata("design:type", String)
|
|
52
|
+
], ImmutableProof.prototype, "id", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
property({ type: "string" }),
|
|
55
|
+
__metadata("design:type", String)
|
|
56
|
+
], ImmutableProof.prototype, "nodeIdentity", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
property({ type: "string" }),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], ImmutableProof.prototype, "userIdentity", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
property({ type: "string", format: "date-time", sortDirection: SortDirection.Descending }),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], ImmutableProof.prototype, "dateCreated", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
property({ type: "string" }),
|
|
67
|
+
__metadata("design:type", String)
|
|
68
|
+
], ImmutableProof.prototype, "proofObjectId", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
property({ type: "string" }),
|
|
71
|
+
__metadata("design:type", String)
|
|
72
|
+
], ImmutableProof.prototype, "proofObjectHash", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
property({ type: "string" }),
|
|
75
|
+
__metadata("design:type", String)
|
|
76
|
+
], ImmutableProof.prototype, "immutableStorageId", void 0);
|
|
77
|
+
ImmutableProof = __decorate([
|
|
78
|
+
entity()
|
|
79
|
+
], ImmutableProof);
|
|
80
|
+
|
|
14
81
|
/**
|
|
15
82
|
* The source used when communicating about these routes.
|
|
16
83
|
*/
|
|
@@ -46,7 +113,7 @@ function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
46
113
|
request: {
|
|
47
114
|
body: {
|
|
48
115
|
proofObject: {
|
|
49
|
-
"@context": "
|
|
116
|
+
"@context": "https://schema.org",
|
|
50
117
|
type: "Person",
|
|
51
118
|
name: "John Smith"
|
|
52
119
|
}
|
|
@@ -164,8 +231,8 @@ function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
164
231
|
operationId: "immutableProofVerify",
|
|
165
232
|
summary: "Verify a proof",
|
|
166
233
|
tag: tagsImmutableProof[0].name,
|
|
167
|
-
method: "
|
|
168
|
-
path: `${baseRouteName}/:id`,
|
|
234
|
+
method: "GET",
|
|
235
|
+
path: `${baseRouteName}/:id/verify`,
|
|
169
236
|
handler: async (httpRequestContext, request) => immutableProofVerify(httpRequestContext, componentName, request),
|
|
170
237
|
requestType: {
|
|
171
238
|
type: "IImmutableProofVerifyRequest",
|
|
@@ -175,13 +242,6 @@ function generateRestRoutesImmutableProof(baseRouteName, componentName) {
|
|
|
175
242
|
request: {
|
|
176
243
|
pathParams: {
|
|
177
244
|
id: "ais:1234567890"
|
|
178
|
-
},
|
|
179
|
-
body: {
|
|
180
|
-
proofObject: {
|
|
181
|
-
"@context": "http://schema.org",
|
|
182
|
-
type: "Person",
|
|
183
|
-
name: "John Smith"
|
|
184
|
-
}
|
|
185
245
|
}
|
|
186
246
|
}
|
|
187
247
|
}
|
|
@@ -277,10 +337,9 @@ async function immutableProofVerify(httpRequestContext, componentName, request)
|
|
|
277
337
|
Guards.object(ROUTES_SOURCE, "request", request);
|
|
278
338
|
Guards.object(ROUTES_SOURCE, "request.pathParams", request.pathParams);
|
|
279
339
|
Guards.stringValue(ROUTES_SOURCE, "request.pathParams.id", request.pathParams.id);
|
|
280
|
-
Guards.object(ROUTES_SOURCE, "request.body.proofObject", request.body.proofObject);
|
|
281
340
|
const mimeType = request.headers?.[HeaderTypes.Accept] === MimeTypes.JsonLd ? "jsonld" : "json";
|
|
282
341
|
const component = ComponentFactory.get(componentName);
|
|
283
|
-
const result = await component.verify(request.pathParams.id
|
|
342
|
+
const result = await component.verify(request.pathParams.id);
|
|
284
343
|
return {
|
|
285
344
|
headers: {
|
|
286
345
|
[HeaderTypes.ContentType]: mimeType === "json" ? MimeTypes.Json : MimeTypes.JsonLd
|
|
@@ -329,39 +388,50 @@ class ImmutableProofService {
|
|
|
329
388
|
*/
|
|
330
389
|
_immutableStorage;
|
|
331
390
|
/**
|
|
332
|
-
* The
|
|
391
|
+
* The background task connector.
|
|
392
|
+
* @internal
|
|
393
|
+
*/
|
|
394
|
+
_backgroundTaskConnector;
|
|
395
|
+
/**
|
|
396
|
+
* The event bus component.
|
|
333
397
|
* @internal
|
|
334
398
|
*/
|
|
335
|
-
|
|
399
|
+
_eventBusComponent;
|
|
336
400
|
/**
|
|
337
|
-
* The
|
|
401
|
+
* The verification method id to use for the proofs.
|
|
338
402
|
* @internal
|
|
339
403
|
*/
|
|
340
|
-
|
|
404
|
+
_verificationMethodId;
|
|
341
405
|
/**
|
|
342
|
-
*
|
|
406
|
+
* The proof hash key id to use for the proofs.
|
|
343
407
|
* @internal
|
|
344
408
|
*/
|
|
345
|
-
|
|
409
|
+
_proofHashKeyId;
|
|
410
|
+
/**
|
|
411
|
+
* The identity connector type.
|
|
412
|
+
* @internal
|
|
413
|
+
*/
|
|
414
|
+
_identityConnectorType;
|
|
346
415
|
/**
|
|
347
416
|
* Create a new instance of ImmutableProofService.
|
|
348
417
|
* @param options The dependencies for the immutable proof connector.
|
|
349
|
-
* @param options.config The configuration for the connector.
|
|
350
|
-
* @param options.vaultConnectorType The vault connector type, defaults to "vault".
|
|
351
|
-
* @param options.immutableProofEntityStorageType The entity storage for proofs, defaults to "immutable-proof".
|
|
352
|
-
* @param options.immutableStorageType The immutable storage, defaults to "immutable-proof".
|
|
353
|
-
* @param options.identityConnectorType The identity connector type, defaults to "identity".
|
|
354
418
|
*/
|
|
355
419
|
constructor(options) {
|
|
356
420
|
this._vaultConnector = VaultConnectorFactory.get(options?.vaultConnectorType ?? "vault");
|
|
357
421
|
this._proofStorage = EntityStorageConnectorFactory.get(options?.immutableProofEntityStorageType ?? StringHelper.kebabCase("ImmutableProof"));
|
|
358
|
-
this._immutableStorage = ImmutableStorageConnectorFactory.get(options?.immutableStorageType ?? "immutable-
|
|
359
|
-
this.
|
|
422
|
+
this._immutableStorage = ImmutableStorageConnectorFactory.get(options?.immutableStorageType ?? "immutable-storage");
|
|
423
|
+
this._identityConnectorType = options?.identityConnectorType ?? "identity";
|
|
424
|
+
this._identityConnector = IdentityConnectorFactory.get(this._identityConnectorType);
|
|
425
|
+
this._backgroundTaskConnector = BackgroundTaskConnectorFactory.get(options?.backgroundTaskConnectorType ?? "background-task");
|
|
426
|
+
if (Is.stringValue(options?.eventBusComponentType)) {
|
|
427
|
+
this._eventBusComponent = ComponentFactory.get(options.eventBusComponentType);
|
|
428
|
+
}
|
|
360
429
|
this._config = options?.config ?? {};
|
|
361
|
-
this.
|
|
362
|
-
this.
|
|
363
|
-
|
|
364
|
-
|
|
430
|
+
this._verificationMethodId = this._config.verificationMethodId ?? "immutable-proof-assertion";
|
|
431
|
+
this._proofHashKeyId = this._config.proofHashKeyId ?? "immutable-proof-hash";
|
|
432
|
+
this._backgroundTaskConnector.registerHandler("immutable-proof", "@twin.org/immutable-proof-task", "processProofTask", async (task) => {
|
|
433
|
+
await this.finaliseTask(task);
|
|
434
|
+
});
|
|
365
435
|
}
|
|
366
436
|
/**
|
|
367
437
|
* Create a new authentication proof.
|
|
@@ -391,7 +461,16 @@ class ImmutableProofService {
|
|
|
391
461
|
proofObjectHash: Converter.bytesToBase64(hash)
|
|
392
462
|
};
|
|
393
463
|
await this._proofStorage.set(proofEntity);
|
|
394
|
-
this.
|
|
464
|
+
const immutableProof = this.proofEntityToJsonLd(proofEntity);
|
|
465
|
+
const hashData = await this.generateHashData(proofEntity.nodeIdentity, immutableProof);
|
|
466
|
+
const proofTaskPayload = {
|
|
467
|
+
proofId: id,
|
|
468
|
+
nodeIdentity,
|
|
469
|
+
identityConnectorType: this._identityConnectorType,
|
|
470
|
+
assertionMethodId: this._verificationMethodId,
|
|
471
|
+
hashData: Converter.bytesToHex(hashData)
|
|
472
|
+
};
|
|
473
|
+
await this._backgroundTaskConnector.create("immutable-proof", proofTaskPayload);
|
|
395
474
|
return new Urn(ImmutableProofService.NAMESPACE, id).toString();
|
|
396
475
|
}
|
|
397
476
|
catch (error) {
|
|
@@ -414,7 +493,7 @@ class ImmutableProofService {
|
|
|
414
493
|
});
|
|
415
494
|
}
|
|
416
495
|
try {
|
|
417
|
-
const { immutableProof } = await this.internalGet(id);
|
|
496
|
+
const { immutableProof } = await this.internalGet(id, false);
|
|
418
497
|
const compacted = await JsonLdProcessor.compact(immutableProof, immutableProof["@context"]);
|
|
419
498
|
return compacted;
|
|
420
499
|
}
|
|
@@ -425,11 +504,10 @@ class ImmutableProofService {
|
|
|
425
504
|
/**
|
|
426
505
|
* Verify an authentication proof.
|
|
427
506
|
* @param id The id of the proof to verify.
|
|
428
|
-
* @param proofObject The object to verify as JSON-LD.
|
|
429
507
|
* @returns The result of the verification and any failures.
|
|
430
508
|
* @throws NotFoundError if the proof is not found.
|
|
431
509
|
*/
|
|
432
|
-
async verify(id
|
|
510
|
+
async verify(id) {
|
|
433
511
|
Guards.stringValue(this.CLASS_NAME, "id", id);
|
|
434
512
|
const urnParsed = Urn.fromValidString(id);
|
|
435
513
|
if (urnParsed.namespaceIdentifier() !== ImmutableProofService.NAMESPACE) {
|
|
@@ -439,7 +517,7 @@ class ImmutableProofService {
|
|
|
439
517
|
});
|
|
440
518
|
}
|
|
441
519
|
try {
|
|
442
|
-
const { verified, failure } = await this.internalGet(id,
|
|
520
|
+
const { verified, failure } = await this.internalGet(id, true);
|
|
443
521
|
return {
|
|
444
522
|
"@context": ImmutableProofTypes.ContextRoot,
|
|
445
523
|
type: ImmutableProofTypes.ImmutableProofVerification,
|
|
@@ -505,13 +583,9 @@ class ImmutableProofService {
|
|
|
505
583
|
* @returns The model.
|
|
506
584
|
* @internal
|
|
507
585
|
*/
|
|
508
|
-
|
|
586
|
+
proofEntityToJsonLd(proofEntity) {
|
|
509
587
|
const model = {
|
|
510
|
-
"@context":
|
|
511
|
-
ImmutableProofTypes.ContextRoot,
|
|
512
|
-
SchemaOrgTypes.ContextRoot,
|
|
513
|
-
DidContexts.ContextVCDataIntegrity
|
|
514
|
-
],
|
|
588
|
+
"@context": ImmutableProofTypes.ContextRoot,
|
|
515
589
|
type: ImmutableProofTypes.ImmutableProof,
|
|
516
590
|
id: proofEntity.id,
|
|
517
591
|
userIdentity: proofEntity.userIdentity,
|
|
@@ -521,74 +595,61 @@ class ImmutableProofService {
|
|
|
521
595
|
return model;
|
|
522
596
|
}
|
|
523
597
|
/**
|
|
524
|
-
*
|
|
525
|
-
* @
|
|
598
|
+
* Process a proof.
|
|
599
|
+
* @param proofEntity The proof entity to process.
|
|
526
600
|
* @internal
|
|
527
601
|
*/
|
|
528
|
-
|
|
529
|
-
if (
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
{
|
|
548
|
-
property: "dateCreated",
|
|
549
|
-
sortDirection: SortDirection.Ascending
|
|
602
|
+
async finaliseTask(task) {
|
|
603
|
+
if (task.status === TaskStatus.Success && Is.object(task.payload) && Is.object(task.result)) {
|
|
604
|
+
const proofEntity = await this._proofStorage.get(task.payload.proofId);
|
|
605
|
+
if (Is.object(proofEntity)) {
|
|
606
|
+
const immutableProof = this.proofEntityToJsonLd(proofEntity);
|
|
607
|
+
// As we are adding the proof to the data we update its context
|
|
608
|
+
immutableProof["@context"] = [
|
|
609
|
+
ImmutableProofTypes.ContextRoot,
|
|
610
|
+
DidContexts.ContextVCDataIntegrity
|
|
611
|
+
];
|
|
612
|
+
immutableProof.proof = task.result.proof;
|
|
613
|
+
if (Is.stringValue(immutableProof.proof.created)) {
|
|
614
|
+
proofEntity.dateCreated = immutableProof.proof.created;
|
|
615
|
+
}
|
|
616
|
+
const compacted = await JsonLdProcessor.compact(immutableProof, immutableProof["@context"]);
|
|
617
|
+
const immutableStoreResult = await this._immutableStorage.store(proofEntity.nodeIdentity, ObjectHelper.toBytes(compacted));
|
|
618
|
+
proofEntity.immutableStorageId = immutableStoreResult.id;
|
|
619
|
+
await this._proofStorage.set(proofEntity);
|
|
620
|
+
await this._eventBusComponent?.publish(ImmutableProofTopics.ProofCreated, { id: new Urn(ImmutableProofService.NAMESPACE, task.payload.proofId).toString() });
|
|
550
621
|
}
|
|
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
|
-
}
|
|
562
|
-
// If there are still remaining proofs, start the timer again
|
|
563
|
-
this._processing = false;
|
|
564
|
-
if (pendingProofs.entities.length > 1) {
|
|
565
|
-
this.startProcessingProofs();
|
|
566
622
|
}
|
|
567
623
|
}
|
|
568
624
|
/**
|
|
569
625
|
* Verify an authentication proof.
|
|
570
626
|
* @param id The id of the proof to verify.
|
|
571
|
-
* @param
|
|
627
|
+
* @param verify Validate the proof.
|
|
572
628
|
* @returns The result of the verification and any failures.
|
|
573
629
|
* @throws NotFoundError if the proof is not found.
|
|
574
630
|
* @internal
|
|
575
631
|
*/
|
|
576
|
-
async internalGet(id,
|
|
632
|
+
async internalGet(id, verify) {
|
|
577
633
|
const urnParsed = Urn.fromValidString(id);
|
|
578
634
|
const proofId = urnParsed.namespaceSpecific(0);
|
|
579
635
|
const proofEntity = await this._proofStorage.get(proofId);
|
|
580
636
|
if (Is.empty(proofEntity)) {
|
|
581
637
|
throw new NotFoundError(this.CLASS_NAME, "proofNotFound", id);
|
|
582
638
|
}
|
|
583
|
-
let proofModel = await this.
|
|
639
|
+
let proofModel = await this.proofEntityToJsonLd(proofEntity);
|
|
584
640
|
let verified = false;
|
|
585
641
|
let failure = ImmutableProofFailure.NotIssued;
|
|
586
642
|
if (Is.stringValue(proofEntity.immutableStorageId)) {
|
|
587
643
|
failure = ImmutableProofFailure.ProofMissing;
|
|
588
|
-
const
|
|
589
|
-
if (Is.uint8Array(
|
|
590
|
-
proofModel = ObjectHelper.fromBytes(
|
|
591
|
-
|
|
644
|
+
const immutableResult = await this._immutableStorage.get(proofEntity.immutableStorageId);
|
|
645
|
+
if (Is.uint8Array(immutableResult.data)) {
|
|
646
|
+
proofModel = ObjectHelper.fromBytes(immutableResult.data);
|
|
647
|
+
proofModel.immutableReceipt = immutableResult.receipt;
|
|
648
|
+
// As we are adding the receipt to the data we update its context
|
|
649
|
+
if (Is.array(proofModel["@context"])) {
|
|
650
|
+
proofModel["@context"].push(ImmutableStorageTypes.ContextRoot);
|
|
651
|
+
}
|
|
652
|
+
if (verify && Is.object(proofModel.proof)) {
|
|
592
653
|
if (proofModel.proof.cryptosuite !== DidCryptoSuites.EdDSAJcs2022) {
|
|
593
654
|
failure = ImmutableProofFailure.CryptoSuiteMismatch;
|
|
594
655
|
}
|
|
@@ -624,84 +685,21 @@ class ImmutableProofService {
|
|
|
624
685
|
* @internal
|
|
625
686
|
*/
|
|
626
687
|
async generateHashData(nodeIdentity, immutableProof) {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
const
|
|
688
|
+
// We hash the data for the proof without the the proof or immutable receipt for the proof
|
|
689
|
+
// without these objects we can simplify the context
|
|
690
|
+
const object = ObjectHelper.omit(immutableProof, ["proof", "immutableReceipt"]);
|
|
691
|
+
object["@context"] = ImmutableProofTypes.ContextRoot;
|
|
692
|
+
const canonicalDocument = JsonHelper.canonicalize(object);
|
|
693
|
+
const proofKey = await this._vaultConnector.getKey(`${nodeIdentity}/${this._proofHashKeyId}`);
|
|
694
|
+
const proofHash = Sha256.sum256(proofKey.privateKey);
|
|
630
695
|
const transformedDocumentHash = Sha256.sum256(Converter.utf8ToBytes(canonicalDocument));
|
|
631
|
-
const hashData = new Uint8Array(
|
|
632
|
-
hashData.set(
|
|
633
|
-
hashData.set(transformedDocumentHash,
|
|
696
|
+
const hashData = new Uint8Array(proofHash.length + transformedDocumentHash.length);
|
|
697
|
+
hashData.set(proofHash);
|
|
698
|
+
hashData.set(transformedDocumentHash, proofHash.length);
|
|
634
699
|
return hashData;
|
|
635
700
|
}
|
|
636
701
|
}
|
|
637
702
|
|
|
638
|
-
// Copyright 2024 IOTA Stiftung.
|
|
639
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
640
|
-
/**
|
|
641
|
-
* Class describing the immutable proof.
|
|
642
|
-
*/
|
|
643
|
-
let ImmutableProof = class ImmutableProof {
|
|
644
|
-
/**
|
|
645
|
-
* The id of the proof.
|
|
646
|
-
*/
|
|
647
|
-
id;
|
|
648
|
-
/**
|
|
649
|
-
* The identity of the node which controls the proof.
|
|
650
|
-
*/
|
|
651
|
-
nodeIdentity;
|
|
652
|
-
/**
|
|
653
|
-
* The identity of the user which created the proof.
|
|
654
|
-
*/
|
|
655
|
-
userIdentity;
|
|
656
|
-
/**
|
|
657
|
-
* The date/time of when the proof was created.
|
|
658
|
-
*/
|
|
659
|
-
dateCreated;
|
|
660
|
-
/**
|
|
661
|
-
* The associated id for the item.
|
|
662
|
-
*/
|
|
663
|
-
proofObjectId;
|
|
664
|
-
/**
|
|
665
|
-
* The associated hash for the item.
|
|
666
|
-
*/
|
|
667
|
-
proofObjectHash;
|
|
668
|
-
/**
|
|
669
|
-
* The immutable storage id.
|
|
670
|
-
*/
|
|
671
|
-
immutableStorageId;
|
|
672
|
-
};
|
|
673
|
-
__decorate([
|
|
674
|
-
property({ type: "string", isPrimary: true }),
|
|
675
|
-
__metadata("design:type", String)
|
|
676
|
-
], ImmutableProof.prototype, "id", void 0);
|
|
677
|
-
__decorate([
|
|
678
|
-
property({ type: "string" }),
|
|
679
|
-
__metadata("design:type", String)
|
|
680
|
-
], ImmutableProof.prototype, "nodeIdentity", void 0);
|
|
681
|
-
__decorate([
|
|
682
|
-
property({ type: "string" }),
|
|
683
|
-
__metadata("design:type", String)
|
|
684
|
-
], ImmutableProof.prototype, "userIdentity", void 0);
|
|
685
|
-
__decorate([
|
|
686
|
-
property({ type: "string", format: "date-time", sortDirection: SortDirection.Descending }),
|
|
687
|
-
__metadata("design:type", String)
|
|
688
|
-
], ImmutableProof.prototype, "dateCreated", void 0);
|
|
689
|
-
__decorate([
|
|
690
|
-
property({ type: "string" }),
|
|
691
|
-
__metadata("design:type", String)
|
|
692
|
-
], ImmutableProof.prototype, "proofObjectId", void 0);
|
|
693
|
-
__decorate([
|
|
694
|
-
property({ type: "string" }),
|
|
695
|
-
__metadata("design:type", String)
|
|
696
|
-
], ImmutableProof.prototype, "proofObjectHash", void 0);
|
|
697
|
-
__decorate([
|
|
698
|
-
property({ type: "string" }),
|
|
699
|
-
__metadata("design:type", String)
|
|
700
|
-
], ImmutableProof.prototype, "immutableStorageId", void 0);
|
|
701
|
-
ImmutableProof = __decorate([
|
|
702
|
-
entity()
|
|
703
|
-
], ImmutableProof);
|
|
704
|
-
|
|
705
703
|
const restEntryPoints = [
|
|
706
704
|
{
|
|
707
705
|
name: "immutable-proof",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type IJsonLdNodeObject } from "@twin.org/data-json-ld";
|
|
2
|
-
import { type
|
|
3
|
-
import type {
|
|
2
|
+
import { type IImmutableProof, type IImmutableProofComponent, type IImmutableProofVerification } from "@twin.org/immutable-proof-models";
|
|
3
|
+
import type { IImmutableProofServiceConstructorOptions } from "./models/IImmutableProofServiceConstructorOptions";
|
|
4
4
|
/**
|
|
5
5
|
* Class for performing immutable proof operations.
|
|
6
6
|
*/
|
|
@@ -16,19 +16,8 @@ export declare class ImmutableProofService implements IImmutableProofComponent {
|
|
|
16
16
|
/**
|
|
17
17
|
* Create a new instance of ImmutableProofService.
|
|
18
18
|
* @param options The dependencies for the immutable proof connector.
|
|
19
|
-
* @param options.config The configuration for the connector.
|
|
20
|
-
* @param options.vaultConnectorType The vault connector type, defaults to "vault".
|
|
21
|
-
* @param options.immutableProofEntityStorageType The entity storage for proofs, defaults to "immutable-proof".
|
|
22
|
-
* @param options.immutableStorageType The immutable storage, defaults to "immutable-proof".
|
|
23
|
-
* @param options.identityConnectorType The identity connector type, defaults to "identity".
|
|
24
19
|
*/
|
|
25
|
-
constructor(options?:
|
|
26
|
-
vaultConnectorType?: string;
|
|
27
|
-
immutableProofEntityStorageType?: string;
|
|
28
|
-
immutableStorageType?: string;
|
|
29
|
-
config?: IImmutableProofServiceConfig;
|
|
30
|
-
identityConnectorType?: string;
|
|
31
|
-
});
|
|
20
|
+
constructor(options?: IImmutableProofServiceConstructorOptions);
|
|
32
21
|
/**
|
|
33
22
|
* Create a new authentication proof.
|
|
34
23
|
* @param proofObject The object for the proof as JSON-LD.
|
|
@@ -47,11 +36,10 @@ export declare class ImmutableProofService implements IImmutableProofComponent {
|
|
|
47
36
|
/**
|
|
48
37
|
* Verify an authentication proof.
|
|
49
38
|
* @param id The id of the proof to verify.
|
|
50
|
-
* @param proofObject The object to verify as JSON-LD.
|
|
51
39
|
* @returns The result of the verification and any failures.
|
|
52
40
|
* @throws NotFoundError if the proof is not found.
|
|
53
41
|
*/
|
|
54
|
-
verify(id: string
|
|
42
|
+
verify(id: string): Promise<IImmutableProofVerification>;
|
|
55
43
|
/**
|
|
56
44
|
* Remove the immutable storage for the proof.
|
|
57
45
|
* @param id The id of the proof to remove the storage from.
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
export * from "./entities/immutableProof";
|
|
1
2
|
export * from "./immutableProofRoutes";
|
|
2
3
|
export * from "./immutableProofService";
|
|
3
|
-
export * from "./entities/immutableProof";
|
|
4
4
|
export * from "./models/IImmutableProofServiceConfig";
|
|
5
|
+
export * from "./models/IImmutableProofServiceConstructorOptions";
|
|
5
6
|
export * from "./restEntryPoints";
|
|
6
7
|
export * from "./schema";
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export interface IImmutableProofServiceConfig {
|
|
5
5
|
/**
|
|
6
|
-
* The
|
|
7
|
-
* @default immutable-proof
|
|
6
|
+
* The verification method id to use for the proof.
|
|
7
|
+
* @default immutable-proof-assertion
|
|
8
8
|
*/
|
|
9
|
-
|
|
9
|
+
verificationMethodId?: string;
|
|
10
10
|
/**
|
|
11
|
-
* The key to use in the proof
|
|
12
|
-
* @default immutable-proof
|
|
11
|
+
* The key to use in the proof hash.
|
|
12
|
+
* @default immutable-proof-hash
|
|
13
13
|
*/
|
|
14
|
-
|
|
14
|
+
proofHashKeyId?: string;
|
|
15
15
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { IImmutableProofServiceConfig } from "./IImmutableProofServiceConfig";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the immutable proof service constructor.
|
|
4
|
+
*/
|
|
5
|
+
export interface IImmutableProofServiceConstructorOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The vault connector type.
|
|
8
|
+
* @default vault
|
|
9
|
+
*/
|
|
10
|
+
vaultConnectorType?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The entity storage for proofs.
|
|
13
|
+
* @default immutable-proof
|
|
14
|
+
*/
|
|
15
|
+
immutableProofEntityStorageType?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The immutable storage.
|
|
18
|
+
* @default immutable-storage
|
|
19
|
+
*/
|
|
20
|
+
immutableStorageType?: string;
|
|
21
|
+
/**
|
|
22
|
+
* The identity connector type.
|
|
23
|
+
* @default identity
|
|
24
|
+
*/
|
|
25
|
+
identityConnectorType?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The background task connector type.
|
|
28
|
+
* @default background-task
|
|
29
|
+
*/
|
|
30
|
+
backgroundTaskConnectorType?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The event bus component type, defaults to no event bus.
|
|
33
|
+
*/
|
|
34
|
+
eventBusComponentType?: string;
|
|
35
|
+
/**
|
|
36
|
+
* The configuration for the connector.
|
|
37
|
+
*/
|
|
38
|
+
config?: IImmutableProofServiceConfig;
|
|
39
|
+
}
|
package/docs/changelog.md
CHANGED