@pyratzlabs/react-fhevm-utils 0.4.0 → 1.0.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.
@@ -7,6 +7,7 @@ interface ProviderProps {
7
7
  }
8
8
  interface ContextProps {
9
9
  instance?: FhevmInstance;
10
+ config?: FhevmConfig;
10
11
  }
11
12
  export declare const FhevmContext: React.Context<ContextProps>;
12
13
  declare const FhevmProvider: ({ children, config }: ProviderProps) => import("react/jsx-runtime").JSX.Element;
@@ -12,6 +12,7 @@ import { createContext, useContext, useEffect, useState, } from "react";
12
12
  import { getOrCreateFhevmInstance } from "../lib/fhevm";
13
13
  export const FhevmContext = createContext({
14
14
  instance: undefined,
15
+ config: undefined,
15
16
  });
16
17
  const FhevmProvider = ({ children, config }) => {
17
18
  const [instance, setInstance] = useState();
@@ -27,7 +28,7 @@ const FhevmProvider = ({ children, config }) => {
27
28
  useEffect(() => {
28
29
  initFhevm();
29
30
  }, []);
30
- return (_jsx(FhevmContext.Provider, { value: { instance }, children: children }));
31
+ return (_jsx(FhevmContext.Provider, { value: { instance, config }, children: children }));
31
32
  };
32
33
  export const useFhevmContext = () => useContext(FhevmContext);
33
34
  export default FhevmProvider;
@@ -0,0 +1,77 @@
1
+ import { Address } from "viem";
2
+ export interface EncryptValueParams {
3
+ tokenAddress: Address;
4
+ }
5
+ export interface EncryptionResult {
6
+ handles: Uint8Array[];
7
+ inputProof: Uint8Array;
8
+ }
9
+ export declare const useEncryptValue: ({ tokenAddress }: EncryptValueParams) => {
10
+ data: undefined;
11
+ variables: undefined;
12
+ error: null;
13
+ isError: false;
14
+ isIdle: true;
15
+ isPending: false;
16
+ isSuccess: false;
17
+ status: "idle";
18
+ mutate: import("@tanstack/react-query").UseMutateFunction<EncryptionResult, Error, bigint, unknown>;
19
+ reset: () => void;
20
+ context: unknown;
21
+ failureCount: number;
22
+ failureReason: Error | null;
23
+ isPaused: boolean;
24
+ submittedAt: number;
25
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<EncryptionResult, Error, bigint, unknown>;
26
+ } | {
27
+ data: undefined;
28
+ variables: bigint;
29
+ error: null;
30
+ isError: false;
31
+ isIdle: false;
32
+ isPending: true;
33
+ isSuccess: false;
34
+ status: "pending";
35
+ mutate: import("@tanstack/react-query").UseMutateFunction<EncryptionResult, Error, bigint, unknown>;
36
+ reset: () => void;
37
+ context: unknown;
38
+ failureCount: number;
39
+ failureReason: Error | null;
40
+ isPaused: boolean;
41
+ submittedAt: number;
42
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<EncryptionResult, Error, bigint, unknown>;
43
+ } | {
44
+ data: undefined;
45
+ error: Error;
46
+ variables: bigint;
47
+ isError: true;
48
+ isIdle: false;
49
+ isPending: false;
50
+ isSuccess: false;
51
+ status: "error";
52
+ mutate: import("@tanstack/react-query").UseMutateFunction<EncryptionResult, Error, bigint, unknown>;
53
+ reset: () => void;
54
+ context: unknown;
55
+ failureCount: number;
56
+ failureReason: Error | null;
57
+ isPaused: boolean;
58
+ submittedAt: number;
59
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<EncryptionResult, Error, bigint, unknown>;
60
+ } | {
61
+ data: EncryptionResult;
62
+ error: null;
63
+ variables: bigint;
64
+ isError: false;
65
+ isIdle: false;
66
+ isPending: false;
67
+ isSuccess: true;
68
+ status: "success";
69
+ mutate: import("@tanstack/react-query").UseMutateFunction<EncryptionResult, Error, bigint, unknown>;
70
+ reset: () => void;
71
+ context: unknown;
72
+ failureCount: number;
73
+ failureReason: Error | null;
74
+ isPaused: boolean;
75
+ submittedAt: number;
76
+ mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<EncryptionResult, Error, bigint, unknown>;
77
+ };
@@ -0,0 +1,50 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { useMutation } from "@tanstack/react-query";
11
+ import { useEffect, useRef } from "react";
12
+ import { useAccount } from "wagmi";
13
+ import { useFhevmContext } from "../context/FhevmProvider";
14
+ export const useEncryptValue = ({ tokenAddress }) => {
15
+ const { instance, config } = useFhevmContext();
16
+ const { address } = useAccount();
17
+ const workerRef = useRef(null);
18
+ useEffect(() => {
19
+ workerRef.current = new Worker(new URL("../workers/encryption.worker", import.meta.url), { type: "module" });
20
+ return () => {
21
+ var _a;
22
+ (_a = workerRef.current) === null || _a === void 0 ? void 0 : _a.terminate();
23
+ };
24
+ }, []);
25
+ const encryptMutation = useMutation({
26
+ mutationFn: (value) => __awaiter(void 0, void 0, void 0, function* () {
27
+ if (!instance)
28
+ throw new Error("Instance is not defined");
29
+ if (!address)
30
+ throw new Error("User is not connected");
31
+ const encryption = new Promise((resolve, reject) => {
32
+ if (!workerRef.current)
33
+ return reject("Worker not initialized");
34
+ workerRef.current.onmessage = (event) => {
35
+ if (event.data.error) {
36
+ reject(event.data.error);
37
+ }
38
+ else {
39
+ resolve(event.data.result);
40
+ }
41
+ };
42
+ workerRef.current.postMessage(Object.assign({ tokenAddress,
43
+ address,
44
+ value }, config));
45
+ });
46
+ return encryption;
47
+ }),
48
+ });
49
+ return Object.assign({}, encryptMutation);
50
+ };
@@ -0,0 +1,11 @@
1
+ import { Address } from "viem";
2
+ export interface EncryptedTransferProps {
3
+ tokenAddress: Address;
4
+ }
5
+ export declare const useEncryptedTransfer: ({ tokenAddress, }: EncryptedTransferProps) => {
6
+ transfer: (to: Address, handles: Uint8Array[], inputProof: Uint8Array) => void;
7
+ isLoading: boolean;
8
+ isFailed: boolean;
9
+ isSuccess: boolean;
10
+ error: import("@wagmi/core").WriteContractErrorType | null;
11
+ };
@@ -0,0 +1,20 @@
1
+ import { usePerformTransaction } from "./usePerformTransaction";
2
+ import { encryptedABI } from "../types/encryptedABI";
3
+ import { toHexString } from "../utils/string.utils";
4
+ export const useEncryptedTransfer = ({ tokenAddress, }) => {
5
+ const { perform, isLoading, isFailed, isSuccess, error } = usePerformTransaction({
6
+ abi: encryptedABI,
7
+ address: tokenAddress,
8
+ functionName: "transfer",
9
+ });
10
+ const transfer = (to, handles, inputProof) => {
11
+ if (handles.length === 0)
12
+ throw new Error("Bad handles format");
13
+ const encryptedAmount = toHexString(handles[0]);
14
+ const proof = toHexString(inputProof);
15
+ perform({
16
+ args: [to, encryptedAmount, proof],
17
+ });
18
+ };
19
+ return { transfer, isLoading, isFailed, isSuccess, error };
20
+ };
@@ -0,0 +1,7 @@
1
+ import { Address } from "viem";
2
+ export interface GetEncryptedBalanceParams {
3
+ tokenAddress: Address;
4
+ }
5
+ export declare const useGetEncryptedBalance: ({ tokenAddress, }: GetEncryptedBalanceParams) => {
6
+ encryptedBalance: BigInt | undefined;
7
+ };
@@ -0,0 +1,16 @@
1
+ import { useAccount, useReadContract } from "wagmi";
2
+ import { encryptedABI } from "../types/encryptedABI";
3
+ export const useGetEncryptedBalance = ({ tokenAddress, }) => {
4
+ const { address } = useAccount();
5
+ const { data } = useReadContract({
6
+ address: tokenAddress,
7
+ abi: encryptedABI,
8
+ functionName: "balanceOf",
9
+ args: [address],
10
+ query: {
11
+ enabled: !!address,
12
+ refetchInterval: 5000,
13
+ },
14
+ });
15
+ return { encryptedBalance: data };
16
+ };
@@ -0,0 +1,3 @@
1
+ export declare const useGetFhevmConfig: () => {
2
+ config: import("..").FhevmConfig | undefined;
3
+ };
@@ -0,0 +1,5 @@
1
+ import { useFhevmContext } from "../context/FhevmProvider";
2
+ export const useGetFhevmConfig = () => {
3
+ const { config } = useFhevmContext();
4
+ return { config };
5
+ };
@@ -0,0 +1,17 @@
1
+ import { Abi, Address, ContractFunctionArgs, ContractFunctionName } from "viem";
2
+ interface Props<TAbi extends Abi, TFunction extends ContractFunctionName<TAbi, "nonpayable" | "payable">> {
3
+ abi: TAbi;
4
+ address: Address;
5
+ functionName: TFunction;
6
+ }
7
+ export declare const usePerformTransaction: <TAbi extends Abi, TFunction extends ContractFunctionName<TAbi, "nonpayable" | "payable">>({ abi, address, functionName, }: Props<TAbi, TFunction>) => {
8
+ error: import("@wagmi/core").WriteContractErrorType | null;
9
+ isSuccess: boolean;
10
+ isLoading: boolean;
11
+ isFailed: boolean;
12
+ perform: ({ args, value, }: {
13
+ args: ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunction>;
14
+ value?: bigint;
15
+ }) => Promise<void>;
16
+ };
17
+ export {};
@@ -0,0 +1,40 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { useConfig, useWaitForTransactionReceipt, useWriteContract, } from "wagmi";
11
+ import { simulateContract } from "@wagmi/core";
12
+ export const usePerformTransaction = ({ abi, address, functionName, }) => {
13
+ const config = useConfig();
14
+ const { writeContract, data: writeContractData, isError: isWriteError, error, } = useWriteContract();
15
+ const { isSuccess, isLoading, isError } = useWaitForTransactionReceipt({
16
+ hash: writeContractData,
17
+ });
18
+ const perform = (_a) => __awaiter(void 0, [_a], void 0, function* ({ args, value, }) {
19
+ try {
20
+ const result = yield simulateContract(config, {
21
+ address,
22
+ abi: abi,
23
+ functionName,
24
+ value,
25
+ args: args,
26
+ });
27
+ writeContract(result.request);
28
+ }
29
+ catch (error) {
30
+ throw new Error(`Simulation failed: ${error}`);
31
+ }
32
+ });
33
+ return {
34
+ error,
35
+ isSuccess,
36
+ isLoading,
37
+ isFailed: isError || isWriteError,
38
+ perform,
39
+ };
40
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  export { default } from "./context/FhevmProvider";
2
2
  export { useFhevmInstance } from "./hooks/useFhevmInstance";
3
3
  export { useDecryptBalance } from "./hooks/useDecryptBalance";
4
+ export { useGetEncryptedBalance } from "./hooks/useGetEncryptedBalance";
5
+ export { useEncryptedTransfer } from "./hooks/useEncryptedTransfer";
6
+ export { useEncryptValue } from "./hooks/useEncryptValue";
7
+ export { type FhevmConfig } from "./types/fhevmConfig";
package/dist/index.js CHANGED
@@ -3,3 +3,6 @@ export { default } from "./context/FhevmProvider";
3
3
  // hooks
4
4
  export { useFhevmInstance } from "./hooks/useFhevmInstance";
5
5
  export { useDecryptBalance } from "./hooks/useDecryptBalance";
6
+ export { useGetEncryptedBalance } from "./hooks/useGetEncryptedBalance";
7
+ export { useEncryptedTransfer } from "./hooks/useEncryptedTransfer";
8
+ export { useEncryptValue } from "./hooks/useEncryptValue";
@@ -0,0 +1,472 @@
1
+ export declare const encryptedABI: readonly [{
2
+ readonly inputs: readonly [{
3
+ readonly internalType: "string";
4
+ readonly name: "name_";
5
+ readonly type: "string";
6
+ }, {
7
+ readonly internalType: "string";
8
+ readonly name: "symbol_";
9
+ readonly type: "string";
10
+ }, {
11
+ readonly internalType: "address";
12
+ readonly name: "admin_";
13
+ readonly type: "address";
14
+ }];
15
+ readonly stateMutability: "nonpayable";
16
+ readonly type: "constructor";
17
+ }, {
18
+ readonly inputs: readonly [{
19
+ readonly internalType: "address";
20
+ readonly name: "spender";
21
+ readonly type: "address";
22
+ }, {
23
+ readonly internalType: "uint256";
24
+ readonly name: "allowance";
25
+ readonly type: "uint256";
26
+ }, {
27
+ readonly internalType: "uint256";
28
+ readonly name: "needed";
29
+ readonly type: "uint256";
30
+ }];
31
+ readonly name: "ERC20InsufficientAllowance";
32
+ readonly type: "error";
33
+ }, {
34
+ readonly inputs: readonly [{
35
+ readonly internalType: "address";
36
+ readonly name: "sender";
37
+ readonly type: "address";
38
+ }, {
39
+ readonly internalType: "uint256";
40
+ readonly name: "balance";
41
+ readonly type: "uint256";
42
+ }, {
43
+ readonly internalType: "uint256";
44
+ readonly name: "needed";
45
+ readonly type: "uint256";
46
+ }];
47
+ readonly name: "ERC20InsufficientBalance";
48
+ readonly type: "error";
49
+ }, {
50
+ readonly inputs: readonly [{
51
+ readonly internalType: "address";
52
+ readonly name: "approver";
53
+ readonly type: "address";
54
+ }];
55
+ readonly name: "ERC20InvalidApprover";
56
+ readonly type: "error";
57
+ }, {
58
+ readonly inputs: readonly [{
59
+ readonly internalType: "address";
60
+ readonly name: "receiver";
61
+ readonly type: "address";
62
+ }];
63
+ readonly name: "ERC20InvalidReceiver";
64
+ readonly type: "error";
65
+ }, {
66
+ readonly inputs: readonly [{
67
+ readonly internalType: "address";
68
+ readonly name: "sender";
69
+ readonly type: "address";
70
+ }];
71
+ readonly name: "ERC20InvalidSender";
72
+ readonly type: "error";
73
+ }, {
74
+ readonly inputs: readonly [{
75
+ readonly internalType: "address";
76
+ readonly name: "spender";
77
+ readonly type: "address";
78
+ }];
79
+ readonly name: "ERC20InvalidSpender";
80
+ readonly type: "error";
81
+ }, {
82
+ readonly inputs: readonly [{
83
+ readonly internalType: "address";
84
+ readonly name: "owner";
85
+ readonly type: "address";
86
+ }];
87
+ readonly name: "OwnableInvalidOwner";
88
+ readonly type: "error";
89
+ }, {
90
+ readonly inputs: readonly [{
91
+ readonly internalType: "address";
92
+ readonly name: "account";
93
+ readonly type: "address";
94
+ }];
95
+ readonly name: "OwnableUnauthorizedAccount";
96
+ readonly type: "error";
97
+ }, {
98
+ readonly inputs: readonly [];
99
+ readonly name: "TFHESenderNotAllowed";
100
+ readonly type: "error";
101
+ }, {
102
+ readonly anonymous: false;
103
+ readonly inputs: readonly [{
104
+ readonly indexed: true;
105
+ readonly internalType: "address";
106
+ readonly name: "owner";
107
+ readonly type: "address";
108
+ }, {
109
+ readonly indexed: true;
110
+ readonly internalType: "address";
111
+ readonly name: "spender";
112
+ readonly type: "address";
113
+ }, {
114
+ readonly indexed: false;
115
+ readonly internalType: "uint256";
116
+ readonly name: "placeholder";
117
+ readonly type: "uint256";
118
+ }];
119
+ readonly name: "Approval";
120
+ readonly type: "event";
121
+ }, {
122
+ readonly anonymous: false;
123
+ readonly inputs: readonly [{
124
+ readonly indexed: true;
125
+ readonly internalType: "address";
126
+ readonly name: "to";
127
+ readonly type: "address";
128
+ }, {
129
+ readonly indexed: false;
130
+ readonly internalType: "uint64";
131
+ readonly name: "amount";
132
+ readonly type: "uint64";
133
+ }];
134
+ readonly name: "Mint";
135
+ readonly type: "event";
136
+ }, {
137
+ readonly anonymous: false;
138
+ readonly inputs: readonly [{
139
+ readonly indexed: true;
140
+ readonly internalType: "address";
141
+ readonly name: "previousOwner";
142
+ readonly type: "address";
143
+ }, {
144
+ readonly indexed: true;
145
+ readonly internalType: "address";
146
+ readonly name: "newOwner";
147
+ readonly type: "address";
148
+ }];
149
+ readonly name: "OwnershipTransferStarted";
150
+ readonly type: "event";
151
+ }, {
152
+ readonly anonymous: false;
153
+ readonly inputs: readonly [{
154
+ readonly indexed: true;
155
+ readonly internalType: "address";
156
+ readonly name: "previousOwner";
157
+ readonly type: "address";
158
+ }, {
159
+ readonly indexed: true;
160
+ readonly internalType: "address";
161
+ readonly name: "newOwner";
162
+ readonly type: "address";
163
+ }];
164
+ readonly name: "OwnershipTransferred";
165
+ readonly type: "event";
166
+ }, {
167
+ readonly anonymous: false;
168
+ readonly inputs: readonly [{
169
+ readonly indexed: true;
170
+ readonly internalType: "address";
171
+ readonly name: "from";
172
+ readonly type: "address";
173
+ }, {
174
+ readonly indexed: true;
175
+ readonly internalType: "address";
176
+ readonly name: "to";
177
+ readonly type: "address";
178
+ }, {
179
+ readonly indexed: false;
180
+ readonly internalType: "uint256";
181
+ readonly name: "transferId";
182
+ readonly type: "uint256";
183
+ }];
184
+ readonly name: "Transfer";
185
+ readonly type: "event";
186
+ }, {
187
+ readonly anonymous: false;
188
+ readonly inputs: readonly [{
189
+ readonly indexed: true;
190
+ readonly internalType: "address";
191
+ readonly name: "from";
192
+ readonly type: "address";
193
+ }, {
194
+ readonly indexed: true;
195
+ readonly internalType: "address";
196
+ readonly name: "to";
197
+ readonly type: "address";
198
+ }, {
199
+ readonly indexed: false;
200
+ readonly internalType: "euint64";
201
+ readonly name: "amount";
202
+ readonly type: "uint256";
203
+ }];
204
+ readonly name: "TransferInfo";
205
+ readonly type: "event";
206
+ }, {
207
+ readonly inputs: readonly [];
208
+ readonly name: "acceptOwnership";
209
+ readonly outputs: readonly [];
210
+ readonly stateMutability: "nonpayable";
211
+ readonly type: "function";
212
+ }, {
213
+ readonly inputs: readonly [{
214
+ readonly internalType: "address";
215
+ readonly name: "owner";
216
+ readonly type: "address";
217
+ }, {
218
+ readonly internalType: "address";
219
+ readonly name: "spender";
220
+ readonly type: "address";
221
+ }];
222
+ readonly name: "allowance";
223
+ readonly outputs: readonly [{
224
+ readonly internalType: "euint64";
225
+ readonly name: "";
226
+ readonly type: "uint256";
227
+ }];
228
+ readonly stateMutability: "view";
229
+ readonly type: "function";
230
+ }, {
231
+ readonly inputs: readonly [{
232
+ readonly internalType: "address";
233
+ readonly name: "spender";
234
+ readonly type: "address";
235
+ }, {
236
+ readonly internalType: "euint64";
237
+ readonly name: "amount";
238
+ readonly type: "uint256";
239
+ }];
240
+ readonly name: "approve";
241
+ readonly outputs: readonly [{
242
+ readonly internalType: "bool";
243
+ readonly name: "";
244
+ readonly type: "bool";
245
+ }];
246
+ readonly stateMutability: "nonpayable";
247
+ readonly type: "function";
248
+ }, {
249
+ readonly inputs: readonly [{
250
+ readonly internalType: "address";
251
+ readonly name: "spender";
252
+ readonly type: "address";
253
+ }, {
254
+ readonly internalType: "einput";
255
+ readonly name: "encryptedAmount";
256
+ readonly type: "bytes32";
257
+ }, {
258
+ readonly internalType: "bytes";
259
+ readonly name: "inputProof";
260
+ readonly type: "bytes";
261
+ }];
262
+ readonly name: "approve";
263
+ readonly outputs: readonly [{
264
+ readonly internalType: "bool";
265
+ readonly name: "";
266
+ readonly type: "bool";
267
+ }];
268
+ readonly stateMutability: "nonpayable";
269
+ readonly type: "function";
270
+ }, {
271
+ readonly inputs: readonly [{
272
+ readonly internalType: "address";
273
+ readonly name: "account";
274
+ readonly type: "address";
275
+ }];
276
+ readonly name: "balanceOf";
277
+ readonly outputs: readonly [{
278
+ readonly internalType: "euint64";
279
+ readonly name: "";
280
+ readonly type: "uint256";
281
+ }];
282
+ readonly stateMutability: "view";
283
+ readonly type: "function";
284
+ }, {
285
+ readonly inputs: readonly [];
286
+ readonly name: "decimals";
287
+ readonly outputs: readonly [{
288
+ readonly internalType: "uint8";
289
+ readonly name: "";
290
+ readonly type: "uint8";
291
+ }];
292
+ readonly stateMutability: "view";
293
+ readonly type: "function";
294
+ }, {
295
+ readonly inputs: readonly [{
296
+ readonly internalType: "address";
297
+ readonly name: "to";
298
+ readonly type: "address";
299
+ }, {
300
+ readonly internalType: "uint64";
301
+ readonly name: "amount";
302
+ readonly type: "uint64";
303
+ }];
304
+ readonly name: "mint";
305
+ readonly outputs: readonly [];
306
+ readonly stateMutability: "nonpayable";
307
+ readonly type: "function";
308
+ }, {
309
+ readonly inputs: readonly [{
310
+ readonly internalType: "address";
311
+ readonly name: "to";
312
+ readonly type: "address";
313
+ }];
314
+ readonly name: "mintTenThousand";
315
+ readonly outputs: readonly [];
316
+ readonly stateMutability: "nonpayable";
317
+ readonly type: "function";
318
+ }, {
319
+ readonly inputs: readonly [];
320
+ readonly name: "name";
321
+ readonly outputs: readonly [{
322
+ readonly internalType: "string";
323
+ readonly name: "";
324
+ readonly type: "string";
325
+ }];
326
+ readonly stateMutability: "view";
327
+ readonly type: "function";
328
+ }, {
329
+ readonly inputs: readonly [];
330
+ readonly name: "owner";
331
+ readonly outputs: readonly [{
332
+ readonly internalType: "address";
333
+ readonly name: "";
334
+ readonly type: "address";
335
+ }];
336
+ readonly stateMutability: "view";
337
+ readonly type: "function";
338
+ }, {
339
+ readonly inputs: readonly [];
340
+ readonly name: "pendingOwner";
341
+ readonly outputs: readonly [{
342
+ readonly internalType: "address";
343
+ readonly name: "";
344
+ readonly type: "address";
345
+ }];
346
+ readonly stateMutability: "view";
347
+ readonly type: "function";
348
+ }, {
349
+ readonly inputs: readonly [];
350
+ readonly name: "renounceOwnership";
351
+ readonly outputs: readonly [];
352
+ readonly stateMutability: "nonpayable";
353
+ readonly type: "function";
354
+ }, {
355
+ readonly inputs: readonly [];
356
+ readonly name: "symbol";
357
+ readonly outputs: readonly [{
358
+ readonly internalType: "string";
359
+ readonly name: "";
360
+ readonly type: "string";
361
+ }];
362
+ readonly stateMutability: "view";
363
+ readonly type: "function";
364
+ }, {
365
+ readonly inputs: readonly [];
366
+ readonly name: "totalSupply";
367
+ readonly outputs: readonly [{
368
+ readonly internalType: "uint64";
369
+ readonly name: "";
370
+ readonly type: "uint64";
371
+ }];
372
+ readonly stateMutability: "view";
373
+ readonly type: "function";
374
+ }, {
375
+ readonly inputs: readonly [{
376
+ readonly internalType: "address";
377
+ readonly name: "to";
378
+ readonly type: "address";
379
+ }, {
380
+ readonly internalType: "einput";
381
+ readonly name: "encryptedAmount";
382
+ readonly type: "bytes32";
383
+ }, {
384
+ readonly internalType: "bytes";
385
+ readonly name: "inputProof";
386
+ readonly type: "bytes";
387
+ }];
388
+ readonly name: "transfer";
389
+ readonly outputs: readonly [{
390
+ readonly internalType: "bool";
391
+ readonly name: "";
392
+ readonly type: "bool";
393
+ }];
394
+ readonly stateMutability: "nonpayable";
395
+ readonly type: "function";
396
+ }, {
397
+ readonly inputs: readonly [{
398
+ readonly internalType: "address";
399
+ readonly name: "to";
400
+ readonly type: "address";
401
+ }, {
402
+ readonly internalType: "euint64";
403
+ readonly name: "amount";
404
+ readonly type: "uint256";
405
+ }];
406
+ readonly name: "transfer";
407
+ readonly outputs: readonly [{
408
+ readonly internalType: "bool";
409
+ readonly name: "";
410
+ readonly type: "bool";
411
+ }];
412
+ readonly stateMutability: "nonpayable";
413
+ readonly type: "function";
414
+ }, {
415
+ readonly inputs: readonly [{
416
+ readonly internalType: "address";
417
+ readonly name: "from";
418
+ readonly type: "address";
419
+ }, {
420
+ readonly internalType: "address";
421
+ readonly name: "to";
422
+ readonly type: "address";
423
+ }, {
424
+ readonly internalType: "euint64";
425
+ readonly name: "amount";
426
+ readonly type: "uint256";
427
+ }];
428
+ readonly name: "transferFrom";
429
+ readonly outputs: readonly [{
430
+ readonly internalType: "bool";
431
+ readonly name: "";
432
+ readonly type: "bool";
433
+ }];
434
+ readonly stateMutability: "nonpayable";
435
+ readonly type: "function";
436
+ }, {
437
+ readonly inputs: readonly [{
438
+ readonly internalType: "address";
439
+ readonly name: "from";
440
+ readonly type: "address";
441
+ }, {
442
+ readonly internalType: "address";
443
+ readonly name: "to";
444
+ readonly type: "address";
445
+ }, {
446
+ readonly internalType: "einput";
447
+ readonly name: "encryptedAmount";
448
+ readonly type: "bytes32";
449
+ }, {
450
+ readonly internalType: "bytes";
451
+ readonly name: "inputProof";
452
+ readonly type: "bytes";
453
+ }];
454
+ readonly name: "transferFrom";
455
+ readonly outputs: readonly [{
456
+ readonly internalType: "bool";
457
+ readonly name: "";
458
+ readonly type: "bool";
459
+ }];
460
+ readonly stateMutability: "nonpayable";
461
+ readonly type: "function";
462
+ }, {
463
+ readonly inputs: readonly [{
464
+ readonly internalType: "address";
465
+ readonly name: "newOwner";
466
+ readonly type: "address";
467
+ }];
468
+ readonly name: "transferOwnership";
469
+ readonly outputs: readonly [];
470
+ readonly stateMutability: "nonpayable";
471
+ readonly type: "function";
472
+ }];
@@ -0,0 +1,329 @@
1
+ export const encryptedABI = [
2
+ {
3
+ inputs: [
4
+ { internalType: "string", name: "name_", type: "string" },
5
+ { internalType: "string", name: "symbol_", type: "string" },
6
+ { internalType: "address", name: "admin_", type: "address" },
7
+ ],
8
+ stateMutability: "nonpayable",
9
+ type: "constructor",
10
+ },
11
+ {
12
+ inputs: [
13
+ { internalType: "address", name: "spender", type: "address" },
14
+ { internalType: "uint256", name: "allowance", type: "uint256" },
15
+ { internalType: "uint256", name: "needed", type: "uint256" },
16
+ ],
17
+ name: "ERC20InsufficientAllowance",
18
+ type: "error",
19
+ },
20
+ {
21
+ inputs: [
22
+ { internalType: "address", name: "sender", type: "address" },
23
+ { internalType: "uint256", name: "balance", type: "uint256" },
24
+ { internalType: "uint256", name: "needed", type: "uint256" },
25
+ ],
26
+ name: "ERC20InsufficientBalance",
27
+ type: "error",
28
+ },
29
+ {
30
+ inputs: [{ internalType: "address", name: "approver", type: "address" }],
31
+ name: "ERC20InvalidApprover",
32
+ type: "error",
33
+ },
34
+ {
35
+ inputs: [{ internalType: "address", name: "receiver", type: "address" }],
36
+ name: "ERC20InvalidReceiver",
37
+ type: "error",
38
+ },
39
+ {
40
+ inputs: [{ internalType: "address", name: "sender", type: "address" }],
41
+ name: "ERC20InvalidSender",
42
+ type: "error",
43
+ },
44
+ {
45
+ inputs: [{ internalType: "address", name: "spender", type: "address" }],
46
+ name: "ERC20InvalidSpender",
47
+ type: "error",
48
+ },
49
+ {
50
+ inputs: [{ internalType: "address", name: "owner", type: "address" }],
51
+ name: "OwnableInvalidOwner",
52
+ type: "error",
53
+ },
54
+ {
55
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
56
+ name: "OwnableUnauthorizedAccount",
57
+ type: "error",
58
+ },
59
+ { inputs: [], name: "TFHESenderNotAllowed", type: "error" },
60
+ {
61
+ anonymous: false,
62
+ inputs: [
63
+ {
64
+ indexed: true,
65
+ internalType: "address",
66
+ name: "owner",
67
+ type: "address",
68
+ },
69
+ {
70
+ indexed: true,
71
+ internalType: "address",
72
+ name: "spender",
73
+ type: "address",
74
+ },
75
+ {
76
+ indexed: false,
77
+ internalType: "uint256",
78
+ name: "placeholder",
79
+ type: "uint256",
80
+ },
81
+ ],
82
+ name: "Approval",
83
+ type: "event",
84
+ },
85
+ {
86
+ anonymous: false,
87
+ inputs: [
88
+ { indexed: true, internalType: "address", name: "to", type: "address" },
89
+ {
90
+ indexed: false,
91
+ internalType: "uint64",
92
+ name: "amount",
93
+ type: "uint64",
94
+ },
95
+ ],
96
+ name: "Mint",
97
+ type: "event",
98
+ },
99
+ {
100
+ anonymous: false,
101
+ inputs: [
102
+ {
103
+ indexed: true,
104
+ internalType: "address",
105
+ name: "previousOwner",
106
+ type: "address",
107
+ },
108
+ {
109
+ indexed: true,
110
+ internalType: "address",
111
+ name: "newOwner",
112
+ type: "address",
113
+ },
114
+ ],
115
+ name: "OwnershipTransferStarted",
116
+ type: "event",
117
+ },
118
+ {
119
+ anonymous: false,
120
+ inputs: [
121
+ {
122
+ indexed: true,
123
+ internalType: "address",
124
+ name: "previousOwner",
125
+ type: "address",
126
+ },
127
+ {
128
+ indexed: true,
129
+ internalType: "address",
130
+ name: "newOwner",
131
+ type: "address",
132
+ },
133
+ ],
134
+ name: "OwnershipTransferred",
135
+ type: "event",
136
+ },
137
+ {
138
+ anonymous: false,
139
+ inputs: [
140
+ { indexed: true, internalType: "address", name: "from", type: "address" },
141
+ { indexed: true, internalType: "address", name: "to", type: "address" },
142
+ {
143
+ indexed: false,
144
+ internalType: "uint256",
145
+ name: "transferId",
146
+ type: "uint256",
147
+ },
148
+ ],
149
+ name: "Transfer",
150
+ type: "event",
151
+ },
152
+ {
153
+ anonymous: false,
154
+ inputs: [
155
+ { indexed: true, internalType: "address", name: "from", type: "address" },
156
+ { indexed: true, internalType: "address", name: "to", type: "address" },
157
+ {
158
+ indexed: false,
159
+ internalType: "euint64",
160
+ name: "amount",
161
+ type: "uint256",
162
+ },
163
+ ],
164
+ name: "TransferInfo",
165
+ type: "event",
166
+ },
167
+ {
168
+ inputs: [],
169
+ name: "acceptOwnership",
170
+ outputs: [],
171
+ stateMutability: "nonpayable",
172
+ type: "function",
173
+ },
174
+ {
175
+ inputs: [
176
+ { internalType: "address", name: "owner", type: "address" },
177
+ { internalType: "address", name: "spender", type: "address" },
178
+ ],
179
+ name: "allowance",
180
+ outputs: [{ internalType: "euint64", name: "", type: "uint256" }],
181
+ stateMutability: "view",
182
+ type: "function",
183
+ },
184
+ {
185
+ inputs: [
186
+ { internalType: "address", name: "spender", type: "address" },
187
+ { internalType: "euint64", name: "amount", type: "uint256" },
188
+ ],
189
+ name: "approve",
190
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
191
+ stateMutability: "nonpayable",
192
+ type: "function",
193
+ },
194
+ {
195
+ inputs: [
196
+ { internalType: "address", name: "spender", type: "address" },
197
+ { internalType: "einput", name: "encryptedAmount", type: "bytes32" },
198
+ { internalType: "bytes", name: "inputProof", type: "bytes" },
199
+ ],
200
+ name: "approve",
201
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
202
+ stateMutability: "nonpayable",
203
+ type: "function",
204
+ },
205
+ {
206
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
207
+ name: "balanceOf",
208
+ outputs: [{ internalType: "euint64", name: "", type: "uint256" }],
209
+ stateMutability: "view",
210
+ type: "function",
211
+ },
212
+ {
213
+ inputs: [],
214
+ name: "decimals",
215
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
216
+ stateMutability: "view",
217
+ type: "function",
218
+ },
219
+ {
220
+ inputs: [
221
+ { internalType: "address", name: "to", type: "address" },
222
+ { internalType: "uint64", name: "amount", type: "uint64" },
223
+ ],
224
+ name: "mint",
225
+ outputs: [],
226
+ stateMutability: "nonpayable",
227
+ type: "function",
228
+ },
229
+ {
230
+ inputs: [{ internalType: "address", name: "to", type: "address" }],
231
+ name: "mintTenThousand",
232
+ outputs: [],
233
+ stateMutability: "nonpayable",
234
+ type: "function",
235
+ },
236
+ {
237
+ inputs: [],
238
+ name: "name",
239
+ outputs: [{ internalType: "string", name: "", type: "string" }],
240
+ stateMutability: "view",
241
+ type: "function",
242
+ },
243
+ {
244
+ inputs: [],
245
+ name: "owner",
246
+ outputs: [{ internalType: "address", name: "", type: "address" }],
247
+ stateMutability: "view",
248
+ type: "function",
249
+ },
250
+ {
251
+ inputs: [],
252
+ name: "pendingOwner",
253
+ outputs: [{ internalType: "address", name: "", type: "address" }],
254
+ stateMutability: "view",
255
+ type: "function",
256
+ },
257
+ {
258
+ inputs: [],
259
+ name: "renounceOwnership",
260
+ outputs: [],
261
+ stateMutability: "nonpayable",
262
+ type: "function",
263
+ },
264
+ {
265
+ inputs: [],
266
+ name: "symbol",
267
+ outputs: [{ internalType: "string", name: "", type: "string" }],
268
+ stateMutability: "view",
269
+ type: "function",
270
+ },
271
+ {
272
+ inputs: [],
273
+ name: "totalSupply",
274
+ outputs: [{ internalType: "uint64", name: "", type: "uint64" }],
275
+ stateMutability: "view",
276
+ type: "function",
277
+ },
278
+ {
279
+ inputs: [
280
+ { internalType: "address", name: "to", type: "address" },
281
+ { internalType: "einput", name: "encryptedAmount", type: "bytes32" },
282
+ { internalType: "bytes", name: "inputProof", type: "bytes" },
283
+ ],
284
+ name: "transfer",
285
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
286
+ stateMutability: "nonpayable",
287
+ type: "function",
288
+ },
289
+ {
290
+ inputs: [
291
+ { internalType: "address", name: "to", type: "address" },
292
+ { internalType: "euint64", name: "amount", type: "uint256" },
293
+ ],
294
+ name: "transfer",
295
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
296
+ stateMutability: "nonpayable",
297
+ type: "function",
298
+ },
299
+ {
300
+ inputs: [
301
+ { internalType: "address", name: "from", type: "address" },
302
+ { internalType: "address", name: "to", type: "address" },
303
+ { internalType: "euint64", name: "amount", type: "uint256" },
304
+ ],
305
+ name: "transferFrom",
306
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
307
+ stateMutability: "nonpayable",
308
+ type: "function",
309
+ },
310
+ {
311
+ inputs: [
312
+ { internalType: "address", name: "from", type: "address" },
313
+ { internalType: "address", name: "to", type: "address" },
314
+ { internalType: "einput", name: "encryptedAmount", type: "bytes32" },
315
+ { internalType: "bytes", name: "inputProof", type: "bytes" },
316
+ ],
317
+ name: "transferFrom",
318
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
319
+ stateMutability: "nonpayable",
320
+ type: "function",
321
+ },
322
+ {
323
+ inputs: [{ internalType: "address", name: "newOwner", type: "address" }],
324
+ name: "transferOwnership",
325
+ outputs: [],
326
+ stateMutability: "nonpayable",
327
+ type: "function",
328
+ },
329
+ ];
@@ -0,0 +1,2 @@
1
+ import { Address } from "viem";
2
+ export declare const toHexString: (bytes: Uint8Array) => Address;
@@ -0,0 +1,5 @@
1
+ export const toHexString = (bytes) => {
2
+ const hexString = "0x" +
3
+ bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
4
+ return hexString;
5
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ /// <reference lib="webworker" />
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ import { getOrCreateFhevmInstance } from "../lib/fhevm";
12
+ const ctx = self;
13
+ ctx.onmessage = (event) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const { tokenAddress, address, value, chainId, networkUrl, network } = event.data;
15
+ const instance = yield getOrCreateFhevmInstance({
16
+ chainId,
17
+ network,
18
+ networkUrl,
19
+ });
20
+ if (!instance || !address) {
21
+ ctx.postMessage({ error: "Instance or address is undefined" });
22
+ return;
23
+ }
24
+ try {
25
+ const result = yield instance
26
+ .createEncryptedInput(tokenAddress, address)
27
+ .add64(value)
28
+ .encrypt();
29
+ ctx.postMessage({ result });
30
+ }
31
+ catch (error) {
32
+ console.error("Worker error", error);
33
+ ctx.postMessage({ error });
34
+ }
35
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pyratzlabs/react-fhevm-utils",
3
- "version": "0.4.0",
3
+ "version": "1.0.0",
4
4
  "description": "React hooks and utilities for Fhevmjs",
5
5
  "main": "dist/index.js",
6
6
  "files": [