@twin.org/standards-w3c-did 0.0.3-next.9 → 0.9.0
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/README.md +1 -1
- package/dist/es/dataTypes/didDataTypes.js +40 -0
- package/dist/es/dataTypes/didDataTypes.js.map +1 -0
- package/dist/es/index.js +5 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IDataIntegrityProof.js.map +1 -1
- package/dist/es/models/IDidDocument.js.map +1 -1
- package/dist/es/models/IDidDocumentVerificationMethod.js.map +1 -1
- package/dist/es/models/IDidService.js +0 -2
- package/dist/es/models/IDidService.js.map +1 -1
- package/dist/es/models/IDidVerifiableCredentialCommon.js.map +1 -1
- package/dist/es/models/IDidVerifiableCredentialV1.js.map +1 -1
- package/dist/es/models/IDidVerifiableCredentialV2.js.map +1 -1
- package/dist/es/models/IDidVerifiablePresentationCommon.js.map +1 -1
- package/dist/es/models/IDidVerifiablePresentationV1.js.map +1 -1
- package/dist/es/models/IDidVerifiablePresentationV2.js.map +1 -1
- package/dist/es/models/IJsonWebSignature2020Proof.js.map +1 -1
- package/dist/es/models/IMultikey.js.map +1 -1
- package/dist/es/models/IProofSignerVerifierAsync.js +2 -0
- package/dist/es/models/IProofSignerVerifierAsync.js.map +1 -0
- package/dist/es/models/didContexts.js +45 -9
- package/dist/es/models/didContexts.js.map +1 -1
- package/dist/es/models/didTypes.js +4 -0
- package/dist/es/models/didTypes.js.map +1 -1
- package/dist/es/models/jwsAlgorithms.js +17 -0
- package/dist/es/models/jwsAlgorithms.js.map +1 -0
- package/dist/es/schemas/DidDocument.json +163 -0
- package/dist/es/schemas/DidVerifiableCredential.json +14 -0
- package/dist/es/schemas/DidVerifiablePresentation.json +14 -0
- package/dist/es/signerVerifiers/dataIntegrityProofAsyncSignerVerifier.js +73 -0
- package/dist/es/signerVerifiers/dataIntegrityProofAsyncSignerVerifier.js.map +1 -0
- package/dist/es/signerVerifiers/dataIntegrityProofSignerVerifier.js +3 -3
- package/dist/es/signerVerifiers/dataIntegrityProofSignerVerifier.js.map +1 -1
- package/dist/es/signerVerifiers/jsonWebSignature2020AsyncSignerVerifier.js +91 -0
- package/dist/es/signerVerifiers/jsonWebSignature2020AsyncSignerVerifier.js.map +1 -0
- package/dist/es/signerVerifiers/jsonWebSignature2020SignerVerifier.js +3 -2
- package/dist/es/signerVerifiers/jsonWebSignature2020SignerVerifier.js.map +1 -1
- package/dist/es/utils/proofHelper.js +39 -0
- package/dist/es/utils/proofHelper.js.map +1 -1
- package/dist/es/utils/verifiableCredentialHelper.js +64 -7
- package/dist/es/utils/verifiableCredentialHelper.js.map +1 -1
- package/dist/types/dataTypes/didDataTypes.d.ts +9 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/models/IDataIntegrityProof.d.ts +4 -3
- package/dist/types/models/IDidDocument.d.ts +4 -3
- package/dist/types/models/IDidDocumentVerificationMethod.d.ts +1 -1
- package/dist/types/models/IDidService.d.ts +3 -2
- package/dist/types/models/IDidVerifiableCredentialCommon.d.ts +9 -8
- package/dist/types/models/IDidVerifiableCredentialV1.d.ts +2 -1
- package/dist/types/models/IDidVerifiableCredentialV2.d.ts +2 -1
- package/dist/types/models/IDidVerifiablePresentationCommon.d.ts +3 -2
- package/dist/types/models/IDidVerifiablePresentationV1.d.ts +2 -1
- package/dist/types/models/IDidVerifiablePresentationV2.d.ts +2 -1
- package/dist/types/models/IJsonWebSignature2020Proof.d.ts +2 -1
- package/dist/types/models/IMultikey.d.ts +2 -1
- package/dist/types/models/IProofSignerVerifierAsync.d.ts +34 -0
- package/dist/types/models/didContexts.d.ts +45 -9
- package/dist/types/models/didTypes.d.ts +4 -0
- package/dist/types/models/jwsAlgorithms.d.ts +17 -0
- package/dist/types/signerVerifiers/dataIntegrityProofAsyncSignerVerifier.d.ts +42 -0
- package/dist/types/signerVerifiers/dataIntegrityProofSignerVerifier.d.ts +3 -3
- package/dist/types/signerVerifiers/jsonWebSignature2020AsyncSignerVerifier.d.ts +41 -0
- package/dist/types/signerVerifiers/jsonWebSignature2020SignerVerifier.d.ts +3 -2
- package/dist/types/utils/proofHelper.d.ts +19 -0
- package/dist/types/utils/verifiableCredentialHelper.d.ts +31 -6
- package/docs/changelog.md +679 -77
- package/docs/examples.md +84 -1
- package/docs/reference/classes/DataIntegrityProofAsyncSignerVerifier.md +139 -0
- package/docs/reference/classes/DataIntegrityProofSignerVerifier.md +9 -6
- package/docs/reference/classes/DidDataTypes.md +25 -0
- package/docs/reference/classes/JsonWebSignature2020AsyncSignerVerifier.md +136 -0
- package/docs/reference/classes/JsonWebSignature2020SignerVerifier.md +10 -6
- package/docs/reference/classes/MultikeyHelper.md +4 -4
- package/docs/reference/classes/ProofHelper.md +73 -5
- package/docs/reference/classes/VerifiableCredentialHelper.md +105 -9
- package/docs/reference/index.md +6 -0
- package/docs/reference/interfaces/IDataIntegrityProof.md +23 -23
- package/docs/reference/interfaces/IDidCredentialSchema.md +2 -2
- package/docs/reference/interfaces/IDidCredentialStatus.md +3 -3
- package/docs/reference/interfaces/IDidDocument.md +21 -21
- package/docs/reference/interfaces/IDidDocumentVerificationMethod.md +9 -17
- package/docs/reference/interfaces/IDidLabel.md +4 -4
- package/docs/reference/interfaces/IDidPresentationVerification.md +4 -4
- package/docs/reference/interfaces/IDidService.md +5 -5
- package/docs/reference/interfaces/IDidVerifiableCredentialCommon.md +24 -21
- package/docs/reference/interfaces/IDidVerifiableCredentialV1.md +26 -26
- package/docs/reference/interfaces/IDidVerifiableCredentialV2.md +26 -26
- package/docs/reference/interfaces/IDidVerifiablePresentationCommon.md +8 -8
- package/docs/reference/interfaces/IDidVerifiablePresentationV1.md +12 -12
- package/docs/reference/interfaces/IDidVerifiablePresentationV2.md +12 -12
- package/docs/reference/interfaces/IJsonWebSignature2020Proof.md +10 -10
- package/docs/reference/interfaces/IMultikey.md +14 -14
- package/docs/reference/interfaces/IProofSignerVerifier.md +3 -3
- package/docs/reference/interfaces/IProofSignerVerifierAsync.md +102 -0
- package/docs/reference/type-aliases/JwsAlgorithms.md +5 -0
- package/docs/reference/variables/DidContexts.md +71 -17
- package/docs/reference/variables/DidCryptoSuites.md +2 -2
- package/docs/reference/variables/DidTypes.md +12 -6
- package/docs/reference/variables/JwsAlgorithms.md +23 -0
- package/docs/reference/variables/ProofTypes.md +2 -2
- package/package.json +9 -9
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Converter, Guards, ObjectHelper } from "@twin.org/core";
|
|
4
|
+
import { JsonLdProcessor } from "@twin.org/data-json-ld";
|
|
5
|
+
import { DataIntegrityProofSignerVerifier } from "./dataIntegrityProofSignerVerifier.js";
|
|
6
|
+
import { DidContexts } from "../models/didContexts.js";
|
|
7
|
+
import { JwsAlgorithms } from "../models/jwsAlgorithms.js";
|
|
8
|
+
/**
|
|
9
|
+
* Helper methods for creating and verifying Data Integrity proofs with async signing callbacks.
|
|
10
|
+
* @see https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022
|
|
11
|
+
*/
|
|
12
|
+
export class DataIntegrityProofAsyncSignerVerifier {
|
|
13
|
+
/**
|
|
14
|
+
* Runtime name for the class.
|
|
15
|
+
*/
|
|
16
|
+
static CLASS_NAME = "DataIntegrityProofAsyncSignerVerifier";
|
|
17
|
+
/**
|
|
18
|
+
* The underlying sync signer verifier for hash and verify operations.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
_syncSignerVerifier;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new instance of DataIntegrityProofAsyncSignerVerifier.
|
|
24
|
+
*/
|
|
25
|
+
constructor() {
|
|
26
|
+
this._syncSignerVerifier = new DataIntegrityProofSignerVerifier();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a proof with an async signing callback.
|
|
30
|
+
* @param unsecuredDocument The data to create the proof for.
|
|
31
|
+
* @param unsignedProof The proof options.
|
|
32
|
+
* @param signCallback Async callback that signs data with a private key from secure storage.
|
|
33
|
+
* @returns The created proof.
|
|
34
|
+
*/
|
|
35
|
+
async createProofWithSigner(unsecuredDocument, unsignedProof, signCallback) {
|
|
36
|
+
Guards.object(DataIntegrityProofAsyncSignerVerifier.CLASS_NAME, "unsecuredDocument", unsecuredDocument);
|
|
37
|
+
Guards.object(DataIntegrityProofAsyncSignerVerifier.CLASS_NAME, "unsignedProof", unsignedProof);
|
|
38
|
+
Guards.function(DataIntegrityProofAsyncSignerVerifier.CLASS_NAME, "signCallback", signCallback);
|
|
39
|
+
const unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);
|
|
40
|
+
const signedProof = ObjectHelper.clone(unsignedProof);
|
|
41
|
+
unsecuredDocumentClone["@context"] = JsonLdProcessor.combineContexts(unsecuredDocumentClone["@context"], DidContexts.ContextDataIntegrity);
|
|
42
|
+
signedProof["@context"] = unsecuredDocumentClone["@context"];
|
|
43
|
+
// Use the sync verifier to create the hash
|
|
44
|
+
const combinedHash = await this.createHash(unsecuredDocument, unsignedProof);
|
|
45
|
+
// Sign with the callback (key stays in secure storage)
|
|
46
|
+
// Pass JWS algorithm for vault validation
|
|
47
|
+
const signature = await signCallback(combinedHash, JwsAlgorithms.EdDSA);
|
|
48
|
+
signedProof.proofValue = `z${Converter.bytesToBase58(signature)}`;
|
|
49
|
+
return signedProof;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Verify a proof for the given data.
|
|
53
|
+
* @param securedDocument The credential to verify.
|
|
54
|
+
* @param signedProof The proof to verify.
|
|
55
|
+
* @param verifyKey The public key to verify the proof with.
|
|
56
|
+
* @returns True if the credential was verified.
|
|
57
|
+
*/
|
|
58
|
+
async verifyProof(securedDocument, signedProof, verifyKey) {
|
|
59
|
+
// Delegate to the sync implementation
|
|
60
|
+
return this._syncSignerVerifier.verifyProof(securedDocument, signedProof, verifyKey);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create a hash for the given data.
|
|
64
|
+
* @param unsecuredDocument The data to create the proof for.
|
|
65
|
+
* @param unsignedProof The unsigned proof.
|
|
66
|
+
* @returns The created hash.
|
|
67
|
+
*/
|
|
68
|
+
async createHash(unsecuredDocument, unsignedProof) {
|
|
69
|
+
// Delegate to the sync implementation
|
|
70
|
+
return this._syncSignerVerifier.createHash(unsecuredDocument, unsignedProof);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=dataIntegrityProofAsyncSignerVerifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dataIntegrityProofAsyncSignerVerifier.js","sourceRoot":"","sources":["../../../src/signerVerifiers/dataIntegrityProofAsyncSignerVerifier.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAGjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D;;;GAGG;AACH,MAAM,OAAO,qCAAqC;IACjD;;OAEG;IACI,MAAM,CAAU,UAAU,2CAA2D;IAE5F;;;OAGG;IACc,mBAAmB,CAAmC;IAEvE;;OAEG;IACH;QACC,IAAI,CAAC,mBAAmB,GAAG,IAAI,gCAAgC,EAAE,CAAC;IACnE,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,qBAAqB,CACjC,iBAAoC,EACpC,aAAkC,EAClC,YAA0E;QAE1E,MAAM,CAAC,MAAM,CACZ,qCAAqC,CAAC,UAAU,uBAEhD,iBAAiB,CACjB,CAAC;QACF,MAAM,CAAC,MAAM,CACZ,qCAAqC,CAAC,UAAU,mBAEhD,aAAa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/core\";\nimport { JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IJwk } from \"@twin.org/web\";\nimport { DataIntegrityProofSignerVerifier } from \"./dataIntegrityProofSignerVerifier.js\";\nimport { DidContexts } from \"../models/didContexts.js\";\nimport type { IDataIntegrityProof } from \"../models/IDataIntegrityProof.js\";\nimport type { IProof } from \"../models/IProof.js\";\nimport type { IProofSignerVerifierAsync } from \"../models/IProofSignerVerifierAsync.js\";\nimport { JwsAlgorithms } from \"../models/jwsAlgorithms.js\";\n\n/**\n * Helper methods for creating and verifying Data Integrity proofs with async signing callbacks.\n * @see https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022\n */\nexport class DataIntegrityProofAsyncSignerVerifier implements IProofSignerVerifierAsync {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DataIntegrityProofAsyncSignerVerifier>();\n\n\t/**\n\t * The underlying sync signer verifier for hash and verify operations.\n\t * @internal\n\t */\n\tprivate readonly _syncSignerVerifier: DataIntegrityProofSignerVerifier;\n\n\t/**\n\t * Create a new instance of DataIntegrityProofAsyncSignerVerifier.\n\t */\n\tconstructor() {\n\t\tthis._syncSignerVerifier = new DataIntegrityProofSignerVerifier();\n\t}\n\n\t/**\n\t * Create a proof with an async signing callback.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The proof options.\n\t * @param signCallback Async callback that signs data with a private key from secure storage.\n\t * @returns The created proof.\n\t */\n\tpublic async createProofWithSigner(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IDataIntegrityProof,\n\t\tsignCallback: (data: Uint8Array, algorithm: string) => Promise<Uint8Array>\n\t): Promise<IProof> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tDataIntegrityProofAsyncSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IProof>(\n\t\t\tDataIntegrityProofAsyncSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof),\n\t\t\tunsignedProof\n\t\t);\n\t\tGuards.function(\n\t\t\tDataIntegrityProofAsyncSignerVerifier.CLASS_NAME,\n\t\t\tnameof(signCallback),\n\t\t\tsignCallback\n\t\t);\n\n\t\tconst unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);\n\n\t\tconst signedProof = ObjectHelper.clone(unsignedProof);\n\n\t\tunsecuredDocumentClone[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\tunsecuredDocumentClone[\"@context\"],\n\t\t\tDidContexts.ContextDataIntegrity\n\t\t);\n\n\t\tsignedProof[\"@context\"] = unsecuredDocumentClone[\"@context\"] as IDataIntegrityProof[\"@context\"];\n\n\t\t// Use the sync verifier to create the hash\n\t\tconst combinedHash = await this.createHash(unsecuredDocument, unsignedProof);\n\n\t\t// Sign with the callback (key stays in secure storage)\n\t\t// Pass JWS algorithm for vault validation\n\t\tconst signature = await signCallback(combinedHash, JwsAlgorithms.EdDSA);\n\n\t\tsignedProof.proofValue = `z${Converter.bytesToBase58(signature)}`;\n\n\t\treturn signedProof;\n\t}\n\n\t/**\n\t * Verify a proof for the given data.\n\t * @param securedDocument The credential to verify.\n\t * @param signedProof The proof to verify.\n\t * @param verifyKey The public key to verify the proof with.\n\t * @returns True if the credential was verified.\n\t */\n\tpublic async verifyProof(\n\t\tsecuredDocument: IJsonLdNodeObject,\n\t\tsignedProof: IDataIntegrityProof,\n\t\tverifyKey: IJwk\n\t): Promise<boolean> {\n\t\t// Delegate to the sync implementation\n\t\treturn this._syncSignerVerifier.verifyProof(securedDocument, signedProof, verifyKey);\n\t}\n\n\t/**\n\t * Create a hash for the given data.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The unsigned proof.\n\t * @returns The created hash.\n\t */\n\tpublic async createHash(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IDataIntegrityProof\n\t): Promise<Uint8Array> {\n\t\t// Delegate to the sync implementation\n\t\treturn this._syncSignerVerifier.createHash(unsecuredDocument, unsignedProof);\n\t}\n}\n"]}
|
|
@@ -7,8 +7,8 @@ import { Jwk } from "@twin.org/web";
|
|
|
7
7
|
import { DidContexts } from "../models/didContexts.js";
|
|
8
8
|
import { DidCryptoSuites } from "../models/didCryptoSuites.js";
|
|
9
9
|
/**
|
|
10
|
-
* Helper methods for creating and verifying proofs.
|
|
11
|
-
* https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022
|
|
10
|
+
* Helper methods for creating and verifying Data Integrity proofs using EdDSA-JCS-2022.
|
|
11
|
+
* @see https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022
|
|
12
12
|
*/
|
|
13
13
|
export class DataIntegrityProofSignerVerifier {
|
|
14
14
|
/**
|
|
@@ -40,7 +40,7 @@ export class DataIntegrityProofSignerVerifier {
|
|
|
40
40
|
return signedProof;
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
|
-
* Verify a proof for the given data
|
|
43
|
+
* Verify a proof for the given data.
|
|
44
44
|
* @param securedDocument The credential to verify.
|
|
45
45
|
* @param signedProof The proof to verify.
|
|
46
46
|
* @param verifyKey The public key to verify the proof with.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataIntegrityProofSignerVerifier.js","sourceRoot":"","sources":["../../../src/signerVerifiers/dataIntegrityProofSignerVerifier.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAEjF,OAAO,EAAE,GAAG,EAAa,MAA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,gBAAgB,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAC7E,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tJsonHelper,\n\tObjectHelper,\n\tUint8ArrayHelper\n} from \"@twin.org/core\";\nimport { Ed25519, Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { Jwk, type IJwk } from \"@twin.org/web\";\nimport { DidContexts } from \"../models/didContexts.js\";\nimport { DidCryptoSuites } from \"../models/didCryptoSuites.js\";\nimport type { IDataIntegrityProof } from \"../models/IDataIntegrityProof.js\";\nimport type { IProof } from \"../models/IProof.js\";\nimport type { IProofSignerVerifier } from \"../models/IProofSignerVerifier.js\";\n\n/**\n * Helper methods for creating and verifying proofs.\n * https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022\n */\nexport class DataIntegrityProofSignerVerifier implements IProofSignerVerifier {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DataIntegrityProofSignerVerifier>();\n\n\t/**\n\t * Create a proof for the given data.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The proof options.\n\t * @param signKey The key to sign the proof with.\n\t * @returns The created proof.\n\t */\n\tpublic async createProof(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IDataIntegrityProof,\n\t\tsignKey: IJwk\n\t): Promise<IProof> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IProof>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof),\n\t\t\tunsignedProof\n\t\t);\n\t\tGuards.object<IJwk>(DataIntegrityProofSignerVerifier.CLASS_NAME, nameof(signKey), signKey);\n\n\t\tconst rawKeys = await Jwk.toRaw(signKey);\n\t\tif (!Is.uint8Array(rawKeys.privateKey)) {\n\t\t\tthrow new GeneralError(DataIntegrityProofSignerVerifier.CLASS_NAME, \"missingPrivateKey\");\n\t\t}\n\n\t\tconst unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);\n\n\t\tconst signedProof = ObjectHelper.clone(unsignedProof);\n\n\t\tunsecuredDocumentClone[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\tunsecuredDocumentClone[\"@context\"],\n\t\t\tDidContexts.ContextDataIntegrity\n\t\t);\n\n\t\tsignedProof[\"@context\"] = unsecuredDocumentClone[\"@context\"] as IDataIntegrityProof[\"@context\"];\n\n\t\tconst combinedHash = await this.createHash(unsecuredDocument, unsignedProof);\n\n\t\tconst signature = Ed25519.sign(rawKeys.privateKey, combinedHash);\n\n\t\tsignedProof.proofValue = `z${Converter.bytesToBase58(signature)}`;\n\n\t\treturn signedProof;\n\t}\n\n\t/**\n\t * Verify a proof for the given data in format.\n\t * @param securedDocument The credential to verify.\n\t * @param signedProof The proof to verify.\n\t * @param verifyKey The public key to verify the proof with.\n\t * @returns True if the credential was verified.\n\t */\n\tpublic async verifyProof(\n\t\tsecuredDocument: IJsonLdNodeObject,\n\t\tsignedProof: IDataIntegrityProof,\n\t\tverifyKey: IJwk\n\t): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(securedDocument),\n\t\t\tsecuredDocument\n\t\t);\n\t\tGuards.object<IDataIntegrityProof>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(signedProof),\n\t\t\tsignedProof\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(signedProof.proofValue),\n\t\t\tsignedProof.proofValue\n\t\t);\n\t\tGuards.object<IJwk>(DataIntegrityProofSignerVerifier.CLASS_NAME, nameof(verifyKey), verifyKey);\n\n\t\tconst rawKeys = await Jwk.toRaw(verifyKey);\n\t\tif (!Is.uint8Array(rawKeys.publicKey)) {\n\t\t\tthrow new GeneralError(DataIntegrityProofSignerVerifier.CLASS_NAME, \"missingPublicKey\");\n\t\t}\n\n\t\tconst combinedHash = await this.createHash(securedDocument, signedProof);\n\n\t\treturn Ed25519.verify(\n\t\t\trawKeys.publicKey,\n\t\t\tcombinedHash,\n\t\t\tConverter.base58ToBytes(signedProof.proofValue.slice(1))\n\t\t);\n\t}\n\n\t/**\n\t * Create a hash for the given data.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The unsigned proof.\n\t * @returns The created hash.\n\t */\n\tpublic async createHash(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IDataIntegrityProof\n\t): Promise<Uint8Array> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IDataIntegrityProof>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof),\n\t\t\tunsignedProof\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof.cryptosuite),\n\t\t\tunsignedProof.cryptosuite\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof.verificationMethod),\n\t\t\tunsignedProof.verificationMethod\n\t\t);\n\n\t\tconst unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);\n\t\tconst proofOptionsClone = ObjectHelper.clone(unsignedProof);\n\n\t\tdelete unsecuredDocumentClone.proof;\n\t\tdelete proofOptionsClone.proofValue;\n\n\t\tif (proofOptionsClone.cryptosuite !== DidCryptoSuites.EdDSAJcs2022) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\t\t\"cryptosuiteNotSupported\",\n\t\t\t\t{\n\t\t\t\t\tcryptoSuite: proofOptionsClone.cryptosuite\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tunsecuredDocumentClone[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\tunsecuredDocumentClone[\"@context\"],\n\t\t\tDidContexts.ContextDataIntegrity\n\t\t);\n\n\t\tproofOptionsClone[\"@context\"] = unsecuredDocumentClone[\n\t\t\t\"@context\"\n\t\t] as IDataIntegrityProof[\"@context\"];\n\n\t\tconst transformedDocument = JsonHelper.canonicalize(unsecuredDocumentClone);\n\n\t\tconst transformedDocumentHash = Sha256.sum256(Converter.utf8ToBytes(transformedDocument));\n\n\t\tconst transformedProofOptions = JsonHelper.canonicalize(proofOptionsClone);\n\n\t\tconst proofOptionsHash = Sha256.sum256(Converter.utf8ToBytes(transformedProofOptions));\n\n\t\treturn Uint8ArrayHelper.concat([proofOptionsHash, transformedDocumentHash]);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dataIntegrityProofSignerVerifier.js","sourceRoot":"","sources":["../../../src/signerVerifiers/dataIntegrityProofSignerVerifier.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAEjF,OAAO,EAAE,GAAG,EAAa,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM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AAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tJsonHelper,\n\tObjectHelper,\n\tUint8ArrayHelper\n} from \"@twin.org/core\";\nimport { Ed25519, Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { Jwk, type IJwk } from \"@twin.org/web\";\nimport { DidContexts } from \"../models/didContexts.js\";\nimport { DidCryptoSuites } from \"../models/didCryptoSuites.js\";\nimport type { IDataIntegrityProof } from \"../models/IDataIntegrityProof.js\";\nimport type { IProof } from \"../models/IProof.js\";\nimport type { IProofSignerVerifier } from \"../models/IProofSignerVerifier.js\";\n\n/**\n * Helper methods for creating and verifying Data Integrity proofs using EdDSA-JCS-2022.\n * @see https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022\n */\nexport class DataIntegrityProofSignerVerifier implements IProofSignerVerifier {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<DataIntegrityProofSignerVerifier>();\n\n\t/**\n\t * Create a proof for the given data.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The proof options.\n\t * @param signKey The key to sign the proof with.\n\t * @returns The created proof.\n\t */\n\tpublic async createProof(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IDataIntegrityProof,\n\t\tsignKey: IJwk\n\t): Promise<IProof> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IProof>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof),\n\t\t\tunsignedProof\n\t\t);\n\t\tGuards.object<IJwk>(DataIntegrityProofSignerVerifier.CLASS_NAME, nameof(signKey), signKey);\n\n\t\tconst rawKeys = await Jwk.toRaw(signKey);\n\t\tif (!Is.uint8Array(rawKeys.privateKey)) {\n\t\t\tthrow new GeneralError(DataIntegrityProofSignerVerifier.CLASS_NAME, \"missingPrivateKey\");\n\t\t}\n\n\t\tconst unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);\n\n\t\tconst signedProof = ObjectHelper.clone(unsignedProof);\n\n\t\tunsecuredDocumentClone[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\tunsecuredDocumentClone[\"@context\"],\n\t\t\tDidContexts.ContextDataIntegrity\n\t\t);\n\n\t\tsignedProof[\"@context\"] = unsecuredDocumentClone[\"@context\"] as IDataIntegrityProof[\"@context\"];\n\n\t\tconst combinedHash = await this.createHash(unsecuredDocument, unsignedProof);\n\n\t\tconst signature = Ed25519.sign(rawKeys.privateKey, combinedHash);\n\n\t\tsignedProof.proofValue = `z${Converter.bytesToBase58(signature)}`;\n\n\t\treturn signedProof;\n\t}\n\n\t/**\n\t * Verify a proof for the given data.\n\t * @param securedDocument The credential to verify.\n\t * @param signedProof The proof to verify.\n\t * @param verifyKey The public key to verify the proof with.\n\t * @returns True if the credential was verified.\n\t */\n\tpublic async verifyProof(\n\t\tsecuredDocument: IJsonLdNodeObject,\n\t\tsignedProof: IDataIntegrityProof,\n\t\tverifyKey: IJwk\n\t): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(securedDocument),\n\t\t\tsecuredDocument\n\t\t);\n\t\tGuards.object<IDataIntegrityProof>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(signedProof),\n\t\t\tsignedProof\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(signedProof.proofValue),\n\t\t\tsignedProof.proofValue\n\t\t);\n\t\tGuards.object<IJwk>(DataIntegrityProofSignerVerifier.CLASS_NAME, nameof(verifyKey), verifyKey);\n\n\t\tconst rawKeys = await Jwk.toRaw(verifyKey);\n\t\tif (!Is.uint8Array(rawKeys.publicKey)) {\n\t\t\tthrow new GeneralError(DataIntegrityProofSignerVerifier.CLASS_NAME, \"missingPublicKey\");\n\t\t}\n\n\t\tconst combinedHash = await this.createHash(securedDocument, signedProof);\n\n\t\treturn Ed25519.verify(\n\t\t\trawKeys.publicKey,\n\t\t\tcombinedHash,\n\t\t\tConverter.base58ToBytes(signedProof.proofValue.slice(1))\n\t\t);\n\t}\n\n\t/**\n\t * Create a hash for the given data.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The unsigned proof.\n\t * @returns The created hash.\n\t */\n\tpublic async createHash(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IDataIntegrityProof\n\t): Promise<Uint8Array> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IDataIntegrityProof>(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof),\n\t\t\tunsignedProof\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof.cryptosuite),\n\t\t\tunsignedProof.cryptosuite\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof.verificationMethod),\n\t\t\tunsignedProof.verificationMethod\n\t\t);\n\n\t\tconst unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);\n\t\tconst proofOptionsClone = ObjectHelper.clone(unsignedProof);\n\n\t\tdelete unsecuredDocumentClone.proof;\n\t\tdelete proofOptionsClone.proofValue;\n\n\t\tif (proofOptionsClone.cryptosuite !== DidCryptoSuites.EdDSAJcs2022) {\n\t\t\tthrow new GeneralError(\n\t\t\t\tDataIntegrityProofSignerVerifier.CLASS_NAME,\n\t\t\t\t\"cryptosuiteNotSupported\",\n\t\t\t\t{\n\t\t\t\t\tcryptoSuite: proofOptionsClone.cryptosuite\n\t\t\t\t}\n\t\t\t);\n\t\t}\n\n\t\tunsecuredDocumentClone[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\tunsecuredDocumentClone[\"@context\"],\n\t\t\tDidContexts.ContextDataIntegrity\n\t\t);\n\n\t\tproofOptionsClone[\"@context\"] = unsecuredDocumentClone[\n\t\t\t\"@context\"\n\t\t] as IDataIntegrityProof[\"@context\"];\n\n\t\tconst transformedDocument = JsonHelper.canonicalize(unsecuredDocumentClone);\n\n\t\tconst transformedDocumentHash = Sha256.sum256(Converter.utf8ToBytes(transformedDocument));\n\n\t\tconst transformedProofOptions = JsonHelper.canonicalize(proofOptionsClone);\n\n\t\tconst proofOptionsHash = Sha256.sum256(Converter.utf8ToBytes(transformedProofOptions));\n\n\t\treturn Uint8ArrayHelper.concat([proofOptionsHash, transformedDocumentHash]);\n\t}\n}\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Converter, Guards, ObjectHelper } from "@twin.org/core";
|
|
4
|
+
import { JsonLdProcessor } from "@twin.org/data-json-ld";
|
|
5
|
+
import { JsonWebSignature2020SignerVerifier } from "./jsonWebSignature2020SignerVerifier.js";
|
|
6
|
+
import { DidContexts } from "../models/didContexts.js";
|
|
7
|
+
import { JwsAlgorithms } from "../models/jwsAlgorithms.js";
|
|
8
|
+
/**
|
|
9
|
+
* Helper methods for creating and verifying JsonWebSignature2020 proofs with async signing callbacks.
|
|
10
|
+
* This implementation creates JWS signatures manually per RFC 7515 to support async signing callbacks.
|
|
11
|
+
*/
|
|
12
|
+
export class JsonWebSignature2020AsyncSignerVerifier {
|
|
13
|
+
/**
|
|
14
|
+
* Runtime name for the class.
|
|
15
|
+
*/
|
|
16
|
+
static CLASS_NAME = "JsonWebSignature2020AsyncSignerVerifier";
|
|
17
|
+
/**
|
|
18
|
+
* The underlying sync signer verifier for hash and verify operations.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
_syncSignerVerifier;
|
|
22
|
+
/**
|
|
23
|
+
* Create a new instance of JsonWebSignature2020AsyncSignerVerifier.
|
|
24
|
+
*/
|
|
25
|
+
constructor() {
|
|
26
|
+
this._syncSignerVerifier = new JsonWebSignature2020SignerVerifier();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a proof with an async signing callback.
|
|
30
|
+
* @param unsecuredDocument The data to create the proof for.
|
|
31
|
+
* @param unsignedProof The proof options.
|
|
32
|
+
* @param signCallback Async callback that signs data with a private key from secure storage.
|
|
33
|
+
* @returns The created proof.
|
|
34
|
+
*/
|
|
35
|
+
async createProofWithSigner(unsecuredDocument, unsignedProof, signCallback) {
|
|
36
|
+
Guards.object(JsonWebSignature2020AsyncSignerVerifier.CLASS_NAME, "unsecuredDocument", unsecuredDocument);
|
|
37
|
+
Guards.object(JsonWebSignature2020AsyncSignerVerifier.CLASS_NAME, "unsignedProof", unsignedProof);
|
|
38
|
+
Guards.function(JsonWebSignature2020AsyncSignerVerifier.CLASS_NAME, "signCallback", signCallback);
|
|
39
|
+
const unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);
|
|
40
|
+
unsecuredDocumentClone["@context"] = JsonLdProcessor.combineContexts(unsecuredDocumentClone["@context"], DidContexts.ContextSecurityJws2020);
|
|
41
|
+
// Use the sync verifier to create the hash
|
|
42
|
+
const hash = await this.createHash(unsecuredDocument, unsignedProof);
|
|
43
|
+
// Create JWS manually per RFC 7515 (Compact Serialization)
|
|
44
|
+
// Format: BASE64URL(UTF8(JWS Protected Header)) || '.' || BASE64URL(JWS Payload) || '.' || BASE64URL(JWS Signature)
|
|
45
|
+
// JWS Protected Header for EdDSA with detached payload
|
|
46
|
+
const header = {
|
|
47
|
+
alg: "EdDSA",
|
|
48
|
+
crit: ["b64"],
|
|
49
|
+
b64: false
|
|
50
|
+
};
|
|
51
|
+
const headerJson = JSON.stringify(header);
|
|
52
|
+
const headerBase64 = Converter.bytesToBase64Url(Converter.utf8ToBytes(headerJson));
|
|
53
|
+
// Create signing input: header.payload (detached payload means payload is the hash)
|
|
54
|
+
const signingInput = Converter.utf8ToBytes(`${headerBase64}.`);
|
|
55
|
+
const dataToSign = new Uint8Array(signingInput.length + hash.length);
|
|
56
|
+
dataToSign.set(signingInput, 0);
|
|
57
|
+
dataToSign.set(hash, signingInput.length);
|
|
58
|
+
// Sign with the callback (key stays in secure storage)
|
|
59
|
+
// Pass JWS algorithm for vault validation
|
|
60
|
+
const signature = await signCallback(dataToSign, JwsAlgorithms.EdDSA);
|
|
61
|
+
// Construct JWS: header..signature (empty payload section for detached content)
|
|
62
|
+
const signatureBase64 = Converter.bytesToBase64Url(signature);
|
|
63
|
+
const jws = `${headerBase64}..${signatureBase64}`;
|
|
64
|
+
const signedProof = ObjectHelper.clone(unsignedProof);
|
|
65
|
+
signedProof["@context"] = unsecuredDocumentClone["@context"];
|
|
66
|
+
signedProof.jws = jws;
|
|
67
|
+
return signedProof;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Verify a proof for the given data.
|
|
71
|
+
* @param securedDocument The credential to verify.
|
|
72
|
+
* @param signedProof The proof to verify.
|
|
73
|
+
* @param verifyKey The public key to verify the proof with.
|
|
74
|
+
* @returns True if the credential was verified.
|
|
75
|
+
*/
|
|
76
|
+
async verifyProof(securedDocument, signedProof, verifyKey) {
|
|
77
|
+
// Delegate to the sync implementation (verification doesn't need the private key)
|
|
78
|
+
return this._syncSignerVerifier.verifyProof(securedDocument, signedProof, verifyKey);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Create a hash for the given data.
|
|
82
|
+
* @param unsecuredDocument The data to create the proof for.
|
|
83
|
+
* @param unsignedProof The unsigned proof.
|
|
84
|
+
* @returns The created hash.
|
|
85
|
+
*/
|
|
86
|
+
async createHash(unsecuredDocument, unsignedProof) {
|
|
87
|
+
// Delegate to the sync implementation
|
|
88
|
+
return this._syncSignerVerifier.createHash(unsecuredDocument, unsignedProof);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=jsonWebSignature2020AsyncSignerVerifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonWebSignature2020AsyncSignerVerifier.js","sourceRoot":"","sources":["../../../src/signerVerifiers/jsonWebSignature2020AsyncSignerVerifier.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAGjF,OAAO,EAAE,kCAAkC,EAAE,MAAM,yCAAyC,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D;;;GAGG;AACH,MAAM,OAAO,uCAAuC;IACnD;;OAEG;IACI,MAAM,CAAU,UAAU,6CAA6D;IAE9F;;;OAGG;IACc,mBAAmB,CAAqC;IAEzE;;OAEG;IACH;QACC,IAAI,CAAC,mBAAmB,GAAG,IAAI,kCAAkC,EAAE,CAAC;IACrE,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,qBAAqB,CACjC,iBAAoC,EACpC,aAAyC,EACzC,YAA0E;QAE1E,MAAM,CAAC,MAAM,CACZ,uCAAuC,CAAC,UAAU,uBAElD,iBAAiB,CACjB,CAAC;QACF,MAAM,CAAC,MAAM,CACZ,uCAAuC,CAAC,UAAU,mBAElD,aAAa,CACb,CAAC;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D,MAAM,GAAG,GAAG,GAAG,YAAY,KAAK,eAAe,EAAE,CAAC;QAElD,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAEtD,WAAW,CAAC,UAAU,CAAC,GAAG,sBAAsB,CAC/C,UAAU,CACgC,CAAC;QAE5C,WAAW,CAAC,GAAG,GAAG,GAAG,CAAC;QAEtB,OAAO,WAAW,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CACvB,eAAkC,EAClC,WAAuC,EACvC,SAAe;QAEf,kFAAkF;QAClF,OAAO,IAAI,CAAC,mBAAmB,CAAC,WAAW,CAAC,eAAe,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACtF,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,UAAU,CACtB,iBAAoC,EACpC,aAAyC;QAEzC,sCAAsC;QACtC,OAAO,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;IAC9E,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Converter, Guards, ObjectHelper } from \"@twin.org/core\";\nimport { JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IJwk } from \"@twin.org/web\";\nimport { JsonWebSignature2020SignerVerifier } from \"./jsonWebSignature2020SignerVerifier.js\";\nimport { DidContexts } from \"../models/didContexts.js\";\nimport type { IJsonWebSignature2020Proof } from \"../models/IJsonWebSignature2020Proof.js\";\nimport type { IProofSignerVerifierAsync } from \"../models/IProofSignerVerifierAsync.js\";\nimport { JwsAlgorithms } from \"../models/jwsAlgorithms.js\";\n\n/**\n * Helper methods for creating and verifying JsonWebSignature2020 proofs with async signing callbacks.\n * This implementation creates JWS signatures manually per RFC 7515 to support async signing callbacks.\n */\nexport class JsonWebSignature2020AsyncSignerVerifier implements IProofSignerVerifierAsync {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<JsonWebSignature2020AsyncSignerVerifier>();\n\n\t/**\n\t * The underlying sync signer verifier for hash and verify operations.\n\t * @internal\n\t */\n\tprivate readonly _syncSignerVerifier: JsonWebSignature2020SignerVerifier;\n\n\t/**\n\t * Create a new instance of JsonWebSignature2020AsyncSignerVerifier.\n\t */\n\tconstructor() {\n\t\tthis._syncSignerVerifier = new JsonWebSignature2020SignerVerifier();\n\t}\n\n\t/**\n\t * Create a proof with an async signing callback.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The proof options.\n\t * @param signCallback Async callback that signs data with a private key from secure storage.\n\t * @returns The created proof.\n\t */\n\tpublic async createProofWithSigner(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IJsonWebSignature2020Proof,\n\t\tsignCallback: (data: Uint8Array, algorithm: string) => Promise<Uint8Array>\n\t): Promise<IJsonWebSignature2020Proof> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tJsonWebSignature2020AsyncSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonWebSignature2020Proof>(\n\t\t\tJsonWebSignature2020AsyncSignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof),\n\t\t\tunsignedProof\n\t\t);\n\t\tGuards.function(\n\t\t\tJsonWebSignature2020AsyncSignerVerifier.CLASS_NAME,\n\t\t\tnameof(signCallback),\n\t\t\tsignCallback\n\t\t);\n\n\t\tconst unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);\n\n\t\tunsecuredDocumentClone[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\tunsecuredDocumentClone[\"@context\"],\n\t\t\tDidContexts.ContextSecurityJws2020\n\t\t);\n\n\t\t// Use the sync verifier to create the hash\n\t\tconst hash = await this.createHash(unsecuredDocument, unsignedProof);\n\n\t\t// Create JWS manually per RFC 7515 (Compact Serialization)\n\t\t// Format: BASE64URL(UTF8(JWS Protected Header)) || '.' || BASE64URL(JWS Payload) || '.' || BASE64URL(JWS Signature)\n\n\t\t// JWS Protected Header for EdDSA with detached payload\n\t\tconst header = {\n\t\t\talg: \"EdDSA\",\n\t\t\tcrit: [\"b64\"],\n\t\t\tb64: false\n\t\t};\n\n\t\tconst headerJson = JSON.stringify(header);\n\t\tconst headerBase64 = Converter.bytesToBase64Url(Converter.utf8ToBytes(headerJson));\n\n\t\t// Create signing input: header.payload (detached payload means payload is the hash)\n\t\tconst signingInput = Converter.utf8ToBytes(`${headerBase64}.`);\n\t\tconst dataToSign = new Uint8Array(signingInput.length + hash.length);\n\t\tdataToSign.set(signingInput, 0);\n\t\tdataToSign.set(hash, signingInput.length);\n\n\t\t// Sign with the callback (key stays in secure storage)\n\t\t// Pass JWS algorithm for vault validation\n\t\tconst signature = await signCallback(dataToSign, JwsAlgorithms.EdDSA);\n\n\t\t// Construct JWS: header..signature (empty payload section for detached content)\n\t\tconst signatureBase64 = Converter.bytesToBase64Url(signature);\n\t\tconst jws = `${headerBase64}..${signatureBase64}`;\n\n\t\tconst signedProof = ObjectHelper.clone(unsignedProof);\n\n\t\tsignedProof[\"@context\"] = unsecuredDocumentClone[\n\t\t\t\"@context\"\n\t\t] as IJsonWebSignature2020Proof[\"@context\"];\n\n\t\tsignedProof.jws = jws;\n\n\t\treturn signedProof;\n\t}\n\n\t/**\n\t * Verify a proof for the given data.\n\t * @param securedDocument The credential to verify.\n\t * @param signedProof The proof to verify.\n\t * @param verifyKey The public key to verify the proof with.\n\t * @returns True if the credential was verified.\n\t */\n\tpublic async verifyProof(\n\t\tsecuredDocument: IJsonLdNodeObject,\n\t\tsignedProof: IJsonWebSignature2020Proof,\n\t\tverifyKey: IJwk\n\t): Promise<boolean> {\n\t\t// Delegate to the sync implementation (verification doesn't need the private key)\n\t\treturn this._syncSignerVerifier.verifyProof(securedDocument, signedProof, verifyKey);\n\t}\n\n\t/**\n\t * Create a hash for the given data.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The unsigned proof.\n\t * @returns The created hash.\n\t */\n\tpublic async createHash(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IJsonWebSignature2020Proof\n\t): Promise<Uint8Array> {\n\t\t// Delegate to the sync implementation\n\t\treturn this._syncSignerVerifier.createHash(unsecuredDocument, unsignedProof);\n\t}\n}\n"]}
|
|
@@ -6,7 +6,8 @@ import { JsonLdProcessor } from "@twin.org/data-json-ld";
|
|
|
6
6
|
import { Jwk, Jws } from "@twin.org/web";
|
|
7
7
|
import { DidContexts } from "../models/didContexts.js";
|
|
8
8
|
/**
|
|
9
|
-
* Helper methods for creating and verifying proofs.
|
|
9
|
+
* Helper methods for creating and verifying JsonWebSignature2020 proofs.
|
|
10
|
+
* @see https://w3c-ccg.github.io/lds-jws2020/
|
|
10
11
|
*/
|
|
11
12
|
export class JsonWebSignature2020SignerVerifier {
|
|
12
13
|
/**
|
|
@@ -35,7 +36,7 @@ export class JsonWebSignature2020SignerVerifier {
|
|
|
35
36
|
return signedProof;
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
|
-
* Verify a proof for the given data
|
|
39
|
+
* Verify a proof for the given data.
|
|
39
40
|
* @param securedDocument The credential to verify.
|
|
40
41
|
* @param signedProof The proof to verify.
|
|
41
42
|
* @param verifyKey The public key to verify the proof with.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonWebSignature2020SignerVerifier.js","sourceRoot":"","sources":["../../../src/signerVerifiers/jsonWebSignature2020SignerVerifier.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,YAAY,EACZ,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAEjF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAa,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD
|
|
1
|
+
{"version":3,"file":"jsonWebSignature2020SignerVerifier.js","sourceRoot":"","sources":["../../../src/signerVerifiers/jsonWebSignature2020SignerVerifier.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,SAAS,EACT,YAAY,EACZ,MAAM,EACN,EAAE,EACF,YAAY,EACZ,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,eAAe,EAA0B,MAAM,wBAAwB,CAAC;AAEjF,OAAO,EAAE,GAAG,EAAE,GAAG,EAAa,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD;;;GAGG;AACH,MAAM,OAAO,kCAAkC;IAC9C;;OAEG;IACI,MAAM,CAAU,UAAU,wCAAwD;IAEzF;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CACvB,iBAAoC,EACpC,aAAyC,EACzC,OAAa;QAEb,MAAM,CAAC,MAAM,CACZ,kCAAkC,CAAC,UAAU,uBAE7C,iBAAiB,CACjB,CAAC;QACF,MAAM,CAAC,MAAM,CACZ,kCAAkC,CAAC,UAAU,mBAE7C,aAAa,CACb,CAAC;QACF,MAAM,CAAC,MAAM,CAAO,kCAAkC,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAE7F,MAAM,sBAAsB,GAAG,YAAY,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAErE,sBAAsB,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC,eAAe,CACnE,sBAAsB,CAAC,UAAU,CAAC,EAClC,WAAW,CAAC,sBAAsB,CAClC,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: Apache-2.0.\nimport {\n\tConverter,\n\tGeneralError,\n\tGuards,\n\tIs,\n\tObjectHelper,\n\tUint8ArrayHelper\n} from \"@twin.org/core\";\nimport { Sha256 } from \"@twin.org/crypto\";\nimport { JsonLdProcessor, type IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { Jwk, Jws, type IJwk } from \"@twin.org/web\";\nimport { DidContexts } from \"../models/didContexts.js\";\nimport type { IJsonWebSignature2020Proof } from \"../models/IJsonWebSignature2020Proof.js\";\nimport type { IProofSignerVerifier } from \"../models/IProofSignerVerifier.js\";\n\n/**\n * Helper methods for creating and verifying JsonWebSignature2020 proofs.\n * @see https://w3c-ccg.github.io/lds-jws2020/\n */\nexport class JsonWebSignature2020SignerVerifier implements IProofSignerVerifier {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<JsonWebSignature2020SignerVerifier>();\n\n\t/**\n\t * Create a proof for the given data.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The proof options.\n\t * @param signKey The key to sign the proof with.\n\t * @returns The created proof.\n\t */\n\tpublic async createProof(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IJsonWebSignature2020Proof,\n\t\tsignKey: IJwk\n\t): Promise<IJsonWebSignature2020Proof> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tJsonWebSignature2020SignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonWebSignature2020Proof>(\n\t\t\tJsonWebSignature2020SignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof),\n\t\t\tunsignedProof\n\t\t);\n\t\tGuards.object<IJwk>(JsonWebSignature2020SignerVerifier.CLASS_NAME, nameof(signKey), signKey);\n\n\t\tconst unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);\n\n\t\tunsecuredDocumentClone[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\tunsecuredDocumentClone[\"@context\"],\n\t\t\tDidContexts.ContextSecurityJws2020\n\t\t);\n\n\t\tconst hash = await this.createHash(unsecuredDocument, unsignedProof);\n\n\t\tconst cryptoKey = await Jwk.toCryptoKey(signKey);\n\n\t\tconst signature = await Jws.create(cryptoKey, hash, signKey.alg);\n\n\t\tconst signedProof = ObjectHelper.clone(unsignedProof);\n\n\t\tsignedProof[\"@context\"] = unsecuredDocumentClone[\n\t\t\t\"@context\"\n\t\t] as IJsonWebSignature2020Proof[\"@context\"];\n\n\t\tsignedProof.jws = signature;\n\n\t\treturn signedProof;\n\t}\n\n\t/**\n\t * Verify a proof for the given data.\n\t * @param securedDocument The credential to verify.\n\t * @param signedProof The proof to verify.\n\t * @param verifyKey The public key to verify the proof with.\n\t * @returns True if the credential was verified.\n\t */\n\tpublic async verifyProof(\n\t\tsecuredDocument: IJsonLdNodeObject,\n\t\tsignedProof: IJsonWebSignature2020Proof,\n\t\tverifyKey: IJwk\n\t): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tJsonWebSignature2020SignerVerifier.CLASS_NAME,\n\t\t\tnameof(securedDocument),\n\t\t\tsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonWebSignature2020Proof>(\n\t\t\tJsonWebSignature2020SignerVerifier.CLASS_NAME,\n\t\t\tnameof(signedProof),\n\t\t\tsignedProof\n\t\t);\n\t\tGuards.object<IJwk>(\n\t\t\tJsonWebSignature2020SignerVerifier.CLASS_NAME,\n\t\t\tnameof(verifyKey),\n\t\t\tverifyKey\n\t\t);\n\t\tconst jws = signedProof.jws;\n\t\tif (!Is.stringValue(jws)) {\n\t\t\tthrow new GeneralError(JsonWebSignature2020SignerVerifier.CLASS_NAME, \"missingJws\");\n\t\t}\n\n\t\tconst hash = await this.createHash(securedDocument, signedProof);\n\n\t\tconst cryptoKey = await Jwk.toCryptoKey(verifyKey);\n\n\t\treturn Jws.verify(jws, cryptoKey, hash);\n\t}\n\n\t/**\n\t * Create a hash for the given data.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The unsigned proof.\n\t * @returns The created hash.\n\t */\n\tpublic async createHash(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IJsonWebSignature2020Proof\n\t): Promise<Uint8Array> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tJsonWebSignature2020SignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonWebSignature2020Proof>(\n\t\t\tJsonWebSignature2020SignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof),\n\t\t\tunsignedProof\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tJsonWebSignature2020SignerVerifier.CLASS_NAME,\n\t\t\tnameof(unsignedProof.verificationMethod),\n\t\t\tunsignedProof.verificationMethod\n\t\t);\n\t\tconst unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);\n\t\tconst proofOptionsClone = ObjectHelper.clone(unsignedProof);\n\n\t\tunsecuredDocumentClone[\"@context\"] = JsonLdProcessor.combineContexts(\n\t\t\tunsecuredDocumentClone[\"@context\"],\n\t\t\tDidContexts.ContextSecurityJws2020\n\t\t);\n\n\t\tproofOptionsClone[\"@context\"] = unsecuredDocumentClone[\n\t\t\t\"@context\"\n\t\t] as IJsonWebSignature2020Proof[\"@context\"];\n\n\t\tdelete unsecuredDocumentClone.proof;\n\t\tdelete proofOptionsClone.jws;\n\n\t\tconst canonizedData: string = await JsonLdProcessor.canonize(unsecuredDocumentClone);\n\t\tconst canonizedProof: string = await JsonLdProcessor.canonize(\n\t\t\tproofOptionsClone as unknown as IJsonLdNodeObject\n\t\t);\n\n\t\tconst hashedProof = Sha256.sum256(Converter.utf8ToBytes(canonizedProof));\n\t\tconst hashedData = Sha256.sum256(Converter.utf8ToBytes(canonizedData));\n\n\t\treturn Uint8ArrayHelper.concat([hashedProof, hashedData]);\n\t}\n}\n"]}
|
|
@@ -4,7 +4,9 @@ import { GeneralError, Guards, Is } from "@twin.org/core";
|
|
|
4
4
|
import { DidContexts } from "../models/didContexts.js";
|
|
5
5
|
import { DidCryptoSuites } from "../models/didCryptoSuites.js";
|
|
6
6
|
import { ProofTypes } from "../models/proofTypes.js";
|
|
7
|
+
import { DataIntegrityProofAsyncSignerVerifier } from "../signerVerifiers/dataIntegrityProofAsyncSignerVerifier.js";
|
|
7
8
|
import { DataIntegrityProofSignerVerifier } from "../signerVerifiers/dataIntegrityProofSignerVerifier.js";
|
|
9
|
+
import { JsonWebSignature2020AsyncSignerVerifier } from "../signerVerifiers/jsonWebSignature2020AsyncSignerVerifier.js";
|
|
8
10
|
import { JsonWebSignature2020SignerVerifier } from "../signerVerifiers/jsonWebSignature2020SignerVerifier.js";
|
|
9
11
|
/**
|
|
10
12
|
* Helper methods for creating and verifying proofs.
|
|
@@ -34,6 +36,27 @@ export class ProofHelper {
|
|
|
34
36
|
}
|
|
35
37
|
return signerVerifier;
|
|
36
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Create an async signer verifier that supports signing with callbacks.
|
|
41
|
+
* This enables signing without exposing private keys.
|
|
42
|
+
* @param proofType The type of proof to create.
|
|
43
|
+
* @returns The created async signer verifier.
|
|
44
|
+
* @throws GeneralError if the proof type is not supported.
|
|
45
|
+
*/
|
|
46
|
+
static createAsyncSignerVerifier(proofType) {
|
|
47
|
+
Guards.arrayOneOf(ProofHelper.CLASS_NAME, "proofType", proofType, Object.values(ProofTypes));
|
|
48
|
+
let signerVerifier;
|
|
49
|
+
if (proofType === ProofTypes.DataIntegrityProof) {
|
|
50
|
+
signerVerifier = new DataIntegrityProofAsyncSignerVerifier();
|
|
51
|
+
}
|
|
52
|
+
else if (proofType === ProofTypes.JsonWebSignature2020) {
|
|
53
|
+
signerVerifier = new JsonWebSignature2020AsyncSignerVerifier();
|
|
54
|
+
}
|
|
55
|
+
if (Is.empty(signerVerifier)) {
|
|
56
|
+
throw new GeneralError(ProofHelper.CLASS_NAME, "unsupportedProofType", { proofType });
|
|
57
|
+
}
|
|
58
|
+
return signerVerifier;
|
|
59
|
+
}
|
|
37
60
|
/**
|
|
38
61
|
* Create a proof for the given data.
|
|
39
62
|
* @param proofType The type of proof to create.
|
|
@@ -49,6 +72,22 @@ export class ProofHelper {
|
|
|
49
72
|
Guards.object(ProofHelper.CLASS_NAME, "signKey", signKey);
|
|
50
73
|
return ProofHelper.createSignerVerifier(proofType).createProof(unsecuredDocument, unsignedProof, signKey);
|
|
51
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Create a proof with an async signing callback.
|
|
77
|
+
* This method prevents private key exposure by delegating signing to a secure callback.
|
|
78
|
+
* @param proofType The type of proof to create.
|
|
79
|
+
* @param unsecuredDocument The data to create the proof for.
|
|
80
|
+
* @param unsignedProof The proof options.
|
|
81
|
+
* @param signCallback Async callback that signs data with a private key from secure storage. The algorithm parameter indicates the expected signing algorithm (e.g., "EdDSA") to enable validation.
|
|
82
|
+
* @returns The created proof.
|
|
83
|
+
*/
|
|
84
|
+
static async createProofWithSigner(proofType, unsecuredDocument, unsignedProof, signCallback) {
|
|
85
|
+
Guards.arrayOneOf(ProofHelper.CLASS_NAME, "proofType", proofType, Object.values(ProofTypes));
|
|
86
|
+
Guards.object(ProofHelper.CLASS_NAME, "unsecuredDocument", unsecuredDocument);
|
|
87
|
+
Guards.object(ProofHelper.CLASS_NAME, "unsignedProof", unsignedProof);
|
|
88
|
+
Guards.function(ProofHelper.CLASS_NAME, "signCallback", signCallback);
|
|
89
|
+
return ProofHelper.createAsyncSignerVerifier(proofType).createProofWithSigner(unsecuredDocument, unsignedProof, signCallback);
|
|
90
|
+
}
|
|
52
91
|
/**
|
|
53
92
|
* Verify a proof for the given data.
|
|
54
93
|
* @param securedDocument The credential to verify.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"proofHelper.js","sourceRoot":"","sources":["../../../src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,EAAE,WAAW,CAAC,oBAAoB;gBAC5C,IAAI,EAAE,UAAU,CAAC,kBAAkB;gBACnC,WAAW,EAAE,eAAe,CAAC,YAAY;gBACzC,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;gBAC3C,kBAAkB,EAAE,oBAAoB;gBACxC,YAAY,EAAE,iBAAiB;gBAC/B,GAAG,WAAW;aACd,CAAC;QACH,CAAC;aAAM,IAAI,SAAS,KAAK,UAAU,CAAC,oBAAoB,EAAE,CAAC;YAC1D,KAAK,GAAG;gBACP,UAAU,EAAE,WAAW,CAAC,sBAAsB;gBAC9C,IAAI,EAAE,UAAU,CAAC,oBAAoB;gBACrC,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;gBAC3C,kBAAkB,EAAE,oBAAoB;gBACxC,YAAY,EAAE,iBAAiB;gBAC/B,GAAG,WAAW;aACd,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,YAAY,CAAC,WAAW,CAAC,UAAU,EAAE,sBAAsB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QACvF,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IJwk } from \"@twin.org/web\";\nimport { DidContexts } from \"../models/didContexts.js\";\nimport { DidCryptoSuites } from \"../models/didCryptoSuites.js\";\nimport type { IProof } from \"../models/IProof.js\";\nimport type { IProofSignerVerifier } from \"../models/IProofSignerVerifier.js\";\nimport { ProofTypes } from \"../models/proofTypes.js\";\nimport { DataIntegrityProofSignerVerifier } from \"../signerVerifiers/dataIntegrityProofSignerVerifier.js\";\nimport { JsonWebSignature2020SignerVerifier } from \"../signerVerifiers/jsonWebSignature2020SignerVerifier.js\";\n\n/**\n * Helper methods for creating and verifying proofs.\n */\nexport class ProofHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ProofHelper>();\n\n\t/**\n\t * Create a signer verifier.\n\t * @param proofType The type of proof to create.\n\t * @returns The created signer verifier.\n\t * @throws GeneralError if the proof type is not supported.\n\t */\n\tpublic static createSignerVerifier(proofType: ProofTypes): IProofSignerVerifier {\n\t\tGuards.arrayOneOf(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\n\t\tlet signerVerifier: IProofSignerVerifier | undefined;\n\t\tif (proofType === ProofTypes.DataIntegrityProof) {\n\t\t\tsignerVerifier = new DataIntegrityProofSignerVerifier();\n\t\t} else if (proofType === ProofTypes.JsonWebSignature2020) {\n\t\t\tsignerVerifier = new JsonWebSignature2020SignerVerifier();\n\t\t}\n\n\t\tif (Is.empty(signerVerifier)) {\n\t\t\tthrow new GeneralError(ProofHelper.CLASS_NAME, \"unsupportedProofType\", { proofType });\n\t\t}\n\t\treturn signerVerifier;\n\t}\n\n\t/**\n\t * Create a proof for the given data.\n\t * @param proofType The type of proof to create.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The proof options.\n\t * @param signKey The key to sign the proof with.\n\t * @returns The created proof.\n\t */\n\tpublic static async createProof(\n\t\tproofType: ProofTypes,\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IProof,\n\t\tsignKey: IJwk\n\t): Promise<IProof> {\n\t\tGuards.arrayOneOf(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(ProofHelper.CLASS_NAME, nameof(unsignedProof), unsignedProof);\n\t\tGuards.object<IJwk>(ProofHelper.CLASS_NAME, nameof(signKey), signKey);\n\t\treturn ProofHelper.createSignerVerifier(proofType).createProof(\n\t\t\tunsecuredDocument as unknown as IJsonLdNodeObject,\n\t\t\tunsignedProof,\n\t\t\tsignKey\n\t\t);\n\t}\n\n\t/**\n\t * Verify a proof for the given data.\n\t * @param securedDocument The credential to verify.\n\t * @param signedProof The proof to verify.\n\t * @param verifyKey The public key to verify the proof with.\n\t * @returns True if the credential was verified.\n\t */\n\tpublic static async verifyProof(\n\t\tsecuredDocument: IJsonLdNodeObject,\n\t\tsignedProof: IProof,\n\t\tverifyKey: IJwk\n\t): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(securedDocument),\n\t\t\tsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(ProofHelper.CLASS_NAME, nameof(signedProof), signedProof);\n\t\tGuards.stringValue(ProofHelper.CLASS_NAME, nameof(signedProof.type), signedProof.type);\n\t\tGuards.object<IJwk>(ProofHelper.CLASS_NAME, nameof(verifyKey), verifyKey);\n\n\t\tconst signerVerifier = ProofHelper.createSignerVerifier(signedProof.type as ProofTypes);\n\n\t\treturn signerVerifier.verifyProof(securedDocument, signedProof, verifyKey);\n\t}\n\n\t/**\n\t * Create an unsigned proof.\n\t * @param proofType The type of proof to create.\n\t * @param verificationMethodId The verification method id.\n\t * @param otherParams Other parameters for the proof.\n\t * @returns The created proof.\n\t * @throws GeneralError if the proof type is not supported.\n\t */\n\tpublic static createUnsignedProof(\n\t\tproofType: ProofTypes,\n\t\tverificationMethodId: string,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\totherParams?: any\n\t): IProof {\n\t\tlet proof: IProof | undefined;\n\t\tif (proofType === ProofTypes.DataIntegrityProof) {\n\t\t\tproof = {\n\t\t\t\t\"@context\": DidContexts.ContextDataIntegrity,\n\t\t\t\ttype: ProofTypes.DataIntegrityProof,\n\t\t\t\tcryptosuite: DidCryptoSuites.EdDSAJcs2022,\n\t\t\t\tcreated: new Date(Date.now()).toISOString(),\n\t\t\t\tverificationMethod: verificationMethodId,\n\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t...otherParams\n\t\t\t};\n\t\t} else if (proofType === ProofTypes.JsonWebSignature2020) {\n\t\t\tproof = {\n\t\t\t\t\"@context\": DidContexts.ContextSecurityJws2020,\n\t\t\t\ttype: ProofTypes.JsonWebSignature2020,\n\t\t\t\tcreated: new Date(Date.now()).toISOString(),\n\t\t\t\tverificationMethod: verificationMethodId,\n\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t...otherParams\n\t\t\t};\n\t\t}\n\t\tif (Is.empty(proof)) {\n\t\t\tthrow new GeneralError(ProofHelper.CLASS_NAME, \"unsupportedProofType\", { proofType });\n\t\t}\n\t\treturn proof;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"proofHelper.js","sourceRoot":"","sources":["../../../src/utils/proofHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAI1D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAI/D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,qCAAqC,EAAE,MAAM,6DAA6D,CAAC;AACpH,OAAO,EAAE,gCAAgC,EAAE,MAAM,wDAAwD,CAAC;AAC1G,OAAO,EAAE,uCAAuC,EAAE,MAAM,+DAA+D,CAAC;AACxH,OA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BACP,UAAU,EAAE,WAAW,CAAC,sBAAsB;gBAC9C,IAAI,EAAE,UAAU,CAAC,oBAAoB;gBACrC,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,WAAW,EAAE;gBAC3C,kBAAkB,EAAE,oBAAoB;gBACxC,YAAY,EAAE,iBAAiB;gBAC/B,GAAG,WAAW;aACd,CAAC;QACH,CAAC;QACD,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,YAAY,CAAC,WAAW,CAAC,UAAU,EAAE,sBAAsB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;QACvF,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { GeneralError, Guards, Is } from \"@twin.org/core\";\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport { nameof } from \"@twin.org/nameof\";\nimport type { IJwk } from \"@twin.org/web\";\nimport { DidContexts } from \"../models/didContexts.js\";\nimport { DidCryptoSuites } from \"../models/didCryptoSuites.js\";\nimport type { IProof } from \"../models/IProof.js\";\nimport type { IProofSignerVerifier } from \"../models/IProofSignerVerifier.js\";\nimport type { IProofSignerVerifierAsync } from \"../models/IProofSignerVerifierAsync.js\";\nimport { ProofTypes } from \"../models/proofTypes.js\";\nimport { DataIntegrityProofAsyncSignerVerifier } from \"../signerVerifiers/dataIntegrityProofAsyncSignerVerifier.js\";\nimport { DataIntegrityProofSignerVerifier } from \"../signerVerifiers/dataIntegrityProofSignerVerifier.js\";\nimport { JsonWebSignature2020AsyncSignerVerifier } from \"../signerVerifiers/jsonWebSignature2020AsyncSignerVerifier.js\";\nimport { JsonWebSignature2020SignerVerifier } from \"../signerVerifiers/jsonWebSignature2020SignerVerifier.js\";\n\n/**\n * Helper methods for creating and verifying proofs.\n */\nexport class ProofHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ProofHelper>();\n\n\t/**\n\t * Create a signer verifier.\n\t * @param proofType The type of proof to create.\n\t * @returns The created signer verifier.\n\t * @throws GeneralError if the proof type is not supported.\n\t */\n\tpublic static createSignerVerifier(proofType: ProofTypes): IProofSignerVerifier {\n\t\tGuards.arrayOneOf(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\n\t\tlet signerVerifier: IProofSignerVerifier | undefined;\n\t\tif (proofType === ProofTypes.DataIntegrityProof) {\n\t\t\tsignerVerifier = new DataIntegrityProofSignerVerifier();\n\t\t} else if (proofType === ProofTypes.JsonWebSignature2020) {\n\t\t\tsignerVerifier = new JsonWebSignature2020SignerVerifier();\n\t\t}\n\n\t\tif (Is.empty(signerVerifier)) {\n\t\t\tthrow new GeneralError(ProofHelper.CLASS_NAME, \"unsupportedProofType\", { proofType });\n\t\t}\n\t\treturn signerVerifier;\n\t}\n\n\t/**\n\t * Create an async signer verifier that supports signing with callbacks.\n\t * This enables signing without exposing private keys.\n\t * @param proofType The type of proof to create.\n\t * @returns The created async signer verifier.\n\t * @throws GeneralError if the proof type is not supported.\n\t */\n\tpublic static createAsyncSignerVerifier(proofType: ProofTypes): IProofSignerVerifierAsync {\n\t\tGuards.arrayOneOf(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\n\t\tlet signerVerifier: IProofSignerVerifierAsync | undefined;\n\t\tif (proofType === ProofTypes.DataIntegrityProof) {\n\t\t\tsignerVerifier = new DataIntegrityProofAsyncSignerVerifier();\n\t\t} else if (proofType === ProofTypes.JsonWebSignature2020) {\n\t\t\tsignerVerifier = new JsonWebSignature2020AsyncSignerVerifier();\n\t\t}\n\n\t\tif (Is.empty(signerVerifier)) {\n\t\t\tthrow new GeneralError(ProofHelper.CLASS_NAME, \"unsupportedProofType\", { proofType });\n\t\t}\n\t\treturn signerVerifier;\n\t}\n\n\t/**\n\t * Create a proof for the given data.\n\t * @param proofType The type of proof to create.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The proof options.\n\t * @param signKey The key to sign the proof with.\n\t * @returns The created proof.\n\t */\n\tpublic static async createProof(\n\t\tproofType: ProofTypes,\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IProof,\n\t\tsignKey: IJwk\n\t): Promise<IProof> {\n\t\tGuards.arrayOneOf(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(ProofHelper.CLASS_NAME, nameof(unsignedProof), unsignedProof);\n\t\tGuards.object<IJwk>(ProofHelper.CLASS_NAME, nameof(signKey), signKey);\n\t\treturn ProofHelper.createSignerVerifier(proofType).createProof(\n\t\t\tunsecuredDocument,\n\t\t\tunsignedProof,\n\t\t\tsignKey\n\t\t);\n\t}\n\n\t/**\n\t * Create a proof with an async signing callback.\n\t * This method prevents private key exposure by delegating signing to a secure callback.\n\t * @param proofType The type of proof to create.\n\t * @param unsecuredDocument The data to create the proof for.\n\t * @param unsignedProof The proof options.\n\t * @param signCallback Async callback that signs data with a private key from secure storage. The algorithm parameter indicates the expected signing algorithm (e.g., \"EdDSA\") to enable validation.\n\t * @returns The created proof.\n\t */\n\tpublic static async createProofWithSigner(\n\t\tproofType: ProofTypes,\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IProof,\n\t\tsignCallback: (data: Uint8Array, algorithm: string) => Promise<Uint8Array>\n\t): Promise<IProof> {\n\t\tGuards.arrayOneOf(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(proofType),\n\t\t\tproofType,\n\t\t\tObject.values(ProofTypes)\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(unsecuredDocument),\n\t\t\tunsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(ProofHelper.CLASS_NAME, nameof(unsignedProof), unsignedProof);\n\t\tGuards.function(ProofHelper.CLASS_NAME, nameof(signCallback), signCallback);\n\n\t\treturn ProofHelper.createAsyncSignerVerifier(proofType).createProofWithSigner(\n\t\t\tunsecuredDocument,\n\t\t\tunsignedProof,\n\t\t\tsignCallback\n\t\t);\n\t}\n\n\t/**\n\t * Verify a proof for the given data.\n\t * @param securedDocument The credential to verify.\n\t * @param signedProof The proof to verify.\n\t * @param verifyKey The public key to verify the proof with.\n\t * @returns True if the credential was verified.\n\t */\n\tpublic static async verifyProof(\n\t\tsecuredDocument: IJsonLdNodeObject,\n\t\tsignedProof: IProof,\n\t\tverifyKey: IJwk\n\t): Promise<boolean> {\n\t\tGuards.object<IJsonLdNodeObject>(\n\t\t\tProofHelper.CLASS_NAME,\n\t\t\tnameof(securedDocument),\n\t\t\tsecuredDocument\n\t\t);\n\t\tGuards.object<IJsonLdNodeObject>(ProofHelper.CLASS_NAME, nameof(signedProof), signedProof);\n\t\tGuards.stringValue(ProofHelper.CLASS_NAME, nameof(signedProof.type), signedProof.type);\n\t\tGuards.object<IJwk>(ProofHelper.CLASS_NAME, nameof(verifyKey), verifyKey);\n\n\t\tconst signerVerifier = ProofHelper.createSignerVerifier(signedProof.type);\n\n\t\treturn signerVerifier.verifyProof(securedDocument, signedProof, verifyKey);\n\t}\n\n\t/**\n\t * Create an unsigned proof.\n\t * @param proofType The type of proof to create.\n\t * @param verificationMethodId The verification method id.\n\t * @param otherParams Other parameters for the proof.\n\t * @returns The created proof.\n\t * @throws GeneralError if the proof type is not supported.\n\t */\n\tpublic static createUnsignedProof(\n\t\tproofType: ProofTypes,\n\t\tverificationMethodId: string,\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\totherParams?: any\n\t): IProof {\n\t\tlet proof: IProof | undefined;\n\t\tif (proofType === ProofTypes.DataIntegrityProof) {\n\t\t\tproof = {\n\t\t\t\t\"@context\": DidContexts.ContextDataIntegrity,\n\t\t\t\ttype: ProofTypes.DataIntegrityProof,\n\t\t\t\tcryptosuite: DidCryptoSuites.EdDSAJcs2022,\n\t\t\t\tcreated: new Date(Date.now()).toISOString(),\n\t\t\t\tverificationMethod: verificationMethodId,\n\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t...otherParams\n\t\t\t};\n\t\t} else if (proofType === ProofTypes.JsonWebSignature2020) {\n\t\t\tproof = {\n\t\t\t\t\"@context\": DidContexts.ContextSecurityJws2020,\n\t\t\t\ttype: ProofTypes.JsonWebSignature2020,\n\t\t\t\tcreated: new Date(Date.now()).toISOString(),\n\t\t\t\tverificationMethod: verificationMethodId,\n\t\t\t\tproofPurpose: \"assertionMethod\",\n\t\t\t\t...otherParams\n\t\t\t};\n\t\t}\n\t\tif (Is.empty(proof)) {\n\t\t\tthrow new GeneralError(ProofHelper.CLASS_NAME, \"unsupportedProofType\", { proofType });\n\t\t}\n\t\treturn proof;\n\t}\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { ObjectHelper } from "@twin.org/core";
|
|
3
|
+
import { ArrayHelper, Is, ObjectHelper } from "@twin.org/core";
|
|
4
|
+
import { DidContexts } from "../models/didContexts.js";
|
|
4
5
|
/**
|
|
5
6
|
* Helper methods for creating and verifying proofs.
|
|
6
7
|
*/
|
|
@@ -10,22 +11,78 @@ export class VerifiableCredentialHelper {
|
|
|
10
11
|
*/
|
|
11
12
|
static CLASS_NAME = "VerifiableCredentialHelper";
|
|
12
13
|
/**
|
|
13
|
-
* Get the
|
|
14
|
-
* @param verifiableCredential The verifiable credential to
|
|
15
|
-
* @returns The
|
|
14
|
+
* Get the JSON-LD context URL for the verifiable credential.
|
|
15
|
+
* @param verifiableCredential The verifiable credential to inspect.
|
|
16
|
+
* @returns The context URL, or undefined if the version cannot be determined.
|
|
17
|
+
*/
|
|
18
|
+
static getContext(verifiableCredential) {
|
|
19
|
+
const contextVersion = VerifiableCredentialHelper.getContextVersion(verifiableCredential);
|
|
20
|
+
if (contextVersion === "v1") {
|
|
21
|
+
return DidContexts.ContextVCv1;
|
|
22
|
+
}
|
|
23
|
+
if (contextVersion === "v2") {
|
|
24
|
+
return DidContexts.ContextVCv2;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get the context version string for the verifiable credential.
|
|
29
|
+
* @param verifiableCredential The verifiable credential to inspect.
|
|
30
|
+
* @returns The context version ("v1" or "v2"), or undefined if not determinable.
|
|
31
|
+
*/
|
|
32
|
+
static getContextVersion(verifiableCredential) {
|
|
33
|
+
const context = ArrayHelper.fromObjectOrArray(verifiableCredential["@context"]);
|
|
34
|
+
if (Is.arrayValue(context)) {
|
|
35
|
+
if (context.includes(DidContexts.ContextVCv1)) {
|
|
36
|
+
return "v1";
|
|
37
|
+
}
|
|
38
|
+
if (context.includes(DidContexts.ContextVCv2)) {
|
|
39
|
+
return "v2";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get the expiration date from a verifiable credential.
|
|
45
|
+
* @param verifiableCredential The verifiable credential to inspect.
|
|
46
|
+
* @returns The expiration date string, or undefined if not present.
|
|
16
47
|
*/
|
|
17
48
|
static getValidUntil(verifiableCredential) {
|
|
18
49
|
return (ObjectHelper.propertyGet(verifiableCredential, "validUntil") ??
|
|
19
50
|
ObjectHelper.propertyGet(verifiableCredential, "expirationDate"));
|
|
20
51
|
}
|
|
21
52
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @param verifiableCredential The verifiable credential to
|
|
24
|
-
* @
|
|
53
|
+
* Set the expiration date on a verifiable credential.
|
|
54
|
+
* @param verifiableCredential The verifiable credential to update.
|
|
55
|
+
* @param validUntil The expiration date to set.
|
|
56
|
+
*/
|
|
57
|
+
static setValidUntil(verifiableCredential, validUntil) {
|
|
58
|
+
if (VerifiableCredentialHelper.getContextVersion(verifiableCredential) === "v2") {
|
|
59
|
+
ObjectHelper.propertySet(verifiableCredential, "validUntil", validUntil);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
ObjectHelper.propertySet(verifiableCredential, "expirationDate", validUntil);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get the issuance date from a verifiable credential.
|
|
67
|
+
* @param verifiableCredential The verifiable credential to inspect.
|
|
68
|
+
* @returns The issuance date string, or undefined if not present.
|
|
25
69
|
*/
|
|
26
70
|
static getValidFrom(verifiableCredential) {
|
|
27
71
|
return (ObjectHelper.propertyGet(verifiableCredential, "validFrom") ??
|
|
28
72
|
ObjectHelper.propertyGet(verifiableCredential, "issuanceDate"));
|
|
29
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Set the issuance date on a verifiable credential.
|
|
76
|
+
* @param verifiableCredential The verifiable credential to update.
|
|
77
|
+
* @param validFrom The issuance date to set.
|
|
78
|
+
*/
|
|
79
|
+
static setValidFrom(verifiableCredential, validFrom) {
|
|
80
|
+
if (VerifiableCredentialHelper.getContextVersion(verifiableCredential) === "v2") {
|
|
81
|
+
ObjectHelper.propertySet(verifiableCredential, "validFrom", validFrom);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
ObjectHelper.propertySet(verifiableCredential, "issuanceDate", validFrom);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
30
87
|
}
|
|
31
88
|
//# sourceMappingURL=verifiableCredentialHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifiableCredentialHelper.js","sourceRoot":"","sources":["../../../src/utils/verifiableCredentialHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"verifiableCredentialHelper.js","sourceRoot":"","sources":["../../../src/utils/verifiableCredentialHelper.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD;;GAEG;AACH,MAAM,OAAO,0BAA0B;IACtC;;OAEG;IACI,MAAM,CAAU,UAAU,gCAAgD;IAEjF;;;;OAIG;IACI,MAAM,CAAC,UAAU,CACvB,oBAA8C;QAE9C,MAAM,cAAc,GAAG,0BAA0B,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,CAAC;QAC1F,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,WAAW,CAAC,WAAW,CAAC;QAChC,CAAC;QACD,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,WAAW,CAAC,WAAW,CAAC;QAChC,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,iBAAiB,CAC9B,oBAA8C;QAE9C,MAAM,OAAO,GAAG,WAAW,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,UAAU,CAAC,CAAC,CAAC;QAChF,IAAI,EAAE,CAAC,UAAU,CAAS,OAAO,CAAC,EAAE,CAAC;YACpC,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC/C,OAAO,IAAI,CAAC;YACb,CAAC;YACD,IAAI,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;gBAC/C,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,oBAA8C;QACzE,OAAO,CACN,YAAY,CAAC,WAAW,CAAC,oBAAoB,EAAE,YAAY,CAAC;YAC5D,YAAY,CAAC,WAAW,CAAC,oBAAoB,EAAE,gBAAgB,CAAC,CAChE,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAC1B,oBAA8C,EAC9C,UAAkB;QAElB,IAAI,0BAA0B,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,KAAK,IAAI,EAAE,CAAC;YACjF,YAAY,CAAC,WAAW,CAAC,oBAAoB,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QAC1E,CAAC;aAAM,CAAC;YACP,YAAY,CAAC,WAAW,CAAC,oBAAoB,EAAE,gBAAgB,EAAE,UAAU,CAAC,CAAC;QAC9E,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,oBAA8C;QACxE,OAAO,CACN,YAAY,CAAC,WAAW,CAAC,oBAAoB,EAAE,WAAW,CAAC;YAC3D,YAAY,CAAC,WAAW,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAC9D,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CACzB,oBAA8C,EAC9C,SAAiB;QAEjB,IAAI,0BAA0B,CAAC,iBAAiB,CAAC,oBAAoB,CAAC,KAAK,IAAI,EAAE,CAAC;YACjF,YAAY,CAAC,WAAW,CAAC,oBAAoB,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QACxE,CAAC;aAAM,CAAC;YACP,YAAY,CAAC,WAAW,CAAC,oBAAoB,EAAE,cAAc,EAAE,SAAS,CAAC,CAAC;QAC3E,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { ArrayHelper, Is, ObjectHelper } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { DidContexts } from \"../models/didContexts.js\";\nimport type { IDidVerifiableCredential } from \"../models/IDidVerifiableCredential.js\";\n\n/**\n * Helper methods for creating and verifying proofs.\n */\nexport class VerifiableCredentialHelper {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<VerifiableCredentialHelper>();\n\n\t/**\n\t * Get the JSON-LD context URL for the verifiable credential.\n\t * @param verifiableCredential The verifiable credential to inspect.\n\t * @returns The context URL, or undefined if the version cannot be determined.\n\t */\n\tpublic static getContext(\n\t\tverifiableCredential: IDidVerifiableCredential\n\t): typeof DidContexts.ContextVCv1 | typeof DidContexts.ContextVCv2 | undefined {\n\t\tconst contextVersion = VerifiableCredentialHelper.getContextVersion(verifiableCredential);\n\t\tif (contextVersion === \"v1\") {\n\t\t\treturn DidContexts.ContextVCv1;\n\t\t}\n\t\tif (contextVersion === \"v2\") {\n\t\t\treturn DidContexts.ContextVCv2;\n\t\t}\n\t}\n\n\t/**\n\t * Get the context version string for the verifiable credential.\n\t * @param verifiableCredential The verifiable credential to inspect.\n\t * @returns The context version (\"v1\" or \"v2\"), or undefined if not determinable.\n\t */\n\tpublic static getContextVersion(\n\t\tverifiableCredential: IDidVerifiableCredential\n\t): \"v1\" | \"v2\" | undefined {\n\t\tconst context = ArrayHelper.fromObjectOrArray(verifiableCredential[\"@context\"]);\n\t\tif (Is.arrayValue<string>(context)) {\n\t\t\tif (context.includes(DidContexts.ContextVCv1)) {\n\t\t\t\treturn \"v1\";\n\t\t\t}\n\t\t\tif (context.includes(DidContexts.ContextVCv2)) {\n\t\t\t\treturn \"v2\";\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Get the expiration date from a verifiable credential.\n\t * @param verifiableCredential The verifiable credential to inspect.\n\t * @returns The expiration date string, or undefined if not present.\n\t */\n\tpublic static getValidUntil(verifiableCredential: IDidVerifiableCredential): string | undefined {\n\t\treturn (\n\t\t\tObjectHelper.propertyGet(verifiableCredential, \"validUntil\") ??\n\t\t\tObjectHelper.propertyGet(verifiableCredential, \"expirationDate\")\n\t\t);\n\t}\n\n\t/**\n\t * Set the expiration date on a verifiable credential.\n\t * @param verifiableCredential The verifiable credential to update.\n\t * @param validUntil The expiration date to set.\n\t */\n\tpublic static setValidUntil(\n\t\tverifiableCredential: IDidVerifiableCredential,\n\t\tvalidUntil: string\n\t): void {\n\t\tif (VerifiableCredentialHelper.getContextVersion(verifiableCredential) === \"v2\") {\n\t\t\tObjectHelper.propertySet(verifiableCredential, \"validUntil\", validUntil);\n\t\t} else {\n\t\t\tObjectHelper.propertySet(verifiableCredential, \"expirationDate\", validUntil);\n\t\t}\n\t}\n\n\t/**\n\t * Get the issuance date from a verifiable credential.\n\t * @param verifiableCredential The verifiable credential to inspect.\n\t * @returns The issuance date string, or undefined if not present.\n\t */\n\tpublic static getValidFrom(verifiableCredential: IDidVerifiableCredential): string | undefined {\n\t\treturn (\n\t\t\tObjectHelper.propertyGet(verifiableCredential, \"validFrom\") ??\n\t\t\tObjectHelper.propertyGet(verifiableCredential, \"issuanceDate\")\n\t\t);\n\t}\n\n\t/**\n\t * Set the issuance date on a verifiable credential.\n\t * @param verifiableCredential The verifiable credential to update.\n\t * @param validFrom The issuance date to set.\n\t */\n\tpublic static setValidFrom(\n\t\tverifiableCredential: IDidVerifiableCredential,\n\t\tvalidFrom: string\n\t): void {\n\t\tif (VerifiableCredentialHelper.getContextVersion(verifiableCredential) === \"v2\") {\n\t\t\tObjectHelper.propertySet(verifiableCredential, \"validFrom\", validFrom);\n\t\t} else {\n\t\t\tObjectHelper.propertySet(verifiableCredential, \"issuanceDate\", validFrom);\n\t\t}\n\t}\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from "./dataTypes/didDataTypes.js";
|
|
1
2
|
export * from "./models/didContexts.js";
|
|
2
3
|
export * from "./models/didCryptoSuites.js";
|
|
3
4
|
export * from "./models/didTypes.js";
|
|
@@ -19,12 +20,16 @@ export * from "./models/IDidVerifiablePresentationCommon.js";
|
|
|
19
20
|
export * from "./models/IDidVerifiablePresentationV1.js";
|
|
20
21
|
export * from "./models/IDidVerifiablePresentationV2.js";
|
|
21
22
|
export * from "./models/IJsonWebSignature2020Proof.js";
|
|
23
|
+
export * from "./models/jwsAlgorithms.js";
|
|
22
24
|
export * from "./models/IMultikey.js";
|
|
23
25
|
export * from "./models/IProof.js";
|
|
24
26
|
export * from "./models/IProofSignerVerifier.js";
|
|
27
|
+
export * from "./models/IProofSignerVerifierAsync.js";
|
|
25
28
|
export * from "./models/proofTypes.js";
|
|
26
29
|
export * from "./signerVerifiers/dataIntegrityProofSignerVerifier.js";
|
|
30
|
+
export * from "./signerVerifiers/dataIntegrityProofAsyncSignerVerifier.js";
|
|
27
31
|
export * from "./signerVerifiers/jsonWebSignature2020SignerVerifier.js";
|
|
32
|
+
export * from "./signerVerifiers/jsonWebSignature2020AsyncSignerVerifier.js";
|
|
28
33
|
export * from "./utils/multikeyHelper.js";
|
|
29
34
|
export * from "./utils/proofHelper.js";
|
|
30
35
|
export * from "./utils/verifiableCredentialHelper.js";
|