Skip to content

Commit ae51469

Browse files
authored
support nested claims (#153)
Signed-off-by: Johannes Tuerk <johannes.tuerk@lissi.id>
1 parent a61e1d2 commit ae51469

File tree

3 files changed

+56
-32
lines changed

3 files changed

+56
-32
lines changed

src/WalletFramework.Oid4Vc/Oid4Vci/Implementations/SdJwtRecordExtensions.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System.Drawing;
2+
using Microsoft.IdentityModel.Tokens;
23
using SD_JWT.Models;
34
using WalletFramework.Core.Cryptography.Models;
45
using WalletFramework.Core.Functional;
56
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models.SdJwt;
67
using WalletFramework.Oid4Vc.Oid4Vci.Issuer.Models;
78
using WalletFramework.SdJwtVc.Models.Credential;
9+
using WalletFramework.SdJwtVc.Models.Credential.Attributes;
810
using WalletFramework.SdJwtVc.Models.Records;
911

1012
namespace WalletFramework.Oid4Vc.Oid4Vci.Implementations;
@@ -19,9 +21,22 @@ public static SdJwtRecord ToRecord(
1921
{
2022
var claims = configuration
2123
.Claims?
22-
.Select(pair => (pair.Key, pair.Value))
23-
.ToDictionary(pair => pair.Key, pair => pair.Value);
24+
.SelectMany(claimMetadata =>
25+
{
26+
var claimMetadatas = new Dictionary<string, ClaimMetadata> { { claimMetadata.Key, claimMetadata.Value } };
2427

28+
if (!claimMetadata.Value.NestedClaims.IsNullOrEmpty())
29+
{
30+
foreach (var nested in claimMetadata.Value.NestedClaims!)
31+
{
32+
claimMetadatas.Add(claimMetadata.Key + "." + nested.Key, nested.Value?.ToObject<ClaimMetadata>()!);
33+
}
34+
}
35+
36+
return claimMetadatas;
37+
})
38+
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
39+
2540
var display = configuration
2641
.CredentialConfiguration
2742
.Display
@@ -52,7 +67,7 @@ public static SdJwtRecord ToRecord(
5267
.ToDictionary(
5368
issuerDisplay => issuerDisplay.Locale.ToNullable()?.ToString(),
5469
issuerDisplay => issuerDisplay.Name.ToNullable()?.ToString());
55-
70+
5671
var record = new SdJwtRecord(
5772
sdJwtDoc,
5873
claims!,

src/WalletFramework.Oid4Vc/Oid4Vci/Models/Metadata/Credential/Attributes/OidClaim.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
23

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

@@ -30,4 +31,8 @@ public class OidClaim
3031
/// </summary>
3132
[JsonProperty("mandatory", NullValueHandling = NullValueHandling.Ignore)]
3233
public string? Mandatory { get; set; }
33-
}
34+
35+
[JsonProperty("nested_claims", NullValueHandling = NullValueHandling.Ignore)]
36+
[JsonExtensionData]
37+
public Dictionary<string, JToken>? NestedClaims { get; set; }
38+
}
Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
23

3-
namespace WalletFramework.SdJwtVc.Models.Credential.Attributes
4-
{
4+
namespace WalletFramework.SdJwtVc.Models.Credential.Attributes;
5+
6+
/// <summary>
7+
/// Represents the specifics about a claim.
8+
/// </summary>
9+
public class ClaimMetadata {
510
/// <summary>
6-
/// Represents the specifics about a claim.
11+
/// Gets or sets the list of display properties associated with a specific credential attribute.
712
/// </summary>
8-
public class ClaimMetadata
9-
{
10-
/// <summary>
11-
/// Gets or sets the list of display properties associated with a specific credential attribute.
12-
/// </summary>
13-
/// <value>
14-
/// The list of display properties. Each display property provides information on how the credential attribute should
15-
/// be displayed.
16-
/// </value>
17-
[JsonProperty("display", NullValueHandling = NullValueHandling.Ignore)]
18-
public List<ClaimDisplay>? Display { get; set; }
13+
/// <value>
14+
/// The list of display properties. Each display property provides information on how the credential attribute should
15+
/// be displayed.
16+
/// </value>
17+
[JsonProperty("display", NullValueHandling = NullValueHandling.Ignore)]
18+
public List<ClaimDisplay>? Display { get; set; }
1919

20-
/// <summary>
21-
/// String value determining type of value of the claim. A non-exhaustive list of valid values defined by this
22-
/// specification are string, number, and image media types such as image/jpeg.
23-
/// </summary>
24-
[JsonProperty("value_type", NullValueHandling = NullValueHandling.Ignore)]
25-
public string? ValueType { get; set; }
26-
27-
/// <summary>
28-
/// String value determining type of value of the claim. A non-exhaustive list of valid values defined by this
29-
/// specification are string, number, and image media types such as image/jpeg.
30-
/// </summary>
31-
[JsonProperty("mandatory", NullValueHandling = NullValueHandling.Ignore)]
32-
public string? Mandatory { get; set; }
33-
}
20+
/// <summary>
21+
/// String value determining type of value of the claim. A non-exhaustive list of valid values defined by this
22+
/// specification are string, number, and image media types such as image/jpeg.
23+
/// </summary>
24+
[JsonProperty("value_type", NullValueHandling = NullValueHandling.Ignore)]
25+
public string? ValueType { get; set; }
26+
27+
/// <summary>
28+
/// String value determining type of value of the claim. A non-exhaustive list of valid values defined by this
29+
/// specification are string, number, and image media types such as image/jpeg.
30+
/// </summary>
31+
[JsonProperty("mandatory", NullValueHandling = NullValueHandling.Ignore)]
32+
public string? Mandatory { get; set; }
33+
34+
[JsonProperty("nested_claims", NullValueHandling = NullValueHandling.Ignore)]
35+
[JsonExtensionData]
36+
public Dictionary<string, JToken>? NestedClaims { get; set; }
3437
}
38+

0 commit comments

Comments
 (0)