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