Skip to content

Commit 9612427

Browse files
Merge pull request #1089 from ProvableHQ/feat/sender-ciphertext
[Feature] Decrypt Sender Ciphertext
2 parents 3d5f9e2 + 14cdf16 commit 9612427

File tree

10 files changed

+346
-142
lines changed

10 files changed

+346
-142
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ jobs:
114114
115115
template-node-ts:
116116
executor: rust-node
117-
resource_class: xlarge
118117
steps:
119118
- setup-sdk
120119
- run:

create-leo-app/template-node/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Account, AleoKeyProvider, AleoKeyProviderParams, initThreadPool, Program
22

33
import * as process from "node:process";
44

5-
await initThreadPool();
5+
// await initThreadPool();
66

77
const programName = "hello_hello.aleo"
88

@@ -78,12 +78,12 @@ async function remoteProgramExecution(programName, functionName, inputs) {
7878
console.log("Resulting transaction")
7979
}
8080

81-
const start = Date.now();
82-
console.log("Starting local execute!");
83-
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
84-
console.log("Local execute finished!", Date.now() - start);
85-
86-
console.log("Starting remote execute");
87-
const auctionTicket = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n auction: {\n starting_bid: 1000u64.private,\n name: 35399035103896773146887283777field.private,\n item: {\n id: 2711777270856651361584090827715149911900945757872672230578290769243507539617field.private,\n offchain_data: [\n 988474637487226873250021955104421895943605632761729320744454284792013483886field.private,\n 1018595503607749325560812785092303652308909717269501712857428145700763090203field.private,\n 1866354748676879328546224733327549476838379876255164483333908854380501015560field.private,\n 17649382157field.private\n ]\n }\n },\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n settings: {\n auction_privacy: 1field.private,\n bid_types_accepted: 2field.private\n },\n _nonce: 3369967065799891136255379173673996324404175734426175774361522329924029135340group.public,\n _version: 0u8.public\n}";
88-
const privateBid = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n bid: {\n amount: 50000u64.private,\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n bid_public_key: 7957235921075215080384898776027711008106448988910535634014947882222019778701group.private\n },\n bid_id: 7560059211950188901208146469854635725646381155467709838136796808753178551929field.private,\n _nonce: 6603986437928263590097393830337419611438422585243442121397081002092267314422group.public,\n _version: 0u8.public\n}";
89-
await remoteProgramExecution("private_auction_test_3.aleo", "select_winner_private", [auctionTicket, privateBid]);
81+
// const start = Date.now();
82+
// console.log("Starting local execute!");
83+
// await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
84+
// console.log("Local execute finished!", Date.now() - start);
85+
//
86+
// console.log("Starting remote execute");
87+
// const auctionTicket = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n auction: {\n starting_bid: 1000u64.private,\n name: 35399035103896773146887283777field.private,\n item: {\n id: 2711777270856651361584090827715149911900945757872672230578290769243507539617field.private,\n offchain_data: [\n 988474637487226873250021955104421895943605632761729320744454284792013483886field.private,\n 1018595503607749325560812785092303652308909717269501712857428145700763090203field.private,\n 1866354748676879328546224733327549476838379876255164483333908854380501015560field.private,\n 17649382157field.private\n ]\n }\n },\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n settings: {\n auction_privacy: 1field.private,\n bid_types_accepted: 2field.private\n },\n _nonce: 3369967065799891136255379173673996324404175734426175774361522329924029135340group.public,\n _version: 0u8.public\n}";
88+
// const privateBid = "{\n owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private,\n bid: {\n amount: 50000u64.private,\n auction_id: 4494702806735512695876583707511065751304542460719196393147692059573188109243field.private,\n bid_public_key: 7957235921075215080384898776027711008106448988910535634014947882222019778701group.private\n },\n bid_id: 7560059211950188901208146469854635725646381155467709838136796808753178551929field.private,\n _nonce: 6603986437928263590097393830337419611438422585243442121397081002092267314422group.public,\n _version: 0u8.public\n}";
89+
// await remoteProgramExecution("private_auction_test_3.aleo", "select_winner_private", [auctionTicket, privateBid]);

sdk/tests/data/records.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/// V1 credits.aleo record.
2+
const CREDITS_RECORD_V1 = "{ owner: aleo12a4wll9ax6w5355jph0dr5wt2vla5sss2t4cnch0tc3vzh643v8qcfvc7a.private, microcredits: 1000000u64.private, _nonce: 3634848344765318974603121890869676775499130077229666060613233255327643175219group.public, _version: 1u8.public }";
3+
4+
/// Record view key for the V1 credits.aleo record.
5+
const CREDITS_RECORD_VIEW_KEY = "5237002936265850807349726649400053591020997883662246784632368923777787639801field";
6+
7+
/// Sender ciphertext of the credits.aleo record.
8+
const CREDITS_SENDER_CIPHERTEXT = "1182590395568997043375432557467567048762179115999922880321493200728848194550field";
9+
10+
/// Sender plaintext of the credits.aleo record.
11+
const CREDITS_SENDER_PLAINTEXT = "aleo1j92w9mhqznj2hvufad796y8suykjppk7f6n6xmncmktfm95vggzqx4sjlh";
12+
113
// Ciphertext records
214
const RECORD_CIPHERTEXT_STRING = "record1qyqsqpe2szk2wwwq56akkwx586hkndl3r8vzdwve32lm7elvphh37rsyqyxx66trwfhkxun9v35hguerqqpqzqrtjzeu6vah9x2me2exkgege824sd8x2379scspmrmtvczs0d93qttl7y92ga0k0rsexu409hu3vlehe3yxjhmey3frh2z5pxm5cmxsv4un97q";
315
const RECORD_CIPHERTEXT_STRING_COPY = "record1qyqsqpe2szk2wwwq56akkwx586hkndl3r8vzdwve32lm7elvphh37rsyqyxx66trwfhkxun9v35hguerqqpqzqrtjzeu6vah9x2me2exkgege824sd8x2379scspmrmtvczs0d93qttl7y92ga0k0rsexu409hu3vlehe3yxjhmey3frh2z5pxm5cmxsv4un97q";
@@ -16,6 +28,10 @@ const VIEW_KEY_STRING = "AViewKey1ccEt8A2Ryva5rxnKcAbn7wgTaTsb79tzkKHFpeKsm9NX";
1628
const RECORD_VIEW_KEY_STRING = "4445718830394614891114647247073357094867447866913203502139893824059966201724field";
1729

1830
export {
31+
CREDITS_RECORD_V1,
32+
CREDITS_RECORD_VIEW_KEY,
33+
CREDITS_SENDER_CIPHERTEXT,
34+
CREDITS_SENDER_PLAINTEXT,
1935
RECORD_CIPHERTEXT_STRING,
2036
RECORD_CIPHERTEXT_STRING_COPY,
2137
RECORD_CIPHERTEXT_STRING_NOT_OWNED,

sdk/tests/network-client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ describe("NodeConnection", () => {
368368
}
369369
});
370370

371-
it.only("should throw for a malformed tx ID", async () => {
371+
it("should throw for a malformed tx ID", async () => {
372372
const connection = new AleoNetworkClient(host);
373373
try {
374374
await connection.waitForTransactionConfirmation(invalidTx);

sdk/tests/wasm.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import {
1212
beaconPrivateKeyString
1313
} from "./data/account-data.js";
1414
import {
15+
CREDITS_RECORD_V1,
16+
CREDITS_RECORD_VIEW_KEY,
17+
CREDITS_SENDER_CIPHERTEXT,
18+
CREDITS_SENDER_PLAINTEXT,
1519
RECORD_CIPHERTEXT_STRING,
1620
RECORD_CIPHERTEXT_STRING_COPY,
1721
RECORD_CIPHERTEXT_STRING_NOT_OWNED,
@@ -20,6 +24,7 @@ import {
2024
RECORD_VIEW_KEY_STRING,
2125
VIEW_KEY_STRING,
2226
} from "./data/records.js";
27+
import process from "node:process";
2328

2429
describe('WASM Objects', () => {
2530
describe('Address', () => {
@@ -483,6 +488,29 @@ describe('WASM Objects', () => {
483488
// Ensure the decrypted record is the same as the plaintext
484489
expect(decryptedRecords[0].toString()).equal(recordPlaintextCopy.toString());
485490
});
491+
it('can decrypt sender ciphertexts', () => {
492+
// Get the private key corresponding to the record.
493+
const private_key = PrivateKey.from_string(<string>process.env["PUZZLE_PK"]);
494+
const view_key = ViewKey.from_private_key(private_key);
495+
496+
// Construct the record and the sender ciphertext.
497+
const record = RecordPlaintext.fromString(CREDITS_RECORD_V1);
498+
const record_view_key = Field.fromString(CREDITS_RECORD_VIEW_KEY);
499+
const sender_ciphertext = Field.fromString(CREDITS_SENDER_CIPHERTEXT);
500+
501+
// Decrypt the sender ciphertext using the record object and ensure it's from the expected address.
502+
let sender = record.decryptSender(view_key, sender_ciphertext);
503+
expect(sender.to_string()).to.equal(CREDITS_SENDER_PLAINTEXT);
504+
505+
// Decrypt the sender ciphertext using the EncryptionToolkit function and ensure it's from the expected address.
506+
sender = EncryptionToolkit.decryptSender(view_key, record, sender_ciphertext);
507+
expect(sender.to_string()).to.equal(CREDITS_SENDER_PLAINTEXT);
508+
509+
// Decrypt the sender ciphertext using only the record view key and ensure it's from the expected address.
510+
sender = EncryptionToolkit.decryptSenderWithRvk(record_view_key, sender_ciphertext);
511+
expect(sender.to_string()).to.equal(CREDITS_SENDER_PLAINTEXT);
512+
})
513+
it('can decryption')
486514
});
487515
describe('VerifyingKey', () => {
488516
it('can get the number of constraints', async () => {

0 commit comments

Comments
 (0)