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

Magic Routing Hint #43

Merged
merged 9 commits into from
May 4, 2024
Merged

Magic Routing Hint #43

merged 9 commits into from
May 4, 2024

Conversation

rajarshimaitra
Copy link
Contributor

This code adds the Magic Routing Hint logic. As most of the logic is at the application layer, the code is added in the test cases of v2 swaps.

No changes in the internals of the library is required.

This is untested. And to test it one has to perform the following.

  • Initiate a reverse swap with Boltz.
  • Use the invoice received in reverse swap and initiate a submarine swap with the same invoice.

src/util/mod.rs Outdated Show resolved Hide resolved
src/util/mod.rs Outdated

use crate::{error::Error, network::electrum::ElectrumConfig};

pub mod ec;
pub mod secrets;

const ENDPOINT: &str = "https://api.testnet.boltz.exchange";
const MAGIC_ROUTING_HINT_CONSTANT: &str = "0846c900051c0000";
const LBTC_ASSET_HASH: &str = "144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49";
Copy link
Collaborator

Choose a reason for hiding this comment

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

The L-BTC asset hash depends on the network

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only found one asset hash from your doc. Added a placeholder for mainnet asset hash. Can be easily updated when I have it.

Comment on lines 53 to 66
let address_hash = sha256::Hash::hash(&Vec::from_hex(&bip21.address.to_string()).unwrap());
let msg = Message::from_digest_slice(address_hash.as_byte_array()).unwrap();

let receiver_sig = bitcoin::secp256k1::schnorr::Signature::from_slice(
&Vec::from_hex(&mrh_resp.signature).unwrap(),
)
.unwrap();

let receiver_pubkey = PublicKey::from_str(&route_hint.src_node_id.to_string())
.unwrap()
.inner;

secp.verify_schnorr(&receiver_sig, &msg, &receiver_pubkey.x_only_public_key().0)
.unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't just be in a test but a public function that is available for consumers of the library to
call
We might want to integrate this in the library function that creates a swap

Copy link
Contributor Author

@rajarshimaitra rajarshimaitra May 4, 2024

Choose a reason for hiding this comment

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

There is no function as "create swap". Depends on the structure of the lib. Currently swap creating steps are in the test itself. Moved the MRH parts into it's own module magic_routing.rs and all the relevant functions are added there.

tests/bitcoin_v2.rs Outdated Show resolved Hide resolved
tests/bitcoin_v2.rs Show resolved Hide resolved
Create a new Magic Routing Hint module with all the relevant code.
Remove them from utility module.

New place holder added for liquid mainnet asset hash.

Remove bip21 as uri parsing isn't supported for liquid. So manual URI string parsing is added.
@i5hi
Copy link
Collaborator

i5hi commented May 4, 2024

Thanks @rajarshimaitra !

@i5hi i5hi merged commit b8b9a5b into SatoshiPortal:trunk May 4, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants