Options
All
  • Public
  • Public/Protected
  • All
Menu

A wrapper to authenticate an object (the 'payload') using a SHA3-512 HMAC tag. Computation of the HMAC includes a nonce to support prevention of replay attacks. The input to the HMAC is the concatenation of the nonce, "." and the base64-encoding of the JSON.stringification of the payload.

Hierarchy

  • HMACAuthenticatedPayload

Index

Constructors

  • Create an HMACAuthenticatedPayload object using the supplied payload, nonce and HMAC.

    Parameters

    • payload: unknown

      Arbitrary JSON-stringifiable data.

    • nonce: string

      A cryptographic nonce.

    • hmac: string

      An HMAC tag in base64 encoding.

    Returns HMACAuthenticatedPayload

Properties

hmac: string

An HMAC tag in base64 encoding.

nonce: string

A cryptographic nonce.

payload: unknown

Arbitrary JSON-stringifiable data.

Methods

  • validate(key: Buffer): boolean
  • Computes the correct HMAC of this object and compares it to the stored HMAC. Returns true if and only if they coincide.

    Parameters

    • key: Buffer

    Returns boolean

  • computeHMAC(key: Buffer, payload: unknown, nonce?: string): string
  • Computes the correct HMAC of the supplied payload, nonce.

    Parameters

    • key: Buffer

      A cryptographic key. Should be exactly 64 bytes long.

    • payload: unknown

      Arbitrary JSON-stringifiable data.

    • nonce: string = ...

      A cryptographic nonce. If no nonce is provided, the current UNIX timestamp (in milliseconds) is used.

    Returns string

  • Create a valid HMACAuthenticatedPayload object using the supplied key, payload and (optionally) a user defined nonce. If no nonce is supplied, the current UNIX timestamp (in milliseconds) will be used as nonce.

    Parameters

    • key: Buffer

      A cryptographic key. Should be exactly 64 bytes long.

    • payload: unknown

      Arbitrary JSON-stringifiable data.

    • nonce: string = ...

      A cryptographic nonce. If no nonce is provided, the current UNIX timestamp (in milliseconds) is used.

    Returns HMACAuthenticatedPayload

  • createKey(): Buffer
  • Creates a new (random) 64 byte key to be used as HMAC key.

    Returns Buffer

  • validate(key: Buffer, payload: unknown, nonce: string, hmac: string): boolean
  • Computes the correct HMAC of the supplied payload, nonce and compares it to the supplied HMAC. Returns true if and only if they coincide.

    Parameters

    • key: Buffer
    • payload: unknown
    • nonce: string
    • hmac: string

    Returns boolean

Generated using TypeDoc