@cofhe/abi 0.6.0 → 0.7.0

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.
package/src/fhenixMap.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import type {
2
- EncryptedAddressInput,
3
- EncryptedBoolInput,
4
- EncryptedUint128Input,
5
- EncryptedUint16Input,
6
- EncryptedUint32Input,
7
- EncryptedUint64Input,
8
- EncryptedUint8Input,
2
+ ExternalAddressHash,
3
+ ExternalBoolHash,
4
+ ExternalUint128Hash,
5
+ ExternalUint16Hash,
6
+ ExternalUint32Hash,
7
+ ExternalUint64Hash,
8
+ ExternalUint8Hash,
9
9
  FheTypes,
10
10
  } from '@cofhe/sdk';
11
11
  import type {
@@ -57,14 +57,15 @@ export type EncryptedReturnType = EBool | EUint8 | EUint16 | EUint32 | EUint64 |
57
57
  export type EncryptedReturnTypeByUtype<U extends FheTypes> = Extract<EncryptedReturnType, { utype: U }>;
58
58
 
59
59
  export type FhenixInternalTypeMap = {
60
- // Input Structs
61
- 'struct InEbool': EncryptedBoolInput;
62
- 'struct InEuint8': EncryptedUint8Input;
63
- 'struct InEuint16': EncryptedUint16Input;
64
- 'struct InEuint32': EncryptedUint32Input;
65
- 'struct InEuint64': EncryptedUint64Input;
66
- 'struct InEuint128': EncryptedUint128Input;
67
- 'struct InEaddress': EncryptedAddressInput;
60
+ // Encrypted input handles (Solidity: externalEbool, externalEuint*, externalEaddress -
61
+ // plain bytes32-based value types, not structs)
62
+ externalEbool: ExternalBoolHash;
63
+ externalEuint8: ExternalUint8Hash;
64
+ externalEuint16: ExternalUint16Hash;
65
+ externalEuint32: ExternalUint32Hash;
66
+ externalEuint64: ExternalUint64Hash;
67
+ externalEuint128: ExternalUint128Hash;
68
+ externalEaddress: ExternalAddressHash;
68
69
 
69
70
  // Exposed encrypted primitives
70
71
  ebool: EBool;
@@ -1,4 +1,4 @@
1
- import { type EncryptableItem, type EncryptedItemInputs } from '@cofhe/sdk';
1
+ import { type EncryptableItem, type EncryptableToExternalHashMap, type HashPlusProofResult } from '@cofhe/sdk';
2
2
 
3
3
  /**
4
4
  * Generates a mock ctHash from the encryptable data.
@@ -36,39 +36,37 @@ export function generateMockCtHash(data: unknown): bigint {
36
36
  }
37
37
 
38
38
  /**
39
- * Generates a mock signature for testing purposes.
39
+ * Generates a mock batch signature for testing purposes.
40
40
  * Returns a hex string that looks like a valid signature.
41
41
  */
42
42
  function generateMockSignature(): `0x${string}` {
43
43
  return '0xMockSignature';
44
44
  }
45
45
 
46
- export function mockEncryptEncryptable<T extends EncryptableItem>(encryptable: T): EncryptedItemInputs<T> {
46
+ /**
47
+ * Converts an EncryptableItem to its mock external hash, without any real encryption or signing.
48
+ *
49
+ * @param encryptable - The EncryptableItem to convert
50
+ * @returns A mock hash (branded by utype), deterministically derived from the encryptable's data
51
+ */
52
+ export function mockEncryptEncryptable<T extends EncryptableItem>(encryptable: T): EncryptableToExternalHashMap<T> {
47
53
  const ctHash = generateMockCtHash(encryptable.data);
48
- const signature = generateMockSignature();
49
-
50
- return {
51
- ctHash,
52
- securityZone: 0,
53
- utype: encryptable.utype,
54
- signature,
55
- } as EncryptedItemInputs<T>;
54
+ return ('0x' + ctHash.toString(16).padStart(64, '0')) as EncryptableToExternalHashMap<T>;
56
55
  }
57
56
 
58
57
  /**
59
- * Converts an EncryptableItem to a mock EncryptedItemInput.
60
- * This is useful for testing and development when you don't need actual encryption.
61
- *
62
- * @param encryptable - The EncryptableItem to convert
63
- * @returns A mock EncryptedItemInput with the same utype and securityZone, but with mock ctHash and signature
58
+ * Converts an array of EncryptableItems into a mock batch-verified result: per-item hashes
59
+ * followed by a single mock batch signature - the same shape `EncryptInputsBuilder.execute()`
60
+ * returns. Useful for testing and development when you don't need actual encryption.
64
61
  *
65
62
  * @example
66
- * const encryptable = Encryptable.uint32(100n);
67
- * const mockEncrypted = mockEncryptedInput(encryptable);
68
- * // Returns: { ctHash: 100n, securityZone: 0, utype: FheTypes.Uint32, signature: "0x..." }
63
+ * const mockEncrypted = mockEncrypt([Encryptable.uint32(100n)]);
64
+ * // Returns: [hash, "0xMockSignature"]
69
65
  */
70
66
  export function mockEncrypt<T extends EncryptableItem[]>(
71
67
  encryptables: [...T] | readonly [...T]
72
- ): [...EncryptedItemInputs<T>] {
73
- return encryptables.map(mockEncryptEncryptable) as [...EncryptedItemInputs<[...T]>];
68
+ ): HashPlusProofResult<T> {
69
+ const hashes = encryptables.map(mockEncryptEncryptable);
70
+ const signature = generateMockSignature();
71
+ return [...hashes, signature] as unknown as HashPlusProofResult<T>;
74
72
  }