diff options
Diffstat (limited to 'wallet/src/commonMain/kotlin/net/taler')
26 files changed, 127 insertions, 134 deletions
diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Base32Crockford.kt b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Base32Crockford.kt index b73f508..88a8ebb 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Base32Crockford.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Base32Crockford.kt @@ -16,20 +16,18 @@ package net.taler.lib.crypto +internal class EncodingException : Exception("Invalid encoding") -class EncodingException : Exception("Invalid encoding") - - -object Base32Crockford { +internal object Base32Crockford { private fun ByteArray.getIntAt(index: Int): Int { val x = this[index].toInt() return if (x >= 0) x else (x + 256) } - private var encTable = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" + private const val encTable = "0123456789ABCDEFGHJKMNPQRSTVWXYZ" - fun encode(data: ByteArray): String { + public fun encode(data: ByteArray): String { val sb = StringBuilder() val size = data.size var bitBuf = 0 @@ -53,7 +51,7 @@ object Base32Crockford { return sb.toString() } - fun decode(encoded: String): ByteArray { + public fun decode(encoded: String): ByteArray { val size = encoded.length var bitpos = 0 var bitbuf = 0 @@ -122,7 +120,7 @@ object Base32Crockford { * @param stringSize size of the string to decode * @return size of the resulting data in bytes */ - fun calculateDecodedDataLength(stringSize: Int): Int { + internal fun calculateDecodedDataLength(stringSize: Int): Int { return stringSize * 5 / 8 } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Crypto.kt b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Crypto.kt index 7ca2ba8..39a2014 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Crypto.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Crypto.kt @@ -36,13 +36,13 @@ internal interface Crypto { fun setupRefreshPlanchet(secretSeed: ByteArray, coinNumber: Int): FreshCoin } -interface HashSha512State { +internal interface HashSha512State { fun update(data: ByteArray): HashSha512State fun final(): ByteArray } -class EddsaKeyPair(val privateKey: ByteArray, val publicKey: ByteArray) -class EcdheKeyPair(val privateKey: ByteArray, val publicKey: ByteArray) -data class FreshCoin(val coinPublicKey: ByteArray, val coinPrivateKey: ByteArray, val bks: ByteArray) { +internal class EddsaKeyPair(val privateKey: ByteArray, val publicKey: ByteArray) +internal class EcdheKeyPair(val privateKey: ByteArray, val publicKey: ByteArray) +internal data class FreshCoin(val coinPublicKey: ByteArray, val coinPrivateKey: ByteArray, val bks: ByteArray) { override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || this::class != other::class) return false @@ -67,12 +67,12 @@ internal expect object CryptoFactory { private val hexArray = arrayOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f') -fun ByteArray.toHexString(): String { +public fun ByteArray.toHexString(): String { val hexChars = CharArray(this.size * 2) for (j in this.indices) { val v = (this[j].toInt() and 0xFF) hexChars[j * 2] = hexArray[v ushr 4] hexChars[j * 2 + 1] = hexArray[v and 0x0F] } - return String(hexChars) + return hexChars.concatToString() } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/CryptoImpl.kt b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/CryptoImpl.kt index 085b44b..95a9156 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/CryptoImpl.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/CryptoImpl.kt @@ -16,7 +16,7 @@ package net.taler.lib.crypto -abstract class CryptoImpl : Crypto { +internal abstract class CryptoImpl : Crypto { companion object { fun Int.toByteArray(): ByteArray { diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Deposit.kt b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Deposit.kt index d63d034..3f6886d 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Deposit.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Deposit.kt @@ -49,7 +49,7 @@ internal class Deposit(private val crypto: Crypto) { val feeDeposit: Amount, val wireInfoHash: String, val denomPublicKey: String, - val denomSignature: String + val denomSignature: String, ) /** @@ -80,7 +80,7 @@ internal class Deposit(private val crypto: Crypto) { /** * URL of the exchange this coin was withdrawn from. */ - val exchangeBaseUrl: String + val exchangeBaseUrl: String, ) /** @@ -97,7 +97,7 @@ internal class Deposit(private val crypto: Crypto) { .put(Base32Crockford.decode(depositInfo.merchantPublicKey)) .put(Base32Crockford.decode(depositInfo.coinPublicKey)) .build() - val coinPriv = Base32Crockford.decode(depositInfo.coinPrivateKey); + val coinPriv = Base32Crockford.decode(depositInfo.coinPrivateKey) val coinSig = crypto.eddsaSign(d, coinPriv) return CoinDepositPermission( coinPublicKey = depositInfo.coinPublicKey, @@ -105,7 +105,7 @@ internal class Deposit(private val crypto: Crypto) { contribution = depositInfo.spendAmount.toJSONString(), denomPublicKey = depositInfo.denomPublicKey, exchangeBaseUrl = depositInfo.exchangeBaseUrl, - denomSignature = depositInfo.denomSignature + denomSignature = depositInfo.denomSignature, ) } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Kdf.kt b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Kdf.kt index ffdefb5..dee2486 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Kdf.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/crypto/Kdf.kt @@ -30,7 +30,7 @@ internal object Kdf { salt: ByteArray, info: ByteArray, sha256: (ByteArray) -> ByteArray, - sha512: (ByteArray) -> ByteArray + sha512: (ByteArray) -> ByteArray, ): ByteArray { //extract val prk = hmacSha512(salt, ikm, sha512) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Amount.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Amount.kt index e7ee929..7a63966 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Amount.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Amount.kt @@ -19,7 +19,7 @@ package net.taler.lib.wallet import net.taler.lib.common.Amount import net.taler.lib.crypto.CryptoImpl.Companion.toByteArray -fun Amount.toByteArray() = ByteArray(8 + 4 + 12).apply { +internal fun Amount.toByteArray() = ByteArray(8 + 4 + 12).apply { value.toByteArray().copyInto(this, 0, 0, 8) fraction.toByteArray().copyInto(this, 8, 0, 4) currency.encodeToByteArray().copyInto(this, 12) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Db.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Db.kt index df809c7..eef0cad 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Db.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Db.kt @@ -39,7 +39,7 @@ internal class FakeDb : Db { private data class Data( val exchanges: HashMap<String, ExchangeRecord> = HashMap(), - val denominations: HashMap<String, ArrayList<DenominationRecord>> = HashMap() + val denominations: HashMap<String, ArrayList<DenominationRecord>> = HashMap(), ) private var data = Data() diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/PaytoUri.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/PaytoUri.kt index 2ae9813..a448f0f 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/PaytoUri.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/PaytoUri.kt @@ -16,10 +16,10 @@ package net.taler.lib.wallet -data class PaytoUri( +internal data class PaytoUri( val targetType: String, val targetPath: String, - val params: Map<String, String> + val params: Map<String, String>, ) { companion object { private const val SCHEMA = "payto://" @@ -38,7 +38,7 @@ data class PaytoUri( val field = it.split('=') if (field.size > 1) put(field[0], field[1]) } - } + }, ) } // end fromString() } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Time.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Time.kt index 6cb5a5c..957598c 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Time.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Time.kt @@ -19,6 +19,6 @@ package net.taler.lib.wallet import net.taler.lib.common.Timestamp import net.taler.lib.crypto.CryptoImpl.Companion.toByteArray -fun Timestamp.roundedToByteArray(): ByteArray = ByteArray(8).apply { +internal fun Timestamp.roundedToByteArray(): ByteArray = ByteArray(8).apply { (truncateSeconds().ms * 1000L).toByteArray().copyInto(this) } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Types.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Types.kt index b068bda..0ae6b9b 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Types.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Types.kt @@ -18,7 +18,7 @@ package net.taler.lib.wallet import net.taler.lib.common.Amount -class CoinRecord( +internal class CoinRecord( /** * Where did the coin come from? Used for recouping coins. */ @@ -73,16 +73,16 @@ class CoinRecord( /** * Status of the coin. */ - val status: CoinStatus + val status: CoinStatus, ) -enum class CoinSourceType(val value: String) { +internal enum class CoinSourceType(val value: String) { WITHDRAW("withdraw"), REFRESH("refresh"), - TIP("tip") + TIP("tip"), } -enum class CoinStatus(val value: String) { +internal enum class CoinStatus(val value: String) { /** * Withdrawn and never shown to anybody. @@ -92,6 +92,6 @@ enum class CoinStatus(val value: String) { /** * A coin that has been spent and refreshed. */ - DORMANT("dormant") + DORMANT("dormant"), } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Utils.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Utils.kt index 498b8a8..5a3b776 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Utils.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/Utils.kt @@ -21,13 +21,11 @@ import io.ktor.client.features.json.JsonFeature import io.ktor.client.features.json.serializer.KotlinxSerializer import io.ktor.client.features.logging.LogLevel import io.ktor.client.features.logging.Logging -import kotlinx.serialization.UnstableDefault import kotlinx.serialization.json.Json -import kotlinx.serialization.json.JsonConfiguration -fun getDefaultHttpClient(): HttpClient = HttpClient { +internal fun getDefaultHttpClient(): HttpClient = HttpClient { install(JsonFeature) { - serializer = KotlinxSerializer(Json(getJsonConfiguration())) + serializer = KotlinxSerializer(getJson()) } install(Logging) { // level = LogLevel.HEADERS @@ -35,7 +33,6 @@ fun getDefaultHttpClient(): HttpClient = HttpClient { } } -@OptIn(UnstableDefault::class) -internal fun getJsonConfiguration() = JsonConfiguration( +internal fun getJson() = Json { ignoreUnknownKeys = true -) +} diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Exchanges.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Exchanges.kt index 2542dd6..b847ebb 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Exchanges.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Exchanges.kt @@ -18,12 +18,12 @@ package net.taler.lib.wallet.api import net.taler.lib.wallet.exchange.ExchangeRecord -data class ExchangeListItem( +public data class ExchangeListItem( val exchangeBaseUrl: String, val currency: String, - val paytoUris: List<String> + val paytoUris: List<String>, ) { - companion object { + internal companion object { fun fromExchangeRecord(exchange: ExchangeRecord): ExchangeListItem? { return if (exchange.details == null || exchange.wireInfo == null) null else ExchangeListItem( @@ -31,13 +31,13 @@ data class ExchangeListItem( currency = exchange.details.currency, paytoUris = exchange.wireInfo.accounts.map { it.paytoUri - } + }, ) } } } -data class GetExchangeTosResult( +public data class GetExchangeTosResult( /** * Markdown version of the current ToS. */ @@ -51,5 +51,5 @@ data class GetExchangeTosResult( /** * Version tag of the last ToS that the user has accepted, if any. */ - val acceptedEtag: String? = null + val acceptedEtag: String? = null, ) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Version.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Version.kt index 12916d3..ddf41db 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Version.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Version.kt @@ -18,9 +18,9 @@ package net.taler.lib.wallet.api import net.taler.lib.common.Version -class SupportedVersions( - val walletVersion: Version, - val exchangeVersion: Version, - val bankVersion: Version, - val merchantVersion: Version +public class SupportedVersions( + public val walletVersion: Version, + public val exchangeVersion: Version, + public val bankVersion: Version, + public val merchantVersion: Version, ) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/WalletApi.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/WalletApi.kt index 026c682..995d3cb 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/WalletApi.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/WalletApi.kt @@ -19,11 +19,11 @@ package net.taler.lib.wallet.api import net.taler.lib.common.Amount public interface WalletApi { - fun getVersions(): SupportedVersions - fun getWithdrawalDetailsForUri(talerWithdrawUri: String): WithdrawalDetailsForUri - fun getWithdrawalDetailsForAmount(exchangeBaseUrl: String, amount: Amount): WithdrawalDetails - fun listExchanges(): List<ExchangeListItem> - fun addExchange(exchangeBaseUrl: String): ExchangeListItem - fun getExchangeTos(exchangeBaseUrl: String): GetExchangeTosResult - fun setExchangeTosAccepted(exchangeBaseUrl: String, acceptedEtag: String) + public fun getVersions(): SupportedVersions + public fun getWithdrawalDetailsForUri(talerWithdrawUri: String): WithdrawalDetailsForUri + public fun getWithdrawalDetailsForAmount(exchangeBaseUrl: String, amount: Amount): WithdrawalDetails + public fun listExchanges(): List<ExchangeListItem> + public fun addExchange(exchangeBaseUrl: String): ExchangeListItem + public fun getExchangeTos(exchangeBaseUrl: String): GetExchangeTosResult + public fun setExchangeTosAccepted(exchangeBaseUrl: String, acceptedEtag: String) } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/WalletFactory.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/WalletFactory.kt index d56f80c..4a72eb7 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/WalletFactory.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/WalletFactory.kt @@ -31,10 +31,10 @@ import net.taler.lib.wallet.operations.Withdraw public expect class WalletFactory { - fun createWalletApi(): WalletApi + public fun createWalletApi(): WalletApi } -internal class WalletApiImpl { +public class WalletApiImpl { private val httpClient: HttpClient = getDefaultHttpClient() private val db: Db = DbFactory().openDb() @@ -43,25 +43,25 @@ internal class WalletApiImpl { private val exchangeManager: Exchange = Exchange(crypto, signature, httpClient, db = db) private val withdrawManager = Withdraw(httpClient, db, crypto, signature, exchangeManager) - fun getVersions(): SupportedVersions { + public fun getVersions(): SupportedVersions { return SupportedVersions( walletVersion = Version(8, 0, 0), exchangeVersion = Version(8, 0, 0), bankVersion = Version(0, 0, 0), - merchantVersion = Version(1, 0, 0) + merchantVersion = Version(1, 0, 0), ) } - suspend fun getWithdrawalDetailsForUri(talerWithdrawUri: String): WithdrawalDetailsForUri { + public suspend fun getWithdrawalDetailsForUri(talerWithdrawUri: String): WithdrawalDetailsForUri { val bankInfo = withdrawManager.getBankInfo(talerWithdrawUri) return WithdrawalDetailsForUri( amount = bankInfo.amount, defaultExchangeBaseUrl = bankInfo.suggestedExchange, - possibleExchanges = emptyList() + possibleExchanges = emptyList(), ) } - suspend fun getWithdrawalDetailsForAmount( + public suspend fun getWithdrawalDetailsForAmount( exchangeBaseUrl: String, amount: Amount ): WithdrawalDetails { @@ -69,37 +69,37 @@ internal class WalletApiImpl { return WithdrawalDetails( tosAccepted = details.exchange.termsOfServiceAccepted, amountRaw = amount, - amountEffective = amount - details.overhead - details.withdrawFee + amountEffective = amount - details.overhead - details.withdrawFee, ) } - suspend fun listExchanges(): List<ExchangeListItem> { + public suspend fun listExchanges(): List<ExchangeListItem> { return db.listExchanges().mapNotNull { exchange -> ExchangeListItem.fromExchangeRecord(exchange) } } - suspend fun addExchange(exchangeBaseUrl: String): ExchangeListItem { + public suspend fun addExchange(exchangeBaseUrl: String): ExchangeListItem { val exchange = exchangeManager.updateFromUrl(exchangeBaseUrl) db.put(exchange) return ExchangeListItem.fromExchangeRecord(exchange) ?: TODO("error handling") } - suspend fun getExchangeTos(exchangeBaseUrl: String): GetExchangeTosResult { + public suspend fun getExchangeTos(exchangeBaseUrl: String): GetExchangeTosResult { val record = db.getExchangeByBaseUrl(exchangeBaseUrl) ?: TODO("error handling") return GetExchangeTosResult( tos = record.termsOfServiceText ?: TODO("error handling"), currentEtag = record.termsOfServiceLastEtag ?: TODO("error handling"), - acceptedEtag = record.termsOfServiceAcceptedEtag + acceptedEtag = record.termsOfServiceAcceptedEtag, ) } - suspend fun setExchangeTosAccepted(exchangeBaseUrl: String, acceptedEtag: String) { + public suspend fun setExchangeTosAccepted(exchangeBaseUrl: String, acceptedEtag: String) { db.transaction { val record = getExchangeByBaseUrl(exchangeBaseUrl) ?: TODO("error handling") val updatedRecord = record.copy( termsOfServiceAcceptedEtag = acceptedEtag, - termsOfServiceAcceptedTimestamp = Timestamp.now() + termsOfServiceAcceptedTimestamp = Timestamp.now(), ) put(updatedRecord) } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Withdrawal.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Withdrawal.kt index 88c96a4..df86881 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Withdrawal.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/api/Withdrawal.kt @@ -32,7 +32,7 @@ public data class WithdrawalDetailsForUri( /** * A list of exchanges that can be used for this withdrawal */ - val possibleExchanges: List<ExchangeListItem> + val possibleExchanges: List<ExchangeListItem>, ) public data class WithdrawalDetails( @@ -49,5 +49,5 @@ public data class WithdrawalDetails( /** * Amount that will be added to the user's wallet balance. */ - val amountEffective: Amount + val amountEffective: Amount, ) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Planchet.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Planchet.kt index fa87348..a343594 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Planchet.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Planchet.kt @@ -75,7 +75,7 @@ internal class Planchet(private val crypto: Crypto) { denomPubHash = Base32Crockford.encode(denomPubHash), reservePub = req.reservePub, withdrawSig = Base32Crockford.encode(sig), - coinEvHash = Base32Crockford.encode(evHash) + coinEvHash = Base32Crockford.encode(evHash), ) } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Recoup.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Recoup.kt index b87eff2..27eb9de 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Recoup.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Recoup.kt @@ -59,7 +59,7 @@ internal class Recoup(private val crypto: Crypto) { /** * Was the coin refreshed (and thus the recoup should go to the old coin)? */ - val refreshed: Boolean + val refreshed: Boolean, ) /** @@ -78,7 +78,7 @@ internal class Recoup(private val crypto: Crypto) { coinSig = Base32Crockford.encode(coinSig), denomPubHash = coin.denomPubHash, denomSig = coin.denomSig, - refreshed = coin.coinSource === REFRESH + refreshed = coin.coinSource === REFRESH, ) } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Refresh.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Refresh.kt index 8098437..42e5f6c 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Refresh.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/crypto/Refresh.kt @@ -101,7 +101,7 @@ internal class Refresh(private val crypto: Crypto) { /** * Base URL for the exchange we're doing the refresh with. */ - val exchangeBaseUrl: String + val exchangeBaseUrl: String, ) data class RefreshPlanchetRecord( @@ -120,7 +120,7 @@ internal class Refresh(private val crypto: Crypto) { /** * Blinding key used. */ - val blindingKey: String + val blindingKey: String, ) /** @@ -131,7 +131,7 @@ internal class Refresh(private val crypto: Crypto) { meltCoin: CoinRecord, meltFee: Amount, newCoinDenominations: DenominationSelectionInfo, - kappa: Int = newCoinDenominations.selectedDenominations.size + kappa: Int = newCoinDenominations.selectedDenominations.size, ) : RefreshSessionRecord { return createRefreshSession(exchangeBaseUrl, meltCoin, meltFee, newCoinDenominations, kappa) { crypto.createEcdheKeyPair() @@ -197,7 +197,7 @@ internal class Refresh(private val crypto: Crypto) { blindingKey = Base32Crockford.encode(fresh.bks), coinEv = Base32Crockford.encode(ev), privateKey = Base32Crockford.encode(fresh.coinPrivateKey), - publicKey = Base32Crockford.encode(fresh.coinPublicKey) + publicKey = Base32Crockford.encode(fresh.coinPublicKey), ) planchets.add(planchet) sessionHashState.update(ev) @@ -231,7 +231,7 @@ internal class Refresh(private val crypto: Crypto) { amountRefreshOutput = totalOutput, amountRefreshInput = valueWithFee, timestampCreated = Timestamp.now(), - finishedTimestamp = null + finishedTimestamp = null, ) } @@ -251,7 +251,7 @@ internal class Refresh(private val crypto: Crypto) { newDenominationHash: String, oldCoinPublicKey: String, transferPublicKey: String, - coinEv: String + coinEv: String, ): String { val coinEvHash = crypto.sha512(Base32Crockford.decode(coinEv)) val coinLink = PurposeBuilder(WALLET_COIN_LINK) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Auditor.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Auditor.kt index 248da8d..996c942 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Auditor.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Auditor.kt @@ -22,7 +22,7 @@ import kotlinx.serialization.Serializable * Auditor information as given by the exchange in /keys. */ @Serializable -data class Auditor( +internal data class Auditor( /** * Auditor's public key. */ @@ -36,14 +36,14 @@ data class Auditor( /** * List of signatures for denominations by the auditor. */ - val denomination_keys: List<AuditorDenomSig> + val denomination_keys: List<AuditorDenomSig>, ) /** * Signature by the auditor that a particular denomination key is audited. */ @Serializable -data class AuditorDenomSig( +internal data class AuditorDenomSig( /** * Denomination public key's hash. */ @@ -52,5 +52,5 @@ data class AuditorDenomSig( /** * The signature. */ - val auditor_sig: String + val auditor_sig: String, ) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Denomination.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Denomination.kt index a515d96..036e4eb 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Denomination.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Denomination.kt @@ -85,14 +85,14 @@ internal data class Denomination( * Signature over the denomination information by the exchange's master * signing key. */ - val master_sig: String + val master_sig: String, ) { fun toDenominationRecord( baseUrl: String, denomPubHash: ByteArray, isOffered: Boolean, isRevoked: Boolean, - status: DenominationStatus + status: DenominationStatus, ): DenominationRecord = DenominationRecord( denomPub = denom_pub, @@ -110,11 +110,11 @@ internal data class Denomination( stampExpireWithdraw = stamp_expire_withdraw, stampStart = stamp_start, status = status, - value = value + value = value, ) } -enum class DenominationStatus { +internal enum class DenominationStatus { /** * Verification was delayed. */ @@ -128,10 +128,10 @@ enum class DenominationStatus { /** * Verified as invalid. */ - VerifiedBad + VerifiedBad, } -data class DenominationRecord( +internal data class DenominationRecord( /** * Value of one coin of the denomination. */ @@ -201,7 +201,7 @@ data class DenominationRecord( /** * Base URL of the exchange. */ - val exchangeBaseUrl: String + val exchangeBaseUrl: String, ) { fun isWithdrawable(now: Timestamp = Timestamp.now()): Boolean { if (isRevoked) return false // can not use revoked denomination @@ -213,15 +213,13 @@ data class DenominationRecord( } } -data class DenominationSelectionInfo( +internal data class DenominationSelectionInfo( val totalCoinValue: Amount, val totalWithdrawCost: Amount, - val selectedDenominations: List<SelectedDenomination> + val selectedDenominations: List<SelectedDenomination>, ) { fun getEarliestDepositExpiry(): Timestamp { - if (selectedDenominations.isEmpty()) return Timestamp( - Timestamp.NEVER - ) + if (selectedDenominations.isEmpty()) return Timestamp.never() var earliest = selectedDenominations[0].denominationRecord.stampExpireDeposit for (i in 1 until selectedDenominations.size) { val stampExpireDeposit = selectedDenominations[i].denominationRecord.stampExpireDeposit @@ -231,4 +229,4 @@ data class DenominationSelectionInfo( } } -data class SelectedDenomination(val count: Int, val denominationRecord: DenominationRecord) +internal data class SelectedDenomination(val count: Int, val denominationRecord: DenominationRecord) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Exchange.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Exchange.kt index e685040..9a6f9e2 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Exchange.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Exchange.kt @@ -49,7 +49,7 @@ internal class Exchange( // using the default Http client adds a json Accept header to each request, so we need a different one // because the exchange is returning XML when it doesn't exactly match a mime type. private val httpNoJsonClient: HttpClient = HttpClient(), - private val db: Db = DbFactory().openDb() + private val db: Db = DbFactory().openDb(), ) { companion object { @@ -75,7 +75,7 @@ internal class Exchange( timestampAdded = now, updateStatus = FetchKeys, updateStarted = now, - updateReason = Initial + updateReason = Initial, ).also { db.put(it) } val recordBeforeUpdate = record.copy() @@ -148,7 +148,7 @@ internal class Exchange( denomPubHash = crypto.sha512(Base32Crockford.decode(d.denom_pub)), isOffered = true, isRevoked = false, - status = Unverified + status = Unverified, ) } @@ -166,7 +166,7 @@ internal class Exchange( val valid = signature.verifyWireAccount( paytoUri = a.paytoUri, signature = a.masterSig, - masterPub = record.details.masterPublicKey + masterPub = record.details.masterPublicKey, ) if (!valid) throw Error("Exchange wire account signature invalid") } @@ -178,7 +178,7 @@ internal class Exchange( val valid = signature.verifyWireFee( type = wireMethod, wireFee = wireFee, - masterPub = record.details.masterPublicKey + masterPub = record.details.masterPublicKey, ) if (!valid) throw Error("Exchange wire fee signature invalid") checkCurrency(record.details.currency, wireFee.wireFee) @@ -187,7 +187,7 @@ internal class Exchange( } val wireInfo = ExchangeWireInfo( accounts = wire.accounts.map { ExchangeBankAccount(it.paytoUri) }, - feesForType = wire.fees + feesForType = wire.fees, ) return record.copy(updateStatus = FetchTerms, wireInfo = wireInfo) } diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/ExchangeRecord.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/ExchangeRecord.kt index bb8bbd1..ca1a42a 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/ExchangeRecord.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/ExchangeRecord.kt @@ -21,7 +21,7 @@ import net.taler.lib.common.Timestamp /** * Exchange record as stored in the wallet's database. */ -data class ExchangeRecord( +internal data class ExchangeRecord( /** * Base url of the exchange. */ @@ -80,7 +80,7 @@ data class ExchangeRecord( val updateStatus: ExchangeUpdateStatus, - val updateReason: ExchangeUpdateReason? = null + val updateReason: ExchangeUpdateReason? = null, ) { init { check(baseUrl == Exchange.normalizeUrl(baseUrl)) { "Base URL was not normalized" } @@ -93,7 +93,7 @@ data class ExchangeRecord( /** * Details about the exchange that we only know after querying /keys and /wire. */ -data class ExchangeDetails( +internal data class ExchangeDetails( /** * Master public key of the exchange. */ @@ -123,20 +123,20 @@ data class ExchangeDetails( /** * Timestamp for last update. */ - val lastUpdateTime: Timestamp + val lastUpdateTime: Timestamp, ) -data class ExchangeWireInfo( +internal data class ExchangeWireInfo( val feesForType: Map<String, List<WireFee>>, - val accounts: List<ExchangeBankAccount> + val accounts: List<ExchangeBankAccount>, ) // TODO is this class needed? -data class ExchangeBankAccount( - val paytoUri: String +internal data class ExchangeBankAccount( + val paytoUri: String, ) -sealed class ExchangeUpdateStatus(val value: String) { +internal sealed class ExchangeUpdateStatus(val value: String) { object FetchKeys : ExchangeUpdateStatus("fetch-keys") object FetchWire : ExchangeUpdateStatus("fetch-wire") object FetchTerms : ExchangeUpdateStatus("fetch-terms") @@ -144,7 +144,7 @@ sealed class ExchangeUpdateStatus(val value: String) { object Finished : ExchangeUpdateStatus("finished") } -sealed class ExchangeUpdateReason(val value: String) { +internal sealed class ExchangeUpdateReason(val value: String) { object Initial : ExchangeUpdateReason("initial") object Forced : ExchangeUpdateReason("forced") object Scheduled : ExchangeUpdateReason("scheduled") diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Keys.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Keys.kt index 12b29db..2a1b0fa 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Keys.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Keys.kt @@ -60,7 +60,7 @@ internal data class Keys( /** * Protocol version. */ - val version: String + val version: String, ) { companion object { /** @@ -76,12 +76,12 @@ internal data class Keys( * Structure of one exchange signing key in the /keys response. */ @Serializable -data class SigningKey( +internal data class SigningKey( val stamp_start: Timestamp, val stamp_expire: Timestamp, val stamp_end: Timestamp, val key: String, - val master_sig: String + val master_sig: String, ) /** @@ -89,9 +89,9 @@ data class SigningKey( * exchange gives us in /keys. */ @Serializable -data class Recoup( +internal data class Recoup( /** * The hash of the denomination public key for which the payback is offered. */ - val h_denom_pub: String + val h_denom_pub: String, ) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Wire.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Wire.kt index 0dca4dd..670a0b9 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Wire.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/exchange/Wire.kt @@ -39,18 +39,18 @@ internal data class Wire( } @Serializable -data class AccountInfo( +internal data class AccountInfo( @SerialName("payto_uri") val paytoUri: String, @SerialName("master_sig") - val masterSig: String + val masterSig: String, ) /** * Wire fees as announced by the exchange. */ @Serializable -data class WireFee( +internal data class WireFee( /** * Fee for wire transfers. */ @@ -75,5 +75,5 @@ data class WireFee( * Signature made by the exchange master key. */ @SerialName("sig") - val signature: String + val signature: String, ) diff --git a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/operations/Withdraw.kt b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/operations/Withdraw.kt index 84851ba..d8e83da 100644 --- a/wallet/src/commonMain/kotlin/net/taler/lib/wallet/operations/Withdraw.kt +++ b/wallet/src/commonMain/kotlin/net/taler/lib/wallet/operations/Withdraw.kt @@ -47,7 +47,7 @@ internal class Withdraw( private val signature: Signature = Signature( crypto ), - private val exchange: Exchange = Exchange(crypto, signature, httpClient, db = db) + private val exchange: Exchange = Exchange(crypto, signature, httpClient, db = db), ) { data class BankDetails( @@ -58,7 +58,7 @@ internal class Withdraw( val suggestedExchange: String?, val confirmTransferUrl: String?, val wireTypes: List<String>, - val extractedStatusUrl: String + val extractedStatusUrl: String, ) @Serializable @@ -75,7 +75,7 @@ internal class Withdraw( @SerialName("suggested_exchange") val suggestedExchange: String?, @SerialName("confirm_transfer_url") - val confirmTransferUrl: String? + val confirmTransferUrl: String?, ) { fun toBankDetails(extractedStatusUrl: String) = BankDetails( amount = amount, @@ -85,7 +85,7 @@ internal class Withdraw( senderPaytoUri = senderPaytoUri, suggestedExchange = suggestedExchange, transferDone = transferDone, - wireTypes = wireTypes + wireTypes = wireTypes, ) } @@ -135,7 +135,7 @@ internal class Withdraw( * Number of currently offered denominations. */ // TODO what is this needed for? - val numOfferedDenoms: Int + val numOfferedDenoms: Int, ) { init { check(exchange.details != null) @@ -167,7 +167,7 @@ internal class Withdraw( internal suspend fun getWithdrawalDetails( exchangeBaseUrl: String, - amount: Amount + amount: Amount, ): WithdrawalDetails { val exchange = exchange.updateFromUrl(exchangeBaseUrl) check(exchange.details != null) @@ -182,7 +182,7 @@ internal class Withdraw( withdrawFee = selectedDenominations.totalWithdrawCost - selectedDenominations.totalCoinValue, overhead = amount - selectedDenominations.totalWithdrawCost, earliestDepositExpiration = selectedDenominations.getEarliestDepositExpiry(), - numOfferedDenoms = possibleDenominations.size + numOfferedDenoms = possibleDenominations.size, ) } @@ -192,7 +192,7 @@ internal class Withdraw( */ internal suspend fun selectDenominations( exchange: ExchangeRecord, - amount: Amount + amount: Amount, ): DenominationSelectionInfo { val exchangeDetails = exchange.details ?: throw Error("Exchange $exchange details not available.") @@ -234,7 +234,7 @@ internal class Withdraw( */ fun getDenominationSelection( amount: Amount, - denoms: List<DenominationRecord> + denoms: List<DenominationRecord>, ): DenominationSelectionInfo { val selectedDenominations = ArrayList<SelectedDenomination>() var totalCoinValue = Amount.zero(amount.currency) @@ -265,7 +265,7 @@ internal class Withdraw( return DenominationSelectionInfo( selectedDenominations = selectedDenominations, totalCoinValue = totalCoinValue, - totalWithdrawCost = totalWithdrawCost + totalWithdrawCost = totalWithdrawCost, ) } |