Skip to content

Commit 06bc532

Browse files
authored
remove dependency between pex & transaction data (#302)
Signed-off-by: kenkosmowski <ken.kosmowski@gmx.de>
1 parent fce340f commit 06bc532

File tree

9 files changed

+52
-64
lines changed

9 files changed

+52
-64
lines changed

src/WalletFramework.Oid4Vc/Oid4Vp/Dcql/Services/DcqlService.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
using WalletFramework.Core.Functional;
66
using WalletFramework.Core.Path;
77
using WalletFramework.Oid4Vc.Oid4Vci.Abstractions;
8-
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models;
98
using WalletFramework.Oid4Vc.Oid4Vci.Implementations;
109
using WalletFramework.Oid4Vc.Oid4Vp.Dcql.Models;
1110
using WalletFramework.Oid4Vc.Oid4Vp.Models;
12-
using WalletFramework.Oid4Vc.Oid4Vp.PresentationExchange.Models;
1311
using WalletFramework.SdJwtVc.Services.SdJwtVcHolderService;
1412

1513
namespace WalletFramework.Oid4Vc.Oid4Vp.Dcql.Services;
@@ -43,9 +41,9 @@ public async Task<Option<PresentationCandidate>> FindPresentationCandidateAsync(
4341
}
4442

4543
public AuthorizationResponse CreateAuthorizationResponse(AuthorizationRequest authorizationRequest,
46-
(string Identifier, string Presentation, Format Format)[] presentationMap)
44+
PresentationMap[] presentationMaps)
4745
{
48-
var vpToken = presentationMap.ToDictionary(
46+
var vpToken = presentationMaps.ToDictionary(
4947
presentationItem => presentationItem.Identifier,
5048
presentationItem => presentationItem.Presentation);
5149

src/WalletFramework.Oid4Vc/Oid4Vp/Dcql/Services/IDcqlService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using LanguageExt;
2-
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models;
32
using WalletFramework.Oid4Vc.Oid4Vp.Dcql.Models;
43
using WalletFramework.Oid4Vc.Oid4Vp.Models;
54

@@ -23,11 +22,11 @@ public interface IDcqlService
2322
/// Creates the Parameters that are necessary to send an OpenId4VP Authorization Response.
2423
/// </summary>
2524
/// <param name="authorizationRequest"></param>
26-
/// <param name="presentationMap"></param>
25+
/// <param name="presentationMaps"></param>
2726
/// <returns>
2827
/// An authorization response including the VP Token.
2928
/// </returns>
3029
AuthorizationResponse CreateAuthorizationResponse(
3130
AuthorizationRequest authorizationRequest,
32-
(string Identifier, string Presentation, Format Format)[] presentationMap);
31+
PresentationMap[] presentationMaps);
3332
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models;
2+
3+
namespace WalletFramework.Oid4Vc.Oid4Vp.Models;
4+
5+
public record PresentationMap(string Identifier, string Presentation, Format Format);

src/WalletFramework.Oid4Vc/Oid4Vp/PresentationExchange/Services/IPexService.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using LanguageExt;
2-
using WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models;
32
using WalletFramework.Oid4Vc.Oid4Vp.Models;
43
using WalletFramework.Oid4Vc.Oid4Vp.PresentationExchange.Models;
54

@@ -26,11 +25,11 @@ public interface IPexService
2625
/// Creates the Parameters that are necessary to send an OpenId4VP Authorization Response.
2726
/// </summary>
2827
/// <param name="authorizationRequest"></param>
29-
/// <param name="presentationMap"></param>
28+
/// <param name="presentationMaps"></param>
3029
/// <returns>
3130
/// A task representing the asynchronous operation. The task result contains the Presentation Submission and the VP Token.
3231
/// </returns>
3332
Task<AuthorizationResponse> CreateAuthorizationResponseAsync(
3433
AuthorizationRequest authorizationRequest,
35-
(string Identifier, string Presentation, Format Format)[] presentationMap);
34+
PresentationMap[] presentationMaps);
3635
}

src/WalletFramework.Oid4Vc/Oid4Vp/PresentationExchange/Services/PexService.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ public async Task<Option<PresentationCandidate>> FindPresentationCandidateAsync(
5050
/// <inheritdoc />
5151
public async Task<AuthorizationResponse> CreateAuthorizationResponseAsync(
5252
AuthorizationRequest authorizationRequest,
53-
(string Identifier, string Presentation, Oid4Vci.CredConfiguration.Models.Format Format)[] presentationMap)
53+
PresentationMap[] presentationMaps)
5454
{
5555
var descriptorMaps = new List<DescriptorMap>();
5656
var vpToken = new List<string>();
5757

58-
for (var index = 0; index < presentationMap.Length; index++)
58+
for (var index = 0; index < presentationMaps.Length; index++)
5959
{
60-
vpToken.Add(presentationMap[index].Presentation);
60+
vpToken.Add(presentationMaps[index].Presentation);
6161

6262
var descriptorMap = new DescriptorMap
6363
{
64-
Format = presentationMap[index].Format.ToString(),
65-
Path = presentationMap.Length > 1 ? "$[" + index + "]" : "$",
66-
Id = presentationMap[index].Identifier,
64+
Format = presentationMaps[index].Format.ToString(),
65+
Path = presentationMaps.Length > 1 ? "$[" + index + "]" : "$",
66+
Id = presentationMaps[index].Identifier,
6767
PathNested = null
6868
};
6969
descriptorMaps.Add(descriptorMap);

src/WalletFramework.Oid4Vc/Oid4Vp/Services/IOid4VpHaipClient.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using WalletFramework.Oid4Vc.Oid4Vp.Models;
2-
using Format = WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models.Format;
32

43
namespace WalletFramework.Oid4Vc.Oid4Vp.Services;
54

@@ -12,9 +11,9 @@ public interface IOid4VpHaipClient
1211
/// Creates the Parameters that are necessary to send an OpenId4VP Authorization Response.
1312
/// </summary>
1413
/// <param name="authorizationRequest"></param>
15-
/// <param name="presentationMap"></param>
14+
/// <param name="presentationMaps"></param>
1615
/// <returns>
1716
/// A task representing the asynchronous operation. The task result contains the Presentation Submission and the VP Token.
1817
/// </returns>
19-
Task<AuthorizationResponse> CreateAuthorizationResponseAsync(AuthorizationRequest authorizationRequest, (string Identifier, string Presentation, Format Format)[] presentationMap);
18+
Task<AuthorizationResponse> CreateAuthorizationResponseAsync(AuthorizationRequest authorizationRequest, PresentationMap[] presentationMaps);
2019
}

src/WalletFramework.Oid4Vc/Oid4Vp/Services/Oid4VpClientService.cs

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public async Task<Option<Uri>> AcceptAuthorizationRequest(
146146

147147
var mdocNonce = Option<Nonce>.None;
148148

149-
var presentationMaps = new List<(string Identifier, string Presentation, Format Format, ICredential PresentedCredential)>();
149+
var presentations = new List<(PresentationMap PresentationMap, ICredential PresentedCredential)>();
150150
foreach (var credential in credentials)
151151
{
152152
var credentialRequirement = authorizationRequest.Requirements.Match<OneOf<CredentialQuery, InputDescriptor>>(
@@ -245,13 +245,12 @@ public async Task<Option<Uri>> AcceptAuthorizationRequest(
245245
throw new ArgumentOutOfRangeException(nameof(credential.Credential));
246246
}
247247

248-
presentationMaps.Add((Identifier: credentialRequirementId, Presentation: presentation, Format: format,
249-
PresentedCredential: presentedCredential));
248+
presentations.Add((PresentationMap: new PresentationMap(credentialRequirementId, presentation, format), PresentedCredential: presentedCredential));
250249
}
251250

252251
var authorizationResponse = await _oid4VpHaipClient.CreateAuthorizationResponseAsync(
253252
authorizationRequest,
254-
presentationMaps.Select(tuple => (tuple.Identifier, tuple.Presentation, tuple.Format)).ToArray()
253+
presentations.Select(tuple => tuple.PresentationMap).ToArray()
255254
);
256255

257256
var content = authorizationRequest.ResponseMode switch
@@ -297,20 +296,20 @@ public async Task<Option<Uri>> AcceptAuthorizationRequest(
297296
throw new InvalidOperationException($"Authorization Response failed with message {str}");
298297
}
299298

300-
var presentedCredentials = presentationMaps.Select(presentationMap =>
299+
var presentedCredentials = presentations.Select(presentation =>
301300
{
302301
PresentedCredentialSet result;
303302

304-
switch (presentationMap.PresentedCredential)
303+
switch (presentation.PresentedCredential)
305304
{
306305
case SdJwtRecord sdJwtRecord:
307306
var issuanceSdJwtDoc = sdJwtRecord.ToSdJwtDoc();
308-
var presentation = new SdJwtDoc(presentationMap.Presentation);
307+
var sdJwtDoc = new SdJwtDoc(presentation.PresentationMap.Presentation);
309308

310309
var nonDisclosed =
311310
from disclosure in issuanceSdJwtDoc.Disclosures
312311
let base64Encoded = disclosure.Base64UrlEncoded
313-
where presentation.Disclosures.All(itm => itm.Base64UrlEncoded != base64Encoded)
312+
where sdJwtDoc.Disclosures.All(itm => itm.Base64UrlEncoded != base64Encoded)
314313
select disclosure;
315314

316315
var presentedClaims =
@@ -344,7 +343,7 @@ from claim in sdJwtRecord.Claims
344343
};
345344
break;
346345
default:
347-
throw new ArgumentOutOfRangeException(nameof(presentationMap.PresentedCredential));
346+
throw new ArgumentOutOfRangeException(nameof(presentation.PresentedCredential));
348347
}
349348

350349
return result;
@@ -355,7 +354,9 @@ from claim in sdJwtRecord.Claims
355354
Id = Guid.NewGuid().ToString(),
356355
ClientId = authorizationRequest.ClientId,
357356
ClientMetadata = authorizationRequest.ClientMetadata,
358-
Name = authorizationRequest.PresentationDefinition.Name,
357+
Name = authorizationRequest.Requirements.Match(
358+
dcqlQuery => Option<string>.None,
359+
presentationDefinition => presentationDefinition.Name),
359360
PresentedCredentialSets = presentedCredentials.ToList()
360361
};
361362

@@ -390,7 +391,7 @@ public async Task<Option<Uri>> AcceptOnDemandRequest(
390391

391392
var context = await _agentProvider.GetContextAsync();
392393

393-
var presentationMaps = new List<(string Identifier, string Presentation, Format Format, ICredential PresentedCredential)>();
394+
var presentations = new List<(PresentationMap PresentationMap, ICredential PresentedCredential)>();
394395
foreach (var credential in credentials)
395396
{
396397
var credentialRequirement =
@@ -544,13 +545,12 @@ from keyAuths in mdoc.IssuerSigned.IssuerAuth.Payload.DeviceKeyInfo.KeyAuthoriza
544545
throw new ArgumentOutOfRangeException(nameof(credential.Credential));
545546
}
546547

547-
presentationMaps.Add((Identifier: credentialRequirementId, Presentation: presentation, Format: format,
548-
PresentedCredential: presentedCredential));
548+
presentations.Add((PresentationMap: new PresentationMap(credentialRequirementId, presentation, format), PresentedCredential: presentedCredential));
549549
}
550550

551551
var authorizationResponse = await _oid4VpHaipClient.CreateAuthorizationResponseAsync(
552552
authorizationRequest,
553-
presentationMaps.Select(tuple => (tuple.Identifier, tuple.Presentation, tuple.Format)).ToArray()
553+
presentations.Select(tuple => tuple.PresentationMap).ToArray()
554554
);
555555

556556
var content = authorizationRequest.ResponseMode switch
@@ -578,20 +578,20 @@ from keyAuths in mdoc.IssuerSigned.IssuerAuth.Payload.DeviceKeyInfo.KeyAuthoriza
578578
throw new InvalidOperationException($"Authorization Response failed with message {str}");
579579
}
580580

581-
var presentedCredentials = presentationMaps.Select(presentationMap =>
581+
var presentedCredentials = presentations.Select(presentation =>
582582
{
583583
PresentedCredentialSet result;
584584

585-
switch (presentationMap.PresentedCredential)
585+
switch (presentation.PresentedCredential)
586586
{
587587
case SdJwtRecord sdJwtRecord:
588588
var issuanceSdJwtDoc = sdJwtRecord.ToSdJwtDoc();
589-
var presentation = new SdJwtDoc(presentationMap.Presentation);
589+
var sdJwtDoc = new SdJwtDoc(presentation.PresentationMap.Presentation);
590590

591591
var nonDisclosed =
592592
from disclosure in issuanceSdJwtDoc.Disclosures
593593
let base64Encoded = disclosure.Base64UrlEncoded
594-
where presentation.Disclosures.All(itm => itm.Base64UrlEncoded != base64Encoded)
594+
where sdJwtDoc.Disclosures.All(itm => itm.Base64UrlEncoded != base64Encoded)
595595
select disclosure;
596596

597597
var presentedClaims =
@@ -625,7 +625,7 @@ from claim in sdJwtRecord.Claims
625625
};
626626
break;
627627
default:
628-
throw new ArgumentOutOfRangeException(nameof(presentationMap.PresentedCredential));
628+
throw new ArgumentOutOfRangeException(nameof(presentation.PresentedCredential));
629629
}
630630

631631
return result;
@@ -636,7 +636,9 @@ from claim in sdJwtRecord.Claims
636636
Id = Guid.NewGuid().ToString(),
637637
ClientId = authorizationRequest.ClientId,
638638
ClientMetadata = authorizationRequest.ClientMetadata,
639-
Name = authorizationRequest.PresentationDefinition.Name,
639+
Name = authorizationRequest.Requirements.Match(
640+
dcqlQuery => Option<string>.None,
641+
presentationDefinition => presentationDefinition.Name),
640642
PresentedCredentialSets = presentedCredentials.ToList()
641643
};
642644

@@ -672,11 +674,11 @@ public async Task<Validation<AuthorizationRequestCancellation, PresentationCandi
672674

673675
var uc5TxDataOption = presentationCandidates
674676
.AuthorizationRequest
675-
.PresentationDefinition
676-
.InputDescriptors
677-
.TraverseAny(descriptor =>
678-
descriptor.TransactionData.OnSome(list => new InputDescriptorTransactionData(descriptor.Id, list))
679-
);
677+
.Requirements.Match(
678+
dcqlQuery => Option<IEnumerable<InputDescriptorTransactionData>>.None,
679+
presentationDefinition => presentationDefinition.InputDescriptors.TraverseAny(descriptor =>
680+
descriptor.TransactionData.OnSome(list =>
681+
new InputDescriptorTransactionData(descriptor.Id, list))));
680682

681683
switch (vpTxDataOption.IsSome, uc5TxDataOption.IsSome)
682684
{
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using WalletFramework.Oid4Vc.Oid4Vp.Dcql.Services;
22
using WalletFramework.Oid4Vc.Oid4Vp.Models;
3-
using WalletFramework.Oid4Vc.Oid4Vp.PresentationExchange.Models;
43
using WalletFramework.Oid4Vc.Oid4Vp.PresentationExchange.Services;
5-
using static Newtonsoft.Json.JsonConvert;
6-
using Format = WalletFramework.Oid4Vc.Oid4Vci.CredConfiguration.Models.Format;
74

85
namespace WalletFramework.Oid4Vc.Oid4Vp.Services;
96

@@ -15,10 +12,10 @@ internal class Oid4VpHaipClient(
1512
/// <inheritdoc />
1613
public Task<AuthorizationResponse> CreateAuthorizationResponseAsync(
1714
AuthorizationRequest authorizationRequest,
18-
(string Identifier, string Presentation, Format Format)[] presentationMap)
15+
PresentationMap[] presentationMaps)
1916
{
2017
return authorizationRequest.Requirements.Match(
21-
dcqlQuery => Task.FromResult(dcqlService.CreateAuthorizationResponse(authorizationRequest, presentationMap)),
22-
presentationDefinition => pexService.CreateAuthorizationResponseAsync(authorizationRequest, presentationMap));
18+
dcqlQuery => Task.FromResult(dcqlService.CreateAuthorizationResponse(authorizationRequest, presentationMaps)),
19+
presentationDefinition => pexService.CreateAuthorizationResponseAsync(authorizationRequest, presentationMaps));
2320
}
2421
}

test/WalletFramework.Oid4Vc.Tests/Oid4Vp/PresentationExchange/Services/PexServiceTests.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Data.Common;
21
using FluentAssertions;
32
using Hyperledger.Aries.Agents;
43
using Hyperledger.Aries.Storage;
@@ -51,20 +50,10 @@ public async Task Can_Create_Authorization_Response()
5150
var authRequest = JsonConvert.DeserializeObject<AuthorizationRequest>(PexTestsDataProvider.GetJsonForTestCase())!;
5251
var presentationDefinition = authRequest.PresentationDefinition!;
5352

54-
var presentationMap = new (string Identifier, string Presentation, Format Format)[]
53+
var presentationMap = new PresentationMap[]
5554
{
56-
new()
57-
{
58-
Identifier = presentationDefinition.InputDescriptors[0].Id,
59-
Presentation = Guid.NewGuid().ToString(),
60-
Format = FormatFun.CreateSdJwtFormat()
61-
},
62-
new()
63-
{
64-
Identifier = presentationDefinition.InputDescriptors[1].Id,
65-
Presentation = Guid.NewGuid().ToString(),
66-
Format = FormatFun.CreateSdJwtFormat()
67-
}
55+
new(presentationDefinition.InputDescriptors[0].Id,Guid.NewGuid().ToString(),FormatFun.CreateSdJwtFormat()),
56+
new(presentationDefinition.InputDescriptors[1].Id,Guid.NewGuid().ToString(),FormatFun.CreateSdJwtFormat())
6857
};
6958

7059
var authResponse = await CreatePexService().CreateAuthorizationResponseAsync(authRequest, presentationMap);

0 commit comments

Comments
 (0)