]> Untitled Git - bdk-cli/commitdiff
Add cookie authentication option for rpc
authorrajarshimaitra <rajarshi149@gmail.com>
Sat, 8 Jan 2022 18:33:12 +0000 (00:03 +0530)
committerrajarshimaitra <rajarshi149@gmail.com>
Sat, 12 Feb 2022 16:57:56 +0000 (22:27 +0530)
src/bdk_cli.rs
src/lib.rs

index baa12cf8e05fb90abb73d58ff9f3ab213835a7fb..10b3b1757074a7eea077245c533c027339712e04 100644 (file)
@@ -191,9 +191,15 @@ where
 
     #[cfg(feature = "rpc")]
     let config: AnyBlockchainConfig = {
-        let auth = Auth::UserPass {
-            username: wallet_opts.rpc_opts.auth.0.clone(),
-            password: wallet_opts.rpc_opts.auth.1.clone(),
+        let auth = if let Some(cookie) = &wallet_opts.rpc_opts.cookie {
+            Auth::Cookie {
+                file: cookie.into(),
+            }
+        } else {
+            Auth::UserPass {
+                username: wallet_opts.rpc_opts.basic_auth.0.clone(),
+                password: wallet_opts.rpc_opts.basic_auth.1.clone(),
+            }
         };
 
         // Use deterministic wallet name derived from descriptor
index 9d083809f128a81f861ef6cc7dcd13668d2b8553..91ad841a97e8253287011e306c98b065d667f71a 100644 (file)
@@ -229,8 +229,9 @@ use bdk_reserves::reserves::ProofOfReserves;
 ///                 #[cfg(feature = "rpc")]
 ///                 rpc_opts: RpcOpts{
 ///                    address: "127.0.0.1:18443".to_string(),
-///                    auth: ("user".to_string(), "password".to_string()),
+///                    basic_auth: ("user".to_string(), "password".to_string()),
 ///                    skip_blocks: None,
+///                    cookie: None,
 ///                },
 ///                #[cfg(feature = "compact_filters")]
 ///                compactfilter_opts: CompactFilterOpts{
@@ -542,15 +543,19 @@ pub struct RpcOpts {
     )]
     pub address: String,
 
-    /// Sets the rpc authentication username:password
+    /// Sets the rpc basic authentication
     #[structopt(
         name = "USER:PASSWD",
         short = "a",
-        long = "auth",
+        long = "basic-auth",
         parse(try_from_str = parse_proxy_auth),
         default_value = "user:password",
     )]
-    pub auth: (String, String),
+    pub basic_auth: (String, String),
+
+    /// Sets an optional cookie authentication
+    #[structopt(name = "COOKIE", long = "cookie")]
+    pub cookie: Option<String>,
 
     /// Optionally skip initial `skip_blocks` blocks
     #[structopt(name = "SKIP_BLOCKS", short = "s", long = "skip-blocks")]
@@ -1479,7 +1484,8 @@ mod test {
                     #[cfg(feature = "rpc")]
                     rpc_opts: RpcOpts {
                         address: "127.0.0.1:18443".to_string(),
-                        auth: ("user".to_string(), "password".to_string()),
+                        basic_auth: ("user".to_string(), "password".to_string()),
+                        cookie: None,
                         skip_blocks: None,
                     },
                 },
@@ -1616,7 +1622,8 @@ mod test {
                             "--descriptor", "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/0/*)",
                             "--change_descriptor", "wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)",
                             "--node", "125.67.89.101:56678",
-                            "--auth", "user:password",
+                            "--basic-auth", "user:password",
+                            "--cookie", "/home/user/.bitcoin/regtest/.cookie",
                             "--skip-blocks", "5",
                             "get_new_address"];
 
@@ -1632,7 +1639,8 @@ mod test {
                     change_descriptor: Some("wpkh(xpubDEnoLuPdBep9bzw5LoGYpsxUQYheRQ9gcgrJhJEcdKFB9cWQRyYmkCyRoTqeD4tJYiVVgt6A3rN6rWn9RYhR9sBsGxji29LYWHuKKbdb1ev/1/*)".to_string()),
                     rpc_opts: RpcOpts {
                         address: "125.67.89.101:56678".to_string(),
-                        auth: ("user".to_string(), "password".to_string()),
+                        basic_auth: ("user".to_string(), "password".to_string()),
+                        cookie: Some("/home/user/.bitcoin/regtest/.cookie".to_string()),
                         skip_blocks: Some(5),
                     },
                 },
@@ -1734,7 +1742,8 @@ mod test {
                     #[cfg(feature = "rpc")]
                     rpc_opts: RpcOpts {
                         address: "127.0.0.1:18443".to_string(),
-                        auth: ("user".to_string(), "password".to_string()),
+                        basic_auth: ("user".to_string(), "password".to_string()),
+                        cookie: None,
                         skip_blocks: None,
                     },
                 },
@@ -1809,7 +1818,8 @@ mod test {
                     #[cfg(feature = "rpc")]
                     rpc_opts: RpcOpts {
                         address: "127.0.0.1:18443".to_string(),
-                        auth: ("user".to_string(), "password".to_string()),
+                        basic_auth: ("user".to_string(), "password".to_string()),
+                        cookie: None,
                         skip_blocks: None,
                     },
                 },
@@ -1871,7 +1881,8 @@ mod test {
                     #[cfg(feature = "rpc")]
                     rpc_opts: RpcOpts {
                         address: "127.0.0.1:18443".to_string(),
-                        auth: ("user".to_string(), "password".to_string()),
+                        basic_auth: ("user".to_string(), "password".to_string()),
+                        cookie: None,
                         skip_blocks: None,
                     },
                     #[cfg(any(feature="compact_filters", feature="electrum", feature="esplora"))]
@@ -1946,7 +1957,8 @@ mod test {
                     #[cfg(feature = "rpc")]
                     rpc_opts: RpcOpts {
                         address: "127.0.0.1:18443".to_string(),
-                        auth: ("user".to_string(), "password".to_string()),
+                        basic_auth: ("user".to_string(), "password".to_string()),
+                        cookie: None,
                         skip_blocks: None,
                     },
                 },