1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! Verifiable Claims.
use ::serde::{Deserialize, Serialize};
use data_integrity::{
    CloneCryptographicSuite, CryptographicSuite, DataIntegrity, DebugCryptographicSuite,
    DeserializeCryptographicSuite, SerializeCryptographicSuite,
};
use educe::Educe;
pub use ssi_claims_core::*;

/// JSON Web signature (JWS).
///
/// See: <https://datatracker.ietf.org/doc/html/rfc7515>
pub use ssi_jws as jws;

pub use jws::{Jws, JwsBuf, JwsPayload, JwsSlice, JwsStr, JwsString, JwsVec};

/// JSON Web tokens (JWT).
///
/// See: <https://datatracker.ietf.org/doc/html/rfc7519>
pub use ssi_jwt as jwt;

pub use jwt::JWTClaims;

/// Selective Disclosure for JWTs (SD-JWT).
///
/// See: <https://www.ietf.org/archive/id/draft-ietf-oauth-selective-disclosure-jwt-08.html>
pub use ssi_sd_jwt as sd_jwt;

/// CBOR Object Signing and Encryption (COSE).
///
/// See: <https://www.rfc-editor.org/rfc/rfc8152.html>
pub use ssi_cose as cose;

/// W3C Verifiable Credentials (VC).
///
/// See: <https://www.w3.org/TR/vc-data-model>
pub use ssi_vc as vc;

/// Securing Verifiable Credentials using JOSE and COSE.
///
/// See: <https://www.w3.org/TR/vc-jose-cose>
pub use ssi_vc_jose_cose as vc_jose_cose;

/// Data-Integrity Proofs.
///
/// See: <https://www.w3.org/TR/vc-data-integrity>
pub use ssi_data_integrity as data_integrity;

/// JSON-like verifiable credential or JWS (presumably JWT).
#[derive(Educe, Serialize, Deserialize)]
#[serde(
    untagged,
    bound(
        serialize = "S: SerializeCryptographicSuite",
        deserialize = "S: DeserializeCryptographicSuite<'de>"
    )
)]
#[educe(Clone(bound("S: CloneCryptographicSuite")))]
#[educe(Debug(bound("S: DebugCryptographicSuite")))]
pub enum JsonCredentialOrJws<S: CryptographicSuite = data_integrity::AnySuite> {
    /// JSON-like verifiable credential.
    Credential(DataIntegrity<vc::AnyJsonCredential, S>),

    /// JSON Web Signature.
    Jws(jws::JwsString),
}

/// JSON-like verifiable presentation or JWS (presumably JWT).
#[derive(Educe, Serialize, Deserialize)]
#[serde(
    untagged,
    bound(
        serialize = "S: SerializeCryptographicSuite",
        deserialize = "S: DeserializeCryptographicSuite<'de>"
    )
)]
#[educe(Clone(bound("S: CloneCryptographicSuite")))]
#[educe(Debug(bound("S: DebugCryptographicSuite")))]
pub enum JsonPresentationOrJws<S: CryptographicSuite = data_integrity::AnySuite> {
    /// JSON-like verifiable presentation.
    Presentation(DataIntegrity<vc::AnyJsonPresentation, S>),

    /// JSON Web Signature.
    Jws(jws::JwsString),
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn accept_proof_without_created_vcdm11_json_ecdsa() {
        let _: DataIntegrity<vc::AnyJsonCredential, data_integrity::AnySuite> =
            serde_json::from_value(serde_json::json!({
              "@context": [
                "https://www.w3.org/2018/credentials/v1"
              ],
              "id": "urn:uuid:36245ee9-9074-4b05-a777-febff2e69757",
              "type": [
                "VerifiableCredential",
              ],
              "issuer": "did:example:issuer",
              "credentialSubject": {
                "id": "urn:uuid:1a0e4ef5-091f-4060-842e-18e519ab9440"
              },
              "proof": {
                "type": "DataIntegrityProof",
                "verificationMethod": "did:example:issuer#key1",
                "cryptosuite": "ecdsa-rdfc-2019",
                "proofPurpose": "assertionMethod",
                "proofValue": "sdfjlsdjflskdfj"
              }
            }))
            .unwrap();
    }

    #[test]
    fn accept_proof_without_created_vcdm2_json_or_jws_bbs() {
        let _: JsonCredentialOrJws = serde_json::from_value(serde_json::json!({
          "@context": [
            "https://www.w3.org/ns/credentials/v2"
          ],
          "id": "urn:uuid:36245ee9-9074-4b05-a777-febff2e69757",
          "type": [
            "VerifiableCredential",
          ],
          "issuer": "did:example:issuer",
          "credentialSubject": {
            "id": "urn:uuid:1a0e4ef5-091f-4060-842e-18e519ab9440"
          },
          "proof": {
            "type": "DataIntegrityProof",
            "verificationMethod": "did:example:issuer#key1",
            "cryptosuite": "bbs-2023",
            "proofPurpose": "assertionMethod",
            "proofValue": "sdfjlsdjflskdfj"
          }
        }))
        .unwrap();
    }
}