Skip to content

Commit

Permalink
More session token function
Browse files Browse the repository at this point in the history
  • Loading branch information
crossle committed Jun 16, 2022
1 parent c0747aa commit 57051de
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions library/src/main/kotlin/one/mixin/bot/SessionToken.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package one.mixin.bot

import net.i2p.crypto.eddsa.EdDSAPrivateKey
import one.mixin.bot.extension.base64Encode
import one.mixin.bot.vo.User
import java.security.Key
import java.security.KeyPair

sealed class SessionToken(open val userId: String, open val sessionId: String) {
data class RSA(
Expand All @@ -15,3 +19,14 @@ sealed class SessionToken(open val userId: String, open val sessionId: String) {
val seed: String
) : SessionToken(userId, sessionId)
}

fun getUserSessionToken(user: User, sessionKey: KeyPair, isRsa: Boolean = false): SessionToken {
return if (isRsa) {
SessionToken.RSA(user.userId, user.sessionId, sessionKey.private)
} else {
SessionToken.EdDSA(
user.userId, user.sessionId,
(sessionKey.private as EdDSAPrivateKey).seed.base64Encode()
)
}
}

0 comments on commit 57051de

Please sign in to comment.