Skip to content

Commit

Permalink
Add base vc to status list credential
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Sep 3, 2024
1 parent 3c793c2 commit eebc84e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
2 changes: 2 additions & 0 deletions bindings/web5_uniffi/src/web5.udl
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ interface StatusListCredential {
sequence<VerifiableCredential>? disabled_credentials
);

[Throws=Web5Error]
VerifiableCredential get_base();
[Throws=Web5Error]
boolean is_disabled(VerifiableCredential credential);
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ impl StatusListCredential {
)?))
}

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())?)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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::{
Expand Down Expand Up @@ -110,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 Down
24 changes: 24 additions & 0 deletions bound/kt/src/main/kotlin/web5/sdk/rust/UniFFI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,8 @@ internal open class UniffiVTableCallbackInterfaceVerifier(








Expand Down Expand Up @@ -1070,6 +1072,8 @@ internal interface UniffiLib : Library {
): Unit
fun uniffi_web5_uniffi_fn_constructor_statuslistcredential_create(`jsonSerializedIssuer`: RustBuffer.ByValue,`statusPurpose`: RustBuffer.ByValue,`disabledCredentials`: RustBuffer.ByValue,uniffi_out_err: UniffiRustCallStatus,
): Pointer
fun uniffi_web5_uniffi_fn_method_statuslistcredential_get_base(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
): Pointer
fun uniffi_web5_uniffi_fn_method_statuslistcredential_is_disabled(`ptr`: Pointer,`credential`: Pointer,uniffi_out_err: UniffiRustCallStatus,
): Byte
fun uniffi_web5_uniffi_fn_clone_verifiablecredential(`ptr`: Pointer,uniffi_out_err: UniffiRustCallStatus,
Expand Down Expand Up @@ -1282,6 +1286,8 @@ internal interface UniffiLib : Library {
): Short
fun uniffi_web5_uniffi_checksum_method_signer_sign(
): Short
fun uniffi_web5_uniffi_checksum_method_statuslistcredential_get_base(
): Short
fun uniffi_web5_uniffi_checksum_method_statuslistcredential_is_disabled(
): Short
fun uniffi_web5_uniffi_checksum_method_verifiablecredential_get_data(
Expand Down Expand Up @@ -1432,6 +1438,9 @@ private fun uniffiCheckApiChecksums(lib: UniffiLib) {
if (lib.uniffi_web5_uniffi_checksum_method_signer_sign() != 5738.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_web5_uniffi_checksum_method_statuslistcredential_get_base() != 15197.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
if (lib.uniffi_web5_uniffi_checksum_method_statuslistcredential_is_disabled() != 23900.toShort()) {
throw RuntimeException("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
}
Expand Down Expand Up @@ -5268,6 +5277,8 @@ public object FfiConverterTypeSigner: FfiConverter<Signer, Pointer> {

public interface StatusListCredentialInterface {

fun `getBase`(): VerifiableCredential

fun `isDisabled`(`credential`: VerifiableCredential): kotlin.Boolean

companion object
Expand Down Expand Up @@ -5355,6 +5366,19 @@ open class StatusListCredential: Disposable, AutoCloseable, StatusListCredential
}


@Throws(Web5Exception::class)override fun `getBase`(): VerifiableCredential {
return FfiConverterTypeVerifiableCredential.lift(
callWithPointer {
uniffiRustCallWithError(Web5Exception) { _status ->
UniffiLib.INSTANCE.uniffi_web5_uniffi_fn_method_statuslistcredential_get_base(
it, _status)
}
}
)
}



@Throws(Web5Exception::class)override fun `isDisabled`(`credential`: VerifiableCredential): kotlin.Boolean {
return FfiConverterBoolean.lift(
callWithPointer {
Expand Down
5 changes: 4 additions & 1 deletion bound/kt/src/main/kotlin/web5/sdk/vc/StatusListCredential.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import web5.sdk.Json
import web5.sdk.rust.StatusListCredential as RustCoreStatusListCredential

data class StatusListCredential(
val base: VerifiableCredential,
internal val rustCoreStatusListCredential: RustCoreStatusListCredential
) {
companion object {
Expand All @@ -17,7 +18,9 @@ data class StatusListCredential(

val rustCoreStatusListCredential = RustCoreStatusListCredential.create(jsonSerializedIssuer, statusPurpose, rustCoreCredentials)

return StatusListCredential(rustCoreStatusListCredential)
val baseVerifiableCredential = VerifiableCredential.fromRustCore(rustCoreStatusListCredential.getBase())

return StatusListCredential(baseVerifiableCredential, rustCoreStatusListCredential)
}
}

Expand Down
22 changes: 22 additions & 0 deletions bound/kt/src/main/kotlin/web5/sdk/vc/VerifiableCredential.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ data class VerifiableCredential private constructor(
internal val rustCoreVerifiableCredential: RustCoreVerifiableCredential,
) {
companion object {
internal fun fromRustCore(rustCoreVerifiableCredential: RustCoreVerifiableCredential): VerifiableCredential {
val data = rustCoreVerifiableCredential.getData()

val issuer = Json.jsonMapper.readValue(data.jsonSerializedIssuer, Issuer::class.java)
val credentialSubject = Json.jsonMapper.readValue(data.jsonSerializedCredentialSubject, CredentialSubject::class.java)
val evidence = data.jsonSerializedEvidence?.let { Json.jsonMapper.readValue<List<Map<String, Any>>>(it) }

return VerifiableCredential(
data.context,
data.type,
data.id,
issuer,
credentialSubject,
Date.from(data.issuanceDate),
data.expirationDate?.let { Date.from(it) },
data.credentialStatus?.let { CredentialStatus(it.id, it.type, it.statusPurpose, it.statusListIndex, it.statusListCredential) },
data.credentialSchema?.let { CredentialSchema(it.id, it.type) },
evidence,
rustCoreVerifiableCredential
)
}

fun create(
issuer: Issuer,
credentialSubject: CredentialSubject,
Expand Down

0 comments on commit eebc84e

Please sign in to comment.