UNPKG

@aws-amplify/core

Version:
37 lines (36 loc) 1.5 kB
"use strict"; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 Object.defineProperty(exports, "__esModule", { value: true }); exports.getHashedPayload = void 0; var constants_1 = require("../constants"); var dataHashHelpers_1 = require("./dataHashHelpers"); /** * Returns the hashed payload. * * @param body `body` (payload) from the request. * @returns String created using the payload in the body of the HTTP request as input to a hash function. This string * uses lowercase hexadecimal characters. If the payload is empty, return precalculated result of an empty hash. * * @internal */ var getHashedPayload = function (body) { // return precalculated empty hash if body is undefined or null if (body == null) { return constants_1.EMPTY_HASH; } if (isSourceData(body)) { var hashedData = (0, dataHashHelpers_1.getHashedDataAsHex)(null, body); return hashedData; } // Defined body is not signable. Return unsigned payload which may or may not be accepted by the service. return constants_1.UNSIGNED_PAYLOAD; }; exports.getHashedPayload = getHashedPayload; var isSourceData = function (body) { return typeof body === 'string' || ArrayBuffer.isView(body) || isArrayBuffer(body); }; var isArrayBuffer = function (arg) { return (typeof ArrayBuffer === 'function' && arg instanceof ArrayBuffer) || Object.prototype.toString.call(arg) === '[object ArrayBuffer]'; };