
          const { Temporal } = require("@js-temporal/polyfill");
          const { URLPattern } = require("urlpattern-polyfill");
        
const require_chunk = require('./chunk-DqRYRqnO.cjs');
const __logtape_logtape = require_chunk.__toESM(require("@logtape/logtape"));
const __opentelemetry_api = require_chunk.__toESM(require("@opentelemetry/api"));
const __fedify_vocab_runtime = require_chunk.__toESM(require("@fedify/vocab-runtime"));

//#region deno.json
var name = "@fedify/fedify";
var version = "2.0.0-dev.7+a392e496";
var license = "MIT";
var exports$1 = {
	".": "./src/mod.ts",
	"./compat": "./src/compat/mod.ts",
	"./federation": "./src/federation/mod.ts",
	"./nodeinfo": "./src/nodeinfo/mod.ts",
	"./sig": "./src/sig/mod.ts",
	"./testing": "./src/testing/mod.ts",
	"./vocab": "./src/vocab/mod.ts",
	"./utils": "./src/utils/mod.ts",
	"./webfinger": "./src/webfinger/mod.ts"
};
var imports = {
	"@multiformats/base-x": "npm:@multiformats/base-x@^4.0.1",
	"@opentelemetry/core": "npm:@opentelemetry/core@^1.30.1",
	"@opentelemetry/sdk-trace-base": "npm:@opentelemetry/sdk-trace-base@^1.30.1",
	"@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@^1.27.0",
	"@std/assert": "jsr:@std/assert@^0.226.0",
	"@std/url": "jsr:@std/url@^0.225.1",
	"asn1js": "npm:asn1js@^3.0.5",
	"es-toolkit": "jsr:@es-toolkit/es-toolkit@^1.39.5",
	"fast-check": "npm:fast-check@^3.22.0",
	"fetch-mock": "npm:fetch-mock@^12.5.2",
	"json-canon": "npm:json-canon@^1.0.1",
	"jsonld": "npm:jsonld@^9.0.0",
	"multicodec": "npm:multicodec@^3.2.1",
	"pkijs": "npm:pkijs@^3.2.4",
	"structured-field-values": "npm:structured-field-values@^2.0.4",
	"uri-template-router": "npm:uri-template-router@^1.0.0",
	"url-template": "npm:url-template@^3.1.1"
};
var include = ["src/vocab/vocab.ts"];
var exclude = [
	".test-report.xml",
	"apidoc/",
	"dist/",
	"node_modules/",
	"npm/",
	"pnpm-lock.yaml",
	"src/cfworkers/dist/",
	"src/cfworkers/fixtures/",
	"src/cfworkers/imports.ts",
	"src/cfworkers/README.md",
	"src/cfworkers/server.ts",
	"src/cfworkers/server.js",
	"src/cfworkers/server.js.map",
	"src/vocab/*.yaml",
	"!src/vocab/vocab.ts"
];
var tasks = {
	"codegen": "deno run --allow-read --allow-write --allow-env --check scripts/codegen.ts && deno fmt src/vocab/vocab.ts && deno cache src/vocab/vocab.ts && deno check src/vocab/vocab.ts",
	"cache": {
		"command": "deno cache src/mod.ts",
		"dependencies": ["codegen"]
	},
	"check": {
		"command": "deno fmt --check && deno lint && deno check src/**/*.ts",
		"dependencies": ["codegen"]
	},
	"test": {
		"command": "deno test --check --doc --allow-read --allow-write --allow-env --unstable-kv --trace-leaks --parallel",
		"dependencies": ["codegen"]
	},
	"coverage": "deno task test --clean --coverage && deno coverage --html coverage",
	"bench": {
		"command": "deno bench --allow-read --allow-write --allow-net --allow-env --allow-run --unstable-kv",
		"dependencies": ["codegen"]
	},
	"apidoc": {
		"command": "deno doc --html --name=Fedify --output=apidoc/ src/mod.ts",
		"dependencies": ["codegen"]
	},
	"publish": {
		"command": "deno publish",
		"dependencies": ["codegen"]
	},
	"pnpm:install": "pnpm install --silent",
	"pnpm:build": {
		"command": "pnpm exec tsdown",
		"dependencies": [
			"codegen",
			"pnpm:install",
			"pnpm:build-vocab"
		]
	},
	"pnpm:build-vocab-runtime": { "command": "cd ../vocab-runtime && pnpm build" },
	"pnpm:build-vocab-tools": { "command": "cd ../vocab-tools && pnpm build" },
	"pnpm:build-vocab": { "dependencies": ["pnpm:build-vocab-runtime", "pnpm:build-vocab-tools"] },
	"test:node": {
		"command": "cd dist/ && node --test",
		"dependencies": ["pnpm:build"]
	},
	"test:bun": {
		"command": "cd dist/ && bun test --timeout 60000",
		"dependencies": ["pnpm:build-vocab", "pnpm:build"]
	},
	"test:cfworkers": {
		"command": "pnpm exec wrangler deploy --dry-run --outdir src/cfworkers && node --import=tsx src/cfworkers/client.ts",
		"dependencies": ["pnpm:build-vocab", "pnpm:build"]
	},
	"test-all": { "dependencies": [
		"check",
		"test",
		"test:node",
		"test:bun",
		"test:cfworkers"
	] }
};
var deno_default = {
	name,
	version,
	license,
	exports: exports$1,
	imports,
	include,
	exclude,
	tasks
};

//#endregion
//#region src/webfinger/lookup.ts
const logger = (0, __logtape_logtape.getLogger)([
	"fedify",
	"webfinger",
	"lookup"
]);
const DEFAULT_MAX_REDIRECTION = 5;
/**
* Looks up a WebFinger resource.
* @param resource The resource URL to look up.
* @param options Extra options for looking up the resource.
* @returns The resource descriptor, or `null` if not found.
* @since 0.2.0
*/
async function lookupWebFinger(resource, options = {}) {
	const tracerProvider = options.tracerProvider ?? __opentelemetry_api.trace.getTracerProvider();
	const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
	return await tracer.startActiveSpan("webfinger.lookup", {
		kind: __opentelemetry_api.SpanKind.CLIENT,
		attributes: {
			"webfinger.resource": resource.toString(),
			"webfinger.resource.scheme": typeof resource === "string" ? resource.replace(/:.*$/, "") : resource.protocol.replace(/:$/, "")
		}
	}, async (span) => {
		try {
			const result = await lookupWebFingerInternal(resource, options);
			span.setStatus({ code: result === null ? __opentelemetry_api.SpanStatusCode.ERROR : __opentelemetry_api.SpanStatusCode.OK });
			return result;
		} catch (error) {
			span.setStatus({
				code: __opentelemetry_api.SpanStatusCode.ERROR,
				message: String(error)
			});
			throw error;
		} finally {
			span.end();
		}
	});
}
async function lookupWebFingerInternal(resource, options = {}) {
	if (typeof resource === "string") resource = new URL(resource);
	let protocol = "https:";
	let server;
	if (resource.protocol === "acct:") {
		const atPos = resource.pathname.lastIndexOf("@");
		if (atPos < 0) return null;
		server = resource.pathname.substring(atPos + 1);
		if (server === "") return null;
	} else {
		protocol = resource.protocol;
		server = resource.host;
	}
	let url = new URL(`${protocol}//${server}/.well-known/webfinger`);
	url.searchParams.set("resource", resource.href);
	let redirected = 0;
	while (true) {
		logger.debug("Fetching WebFinger resource descriptor from {url}...", { url: url.href });
		let response;
		if (options.allowPrivateAddress !== true) try {
			await (0, __fedify_vocab_runtime.validatePublicUrl)(url.href);
		} catch (e) {
			if (e instanceof __fedify_vocab_runtime.UrlError) {
				logger.error("Invalid URL for WebFinger resource descriptor: {error}", { error: e });
				return null;
			}
			throw e;
		}
		try {
			response = await fetch(url, {
				headers: {
					Accept: "application/jrd+json",
					"User-Agent": typeof options.userAgent === "string" ? options.userAgent : (0, __fedify_vocab_runtime.getUserAgent)(options.userAgent)
				},
				redirect: "manual",
				signal: options.signal
			});
		} catch (error) {
			logger.debug("Failed to fetch WebFinger resource descriptor: {error}", {
				url: url.href,
				error
			});
			return null;
		}
		if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
			redirected++;
			const maxRedirection = options.maxRedirection ?? DEFAULT_MAX_REDIRECTION;
			if (redirected >= maxRedirection) {
				logger.error("Too many redirections ({redirections}) while fetching WebFinger resource descriptor.", { redirections: redirected });
				return null;
			}
			const redirectedUrl = new URL(response.headers.get("Location"), response.url == null || response.url === "" ? url : response.url);
			if (redirectedUrl.protocol !== url.protocol) {
				logger.error("Redirected to a different protocol ({protocol} to {redirectedProtocol}) while fetching WebFinger resource descriptor.", {
					protocol: url.protocol,
					redirectedProtocol: redirectedUrl.protocol
				});
				return null;
			}
			url = redirectedUrl;
			continue;
		}
		if (!response.ok) {
			logger.debug("Failed to fetch WebFinger resource descriptor: {status} {statusText}.", {
				url: url.href,
				status: response.status,
				statusText: response.statusText
			});
			return null;
		}
		try {
			return await response.json();
		} catch (e) {
			if (e instanceof SyntaxError) {
				logger.debug("Failed to parse WebFinger resource descriptor as JSON: {error}", { error: e });
				return null;
			}
			throw e;
		}
	}
}

//#endregion
Object.defineProperty(exports, 'deno_default', {
  enumerable: true,
  get: function () {
    return deno_default;
  }
});
Object.defineProperty(exports, 'lookupWebFinger', {
  enumerable: true,
  get: function () {
    return lookupWebFinger;
  }
});