web-push-0.5: Send messages using Web Push protocol.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Web.WebPush.Keys

Synopsis

Documentation

newtype VAPIDKeys Source #

VAPIDKeys are the public and private keys used to sign the JWT authentication token sent for the push sendPushNotification

The key is an ECDSA key pair with the p256 curve

Constructors

VAPIDKeys 

Fields

Instances

Instances details
Show VAPIDKeys Source # 
Instance details

Defined in Web.WebPush.Keys

vapidPublicKey :: VAPIDKeys -> PublicKey Source #

Get the public key from the VAPID keys

data VAPIDKeysError Source #

Errors from reading the VAPID keys from files

Constructors

VAPIDKeysPublicKeyError PublicKeyError

Error reading the public key

VAPIDKeysPrivateKeyError PrivateKeyError

Error reading the private key

VAPIDKeysCurveMismatch

The public and private keys are not on the same curve

Instances

Instances details
Show VAPIDKeysError Source # 
Instance details

Defined in Web.WebPush.Keys

readVapidKeys Source #

Arguments

:: FilePath

Path to the public key file

-> FilePath

Path to the private key file

-> IO (Either VAPIDKeysError VAPIDKeys) 

Read the public and private keys from files

toKeyPair :: PublicKey -> PrivateKey -> KeyPair Source #

Convert public and private keys to a key pair

data PrivateKeyError Source #

Errors from reading the VAPID private key from files

Constructors

PrivateKeyPEMParseError PEMError

Error parsing the PEM file

PrivateKeyUnknownCurveName

The curve name is not known

PrivateKeyWrongCurve CurveName

The curve is not p256

PrivateKeyInvalidPEM

The PEM file is not a single private key

Instances

Instances details
Show PrivateKeyError Source # 
Instance details

Defined in Web.WebPush.Keys

readWebPushPrivateKey :: FilePath -> IO (Either PrivateKeyError PrivateKey) Source #

Read the private key from a PEM file

The private key is an ECDSA private number on the p256 curve

data PublicKeyError Source #

Errors from reading the VAPID public key from files

Constructors

PublicKeyPEMParseError PEMError

PEM encoding error

PublicKeyASN1Error ASN1Error

ASN1 decoding error

PublicKeyFromASN1Error String

Error converting ASN1 to ECDSA public key

PublicKeyUnsupportedKeyType

The key type is not supported

PublicKeyUnknownCurve

The curve is not known

PublicKeyUnserialiseError

Error unserialising the EC point

PublicKeyInvalidPEM

The PEM file is not a single public key

Instances

Instances details
Show PublicKeyError Source # 
Instance details

Defined in Web.WebPush.Keys

readWebPushPublicKey :: FilePath -> IO (Either PublicKeyError PublicKey) Source #

Read the public key from a PEM file

The public key is an ECDSA public point on the p256 curve

writeVAPIDKeys :: FilePath -> FilePath -> VAPIDKeys -> IO () Source #

Write the public and private keys to files NOTE: This will overwrite any existing files and it does not store keys in the exact same format as they were read in from if they were created with OpenSSL

generateVAPIDKeys :: MonadRandom m => m (Either String VAPIDKeys) Source #

Generate a new VAPID key pair, this is an ECDSA key pair on the p256 curve

Store them securely and use them across multiple push notification requests.

vapidPublicKeyBytes :: PublicKey -> Either String [Word8] Source #

Pass the VAPID public key bytes as applicationServerKey when calling subscribe on the PushManager object on a registered service worker

applicationServerKey = new Uint8Array( #{toJSON vapidPublicKeyBytes} )