diff --git a/src/nativeMain/kotlin/fr/acinq/secp256k1/Secp256k1Native.kt b/src/nativeMain/kotlin/fr/acinq/secp256k1/Secp256k1Native.kt index 18b0d41..fcc29c2 100644 --- a/src/nativeMain/kotlin/fr/acinq/secp256k1/Secp256k1Native.kt +++ b/src/nativeMain/kotlin/fr/acinq/secp256k1/Secp256k1Native.kt @@ -559,10 +559,8 @@ public object Secp256k1Native : Secp256k1 { vssCommitments.forEachIndexed { index, commitments -> val pubkeyArray = allocArray(commitments.size) commitments.forEachIndexed { commitmentIndex, pubkeyData -> - pubkeyData.usePinned { pinned -> - if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pinned.get()), pubkeyData.size.convert()) == 0) { - error("Failed to parse public key") - } + if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pubkeyData), pubkeyData.size.convert()) == 0) { + error("Failed to parse public key") } } nVssCommitments[index] = pubkeyArray @@ -605,20 +603,24 @@ public object Secp256k1Native : Secp256k1 { memScoped { val nFrostShare = allocFrostShare(share) -// val nVssCommitment = vssCommitment.map { allocPublicKey(it).ptr }.toCValues() +// val nVssCommitment = vssCommitment.map { allocPublicKey(it).ptr } val nVssCommitment = allocArray>(vssCommitment.size) - vssCommitment.forEachIndexed { index, pubkeyData -> - pubkeyData.usePinned { pinned -> - if (secp256k1_ec_pubkey_parse(ctx, nVssCommitment[index], toNat(pinned.get()), pubkeyData.size.convert()) == 0) { - error("Failed to parse public key") - } - } + vssCommitment.forEachIndexed { index, bytes -> + memcpy(nVssCommitment[index], bytes.refTo(0).getPointer(memScope), bytes.size.convert()) } +// val nVssCommitment = allocArray>(vssCommitment.size) +// vssCommitment.forEachIndexed { index, pubkeyData -> +// pubkeyData.usePinned { pinned -> +// if (secp256k1_ec_pubkey_parse(ctx, nVssCommitment[index], toNat(pinned.get()), pubkeyData.size.convert()) == 0) { +// error("Failed to parse public key") +// } +// } +// } return secp256k1_frost_share_verify( ctx = ctx, - threshold = vssCommitment.size.convert(), + threshold = threshold.convert(), id33 = toNat(id33), share = nFrostShare.ptr, vss_commitment = nVssCommitment @@ -652,10 +654,8 @@ public object Secp256k1Native : Secp256k1 { vssCommitments.forEachIndexed { index, commitments -> val pubkeyArray = allocArray(commitments.size) commitments.forEachIndexed { commitmentIndex, pubkeyData -> - pubkeyData.usePinned { pinned -> - if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pinned.get()), pubkeyData.size.convert()) == 0) { - error("Failed to parse public key") - } + if (secp256k1_ec_pubkey_parse(ctx, pubkeyArray[commitmentIndex].ptr, toNat(pubkeyData), pubkeyData.size.convert()) == 0) { + error("Failed to parse public key") } } nVssCommitments[index] = pubkeyArray