001/* 002 * Copyright 2026 Revetware LLC. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package com.revetsec.webauthn; 018 019import com.revetsec.json.JsonObject; 020import org.jspecify.annotations.NonNull; 021 022import javax.annotation.concurrent.Immutable; 023 024import static java.util.Objects.requireNonNull; 025 026/** Library-prepared browser options and opaque single-use ceremony handle. 027 * @since 1.0.0 */ 028@Immutable 029public final class WebAuthnBrowserRequest { 030 private final @NonNull String ceremonyId; 031 private final @NonNull JsonObject publicKey; 032 private final @NonNull String json; 033 034 WebAuthnBrowserRequest(@NonNull String ceremonyId, @NonNull JsonObject publicKey) { 035 this.ceremonyId = requireNonNull(ceremonyId); 036 this.publicKey = requireNonNull(publicKey); 037 this.json = JsonObject.builder().put("ceremonyId", ceremonyId) 038 .put("publicKey", publicKey).build().toJson(); 039 } 040 041 /** Returns the opaque ceremony handle for the completion call. 042 * @return canonical base64url ceremony ID 043 * @since 1.0.0 */ 044 public @NonNull String getCeremonyId() { return this.ceremonyId; } 045 /** Returns the JSON options for the browser's WebAuthn conversion API. 046 * @return immutable public-key options 047 * @since 1.0.0 */ 048 public @NonNull JsonObject getPublicKeyOptions() { return this.publicKey; } 049 /** Returns JSON containing {@code ceremonyId} and {@code publicKey}. 050 * @return the browser request JSON 051 * @since 1.0.0 */ 052 public @NonNull String getJson() { return this.json; } 053 /** Redacts the challenge and account display fields. 054 * @return a fixed description 055 * @since 1.0.0 */ 056 @Override public @NonNull String toString() { return "WebAuthnBrowserRequest{<redacted>}"; } 057}