use crate::error::Result;
use crate::http::HttpClient;
use crate::types::{
SiweChallenge, Web3KeysList, Web3RevokeResult, Web3SignupResult, Web3SubscribeResult,
};
#[derive(Debug, Clone)]
pub struct Web3Resource {
http: HttpClient,
}
impl Web3Resource {
pub(crate) fn new(http: HttpClient) -> Self {
Self { http }
}
pub async fn challenge(&self, address: &str) -> Result<SiweChallenge> {
let body = serde_json::json!({ "address": address });
self.http.post("/v1/auth/web3/challenge", &body).await
}
pub async fn signup(&self, message: &str, signature: &str) -> Result<Web3SignupResult> {
let body = serde_json::json!({
"message": message,
"signature": signature,
});
self.http.post("/v1/web3/signup", &body).await
}
pub async fn list_keys(&self, message: &str, signature: &str) -> Result<Web3KeysList> {
let body = serde_json::json!({
"message": message,
"signature": signature,
});
self.http.post("/v1/web3/keys", &body).await
}
pub async fn revoke_key(
&self,
message: &str,
signature: &str,
key_id: &str,
) -> Result<Web3RevokeResult> {
let body = serde_json::json!({
"message": message,
"signature": signature,
"keyId": key_id,
});
self.http.post("/v1/web3/keys/revoke", &body).await
}
pub async fn subscribe(
&self,
tier: &str,
payment_signature: &str,
) -> Result<Web3SubscribeResult> {
let body = serde_json::json!({
"tier": tier,
"paymentSignature": payment_signature,
});
self.http.post("/v1/web3/subscribe", &body).await
}
}