Function verifyEnvelope

  • The receiving side: the three headers, the raw payload and the receiver's clock.

    Parameters

    • secret: string

      The destination's nonempty secret, used as UTF-8 bytes without base64 decoding.

    • headers: Record<string, undefined | string | string[]>

      The delivery's headers; the timestamp must contain only ASCII digits and is authenticated literally.

    • payload: string

      The body exactly as it arrived, before any parse.

    • nowMs: number

      The receiver's clock, in milliseconds since the epoch.

    • options: {
          windowMs?: number;
          names?: EnvelopeHeaderNames;
      } = {}

      windowMs, how far the delivery's time may be from nowMs (ENVELOPE_WINDOW_MS when absent); names, the header names (DEFAULT_ENVELOPE_HEADERS when absent).

    Returns {
        valid: boolean;
        error?: string;
    }

    { valid: true }, or valid: false with why: an empty secret, a header missing, a bad timestamp, a timestamp outside the window (including a NaN clock or window), or a signature that does not match.

    • valid: boolean
    • Optional error?: string