Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.lightningkite.lightningserver.sessions.proofs.extensions

import com.lightningkite.lightningserver.runtime.ServerRuntime
import com.lightningkite.lightningserver.runtime.now
import com.lightningkite.lightningserver.sessions.proofs.Proof
import com.lightningkite.lightningserver.sessions.proofs.proofMethods
import kotlin.time.Duration.Companion.hours

context(_: ServerRuntime)
public val Proof.expired: Boolean get() = (expiresAt ?: (at + 1.hours)) < now()

context(server: ServerRuntime)
public suspend fun Proof.isValid(): Boolean =
server.proofMethods.find { it.info.via == via }?.verify(this) == true
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.lightningkite.lightningserver.sessions.proofs.*
import kotlinx.io.*
import kotlin.io.encoding.Base64
import kotlin.time.Duration
import kotlin.time.Duration.Companion.hours
import kotlin.time.Instant

private fun signingInfo(
Expand All @@ -23,10 +24,7 @@ private fun signingInfo(
writeString(value)
writeInt(strength)
writeLong(at.toEpochMilliseconds())
writeLong(
expiresAt?.toEpochMilliseconds()
?: throw IllegalStateException("expiredAt cannot be null for proof signature verification")
)
writeLong(expiresAt?.toEpochMilliseconds() ?: (at.plus(1.hours)).toEpochMilliseconds())
}
.readByteArray()

Expand Down
Loading