Skip to content

Commit 815d461

Browse files
implement to scalar
1 parent 8f0c141 commit 815d461

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

wasm/src/types/integer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ macro_rules! impl_integer {
146146
Self(self.0.rem_wrapped(&other.0))
147147
}
148148

149-
// /// Convert to Scalar.
150-
// #[wasm_bindgen(js_name = "toScalar")]
151-
// pub fn to_scalar(&self) -> crate::Scalar {
152-
// crate::Scalar(self.0.to_scalar())
153-
// }
149+
/// Convert to Scalar.
150+
#[wasm_bindgen(js_name = "toScalar")]
151+
pub fn to_scalar(&self) -> crate::Scalar {
152+
crate::Scalar::from_native(self.0.to_scalar())
153+
}
154154

155155
// /// Convert from Field.
156156
// #[wasm_bindgen(js_name = "fromField")]

wasm/src/types/scalar.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ impl Scalar {
4747
self.0.to_string()
4848
}
4949

50+
/// Constructs a Scalar from its native representation that can be exposed to JavaScript.
51+
pub(crate) fn from_native(native: ScalarNative) -> Self {
52+
Scalar(native)
53+
}
54+
5055
/// Create a scalar element from a Uint8Array of left endian bytes.
5156
#[wasm_bindgen(js_name = "fromBytesLe")]
5257
pub fn from_bytes_le(bytes: &Uint8Array) -> Result<Scalar, String> {

0 commit comments

Comments
 (0)