Public Key

Core Public Key functionality depends on Ristretto element from curve25519.

So if you operate with it on low level, and has a Ristretto in your hands, instantiate object using one of this two methods:

val publicKeyRistretto: RistrettoElement
val publicKeyCompressedRistretto: CompressedRistretto

val publicKey: PublicKey = PublicKey(publicKeyRistretto)
val publicKeyFromCompressed: PublicKey = PublicKey.fromCompressed(publicKeyCompressedRistretto)

// publicKey == publicKeyFromCompressed, 
// if publicKeyCompressedRistretto is a compressed form of publicKeyRistretto

To get a compressed version of Public Key's Ristretto use this, however we only use this for signing and verifying inside our library:

val publicKey: PublicKey
val publicKeyCompressedRistretto: CompressedRistretto = publicKey.asCompressed()

But more likely, you will operate with byte arrays.

So you can either instantiate Public Key or convert it to Byte Array using this:

val publicKeyByteArray: ByteArray // should be 32 bytes
val publicKey: PublicKey = PublicKey.fromByteArray(publicKeyByteArray)
val backToByteArray: ByteArray = publicKey.toByteArray()

// publicKeyByteArray == backToByteArray

Verifying signatures

Same as for Secret Key you can verify it using transcript, or using simple method:

val publicKey: PublicKey
val message: ByteArray
val signedMessage: ByteArray

val signature: Signature = Signature.fromByteArray(signedMessage)

val signingContext: SigningContext = SigningContext

val simplyVerified: Boolean = publicKey.verifySimple(signingContext, message, signature)

val signingTranscript: SigningTranscript = signingContext.bytes(message)
val verified: Boolean = publicKey.verify(signingTranscript, signature)

// simplyVerified == verified

Last updated