diff --git a/.changeset/warm-scissors-count.md b/.changeset/warm-scissors-count.md new file mode 100644 index 00000000..9aa8daee --- /dev/null +++ b/.changeset/warm-scissors-count.md @@ -0,0 +1,8 @@ +--- +'@cofhe/react': minor +'@cofhe/sdk': minor +--- + +Align builder patterns in cofhe client api (`client.encryptInputs(..).encrypt()` and `client.decryptHandles(..).decrypt()`) to use the same terminator function `.execute()` instead of `.encrypt()`/`.decrypt()`. + +Rename `setStepCallback` of encryptInputs builder to `onStep` to improve ergonomics. diff --git a/README.md b/README.md index fe4a090d..9f9dbc60 100644 --- a/README.md +++ b/README.md @@ -104,5 +104,5 @@ Type `CofheInUint8` -> `EncryptedUint8Input` # Changes -- Fhe keys aren't fetched until `client.encryptInputs(...).encrypt()`, they aren't used anywhere else other than encrypting inputs, so their fetching is deferred until then. -- Initializing the tfhe wasm is also deferred until `client.encryptInputs(...).encrypt()` is called +- Fhe keys aren't fetched until `client.encryptInputs(...).execute()`, they aren't used anywhere else other than encrypting inputs, so their fetching is deferred until then. +- Initializing the tfhe wasm is also deferred until `client.encryptInputs(...).execute()` is called diff --git a/packages/hardhat-plugin-test/test/encrypt-inputs.test.ts b/packages/hardhat-plugin-test/test/encrypt-inputs.test.ts index 081af54d..07b34b9d 100644 --- a/packages/hardhat-plugin-test/test/encrypt-inputs.test.ts +++ b/packages/hardhat-plugin-test/test/encrypt-inputs.test.ts @@ -11,7 +11,7 @@ describe('Encrypt Inputs Test', () => { const client = await hre.cofhe.createClientWithBatteries(signer); - const encrypted = await client.encryptInputs([Encryptable.uint32(7n)]).encrypt(); + const encrypted = await client.encryptInputs([Encryptable.uint32(7n)]).execute(); // Add number to TestBed const testBed = await hre.cofhe.mocks.getTestBed(); @@ -19,7 +19,7 @@ describe('Encrypt Inputs Test', () => { const ctHash = await testBed.numberHash(); // Decrypt number from TestBed - const unsealed = await client.decryptHandle(ctHash, FheTypes.Uint32).decrypt(); + const unsealed = await client.decryptHandle(ctHash, FheTypes.Uint32).execute(); expect(unsealed).to.be.equal(7n); }); diff --git a/packages/hardhat-plugin-test/test/integration-base-sepolia.test.ts b/packages/hardhat-plugin-test/test/integration-base-sepolia.test.ts index c88f96f3..85a7d549 100644 --- a/packages/hardhat-plugin-test/test/integration-base-sepolia.test.ts +++ b/packages/hardhat-plugin-test/test/integration-base-sepolia.test.ts @@ -97,7 +97,7 @@ describe('Base Sepolia Integration Tests', () => { const testValue = 100n; // Encrypt and store a value - const encrypted = await cofheClient.encryptInputs([Encryptable.uint32(testValue)]).encrypt(); + const encrypted = await cofheClient.encryptInputs([Encryptable.uint32(testValue)]).execute(); const tx = await testContract.connect(baseSepoliaSigner).setValue(encrypted[0]); const receipt = await tx.wait(); @@ -107,7 +107,7 @@ describe('Base Sepolia Integration Tests', () => { const ctHash = await testContract.getValueHash(); // Decrypt the value using the ctHash from the encrypted input - const unsealedResult = await cofheClient.decryptHandle(ctHash, FheTypes.Uint32).decrypt(); + const unsealedResult = await cofheClient.decryptHandle(ctHash, FheTypes.Uint32).execute(); // Verify the decrypted value matches expect(unsealedResult).to.be.equal(testValue); diff --git a/packages/hardhat-plugin-test/test/integration-hardhat.test.ts b/packages/hardhat-plugin-test/test/integration-hardhat.test.ts index 12e3fdae..271563e9 100644 --- a/packages/hardhat-plugin-test/test/integration-hardhat.test.ts +++ b/packages/hardhat-plugin-test/test/integration-hardhat.test.ts @@ -36,13 +36,13 @@ describe('Hardhat Integration Tests', () => { const testValue = 100n; // Encrypt and store a value - const encrypted = await cofheClient.encryptInputs([Encryptable.uint32(testValue)]).encrypt(); + const encrypted = await cofheClient.encryptInputs([Encryptable.uint32(testValue)]).execute(); const tx = await testContract.connect(signer).setValue(encrypted[0]); await tx.wait(); // Decrypt the value using the ctHash from the encrypted input - const unsealedResult = await cofheClient.decryptHandle(encrypted[0].ctHash, FheTypes.Uint32).decrypt(); + const unsealedResult = await cofheClient.decryptHandle(encrypted[0].ctHash, FheTypes.Uint32).execute(); // Verify the decrypted value matches expect(unsealedResult).to.be.equal(testValue); diff --git a/packages/hardhat-plugin-test/test/integration-localcofhe.test.ts b/packages/hardhat-plugin-test/test/integration-localcofhe.test.ts index 961740cb..cd91412c 100644 --- a/packages/hardhat-plugin-test/test/integration-localcofhe.test.ts +++ b/packages/hardhat-plugin-test/test/integration-localcofhe.test.ts @@ -86,7 +86,7 @@ describe('Local Cofhe Integration Tests', () => { const testValue = 101n; // Encrypt and store a value - const encrypted = await cofheClient.encryptInputs([Encryptable.uint32(testValue)]).encrypt(); + const encrypted = await cofheClient.encryptInputs([Encryptable.uint32(testValue)]).execute(); const tx = await testContract.connect(localcofheSigner).setValue(encrypted[0]); await tx.wait(); @@ -96,7 +96,7 @@ describe('Local Cofhe Integration Tests', () => { const ctHash = await testContract.getValueHash(); // Decrypt the value using the ctHash from the encrypted input - const unsealedResult = await cofheClient.decryptHandle(ctHash, FheTypes.Uint32).decrypt(); + const unsealedResult = await cofheClient.decryptHandle(ctHash, FheTypes.Uint32).execute(); // Verify the decrypted value matches expect(unsealedResult).to.be.equal(testValue); diff --git a/packages/hardhat-plugin-test/test/permit-unseal.test.ts b/packages/hardhat-plugin-test/test/permit-unseal.test.ts index 2a6f5fe0..bc9a7255 100644 --- a/packages/hardhat-plugin-test/test/permit-unseal.test.ts +++ b/packages/hardhat-plugin-test/test/permit-unseal.test.ts @@ -17,7 +17,7 @@ describe('Permit Unseal Test', () => { const ctHash = await testBed.numberHash(); // Decrypt number from TestBed - const unsealed = await client.decryptHandle(ctHash, FheTypes.Uint32).decrypt(); + const unsealed = await client.decryptHandle(ctHash, FheTypes.Uint32).execute(); expect(unsealed).to.be.equal(7n); }); diff --git a/packages/react/src/hooks/useCofheDecrypt.ts b/packages/react/src/hooks/useCofheDecrypt.ts index f29ef8ca..e8633a37 100644 --- a/packages/react/src/hooks/useCofheDecrypt.ts +++ b/packages/react/src/hooks/useCofheDecrypt.ts @@ -30,7 +30,7 @@ export function useCofheDecrypt { assert(input, 'input is guaranteed to be defined by enabled condition'); - return client.decryptHandle(input.ctHash, input.utype).decrypt(); + return client.decryptHandle(input.ctHash, input.utype).execute(); }, meta: { persist: true, diff --git a/packages/react/src/hooks/useCofheEncrypt.ts b/packages/react/src/hooks/useCofheEncrypt.ts index 8b8aef4d..c40cbeab 100644 --- a/packages/react/src/hooks/useCofheEncrypt.ts +++ b/packages/react/src/hooks/useCofheEncrypt.ts @@ -145,7 +145,7 @@ export function useCofheEncrypt(options?: UseCofheEncryptOptions): UseMutationRe }; // Always set callback so we can track steps consistently. - builder.setStepCallback(combinedOnStepChange); + builder.onStep(combinedOnStepChange); if (hasEncryptInputsOptions(variables)) { if (variables.account) builder.setAccount(variables.account); @@ -153,7 +153,7 @@ export function useCofheEncrypt(options?: UseCofheEncryptOptions): UseMutationRe if (variables.securityZone) builder.setSecurityZone(variables.securityZone); } - return builder.encrypt(); + return builder.execute(); }, }); diff --git a/packages/sdk/core/client.test.ts b/packages/sdk/core/client.test.ts index edbb8333..bb6ae1a7 100644 --- a/packages/sdk/core/client.test.ts +++ b/packages/sdk/core/client.test.ts @@ -383,7 +383,7 @@ describe('createCofheClientBase', () => { describe('encryptInputs', () => { it('should throw if not connected', async () => { try { - await client.encryptInputs([Encryptable.uint8(1n), Encryptable.uint8(2n), Encryptable.uint8(3n)]).encrypt(); + await client.encryptInputs([Encryptable.uint8(1n), Encryptable.uint8(2n), Encryptable.uint8(3n)]).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.NotConnected); @@ -400,7 +400,7 @@ describe('createCofheClientBase', () => { expect(builder).toBeDefined(); expect(builder).toBeInstanceOf(EncryptInputsBuilder); - expect(builder).toHaveProperty('encrypt'); + expect(builder).toHaveProperty('execute'); expect(builder.getChainId()).toBe(123); expect(builder.getAccount()).toBe('0xtest'); }); diff --git a/packages/sdk/core/decrypt/decryptHandleBuilder.ts b/packages/sdk/core/decrypt/decryptHandleBuilder.ts index 5072cc79..d6600d12 100644 --- a/packages/sdk/core/decrypt/decryptHandleBuilder.ts +++ b/packages/sdk/core/decrypt/decryptHandleBuilder.ts @@ -19,7 +19,7 @@ import { tnSealOutputV2 } from './tnSealOutputV2.js'; * .setAccount(account) * .setPermitHash(permitHash) * .setPermit(permit) - * .decrypt() + * .execute() * * If chainId not set, uses client's chainId * If account not set, uses client's account @@ -67,7 +67,7 @@ export class DecryptHandlesBuilder extends BaseBuilder { * ```typescript * const unsealed = await decryptHandle(ctHash, utype) * .setChainId(11155111) - * .decrypt(); + * .execute(); * ``` * * @returns The chainable DecryptHandlesBuilder instance. @@ -90,7 +90,7 @@ export class DecryptHandlesBuilder extends BaseBuilder { * ```typescript * const unsealed = await decryptHandle(ctHash, utype) * .setAccount('0x1234567890123456789012345678901234567890') - * .decrypt(); + * .execute(); * ``` * * @returns The chainable DecryptHandlesBuilder instance. @@ -114,7 +114,7 @@ export class DecryptHandlesBuilder extends BaseBuilder { * ```typescript * const unsealed = await decryptHandle(ctHash, utype) * .setPermitHash('0x1234567890123456789012345678901234567890') - * .decrypt(); + * .execute(); * ``` * * @returns The chainable DecryptHandlesBuilder instance. @@ -137,7 +137,7 @@ export class DecryptHandlesBuilder extends BaseBuilder { * ```typescript * const unsealed = await decryptHandle(ctHash, utype) * .setPermit(permit) - * .decrypt(); + * .execute(); * ``` * * @returns The chainable DecryptHandlesBuilder instance. @@ -246,12 +246,12 @@ export class DecryptHandlesBuilder extends BaseBuilder { * const unsealed = await decryptHandle(ctHash, utype) * .setChainId(11155111) // optional * .setAccount('0x123...890') // optional - * .decrypt(); // execute + * .execute(); // execute * ``` * * @returns The unsealed item. */ - async decrypt(): Promise> { + async execute(): Promise> { // Ensure utype is valid this.validateUtypeOrThrow(); diff --git a/packages/sdk/core/encrypt/encryptInputsBuilder.test.ts b/packages/sdk/core/encrypt/encryptInputsBuilder.test.ts index 0f821a57..5e562dc0 100644 --- a/packages/sdk/core/encrypt/encryptInputsBuilder.test.ts +++ b/packages/sdk/core/encrypt/encryptInputsBuilder.test.ts @@ -278,7 +278,7 @@ describe('EncryptInputsBuilder', () => { }); it('should throw an error if config is not set', async () => { - // Should throw before .encrypt() is called + // Should throw before .execute() is called try { new EncryptInputsBuilder({ ...createDefaultParams(), @@ -291,7 +291,7 @@ describe('EncryptInputsBuilder', () => { }); it('should throw an error if tfhePublicKeyDeserializer is not set', async () => { - // Should throw before .encrypt() is called + // Should throw before .execute() is called try { new EncryptInputsBuilder({ ...createDefaultParams(), @@ -304,7 +304,7 @@ describe('EncryptInputsBuilder', () => { }); it('should throw an error if compactPkeCrsDeserializer is not set', async () => { - // Should throw before .encrypt() is called + // Should throw before .execute() is called try { new EncryptInputsBuilder({ ...createDefaultParams(), @@ -321,7 +321,7 @@ describe('EncryptInputsBuilder', () => { await new EncryptInputsBuilder({ ...createDefaultParams(), initTfhe: vi.fn().mockRejectedValue(new Error('Failed to initialize TFHE')), - }).encrypt(); + }).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.InitTfheFailed); @@ -332,7 +332,7 @@ describe('EncryptInputsBuilder', () => { const result = await new EncryptInputsBuilder({ ...createDefaultParams(), initTfhe: mockInitTfhe, - }).encrypt(); + }).execute(); expect(result).toBeDefined(); }); }); @@ -354,7 +354,7 @@ describe('EncryptInputsBuilder', () => { const result = builder .setAccount(sender) .setSecurityZone(securityZone) - .setStepCallback(() => {}); + .onStep(() => {}); expect(result).toBe(builder); expect(result.getAccount()).toBe(sender); @@ -366,7 +366,7 @@ describe('EncryptInputsBuilder', () => { await new EncryptInputsBuilder({ ...createDefaultParams(), account: undefined, - }).encrypt(); + }).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.AccountUninitialized); @@ -389,7 +389,7 @@ describe('EncryptInputsBuilder', () => { const result = builder .setSecurityZone(securityZone) .setAccount(sender) - .setStepCallback(() => {}); + .onStep(() => {}); expect(result).toBe(builder); expect(result.getAccount()).toBe(sender); @@ -410,7 +410,7 @@ describe('EncryptInputsBuilder', () => { await new EncryptInputsBuilder({ ...createDefaultParams(), chainId: undefined, - }).encrypt(); + }).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.ChainIdUninitialized); @@ -427,7 +427,7 @@ describe('EncryptInputsBuilder', () => { account: '0x1234567890123456789012345678901234567890', chainId: 1, config: createMockCofheConfig(defaultChainId, undefined as unknown as string), - }).encrypt(); + }).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.ZkVerifierUrlUninitialized); @@ -435,16 +435,16 @@ describe('EncryptInputsBuilder', () => { }); }); - describe('setStepCallback', () => { + describe('onStep', () => { it('should set step callback and return builder for chaining', () => { const callback = vi.fn(); - const result = builder.setStepCallback(callback); + const result = builder.onStep(callback); expect(result).toBe(builder); }); it('should allow chaining with other methods', () => { const callback = vi.fn(); - const result = builder.setStepCallback(callback).setSecurityZone(15); + const result = builder.onStep(callback).setSecurityZone(15); expect(result).toBe(builder); }); @@ -453,9 +453,9 @@ describe('EncryptInputsBuilder', () => { describe('encrypt', () => { it('should execute the full encryption flow with step callbacks', async () => { const stepCallback = vi.fn(); - builder.setStepCallback(stepCallback); + builder.onStep(stepCallback); - const result = await builder.encrypt(); + const result = await builder.execute(); // Verify step callbacks were called in order expect(stepCallback).toHaveBeenCalledTimes(10); @@ -568,7 +568,7 @@ describe('EncryptInputsBuilder', () => { const overriddenSender = '0x5555555555555555555555555555555555555555'; builder.setAccount(overriddenSender); - const result = await builder.encrypt(); + const result = await builder.execute(); // Verify result embedded metadata const [encrypted] = result; @@ -585,7 +585,7 @@ describe('EncryptInputsBuilder', () => { insertMockKeys(defaultChainId, overriddenZone); - const result = await builder.encrypt(); + const result = await builder.execute(); // Verify result embedded metadata const [encrypted] = result; @@ -598,7 +598,7 @@ describe('EncryptInputsBuilder', () => { it('should work without step callback', async () => { // No step callback set - const result = await builder.encrypt(); + const result = await builder.execute(); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); @@ -614,7 +614,7 @@ describe('EncryptInputsBuilder', () => { ], }); - const result = await multiInputBuilder.encrypt(); + const result = await multiInputBuilder.execute(); expect(result).toBeDefined(); expect(Array.isArray(result)).toBe(true); @@ -646,7 +646,7 @@ describe('EncryptInputsBuilder', () => { Encryptable.uint128(100n), Encryptable.uint128(100n), ], - }).encrypt(); + }).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.ZkPackFailed); @@ -674,17 +674,17 @@ describe('EncryptInputsBuilder', () => { // TODO: Implement error handling tests // describe('error handling', () => { // it('should handle ZK pack errors gracefully', async () => { - // const result = await builder.encrypt(); + // const result = await builder.execute(); // expectResultError(result, CofheErrorCode.InternalError, 'ZK pack failed'); // }); // it('should handle ZK prove errors gracefully', async () => { - // const result = await builder.encrypt(); + // const result = await builder.execute(); // expectResultError(result, CofheErrorCode.InternalError, 'ZK prove failed'); // }); // it('should handle ZK verify errors gracefully', async () => { - // const result = await builder.encrypt(); + // const result = await builder.execute(); // expectResultError(result, CofheErrorCode.InternalError, 'ZK verify failed'); // }); // }); @@ -697,11 +697,7 @@ describe('EncryptInputsBuilder', () => { insertMockKeys(defaultChainId, securityZone); const stepCallback = vi.fn(); - const result = await builder - .setAccount(sender) - .setSecurityZone(securityZone) - .setStepCallback(stepCallback) - .encrypt(); + const result = await builder.setAccount(sender).setSecurityZone(securityZone).onStep(stepCallback).execute(); expect(result).toBeDefined(); expect(stepCallback).toHaveBeenCalledTimes(10); @@ -725,8 +721,8 @@ describe('EncryptInputsBuilder', () => { builder.setSecurityZone(securityZone); // Call encrypt multiple times to ensure state is maintained - const result1 = await builder.encrypt(); - const result2 = await builder.encrypt(); + const result1 = await builder.execute(); + const result2 = await builder.execute(); expect(result1).toBeDefined(); expect(result2).toBeDefined(); diff --git a/packages/sdk/core/encrypt/encryptInputsBuilder.ts b/packages/sdk/core/encrypt/encryptInputsBuilder.ts index 4ea1632e..013481c7 100644 --- a/packages/sdk/core/encrypt/encryptInputsBuilder.ts +++ b/packages/sdk/core/encrypt/encryptInputsBuilder.ts @@ -149,7 +149,7 @@ export class EncryptInputsBuilder extends BaseBuild * ```typescript * const encrypted = await encryptInputs([Encryptable.uint128(10n)]) * .setAccount("0x123") - * .encrypt(); + * .execute(); * ``` * * @returns The chainable EncryptInputsBuilder instance. @@ -172,7 +172,7 @@ export class EncryptInputsBuilder extends BaseBuild * ```typescript * const encrypted = await encryptInputs([Encryptable.uint128(10n)]) * .setChainId(11155111) - * .encrypt(); + * .execute(); * ``` * * @returns The chainable EncryptInputsBuilder instance. @@ -195,7 +195,7 @@ export class EncryptInputsBuilder extends BaseBuild * ```typescript * const encrypted = await encryptInputs([Encryptable.uint128(10n)]) * .setSecurityZone(1) - * .encrypt(); + * .execute(); * ``` * * @returns The chainable EncryptInputsBuilder instance. @@ -218,7 +218,7 @@ export class EncryptInputsBuilder extends BaseBuild * ```typescript * const encrypted = await encryptInputs([Encryptable.uint128(10n)]) * .setUseWorker(false) - * .encrypt(); + * .execute(); * ``` * * @returns The chainable EncryptInputsBuilder instance. @@ -254,13 +254,13 @@ export class EncryptInputsBuilder extends BaseBuild * Example: * ```typescript * const encrypted = await encryptInputs([Encryptable.uint128(10n)]) - * .setStepCallback((step: EncryptStep) => console.log(step)) - * .encrypt(); + * .onStep((step: EncryptStep) => console.log(step)) + * .execute(); * ``` * * @returns The EncryptInputsBuilder instance. */ - setStepCallback(callback: EncryptStepCallbackFunction): EncryptInputsBuilder { + onStep(callback: EncryptStepCallbackFunction): EncryptInputsBuilder { this.stepCallback = callback; return this; } @@ -404,7 +404,7 @@ export class EncryptInputsBuilder extends BaseBuild * cofheMocksInsertPackedHashes - stores the ctHashes and their plaintext values for on-chain mocking of FHE operations. * cofheMocksZkCreateProofSignatures - creates signatures to be included in the encrypted inputs. The signers address is known and verified in the mock contracts. */ - private async mocksEncrypt(): Promise<[...EncryptedItemInputs]> { + private async mocksExecute(): Promise<[...EncryptedItemInputs]> { this.assertAccount(); this.assertPublicClient(); this.assertWalletClient(); @@ -450,7 +450,7 @@ export class EncryptInputsBuilder extends BaseBuild /** * In the production context, perform a true encryption with the CoFHE coprocessor. */ - private async productionEncrypt(): Promise<[...EncryptedItemInputs]> { + private async productionExecute(): Promise<[...EncryptedItemInputs]> { this.assertAccount(); this.assertChainId(); @@ -545,16 +545,16 @@ export class EncryptInputsBuilder extends BaseBuild * const encrypted = await encryptInputs([Encryptable.uint128(10n)]) * .setAccount('0x123...890') // optional * .setChainId(11155111) // optional - * .encrypt(); // execute + * .execute(); // execute * ``` * * @returns The encrypted inputs. */ - async encrypt(): Promise<[...EncryptedItemInputs]> { + async execute(): Promise<[...EncryptedItemInputs]> { // On hardhat chain, interact with MockZkVerifier contract instead of CoFHE - if (this.chainId === hardhat.id) return this.mocksEncrypt(); + if (this.chainId === hardhat.id) return this.mocksExecute(); // On other chains, interact with CoFHE coprocessor - return this.productionEncrypt(); + return this.productionExecute(); } } diff --git a/packages/sdk/node/client.test.ts b/packages/sdk/node/client.test.ts index aec9f563..bd5b2c1b 100644 --- a/packages/sdk/node/client.test.ts +++ b/packages/sdk/node/client.test.ts @@ -130,7 +130,7 @@ describe('@cofhe/node - Client Integration Tests', () => { expect(typeof builder.setChainId).toBe('function'); expect(typeof builder.setAccount).toBe('function'); expect(typeof builder.setSecurityZone).toBe('function'); - expect(typeof builder.encrypt).toBe('function'); + expect(typeof builder.execute).toBe('function'); }, 30000); it('should create decrypt builder after connection', async () => { @@ -141,7 +141,7 @@ describe('@cofhe/node - Client Integration Tests', () => { expect(builder).toBeDefined(); expect(typeof builder.setChainId).toBe('function'); expect(typeof builder.setAccount).toBe('function'); - expect(typeof builder.decrypt).toBe('function'); + expect(typeof builder.execute).toBe('function'); }, 30000); }); }); diff --git a/packages/sdk/node/encryptInputs.test.ts b/packages/sdk/node/encryptInputs.test.ts index 47afb3bb..46d51bc7 100644 --- a/packages/sdk/node/encryptInputs.test.ts +++ b/packages/sdk/node/encryptInputs.test.ts @@ -43,7 +43,7 @@ describe('@cofhe/node - Encrypt Inputs', () => { await cofheClient.connect(publicClient, walletClient); // This will trigger real TFHE initialization - const encrypted = await cofheClient.encryptInputs([Encryptable.uint128(100n)]).encrypt(); + const encrypted = await cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute(); // If we get here, TFHE was initialized successfully expect(encrypted).toBeDefined(); @@ -53,10 +53,10 @@ describe('@cofhe/node - Encrypt Inputs', () => { await cofheClient.connect(publicClient, walletClient); // First encryption - await cofheClient.encryptInputs([Encryptable.uint128(100n)]).encrypt(); + await cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute(); // Second encryption should reuse initialization - await cofheClient.encryptInputs([Encryptable.uint64(50n)]).encrypt(); + await cofheClient.encryptInputs([Encryptable.uint64(50n)]).execute(); }, 120000); }); @@ -64,7 +64,7 @@ describe('@cofhe/node - Encrypt Inputs', () => { it('should encrypt a bool with real TFHE', async () => { await cofheClient.connect(publicClient, walletClient); - const encrypted = await cofheClient.encryptInputs([Encryptable.bool(true)]).encrypt(); + const encrypted = await cofheClient.encryptInputs([Encryptable.bool(true)]).execute(); expect(encrypted.length).toBe(1); expect(encrypted[0].utype).toBe(FheTypes.Bool); @@ -88,7 +88,7 @@ describe('@cofhe/node - Encrypt Inputs', () => { Encryptable.address('0x742d35Cc6634C0532925a3b844D16faC4c175E99'), ]; - const encrypted = await cofheClient.encryptInputs(inputs).encrypt(); + const encrypted = await cofheClient.encryptInputs(inputs).execute(); expect(encrypted.length).toBe(7); // Verify each type @@ -112,7 +112,7 @@ describe('@cofhe/node - Encrypt Inputs', () => { .setChainId(snapshot.chainId!) .setAccount(snapshot.account!) .setSecurityZone(0) - .encrypt(); + .execute(); expect(encrypted.length).toBe(1); expect(encrypted[0].utype).toBe(FheTypes.Uint128); @@ -123,7 +123,7 @@ describe('@cofhe/node - Encrypt Inputs', () => { it('should fail gracefully when not connected', async () => { // Don't connect the client try { - await cofheClient.encryptInputs([Encryptable.uint128(100n)]).encrypt(); + await cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.NotConnected); @@ -145,7 +145,7 @@ describe('@cofhe/node - Encrypt Inputs', () => { await badClient.connect(publicClient, walletClient); try { - await badClient.encryptInputs([Encryptable.uint128(100n)]).encrypt(); + await badClient.encryptInputs([Encryptable.uint128(100n)]).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.ZkVerifyFailed); diff --git a/packages/sdk/web/client.web.test.ts b/packages/sdk/web/client.web.test.ts index f5f9b791..ad339964 100644 --- a/packages/sdk/web/client.web.test.ts +++ b/packages/sdk/web/client.web.test.ts @@ -130,7 +130,7 @@ describe('@cofhe/web - Client', () => { expect(typeof builder.setChainId).toBe('function'); expect(typeof builder.setAccount).toBe('function'); expect(typeof builder.setSecurityZone).toBe('function'); - expect(typeof builder.encrypt).toBe('function'); + expect(typeof builder.execute).toBe('function'); }, 30000); it('should create decrypt builder after connection', async () => { @@ -141,7 +141,7 @@ describe('@cofhe/web - Client', () => { expect(builder).toBeDefined(); expect(typeof builder.setChainId).toBe('function'); expect(typeof builder.setAccount).toBe('function'); - expect(typeof builder.decrypt).toBe('function'); + expect(typeof builder.execute).toBe('function'); }, 30000); }); }); diff --git a/packages/sdk/web/encryptInputs.web.test.ts b/packages/sdk/web/encryptInputs.web.test.ts index 4214e331..c5055ae4 100644 --- a/packages/sdk/web/encryptInputs.web.test.ts +++ b/packages/sdk/web/encryptInputs.web.test.ts @@ -43,7 +43,7 @@ describe('@cofhe/web - Encrypt Inputs Browser Tests', () => { await cofheClient.connect(publicClient, walletClient); // This will trigger real TFHE initialization in browser - const result = await cofheClient.encryptInputs([Encryptable.uint128(100n)]).encrypt(); + const result = await cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute(); // If we get here, TFHE was initialized successfully expect(result).toBeDefined(); @@ -53,10 +53,10 @@ describe('@cofhe/web - Encrypt Inputs Browser Tests', () => { await cofheClient.connect(publicClient, walletClient); // First encryption - expect(cofheClient.encryptInputs([Encryptable.uint128(100n)]).encrypt()).resolves.not.toThrow(); + expect(cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute()).resolves.not.toThrow(); // Second encryption should reuse initialization - expect(cofheClient.encryptInputs([Encryptable.uint64(50n)]).encrypt()).resolves.not.toThrow(); + expect(cofheClient.encryptInputs([Encryptable.uint64(50n)]).execute()).resolves.not.toThrow(); }, 60000); }); @@ -64,7 +64,7 @@ describe('@cofhe/web - Encrypt Inputs Browser Tests', () => { it('should encrypt a bool with real TFHE in browser', async () => { await cofheClient.connect(publicClient, walletClient); - const result = await cofheClient.encryptInputs([Encryptable.bool(true)]).encrypt(); + const result = await cofheClient.encryptInputs([Encryptable.bool(true)]).execute(); expect(result).toBeDefined(); expect(result.length).toBe(1); @@ -89,7 +89,7 @@ describe('@cofhe/web - Encrypt Inputs Browser Tests', () => { Encryptable.address('0x742d35Cc6634C0532925a3b844D16faC4c175E99'), ]; - const result = await cofheClient.encryptInputs(inputs).encrypt(); + const result = await cofheClient.encryptInputs(inputs).execute(); expect(result).toBeDefined(); expect(result.length).toBe(7); @@ -114,7 +114,7 @@ describe('@cofhe/web - Encrypt Inputs Browser Tests', () => { .setChainId(snapshot.chainId!) .setAccount(snapshot.account!) .setSecurityZone(0) - .encrypt(); + .execute(); expect(encrypted.length).toBe(1); expect(encrypted[0].utype).toBe(FheTypes.Uint128); @@ -125,7 +125,7 @@ describe('@cofhe/web - Encrypt Inputs Browser Tests', () => { it('should fail gracefully when not connected', async () => { // Don't connect the client try { - const promise = cofheClient.encryptInputs([Encryptable.uint128(100n)]).encrypt(); + const promise = cofheClient.encryptInputs([Encryptable.uint128(100n)]).execute(); } catch (error) { expect(error).toBeInstanceOf(CofheError); expect((error as CofheError).code).toBe(CofheErrorCode.NotConnected); @@ -146,7 +146,7 @@ describe('@cofhe/web - Encrypt Inputs Browser Tests', () => { const badClient = createCofheClient(badConfig); await badClient.connect(publicClient, walletClient); - const promise = badClient.encryptInputs([Encryptable.uint128(100n)]).encrypt(); + const promise = badClient.encryptInputs([Encryptable.uint128(100n)]).execute(); expect(promise).rejects.toThrow(); }, 60000); }); @@ -159,7 +159,7 @@ describe('@cofhe/web - Encrypt Inputs Browser Tests', () => { // Perform 5 encryptions for (let i = 0; i < 5; i++) { - await cofheClient.encryptInputs([Encryptable.uint128(BigInt(i))]).encrypt(); + await cofheClient.encryptInputs([Encryptable.uint128(BigInt(i))]).execute(); } const duration = Date.now() - start; diff --git a/packages/sdk/web/worker.builder.web.test.ts b/packages/sdk/web/worker.builder.web.test.ts index ddeb9eed..895f7d24 100644 --- a/packages/sdk/web/worker.builder.web.test.ts +++ b/packages/sdk/web/worker.builder.web.test.ts @@ -56,10 +56,10 @@ describe('@cofhe/sdk/web - EncryptInputsBuilder Worker Methods', () => { const builder = cofheClient .encryptInputs([Encryptable.uint128(100n)]) .setUseWorker(false) - .setStepCallback(() => {}); + .onStep(() => {}); expect(builder).toBeDefined(); - expect(builder).toHaveProperty('encrypt'); + expect(builder).toHaveProperty('execute'); }); it('should accept true parameter', () => { diff --git a/packages/sdk/web/worker.config.web.test.ts b/packages/sdk/web/worker.config.web.test.ts index bcba7750..395cc7c5 100644 --- a/packages/sdk/web/worker.config.web.test.ts +++ b/packages/sdk/web/worker.config.web.test.ts @@ -44,12 +44,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { let proveContext: any; const result = await client .encryptInputs([Encryptable.uint128(100n)]) - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); expect(result).toBeDefined(); @@ -85,12 +85,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { let proveContext: any; const result = await client .encryptInputs([Encryptable.uint128(100n)]) - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); expect(result).toBeDefined(); @@ -116,12 +116,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { const result = await client .encryptInputs([Encryptable.uint128(100n)]) .setUseWorker(false) // Override to false - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); expect(result).toBeDefined(); @@ -144,12 +144,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { const result = await client .encryptInputs([Encryptable.uint128(100n)]) .setUseWorker(true) // Override to true - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); expect(result).toBeDefined(); @@ -170,12 +170,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { let proveContext: any; const result = await client .encryptInputs([Encryptable.uint128(100n)]) - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); expect(result).toBeDefined(); @@ -214,12 +214,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { let proveContext: any; const result = await client .encryptInputs([Encryptable.uint128(100n)]) - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); // Verify encryption succeeded via fallback to main thread expect(result).toBeDefined(); @@ -249,12 +249,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { let proveContext: any; const result = await client .encryptInputs([Encryptable.uint128(100n), Encryptable.uint64(50n), Encryptable.bool(true)]) - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); // All values should encrypt successfully via fallback expect(result).toBeDefined(); @@ -284,12 +284,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { let proveContext: any; const result = await client .encryptInputs([Encryptable.uint8(42n)]) - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); expect(result).toBeDefined(); @@ -311,12 +311,12 @@ describe('@cofhe/sdk/web - Worker Configuration Tests', () => { const result = await client .encryptInputs([Encryptable.uint8(42n)]) .setUseWorker(false) // But override to disable worker - .setStepCallback((step, context) => { + .onStep((step, context) => { if (step === 'prove' && context?.isEnd) { proveContext = context; } }) - .encrypt(); + .execute(); expect(result).toBeDefined(); diff --git a/packages/sdk/web/worker.output.web.test.ts b/packages/sdk/web/worker.output.web.test.ts index dd629cb6..d110c496 100644 --- a/packages/sdk/web/worker.output.web.test.ts +++ b/packages/sdk/web/worker.output.web.test.ts @@ -49,8 +49,8 @@ describe('@cofhe/sdk/web - Worker vs Main Thread Output Validation', () => { const value = Encryptable.uint128(12345n); const [resultWithWorker, resultWithoutWorker] = await Promise.all([ - clientWithWorker.encryptInputs([value]).encrypt(), - clientWithoutWorker.encryptInputs([value]).encrypt(), + clientWithWorker.encryptInputs([value]).execute(), + clientWithoutWorker.encryptInputs([value]).execute(), ]); // Both should succeed