diff --git a/apollo/src/appleTest/kotlin/org/hyperledger/identus/apollo/secp256k1/KMMEdKeyPairTest.kt b/apollo/src/appleTest/kotlin/org/hyperledger/identus/apollo/secp256k1/KMMEdKeyPairTest.kt new file mode 100644 index 000000000..0a8e5d053 --- /dev/null +++ b/apollo/src/appleTest/kotlin/org/hyperledger/identus/apollo/secp256k1/KMMEdKeyPairTest.kt @@ -0,0 +1,18 @@ +package org.hyperledger.identus.apollo.secp256k1 + +import org.hyperledger.identus.apollo.base64.base64DecodedBytes +import org.hyperledger.identus.apollo.utils.KMMEdPublicKey +import kotlin.test.Test +import kotlin.test.assertTrue + +class KMMEdKeyPairTest { + + @Test + fun ed_signature_verify() { + val message = "testing".encodeToByteArray() + val edsk = KMMEdPublicKey("z+a8g8i/3yajE/QDIxIF7sP1m/aLKTOfygIuSJanRAg".base64DecodedBytes) + val sig = "zZzeTBYjrpowc+skEMVQSVTzntzXvZGcbBbNY0gHKF6z+e40Q5G3o35lX4Mf0J8iRde/LAn77JdzIh6gQv7hAA".base64DecodedBytes + val verify = edsk.verify(message, sig) + assertTrue(verify) + } +} diff --git a/apollo/src/appleTest/kotlin/org/hyperledger/identus/apollo/secp256k1/Secp256k1Tests.kt b/apollo/src/appleTest/kotlin/org/hyperledger/identus/apollo/secp256k1/Secp256k1Tests.kt index f0b453533..94fb6cffc 100644 --- a/apollo/src/appleTest/kotlin/org/hyperledger/identus/apollo/secp256k1/Secp256k1Tests.kt +++ b/apollo/src/appleTest/kotlin/org/hyperledger/identus/apollo/secp256k1/Secp256k1Tests.kt @@ -1,13 +1,19 @@ package org.hyperledger.identus.apollo.secp256k1 import fr.acinq.secp256k1.Secp256k1Native -import kotlin.test.Test -import kotlin.test.assertContentEquals -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue +import org.hyperledger.identus.apollo.utils.KMMEdKeyPair +import kotlin.test.* class Secp256k1Tests { + @Test + fun verifyValidPrivateKeyEd() { + + val keypair = KMMEdKeyPair.generateKeyPair() + keypair.privateKey.raw + } + + + @Test fun verifyValidPrivateKey() { val secp256k1 = Secp256k1Native diff --git a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPrivateKey.kt b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPrivateKey.kt index d23cd4a36..22e80ea1d 100644 --- a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPrivateKey.kt +++ b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPrivateKey.kt @@ -49,7 +49,7 @@ actual class KMMEdPrivateKey(bytes: ByteArray) { actual fun sign(message: ByteArray): ByteArray { val sig = keyPair.sign(Buffer.from(message)) - return sig.toHex().encodeToByteArray() + return sig.toBytes().toByteArray() } /** diff --git a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPublicKey.kt b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPublicKey.kt index 6b3f0a358..26e777b51 100644 --- a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPublicKey.kt +++ b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/KMMEdPublicKey.kt @@ -46,6 +46,12 @@ actual class KMMEdPublicKey(bytes: ByteArray) { * @return Boolean */ actual fun verify(message: ByteArray, sig: ByteArray): Boolean { - return keyPair.verify(Buffer.from(message), sig.decodeToString()) + + return keyPair.verify( + Buffer.from(message), + sig.toHexString() + + + ) } } diff --git a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/external/Ellipticjs.kt b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/external/Ellipticjs.kt index 1006fc84f..deed952b8 100644 --- a/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/external/Ellipticjs.kt +++ b/apollo/src/jsMain/kotlin/org/hyperledger/identus/apollo/utils/external/Ellipticjs.kt @@ -279,7 +279,7 @@ open external class eddsa(name: String /* "ed25519" */) { open fun isPoint(param_val: Any): Boolean open class Signature { constructor(eddsa: eddsa, sig: _eddsa_Signature) - constructor(eddsa: eddsa, sig: String) + constructor(eddsa: eddsa, sig: Any) open fun toBytes(): Buffer open fun toHex(): String }