* Fixup for #6 Behaviour was changed in the JNI wapper but not in Kotlin native code. * Set version to 0.2.1-1.4-M3
This commit is contained in:
parent
eeac972785
commit
0cc4c251f9
@ -24,7 +24,7 @@ buildscript {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "fr.acinq.secp256k1"
|
group = "fr.acinq.secp256k1"
|
||||||
version = "0.2.0-1.4-M3"
|
version = "0.2.1-1.4-M3"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
jcenter()
|
jcenter()
|
||||||
|
@ -18,10 +18,10 @@ public object Secp256k1Native : Secp256k1 {
|
|||||||
val sig = alloc<secp256k1_ecdsa_signature>()
|
val sig = alloc<secp256k1_ecdsa_signature>()
|
||||||
val nativeBytes = toNat(input)
|
val nativeBytes = toNat(input)
|
||||||
|
|
||||||
val result = when (input.size) {
|
val result = when {
|
||||||
64 -> secp256k1_ecdsa_signature_parse_compact(ctx, sig.ptr, nativeBytes)
|
input.size == 64 -> secp256k1_ecdsa_signature_parse_compact(ctx, sig.ptr, nativeBytes)
|
||||||
in 70..73 -> secp256k1_ecdsa_signature_parse_der(ctx, sig.ptr, nativeBytes, input.size.convert())
|
input.size < 64 -> throw Secp256k1Exception("Unknown signature format")
|
||||||
else -> throw Secp256k1Exception("Unknown signature format")
|
else -> secp256k1_ecdsa_signature_parse_der(ctx, sig.ptr, nativeBytes, input.size.convert())
|
||||||
}
|
}
|
||||||
result.requireSuccess("cannot parse signature (size = ${input.size} sig = ${Hex.encode(input)}")
|
result.requireSuccess("cannot parse signature (size = ${input.size} sig = ${Hex.encode(input)}")
|
||||||
return sig
|
return sig
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package fr.acinq.secp256k1
|
package fr.acinq.secp256k1
|
||||||
|
|
||||||
|
import kotlin.random.Random
|
||||||
import kotlin.test.*
|
import kotlin.test.*
|
||||||
|
|
||||||
|
|
||||||
@ -265,4 +266,24 @@ class Secp256k1Test {
|
|||||||
Hex.encode(der).toUpperCase(),
|
Hex.encode(der).toUpperCase(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testFormatConversion() {
|
||||||
|
val random = Random.Default
|
||||||
|
|
||||||
|
fun randomBytes(length: Int): ByteArray {
|
||||||
|
val buffer = ByteArray(length)
|
||||||
|
random.nextBytes(buffer)
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
repeat(200) {
|
||||||
|
val priv = randomBytes(32)
|
||||||
|
val pub = Secp256k1.pubkeyCreate(priv)
|
||||||
|
val data = randomBytes(32)
|
||||||
|
val sig = Secp256k1.sign(data, priv)
|
||||||
|
val der = Secp256k1.compact2der(sig)
|
||||||
|
Secp256k1.verify(der, data, pub)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user