@twin.org/identity-connector-entity-storage 0.0.1-next.23 → 0.0.1-next.25
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 +53 -41
- package/dist/esm/index.mjs +53 -41
- package/dist/types/entityStorageIdentityConnector.d.ts +5 -5
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/EntityStorageIdentityConnector.md +9 -9
- package/docs/reference/functions/initSchema.md +2 -2
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -36,19 +36,19 @@ exports.IdentityDocument = class IdentityDocument {
|
|
|
36
36
|
__decorate([
|
|
37
37
|
entity.property({ type: "string", isPrimary: true }),
|
|
38
38
|
__metadata("design:type", String)
|
|
39
|
-
], exports.IdentityDocument.prototype, "id",
|
|
39
|
+
], exports.IdentityDocument.prototype, "id", void 0);
|
|
40
40
|
__decorate([
|
|
41
41
|
entity.property({ type: "object" }),
|
|
42
42
|
__metadata("design:type", Object)
|
|
43
|
-
], exports.IdentityDocument.prototype, "document",
|
|
43
|
+
], exports.IdentityDocument.prototype, "document", void 0);
|
|
44
44
|
__decorate([
|
|
45
45
|
entity.property({ type: "string" }),
|
|
46
46
|
__metadata("design:type", String)
|
|
47
|
-
], exports.IdentityDocument.prototype, "signature",
|
|
47
|
+
], exports.IdentityDocument.prototype, "signature", void 0);
|
|
48
48
|
__decorate([
|
|
49
49
|
entity.property({ type: "string" }),
|
|
50
50
|
__metadata("design:type", String)
|
|
51
|
-
], exports.IdentityDocument.prototype, "controller",
|
|
51
|
+
], exports.IdentityDocument.prototype, "controller", void 0);
|
|
52
52
|
exports.IdentityDocument = __decorate([
|
|
53
53
|
entity.entity()
|
|
54
54
|
], exports.IdentityDocument);
|
|
@@ -75,15 +75,15 @@ exports.IdentityProfile = class IdentityProfile {
|
|
|
75
75
|
__decorate([
|
|
76
76
|
entity.property({ type: "string", isPrimary: true }),
|
|
77
77
|
__metadata("design:type", String)
|
|
78
|
-
], exports.IdentityProfile.prototype, "identity",
|
|
78
|
+
], exports.IdentityProfile.prototype, "identity", void 0);
|
|
79
79
|
__decorate([
|
|
80
80
|
entity.property({ type: "object" }),
|
|
81
81
|
__metadata("design:type", Object)
|
|
82
|
-
], exports.IdentityProfile.prototype, "publicProfile",
|
|
82
|
+
], exports.IdentityProfile.prototype, "publicProfile", void 0);
|
|
83
83
|
__decorate([
|
|
84
84
|
entity.property({ type: "object" }),
|
|
85
85
|
__metadata("design:type", Object)
|
|
86
|
-
], exports.IdentityProfile.prototype, "privateProfile",
|
|
86
|
+
], exports.IdentityProfile.prototype, "privateProfile", void 0);
|
|
87
87
|
exports.IdentityProfile = __decorate([
|
|
88
88
|
entity.entity()
|
|
89
89
|
], exports.IdentityProfile);
|
|
@@ -251,8 +251,8 @@ class EntityStorageIdentityConnector {
|
|
|
251
251
|
core.Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
252
252
|
core.Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
253
253
|
try {
|
|
254
|
-
const idParts = identityModels.DocumentHelper.
|
|
255
|
-
if (core.Is.empty(idParts.
|
|
254
|
+
const idParts = identityModels.DocumentHelper.parseId(verificationMethodId);
|
|
255
|
+
if (core.Is.empty(idParts.fragment)) {
|
|
256
256
|
throw new core.NotFoundError(this.CLASS_NAME, "missingDid", verificationMethodId);
|
|
257
257
|
}
|
|
258
258
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -300,8 +300,18 @@ class EntityStorageIdentityConnector {
|
|
|
300
300
|
core.Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
301
301
|
core.Guards.stringValue(this.CLASS_NAME, "documentId", documentId);
|
|
302
302
|
core.Guards.stringValue(this.CLASS_NAME, "serviceId", serviceId);
|
|
303
|
-
core.
|
|
304
|
-
|
|
303
|
+
if (core.Is.array(serviceType)) {
|
|
304
|
+
core.Guards.arrayValue(this.CLASS_NAME, "serviceType", serviceType);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
core.Guards.stringValue(this.CLASS_NAME, "serviceType", serviceType);
|
|
308
|
+
}
|
|
309
|
+
if (core.Is.array(serviceEndpoint)) {
|
|
310
|
+
core.Guards.arrayValue(this.CLASS_NAME, "serviceEndpoint", serviceEndpoint);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
core.Guards.stringValue(this.CLASS_NAME, "serviceEndpoint", serviceEndpoint);
|
|
314
|
+
}
|
|
305
315
|
try {
|
|
306
316
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(documentId);
|
|
307
317
|
if (core.Is.undefined(didIdentityDocument)) {
|
|
@@ -341,8 +351,8 @@ class EntityStorageIdentityConnector {
|
|
|
341
351
|
core.Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
342
352
|
core.Guards.stringValue(this.CLASS_NAME, "serviceId", serviceId);
|
|
343
353
|
try {
|
|
344
|
-
const idParts = identityModels.DocumentHelper.
|
|
345
|
-
if (core.Is.empty(idParts.
|
|
354
|
+
const idParts = identityModels.DocumentHelper.parseId(serviceId);
|
|
355
|
+
if (core.Is.empty(idParts.fragment)) {
|
|
346
356
|
throw new core.NotFoundError(this.CLASS_NAME, "missingDid", serviceId);
|
|
347
357
|
}
|
|
348
358
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -374,21 +384,21 @@ class EntityStorageIdentityConnector {
|
|
|
374
384
|
* @param controller The controller of the identity who can make changes.
|
|
375
385
|
* @param verificationMethodId The verification method id to use.
|
|
376
386
|
* @param id The id of the credential.
|
|
377
|
-
* @param
|
|
387
|
+
* @param subject The credential subject to store in the verifiable credential.
|
|
378
388
|
* @param revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.
|
|
379
389
|
* @returns The created verifiable credential and its token.
|
|
380
390
|
* @throws NotFoundError if the id can not be resolved.
|
|
381
391
|
*/
|
|
382
|
-
async createVerifiableCredential(controller, verificationMethodId, id,
|
|
392
|
+
async createVerifiableCredential(controller, verificationMethodId, id, subject, revocationIndex) {
|
|
383
393
|
core.Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
384
394
|
core.Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
385
|
-
core.Guards.object(this.CLASS_NAME, "
|
|
395
|
+
core.Guards.object(this.CLASS_NAME, "subject", subject);
|
|
386
396
|
if (!core.Is.undefined(revocationIndex)) {
|
|
387
397
|
core.Guards.number(this.CLASS_NAME, "revocationIndex", revocationIndex);
|
|
388
398
|
}
|
|
389
399
|
try {
|
|
390
|
-
const idParts = identityModels.DocumentHelper.
|
|
391
|
-
if (core.Is.empty(idParts.
|
|
400
|
+
const idParts = identityModels.DocumentHelper.parseId(verificationMethodId);
|
|
401
|
+
if (core.Is.empty(idParts.fragment)) {
|
|
392
402
|
throw new core.NotFoundError(this.CLASS_NAME, "missingDid", verificationMethodId);
|
|
393
403
|
}
|
|
394
404
|
const issuerIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -414,11 +424,13 @@ class EntityStorageIdentityConnector {
|
|
|
414
424
|
});
|
|
415
425
|
}
|
|
416
426
|
const revocationService = issuerDidDocument.service?.find(s => s.id.endsWith("#revocation"));
|
|
417
|
-
const
|
|
427
|
+
const subjectClone = core.ObjectHelper.clone(subject);
|
|
418
428
|
const finalTypes = [standardsW3cDid.DidTypes.VerifiableCredential];
|
|
419
|
-
const credContext = core.ObjectHelper.extractProperty(
|
|
420
|
-
|
|
421
|
-
|
|
429
|
+
const credContext = core.ObjectHelper.extractProperty(subjectClone, [
|
|
430
|
+
"@context"
|
|
431
|
+
]);
|
|
432
|
+
const credId = core.ObjectHelper.extractProperty(subjectClone, ["@id", "id"], false);
|
|
433
|
+
const credType = core.ObjectHelper.extractProperty(subjectClone, ["@type", "type"]);
|
|
422
434
|
if (core.Is.stringValue(credType)) {
|
|
423
435
|
finalTypes.push(credType);
|
|
424
436
|
}
|
|
@@ -426,7 +438,7 @@ class EntityStorageIdentityConnector {
|
|
|
426
438
|
"@context": dataJsonLd.JsonLdProcessor.combineContexts(standardsW3cDid.DidContexts.ContextVCv2, credContext),
|
|
427
439
|
id,
|
|
428
440
|
type: finalTypes,
|
|
429
|
-
credentialSubject:
|
|
441
|
+
credentialSubject: subjectClone,
|
|
430
442
|
issuer: issuerDidDocument.id,
|
|
431
443
|
issuanceDate: new Date().toISOString(),
|
|
432
444
|
credentialStatus: revocationService && !core.Is.undefined(revocationIndex)
|
|
@@ -467,7 +479,7 @@ class EntityStorageIdentityConnector {
|
|
|
467
479
|
vc: jwtVc
|
|
468
480
|
};
|
|
469
481
|
const signature = await web.Jwt.encodeWithSigner(jwtHeader, jwtPayload, async (alg, key, payload) => {
|
|
470
|
-
const sig = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(idParts.id, idParts.
|
|
482
|
+
const sig = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(idParts.id, idParts.fragment ?? ""), payload);
|
|
471
483
|
return sig;
|
|
472
484
|
});
|
|
473
485
|
return {
|
|
@@ -634,7 +646,7 @@ class EntityStorageIdentityConnector {
|
|
|
634
646
|
/**
|
|
635
647
|
* Create a verifiable presentation from the supplied verifiable credentials.
|
|
636
648
|
* @param controller The controller of the identity who can make changes.
|
|
637
|
-
* @param
|
|
649
|
+
* @param verificationMethodId The method to associate with the presentation.
|
|
638
650
|
* @param presentationId The id of the presentation.
|
|
639
651
|
* @param contexts The contexts for the data stored in the verifiable credential.
|
|
640
652
|
* @param types The types for the data stored in the verifiable credential.
|
|
@@ -643,9 +655,9 @@ class EntityStorageIdentityConnector {
|
|
|
643
655
|
* @returns The created verifiable presentation and its token.
|
|
644
656
|
* @throws NotFoundError if the id can not be resolved.
|
|
645
657
|
*/
|
|
646
|
-
async createVerifiablePresentation(controller,
|
|
658
|
+
async createVerifiablePresentation(controller, verificationMethodId, presentationId, contexts, types, verifiableCredentials, expiresInMinutes) {
|
|
647
659
|
core.Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
648
|
-
core.Guards.stringValue(this.CLASS_NAME, "
|
|
660
|
+
core.Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
649
661
|
if (core.Is.array(types)) {
|
|
650
662
|
core.Guards.arrayValue(this.CLASS_NAME, "types", types);
|
|
651
663
|
}
|
|
@@ -657,9 +669,9 @@ class EntityStorageIdentityConnector {
|
|
|
657
669
|
core.Guards.integer(this.CLASS_NAME, "expiresInMinutes", expiresInMinutes);
|
|
658
670
|
}
|
|
659
671
|
try {
|
|
660
|
-
const idParts = identityModels.DocumentHelper.
|
|
661
|
-
if (core.Is.empty(idParts.
|
|
662
|
-
throw new core.NotFoundError(this.CLASS_NAME, "missingDid",
|
|
672
|
+
const idParts = identityModels.DocumentHelper.parseId(verificationMethodId);
|
|
673
|
+
if (core.Is.empty(idParts.fragment)) {
|
|
674
|
+
throw new core.NotFoundError(this.CLASS_NAME, "missingDid", verificationMethodId);
|
|
663
675
|
}
|
|
664
676
|
const holderIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
665
677
|
if (core.Is.undefined(holderIdentityDocument)) {
|
|
@@ -670,17 +682,17 @@ class EntityStorageIdentityConnector {
|
|
|
670
682
|
const methods = this.getAllMethods(holderDidDocument);
|
|
671
683
|
const methodAndArray = methods.find(m => {
|
|
672
684
|
if (core.Is.string(m.method)) {
|
|
673
|
-
return m.method ===
|
|
685
|
+
return m.method === verificationMethodId;
|
|
674
686
|
}
|
|
675
|
-
return m.method.id ===
|
|
687
|
+
return m.method.id === verificationMethodId;
|
|
676
688
|
});
|
|
677
689
|
if (!methodAndArray) {
|
|
678
|
-
throw new core.GeneralError(this.CLASS_NAME, "methodMissing", { method:
|
|
690
|
+
throw new core.GeneralError(this.CLASS_NAME, "methodMissing", { method: verificationMethodId });
|
|
679
691
|
}
|
|
680
692
|
const didMethod = methodAndArray.method;
|
|
681
693
|
if (!core.Is.stringValue(didMethod.publicKeyJwk?.x)) {
|
|
682
694
|
throw new core.GeneralError(this.CLASS_NAME, "publicKeyJwkMissing", {
|
|
683
|
-
method:
|
|
695
|
+
method: verificationMethodId
|
|
684
696
|
});
|
|
685
697
|
}
|
|
686
698
|
const finalTypes = [standardsW3cDid.DidTypes.VerifiablePresentation];
|
|
@@ -717,7 +729,7 @@ class EntityStorageIdentityConnector {
|
|
|
717
729
|
jwtPayload.exp = Math.floor(Date.now() / 1000) + expiresInSeconds;
|
|
718
730
|
}
|
|
719
731
|
const signature = await web.Jwt.encodeWithSigner(jwtHeader, jwtPayload, async (alg, key, payload) => {
|
|
720
|
-
const sig = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(idParts.id, idParts.
|
|
732
|
+
const sig = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(idParts.id, idParts.fragment ?? ""), payload);
|
|
721
733
|
return sig;
|
|
722
734
|
});
|
|
723
735
|
return {
|
|
@@ -810,8 +822,8 @@ class EntityStorageIdentityConnector {
|
|
|
810
822
|
core.Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
811
823
|
core.Guards.uint8Array(this.CLASS_NAME, "bytes", bytes);
|
|
812
824
|
try {
|
|
813
|
-
const idParts = identityModels.DocumentHelper.
|
|
814
|
-
if (core.Is.empty(idParts.
|
|
825
|
+
const idParts = identityModels.DocumentHelper.parseId(verificationMethodId);
|
|
826
|
+
if (core.Is.empty(idParts.fragment)) {
|
|
815
827
|
throw new core.NotFoundError(this.CLASS_NAME, "missingDid", verificationMethodId);
|
|
816
828
|
}
|
|
817
829
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -836,7 +848,7 @@ class EntityStorageIdentityConnector {
|
|
|
836
848
|
method: verificationMethodId
|
|
837
849
|
});
|
|
838
850
|
}
|
|
839
|
-
const signature = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(didDocument.id, idParts.
|
|
851
|
+
const signature = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(didDocument.id, idParts.fragment ?? ""), bytes);
|
|
840
852
|
return {
|
|
841
853
|
"@context": standardsW3cDid.DidContexts.ContextVCDataIntegrity,
|
|
842
854
|
type: standardsW3cDid.DidTypes.DataIntegrityProof,
|
|
@@ -871,8 +883,8 @@ class EntityStorageIdentityConnector {
|
|
|
871
883
|
if (proof.cryptosuite !== standardsW3cDid.DidCryptoSuites.EdDSAJcs2022) {
|
|
872
884
|
throw new core.GeneralError(this.CLASS_NAME, "cryptoSuite", { cryptosuite: proof.cryptosuite });
|
|
873
885
|
}
|
|
874
|
-
const idParts = identityModels.DocumentHelper.
|
|
875
|
-
if (core.Is.empty(idParts.
|
|
886
|
+
const idParts = identityModels.DocumentHelper.parseId(proof.verificationMethod);
|
|
887
|
+
if (core.Is.empty(idParts.fragment)) {
|
|
876
888
|
throw new core.NotFoundError(this.CLASS_NAME, "missingDid", proof.verificationMethod);
|
|
877
889
|
}
|
|
878
890
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -899,7 +911,7 @@ class EntityStorageIdentityConnector {
|
|
|
899
911
|
method: proof.verificationMethodId
|
|
900
912
|
});
|
|
901
913
|
}
|
|
902
|
-
return this._vaultConnector.verify(EntityStorageIdentityConnector.buildVaultKey(didIdentityDocument.id, idParts.
|
|
914
|
+
return this._vaultConnector.verify(EntityStorageIdentityConnector.buildVaultKey(didIdentityDocument.id, idParts.fragment), bytes, core.Converter.base58ToBytes(proof.proofValue));
|
|
903
915
|
}
|
|
904
916
|
catch (error) {
|
|
905
917
|
throw new core.GeneralError(this.CLASS_NAME, "verifyProofFailed", undefined, error);
|
package/dist/esm/index.mjs
CHANGED
|
@@ -34,19 +34,19 @@ let IdentityDocument = class IdentityDocument {
|
|
|
34
34
|
__decorate([
|
|
35
35
|
property({ type: "string", isPrimary: true }),
|
|
36
36
|
__metadata("design:type", String)
|
|
37
|
-
], IdentityDocument.prototype, "id",
|
|
37
|
+
], IdentityDocument.prototype, "id", void 0);
|
|
38
38
|
__decorate([
|
|
39
39
|
property({ type: "object" }),
|
|
40
40
|
__metadata("design:type", Object)
|
|
41
|
-
], IdentityDocument.prototype, "document",
|
|
41
|
+
], IdentityDocument.prototype, "document", void 0);
|
|
42
42
|
__decorate([
|
|
43
43
|
property({ type: "string" }),
|
|
44
44
|
__metadata("design:type", String)
|
|
45
|
-
], IdentityDocument.prototype, "signature",
|
|
45
|
+
], IdentityDocument.prototype, "signature", void 0);
|
|
46
46
|
__decorate([
|
|
47
47
|
property({ type: "string" }),
|
|
48
48
|
__metadata("design:type", String)
|
|
49
|
-
], IdentityDocument.prototype, "controller",
|
|
49
|
+
], IdentityDocument.prototype, "controller", void 0);
|
|
50
50
|
IdentityDocument = __decorate([
|
|
51
51
|
entity()
|
|
52
52
|
], IdentityDocument);
|
|
@@ -73,15 +73,15 @@ let IdentityProfile = class IdentityProfile {
|
|
|
73
73
|
__decorate([
|
|
74
74
|
property({ type: "string", isPrimary: true }),
|
|
75
75
|
__metadata("design:type", String)
|
|
76
|
-
], IdentityProfile.prototype, "identity",
|
|
76
|
+
], IdentityProfile.prototype, "identity", void 0);
|
|
77
77
|
__decorate([
|
|
78
78
|
property({ type: "object" }),
|
|
79
79
|
__metadata("design:type", Object)
|
|
80
|
-
], IdentityProfile.prototype, "publicProfile",
|
|
80
|
+
], IdentityProfile.prototype, "publicProfile", void 0);
|
|
81
81
|
__decorate([
|
|
82
82
|
property({ type: "object" }),
|
|
83
83
|
__metadata("design:type", Object)
|
|
84
|
-
], IdentityProfile.prototype, "privateProfile",
|
|
84
|
+
], IdentityProfile.prototype, "privateProfile", void 0);
|
|
85
85
|
IdentityProfile = __decorate([
|
|
86
86
|
entity()
|
|
87
87
|
], IdentityProfile);
|
|
@@ -249,8 +249,8 @@ class EntityStorageIdentityConnector {
|
|
|
249
249
|
Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
250
250
|
Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
251
251
|
try {
|
|
252
|
-
const idParts = DocumentHelper.
|
|
253
|
-
if (Is.empty(idParts.
|
|
252
|
+
const idParts = DocumentHelper.parseId(verificationMethodId);
|
|
253
|
+
if (Is.empty(idParts.fragment)) {
|
|
254
254
|
throw new NotFoundError(this.CLASS_NAME, "missingDid", verificationMethodId);
|
|
255
255
|
}
|
|
256
256
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -298,8 +298,18 @@ class EntityStorageIdentityConnector {
|
|
|
298
298
|
Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
299
299
|
Guards.stringValue(this.CLASS_NAME, "documentId", documentId);
|
|
300
300
|
Guards.stringValue(this.CLASS_NAME, "serviceId", serviceId);
|
|
301
|
-
|
|
302
|
-
|
|
301
|
+
if (Is.array(serviceType)) {
|
|
302
|
+
Guards.arrayValue(this.CLASS_NAME, "serviceType", serviceType);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
Guards.stringValue(this.CLASS_NAME, "serviceType", serviceType);
|
|
306
|
+
}
|
|
307
|
+
if (Is.array(serviceEndpoint)) {
|
|
308
|
+
Guards.arrayValue(this.CLASS_NAME, "serviceEndpoint", serviceEndpoint);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
Guards.stringValue(this.CLASS_NAME, "serviceEndpoint", serviceEndpoint);
|
|
312
|
+
}
|
|
303
313
|
try {
|
|
304
314
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(documentId);
|
|
305
315
|
if (Is.undefined(didIdentityDocument)) {
|
|
@@ -339,8 +349,8 @@ class EntityStorageIdentityConnector {
|
|
|
339
349
|
Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
340
350
|
Guards.stringValue(this.CLASS_NAME, "serviceId", serviceId);
|
|
341
351
|
try {
|
|
342
|
-
const idParts = DocumentHelper.
|
|
343
|
-
if (Is.empty(idParts.
|
|
352
|
+
const idParts = DocumentHelper.parseId(serviceId);
|
|
353
|
+
if (Is.empty(idParts.fragment)) {
|
|
344
354
|
throw new NotFoundError(this.CLASS_NAME, "missingDid", serviceId);
|
|
345
355
|
}
|
|
346
356
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -372,21 +382,21 @@ class EntityStorageIdentityConnector {
|
|
|
372
382
|
* @param controller The controller of the identity who can make changes.
|
|
373
383
|
* @param verificationMethodId The verification method id to use.
|
|
374
384
|
* @param id The id of the credential.
|
|
375
|
-
* @param
|
|
385
|
+
* @param subject The credential subject to store in the verifiable credential.
|
|
376
386
|
* @param revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.
|
|
377
387
|
* @returns The created verifiable credential and its token.
|
|
378
388
|
* @throws NotFoundError if the id can not be resolved.
|
|
379
389
|
*/
|
|
380
|
-
async createVerifiableCredential(controller, verificationMethodId, id,
|
|
390
|
+
async createVerifiableCredential(controller, verificationMethodId, id, subject, revocationIndex) {
|
|
381
391
|
Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
382
392
|
Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
383
|
-
Guards.object(this.CLASS_NAME, "
|
|
393
|
+
Guards.object(this.CLASS_NAME, "subject", subject);
|
|
384
394
|
if (!Is.undefined(revocationIndex)) {
|
|
385
395
|
Guards.number(this.CLASS_NAME, "revocationIndex", revocationIndex);
|
|
386
396
|
}
|
|
387
397
|
try {
|
|
388
|
-
const idParts = DocumentHelper.
|
|
389
|
-
if (Is.empty(idParts.
|
|
398
|
+
const idParts = DocumentHelper.parseId(verificationMethodId);
|
|
399
|
+
if (Is.empty(idParts.fragment)) {
|
|
390
400
|
throw new NotFoundError(this.CLASS_NAME, "missingDid", verificationMethodId);
|
|
391
401
|
}
|
|
392
402
|
const issuerIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -412,11 +422,13 @@ class EntityStorageIdentityConnector {
|
|
|
412
422
|
});
|
|
413
423
|
}
|
|
414
424
|
const revocationService = issuerDidDocument.service?.find(s => s.id.endsWith("#revocation"));
|
|
415
|
-
const
|
|
425
|
+
const subjectClone = ObjectHelper.clone(subject);
|
|
416
426
|
const finalTypes = [DidTypes.VerifiableCredential];
|
|
417
|
-
const credContext = ObjectHelper.extractProperty(
|
|
418
|
-
|
|
419
|
-
|
|
427
|
+
const credContext = ObjectHelper.extractProperty(subjectClone, [
|
|
428
|
+
"@context"
|
|
429
|
+
]);
|
|
430
|
+
const credId = ObjectHelper.extractProperty(subjectClone, ["@id", "id"], false);
|
|
431
|
+
const credType = ObjectHelper.extractProperty(subjectClone, ["@type", "type"]);
|
|
420
432
|
if (Is.stringValue(credType)) {
|
|
421
433
|
finalTypes.push(credType);
|
|
422
434
|
}
|
|
@@ -424,7 +436,7 @@ class EntityStorageIdentityConnector {
|
|
|
424
436
|
"@context": JsonLdProcessor.combineContexts(DidContexts.ContextVCv2, credContext),
|
|
425
437
|
id,
|
|
426
438
|
type: finalTypes,
|
|
427
|
-
credentialSubject:
|
|
439
|
+
credentialSubject: subjectClone,
|
|
428
440
|
issuer: issuerDidDocument.id,
|
|
429
441
|
issuanceDate: new Date().toISOString(),
|
|
430
442
|
credentialStatus: revocationService && !Is.undefined(revocationIndex)
|
|
@@ -465,7 +477,7 @@ class EntityStorageIdentityConnector {
|
|
|
465
477
|
vc: jwtVc
|
|
466
478
|
};
|
|
467
479
|
const signature = await Jwt.encodeWithSigner(jwtHeader, jwtPayload, async (alg, key, payload) => {
|
|
468
|
-
const sig = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(idParts.id, idParts.
|
|
480
|
+
const sig = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(idParts.id, idParts.fragment ?? ""), payload);
|
|
469
481
|
return sig;
|
|
470
482
|
});
|
|
471
483
|
return {
|
|
@@ -632,7 +644,7 @@ class EntityStorageIdentityConnector {
|
|
|
632
644
|
/**
|
|
633
645
|
* Create a verifiable presentation from the supplied verifiable credentials.
|
|
634
646
|
* @param controller The controller of the identity who can make changes.
|
|
635
|
-
* @param
|
|
647
|
+
* @param verificationMethodId The method to associate with the presentation.
|
|
636
648
|
* @param presentationId The id of the presentation.
|
|
637
649
|
* @param contexts The contexts for the data stored in the verifiable credential.
|
|
638
650
|
* @param types The types for the data stored in the verifiable credential.
|
|
@@ -641,9 +653,9 @@ class EntityStorageIdentityConnector {
|
|
|
641
653
|
* @returns The created verifiable presentation and its token.
|
|
642
654
|
* @throws NotFoundError if the id can not be resolved.
|
|
643
655
|
*/
|
|
644
|
-
async createVerifiablePresentation(controller,
|
|
656
|
+
async createVerifiablePresentation(controller, verificationMethodId, presentationId, contexts, types, verifiableCredentials, expiresInMinutes) {
|
|
645
657
|
Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
646
|
-
Guards.stringValue(this.CLASS_NAME, "
|
|
658
|
+
Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
647
659
|
if (Is.array(types)) {
|
|
648
660
|
Guards.arrayValue(this.CLASS_NAME, "types", types);
|
|
649
661
|
}
|
|
@@ -655,9 +667,9 @@ class EntityStorageIdentityConnector {
|
|
|
655
667
|
Guards.integer(this.CLASS_NAME, "expiresInMinutes", expiresInMinutes);
|
|
656
668
|
}
|
|
657
669
|
try {
|
|
658
|
-
const idParts = DocumentHelper.
|
|
659
|
-
if (Is.empty(idParts.
|
|
660
|
-
throw new NotFoundError(this.CLASS_NAME, "missingDid",
|
|
670
|
+
const idParts = DocumentHelper.parseId(verificationMethodId);
|
|
671
|
+
if (Is.empty(idParts.fragment)) {
|
|
672
|
+
throw new NotFoundError(this.CLASS_NAME, "missingDid", verificationMethodId);
|
|
661
673
|
}
|
|
662
674
|
const holderIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
663
675
|
if (Is.undefined(holderIdentityDocument)) {
|
|
@@ -668,17 +680,17 @@ class EntityStorageIdentityConnector {
|
|
|
668
680
|
const methods = this.getAllMethods(holderDidDocument);
|
|
669
681
|
const methodAndArray = methods.find(m => {
|
|
670
682
|
if (Is.string(m.method)) {
|
|
671
|
-
return m.method ===
|
|
683
|
+
return m.method === verificationMethodId;
|
|
672
684
|
}
|
|
673
|
-
return m.method.id ===
|
|
685
|
+
return m.method.id === verificationMethodId;
|
|
674
686
|
});
|
|
675
687
|
if (!methodAndArray) {
|
|
676
|
-
throw new GeneralError(this.CLASS_NAME, "methodMissing", { method:
|
|
688
|
+
throw new GeneralError(this.CLASS_NAME, "methodMissing", { method: verificationMethodId });
|
|
677
689
|
}
|
|
678
690
|
const didMethod = methodAndArray.method;
|
|
679
691
|
if (!Is.stringValue(didMethod.publicKeyJwk?.x)) {
|
|
680
692
|
throw new GeneralError(this.CLASS_NAME, "publicKeyJwkMissing", {
|
|
681
|
-
method:
|
|
693
|
+
method: verificationMethodId
|
|
682
694
|
});
|
|
683
695
|
}
|
|
684
696
|
const finalTypes = [DidTypes.VerifiablePresentation];
|
|
@@ -715,7 +727,7 @@ class EntityStorageIdentityConnector {
|
|
|
715
727
|
jwtPayload.exp = Math.floor(Date.now() / 1000) + expiresInSeconds;
|
|
716
728
|
}
|
|
717
729
|
const signature = await Jwt.encodeWithSigner(jwtHeader, jwtPayload, async (alg, key, payload) => {
|
|
718
|
-
const sig = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(idParts.id, idParts.
|
|
730
|
+
const sig = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(idParts.id, idParts.fragment ?? ""), payload);
|
|
719
731
|
return sig;
|
|
720
732
|
});
|
|
721
733
|
return {
|
|
@@ -808,8 +820,8 @@ class EntityStorageIdentityConnector {
|
|
|
808
820
|
Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
809
821
|
Guards.uint8Array(this.CLASS_NAME, "bytes", bytes);
|
|
810
822
|
try {
|
|
811
|
-
const idParts = DocumentHelper.
|
|
812
|
-
if (Is.empty(idParts.
|
|
823
|
+
const idParts = DocumentHelper.parseId(verificationMethodId);
|
|
824
|
+
if (Is.empty(idParts.fragment)) {
|
|
813
825
|
throw new NotFoundError(this.CLASS_NAME, "missingDid", verificationMethodId);
|
|
814
826
|
}
|
|
815
827
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -834,7 +846,7 @@ class EntityStorageIdentityConnector {
|
|
|
834
846
|
method: verificationMethodId
|
|
835
847
|
});
|
|
836
848
|
}
|
|
837
|
-
const signature = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(didDocument.id, idParts.
|
|
849
|
+
const signature = await this._vaultConnector.sign(EntityStorageIdentityConnector.buildVaultKey(didDocument.id, idParts.fragment ?? ""), bytes);
|
|
838
850
|
return {
|
|
839
851
|
"@context": DidContexts.ContextVCDataIntegrity,
|
|
840
852
|
type: DidTypes.DataIntegrityProof,
|
|
@@ -869,8 +881,8 @@ class EntityStorageIdentityConnector {
|
|
|
869
881
|
if (proof.cryptosuite !== DidCryptoSuites.EdDSAJcs2022) {
|
|
870
882
|
throw new GeneralError(this.CLASS_NAME, "cryptoSuite", { cryptosuite: proof.cryptosuite });
|
|
871
883
|
}
|
|
872
|
-
const idParts = DocumentHelper.
|
|
873
|
-
if (Is.empty(idParts.
|
|
884
|
+
const idParts = DocumentHelper.parseId(proof.verificationMethod);
|
|
885
|
+
if (Is.empty(idParts.fragment)) {
|
|
874
886
|
throw new NotFoundError(this.CLASS_NAME, "missingDid", proof.verificationMethod);
|
|
875
887
|
}
|
|
876
888
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
@@ -897,7 +909,7 @@ class EntityStorageIdentityConnector {
|
|
|
897
909
|
method: proof.verificationMethodId
|
|
898
910
|
});
|
|
899
911
|
}
|
|
900
|
-
return this._vaultConnector.verify(EntityStorageIdentityConnector.buildVaultKey(didIdentityDocument.id, idParts.
|
|
912
|
+
return this._vaultConnector.verify(EntityStorageIdentityConnector.buildVaultKey(didIdentityDocument.id, idParts.fragment), bytes, Converter.base58ToBytes(proof.proofValue));
|
|
901
913
|
}
|
|
902
914
|
catch (error) {
|
|
903
915
|
throw new GeneralError(this.CLASS_NAME, "verifyProofFailed", undefined, error);
|
|
@@ -55,7 +55,7 @@ export declare class EntityStorageIdentityConnector implements IIdentityConnecto
|
|
|
55
55
|
* @returns The service.
|
|
56
56
|
* @throws NotFoundError if the id can not be resolved.
|
|
57
57
|
*/
|
|
58
|
-
addService(controller: string, documentId: string, serviceId: string, serviceType: string, serviceEndpoint: string): Promise<IDidService>;
|
|
58
|
+
addService(controller: string, documentId: string, serviceId: string, serviceType: string | string[], serviceEndpoint: string | string[]): Promise<IDidService>;
|
|
59
59
|
/**
|
|
60
60
|
* Remove a service from the document.
|
|
61
61
|
* @param controller The controller of the identity who can make changes.
|
|
@@ -69,12 +69,12 @@ export declare class EntityStorageIdentityConnector implements IIdentityConnecto
|
|
|
69
69
|
* @param controller The controller of the identity who can make changes.
|
|
70
70
|
* @param verificationMethodId The verification method id to use.
|
|
71
71
|
* @param id The id of the credential.
|
|
72
|
-
* @param
|
|
72
|
+
* @param subject The credential subject to store in the verifiable credential.
|
|
73
73
|
* @param revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.
|
|
74
74
|
* @returns The created verifiable credential and its token.
|
|
75
75
|
* @throws NotFoundError if the id can not be resolved.
|
|
76
76
|
*/
|
|
77
|
-
createVerifiableCredential(controller: string, verificationMethodId: string, id: string | undefined,
|
|
77
|
+
createVerifiableCredential(controller: string, verificationMethodId: string, id: string | undefined, subject: IJsonLdNodeObject, revocationIndex?: number): Promise<{
|
|
78
78
|
verifiableCredential: IDidVerifiableCredential;
|
|
79
79
|
jwt: string;
|
|
80
80
|
}>;
|
|
@@ -106,7 +106,7 @@ export declare class EntityStorageIdentityConnector implements IIdentityConnecto
|
|
|
106
106
|
/**
|
|
107
107
|
* Create a verifiable presentation from the supplied verifiable credentials.
|
|
108
108
|
* @param controller The controller of the identity who can make changes.
|
|
109
|
-
* @param
|
|
109
|
+
* @param verificationMethodId The method to associate with the presentation.
|
|
110
110
|
* @param presentationId The id of the presentation.
|
|
111
111
|
* @param contexts The contexts for the data stored in the verifiable credential.
|
|
112
112
|
* @param types The types for the data stored in the verifiable credential.
|
|
@@ -115,7 +115,7 @@ export declare class EntityStorageIdentityConnector implements IIdentityConnecto
|
|
|
115
115
|
* @returns The created verifiable presentation and its token.
|
|
116
116
|
* @throws NotFoundError if the id can not be resolved.
|
|
117
117
|
*/
|
|
118
|
-
createVerifiablePresentation(controller: string,
|
|
118
|
+
createVerifiablePresentation(controller: string, verificationMethodId: string, presentationId: string | undefined, contexts: IJsonLdContextDefinitionRoot | undefined, types: string | string[] | undefined, verifiableCredentials: (string | IDidVerifiableCredential)[], expiresInMinutes?: number): Promise<{
|
|
119
119
|
verifiablePresentation: IDidVerifiablePresentation;
|
|
120
120
|
jwt: string;
|
|
121
121
|
}>;
|
package/docs/changelog.md
CHANGED
|
@@ -194,16 +194,16 @@ The id of the service.
|
|
|
194
194
|
|
|
195
195
|
##### serviceType
|
|
196
196
|
|
|
197
|
-
`string`
|
|
198
|
-
|
|
199
197
|
The type of the service.
|
|
200
198
|
|
|
201
|
-
|
|
199
|
+
`string` | `string`[]
|
|
202
200
|
|
|
203
|
-
|
|
201
|
+
##### serviceEndpoint
|
|
204
202
|
|
|
205
203
|
The endpoint for the service.
|
|
206
204
|
|
|
205
|
+
`string` | `string`[]
|
|
206
|
+
|
|
207
207
|
#### Returns
|
|
208
208
|
|
|
209
209
|
`Promise`\<`IDidService`\>
|
|
@@ -258,7 +258,7 @@ NotFoundError if the id can not be resolved.
|
|
|
258
258
|
|
|
259
259
|
### createVerifiableCredential()
|
|
260
260
|
|
|
261
|
-
> **createVerifiableCredential**(`controller`, `verificationMethodId`, `id`, `
|
|
261
|
+
> **createVerifiableCredential**(`controller`, `verificationMethodId`, `id`, `subject`, `revocationIndex`?): `Promise`\<\{ `verifiableCredential`: `IDidVerifiableCredential`; `jwt`: `string`; \}\>
|
|
262
262
|
|
|
263
263
|
Create a verifiable credential for a verification method.
|
|
264
264
|
|
|
@@ -282,11 +282,11 @@ The id of the credential.
|
|
|
282
282
|
|
|
283
283
|
`undefined` | `string`
|
|
284
284
|
|
|
285
|
-
#####
|
|
285
|
+
##### subject
|
|
286
286
|
|
|
287
287
|
`IJsonLdNodeObject`
|
|
288
288
|
|
|
289
|
-
The credential to store in the verifiable credential.
|
|
289
|
+
The credential subject to store in the verifiable credential.
|
|
290
290
|
|
|
291
291
|
##### revocationIndex?
|
|
292
292
|
|
|
@@ -414,7 +414,7 @@ Nothing.
|
|
|
414
414
|
|
|
415
415
|
### createVerifiablePresentation()
|
|
416
416
|
|
|
417
|
-
> **createVerifiablePresentation**(`controller`, `
|
|
417
|
+
> **createVerifiablePresentation**(`controller`, `verificationMethodId`, `presentationId`, `contexts`, `types`, `verifiableCredentials`, `expiresInMinutes`?): `Promise`\<\{ `verifiablePresentation`: `IDidVerifiablePresentation`; `jwt`: `string`; \}\>
|
|
418
418
|
|
|
419
419
|
Create a verifiable presentation from the supplied verifiable credentials.
|
|
420
420
|
|
|
@@ -426,7 +426,7 @@ Create a verifiable presentation from the supplied verifiable credentials.
|
|
|
426
426
|
|
|
427
427
|
The controller of the identity who can make changes.
|
|
428
428
|
|
|
429
|
-
#####
|
|
429
|
+
##### verificationMethodId
|
|
430
430
|
|
|
431
431
|
`string`
|
|
432
432
|
|
|
@@ -10,13 +10,13 @@ Initialize the schema for the identity entity storage connector.
|
|
|
10
10
|
|
|
11
11
|
Options for which entities to register.
|
|
12
12
|
|
|
13
|
-
#### includeDocument
|
|
13
|
+
#### includeDocument?
|
|
14
14
|
|
|
15
15
|
`boolean`
|
|
16
16
|
|
|
17
17
|
Whether to include the document entity, defaults to true.
|
|
18
18
|
|
|
19
|
-
#### includeProfile
|
|
19
|
+
#### includeProfile?
|
|
20
20
|
|
|
21
21
|
`boolean`
|
|
22
22
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/identity-connector-entity-storage",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.25",
|
|
4
4
|
"description": "Identity connector implementation using entity storage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@twin.org/data-core": "next",
|
|
20
20
|
"@twin.org/data-json-ld": "next",
|
|
21
21
|
"@twin.org/entity": "next",
|
|
22
|
-
"@twin.org/identity-models": "0.0.1-next.
|
|
22
|
+
"@twin.org/identity-models": "0.0.1-next.25",
|
|
23
23
|
"@twin.org/nameof": "next",
|
|
24
24
|
"@twin.org/standards-w3c-did": "next",
|
|
25
25
|
"@twin.org/vault-models": "next",
|