UNPKG

2.46 kBTypeScriptView Raw
1import CryptoJS = require('crypto-js');
2import * as Crypto from './crypto';
3import * as Client from './client';
4
5declare namespace hawk {
6 namespace client {
7 function authenticate(
8 request: XMLHttpRequest | Response,
9 credentials: Client.Credentials,
10 artifacts: Crypto.Artifacts,
11 options?: Client.AuthenticateOptions,
12 ): boolean;
13 function authenticateTimestamp(
14 message: string,
15 credentials: Client.Credentials,
16 updateClock?: boolean,
17 ): boolean;
18 function bewit(uri: string, options?: Client.BewitOptions): string;
19 function header(uri: string | utils.ParsedUri, method: string, options?: Client.HeaderOptions): Client.Header;
20 function message(host: string, port: number, message: string, options: Client.MessageOptions): Client.Message;
21 }
22
23 namespace crypto {
24 const headerVersion: string;
25 const algorithms: string[];
26
27 function calculateMac(type: string, credentials: Client.Credentials, options: Crypto.Artifacts): string;
28 function calculatePayloadHash(payload: string, algorithm: string, contentType: string): string;
29 function calculateTsMac(ts: string, credentials: Client.Credentials): string;
30 function generateNormalizedString(type: string, options: Crypto.Artifacts): string;
31 }
32
33 namespace utils {
34 interface ParsedUri {
35 host: string;
36 port: string;
37 resource: string;
38 }
39
40 const storage: Storage;
41 /** `scheme://credentials@host:port/resource#fragment` */
42 const uriRegex: RegExp;
43
44 function base64urlEncode(value: string | Buffer, encoding?: BufferEncoding): string;
45 function escapeHeaderAttribute(attribute: string): string;
46 function getNtpSecOffset(): number;
47 function now(localtimeOffsetMsec?: number): number;
48 function nowSec(localtimeOffsetMsec?: number): number;
49 function parseAuthorizationHeader(header: string, keys?: string[]): Record<string, string>;
50 function parseContentType(header?: string): string;
51 function parseUri(input: string): ParsedUri;
52 function randomString(size: number): string;
53 function setNtpSecOffset(offset: number): void;
54 function setStorage(storage: Storage): void;
55 }
56
57 namespace crypto {
58 const utils: typeof CryptoJS;
59 }
60}
61
62export = hawk;