Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Active Liveness Metadata #265

Merged
merged 7 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Sources/SmileID/Classes/Networking/Models/v2/Metadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public struct Metadata: Codable {
Metadata(items: [
.sdk,
.sdkVersion,
.activeLivenessVersion,
.clientIP,
.fingerprint,
.deviceModel,
Expand Down Expand Up @@ -50,10 +51,21 @@ public class Metadatum: Codable {

public static let sdk = Metadatum(name: "sdk", value: "iOS")
public static let sdkVersion = Metadatum(name: "sdk_version", value: SmileID.version)
public static let activeLivenessVersion = Metadatum(name: "active_liveness_version", value: "1.0.0")
public static let clientIP = Metadatum(name: "client_ip", value: getIPAddress(useIPv4: true))
public static let fingerprint = Metadatum(name: "fingerprint", value: SmileID.deviceId)
public static let deviceModel = Metadatum(name: "device_model", value: UIDevice.current.modelName)
public static let deviceOS = Metadatum(name: "device_os", value: UIDevice.current.systemVersion)

public class ActiveLivenessType: Metadatum {
public init(livenessType: LivenessType) {
super.init(name: "active_liveness_type", value: livenessType.rawValue)
}

public required init(from decoder: Decoder) throws {
try super.init(from: decoder)
}
}

public class SelfieImageOrigin: Metadatum {
public init(cameraFacing: CameraFacingValue) {
Expand Down Expand Up @@ -136,6 +148,11 @@ public class Metadatum: Codable {
}
}

public enum LivenessType: String, Codable {
case headPose = "head_pose"
case smile = "smile"
}

public enum DocumentImageOriginValue: String {
case gallery
case cameraAutoCapture = "camera_auto_capture"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ extension EnhancedSmartSelfieViewModel {
livenessImages = []
selfieCaptureState = .capturingSelfie
failureReason = nil
resetSelfieCaptureMetadata()
}

private func handleWindowSizeChanged(to rect: CGSize, edgeInsets: EdgeInsets) {
Expand Down Expand Up @@ -446,7 +447,7 @@ extension EnhancedSmartSelfieViewModel: LivenessCheckManagerDelegate {
extension EnhancedSmartSelfieViewModel: SelfieSubmissionDelegate {
public func submitJob() async throws {
// Add metadata before submission
addSelfieCaptureDurationMetaData()
addSelfieCaptureMetaData()

if skipApiSubmission {
// Skip API submission and update processing state to success
Expand All @@ -469,9 +470,15 @@ extension EnhancedSmartSelfieViewModel: SelfieSubmissionDelegate {
try await submissionManager.submitJob(failureReason: self.failureReason)
}

private func addSelfieCaptureDurationMetaData() {
private func addSelfieCaptureMetaData() {
localMetadata.addMetadata(
Metadatum.SelfieCaptureDuration(duration: metadataTimerStart.elapsedTime()))
localMetadata.addMetadata(Metadatum.ActiveLivenessType(livenessType: LivenessType.headPose))
}

private func resetSelfieCaptureMetadata() {
localMetadata.metadata.removeAllOfType(Metadatum.SelfieCaptureDuration.self)
localMetadata.metadata.removeAllOfType(Metadatum.ActiveLivenessType.self)
}

public func onFinished(callback: SmartSelfieResultDelegate) {
Expand Down
Loading