Skip to content

Commit

Permalink
Merge branch 'release/0.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Sep 19, 2019
2 parents e306350 + 472b69a commit f5758b2
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 48 deletions.
7 changes: 6 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ encryption backed by ARM Trusted Execution Environment (TEE).
Note: The curve used for ETH signing is not backed by the TEE,
therefore private keys exist in memory while in use but are encrypted with TEE keys at rest.

[FAQ and helpdesk support](http://bit.ly/uPort_helpdesk)

### Import

in your main `build.gradle`:
Expand All @@ -28,7 +30,7 @@ allprojects {
```
in your app `build.gradle`:
```groovy
uport_signer_version = "0.3.3"
uport_signer_version = "0.3.4"
dependencies {
//...
implementation "com.github.uport-project:uport-android-signer:$uport_signer_version"
Expand Down Expand Up @@ -157,6 +159,9 @@ UportHDSigner().signJwtBundle(activity, seedHandle, derivationPath, data, prompt

### Changelog

#### 0.3.4
* [support] upgrade to kethereum 0.76.1 (#19)

#### 0.3.3
* [bugfix] erratic `UserNotAuthenticatedException` when using `prompt` with pattern keyguard (#18)

Expand Down
18 changes: 7 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
buildscript {
ext {
kotlin_version = "1.3.41"
android_tools_version = '3.4.1'
coroutines_version = "1.2.2"
kotlin_version = "1.3.50"
android_tools_version = '3.5.0'
coroutines_version = "1.3.0"

build_tools_version = "28.0.3"

Expand All @@ -23,11 +23,12 @@ buildscript {
detekt_version = "1.0.0-RC14"

spongycastle_version = "1.58.0.0"
kethereum_version = "0.75.1"
kotlin_common_version = "0.1.2"
kethereum_version = "0.76.1"
khex_version = "1.0.0-RC3"
kotlin_common_version = "0.3.1"
jacoco_version = "0.8.4"

current_release_version = "0.3.3"
current_release_version = "0.3.4"
}

repositories {
Expand Down Expand Up @@ -111,11 +112,6 @@ subprojects { subproject ->

if (subproject.plugins.hasPlugin("com.android.application") || subproject.plugins.hasPlugin("com.android.library")) {
subproject.android {
packagingOptions {
exclude "META-INF/main.kotlin_module"
exclude "META-INF/atomicfu.kotlin_module"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand Down
15 changes: 14 additions & 1 deletion demoapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ android {
minifyEnabled true
shrinkResources true
zipAlignEnabled true
useProguard true

signingConfig signingConfigs.debug

proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}

packagingOptions {
pickFirst "META-INF/main.kotlin_module"
pickFirst "META-INF/atomicfu.kotlin_module"
pickFirst "META-INF/kotlinx-io.kotlin_module"
pickFirst "META-INF/extensions.kotlin_module"
pickFirst "META-INF/core.kotlin_module"
}
}

dependencies {
Expand All @@ -55,6 +62,12 @@ dependencies {
// implementation "com.github.uport-project:uport-android-signer:$current_release_version"
implementation project(":signer")

//used to generate and encode seeds to demonstrate importing them
implementation "com.github.uport-project.kotlin-common:core:$kotlin_common_version"
implementation "com.github.komputing.KHex:extensions-jvm:$khex_version"
implementation "com.github.komputing.KEthereum:bip39:$kethereum_version"
implementation "com.github.komputing.KEthereum:bip39_wordlist_en:$kethereum_version"

implementation "com.android.support.constraint:constraint-layout:$constraint_layout_version"

testImplementation("junit:junit:$junit_version")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.android.synthetic.main.content_create_keys.*
import me.uport.sdk.core.decodeBase64
import org.kethereum.bip39.generateMnemonic
import org.kethereum.bip39.wordlists.WORDLIST_ENGLISH
import org.walleth.khex.toHexString
import org.komputing.khex.extensions.toHexString


class CreateKeysActivity : AppCompatActivity() {
Expand All @@ -26,9 +26,9 @@ class CreateKeysActivity : AppCompatActivity() {
mnemonicPhraseField.setText(phrase)
}

importButton.setOnClickListener { _ ->
importButton.setOnClickListener { view ->
val phrase = mnemonicPhraseField.text.toString()
UportHDSigner().importHDSeed(this, KeyProtection.Level.SIMPLE, phrase) { err, address, publicKey ->
UportHDSigner().importHDSeed(view.context, KeyProtection.Level.SIMPLE, phrase) { err, address, publicKey ->
errorField.text = "error: ${err.toString()}"
publicKeyField.text = "publicKey: ${publicKey.decodeBase64().toHexString()}"
addressField.text = "address: $address"
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ org.gradle.jvmargs=-Xmx1536m
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
kotlin.code.style=official
kotlin.incremental=true
kotlin.incremental=true

android.enableR8=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-all.zip
28 changes: 21 additions & 7 deletions signer/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.time.temporal.TemporalAdjusters

apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "com.github.dcendents.android-maven"
Expand Down Expand Up @@ -39,29 +41,41 @@ android {
// execution "ANDROID_TEST_ORCHESTRATOR"
}

}
packagingOptions {
exclude "META-INF/main.kotlin_module"
exclude "META-INF/atomicfu.kotlin_module"
exclude "META-INF/kotlinx-io.kotlin_module"
exclude "META-INF/extensions.kotlin_module"
exclude "META-INF/core.kotlin_module"
}

//XXX: this is needed until https://github.com/komputing/KEthereum/issues/65 is fixed
configurations.all {
exclude group: "com.github.walleth"
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation "com.android.support:appcompat-v7:$support_lib_version"

api "com.github.komputing.KEthereum:bip39:$kethereum_version"
api "com.github.komputing.KEthereum:bip32:$kethereum_version"
api "com.github.komputing.KEthereum:bip39_wordlist_en:$kethereum_version"
implementation "com.github.komputing.KEthereum:bip39:$kethereum_version"
implementation "com.github.komputing.KEthereum:bip32:$kethereum_version"
implementation "com.github.komputing.KEthereum:bip39_wordlist_en:$kethereum_version"

api "com.github.komputing.KEthereum:model:$kethereum_version"

implementation "com.github.komputing.KEthereum:crypto:$kethereum_version"
implementation "com.github.komputing.KEthereum:extensions:$kethereum_version"
implementation "com.github.komputing.KEthereum:hashes:$kethereum_version"
api "com.github.uport-project.kotlin-common:signer-common:$kotlin_common_version"
implementation "com.github.uport-project.kotlin-common:core:$kotlin_common_version"
implementation "com.madgag.spongycastle:prov:$spongycastle_version"

androidTestImplementation "com.android.support.test:runner:$test_runner_version"
androidTestImplementation "com.android.support.test:rules:$test_rules_version"
androidTestImplementation "com.willowtreeapps.assertk:assertk-jvm:$assertk_version"
androidTestImplementation "com.github.uport-project.kotlin-common:test-helpers:$kotlin_common_version"
androidTestImplementation "com.github.komputing.KHex:extensions-jvm:$khex_version"

testImplementation "com.willowtreeapps.assertk:assertk-jvm:$assertk_version"
testImplementation "com.github.komputing.KEthereum:bip44:$kethereum_version"
testImplementation "com.github.komputing.KHex:extensions-jvm:$khex_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import org.kethereum.bip32.toKey
import org.kethereum.bip39.model.MnemonicWords
import org.kethereum.bip39.toSeed
import org.kethereum.extensions.hexToBigInteger
import org.komputing.khex.extensions.hexToByteArray
import org.spongycastle.jce.provider.BouncyCastleProvider
import org.walleth.khex.hexToByteArray
import java.security.Security
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import org.kethereum.crypto.signMessage
import org.kethereum.crypto.toECKeyPair
import org.kethereum.extensions.hexToBigInteger
import org.kethereum.model.PrivateKey
import org.komputing.khex.extensions.hexToByteArray
import org.komputing.khex.extensions.toNoPrefixHexString
import org.spongycastle.util.encoders.Hex
import org.walleth.khex.hexToByteArray
import org.walleth.khex.toNoPrefixHexString
import java.math.BigInteger
import java.util.*
import java.util.concurrent.CountDownLatch
Expand Down Expand Up @@ -185,6 +185,7 @@ class SignerTests {
assertEquals(referenceSignature, sigData)
}

@Suppress("DEPRECATION")
@Test
fun testJwtDer() {
val referencePrivateKey = "5047c789919e943c559d8c134091d47b4642122ba0111dfa842ef6edefb48f38"
Expand Down
2 changes: 1 addition & 1 deletion signer/src/main/java/com/uport/sdk/signer/UportSigner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ open class UportSigner {

data class EncryptionCombo(val keyProtection: KeyProtection, val encPayload: String, val err: Exception?)

internal val EMPTY_SIGNATURE_DATA = SignatureData(BigInteger.ZERO, BigInteger.ZERO, 0)
internal val EMPTY_SIGNATURE_DATA = SignatureData(BigInteger.ZERO, BigInteger.ZERO, BigInteger.ZERO)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package com.uport.sdk.signer.crypto.bip32
import org.junit.Assert.assertEquals
import org.junit.Test
import org.kethereum.bip32.model.Seed
import org.kethereum.bip32.model.XPriv
import org.kethereum.bip32.toExtendedKey
import org.kethereum.bip32.toKey
import org.walleth.khex.hexToByteArray
import org.komputing.khex.extensions.hexToByteArray

class DerivationTest {

Expand All @@ -18,15 +16,12 @@ class DerivationTest {

val derivedKey = Seed(it.seed.hexToByteArray()).toKey(it.path)

val obtainedPub = derivedKey.asPublicOnly().serialize()
val obtainedPub = derivedKey.serialize(publicKeyOnly = true)
assertEquals(it.expectedPublicKey, obtainedPub)

val obtainedPrv = derivedKey.serialize()
assertEquals(it.expectedPrivateKey, obtainedPrv)

assertEquals(XPriv(it.expectedPublicKey).toExtendedKey(), derivedKey.asPublicOnly())
assertEquals(XPriv(it.expectedPrivateKey).toExtendedKey(), derivedKey)

counter++

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.kethereum.bip32.generateChildKey
import org.kethereum.bip32.model.ExtendedKey
import org.kethereum.bip32.model.Seed
import org.kethereum.bip32.toExtendedKey
import org.kethereum.bip44.BIP44Element
import org.kethereum.model.ECKeyPair
import org.kethereum.model.PrivateKey
import org.komputing.khex.extensions.hexToByteArray
import org.spongycastle.jce.provider.BouncyCastleProvider
import org.walleth.khex.hexToByteArray
import java.math.BigInteger
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.security.Security
Expand All @@ -39,7 +35,7 @@ class ExtendedKeyTest {
val seed = "000102030405060708090a0b0c0d0e0f".hexToByteArray()
val expectedExtendedPublicKey = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8"
val key = Seed(seed).toExtendedKey(true)
val encoded = key.serialize()
val encoded = key.serialize(publicKeyOnly = true)
assertEquals(expectedExtendedPublicKey, encoded)
}

Expand All @@ -54,6 +50,23 @@ class ExtendedKeyTest {
assertEquals(expectedExtendedPrivateKey, encoded)
}

@Test
fun `derive non hardened public vs private`() {
val seed = "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542".hexToByteArray()
val expectedExtendedPublicKey = "xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH"
val extendedPriv = Seed(seed).toExtendedKey()
val extendedPub = Seed(seed).toExtendedKey(publicKeyOnly = true)

val childPriv = extendedPriv.generateChildKey(BIP44Element(false, 0))
val childPub = extendedPub.generateChildKey(BIP44Element(false, 0))

val encodedPriv = childPriv.serialize(publicKeyOnly = true)
val encodedPub = childPub.serialize(publicKeyOnly = true)

assertEquals(encodedPub, encodedPriv)
assertEquals(expectedExtendedPublicKey, encodedPub)
}

@Test
fun createNonHardenedChildPublicKey() {
//Chain m/0
Expand All @@ -62,7 +75,7 @@ class ExtendedKeyTest {
val key = Seed(seed).toExtendedKey(true)

val child = key.generateChildKey(BIP44Element(false, 0))
val encoded = child.serialize()
val encoded = child.serialize(publicKeyOnly = true)
assertEquals(expectedExtendedPublicKey, encoded)
}

Expand Down Expand Up @@ -96,9 +109,8 @@ class ExtendedKeyTest {

val child1 = master.generateChildKey(BIP44Element(false, 0))
val child2 = child1.generateChildKey(BIP44Element(true, 2147483647))
.asPublicOnly()

val result = child2.serialize()
val result = child2.serialize(true)
assertEquals(expectedExtendedPublicKey, result)

}
Expand Down Expand Up @@ -139,5 +151,3 @@ class ExtendedKeyTest {
}

}

internal fun ExtendedKey.asPublicOnly(): ExtendedKey = this.copy(keyPair = ECKeyPair(PrivateKey(BigInteger.ZERO), this.keyPair.publicKey))
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import org.kethereum.bip39.toKey
import org.kethereum.bip39.toSeed
import org.kethereum.bip39.validate
import org.kethereum.bip39.wordlists.WORDLIST_ENGLISH
import org.komputing.khex.extensions.hexToByteArray
import org.spongycastle.jce.provider.BouncyCastleProvider
import org.walleth.khex.hexToByteArray
import java.security.Security

/**
Expand Down

0 comments on commit f5758b2

Please sign in to comment.