Skip to content

Commit

Permalink
fix: ed25519 JS signature as buffer not hex buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Javier Ribó <[email protected]>
  • Loading branch information
elribonazo committed Sep 30, 2024
1 parent 2b4a59b commit 93a10dc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()


)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 93a10dc

Please sign in to comment.