Skip to content

Commit 8f57ba5

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 2f5a966 commit 8f57ba5

File tree

3 files changed

+101
-9
lines changed

3 files changed

+101
-9
lines changed

bindings/ldk_node.udl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ interface Builder {
135135
[Throws=BuildError]
136136
Node build_with_fs_store(NodeEntropy node_entropy);
137137
[Throws=BuildError]
138-
Node build_with_vss_store(NodeEntropy node_entropy, string vss_url, string store_id, string lnurl_auth_server_url, record<string, string> fixed_headers);
138+
Node build_with_vss_store(NodeEntropy node_entropy, string vss_url, string store_id, record<string, string> fixed_headers);
139+
[Throws=BuildError]
140+
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);
139141
[Throws=BuildError]
140142
Node build_with_vss_store_and_fixed_headers(NodeEntropy node_entropy, string vss_url, string store_id, record<string, string> fixed_headers);
141143
[Throws=BuildError]

src/builder.rs

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

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

615642
self.build_with_store(node_entropy, vss_store)
616643
}
@@ -956,6 +983,29 @@ impl ArcedNodeBuilder {
956983
self.inner.read().unwrap().build_with_fs_store(*node_entropy).map(Arc::new)
957984
}
958985

986+
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
987+
/// previously configured.
988+
///
989+
/// Uses a simple authentication scheme proving knowledge of a secret key.
990+
///
991+
/// `fixed_headers` are included as it is in all the requests made to VSS and LNURL auth server.
992+
///
993+
/// **Caution**: VSS support is in **alpha** and is considered experimental.
994+
/// Using VSS (or any remote persistence) may cause LDK to panic if persistence failures are
995+
/// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
996+
///
997+
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
998+
pub fn build_with_vss_store(
999+
&self, node_entropy: Arc<NodeEntropy>, vss_url: String, store_id: String,
1000+
fixed_headers: HashMap<String, String>,
1001+
) -> Result<Arc<Node>, BuildError> {
1002+
self.inner
1003+
.read()
1004+
.unwrap()
1005+
.build_with_vss_store(*node_entropy, vss_url, store_id, fixed_headers)
1006+
.map(Arc::new)
1007+
}
1008+
9591009
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
9601010
/// previously configured.
9611011
///
@@ -973,14 +1023,14 @@ impl ArcedNodeBuilder {
9731023
///
9741024
/// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
9751025
/// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
976-
pub fn build_with_vss_store(
1026+
pub fn build_with_vss_store_and_lnurl_auth(
9771027
&self, node_entropy: Arc<NodeEntropy>, vss_url: String, store_id: String,
9781028
lnurl_auth_server_url: String, fixed_headers: HashMap<String, String>,
9791029
) -> Result<Arc<Node>, BuildError> {
9801030
self.inner
9811031
.read()
9821032
.unwrap()
983-
.build_with_vss_store(
1033+
.build_with_vss_store_and_lnurl_auth(
9841034
*node_entropy,
9851035
vss_url,
9861036
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 prost::Message;
2929
use rand::RngCore;
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
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
@@ -853,6 +855,44 @@ impl VssStoreBuilder {
853855
Self { node_entropy, vss_url, store_id, network }
854856
}
855857

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

0 commit comments

Comments
 (0)