@inco/js 0.8.0-devnet-11 → 0.8.0-devnet-12
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/README.md +541 -47
- package/dist/cjs/binary.d.ts +84 -0
- package/dist/cjs/binary.js +81 -4
- package/dist/cjs/chain.d.ts +21 -4
- package/dist/cjs/chain.js +18 -7
- package/dist/cjs/encryption/encryption.d.ts +115 -0
- package/dist/cjs/encryption/encryption.js +98 -7
- package/dist/cjs/generated/local-node.d.ts +2 -2
- package/dist/cjs/generated/local-node.js +2 -2
- package/dist/cjs/handle.d.ts +41 -0
- package/dist/cjs/handle.js +31 -6
- package/dist/cjs/lite/lightning.d.ts +19 -0
- package/dist/cjs/lite/lightning.js +20 -5
- package/dist/cjs/local/local-node.d.ts +18 -0
- package/dist/cjs/local/local-node.js +18 -3
- package/dist/cjs/reencryption/eip712.d.ts +27 -0
- package/dist/cjs/reencryption/eip712.js +20 -7
- package/dist/cjs/reencryption/types.d.ts +24 -0
- package/dist/cjs/viem.d.ts +11 -0
- package/dist/cjs/viem.js +12 -1
- package/dist/esm/binary.d.ts +84 -0
- package/dist/esm/binary.js +81 -4
- package/dist/esm/chain.d.ts +21 -4
- package/dist/esm/chain.js +17 -6
- package/dist/esm/encryption/encryption.d.ts +115 -0
- package/dist/esm/encryption/encryption.js +98 -7
- package/dist/esm/generated/local-node.d.ts +2 -2
- package/dist/esm/generated/local-node.js +2 -2
- package/dist/esm/handle.d.ts +41 -0
- package/dist/esm/handle.js +31 -6
- package/dist/esm/lite/lightning.d.ts +19 -0
- package/dist/esm/lite/lightning.js +20 -5
- package/dist/esm/local/local-node.d.ts +18 -0
- package/dist/esm/local/local-node.js +18 -3
- package/dist/esm/reencryption/eip712.d.ts +27 -0
- package/dist/esm/reencryption/eip712.js +20 -7
- package/dist/esm/reencryption/types.d.ts +24 -0
- package/dist/esm/viem.d.ts +11 -0
- package/dist/esm/viem.js +12 -1
- package/dist/types/binary.d.ts +84 -0
- package/dist/types/chain.d.ts +21 -4
- package/dist/types/encryption/encryption.d.ts +115 -0
- package/dist/types/generated/local-node.d.ts +2 -2
- package/dist/types/handle.d.ts +41 -0
- package/dist/types/lite/lightning.d.ts +19 -0
- package/dist/types/local/local-node.d.ts +18 -0
- package/dist/types/reencryption/eip712.d.ts +27 -0
- package/dist/types/reencryption/types.d.ts +24 -0
- package/dist/types/viem.d.ts +11 -0
- package/package.json +1 -7
|
@@ -1,37 +1,79 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
2
|
import { ByteArray, Hex } from 'viem';
|
|
3
3
|
import { Bytes32 } from '../binary.js';
|
|
4
|
+
/**
|
|
5
|
+
* A function that encrypts a plaintext value, embedding its {@link InputContext} into the resulting ciphertext.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam S - The encryption scheme (e.g. X-Wing).
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const result = await encrypt({ plaintext: { scheme: 2, type: 5, value: 42n }, context });
|
|
11
|
+
* // result.handle, result.ciphertext, result.prehandle
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
4
14
|
export type Encryptor<S extends EncryptionScheme = EncryptionScheme> = <T extends SupportedFheType>(plaintext: PlaintextWithContextOf<S, T>) => Promise<EncryptResultOf<S, T>>;
|
|
15
|
+
/**
|
|
16
|
+
* A function that decrypts a ciphertext back to its plaintext value.
|
|
17
|
+
*
|
|
18
|
+
* @typeParam S - The encryption scheme (e.g. X-Wing).
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const plaintext = await decrypt({ scheme: 2, type: 5, value: '0x...' });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
5
24
|
export type Decryptor<S extends EncryptionScheme = EncryptionScheme> = <T extends SupportedFheType>(ciphertext: CiphertextOf<S, T>) => Promise<PlaintextOf<S, T>>;
|
|
25
|
+
/**
|
|
26
|
+
* Subset of ENCRYPTION types currently supported for encryption/decryption.
|
|
27
|
+
*
|
|
28
|
+
* @remarks TODO: review need of `euint64` and `euint160` — `Lib.sol` only supports `euint256` and `ebool`.
|
|
29
|
+
*/
|
|
6
30
|
export declare const supportedFheTypes: {
|
|
7
31
|
readonly euint64: 5;
|
|
8
32
|
readonly euint160: 7;
|
|
9
33
|
readonly euint256: 8;
|
|
10
34
|
readonly ebool: 0;
|
|
11
35
|
};
|
|
36
|
+
/** Schema that validates a string is one of the supported ENCRYPTION type names. */
|
|
12
37
|
export declare const SupportedFheTypeName: Schema.SchemaClass<"ebool" | "euint64" | "euint160" | "euint256", "ebool" | "euint64" | "euint160" | "euint256", never>;
|
|
38
|
+
/** A supported ENCRYPTION type name (e.g. `"euint256"`, `"ebool"`). */
|
|
13
39
|
export type SupportedFheTypeName = typeof SupportedFheTypeName.Type;
|
|
40
|
+
/** Schema that validates a number is one of the supported ENCRYPTION type integer identifiers. */
|
|
14
41
|
export declare const SupportedFheType: Schema.SchemaClass<0 | 5 | 7 | 8, 0 | 5 | 7 | 8, never>;
|
|
42
|
+
/** Integer identifier of a supported ENCRYPTION type (a subset of all ENCRYPTION types). */
|
|
15
43
|
export type SupportedFheType = typeof SupportedFheType.Type;
|
|
44
|
+
/** Map of encryption scheme names to their integer identifiers. Currently only X-Wing (2) is supported. */
|
|
16
45
|
export declare const encryptionSchemes: {
|
|
17
46
|
readonly xwing: 2;
|
|
18
47
|
};
|
|
48
|
+
/**
|
|
49
|
+
* Returns the human-readable name of an encryption scheme.
|
|
50
|
+
* @param scheme - The encryption scheme integer identifier.
|
|
51
|
+
* @returns The scheme name (e.g. `"X-Wing"`).
|
|
52
|
+
* @throws If the scheme identifier is unknown.
|
|
53
|
+
*/
|
|
19
54
|
export declare function getEncryptionSchemeName(scheme: number): string;
|
|
55
|
+
/** The typeof {@link encryptionSchemes} — mapping from scheme names to integer IDs. */
|
|
20
56
|
export type EncryptionSchemes = typeof encryptionSchemes;
|
|
57
|
+
/** The integer identifier for the X-Wing encryption scheme (`2`). */
|
|
21
58
|
export type XwingScheme = EncryptionSchemes['xwing'];
|
|
59
|
+
/** Schema that validates a value is a known encryption scheme identifier. */
|
|
22
60
|
export declare const EncryptionScheme: Schema.Literal<[2]>;
|
|
61
|
+
/** An encryption scheme identifier (currently only X-Wing = `2`). */
|
|
23
62
|
export type EncryptionScheme = typeof EncryptionScheme.Type;
|
|
24
63
|
type DistType<P, S extends EncryptionScheme, T extends SupportedFheType> = P extends any ? P & {
|
|
25
64
|
scheme: S;
|
|
26
65
|
type: T;
|
|
27
66
|
} : never;
|
|
67
|
+
/** Schema for an ENCRYPTION ciphertext: encryption scheme, ENCRYPTION type, and the encrypted value as a hex string. */
|
|
28
68
|
export declare const Ciphertext: Schema.Struct<{
|
|
29
69
|
scheme: Schema.Literal<[2]>;
|
|
30
70
|
type: Schema.SchemaClass<0 | 5 | 7 | 8, 0 | 5 | 7 | 8, never>;
|
|
31
71
|
value: Schema.TemplateLiteral<`0x${string}`>;
|
|
32
72
|
}>;
|
|
73
|
+
/** An ENCRYPTION ciphertext containing the encryption scheme, ENCRYPTION type, and encrypted hex value. */
|
|
33
74
|
export type Ciphertext = typeof Ciphertext.Type;
|
|
34
75
|
export type CiphertextOf<S extends EncryptionScheme, T extends SupportedFheType> = DistType<Ciphertext, S, T>;
|
|
76
|
+
/** Schema for a ciphertext paired with the {@link InputContext} it was encrypted under. */
|
|
35
77
|
export declare const CiphertextWithContext: Schema.Struct<{
|
|
36
78
|
ciphertext: Schema.Struct<{
|
|
37
79
|
scheme: Schema.Literal<[2]>;
|
|
@@ -46,10 +88,12 @@ export declare const CiphertextWithContext: Schema.Struct<{
|
|
|
46
88
|
version: typeof Schema.Number;
|
|
47
89
|
}>;
|
|
48
90
|
}>;
|
|
91
|
+
/** A ciphertext paired with the {@link InputContext} it was encrypted under. */
|
|
49
92
|
export type CiphertextWithContext = typeof CiphertextWithContext.Type;
|
|
50
93
|
export type CiphertextWithContextOf<S extends EncryptionScheme, T extends SupportedFheType> = CiphertextWithContext & {
|
|
51
94
|
ciphertext: CiphertextOf<S, T>;
|
|
52
95
|
};
|
|
96
|
+
/** Schema for the result of an encryption operation: ciphertext, input context, prehandle, and final handle. */
|
|
53
97
|
export declare const EncryptResult: Schema.Struct<{
|
|
54
98
|
ciphertext: Schema.Struct<{
|
|
55
99
|
scheme: Schema.Literal<[2]>;
|
|
@@ -66,10 +110,16 @@ export declare const EncryptResult: Schema.Struct<{
|
|
|
66
110
|
prehandle: Schema.brand<Schema.filter<Schema.transformOrFail<Schema.Union<[typeof Schema.String, Schema.refine<object & Uint8Array<ArrayBufferLike>, Schema.Schema<object, object, never>>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">;
|
|
67
111
|
handle: Schema.brand<Schema.filter<Schema.transformOrFail<Schema.Union<[typeof Schema.String, Schema.refine<object & Uint8Array<ArrayBufferLike>, Schema.Schema<object, object, never>>]>, Schema.TemplateLiteral<`0x${string}`>, never>>, "Bytes32">;
|
|
68
112
|
}>;
|
|
113
|
+
/** The result of an encryption operation, containing the ciphertext, context, prehandle, and deterministic handle. */
|
|
69
114
|
export type EncryptResult = typeof EncryptResult.Type;
|
|
70
115
|
export type EncryptResultOf<S extends EncryptionScheme, T extends SupportedFheType> = EncryptResult & {
|
|
71
116
|
ciphertext: CiphertextOf<S, T>;
|
|
72
117
|
};
|
|
118
|
+
/**
|
|
119
|
+
* Schema for an ENCRYPTION plaintext value. The `value` field type depends on the ENCRYPTION type:
|
|
120
|
+
* - `euint64` / `euint160` / `euint256`: `bigint`
|
|
121
|
+
* - `ebool`: `boolean`
|
|
122
|
+
*/
|
|
73
123
|
export declare const Plaintext: Schema.Union<[Schema.Struct<{
|
|
74
124
|
scheme: Schema.Literal<[2]>;
|
|
75
125
|
type: Schema.Literal<[5, 7, 8]>;
|
|
@@ -79,8 +129,10 @@ export declare const Plaintext: Schema.Union<[Schema.Struct<{
|
|
|
79
129
|
type: Schema.Literal<[0]>;
|
|
80
130
|
value: typeof Schema.Boolean;
|
|
81
131
|
}>]>;
|
|
132
|
+
/** An ENCRYPTION plaintext value — `bigint` for integer types, `boolean` for `ebool`. */
|
|
82
133
|
export type Plaintext = typeof Plaintext.Type;
|
|
83
134
|
export type PlaintextOf<S extends EncryptionScheme, T extends SupportedFheType> = DistType<Plaintext, S, T>;
|
|
135
|
+
/** Schema for a plaintext paired with the {@link InputContext} it will be encrypted under. */
|
|
84
136
|
export declare const PlaintextWithContext: Schema.Struct<{
|
|
85
137
|
plaintext: Schema.Union<[Schema.Struct<{
|
|
86
138
|
scheme: Schema.Literal<[2]>;
|
|
@@ -99,20 +151,83 @@ export declare const PlaintextWithContext: Schema.Struct<{
|
|
|
99
151
|
version: typeof Schema.Number;
|
|
100
152
|
}>;
|
|
101
153
|
}>;
|
|
154
|
+
/** A plaintext paired with the {@link InputContext} it will be encrypted under. */
|
|
102
155
|
export type PlaintextWithContext = typeof PlaintextWithContext.Type;
|
|
103
156
|
export type PlaintextWithContextOf<S extends EncryptionScheme, T extends SupportedFheType> = PlaintextWithContext & {
|
|
104
157
|
plaintext: PlaintextOf<S, T>;
|
|
105
158
|
};
|
|
159
|
+
/**
|
|
160
|
+
* Converts a `bigint` to a typed {@link Plaintext} value.
|
|
161
|
+
*
|
|
162
|
+
* For integer ENCRYPTION types (`euint64`, `euint160`, `euint256`) the value is passed through as-is.
|
|
163
|
+
* For `ebool`, non-zero values become `true`.
|
|
164
|
+
*
|
|
165
|
+
* @param scheme - The encryption scheme identifier.
|
|
166
|
+
* @param type - The ENCRYPTION type to interpret the value as.
|
|
167
|
+
* @param bigPt - The raw bigint plaintext value.
|
|
168
|
+
* @returns A typed `Plaintext` matching the given scheme and ENCRYPTION type.
|
|
169
|
+
* @throws If `type` is not a supported ENCRYPTION type.
|
|
170
|
+
*/
|
|
106
171
|
export declare function bigintToPlaintext<S extends EncryptionScheme, T extends SupportedFheType>(scheme: S, type: T, bigPt: bigint): PlaintextOf<S, T>;
|
|
172
|
+
/**
|
|
173
|
+
* Decodes an ABI-encoded ciphertext input into its components.
|
|
174
|
+
*
|
|
175
|
+
* The input format is: `4-byte version || abi.encode(bytes32 handle, bytes ciphertext)`.
|
|
176
|
+
*
|
|
177
|
+
* @param input - The raw encoded input as a byte array or hex string.
|
|
178
|
+
* @returns The decoded version, handle, and ciphertext.
|
|
179
|
+
*/
|
|
107
180
|
export declare function decodeCiphertextInput(input: ByteArray | Hex): {
|
|
108
181
|
version: number;
|
|
109
182
|
handle: Hex;
|
|
110
183
|
ciphertext: Hex;
|
|
111
184
|
};
|
|
185
|
+
/**
|
|
186
|
+
* Encodes a handle and ciphertext into the on-chain input format.
|
|
187
|
+
*
|
|
188
|
+
* The output format is: `4-byte version || abi.encode(bytes32 handle, bytes ciphertext)`.
|
|
189
|
+
*
|
|
190
|
+
* @param version - The encoding version (int32).
|
|
191
|
+
* @param handle - The 32-byte handle as a hex string.
|
|
192
|
+
* @param ciphertext - The ciphertext as a hex string.
|
|
193
|
+
* @returns The ABI-encoded input as a hex string.
|
|
194
|
+
*/
|
|
112
195
|
export declare function encodeCiphertextInput(version: number, handle: Hex, ciphertext: Hex): Hex;
|
|
196
|
+
/**
|
|
197
|
+
* Converts a {@link Plaintext} to its `bigint` representation.
|
|
198
|
+
*
|
|
199
|
+
* Integer types pass through directly; `ebool` maps `true` → `1n`, `false` → `0n`.
|
|
200
|
+
*
|
|
201
|
+
* @param plaintext - The plaintext to convert.
|
|
202
|
+
* @returns The bigint representation of the plaintext value.
|
|
203
|
+
*/
|
|
113
204
|
export declare function plaintextToBigint(plaintext: Plaintext): bigint;
|
|
205
|
+
/**
|
|
206
|
+
* Converts a {@link Plaintext} to a {@link Bytes32} hex string.
|
|
207
|
+
* @param plaintext - The plaintext to convert.
|
|
208
|
+
* @returns A 32-byte hex representation of the plaintext value.
|
|
209
|
+
*/
|
|
114
210
|
export declare function plaintextToBytes32(plaintext: Plaintext): Bytes32;
|
|
211
|
+
/**
|
|
212
|
+
* Converts a {@link Plaintext} to a 32-byte `Buffer`.
|
|
213
|
+
* @param plaintext - The plaintext to convert.
|
|
214
|
+
* @returns A 32-byte big-endian buffer of the plaintext value.
|
|
215
|
+
*/
|
|
115
216
|
export declare function plaintextToBytes(plaintext: Plaintext): Buffer;
|
|
217
|
+
/**
|
|
218
|
+
* Parses a {@link Bytes32} hex string into a typed {@link Plaintext}.
|
|
219
|
+
* @param plaintext - The 32-byte hex value to interpret.
|
|
220
|
+
* @param scheme - The encryption scheme identifier.
|
|
221
|
+
* @param type - The ENCRYPTION type to interpret the bytes as.
|
|
222
|
+
* @returns A typed `Plaintext` value.
|
|
223
|
+
*/
|
|
116
224
|
export declare function bytes32ToPlaintext(plaintext: Bytes32, scheme: EncryptionScheme, type: SupportedFheType): Plaintext;
|
|
225
|
+
/**
|
|
226
|
+
* Parses a `Uint8Array` into a typed {@link Plaintext}.
|
|
227
|
+
* @param plaintext - The byte array to interpret.
|
|
228
|
+
* @param scheme - The encryption scheme identifier.
|
|
229
|
+
* @param type - The ENCRYPTION type to interpret the bytes as.
|
|
230
|
+
* @returns A typed `Plaintext` value.
|
|
231
|
+
*/
|
|
117
232
|
export declare function bytesToPlaintext(plaintext: Uint8Array, scheme: EncryptionScheme, type: SupportedFheType): Plaintext;
|
|
118
233
|
export {};
|
|
@@ -19,9 +19,9 @@ export declare const localNodeLightningConfig: {
|
|
|
19
19
|
readonly executorAddress: "0xDF3830489208461f72Df6E45D0e6cbF9DBB74fe1";
|
|
20
20
|
readonly chainId: 31337;
|
|
21
21
|
readonly covalidatorUrls: readonly ["http://localhost:50055"];
|
|
22
|
-
readonly signers: readonly ["
|
|
22
|
+
readonly signers: readonly ["0x16844D5b82DdA890dc4DFc1407Ce4b1ebFdF6a93"];
|
|
23
23
|
readonly hostChainRpcUrl: "http://localhost:8545";
|
|
24
|
-
readonly senderPrivateKey: "
|
|
24
|
+
readonly senderPrivateKey: "0x3f9007c8e8de6208a5af414990834e80920255754b247f8a2cdeb293587cab1b";
|
|
25
25
|
};
|
|
26
26
|
readonly alphanet: {
|
|
27
27
|
readonly executorAddress: "0xc0d693DeEF0A91CE39208676b6da09B822abd199";
|
package/dist/types/handle.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
2
|
import { HexString } from './binary.js';
|
|
3
|
+
/** Current handle version byte, appended as the last byte of every handle. */
|
|
3
4
|
export declare const HANDLE_VERSION = 0;
|
|
5
|
+
/**
|
|
6
|
+
* Map of ENCRYPTION type names to their integer identifiers (matching tfhe-rs `FheType`).
|
|
7
|
+
*
|
|
8
|
+
* Keys provide a semantic interpretation over the underlying integral type.
|
|
9
|
+
* For example, `ebool` interprets a `uint16` as a boolean, `ebytes64` interprets
|
|
10
|
+
* a `uint512` as a 64-byte array, etc.
|
|
11
|
+
*/
|
|
4
12
|
export declare const handleTypes: Readonly<{
|
|
5
13
|
ebool: 0;
|
|
6
14
|
euint4: 1;
|
|
@@ -15,11 +23,21 @@ export declare const handleTypes: Readonly<{
|
|
|
15
23
|
ebytes128: 10;
|
|
16
24
|
ebytes256: 11;
|
|
17
25
|
}>;
|
|
26
|
+
/** Schema that validates a string is one of the known ENCRYPTION type names (e.g. `"ebool"`, `"euint256"`). */
|
|
18
27
|
export declare const HandleTypeName: Schema.SchemaClass<"ebool" | "euint4" | "euint8" | "euint16" | "euint32" | "euint64" | "euint128" | "euint160" | "euint256" | "ebytes64" | "ebytes128" | "ebytes256", "ebool" | "euint4" | "euint8" | "euint16" | "euint32" | "euint64" | "euint128" | "euint160" | "euint256" | "ebytes64" | "ebytes128" | "ebytes256", never>;
|
|
28
|
+
/** A valid ENCRYPTION type name string (e.g. `"ebool"`, `"euint32"`, `"ebytes64"`). */
|
|
19
29
|
export type HandleTypeName = typeof HandleTypeName.Type;
|
|
30
|
+
/** The typeof {@link handleTypes} — mapping from ENCRYPTION type names to integer IDs. */
|
|
20
31
|
export type HandleTypes = typeof handleTypes;
|
|
32
|
+
/** Integer identifier of an ENCRYPTION type (0–11), corresponding to a {@link HandleTypeName}. */
|
|
21
33
|
export type FheType = HandleTypes[keyof HandleTypes];
|
|
34
|
+
/**
|
|
35
|
+
* Type guard that checks whether a number is a valid {@link FheType} identifier.
|
|
36
|
+
* @param value - The number to check.
|
|
37
|
+
* @returns `true` if `value` is a known ENCRYPTION type integer (0–11).
|
|
38
|
+
*/
|
|
22
39
|
export declare function isFheType(value: number): value is FheType;
|
|
40
|
+
/** Schema for the context required to compute a deterministic ENCRYPTION handle from a prehandle. */
|
|
23
41
|
export declare const InputContext: Schema.Struct<{
|
|
24
42
|
hostChainId: typeof Schema.BigInt;
|
|
25
43
|
aclAddress: Schema.TemplateLiteral<`0x${string}`>;
|
|
@@ -27,7 +45,15 @@ export declare const InputContext: Schema.Struct<{
|
|
|
27
45
|
contractAddress: Schema.TemplateLiteral<`0x${string}`>;
|
|
28
46
|
version: typeof Schema.Number;
|
|
29
47
|
}>;
|
|
48
|
+
/** Context fields (chain ID, ACL address, user/contract addresses, version) used to derive a deterministic handle. */
|
|
30
49
|
export type InputContext = typeof InputContext.Type;
|
|
50
|
+
/**
|
|
51
|
+
* A 32-byte hex string representing an ENCRYPTION ciphertext handle.
|
|
52
|
+
*
|
|
53
|
+
* Format: `keccak_hash[0:29] || index_handle || handle_type || handle_version`
|
|
54
|
+
*
|
|
55
|
+
* @see {@link https://github.com/Inco-fhevm/inco-monorepo/blob/636756f512ae16535bdcb9a43df76bf14fbd6ba7/pkg/fhe/handle.md Handle format spec}
|
|
56
|
+
*/
|
|
31
57
|
export type Handle = HexString;
|
|
32
58
|
/**
|
|
33
59
|
* Expected length of a handle in bytes.
|
|
@@ -41,6 +67,13 @@ export declare const HANDLE_LENGTH_BYTES = 32;
|
|
|
41
67
|
* @throws Error if handle is malformed (wrong format, length, or unsupported version)
|
|
42
68
|
*/
|
|
43
69
|
export declare function validateHandle(handle: HexString): void;
|
|
70
|
+
/**
|
|
71
|
+
* Extracts the {@link FheType} from byte 30 of a validated handle.
|
|
72
|
+
* @param handle - A 32-byte hex handle string.
|
|
73
|
+
* @returns The ENCRYPTION type identifier stored in the handle.
|
|
74
|
+
* @throws If the handle is malformed or contains an invalid ENCRYPTION type.
|
|
75
|
+
* @see {@link https://github.com/Inco-fhevm/inco-monorepo/blob/636756f512ae16535bdcb9a43df76bf14fbd6ba7/pkg/fhe/handle.md Handle format spec}
|
|
76
|
+
*/
|
|
44
77
|
export declare function getHandleType(handle: HexString): FheType;
|
|
45
78
|
/**
|
|
46
79
|
* Computes the prehandle hash for an input based on the ciphertext
|
|
@@ -67,4 +100,12 @@ export declare function computeHandle({ prehandle, context, }: {
|
|
|
67
100
|
prehandle: Uint8Array;
|
|
68
101
|
context: InputContext;
|
|
69
102
|
}): Buffer;
|
|
103
|
+
/**
|
|
104
|
+
* Computes the Keccak-256 hash of an ABI-packed {@link InputContext}.
|
|
105
|
+
*
|
|
106
|
+
* The context is packed as: `"evm/" || chainId || aclAddress || userAddress || contractAddress || version`.
|
|
107
|
+
*
|
|
108
|
+
* @param context - The input context to hash.
|
|
109
|
+
* @returns A 32-byte `Buffer` containing the Keccak-256 digest.
|
|
110
|
+
*/
|
|
70
111
|
export declare function hashInputContext(context: InputContext): Buffer;
|
|
@@ -127,6 +127,7 @@ export declare class Lightning<T extends DeploymentSlice = DeploymentSlice> {
|
|
|
127
127
|
* @param chain the chain to use to filter the deployments
|
|
128
128
|
*/
|
|
129
129
|
static latest<P extends Pepper>(pepper: P, chainId: ChainId): Promise<Lightning<Deployment>>;
|
|
130
|
+
/** Returns a shallow copy of the deployment configuration this Lightning instance is bound to. */
|
|
130
131
|
get deployment(): T;
|
|
131
132
|
/**
|
|
132
133
|
* Encrypt a value using the network's public key (ECIES or X-Wing).
|
|
@@ -384,7 +385,25 @@ export declare class Lightning<T extends DeploymentSlice = DeploymentSlice> {
|
|
|
384
385
|
}, threshold: number): string[];
|
|
385
386
|
private static isIdByName;
|
|
386
387
|
private static plaintextFromValue;
|
|
388
|
+
/**
|
|
389
|
+
* Reads the network public key from the on-chain Inco Verifier contract.
|
|
390
|
+
*
|
|
391
|
+
* Falls back to the legacy `eciesPubkey()` getter for older contract versions.
|
|
392
|
+
*
|
|
393
|
+
* @param client - A viem public client connected to the host chain.
|
|
394
|
+
* @param executorAddress - The address of the Inco Lightning executor contract.
|
|
395
|
+
* @returns The network public key as a hex string.
|
|
396
|
+
*/
|
|
387
397
|
static getNetworkPubkey(client: PublicClient, executorAddress: Address): Promise<HexString>;
|
|
398
|
+
/**
|
|
399
|
+
* Resolves the Inco Verifier contract instance associated with a Lightning executor.
|
|
400
|
+
*
|
|
401
|
+
* Reads the `incoVerifier` address from the executor contract and returns a typed contract handle.
|
|
402
|
+
*
|
|
403
|
+
* @param client - A viem public client connected to the host chain.
|
|
404
|
+
* @param executorAddress - The address of the Inco Lightning executor contract.
|
|
405
|
+
* @returns A viem contract instance bound to the Inco Verifier ABI.
|
|
406
|
+
*/
|
|
388
407
|
static getIncoVerifierContract(client: PublicClient, executorAddress: Address): Promise<GetContractReturnType<typeof incoVerifierAbi, PublicClient, Address>>;
|
|
389
408
|
/**
|
|
390
409
|
* Retrieves the verifier contract details including threshold, signers, and XWING public key from the Inco Verifier contract.
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Schema for the environment variables required to connect to a local Inco node.
|
|
4
|
+
*
|
|
5
|
+
* Includes executor/sender addresses, keys, covalidator settings, and optional
|
|
6
|
+
* remote compute-server overrides. Typically populated from a `.env` file.
|
|
7
|
+
*/
|
|
2
8
|
export declare const LocalNodeEnv: Schema.Struct<{
|
|
3
9
|
DEPLOYER_ADDRESS: Schema.brand<Schema.filter<Schema.TemplateLiteral<`0x${string}`>>, "Address">;
|
|
4
10
|
STATE_DUMP: typeof Schema.String;
|
|
@@ -14,6 +20,18 @@ export declare const LocalNodeEnv: Schema.Struct<{
|
|
|
14
20
|
COVALIDATOR_HOST_CHAIN_ID: Schema.optional<typeof Schema.String>;
|
|
15
21
|
COVALIDATOR_URL: Schema.optional<typeof Schema.String>;
|
|
16
22
|
COVALIDATOR_HOST_CHAIN_RPC_URL: Schema.optional<typeof Schema.String>;
|
|
23
|
+
COVALIDATOR_COMPUTE_TYPE: Schema.optional<typeof Schema.String>;
|
|
24
|
+
COVALIDATOR_STORAGE_KEY: Schema.optional<Schema.TemplateLiteral<`0x${string}`>>;
|
|
17
25
|
}>;
|
|
26
|
+
/** Parsed local node environment configuration. */
|
|
18
27
|
export type LocalNodeEnv = typeof LocalNodeEnv.Type;
|
|
28
|
+
/**
|
|
29
|
+
* Parses a dotenv-formatted string or `Buffer` into a validated {@link LocalNodeEnv}.
|
|
30
|
+
*
|
|
31
|
+
* Falls back to `process.env` when no argument is provided.
|
|
32
|
+
*
|
|
33
|
+
* @param envFileOrObj - A dotenv-formatted string, `Buffer`, or `undefined` to use `process.env`.
|
|
34
|
+
* @returns A validated `LocalNodeEnv` object.
|
|
35
|
+
* @throws If required environment variables are missing or invalid.
|
|
36
|
+
*/
|
|
19
37
|
export declare function parseLocalEnv(envFileOrObj?: string | Buffer): LocalNodeEnv;
|
|
@@ -14,9 +14,36 @@ declare const baseEIP712: Schema.Struct<{
|
|
|
14
14
|
}>>>;
|
|
15
15
|
}>;
|
|
16
16
|
type BaseEIP712 = typeof baseEIP712.Type;
|
|
17
|
+
/**
|
|
18
|
+
* An EIP-712 typed data payload with a generic `message` field.
|
|
19
|
+
*
|
|
20
|
+
* Extends the base EIP-712 structure (domain, primaryType, types) with
|
|
21
|
+
* a strongly-typed `message` object for signing.
|
|
22
|
+
*
|
|
23
|
+
* @typeParam Message - The shape of the application-specific message to sign.
|
|
24
|
+
*/
|
|
17
25
|
export interface EIP712<Message extends object> extends BaseEIP712 {
|
|
18
26
|
message: Message;
|
|
19
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Creates an EIP-712 typed data payload for user signing.
|
|
30
|
+
*
|
|
31
|
+
* Used to verify the user controls the private key corresponding to the ephemeral
|
|
32
|
+
* public key embedded in the payload. The `message` keys must exactly match the
|
|
33
|
+
* `name` values in `primaryTypeFields`.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam PrimaryType - The EIP-712 primary type name.
|
|
36
|
+
* @typeParam Message - The shape of the message to sign.
|
|
37
|
+
* @param params.chainId - The chain ID for the EIP-712 domain.
|
|
38
|
+
* @param params.primaryType - The primary type name (e.g. `"Reencrypt"`).
|
|
39
|
+
* @param params.primaryTypeFields - The field definitions for the primary type.
|
|
40
|
+
* @param params.message - The message object to sign (must match `primaryTypeFields`).
|
|
41
|
+
* @param params.verifyingContract - Optional verifying contract address for the domain.
|
|
42
|
+
* @param params.domainName - Human-readable name for the EIP-712 domain.
|
|
43
|
+
* @param params.domainVersion - Version string for the EIP-712 domain.
|
|
44
|
+
* @returns A complete {@link EIP712} payload ready for signing.
|
|
45
|
+
* @throws If message keys do not match `primaryTypeFields` names.
|
|
46
|
+
*/
|
|
20
47
|
export declare function createEIP712Payload<PrimaryType extends string, Message extends object>({ chainId, primaryType, primaryTypeFields, message, verifyingContract, domainName, domainVersion, }: {
|
|
21
48
|
chainId: bigint;
|
|
22
49
|
primaryType: PrimaryType;
|
|
@@ -4,18 +4,42 @@ import { CiphertextOf, EncryptionScheme, PlaintextOf, SupportedFheType } from '.
|
|
|
4
4
|
import { Handle } from '../handle.js';
|
|
5
5
|
import type { XwingKeypair } from '../lite/xwing.js';
|
|
6
6
|
import type { BackoffConfig } from '../retry.js';
|
|
7
|
+
/**
|
|
8
|
+
* The core reencryption function type. Takes a handle (and optional ciphertext) and returns
|
|
9
|
+
* the decrypted plaintext. Supports retry configuration for handles that are not yet available.
|
|
10
|
+
*
|
|
11
|
+
* @typeParam S - The encryption scheme (e.g. X-Wing).
|
|
12
|
+
*/
|
|
7
13
|
export type Reencryptor<S extends EncryptionScheme> = <T extends SupportedFheType>(args: ReencryptFnArgs<S, T>, backoffConfig?: Partial<BackoffConfig>) => Promise<PlaintextOf<S, T>>;
|
|
14
|
+
/** Arguments required to construct a {@link Reencryptor}. */
|
|
8
15
|
export interface ReencryptorArgs {
|
|
9
16
|
chainId: bigint;
|
|
10
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Arguments for a single reencryption call.
|
|
20
|
+
*
|
|
21
|
+
* @typeParam S - The encryption scheme.
|
|
22
|
+
* @typeParam T - The ENCRYPTION type of the ciphertext.
|
|
23
|
+
*/
|
|
11
24
|
export type ReencryptFnArgs<S extends EncryptionScheme, T extends SupportedFheType> = {
|
|
12
25
|
handle: Handle;
|
|
26
|
+
/**
|
|
27
|
+
* Optional ciphertext hint. If provided, the reencrypt endpoint may use it directly
|
|
28
|
+
* instead of fetching from the covalidators.
|
|
29
|
+
*/
|
|
13
30
|
ciphertext?: CiphertextOf<S, T>;
|
|
14
31
|
};
|
|
32
|
+
/** Union of supported ephemeral keypair types for reencryption (currently X-Wing only). */
|
|
15
33
|
export type SupportedEphemeralKeypairs = XwingKeypair;
|
|
34
|
+
/** An object whose public key can be serialized to a `Uint8Array`. */
|
|
16
35
|
export interface PubKeyEncodable {
|
|
17
36
|
encodePublicKey(): Uint8Array;
|
|
18
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* A reencryption request to be sent to a reencrypt endpoint.
|
|
40
|
+
*
|
|
41
|
+
* @typeParam EKP - The type of ephemeral keypair used for the reencryption session.
|
|
42
|
+
*/
|
|
19
43
|
export interface ReencryptEndpointRequest<EKP extends SupportedEphemeralKeypairs> {
|
|
20
44
|
userAddress: Address;
|
|
21
45
|
handle: Handle;
|
package/dist/types/viem.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Chain } from 'viem';
|
|
2
2
|
import { Chainish } from './chain.js';
|
|
3
|
+
/** Map of supported chain short names to their viem chain objects. */
|
|
3
4
|
export declare const chains: {
|
|
4
5
|
sepolia: {
|
|
5
6
|
blockExplorers: {
|
|
@@ -778,4 +779,14 @@ export declare const chains: {
|
|
|
778
779
|
readonly network: "worldchain-sepolia";
|
|
779
780
|
};
|
|
780
781
|
};
|
|
782
|
+
/**
|
|
783
|
+
* Resolves a {@link Chainish} value to a viem {@link Chain} object.
|
|
784
|
+
*
|
|
785
|
+
* Accepts a chain ID (`number` or `bigint`), an object with an `id` field,
|
|
786
|
+
* or a chain short name (e.g. `"baseSepolia"`).
|
|
787
|
+
*
|
|
788
|
+
* @param chainish - The chain identifier to resolve.
|
|
789
|
+
* @returns The matching `viem` chain object.
|
|
790
|
+
* @throws If no supported chain matches the given identifier.
|
|
791
|
+
*/
|
|
781
792
|
export declare function getViemChain(chainish: Chainish): Chain;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inco/js",
|
|
3
|
-
"version": "0.8.0-devnet-
|
|
3
|
+
"version": "0.8.0-devnet-12",
|
|
4
4
|
"repository": "https://github.com/Inco-fhevm/inco-monorepo",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -24,12 +24,6 @@
|
|
|
24
24
|
"require": "./dist/cjs/lite/index.js",
|
|
25
25
|
"default": "./dist/cjs/lite/index.js"
|
|
26
26
|
},
|
|
27
|
-
"./fhevm": {
|
|
28
|
-
"types": "./dist/types/fhevm/index.d.ts",
|
|
29
|
-
"import": "./dist/esm/fhevm/index.js",
|
|
30
|
-
"require": "./dist/cjs/fhevm/index.js",
|
|
31
|
-
"default": "./dist/cjs/fhevm/index.js"
|
|
32
|
-
},
|
|
33
27
|
"./reencryption": {
|
|
34
28
|
"types": "./dist/types/reencryption/index.d.ts",
|
|
35
29
|
"import": "./dist/esm/reencryption/index.js",
|