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

Improve Java compatibility #126

Merged
merged 1 commit into from
Feb 22, 2024
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
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
Loading