| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
LibP2P.Crypto.Key
Description
Key types and KeyPair abstraction for libp2p peer identity.
Synopsis
- data KeyType
- data KeyPair = KeyPair {}
- data PublicKey = PublicKey {
- pkType :: KeyType
- pkBytes :: ByteString
- data PrivateKey = PrivateKey {
- skType :: KeyType
- skBytes :: ByteString
- publicKey :: KeyPair -> PublicKey
- sign :: PrivateKey -> ByteString -> Either String ByteString
- verify :: PublicKey -> ByteString -> ByteString -> Bool
- keyPairFromPrivateKey :: PrivateKey -> Either String KeyPair
- generateRSAKeyPair :: IO KeyPair
- generateSecp256k1KeyPair :: IO KeyPair
- generateECDSAKeyPair :: IO KeyPair
Documentation
Supported key types per the libp2p spec.
A key pair containing both public and private keys.
Constructors
| KeyPair | |
Fields
| |
A public key with its type.
Constructors
| PublicKey | |
Fields
| |
data PrivateKey Source #
A private key with its type.
Constructors
| PrivateKey | |
Fields
| |
sign :: PrivateKey -> ByteString -> Either String ByteString Source #
Sign a message with a private key.
Signing is deterministic (and therefore pure) for every key type: Ed25519 and RSA (PKCS#1 v1.5) are deterministic by construction, and secp256k1/ECDSA use RFC 6979 deterministic nonces. Returns Left on invalid key bytes.
verify :: PublicKey -> ByteString -> ByteString -> Bool Source #
Verify a signature against a public key and message. Supports every libp2p key type so remote peers of any type can be authenticated.
keyPairFromPrivateKey :: PrivateKey -> Either String KeyPair Source #
Reconstruct a full key pair from a private key in libp2p wire format, deriving the public key. This is the import path for keys produced by other implementations (the peer-ids spec requires that implementations can produce the public key from the private key).
generateRSAKeyPair :: IO KeyPair Source #
Generate a new RSA key pair (2048-bit) with libp2p wire-format key bytes.
generateSecp256k1KeyPair :: IO KeyPair Source #
Generate a new secp256k1 key pair with libp2p wire-format key bytes.
generateECDSAKeyPair :: IO KeyPair Source #
Generate a new ECDSA (P-256) key pair with libp2p wire-format key bytes.