Skip to main content

ssi_claims/
lib.rs

1//! Verifiable Claims.
2use ::serde::{Deserialize, Serialize};
3use data_integrity::{
4    CloneCryptographicSuite, CryptographicSuite, DataIntegrity, DebugCryptographicSuite,
5    DeserializeCryptographicSuite, SerializeCryptographicSuite,
6};
7use educe::Educe;
8pub use ssi_claims_core::*;
9
10/// JSON Web signature (JWS).
11///
12/// See: <https://datatracker.ietf.org/doc/html/rfc7515>
13pub use ssi_jws as jws;
14
15pub use jws::{Jws, JwsBuf, JwsPayload, JwsSlice, JwsStr, JwsString, JwsVec};
16
17/// JSON Web tokens (JWT).
18///
19/// See: <https://datatracker.ietf.org/doc/html/rfc7519>
20pub use ssi_jwt as jwt;
21
22pub use jwt::JWTClaims;
23
24/// Selective Disclosure for JWTs (SD-JWT).
25///
26/// See: <https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-08.html>
27pub use ssi_sd_jwt as sd_jwt;
28
29/// CBOR Object Signing and Encryption (COSE).
30///
31/// See: <https://www.rfc-editor.org/rfc/rfc8152.html>
32pub use ssi_cose as cose;
33
34/// W3C Verifiable Credentials (VC).
35///
36/// See: <https://www.w3.org/TR/vc-data-model>
37pub use ssi_vc as vc;
38
39/// Securing Verifiable Credentials using JOSE and COSE.
40///
41/// See: <https://www.w3.org/TR/vc-jose-cose>
42pub use ssi_vc_jose_cose as vc_jose_cose;
43
44/// Data-Integrity Proofs.
45///
46/// See: <https://www.w3.org/TR/vc-data-integrity>
47pub use ssi_data_integrity as data_integrity;
48
49/// JSON-like verifiable credential or JWS (presumably JWT).
50#[derive(Educe, Serialize, Deserialize)]
51#[serde(
52    untagged,
53    bound(
54        serialize = "S: SerializeCryptographicSuite",
55        deserialize = "S: DeserializeCryptographicSuite<'de>"
56    )
57)]
58#[educe(Clone(bound("S: CloneCryptographicSuite")))]
59#[educe(Debug(bound("S: DebugCryptographicSuite")))]
60pub enum JsonCredentialOrJws<S: CryptographicSuite = data_integrity::AnySuite> {
61    /// JSON-like verifiable credential.
62    Credential(Box<DataIntegrity<vc::AnyJsonCredential, S>>),
63
64    /// JSON Web Signature.
65    Jws(jws::JwsString),
66}
67
68/// JSON-like verifiable presentation or JWS (presumably JWT).
69#[derive(Educe, Serialize, Deserialize)]
70#[serde(
71    untagged,
72    bound(
73        serialize = "S: SerializeCryptographicSuite",
74        deserialize = "S: DeserializeCryptographicSuite<'de>"
75    )
76)]
77#[educe(Clone(bound("S: CloneCryptographicSuite")))]
78#[educe(Debug(bound("S: DebugCryptographicSuite")))]
79pub enum JsonPresentationOrJws<S: CryptographicSuite = data_integrity::AnySuite> {
80    /// JSON-like verifiable presentation.
81    Presentation(Box<DataIntegrity<vc::AnyJsonPresentation, S>>),
82
83    /// JSON Web Signature.
84    Jws(jws::JwsString),
85}
86
87#[cfg(test)]
88mod tests {
89    use super::*;
90
91    #[test]
92    fn accept_proof_without_created_vcdm11_json_ecdsa() {
93        let _: DataIntegrity<vc::AnyJsonCredential, data_integrity::AnySuite> =
94            serde_json::from_value(serde_json::json!({
95              "@context": [
96                "https://www.w3.org/2018/credentials/v1"
97              ],
98              "id": "urn:uuid:36245ee9-9074-4b05-a777-febff2e69757",
99              "type": [
100                "VerifiableCredential",
101              ],
102              "issuer": "did:example:issuer",
103              "credentialSubject": {
104                "id": "urn:uuid:1a0e4ef5-091f-4060-842e-18e519ab9440"
105              },
106              "proof": {
107                "type": "DataIntegrityProof",
108                "verificationMethod": "did:example:issuer#key1",
109                "cryptosuite": "ecdsa-rdfc-2019",
110                "proofPurpose": "assertionMethod",
111                "proofValue": "sdfjlsdjflskdfj"
112              }
113            }))
114            .unwrap();
115    }
116
117    #[test]
118    fn accept_proof_without_created_vcdm2_json_or_jws_bbs() {
119        let _: JsonCredentialOrJws = serde_json::from_value(serde_json::json!({
120          "@context": [
121            "https://www.w3.org/ns/credentials/v2"
122          ],
123          "id": "urn:uuid:36245ee9-9074-4b05-a777-febff2e69757",
124          "type": [
125            "VerifiableCredential",
126          ],
127          "issuer": "did:example:issuer",
128          "credentialSubject": {
129            "id": "urn:uuid:1a0e4ef5-091f-4060-842e-18e519ab9440"
130          },
131          "proof": {
132            "type": "DataIntegrityProof",
133            "verificationMethod": "did:example:issuer#key1",
134            "cryptosuite": "bbs-2023",
135            "proofPurpose": "assertionMethod",
136            "proofValue": "sdfjlsdjflskdfj"
137          }
138        }))
139        .unwrap();
140    }
141}