libp2p-hs-0.1.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

LibP2P.Crypto.Secp256k1

Description

Secp256k1 key operations for libp2p peer identity, using crypton.

Wire formats follow the libp2p peer-ids spec: - Public key: 33-byte SEC1 compressed point (0x02/0x03 prefix + 32-byte X). - Private key: 32-byte big-endian scalar. - Signatures: ECDSA over SHA-256 with deterministic nonces (RFC 6979), DER-encoded (SEQUENCE { r, s }).

Operates on raw ByteString so this module has no dependency on LibP2P.Crypto.Key.

Synopsis

Documentation

generate :: IO (ByteString, ByteString) Source #

Generate a new secp256k1 key pair, returning (compressed public, 32-byte private).

sign :: ByteString -> ByteString -> Either String ByteString Source #

Sign a message with a 32-byte private scalar (ECDSA/SHA-256, DER output). Nonces are deterministic per RFC 6979, so signing is pure: the same key and message always produce the same signature.

verify :: ByteString -> ByteString -> ByteString -> Bool Source #

Verify a DER signature against a 33-byte compressed public key (ECDSA/SHA-256).

derivePublicKey :: ByteString -> Either String ByteString Source #

Derive the 33-byte compressed public key from a 32-byte private scalar.

decodePoint :: ByteString -> Either String Point Source #

Decode a 33-byte SEC1 compressed public key into a curve point, rejecting inputs that do not name a point on the curve: X coordinates outside the field and X coordinates for which x^3 + ax + b is a quadratic non-residue (the candidate square root then fails the curve equation). The point at infinity is not decodable (its SEC1 form is a single zero byte, rejected by the length check).