Skip to content

Commit

Permalink
Improve Java compatibility (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc authored Feb 22, 2024
1 parent 8f21686 commit 50b9c34
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ val jvmVersion = JavaVersion.VERSION_11

allprojects {
group = "org.stellar.wallet-sdk"
version = "1.2.1"
version = "1.2.2"
}

subprojects {
Expand Down
21 changes: 17 additions & 4 deletions wallet-sdk/src/main/kotlin/org/stellar/walletsdk/auth/Sep10.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import io.ktor.http.*
import java.util.*
import kotlinx.datetime.Clock
import mu.KotlinLogging
import org.stellar.sdk.Network
Expand All @@ -14,6 +13,8 @@ import org.stellar.walletsdk.exception.*
import org.stellar.walletsdk.horizon.AccountKeyPair
import org.stellar.walletsdk.util.Util.authGet
import org.stellar.walletsdk.util.Util.postJson
import java.math.BigInteger
import java.util.*

private val log = KotlinLogging.logger {}

Expand Down Expand Up @@ -46,7 +47,19 @@ internal constructor(
clientDomain: String? = null
): AuthToken {
val challengeTxn =
challenge(accountAddress, memoId, clientDomain ?: cfg.app.defaultClientDomain)
challenge(accountAddress, memoId?.toString(), clientDomain ?: cfg.app.defaultClientDomain)
val signedTxn = sign(accountAddress, challengeTxn, walletSigner ?: cfg.app.defaultSigner)
return getToken(signedTxn)
}

suspend fun authenticateBigInt(
accountAddress: AccountKeyPair,
walletSigner: WalletSigner? = null,
memoId: BigInteger? = null,
clientDomain: String? = null
): AuthToken {
val challengeTxn =
challenge(accountAddress, memoId?.toString(), clientDomain ?: cfg.app.defaultClientDomain)
val signedTxn = sign(accountAddress, challengeTxn, walletSigner ?: cfg.app.defaultSigner)
return getToken(signedTxn)
}
Expand All @@ -63,7 +76,7 @@ internal constructor(
@Suppress("ThrowsCount")
private suspend fun challenge(
account: AccountKeyPair,
memoId: ULong? = null,
memoId: String? = null,
clientDomain: String? = null
): ChallengeResponse {
val url = URLBuilder(webAuthEndpoint)
Expand All @@ -73,7 +86,7 @@ internal constructor(
url.parameters.append("home_domain", homeDomain)

if (memoId != null) {
url.parameters.append("memo", memoId.toString())
url.parameters.append("memo", memoId)
}

if (!clientDomain.isNullOrBlank()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ sealed interface AccountKeyPair {
get() = keyPair.publicKey
}

@JvmInline
value class PublicKeyPair(override val keyPair: KeyPair) : AccountKeyPair {
data class PublicKeyPair(override val keyPair: KeyPair) : AccountKeyPair {
override fun toString() = "${PublicKeyPair::class.simpleName}(address=$address)"
}

@JvmInline
value class SigningKeyPair(override val keyPair: KeyPair) : AccountKeyPair {
data class SigningKeyPair(override val keyPair: KeyPair) : AccountKeyPair {
init {
require(keyPair.canSign()) { "This keypair doesn't have private key and can't sign" }
}
Expand All @@ -35,6 +33,7 @@ value class SigningKeyPair(override val keyPair: KeyPair) : AccountKeyPair {
}

companion object {
@JvmStatic
fun fromSecret(secret: String): SigningKeyPair {
return SigningKeyPair(KeyPair.fromSecretSeed(secret))
}
Expand Down

0 comments on commit 50b9c34

Please sign in to comment.