working rss feed to nostr publish

This commit is contained in:
2023-11-24 00:43:28 -05:00
parent 06edcb57ae
commit 88d2f9cfec
8396 changed files with 783105 additions and 0 deletions
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+4
View File
@@ -0,0 +1,4 @@
# @smithy/signature-v4
[![NPM version](https://img.shields.io/npm/v/@smithy/signature-v4/latest.svg)](https://www.npmjs.com/package/@smithy/signature-v4)
[![NPM downloads](https://img.shields.io/npm/dm/@smithy/signature-v4.svg)](https://www.npmjs.com/package/@smithy/signature-v4)
+194
View File
@@ -0,0 +1,194 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SignatureV4 = void 0;
const eventstream_codec_1 = require("@smithy/eventstream-codec");
const util_hex_encoding_1 = require("@smithy/util-hex-encoding");
const util_middleware_1 = require("@smithy/util-middleware");
const util_utf8_1 = require("@smithy/util-utf8");
const constants_1 = require("./constants");
const credentialDerivation_1 = require("./credentialDerivation");
const getCanonicalHeaders_1 = require("./getCanonicalHeaders");
const getCanonicalQuery_1 = require("./getCanonicalQuery");
const getPayloadHash_1 = require("./getPayloadHash");
const headerUtil_1 = require("./headerUtil");
const moveHeadersToQuery_1 = require("./moveHeadersToQuery");
const prepareRequest_1 = require("./prepareRequest");
const utilDate_1 = require("./utilDate");
class SignatureV4 {
constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath = true, }) {
this.headerMarshaller = new eventstream_codec_1.HeaderMarshaller(util_utf8_1.toUtf8, util_utf8_1.fromUtf8);
this.service = service;
this.sha256 = sha256;
this.uriEscapePath = uriEscapePath;
this.applyChecksum = typeof applyChecksum === "boolean" ? applyChecksum : true;
this.regionProvider = (0, util_middleware_1.normalizeProvider)(region);
this.credentialProvider = (0, util_middleware_1.normalizeProvider)(credentials);
}
async presign(originalRequest, options = {}) {
const { signingDate = new Date(), expiresIn = 3600, unsignableHeaders, unhoistableHeaders, signableHeaders, signingRegion, signingService, } = options;
const credentials = await this.credentialProvider();
this.validateResolvedCredentials(credentials);
const region = signingRegion !== null && signingRegion !== void 0 ? signingRegion : (await this.regionProvider());
const { longDate, shortDate } = formatDate(signingDate);
if (expiresIn > constants_1.MAX_PRESIGNED_TTL) {
return Promise.reject("Signature version 4 presigned URLs" + " must have an expiration date less than one week in" + " the future");
}
const scope = (0, credentialDerivation_1.createScope)(shortDate, region, signingService !== null && signingService !== void 0 ? signingService : this.service);
const request = (0, moveHeadersToQuery_1.moveHeadersToQuery)((0, prepareRequest_1.prepareRequest)(originalRequest), { unhoistableHeaders });
if (credentials.sessionToken) {
request.query[constants_1.TOKEN_QUERY_PARAM] = credentials.sessionToken;
}
request.query[constants_1.ALGORITHM_QUERY_PARAM] = constants_1.ALGORITHM_IDENTIFIER;
request.query[constants_1.CREDENTIAL_QUERY_PARAM] = `${credentials.accessKeyId}/${scope}`;
request.query[constants_1.AMZ_DATE_QUERY_PARAM] = longDate;
request.query[constants_1.EXPIRES_QUERY_PARAM] = expiresIn.toString(10);
const canonicalHeaders = (0, getCanonicalHeaders_1.getCanonicalHeaders)(request, unsignableHeaders, signableHeaders);
request.query[constants_1.SIGNED_HEADERS_QUERY_PARAM] = getCanonicalHeaderList(canonicalHeaders);
request.query[constants_1.SIGNATURE_QUERY_PARAM] = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate, signingService), this.createCanonicalRequest(request, canonicalHeaders, await (0, getPayloadHash_1.getPayloadHash)(originalRequest, this.sha256)));
return request;
}
async sign(toSign, options) {
if (typeof toSign === "string") {
return this.signString(toSign, options);
}
else if (toSign.headers && toSign.payload) {
return this.signEvent(toSign, options);
}
else if (toSign.message) {
return this.signMessage(toSign, options);
}
else {
return this.signRequest(toSign, options);
}
}
async signEvent({ headers, payload }, { signingDate = new Date(), priorSignature, signingRegion, signingService }) {
const region = signingRegion !== null && signingRegion !== void 0 ? signingRegion : (await this.regionProvider());
const { shortDate, longDate } = formatDate(signingDate);
const scope = (0, credentialDerivation_1.createScope)(shortDate, region, signingService !== null && signingService !== void 0 ? signingService : this.service);
const hashedPayload = await (0, getPayloadHash_1.getPayloadHash)({ headers: {}, body: payload }, this.sha256);
const hash = new this.sha256();
hash.update(headers);
const hashedHeaders = (0, util_hex_encoding_1.toHex)(await hash.digest());
const stringToSign = [
constants_1.EVENT_ALGORITHM_IDENTIFIER,
longDate,
scope,
priorSignature,
hashedHeaders,
hashedPayload,
].join("\n");
return this.signString(stringToSign, { signingDate, signingRegion: region, signingService });
}
async signMessage(signableMessage, { signingDate = new Date(), signingRegion, signingService }) {
const promise = this.signEvent({
headers: this.headerMarshaller.format(signableMessage.message.headers),
payload: signableMessage.message.body,
}, {
signingDate,
signingRegion,
signingService,
priorSignature: signableMessage.priorSignature,
});
return promise.then((signature) => {
return { message: signableMessage.message, signature };
});
}
async signString(stringToSign, { signingDate = new Date(), signingRegion, signingService } = {}) {
const credentials = await this.credentialProvider();
this.validateResolvedCredentials(credentials);
const region = signingRegion !== null && signingRegion !== void 0 ? signingRegion : (await this.regionProvider());
const { shortDate } = formatDate(signingDate);
const hash = new this.sha256(await this.getSigningKey(credentials, region, shortDate, signingService));
hash.update((0, util_utf8_1.toUint8Array)(stringToSign));
return (0, util_hex_encoding_1.toHex)(await hash.digest());
}
async signRequest(requestToSign, { signingDate = new Date(), signableHeaders, unsignableHeaders, signingRegion, signingService, } = {}) {
const credentials = await this.credentialProvider();
this.validateResolvedCredentials(credentials);
const region = signingRegion !== null && signingRegion !== void 0 ? signingRegion : (await this.regionProvider());
const request = (0, prepareRequest_1.prepareRequest)(requestToSign);
const { longDate, shortDate } = formatDate(signingDate);
const scope = (0, credentialDerivation_1.createScope)(shortDate, region, signingService !== null && signingService !== void 0 ? signingService : this.service);
request.headers[constants_1.AMZ_DATE_HEADER] = longDate;
if (credentials.sessionToken) {
request.headers[constants_1.TOKEN_HEADER] = credentials.sessionToken;
}
const payloadHash = await (0, getPayloadHash_1.getPayloadHash)(request, this.sha256);
if (!(0, headerUtil_1.hasHeader)(constants_1.SHA256_HEADER, request.headers) && this.applyChecksum) {
request.headers[constants_1.SHA256_HEADER] = payloadHash;
}
const canonicalHeaders = (0, getCanonicalHeaders_1.getCanonicalHeaders)(request, unsignableHeaders, signableHeaders);
const signature = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate, signingService), this.createCanonicalRequest(request, canonicalHeaders, payloadHash));
request.headers[constants_1.AUTH_HEADER] =
`${constants_1.ALGORITHM_IDENTIFIER} ` +
`Credential=${credentials.accessKeyId}/${scope}, ` +
`SignedHeaders=${getCanonicalHeaderList(canonicalHeaders)}, ` +
`Signature=${signature}`;
return request;
}
createCanonicalRequest(request, canonicalHeaders, payloadHash) {
const sortedHeaders = Object.keys(canonicalHeaders).sort();
return `${request.method}
${this.getCanonicalPath(request)}
${(0, getCanonicalQuery_1.getCanonicalQuery)(request)}
${sortedHeaders.map((name) => `${name}:${canonicalHeaders[name]}`).join("\n")}
${sortedHeaders.join(";")}
${payloadHash}`;
}
async createStringToSign(longDate, credentialScope, canonicalRequest) {
const hash = new this.sha256();
hash.update((0, util_utf8_1.toUint8Array)(canonicalRequest));
const hashedRequest = await hash.digest();
return `${constants_1.ALGORITHM_IDENTIFIER}
${longDate}
${credentialScope}
${(0, util_hex_encoding_1.toHex)(hashedRequest)}`;
}
getCanonicalPath({ path }) {
if (this.uriEscapePath) {
const normalizedPathSegments = [];
for (const pathSegment of path.split("/")) {
if ((pathSegment === null || pathSegment === void 0 ? void 0 : pathSegment.length) === 0)
continue;
if (pathSegment === ".")
continue;
if (pathSegment === "..") {
normalizedPathSegments.pop();
}
else {
normalizedPathSegments.push(pathSegment);
}
}
const normalizedPath = `${(path === null || path === void 0 ? void 0 : path.startsWith("/")) ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && (path === null || path === void 0 ? void 0 : path.endsWith("/")) ? "/" : ""}`;
const doubleEncoded = encodeURIComponent(normalizedPath);
return doubleEncoded.replace(/%2F/g, "/");
}
return path;
}
async getSignature(longDate, credentialScope, keyPromise, canonicalRequest) {
const stringToSign = await this.createStringToSign(longDate, credentialScope, canonicalRequest);
const hash = new this.sha256(await keyPromise);
hash.update((0, util_utf8_1.toUint8Array)(stringToSign));
return (0, util_hex_encoding_1.toHex)(await hash.digest());
}
getSigningKey(credentials, region, shortDate, service) {
return (0, credentialDerivation_1.getSigningKey)(this.sha256, credentials, shortDate, region, service || this.service);
}
validateResolvedCredentials(credentials) {
if (typeof credentials !== "object" ||
typeof credentials.accessKeyId !== "string" ||
typeof credentials.secretAccessKey !== "string") {
throw new Error("Resolved credential object is not valid");
}
}
}
exports.SignatureV4 = SignatureV4;
const formatDate = (now) => {
const longDate = (0, utilDate_1.iso8601)(now).replace(/[\-:]/g, "");
return {
longDate,
shortDate: longDate.slice(0, 8),
};
};
const getCanonicalHeaderList = (headers) => Object.keys(headers).sort().join(";");
+17
View File
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloneQuery = exports.cloneRequest = void 0;
const cloneRequest = ({ headers, query, ...rest }) => ({
...rest,
headers: { ...headers },
query: query ? (0, exports.cloneQuery)(query) : undefined,
});
exports.cloneRequest = cloneRequest;
const cloneQuery = (query) => Object.keys(query).reduce((carry, paramName) => {
const param = query[paramName];
return {
...carry,
[paramName]: Array.isArray(param) ? [...param] : param,
};
}, {});
exports.cloneQuery = cloneQuery;
+46
View File
@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAX_PRESIGNED_TTL = exports.KEY_TYPE_IDENTIFIER = exports.MAX_CACHE_SIZE = exports.UNSIGNED_PAYLOAD = exports.EVENT_ALGORITHM_IDENTIFIER = exports.ALGORITHM_IDENTIFIER_V4A = exports.ALGORITHM_IDENTIFIER = exports.UNSIGNABLE_PATTERNS = exports.SEC_HEADER_PATTERN = exports.PROXY_HEADER_PATTERN = exports.ALWAYS_UNSIGNABLE_HEADERS = exports.HOST_HEADER = exports.TOKEN_HEADER = exports.SHA256_HEADER = exports.SIGNATURE_HEADER = exports.GENERATED_HEADERS = exports.DATE_HEADER = exports.AMZ_DATE_HEADER = exports.AUTH_HEADER = exports.REGION_SET_PARAM = exports.TOKEN_QUERY_PARAM = exports.SIGNATURE_QUERY_PARAM = exports.EXPIRES_QUERY_PARAM = exports.SIGNED_HEADERS_QUERY_PARAM = exports.AMZ_DATE_QUERY_PARAM = exports.CREDENTIAL_QUERY_PARAM = exports.ALGORITHM_QUERY_PARAM = void 0;
exports.ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
exports.CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
exports.AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
exports.SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
exports.EXPIRES_QUERY_PARAM = "X-Amz-Expires";
exports.SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
exports.TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
exports.REGION_SET_PARAM = "X-Amz-Region-Set";
exports.AUTH_HEADER = "authorization";
exports.AMZ_DATE_HEADER = exports.AMZ_DATE_QUERY_PARAM.toLowerCase();
exports.DATE_HEADER = "date";
exports.GENERATED_HEADERS = [exports.AUTH_HEADER, exports.AMZ_DATE_HEADER, exports.DATE_HEADER];
exports.SIGNATURE_HEADER = exports.SIGNATURE_QUERY_PARAM.toLowerCase();
exports.SHA256_HEADER = "x-amz-content-sha256";
exports.TOKEN_HEADER = exports.TOKEN_QUERY_PARAM.toLowerCase();
exports.HOST_HEADER = "host";
exports.ALWAYS_UNSIGNABLE_HEADERS = {
authorization: true,
"cache-control": true,
connection: true,
expect: true,
from: true,
"keep-alive": true,
"max-forwards": true,
pragma: true,
referer: true,
te: true,
trailer: true,
"transfer-encoding": true,
upgrade: true,
"user-agent": true,
"x-amzn-trace-id": true,
};
exports.PROXY_HEADER_PATTERN = /^proxy-/;
exports.SEC_HEADER_PATTERN = /^sec-/;
exports.UNSIGNABLE_PATTERNS = [/^proxy-/i, /^sec-/i];
exports.ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
exports.ALGORITHM_IDENTIFIER_V4A = "AWS4-ECDSA-P256-SHA256";
exports.EVENT_ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256-PAYLOAD";
exports.UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
exports.MAX_CACHE_SIZE = 50;
exports.KEY_TYPE_IDENTIFIER = "aws4_request";
exports.MAX_PRESIGNED_TTL = 60 * 60 * 24 * 7;
+39
View File
@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.clearCredentialCache = exports.getSigningKey = exports.createScope = void 0;
const util_hex_encoding_1 = require("@smithy/util-hex-encoding");
const util_utf8_1 = require("@smithy/util-utf8");
const constants_1 = require("./constants");
const signingKeyCache = {};
const cacheQueue = [];
const createScope = (shortDate, region, service) => `${shortDate}/${region}/${service}/${constants_1.KEY_TYPE_IDENTIFIER}`;
exports.createScope = createScope;
const getSigningKey = async (sha256Constructor, credentials, shortDate, region, service) => {
const credsHash = await hmac(sha256Constructor, credentials.secretAccessKey, credentials.accessKeyId);
const cacheKey = `${shortDate}:${region}:${service}:${(0, util_hex_encoding_1.toHex)(credsHash)}:${credentials.sessionToken}`;
if (cacheKey in signingKeyCache) {
return signingKeyCache[cacheKey];
}
cacheQueue.push(cacheKey);
while (cacheQueue.length > constants_1.MAX_CACHE_SIZE) {
delete signingKeyCache[cacheQueue.shift()];
}
let key = `AWS4${credentials.secretAccessKey}`;
for (const signable of [shortDate, region, service, constants_1.KEY_TYPE_IDENTIFIER]) {
key = await hmac(sha256Constructor, key, signable);
}
return (signingKeyCache[cacheKey] = key);
};
exports.getSigningKey = getSigningKey;
const clearCredentialCache = () => {
cacheQueue.length = 0;
Object.keys(signingKeyCache).forEach((cacheKey) => {
delete signingKeyCache[cacheKey];
});
};
exports.clearCredentialCache = clearCredentialCache;
const hmac = (ctor, secret, data) => {
const hash = new ctor(secret);
hash.update((0, util_utf8_1.toUint8Array)(data));
return hash.digest();
};
+24
View File
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCanonicalHeaders = void 0;
const constants_1 = require("./constants");
const getCanonicalHeaders = ({ headers }, unsignableHeaders, signableHeaders) => {
const canonical = {};
for (const headerName of Object.keys(headers).sort()) {
if (headers[headerName] == undefined) {
continue;
}
const canonicalHeaderName = headerName.toLowerCase();
if (canonicalHeaderName in constants_1.ALWAYS_UNSIGNABLE_HEADERS ||
(unsignableHeaders === null || unsignableHeaders === void 0 ? void 0 : unsignableHeaders.has(canonicalHeaderName)) ||
constants_1.PROXY_HEADER_PATTERN.test(canonicalHeaderName) ||
constants_1.SEC_HEADER_PATTERN.test(canonicalHeaderName)) {
if (!signableHeaders || (signableHeaders && !signableHeaders.has(canonicalHeaderName))) {
continue;
}
}
canonical[canonicalHeaderName] = headers[headerName].trim().replace(/\s+/g, " ");
}
return canonical;
};
exports.getCanonicalHeaders = getCanonicalHeaders;
+31
View File
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCanonicalQuery = void 0;
const util_uri_escape_1 = require("@smithy/util-uri-escape");
const constants_1 = require("./constants");
const getCanonicalQuery = ({ query = {} }) => {
const keys = [];
const serialized = {};
for (const key of Object.keys(query).sort()) {
if (key.toLowerCase() === constants_1.SIGNATURE_HEADER) {
continue;
}
keys.push(key);
const value = query[key];
if (typeof value === "string") {
serialized[key] = `${(0, util_uri_escape_1.escapeUri)(key)}=${(0, util_uri_escape_1.escapeUri)(value)}`;
}
else if (Array.isArray(value)) {
serialized[key] = value
.slice(0)
.reduce((encoded, value) => encoded.concat([`${(0, util_uri_escape_1.escapeUri)(key)}=${(0, util_uri_escape_1.escapeUri)(value)}`]), [])
.sort()
.join("&");
}
}
return keys
.map((key) => serialized[key])
.filter((serialized) => serialized)
.join("&");
};
exports.getCanonicalQuery = getCanonicalQuery;
+24
View File
@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPayloadHash = void 0;
const is_array_buffer_1 = require("@smithy/is-array-buffer");
const util_hex_encoding_1 = require("@smithy/util-hex-encoding");
const util_utf8_1 = require("@smithy/util-utf8");
const constants_1 = require("./constants");
const getPayloadHash = async ({ headers, body }, hashConstructor) => {
for (const headerName of Object.keys(headers)) {
if (headerName.toLowerCase() === constants_1.SHA256_HEADER) {
return headers[headerName];
}
}
if (body == undefined) {
return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
}
else if (typeof body === "string" || ArrayBuffer.isView(body) || (0, is_array_buffer_1.isArrayBuffer)(body)) {
const hashCtor = new hashConstructor();
hashCtor.update((0, util_utf8_1.toUint8Array)(body));
return (0, util_hex_encoding_1.toHex)(await hashCtor.digest());
}
return constants_1.UNSIGNED_PAYLOAD;
};
exports.getPayloadHash = getPayloadHash;
+32
View File
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteHeader = exports.getHeaderValue = exports.hasHeader = void 0;
const hasHeader = (soughtHeader, headers) => {
soughtHeader = soughtHeader.toLowerCase();
for (const headerName of Object.keys(headers)) {
if (soughtHeader === headerName.toLowerCase()) {
return true;
}
}
return false;
};
exports.hasHeader = hasHeader;
const getHeaderValue = (soughtHeader, headers) => {
soughtHeader = soughtHeader.toLowerCase();
for (const headerName of Object.keys(headers)) {
if (soughtHeader === headerName.toLowerCase()) {
return headers[headerName];
}
}
return undefined;
};
exports.getHeaderValue = getHeaderValue;
const deleteHeader = (soughtHeader, headers) => {
soughtHeader = soughtHeader.toLowerCase();
for (const headerName of Object.keys(headers)) {
if (soughtHeader === headerName.toLowerCase()) {
delete headers[headerName];
}
}
};
exports.deleteHeader = deleteHeader;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareRequest = exports.moveHeadersToQuery = exports.getPayloadHash = exports.getCanonicalQuery = exports.getCanonicalHeaders = void 0;
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./SignatureV4"), exports);
var getCanonicalHeaders_1 = require("./getCanonicalHeaders");
Object.defineProperty(exports, "getCanonicalHeaders", { enumerable: true, get: function () { return getCanonicalHeaders_1.getCanonicalHeaders; } });
var getCanonicalQuery_1 = require("./getCanonicalQuery");
Object.defineProperty(exports, "getCanonicalQuery", { enumerable: true, get: function () { return getCanonicalQuery_1.getCanonicalQuery; } });
var getPayloadHash_1 = require("./getPayloadHash");
Object.defineProperty(exports, "getPayloadHash", { enumerable: true, get: function () { return getPayloadHash_1.getPayloadHash; } });
var moveHeadersToQuery_1 = require("./moveHeadersToQuery");
Object.defineProperty(exports, "moveHeadersToQuery", { enumerable: true, get: function () { return moveHeadersToQuery_1.moveHeadersToQuery; } });
var prepareRequest_1 = require("./prepareRequest");
Object.defineProperty(exports, "prepareRequest", { enumerable: true, get: function () { return prepareRequest_1.prepareRequest; } });
tslib_1.__exportStar(require("./credentialDerivation"), exports);
+21
View File
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.moveHeadersToQuery = void 0;
const cloneRequest_1 = require("./cloneRequest");
const moveHeadersToQuery = (request, options = {}) => {
var _a;
const { headers, query = {} } = typeof request.clone === "function" ? request.clone() : (0, cloneRequest_1.cloneRequest)(request);
for (const name of Object.keys(headers)) {
const lname = name.toLowerCase();
if (lname.slice(0, 6) === "x-amz-" && !((_a = options.unhoistableHeaders) === null || _a === void 0 ? void 0 : _a.has(lname))) {
query[name] = headers[name];
delete headers[name];
}
}
return {
...request,
headers,
query,
};
};
exports.moveHeadersToQuery = moveHeadersToQuery;
+15
View File
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareRequest = void 0;
const cloneRequest_1 = require("./cloneRequest");
const constants_1 = require("./constants");
const prepareRequest = (request) => {
request = typeof request.clone === "function" ? request.clone() : (0, cloneRequest_1.cloneRequest)(request);
for (const headerName of Object.keys(request.headers)) {
if (constants_1.GENERATED_HEADERS.indexOf(headerName.toLowerCase()) > -1) {
delete request.headers[headerName];
}
}
return request;
};
exports.prepareRequest = prepareRequest;
+402
View File
@@ -0,0 +1,402 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.requests = exports.signingDate = exports.credentials = exports.service = exports.region = void 0;
exports.region = "us-east-1";
exports.service = "service";
exports.credentials = {
accessKeyId: "AKIDEXAMPLE",
secretAccessKey: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
};
exports.signingDate = new Date("2015-08-30T12:36:00Z");
exports.requests = [
{
name: "get-header-key-duplicate",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value2,value2,value1",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=c9d5ea9f3f72853aea855b47ea873832890dbdd183b4468f858259531a5138ea",
},
{
name: "get-header-value-multiline",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value1,value2,value3",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=ba17b383a53190154eb5fa66a1b836cc297cc0a3d70a5d00705980573d8ff790",
},
{
name: "get-header-value-order",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value4,value1,value3,value2",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=08c7e5a9acfcfeb3ab6b2185e75ce8b1deb5e634ec47601a50643f830c755c01",
},
{
name: "get-header-value-trim",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value1",
"my-header2": '"a b c"',
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;my-header2;x-amz-date, Signature=acc3ed3afb60bb290fc8d2dd0098b9911fcaa05412b367055dee359757a9c736",
},
{
name: "get-unreserved",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=07ef7494c76fa4850883e2b006601f940f8a34d404d0cfa977f52a65bbf5f24f",
},
{
name: "get-utf8",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/ሴ",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=8318018e0b0f223aa2bbf98705b62bb787dc9c0e678f255a891fd03141be5d85",
},
{
name: "get-vanilla",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31",
},
{
name: "get-vanilla-empty-query-key",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {
Param1: "value1",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=a67d582fa61cc504c4bae71f336f98b97f1ea3c7a6bfe1b6e45aec72011b9aeb",
},
{
name: "get-vanilla-query",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31",
},
{
name: "get-vanilla-query-order-key-case",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {
Param2: "value2",
Param1: "value1",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=b97d918cfa904a5beff61c982a1b6f458b799221646efd99d3219ec94cdf2500",
},
{
name: "get-vanilla-query-unreserved",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {
"-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz": "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=9c3e54bfcdf0b19771a7f523ee5669cdf59bc7cc0884027167c21bb143a40197",
},
{
name: "get-vanilla-utf8-query",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {
: "bar",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=2cdec8eed098649ff3a119c94853b13c643bcf08f8b0a1d91e12c9027818dd04",
},
{
name: "post-header-key-case",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b",
},
{
name: "post-header-key-sort",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value1",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=c5410059b04c1ee005303aed430f6e6645f61f4dc9e1461ec8f8916fdf18852c",
},
{
name: "post-header-value-case",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "VALUE1",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=cdbc9802e29d2942e5e10b5bccfdd67c5f22c7c4e8ae67b53629efa58b974b7d",
},
{
name: "post-sts-header-after",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b",
},
{
name: "post-sts-header-before",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
"x-amz-security-token": "AQoDYXdzEPT//////////wEXAMPLEtc764bNrC9SAPBSM22wDOk4x4HIZ8j4FZTwdQWLWsKWHGBuFqwAeMicRXmxfpSPfIeoIYRqTflfKD8YUuwthAx7mSEI/qkPpKPi/kMcGdQrmGdeehM4IC1NtBmUpp2wUE8phUZampKsburEDy0KPkyQDYwT7WZ0wq5VSXDvp75YU9HFvlRd8Tx6q6fE8YQcHNVXAkiY9q6d+xo0rKwT38xVqr7ZD0u0iPPkUL64lIZbqBAz+scqKmlzm8FDrypNC9Yjc8fPOLn9FX9KSYvKTr4rvx3iSIlTJabIQwj2ICCR/oLxBA==",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=85d96828115b5dc0cfc3bd16ad9e210dd772bbebba041836c64533a82be05ead",
},
{
name: "post-vanilla",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b",
},
{
name: "post-vanilla-empty-query-value",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {
Param1: "value1",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=28038455d6de14eafc1f9222cf5aa6f1a96197d7deb8263271d420d138af7f11",
},
{
name: "post-vanilla-query",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {
Param1: "value1",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=28038455d6de14eafc1f9222cf5aa6f1a96197d7deb8263271d420d138af7f11",
},
{
name: "post-vanilla-query-nonunreserved",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {
"@#$%^": "",
"+": '/,?><`";:\\|][{}',
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=66c82657c86e26fb25238d0e69f011edc4c6df5ae71119d7cb98ed9b87393c1e",
},
{
name: "post-vanilla-query-space",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {
p: "",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=e71688addb58a26418614085fb730ba3faa623b461c17f48f2fbdb9361b94a9b",
},
{
name: "post-x-www-form-urlencoded",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
"content-type": "application/x-www-form-urlencoded",
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
body: "Param1=value1",
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=ff11897932ad3f4e8b18135d722051e5ac45fc38421b1da7b9d196a0fe09473a",
},
{
name: "post-x-www-form-urlencoded-parameters",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
"content-type": "application/x-www-form-urlencoded; charset=utf8",
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
body: "Param1=value1",
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=1a72ec8f64bd914b0e42e42607c7fbce7fb2c7465f63e3092b3b0d39fa77a6fe",
},
];
+20
View File
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toDate = exports.iso8601 = void 0;
const iso8601 = (time) => (0, exports.toDate)(time)
.toISOString()
.replace(/\.\d{3}Z$/, "Z");
exports.iso8601 = iso8601;
const toDate = (time) => {
if (typeof time === "number") {
return new Date(time * 1000);
}
if (typeof time === "string") {
if (Number(time)) {
return new Date(Number(time) * 1000);
}
return new Date(time);
}
return time;
};
exports.toDate = toDate;
+190
View File
@@ -0,0 +1,190 @@
import { HeaderMarshaller } from "@smithy/eventstream-codec";
import { toHex } from "@smithy/util-hex-encoding";
import { normalizeProvider } from "@smithy/util-middleware";
import { fromUtf8, toUint8Array, toUtf8 } from "@smithy/util-utf8";
import { ALGORITHM_IDENTIFIER, ALGORITHM_QUERY_PARAM, AMZ_DATE_HEADER, AMZ_DATE_QUERY_PARAM, AUTH_HEADER, CREDENTIAL_QUERY_PARAM, EVENT_ALGORITHM_IDENTIFIER, EXPIRES_QUERY_PARAM, MAX_PRESIGNED_TTL, SHA256_HEADER, SIGNATURE_QUERY_PARAM, SIGNED_HEADERS_QUERY_PARAM, TOKEN_HEADER, TOKEN_QUERY_PARAM, } from "./constants";
import { createScope, getSigningKey } from "./credentialDerivation";
import { getCanonicalHeaders } from "./getCanonicalHeaders";
import { getCanonicalQuery } from "./getCanonicalQuery";
import { getPayloadHash } from "./getPayloadHash";
import { hasHeader } from "./headerUtil";
import { moveHeadersToQuery } from "./moveHeadersToQuery";
import { prepareRequest } from "./prepareRequest";
import { iso8601 } from "./utilDate";
export class SignatureV4 {
constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath = true, }) {
this.headerMarshaller = new HeaderMarshaller(toUtf8, fromUtf8);
this.service = service;
this.sha256 = sha256;
this.uriEscapePath = uriEscapePath;
this.applyChecksum = typeof applyChecksum === "boolean" ? applyChecksum : true;
this.regionProvider = normalizeProvider(region);
this.credentialProvider = normalizeProvider(credentials);
}
async presign(originalRequest, options = {}) {
const { signingDate = new Date(), expiresIn = 3600, unsignableHeaders, unhoistableHeaders, signableHeaders, signingRegion, signingService, } = options;
const credentials = await this.credentialProvider();
this.validateResolvedCredentials(credentials);
const region = signingRegion ?? (await this.regionProvider());
const { longDate, shortDate } = formatDate(signingDate);
if (expiresIn > MAX_PRESIGNED_TTL) {
return Promise.reject("Signature version 4 presigned URLs" + " must have an expiration date less than one week in" + " the future");
}
const scope = createScope(shortDate, region, signingService ?? this.service);
const request = moveHeadersToQuery(prepareRequest(originalRequest), { unhoistableHeaders });
if (credentials.sessionToken) {
request.query[TOKEN_QUERY_PARAM] = credentials.sessionToken;
}
request.query[ALGORITHM_QUERY_PARAM] = ALGORITHM_IDENTIFIER;
request.query[CREDENTIAL_QUERY_PARAM] = `${credentials.accessKeyId}/${scope}`;
request.query[AMZ_DATE_QUERY_PARAM] = longDate;
request.query[EXPIRES_QUERY_PARAM] = expiresIn.toString(10);
const canonicalHeaders = getCanonicalHeaders(request, unsignableHeaders, signableHeaders);
request.query[SIGNED_HEADERS_QUERY_PARAM] = getCanonicalHeaderList(canonicalHeaders);
request.query[SIGNATURE_QUERY_PARAM] = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate, signingService), this.createCanonicalRequest(request, canonicalHeaders, await getPayloadHash(originalRequest, this.sha256)));
return request;
}
async sign(toSign, options) {
if (typeof toSign === "string") {
return this.signString(toSign, options);
}
else if (toSign.headers && toSign.payload) {
return this.signEvent(toSign, options);
}
else if (toSign.message) {
return this.signMessage(toSign, options);
}
else {
return this.signRequest(toSign, options);
}
}
async signEvent({ headers, payload }, { signingDate = new Date(), priorSignature, signingRegion, signingService }) {
const region = signingRegion ?? (await this.regionProvider());
const { shortDate, longDate } = formatDate(signingDate);
const scope = createScope(shortDate, region, signingService ?? this.service);
const hashedPayload = await getPayloadHash({ headers: {}, body: payload }, this.sha256);
const hash = new this.sha256();
hash.update(headers);
const hashedHeaders = toHex(await hash.digest());
const stringToSign = [
EVENT_ALGORITHM_IDENTIFIER,
longDate,
scope,
priorSignature,
hashedHeaders,
hashedPayload,
].join("\n");
return this.signString(stringToSign, { signingDate, signingRegion: region, signingService });
}
async signMessage(signableMessage, { signingDate = new Date(), signingRegion, signingService }) {
const promise = this.signEvent({
headers: this.headerMarshaller.format(signableMessage.message.headers),
payload: signableMessage.message.body,
}, {
signingDate,
signingRegion,
signingService,
priorSignature: signableMessage.priorSignature,
});
return promise.then((signature) => {
return { message: signableMessage.message, signature };
});
}
async signString(stringToSign, { signingDate = new Date(), signingRegion, signingService } = {}) {
const credentials = await this.credentialProvider();
this.validateResolvedCredentials(credentials);
const region = signingRegion ?? (await this.regionProvider());
const { shortDate } = formatDate(signingDate);
const hash = new this.sha256(await this.getSigningKey(credentials, region, shortDate, signingService));
hash.update(toUint8Array(stringToSign));
return toHex(await hash.digest());
}
async signRequest(requestToSign, { signingDate = new Date(), signableHeaders, unsignableHeaders, signingRegion, signingService, } = {}) {
const credentials = await this.credentialProvider();
this.validateResolvedCredentials(credentials);
const region = signingRegion ?? (await this.regionProvider());
const request = prepareRequest(requestToSign);
const { longDate, shortDate } = formatDate(signingDate);
const scope = createScope(shortDate, region, signingService ?? this.service);
request.headers[AMZ_DATE_HEADER] = longDate;
if (credentials.sessionToken) {
request.headers[TOKEN_HEADER] = credentials.sessionToken;
}
const payloadHash = await getPayloadHash(request, this.sha256);
if (!hasHeader(SHA256_HEADER, request.headers) && this.applyChecksum) {
request.headers[SHA256_HEADER] = payloadHash;
}
const canonicalHeaders = getCanonicalHeaders(request, unsignableHeaders, signableHeaders);
const signature = await this.getSignature(longDate, scope, this.getSigningKey(credentials, region, shortDate, signingService), this.createCanonicalRequest(request, canonicalHeaders, payloadHash));
request.headers[AUTH_HEADER] =
`${ALGORITHM_IDENTIFIER} ` +
`Credential=${credentials.accessKeyId}/${scope}, ` +
`SignedHeaders=${getCanonicalHeaderList(canonicalHeaders)}, ` +
`Signature=${signature}`;
return request;
}
createCanonicalRequest(request, canonicalHeaders, payloadHash) {
const sortedHeaders = Object.keys(canonicalHeaders).sort();
return `${request.method}
${this.getCanonicalPath(request)}
${getCanonicalQuery(request)}
${sortedHeaders.map((name) => `${name}:${canonicalHeaders[name]}`).join("\n")}
${sortedHeaders.join(";")}
${payloadHash}`;
}
async createStringToSign(longDate, credentialScope, canonicalRequest) {
const hash = new this.sha256();
hash.update(toUint8Array(canonicalRequest));
const hashedRequest = await hash.digest();
return `${ALGORITHM_IDENTIFIER}
${longDate}
${credentialScope}
${toHex(hashedRequest)}`;
}
getCanonicalPath({ path }) {
if (this.uriEscapePath) {
const normalizedPathSegments = [];
for (const pathSegment of path.split("/")) {
if (pathSegment?.length === 0)
continue;
if (pathSegment === ".")
continue;
if (pathSegment === "..") {
normalizedPathSegments.pop();
}
else {
normalizedPathSegments.push(pathSegment);
}
}
const normalizedPath = `${path?.startsWith("/") ? "/" : ""}${normalizedPathSegments.join("/")}${normalizedPathSegments.length > 0 && path?.endsWith("/") ? "/" : ""}`;
const doubleEncoded = encodeURIComponent(normalizedPath);
return doubleEncoded.replace(/%2F/g, "/");
}
return path;
}
async getSignature(longDate, credentialScope, keyPromise, canonicalRequest) {
const stringToSign = await this.createStringToSign(longDate, credentialScope, canonicalRequest);
const hash = new this.sha256(await keyPromise);
hash.update(toUint8Array(stringToSign));
return toHex(await hash.digest());
}
getSigningKey(credentials, region, shortDate, service) {
return getSigningKey(this.sha256, credentials, shortDate, region, service || this.service);
}
validateResolvedCredentials(credentials) {
if (typeof credentials !== "object" ||
typeof credentials.accessKeyId !== "string" ||
typeof credentials.secretAccessKey !== "string") {
throw new Error("Resolved credential object is not valid");
}
}
}
const formatDate = (now) => {
const longDate = iso8601(now).replace(/[\-:]/g, "");
return {
longDate,
shortDate: longDate.slice(0, 8),
};
};
const getCanonicalHeaderList = (headers) => Object.keys(headers).sort().join(";");
+12
View File
@@ -0,0 +1,12 @@
export const cloneRequest = ({ headers, query, ...rest }) => ({
...rest,
headers: { ...headers },
query: query ? cloneQuery(query) : undefined,
});
export const cloneQuery = (query) => Object.keys(query).reduce((carry, paramName) => {
const param = query[paramName];
return {
...carry,
[paramName]: Array.isArray(param) ? [...param] : param,
};
}, {});
+43
View File
@@ -0,0 +1,43 @@
export const ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
export const CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
export const AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
export const SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
export const EXPIRES_QUERY_PARAM = "X-Amz-Expires";
export const SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
export const TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
export const REGION_SET_PARAM = "X-Amz-Region-Set";
export const AUTH_HEADER = "authorization";
export const AMZ_DATE_HEADER = AMZ_DATE_QUERY_PARAM.toLowerCase();
export const DATE_HEADER = "date";
export const GENERATED_HEADERS = [AUTH_HEADER, AMZ_DATE_HEADER, DATE_HEADER];
export const SIGNATURE_HEADER = SIGNATURE_QUERY_PARAM.toLowerCase();
export const SHA256_HEADER = "x-amz-content-sha256";
export const TOKEN_HEADER = TOKEN_QUERY_PARAM.toLowerCase();
export const HOST_HEADER = "host";
export const ALWAYS_UNSIGNABLE_HEADERS = {
authorization: true,
"cache-control": true,
connection: true,
expect: true,
from: true,
"keep-alive": true,
"max-forwards": true,
pragma: true,
referer: true,
te: true,
trailer: true,
"transfer-encoding": true,
upgrade: true,
"user-agent": true,
"x-amzn-trace-id": true,
};
export const PROXY_HEADER_PATTERN = /^proxy-/;
export const SEC_HEADER_PATTERN = /^sec-/;
export const UNSIGNABLE_PATTERNS = [/^proxy-/i, /^sec-/i];
export const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
export const ALGORITHM_IDENTIFIER_V4A = "AWS4-ECDSA-P256-SHA256";
export const EVENT_ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256-PAYLOAD";
export const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
export const MAX_CACHE_SIZE = 50;
export const KEY_TYPE_IDENTIFIER = "aws4_request";
export const MAX_PRESIGNED_TTL = 60 * 60 * 24 * 7;
+33
View File
@@ -0,0 +1,33 @@
import { toHex } from "@smithy/util-hex-encoding";
import { toUint8Array } from "@smithy/util-utf8";
import { KEY_TYPE_IDENTIFIER, MAX_CACHE_SIZE } from "./constants";
const signingKeyCache = {};
const cacheQueue = [];
export const createScope = (shortDate, region, service) => `${shortDate}/${region}/${service}/${KEY_TYPE_IDENTIFIER}`;
export const getSigningKey = async (sha256Constructor, credentials, shortDate, region, service) => {
const credsHash = await hmac(sha256Constructor, credentials.secretAccessKey, credentials.accessKeyId);
const cacheKey = `${shortDate}:${region}:${service}:${toHex(credsHash)}:${credentials.sessionToken}`;
if (cacheKey in signingKeyCache) {
return signingKeyCache[cacheKey];
}
cacheQueue.push(cacheKey);
while (cacheQueue.length > MAX_CACHE_SIZE) {
delete signingKeyCache[cacheQueue.shift()];
}
let key = `AWS4${credentials.secretAccessKey}`;
for (const signable of [shortDate, region, service, KEY_TYPE_IDENTIFIER]) {
key = await hmac(sha256Constructor, key, signable);
}
return (signingKeyCache[cacheKey] = key);
};
export const clearCredentialCache = () => {
cacheQueue.length = 0;
Object.keys(signingKeyCache).forEach((cacheKey) => {
delete signingKeyCache[cacheKey];
});
};
const hmac = (ctor, secret, data) => {
const hash = new ctor(secret);
hash.update(toUint8Array(data));
return hash.digest();
};
+20
View File
@@ -0,0 +1,20 @@
import { ALWAYS_UNSIGNABLE_HEADERS, PROXY_HEADER_PATTERN, SEC_HEADER_PATTERN } from "./constants";
export const getCanonicalHeaders = ({ headers }, unsignableHeaders, signableHeaders) => {
const canonical = {};
for (const headerName of Object.keys(headers).sort()) {
if (headers[headerName] == undefined) {
continue;
}
const canonicalHeaderName = headerName.toLowerCase();
if (canonicalHeaderName in ALWAYS_UNSIGNABLE_HEADERS ||
unsignableHeaders?.has(canonicalHeaderName) ||
PROXY_HEADER_PATTERN.test(canonicalHeaderName) ||
SEC_HEADER_PATTERN.test(canonicalHeaderName)) {
if (!signableHeaders || (signableHeaders && !signableHeaders.has(canonicalHeaderName))) {
continue;
}
}
canonical[canonicalHeaderName] = headers[headerName].trim().replace(/\s+/g, " ");
}
return canonical;
};
+27
View File
@@ -0,0 +1,27 @@
import { escapeUri } from "@smithy/util-uri-escape";
import { SIGNATURE_HEADER } from "./constants";
export const getCanonicalQuery = ({ query = {} }) => {
const keys = [];
const serialized = {};
for (const key of Object.keys(query).sort()) {
if (key.toLowerCase() === SIGNATURE_HEADER) {
continue;
}
keys.push(key);
const value = query[key];
if (typeof value === "string") {
serialized[key] = `${escapeUri(key)}=${escapeUri(value)}`;
}
else if (Array.isArray(value)) {
serialized[key] = value
.slice(0)
.reduce((encoded, value) => encoded.concat([`${escapeUri(key)}=${escapeUri(value)}`]), [])
.sort()
.join("&");
}
}
return keys
.map((key) => serialized[key])
.filter((serialized) => serialized)
.join("&");
};
+20
View File
@@ -0,0 +1,20 @@
import { isArrayBuffer } from "@smithy/is-array-buffer";
import { toHex } from "@smithy/util-hex-encoding";
import { toUint8Array } from "@smithy/util-utf8";
import { SHA256_HEADER, UNSIGNED_PAYLOAD } from "./constants";
export const getPayloadHash = async ({ headers, body }, hashConstructor) => {
for (const headerName of Object.keys(headers)) {
if (headerName.toLowerCase() === SHA256_HEADER) {
return headers[headerName];
}
}
if (body == undefined) {
return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
}
else if (typeof body === "string" || ArrayBuffer.isView(body) || isArrayBuffer(body)) {
const hashCtor = new hashConstructor();
hashCtor.update(toUint8Array(body));
return toHex(await hashCtor.digest());
}
return UNSIGNED_PAYLOAD;
};
+26
View File
@@ -0,0 +1,26 @@
export const hasHeader = (soughtHeader, headers) => {
soughtHeader = soughtHeader.toLowerCase();
for (const headerName of Object.keys(headers)) {
if (soughtHeader === headerName.toLowerCase()) {
return true;
}
}
return false;
};
export const getHeaderValue = (soughtHeader, headers) => {
soughtHeader = soughtHeader.toLowerCase();
for (const headerName of Object.keys(headers)) {
if (soughtHeader === headerName.toLowerCase()) {
return headers[headerName];
}
}
return undefined;
};
export const deleteHeader = (soughtHeader, headers) => {
soughtHeader = soughtHeader.toLowerCase();
for (const headerName of Object.keys(headers)) {
if (soughtHeader === headerName.toLowerCase()) {
delete headers[headerName];
}
}
};
+7
View File
@@ -0,0 +1,7 @@
export * from "./SignatureV4";
export { getCanonicalHeaders } from "./getCanonicalHeaders";
export { getCanonicalQuery } from "./getCanonicalQuery";
export { getPayloadHash } from "./getPayloadHash";
export { moveHeadersToQuery } from "./moveHeadersToQuery";
export { prepareRequest } from "./prepareRequest";
export * from "./credentialDerivation";
+16
View File
@@ -0,0 +1,16 @@
import { cloneRequest } from "./cloneRequest";
export const moveHeadersToQuery = (request, options = {}) => {
const { headers, query = {} } = typeof request.clone === "function" ? request.clone() : cloneRequest(request);
for (const name of Object.keys(headers)) {
const lname = name.toLowerCase();
if (lname.slice(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) {
query[name] = headers[name];
delete headers[name];
}
}
return {
...request,
headers,
query,
};
};
+11
View File
@@ -0,0 +1,11 @@
import { cloneRequest } from "./cloneRequest";
import { GENERATED_HEADERS } from "./constants";
export const prepareRequest = (request) => {
request = typeof request.clone === "function" ? request.clone() : cloneRequest(request);
for (const headerName of Object.keys(request.headers)) {
if (GENERATED_HEADERS.indexOf(headerName.toLowerCase()) > -1) {
delete request.headers[headerName];
}
}
return request;
};
+399
View File
@@ -0,0 +1,399 @@
export const region = "us-east-1";
export const service = "service";
export const credentials = {
accessKeyId: "AKIDEXAMPLE",
secretAccessKey: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
};
export const signingDate = new Date("2015-08-30T12:36:00Z");
export const requests = [
{
name: "get-header-key-duplicate",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value2,value2,value1",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=c9d5ea9f3f72853aea855b47ea873832890dbdd183b4468f858259531a5138ea",
},
{
name: "get-header-value-multiline",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value1,value2,value3",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=ba17b383a53190154eb5fa66a1b836cc297cc0a3d70a5d00705980573d8ff790",
},
{
name: "get-header-value-order",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value4,value1,value3,value2",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=08c7e5a9acfcfeb3ab6b2185e75ce8b1deb5e634ec47601a50643f830c755c01",
},
{
name: "get-header-value-trim",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value1",
"my-header2": '"a b c"',
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;my-header2;x-amz-date, Signature=acc3ed3afb60bb290fc8d2dd0098b9911fcaa05412b367055dee359757a9c736",
},
{
name: "get-unreserved",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=07ef7494c76fa4850883e2b006601f940f8a34d404d0cfa977f52a65bbf5f24f",
},
{
name: "get-utf8",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/ሴ",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=8318018e0b0f223aa2bbf98705b62bb787dc9c0e678f255a891fd03141be5d85",
},
{
name: "get-vanilla",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31",
},
{
name: "get-vanilla-empty-query-key",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {
Param1: "value1",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=a67d582fa61cc504c4bae71f336f98b97f1ea3c7a6bfe1b6e45aec72011b9aeb",
},
{
name: "get-vanilla-query",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5fa00fa31553b73ebf1942676e86291e8372ff2a2260956d9b8aae1d763fbf31",
},
{
name: "get-vanilla-query-order-key-case",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {
Param2: "value2",
Param1: "value1",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=b97d918cfa904a5beff61c982a1b6f458b799221646efd99d3219ec94cdf2500",
},
{
name: "get-vanilla-query-unreserved",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {
"-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz": "-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=9c3e54bfcdf0b19771a7f523ee5669cdf59bc7cc0884027167c21bb143a40197",
},
{
name: "get-vanilla-utf8-query",
request: {
protocol: "https:",
method: "GET",
hostname: "example.amazonaws.com",
query: {
: "bar",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=2cdec8eed098649ff3a119c94853b13c643bcf08f8b0a1d91e12c9027818dd04",
},
{
name: "post-header-key-case",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b",
},
{
name: "post-header-key-sort",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "value1",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=c5410059b04c1ee005303aed430f6e6645f61f4dc9e1461ec8f8916fdf18852c",
},
{
name: "post-header-value-case",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"my-header1": "VALUE1",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;my-header1;x-amz-date, Signature=cdbc9802e29d2942e5e10b5bccfdd67c5f22c7c4e8ae67b53629efa58b974b7d",
},
{
name: "post-sts-header-after",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b",
},
{
name: "post-sts-header-before",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
"x-amz-security-token": "AQoDYXdzEPT//////////wEXAMPLEtc764bNrC9SAPBSM22wDOk4x4HIZ8j4FZTwdQWLWsKWHGBuFqwAeMicRXmxfpSPfIeoIYRqTflfKD8YUuwthAx7mSEI/qkPpKPi/kMcGdQrmGdeehM4IC1NtBmUpp2wUE8phUZampKsburEDy0KPkyQDYwT7WZ0wq5VSXDvp75YU9HFvlRd8Tx6q6fE8YQcHNVXAkiY9q6d+xo0rKwT38xVqr7ZD0u0iPPkUL64lIZbqBAz+scqKmlzm8FDrypNC9Yjc8fPOLn9FX9KSYvKTr4rvx3iSIlTJabIQwj2ICCR/oLxBA==",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date;x-amz-security-token, Signature=85d96828115b5dc0cfc3bd16ad9e210dd772bbebba041836c64533a82be05ead",
},
{
name: "post-vanilla",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=5da7c1a2acd57cee7505fc6676e4e544621c30862966e37dddb68e92efbe5d6b",
},
{
name: "post-vanilla-empty-query-value",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {
Param1: "value1",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=28038455d6de14eafc1f9222cf5aa6f1a96197d7deb8263271d420d138af7f11",
},
{
name: "post-vanilla-query",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {
Param1: "value1",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=28038455d6de14eafc1f9222cf5aa6f1a96197d7deb8263271d420d138af7f11",
},
{
name: "post-vanilla-query-nonunreserved",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {
"@#$%^": "",
"+": '/,?><`";:\\|][{}',
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=66c82657c86e26fb25238d0e69f011edc4c6df5ae71119d7cb98ed9b87393c1e",
},
{
name: "post-vanilla-query-space",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {
p: "",
},
headers: {
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=host;x-amz-date, Signature=e71688addb58a26418614085fb730ba3faa623b461c17f48f2fbdb9361b94a9b",
},
{
name: "post-x-www-form-urlencoded",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
"content-type": "application/x-www-form-urlencoded",
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
body: "Param1=value1",
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=ff11897932ad3f4e8b18135d722051e5ac45fc38421b1da7b9d196a0fe09473a",
},
{
name: "post-x-www-form-urlencoded-parameters",
request: {
protocol: "https:",
method: "POST",
hostname: "example.amazonaws.com",
query: {},
headers: {
"content-type": "application/x-www-form-urlencoded; charset=utf8",
host: "example.amazonaws.com",
"x-amz-date": "20150830T123600Z",
},
body: "Param1=value1",
path: "/",
},
authorization: "AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=1a72ec8f64bd914b0e42e42607c7fbce7fb2c7465f63e3092b3b0d39fa77a6fe",
},
];
+15
View File
@@ -0,0 +1,15 @@
export const iso8601 = (time) => toDate(time)
.toISOString()
.replace(/\.\d{3}Z$/, "Z");
export const toDate = (time) => {
if (typeof time === "number") {
return new Date(time * 1000);
}
if (typeof time === "string") {
if (Number(time)) {
return new Date(Number(time) * 1000);
}
return new Date(time);
}
return time;
};
+67
View File
@@ -0,0 +1,67 @@
import { AwsCredentialIdentity, ChecksumConstructor, EventSigner, EventSigningArguments, FormattedEvent, HashConstructor, HttpRequest, MessageSigner, Provider, RequestPresigner, RequestPresigningArguments, RequestSigner, RequestSigningArguments, SignableMessage, SignedMessage, SigningArguments, StringSigner } from "@smithy/types";
export interface SignatureV4Init {
/**
* The service signing name.
*/
service: string;
/**
* The region name or a function that returns a promise that will be
* resolved with the region name.
*/
region: string | Provider<string>;
/**
* The credentials with which the request should be signed or a function
* that returns a promise that will be resolved with credentials.
*/
credentials: AwsCredentialIdentity | Provider<AwsCredentialIdentity>;
/**
* A constructor function for a hash object that will calculate SHA-256 HMAC
* checksums.
*/
sha256?: ChecksumConstructor | HashConstructor;
/**
* Whether to uri-escape the request URI path as part of computing the
* canonical request string. This is required for every AWS service, except
* Amazon S3, as of late 2017.
*
* @default [true]
*/
uriEscapePath?: boolean;
/**
* Whether to calculate a checksum of the request body and include it as
* either a request header (when signing) or as a query string parameter
* (when presigning). This is required for AWS Glacier and Amazon S3 and optional for
* every other AWS service as of late 2017.
*
* @default [true]
*/
applyChecksum?: boolean;
}
export interface SignatureV4CryptoInit {
sha256: ChecksumConstructor | HashConstructor;
}
export declare class SignatureV4 implements RequestPresigner, RequestSigner, StringSigner, EventSigner, MessageSigner {
private readonly service;
private readonly regionProvider;
private readonly credentialProvider;
private readonly sha256;
private readonly uriEscapePath;
private readonly applyChecksum;
private readonly headerMarshaller;
constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath, }: SignatureV4Init & SignatureV4CryptoInit);
presign(originalRequest: HttpRequest, options?: RequestPresigningArguments): Promise<HttpRequest>;
sign(stringToSign: string, options?: SigningArguments): Promise<string>;
sign(event: FormattedEvent, options: EventSigningArguments): Promise<string>;
sign(event: SignableMessage, options: SigningArguments): Promise<SignedMessage>;
sign(requestToSign: HttpRequest, options?: RequestSigningArguments): Promise<HttpRequest>;
private signEvent;
signMessage(signableMessage: SignableMessage, { signingDate, signingRegion, signingService }: SigningArguments): Promise<SignedMessage>;
private signString;
private signRequest;
private createCanonicalRequest;
private createStringToSign;
private getCanonicalPath;
private getSignature;
private getSigningKey;
private validateResolvedCredentials;
}
+6
View File
@@ -0,0 +1,6 @@
import { HttpRequest, QueryParameterBag } from "@smithy/types";
/**
* @internal
*/
export declare const cloneRequest: ({ headers, query, ...rest }: HttpRequest) => HttpRequest;
export declare const cloneQuery: (query: QueryParameterBag) => QueryParameterBag;
+43
View File
@@ -0,0 +1,43 @@
export declare const ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
export declare const CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
export declare const AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
export declare const SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
export declare const EXPIRES_QUERY_PARAM = "X-Amz-Expires";
export declare const SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
export declare const TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
export declare const REGION_SET_PARAM = "X-Amz-Region-Set";
export declare const AUTH_HEADER = "authorization";
export declare const AMZ_DATE_HEADER: string;
export declare const DATE_HEADER = "date";
export declare const GENERATED_HEADERS: string[];
export declare const SIGNATURE_HEADER: string;
export declare const SHA256_HEADER = "x-amz-content-sha256";
export declare const TOKEN_HEADER: string;
export declare const HOST_HEADER = "host";
export declare const ALWAYS_UNSIGNABLE_HEADERS: {
authorization: boolean;
"cache-control": boolean;
connection: boolean;
expect: boolean;
from: boolean;
"keep-alive": boolean;
"max-forwards": boolean;
pragma: boolean;
referer: boolean;
te: boolean;
trailer: boolean;
"transfer-encoding": boolean;
upgrade: boolean;
"user-agent": boolean;
"x-amzn-trace-id": boolean;
};
export declare const PROXY_HEADER_PATTERN: RegExp;
export declare const SEC_HEADER_PATTERN: RegExp;
export declare const UNSIGNABLE_PATTERNS: RegExp[];
export declare const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
export declare const ALGORITHM_IDENTIFIER_V4A = "AWS4-ECDSA-P256-SHA256";
export declare const EVENT_ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256-PAYLOAD";
export declare const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
export declare const MAX_CACHE_SIZE = 50;
export declare const KEY_TYPE_IDENTIFIER = "aws4_request";
export declare const MAX_PRESIGNED_TTL: number;
+26
View File
@@ -0,0 +1,26 @@
import { AwsCredentialIdentity, ChecksumConstructor, HashConstructor } from "@smithy/types";
/**
* Create a string describing the scope of credentials used to sign a request.
*
* @param shortDate The current calendar date in the form YYYYMMDD.
* @param region The AWS region in which the service resides.
* @param service The service to which the signed request is being sent.
*/
export declare const createScope: (shortDate: string, region: string, service: string) => string;
/**
* Derive a signing key from its composite parts
*
* @param sha256Constructor A constructor function that can instantiate SHA-256
* hash objects.
* @param credentials The credentials with which the request will be
* signed.
* @param shortDate The current calendar date in the form YYYYMMDD.
* @param region The AWS region in which the service resides.
* @param service The service to which the signed request is being
* sent.
*/
export declare const getSigningKey: (sha256Constructor: ChecksumConstructor | HashConstructor, credentials: AwsCredentialIdentity, shortDate: string, region: string, service: string) => Promise<Uint8Array>;
/**
* @internal
*/
export declare const clearCredentialCache: () => void;
@@ -0,0 +1,5 @@
import { HeaderBag, HttpRequest } from "@smithy/types";
/**
* @private
*/
export declare const getCanonicalHeaders: ({ headers }: HttpRequest, unsignableHeaders?: Set<string>, signableHeaders?: Set<string>) => HeaderBag;
+5
View File
@@ -0,0 +1,5 @@
import { HttpRequest } from "@smithy/types";
/**
* @private
*/
export declare const getCanonicalQuery: ({ query }: HttpRequest) => string;
+5
View File
@@ -0,0 +1,5 @@
import { ChecksumConstructor, HashConstructor, HttpRequest } from "@smithy/types";
/**
* @private
*/
export declare const getPayloadHash: ({ headers, body }: HttpRequest, hashConstructor: ChecksumConstructor | HashConstructor) => Promise<string>;
+4
View File
@@ -0,0 +1,4 @@
import { HeaderBag } from "@smithy/types";
export declare const hasHeader: (soughtHeader: string, headers: HeaderBag) => boolean;
export declare const getHeaderValue: (soughtHeader: string, headers: HeaderBag) => string | undefined;
export declare const deleteHeader: (soughtHeader: string, headers: HeaderBag) => void;
+7
View File
@@ -0,0 +1,7 @@
export * from "./SignatureV4";
export { getCanonicalHeaders } from "./getCanonicalHeaders";
export { getCanonicalQuery } from "./getCanonicalQuery";
export { getPayloadHash } from "./getPayloadHash";
export { moveHeadersToQuery } from "./moveHeadersToQuery";
export { prepareRequest } from "./prepareRequest";
export * from "./credentialDerivation";
+9
View File
@@ -0,0 +1,9 @@
import { HttpRequest, QueryParameterBag } from "@smithy/types";
/**
* @private
*/
export declare const moveHeadersToQuery: (request: HttpRequest, options?: {
unhoistableHeaders?: Set<string>;
}) => HttpRequest & {
query: QueryParameterBag;
};
+5
View File
@@ -0,0 +1,5 @@
import { HttpRequest } from "@smithy/types";
/**
* @private
*/
export declare const prepareRequest: (request: HttpRequest) => HttpRequest;
+14
View File
@@ -0,0 +1,14 @@
import { HttpRequest } from "@smithy/types";
export interface TestCase {
name: string;
request: HttpRequest;
authorization: string;
}
export declare const region = "us-east-1";
export declare const service = "service";
export declare const credentials: {
accessKeyId: string;
secretAccessKey: string;
};
export declare const signingDate: Date;
export declare const requests: Array<TestCase>;
+67
View File
@@ -0,0 +1,67 @@
import { AwsCredentialIdentity, ChecksumConstructor, EventSigner, EventSigningArguments, FormattedEvent, HashConstructor, HttpRequest, MessageSigner, Provider, RequestPresigner, RequestPresigningArguments, RequestSigner, RequestSigningArguments, SignableMessage, SignedMessage, SigningArguments, StringSigner } from "@smithy/types";
export interface SignatureV4Init {
/**
* The service signing name.
*/
service: string;
/**
* The region name or a function that returns a promise that will be
* resolved with the region name.
*/
region: string | Provider<string>;
/**
* The credentials with which the request should be signed or a function
* that returns a promise that will be resolved with credentials.
*/
credentials: AwsCredentialIdentity | Provider<AwsCredentialIdentity>;
/**
* A constructor function for a hash object that will calculate SHA-256 HMAC
* checksums.
*/
sha256?: ChecksumConstructor | HashConstructor;
/**
* Whether to uri-escape the request URI path as part of computing the
* canonical request string. This is required for every AWS service, except
* Amazon S3, as of late 2017.
*
* @default [true]
*/
uriEscapePath?: boolean;
/**
* Whether to calculate a checksum of the request body and include it as
* either a request header (when signing) or as a query string parameter
* (when presigning). This is required for AWS Glacier and Amazon S3 and optional for
* every other AWS service as of late 2017.
*
* @default [true]
*/
applyChecksum?: boolean;
}
export interface SignatureV4CryptoInit {
sha256: ChecksumConstructor | HashConstructor;
}
export declare class SignatureV4 implements RequestPresigner, RequestSigner, StringSigner, EventSigner, MessageSigner {
private readonly service;
private readonly regionProvider;
private readonly credentialProvider;
private readonly sha256;
private readonly uriEscapePath;
private readonly applyChecksum;
private readonly headerMarshaller;
constructor({ applyChecksum, credentials, region, service, sha256, uriEscapePath, }: SignatureV4Init & SignatureV4CryptoInit);
presign(originalRequest: HttpRequest, options?: RequestPresigningArguments): Promise<HttpRequest>;
sign(stringToSign: string, options?: SigningArguments): Promise<string>;
sign(event: FormattedEvent, options: EventSigningArguments): Promise<string>;
sign(event: SignableMessage, options: SigningArguments): Promise<SignedMessage>;
sign(requestToSign: HttpRequest, options?: RequestSigningArguments): Promise<HttpRequest>;
private signEvent;
signMessage(signableMessage: SignableMessage, { signingDate, signingRegion, signingService }: SigningArguments): Promise<SignedMessage>;
private signString;
private signRequest;
private createCanonicalRequest;
private createStringToSign;
private getCanonicalPath;
private getSignature;
private getSigningKey;
private validateResolvedCredentials;
}
+6
View File
@@ -0,0 +1,6 @@
import { HttpRequest, QueryParameterBag } from "@smithy/types";
/**
* @internal
*/
export declare const cloneRequest: ({ headers, query, ...rest }: HttpRequest) => HttpRequest;
export declare const cloneQuery: (query: QueryParameterBag) => QueryParameterBag;
+43
View File
@@ -0,0 +1,43 @@
export declare const ALGORITHM_QUERY_PARAM = "X-Amz-Algorithm";
export declare const CREDENTIAL_QUERY_PARAM = "X-Amz-Credential";
export declare const AMZ_DATE_QUERY_PARAM = "X-Amz-Date";
export declare const SIGNED_HEADERS_QUERY_PARAM = "X-Amz-SignedHeaders";
export declare const EXPIRES_QUERY_PARAM = "X-Amz-Expires";
export declare const SIGNATURE_QUERY_PARAM = "X-Amz-Signature";
export declare const TOKEN_QUERY_PARAM = "X-Amz-Security-Token";
export declare const REGION_SET_PARAM = "X-Amz-Region-Set";
export declare const AUTH_HEADER = "authorization";
export declare const AMZ_DATE_HEADER: string;
export declare const DATE_HEADER = "date";
export declare const GENERATED_HEADERS: string[];
export declare const SIGNATURE_HEADER: string;
export declare const SHA256_HEADER = "x-amz-content-sha256";
export declare const TOKEN_HEADER: string;
export declare const HOST_HEADER = "host";
export declare const ALWAYS_UNSIGNABLE_HEADERS: {
authorization: boolean;
"cache-control": boolean;
connection: boolean;
expect: boolean;
from: boolean;
"keep-alive": boolean;
"max-forwards": boolean;
pragma: boolean;
referer: boolean;
te: boolean;
trailer: boolean;
"transfer-encoding": boolean;
upgrade: boolean;
"user-agent": boolean;
"x-amzn-trace-id": boolean;
};
export declare const PROXY_HEADER_PATTERN: RegExp;
export declare const SEC_HEADER_PATTERN: RegExp;
export declare const UNSIGNABLE_PATTERNS: RegExp[];
export declare const ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256";
export declare const ALGORITHM_IDENTIFIER_V4A = "AWS4-ECDSA-P256-SHA256";
export declare const EVENT_ALGORITHM_IDENTIFIER = "AWS4-HMAC-SHA256-PAYLOAD";
export declare const UNSIGNED_PAYLOAD = "UNSIGNED-PAYLOAD";
export declare const MAX_CACHE_SIZE = 50;
export declare const KEY_TYPE_IDENTIFIER = "aws4_request";
export declare const MAX_PRESIGNED_TTL: number;
@@ -0,0 +1,26 @@
import { AwsCredentialIdentity, ChecksumConstructor, HashConstructor } from "@smithy/types";
/**
* Create a string describing the scope of credentials used to sign a request.
*
* @param shortDate The current calendar date in the form YYYYMMDD.
* @param region The AWS region in which the service resides.
* @param service The service to which the signed request is being sent.
*/
export declare const createScope: (shortDate: string, region: string, service: string) => string;
/**
* Derive a signing key from its composite parts
*
* @param sha256Constructor A constructor function that can instantiate SHA-256
* hash objects.
* @param credentials The credentials with which the request will be
* signed.
* @param shortDate The current calendar date in the form YYYYMMDD.
* @param region The AWS region in which the service resides.
* @param service The service to which the signed request is being
* sent.
*/
export declare const getSigningKey: (sha256Constructor: ChecksumConstructor | HashConstructor, credentials: AwsCredentialIdentity, shortDate: string, region: string, service: string) => Promise<Uint8Array>;
/**
* @internal
*/
export declare const clearCredentialCache: () => void;
@@ -0,0 +1,5 @@
import { HeaderBag, HttpRequest } from "@smithy/types";
/**
* @private
*/
export declare const getCanonicalHeaders: ({ headers }: HttpRequest, unsignableHeaders?: Set<string>, signableHeaders?: Set<string>) => HeaderBag;
@@ -0,0 +1,5 @@
import { HttpRequest } from "@smithy/types";
/**
* @private
*/
export declare const getCanonicalQuery: ({ query }: HttpRequest) => string;
@@ -0,0 +1,5 @@
import { ChecksumConstructor, HashConstructor, HttpRequest } from "@smithy/types";
/**
* @private
*/
export declare const getPayloadHash: ({ headers, body }: HttpRequest, hashConstructor: ChecksumConstructor | HashConstructor) => Promise<string>;
+4
View File
@@ -0,0 +1,4 @@
import { HeaderBag } from "@smithy/types";
export declare const hasHeader: (soughtHeader: string, headers: HeaderBag) => boolean;
export declare const getHeaderValue: (soughtHeader: string, headers: HeaderBag) => string | undefined;
export declare const deleteHeader: (soughtHeader: string, headers: HeaderBag) => void;
+7
View File
@@ -0,0 +1,7 @@
export * from "./SignatureV4";
export { getCanonicalHeaders } from "./getCanonicalHeaders";
export { getCanonicalQuery } from "./getCanonicalQuery";
export { getPayloadHash } from "./getPayloadHash";
export { moveHeadersToQuery } from "./moveHeadersToQuery";
export { prepareRequest } from "./prepareRequest";
export * from "./credentialDerivation";
@@ -0,0 +1,9 @@
import { HttpRequest, QueryParameterBag } from "@smithy/types";
/**
* @private
*/
export declare const moveHeadersToQuery: (request: HttpRequest, options?: {
unhoistableHeaders?: Set<string>;
}) => HttpRequest & {
query: QueryParameterBag;
};
@@ -0,0 +1,5 @@
import { HttpRequest } from "@smithy/types";
/**
* @private
*/
export declare const prepareRequest: (request: HttpRequest) => HttpRequest;
+14
View File
@@ -0,0 +1,14 @@
import { HttpRequest } from "@smithy/types";
export interface TestCase {
name: string;
request: HttpRequest;
authorization: string;
}
export declare const region = "us-east-1";
export declare const service = "service";
export declare const credentials: {
accessKeyId: string;
secretAccessKey: string;
};
export declare const signingDate: Date;
export declare const requests: Array<TestCase>;
+2
View File
@@ -0,0 +1,2 @@
export declare const iso8601: (time: number | string | Date) => string;
export declare const toDate: (time: number | string | Date) => Date;
+2
View File
@@ -0,0 +1,2 @@
export declare const iso8601: (time: number | string | Date) => string;
export declare const toDate: (time: number | string | Date) => Date;
+70
View File
@@ -0,0 +1,70 @@
{
"name": "@smithy/signature-v4",
"version": "2.0.16",
"description": "A standalone implementation of the AWS Signature V4 request signing algorithm",
"main": "./dist-cjs/index.js",
"module": "./dist-es/index.js",
"types": "./dist-types/index.d.ts",
"scripts": {
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
"build:cjs": "yarn g:tsc -p tsconfig.cjs.json",
"build:es": "yarn g:tsc -p tsconfig.es.json",
"build:types": "yarn g:tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"stage-release": "rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
"format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
"extract:docs": "api-extractor run --local",
"test": "yarn g:jest --coverage"
},
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0",
"dependencies": {
"@smithy/eventstream-codec": "^2.0.14",
"@smithy/is-array-buffer": "^2.0.0",
"@smithy/types": "^2.6.0",
"@smithy/util-hex-encoding": "^2.0.0",
"@smithy/util-middleware": "^2.0.7",
"@smithy/util-uri-escape": "^2.0.0",
"@smithy/util-utf8": "^2.0.2",
"tslib": "^2.5.0"
},
"devDependencies": {
"@aws-crypto/sha256-js": "3.0.0",
"@smithy/protocol-http": "^3.0.10",
"@tsconfig/recommended": "1.0.1",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
"rimraf": "3.0.2",
"typedoc": "0.23.23"
},
"engines": {
"node": ">=14.0.0"
},
"typesVersions": {
"<4.0": {
"dist-types/*": [
"dist-types/ts3.4/*"
]
}
},
"files": [
"dist-*/**"
],
"homepage": "https://github.com/awslabs/smithy-typescript/tree/main/packages/signature-v4",
"repository": {
"type": "git",
"url": "https://github.com/awslabs/smithy-typescript.git",
"directory": "packages/signature-v4"
},
"typedoc": {
"entryPoint": "src/index.ts"
},
"publishConfig": {
"directory": ".release/package"
}
}