mirror of
https://github.com/pezkuwichain/pezkuwi-wallet-android.git
synced 2026-07-22 17:15:48 +00:00
feat: Bitcoin key derivation, secrets storage, and chain-family plumbing
Derives a BIP84 (native SegWit) keypair alongside the existing substrate/ ethereum/tron ones, stores it in MetaAccountSecrets/CloudBackup, persists bitcoinPublicKey/bitcoinAddress on meta_accounts (DB migration 74->75), and threads isBitcoinBased through Chain/ChainLocal/mappers/ChainExt/ChainRegistry the same way isTronBased was wired. Adds BitcoinAddressBackfillMigration, mirroring TronAddressBackfillMigration, so existing wallets get a Bitcoin address without re-import.
This commit is contained in:
@@ -58,6 +58,7 @@ fun chainOf(
|
||||
isTestNet = false,
|
||||
isEthereumBased = false,
|
||||
isTronBased = false,
|
||||
isBitcoinBased = false,
|
||||
hasCrowdloans = false,
|
||||
additional = "",
|
||||
governance = "governance",
|
||||
|
||||
@@ -94,6 +94,7 @@ import io.novafoundation.nova.core_db.migrations.AddStakingTypeToTotalRewards_44
|
||||
import io.novafoundation.nova.core_db.migrations.AddSwapOption_48_49
|
||||
import io.novafoundation.nova.core_db.migrations.AddTransactionVersionToRuntime_50_51
|
||||
import io.novafoundation.nova.core_db.migrations.AddTransferApisTable_29_30
|
||||
import io.novafoundation.nova.core_db.migrations.AddBitcoinSupport_74_75
|
||||
import io.novafoundation.nova.core_db.migrations.AddTronSupport_73_74
|
||||
import io.novafoundation.nova.core_db.migrations.AddTypeExtrasToMetaAccount_68_69
|
||||
import io.novafoundation.nova.core_db.migrations.AddVersioningToGovernanceDapps_32_33
|
||||
@@ -167,7 +168,7 @@ import io.novafoundation.nova.core_db.model.operation.SwapTypeLocal
|
||||
import io.novafoundation.nova.core_db.model.operation.TransferTypeLocal
|
||||
|
||||
@Database(
|
||||
version = 74,
|
||||
version = 75,
|
||||
entities = [
|
||||
AccountLocal::class,
|
||||
NodeLocal::class,
|
||||
@@ -273,6 +274,7 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
.addMigrations(AddTypeExtrasToMetaAccount_68_69, AddMultisigCalls_69_70, AddMultisigSupportFlag_70_71)
|
||||
.addMigrations(AddGifts_71_72, AddFieldsToContributions)
|
||||
.addMigrations(AddTronSupport_73_74)
|
||||
.addMigrations(AddBitcoinSupport_74_75)
|
||||
.build()
|
||||
}
|
||||
return instance!!
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package io.novafoundation.nova.core_db.migrations
|
||||
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
|
||||
val AddBitcoinSupport_74_75 = object : Migration(74, 75) {
|
||||
|
||||
override fun migrate(db: SupportSQLiteDatabase) {
|
||||
db.execSQL("ALTER TABLE chains ADD COLUMN isBitcoinBased INTEGER NOT NULL DEFAULT 0")
|
||||
|
||||
db.execSQL("ALTER TABLE meta_accounts ADD COLUMN bitcoinPublicKey BLOB")
|
||||
db.execSQL("ALTER TABLE meta_accounts ADD COLUMN bitcoinAddress BLOB")
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,8 @@ data class ChainLocal(
|
||||
val isEthereumBased: Boolean,
|
||||
@ColumnInfo(defaultValue = "0")
|
||||
val isTronBased: Boolean,
|
||||
@ColumnInfo(defaultValue = "0")
|
||||
val isBitcoinBased: Boolean,
|
||||
val isTestNet: Boolean,
|
||||
@ColumnInfo(defaultValue = "1")
|
||||
val hasSubstrateRuntime: Boolean,
|
||||
|
||||
+40
-1
@@ -39,6 +39,8 @@ class MetaAccountLocal(
|
||||
val typeExtras: SerializedJson?,
|
||||
val tronPublicKey: ByteArray? = null,
|
||||
val tronAddress: ByteArray? = null,
|
||||
val bitcoinPublicKey: ByteArray? = null,
|
||||
val bitcoinAddress: ByteArray? = null,
|
||||
) {
|
||||
|
||||
enum class Status {
|
||||
@@ -59,6 +61,9 @@ class MetaAccountLocal(
|
||||
const val TRON_PUBKEY = "tronPublicKey"
|
||||
const val TRON_ADDRESS = "tronAddress"
|
||||
|
||||
const val BITCOIN_PUBKEY = "bitcoinPublicKey"
|
||||
const val BITCOIN_ADDRESS = "bitcoinAddress"
|
||||
|
||||
const val NAME = "name"
|
||||
const val IS_SELECTED = "isSelected"
|
||||
const val POSITION = "position"
|
||||
@@ -90,7 +95,37 @@ class MetaAccountLocal(
|
||||
globallyUniqueId = globallyUniqueId,
|
||||
typeExtras = typeExtras,
|
||||
tronPublicKey = tronPublicKey,
|
||||
tronAddress = tronAddress
|
||||
tronAddress = tronAddress,
|
||||
bitcoinPublicKey = bitcoinPublicKey,
|
||||
bitcoinAddress = bitcoinAddress,
|
||||
).also {
|
||||
it.id = id
|
||||
}
|
||||
}
|
||||
|
||||
// We do not use copy as we need explicitly set id
|
||||
fun addBitcoinAccount(
|
||||
bitcoinPublicKey: ByteArray,
|
||||
bitcoinAddress: ByteArray,
|
||||
): MetaAccountLocal {
|
||||
return MetaAccountLocal(
|
||||
substratePublicKey = substratePublicKey,
|
||||
substrateCryptoType = substrateCryptoType,
|
||||
substrateAccountId = substrateAccountId,
|
||||
ethereumPublicKey = ethereumPublicKey,
|
||||
ethereumAddress = ethereumAddress,
|
||||
name = name,
|
||||
parentMetaId = parentMetaId,
|
||||
isSelected = isSelected,
|
||||
position = position,
|
||||
type = type,
|
||||
status = status,
|
||||
globallyUniqueId = globallyUniqueId,
|
||||
typeExtras = typeExtras,
|
||||
tronPublicKey = tronPublicKey,
|
||||
tronAddress = tronAddress,
|
||||
bitcoinPublicKey = bitcoinPublicKey,
|
||||
bitcoinAddress = bitcoinAddress,
|
||||
).also {
|
||||
it.id = id
|
||||
}
|
||||
@@ -109,6 +144,8 @@ class MetaAccountLocal(
|
||||
if (!ethereumAddress.contentEquals(other.ethereumAddress)) return false
|
||||
if (!tronPublicKey.contentEquals(other.tronPublicKey)) return false
|
||||
if (!tronAddress.contentEquals(other.tronAddress)) return false
|
||||
if (!bitcoinPublicKey.contentEquals(other.bitcoinPublicKey)) return false
|
||||
if (!bitcoinAddress.contentEquals(other.bitcoinAddress)) return false
|
||||
if (name != other.name) return false
|
||||
if (parentMetaId != other.parentMetaId) return false
|
||||
if (isSelected != other.isSelected) return false
|
||||
@@ -130,6 +167,8 @@ class MetaAccountLocal(
|
||||
result = 31 * result + (ethereumAddress?.contentHashCode() ?: 0)
|
||||
result = 31 * result + (tronPublicKey?.contentHashCode() ?: 0)
|
||||
result = 31 * result + (tronAddress?.contentHashCode() ?: 0)
|
||||
result = 31 * result + (bitcoinPublicKey?.contentHashCode() ?: 0)
|
||||
result = 31 * result + (bitcoinAddress?.contentHashCode() ?: 0)
|
||||
result = 31 * result + name.hashCode()
|
||||
result = 31 * result + (parentMetaId?.hashCode() ?: 0)
|
||||
result = 31 * result + isSelected.hashCode()
|
||||
|
||||
Reference in New Issue
Block a user