@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/CHANGELOG.md +29 -0
- package/README.md +36 -25
- package/dist/index.cjs +93 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +48 -17
- package/dist/index.d.ts +48 -17
- package/dist/index.js +93 -54
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/encryptedInputs.ts +234 -234
- package/src/fhenixMap.ts +16 -15
- package/src/mockEncrypt.ts +19 -21
package/src/fhenixMap.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
//
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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;
|
package/src/mockEncrypt.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type EncryptableItem, type
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
60
|
-
*
|
|
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
|
|
67
|
-
*
|
|
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
|
-
):
|
|
73
|
-
|
|
68
|
+
): HashPlusProofResult<T> {
|
|
69
|
+
const hashes = encryptables.map(mockEncryptEncryptable);
|
|
70
|
+
const signature = generateMockSignature();
|
|
71
|
+
return [...hashes, signature] as unknown as HashPlusProofResult<T>;
|
|
74
72
|
}
|