Skip to content

Commit ba3cea3

Browse files
authored
Merge pull request #996 from ProvableHQ/feat/getter-function-for-view-key
Feat/getter function for view key
2 parents ff0775f + 4dea839 commit ba3cea3

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

wasm/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
"rimraf": "^6.0.1",
4949
"rollup": "^4.32.0"
5050
}
51-
}
51+
}

wasm/src/ledger/transition.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ impl Transition {
176176
Group::from(self.0.tpk())
177177
}
178178

179+
/// Get the transition view key of the transition.
180+
pub fn tvk(&self, view_key: &ViewKey) -> Field {
181+
let tpk = self.tpk();
182+
tpk.scalar_multiply(&view_key.to_scalar()).to_x_coordinate()
183+
}
184+
179185
/// Get the transition commitment of the transition.
180186
pub fn tcm(&self) -> Field {
181187
Field::from(self.0.tcm())
@@ -244,6 +250,7 @@ mod tests {
244250
pub const OUTPUT_RECORD_COMMITMENT: &str =
245251
"3771264214823666953346974490700157125043441681812666085949968314967709800215field";
246252
pub const TRANSITION: &str = r#"{"id":"au1naeu56spz0x0zct003sa8qgpzndy6nxj8rrcm7n0fehy9llcl5yscflt0k","program":"token_registry.aleo","function":"burn_private","inputs":[{"type":"record","id":"4569194627311410524427044648350523511369013276760031398859310110870190258038field","tag":"4584393733726099907383249165298083023636530416018938077800083356406243497342field"},{"type":"public","id":"4155661860779318196369465902681808025430867777096367712868886959018716227815field","value":"2853086u128"}],"outputs":[{"type":"record","id":"3771264214823666953346974490700157125043441681812666085949968314967709800215field","checksum":"17461704767783030875142836237730678349755524657182224909428747180538982740field","value":"record1qyqspwnlv6gfxx05yj7aw7z2dl44gyh06jrvgf42jux0dep33cy7jlsvqsrxzmt0w4h8ggcqqgqsqwdwr889h9fhnyclazs8yt26t6r5ua4qk7yksj7p40rz9846mzgrpp6x76m9de0kjezrqqpqyq9sj8x3qdmz6nal4j470a0wwcray54lffe3ya5u2zlpeq45lg4up3na8gul0vgrn3eced6dka4ax2ja85xzds4pmqf8csrn8ku5cv3qz8m90p6x2unwv9k97ct4w35x7unf0fshg6t0de0hyet3w45hyetyyvqqyqgq8djhghnte2w86qsdjaumy4zcux2fxszm3ej2956af8cpl2w95g9pqct4w35x7unf0fjkghm4de6xjmprqqpqzqxd6c782j0ny65ed2ckzp3vlx7cv8drslasq8kqpdzmjeyzal38qemw38x0axnz5t53fj6ttavh8l4jlfjdryc6mesd4w6uvpmzfsqqjvtu0xd"},{"type":"future","id":"2177527202823505610844479366424698260670813913152550670302738921219693374616field","value":"{\n program_id: token_registry.aleo,\n function_name: burn_private,\n arguments: [\n 3443843282313283355522573239085696902919850365217539366784739393210722344986field,\n 2853086u128,\n aleo1tjkv7vquk6yldxz53ecwsy5csnun43rfaknpkjc97v5223dlnyxsglv7nm,\n 5783861720504029593520331872442756678068735468923730684279741068753131773333field\n ]\n}"}],"tpk":"8426225807947287980879824833030089440060785195861154519084544916641544071836group","tcm":"3226339871444496417979841037237975848011574524309845233165930705339306709897field","scm":"6845182532650964173356391969005331370591444046632036068754797772530920467754field"}"#;
253+
pub const TEST_PRIVATE_KEY: &str = "APrivateKey1zkp6rE5FSWGD3jxrsAT64aZutFs3w6xvF8uQzGZKJEKsN8j";
247254

248255
#[test]
249256
fn transition_to_and_from_serialization() {
@@ -254,8 +261,12 @@ mod tests {
254261
assert!(Transition::from_bytes_le(bytes).is_ok());
255262
}
256263

257-
#[test]
264+
#[wasm_bindgen_test]
258265
fn test_transition_helpers() {
266+
// Create a view key from the test private key.
267+
let private_key = PrivateKey::from_str(TEST_PRIVATE_KEY).unwrap();
268+
let view_key = ViewKey::from_private_key(&private_key);
269+
259270
let transition = Transition::from_string(TRANSITION).unwrap();
260271
assert_eq!(transition.program_id(), "token_registry.aleo");
261272
assert_eq!(transition.function_name(), "burn_private");
@@ -274,6 +285,11 @@ mod tests {
274285
Field::from_string("6845182532650964173356391969005331370591444046632036068754797772530920467754field")
275286
.unwrap()
276287
);
288+
assert_eq!(
289+
transition.tvk(&view_key),
290+
Field::from_string("4386935145534748320784836619728244316439880324135120862336274251207085504468field")
291+
.unwrap()
292+
)
277293
}
278294

279295
#[wasm_bindgen_test]

0 commit comments

Comments
 (0)