Skip to content

Commit

Permalink
add credential generic types for try from AnyJsonPresentation
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Tate <[email protected]>
  • Loading branch information
Ryanmtate committed Sep 24, 2024
1 parent d516997 commit 80a5f6b
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/core/response/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ use crate::core::presentation_submission::PresentationSubmission as Presentation
use anyhow::Error;
use base64::prelude::*;
use serde_json::{Map, Value as Json};
use ssi::prelude::AnyJsonPresentation;
use ssi::{
claims::vc::{self, syntax::NonEmptyObject},
prelude::AnyJsonPresentation,
};

#[derive(Debug, Clone)]
pub struct IdToken(pub String);
Expand Down Expand Up @@ -85,11 +88,35 @@ impl From<VpToken> for Json {
}
}

impl TryFrom<AnyJsonPresentation> for VpToken {
impl TryFrom<AnyJsonPresentation<vc::v1::syntax::JsonCredential<NonEmptyObject>>> for VpToken {
type Error = Error;

fn try_from(vp: AnyJsonPresentation) -> Result<Self, Self::Error> {
Ok(VpToken::Single(serde_json::to_vec(&vp)?))
fn try_from(
vp: AnyJsonPresentation<vc::v1::syntax::JsonCredential<NonEmptyObject>>,
) -> Result<Self, Self::Error> {
let map = serde_json::to_value(&vp)?
.as_object()
.ok_or_else(|| Error::msg("Invalid VP"))?
.to_owned()
.into();

Ok(VpToken::SingleAsMap(map))
}
}

impl TryFrom<AnyJsonPresentation<vc::v2::syntax::JsonCredential<NonEmptyObject>>> for VpToken {
type Error = Error;

fn try_from(
vp: AnyJsonPresentation<vc::v2::syntax::JsonCredential<NonEmptyObject>>,
) -> Result<Self, Self::Error> {
let map = serde_json::to_value(&vp)?
.as_object()
.ok_or_else(|| Error::msg("Invalid VP"))?
.to_owned()
.into();

Ok(VpToken::SingleAsMap(map))
}
}

Expand Down

0 comments on commit 80a5f6b

Please sign in to comment.