UNPKG

@aws-amplify/auth

Version:
31 lines (29 loc) 1.09 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.getBytesFromHex = void 0; const constants_1 = require("./constants"); /** * Converts a hexadecimal encoded string to a Uint8Array of bytes. * * @param encoded The hexadecimal encoded string */ const getBytesFromHex = (encoded) => { if (encoded.length % 2 !== 0) { throw new Error('Hex encoded strings must have an even number length'); } const out = new Uint8Array(encoded.length / 2); for (let i = 0; i < encoded.length; i += 2) { const encodedByte = encoded.slice(i, i + 2).toLowerCase(); if (encodedByte in constants_1.HEX_TO_SHORT) { out[i / 2] = constants_1.HEX_TO_SHORT[encodedByte]; } else { throw new Error(`Cannot decode unrecognized sequence ${encodedByte} as hexadecimal`); } } return out; }; exports.getBytesFromHex = getBytesFromHex; //# sourceMappingURL=getBytesFromHex.js.map