Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unblinding UTXO] Ability to detect and spend unblinded addresses #36 #39

Draft
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Docker is required for linux builds.

```bash
dart pub global activate ffigen
cargo install flutter_rust_bridge_codegen
cargo install flutter_rust_bridge_codegen --version 2.0.0-dev.31
cargo install cargo-expand
cargo install cargo-ndk
@if [ $$(uname) == "Darwin" ] ; then cargo install cargo-lipo ; fi
Expand Down
44 changes: 39 additions & 5 deletions rust/src/api/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use lwk_wollet::full_scan_with_electrum_client;
// use lwk_wollet::elements_miniscript::descriptor;
use lwk_wollet::AddressResult;
use lwk_wollet::ElectrumClient;
use lwk_wollet::Update;
use lwk_wollet::WolletDescriptor;

pub use std::sync::Mutex;
Expand Down Expand Up @@ -234,10 +233,10 @@ impl Wallet {

#[cfg(test)]
mod tests {

use std::{thread, time::Duration};

use super::*;
use elements::AssetId;
use lwk_wollet::bitcoin::Address;
use std::{thread, time::Duration};
#[test]
fn testable_wallets() {
let mnemonic =
Expand Down Expand Up @@ -415,7 +414,6 @@ mod tests {
// .unwrap_err();
// assert_eq!(err.to_string(), "FIXME");
// * */

// // Create tx sending the unblinded utxo
// let node_address = server.node_getnewaddress();

Expand Down Expand Up @@ -443,4 +441,40 @@ mod tests {

// // TODO: more cases
// }

#[test]
fn test_unblinded_detection() {
let network = Network::Testnet;
let mnemonic = "";
let descriptor = Descriptor::new_confidential(network, mnemonic.to_string())
.expect("Failed to create descriptor");
let wallet = Wallet::init(network, "/tmp/lwk_test".to_string(), descriptor).expect("");

let confidential_address = wallet.address_last_unused().unwrap();
println!("The confidential address is {}", confidential_address);

//Write code to halt for the payment to be made. maybe we can add a timer? or take an input from user that confirms that he did the pyment or not.

let electrum_url = "les.bullbitcoin.com:995".to_string();
wallet.sync(electrum_url.clone()).unwrap();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're on testnet now, I'll change this to use blockstream testnet url.


let balance_before = wallet.balances().unwrap();
let txs_before = wallet.txs().unwrap();

assert!(balance.get(0), >0);
assert!(!txs_before.is_empty());

let blinding_key = wallet.blinding_key().unwrap();
let unblinded_address = "";
let unblinded_address = println!("The unblinded address is {}", unblinded_address);
println!("Fund the unblinded address");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to create a function that converts unblinded_address to blinded using the binding key.
I couldn't find any method that does this either in lwk-dart repo or in lwk.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean blinded to unblinded? We don't need to go the other way around.

let unblinded_address = confidential_address.standard;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct has methods to go either direction:

https://docs.rs/elements/0.24.1/elements/address/struct.Address.html


wallet.sync(electrum_url.clone()).unwrap();

let balance_after = wallet.balances().unwrap();
let txs_after = wallet.txs().unwrap();

assert!(balance_after.get(0), "{}", balance_before.get(0));
println!("Payment to unblinded address not detected");
}
}