Skip to content

Commit 49c13a6

Browse files
Add fmt lints and fix output types
1 parent 65dc230 commit 49c13a6

File tree

11 files changed

+125
-182
lines changed

11 files changed

+125
-182
lines changed

wasm/src/algorithms/bhp/bhp1024.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::{Field, types::native::{
18-
BHP1024Native,
19-
}, Scalar};
17+
use crate::{Field, Scalar, types::native::BHP1024Native};
2018
use snarkvm_console::algorithms::{Commit, Hash};
2119

2220
use js_sys::Array;
@@ -35,33 +33,24 @@ impl BHP1024 {
3533
/// Hash an array of booleans.
3634
pub fn hash(&self, input: Array) -> Result<Field, String> {
3735
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
38-
let input = input.to_vec()
36+
let input = input
37+
.to_vec()
3938
.iter()
40-
.map(|x| x
41-
.as_bool()
42-
.ok_or_else(|| "Input must be a boolean array".to_string())
43-
)
39+
.map(|x| x.as_bool().ok_or_else(|| "Input must be a boolean array".to_string()))
4440
.collect::<Result<Vec<bool>, String>>()?;
4541

46-
47-
self.0.hash(&input)
48-
.map(|field| Field::from(field))
49-
.map_err(|e| e.to_string())
42+
self.0.hash(&input).map(|field| Field::from(field)).map_err(|e| e.to_string())
5043
}
5144

5245
/// Commit to an array of booleans.
5346
pub fn commit(&self, input: Array, randomizer: Scalar) -> Result<Field, String> {
5447
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
55-
let input = input.to_vec()
48+
let input = input
49+
.to_vec()
5650
.iter()
57-
.map(|x| x
58-
.as_bool()
59-
.ok_or_else(|| "Input must be a boolean array".to_string())
60-
)
51+
.map(|x| x.as_bool().ok_or_else(|| "Input must be a boolean array".to_string()))
6152
.collect::<Result<Vec<bool>, String>>()?;
6253

63-
self.0.commit(&input, &randomizer)
64-
.map(|field| Field::from(field))
65-
.map_err(|e| e.to_string())
54+
self.0.commit(&input, &randomizer).map(|field| Field::from(field)).map_err(|e| e.to_string())
6655
}
67-
}
56+
}

wasm/src/algorithms/bhp/bhp256.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::{Field, types::native::{
18-
BHP256Native,
19-
}, Scalar};
17+
use crate::{Field, Scalar, types::native::BHP256Native};
2018
use snarkvm_console::algorithms::{Commit, Hash};
2119

2220
use js_sys::Array;
@@ -35,33 +33,24 @@ impl BHP256 {
3533
/// Hash an array of booleans.
3634
pub fn hash(&self, input: Array) -> Result<Field, String> {
3735
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
38-
let input = input.to_vec()
36+
let input = input
37+
.to_vec()
3938
.iter()
40-
.map(|x| x
41-
.as_bool()
42-
.ok_or_else(|| "Input must be a boolean array".to_string())
43-
)
39+
.map(|x| x.as_bool().ok_or_else(|| "Input must be a boolean array".to_string()))
4440
.collect::<Result<Vec<bool>, String>>()?;
4541

46-
47-
self.0.hash(&input)
48-
.map(|field| Field::from(field))
49-
.map_err(|e| e.to_string())
42+
self.0.hash(&input).map(|field| Field::from(field)).map_err(|e| e.to_string())
5043
}
5144

5245
/// Commit to an array of booleans.
5346
pub fn commit(&self, input: Array, randomizer: Scalar) -> Result<Field, String> {
5447
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
55-
let input = input.to_vec()
48+
let input = input
49+
.to_vec()
5650
.iter()
57-
.map(|x| x
58-
.as_bool()
59-
.ok_or_else(|| "Input must be a boolean array".to_string())
60-
)
51+
.map(|x| x.as_bool().ok_or_else(|| "Input must be a boolean array".to_string()))
6152
.collect::<Result<Vec<bool>, String>>()?;
6253

63-
self.0.commit(&input, &randomizer)
64-
.map(|field| Field::from(field))
65-
.map_err(|e| e.to_string())
54+
self.0.commit(&input, &randomizer).map(|field| Field::from(field)).map_err(|e| e.to_string())
6655
}
67-
}
56+
}

wasm/src/algorithms/bhp/bhp512.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::{Field, types::native::{
18-
BHP512Native,
19-
}, Scalar};
17+
use crate::{Field, Scalar, types::native::BHP512Native};
2018
use snarkvm_console::algorithms::{Commit, Hash};
2119

2220
use js_sys::Array;
@@ -35,33 +33,24 @@ impl BHP512 {
3533
/// Hash an array of booleans.
3634
pub fn hash(&self, input: Array) -> Result<Field, String> {
3735
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
38-
let input = input.to_vec()
36+
let input = input
37+
.to_vec()
3938
.iter()
40-
.map(|x| x
41-
.as_bool()
42-
.ok_or_else(|| "Input must be a boolean array".to_string())
43-
)
39+
.map(|x| x.as_bool().ok_or_else(|| "Input must be a boolean array".to_string()))
4440
.collect::<Result<Vec<bool>, String>>()?;
4541

46-
47-
self.0.hash(&input)
48-
.map(|field| Field::from(field))
49-
.map_err(|e| e.to_string())
42+
self.0.hash(&input).map(|field| Field::from(field)).map_err(|e| e.to_string())
5043
}
5144

5245
/// Commit to an array of booleans.
5346
pub fn commit(&self, input: Array, randomizer: Scalar) -> Result<Field, String> {
5447
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
55-
let input = input.to_vec()
48+
let input = input
49+
.to_vec()
5650
.iter()
57-
.map(|x| x
58-
.as_bool()
59-
.ok_or_else(|| "Input must be a boolean array".to_string())
60-
)
51+
.map(|x| x.as_bool().ok_or_else(|| "Input must be a boolean array".to_string()))
6152
.collect::<Result<Vec<bool>, String>>()?;
6253

63-
self.0.commit(&input, &randomizer)
64-
.map(|field| Field::from(field))
65-
.map_err(|e| e.to_string())
54+
self.0.commit(&input, &randomizer).map(|field| Field::from(field)).map_err(|e| e.to_string())
6655
}
67-
}
56+
}

wasm/src/algorithms/bhp/bhp768.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::{Field, types::native::{
18-
BHP768Native,
19-
}, Scalar};
17+
use crate::{Field, Scalar, types::native::BHP768Native};
2018
use snarkvm_console::algorithms::{Commit, Hash};
2119

2220
use js_sys::Array;
@@ -35,33 +33,24 @@ impl BHP768 {
3533
/// Hash an array of booleans.
3634
pub fn hash(&self, input: Array) -> Result<Field, String> {
3735
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
38-
let input = input.to_vec()
36+
let input = input
37+
.to_vec()
3938
.iter()
40-
.map(|x| x
41-
.as_bool()
42-
.ok_or_else(|| "Input must be a boolean array".to_string())
43-
)
39+
.map(|x| x.as_bool().ok_or_else(|| "Input must be a boolean array".to_string()))
4440
.collect::<Result<Vec<bool>, String>>()?;
4541

46-
47-
self.0.hash(&input)
48-
.map(|field| Field::from(field))
49-
.map_err(|e| e.to_string())
42+
self.0.hash(&input).map(|field| Field::from(field)).map_err(|e| e.to_string())
5043
}
5144

5245
/// Commit to an array of booleans.
5346
pub fn commit(&self, input: Array, randomizer: Scalar) -> Result<Field, String> {
5447
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
55-
let input = input.to_vec()
48+
let input = input
49+
.to_vec()
5650
.iter()
57-
.map(|x| x
58-
.as_bool()
59-
.ok_or_else(|| "Input must be a boolean array".to_string())
60-
)
51+
.map(|x| x.as_bool().ok_or_else(|| "Input must be a boolean array".to_string()))
6152
.collect::<Result<Vec<bool>, String>>()?;
6253

63-
self.0.commit(&input, &randomizer)
64-
.map(|field| Field::from(field))
65-
.map_err(|e| e.to_string())
54+
self.0.commit(&input, &randomizer).map(|field| Field::from(field)).map_err(|e| e.to_string())
6655
}
67-
}
56+
}

wasm/src/algorithms/bhp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

17+
pub mod bhp1024;
1718
pub mod bhp256;
1819
pub mod bhp512;
1920
pub mod bhp768;
20-
pub mod bhp1024;

wasm/src/algorithms/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ pub mod bhp;
1818
pub use bhp::*;
1919

2020
pub mod poseidon;
21-
pub use poseidon::*;
21+
pub use poseidon::*;

wasm/src/algorithms/poseidon/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ pub mod poseidon4;
2121
pub use poseidon4::*;
2222

2323
pub mod poseidon8;
24-
pub use poseidon8::*;
24+
pub use poseidon8::*;

wasm/src/algorithms/poseidon/poseidon2.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::{Field, types::native::{
18-
Poseidon2Native, FieldNative,
19-
}, Scalar};
17+
use crate::{
18+
Field,
19+
Group,
20+
Scalar,
21+
types::native::{FieldNative, Poseidon2Native},
22+
};
2023
use snarkvm_console::algorithms::{Hash, HashToGroup, HashToScalar};
2124

2225
use js_sys::Array;
23-
use wasm_bindgen::convert::TryFromJsValue;
24-
use wasm_bindgen::prelude::*;
26+
use wasm_bindgen::{convert::TryFromJsValue, prelude::*};
2527

2628
#[wasm_bindgen]
2729
pub struct Poseidon2(Poseidon2Native);
@@ -36,48 +38,42 @@ impl Poseidon2 {
3638
/// Hash an array of fields.
3739
pub fn hash(&self, input: Array) -> Result<Field, String> {
3840
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
39-
let input = input.to_vec()
41+
let input = input
42+
.to_vec()
4043
.into_iter()
41-
.map(|x| Field::try_from_js_value(x)
42-
.map(|x| *x)
43-
.map_err(|_| "Input must be an array of fields".to_string())
44-
)
44+
.map(|x| {
45+
Field::try_from_js_value(x).map(|x| *x).map_err(|_| "Input must be an array of fields".to_string())
46+
})
4547
.collect::<Result<Vec<FieldNative>, String>>()?;
4648

47-
self.0.hash(&input)
48-
.map(|field| Field::from(field))
49-
.map_err(|e| e.to_string())
49+
self.0.hash(&input).map(|field| Field::from(field)).map_err(|e| e.to_string())
5050
}
5151

5252
/// Hash to a scalar.
5353
pub fn hash_to_scalar(&self, input: Array) -> Result<Scalar, String> {
5454
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
55-
let input = input.to_vec()
55+
let input = input
56+
.to_vec()
5657
.into_iter()
57-
.map(|x| Field::try_from_js_value(x)
58-
.map(|x| *x)
59-
.map_err(|_| "Input must be an array of fields".to_string())
60-
)
58+
.map(|x| {
59+
Field::try_from_js_value(x).map(|x| *x).map_err(|_| "Input must be an array of fields".to_string())
60+
})
6161
.collect::<Result<Vec<FieldNative>, String>>()?;
6262

63-
self.0.hash_to_scalar(&input)
64-
.map(|scalar| Scalar::from(scalar))
65-
.map_err(|e| e.to_string())
63+
self.0.hash_to_scalar(&input).map(|scalar| Scalar::from(scalar)).map_err(|e| e.to_string())
6664
}
6765

6866
/// Hash to group.
69-
pub fn hash_to_group(&self, input: Array) -> Result<Field, String> {
67+
pub fn hash_to_group(&self, input: Array) -> Result<Group, String> {
7068
// Convert an array of booleans to a vector of booleans, failing if any values aren't booleans.
71-
let input = input.to_vec()
69+
let input = input
70+
.to_vec()
7271
.into_iter()
73-
.map(|x| Field::try_from_js_value(x)
74-
.map(|x| *x)
75-
.map_err(|_| "Input must be an array of fields".to_string())
76-
)
72+
.map(|x| {
73+
Field::try_from_js_value(x).map(|x| *x).map_err(|_| "Input must be an array of fields".to_string())
74+
})
7775
.collect::<Result<Vec<FieldNative>, String>>()?;
7876

79-
self.0.hash_to_group(&input)
80-
.map(|field| Field::from(field))
81-
.map_err(|e| e.to_string())
77+
self.0.hash_to_group(&input).map(|group| Group::from(group)).map_err(|e| e.to_string())
8278
}
83-
}
79+
}

0 commit comments

Comments
 (0)