Updated on 2026-08-14
This commit is contained in:
commit
ebc298a557
2 changed files with 37 additions and 1 deletions
|
|
@ -17,6 +17,7 @@ import com.tangem.tap.domain.userWalletList.repository.implementation.DefaultUse
|
|||
import com.tangem.tap.domain.userWalletList.repository.implementation.DefaultUserWalletsSensitiveInformationRepository
|
||||
import com.tangem.tap.domain.userWalletList.utils.json.ByteArrayKeyAdapter
|
||||
import com.tangem.tap.domain.userWalletList.utils.json.CardBackupStatusAdapter
|
||||
import com.tangem.tap.domain.userWalletList.utils.json.DerivationPathAdapterWithMigration
|
||||
import com.tangem.tap.domain.userWalletList.utils.json.ExtendedPublicKeysMapAdapter
|
||||
import com.tangem.tap.domain.userWalletList.utils.json.ScanResponseDerivedKeysMapAdapter
|
||||
import com.tangem.tap.domain.userWalletList.utils.json.WalletDerivedKeysMapAdapter
|
||||
|
|
@ -33,8 +34,8 @@ fun UserWalletsListManager.Companion.provideBiometricImplementation(
|
|||
.add(ByteArrayKeyAdapter())
|
||||
.add(ExtendedPublicKeysMapAdapter())
|
||||
.add(CardBackupStatusAdapter())
|
||||
.add(DerivationPathAdapterWithMigration())
|
||||
.add(TangemSdkAdapter.DateAdapter())
|
||||
.add(TangemSdkAdapter.DerivationPathAdapter())
|
||||
.add(TangemSdkAdapter.DerivationNodeAdapter())
|
||||
.add(TangemSdkAdapter.FirmwareVersionAdapter()) // For PrimaryCard model
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
package com.tangem.tap.domain.userWalletList.utils.json
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import com.tangem.common.extensions.guard
|
||||
import com.tangem.common.json.MoshiJsonConverter
|
||||
import com.tangem.crypto.hdWallet.DerivationNode
|
||||
import com.tangem.crypto.hdWallet.DerivationPath
|
||||
import timber.log.Timber
|
||||
|
||||
class DerivationPathAdapterWithMigration {
|
||||
@ToJson
|
||||
fun toJson(src: DerivationPath): String = src.rawPath
|
||||
|
||||
@FromJson
|
||||
fun fromJson(json: String): DerivationPath {
|
||||
val jsonMap = MoshiJsonConverter.default().toMap(json)
|
||||
return if (jsonMap.isEmpty()) {
|
||||
DerivationPath(json)
|
||||
} else {
|
||||
fromLegacyScheme(jsonMap)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun fromLegacyScheme(jsonMap: Map<String, Any>): DerivationPath {
|
||||
val rawPath = jsonMap["rawPath"] as String
|
||||
val nodeIndexes = (jsonMap["nodes"] as? List<Number>).guard {
|
||||
Timber.e("Unable to convert derivation path nodes from JSON")
|
||||
return DerivationPath(rawPath)
|
||||
}
|
||||
val nodes = nodeIndexes.map { DerivationNode.fromIndex(it.toLong()) }
|
||||
return DerivationPath(rawPath, nodes)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue