Skip to content

Commit

Permalink
Create UFVK from Ledger device and sync it
Browse files Browse the repository at this point in the history
  • Loading branch information
pacu committed Jan 2, 2025
1 parent 2397094 commit 35bc048
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/commands/init_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
/// Ledger Live).
use anyhow::anyhow;
use bip32::{secp256k1::{elliptic_curve::PublicKey, Secp256k1}, PublicKeyBytes};
use futures_util::TryFutureExt;
use gumdrop::Options;
use ledger_zcash::app::ZcashApp;
use ledger_zcash::{app::ZcashApp, config::{DK_SIZE, FVK_SIZE}};
use ledger_transport_hid::{hidapi::HidApi, TransportNativeHID};
use sapling::{keys::FullViewingKey, zip32::{DiversifiableFullViewingKey, DiversifierKey}, Diversifier };
use transparent::keys::AccountPubKey;
Expand Down Expand Up @@ -145,11 +144,19 @@ impl Command {

println!("Get Diverisifier Key");
let dk = DiversifierKey::from_bytes(dk_bytes);
println!("DK {:?}",fvk_bytes);
// let dfvk = DiversifiableFullViewingKey {
// fvk: fvk,
// dk: dk
// };
println!("DK {:?}",dk_bytes);

// Create a slice that contains the FVK + DK so we can create a Diversifiable FVK
// from bytes
let mut dfvk_bytes = [0u8; FVK_SIZE + DK_SIZE];

dfvk_bytes[..FVK_SIZE].copy_from_slice(&fvk_bytes);
dfvk_bytes[FVK_SIZE..FVK_SIZE + DK_SIZE].copy_from_slice(&dk_bytes);


let dfvk = DiversifiableFullViewingKey::from_bytes(&dfvk_bytes)
.expect("Unable to create Sapling Diversifiable Full Viewing Key");


let path = BIP44Path::from_string("m/44'/133'/0'/0/0")
.map_err(|_|anyhow!("Error mapping path m/44'/133'/0/0"))?;
Expand All @@ -173,7 +180,7 @@ impl Command {

let ufvk = UnifiedFullViewingKey::new(
Some(account_pub_key),
None,
Some(dfvk),
None,
)
.map_err(anyhow::Error::new)?;
Expand Down
5 changes: 5 additions & 0 deletions src/commands/list_addresses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ impl Command {
let account = select_account(&db_data, self.account_id)?;

println!("Account {:?}", account.id());
#[cfg(not(feature = "ledger-support"))]
let (ua, _) = account
.uivk()
.default_address(UnifiedAddressRequest::all())?;
#[cfg(feature = "ledger-support")]
let (ua, _) = account
.uivk()
.default_address(UnifiedAddressRequest::new(false, true, true))?;
println!(" Default Address: {}", ua.encode(&params));
Ok(())
}
Expand Down

0 comments on commit 35bc048

Please sign in to comment.