Skip to content

Commit

Permalink
Add fingerprint (#400)
Browse files Browse the repository at this point in the history
* Track document image origin

* Update test

* Add fingerprint

* Use default empty string instead of lateinit var

* Update test
  • Loading branch information
vanshg authored Jul 3, 2024
1 parent b31aa56 commit cdd855d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ coil = "2.6.0"
compose-lint-checks = "1.3.1"
coroutines = "1.8.1"
datastore = "1.1.1"
fingerprint-js = "2.1.0"
junit = "4.13.2"
kotlin = "2.0.0"
kotlin-immutable-collections = "0.3.7"
Expand Down Expand Up @@ -90,6 +91,7 @@ compose-lint-checks = { module = "com.slack.lint.compose:compose-lint-checks", v
coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
datastore = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" }
fingerprint-js = { module = "com.github.fingerprintjs:fingerprint-android", version.ref = "fingerprint-js" }
junit = { module = "junit:junit", version.ref = "junit" }
kotlin-immutable-collections = { module = "org.jetbrains.kotlinx:kotlinx-collections-immutable", version.ref = "kotlin-immutable-collections" }
leakcanary = { module = "com.squareup.leakcanary:leakcanary-android", version.ref = "leakcanary" }
Expand Down
2 changes: 2 additions & 0 deletions lib/lib.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ dependencies {
testImplementation(libs.mockk)
androidTestImplementation(libs.mockk.android)

implementation(libs.fingerprint.js)

androidTestImplementation(libs.androidx.test.core)
androidTestImplementation(libs.androidx.test.rules)
androidTestImplementation(libs.androidx.test.junit)
Expand Down
7 changes: 7 additions & 0 deletions lib/src/main/java/com/smileidentity/SmileID.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.smileidentity
import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE
import com.fingerprintjs.android.fingerprint.Fingerprinter
import com.fingerprintjs.android.fingerprint.FingerprinterFactory
import com.google.android.gms.common.moduleinstall.ModuleInstall
import com.google.android.gms.common.moduleinstall.ModuleInstallRequest
import com.google.mlkit.common.sdkinternal.MlKitContext
Expand Down Expand Up @@ -85,6 +87,7 @@ object SmileID {
internal var apiKey: String? = null

internal lateinit var fileSavePath: String
internal var fingerprint = ""

/**
* Initialize the SDK. This must be called before any other SDK methods.
Expand Down Expand Up @@ -137,6 +140,10 @@ object SmileID {

// Usually looks like: /data/user/0/<package name>/app_SmileID
fileSavePath = context.getDir("SmileID", MODE_PRIVATE).absolutePath
FingerprinterFactory.create(context).getFingerprint(version = Fingerprinter.Version.V_5) {
// Returns empty string if there was an error
fingerprint = it
}
}

/**
Expand Down
9 changes: 8 additions & 1 deletion lib/src/main/java/com/smileidentity/models/v2/Metadata.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.smileidentity.models.v2

import android.os.Parcelable
import com.smileidentity.BuildConfig
import com.smileidentity.SmileID
import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass
import dev.zacsweers.moshix.sealed.annotations.TypeLabel
Expand All @@ -14,7 +15,9 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class Metadata(val items: List<Metadatum>) : Parcelable {
companion object {
fun default(): Metadata = Metadata(listOf(Metadatum.Sdk, Metadatum.SdkVersion))
fun default(): Metadata = Metadata(
listOf(Metadatum.Sdk, Metadatum.SdkVersion, Metadatum.Fingerprint),
)
}
}

Expand All @@ -34,6 +37,10 @@ sealed class Metadatum(
@TypeLabel(label = "sdk_version")
data object SdkVersion : Metadatum(BuildConfig.VERSION_NAME)

@Parcelize
@TypeLabel(label = "fingerprint")
data object Fingerprint : Metadatum(SmileID.fingerprint)

@Parcelize
@TypeLabel(label = "document_front_image_origin")
data class DocumentFrontImageOrigin(val origin: DocumentImageOriginValue) :
Expand Down
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
// TODO: Remove once https://github.com/fingerprintjs/fingerprintjs-android/issues/76 is
// resolved
maven("https://jitpack.io")
}
}

0 comments on commit cdd855d

Please sign in to comment.