Skip to content

Commit

Permalink
fix pubkey extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
roeierez committed Sep 22, 2024
1 parent 1608d0e commit 76942b5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libs/sdk-common/src/lnurl/specs/auth.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;

use bitcoin::hashes::hex::ToHex;
use bitcoin::util::bip32::ChildNumber;
use bitcoin::util::bip32::{ChildNumber, ExtendedPubKey};
use reqwest::Url;

use crate::prelude::*;
Expand Down Expand Up @@ -34,7 +34,8 @@ pub async fn perform_lnurl_auth<S: LnurlAuthSigner>(
.map_err(|e| LnUrlError::Generic(format!("Error decoding k1: {e}")))?,
&derivation_path,
)?;
let xpub = signer.derive_bip32_pub_key(&derivation_path)?;
let xpub_bytes = signer.derive_bip32_pub_key(&derivation_path)?;
let xpub = ExtendedPubKey::decode(xpub_bytes.as_slice())?;

// <LNURL_hostname_and_path>?<LNURL_existing_query_parameters>&sig=<hex(sign(utf8ToBytes(k1), linkingPrivKey))>&key=<hex(linkingKey)>
let mut callback_url =
Expand All @@ -44,7 +45,7 @@ pub async fn perform_lnurl_auth<S: LnurlAuthSigner>(
.append_pair("sig", &sig.to_hex());
callback_url
.query_pairs_mut()
.append_pair("key", xpub.to_hex().as_str());
.append_pair("key", &xpub.public_key.to_hex());

get_parse_and_log_response(callback_url.as_ref(), false)
.await
Expand Down Expand Up @@ -100,7 +101,10 @@ pub fn get_derivation_path<S: LnurlAuthSigner>(
.domain()
.ok_or(LnUrlError::invalid_uri("Could not determine domain"))?;

let hmac = signer.hmac_sha256(&[ChildNumber::from_hardened_idx(138)?], domain.as_bytes())?;
let hmac = signer.hmac_sha256(
&[ChildNumber::from_hardened_idx(138)?, ChildNumber::from(0)],
domain.as_bytes(),
)?;

// m/138'/<long1>/<long2>/<long3>/<long4>
Ok(vec![
Expand Down

0 comments on commit 76942b5

Please sign in to comment.