@types/hawk

  • Version 9.0.1
  • Published
  • 15.2 kB
  • 4 dependencies
  • MIT license

Install

npm i @types/hawk
yarn add @types/hawk
pnpm add @types/hawk

Overview

TypeScript definitions for hawk

Index

Functions

function setTimeFunction

setTimeFunction: (fn: () => number) => void;
  • override the now function, e.g., to use sntp

Namespaces

namespace client

module 'lib/client.d.ts' {}
  • Oz application id

function authenticate

authenticate: (
res: http.IncomingMessage | request.Response,
credentials: Credentials,
artifacts: Crypto.Artifacts,
options?: AuthenticateOptions
) => Authentication;

    function getBewit

    getBewit: (uri: string, options: BewitOptions) => string;

      function header

      header: (uri: string, method: string, options?: HeaderOptions) => Header;

        function message

        message: (
        host: string,
        port: number,
        message: string,
        options?: MessageOptions
        ) => Message;

          interface AuthenticateOptions

          interface AuthenticateOptions {}

            property payload

            payload?: string;
            • optional payload received

            property required

            required?: boolean;
            • specifies if a Server-Authorization header is required. Defaults to 'false'

            interface Authentication

            interface Authentication {}

              property headers

              headers: Record<string, string>;

                interface BewitOptions

                interface BewitOptions {}

                  property credentials

                  credentials: Credentials;

                    property ext

                    ext?: string;
                    • Application specific data sent via the ext attribute

                    property localtimeOffsetMsec

                    localtimeOffsetMsec: number;
                    • Time offset to sync with server time

                    property ttlSec

                    ttlSec: number;
                    • TTL in seconds

                    interface Credentials

                    interface Credentials {}

                      property algorithm

                      algorithm: 'sha1' | 'sha256';

                        property id

                        id: string;

                          property key

                          key: string;

                            interface Header

                            interface Header {}

                              property artifacts

                              artifacts: Crypto.Artifacts;

                                property header

                                header: string;

                                  interface HeaderOptions

                                  interface HeaderOptions {}

                                    property app

                                    app?: string;
                                    • Oz application id

                                    property contentType

                                    contentType?: string;
                                    • Payload content-type (ignored if hash provided)

                                    property credentials

                                    credentials: Credentials;

                                      property dlg

                                      dlg?: string;
                                      • Oz delegated-by application id

                                      property ext

                                      ext?: string;
                                      • Application specific data sent via the ext attribute

                                      property hash

                                      hash?: string;
                                      • Pre-calculated payload hash

                                      property localtimeOffsetMsec

                                      localtimeOffsetMsec?: number;
                                      • Time offset to sync with server time (ignored if timestamp provided)

                                      property nonce

                                      nonce?: string;
                                      • A pre-generated nonce

                                      property payload

                                      payload?: string;
                                      • UTF-8 encoded string for body hash generation (ignored if hash provided)

                                      property timestamp

                                      timestamp?: number;
                                      • A pre-calculated timestamp in seconds

                                      interface Message

                                      interface Message {}

                                        property hash

                                        hash: string;

                                          property id

                                          id: string;

                                            property mac

                                            mac: string;

                                              property nonce

                                              nonce: string;

                                                property ts

                                                ts: string;

                                                  interface MessageOptions

                                                  interface MessageOptions {}

                                                    property credentials

                                                    credentials: Credentials;

                                                      property localtimeOffsetMsec

                                                      localtimeOffsetMsec: number;
                                                      • Time offset to sync with server time (ignored if timestamp provided)

                                                      property nonce

                                                      nonce: string;
                                                      • A pre-generated nonce

                                                      property timestamp

                                                      timestamp: number;
                                                      • A pre-calculated timestamp in seconds

                                                      namespace crypto

                                                      module 'lib/crypto.d.ts' {}

                                                        variable algorithms

                                                        const algorithms: string[];

                                                          variable headerVersion

                                                          const headerVersion: string;

                                                            function calculateMac

                                                            calculateMac: (
                                                            type: string,
                                                            credentials: Client.Credentials,
                                                            options: Artifacts
                                                            ) => string;

                                                              function calculatePayloadHash

                                                              calculatePayloadHash: (
                                                              payload: string,
                                                              algorithm: string,
                                                              contentType: string
                                                              ) => string;

                                                                function calculateTsMac

                                                                calculateTsMac: (ts: string, credentials: Client.Credentials) => string;

                                                                  function finalizePayloadHash

                                                                  finalizePayloadHash: (hash: any) => string;

                                                                    function generateNormalizedString

                                                                    generateNormalizedString: (type: string, options: Artifacts) => string;

                                                                      function initializePayloadHash

                                                                      initializePayloadHash: (algorithm: string, contentType: string) => string;

                                                                        function timestampMessage

                                                                        timestampMessage: (
                                                                        credentials: Client.Credentials,
                                                                        localtimeOffsetMsec: number
                                                                        ) => TimestampMessage;

                                                                          interface Artifacts

                                                                          interface Artifacts {}

                                                                            property app

                                                                            app?: string;

                                                                              property dlg

                                                                              dlg?: string;

                                                                                property ext

                                                                                ext?: string;

                                                                                  property hash

                                                                                  hash?: string;

                                                                                    property host

                                                                                    host: string;

                                                                                      property method

                                                                                      method: string;

                                                                                        property nonce

                                                                                        nonce: string;

                                                                                          property port

                                                                                          port: number;

                                                                                            property resource

                                                                                            resource: string;

                                                                                              property ts

                                                                                              ts: string;

                                                                                                interface TimestampMessage

                                                                                                interface TimestampMessage {}

                                                                                                  property ts

                                                                                                  ts: number;

                                                                                                    property tsm

                                                                                                    tsm: string;

                                                                                                      namespace server

                                                                                                      module 'lib/server.d.ts' {}
                                                                                                      • optional header field name, used to override the default 'Host' header when used behind a cache of a proxy. Apache2 changes the value of the 'Host' header while preserving the original (which is what the module must verify) in the 'x-forwarded-host' header field. Only used when passed a node http.ServerRequest object.

                                                                                                      function authenticate

                                                                                                      authenticate: (
                                                                                                      req: any,
                                                                                                      credentialsFunc: CredentialsFunc,
                                                                                                      options?: AuthenticateOptions
                                                                                                      ) => Promise<Authentication>;

                                                                                                        function authenticateBewit

                                                                                                        authenticateBewit: (
                                                                                                        req: any,
                                                                                                        credentialsFunc: CredentialsFunc,
                                                                                                        options?: AuthenticateBewitOptions
                                                                                                        ) => Promise<AuthenticatedBewit>;

                                                                                                          function authenticateMessage

                                                                                                          authenticateMessage: (
                                                                                                          host: string,
                                                                                                          port: number,
                                                                                                          message: string,
                                                                                                          authorization: Message,
                                                                                                          credentialsFunc: CredentialsFunc,
                                                                                                          options: AuthenticateMessageOptions
                                                                                                          ) => Promise<AuthenticatedMessage>;

                                                                                                            function authenticatePayload

                                                                                                            authenticatePayload: (
                                                                                                            payload: string,
                                                                                                            credentials: Credentials,
                                                                                                            artifacts: Crypto.Artifacts,
                                                                                                            contentType: string
                                                                                                            ) => void;

                                                                                                              function authenticatePayloadHash

                                                                                                              authenticatePayloadHash: (
                                                                                                              calculatedHash: string,
                                                                                                              artifacts: Crypto.Artifacts
                                                                                                              ) => void;

                                                                                                                function header

                                                                                                                header: (
                                                                                                                credentials: Credentials,
                                                                                                                artifacts: Crypto.Artifacts,
                                                                                                                options?: HeaderOptions
                                                                                                                ) => string;

                                                                                                                  interface AuthenticatedBewit

                                                                                                                  interface AuthenticatedBewit extends AuthenticatedMessage {}

                                                                                                                    property bewit

                                                                                                                    bewit: Bewit;

                                                                                                                      interface AuthenticatedMessage

                                                                                                                      interface AuthenticatedMessage {}

                                                                                                                        property credentials

                                                                                                                        credentials: Credentials;

                                                                                                                          interface AuthenticateOptions

                                                                                                                          interface AuthenticateOptions {}

                                                                                                                            property host

                                                                                                                            host?: string;
                                                                                                                            • optional host name override. Only used when passed a node request object.

                                                                                                                            property hostHeaderName

                                                                                                                            hostHeaderName?: string;
                                                                                                                            • optional header field name, used to override the default 'Host' header when used behind a cache of a proxy. Apache2 changes the value of the 'Host' header while preserving the original (which is what the module must verify) in the 'x-forwarded-host' header field. Only used when passed a node http.ServerRequest object.

                                                                                                                            property localtimeOffsetMsec

                                                                                                                            localtimeOffsetMsec?: number;
                                                                                                                            • Optional local clock time offset express in a number of milliseconds (positive or negative). Defaults to 0.

                                                                                                                            property nonceFunc

                                                                                                                            nonceFunc?: NonceFunc;
                                                                                                                            • optional nonce validation function. The function signature is async function(key, nonce, ts) and it must return no value for success or throw an error for invalid state.

                                                                                                                            property payload

                                                                                                                            payload?: string;
                                                                                                                            • optional payload for validation. The client calculates the hash value and includes it via the 'hash' header attribute. The server always ensures the value provided has been included in the request MAC. When this option is provided, it validates the hash value itself. Validation is done by calculating a hash value over the entire payload (assuming it has already be normalized to the same format and encoding used by the client to calculate the hash on request). If the payload is not available at the time of authentication, the authenticatePayload() method can be used by passing it the credentials and attributes.hash returned from authenticate().

                                                                                                                            property port

                                                                                                                            port?: number;
                                                                                                                            • optional port override. Only used when passed a node request object.

                                                                                                                            property timestampSkewSec

                                                                                                                            timestampSkewSec?: number;
                                                                                                                            • optional number of seconds of permitted clock skew for incoming timestamps. Defaults to 60 seconds. Provides a +/- skew which means actual allowed window is double the number of seconds.

                                                                                                                            interface Authentication

                                                                                                                            interface Authentication {}

                                                                                                                              property artifacts

                                                                                                                              artifacts: Crypto.Artifacts;

                                                                                                                                property credentials

                                                                                                                                credentials: Credentials;

                                                                                                                                  interface Bewit

                                                                                                                                  interface Bewit {}

                                                                                                                                    property exp

                                                                                                                                    exp: string;

                                                                                                                                      property ext

                                                                                                                                      ext: string;

                                                                                                                                        property id

                                                                                                                                        id: string;

                                                                                                                                          property mac

                                                                                                                                          mac: string;

                                                                                                                                            interface Credentials

                                                                                                                                            interface Credentials {}

                                                                                                                                              property algorithm

                                                                                                                                              algorithm: 'sha1' | 'sha256';

                                                                                                                                                property key

                                                                                                                                                key: string;

                                                                                                                                                  property user

                                                                                                                                                  user: string;

                                                                                                                                                    interface HeaderOptions

                                                                                                                                                    interface HeaderOptions {}

                                                                                                                                                      property contentType

                                                                                                                                                      contentType?: string;
                                                                                                                                                      • Payload content-type (ignored if hash provided)

                                                                                                                                                      property ext

                                                                                                                                                      ext?: string;
                                                                                                                                                      • Application specific data sent via the ext attribute

                                                                                                                                                      property hash

                                                                                                                                                      hash?: string;
                                                                                                                                                      • Pre-calculated payload hash

                                                                                                                                                      property payload

                                                                                                                                                      payload?: string;
                                                                                                                                                      • UTF-8 encoded string for body hash generation (ignored if hash provided)

                                                                                                                                                      type AuthenticateBewitOptions

                                                                                                                                                      type AuthenticateBewitOptions = Pick<
                                                                                                                                                      AuthenticateOptions,
                                                                                                                                                      'hostHeaderName' | 'localtimeOffsetMsec' | 'host' | 'port'
                                                                                                                                                      >;

                                                                                                                                                        type AuthenticateMessageOptions

                                                                                                                                                        type AuthenticateMessageOptions = Pick<
                                                                                                                                                        AuthenticateOptions,
                                                                                                                                                        'nonceFunc' | 'timestampSkewSec' | 'localtimeOffsetMsec'
                                                                                                                                                        >;

                                                                                                                                                          type CredentialsFunc

                                                                                                                                                          type CredentialsFunc = (id: string) => Promise<Credentials> | Credentials;

                                                                                                                                                            type NonceFunc

                                                                                                                                                            type NonceFunc = (key: string, nonce: string, ts: string) => Promise<void> | void;

                                                                                                                                                              namespace uri

                                                                                                                                                              namespace uri {}

                                                                                                                                                                variable authenticate

                                                                                                                                                                const authenticate: (
                                                                                                                                                                req: any,
                                                                                                                                                                credentialsFunc: server.CredentialsFunc,
                                                                                                                                                                options?: server.AuthenticateBewitOptions
                                                                                                                                                                ) => Promise<server.AuthenticatedBewit>;

                                                                                                                                                                  variable getBewit

                                                                                                                                                                  const getBewit: (uri: string, options: client.BewitOptions) => string;

                                                                                                                                                                    namespace utils

                                                                                                                                                                    module 'lib/utils.d.ts' {}
                                                                                                                                                                    • Limit the length of uris and headers to avoid a DoS attack on string matching

                                                                                                                                                                    variable limits

                                                                                                                                                                    const limits: { maxMatchLength: number };

                                                                                                                                                                      variable version

                                                                                                                                                                      const version: string;

                                                                                                                                                                        function now

                                                                                                                                                                        now: (localtimeOffsetMsec: number) => number;

                                                                                                                                                                          function nowSecs

                                                                                                                                                                          nowSecs: (localtimeOffsetMsec: number) => number;

                                                                                                                                                                            function parseAuthorizationHeader

                                                                                                                                                                            parseAuthorizationHeader: (
                                                                                                                                                                            header: string,
                                                                                                                                                                            keys?: string[]
                                                                                                                                                                            ) => Record<string, string>;

                                                                                                                                                                              function parseContentType

                                                                                                                                                                              parseContentType: (header?: string) => string;

                                                                                                                                                                                function parseHost

                                                                                                                                                                                parseHost: (
                                                                                                                                                                                req: http.RequestOptions | https.RequestOptions,
                                                                                                                                                                                hostHeaderName?: string
                                                                                                                                                                                ) => Host | null;

                                                                                                                                                                                  function parseRequest

                                                                                                                                                                                  parseRequest: (
                                                                                                                                                                                  req: http.RequestOptions | https.RequestOptions,
                                                                                                                                                                                  options?: ParseRequestOptions
                                                                                                                                                                                  ) => CustomRequest;

                                                                                                                                                                                    function unauthorized

                                                                                                                                                                                    unauthorized: (
                                                                                                                                                                                    message?: string,
                                                                                                                                                                                    attributes?: string | Boom.unauthorized.Attributes
                                                                                                                                                                                    ) => Boom.Boom & Boom.unauthorized.MissingAuth;

                                                                                                                                                                                      interface CustomRequest

                                                                                                                                                                                      interface CustomRequest {}

                                                                                                                                                                                        property authorization

                                                                                                                                                                                        authorization: string;

                                                                                                                                                                                          property contentType

                                                                                                                                                                                          contentType: string;

                                                                                                                                                                                            property host

                                                                                                                                                                                            host: string;

                                                                                                                                                                                              property method

                                                                                                                                                                                              method: string;

                                                                                                                                                                                                property port

                                                                                                                                                                                                port: number;

                                                                                                                                                                                                  property url

                                                                                                                                                                                                  url: string;

                                                                                                                                                                                                    interface Host

                                                                                                                                                                                                    interface Host {}

                                                                                                                                                                                                      property name

                                                                                                                                                                                                      name: string;

                                                                                                                                                                                                        property port

                                                                                                                                                                                                        port: number;

                                                                                                                                                                                                          interface ParseRequestOptions

                                                                                                                                                                                                          interface ParseRequestOptions {}

                                                                                                                                                                                                            property host

                                                                                                                                                                                                            host?: string;

                                                                                                                                                                                                              property hostHeaderName

                                                                                                                                                                                                              hostHeaderName?: string;

                                                                                                                                                                                                                property name

                                                                                                                                                                                                                name?: string;

                                                                                                                                                                                                                  property port

                                                                                                                                                                                                                  port?: number;

                                                                                                                                                                                                                    Package Files (5)

                                                                                                                                                                                                                    Dependencies (4)

                                                                                                                                                                                                                    Dev Dependencies (0)

                                                                                                                                                                                                                    No dev dependencies.

                                                                                                                                                                                                                    Peer Dependencies (0)

                                                                                                                                                                                                                    No peer dependencies.

                                                                                                                                                                                                                    Badge

                                                                                                                                                                                                                    To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                                    You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/hawk.

                                                                                                                                                                                                                    • Markdown
                                                                                                                                                                                                                      [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/hawk)
                                                                                                                                                                                                                    • HTML
                                                                                                                                                                                                                      <a href="https://www.jsdocs.io/package/@types/hawk"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>