
      import { Temporal } from "@js-temporal/polyfill";
      import { URLPattern } from "urlpattern-polyfill";
      globalThis.addEventListener = () => {};
    
import { Create, CryptographicKey, lookupObject } from "../lookup-Dvhilldd.js";
import { assertEquals } from "../assert_equals-DSbWqCm3.js";
import { assert } from "../assert-MZs1qjMx.js";
import "../assert_instance_of-DHz7EHNU.js";
import "../actor-B5o1xrFI.js";
import "../key-jo5CucF6.js";
import { doesActorOwnKey, getKeyOwner } from "../owner-_G6LyiEi.js";
import { mockDocumentLoader, test } from "../testing-cwlO8Sns.js";
import "../std__assert-DWivtrGR.js";
import { assertFalse } from "../assert_rejects-Ce45JcFg.js";
import "../assert_throws-BNXdRGWP.js";
import "../assert_not_equals-C80BG-_5.js";
import { rsaPublicKey1, rsaPublicKey2 } from "../keys-BSzUEVJu.js";
import { createTestTracerProvider } from "../otel-1BmGPuZc.js";

//#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
	};
	const owner = await getKeyOwner(new URL("https://example.com/users/handle#main-key"), options);
	assertEquals(owner, 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));
	const owner3 = await getKeyOwner(rsaPublicKey1, options);
	assertEquals(owner3, owner2);
	const noOwner = await getKeyOwner(new URL("https://example.com/key2"), options);
	assertEquals(noOwner, null);
	const noOwner2 = await getKeyOwner(new URL("https://example.com/object"), options);
	assertEquals(noOwner2, null);
});
test("doesActorOwnKey() records OpenTelemetry span", async () => {
	const [tracerProvider, exporter] = createTestTracerProvider();
	const activity = new Create({
		id: new URL("https://example.com/activity"),
		actor: new URL("https://example.com/person")
	});
	const key = new CryptographicKey({
		id: new URL("https://example.com/person#key"),
		owner: new URL("https://example.com/person")
	});
	const result = await doesActorOwnKey(activity, key, {
		documentLoader: mockDocumentLoader,
		tracerProvider
	});
	assert(result);
	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