@@ -35,9 +35,11 @@ import eu.europa.ec.eudi.wallet.document.sample.SampleDocumentManager
35
35
import eu.europa.ec.eudi.wallet.internal.getCertificate
36
36
import eu.europa.ec.eudi.wallet.internal.mainExecutor
37
37
import eu.europa.ec.eudi.wallet.issue.openid4vci.*
38
+ import eu.europa.ec.eudi.wallet.keystore.KeyGenerator
39
+ import eu.europa.ec.eudi.wallet.keystore.KeyGeneratorImpl
38
40
import eu.europa.ec.eudi.wallet.transfer.openid4vp.OpenId4VpCBORResponse
39
- import eu.europa.ec.eudi.wallet.transfer.openid4vp.OpenId4VpCBORResponseGeneratorImpl
40
41
import eu.europa.ec.eudi.wallet.transfer.openid4vp.OpenId4vpManager
42
+ import eu.europa.ec.eudi.wallet.transfer.openid4vp.responseGenerator.OpenId4VpResponseGeneratorDelegator
41
43
import eu.europa.ec.eudi.wallet.util.DefaultNfcEngagementService
42
44
import java.security.cert.X509Certificate
43
45
import java.util.concurrent.Executor
@@ -68,7 +70,7 @@ import java.util.concurrent.Executor
68
70
*
69
71
*/
70
72
@SuppressLint(" StaticFieldLeak" )
71
- object EudiWallet {
73
+ object EudiWallet : KeyGenerator by KeyGeneratorImpl {
72
74
73
75
@Volatile
74
76
private lateinit var context: Context
@@ -88,6 +90,7 @@ object EudiWallet {
88
90
fun init (context : Context , config : EudiWalletConfig ) {
89
91
this .context = context.applicationContext
90
92
this ._config = config
93
+ DocumentManagerSdJwt .init (context, config.userAuthenticationRequired)
91
94
}
92
95
93
96
/* *
@@ -197,7 +200,9 @@ object EudiWallet {
197
200
* @throws IllegalStateException if [EudiWallet] is not firstly initialized via the [init] method
198
201
*/
199
202
fun deleteDocumentById (documentId : DocumentId ): DeleteDocumentResult =
200
- documentManager.deleteDocumentById(documentId)
203
+ documentManager.deleteDocumentById(documentId).apply {
204
+ if (this is DeleteDocumentResult .Success ) DocumentManagerSdJwt .deleteDocument(documentId)
205
+ }
201
206
202
207
/* *
203
208
* Create an [UnsignedDocument] for the given [docType]
@@ -224,7 +229,10 @@ object EudiWallet {
224
229
* @return [StoreDocumentResult]
225
230
* @throws IllegalStateException if [EudiWallet] is not firstly initialized via the [init] method
226
231
*/
227
- fun storeIssuedDocument (unsignedDocument : UnsignedDocument , data : ByteArray ): StoreDocumentResult =
232
+ fun storeIssuedDocument (
233
+ unsignedDocument : UnsignedDocument ,
234
+ data : ByteArray
235
+ ): StoreDocumentResult =
228
236
documentManager.storeIssuedDocument(unsignedDocument, data)
229
237
230
238
private var openId4VciManager: OpenId4VciManager ? = null
@@ -280,7 +288,15 @@ object EudiWallet {
280
288
config(config)
281
289
logger = this @EudiWallet.logger
282
290
ktorHttpClientFactory = _config .ktorHttpClientFactory
283
- }.also { it.issueDocumentByDocType(docType, txCode, executor, authorizationHandler, onEvent) }
291
+ }.also {
292
+ it.issueDocumentByDocType(
293
+ docType,
294
+ txCode,
295
+ executor,
296
+ authorizationHandler,
297
+ onEvent
298
+ )
299
+ }
284
300
} ? : run {
285
301
(executor ? : context.mainExecutor()).execute {
286
302
onEvent(IssueEvent .failure(IllegalStateException (" OpenId4Vci config is not set in configuration" )))
@@ -316,7 +332,15 @@ object EudiWallet {
316
332
config(config)
317
333
logger = this @EudiWallet.logger
318
334
ktorHttpClientFactory = _config .ktorHttpClientFactory
319
- }.also { it.issueDocumentByOffer(offer, txCode, executor, authorizationHandler, onEvent) }
335
+ }.also {
336
+ it.issueDocumentByOffer(
337
+ offer,
338
+ txCode,
339
+ executor,
340
+ authorizationHandler,
341
+ onEvent
342
+ )
343
+ }
320
344
} ? : run {
321
345
(executor ? : context.mainExecutor()).execute {
322
346
onEvent(IssueEvent .failure(IllegalStateException (" OpenId4Vci config is not set in configuration" )))
@@ -351,7 +375,15 @@ object EudiWallet {
351
375
config(config)
352
376
logger = this @EudiWallet.logger
353
377
ktorHttpClientFactory = _config .ktorHttpClientFactory
354
- }.also { it.issueDocumentByOfferUri(offerUri, txCode, executor, authorizationHandler, onEvent) }
378
+ }.also {
379
+ it.issueDocumentByOfferUri(
380
+ offerUri,
381
+ txCode,
382
+ executor,
383
+ authorizationHandler,
384
+ onEvent
385
+ )
386
+ }
355
387
} ? : run {
356
388
(executor ? : context.mainExecutor()).execute {
357
389
onEvent(IssueEvent .failure(IllegalStateException (" OpenId4Vci config is not set in configuration" )))
@@ -383,7 +415,12 @@ object EudiWallet {
383
415
ktorHttpClientFactory = _config .ktorHttpClientFactory
384
416
}.also {
385
417
when (val document = documentManager.getDocumentById(documentId)) {
386
- is DeferredDocument -> it.issueDeferredDocument(document, executor, onResult)
418
+ is DeferredDocument -> it.issueDeferredDocument(
419
+ document,
420
+ executor,
421
+ onResult
422
+ )
423
+
387
424
else -> (executor ? : context.mainExecutor()).execute {
388
425
onResult(
389
426
DeferredIssueResult .DocumentFailed (
@@ -474,8 +511,16 @@ object EudiWallet {
474
511
* @return [EudiWallet]
475
512
*/
476
513
fun setTrustedReaderCertificates (trustedReaderCertificates : List <X509Certificate >) = apply {
477
- deviceResponseGenerator.setReaderTrustStore(ReaderTrustStore .getDefault(trustedReaderCertificates))
478
- openId4VpCBORResponseGenerator.setReaderTrustStore(ReaderTrustStore .getDefault(trustedReaderCertificates))
514
+ deviceResponseGenerator.setReaderTrustStore(
515
+ ReaderTrustStore .getDefault(
516
+ trustedReaderCertificates
517
+ )
518
+ )
519
+ openId4VpCBORResponseGenerator.setReaderTrustStore(
520
+ ReaderTrustStore .getDefault(
521
+ trustedReaderCertificates
522
+ )
523
+ )
479
524
}
480
525
481
526
/* *
@@ -630,9 +675,10 @@ object EudiWallet {
630
675
// create response
631
676
val responseResult = when (transferMode) {
632
677
TransferMode .OPENID4VP ->
633
- openId4vpManager?.responseGenerator?.createResponse(disclosedDocuments) ? : ResponseResult .Failure (
634
- Throwable (" Openid4vpManager has not been initialized properly" )
635
- )
678
+ openId4vpManager?.responseGenerator?.createResponse(disclosedDocuments)
679
+ ? : ResponseResult .Failure (
680
+ Throwable (" Openid4vpManager has not been initialized properly" )
681
+ )
636
682
637
683
TransferMode .ISO_18013_5 , TransferMode .REST_API ->
638
684
transferManager.responseGenerator.createResponse(disclosedDocuments)
@@ -645,7 +691,12 @@ object EudiWallet {
645
691
is ResponseResult .Success -> {
646
692
when (transferMode) {
647
693
TransferMode .OPENID4VP ->
648
- openId4vpManager?.sendResponse((responseResult.response as OpenId4VpCBORResponse ).deviceResponseBytes)
694
+ openId4vpManager?.sendResponse(
695
+ when (val result = responseResult.response){
696
+ is OpenId4VpCBORResponse -> result.deviceResponseBytes
697
+ is DeviceResponse -> result.deviceResponseBytes
698
+ else -> throw Exception ()
699
+ })
649
700
650
701
TransferMode .ISO_18013_5 , TransferMode .REST_API ->
651
702
transferManager.sendResponse((responseResult.response as DeviceResponse ).deviceResponseBytes)
@@ -695,9 +746,23 @@ object EudiWallet {
695
746
696
747
private val transferManagerDocumentsResolver: DocumentsResolver
697
748
get() = DocumentsResolver { req ->
698
- documentManager.getDocuments(Document .State .ISSUED )
749
+
750
+ DocumentManagerSdJwt
751
+ .getAllDocuments()
752
+ // .filter { doc -> doc.vct == req.docType }
753
+ .map { doc ->
754
+ RequestDocument (
755
+ documentId = doc.id,
756
+ docType = doc.vct,
757
+ docName = doc.docName,
758
+ userAuthentication = doc.requiresUserAuth,
759
+ docRequest = req
760
+ )
761
+ }.takeIf { it.isNotEmpty() }?.let { return @DocumentsResolver it }
762
+
763
+ return @DocumentsResolver documentManager.getDocuments(Document .State .ISSUED )
699
764
.filterIsInstance<IssuedDocument >()
700
- .filter { doc -> doc.docType == req.docType }
765
+ // .filter { doc -> doc.docType == req.docType }
701
766
.map { doc ->
702
767
RequestDocument (
703
768
documentId = doc.id,
@@ -721,9 +786,9 @@ object EudiWallet {
721
786
}
722
787
}
723
788
724
- private val openId4VpCBORResponseGenerator: OpenId4VpCBORResponseGeneratorImpl by lazy {
789
+ private val openId4VpCBORResponseGenerator: OpenId4VpResponseGeneratorDelegator by lazy {
725
790
requireInit {
726
- OpenId4VpCBORResponseGeneratorImpl .Builder (context)
791
+ OpenId4VpResponseGeneratorDelegator .Builder (context)
727
792
.apply {
728
793
_config .trustedReaderCertificates?.let {
729
794
readerTrustStore = ReaderTrustStore .getDefault(it)
0 commit comments