Skip to content

Commit

Permalink
remove as_jwt_vc method for sd jwt, update method names for return de…
Browse files Browse the repository at this point in the history
…coded sd jwt claims

Signed-off-by: Ryan Tate <[email protected]>
  • Loading branch information
Ryanmtate committed Oct 18, 2024
1 parent 6fe5a9c commit 52d98c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
20 changes: 5 additions & 15 deletions src/credential/sd_jwt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{jwt_vc::JwtVc, Credential, CredentialFormat, ParsedCredential, ParsedCredentialInner};
use super::{Credential, CredentialFormat, ParsedCredential, ParsedCredentialInner};
use crate::{oid4vp::permission_request::RequestedField, CredentialType, KeyAlias};

use std::sync::Arc;
Expand All @@ -25,8 +25,8 @@ pub struct SdJwt {

// Internal utility methods for decoding a SdJwt.
impl SdJwt {
/// Decode a SdJwt instance and return the revealed claims as a JSON value.
pub fn decode_reveal_json(&self) -> Result<serde_json::Value, SdJwtError> {
/// Return the revealed claims as a JSON value.
pub fn revealed_claims_as_json(&self) -> Result<serde_json::Value, SdJwtError> {
serde_json::to_value(&self.credential)
.map_err(|e| SdJwtError::Serialization(format!("{e:?}")))
}
Expand Down Expand Up @@ -140,21 +140,11 @@ impl SdJwt {
CredentialType(self.types().join("+"))
}

/// Decode a SdJwt instance and return the revealed claims as a JSON string.
pub fn decode_reveal_json_string(&self) -> Result<String, SdJwtError> {
/// Return the revealed claims as a UTF-8 encoded JSON string.
pub fn revealed_claims_as_json_string(&self) -> Result<String, SdJwtError> {
serde_json::to_string(&self.credential)
.map_err(|e| SdJwtError::Serialization(format!("{e:?}")))
}

/// Return the SdJwt as a JwtVc instance.
pub fn as_jwt_vc(self: Arc<Self>) -> Result<Arc<JwtVc>, SdJwtError> {
JwtVc::from_compact_jws_bytes(
self.id,
self.inner.as_bytes().into(),
self.key_alias.clone(),
)
.map_err(|e| SdJwtError::SdJwtVcInitError(format!("{e:?}")))
}
}

impl From<SdJwt> for ParsedCredential {
Expand Down
2 changes: 1 addition & 1 deletion src/oid4vp/holder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ mod tests {
// available at localhost:3000.
//
// See: https://github.com/spruceid/companion/pull/1
#[ignore]
// #[ignore]
#[tokio::test]
async fn test_oid4vp_url() -> Result<(), Box<dyn std::error::Error>> {
let example_sd_jwt = include_str!("../../tests/examples/sd_vc.jwt");
Expand Down

0 comments on commit 52d98c1

Please sign in to comment.