@pyratzlabs/react-fhevm-utils 2.0.1 → 2.0.2
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.
|
@@ -15,14 +15,20 @@ export declare const useEncryptValue: ({ tokenAddress }: EncryptValueParams) =>
|
|
|
15
15
|
isPending: false;
|
|
16
16
|
isSuccess: false;
|
|
17
17
|
status: "idle";
|
|
18
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<
|
|
18
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<{
|
|
19
|
+
handles: Uint8Array[];
|
|
20
|
+
inputProof: Uint8Array;
|
|
21
|
+
}, Error, bigint, unknown>;
|
|
19
22
|
reset: () => void;
|
|
20
23
|
context: unknown;
|
|
21
24
|
failureCount: number;
|
|
22
25
|
failureReason: Error | null;
|
|
23
26
|
isPaused: boolean;
|
|
24
27
|
submittedAt: number;
|
|
25
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<
|
|
28
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
29
|
+
handles: Uint8Array[];
|
|
30
|
+
inputProof: Uint8Array;
|
|
31
|
+
}, Error, bigint, unknown>;
|
|
26
32
|
} | {
|
|
27
33
|
data: undefined;
|
|
28
34
|
variables: bigint;
|
|
@@ -32,14 +38,20 @@ export declare const useEncryptValue: ({ tokenAddress }: EncryptValueParams) =>
|
|
|
32
38
|
isPending: true;
|
|
33
39
|
isSuccess: false;
|
|
34
40
|
status: "pending";
|
|
35
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<
|
|
41
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<{
|
|
42
|
+
handles: Uint8Array[];
|
|
43
|
+
inputProof: Uint8Array;
|
|
44
|
+
}, Error, bigint, unknown>;
|
|
36
45
|
reset: () => void;
|
|
37
46
|
context: unknown;
|
|
38
47
|
failureCount: number;
|
|
39
48
|
failureReason: Error | null;
|
|
40
49
|
isPaused: boolean;
|
|
41
50
|
submittedAt: number;
|
|
42
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<
|
|
51
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
52
|
+
handles: Uint8Array[];
|
|
53
|
+
inputProof: Uint8Array;
|
|
54
|
+
}, Error, bigint, unknown>;
|
|
43
55
|
} | {
|
|
44
56
|
data: undefined;
|
|
45
57
|
error: Error;
|
|
@@ -49,16 +61,25 @@ export declare const useEncryptValue: ({ tokenAddress }: EncryptValueParams) =>
|
|
|
49
61
|
isPending: false;
|
|
50
62
|
isSuccess: false;
|
|
51
63
|
status: "error";
|
|
52
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<
|
|
64
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<{
|
|
65
|
+
handles: Uint8Array[];
|
|
66
|
+
inputProof: Uint8Array;
|
|
67
|
+
}, Error, bigint, unknown>;
|
|
53
68
|
reset: () => void;
|
|
54
69
|
context: unknown;
|
|
55
70
|
failureCount: number;
|
|
56
71
|
failureReason: Error | null;
|
|
57
72
|
isPaused: boolean;
|
|
58
73
|
submittedAt: number;
|
|
59
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<
|
|
74
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
75
|
+
handles: Uint8Array[];
|
|
76
|
+
inputProof: Uint8Array;
|
|
77
|
+
}, Error, bigint, unknown>;
|
|
60
78
|
} | {
|
|
61
|
-
data:
|
|
79
|
+
data: {
|
|
80
|
+
handles: Uint8Array[];
|
|
81
|
+
inputProof: Uint8Array;
|
|
82
|
+
};
|
|
62
83
|
error: null;
|
|
63
84
|
variables: bigint;
|
|
64
85
|
isError: false;
|
|
@@ -66,12 +87,18 @@ export declare const useEncryptValue: ({ tokenAddress }: EncryptValueParams) =>
|
|
|
66
87
|
isPending: false;
|
|
67
88
|
isSuccess: true;
|
|
68
89
|
status: "success";
|
|
69
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<
|
|
90
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<{
|
|
91
|
+
handles: Uint8Array[];
|
|
92
|
+
inputProof: Uint8Array;
|
|
93
|
+
}, Error, bigint, unknown>;
|
|
70
94
|
reset: () => void;
|
|
71
95
|
context: unknown;
|
|
72
96
|
failureCount: number;
|
|
73
97
|
failureReason: Error | null;
|
|
74
98
|
isPaused: boolean;
|
|
75
99
|
submittedAt: number;
|
|
76
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<
|
|
100
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
101
|
+
handles: Uint8Array[];
|
|
102
|
+
inputProof: Uint8Array;
|
|
103
|
+
}, Error, bigint, unknown>;
|
|
77
104
|
};
|
|
@@ -8,42 +8,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { useMutation } from "@tanstack/react-query";
|
|
11
|
-
import { useEffect, useRef } from "react";
|
|
12
11
|
import { useAccount } from "wagmi";
|
|
13
12
|
import { useFhevmContext } from "../context/FhevmProvider";
|
|
14
13
|
export const useEncryptValue = ({ tokenAddress }) => {
|
|
15
|
-
const { instance
|
|
14
|
+
const { instance } = useFhevmContext();
|
|
16
15
|
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
16
|
const encryptMutation = useMutation({
|
|
26
17
|
mutationFn: (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
27
18
|
if (!instance)
|
|
28
19
|
throw new Error("Instance is not defined");
|
|
29
20
|
if (!address)
|
|
30
21
|
throw new Error("User is not connected");
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
|
22
|
+
const result = yield instance
|
|
23
|
+
.createEncryptedInput(tokenAddress, address)
|
|
24
|
+
.add64(value)
|
|
25
|
+
.encrypt();
|
|
26
|
+
return result;
|
|
47
27
|
}),
|
|
48
28
|
});
|
|
49
29
|
return Object.assign({}, encryptMutation);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { padHex } from "viem";
|
|
1
2
|
import { usePerformTransaction } from "./usePerformTransaction";
|
|
2
3
|
import { encryptedABI } from "../types/encryptedABI";
|
|
3
4
|
import { toHexString } from "../utils/string.utils";
|
|
@@ -10,7 +11,7 @@ export const useEncryptedApprove = ({ tokenAddress }) => {
|
|
|
10
11
|
const confidentialApprove = (spender, handles, inputProof) => {
|
|
11
12
|
if (handles.length === 0)
|
|
12
13
|
throw new Error("Bad handles format");
|
|
13
|
-
const encryptedAmount = toHexString(handles[0]);
|
|
14
|
+
const encryptedAmount = padHex(toHexString(handles[0]), { size: 32 });
|
|
14
15
|
const proof = toHexString(inputProof);
|
|
15
16
|
perform({
|
|
16
17
|
args: [spender, encryptedAmount, proof],
|