-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
getSigningValues.ts
45 lines (43 loc) · 1.22 KB
/
getSigningValues.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { SignRequestOptions } from '../types';
import { SigningValues } from '../types/signer';
import { getCredentialScope } from './getCredentialScope';
import { getFormattedDates } from './getFormattedDates';
/**
* Extracts common values used for signing both requests and urls.
*
* @param options `SignRequestOptions` object containing values used to construct the signature.
* @returns Common `SigningValues` used for signing.
*
* @internal
*/
export const getSigningValues = ({
credentials,
signingDate = new Date(),
signingRegion,
signingService,
uriEscapePath = true,
}: SignRequestOptions): SigningValues => {
// get properties from credentials
const { accessKeyId, secretAccessKey, sessionToken } = credentials;
// get formatted dates for signing
const { longDate, shortDate } = getFormattedDates(signingDate);
// copy header and set signing properties
const credentialScope = getCredentialScope(
shortDate,
signingRegion,
signingService
);
return {
accessKeyId,
credentialScope,
longDate,
secretAccessKey,
sessionToken,
shortDate,
signingRegion,
signingService,
uriEscapePath,
};
};