forked from spruceid/ssi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend.rs
60 lines (52 loc) · 1.85 KB
/
send.rs
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
//! When too many lifetime requirements are added to async fns in traits, the
//! compiler may get confused, triggering this issue:
//! <https://github.com/rust-lang/rust/issues/100013>
//! This test ensures that the Rust compiler is able to prove that the
//! `CryptographicSuite::sign` returns a future that is `Send` without
//! triggering the issue.
mod vcdm_v1_sign;
mod vcdm_v2_sign;
use serde::{Deserialize, Serialize};
use ssi::{
claims::{
data_integrity::{AnySuite, CryptographicSuite, ProofOptions},
vc::v1::JsonCredential,
},
dids::{DIDResolver, DIDJWK},
verification_methods::SingleSecretSigner,
JWK,
};
use static_iref::uri;
use std::future::Future;
fn assert_send(f: impl Send + Future) {
drop(f)
}
#[test]
fn data_integrity_sign_is_send() {
let credential = JsonCredential::<Claims>::new(
Some(uri!("https://example.org/#CredentialId").to_owned()), // id
uri!("https://example.org/#Issuer").to_owned().into(), // issuer
xsd_types::DateTime::now(), // issuance date
vec![],
);
let key = JWK::generate_p256(); // requires the `p256` feature.
let did = DIDJWK::generate_url(&key.to_public());
let vm_resolver = DIDJWK.into_vm_resolver();
let signer = SingleSecretSigner::new(key.clone()).into_local();
let verification_method = did.into_iri().into();
let cryptosuite = AnySuite::pick(&key, Some(&verification_method))
.expect("could not find appropriate cryptosuite");
assert_send(cryptosuite.sign(
credential,
&vm_resolver,
&signer,
ProofOptions::from_method(verification_method),
))
}
#[derive(Serialize, Deserialize)]
pub struct Claims {
#[serde(rename = "https://example.org/#name")]
name: String,
#[serde(rename = "https://example.org/#email")]
email: String,
}