-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
519 additions
and
39 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nightly-2023-06-26 | ||
nightly |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UFVKInfo>, mfp: [u8; 4]) -> URResult<ZcashAccounts> { | ||
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::<URResult<Vec<ZcashUnifiedFullViewingKey>>>()?; | ||
let accounts = ZcashAccounts::new(mfp, keys); | ||
Ok(accounts) | ||
} |
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
rust/rust_c/src/wallet/src/multi_coins_wallet/src/zcash.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CSliceFFI<ZcashKey>>, | ||
) -> *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<UFVKInfo> = 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(), | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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://[email protected]/KeystoneHQ/keystone-sdk-rust.git", tag = "0.0.32" } | ||
ur-parse-lib = { git = "https://[email protected]/KeystoneHQ/keystone-sdk-rust.git", tag = "0.0.32" } | ||
ur-registry = { git = "https://[email protected]/KeystoneHQ/keystone-sdk-rust.git", tag = "0.0.33-alpha1" } | ||
ur-parse-lib = { git = "https://[email protected]/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 = [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters