Skip to content

Commit 38ae0f9

Browse files
committed
Add support for the simple "sigs-based auth" VSS scheme
At lightningdevkit/vss-server#79 we added a new, trivial, VSS authentication scheme that ensures client isolation without much else. This is great for testing, and we expect some to do new-account-rate-limiting via other means, so might well become a common default. Here we add support to it in ldk-node.
1 parent 1fbc4ed commit 38ae0f9

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

src/builder.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,32 @@ impl NodeBuilder {
568568
self.build_with_store(node_entropy, kv_store)
569569
}
570570

571+
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
572+
/// previously configured.
573+
///
574+
/// Uses a simple authentication scheme proving knowledge of a secret key.
575+
///
576+
/// `fixed_headers` are included as it is in all the requests made to VSS and LNURL auth server.
577+
///
578+
/// **Caution**: VSS support is in **alpha** and is considered experimental.
579+
/// Using VSS (or any remote persistence) may cause LDK to panic if persistence failures are
580+
/// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
581+
///
582+
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
583+
pub fn build_with_vss_store(
584+
&self, node_entropy: NodeEntropy, vss_url: String, store_id: String,
585+
fixed_headers: HashMap<String, String>,
586+
) -> Result<Node, BuildError> {
587+
let logger = setup_logger(&self.log_writer_config, &self.config)?;
588+
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
589+
let vss_store = builder.build_with_sigs_auth(fixed_headers).map_err(|e| {
590+
log_error!(logger, "Failed to setup VSS store: {}", e);
591+
BuildError::KVStoreSetupFailed
592+
})?;
593+
594+
self.build_with_store(node_entropy, vss_store)
595+
}
596+
571597
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
572598
/// previously configured.
573599
///
@@ -585,13 +611,13 @@ impl NodeBuilder {
585611
///
586612
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
587613
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
588-
pub fn build_with_vss_store(
614+
pub fn build_with_vss_store_and_lnurl_auth(
589615
&self, node_entropy: NodeEntropy, vss_url: String, store_id: String,
590616
lnurl_auth_server_url: String, fixed_headers: HashMap<String, String>,
591617
) -> Result<Node, BuildError> {
592618
let logger = setup_logger(&self.log_writer_config, &self.config)?;
593619
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
594-
let vss_store = builder.build(lnurl_auth_server_url, fixed_headers).map_err(|e| {
620+
let vss_store = builder.build_with_lnurl(lnurl_auth_server_url, fixed_headers).map_err(|e| {
595621
log_error!(logger, "Failed to setup VSS store: {}", e);
596622
BuildError::KVStoreSetupFailed
597623
})?;

src/io/vss_store.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use rand::RngCore;
3030
use vss_client::client::VssClient;
3131
use vss_client::error::VssError;
3232
use vss_client::headers::{FixedHeaders, LnurlAuthToJwtProvider, VssHeaderProvider};
33+
use vss_client::sigs_auth::SigsAuthProvider;
3334
use vss_client::types::{
3435
DeleteObjectRequest, GetObjectRequest, KeyValue, ListKeyVersionsRequest, PutObjectRequest,
3536
Storable,
@@ -69,6 +70,7 @@ impl_writeable_tlv_based_enum!(VssSchemaVersion,
6970

7071
const VSS_HARDENED_CHILD_INDEX: u32 = 877;
7172
const VSS_LNURL_AUTH_HARDENED_CHILD_INDEX: u32 = 138;
73+
const VSS_SIGS_AUTH_HARDENED_CHILD_INDEX: u32 = 139;
7274
const VSS_SCHEMA_VERSION_KEY: &str = "vss_schema_version";
7375

7476
// We set this to a small number of threads that would still allow to make some progress if one
@@ -856,6 +858,44 @@ impl VssStoreBuilder {
856858
Self { node_entropy, vss_url, store_id, network }
857859
}
858860

861+
/// Builds a [`VssStore`] with the simple signature-based authentication scheme.
862+
///
863+
/// `fixed_headers` are included as it is in all the requests made to VSS and LNURL auth
864+
/// server.
865+
///
866+
/// **Caution**: VSS support is in **alpha** and is considered experimental. Using VSS (or any
867+
/// remote persistence) may cause LDK to panic if persistence failures are unrecoverable, i.e.,
868+
/// if they remain unresolved after internal retries are exhausted.
869+
///
870+
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
871+
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
872+
pub fn build_with_sigs_auth(
873+
&self, fixed_headers: HashMap<String, String>,
874+
) -> Result<VssStore, VssStoreBuildError> {
875+
let secp_ctx = Secp256k1::new();
876+
let seed_bytes = self.node_entropy.to_seed_bytes();
877+
let vss_xprv = Xpriv::new_master(self.network, &seed_bytes)
878+
.map_err(|_| VssStoreBuildError::KeyDerivationFailed)
879+
.and_then(|master| {
880+
master
881+
.derive_priv(
882+
&secp_ctx,
883+
&[ChildNumber::Hardened { index: VSS_HARDENED_CHILD_INDEX }],
884+
)
885+
.map_err(|_| VssStoreBuildError::KeyDerivationFailed)
886+
})?;
887+
888+
let sigs_auth_xprv = vss_xprv
889+
.derive_priv(
890+
&secp_ctx,
891+
&[ChildNumber::Hardened { index: VSS_SIGS_AUTH_HARDENED_CHILD_INDEX }],
892+
)
893+
.map_err(|_| VssStoreBuildError::KeyDerivationFailed)?;
894+
895+
let auth_provider = SigsAuthProvider::new(sigs_auth_xprv.private_key, fixed_headers);
896+
self.build_with_header_provider(Arc::new(auth_provider))
897+
}
898+
859899
/// Builds a [`VssStore`] with [LNURL-auth] based authentication scheme as default method for
860900
/// authentication/authorization.
861901
///
@@ -872,7 +912,7 @@ impl VssStoreBuilder {
872912
///
873913
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
874914
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
875-
pub fn build(
915+
pub fn build_with_lnurl(
876916
&self, lnurl_auth_server_url: String, fixed_headers: HashMap<String, String>,
877917
) -> Result<VssStore, VssStoreBuildError> {
878918
let secp_ctx = Secp256k1::new();

0 commit comments

Comments
 (0)