Skip to content

Commit a837ca9

Browse files
vishnumadnevotgnabAMITGOELNYAmit Goel
authored
Add Android Native SDK (coinbase#594)
* first commit * ios example app scaffolding * README * Update README.md * pod * integrate pod * Create .codeflow.yml * remove example on pod * cleanup * cleanup * handshake * handshake request encoder / response handler * ios proof of concept * Update README.md * reorg * host example app * build settings * cleanup * request message renderer * url rendering * isCoinbaseWalletInstalled * refactor * key manager * url codable / task manager pod * make request * reintroduce message renderer * dedup Message with custom coding * response handler * key storage * hmmmmm * key storage / no error throwing during init * add domain to key storage * response handling / error handling * distinguish request/response types * access control * initial request * host example app * host * handle encrypted response * simplify symkey generation flow * rename Update README.md Update README.md * update path * ios 12 support * make RawRepresentableKey public * clean up cryptography * RawRepresentableKey * make initialzier public * ugh * hmmmmm * Add prototype client app and client sdk (#3) * refactor associated value structure * TaskManager * Update README.md * Update README.md * Update README.md * add field name for encruypted data * sample host app * reorg * move under packages * readme * sample ios client app * pod settings * add `optional` filed to `Action` * Update README.md * update example app * define ReturnType * Update README.md Update README.md * Add actions to handshake function * Update return value * introduce Web3JSONRPC helper * nested params * access control * # This is a combination of 2 commits. # This is the 1st commit message: access control # This is the commit message #2: Revert "access control" This reverts commit c8ea3da. * remove public initializers access control # This is the commit message #2: Revert "access control" This reverts commit c8ea3da. # This is the commit message #3: remove public initializers * use JSONSerialization to simplify Web3JSONRPC encoding * singleton * clean up error type * host example * Creates WalletSDK Android Demo application (coinbase#587) * Configures view and client side processing to integrate with the coinbase wallet. Co-authored-by: Amit Goel <[email protected]> * ios example app * example app * Refactor encryption/decryption serializers * Downgrade gradle version * add timestamp to message * allow custom scheme / keystorage error message * keystorageerror * resolve missing imports * ios example app * Add web3 methods * sampel ios app * response handler * swizzle * update request on sample app * cleanup keymanager implementation * Update json decoding/encoding * Update Demo App to support RemoveAccount * small UI changes * displays appropriate CTA's on connected state * fix send and sign transaction mapping to WEB3 string * Reverted sharedpref `apply()` back to `commit()` * Make java interop nicer Co-authored-by: Jungho Bang <[email protected]> Co-authored-by: Amit Goel <[email protected]> Co-authored-by: Amit Goel <[email protected]>
1 parent 9d538c3 commit a837ca9

File tree

79 files changed

+2623
-0
lines changed

Some content is hidden

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

79 files changed

+2623
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Packages
44

55
- [wallet-sdk](packages/wallet-sdk/): web
6+
- [wallet-native-sdk](packages/wallet-native-sdk/): native
67

78
## License
89

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea
5+
/.idea/caches
6+
/.idea/libraries
7+
/.idea/modules.xml
8+
/.idea/workspace.xml
9+
/.idea/navEditor.xml
10+
/.idea/assetWizardSettings.xml
11+
.DS_Store
12+
/build
13+
/captures
14+
.externalNativeBuild
15+
.cxx
16+
local.properties

examples/native-sdk-android-client/.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[{*.kt, *.kts}]
2+
max_line_length = 120
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'org.jetbrains.kotlin.android'
4+
}
5+
6+
android {
7+
compileSdk 32
8+
9+
defaultConfig {
10+
applicationId "com.coinbase.android.beta"
11+
minSdk 23
12+
targetSdk 32
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
kotlinOptions {
30+
jvmTarget = '1.8'
31+
}
32+
buildFeatures {
33+
viewBinding true
34+
}
35+
}
36+
37+
dependencies {
38+
implementation 'androidx.core:core-ktx:1.8.0'
39+
implementation 'androidx.appcompat:appcompat:1.4.2'
40+
implementation 'com.google.android.material:material:1.6.1'
41+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
42+
testImplementation 'junit:junit:4.13.2'
43+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
44+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
45+
46+
implementation project(':nativesdk')
47+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.coinbase.android.beta
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.coinbase.android.beta", appContext.packageName)
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
package="com.coinbase.android.beta">
5+
6+
<application
7+
android:allowBackup="true"
8+
android:dataExtractionRules="@xml/data_extraction_rules"
9+
android:fullBackupContent="@xml/backup_rules"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/Theme.ClientApp"
15+
tools:targetApi="31">
16+
<activity
17+
android:name=".MainActivity"
18+
android:exported="true">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
<queries>
28+
<package android:name="org.toshi" />
29+
</queries>
30+
</manifest>
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package com.coinbase.android.beta
2+
3+
import android.content.Intent
4+
import android.net.Uri
5+
import android.os.Bundle
6+
import androidx.activity.result.ActivityResultLauncher
7+
import androidx.activity.result.contract.ActivityResultContracts
8+
import androidx.appcompat.app.AppCompatActivity
9+
import androidx.core.view.isVisible
10+
import com.coinbase.android.beta.databinding.ActivityMainBinding
11+
import com.coinbase.android.nativesdk.CoinbaseWalletSDK
12+
import com.coinbase.android.nativesdk.message.request.RequestContent
13+
import com.coinbase.android.nativesdk.message.request.Web3JsonRPC
14+
import com.coinbase.android.nativesdk.message.response.ReturnValue
15+
16+
class MainActivity : AppCompatActivity() {
17+
18+
private lateinit var binding: ActivityMainBinding
19+
private lateinit var launcher: ActivityResultLauncher<Intent>
20+
21+
private val client by lazy {
22+
CoinbaseWalletSDK(
23+
appContext = applicationContext,
24+
domain = Uri.parse("https://www.coinbase.com"),
25+
openIntent = { intent -> launcher.launch(intent) }
26+
)
27+
}
28+
29+
override fun onCreate(savedInstanceState: Bundle?) {
30+
super.onCreate(savedInstanceState)
31+
binding = ActivityMainBinding.inflate(layoutInflater)
32+
setContentView(binding.root)
33+
34+
launcher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
35+
val uri = result.data?.data ?: return@registerForActivityResult
36+
client.handleResponse(uri)
37+
}
38+
}
39+
40+
override fun onStart() = with(binding) {
41+
super.onStart()
42+
43+
setVisibility()
44+
connectWalletButton.setOnClickListener {
45+
client.initiateHandshake(
46+
initialActions = listOf(
47+
Web3JsonRPC.RequestAccounts().action(), //Web3JsonRPC.SwitchEthereumChain(420).action()
48+
)
49+
) { result: Result<List<ReturnValue>> ->
50+
result
51+
.onSuccess { returnValues: List<ReturnValue> ->
52+
textArea.text = buildString {
53+
append("Handshake Successful\n\n")
54+
returnValues.forEach { returnValue ->
55+
if (returnValue is ReturnValue.Result) {
56+
append("Result: ${returnValue.value}")
57+
}
58+
}
59+
}
60+
setVisibility()
61+
}
62+
.onFailure { err ->
63+
textArea.text = buildString {
64+
append("Handshake Error: \n\n")
65+
append(err.message)
66+
}
67+
}
68+
}
69+
}
70+
71+
personalSign.setOnClickListener {
72+
client.makeRequest(
73+
request = RequestContent.Request(
74+
actions = listOf(
75+
// Web3JsonRPC.SwitchEthereumChain(420).action(),
76+
// Web3JsonRPC.RequestAccounts().action(),
77+
Web3JsonRPC.PersonalSign("0xabcdefabcdefabcdefabcdefabcdefabcdef", "Hello world").action()
78+
)
79+
)
80+
) { result ->
81+
result.fold(
82+
onSuccess = { res ->
83+
// textArea.text = "Request Successful: \n${res.results.joinToString()}"
84+
},
85+
onFailure = { err ->
86+
textArea.text = "Request Error: \n${err.message}"
87+
}
88+
)
89+
}
90+
}
91+
92+
removeAccount.setOnClickListener {
93+
client.resetSession()
94+
setVisibility()
95+
}
96+
}
97+
98+
private fun setVisibility() = with(binding) {
99+
val isConnected = client.hasEstablishedConnection
100+
connectContainer.isVisible = !isConnected
101+
requestContainer.isVisible = isConnected
102+
}
103+
}

0 commit comments

Comments
 (0)