From 65aa7d84743bb8d17f9d9b6f2407f59c87a9dfa2 Mon Sep 17 00:00:00 2001 From: Francisco Gindre Date: Fri, 2 Apr 2021 19:18:16 -0300 Subject: [PATCH] [wip] autoshield poc with uvks --- Cargo.lock | 24 +-- Cargo.toml | 4 +- .../DerivationToolTests.swift | 20 +- Example/ZcashLightClientSample/Podfile | 4 +- Example/ZcashLightClientSample/Podfile.lock | 8 +- .../ZcashLightClientSample/AppDelegate.swift | 4 +- .../Base.lproj/Main.storyboard | 113 +++++------- .../DemoAppConfig.swift | 1 - .../Get UTXOs/GetUTXOsViewController.swift | 81 +------- ZcashLightClientKit.podspec | 11 ++ .../DatabaseMigrationManager.swift | 7 +- .../DatabaseStorage/StorageManager.swift | 10 +- .../Block/Downloader/BlockDownloader.swift | 2 +- .../Processor/CompactBlockProcessor.swift | 4 +- .../Entity/AccountEntity.swift | 2 - .../Extensions/ZcashSDK+extensions.swift | 2 +- ZcashLightClientKit/Initializer.swift | 15 +- .../Rust/ZcashRustBackend.swift | 89 +++++++-- .../Rust/ZcashRustBackendWelding.swift | 25 ++- .../Service/LightWalletGRPCService.swift | 13 +- ZcashLightClientKit/Synchronizer.swift | 7 +- ZcashLightClientKit/Tool/DerivationTool.swift | 47 +++-- .../WalletTransactionEncoder.swift | 5 - .../UIKit/Synchronizer/SDKSynchronizer.swift | 11 +- ZcashLightClientKit/zcashlc/zcashlc.h | 26 ++- .../NetworkUpgradeTests.swift | 11 +- .../TestCoordinator.swift | 28 ++- ZcashLightClientKitTests/WalletTests.swift | 34 ++-- .../WalletTransactionEncoderTests.swift | 4 +- .../ZcashRustBackendTests.swift | 19 -- .../utils/DarkSideWalletService.swift | 16 ++ .../utils/FakeService.swift | 16 ++ ZcashLightClientKitTests/utils/Stubs.swift | 51 ++++- rust/src/lib.rs | 174 +++++++++++++++--- 34 files changed, 561 insertions(+), 327 deletions(-) rename {ZcashLightClientKitTests => DerivationToolTests}/DerivationToolTests.swift (80%) diff --git a/Cargo.lock b/Cargo.lock index bf9cef2d..85fd29a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -437,7 +437,7 @@ checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" [[package]] name = "equihash" version = "0.1.0" -source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#111161b47ee788867989c3c52627034659799be8" +source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#3dcdc51b369d9470d69baecdd5e992f45a57cbcd" dependencies = [ "blake2b_simd", "byteorder", @@ -693,9 +693,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.91" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8916b1f6ca17130ec6568feccee27c156ad12037880833a3b842a823236502e7" +checksum = "56d855069fafbb9b344c0f962150cd2c1187975cb1c22c1522c240d8c4986714" [[package]] name = "libsqlite3-sys" @@ -859,9 +859,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" dependencies = [ "unicode-xid", ] @@ -1288,9 +1288,9 @@ checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6498a9efc342871f91cc2d0d694c674368b4ceb40f62b65a7a08c3792935e702" +checksum = "3ce15dd3ed8aa2f8eeac4716d6ef5ab58b6b9256db41d7e1a0224c2788e8fd87" dependencies = [ "proc-macro2", "quote", @@ -1540,7 +1540,7 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] name = "zcash_client_backend" version = "0.5.0" -source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#111161b47ee788867989c3c52627034659799be8" +source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#3dcdc51b369d9470d69baecdd5e992f45a57cbcd" dependencies = [ "base64", "bech32", @@ -1551,6 +1551,7 @@ dependencies = [ "hdwallet", "hex", "jubjub", + "log", "nom", "percent-encoding", "protobuf", @@ -1567,7 +1568,7 @@ dependencies = [ [[package]] name = "zcash_client_sqlite" version = "0.3.0" -source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#111161b47ee788867989c3c52627034659799be8" +source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#3dcdc51b369d9470d69baecdd5e992f45a57cbcd" dependencies = [ "bech32", "bs58 0.4.0", @@ -1577,6 +1578,7 @@ dependencies = [ "protobuf", "rand_core 0.5.1", "rusqlite", + "secp256k1", "time", "zcash_client_backend", "zcash_primitives", @@ -1585,7 +1587,7 @@ dependencies = [ [[package]] name = "zcash_primitives" version = "0.5.0" -source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#111161b47ee788867989c3c52627034659799be8" +source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#3dcdc51b369d9470d69baecdd5e992f45a57cbcd" dependencies = [ "aes", "bitvec 0.18.5", @@ -1614,7 +1616,7 @@ dependencies = [ [[package]] name = "zcash_proofs" version = "0.5.0" -source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#111161b47ee788867989c3c52627034659799be8" +source = "git+https://github.com/nuttycom/librustzcash?branch=autoshield-poc-daa#3dcdc51b369d9470d69baecdd5e992f45a57cbcd" dependencies = [ "bellman", "blake2b_simd", diff --git a/Cargo.toml b/Cargo.toml index fc8305ed..818f790a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,5 +57,5 @@ zcash_proofs = {git = "https://github.com/nuttycom/librustzcash", branch = "auto [features] -mainnet = ["zcash_client_sqlite/mainnet", "zcash_client_sqlite/transparent-inputs", "zcash_client_backend/transparent-inputs", "zcash_primitives/transparent-inputs"] -testnet = ["zcash_client_sqlite/transparent-inputs", "zcash_client_backend/transparent-inputs", "zcash_primitives/transparent-inputs"] \ No newline at end of file +mainnet = ["zcash_client_sqlite/mainnet", "zcash_client_backend/transparent-inputs", "zcash_primitives/transparent-inputs"] +testnet = ["zcash_client_backend/transparent-inputs", "zcash_primitives/transparent-inputs"] \ No newline at end of file diff --git a/ZcashLightClientKitTests/DerivationToolTests.swift b/DerivationToolTests/DerivationToolTests.swift similarity index 80% rename from ZcashLightClientKitTests/DerivationToolTests.swift rename to DerivationToolTests/DerivationToolTests.swift index 1f2497c3..387c2a77 100644 --- a/ZcashLightClientKitTests/DerivationToolTests.swift +++ b/DerivationToolTests/DerivationToolTests.swift @@ -74,7 +74,25 @@ class DerivationToolTests: XCTestCase { } func testDeriveSecretKeyFromSeed() throws { - XCTAssertEqual(try DerivationTool.default.deriveTransparentPrivateKey(seed: [UInt8](seedData)), "127ec31a3482e53940aaefbc41c9621a344c84e4e16cc2c9af380d81b8f7bb74") + XCTAssertEqual(try DerivationTool.default.deriveTransparentPrivateKey(seed: [UInt8](seedData)), "KwqfQoTCuQdCLvzpAEtkt1o8J62WJuZXD3cGRAf1bgmPWuLamHLo") + } + + func testDeriveUnifiedKeysFromSeed() throws { + let unifiedKeys = try DerivationTool.default.deriveUnifiedViewingKeysFromSeed([UInt8](seedData), numberOfAccounts: 1) + XCTAssertEqual(unifiedKeys.count, 1) + + XCTAssertEqual(unifiedKeys[0].extfxk, expectedViewingKey) + + XCTAssertEqual(expectedTransparentAddress, try DerivationTool.default.deriveTransparentAddressFromPublicKey(unifiedKeys[0].extpub)) + } + + func testDeriveQuiteALotOfUnifiedKeysFromSeed() throws { + let unifiedKeys = try DerivationTool.default.deriveUnifiedViewingKeysFromSeed([UInt8](seedData), numberOfAccounts: 10) + XCTAssertEqual(unifiedKeys.count, 10) + + XCTAssertEqual(unifiedKeys[0].extfxk, expectedViewingKey) + + XCTAssertEqual(expectedTransparentAddress, try DerivationTool.default.deriveTransparentAddressFromPublicKey(unifiedKeys[0].extpub)) } } diff --git a/Example/ZcashLightClientSample/Podfile b/Example/ZcashLightClientSample/Podfile index 25c04531..29c521f5 100644 --- a/Example/ZcashLightClientSample/Podfile +++ b/Example/ZcashLightClientSample/Podfile @@ -5,12 +5,12 @@ target 'ZcashLightClientSample' do use_frameworks! pod "KRProgressHUD" # Pods for ZcashLightClientSample - pod 'ZcashLightClientKit', :path => '../../', :testspecs => ['Tests'] + pod 'ZcashLightClientKit', :path => '../../', :testspecs => ['Tests', 'DerivationToolTests'] pod 'gRPC-Swift', '= 1.0.0-alpha.19' pod 'PaginatedTableView' pod 'NotificationBubbles' pod 'MnemonicSwift', '~> 2.0.0' - pod 'gRPC-Swift-Plugins', '= 1.0.0-alpha.19' + pod 'gRPC-Swift-Plugins', '= 1.0.0-alpha.19' target 'ZcashLightClientSampleTests' do use_frameworks! inherit! :search_paths diff --git a/Example/ZcashLightClientSample/Podfile.lock b/Example/ZcashLightClientSample/Podfile.lock index ea62bd72..12759658 100644 --- a/Example/ZcashLightClientSample/Podfile.lock +++ b/Example/ZcashLightClientSample/Podfile.lock @@ -69,6 +69,9 @@ PODS: - ZcashLightClientKit (0.10.0): - gRPC-Swift (= 1.0.0-alpha.19) - SQLite.swift (~> 0.12.2) + - ZcashLightClientKit/DerivationToolTests (0.10.0): + - gRPC-Swift (= 1.0.0-alpha.19) + - SQLite.swift (~> 0.12.2) - ZcashLightClientKit/Tests (0.10.0): - gRPC-Swift (= 1.0.0-alpha.19) - SQLite.swift (~> 0.12.2) @@ -81,6 +84,7 @@ DEPENDENCIES: - NotificationBubbles - PaginatedTableView - ZcashLightClientKit (from `../../`) + - ZcashLightClientKit/DerivationToolTests (from `../../`) - ZcashLightClientKit/Tests (from `../../`) SPEC REPOS: @@ -145,8 +149,8 @@ SPEC CHECKSUMS: SwiftNIOTLS: 46bb3a0ff37d6b52ae6baf5207ec3cd411da327c SwiftNIOTransportServices: 801923921fbecdcde1e1c1ff38e812167d01ead1 SwiftProtobuf: 4ef85479c18ca85b5482b343df9c319c62bda699 - ZcashLightClientKit: a1a36be74ca95e2802ba3d6bcc40e9b2753eb0da + ZcashLightClientKit: 2489ea17976192891b4c509e355194f1fea9d8f4 -PODFILE CHECKSUM: db5fd49340d00419df0653aac7d56eaeb37d71b6 +PODFILE CHECKSUM: 459c257dc96354d8f60d386deee2f61d3dff05e6 COCOAPODS: 1.10.1 diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample/AppDelegate.swift b/Example/ZcashLightClientSample/ZcashLightClientSample/AppDelegate.swift index 493702a3..bc84b807 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample/AppDelegate.swift +++ b/Example/ZcashLightClientSample/ZcashLightClientSample/AppDelegate.swift @@ -40,9 +40,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { spendParamsURL: try! __spendParamsURL(), outputParamsURL: try! __outputParamsURL(), loggerProxy: loggerProxy) - try! wallet.initialize(viewingKeys: try DerivationTool.default.deriveViewingKeys(seed: DemoAppConfig.seed, numberOfAccounts: 1), - walletBirthday: BlockHeight(DemoAppConfig.birthdayHeight)) // Init or DIE + let unifiedViewingKeys = try! DerivationTool.default.deriveUnifiedViewingKeysFromSeed(DemoAppConfig.seed, accounts: 1) + try! wallet.initialize(unifiedViewingKeys: unifiedViewingKeys, walletBirthday: DemoAppConfig.birthdayHeight) var storage = SampleStorage.shared storage!.seed = Data(DemoAppConfig.seed) storage!.privateKey = try! DerivationTool.default.deriveSpendingKeys(seed: DemoAppConfig.seed, numberOfAccounts: 1)[0] diff --git a/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard b/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard index 6f520899..bfbf8c5b 100644 --- a/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard +++ b/Example/ZcashLightClientSample/ZcashLightClientSample/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -21,7 +21,7 @@ - + @@ -41,7 +41,7 @@ - + @@ -61,7 +61,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -101,7 +101,7 @@ - + @@ -121,7 +121,7 @@ - + @@ -141,7 +141,7 @@ - + @@ -161,7 +161,7 @@ - + @@ -181,7 +181,7 @@ - + @@ -201,7 +201,7 @@ - + @@ -221,7 +221,7 @@ - + @@ -241,7 +241,7 @@ - + @@ -261,7 +261,7 @@ - + @@ -281,7 +281,7 @@ - + @@ -333,7 +333,7 @@ - + @@ -392,7 +392,7 @@ - + @@ -442,7 +442,7 @@ - + @@ -466,7 +466,7 @@ - + @@ -490,7 +490,7 @@ - + @@ -514,7 +514,7 @@ - + @@ -538,7 +538,7 @@ - + @@ -562,7 +562,7 @@ - + @@ -1396,50 +1396,29 @@ - - - - - - - - - - - + + - + - -