Skip to content

Commit

Permalink
Start implementation for VpTokenItem From method for specific JsonPre…
Browse files Browse the repository at this point in the history
…sentation
  • Loading branch information
Joey Silberman authored and Joey Silberman committed Nov 4, 2024
1 parent eef7f70 commit 1087c81
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/core/response/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ pub use crate::core::authorization_request::parameters::State;
use crate::core::object::TypedParameter;

use anyhow::Error;
use serde::ser::Serialize as _;
use serde::{Deserialize, Serialize};
use serde_json::Value as Json;
use ssi::{claims::vc, one_or_many::OneOrManyRef, prelude::AnyJsonPresentation, OneOrMany};
use ssi::{
claims::vc::{self, v2::SpecializedJsonCredential},
json_ld::{JsonLdObject, Object},
one_or_many::OneOrManyRef,
prelude::AnyJsonPresentation,
OneOrMany,
};

#[derive(Debug, Clone)]
pub struct IdToken(pub String);
Expand Down Expand Up @@ -187,6 +194,20 @@ impl From<vc::v2::syntax::JsonPresentation> for VpTokenItem {
}
}

impl From<vc::v2::syntax::JsonPresentation<SpecializedJsonCredential<Object>>> for VpTokenItem {
fn from(value: vc::v2::syntax::JsonPresentation<SpecializedJsonCredential<Object>>) -> Self {
let serde_json::Value::Object(obj) = serde_json::to_value(value)
// SAFETY: by definition a VCDM2.0 presentation is a JSON object.
.unwrap()
else {
// SAFETY: by definition a VCDM2.0 presentation is a JSON object.
unreachable!()
};

Self::JsonObject(obj)
}
}

impl From<AnyJsonPresentation> for VpTokenItem {
fn from(value: AnyJsonPresentation) -> Self {
let serde_json::Value::Object(obj) = serde_json::to_value(value)
Expand Down

0 comments on commit 1087c81

Please sign in to comment.