Fork Aux to make Torch

This commit is contained in:
Kgothatso Ngako committed 2026-06-17 18:10:06 +03:00
1 parent 3df0b9ba4c
commit bad1b0eb31
343 files changed
+2747 -3382

No files matched your search

@@ -0,0 +1,71 @@
package at.torch.compose.extensions
import at.torch.compose.exceptions.InvalidNostrPrivateKeyException
import co.touchlab.kermit.Logger
import com.vitorpamplona.quartz.nip19Bech32.bech32.Bech32
import fr.acinq.bitcoin.PrivateKey
import fr.acinq.secp256k1.Hex
import io.ktor.utils.io.core.toByteArray
fun String.assureValidNsec() = if (startsWith("nsec")) this else this.hexToNsecHrp()
fun String.assureValidNpub() = if (startsWith("npub")) this else this.hexToNpubHrp()
fun String.assureValidPubKeyHex() = if (startsWith("npub")) this.bech32ToHexOrThrow() else this
fun String.hexToNoteHrp() =
Bech32.encodeBytes(
hrp = "note",
data = Hex.decode(this),
encoding = Bech32.Encoding.Bech32,
)
fun String.hexToNpubHrp() =
Bech32.encodeBytes(
hrp = "npub",
data = Hex.decode(this),
encoding = Bech32.Encoding.Bech32,
)
fun String.hexToNsecHrp() =
Bech32.encodeBytes(
hrp = "nsec",
data = Hex.decode(this),
encoding = Bech32.Encoding.Bech32,
)
fun String.urlToLnUrlHrp() =
Bech32.encodeBytes(
hrp = "lnurl",
data = this.toByteArray(),
encoding = Bech32.Encoding.Bech32,
)
fun String.bech32ToHexOrThrow() = Bech32.decodeBytes(bech32 = this).second.toHex()
fun String.bech32ToHexOrNull() = runCatching { this.bech32ToHexOrThrow() }.getOrNull()
fun ByteArray.toNpub() = Bech32.encodeBytes(hrp = "npub", this, Bech32.Encoding.Bech32)
@OptIn(ExperimentalStdlibApi::class)
fun ByteArray.toHex() = Hex.encode(this)
@Throws(IllegalArgumentException::class)
fun String.bechToBytesOrThrow(hrp: String? = null): ByteArray {
val decodedForm = Bech32.decodeBytes(this)
hrp?.also { require(it == decodedForm.first) }
return decodedForm.second
}
fun String.extractKeyPairFromPrivateKeyOrThrow(): Pair<String, String> {
return try {
val nsec = this.assureValidNsec()
val decoded = Bech32.decodeBytes(nsec)
val pubkey = PrivateKey(decoded.second).publicKey().value.toByteArray()
nsec to pubkey.toNpub()
} catch (error: IllegalArgumentException) {
Logger.withTag("String.extractKeyPairFromPrivateKeyOrThrow").w(error) { error.message ?: "" }
throw _root_ide_package_.ac.cord.compose.exceptions.InvalidNostrPrivateKeyException()
}
}
@@ -0,0 +1,29 @@
package at.torch.compose.extensions
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.TimeZone
import kotlinx.datetime.format
import kotlinx.datetime.format.MonthNames
import kotlinx.datetime.format.char
import kotlinx.datetime.toLocalDateTime
import kotlin.time.Instant
fun Instant.toFormattedTimeAndDateString(): String {
return toLocalDateTime(TimeZone.currentSystemDefault()).format(
LocalDateTime.Format {
hour()
char(':')
minute()
char(' ')
day()
char(' ')
monthName(
MonthNames.ENGLISH_ABBREVIATED
)
char(' ')
year()
}
)
}
@@ -0,0 +1,15 @@
package at.torch.compose.extensions
import fr.acinq.phoenix.PhoenixGlobal
import fr.acinq.phoenix.data.StartBusinessResult
import fr.acinq.phoenix.utils.preferences.GlobalPrefs
import kotlinx.coroutines.flow.Flow
expect suspend fun platformStartupLogic(words: List<String>): StartBusinessResult
expect fun schedulePlatformLogic(phoenixGlobal: PhoenixGlobal)
expect fun getShowIntroFlow(phoenixGlobal: PhoenixGlobal): Flow<Boolean>
expect fun getGlobalPrefs(phoenixGlobal: PhoenixGlobal): GlobalPrefs