@twin.org/standards-w3c-did 0.0.2-next.8 → 0.0.3-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/index.js +33 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/models/IDataIntegrityProof.js +2 -0
- package/dist/es/models/IDataIntegrityProof.js.map +1 -0
- package/dist/es/models/IDidCredentialSchema.js +4 -0
- package/dist/es/models/IDidCredentialSchema.js.map +1 -0
- package/dist/es/models/IDidCredentialStatus.js +4 -0
- package/dist/es/models/IDidCredentialStatus.js.map +1 -0
- package/dist/es/models/IDidDocument.js +2 -0
- package/dist/es/models/IDidDocument.js.map +1 -0
- package/dist/es/models/IDidDocumentVerificationMethod.js +2 -0
- package/dist/es/models/IDidDocumentVerificationMethod.js.map +1 -0
- package/dist/es/models/IDidLabel.js +4 -0
- package/dist/es/models/IDidLabel.js.map +1 -0
- package/dist/es/models/IDidPresentationVerification.js +2 -0
- package/dist/es/models/IDidPresentationVerification.js.map +1 -0
- package/dist/es/models/IDidService.js +4 -0
- package/dist/es/models/IDidService.js.map +1 -0
- package/dist/es/models/IDidVerifiableCredential.js +2 -0
- package/dist/es/models/IDidVerifiableCredential.js.map +1 -0
- package/dist/es/models/IDidVerifiableCredentialCommon.js +2 -0
- package/dist/es/models/IDidVerifiableCredentialCommon.js.map +1 -0
- package/dist/es/models/IDidVerifiableCredentialV1.js +2 -0
- package/dist/es/models/IDidVerifiableCredentialV1.js.map +1 -0
- package/dist/es/models/IDidVerifiableCredentialV2.js +2 -0
- package/dist/es/models/IDidVerifiableCredentialV2.js.map +1 -0
- package/dist/es/models/IDidVerifiablePresentation.js +2 -0
- package/dist/es/models/IDidVerifiablePresentation.js.map +1 -0
- package/dist/es/models/IDidVerifiablePresentationCommon.js +2 -0
- package/dist/es/models/IDidVerifiablePresentationCommon.js.map +1 -0
- package/dist/es/models/IDidVerifiablePresentationV1.js +2 -0
- package/dist/es/models/IDidVerifiablePresentationV1.js.map +1 -0
- package/dist/es/models/IDidVerifiablePresentationV2.js +2 -0
- package/dist/es/models/IDidVerifiablePresentationV2.js.map +1 -0
- package/dist/es/models/IJsonWebSignature2020Proof.js +2 -0
- package/dist/es/models/IJsonWebSignature2020Proof.js.map +1 -0
- package/dist/es/models/IMultikey.js +2 -0
- package/dist/es/models/IMultikey.js.map +1 -0
- package/dist/es/models/IProof.js +2 -0
- package/dist/es/models/IProof.js.map +1 -0
- package/dist/es/models/IProofSignerVerifier.js +2 -0
- package/dist/es/models/IProofSignerVerifier.js.map +1 -0
- package/dist/es/models/didContexts.js +41 -0
- package/dist/es/models/didContexts.js.map +1 -0
- package/dist/es/models/didCryptoSuites.js +19 -0
- package/dist/es/models/didCryptoSuites.js.map +1 -0
- package/dist/es/models/didTypes.js +33 -0
- package/dist/es/models/didTypes.js.map +1 -0
- package/dist/es/models/didVerificationMethodType.js +31 -0
- package/dist/es/models/didVerificationMethodType.js.map +1 -0
- package/dist/es/models/proofTypes.js +17 -0
- package/dist/es/models/proofTypes.js.map +1 -0
- package/dist/es/signerVerifiers/dataIntegrityProofSignerVerifier.js +90 -0
- package/dist/es/signerVerifiers/dataIntegrityProofSignerVerifier.js.map +1 -0
- package/dist/es/signerVerifiers/jsonWebSignature2020SignerVerifier.js +79 -0
- package/dist/es/signerVerifiers/jsonWebSignature2020SignerVerifier.js.map +1 -0
- package/dist/es/utils/multikeyHelper.js +114 -0
- package/dist/es/utils/multikeyHelper.js.map +1 -0
- package/dist/es/utils/proofHelper.js +106 -0
- package/dist/es/utils/proofHelper.js.map +1 -0
- package/dist/es/utils/verifiableCredentialHelper.js +31 -0
- package/dist/es/utils/verifiableCredentialHelper.js.map +1 -0
- package/dist/types/index.d.ts +30 -30
- package/dist/types/models/IDataIntegrityProof.d.ts +3 -3
- package/dist/types/models/IDidDocument.d.ts +3 -3
- package/dist/types/models/IDidPresentationVerification.d.ts +1 -1
- package/dist/types/models/IDidVerifiableCredential.d.ts +2 -2
- package/dist/types/models/IDidVerifiableCredentialCommon.d.ts +4 -4
- package/dist/types/models/IDidVerifiableCredentialV1.d.ts +2 -2
- package/dist/types/models/IDidVerifiableCredentialV2.d.ts +2 -2
- package/dist/types/models/IDidVerifiablePresentation.d.ts +2 -2
- package/dist/types/models/IDidVerifiablePresentationCommon.d.ts +1 -1
- package/dist/types/models/IDidVerifiablePresentationV1.d.ts +3 -3
- package/dist/types/models/IDidVerifiablePresentationV2.d.ts +3 -3
- package/dist/types/models/IJsonWebSignature2020Proof.d.ts +2 -2
- package/dist/types/models/IMultikey.d.ts +2 -2
- package/dist/types/models/IProof.d.ts +2 -2
- package/dist/types/models/IProofSignerVerifier.d.ts +1 -1
- package/dist/types/models/didVerificationMethodType.d.ts +1 -1
- package/dist/types/signerVerifiers/dataIntegrityProofSignerVerifier.d.ts +4 -4
- package/dist/types/signerVerifiers/jsonWebSignature2020SignerVerifier.d.ts +3 -3
- package/dist/types/utils/multikeyHelper.d.ts +1 -1
- package/dist/types/utils/proofHelper.d.ts +3 -3
- package/dist/types/utils/verifiableCredentialHelper.d.ts +1 -1
- package/docs/changelog.md +76 -0
- package/docs/reference/classes/DataIntegrityProofSignerVerifier.md +3 -3
- package/docs/reference/classes/JsonWebSignature2020SignerVerifier.md +3 -3
- package/docs/reference/classes/MultikeyHelper.md +3 -3
- package/docs/reference/classes/ProofHelper.md +2 -2
- package/docs/reference/classes/VerifiableCredentialHelper.md +4 -4
- package/docs/reference/interfaces/IDidDocumentVerificationMethod.md +2 -2
- package/docs/reference/interfaces/IProofSignerVerifier.md +2 -2
- package/locales/en.json +4 -8
- package/package.json +20 -8
- package/dist/cjs/index.cjs +0 -557
- package/dist/esm/index.mjs +0 -546
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
export * from "./models/didContexts.js";
|
|
4
|
+
export * from "./models/didCryptoSuites.js";
|
|
5
|
+
export * from "./models/didTypes.js";
|
|
6
|
+
export * from "./models/didVerificationMethodType.js";
|
|
7
|
+
export * from "./models/IDataIntegrityProof.js";
|
|
8
|
+
export * from "./models/IDidCredentialSchema.js";
|
|
9
|
+
export * from "./models/IDidCredentialStatus.js";
|
|
10
|
+
export * from "./models/IDidDocument.js";
|
|
11
|
+
export * from "./models/IDidDocumentVerificationMethod.js";
|
|
12
|
+
export * from "./models/IDidLabel.js";
|
|
13
|
+
export * from "./models/IDidPresentationVerification.js";
|
|
14
|
+
export * from "./models/IDidService.js";
|
|
15
|
+
export * from "./models/IDidVerifiableCredential.js";
|
|
16
|
+
export * from "./models/IDidVerifiableCredentialCommon.js";
|
|
17
|
+
export * from "./models/IDidVerifiableCredentialV1.js";
|
|
18
|
+
export * from "./models/IDidVerifiableCredentialV2.js";
|
|
19
|
+
export * from "./models/IDidVerifiablePresentation.js";
|
|
20
|
+
export * from "./models/IDidVerifiablePresentationCommon.js";
|
|
21
|
+
export * from "./models/IDidVerifiablePresentationV1.js";
|
|
22
|
+
export * from "./models/IDidVerifiablePresentationV2.js";
|
|
23
|
+
export * from "./models/IJsonWebSignature2020Proof.js";
|
|
24
|
+
export * from "./models/IMultikey.js";
|
|
25
|
+
export * from "./models/IProof.js";
|
|
26
|
+
export * from "./models/IProofSignerVerifier.js";
|
|
27
|
+
export * from "./models/proofTypes.js";
|
|
28
|
+
export * from "./signerVerifiers/dataIntegrityProofSignerVerifier.js";
|
|
29
|
+
export * from "./signerVerifiers/jsonWebSignature2020SignerVerifier.js";
|
|
30
|
+
export * from "./utils/multikeyHelper.js";
|
|
31
|
+
export * from "./utils/proofHelper.js";
|
|
32
|
+
export * from "./utils/verifiableCredentialHelper.js";
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,uCAAuC,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,cAAc,kCAAkC,CAAC;AACjD,cAAc,kCAAkC,CAAC;AACjD,cAAc,0BAA0B,CAAC;AACzC,cAAc,4CAA4C,CAAC;AAC3D,cAAc,uBAAuB,CAAC;AACtC,cAAc,0CAA0C,CAAC;AACzD,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC;AACrD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,wCAAwC,CAAC;AACvD,cAAc,8CAA8C,CAAC;AAC7D,cAAc,0CAA0C,CAAC;AACzD,cAAc,0CAA0C,CAAC;AACzD,cAAc,wCAAwC,CAAC;AACvD,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,kCAAkC,CAAC;AACjD,cAAc,wBAAwB,CAAC;AACvC,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,2BAA2B,CAAC;AAC1C,cAAc,wBAAwB,CAAC;AACvC,cAAc,uCAAuC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./models/didContexts.js\";\nexport * from \"./models/didCryptoSuites.js\";\nexport * from \"./models/didTypes.js\";\nexport * from \"./models/didVerificationMethodType.js\";\nexport * from \"./models/IDataIntegrityProof.js\";\nexport * from \"./models/IDidCredentialSchema.js\";\nexport * from \"./models/IDidCredentialStatus.js\";\nexport * from \"./models/IDidDocument.js\";\nexport * from \"./models/IDidDocumentVerificationMethod.js\";\nexport * from \"./models/IDidLabel.js\";\nexport * from \"./models/IDidPresentationVerification.js\";\nexport * from \"./models/IDidService.js\";\nexport * from \"./models/IDidVerifiableCredential.js\";\nexport * from \"./models/IDidVerifiableCredentialCommon.js\";\nexport * from \"./models/IDidVerifiableCredentialV1.js\";\nexport * from \"./models/IDidVerifiableCredentialV2.js\";\nexport * from \"./models/IDidVerifiablePresentation.js\";\nexport * from \"./models/IDidVerifiablePresentationCommon.js\";\nexport * from \"./models/IDidVerifiablePresentationV1.js\";\nexport * from \"./models/IDidVerifiablePresentationV2.js\";\nexport * from \"./models/IJsonWebSignature2020Proof.js\";\nexport * from \"./models/IMultikey.js\";\nexport * from \"./models/IProof.js\";\nexport * from \"./models/IProofSignerVerifier.js\";\nexport * from \"./models/proofTypes.js\";\nexport * from \"./signerVerifiers/dataIntegrityProofSignerVerifier.js\";\nexport * from \"./signerVerifiers/jsonWebSignature2020SignerVerifier.js\";\nexport * from \"./utils/multikeyHelper.js\";\nexport * from \"./utils/proofHelper.js\";\nexport * from \"./utils/verifiableCredentialHelper.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDataIntegrityProof.js","sourceRoot":"","sources":["../../../src/models/IDataIntegrityProof.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type { DidContexts } from \"./didContexts.js\";\nimport type { DidCryptoSuites } from \"./didCryptoSuites.js\";\nimport type { ProofTypes } from \"./proofTypes.js\";\n\n/**\n * Interface describing a did proof.\n * https://www.w3.org/TR/vc-data-integrity/\n */\nexport interface IDataIntegrityProof {\n\t/**\n\t * JSON-LD Context.\n\t */\n\t\"@context\"?:\n\t\t| typeof DidContexts.ContextDataIntegrity\n\t\t| [typeof DidContexts.ContextDataIntegrity, ...IJsonLdContextDefinitionElement[]];\n\n\t/**\n\t * JSON-LD Type.\n\t */\n\ttype: typeof ProofTypes.DataIntegrityProof;\n\n\t/**\n\t * An identifier for the cryptographic suite that can be used to verify the proof.\n\t */\n\tcryptosuite: DidCryptoSuites | string;\n\n\t/**\n\t * The id of the proof.\n\t */\n\tid?: string;\n\n\t/**\n\t * The reason the proof was created.\n\t */\n\tproofPurpose: string;\n\n\t/**\n\t * Contains the base-encoded binary data necessary to verify the\n\t * digital proof using the verificationMethod specified.\n\t */\n\tproofValue?: string;\n\n\t/**\n\t * The verification method of the proof.\n\t */\n\tverificationMethod?: string;\n\n\t/**\n\t * The iso date of when the proof was created.\n\t */\n\tcreated?: string;\n\n\t/**\n\t * The iso date of when the proof expires.\n\t */\n\texpires?: string;\n\n\t/**\n\t * One or more security domains in which the proof is meant to be used.\n\t */\n\tdomain?: string | string[];\n\n\t/**\n\t * Provided to mitigate replay attacks on domains.\n\t */\n\tchallenge?: string | string[];\n\n\t/**\n\t * Identifies another data integrity proof that MUST verify before\n\t * the current proof is processed\n\t */\n\tpreviousProof?: string;\n\n\t/**\n\t * Use of this field is to increase privacy by decreasing linkability\n\t * that is the result of deterministically generated signatures.\n\t */\n\tnonce?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidCredentialSchema.js","sourceRoot":"","sources":["../../../src/models/IDidCredentialSchema.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface describing a DID credential schema.\n */\nexport interface IDidCredentialSchema {\n\t/**\n\t * The URI id.\n\t */\n\tid: string;\n\n\t/**\n\t * The credential schema type.\n\t */\n\ttype: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidCredentialStatus.js","sourceRoot":"","sources":["../../../src/models/IDidCredentialStatus.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface describing a DID credential status.\n */\nexport interface IDidCredentialStatus {\n\t/**\n\t * Additional properties.\n\t */\n\t[key: string]: unknown;\n\n\t/**\n\t * The URI id.\n\t */\n\tid: string;\n\n\t/**\n\t * The credential status type.\n\t */\n\ttype: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidDocument.js","sourceRoot":"","sources":["../../../src/models/IDidDocument.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type { DidContexts } from \"./didContexts.js\";\nimport type { IDidDocumentVerificationMethod } from \"./IDidDocumentVerificationMethod.js\";\nimport type { IDidService } from \"./IDidService.js\";\n\n/**\n * Interface describing a DID Document.\n * Spec https://www.w3.org/TR/did-core/#did-document-properties.\n */\nexport interface IDidDocument {\n\t/**\n\t * The context for the document.\n\t */\n\t\"@context\":\n\t\t| typeof DidContexts.Context\n\t\t| [typeof DidContexts.Context, ...IJsonLdContextDefinitionElement[]];\n\n\t/**\n\t * The id for the document.\n\t */\n\tid: string;\n\n\t/**\n\t * Aliases for the document.\n\t */\n\talsoKnownAs?: string | string[];\n\n\t/**\n\t * The controller for the document.\n\t */\n\tcontroller?: string | string[];\n\n\t/**\n\t * The verification methods.\n\t */\n\tverificationMethod?: (string | IDidDocumentVerificationMethod)[];\n\n\t/**\n\t * The authentication methods.\n\t */\n\tauthentication?: (string | IDidDocumentVerificationMethod)[];\n\n\t/**\n\t * The assertion methods.\n\t */\n\tassertionMethod?: (string | IDidDocumentVerificationMethod)[];\n\n\t/**\n\t * The key agreements.\n\t */\n\tkeyAgreement?: (string | IDidDocumentVerificationMethod)[];\n\n\t/**\n\t * The capability invocations.\n\t */\n\tcapabilityInvocation?: (string | IDidDocumentVerificationMethod)[];\n\n\t/**\n\t * The capability delegations.\n\t */\n\tcapabilityDelegation?: (string | IDidDocumentVerificationMethod)[];\n\n\t/**\n\t * The services.\n\t */\n\tservice?: IDidService[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidDocumentVerificationMethod.js","sourceRoot":"","sources":["../../../src/models/IDidDocumentVerificationMethod.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IJwk } from \"@twin.org/web\";\n\n/**\n * Interface describing a DID document verification method.\n */\nexport interface IDidDocumentVerificationMethod extends IJsonLdNodeObject {\n\t/**\n\t * The id of the entry.\n\t */\n\tid: string;\n\n\t/**\n\t * The controller for the entry.\n\t */\n\tcontroller: string;\n\n\t/**\n\t * The type of the entry.\n\t */\n\ttype: string;\n\n\t/**\n\t * The public key for the entry.\n\t * Spec https://datatracker.ietf.org/doc/html/draft-multiformats-multibase-03 .\n\t */\n\tpublicKeyMultibase?: string;\n\n\t/**\n\t * The public key for the entry as a JWK.\n\t * Spec https://datatracker.ietf.org/doc/html/rfc7517 .\n\t */\n\tpublicKeyJwk?: IJwk & IJsonLdNodeObject;\n\n\t/**\n\t * Multi key partial revocation.\n\t */\n\trevocation?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidLabel.js","sourceRoot":"","sources":["../../../src/models/IDidLabel.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface describing a DID Label.\n */\nexport interface IDidLabel {\n\t/**\n\t * The value for the label.\n\t */\n\t\"@value\": string;\n\n\t/**\n\t * The language for the label.\n\t */\n\t\"@language\": string;\n\n\t/**\n\t * The direction of the label.\n\t */\n\t\"@direction\"?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidPresentationVerification.js","sourceRoot":"","sources":["../../../src/models/IDidPresentationVerification.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDidDocument } from \"./IDidDocument.js\";\n\n/**\n * Interface describing the result of checking verifiable presentation.\n */\nexport interface IDidPresentationVerification {\n\t/**\n\t * Is the whole presentation verified.\n\t */\n\tisVerified: boolean;\n\n\t/**\n\t * Who was the holder.\n\t */\n\tholder?: {\n\t\t/**\n\t\t * The id of the holder.\n\t\t */\n\t\tid: string;\n\n\t\t/**\n\t\t * Is the holder verified.\n\t\t */\n\t\tisVerified: boolean;\n\n\t\t/**\n\t\t * The DID document for the holder.\n\t\t */\n\t\tdocument?: IDidDocument;\n\t};\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidService.js","sourceRoot":"","sources":["../../../src/models/IDidService.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Interface describing a did document service.\n */\nexport interface IDidService {\n\t/**\n\t * The id of the service.\n\t */\n\tid: string;\n\n\t/**\n\t * The type of the service.\n\t */\n\ttype: string | string[];\n\n\t/**\n\t * The endpoint for the service.\n\t */\n\tserviceEndpoint: string | string[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidVerifiableCredential.js","sourceRoot":"","sources":["../../../src/models/IDidVerifiableCredential.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDidVerifiableCredentialV1 } from \"./IDidVerifiableCredentialV1.js\";\nimport type { IDidVerifiableCredentialV2 } from \"./IDidVerifiableCredentialV2.js\";\n\n/**\n * Interface describing a verifiable credential.\n */\nexport type IDidVerifiableCredential = IDidVerifiableCredentialV1 | IDidVerifiableCredentialV2;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidVerifiableCredentialCommon.js","sourceRoot":"","sources":["../../../src/models/IDidVerifiableCredentialCommon.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IDidCredentialSchema } from \"./IDidCredentialSchema.js\";\nimport type { IDidCredentialStatus } from \"./IDidCredentialStatus.js\";\nimport type { IDidLabel } from \"./IDidLabel.js\";\nimport type { IProof } from \"./IProof.js\";\n\n/**\n * Interface describing a verifiable credential.\n * https://www.w3.org/TR/vc-data-model-2.0\n */\nexport interface IDidVerifiableCredentialCommon {\n\t/**\n\t * The identifier for the verifiable credential.\n\t */\n\tid?: string;\n\n\t/**\n\t * The types of the data stored in the verifiable credential.\n\t */\n\ttype: string | string[];\n\n\t/**\n\t * The data for the verifiable credential.\n\t */\n\tcredentialSubject?: IJsonLdNodeObject | IJsonLdNodeObject[];\n\n\t/**\n\t * Used to discover information about the current status of the\n\t * verifiable credential, such as whether it is suspended or revoked.\n\t */\n\tcredentialStatus?: IDidCredentialStatus | IDidCredentialStatus[];\n\n\t/**\n\t * Annotate type definitions or lock them to specific versions of the vocabulary.\n\t */\n\tcredentialSchema?: IDidCredentialSchema | IDidCredentialSchema[];\n\n\t/**\n\t * The issuing identity.\n\t */\n\tissuer?: string | { id: string; name?: string | IDidLabel[]; description?: string | IDidLabel[] };\n\n\t/**\n\t * The name of the credential.\n\t */\n\tname?: string | IDidLabel[];\n\n\t/**\n\t * The description of the credential.\n\t */\n\tdescription?: string | IDidLabel[];\n\n\t/**\n\t * Evidence associated with the Credential.\n\t */\n\tevidence?: IJsonLdNodeObject | IJsonLdNodeObject[];\n\n\t/**\n\t * Proofs that the verifiable credential is valid.\n\t * Optional if a different proof method is used, such as JWT.\n\t */\n\tproof?: IProof | IProof[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidVerifiableCredentialV1.js","sourceRoot":"","sources":["../../../src/models/IDidVerifiableCredentialV1.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type { DidContexts } from \"./didContexts.js\";\nimport type { IDidVerifiableCredentialCommon } from \"./IDidVerifiableCredentialCommon.js\";\n\n/**\n * Interface describing a verifiable credential.\n * https://www.w3.org/TR/vc-data-model-1.1\n */\nexport interface IDidVerifiableCredentialV1 extends IDidVerifiableCredentialCommon {\n\t/**\n\t * The context for the verifiable credential.\n\t */\n\t\"@context\":\n\t\t| typeof DidContexts.ContextVCv1\n\t\t| [typeof DidContexts.ContextVCv1, ...IJsonLdContextDefinitionElement[]];\n\n\t/**\n\t * The date the verifiable credential was issued, depending on version validFrom might be set instead.\n\t */\n\tissuanceDate?: string;\n\n\t/**\n\t * The date the verifiable credential expires, depending on version validUntil might be set instead.\n\t */\n\texpirationDate?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidVerifiableCredentialV2.js","sourceRoot":"","sources":["../../../src/models/IDidVerifiableCredentialV2.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type { DidContexts } from \"./didContexts.js\";\nimport type { IDidVerifiableCredentialCommon } from \"./IDidVerifiableCredentialCommon.js\";\n\n/**\n * Interface describing a verifiable credential.\n * https://www.w3.org/TR/vc-data-model-2.0\n */\nexport interface IDidVerifiableCredentialV2 extends IDidVerifiableCredentialCommon {\n\t/**\n\t * The context for the verifiable credential.\n\t */\n\t\"@context\":\n\t\t| typeof DidContexts.ContextVCv2\n\t\t| [typeof DidContexts.ContextVCv2, ...IJsonLdContextDefinitionElement[]];\n\n\t/**\n\t * The date the verifiable credential is valid from.\n\t */\n\tvalidFrom?: string;\n\n\t/**\n\t * The date the verifiable credential is valid until.\n\t */\n\tvalidUntil?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidVerifiablePresentation.js","sourceRoot":"","sources":["../../../src/models/IDidVerifiablePresentation.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDidVerifiablePresentationV1 } from \"./IDidVerifiablePresentationV1.js\";\nimport type { IDidVerifiablePresentationV2 } from \"./IDidVerifiablePresentationV2.js\";\n\n/**\n * Interface describing a verifiable presentation.\n */\nexport type IDidVerifiablePresentation =\n\t| IDidVerifiablePresentationV1\n\t| IDidVerifiablePresentationV2;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidVerifiablePresentationCommon.js","sourceRoot":"","sources":["../../../src/models/IDidVerifiablePresentationCommon.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IProof } from \"./IProof.js\";\n\n/**\n * Interface describing a verifiable presentation.\n */\nexport interface IDidVerifiablePresentationCommon {\n\t/**\n\t * Provide a unique identifier for the presentation.\n\t */\n\tid?: string;\n\n\t/**\n\t * The types of the data stored in the verifiable credential.\n\t */\n\ttype: string | string[];\n\n\t/**\n\t * The entity generating the presentation.\n\t */\n\tholder?: string;\n\n\t/**\n\t * Proofs that the verifiable presentation is valid.\n\t * Optional if a different proof method is used, such as JWT.\n\t */\n\tproof?: IProof | IProof[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidVerifiablePresentationV1.js","sourceRoot":"","sources":["../../../src/models/IDidVerifiablePresentationV1.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type { DidContexts } from \"./didContexts.js\";\nimport type { IDidVerifiableCredentialV1 } from \"./IDidVerifiableCredentialV1.js\";\nimport type { IDidVerifiablePresentationCommon } from \"./IDidVerifiablePresentationCommon.js\";\n\n/**\n * Interface describing a verifiable presentation.\n */\nexport interface IDidVerifiablePresentationV1 extends IDidVerifiablePresentationCommon {\n\t/**\n\t * The context for the verifiable presentation.\n\t */\n\t\"@context\":\n\t\t| typeof DidContexts.ContextVCv1\n\t\t| [typeof DidContexts.ContextVCv1, ...IJsonLdContextDefinitionElement[]];\n\n\t/**\n\t * The data for the verifiable credentials.\n\t */\n\tverifiableCredential?: (string | IDidVerifiableCredentialV1)[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IDidVerifiablePresentationV2.js","sourceRoot":"","sources":["../../../src/models/IDidVerifiablePresentationV2.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type { DidContexts } from \"./didContexts.js\";\nimport type { IDidVerifiableCredentialV2 } from \"./IDidVerifiableCredentialV2.js\";\nimport type { IDidVerifiablePresentationCommon } from \"./IDidVerifiablePresentationCommon.js\";\n\n/**\n * Interface describing a verifiable presentation.\n */\nexport interface IDidVerifiablePresentationV2 extends IDidVerifiablePresentationCommon {\n\t/**\n\t * The context for the verifiable presentation.\n\t */\n\t\"@context\":\n\t\t| typeof DidContexts.ContextVCv2\n\t\t| [typeof DidContexts.ContextVCv2, ...IJsonLdContextDefinitionElement[]];\n\n\t/**\n\t * The data for the verifiable credentials.\n\t */\n\tverifiableCredential?: (string | IDidVerifiableCredentialV2)[];\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IJsonWebSignature2020Proof.js","sourceRoot":"","sources":["../../../src/models/IJsonWebSignature2020Proof.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type { DidContexts } from \"./didContexts.js\";\nimport type { ProofTypes } from \"./proofTypes.js\";\n\n/**\n * Interface describing a did proof in JSON Web Signature 2020 Format.\n * https://www.w3.org/TR/vc-jws-2020/\n */\nexport interface IJsonWebSignature2020Proof {\n\t/**\n\t * JSON-LD Context.\n\t */\n\t\"@context\"?:\n\t\t| typeof DidContexts.ContextSecurityJws2020\n\t\t| [typeof DidContexts.ContextSecurityJws2020, ...IJsonLdContextDefinitionElement[]];\n\n\t/**\n\t * JSON-LD Type.\n\t */\n\ttype: typeof ProofTypes.JsonWebSignature2020;\n\n\t/**\n\t * The reason the proof was created.\n\t */\n\tproofPurpose: string;\n\n\t/**\n\t * The verification method of the proof.\n\t */\n\tverificationMethod?: string;\n\n\t/**\n\t * The iso date of when the proof was created.\n\t */\n\tcreated?: string;\n\n\t/**\n\t * The JSON Web Signature.\n\t */\n\tjws?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IMultikey.js","sourceRoot":"","sources":["../../../src/models/IMultikey.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdContextDefinitionElement } from \"@twin.org/data-json-ld\";\nimport type { DidContexts } from \"./didContexts.js\";\nimport type { DidTypes } from \"./didTypes.js\";\n\n/**\n * Interface describing a Multikey.\n * https://www.w3.org/TR/cid-1.0/\n */\nexport interface IMultikey {\n\t/**\n\t * JSON-LD Context.\n\t */\n\t\"@context\"?:\n\t\t| typeof DidContexts.ContextControllerIdentifiers\n\t\t| typeof DidContexts.ContextSecurityMultikey\n\t\t| [typeof DidContexts.ContextControllerIdentifiers, ...IJsonLdContextDefinitionElement[]]\n\t\t| [typeof DidContexts.ContextSecurityMultikey, ...IJsonLdContextDefinitionElement[]];\n\n\t/**\n\t * The id of the entry.\n\t */\n\tid?: string;\n\n\t/**\n\t * The type of the entry.\n\t */\n\ttype: typeof DidTypes.Multikey;\n\n\t/**\n\t * The controller for the entry.\n\t */\n\tcontroller?: string;\n\n\t/**\n\t * The public key for the entry.\n\t */\n\tpublicKeyMultibase: string;\n\n\t/**\n\t * The secret key for the entry.\n\t */\n\tsecretKeyMultibase?: string;\n\n\t/**\n\t * The date the entry expires.\n\t */\n\texpires?: string;\n\n\t/**\n\t * The date the entry was revoked.\n\t */\n\trevoked?: string;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IProof.js","sourceRoot":"","sources":["../../../src/models/IProof.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDataIntegrityProof } from \"./IDataIntegrityProof.js\";\nimport type { IJsonWebSignature2020Proof } from \"./IJsonWebSignature2020Proof.js\";\n\n/**\n * Interface describing a proof.\n */\nexport type IProof = IDataIntegrityProof | IJsonWebSignature2020Proof;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IProofSignerVerifier.js","sourceRoot":"","sources":["../../../src/models/IProofSignerVerifier.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IJsonLdNodeObject } from \"@twin.org/data-json-ld\";\nimport type { IJwk } from \"@twin.org/web\";\nimport type { IProof } from \"./IProof.js\";\n\n/**\n * Interface describing a proof signer and verifier.\n */\nexport interface IProofSignerVerifier {\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\tcreateProof(\n\t\tunsecuredDocument: IJsonLdNodeObject,\n\t\tunsignedProof: IProof,\n\t\tsignKey: IJwk\n\t): Promise<IProof>;\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\tverifyProof(\n\t\tsecuredDocument: IJsonLdNodeObject,\n\t\tsignedProof: IProof,\n\t\tverifyKey: IJwk\n\t): Promise<boolean>;\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\tcreateHash(unsecuredDocument: IJsonLdNodeObject, unsignedProof: IProof): Promise<Uint8Array>;\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The contexts for DIDs.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const DidContexts = {
|
|
8
|
+
/**
|
|
9
|
+
* The context root for DID.
|
|
10
|
+
*/
|
|
11
|
+
Context: "https://www.w3.org/ns/did/v1",
|
|
12
|
+
/**
|
|
13
|
+
* The context root for DID VC v1.
|
|
14
|
+
*/
|
|
15
|
+
ContextVCv1: "https://www.w3.org/2018/credentials/v1",
|
|
16
|
+
/**
|
|
17
|
+
* The context root for DID VC v2.
|
|
18
|
+
*/
|
|
19
|
+
ContextVCv2: "https://www.w3.org/ns/credentials/v2",
|
|
20
|
+
/**
|
|
21
|
+
* The context root for security ed25519 suites.
|
|
22
|
+
*/
|
|
23
|
+
ContextSecurityEd25519: "https://w3id.org/security/suites/ed25519-2020/v1",
|
|
24
|
+
/**
|
|
25
|
+
* The context root for security jws-2020 suites.
|
|
26
|
+
*/
|
|
27
|
+
ContextSecurityJws2020: "https://w3id.org/security/suites/jws-2020/v1",
|
|
28
|
+
/**
|
|
29
|
+
* The context root for VC Data Integrity.
|
|
30
|
+
*/
|
|
31
|
+
ContextDataIntegrity: "https://www.w3.org/ns/credentials/v2",
|
|
32
|
+
/**
|
|
33
|
+
* The context root for VC Data Integrity.
|
|
34
|
+
*/
|
|
35
|
+
ContextControllerIdentifiers: "https://www.w3.org/ns/cid/v1",
|
|
36
|
+
/**
|
|
37
|
+
* The context root for security multikey suites.
|
|
38
|
+
*/
|
|
39
|
+
ContextSecurityMultikey: "https://w3id.org/security/multikey/v1"
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=didContexts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"didContexts.js","sourceRoot":"","sources":["../../../src/models/didContexts.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B;;OAEG;IACH,OAAO,EAAE,8BAA8B;IAEvC;;OAEG;IACH,WAAW,EAAE,wCAAwC;IAErD;;OAEG;IACH,WAAW,EAAE,sCAAsC;IAEnD;;OAEG;IACH,sBAAsB,EAAE,kDAAkD;IAE1E;;OAEG;IACH,sBAAsB,EAAE,8CAA8C;IAEtE;;OAEG;IACH,oBAAoB,EAAE,sCAAsC;IAE5D;;OAEG;IACH,4BAA4B,EAAE,8BAA8B;IAE5D;;OAEG;IACH,uBAAuB,EAAE,uCAAuC;CACvD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The contexts for DIDs.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const DidContexts = {\n\t/**\n\t * The context root for DID.\n\t */\n\tContext: \"https://www.w3.org/ns/did/v1\",\n\n\t/**\n\t * The context root for DID VC v1.\n\t */\n\tContextVCv1: \"https://www.w3.org/2018/credentials/v1\",\n\n\t/**\n\t * The context root for DID VC v2.\n\t */\n\tContextVCv2: \"https://www.w3.org/ns/credentials/v2\",\n\n\t/**\n\t * The context root for security ed25519 suites.\n\t */\n\tContextSecurityEd25519: \"https://w3id.org/security/suites/ed25519-2020/v1\",\n\n\t/**\n\t * The context root for security jws-2020 suites.\n\t */\n\tContextSecurityJws2020: \"https://w3id.org/security/suites/jws-2020/v1\",\n\n\t/**\n\t * The context root for VC Data Integrity.\n\t */\n\tContextDataIntegrity: \"https://www.w3.org/ns/credentials/v2\",\n\n\t/**\n\t * The context root for VC Data Integrity.\n\t */\n\tContextControllerIdentifiers: \"https://www.w3.org/ns/cid/v1\",\n\n\t/**\n\t * The context root for security multikey suites.\n\t */\n\tContextSecurityMultikey: \"https://w3id.org/security/multikey/v1\"\n} as const;\n\n/**\n * The contexts for DIDs.\n */\nexport type DidContexts = (typeof DidContexts)[keyof typeof DidContexts];\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The types for DID Proof crypto suites.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const DidCryptoSuites = {
|
|
8
|
+
/**
|
|
9
|
+
* The type for EdDSA crypto suite for JSON Canonicalization Scheme [RFC8785].
|
|
10
|
+
* https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022
|
|
11
|
+
*/
|
|
12
|
+
EdDSAJcs2022: "eddsa-jcs-2022",
|
|
13
|
+
/**
|
|
14
|
+
* The type for EdDSA crypto suite for RDF Dataset Canonicalization.
|
|
15
|
+
* https://www.w3.org/TR/vc-di-eddsa/#eddsa-rdfc-2022
|
|
16
|
+
*/
|
|
17
|
+
EdDSARdfc2022: "eddsa-rdfc-2022"
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=didCryptoSuites.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"didCryptoSuites.js","sourceRoot":"","sources":["../../../src/models/didCryptoSuites.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B;;;OAGG;IACH,YAAY,EAAE,gBAAgB;IAE9B;;;OAGG;IACH,aAAa,EAAE,iBAAiB;CACvB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The types for DID Proof crypto suites.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const DidCryptoSuites = {\n\t/**\n\t * The type for EdDSA crypto suite for JSON Canonicalization Scheme [RFC8785].\n\t * https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022\n\t */\n\tEdDSAJcs2022: \"eddsa-jcs-2022\",\n\n\t/**\n\t * The type for EdDSA crypto suite for RDF Dataset Canonicalization.\n\t * https://www.w3.org/TR/vc-di-eddsa/#eddsa-rdfc-2022\n\t */\n\tEdDSARdfc2022: \"eddsa-rdfc-2022\"\n} as const;\n\n/**\n * The types for DID Proof crypto suites.\n */\nexport type DidCryptoSuites = (typeof DidCryptoSuites)[keyof typeof DidCryptoSuites];\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The types for DIDs.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const DidTypes = {
|
|
8
|
+
/**
|
|
9
|
+
* The type for Verifiable Credential.
|
|
10
|
+
*/
|
|
11
|
+
VerifiableCredential: "VerifiableCredential",
|
|
12
|
+
/**
|
|
13
|
+
* The type for Verifiable Presentation.
|
|
14
|
+
*/
|
|
15
|
+
VerifiablePresentation: "VerifiablePresentation",
|
|
16
|
+
/**
|
|
17
|
+
* The type for Ed25519VerificationKey2020.
|
|
18
|
+
*/
|
|
19
|
+
Ed25519VerificationKey2020: "Ed25519VerificationKey2020",
|
|
20
|
+
/**
|
|
21
|
+
* The type for JsonWebKey2020.
|
|
22
|
+
*/
|
|
23
|
+
JsonWebKey2020: "JsonWebKey2020",
|
|
24
|
+
/**
|
|
25
|
+
* The type for LinkedDomains.
|
|
26
|
+
*/
|
|
27
|
+
LinkedDomains: "LinkedDomains",
|
|
28
|
+
/**
|
|
29
|
+
* The type for Multikey.
|
|
30
|
+
*/
|
|
31
|
+
Multikey: "Multikey"
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=didTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"didTypes.js","sourceRoot":"","sources":["../../../src/models/didTypes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,QAAQ,GAAG;IACvB;;OAEG;IACH,oBAAoB,EAAE,sBAAsB;IAE5C;;OAEG;IACH,sBAAsB,EAAE,wBAAwB;IAEhD;;OAEG;IACH,0BAA0B,EAAE,4BAA4B;IAExD;;OAEG;IACH,cAAc,EAAE,gBAAgB;IAEhC;;OAEG;IACH,aAAa,EAAE,eAAe;IAE9B;;OAEG;IACH,QAAQ,EAAE,UAAU;CACX,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The types for DIDs.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const DidTypes = {\n\t/**\n\t * The type for Verifiable Credential.\n\t */\n\tVerifiableCredential: \"VerifiableCredential\",\n\n\t/**\n\t * The type for Verifiable Presentation.\n\t */\n\tVerifiablePresentation: \"VerifiablePresentation\",\n\n\t/**\n\t * The type for Ed25519VerificationKey2020.\n\t */\n\tEd25519VerificationKey2020: \"Ed25519VerificationKey2020\",\n\n\t/**\n\t * The type for JsonWebKey2020.\n\t */\n\tJsonWebKey2020: \"JsonWebKey2020\",\n\n\t/**\n\t * The type for LinkedDomains.\n\t */\n\tLinkedDomains: \"LinkedDomains\",\n\n\t/**\n\t * The type for Multikey.\n\t */\n\tMultikey: \"Multikey\"\n} as const;\n\n/**\n * The types for DIDs.\n */\nexport type DidTypes = (typeof DidTypes)[keyof typeof DidTypes];\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The types of verification method.
|
|
3
|
+
*/
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5
|
+
export const DidVerificationMethodType = {
|
|
6
|
+
/**
|
|
7
|
+
* VerificationMethod.
|
|
8
|
+
*/
|
|
9
|
+
VerificationMethod: "verificationMethod",
|
|
10
|
+
/**
|
|
11
|
+
* Authentication.
|
|
12
|
+
*/
|
|
13
|
+
Authentication: "authentication",
|
|
14
|
+
/**
|
|
15
|
+
* Assertion Method.
|
|
16
|
+
*/
|
|
17
|
+
AssertionMethod: "assertionMethod",
|
|
18
|
+
/**
|
|
19
|
+
* Key Agreement.
|
|
20
|
+
*/
|
|
21
|
+
KeyAgreement: "keyAgreement",
|
|
22
|
+
/**
|
|
23
|
+
* Capability Invocation.
|
|
24
|
+
*/
|
|
25
|
+
CapabilityInvocation: "capabilityInvocation",
|
|
26
|
+
/**
|
|
27
|
+
* Capability Delegation.
|
|
28
|
+
*/
|
|
29
|
+
CapabilityDelegation: "capabilityDelegation"
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=didVerificationMethodType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"didVerificationMethodType.js","sourceRoot":"","sources":["../../../src/models/didVerificationMethodType.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,yBAAyB,GAUlC;IACH;;OAEG;IACH,kBAAkB,EAAE,oBAAoB;IAExC;;OAEG;IACH,cAAc,EAAE,gBAAgB;IAEhC;;OAEG;IACH,eAAe,EAAE,iBAAiB;IAElC;;OAEG;IACH,YAAY,EAAE,cAAc;IAE5B;;OAEG;IACH,oBAAoB,EAAE,sBAAsB;IAE5C;;OAEG;IACH,oBAAoB,EAAE,sBAAsB;CACnC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IDidDocument } from \"./IDidDocument.js\";\n\n/**\n * The types of verification method.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const DidVerificationMethodType: {\n\t[id: string]: keyof Pick<\n\t\tIDidDocument,\n\t\t| \"verificationMethod\"\n\t\t| \"authentication\"\n\t\t| \"assertionMethod\"\n\t\t| \"keyAgreement\"\n\t\t| \"capabilityInvocation\"\n\t\t| \"capabilityDelegation\"\n\t>;\n} = {\n\t/**\n\t * VerificationMethod.\n\t */\n\tVerificationMethod: \"verificationMethod\",\n\n\t/**\n\t * Authentication.\n\t */\n\tAuthentication: \"authentication\",\n\n\t/**\n\t * Assertion Method.\n\t */\n\tAssertionMethod: \"assertionMethod\",\n\n\t/**\n\t * Key Agreement.\n\t */\n\tKeyAgreement: \"keyAgreement\",\n\n\t/**\n\t * Capability Invocation.\n\t */\n\tCapabilityInvocation: \"capabilityInvocation\",\n\n\t/**\n\t * Capability Delegation.\n\t */\n\tCapabilityDelegation: \"capabilityDelegation\"\n} as const;\n\n/**\n * The types of verification method.\n */\nexport type DidVerificationMethodType =\n\t(typeof DidVerificationMethodType)[keyof typeof DidVerificationMethodType];\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
/**
|
|
4
|
+
* The types for proofs.
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
7
|
+
export const ProofTypes = {
|
|
8
|
+
/**
|
|
9
|
+
* The type for Data Integrity Proof.
|
|
10
|
+
*/
|
|
11
|
+
DataIntegrityProof: "DataIntegrityProof",
|
|
12
|
+
/**
|
|
13
|
+
* The type for Json Web Signature 2020.
|
|
14
|
+
*/
|
|
15
|
+
JsonWebSignature2020: "JsonWebSignature2020"
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=proofTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proofTypes.js","sourceRoot":"","sources":["../../../src/models/proofTypes.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AAEvC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB;;OAEG;IACH,kBAAkB,EAAE,oBAAoB;IAExC;;OAEG;IACH,oBAAoB,EAAE,sBAAsB;CACnC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * The types for proofs.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const ProofTypes = {\n\t/**\n\t * The type for Data Integrity Proof.\n\t */\n\tDataIntegrityProof: \"DataIntegrityProof\",\n\n\t/**\n\t * The type for Json Web Signature 2020.\n\t */\n\tJsonWebSignature2020: \"JsonWebSignature2020\"\n} as const;\n\n/**\n * The types for proofs.\n */\nexport type ProofTypes = (typeof ProofTypes)[keyof typeof ProofTypes];\n"]}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Copyright 2024 IOTA Stiftung.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
+
import { Converter, GeneralError, Guards, Is, JsonHelper, ObjectHelper, Uint8ArrayHelper } from "@twin.org/core";
|
|
4
|
+
import { Ed25519, Sha256 } from "@twin.org/crypto";
|
|
5
|
+
import { JsonLdProcessor } from "@twin.org/data-json-ld";
|
|
6
|
+
import { Jwk } from "@twin.org/web";
|
|
7
|
+
import { DidContexts } from "../models/didContexts.js";
|
|
8
|
+
import { DidCryptoSuites } from "../models/didCryptoSuites.js";
|
|
9
|
+
/**
|
|
10
|
+
* Helper methods for creating and verifying proofs.
|
|
11
|
+
* https://www.w3.org/TR/vc-di-eddsa/#eddsa-jcs-2022
|
|
12
|
+
*/
|
|
13
|
+
export class DataIntegrityProofSignerVerifier {
|
|
14
|
+
/**
|
|
15
|
+
* Runtime name for the class.
|
|
16
|
+
*/
|
|
17
|
+
static CLASS_NAME = "DataIntegrityProofSignerVerifier";
|
|
18
|
+
/**
|
|
19
|
+
* Create a proof for the given data.
|
|
20
|
+
* @param unsecuredDocument The data to create the proof for.
|
|
21
|
+
* @param unsignedProof The proof options.
|
|
22
|
+
* @param signKey The key to sign the proof with.
|
|
23
|
+
* @returns The created proof.
|
|
24
|
+
*/
|
|
25
|
+
async createProof(unsecuredDocument, unsignedProof, signKey) {
|
|
26
|
+
Guards.object(DataIntegrityProofSignerVerifier.CLASS_NAME, "unsecuredDocument", unsecuredDocument);
|
|
27
|
+
Guards.object(DataIntegrityProofSignerVerifier.CLASS_NAME, "unsignedProof", unsignedProof);
|
|
28
|
+
Guards.object(DataIntegrityProofSignerVerifier.CLASS_NAME, "signKey", signKey);
|
|
29
|
+
const rawKeys = await Jwk.toRaw(signKey);
|
|
30
|
+
if (!Is.uint8Array(rawKeys.privateKey)) {
|
|
31
|
+
throw new GeneralError(DataIntegrityProofSignerVerifier.CLASS_NAME, "missingPrivateKey");
|
|
32
|
+
}
|
|
33
|
+
const unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);
|
|
34
|
+
const signedProof = ObjectHelper.clone(unsignedProof);
|
|
35
|
+
unsecuredDocumentClone["@context"] = JsonLdProcessor.combineContexts(unsecuredDocumentClone["@context"], DidContexts.ContextDataIntegrity);
|
|
36
|
+
signedProof["@context"] = unsecuredDocumentClone["@context"];
|
|
37
|
+
const combinedHash = await this.createHash(unsecuredDocument, unsignedProof);
|
|
38
|
+
const signature = Ed25519.sign(rawKeys.privateKey, combinedHash);
|
|
39
|
+
signedProof.proofValue = `z${Converter.bytesToBase58(signature)}`;
|
|
40
|
+
return signedProof;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Verify a proof for the given data in format.
|
|
44
|
+
* @param securedDocument The credential to verify.
|
|
45
|
+
* @param signedProof The proof to verify.
|
|
46
|
+
* @param verifyKey The public key to verify the proof with.
|
|
47
|
+
* @returns True if the credential was verified.
|
|
48
|
+
*/
|
|
49
|
+
async verifyProof(securedDocument, signedProof, verifyKey) {
|
|
50
|
+
Guards.object(DataIntegrityProofSignerVerifier.CLASS_NAME, "securedDocument", securedDocument);
|
|
51
|
+
Guards.object(DataIntegrityProofSignerVerifier.CLASS_NAME, "signedProof", signedProof);
|
|
52
|
+
Guards.stringValue(DataIntegrityProofSignerVerifier.CLASS_NAME, "signedProof.proofValue", signedProof.proofValue);
|
|
53
|
+
Guards.object(DataIntegrityProofSignerVerifier.CLASS_NAME, "verifyKey", verifyKey);
|
|
54
|
+
const rawKeys = await Jwk.toRaw(verifyKey);
|
|
55
|
+
if (!Is.uint8Array(rawKeys.publicKey)) {
|
|
56
|
+
throw new GeneralError(DataIntegrityProofSignerVerifier.CLASS_NAME, "missingPublicKey");
|
|
57
|
+
}
|
|
58
|
+
const combinedHash = await this.createHash(securedDocument, signedProof);
|
|
59
|
+
return Ed25519.verify(rawKeys.publicKey, combinedHash, Converter.base58ToBytes(signedProof.proofValue.slice(1)));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a hash for the given data.
|
|
63
|
+
* @param unsecuredDocument The data to create the proof for.
|
|
64
|
+
* @param unsignedProof The unsigned proof.
|
|
65
|
+
* @returns The created hash.
|
|
66
|
+
*/
|
|
67
|
+
async createHash(unsecuredDocument, unsignedProof) {
|
|
68
|
+
Guards.object(DataIntegrityProofSignerVerifier.CLASS_NAME, "unsecuredDocument", unsecuredDocument);
|
|
69
|
+
Guards.object(DataIntegrityProofSignerVerifier.CLASS_NAME, "unsignedProof", unsignedProof);
|
|
70
|
+
Guards.stringValue(DataIntegrityProofSignerVerifier.CLASS_NAME, "unsignedProof.cryptosuite", unsignedProof.cryptosuite);
|
|
71
|
+
Guards.stringValue(DataIntegrityProofSignerVerifier.CLASS_NAME, "unsignedProof.verificationMethod", unsignedProof.verificationMethod);
|
|
72
|
+
const unsecuredDocumentClone = ObjectHelper.clone(unsecuredDocument);
|
|
73
|
+
const proofOptionsClone = ObjectHelper.clone(unsignedProof);
|
|
74
|
+
delete unsecuredDocumentClone.proof;
|
|
75
|
+
delete proofOptionsClone.proofValue;
|
|
76
|
+
if (proofOptionsClone.cryptosuite !== DidCryptoSuites.EdDSAJcs2022) {
|
|
77
|
+
throw new GeneralError(DataIntegrityProofSignerVerifier.CLASS_NAME, "cryptosuiteNotSupported", {
|
|
78
|
+
cryptoSuite: proofOptionsClone.cryptosuite
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
unsecuredDocumentClone["@context"] = JsonLdProcessor.combineContexts(unsecuredDocumentClone["@context"], DidContexts.ContextDataIntegrity);
|
|
82
|
+
proofOptionsClone["@context"] = unsecuredDocumentClone["@context"];
|
|
83
|
+
const transformedDocument = JsonHelper.canonicalize(unsecuredDocumentClone);
|
|
84
|
+
const transformedDocumentHash = Sha256.sum256(Converter.utf8ToBytes(transformedDocument));
|
|
85
|
+
const transformedProofOptions = JsonHelper.canonicalize(proofOptionsClone);
|
|
86
|
+
const proofOptionsHash = Sha256.sum256(Converter.utf8ToBytes(transformedProofOptions));
|
|
87
|
+
return Uint8ArrayHelper.concat([proofOptionsHash, transformedDocumentHash]);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=dataIntegrityProofSignerVerifier.js.map
|
|
@@ -0,0 +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,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAK/D;;;GAGG;AACH,MAAM,OAAO,gCAAgC;IAC5C;;OAEG;IACI,MAAM,CAAU,UAAU,sCAAsD;IAEvF;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CACvB,iBAAoC,EACpC,aAAkC,EAClC,OAAa;QAEb,MAAM,CAAC,MAAM,CACZ,gCAAgC,CAAC,UAAU,uBAE3C,iBAAiB,CACjB,CAAC;QACF,MAAM,CAAC,MAAM,CACZ,gCAAgC,CAAC,UAAU,mBAE3C,aAAa,CACb,CAAC;QACF,MAAM,CAAC,MAAM,CAAO,gCAAgC,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAE3F,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YACxC,MAAM,IAAI,YAAY,CAAC,gCAAgC,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC;QAC1F,CAAC;QAED,MAAM,sBAAsB,GAAG,YAAY,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAErE,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAEtD,sBAAsB,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC,eAAe,CACnE,sBAAsB,CAAC,UAAU,CAAC,EAClC,WAAW,CAAC,oBAAoB,CAChC,CAAC;QAEF,WAAW,CAAC,UAAU,CAAC,GAAG,sBAAsB,CAAC,UAAU,CAAoC,CAAC;QAEhG,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC;QAE7E,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;QAEjE,WAAW,CAAC,UAAU,GAAG,IAAI,SAAS,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;QAElE,OAAO,WAAW,CAAC;IACpB,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,WAAW,CACvB,eAAkC,EAClC,WAAgC,EAChC,SAAe;QAEf,MAAM,CAAC,MAAM,CACZ,gCAAgC,CAAC,UAAU,qBAE3C,eAAe,CACf,CAAC;QACF,MAAM,CAAC,MAAM,CACZ,gCAAgC,CAAC,UAAU,iBAE3C,WAAW,CACX,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,gCAAgC,CAAC,UAAU,4BAE3C,WAAW,CAAC,UAAU,CACtB,CAAC;QACF,MAAM,CAAC,MAAM,CAAO,gCAAgC,CAAC,UAAU,eAAqB,SAAS,CAAC,CAAC;QAE/F,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,YAAY,CAAC,gCAAgC,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QACzF,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,eAAe,EAAE,WAAW,CAAC,CAAC;QAEzE,OAAO,OAAO,CAAC,MAAM,CACpB,OAAO,CAAC,SAAS,EACjB,YAAY,EACZ,SAAS,CAAC,aAAa,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CACxD,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,UAAU,CACtB,iBAAoC,EACpC,aAAkC;QAElC,MAAM,CAAC,MAAM,CACZ,gCAAgC,CAAC,UAAU,uBAE3C,iBAAiB,CACjB,CAAC;QACF,MAAM,CAAC,MAAM,CACZ,gCAAgC,CAAC,UAAU,mBAE3C,aAAa,CACb,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,gCAAgC,CAAC,UAAU,+BAE3C,aAAa,CAAC,WAAW,CACzB,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,gCAAgC,CAAC,UAAU,sCAE3C,aAAa,CAAC,kBAAkB,CAChC,CAAC;QAEF,MAAM,sBAAsB,GAAG,YAAY,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACrE,MAAM,iBAAiB,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QAE5D,OAAO,sBAAsB,CAAC,KAAK,CAAC;QACpC,OAAO,iBAAiB,CAAC,UAAU,CAAC;QAEpC,IAAI,iBAAiB,CAAC,WAAW,KAAK,eAAe,CAAC,YAAY,EAAE,CAAC;YACpE,MAAM,IAAI,YAAY,CACrB,gCAAgC,CAAC,UAAU,EAC3C,yBAAyB,EACzB;gBACC,WAAW,EAAE,iBAAiB,CAAC,WAAW;aAC1C,CACD,CAAC;QACH,CAAC;QAED,sBAAsB,CAAC,UAAU,CAAC,GAAG,eAAe,CAAC,eAAe,CACnE,sBAAsB,CAAC,UAAU,CAAC,EAClC,WAAW,CAAC,oBAAoB,CAChC,CAAC;QAEF,iBAAiB,CAAC,UAAU,CAAC,GAAG,sBAAsB,CACrD,UAAU,CACyB,CAAC;QAErC,MAAM,mBAAmB,GAAG,UAAU,CAAC,YAAY,CAAC,sBAAsB,CAAC,CAAC;QAE5E,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC,CAAC;QAE1F,MAAM,uBAAuB,GAAG,UAAU,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC;QAE3E,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,WAAW,CAAC,uBAAuB,CAAC,CAAC,CAAC;QAEvF,OAAO,gBAAgB,CAAC,MAAM,CAAC,CAAC,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"]}
|