Skip to content

Commit 2621182

Browse files
[Feature] Domain separators (#1105)
* Create domain separator in function in wasm * Give domain separator camelCase name * Add Record Scanner domain separator to SDK constants
1 parent 462eb89 commit 2621182

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

sdk/src/browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ export {
127127
PUBLIC_TRANSFER,
128128
PUBLIC_TRANSFER_AS_SIGNER,
129129
PUBLIC_TO_PRIVATE_TRANSFER,
130+
RECORD_DOMAIN,
130131
VALID_TRANSFER_TYPES,
131132
} from "./constants.js";
132133

sdk/src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,5 @@ export const PUBLIC_TO_PRIVATE_TRANSFER = new Set([
111111
"transfer_public_to_private",
112112
"transferPublicToPrivate",
113113
]);
114+
115+
export const RECORD_DOMAIN = "RecordScannerV0";

wasm/src/types/field.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use crate::{
1818
Plaintext,
1919
from_js_typed_array,
2020
to_bits_array_le,
21-
types::native::{FieldNative, LiteralNative, PlaintextNative},
21+
types::native::{CurrentNetwork, FieldNative, LiteralNative, PlaintextNative},
2222
};
23-
use snarkvm_console::prelude::{Double, FromBits, FromBytes, One, Pow, ToBits, ToBytes, Zero};
24-
use snarkvm_wasm::utilities::Uniform;
23+
use snarkvm_console::prelude::{Double, Environment, FromBits, FromBytes, One, Pow, ToBits, ToBytes, Zero};
24+
use snarkvm_wasm::{fields::PrimeField, utilities::Uniform};
2525

2626
use js_sys::{Array, Uint8Array};
2727
use std::{ops::Deref, str::FromStr, sync::OnceLock};
@@ -115,6 +115,14 @@ impl Field {
115115
Field(self.0 / other.0)
116116
}
117117

118+
/// Initializes a new field as a domain separator.
119+
#[wasm_bindgen(js_name = "newDomainSeparator")]
120+
pub fn new_domain_separator(&self, domain: &str) -> Field {
121+
let domain_native =
122+
FieldNative::new(<CurrentNetwork as Environment>::Field::from_bytes_le_mod_order(domain.as_bytes()));
123+
Field::from(domain_native)
124+
}
125+
118126
/// Power of a field element.
119127
pub fn pow(&self, other: &Field) -> Field {
120128
Field(self.0.pow(other.0))

0 commit comments

Comments
 (0)