diff --git a/rust/apps/wallets/Cargo.lock b/rust/apps/wallets/Cargo.lock index 5928ae1a3..ee570d46b 100644 --- a/rust/apps/wallets/Cargo.lock +++ b/rust/apps/wallets/Cargo.lock @@ -8,6 +8,17 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + [[package]] name = "ahash" version = "0.8.3" @@ -116,6 +127,20 @@ version = "0.10.0-beta" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98f7eed2b2781a6f0b5c903471d48e15f56fb4e1165df8a9a2337fd1a59d45ea" +[[package]] +name = "bip32" +version = "0.5.2" +dependencies = [ + "bs58 0.5.1", + "hmac", + "rand_core", + "ripemd", + "secp256k1 0.29.1", + "sha2 0.10.7", + "subtle", + "zeroize", +] + [[package]] name = "bitcoin" version = "0.31.1" @@ -128,7 +153,7 @@ dependencies = [ "core2", "hex-conservative", "hex_lit", - "secp256k1", + "secp256k1 0.28.2", ] [[package]] @@ -169,6 +194,18 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "blake2" version = "0.10.6" @@ -178,6 +215,17 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "blake2b_simd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + [[package]] name = "block-buffer" version = "0.9.0" @@ -196,6 +244,17 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bls12_381" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + [[package]] name = "bs58" version = "0.4.0" @@ -205,6 +264,16 @@ dependencies = [ "sha2 0.9.9", ] +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "sha2 0.10.7", + "tinyvec", +] + [[package]] name = "byteorder" version = "1.4.3" @@ -217,6 +286,15 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +[[package]] +name = "cbc" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b52a9543ae338f279b96b0b9fed9c8093744685043739079ce85cd58f289a6" +dependencies = [ + "cipher", +] + [[package]] name = "cc" version = "1.0.79" @@ -229,12 +307,28 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + [[package]] name = "const-oid" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" +[[package]] +name = "constant_time_eq" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" + [[package]] name = "core2" version = "0.3.3" @@ -377,6 +471,15 @@ dependencies = [ "libc", ] +[[package]] +name = "f4jumble" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a83e8d7fd0c526af4aad893b7c9fe41e2699ed8a776a6c74aecdeafe05afc75" +dependencies = [ + "blake2b_simd", +] + [[package]] name = "fastrand" version = "1.9.0" @@ -386,12 +489,43 @@ dependencies = [ "instant", ] +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "bitvec", + "rand_core", + "subtle", +] + [[package]] name = "fixedbitset" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" +[[package]] +name = "fpe" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26c4b37de5ae15812a764c958297cfc50f5c010438f60c6ce75d11b802abd404" +dependencies = [ + "cbc", + "cipher", + "libm", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "generic-array" version = "0.14.7" @@ -402,6 +536,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -450,6 +595,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "indexmap" version = "1.9.3" @@ -460,6 +614,15 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "inout" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" +dependencies = [ + "generic-array", +] + [[package]] name = "instant" version = "0.1.12" @@ -495,17 +658,45 @@ version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +[[package]] +name = "jubjub" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8499f7a74008aafbecb2a2e608a3e13e4dd3e84df198b604451efe93f2de6e61" +dependencies = [ + "bitvec", + "bls12_381", + "ff", + "group", + "rand_core", + "subtle", +] + [[package]] name = "keystore" version = "0.1.0" dependencies = [ + "aes", "arrayref", + "bip32", + "blake2b_simd", + "bs58 0.5.1", + "byteorder", "cstr_core", "cty", + "f4jumble", + "ff", + "fpe", + "group", "num-bigint-dig", + "pasta_curves", "rand_chacha", + "reddsa", + "ripemd", "rust_tools", + "secp256k1 0.29.1", "sha2 0.10.7", + "subtle", "third_party", ] @@ -598,6 +789,16 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + [[package]] name = "num-bigint-dig" version = "0.8.2" @@ -617,11 +818,10 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] @@ -638,9 +838,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm", @@ -667,6 +867,20 @@ dependencies = [ "num-traits", ] +[[package]] +name = "pasta_curves" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e57598f73cc7e1b2ac63c79c517b31a0877cd7c402cdcaa311b5208de7a095" +dependencies = [ + "blake2b_simd", + "ff", + "group", + "rand", + "static_assertions", + "subtle", +] + [[package]] name = "paste" version = "1.0.12" @@ -848,6 +1062,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "rand" version = "0.8.5" @@ -883,6 +1103,21 @@ dependencies = [ "rand_core", ] +[[package]] +name = "reddsa" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78a5191930e84973293aa5f532b513404460cd2216c1cfb76d08748c15b40b02" +dependencies = [ + "blake2b_simd", + "byteorder", + "group", + "hex", + "jubjub", + "pasta_curves", + "rand_core", +] + [[package]] name = "redox_syscall" version = "0.3.5" @@ -913,6 +1148,15 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + [[package]] name = "rippled_binary_codec" version = "0.0.6" @@ -1012,8 +1256,17 @@ version = "0.28.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" dependencies = [ - "bitcoin_hashes 0.12.0", - "secp256k1-sys", + "bitcoin_hashes 0.13.0", + "secp256k1-sys 0.9.2", +] + +[[package]] +name = "secp256k1" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9465315bc9d4566e1724f0fffcbcc446268cb522e60f9a27bcded6b19c108113" +dependencies = [ + "secp256k1-sys 0.10.1", ] [[package]] @@ -1025,6 +1278,15 @@ dependencies = [ "cc", ] +[[package]] +name = "secp256k1-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4387882333d3aa8cb20530a17c69a3752e97837832f34f6dccc760e715001d9" +dependencies = [ + "cc", +] + [[package]] name = "serde" version = "1.0.160" @@ -1138,11 +1400,17 @@ dependencies = [ "der", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -1166,6 +1434,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" version = "3.5.0" @@ -1247,6 +1521,21 @@ dependencies = [ "syn 2.0.23", ] +[[package]] +name = "tinyvec" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "typenum" version = "1.16.0" @@ -1280,7 +1569,7 @@ dependencies = [ [[package]] name = "ur-parse-lib" version = "0.2.0" -source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.32#8a21ca56a1beb2cb665c9549bfcc014849b457df" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.33-alpha1#42c7afd389cdc8d2c47a77afaaabb89e196a0192" dependencies = [ "hex", "ur", @@ -1290,9 +1579,9 @@ dependencies = [ [[package]] name = "ur-registry" version = "0.1.0" -source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.32#8a21ca56a1beb2cb665c9549bfcc014849b457df" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.33-alpha1#42c7afd389cdc8d2c47a77afaaabb89e196a0192" dependencies = [ - "bs58", + "bs58 0.4.0", "core2", "hex", "libflate", @@ -1455,6 +1744,15 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + [[package]] name = "zeroize" version = "1.6.0" diff --git a/rust/apps/wallets/rust-toolchain b/rust/apps/wallets/rust-toolchain index b0e494995..07ade694b 100644 --- a/rust/apps/wallets/rust-toolchain +++ b/rust/apps/wallets/rust-toolchain @@ -1 +1 @@ -nightly-2023-06-26 \ No newline at end of file +nightly \ No newline at end of file diff --git a/rust/apps/wallets/src/lib.rs b/rust/apps/wallets/src/lib.rs index 7077952dd..6ee097e4e 100644 --- a/rust/apps/wallets/src/lib.rs +++ b/rust/apps/wallets/src/lib.rs @@ -26,6 +26,7 @@ pub mod solana; pub mod sui; pub mod thor_wallet; pub mod tonkeeper; +pub mod zcash; mod utils; pub mod xbull; pub mod xrp_toolkit; diff --git a/rust/apps/wallets/src/zcash.rs b/rust/apps/wallets/src/zcash.rs new file mode 100644 index 000000000..5d308dde1 --- /dev/null +++ b/rust/apps/wallets/src/zcash.rs @@ -0,0 +1,72 @@ +use alloc::string::{String, ToString}; +use alloc::vec; +use alloc::vec::Vec; + +use app_utils::impl_public_struct; +use keystore::algorithms::zcash::vendor::{ + zcash_keys::keys::UnifiedFullViewingKey, zcash_protocol::consensus::MainNetwork, +}; +use third_party::ur_registry::{ + crypto_hd_key::CryptoHDKey, + crypto_key_path::CryptoKeyPath, + error::{URError, URResult}, + zcash::{ + zcash_accounts::ZcashAccounts, zcash_full_viewing_key::ZcashFullViewingKey, + zcash_unified_full_viewing_key::ZcashUnifiedFullViewingKey, + }, +}; + +impl_public_struct!(UFVKInfo { + key_text: String, + key_name: String, + transparent_key_path: String, + orchard_key_path: String +}); + +pub fn generate_sync_ur(key_infos: Vec, mfp: [u8; 4]) -> URResult { + let keys = key_infos + .iter() + .map(|info| { + let ufvk = UnifiedFullViewingKey::decode(&MainNetwork, &info.key_text) + .map_err(|e| URError::UrEncodeError(e.to_string()))?; + + let transprant = ufvk.transparent().and_then(|v| Some(v.serialize())); + let orchard = ufvk + .orchard() + .and_then(|v| Some(v.to_bytes())) + .ok_or(URError::UrEncodeError(format!("Zcash missing orchard fvk")))?; + + let transparent_key = transprant + .map(|v| { + let (chaincode, pubkey) = v.split_at(32); + let keypath = CryptoKeyPath::from_path(info.transparent_key_path.clone(), None) + .map_err(|e| URError::UrEncodeError(e))?; + Ok(CryptoHDKey::new_extended_key( + None, + pubkey.to_vec(), + Some(chaincode.to_vec()), + None, + Some(keypath), + None, + None, + None, + None, + )) + }) + .transpose()?; + + let keypath = CryptoKeyPath::from_path(info.orchard_key_path.clone(), None) + .map_err(|e| URError::UrEncodeError(e))?; + + let orchard_key = ZcashFullViewingKey::new(keypath, orchard.to_vec()); + + Ok(ZcashUnifiedFullViewingKey::new( + transparent_key, + orchard_key, + Some(info.key_name.clone()), + )) + }) + .collect::>>()?; + let accounts = ZcashAccounts::new(mfp, keys); + Ok(accounts) +} diff --git a/rust/docs/README.md b/rust/docs/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/rust/keystore/Cargo.lock b/rust/keystore/Cargo.lock index 85f7f891e..d05940adf 100644 --- a/rust/keystore/Cargo.lock +++ b/rust/keystore/Cargo.lock @@ -1366,7 +1366,7 @@ dependencies = [ "thiserror-core", "unicode-blocks", "ur-parse-lib", - "ur-registry", + "ur-registry 0.1.0 (git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.33-alpha0)", ] [[package]] @@ -1441,7 +1441,7 @@ source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.32 dependencies = [ "hex", "ur", - "ur-registry", + "ur-registry 0.1.0 (git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.32)", ] [[package]] @@ -1463,6 +1463,25 @@ dependencies = [ "ur", ] +[[package]] +name = "ur-registry" +version = "0.1.0" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.33-alpha0#4db1ee793ccd796e2cb8ba96212785aeadd84e18" +dependencies = [ + "bs58 0.4.0", + "core2", + "hex", + "libflate", + "minicbor", + "paste", + "prost", + "prost-build", + "prost-types", + "serde", + "thiserror-core", + "ur", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/rust/rust_c/Cargo.lock b/rust/rust_c/Cargo.lock index 5ba9e59fd..07dc62201 100644 --- a/rust/rust_c/Cargo.lock +++ b/rust/rust_c/Cargo.lock @@ -3278,7 +3278,7 @@ dependencies = [ [[package]] name = "ur-parse-lib" version = "0.2.0" -source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.32#8a21ca56a1beb2cb665c9549bfcc014849b457df" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.33-alpha1#42c7afd389cdc8d2c47a77afaaabb89e196a0192" dependencies = [ "hex", "ur", @@ -3288,7 +3288,7 @@ dependencies = [ [[package]] name = "ur-registry" version = "0.1.0" -source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.32#8a21ca56a1beb2cb665c9549bfcc014849b457df" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.33-alpha1#42c7afd389cdc8d2c47a77afaaabb89e196a0192" dependencies = [ "bs58 0.4.0", "core2", diff --git a/rust/rust_c/src/common/src/structs.rs b/rust/rust_c/src/common/src/structs.rs index 6f9ec9a25..720d6d560 100644 --- a/rust/rust_c/src/common/src/structs.rs +++ b/rust/rust_c/src/common/src/structs.rs @@ -190,3 +190,31 @@ impl Free for PtrT { } } } + +#[repr(C)] +pub struct ZcashKey { + pub key_text: PtrString, + pub key_name: PtrString, + pub transparent_key_path: PtrString, + pub orchard_key_path: PtrString, +} + +impl_c_ptr!(ZcashKey); + +impl Free for ZcashKey { + fn free(&self) { + free_str_ptr!(self.key_text); + free_str_ptr!(self.key_name); + free_str_ptr!(self.transparent_key_path); + free_str_ptr!(self.orchard_key_path); + } +} + +impl Free for PtrT { + fn free(&self) { + unsafe { + let x = Box::from_raw(*self); + x.free() + } + } +} diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs b/rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs index 9bdbc3eda..69cd46cfd 100644 --- a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs +++ b/rust/rust_c/src/wallet/src/multi_coins_wallet/src/lib.rs @@ -16,6 +16,7 @@ pub mod tonkeeper; mod utils; pub mod xbull; pub mod xrp_toolkit; +pub mod zcash; pub mod thor_wallet; diff --git a/rust/rust_c/src/wallet/src/multi_coins_wallet/src/zcash.rs b/rust/rust_c/src/wallet/src/multi_coins_wallet/src/zcash.rs new file mode 100644 index 000000000..56586e774 --- /dev/null +++ b/rust/rust_c/src/wallet/src/multi_coins_wallet/src/zcash.rs @@ -0,0 +1,61 @@ +use alloc::string::ToString; +use alloc::vec::Vec; +use alloc::{format, slice}; +use app_wallets::zcash::{generate_sync_ur, UFVKInfo}; +use common_rust_c::extract_array; +use common_rust_c::ffi::CSliceFFI; +use common_rust_c::structs::ZcashKey; +use common_rust_c::types::{Ptr, PtrBytes, PtrString}; +use common_rust_c::ur::{UREncodeResult, FRAGMENT_MAX_LENGTH_DEFAULT}; +use common_rust_c::utils::{recover_c_array, recover_c_char}; +use third_party::ur_registry::bytes::Bytes; +use third_party::ur_registry::error::URError; +use third_party::ur_registry::traits::RegistryItem; +use third_party::ur_registry::zcash::zcash_accounts::ZcashAccounts; + +#[no_mangle] +pub extern "C" fn get_connect_zcash_wallet_ur( + mfp: PtrBytes, + mfp_len: u32, + zcash_keys: Ptr>, +) -> *mut UREncodeResult { + if mfp_len != 4 { + return UREncodeResult::from(URError::UrEncodeError(format!( + "master fingerprint length must be 4, current is {}", + mfp_len + ))) + .c_ptr(); + } + let mfp = extract_array!(mfp, u8, mfp_len); + let mfp = match <[u8; 4]>::try_from(mfp) { + Ok(mfp) => mfp, + Err(e) => return UREncodeResult::from(URError::UrEncodeError(e.to_string())).c_ptr(), + }; + unsafe { + let keys = recover_c_array(zcash_keys); + let ufvks: Vec = keys + .iter() + .map(|v| { + UFVKInfo::new( + recover_c_char(v.key_text), + recover_c_char(v.key_name), + recover_c_char(v.transparent_key_path), + recover_c_char(v.orchard_key_path), + ) + }) + .collect(); + let result = generate_sync_ur(ufvks, mfp); + match result.map(|v| v.try_into()) { + Ok(v) => match v { + Ok(data) => UREncodeResult::encode( + data, + ZcashAccounts::get_registry_type().get_type(), + FRAGMENT_MAX_LENGTH_DEFAULT, + ) + .c_ptr(), + Err(e) => UREncodeResult::from(e).c_ptr(), + }, + Err(e) => UREncodeResult::from(e).c_ptr(), + } + } +} diff --git a/rust/third_party/Cargo.lock b/rust/third_party/Cargo.lock index 27fdd8857..0ddcbeba1 100644 --- a/rust/third_party/Cargo.lock +++ b/rust/third_party/Cargo.lock @@ -1094,7 +1094,7 @@ dependencies = [ [[package]] name = "ur-parse-lib" version = "0.2.0" -source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.32#8a21ca56a1beb2cb665c9549bfcc014849b457df" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.33-alpha1#42c7afd389cdc8d2c47a77afaaabb89e196a0192" dependencies = [ "hex", "ur", @@ -1104,7 +1104,7 @@ dependencies = [ [[package]] name = "ur-registry" version = "0.1.0" -source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.32#8a21ca56a1beb2cb665c9549bfcc014849b457df" +source = "git+https://git@github.com/KeystoneHQ/keystone-sdk-rust.git?tag=0.0.33-alpha1#42c7afd389cdc8d2c47a77afaaabb89e196a0192" dependencies = [ "bs58", "core2", diff --git a/rust/third_party/Cargo.toml b/rust/third_party/Cargo.toml index 1509d61b8..16d50fc8c 100644 --- a/rust/third_party/Cargo.toml +++ b/rust/third_party/Cargo.toml @@ -20,8 +20,8 @@ rsa = { version = "0.8.2", default-features = false } sha1 = { version = "0.10.5", default-features = false } cty = "0.2.2" cstr_core = "0.2.6" -ur-registry = { git = "https://git@github.com/KeystoneHQ/keystone-sdk-rust.git", tag = "0.0.32" } -ur-parse-lib = { git = "https://git@github.com/KeystoneHQ/keystone-sdk-rust.git", tag = "0.0.32" } +ur-registry = { git = "https://git@github.com/KeystoneHQ/keystone-sdk-rust.git", tag = "0.0.33-alpha1" } +ur-parse-lib = { git = "https://git@github.com/KeystoneHQ/keystone-sdk-rust.git", tag = "0.0.33-alpha1" } ed25519-bip32-core = { version = "0.1.1", default-features = false } cryptoxide = "0.4" itertools = { version = "0.10.5", default-features = false, features = [ diff --git a/src/ui/gui_components/gui_status_bar.c b/src/ui/gui_components/gui_status_bar.c index 3f0a1827a..0a3564b99 100644 --- a/src/ui/gui_components/gui_status_bar.c +++ b/src/ui/gui_components/gui_status_bar.c @@ -104,6 +104,7 @@ const static CoinWalletInfo_t g_walletBtn[] = { {WALLET_LIST_TYPHON, "Typhon Wallet", &walletTyphon}, {WALLET_LIST_BLUE, "BlueWallet", &walletBluewallet}, {WALLET_LIST_SUB, "SubWallet", &walletSubwallet}, + {WALLET_LIST_ZASHI, "Zashi", &walletZashi}, {WALLET_LIST_SOLFARE, "Solflare", &walletSolflare}, {WALLET_LIST_BACKPACK, "Backpack", &walletBackpack}, {WALLET_LIST_RABBY, "Rabby", &walletRabby}, diff --git a/src/ui/gui_widgets/gui_connect_wallet_widgets.c b/src/ui/gui_widgets/gui_connect_wallet_widgets.c index 2ff7ef279..158e466f9 100644 --- a/src/ui/gui_widgets/gui_connect_wallet_widgets.c +++ b/src/ui/gui_widgets/gui_connect_wallet_widgets.c @@ -349,7 +349,6 @@ static void GuiInitWalletListArray() } } - // static void GuiInitWalletListArray() // { // SetWalletListEnable(true); @@ -457,7 +456,6 @@ static void OpenQRCodeHandler(lv_event_t *e) GuiEmitSignal(SIG_SETUP_VIEW_TILE_NEXT, NULL, 0); } - #ifndef BTC_ONLY void GuiConnectWalletPasswordErrorCount(void *param) { @@ -869,7 +867,6 @@ static void AddKeystoneWalletCoins(void) lv_obj_align(img, LV_ALIGN_TOP_LEFT, 132, 2); } - static void AddBlueWalletCoins(void) { if (lv_obj_get_child_cnt(g_coinCont) > 0) { @@ -998,7 +995,6 @@ static void AddThorWalletCoins(void) } } - static void AddNightlyCoins(void) { if (lv_obj_get_child_cnt(g_coinCont) > 0) { @@ -1013,8 +1009,6 @@ static void AddNightlyCoins(void) } } - - static void AddChainAddress(void) { if (lv_obj_get_child_cnt(g_bottomCont) > 0) { @@ -1181,7 +1175,6 @@ UREncodeResult *GuiGetKeplrData(void) return GuiGetKeplrDataByIndex(GetConnectWalletAccountIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex))); } - UREncodeResult *GuiGetADAData(void) { return GuiGetADADataByIndex(GetWalletNameByIndex(g_connectWalletTileView.walletIndex)); @@ -1210,14 +1203,21 @@ UREncodeResult *GuiGetTonData(void) UREncodeResult *GuiGetZecData(void) { - uint8_t* mfp = NULL; - char* path = NULL; - char* xpub; - char* walletName = GetWalletName(); - if (walletName == NULL) { - walletName = "Keystone"; - } - return get_tonkeeper_wallet_ur(xpub, walletName, mfp, mfp == NULL ? 0 : 4, path); + uint8_t mfp[4]; + GetMasterFingerPrint(mfp); + CSliceFFI_ZcashKey *keys = SRAM_MALLOC(sizeof(CSliceFFI_ZcashKey)); + ZcashKey data[1]; + keys->data = data; + keys->size = 1; + char ufvk[384] = {'\0'}; + GetZcashUFVK(GetCurrentAccountIndex(), ufvk); + data[0].key_text = ufvk; + data[0].key_name = GetWalletName(); + char transparent_path[24] = "m/44'/133'/0'"; + char orchard_path[24] = "m/32'/133'/0'"; + data[0].transparent_key_path = transparent_path; + data[0].orchard_key_path = orchard_path; + return get_connect_zcash_wallet_ur(mfp, mfp == NULL ? 0 : 4, keys); } void GuiPrepareArConnectWalletView(void) @@ -1346,7 +1346,7 @@ void GuiConnectWalletSetQrdata(WALLET_LIST_INDEX_ENUM index) AddTonCoins(); break; case WALLET_LIST_ZASHI: - func = GuiGetTonData; + func = GuiGetZecData; AddZecCoins(); break; case WALLET_LIST_KEYSTONE: @@ -1996,7 +1996,6 @@ int8_t GuiConnectWalletNextTile(void) return SUCCESS_CODE; } - int8_t GuiConnectWalletPrevTile(void) { switch (g_connectWalletTileView.currentTile) {