const require_rolldown_runtime = require('../../../../../_virtual/rolldown_runtime.cjs');
const require_buffer_utils = require('../lib/buffer_utils.cjs');
const require_base64url = require('./base64url.cjs');
const require_errors = require('./errors.cjs');
const require_is_object = require('../lib/is_object.cjs');

//#region ../../node_modules/jose/dist/webapi/util/decode_jwt.js
function decodeJwt(jwt) {
	if (typeof jwt !== "string") throw new require_errors.JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
	const { 1: payload, length } = jwt.split(".");
	if (length === 5) throw new require_errors.JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
	if (length !== 3) throw new require_errors.JWTInvalid("Invalid JWT");
	if (!payload) throw new require_errors.JWTInvalid("JWTs must contain a payload");
	let decoded;
	try {
		decoded = require_base64url.decode(payload);
	} catch {
		throw new require_errors.JWTInvalid("Failed to base64url decode the payload");
	}
	let result;
	try {
		result = JSON.parse(require_buffer_utils.decoder.decode(decoded));
	} catch {
		throw new require_errors.JWTInvalid("Failed to parse the decoded payload as JSON");
	}
	if (!require_is_object.default(result)) throw new require_errors.JWTInvalid("Invalid JWT Claims Set");
	return result;
}

//#endregion
exports.decodeJwt = decodeJwt;
//# sourceMappingURL=decode_jwt.cjs.map