package com.peachpasswords.passkeys import android.app.PendingIntent import android.content.Context import android.graphics.drawable.Icon import android.os.Build import androidx.biometric.BiometricManager.Authenticators.BIOMETRIC_STRONG import androidx.biometric.BiometricManager.Authenticators.DEVICE_CREDENTIAL import androidx.credentials.provider.BeginGetPublicKeyCredentialOption import androidx.credentials.provider.BiometricPromptData import androidx.credentials.provider.PublicKeyCredentialEntry import java.time.Instant internal object PasskeyCredentialEntryFactory { fun create( context: Context, username: String, displayName: String, lastUsedTime: Instant, pendingIntent: PendingIntent, option: BeginGetPublicKeyCredentialOption, icon: Icon, requireCredentialManagerVerification: Boolean, ): PublicKeyCredentialEntry { val builder = PublicKeyCredentialEntry.Builder(context, username, pendingIntent, option) .setDisplayName(displayName) .setLastUsedTime(lastUsedTime) .setIcon(icon) .setAutoSelectAllowed(false) if (requireCredentialManagerVerification && Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM ) { builder.setBiometricPromptData( BiometricPromptData( cryptoObject = null, allowedAuthenticators = BIOMETRIC_STRONG or DEVICE_CREDENTIAL, ), ) } return builder.build() } }