From 0846e816e9160a96e244b612d7d5957dc4f4a341 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 14 Jan 2021 12:37:31 +0600 Subject: [PATCH 01/43] start 0.31.1 --- CHANGELOG.md | 2 ++ gradle.properties | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a667251bd..d72312dc67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # TelegramBotAPI changelog +## 0.31.1 + ## 0.31.0 **THIS UPDATE CONTAINS BREAKING CHANGES** diff --git a/gradle.properties b/gradle.properties index ff09a58916..4cebf58445 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.16 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.31.0 +library_version=0.31.1 github_release_plugin_version=2.2.12 From c0ea479fe313995408d0e90e4639457266051c9d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 14 Jan 2021 14:03:25 +0600 Subject: [PATCH 02/43] add primitives for Telegram Passport API --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 10 +++ .../files/abstracts/TelegramMediaFile.kt | 1 + .../tgbotapi/types/passport/EncryptedData.kt | 20 +++++ .../tgbotapi/types/passport/PassportData.kt | 15 ++++ .../types/passport/encrypted_data/Email.kt | 16 ++++ .../encrypted_data/EncryptedAddress.kt | 16 ++++ .../EncryptedElementSerializer.kt | 86 +++++++++++++++++++ .../EncryptedPersonalDetails.kt | 17 ++++ .../types/passport/encrypted_data/Passport.kt | 37 ++++++++ .../passport/encrypted_data/PassportFile.kt | 25 ++++++ .../passport/encrypted_data/PhoneNumber.kt | 17 ++++ .../TranslatableFilesCollection.kt | 58 +++++++++++++ .../encrypted_data/TranslatableIDDocument.kt | 43 ++++++++++ .../abstracts/EncryptedPassportElement.kt | 17 ++++ .../abstracts/FilesCollection.kt | 10 +++ .../encrypted_data/abstracts/Translatable.kt | 10 +++ .../encrypted_data/abstracts/WithData.kt | 10 +++ .../encrypted_data/abstracts/WithEmail.kt | 9 ++ .../encrypted_data/abstracts/WithFrontSide.kt | 10 +++ .../abstracts/WithPhoneNumber.kt | 9 ++ .../abstracts/WithReverseSide.kt | 10 +++ .../encrypted_data/abstracts/WithSelfie.kt | 10 +++ 22 files changed, 456 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportData.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/FilesCollection.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/Translatable.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithEmail.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithFrontSide.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithPhoneNumber.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithReverseSide.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithSelfie.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index c66d9d81a2..d73d87bb2c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -357,3 +357,13 @@ const val forceField = "force" const val regularPollType = "regular" const val quizPollType = "quiz" + +const val dataField = "data" +const val credentialsField = "credentials" +const val hashField = "hash" +const val translationField = "translation" +const val filesField = "files" +const val frontSideField = "front_side" +const val reverseSideField = "reverse_side" +const val selfieField = "selfie" +const val secretField = "secret" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/abstracts/TelegramMediaFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/abstracts/TelegramMediaFile.kt index f0614a5f48..149391a69c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/abstracts/TelegramMediaFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/files/abstracts/TelegramMediaFile.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.types.FileUniqueId internal const val fileIdField = "file_id" internal const val fileSizeField = "file_size" +internal const val fileDateField = "file_date" internal const val filePathField = "file_path" /** diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt new file mode 100644 index 0000000000..92953f6fee --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt @@ -0,0 +1,20 @@ +package dev.inmo.tgbotapi.types.passport + +import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +typealias Base64EncodedData = String +typealias EncryptedAndBase64EncodedData = String +typealias EncryptedByBotRSAAndBase64EncodedData = String +typealias EncryptedData = String + +@Serializable +data class EncryptedCredentials( + @SerialName(dataField) + val data: EncryptedAndBase64EncodedData, + @SerialName(hashField) + val hash: Base64EncodedData, + @SerialName(secretField) + val secret: EncryptedByBotRSAAndBase64EncodedData +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportData.kt new file mode 100644 index 0000000000..9bf4884791 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportData.kt @@ -0,0 +1,15 @@ +package dev.inmo.tgbotapi.types.passport + +import dev.inmo.tgbotapi.types.credentialsField +import dev.inmo.tgbotapi.types.dataField +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class PassportData( + @SerialName(dataField) + val data: List, + @SerialName(credentialsField) + val credentials: EncryptedCredentials +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt new file mode 100644 index 0000000000..bf641d08de --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.passport.Base64EncodedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithEmail +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +data class Email( + @SerialName(emailField) + override val email: String, + @SerialName(hashField) + override val hash: Base64EncodedData +) : WithEmail { +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt new file mode 100644 index 0000000000..5d10c2f152 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt @@ -0,0 +1,16 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.types.dataField +import dev.inmo.tgbotapi.types.hashField +import dev.inmo.tgbotapi.types.passport.* +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +data class EncryptedAddress( + @SerialName(dataField) + override val data: EncryptedAndBase64EncodedData, + @SerialName(hashField) + override val hash: Base64EncodedData +) : WithData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt new file mode 100644 index 0000000000..c753cd3024 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt @@ -0,0 +1,86 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.types.hashField +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import dev.inmo.tgbotapi.types.typeField +import dev.inmo.tgbotapi.utils.nonstrictJsonFormat +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializer +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder +import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.* + +@Serializer(EncryptedPassportElement::class) +object EncryptedElementSerializer : KSerializer { + private val jsonSerializer = JsonObject.serializer() + override val descriptor: SerialDescriptor = jsonSerializer.descriptor + + override fun deserialize(decoder: Decoder): EncryptedPassportElement { + val json = jsonSerializer.deserialize(decoder) + return when (json[typeField] ?.jsonPrimitive ?.content) { + "personal_details" -> nonstrictJsonFormat.decodeFromJsonElement(EncryptedPersonalDetails.serializer(), json) + "passport" -> nonstrictJsonFormat.decodeFromJsonElement(CommonPassport.serializer(), json) + "driver_license" -> nonstrictJsonFormat.decodeFromJsonElement(DriverLicense.serializer(), json) + "identity_card" -> nonstrictJsonFormat.decodeFromJsonElement(IdentityCard.serializer(), json) + "internal_passport" -> nonstrictJsonFormat.decodeFromJsonElement(InternalPassport.serializer(), json) + "address" -> nonstrictJsonFormat.decodeFromJsonElement(EncryptedAddress.serializer(), json) + "utility_bill" -> nonstrictJsonFormat.decodeFromJsonElement(UtilityBill.serializer(), json) + "bank_statement" -> nonstrictJsonFormat.decodeFromJsonElement(BankStatement.serializer(), json) + "rental_agreement" -> nonstrictJsonFormat.decodeFromJsonElement(RentalAgreement.serializer(), json) + "passport_registration" -> nonstrictJsonFormat.decodeFromJsonElement(PassportRegistration.serializer(), json) + "temporary_registration" -> nonstrictJsonFormat.decodeFromJsonElement(TemporaryRegistration.serializer(), json) + "phone_number" -> nonstrictJsonFormat.decodeFromJsonElement(PhoneNumber.serializer(), json) + "email" -> nonstrictJsonFormat.decodeFromJsonElement(Email.serializer(), json) + else -> UnknownEncryptedPassportElement(json, json[hashField] ?.jsonPrimitive ?.content ?: "") + } + } + + override fun serialize(encoder: Encoder, value: EncryptedPassportElement) { + val json = when (value) { + is EncryptedPersonalDetails -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(EncryptedPersonalDetails.serializer(), value).jsonObject + (typeField to JsonPrimitive("personal_details")) + ) + is CommonPassport -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(CommonPassport.serializer(), value).jsonObject + (typeField to JsonPrimitive("passport")) + ) + is DriverLicense -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(DriverLicense.serializer(), value).jsonObject + (typeField to JsonPrimitive("driver_license")) + ) + is IdentityCard -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(IdentityCard.serializer(), value).jsonObject + (typeField to JsonPrimitive("identity_card")) + ) + is InternalPassport -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(InternalPassport.serializer(), value).jsonObject + (typeField to JsonPrimitive("internal_passport")) + ) + is EncryptedAddress -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(EncryptedAddress.serializer(), value).jsonObject + (typeField to JsonPrimitive("address")) + ) + is UtilityBill -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(UtilityBill.serializer(), value).jsonObject + (typeField to JsonPrimitive("utility_bill")) + ) + is BankStatement -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(BankStatement.serializer(), value).jsonObject + (typeField to JsonPrimitive("bank_statement")) + ) + is RentalAgreement -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(RentalAgreement.serializer(), value).jsonObject + (typeField to JsonPrimitive("rental_agreement")) + ) + is PassportRegistration -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(PassportRegistration.serializer(), value).jsonObject + (typeField to JsonPrimitive("passport_registration")) + ) + is TemporaryRegistration -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(TemporaryRegistration.serializer(), value).jsonObject + (typeField to JsonPrimitive("temporary_registration")) + ) + is PhoneNumber -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(PhoneNumber.serializer(), value).jsonObject + (typeField to JsonPrimitive("phone_number")) + ) + is Email -> JsonObject( + nonstrictJsonFormat.encodeToJsonElement(Email.serializer(), value).jsonObject + (typeField to JsonPrimitive("email")) + ) + is UnknownEncryptedPassportElement -> value.rawJson + else -> return + } + jsonSerializer.serialize(encoder, json) + } + +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt new file mode 100644 index 0000000000..76043d8ed3 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.types.dataField +import dev.inmo.tgbotapi.types.hashField +import dev.inmo.tgbotapi.types.passport.Base64EncodedData +import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +data class EncryptedPersonalDetails( + @SerialName(dataField) + override val data: EncryptedAndBase64EncodedData, + @SerialName(hashField) + override val hash: Base64EncodedData +) : WithData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt new file mode 100644 index 0000000000..c74a37d5d0 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt @@ -0,0 +1,37 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.passport.* +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +sealed class Passport : WithData, WithFrontSide, WithSelfie, Translatable + +@Serializable(EncryptedElementSerializer::class) +data class CommonPassport( + @SerialName(dataField) + override val data: EncryptedAndBase64EncodedData, + @SerialName(frontSideField) + override val frontSide: PassportFile?, + @SerialName(selfieField) + override val selfie: PassportFile?, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : Passport() +@Serializable(EncryptedElementSerializer::class) +data class InternalPassport( + @SerialName(dataField) + override val data: EncryptedAndBase64EncodedData, + @SerialName(frontSideField) + override val frontSide: PassportFile?, + @SerialName(selfieField) + override val selfie: PassportFile?, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : Passport() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt new file mode 100644 index 0000000000..85e5876822 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt @@ -0,0 +1,25 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.requests.abstracts.FileId +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.files.abstracts.* +import dev.inmo.tgbotapi.types.files.abstracts.fileIdField +import dev.inmo.tgbotapi.types.files.abstracts.fileSizeField +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format + * when decrypted and don't exceed 10MB. + */ +@Serializable +data class PassportFile( + @SerialName(fileIdField) + override val fileId: FileId, + @SerialName(fileUniqueIdField) + override val fileUniqueId: FileUniqueId, + @SerialName(fileSizeField) + override val fileSize: Long, + @SerialName(fileDateField) + val uploadingDate: TelegramDate +) : TelegramMediaFile diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt new file mode 100644 index 0000000000..4e0993348e --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.types.hashField +import dev.inmo.tgbotapi.types.passport.Base64EncodedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithPhoneNumber +import dev.inmo.tgbotapi.types.phoneNumberField +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +data class PhoneNumber( + @SerialName(phoneNumberField) + override val phoneNumber: String, + @SerialName(hashField) + override val hash: Base64EncodedData +) : WithPhoneNumber { +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt new file mode 100644 index 0000000000..4baf3945aa --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt @@ -0,0 +1,58 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.passport.Base64EncodedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.FilesCollection +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.Translatable +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +sealed class TranslatableFilesCollection : Translatable, FilesCollection + +@Serializable(EncryptedElementSerializer::class) +data class UtilityBill( + @SerialName(filesField) + override val files: List, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : TranslatableFilesCollection() +@Serializable(EncryptedElementSerializer::class) +data class BankStatement( + @SerialName(filesField) + override val files: List, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : TranslatableFilesCollection() +@Serializable(EncryptedElementSerializer::class) +data class RentalAgreement( + @SerialName(filesField) + override val files: List, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : TranslatableFilesCollection() +@Serializable(EncryptedElementSerializer::class) +data class PassportRegistration( + @SerialName(filesField) + override val files: List, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : TranslatableFilesCollection() +@Serializable(EncryptedElementSerializer::class) +data class TemporaryRegistration( + @SerialName(filesField) + override val files: List, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : TranslatableFilesCollection() + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt new file mode 100644 index 0000000000..3670018507 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt @@ -0,0 +1,43 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.passport.Base64EncodedData +import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +sealed class TranslatableIDDocument : WithData, WithFrontSide, WithReverseSide, WithSelfie, Translatable + +@Serializable(EncryptedElementSerializer::class) +data class DriverLicense( + @SerialName(dataField) + override val data: EncryptedAndBase64EncodedData, + @SerialName(frontSideField) + override val frontSide: PassportFile?, + @SerialName(reverseSideField) + override val reverseSide: PassportFile?, + @SerialName(selfieField) + override val selfie: PassportFile?, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : TranslatableIDDocument() + +@Serializable(EncryptedElementSerializer::class) +data class IdentityCard( + @SerialName(dataField) + override val data: EncryptedAndBase64EncodedData, + @SerialName(frontSideField) + override val frontSide: PassportFile?, + @SerialName(reverseSideField) + override val reverseSide: PassportFile?, + @SerialName(selfieField) + override val selfie: PassportFile?, + @SerialName(translationField) + override val translations: List, + @SerialName(hashField) + override val hash: Base64EncodedData +) : TranslatableIDDocument() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt new file mode 100644 index 0000000000..cce51ce039 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt @@ -0,0 +1,17 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.Base64EncodedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.JsonObject + +@Serializable(EncryptedElementSerializer::class) +interface EncryptedPassportElement { + val hash: Base64EncodedData +} + +@Serializable(EncryptedElementSerializer::class) +data class UnknownEncryptedPassportElement( + val rawJson: JsonObject, + override val hash: Base64EncodedData +) : EncryptedPassportElement diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/FilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/FilesCollection.kt new file mode 100644 index 0000000000..aa58eb3ecc --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/FilesCollection.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface FilesCollection : EncryptedPassportElement { + val files: List +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/Translatable.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/Translatable.kt new file mode 100644 index 0000000000..0e7d7f0af9 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/Translatable.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface Translatable : EncryptedPassportElement { + val translations: List +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt new file mode 100644 index 0000000000..23e63f5013 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithData : EncryptedPassportElement { + val data: EncryptedAndBase64EncodedData +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithEmail.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithEmail.kt new file mode 100644 index 0000000000..57b069a55f --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithEmail.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithEmail : EncryptedPassportElement { + val email: String +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithFrontSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithFrontSide.kt new file mode 100644 index 0000000000..400ffae9cd --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithFrontSide.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithFrontSide : EncryptedPassportElement { + val frontSide: PassportFile? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithPhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithPhoneNumber.kt new file mode 100644 index 0000000000..47e1ecdf30 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithPhoneNumber.kt @@ -0,0 +1,9 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithPhoneNumber : EncryptedPassportElement { + val phoneNumber: String +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithReverseSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithReverseSide.kt new file mode 100644 index 0000000000..059b517955 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithReverseSide.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithReverseSide : EncryptedPassportElement { + val reverseSide: PassportFile? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithSelfie.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithSelfie.kt new file mode 100644 index 0000000000..fed2706bab --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithSelfie.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithSelfie : EncryptedPassportElement { + val selfie: PassportFile? +} \ No newline at end of file From ef2273589453c7258b921198897590b5c1e95068 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 14 Jan 2021 21:27:58 +0600 Subject: [PATCH 03/43] add base64 serialization dependency and update micro_utils up to 0.4.17 --- CHANGELOG.md | 4 ++++ gradle.properties | 2 +- tgbotapi.core/build.gradle | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d72312dc67..0109cb35af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.31.1 +* `Common`: + * `Version`: + * `MicroUtils`: `0.4.16` -> `0.4.17` + ## 0.31.0 **THIS UPDATE CONTAINS BREAKING CHANGES** diff --git a/gradle.properties b/gradle.properties index 4cebf58445..9d62691e15 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.3 uuid_version=0.2.3 ktor_version=1.5.0 -micro_utils_version=0.4.16 +micro_utils_version=0.4.17 javax_activation_version=1.1.1 diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index 9d12635f6c..7ba634fb89 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -47,6 +47,7 @@ kotlin { api "com.benasher44:uuid:$uuid_version" api "dev.inmo:micro_utils.coroutines:$micro_utils_version" + api "dev.inmo:micro_utils.serialization.base64:$micro_utils_version" api "io.ktor:ktor-client-core:$ktor_version" } From 5d87b86afeb679b78bc46320a2446db295201e15 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 15 Jan 2021 16:02:16 +0600 Subject: [PATCH 04/43] update passport data to use Base64StringSerializer --- .../tgbotapi/types/passport/EncryptedData.kt | 13 ++++++++----- .../types/passport/encrypted_data/Email.kt | 4 +++- .../passport/encrypted_data/EncryptedAddress.kt | 8 ++++---- .../encrypted_data/EncryptedPersonalDetails.kt | 12 ++++++------ .../types/passport/encrypted_data/Passport.kt | 11 +++++++---- .../types/passport/encrypted_data/PhoneNumber.kt | 4 +++- .../TranslatableFilesCollection.kt | 16 +++++++++++----- .../encrypted_data/TranslatableIDDocument.kt | 13 ++++++++----- .../abstracts/EncryptedPassportElement.kt | 6 ++++-- .../encrypted_data/abstracts/WithData.kt | 3 ++- 10 files changed, 56 insertions(+), 34 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt index 92953f6fee..ce198b65da 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt @@ -1,20 +1,23 @@ package dev.inmo.tgbotapi.types.passport +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -typealias Base64EncodedData = String typealias EncryptedAndBase64EncodedData = String -typealias EncryptedByBotRSAAndBase64EncodedData = String +typealias EncryptedByBotPublicKeyData = String typealias EncryptedData = String @Serializable data class EncryptedCredentials( @SerialName(dataField) - val data: EncryptedAndBase64EncodedData, + @Serializable(Base64StringSerializer::class) + val data: EncryptedData, @SerialName(hashField) - val hash: Base64EncodedData, + @Serializable(Base64StringSerializer::class) + val hash: String, @SerialName(secretField) - val secret: EncryptedByBotRSAAndBase64EncodedData + @Serializable(Base64StringSerializer::class) + val secret: EncryptedByBotPublicKeyData ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt index bf641d08de..13d51fcb40 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithEmail @@ -11,6 +12,7 @@ data class Email( @SerialName(emailField) override val email: String, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : WithEmail { } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt index 5d10c2f152..277bd63670 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt @@ -1,7 +1,7 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.dataField -import dev.inmo.tgbotapi.types.hashField import dev.inmo.tgbotapi.types.passport.* import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import kotlinx.serialization.SerialName @@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) data class EncryptedAddress( @SerialName(dataField) - override val data: EncryptedAndBase64EncodedData, - @SerialName(hashField) - override val hash: Base64EncodedData + override val data: EncryptedData, + @Serializable(Base64StringSerializer::class) + override val hash: String ) : WithData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt index 76043d8ed3..6a21d51bb6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt @@ -1,9 +1,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.dataField -import dev.inmo.tgbotapi.types.hashField -import dev.inmo.tgbotapi.types.passport.Base64EncodedData -import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData +import dev.inmo.tgbotapi.types.passport.* import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -11,7 +10,8 @@ import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) data class EncryptedPersonalDetails( @SerialName(dataField) - override val data: EncryptedAndBase64EncodedData, - @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val data: EncryptedData, + @Serializable(Base64StringSerializer::class) + override val hash: String ) : WithData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt index c74a37d5d0..a666120399 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.* import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* @@ -12,7 +13,7 @@ sealed class Passport : WithData, WithFrontSide, WithSelfie, Translatable @Serializable(EncryptedElementSerializer::class) data class CommonPassport( @SerialName(dataField) - override val data: EncryptedAndBase64EncodedData, + override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile?, @SerialName(selfieField) @@ -20,12 +21,13 @@ data class CommonPassport( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : Passport() @Serializable(EncryptedElementSerializer::class) data class InternalPassport( @SerialName(dataField) - override val data: EncryptedAndBase64EncodedData, + override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile?, @SerialName(selfieField) @@ -33,5 +35,6 @@ data class InternalPassport( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : Passport() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt index 4e0993348e..f05691e8ff 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.hashField import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithPhoneNumber @@ -12,6 +13,7 @@ data class PhoneNumber( @SerialName(phoneNumberField) override val phoneNumber: String, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : WithPhoneNumber { } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt index 4baf3945aa..ee0645f11f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.FilesCollection @@ -17,7 +18,8 @@ data class UtilityBill( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : TranslatableFilesCollection() @Serializable(EncryptedElementSerializer::class) data class BankStatement( @@ -26,7 +28,8 @@ data class BankStatement( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : TranslatableFilesCollection() @Serializable(EncryptedElementSerializer::class) data class RentalAgreement( @@ -35,7 +38,8 @@ data class RentalAgreement( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : TranslatableFilesCollection() @Serializable(EncryptedElementSerializer::class) data class PassportRegistration( @@ -44,7 +48,8 @@ data class PassportRegistration( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : TranslatableFilesCollection() @Serializable(EncryptedElementSerializer::class) data class TemporaryRegistration( @@ -53,6 +58,7 @@ data class TemporaryRegistration( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : TranslatableFilesCollection() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt index 3670018507..356e73536c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.Base64EncodedData -import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData +import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -13,7 +14,7 @@ sealed class TranslatableIDDocument : WithData, WithFrontSide, WithReverseSide, @Serializable(EncryptedElementSerializer::class) data class DriverLicense( @SerialName(dataField) - override val data: EncryptedAndBase64EncodedData, + override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile?, @SerialName(reverseSideField) @@ -23,13 +24,14 @@ data class DriverLicense( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : TranslatableIDDocument() @Serializable(EncryptedElementSerializer::class) data class IdentityCard( @SerialName(dataField) - override val data: EncryptedAndBase64EncodedData, + override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile?, @SerialName(reverseSideField) @@ -39,5 +41,6 @@ data class IdentityCard( @SerialName(translationField) override val translations: List, @SerialName(hashField) - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : TranslatableIDDocument() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt index cce51ce039..664b31e488 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer import kotlinx.serialization.Serializable @@ -7,11 +8,12 @@ import kotlinx.serialization.json.JsonObject @Serializable(EncryptedElementSerializer::class) interface EncryptedPassportElement { - val hash: Base64EncodedData + val hash: String } @Serializable(EncryptedElementSerializer::class) data class UnknownEncryptedPassportElement( val rawJson: JsonObject, - override val hash: Base64EncodedData + @Serializable(Base64StringSerializer::class) + override val hash: String ) : EncryptedPassportElement diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt index 23e63f5013..ba72eca9e4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt @@ -1,10 +1,11 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData +import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) interface WithData : EncryptedPassportElement { - val data: EncryptedAndBase64EncodedData + val data: EncryptedData } \ No newline at end of file From a2ae4f71dea27a92558d7333f1204d2a82d97dfd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 15 Jan 2021 16:27:22 +0600 Subject: [PATCH 05/43] new PassportMessage type --- .../inmo/tgbotapi/types/message/PassportMessage.kt | 14 ++++++++++++++ .../dev/inmo/tgbotapi/types/message/RawMessage.kt | 10 +++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt new file mode 100644 index 0000000000..2b5f74788d --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt @@ -0,0 +1,14 @@ +package dev.inmo.tgbotapi.types.message + +import com.soywiz.klock.DateTime +import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.passport.PassportData + +data class PassportMessage( + override val messageId: MessageIdentifier, + override val chat: Chat, + override val date: DateTime, + val passportData: PassportData +) : Message diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index a51e011d8a..699bf39381 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -18,6 +18,7 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.MessageContent import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import dev.inmo.tgbotapi.types.message.payments.SuccessfulPaymentInfo +import dev.inmo.tgbotapi.types.passport.PassportData import dev.inmo.tgbotapi.types.payments.Invoice import dev.inmo.tgbotapi.types.payments.SuccessfulPayment import dev.inmo.tgbotapi.types.polls.Poll @@ -84,7 +85,7 @@ internal data class RawMessage( private val connected_website: String? = null, // passport property - private val passport_data: Unit? = null, + private val passport_data: PassportData? = null, private val proximity_alert_triggered: ProximityAlertTriggered? = null, private val reply_markup: InlineKeyboardMarkup? = null @@ -324,6 +325,13 @@ internal data class RawMessage( ) else -> error("Unknown type of chat: $chat") } + } ?: passport_data ?.let{ + PassportMessage( + messageId, + chat, + date.asDate, + passport_data + ) } ?: error("Was not found supported type of data") } catch (e: Exception) { UnknownMessageType( From 6dcdc2ab7f71c952e40cc599ddb60c29ec789285 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Jan 2021 15:35:25 +0600 Subject: [PATCH 06/43] now PassportMessage contains user too --- .../dev/inmo/tgbotapi/types/message/PassportMessage.kt | 5 ++++- .../kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt index 2b5f74788d..55153e159f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/PassportMessage.kt @@ -2,13 +2,16 @@ package dev.inmo.tgbotapi.types.message import com.soywiz.klock.DateTime import dev.inmo.tgbotapi.types.MessageIdentifier +import dev.inmo.tgbotapi.types.User import dev.inmo.tgbotapi.types.chat.abstracts.Chat +import dev.inmo.tgbotapi.types.message.abstracts.FromUserMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.passport.PassportData data class PassportMessage( override val messageId: MessageIdentifier, override val chat: Chat, + override val user: User, override val date: DateTime, val passportData: PassportData -) : Message +) : Message, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt index 699bf39381..b692284b71 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/RawMessage.kt @@ -329,6 +329,7 @@ internal data class RawMessage( PassportMessage( messageId, chat, + from ?: error("For passport must be provided user, but got null"), date.asDate, passport_data ) From 5a3edc2b44b9a41ff5a800b2e431ddb1133bb6d4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Jan 2021 15:43:08 +0600 Subject: [PATCH 07/43] add passportMessages extension --- .../utils/updates/SentMessageUpdatesConversations.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/SentMessageUpdatesConversations.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/SentMessageUpdatesConversations.kt index 533488ed3e..29897d31aa 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/SentMessageUpdatesConversations.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/SentMessageUpdatesConversations.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates +import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.update.abstracts.BaseSentMessageUpdate import kotlinx.coroutines.flow.Flow @@ -26,6 +27,11 @@ inline fun Flow.chatEvents() = mapNotNull { it.data as? ChatEventMessage<*> } +@Suppress("NOTHING_TO_INLINE") +inline fun Flow.passportMessages() = mapNotNull { + it.data as? PassportMessage +} + /** * Will map incoming [BaseSentMessageUpdate]s to [UnknownMessageType] from [BaseSentMessageUpdate.data] */ From 6b414d64b0038149a15ba06bd0c7ec035baaaf56 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Jan 2021 15:45:20 +0600 Subject: [PATCH 08/43] remove redundant imports --- .../dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt | 1 - .../inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt | 1 - .../types/passport/encrypted_data/TranslatableFilesCollection.kt | 1 - .../types/passport/encrypted_data/TranslatableIDDocument.kt | 1 - .../encrypted_data/abstracts/EncryptedPassportElement.kt | 1 - 5 files changed, 5 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt index 13d51fcb40..9692375ed7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithEmail import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt index f05691e8ff..8464429264 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.hashField -import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithPhoneNumber import dev.inmo.tgbotapi.types.phoneNumberField import kotlinx.serialization.SerialName diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt index ee0645f11f..1151f305fd 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.FilesCollection import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.Translatable import kotlinx.serialization.SerialName diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt index 356e73536c..e65c856c4e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt @@ -2,7 +2,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* import kotlinx.serialization.SerialName diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt index 664b31e488..4716d225d2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer -import dev.inmo.tgbotapi.types.passport.Base64EncodedData import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonObject From c1ab9da4c4d3f2eb986a055cf3dd21d63ba74447 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Jan 2021 16:11:38 +0600 Subject: [PATCH 09/43] fix error with deserialization of passport data --- .../tgbotapi/types/passport/encrypted_data/Email.kt | 2 +- .../types/passport/encrypted_data/EncryptedAddress.kt | 2 +- .../encrypted_data/EncryptedPersonalDetails.kt | 2 +- .../tgbotapi/types/passport/encrypted_data/Passport.kt | 4 ++-- .../types/passport/encrypted_data/PhoneNumber.kt | 2 +- .../encrypted_data/TranslatableFilesCollection.kt | 10 +++++----- .../passport/encrypted_data/TranslatableIDDocument.kt | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt index 9692375ed7..4770506f5d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithEmail import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -@Serializable(EncryptedElementSerializer::class) +@Serializable data class Email( @SerialName(emailField) override val email: String, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt index 277bd63670..f31177f85b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -@Serializable(EncryptedElementSerializer::class) +@Serializable data class EncryptedAddress( @SerialName(dataField) override val data: EncryptedData, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt index 6a21d51bb6..0c5e0cf191 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -@Serializable(EncryptedElementSerializer::class) +@Serializable data class EncryptedPersonalDetails( @SerialName(dataField) @Serializable(Base64StringSerializer::class) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt index a666120399..2ddd805bee 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt @@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) sealed class Passport : WithData, WithFrontSide, WithSelfie, Translatable -@Serializable(EncryptedElementSerializer::class) +@Serializable data class CommonPassport( @SerialName(dataField) override val data: EncryptedData, @@ -24,7 +24,7 @@ data class CommonPassport( @Serializable(Base64StringSerializer::class) override val hash: String ) : Passport() -@Serializable(EncryptedElementSerializer::class) +@Serializable data class InternalPassport( @SerialName(dataField) override val data: EncryptedData, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt index 8464429264..563339ade1 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt @@ -7,7 +7,7 @@ import dev.inmo.tgbotapi.types.phoneNumberField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -@Serializable(EncryptedElementSerializer::class) +@Serializable data class PhoneNumber( @SerialName(phoneNumberField) override val phoneNumber: String, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt index 1151f305fd..4386527c77 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt @@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) sealed class TranslatableFilesCollection : Translatable, FilesCollection -@Serializable(EncryptedElementSerializer::class) +@Serializable data class UtilityBill( @SerialName(filesField) override val files: List, @@ -20,7 +20,7 @@ data class UtilityBill( @Serializable(Base64StringSerializer::class) override val hash: String ) : TranslatableFilesCollection() -@Serializable(EncryptedElementSerializer::class) +@Serializable data class BankStatement( @SerialName(filesField) override val files: List, @@ -30,7 +30,7 @@ data class BankStatement( @Serializable(Base64StringSerializer::class) override val hash: String ) : TranslatableFilesCollection() -@Serializable(EncryptedElementSerializer::class) +@Serializable data class RentalAgreement( @SerialName(filesField) override val files: List, @@ -40,7 +40,7 @@ data class RentalAgreement( @Serializable(Base64StringSerializer::class) override val hash: String ) : TranslatableFilesCollection() -@Serializable(EncryptedElementSerializer::class) +@Serializable data class PassportRegistration( @SerialName(filesField) override val files: List, @@ -50,7 +50,7 @@ data class PassportRegistration( @Serializable(Base64StringSerializer::class) override val hash: String ) : TranslatableFilesCollection() -@Serializable(EncryptedElementSerializer::class) +@Serializable data class TemporaryRegistration( @SerialName(filesField) override val files: List, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt index e65c856c4e..e6d9fabfc9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt @@ -10,7 +10,7 @@ import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) sealed class TranslatableIDDocument : WithData, WithFrontSide, WithReverseSide, WithSelfie, Translatable -@Serializable(EncryptedElementSerializer::class) +@Serializable data class DriverLicense( @SerialName(dataField) override val data: EncryptedData, @@ -27,7 +27,7 @@ data class DriverLicense( override val hash: String ) : TranslatableIDDocument() -@Serializable(EncryptedElementSerializer::class) +@Serializable data class IdentityCard( @SerialName(dataField) override val data: EncryptedData, From 26fd5e51bf0b573ba583dfd14a6b840dd4c117cd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Jan 2021 16:24:33 +0600 Subject: [PATCH 10/43] filesSize in PassportFile is nullable for now --- .../tgbotapi/types/passport/encrypted_data/PassportFile.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt index 85e5876822..5fdbd8a5c9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt @@ -18,8 +18,8 @@ data class PassportFile( override val fileId: FileId, @SerialName(fileUniqueIdField) override val fileUniqueId: FileUniqueId, - @SerialName(fileSizeField) - override val fileSize: Long, @SerialName(fileDateField) - val uploadingDate: TelegramDate + val uploadingDate: TelegramDate, + @SerialName(fileSizeField) + override val fileSize: Long? = null ) : TelegramMediaFile From fb61a94c5ef7016b9f2e7b4a76eb0e17a8714d4c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Jan 2021 16:30:25 +0600 Subject: [PATCH 11/43] fix defaults in encrypted passport data --- .../types/passport/encrypted_data/Passport.kt | 12 ++++++------ .../TranslatableFilesCollection.kt | 8 ++++---- .../encrypted_data/TranslatableIDDocument.kt | 16 ++++++++-------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt index 2ddd805bee..1073ea4a79 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt @@ -15,11 +15,11 @@ data class CommonPassport( @SerialName(dataField) override val data: EncryptedData, @SerialName(frontSideField) - override val frontSide: PassportFile?, + override val frontSide: PassportFile? = null, @SerialName(selfieField) - override val selfie: PassportFile?, + override val selfie: PassportFile? = null, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String @@ -29,11 +29,11 @@ data class InternalPassport( @SerialName(dataField) override val data: EncryptedData, @SerialName(frontSideField) - override val frontSide: PassportFile?, + override val frontSide: PassportFile? = null, @SerialName(selfieField) - override val selfie: PassportFile?, + override val selfie: PassportFile? = null, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt index 4386527c77..4ba36b214d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt @@ -25,7 +25,7 @@ data class BankStatement( @SerialName(filesField) override val files: List, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String @@ -35,7 +35,7 @@ data class RentalAgreement( @SerialName(filesField) override val files: List, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String @@ -45,7 +45,7 @@ data class PassportRegistration( @SerialName(filesField) override val files: List, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String @@ -55,7 +55,7 @@ data class TemporaryRegistration( @SerialName(filesField) override val files: List, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt index e6d9fabfc9..dcad6fd43a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt @@ -15,13 +15,13 @@ data class DriverLicense( @SerialName(dataField) override val data: EncryptedData, @SerialName(frontSideField) - override val frontSide: PassportFile?, + override val frontSide: PassportFile? = null, @SerialName(reverseSideField) - override val reverseSide: PassportFile?, + override val reverseSide: PassportFile? = null, @SerialName(selfieField) - override val selfie: PassportFile?, + override val selfie: PassportFile? = null, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String @@ -32,13 +32,13 @@ data class IdentityCard( @SerialName(dataField) override val data: EncryptedData, @SerialName(frontSideField) - override val frontSide: PassportFile?, + override val frontSide: PassportFile? = null, @SerialName(reverseSideField) - override val reverseSide: PassportFile?, + override val reverseSide: PassportFile? = null, @SerialName(selfieField) - override val selfie: PassportFile?, + override val selfie: PassportFile? = null, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String From 81de59f37ca9ab6ed4894300b8291d7fe4196341 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Jan 2021 16:34:05 +0600 Subject: [PATCH 12/43] fix of translations in UtilityBill --- .../passport/encrypted_data/TranslatableFilesCollection.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt index 4ba36b214d..4339ad958b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt @@ -15,7 +15,7 @@ data class UtilityBill( @SerialName(filesField) override val files: List, @SerialName(translationField) - override val translations: List, + override val translations: List = emptyList(), @SerialName(hashField) @Serializable(Base64StringSerializer::class) override val hash: String From 2dc8521aeda0bc9652dd73ef9587b03ffddf988b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 17 Jan 2021 16:44:35 +0600 Subject: [PATCH 13/43] now all data field are predecrypted with Base64StringSerializer --- .../tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt | 1 + .../dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt | 2 ++ .../types/passport/encrypted_data/TranslatableIDDocument.kt | 2 ++ 3 files changed, 5 insertions(+) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt index f31177f85b..e4db912d94 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt @@ -10,6 +10,7 @@ import kotlinx.serialization.Serializable @Serializable data class EncryptedAddress( @SerialName(dataField) + @Serializable(Base64StringSerializer::class) override val data: EncryptedData, @Serializable(Base64StringSerializer::class) override val hash: String diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt index 1073ea4a79..fc856e0303 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt @@ -13,6 +13,7 @@ sealed class Passport : WithData, WithFrontSide, WithSelfie, Translatable @Serializable data class CommonPassport( @SerialName(dataField) + @Serializable(Base64StringSerializer::class) override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile? = null, @@ -27,6 +28,7 @@ data class CommonPassport( @Serializable data class InternalPassport( @SerialName(dataField) + @Serializable(Base64StringSerializer::class) override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile? = null, diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt index dcad6fd43a..45d874c784 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt @@ -13,6 +13,7 @@ sealed class TranslatableIDDocument : WithData, WithFrontSide, WithReverseSide, @Serializable data class DriverLicense( @SerialName(dataField) + @Serializable(Base64StringSerializer::class) override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile? = null, @@ -30,6 +31,7 @@ data class DriverLicense( @Serializable data class IdentityCard( @SerialName(dataField) + @Serializable(Base64StringSerializer::class) override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile? = null, From 09748615aeca705a9a98cff773a77628a7a6a619 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 18 Jan 2021 23:43:21 +0600 Subject: [PATCH 14/43] optimize imports --- .../dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt | 3 ++- .../tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt | 2 +- .../passport/encrypted_data/EncryptedElementSerializer.kt | 3 ++- .../types/passport/encrypted_data/EncryptedPersonalDetails.kt | 2 +- .../inmo/tgbotapi/types/passport/encrypted_data/Passport.kt | 2 +- .../tgbotapi/types/passport/encrypted_data/PassportFile.kt | 2 -- .../types/passport/encrypted_data/abstracts/WithData.kt | 1 - .../tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt | 3 ++- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt index 4770506f5d..c5e83c94d8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer -import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.emailField +import dev.inmo.tgbotapi.types.hashField import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithEmail import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt index e4db912d94..b63f1865bf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.dataField -import dev.inmo.tgbotapi.types.passport.* +import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt index c753cd3024..b149eba867 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.tgbotapi.types.hashField -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.UnknownEncryptedPassportElement import dev.inmo.tgbotapi.types.typeField import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.KSerializer diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt index 0c5e0cf191..90149a261e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.dataField -import dev.inmo.tgbotapi.types.passport.* +import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt index fc856e0303..882c91c895 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.* +import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt index 5fdbd8a5c9..cf00e2fc2a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt @@ -3,8 +3,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.files.abstracts.* -import dev.inmo.tgbotapi.types.files.abstracts.fileIdField -import dev.inmo.tgbotapi.types.files.abstracts.fileSizeField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt index ba72eca9e4..163b9d43b6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt @@ -1,6 +1,5 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts -import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt index 143dd51d53..c5347a12ad 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/internal/CaptionAndTextSourcesToText.kt @@ -1,9 +1,10 @@ package dev.inmo.tgbotapi.utils.internal import dev.inmo.tgbotapi.CommonAbstracts.* -import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.ParseMode.* +import dev.inmo.tgbotapi.types.captionLength import dev.inmo.tgbotapi.types.message.content.TextContent +import dev.inmo.tgbotapi.types.textLength internal fun createFormattedText( entities: TextSourcesList, From 73b3daa68b1eba9661720bba84a2a6412734e61b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Jan 2021 00:39:46 +0600 Subject: [PATCH 15/43] Update micro_utils dependency --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 9d62691e15..97f5960b25 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.3 uuid_version=0.2.3 ktor_version=1.5.0 -micro_utils_version=0.4.17 +micro_utils_version=0.4.18 javax_activation_version=1.1.1 From a4bf6911c7c5a5aad9c9d847fa48216cdf609888 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Jan 2021 00:40:29 +0600 Subject: [PATCH 16/43] Update micro_utils version note --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0109cb35af..e483ed977b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ * `Common`: * `Version`: - * `MicroUtils`: `0.4.16` -> `0.4.17` + * `MicroUtils`: `0.4.16` -> `0.4.18` ## 0.31.0 From ae2f4579e20c80b18aa659abd90d347f27b91ce3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Jan 2021 10:52:30 +0600 Subject: [PATCH 17/43] start 0.32.0 as a migration from 0.31.1 due to breaking changes in MediaGroupMessage type --- CHANGELOG.md | 5 ++- gradle.properties | 2 +- .../requests/send/media/SendMediaGroup.kt | 24 +++++----- .../types/message/ChannelMediaGroupMessage.kt | 6 +-- .../types/message/CommonMediaGroupMessage.kt | 6 +-- .../message/abstracts/MediaGroupMessage.kt | 2 +- .../content/abstracts/MediaGroupContent.kt | 14 ++++-- .../ChannelPostMediaGroupUpdate.kt | 3 +- .../EditChannelPostMediaGroupUpdate.kt | 3 +- .../EditMessageMediaGroupUpdate.kt | 3 +- .../MediaGroupUpdates/MediaGroupUpdate.kt | 5 ++- .../MessageMediaGroupUpdate.kt | 3 +- .../api/InternalUtils/UpdatesUtils.kt | 2 +- .../api/send/media/SendMediaGroup.kt | 4 +- .../extensions/api/utils/UpdatesHandling.kt | 2 +- .../expectations/WaitMediaGroup.kt | 26 +++++------ .../triggers_handling/MediaGroupTriggers.kt | 44 +++++++++---------- .../tgbotapi/extensions/utils/ClassCasts.kt | 12 ++--- .../utils/shortcuts/MediaGroupsShortcuts.kt | 10 ++--- .../extensions/utils/updates/UpdatesUtils.kt | 2 +- .../updates/retrieving/MediaGroupsIncluder.kt | 3 +- 21 files changed, 101 insertions(+), 80 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e483ed977b..c5207890f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ # TelegramBotAPI changelog -## 0.31.1 +## 0.32.0 * `Common`: * `Version`: * `MicroUtils`: `0.4.16` -> `0.4.18` +* `Core`: + * Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` + * Methods and types related to `MediaGroupMessage` have been modified according to their meanings ## 0.31.0 diff --git a/gradle.properties b/gradle.properties index 97f5960b25..cc3412fe0d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,6 +17,6 @@ micro_utils_version=0.4.18 javax_activation_version=1.1.1 library_group=dev.inmo -library_version=0.31.1 +library_version=0.32.0 github_release_plugin_version=2.2.12 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt index df4a949fa1..1352d3a9b9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/send/media/SendMediaGroup.kt @@ -8,6 +8,10 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.InputMedia.* import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.TelegramBotAPIMessageDeserializeOnlySerializerClass +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent +import dev.inmo.tgbotapi.types.message.content.media.AudioContent +import dev.inmo.tgbotapi.types.message.content.media.DocumentContent import dev.inmo.tgbotapi.utils.* import kotlinx.serialization.* import kotlinx.serialization.builtins.ListSerializer @@ -17,13 +21,13 @@ const val rawSendingMediaGroupsWarning = "Media groups contains restrictions rel " types. Currently it is possible to combine photo + video OR audio OR documents" @RiskFeature(rawSendingMediaGroupsWarning) -fun SendMediaGroup( +fun SendMediaGroup( chatId: ChatIdentifier, media: List, disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null -): Request> { +): Request>> { if (media.size !in mediaCountInMediaGroup) { throwRangeError("Count of members in media group", mediaCountInMediaGroup, media.size) } @@ -47,14 +51,14 @@ fun SendMediaGroup( allowSendingWithoutReply ) - return if (files.isEmpty()) { + return (if (files.isEmpty()) { data } else { MultipartRequestImpl( data, SendMediaGroupFiles(files) ) - } + }) as Request>> } /** @@ -69,7 +73,7 @@ inline fun SendPlaylist( disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) /** * Use this method to be sure that you are correctly sending documents media group @@ -83,7 +87,7 @@ inline fun SendDocumentsGroup( disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) /** * Use this method to be sure that you are correctly sending visual media group @@ -98,9 +102,9 @@ inline fun SendVisualMediaGroup( disableNotification: Boolean = false, replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null -) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) +) = SendMediaGroup(chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply) -private val messagesListSerializer: KSerializer> +private val messagesListSerializer: KSerializer>> = ListSerializer(TelegramBotAPIMessageDeserializeOnlySerializerClass()) @Serializable @@ -114,7 +118,7 @@ data class SendMediaGroupData internal constructor( override val replyToMessageId: MessageIdentifier? = null, @SerialName(allowSendingWithoutReplyField) override val allowSendingWithoutReply: Boolean? = null -) : DataRequest>, SendMessageRequest> { +) : DataRequest>>, SendMessageRequest>> { @SerialName(mediaField) private val convertedMedia: String get() = buildJsonArray { @@ -127,7 +131,7 @@ data class SendMediaGroupData internal constructor( override fun method(): String = "sendMediaGroup" override val requestSerializer: SerializationStrategy<*> get() = serializer() - override val resultDeserializer: DeserializationStrategy> + override val resultDeserializer: DeserializationStrategy>> get() = messagesListSerializer } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt index 70d670d41e..3f3688e702 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/ChannelMediaGroupMessage.kt @@ -9,14 +9,14 @@ import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.abstracts.Message import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent -data class ChannelMediaGroupMessage( +data class ChannelMediaGroupMessage( override val messageId: MessageIdentifier, override val chat: Chat, override val date: DateTime, override val mediaGroupId: MediaGroupIdentifier, - override val content: MediaGroupContent, + override val content: T, override val editDate: DateTime?, override val forwardInfo: ForwardInfo?, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup? -) : MediaGroupMessage +) : MediaGroupMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt index 2694c7d187..49d1118e57 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/CommonMediaGroupMessage.kt @@ -7,15 +7,15 @@ import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent -data class CommonMediaGroupMessage( +data class CommonMediaGroupMessage( override val messageId: MessageIdentifier, override val user: User, override val chat: Chat, override val date: DateTime, override val mediaGroupId: MediaGroupIdentifier, - override val content: MediaGroupContent, + override val content: T, override val editDate: DateTime?, override val forwardInfo: ForwardInfo?, override val replyTo: Message?, override val replyMarkup: InlineKeyboardMarkup? -) : MediaGroupMessage, FromUserMessage +) : MediaGroupMessage, FromUserMessage diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt index c78ab44f77..307ba6e78c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/abstracts/MediaGroupMessage.kt @@ -3,6 +3,6 @@ package dev.inmo.tgbotapi.types.message.abstracts import dev.inmo.tgbotapi.types.MediaGroupIdentifier import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent -interface MediaGroupMessage : CommonMessage { +interface MediaGroupMessage : CommonMessage { val mediaGroupId: MediaGroupIdentifier } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaGroupContent.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaGroupContent.kt index a284c0c4b8..7cf2eb6b16 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaGroupContent.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/message/content/abstracts/MediaGroupContent.kt @@ -1,12 +1,18 @@ package dev.inmo.tgbotapi.types.message.content.abstracts import dev.inmo.tgbotapi.CommonAbstracts.CaptionedInput -import dev.inmo.tgbotapi.types.InputMedia.MediaGroupMemberInputMedia +import dev.inmo.tgbotapi.types.InputMedia.* interface MediaGroupContent : MediaContent, CaptionedInput { fun toMediaGroupMemberInputMedia(): MediaGroupMemberInputMedia } -interface VisualMediaGroupContent : MediaGroupContent -interface AudioMediaGroupContent : MediaGroupContent -interface DocumentMediaGroupContent : MediaGroupContent +interface VisualMediaGroupContent : MediaGroupContent { + override fun toMediaGroupMemberInputMedia(): VisualMediaGroupMemberInputMedia +} +interface AudioMediaGroupContent : MediaGroupContent { + override fun toMediaGroupMemberInputMedia(): AudioMediaGroupMemberInputMedia +} +interface DocumentMediaGroupContent : MediaGroupContent { + override fun toMediaGroupMemberInputMedia(): DocumentMediaGroupMemberInputMedia +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/ChannelPostMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/ChannelPostMediaGroupUpdate.kt index fa4532d80d..505caf47ef 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/ChannelPostMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/ChannelPostMediaGroupUpdate.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.update.MediaGroupUpdates import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate data class ChannelPostMediaGroupUpdate( override val origins: List ) : SentMediaGroupUpdate { override val updateId: UpdateIdentifier = origins.last().updateId - override val data: List = origins.mapNotNull { it.data as? MediaGroupMessage } + override val data: List> = origins.mapNotNull { it.data as? MediaGroupMessage } } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt index 596088bbcb..8c0935d199 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/EditChannelPostMediaGroupUpdate.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.update.MediaGroupUpdates import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.update.EditChannelPostUpdate data class EditChannelPostMediaGroupUpdate( override val origin: EditChannelPostUpdate ) : EditMediaGroupUpdate { override val updateId: UpdateIdentifier = origin.updateId - override val data: MediaGroupMessage = origin.data as MediaGroupMessage + override val data: MediaGroupMessage = origin.data as MediaGroupMessage } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt index 0a88e5c117..075b3c38d2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/EditMessageMediaGroupUpdate.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.update.MediaGroupUpdates import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.update.EditMessageUpdate data class EditMessageMediaGroupUpdate( override val origin: EditMessageUpdate ) : EditMediaGroupUpdate { override val updateId: UpdateIdentifier = origin.updateId - override val data: MediaGroupMessage = origin.data as MediaGroupMessage + override val data: MediaGroupMessage = origin.data as MediaGroupMessage } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MediaGroupUpdate.kt index 77c7f41f8d..b50e772ba7 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MediaGroupUpdate.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.update.MediaGroupUpdates import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.update.abstracts.* /** @@ -13,11 +14,11 @@ import dev.inmo.tgbotapi.types.update.abstracts.* interface MediaGroupUpdate : Update interface SentMediaGroupUpdate: MediaGroupUpdate { - override val data: List + override val data: List> val origins: List } interface EditMediaGroupUpdate : BaseEditMessageUpdate, MediaGroupUpdate { - override val data: MediaGroupMessage + override val data: MediaGroupMessage val origin: BaseMessageUpdate } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MessageMediaGroupUpdate.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MessageMediaGroupUpdate.kt index f5bb8e69e7..3dd3c86cb0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MessageMediaGroupUpdate.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/update/MediaGroupUpdates/MessageMediaGroupUpdate.kt @@ -2,11 +2,12 @@ package dev.inmo.tgbotapi.types.update.MediaGroupUpdates import dev.inmo.tgbotapi.types.UpdateIdentifier import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate data class MessageMediaGroupUpdate( override val origins: List ) : SentMediaGroupUpdate { override val updateId: UpdateIdentifier = origins.last().updateId - override val data: List = origins.mapNotNull { it.data as? MediaGroupMessage } + override val data: List> = origins.mapNotNull { it.data as? MediaGroupMessage } } \ No newline at end of file diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/InternalUtils/UpdatesUtils.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/InternalUtils/UpdatesUtils.kt index 42caeeb6b8..8a35681bd7 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/InternalUtils/UpdatesUtils.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/InternalUtils/UpdatesUtils.kt @@ -23,7 +23,7 @@ internal fun List.convertWithMediaGroupUpdates(): List { val resultUpdates = mutableListOf() val mediaGroups = mutableMapOf>() for (update in this) { - val data = (update.data as? MediaGroupMessage) + val data = (update.data as? MediaGroupMessage<*>) if (data == null) { resultUpdates.add(update) continue diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt index 6a115897b8..e8cf10588f 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/send/media/SendMediaGroup.kt @@ -7,6 +7,8 @@ import dev.inmo.tgbotapi.types.InputMedia.* import dev.inmo.tgbotapi.types.MessageIdentifier import dev.inmo.tgbotapi.types.chat.abstracts.Chat import dev.inmo.tgbotapi.types.message.abstracts.Message +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent +import dev.inmo.tgbotapi.types.message.content.abstracts.VisualMediaGroupContent import dev.inmo.tgbotapi.utils.RiskFeature /** @@ -20,7 +22,7 @@ suspend fun TelegramBot.sendMediaGroup( replyToMessageId: MessageIdentifier? = null, allowSendingWithoutReply: Boolean? = null ) = execute( - SendMediaGroup( + SendMediaGroup( chatId, media, disableNotification, replyToMessageId, allowSendingWithoutReply ) ) diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/utils/UpdatesHandling.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/utils/UpdatesHandling.kt index 3f9e249fea..54845e4c3a 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/utils/UpdatesHandling.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/utils/UpdatesHandling.kt @@ -31,7 +31,7 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( launch { for (update in updatesChannel) { when (val data = update.data) { - is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) + is MediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) else -> output(update) } } diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt index f94531487a..0ed50f8add 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt @@ -16,12 +16,12 @@ internal suspend inline fun BehaviourContext.onM count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, - noinline filter: (suspend (List) -> Boolean)? = null + noinline filter: (suspend (List>) -> Boolean)? = null ) = flowsUpdatesFilter.expectFlow(bot, initRequest, count, errorFactory) { update -> update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup -> - if (mediaGroup.all { message -> message.content is T } && (filter == null || filter(mediaGroup))) { + if (mediaGroup.all { message -> message.content is T } && (filter == null || filter(mediaGroup as List>))) { listOf( - mediaGroup.map { it.content as T } + mediaGroup.map { it.content as T } as List> ) } else { null @@ -33,29 +33,29 @@ suspend fun BehaviourContext.waitPlaylist( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) + filter: (suspend (List>) -> Boolean)? = null +) = onMediaGroup(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitDocumentsGroup( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) + filter: (suspend (List>) -> Boolean)? = null +) = onMediaGroup(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitVisualGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) + filter: (suspend (List>) -> Boolean)? = null +) = onMediaGroup(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitPhotoGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) + filter: (suspend (List>) -> Boolean)? = null +) = onMediaGroup(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitVideoGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - filter: (suspend (List) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) + filter: (suspend (List>) -> Boolean)? = null +) = onMediaGroup(count, initRequest, errorFactory, filter) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt index e273335bf8..6e195fddbc 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -12,8 +12,7 @@ import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.abstracts.* -import dev.inmo.tgbotapi.types.message.content.media.PhotoContent -import dev.inmo.tgbotapi.types.message.content.media.VideoContent +import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.utils.PreviewFeature import kotlinx.coroutines.flow.filter @@ -21,12 +20,12 @@ import kotlinx.coroutines.flow.filter @PreviewFeature internal suspend inline fun BehaviourContext.onMediaGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, - noinline additionalFilter: (suspend (List) -> Boolean)? = null, - noinline scenarioReceiver: BehaviourContextAndTypeReceiver> + noinline additionalFilter: (suspend (List>) -> Boolean)? = null, + noinline scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = flowsUpdatesFilter.expectFlow(bot) { update -> update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup -> - if (mediaGroup.all { message -> message.content is T } && (additionalFilter == null || additionalFilter(mediaGroup))) { - listOf(mediaGroup) + if (mediaGroup.all { message -> message.content is T } && (additionalFilter == null || additionalFilter(mediaGroup as List>))) { + listOf(mediaGroup as List>) } else { null } @@ -35,10 +34,11 @@ internal suspend inline fun BehaviourContext.onM val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) { val subFilter = FlowsUpdatesFilter() val subBehaviourContext = copy(flowsUpdatesFilter = subFilter) + val mediaGroupChat = mediaGroup.chat!! flowsUpdatesFilter.allUpdatesFlow.filter { val chat = it.sourceChat() ?: return@filter false - chat.id.chatId == mediaGroup.chat!!.id.chatId + chat.id.chatId == mediaGroupChat.id.chatId }.subscribeSafelyWithoutExceptions(scope, subFilter.asUpdateReceiver) to subBehaviourContext } else { null to this @@ -49,27 +49,27 @@ internal suspend inline fun BehaviourContext.onM suspend fun BehaviourContext.onPlaylist( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List) -> Boolean)? = null, - scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) + additionalFilter: (suspend (List>) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver>> +) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onDocumentsGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List) -> Boolean)? = null, - scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) + additionalFilter: (suspend (List>) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver>> +) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVisualGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List) -> Boolean)? = null, - scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) + additionalFilter: (suspend (List>) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver>> +) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onPhotoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List) -> Boolean)? = null, - scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) + additionalFilter: (suspend (List>) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver>> +) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVideoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, - additionalFilter: (suspend (List) -> Boolean)? = null, - scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) + additionalFilter: (suspend (List>) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver>> +) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index a6956c3282..25c0e86e29 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -160,17 +160,17 @@ inline fun Message.asChannelEventMessage(): ChannelEventMessage? = @PreviewFeature inline fun Message.requireChannelEventMessage(): ChannelEventMessage = this as ChannelEventMessage @PreviewFeature -inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage? = this as? ChannelMediaGroupMessage +inline fun Message.asChannelMediaGroupMessage(): ChannelMediaGroupMessage? = this as? ChannelMediaGroupMessage @PreviewFeature -inline fun Message.requireChannelMediaGroupMessage(): ChannelMediaGroupMessage = this as ChannelMediaGroupMessage +inline fun Message.requireChannelMediaGroupMessage(): ChannelMediaGroupMessage = this as ChannelMediaGroupMessage @PreviewFeature inline fun Message.asCommonGroupEventMessage(): CommonGroupEventMessage? = this as? CommonGroupEventMessage @PreviewFeature inline fun Message.requireCommonGroupEventMessage(): CommonGroupEventMessage = this as CommonGroupEventMessage @PreviewFeature -inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage? = this as? CommonMediaGroupMessage +inline fun Message.asCommonMediaGroupMessage(): CommonMediaGroupMessage? = this as? CommonMediaGroupMessage @PreviewFeature -inline fun Message.requireCommonMediaGroupMessage(): CommonMediaGroupMessage = this as CommonMediaGroupMessage +inline fun Message.requireCommonMediaGroupMessage(): CommonMediaGroupMessage = this as CommonMediaGroupMessage @PreviewFeature inline fun Message.asCommonSupergroupEventMessage(): CommonSupergroupEventMessage? = this as? CommonSupergroupEventMessage @PreviewFeature @@ -212,9 +212,9 @@ inline fun Message.asGroupMessage(): GroupMessage? = this as? Gr @PreviewFeature inline fun Message.requireGroupMessage(): GroupMessage = this as GroupMessage @PreviewFeature -inline fun Message.asMediaGroupMessage(): MediaGroupMessage? = this as? MediaGroupMessage +inline fun Message.asMediaGroupMessage(): MediaGroupMessage? = this as? MediaGroupMessage @PreviewFeature -inline fun Message.requireMediaGroupMessage(): MediaGroupMessage = this as MediaGroupMessage +inline fun Message.requireMediaGroupMessage(): MediaGroupMessage = this as MediaGroupMessage @PreviewFeature inline fun Message.asPossiblyEditedMessage(): PossiblyEditedMessage? = this as? PossiblyEditedMessage @PreviewFeature diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt index 031d187697..78376ea9ad 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/shortcuts/MediaGroupsShortcuts.kt @@ -8,13 +8,13 @@ import dev.inmo.tgbotapi.types.message.abstracts.* import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.SentMediaGroupUpdate -val List>.forwardInfo: ForwardInfo? +val List>.forwardInfo: ForwardInfo? get() = firstOrNull() ?.forwardInfo -val List>.replyTo: Message? +val List>.replyTo: Message? get() = firstOrNull() ?.replyTo -val List>.chat: Chat? +val List>.chat: Chat? get() = firstOrNull() ?.chat -val List.mediaGroupId: MediaGroupIdentifier? +val List>.mediaGroupId: MediaGroupIdentifier? get() = firstOrNull() ?.mediaGroupId val SentMediaGroupUpdate.forwardInfo: ForwardInfo? @@ -30,7 +30,7 @@ fun List>.createResend( chatId: ChatId, disableNotification: Boolean = false, replyTo: MessageIdentifier? = null -) = SendMediaGroup( +) = SendMediaGroup( chatId, map { it.content.toMediaGroupMemberInputMedia() }, disableNotification, diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt index 4d0963708f..63a3983c87 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/UpdatesUtils.kt @@ -34,7 +34,7 @@ fun List.convertWithMediaGroupUpdates(): List { val resultUpdates = mutableListOf() val mediaGroups = mutableMapOf>() for (update in this) { - val data = (update.data as? MediaGroupMessage) + val data = (update.data as? MediaGroupMessage<*>) if (data == null) { resultUpdates.add(update) continue diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt index 75ef278a8d..bae30b47ce 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/MediaGroupsIncluder.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.extensions.utils.updates.retrieving import dev.inmo.tgbotapi.extensions.utils.updates.convertWithMediaGroupUpdates import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage +import dev.inmo.tgbotapi.types.message.content.abstracts.MediaGroupContent import dev.inmo.tgbotapi.types.update.abstracts.BaseMessageUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.UpdateReceiver @@ -32,7 +33,7 @@ fun CoroutineScope.updateHandlerWithMediaGroupsAdaptation( launch { for (update in updatesChannel) { when (val data = update.data) { - is MediaGroupMessage -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) + is MediaGroupMessage<*> -> mediaGroupChannel.send("${data.mediaGroupId}${update::class.simpleName}" to update as BaseMessageUpdate) else -> output(update) } } From b973278b0abe41b51787213f6586e53832db975b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Jan 2021 11:00:12 +0600 Subject: [PATCH 18/43] add note about breaking changes --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5207890f8..b3a6ac5d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,13 @@ ## 0.32.0 +**THIS UPDATE CONTAINS BREAKING CHANGES** + * `Common`: * `Version`: * `MicroUtils`: `0.4.16` -> `0.4.18` * `Core`: - * Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` + * **BC** Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` * Methods and types related to `MediaGroupMessage` have been modified according to their meanings ## 0.31.0 From 30a4a7bd8b295fecc240d669240dc2c3b2382936 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Jan 2021 13:52:06 +0600 Subject: [PATCH 19/43] update micro_utils dependency --- CHANGELOG.md | 2 +- gradle.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3a6ac5d75..8e5dfe89dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * `Common`: * `Version`: - * `MicroUtils`: `0.4.16` -> `0.4.18` + * `MicroUtils`: `0.4.16` -> `0.4.19` * `Core`: * **BC** Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` * Methods and types related to `MediaGroupMessage` have been modified according to their meanings diff --git a/gradle.properties b/gradle.properties index cc3412fe0d..f23a194d11 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.3 uuid_version=0.2.3 ktor_version=1.5.0 -micro_utils_version=0.4.18 +micro_utils_version=0.4.19 javax_activation_version=1.1.1 From fc71e028c47ea0eb68764af2de39c8ffe16780b1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Jan 2021 18:50:45 +0600 Subject: [PATCH 20/43] improving work of behaviour_builder --- CHANGELOG.md | 11 ++- .../updateshandlers/FlowsUpdatesFilter.kt | 76 +++++++++++++------ .../behaviour_builder/BehaviourContext.kt | 52 ++++++++++++- .../extensions/behaviour_builder/Variants.kt | 21 +++++ .../expectations/WaitContent.kt | 24 +++--- .../expectations/WaitMediaGroup.kt | 20 +++-- .../CallbackQueryTriggers.kt | 28 +++---- .../triggers_handling/CommandHandling.kt | 13 ++++ .../triggers_handling/ContentTriggers.kt | 56 +++++--------- .../triggers_handling/EventTriggers.kt | 27 ++----- .../triggers_handling/MediaGroupTriggers.kt | 48 ++++++------ 11 files changed, 234 insertions(+), 142 deletions(-) create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e5dfe89dc..49f696735e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,17 @@ * `Version`: * `MicroUtils`: `0.4.16` -> `0.4.19` * `Core`: - * **BC** Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` + * **BREAKING CHANGE** Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` * Methods and types related to `MediaGroupMessage` have been modified according to their meanings + * **Important Change** `FlowsUpdatesFilter` now is an interface. Old class has been renamed to + `DefaultFlowsUpdatesFilter` and factory method `FlowsUpdatesFilter` has been added +* `Behaviour Builder`: + * Trigger and expectation extensions for `MessageContent` (`onContentMessage` and `waitContentMessage`) + * `onMediaGroup` has been replaced + * `waitMediaGroup` has been added + * `onVisualMediaGroup` now is just an alternative to `onVisualGallery` + * `command` and `onCommand` expectations has been added for commands `String` variant + * New extensions `BehaviourContext#oneOf`, `BehaviourContext#parallel` and `Deferred#withAction` ## 0.31.0 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt index e44d863dd5..b07bc97cf6 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/updateshandlers/FlowsUpdatesFilter.kt @@ -7,15 +7,47 @@ import dev.inmo.tgbotapi.types.update.abstracts.UnknownUpdate import dev.inmo.tgbotapi.types.update.abstracts.Update import kotlinx.coroutines.flow.* -@Suppress("EXPERIMENTAL_API_USAGE", "unused") -class FlowsUpdatesFilter( +interface FlowsUpdatesFilter : UpdatesFilter { + override val allowedUpdates: List + get() = ALL_UPDATES_LIST + val allUpdatesFlow: Flow + val allUpdatesWithoutMediaGroupsGroupingFlow: Flow + + val messageFlow: Flow + val messageMediaGroupFlow: Flow + val editedMessageFlow: Flow + val editedMessageMediaGroupFlow: Flow + val channelPostFlow: Flow + val channelPostMediaGroupFlow: Flow + val editedChannelPostFlow: Flow + val editedChannelPostMediaGroupFlow: Flow + val chosenInlineResultFlow: Flow + val inlineQueryFlow: Flow + val callbackQueryFlow: Flow + val shippingQueryFlow: Flow + val preCheckoutQueryFlow: Flow + val pollFlow: Flow + val pollAnswerFlow: Flow + val unknownUpdateTypeFlow: Flow +} + +/** + * Creates [DefaultFlowsUpdatesFilter] + */ +@Suppress("FunctionName") +fun FlowsUpdatesFilter( broadcastChannelsSize: Int = 100 -): UpdatesFilter { +) = DefaultFlowsUpdatesFilter(broadcastChannelsSize) + +@Suppress("EXPERIMENTAL_API_USAGE", "unused") +class DefaultFlowsUpdatesFilter( + broadcastChannelsSize: Int = 100 +): FlowsUpdatesFilter { private val updatesSharedFlow = MutableSharedFlow(extraBufferCapacity = broadcastChannelsSize) @Suppress("MemberVisibilityCanBePrivate") - val allUpdatesFlow: Flow = updatesSharedFlow.asSharedFlow() + override val allUpdatesFlow: Flow = updatesSharedFlow.asSharedFlow() @Suppress("MemberVisibilityCanBePrivate") - val allUpdatesWithoutMediaGroupsGroupingFlow: Flow = updatesSharedFlow.flatMapConcat { + override val allUpdatesWithoutMediaGroupsGroupingFlow: Flow = allUpdatesFlow.flatMapConcat { when (it) { is SentMediaGroupUpdate -> it.origins.asFlow() is EditMediaGroupUpdate -> flowOf(it.origin) @@ -23,26 +55,24 @@ class FlowsUpdatesFilter( } } - override val allowedUpdates: List - get() = ALL_UPDATES_LIST override val asUpdateReceiver: UpdateReceiver = { updatesSharedFlow.emit(it) } - val messageFlow: Flow = allUpdatesFlow.filterIsInstance() - val messageMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() - val editedMessageFlow: Flow = allUpdatesFlow.filterIsInstance() - val editedMessageMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() - val channelPostFlow: Flow = allUpdatesFlow.filterIsInstance() - val channelPostMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() - val editedChannelPostFlow: Flow = allUpdatesFlow.filterIsInstance() - val editedChannelPostMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() - val chosenInlineResultFlow: Flow = allUpdatesFlow.filterIsInstance() - val inlineQueryFlow: Flow = allUpdatesFlow.filterIsInstance() - val callbackQueryFlow: Flow = allUpdatesFlow.filterIsInstance() - val shippingQueryFlow: Flow = allUpdatesFlow.filterIsInstance() - val preCheckoutQueryFlow: Flow = allUpdatesFlow.filterIsInstance() - val pollFlow: Flow = allUpdatesFlow.filterIsInstance() - val pollAnswerFlow: Flow = allUpdatesFlow.filterIsInstance() - val unknownUpdateTypeFlow: Flow = allUpdatesFlow.filterIsInstance() + override val messageFlow: Flow = allUpdatesFlow.filterIsInstance() + override val messageMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() + override val editedMessageFlow: Flow = allUpdatesFlow.filterIsInstance() + override val editedMessageMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() + override val channelPostFlow: Flow = allUpdatesFlow.filterIsInstance() + override val channelPostMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() + override val editedChannelPostFlow: Flow = allUpdatesFlow.filterIsInstance() + override val editedChannelPostMediaGroupFlow: Flow = allUpdatesFlow.filterIsInstance() + override val chosenInlineResultFlow: Flow = allUpdatesFlow.filterIsInstance() + override val inlineQueryFlow: Flow = allUpdatesFlow.filterIsInstance() + override val callbackQueryFlow: Flow = allUpdatesFlow.filterIsInstance() + override val shippingQueryFlow: Flow = allUpdatesFlow.filterIsInstance() + override val preCheckoutQueryFlow: Flow = allUpdatesFlow.filterIsInstance() + override val pollFlow: Flow = allUpdatesFlow.filterIsInstance() + override val pollAnswerFlow: Flow = allUpdatesFlow.filterIsInstance() + override val unknownUpdateTypeFlow: Flow = allUpdatesFlow.filterIsInstance() } \ No newline at end of file diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt index 5d3afb72a1..d881a5f1ba 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext.kt @@ -1,9 +1,11 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.types.update.abstracts.Update import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter -import dev.inmo.tgbotapi.updateshandlers.UpdatesFilter -import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.filter typealias BehaviourContextReceiver = suspend BehaviourContext.() -> T typealias BehaviourContextAndTypeReceiver = suspend BehaviourContext.(I) -> T @@ -19,4 +21,48 @@ data class BehaviourContext( val bot: TelegramBot, val scope: CoroutineScope, val flowsUpdatesFilter: FlowsUpdatesFilter = FlowsUpdatesFilter() -) : UpdatesFilter by flowsUpdatesFilter, TelegramBot by bot, CoroutineScope by scope +) : FlowsUpdatesFilter by flowsUpdatesFilter, TelegramBot by bot, CoroutineScope by scope + +/** + * Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [newFlowsUpdatesFilterSetUp] is provided and + * [CoroutineScope] as new [BehaviourContext.scope] + * + * @param newFlowsUpdatesFilterSetUp As a parameter receives [FlowsUpdatesFilter] from old [this] [BehaviourContext.flowsUpdatesFilter] + */ +suspend fun BehaviourContext.doInSubContextWithFlowsUpdatesFilterSetup( + newFlowsUpdatesFilterSetUp: BehaviourContextAndTypeReceiver?, + behaviourContextReceiver: BehaviourContextReceiver +) = copy( + flowsUpdatesFilter = FlowsUpdatesFilter(), + scope = CoroutineScope(scope.coroutineContext + SupervisorJob()) +).run { + newFlowsUpdatesFilterSetUp ?.let { + it.apply { invoke(this@run, this@doInSubContextWithFlowsUpdatesFilterSetup.flowsUpdatesFilter) } + } + behaviourContextReceiver().also { stop() } +} + +/** + * Creates new one [BehaviourContext], adding subsequent [FlowsUpdatesFilter] in case [updatesFilter] is provided and + * [CoroutineScope] as new [BehaviourContext.scope] + */ +suspend fun BehaviourContext.doInSubContextWithUpdatesFilter( + updatesFilter: BehaviourContextAndTypeReceiver?, + behaviourContextReceiver: BehaviourContextReceiver +) = doInSubContextWithFlowsUpdatesFilterSetup( + newFlowsUpdatesFilterSetUp = updatesFilter ?.let { + { oldOne -> + oldOne.allUpdatesFlow.filter { updatesFilter(it) }.subscribeSafelyWithoutExceptions(scope, asUpdateReceiver) + } + }, + behaviourContextReceiver +) + +suspend fun BehaviourContext.doInSubContext( + behaviourContextReceiver: BehaviourContextReceiver +) = doInSubContextWithFlowsUpdatesFilterSetup(newFlowsUpdatesFilterSetUp = null, behaviourContextReceiver) + +/** + * This method will cancel ALL subsequent contexts, expectations and waiters + */ +fun BehaviourContext.stop() = scope.cancel() diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt new file mode 100644 index 0000000000..4289c347a5 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder + +import dev.inmo.micro_utils.coroutines.DeferredAction +import dev.inmo.micro_utils.coroutines.invokeFirstOf +import kotlinx.coroutines.* + +suspend fun BehaviourContext.parallel( + action: BehaviourContextReceiver +) = async { + action() +} + +inline infix fun Deferred.withAction(noinline callback: suspend (T) -> O) = DeferredAction(this, callback) + +suspend fun BehaviourContext.oneOf( + deferredActions: Iterable> +) = deferredActions.invokeFirstOf(scope) + +suspend fun BehaviourContext.oneOf( + vararg deferredActions: DeferredAction<*, O> +) = oneOf(deferredActions.toList()) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt index 26a55849df..fe5cdbf153 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitContent.kt @@ -59,6 +59,12 @@ private suspend inline fun BehaviourContext.waitCon } } +suspend fun BehaviourContext.waitContentMessage( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: CommonMessageToContentMapper? = null +) = waitContent(count, initRequest, false, errorFactory, filter) suspend fun BehaviourContext.waitContact( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, @@ -101,14 +107,14 @@ suspend fun BehaviourContext.waitVenue( count: Int = 1, filter: CommonMessageToContentMapper? = null ) = waitContent(count, initRequest, false, errorFactory, filter) -suspend fun BehaviourContext.waitAudioMediaGroup( +suspend fun BehaviourContext.waitAudioMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = true, filter: CommonMessageToContentMapper? = null ) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) -suspend fun BehaviourContext.waitDocumentMediaGroup( +suspend fun BehaviourContext.waitDocumentMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, @@ -119,17 +125,17 @@ suspend fun BehaviourContext.waitMedia( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, filter: CommonMessageToContentMapper? = null ) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) -suspend fun BehaviourContext.waitMediaGroup( +suspend fun BehaviourContext.waitAnyMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, includeMediaGroups: Boolean = true, filter: CommonMessageToContentMapper? = null ) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) -suspend fun BehaviourContext.waitVisualMediaGroup( +suspend fun BehaviourContext.waitVisualMediaGroupContent( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, @@ -146,21 +152,21 @@ suspend fun BehaviourContext.waitAudio( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, filter: CommonMessageToContentMapper? = null ) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) suspend fun BehaviourContext.waitDocument( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, filter: CommonMessageToContentMapper? = null ) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) suspend fun BehaviourContext.waitPhoto( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, filter: CommonMessageToContentMapper? = null ) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) suspend fun BehaviourContext.waitSticker( @@ -173,7 +179,7 @@ suspend fun BehaviourContext.waitVideo( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, filter: CommonMessageToContentMapper? = null ) = waitContent(count, initRequest, includeMediaGroups, errorFactory, filter) suspend fun BehaviourContext.waitVideoNote( diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt index 0ed50f8add..5aa0bc8e90 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitMediaGroup.kt @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList @PreviewFeature -internal suspend inline fun BehaviourContext.onMediaGroup( +internal suspend inline fun BehaviourContext.buildMediaGroupWaiter( count: Int = 1, initRequest: Request<*>? = null, noinline errorFactory: NullableRequestBuilder<*> = { null }, @@ -21,7 +21,7 @@ internal suspend inline fun BehaviourContext.onM update.asSentMediaGroupUpdate() ?.data ?.let { mediaGroup -> if (mediaGroup.all { message -> message.content is T } && (filter == null || filter(mediaGroup as List>))) { listOf( - mediaGroup.map { it.content as T } as List> + mediaGroup.map { it.content as T } ) } else { null @@ -29,33 +29,39 @@ internal suspend inline fun BehaviourContext.onM } ?: emptyList() }.take(count).toList() +suspend fun BehaviourContext.waitMediaGroup( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: (suspend (List>) -> Boolean)? = null +) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitPlaylist( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, filter: (suspend (List>) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) +) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitDocumentsGroup( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, filter: (suspend (List>) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) +) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitVisualGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, filter: (suspend (List>) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) +) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitPhotoGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, filter: (suspend (List>) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) +) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) suspend fun BehaviourContext.waitVideoGallery( initRequest: Request<*>? = null, errorFactory: NullableRequestBuilder<*> = { null }, count: Int = 1, filter: (suspend (List>) -> Boolean)? = null -) = onMediaGroup(count, initRequest, errorFactory, filter) +) = buildMediaGroupWaiter(count, initRequest, errorFactory, filter) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt index 5432c7fa58..d66c64eab8 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CallbackQueryTriggers.kt @@ -1,18 +1,12 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver +import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.CallbackQuery.* -import dev.inmo.tgbotapi.types.message.ChatEvents.* -import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* -import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter -import kotlinx.coroutines.flow.filter internal suspend inline fun BehaviourContext.onCallbackQuery( includeFilterByChatInBehaviourSubContext: Boolean = true, @@ -27,19 +21,15 @@ internal suspend inline fun BehaviourContext.onCallb } }.let(::listOfNotNull) }.subscribeSafelyWithoutExceptions(scope) { triggerQuery -> - val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) { - val subFilter = FlowsUpdatesFilter() - val subBehaviourContext = copy(flowsUpdatesFilter = subFilter) - - flowsUpdatesFilter.allUpdatesFlow.filter { - val chat = it.sourceChat() ?: return@filter false - chat.id.chatId == triggerQuery.user.id.chatId - }.subscribeSafelyWithoutExceptions(scope, subFilter.asUpdateReceiver) to subBehaviourContext - } else { - null to this + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerQuery.user.id.chatId } + } else { + null + } + ) { + scenarioReceiver(triggerQuery) } - safelyWithoutExceptions { scenario.scenarioReceiver(triggerQuery) } - jobToCancel ?.cancel() } diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt index ab7ebe9060..35c88e1f0e 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/CommandHandling.kt @@ -26,6 +26,12 @@ suspend fun BehaviourContext.command( }, scenarioReceiver ) +suspend fun BehaviourContext.command( + command: String, + requireOnlyCommandInMessage: Boolean = true, + includeFilterByChatInBehaviourSubContext: Boolean = true, + scenarioReceiver: BehaviourContextAndTypeReceiver> +) = command(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, scenarioReceiver) suspend inline fun BehaviourContext.onCommand( commandRegex: Regex, @@ -33,3 +39,10 @@ suspend inline fun BehaviourContext.onCommand( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline scenarioReceiver: BehaviourContextAndTypeReceiver> ): Job = command(commandRegex, requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, scenarioReceiver) + +suspend inline fun BehaviourContext.onCommand( + command: String, + requireOnlyCommandInMessage: Boolean = true, + includeFilterByChatInBehaviourSubContext: Boolean = true, + noinline scenarioReceiver: BehaviourContextAndTypeReceiver> +): Job = onCommand(command.toRegex(), requireOnlyCommandInMessage, includeFilterByChatInBehaviourSubContext, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt index a12e414286..591686026e 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/ContentTriggers.kt @@ -2,11 +2,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling - -import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver +import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat @@ -16,9 +13,7 @@ import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent -import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.utils.PreviewFeature -import kotlinx.coroutines.flow.filter typealias CommonMessageFilter = (suspend (CommonMessage) -> Boolean) @@ -50,21 +45,22 @@ internal suspend inline fun BehaviourContext.onCont } }.let(::listOfNotNull) }.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> - val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) { - val subFilter = FlowsUpdatesFilter() - val subBehaviourContext = copy(flowsUpdatesFilter = subFilter) - - flowsUpdatesFilter.allUpdatesFlow.filter { - val chat = it.sourceChat() ?: return@filter false - chat.id.chatId == triggerMessage.chat.id.chatId - }.subscribeSafelyWithoutExceptions(scope, subFilter.asUpdateReceiver) to subBehaviourContext - } else { - null to this + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else { + null + } + ) { + scenarioReceiver(triggerMessage) } - safelyWithoutExceptions { scenario.scenarioReceiver(triggerMessage) } - jobToCancel ?.cancel() } +suspend fun BehaviourContext.onContentMessage( + includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: CommonMessageFilter? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver> +) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onContact( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, @@ -105,7 +101,7 @@ suspend fun BehaviourContext.onAudioMediaGroup( additionalFilter: CommonMessageFilter? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onContent(includeFilterByChatInBehaviourSubContext, true, additionalFilter, scenarioReceiver) -suspend fun BehaviourContext.onDocumentMediaGroup( +suspend fun BehaviourContext.onDocumentMediaGroupContent( includeFilterByChatInBehaviourSubContext: Boolean = true, includeMediaGroups: Boolean = true, additionalFilter: CommonMessageFilter? = null, @@ -113,7 +109,7 @@ suspend fun BehaviourContext.onDocumentMediaGroup( ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onMediaCollection( includeFilterByChatInBehaviourSubContext: Boolean = true, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, additionalFilter: (suspend (CommonMessage>) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver>> ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) @@ -123,18 +119,6 @@ suspend fun BehaviourContext.onMedia( additionalFilter: CommonMessageFilter? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) -suspend fun BehaviourContext.onMediaGroup( - includeFilterByChatInBehaviourSubContext: Boolean = true, - includeMediaGroups: Boolean = true, - additionalFilter: CommonMessageFilter? = null, - scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) -suspend fun BehaviourContext.onVisualMediaGroup( - includeFilterByChatInBehaviourSubContext: Boolean = true, - includeMediaGroups: Boolean = true, - additionalFilter: CommonMessageFilter? = null, - scenarioReceiver: BehaviourContextAndTypeReceiver> -) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onAnimation( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: CommonMessageFilter? = null, @@ -142,19 +126,19 @@ suspend fun BehaviourContext.onAnimation( ) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onAudio( includeFilterByChatInBehaviourSubContext: Boolean = true, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onDocument( includeFilterByChatInBehaviourSubContext: Boolean = true, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onPhoto( includeFilterByChatInBehaviourSubContext: Boolean = true, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) @@ -165,7 +149,7 @@ suspend fun BehaviourContext.onSticker( ) = onContent(includeFilterByChatInBehaviourSubContext, false, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVideo( includeFilterByChatInBehaviourSubContext: Boolean = true, - includeMediaGroups: Boolean = true, + includeMediaGroups: Boolean = false, additionalFilter: CommonMessageFilter? = null, scenarioReceiver: BehaviourContextAndTypeReceiver> ) = onContent(includeFilterByChatInBehaviourSubContext, includeMediaGroups, additionalFilter, scenarioReceiver) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt index c3a9d1b0da..d5b9404550 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/EventTriggers.kt @@ -1,21 +1,14 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver +import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.message.ChatEvents.* import dev.inmo.tgbotapi.types.message.ChatEvents.abstracts.* import dev.inmo.tgbotapi.types.message.abstracts.ChatEventMessage -import dev.inmo.tgbotapi.types.message.content.* -import dev.inmo.tgbotapi.types.message.content.abstracts.* -import dev.inmo.tgbotapi.types.message.content.media.* -import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter -import kotlinx.coroutines.flow.filter internal suspend inline fun BehaviourContext.onEvent( includeFilterByChatInBehaviourSubContext: Boolean = true, @@ -31,19 +24,13 @@ internal suspend inline fun BehaviourContext.onEvent( } }.let(::listOfNotNull) }.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> - val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) { - val subFilter = FlowsUpdatesFilter() - val subBehaviourContext = copy(flowsUpdatesFilter = subFilter) - - flowsUpdatesFilter.allUpdatesFlow.filter { - val chat = it.sourceChat() ?: return@filter false - chat.id.chatId == triggerMessage.chat.id.chatId - }.subscribeSafelyWithoutExceptions(scope, subFilter.asUpdateReceiver) to subBehaviourContext - } else { - null to this + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else null + ) { + scenarioReceiver(triggerMessage) } - safelyWithoutExceptions { scenario.scenarioReceiver(triggerMessage) } - jobToCancel ?.cancel() } suspend fun BehaviourContext.onChannelEvent( diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt index 6e195fddbc..639f2cbeff 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/MediaGroupTriggers.kt @@ -2,10 +2,8 @@ package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling -import dev.inmo.micro_utils.coroutines.safelyWithoutExceptions import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext -import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContextAndTypeReceiver +import dev.inmo.tgbotapi.extensions.behaviour_builder.* import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat @@ -13,12 +11,10 @@ import dev.inmo.tgbotapi.extensions.utils.shortcuts.chat import dev.inmo.tgbotapi.types.message.abstracts.MediaGroupMessage import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* -import dev.inmo.tgbotapi.updateshandlers.FlowsUpdatesFilter import dev.inmo.tgbotapi.utils.PreviewFeature -import kotlinx.coroutines.flow.filter @PreviewFeature -internal suspend inline fun BehaviourContext.onMediaGroup( +internal suspend inline fun BehaviourContext.buildMediaGroupTrigger( includeFilterByChatInBehaviourSubContext: Boolean = true, noinline additionalFilter: (suspend (List>) -> Boolean)? = null, noinline scenarioReceiver: BehaviourContextAndTypeReceiver>> @@ -31,45 +27,49 @@ internal suspend inline fun BehaviourContext.onM } } ?: emptyList() }.subscribeSafelyWithoutExceptions(scope) { mediaGroup -> - val (jobToCancel, scenario) = if (includeFilterByChatInBehaviourSubContext) { - val subFilter = FlowsUpdatesFilter() - val subBehaviourContext = copy(flowsUpdatesFilter = subFilter) - val mediaGroupChat = mediaGroup.chat!! - - flowsUpdatesFilter.allUpdatesFlow.filter { - val chat = it.sourceChat() ?: return@filter false - chat.id.chatId == mediaGroupChat.id.chatId - }.subscribeSafelyWithoutExceptions(scope, subFilter.asUpdateReceiver) to subBehaviourContext - } else { - null to this + val mediaGroupChat = mediaGroup.chat!! + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == mediaGroupChat.id.chatId } + } else null + ) { + scenarioReceiver(mediaGroup) } - safelyWithoutExceptions { scenario.scenarioReceiver(mediaGroup) } - jobToCancel ?.cancel() } +suspend fun BehaviourContext.onMediaGroup( + includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: (suspend (List>) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver>> +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onPlaylist( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onDocumentsGroup( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVisualGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +suspend fun BehaviourContext.onVisualMediaGroup( + includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: (suspend (List>) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver>> +) = onVisualGallery(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onPhotoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) suspend fun BehaviourContext.onVideoGallery( includeFilterByChatInBehaviourSubContext: Boolean = true, additionalFilter: (suspend (List>) -> Boolean)? = null, scenarioReceiver: BehaviourContextAndTypeReceiver>> -) = onMediaGroup(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) +) = buildMediaGroupTrigger(includeFilterByChatInBehaviourSubContext, additionalFilter, scenarioReceiver) From 08b87107729990a9d7fcf44ef7172940e4da47d5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Jan 2021 20:18:30 +0600 Subject: [PATCH 21/43] add asAction and several variants of oneOf --- .../extensions/behaviour_builder/Variants.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt index 4289c347a5..63ed115bef 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/Variants.kt @@ -12,10 +12,20 @@ suspend fun BehaviourContext.parallel( inline infix fun Deferred.withAction(noinline callback: suspend (T) -> O) = DeferredAction(this, callback) -suspend fun BehaviourContext.oneOf( +inline fun Deferred.asAction() = DeferredAction(this) { it } + +suspend fun BehaviourContext.oneOfActions( deferredActions: Iterable> ) = deferredActions.invokeFirstOf(scope) -suspend fun BehaviourContext.oneOf( +suspend fun BehaviourContext.oneOfActions( vararg deferredActions: DeferredAction<*, O> +) = this@oneOfActions.oneOfActions(deferredActions.toList()) + +suspend fun BehaviourContext.oneOf( + deferredActions: Iterable> +) = oneOfActions(deferredActions.map { it.asAction() }) + +suspend fun BehaviourContext.oneOf( + vararg deferredActions: Deferred ) = oneOf(deferredActions.toList()) From 9983e111ec77684ddc4c5ba26311c07cac45baf1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 22 Jan 2021 21:53:37 +0600 Subject: [PATCH 22/43] update EncryptedElementSerializer --- gradle.properties | 2 +- tgbotapi.core/build.gradle | 1 + .../EncryptedElementSerializer.kt | 89 +++++++------------ 3 files changed, 32 insertions(+), 60 deletions(-) diff --git a/gradle.properties b/gradle.properties index f23a194d11..2f911f8bab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.3 uuid_version=0.2.3 ktor_version=1.5.0 -micro_utils_version=0.4.19 +micro_utils_version=0.4.20 javax_activation_version=1.1.1 diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index 7ba634fb89..d38ff75ff5 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -48,6 +48,7 @@ kotlin { api "dev.inmo:micro_utils.coroutines:$micro_utils_version" api "dev.inmo:micro_utils.serialization.base64:$micro_utils_version" + api "dev.inmo:micro_utils.serialization.encapsulator:$micro_utils_version" api "io.ktor:ktor-client-core:$ktor_version" } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt index b149eba867..5499e76b22 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.serialization.encapsulator.Encapsulator import dev.inmo.tgbotapi.types.hashField import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.UnknownEncryptedPassportElement @@ -12,6 +13,22 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.* +val encryptedElementsClassesByTypes = mapOf( + "personal_details" to Encapsulator(EncryptedPersonalDetails::class, EncryptedPersonalDetails.serializer()), + "passport" to Encapsulator(CommonPassport::class, CommonPassport.serializer()), + "driver_license" to Encapsulator(DriverLicense::class, DriverLicense.serializer()), + "identity_card" to Encapsulator(IdentityCard::class, IdentityCard.serializer()), + "internal_passport" to Encapsulator(InternalPassport::class, InternalPassport.serializer()), + "address" to Encapsulator(EncryptedAddress::class, EncryptedAddress.serializer()), + "utility_bill" to Encapsulator(UtilityBill::class, UtilityBill.serializer()), + "bank_statement" to Encapsulator(BankStatement::class, BankStatement.serializer()), + "rental_agreement" to Encapsulator(RentalAgreement::class, RentalAgreement.serializer()), + "passport_registration" to Encapsulator(PassportRegistration::class, PassportRegistration.serializer()), + "temporary_registration" to Encapsulator(TemporaryRegistration::class, TemporaryRegistration.serializer()), + "phone_number" to Encapsulator(PhoneNumber::class, PhoneNumber.serializer()), + "email" to Encapsulator(Email::class, Email.serializer()) +) + @Serializer(EncryptedPassportElement::class) object EncryptedElementSerializer : KSerializer { private val jsonSerializer = JsonObject.serializer() @@ -19,69 +36,23 @@ object EncryptedElementSerializer : KSerializer { override fun deserialize(decoder: Decoder): EncryptedPassportElement { val json = jsonSerializer.deserialize(decoder) - return when (json[typeField] ?.jsonPrimitive ?.content) { - "personal_details" -> nonstrictJsonFormat.decodeFromJsonElement(EncryptedPersonalDetails.serializer(), json) - "passport" -> nonstrictJsonFormat.decodeFromJsonElement(CommonPassport.serializer(), json) - "driver_license" -> nonstrictJsonFormat.decodeFromJsonElement(DriverLicense.serializer(), json) - "identity_card" -> nonstrictJsonFormat.decodeFromJsonElement(IdentityCard.serializer(), json) - "internal_passport" -> nonstrictJsonFormat.decodeFromJsonElement(InternalPassport.serializer(), json) - "address" -> nonstrictJsonFormat.decodeFromJsonElement(EncryptedAddress.serializer(), json) - "utility_bill" -> nonstrictJsonFormat.decodeFromJsonElement(UtilityBill.serializer(), json) - "bank_statement" -> nonstrictJsonFormat.decodeFromJsonElement(BankStatement.serializer(), json) - "rental_agreement" -> nonstrictJsonFormat.decodeFromJsonElement(RentalAgreement.serializer(), json) - "passport_registration" -> nonstrictJsonFormat.decodeFromJsonElement(PassportRegistration.serializer(), json) - "temporary_registration" -> nonstrictJsonFormat.decodeFromJsonElement(TemporaryRegistration.serializer(), json) - "phone_number" -> nonstrictJsonFormat.decodeFromJsonElement(PhoneNumber.serializer(), json) - "email" -> nonstrictJsonFormat.decodeFromJsonElement(Email.serializer(), json) - else -> UnknownEncryptedPassportElement(json, json[hashField] ?.jsonPrimitive ?.content ?: "") - } + return json[typeField] ?.jsonPrimitive ?.content ?.let { type -> + encryptedElementsClassesByTypes[type] ?.serializer ?.let { deserializer -> + nonstrictJsonFormat.decodeFromJsonElement(deserializer, json) + } + } ?: UnknownEncryptedPassportElement(json, json[hashField] ?.jsonPrimitive ?.content ?: "") } override fun serialize(encoder: Encoder, value: EncryptedPassportElement) { - val json = when (value) { - is EncryptedPersonalDetails -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(EncryptedPersonalDetails.serializer(), value).jsonObject + (typeField to JsonPrimitive("personal_details")) - ) - is CommonPassport -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(CommonPassport.serializer(), value).jsonObject + (typeField to JsonPrimitive("passport")) - ) - is DriverLicense -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(DriverLicense.serializer(), value).jsonObject + (typeField to JsonPrimitive("driver_license")) - ) - is IdentityCard -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(IdentityCard.serializer(), value).jsonObject + (typeField to JsonPrimitive("identity_card")) - ) - is InternalPassport -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(InternalPassport.serializer(), value).jsonObject + (typeField to JsonPrimitive("internal_passport")) - ) - is EncryptedAddress -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(EncryptedAddress.serializer(), value).jsonObject + (typeField to JsonPrimitive("address")) - ) - is UtilityBill -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(UtilityBill.serializer(), value).jsonObject + (typeField to JsonPrimitive("utility_bill")) - ) - is BankStatement -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(BankStatement.serializer(), value).jsonObject + (typeField to JsonPrimitive("bank_statement")) - ) - is RentalAgreement -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(RentalAgreement.serializer(), value).jsonObject + (typeField to JsonPrimitive("rental_agreement")) - ) - is PassportRegistration -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(PassportRegistration.serializer(), value).jsonObject + (typeField to JsonPrimitive("passport_registration")) - ) - is TemporaryRegistration -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(TemporaryRegistration.serializer(), value).jsonObject + (typeField to JsonPrimitive("temporary_registration")) - ) - is PhoneNumber -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(PhoneNumber.serializer(), value).jsonObject + (typeField to JsonPrimitive("phone_number")) - ) - is Email -> JsonObject( - nonstrictJsonFormat.encodeToJsonElement(Email.serializer(), value).jsonObject + (typeField to JsonPrimitive("email")) - ) - is UnknownEncryptedPassportElement -> value.rawJson - else -> return + val json = value.let { + encryptedElementsClassesByTypes.forEach { (key, encapsulator) -> + val json = encapsulator.encapsulate(value) { data -> + nonstrictJsonFormat.encodeToJsonElement(this as KSerializer, data).jsonObject + } ?: return@forEach + return@let JsonObject(json + (typeField to JsonPrimitive(key))) + } + (value as? UnknownEncryptedPassportElement) ?.rawJson ?: return } jsonSerializer.serialize(encoder, json) } - } From e0ff14b7fed06e0370de86f3c117d2748380a019 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 22 Jan 2021 21:57:23 +0600 Subject: [PATCH 23/43] update gradle wrapper --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ca8c529fce..b9d52d8cb7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-bin.zip From f3590762f3506ba535e13eb3b45a515d7f0a93ec Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 22 Jan 2021 23:01:37 +0600 Subject: [PATCH 24/43] add PassportElementError realization --- .../requests/SetPassportDataErrors.kt | 19 ++ .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 12 + .../EncryptedElementSerializer.kt | 5 + .../passport/errors/PassportElementError.kt | 229 ++++++++++++++++++ 4 files changed, 265 insertions(+) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/errors/PassportElementError.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt new file mode 100644 index 0000000000..3bb3b34e74 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt @@ -0,0 +1,19 @@ +package dev.inmo.tgbotapi.requests + +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.passport.errors.PassportElementError +import kotlinx.serialization.* +import kotlinx.serialization.builtins.serializer + +@Serializable +data class SetPassportDataErrors( + @SerialName(userIdField) + val user: UserId, + @SerialName(errorsField) + val errors: List +) : Request { + override val resultDeserializer: DeserializationStrategy + get() = Boolean.serializer() + override fun method(): String = "setPassportDataErrors" +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index d73d87bb2c..7346a72269 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -362,8 +362,20 @@ const val dataField = "data" const val credentialsField = "credentials" const val hashField = "hash" const val translationField = "translation" +const val translationFileField = "translation_file" +const val fileField = "file" const val filesField = "files" +const val translationFilesField = "translation_files" const val frontSideField = "front_side" const val reverseSideField = "reverse_side" const val selfieField = "selfie" const val secretField = "secret" + +const val errorsField = "errors" +const val sourceField = "source" +const val fieldNameField = "field_name" +const val dataHashField = "data_hash" +const val fileHashField = "file_hash" +const val fileHashesField = "file_hashes" +const val messageField = "message" +const val unspecifiedField = "unspecified" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt index 5499e76b22..28caca9889 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt @@ -5,6 +5,7 @@ import dev.inmo.tgbotapi.types.hashField import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.UnknownEncryptedPassportElement import dev.inmo.tgbotapi.types.typeField +import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.KSerializer import kotlinx.serialization.Serializer @@ -29,6 +30,10 @@ val encryptedElementsClassesByTypes = mapOf( "email" to Encapsulator(Email::class, Email.serializer()) ) +@RiskFeature("Remember that this method may return \"unknown\" in case if encrypted element was not defined in library") +val EncryptedPassportElement.type: String + get() = encryptedElementsClassesByTypes.keys.firstOrNull { encryptedElementsClassesByTypes.getValue(it).klass.isInstance(this) } ?: "unknown" + @Serializer(EncryptedPassportElement::class) object EncryptedElementSerializer : KSerializer { private val jsonSerializer = JsonObject.serializer() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/errors/PassportElementError.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/errors/PassportElementError.kt new file mode 100644 index 0000000000..d7526eee44 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/errors/PassportElementError.kt @@ -0,0 +1,229 @@ +package dev.inmo.tgbotapi.types.passport.errors + +import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import dev.inmo.tgbotapi.types.passport.encrypted_data.type +import kotlinx.serialization.* +import kotlinx.serialization.encoding.Encoder + +@Serializable(PassportElementErrorSerializer::class) +sealed class PassportElementError { + abstract val source: String + abstract val type: String + abstract val message: String +} + +@Serializer(PassportElementError::class) +internal object PassportElementErrorSerializer : KSerializer { + override fun serialize(encoder: Encoder, value: PassportElementError) { + val neverMindAboutThisVariable = when (value) { + is PassportElementErrorFrontSide -> PassportElementErrorFrontSide.serializer().serialize(encoder, value) + is PassportElementErrorReverseSide -> PassportElementErrorReverseSide.serializer().serialize(encoder, value) + is PassportElementErrorSelfie -> PassportElementErrorSelfie.serializer().serialize(encoder, value) + is PassportElementErrorFile -> PassportElementErrorFile.serializer().serialize(encoder, value) + is PassportElementErrorTranslationFile -> PassportElementErrorTranslationFile.serializer().serialize(encoder, value) + is PassportElementErrorUnspecified -> PassportElementErrorUnspecified.serializer().serialize(encoder, value) + is PassportElementErrorDataField -> PassportElementErrorDataField.serializer().serialize(encoder, value) + is PassportElementErrorFiles -> PassportElementErrorFiles.serializer().serialize(encoder, value) + is PassportElementErrorTranslationFiles -> PassportElementErrorTranslationFiles.serializer().serialize(encoder, value) + } + } +} + +@Serializable +sealed class PassportSingleElementError : PassportElementError() { + abstract val elementHash: String +} + +@Serializable +sealed class PassportMultipleElementsError : PassportElementError() { + abstract val elementsHashes: List +} + +@Serializable +sealed class PassportElementFileError : PassportSingleElementError() + +@Serializable +sealed class PassportElementFilesError : PassportMultipleElementsError() + +@Serializable +data class PassportElementErrorDataField( + @SerialName(typeField) + override val type: String, + @SerialName(fieldNameField) + val fieldName: String, + @SerialName(dataHashField) + @Serializable(Base64StringSerializer::class) + override val elementHash: String, + @SerialName(messageField) + override val message: String +) : PassportSingleElementError() { + @SerialName(sourceField) + @Required + override val source: String = dataField +} +fun WithData.createDataError(field: String, message: String) = PassportElementErrorDataField( + type, + field, + hash, + message +) + +@Serializable +data class PassportElementErrorFrontSide( + @SerialName(typeField) + override val type: String, + @SerialName(fileHashField) + @Serializable(Base64StringSerializer::class) + override val elementHash: String, + @SerialName(messageField) + override val message: String +) : PassportElementFileError() { + @SerialName(sourceField) + @Required + override val source: String = frontSideField +} +fun WithFrontSide.createFrontSideError(message: String, unencryptedFileHash: String) = PassportElementErrorFrontSide( + type, + unencryptedFileHash, + message +) + +@Serializable +data class PassportElementErrorReverseSide( + @SerialName(typeField) + override val type: String, + @SerialName(fileHashField) + @Serializable(Base64StringSerializer::class) + override val elementHash: String, + @SerialName(messageField) + override val message: String +) : PassportElementFileError() { + @SerialName(sourceField) + @Required + override val source: String = reverseSideField +} +fun WithReverseSide.createReverseSideError(message: String, unencryptedFileHash: String) = PassportElementErrorReverseSide( + type, + unencryptedFileHash, + message +) +@Serializable +data class PassportElementErrorSelfie( + @SerialName(typeField) + override val type: String, + @SerialName(fileHashField) + @Serializable(Base64StringSerializer::class) + override val elementHash: String, + @SerialName(messageField) + override val message: String +) : PassportElementFileError() { + @SerialName(sourceField) + @Required + override val source: String = selfieField +} +fun WithSelfie.createSelfieError(message: String, unencryptedFileHash: String) = PassportElementErrorSelfie( + type, + unencryptedFileHash, + message +) + + +@Serializable +data class PassportElementErrorFile( + @SerialName(typeField) + override val type: String, + @SerialName(fileHashField) + @Serializable(Base64StringSerializer::class) + override val elementHash: String, + @SerialName(messageField) + override val message: String +) : PassportElementFileError() { + @SerialName(sourceField) + @Required + override val source: String = fileField +} +fun FilesCollection.createFileError(message: String, unencryptedFileHash: String) = PassportElementErrorFile( + type, + unencryptedFileHash, + message +) + +@Serializable +data class PassportElementErrorFiles( + @SerialName(typeField) + override val type: String, + @SerialName(fileHashesField) + override val elementsHashes: List<@Serializable(Base64StringSerializer::class) String>, + @SerialName(messageField) + override val message: String +) : PassportElementFilesError() { + @SerialName(sourceField) + @Required + override val source: String = filesField +} +fun FilesCollection.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorFiles( + type, + unencryptedFileHashes, + message +) + + +@Serializable +data class PassportElementErrorTranslationFile( + @SerialName(typeField) + override val type: String, + @SerialName(fileHashField) + @Serializable(Base64StringSerializer::class) + override val elementHash: String, + @SerialName(messageField) + override val message: String +) : PassportElementFileError() { + @SerialName(sourceField) + @Required + override val source: String = translationFileField +} +fun Translatable.createFileError(message: String, unencryptedFileHash: String) = PassportElementErrorTranslationFile( + type, + unencryptedFileHash, + message +) +@Serializable +data class PassportElementErrorTranslationFiles( + @SerialName(typeField) + override val type: String, + @SerialName(fileHashesField) + override val elementsHashes: List<@Serializable(Base64StringSerializer::class) String>, + @SerialName(messageField) + override val message: String +) : PassportElementFilesError() { + @SerialName(sourceField) + @Required + override val source: String = translationFilesField +} +fun Translatable.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorTranslationFiles( + type, + unencryptedFileHashes, + message +) + +@Serializable +data class PassportElementErrorUnspecified( + @SerialName(typeField) + override val type: String, + @SerialName(fileHashField) + @Serializable(Base64StringSerializer::class) + override val elementHash: String, + @SerialName(messageField) + override val message: String +) : PassportElementFileError() { + @SerialName(sourceField) + @Required + override val source: String = unspecifiedField +} +fun EncryptedPassportElement.createUnspecifiedError(message: String, elementHash: String) = PassportElementErrorUnspecified( + type, + elementHash, + message +) From cdcfaf5a296aa6e8844b434a73e1889bc2ad27f4 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 22 Jan 2021 23:14:24 +0600 Subject: [PATCH 25/43] fixes in passport errors serialization and replacing of PassportElementError --- .../requests/SetPassportDataErrors.kt | 2 +- .../{errors => }/PassportElementError.kt | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{errors => }/PassportElementError.kt (75%) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt index 3bb3b34e74..d98d88574e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt @@ -2,7 +2,7 @@ package dev.inmo.tgbotapi.requests import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.errors.PassportElementError +import dev.inmo.tgbotapi.types.passport.PassportElementError import kotlinx.serialization.* import kotlinx.serialization.builtins.serializer diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/errors/PassportElementError.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt similarity index 75% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/errors/PassportElementError.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt index d7526eee44..5fa154736a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/errors/PassportElementError.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt @@ -1,11 +1,17 @@ -package dev.inmo.tgbotapi.types.passport.errors +@file:Suppress("unused", "EXPERIMENTAL_API_USAGE") + +package dev.inmo.tgbotapi.types.passport import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* import dev.inmo.tgbotapi.types.passport.encrypted_data.type +import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.* +import kotlinx.serialization.descriptors.SerialDescriptor +import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder +import kotlinx.serialization.json.* @Serializable(PassportElementErrorSerializer::class) sealed class PassportElementError { @@ -14,8 +20,33 @@ sealed class PassportElementError { abstract val message: String } -@Serializer(PassportElementError::class) -internal object PassportElementErrorSerializer : KSerializer { +data class UnknownPassportElementError( + val raw: JsonObject +) : PassportElementError() { + override val source: String = raw[sourceField] ?.jsonPrimitive ?.contentOrNull ?: "" + override val type: String = raw[typeField] ?.jsonPrimitive ?.contentOrNull ?: "" + override val message: String = raw[messageField] ?.jsonPrimitive ?.contentOrNull ?: "" +} + +object PassportElementErrorSerializer : KSerializer { + private val jsonObjectSerializer = JsonObject.serializer() + override val descriptor: SerialDescriptor + get() = jsonObjectSerializer.descriptor + override fun deserialize(decoder: Decoder): PassportElementError { + val json = jsonObjectSerializer.deserialize(decoder) + return when (json[sourceField] ?.jsonPrimitive ?.content) { + "dataField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorDataField.serializer(), json) + "frontSideField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorFrontSide.serializer(), json) + "reverseSideField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorReverseSide.serializer(), json) + "selfieField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorSelfie.serializer(), json) + "fileField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementFileError.serializer(), json) + "filesField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementFilesError.serializer(), json) + "translationFileField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorTranslationFile.serializer(), json) + "translationFilesField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorTranslationFiles.serializer(), json) + "unspecifiedField" -> nonstrictJsonFormat.decodeFromJsonElement(PassportElementErrorUnspecified.serializer(), json) + else -> UnknownPassportElementError(json) + } + } override fun serialize(encoder: Encoder, value: PassportElementError) { val neverMindAboutThisVariable = when (value) { is PassportElementErrorFrontSide -> PassportElementErrorFrontSide.serializer().serialize(encoder, value) @@ -27,6 +58,7 @@ internal object PassportElementErrorSerializer : KSerializer PassportElementErrorDataField.serializer().serialize(encoder, value) is PassportElementErrorFiles -> PassportElementErrorFiles.serializer().serialize(encoder, value) is PassportElementErrorTranslationFiles -> PassportElementErrorTranslationFiles.serializer().serialize(encoder, value) + is UnknownPassportElementError -> jsonObjectSerializer.serialize(encoder, value.raw) } } } From 1d99e632a4bf260f43876d85b619166b549c677f Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 22 Jan 2021 23:40:33 +0600 Subject: [PATCH 26/43] fix of SetPassportDataErrors request parent interface --- .../dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt index d98d88574e..80a039fd40 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/requests/SetPassportDataErrors.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.requests import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.requests.abstracts.SimpleRequest import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.PassportElementError import kotlinx.serialization.* @@ -12,8 +13,10 @@ data class SetPassportDataErrors( val user: UserId, @SerialName(errorsField) val errors: List -) : Request { +) : SimpleRequest { override val resultDeserializer: DeserializationStrategy get() = Boolean.serializer() override fun method(): String = "setPassportDataErrors" + override val requestSerializer: SerializationStrategy<*> + get() = serializer() } From 2f52ad45a4b1399b8832942df34ade32fe4274e9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 23 Jan 2021 12:21:57 +0600 Subject: [PATCH 27/43] add tools for passport files hashes calculation --- CHANGELOG.md | 2 +- gradle.properties | 2 +- tgbotapi.core/build.gradle | 1 + .../inmo/tgbotapi/types/passport/PassportElementError.kt | 5 +++++ .../kotlin/dev/inmo/tgbotapi/types/passport/FileHashes.kt | 7 +++++++ 5 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/passport/FileHashes.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 49f696735e..0bbbc0ccb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * `Common`: * `Version`: - * `MicroUtils`: `0.4.16` -> `0.4.19` + * `MicroUtils`: `0.4.16` -> `0.4.21` * `Core`: * **BREAKING CHANGE** Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` * Methods and types related to `MediaGroupMessage` have been modified according to their meanings diff --git a/gradle.properties b/gradle.properties index 2f911f8bab..5017be276e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ klock_version=2.0.3 uuid_version=0.2.3 ktor_version=1.5.0 -micro_utils_version=0.4.20 +micro_utils_version=0.4.21 javax_activation_version=1.1.1 diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index d38ff75ff5..dbb55557e9 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -46,6 +46,7 @@ kotlin { api "com.soywiz.korlibs.klock:klock:$klock_version" api "com.benasher44:uuid:$uuid_version" + api "dev.inmo:micro_utils.crypto:$micro_utils_version" api "dev.inmo:micro_utils.coroutines:$micro_utils_version" api "dev.inmo:micro_utils.serialization.base64:$micro_utils_version" api "dev.inmo:micro_utils.serialization.encapsulator:$micro_utils_version" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt index 5fa154736a..a3cf28594a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt @@ -2,6 +2,8 @@ package dev.inmo.tgbotapi.types.passport +import dev.inmo.micro_utils.crypto.MD5 +import dev.inmo.micro_utils.crypto.md5 import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* @@ -13,6 +15,9 @@ import kotlinx.serialization.encoding.Decoder import kotlinx.serialization.encoding.Encoder import kotlinx.serialization.json.* +val ByteArray.passportFileHash: MD5 + get() = md5() + @Serializable(PassportElementErrorSerializer::class) sealed class PassportElementError { abstract val source: String diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/passport/FileHashes.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/passport/FileHashes.kt new file mode 100644 index 0000000000..0249909252 --- /dev/null +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/types/passport/FileHashes.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.passport + +import dev.inmo.micro_utils.crypto.MD5 +import java.io.File + +val File.passportFileHash: MD5 + get() = readBytes().passportFileHash From d34deade0d8faa2ab5a3be52a8ce18108d80a4a8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 23 Jan 2021 18:49:34 +0600 Subject: [PATCH 28/43] temporal state (currently tools for files decryption in JS do work --- gradle.properties | 2 + tgbotapi.core/build.gradle | 6 ++- .../utils/passport/DecryptionContext.kt | 25 +++++++++ .../inmo/tgbotapi/passport/DecryptionTest.kt | 52 +++++++++++++++++++ .../passport/DecryptionContextRealization.kt | 50 ++++++++++++++++++ .../tgbotapi/passport/DecryptionTestKeys.kt | 32 ++++++++++++ .../passport/DecryptionContextRealization.kt | 40 ++++++++++++++ .../tgbotapi/passport/DecryptionTestKeys.kt | 31 +++++++++++ 8 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt create mode 100644 tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt create mode 100644 tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt create mode 100644 tgbotapi.core/src/jsTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt create mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt create mode 100644 tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt diff --git a/gradle.properties b/gradle.properties index 5017be276e..6f5f4fb15b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,6 +16,8 @@ micro_utils_version=0.4.21 javax_activation_version=1.1.1 +crypto_version=1.0.1 + library_group=dev.inmo library_version=0.32.0 diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index dbb55557e9..937d88062d 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -71,12 +71,16 @@ kotlin { api "javax.activation:activation:$javax_activation_version" } } + jsMain { + dependencies { + api npm("crypto", "${crypto_version}") + } + } jvmTest { dependencies { implementation kotlin('test-junit') } } - jsTest { dependencies { implementation kotlin('test-junit') diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt new file mode 100644 index 0000000000..5ce250d389 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt @@ -0,0 +1,25 @@ +package dev.inmo.tgbotapi.utils.passport + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.DownloadFile +import dev.inmo.tgbotapi.requests.get.GetFile +import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile + +expect class DecryptionContext( + key: String +) { + fun ByteArray.decrypt(): ByteArray +} + +suspend fun DecryptionContext.decrypt( + file: PassportFile, + bot: TelegramBot +): ByteArray { + return bot.execute( + DownloadFile( + bot.execute( + GetFile(file.fileId) + ).filePath + ) + ).decrypt() +} diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt new file mode 100644 index 0000000000..090ed96e02 --- /dev/null +++ b/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt @@ -0,0 +1,52 @@ +package dev.inmo.tgbotapi.passport + +import dev.inmo.micro_utils.crypto.decodeBase64 +import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData +import dev.inmo.tgbotapi.utils.passport.DecryptionContext +import kotlin.test.Test +import kotlin.test.assertEquals + +//expect val privateKey: String +//expect val encryptedLoremIpsum: EncryptedAndBase64EncodedData +val privateKey: String = """-----BEGIN PRIVATE KEY----- +MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCaaMFkmMBi6Vl5 +vzy7wQjoZNLN+e9e6Lb/WBekJxfbNMt+EN9Zv7xT9xzfY68DX7v0uGoLcAqS5Mh5 +8ELiJbzg4O8dbxkggt0G+kxcbT+a3ofm1Aqhr+LkpsFh5qbLqbAHSQJAF0HPqrAc +5c6MoQVTZlWGU/j3enCcUFo7Jpsi8La6MqYboF5xGwGEZ9tOA6rMDSekr5Rdm637 +D/w4h284UX7VnqPdpZ/943VK2qvmPjm8HkFSxkSAB8RHlFyjazzm9FNOcVRGLynv +/cq7mWgyxt5nqiCG7w+lFNAFNQNvAO0rfeiTJbEzubquu4Mg31QrvLIuz+fUbsGk +ipfpN1czAgMBAAECggEAPlAoO8CpY0FoqolSqTKttZt6t0U2JMclksaqQ8TDC+Oy +e52zhTSre/ct37kK2AG6iHgj05nTqpRJk2wykbFJGDeuR+Kd8VDeggJg7qvoD0fe +8HiCEd45Yq0pPaknhulj8Iy2K8c29+eaSw8y2+3fiFi0CxG4V6dB6tNClrxtvxtl +IE85Utzmk4PLTCs010zxNVm+FwrvqlpjjhspljzleUuWE1KuldO9tNSlwUUfBr4i +BJJn4jDkQMloXoM/ArZEp7mn57N9+ZuEgVjRMCpRGEAbQI+aLCznBB1kCOY7WL8S +CwkP++SvcptaUpOjoXZZyuGU4CgBnu0+40ORbNchgQKBgQDLIbB9+WHDcZAn1g6M +8jaNDRU4HGu5vJSajFQK8Uaczg87hAxmk6R1GF0LOyoadaVmD5ax93mQxWSE/4hT +wyAPaQOFl7A/i1k/Dx/kURjRwF1sLWDFdMo/8t5bXumzrzb1bHYnHPS7S0lBAU+X +SrbIw+hv69aKawcQqdd54S1OBwKBgQDCmMarwMVn4xnOh+DOuLS4IQzPT84WgzH+ +wKw55hZGMqZ4S3JRVv256daweEbKAeR5NCccPmir0H86jwUW6WFAtxqfPWF4piVi +UD6DrUt0gWwzMGy3kbAp0hLBtsQRp/41mKuAXkvMVQ2ysInn6lmHhZvjduK8lvKh +fMRDMjxidQKBgFiciK5blI86wgTutwg7PRrI40HH/CJZJoZIwvzHBeOvbCutTe+N +ZoeCKkyU8af7PDzKfhWCfHBv+4qdIi5QB3NRfyzO4B7IPhVpFqN10RrnDJn9LaLV +cMj2vJMlU1OEErh7KQuk8QmnLPyDguHfwN7Rv1rbiYp2Z+2X+Zx8Y1QPAoGBAJIf +nq/CJXoJMou/xLP2Rt4tEy1pQ9vr0FL341vmxrsXtaGHJeSmagh861XAO4fdO+83 +llbDFl5ORft3Ad9eiETMOhVxRgwO1uuoTgkazBpERTd7GWgO4jXFJYiI8VpAx8b/ +SWkvZcOd6pdPsX6Qn4IAdjqsPz5WKwPQaJ/8zRMxAoGAGaOuyXaFZNl8IeTGYMDL +OEg9BHa+Du8jSv0vL/fCN2s/2TcvSa9uEnv8KHz59JHevvxoDNbQYlN8Ge8adFv4 +xZYQ3h/qh2ohnTUfrG4hcFUVBuv5HBdwgWhVFm5v98KQsqVzGfKorN2DemEv3/au +PFGkuu4lCPeDqu5u0dBojoA= +-----END PRIVATE KEY-----""" +val encryptedLoremIpsum = "KeuPVezTbMW4MvOGJFTAt34PRaL9iepGb1g4QEi5EQYjKXeXo7RytFOCVx6pW9O/uoMWhl+cX32kNqJVWyK7a22kuhnNT2+aiXqEpuh+madx+LK1zUvGDR1A1Mrf3fFOugcnadCQKICiqvl9cFdqsBkJQOFEs9qj5wiu1F57kekuHLWI7ZnHOojkRNq7l1aCHL0DxcLCfZW5CtWAi8g/zUE5WnGd+vUZ+hqc1vnehDul8JE8YUQbAiIxetzba9XoWouTHYZRZcNCztDbrRBYnq2UCcI5adEwQ3VNcES0lIjRuwn1BBWpvk7VOjqh+4c2tSebDX5AkqrO8XwQYwo8OwvZF+hUXFRK6QLHd4B1JQIdygCaEODG0X353upiEKJXDBqv/ZMXR9KqYZBZEfu48ZM/J6heNjVSOP4TSDrXywJgIOieu8mrQ4d7Or7Twnsu/B+bqS37PvVlfU4wHLl7ehXFj4Kusat6cIrb0R4F/Y3fL4+FcfEsk4ioEAndYBFrc1S11vo/TkcuFnXtqrr181gC5JD5LtsUH6sst36vE/JdL/UwTGqhu+rDUcgvr7FiunkasWBnzCtFs58JJrRycUKPzyKINS16GkY8yYtp7xJXBGPYOFM+J7npcKW7P41j1KceDaUArjph2yIELEXCr8qUZzWXZdrw96Te8gLi99c=" + + +class DecryptionTest { + val inputText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." + + @Test + fun testThatDecryptionIsWorkingCorrectly() { + DecryptionContext(privateKey).apply { + val decrypted = encryptedLoremIpsum.decodeBase64().decrypt().decodeToString() + assertEquals(inputText, decrypted) + } + } +} diff --git a/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt b/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt new file mode 100644 index 0000000000..7ab9c556a1 --- /dev/null +++ b/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt @@ -0,0 +1,50 @@ +package dev.inmo.tgbotapi.utils.passport + +import dev.inmo.micro_utils.common.toArrayBuffer +import dev.inmo.micro_utils.common.toByteArray +import dev.inmo.micro_utils.crypto.encodeBase64 +import dev.inmo.micro_utils.crypto.encodeBase64String +import org.khronos.webgl.ArrayBuffer +import kotlin.js.Json +import kotlin.js.json + +private external interface InternalBuffer { + val buffer: ArrayBuffer +} + +private external object Buffer { + fun from(data: String): InternalBuffer +} + +private external interface CryptoConstants { + val RSA_PKCS1_OAEP_PADDING: Any +} +private external interface Crypto { + val constants: CryptoConstants + fun privateDecrypt( + key: Json, + data: InternalBuffer + ): InternalBuffer + fun privateEncrypt( + key: Json, + data: InternalBuffer + ) : InternalBuffer + +} + +@JsModule("crypto") +@JsNonModule +private external val crypto: Crypto + +actual class DecryptionContext actual constructor(key: String) { + private val key = json( + "key" to key, + "padding" to crypto.constants.RSA_PKCS1_OAEP_PADDING + ) + actual fun ByteArray.decrypt(): ByteArray { + return crypto.privateDecrypt( + key, + Buffer.from(encodeBase64String()) + ).buffer.toByteArray() + } +} diff --git a/tgbotapi.core/src/jsTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt b/tgbotapi.core/src/jsTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt new file mode 100644 index 0000000000..e82a07397c --- /dev/null +++ b/tgbotapi.core/src/jsTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt @@ -0,0 +1,32 @@ +package dev.inmo.tgbotapi.passport + +import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData + +//actual val privateKey = """-----BEGIN RSA PRIVATE KEY----- +//MIIEowIBAAKCAQEAt0hdC7xyjrRAXxqrd5i06haPfKLdAvRWsPy2yWtYTFom5dBj +//atMUnFKekTwsmhKbRPBoqF7Da0RF+/Y9q9zmZv05+tNz2FEYGJ6o7r/gdAEX+pKs +//Hd84avm9RahGOwbZgcE8r8Md/tg/ZJCSMsVElzM/Gw02+U1uJQE4n/E2AATbRl0M +//oWdyXjh6Zk6HMiTCvhtQOHoMa9yI00wmHVAlZonovZSRQ2mqfwPlbkDhjsDUQMZp +//WcSPQblAd8FLcWsR1Mh86rQl1GxZVWYONaNwoeATe4p6Ng438HCL7jO7nc4jXJwp +//xqwGI9eUYlHolApBeMQK7oEYDTQ+e0iTvFryPQIDAQABAoIBAAnV81BW65rm53Fz +//H/KKGmNZlJeuscefzysuVKzYeuOWDvJUTZGFBF0jPekzXn1iNDzt3d/zPe96uXq9 +//CzA26ZJrUno4cMYSDAX+NbiiSWxQRrYmut/bg86R2mtrjWFLi86fzR7tjKWJe1Vt +//QLtCxNyMXn2YJvQYCKopt501t50mjkgR3xM375cfVmpomcZXh1K+z4ZxFVzivjvK +//ZAga3BPQ/hd6dhnwUdB/yFZFao1dDmsvJVjsnjpnWD3uqtciTeg2iqtXVLpaLfbJ +//gWOt5P94uIP5r1+qvyrrPXzUGONm4l+43zgvleEgAXWGxnutsYaFfazVQ6qOVyE7 +//fGMQfcECgYEA5Zt1fwTVoYIohq4Do/y5TnNcoj4AajXZU1OutFcPM3aNex16UPBW +//hP7Gakq3TwTKxEILDqOwo86IJuG+lX18kUwaj1f/3T0kDFvE6iLimiPYRNByog4c +//Z5Kwqn+vrnl4ciRDoz7jJsURms2PE7mYV7bndA24Gb0FZJRWiB1xI+0CgYEAzFm7 +//uTSyzacTsqorkyUFIwoGgMIE5NDBQNCVhflJcrmuHRYNwxkH9HRCXqyeHKLiNPRa +//zAoBo3WynjActoy0tFJ90qZI1203iT9BMRbPDiZEXnMH4MrWmk7e7poAUsPVKaRr +//hxvHjr2gTOLY0ClolMvnyNxZcZ/jBxAG0WwK3ZECgYEAwSkdmbQZfPwg19zBF05f +//Ho6SmbMLak7O+/jkerbbBPJxZ+eOpVTrlIs5pOYifImNg7oDz1cKHWR8yikTynN9 +//PkcF+R2RFTCAiR0S9d5PQFlzccDjD05Lux5/HZC53VA3cd7sQAOB2XXkr5TLD08N +//yI0I/mskPBL23Hymp3ANZKkCgYAO2fqttCnGjnz9ACcYk5ky+biNRQyMAKv65O3p +//BbwTzXDdBkxLwJb2ajikntEC7ceY56VtrNB/q78mhgKgNcuwS0p/s7wZhAOEQwee +//5LR5p8hSQPPyn2tHXbIQDzs0yKzGUP/LmvY+5oMu81Gkl03VephG3dTWUDN0wPJt +//5/dGMQKBgE++3BNLLV8siedqwjhSrRB/KmpbLPtoOUlRJYBfG+oITgl/d/W2NKOg +//C5GztdiZUKlHsvvcYoAAWrgEE3bKg+D7GI15yzAjQQZH6AOgL+CEnunIHBaxEEgG +//RS39yB/kPcn9ZtvcJd9v8myQnQjhco8Z2RUwb6IUIoOBvZlSGhGe +//-----END RSA PRIVATE KEY-----""" +//actual val encryptedLoremIpsum: EncryptedAndBase64EncodedData = "KeuPVezTbMW4MvOGJFTAt34PRaL9iepGb1g4QEi5EQYjKXeXo7RytFOCVx6pW9O/uoMWhl+cX32kNqJVWyK7a22kuhnNT2+aiXqEpuh+madx+LK1zUvGDR1A1Mrf3fFOugcnadCQKICiqvl9cFdqsBkJQOFEs9qj5wiu1F57kekuHLWI7ZnHOojkRNq7l1aCHL0DxcLCfZW5CtWAi8g/zUE5WnGd+vUZ+hqc1vnehDul8JE8YUQbAiIxetzba9XoWouTHYZRZcNCztDbrRBYnq2UCcI5adEwQ3VNcES0lIjRuwn1BBWpvk7VOjqh+4c2tSebDX5AkqrO8XwQYwo8OwvZF+hUXFRK6QLHd4B1JQIdygCaEODG0X353upiEKJXDBqv/ZMXR9KqYZBZEfu48ZM/J6heNjVSOP4TSDrXywJgIOieu8mrQ4d7Or7Twnsu/B+bqS37PvVlfU4wHLl7ehXFj4Kusat6cIrb0R4F/Y3fL4+FcfEsk4ioEAndYBFrc1S11vo/TkcuFnXtqrr181gC5JD5LtsUH6sst36vE/JdL/UwTGqhu+rDUcgvr7FiunkasWBnzCtFs58JJrRycUKPzyKINS16GkY8yYtp7xJXBGPYOFM+J7npcKW7P41j1KceDaUArjph2yIELEXCr8qUZzWXZdrw96Te8gLi99c=" diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt new file mode 100644 index 0000000000..8a88aeb73c --- /dev/null +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt @@ -0,0 +1,40 @@ +package dev.inmo.tgbotapi.utils.passport + +import dev.inmo.micro_utils.crypto.decodeBase64 +import sun.security.rsa.RSAPublicKeyImpl +import java.security.KeyFactory +import java.security.interfaces.RSAPrivateKey +import java.security.spec.PKCS8EncodedKeySpec +import javax.crypto.Cipher + +private val regexToRemoveFromKey = Regex("(-----(BEGIN|END) ((?:.*? KEY)|CERTIFICATE)-----|[\\s])") + +private fun String.adaptKey() { + val replaced = replace(regexToRemoveFromKey, "") + +} + +/** + * @param key PKCS8 + */ +actual class DecryptionContext actual constructor(key: String) { + private val privateKey: RSAPrivateKey = KeyFactory.getInstance("RSA").generatePrivate( + PKCS8EncodedKeySpec(key.replace(regexToRemoveFromKey, "").decodeBase64()) + ) as RSAPrivateKey + private val chunkSize: Int = privateKey.modulus.bitLength() / 8 + + actual fun ByteArray.decrypt(): ByteArray { + return Cipher.getInstance("RSA/ECB/PKCS1Padding").run { + init(Cipher.DECRYPT_MODE, privateKey) + (0 until size step chunkSize).flatMap { + val firstIndex = it + val lastIndexExclusive = if (it + chunkSize > size) { + size + } else { + it + chunkSize + } + doFinal(copyOfRange(firstIndex, lastIndexExclusive)).toList() + }.toByteArray() + } + } +} \ No newline at end of file diff --git a/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt b/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt new file mode 100644 index 0000000000..542015c3f1 --- /dev/null +++ b/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt @@ -0,0 +1,31 @@ +package dev.inmo.tgbotapi.passport + +//actual val privateKey: String = """-----BEGIN PRIVATE KEY----- +//MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCaaMFkmMBi6Vl5 +//vzy7wQjoZNLN+e9e6Lb/WBekJxfbNMt+EN9Zv7xT9xzfY68DX7v0uGoLcAqS5Mh5 +//8ELiJbzg4O8dbxkggt0G+kxcbT+a3ofm1Aqhr+LkpsFh5qbLqbAHSQJAF0HPqrAc +//5c6MoQVTZlWGU/j3enCcUFo7Jpsi8La6MqYboF5xGwGEZ9tOA6rMDSekr5Rdm637 +//D/w4h284UX7VnqPdpZ/943VK2qvmPjm8HkFSxkSAB8RHlFyjazzm9FNOcVRGLynv +///cq7mWgyxt5nqiCG7w+lFNAFNQNvAO0rfeiTJbEzubquu4Mg31QrvLIuz+fUbsGk +//ipfpN1czAgMBAAECggEAPlAoO8CpY0FoqolSqTKttZt6t0U2JMclksaqQ8TDC+Oy +//e52zhTSre/ct37kK2AG6iHgj05nTqpRJk2wykbFJGDeuR+Kd8VDeggJg7qvoD0fe +//8HiCEd45Yq0pPaknhulj8Iy2K8c29+eaSw8y2+3fiFi0CxG4V6dB6tNClrxtvxtl +//IE85Utzmk4PLTCs010zxNVm+FwrvqlpjjhspljzleUuWE1KuldO9tNSlwUUfBr4i +//BJJn4jDkQMloXoM/ArZEp7mn57N9+ZuEgVjRMCpRGEAbQI+aLCznBB1kCOY7WL8S +//CwkP++SvcptaUpOjoXZZyuGU4CgBnu0+40ORbNchgQKBgQDLIbB9+WHDcZAn1g6M +//8jaNDRU4HGu5vJSajFQK8Uaczg87hAxmk6R1GF0LOyoadaVmD5ax93mQxWSE/4hT +//wyAPaQOFl7A/i1k/Dx/kURjRwF1sLWDFdMo/8t5bXumzrzb1bHYnHPS7S0lBAU+X +//SrbIw+hv69aKawcQqdd54S1OBwKBgQDCmMarwMVn4xnOh+DOuLS4IQzPT84WgzH+ +//wKw55hZGMqZ4S3JRVv256daweEbKAeR5NCccPmir0H86jwUW6WFAtxqfPWF4piVi +//UD6DrUt0gWwzMGy3kbAp0hLBtsQRp/41mKuAXkvMVQ2ysInn6lmHhZvjduK8lvKh +//fMRDMjxidQKBgFiciK5blI86wgTutwg7PRrI40HH/CJZJoZIwvzHBeOvbCutTe+N +//ZoeCKkyU8af7PDzKfhWCfHBv+4qdIi5QB3NRfyzO4B7IPhVpFqN10RrnDJn9LaLV +//cMj2vJMlU1OEErh7KQuk8QmnLPyDguHfwN7Rv1rbiYp2Z+2X+Zx8Y1QPAoGBAJIf +//nq/CJXoJMou/xLP2Rt4tEy1pQ9vr0FL341vmxrsXtaGHJeSmagh861XAO4fdO+83 +//llbDFl5ORft3Ad9eiETMOhVxRgwO1uuoTgkazBpERTd7GWgO4jXFJYiI8VpAx8b/ +//SWkvZcOd6pdPsX6Qn4IAdjqsPz5WKwPQaJ/8zRMxAoGAGaOuyXaFZNl8IeTGYMDL +//OEg9BHa+Du8jSv0vL/fCN2s/2TcvSa9uEnv8KHz59JHevvxoDNbQYlN8Ge8adFv4 +//xZYQ3h/qh2ohnTUfrG4hcFUVBuv5HBdwgWhVFm5v98KQsqVzGfKorN2DemEv3/au +//PFGkuu4lCPeDqu5u0dBojoA= +//-----END PRIVATE KEY-----""" +//actual val encryptedLoremIpsum = "KeuPVezTbMW4MvOGJFTAt34PRaL9iepGb1g4QEi5EQYjKXeXo7RytFOCVx6pW9O/uoMWhl+cX32kNqJVWyK7a22kuhnNT2+aiXqEpuh+madx+LK1zUvGDR1A1Mrf3fFOugcnadCQKICiqvl9cFdqsBkJQOFEs9qj5wiu1F57kekuHLWI7ZnHOojkRNq7l1aCHL0DxcLCfZW5CtWAi8g/zUE5WnGd+vUZ+hqc1vnehDul8JE8YUQbAiIxetzba9XoWouTHYZRZcNCztDbrRBYnq2UCcI5adEwQ3VNcES0lIjRuwn1BBWpvk7VOjqh+4c2tSebDX5AkqrO8XwQYwo8OwvZF+hUXFRK6QLHd4B1JQIdygCaEODG0X353upiEKJXDBqv/ZMXR9KqYZBZEfu48ZM/J6heNjVSOP4TSDrXywJgIOieu8mrQ4d7Or7Twnsu/B+bqS37PvVlfU4wHLl7ehXFj4Kusat6cIrb0R4F/Y3fL4+FcfEsk4ioEAndYBFrc1S11vo/TkcuFnXtqrr181gC5JD5LtsUH6sst36vE/JdL/UwTGqhu+rDUcgvr7FiunkasWBnzCtFs58JJrRycUKPzyKINS16GkY8yYtp7xJXBGPYOFM+J7npcKW7P41j1KceDaUArjph2yIELEXCr8qUZzWXZdrw96Te8gLi99c=" From 4d63e3a17db821f21fcc1f660a64976fba96f570 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 23 Jan 2021 20:50:40 +0600 Subject: [PATCH 29/43] complete tools for handling of encrypted data --- gradle.properties | 2 - tgbotapi.core/build.gradle | 5 -- .../utils/passport/DecryptionContext.kt | 15 ++++-- .../passport/DecryptionContextRealization.kt | 50 ------------------- .../passport/DecryptionContextRealization.kt | 17 +++---- .../inmo/tgbotapi/passport/DecryptionTest.kt | 6 +-- .../tgbotapi/passport/DecryptionTestKeys.kt | 31 ------------ 7 files changed, 22 insertions(+), 104 deletions(-) delete mode 100644 tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt rename tgbotapi.core/src/{commonTest => jvmTest}/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt (95%) delete mode 100644 tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt diff --git a/gradle.properties b/gradle.properties index 6f5f4fb15b..5017be276e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,8 +16,6 @@ micro_utils_version=0.4.21 javax_activation_version=1.1.1 -crypto_version=1.0.1 - library_group=dev.inmo library_version=0.32.0 diff --git a/tgbotapi.core/build.gradle b/tgbotapi.core/build.gradle index 937d88062d..1894298a2a 100644 --- a/tgbotapi.core/build.gradle +++ b/tgbotapi.core/build.gradle @@ -71,11 +71,6 @@ kotlin { api "javax.activation:activation:$javax_activation_version" } } - jsMain { - dependencies { - api npm("crypto", "${crypto_version}") - } - } jvmTest { dependencies { implementation kotlin('test-junit') diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt index 5ce250d389..425970e31e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt @@ -4,14 +4,15 @@ import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.get.GetFile import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData +import dev.inmo.tgbotapi.utils.nonstrictJsonFormat +import kotlinx.serialization.json.JsonObject -expect class DecryptionContext( - key: String -) { +interface Decryptor { fun ByteArray.decrypt(): ByteArray } -suspend fun DecryptionContext.decrypt( +suspend fun Decryptor.decrypt( file: PassportFile, bot: TelegramBot ): ByteArray { @@ -23,3 +24,9 @@ suspend fun DecryptionContext.decrypt( ) ).decrypt() } +fun Decryptor.decryptData( + data: WithData +) = nonstrictJsonFormat.decodeFromString( + JsonObject.serializer(), + data.data.encodeToByteArray().decrypt().decodeToString() +) diff --git a/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt b/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt deleted file mode 100644 index 7ab9c556a1..0000000000 --- a/tgbotapi.core/src/jsMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt +++ /dev/null @@ -1,50 +0,0 @@ -package dev.inmo.tgbotapi.utils.passport - -import dev.inmo.micro_utils.common.toArrayBuffer -import dev.inmo.micro_utils.common.toByteArray -import dev.inmo.micro_utils.crypto.encodeBase64 -import dev.inmo.micro_utils.crypto.encodeBase64String -import org.khronos.webgl.ArrayBuffer -import kotlin.js.Json -import kotlin.js.json - -private external interface InternalBuffer { - val buffer: ArrayBuffer -} - -private external object Buffer { - fun from(data: String): InternalBuffer -} - -private external interface CryptoConstants { - val RSA_PKCS1_OAEP_PADDING: Any -} -private external interface Crypto { - val constants: CryptoConstants - fun privateDecrypt( - key: Json, - data: InternalBuffer - ): InternalBuffer - fun privateEncrypt( - key: Json, - data: InternalBuffer - ) : InternalBuffer - -} - -@JsModule("crypto") -@JsNonModule -private external val crypto: Crypto - -actual class DecryptionContext actual constructor(key: String) { - private val key = json( - "key" to key, - "padding" to crypto.constants.RSA_PKCS1_OAEP_PADDING - ) - actual fun ByteArray.decrypt(): ByteArray { - return crypto.privateDecrypt( - key, - Buffer.from(encodeBase64String()) - ).buffer.toByteArray() - } -} diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt index 8a88aeb73c..402a295a99 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt @@ -1,7 +1,6 @@ package dev.inmo.tgbotapi.utils.passport import dev.inmo.micro_utils.crypto.decodeBase64 -import sun.security.rsa.RSAPublicKeyImpl import java.security.KeyFactory import java.security.interfaces.RSAPrivateKey import java.security.spec.PKCS8EncodedKeySpec @@ -9,21 +8,16 @@ import javax.crypto.Cipher private val regexToRemoveFromKey = Regex("(-----(BEGIN|END) ((?:.*? KEY)|CERTIFICATE)-----|[\\s])") -private fun String.adaptKey() { - val replaced = replace(regexToRemoveFromKey, "") - -} - /** * @param key PKCS8 */ -actual class DecryptionContext actual constructor(key: String) { +class PKCS8Decryptor (key: String): Decryptor { private val privateKey: RSAPrivateKey = KeyFactory.getInstance("RSA").generatePrivate( PKCS8EncodedKeySpec(key.replace(regexToRemoveFromKey, "").decodeBase64()) ) as RSAPrivateKey private val chunkSize: Int = privateKey.modulus.bitLength() / 8 - actual fun ByteArray.decrypt(): ByteArray { + override fun ByteArray.decrypt(): ByteArray { return Cipher.getInstance("RSA/ECB/PKCS1Padding").run { init(Cipher.DECRYPT_MODE, privateKey) (0 until size step chunkSize).flatMap { @@ -37,4 +31,9 @@ actual class DecryptionContext actual constructor(key: String) { }.toByteArray() } } -} \ No newline at end of file +} + +fun Decryptor(key: String) = PKCS8Decryptor(key) + +inline fun doWithDecryptor(decryptor: Decryptor, crossinline block: Decryptor.() -> T) = decryptor.run(block) +inline fun doWithDecryptor(key: String, crossinline block: Decryptor.() -> T) = doWithDecryptor(Decryptor(key), block) diff --git a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt b/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt similarity index 95% rename from tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt rename to tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt index 090ed96e02..7f9562bffb 100644 --- a/tgbotapi.core/src/commonTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt +++ b/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt @@ -1,8 +1,8 @@ package dev.inmo.tgbotapi.passport import dev.inmo.micro_utils.crypto.decodeBase64 -import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData -import dev.inmo.tgbotapi.utils.passport.DecryptionContext +import dev.inmo.tgbotapi.utils.passport.Decryptor +import dev.inmo.tgbotapi.utils.passport.doWithDecryptor import kotlin.test.Test import kotlin.test.assertEquals @@ -44,7 +44,7 @@ class DecryptionTest { @Test fun testThatDecryptionIsWorkingCorrectly() { - DecryptionContext(privateKey).apply { + doWithDecryptor(privateKey) { val decrypted = encryptedLoremIpsum.decodeBase64().decrypt().decodeToString() assertEquals(inputText, decrypted) } diff --git a/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt b/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt deleted file mode 100644 index 542015c3f1..0000000000 --- a/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt +++ /dev/null @@ -1,31 +0,0 @@ -package dev.inmo.tgbotapi.passport - -//actual val privateKey: String = """-----BEGIN PRIVATE KEY----- -//MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCaaMFkmMBi6Vl5 -//vzy7wQjoZNLN+e9e6Lb/WBekJxfbNMt+EN9Zv7xT9xzfY68DX7v0uGoLcAqS5Mh5 -//8ELiJbzg4O8dbxkggt0G+kxcbT+a3ofm1Aqhr+LkpsFh5qbLqbAHSQJAF0HPqrAc -//5c6MoQVTZlWGU/j3enCcUFo7Jpsi8La6MqYboF5xGwGEZ9tOA6rMDSekr5Rdm637 -//D/w4h284UX7VnqPdpZ/943VK2qvmPjm8HkFSxkSAB8RHlFyjazzm9FNOcVRGLynv -///cq7mWgyxt5nqiCG7w+lFNAFNQNvAO0rfeiTJbEzubquu4Mg31QrvLIuz+fUbsGk -//ipfpN1czAgMBAAECggEAPlAoO8CpY0FoqolSqTKttZt6t0U2JMclksaqQ8TDC+Oy -//e52zhTSre/ct37kK2AG6iHgj05nTqpRJk2wykbFJGDeuR+Kd8VDeggJg7qvoD0fe -//8HiCEd45Yq0pPaknhulj8Iy2K8c29+eaSw8y2+3fiFi0CxG4V6dB6tNClrxtvxtl -//IE85Utzmk4PLTCs010zxNVm+FwrvqlpjjhspljzleUuWE1KuldO9tNSlwUUfBr4i -//BJJn4jDkQMloXoM/ArZEp7mn57N9+ZuEgVjRMCpRGEAbQI+aLCznBB1kCOY7WL8S -//CwkP++SvcptaUpOjoXZZyuGU4CgBnu0+40ORbNchgQKBgQDLIbB9+WHDcZAn1g6M -//8jaNDRU4HGu5vJSajFQK8Uaczg87hAxmk6R1GF0LOyoadaVmD5ax93mQxWSE/4hT -//wyAPaQOFl7A/i1k/Dx/kURjRwF1sLWDFdMo/8t5bXumzrzb1bHYnHPS7S0lBAU+X -//SrbIw+hv69aKawcQqdd54S1OBwKBgQDCmMarwMVn4xnOh+DOuLS4IQzPT84WgzH+ -//wKw55hZGMqZ4S3JRVv256daweEbKAeR5NCccPmir0H86jwUW6WFAtxqfPWF4piVi -//UD6DrUt0gWwzMGy3kbAp0hLBtsQRp/41mKuAXkvMVQ2ysInn6lmHhZvjduK8lvKh -//fMRDMjxidQKBgFiciK5blI86wgTutwg7PRrI40HH/CJZJoZIwvzHBeOvbCutTe+N -//ZoeCKkyU8af7PDzKfhWCfHBv+4qdIi5QB3NRfyzO4B7IPhVpFqN10RrnDJn9LaLV -//cMj2vJMlU1OEErh7KQuk8QmnLPyDguHfwN7Rv1rbiYp2Z+2X+Zx8Y1QPAoGBAJIf -//nq/CJXoJMou/xLP2Rt4tEy1pQ9vr0FL341vmxrsXtaGHJeSmagh861XAO4fdO+83 -//llbDFl5ORft3Ad9eiETMOhVxRgwO1uuoTgkazBpERTd7GWgO4jXFJYiI8VpAx8b/ -//SWkvZcOd6pdPsX6Qn4IAdjqsPz5WKwPQaJ/8zRMxAoGAGaOuyXaFZNl8IeTGYMDL -//OEg9BHa+Du8jSv0vL/fCN2s/2TcvSa9uEnv8KHz59JHevvxoDNbQYlN8Ge8adFv4 -//xZYQ3h/qh2ohnTUfrG4hcFUVBuv5HBdwgWhVFm5v98KQsqVzGfKorN2DemEv3/au -//PFGkuu4lCPeDqu5u0dBojoA= -//-----END PRIVATE KEY-----""" -//actual val encryptedLoremIpsum = "KeuPVezTbMW4MvOGJFTAt34PRaL9iepGb1g4QEi5EQYjKXeXo7RytFOCVx6pW9O/uoMWhl+cX32kNqJVWyK7a22kuhnNT2+aiXqEpuh+madx+LK1zUvGDR1A1Mrf3fFOugcnadCQKICiqvl9cFdqsBkJQOFEs9qj5wiu1F57kekuHLWI7ZnHOojkRNq7l1aCHL0DxcLCfZW5CtWAi8g/zUE5WnGd+vUZ+hqc1vnehDul8JE8YUQbAiIxetzba9XoWouTHYZRZcNCztDbrRBYnq2UCcI5adEwQ3VNcES0lIjRuwn1BBWpvk7VOjqh+4c2tSebDX5AkqrO8XwQYwo8OwvZF+hUXFRK6QLHd4B1JQIdygCaEODG0X353upiEKJXDBqv/ZMXR9KqYZBZEfu48ZM/J6heNjVSOP4TSDrXywJgIOieu8mrQ4d7Or7Twnsu/B+bqS37PvVlfU4wHLl7ehXFj4Kusat6cIrb0R4F/Y3fL4+FcfEsk4ioEAndYBFrc1S11vo/TkcuFnXtqrr181gC5JD5LtsUH6sst36vE/JdL/UwTGqhu+rDUcgvr7FiunkasWBnzCtFs58JJrRycUKPzyKINS16GkY8yYtp7xJXBGPYOFM+J7npcKW7P41j1KceDaUArjph2yIELEXCr8qUZzWXZdrw96Te8gLi99c=" From c425e2ecc3e124d5a9d343483e74e6243880cfe5 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sat, 23 Jan 2021 21:10:57 +0600 Subject: [PATCH 30/43] update classcasts --- .../tgbotapi/extensions/utils/ClassCasts.kt | 179 ++++++++++++++++++ 1 file changed, 179 insertions(+) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 25c0e86e29..95b212fe0d 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -37,6 +37,9 @@ import dev.inmo.tgbotapi.types.message.content.* import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent +import dev.inmo.tgbotapi.types.passport.* +import dev.inmo.tgbotapi.types.passport.encrypted_data.* +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* import dev.inmo.tgbotapi.types.polls.* import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* @@ -156,6 +159,182 @@ inline fun CallbackQuery.asUnknownCallbackQueryType(): UnknownCallbackQueryType? @PreviewFeature inline fun CallbackQuery.requireUnknownCallbackQueryType(): UnknownCallbackQueryType = this as UnknownCallbackQueryType @PreviewFeature +inline fun PassportElementError.asPassportElementErrorDataField(): PassportElementErrorDataField? = this as? PassportElementErrorDataField +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorDataField(): PassportElementErrorDataField = this as PassportElementErrorDataField +@PreviewFeature +inline fun PassportElementError.asPassportElementErrorFile(): PassportElementErrorFile? = this as? PassportElementErrorFile +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorFile(): PassportElementErrorFile = this as PassportElementErrorFile +@PreviewFeature +inline fun PassportElementError.asPassportElementErrorFiles(): PassportElementErrorFiles? = this as? PassportElementErrorFiles +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorFiles(): PassportElementErrorFiles = this as PassportElementErrorFiles +@PreviewFeature +inline fun PassportElementError.asPassportElementErrorFrontSide(): PassportElementErrorFrontSide? = this as? PassportElementErrorFrontSide +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorFrontSide(): PassportElementErrorFrontSide = this as PassportElementErrorFrontSide +@PreviewFeature +inline fun PassportElementError.asPassportElementErrorReverseSide(): PassportElementErrorReverseSide? = this as? PassportElementErrorReverseSide +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorReverseSide(): PassportElementErrorReverseSide = this as PassportElementErrorReverseSide +@PreviewFeature +inline fun PassportElementError.asPassportElementErrorSelfie(): PassportElementErrorSelfie? = this as? PassportElementErrorSelfie +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorSelfie(): PassportElementErrorSelfie = this as PassportElementErrorSelfie +@PreviewFeature +inline fun PassportElementError.asPassportElementErrorTranslationFile(): PassportElementErrorTranslationFile? = this as? PassportElementErrorTranslationFile +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorTranslationFile(): PassportElementErrorTranslationFile = this as PassportElementErrorTranslationFile +@PreviewFeature +inline fun PassportElementError.asPassportElementErrorTranslationFiles(): PassportElementErrorTranslationFiles? = this as? PassportElementErrorTranslationFiles +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorTranslationFiles(): PassportElementErrorTranslationFiles = this as PassportElementErrorTranslationFiles +@PreviewFeature +inline fun PassportElementError.asPassportElementErrorUnspecified(): PassportElementErrorUnspecified? = this as? PassportElementErrorUnspecified +@PreviewFeature +inline fun PassportElementError.requirePassportElementErrorUnspecified(): PassportElementErrorUnspecified = this as PassportElementErrorUnspecified +@PreviewFeature +inline fun PassportElementError.asPassportElementFileError(): PassportElementFileError? = this as? PassportElementFileError +@PreviewFeature +inline fun PassportElementError.requirePassportElementFileError(): PassportElementFileError = this as PassportElementFileError +@PreviewFeature +inline fun PassportElementError.asPassportElementFilesError(): PassportElementFilesError? = this as? PassportElementFilesError +@PreviewFeature +inline fun PassportElementError.requirePassportElementFilesError(): PassportElementFilesError = this as PassportElementFilesError +@PreviewFeature +inline fun PassportElementError.asPassportMultipleElementsError(): PassportMultipleElementsError? = this as? PassportMultipleElementsError +@PreviewFeature +inline fun PassportElementError.requirePassportMultipleElementsError(): PassportMultipleElementsError = this as PassportMultipleElementsError +@PreviewFeature +inline fun PassportElementError.asPassportSingleElementError(): PassportSingleElementError? = this as? PassportSingleElementError +@PreviewFeature +inline fun PassportElementError.requirePassportSingleElementError(): PassportSingleElementError = this as PassportSingleElementError +@PreviewFeature +inline fun PassportElementError.asUnknownPassportElementError(): UnknownPassportElementError? = this as? UnknownPassportElementError +@PreviewFeature +inline fun PassportElementError.requireUnknownPassportElementError(): UnknownPassportElementError = this as UnknownPassportElementError +@PreviewFeature +inline fun EncryptedPassportElement.asBankStatement(): BankStatement? = this as? BankStatement +@PreviewFeature +inline fun EncryptedPassportElement.requireBankStatement(): BankStatement = this as BankStatement +@PreviewFeature +inline fun EncryptedPassportElement.asCommonPassport(): CommonPassport? = this as? CommonPassport +@PreviewFeature +inline fun EncryptedPassportElement.requireCommonPassport(): CommonPassport = this as CommonPassport +@PreviewFeature +inline fun EncryptedPassportElement.asDriverLicense(): DriverLicense? = this as? DriverLicense +@PreviewFeature +inline fun EncryptedPassportElement.requireDriverLicense(): DriverLicense = this as DriverLicense +@PreviewFeature +inline fun EncryptedPassportElement.asEmail(): Email? = this as? Email +@PreviewFeature +inline fun EncryptedPassportElement.requireEmail(): Email = this as Email +@PreviewFeature +inline fun EncryptedPassportElement.asEncryptedAddress(): EncryptedAddress? = this as? EncryptedAddress +@PreviewFeature +inline fun EncryptedPassportElement.requireEncryptedAddress(): EncryptedAddress = this as EncryptedAddress +@PreviewFeature +inline fun EncryptedPassportElement.asEncryptedPersonalDetails(): EncryptedPersonalDetails? = this as? EncryptedPersonalDetails +@PreviewFeature +inline fun EncryptedPassportElement.requireEncryptedPersonalDetails(): EncryptedPersonalDetails = this as EncryptedPersonalDetails +@PreviewFeature +inline fun EncryptedPassportElement.asIdentityCard(): IdentityCard? = this as? IdentityCard +@PreviewFeature +inline fun EncryptedPassportElement.requireIdentityCard(): IdentityCard = this as IdentityCard +@PreviewFeature +inline fun EncryptedPassportElement.asInternalPassport(): InternalPassport? = this as? InternalPassport +@PreviewFeature +inline fun EncryptedPassportElement.requireInternalPassport(): InternalPassport = this as InternalPassport +@PreviewFeature +inline fun EncryptedPassportElement.asPassport(): Passport? = this as? Passport +@PreviewFeature +inline fun EncryptedPassportElement.requirePassport(): Passport = this as Passport +@PreviewFeature +inline fun EncryptedPassportElement.asPassportRegistration(): PassportRegistration? = this as? PassportRegistration +@PreviewFeature +inline fun EncryptedPassportElement.requirePassportRegistration(): PassportRegistration = this as PassportRegistration +@PreviewFeature +inline fun EncryptedPassportElement.asPhoneNumber(): PhoneNumber? = this as? PhoneNumber +@PreviewFeature +inline fun EncryptedPassportElement.requirePhoneNumber(): PhoneNumber = this as PhoneNumber +@PreviewFeature +inline fun EncryptedPassportElement.asRentalAgreement(): RentalAgreement? = this as? RentalAgreement +@PreviewFeature +inline fun EncryptedPassportElement.requireRentalAgreement(): RentalAgreement = this as RentalAgreement +@PreviewFeature +inline fun EncryptedPassportElement.asTemporaryRegistration(): TemporaryRegistration? = this as? TemporaryRegistration +@PreviewFeature +inline fun EncryptedPassportElement.requireTemporaryRegistration(): TemporaryRegistration = this as TemporaryRegistration +@PreviewFeature +inline fun EncryptedPassportElement.asTranslatableFilesCollection(): TranslatableFilesCollection? = this as? TranslatableFilesCollection +@PreviewFeature +inline fun EncryptedPassportElement.requireTranslatableFilesCollection(): TranslatableFilesCollection = this as TranslatableFilesCollection +@PreviewFeature +inline fun EncryptedPassportElement.asTranslatableIDDocument(): TranslatableIDDocument? = this as? TranslatableIDDocument +@PreviewFeature +inline fun EncryptedPassportElement.requireTranslatableIDDocument(): TranslatableIDDocument = this as TranslatableIDDocument +@PreviewFeature +inline fun EncryptedPassportElement.asUtilityBill(): UtilityBill? = this as? UtilityBill +@PreviewFeature +inline fun EncryptedPassportElement.requireUtilityBill(): UtilityBill = this as UtilityBill +@PreviewFeature +inline fun EncryptedPassportElement.asFilesCollection(): FilesCollection? = this as? FilesCollection +@PreviewFeature +inline fun EncryptedPassportElement.requireFilesCollection(): FilesCollection = this as FilesCollection +@PreviewFeature +inline fun EncryptedPassportElement.asTranslatable(): Translatable? = this as? Translatable +@PreviewFeature +inline fun EncryptedPassportElement.requireTranslatable(): Translatable = this as Translatable +@PreviewFeature +inline fun EncryptedPassportElement.asUnknownEncryptedPassportElement(): UnknownEncryptedPassportElement? = this as? UnknownEncryptedPassportElement +@PreviewFeature +inline fun EncryptedPassportElement.requireUnknownEncryptedPassportElement(): UnknownEncryptedPassportElement = this as UnknownEncryptedPassportElement +@PreviewFeature +inline fun EncryptedPassportElement.asWithData(): WithData? = this as? WithData +@PreviewFeature +inline fun EncryptedPassportElement.requireWithData(): WithData = this as WithData +@PreviewFeature +inline fun EncryptedPassportElement.asWithEmail(): WithEmail? = this as? WithEmail +@PreviewFeature +inline fun EncryptedPassportElement.requireWithEmail(): WithEmail = this as WithEmail +@PreviewFeature +inline fun EncryptedPassportElement.asWithFrontSide(): WithFrontSide? = this as? WithFrontSide +@PreviewFeature +inline fun EncryptedPassportElement.requireWithFrontSide(): WithFrontSide = this as WithFrontSide +@PreviewFeature +inline fun EncryptedPassportElement.asWithPhoneNumber(): WithPhoneNumber? = this as? WithPhoneNumber +@PreviewFeature +inline fun EncryptedPassportElement.requireWithPhoneNumber(): WithPhoneNumber = this as WithPhoneNumber +@PreviewFeature +inline fun EncryptedPassportElement.asWithReverseSide(): WithReverseSide? = this as? WithReverseSide +@PreviewFeature +inline fun EncryptedPassportElement.requireWithReverseSide(): WithReverseSide = this as WithReverseSide +@PreviewFeature +inline fun EncryptedPassportElement.asWithSelfie(): WithSelfie? = this as? WithSelfie +@PreviewFeature +inline fun EncryptedPassportElement.requireWithSelfie(): WithSelfie = this as WithSelfie +@PreviewFeature +inline fun Message.asAnonymousGroupMessageImpl(): AnonymousGroupMessageImpl? = this as? AnonymousGroupMessageImpl +@PreviewFeature +inline fun Message.requireAnonymousGroupMessageImpl(): AnonymousGroupMessageImpl = this as AnonymousGroupMessageImpl +@PreviewFeature +inline fun Message.asChannelMessageImpl(): ChannelMessageImpl? = this as? ChannelMessageImpl +@PreviewFeature +inline fun Message.requireChannelMessageImpl(): ChannelMessageImpl = this as ChannelMessageImpl +@PreviewFeature +inline fun Message.asFromChannelGroupMessageImpl(): FromChannelGroupMessageImpl? = this as? FromChannelGroupMessageImpl +@PreviewFeature +inline fun Message.requireFromChannelGroupMessageImpl(): FromChannelGroupMessageImpl = this as FromChannelGroupMessageImpl +@PreviewFeature +inline fun Message.asPassportMessage(): PassportMessage? = this as? PassportMessage +@PreviewFeature +inline fun Message.requirePassportMessage(): PassportMessage = this as PassportMessage +@PreviewFeature +inline fun Message.asPrivateMessageImpl(): PrivateMessageImpl? = this as? PrivateMessageImpl +@PreviewFeature +inline fun Message.requirePrivateMessageImpl(): PrivateMessageImpl = this as PrivateMessageImpl +@PreviewFeature inline fun Message.asChannelEventMessage(): ChannelEventMessage? = this as? ChannelEventMessage @PreviewFeature inline fun Message.requireChannelEventMessage(): ChannelEventMessage = this as ChannelEventMessage From 1359dd549f2410148fd4fac20848a22d884141a3 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 25 Jan 2021 04:42:23 +0600 Subject: [PATCH 31/43] Create regular-build.yml --- .github/workflows/regular-build.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/regular-build.yml diff --git a/.github/workflows/regular-build.yml b/.github/workflows/regular-build.yml new file mode 100644 index 0000000000..ceab9f2734 --- /dev/null +++ b/.github/workflows/regular-build.yml @@ -0,0 +1,16 @@ +name: Build + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Build with Gradle + run: ./gradlew build From 0c711339699c2d25c70899f4d11d2909b9104599 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 25 Jan 2021 10:29:11 +0600 Subject: [PATCH 32/43] add expectations and triggers for passport --- .../expectations/WaitPassportData.kt | 54 +++++++++++++++++++ .../triggers_handling/PassportTriggers.kt | 42 +++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt create mode 100644 tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt new file mode 100644 index 0000000000..1e043d5901 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt @@ -0,0 +1,54 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.expectations + +import dev.inmo.tgbotapi.extensions.behaviour_builder.BehaviourContext +import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.requests.abstracts.Request +import dev.inmo.tgbotapi.types.message.PassportMessage +import dev.inmo.tgbotapi.types.passport.PassportData +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement +import dev.inmo.tgbotapi.utils.RiskFeature +import kotlinx.coroutines.flow.toList + +typealias PassportMessageMapper = suspend PassportMessage.() -> PassportData + +@RiskFeature("Do not use this message directly, use waitPassportMessagesWith or waitAnyPassportMessages instead") +suspend fun BehaviourContext.waitPassportMessages( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + mapper: suspend PassportMessage.() -> O? +): List = expectFlow( + initRequest, + count, + errorFactory +) { + it.asMessageUpdate() ?.data ?.asPassportMessage() ?.mapper().let(::listOfNotNull) +}.toList().toList() + +suspend inline fun BehaviourContext.waitPassportMessagesWith( + count: Int = 1, + initRequest: Request<*>? = null, + noinline errorFactory: NullableRequestBuilder<*> = { null }, + noinline filter: PassportMessageMapper? = null +) : List = waitPassportMessages( + initRequest, + errorFactory, + count +) { + if (passportData.data.any { it is T }) { + if (filter == null) { + passportData + } else { + filter(this) + } + } else { + null + } +} + +suspend fun BehaviourContext.waitAnyPassportMessages( + initRequest: Request<*>? = null, + errorFactory: NullableRequestBuilder<*> = { null }, + count: Int = 1, + filter: PassportMessageMapper? = null +) = waitPassportMessagesWith(count, initRequest, errorFactory, filter) diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt new file mode 100644 index 0000000000..5b2520fc11 --- /dev/null +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt @@ -0,0 +1,42 @@ +package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling + +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import dev.inmo.tgbotapi.extensions.behaviour_builder.* +import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow +import dev.inmo.tgbotapi.extensions.utils.* +import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat +import dev.inmo.tgbotapi.types.message.PassportMessage +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement + +suspend inline fun BehaviourContext.onPassportMessageWith( + includeFilterByChatInBehaviourSubContext: Boolean = true, + noinline additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, + noinline scenarioReceiver: BehaviourContextAndTypeReceiver +) = flowsUpdatesFilter.expectFlow(bot) { + it.asMessageUpdate() ?.data ?.asPassportMessage() ?.let { message -> + if (message.passportData.data.any { it is T }) { + if (additionalFilter == null || additionalFilter(message)) message else null + } else { + null + } + }.let(::listOfNotNull) +}.subscribeSafelyWithoutExceptions(scope) { triggerMessage -> + doInSubContextWithUpdatesFilter( + updatesFilter = if (includeFilterByChatInBehaviourSubContext) { + { it.sourceChat() ?.id ?.chatId == triggerMessage.chat.id.chatId } + } else null + ) { + scenarioReceiver(triggerMessage) + } +} + +suspend fun BehaviourContext.onPassportMessage( + includeFilterByChatInBehaviourSubContext: Boolean = true, + additionalFilter: (suspend (PassportMessage) -> Boolean)? = null, + scenarioReceiver: BehaviourContextAndTypeReceiver +) = onPassportMessageWith( + includeFilterByChatInBehaviourSubContext, + additionalFilter, + scenarioReceiver +) + From 1dc3ce2fb5b57deba17db5d4c1706443561c70c7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Mon, 25 Jan 2021 10:43:51 +0600 Subject: [PATCH 33/43] add passport in API --- CHANGELOG.md | 2 + .../utils/passport/DecryptionContext.kt | 3 +- .../api/passport/SetPassportDataErrors.kt | 45 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bbbc0ccb7..d791fd8359 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ * `onVisualMediaGroup` now is just an alternative to `onVisualGallery` * `command` and `onCommand` expectations has been added for commands `String` variant * New extensions `BehaviourContext#oneOf`, `BehaviourContext#parallel` and `Deferred#withAction` +* `API`: + * **PASSPORT** New extensions `TelegramBot#setPassportDataErrors` ## 0.31.0 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt index 425970e31e..83914a9144 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt @@ -3,6 +3,7 @@ package dev.inmo.tgbotapi.utils.passport import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.get.GetFile +import dev.inmo.tgbotapi.types.passport.EncryptedCredentials import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import dev.inmo.tgbotapi.utils.nonstrictJsonFormat @@ -25,7 +26,7 @@ suspend fun Decryptor.decrypt( ).decrypt() } fun Decryptor.decryptData( - data: WithData + data: EncryptedCredentials ) = nonstrictJsonFormat.decodeFromString( JsonObject.serializer(), data.data.encodeToByteArray().decrypt().decodeToString() diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt new file mode 100644 index 0000000000..341f786dd8 --- /dev/null +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt @@ -0,0 +1,45 @@ +package dev.inmo.tgbotapi.extensions.api.passport + +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.SetPassportDataErrors +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.message.PassportMessage +import dev.inmo.tgbotapi.types.passport.PassportData +import dev.inmo.tgbotapi.types.passport.PassportElementError +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement +import dev.inmo.tgbotapi.utils.passport.Decryptor + +suspend fun TelegramBot.setPassportDataErrors( + userId: UserId, + errors: List +) = execute(SetPassportDataErrors(userId, errors)) +suspend fun TelegramBot.setPassportDataErrors( + user: User, + errors: List +) = setPassportDataErrors(user.id, errors) + +suspend fun TelegramBot.setPassportDataErrors( + userId: UserId, + passportData: PassportData, + decryptor: Decryptor, + mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError +): Boolean = setPassportDataErrors( + userId, + passportData.data.map { decryptor.mapper(it) }.also { + if (it.isEmpty()) { + return@setPassportDataErrors false + } + } +) +suspend fun TelegramBot.setPassportDataErrors( + user: User, + passportData: PassportData, + decryptor: Decryptor, + mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError +) = setPassportDataErrors(user.id, passportData, decryptor, mapper) + +suspend fun TelegramBot.setPassportDataErrors( + passportMessage: PassportMessage, + decryptor: Decryptor, + mapper: suspend Decryptor.(EncryptedPassportElement) -> PassportElementError +) = setPassportDataErrors(passportMessage.user, passportMessage.passportData, decryptor, mapper) From e0bf67d8f9e2a8b8e4c97b314a66cf47547dd2dd Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Jan 2021 16:03:30 +0600 Subject: [PATCH 34/43] global update of passport --- CHANGELOG.md | 3 +- gradle.properties | 4 +- .../tgbotapi/types/passport/EncryptedData.kt | 16 +++--- .../types/passport/PassportElementError.kt | 54 +++++++++---------- .../types/passport/encrypted_data/Email.kt | 7 +-- .../encrypted_data/EncryptedAddress.kt | 9 ++-- .../EncryptedElementSerializer.kt | 3 +- .../EncryptedPersonalDetails.kt | 9 ++-- .../types/passport/encrypted_data/Passport.kt | 14 ++--- .../passport/encrypted_data/PhoneNumber.kt | 7 +-- .../TranslatableFilesCollection.kt | 25 +++++---- .../encrypted_data/TranslatableIDDocument.kt | 14 ++--- .../abstracts/EncryptedPassportElement.kt | 11 ++-- .../utils/passport/DecryptionContext.kt | 2 +- .../passport/DecryptionContextRealization.kt | 2 +- .../inmo/tgbotapi/passport/DecryptionTest.kt | 2 +- 16 files changed, 95 insertions(+), 87 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d791fd8359..85c5f369f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ * `Common`: * `Version`: - * `MicroUtils`: `0.4.16` -> `0.4.21` + * `MicroUtils`: `0.4.16` -> `0.4.23` + * `Klock`: `0.2.3` -> `0.2.4` * `Core`: * **BREAKING CHANGE** Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` * Methods and types related to `MediaGroupMessage` have been modified according to their meanings diff --git a/gradle.properties b/gradle.properties index 5017be276e..d8cdce6fd8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,11 +8,11 @@ kotlin.incremental.js=true kotlin_version=1.4.21 kotlin_coroutines_version=1.4.2 kotlin_serialisation_runtime_version=1.0.1 -klock_version=2.0.3 +klock_version=2.0.4 uuid_version=0.2.3 ktor_version=1.5.0 -micro_utils_version=0.4.21 +micro_utils_version=0.4.23 javax_activation_version=1.1.1 diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt index ce198b65da..11eca0828e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt @@ -1,23 +1,23 @@ package dev.inmo.tgbotapi.types.passport -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.crypto.SourceBytes +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable -typealias EncryptedAndBase64EncodedData = String -typealias EncryptedByBotPublicKeyData = String -typealias EncryptedData = String +typealias EncryptedByBotPublicKeyData = SourceBytes +typealias EncryptedData = SourceBytes @Serializable data class EncryptedCredentials( @SerialName(dataField) - @Serializable(Base64StringSerializer::class) + @Serializable(Base64BytesToFromStringSerializer::class) val data: EncryptedData, @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - val hash: String, + @Serializable(Base64BytesToFromStringSerializer::class) + val hash: SourceBytes, @SerialName(secretField) - @Serializable(Base64StringSerializer::class) + @Serializable(Base64BytesToFromStringSerializer::class) val secret: EncryptedByBotPublicKeyData ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt index a3cf28594a..35df08b4ab 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt @@ -4,7 +4,7 @@ package dev.inmo.tgbotapi.types.passport import dev.inmo.micro_utils.crypto.MD5 import dev.inmo.micro_utils.crypto.md5 -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* import dev.inmo.tgbotapi.types.passport.encrypted_data.type @@ -70,12 +70,12 @@ object PassportElementErrorSerializer : KSerializer { @Serializable sealed class PassportSingleElementError : PassportElementError() { - abstract val elementHash: String + abstract val elementHash: PassportElementHash } @Serializable sealed class PassportMultipleElementsError : PassportElementError() { - abstract val elementsHashes: List + abstract val elementsHashes: List } @Serializable @@ -91,8 +91,8 @@ data class PassportElementErrorDataField( @SerialName(fieldNameField) val fieldName: String, @SerialName(dataHashField) - @Serializable(Base64StringSerializer::class) - override val elementHash: String, + @Serializable(Base64BytesToFromStringSerializer::class) + override val elementHash: PassportElementHash, @SerialName(messageField) override val message: String ) : PassportSingleElementError() { @@ -112,8 +112,8 @@ data class PassportElementErrorFrontSide( @SerialName(typeField) override val type: String, @SerialName(fileHashField) - @Serializable(Base64StringSerializer::class) - override val elementHash: String, + @Serializable(Base64BytesToFromStringSerializer::class) + override val elementHash: PassportElementHash, @SerialName(messageField) override val message: String ) : PassportElementFileError() { @@ -121,7 +121,7 @@ data class PassportElementErrorFrontSide( @Required override val source: String = frontSideField } -fun WithFrontSide.createFrontSideError(message: String, unencryptedFileHash: String) = PassportElementErrorFrontSide( +fun WithFrontSide.createFrontSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFrontSide( type, unencryptedFileHash, message @@ -132,8 +132,8 @@ data class PassportElementErrorReverseSide( @SerialName(typeField) override val type: String, @SerialName(fileHashField) - @Serializable(Base64StringSerializer::class) - override val elementHash: String, + @Serializable(Base64BytesToFromStringSerializer::class) + override val elementHash: PassportElementHash, @SerialName(messageField) override val message: String ) : PassportElementFileError() { @@ -141,7 +141,7 @@ data class PassportElementErrorReverseSide( @Required override val source: String = reverseSideField } -fun WithReverseSide.createReverseSideError(message: String, unencryptedFileHash: String) = PassportElementErrorReverseSide( +fun WithReverseSide.createReverseSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorReverseSide( type, unencryptedFileHash, message @@ -151,8 +151,8 @@ data class PassportElementErrorSelfie( @SerialName(typeField) override val type: String, @SerialName(fileHashField) - @Serializable(Base64StringSerializer::class) - override val elementHash: String, + @Serializable(Base64BytesToFromStringSerializer::class) + override val elementHash: PassportElementHash, @SerialName(messageField) override val message: String ) : PassportElementFileError() { @@ -160,7 +160,7 @@ data class PassportElementErrorSelfie( @Required override val source: String = selfieField } -fun WithSelfie.createSelfieError(message: String, unencryptedFileHash: String) = PassportElementErrorSelfie( +fun WithSelfie.createSelfieError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorSelfie( type, unencryptedFileHash, message @@ -172,8 +172,8 @@ data class PassportElementErrorFile( @SerialName(typeField) override val type: String, @SerialName(fileHashField) - @Serializable(Base64StringSerializer::class) - override val elementHash: String, + @Serializable(Base64BytesToFromStringSerializer::class) + override val elementHash: PassportElementHash, @SerialName(messageField) override val message: String ) : PassportElementFileError() { @@ -181,7 +181,7 @@ data class PassportElementErrorFile( @Required override val source: String = fileField } -fun FilesCollection.createFileError(message: String, unencryptedFileHash: String) = PassportElementErrorFile( +fun FilesCollection.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFile( type, unencryptedFileHash, message @@ -192,7 +192,7 @@ data class PassportElementErrorFiles( @SerialName(typeField) override val type: String, @SerialName(fileHashesField) - override val elementsHashes: List<@Serializable(Base64StringSerializer::class) String>, + override val elementsHashes: List<@Serializable(Base64BytesToFromStringSerializer::class) PassportElementHash>, @SerialName(messageField) override val message: String ) : PassportElementFilesError() { @@ -200,7 +200,7 @@ data class PassportElementErrorFiles( @Required override val source: String = filesField } -fun FilesCollection.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorFiles( +fun FilesCollection.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorFiles( type, unencryptedFileHashes, message @@ -212,8 +212,8 @@ data class PassportElementErrorTranslationFile( @SerialName(typeField) override val type: String, @SerialName(fileHashField) - @Serializable(Base64StringSerializer::class) - override val elementHash: String, + @Serializable(Base64BytesToFromStringSerializer::class) + override val elementHash: PassportElementHash, @SerialName(messageField) override val message: String ) : PassportElementFileError() { @@ -221,7 +221,7 @@ data class PassportElementErrorTranslationFile( @Required override val source: String = translationFileField } -fun Translatable.createFileError(message: String, unencryptedFileHash: String) = PassportElementErrorTranslationFile( +fun Translatable.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorTranslationFile( type, unencryptedFileHash, message @@ -231,7 +231,7 @@ data class PassportElementErrorTranslationFiles( @SerialName(typeField) override val type: String, @SerialName(fileHashesField) - override val elementsHashes: List<@Serializable(Base64StringSerializer::class) String>, + override val elementsHashes: List<@Serializable(Base64BytesToFromStringSerializer::class) PassportElementHash>, @SerialName(messageField) override val message: String ) : PassportElementFilesError() { @@ -239,7 +239,7 @@ data class PassportElementErrorTranslationFiles( @Required override val source: String = translationFilesField } -fun Translatable.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorTranslationFiles( +fun Translatable.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorTranslationFiles( type, unencryptedFileHashes, message @@ -250,8 +250,8 @@ data class PassportElementErrorUnspecified( @SerialName(typeField) override val type: String, @SerialName(fileHashField) - @Serializable(Base64StringSerializer::class) - override val elementHash: String, + @Serializable(Base64BytesToFromStringSerializer::class) + override val elementHash: PassportElementHash, @SerialName(messageField) override val message: String ) : PassportElementFileError() { @@ -259,7 +259,7 @@ data class PassportElementErrorUnspecified( @Required override val source: String = unspecifiedField } -fun EncryptedPassportElement.createUnspecifiedError(message: String, elementHash: String) = PassportElementErrorUnspecified( +fun EncryptedPassportElement.createUnspecifiedError(message: String, elementHash: PassportElementHash) = PassportElementErrorUnspecified( type, elementHash, message diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt index c5e83c94d8..baadbdb726 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.emailField import dev.inmo.tgbotapi.types.hashField +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithEmail import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -12,7 +13,7 @@ data class Email( @SerialName(emailField) override val email: String, @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : WithEmail { } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt index b63f1865bf..abff88fed8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.dataField import dev.inmo.tgbotapi.types.passport.EncryptedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,8 +11,8 @@ import kotlinx.serialization.Serializable @Serializable data class EncryptedAddress( @SerialName(dataField) - @Serializable(Base64StringSerializer::class) + @Serializable(Base64BytesToFromStringSerializer::class) override val data: EncryptedData, - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : WithData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt index 28caca9889..97e48e4e1b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt @@ -1,5 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data +import dev.inmo.micro_utils.crypto.decodeBase64 import dev.inmo.micro_utils.serialization.encapsulator.Encapsulator import dev.inmo.tgbotapi.types.hashField import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement @@ -45,7 +46,7 @@ object EncryptedElementSerializer : KSerializer { encryptedElementsClassesByTypes[type] ?.serializer ?.let { deserializer -> nonstrictJsonFormat.decodeFromJsonElement(deserializer, json) } - } ?: UnknownEncryptedPassportElement(json, json[hashField] ?.jsonPrimitive ?.content ?: "") + } ?: UnknownEncryptedPassportElement(json, json[hashField] ?.jsonPrimitive ?.content ?.decodeBase64() ?: byteArrayOf()) } override fun serialize(encoder: Encoder, value: EncryptedPassportElement) { diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt index 90149a261e..e3f25ec6df 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt @@ -1,8 +1,9 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.dataField import dev.inmo.tgbotapi.types.passport.EncryptedData +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,8 +11,8 @@ import kotlinx.serialization.Serializable @Serializable data class EncryptedPersonalDetails( @SerialName(dataField) - @Serializable(Base64StringSerializer::class) + @Serializable(Base64BytesToFromStringSerializer::class) override val data: EncryptedData, - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : WithData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt index 882c91c895..9cf858b00e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* @@ -13,7 +13,7 @@ sealed class Passport : WithData, WithFrontSide, WithSelfie, Translatable @Serializable data class CommonPassport( @SerialName(dataField) - @Serializable(Base64StringSerializer::class) + @Serializable(Base64BytesToFromStringSerializer::class) override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile? = null, @@ -22,13 +22,13 @@ data class CommonPassport( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : Passport() @Serializable data class InternalPassport( @SerialName(dataField) - @Serializable(Base64StringSerializer::class) + @Serializable(Base64BytesToFromStringSerializer::class) override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile? = null, @@ -37,6 +37,6 @@ data class InternalPassport( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : Passport() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt index 563339ade1..48c74f2350 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt @@ -1,7 +1,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.hashField +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.PassportElementHash import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithPhoneNumber import dev.inmo.tgbotapi.types.phoneNumberField import kotlinx.serialization.SerialName @@ -12,7 +13,7 @@ data class PhoneNumber( @SerialName(phoneNumberField) override val phoneNumber: String, @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : WithPhoneNumber { } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt index 4339ad958b..1ad210ca6b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt @@ -1,9 +1,8 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.FilesCollection -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.Translatable +import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -17,8 +16,8 @@ data class UtilityBill( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : TranslatableFilesCollection() @Serializable data class BankStatement( @@ -27,8 +26,8 @@ data class BankStatement( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : TranslatableFilesCollection() @Serializable data class RentalAgreement( @@ -37,8 +36,8 @@ data class RentalAgreement( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : TranslatableFilesCollection() @Serializable data class PassportRegistration( @@ -47,8 +46,8 @@ data class PassportRegistration( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : TranslatableFilesCollection() @Serializable data class TemporaryRegistration( @@ -57,7 +56,7 @@ data class TemporaryRegistration( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : TranslatableFilesCollection() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt index 45d874c784..dc7eb6caed 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt @@ -1,6 +1,6 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.passport.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* @@ -13,7 +13,7 @@ sealed class TranslatableIDDocument : WithData, WithFrontSide, WithReverseSide, @Serializable data class DriverLicense( @SerialName(dataField) - @Serializable(Base64StringSerializer::class) + @Serializable(Base64BytesToFromStringSerializer::class) override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile? = null, @@ -24,14 +24,14 @@ data class DriverLicense( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : TranslatableIDDocument() @Serializable data class IdentityCard( @SerialName(dataField) - @Serializable(Base64StringSerializer::class) + @Serializable(Base64BytesToFromStringSerializer::class) override val data: EncryptedData, @SerialName(frontSideField) override val frontSide: PassportFile? = null, @@ -42,6 +42,6 @@ data class IdentityCard( @SerialName(translationField) override val translations: List = emptyList(), @SerialName(hashField) - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : TranslatableIDDocument() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt index 4716d225d2..d2389194de 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt @@ -1,18 +1,21 @@ package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts -import dev.inmo.micro_utils.serialization.base64.Base64StringSerializer +import dev.inmo.micro_utils.crypto.SourceBytes +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonObject +typealias PassportElementHash = SourceBytes + @Serializable(EncryptedElementSerializer::class) interface EncryptedPassportElement { - val hash: String + val hash: PassportElementHash } @Serializable(EncryptedElementSerializer::class) data class UnknownEncryptedPassportElement( val rawJson: JsonObject, - @Serializable(Base64StringSerializer::class) - override val hash: String + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: PassportElementHash ) : EncryptedPassportElement diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt index 83914a9144..eb5367fe1e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt @@ -29,5 +29,5 @@ fun Decryptor.decryptData( data: EncryptedCredentials ) = nonstrictJsonFormat.decodeFromString( JsonObject.serializer(), - data.data.encodeToByteArray().decrypt().decodeToString() + data.data.decrypt().decodeToString() ) diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt index 402a295a99..05563313bb 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt @@ -18,7 +18,7 @@ class PKCS8Decryptor (key: String): Decryptor { private val chunkSize: Int = privateKey.modulus.bitLength() / 8 override fun ByteArray.decrypt(): ByteArray { - return Cipher.getInstance("RSA/ECB/PKCS1Padding").run { + return Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING").run { init(Cipher.DECRYPT_MODE, privateKey) (0 until size step chunkSize).flatMap { val firstIndex = it diff --git a/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt b/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt index 7f9562bffb..b96cde1744 100644 --- a/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt +++ b/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt @@ -36,7 +36,7 @@ OEg9BHa+Du8jSv0vL/fCN2s/2TcvSa9uEnv8KHz59JHevvxoDNbQYlN8Ge8adFv4 xZYQ3h/qh2ohnTUfrG4hcFUVBuv5HBdwgWhVFm5v98KQsqVzGfKorN2DemEv3/au PFGkuu4lCPeDqu5u0dBojoA= -----END PRIVATE KEY-----""" -val encryptedLoremIpsum = "KeuPVezTbMW4MvOGJFTAt34PRaL9iepGb1g4QEi5EQYjKXeXo7RytFOCVx6pW9O/uoMWhl+cX32kNqJVWyK7a22kuhnNT2+aiXqEpuh+madx+LK1zUvGDR1A1Mrf3fFOugcnadCQKICiqvl9cFdqsBkJQOFEs9qj5wiu1F57kekuHLWI7ZnHOojkRNq7l1aCHL0DxcLCfZW5CtWAi8g/zUE5WnGd+vUZ+hqc1vnehDul8JE8YUQbAiIxetzba9XoWouTHYZRZcNCztDbrRBYnq2UCcI5adEwQ3VNcES0lIjRuwn1BBWpvk7VOjqh+4c2tSebDX5AkqrO8XwQYwo8OwvZF+hUXFRK6QLHd4B1JQIdygCaEODG0X353upiEKJXDBqv/ZMXR9KqYZBZEfu48ZM/J6heNjVSOP4TSDrXywJgIOieu8mrQ4d7Or7Twnsu/B+bqS37PvVlfU4wHLl7ehXFj4Kusat6cIrb0R4F/Y3fL4+FcfEsk4ioEAndYBFrc1S11vo/TkcuFnXtqrr181gC5JD5LtsUH6sst36vE/JdL/UwTGqhu+rDUcgvr7FiunkasWBnzCtFs58JJrRycUKPzyKINS16GkY8yYtp7xJXBGPYOFM+J7npcKW7P41j1KceDaUArjph2yIELEXCr8qUZzWXZdrw96Te8gLi99c=" +val encryptedLoremIpsum = "F57wnFj3PTQ+xNgDFLCNRIHVf8Kp7YiaQdYOOEpuWMuICFBvVDrTst82jxhRuKj8w9qDZ0ys9pQ30QjnmCP0h/d8HhmLcG3sYY9fnDgd4hegY0D917Xhc0F5KwheFxNgHFn5uRuTdAoyBVUeAzclpR7XoEO8Zp+kYvNty7eOpLVC2jXBTiTBClXmxM15M48Pw7ClZr2lvjFf7r+4Bh8UAYM8IIKctV/Vk1iR7SIilHOw/GNhgBB1zy0SYlwSuvPEIPfZnEPL4zS9VqDN4Di53Zt7ZLhySBMDi1qA4V6OnjSoF6nexCrytMqIsLHrTbfin5ni20F+vIITFxa7kJU2+AVQFTsYrquL5zN9ms56kkLd3HMv/fdrz9Ry19vSaIjyajipoWPM6BvzNccYk2xnZx+5qzpZUQjsh+Xr+HD7GcpdGwavcz7WqGlx9qKBPwU0rq0+QCRpDz/hnl2gdChk+bjTAfuRWJDoUUetVV283BG8UY5SENH7EjOhtaMsEgog6VI2yyiei6azxZ+MTqkREnHWmjefsBHmbAbf2EEZag+nSjIZhNT62FkhWq5jBghjduoKixS5OUvWniY3wSx0RSXsJPVg9C80EyeO8wyOop7x0wN5zxKoXrniX6AGruEt74SJt9RZamniog2X5CJ27D94HvoF2qXSv9QeqK+qUj9XxGhn0AtqFnvg/yU/jUp6z4yGQ7CkIMHEMbq4ylRA87ydhu3HbqdrW3q8aRXtvo+VFQ8jmsOq+ssj2q7y2WegBMNCBMRjn197S/eBW4EweIqh9+3VsDRoabfUUuCDXBlA+qFOAYEB44TGiaXqneHjUwhDahKlui8556ILcUP4yNnFNA6wx/tgRiW40cEa6vs4CF4UPtzKrVgWwS8/hRd7OBaK/jU3KnMGKZej9AtV28ErDmBTcixMzpflPmUFQABwH7IhUzJMVlqDifZuVjthGZ3FWuPaFOcesQoScQ1q93pohz1vjwtyT5fU36JzyhYpEpmN6h3GiAFV6qT0VDiE" class DecryptionTest { From 15066c9d6389d198ee56a0b3405896ae634ba882 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Jan 2021 17:08:25 +0600 Subject: [PATCH 35/43] add SecureData and DecryptedCredentials --- .../kotlin/dev/inmo/tgbotapi/types/Common.kt | 14 +++++ .../tgbotapi/types/passport/PassportData.kt | 3 +- .../types/passport/PassportElementError.kt | 4 +- .../passport/credentials/DataCredentials.kt | 14 +++++ .../credentials/DecryptedCredentials.kt | 15 ++++++ .../EncryptedCredentials.kt} | 2 +- .../passport/credentials/FileCredentials.kt | 13 +++++ .../passport/decrypted/AddressSecureValue.kt | 13 +++++ .../IdentityWithReverseSideSecureValue.kt | 39 ++++++++++++++ .../decrypted/OtherDocumentsSecureValue.kt | 52 +++++++++++++++++++ .../passport/decrypted/PassportSecureValue.kt | 36 +++++++++++++ .../decrypted/PersonalDetailsSecureValue.kt | 13 +++++ .../types/passport/decrypted/SecureData.kt | 29 +++++++++++ .../decrypted/abstracts/SecureValue.kt | 3 ++ .../abstracts/SecureValueIdentity.kt | 8 +++ .../abstracts/SecureValueWithData.kt | 7 +++ .../abstracts/SecureValueWithFiles.kt | 7 +++ .../abstracts/SecureValueWithReverseSide.kt | 7 +++ .../abstracts/SecureValueWithTranslations.kt | 7 +++ .../{encrypted_data => encrypted}/Email.kt | 6 +-- .../EncryptedAddress.kt | 8 +-- .../EncryptedElementSerializer.kt | 6 +-- .../EncryptedPersonalDetails.kt | 8 +-- .../{encrypted_data => encrypted}/Passport.kt | 6 +-- .../PassportFile.kt | 2 +- .../PhoneNumber.kt | 6 +-- .../TranslatableFilesCollection.kt | 4 +- .../TranslatableIDDocument.kt | 6 +-- .../abstracts/EncryptedPassportElement.kt | 4 +- .../encrypted/abstracts/FilesCollection.kt | 10 ++++ .../encrypted/abstracts/Translatable.kt | 10 ++++ .../passport/encrypted/abstracts/WithData.kt | 10 ++++ .../abstracts/WithEmail.kt | 4 +- .../encrypted/abstracts/WithFrontSide.kt | 10 ++++ .../abstracts/WithPhoneNumber.kt | 4 +- .../encrypted/abstracts/WithReverseSide.kt | 10 ++++ .../encrypted/abstracts/WithSelfie.kt | 10 ++++ .../abstracts/FilesCollection.kt | 10 ---- .../encrypted_data/abstracts/Translatable.kt | 10 ---- .../encrypted_data/abstracts/WithData.kt | 10 ---- .../encrypted_data/abstracts/WithFrontSide.kt | 10 ---- .../abstracts/WithReverseSide.kt | 10 ---- .../encrypted_data/abstracts/WithSelfie.kt | 10 ---- .../utils/passport/DecryptionContext.kt | 5 +- .../tgbotapi/passport/DecryptionTestKeys.kt | 32 ------------ .../utils/passport/CredentialsDecryptor.kt | 2 + ...ontextRealization.kt => PKCS8Decryptor.kt} | 0 .../api/passport/SetPassportDataErrors.kt | 2 +- .../expectations/WaitPassportData.kt | 2 +- .../triggers_handling/PassportTriggers.kt | 2 +- .../tgbotapi/extensions/utils/ClassCasts.kt | 4 +- 51 files changed, 383 insertions(+), 136 deletions(-) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DataCredentials.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DecryptedCredentials.kt rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{EncryptedData.kt => credentials/EncryptedCredentials.kt} (93%) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/FileCredentials.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/AddressSecureValue.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/IdentityWithReverseSideSecureValue.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/OtherDocumentsSecureValue.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PassportSecureValue.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PersonalDetailsSecureValue.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/SecureData.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithFiles.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithReverseSide.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithTranslations.kt rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/Email.kt (69%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/EncryptedAddress.kt (64%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/EncryptedElementSerializer.kt (93%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/EncryptedPersonalDetails.kt (65%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/Passport.kt (89%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/PassportFile.kt (92%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/PhoneNumber.kt (70%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/TranslatableFilesCollection.kt (94%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/TranslatableIDDocument.kt (90%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/abstracts/EncryptedPassportElement.kt (81%) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/FilesCollection.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/Translatable.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithData.kt rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/abstracts/WithEmail.kt (52%) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithFrontSide.kt rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/{encrypted_data => encrypted}/abstracts/WithPhoneNumber.kt (54%) create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithReverseSide.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithSelfie.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/FilesCollection.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/Translatable.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithFrontSide.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithReverseSide.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithSelfie.kt delete mode 100644 tgbotapi.core/src/jsTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt create mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecryptor.kt rename tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/{DecryptionContextRealization.kt => PKCS8Decryptor.kt} (100%) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt index 7346a72269..44c9955298 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/Common.kt @@ -379,3 +379,17 @@ const val fileHashField = "file_hash" const val fileHashesField = "file_hashes" const val messageField = "message" const val unspecifiedField = "unspecified" + +const val secureDataField = "secure_data" +const val nonceField = "nonce" + +const val personalDetailsField = "personal_details" +const val passportField = "passport" +const val internalPassportField = "internal_passport" +const val driverLicenseField = "driver_license" +const val identityCardField = "identity_card" +const val utilityBillField = "utility_bill" +const val bankStatementField = "bank_statement" +const val rentalAgreementField = "rental_agreement" +const val passportRegistrationField = "passport_registration" +const val temporaryRegistrationField = "temporary_registration" diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportData.kt index 9bf4884791..9a55da08ab 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportData.kt @@ -2,7 +2,8 @@ package dev.inmo.tgbotapi.types.passport import dev.inmo.tgbotapi.types.credentialsField import dev.inmo.tgbotapi.types.dataField -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt index 35df08b4ab..9db2e83596 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt @@ -6,8 +6,8 @@ import dev.inmo.micro_utils.crypto.MD5 import dev.inmo.micro_utils.crypto.md5 import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* -import dev.inmo.tgbotapi.types.passport.encrypted_data.type +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.* +import dev.inmo.tgbotapi.types.passport.encrypted.type import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.* import kotlinx.serialization.descriptors.SerialDescriptor diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DataCredentials.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DataCredentials.kt new file mode 100644 index 0000000000..4db61a1f7e --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DataCredentials.kt @@ -0,0 +1,14 @@ +package dev.inmo.tgbotapi.types.passport.credentials + +import dev.inmo.tgbotapi.types.dataHashField +import dev.inmo.tgbotapi.types.secretField +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class DataCredentials( + @SerialName(dataHashField) + val dataHash: String, + @SerialName(secretField) + val secret: String +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DecryptedCredentials.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DecryptedCredentials.kt new file mode 100644 index 0000000000..b732b38281 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DecryptedCredentials.kt @@ -0,0 +1,15 @@ +package dev.inmo.tgbotapi.types.passport.credentials + +import dev.inmo.tgbotapi.types.nonceField +import dev.inmo.tgbotapi.types.passport.decrypted.SecureData +import dev.inmo.tgbotapi.types.secureDataField +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class DecryptedCredentials( + @SerialName(secureDataField) + val secureData: List, + @SerialName(nonceField) + val nonce: String +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/EncryptedCredentials.kt similarity index 93% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/EncryptedCredentials.kt index 11eca0828e..4cd8231c3f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/EncryptedData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/EncryptedCredentials.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.types.passport +package dev.inmo.tgbotapi.types.passport.credentials import dev.inmo.micro_utils.crypto.SourceBytes import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/FileCredentials.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/FileCredentials.kt new file mode 100644 index 0000000000..f73784af17 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/FileCredentials.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.types.passport.credentials + +import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class FileCredentials( + @SerialName(fileHashField) + val fileHash: String, + @SerialName(secretField) + val secret: String +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/AddressSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/AddressSecureValue.kt new file mode 100644 index 0000000000..b47fe28fdc --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/AddressSecureValue.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.types.passport.decrypted + +import dev.inmo.tgbotapi.types.dataField +import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials +import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class AddressSecureValue( + @SerialName(dataField) + override val data: DataCredentials +) : SecureValueWithData \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/IdentityWithReverseSideSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/IdentityWithReverseSideSecureValue.kt new file mode 100644 index 0000000000..ff65ae0c5d --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/IdentityWithReverseSideSecureValue.kt @@ -0,0 +1,39 @@ +package dev.inmo.tgbotapi.types.passport.decrypted + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials +import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials +import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +sealed class IdentityWithReverseSideSecureValue : SecureValueIdentity, SecureValueWithData, SecureValueWithTranslations, SecureValueWithReverseSide + +@Serializable +data class DriverLicenseSecureValue( + @SerialName(dataField) + override val data: DataCredentials, + @SerialName(frontSideField) + override val frontSide: FileCredentials, + @SerialName(reverseSideField) + override val reverseSide: FileCredentials, + @SerialName(selfieField) + override val selfie: FileCredentials, + @SerialName(translationField) + override val translation: List +) : IdentityWithReverseSideSecureValue() + +@Serializable +data class IdentityCardSecureValue( + @SerialName(dataField) + override val data: DataCredentials, + @SerialName(frontSideField) + override val frontSide: FileCredentials, + @SerialName(reverseSideField) + override val reverseSide: FileCredentials, + @SerialName(selfieField) + override val selfie: FileCredentials, + @SerialName(translationField) + override val translation: List +) : IdentityWithReverseSideSecureValue() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/OtherDocumentsSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/OtherDocumentsSecureValue.kt new file mode 100644 index 0000000000..8c304ed8af --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/OtherDocumentsSecureValue.kt @@ -0,0 +1,52 @@ +package dev.inmo.tgbotapi.types.passport.decrypted + +import dev.inmo.tgbotapi.types.filesField +import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials +import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithFiles +import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithTranslations +import dev.inmo.tgbotapi.types.translationField +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +sealed class OtherDocumentsSecureValue : SecureValueWithTranslations, SecureValueWithFiles + +@Serializable +data class UtilityBillSecureValue( + @SerialName(translationField) + override val translation: List, + @SerialName(filesField) + override val files: List +) : OtherDocumentsSecureValue() + +@Serializable +data class BankStatementSecureValue( + @SerialName(translationField) + override val translation: List, + @SerialName(filesField) + override val files: List +) : OtherDocumentsSecureValue() + +@Serializable +data class RentalAgreementSecureValue( + @SerialName(translationField) + override val translation: List, + @SerialName(filesField) + override val files: List +) : OtherDocumentsSecureValue() + +@Serializable +data class PassportRegistrationSecureValue( + @SerialName(translationField) + override val translation: List, + @SerialName(filesField) + override val files: List +) : OtherDocumentsSecureValue() + +@Serializable +data class TemporalRegistrationSecureValue( + @SerialName(translationField) + override val translation: List, + @SerialName(filesField) + override val files: List +) : OtherDocumentsSecureValue() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PassportSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PassportSecureValue.kt new file mode 100644 index 0000000000..9037c02f6b --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PassportSecureValue.kt @@ -0,0 +1,36 @@ +package dev.inmo.tgbotapi.types.passport.decrypted + +import dev.inmo.tgbotapi.types.* +import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials +import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials +import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +sealed class PassportSecureValue : SecureValueIdentity, SecureValueWithData, SecureValueWithTranslations + +@Serializable +data class CommonPassportSecureValue( + @SerialName(dataField) + override val data: DataCredentials, + @SerialName(frontSideField) + override val frontSide: FileCredentials, + @SerialName(selfieField) + override val selfie: FileCredentials, + @SerialName(translationField) + override val translation: List +) : PassportSecureValue() + +@Serializable +data class InternalPassportSecureValue( + @SerialName(dataField) + override val data: DataCredentials, + @SerialName(frontSideField) + override val frontSide: FileCredentials, + @SerialName(selfieField) + override val selfie: FileCredentials, + @SerialName(translationField) + override val translation: List +) : PassportSecureValue() + diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PersonalDetailsSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PersonalDetailsSecureValue.kt new file mode 100644 index 0000000000..185c710fc9 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PersonalDetailsSecureValue.kt @@ -0,0 +1,13 @@ +package dev.inmo.tgbotapi.types.passport.decrypted + +import dev.inmo.tgbotapi.types.dataField +import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials +import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class PersonalDetailsSecureValue( + @SerialName(dataField) + override val data: DataCredentials +) : SecureValueWithData \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/SecureData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/SecureData.kt new file mode 100644 index 0000000000..dd2fb40eed --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/SecureData.kt @@ -0,0 +1,29 @@ +package dev.inmo.tgbotapi.types.passport.decrypted + +import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +data class SecureData( + @SerialName(personalDetailsField) + val personalDetails: PersonalDetailsSecureValue? = null, + @SerialName(passportField) + val passport: PassportSecureValue? = null, + @SerialName(internalPassportField) + val internalPassport: InternalPassportSecureValue? = null, + @SerialName(driverLicenseField) + val driverLicense: DriverLicenseSecureValue? = null, + @SerialName(identityCardField) + val identityCard: IdentityCardSecureValue? = null, + @SerialName(utilityBillField) + val utilityBill: UtilityBillSecureValue? = null, + @SerialName(bankStatementField) + val bankStatement: BankStatementSecureValue? = null, + @SerialName(rentalAgreementField) + val rentalAgreement: RentalAgreementSecureValue? = null, + @SerialName(passportRegistrationField) + val passportRegistration: PassportRegistrationSecureValue? = null, + @SerialName(temporaryRegistrationField) + val temporaryRegistration: TemporalRegistrationSecureValue? = null, +) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue.kt new file mode 100644 index 0000000000..9db0d7c823 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue.kt @@ -0,0 +1,3 @@ +package dev.inmo.tgbotapi.types.passport.decrypted.abstracts + +interface SecureValue diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity.kt new file mode 100644 index 0000000000..1c4847a181 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity.kt @@ -0,0 +1,8 @@ +package dev.inmo.tgbotapi.types.passport.decrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials + +interface SecureValueIdentity : SecureValue { + val frontSide: FileCredentials + val selfie: FileCredentials +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData.kt new file mode 100644 index 0000000000..c3eb5a8b35 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.passport.decrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials + +interface SecureValueWithData : SecureValue { + val data: DataCredentials +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithFiles.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithFiles.kt new file mode 100644 index 0000000000..ea201f1ee8 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithFiles.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.passport.decrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials + +interface SecureValueWithFiles : SecureValue { + val files: List +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithReverseSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithReverseSide.kt new file mode 100644 index 0000000000..b833b9284d --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithReverseSide.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.passport.decrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials + +interface SecureValueWithReverseSide : SecureValue { + val reverseSide: FileCredentials +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithTranslations.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithTranslations.kt new file mode 100644 index 0000000000..f540a2ad7f --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithTranslations.kt @@ -0,0 +1,7 @@ +package dev.inmo.tgbotapi.types.passport.decrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials + +interface SecureValueWithTranslations : SecureValue { + val translation: List +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt similarity index 69% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt index baadbdb726..ca3f3f7f92 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Email.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt @@ -1,10 +1,10 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.emailField import dev.inmo.tgbotapi.types.hashField -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.PassportElementHash -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithEmail +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.WithEmail import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt similarity index 64% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt index abff88fed8..6bb91ac32d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedAddress.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt @@ -1,10 +1,10 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.dataField -import dev.inmo.tgbotapi.types.passport.EncryptedData -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.PassportElementHash -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedElementSerializer.kt similarity index 93% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedElementSerializer.kt index 97e48e4e1b..52cb81f1af 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedElementSerializer.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedElementSerializer.kt @@ -1,10 +1,10 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.crypto.decodeBase64 import dev.inmo.micro_utils.serialization.encapsulator.Encapsulator import dev.inmo.tgbotapi.types.hashField -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.UnknownEncryptedPassportElement +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.UnknownEncryptedPassportElement import dev.inmo.tgbotapi.types.typeField import dev.inmo.tgbotapi.utils.RiskFeature import dev.inmo.tgbotapi.utils.nonstrictJsonFormat diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt similarity index 65% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt index e3f25ec6df..3e79d2370d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/EncryptedPersonalDetails.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt @@ -1,10 +1,10 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.dataField -import dev.inmo.tgbotapi.types.passport.EncryptedData -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.PassportElementHash -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.WithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Passport.kt similarity index 89% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Passport.kt index 9cf858b00e..c23fb1857f 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/Passport.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Passport.kt @@ -1,9 +1,9 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.EncryptedData -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PassportFile.kt similarity index 92% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PassportFile.kt index cf00e2fc2a..675105120b 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PassportFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PassportFile.kt @@ -1,4 +1,4 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.tgbotapi.requests.abstracts.FileId import dev.inmo.tgbotapi.types.* diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt similarity index 70% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt index 48c74f2350..3d70962190 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/PhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt @@ -1,9 +1,9 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.hashField -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.PassportElementHash -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithPhoneNumber +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.WithPhoneNumber import dev.inmo.tgbotapi.types.phoneNumberField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableFilesCollection.kt similarity index 94% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableFilesCollection.kt index 1ad210ca6b..377aad5ce2 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableFilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableFilesCollection.kt @@ -1,8 +1,8 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableIDDocument.kt similarity index 90% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableIDDocument.kt index dc7eb6caed..e20de95245 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/TranslatableIDDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableIDDocument.kt @@ -1,9 +1,9 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data +package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.EncryptedData -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElement.kt similarity index 81% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElement.kt index d2389194de..6bf1d843df 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/EncryptedPassportElement.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElement.kt @@ -1,8 +1,8 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts import dev.inmo.micro_utils.crypto.SourceBytes import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer import kotlinx.serialization.Serializable import kotlinx.serialization.json.JsonObject diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/FilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/FilesCollection.kt new file mode 100644 index 0000000000..bf50a864b2 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/FilesCollection.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface FilesCollection : EncryptedPassportElement { + val files: List +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/Translatable.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/Translatable.kt new file mode 100644 index 0000000000..c538e91d17 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/Translatable.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface Translatable : EncryptedPassportElement { + val translations: List +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithData.kt new file mode 100644 index 0000000000..9e464fec51 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithData.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithData : EncryptedPassportElement { + val data: EncryptedData +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithEmail.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithEmail.kt similarity index 52% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithEmail.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithEmail.kt index 57b069a55f..0442d15771 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithEmail.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithEmail.kt @@ -1,6 +1,6 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithFrontSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithFrontSide.kt new file mode 100644 index 0000000000..396ef60aea --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithFrontSide.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithFrontSide : EncryptedPassportElement { + val frontSide: PassportFile? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithPhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithPhoneNumber.kt similarity index 54% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithPhoneNumber.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithPhoneNumber.kt index 47e1ecdf30..9181eba0e4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithPhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithPhoneNumber.kt @@ -1,6 +1,6 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithReverseSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithReverseSide.kt new file mode 100644 index 0000000000..47d443c3ec --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithReverseSide.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithReverseSide : EncryptedPassportElement { + val reverseSide: PassportFile? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithSelfie.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithSelfie.kt new file mode 100644 index 0000000000..6928c2c311 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithSelfie.kt @@ -0,0 +1,10 @@ +package dev.inmo.tgbotapi.types.passport.encrypted.abstracts + +import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer +import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile +import kotlinx.serialization.Serializable + +@Serializable(EncryptedElementSerializer::class) +interface WithSelfie : EncryptedPassportElement { + val selfie: PassportFile? +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/FilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/FilesCollection.kt deleted file mode 100644 index aa58eb3ecc..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/FilesCollection.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts - -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer -import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile -import kotlinx.serialization.Serializable - -@Serializable(EncryptedElementSerializer::class) -interface FilesCollection : EncryptedPassportElement { - val files: List -} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/Translatable.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/Translatable.kt deleted file mode 100644 index 0e7d7f0af9..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/Translatable.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts - -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer -import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile -import kotlinx.serialization.Serializable - -@Serializable(EncryptedElementSerializer::class) -interface Translatable : EncryptedPassportElement { - val translations: List -} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt deleted file mode 100644 index 163b9d43b6..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithData.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts - -import dev.inmo.tgbotapi.types.passport.EncryptedData -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer -import kotlinx.serialization.Serializable - -@Serializable(EncryptedElementSerializer::class) -interface WithData : EncryptedPassportElement { - val data: EncryptedData -} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithFrontSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithFrontSide.kt deleted file mode 100644 index 400ffae9cd..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithFrontSide.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts - -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer -import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile -import kotlinx.serialization.Serializable - -@Serializable(EncryptedElementSerializer::class) -interface WithFrontSide : EncryptedPassportElement { - val frontSide: PassportFile? -} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithReverseSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithReverseSide.kt deleted file mode 100644 index 059b517955..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithReverseSide.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts - -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer -import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile -import kotlinx.serialization.Serializable - -@Serializable(EncryptedElementSerializer::class) -interface WithReverseSide : EncryptedPassportElement { - val reverseSide: PassportFile? -} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithSelfie.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithSelfie.kt deleted file mode 100644 index fed2706bab..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted_data/abstracts/WithSelfie.kt +++ /dev/null @@ -1,10 +0,0 @@ -package dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts - -import dev.inmo.tgbotapi.types.passport.encrypted_data.EncryptedElementSerializer -import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile -import kotlinx.serialization.Serializable - -@Serializable(EncryptedElementSerializer::class) -interface WithSelfie : EncryptedPassportElement { - val selfie: PassportFile? -} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt index eb5367fe1e..cf0e4e7624 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt @@ -3,9 +3,8 @@ package dev.inmo.tgbotapi.utils.passport import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.get.GetFile -import dev.inmo.tgbotapi.types.passport.EncryptedCredentials -import dev.inmo.tgbotapi.types.passport.encrypted_data.PassportFile -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.WithData +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials +import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.json.JsonObject diff --git a/tgbotapi.core/src/jsTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt b/tgbotapi.core/src/jsTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt deleted file mode 100644 index e82a07397c..0000000000 --- a/tgbotapi.core/src/jsTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTestKeys.kt +++ /dev/null @@ -1,32 +0,0 @@ -package dev.inmo.tgbotapi.passport - -import dev.inmo.tgbotapi.types.passport.EncryptedAndBase64EncodedData - -//actual val privateKey = """-----BEGIN RSA PRIVATE KEY----- -//MIIEowIBAAKCAQEAt0hdC7xyjrRAXxqrd5i06haPfKLdAvRWsPy2yWtYTFom5dBj -//atMUnFKekTwsmhKbRPBoqF7Da0RF+/Y9q9zmZv05+tNz2FEYGJ6o7r/gdAEX+pKs -//Hd84avm9RahGOwbZgcE8r8Md/tg/ZJCSMsVElzM/Gw02+U1uJQE4n/E2AATbRl0M -//oWdyXjh6Zk6HMiTCvhtQOHoMa9yI00wmHVAlZonovZSRQ2mqfwPlbkDhjsDUQMZp -//WcSPQblAd8FLcWsR1Mh86rQl1GxZVWYONaNwoeATe4p6Ng438HCL7jO7nc4jXJwp -//xqwGI9eUYlHolApBeMQK7oEYDTQ+e0iTvFryPQIDAQABAoIBAAnV81BW65rm53Fz -//H/KKGmNZlJeuscefzysuVKzYeuOWDvJUTZGFBF0jPekzXn1iNDzt3d/zPe96uXq9 -//CzA26ZJrUno4cMYSDAX+NbiiSWxQRrYmut/bg86R2mtrjWFLi86fzR7tjKWJe1Vt -//QLtCxNyMXn2YJvQYCKopt501t50mjkgR3xM375cfVmpomcZXh1K+z4ZxFVzivjvK -//ZAga3BPQ/hd6dhnwUdB/yFZFao1dDmsvJVjsnjpnWD3uqtciTeg2iqtXVLpaLfbJ -//gWOt5P94uIP5r1+qvyrrPXzUGONm4l+43zgvleEgAXWGxnutsYaFfazVQ6qOVyE7 -//fGMQfcECgYEA5Zt1fwTVoYIohq4Do/y5TnNcoj4AajXZU1OutFcPM3aNex16UPBW -//hP7Gakq3TwTKxEILDqOwo86IJuG+lX18kUwaj1f/3T0kDFvE6iLimiPYRNByog4c -//Z5Kwqn+vrnl4ciRDoz7jJsURms2PE7mYV7bndA24Gb0FZJRWiB1xI+0CgYEAzFm7 -//uTSyzacTsqorkyUFIwoGgMIE5NDBQNCVhflJcrmuHRYNwxkH9HRCXqyeHKLiNPRa -//zAoBo3WynjActoy0tFJ90qZI1203iT9BMRbPDiZEXnMH4MrWmk7e7poAUsPVKaRr -//hxvHjr2gTOLY0ClolMvnyNxZcZ/jBxAG0WwK3ZECgYEAwSkdmbQZfPwg19zBF05f -//Ho6SmbMLak7O+/jkerbbBPJxZ+eOpVTrlIs5pOYifImNg7oDz1cKHWR8yikTynN9 -//PkcF+R2RFTCAiR0S9d5PQFlzccDjD05Lux5/HZC53VA3cd7sQAOB2XXkr5TLD08N -//yI0I/mskPBL23Hymp3ANZKkCgYAO2fqttCnGjnz9ACcYk5ky+biNRQyMAKv65O3p -//BbwTzXDdBkxLwJb2ajikntEC7ceY56VtrNB/q78mhgKgNcuwS0p/s7wZhAOEQwee -//5LR5p8hSQPPyn2tHXbIQDzs0yKzGUP/LmvY+5oMu81Gkl03VephG3dTWUDN0wPJt -//5/dGMQKBgE++3BNLLV8siedqwjhSrRB/KmpbLPtoOUlRJYBfG+oITgl/d/W2NKOg -//C5GztdiZUKlHsvvcYoAAWrgEE3bKg+D7GI15yzAjQQZH6AOgL+CEnunIHBaxEEgG -//RS39yB/kPcn9ZtvcJd9v8myQnQjhco8Z2RUwb6IUIoOBvZlSGhGe -//-----END RSA PRIVATE KEY-----""" -//actual val encryptedLoremIpsum: EncryptedAndBase64EncodedData = "KeuPVezTbMW4MvOGJFTAt34PRaL9iepGb1g4QEi5EQYjKXeXo7RytFOCVx6pW9O/uoMWhl+cX32kNqJVWyK7a22kuhnNT2+aiXqEpuh+madx+LK1zUvGDR1A1Mrf3fFOugcnadCQKICiqvl9cFdqsBkJQOFEs9qj5wiu1F57kekuHLWI7ZnHOojkRNq7l1aCHL0DxcLCfZW5CtWAi8g/zUE5WnGd+vUZ+hqc1vnehDul8JE8YUQbAiIxetzba9XoWouTHYZRZcNCztDbrRBYnq2UCcI5adEwQ3VNcES0lIjRuwn1BBWpvk7VOjqh+4c2tSebDX5AkqrO8XwQYwo8OwvZF+hUXFRK6QLHd4B1JQIdygCaEODG0X353upiEKJXDBqv/ZMXR9KqYZBZEfu48ZM/J6heNjVSOP4TSDrXywJgIOieu8mrQ4d7Or7Twnsu/B+bqS37PvVlfU4wHLl7ehXFj4Kusat6cIrb0R4F/Y3fL4+FcfEsk4ioEAndYBFrc1S11vo/TkcuFnXtqrr181gC5JD5LtsUH6sst36vE/JdL/UwTGqhu+rDUcgvr7FiunkasWBnzCtFs58JJrRycUKPzyKINS16GkY8yYtp7xJXBGPYOFM+J7npcKW7P41j1KceDaUArjph2yIELEXCr8qUZzWXZdrw96Te8gLi99c=" diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecryptor.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecryptor.kt new file mode 100644 index 0000000000..d2bffb492e --- /dev/null +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecryptor.kt @@ -0,0 +1,2 @@ +package dev.inmo.tgbotapi.utils.passport + diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PKCS8Decryptor.kt similarity index 100% rename from tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContextRealization.kt rename to tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PKCS8Decryptor.kt diff --git a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt index 341f786dd8..5e19524a04 100644 --- a/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt +++ b/tgbotapi.extensions.api/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/api/passport/SetPassportDataErrors.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.types.* import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.passport.PassportData import dev.inmo.tgbotapi.types.passport.PassportElementError -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement import dev.inmo.tgbotapi.utils.passport.Decryptor suspend fun TelegramBot.setPassportDataErrors( diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt index 1e043d5901..309a4705d0 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/expectations/WaitPassportData.kt @@ -5,7 +5,7 @@ import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.requests.abstracts.Request import dev.inmo.tgbotapi.types.message.PassportMessage import dev.inmo.tgbotapi.types.passport.PassportData -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement import dev.inmo.tgbotapi.utils.RiskFeature import kotlinx.coroutines.flow.toList diff --git a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt index 5b2520fc11..971a55419f 100644 --- a/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt +++ b/tgbotapi.extensions.behaviour_builder/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/behaviour_builder/triggers_handling/PassportTriggers.kt @@ -6,7 +6,7 @@ import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow import dev.inmo.tgbotapi.extensions.utils.* import dev.inmo.tgbotapi.extensions.utils.extensions.sourceChat import dev.inmo.tgbotapi.types.message.PassportMessage -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.EncryptedPassportElement +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElement suspend inline fun BehaviourContext.onPassportMessageWith( includeFilterByChatInBehaviourSubContext: Boolean = true, diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 95b212fe0d..9f25cd2f6f 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -38,8 +38,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import dev.inmo.tgbotapi.types.passport.* -import dev.inmo.tgbotapi.types.passport.encrypted_data.* -import dev.inmo.tgbotapi.types.passport.encrypted_data.abstracts.* +import dev.inmo.tgbotapi.types.passport.encrypted.* +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.* import dev.inmo.tgbotapi.types.polls.* import dev.inmo.tgbotapi.types.update.* import dev.inmo.tgbotapi.types.update.MediaGroupUpdates.* From fbe91a632120016dad94afbe5cd72a27617a9ab9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Jan 2021 22:03:14 +0600 Subject: [PATCH 36/43] complete preview tools for passport --- .../passport/credentials/DataCredentials.kt | 14 ----- .../credentials/DecryptedCredentials.kt | 2 +- .../credentials/EndDataCredentials.kt | 35 +++++++++++++ .../passport/credentials/FileCredentials.kt | 13 ----- .../passport/decrypted/AddressSecureValue.kt | 5 +- .../IdentityWithReverseSideSecureValue.kt | 28 +++++----- .../decrypted/OtherDocumentsSecureValue.kt | 26 ++++++---- .../passport/decrypted/PassportSecureValue.kt | 24 +++++---- .../decrypted/PersonalDetailsSecureValue.kt | 5 +- .../types/passport/decrypted/SecureData.kt | 17 +++++- .../decrypted/abstracts/SecureValue.kt | 6 ++- .../abstracts/SecureValueIdentity.kt | 4 +- .../abstracts/SecureValueWithData.kt | 2 +- .../abstracts/SecureValueWithReverseSide.kt | 2 +- .../utils/passport/DecryptionContext.kt | 23 ++------ .../tgbotapi/utils/passport/AESDecryptor.kt | 21 ++++++++ .../utils/passport/CredentialsDecrypting.kt | 29 +++++++++++ .../utils/passport/CredentialsDecryptor.kt | 2 - .../ElementDecryptingWithSecureData.kt | 28 ++++++++++ .../utils/passport/EndDataDecryptor.kt | 15 ++++++ .../tgbotapi/utils/passport/PKCS8Decryptor.kt | 39 -------------- .../PassportDataDecryptionHandling.kt | 15 ++++++ .../inmo/tgbotapi/passport/DecryptionTest.kt | 52 ------------------- 23 files changed, 222 insertions(+), 185 deletions(-) delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DataCredentials.kt create mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/EndDataCredentials.kt delete mode 100644 tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/FileCredentials.kt create mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/AESDecryptor.kt create mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecrypting.kt delete mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecryptor.kt create mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/ElementDecryptingWithSecureData.kt create mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/EndDataDecryptor.kt delete mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PKCS8Decryptor.kt create mode 100644 tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PassportDataDecryptionHandling.kt delete mode 100644 tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DataCredentials.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DataCredentials.kt deleted file mode 100644 index 4db61a1f7e..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DataCredentials.kt +++ /dev/null @@ -1,14 +0,0 @@ -package dev.inmo.tgbotapi.types.passport.credentials - -import dev.inmo.tgbotapi.types.dataHashField -import dev.inmo.tgbotapi.types.secretField -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class DataCredentials( - @SerialName(dataHashField) - val dataHash: String, - @SerialName(secretField) - val secret: String -) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DecryptedCredentials.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DecryptedCredentials.kt index b732b38281..c33a6bcdbf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DecryptedCredentials.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/DecryptedCredentials.kt @@ -9,7 +9,7 @@ import kotlinx.serialization.Serializable @Serializable data class DecryptedCredentials( @SerialName(secureDataField) - val secureData: List, + val secureData: SecureData, @SerialName(nonceField) val nonce: String ) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/EndDataCredentials.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/EndDataCredentials.kt new file mode 100644 index 0000000000..7bcc7838b2 --- /dev/null +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/EndDataCredentials.kt @@ -0,0 +1,35 @@ +package dev.inmo.tgbotapi.types.passport.credentials + +import dev.inmo.micro_utils.crypto.SourceBytes +import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer +import dev.inmo.tgbotapi.types.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +@Serializable +sealed class EndDataCredentials { + @Serializable(Base64BytesToFromStringSerializer::class) + abstract val hash: SourceBytes + @Serializable(Base64BytesToFromStringSerializer::class) + abstract val secret: SourceBytes +} + +@Serializable +data class DataCredentials( + @SerialName(dataHashField) + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: SourceBytes, + @SerialName(secretField) + @Serializable(Base64BytesToFromStringSerializer::class) + override val secret: SourceBytes +) : EndDataCredentials() + +@Serializable +data class FileCredentials( + @SerialName(fileHashField) + @Serializable(Base64BytesToFromStringSerializer::class) + override val hash: SourceBytes, + @SerialName(secretField) + @Serializable(Base64BytesToFromStringSerializer::class) + override val secret: SourceBytes +) : EndDataCredentials() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/FileCredentials.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/FileCredentials.kt deleted file mode 100644 index f73784af17..0000000000 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/credentials/FileCredentials.kt +++ /dev/null @@ -1,13 +0,0 @@ -package dev.inmo.tgbotapi.types.passport.credentials - -import dev.inmo.tgbotapi.types.* -import kotlinx.serialization.SerialName -import kotlinx.serialization.Serializable - -@Serializable -data class FileCredentials( - @SerialName(fileHashField) - val fileHash: String, - @SerialName(secretField) - val secret: String -) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/AddressSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/AddressSecureValue.kt index b47fe28fdc..d403e11db3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/AddressSecureValue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/AddressSecureValue.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.passport.decrypted import dev.inmo.tgbotapi.types.dataField import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials +import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,4 +11,6 @@ import kotlinx.serialization.Serializable data class AddressSecureValue( @SerialName(dataField) override val data: DataCredentials -) : SecureValueWithData \ No newline at end of file +) : SecureValueWithData { + override val credentials: List = listOf(data) +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/IdentityWithReverseSideSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/IdentityWithReverseSideSecureValue.kt index ff65ae0c5d..c05a7a7692 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/IdentityWithReverseSideSecureValue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/IdentityWithReverseSideSecureValue.kt @@ -1,39 +1,41 @@ package dev.inmo.tgbotapi.types.passport.decrypted import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials -import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials +import dev.inmo.tgbotapi.types.passport.credentials.* import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -sealed class IdentityWithReverseSideSecureValue : SecureValueIdentity, SecureValueWithData, SecureValueWithTranslations, SecureValueWithReverseSide +sealed class IdentityWithReverseSideSecureValue : SecureValueIdentity, SecureValueWithData, SecureValueWithTranslations, SecureValueWithReverseSide { + override val credentials: List + get() = listOfNotNull(data, frontSide, reverseSide, selfie) + translation +} @Serializable data class DriverLicenseSecureValue( @SerialName(dataField) - override val data: DataCredentials, + override val data: DataCredentials? = null, @SerialName(frontSideField) - override val frontSide: FileCredentials, + override val frontSide: FileCredentials? = null, @SerialName(reverseSideField) - override val reverseSide: FileCredentials, + override val reverseSide: FileCredentials? = null, @SerialName(selfieField) - override val selfie: FileCredentials, + override val selfie: FileCredentials? = null, @SerialName(translationField) - override val translation: List + override val translation: List = emptyList() ) : IdentityWithReverseSideSecureValue() @Serializable data class IdentityCardSecureValue( @SerialName(dataField) - override val data: DataCredentials, + override val data: DataCredentials? = null, @SerialName(frontSideField) - override val frontSide: FileCredentials, + override val frontSide: FileCredentials? = null, @SerialName(reverseSideField) - override val reverseSide: FileCredentials, + override val reverseSide: FileCredentials? = null, @SerialName(selfieField) - override val selfie: FileCredentials, + override val selfie: FileCredentials? = null, @SerialName(translationField) - override val translation: List + override val translation: List = emptyList() ) : IdentityWithReverseSideSecureValue() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/OtherDocumentsSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/OtherDocumentsSecureValue.kt index 8c304ed8af..778a773cbf 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/OtherDocumentsSecureValue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/OtherDocumentsSecureValue.kt @@ -1,6 +1,7 @@ package dev.inmo.tgbotapi.types.passport.decrypted import dev.inmo.tgbotapi.types.filesField +import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithFiles import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithTranslations @@ -9,44 +10,47 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -sealed class OtherDocumentsSecureValue : SecureValueWithTranslations, SecureValueWithFiles +sealed class OtherDocumentsSecureValue : SecureValueWithTranslations, SecureValueWithFiles { + override val credentials: List + get() = translation + files +} @Serializable data class UtilityBillSecureValue( @SerialName(translationField) - override val translation: List, + override val translation: List = emptyList(), @SerialName(filesField) - override val files: List + override val files: List = emptyList() ) : OtherDocumentsSecureValue() @Serializable data class BankStatementSecureValue( @SerialName(translationField) - override val translation: List, + override val translation: List = emptyList(), @SerialName(filesField) - override val files: List + override val files: List = emptyList() ) : OtherDocumentsSecureValue() @Serializable data class RentalAgreementSecureValue( @SerialName(translationField) - override val translation: List, + override val translation: List = emptyList(), @SerialName(filesField) - override val files: List + override val files: List = emptyList() ) : OtherDocumentsSecureValue() @Serializable data class PassportRegistrationSecureValue( @SerialName(translationField) - override val translation: List, + override val translation: List = emptyList(), @SerialName(filesField) - override val files: List + override val files: List = emptyList() ) : OtherDocumentsSecureValue() @Serializable data class TemporalRegistrationSecureValue( @SerialName(translationField) - override val translation: List, + override val translation: List = emptyList(), @SerialName(filesField) - override val files: List + override val files: List = emptyList() ) : OtherDocumentsSecureValue() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PassportSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PassportSecureValue.kt index 9037c02f6b..effe727275 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PassportSecureValue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PassportSecureValue.kt @@ -1,36 +1,38 @@ package dev.inmo.tgbotapi.types.passport.decrypted import dev.inmo.tgbotapi.types.* -import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials -import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials +import dev.inmo.tgbotapi.types.passport.credentials.* import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.* import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -sealed class PassportSecureValue : SecureValueIdentity, SecureValueWithData, SecureValueWithTranslations +sealed class PassportSecureValue : SecureValueIdentity, SecureValueWithData, SecureValueWithTranslations { + override val credentials: List + get() = listOfNotNull(data, frontSide, selfie) + translation +} @Serializable data class CommonPassportSecureValue( @SerialName(dataField) - override val data: DataCredentials, + override val data: DataCredentials? = null, @SerialName(frontSideField) - override val frontSide: FileCredentials, + override val frontSide: FileCredentials? = null, @SerialName(selfieField) - override val selfie: FileCredentials, + override val selfie: FileCredentials? = null, @SerialName(translationField) - override val translation: List + override val translation: List = emptyList() ) : PassportSecureValue() @Serializable data class InternalPassportSecureValue( @SerialName(dataField) - override val data: DataCredentials, + override val data: DataCredentials? = null, @SerialName(frontSideField) - override val frontSide: FileCredentials, + override val frontSide: FileCredentials? = null, @SerialName(selfieField) - override val selfie: FileCredentials, + override val selfie: FileCredentials? = null, @SerialName(translationField) - override val translation: List + override val translation: List = emptyList() ) : PassportSecureValue() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PersonalDetailsSecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PersonalDetailsSecureValue.kt index 185c710fc9..120b2bf77a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PersonalDetailsSecureValue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/PersonalDetailsSecureValue.kt @@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.types.passport.decrypted import dev.inmo.tgbotapi.types.dataField import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials +import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.SecureValueWithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -10,4 +11,6 @@ import kotlinx.serialization.Serializable data class PersonalDetailsSecureValue( @SerialName(dataField) override val data: DataCredentials -) : SecureValueWithData \ No newline at end of file +) : SecureValueWithData { + override val credentials: List = listOf(data) +} \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/SecureData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/SecureData.kt index dd2fb40eed..c2b9092603 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/SecureData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/SecureData.kt @@ -9,7 +9,7 @@ data class SecureData( @SerialName(personalDetailsField) val personalDetails: PersonalDetailsSecureValue? = null, @SerialName(passportField) - val passport: PassportSecureValue? = null, + val passport: CommonPassportSecureValue? = null, @SerialName(internalPassportField) val internalPassport: InternalPassportSecureValue? = null, @SerialName(driverLicenseField) @@ -26,4 +26,17 @@ data class SecureData( val passportRegistration: PassportRegistrationSecureValue? = null, @SerialName(temporaryRegistrationField) val temporaryRegistration: TemporalRegistrationSecureValue? = null, -) +) { + val allCredentials by lazy { + (personalDetails ?.credentials ?: emptyList()) + + (passport ?.credentials ?: emptyList()) + + (internalPassport ?.credentials ?: emptyList()) + + (driverLicense ?.credentials ?: emptyList()) + + (identityCard ?.credentials ?: emptyList()) + + (utilityBill ?.credentials ?: emptyList()) + + (bankStatement ?.credentials ?: emptyList()) + + (rentalAgreement ?.credentials ?: emptyList()) + + (passportRegistration ?.credentials ?: emptyList()) + + (temporaryRegistration ?.credentials ?: emptyList()) + } +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue.kt index 9db0d7c823..b9bb54371c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValue.kt @@ -1,3 +1,7 @@ package dev.inmo.tgbotapi.types.passport.decrypted.abstracts -interface SecureValue +import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials + +interface SecureValue { + val credentials: List +} diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity.kt index 1c4847a181..e1de83733a 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueIdentity.kt @@ -3,6 +3,6 @@ package dev.inmo.tgbotapi.types.passport.decrypted.abstracts import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials interface SecureValueIdentity : SecureValue { - val frontSide: FileCredentials - val selfie: FileCredentials + val frontSide: FileCredentials? + val selfie: FileCredentials? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData.kt index c3eb5a8b35..9e984cd3b0 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithData.kt @@ -3,5 +3,5 @@ package dev.inmo.tgbotapi.types.passport.decrypted.abstracts import dev.inmo.tgbotapi.types.passport.credentials.DataCredentials interface SecureValueWithData : SecureValue { - val data: DataCredentials + val data: DataCredentials? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithReverseSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithReverseSide.kt index b833b9284d..9706c5d041 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithReverseSide.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/decrypted/abstracts/SecureValueWithReverseSide.kt @@ -3,5 +3,5 @@ package dev.inmo.tgbotapi.types.passport.decrypted.abstracts import dev.inmo.tgbotapi.types.passport.credentials.FileCredentials interface SecureValueWithReverseSide : SecureValue { - val reverseSide: FileCredentials + val reverseSide: FileCredentials? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt index cf0e4e7624..f179e3f627 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/passport/DecryptionContext.kt @@ -1,32 +1,15 @@ package dev.inmo.tgbotapi.utils.passport +import dev.inmo.micro_utils.crypto.SourceBytes import dev.inmo.tgbotapi.bot.TelegramBot import dev.inmo.tgbotapi.requests.DownloadFile import dev.inmo.tgbotapi.requests.get.GetFile import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile import dev.inmo.tgbotapi.utils.nonstrictJsonFormat import kotlinx.serialization.json.JsonObject interface Decryptor { - fun ByteArray.decrypt(): ByteArray + fun decrypt(data: EncryptedData): SourceBytes } - -suspend fun Decryptor.decrypt( - file: PassportFile, - bot: TelegramBot -): ByteArray { - return bot.execute( - DownloadFile( - bot.execute( - GetFile(file.fileId) - ).filePath - ) - ).decrypt() -} -fun Decryptor.decryptData( - data: EncryptedCredentials -) = nonstrictJsonFormat.decodeFromString( - JsonObject.serializer(), - data.data.decrypt().decodeToString() -) diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/AESDecryptor.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/AESDecryptor.kt new file mode 100644 index 0000000000..99b5185bd0 --- /dev/null +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/AESDecryptor.kt @@ -0,0 +1,21 @@ +package dev.inmo.tgbotapi.utils.passport + +import dev.inmo.micro_utils.crypto.SourceBytes +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData +import javax.crypto.Cipher +import javax.crypto.spec.IvParameterSpec +import javax.crypto.spec.SecretKeySpec + +class AESDecryptor(key: SourceBytes, private val iv: ByteArray) : Decryptor { + private val key = SecretKeySpec(key, "AES"); + + override fun decrypt(data: EncryptedData): SourceBytes { + return Cipher.getInstance("AES/CBC/NOPADDING").run { + init(Cipher.DECRYPT_MODE, key, IvParameterSpec(this@AESDecryptor.iv)) + val decryptedCredentials = doFinal(data) + + val padding = decryptedCredentials.first() + decryptedCredentials.copyOfRange(padding.toInt(), decryptedCredentials.size) + } + } +} diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecrypting.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecrypting.kt new file mode 100644 index 0000000000..7639ee5845 --- /dev/null +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecrypting.kt @@ -0,0 +1,29 @@ +package dev.inmo.tgbotapi.utils.passport + +import dev.inmo.micro_utils.crypto.decodeBase64 +import dev.inmo.tgbotapi.types.passport.credentials.DecryptedCredentials +import dev.inmo.tgbotapi.types.passport.credentials.EncryptedCredentials +import dev.inmo.tgbotapi.utils.nonstrictJsonFormat +import java.security.* +import java.security.spec.PKCS8EncodedKeySpec +import javax.crypto.Cipher +import javax.crypto.spec.IvParameterSpec +import javax.crypto.spec.SecretKeySpec + +private val regexToRemoveFromKey = Regex("(-----(BEGIN|END) ((?:.*? KEY)|CERTIFICATE)-----|[\\s])") + +fun EncryptedCredentials.decryptWithPKCS8PrivateKey(privateKey: PrivateKey): DecryptedCredentials { + val decrypted = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding").run { + init(Cipher.DECRYPT_MODE, privateKey) + doFinal(secret) + } + val dataDecryptor = (decrypted to hash).createDecryptor() + val decryptedCredentials = dataDecryptor.decrypt(data).decodeToString() + return nonstrictJsonFormat.decodeFromString(DecryptedCredentials.serializer(), decryptedCredentials) +} + +fun EncryptedCredentials.decryptWithPKCS8PrivateKey(key: String) = decryptWithPKCS8PrivateKey( + KeyFactory.getInstance("RSA").generatePrivate( + PKCS8EncodedKeySpec(key.replace(regexToRemoveFromKey, "").decodeBase64()) + ) +) diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecryptor.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecryptor.kt deleted file mode 100644 index d2bffb492e..0000000000 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/CredentialsDecryptor.kt +++ /dev/null @@ -1,2 +0,0 @@ -package dev.inmo.tgbotapi.utils.passport - diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/ElementDecryptingWithSecureData.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/ElementDecryptingWithSecureData.kt new file mode 100644 index 0000000000..e184139b0d --- /dev/null +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/ElementDecryptingWithSecureData.kt @@ -0,0 +1,28 @@ +package dev.inmo.tgbotapi.utils.passport + +import dev.inmo.micro_utils.crypto.SourceBytes +import dev.inmo.tgbotapi.bot.TelegramBot +import dev.inmo.tgbotapi.requests.DownloadFile +import dev.inmo.tgbotapi.requests.get.GetFile +import dev.inmo.tgbotapi.types.passport.credentials.* +import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile + +fun EndDataCredentials.decryptData( + bytes: EncryptedData +): SourceBytes { + return createDecryptor().decrypt(bytes) +} + +fun FileCredentials.decryptFile( + fileBytes: ByteArray +): SourceBytes { + return createDecryptor().decrypt(fileBytes) +} +suspend fun FileCredentials.decryptFile( + bot: TelegramBot, + passportFile: PassportFile +): SourceBytes { + val pathedFile = bot.execute(GetFile(passportFile.fileId)) + val bytes = bot.execute(DownloadFile(pathedFile.filePath)) + return decryptFile(bytes) +} diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/EndDataDecryptor.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/EndDataDecryptor.kt new file mode 100644 index 0000000000..02a509a53e --- /dev/null +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/EndDataDecryptor.kt @@ -0,0 +1,15 @@ +package dev.inmo.tgbotapi.utils.passport + +import dev.inmo.micro_utils.crypto.SourceBytes +import dev.inmo.tgbotapi.types.passport.credentials.EndDataCredentials +import java.security.MessageDigest + +fun Pair.createDecryptor(): Decryptor { + val secretHash = MessageDigest.getInstance("SHA-512").digest(first + second) + val key = secretHash.copyOf(32) + val iv = secretHash.copyOfRange(32, 48) + + return AESDecryptor(key, iv) +} + +fun EndDataCredentials.createDecryptor() = (secret to hash).createDecryptor() diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PKCS8Decryptor.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PKCS8Decryptor.kt deleted file mode 100644 index 05563313bb..0000000000 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PKCS8Decryptor.kt +++ /dev/null @@ -1,39 +0,0 @@ -package dev.inmo.tgbotapi.utils.passport - -import dev.inmo.micro_utils.crypto.decodeBase64 -import java.security.KeyFactory -import java.security.interfaces.RSAPrivateKey -import java.security.spec.PKCS8EncodedKeySpec -import javax.crypto.Cipher - -private val regexToRemoveFromKey = Regex("(-----(BEGIN|END) ((?:.*? KEY)|CERTIFICATE)-----|[\\s])") - -/** - * @param key PKCS8 - */ -class PKCS8Decryptor (key: String): Decryptor { - private val privateKey: RSAPrivateKey = KeyFactory.getInstance("RSA").generatePrivate( - PKCS8EncodedKeySpec(key.replace(regexToRemoveFromKey, "").decodeBase64()) - ) as RSAPrivateKey - private val chunkSize: Int = privateKey.modulus.bitLength() / 8 - - override fun ByteArray.decrypt(): ByteArray { - return Cipher.getInstance("RSA/ECB/OAEPWITHSHA-256ANDMGF1PADDING").run { - init(Cipher.DECRYPT_MODE, privateKey) - (0 until size step chunkSize).flatMap { - val firstIndex = it - val lastIndexExclusive = if (it + chunkSize > size) { - size - } else { - it + chunkSize - } - doFinal(copyOfRange(firstIndex, lastIndexExclusive)).toList() - }.toByteArray() - } - } -} - -fun Decryptor(key: String) = PKCS8Decryptor(key) - -inline fun doWithDecryptor(decryptor: Decryptor, crossinline block: Decryptor.() -> T) = decryptor.run(block) -inline fun doWithDecryptor(key: String, crossinline block: Decryptor.() -> T) = doWithDecryptor(Decryptor(key), block) diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PassportDataDecryptionHandling.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PassportDataDecryptionHandling.kt new file mode 100644 index 0000000000..4743dd5ac1 --- /dev/null +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PassportDataDecryptionHandling.kt @@ -0,0 +1,15 @@ +package dev.inmo.tgbotapi.utils.passport + +import dev.inmo.tgbotapi.types.passport.PassportData +import dev.inmo.tgbotapi.types.passport.decrypted.SecureData +import java.security.PrivateKey + +inline fun PassportData.doInDecryptionContextWithPKCS8Key( + pkcs8Key: PrivateKey, + expectedNonce: String? = null, + crossinline block: SecureData.() -> T +): T { + val decryptedCredentials = credentials.decryptWithPKCS8PrivateKey(pkcs8Key) + expectedNonce ?.let { require(expectedNonce == decryptedCredentials.nonce) } + return decryptedCredentials.secureData.run(block) +} diff --git a/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt b/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt deleted file mode 100644 index b96cde1744..0000000000 --- a/tgbotapi.core/src/jvmTest/kotlin/dev/inmo/tgbotapi/passport/DecryptionTest.kt +++ /dev/null @@ -1,52 +0,0 @@ -package dev.inmo.tgbotapi.passport - -import dev.inmo.micro_utils.crypto.decodeBase64 -import dev.inmo.tgbotapi.utils.passport.Decryptor -import dev.inmo.tgbotapi.utils.passport.doWithDecryptor -import kotlin.test.Test -import kotlin.test.assertEquals - -//expect val privateKey: String -//expect val encryptedLoremIpsum: EncryptedAndBase64EncodedData -val privateKey: String = """-----BEGIN PRIVATE KEY----- -MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCaaMFkmMBi6Vl5 -vzy7wQjoZNLN+e9e6Lb/WBekJxfbNMt+EN9Zv7xT9xzfY68DX7v0uGoLcAqS5Mh5 -8ELiJbzg4O8dbxkggt0G+kxcbT+a3ofm1Aqhr+LkpsFh5qbLqbAHSQJAF0HPqrAc -5c6MoQVTZlWGU/j3enCcUFo7Jpsi8La6MqYboF5xGwGEZ9tOA6rMDSekr5Rdm637 -D/w4h284UX7VnqPdpZ/943VK2qvmPjm8HkFSxkSAB8RHlFyjazzm9FNOcVRGLynv -/cq7mWgyxt5nqiCG7w+lFNAFNQNvAO0rfeiTJbEzubquu4Mg31QrvLIuz+fUbsGk -ipfpN1czAgMBAAECggEAPlAoO8CpY0FoqolSqTKttZt6t0U2JMclksaqQ8TDC+Oy -e52zhTSre/ct37kK2AG6iHgj05nTqpRJk2wykbFJGDeuR+Kd8VDeggJg7qvoD0fe -8HiCEd45Yq0pPaknhulj8Iy2K8c29+eaSw8y2+3fiFi0CxG4V6dB6tNClrxtvxtl -IE85Utzmk4PLTCs010zxNVm+FwrvqlpjjhspljzleUuWE1KuldO9tNSlwUUfBr4i -BJJn4jDkQMloXoM/ArZEp7mn57N9+ZuEgVjRMCpRGEAbQI+aLCznBB1kCOY7WL8S -CwkP++SvcptaUpOjoXZZyuGU4CgBnu0+40ORbNchgQKBgQDLIbB9+WHDcZAn1g6M -8jaNDRU4HGu5vJSajFQK8Uaczg87hAxmk6R1GF0LOyoadaVmD5ax93mQxWSE/4hT -wyAPaQOFl7A/i1k/Dx/kURjRwF1sLWDFdMo/8t5bXumzrzb1bHYnHPS7S0lBAU+X -SrbIw+hv69aKawcQqdd54S1OBwKBgQDCmMarwMVn4xnOh+DOuLS4IQzPT84WgzH+ -wKw55hZGMqZ4S3JRVv256daweEbKAeR5NCccPmir0H86jwUW6WFAtxqfPWF4piVi -UD6DrUt0gWwzMGy3kbAp0hLBtsQRp/41mKuAXkvMVQ2ysInn6lmHhZvjduK8lvKh -fMRDMjxidQKBgFiciK5blI86wgTutwg7PRrI40HH/CJZJoZIwvzHBeOvbCutTe+N -ZoeCKkyU8af7PDzKfhWCfHBv+4qdIi5QB3NRfyzO4B7IPhVpFqN10RrnDJn9LaLV -cMj2vJMlU1OEErh7KQuk8QmnLPyDguHfwN7Rv1rbiYp2Z+2X+Zx8Y1QPAoGBAJIf -nq/CJXoJMou/xLP2Rt4tEy1pQ9vr0FL341vmxrsXtaGHJeSmagh861XAO4fdO+83 -llbDFl5ORft3Ad9eiETMOhVxRgwO1uuoTgkazBpERTd7GWgO4jXFJYiI8VpAx8b/ -SWkvZcOd6pdPsX6Qn4IAdjqsPz5WKwPQaJ/8zRMxAoGAGaOuyXaFZNl8IeTGYMDL -OEg9BHa+Du8jSv0vL/fCN2s/2TcvSa9uEnv8KHz59JHevvxoDNbQYlN8Ge8adFv4 -xZYQ3h/qh2ohnTUfrG4hcFUVBuv5HBdwgWhVFm5v98KQsqVzGfKorN2DemEv3/au -PFGkuu4lCPeDqu5u0dBojoA= ------END PRIVATE KEY-----""" -val encryptedLoremIpsum = "F57wnFj3PTQ+xNgDFLCNRIHVf8Kp7YiaQdYOOEpuWMuICFBvVDrTst82jxhRuKj8w9qDZ0ys9pQ30QjnmCP0h/d8HhmLcG3sYY9fnDgd4hegY0D917Xhc0F5KwheFxNgHFn5uRuTdAoyBVUeAzclpR7XoEO8Zp+kYvNty7eOpLVC2jXBTiTBClXmxM15M48Pw7ClZr2lvjFf7r+4Bh8UAYM8IIKctV/Vk1iR7SIilHOw/GNhgBB1zy0SYlwSuvPEIPfZnEPL4zS9VqDN4Di53Zt7ZLhySBMDi1qA4V6OnjSoF6nexCrytMqIsLHrTbfin5ni20F+vIITFxa7kJU2+AVQFTsYrquL5zN9ms56kkLd3HMv/fdrz9Ry19vSaIjyajipoWPM6BvzNccYk2xnZx+5qzpZUQjsh+Xr+HD7GcpdGwavcz7WqGlx9qKBPwU0rq0+QCRpDz/hnl2gdChk+bjTAfuRWJDoUUetVV283BG8UY5SENH7EjOhtaMsEgog6VI2yyiei6azxZ+MTqkREnHWmjefsBHmbAbf2EEZag+nSjIZhNT62FkhWq5jBghjduoKixS5OUvWniY3wSx0RSXsJPVg9C80EyeO8wyOop7x0wN5zxKoXrniX6AGruEt74SJt9RZamniog2X5CJ27D94HvoF2qXSv9QeqK+qUj9XxGhn0AtqFnvg/yU/jUp6z4yGQ7CkIMHEMbq4ylRA87ydhu3HbqdrW3q8aRXtvo+VFQ8jmsOq+ssj2q7y2WegBMNCBMRjn197S/eBW4EweIqh9+3VsDRoabfUUuCDXBlA+qFOAYEB44TGiaXqneHjUwhDahKlui8556ILcUP4yNnFNA6wx/tgRiW40cEa6vs4CF4UPtzKrVgWwS8/hRd7OBaK/jU3KnMGKZej9AtV28ErDmBTcixMzpflPmUFQABwH7IhUzJMVlqDifZuVjthGZ3FWuPaFOcesQoScQ1q93pohz1vjwtyT5fU36JzyhYpEpmN6h3GiAFV6qT0VDiE" - - -class DecryptionTest { - val inputText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." - - @Test - fun testThatDecryptionIsWorkingCorrectly() { - doWithDecryptor(privateKey) { - val decrypted = encryptedLoremIpsum.decodeBase64().decrypt().decodeToString() - assertEquals(inputText, decrypted) - } - } -} From b0eef4f82d0db39d0721d1a2a206a352ca5a29ce Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Jan 2021 22:06:52 +0600 Subject: [PATCH 37/43] update ktor --- CHANGELOG.md | 1 + gradle.properties | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c5f369f1..b1203c11fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * `Version`: * `MicroUtils`: `0.4.16` -> `0.4.23` * `Klock`: `0.2.3` -> `0.2.4` + * `Ktor`: `1.5.0` -> `1.5.1` * `Core`: * **BREAKING CHANGE** Now `MediaGroupMessage` have a generic type related to `MediaGroupContent` * Methods and types related to `MediaGroupMessage` have been modified according to their meanings diff --git a/gradle.properties b/gradle.properties index d8cdce6fd8..710eeb454a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ kotlin_coroutines_version=1.4.2 kotlin_serialisation_runtime_version=1.0.1 klock_version=2.0.4 uuid_version=0.2.3 -ktor_version=1.5.0 +ktor_version=1.5.1 micro_utils_version=0.4.23 From d67c80bc99a61bc74e0a13aeac02ff0d98f42d4c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Thu, 28 Jan 2021 22:21:21 +0600 Subject: [PATCH 38/43] ClassCasts update for SecureValue --- .../tgbotapi/extensions/utils/ClassCasts.kt | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index 9f25cd2f6f..b2f24fd9b9 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -38,6 +38,8 @@ import dev.inmo.tgbotapi.types.message.content.abstracts.* import dev.inmo.tgbotapi.types.message.content.media.* import dev.inmo.tgbotapi.types.message.payments.InvoiceContent import dev.inmo.tgbotapi.types.passport.* +import dev.inmo.tgbotapi.types.passport.decrypted.* +import dev.inmo.tgbotapi.types.passport.decrypted.abstracts.* import dev.inmo.tgbotapi.types.passport.encrypted.* import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.* import dev.inmo.tgbotapi.types.polls.* @@ -315,6 +317,82 @@ inline fun EncryptedPassportElement.asWithSelfie(): WithSelfie? = this as? WithS @PreviewFeature inline fun EncryptedPassportElement.requireWithSelfie(): WithSelfie = this as WithSelfie @PreviewFeature +inline fun SecureValue.asAddressSecureValue(): AddressSecureValue? = this as? AddressSecureValue +@PreviewFeature +inline fun SecureValue.requireAddressSecureValue(): AddressSecureValue = this as AddressSecureValue +@PreviewFeature +inline fun SecureValue.asBankStatementSecureValue(): BankStatementSecureValue? = this as? BankStatementSecureValue +@PreviewFeature +inline fun SecureValue.requireBankStatementSecureValue(): BankStatementSecureValue = this as BankStatementSecureValue +@PreviewFeature +inline fun SecureValue.asCommonPassportSecureValue(): CommonPassportSecureValue? = this as? CommonPassportSecureValue +@PreviewFeature +inline fun SecureValue.requireCommonPassportSecureValue(): CommonPassportSecureValue = this as CommonPassportSecureValue +@PreviewFeature +inline fun SecureValue.asDriverLicenseSecureValue(): DriverLicenseSecureValue? = this as? DriverLicenseSecureValue +@PreviewFeature +inline fun SecureValue.requireDriverLicenseSecureValue(): DriverLicenseSecureValue = this as DriverLicenseSecureValue +@PreviewFeature +inline fun SecureValue.asIdentityCardSecureValue(): IdentityCardSecureValue? = this as? IdentityCardSecureValue +@PreviewFeature +inline fun SecureValue.requireIdentityCardSecureValue(): IdentityCardSecureValue = this as IdentityCardSecureValue +@PreviewFeature +inline fun SecureValue.asIdentityWithReverseSideSecureValue(): IdentityWithReverseSideSecureValue? = this as? IdentityWithReverseSideSecureValue +@PreviewFeature +inline fun SecureValue.requireIdentityWithReverseSideSecureValue(): IdentityWithReverseSideSecureValue = this as IdentityWithReverseSideSecureValue +@PreviewFeature +inline fun SecureValue.asInternalPassportSecureValue(): InternalPassportSecureValue? = this as? InternalPassportSecureValue +@PreviewFeature +inline fun SecureValue.requireInternalPassportSecureValue(): InternalPassportSecureValue = this as InternalPassportSecureValue +@PreviewFeature +inline fun SecureValue.asOtherDocumentsSecureValue(): OtherDocumentsSecureValue? = this as? OtherDocumentsSecureValue +@PreviewFeature +inline fun SecureValue.requireOtherDocumentsSecureValue(): OtherDocumentsSecureValue = this as OtherDocumentsSecureValue +@PreviewFeature +inline fun SecureValue.asPassportRegistrationSecureValue(): PassportRegistrationSecureValue? = this as? PassportRegistrationSecureValue +@PreviewFeature +inline fun SecureValue.requirePassportRegistrationSecureValue(): PassportRegistrationSecureValue = this as PassportRegistrationSecureValue +@PreviewFeature +inline fun SecureValue.asPassportSecureValue(): PassportSecureValue? = this as? PassportSecureValue +@PreviewFeature +inline fun SecureValue.requirePassportSecureValue(): PassportSecureValue = this as PassportSecureValue +@PreviewFeature +inline fun SecureValue.asPersonalDetailsSecureValue(): PersonalDetailsSecureValue? = this as? PersonalDetailsSecureValue +@PreviewFeature +inline fun SecureValue.requirePersonalDetailsSecureValue(): PersonalDetailsSecureValue = this as PersonalDetailsSecureValue +@PreviewFeature +inline fun SecureValue.asRentalAgreementSecureValue(): RentalAgreementSecureValue? = this as? RentalAgreementSecureValue +@PreviewFeature +inline fun SecureValue.requireRentalAgreementSecureValue(): RentalAgreementSecureValue = this as RentalAgreementSecureValue +@PreviewFeature +inline fun SecureValue.asTemporalRegistrationSecureValue(): TemporalRegistrationSecureValue? = this as? TemporalRegistrationSecureValue +@PreviewFeature +inline fun SecureValue.requireTemporalRegistrationSecureValue(): TemporalRegistrationSecureValue = this as TemporalRegistrationSecureValue +@PreviewFeature +inline fun SecureValue.asUtilityBillSecureValue(): UtilityBillSecureValue? = this as? UtilityBillSecureValue +@PreviewFeature +inline fun SecureValue.requireUtilityBillSecureValue(): UtilityBillSecureValue = this as UtilityBillSecureValue +@PreviewFeature +inline fun SecureValue.asSecureValueIdentity(): SecureValueIdentity? = this as? SecureValueIdentity +@PreviewFeature +inline fun SecureValue.requireSecureValueIdentity(): SecureValueIdentity = this as SecureValueIdentity +@PreviewFeature +inline fun SecureValue.asSecureValueWithData(): SecureValueWithData? = this as? SecureValueWithData +@PreviewFeature +inline fun SecureValue.requireSecureValueWithData(): SecureValueWithData = this as SecureValueWithData +@PreviewFeature +inline fun SecureValue.asSecureValueWithFiles(): SecureValueWithFiles? = this as? SecureValueWithFiles +@PreviewFeature +inline fun SecureValue.requireSecureValueWithFiles(): SecureValueWithFiles = this as SecureValueWithFiles +@PreviewFeature +inline fun SecureValue.asSecureValueWithReverseSide(): SecureValueWithReverseSide? = this as? SecureValueWithReverseSide +@PreviewFeature +inline fun SecureValue.requireSecureValueWithReverseSide(): SecureValueWithReverseSide = this as SecureValueWithReverseSide +@PreviewFeature +inline fun SecureValue.asSecureValueWithTranslations(): SecureValueWithTranslations? = this as? SecureValueWithTranslations +@PreviewFeature +inline fun SecureValue.requireSecureValueWithTranslations(): SecureValueWithTranslations = this as SecureValueWithTranslations +@PreviewFeature inline fun Message.asAnonymousGroupMessageImpl(): AnonymousGroupMessageImpl? = this as? AnonymousGroupMessageImpl @PreviewFeature inline fun Message.requireAnonymousGroupMessageImpl(): AnonymousGroupMessageImpl = this as AnonymousGroupMessageImpl From 9e73d0c461f5d328e6858dbf9a59cfcfc42e735b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Jan 2021 00:56:47 +0600 Subject: [PATCH 39/43] add opportunity to manually set up delay for media groups webhooks --- .../extensions/utils/updates/retrieving/Webhook.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt index fcb780754d..5111c46980 100644 --- a/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt +++ b/tgbotapi.extensions.utils/src/jvmMain/kotlin/dev/inmo/tgbotapi/extensions/utils/updates/retrieving/Webhook.kt @@ -34,9 +34,10 @@ import java.util.concurrent.Executors fun Route.includeWebhookHandlingInRoute( scope: CoroutineScope, exceptionsHandler: ExceptionHandler? = null, + mediaGroupsDebounceTimeMillis: Long = 1000L, block: UpdateReceiver ) { - val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block) + val transformer = scope.updateHandlerWithMediaGroupsAdaptation(block, mediaGroupsDebounceTimeMillis) post { safely( exceptionsHandler ?: {} @@ -56,10 +57,12 @@ fun Route.includeWebhookHandlingInRoute( fun Route.includeWebhookHandlingInRouteWithFlows( scope: CoroutineScope, exceptionsHandler: ExceptionHandler? = null, + mediaGroupsDebounceTimeMillis: Long = 1000L, block: FlowsUpdatesFilter.() -> Unit ) = includeWebhookHandlingInRoute( scope, exceptionsHandler, + mediaGroupsDebounceTimeMillis, flowsUpdatesFilter(block = block).asUpdateReceiver ) @@ -83,6 +86,7 @@ fun startListenWebhooks( listenRoute: String? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null, scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), + mediaGroupsDebounceTimeMillis: Long = 1000L, block: UpdateReceiver ): ApplicationEngine { val env = applicationEngineEnvironment { @@ -90,8 +94,8 @@ fun startListenWebhooks( module { routing { listenRoute ?.also { - createRouteFromPath(it).includeWebhookHandlingInRoute(scope, exceptionsHandler, block) - } ?: includeWebhookHandlingInRoute(scope, exceptionsHandler, block) + createRouteFromPath(it).includeWebhookHandlingInRoute(scope, exceptionsHandler, mediaGroupsDebounceTimeMillis, block) + } ?: includeWebhookHandlingInRoute(scope, exceptionsHandler, mediaGroupsDebounceTimeMillis, block) } } privateKeyConfig ?.let { @@ -137,10 +141,11 @@ suspend fun RequestsExecutor.setWebhookInfoAndStartListenWebhooks( listenRoute: String = "/", privateKeyConfig: WebhookPrivateKeyConfig? = null, scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), + mediaGroupsDebounceTimeMillis: Long = 1000L, block: UpdateReceiver ): ApplicationEngine = try { execute(setWebhookRequest) - startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, block) + startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, mediaGroupsDebounceTimeMillis, block) } catch (e: Exception) { throw e } From 040654f1315477c0241ec0c9058b9709964d78c1 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Jan 2021 01:18:44 +0600 Subject: [PATCH 40/43] refill readme --- tgbotapi.core/README.md | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tgbotapi.core/README.md b/tgbotapi.core/README.md index a36ece9cd3..0b8ed3f0d4 100644 --- a/tgbotapi.core/README.md +++ b/tgbotapi.core/README.md @@ -11,9 +11,6 @@ moments are describing by official [Telegram Bot API](https://core.telegram.org/ ## Compatibility This version compatible with [4th of November 2020 update of TelegramBotAPI (version 5.0)](https://core.telegram.org/bots/api#november-4-2020). -There is only one exception of implemented functionality - Telegram Passport API, which was presented in -[August 2018 update of TelegramBotAPI](https://core.telegram.org/bots/api-changelog#august-27-2018) update. It will be implemented -as soon as possible. ## How to implement library? @@ -149,3 +146,18 @@ Here was used `okhttp` realisation of client, but there are several others engin available on ktor.io site for [client](https://ktor.io/clients/http-client/engines.html) and [server](https://ktor.io/quickstart/artifacts.html) engines. +### Passport + +In case you wish to work with `Telegram Passport`, currently there are several useful things, but most part of working +with decryption and handling is available only on JVM. Next snippet contains example of data decryption on JVM platform: + +```kotlin +passportMessage.passportData.doInDecryptionContextWithPKCS8Key(privateKey) { + val passportDataSecureValue = passport ?.data ?: return@doInDecryptionContextWithPKCS8Key + val passportData = (passportMessage.passportData.data.firstOrNull { it is CommonPassport } ?: return@doInDecryptionContextWithPKCS8Key) as CommonPassport + val decrypted = passportDataSecureValue.decrypt( + passportData.data + ) ?.decodeToString() ?: return@doInDecryptionContextWithPKCS8Key + println(decrypted) +} +``` From ecc608f51a2f2651215ec12234b924a03254c3e7 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Jan 2021 10:44:11 +0600 Subject: [PATCH 41/43] add additional variant of doInDecryptionContextWithPKCS8Key --- .../utils/passport/PassportDataDecryptionHandling.kt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PassportDataDecryptionHandling.kt b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PassportDataDecryptionHandling.kt index 4743dd5ac1..a5a7dcfaaf 100644 --- a/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PassportDataDecryptionHandling.kt +++ b/tgbotapi.core/src/jvmMain/kotlin/dev/inmo/tgbotapi/utils/passport/PassportDataDecryptionHandling.kt @@ -13,3 +13,12 @@ inline fun PassportData.doInDecryptionContextWithPKCS8Key( expectedNonce ?.let { require(expectedNonce == decryptedCredentials.nonce) } return decryptedCredentials.secureData.run(block) } +inline fun PassportData.doInDecryptionContextWithPKCS8Key( + pkcs8Key: String, + expectedNonce: String? = null, + crossinline block: SecureData.() -> T +): T { + val decryptedCredentials = credentials.decryptWithPKCS8PrivateKey(pkcs8Key) + expectedNonce ?.let { require(expectedNonce == decryptedCredentials.nonce) } + return decryptedCredentials.secureData.run(block) +} From 131ec4d6d50f44af59199bb8ba7218500b69e665 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Jan 2021 12:44:13 +0600 Subject: [PATCH 42/43] renames of EncryptedPassportElements --- .../types/passport/PassportElementError.kt | 16 ++++---- .../types/passport/encrypted/Email.kt | 5 +-- .../passport/encrypted/EncryptedAddress.kt | 4 +- ...ElementWithTranslatableFilesCollection.kt} | 12 +++--- ...sportElementWithTranslatableIDDocument.kt} | 6 +-- .../encrypted/EncryptedPersonalDetails.kt | 4 +- .../types/passport/encrypted/Passport.kt | 2 +- .../types/passport/encrypted/PhoneNumber.kt | 5 +-- ...> EncryptedPassportElementTranslatable.kt} | 2 +- ...kt => EncryptedPassportElementWithData.kt} | 2 +- ...t => EncryptedPassportElementWithEmail.kt} | 2 +- ...ptedPassportElementWithFilesCollection.kt} | 2 +- ... EncryptedPassportElementWithFrontSide.kt} | 2 +- ...ncryptedPassportElementWithPhoneNumber.kt} | 2 +- ...ncryptedPassportElementWithReverseSide.kt} | 2 +- ... => EncryptedPassportElementWithSelfie.kt} | 2 +- .../tgbotapi/extensions/utils/ClassCasts.kt | 40 +++++++++---------- 17 files changed, 54 insertions(+), 56 deletions(-) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/{TranslatableFilesCollection.kt => EncryptedPassportElementWithTranslatableFilesCollection.kt} (81%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/{TranslatableIDDocument.kt => EncryptedPassportElementWithTranslatableIDDocument.kt} (82%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/{Translatable.kt => EncryptedPassportElementTranslatable.kt} (81%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/{WithData.kt => EncryptedPassportElementWithData.kt} (81%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/{WithEmail.kt => EncryptedPassportElementWithEmail.kt} (77%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/{FilesCollection.kt => EncryptedPassportElementWithFilesCollection.kt} (79%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/{WithFrontSide.kt => EncryptedPassportElementWithFrontSide.kt} (80%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/{WithPhoneNumber.kt => EncryptedPassportElementWithPhoneNumber.kt} (76%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/{WithReverseSide.kt => EncryptedPassportElementWithReverseSide.kt} (80%) rename tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/{WithSelfie.kt => EncryptedPassportElementWithSelfie.kt} (81%) diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt index 9db2e83596..74dfc64364 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/PassportElementError.kt @@ -100,7 +100,7 @@ data class PassportElementErrorDataField( @Required override val source: String = dataField } -fun WithData.createDataError(field: String, message: String) = PassportElementErrorDataField( +fun EncryptedPassportElementWithData.createDataError(field: String, message: String) = PassportElementErrorDataField( type, field, hash, @@ -121,7 +121,7 @@ data class PassportElementErrorFrontSide( @Required override val source: String = frontSideField } -fun WithFrontSide.createFrontSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFrontSide( +fun EncryptedPassportElementWithFrontSide.createFrontSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFrontSide( type, unencryptedFileHash, message @@ -141,7 +141,7 @@ data class PassportElementErrorReverseSide( @Required override val source: String = reverseSideField } -fun WithReverseSide.createReverseSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorReverseSide( +fun EncryptedPassportElementWithReverseSide.createReverseSideError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorReverseSide( type, unencryptedFileHash, message @@ -160,7 +160,7 @@ data class PassportElementErrorSelfie( @Required override val source: String = selfieField } -fun WithSelfie.createSelfieError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorSelfie( +fun EncryptedPassportElementWithSelfie.createSelfieError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorSelfie( type, unencryptedFileHash, message @@ -181,7 +181,7 @@ data class PassportElementErrorFile( @Required override val source: String = fileField } -fun FilesCollection.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFile( +fun EncryptedPassportElementWithFilesCollection.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorFile( type, unencryptedFileHash, message @@ -200,7 +200,7 @@ data class PassportElementErrorFiles( @Required override val source: String = filesField } -fun FilesCollection.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorFiles( +fun EncryptedPassportElementWithFilesCollection.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorFiles( type, unencryptedFileHashes, message @@ -221,7 +221,7 @@ data class PassportElementErrorTranslationFile( @Required override val source: String = translationFileField } -fun Translatable.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorTranslationFile( +fun EncryptedPassportElementTranslatable.createFileError(message: String, unencryptedFileHash: PassportElementHash) = PassportElementErrorTranslationFile( type, unencryptedFileHash, message @@ -239,7 +239,7 @@ data class PassportElementErrorTranslationFiles( @Required override val source: String = translationFilesField } -fun Translatable.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorTranslationFiles( +fun EncryptedPassportElementTranslatable.createFilesError(message: String, unencryptedFileHashes: List) = PassportElementErrorTranslationFiles( type, unencryptedFileHashes, message diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt index ca3f3f7f92..a8ed36220e 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Email.kt @@ -4,7 +4,7 @@ import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializ import dev.inmo.tgbotapi.types.emailField import dev.inmo.tgbotapi.types.hashField import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash -import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.WithEmail +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithEmail import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -15,5 +15,4 @@ data class Email( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : WithEmail { -} \ No newline at end of file +) : EncryptedPassportElementWithEmail diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt index 6bb91ac32d..3e3f1d2010 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedAddress.kt @@ -4,7 +4,7 @@ import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializ import dev.inmo.tgbotapi.types.dataField import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash -import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.WithData +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -15,4 +15,4 @@ data class EncryptedAddress( override val data: EncryptedData, @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : WithData +) : EncryptedPassportElementWithData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableFilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPassportElementWithTranslatableFilesCollection.kt similarity index 81% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableFilesCollection.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPassportElementWithTranslatableFilesCollection.kt index 377aad5ce2..00ecd47924 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableFilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPassportElementWithTranslatableFilesCollection.kt @@ -7,7 +7,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -sealed class TranslatableFilesCollection : Translatable, FilesCollection +sealed class EncryptedPassportElementWithTranslatableFilesCollection : EncryptedPassportElementTranslatable, EncryptedPassportElementWithFilesCollection @Serializable data class UtilityBill( @@ -18,7 +18,7 @@ data class UtilityBill( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : TranslatableFilesCollection() +) : EncryptedPassportElementWithTranslatableFilesCollection() @Serializable data class BankStatement( @SerialName(filesField) @@ -28,7 +28,7 @@ data class BankStatement( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : TranslatableFilesCollection() +) : EncryptedPassportElementWithTranslatableFilesCollection() @Serializable data class RentalAgreement( @SerialName(filesField) @@ -38,7 +38,7 @@ data class RentalAgreement( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : TranslatableFilesCollection() +) : EncryptedPassportElementWithTranslatableFilesCollection() @Serializable data class PassportRegistration( @SerialName(filesField) @@ -48,7 +48,7 @@ data class PassportRegistration( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : TranslatableFilesCollection() +) : EncryptedPassportElementWithTranslatableFilesCollection() @Serializable data class TemporaryRegistration( @SerialName(filesField) @@ -58,5 +58,5 @@ data class TemporaryRegistration( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : TranslatableFilesCollection() +) : EncryptedPassportElementWithTranslatableFilesCollection() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableIDDocument.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPassportElementWithTranslatableIDDocument.kt similarity index 82% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableIDDocument.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPassportElementWithTranslatableIDDocument.kt index e20de95245..02d587e8bc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/TranslatableIDDocument.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPassportElementWithTranslatableIDDocument.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -sealed class TranslatableIDDocument : WithData, WithFrontSide, WithReverseSide, WithSelfie, Translatable +sealed class EncryptedPassportElementWithTranslatableIDDocument : EncryptedPassportElementWithData, EncryptedPassportElementWithFrontSide, EncryptedPassportElementWithReverseSide, EncryptedPassportElementWithSelfie, EncryptedPassportElementTranslatable @Serializable data class DriverLicense( @@ -26,7 +26,7 @@ data class DriverLicense( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : TranslatableIDDocument() +) : EncryptedPassportElementWithTranslatableIDDocument() @Serializable data class IdentityCard( @@ -44,4 +44,4 @@ data class IdentityCard( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : TranslatableIDDocument() +) : EncryptedPassportElementWithTranslatableIDDocument() diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt index 3e79d2370d..fe1142a7e4 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/EncryptedPersonalDetails.kt @@ -4,7 +4,7 @@ import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializ import dev.inmo.tgbotapi.types.dataField import dev.inmo.tgbotapi.types.passport.credentials.EncryptedData import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash -import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.WithData +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithData import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -15,4 +15,4 @@ data class EncryptedPersonalDetails( override val data: EncryptedData, @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : WithData +) : EncryptedPassportElementWithData diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Passport.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Passport.kt index c23fb1857f..e79bcb017c 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Passport.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/Passport.kt @@ -8,7 +8,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -sealed class Passport : WithData, WithFrontSide, WithSelfie, Translatable +sealed class Passport : EncryptedPassportElementWithData, EncryptedPassportElementWithFrontSide, EncryptedPassportElementWithSelfie, EncryptedPassportElementTranslatable @Serializable data class CommonPassport( diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt index 3d70962190..88dc723765 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/PhoneNumber.kt @@ -3,7 +3,7 @@ package dev.inmo.tgbotapi.types.passport.encrypted import dev.inmo.micro_utils.serialization.base64.Base64BytesToFromStringSerializer import dev.inmo.tgbotapi.types.hashField import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.PassportElementHash -import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.WithPhoneNumber +import dev.inmo.tgbotapi.types.passport.encrypted.abstracts.EncryptedPassportElementWithPhoneNumber import dev.inmo.tgbotapi.types.phoneNumberField import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -15,5 +15,4 @@ data class PhoneNumber( @SerialName(hashField) @Serializable(Base64BytesToFromStringSerializer::class) override val hash: PassportElementHash -) : WithPhoneNumber { -} \ No newline at end of file +) : EncryptedPassportElementWithPhoneNumber diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/Translatable.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementTranslatable.kt similarity index 81% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/Translatable.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementTranslatable.kt index c538e91d17..32c3a2af89 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/Translatable.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementTranslatable.kt @@ -5,6 +5,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -interface Translatable : EncryptedPassportElement { +interface EncryptedPassportElementTranslatable : EncryptedPassportElement { val translations: List } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithData.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithData.kt similarity index 81% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithData.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithData.kt index 9e464fec51..9332b22b0d 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithData.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithData.kt @@ -5,6 +5,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -interface WithData : EncryptedPassportElement { +interface EncryptedPassportElementWithData : EncryptedPassportElement { val data: EncryptedData } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithEmail.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithEmail.kt similarity index 77% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithEmail.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithEmail.kt index 0442d15771..e0ddcca903 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithEmail.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithEmail.kt @@ -4,6 +4,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -interface WithEmail : EncryptedPassportElement { +interface EncryptedPassportElementWithEmail : EncryptedPassportElement { val email: String } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/FilesCollection.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithFilesCollection.kt similarity index 79% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/FilesCollection.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithFilesCollection.kt index bf50a864b2..e9edc842e5 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/FilesCollection.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithFilesCollection.kt @@ -5,6 +5,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -interface FilesCollection : EncryptedPassportElement { +interface EncryptedPassportElementWithFilesCollection : EncryptedPassportElement { val files: List } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithFrontSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithFrontSide.kt similarity index 80% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithFrontSide.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithFrontSide.kt index 396ef60aea..dbce257cd9 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithFrontSide.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithFrontSide.kt @@ -5,6 +5,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -interface WithFrontSide : EncryptedPassportElement { +interface EncryptedPassportElementWithFrontSide : EncryptedPassportElement { val frontSide: PassportFile? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithPhoneNumber.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithPhoneNumber.kt similarity index 76% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithPhoneNumber.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithPhoneNumber.kt index 9181eba0e4..59e4939925 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithPhoneNumber.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithPhoneNumber.kt @@ -4,6 +4,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.EncryptedElementSerializer import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -interface WithPhoneNumber : EncryptedPassportElement { +interface EncryptedPassportElementWithPhoneNumber : EncryptedPassportElement { val phoneNumber: String } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithReverseSide.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithReverseSide.kt similarity index 80% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithReverseSide.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithReverseSide.kt index 47d443c3ec..24bf4f1874 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithReverseSide.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithReverseSide.kt @@ -5,6 +5,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -interface WithReverseSide : EncryptedPassportElement { +interface EncryptedPassportElementWithReverseSide : EncryptedPassportElement { val reverseSide: PassportFile? } \ No newline at end of file diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithSelfie.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithSelfie.kt similarity index 81% rename from tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithSelfie.kt rename to tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithSelfie.kt index 6928c2c311..d36de7e9cc 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/WithSelfie.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/types/passport/encrypted/abstracts/EncryptedPassportElementWithSelfie.kt @@ -5,6 +5,6 @@ import dev.inmo.tgbotapi.types.passport.encrypted.PassportFile import kotlinx.serialization.Serializable @Serializable(EncryptedElementSerializer::class) -interface WithSelfie : EncryptedPassportElement { +interface EncryptedPassportElementWithSelfie : EncryptedPassportElement { val selfie: PassportFile? } \ No newline at end of file diff --git a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt index b2f24fd9b9..b9ec7bb441 100644 --- a/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt +++ b/tgbotapi.extensions.utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/ClassCasts.kt @@ -269,53 +269,53 @@ inline fun EncryptedPassportElement.asTemporaryRegistration(): TemporaryRegistra @PreviewFeature inline fun EncryptedPassportElement.requireTemporaryRegistration(): TemporaryRegistration = this as TemporaryRegistration @PreviewFeature -inline fun EncryptedPassportElement.asTranslatableFilesCollection(): TranslatableFilesCollection? = this as? TranslatableFilesCollection +inline fun EncryptedPassportElement.asEncryptedPassportElementWithTranslatableFilesCollection(): EncryptedPassportElementWithTranslatableFilesCollection? = this as? EncryptedPassportElementWithTranslatableFilesCollection @PreviewFeature -inline fun EncryptedPassportElement.requireTranslatableFilesCollection(): TranslatableFilesCollection = this as TranslatableFilesCollection +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithTranslatableFilesCollection(): EncryptedPassportElementWithTranslatableFilesCollection = this as EncryptedPassportElementWithTranslatableFilesCollection @PreviewFeature -inline fun EncryptedPassportElement.asTranslatableIDDocument(): TranslatableIDDocument? = this as? TranslatableIDDocument +inline fun EncryptedPassportElement.asEncryptedPassportElementWithTranslatableIDDocument(): EncryptedPassportElementWithTranslatableIDDocument? = this as? EncryptedPassportElementWithTranslatableIDDocument @PreviewFeature -inline fun EncryptedPassportElement.requireTranslatableIDDocument(): TranslatableIDDocument = this as TranslatableIDDocument +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithTranslatableIDDocument(): EncryptedPassportElementWithTranslatableIDDocument = this as EncryptedPassportElementWithTranslatableIDDocument @PreviewFeature inline fun EncryptedPassportElement.asUtilityBill(): UtilityBill? = this as? UtilityBill @PreviewFeature inline fun EncryptedPassportElement.requireUtilityBill(): UtilityBill = this as UtilityBill @PreviewFeature -inline fun EncryptedPassportElement.asFilesCollection(): FilesCollection? = this as? FilesCollection +inline fun EncryptedPassportElement.asEncryptedPassportElementWithFilesCollection(): EncryptedPassportElementWithFilesCollection? = this as? EncryptedPassportElementWithFilesCollection @PreviewFeature -inline fun EncryptedPassportElement.requireFilesCollection(): FilesCollection = this as FilesCollection +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithFilesCollection(): EncryptedPassportElementWithFilesCollection = this as EncryptedPassportElementWithFilesCollection @PreviewFeature -inline fun EncryptedPassportElement.asTranslatable(): Translatable? = this as? Translatable +inline fun EncryptedPassportElement.asEncryptedPassportElementTranslatable(): EncryptedPassportElementTranslatable? = this as? EncryptedPassportElementTranslatable @PreviewFeature -inline fun EncryptedPassportElement.requireTranslatable(): Translatable = this as Translatable +inline fun EncryptedPassportElement.requireEncryptedPassportElementTranslatable(): EncryptedPassportElementTranslatable = this as EncryptedPassportElementTranslatable @PreviewFeature inline fun EncryptedPassportElement.asUnknownEncryptedPassportElement(): UnknownEncryptedPassportElement? = this as? UnknownEncryptedPassportElement @PreviewFeature inline fun EncryptedPassportElement.requireUnknownEncryptedPassportElement(): UnknownEncryptedPassportElement = this as UnknownEncryptedPassportElement @PreviewFeature -inline fun EncryptedPassportElement.asWithData(): WithData? = this as? WithData +inline fun EncryptedPassportElement.asEncryptedPassportElementWithData(): EncryptedPassportElementWithData? = this as? EncryptedPassportElementWithData @PreviewFeature -inline fun EncryptedPassportElement.requireWithData(): WithData = this as WithData +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithData(): EncryptedPassportElementWithData = this as EncryptedPassportElementWithData @PreviewFeature -inline fun EncryptedPassportElement.asWithEmail(): WithEmail? = this as? WithEmail +inline fun EncryptedPassportElement.asEncryptedPassportElementWithEmail(): EncryptedPassportElementWithEmail? = this as? EncryptedPassportElementWithEmail @PreviewFeature -inline fun EncryptedPassportElement.requireWithEmail(): WithEmail = this as WithEmail +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithEmail(): EncryptedPassportElementWithEmail = this as EncryptedPassportElementWithEmail @PreviewFeature -inline fun EncryptedPassportElement.asWithFrontSide(): WithFrontSide? = this as? WithFrontSide +inline fun EncryptedPassportElement.asEncryptedPassportElementWithFrontSide(): EncryptedPassportElementWithFrontSide? = this as? EncryptedPassportElementWithFrontSide @PreviewFeature -inline fun EncryptedPassportElement.requireWithFrontSide(): WithFrontSide = this as WithFrontSide +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithFrontSide(): EncryptedPassportElementWithFrontSide = this as EncryptedPassportElementWithFrontSide @PreviewFeature -inline fun EncryptedPassportElement.asWithPhoneNumber(): WithPhoneNumber? = this as? WithPhoneNumber +inline fun EncryptedPassportElement.asEncryptedPassportElementWithPhoneNumber(): EncryptedPassportElementWithPhoneNumber? = this as? EncryptedPassportElementWithPhoneNumber @PreviewFeature -inline fun EncryptedPassportElement.requireWithPhoneNumber(): WithPhoneNumber = this as WithPhoneNumber +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithPhoneNumber(): EncryptedPassportElementWithPhoneNumber = this as EncryptedPassportElementWithPhoneNumber @PreviewFeature -inline fun EncryptedPassportElement.asWithReverseSide(): WithReverseSide? = this as? WithReverseSide +inline fun EncryptedPassportElement.asEncryptedPassportElementWithReverseSide(): EncryptedPassportElementWithReverseSide? = this as? EncryptedPassportElementWithReverseSide @PreviewFeature -inline fun EncryptedPassportElement.requireWithReverseSide(): WithReverseSide = this as WithReverseSide +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithReverseSide(): EncryptedPassportElementWithReverseSide = this as EncryptedPassportElementWithReverseSide @PreviewFeature -inline fun EncryptedPassportElement.asWithSelfie(): WithSelfie? = this as? WithSelfie +inline fun EncryptedPassportElement.asEncryptedPassportElementWithSelfie(): EncryptedPassportElementWithSelfie? = this as? EncryptedPassportElementWithSelfie @PreviewFeature -inline fun EncryptedPassportElement.requireWithSelfie(): WithSelfie = this as WithSelfie +inline fun EncryptedPassportElement.requireEncryptedPassportElementWithSelfie(): EncryptedPassportElementWithSelfie = this as EncryptedPassportElementWithSelfie @PreviewFeature inline fun SecureValue.asAddressSecureValue(): AddressSecureValue? = this as? AddressSecureValue @PreviewFeature From ec0a10e36e030544a3387c8c5c8f0e186c020275 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 29 Jan 2021 13:28:18 +0600 Subject: [PATCH 43/43] fillup changelog --- CHANGELOG.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1203c11fb..74684b3d5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,16 @@ * Methods and types related to `MediaGroupMessage` have been modified according to their meanings * **Important Change** `FlowsUpdatesFilter` now is an interface. Old class has been renamed to `DefaultFlowsUpdatesFilter` and factory method `FlowsUpdatesFilter` has been added + * **PASSPORT** Full support of `Telegram Passport API` + * `PassportData` + * All variants of `EncryptedPassportElement` + * All variants of `SecureValue` + * All variants of `PassportElementError` + * New request `SetPassportDataErrors` + * `Credentials`: + * `EncryptedCredentials` + * `DeryptedCredentials` + * `EndDataCredentials` * `Behaviour Builder`: * Trigger and expectation extensions for `MessageContent` (`onContentMessage` and `waitContentMessage`) * `onMediaGroup` has been replaced @@ -21,6 +31,28 @@ * `onVisualMediaGroup` now is just an alternative to `onVisualGallery` * `command` and `onCommand` expectations has been added for commands `String` variant * New extensions `BehaviourContext#oneOf`, `BehaviourContext#parallel` and `Deferred#withAction` + * Several renames: + * `waitAudioMediaGroup` -> `waitAudioMediaGroupContent` + * `waitDocumentMediaGroup` -> `waitDocumentMediaGroupContent` + * `waitMediaGroup` -> `waitAnyMediaGroupContent` + * `waitVisualMediaGroup` -> `waitVisualMediaGroupContent` + * New extensions `BehaviourContext#waitPassportMessagesWith` and `BehaviourContext#waitAnyPassportMessages` + * New extensions `BehaviourContext#onPassportMessage` and `BehaviourContext#onPassportMessageWith` +* `Utils`: + * New `ClassCasts` for + * `Message` + * **PASSPORT** `EncryptedPassportElement` + * **PASSPORT** `PassportElementError` + * **PASSPORT** `SecureValue` + * Several tools for decryption have been added: + * `AESDecryptor` is available for `JVM` platform + * Extensions `EncryptedCredentials#decryptWithPKCS8PrivateKey` are available for `JVM` + platform + * Extensions `EndDataCredentials#decryptData` and `FileCredentials#decryptFile` have been added + * Several extensions `createDecryptor` + * Several extensions `doInDecryptionContextWithPKCS8Key` + * New extension `Flow#passportMessages` + * In most of webhook setting up functions/methods now available parameter `mediaGroupsDebounceTimeMillis` * `API`: * **PASSPORT** New extensions `TelegramBot#setPassportDataErrors`