ARCHIVED — This package has been migrated to github.com/wavy-node/backend. It now lives in the backend monorepo at
packages/utils.
A set of utilities for integrating WavyNode.
npm install @wavynode/utilsA complete example can be found in the template repo
import{validateSignature}from'@wavynode/utils'constisValid=validateSignature({method: 'POST',path: '/v1/users',body: {name: 'John Doe'},timestamp: Date.now(),signature: 'some-signature',secret: 'your-secret',})if(isValid){// The signature is valid}Validates the signature sent with each request.
Parameters
params.method: The HTTP method of the request (GETorPOST).params.path: The path of the request.params.body: The body of the request. Use{}if empty.params.timestamp: The timestamp of the request.params.signature: The signature sent with the request.params.secret: Your secret from environment variables.params.timeTolerance(optional): The time tolerance for the signature in milliseconds. Defaults to 5 minutes.
Returns
A boolean indicating whether the signature is valid.
Creates a base64 hmac signature for the given message using the secret.
Parameters
message: The message to sign.secret: Your secret.
Returns
The base64 hmac signature.
Creates a unique message to be signed for each request.
Parameters
params.method: The HTTP method of the request (GETorPOST).params.path: The path of the request.params.body: The body of the request. Use{}if empty.params.timestamp: The timestamp of the request.
Returns
A unique message to be signed.