Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

encryptInputs with improved API#24

Merged
architect-dev merged 11 commits into
mainfrom
encrypt-override-sender
Aug 25, 2025
Merged

encryptInputs with improved API#24
architect-dev merged 11 commits into
mainfrom
encrypt-override-sender

Conversation

@architect-dev

@architect-dev architect-dev commented Aug 19, 2025

Copy link
Copy Markdown
Collaborator

Refactored encrypt function named encryptInput

Breaks apart the encrypt inputs and options to improve the api. Also introduces the ability to override the sender embedded in the encrypted inputs.

New api:

 const encrypted = await cofhejs
   .encryptInputs([Encryptable.uint128(value)])
   .setSender(paymasterData.address) // optional - defaults to cofhejs initialized sender
   .setSecurityZone(0) // optional - defaults to 0
   .setStepCallback((step) => console.log(step)) // optional - used for debugging and UIs
   .encrypt();

import { CofhejsError, CofhejsErrorCode } from "../../types";
import { ZkPackProveVerify } from "./zkPackProveVerify";

export class EncryptInputsBuilder<T extends any[]> {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class is responsible for the updated functionality. The types of the inputs are inferred from the parameters, and the types of the outputs are inferred from the inputs.
Ex:
call: cofhejs.encryptInputs([Encryptable.bool(true)])
input types: [EncryptableBool]
output types: [CofheInBool]

The other input parameters (sender / chainId / zk) are provided in the body of cofhejs.encryptInputs. The sender / chainId are pulled from the store, and the zk is created in the multiple entrypoints (in node the zk package uses the tfhe-node builder, and in web it uses the tfhe builder)

Comment thread src/node/sdk.ts
* .encrypt();
* ```
*/
export function encryptInputs<T extends any[]>(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the function that gets exposed as cofhejs.encryptInputs. The state variables are injected here, along with a node specific zkPackProveVerify implementation

Comment thread test/arb-sepolia.test.ts Outdated
console.log(`Log Encrypt State :: ${state}`);
};

const nestedEncrypt = await cofhejs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested working implementation against arb-sepolia.

@architect-dev

architect-dev commented Aug 20, 2025

Copy link
Copy Markdown
Collaborator Author

Remaining:

  • Add the new encryptInputs function to the web endpoint
  • Mark the existing encrypt implementation as deprecated
  • Better comment the functionality
  • Integrate with the mocks so that the zk step gets re-routed to the on-chain mock steps
  • Create unit tests

@architect-dev architect-dev changed the title Add ability to override the account used for encrypt (UGLY) encryptInputs with improved API Aug 22, 2025
@architect-dev

Copy link
Copy Markdown
Collaborator Author

@tovi-fhe ready for a look.

@architect-dev
architect-dev merged commit c9ea85c into main Aug 25, 2025
1 of 4 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant