Skip to content

Commit

Permalink
updated signature text
Browse files Browse the repository at this point in the history
Updated consent signature text
Added test
  • Loading branch information
Alex Risch authored and Alex Risch committed May 4, 2024
1 parent 8b60283 commit 1995bcd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.web3j.crypto.Hash
import org.xmtp.android.library.messages.PrivateKeyBuilder
import org.xmtp.android.library.messages.Signature
import org.xmtp.android.library.messages.consentProofText
import org.xmtp.android.library.messages.verify

@RunWith(AndroidJUnit4::class)
Expand All @@ -23,4 +25,14 @@ class SignatureTest {
)
)
}

@Test
fun testConsentProofText() {
val timestamp = 1581663600000
val exampleAddress = "0x1234567890abcdef";
val signatureClass = Signature.newBuilder().build()
val text = signatureClass.consentProofText(exampleAddress, timestamp)
val expected = "XMTP : Grant inbox consent to sender\n\nCurrent Time: Fri, 14 Feb 2020 07:00:00 GMT\nFrom Address: 0x1234567890abcdef\n\nFor more info: https://xmtp.org/signatures/"
assert(text == expected)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.google.protobuf.kotlin.toByteString
import org.xmtp.android.library.Util
import org.xmtp.android.library.toHex
import org.xmtp.proto.message.contents.SignatureOuterClass
import java.text.SimpleDateFormat
import java.util.TimeZone

typealias Signature = org.xmtp.proto.message.contents.SignatureOuterClass.Signature

Expand Down Expand Up @@ -47,8 +49,12 @@ fun Signature.createIdentityText(key: ByteArray): String =
fun Signature.enableIdentityText(key: ByteArray): String =
("XMTP : Enable Identity\n" + "${key.toHex()}\n" + "\n" + "For more info: https://xmtp.org/signatures/")

fun Signature.consentProofText(peerAddress: String, timestamp: Long): String =
("XMTP : Grant inbox consent to sender\n" + "\n" + "Current Time: ${timestamp}\n" + "From Address: ${peerAddress}\n" + "\n" + "For more info: https://xmtp.org/signatures/")
fun Signature.consentProofText(peerAddress: String, timestamp: Long): String {
val formatter = SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss 'GMT'")
formatter.timeZone = TimeZone.getTimeZone("UTC")
val timestampString = formatter.format(timestamp)
return ("XMTP : Grant inbox consent to sender\n" + "\n" + "Current Time: ${timestampString}\n" + "From Address: ${peerAddress}\n" + "\n" + "For more info: https://xmtp.org/signatures/")
}

val Signature.rawData: ByteArray
get() = if (hasEcdsaCompact()) {
Expand Down

0 comments on commit 1995bcd

Please sign in to comment.