import { StorageKeys as e } from "../../types/cache.types.mjs";
import "../../types/index.mjs";
import { Logger as t } from "../../error-handling/logger.mjs";
import "../../error-handling/index.mjs";
import { get as n, set as r } from "idb-keyval";
new class {
	generateMessageId() {
		return `msg_${(/* @__PURE__ */ new Date()).getTime()}_${Math.random().toString(36).substring(2, 15)}`;
	}
	async saveSignedMessage(i, a, o, s, c, l) {
		try {
			let t = this.generateMessageId(), u = await n(e.SIGNED_MESSAGES) || {}, d = {
				chainId: i,
				messageText: a,
				messageType: o,
				subAccountAddress: s,
				signature: c,
				appMetaData: l
			};
			u[t] = {
				timestamp: (/* @__PURE__ */ new Date()).toISOString(),
				...d
			}, await r(e.SIGNED_MESSAGES, u);
		} catch (e) {
			t.error("Failed to save signed message:", e, {
				chainId: i,
				messageType: o
			});
		}
	}
	async getAllSignedMessages() {
		try {
			let t = await n(e.SIGNED_MESSAGES) || {};
			return Object.values(t).sort((e, t) => new Date(t.timestamp).getTime() - new Date(e.timestamp).getTime());
		} catch (e) {
			return t.error("Failed to retrieve signed messages:", e), [];
		}
	}
}();
//#endregion
