@twin.org/identity-connector-entity-storage 0.0.1-next.13 → 0.0.1-next.14
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
|
@@ -801,7 +801,7 @@ class EntityStorageIdentityConnector {
|
|
|
801
801
|
* @param controller The controller of the identity who can make changes.
|
|
802
802
|
* @param verificationMethodId The verification method id to use.
|
|
803
803
|
* @param bytes The data bytes to sign.
|
|
804
|
-
* @returns The proof
|
|
804
|
+
* @returns The proof.
|
|
805
805
|
*/
|
|
806
806
|
async createProof(controller, verificationMethodId, bytes) {
|
|
807
807
|
core.Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
@@ -834,8 +834,13 @@ class EntityStorageIdentityConnector {
|
|
|
834
834
|
}
|
|
835
835
|
const signature = await this._vaultConnector.sign(this.buildVaultKey(didDocument.id, verificationMethodId), bytes);
|
|
836
836
|
return {
|
|
837
|
-
|
|
838
|
-
|
|
837
|
+
"@context": standardsW3cDid.DidContexts.ContextVCDataIntegrity,
|
|
838
|
+
type: standardsW3cDid.DidTypes.DataIntegrityProof,
|
|
839
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
840
|
+
created: new Date(Date.now()).toISOString(),
|
|
841
|
+
verificationMethod: verificationMethodId,
|
|
842
|
+
proofPurpose: "assertionMethod",
|
|
843
|
+
proofValue: core.Converter.bytesToBase58(signature)
|
|
839
844
|
};
|
|
840
845
|
}
|
|
841
846
|
catch (error) {
|
|
@@ -844,21 +849,27 @@ class EntityStorageIdentityConnector {
|
|
|
844
849
|
}
|
|
845
850
|
/**
|
|
846
851
|
* Verify proof for arbitrary data with the specified verification method.
|
|
847
|
-
* @param verificationMethodId The verification method id to use.
|
|
848
852
|
* @param bytes The data bytes to verify.
|
|
849
|
-
* @param
|
|
850
|
-
* @
|
|
851
|
-
* @returns True if the signature is valid.
|
|
853
|
+
* @param proof The proof to verify.
|
|
854
|
+
* @returns True if the proof is verified.
|
|
852
855
|
*/
|
|
853
|
-
async verifyProof(
|
|
854
|
-
core.Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
856
|
+
async verifyProof(bytes, proof) {
|
|
855
857
|
core.Guards.uint8Array(this.CLASS_NAME, "bytes", bytes);
|
|
856
|
-
core.Guards.
|
|
857
|
-
core.Guards.
|
|
858
|
+
core.Guards.object(this.CLASS_NAME, "proof", proof);
|
|
859
|
+
core.Guards.stringValue(this.CLASS_NAME, "proof.type", proof.type);
|
|
860
|
+
core.Guards.stringValue(this.CLASS_NAME, "proof.cryptosuite", proof.cryptosuite);
|
|
861
|
+
core.Guards.stringValue(this.CLASS_NAME, "proof.verificationMethod", proof.verificationMethod);
|
|
862
|
+
core.Guards.stringBase58(this.CLASS_NAME, "proof.proofValue", proof.proofValue);
|
|
858
863
|
try {
|
|
859
|
-
|
|
864
|
+
if (proof.type !== standardsW3cDid.DidTypes.DataIntegrityProof) {
|
|
865
|
+
throw new core.GeneralError(this.CLASS_NAME, "proofType", { proofType: proof.type });
|
|
866
|
+
}
|
|
867
|
+
if (proof.cryptosuite !== "eddsa-jcs-2022") {
|
|
868
|
+
throw new core.GeneralError(this.CLASS_NAME, "cryptoSuite", { cryptosuite: proof.cryptosuite });
|
|
869
|
+
}
|
|
870
|
+
const idParts = identityModels.DocumentHelper.parse(proof.verificationMethod);
|
|
860
871
|
if (core.Is.empty(idParts.hash)) {
|
|
861
|
-
throw new core.NotFoundError(this.CLASS_NAME, "missingDid",
|
|
872
|
+
throw new core.NotFoundError(this.CLASS_NAME, "missingDid", proof.verificationMethod);
|
|
862
873
|
}
|
|
863
874
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
864
875
|
if (core.Is.undefined(didIdentityDocument)) {
|
|
@@ -869,9 +880,9 @@ class EntityStorageIdentityConnector {
|
|
|
869
880
|
const methods = this.getAllMethods(didDocument);
|
|
870
881
|
const methodAndArray = methods.find(m => {
|
|
871
882
|
if (core.Is.string(m.method)) {
|
|
872
|
-
return m.method ===
|
|
883
|
+
return m.method === proof.verificationMethod;
|
|
873
884
|
}
|
|
874
|
-
return m.method.id ===
|
|
885
|
+
return m.method.id === proof.verificationMethod;
|
|
875
886
|
});
|
|
876
887
|
if (!methodAndArray) {
|
|
877
888
|
throw new core.GeneralError(this.CLASS_NAME, "methodMissing");
|
|
@@ -880,7 +891,7 @@ class EntityStorageIdentityConnector {
|
|
|
880
891
|
if (!core.Is.stringValue(didMethod.publicKeyJwk?.x)) {
|
|
881
892
|
throw new core.GeneralError(this.CLASS_NAME, "publicKeyJwkMissing");
|
|
882
893
|
}
|
|
883
|
-
return this._vaultConnector.verify(this.buildVaultKey(didIdentityDocument.id,
|
|
894
|
+
return this._vaultConnector.verify(this.buildVaultKey(didIdentityDocument.id, proof.verificationMethod), bytes, core.Converter.base58ToBytes(proof.proofValue));
|
|
884
895
|
}
|
|
885
896
|
catch (error) {
|
|
886
897
|
throw new core.GeneralError(this.CLASS_NAME, "verifyProofFailed", undefined, error);
|
package/dist/esm/index.mjs
CHANGED
|
@@ -799,7 +799,7 @@ class EntityStorageIdentityConnector {
|
|
|
799
799
|
* @param controller The controller of the identity who can make changes.
|
|
800
800
|
* @param verificationMethodId The verification method id to use.
|
|
801
801
|
* @param bytes The data bytes to sign.
|
|
802
|
-
* @returns The proof
|
|
802
|
+
* @returns The proof.
|
|
803
803
|
*/
|
|
804
804
|
async createProof(controller, verificationMethodId, bytes) {
|
|
805
805
|
Guards.stringValue(this.CLASS_NAME, "controller", controller);
|
|
@@ -832,8 +832,13 @@ class EntityStorageIdentityConnector {
|
|
|
832
832
|
}
|
|
833
833
|
const signature = await this._vaultConnector.sign(this.buildVaultKey(didDocument.id, verificationMethodId), bytes);
|
|
834
834
|
return {
|
|
835
|
-
|
|
836
|
-
|
|
835
|
+
"@context": DidContexts.ContextVCDataIntegrity,
|
|
836
|
+
type: DidTypes.DataIntegrityProof,
|
|
837
|
+
cryptosuite: "eddsa-jcs-2022",
|
|
838
|
+
created: new Date(Date.now()).toISOString(),
|
|
839
|
+
verificationMethod: verificationMethodId,
|
|
840
|
+
proofPurpose: "assertionMethod",
|
|
841
|
+
proofValue: Converter.bytesToBase58(signature)
|
|
837
842
|
};
|
|
838
843
|
}
|
|
839
844
|
catch (error) {
|
|
@@ -842,21 +847,27 @@ class EntityStorageIdentityConnector {
|
|
|
842
847
|
}
|
|
843
848
|
/**
|
|
844
849
|
* Verify proof for arbitrary data with the specified verification method.
|
|
845
|
-
* @param verificationMethodId The verification method id to use.
|
|
846
850
|
* @param bytes The data bytes to verify.
|
|
847
|
-
* @param
|
|
848
|
-
* @
|
|
849
|
-
* @returns True if the signature is valid.
|
|
851
|
+
* @param proof The proof to verify.
|
|
852
|
+
* @returns True if the proof is verified.
|
|
850
853
|
*/
|
|
851
|
-
async verifyProof(
|
|
852
|
-
Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
|
|
854
|
+
async verifyProof(bytes, proof) {
|
|
853
855
|
Guards.uint8Array(this.CLASS_NAME, "bytes", bytes);
|
|
854
|
-
Guards.
|
|
855
|
-
Guards.
|
|
856
|
+
Guards.object(this.CLASS_NAME, "proof", proof);
|
|
857
|
+
Guards.stringValue(this.CLASS_NAME, "proof.type", proof.type);
|
|
858
|
+
Guards.stringValue(this.CLASS_NAME, "proof.cryptosuite", proof.cryptosuite);
|
|
859
|
+
Guards.stringValue(this.CLASS_NAME, "proof.verificationMethod", proof.verificationMethod);
|
|
860
|
+
Guards.stringBase58(this.CLASS_NAME, "proof.proofValue", proof.proofValue);
|
|
856
861
|
try {
|
|
857
|
-
|
|
862
|
+
if (proof.type !== DidTypes.DataIntegrityProof) {
|
|
863
|
+
throw new GeneralError(this.CLASS_NAME, "proofType", { proofType: proof.type });
|
|
864
|
+
}
|
|
865
|
+
if (proof.cryptosuite !== "eddsa-jcs-2022") {
|
|
866
|
+
throw new GeneralError(this.CLASS_NAME, "cryptoSuite", { cryptosuite: proof.cryptosuite });
|
|
867
|
+
}
|
|
868
|
+
const idParts = DocumentHelper.parse(proof.verificationMethod);
|
|
858
869
|
if (Is.empty(idParts.hash)) {
|
|
859
|
-
throw new NotFoundError(this.CLASS_NAME, "missingDid",
|
|
870
|
+
throw new NotFoundError(this.CLASS_NAME, "missingDid", proof.verificationMethod);
|
|
860
871
|
}
|
|
861
872
|
const didIdentityDocument = await this._didDocumentEntityStorage.get(idParts.id);
|
|
862
873
|
if (Is.undefined(didIdentityDocument)) {
|
|
@@ -867,9 +878,9 @@ class EntityStorageIdentityConnector {
|
|
|
867
878
|
const methods = this.getAllMethods(didDocument);
|
|
868
879
|
const methodAndArray = methods.find(m => {
|
|
869
880
|
if (Is.string(m.method)) {
|
|
870
|
-
return m.method ===
|
|
881
|
+
return m.method === proof.verificationMethod;
|
|
871
882
|
}
|
|
872
|
-
return m.method.id ===
|
|
883
|
+
return m.method.id === proof.verificationMethod;
|
|
873
884
|
});
|
|
874
885
|
if (!methodAndArray) {
|
|
875
886
|
throw new GeneralError(this.CLASS_NAME, "methodMissing");
|
|
@@ -878,7 +889,7 @@ class EntityStorageIdentityConnector {
|
|
|
878
889
|
if (!Is.stringValue(didMethod.publicKeyJwk?.x)) {
|
|
879
890
|
throw new GeneralError(this.CLASS_NAME, "publicKeyJwkMissing");
|
|
880
891
|
}
|
|
881
|
-
return this._vaultConnector.verify(this.buildVaultKey(didIdentityDocument.id,
|
|
892
|
+
return this._vaultConnector.verify(this.buildVaultKey(didIdentityDocument.id, proof.verificationMethod), bytes, Converter.base58ToBytes(proof.proofValue));
|
|
882
893
|
}
|
|
883
894
|
catch (error) {
|
|
884
895
|
throw new GeneralError(this.CLASS_NAME, "verifyProofFailed", undefined, error);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type IJsonLdContextDefinitionRoot, type IJsonLdObject } from "@twin.org/data-json-ld";
|
|
2
2
|
import { type IIdentityConnector } from "@twin.org/identity-models";
|
|
3
|
-
import { DidVerificationMethodType, type IDidDocument, type IDidDocumentVerificationMethod, type IDidService, type IDidVerifiableCredential, type IDidVerifiablePresentation } from "@twin.org/standards-w3c-did";
|
|
3
|
+
import { DidVerificationMethodType, type IDidProof, type IDidDocument, type IDidDocumentVerificationMethod, type IDidService, type IDidVerifiableCredential, type IDidVerifiablePresentation } from "@twin.org/standards-w3c-did";
|
|
4
4
|
/**
|
|
5
5
|
* Class for performing identity operations using entity storage.
|
|
6
6
|
*/
|
|
@@ -145,19 +145,14 @@ export declare class EntityStorageIdentityConnector implements IIdentityConnecto
|
|
|
145
145
|
* @param controller The controller of the identity who can make changes.
|
|
146
146
|
* @param verificationMethodId The verification method id to use.
|
|
147
147
|
* @param bytes The data bytes to sign.
|
|
148
|
-
* @returns The proof
|
|
148
|
+
* @returns The proof.
|
|
149
149
|
*/
|
|
150
|
-
createProof(controller: string, verificationMethodId: string, bytes: Uint8Array): Promise<
|
|
151
|
-
type: string;
|
|
152
|
-
value: Uint8Array;
|
|
153
|
-
}>;
|
|
150
|
+
createProof(controller: string, verificationMethodId: string, bytes: Uint8Array): Promise<IDidProof>;
|
|
154
151
|
/**
|
|
155
152
|
* Verify proof for arbitrary data with the specified verification method.
|
|
156
|
-
* @param verificationMethodId The verification method id to use.
|
|
157
153
|
* @param bytes The data bytes to verify.
|
|
158
|
-
* @param
|
|
159
|
-
* @
|
|
160
|
-
* @returns True if the signature is valid.
|
|
154
|
+
* @param proof The proof to verify.
|
|
155
|
+
* @returns True if the proof is verified.
|
|
161
156
|
*/
|
|
162
|
-
verifyProof(
|
|
157
|
+
verifyProof(bytes: Uint8Array, proof: IDidProof): Promise<boolean>;
|
|
163
158
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -524,7 +524,7 @@ The presentation stored in the jwt and the revocation status.
|
|
|
524
524
|
|
|
525
525
|
### createProof()
|
|
526
526
|
|
|
527
|
-
> **createProof**(`controller`, `verificationMethodId`, `bytes`): `Promise`\<`
|
|
527
|
+
> **createProof**(`controller`, `verificationMethodId`, `bytes`): `Promise`\<`IDidProof`\>
|
|
528
528
|
|
|
529
529
|
Create a proof for arbitrary data with the specified verification method.
|
|
530
530
|
|
|
@@ -544,17 +544,9 @@ The data bytes to sign.
|
|
|
544
544
|
|
|
545
545
|
#### Returns
|
|
546
546
|
|
|
547
|
-
`Promise`\<`
|
|
548
|
-
|
|
549
|
-
The proof signature type and value.
|
|
550
|
-
|
|
551
|
-
##### type
|
|
547
|
+
`Promise`\<`IDidProof`\>
|
|
552
548
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
##### value
|
|
556
|
-
|
|
557
|
-
> **value**: `Uint8Array`
|
|
549
|
+
The proof.
|
|
558
550
|
|
|
559
551
|
#### Implementation of
|
|
560
552
|
|
|
@@ -564,33 +556,25 @@ The proof signature type and value.
|
|
|
564
556
|
|
|
565
557
|
### verifyProof()
|
|
566
558
|
|
|
567
|
-
> **verifyProof**(`
|
|
559
|
+
> **verifyProof**(`bytes`, `proof`): `Promise`\<`boolean`\>
|
|
568
560
|
|
|
569
561
|
Verify proof for arbitrary data with the specified verification method.
|
|
570
562
|
|
|
571
563
|
#### Parameters
|
|
572
564
|
|
|
573
|
-
• **verificationMethodId**: `string`
|
|
574
|
-
|
|
575
|
-
The verification method id to use.
|
|
576
|
-
|
|
577
565
|
• **bytes**: `Uint8Array`
|
|
578
566
|
|
|
579
567
|
The data bytes to verify.
|
|
580
568
|
|
|
581
|
-
• **
|
|
582
|
-
|
|
583
|
-
The type of the signature for the proof.
|
|
584
|
-
|
|
585
|
-
• **signatureValue**: `Uint8Array`
|
|
569
|
+
• **proof**: `IDidProof`
|
|
586
570
|
|
|
587
|
-
The
|
|
571
|
+
The proof to verify.
|
|
588
572
|
|
|
589
573
|
#### Returns
|
|
590
574
|
|
|
591
575
|
`Promise`\<`boolean`\>
|
|
592
576
|
|
|
593
|
-
True if the
|
|
577
|
+
True if the proof is verified.
|
|
594
578
|
|
|
595
579
|
#### Implementation of
|
|
596
580
|
|
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.14",
|
|
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.14",
|
|
23
23
|
"@twin.org/nameof": "next",
|
|
24
24
|
"@twin.org/standards-w3c-did": "next",
|
|
25
25
|
"@twin.org/vault-models": "next",
|