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

Commit f1f3b65

Browse files
authored
Merge pull request #181 from blocoio/connectActivity
Blockstack Connect integration (Release 0.6)
2 parents 2b5103b + b98fbe6 commit f1f3b65

File tree

74 files changed

+1106
-328
lines changed

Some content is hidden

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

74 files changed

+1106
-328
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ 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+
## Unrelease
8+
### Added
9+
- additional parameters `sendToSignIn`, `appDetails` for `BlockstackSignIn`
10+
- `Context.getBlockstackSharedPreferences` to be used for `SessionStore`
11+
- `ConnectActivty` and `ConnectHowItWorksActivity` to show user on-boarding
12+
- `BlockstackConnect` for simplified integration
13+
### Changed
14+
- use app.blockstack.org (connect) instead of browser.blockstack.org for sign in.
15+
716
## [0.5.0] - 2019-10-12
817

918
### Added

blockstack-sdk/build.gradle

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
plugins {
2-
id 'org.ajoberstar.git-publish' version '2.1.0'
3-
}
41

52
apply plugin: 'com.android.library'
63
apply plugin: 'com.github.dcendents.android-maven'
@@ -23,7 +20,7 @@ android {
2320
signingConfigs {
2421
debug {
2522
storeFile mySigningConfigs.debug.storeFile
26-
storePassword mySigningConfigs.debug.storePassword
23+
storePassword mySigningConfigs.debug.storePassword
2724
keyAlias mySigningConfigs.debug.keyAlias
2825
keyPassword mySigningConfigs.debug.keyPassword
2926
}
@@ -41,7 +38,20 @@ android {
4138
}
4239

4340
packagingOptions {
44-
exclude 'META-INF/*'
41+
exclude 'META-INF/kotlinx-io.kotlin_module'
42+
exclude 'META-INF/kbignumbers.kotlin_module'
43+
exclude 'META-INF/ripemd160.kotlin_module'
44+
exclude 'META-INF/atomicfu.kotlin_module'
45+
exclude 'META-INF/extensions.kotlin_module'
46+
exclude 'META-INF/core.kotlin_module'
47+
exclude 'META-INF/keccak.kotlin_module'
48+
exclude 'META-INF/sha256.kotlin_module'
49+
exclude 'META-INF/khash-extensions.kotlin_module'
50+
}
51+
52+
compileOptions {
53+
sourceCompatibility JavaVersion.VERSION_1_8
54+
targetCompatibility JavaVersion.VERSION_1_8
4555
}
4656

4757
lintOptions {
@@ -55,49 +65,52 @@ dokka {
5565
outputDirectory = "$buildDir/javadoc"
5666
}
5767

58-
gitPublish {
59-
repoUri = 'git@github.com:blockstack/blockstack-android.git'
60-
branch = 'gh-pages'
61-
contents {
62-
from 'build/javadoc/blockstack-sdk'
63-
}
64-
commitMessage = '[skip ci] udpateing docs' // defaults to 'Generated by gradle-git-publish'
65-
}
6668

6769
dependencies {
6870
implementation fileTree(dir: 'libs', include: ['*.jar'])
69-
implementation 'androidx.appcompat:appcompat:1.1.0'
70-
implementation 'androidx.preference:preference:1.1.0'
71-
implementation 'androidx.browser:browser:1.0.0'
72-
api 'com.squareup.okhttp3:okhttp:3.12.1'
71+
72+
implementation 'com.google.android.material:material:1.2.1'
73+
74+
implementation 'androidx.appcompat:appcompat:1.2.0'
75+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
76+
implementation 'androidx.preference:preference:1.1.1'
77+
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
78+
implementation 'androidx.browser:browser:1.2.0'
79+
7380
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
7481
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
75-
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0'
82+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.5-native-mt'
83+
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-alpha03"
84+
85+
implementation 'org.bouncycastle:bcprov-jdk15on:1.65'
7686

7787
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-
}
8788
implementation "com.github.komputing.kethereum:bip39_wordlist_en:$kethereum_version"
89+
implementation "com.github.komputing:kbase58:$kbase58_version"
90+
implementation "com.github.komputing.khash:sha256:$khash_version"
91+
implementation "com.github.komputing.khash:ripemd160:$khash_version"
8892

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'
93+
api 'com.squareup.okhttp3:okhttp:3.14.2'
94+
95+
api("com.github.komputing.kethereum:bip32:$kethereum_version") {
96+
exclude group: 'com.github.komputing.KHash'
97+
}
98+
api "com.github.komputing:kbip44:$kbip44_version"
99+
api("com.github.komputing.kethereum:bip39:$kethereum_version") {
100+
exclude group: 'com.github.komputing.KHash'
101+
}
102+
api("com.github.uport-project.kotlin-did-jwt:jwt:$did_jwt_version") {
103+
exclude group: 'com.github.komputing.KHash'
92104
exclude group: 'com.squareup.okhttp3'
93105
}
94106

95-
testImplementation 'junit:junit:4.12'
96-
testImplementation 'org.json:json:20180130'
97-
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
98-
androidTestImplementation 'androidx.test:rules:1.2.0'
99-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
100-
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.2.0'
107+
testImplementation 'junit:junit:4.13'
108+
testImplementation 'org.json:json:20190722'
109+
110+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
111+
androidTestImplementation 'androidx.test:rules:1.3.0'
112+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
113+
androidTestImplementation 'androidx.test.espresso:espresso-intents:3.3.0'
101114
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
102115
}
103116

@@ -121,11 +134,9 @@ task downloadBlockstackJs(type: Download) {
121134
task updateBlockstackJs(dependsOn: downloadBlockstackJs, type: Copy) {
122135
from downloadBlockstackJs.dest
123136
into 'src/main/res/raw'
124-
include ('blockstack.js')
125-
rename ('(.*)', 'org_blockstack_$1')
137+
include('blockstack.js')
138+
rename('(.*)', 'org_blockstack_$1')
126139
eachFile { fcp ->
127140
fcp.path = fcp.name
128141
}
129142
}
130-
131-

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AppLinkVerifierTest {
2121

2222
@Before
2323
fun setup() {
24-
appLinkVerifier = AppLinkVerifier(rule.activity, "https://flamboyant-darwin-d11c17.netlify.com".toBlockstackConfig(arrayOf()))
24+
appLinkVerifier = AppLinkVerifier(rule.activity, "https://flamboyant-darwin-d11c17.netlify.app".toBlockstackConfig(arrayOf()))
2525
}
2626

2727
@Test
@@ -35,7 +35,7 @@ class AppLinkVerifierTest {
3535

3636
@Test
3737
fun testValidFingerprints() {
38-
val betaAppLinkVerifier = AppLinkVerifier(rule.activity, "https://flamboyant-darwin-d11c17.netlify.com".toBlockstackConfig(arrayOf()))
38+
val betaAppLinkVerifier = AppLinkVerifier(rule.activity, "https://flamboyant-darwin-d11c17.netlify.app".toBlockstackConfig(arrayOf()))
3939
val warning = betaAppLinkVerifier.verify()
4040
assertThat(warning, isEmptyOrNullString())
4141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BlockstackSessionAuthProfileTest {
3535

3636
@Before
3737
fun setup() {
38-
config = "https://flamboyant-darwin-d11c17.netlify.com".toBlockstackConfig(emptyArray())
38+
config = "https://flamboyant-darwin-d11c17.netlify.app".toBlockstackConfig(emptyArray())
3939
sessionStore = sessionStoreforIntegrationTests(rule)
4040
session = BlockstackSession(sessionStore,
4141
config, blockstack = Blockstack())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class BlockstackSessionStorageOfflineTest {
3737
}
3838

3939
session = BlockstackSession(
40-
appConfig = "https://flamboyant-darwin-d11c17.netlify.com".toBlockstackConfig(emptyArray()),
40+
appConfig = "https://flamboyant-darwin-d11c17.netlify.app".toBlockstackConfig(emptyArray()),
4141
sessionStore = sessionStoreforIntegrationTests(rule),
4242
callFactory = callFactory, blockstack = Blockstack())
4343
runBlocking {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.blockstack.android.sdk.test.TestActivity
1111
import org.hamcrest.CoreMatchers.*
1212
import org.hamcrest.MatcherAssert.assertThat
1313
import org.hamcrest.Matchers
14+
import org.hamcrest.Matchers.greaterThanOrEqualTo
1415
import org.json.JSONObject
1516
import org.junit.Assert.assertTrue
1617
import org.junit.Assert.fail
@@ -42,7 +43,7 @@ class BlockstackSessionStorageTest {
4243
fun setup() {
4344
blockstack = Blockstack()
4445
session = BlockstackSession(
45-
appConfig = "https://flamboyant-darwin-d11c17.netlify.com".toBlockstackConfig(emptyArray()),
46+
appConfig = "https://flamboyant-darwin-d11c17.netlify.app".toBlockstackConfig(emptyArray()),
4647
sessionStore = sessionStoreforIntegrationTests(rule),
4748
blockstack = blockstack)
4849
val gaiaHubConfig = runBlocking {
@@ -341,7 +342,8 @@ class BlockstackSessionStorageTest {
341342

342343
}
343344

344-
assertThat(fileCount?.value, `is`(Matchers.greaterThanOrEqualTo(1)))
345+
346+
assertThat(fileCount?.value ?:-1, `is`(greaterThanOrEqualTo(1)))
345347
}
346348

347349

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

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ import org.kethereum.bip32.model.ExtendedKey
2020
import org.kethereum.bip32.toKey
2121
import org.kethereum.bip39.model.MnemonicWords
2222
import org.kethereum.bip39.toSeed
23-
import org.kethereum.bip44.BIP44Element
2423
import org.kethereum.extensions.toHexStringNoPrefix
24+
import org.komputing.kbip44.BIP44Element
2525
import java.security.InvalidParameterException
2626
import java.util.*
2727

@@ -36,6 +36,7 @@ class BlockstackSignInTest {
3636
private lateinit var blockstack: Blockstack
3737
private lateinit var appConfig: BlockstackConfig
3838
private lateinit var keys: ExtendedKey
39+
3940
@get:Rule
4041
val rule = ActivityTestRule(TestActivity::class.java)
4142

@@ -46,7 +47,7 @@ class BlockstackSignInTest {
4647

4748
@Before
4849
fun setup() {
49-
config = "https://flamboyant-darwin-d11c17.netlify.com".toBlockstackConfig(emptyArray())
50+
config = "https://flamboyant-darwin-d11c17.netlify.app".toBlockstackConfig(emptyArray())
5051
sessionStore = sessionStoreforIntegrationTests(rule)
5152
signIn = BlockstackSignIn(
5253
sessionStore, config)
@@ -56,7 +57,7 @@ class BlockstackSignInTest {
5657
identity = BlockstackIdentity(words.toSeed().toKey("m/888'/0'"))
5758
keys = identity.identityKeys.generateChildKey(BIP44Element(true, 0))
5859
val privateKey = keys.keyPair.privateKey.key.toHexStringNoPrefix()
59-
appConfig = "https://flamboyant-darwin-d11c17.netlify.com".toBlockstackConfig(emptyArray())
60+
appConfig = "https://flamboyant-darwin-d11c17.netlify.app".toBlockstackConfig(emptyArray())
6061
blockstack = Blockstack()
6162
session = BlockstackSession(sessionStore, callFactory = callFactory, appConfig = appConfig, blockstack = blockstack)
6263
}
@@ -86,6 +87,17 @@ class BlockstackSignInTest {
8687
assertThat(appNode.toBtcAddress(), CoreMatchers.`is`(expectedAppNodeAddress))
8788
}
8889

90+
@Test
91+
fun testAppsNodeWithTrailingSlash() {
92+
val account = BlockstackAccount(null, keys, identity.salt)
93+
val appsNode = account.getAppsNode()
94+
95+
val origin = "https://amazing.app:443/"
96+
val appNode = appsNode.getAppNode(origin)
97+
val expectedAppNodeAddress = "1A9NEhnXq5jDp9BRT4DrwadRP5jbBK896X"
98+
assertThat(appNode.toBtcAddress(), CoreMatchers.`is`(expectedAppNodeAddress))
99+
}
100+
89101
@Test
90102
fun generateAndStoreTransitKeyReturnsTheCorrectKey() {
91103
val key = signIn.generateAndStoreTransitKey()
@@ -99,14 +111,14 @@ class BlockstackSignInTest {
99111
fun makeAuthRequestReturnsValidRequestToken() {
100112
val key = signIn.generateAndStoreTransitKey()
101113
val authRequest = runBlocking {
102-
signIn.makeAuthRequest(key, Date(System.currentTimeMillis() + 3600000).time, mapOf("solicitGaiaHubUrl" to true))
114+
signIn.makeAuthRequest(key, Date(System.currentTimeMillis() + 3600000).time, false, mapOf("solicitGaiaHubUrl" to true))
103115
}
104116
assertThat(authRequest, Matchers.startsWith("ey"))
105117

106118
val token = Blockstack().decodeToken(authRequest)
107119
val payload = token.second
108120
assertThat(payload, `is`(notNullValue()))
109-
assertThat(payload.optString("domain_name"), `is`(config.appDomain.toString()))
121+
assertThat(payload.optString("domain_name"), `is`(config.appDomain.getOrigin()))
110122
assertThat(payload.optBoolean("solicitGaiaHubUrl"), `is`(true))
111123
}
112124

@@ -115,7 +127,7 @@ class BlockstackSignInTest {
115127
fun testMakeAuthResponse2HandlePendingLogin2() {
116128
val expiresAt = Date().time + 3600 * 24 * 7
117129
val authRequest = runBlocking {
118-
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, emptyMap())
130+
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, false, emptyMap())
119131
}
120132
val authResponse = runBlocking {
121133
val account = BlockstackAccount(null, keys, identity.salt)
@@ -130,15 +142,15 @@ class BlockstackSignInTest {
130142
}
131143

132144
assertThat(result?.json?.getString("decentralizedID"), CoreMatchers.`is`("did:btc-addr:1JeTQ5cQjsD57YGcsVFhwT7iuQUXJR6BSk"))
133-
assertThat(result?.json?.getString("appPrivateKey"), CoreMatchers.`is`("a8025a881da1074b012995beef7e7ccb42fea2ec66e62367c8d73734033ee33b"))
145+
assertThat(result?.json?.getString("appPrivateKey"), CoreMatchers.`is`("6b52c9c23cb75d5e420441929a473fa49772575520f583e3e03d2919ac663a3a"))
134146
}
135147

136148

137149
@Test
138-
fun testVerifyAuthResponse() {
150+
fun testVerifyAuthRequest() {
139151
val expiresAt = Date().time + 3600 * 24 * 7
140152
val authRequest = runBlocking {
141-
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, emptyMap())
153+
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, false, emptyMap())
142154
}
143155

144156
val result = runBlocking {
@@ -152,7 +164,7 @@ class BlockstackSignInTest {
152164
fun testVerifyAuthResponseWithoutUsername() {
153165
val expiresAt = Date().time + 3600 * 24 * 7
154166
val authRequest = runBlocking {
155-
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, emptyMap())
167+
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, false, emptyMap())
156168
}
157169
val authResponse = runBlocking {
158170
val account = BlockstackAccount(null, keys, identity.salt)
@@ -169,7 +181,7 @@ class BlockstackSignInTest {
169181
fun testVerifyAuthResponseWithUsername() {
170182
val expiresAt = Date().time + 3600 * 24 * 7
171183
val authRequest = runBlocking {
172-
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, emptyMap())
184+
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, false, emptyMap())
173185
}
174186
val authResponse = runBlocking {
175187
val account = BlockstackAccount("public_profile_for_testing.id.blockstack", keys, identity.salt)
@@ -185,7 +197,7 @@ class BlockstackSignInTest {
185197
fun testVerifyAuthResponseWithWrongUsernameWithImage() {
186198
val expiresAt = Date().time + 3600 * 24 * 7
187199
val authRequest = runBlocking {
188-
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, emptyMap())
200+
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, false, emptyMap())
189201
}
190202
val authResponse = runBlocking {
191203
val account = BlockstackAccount("friedger.id", keys, identity.salt)
@@ -202,7 +214,7 @@ class BlockstackSignInTest {
202214
fun testVerifyAuthResponseWithWrongUsername() {
203215
val expiresAt = Date().time + 3600 * 24 * 7
204216
val authRequest = runBlocking {
205-
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, emptyMap())
217+
BlockstackSignIn(sessionStore, appConfig).makeAuthRequest(TRANSIT_PRIVATE_KEY, expiresAt, false, emptyMap())
206218
}
207219
runBlocking {
208220
val account = BlockstackAccount("invalid$$.id.blockstack", keys, identity.salt)
@@ -219,7 +231,7 @@ class BlockstackSignInTest {
219231
fun testVerifyAuthUnencryptedAuthResponse() {
220232
val authResponse = runBlocking {
221233
val account = BlockstackAccount("public_profile_for_testing.id.blockstack", keys, identity.salt)
222-
blockstack.makeAuthResponseUnencrypted(account, "https://flamboyant-darwin-d11c17.netlify.com", emptyArray())
234+
blockstack.makeAuthResponseUnencrypted(account, "https://flamboyant-darwin-d11c17.netlify.app", emptyArray())
223235
}
224236
assertThat(authResponse, CoreMatchers.`is`(CoreMatchers.notNullValue()))
225237
val result = runBlocking {

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.junit.Before
1313
import org.junit.Rule
1414
import org.junit.Test
1515
import org.junit.runner.RunWith
16+
import java.net.URI
1617

1718

1819
private val PRIVATE_KEY = "a5c61c6ca7b3e7e55edee68566aeab22e4da26baa285c7bd10e8d2218aa3b229"
@@ -70,5 +71,14 @@ class BlockstackTest {
7071
val plainText = blockstack.decryptContent(result.value!!.json.toString(), false, CryptoOptions(privateKey = PRIVATE_KEY))
7172
assertThat(plainText.value as String, `is`(message))
7273
}
74+
75+
@Test
76+
fun testOriginOrUri() {
77+
assertThat(URI("https://blockstack.org:443/wiki").getOrigin(), `is`("https://blockstack.org:443"))
78+
assertThat(URI("https://blockstack.org:443").getOrigin(), `is`("https://blockstack.org:443"))
79+
assertThat(URI("https://blockstack.org").getOrigin(), `is`("https://blockstack.org"))
80+
assertThat(URI("https://user@blockstack.org").getOrigin(), `is`("https://blockstack.org"))
81+
assertThat(URI("blockstack://blockstack.id").getOrigin(), `is`("blockstack://blockstack.id"))
82+
}
7383
}
7484

0 commit comments

Comments
 (0)