Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cred status list impl #320

Merged
merged 12 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading