diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3c93b430..734b0018 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,43 +10,9 @@ jobs: matrix: include: - os: macos-latest - gradle_args: publishIosX64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishIosArm64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishIosSimulatorArm64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishTvosX64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishTvosArm64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishTvosSimulatorArm64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishTvosSimulatorArm64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishWatchosArm32PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishWatchosArm64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishWatchosX64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishWatchosSimulatorArm64PublicationToSonatypeRepository - - - os: macos-latest - gradle_args: publishMacosX64PublicationToSonatypeRepository - - os: macos-latest - gradle_args: publishMacosArm64PublicationToSonatypeRepository - - - os: ubuntu-latest - gradle_args: publishKotlinMultiplatformPublicationToSonatypeRepository - - os: ubuntu-latest - gradle_args: jvmTest publishJvmPublicationToSonatypeRepository - - os: ubuntu-latest - gradle_args: publishLinuxX64PublicationToSonatypeRepository - - os: ubuntu-latest - gradle_args: publishArmX64PublicationToSonatypeRepository + gradle_args: publishIosX64PublicationToSonatypeRepository publishIosArm64PublicationToSonatypeRepository publishIosSimulatorArm64PublicationToSonatypeRepository publishTvosX64PublicationToSonatypeRepository publishTvosArm64PublicationToSonatypeRepository publishTvosSimulatorArm64PublicationToSonatypeRepository publishTvosSimulatorArm64PublicationToSonatypeRepository publishWatchosArm32PublicationToSonatypeRepository publishWatchosArm64PublicationToSonatypeRepository publishWatchosX64PublicationToSonatypeRepository publishWatchosSimulatorArm64PublicationToSonatypeRepository publishMacosX64PublicationToSonatypeRepository publishMacosArm64PublicationToSonatypeRepository - os: ubuntu-latest - gradle_args: publishMingwX64PublicationToSonatypeRepository + gradle_args: publishKotlinMultiplatformPublicationToSonatypeRepository publishJvmPublicationToSonatypeRepository publishLinuxX64PublicationToSonatypeRepository publishArm64PublicationToSonatypeRepository publishMingwX64PublicationToSonatypeRepository runs-on: ${{ matrix.os }} steps: diff --git a/tl/src/TlCombinator.kt b/tl/src/TlCombinator.kt index 8a7e6500..b44be8e9 100644 --- a/tl/src/TlCombinator.kt +++ b/tl/src/TlCombinator.kt @@ -11,18 +11,17 @@ public abstract class TlCombinator private constructor( constructors.toList() ) - private val class2Constructor: Map, TlCodec> - private val id2Constructor: Map> - - init { - class2Constructor = constructors.toMap() - id2Constructor = class2Constructor.entries.groupingBy { it.value.id } + private val class2Constructor: Map, TlConstructor> = constructors.toMap() + private val id2Constructor: Map> by lazy { + class2Constructor.entries + .groupingBy { it.value.id } .aggregate, TlConstructor>, Int, Map.Entry, TlConstructor>> { _, accumulator, element, _ -> if (accumulator != null) { throw IllegalArgumentException("Duplicate ID: ${element.key}") } element - }.mapValues { it.value.value } + } + .mapValues { it.value.value } } override fun findConstructorOrNull(id: Int): TlDecoder? = id2Constructor[id] diff --git a/tl/src/TlConstructor.kt b/tl/src/TlConstructor.kt index c2ccc118..a8f13ecc 100644 --- a/tl/src/TlConstructor.kt +++ b/tl/src/TlConstructor.kt @@ -14,9 +14,7 @@ public abstract class TlConstructor( .replace(")", "") .replace(";", "") } - public val id: Int by lazy(LazyThreadSafetyMode.PUBLICATION) { - id ?: crc32(this.schema.toByteArray()) - } + public val id: Int = id ?: crc32(this.schema.toByteArray()) override fun encodeBoxed(writer: TlWriter, value: T) { writer.writeInt(id) diff --git a/tonapi-tl/api/ton-kotlin-tonapi-tl.api b/tonapi-tl/api/ton-kotlin-tonapi-tl.api index 15d0aa5a..6cebc42b 100644 --- a/tonapi-tl/api/ton-kotlin-tonapi-tl.api +++ b/tonapi-tl/api/ton-kotlin-tonapi-tl.api @@ -2113,39 +2113,13 @@ public final class org/ton/api/pk/PrivateKeyEd25519 : org/ton/api/pk/PrivateKey, public fun toString ()Ljava/lang/String; } -public final class org/ton/api/pk/PrivateKeyEd25519$Companion : org/ton/tl/TlCodec { - public synthetic fun decode (Lio/ktor/utils/io/core/Input;)Ljava/lang/Object; - public fun decode (Lio/ktor/utils/io/core/Input;)Lorg/ton/api/pk/PrivateKeyEd25519; - public synthetic fun decode (Lorg/ton/tl/ByteString;)Ljava/lang/Object; - public fun decode (Lorg/ton/tl/ByteString;)Lorg/ton/api/pk/PrivateKeyEd25519; +public final class org/ton/api/pk/PrivateKeyEd25519$Companion : org/ton/tl/TlConstructor { public synthetic fun decode (Lorg/ton/tl/TlReader;)Ljava/lang/Object; public fun decode (Lorg/ton/tl/TlReader;)Lorg/ton/api/pk/PrivateKeyEd25519; - public synthetic fun decode ([B)Ljava/lang/Object; - public fun decode ([B)Lorg/ton/api/pk/PrivateKeyEd25519; - public synthetic fun decodeBoxed (Lio/ktor/utils/io/core/Input;)Ljava/lang/Object; - public fun decodeBoxed (Lio/ktor/utils/io/core/Input;)Lorg/ton/api/pk/PrivateKeyEd25519; - public synthetic fun decodeBoxed (Lorg/ton/tl/ByteString;)Ljava/lang/Object; - public fun decodeBoxed (Lorg/ton/tl/ByteString;)Lorg/ton/api/pk/PrivateKeyEd25519; - public synthetic fun decodeBoxed (Lorg/ton/tl/TlReader;)Ljava/lang/Object; - public fun decodeBoxed (Lorg/ton/tl/TlReader;)Lorg/ton/api/pk/PrivateKeyEd25519; - public synthetic fun decodeBoxed ([B)Ljava/lang/Object; - public fun decodeBoxed ([B)Lorg/ton/api/pk/PrivateKeyEd25519; - public synthetic fun encode (Lio/ktor/utils/io/core/Output;Ljava/lang/Object;)V - public fun encode (Lio/ktor/utils/io/core/Output;Lorg/ton/api/pk/PrivateKeyEd25519;)V public synthetic fun encode (Lorg/ton/tl/TlWriter;Ljava/lang/Object;)V public fun encode (Lorg/ton/tl/TlWriter;Lorg/ton/api/pk/PrivateKeyEd25519;)V - public synthetic fun encodeBoxed (Lio/ktor/utils/io/core/Output;Ljava/lang/Object;)V - public fun encodeBoxed (Lio/ktor/utils/io/core/Output;Lorg/ton/api/pk/PrivateKeyEd25519;)V - public synthetic fun encodeBoxed (Lorg/ton/tl/TlWriter;Ljava/lang/Object;)V - public fun encodeBoxed (Lorg/ton/tl/TlWriter;Lorg/ton/api/pk/PrivateKeyEd25519;)V - public synthetic fun encodeToByteArray (Ljava/lang/Object;Z)[B - public fun encodeToByteArray (Lorg/ton/api/pk/PrivateKeyEd25519;Z)[B - public synthetic fun encodeToByteString (Ljava/lang/Object;Z)Lorg/ton/tl/ByteString; - public fun encodeToByteString (Lorg/ton/api/pk/PrivateKeyEd25519;Z)Lorg/ton/tl/ByteString; public final fun generate (Lkotlin/random/Random;)Lorg/ton/api/pk/PrivateKeyEd25519; public static synthetic fun generate$default (Lorg/ton/api/pk/PrivateKeyEd25519$Companion;Lkotlin/random/Random;ILjava/lang/Object;)Lorg/ton/api/pk/PrivateKeyEd25519; - public synthetic fun hash (Ljava/lang/Object;)[B - public fun hash (Lorg/ton/api/pk/PrivateKeyEd25519;)[B public final fun of ([B)Lorg/ton/api/pk/PrivateKeyEd25519; public final fun tlConstructor ()Lorg/ton/tl/TlConstructor; } @@ -2243,45 +2217,17 @@ public final class org/ton/api/pub/PublicKeyEd25519 : org/ton/api/pub/PublicKey, public final fun getKey ()Lorg/ton/tl/ByteString; public fun hashCode ()I public static final fun of (Lorg/ton/api/pk/PrivateKeyEd25519;)Lorg/ton/api/pub/PublicKeyEd25519; - public static final fun tlConstructor ()Lorg/ton/tl/TlConstructor; public fun toAdnlIdShort ()Lorg/ton/api/adnl/AdnlIdShort; public fun toString ()Ljava/lang/String; public fun verify ([B[B)Z } -public final class org/ton/api/pub/PublicKeyEd25519$Companion : org/ton/tl/TlCodec { - public synthetic fun decode (Lio/ktor/utils/io/core/Input;)Ljava/lang/Object; - public fun decode (Lio/ktor/utils/io/core/Input;)Lorg/ton/api/pub/PublicKeyEd25519; - public synthetic fun decode (Lorg/ton/tl/ByteString;)Ljava/lang/Object; - public fun decode (Lorg/ton/tl/ByteString;)Lorg/ton/api/pub/PublicKeyEd25519; +public final class org/ton/api/pub/PublicKeyEd25519$Companion : org/ton/tl/TlConstructor { public synthetic fun decode (Lorg/ton/tl/TlReader;)Ljava/lang/Object; public fun decode (Lorg/ton/tl/TlReader;)Lorg/ton/api/pub/PublicKeyEd25519; - public synthetic fun decode ([B)Ljava/lang/Object; - public fun decode ([B)Lorg/ton/api/pub/PublicKeyEd25519; - public synthetic fun decodeBoxed (Lio/ktor/utils/io/core/Input;)Ljava/lang/Object; - public fun decodeBoxed (Lio/ktor/utils/io/core/Input;)Lorg/ton/api/pub/PublicKeyEd25519; - public synthetic fun decodeBoxed (Lorg/ton/tl/ByteString;)Ljava/lang/Object; - public fun decodeBoxed (Lorg/ton/tl/ByteString;)Lorg/ton/api/pub/PublicKeyEd25519; - public synthetic fun decodeBoxed (Lorg/ton/tl/TlReader;)Ljava/lang/Object; - public fun decodeBoxed (Lorg/ton/tl/TlReader;)Lorg/ton/api/pub/PublicKeyEd25519; - public synthetic fun decodeBoxed ([B)Ljava/lang/Object; - public fun decodeBoxed ([B)Lorg/ton/api/pub/PublicKeyEd25519; - public synthetic fun encode (Lio/ktor/utils/io/core/Output;Ljava/lang/Object;)V - public fun encode (Lio/ktor/utils/io/core/Output;Lorg/ton/api/pub/PublicKeyEd25519;)V public synthetic fun encode (Lorg/ton/tl/TlWriter;Ljava/lang/Object;)V public fun encode (Lorg/ton/tl/TlWriter;Lorg/ton/api/pub/PublicKeyEd25519;)V - public synthetic fun encodeBoxed (Lio/ktor/utils/io/core/Output;Ljava/lang/Object;)V - public fun encodeBoxed (Lio/ktor/utils/io/core/Output;Lorg/ton/api/pub/PublicKeyEd25519;)V - public synthetic fun encodeBoxed (Lorg/ton/tl/TlWriter;Ljava/lang/Object;)V - public fun encodeBoxed (Lorg/ton/tl/TlWriter;Lorg/ton/api/pub/PublicKeyEd25519;)V - public synthetic fun encodeToByteArray (Ljava/lang/Object;Z)[B - public fun encodeToByteArray (Lorg/ton/api/pub/PublicKeyEd25519;Z)[B - public synthetic fun encodeToByteString (Ljava/lang/Object;Z)Lorg/ton/tl/ByteString; - public fun encodeToByteString (Lorg/ton/api/pub/PublicKeyEd25519;Z)Lorg/ton/tl/ByteString; - public synthetic fun hash (Ljava/lang/Object;)[B - public fun hash (Lorg/ton/api/pub/PublicKeyEd25519;)[B public final fun of (Lorg/ton/api/pk/PrivateKeyEd25519;)Lorg/ton/api/pub/PublicKeyEd25519; - public final fun tlConstructor ()Lorg/ton/tl/TlConstructor; } public final class org/ton/api/pub/PublicKeyOverlay : org/ton/api/pub/PublicKey, org/ton/crypto/Encryptor { diff --git a/tonapi-tl/src/pk/ed25519.kt b/tonapi-tl/src/pk/ed25519.kt index 0b10a06c..ad442574 100644 --- a/tonapi-tl/src/pk/ed25519.kt +++ b/tonapi-tl/src/pk/ed25519.kt @@ -38,9 +38,11 @@ public data class PrivateKeyEd25519( public fun sharedKey(publicKey: PublicKeyEd25519): ByteArray = Ed25519.sharedKey(key.toByteArray(), publicKey.key.toByteArray()) - public companion object : TlCodec by PrivateKeyEd25519TlConstructor { + public companion object : TlConstructor( + schema = "pk.ed25519 key:int256 = PrivateKey" + ) { @JvmStatic - public fun tlConstructor(): TlConstructor = PrivateKeyEd25519TlConstructor + public fun tlConstructor(): TlConstructor = this @JvmStatic public fun generate(random: Random = SecureRandom): PrivateKeyEd25519 = @@ -53,6 +55,15 @@ public data class PrivateKeyEd25519( Ed25519.KEY_SIZE_BYTES + Int.SIZE_BYTES -> decodeBoxed(byteArray) else -> throw IllegalArgumentException("Invalid key size: ${byteArray.size}") } + + public override fun encode(writer: TlWriter, value: PrivateKeyEd25519) { + writer.writeRaw(value.key) + } + + public override fun decode(reader: TlReader): PrivateKeyEd25519 { + val key = reader.readByteString(32) + return PrivateKeyEd25519(key) + } } override fun decrypt(data: ByteArray): ByteArray = @@ -61,16 +72,3 @@ public data class PrivateKeyEd25519( override fun sign(message: ByteArray): ByteArray = _decryptor.sign(message) } - -private object PrivateKeyEd25519TlConstructor : TlConstructor( - schema = "pk.ed25519 key:int256 = PrivateKey" -) { - override fun encode(writer: TlWriter, value: PrivateKeyEd25519) { - writer.writeRaw(value.key) - } - - override fun decode(reader: TlReader): PrivateKeyEd25519 { - val key = reader.readByteString(32) - return PrivateKeyEd25519(key) - } -} diff --git a/tonapi-tl/src/pk/pk.kt b/tonapi-tl/src/pk/pk.kt index 22ecde8a..be068009 100644 --- a/tonapi-tl/src/pk/pk.kt +++ b/tonapi-tl/src/pk/pk.kt @@ -16,7 +16,7 @@ public sealed interface PrivateKey : Decryptor { public companion object : TlCombinator( PrivateKey::class, PrivateKeyUnencrypted::class to PrivateKeyUnencrypted, - PrivateKeyEd25519::class to PrivateKeyEd25519.tlConstructor(), + PrivateKeyEd25519::class to PrivateKeyEd25519, PrivateKeyAes::class to PrivateKeyAes, PrivateKeyOverlay::class to PrivateKeyOverlay, ) diff --git a/tonapi-tl/src/pub/ed25519.kt b/tonapi-tl/src/pub/ed25519.kt index 39a56151..82e7a556 100644 --- a/tonapi-tl/src/pub/ed25519.kt +++ b/tonapi-tl/src/pub/ed25519.kt @@ -33,13 +33,21 @@ public data class PublicKeyEd25519( override fun toAdnlIdShort(): AdnlIdShort = _adnlIdShort - public companion object : TlCodec by PublicKeyEd25519TlConstructor { - @JvmStatic - public fun tlConstructor(): TlConstructor = PublicKeyEd25519TlConstructor - + public companion object : TlConstructor( + schema = "pub.ed25519 key:int256 = PublicKey", + ) { @JvmStatic public fun of(privateKey: PrivateKeyEd25519): PublicKeyEd25519 = PublicKeyEd25519(Ed25519.publicKey(privateKey.key.toByteArray()).asByteString()) + + override fun encode(writer: TlWriter, value: PublicKeyEd25519) { + writer.writeRaw(value.key) + } + + override fun decode(reader: TlReader): PublicKeyEd25519 { + val key = reader.readByteString(32) + return PublicKeyEd25519(key) + } } override fun encrypt(data: ByteArray): ByteArray = @@ -48,16 +56,3 @@ public data class PublicKeyEd25519( override fun verify(message: ByteArray, signature: ByteArray?): Boolean = _encryptor.verify(message, signature) } - -private object PublicKeyEd25519TlConstructor : TlConstructor( - schema = "pub.ed25519 key:int256 = PublicKey", -) { - override fun encode(writer: TlWriter, value: PublicKeyEd25519) { - writer.writeRaw(value.key) - } - - override fun decode(reader: TlReader): PublicKeyEd25519 { - val key = reader.readByteString(32) - return PublicKeyEd25519(key) - } -} diff --git a/tonapi-tl/src/pub/pub.kt b/tonapi-tl/src/pub/pub.kt index d9be9016..ed861a44 100644 --- a/tonapi-tl/src/pub/pub.kt +++ b/tonapi-tl/src/pub/pub.kt @@ -23,7 +23,7 @@ public sealed interface PublicKey : Encryptor, TlObject { public companion object : TlCombinator( PublicKey::class, - PublicKeyEd25519::class to PublicKeyEd25519.tlConstructor(), + PublicKeyEd25519::class to PublicKeyEd25519, PublicKeyUnencrypted::class to PublicKeyUnencrypted, PublicKeyAes::class to PublicKeyAes, PublicKeyOverlay::class to PublicKeyOverlay,