From 7271d5ff76d6957e460a84b152af54f92f7ec0a6 Mon Sep 17 00:00:00 2001 From: 0xmad <0xmad@users.noreply.github.com> Date: Fri, 1 Mar 2024 09:35:00 -0600 Subject: [PATCH] feat(cli): return additional data from publish batch command - [x] Return encryption private key - [x] Return encrypted messages --- cli/tests/unit/publish.test.ts | 4 +++- cli/ts/commands/publish.ts | 2 ++ cli/ts/utils/interfaces.ts | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/cli/tests/unit/publish.test.ts b/cli/tests/unit/publish.test.ts index 1ab2d9f4a8..d7ceeab160 100644 --- a/cli/tests/unit/publish.test.ts +++ b/cli/tests/unit/publish.test.ts @@ -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 () => { diff --git a/cli/ts/commands/publish.ts b/cli/ts/commands/publish.ts index 7545f5fa40..a9fbceda28 100644 --- a/cli/ts/commands/publish.ts +++ b/cli/ts/commands/publish.ts @@ -239,5 +239,7 @@ export const publishBatch = async ({ return { hash: receipt?.hash, + encryptedMessages: preparedMessages, + privateKey: encryptionKeypair.privKey.serialize(), }; }; diff --git a/cli/ts/utils/interfaces.ts b/cli/ts/utils/interfaces.ts index 02efcaefb6..37f478fed2 100644 --- a/cli/ts/utils/interfaces.ts +++ b/cli/ts/utils/interfaces.ts @@ -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 { @@ -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; } /**