-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02796a9
commit f1ffc01
Showing
34 changed files
with
605 additions
and
173 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
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
17 changes: 17 additions & 0 deletions
17
apps/wallet/data/rn/src/main/java/com/tonapps/wallet/data/rn/RNException.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.tonapps.wallet.data.rn | ||
|
||
sealed class RNException(message: String, cause: Throwable? = null) : Exception(message, cause) { | ||
|
||
data object EmptyChunks: RNException("wallets_chunks = 0") { | ||
private fun readResolve(): Any = EmptyChunks | ||
} | ||
|
||
data class NotFoundChunk(val chunk: Int): RNException("chunk $chunk not found") | ||
|
||
data class NotFoundMnemonic(val walletId: String): RNException("mnemonic for wallet $walletId not found") | ||
|
||
data object NotFoundPasscode: RNException("passcode not found") { | ||
private fun readResolve(): Any = NotFoundPasscode | ||
} | ||
|
||
} |
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
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
36 changes: 36 additions & 0 deletions
36
apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/extensions/AccountRepository.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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.tonapps.tonkeeper.extensions | ||
|
||
import com.tonapps.wallet.data.account.AccountRepository | ||
import com.tonapps.wallet.data.rn.RNException | ||
import com.tonapps.wallet.data.rn.RNLegacy | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.ton.api.pk.PrivateKeyEd25519 | ||
import org.ton.mnemonic.Mnemonic | ||
import uikit.navigation.NavigationActivity | ||
|
||
suspend fun AccountRepository.requestPrivateKey( | ||
activity: NavigationActivity, | ||
rnLegacy: RNLegacy, | ||
walletId: String, | ||
): PrivateKeyEd25519 = withContext(Dispatchers.IO) { | ||
val privateKeyEd25519 = getPrivateKey(walletId) | ||
if (privateKeyEd25519 != null) { | ||
privateKeyEd25519 | ||
} else { | ||
val vaultState = rnLegacy.requestVault(activity) | ||
val mnemonic = vaultState.getDecryptedData(walletId)?.mnemonic ?: throw RNException.NotFoundMnemonic(walletId) | ||
val seed = Mnemonic.toSeed(splitMnemonic(mnemonic)) | ||
PrivateKeyEd25519(seed) | ||
} | ||
} | ||
|
||
private fun splitMnemonic(mnemonic: String): List<String> { | ||
val words = if (mnemonic.contains(",")) { | ||
mnemonic.split(",") | ||
} else { | ||
mnemonic.split(" ") | ||
} | ||
return words.map { it.trim() } | ||
} | ||
|
39 changes: 39 additions & 0 deletions
39
apps/wallet/instance/app/src/main/java/com/tonapps/tonkeeper/extensions/RNLegacy.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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.tonapps.tonkeeper.extensions | ||
|
||
import com.tonapps.wallet.data.passcode.dialog.PasscodeDialog | ||
import com.tonapps.wallet.data.rn.RNException | ||
import com.tonapps.wallet.data.rn.RNLegacy | ||
import com.tonapps.wallet.data.rn.data.RNVaultState | ||
import com.tonapps.wallet.data.rn.data.RNWallets | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import uikit.navigation.NavigationActivity | ||
|
||
suspend fun RNLegacy.requestVault( | ||
activity: NavigationActivity | ||
): RNVaultState = withContext(Dispatchers.IO) { | ||
val wallets = getWallets() | ||
if (wallets.count == 0) { | ||
throw IllegalStateException("No wallets found") | ||
} | ||
val passcode = requestPasscode(activity, wallets) | ||
getVaultStateWithThrow(passcode) | ||
} | ||
|
||
private suspend fun RNLegacy.requestPasscode( | ||
activity: NavigationActivity, | ||
wallets: RNWallets | ||
): String = withContext(Dispatchers.Main) { | ||
val passcodeFromBiometry = if (wallets.biometryEnabled) { | ||
exportPasscodeWithBiometry() | ||
} else { | ||
null | ||
} | ||
val passcode = if (!passcodeFromBiometry.isNullOrBlank()) { | ||
passcodeFromBiometry | ||
} else { | ||
PasscodeDialog.request(activity) | ||
} | ||
|
||
passcode ?: throw RNException.NotFoundPasscode | ||
} |
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.