Skip to content

Commit 3468b47

Browse files
committed
Check address validity with ERC55
1 parent b5f99af commit 3468b47

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ dependencies {
2929
implementation "com.github.walleth.kethereum:extensions_transactions:${KETHEREUM_VERSION}"
3030
implementation "com.github.walleth.kethereum:flows:${KETHEREUM_VERSION}"
3131
implementation "com.github.walleth.kethereum:rpc:${KETHEREUM_VERSION}"
32+
implementation "com.github.walleth.kethereum:erc55:${KETHEREUM_VERSION}"
3233
implementation "com.github.walleth.kethereum:rpc_min3:${KETHEREUM_VERSION}"
3334
implementation "com.github.walleth.kethereum:model:${KETHEREUM_VERSION}"
3435
implementation "com.github.walleth.kethereum:crypto:${KETHEREUM_VERSION}"

src/main/kotlin/org/komputing/fauceth/Application.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.kethereum.crypto.createEthereumKeyPair
1616
import org.kethereum.crypto.toAddress
1717
import org.kethereum.crypto.toECKeyPair
1818
import org.kethereum.eip155.signViaEIP155
19+
import org.kethereum.erc55.isValid
1920
import org.kethereum.extensions.transactions.encodeLegacyTxRLP
2021
import org.kethereum.model.*
2122
import org.kethereum.rpc.HttpEthereumRPC
@@ -85,15 +86,15 @@ fun Application.module() {
8586
val receiveParameters = call.receiveParameters()
8687

8788
val captchaResult: Boolean = verifyCaptcha(receiveParameters["h-captcha-response"] ?: "", hcaptchaSecret)
88-
val address = receiveParameters[ADDRESS_KEY]
89-
if (address?.length != 42) {
89+
val address = Address(receiveParameters[ADDRESS_KEY]?:"")
90+
if (!address.isValid()) {
9091
call.respondText("""Swal.fire("Error", "Address invalid", "error");""")
9192
} else if (!captchaResult) {
9293
call.respondText("""Swal.fire("Error", "Could not verify your humanity", "error");""")
9394
} else {
9495

9596
val tx = createEmptyTransaction().apply {
96-
to = Address(address)
97+
to = address
9798
value = ETH_IN_WEI
9899
nonce = atomicNonce.getAndIncrement()
99100
gasLimit = DEFAULT_GAS_LIMIT

0 commit comments

Comments
 (0)