Allows validation that requests originated from Lucid. This class can only be instanciated in a NodeJS environment.
Technically any environment that provides NodeJS compatible implementations of globalThis.Buffer
and
globalThis.require('crypto')
will work.
Constructors
new SignatureValidator()
new SignatureValidator(dependencies, publicKey): SignatureValidator
Parameters
Parameter | Type |
---|---|
dependencies | CryptoDependencies |
publicKey | string |
Returns
Methods
validate()
validate(
body,
headers,
url): boolean
Validate a given request came from Lucid.
Parameters
Parameter | Type | Description |
---|---|---|
body | unknown | The body of the request as a plain JavaScript object. This should be JSON.parse called on exactly the request body that came from Lucid. |
headers | object | The headers that are associated with the request. Only 'x-lucid-rsa-nonce' and 'x-lucid-signature' are required. |
headers.x-lucid-rsa-nonce | string | - |
headers.x-lucid-signature | string | - |
url | string | The url of the current endpoint that is being requested. |
Returns
boolean
true if the request is valid