Nip incompliant pubkey (length 32 expected)
"pubkey": <32-bytes lowercase hex-encoded public key of the event creator>
https://github.com/prolic/futr/blob/672758c0a654f310b8c5ac6c87a2bcc3e3b696e8/src/Nostr/Event.hs#L94
ghci> kp <- generateKeyPair
ghci> pk = exportXOnlyPubKey . deriveXOnlyPubKey $ kp
ghci> BS.length . Hex.decodeLenient . encodeUtf8 . T.pack $ pk
64
-- or
ghci> BS.length . getXOnlyPubKey . deriveXOnlyPubKey $ kp
64
-- therefore
ghci> xOnlyPubKey . getXOnlyPubKey . deriveXOnlyPubKey $ kp
Nothing
Am I missing something? Does this, how does this work?
Sorry, I'm not following, can you explain what's the issues here?
64 bytes is coming out from exportXOnlyPubKey but the spec asks for a 32 bytes. I'm trying to understand why / how this isn't creating invalid events with pubkeys like: ae6fb593b1613d445a198d9b7f287e08b61f0d13e56b98259c409937cf3d4c758e37918d84ab20dcf6f3698185685bd66ddbf86829878a8b5e8e817bef086643
ghci> xOnlyPubKey . getXOnlyPubKey . deriveXOnlyPubKey $ kp
This loop return Nothing because building the XOnlyPub takes 32 bytes but getXOnlyPubKey puts out 64.
I have to double check that, maybe I get to it on the weekend.
Sascha-Oliver Prolic
Am Mo., 7. Aug. 2023 um 20:06 Uhr schrieb AutonomousOrganization < @.***>:
64 bytes is coming out from exportXOnlyPubKey but the spec asks for a 32 bytes. I'm trying to understand why / how this isn't creating invalid events with pubkeys like:
ae6fb593b1613d445a198d9b7f287e08b61f0d13e56b98259c409937cf3d4c758e37918d84ab20dcf6f3698185685bd66ddbf86829878a8b5e8e817bef086643
ghci> xOnlyPubKey . getXOnlyPubKey . deriveXOnlyPubKey $ kp
This loop return Nothing because building the XOnlyPub takes 32 bytes but getXOnlyPubKey puts out 64.
— Reply to this email directly, view it on GitHub https://github.com/prolic/futr/issues/16#issuecomment-1668726057, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADAJPFO32A2E7MT7YHGEH3XUF7H3ANCNFSM6AAAAAA262D764 . You are receiving this because you commented.Message ID: @.***>
The problem is in the underlying secp256k1 library:
exportXOnlyPubKey :: XOnlyPubKey -> String
exportXOnlyPubKey (XOnlyPubKey p) = unsafePerformIO $ do
unsafeUseByteString p $ \(p_ptr, _) -> do
serialized <- mallocBytes 64 -- !! <--- 32
ret <- schnorrPubKeySerialize ctx serialized p_ptr
unless (isSuccess ret) $ do
free serialized
error "could not serialize x-only public key"
out <- unsafePackByteString (serialized, 64) -- !! <-- 32
return $ exportText out
I've learned a lot picking through futr and secp256k1-schnorr. Got the sign verify working here: futr2
I'm going to close this issue. I've removed the secp256k1-schnorr dependency and I am now working on some major changes for this project.