Skip to content

Commit cf99ac2

Browse files
Refactor document creation settings to ensure credential count does not exceed batch size
1 parent 8ca9158 commit cf99ac2

17 files changed

Lines changed: 275 additions & 207 deletions

File tree

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,30 @@ val onIssueEvent = OnIssueEvent { event ->
559559

560560
is IssueEvent.DocumentRequiresCreateSettings -> {
561561
// Need to provide settings for document creation
562-
val offeredDocument = event.offeredDocument
563-
val createSettings = wallet.getDefaultCreateDocumentSettings(offeredDocument)
564-
562+
// Create document settings can be varied depending on the document type
563+
564+
val format = event.offeredDocument.documentFormat
565+
val isEuPid = when(format) {
566+
is MsoMdocFormat -> format.docType == "eu.europa.ec.eudi.pid.1"
567+
is SdJwtVcFormat -> format.vct == "urn:eudi:pid:1"
568+
else -> false
569+
}
570+
val createDocumentSettings = when {
571+
isEuPid -> eudiWallet.getDefaultCreateDocumentSettings(
572+
offeredDocument = event.offeredDocument,
573+
numberOfCredentials = 5,
574+
credentialPolicy = CreateDocumentSettings.CredentialPolicy.OneTimeUse
575+
)
576+
577+
578+
else -> eudiWallet.getDefaultCreateDocumentSettings(
579+
offeredDocument = event.offeredDocument,
580+
numberOfCredentials = 1,
581+
credentialPolicy = CreateDocumentSettings.CredentialPolicy.RotateUse
582+
)
583+
}
565584
// Resume with settings
566-
event.resume(createSettings)
585+
event.resume(createDocumentSettings)
567586

568587
// Or cancel
569588
// event.cancel("User cancelled")

docs/wallet-core/eu.europa.ec.eudi.wallet.document/-document-extensions/get-default-create-document-settings.md

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,33 @@
1010

1111
@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-static/index.html)
1212

13-
fun [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md).[getDefaultCreateDocumentSettings](get-default-create-document-settings.md)(attestationChallenge: [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-byte-array/index.html)? = null, numberOfCredentials: [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-int/index.html) = 1, credentialPolicy: CreateDocumentSettings.CredentialPolicy = RotateUse, configure: AndroidKeystoreCreateKeySettings.Builder.() -> [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-unit/index.html)? = null): CreateDocumentSettings
13+
fun [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md).[getDefaultCreateDocumentSettings](get-default-create-document-settings.md)(offeredDocument: [Offer.OfferedDocument](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/index.md), attestationChallenge: [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-byte-array/index.html)? = null, numberOfCredentials: [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-int/index.html) = 1, credentialPolicy: CreateDocumentSettings.CredentialPolicy = RotateUse, configure: AndroidKeystoreCreateKeySettings.Builder.() -> [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-unit/index.html)? = null): CreateDocumentSettings
1414

15-
Returns the default CreateDocumentSettings for the [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md) instance. The default settings are based on the [EudiWalletConfig](../../eu.europa.ec.eudi.wallet/-eudi-wallet-config/index.md) and the presence of an available AndroidKeystoreSecureArea implementation. The [attestationChallenge](get-default-create-document-settings.md) is generated using a [SecureRandom](https://developer.android.com/reference/kotlin/java/security/SecureRandom.html) instance if not provided. The [configure](get-default-create-document-settings.md) lambda can be used to further customize the AndroidKeystoreCreateKeySettings.
15+
Returns the default CreateDocumentSettings for the [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md) instance. The default settings are based on the [EudiWalletConfig](../../eu.europa.ec.eudi.wallet/-eudi-wallet-config/index.md) and the presence of an available AndroidKeystoreSecureArea implementation.
16+
17+
The number of credentials in the returned settings is limited to the [Offer.OfferedDocument.batchCredentialIssuanceSize](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/batch-credential-issuance-size.md), ensuring compatibility with issuer capabilities.
18+
19+
The [attestationChallenge](get-default-create-document-settings.md) is generated using a [SecureRandom](https://developer.android.com/reference/kotlin/java/security/SecureRandom.html) instance if not provided. The [configure](get-default-create-document-settings.md) lambda can be used to further customize the AndroidKeystoreCreateKeySettings.
1620

1721
#### Receiver
1822

1923
The [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md) instance.
2024

2125
#### Return
2226

23-
The default CreateDocumentSettings.
27+
The default CreateDocumentSettings configured for the offered document.
2428

2529
#### Parameters
2630

2731
androidJvm
2832

2933
| | |
3034
|---|---|
35+
| offeredDocument | The [Offer.OfferedDocument](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/index.md) for which to create the default settings. Used to determine the maximum number of credentials allowed. |
3136
| attestationChallenge | The attestation challenge to use when creating the keys. If `null`, a random challenge will be generated. |
32-
| numberOfCredentials | The number of credentials to pre-generate for the document. Defaults to 1. |
37+
| numberOfCredentials | The number of credentials to pre-generate for the document. Will be limited to not exceed [Offer.OfferedDocument.batchCredentialIssuanceSize](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/batch-credential-issuance-size.md). Defaults to 1. |
3338
| credentialPolicy | The policy for credential usage (OneTimeUse or RotateUse). Defaults to RotateUse. |
34-
| configure | A lambda to further customize the AndroidKeystoreCreateKeySettings. |
39+
| configure | A lambda to further customize the AndroidKeystoreCreateKeySettings. If not provided, settings will use values from [EudiWalletConfig](../../eu.europa.ec.eudi.wallet/-eudi-wallet-config/index.md). |
3540

3641
#### See also
3742

@@ -47,37 +52,3 @@ androidJvm
4752
| | |
4853
|---|---|
4954
| NoSuchElementException | if no AndroidKeystoreSecureArea implementation is available. |
50-
51-
[androidJvm]\
52-
53-
@[JvmOverloads](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-overloads/index.html)
54-
55-
@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-static/index.html)
56-
57-
fun [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md).[getDefaultCreateDocumentSettings](get-default-create-document-settings.md)(offeredDocument: [Offer.OfferedDocument](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/index.md), attestationChallenge: [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-byte-array/index.html)? = null, configure: AndroidKeystoreCreateKeySettings.Builder.() -> [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-unit/index.html)? = null): CreateDocumentSettings
58-
59-
Returns the default CreateDocumentSettings for the [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md) instance based on an [Offer.OfferedDocument](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/index.md). The settings are derived from the issuer metadata and the document configuration within the offer. The [attestationChallenge](get-default-create-document-settings.md) is generated using a [SecureRandom](https://developer.android.com/reference/kotlin/java/security/SecureRandom.html) instance if not provided. The [configure](get-default-create-document-settings.md) lambda can be used to further customize the AndroidKeystoreCreateKeySettings.
60-
61-
#### Receiver
62-
63-
The [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md) instance.
64-
65-
#### Return
66-
67-
The default CreateDocumentSettings tailored for the offered document.
68-
69-
#### Parameters
70-
71-
androidJvm
72-
73-
| | |
74-
|---|---|
75-
| offeredDocument | The [Offer.OfferedDocument](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/index.md) from which to derive settings. |
76-
| attestationChallenge | The attestation challenge to use when creating the keys. If `null`, a random challenge will be generated. |
77-
| configure | A lambda to further customize the AndroidKeystoreCreateKeySettings. |
78-
79-
#### Throws
80-
81-
| | |
82-
|---|---|
83-
| NoSuchElementException | if no AndroidKeystoreSecureArea implementation is available. |

docs/wallet-core/eu.europa.ec.eudi.wallet.document/-document-extensions/get-default-key-unlock-data.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
# getDefaultKeyUnlockData
44

55
[androidJvm]\
6+
suspend fun IssuedDocument.[getDefaultKeyUnlockData](get-default-key-unlock-data.md)(): AndroidKeystoreKeyUnlockData?
7+
8+
Returns the default AndroidKeystoreKeyUnlockData for the IssuedDocument. The default key unlock data is based on the IssuedDocument.findCredential
9+
10+
#### Receiver
11+
12+
The IssuedDocument instance.
13+
14+
#### Return
15+
16+
The default AndroidKeystoreKeyUnlockData for the IssuedDocument if it requires user authentication, otherwise `null`.
17+
18+
#### See also
19+
20+
| |
21+
|---|
22+
| [DocumentExtensions.getDefaultKeyUnlockData](get-default-key-unlock-data.md) |
23+
24+
#### Throws
25+
26+
| | |
27+
|---|---|
28+
| [IllegalArgumentException](https://developer.android.com/reference/kotlin/java/lang/IllegalArgumentException.html) | if the document is not managed by AndroidKeystoreSecureArea. |
29+
30+
[androidJvm]\
31+
32+
@[JvmName](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-name/index.html)(name = "getDefaultKeyUnlockDataForDocument")
33+
634
suspend fun [getDefaultKeyUnlockData](get-default-key-unlock-data.md)(document: IssuedDocument): AndroidKeystoreKeyUnlockData?
735

836
Returns the default AndroidKeystoreKeyUnlockData for the given IssuedDocument. The key unlock data is retrieved based on the document's associated credential.
@@ -30,7 +58,7 @@ androidJvm
3058

3159
| | |
3260
|---|---|
33-
| [IllegalStateException](https://developer.android.com/reference/kotlin/java/lang/IllegalStateException.html) | if the document is not managed by AndroidKeystoreSecureArea. |
61+
| [IllegalArgumentException](https://developer.android.com/reference/kotlin/java/lang/IllegalArgumentException.html) | if the document is not managed by AndroidKeystoreSecureArea. |
3462

3563
[androidJvm]\
3664

docs/wallet-core/eu.europa.ec.eudi.wallet.document/-document-extensions/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ Provides extension functions for Document and [EudiWallet](../../eu.europa.ec.eu
1717

1818
| Name | Summary |
1919
|---|---|
20-
| [getDefaultCreateDocumentSettings](get-default-create-document-settings.md) | [androidJvm]<br>@[JvmOverloads](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-overloads/index.html)<br>@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-static/index.html)<br>fun [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md).[getDefaultCreateDocumentSettings](get-default-create-document-settings.md)(offeredDocument: [Offer.OfferedDocument](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/index.md), attestationChallenge: [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-byte-array/index.html)? = null, configure: AndroidKeystoreCreateKeySettings.Builder.() -&gt; [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-unit/index.html)? = null): CreateDocumentSettings<br>Returns the default CreateDocumentSettings for the [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md) instance based on an [Offer.OfferedDocument](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/index.md). The settings are derived from the issuer metadata and the document configuration within the offer. The [attestationChallenge](get-default-create-document-settings.md) is generated using a [SecureRandom](https://developer.android.com/reference/kotlin/java/security/SecureRandom.html) instance if not provided. The [configure](get-default-create-document-settings.md) lambda can be used to further customize the AndroidKeystoreCreateKeySettings.<br>[androidJvm]<br>@[JvmName](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-name/index.html)(name = &quot;getDefaultCreateDocumentSettings&quot;)<br>@[JvmOverloads](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-overloads/index.html)<br>@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-static/index.html)<br>fun [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md).[getDefaultCreateDocumentSettings](get-default-create-document-settings.md)(attestationChallenge: [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-byte-array/index.html)? = null, numberOfCredentials: [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-int/index.html) = 1, credentialPolicy: CreateDocumentSettings.CredentialPolicy = RotateUse, configure: AndroidKeystoreCreateKeySettings.Builder.() -&gt; [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-unit/index.html)? = null): CreateDocumentSettings<br>Returns the default CreateDocumentSettings for the [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md) instance. The default settings are based on the [EudiWalletConfig](../../eu.europa.ec.eudi.wallet/-eudi-wallet-config/index.md) and the presence of an available AndroidKeystoreSecureArea implementation. The [attestationChallenge](get-default-create-document-settings.md) is generated using a [SecureRandom](https://developer.android.com/reference/kotlin/java/security/SecureRandom.html) instance if not provided. The [configure](get-default-create-document-settings.md) lambda can be used to further customize the AndroidKeystoreCreateKeySettings. |
21-
| [getDefaultKeyUnlockData](get-default-key-unlock-data.md) | [androidJvm]<br>suspend fun [getDefaultKeyUnlockData](get-default-key-unlock-data.md)(document: IssuedDocument): AndroidKeystoreKeyUnlockData?<br>Returns the default AndroidKeystoreKeyUnlockData for the given IssuedDocument. The key unlock data is retrieved based on the document's associated credential.<br>[androidJvm]<br>@[JvmName](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-name/index.html)(name = &quot;getDefaultKeyUnlockData&quot;)<br>@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-static/index.html)<br>fun [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md).[getDefaultKeyUnlockData](get-default-key-unlock-data.md)(documentId: DocumentId): AndroidKeystoreKeyUnlockData?<br>Returns the default AndroidKeystoreKeyUnlockData for the given DocumentId. The default key unlock data is based on the Document.keyAlias of the found document. This is applicable only if the document's key requires user authentication.<br>[androidJvm]<br>fun [getDefaultKeyUnlockData](get-default-key-unlock-data.md)(secureArea: SecureArea, keyAlias: [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-string/index.html)): AndroidKeystoreKeyUnlockData?<br>Returns the default AndroidKeystoreKeyUnlockData for the given SecureArea and [keyAlias](get-default-key-unlock-data.md) if the [secureArea](get-default-key-unlock-data.md) is an instance of AndroidKeystoreSecureArea. |
20+
| [getDefaultCreateDocumentSettings](get-default-create-document-settings.md) | [androidJvm]<br>@[JvmName](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-name/index.html)(name = &quot;getDefaultCreateDocumentSettings&quot;)<br>@[JvmOverloads](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-overloads/index.html)<br>@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-static/index.html)<br>fun [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md).[getDefaultCreateDocumentSettings](get-default-create-document-settings.md)(offeredDocument: [Offer.OfferedDocument](../../eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/index.md), attestationChallenge: [ByteArray](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-byte-array/index.html)? = null, numberOfCredentials: [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-int/index.html) = 1, credentialPolicy: CreateDocumentSettings.CredentialPolicy = RotateUse, configure: AndroidKeystoreCreateKeySettings.Builder.() -&gt; [Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-unit/index.html)? = null): CreateDocumentSettings<br>Returns the default CreateDocumentSettings for the [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md) instance. The default settings are based on the [EudiWalletConfig](../../eu.europa.ec.eudi.wallet/-eudi-wallet-config/index.md) and the presence of an available AndroidKeystoreSecureArea implementation. |
21+
| [getDefaultKeyUnlockData](get-default-key-unlock-data.md) | [androidJvm]<br>suspend fun IssuedDocument.[getDefaultKeyUnlockData](get-default-key-unlock-data.md)(): AndroidKeystoreKeyUnlockData?<br>Returns the default AndroidKeystoreKeyUnlockData for the IssuedDocument. The default key unlock data is based on the IssuedDocument.findCredential<br>[androidJvm]<br>@[JvmName](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-name/index.html)(name = &quot;getDefaultKeyUnlockDataForDocument&quot;)<br>suspend fun [getDefaultKeyUnlockData](get-default-key-unlock-data.md)(document: IssuedDocument): AndroidKeystoreKeyUnlockData?<br>Returns the default AndroidKeystoreKeyUnlockData for the given IssuedDocument. The key unlock data is retrieved based on the document's associated credential.<br>[androidJvm]<br>@[JvmName](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-name/index.html)(name = &quot;getDefaultKeyUnlockData&quot;)<br>@[JvmStatic](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin.jvm/-jvm-static/index.html)<br>fun [EudiWallet](../../eu.europa.ec.eudi.wallet/-eudi-wallet/index.md).[getDefaultKeyUnlockData](get-default-key-unlock-data.md)(documentId: DocumentId): AndroidKeystoreKeyUnlockData?<br>Returns the default AndroidKeystoreKeyUnlockData for the given DocumentId. The default key unlock data is based on the Document.keyAlias of the found document. This is applicable only if the document's key requires user authentication.<br>[androidJvm]<br>fun [getDefaultKeyUnlockData](get-default-key-unlock-data.md)(secureArea: SecureArea, keyAlias: [String](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-string/index.html)): AndroidKeystoreKeyUnlockData?<br>Returns the default AndroidKeystoreKeyUnlockData for the given SecureArea and [keyAlias](get-default-key-unlock-data.md) if the [secureArea](get-default-key-unlock-data.md) is an instance of AndroidKeystoreSecureArea. |
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//[wallet-core](../../../../index.md)/[eu.europa.ec.eudi.wallet.issue.openid4vci](../../index.md)/[Offer](../index.md)/[OfferedDocument](index.md)/[batchCredentialIssuanceSize](batch-credential-issuance-size.md)
2+
3+
# batchCredentialIssuanceSize
4+
5+
[androidJvm]\
6+
val [batchCredentialIssuanceSize](batch-credential-issuance-size.md): [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin-stdlib/kotlin/-int/index.html)
7+
8+
Returns the batch credential issuance size based on the issuer metadata. If the issuer does not support batch credential issuance, returns 1.

docs/wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/-offer/-offered-document/credential-policy.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)