Skip to content

Commit

Permalink
Collect Metadata on iOS (#233)
Browse files Browse the repository at this point in the history
* reworking metadata collection

* Update SelfieViewModel.swift

* lint metadata

* running lint

* fixed fingeprinting and lint

* fixed devicemodels

* chore: update proj file for carthage

* fix: correct import for UIKit

* Update CHANGELOG.md

---------

Co-authored-by: JNdhlovu <[email protected]>
  • Loading branch information
jumaallan and JNdhlovu authored Sep 20, 2024
1 parent f42b2f9 commit 9b3464d
Show file tree
Hide file tree
Showing 24 changed files with 2,797 additions and 763 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Release Notes
## Unreleased

### Added
* Add metadata support

## 10.2.10

### Added
Expand Down
10 changes: 9 additions & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ PODS:
- ArkanaKeys (1.0.0):
- ArkanaKeysInterfaces (~> 1.0.0)
- ArkanaKeysInterfaces (1.0.0)
- FingerprintJS (1.5.0):
- FingerprintJS/Core (= 1.5.0)
- FingerprintJS/Core (1.5.0):
- FingerprintJS/SystemControl
- FingerprintJS/SystemControl (1.5.0)
- lottie-ios (4.4.3)
- netfox (1.21.0)
- Sentry (8.36.0):
- Sentry/Core (= 8.36.0)
- Sentry/Core (8.36.0)
- SmileID (10.2.10):
- FingerprintJS
- lottie-ios (~> 4.4.2)
- ZIPFoundation (~> 0.9)
- SwiftLint (0.55.1)
Expand All @@ -23,6 +29,7 @@ DEPENDENCIES:

SPEC REPOS:
trunk:
- FingerprintJS
- lottie-ios
- netfox
- Sentry
Expand All @@ -40,10 +47,11 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
ArkanaKeys: 356555f467c55ae40ba074c1b4d9cb5c38a55f3d
ArkanaKeysInterfaces: 81d21923368b058e2b6fd932ec96855166ef6d19
FingerprintJS: 96410117a394cca04d0f1e2374944c8697f2cceb
lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418
netfox: 9d5cc727fe7576c4c7688a2504618a156b7d44b7
Sentry: f8374b5415bc38dfb5645941b3ae31230fbeae57
SmileID: ee09d74009d391e10b1576599264fdb43ef13c24
SmileID: 41b6c7ea0ec44116c43e94a1221acde297bd3b08
SwiftLint: 3fe909719babe5537c552ee8181c0031392be933
ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c

Expand Down
146 changes: 74 additions & 72 deletions Example/SmileID.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/weichsel/ZIPFoundation.git", .upToNextMajor(from: "0.9.0")),
.package(url: "https://github.com/airbnb/lottie-spm", from: "4.4.2")
.package(url: "https://github.com/airbnb/lottie-spm", from: "4.4.2"),
.package(url: "https://github.com/fingerprintjs/fingerprintjs-ios", from: "4.4.2")
],
targets: [
.target(
name: "SmileID",
dependencies: ["ZIPFoundation", .product(name: "Lottie", package: "lottie-spm")],
dependencies: ["ZIPFoundation", "FingerprintJS", .product(name: "Lottie", package: "lottie-spm")],
path: "Sources/SmileID",
resources: [.process("Resources")]
),
Expand Down
1 change: 1 addition & 0 deletions SmileID.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/smileidentity/ios.git", :tag => "v10.2.10" }
s.ios.deployment_target = '13.0'
s.dependency 'ZIPFoundation', '~> 0.9'
s.dependency 'FingerprintJS'
s.dependency 'lottie-ios', '~> 4.4.2'
s.swift_version = '5.5'
s.source_files = 'Sources/SmileID/Classes/**/*'
Expand Down
1,557 changes: 1,181 additions & 376 deletions SmileID.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "fingerprintjs-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/fingerprintjs/fingerprintjs-ios/",
"state" : {
"revision" : "bd93291c149e328919a9a2881575494f6ea9245f",
"version" : "1.5.0"
}
},
{
"identity" : "lottie-spm",
"kind" : "remoteSourceControl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@ internal enum BiometricKycStep {

internal class OrchestratedBiometricKycViewModel: ObservableObject {
// MARK: - Input Properties

private let userId: String
private let jobId: String
private let allowNewEnroll: Bool
private var extraPartnerParams: [String: String]
private let localMetadata = LocalMetadata()
private var idInfo: IdInfo

// MARK: - Other Properties

internal var selfieFile: URL?
internal var livenessFiles: [URL]?
private var error: Error?
private var didSubmitBiometricJob: Bool = false

// MARK: - UI Properties

/// we use `errorMessageRes` to map to the actual code to the stringRes to allow localization,
/// and use `errorMessage` to show the actual platform error message that we show if
/// `errorMessageRes` is not set by the partner
@Published var errorMessageRes: String?
@Published var errorMessage: String?
@Published @MainActor private(set) var step: BiometricKycStep = .selfie

init(
userId: String,
jobId: String,
Expand All @@ -44,15 +45,15 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
self.idInfo = idInfo
self.extraPartnerParams = extraPartnerParams
}

func onRetry() {
if selfieFile != nil {
submitJob()
} else {
DispatchQueue.main.async { self.step = .selfie }
}
}

func onFinished(delegate: BiometricKycResultDelegate) {
if let selfieFile = selfieFile,
let livenessFiles = livenessFiles,
Expand All @@ -68,7 +69,7 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
delegate.didError(error: SmileIDError.unknown("onFinish with no result or error"))
}
}

func submitJob() {
DispatchQueue.main.async { self.step = .processing(.inProgress) }
Task {
Expand All @@ -77,19 +78,19 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
jobId: jobId,
fileType: FileType.selfie
)

livenessFiles = try LocalStorage.getFilesByType(
jobId: jobId,
fileType: FileType.liveness
)

guard let selfieFile else {
// Set step to .selfieCapture so that the Retry button goes back to this step
DispatchQueue.main.async { self.step = .selfie }
error = SmileIDError.unknown("Error capturing selfie")
return
}

var allFiles = [URL]()
let infoJson = try LocalStorage.createInfoJsonFile(
jobId: jobId,
Expand Down Expand Up @@ -117,13 +118,15 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
jobType: .biometricKyc,
enrollment: false,
allowNewEnroll: allowNewEnroll,
localMetadata: localMetadata,
partnerParams: extraPartnerParams
)
}
let authResponse = try await SmileID.api.authenticate(request: authRequest)
let prepUploadRequest = PrepUploadRequest(
partnerParams: authResponse.partnerParams.copy(extras: extraPartnerParams),
allowNewEnroll: String(allowNewEnroll), // TODO: - Fix when Michael changes this to boolean
metadata: localMetadata.metadata.items,
timestamp: authResponse.timestamp,
signature: authResponse.signature
)
Expand All @@ -134,12 +137,12 @@ internal class OrchestratedBiometricKycViewModel: ObservableObject {
)
} catch let error as SmileIDError {
switch error {
case .api("2215", _):
prepUploadResponse = try await SmileID.api.prepUpload(
request: prepUploadRequest.copy(retry: "true")
)
default:
throw error
case .api("2215", _):
prepUploadResponse = try await SmileID.api.prepUpload(
request: prepUploadRequest.copy(retry: "true")
)
default:
throw error
}
}
let _ = try await SmileID.api.upload(
Expand Down Expand Up @@ -202,7 +205,7 @@ extension OrchestratedBiometricKycViewModel: SmartSelfieResultDelegate {
) {
submitJob()
}

func didError(error _: Error) {
error = SmileIDError.unknown("Error capturing selfie")
DispatchQueue.main.async { self.step = .processing(.error) }
Expand Down
Loading

0 comments on commit 9b3464d

Please sign in to comment.