//#region src/passkey/index.ts
function e(e) {
	let t = e.replace(/-/g, "+").replace(/_/g, "/"), n = (4 - t.length % 4) % 4, r = t + "=".repeat(n), i = atob(r), a = new Uint8Array(i.length);
	for (let e = 0; e < i.length; e++) a[e] = i.charCodeAt(e);
	return a;
}
function t(e) {
	let t = String.fromCharCode(...e);
	return btoa(t).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
}
function n(e) {
	return t(new Uint8Array(e));
}
function r() {
	return typeof window > "u" ? !1 : window.PublicKeyCredential !== void 0 && typeof window.PublicKeyCredential == "function";
}
async function i() {
	if (!r()) return !1;
	try {
		return await PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
	} catch {
		return !1;
	}
}
function a(t) {
	let n = t.publicKey, r = {
		...n,
		challenge: e(n.challenge).buffer,
		user: {
			...n.user,
			id: e(n.user.id).buffer
		}
	};
	return n.excludeCredentials && (r.excludeCredentials = n.excludeCredentials.map((t) => ({
		...t,
		id: e(t.id).buffer
	}))), r;
}
function o(t) {
	let n = t.publicKey, r = {
		...n,
		challenge: e(n.challenge).buffer
	};
	return n.allowCredentials && (r.allowCredentials = n.allowCredentials.map((t) => ({
		...t,
		id: e(t.id).buffer
	}))), r;
}
function s(e) {
	let t = e.response;
	return {
		id: e.id,
		rawId: n(e.rawId),
		type: e.type,
		response: {
			clientDataJSON: n(t.clientDataJSON),
			attestationObject: n(t.attestationObject)
		}
	};
}
function c(e) {
	let t = e.response;
	return {
		id: e.id,
		rawId: n(e.rawId),
		type: e.type,
		response: {
			clientDataJSON: n(t.clientDataJSON),
			authenticatorData: n(t.authenticatorData),
			signature: n(t.signature),
			userHandle: t.userHandle ? n(t.userHandle) : void 0
		}
	};
}
async function l(e) {
	if (!r()) throw Error("WebAuthn is not supported in this browser");
	let t = a(e), n = await navigator.credentials.create({ publicKey: t });
	if (!n) throw Error("Failed to create credential");
	return s(n);
}
async function u(e) {
	if (!r()) throw Error("WebAuthn is not supported in this browser");
	let t = o(e), n = await navigator.credentials.get({ publicKey: t });
	if (!n) throw Error("Failed to get credential");
	return c(n);
}
//#endregion
export { n as arrayBufferToBase64url, u as authenticateWithPasskey, e as base64urlToUint8Array, c as formatAuthenticationCredential, s as formatRegistrationCredential, i as isPlatformAuthenticatorAvailable, r as isWebAuthnSupported, o as prepareAuthenticationOptions, a as prepareRegistrationOptions, l as registerPasskey, t as uint8ArrayToBase64url };

//# sourceMappingURL=index.js.map