import "@js-temporal/polyfill";
import "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { g as Multikey, s as CryptographicKey } from "../vocab-C5EUmVTj.mjs";
import { t as test } from "../testing-BQeTO4ss.mjs";
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
import { t as assertInstanceOf } from "../assert_instance_of-C4Ri6VuN.mjs";
import { t as assert } from "../assert-DikXweDx.mjs";
import { t as MemoryKvStore } from "../kv-OuT2IU64.mjs";
import { t as KvKeyCache } from "../keycache-Bgm-3VZ1.mjs";
//#region src/federation/keycache.test.ts
test("KvKeyCache.set()", async () => {
	const kv = new MemoryKvStore();
	const cache = new KvKeyCache(kv, ["pk"]);
	await cache.set(new URL("https://example.com/key"), new CryptographicKey({ id: new URL("https://example.com/key") }));
	assertEquals(await kv.get(["pk", "https://example.com/key"]), {
		"@context": "https://w3id.org/security/v1",
		id: "https://example.com/key",
		type: "CryptographicKey"
	});
	await cache.set(new URL("https://example.com/key2"), new Multikey({ id: new URL("https://example.com/key2") }));
	assertEquals(await kv.get(["pk", "https://example.com/key2"]), {
		"@context": "https://w3id.org/security/multikey/v1",
		id: "https://example.com/key2",
		type: "Multikey"
	});
	await cache.set(new URL("https://example.com/null"), null);
	assert(cache.nullKeys.has("https://example.com/null"));
	assertEquals(await kv.get(["pk", "https://example.com/null"]), { _fedify: "key-unavailable" });
});
test("KvKeyCache.get()", async () => {
	const kv = new MemoryKvStore();
	const cache = new KvKeyCache(kv, ["pk"]);
	await kv.set(["pk", "https://example.com/key"], {
		"@context": "https://w3id.org/security/v1",
		id: "https://example.com/key",
		type: "CryptographicKey"
	});
	const cryptoKey = await cache.get(new URL("https://example.com/key"));
	assertInstanceOf(cryptoKey, CryptographicKey);
	assertEquals(cryptoKey?.id?.href, "https://example.com/key");
	await kv.set(["pk", "https://example.com/key2"], {
		"@context": "https://w3id.org/security/multikey/v1",
		id: "https://example.com/key2",
		type: "Multikey"
	});
	const multikey = await cache.get(new URL("https://example.com/key2"));
	assertInstanceOf(multikey, Multikey);
	assertEquals(multikey?.id?.href, "https://example.com/key2");
	cache.nullKeys.add("https://example.com/null");
	assertEquals(await cache.get(new URL("https://example.com/null")), null);
	await kv.set(["pk", "https://example.com/null2"], { _fedify: "key-unavailable" });
	assertEquals(await new KvKeyCache(kv, ["pk"]).get(new URL("https://example.com/null2")), null);
});
//#endregion
export {};
