Skip to content

Commit

Permalink
fix publish
Browse files Browse the repository at this point in the history
  • Loading branch information
andreypfau committed Dec 12, 2023
1 parent b758ae2 commit 72cc163
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 136 deletions.
38 changes: 2 additions & 36 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 6 additions & 7 deletions tl/src/TlCombinator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,17 @@ public abstract class TlCombinator<T : Any> private constructor(
constructors.toList()
)

private val class2Constructor: Map<KClass<out T>, TlCodec<out T>>
private val id2Constructor: Map<Int, TlCodec<out T>>

init {
class2Constructor = constructors.toMap()
id2Constructor = class2Constructor.entries.groupingBy { it.value.id }
private val class2Constructor: Map<KClass<out T>, TlConstructor<out T>> = constructors.toMap()
private val id2Constructor: Map<Int, TlCodec<out T>> by lazy {
class2Constructor.entries
.groupingBy { it.value.id }
.aggregate<Map.Entry<KClass<out T>, TlConstructor<out T>>, Int, Map.Entry<KClass<*>, TlConstructor<out T>>> { _, 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<out T>? = id2Constructor[id]
Expand Down
4 changes: 1 addition & 3 deletions tl/src/TlConstructor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public abstract class TlConstructor<T : Any>(
.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)
Expand Down
58 changes: 2 additions & 56 deletions tonapi-tl/api/ton-kotlin-tonapi-tl.api
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 13 additions & 15 deletions tonapi-tl/src/pk/ed25519.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrivateKeyEd25519> by PrivateKeyEd25519TlConstructor {
public companion object : TlConstructor<PrivateKeyEd25519>(
schema = "pk.ed25519 key:int256 = PrivateKey"
) {
@JvmStatic
public fun tlConstructor(): TlConstructor<PrivateKeyEd25519> = PrivateKeyEd25519TlConstructor
public fun tlConstructor(): TlConstructor<PrivateKeyEd25519> = this

@JvmStatic
public fun generate(random: Random = SecureRandom): PrivateKeyEd25519 =
Expand All @@ -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 =
Expand All @@ -61,16 +72,3 @@ public data class PrivateKeyEd25519(
override fun sign(message: ByteArray): ByteArray =
_decryptor.sign(message)
}

private object PrivateKeyEd25519TlConstructor : TlConstructor<PrivateKeyEd25519>(
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)
}
}
2 changes: 1 addition & 1 deletion tonapi-tl/src/pk/pk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed interface PrivateKey : Decryptor {
public companion object : TlCombinator<PrivateKey>(
PrivateKey::class,
PrivateKeyUnencrypted::class to PrivateKeyUnencrypted,
PrivateKeyEd25519::class to PrivateKeyEd25519.tlConstructor(),
PrivateKeyEd25519::class to PrivateKeyEd25519,
PrivateKeyAes::class to PrivateKeyAes,
PrivateKeyOverlay::class to PrivateKeyOverlay,
)
Expand Down
29 changes: 12 additions & 17 deletions tonapi-tl/src/pub/ed25519.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,21 @@ public data class PublicKeyEd25519(

override fun toAdnlIdShort(): AdnlIdShort = _adnlIdShort

public companion object : TlCodec<PublicKeyEd25519> by PublicKeyEd25519TlConstructor {
@JvmStatic
public fun tlConstructor(): TlConstructor<PublicKeyEd25519> = PublicKeyEd25519TlConstructor

public companion object : TlConstructor<PublicKeyEd25519>(
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 =
Expand All @@ -48,16 +56,3 @@ public data class PublicKeyEd25519(
override fun verify(message: ByteArray, signature: ByteArray?): Boolean =
_encryptor.verify(message, signature)
}

private object PublicKeyEd25519TlConstructor : TlConstructor<PublicKeyEd25519>(
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)
}
}
2 changes: 1 addition & 1 deletion tonapi-tl/src/pub/pub.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public sealed interface PublicKey : Encryptor, TlObject<PublicKey> {

public companion object : TlCombinator<PublicKey>(
PublicKey::class,
PublicKeyEd25519::class to PublicKeyEd25519.tlConstructor(),
PublicKeyEd25519::class to PublicKeyEd25519,
PublicKeyUnencrypted::class to PublicKeyUnencrypted,
PublicKeyAes::class to PublicKeyAes,
PublicKeyOverlay::class to PublicKeyOverlay,
Expand Down

0 comments on commit 72cc163

Please sign in to comment.