Skip to content

Commit c70be23

Browse files
committed
fix credential request json
Signed-off-by: Kevin <kevin.dinh@lissi.id>
1 parent 0b04128 commit c70be23

File tree

17 files changed

+53
-100
lines changed

17 files changed

+53
-100
lines changed

src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Implementations/CredentialRequestService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async Task<Validation<CredentialResponse>> ICredentialRequestService.RequestCred
8686
clientOptions);
8787

8888
var result = new SdJwtCredentialRequest(vciRequest, sdJwt.Vct);
89-
return result.AsJson();
89+
return result.EncodeToJson();
9090
},
9191
async mdoc =>
9292
{

src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/CredentialRequest.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using LanguageExt;
2-
using Newtonsoft.Json;
2+
using Newtonsoft.Json.Linq;
33
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models;
44

55
namespace WalletFramework.Oid4Vc.Oid4Vci.CredRequest.Models;
@@ -14,12 +14,30 @@ public record CredentialRequest(Option<ProofOfPossession> Proof, Format Format)
1414
/// <summary>
1515
/// Gets the proof of possession of the key material the issued credential shall be bound to.
1616
/// </summary>
17-
[JsonProperty("proof")]
1817
public Option<ProofOfPossession> Proof { get; } = Proof;
1918

2019
/// <summary>
2120
/// Gets the format of the credential to be issued.
2221
/// </summary>
23-
[JsonProperty("format")]
2422
public Format Format { get; } = Format;
2523
}
24+
25+
public static class CredentialRequestFun
26+
{
27+
private const string ProofJsonKey = "proof";
28+
private const string FormatJsonKey = "format";
29+
30+
public static JObject EncodeToJson(this CredentialRequest request)
31+
{
32+
var result = new JObject();
33+
34+
request.Proof.IfSome(proof =>
35+
{
36+
result.Add(ProofJsonKey, JObject.FromObject(proof));
37+
});
38+
39+
result.Add(FormatJsonKey, request.Format.ToString());
40+
41+
return result;
42+
}
43+
}

src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/Mdoc/MdocCredentialRequest.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,9 @@ public static class MdocCredentialRequestFun
2727
{
2828
public static string AsJson(this MdocCredentialRequest request)
2929
{
30-
var json = new JObject();
31-
32-
var vciRequest = JObject.FromObject(request.VciRequest);
33-
foreach (var property in vciRequest.Properties())
34-
{
35-
json.Add(property);
36-
}
30+
var json = request.VciRequest.EncodeToJson();
3731

38-
var vct = JToken.FromObject(request.DocType);
39-
json.Add("doctype", vct);
32+
json.Add("doctype", request.DocType.ToString());
4033

4134
return json.ToString();
4235
}

src/WalletFramework.Oid4Vc/Oid4Vci/CredRequest/Models/SdJwt/SdJwtCredentialRequest.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Newtonsoft.Json;
21
using Newtonsoft.Json.Linq;
32
using WalletFramework.SdJwtVc.Models;
43

@@ -11,7 +10,6 @@ public record SdJwtCredentialRequest
1110
/// <summary>
1211
/// Gets the verifiable credential type (vct).
1312
/// </summary>
14-
[JsonProperty("vct")]
1513
public Vct Vct { get; }
1614

1715
internal SdJwtCredentialRequest(CredentialRequest vciRequest, Vct vct)
@@ -23,18 +21,11 @@ internal SdJwtCredentialRequest(CredentialRequest vciRequest, Vct vct)
2321

2422
public static class SdJwtCredentialRequestFun
2523
{
26-
public static string AsJson(this SdJwtCredentialRequest request)
24+
public static string EncodeToJson(this SdJwtCredentialRequest request)
2725
{
28-
var json = new JObject();
29-
30-
var vciRequest = JObject.FromObject(request.VciRequest);
31-
foreach (var property in vciRequest.Properties())
32-
{
33-
json.Add(property);
34-
}
26+
var json = request.VciRequest.EncodeToJson();
3527

36-
var vct = JToken.FromObject(request.Vct);
37-
json.Add("vct", vct);
28+
json.Add("vct", request.Vct.ToString());
3829

3930
return json.ToString();
4031
}

test/WalletFramework.Oid4Vc.Tests/Oid4Vci/AuthFlow/AuthFlowSessionRecordTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
using WalletFramework.Oid4Vc.Oid4Vci.Authorization.Models;
1010
using WalletFramework.Oid4Vc.Oid4Vci.CredOffer.Models;
1111
using WalletFramework.Oid4Vc.Tests.Oid4Vci.AuthFlow.Samples;
12-
using WalletFramework.Oid4Vc.Tests.Oid4Vci.Samples;
12+
using WalletFramework.Oid4Vc.Tests.Oid4Vci.Issuer.Samples;
1313

1414
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.AuthFlow;
1515

test/WalletFramework.Oid4Vc.Tests/Oid4Vci/AuthFlow/Samples/AuthFlowSamples.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Newtonsoft.Json.Linq;
2-
using WalletFramework.Oid4Vc.Tests.Oid4Vci.Samples;
2+
using WalletFramework.Oid4Vc.Tests.Oid4Vci.Issuer.Samples;
33

44
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.AuthFlow.Samples;
55

test/WalletFramework.Oid4Vc.Tests/Oid4Vci/CredConfiguration/MdocConfigurationTests.cs renamed to test/WalletFramework.Oid4Vc.Tests/Oid4Vci/CredConfiguration/Mdoc/MdocConfigurationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using FluentAssertions;
22
using WalletFramework.Core.Functional;
33
using WalletFramework.Core.Json.Errors;
4-
using WalletFramework.Oid4Vc.Tests.Oid4Vci.Samples.Mdoc;
4+
using WalletFramework.Oid4Vc.Tests.Oid4Vci.CredConfiguration.Mdoc.Samples;
55
using static WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models.Mdoc.MdocConfiguration;
66

7-
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.CredConfiguration;
7+
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.CredConfiguration.Mdoc;
88

99
public class MdocConfigurationTests
1010
{

test/WalletFramework.Oid4Vc.Tests/Oid4Vci/Samples/Mdoc/MdocConfigurationSample.cs renamed to test/WalletFramework.Oid4Vc.Tests/Oid4Vci/CredConfiguration/Mdoc/Samples/MdocConfigurationSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
using static WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models.Format;
1414
using static WalletFramework.MdocLib.NameSpace;
1515

16-
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.Samples.Mdoc;
16+
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.CredConfiguration.Mdoc.Samples;
1717

1818
public static class MdocConfigurationSample
1919
{

test/WalletFramework.Oid4Vc.Tests/Oid4Vci/Samples/SdJwt/SdJwtConfigurationSample.cs renamed to test/WalletFramework.Oid4Vc.Tests/Oid4Vci/CredConfiguration/SdJwt/Samples/SdJwtConfigurationSample.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models;
44
using WalletFramework.SdJwtVc.Models;
55

6-
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.Samples.SdJwt;
6+
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.CredConfiguration.SdJwt.Samples;
77

88
public static class SdJwtConfigurationSample
99
{
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.CredConfiguration;
1+
namespace WalletFramework.Oid4Vc.Tests.Oid4Vci.CredConfiguration.SdJwt;
22

33
public class SdJwtConfigurationTests
44
{
5+
// TODO: Implement this
56
[Fact]
67
public void Can_Parse()
78
{
8-
99
}
1010
}

0 commit comments

Comments
 (0)