@@ -41,38 +41,38 @@ public class DigitalIdentityService {
4141 private final UnsignedPathFactory pathFactory ;
4242 private final YotiHttpRequestBuilderFactory requestBuilderFactory ;
4343 private final ReceiptParser receiptParser ;
44-
44+ private final DigitalIdentitySignedRequestStrategy authStrategy ;
4545 private final String apiUrl ;
4646
47- public DigitalIdentityService (
47+ private DigitalIdentityService (
4848 UnsignedPathFactory pathFactory ,
4949 YotiHttpRequestBuilderFactory requestBuilderFactory ,
50- ReceiptParser receiptParser ) {
50+ ReceiptParser receiptParser ,
51+ DigitalIdentitySignedRequestStrategy authStrategy ) {
5152 this .pathFactory = pathFactory ;
5253 this .requestBuilderFactory = requestBuilderFactory ;
5354 this .receiptParser = receiptParser ;
54-
55+ this . authStrategy = authStrategy ;
5556 this .apiUrl = System .getProperty (PROPERTY_YOTI_API_URL , DEFAULT_IDENTITY_URL );
5657 }
5758
58- public static DigitalIdentityService newInstance () {
59+ public static DigitalIdentityService newInstance (KeyPair keyPair , String sdkId ) {
5960 return new DigitalIdentityService (
6061 new UnsignedPathFactory (),
6162 new YotiHttpRequestBuilderFactory (),
62- ReceiptParser .newInstance ()
63+ ReceiptParser .newInstance (),
64+ new DigitalIdentitySignedRequestStrategy (keyPair , sdkId )
6365 );
6466 }
6567
66- public ShareSession createShareSession (DigitalIdentitySignedRequestStrategy authStrategy , ShareSessionRequest shareSessionRequest )
67- throws DigitalIdentityException {
68- Validation .notNull (authStrategy , "signedRequestStrategy" );
68+ public ShareSession createShareSession (ShareSessionRequest shareSessionRequest ) throws DigitalIdentityException {
6969 Validation .notNull (shareSessionRequest , "Share Session request" );
7070
7171 String path = pathFactory .createIdentitySessionPath ();
7272
7373 try {
7474 byte [] payload = ResourceMapper .writeValueAsString (shareSessionRequest );
75- return createSignedRequest (authStrategy , path , HTTP_POST , payload ).execute (ShareSession .class );
75+ return createSignedRequest (path , HTTP_POST , payload ).execute (ShareSession .class );
7676 } catch (IOException ex ) {
7777 throw new DigitalIdentityException ("Error while parsing the share session creation request " , ex );
7878 } catch (URISyntaxException ex ) {
@@ -84,17 +84,13 @@ public ShareSession createShareSession(DigitalIdentitySignedRequestStrategy auth
8484 }
8585 }
8686
87- public ShareSession fetchShareSession (DigitalIdentitySignedRequestStrategy authStrategy , String sessionId )
88- throws DigitalIdentityException {
89- Validation .notNull (authStrategy , "signedRequestStrategy" );
87+ public ShareSession fetchShareSession (String sessionId ) throws DigitalIdentityException {
9088 Validation .notNull (sessionId , "Session ID" );
91-
9289 String path = pathFactory .createIdentitySessionRetrievalPath (sessionId );
93-
9490 LOG .debug ("Requesting share session '{}' at '{}'" , sessionId , path );
9591
9692 try {
97- return createSignedRequest (authStrategy , path ).execute (ShareSession .class );
93+ return createSignedRequest (path ).execute (ShareSession .class );
9894 } catch (Exception ex ) {
9995 throw new DigitalIdentityException (
10096 String .format ("Error while fetching the share session '{%s}' " , sessionId ),
@@ -103,35 +99,31 @@ public ShareSession fetchShareSession(DigitalIdentitySignedRequestStrategy authS
10399 }
104100 }
105101
106- public ShareSessionQrCode createShareQrCode (DigitalIdentitySignedRequestStrategy authStrategy , String sessionId )
107- throws DigitalIdentityException {
108- Validation .notNull (authStrategy , "signedRequestStrategy" );
102+ public ShareSessionQrCode createShareQrCode (String sessionId ) throws DigitalIdentityException {
109103 Validation .notNullOrEmpty (sessionId , "Session ID" );
110104
111105 String path = pathFactory .createIdentitySessionQrCodePath (sessionId );
112106
113107 LOG .debug ("Requesting share session '{}' QR code creation at '{}'" , sessionId , path );
114108
115109 try {
116- return createSignedRequest (authStrategy , path , HTTP_POST , EMPTY_JSON ).execute (ShareSessionQrCode .class );
110+ return createSignedRequest (path , HTTP_POST , EMPTY_JSON ).execute (ShareSessionQrCode .class );
117111 } catch (GeneralSecurityException ex ) {
118112 throw new DigitalIdentityException ("Error while signing the share QR code creation request " , ex );
119113 } catch (IOException | URISyntaxException | ResourceException ex ) {
120114 throw new DigitalIdentityException ("Error while executing the share QR code creation request " , ex );
121115 }
122116 }
123117
124- public ShareSessionQrCode fetchShareQrCode (DigitalIdentitySignedRequestStrategy authStrategy , String qrCodeId )
125- throws DigitalIdentityException {
126- Validation .notNull (authStrategy , "signedRequestStrategy" );
118+ public ShareSessionQrCode fetchShareQrCode (String qrCodeId ) throws DigitalIdentityException {
127119 Validation .notNullOrEmpty (qrCodeId , "QR Code ID" );
128120
129121 String path = pathFactory .createIdentitySessionQrCodeRetrievalPath (qrCodeId );
130122
131123 LOG .debug ("Requesting share session QR code '{} at '{}'" , qrCodeId , path );
132124
133125 try {
134- return createSignedRequest (authStrategy , path ).execute (ShareSessionQrCode .class );
126+ return createSignedRequest (path ).execute (ShareSessionQrCode .class );
135127 } catch (Exception ex ) {
136128 throw new DigitalIdentityException (
137129 String .format ("Error while fetching the share session QR code '{%s}' " , qrCodeId ),
@@ -140,25 +132,24 @@ public ShareSessionQrCode fetchShareQrCode(DigitalIdentitySignedRequestStrategy
140132 }
141133 }
142134
143- public Receipt fetchShareReceipt (DigitalIdentitySignedRequestStrategy authStrategy , KeyPair keyPair , String receiptId ) throws DigitalIdentityException {
144- WrappedReceipt wrappedReceipt = doFetchShareReceipt (authStrategy , receiptId );
135+ public Receipt fetchShareReceipt (KeyPair keyPair , String receiptId ) throws DigitalIdentityException {
136+ WrappedReceipt wrappedReceipt = doFetchShareReceipt (receiptId );
145137
146138 return Optional .ofNullable (wrappedReceipt .getError ())
147139 .map (ignored -> receiptParser .create (wrappedReceipt ))
148140 .orElseGet (() -> {
149- ReceiptItemKey receiptKey = fetchShareReceiptKey (authStrategy , wrappedReceipt );
141+ ReceiptItemKey receiptKey = fetchShareReceiptKey (wrappedReceipt );
150142
151143 return receiptParser .create (wrappedReceipt , receiptKey , keyPair .getPrivate ());
152144 });
153145 }
154146
155- private WrappedReceipt doFetchShareReceipt (DigitalIdentitySignedRequestStrategy authStrategy , String receiptId ) {
147+ private WrappedReceipt doFetchShareReceipt (String receiptId ) {
156148 String path = pathFactory .createIdentitySessionReceiptRetrievalPath (receiptId );
157-
158149 LOG .debug ("Requesting share session receipt '{}' at '{}'" , receiptId , path );
159150
160151 try {
161- return createSignedRequest (authStrategy , path ).execute (WrappedReceipt .class );
152+ return createSignedRequest (path ).execute (WrappedReceipt .class );
162153 } catch (Exception ex ) {
163154 throw new DigitalIdentityException (
164155 String .format ("Error while fetching the share session QR code '{%s}' " , receiptId ),
@@ -167,16 +158,13 @@ private WrappedReceipt doFetchShareReceipt(DigitalIdentitySignedRequestStrategy
167158 }
168159 }
169160
170- private ReceiptItemKey fetchShareReceiptKey (DigitalIdentitySignedRequestStrategy authStrategy , WrappedReceipt wrappedReceipt )
171- throws DigitalIdentityException {
161+ private ReceiptItemKey fetchShareReceiptKey (WrappedReceipt wrappedReceipt ) throws DigitalIdentityException {
172162 String wrappedItemKeyId = wrappedReceipt .getWrappedItemKeyId ();
173-
174163 String path = pathFactory .createIdentitySessionReceiptKeyRetrievalPath (wrappedItemKeyId );
175-
176164 LOG .debug ("Requesting share session receipt item key '{}' at '{}'" , wrappedItemKeyId , path );
177165
178166 try {
179- return createSignedRequest (authStrategy , path ).execute (ReceiptItemKey .class );
167+ return createSignedRequest (path ).execute (ReceiptItemKey .class );
180168 } catch (Exception ex ) {
181169 throw new DigitalIdentityException (
182170 String .format ("Error while fetching the share session receipt key '{%s}' " , wrappedItemKeyId ),
@@ -185,16 +173,14 @@ private ReceiptItemKey fetchShareReceiptKey(DigitalIdentitySignedRequestStrategy
185173 }
186174 }
187175
188- public MatchResult fetchMatch (DigitalIdentitySignedRequestStrategy authStrategy , MatchRequest matchRequest )
189- throws DigitalIdentityException {
190- Validation .notNull (authStrategy , "Application Key Pair" );
176+ public MatchResult fetchMatch (MatchRequest matchRequest ) throws DigitalIdentityException {
191177 Validation .notNull (matchRequest , "DID Match request" );
192178
193179 String path = pathFactory .createIdentityMatchPath ();
194180
195181 try {
196182 byte [] payload = ResourceMapper .writeValueAsString (matchRequest );
197- return createSignedRequest (authStrategy , path , HTTP_POST , payload ).execute (MatchResult .class );
183+ return createSignedRequest (path , HTTP_POST , payload ).execute (MatchResult .class );
198184 } catch (IOException ex ) {
199185 throw new DigitalIdentityException ("Error while parsing the DID Match request" , ex );
200186 } catch (URISyntaxException ex ) {
@@ -206,12 +192,11 @@ public MatchResult fetchMatch(DigitalIdentitySignedRequestStrategy authStrategy,
206192 }
207193 }
208194
209- YotiHttpRequest createSignedRequest (DigitalIdentitySignedRequestStrategy authStrategy , String path )
210- throws GeneralSecurityException , UnsupportedEncodingException , URISyntaxException {
211- return createSignedRequest (authStrategy , path , HTTP_GET , null );
195+ YotiHttpRequest createSignedRequest (String path ) throws GeneralSecurityException , UnsupportedEncodingException , URISyntaxException {
196+ return createSignedRequest (path , HTTP_GET , null );
212197 }
213198
214- YotiHttpRequest createSignedRequest (DigitalIdentitySignedRequestStrategy authStrategy , String path , String method , byte [] payload )
199+ YotiHttpRequest createSignedRequest (String path , String method , byte [] payload )
215200 throws GeneralSecurityException , UnsupportedEncodingException , URISyntaxException {
216201 YotiHttpRequestBuilder request = requestBuilderFactory .create ()
217202 .withAuthStrategy (authStrategy )
0 commit comments