@fgiova/aws-signature
Version:
[](https://www.npmjs.com/package/@fgiova/aws-signature)  [ • 1.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPayloadHash = getPayloadHash;
const constants_1 = require("./constants");
const utils_1 = require("./utils");
const crypto_1 = require("crypto");
/**
* @private
*/
function getPayloadHash({ headers, body }) {
if (headers) {
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, utils_1.isArrayBuffer)(body)) {
return (0, crypto_1.createHash)("sha256").update((0, utils_1.toUint8Array)(body)).digest("hex");
}
// As any defined body that is not a string or binary data is a stream, this
// body is unsignable. Attempt to send the request with an unsigned payload,
// which may or may not be accepted by the service.
return constants_1.UNSIGNED_PAYLOAD;
}