@cofhe/sdk 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/adapters/ethers6.ts +28 -28
  3. package/adapters/hardhat.ts +0 -1
  4. package/adapters/index.test.ts +14 -19
  5. package/adapters/smartWallet.ts +81 -73
  6. package/adapters/test-utils.ts +45 -45
  7. package/adapters/types.ts +3 -3
  8. package/chains/chains/localcofhe.ts +14 -0
  9. package/chains/chains.test.ts +2 -1
  10. package/chains/defineChain.ts +2 -2
  11. package/chains/index.ts +3 -1
  12. package/chains/types.ts +3 -3
  13. package/core/baseBuilder.ts +30 -49
  14. package/core/client.test.ts +200 -72
  15. package/core/client.ts +152 -148
  16. package/core/clientTypes.ts +114 -0
  17. package/core/config.test.ts +30 -11
  18. package/core/config.ts +26 -13
  19. package/core/consts.ts +18 -0
  20. package/core/decrypt/cofheMocksSealOutput.ts +2 -4
  21. package/core/decrypt/decryptHandleBuilder.ts +51 -45
  22. package/core/decrypt/{tnSealOutput.ts → tnSealOutputV1.ts} +1 -1
  23. package/core/decrypt/tnSealOutputV2.ts +298 -0
  24. package/core/encrypt/cofheMocksZkVerifySign.ts +15 -16
  25. package/core/encrypt/encryptInputsBuilder.test.ts +132 -116
  26. package/core/encrypt/encryptInputsBuilder.ts +159 -111
  27. package/core/encrypt/encryptUtils.ts +6 -3
  28. package/core/encrypt/zkPackProveVerify.ts +70 -8
  29. package/core/error.ts +0 -2
  30. package/core/fetchKeys.test.ts +1 -18
  31. package/core/fetchKeys.ts +0 -26
  32. package/core/index.ts +37 -17
  33. package/core/keyStore.ts +65 -38
  34. package/core/permits.test.ts +255 -4
  35. package/core/permits.ts +83 -18
  36. package/core/types.ts +198 -152
  37. package/core/utils.ts +43 -1
  38. package/dist/adapters.d.cts +38 -20
  39. package/dist/adapters.d.ts +38 -20
  40. package/dist/chains.cjs +18 -8
  41. package/dist/chains.d.cts +31 -9
  42. package/dist/chains.d.ts +31 -9
  43. package/dist/chains.js +1 -1
  44. package/dist/{chunk-KFGPTJ6X.js → chunk-I5WFEYXX.js} +1768 -1526
  45. package/dist/{chunk-LU7BMUUT.js → chunk-R3B5TMVX.js} +330 -197
  46. package/dist/{chunk-GZCQQYVI.js → chunk-TBLR7NNE.js} +18 -9
  47. package/dist/{types-PhwGgQvs.d.ts → clientTypes-RqkgkV2i.d.ts} +331 -429
  48. package/dist/{types-bB7wLj0q.d.cts → clientTypes-e4filDzK.d.cts} +331 -429
  49. package/dist/core.cjs +3000 -2625
  50. package/dist/core.d.cts +113 -7
  51. package/dist/core.d.ts +113 -7
  52. package/dist/core.js +3 -3
  53. package/dist/node.cjs +2851 -2526
  54. package/dist/node.d.cts +4 -4
  55. package/dist/node.d.ts +4 -4
  56. package/dist/node.js +4 -3
  57. package/dist/{permit-S9CnI6MF.d.cts → permit-MZ502UBl.d.cts} +54 -41
  58. package/dist/{permit-S9CnI6MF.d.ts → permit-MZ502UBl.d.ts} +54 -41
  59. package/dist/permits.cjs +328 -195
  60. package/dist/permits.d.cts +113 -825
  61. package/dist/permits.d.ts +113 -825
  62. package/dist/permits.js +1 -1
  63. package/dist/types-YiAC4gig.d.cts +33 -0
  64. package/dist/types-YiAC4gig.d.ts +33 -0
  65. package/dist/web.cjs +3067 -2527
  66. package/dist/web.d.cts +22 -6
  67. package/dist/web.d.ts +22 -6
  68. package/dist/web.js +185 -9
  69. package/dist/zkProve.worker.cjs +93 -0
  70. package/dist/zkProve.worker.d.cts +2 -0
  71. package/dist/zkProve.worker.d.ts +2 -0
  72. package/dist/zkProve.worker.js +91 -0
  73. package/node/client.test.ts +20 -25
  74. package/node/encryptInputs.test.ts +18 -38
  75. package/node/index.ts +1 -0
  76. package/package.json +15 -15
  77. package/permits/index.ts +1 -0
  78. package/permits/localstorage.test.ts +9 -14
  79. package/permits/onchain-utils.ts +221 -0
  80. package/permits/permit.test.ts +76 -27
  81. package/permits/permit.ts +58 -95
  82. package/permits/sealing.test.ts +3 -3
  83. package/permits/sealing.ts +2 -2
  84. package/permits/store.test.ts +10 -50
  85. package/permits/store.ts +9 -21
  86. package/permits/test-utils.ts +11 -3
  87. package/permits/types.ts +39 -9
  88. package/permits/utils.ts +0 -5
  89. package/permits/validation.test.ts +29 -32
  90. package/permits/validation.ts +114 -176
  91. package/web/client.web.test.ts +20 -25
  92. package/web/config.web.test.ts +0 -2
  93. package/web/encryptInputs.web.test.ts +31 -54
  94. package/web/index.ts +65 -1
  95. package/web/storage.ts +19 -5
  96. package/web/worker.builder.web.test.ts +148 -0
  97. package/web/worker.config.web.test.ts +329 -0
  98. package/web/worker.output.web.test.ts +84 -0
  99. package/web/workerManager.test.ts +80 -0
  100. package/web/workerManager.ts +214 -0
  101. package/web/workerManager.web.test.ts +114 -0
  102. package/web/zkProve.worker.ts +133 -0
  103. package/core/result.test.ts +0 -180
  104. package/core/result.ts +0 -67
  105. package/core/test-utils.ts +0 -45
  106. package/dist/types-KImPrEIe.d.cts +0 -48
  107. package/dist/types-KImPrEIe.d.ts +0 -48
@@ -14,16 +14,19 @@ import { MockZkVerifierAbi } from './MockZkVerifierAbi.js';
14
14
  import { hardhat } from 'viem/chains';
15
15
  import { CofhesdkError, CofhesdkErrorCode } from '../error.js';
16
16
  import { privateKeyToAccount } from 'viem/accounts';
17
-
18
- // Address the Mock ZkVerifier contract is deployed to on the Hardhat chain
19
- export const MocksZkVerifierAddress = '0x0000000000000000000000000000000000000100';
20
- // Private key of the account expected to sign the encrypted inputs
21
- export const MocksEncryptedInputSignerPkey = '0x6c8d7f768a6bb4aafe85e8a2f5a9680355239c7e14646ed62b044e39de154512';
17
+ import { MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY, MOCKS_ZK_VERIFIER_ADDRESS } from '../consts.js';
22
18
 
23
19
  type EncryptableItemWithCtHash = EncryptableItem & {
24
20
  ctHash: bigint;
25
21
  };
26
22
 
23
+ function createMockZkVerifierSigner() {
24
+ return createWalletClient({
25
+ chain: hardhat,
26
+ transport: http(),
27
+ account: privateKeyToAccount(MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY),
28
+ });
29
+ }
27
30
  /**
28
31
  * The mocks don't use a tfhe builder, so we check the encryptable bits here to preserve parity
29
32
  */
@@ -101,7 +104,7 @@ async function calcCtHashes(
101
104
 
102
105
  try {
103
106
  ctHashes = (await publicClient.readContract({
104
- address: MocksZkVerifierAddress,
107
+ address: MOCKS_ZK_VERIFIER_ADDRESS,
105
108
  abi: MockZkVerifierAbi,
106
109
  functionName: 'zkVerifyCalcCtHashesPacked',
107
110
  args: calcCtHashesArgs,
@@ -112,7 +115,7 @@ async function calcCtHashes(
112
115
  message: `mockZkVerifySign calcCtHashes failed while calling zkVerifyCalcCtHashesPacked`,
113
116
  cause: err instanceof Error ? err : undefined,
114
117
  context: {
115
- address: MocksZkVerifierAddress,
118
+ address: MOCKS_ZK_VERIFIER_ADDRESS,
116
119
  items,
117
120
  account,
118
121
  securityZone,
@@ -153,7 +156,7 @@ async function insertCtHashes(items: EncryptableItemWithCtHash[], walletClient:
153
156
  const account = walletClient.account!;
154
157
 
155
158
  await walletClient.writeContract({
156
- address: MocksZkVerifierAddress,
159
+ address: MOCKS_ZK_VERIFIER_ADDRESS,
157
160
  abi: MockZkVerifierAbi,
158
161
  functionName: 'insertPackedCtHashes',
159
162
  args: insertPackedCtHashesArgs,
@@ -187,18 +190,14 @@ async function createProofSignatures(items: EncryptableItemWithCtHash[], securit
187
190
  let encInputSignerClient: WalletClient | undefined;
188
191
 
189
192
  try {
190
- encInputSignerClient = createWalletClient({
191
- chain: hardhat,
192
- transport: http(),
193
- account: privateKeyToAccount(MocksEncryptedInputSignerPkey),
194
- });
193
+ encInputSignerClient = createMockZkVerifierSigner();
195
194
  } catch (err) {
196
195
  throw new CofhesdkError({
197
196
  code: CofhesdkErrorCode.ZkMocksCreateProofSignatureFailed,
198
197
  message: `mockZkVerifySign createProofSignatures failed while creating wallet client`,
199
198
  cause: err instanceof Error ? err : undefined,
200
199
  context: {
201
- MocksEncryptedInputSignerPkey,
200
+ MOCKS_ZK_VERIFIER_SIGNER_PRIVATE_KEY,
202
201
  },
203
202
  });
204
203
  }
@@ -258,8 +257,8 @@ export async function cofheMocksZkVerifySign(
258
257
  walletClient: WalletClient,
259
258
  zkvWalletClient: WalletClient | undefined
260
259
  ): Promise<VerifyResult[]> {
261
- // Use config.mocks.zkvWalletClient if provided, otherwise use connected walletClient
262
- const _walletClient = zkvWalletClient ?? walletClient;
260
+ // Use config._internal?.zkvWalletClient if provided, otherwise use a mock zk verifier signer
261
+ const _walletClient = zkvWalletClient ?? createMockZkVerifierSigner();
263
262
 
264
263
  // Call MockZkVerifier contract to calculate the ctHashes
265
264
  const encryptableItems = await calcCtHashes(items, account, securityZone, publicClient);
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-unused-vars */
2
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
3
2
  import { EncryptInputsBuilder } from './encryptInputsBuilder.js';
4
3
  import {
@@ -18,7 +17,6 @@ import { type CofhesdkConfig, createCofhesdkConfigBase } from '../config.js';
18
17
  import { type ZkBuilderAndCrsGenerator } from './zkPackProveVerify.js';
19
18
  import { type KeysStorage, createKeysStore } from '../keyStore.js';
20
19
  import { type FheKeyDeserializer } from '../fetchKeys.js';
21
- import { expectResultSuccess, expectResultError } from '../test-utils.js';
22
20
 
23
21
  const MockZkVerifierUrl = 'http://localhost:3001';
24
22
 
@@ -93,25 +91,25 @@ class MockZkListBuilder {
93
91
  this.items = items;
94
92
  }
95
93
  push_boolean(data: boolean): void {
96
- this.items.push({ utype: FheTypes.Bool, data });
94
+ this.items.push({ utype: FheTypes.Bool, data, securityZone: 0 });
97
95
  }
98
96
  push_u8(data: number): void {
99
- this.items.push({ utype: FheTypes.Uint8, data: BigInt(data) });
97
+ this.items.push({ utype: FheTypes.Uint8, data: BigInt(data), securityZone: 0 });
100
98
  }
101
99
  push_u16(data: number): void {
102
- this.items.push({ utype: FheTypes.Uint16, data: BigInt(data) });
100
+ this.items.push({ utype: FheTypes.Uint16, data: BigInt(data), securityZone: 0 });
103
101
  }
104
102
  push_u32(data: number): void {
105
- this.items.push({ utype: FheTypes.Uint32, data: BigInt(data) });
103
+ this.items.push({ utype: FheTypes.Uint32, data: BigInt(data), securityZone: 0 });
106
104
  }
107
105
  push_u64(data: bigint): void {
108
- this.items.push({ utype: FheTypes.Uint64, data });
106
+ this.items.push({ utype: FheTypes.Uint64, data, securityZone: 0 });
109
107
  }
110
108
  push_u128(data: bigint): void {
111
- this.items.push({ utype: FheTypes.Uint128, data });
109
+ this.items.push({ utype: FheTypes.Uint128, data, securityZone: 0 });
112
110
  }
113
111
  push_u160(data: bigint): void {
114
- this.items.push({ utype: FheTypes.Uint160, data });
112
+ this.items.push({ utype: FheTypes.Uint160, data, securityZone: 0 });
115
113
  }
116
114
  build_with_proof_packed(_crs: any, metadata: Uint8Array, _computeLoad: 1): MockZkProvenList {
117
115
  // Clear items to prevent persisting items between tests
@@ -249,6 +247,7 @@ describe('EncryptInputsBuilder', () => {
249
247
  compactPkeCrsDeserializer: mockCompactPkeCrsDeserializer,
250
248
  zkBuilderAndCrsGenerator: mockZkBuilderAndCrsGenerator,
251
249
  initTfhe: mockInitTfhe,
250
+ zkProveWorkerFn: undefined,
252
251
  keysStorage: keysStorage,
253
252
  requireConnected: vi.fn(),
254
253
  };
@@ -279,58 +278,62 @@ describe('EncryptInputsBuilder', () => {
279
278
  });
280
279
 
281
280
  it('should throw an error if config is not set', async () => {
282
- const builder = new EncryptInputsBuilder({
283
- ...createDefaultParams(),
284
- config: undefined as unknown as CofhesdkConfig,
285
- });
286
- const result = await builder.encrypt();
287
- expectResultError(result, CofhesdkErrorCode.MissingConfig);
281
+ // Should throw before .encrypt() is called
282
+ try {
283
+ new EncryptInputsBuilder({
284
+ ...createDefaultParams(),
285
+ config: undefined as unknown as CofhesdkConfig,
286
+ });
287
+ } catch (error) {
288
+ expect(error).toBeInstanceOf(CofhesdkError);
289
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.MissingConfig);
290
+ }
288
291
  });
289
292
 
290
293
  it('should throw an error if tfhePublicKeyDeserializer is not set', async () => {
291
- const builder = new EncryptInputsBuilder({
292
- ...createDefaultParams(),
293
- tfhePublicKeyDeserializer: undefined as unknown as FheKeyDeserializer,
294
- });
295
- const result = await builder.encrypt();
296
- expectResultError(result, CofhesdkErrorCode.MissingTfhePublicKeyDeserializer);
294
+ // Should throw before .encrypt() is called
295
+ try {
296
+ new EncryptInputsBuilder({
297
+ ...createDefaultParams(),
298
+ tfhePublicKeyDeserializer: undefined as unknown as FheKeyDeserializer,
299
+ });
300
+ } catch (error) {
301
+ expect(error).toBeInstanceOf(CofhesdkError);
302
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.MissingTfhePublicKeyDeserializer);
303
+ }
297
304
  });
298
305
 
299
306
  it('should throw an error if compactPkeCrsDeserializer is not set', async () => {
300
- const builder = new EncryptInputsBuilder({
301
- ...createDefaultParams(),
302
- compactPkeCrsDeserializer: undefined as unknown as FheKeyDeserializer,
303
- });
304
- const result = await builder.encrypt();
305
- expectResultError(result, CofhesdkErrorCode.MissingCompactPkeCrsDeserializer);
307
+ // Should throw before .encrypt() is called
308
+ try {
309
+ new EncryptInputsBuilder({
310
+ ...createDefaultParams(),
311
+ compactPkeCrsDeserializer: undefined as unknown as FheKeyDeserializer,
312
+ });
313
+ } catch (error) {
314
+ expect(error).toBeInstanceOf(CofhesdkError);
315
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.MissingCompactPkeCrsDeserializer);
316
+ }
306
317
  });
307
318
 
308
319
  it('should throw an error if initTfhe throws an error', async () => {
309
- const builder = new EncryptInputsBuilder({
310
- ...createDefaultParams(),
311
- initTfhe: vi.fn().mockRejectedValue(new Error('Failed to initialize TFHE')),
312
- });
313
- const result = await builder.encrypt();
314
- expectResultError(result, CofhesdkErrorCode.InitTfheFailed);
315
- });
316
-
317
- it('should throw an error if initTfhe throws', async () => {
318
- const mockInitTfhe = vi.fn().mockRejectedValue(new Error('Failed to initialize TFHE'));
319
- const builder = new EncryptInputsBuilder({
320
- ...createDefaultParams(),
321
- initTfhe: mockInitTfhe,
322
- });
323
- const result = await builder.encrypt();
324
- expectResultError(result, CofhesdkErrorCode.InitTfheFailed);
320
+ try {
321
+ await new EncryptInputsBuilder({
322
+ ...createDefaultParams(),
323
+ initTfhe: vi.fn().mockRejectedValue(new Error('Failed to initialize TFHE')),
324
+ }).encrypt();
325
+ } catch (error) {
326
+ expect(error).toBeInstanceOf(CofhesdkError);
327
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.InitTfheFailed);
328
+ }
325
329
  });
326
330
 
327
331
  it('should not throw an error if initTfhe is set', async () => {
328
- const builder = new EncryptInputsBuilder({
332
+ const result = await new EncryptInputsBuilder({
329
333
  ...createDefaultParams(),
330
334
  initTfhe: mockInitTfhe,
331
- });
332
- const result = await builder.encrypt();
333
- expectResultSuccess(result);
335
+ }).encrypt();
336
+ expect(result).toBeDefined();
334
337
  });
335
338
  });
336
339
 
@@ -359,12 +362,15 @@ describe('EncryptInputsBuilder', () => {
359
362
  });
360
363
 
361
364
  it('should throw an error if account is not set', async () => {
362
- const builder = new EncryptInputsBuilder({
363
- ...createDefaultParams(),
364
- account: undefined,
365
- });
366
- const result = await builder.encrypt();
367
- expectResultError(result, CofhesdkErrorCode.AccountUninitialized);
365
+ try {
366
+ await new EncryptInputsBuilder({
367
+ ...createDefaultParams(),
368
+ account: undefined,
369
+ }).encrypt();
370
+ } catch (error) {
371
+ expect(error).toBeInstanceOf(CofhesdkError);
372
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.AccountUninitialized);
373
+ }
368
374
  });
369
375
  });
370
376
 
@@ -400,27 +406,32 @@ describe('EncryptInputsBuilder', () => {
400
406
  });
401
407
 
402
408
  it('should throw an error if chainId is not set', async () => {
403
- const builder = new EncryptInputsBuilder({
404
- ...createDefaultParams(),
405
- chainId: undefined,
406
- });
407
- const result = await builder.encrypt();
408
- expectResultError(result, CofhesdkErrorCode.ChainIdUninitialized);
409
+ try {
410
+ await new EncryptInputsBuilder({
411
+ ...createDefaultParams(),
412
+ chainId: undefined,
413
+ }).encrypt();
414
+ } catch (error) {
415
+ expect(error).toBeInstanceOf(CofhesdkError);
416
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.ChainIdUninitialized);
417
+ }
409
418
  });
410
419
  });
411
420
 
412
421
  describe('zkVerifierUrl', () => {
413
422
  it('should throw if zkVerifierUrl is not set', async () => {
414
- builder = new EncryptInputsBuilder({
415
- ...createDefaultParams(),
416
- inputs: [Encryptable.uint128(100n)] as [EncryptableUint128],
417
- account: '0x1234567890123456789012345678901234567890',
418
- chainId: 1,
419
- config: createMockCofhesdkConfig(defaultChainId, undefined as unknown as string),
420
- });
421
-
422
- const result = await builder.encrypt();
423
- expectResultError(result, CofhesdkErrorCode.ZkVerifierUrlUninitialized);
423
+ try {
424
+ await new EncryptInputsBuilder({
425
+ ...createDefaultParams(),
426
+ inputs: [Encryptable.uint128(100n)] as [EncryptableUint128],
427
+ account: '0x1234567890123456789012345678901234567890',
428
+ chainId: 1,
429
+ config: createMockCofhesdkConfig(defaultChainId, undefined as unknown as string),
430
+ }).encrypt();
431
+ } catch (error) {
432
+ expect(error).toBeInstanceOf(CofhesdkError);
433
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.ZkVerifierUrlUninitialized);
434
+ }
424
435
  });
425
436
  });
426
437
 
@@ -444,7 +455,7 @@ describe('EncryptInputsBuilder', () => {
444
455
  const stepCallback = vi.fn();
445
456
  builder.setStepCallback(stepCallback);
446
457
 
447
- const result = expectResultSuccess(await builder.encrypt());
458
+ const result = await builder.encrypt();
448
459
 
449
460
  // Verify step callbacks were called in order
450
461
  expect(stepCallback).toHaveBeenCalledTimes(10);
@@ -557,7 +568,7 @@ describe('EncryptInputsBuilder', () => {
557
568
  const overriddenSender = '0x5555555555555555555555555555555555555555';
558
569
  builder.setAccount(overriddenSender);
559
570
 
560
- const result = expectResultSuccess(await builder.encrypt());
571
+ const result = await builder.encrypt();
561
572
 
562
573
  // Verify result embedded metadata
563
574
  const [encrypted] = result;
@@ -574,7 +585,7 @@ describe('EncryptInputsBuilder', () => {
574
585
 
575
586
  insertMockKeys(defaultChainId, overriddenZone);
576
587
 
577
- const result = expectResultSuccess(await builder.encrypt());
588
+ const result = await builder.encrypt();
578
589
 
579
590
  // Verify result embedded metadata
580
591
  const [encrypted] = result;
@@ -587,7 +598,7 @@ describe('EncryptInputsBuilder', () => {
587
598
 
588
599
  it('should work without step callback', async () => {
589
600
  // No step callback set
590
- const result = expectResultSuccess(await builder.encrypt());
601
+ const result = await builder.encrypt();
591
602
 
592
603
  expect(result).toBeDefined();
593
604
  expect(Array.isArray(result)).toBe(true);
@@ -603,54 +614,60 @@ describe('EncryptInputsBuilder', () => {
603
614
  ],
604
615
  });
605
616
 
606
- const result = expectResultSuccess(await multiInputBuilder.encrypt());
617
+ const result = await multiInputBuilder.encrypt();
607
618
 
608
619
  expect(result).toBeDefined();
609
620
  expect(Array.isArray(result)).toBe(true);
610
621
  });
611
622
 
612
623
  it('should throw an error if total bits exceeds 2048', async () => {
613
- const builder = new EncryptInputsBuilder({
614
- ...createDefaultParams(),
615
- inputs: [
616
- Encryptable.uint128(100n),
617
- Encryptable.uint128(100n),
618
- Encryptable.uint128(100n),
619
- Encryptable.uint128(100n),
620
- Encryptable.uint128(100n),
621
- Encryptable.uint128(100n),
622
- Encryptable.uint128(100n),
623
- Encryptable.uint128(100n),
624
- Encryptable.uint128(100n),
625
- Encryptable.uint128(100n),
626
- Encryptable.uint128(100n),
627
- Encryptable.uint128(100n),
628
- Encryptable.uint128(100n),
629
- Encryptable.uint128(100n),
630
- Encryptable.uint128(100n),
631
- Encryptable.uint128(100n),
632
- Encryptable.uint128(100n),
633
- Encryptable.uint128(100n),
634
- Encryptable.uint128(100n),
635
- Encryptable.uint128(100n),
636
- ],
637
- });
638
- const result = await builder.encrypt();
639
- expectResultError(result, CofhesdkErrorCode.ZkPackFailed);
624
+ try {
625
+ await new EncryptInputsBuilder({
626
+ ...createDefaultParams(),
627
+ inputs: [
628
+ Encryptable.uint128(100n),
629
+ Encryptable.uint128(100n),
630
+ Encryptable.uint128(100n),
631
+ Encryptable.uint128(100n),
632
+ Encryptable.uint128(100n),
633
+ Encryptable.uint128(100n),
634
+ Encryptable.uint128(100n),
635
+ Encryptable.uint128(100n),
636
+ Encryptable.uint128(100n),
637
+ Encryptable.uint128(100n),
638
+ Encryptable.uint128(100n),
639
+ Encryptable.uint128(100n),
640
+ Encryptable.uint128(100n),
641
+ Encryptable.uint128(100n),
642
+ Encryptable.uint128(100n),
643
+ Encryptable.uint128(100n),
644
+ Encryptable.uint128(100n),
645
+ Encryptable.uint128(100n),
646
+ Encryptable.uint128(100n),
647
+ Encryptable.uint128(100n),
648
+ ],
649
+ }).encrypt();
650
+ } catch (error) {
651
+ expect(error).toBeInstanceOf(CofhesdkError);
652
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.ZkPackFailed);
653
+ }
640
654
  });
641
655
 
642
656
  it('should throw an error if utype is invalid', async () => {
643
- const builder = new EncryptInputsBuilder({
644
- ...createDefaultParams(),
645
- inputs: [
646
- {
647
- data: 10n,
648
- utype: FheTypes.Uint10, // Invalid utype
649
- },
650
- ] as unknown as [EncryptableItem],
651
- });
652
- const result = await builder.encrypt();
653
- expectResultError(result, CofhesdkErrorCode.ZkPackFailed);
657
+ try {
658
+ await new EncryptInputsBuilder({
659
+ ...createDefaultParams(),
660
+ inputs: [
661
+ {
662
+ data: 10n,
663
+ utype: FheTypes.Uint10, // Invalid utype
664
+ },
665
+ ] as unknown as [EncryptableItem],
666
+ });
667
+ } catch (error) {
668
+ expect(error).toBeInstanceOf(CofhesdkError);
669
+ expect((error as CofhesdkError).code).toBe(CofhesdkErrorCode.ZkPackFailed);
670
+ }
654
671
  });
655
672
  });
656
673
 
@@ -685,13 +702,12 @@ describe('EncryptInputsBuilder', () => {
685
702
  .setSecurityZone(securityZone)
686
703
  .setStepCallback(stepCallback)
687
704
  .encrypt();
688
- const resultData = expectResultSuccess(result);
689
705
 
690
706
  expect(result).toBeDefined();
691
707
  expect(stepCallback).toHaveBeenCalledTimes(10);
692
708
 
693
709
  // Verify result embedded metadata
694
- const [encrypted] = resultData;
710
+ const [encrypted] = result;
695
711
  const encryptedMetadata = unpackMetadata(encrypted.signature);
696
712
  expect(encryptedMetadata).toBeDefined();
697
713
  expect(encryptedMetadata.signer).toBe(sender);
@@ -709,8 +725,8 @@ describe('EncryptInputsBuilder', () => {
709
725
  builder.setSecurityZone(securityZone);
710
726
 
711
727
  // Call encrypt multiple times to ensure state is maintained
712
- const result1 = expectResultSuccess(await builder.encrypt());
713
- const result2 = expectResultSuccess(await builder.encrypt());
728
+ const result1 = await builder.encrypt();
729
+ const result2 = await builder.encrypt();
714
730
 
715
731
  expect(result1).toBeDefined();
716
732
  expect(result2).toBeDefined();