Skip to content

Commit

Permalink
Merge branch 'main' into fix/ABW-3664-default-modal-insets
Browse files Browse the repository at this point in the history
# Conflicts:
#	app/src/main/java/com/babylon/wallet/android/presentation/settings/preferences/gateways/GatewaysScreen.kt
  • Loading branch information
jakub-rdx committed Aug 6, 2024
2 parents 5a3a395 + 77b3894 commit e9d2a26
Show file tree
Hide file tree
Showing 90 changed files with 1,223 additions and 1,639 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/com/babylon/wallet/android/WalletApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ import com.babylon.wallet.android.presentation.accessfactorsources.derivepublick
import com.babylon.wallet.android.presentation.accessfactorsources.signatures.getSignatures
import com.babylon.wallet.android.presentation.dapp.authorized.login.dAppLoginAuthorized
import com.babylon.wallet.android.presentation.dapp.unauthorized.login.dAppLoginUnauthorized
import com.babylon.wallet.android.presentation.dialogs.address.addressDetails
import com.babylon.wallet.android.presentation.dialogs.dapp.dappInteractionDialog
import com.babylon.wallet.android.presentation.dialogs.transaction.transactionStatusDialog
import com.babylon.wallet.android.presentation.main.MAIN_ROUTE
import com.babylon.wallet.android.presentation.main.MainEvent
import com.babylon.wallet.android.presentation.main.MainViewModel
import com.babylon.wallet.android.presentation.mobileconnect.mobileConnect
import com.babylon.wallet.android.presentation.navigation.NavigationHost
import com.babylon.wallet.android.presentation.navigation.PriorityRoutes
import com.babylon.wallet.android.presentation.rootdetection.ROUTE_ROOT_DETECTION
import com.babylon.wallet.android.presentation.status.address.addressDetails
import com.babylon.wallet.android.presentation.status.dapp.dappInteractionDialog
import com.babylon.wallet.android.presentation.status.transaction.transactionStatusDialog
import com.babylon.wallet.android.presentation.transaction.transactionReview
import com.babylon.wallet.android.presentation.ui.composables.BDFSErrorDialog
import com.babylon.wallet.android.presentation.ui.composables.BasicPromptAlertDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ private fun DappToWalletInteractionUnauthorizedRequestItems.parseUnauthorizedReq
)
}

fun DappToWalletInteractionPersonaDataRequestItem.toDomainModel(isOngoing: Boolean = false): PersonaRequestItem? {
if (isRequestingName == null && numberOfRequestedPhoneNumbers == null && numberOfRequestedEmailAddresses == null) return null
fun DappToWalletInteractionPersonaDataRequestItem.toDomainModel(isOngoing: Boolean = false): PersonaRequestItem {
return PersonaRequestItem(
isRequestingName = isRequestingName == true,
numberOfRequestedEmailAddresses = numberOfRequestedEmailAddresses?.toDomainModel(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.babylon.wallet.android.data.transaction

import com.babylon.wallet.android.domain.RadixWalletException
import com.babylon.wallet.android.domain.model.signing.SignRequest
import com.babylon.wallet.android.domain.model.signing.SignType
import com.babylon.wallet.android.domain.usecases.assets.GetEntitiesOwnerKeysUseCase
import com.babylon.wallet.android.domain.usecases.transaction.CollectSignersSignaturesUseCase
import com.babylon.wallet.android.domain.usecases.transaction.GenerateAuthSigningFactorInstanceUseCase
import com.babylon.wallet.android.domain.usecases.transaction.SignRequest
import com.babylon.wallet.android.presentation.accessfactorsources.AccessFactorSourcesInput
import com.babylon.wallet.android.presentation.accessfactorsources.AccessFactorSourcesProxy
import com.radixdlt.sargon.HierarchicalDeterministicFactorInstance
import com.radixdlt.sargon.PublicKey
import com.radixdlt.sargon.PublicKeyHash
Expand All @@ -14,22 +15,16 @@ import com.radixdlt.sargon.extensions.ProfileEntity
import com.radixdlt.sargon.extensions.hex
import com.radixdlt.sargon.extensions.init
import com.radixdlt.sargon.extensions.setOwnerKeysHashes
import kotlinx.coroutines.flow.merge
import rdx.works.core.domain.TransactionManifestData
import rdx.works.core.sargon.transactionSigningFactorInstance
import javax.inject.Inject

class ROLAClient @Inject constructor(
private val getEntitiesOwnerKeysUseCase: GetEntitiesOwnerKeysUseCase,
private val generateAuthSigningFactorInstanceUseCase: GenerateAuthSigningFactorInstanceUseCase,
private val collectSignersSignaturesUseCase: CollectSignersSignaturesUseCase
private val accessFactorSourcesProxy: AccessFactorSourcesProxy
) {

val signingState = merge(
collectSignersSignaturesUseCase.interactionState,
generateAuthSigningFactorInstanceUseCase.interactionState
)

suspend fun generateAuthSigningFactorInstance(entity: ProfileEntity): Result<HierarchicalDeterministicFactorInstance> {
return generateAuthSigningFactorInstanceUseCase(entity)
}
Expand Down Expand Up @@ -62,25 +57,17 @@ class ROLAClient @Inject constructor(
}

suspend fun signAuthChallenge(
entity: ProfileEntity,
signRequest: SignRequest.SignAuthChallengeRequest,
deviceBiometricAuthenticationProvider: suspend () -> Boolean
): Result<SignatureWithPublicKey> {
val result = collectSignersSignaturesUseCase(
signers = listOf(entity),
signRequest = signRequest,
deviceBiometricAuthenticationProvider = deviceBiometricAuthenticationProvider
)
return when (val exception = result.exceptionOrNull()) {
null -> result.mapCatching { signatures ->
if (signatures.size == 1) {
signatures.first()
} else {
throw RadixWalletException.DappRequestException.FailedToSignAuthChallenge()
}
}

else -> Result.failure(RadixWalletException.DappRequestException.FailedToSignAuthChallenge(exception))
entities: List<ProfileEntity>
): Result<Map<ProfileEntity, SignatureWithPublicKey>> {
return accessFactorSourcesProxy.getSignatures(
accessFactorSourcesInput = AccessFactorSourcesInput.ToGetSignatures(
signType = SignType.ProvingOwnership,
signRequest = signRequest,
signers = entities
)
).mapCatching { output ->
output.signersWithSignatures
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,10 @@ sealed interface IncomingMessage {
val oneTimeAccountsRequestItem: AccountsRequestItem? = null,
val oneTimePersonaDataRequestItem: PersonaRequestItem? = null
) : IncomingRequest(remoteEntityId, interactionId, requestMetadata) {

fun isValidRequest(): Boolean {
return oneTimeAccountsRequestItem?.isValidRequestItem() != false
}

fun needSignatures(): Boolean {
return oneTimeAccountsRequestItem?.challenge != null
}
}

data class TransactionRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.babylon.wallet.android.domain.model.signing

import com.radixdlt.sargon.SignatureWithPublicKey
import com.radixdlt.sargon.extensions.ProfileEntity

/**
* A data class that holds an entity and its signature
*
*/
data class EntityWithSignature(
val entity: ProfileEntity,
val signatureWithPublicKey: SignatureWithPublicKey
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.babylon.wallet.android.domain.model.signing

import com.babylon.wallet.android.utils.removeTrailingSlash
import com.radixdlt.sargon.BagOfBytes
import com.radixdlt.sargon.Hash
import com.radixdlt.sargon.TransactionIntent
import com.radixdlt.sargon.extensions.bagOfBytesOf
import com.radixdlt.sargon.extensions.compile
import com.radixdlt.sargon.extensions.hash
import com.radixdlt.sargon.extensions.hexToBagOfBytes
import rdx.works.core.toByteArray

sealed interface SignRequest {

val dataToSign: BagOfBytes
val hashedDataToSign: Hash

class SignTransactionRequest(
intent: TransactionIntent
) : SignRequest {
// Used when signing with Ledger
override val dataToSign: BagOfBytes = intent.compile()

// Used when signing with device
override val hashedDataToSign: Hash = intent.hash().hash
}

class SignAuthChallengeRequest(
val challengeHex: String,
val origin: String,
val dAppDefinitionAddress: String
) : SignRequest {

// TODO removeTrailingSlash is a hack to fix the issue with dapp login, it should be removed after logic is moved to sargon
override val dataToSign: BagOfBytes
get() {
require(dAppDefinitionAddress.length <= UByte.MAX_VALUE.toInt())
return bagOfBytesOf(
byteArrayOf(ROLA_PAYLOAD_PREFIX.toByte()) +
challengeHex.hexToBagOfBytes().toByteArray() +
dAppDefinitionAddress.length.toUByte().toByte() +
dAppDefinitionAddress.toByteArray() +
origin.removeTrailingSlash().toByteArray()
)
}

override val hashedDataToSign: Hash
get() = dataToSign.hash()

companion object {
const val ROLA_PAYLOAD_PREFIX = 0x52
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.babylon.wallet.android.domain.model.signing

enum class SignType {
SigningTransaction, ProvingOwnership
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,8 @@ class AuthorizeSpecifiedPersonaUseCase @Inject constructor(
var operationResult: Result<DAppData> = Result.failure(
RadixWalletException.DappRequestException.NotPossibleToAuthenticateAutomatically
)
if (incomingRequest.isMobileConnectRequest) {
return operationResult
}

(incomingRequest as? AuthorizedRequest)?.let { request ->
if (incomingRequest.needSignatures()) {
return@let
}
(request.authRequest as? AuthorizedRequest.AuthRequest.UsePersonaRequest)?.let {
val authorizedDapp = dAppConnectionRepository.getAuthorizedDApp(
dAppDefinitionAddress = AccountAddress.init(request.metadata.dAppDefinitionAddress)
Expand All @@ -62,6 +57,9 @@ class AuthorizeSpecifiedPersonaUseCase @Inject constructor(
respondWithInvalidPersona(incomingRequest)
return Result.failure(RadixWalletException.DappRequestException.InvalidPersona)
}
if (incomingRequest.needSignatures() || incomingRequest.isMobileConnectRequest) {
return operationResult
}
val authorizedPersonaSimple = authorizedDapp
.referencesToAuthorizedPersonas
.firstOrNull { authorizedPersonaSimple ->
Expand Down
Loading

0 comments on commit e9d2a26

Please sign in to comment.