Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NIP98 auth for nostr.build #1191

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions mutiny-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ use ::nostr::prelude::rand::rngs::OsRng;
use ::nostr::prelude::ZapRequestData;
#[cfg(target_arch = "wasm32")]
use ::nostr::Tag;
use ::nostr::{EventBuilder, EventId, JsonUtil, Keys, Kind};
use ::nostr::{EventBuilder, EventId, HttpMethod, JsonUtil, Keys, Kind};
use async_lock::RwLock;
use bdk_chain::ConfirmationTime;
use bip39::Mnemonic;
Expand Down Expand Up @@ -2499,11 +2499,26 @@ impl<S: MutinyStorage> MutinyWallet<S> {
/// Uploads a profile pic to nostr.build and returns the uploaded file's URL
pub async fn upload_profile_pic(&self, image_bytes: Vec<u8>) -> Result<String, MutinyError> {
let client = reqwest::Client::new();

let hash = sha256::Hash::hash(&image_bytes);
let form = Form::new().part("fileToUpload", Part::bytes(image_bytes));

let url = "https://nostr.build/api/v2/upload/profile";

let nip98 = ::nostr::nips::nip98::HttpData {
url: url.into(),
method: HttpMethod::POST,
payload: Some(hash),
};
let event_builder = EventBuilder::http_auth(nip98);
let event = self.nostr.client.sign_event_builder(event_builder).await?;

let res: NostrBuildResult = client
.post("https://nostr.build/api/v2/upload/profile")
.post(url)
.multipart(form)
.header(
"Authorization",
format!("Nostr {}", base64::encode(event.as_json().as_bytes())),
)
.send()
.await
.map_err(|e| {
Expand Down
Loading