UNPKG

2.62 kBTypeScriptView Raw
1import * as http from "http";
2import * as request from "request";
3import * as Crypto from "./crypto";
4
5export interface Credentials {
6 algorithm: "sha1" | "sha256";
7 id: string;
8 key: string;
9}
10
11export interface HeaderOptions {
12 /** Oz application id */
13 app?: string | undefined;
14 /** Payload content-type (ignored if hash provided) */
15 contentType?: string | undefined;
16 credentials: Credentials;
17 /** Oz delegated-by application id */
18 dlg?: string | undefined;
19 /** Application specific data sent via the ext attribute */
20 ext?: string | undefined;
21 /** Pre-calculated payload hash */
22 hash?: string | undefined;
23 /** Time offset to sync with server time (ignored if timestamp provided) */
24 localtimeOffsetMsec?: number | undefined;
25 /** A pre-generated nonce */
26 nonce?: string | undefined;
27 /** UTF-8 encoded string for body hash generation (ignored if hash provided) */
28 payload?: string | undefined;
29 /** A pre-calculated timestamp in seconds */
30 timestamp?: number | undefined;
31}
32
33export interface Header {
34 header: string;
35 artifacts: Crypto.Artifacts;
36}
37
38export interface AuthenticateOptions {
39 /** optional payload received */
40 payload?: string | undefined;
41 /** specifies if a Server-Authorization header is required. Defaults to 'false' */
42 required?: boolean | undefined;
43}
44
45export interface Authentication {
46 headers: Record<string, string>;
47}
48
49export interface BewitOptions {
50 credentials: Credentials;
51 /** Application specific data sent via the ext attribute */
52 ext?: string | undefined;
53 /** Time offset to sync with server time */
54 localtimeOffsetMsec: number;
55 /** TTL in seconds */
56 ttlSec: number;
57}
58
59export interface MessageOptions {
60 credentials: Credentials;
61 /** Time offset to sync with server time (ignored if timestamp provided) */
62 localtimeOffsetMsec: number;
63 /** A pre-generated nonce */
64 nonce: string;
65 /** A pre-calculated timestamp in seconds */
66 timestamp: number;
67}
68
69export interface Message {
70 hash: string;
71 id: string;
72 mac: string;
73 nonce: string;
74 ts: string;
75}
76
77export function authenticate(
78 res: http.IncomingMessage | request.Response,
79 credentials: Credentials,
80 artifacts: Crypto.Artifacts,
81 options?: AuthenticateOptions,
82): Authentication;
83
84export function getBewit(uri: string, options: BewitOptions): string;
85
86export function header(uri: string, method: string, options?: HeaderOptions): Header;
87
88export function message(host: string, port: number, message: string, options?: MessageOptions): Message;