haskell-bitcoin / libsecp256k1-haskell

Haskell bindings for secp256k1 library
MIT License
0 stars 2 forks source link

Wrong export for schnorr signatures #8

Open prolic opened 2 days ago

prolic commented 2 days ago

I made it work with this:

-- Function to extract ByteString from Signature
signatureToByteString :: Signature -> IO BS.ByteString
signatureToByteString (Signature (S.Signature fptr)) =
    withForeignPtr fptr $ \ptr -> BS.create sigSize $ \destPtr -> do
        let bytePtr = castPtr ptr :: Ptr Word8  -- Cast Ptr Prim.Sig64 to Ptr Word8
        bytes <- peekArray sigSize bytePtr      -- Read the bytes from the casted pointer
        -- Copy bytes into destination pointer
        mapM_ (\(i, b) -> pokeElemOff destPtr i b) (zip [0..] bytes)

using ecdsaSignatureSerializeCompact gives wrong results.

prolic commented 2 days ago

@wraithm @ProofOfKeags

ProofOfKeags commented 15 hours ago

What do you mean by "gives wrong results" how did you observe this behavior?

I took a look at the code you provided but as far as I can tell all it does is copy the underlying buffer.

ProofOfKeags commented 15 hours ago

Also it's worth noting that using ecdsaSignatureSerializeCompact is unlikely to work with Schnorr sigs.

prolic commented 14 hours ago

That's my point, I can't export the schnorr signatures to bytestring (or hex). If you want, I can submit a pull request by tomorrow.

On Mon, Sep 30, 2024, 13:30 ProofOfKeags @.***> wrote:

Also it's worth noting that using ecdsaSignatureSerializeCompact is unlikely to work with Schnorr sigs.

— Reply to this email directly, view it on GitHub https://github.com/haskell-bitcoin/libsecp256k1-haskell/issues/8#issuecomment-2383777377, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADAJPBHU5VJ624MIY6437TZZGDD7AVCNFSM6AAAAABPBFVUMCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOBTG43TOMZXG4 . You are receiving this because you authored the thread.Message ID: @.***>

ProofOfKeags commented 13 hours ago

If you want to submit a PR feel free. Otherwise I'll take care of it this week. It looks like we need to mark signatures internally by what kind they are and then export them accordingly. From there we also need to modify the import function to accept a hint about what kind of signature it is, since there isn't a structural difference between ecdsa sigs and schnorr sigs when parsing them.