Skip to content

Class: MessageVerifier

Message verifier is similar to the encryption. However, the actual payload is not encrypted and just base64 encoded. This is helpful when you are not concerned about the confidentiality of the data, but just want to make sure that is not tampered after encoding.

Constructors

Constructor

ts
new MessageVerifier(secret: string): MessageVerifier;

Parameters

ParameterType
secretstring

Returns

MessageVerifier

Methods

encodable()

ts
encodable(value: unknown): boolean;

Checks if the value can be encoded

Parameters

ParameterType
valueunknown

Returns

boolean


sign()

ts
sign(
   payload: any,
   expiresIn?: string | number,
   purpose?: string): string;

Sign a given piece of value using the app secret. A wide range of data types are supported. See @nhtio/serialization for more information on the supported data types.

You can optionally define a purpose for which the value was signed and mentioning a different purpose/no purpose during unsign will fail.

Parameters

ParameterType
payloadany
expiresIn?string | number
purpose?string

Returns

string


unsign()

ts
unsign<T>(payload: string, purpose?: string): null | T;

Unsign a previously signed value with an optional purpose

Type Parameters

Type Parameter
T extends any

Parameters

ParameterType
payloadstring
purpose?string

Returns

null | T


encodable()

ts
static encodable(value: unknown): boolean;

Checks if the value can be encoded

Parameters

ParameterType
valueunknown

Returns

boolean