Skip to content

Commit

Permalink
Merge pull request #1260 from privacy-scaling-explorations/feature/pu…
Browse files Browse the repository at this point in the history
…blish-batch-additional-data

feat(cli): return additional data from publish batch command
  • Loading branch information
ctrlc03 authored Mar 1, 2024
2 parents 27d8f64 + 7271d5f commit e94530f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cli/tests/unit/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ describe("publish", () => {
const pollContract = PollFactory.connect(pollAddresses.poll, signer);
const initialNumMessages = await pollContract.numMessages();

const { hash } = await publishBatch(defaultArgs);
const { hash, encryptedMessages, privateKey } = await publishBatch(defaultArgs);
const numMessages = await pollContract.numMessages();

expect(initialNumMessages).to.eq(1n);
expect(hash).to.not.eq(null);
expect(hash).to.not.eq(undefined);
expect(numMessages).to.eq(BigInt(messages.length + 1));
expect(privateKey).to.not.eq(undefined);
expect(encryptedMessages.length).to.eq(defaultArgs.messages.length);
});

it("should throw error if public key is invalid", async () => {
Expand Down
2 changes: 2 additions & 0 deletions cli/ts/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,7 @@ export const publishBatch = async ({

return {
hash: receipt?.hash,
encryptedMessages: preparedMessages,
privateKey: encryptionKeypair.privKey.serialize(),
};
};
17 changes: 17 additions & 0 deletions cli/ts/utils/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Signer } from "ethers";

import type { SnarkProof } from "maci-contracts";
import type { CircuitInputs } from "maci-core";
import type { IMessageContractParams } from "maci-domainobjs";
import type { Groth16Proof, PublicSignals } from "snarkjs";

export interface DeployedContracts {
Expand Down Expand Up @@ -810,8 +811,24 @@ export interface IPublishMessage {
salt?: bigint;
}

/**
* Interface that represents publish batch return data
*/
export interface IPublishBatchData {
/**
* Publish transaction hash
*/
hash?: string;

/**
* Encrypted publish messages
*/
encryptedMessages: IMessageContractParams[];

/**
* Encryption private key
*/
privateKey: string;
}

/**
Expand Down

0 comments on commit e94530f

Please sign in to comment.