Skip to content

Commit

Permalink
update tezos support
Browse files Browse the repository at this point in the history
  • Loading branch information
hvthhien committed Jan 7, 2022
1 parent ad85b46 commit 8aeb50f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {

defaultConfig {
applicationId "com.bitmark.libauk_example"
minSdkVersion 23
minSdkVersion 24
targetSdkVersion 31
versionCode 1
versionName "1.0"
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ buildscript {
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.2"
Expand All @@ -18,6 +19,7 @@ allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
3 changes: 2 additions & 1 deletion libauk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {
buildToolsVersion "30.0.2"

defaultConfig {
minSdkVersion 23
minSdkVersion 24
targetSdkVersion 31
versionCode 1
versionName "1.0"
Expand Down Expand Up @@ -41,6 +41,7 @@ dependencies {
implementation 'org.web3j:core:4.8.7-android'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
implementation 'io.camlcase:kotlintezos:2.0.2'
testImplementation 'junit:junit:4.13.1'
testImplementation 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
10 changes: 10 additions & 0 deletions libauk/src/main/java/com/bitmark/libauk/storage/WalletStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.bitmark.libauk.model.KeyInfo
import com.bitmark.libauk.model.Seed
import com.bitmark.libauk.util.fromJson
import com.bitmark.libauk.util.newGsonInstance
import io.camlcase.kotlintezos.wallet.HDWallet
import io.reactivex.Completable
import io.reactivex.Single
import org.web3j.crypto.*
Expand All @@ -21,6 +22,7 @@ interface WalletStorage {
fun signPersonalMessage(message: ByteArray): Single<Sign.SignatureData>
fun signTransaction(transaction: RawTransaction, chainId: Long): Single<ByteArray>
fun exportMnemonicWords(): Single<String>
fun getTezosWallet(): Single<HDWallet>
fun removeKeys(): Completable
}

Expand Down Expand Up @@ -149,6 +151,14 @@ internal class WalletStorageImpl(private val secureFileStorage: SecureFileStorag
MnemonicUtils.generateMnemonic(seed.data)
}

override fun getTezosWallet(): Single<HDWallet> = secureFileStorage.rxSingle { storage ->
val json = storage.readOnFilesDir(SEED_FILE_NAME)
val seed = newGsonInstance().fromJson<Seed>(String(json))
MnemonicUtils.generateMnemonic(seed.data)
}.map {
HDWallet(it.split(" "))
}

override fun removeKeys(): Completable = secureFileStorage.rxSingle { storage ->
storage.isExisting(SEED_FILE_NAME) && storage.isExisting(ETH_KEY_INFO_FILE_NAME)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import com.bitmark.libauk.util.newGsonInstance
import com.nhaarman.mockitokotlin2.*
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.web3j.crypto.MnemonicUtils
import org.web3j.crypto.RawTransaction
import java.math.BigInteger
import java.util.*

class WalletStorageTest {
class WalletStorageUnitTest {

private lateinit var walletStorage: WalletStorage
private val secureFileStorage: SecureFileStorage = mock()
Expand Down Expand Up @@ -171,6 +172,24 @@ class WalletStorageTest {
)
}

// @Test
// fun getTezosWallet() {
// val words = "victory fatigue diet funny senior coral motion canal leg elite hen model"
// val entropy = MnemonicUtils.generateEntropy(words)
// val seed = Seed(entropy, Date(), "Test")
// val seedString = newGsonInstance().toJson(seed)
//
// given(secureFileStorage.readOnFilesDir(WalletStorageImpl.SEED_FILE_NAME)).willReturn(
// seedString.toByteArray()
// )
//
// walletStorage.getTezosWallet()
// .test()
// .assertValue {
// it.mainAddress == "tz10000"
// }
// }

@Test
fun removeKeys() {
given(secureFileStorage.isExisting(WalletStorageImpl.SEED_FILE_NAME)).willReturn(
Expand Down

0 comments on commit 8aeb50f

Please sign in to comment.