
//#region ../didcomm/src/handlers/DidCommMessageHandlerMiddleware.ts
var DidCommMessageHandlerMiddlewareRunner = class {
	static async run(middlewares, inboundMessageContext) {
		const compose = (middlewares$1) => {
			return async (inboundMessageContext$1) => {
				let index = -1;
				async function dispatch(i) {
					if (i <= index) throw new Error("next() called multiple times");
					index = i;
					const fn = middlewares$1[i];
					if (!fn) return;
					await fn(inboundMessageContext$1, () => dispatch(i + 1));
				}
				await dispatch(0);
			};
		};
		await compose(middlewares)(inboundMessageContext);
	}
};

//#endregion
exports.DidCommMessageHandlerMiddlewareRunner = DidCommMessageHandlerMiddlewareRunner;