@@ -21,6 +21,7 @@ use ldk_node::bitcoin::Network;
2121use ldk_node:: bitcoin:: hashes:: Hash ;
2222use ldk_node:: bitcoin:: io;
2323use ldk_node:: bitcoin:: secp256k1:: PublicKey ;
24+ use ldk_node:: entropy:: NodeEntropy ;
2425use ldk_node:: io:: sqlite_store:: SqliteStore ;
2526use ldk_node:: lightning:: ln:: msgs:: SocketAddress ;
2627use ldk_node:: lightning:: util:: logger:: Logger as _;
@@ -63,6 +64,7 @@ pub use cdk::nuts::nut00::CurrencyUnit;
6364pub use event:: { Event , EventQueue } ;
6465pub use ldk_node:: bip39:: Mnemonic ;
6566pub use ldk_node:: bitcoin;
67+ use ldk_node:: io:: vss_store:: VssStore ;
6668pub use ldk_node:: payment:: ConfirmationStatus ;
6769pub use store:: { PaymentId , PaymentType , Transaction , TxStatus } ;
6870pub use trusted_wallet:: ExtraConfig ;
@@ -154,24 +156,58 @@ pub enum Seed {
154156 Seed64 ( [ u8 ; 64 ] ) ,
155157}
156158
157- /// Represents the authentication method for a Versioned Storage Service (VSS).
159+ impl Seed {
160+ pub ( crate ) fn to_node_entropy ( & self ) -> NodeEntropy {
161+ match self {
162+ Seed :: Seed64 ( s) => NodeEntropy :: from_seed_bytes ( * s) ,
163+ Seed :: Mnemonic { mnemonic, passphrase } => {
164+ NodeEntropy :: from_bip39_mnemonic ( mnemonic. clone ( ) , passphrase. clone ( ) )
165+ } ,
166+ }
167+ }
168+ }
169+
170+ /// Authentication method used on every request to the [VSS] server.
171+ ///
172+ /// **Caution**: VSS support is in **alpha** and is considered experimental.
173+ /// Using VSS (or any remote persistence) may cause LDK to panic if persistence
174+ /// failures are unrecoverable, i.e., if they remain unresolved after internal
175+ /// retries are exhausted.
176+ ///
177+ /// [VSS]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
158178#[ derive( Debug , Clone ) ]
159179pub enum VssAuth {
160- /// Authentication using an LNURL-auth server.
180+ /// [LNURL-auth] based authentication scheme.
181+ ///
182+ /// The LNURL challenge will be retrieved by making a request to the given
183+ /// URL. The returned JWT token in response to the signed LNURL request
184+ /// will be used for authentication/authorization of all the requests made
185+ /// to VSS.
186+ ///
187+ /// [LNURL-auth]: https://github.com/lnurl/luds/blob/luds/04.md
161188 LNURLAuthServer ( String ) ,
162- /// Authentication using a fixed set of HTTP headers.
189+ /// A fixed set of HTTP headers included as-is on every request made to
190+ /// VSS.
163191 FixedHeaders ( HashMap < String , String > ) ,
164192}
165193
166- /// Configuration for a Versioned Storage Service (VSS).
194+ /// Configuration for a [Versioned Storage Service (VSS)] backend.
195+ ///
196+ /// **Caution**: VSS support is in **alpha** and is considered experimental.
197+ /// Using VSS (or any remote persistence) may cause LDK to panic if persistence
198+ /// failures are unrecoverable, i.e., if they remain unresolved after internal
199+ /// retries are exhausted.
200+ ///
201+ /// [Versioned Storage Service (VSS)]: https://github.com/lightningdevkit/vss-server/blob/main/README.md
167202#[ derive( Debug , Clone ) ]
168- #[ allow( dead_code) ]
169203pub struct VssConfig {
170- /// The URL of the VSS.
204+ /// Base URL of the VSS server (e.g. `https://vss.example.com/vss`) .
171205 pub vss_url : String ,
172- /// The store ID for the VSS.
206+ /// Segments storage from other storage accessed under the same seed (as
207+ /// storage keyed by different seeds is already segmented to prevent
208+ /// wallets from reading data for unrelated wallets). Can be any value.
173209 pub store_id : String ,
174- /// Authentication method for the VSS.
210+ /// Authentication method attached to every VSS request .
175211 pub headers : VssAuth ,
176212}
177213
@@ -180,7 +216,10 @@ pub struct VssConfig {
180216pub enum StorageConfig {
181217 /// Local SQLite database configuration.
182218 LocalSQLite ( String ) ,
183- // todo VSS(VssConfig),
219+ /// Versioned Storage Service configuration. The same store backs LDK
220+ /// channel state and orange-sdk metadata, so a seed-based recovery against
221+ /// the configured VSS endpoint restores both.
222+ Vss ( VssConfig ) ,
184223}
185224
186225/// Configuration for the blockchain data source.
@@ -411,6 +450,8 @@ pub enum InitFailure {
411450 LdkNodeStartFailure ( NodeError ) ,
412451 /// Failure in the trusted wallet implementation.
413452 TrustedFailure ( TrustedError ) ,
453+ /// Failure to build the VSS-backed store.
454+ VssStoreBuildFailure ( ldk_node:: io:: vss_store:: VssStoreBuildError ) ,
414455}
415456
416457impl From < io:: Error > for InitFailure {
@@ -437,6 +478,12 @@ impl From<TrustedError> for InitFailure {
437478 }
438479}
439480
481+ impl From < ldk_node:: io:: vss_store:: VssStoreBuildError > for InitFailure {
482+ fn from ( e : ldk_node:: io:: vss_store:: VssStoreBuildError ) -> InitFailure {
483+ InitFailure :: VssStoreBuildFailure ( e)
484+ }
485+ }
486+
440487/// Represents possible errors during wallet operations.
441488#[ derive( Debug ) ]
442489pub enum WalletError {
@@ -526,6 +573,21 @@ impl Wallet {
526573 StorageConfig :: LocalSQLite ( path) => {
527574 Arc :: new ( SqliteStore :: new ( path. into ( ) , Some ( "orange.sqlite" . to_owned ( ) ) , None ) ?)
528575 } ,
576+ StorageConfig :: Vss ( vss_config) => {
577+ let builder = VssStore :: builder (
578+ config. seed . to_node_entropy ( ) ,
579+ vss_config. vss_url . clone ( ) ,
580+ vss_config. store_id . clone ( ) ,
581+ config. network ,
582+ ) ;
583+ let vss_store = match & vss_config. headers {
584+ VssAuth :: FixedHeaders ( h) => builder. build_with_fixed_headers ( h. clone ( ) ) ?,
585+ VssAuth :: LNURLAuthServer ( url) => {
586+ builder. build_with_lnurl ( url. clone ( ) , HashMap :: new ( ) ) ?
587+ } ,
588+ } ;
589+ Arc :: new ( vss_store)
590+ } ,
529591 } ;
530592
531593 let event_queue = Arc :: new ( EventQueue :: new ( Arc :: clone ( & store) , Arc :: clone ( & logger) ) ) ;
0 commit comments