-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ErgoAuth Android implementation done #112
- Loading branch information
1 parent
ccbcbba
commit ff755d7
Showing
8 changed files
with
206 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 31 additions & 6 deletions
37
android/src/main/java/org/ergoplatform/android/ergoauth/ErgoAuthenticationViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,51 @@ | ||
package org.ergoplatform.android.ergoauth | ||
|
||
import android.content.Context | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import kotlinx.coroutines.CoroutineScope | ||
import org.ergoplatform.ergoauth.ErgoAuthRequest | ||
import org.ergoplatform.SigningSecrets | ||
import org.ergoplatform.android.ui.AndroidStringProvider | ||
import org.ergoplatform.api.AesEncryptionManager | ||
import org.ergoplatform.api.AndroidEncryptionManager | ||
import org.ergoplatform.uilogic.StringProvider | ||
import org.ergoplatform.uilogic.ergoauth.ErgoAuthUiLogic | ||
|
||
class ErgoAuthenticationViewModel: ViewModel() { | ||
val uiLogic = AndroidUiLogic() | ||
|
||
private val _authRequest = MutableLiveData<ErgoAuthRequest?>() | ||
val authRequest: LiveData<ErgoAuthRequest?> get() = _authRequest | ||
private val _state = MutableLiveData(ErgoAuthUiLogic.State.FETCHING_DATA) | ||
val state: LiveData<ErgoAuthUiLogic.State?> get() = _state | ||
|
||
fun startAuthenticationFromBiometrics(context: Context) { | ||
uiLogic.walletConfig?.secretStorage?.let { | ||
val decryptData = AndroidEncryptionManager.decryptDataWithDeviceKey(it) | ||
val secrets = SigningSecrets.fromBytes(decryptData!!) | ||
uiLogic.startResponse(secrets!!, AndroidStringProvider(context)) | ||
} | ||
} | ||
|
||
fun startAuthenticationFromPassword(password: String, texts: StringProvider): Boolean { | ||
return uiLogic.walletConfig?.secretStorage?.let { | ||
return try { | ||
val decryptData = AesEncryptionManager.decryptData(password, it) | ||
val secrets = SigningSecrets.fromBytes(decryptData!!) | ||
uiLogic.startResponse(secrets!!, texts) | ||
true | ||
} catch (t: Throwable) { | ||
false | ||
} | ||
} ?: false | ||
} | ||
|
||
inner class AndroidUiLogic: ErgoAuthUiLogic() { | ||
override val coroutineScope: CoroutineScope | ||
get() = viewModelScope | ||
|
||
override fun notifyAuthRequestFetched() { | ||
_authRequest.postValue(ergAuthRequest) | ||
override fun notifyStateChanged(newState: State) { | ||
_state.postValue(newState) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.