-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Description --- Utilize the view key from the ledger to perform recovery on a wallet, and support one-sided transactions. Motivation and Context --- Allow recovery. How Has This Been Tested? --- Manually - [x] Software -> Software - [x] One-sided - [x] Interactive - [x] Ledger -> Software - [x] One-sided - [x] Interactive - [x] Ledger -> Ledger - [x] Interactive - [x] One-sided - [x] Software recovery - [x] Ledger recovery What process can a PR reviewer use to test or verify this change? --- Please run a manual test between wallets. Breaking Changes --- - [ ] None - [x] Requires data directory on base node to be deleted - [x] Requires hard fork - [ ] Other - Please specify --------- Co-authored-by: SW van Heerden <[email protected]>
- Loading branch information
1 parent
29f618e
commit fb2de35
Showing
39 changed files
with
420 additions
and
193 deletions.
There are no files selected for viewing
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
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
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
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
44 changes: 44 additions & 0 deletions
44
applications/minotari_ledger_wallet/wallet/src/handlers/get_dh_shared_secret.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,44 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use core::ops::Deref; | ||
|
||
use ledger_device_sdk::io::Comm; | ||
use tari_crypto::{ristretto::RistrettoPublicKey, tari_utilities::ByteArray}; | ||
|
||
use crate::{ | ||
utils::{derive_from_bip32_key, get_key_from_canonical_bytes}, | ||
AppSW, | ||
KeyType, | ||
RESPONSE_VERSION, | ||
}; | ||
|
||
pub fn handler_get_dh_shared_secret(comm: &mut Comm) -> Result<(), AppSW> { | ||
let data = comm.get_data().map_err(|_| AppSW::WrongApduLength)?; | ||
|
||
let mut account_bytes = [0u8; 8]; | ||
account_bytes.clone_from_slice(&data[0..8]); | ||
let account = u64::from_le_bytes(account_bytes); | ||
|
||
let mut index_bytes = [0u8; 8]; | ||
index_bytes.clone_from_slice(&data[8..16]); | ||
let index = u64::from_le_bytes(index_bytes); | ||
|
||
let mut key_bytes = [0u8; 8]; | ||
key_bytes.clone_from_slice(&data[16..24]); | ||
let key_int = u64::from_le_bytes(key_bytes); | ||
let key = KeyType::from_branch_key(key_int); | ||
|
||
let public_key: RistrettoPublicKey = get_key_from_canonical_bytes(&data[24..56])?; | ||
|
||
let shared_secret_key = match derive_from_bip32_key(account, index, key) { | ||
Ok(k) => k.deref() * public_key, | ||
Err(e) => return Err(e), | ||
}; | ||
|
||
comm.append(&[RESPONSE_VERSION]); // version | ||
comm.append(shared_secret_key.as_bytes()); | ||
comm.reply_ok(); | ||
|
||
Ok(()) | ||
} |
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
26 changes: 26 additions & 0 deletions
26
applications/minotari_ledger_wallet/wallet/src/handlers/get_view_key.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,26 @@ | ||
// Copyright 2024 The Tari Project | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
use ledger_device_sdk::io::Comm; | ||
use tari_crypto::tari_utilities::ByteArray; | ||
|
||
use crate::{utils::derive_from_bip32_key, AppSW, KeyType, RESPONSE_VERSION, STATIC_VIEW_INDEX}; | ||
|
||
pub fn handler_get_view_key(comm: &mut Comm) -> Result<(), AppSW> { | ||
let data = comm.get_data().map_err(|_| AppSW::WrongApduLength)?; | ||
|
||
let mut account_bytes = [0u8; 8]; | ||
account_bytes.clone_from_slice(&data[0..8]); | ||
let account = u64::from_le_bytes(account_bytes); | ||
|
||
let p = match derive_from_bip32_key(account, STATIC_VIEW_INDEX, KeyType::ViewKey) { | ||
Ok(k) => k, | ||
Err(e) => return Err(e), | ||
}; | ||
|
||
comm.append(&[RESPONSE_VERSION]); // version | ||
comm.append(p.as_bytes()); | ||
comm.reply_ok(); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.