-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
648 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,31 @@ | ||
# TODO | ||
# ktproto - Kotlin Library for MTProto Protocol | ||
|
||
⚠️ ALL OF THIS IS WORK IN PROGRESS ⚠️ | ||
|
||
`ktproto` is a Kotlin library designed to simplify working with Telegram's MTProto protocol. This library provides the tools you need to establish connections, perform authentication, and interact with the Telegram API using the MTProto protocol. | ||
|
||
## Features | ||
|
||
- Establish connections to Telegram's servers. | ||
- Interact with the Telegram API using MTProto protocol. | ||
- Built-in integration with TL (Maintained in a separate repo: https://github.com/kotlin-telegram/ktproto) | ||
|
||
## Usage | ||
|
||
```kotlin | ||
@OngoingConnection | ||
private suspend fun main(): Unit = weakCoroutineScope { | ||
val transport = openKtorSocketTransport( | ||
hostname = "149.154.167.51", | ||
port = 443 | ||
) | ||
val client = plainMTProtoClient( | ||
transport = transport, | ||
scope = this | ||
) | ||
repeat(10) { | ||
createAuthorizationKey(client, keys) | ||
} | ||
// Sending encrypted requests are not supported ATM | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ kotlin { | |
jvm { | ||
jvmToolchain(8) | ||
} | ||
js(IR) { | ||
js { | ||
browser() | ||
nodejs() | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ain/kotlin/kotl/client/ktor/DataCenter.kt → .../kotlin/ktproto/client/ktor/DataCenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../ktor/websocket/KtorWebsocketTransport.kt → .../ktor/websocket/KtorWebsocketTransport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...kotlin/kotl/client/ktor/DataCenter.ios.kt → ...lin/ktproto/client/ktor/DataCenter.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package kotl.client.ktor | ||
package ktproto.client.ktor | ||
|
||
internal actual fun isJS(): Boolean = false |
2 changes: 1 addition & 1 deletion
2
.../kotlin/kotl/client/ktor/DataCenter.js.kt → ...tlin/ktproto/client/ktor/DataCenter.js.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package kotl.client.ktor | ||
package ktproto.client.ktor | ||
|
||
internal actual fun isJS(): Boolean = true |
41 changes: 0 additions & 41 deletions
41
client/ktor/src/jvmMain/kotlin/kotl/client/ktor/ClientMain.kt
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
client/ktor/src/jvmMain/kotlin/ktproto/client/ktor/ClientMain.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package ktproto.client.ktor | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.plugins.logging.* | ||
import kotl.serialization.TL | ||
import kotl.serialization.bare.bare | ||
import kotl.serialization.bytes.Bytes | ||
import kotlinx.serialization.encodeToByteArray | ||
import ktproto.client.authorization.createAuthorizationKey | ||
import ktproto.client.ktor.socket.openKtorSocketTransport | ||
import ktproto.client.plain.plainMTProtoClient | ||
import ktproto.client.rsa.RsaPublicKey | ||
import ktproto.client.rsa.TLRsaPublicKey | ||
import ktproto.client.rsa.fingerprint | ||
import ktproto.io.annotation.OngoingConnection | ||
import ktproto.stdlib.scope.weakCoroutineScope | ||
|
||
private object DC : DataCenter { | ||
override val name: String = "pluto" | ||
override val isTest: Boolean = false | ||
} | ||
|
||
private val httpClient = HttpClient { | ||
Logging { | ||
level = LogLevel.ALL | ||
logger = object : Logger { | ||
override fun log(message: String) = println(message) | ||
} | ||
} | ||
} | ||
|
||
// Fingerprint: d09d1d85de64fd85 | ||
private val productionKey = RsaPublicKey(""" | ||
-----BEGIN RSA PUBLIC KEY----- | ||
MIIBCgKCAQEA6LszBcC1LGzyr992NzE0ieY+BSaOW622Aa9Bd4ZHLl+TuFQ4lo4g | ||
5nKaMBwK/BIb9xUfg0Q29/2mgIR6Zr9krM7HjuIcCzFvDtr+L0GQjae9H0pRB2OO | ||
62cECs5HKhT5DZ98K33vmWiLowc621dQuwKWSQKjWf50XYFw42h21P2KXUGyp2y/ | ||
+aEyZ+uVgLLQbRA1dEjSDZ2iGRy12Mk5gpYc397aYp438fsJoHIgJ2lgMv5h7WY9 | ||
t6N/byY9Nw9p21Og3AoXSL2q/2IJ1WRUhebgAdGVMlV1fkuOQoEzR7EdpqtQD9Cs | ||
5+bfo3Nhmcyvk5ftB0WkJ9z6bNZ7yxrP8wIDAQAB | ||
-----END RSA PUBLIC KEY----- | ||
""".trimIndent()) | ||
|
||
// Fingerprint: b25898df208d2603 | ||
private val testKey = RsaPublicKey(""" | ||
-----BEGIN RSA PUBLIC KEY----- | ||
MIIBCgKCAQEAyMEdY1aR+sCR3ZSJrtztKTKqigvO/vBfqACJLZtS7QMgCGXJ6XIR | ||
yy7mx66W0/sOFa7/1mAZtEoIokDP3ShoqF4fVNb6XeqgQfaUHd8wJpDWHcR2OFwv | ||
plUUI1PLTktZ9uW2WE23b+ixNwJjJGwBDJPQEQFBE+vfmH0JP503wr5INS1poWg/ | ||
j25sIWeYPHYeOrFp/eXaqhISP6G+q2IeTaWTXpwZj4LzXq5YOpk4bYEQ6mvRq7D1 | ||
aHWfYmlEGepfaYR8Q0YqvvhYtMte3ITnuSJs171+GDqpdKcSwHnd6FudwGO4pcCO | ||
j4WcDuXc2CTHgH8gFTNhp/Y8/SpDOhvn9QIDAQAB | ||
-----END RSA PUBLIC KEY----- | ||
""".trimIndent()) | ||
|
||
private val keys = listOf(productionKey, testKey) | ||
|
||
@OngoingConnection | ||
private suspend fun main(): Unit = weakCoroutineScope { | ||
val transport = openKtorSocketTransport( | ||
hostname = "149.154.167.51", | ||
port = 443 | ||
) | ||
val client = plainMTProtoClient( | ||
transport = transport, | ||
scope = this | ||
) | ||
repeat(10) { | ||
createAuthorizationKey(client, keys) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...kotlin/kotl/client/ktor/DataCenter.jvm.kt → ...lin/ktproto/client/ktor/DataCenter.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package kotl.client.ktor | ||
package ktproto.client.ktor | ||
|
||
internal actual fun isJS(): Boolean = false |
2 changes: 1 addition & 1 deletion
2
...client/ktor/socket/KtorSocketTransport.kt → ...client/ktor/socket/KtorSocketTransport.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package ktproto.client | ||
|
||
import kotl.core.descriptor.TLExpressionDescriptor | ||
import kotl.core.element.TLExpression | ||
import kotl.core.element.TLFunction | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
public interface MTProtoClient { | ||
public val updates: Flow<TLExpression> | ||
public suspend fun execute(request: MTProtoRequest): TLExpression | ||
|
||
public suspend fun execute( | ||
function: TLFunction, | ||
responseDescriptor: TLExpressionDescriptor | ||
): TLExpression | ||
} |
9 changes: 0 additions & 9 deletions
9
client/src/commonMain/kotlin/ktproto/client/MTProtoRequest.kt
This file was deleted.
Oops, something went wrong.
51 changes: 44 additions & 7 deletions
51
client/src/commonMain/kotlin/ktproto/client/authorization/CreateAuthorizationKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.