@cofhe/abi 0.5.1 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @cofhe/abi Changelog
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [bf23270]
8
+ - Updated dependencies [2711f9b]
9
+ - Updated dependencies [566f126]
10
+ - @cofhe/sdk@0.6.0
11
+
12
+ ## 0.5.2
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [2fbb918]
17
+ - @cofhe/sdk@0.5.2
18
+
3
19
  ## 0.5.1
4
20
 
5
21
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cofhe/abi",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "ABI utilities for Fhenix FHE contracts",
6
6
  "types": "./dist/index.d.ts",
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "abitype": "1.2.3",
30
- "@cofhe/sdk": "0.5.1"
30
+ "@cofhe/sdk": "0.6.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "20.19.15",
@@ -1,17 +1,4 @@
1
- import {
2
- FheTypes,
3
- type EncryptableItem,
4
- type EncryptableToEncryptedItemInputMap,
5
- type EncryptedAddressInput,
6
- type EncryptedBoolInput,
7
- type EncryptedItemInput,
8
- type EncryptedItemInputs,
9
- type EncryptedUint128Input,
10
- type EncryptedUint16Input,
11
- type EncryptedUint32Input,
12
- type EncryptedUint64Input,
13
- type EncryptedUint8Input,
14
- } from '@cofhe/sdk';
1
+ import { type EncryptableItem, type EncryptedItemInputs } from '@cofhe/sdk';
15
2
 
16
3
  /**
17
4
  * Generates a mock ctHash from the encryptable data.
@@ -25,14 +12,15 @@ export function generateMockCtHash(data: unknown): bigint {
25
12
  return data;
26
13
  }
27
14
  if (typeof data === 'string') {
28
- // Simple hash: convert string to number and create a bigint
15
+ // Keep only the low 32 bits after each round so the accumulator stays in
16
+ // the uint32 range instead of growing as an unbounded bigint.
29
17
  let hash = 0n;
30
18
  for (let i = 0; i < data.length; i++) {
31
19
  const char = data.charCodeAt(i);
32
20
  hash = (hash << 5n) - hash + BigInt(char);
33
- hash = hash & hash; // Convert to 32-bit integer
21
+ hash = BigInt.asUintN(32, hash);
34
22
  }
35
- return hash < 0n ? -hash : hash;
23
+ return hash;
36
24
  }
37
25
  // Fallback: use a simple hash based on string representation
38
26
  return BigInt(
@@ -1,139 +0,0 @@
1
- import {
2
- FheTypes,
3
- type EncryptableItem,
4
- type EncryptedAddressInput,
5
- type EncryptedBoolInput,
6
- type EncryptedItemInput,
7
- type EncryptedUint128Input,
8
- type EncryptedUint16Input,
9
- type EncryptedUint32Input,
10
- type EncryptedUint64Input,
11
- type EncryptedUint8Input,
12
- } from '@cofhe/sdk';
13
-
14
- /**
15
- * Generates a mock ctHash from the encryptable data.
16
- * This is a simple deterministic hash function for testing purposes.
17
- */
18
- function generateMockCtHash(data: unknown): bigint {
19
- if (typeof data === 'boolean') {
20
- return BigInt(data ? 1 : 0);
21
- }
22
- if (typeof data === 'bigint') {
23
- return data;
24
- }
25
- if (typeof data === 'string') {
26
- // Simple hash: convert string to number and create a bigint
27
- let hash = 0n;
28
- for (let i = 0; i < data.length; i++) {
29
- const char = data.charCodeAt(i);
30
- hash = (hash << 5n) - hash + BigInt(char);
31
- hash = hash & hash; // Convert to 32-bit integer
32
- }
33
- return hash < 0n ? -hash : hash;
34
- }
35
- // Fallback: use a simple hash based on string representation
36
- return BigInt(
37
- Math.abs(
38
- JSON.stringify(data)
39
- .split('')
40
- .reduce((a, b) => {
41
- a = (a << 5) - a + b.charCodeAt(0);
42
- return a & a;
43
- }, 0)
44
- )
45
- );
46
- }
47
-
48
- /**
49
- * Generates a mock signature for testing purposes.
50
- * Returns a hex string that looks like a valid signature.
51
- */
52
- function generateMockSignature(): `0x${string}` {
53
- // Generate a 64-character hex string (32 bytes)
54
- const hexChars = '0123456789abcdef';
55
- let signature = '0x';
56
- for (let i = 0; i < 64; i++) {
57
- signature += hexChars[Math.floor(Math.random() * hexChars.length)];
58
- }
59
- return signature as `0x${string}`;
60
- }
61
-
62
- /**
63
- * Converts an EncryptableItem to a mock EncryptedItemInput.
64
- * This is useful for testing and development when you don't need actual encryption.
65
- *
66
- * @param encryptable - The EncryptableItem to convert
67
- * @returns A mock EncryptedItemInput with the same utype and securityZone, but with mock ctHash and signature
68
- *
69
- * @example
70
- * const encryptable = Encryptable.uint32(100n);
71
- * const mockEncrypted = mockEncryptedInput(encryptable);
72
- * // Returns: { ctHash: 100n, securityZone: 0, utype: FheTypes.Uint32, signature: "0x..." }
73
- */
74
- export function mockEncryptedInput<T extends EncryptableItem>(encryptable: T): EncryptedItemInput {
75
- const ctHash = generateMockCtHash(encryptable.data);
76
- const signature = generateMockSignature();
77
-
78
- // Map based on utype to return the correct specific type
79
- switch (encryptable.utype) {
80
- case FheTypes.Bool:
81
- return {
82
- ctHash,
83
- securityZone: 0,
84
- utype: FheTypes.Bool,
85
- signature,
86
- } as EncryptedBoolInput;
87
-
88
- case FheTypes.Uint8:
89
- return {
90
- ctHash,
91
- securityZone: 0,
92
- utype: FheTypes.Uint8,
93
- signature,
94
- } as EncryptedUint8Input;
95
-
96
- case FheTypes.Uint16:
97
- return {
98
- ctHash,
99
- securityZone: 0,
100
- utype: FheTypes.Uint16,
101
- signature,
102
- } as EncryptedUint16Input;
103
-
104
- case FheTypes.Uint32:
105
- return {
106
- ctHash,
107
- securityZone: 0,
108
- utype: FheTypes.Uint32,
109
- signature,
110
- } as EncryptedUint32Input;
111
-
112
- case FheTypes.Uint64:
113
- return {
114
- ctHash,
115
- securityZone: 0,
116
- utype: FheTypes.Uint64,
117
- signature,
118
- } as EncryptedUint64Input;
119
-
120
- case FheTypes.Uint128:
121
- return {
122
- ctHash,
123
- securityZone: 0,
124
- utype: FheTypes.Uint128,
125
- signature,
126
- } as EncryptedUint128Input;
127
-
128
- case FheTypes.Uint160:
129
- return {
130
- ctHash,
131
- securityZone: 0,
132
- utype: FheTypes.Uint160,
133
- signature,
134
- } as EncryptedAddressInput;
135
-
136
- default:
137
- throw new Error(`Unsupported encryptable: ${encryptable}`);
138
- }
139
- }