Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
vkanellopoulos committed Nov 6, 2023
1 parent c4d5561 commit 7d0e947
Showing 1 changed file with 109 additions and 108 deletions.
217 changes: 109 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,27 @@ object is created using the `EudiWalletConfig.Builder` class. The builder allows
the following options:

- `documentsStorageDir` method allows you to specify the directory where the documents are stored.
The default value is the application's no-backup files directory.
- `encryptDocumentsInStorage` method allows you to specify if the documents should be encrypted in
the storage.
the storage. The default value is `true`.
- `useHardwareToStoreKeys` method allows you to specify if the StrongBox Android Keystore should be
used, if available.
used, if available. The default value is `true`.
- `bleTransferMode` method allows you to specify the BLE transfer mode. The BLE transfer mode can
be one of the following:
+ `EudiWalletConfig.BLE_SERVER_PERIPHERAL_MODE` - the device will act as a BLE server
+ `EudiWalletConfig.BLE_CLIENT_CENTRAL_MODE` - the device will act as a BLE client
The default value is `EudiWalletConfig.BLE_SERVER_PERIPHERAL_MODE`.
- `bleClearCacheEnabled` method allows you to specify if the BLE cache should be cleared after the
transfer.
transfer. The default value is `false`.
- `userAuthenticationRequired` method allows you to specify if the user authentication is required
when using documents' keys.
when using documents' keys. The default value is `false`.
- `userAuthenticationTimeOut` method allows you to specify the user authentication timeout in
milliseconds. If the value is 0, the user authentication is required for every use of the key,
otherwise it's required within the given amount of milliseconds.
otherwise it's required within the given amount of milliseconds. The default value is 30000.
- `trustedReaderCertificates` method allows you to specify the list of trusted reader certificates.
- `openId4VpVerifierApiUri` method allows you to specify the verifier api uri for OpenID4VP.
The default value is an empty list.
- `openId4VpVerifierApiUri` method allows you to specify the verifier api uri for OpenID4VP. The
default value is null.

The following example shows how to initialize the library:

Expand Down Expand Up @@ -120,6 +124,13 @@ val config = EudiWalletConfig.Builder(applicationContext)
EudiWalletSDK.init(applicationContext, config)
```

To initialize the library with the default configuration, you can use the following code:

```kotlin
val config = EudiWalletConfig.Builder(applicationContext).build()
EudiWalletSDK.init(applicationContext, config)
```

Library initialization is recommended to be done in the `Application.onCreate` method.

### Manage documents
Expand Down Expand Up @@ -366,7 +377,7 @@ val transferEventListener = TransferEvent.Listener { event ->
}
is ResponseResult.Response -> {
val responseBytes = responseResult.bytes
transferManager.sendResponse(responseBytes)
EudiWalletSDK.sendResponse(responseBytes)
}
is ResponseResult.UserAuthRequired -> {
// user authentication is required. Get the crypto object from responseResult.cryptoObject
Expand All @@ -382,14 +393,14 @@ val transferEventListener = TransferEvent.Listener { event ->
is TransferEvent.Disconnected -> {
// event when the devices are disconnected
// presentation can be stopped here
transferManager.stopPresentation()
EudiWalletSDK.stopPresentation()
}
is TransferEvent.Error -> {
// event when an error occurs. Get the error from event.error
val error: Throwable = event.error
// handle error
// stop presentation
transferManager.stopPresentation()
EudiWalletSDK.stopPresentation()
}
}
}
Expand Down Expand Up @@ -535,116 +546,106 @@ EudiWalletSDK.addTransferEventListener(transferEventListener)
}
```

4. OpenID4VP

To use the OpenID4VP functionality, the configuration that is used to initialize the library
must
contain the `openId4VpVerifierApiUri`. See
the [Initialize the library](#initialize-the-library)
section.

Then, declare to your app's manifest file (AndroidManifest.xml) the following Intent Filters
for
your MainActivity:
```xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="mdoc-openid4vp" android:host="*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="${verifierHostName}" />
</intent-filter>
```
where `${verifierHostName}` is the host name of the verifier. Also
set `launchMode="singleTask"`
for this activity.
Then your MainActivity use the `EudiWalletSDK.openId4vpManager` property to get
the `OpenId4VpManager` object and use it to initiate the transfer, as shown in the example
below:
```kotlin
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import eu.europa.ec.eudi.iso18013.transfer.DisclosedDocument
import eu.europa.ec.eudi.iso18013.transfer.DisclosedDocuments
import eu.europa.ec.eudi.iso18013.transfer.ResponseResult
import eu.europa.ec.eudi.iso18013.transfer.TransferEvent
import eu.europa.ec.eudi.wallet.EudiWalletSDK
4. OpenID4VP

To use the OpenID4VP functionality, the configuration that is used to initialize the library
must contain the `openId4VpVerifierApiUri`. See
the [Initialize the library](#initialize-the-library) section.

Then, declare to your app's manifest file (AndroidManifest.xml) the following Intent Filters for
your MainActivity:
```xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="mdoc-openid4vp" android:host="*" />
</intent-filter>
```
Also set `launchMode="singleTask"` for this activity.
Then your MainActivity use the `EudiWalletSDK.openId4vpManager` property to get
the `OpenId4VpManager` object and use it to initiate the transfer, as shown in the example
below:
```kotlin
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import eu.europa.ec.eudi.iso18013.transfer.DisclosedDocument
import eu.europa.ec.eudi.iso18013.transfer.DisclosedDocuments
import eu.europa.ec.eudi.iso18013.transfer.ResponseResult
import eu.europa.ec.eudi.iso18013.transfer.TransferEvent
import eu.europa.ec.eudi.wallet.EudiWalletSDK
class MainActivity : AppCompatActivity() {
class MainActivity : AppCompatActivity() {
val transferEventListener = TransferEvent.Listener { event ->
when (event) {
is TransferEvent.RequestReceived -> {
val disclosedDocuments = DisclosedDocuments(
listOf<DisclosedDocument>(
// get disclosed documents from user
)
val transferEventListener = TransferEvent.Listener { event ->
when (event) {
is TransferEvent.RequestReceived -> {
val disclosedDocuments = DisclosedDocuments(
listOf<DisclosedDocument>(
// get disclosed documents from user
)
val result = EudiWalletSDK.createResponse(disclosedDocuments)
when (result) {
is ResponseResult.Response -> {
EudiWalletSDK.openId4vpManager.sendResponse(result.bytes)
EudiWalletSDK.openId4vpManager.close()
}
is ResponseResult.UserAuthRequired -> {
// perform user authentication
// and try send data again
}
is ResponseResult.Failure -> {
val cause = result.throwable
// handle failure
// close connection
EudiWalletSDK.openId4vpManager.close()
}
)
val result = EudiWalletSDK.createResponse(disclosedDocuments)
when (result) {
is ResponseResult.Response -> {
EudiWalletSDK.openId4vpManager.sendResponse(result.bytes)
EudiWalletSDK.openId4vpManager.close()
}
is ResponseResult.UserAuthRequired -> {
// perform user authentication
// and try send data again
}
is ResponseResult.Failure -> {
val cause = result.throwable
// handle failure
// close connection
EudiWalletSDK.openId4vpManager.close()
}
}
else -> {
// rest of event handling
}
}
else -> {
// rest of event handling
}
}
// ... rest of activity code
}
// ... rest of activity code
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
EudiWalletSDK.openId4vpManager.addTransferEventListener(transferEventListener)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
EudiWalletSDK.openId4vpManager.addTransferEventListener(transferEventListener)
}
override fun onResume() {
super.onResume()
handleOpenId4VpIntent(intent)
}
override fun onResume() {
super.onResume()
handleOpenId4VpIntent(intent)
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(null)
handleOpenId4VpIntent(intent)
}
private fun handleOpenId4VpIntent(intent: Intent) {
when (intent.scheme) {
"mdoc-openid4vp" -> EudiWalletSDK.openId4vpManager.resolveRequestUri(intent.toUri(0))
else -> {
// do nothing
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
setIntent(null)
handleOpenId4VpIntent(intent)
}
private fun handleOpenId4VpIntent(intent: Intent) {
when (intent.scheme) {
"mdoc-openid4vp" -> EudiWalletSDK.openId4vpManager.resolveRequestUri(intent.toUri(0))
else -> {
// do nothing
}
}
}
```
}
}
```
#### Receiving request and sending response
When a request is received, the `TransferEvent.RequestReceived` event is triggered. The request can
Expand Down

0 comments on commit 7d0e947

Please sign in to comment.