diff --git a/lib/build.gradle b/lib/build.gradle index f10dfeb..4a75727 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -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' @@ -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' diff --git a/lib/src/main/kotlin/org/walletconnect/impls/MoshiPayloadAdapter.kt b/lib/src/main/kotlin/org/walletconnect/impls/MoshiPayloadAdapter.kt index 01a317d..5cec13d 100644 --- a/lib/src/main/kotlin/org/walletconnect/impls/MoshiPayloadAdapter.kt +++ b/lib/src/main/kotlin/org/walletconnect/impls/MoshiPayloadAdapter.kt @@ -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 { @@ -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) @@ -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() diff --git a/sample/app/build.gradle b/sample/app/build.gradle index 3e74f02..9a4acef 100644 --- a/sample/app/build.gradle +++ b/sample/app/build.gradle @@ -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}" @@ -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' -} \ No newline at end of file +} diff --git a/sample/app/src/main/java/io/walletconnect/example/ExampleApplication.kt b/sample/app/src/main/java/io/walletconnect/example/ExampleApplication.kt index 6012e0f..d2e8319 100644 --- a/sample/app/src/main/java/io/walletconnect/example/ExampleApplication.kt +++ b/sample/app/src/main/java/io/walletconnect/example/ExampleApplication.kt @@ -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.* @@ -59,4 +59,4 @@ class ExampleApplication : MultiDexApplication() { session.offer() } } -} \ No newline at end of file +} diff --git a/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt b/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt index 0f83e1d..7c373dd 100644 --- a/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt +++ b/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt @@ -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 @@ -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 @@ -70,7 +81,7 @@ class MainActivity : Activity(), Session.Callback { null, null, "0x5AF3107A4000", - ""bu + "" ), ::handleResponse )