import "@js-temporal/polyfill";
import "urlpattern-polyfill";
globalThis.addEventListener = () => {};
import { o as Create, s as CryptographicKey } from "../vocab-C5EUmVTj.mjs";
import { t as lookupObject } from "../lookup-D1kdVIs5.mjs";
import { a as mockDocumentLoader, t as test } from "../testing-BQeTO4ss.mjs";
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
import "../std__assert-2v7gYiZp.mjs";
import { n as assertFalse } from "../assert_rejects-CJC9ThS-.mjs";
import { t as assert } from "../assert-DikXweDx.mjs";
import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-LW_PkCQl.mjs";
import { t as createTestTracerProvider } from "../otel-D00WjYJ1.mjs";
import { o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-BkXWqCAE.mjs";
//#region src/sig/owner.test.ts
test("doesActorOwnKey()", async () => {
	const options = {
		documentLoader: mockDocumentLoader,
		contextLoader: mockDocumentLoader
	};
	const activity = new Create({ actor: new URL("https://example.com/person") });
	assert(await doesActorOwnKey(activity, rsaPublicKey1, options));
	assert(await doesActorOwnKey(activity, rsaPublicKey2, options));
	const activity2 = new Create({ actor: new URL("https://example.com/hong-gildong") });
	assertFalse(await doesActorOwnKey(activity2, rsaPublicKey1, options));
	assertFalse(await doesActorOwnKey(activity2, rsaPublicKey2, options));
});
test("getKeyOwner()", async () => {
	const options = {
		documentLoader: mockDocumentLoader,
		contextLoader: mockDocumentLoader
	};
	assertEquals(await getKeyOwner(new URL("https://example.com/users/handle#main-key"), options), await lookupObject("https://example.com/users/handle", options));
	const owner2 = await getKeyOwner(new URL("https://example.com/key"), options);
	assertEquals(owner2, await lookupObject("https://example.com/person", options));
	assertEquals(await getKeyOwner(rsaPublicKey1, options), owner2);
	assertEquals(await getKeyOwner(new URL("https://example.com/key2"), options), null);
	assertEquals(await getKeyOwner(new URL("https://example.com/object"), options), null);
});
test("doesActorOwnKey() records OpenTelemetry span", async () => {
	const [tracerProvider, exporter] = createTestTracerProvider();
	assert(await doesActorOwnKey(new Create({
		id: new URL("https://example.com/activity"),
		actor: new URL("https://example.com/person")
	}), new CryptographicKey({
		id: new URL("https://example.com/person#key"),
		owner: new URL("https://example.com/person")
	}), {
		documentLoader: mockDocumentLoader,
		tracerProvider
	}));
	const spans = exporter.getSpans("activitypub.verify_key_ownership");
	assertEquals(spans.length, 1);
	const span = spans[0];
	assertEquals(span.attributes["activitypub.actor.id"], "https://example.com/person");
	assertEquals(span.attributes["activitypub.key.id"], "https://example.com/person#key");
	assertEquals(span.attributes["activitypub.key_ownership.verified"], true);
	assertEquals(span.attributes["activitypub.key_ownership.method"], "owner_id");
});
//#endregion
export {};
