-
Notifications
You must be signed in to change notification settings - Fork 43
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
Implement lnurl auth signer #1088
Conversation
let sig = Secp256k1::new().sign_ecdsa(&k1_to_sign, &linking_keys.secret_key()); | ||
let url = Url::from_str(&req_data.url).map_err(|e| LnUrlError::InvalidUri(e.to_string()))?; | ||
let derivation_path = get_derivation_path(signer, url)?; | ||
let sig = signer.sign_ecdsa(req_data.k1.as_bytes(), &derivation_path)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this k1
needs to be decoded from hex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I wonder how it is working also with this code...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
let url = Url::from_str(&req_data.url).map_err(|e| LnUrlError::InvalidUri(e.to_string()))?; | ||
let derivation_path = get_derivation_path(signer, url)?; | ||
let sig = signer.sign_ecdsa(req_data.k1.as_bytes(), &derivation_path)?; | ||
let xpub = signer.derive_bip32_pub_key(&derivation_path)?; | ||
|
||
// <LNURL_hostname_and_path>?<LNURL_existing_query_parameters>&sig=<hex(sign(utf8ToBytes(k1), linkingPrivKey))>&key=<hex(linkingKey)> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From LUD-04:
// <LNURL_hostname_and_path>?<LNURL_existing_query_parameters>&sig=<hex(sign(utf8ToBytes(k1), linkingPrivKey))>&key=<hex(linkingKey)> | |
// <LNURL_hostname_and_path>?<LNURL_existing_query_parameters>&sig=<hex(sign(hexToBytes(k1), linkingPrivKey))>&key=<hex(linkingKey)> |
libs/sdk-core/src/lnurl/auth.rs
Outdated
fn sign_ecdsa(&self, msg: &[u8], derivation_path: &[ChildNumber]) -> LnUrlResult<Vec<u8>> { | ||
let xpriv = self.node_api.derive_bip32_key(derivation_path.to_vec())?; | ||
let sig = Secp256k1::new().sign_ecdsa( | ||
&Message::from_slice(msg).map_err(|_| LnUrlError::generic("failed to sign"))?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&Message::from_slice(msg).map_err(|_| LnUrlError::generic("failed to sign"))?, | |
&Message::from_slice(msg).map_err(|_| LnUrlError::generic("Failed to sign"))?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
libs/sdk-core/src/lnurl/auth.rs
Outdated
|
||
use crate::node_api::NodeAPI; | ||
|
||
pub(crate) struct SDKLnurlAuthSigner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit about naming, Sdk
is used throughout for structs and enums (correct or not, just for consistency)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
use reqwest::Url; | ||
|
||
use crate::prelude::*; | ||
|
||
pub trait LnurAuthSigner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, just spotted:
pub trait LnurAuthSigner { | |
pub trait LnurlAuthSigner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It worked before and after the last 2 commits, but it's more readable now. Tested on stacker news.
This PR changes the lnurl auth functionality to support signers that don't expose private keys.
Instead of passing the private key (linking key) to the lnurl module for signing the lnurl module expect a signer implementation with some basic building blocks for siginig and deriving public keys.
Also the caller now doesn't need to have a knowledge about the lnurl auth internals (constructing the linking key for example) as the lnurl module takes care of it.
This is needed in order also to support splitting the signer from the sdk implementation in breez-ask-liquid project.