From 4c7fa06992c5f6319b212818b4846b5fb56c2f43 Mon Sep 17 00:00:00 2001 From: Eric Tu Date: Mon, 16 Sep 2024 12:03:18 -0400 Subject: [PATCH] trying to get web wallet working still --- src/bindgen/wallet.rs | 18 +++++++++++++++++- src/wallet.rs | 2 +- tests/tests.rs | 19 +++++++++++++++---- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/bindgen/wallet.rs b/src/bindgen/wallet.rs index 916a58e..82f2bf4 100644 --- a/src/bindgen/wallet.rs +++ b/src/bindgen/wallet.rs @@ -7,7 +7,8 @@ use tonic_web_wasm_client::Client; use zcash_address::ZcashAddress; use zcash_client_memory::MemoryWalletDb; -use zcash_primitives::consensus::{self, BlockHeight}; +use zcash_keys::keys::UnifiedFullViewingKey; +use zcash_primitives::consensus::{self, BlockHeight, NetworkConstants, MAIN_NETWORK}; use crate::error::Error; use crate::{BlockRange, MemoryWallet, Wallet, PRUNING_DEPTH}; @@ -84,6 +85,21 @@ impl WebWallet { .await } + pub async fn import_ufvk( + &mut self, + key: &str, + birthday_height: Option, + ) -> Result { + let s = zcash_keys::encoding::decode_extended_full_viewing_key( + MAIN_NETWORK.hrp_sapling_extended_full_viewing_key(), + &key.trim(), + ) + .unwrap(); + let ufvk = UnifiedFullViewingKey::from_sapling_extended_full_viewing_key(s).unwrap(); + + self.inner.import_ufvk(ufvk, birthday_height).await + } + pub fn suggest_scan_ranges(&self) -> Result, Error> { self.inner.suggest_scan_ranges() } diff --git a/src/wallet.rs b/src/wallet.rs index 9a9714f..488c4b2 100644 --- a/src/wallet.rs +++ b/src/wallet.rs @@ -192,7 +192,7 @@ where let _account = self .db - .import_account_ufvk(&ufvk, &birthday, AccountPurpose::Spending)?; + .import_account_ufvk(&ufvk, &birthday, AccountPurpose::ViewOnly)?; Ok("0".to_string()) } diff --git a/tests/tests.rs b/tests/tests.rs index 327abe9..0fd21a5 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -3,7 +3,11 @@ wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser); use webz_core::{bindgen::wallet::WebWallet, Wallet}; use zcash_address::ZcashAddress; -use zcash_primitives::consensus::Network; +use zcash_keys::keys::UnifiedFullViewingKey; +use zcash_primitives::{ + consensus::{MainNetwork, Network}, + constants, +}; const SEED: &str = "visit armed kite pen cradle toward reward clay marble oil write dove blind oyster silk oyster original message skate bench tone enable stadium element"; const HD_INDEX: u32 = 0; @@ -17,6 +21,7 @@ pub fn initialize() { webz_core::init::start(); }); } +const key_str: &'static str = "zxviews1q0duytgcqqqqpqre26wkl45gvwwwd706xw608hucmvfalr759ejwf7qshjf5r9aa7323zulvz6plhttp5mltqcgs9t039cx2d09mgq05ts63n8u35hyv6h9nc9ctqqtue2u7cer2mqegunuulq2luhq3ywjcz35yyljewa4mgkgjzyfwh6fr6jd0dzd44ghk0nxdv2hnv4j5nxfwv24rwdmgllhe0p8568sgqt9ckt02v2kxf5ahtql6s0ltjpkckw8gtymxtxuu9gcr0swvz"; #[wasm_bindgen_test] async fn test_get_and_scan_range() { @@ -24,7 +29,15 @@ async fn test_get_and_scan_range() { let mut w = WebWallet::new("test", "https://zcash-testnet.chainsafe.dev", 1).unwrap(); - let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap(); + // let id = w.create_account(SEED, HD_INDEX, BIRTHDAY).await.unwrap(); + let s = zcash_keys::encoding::decode_extended_full_viewing_key( + constants::mainnet::HRP_SAPLING_EXTENDED_FULL_VIEWING_KEY, + &key_str.trim(), + ) + .unwrap(); + + let id = w.import_ufvk(&key_str, Some(2477329)).await.unwrap(); + tracing::info!("Created account with id: {}", id); tracing::info!("Syncing wallet"); @@ -126,8 +139,6 @@ async fn test_get_and_scan_range_native() { #[cfg(feature = "native")] #[tokio::test] async fn test_post_board() { - let key_str = "zxviews1q0duytgcqqqqpqre26wkl45gvwwwd706xw608hucmvfalr759ejwf7qshjf5r9aa7323zulvz6plhttp5mltqcgs9t039cx2d09mgq05ts63n8u35hyv6h9nc9ctqqtue2u7cer2mqegunuulq2luhq3ywjcz35yyljewa4mgkgjzyfwh6fr6jd0dzd44ghk0nxdv2hnv4j5nxfwv24rwdmgllhe0p8568sgqt9ckt02v2kxf5ahtql6s0ltjpkckw8gtymxtxuu9gcr0swvz"; - use zcash_keys::keys::UnifiedFullViewingKey; use zcash_primitives::{consensus, constants}; let db_cache = tempfile::tempdir().unwrap();