@zama-fhe/sdk 1.0.0-alpha.10
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/LICENSE +28 -0
- package/README.md +801 -0
- package/dist/chunk-5QJTGZHY.js +101 -0
- package/dist/chunk-5QJTGZHY.js.map +1 -0
- package/dist/chunk-6JRD26PS.js +114 -0
- package/dist/chunk-6JRD26PS.js.map +1 -0
- package/dist/chunk-PHE3BSIB.js +5143 -0
- package/dist/chunk-PHE3BSIB.js.map +1 -0
- package/dist/chunk-UF47M3QR.js +32 -0
- package/dist/chunk-UF47M3QR.js.map +1 -0
- package/dist/chunk-WYWAO3QE.js +182 -0
- package/dist/chunk-WYWAO3QE.js.map +1 -0
- package/dist/cleartext/index.d.ts +45 -0
- package/dist/cleartext/index.js +522 -0
- package/dist/cleartext/index.js.map +1 -0
- package/dist/ethers/index.d.ts +86 -0
- package/dist/ethers/index.js +148 -0
- package/dist/ethers/index.js.map +1 -0
- package/dist/index.d.ts +33405 -0
- package/dist/index.js +3563 -0
- package/dist/index.js.map +1 -0
- package/dist/node/index.d.ts +195 -0
- package/dist/node/index.js +337 -0
- package/dist/node/index.js.map +1 -0
- package/dist/relayer-sdk-Dh9aQmBm.d.ts +39 -0
- package/dist/relayer-sdk.node-worker.d.ts +2 -0
- package/dist/relayer-sdk.node-worker.js +348 -0
- package/dist/relayer-sdk.node-worker.js.map +1 -0
- package/dist/relayer-sdk.types-CgHZ6qZn.d.ts +327 -0
- package/dist/relayer-sdk.worker.js +511 -0
- package/dist/relayer-sdk.worker.js.map +1 -0
- package/dist/relayer-utils-phBmWrNB.d.ts +10 -0
- package/dist/token.types-CUTkehsp.d.ts +299 -0
- package/dist/transfer-batcher-CNtrNMz6.d.ts +197 -0
- package/dist/viem/index.d.ts +58 -0
- package/dist/viem/index.js +143 -0
- package/dist/viem/index.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import * as SDK from '@zama-fhe/relayer-sdk/bundle';
|
|
2
|
+
import { FhevmInstanceConfig, Address, ZKProofLike, KmsDelegatedUserDecryptEIP712Type, InputProofBytesType } from '@zama-fhe/relayer-sdk/bundle';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Optional logger for worker client observability.
|
|
6
|
+
* Pass to `WorkerClientConfig` or `NodeWorkerClientConfig` to observe
|
|
7
|
+
* request lifecycle (start, success, error, timeout).
|
|
8
|
+
*/
|
|
9
|
+
interface GenericLogger {
|
|
10
|
+
info: (message: string, data?: Record<string, unknown>) => void;
|
|
11
|
+
debug: (message: string, data?: Record<string, unknown>) => void;
|
|
12
|
+
warn: (message: string, data?: Record<string, unknown>) => void;
|
|
13
|
+
error: (message: string, data?: Record<string, unknown>) => void;
|
|
14
|
+
}
|
|
15
|
+
type WorkerRequestType = "INIT" | "NODE_INIT" | "UPDATE_CSRF" | "ENCRYPT" | "USER_DECRYPT" | "PUBLIC_DECRYPT" | "GENERATE_KEYPAIR" | "CREATE_EIP712" | "CREATE_DELEGATED_EIP712" | "DELEGATED_USER_DECRYPT" | "REQUEST_ZK_PROOF_VERIFICATION" | "GET_PUBLIC_KEY" | "GET_PUBLIC_PARAMS";
|
|
16
|
+
interface BaseRequest {
|
|
17
|
+
id: string;
|
|
18
|
+
type: WorkerRequestType;
|
|
19
|
+
}
|
|
20
|
+
interface InitRequest extends BaseRequest {
|
|
21
|
+
type: "INIT";
|
|
22
|
+
payload: {
|
|
23
|
+
cdnUrl: string;
|
|
24
|
+
fhevmConfig: FhevmInstanceConfig;
|
|
25
|
+
csrfToken: string;
|
|
26
|
+
/** Expected SHA-384 hex digest for integrity verification. */
|
|
27
|
+
integrity?: string;
|
|
28
|
+
/** Number of WASM threads for parallel FHE operations. */
|
|
29
|
+
thread?: number;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
interface NodeInitRequest extends BaseRequest {
|
|
33
|
+
type: "NODE_INIT";
|
|
34
|
+
payload: {
|
|
35
|
+
fhevmConfig: FhevmInstanceConfig;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
interface UpdateCsrfRequest extends BaseRequest {
|
|
39
|
+
type: "UPDATE_CSRF";
|
|
40
|
+
payload: {
|
|
41
|
+
csrfToken: string;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface EncryptRequest extends BaseRequest {
|
|
45
|
+
type: "ENCRYPT";
|
|
46
|
+
payload: {
|
|
47
|
+
values: EncryptInput[];
|
|
48
|
+
contractAddress: Address;
|
|
49
|
+
userAddress: Address;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
interface UserDecryptRequest extends BaseRequest {
|
|
53
|
+
type: "USER_DECRYPT";
|
|
54
|
+
payload: {
|
|
55
|
+
handles: string[];
|
|
56
|
+
contractAddress: Address;
|
|
57
|
+
signedContractAddresses: Address[];
|
|
58
|
+
privateKey: string;
|
|
59
|
+
publicKey: string;
|
|
60
|
+
signature: string;
|
|
61
|
+
signerAddress: Address;
|
|
62
|
+
startTimestamp: number;
|
|
63
|
+
durationDays: number;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
interface PublicDecryptRequest extends BaseRequest {
|
|
67
|
+
type: "PUBLIC_DECRYPT";
|
|
68
|
+
payload: {
|
|
69
|
+
handles: string[];
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
interface GenerateKeypairRequest extends BaseRequest {
|
|
73
|
+
type: "GENERATE_KEYPAIR";
|
|
74
|
+
payload: Record<string, never>;
|
|
75
|
+
}
|
|
76
|
+
interface CreateEIP712Request extends BaseRequest {
|
|
77
|
+
type: "CREATE_EIP712";
|
|
78
|
+
payload: {
|
|
79
|
+
publicKey: string;
|
|
80
|
+
contractAddresses: Address[];
|
|
81
|
+
startTimestamp: number;
|
|
82
|
+
durationDays: number;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
interface CreateDelegatedEIP712Request extends BaseRequest {
|
|
86
|
+
type: "CREATE_DELEGATED_EIP712";
|
|
87
|
+
payload: {
|
|
88
|
+
publicKey: string;
|
|
89
|
+
contractAddresses: Address[];
|
|
90
|
+
delegatorAddress: string;
|
|
91
|
+
startTimestamp: number;
|
|
92
|
+
durationDays: number;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
interface DelegatedUserDecryptRequest extends BaseRequest {
|
|
96
|
+
type: "DELEGATED_USER_DECRYPT";
|
|
97
|
+
payload: {
|
|
98
|
+
handles: string[];
|
|
99
|
+
contractAddress: Address;
|
|
100
|
+
signedContractAddresses: Address[];
|
|
101
|
+
privateKey: string;
|
|
102
|
+
publicKey: string;
|
|
103
|
+
signature: string;
|
|
104
|
+
delegatorAddress: Address;
|
|
105
|
+
delegateAddress: Address;
|
|
106
|
+
startTimestamp: number;
|
|
107
|
+
durationDays: number;
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
interface RequestZKProofVerificationRequest extends BaseRequest {
|
|
111
|
+
type: "REQUEST_ZK_PROOF_VERIFICATION";
|
|
112
|
+
payload: {
|
|
113
|
+
zkProof: ZKProofLike;
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
interface GetPublicKeyRequest extends BaseRequest {
|
|
117
|
+
type: "GET_PUBLIC_KEY";
|
|
118
|
+
payload: Record<string, never>;
|
|
119
|
+
}
|
|
120
|
+
interface GetPublicParamsRequest extends BaseRequest {
|
|
121
|
+
type: "GET_PUBLIC_PARAMS";
|
|
122
|
+
payload: {
|
|
123
|
+
bits: number;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
type WorkerRequest = InitRequest | NodeInitRequest | UpdateCsrfRequest | EncryptRequest | UserDecryptRequest | PublicDecryptRequest | GenerateKeypairRequest | CreateEIP712Request | CreateDelegatedEIP712Request | DelegatedUserDecryptRequest | RequestZKProofVerificationRequest | GetPublicKeyRequest | GetPublicParamsRequest;
|
|
127
|
+
type EncryptPayload = EncryptRequest["payload"];
|
|
128
|
+
type UserDecryptPayload = UserDecryptRequest["payload"];
|
|
129
|
+
type DelegatedUserDecryptPayload = DelegatedUserDecryptRequest["payload"];
|
|
130
|
+
type CreateEIP712Payload = CreateEIP712Request["payload"];
|
|
131
|
+
type CreateDelegatedEIP712Payload = CreateDelegatedEIP712Request["payload"];
|
|
132
|
+
interface BaseResponse {
|
|
133
|
+
id: string;
|
|
134
|
+
type: WorkerRequestType;
|
|
135
|
+
}
|
|
136
|
+
interface SuccessResponse<T> extends BaseResponse {
|
|
137
|
+
success: true;
|
|
138
|
+
data: T;
|
|
139
|
+
}
|
|
140
|
+
interface ErrorResponse extends BaseResponse {
|
|
141
|
+
success: false;
|
|
142
|
+
error: string;
|
|
143
|
+
/** HTTP status code from the relayer, when available. */
|
|
144
|
+
statusCode?: number;
|
|
145
|
+
}
|
|
146
|
+
type WorkerResponse<T> = SuccessResponse<T> | ErrorResponse;
|
|
147
|
+
interface EncryptResponseData {
|
|
148
|
+
handles: Uint8Array[];
|
|
149
|
+
inputProof: Uint8Array;
|
|
150
|
+
}
|
|
151
|
+
interface UserDecryptResponseData {
|
|
152
|
+
clearValues: Record<string, DecryptedValue>;
|
|
153
|
+
}
|
|
154
|
+
interface PublicDecryptResponseData {
|
|
155
|
+
clearValues: Record<string, bigint>;
|
|
156
|
+
abiEncodedClearValues: string;
|
|
157
|
+
decryptionProof: Address;
|
|
158
|
+
}
|
|
159
|
+
interface GenerateKeypairResponseData {
|
|
160
|
+
publicKey: string;
|
|
161
|
+
privateKey: string;
|
|
162
|
+
}
|
|
163
|
+
interface CreateEIP712ResponseData {
|
|
164
|
+
domain: {
|
|
165
|
+
name: string;
|
|
166
|
+
version: string;
|
|
167
|
+
chainId: number;
|
|
168
|
+
verifyingContract: Address;
|
|
169
|
+
};
|
|
170
|
+
types: {
|
|
171
|
+
UserDecryptRequestVerification: Array<{
|
|
172
|
+
name: string;
|
|
173
|
+
type: string;
|
|
174
|
+
}>;
|
|
175
|
+
};
|
|
176
|
+
message: {
|
|
177
|
+
publicKey: string;
|
|
178
|
+
contractAddresses: string[];
|
|
179
|
+
startTimestamp: bigint;
|
|
180
|
+
durationDays: bigint;
|
|
181
|
+
extraData: string;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
type CreateDelegatedEIP712ResponseData = KmsDelegatedUserDecryptEIP712Type;
|
|
185
|
+
interface DelegatedUserDecryptResponseData {
|
|
186
|
+
clearValues: Record<string, DecryptedValue>;
|
|
187
|
+
}
|
|
188
|
+
type RequestZKProofVerificationResponseData = InputProofBytesType;
|
|
189
|
+
interface GetPublicKeyResponseData {
|
|
190
|
+
result: {
|
|
191
|
+
publicKeyId: string;
|
|
192
|
+
publicKey: Uint8Array;
|
|
193
|
+
} | null;
|
|
194
|
+
}
|
|
195
|
+
interface GetPublicParamsResponseData {
|
|
196
|
+
result: {
|
|
197
|
+
publicParams: Uint8Array;
|
|
198
|
+
publicParamsId: string;
|
|
199
|
+
} | null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Generic hex-encoded string (signatures, tx hashes, proofs, etc.). */
|
|
203
|
+
type Hex = `0x${string}`;
|
|
204
|
+
/** Network configuration for the Relayer SDK */
|
|
205
|
+
type NetworkType = "hardhat" | "sepolia" | "mainnet";
|
|
206
|
+
/** Security options for RelayerWeb. */
|
|
207
|
+
interface RelayerWebSecurityConfig {
|
|
208
|
+
/** Resolve the current CSRF token. Called before each authenticated network request. */
|
|
209
|
+
getCsrfToken?: () => string;
|
|
210
|
+
/** Verify SHA-384 integrity of the CDN bundle. Defaults to `true`. Set to `false` only in test environments with mocked SDK scripts. */
|
|
211
|
+
integrityCheck?: boolean;
|
|
212
|
+
}
|
|
213
|
+
/** Configuration for RelayerWeb (browser backend) initialization. */
|
|
214
|
+
interface RelayerWebConfig {
|
|
215
|
+
transports: Record<number, Partial<SDK.FhevmInstanceConfig>>;
|
|
216
|
+
/** Resolve the current chain ID. Called lazily before each operation; the worker is re-initialized when the value changes. */
|
|
217
|
+
getChainId: () => Promise<number>;
|
|
218
|
+
/** Security options (CSRF, CDN integrity). */
|
|
219
|
+
security?: RelayerWebSecurityConfig;
|
|
220
|
+
/** Optional logger for observing worker lifecycle and request timing. */
|
|
221
|
+
logger?: GenericLogger;
|
|
222
|
+
/**
|
|
223
|
+
* Number of WASM threads for parallel FHE operations inside the Web Worker.
|
|
224
|
+
* Uses `wasm-bindgen-rayon` under the hood via `SharedArrayBuffer`.
|
|
225
|
+
*
|
|
226
|
+
* **Requirements:** The page must be served with COOP/COEP headers:
|
|
227
|
+
* - `Cross-Origin-Opener-Policy: same-origin`
|
|
228
|
+
* - `Cross-Origin-Embedder-Policy: require-corp`
|
|
229
|
+
*
|
|
230
|
+
* 4–8 threads is the practical sweet spot; beyond that, diminishing returns
|
|
231
|
+
* and higher memory usage on low-end devices.
|
|
232
|
+
*
|
|
233
|
+
* When omitted, the relayer SDK uses its default (single-threaded).
|
|
234
|
+
*/
|
|
235
|
+
threads?: number;
|
|
236
|
+
/** Called whenever the SDK status changes (e.g. idle → initializing → ready). */
|
|
237
|
+
onStatusChange?: (status: RelayerSDKStatus, error?: Error) => void;
|
|
238
|
+
}
|
|
239
|
+
/** Result from encryption operation */
|
|
240
|
+
interface EncryptResult {
|
|
241
|
+
handles: Uint8Array[];
|
|
242
|
+
inputProof: Uint8Array;
|
|
243
|
+
}
|
|
244
|
+
/** Supported FHE encrypted types. */
|
|
245
|
+
type FheType = "ebool" | "euint8" | "euint16" | "euint32" | "euint64" | "euint128" | "euint256" | "eaddress";
|
|
246
|
+
/** A single value to encrypt with its FHE type. */
|
|
247
|
+
interface EncryptInput {
|
|
248
|
+
value: bigint | boolean;
|
|
249
|
+
type: FheType;
|
|
250
|
+
}
|
|
251
|
+
/** Parameters for encryption */
|
|
252
|
+
interface EncryptParams {
|
|
253
|
+
/** Typed inputs for encryption. Each value must specify its FHE type. */
|
|
254
|
+
values: EncryptInput[];
|
|
255
|
+
contractAddress: Address;
|
|
256
|
+
userAddress: Address;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Union of possible decrypted value types.
|
|
260
|
+
* - bigint for euintN types
|
|
261
|
+
* - boolean for ebool
|
|
262
|
+
* - hex string for eaddress
|
|
263
|
+
*/
|
|
264
|
+
type DecryptedValue = bigint | boolean | `0x${string}`;
|
|
265
|
+
/** Parameters for user decryption */
|
|
266
|
+
interface UserDecryptParams {
|
|
267
|
+
handles: string[];
|
|
268
|
+
contractAddress: Address;
|
|
269
|
+
signedContractAddresses: Address[];
|
|
270
|
+
privateKey: string;
|
|
271
|
+
publicKey: string;
|
|
272
|
+
signature: string;
|
|
273
|
+
signerAddress: Address;
|
|
274
|
+
startTimestamp: number;
|
|
275
|
+
durationDays: number;
|
|
276
|
+
}
|
|
277
|
+
/** Result from public decryption */
|
|
278
|
+
interface PublicDecryptResult {
|
|
279
|
+
clearValues: Record<string, bigint>;
|
|
280
|
+
abiEncodedClearValues: string;
|
|
281
|
+
decryptionProof: Address;
|
|
282
|
+
}
|
|
283
|
+
/** Keypair for FHE operations */
|
|
284
|
+
interface FHEKeypair {
|
|
285
|
+
publicKey: string;
|
|
286
|
+
privateKey: string;
|
|
287
|
+
}
|
|
288
|
+
/** EIP712 typed data structure */
|
|
289
|
+
interface EIP712TypedData {
|
|
290
|
+
domain: {
|
|
291
|
+
name: string;
|
|
292
|
+
version: string;
|
|
293
|
+
chainId: number;
|
|
294
|
+
verifyingContract: Address;
|
|
295
|
+
};
|
|
296
|
+
types: {
|
|
297
|
+
[key: string]: Array<{
|
|
298
|
+
name: string;
|
|
299
|
+
type: string;
|
|
300
|
+
}>;
|
|
301
|
+
};
|
|
302
|
+
primaryType?: string;
|
|
303
|
+
message: {
|
|
304
|
+
publicKey: string;
|
|
305
|
+
contractAddresses: string[];
|
|
306
|
+
startTimestamp: bigint;
|
|
307
|
+
durationDays: bigint;
|
|
308
|
+
extraData: string;
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
/** Parameters for delegated user decryption */
|
|
312
|
+
interface DelegatedUserDecryptParams {
|
|
313
|
+
handles: string[];
|
|
314
|
+
contractAddress: Address;
|
|
315
|
+
signedContractAddresses: Address[];
|
|
316
|
+
privateKey: string;
|
|
317
|
+
publicKey: string;
|
|
318
|
+
signature: string;
|
|
319
|
+
delegatorAddress: Address;
|
|
320
|
+
delegateAddress: Address;
|
|
321
|
+
startTimestamp: number;
|
|
322
|
+
durationDays: number;
|
|
323
|
+
}
|
|
324
|
+
/** SDK status */
|
|
325
|
+
type RelayerSDKStatus = "idle" | "initializing" | "ready" | "error";
|
|
326
|
+
|
|
327
|
+
export type { PublicDecryptRequest as A, BaseRequest as B, CreateEIP712Payload as C, DecryptedValue as D, EIP712TypedData as E, FHEKeypair as F, GenericLogger as G, Hex as H, InitRequest as I, RequestZKProofVerificationRequest as J, UpdateCsrfRequest as K, UserDecryptRequest as L, RelayerWebConfig as M, NodeInitRequest as N, RelayerSDKStatus as O, PublicDecryptResult as P, EncryptInput as Q, RequestZKProofVerificationResponseData as R, SuccessResponse as S, FheType as T, UserDecryptParams as U, NetworkType as V, WorkerRequest as W, RelayerWebSecurityConfig as X, EncryptParams as a, EncryptResult as b, DelegatedUserDecryptParams as c, WorkerRequestType as d, WorkerResponse as e, GenerateKeypairResponseData as f, CreateEIP712ResponseData as g, EncryptPayload as h, EncryptResponseData as i, UserDecryptPayload as j, UserDecryptResponseData as k, PublicDecryptResponseData as l, CreateDelegatedEIP712Payload as m, CreateDelegatedEIP712ResponseData as n, DelegatedUserDecryptPayload as o, DelegatedUserDecryptResponseData as p, GetPublicKeyResponseData as q, GetPublicParamsResponseData as r, CreateDelegatedEIP712Request as s, CreateEIP712Request as t, DelegatedUserDecryptRequest as u, EncryptRequest as v, ErrorResponse as w, GenerateKeypairRequest as x, GetPublicKeyRequest as y, GetPublicParamsRequest as z };
|