UNPKG

@acusti/aws-signature-v4

Version:

A lightweight isomorphic module to generate request headers that fulfill the AWS SigV4 signing process

86 lines (85 loc) 3.49 kB
import { type AWSOptions as _AWSOptions, type FetchHeaders, type FetchOptions } from './types.js'; export type AWSOptions = _AWSOptions; type FetchOptionsWithHeaders = { headers: FetchHeaders; } & Omit<FetchOptions, 'headers'>; /** * @private * Create canonical headers * <pre> CanonicalHeaders = CanonicalHeadersEntry0 + CanonicalHeadersEntry1 + ... + CanonicalHeadersEntryN CanonicalHeadersEntry = Lowercase(HeaderName) + ':' + Trimall(HeaderValue) + '\n' </pre> */ declare const getCanonicalHeaders: (headers: FetchHeaders) => string; /** * @private * The list of headers that were included in the canonical headers * For HTTP/1.1 requests, the host header must be included as a signed header. * For HTTP/2 requests that include the :authority header instead of the host header, * you must include the :authority header as a signed header. If you include a date or * x-amz-date header, you must also include that header in the list of signed headers. */ declare const getSignedHeaders: (headers: FetchHeaders) => string; /** * @private * Create a canonical request * Refer to {@link http://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html|Create a Canonical Request} * <pre> CanonicalRequest = HTTPRequestMethod + '\n' + CanonicalURI + '\n' + CanonicalQueryString + '\n' + CanonicalHeaders + '\n' + SignedHeaders + '\n' + HexEncode(Hash(RequestPayload)) </pre> */ declare const getCanonicalString: (resource: string, fetchOptions: FetchOptionsWithHeaders) => Promise<string>; declare const getRegionFromResource: (resource: string) => string; declare const getCredentialScope: ({ dateString, region, service, }: { dateString: string; region: string; service: string; }) => string; /** * @private * Create a string to sign * Refer to {@link http://docs.aws.amazon.com/general/latest/gr/sigv4-create-string-to-sign.html|Create String to Sign} */ declare const getStringToSign: ({ algorithm, canonicalString, dateTimeString, scope, }: { algorithm: string; canonicalString: string; dateTimeString: string; scope: string; }) => Promise<string>; /** * @private * Create signing key * Refer to {@link http://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html|Calculate Signature} */ declare const getSigningKey: ({ dateString, region, secretAccessKey, service, }: { dateString: string; region: string; secretAccessKey: string; service: string; }) => Promise<string | Uint8Array<ArrayBuffer>>; declare const getSignature: (signingKey: string | Uint8Array, stringToSign: string) => Promise<string>; /** * @private * Create authorization headers to include in the HTTP request * Refer to {@link http://docs.aws.amazon.com/general/latest/gr/sigv4-add-signature-to-request.html|Add signature to request} */ declare const getAuthorizationHeader: ({ accessKeyId, algorithm, scope, signature, signedHeaders, }: { accessKeyId: string; algorithm: string; scope: string; signature: string; signedHeaders: string; }) => string; declare const getHeadersWithAuthorization: (resource: string, fetchOptions: FetchOptions, { accessKeyId, region, secretAccessKey, service, sessionToken, }: AWSOptions) => Promise<FetchHeaders>; export { getAuthorizationHeader, getCanonicalHeaders, getCanonicalString, getCredentialScope, getHeadersWithAuthorization, getRegionFromResource, getSignature, getSignedHeaders, getSigningKey, getStringToSign, };