(sendNotification will automatically encrypt the payload for you, so if
you use sendNotification you don't need to worry about it).

Input

The encrypt() method expects the following input:

userPublicKey: the public key of the receiver (from the browser).

userAuth: the auth secret of the receiver (from the browser).

payload: the message to attach to the notification.

Returns

This method returns an object with the following fields:

localPublicKey: The public key matched the private key used during
encryption.

salt: A string representing the salt used to encrypt the payload.

cipherText: The encrypted payload as a Buffer.

getVapidHeaders(audience, subject, publicKey, privateKey, expiration)

constparsedUrl=url.parse(subscription.endpoint);

constaudience=parsedUrl.protocol+'//'+

parsedUrl.hostname;

constvapidHeaders=vapidHelper.getVapidHeaders(

audience,

'mailto: example@web-push-node.org',

vapidDetails.publicKey,

vapidDetails.privateKey

);

The getVapidHeaders() method will take in the values needed to create
an Authorization and Crypto-Key header.

Input

The getVapidHeaders() method expects the following input:

audience: the origin of the push service.

subject: the mailto or URL for your application.

publicKey: the VAPID public key.

privateKey: the VAPID private key.

Returns

This method returns an object with the following fields:

localPublicKey: The public key matched the private key used during
encryption.

salt: A string representing the salt used to encrypt the payload.

cipherText: The encrypted payload as a Buffer.

generateRequestDetails(pushSubscription, payload, options)

constpushSubscription={

endpoint:'< Push Subscription URL >';

keys:{

p256dh:'< User Public Encryption Key >',

auth:'< User Auth Secret >'

}

};

constpayload='< Push Payload String >';

constoptions={

gcmAPIKey:'< GCM API Key >',

vapidDetails:{

subject:'< \'mailto\' Address or URL >',

publicKey:'< URL Safe Base64 Encoded Public Key >',

privateKey:'< URL Safe Base64 Encoded Private Key >',

}

TTL:<Number>,

headers:{

'< header name >':'< header value >'

}

}

try{

constdetails=webpush.generateRequestDetails(

pushSubscription,

payload,

options

);

}catch(err){

console.error(err);

}

Note: When calling generateRequestDetails() the payload argument
does not need to be defined, passing in null will return no body and
exclude any unnecessary headers.
Headers related to the GCM API Key and / or VAPID keys will be included
if supplied and required.

Input

Push Subscription

The first argument must be an object containing the details for a push
subscription.

The expected format is the same output as JSON.stringify'ing a PushSubscription
in the browser.

Payload

The payload is optional, but if set, will be encrypted and a Buffer
will be returned via the payload parameter.