Skip to content

Commit ebacb61

Browse files
authored
Merge pull request #1 from WalletConnect/develop
Merge develop into master
2 parents b05a199 + 2113637 commit ebacb61

File tree

167 files changed

+5196
-1892
lines changed

Some content is hidden

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

167 files changed

+5196
-1892
lines changed

README.md

Lines changed: 196 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,69 +9,241 @@ Kotlin implementation of WalletConnect v2 protocol for Android applications.
99
* Java 11
1010

1111
## Installation
12-
root/build.gradle:
12+
root/build.gradle.kts:
1313

1414
```gradle
1515
allprojects {
1616
repositories {
17-
maven { url "https://jitpack.io" }
17+
maven(url = "https://jitpack.io")
1818
}
1919
}
2020
```
2121

2222
<br>
2323

24-
app/build.gradle(.kts)
24+
app/build.gradle
2525

2626
```gradle
27-
groovy - implementation 'com.walletconnect:walletconnectv2:1.0.0-alpha01'
28-
29-
kotlin - implementation("com.walletconnect:walletconnectv2:1.0.0-alpha01")
30-
27+
implementation("com.walletconnect:walletconnectv2:1.0.0-beta01")
3128
```
3229

3330
## **Usage**
3431

3532
### **Initialize WalletConnect Client**
3633
```kotlin
37-
val initializeParams = ClientTypes.InitialParams(useTls = true, hostName = "relay.walletconnect.org", apiKey = "sample key", isController = true)
34+
val appMetaData = AppMetaData(name = "Wallet Name", description = "Wallet Description", url = "Wallet Url", icons = listOfIconUrlStrings)
35+
val initializeParams = ClientTypes.InitialParams(application = application, projectId = "project id", appMetaData = appMetaData)
3836
WalletConnectClient.initalize(initalizeParams)
3937
```
40-
The controller client will always be the "wallet" which is exposing blockchain accounts to a "Dapp" and therefore is also in charge of signing.
41-
To initialize the WalletConnect client, create a ClientTypes.InitialParams object in the Android Application class. The InitialParams object will need at least the API key and the Application. The InitialParams object will then be passed to the WalletConnect.initialize function.
38+
39+
The controller client will always be the wallet which is exposing blockchain accounts to a Dapp and therefore is also in charge of signing.
40+
To initialize the WalletConnect client, create a `ClientTypes.InitialParams` object in the Android Application class. The InitialParams object will need at least the application class, the ProjectID and the wallet's AppMetaData. The InitialParams object will then be passed to the `WalletConnectClient` initialize function. IntitalParams also allows for custom URLs by passing URL string into the `hostName` property.
41+
42+
### **WalletConnectClientListeners.Session Listeners**
43+
```kotlin
44+
val listener = object: WalletConnectClientListener {
45+
override fun onSessionProposal(sessionProposal: WalletConnectClientData.SessionProposal) {
46+
// Session Proposal object sent by Dapp after pairing was successful
47+
}
48+
49+
override fun onSessionRequest(sessionRequest: WalletConnectClientData.SessionRequest) {
50+
// JSON-RPC methods wrapped by SessionRequest object sent by Dapp
51+
}
52+
53+
override fun onSessionDelete(deletedSession: WalletConnectClientData.DeletedSession) {
54+
// Triggered when the session is deleted by the peer
55+
}
56+
57+
override fun onSessionNotification(sessionNotification: WalletConnectClientData.SessionNotification) {
58+
// Triggered when the peer emits events as notifications that match the list of types agreed upon session settlement
59+
}
60+
}
61+
WalletConnectClient.setWalletConnectListener(listener)
62+
```
63+
64+
The WalletConnectClient needs a `WalletConnectClientListener` passed to it for it to be able to expose asynchronously updates sent from the Dapp.
4265

4366
### **Pair Clients**
4467
```kotlin
4568
val pairParams = ClientTypes.PairParams("wc:...")
46-
val pairListener = WalletConnectClientListeners.Pairing { sessionProposal -> /* handle session proposal */ }
69+
val pairListener = object: WalletConnectClientListeners.Pairing {
70+
override fun onSuccess(settledPairing: WalletConnectClientData.SettledPairing) {
71+
// Settled pairing
72+
}
73+
74+
override fun onError(error: Throwable) {
75+
// Pairing approval error
76+
}
77+
}
4778
WalletConnectClient.pair(pairParams, pairListener)
4879
```
4980

50-
To pair the wallet with the Dapp, call the WalletConnectClient.pair function which needs a ClientTypes.PairParams and WalletConnectClientListeners.Pairing.
81+
To pair the wallet with the Dapp, call the WalletConnectClient.pair function which needs a `ClientTypes.PairParams` and `WalletConnectClientListeners.Pairing`.
5182
ClientTypes.Params is where the Dapp Uri will be passed.
52-
WalletConnectClientListeners.Pairing is the callback that will be asynchronously called once there a pairing has been made with the Dapp. A SessionProposal object is returned once a pairing is made.
83+
WalletConnectClientListeners.Pairing is the callback that will be asynchronously called once there a pairing has been made with the Dapp.
5384

5485
### **Session Approval**
86+
NOTE: addresses provided in `accounts` array should follow [CAPI10](https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md) semantics.
5587
```kotlin
5688
val accounts: List<String> = /*list of accounts on chains*/
57-
val proposerPublicKey: String = /*proposerPublicKey from the Session Proposal*/
58-
val proposalTtl: Long = /*Ttl from the Session Proposal*/
59-
val proposalTopic: String = /*Topic from the Session Proposal*/
60-
val approveParams: ClientTypes.ApproveParams = ClientTypes.ApproveParams(accounts, proposerPublicKey, proposalTtl, proposalTopic)
61-
62-
WalletConnectClient.approve(approveParams)
89+
val sessionProposal: WalletConnectClientData = /*Session Proposal object*/
90+
val approveParams: ClientTypes.ApproveParams = ClientTypes.ApproveParams(sessionProposal, accounts)
91+
val listener: WalletConnectClientListeners.SessionApprove {
92+
override fun onSuccess(settledSession: WalletConnectClientData.SettledSession) {
93+
// Approve session success
94+
}
95+
96+
override fun onError(error: Throwable) {
97+
// Approve session error
98+
}
99+
}
100+
WalletConnectClient.approve(approveParams, listener)
63101
```
64-
To send an approval for the Session Proposal, pass the Session Proposal public key, ttl, and topic along with the list of accounts to the WalletConnectClient.approve function.
102+
103+
To send an approval, pass a Session Proposal object along with the list of accounts to the `WalletConnectClient.approve` function. Listener will asynchronously expose the settled session if the operation is successful.
65104

66105
### **Session Rejection**
67106
```kotlin
68107
val rejectionReason: String = /*The reason for rejecting the Session Proposal*/
69108
val proposalTopic: String = /*Topic from the Session Proposal*/
70109
val rejectParams: ClientTypes.RejectParams = ClientTypes.RejectParams(rejectionReason, proposalTopic)
110+
val listener: WalletConnectClientListneners.SessionReject {
111+
override fun onSuccess(rejectedSession: WalletConnectClientData.RejectedSession) {
112+
// Rejection proposal
113+
}
114+
115+
override fun onError(error: Throwable) {
116+
//Rejected proposal error
117+
}
118+
}
119+
WalletConnectClient.reject(rejectParams, listener)
120+
```
121+
To send a rejection for the Session Proposal, pass a rejection reason and the Session Proposal topic to the `WalletConnectClient.reject` function. Listener will asynchronously expose a `RejectedSession` object that will mirror the data sent for rejection.
122+
123+
### **Session Disconnect**
124+
```kotlin
125+
val disconnectionReason: String = /*The reason for disconnecting the Settled Session*/
126+
val sessionTopic: String = /*Topic from the Settled Session*/
127+
val disconnectParams = ClientTypes.DisconnectParams(sessionTopic, disconnectionReason)
128+
val listener = object : WalletConnectClientListeners.SessionDelete {
129+
override fun onSuccess(deletedSession: WalletConnectClientData.DeletedSession) {
130+
// DeleteSession object with topic and reason
131+
}
132+
133+
override fun onError(error: Throwable) {
134+
// Session disconnect error
135+
}
136+
}
137+
138+
WalletConnectClient.disconnect(disconnectParams, listener)
139+
```
140+
To disconnect from a settle session, pass a disconnection reason and the Settled Session topic to the `WalletConnectClient.disconnect` function. Listener will asynchronously expose a DeleteSession object that will mirror the data sent for rejection.
141+
142+
### **Respond Request**
143+
```kotlin
144+
val sessionRequestTopic: String = /*Topic of Settled Session*/
145+
val jsonRpcResponse: WalletConnectClientData.JsonRpcResponse.JsonRpcResult = /*Settled Session Request ID along with request data*/
146+
val result = ClientTypes.ResponseParams(sessionTopic = sessionRequestTopic, jsonRpcResponse = jsonRpcResponse)
147+
val listener = object : WalletConnectClientListeners.SessionPayload {
148+
override fun onError(error: Throwable) {
149+
// Error
150+
}
151+
}
152+
153+
WalletConnectClient.respond(result, listener)
154+
```
155+
To respond to JSON-RPC methods that were sent from Dapps for a settle session, submit a `ClientTypes.ResponseParams` with the settled session's topic and request ID along with the respond data to the `WalletConnectClient.respond` function. Any errors would exposed through the `WalletConnectClientListeners.SessionPayload` listener.
156+
157+
### **Reject Request**
158+
```kotlin
159+
val sessionRequestTopic: String = /*Topic of Settled Session*/
160+
val jsonRpcResponseError: WalletConnectClientData.JsonRpcResponse.JsonRpcError = /*Settled Session Request ID along with error code and message*/
161+
val result = ClientTypes.ResponseParams(sessionTopic = sessionRequestTopic, jsonRpcResponse = jsonRpcResponseError)
162+
val listener = object : WalletConnectClientListeners.SessionPayload {
163+
override fun onError(error: Throwable) {
164+
// Error
165+
}
166+
}
167+
168+
WalletConnectClient.respond(result, listener)
169+
```
170+
To reject a JSON-RPC method that was sent from a Dapps for a settle session, submit a `ClientTypes.ResponseParams` with the settled session's topic and request ID along with the rejection data to the `WalletConnectClient.respond` function. Any errors would exposed through the `WalletConnectClientListeners.SessionPayload` listener.
171+
172+
### **Session Update**
173+
```kotlin
174+
val sessionTopic: String = /*Topic of Settled Session*/
175+
val sessionState: WalletConnectClientData.SessionState = /*object with list of accounts to update*/
176+
val updateParams = ClientTypes.UpdateParams(sessionTopic = sessionTopic, sessionState = sessionState)
177+
val listener = object : WalletConnectClientListeners.SessionUpdate {
178+
override fun onSuccess(updatedSession: WalletConnectClientData.UpdatedSession) {
179+
// Callback for when Dapps successfully updates settled session
180+
}
181+
182+
override fun onError(error: Throwable) {
183+
// Error
184+
}
185+
}
186+
187+
WalletConnectClient.update(updateParams, listener)
188+
```
189+
To update a settled session, create a `ClientTypes.UpdateParams` object with the settled session's topic and accounts to update session with to `WalletConnectClient.update`. Listener will echo the accounts updated on the Dapp if action is successful.
190+
191+
### **Session Upgrade**
192+
```kotlin
193+
val sessionTopic: String = /*Topic of Settled Session*/
194+
val permissions: WalletConnectClientData.SessionPermissions = /*list of blockchains and JSON-RPC methods to upgrade with*/
195+
val upgradeParams = ClientTypes.UpgradeParams(sessionTopic = sessionTopic, permissions = permissions)
196+
val listener = object : WalletConnectClientListeners.SessionUpgrade {
197+
override fun onSuccess(upgradedSession: WalletConnectClientData.UpgradedSession) {
198+
// Callback for when Dapps successfully upgrades settled session
199+
}
200+
201+
override fun onError(error: Throwable) {
202+
// Error
203+
}
204+
}
71205

72-
WalletConnectClient.reject(rejectParams)
206+
WalletConnectClient.upgrade(upgradeParams, listener)
73207
```
74-
To send a rejection for the Session Proposal, pass a rejection reason and the Session Proposal public key to the WalletConnectClient.approve function.
208+
To upgrade a settled session, create a `ClientTypes.UpgradeParams` object with the settled session's topic and blockchains and JSON-RPC methods to upgrade the session with to `WalletConnectClient.upgrade`. Listener will echo the blockchains and JSON-RPC methods upgraded on the Dapp if action is successful.
209+
210+
### **Session Ping**
211+
```kotlin
212+
val sessionTopic: String = /*Topic of Settled Session*/
213+
val pingParams = ClientTypes.PingParams(sessionTopic)
214+
val listener = object : WalletConnectClientListeners.SessionPing {
215+
override fun onSuccess(topic: String) {
216+
// Topic being pinged
217+
}
218+
219+
override fun onError(error: Throwable) {
220+
// Error
221+
}
222+
}
223+
224+
WalletConnectClient.ping(pingParams, listener)
225+
```
226+
To ping a Dapp with a settled session, call `WalletConnectClient.ping` with the `ClientTypes.PingParams` with a settle session's topic. If ping is successful, topic is echo'd in listener.
227+
228+
### **Get List of Settled Sessions**
229+
```kotlin
230+
WalletConnectClient.getListOfSettledSessions()
231+
```
232+
To get a list of the most current setteld sessions, call `WalletConnectClient.getListOfSettledSessions()` which will return a list of type `WalletConnectClientData.SettledSession`.
233+
234+
### **Get List of Pending Sessions**
235+
```kotlin
236+
WalletConnectClient.getListOfPendingSession()
237+
```
238+
To get a list of the most current pending sessions, call `WalletConnectClient.getListOfPendingSession()` which will return a list of type `WalletConnectClientData.SessionProposal`.
239+
240+
### **Shutdown SDK**
241+
```kotlin
242+
WalletConnectClient.shutdown()
243+
```
244+
To make sure that the internal coroutines are handled correctly when leaving the application, call `WalletConnectClient.shutdown()` before exiting from the application.
245+
<br>
246+
247+
## API Keys
75248

76-
### **Contributing**
77-
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
249+
For api keys look at [API Keys](../../api/api-keys.md)

build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ buildscript {
55
mavenCentral()
66
}
77
dependencies {
8-
classpath ("com.android.tools.build:gradle:7.0.3")
8+
classpath ("com.android.tools.build:gradle:7.0.4")
99
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
10+
classpath("com.squareup.sqldelight:gradle-plugin:$sqlDelightVersion")
1011
}
1112
}
1213

1314
allprojects {
1415
repositories {
1516
google()
17+
maven(url = "https://jitpack.io")
1618
mavenLocal()
1719
mavenCentral()
1820
jcenter() // Warning: this repository is going to shut down soon

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import org.gradle.kotlin.dsl.DependencyHandlerScope
33

44
const val kotlinVersion = "1.5.31"
55
val jvmVersion = JavaVersion.VERSION_11
6+
const val sqlDelightVersion = "1.5.2"
67

78
fun DependencyHandlerScope.scanner() {
89
val mlKitBarcode = "16.0.1"
@@ -21,6 +22,7 @@ fun DependencyHandlerScope.lifecycle() {
2122
val lifecycleVersion = "2.3.1"
2223
"implementation"("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion")
2324
"implementation"("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion")
25+
"implementation"("androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha01")
2426
}
2527

2628
fun DependencyHandlerScope.navigationComponent() {
@@ -54,11 +56,6 @@ fun DependencyHandlerScope.moshi() {
5456
"kapt"("com.squareup.moshi:moshi-kotlin-codegen:$moshiVersion")
5557
}
5658

57-
fun DependencyHandlerScope.json() {
58-
val jsonVersion = "20210307"
59-
"implementation"("org.json:json:$jsonVersion")
60-
}
61-
6259
fun DependencyHandlerScope.okhttp() {
6360
val okhttpVersion = "4.9.0"
6461

@@ -67,23 +64,45 @@ fun DependencyHandlerScope.okhttp() {
6764
"implementation"("com.squareup.okhttp3:logging-interceptor")
6865
}
6966

70-
fun DependencyHandlerScope.lazySodium() {
71-
val lazySodiumVersion = "5.0.2@aar"
72-
val jnaVersion = "5.8.0@aar"
73-
val slf4jVersion = "1.7.32"
67+
fun DependencyHandlerScope.bouncyCastle() {
68+
val bouncyCastleVersion = "1.70"
69+
"implementation"("org.bouncycastle:bcprov-jdk15on:$bouncyCastleVersion")
70+
}
71+
72+
fun DependencyHandlerScope.sqlDelight() {
73+
"implementation"("com.squareup.sqldelight:android-driver:$sqlDelightVersion")
74+
"implementation"("com.squareup.sqldelight:coroutines-extensions-jvm:$sqlDelightVersion")
7475

75-
"implementation"("com.goterl:lazysodium-android:$lazySodiumVersion")
76-
"implementation"("net.java.dev.jna:jna:$jnaVersion")
77-
"testImplementation"("org.slf4j:slf4j-nop:$slf4jVersion")
76+
"testImplementation"("com.squareup.sqldelight:sqlite-driver:$sqlDelightVersion")
77+
"testImplementation"("org.xerial:sqlite-jdbc:3.8.10.2") {
78+
// Override the version of sqlite used by sqlite-driver to match Android API 23
79+
isForce = true
80+
}
7881
}
7982

8083
fun DependencyHandlerScope.jUnit5() {
8184
val jUnit5Version = "5.7.2"
8285

86+
"testImplementation"("androidx.test.ext:junit-ktx:1.1.3")
87+
"testImplementation"("androidx.test:core-ktx:1.4.0")
8388
"testImplementation"(platform("org.junit:junit-bom:$jUnit5Version"))
8489
"testImplementation"("org.junit.jupiter:junit-jupiter-api:$jUnit5Version")
8590
"testRuntimeOnly"("org.junit.jupiter:junit-jupiter-engine:$jUnit5Version")
8691
"testImplementation"("org.jetbrains.kotlin:kotlin-test-junit5:$kotlinVersion")
92+
93+
"androidTestImplementation"("androidx.test:core-ktx:1.4.0")
94+
"androidTestImplementation"("androidx.test:runner:1.4.0")
95+
"androidTestImplementation"("androidx.test:rules:1.4.0")
96+
97+
"androidTestImplementation"("org.junit.jupiter:junit-jupiter-api:$jUnit5Version")
98+
"androidTestImplementation"("de.mannodermaus.junit5:android-test-core:1.3.0")
99+
"androidTestRuntimeOnly"("de.mannodermaus.junit5:android-test-runner:1.3.0")
100+
}
101+
102+
fun DependencyHandlerScope.robolectric() {
103+
val robolectricVersion = "4.6"
104+
105+
"testImplementation"("org.robolectric:robolectric:$robolectricVersion")
87106
}
88107

89108
fun DependencyHandlerScope.mockk() {
@@ -96,4 +115,9 @@ fun DependencyHandlerScope.timber() {
96115
val timberVersion = "5.0.1"
97116

98117
"implementation"("com.jakewharton.timber:timber:$timberVersion")
118+
}
119+
120+
fun DependencyHandlerScope.security() {
121+
val androidSecurityVersion = "1.0.0"
122+
"implementation"("androidx.security:security-crypto:$androidSecurityVersion")
99123
}

gradle.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
1010
# When configured, Gradle will run in incubating parallel mode.
1111
# This option should only be used with decoupled projects. More details, visit
1212
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13-
# org.gradle.parallel=true
13+
org.gradle.parallel=true
1414
# AndroidX package structure to make it clearer which packages are bundled with the
1515
# Android operating system, and which are packaged with your app"s APK
1616
# https://developer.android.com/topic/libraries/support-library/androidx-rn
1717
android.useAndroidX=true
18+
android.enableJetifier=true
1819
# Kotlin code style for this project: "official" or "obsolete":
1920
kotlin.code.style=official

jitpack.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jdk:
2+
- openjdk11

0 commit comments

Comments
 (0)