From 7806b5114f791ae304fc8b092dbdfd73580a0883 Mon Sep 17 00:00:00 2001 From: Francisco Gindre Date: Sun, 2 Oct 2022 19:11:17 -0700 Subject: [PATCH] Use UnifiedSpendingKey for shielding and Spending (#535) [#534] Use UnifiedSpendingKey for shielding and Spending This commit implements the use of Unified Spending Keys for shielding and spending as well as rolling Unified Addresses. Users should obtain addresses by rolling them from the SDK. USKs replace Sapling Extended Spending keys and TransparentAccountPrivKeys when shielding or spending Closes #534 Co-authored-by: Kris Nuttycombe * Fix rebase issues * PR Suggestion. Make `lastError` an Optional * Fix test `testReOrgRemovesOutboundTxAndIsNeverMined` Co-authored-by: Kris Nuttycombe --- .../project.pbxproj | 14 - .../xcshareddata/swiftpm/Package.resolved | 294 ++-- .../ZcashLightClientSample/AppDelegate.swift | 7 +- .../Base.lproj/Main.storyboard | 251 +--- .../DerivationToolViewController.swift | 184 --- .../GetAddressViewController.swift | 46 +- .../Get UTXOs/GetUTXOsViewController.swift | 15 +- .../Send/SendViewController.swift | 29 +- Package.resolved | 186 ++- Package.swift | 2 +- .../Block/Downloader/BlockDownloader.swift | 1 - .../Processor/CompactBlockEnhancement.swift | 8 +- .../Processor/CompactBlockProcessor.swift | 62 +- .../Processor/FetchUnspentTxOutputs.swift | 26 +- .../Entity/AccountEntity.swift | 39 +- Sources/ZcashLightClientKit/Initializer.swift | 44 +- .../Model/WalletTypes.swift | 11 +- .../Rust/ZcashRustBackend.swift | 1180 ++++++++--------- .../Rust/ZcashRustBackendWelding.swift | 773 ++++++----- .../ZcashLightClientKit/Synchronizer.swift | 25 +- .../Synchronizer/SDKSynchronizer.swift | 52 +- .../Tool/DerivationTool.swift | 316 +---- .../PersistentTransactionManager.swift | 6 +- .../Transaction/TransactionEncoder.swift | 11 +- .../Transaction/TransactionManager.swift | 4 +- .../WalletTransactionEncoder.swift | 18 +- Tests/DarksideTests/AdvancedReOrgTests.swift | 16 +- Tests/DarksideTests/BalanceTests.swift | 28 +- Tests/DarksideTests/NetworkUpgradeTests.swift | 20 +- .../PendingTransactionUpdatesTest.swift | 4 +- Tests/DarksideTests/RewindRescanTests.swift | 8 +- Tests/DarksideTests/ShieldFundsTests.swift | 14 +- .../TransactionEnhancementTests.swift | 20 +- Tests/DarksideTests/Z2TReceiveTests.swift | 4 +- Tests/NetworkTests/BlockScanTests.swift | 16 +- .../NetworkTests/ZcashRustBackendTests.swift | 155 ++- .../DerivationToolMainnetTests.swift | 99 +- .../DerivationToolTestnetTests.swift | 136 +- Tests/OfflineTests/NullBytesTests.swift | 56 +- Tests/OfflineTests/RecipientTests.swift | 2 +- .../OfflineTests/UnifiedTypecodesTests.swift | 287 +--- Tests/OfflineTests/WalletTests.swift | 5 +- Tests/TestUtils/Stubs.swift | 144 +- Tests/TestUtils/TestCoordinator.swift | 63 +- Tests/TestUtils/TestVector.swift | 240 ++++ changelog.md | 79 +- 46 files changed, 2242 insertions(+), 2758 deletions(-) delete mode 100644 Example/ZcashLightClientSample/ZcashLightClientSample/Derivation Tool/DerivationToolViewController.swift create mode 100644 Tests/TestUtils/TestVector.swift diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.pbxproj b/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.pbxproj index 7959044a..b73f2fd2 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.pbxproj +++ b/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 0D1BE4512581585C00F78BE3 /* DerivationToolViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D1BE4502581585C00F78BE3 /* DerivationToolViewController.swift */; }; 0D1BE47F2581937100F78BE3 /* GetUTXOsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D1BE47E2581937100F78BE3 /* GetUTXOsViewController.swift */; }; 0D49A18C241698A800CC0649 /* SampleLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D49A18B241698A800CC0649 /* SampleLogger.swift */; }; 0D4EBA312396CFD70041B507 /* SendViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D4EBA302396CFD70041B507 /* SendViewController.swift */; }; @@ -33,7 +32,6 @@ 0DA1C4C627D11D9500E5006E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D907F152322CC5900D641FE /* AppDelegate.swift */; }; 0DA1C4C727D11D9500E5006E /* SaplingParametersViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D6CE8BC252E3C4A0005D707 /* SaplingParametersViewController.swift */; }; 0DA1C4C827D11D9500E5006E /* GetUTXOsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D1BE47E2581937100F78BE3 /* GetUTXOsViewController.swift */; }; - 0DA1C4C927D11D9500E5006E /* DerivationToolViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D1BE4502581585C00F78BE3 /* DerivationToolViewController.swift */; }; 0DA1C4CB27D11D9500E5006E /* SampleLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0D49A18B241698A800CC0649 /* SampleLogger.swift */; }; 0DA1C4CC27D11D9500E5006E /* TransactionsDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DA58B952397F2CB004596EA /* TransactionsDataSource.swift */; }; 0DA1C4CD27D11D9500E5006E /* PaginatedTransactionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DF53E6623A438F100D7249C /* PaginatedTransactionsViewController.swift */; }; @@ -72,7 +70,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 0D1BE4502581585C00F78BE3 /* DerivationToolViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DerivationToolViewController.swift; sourceTree = ""; }; 0D1BE47E2581937100F78BE3 /* GetUTXOsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetUTXOsViewController.swift; sourceTree = ""; }; 0D49A18B241698A800CC0649 /* SampleLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleLogger.swift; sourceTree = ""; }; 0D4EBA302396CFD70041B507 /* SendViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendViewController.swift; sourceTree = ""; }; @@ -143,14 +140,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 0D1BE44F2581583D00F78BE3 /* Derivation Tool */ = { - isa = PBXGroup; - children = ( - 0D1BE4502581585C00F78BE3 /* DerivationToolViewController.swift */, - ); - path = "Derivation Tool"; - sourceTree = ""; - }; 0D1BE47D2581933C00F78BE3 /* Get UTXOs */ = { isa = PBXGroup; children = ( @@ -227,7 +216,6 @@ children = ( 0D76121426B1D5D7001CA417 /* Constants */, 0D1BE47D2581933C00F78BE3 /* Get UTXOs */, - 0D1BE44F2581583D00F78BE3 /* Derivation Tool */, 0D6CE8BB252E3C1A0005D707 /* Sapling Parameters */, 0DBF8F9323A80F0E0010B85F /* Transaction Detail */, 0DF53E6523A438BA00D7249C /* Paginated Transactions */, @@ -530,7 +518,6 @@ 0D907F162322CC5900D641FE /* AppDelegate.swift in Sources */, 0D6CE8BD252E3C4A0005D707 /* SaplingParametersViewController.swift in Sources */, 0D1BE47F2581937100F78BE3 /* GetUTXOsViewController.swift in Sources */, - 0D1BE4512581585C00F78BE3 /* DerivationToolViewController.swift in Sources */, 0D49A18C241698A800CC0649 /* SampleLogger.swift in Sources */, 0DA58B962397F2CB004596EA /* TransactionsDataSource.swift in Sources */, 0DF53E6723A438F100D7249C /* PaginatedTransactionsViewController.swift in Sources */, @@ -562,7 +549,6 @@ 0DA1C4C627D11D9500E5006E /* AppDelegate.swift in Sources */, 0DA1C4C727D11D9500E5006E /* SaplingParametersViewController.swift in Sources */, 0DA1C4C827D11D9500E5006E /* GetUTXOsViewController.swift in Sources */, - 0DA1C4C927D11D9500E5006E /* DerivationToolViewController.swift in Sources */, 0DA1C4CB27D11D9500E5006E /* SampleLogger.swift in Sources */, 0DA1C4CC27D11D9500E5006E /* TransactionsDataSource.swift in Sources */, 0DA1C4CD27D11D9500E5006E /* PaginatedTransactionsViewController.swift in Sources */, diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 666e892b..789aa67a 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Example/ZcashLightClientSample/ZcashLightClientSample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,151 +1,149 @@ { - "object": { - "pins": [ - { - "package": "grpc-swift", - "repositoryURL": "https://github.com/grpc/grpc-swift.git", - "state": { - "branch": null, - "revision": "466cc881f1760ed8c0e685900ed62dab7846a571", - "version": "1.8.0" - } - }, - { - "package": "KRActivityIndicatorView", - "repositoryURL": "https://github.com/krimpedance/KRActivityIndicatorView.git", - "state": { - "branch": null, - "revision": "bcb0e841d6de0cd343a32bd5056580a56d06c0bc", - "version": "3.0.7" - } - }, - { - "package": "KRProgressHUD", - "repositoryURL": "https://github.com/krimpedance/KRProgressHUD.git", - "state": { - "branch": null, - "revision": "265142816d8f8ea93840accaf4ac7c49998e77c2", - "version": "3.4.7" - } - }, - { - "package": "MnemonicSwift", - "repositoryURL": "https://github.com/zcash-hackworks/MnemonicSwift.git", - "state": { - "branch": null, - "revision": "716a2c32ac2bbd8a1499ac834077df42b75edc85", - "version": "2.2.4" - } - }, - { - "package": "NotificationBubbles", - "repositoryURL": "https://github.com/pacu/NotificationBubbles.git", - "state": { - "branch": null, - "revision": "ae6d47f3a415c9eec5daa8e04d040c0e68654f00", - "version": "1.0.0" - } - }, - { - "package": "PaginatedTableView", - "repositoryURL": "https://github.com/dh-ecc/PaginatedTableView", - "state": { - "branch": "master", - "revision": "a3fd9f079d6c9ac3095ee3ef2369a68c29ba04db", - "version": null - } - }, - { - "package": "SQLite.swift", - "repositoryURL": "https://github.com/stephencelis/SQLite.swift.git", - "state": { - "branch": null, - "revision": "60a65015f6402b7c34b9a924f755ca0a73afeeaa", - "version": "0.13.1" - } - }, - { - "package": "swift-crypto", - "repositoryURL": "https://github.com/apple/swift-crypto.git", - "state": { - "branch": null, - "revision": "d9825fa541df64b1a7b182178d61b9a82730d01f", - "version": "2.1.0" - } - }, - { - "package": "swift-log", - "repositoryURL": "https://github.com/apple/swift-log.git", - "state": { - "branch": null, - "revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7", - "version": "1.4.2" - } - }, - { - "package": "swift-nio", - "repositoryURL": "https://github.com/apple/swift-nio.git", - "state": { - "branch": null, - "revision": "51c3fc2e4a0fcdf4a25089b288dd65b73df1b0ef", - "version": "2.37.0" - } - }, - { - "package": "swift-nio-extras", - "repositoryURL": "https://github.com/apple/swift-nio-extras.git", - "state": { - "branch": null, - "revision": "f73ca5ee9c6806800243f1ac415fcf82de9a4c91", - "version": "1.10.2" - } - }, - { - "package": "swift-nio-http2", - "repositoryURL": "https://github.com/apple/swift-nio-http2.git", - "state": { - "branch": null, - "revision": "108ac15087ea9b79abb6f6742699cf31de0e8772", - "version": "1.22.0" - } - }, - { - "package": "swift-nio-ssl", - "repositoryURL": "https://github.com/apple/swift-nio-ssl.git", - "state": { - "branch": null, - "revision": "52a486ff6de9bc3e26bf634c5413c41c5fa89ca5", - "version": "2.17.2" - } - }, - { - "package": "swift-nio-transport-services", - "repositoryURL": "https://github.com/apple/swift-nio-transport-services.git", - "state": { - "branch": null, - "revision": "8ab824b140d0ebcd87e9149266ddc353e3705a3e", - "version": "1.11.4" - } - }, - { - "package": "SwiftProtobuf", - "repositoryURL": "https://github.com/apple/swift-protobuf.git", - "state": { - "branch": null, - "revision": "e1499bc69b9040b29184f7f2996f7bab467c1639", - "version": "1.19.0" - } - }, - { - "package": "libzcashlc", - "repositoryURL": "https://github.com/zcash-hackworks/zcash-light-client-ffi", - "state": { - "branch": "bin/librustzcash_0_7", - "revision": "823f864a7952073fb9718cf75610691756e34d59", - "version": null - } + "pins" : [ + { + "identity" : "grpc-swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/grpc/grpc-swift.git", + "state" : { + "revision" : "466cc881f1760ed8c0e685900ed62dab7846a571", + "version" : "1.8.0" } - ] - }, - "version": 1 + }, + { + "identity" : "kractivityindicatorview", + "kind" : "remoteSourceControl", + "location" : "https://github.com/krimpedance/KRActivityIndicatorView.git", + "state" : { + "revision" : "bcb0e841d6de0cd343a32bd5056580a56d06c0bc", + "version" : "3.0.7" + } + }, + { + "identity" : "krprogresshud", + "kind" : "remoteSourceControl", + "location" : "https://github.com/krimpedance/KRProgressHUD.git", + "state" : { + "revision" : "265142816d8f8ea93840accaf4ac7c49998e77c2", + "version" : "3.4.7" + } + }, + { + "identity" : "mnemonicswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/zcash-hackworks/MnemonicSwift.git", + "state" : { + "revision" : "716a2c32ac2bbd8a1499ac834077df42b75edc85", + "version" : "2.2.4" + } + }, + { + "identity" : "notificationbubbles", + "kind" : "remoteSourceControl", + "location" : "https://github.com/pacu/NotificationBubbles.git", + "state" : { + "revision" : "ae6d47f3a415c9eec5daa8e04d040c0e68654f00", + "version" : "1.0.0" + } + }, + { + "identity" : "paginatedtableview", + "kind" : "remoteSourceControl", + "location" : "https://github.com/dh-ecc/PaginatedTableView", + "state" : { + "branch" : "master", + "revision" : "a3fd9f079d6c9ac3095ee3ef2369a68c29ba04db" + } + }, + { + "identity" : "sqlite.swift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/stephencelis/SQLite.swift.git", + "state" : { + "revision" : "60a65015f6402b7c34b9a924f755ca0a73afeeaa", + "version" : "0.13.1" + } + }, + { + "identity" : "swift-crypto", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-crypto.git", + "state" : { + "revision" : "d9825fa541df64b1a7b182178d61b9a82730d01f", + "version" : "2.1.0" + } + }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "5d66f7ba25daf4f94100e7022febf3c75e37a6c7", + "version" : "1.4.2" + } + }, + { + "identity" : "swift-nio", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio.git", + "state" : { + "revision" : "51c3fc2e4a0fcdf4a25089b288dd65b73df1b0ef", + "version" : "2.37.0" + } + }, + { + "identity" : "swift-nio-extras", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-extras.git", + "state" : { + "revision" : "f73ca5ee9c6806800243f1ac415fcf82de9a4c91", + "version" : "1.10.2" + } + }, + { + "identity" : "swift-nio-http2", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-http2.git", + "state" : { + "revision" : "108ac15087ea9b79abb6f6742699cf31de0e8772", + "version" : "1.22.0" + } + }, + { + "identity" : "swift-nio-ssl", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-ssl.git", + "state" : { + "revision" : "52a486ff6de9bc3e26bf634c5413c41c5fa89ca5", + "version" : "2.17.2" + } + }, + { + "identity" : "swift-nio-transport-services", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-nio-transport-services.git", + "state" : { + "revision" : "8ab824b140d0ebcd87e9149266ddc353e3705a3e", + "version" : "1.11.4" + } + }, + { + "identity" : "swift-protobuf", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-protobuf.git", + "state" : { + "revision" : "e1499bc69b9040b29184f7f2996f7bab467c1639", + "version" : "1.19.0" + } + }, + { + "identity" : "zcash-light-client-ffi", + "kind" : "remoteSourceControl", + "location" : "https://github.com/zcash-hackworks/zcash-light-client-ffi", + "state" : { + "branch" : "bin/librustzcash_0_7", + "revision" : "14d5b977a076775447a0630387596c21cacbd09a" + } + } + ], + "version" : 2 } diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample/AppDelegate.swift b/Example/ZcashLightClientSample/ZcashLightClientSample/AppDelegate.swift index 1ff3a5ae..470eca31 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample/AppDelegate.swift +++ b/Example/ZcashLightClientSample/ZcashLightClientSample/AppDelegate.swift @@ -33,8 +33,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { if let wallet = wallet { return wallet } else { - let unifiedFullViewingKeys = try! DerivationTool(networkType: kZcashNetwork.networkType) - .deriveUnifiedFullViewingKeysFromSeed(DemoAppConfig.seed, numberOfAccounts: 1) + let ufvk = try! DerivationTool(networkType: kZcashNetwork.networkType) + .deriveUnifiedSpendingKey(seed: DemoAppConfig.seed, accountIndex: 0) + .deriveFullViewingKey() let wallet = Initializer( cacheDbURL: try! cacheDbURLHelper(), @@ -44,7 +45,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { network: kZcashNetwork, spendParamsURL: try! spendParamsURLHelper(), outputParamsURL: try! outputParamsURLHelper(), - viewingKeys: unifiedFullViewingKeys, + viewingKeys: [ufvk], walletBirthday: DemoAppConfig.birthdayHeight, loggerProxy: loggerProxy ) diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard b/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard index cecb96ea..34776d29 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard +++ b/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard @@ -1,7 +1,9 @@ - + + - + + @@ -12,7 +14,7 @@ - + @@ -274,19 +276,16 @@ - - - - + - +