Skip to content

Commit

Permalink
better tonconnect message error
Browse files Browse the repository at this point in the history
  • Loading branch information
polstianka committed Oct 27, 2024
1 parent f951fc0 commit 8404cf0
Show file tree
Hide file tree
Showing 38 changed files with 2,107 additions and 86 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/wallet/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ android {

dependencies {
implementation(Dependence.Koin.core)
implementation(project(Dependence.Wallet.http))
implementation(project(Dependence.Module.tonApi))
implementation(project(Dependence.Lib.network))
implementation(project(Dependence.Lib.blockchain))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.util.Log
import com.tonapps.blockchain.ton.TonNetwork
import com.tonapps.blockchain.ton.extensions.isValidTonAddress
import com.tonapps.blockchain.ton.extensions.toAccountId
import com.tonapps.extensions.currentTimeSeconds
import kotlinx.datetime.Clock
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
Expand All @@ -28,11 +29,7 @@ data class SignRequestEntity(
val from: AddrStd?
get() {
val value = fromValue ?: return null
return try {
AddrStd.parse(value)
} catch (e: Throwable) {
null
}
return AddrStd.parse(value)
}

constructor(json: JSONObject, appUri: Uri) : this(
Expand Down Expand Up @@ -87,12 +84,21 @@ data class SignRequestEntity(
}

private fun parseValidUnit(json: JSONObject): Long {
val value = json.optLong("valid_until", json.optLong("validUntil", 0))
if (value > 1000000000000) {
return value / 1000
val value = json.opt("valid_until") ?: json.opt("validUntil")
if (value == null) {
return 0
}
val validUnit = when (value) {
is Long -> value
is Int -> value.toLong()
is String -> value.toLongOrNull() ?: throw IllegalArgumentException("Invalid validUntil parameter. Expected: int64 (Like ${currentTimeSeconds()}), Received: $value")
else -> throw IllegalArgumentException("Invalid validUntil parameter. Expected: int64 (Like ${currentTimeSeconds()}), Received: $value")
}
if (validUnit > 1000000000000) {
return validUnit / 1000
}
if (value > 1000000000) {
return value
if (validUnit > 1000000000) {
return validUnit
}
return 0
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.tonapps.wallet.data.dapps.entities

import android.net.Uri
import android.os.Parcelable
import android.util.Base64
import com.tonapps.security.CryptoBox
import com.tonapps.security.Sodium
import com.tonapps.security.hex
import kotlinx.parcelize.Parcelize
import org.json.JSONObject

@Parcelize
data class AppConnectEntity(
val accountId: String,
val testnet: Boolean,
Expand All @@ -18,7 +21,7 @@ data class AppConnectEntity(
val proofPayload: String?,
val timestamp: Long = (System.currentTimeMillis() / 1000L),
val pushEnabled: Boolean,
) {
): Parcelable {

enum class Type(val value: Int) {
Internal(1), External(2)
Expand Down Expand Up @@ -59,14 +62,9 @@ data class AppConnectEntity(
}

fun decryptEventMessage(message: String): JSONObject {
var string = "..."
try {
val bytes = Base64.decode(message, Base64.NO_WRAP)
val decrypted = decryptMessage(bytes)
string = decrypted.toString(Charsets.UTF_8)
return JSONObject(string)
} catch (e: Throwable) {
throw IllegalArgumentException("Failed to decrypt message: $message;\nstring = $string", e)
}
val bytes = Base64.decode(message, Base64.NO_WRAP)
val decrypted = decryptMessage(bytes)
val string = decrypted.toString(Charsets.UTF_8)
return JSONObject(string)
}
}
1 change: 1 addition & 0 deletions apps/wallet/http/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
36 changes: 36 additions & 0 deletions apps/wallet/http/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
}

android {
namespace = Build.namespacePrefix("wallet.http")
compileSdk = Build.compileSdkVersion

defaultConfig {
minSdk = Build.minSdkVersion
consumerProguardFiles("consumer-rules.pro")
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
api(platform(Dependence.Firebase.bom))
api(Dependence.Firebase.crashlytics)
api(Dependence.Squareup.okhttp)
api(Dependence.Squareup.okio)
api(Dependence.guava)
implementation(Dependence.Koin.core)
implementation(Dependence.GooglePlay.cronet)
implementation(project(Dependence.Lib.extensions))
implementation(project(Dependence.Lib.network))
}


1 change: 1 addition & 0 deletions apps/wallet/http/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest />
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.tonapps.wallet.http

class HttpClientHolder {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.tonapps.wallet.http

import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module

Loading

0 comments on commit 8404cf0

Please sign in to comment.