1 | import * as http from 'http';
|
2 | import * as request from 'request';
|
3 |
|
4 | import * as Crypto from './crypto';
|
5 | import * as Utils from './utils';
|
6 | import { Message } from './client';
|
7 |
|
8 | export type CredentialsFunc = (id: string) => Promise<Credentials> | Credentials;
|
9 | export type NonceFunc = (key: string, nonce: string, ts: string) => Promise<void> | void;
|
10 |
|
11 | export interface AuthenticateOptions {
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | hostHeaderName?: string | undefined;
|
19 | |
20 |
|
21 |
|
22 |
|
23 | nonceFunc?: NonceFunc | undefined;
|
24 | |
25 |
|
26 |
|
27 |
|
28 | timestampSkewSec?: number | undefined;
|
29 | |
30 |
|
31 |
|
32 |
|
33 | localtimeOffsetMsec?: number | undefined;
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | payload?: string | undefined;
|
44 | |
45 |
|
46 |
|
47 | host?: string | undefined;
|
48 | |
49 |
|
50 |
|
51 | port?: number | undefined;
|
52 | }
|
53 |
|
54 | export interface Credentials {
|
55 | algorithm: 'sha1' | 'sha256';
|
56 | key: string;
|
57 | user: string;
|
58 | }
|
59 |
|
60 | export interface Authentication {
|
61 | artifacts: Crypto.Artifacts;
|
62 | credentials: Credentials;
|
63 | }
|
64 |
|
65 | export interface HeaderOptions {
|
66 |
|
67 | contentType?: string | undefined;
|
68 |
|
69 | ext?: string | undefined;
|
70 |
|
71 | hash?: string | undefined;
|
72 |
|
73 | payload?: string | undefined;
|
74 | }
|
75 |
|
76 | export type AuthenticateBewitOptions = Pick<
|
77 | AuthenticateOptions,
|
78 | 'hostHeaderName' | 'localtimeOffsetMsec' | 'host' | 'port'
|
79 | >;
|
80 |
|
81 | export interface Bewit {
|
82 | id: string;
|
83 | exp: string;
|
84 | mac: string;
|
85 | ext: string;
|
86 | }
|
87 |
|
88 | export interface AuthenticatedBewit extends AuthenticatedMessage {
|
89 | bewit: Bewit;
|
90 | }
|
91 |
|
92 | export interface AuthenticatedMessage {
|
93 | credentials: Credentials;
|
94 | }
|
95 |
|
96 | export type AuthenticateMessageOptions = Pick<
|
97 | AuthenticateOptions,
|
98 | 'nonceFunc' | 'timestampSkewSec' | 'localtimeOffsetMsec'
|
99 | >;
|
100 |
|
101 | export function authenticate(
|
102 | req: http.IncomingMessage,
|
103 | credentialsFunc: CredentialsFunc,
|
104 | options?: AuthenticateOptions,
|
105 | ): Promise<Authentication>;
|
106 |
|
107 | export function authenticateBewit(
|
108 | req: http.IncomingMessage,
|
109 | credentialsFunc: CredentialsFunc,
|
110 | options?: AuthenticateBewitOptions,
|
111 | ): Promise<AuthenticatedBewit>;
|
112 |
|
113 | export function authenticateMessage(
|
114 | host: string,
|
115 | port: number,
|
116 | message: string,
|
117 | authorization: Message,
|
118 | credentialsFunc: CredentialsFunc,
|
119 | options: AuthenticateMessageOptions,
|
120 | ): Promise<AuthenticatedMessage>;
|
121 |
|
122 | export function authenticatePayload(
|
123 | payload: string,
|
124 | credentials: Credentials,
|
125 | artifacts: Crypto.Artifacts,
|
126 | contentType: string,
|
127 | ): void;
|
128 |
|
129 | export function authenticatePayloadHash(calculatedHash: string, artifacts: Crypto.Artifacts): void;
|
130 |
|
131 | export function header(credentials: Credentials, artifacts: Crypto.Artifacts, options?: HeaderOptions): string;
|