Skip to content

Commit 4588299

Browse files
TheBlueMattvincenzopalazzo
authored andcommitted
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 d3c4538 commit 4588299

3 files changed

Lines changed: 101 additions & 9 deletions

File tree

bindings/ldk_node.udl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ interface Builder {
6262
[Throws=BuildError]
6363
Node build_with_fs_store(NodeEntropy node_entropy);
6464
[Throws=BuildError]
65-
Node build_with_vss_store(NodeEntropy node_entropy, string vss_url, string store_id, string lnurl_auth_server_url, record<string, string> fixed_headers);
65+
Node build_with_vss_store(NodeEntropy node_entropy, string vss_url, string store_id, record<string, string> fixed_headers);
66+
[Throws=BuildError]
67+
Node build_with_vss_store_and_lnurl_auth(NodeEntropy node_entropy, string vss_url, string store_id, string lnurl_auth_server_url, record<string, string> fixed_headers);
6668
[Throws=BuildError]
6769
Node build_with_vss_store_and_fixed_headers(NodeEntropy node_entropy, string vss_url, string store_id, record<string, string> fixed_headers);
6870
[Throws=BuildError]

src/builder.rs

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,32 @@ impl NodeBuilder {
586586
self.build_with_store(node_entropy, kv_store)
587587
}
588588

589+
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
590+
/// previously configured.
591+
///
592+
/// Uses a simple authentication scheme proving knowledge of a secret key.
593+
///
594+
/// `fixed_headers` are included as it is in all the requests made to VSS and LNURL auth server.
595+
///
596+
/// **Caution**: VSS support is in **alpha** and is considered experimental.
597+
/// Using VSS (or any remote persistence) may cause LDK to panic if persistence failures are
598+
/// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
599+
///
600+
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
601+
pub fn build_with_vss_store(
602+
&self, node_entropy: NodeEntropy, vss_url: String, store_id: String,
603+
fixed_headers: HashMap<String, String>,
604+
) -> Result<Node, BuildError> {
605+
let logger = setup_logger(&self.log_writer_config, &self.config)?;
606+
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
607+
let vss_store = builder.build_with_sigs_auth(fixed_headers).map_err(|e| {
608+
log_error!(logger, "Failed to setup VSS store: {}", e);
609+
BuildError::KVStoreSetupFailed
610+
})?;
611+
612+
self.build_with_store(node_entropy, vss_store)
613+
}
614+
589615
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
590616
/// previously configured.
591617
///
@@ -603,16 +629,17 @@ impl NodeBuilder {
603629
///
604630
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
605631
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
606-
pub fn build_with_vss_store(
632+
pub fn build_with_vss_store_and_lnurl_auth(
607633
&self, node_entropy: NodeEntropy, vss_url: String, store_id: String,
608634
lnurl_auth_server_url: String, fixed_headers: HashMap<String, String>,
609635
) -> Result<Node, BuildError> {
610636
let logger = setup_logger(&self.log_writer_config, &self.config)?;
611637
let builder = VssStoreBuilder::new(node_entropy, vss_url, store_id, self.config.network);
612-
let vss_store = builder.build(lnurl_auth_server_url, fixed_headers).map_err(|e| {
613-
log_error!(logger, "Failed to setup VSS store: {}", e);
614-
BuildError::KVStoreSetupFailed
615-
})?;
638+
let vss_store =
639+
builder.build_with_lnurl(lnurl_auth_server_url, fixed_headers).map_err(|e| {
640+
log_error!(logger, "Failed to setup VSS store: {}", e);
641+
BuildError::KVStoreSetupFailed
642+
})?;
616643

617644
self.build_with_store(node_entropy, vss_store)
618645
}
@@ -958,6 +985,29 @@ impl ArcedNodeBuilder {
958985
self.inner.read().unwrap().build_with_fs_store(*node_entropy).map(Arc::new)
959986
}
960987

988+
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
989+
/// previously configured.
990+
///
991+
/// Uses a simple authentication scheme proving knowledge of a secret key.
992+
///
993+
/// `fixed_headers` are included as it is in all the requests made to VSS and LNURL auth server.
994+
///
995+
/// **Caution**: VSS support is in **alpha** and is considered experimental.
996+
/// Using VSS (or any remote persistence) may cause LDK to panic if persistence failures are
997+
/// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
998+
///
999+
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
1000+
pub fn build_with_vss_store(
1001+
&self, node_entropy: Arc<NodeEntropy>, vss_url: String, store_id: String,
1002+
fixed_headers: HashMap<String, String>,
1003+
) -> Result<Arc<Node>, BuildError> {
1004+
self.inner
1005+
.read()
1006+
.unwrap()
1007+
.build_with_vss_store(*node_entropy, vss_url, store_id, fixed_headers)
1008+
.map(Arc::new)
1009+
}
1010+
9611011
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
9621012
/// previously configured.
9631013
///
@@ -975,14 +1025,14 @@ impl ArcedNodeBuilder {
9751025
///
9761026
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
9771027
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
978-
pub fn build_with_vss_store(
1028+
pub fn build_with_vss_store_and_lnurl_auth(
9791029
&self, node_entropy: Arc<NodeEntropy>, vss_url: String, store_id: String,
9801030
lnurl_auth_server_url: String, fixed_headers: HashMap<String, String>,
9811031
) -> Result<Arc<Node>, BuildError> {
9821032
self.inner
9831033
.read()
9841034
.unwrap()
985-
.build_with_vss_store(
1035+
.build_with_vss_store_and_lnurl_auth(
9861036
*node_entropy,
9871037
vss_url,
9881038
store_id,

src/io/vss_store.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use lightning::util::ser::{Readable, Writeable};
2929
use prost::Message;
3030
use vss_client::client::VssClient;
3131
use vss_client::error::VssError;
32+
use vss_client::headers::sigs_auth::SigsAuthProvider;
3233
use vss_client::headers::{FixedHeaders, LnurlAuthToJwtProvider, VssHeaderProvider};
3334
use vss_client::types::{
3435
DeleteObjectRequest, GetObjectRequest, KeyValue, ListKeyVersionsRequest, PutObjectRequest,
@@ -69,6 +70,7 @@ impl_writeable_tlv_based_enum!(VssSchemaVersion,
6970
);
7071

7172
const VSS_HARDENED_CHILD_INDEX: u32 = 877;
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
@@ -867,6 +869,44 @@ impl VssStoreBuilder {
867869
Self { node_entropy, vss_url, store_id, network }
868870
}
869871

872+
/// Builds a [`VssStore`] with the simple signature-based authentication scheme.
873+
///
874+
/// `fixed_headers` are included as it is in all the requests made to VSS and LNURL auth
875+
/// server.
876+
///
877+
/// **Caution**: VSS support is in **alpha** and is considered experimental. Using VSS (or any
878+
/// remote persistence) may cause LDK to panic if persistence failures are unrecoverable, i.e.,
879+
/// if they remain unresolved after internal retries are exhausted.
880+
///
881+
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
882+
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
883+
pub fn build_with_sigs_auth(
884+
&self, fixed_headers: HashMap<String, String>,
885+
) -> Result<VssStore, VssStoreBuildError> {
886+
let secp_ctx = Secp256k1::new();
887+
let seed_bytes = self.node_entropy.to_seed_bytes();
888+
let vss_xprv = Xpriv::new_master(self.network, &seed_bytes)
889+
.map_err(|_| VssStoreBuildError::KeyDerivationFailed)
890+
.and_then(|master| {
891+
master
892+
.derive_priv(
893+
&secp_ctx,
894+
&[ChildNumber::Hardened { index: VSS_HARDENED_CHILD_INDEX }],
895+
)
896+
.map_err(|_| VssStoreBuildError::KeyDerivationFailed)
897+
})?;
898+
899+
let sigs_auth_xprv = vss_xprv
900+
.derive_priv(
901+
&secp_ctx,
902+
&[ChildNumber::Hardened { index: VSS_SIGS_AUTH_HARDENED_CHILD_INDEX }],
903+
)
904+
.map_err(|_| VssStoreBuildError::KeyDerivationFailed)?;
905+
906+
let auth_provider = SigsAuthProvider::new(sigs_auth_xprv.private_key, fixed_headers);
907+
self.build_with_header_provider(Arc::new(auth_provider))
908+
}
909+
870910
/// Builds a [`VssStore`] with [LNURL-auth] based authentication scheme as default method for
871911
/// authentication/authorization.
872912
///
@@ -883,7 +923,7 @@ impl VssStoreBuilder {
883923
///
884924
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
885925
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
886-
pub fn build(
926+
pub fn build_with_lnurl(
887927
&self, lnurl_auth_server_url: String, fixed_headers: HashMap<String, String>,
888928
) -> Result<VssStore, VssStoreBuildError> {
889929
let secp_ctx = Secp256k1::new();

0 commit comments

Comments
 (0)