Increase test and fix some compiler errors on the JNI side.

This commit is contained in:
kngako
2024-08-19 21:40:56 +02:00
parent e7f074d36e
commit b1e96f329b
7 changed files with 439 additions and 161 deletions

View File

@@ -329,7 +329,7 @@ public interface Secp256k1 {
public const val FROST_PARTIAL_SIGNATURE_SIZE: Int = 36
public const val FROST_SHARE_SIZE: Int = 37
public const val FROST_SHARE_SIZE: Int = 32
public const val FROST_TWEAK_CACHE_SIZE: Int = 102
public const val FROST_SESSION_SIZE: Int = 134
public const val FROST_SECNONCE_SIZE: Int = 69

View File

@@ -489,11 +489,11 @@ public object Secp256k1Native : Secp256k1 {
totalSigners: Int,
ids33: Array<ByteArray>
): Triple<Array<ByteArray>, Array<ByteArray>, ByteArray> {
require(seed32.size == 32, { "seed size should be 32" })
require(threshold > 1, { "threshold cannot be less then 1" })
require(threshold <= totalSigners, { "threshold($threshold) cannot be greater then totalSigners ($totalSigners)" })
require(ids33.size == totalSigners, { "ids33 size need to be the same as totalSigners size" })
ids33.forEach { require(it.size == 33, { "id33 size must be 33" }) }
require(seed32.size == 32) { "seed size should be 32" }
require(threshold > 1) { "threshold cannot be less then 1" }
require(threshold <= totalSigners) { "threshold($threshold) cannot be greater then totalSigners ($totalSigners)" }
require(ids33.size == totalSigners) { "ids33 size need to be the same as totalSigners size" }
ids33.forEach { require(it.size == 33) { "id33 size must be 33" } }
memScoped {
val nShares = allocArray<secp256k1_frost_share>(ids33.size)
@@ -534,18 +534,18 @@ public object Secp256k1Native : Secp256k1 {
threshold: Int,
id33: ByteArray
): Pair<ByteArray, ByteArray> {
require(totalShares.size == totalShareCount)
totalShares.forEach { require(it.size == 33) }
require(vssCommitments.size == totalShareCount)
require(totalShares.size == totalShareCount) { "totalShare array size (${totalShares.size}) should be the same as total share count ($totalShareCount)" }
totalShares.forEach { require(it.size == 32) { "all shares should be of size 32" } }
require(vssCommitments.size == totalShareCount) { "vssCommitments array size ${vssCommitments.size} should be the same as total share count ($totalShareCount)" }
vssCommitments.forEach { vssCommitment ->
require(vssCommitment.size == threshold)
require(vssCommitment.size == threshold) { "all vss commitment array size (${vssCommitment.size}) should be the same as the threshold size ($threshold)" }
vssCommitment.forEach { publicKey ->
require(publicKey.size == 33 || publicKey.size == 65)
require(publicKey.size == 33 || publicKey.size == 65) { "vss commitment data size should be 33 or 65" }
}
}
require(threshold > 1)
require(threshold <= totalShareCount)
require(id33.size == 33)
require(threshold > 1) { "threshold should be greater then 1" }
require(threshold <= totalShareCount) { "Threshold can not be greater then the total share count" }
require(id33.size == 33) { "id size should be 33" }
memScoped {
val nAggregateShare = alloc<secp256k1_frost_share>()
@@ -562,7 +562,7 @@ public object Secp256k1Native : Secp256k1 {
).reinterpret()
}
secp256k1_frost_share_agg(
val result = secp256k1_frost_share_agg(
ctx = ctx,
agg_share = nAggregateShare.ptr,
agg_pk = nAggregatePublicKey.ptr,
@@ -572,6 +572,7 @@ public object Secp256k1Native : Secp256k1 {
threshold = threshold.convert(),
id33 = toNat(id33)
)
println("Aggregate Result: $result")
return Pair(
serializeFrostShare(nAggregateShare),
@@ -587,13 +588,13 @@ public object Secp256k1Native : Secp256k1 {
share: ByteArray,
vssCommitment: Array<ByteArray>
): Int {
require(threshold > 1)
require(id33.size == 33)
require(share.size == Secp256k1.FROST_SHARE_SIZE)
require(threshold > 1) { "threshold should be greater then 1" }
require(id33.size == 33) { "id size should be 33" }
require(share.size == Secp256k1.FROST_SHARE_SIZE) { "all shares should be of size 32" }
require(vssCommitment.size == threshold)
require(vssCommitment.size == threshold) { "all vss commitment array size (${vssCommitment.size}) should be the same as the threshold size ($threshold)" }
vssCommitment.forEach { publicKey ->
require(publicKey.size == 33 || publicKey.size == 65)
require(publicKey.size == 33 || publicKey.size == 65) { "vss commitment data size should be 33 or 65" }
}
memScoped {