Skip to content

Commit

Permalink
Merge pull request #22 from WalletConnect/update_khex
Browse files Browse the repository at this point in the history
Closes #21: Update khex
  • Loading branch information
rmeissner authored Dec 11, 2019
2 parents 112a162 + 50fff5e commit 4d5ce1c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
8 changes: 3 additions & 5 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"

implementation "com.github.komputing:khex:0.6"
implementation "com.github.komputing:khex:1.0.0-RC6"

implementation 'org.bouncycastle:bcprov-jdk15on:1.64'

Expand All @@ -20,11 +20,9 @@ dependencies {

implementation "com.squareup.okhttp3:okhttp:$versions.okhttp"

implementation group: 'org.slf4j', name: 'slf4j-log4j12', version: "1.7.25"

testImplementation 'org.assertj:assertj-core:3.14.0'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.3.2'
testCompile 'org.junit.jupiter:junit-jupiter-params:5.3.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.3.2'
testRuntime 'org.junit.jupiter:junit-jupiter-engine:5.3.2'


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import org.bouncycastle.crypto.paddings.PKCS7Padding
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher
import org.bouncycastle.crypto.params.KeyParameter
import org.bouncycastle.crypto.params.ParametersWithIV
import org.komputing.khex.decode
import org.komputing.khex.extensions.toNoPrefixHexString
import org.walletconnect.Session
import org.walletconnect.nullOnThrow
import org.walletconnect.types.*
import org.walleth.khex.hexToByteArray
import org.walleth.khex.toNoPrefixHexString
import java.security.SecureRandom

class MoshiPayloadAdapter(moshi: Moshi) : Session.PayloadAdapter {
Expand All @@ -42,12 +41,12 @@ class MoshiPayloadAdapter(moshi: Moshi) : Session.PayloadAdapter {
padding
)
val ivAndKey = ParametersWithIV(
KeyParameter(key.hexToByteArray()),
encryptedPayload.iv.hexToByteArray()
KeyParameter(decode(key)),
decode(encryptedPayload.iv)
)
aes.init(false, ivAndKey)

val encryptedData = encryptedPayload.data.hexToByteArray()
val encryptedData = decode(encryptedPayload.data)
val minSize = aes.getOutputSize(encryptedData.size)
val outBuf = ByteArray(minSize)
var len = aes.processBytes(encryptedData, 0, encryptedData.size, outBuf, 0)
Expand All @@ -58,7 +57,7 @@ class MoshiPayloadAdapter(moshi: Moshi) : Session.PayloadAdapter {

override fun prepare(data: Session.MethodCall, key: String): String {
val bytesData = data.toBytes()
val hexKey = key.hexToByteArray()
val hexKey = decode(key)
val iv = createRandomBytes(16)

val padding = PKCS7Padding()
Expand Down
4 changes: 2 additions & 2 deletions sample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies {

implementation "org.java-websocket:Java-WebSocket:1.4.0"

implementation "com.github.walleth:khex:0.6"
implementation "com.github.komputing:khex:1.0.0-RC6"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}"

Expand All @@ -64,4 +64,4 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import androidx.multidex.MultiDexApplication
import com.squareup.moshi.Moshi
import io.walletconnect.example.server.BridgeServer
import okhttp3.OkHttpClient
import org.komputing.khex.extensions.toNoPrefixHexString
import org.walletconnect.Session
import org.walletconnect.impls.*
import org.walletconnect.nullOnThrow
import org.walleth.khex.toNoPrefixHexString
import java.io.File
import java.util.*

Expand Down Expand Up @@ -59,4 +59,4 @@ class ExampleApplication : MultiDexApplication() {
session.offer()
}
}
}
}
19 changes: 15 additions & 4 deletions sample/app/src/main/java/io/walletconnect/example/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ class MainActivity : Activity(), Session.Callback {
private var txRequest: Long? = null
private val uiScope = CoroutineScope(Dispatchers.Main)

override fun handleMethodCall(call: Session.MethodCall) {
override fun onStatus(status: Session.Status) {
when(status) {
Session.Status.Approved -> sessionApproved()
Session.Status.Closed -> sessionClosed()
Session.Status.Connected,
Session.Status.Disconnected,
is Session.Status.Error -> {
// Do Stuff
}
}
}

override fun sessionApproved() {
override fun onMethodCall(call: Session.MethodCall) {
}
private fun sessionApproved() {
uiScope.launch {
screen_main_status.text = "Connected: ${ExampleApplication.session.approvedAccounts()}"
screen_main_connect_button.visibility = View.GONE
Expand All @@ -30,7 +41,7 @@ class MainActivity : Activity(), Session.Callback {
}
}

override fun sessionClosed() {
private fun sessionClosed() {
uiScope.launch {
screen_main_status.text = "Disconnected"
screen_main_connect_button.visibility = View.VISIBLE
Expand Down Expand Up @@ -70,7 +81,7 @@ class MainActivity : Activity(), Session.Callback {
null,
null,
"0x5AF3107A4000",
""bu
""
),
::handleResponse
)
Expand Down

0 comments on commit 4d5ce1c

Please sign in to comment.