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

LibP2P.Crypto.Key

Description

Key types and KeyPair abstraction for libp2p peer identity.

Synopsis

Documentation

data KeyType Source #

Supported key types per the libp2p spec.

Constructors

Ed25519 
RSA 
Secp256k1 
ECDSA 

Instances

Instances details
Show KeyType Source # 
Instance details

Defined in LibP2P.Crypto.Key

Eq KeyType Source # 
Instance details

Defined in LibP2P.Crypto.Key

Methods

(==) :: KeyType -> KeyType -> Bool #

(/=) :: KeyType -> KeyType -> Bool #

Ord KeyType Source # 
Instance details

Defined in LibP2P.Crypto.Key

data KeyPair Source #

A key pair containing both public and private keys.

Constructors

KeyPair 

data PublicKey Source #

A public key with its type.

Constructors

PublicKey 

Instances

Instances details
Show PublicKey Source # 
Instance details

Defined in LibP2P.Crypto.Key

Eq PublicKey Source # 
Instance details

Defined in LibP2P.Crypto.Key

data PrivateKey Source #

A private key with its type.

Constructors

PrivateKey 

publicKey :: KeyPair -> PublicKey Source #

Extract the public key from a key pair.

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.