Skip to content

Commit

Permalink
Fixed keysign wrong reshare error (#1335)
Browse files Browse the repository at this point in the history
* Fixed keysign wrong reshare issue

* Update app/src/main/java/com/vultisig/wallet/ui/models/keysign/JoinKeysignViewModel.kt

Co-authored-by: yvebe <[email protected]>

* fix

---------

Co-authored-by: yvebe <[email protected]>
  • Loading branch information
yevhen1sec and yvebe authored Nov 11, 2024
1 parent 2ba94c0 commit 28ab65e
Showing 1 changed file with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ internal class JoinKeysignViewModel @Inject constructor(
private var tempKeysignMessageProto: KeysignMessageProto? = null
private val keysignPayload: KeysignPayload?
get() = _keysignPayload

private val deepLinkHelper = MutableStateFlow<DeepLinkHelper?>(null)

val keysignViewModel: KeysignViewModel
get() = KeysignViewModel(
vault = _currentVault,
Expand Down Expand Up @@ -233,22 +236,15 @@ internal class JoinKeysignViewModel @Inject constructor(
try {
val content = Base64.UrlSafe.decode(qrBase64.toByteArray())
.decodeToString()
val deepLink = DeepLinkHelper(content)
val qrCodeContent = deepLink.getJsonData()
deepLinkHelper.value = DeepLinkHelper(content)
val qrCodeContent = requireNotNull(deepLinkHelper.value).getJsonData()
qrCodeContent ?: run {
throw Exception("Invalid QR code content")
}
val rawJson = decompressQr(qrCodeContent.decodeBase64Bytes())

val payloadProto = protoBuf.decodeFromByteArray<KeysignMessage>(rawJson)
Timber.d("Decoded KeysignMessageProto: $payloadProto")
if (deepLink.hasResharePrefix()) {
if (_currentVault.resharePrefix != deepLink.getResharePrefix()) {
currentState.value =
JoinKeysignState.Error(JoinKeysignError.WrongReShare)
return@launch
}
}
this@JoinKeysignViewModel._sessionID = payloadProto.sessionId
this@JoinKeysignViewModel._serviceName = payloadProto.serviceName
this@JoinKeysignViewModel._useVultisigRelay = payloadProto.useVultisigRelay
Expand Down Expand Up @@ -316,6 +312,14 @@ internal class JoinKeysignViewModel @Inject constructor(
return false
}

if (deepLinkHelper.value?.hasResharePrefix() == true) {
if (_currentVault.resharePrefix != requireNotNull(deepLinkHelper.value).getResharePrefix()) {
currentState.value =
JoinKeysignState.Error(JoinKeysignError.WrongReShare)
return false
}
}

val ksPayload = payload.payload
this@JoinKeysignViewModel._keysignPayload = ksPayload

Expand Down

0 comments on commit 28ab65e

Please sign in to comment.