-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(secp256k1): Exposing EC Secp256K1
- Loading branch information
Showing
3 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ryption/src/commonTest/kotlin/io/iohk/atala/prism/apollo/utils/KMMECSecp256k1KeysTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
import io.iohk.atala.prism.apollo.base64.base64UrlDecodedBytes | ||
import io.iohk.atala.prism.apollo.base64.base64UrlEncoded | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertTrue | ||
|
||
class KMMECSecp256k1KeysTests { | ||
@Test | ||
fun testSigning() { | ||
val privateKeyBase64 = "N_JFgvYaReyRXwassz5FHg33A4I6dczzdXrjdHGksmg" | ||
val base64ByteArray = privateKeyBase64.base64UrlDecodedBytes | ||
val privateKey = KMMECSecp256k1PrivateKey.secp256k1FromByteArray(base64ByteArray) | ||
val message = "Test" | ||
val signature = privateKey.sign(message.encodeToByteArray()) | ||
assertEquals("MEUCIQCFeGlhJrH-9R70X4JzrurWs52SwuxCnJ8ky6riFwMOrwIgT7zlLo7URMHW5tiMgG73IOw2Dm3XyLl1iqW1-t5NFWQ", signature.base64UrlEncoded) | ||
} | ||
|
||
@Test | ||
fun testVerifyingFromPrivateKey() { | ||
val privateKeyBase64 = "N_JFgvYaReyRXwassz5FHg33A4I6dczzdXrjdHGksmg" | ||
val base64ByteArray = privateKeyBase64.base64UrlDecodedBytes | ||
val privateKey = KMMECSecp256k1PrivateKey.secp256k1FromByteArray(base64ByteArray) | ||
val message = "Test" | ||
val signature = privateKey.sign(message.encodeToByteArray()) | ||
assertEquals("MEUCIQCFeGlhJrH-9R70X4JzrurWs52SwuxCnJ8ky6riFwMOrwIgT7zlLo7URMHW5tiMgG73IOw2Dm3XyLl1iqW1-t5NFWQ", signature.base64UrlEncoded) | ||
assertTrue(privateKey.verify(signature, message.encodeToByteArray())) | ||
} | ||
|
||
@Test | ||
fun testVerifyingFromPublicKey() { | ||
val privateKeyBase64 = "N_JFgvYaReyRXwassz5FHg33A4I6dczzdXrjdHGksmg" | ||
val base64ByteArray = privateKeyBase64.base64UrlDecodedBytes | ||
val privateKey = KMMECSecp256k1PrivateKey.secp256k1FromByteArray(base64ByteArray) | ||
val message = "Test" | ||
val signature = privateKey.sign(message.encodeToByteArray()) | ||
assertEquals("MEUCIQCFeGlhJrH-9R70X4JzrurWs52SwuxCnJ8ky6riFwMOrwIgT7zlLo7URMHW5tiMgG73IOw2Dm3XyLl1iqW1-t5NFWQ", signature.base64UrlEncoded) | ||
val publicKey = privateKey.getPublicKey() | ||
assertTrue(publicKey.verify(signature, message.encodeToByteArray())) | ||
} | ||
} |