use crate::Url;
use nostr_sdk::prelude::*;

use base64;
use bitcoin::hashes::sha256::Hash as Sha256Hash;

pub async fn build_nip98_auth_event(
    keys: &Keys,
    url: Url,
    hash: Sha256Hash,
) -> Event {
    let data = HttpData::new(url.clone(), HttpMethod::POST).payload(hash);

    EventBuilder::http_auth(data).sign(keys).await.unwrap()
}

pub async fn build_nip98_auth_event_b64(
    keys: &Keys,
    url: Url,
    hash: Sha256Hash,
) -> String {
    let event = build_nip98_auth_event(keys, url.clone(), hash).await;

    #[allow(deprecated)]
    base64::encode(event.as_json())
}
