UNPKG

@akamai-consulting/edgegrid-js-fetch

Version:

Signing and fetch library the Akamai OPEN EdgeGrid Authentication scheme in a JS environment that supports the fetch spec

70 lines (69 loc) 2.89 kB
export declare const MAX_BODY = 131072; /** * Create timestamp with format "yyyyMMddTHH:mm:ss+0000" * * @returns {string} Timestamp in format "yyyyMMddTHH:mm:ss+0000" */ export declare function createTimestamp(): string; /** * Returns the hash of the contents of a stream * * @param {ReadableStream} stream A stream to read * @returns {Promise<string>} hash of contents of stream */ export declare function streamHash(stream: ReadableStream): Promise<string>; /** * Returns data to be signed for a request * @param {Request} request The request Object to sign. * @param {String} authHeader The authorization header. * @param {String} [contentHash] The hash of the body content to include in the signature. * * @returns {Promise<String>} A Promise resolving to a string containing the data to be signed * */ export declare function dataToSign(request: Request, authHeader: string, contentHash?: string): Promise<string>; /** * Determines if the http status code represents a redirect * * @param {number} statusCode The status codefrom an HTTP request * * @returns {boolean} `true` if the status code represents a redirect. Else `false` * */ export declare function isRedirect(statusCode: number): boolean; /** * Returns an HMAC signature, using SHA256 hash algorigthm * @param {string} data The data to be signed * @param {string} key The key used to sign data * * @returns {Promise<string>} The signature * */ export declare function base64HmacSha256(data: string, key: string): Promise<string>; /** * Creates a String containing a tab delimited set of headers. * @param {Object} headers Object containing the headers to add to the set. * @returns {String} String containing a tab delimited set of headers. */ export declare function canonicalizeHeaders(headers: { [x: string]: string; }): string; /** * Creates a String containing a tab delimited set of headers. * @param {string} timestamp Timestamp in format "yyyyMMddTHH:mm:ss+0000" * @param {string} clientSecret Client secret * * @returns {Promise<string>} Promise resolving to the signing key */ export declare function signingKey(timestamp: string, clientSecret: string): Promise<string>; /** * * @param {Object} request The request Object. * @param {string} timestamp The timestamp with format "yyyyMMddTHH:mm:ss+0000". * @param {string} clientSecret The client secret value from the .edgerc file. * @param {string} authHeader The authorization header. * @param {String} [contentHash] The hash of the body content to include in the signature. * * @returns {Promise<string>} A Promise resolving to a string represented the requests signature */ export declare function signRequestWithContentHash(request: Request, timestamp: string, clientSecret: string, authHeader: string, contentHash?: string): Promise<string>;