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

support nested claims #153

Merged
merged 1 commit into from
Aug 13, 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
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Drawing;
using Microsoft.IdentityModel.Tokens;
using SD_JWT.Models;
using WalletFramework.Core.Cryptography.Models;
using WalletFramework.Core.Functional;
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models.SdJwt;
using WalletFramework.Oid4Vc.Oid4Vci.Issuer.Models;
using WalletFramework.SdJwtVc.Models.Credential;
using WalletFramework.SdJwtVc.Models.Credential.Attributes;
using WalletFramework.SdJwtVc.Models.Records;

namespace WalletFramework.Oid4Vc.Oid4Vci.Implementations;
Expand All @@ -19,9 +21,22 @@ public static SdJwtRecord ToRecord(
{
var claims = configuration
.Claims?
.Select(pair => (pair.Key, pair.Value))
.ToDictionary(pair => pair.Key, pair => pair.Value);
.SelectMany(claimMetadata =>
{
var claimMetadatas = new Dictionary<string, ClaimMetadata> { { claimMetadata.Key, claimMetadata.Value } };

if (!claimMetadata.Value.NestedClaims.IsNullOrEmpty())
{
foreach (var nested in claimMetadata.Value.NestedClaims!)
{
claimMetadatas.Add(claimMetadata.Key + "." + nested.Key, nested.Value?.ToObject<ClaimMetadata>()!);
}
}

return claimMetadatas;
})
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

var display = configuration
.CredentialConfiguration
.Display
Expand Down Expand Up @@ -52,7 +67,7 @@ public static SdJwtRecord ToRecord(
.ToDictionary(
issuerDisplay => issuerDisplay.Locale.ToNullable()?.ToString(),
issuerDisplay => issuerDisplay.Name.ToNullable()?.ToString());

var record = new SdJwtRecord(
sdJwtDoc,
claims!,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace WalletFramework.Oid4Vc.Oid4Vci.Models.Metadata.Credential.Attributes;

Expand Down Expand Up @@ -30,4 +31,8 @@ public class OidClaim
/// </summary>
[JsonProperty("mandatory", NullValueHandling = NullValueHandling.Ignore)]
public string? Mandatory { get; set; }
}

[JsonProperty("nested_claims", NullValueHandling = NullValueHandling.Ignore)]
[JsonExtensionData]
public Dictionary<string, JToken>? NestedClaims { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace WalletFramework.SdJwtVc.Models.Credential.Attributes
{
namespace WalletFramework.SdJwtVc.Models.Credential.Attributes;

/// <summary>
/// Represents the specifics about a claim.
/// </summary>
public class ClaimMetadata {
/// <summary>
/// Represents the specifics about a claim.
/// Gets or sets the list of display properties associated with a specific credential attribute.
/// </summary>
public class ClaimMetadata
{
/// <summary>
/// Gets or sets the list of display properties associated with a specific credential attribute.
/// </summary>
/// <value>
/// The list of display properties. Each display property provides information on how the credential attribute should
/// be displayed.
/// </value>
[JsonProperty("display", NullValueHandling = NullValueHandling.Ignore)]
public List<ClaimDisplay>? Display { get; set; }
/// <value>
/// The list of display properties. Each display property provides information on how the credential attribute should
/// be displayed.
/// </value>
[JsonProperty("display", NullValueHandling = NullValueHandling.Ignore)]
public List<ClaimDisplay>? Display { get; set; }

/// <summary>
/// String value determining type of value of the claim. A non-exhaustive list of valid values defined by this
/// specification are string, number, and image media types such as image/jpeg.
/// </summary>
[JsonProperty("value_type", NullValueHandling = NullValueHandling.Ignore)]
public string? ValueType { get; set; }

/// <summary>
/// String value determining type of value of the claim. A non-exhaustive list of valid values defined by this
/// specification are string, number, and image media types such as image/jpeg.
/// </summary>
[JsonProperty("mandatory", NullValueHandling = NullValueHandling.Ignore)]
public string? Mandatory { get; set; }
}
/// <summary>
/// String value determining type of value of the claim. A non-exhaustive list of valid values defined by this
/// specification are string, number, and image media types such as image/jpeg.
/// </summary>
[JsonProperty("value_type", NullValueHandling = NullValueHandling.Ignore)]
public string? ValueType { get; set; }

/// <summary>
/// String value determining type of value of the claim. A non-exhaustive list of valid values defined by this
/// specification are string, number, and image media types such as image/jpeg.
/// </summary>
[JsonProperty("mandatory", NullValueHandling = NullValueHandling.Ignore)]
public string? Mandatory { get; set; }

[JsonProperty("nested_claims", NullValueHandling = NullValueHandling.Ignore)]
[JsonExtensionData]
public Dictionary<string, JToken>? NestedClaims { get; set; }
}

Loading