-
Notifications
You must be signed in to change notification settings - Fork 3
feat: bump core to 0.3.9 and hw reliability #1062
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
493eee4
ee98278
44a42ae
c3a41d2
5ae87c0
25c3a79
32dbef7
1ba128d
3dfbc32
2e5fba0
f572fb0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package to.bitkit.ext | ||
|
|
||
| import kotlinx.serialization.json.JsonArray | ||
| import kotlinx.serialization.json.JsonElement | ||
| import kotlinx.serialization.json.JsonObject | ||
| import kotlinx.serialization.json.JsonPrimitive | ||
| import to.bitkit.di.json | ||
| import to.bitkit.models.ActivityBackupV1 | ||
| import to.bitkit.models.MetadataBackupV1 | ||
| import to.bitkit.models.WalletScope | ||
|
|
||
| fun String.decodeActivityBackupV1Compat(): ActivityBackupV1 = | ||
| json.decodeFromString(normalizeLegacyWalletIdsInBackupJson(this)) | ||
|
|
||
| fun String.decodeMetadataBackupV1Compat(): MetadataBackupV1 = | ||
| json.decodeFromString(normalizeLegacyWalletIdsInBackupJson(this)) | ||
|
|
||
| private fun normalizeLegacyWalletIdsInBackupJson( | ||
| raw: String, | ||
| walletId: String = WalletScope.default, | ||
| ): String { | ||
| val normalized = json.parseToJsonElement(raw).normalizeLegacyWalletIds(walletId) | ||
| return json.encodeToString(normalized) | ||
| } | ||
|
|
||
| private fun JsonElement.normalizeLegacyWalletIds(walletId: String): JsonElement = when (this) { | ||
| is JsonObject -> { | ||
| val patched = if (needsLegacyWalletId() && "walletId" !in this) { | ||
| this + ("walletId" to JsonPrimitive(walletId)) | ||
| } else { | ||
| this | ||
| } | ||
| JsonObject(patched.mapValues { (_, value) -> value.normalizeLegacyWalletIds(walletId) }) | ||
| } | ||
| is JsonArray -> JsonArray(map { it.normalizeLegacyWalletIds(walletId) }) | ||
| else -> this | ||
| } | ||
|
|
||
| private fun JsonObject.needsLegacyWalletId(): Boolean = when { | ||
| "paymentId" in this && "tags" in this && "isReceive" in this -> true | ||
| "activityId" in this && "tags" in this && "paymentId" !in this -> true | ||
| "txId" in this && "txType" in this && "value" in this -> true | ||
| "invoice" in this && "status" in this && "txType" in this -> true | ||
| else -> false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package to.bitkit.ext | ||
|
|
||
| import com.synonym.bitkitcore.TrezorException | ||
|
|
||
| fun Throwable.isTrezorUserCancellation(): Boolean { | ||
| var current: Throwable? = this | ||
| while (current != null) { | ||
| when (current) { | ||
| is TrezorException.UserCancelled, | ||
| is TrezorException.PinCancelled, | ||
| is TrezorException.PassphraseCancelled, | ||
| -> return true | ||
| } | ||
| current = current.cause | ||
| } | ||
| return false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package to.bitkit.models | ||
|
|
||
| import com.synonym.bitkitcore.deriveWalletId | ||
|
|
||
| object HwWalletId { | ||
| fun derive(xpubs: Map<String, String>, deviceType: String = "trezor"): String { | ||
| require(xpubs.isNotEmpty()) { "xpubs must not be empty" } | ||
| return deriveWalletId(deviceType = deviceType, xpubs = xpubs.values.toList()) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package to.bitkit.models | ||
|
|
||
| import androidx.annotation.VisibleForTesting | ||
| import com.synonym.bitkitcore.getDefaultWalletId | ||
|
|
||
| object WalletScope { | ||
| @VisibleForTesting | ||
| internal var testOverride: String? = null | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A missed tearDown or parallel run leaks a wallet id across test |
||
|
|
||
| val default: String | ||
| get() = testOverride ?: lazyDefault | ||
|
|
||
| private val lazyDefault: String by lazy { getDefaultWalletId() } | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend also revert the changes from this file, same reason https://github.com/synonymdev/bitkit-android/pull/1062/changes#r3535801605 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This compatibility layer should be handled by #1046 , gated by synonymdev/bitkit-core#113
I recommend drop this file and wait for Bitkit-core implementation
Summarizing, we need to implement wallet-scope backup migrations because of the new walletId. The logic must be in Bitkit-core for single source of true
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree long-term: wallet-scoped backup migration belongs in Core (#113) and the app integration in #1046.
BackupRestoreCompatis a minimal bridge added after Codex flagged legacy VSS restore failing on missingwalletIdonce we bumped to 0.3.9 (P1 on this PR). It keeps existing hot-wallet cloud backup restore working until Core exposes migration APIs — it does not add Trezor/HW tag product scope for 2.4.0.Happy to drop it as soon as synonymdev/bitkit-core#113 lands and wire the proper flow in #1046.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: might also be patch-able by making the serializer more lenient on Kotlin's
Jsoninstance, maybe a derivation of our globaldi.jsoninstance (if that wasn't already tried and deemed not applicable here); or perhaps by playing with an optionalwalletIdon a domain replica of the original serialized model originating from core, which adds optional fields, given that thejsoninstance is already configured withisLenient = true