From 000b081ad8bbb617a58fb0d49ad28b77e5ea1f18 Mon Sep 17 00:00:00 2001 From: Gleb Date: Wed, 21 Feb 2024 14:42:33 -0800 Subject: [PATCH] Improve Java compatibility --- build.gradle.kts | 2 +- .../org/stellar/walletsdk/auth/Sep10.kt | 21 +++++++++++++++---- .../org/stellar/walletsdk/horizon/Account.kt | 7 +++---- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 99f50fdf..65c2c217 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ val jvmVersion = JavaVersion.VERSION_11 allprojects { group = "org.stellar.wallet-sdk" - version = "1.2.1" + version = "1.2.2" } subprojects { diff --git a/wallet-sdk/src/main/kotlin/org/stellar/walletsdk/auth/Sep10.kt b/wallet-sdk/src/main/kotlin/org/stellar/walletsdk/auth/Sep10.kt index 51bc1b00..985aa170 100644 --- a/wallet-sdk/src/main/kotlin/org/stellar/walletsdk/auth/Sep10.kt +++ b/wallet-sdk/src/main/kotlin/org/stellar/walletsdk/auth/Sep10.kt @@ -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 @@ -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 {} @@ -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) } @@ -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) @@ -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()) { diff --git a/wallet-sdk/src/main/kotlin/org/stellar/walletsdk/horizon/Account.kt b/wallet-sdk/src/main/kotlin/org/stellar/walletsdk/horizon/Account.kt index d8a0b034..68a9d7a1 100644 --- a/wallet-sdk/src/main/kotlin/org/stellar/walletsdk/horizon/Account.kt +++ b/wallet-sdk/src/main/kotlin/org/stellar/walletsdk/horizon/Account.kt @@ -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" } } @@ -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)) }