-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:leecam/CMWallet into main
- Loading branch information
Showing
13 changed files
with
224 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"format": "mso_mdoc", | ||
"credential": { | ||
"docType": "org.iso.18013.5.1.mDL", | ||
"nameSpaces": { | ||
"org.iso.18013.5.1": { | ||
"family_name": { | ||
"value": "James", | ||
"display": "Family Name", | ||
"display_value": "Bond" | ||
}, | ||
"given_name": { | ||
"value": "Jon", | ||
"display": "Given Name", | ||
"display_value": "Jon" | ||
}, | ||
"age_over_21": { | ||
"value": true, | ||
"display": "Age Over 21", | ||
"display_value": "True" | ||
} | ||
} | ||
} | ||
}, | ||
"metadata": { | ||
"verification": { | ||
"title": "James Bond's Driving License", | ||
"subtitle": "Gotham City DMV" | ||
} | ||
}, | ||
"deviceKey": "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgkAHk14S-CcPohE9v9rsVV8j7KRxrEqYYp1XuidZD2b6hRANCAAR07xfD2-9IWUn1YLsl3r0D-Nnx9toOLnhf3aMhuQmbGgxMzD6Kl_nY_UykJ-qdykIqCacRdWEGu42EotRizdWF", | ||
"issuerSigned": "ompuYW1lU3BhY2VzoXFvcmcuaXNvLjE4MDEzLjUuMYPYGFhUpGhkaWdlc3RJRABmcmFuZG9tUKRsGD3aPLpwu_wGZyvuvdxxZWxlbWVudElkZW50aWZpZXJrZmFtaWx5X25hbWVsZWxlbWVudFZhbHVlZVNtaXRo2BhYUaRoZGlnZXN0S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obWdTSEEtMjU2Z2RvY1R5cGV1b3JnLmlzby4xODAxMy41LjEubURMbHZhbHVlRGlnZXN0c6Fxb3JnLmlzby4xODAxMy41LjGjAFgg-TGk78sfX6xxEfdjckEmDSfiVWzOGIIwTqm0oQetoR8BWCAcX3iJNwCyYOy1Bfl9sAjv1lEuD7iXI5dJbkwPUB6-RwJYIGFOQ5HGtkmhrJWuJ6eTdM2PC_lAIDR5_9pWUiRogpWwbWRldmljZUtleUluZm-haWRldmljZUtleaQBAiABIVggdO8Xw9vvSFlJ9WC7Jd69A_jZ8fbaDi54X92jIbkJmxoiWCAMTMw-ipf52P1MpCfqncpCKgmnEXVhBruNhKLUYs3VhWx2YWxpZGl0eUluZm-jZnNpZ25lZMB4GzIwMjQtMTEtMTdUMjA6NTI6MjIuOTE5NzgyWml2YWxpZEZyb23AeBsyMDI0LTExLTE3VDIwOjUyOjIyLjkxOTc4OVpqdmFsaWRVbnRpbMB4GzIwMzQtMTEtMDVUMjA6NTI6MjIuOTE5Nzg5WlhAl1Lt2d0SSsbuMizlTkVeLR7wucamVyUhyHm6PdG1W0YWXIxfLGwP0rG7Zhpuomh5kpItM7lRdR_FdkJHXO81MQ==" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
app/src/main/java/com/credman/cmwallet/data/room/Credential.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.credman.cmwallet.data.room | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.credman.cmwallet.data.model.CredentialItem | ||
import org.json.JSONObject | ||
|
||
@Entity | ||
data class Credential( | ||
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = "id") val id: Long = 0, | ||
@ColumnInfo(name = "credJson") val credJson: String, | ||
) { | ||
fun toCredentialItem(): CredentialItem = CredentialItem( | ||
id = id.toString(), | ||
json = JSONObject(credJson), | ||
) | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/credman/cmwallet/data/room/CredentialDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.credman.cmwallet.data.room | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import androidx.room.Update | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
@Dao | ||
interface CredentialDao { | ||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertAll(vararg creds: Credential) | ||
|
||
@Update | ||
suspend fun updateUsers(vararg creds: Credential) | ||
|
||
@Delete | ||
suspend fun delete(cred: Credential) | ||
|
||
@Query("SELECT * FROM credential") | ||
fun getAll(): Flow<List<Credential>> | ||
|
||
@Query("SELECT * FROM credential WHERE id = :id") | ||
fun loadCredById(id: Long): Credential? | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/credman/cmwallet/data/room/CredentialDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.credman.cmwallet.data.room | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
|
||
@Database(entities = [Credential::class], version = 1) | ||
abstract class CredentialDatabase : RoomDatabase() { | ||
abstract fun credentialDao(): CredentialDao | ||
} |
27 changes: 21 additions & 6 deletions
27
app/src/main/java/com/credman/cmwallet/data/source/CredentialDatabaseDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
package com.credman.cmwallet.data.source | ||
|
||
import android.util.Log | ||
import com.credman.cmwallet.CmWalletApplication | ||
import com.credman.cmwallet.data.model.CredentialItem | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.transform | ||
|
||
class CredentialDatabaseDataSource { | ||
val credentialDao = CmWalletApplication | ||
.database | ||
.credentialDao() | ||
|
||
// TODO: Make this a Room database, for now just return an empty list | ||
private val _credentials = MutableStateFlow(emptyList<CredentialItem>()) | ||
val credentials: StateFlow<List<CredentialItem>> = _credentials.asStateFlow() | ||
val credentials: Flow<List<CredentialItem>> = credentialDao | ||
.getAll() | ||
.transform { list -> | ||
emit(list.map { it.toCredentialItem() }) | ||
} | ||
|
||
fun getCredential(id: String): CredentialItem? { | ||
return try { | ||
credentialDao.loadCredById(id.toLong())?.toCredentialItem() | ||
} catch (e: Exception) { | ||
Log.e(CmWalletApplication.TAG, "database retrieval error", e) | ||
null | ||
} | ||
} | ||
} |
Oops, something went wrong.