Skip to content

Commit

Permalink
cred status list impl (#320)
Browse files Browse the repository at this point in the history
* cred status list impl

* update

* lint and bind

* update to bindings and kt code

* lint

* remove comments

* lint

* Update crates/web5/src/credentials/mod.rs

Co-authored-by: Diane Huxley <[email protected]>

* nits and updates

* Add base vc to status list credential

---------

Co-authored-by: Diane Huxley <[email protected]>
Co-authored-by: Kendall Weihe <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2024
1 parent b07b7ed commit c63823e
Show file tree
Hide file tree
Showing 18 changed files with 1,202 additions and 19 deletions.
2 changes: 2 additions & 0 deletions bindings/web5_uniffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use web5_uniffi_wrapper::{
credentials::{
presentation_definition::PresentationDefinition,
status_list_credential::StatusListCredential,
verifiable_credential_1_1::{
VerifiableCredential,
VerifiableCredentialCreateOptions as VerifiableCredentialCreateOptionsData,
Expand Down Expand Up @@ -33,6 +34,7 @@ use web5_uniffi_wrapper::{
};

use web5::{
credentials::verifiable_credential_1_1::CredentialStatus as CredentialStatusData,
credentials::CredentialSchema as CredentialSchemaData,
crypto::{dsa::Dsa, jwk::Jwk as JwkData},
dids::{
Expand Down
24 changes: 24 additions & 0 deletions bindings/web5_uniffi/src/web5.udl
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ dictionary VerifiableCredentialCreateOptionsData {
sequence<string>? type;
timestamp? issuance_date;
timestamp? expiration_date;
CredentialStatusData? credential_status;
CredentialSchemaData? credential_schema;
string? json_serialized_evidence;
};
Expand Down Expand Up @@ -284,11 +285,34 @@ dictionary VerifiableCredentialData {
string json_serialized_credential_subject;
timestamp issuance_date;
timestamp? expiration_date;
CredentialStatusData? credential_status;
CredentialSchemaData? credential_schema;
string? json_serialized_evidence;
};

dictionary CredentialSchemaData {
string id;
string type;
};

dictionary CredentialStatusData {
string id;
string type;
string status_purpose;
string status_list_index;
string status_list_credential;
};

interface StatusListCredential {
[Throws=Web5Error, Name=create]
constructor(
string json_serialized_issuer,
string status_purpose,
sequence<VerifiableCredential>? disabled_credentials
);

[Throws=Web5Error]
VerifiableCredential get_base();
[Throws=Web5Error]
boolean is_disabled(VerifiableCredential credential);
};
1 change: 1 addition & 0 deletions bindings/web5_uniffi_wrapper/src/credentials/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod presentation_definition;
pub mod status_list_credential;
pub mod verifiable_credential_1_1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::credentials::verifiable_credential_1_1::VerifiableCredential;
use crate::errors::Result;
use std::sync::Arc;
use web5::credentials::Issuer;
use web5::{
credentials::verifiable_credential_1_1::VerifiableCredential as InnerVerifiableCredential,
credentials::StatusListCredential as InnerStatusListCredential, json::FromJson,
};

pub struct StatusListCredential(pub InnerStatusListCredential);

impl StatusListCredential {
pub fn create(
json_serialized_issuer: String,
status_purpose: String,
credentials_to_disable: Option<Vec<Arc<VerifiableCredential>>>,
) -> Result<Self> {
let issuer = Issuer::from_json_string(&json_serialized_issuer)?;

let inner_vcs: Option<Vec<InnerVerifiableCredential>> =
credentials_to_disable.map(|credentials| {
credentials
.into_iter()
.map(|vc| vc.inner_vc.clone())
.collect()
});

Ok(Self(InnerStatusListCredential::create(
issuer,
status_purpose,
inner_vcs,
)?))
}

pub fn get_base(&self) -> Result<Arc<VerifiableCredential>> {
let vc = VerifiableCredential::from_inner(&self.0.base)?;
Ok(Arc::new(vc))
}

pub fn is_disabled(&self, credential: Arc<VerifiableCredential>) -> Result<bool> {
Ok(self.0.is_disabled(&credential.inner_vc.clone())?)
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use crate::{dids::bearer_did::BearerDid, errors::Result};
use std::{sync::Arc, time::SystemTime};
use web5::credentials::verifiable_credential_1_1::CredentialStatus;
use web5::credentials::Issuer;
use web5::json::ToJson;
use web5::{
credentials::{
verifiable_credential_1_1::{
VerifiableCredential as InnerVerifiableCredential,
VerifiableCredentialCreateOptions as InnerVerifiableCredentialCreateOptions,
},
CredentialSchema, CredentialSubject, Issuer,
CredentialSchema, CredentialSubject,
},
json::{FromJson as _, JsonObject},
};
Expand All @@ -18,12 +21,13 @@ pub struct VerifiableCredentialCreateOptions {
pub r#type: Option<Vec<String>>,
pub issuance_date: Option<SystemTime>,
pub expiration_date: Option<SystemTime>,
pub credential_status: Option<CredentialStatus>,
pub credential_schema: Option<CredentialSchema>,
pub json_serialized_evidence: Option<String>,
}

pub struct VerifiableCredential {
inner_vc: InnerVerifiableCredential,
pub inner_vc: InnerVerifiableCredential,
json_serialized_issuer: String,
json_serialized_credential_subject: String,
}
Expand Down Expand Up @@ -51,6 +55,7 @@ impl VerifiableCredential {
r#type: options.r#type,
issuance_date: options.issuance_date,
expiration_date: options.expiration_date,
credential_status: options.credential_status,
credential_schema: options.credential_schema,
evidence,
};
Expand Down Expand Up @@ -79,6 +84,7 @@ impl VerifiableCredential {
json_serialized_credential_subject: self.json_serialized_credential_subject.clone(),
issuance_date: self.inner_vc.issuance_date,
expiration_date: self.inner_vc.expiration_date,
credential_status: self.inner_vc.credential_status.clone(),
credential_schema: self.inner_vc.credential_schema.clone(),
json_serialized_evidence,
})
Expand All @@ -105,6 +111,16 @@ impl VerifiableCredential {
let vc_jwt = self.inner_vc.sign(&bearer_did.0, verification_method_id)?;
Ok(vc_jwt)
}

pub(crate) fn from_inner(inner_vc: &InnerVerifiableCredential) -> Result<Self> {
let json_serialized_issuer = inner_vc.issuer.to_json_string()?;
let json_serialized_credential_subject = inner_vc.credential_subject.to_json_string()?;
Ok(Self {
inner_vc: inner_vc.clone(),
json_serialized_issuer,
json_serialized_credential_subject,
})
}
}

#[derive(Clone)]
Expand All @@ -116,6 +132,7 @@ pub struct VerifiableCredentialData {
pub json_serialized_credential_subject: String,
pub issuance_date: SystemTime,
pub expiration_date: Option<SystemTime>,
pub credential_status: Option<CredentialStatus>,
pub credential_schema: Option<CredentialSchema>,
pub json_serialized_evidence: Option<String>,
}
Loading

0 comments on commit c63823e

Please sign in to comment.