Skip to content

Commit

Permalink
update muliple personas support
Browse files Browse the repository at this point in the history
  • Loading branch information
hvthhien committed Nov 22, 2021
1 parent 3a26167 commit ad85b46
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 87 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}

buildTypes {
release {
minifyEnabled false
Expand Down
2 changes: 1 addition & 1 deletion libauk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'org.web3j:core:4.8.7-android'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
testImplementation 'junit:junit:4.13.1'
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import androidx.test.platform.app.InstrumentationRegistry
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.util.*

class SecureFileStorageTest {

private val appContext = InstrumentationRegistry.getInstrumentation().targetContext

private lateinit var filePrefix: String
private val secureFileStorage = SecureFileStorageImpl(appContext)
private val secureFileStorage = SecureFileStorageImpl(appContext, UUID.randomUUID())

@Before
fun beforeEach() {
Expand Down
19 changes: 9 additions & 10 deletions libauk/src/main/java/com/bitmark/libauk/LibAuk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import android.content.Context
import com.bitmark.libauk.storage.SecureFileStorageImpl
import com.bitmark.libauk.storage.WalletStorage
import com.bitmark.libauk.storage.WalletStorageImpl
import java.util.*

class LibAuk constructor(context: Context) {

val wallet: WalletStorage

init {
val storage = SecureFileStorageImpl(context)
wallet = WalletStorageImpl(storage)
}
class LibAuk {

companion object {
@Volatile
private var INSTANCE: LibAuk? = null

@Synchronized
fun getInstance(context: Context): LibAuk =
INSTANCE ?: LibAuk(context).also { INSTANCE = it }
fun getInstance(): LibAuk =
INSTANCE ?: LibAuk().also { INSTANCE = it }
}

fun getStorage(uuid: UUID, context: Context): WalletStorage {
val storage = SecureFileStorageImpl(context, uuid)
return WalletStorageImpl(storage)
}
}
16 changes: 15 additions & 1 deletion libauk/src/main/java/com/bitmark/libauk/model/Seed.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package com.bitmark.libauk.model

import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName
import java.util.*

class Seed(val data: ByteArray, val creationDate: Date?, var name: String)
class Seed(
@Expose
@SerializedName("data")
val data: ByteArray,

@Expose
@SerializedName("creationDate")
val creationDate: Date?,

@Expose
@SerializedName("name")
var name: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.reactivex.Completable
import io.reactivex.Single
import java.io.ByteArrayOutputStream
import java.io.File
import java.util.*

internal interface SecureFileStorage {
fun write(path: String, name: String, data: ByteArray)
Expand All @@ -26,11 +27,7 @@ internal interface SecureFileStorage {
fun deleteOnFilesDir(name: String): Boolean
}

internal class SecureFileStorageImpl constructor(private val context: Context) : SecureFileStorage {

companion object {
const val SECURE_FILE_KEY_ALIAS = "secure_file_key_set_alias"
}
internal class SecureFileStorageImpl constructor(private val context: Context, private val alias: UUID) : SecureFileStorage {

private val masterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
Expand Down Expand Up @@ -97,7 +94,7 @@ internal class SecureFileStorageImpl constructor(private val context: Context) :
f,
masterKey,
EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).setKeysetAlias(SECURE_FILE_KEY_ALIAS)
).setKeysetAlias(alias.toString())
}

internal fun <T> SecureFileStorage.rxSingle(action: (SecureFileStorage) -> T) =
Expand Down
Loading

0 comments on commit ad85b46

Please sign in to comment.