Skip to content

Commit

Permalink
added support RFC compliant and non-compliant g1/g2 swapped beacons
Browse files Browse the repository at this point in the history
- replaced BLS12-381 lib with ZKcrypto's lib as it's lower level
- changed the interface almost completely, so users don't need to know
  whether they're using a chained or unchained network
  • Loading branch information
CluEleSsUK committed Aug 28, 2023
1 parent 9855eea commit 09b22d4
Show file tree
Hide file tree
Showing 10 changed files with 388 additions and 243 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
drand-client-rs.iml
12 changes: 5 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ edition = "2021"

[dependencies]
hex = { version = "0.4.3", features = ["serde"] }
url = "2.3.1"
reqwest = { version = "0.11", features = ["blocking"] }
json = "0.12.4"
bls-signatures = "0.13.0"
sha2 = "0.9"
bls12_381 = { version = "0.8.0", features = ["experimental"] }
thiserror = "1.0.38"
sha256 = "1.1.1"
serde = { version = "1.0.151", features = ["derive"] }
serde_json = "1.0.91"
serde = { version = "1.0.187", features = ["derive"] }
serde_json = "1.0.105"
reqwest = { version = "0.11.20", features = ["blocking", "json"] }
28 changes: 0 additions & 28 deletions src/bls.rs

This file was deleted.

3 changes: 2 additions & 1 deletion src/chain_info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use serde::Deserialize;
use crate::scheme::SchemeID;

#[derive(Deserialize, Debug, PartialEq, Clone)]
pub struct ChainInfo {
#[serde(alias = "schemeID")]
pub scheme_id: String,
pub scheme_id: SchemeID,
#[serde(with = "hex")]
pub public_key: Vec<u8>,
#[serde(with = "hex", alias = "hash")]
Expand Down
56 changes: 0 additions & 56 deletions src/chained.rs

This file was deleted.

28 changes: 13 additions & 15 deletions src/http.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
use reqwest::blocking::Client;
use reqwest::StatusCode;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum HttpError {
#[error("not found")]
NotFound,
#[error("unexpected")]
Unexpected,
}
use crate::{Transport, TransportError};

pub struct HttpTransport {
pub client: Client,
}

impl HttpTransport {
pub fn fetch(&self, url: &str) -> Result<String, HttpError> {
impl Transport for HttpTransport {
fn fetch(&self, url: &str) -> Result<String, TransportError> {
let res = self
.client
.get(url)
.send()
.map_err(|_| HttpError::Unexpected)?;
.map_err(|_| TransportError::Unexpected)?;

match res.status() {
StatusCode::OK => res.text().map_err(|_| HttpError::Unexpected),
StatusCode::OK => res.text().map_err(|_| TransportError::Unexpected),

StatusCode::NOT_FOUND => Err(HttpError::NotFound),
StatusCode::NOT_FOUND => Err(TransportError::NotFound),

_ => Err(HttpError::Unexpected),
_ => Err(TransportError::Unexpected),
}
}
}

pub fn new_http_transport() -> HttpTransport {
HttpTransport {
client: Client::new()
}
}
Loading

0 comments on commit 09b22d4

Please sign in to comment.