Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch invoice decoding exceptions #567

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ kotlin {

val commonMain by sourceSets.getting {
dependencies {
api("fr.acinq.bitcoin:bitcoin-kmp:0.14.0") // when upgrading, keep secp256k1-kmp-jni-jvm in sync below
api("fr.acinq.bitcoin:bitcoin-kmp:0.15.0") // when upgrading, keep secp256k1-kmp-jni-jvm in sync below
api("org.kodein.log:canard:0.18.0")
api("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion")
api("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
Expand Down Expand Up @@ -63,7 +63,7 @@ kotlin {
api(ktor("client-okhttp"))
api(ktor("network"))
api(ktor("network-tls"))
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm:0.11.0")
implementation("fr.acinq.secp256k1:secp256k1-kmp-jni-jvm:0.12.0")
implementation("org.slf4j:slf4j-api:1.7.36")
api("org.xerial:sqlite-jdbc:3.32.3.2")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ data class PaymentRequest(
return loop(input, listOf())
}

fun read(input: String): PaymentRequest {
fun read(input: String): Try<PaymentRequest> = runTrying {
val (hrp, data) = Bech32.decode(input)
val prefix = prefixes.values.find { hrp.startsWith(it) } ?: throw IllegalArgumentException("unknown prefix $hrp")
val amount = decodeAmount(hrp.drop(prefix.length))
Expand Down Expand Up @@ -217,8 +217,8 @@ data class PaymentRequest(

loop(data.drop(7).dropLast(104))
val pr = PaymentRequest(prefix, amount, timestamp, nodeId, tags, sigandrecid.toByteVector())
require(pr.signedPreimage().contentEquals(tohash))
return pr
require(pr.signedPreimage().contentEquals(tohash)) { "invoice isn't canonically encoded" }
pr
}

fun decodeAmount(input: String): MilliSatoshi? {
Expand Down
Loading
Loading