Skip to content
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

Switch from ZIP 32 account indices to UUID account identifiers #1640

Merged
merged 47 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
9b35832
Switch from ZIP 32 account indices to UUID account identifiers
str4d Nov 22, 2024
56a3858
Rename TransactionRecipient.Account
HonzaR Dec 3, 2024
c66b7ad
Fix `Backend.createAccount` API parameters
HonzaR Dec 4, 2024
5d07455
Add `importAccountUfvk` to the Rust backend.
nuttycom Dec 4, 2024
c8c1b2a
Propagate accountName and keySource across SDK
HonzaR Dec 4, 2024
5c3d1b5
Propagate new importAccount across SDK
HonzaR Dec 5, 2024
32e68e3
Wrap createAccount setup information
HonzaR Dec 5, 2024
cdfdbc9
Wrap importAccount setup information
HonzaR Dec 5, 2024
1cfba57
WIP: Add key derivation metadata to JniAccount
nuttycom Dec 6, 2024
7efea35
Fix JniAccount
HonzaR Dec 6, 2024
c1d2ff8
Use updated JniAccount across SDK
HonzaR Dec 6, 2024
ee27c0e
Several tests fix
HonzaR Dec 8, 2024
d87c5bd
Add `Zip32AccountIndex` wrapper
HonzaR Dec 9, 2024
d2b4d1f
Update key source parameter
HonzaR Dec 9, 2024
e4ffb26
Merge branch 'feature-2.2.7' into account-uuids
HonzaR Dec 9, 2024
02e1569
Remove account from `UnifiedSpendingKey`
HonzaR Dec 9, 2024
8823694
Fix `importAccountByUfvk` API
HonzaR Dec 9, 2024
922eb0e
Remove account_uuid from `JniUnifiedSpendingKey` creation
HonzaR Dec 9, 2024
7a95e23
Fixture fix
HonzaR Dec 9, 2024
89b06e4
Refactor Account.accountUuid to wrapper class
HonzaR Dec 9, 2024
d9482b1
Revert "Remove account_uuid from `JniUnifiedSpendingKey` creation"
HonzaR Dec 10, 2024
f669645
Add `JniAccountUsk`
HonzaR Dec 10, 2024
63a9a54
Add `seedFingerprint` and `zip32AccountIndex`
HonzaR Dec 10, 2024
fe653d4
Transactions by account UUID
HonzaR Dec 10, 2024
52f5b28
Refactor default account creation
HonzaR Dec 10, 2024
0909a73
Migrate to Rust crate revision with bugfix to account UUID migration
str4d Dec 10, 2024
477c933
Migrate to Rust crate revision with another bugfix to account UUID mi…
str4d Dec 10, 2024
d299b21
Test fix
HonzaR Dec 11, 2024
3c74069
Migrate to Rust crate revision with a third bugfix to account UUID mi…
str4d Dec 11, 2024
e54fb17
Self-review fixes
HonzaR Dec 11, 2024
51f5cd4
Tests fix
HonzaR Dec 11, 2024
c9bc790
Changelog update
HonzaR Dec 11, 2024
8b558f7
Update backend-lib/src/main/rust/lib.rs
HonzaR Dec 11, 2024
105da9d
Update backend-lib/src/main/rust/lib.rs
HonzaR Dec 11, 2024
0b603e2
Changelog update
HonzaR Dec 11, 2024
c68be81
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/Synchronizer.kt
HonzaR Dec 11, 2024
d07857c
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/Typesafe…
HonzaR Dec 11, 2024
0fae465
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/Typesafe…
HonzaR Dec 11, 2024
f78ed39
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/Typesafe…
HonzaR Dec 11, 2024
b59e768
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/Typesafe…
HonzaR Dec 11, 2024
e01773e
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/internal/Typesafe…
HonzaR Dec 11, 2024
840df94
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/AccountImpo…
HonzaR Dec 11, 2024
07f357e
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/AccountCrea…
HonzaR Dec 11, 2024
a03ae02
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/model/Account.kt
HonzaR Dec 11, 2024
cb8036d
Update sdk-lib/src/main/java/cash/z/ecc/android/sdk/SdkSynchronizer.kt
HonzaR Dec 11, 2024
e07d65d
Refactor inputs of `importAccountUfvk`
HonzaR Dec 11, 2024
7a064ec
Use `FirsClassByteArray` for `seed` parameter
HonzaR Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,30 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added
- `Synchronizer.getAccounts()`
- `Synchronizer.walletBalances: StateFlow<Map<Account, AccountBalance>?>` that is replacement for the removed
- `Synchronizer.importAccountByUfvk()` has been added
- `Synchronizer.getAccounts()` returning all the created or imported accounts. See the documentation in `Account`.
- `Synchronizer.walletBalances: StateFlow<Map<AccountUuid, AccountBalance>?>` that is replacement for the removed
`orchardBalances`, `saplingBalances`, and `transparentBalance`
- `getTransactions(accountUuid: AccountUuid)` to get transactions belonging to the given account
- `Zip32AccountIndex`, `AccountUuid`, `AccountUsk`, `AccountPurpose`, `AccountCreateSetup`, and `AcountImportSetup`
model classes have been added to support the new or the changed APIs

### Changed
- `Synchronizer.orchardBalances`, `Synchronizer.saplingBalances`, and `Synchronizer.transparentBalance` have been
replaced by `Synchronizer.walletBalances` that provides these balances based on `Account`
### Changed
- `Account` data class works with `accountUuid: AccountUuid` instead of the previous ZIP 32 account index
- These functions from `DerivationTool` have been refactored to work with the new `Zip32AccountIndex` instead of the
`Account` data class: `deriveUnifiedSpendingKey`, `deriveUnifiedAddress`, `deriveArbitraryAccountKey`
- `WalletCoordinator` now provides a way to instantiate `Synchronizer` with the new `accountName` and `keySource`
parameters
- `UnifiedSpendingKey` does not hold `Account` information anymore, it has been replaced by `AccountUsk` model class
in a few internal cases
- `Synchronizer.send` extension function receives `Account` on input
- `PendingTransaction` sealed class descendants have been renamed

### Removed
- `Synchronizer.sendToAddress` and `Synchronizer.shieldFunds` have been removed, use
`Synchronizer.createProposedTransactions` and `Synchronizer.proposeShielding` instead
- `Synchronizer.orchardBalances`, `Synchronizer.saplingBalances`, and `Synchronizer.transparentBalance`
(use `Synchronizer.walletBalances` instead).

### Fixed
- The `CompactBlockProcessor` now correctly distinguishes between `Response.Failure.Server.Unavailable` and other
Expand Down
38 changes: 16 additions & 22 deletions backend-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions backend-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ rayon = "1.7"
# JNI
anyhow = "1"
jni = { version = "0.21", default-features = false }
uuid = "1"

# Logging
log-panics = "2.0.0"
Expand Down Expand Up @@ -69,3 +70,10 @@ xz2 = { version = "0.1", features = ["static"] }
name = "zcashwalletsdk"
path = "src/main/rust/lib.rs"
crate-type = ["staticlib", "cdylib"]

[patch.crates-io]
zcash_address = { git = "https://github.com/zcash/librustzcash", rev = "c2ebc05be118a972352801a328e6c61f69bb8a16" }
zcash_client_backend = { git = "https://github.com/zcash/librustzcash", rev = "c2ebc05be118a972352801a328e6c61f69bb8a16" }
zcash_client_sqlite = { git = "https://github.com/zcash/librustzcash", rev = "c2ebc05be118a972352801a328e6c61f69bb8a16" }
zcash_primitives = { git = "https://github.com/zcash/librustzcash", rev = "c2ebc05be118a972352801a328e6c61f69bb8a16" }
zcash_proofs = { git = "https://github.com/zcash/librustzcash", rev = "c2ebc05be118a972352801a328e6c61f69bb8a16" }
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package cash.z.ecc.android.sdk.internal

import cash.z.ecc.android.sdk.internal.model.JniAccount
import cash.z.ecc.android.sdk.internal.model.JniAccountUsk
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
import cash.z.ecc.android.sdk.internal.model.JniRewindResult
import cash.z.ecc.android.sdk.internal.model.JniScanRange
import cash.z.ecc.android.sdk.internal.model.JniScanSummary
import cash.z.ecc.android.sdk.internal.model.JniSubtreeRoot
import cash.z.ecc.android.sdk.internal.model.JniTransactionDataRequest
import cash.z.ecc.android.sdk.internal.model.JniUnifiedSpendingKey
import cash.z.ecc.android.sdk.internal.model.JniWalletSummary
import cash.z.ecc.android.sdk.internal.model.ProposalUnsafe

Expand All @@ -24,7 +24,7 @@ interface Backend {
suspend fun initBlockMetaDb(): Int

suspend fun proposeTransfer(
accountIndex: Int,
accountUuid: ByteArray,
to: String,
value: Long,
memo: ByteArray? = null
Expand All @@ -35,12 +35,12 @@ interface Backend {
*/
@Throws(RuntimeException::class)
suspend fun proposeTransferFromUri(
accountIndex: Int,
accountUuid: ByteArray,
uri: String
): ProposalUnsafe

suspend fun proposeShielding(
accountIndex: Int,
accountUuid: ByteArray,
shieldingThreshold: Long,
memo: ByteArray? = null,
transparentReceiver: String? = null
Expand Down Expand Up @@ -85,10 +85,28 @@ interface Backend {
*/
@Throws(RuntimeException::class)
suspend fun createAccount(
accountName: String,
keySource: String?,
seed: ByteArray,
treeState: ByteArray,
recoverUntil: Long?
): JniUnifiedSpendingKey
recoverUntil: Long?,
): JniAccountUsk

/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
@Suppress("LongParameterList")
suspend fun importAccountUfvk(
accountName: String,
keySource: String?,
ufvk: String,
treeState: ByteArray,
recoverUntil: Long?,
purpose: Int,
seedFingerprint: ByteArray?,
zip32AccountIndex: Long?,
): JniAccount

/**
* @throws RuntimeException as a common indicator of the operation failure
Expand All @@ -109,13 +127,13 @@ interface Backend {
fun isValidTexAddr(addr: String): Boolean

@Throws(RuntimeException::class)
suspend fun getCurrentAddress(accountIndex: Int): String
suspend fun getCurrentAddress(accountUuid: ByteArray): String

fun getTransparentReceiver(ua: String): String?

fun getSaplingReceiver(ua: String): String?

suspend fun listTransparentReceivers(accountIndex: Int): List<String>
suspend fun listTransparentReceivers(accountUuid: ByteArray): List<String>

fun getBranchIdForHeight(height: Long): Long

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ interface Derivation {
fun deriveUnifiedAddress(
seed: ByteArray,
networkId: Int,
accountIndex: Int
accountIndex: Long
): String

fun deriveUnifiedSpendingKey(
seed: ByteArray,
networkId: Int,
accountIndex: Int
): JniUnifiedSpendingKey
accountIndex: Long
): ByteArray

/**
* @return a unified full viewing key.
Expand Down Expand Up @@ -66,7 +66,7 @@ interface Derivation {
contextString: ByteArray,
seed: ByteArray,
networkId: Int,
accountIndex: Int
accountIndex: Long
): ByteArray

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cash.z.ecc.android.sdk.internal.jni

import cash.z.ecc.android.sdk.internal.model.JniAccount

/**
* The number of bytes in the account UUID parameter. It's used e.g. in [JniAccount.accountUuid], or
* [JniUnifiedSpendingKey.accountUuid]
*/
const val JNI_ACCOUNT_UUID_BYTES_SIZE = 16

/**
* The number of bytes in the seed fingerprint parameter. It's used e.g. in [JniAccount.seedFingerprint]
*/
const val JNI_ACCOUNT_SEED_FP_BYTES_SIZE = 32
Loading
Loading