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.totp;
018
019import com.revetsec.OperationBinding;
020
021import org.jspecify.annotations.NonNull;
022import javax.annotation.concurrent.Immutable;
023import java.time.Instant;
024
025import static java.util.Objects.requireNonNull;
026
027/** Library-created proof of a committed fresh TOTP acceptance; application login completion remains separate.
028 * @since 1.0.0 */
029@Immutable
030public final class TotpVerification {
031    private final @NonNull String credentialNamespace;
032    private final @NonNull String recoveryEpoch;
033    private final @NonNull String accountId;
034    private final @NonNull String factorId;
035    private final @NonNull Instant verifiedAt;
036    private final @NonNull String operationBinding;
037
038    TotpVerification(@NonNull String credentialNamespace, @NonNull String recoveryEpoch, @NonNull String accountId, @NonNull String factorId, @NonNull Instant verifiedAt, @NonNull String operationBinding) {
039        this.credentialNamespace = requireNonNull(credentialNamespace);
040        this.recoveryEpoch = requireNonNull(recoveryEpoch);
041        this.accountId = requireNonNull(accountId);
042        this.factorId = requireNonNull(factorId);
043        this.verifiedAt = requireNonNull(verifiedAt);
044        this.operationBinding = requireNonNull(operationBinding);
045    }
046
047    /** The application credential namespace.
048     * @return credentialNamespace
049     * @since 1.0.0 */
050    public @NonNull String getCredentialNamespace() { return this.credentialNamespace; }
051
052    /** The admitted recovery epoch; session completion must enforce it.
053     * @return recoveryEpoch
054     * @since 1.0.0 */
055    public @NonNull String getRecoveryEpoch() { return this.recoveryEpoch; }
056
057    /** The application-approved account identifier.
058     * @return accountId
059     * @since 1.0.0 */
060    public @NonNull String getAccountId() { return this.accountId; }
061
062    /** The verified active factor generation.
063     * @return factorId
064     * @since 1.0.0 */
065    public @NonNull String getFactorId() { return this.factorId; }
066
067    /** The confirmed verification instant.
068     * @return verifiedAt
069     * @since 1.0.0 */
070    public @NonNull Instant getVerifiedAt() { return this.verifiedAt; }
071
072    /** The server-owned pending operation binding.
073     * @return operationBinding
074     * @since 1.0.0 */
075    public @NonNull OperationBinding getOperationBinding() {
076        return OperationBinding.fromTrustedPersistence(this.operationBinding);
077    }
078
079    /** Returns the verified method provenance.
080     * @return authentication method
081     * @since 1.0.0 */
082    public @NonNull TotpAuthenticationMethod getMethod() { return TotpAuthenticationMethod.TOTP; }
083
084    /** Redacts all account, operation and secret data.
085     * @return a fixed description
086     * @since 1.0.0 */
087    @Override public @NonNull String toString() { return "TotpVerification{<redacted>}"; }
088}