Skip to content

Commit

Permalink
Fix DataIntegrity created type (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbihel authored Jul 22, 2024
1 parent 88110a9 commit 04720d4
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ chrono = "0.4.24"
iref = "3.1.2"
static-iref = "3.0"
rdf-types = "0.22.3"
xsd-types = "0.9.4"
xsd-types = "0.9.5"
locspan = "0.8"
json-syntax = "0.12.5"
nquads-syntax = "0.19"
Expand Down
8 changes: 4 additions & 4 deletions crates/claims/crates/data-integrity/core/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ProofOptions<M, T> {

/// Date a creation of the proof.
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<xsd_types::DateTime>,
pub created: Option<xsd_types::DateTimeStamp>,

/// Verification method.
pub verification_method: Option<ReferenceOrOwned<M>>,
Expand Down Expand Up @@ -74,7 +74,7 @@ impl<M, T: Default> Default for ProofOptions<M, T> {
fn default() -> Self {
Self {
context: None,
created: Some(xsd_types::DateTime::now_ms()),
created: Some(xsd_types::DateTimeStamp::now_ms()),
verification_method: None,
proof_purpose: ProofPurpose::default(),
expires: None,
Expand All @@ -89,7 +89,7 @@ impl<M, T: Default> Default for ProofOptions<M, T> {

impl<M, T> ProofOptions<M, T> {
pub fn new(
created: xsd_types::DateTime,
created: xsd_types::DateTimeStamp,
verification_method: ReferenceOrOwned<M>,
proof_purpose: ProofPurpose,
options: T,
Expand All @@ -111,7 +111,7 @@ impl<M, T> ProofOptions<M, T> {
pub fn from_method_and_options(verification_method: ReferenceOrOwned<M>, options: T) -> Self {
Self {
context: None,
created: Some(xsd_types::DateTime::now_ms()),
created: Some(xsd_types::DateTimeStamp::now_ms()),
verification_method: Some(verification_method),
proof_purpose: ProofPurpose::default(),
expires: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct ProofConfiguration<S: CryptographicSuite> {

/// Date a creation of the proof.
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<xsd_types::DateTime>,
pub created: Option<xsd_types::DateTimeStamp>,

/// Verification method.
#[serde(serialize_with = "S::serialize_verification_method_ref")]
Expand Down Expand Up @@ -90,7 +90,7 @@ pub struct ProofConfiguration<S: CryptographicSuite> {
impl<S: CryptographicSuite> ProofConfiguration<S> {
pub fn new(
type_: S,
created: xsd_types::DateTime,
created: xsd_types::DateTimeStamp,
verification_method: ReferenceOrOwned<S::VerificationMethod>,
proof_purpose: ProofPurpose,
options: S::ProofOptions,
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<S: CryptographicSuite> ProofConfiguration<S> {
Self {
context: None,
type_,
created: Some(xsd_types::DateTime::now_ms()),
created: Some(xsd_types::DateTimeStamp::now_ms()),
verification_method,
proof_purpose: ProofPurpose::default(),
expires: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct ProofConfigurationRef<'a, S: CryptographicSuite> {
pub type_: &'a S,

#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<xsd_types::DateTime>,
pub created: Option<xsd_types::DateTimeStamp>,

#[serde(serialize_with = "S::serialize_verification_method_ref_ref")]
pub verification_method: ReferenceOrOwnedRef<'a, S::VerificationMethod>,
Expand Down Expand Up @@ -141,7 +141,7 @@ pub struct ProofConfigurationRefWithoutOptions<'a, S: CryptographicSuite> {
pub type_: &'a S,

#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<xsd_types::DateTime>,
pub created: Option<xsd_types::DateTimeStamp>,

#[serde(serialize_with = "S::serialize_verification_method_ref_ref")]
pub verification_method: ReferenceOrOwnedRef<'a, S::VerificationMethod>,
Expand Down
20 changes: 16 additions & 4 deletions crates/claims/crates/data-integrity/core/src/proof/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ pub use replay_map::*;

mod configuration;

fn datetime_to_utc_datetimestamp(
d: Option<xsd_types::DateTime>,
) -> Option<xsd_types::DateTimeStamp> {
d.map(|d| {
xsd_types::DateTimeStamp::new(
d.date_time,
d.offset
.unwrap_or(chrono::FixedOffset::east_opt(0).unwrap()),
)
})
}

impl<'de, T: DeserializeCryptographicSuite<'de>> Proof<T> {
fn deserialize_with_type<S>(type_: Type, mut deserializer: S) -> Result<Self, S::Error>
where
Expand All @@ -38,10 +50,10 @@ impl<'de, T: DeserializeCryptographicSuite<'de>> Proof<T> {
.map_err(|_| serde::de::Error::custom("unexpected cryptosuite"))?;

let mut context = None;
let mut created = None;
let mut created: Option<xsd_types::DateTime> = None;
let mut verification_method = None;
let mut proof_purpose = None;
let mut expires = None;
let mut expires: Option<xsd_types::DateTime> = None;
let mut domains = None;
let mut challenge = None;
let mut nonce = None;
Expand Down Expand Up @@ -86,13 +98,13 @@ impl<'de, T: DeserializeCryptographicSuite<'de>> Proof<T> {
Ok(Self {
context,
type_: suite,
created,
created: datetime_to_utc_datetimestamp(created),
verification_method: verification_method
.map(|v| v.map(VerificationMethodOf::unwrap).into())
.ok_or_else(|| serde::de::Error::custom("missing `verificationMethod` property"))?,
proof_purpose: proof_purpose
.ok_or_else(|| serde::de::Error::custom("missing `proofPurpose` property"))?,
expires,
expires: datetime_to_utc_datetimestamp(expires),
domains: domains.unwrap_or_default(),
challenge,
nonce,
Expand Down
14 changes: 10 additions & 4 deletions crates/claims/crates/data-integrity/core/src/proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ pub struct Proof<S: CryptographicSuite> {
pub type_: S,

/// Date a creation of the proof.
#[serde(skip_serializing_if = "Option::is_none")]
pub created: Option<xsd_types::DateTime>,
#[serde(
deserialize_with = "de::deserialize_datetime_utc",
skip_serializing_if = "Option::is_none"
)]
pub created: Option<xsd_types::DateTimeStamp>,

/// Verification method.
#[serde(serialize_with = "S::serialize_verification_method_ref")]
Expand All @@ -59,7 +62,10 @@ pub struct Proof<S: CryptographicSuite> {
pub proof_purpose: ProofPurpose,

/// Specifies when the proof expires.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(
deserialize_with = "de::deserialize_datetime_utc",
skip_serializing_if = "Option::is_none"
)]
pub expires: Option<xsd_types::DateTimeStamp>,

#[allow(rustdoc::bare_urls)]
Expand Down Expand Up @@ -113,7 +119,7 @@ impl<T: CryptographicSuite> Proof<T> {
/// Creates a new proof.
pub fn new(
type_: T,
created: xsd_types::DateTime,
created: xsd_types::DateTimeStamp,
verification_method: ReferenceOrOwned<T::VerificationMethod>,
proof_purpose: ProofPurpose,
options: T::ProofOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct ProofRef<'a, S: CryptographicSuite> {

pub type_: &'a S,

pub created: Option<xsd_types::DateTime>,
pub created: Option<xsd_types::DateTimeStamp>,

pub verification_method: ReferenceOrOwnedRef<'a, S::VerificationMethod>,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ _:b5 <https://windsurf.grotto-networking.com/selective#year> \"2023\"^^<http://w
];
let proof_configuration = ProofConfiguration::new(
Bbs2023,
xsd_types::DateTime::now_ms(),
xsd_types::DateTimeStamp::now_ms(),
ReferenceOrOwned::Reference("did:method:test".parse().unwrap()),
ProofPurpose::Assertion,
(),
Expand Down
10 changes: 8 additions & 2 deletions crates/dids/methods/pkh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,11 @@ mod tests {
})],
);

let issuance_date = cred.issuance_date.clone().unwrap();
let created_date =
xsd_types::DateTimeStamp::new(issuance_date.date_time, issuance_date.offset.unwrap());
let issue_options = ProofOptions::new(
cred.issuance_date.clone().unwrap(),
created_date,
IriBuf::new(did.to_string() + vm_relative_url)
.unwrap()
.into(),
Expand Down Expand Up @@ -1104,8 +1107,11 @@ mod tests {
"id": "did:example:foo"
})],
);
let issuance_date = cred.issuance_date.clone().unwrap();
let created_date =
xsd_types::DateTimeStamp::new(issuance_date.date_time, issuance_date.offset.unwrap());
let issue_options = ProofOptions::new(
cred.issuance_date.clone().unwrap(),
created_date,
IriBuf::new(did.to_string() + vm_relative_url)
.unwrap()
.into(),
Expand Down
10 changes: 8 additions & 2 deletions crates/dids/methods/tz/tests/did.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,11 @@ async fn credential_prove_verify_did_tz2() {
let params = VerificationParameters::from_resolver(&didtz);
let signer = SingleSecretSigner::new(key.clone()).into_local();

let issuance_date = cred.issuance_date.clone().unwrap();
let created_date =
xsd_types::DateTimeStamp::new(issuance_date.date_time, issuance_date.offset.unwrap());
let vc_issue_options = SuiteOptions::new(
cred.issuance_date.clone().unwrap(),
created_date,
IriBuf::new(format!("{did}#blockchainAccountId"))
.unwrap()
.into(),
Expand Down Expand Up @@ -431,8 +434,11 @@ async fn credential_prove_verify_did_tz3() {
let params = VerificationParameters::from_resolver(&didtz);
let signer = SingleSecretSigner::new(key.clone()).into_local();

let issuance_date = cred.issuance_date.clone().unwrap();
let created_date =
xsd_types::DateTimeStamp::new(issuance_date.date_time, issuance_date.offset.unwrap());
let vc_issue_options = SuiteOptions::new(
cred.issuance_date.clone().unwrap(),
created_date,
IriBuf::new(format!("{did}#blockchainAccountId"))
.unwrap()
.into(),
Expand Down

0 comments on commit 04720d4

Please sign in to comment.