Sign announcements (#267)

* wip

* announcements WIP

* works

* restore mainnet
This commit is contained in:
callebtc
2025-08-20 13:24:52 +02:00
committed by GitHub
parent 4acfafb998
commit c5a3368b9f
7 changed files with 501 additions and 41 deletions
@@ -56,7 +56,7 @@ data class BitchatPacket(
val recipientID: ByteArray? = null,
val timestamp: ULong,
val payload: ByteArray,
val signature: ByteArray? = null,
var signature: ByteArray? = null, // Changed from val to var for packet signing
var ttl: UByte
) : Parcelable {
@@ -80,6 +80,26 @@ data class BitchatPacket(
return BinaryProtocol.encode(this)
}
/**
* Create binary representation for signing (without signature and TTL fields)
* TTL is excluded because it changes during packet relay operations
*/
fun toBinaryDataForSigning(): ByteArray? {
// Create a copy without signature and with fixed TTL for signing
// TTL must be excluded because it changes during relay
val unsignedPacket = BitchatPacket(
version = version,
type = type,
senderID = senderID,
recipientID = recipientID,
timestamp = timestamp,
payload = payload,
signature = null, // Remove signature for signing
ttl = 0u // Use fixed TTL=0 for signing to ensure relay compatibility
)
return BinaryProtocol.encode(unsignedPacket)
}
companion object {
fun fromBinaryData(data: ByteArray): BitchatPacket? {
return BinaryProtocol.decode(data)