Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): return additional data from publish batch command #1260

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading