Skip to content

Commit c4c1847

Browse files
committed
all tests pass
1 parent 7975106 commit c4c1847

File tree

3 files changed

+18
-26
lines changed

3 files changed

+18
-26
lines changed

sdk/tests/wasm.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ describe('WASM Objects', () => {
450450
const recordCiphertextNotOwned = RecordCiphertext.fromString(recordCiphertextStringNotOwned);
451451
const recordCiphertextNotOwned2 = RecordCiphertext.fromString(recordCiphertextStringNotOwned2);
452452
const recordCiphertextArray = [recordCiphertext, recordCiphertextNotOwned, recordCiphertextNotOwned2];
453+
// Create copies of the record ciphertexts
454+
const recordCiphertextCopy1 = RecordCiphertext.fromString(recordCiphertextString);
455+
const recordCiphertextNotOwnedCopy1 = RecordCiphertext.fromString(recordCiphertextStringNotOwned);
456+
const recordCiphertextNotOwned2Copy1 = RecordCiphertext.fromString(recordCiphertextStringNotOwned2);
457+
const recordCiphertextArrayCopy = [recordCiphertextCopy1, recordCiphertextNotOwnedCopy1, recordCiphertextNotOwned2Copy1];
453458
const recordPlaintextString = `{
454459
owner: aleo1j7qxyunfldj2lp8hsvy7mw5k8zaqgjfyr72x2gh3x4ewgae8v5gscf5jh3.private,
455460
microcredits: 1500000000000000u64.private,
@@ -482,7 +487,7 @@ owner: aleo1j7qxyunfldj2lp8hsvy7mw5k8zaqgjfyr72x2gh3x4ewgae8v5gscf5jh3.private,
482487
expect(ownedRecords[0].toString()).equal(recordCiphertextStringCopy.toString());
483488
});
484489
it('can decrypt a record ciphertext from an array of record ciphertexts', () => {
485-
const decryptedRecords = EncryptionToolkit.decryptOwnedRecords(viewKey, recordCiphertextArray);
490+
const decryptedRecords = EncryptionToolkit.decryptOwnedRecords(viewKey, recordCiphertextArrayCopy);
486491
// Ensure the decrypted record is the same as the plaintext
487492
expect(decryptedRecords[0].toString()).equal(recordPlaintextCopy.toString());
488493
});

wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@provablehq/wasm",
33
"version": "0.9.4",
4-
"type": "module",
4+
55
"description": "SnarkVM WASM binaries with javascript bindings",
66
"collaborators": [
77
"The Provable Team"

wasm/src/utilities/encrypt.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl EncryptionToolkit {
226226
// Use Rayon to parallelize the decryption process and store successful decryptions.
227227
let decrypted_records: Vec<RecordPlaintext> = records
228228
.par_iter()
229-
.filter_map(|record| match Self::try_decrypt_single_record(view_key, record) {
229+
.filter_map(|record| match try_decrypt_single_record(view_key, record) {
230230
Ok(plaintext) => Some(plaintext),
231231
Err(_) => None,
232232
})
@@ -252,33 +252,20 @@ impl EncryptionToolkit {
252252

253253
Ok(owned_records)
254254
}
255-
256-
// Private helper method within the impl block to decrypt
257-
fn try_decrypt_single_record(view_key: &ViewKey, record: &RecordCiphertext) -> Result<RecordPlaintext, String> {
258-
// Generate the record view key using the owner's view key
259-
let record_vk = EncryptionToolkit::generate_record_view_key(view_key, record)
260-
.map_err(|_| "Failed to generate record view key".to_string())?;
261-
262-
// Attempt to decrypt the record using the generated record view key
263-
let decryption_attempt = EncryptionToolkit::decrypt_record_symmetric_unchecked(&record_vk, record)
264-
.map_err(|_| "Failed to decrypt record".to_string())?;
265-
266-
Ok(decryption_attempt)
267-
}
268255
}
269256

270-
// // Private helper method within the impl block to decrypt
271-
// fn try_decrypt_single_record(view_key: &ViewKey, record: &RecordCiphertext) -> Result<RecordPlaintext, String> {
272-
// // Generate the record view key using the owner's view key
273-
// let record_vk = EncryptionToolkit::generate_record_view_key(view_key, record)
274-
// .map_err(|_| "Failed to generate record view key".to_string())?;
257+
// Private helper method within the impl block to decrypt
258+
fn try_decrypt_single_record(view_key: &ViewKey, record: &RecordCiphertext) -> Result<RecordPlaintext, String> {
259+
// Generate the record view key using the owner's view key
260+
let record_vk = EncryptionToolkit::generate_record_view_key(view_key, record)
261+
.map_err(|_| "Failed to generate record view key".to_string())?;
275262

276-
// // Attempt to decrypt the record using the generated record view key
277-
// let decryption_attempt = EncryptionToolkit::decrypt_record_symmetric_unchecked(&record_vk, record)
278-
// .map_err(|_| "Failed to decrypt record".to_string())?;
263+
// Attempt to decrypt the record using the generated record view key
264+
let decryption_attempt = EncryptionToolkit::decrypt_record_symmetric_unchecked(&record_vk, record)
265+
.map_err(|_| "Failed to decrypt record".to_string())?;
279266

280-
// Ok(decryption_attempt)
281-
// }
267+
Ok(decryption_attempt)
268+
}
282269

283270
#[cfg(test)]
284271
mod tests {

0 commit comments

Comments
 (0)