@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.
@@ -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 signature type and value.
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
- type: "Ed25519",
838
- value: signature
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 signatureType The type of the signature for the proof.
850
- * @param signatureValue The value of the signature for the proof.
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(verificationMethodId, bytes, signatureType, signatureValue) {
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.stringValue(this.CLASS_NAME, "signatureType", signatureType);
857
- core.Guards.uint8Array(this.CLASS_NAME, "signatureValue", signatureValue);
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
- const idParts = identityModels.DocumentHelper.parse(verificationMethodId);
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", verificationMethodId);
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 === verificationMethodId;
883
+ return m.method === proof.verificationMethod;
873
884
  }
874
- return m.method.id === verificationMethodId;
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, verificationMethodId), bytes, signatureValue);
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);
@@ -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 signature type and value.
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
- type: "Ed25519",
836
- value: signature
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 signatureType The type of the signature for the proof.
848
- * @param signatureValue The value of the signature for the proof.
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(verificationMethodId, bytes, signatureType, signatureValue) {
852
- Guards.stringValue(this.CLASS_NAME, "verificationMethodId", verificationMethodId);
854
+ async verifyProof(bytes, proof) {
853
855
  Guards.uint8Array(this.CLASS_NAME, "bytes", bytes);
854
- Guards.stringValue(this.CLASS_NAME, "signatureType", signatureType);
855
- Guards.uint8Array(this.CLASS_NAME, "signatureValue", signatureValue);
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
- const idParts = DocumentHelper.parse(verificationMethodId);
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", verificationMethodId);
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 === verificationMethodId;
881
+ return m.method === proof.verificationMethod;
871
882
  }
872
- return m.method.id === verificationMethodId;
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, verificationMethodId), bytes, signatureValue);
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 signature type and value.
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 signatureType The type of the signature for the proof.
159
- * @param signatureValue The value of the signature for the proof.
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(verificationMethodId: string, bytes: Uint8Array, signatureType: string, signatureValue: Uint8Array): Promise<boolean>;
157
+ verifyProof(bytes: Uint8Array, proof: IDidProof): Promise<boolean>;
163
158
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/identity-connector-entity-storage- Changelog
2
2
 
3
- ## v0.0.1-next.13
3
+ ## v0.0.1-next.14
4
4
 
5
5
  - Initial Release
@@ -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`\<`object`\>
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`\<`object`\>
548
-
549
- The proof signature type and value.
550
-
551
- ##### type
547
+ `Promise`\<`IDidProof`\>
552
548
 
553
- > **type**: `string`
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**(`verificationMethodId`, `bytes`, `signatureType`, `signatureValue`): `Promise`\<`boolean`\>
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
- • **signatureType**: `string`
582
-
583
- The type of the signature for the proof.
584
-
585
- • **signatureValue**: `Uint8Array`
569
+ • **proof**: `IDidProof`
586
570
 
587
- The value of the signature for the proof.
571
+ The proof to verify.
588
572
 
589
573
  #### Returns
590
574
 
591
575
  `Promise`\<`boolean`\>
592
576
 
593
- True if the signature is valid.
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.13",
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.13",
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",