UNPKG

snarkyjs-elgamal

Version:

This repository implements Elgmal, a partial homomorphic encryption scheme originally described by [Taher Elgamal in 1985](https://caislab.kaist.ac.kr/lecture/2010/spring/cs548/basic/B02.pdf). This implementation includes the original version of Elgamal,

60 lines 2.48 kB
import { Add } from './Add'; import { isReady, shutdown, Field, Mina, PrivateKey, AccountUpdate, } from 'snarkyjs'; /* * This file specifies how to test the `Add` example smart contract. It is safe to delete this file and replace * with your own tests. * * See https://docs.minaprotocol.com/zkapps for more info. */ let proofsEnabled = false; describe('Add', () => { let deployerAccount, deployerKey, senderAccount, senderKey, zkAppAddress, zkAppPrivateKey, zkApp; beforeAll(async () => { await isReady; if (proofsEnabled) Add.compile(); }); beforeEach(() => { const Local = Mina.LocalBlockchain({ proofsEnabled }); Mina.setActiveInstance(Local); ({ privateKey: deployerKey, publicKey: deployerAccount } = Local.testAccounts[0]); ({ privateKey: senderKey, publicKey: senderAccount } = Local.testAccounts[1]); zkAppPrivateKey = PrivateKey.random(); zkAppAddress = zkAppPrivateKey.toPublicKey(); zkApp = new Add(zkAppAddress); }); afterAll(() => { // `shutdown()` internally calls `process.exit()` which will exit the running Jest process early. // Specifying a timeout of 0 is a workaround to defer `shutdown()` until Jest is done running all tests. // This should be fixed with https://github.com/MinaProtocol/mina/issues/10943 setTimeout(shutdown, 0); }); async function localDeploy() { const txn = await Mina.transaction(deployerAccount, () => { AccountUpdate.fundNewAccount(deployerAccount); zkApp.deploy(); }); await txn.prove(); // this tx needs .sign(), because `deploy()` adds an account update that requires signature authorization await txn.sign([deployerKey, zkAppPrivateKey]).send(); } it('generates and deploys the `Add` smart contract', async () => { await localDeploy(); const num = zkApp.num.get(); expect(num).toEqual(Field(1)); }); it('correctly updates the num state on the `Add` smart contract', async () => { await localDeploy(); // update transaction const txn = await Mina.transaction(senderAccount, () => { zkApp.update(); }); await txn.prove(); await txn.sign([senderKey]).send(); const updatedNum = zkApp.num.get(); expect(updatedNum).toEqual(Field(3)); }); }); //# sourceMappingURL=Add.test.js.map