Skip to content

Commit 7734661

Browse files
import snarkvm traits
1 parent 63cc025 commit 7734661

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

wasm/src/types/field.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use wasm_bindgen::prelude::*;
3131
/// Field element.
3232
#[wasm_bindgen]
3333
#[derive(Clone, Debug, Eq, PartialEq)]
34-
pub struct Field(pub FieldNative);
34+
pub struct Field(FieldNative);
3535

3636
#[wasm_bindgen]
3737
impl Field {

wasm/src/types/integer.rs

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,19 @@ use crate::{
2222
use js_sys::{Array, Uint8Array};
2323
use std::{ops::Deref, str::FromStr};
2424
use wasm_bindgen::prelude::*;
25+
use snarkvm_console::prelude::{
26+
FromBytes, ToBytes, FromBits, ToBits,
27+
AbsChecked, AbsWrapped,
28+
AddWrapped, SubWrapped, MulWrapped, DivWrapped,
29+
RemWrapped, Pow, Rem,
30+
};
31+
2532

2633
macro_rules! impl_integer {
2734
($name:ident, $native:ty) => {
2835
#[wasm_bindgen]
2936
#[derive(Clone, Debug, Eq, PartialEq)]
30-
pub struct $name(pub $native);
37+
pub struct $name($native);
3138

3239
#[wasm_bindgen]
3340
impl $name {
@@ -126,36 +133,36 @@ macro_rules! impl_integer {
126133
Self(self.0.rem_wrapped(&other.0))
127134
}
128135

129-
/// Convert to Scalar.
130-
#[wasm_bindgen(js_name = "toScalar")]
131-
pub fn to_scalar(&self) -> crate::Scalar {
132-
crate::Scalar(self.0.to_scalar())
133-
}
134-
135-
/// Convert from Field.
136-
#[wasm_bindgen(js_name = "fromField")]
137-
pub fn from_field(field: &crate::Field) -> Result<$name, String> {
138-
<$native>::from_field(&field.0)
139-
.map(Self)
140-
.map_err(|e| e.to_string())
141-
}
142-
143-
/// Convert from Fields.
144-
#[wasm_bindgen(js_name = "fromFields")]
145-
pub fn from_fields(fields: js_sys::Array) -> Result<$name, String> {
146-
// Collect JsValue → Field
147-
let rust_fields: Result<Vec<_>, _> = fields.iter().map(|jsv| {
148-
149-
let field_str = jsv.as_string().ok_or("Expected string for Field")?;
150-
let field = FieldNative::from_str(&field_str).map_err(|e| e.to_string())?;
151-
Ok(field)
152-
}).collect();
153-
154-
let rust_fields = rust_fields?;
155-
<$native>::from_fields(&rust_fields)
156-
.map(Self)
157-
.map_err(|e| e.to_string())
158-
}
136+
// /// Convert to Scalar.
137+
// #[wasm_bindgen(js_name = "toScalar")]
138+
// pub fn to_scalar(&self) -> crate::Scalar {
139+
// crate::Scalar(self.0.to_scalar())
140+
// }
141+
142+
// /// Convert from Field.
143+
// #[wasm_bindgen(js_name = "fromField")]
144+
// pub fn from_field(field: &crate::Field) -> Result<$name, String> {
145+
// <$native>::from_field(&field.0)
146+
// .map(Self)
147+
// .map_err(|e| e.to_string())
148+
// }
149+
150+
// /// Convert from Fields.
151+
// #[wasm_bindgen(js_name = "fromFields")]
152+
// pub fn from_fields(fields: js_sys::Array) -> Result<$name, String> {
153+
// // Collect JsValue → Field
154+
// let rust_fields: Result<Vec<_>, _> = fields.iter().map(|jsv| {
155+
156+
// let field_str = jsv.as_string().ok_or("Expected string for Field")?;
157+
// let field = FieldNative::from_str(&field_str).map_err(|e| e.to_string())?;
158+
// Ok(field)
159+
// }).collect();
160+
161+
// let rust_fields = rust_fields?;
162+
// <$native>::from_fields(&rust_fields)
163+
// .map(Self)
164+
// .map_err(|e| e.to_string())
165+
// }
159166

160167
/// Clone.
161168
pub fn clone(&self) -> $name {

wasm/src/types/scalar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use wasm_bindgen::prelude::*;
3030
/// Scalar field element.
3131
#[wasm_bindgen]
3232
#[derive(Clone, Debug, Eq, PartialEq)]
33-
pub struct Scalar(pub ScalarNative);
33+
pub struct Scalar(ScalarNative);
3434

3535
#[wasm_bindgen]
3636
impl Scalar {

0 commit comments

Comments
 (0)