Skip to content

Commit

Permalink
Final 1640 changes stirp out
Browse files Browse the repository at this point in the history
The rest of the changes (tests changes) will be used by 1640 though
  • Loading branch information
HonzaR committed Dec 4, 2024
1 parent 6f51c74 commit 2f4ac4c
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ class JniUnifiedSpendingKey(
*/
val bytes: ByteArray
) {
init {
require(accountUuid.size == 16) {
"Account UUID must be 16 bytes"
}
}

// Override to prevent leaking key to logs
override fun toString() = "JniUnifiedSpendingKey(account=$account, bytes=***)"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TestWallet(
DerivationTool.getInstance().deriveUnifiedSpendingKey(
seed = seed,
network = network,
accountIndex = AccountFixture.ZIP_32_ACCOUNT_INDEX
account = AccountFixture.new()
)
}
val synchronizer: SdkSynchronizer =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class SampleCodeTest {
DerivationTool.getInstance().deriveUnifiedSpendingKey(
seed,
ZcashNetwork.Mainnet,
AccountFixture.ZIP_32_ACCOUNT_INDEX
AccountFixture.new()
)
synchronizer.createProposedTransactions(
synchronizer.proposeTransfer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import cash.z.ecc.android.sdk.ext.convertZatoshiToZec
import cash.z.ecc.android.sdk.ext.convertZatoshiToZecString
import cash.z.ecc.android.sdk.ext.toUsdString
import cash.z.ecc.android.sdk.internal.Twig
import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.PercentDecimal
import cash.z.ecc.android.sdk.model.WalletBalance
import cash.z.ecc.android.sdk.model.Zatoshi
Expand Down Expand Up @@ -78,7 +79,7 @@ class GetBalanceFragment : BaseDemoFragment<FragmentGetBalanceBinding>() {
DerivationTool.getInstance().deriveUnifiedSpendingKey(
seed,
network,
CURRENT_ZIP_32_ACCOUNT_INDEX
Account(CURRENT_ZIP_32_ACCOUNT_INDEX)
)
sharedViewModel.synchronizerFlow.value?.let { synchronizer ->
synchronizer.proposeShielding(usk.account, Zatoshi(100000))?.let { it1 ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import cash.z.ecc.android.sdk.demoapp.BaseDemoFragment
import cash.z.ecc.android.sdk.demoapp.databinding.FragmentGetPrivateKeyBinding
import cash.z.ecc.android.sdk.demoapp.ext.requireApplicationContext
import cash.z.ecc.android.sdk.demoapp.util.fromResources
import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.ZcashNetwork
import cash.z.ecc.android.sdk.tool.DerivationTool
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -49,7 +50,7 @@ class GetPrivateKeyFragment : BaseDemoFragment<FragmentGetPrivateKeyBinding>() {
DerivationTool.getInstance().deriveUnifiedSpendingKey(
seed,
ZcashNetwork.fromResources(requireApplicationContext()),
5
Account(5)
)

// derive the key that allows you to view but not spend transactions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cash.z.ecc.android.sdk.fixture
import cash.z.ecc.android.sdk.model.Account
import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.model.ZcashNetwork
import java.util.UUID

/**
* Provides two default wallets, making it easy to test sending funds back and forth between them.
Expand All @@ -20,7 +19,7 @@ sealed class WalletFixture {
@Suppress("MaxLineLength")
data object Ben : WalletFixture() {
override val accounts: List<Account>
get() = listOf(AccountFixture.new(UUID.fromString("52175368-821a-4664-8a7c-6a75d850f71c")))
get() = listOf(AccountFixture.new(0))

override val seedPhrase: String
get() =
Expand Down Expand Up @@ -57,7 +56,7 @@ sealed class WalletFixture {
@Suppress("MaxLineLength")
data object Alice : WalletFixture() {
override val accounts: List<Account>
get() = listOf(AccountFixture.new(UUID.fromString("8a204240-73a5-4e7a-93c2-a6e05711a000")))
get() = listOf(AccountFixture.new(1))

override val seedPhrase: String
get() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object WalletFixture {
accountIndex: Int = ACCOUNT_INDEX
) = RustDerivationTool.new().deriveUnifiedSpendingKey(
Mnemonics.MnemonicCode(seed).toEntropy(),
network,
network.id,
accountIndex
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ import java.util.UUID
* Note that these values are used in the automated tests only and are not passed across the JNI.
*/
object AccountFixture {
@Suppress("UnusedPrivateMember")
val ACCOUNT_UUID = UUID.fromString("01234567-89ab-cdef-0123-456789abcdef")
const val ZIP_32_ACCOUNT_INDEX = 0

fun new(accountUuid: UUID = ACCOUNT_UUID) =
fun new(accountId: Int = ZIP_32_ACCOUNT_INDEX) =
Account(
accountUuid = accountUuid.toByteArray()
value = accountId
)
}

private const val UUID_V4_BYTE_SIZE = 16

// This provides us with a way to convert [UUID] to [ByteArray]
@Suppress("UnusedPrivateMember")
private fun UUID.toByteArray(): ByteArray =
ByteBuffer
.allocate(UUID_V4_BYTE_SIZE)
Expand Down
17 changes: 0 additions & 17 deletions sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,4 @@ data class Account(val value: Int) {
init {
require(value >= 0) { "Account index must be >= 0 but actually is $value" }
}

companion object {
val DEFAULT = Account(0)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as Account

return accountUuid.contentEquals(other.accountUuid)
}

override fun hashCode(): Int {
return accountUuid.contentHashCode()
}
}

0 comments on commit 2f4ac4c

Please sign in to comment.