Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit ca88a12

Browse files
authored
Merge pull request #171 from blockstack/develop
Version 0.5.0
2 parents 9dd25c4 + d21c28d commit ca88a12

File tree

86 files changed

+7331
-2479
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+7331
-2479
lines changed

.idea/assetWizardSettings.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 13 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## Unreleased
7+
## [0.5.0] - 2019-10-12
8+
9+
### Added
10+
- A `ResultError` type and enum `ErrorCode` to better represent errors from Blockstack
11+
12+
### Changed
13+
- Replaced J2V8 with kotlin implementation of auth and storage protocol
14+
- Removed callbacks from all method calls
15+
- Replaced `Result.error` type String with type `ResultError`
16+
- `loadUserData` throws an error if user not logged in
17+
- `Network` methods return results, no callback used anymore
18+
- `Network.getNamePrice` is using v2 API (expecting amounts in decimals, not hex format)
819

920
## [0.4.8] - 2019-09-16
1021

blockstack-sdk/build.gradle

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ apply plugin: 'org.jetbrains.dokka-android'
99
group = 'com.github.blockstack'
1010

1111
android {
12-
compileSdkVersion 28
12+
compileSdkVersion 29
1313

1414
defaultConfig {
15-
minSdkVersion 19
16-
targetSdkVersion 28
15+
minSdkVersion 21
16+
targetSdkVersion 29
1717
versionCode 2
1818
versionName "0.2.0"
1919

2020
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
21-
2221
}
2322

2423
signingConfigs {
@@ -41,6 +40,13 @@ android {
4140
unitTests.returnDefaultValues = true
4241
}
4342

43+
packagingOptions {
44+
exclude 'META-INF/*'
45+
}
46+
47+
lintOptions {
48+
disable 'InvalidPackage'
49+
}
4450
}
4551

4652
dokka {
@@ -59,27 +65,56 @@ gitPublish {
5965
}
6066

6167
dependencies {
62-
implementation 'com.eclipsesource.j2v8:j2v8:4.8.4@aar'
68+
implementation fileTree(dir: 'libs', include: ['*.jar'])
69+
implementation 'androidx.appcompat:appcompat:1.1.0'
70+
implementation 'androidx.preference:preference:1.1.0'
6371
implementation 'androidx.browser:browser:1.0.0'
64-
implementation 'androidx.appcompat:appcompat:1.0.2'
6572
api 'com.squareup.okhttp3:okhttp:3.12.1'
73+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
74+
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
75+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
76+
77+
implementation "com.github.komputing.kethereum:crypto_api:$kethereum_version"
78+
implementation "com.github.komputing.kethereum:base58:$kethereum_version"
79+
implementation "com.github.komputing.kethereum:hashes:$kethereum_version"
80+
api ("com.github.komputing.kethereum:bip32:$kethereum_version") {
81+
exclude group:'com.github.komputing.KHash'
82+
}
83+
api "com.github.komputing.kethereum:bip44:$kethereum_version"
84+
api ("com.github.komputing.kethereum:bip39:$kethereum_version") {
85+
exclude group:'com.github.komputing.KHash'
86+
}
87+
implementation "com.github.komputing.kethereum:bip39_wordlist_en:$kethereum_version"
88+
89+
implementation 'org.bouncycastle:bcprov-jdk15on:1.62'
90+
api ("com.github.uport-project.kotlin-did-jwt:jwt:$did_jwt_version") {
91+
exclude group:'com.github.komputing.KHash'
92+
exclude group: 'com.squareup.okhttp3'
93+
}
94+
6695
testImplementation 'junit:junit:4.12'
6796
testImplementation 'org.json:json:20180130'
6897
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
6998
androidTestImplementation 'androidx.test:rules:1.2.0'
7099
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
100+
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
71101
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
72-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
73-
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
74-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
75102
}
76103

77104
apply plugin: 'kotlin-android'
78105
apply plugin: 'kotlin-android-extensions'
79106

80107

108+
/**
109+
* How to get a new `blockstack.js` version?
110+
*
111+
* 1. change the url in downloadBlockstackJs
112+
* 2. ./gradlew updateBlockstackJs
113+
*/
114+
115+
81116
task downloadBlockstackJs(type: Download) {
82-
src 'https://unpkg.com/blockstack@19.2.1/dist/blockstack.js'
117+
src 'https://unpkg.com/blockstack@19.4.0-beta.1/dist/blockstack.js'
83118
dest new File(buildDir, 'blockstack.js')
84119
}
85120

Lines changed: 22 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
package org.blockstack.android.sdk
22

3-
import android.content.Context
43
import android.preference.PreferenceManager
5-
import android.util.Log
64
import androidx.test.ext.junit.runners.AndroidJUnit4
75
import androidx.test.rule.ActivityTestRule
86
import kotlinx.coroutines.runBlocking
97
import org.blockstack.android.sdk.model.BlockstackConfig
10-
import org.blockstack.android.sdk.model.Profile
11-
import org.blockstack.android.sdk.model.Proof
128
import org.blockstack.android.sdk.model.toBlockstackConfig
139
import org.blockstack.android.sdk.test.TestActivity
1410
import org.hamcrest.CoreMatchers.`is`
15-
import org.hamcrest.CoreMatchers.nullValue
1611
import org.hamcrest.MatcherAssert.assertThat
1712
import org.hamcrest.Matchers
1813
import org.hamcrest.Matchers.notNullValue
19-
import org.hamcrest.Matchers.startsWith
20-
import org.json.JSONObject
21-
import org.junit.*
14+
import org.junit.Assert
15+
import org.junit.Before
16+
import org.junit.Rule
17+
import org.junit.Test
2218
import org.junit.runner.RunWith
23-
import java.util.*
24-
import java.util.concurrent.CountDownLatch
2519

2620
val A_VALID_BLOCKSTACK_SESSION_JSON = "{\"transitKey\":\"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f\",\"userData\":{\"username\":null,\"profile\":{\"@type\":\"Person\",\"@context\":\"http:\\/\\/schema.org\",\"apps\":{\"https:\\/\\/app.graphitedocs.com\":\"https:\\/\\/gaia.blockstack.org\\/hub\\/1Fuzd6sJXqtXhgoFpb8W19Ao4BCG3EHQGf\\/\",\"https:\\/\\/app.misthos.io\":\"https:\\/\\/gaia.blockstack.org\\/hub\\/1CkGhNN71a1dpgXQjncunYZpXakJvwrpmc\\/\"},\"image\":[{\"@type\":\"ImageObject\",\"name\":\"avatar\",\"contentUrl\":\"https:\\/\\/gaia.blockstack.org\\/hub\\/12Gpr9kYXJJn4fWec4nRVwHLSrrTieeywt\\/\\/avatar-0\"}],\"name\":\"fm\"},\"decentralizedID\":\"did:btc-addr:12Gpr9kYXJJn4fWec4nRVwHLSrrTieeywt\",\"identityAddress\":\"12Gpr9kYXJJn4fWec4nRVwHLSrrTieeywt\",\"appPrivateKey\":\"89f92476f13f5b173e53926ad7d6e22baf78c6b1dcdf200c38dc73d2bf47d43b\",\"coreSessionToken\":null,\"authResponseToken\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJqdGkiOiI3MWI3NWY1Yi0xNDJkLTQxMzQtOGZkYy0zYWUyMWRmZTkzNjAiLCJpYXQiOjE1MzcxNjkxODYsImV4cCI6MTUzOTc2MTE4NSwiaXNzIjoiZGlkOmJ0Yy1hZGRyOjEyR3ByOWtZWEpKbjRmV2VjNG5SVndITFNyclRpZWV5d3QiLCJwcml2YXRlX2tleSI6IjdiMjI2OTc2MjIzYTIyMzEzOTMzMzM2NTM5MzYzNTY2NjMzNzM5NjM2MjYyMzAzNjY0NjMzMjM0MzIzNzY2NjY2MjYzMzczMjMyMzgzOTIyMmM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jNhM2NiMjA0MTY0Y2I4ZSJdLCJwcm9maWxlIjpudWxsLCJ1c2VybmFtZSI6bnVsbCwiY29yZV90b2tlbiI6bnVsbCwiZW1haWwiOiJmcmllZGdlckBnbWFpbC5jb20iLCJwcm9maWxlX3VybCI6Imh0dHBzOi8vZ2FpYS5ibG9ja3N0YWNrLm9yZy9odWIvMTJHcHI5a1lYSkpuNGZXZWM0blJWd0hMU3JyVGllZXl3dC9wcm9maWxlLmpzb24iLCJodWJVcmwiOiJodHRwczovL2h1Yi5ibG9ja3N0YWNrLm9yZyIsInZlcnNpb24iOiIxLjIuMCJ9.QM8wx-EDjZrHk1ubK99divaejN5XAcCn_OkYAiPXQUNtzENUy8ogyrHzB4xC7mwfMckzFsMxEOdzwVW_Xcjqqg\",\"hubUrl\":\"https:\\/\\/hub.blockstack.org\"}}"
2721

@@ -43,21 +37,10 @@ class BlockstackSessionAuthProfileTest {
4337
fun setup() {
4438
config = "https://flamboyant-darwin-d11c17.netlify.com".toBlockstackConfig(emptyArray())
4539
sessionStore = sessionStoreforIntegrationTests(rule)
46-
session = BlockstackSession(rule.activity,
47-
config,
48-
sessionStore = sessionStore,
49-
executor = IntegrationTestExecutor(rule))
40+
session = BlockstackSession(sessionStore,
41+
config, blockstack = Blockstack())
5042
}
5143

52-
@After
53-
fun teardown() {
54-
session.release()
55-
}
56-
57-
@Test
58-
fun loadedIsTrueAfterSessionCreated() {
59-
Assert.assertThat(session.loaded, Matchers.`is`(true))
60-
}
6144

6245
@Test
6346
fun userIsSignedInAfterSessionCreated() {
@@ -71,20 +54,23 @@ class BlockstackSessionAuthProfileTest {
7154

7255
@Test
7356
fun testHandlingPendingSignInWithInvalidToken() {
74-
val latch = CountDownLatch(1)
7557
var error: String? = null
76-
session.handlePendingSignIn("authResponse") {
77-
latch.countDown()
78-
error = it.error
58+
runBlocking {
59+
val it = session.handlePendingSignIn("invalidAuthResponseToken")
60+
error = it.error?.message
7961
}
80-
latch.await()
81-
Assert.assertThat(error, Matchers.`is`("The authResponse parameter is an invalid base64 encoded token\n2 dots requires\nAuth response: authResponse"))
62+
Assert.assertThat(error, Matchers.`is`("The authResponse parameter is an invalid base64 encoded token\n2 dots requires\nAuth response: invalidAuthResponseToken"))
8263
}
8364

8465
@Test
85-
fun loadUserDataIsNullAfterSignOut() {
66+
fun loadUserDataIsInvalidAfterSignOut() {
8667
session.signUserOut()
87-
assertThat(session.loadUserData(), `is`(nullValue()))
68+
try {
69+
session.loadUserData()
70+
throw AssertionError("should have thrown an error that no user data was found")
71+
} catch (e: Exception) {
72+
assertThat(e.message, `is`("No user data found. Did the user sign in?"))
73+
}
8874
}
8975

9076
@Test
@@ -94,6 +80,8 @@ class BlockstackSessionAuthProfileTest {
9480
assertThat(session.isUserSignedIn(), `is`(false))
9581
}
9682

83+
/* TODO implement validateProofs
84+
9785
@Test
9886
fun verifyProofsReturnsEmptyListForEmptyProfile() {
9987
val latch = CountDownLatch(1)
@@ -113,6 +101,7 @@ class BlockstackSessionAuthProfileTest {
113101
assertThat(proofList!!.size, `is`(0))
114102
}
115103
104+
116105
@Test
117106
fun verifyProofsReturnsAllProofsForFriedger() {
118107
val latch = CountDownLatch(1)
@@ -139,46 +128,13 @@ class BlockstackSessionAuthProfileTest {
139128
assertThat(proofList!![2].valid, `is`(true))
140129
}
141130
142-
@Test
143-
fun generateAndStoreTransitKeyReturnsTheCorrectKey() {
144-
val key = session.generateAndStoreTransitKey()
145-
val storedKey = sessionStore.sessionData.json.getString("transitKey")
146-
assertThat(key, `is`(storedKey))
147-
}
131+
*/
148132

149-
@Test
150-
fun makeAuthRequestReturnsValidRequestToken() {
151-
val key = session.generateAndStoreTransitKey()
152-
val authRequest = session.makeAuthRequest(key, Date(System.currentTimeMillis() + 3600000).time, mapOf(Pair("solicitGaiaHubUrl", true)))
153-
assertThat(authRequest, startsWith("ey"))
154-
155-
val tokenPair = session.wrapProfileToken(authRequest)
156-
val payload = tokenPair.decodedToken?.json?.optJSONObject("payload")
157-
Log.d("payload", payload.toString())
158-
assertThat(payload?.optString("domain_name"), `is`(config.appDomain.toString()))
159-
assertThat(payload?.optBoolean("solicitGaiaHubUrl"), `is`(true))
160-
}
161-
}
162-
163-
class IntegrationTestExecutor(var rule: ActivityTestRule<*>) : Executor {
164-
override fun onMainThread(function: (Context) -> Unit) {
165-
function(rule.activity)
166-
}
167-
168-
override fun onNetworkThread(function: suspend () -> Unit) {
169-
runBlocking {
170-
function()
171-
}
172-
}
173-
174-
override fun onV8Thread(function: () -> Unit) {
175-
function()
176-
}
177133
}
178134

179135
fun sessionStoreforIntegrationTests(rule: ActivityTestRule<*>): SessionStore {
180136
val prefs = PreferenceManager.getDefaultSharedPreferences(rule.activity)
181-
prefs.edit().putString("blockstack_session", A_VALID_BLOCKSTACK_SESSION_JSON)
137+
prefs.edit().putString(BLOCKSTACK_SESSION, A_VALID_BLOCKSTACK_SESSION_JSON)
182138
.apply()
183139
return SessionStore(prefs)
184140
}

blockstack-sdk/src/androidTest/java/org/blockstack/android/sdk/BlockstackSessionCompanionTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ class BlockstackSessionCompanionTest {
1919

2020
@Test
2121
fun verifyAuthResponseReturnsNullForValidAuthResponse() {
22-
assertThat(BlockstackSession.verifyAuthResponse(TOKEN), isEmptyOrNullString())
22+
assertThat(Blockstack.verifyAuthResponse(TOKEN)?.message, isEmptyOrNullString())
2323
}
2424

2525
@Test
2626
fun verifyAuthResponseReturnsErrorForInValidAuthResponse() {
27-
assertThat(BlockstackSession.verifyAuthResponse("a.b.c"), `is`("The authResponse parameter is an invalid base64 encoded token\nbad base-64\nAuth response: a.b.c"))
27+
assertThat(Blockstack.verifyAuthResponse("a.b.c")?.message, `is`("The authResponse parameter is an invalid base64 encoded token\nbad base-64\nAuth response: a.b.c"))
2828
}
2929
}

blockstack-sdk/src/androidTest/java/org/blockstack/android/sdk/BlockstackSessionLoginTest.kt

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)