Skip to content

Commit 288f97e

Browse files
Export GraphKey and expose toField methods on Scalars and View Keys
1 parent 9d5b843 commit 288f97e

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

sdk/src/browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export {
7272
ExecutionResponse,
7373
EncryptionToolkit,
7474
Field,
75+
GraphKey,
7576
Group,
7677
I8,
7778
I16,

sdk/src/wasm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export {
1313
Execution,
1414
ExecutionResponse,
1515
Field,
16+
GraphKey,
1617
Group,
1718
I8,
1819
I16,

wasm/src/account/view_key.rs

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

17-
use super::{Address, PrivateKey};
18-
use crate::record::RecordCiphertext;
19-
20-
use crate::{Scalar, types::native::ViewKeyNative};
17+
use crate::{Address, Field, PrivateKey, RecordCiphertext, Scalar, types::native::ViewKeyNative};
2118
use core::{convert::TryFrom, fmt, ops::Deref, str::FromStr};
19+
use snarkvm_console::prelude::ToField;
2220
use wasm_bindgen::prelude::*;
2321

2422
#[wasm_bindgen]
@@ -63,6 +61,12 @@ impl ViewKey {
6361
Scalar::from(*self.0)
6462
}
6563

64+
/// Cast the view key to a field.
65+
#[wasm_bindgen(js_name = toField)]
66+
pub fn to_field(&self) -> Result<Field, String> {
67+
Ok(Field::from(self.0.to_field().map_err(|e| e.to_string())?))
68+
}
69+
6670
/// Decrypt a record ciphertext with a view key
6771
///
6872
/// @param {string} ciphertext String representation of a record ciphertext

wasm/src/types/scalar.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
// along with the Provable SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

1717
use crate::{
18+
Field,
1819
Plaintext,
1920
from_js_typed_array,
2021
to_bits_array_le,
2122
types::native::{LiteralNative, PlaintextNative, ScalarNative},
2223
};
23-
use snarkvm_console::prelude::{Double, FromBits, FromBytes, One, Pow, ToBits, ToBytes, Uniform, Zero};
24+
use snarkvm_console::prelude::{Double, FromBits, FromBytes, One, Pow, ToBits, ToBytes, ToField, Uniform, Zero};
2425

2526
use js_sys::{Array, Uint8Array};
2627
use std::{ops::Deref, str::FromStr, sync::OnceLock};
@@ -81,6 +82,12 @@ impl Scalar {
8182
Plaintext::from(PlaintextNative::Literal(LiteralNative::Scalar(self.0), OnceLock::new()))
8283
}
8384

85+
/// Cast the scalar element to a field element.
86+
#[wasm_bindgen(js_name = "toField")]
87+
pub fn to_field(&self) -> Result<Field, String> {
88+
Ok(Field::from(self.0.to_field().map_err(|e| e.to_string())?))
89+
}
90+
8491
/// Clone the scalar element.
8592
#[allow(clippy::should_implement_trait)]
8693
pub fn clone(&self) -> Scalar {

0 commit comments

Comments
 (0)