Skip to content

Commit 52f7efd

Browse files
add toPlaintext
1 parent 254a871 commit 52f7efd

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

wasm/src/types/integer.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use crate::{from_js_typed_array, to_bits_array_le, types::native::*};
1818
// use crate::types::{U8, U16, U32};
1919
use js_sys::{Array, Uint8Array};
20+
use once_cell::sync::OnceCell;
2021
use snarkvm_console::prelude::{
2122
AbsChecked,
2223
AbsWrapped,
@@ -34,6 +35,7 @@ use snarkvm_console::prelude::{
3435
ToBits,
3536
ToBytes,
3637
};
38+
use crate::Plaintext;
3739
use std::{ops::Deref, str::FromStr};
3840
use wasm_bindgen::prelude::*;
3941

@@ -158,6 +160,12 @@ macro_rules! impl_integer {
158160
self.0.to_scalar().into()
159161
}
160162

163+
/// Convert to plaintext.
164+
#[wasm_bindgen(js_name = "toPlaintext")]
165+
pub fn to_plaintext(&self) -> Plaintext {
166+
Plaintext::from(PlaintextNative::Literal(LiteralNative::Integer(self.0), OnceCell::new()))
167+
}
168+
161169
/// Convert from Field.
162170
#[wasm_bindgen(js_name = "fromField")]
163171
pub fn from_field(field: &crate::Field) -> Result<$name, String> {

0 commit comments

Comments
 (0)