1use ::serde::{Deserialize, Serialize};
3use data_integrity::{
4 CloneCryptographicSuite, CryptographicSuite, DataIntegrity, DebugCryptographicSuite,
5 DeserializeCryptographicSuite, SerializeCryptographicSuite,
6};
7use educe::Educe;
8pub use ssi_claims_core::*;
9
10pub use ssi_jws as jws;
14
15pub use jws::{Jws, JwsBuf, JwsPayload, JwsSlice, JwsStr, JwsString, JwsVec};
16
17pub use ssi_jwt as jwt;
21
22pub use jwt::JWTClaims;
23
24pub use ssi_sd_jwt as sd_jwt;
28
29pub use ssi_cose as cose;
33
34pub use ssi_vc as vc;
38
39pub use ssi_vc_jose_cose as vc_jose_cose;
43
44pub use ssi_data_integrity as data_integrity;
48
49#[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 Credential(Box<DataIntegrity<vc::AnyJsonCredential, S>>),
63
64 Jws(jws::JwsString),
66}
67
68#[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 Presentation(Box<DataIntegrity<vc::AnyJsonPresentation, S>>),
82
83 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}