krz/domain-dig

an ios app for DNS & SSL analysis

clone: git clone https://gitbay.org/krz/domain-dig.git

v5.0.1: DomainDig/OwnerAccess.swift · raw

 1import CloudKit
 2
 3/// Owner-only entitlement support. The app owner is identified by their CloudKit
 4/// user-record ID  a stable, opaque per-Apple-ID value for this app's container.
 5/// `PurchaseService` grants the owner Pro+ when the signed-in iCloud user matches,
 6/// so the owner does not need a purchase.
 7///
 8/// Publishing the record ID here is safe: it is not an Apple ID or any personal
 9/// identifier, it is scoped to the `iCloud.net.cleberg.DomainDig` container, and
10/// CloudKit identity is verified server-side  another user cannot present it as
11/// their own. An empty value makes the allowlist inert.
12enum OwnerAccess {
13    static let ownerUserRecordID = "_1c35d6a25540b3ef00023cc0425ec373"
14
15    static var isConfigured: Bool { !ownerUserRecordID.isEmpty }
16
17    /// The current iCloud user's record name for this app's container, or nil if
18    /// it is unavailable (not signed into iCloud, restricted, or offline before
19    /// the first fetch).
20    static func currentUserRecordName() async -> String? {
21        do {
22            return try await CKContainer.default().userRecordID().recordName
23        } catch {
24            return nil
25        }
26    }
27
28    /// True only when the allowlist is configured and the current iCloud user is
29    /// the owner.
30    static func isOwner() async -> Bool {
31        guard isConfigured else { return false }
32        return await currentUserRecordName() == ownerUserRecordID
33    }
34}