-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from Duddino/custom-url
Add ability to use different URL than duddino.com for sapling params
- Loading branch information
Showing
6 changed files
with
73 additions
and
65 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use pivx_proofs::prover::LocalTxProver; | ||
use reqwest::Client; | ||
use std::error::Error; | ||
use tokio::sync::OnceCell; | ||
use wasm_bindgen::prelude::*; | ||
|
||
static PROVER: OnceCell<LocalTxProver> = OnceCell::const_new(); | ||
|
||
pub async fn get_prover() -> &'static LocalTxProver { | ||
let default_urls = &["https://https://pivxla.bz", "https://duddino.com"]; | ||
for url in default_urls { | ||
if let Ok(prover) = get_with_url(url).await { | ||
return prover; | ||
} | ||
} | ||
panic!("Failed to download prover"); | ||
} | ||
|
||
/** | ||
* gets prover using the specified url. If the prover has already been downloaded | ||
* no request will be made | ||
*/ | ||
pub async fn get_with_url(url: &str) -> Result<&'static LocalTxProver, Box<dyn Error>> { | ||
PROVER | ||
.get_or_try_init(|| async { | ||
let c = Client::new(); | ||
let out_url = format!("{}/sapling-output.params", url); | ||
let spend_url = format!("{}/sapling-spend.params", url); | ||
let sapling_output_bytes = c.get(&out_url).send().await?.bytes().await?; | ||
let sapling_spend_bytes = c.get(&spend_url).send().await?.bytes().await?; | ||
|
||
if sha256::digest(&*sapling_output_bytes) | ||
!= "2f0ebbcbb9bb0bcffe95a397e7eba89c29eb4dde6191c339db88570e3f3fb0e4" | ||
{ | ||
Err("Sha256 does not match for sapling output")?; | ||
} | ||
|
||
if sha256::digest(&*sapling_spend_bytes) | ||
!= "8e48ffd23abb3a5fd9c5589204f32d9c31285a04b78096ba40a79b75677efc13" | ||
{ | ||
Err("Sha256 does not match for sapling spend")?; | ||
} | ||
Ok(LocalTxProver::from_bytes( | ||
&sapling_spend_bytes, | ||
&sapling_output_bytes, | ||
)) | ||
}) | ||
.await | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn load_prover() -> bool { | ||
get_prover().await; | ||
true | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub async fn load_prover_with_url(url: &str) -> bool { | ||
get_with_url(url).await.is_ok() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters