Skip to content
57 changes: 51 additions & 6 deletions src/WalletFramework.Core/ClaimPaths/ClaimPath.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Text;
using LanguageExt;
using WalletFramework.Core.ClaimPaths.Errors;
using WalletFramework.Core.Functional;
using WalletFramework.Core.Path;
Expand Down Expand Up @@ -31,18 +33,61 @@ from components in array.TraverseAll(ClaimPathComponent.Create)
from path in FromComponents(components)
select path;
}

public static JArray ToJArray(ClaimPath claimPath)
{
var array = new JArray();
foreach (var component in claimPath.GetPathComponents())
{
component.Match(
key =>
{
array.Add(new JValue(key));
return Unit.Default;
},
index =>
{
array.Add(new JValue(index));
return Unit.Default;
},
_ =>
{
array.Add(JValue.CreateNull());
return Unit.Default;
}
);
}
return array;
}
}

public static class ClaimPathFun
{
public static JsonPath ToJsonPath(this ClaimPath claimPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use a StringBuilder

{
var jsonPath = "$." + string.Join('.', claimPath.GetPathComponents().Select(x =>
var jsonPath = new StringBuilder();
jsonPath.Append('$');

foreach (var component in claimPath.GetPathComponents())
{
if (x.IsKey) return x.AsKey();
if (x.IsIndex) return x.AsIndex()?.ToString();
return null;
}).Where(x => x is not null));
return JsonPath.ValidJsonPath(jsonPath).UnwrapOrThrow();
component.Match(
key =>
{
jsonPath.Append($".{key}");
return Unit.Default;
},
integer =>
{
jsonPath.Append($"[{integer}]");
return Unit.Default;
},
_ =>
{
jsonPath.Append("[*]");
return Unit.Default;
});
}

return JsonPath.ValidJsonPath(jsonPath.ToString()).UnwrapOrThrow();
}
}
2 changes: 2 additions & 0 deletions src/WalletFramework.Core/Credentials/CredentialSetId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ private CredentialSetId(string value)
}

public string AsString() => Value;

public Guid AsGuid() => Guid.Parse(Value);

public override string ToString() => Value;

Expand Down
14 changes: 0 additions & 14 deletions src/WalletFramework.MdocVc/ClaimDisplay.cs

This file was deleted.

15 changes: 0 additions & 15 deletions src/WalletFramework.MdocVc/Display/MdocDisplay.cs

This file was deleted.

17 changes: 0 additions & 17 deletions src/WalletFramework.MdocVc/Display/MdocLogo.cs

This file was deleted.

22 changes: 0 additions & 22 deletions src/WalletFramework.MdocVc/Display/MdocName.cs

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions src/WalletFramework.MdocVc/MdocCredential.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
using WalletFramework.Core.Credentials.Abstractions;
using WalletFramework.Core.Cryptography.Models;
using WalletFramework.MdocLib;
using WalletFramework.MdocVc.Display;

namespace WalletFramework.MdocVc;

public record MdocCredential(
Mdoc Mdoc,
CredentialId CredentialId,
CredentialSetId CredentialSetId,
Option<List<MdocDisplay>> Displays,
KeyId KeyId,
CredentialState CredentialState,
bool OneTimeUse,
Expand Down
4 changes: 1 addition & 3 deletions src/WalletFramework.MdocVc/MdocCredentialExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@
using WalletFramework.Core.Credentials;
using WalletFramework.Core.Cryptography.Models;
using WalletFramework.MdocLib;
using WalletFramework.MdocVc.Display;

namespace WalletFramework.MdocVc;

public static class MdocCredentialExtensions
{
public static MdocCredential ToMdocCredential(
this Mdoc mdoc,
Option<List<MdocDisplay>> displays,
KeyId keyId,
CredentialSetId credentialSetId,
CredentialState credentialState,
bool oneTimeUse,
Option<DateTime> expiresAt,
CredentialId credentialId)
{
return new MdocCredential(mdoc, credentialId, credentialSetId, displays, keyId, credentialState, oneTimeUse, expiresAt);
return new MdocCredential(mdoc, credentialId, credentialSetId, keyId, credentialState, oneTimeUse, expiresAt);
}

public static string ToJsonString(this MdocCredential mdocCredential)
Expand Down
Loading