-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
86 additions
and
39 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::sync::Arc; | ||
|
||
use gl_client::{ | ||
bitcoin::{ | ||
hashes::{sha256, Hash, HashEngine, Hmac, HmacEngine}, | ||
secp256k1::{Message, Secp256k1}, | ||
util::bip32::ChildNumber, | ||
}, | ||
lightning::util::ser::Writeable, | ||
}; | ||
use sdk_common::prelude::{LnUrlError, LnUrlResult, LnurAuthSigner}; | ||
|
||
use crate::node_api::NodeAPI; | ||
|
||
pub(crate) struct SDKLnurlAuthSigner { | ||
node_api: Arc<dyn NodeAPI>, | ||
} | ||
|
||
impl SDKLnurlAuthSigner { | ||
pub fn new(node_api: Arc<dyn NodeAPI>) -> Self { | ||
Self { node_api } | ||
} | ||
} | ||
|
||
impl LnurAuthSigner for SDKLnurlAuthSigner { | ||
fn derive_bip32_pub_key(&self, derivation_path: &[ChildNumber]) -> LnUrlResult<Vec<u8>> { | ||
Ok(self | ||
.node_api | ||
.derive_bip32_key(derivation_path.to_vec())? | ||
.to_keypair(&Secp256k1::new()) | ||
.public_key() | ||
.encode()) | ||
} | ||
|
||
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"))?, | ||
&xpriv.private_key, | ||
); | ||
Ok(sig.encode()) | ||
} | ||
|
||
fn hmac_sha256( | ||
&self, | ||
key_derivation_path: &[ChildNumber], | ||
input: &[u8], | ||
) -> LnUrlResult<Vec<u8>> { | ||
let priv_key = self | ||
.node_api | ||
.derive_bip32_key(key_derivation_path.to_vec())?; | ||
let mut engine = HmacEngine::<sha256::Hash>::new(priv_key.encode().as_slice()); | ||
engine.input(input); | ||
Ok(Hmac::<sha256::Hash>::from_engine(engine) | ||
.as_inner() | ||
.to_vec()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod auth; | ||
pub mod pay; | ||
|
||
#[cfg(test)] | ||
|