Skip to content

Commit

Permalink
move logging and ktorHttpClientFactory config to EudiWalletConfig; cr…
Browse files Browse the repository at this point in the history
…eate Logger class; Logger and ktorHttpClientFactory will be use in both OpenId4VciManager and OpenId4vpManager
  • Loading branch information
vkanellopoulos committed Jun 25, 2024
1 parent c9b11a1 commit 6055e69
Show file tree
Hide file tree
Showing 88 changed files with 1,200 additions and 668 deletions.
92 changes: 61 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,17 @@ The following example shows how to initialize the library:

import eu.europa.ec.eudi.wallet.EudiWallet
import eu.europa.ec.eudi.wallet.EudiWalletConfig
import eu.europa.ec.eudi.wallet.Logger
import java.security.cert.X509Certificate

val storageDir = applicationContext.noBackupFilesDir
val verifierApiUri = "https://verifier-api-uri"
val config = EudiWalletConfig.Builder(applicationContext)
.logLevel(Logger.LEVEL_DEBUG)
.ktorHttpClientFactory {
// provide your own Ktor HttpClient
// this will be used for OpenId4VCI and OpenId4VP communication
}
.bleTransferMode(
EudiWalletConfig.BLE_SERVER_PERIPHERAL_MODE,
EudiWalletConfig.BLE_CLIENT_CENTRAL_MODE
Expand Down Expand Up @@ -201,7 +207,6 @@ val config = EudiWalletConfig.Builder(applicationContext)
useDPoP(false)
parUsage(ParUsage.IF_SUPPORTED)
proofTypes(Config.ProofType.JWT, Config.ProofType.CWT)
debugLogging(LogLevel.DEBUG)
}
.build()

Expand All @@ -219,26 +224,22 @@ Library initialization is recommended to be done in the `Application.onCreate` m

### Manage documents

Document is a data structure that contains the following information:

- `id` document's unique identifier
- `docType` document's docType (example: "eu.europa.ec.eudiw.pid.1")
- `name` document's name. This is a human readable name.
- `hardwareBacked` document's storage is hardware backed
- `createdAt` document's creation date
- `requiresUserAuth` flag that indicates if the document requires user authentication to be accessed
- `nameSpacedData` retrieves the document's data, grouped by nameSpace. Values are in CBOR bytes

The library provides a set of methods to work with documents.

#### Listing documents

The `EudiWallet.getDocuments` method that returns the list of documents stored in the library.

The following example shows how to list documents:
The following example shows how to list issued documents:

```kotlin
val documents: List<IssuedDocument> = EudiWallet.getDocuments()
```

To list all documents, including unsigned and deferred, use the following code:

```kotlin
val documents = EudiWallet.getDocuments()
val documents: List<Document> = EudiWallet.getAllDocuments()
```

#### Retrieving a document
Expand Down Expand Up @@ -273,49 +274,78 @@ when (result) {

#### Issuing/Adding a document

Adding a document is a two-step process. First, you need to create an issuanceRequest using the
method `EudiWallet.createIssuanceRequest`. The issuanceRequest holds the public certificate
Adding a document is a two-step process. First, you need to create an unsigned document using the
method `EudiWallet.createDocument`. The unsigned document holds the public certificate
that will be used from the issuer to sign the document.

Later, when document's data is available, you can create the document using the
method `EudiWallet.addDocument` to add the document to document storage.
method `EudiWallet.storeIssuedDocument` to add the document to document storage.

The following example shows how to add a document:

```kotlin
val docType = "eu.europa.ec.eudiw.pid.1"
val docType = "eu.europa.ec.eudi.pid.1"
val hardwareBacked = false
val attestationChallenge = byteArrayOf(
// attestation challenge bytes
// provided by the issuer
)
val requestResult =
EudiWallet.createIssuanceRequest(docType, hardwareBacked, attestationChallenge)
when (requestResult) {
val result = EudiWallet.createDocument(docType, hardwareBacked, attestationChallenge)
when (result) {
is CreateIssuanceRequestResult.Failure -> {
val error = requestResult.throwable
// handle error while creating issuance request
val error = result.throwable
// handle error
}

is CreateIssuanceRequestResult.Success -> {
val request = requestResult.issuanceRequest
val docType = request.docType
val unsignedDocument = result.issuanceRequest
val docType = unsignedDocument.docType
// the device certificate that will be used in the signing of the document
// from the issuer while creating the MSO (Mobile Security Object)
val certificateNeedAuth = request.certificateNeedAuth
val certificateNeedAuth = unsignedDocument.certificateNeedAuth
// or
val publicKey = unsignedDocument.publicKey

// if the issuer requires the user to prove possession of the private key corresponding to the certificateNeedAuth
// then user can use the method below to sign issuer's data and send the signature to the issuer
val signingInputFromIssuer = byteArrayOf(
// signing input bytes from the issuer
// provided by the issuer
)
val signatureResult = unsignedDocument.signWithAuthKey(signingInputFromIssuer)
when (signatureResult) {
is SignedWithAuthKeyResult.Success -> {
val signature = signatureResult.signature
// signature for the issuer
}
is SignedWithAuthKeyResult.Failure -> {
val error = signatureResult.throwable
// handle error while signing with auth key
}
is SignedWithAuthKeyResult.UserAuthRequired -> {
// user authentication is required to sign with auth key
val cryptoObject = signatureResult.cryptoObject
// use cryptoObject to authenticate the user
// after user authentication, the user can sign with auth key again
}
}

// ... code that sends certificate to issuer and receives document's data
// ... code that sends docType and certificates to issuer and signature if required

val issuerData: ByteArray = byteArrayOf() // CBOR bytes received from issuer
// after receiving the MSO from the issuer, the user can start the issuance process
val issuerData: ByteArray = byteArrayOf(
// CBOR bytes of the document
)

val addResult = EudiWallet.addDocument(request, issuerData)
val storeResult = EudiWallet.storeIssuedDocument(unsignedDocument, issuerData)

when (addResult) {
when (storeResult) {
is AddDocumentResult.Failure -> {
val error = addResult.throwable
val error = storeResult.throwable
// handle error while adding document
}
is AddDocumentResult.Success -> {
val documentId = addResult.documentId
val documentId = storeResult.documentId
// the documentId of the newly added document
// use the documentId to retrieve the document
documentManager.getDocumentById(documentId)
Expand Down
13 changes: 7 additions & 6 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

## Packages

| Name |
|---|
| [eu.europa.ec.eudi.wallet](wallet-core/eu.europa.ec.eudi.wallet/index.md) |
| [eu.europa.ec.eudi.wallet.document](wallet-core/eu.europa.ec.eudi.wallet.document/index.md) |
| [eu.europa.ec.eudi.wallet.issue.openid4vci](wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/index.md) |
| Name |
|-----------------------------------------------------------------------------------------------------------------|
| [eu.europa.ec.eudi.wallet](wallet-core/eu.europa.ec.eudi.wallet/index.md) |
| [eu.europa.ec.eudi.wallet.document](wallet-core/eu.europa.ec.eudi.wallet.document/index.md) |
| [eu.europa.ec.eudi.wallet.issue.openid4vci](wallet-core/eu.europa.ec.eudi.wallet.issue.openid4vci/index.md) |
| [eu.europa.ec.eudi.wallet.logging](wallet-core/eu.europa.ec.eudi.wallet.logging/index.md) |
| [eu.europa.ec.eudi.wallet.transfer.openid4vp](wallet-core/eu.europa.ec.eudi.wallet.transfer.openid4vp/index.md) |
| [eu.europa.ec.eudi.wallet.util](wallet-core/eu.europa.ec.eudi.wallet.util/index.md) |
| [eu.europa.ec.eudi.wallet.util](wallet-core/eu.europa.ec.eudi.wallet.util/index.md) |
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ androidJvm

## Functions

| Name | Summary |
|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [build](build.md) | [androidJvm]<br>fun [build](build.md)(): [OpenId4VciManager](../index.md)<br>Build the [OpenId4VciManager](../index.md) |
| [config](config.md) | [androidJvm]<br>fun [config](config.md)(config: [OpenId4VciManager.Config](../-config/index.md)): [OpenId4VciManager.Builder](index.md)<br>Set the [Config](../-config/index.md) to use |
| [documentManager](document-manager.md) | [androidJvm]<br>fun [documentManager](document-manager.md)(documentManager: DocumentManager): [OpenId4VciManager.Builder](index.md)<br>Set the DocumentManager to use |
| Name | Summary |
|--------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [build](build.md) | [androidJvm]<br>fun [build](build.md)(): [OpenId4VciManager](../index.md)<br>Build the [OpenId4VciManager](../index.md) |
| [config](config.md) | [androidJvm]<br>fun [config](config.md)(config: [OpenId4VciManager.Config](../-config/index.md)): [OpenId4VciManager.Builder](index.md)<br>Set the [Config](../-config/index.md) to use |
| [documentManager](document-manager.md) | [androidJvm]<br>fun [documentManager](document-manager.md)(documentManager: DocumentManager): [OpenId4VciManager.Builder](index.md)<br>Set the DocumentManager to use |
| [ktHttpClientFactory](kt-http-client-factory.md) | [androidJvm]<br>fun [ktHttpClientFactory](kt-http-client-factory.md)(factory: () -&gt; HttpClient): [OpenId4VciManager.Builder](index.md)<br>Override the Ktor HTTP client factory |
| [logger](logger.md) | [androidJvm]<br>fun [logger](logger.md)(logger: [Logger](../../../eu.europa.ec.eudi.wallet.logging/-logger/index.md)): [OpenId4VciManager.Builder](index.md) |

## Properties

| Name | Summary |
|----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| [config](config.md) | [androidJvm]<br>var [config](config.md): [OpenId4VciManager.Config](../-config/index.md)?<br>the [Config](../-config/index.md) to use |
| [documentManager](document-manager.md) | [androidJvm]<br>var [documentManager](document-manager.md): DocumentManager?<br>the DocumentManager to use requires user authentication |
| Name | Summary |
|------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| [config](config.md) | [androidJvm]<br>var [config](config.md): [OpenId4VciManager.Config](../-config/index.md)?<br>the [Config](../-config/index.md) to use |
| [documentManager](document-manager.md) | [androidJvm]<br>var [documentManager](document-manager.md): DocumentManager?<br>the DocumentManager to use requires user authentication |
| [ktorHttpClientFactory](ktor-http-client-factory.md) | [androidJvm]<br>var [ktorHttpClientFactory](ktor-http-client-factory.md): () -&gt; HttpClient? |
| [logger](logger.md) | [androidJvm]<br>var [logger](logger.md): [Logger](../../../eu.europa.ec.eudi.wallet.logging/-logger/index.md)? |
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//[wallet-core](../../../../index.md)/[eu.europa.ec.eudi.wallet.issue.openid4vci](../../index.md)/[OpenId4VciManager](../index.md)/[Builder](index.md)/[ktHttpClientFactory](kt-http-client-factory.md)

# ktHttpClientFactory

[androidJvm]\
fun [ktHttpClientFactory](kt-http-client-factory.md)(factory: () -&gt;
HttpClient): [OpenId4VciManager.Builder](index.md)

Override the Ktor HTTP client factory
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//[wallet-core](../../../../index.md)/[eu.europa.ec.eudi.wallet.issue.openid4vci](../../index.md)/[OpenId4VciManager](../index.md)/[Config](index.md)/[ktorHttpClientFactory](ktor-http-client-factory.md)
//[wallet-core](../../../../index.md)/[eu.europa.ec.eudi.wallet.issue.openid4vci](../../index.md)/[OpenId4VciManager](../index.md)/[Builder](index.md)/[ktorHttpClientFactory](ktor-http-client-factory.md)

# ktorHttpClientFactory

[androidJvm]\
val [ktorHttpClientFactory](ktor-http-client-factory.md): () -&gt; HttpClient
var [ktorHttpClientFactory](ktor-http-client-factory.md): () -&gt; HttpClient?
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//[wallet-core](../../../../index.md)/[eu.europa.ec.eudi.wallet.issue.openid4vci](../../index.md)/[OpenId4VciManager](../index.md)/[Builder](index.md)/[logger](logger.md)

# logger

[androidJvm]\
fun [logger](logger.md)(
logger: [Logger](../../../eu.europa.ec.eudi.wallet.logging/-logger/index.md)): [OpenId4VciManager.Builder](index.md)

var [logger](logger.md): [Logger](../../../eu.europa.ec.eudi.wallet.logging/-logger/index.md)?

This file was deleted.

Loading

0 comments on commit 6055e69

Please sign in to comment.