Some checks failed
CI / test (push) Has been cancelled
Move the app payload under swift/ while keeping git, package.json, and .smartconfig.json at the repo root. This standardizes the Swift app setup so build, test, run, and watch workflows match the other repos.
20 lines
704 B
Swift
20 lines
704 B
Swift
import CryptoKit
|
|
import Foundation
|
|
|
|
enum OneTimePasscodeGenerator {
|
|
static func code(for pairingCode: String, at date: Date) -> String {
|
|
let timeSlot = Int(date.timeIntervalSince1970 / 30)
|
|
let digest = SHA256.hash(data: Data("\(pairingCode)|\(timeSlot)".utf8))
|
|
let value = digest.prefix(4).reduce(UInt32(0)) { partialResult, byte in
|
|
(partialResult << 8) | UInt32(byte)
|
|
}
|
|
|
|
return String(format: "%06d", locale: Locale(identifier: "en_US_POSIX"), Int(value % 1_000_000))
|
|
}
|
|
|
|
static func renewalCountdown(at date: Date) -> Int {
|
|
let elapsed = Int(date.timeIntervalSince1970) % 30
|
|
return elapsed == 0 ? 30 : 30 - elapsed
|
|
}
|
|
}
|