MCPcopy Create free account
hub / github.com/ProvableHQ/sdk / test_ciphertext_decryption_method

Function test_ciphertext_decryption_method

wasm/src/programs/data/ciphertext.rs:323–369  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

321
322 #[wasm_bindgen_test]
323 fn test_ciphertext_decryption_method() {
324 // Construct the private key and view key associated with the transition.
325 let private_key = PrivateKey::from_string(PRIVATE_KEY).unwrap();
326 let view_key = ViewKey::from_private_key(&private_key);
327
328 // Construct the ciphertext to be decrypted and the transition it is a part of.
329 let transition = Transition::from_string(TRANSITION).unwrap();
330 let ciphertext = Ciphertext::from_string(CIPHERTEXT.to_string()).unwrap();
331
332 // Compute the tpk and tvk.
333 let tpk = transition.tpk();
334 let tvk = tpk.scalar_multiply(&view_key.to_scalar()).to_x_coordinate();
335
336 // Decrypt the ciphertext using the transition view key.
337 if CurrentNetwork::ID == 1 {
338 let decrypted_plaintext_1 = ciphertext
339 .decrypt_with_transition_info(view_key, tpk, transition.program_id(), transition.function_name(), 1)
340 .unwrap();
341 let decrypted_plaintext_2 = ciphertext
342 .decrypt_with_transition_view_key(tvk, transition.program_id(), transition.function_name(), 1)
343 .unwrap();
344
345 // Ensure the decrypted plaintexts are correct.
346 assert_eq!(decrypted_plaintext_1.to_string(), "2u32");
347 assert_eq!(decrypted_plaintext_2.to_string(), "2u32");
348 } else {
349 let private_key = PrivateKey::from_string(&get_env("PUZZLE_PK")).unwrap();
350 let ciphertext = Ciphertext::from_string(MAINNET_CIPHERTEXT.to_string()).unwrap();
351 let view_key = ViewKey::from_private_key(&private_key);
352 let tpk =
353 Group::from_string("4836727228112195507899959946473951966332108644709301619354443293014225839809group")
354 .unwrap();
355 let decrypted_plaintext = ciphertext
356 .decrypt_with_transition_info(
357 view_key,
358 tpk,
359 "puzzle_spinner_v002.aleo".to_string(),
360 "spin".to_string(),
361 2,
362 )
363 .unwrap();
364 assert_eq!(
365 decrypted_plaintext.to_string(),
366 crate::utilities::test::PUZZLE_SPINNER_V002_INPUT_2.to_string()
367 );
368 }
369 }
370}

Callers

nothing calls this directly

Calls 9

tpkMethod · 0.80
to_x_coordinateMethod · 0.80
scalar_multiplyMethod · 0.80
to_stringMethod · 0.45
to_scalarMethod · 0.45
program_idMethod · 0.45
function_nameMethod · 0.45

Tested by

no test coverage detected