protoblock 0.1.6

Asynchronous Bitcoin block ingestion pipeline with built-in reorg handling, backpressure, and observability
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//! HTTP authentication helpers for wiring Bitcoin Core credentials into the
//! underlying `jsonrpsee` client builder.

use anyhow::{Context, Result};
use base64::{engine::general_purpose::STANDARD as BASE64_STANDARD, Engine as _};
use jsonrpsee::http_client::{HeaderMap, HeaderValue};

pub(crate) fn build_auth_headers(user: &str, password: &str) -> Result<HeaderMap> {
    let mut headers = HeaderMap::new();
    let credentials = format!("{user}:{password}");
    let encoded = BASE64_STANDARD.encode(credentials);
    let value = HeaderValue::from_str(&format!("Basic {encoded}"))
        .context("failed to build Authorization header")?;
    headers.insert("Authorization", value);
    Ok(headers)
}