Skip to content

Commit 60531a3

Browse files
authored
payment transaction data (#269)
* payment transaction data Signed-off-by: Kevin <kevin.dinh@lissi.id> * vp error response Signed-off-by: Kevin <kevin.dinh@lissi.id> * sd-jwt transaction data Signed-off-by: Kevin <kevin.dinh@lissi.id> * fix tests Signed-off-by: Kevin <kevin.dinh@lissi.id> * sd-jwt transaction data 2 Signed-off-by: Kevin <kevin.dinh@lissi.id> * sd-jwt transaction data 3 Signed-off-by: Kevin <kevin.dinh@lissi.id> * sd-jwt transaction data 4 Signed-off-by: Kevin <kevin.dinh@lissi.id> * sd-jwt transaction data 5 Signed-off-by: Kevin <kevin.dinh@lissi.id> --------- Signed-off-by: Kevin <kevin.dinh@lissi.id>
1 parent ed51448 commit 60531a3

File tree

59 files changed

+1606
-719
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1606
-719
lines changed

src/WalletFramework.Core/Credentials/CredentialSetId.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace WalletFramework.Core.Credentials;
55

6-
public readonly struct CredentialSetId
6+
public readonly record struct CredentialSetId
77
{
88
private string Value { get; }
99

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
using WalletFramework.Core.Functional;
3+
4+
namespace WalletFramework.Core.Encoding.Errors;
5+
6+
public record CouldNotParseToUtf8StringError(Exception E)
7+
: Error("Could not parse the byte array to an UTF-8 string", E);

src/WalletFramework.Core/Encoding/Sha256Hash.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Security.Cryptography;
2+
using WalletFramework.Core.Base64Url;
23

34
namespace WalletFramework.Core.Encoding;
45

@@ -13,7 +14,7 @@ private Sha256Hash(byte[] value)
1314

1415
public byte[] AsBytes => Value;
1516

16-
public override string ToString() => Value.ToString();
17+
public string AsHex => BitConverter.ToString(Value).Replace("-", "").ToLower();
1718

1819
public static implicit operator byte[](Sha256Hash sha256Hash) => sha256Hash.Value;
1920

src/WalletFramework.Core/Functional/TaskFun.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,22 @@ public static async Task<T> OnException<T>(this Task<T> task, Func<Exception, T>
4545
}
4646
}
4747

48+
public static async Task<T2> OnException<T1, T2>(
49+
this Task<T1> task,
50+
Func<T1, T2> onSuccess,
51+
Func<Exception, T2> fallback)
52+
{
53+
try
54+
{
55+
var t1 = await task;
56+
return onSuccess(t1);
57+
}
58+
catch (Exception e)
59+
{
60+
return fallback(e);
61+
}
62+
}
63+
4864
public static async Task<TaskCompletionResult> OnException(this Task task, Func<Exception, Task> fallback)
4965
{
5066
try

src/WalletFramework.Core/Functional/Validation.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,14 @@ public static T UnwrapOrThrow<T>(this Validation<T> validation, Exception e) =>
298298

299299
public static T UnwrapOrThrow<T>(this Validation<T> validation) =>
300300
validation.UnwrapOrThrow(new InvalidOperationException($"Value of Type `{typeof(T)}` is corrupt"));
301+
302+
public static T UnwrapOrThrow<T, TError>(this Validation<TError, T> validation, Exception e) =>
303+
validation.Match(
304+
t => t,
305+
_ => throw e);
306+
307+
public static T UnwrapOrThrow<T, TError>(this Validation<TError, T> validation) =>
308+
validation.UnwrapOrThrow(new InvalidOperationException($"Value of Type `{typeof(T)}` is corrupt"));
301309

302310
public static Validator<T> AggregateValidators<T>(this IEnumerable<Validator<T>> validators) => t =>
303311
{

src/WalletFramework.Core/Json/JsonFun.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Globalization;
22
using Newtonsoft.Json.Linq;
3+
using WalletFramework.Core.Base64Url;
4+
using WalletFramework.Core.Encoding.Errors;
35
using WalletFramework.Core.Functional;
46
using WalletFramework.Core.Json.Errors;
57

@@ -171,4 +173,30 @@ public static JToken RemoveNulls(this JToken token)
171173
return token;
172174
}
173175
}
176+
177+
public static Validation<JObject> DecodeToJObject(this Base64UrlString base64UrlString)
178+
{
179+
string json;
180+
try
181+
{
182+
var bytes = base64UrlString.AsByteArray;
183+
json = System.Text.Encoding.UTF8.GetString(bytes);
184+
}
185+
catch (Exception e)
186+
{
187+
return new CouldNotParseToUtf8StringError(e);
188+
}
189+
190+
JObject result;
191+
try
192+
{
193+
result = JObject.Parse(json);
194+
}
195+
catch (Exception e)
196+
{
197+
return new InvalidJsonError(json, e);
198+
}
199+
200+
return result;
201+
}
174202
}

src/WalletFramework.Core/Localization/Locale.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public readonly record struct Locale
2222

2323
public static implicit operator string(Locale locale) => locale.Value.ToString();
2424

25+
public CultureInfo AsCultureInfo => Value;
26+
2527
[JsonConstructor]
2628
private Locale(string locale)
2729
{
@@ -90,4 +92,14 @@ public static TDisplay FindOrDefault<TDisplay>(this IDictionary<Locale, TDisplay
9092

9193
return displays[matchedLocale];
9294
}
95+
96+
public static bool IsGerman(this Locale locale)
97+
{
98+
return locale.ToString().Contains("de");
99+
}
100+
101+
public static bool IsEnglish(this Locale locale)
102+
{
103+
return locale.ToString().Contains("en");
104+
}
93105
}

src/WalletFramework.MdocLib/NameSpace.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace WalletFramework.MdocLib;
66

7-
public readonly struct NameSpace
7+
public readonly record struct NameSpace
88
{
99
public string Value { get; }
1010

src/WalletFramework.Oid4Vc/ClientAttestation/CombinedWalletAttestation.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using WalletFramework.Oid4Vc.Oid4Vci.AuthFlow.Models;
2-
31
namespace WalletFramework.Oid4Vc.ClientAttestation;
42

53
public record CombinedWalletAttestation
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Newtonsoft.Json;
2+
3+
namespace WalletFramework.Oid4Vc.Errors;
4+
5+
/// <summary>
6+
/// Represents an error response when the request is invalid or unauthorized.
7+
/// </summary>
8+
public record ErrorResponse(string Error, string? ErrorDescription, string? ErrorUri)
9+
{
10+
/// <summary>
11+
/// Gets or sets the error code indicating the type of error that occurred.
12+
/// </summary>
13+
[JsonProperty("error")]
14+
public string Error { get; } = Error;
15+
16+
/// <summary>
17+
/// Gets or sets the human-readable text providing additional information about the error.
18+
/// </summary>
19+
[JsonProperty("error_description", NullValueHandling = NullValueHandling.Ignore)]
20+
public string? ErrorDescription { get; } = ErrorDescription;
21+
22+
/// <summary>
23+
/// Gets or sets the URI identifying a human-readable web page with information about the error.
24+
/// </summary>
25+
[JsonProperty("error_uri", NullValueHandling = NullValueHandling.Ignore)]
26+
public string? ErrorUri { get; } = ErrorUri;
27+
}
28+
29+
public static class ErrorResponseFun
30+
{
31+
public static FormUrlEncodedContent ToFormUrlContent(this ErrorResponse errorResponse)
32+
{
33+
var dict = new Dictionary<string, string>
34+
{
35+
{ "error", errorResponse.Error },
36+
};
37+
38+
if (errorResponse.ErrorDescription is not null)
39+
{
40+
dict.Add("error_description", errorResponse.ErrorDescription);
41+
}
42+
43+
if (errorResponse.ErrorUri is not null)
44+
{
45+
dict.Add("error_uri", errorResponse.ErrorUri);
46+
}
47+
48+
return new FormUrlEncodedContent(dict);
49+
}
50+
}

0 commit comments

Comments
 (0)