UNPKG

1.09 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getPayloadHash = void 0;
4const is_array_buffer_1 = require("@aws-sdk/is-array-buffer");
5const util_hex_encoding_1 = require("@aws-sdk/util-hex-encoding");
6const util_utf8_1 = require("@aws-sdk/util-utf8");
7const constants_1 = require("./constants");
8const getPayloadHash = async ({ headers, body }, hashConstructor) => {
9 for (const headerName of Object.keys(headers)) {
10 if (headerName.toLowerCase() === constants_1.SHA256_HEADER) {
11 return headers[headerName];
12 }
13 }
14 if (body == undefined) {
15 return "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
16 }
17 else if (typeof body === "string" || ArrayBuffer.isView(body) || (0, is_array_buffer_1.isArrayBuffer)(body)) {
18 const hashCtor = new hashConstructor();
19 hashCtor.update((0, util_utf8_1.toUint8Array)(body));
20 return (0, util_hex_encoding_1.toHex)(await hashCtor.digest());
21 }
22 return constants_1.UNSIGNED_PAYLOAD;
23};
24exports.getPayloadHash = getPayloadHash;