VaultEntry.kt

2.7 KB · raw

1package com.peachpasswords.vault23import android.os.Parcelable4import kotlinx.parcelize.Parcelize5import kotlinx.serialization.SerialName6import kotlinx.serialization.Serializable78@Parcelize9@Serializable10data class VaultEntry(11    val id: String,12    val type: String? = null,13    val title: String,14    val username: String? = null,15    val email: String? = null,16    val password: String? = null,17    val url: String? = null,18    val additionalUrls: List<String>? = null,19    val totp: String? = null,20    val notes: String? = null,21    val breach: Int? = null,22    val passwordChangedAt: Long? = null,23    /** Past passwords, newest first. Captured automatically on password change. */24    val passwordHistory: List<PasswordHistoryItem>? = null,25    val canary: Canary? = null,26    val createdAt: Long,27    val modifiedAt: Long,28    val deletedAt: Long? = null,29    val tags: List<String>? = null,30    val passkey: PasskeyData? = null,31    val signCount: Int? = null,32    val lastUsedAt: Long? = null,33    val cardholderName: String? = null,34    val cardNumber: String? = null,35    val expMonth: String? = null,36    val expYear: String? = null,37    val cvc: String? = null,38    val cardNickname: String? = null,39    /**40     * "visa" | "mastercard" | "amex" | "discover" | "unknown" — derivable from cardNumber.41     * Serialized as "network" to match the browser's card shape so it survives sync (MF-3).42     */43    @SerialName("network")44    val cardNetwork: String? = null,45    /**46     * Last 4 PAN digits. Derived from cardNumber on save (see VaultRepository) and47     * serialized as "last4" for browser parity — the browser stores this separately48     * rather than deriving it at render time (MF-3).49     */50    @SerialName("last4")51    val last4: String? = null,52    val rpId: String? = null,53    val rpName: String? = null,54    val credentialId: String? = null,55    val publicKeyCose: String? = null,56    val userHandle: String? = null,57    val userName: String? = null,58    val userDisplayName: String? = null,59    val algorithm: Int? = null,60    val aaguid: String? = null,61    val backupEligible: Boolean? = null,62    val backupState: Boolean? = null,63    val browser: String? = null,64    val transports: List<String>? = null,65) : Parcelable6667fun VaultEntry.isLogin() = type == "login" || type == null68fun VaultEntry.isNote() = type == "note"69fun VaultEntry.isCard() = type == "card"70fun VaultEntry.isDeleted() = deletedAt != null71fun VaultEntry.hasTOTP() = !totp.isNullOrBlank()72fun VaultEntry.hasPasskey() = passkey != null73fun VaultEntry.isBreach() = (breach ?: 0) > 07475fun VaultEntry.domainKey(): String? {76    val urlStr = url ?: return null77    return try {78        val host = java.net.URL(urlStr).host79        host.removePrefix("www.")80    } catch (_: Exception) {81        null82    }83}