28
28
29
29
namespace Org . Eclipse . TractusX . SsiCredentialIssuer . Wallet . Service . Services ;
30
30
31
- public class WalletService : IWalletService
31
+ public class WalletService ( IBasicAuthTokenService basicAuthTokenService , IOptions < WalletSettings > options )
32
+ : IWalletService
32
33
{
33
34
private const string NoIdErrorMessage = "Response must contain a valid id" ;
34
35
private static readonly JsonSerializerOptions Options = new ( ) { PropertyNamingPolicy = JsonNamingPolicy . CamelCase } ;
35
36
36
- private readonly IBasicAuthTokenService _basicAuthTokenService ;
37
- private readonly WalletSettings _settings ;
38
-
39
- public WalletService ( IBasicAuthTokenService basicAuthTokenService , IOptions < WalletSettings > options )
40
- {
41
- _basicAuthTokenService = basicAuthTokenService ;
42
- _settings = options . Value ;
43
- }
37
+ private readonly WalletSettings _settings = options . Value ;
44
38
45
39
public async Task < Guid > CreateCredential ( JsonDocument payload , CancellationToken cancellationToken )
46
40
{
47
- using var client = await _basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( _settings , cancellationToken ) ;
48
- var data = new CreateCredentialRequest ( "catena-x-portal" , new CredentialPayload ( payload ) ) ;
49
- var result = await client . PostAsJsonAsync ( "api/v2.0.0/credentials" , data , Options , cancellationToken )
41
+ using var client = await basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( _settings , cancellationToken ) ;
42
+ var data = new CreateCredentialRequest ( _settings . WalletApplication , new CredentialPayload ( payload ) ) ;
43
+ var result = await client . PostAsJsonAsync ( _settings . CreateCredentialPath , data , Options , cancellationToken )
50
44
. CatchingIntoServiceExceptionFor ( "create-credential" , HttpAsyncResponseMessageExtension . RecoverOptions . INFRASTRUCTURE ,
51
45
async x => ( false , await x . Content . ReadAsStringAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ) )
52
46
. ConfigureAwait ( false ) ;
@@ -61,9 +55,9 @@ public async Task<Guid> CreateCredential(JsonDocument payload, CancellationToken
61
55
62
56
public async Task < string > SignCredential ( Guid credentialId , CancellationToken cancellationToken )
63
57
{
64
- using var client = await _basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( _settings , cancellationToken ) ;
58
+ using var client = await basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( _settings , cancellationToken ) ;
65
59
var data = new SignCredentialRequest ( new SignPayload ( new SignUpdate ( "external" , "jwt" ) ) ) ;
66
- var result = await client . PatchAsJsonAsync ( $ "/api/v2.0.0/credentials/ { credentialId } " , data , Options , cancellationToken )
60
+ var result = await client . PatchAsJsonAsync ( string . Format ( _settings . SignCredentialPath , credentialId ) , data , Options , cancellationToken )
67
61
. CatchingIntoServiceExceptionFor ( "sign-credential" , HttpAsyncResponseMessageExtension . RecoverOptions . INFRASTRUCTURE ,
68
62
async x => ( false , await x . Content . ReadAsStringAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ) )
69
63
. ConfigureAwait ( false ) ;
@@ -78,8 +72,8 @@ public async Task<string> SignCredential(Guid credentialId, CancellationToken ca
78
72
79
73
public async Task < JsonDocument > GetCredential ( Guid externalCredentialId , CancellationToken cancellationToken )
80
74
{
81
- using var client = await _basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( _settings , cancellationToken ) ;
82
- var result = await client . GetAsync ( $ "/api/v2.0.0/credentials/ { externalCredentialId } " , cancellationToken )
75
+ using var client = await basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( _settings , cancellationToken ) ;
76
+ var result = await client . GetAsync ( string . Format ( _settings . GetCredentialPath , externalCredentialId ) , cancellationToken )
83
77
. CatchingIntoServiceExceptionFor ( "get-credential" , HttpAsyncResponseMessageExtension . RecoverOptions . INFRASTRUCTURE ,
84
78
async x => ( false , await x . Content . ReadAsStringAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ) )
85
79
. ConfigureAwait ( false ) ;
@@ -100,9 +94,9 @@ public async Task<Guid> CreateCredentialForHolder(string holderWalletUrl, string
100
94
ClientSecret = clientSecret ,
101
95
TokenAddress = $ "{ holderWalletUrl } /oauth/token"
102
96
} ;
103
- using var client = await _basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( authSettings , cancellationToken ) ;
104
- var data = new DeriveCredentialData ( "catena-x-portal" , new DeriveCredentialPayload ( new DeriveCredential ( credential ) ) ) ;
105
- var result = await client . PostAsJsonAsync ( "/api/v2.0.0/credentials" , data , Options , cancellationToken )
97
+ using var client = await basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( authSettings , cancellationToken ) ;
98
+ var data = new DeriveCredentialData ( _settings . WalletApplication , new DeriveCredentialPayload ( new DeriveCredential ( credential ) ) ) ;
99
+ var result = await client . PostAsJsonAsync ( _settings . CreateCredentialPath , data , Options , cancellationToken )
106
100
. CatchingIntoServiceExceptionFor ( "create-holder-credential" , HttpAsyncResponseMessageExtension . RecoverOptions . INFRASTRUCTURE ,
107
101
async x => ( false , await x . Content . ReadAsStringAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ) )
108
102
. ConfigureAwait ( false ) ;
@@ -117,9 +111,9 @@ public async Task<Guid> CreateCredentialForHolder(string holderWalletUrl, string
117
111
118
112
public async Task RevokeCredentialForIssuer ( Guid externalCredentialId , CancellationToken cancellationToken )
119
113
{
120
- using var client = await _basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( _settings , cancellationToken ) ;
114
+ using var client = await basicAuthTokenService . GetBasicAuthorizedClient < WalletService > ( _settings , cancellationToken ) ;
121
115
var data = new RevokeCredentialRequest ( new RevokePayload ( true ) ) ;
122
- await client . PatchAsJsonAsync ( $ "/api/v2.0.0/credentials/ { externalCredentialId } " , data , Options , cancellationToken )
116
+ await client . PatchAsJsonAsync ( string . Format ( _settings . RevokeCredentialPath , externalCredentialId ) , data , Options , cancellationToken )
123
117
. CatchingIntoServiceExceptionFor ( "revoke-credential" , HttpAsyncResponseMessageExtension . RecoverOptions . INFRASTRUCTURE ,
124
118
async x => ( false , await x . Content . ReadAsStringAsync ( ) . ConfigureAwait ( ConfigureAwaitOptions . None ) ) )
125
119
. ConfigureAwait ( false ) ;
0 commit comments