@@ -77,7 +77,7 @@ use std::sync::atomic::AtomicBool;
77
77
use std:: sync:: { Arc , Mutex , RwLock } ;
78
78
use std:: time:: SystemTime ;
79
79
#[ cfg( any( vss, vss_test) ) ]
80
- use vss_client:: headers:: { FixedHeaders , VssHeaderProvider } ;
80
+ use vss_client:: headers:: { FixedHeaders , LnurlAuthToJwtProvider , VssHeaderProvider } ;
81
81
82
82
#[ derive( Debug , Clone ) ]
83
83
enum ChainDataSourceConfig {
@@ -361,10 +361,66 @@ impl NodeBuilder {
361
361
self . build_with_store ( kv_store)
362
362
}
363
363
364
+ /// Builds a [`Node`] instance with a [VSS] backend and according to the options
365
+ /// previously configured.
366
+ ///
367
+ /// Uses [LNURL-auth] based authentication scheme as default method for authentication/authorization.
368
+ ///
369
+ /// The LNURL challenge will be retrieved by making a request to the given `lnurl_auth_server_url`.
370
+ /// The returned JWT token in response to the signed LNURL request, will be used for
371
+ /// authentication/authorization of all the requests made to VSS.
372
+ ///
373
+ /// `fixed_headers` are included as it is in all the requests made to VSS and LNURL auth server.
374
+ ///
375
+ /// **Caution**: VSS support is in **alpha** and is considered experimental.
376
+ /// Using VSS (or any remote persistence) may cause LDK to panic if persistence failures are
377
+ /// unrecoverable, i.e., if they remain unresolved after internal retries are exhausted.
378
+ ///
379
+ /// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
380
+ /// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
381
+ #[ cfg( any( vss, vss_test) ) ]
382
+ pub fn build_with_vss_store (
383
+ & self , vss_url : String , store_id : String , lnurl_auth_server_url : String ,
384
+ fixed_headers : HashMap < String , String > ,
385
+ ) -> Result < Node , BuildError > {
386
+ use bitcoin:: key:: Secp256k1 ;
387
+
388
+ let logger = setup_logger ( & self . config ) ?;
389
+
390
+ let seed_bytes = seed_bytes_from_config (
391
+ & self . config ,
392
+ self . entropy_source_config . as_ref ( ) ,
393
+ Arc :: clone ( & logger) ,
394
+ ) ?;
395
+
396
+ let config = Arc :: new ( self . config . clone ( ) ) ;
397
+
398
+ let vss_xprv = derive_vss_xprv ( config, & seed_bytes, Arc :: clone ( & logger) ) ?;
399
+
400
+ let lnurl_auth_xprv = vss_xprv
401
+ . derive_priv ( & Secp256k1 :: new ( ) , & [ ChildNumber :: Hardened { index : 138 } ] )
402
+ . map_err ( |e| {
403
+ log_error ! ( logger, "Failed to derive VSS secret: {}" , e) ;
404
+ BuildError :: KVStoreSetupFailed
405
+ } ) ?;
406
+
407
+ let lnurl_auth_jwt_provider =
408
+ LnurlAuthToJwtProvider :: new ( lnurl_auth_xprv, lnurl_auth_server_url, fixed_headers)
409
+ . map_err ( |e| {
410
+ log_error ! ( logger, "Failed to create LnurlAuthToJwtProvider: {}" , e) ;
411
+ BuildError :: KVStoreSetupFailed
412
+ } ) ?;
413
+
414
+ let header_provider = Arc :: new ( lnurl_auth_jwt_provider) ;
415
+
416
+ self . build_with_vss_store_and_header_provider ( vss_url, store_id, header_provider)
417
+ }
418
+
364
419
/// Builds a [`Node`] instance with a [VSS] backend and according to the options
365
420
/// previously configured.
366
421
///
367
422
/// Uses [`FixedHeaders`] as default method for authentication/authorization.
423
+ ///
368
424
/// Given `fixed_headers` are included as it is in all the requests made to VSS.
369
425
///
370
426
/// **Caution**: VSS support is in **alpha** and is considered experimental.
0 commit comments