Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceanis committed Dec 17, 2018
2 parents 0a4ddad + 6615ec3 commit e55d4e0
Show file tree
Hide file tree
Showing 127 changed files with 1,713 additions and 571 deletions.
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: Bug report
about: Create a report to help us improve

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
77 changes: 64 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ In your main `build.gradle` file, add:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
...
//...
}
}
```

In your application `build.gradle`:
```groovy
def uport_sdk_version = "v0.3.0"
def uport_sdk_version = "v0.3.1"
dependencies {
...
//...
// core SDK
implementation "com.github.uport-project.uport-android-sdk:sdk:$uport_sdk_version"
}
Expand Down Expand Up @@ -122,9 +122,9 @@ Uport.defaultAccount?.send(activity, destination, amountInWei) { err, txHash ->

//call contract
val contractAddress = "0x010101..."
val data = <ABI encoded method call>
val data : ByteArray = <ABI encoded contract method call>

val txHash = Uport.defaultAccount?.send(activity, contractAddress, data)
val txHash : String = Uport.defaultAccount?.send(activity, contractAddress, data)
val receipt = Networks.rinkeby.awaitConfirmation(txHash)

```
Expand All @@ -135,16 +135,63 @@ Off-chain interaction is essentially signing and verifying JWTs using uport-spec
Verification of such tokens implies resolving a
[Decentralized Identity (DID) document](https://github.com/uport-project/specs/blob/develop/pki/diddocument.md)
that will contain the keys or address that should match a JWT signature.

To obtain a `DIDDocument` one needs to use a `DIDResolver`.
`UniversalDID` is a global registry of `DIDResolver`s for apps using the SDK.
During SDK initialization this registry gets populated with resolvers for
[uport-did](https://github.com/uport-project/uport-did-resolver) and [ethr-did](https://github.com/uport-project/ethr-did-resolver)


The `UniversalDID` is a global registry of `DIDResolver`s for apps using the SDK.
During SDK initialization this registry gets populated with default resolvers for
[uport-did](https://github.com/uport-project/uport-did-resolver),
[ethr-did](https://github.com/uport-project/ethr-did-resolver)
and [https-did](https://github.com/uport-project/https-did-resolver)
You can register your own resolver(s) using `UniversalDID.registerResolver(resolver)`
Registering a new resolver that resolves the same DID method will override the previous one.

These `DIDDocument`s are used during verification of compatible JWT tokens.

##### verify a JWT token

```kotlin

//in a coroutine context:
val tokenPayload : JWTPayload? = JWTTools().verify(token)

if (tokenPayload != null) {
//verified
} else {
//token cannot be verified
}

```
//TODO: Details about how to use these docs for verification of JWTs to be added when
JWT verification functionality is finalized
```


##### create a JWT token

```kotlin

val payload = mapOf( "claims" to mapOf( "name" to "R Daneel Olivaw" ) )

val signer = KPSigner("0x1234")
val issuer = "did:ethr:0x${signer.getAddress()}"

//in a coroutine context
val jwt : String = JWTTools().create(payload, issuer, signer)

```

### Encrypted messaging

//compute an encryption publicKey starting from a private key (can be an ethereum private key)
val publicKey = Crypto.getEncryptionPublicKey(privateKeyBytes).

//encrypt a message with an intended recipient
val encryptedBundle = Crypto.encrypt("hello world", recipientPublicKeyBase64)
val serializedMessage = encryptedBundle.toJson()

//decrypt a message
val receivedBundle = EncryptedMessage.fromJson(serializedMessage)
val decryptedMessage = Crypto.decrypt(receivedBundle, recipientSecretKey)



### Dependencies

Expand All @@ -158,7 +205,11 @@ but that may be removed when pure kotlin implementations of the required cryptog

### Changelog

* 0.3.0 - upcoming release with breaking changes
* 0.3.1
* add https DID resolver
* use UniversalDID for JWT verification
* add encryption/decryption functionality
* 0.3.0
* add universal DID resolver
* add cleaner way of creating JWTs with abstracted signer
* updated to kethereum 0.63 which has a different key derivation and mnemonic API.
Expand Down
37 changes: 29 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@ buildscript {

ext {

kotlin_version = '1.2.71'
kotlin_serialization_version = '0.6.2'
coroutines_version = "0.30.2"
kotlin_version = '1.3.11'
kotlin_serialization_version = '0.9.1'
coroutines_version = "1.0.1"

android_tools_version = '3.3.0-beta04'
android_tools_version = '3.3.0-rc02'

build_tools_version = "28.0.3"

min_sdk_version = 19
compile_sdk_version = 28
target_sdk_version = compile_sdk_version

test_runner_version = "1.0.2"
test_rules_version = test_runner_version
support_lib_version = "28.0.0"
play_services_version = "15.0.0"

test_runner_version = "1.0.2"
test_rules_version = test_runner_version

espresso_version = "3.0.2"
junit_version = "4.12"
mockito_version = "2.23.0"
Expand All @@ -32,8 +34,9 @@ buildscript {
kmnid_version = "0.2.1"
kethereum_version = "0.63"
khex_version = "0.5"
tweetnacl_k_version = "0.0.1"

uport_sdk_version = "0.3.0"
uport_sdk_version = "0.3.1"
}

repositories {
Expand All @@ -46,7 +49,7 @@ buildscript {
dependencies {
classpath "com.android.tools.build:gradle:$android_tools_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:$kotlin_serialization_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.github.gnosis.bivrost-kotlin:bivrost-gradle-plugin:$bivrost_version"
}
}
Expand All @@ -59,6 +62,24 @@ allprojects {
maven { url "https://kotlin.bintray.com/kotlinx" }
mavenLocal()
}

//address warnings about multiple kotlin runtimes in classpath
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module("org.jetbrains.kotlin:kotlin-stdlib-jre7") because "warning about multiple runtimes in the classpath" with module("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version")
substitute module("org.jetbrains.kotlin:kotlin-stdlib-jre8") because "warning about multiple runtimes in the classpath" with module("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version")

}
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'org.jetbrains.kotlin' && requested.name in [
'kotlin-reflect', 'kotlin-stdlib', 'kotlin-stdlib-common',
'kotlin-stdlib-jdk7', 'kotlin-stdlib-jdk8',
]) {
details.useVersion kotlin_version
}
}
}
}

subprojects { subproject ->
Expand Down
8 changes: 1 addition & 7 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,4 @@ dependencies {
}

sourceCompatibility = "1.7"
targetCompatibility = "1.7"

kotlin {
experimental {
coroutines "enable"
}
}
targetCompatibility = "1.7"
9 changes: 4 additions & 5 deletions core/src/main/java/me/uport/sdk/core/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ package me.uport.sdk.core

import android.support.annotation.VisibleForTesting
import android.support.annotation.VisibleForTesting.PRIVATE
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.android.Main
import kotlinx.coroutines.Dispatchers
import org.kethereum.extensions.toHexStringNoPrefix
import org.spongycastle.util.encoders.Base64
import org.walleth.khex.clean0xPrefix
import org.walleth.khex.prepend0xPrefix
import java.math.BigInteger
import java.nio.charset.Charset
import kotlin.coroutines.experimental.CoroutineContext
import kotlin.coroutines.experimental.EmptyCoroutineContext
import kotlinx.coroutines.experimental.android.UI as mainLooperContext
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlinx.coroutines.Dispatchers.Main as mainLooperContext

/**
* Shorthand for a mockable UI context in unit tests
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/me/uport/sdk/core/IFuelTokenProvider.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package me.uport.sdk.identity
package me.uport.sdk.core

import kotlin.coroutines.experimental.suspendCoroutine
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

interface IFuelTokenProvider {
fun onCreateFuelToken(deviceAddress: String, callback: (err: Exception?, fuelToken: String) -> Unit)
}



suspend fun IFuelTokenProvider.onCreateFuelToken(deviceAddress: String): String = suspendCoroutine {
this.onCreateFuelToken(deviceAddress) { err, fuelToken ->
if (err != null) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/me/uport/sdk/core/ITimeProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ interface ITimeProvider {
* Returns the current timestamp in milliseconds
* @return the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.
*/
fun now() : Long
fun now(): Long
}


/**
* Default time provider
*/
object SystemTimeProvider : ITimeProvider {
override fun now() = System.currentTimeMillis()
override fun now() = System.currentTimeMillis()
}
2 changes: 1 addition & 1 deletion core/src/main/java/me/uport/sdk/core/Networks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object Networks {
/**
* Gets an [EthNetwork] based on a networkId
*/
fun get(networkId: String) : EthNetwork {
fun get(networkId: String): EthNetwork {
val cleanNetId = networkId.clean0xPrefix().padStart(2, '0').prepend0xPrefix()
return NETWORK_CONFIG[cleanNetId]
?: throw IllegalStateException("network [$networkId] not configured")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package me.uport.sdk.core.experimental

import me.uport.sdk.core.urlGet
import me.uport.sdk.core.urlPost
import kotlin.coroutines.experimental.suspendCoroutine
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

/**
* wraps a [urlPost] in a suspend function
Expand Down
10 changes: 5 additions & 5 deletions core/src/test/java/me/uport/sdk/core/ExtensionsKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package me.uport.sdk.core

import kotlinx.coroutines.experimental.runBlocking
import kotlinx.coroutines.experimental.withContext
import org.junit.Test

import org.junit.Assert.*
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.junit.Assert.assertArrayEquals
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test

class ExtensionsKtTest {

Expand Down
6 changes: 0 additions & 6 deletions credentials/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,4 @@ dependencies {
testImplementation "junit:junit:$junit_version"
testImplementation "org.mockito:mockito-inline:$mockito_version"
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:$mockito_kotlin_version"
}

kotlin {
experimental {
coroutines "enable"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.uport.sdk.credentials

import android.support.annotation.Keep
import me.uport.sdk.credentials.RequestAccountType.*

/**
* A class that encapsulates the supported parameter types for creating a SelectiveDisclosureRequest.
Expand All @@ -15,7 +16,7 @@ import android.support.annotation.Keep
class SelectiveDisclosureRequestParams(
/**
* [**required**]
* a list of attributes for which you are requesting credentials.
* a simple_list of attributes for which you are requesting credentials.
* Ex. [ 'name', 'country' ]
*/
val requested: List<String>,
Expand All @@ -31,7 +32,7 @@ class SelectiveDisclosureRequestParams(

/**
* [**optional**]
* A list of signed claims being requested.
* A simple_list of signed claims being requested.
* This is semantically similar to the [requested] field
* but the response should contain signatures as well.
*/
Expand Down Expand Up @@ -59,7 +60,7 @@ class SelectiveDisclosureRequestParams(

/**
* [**optional**]
* A list of signed claims about the issuer, usually signed by 3rd parties.
* A simple_list of signed claims about the issuer, usually signed by 3rd parties.
*/
val vc: List<String>? = null,

Expand Down
Loading

0 comments on commit e55d4e0

Please sign in to comment.