@pyratzlabs/react-fhevm-utils 2.0.0 → 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.
- package/dist/context/FhevmProvider.d.ts +1 -1
- package/dist/hooks/useDecryptHandles.d.ts +10 -10
- package/dist/hooks/useEncryptValue.js +6 -6
- package/dist/hooks/useEncryptedApprove.js +2 -1
- package/dist/hooks/useFhevmInstance.d.ts +1 -1
- package/dist/hooks/useGetEncryptedBalance.d.ts +1 -1
- package/dist/hooks/useGetEncryptedBalance.js +1 -1
- package/dist/lib/fhevm.d.ts +1 -1
- package/dist/lib/fhevm.js +3 -4
- package/dist/types/encryptedABI.d.ts +768 -97
- package/dist/types/encryptedABI.js +1057 -185
- package/dist/workers/encryption.worker.d.ts +0 -11
- package/dist/workers/encryption.worker.js +22 -7
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from "react";
|
|
2
2
|
import { FhevmConfig } from "../types/fhevmConfig";
|
|
3
|
-
import { FhevmInstance } from "@zama-fhe/relayer-sdk/
|
|
3
|
+
import { FhevmInstance } from "@zama-fhe/relayer-sdk/bundle";
|
|
4
4
|
interface ProviderProps {
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
config?: FhevmConfig;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HandleContractPair } from "@zama-fhe/relayer-sdk/
|
|
1
|
+
import type { HandleContractPair } from "@zama-fhe/relayer-sdk/bundle";
|
|
2
2
|
export declare const useDecryptHandles: () => {
|
|
3
3
|
data: undefined;
|
|
4
4
|
variables: undefined;
|
|
@@ -8,14 +8,14 @@ export declare const useDecryptHandles: () => {
|
|
|
8
8
|
isPending: false;
|
|
9
9
|
isSuccess: false;
|
|
10
10
|
status: "idle";
|
|
11
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk
|
|
11
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
12
12
|
reset: () => void;
|
|
13
13
|
context: unknown;
|
|
14
14
|
failureCount: number;
|
|
15
15
|
failureReason: Error | null;
|
|
16
16
|
isPaused: boolean;
|
|
17
17
|
submittedAt: number;
|
|
18
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk
|
|
18
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
19
19
|
} | {
|
|
20
20
|
data: undefined;
|
|
21
21
|
variables: HandleContractPair[];
|
|
@@ -25,14 +25,14 @@ export declare const useDecryptHandles: () => {
|
|
|
25
25
|
isPending: true;
|
|
26
26
|
isSuccess: false;
|
|
27
27
|
status: "pending";
|
|
28
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk
|
|
28
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
29
29
|
reset: () => void;
|
|
30
30
|
context: unknown;
|
|
31
31
|
failureCount: number;
|
|
32
32
|
failureReason: Error | null;
|
|
33
33
|
isPaused: boolean;
|
|
34
34
|
submittedAt: number;
|
|
35
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk
|
|
35
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
36
36
|
} | {
|
|
37
37
|
data: undefined;
|
|
38
38
|
error: Error;
|
|
@@ -42,16 +42,16 @@ export declare const useDecryptHandles: () => {
|
|
|
42
42
|
isPending: false;
|
|
43
43
|
isSuccess: false;
|
|
44
44
|
status: "error";
|
|
45
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk
|
|
45
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
46
46
|
reset: () => void;
|
|
47
47
|
context: unknown;
|
|
48
48
|
failureCount: number;
|
|
49
49
|
failureReason: Error | null;
|
|
50
50
|
isPaused: boolean;
|
|
51
51
|
submittedAt: number;
|
|
52
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk
|
|
52
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
53
53
|
} | {
|
|
54
|
-
data: import("@zama-fhe/relayer-sdk
|
|
54
|
+
data: import("@zama-fhe/relayer-sdk").DecryptedResults;
|
|
55
55
|
error: null;
|
|
56
56
|
variables: HandleContractPair[];
|
|
57
57
|
isError: false;
|
|
@@ -59,12 +59,12 @@ export declare const useDecryptHandles: () => {
|
|
|
59
59
|
isPending: false;
|
|
60
60
|
isSuccess: true;
|
|
61
61
|
status: "success";
|
|
62
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk
|
|
62
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
63
63
|
reset: () => void;
|
|
64
64
|
context: unknown;
|
|
65
65
|
failureCount: number;
|
|
66
66
|
failureReason: Error | null;
|
|
67
67
|
isPaused: boolean;
|
|
68
68
|
submittedAt: number;
|
|
69
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk
|
|
69
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
70
70
|
};
|
|
@@ -10,9 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { useMutation } from "@tanstack/react-query";
|
|
11
11
|
import { useAccount } from "wagmi";
|
|
12
12
|
import { useFhevmContext } from "../context/FhevmProvider";
|
|
13
|
-
import { encryptInt64 } from "../workers/encryption.worker";
|
|
14
13
|
export const useEncryptValue = ({ tokenAddress }) => {
|
|
15
|
-
const { instance
|
|
14
|
+
const { instance } = useFhevmContext();
|
|
16
15
|
const { address } = useAccount();
|
|
17
16
|
const encryptMutation = useMutation({
|
|
18
17
|
mutationFn: (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -20,10 +19,11 @@ export const useEncryptValue = ({ tokenAddress }) => {
|
|
|
20
19
|
throw new Error("Instance is not defined");
|
|
21
20
|
if (!address)
|
|
22
21
|
throw new Error("User is not connected");
|
|
23
|
-
|
|
24
|
-
address
|
|
25
|
-
value
|
|
26
|
-
|
|
22
|
+
const result = yield instance
|
|
23
|
+
.createEncryptedInput(tokenAddress, address)
|
|
24
|
+
.add64(value)
|
|
25
|
+
.encrypt();
|
|
26
|
+
return result;
|
|
27
27
|
}),
|
|
28
28
|
});
|
|
29
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],
|
|
@@ -5,7 +5,7 @@ export const useGetEncryptedBalance = ({ tokenAddress, userAddress, }) => {
|
|
|
5
5
|
const { data } = useReadContract({
|
|
6
6
|
address: tokenAddress,
|
|
7
7
|
abi: encryptedABI,
|
|
8
|
-
functionName: "
|
|
8
|
+
functionName: "confidentialBalanceOf",
|
|
9
9
|
args: [userAddress !== null && userAddress !== void 0 ? userAddress : address],
|
|
10
10
|
query: {
|
|
11
11
|
enabled: !!address,
|
package/dist/lib/fhevm.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FhevmConfig } from "../types/fhevmConfig";
|
|
2
|
-
import { createInstance, FhevmInstance, SepoliaConfig, initSDK } from "@zama-fhe/relayer-sdk/
|
|
2
|
+
import type { createInstance, FhevmInstance, SepoliaConfig, initSDK } from "@zama-fhe/relayer-sdk/bundle";
|
|
3
3
|
declare global {
|
|
4
4
|
interface Window {
|
|
5
5
|
relayerSDK: {
|
package/dist/lib/fhevm.js
CHANGED
|
@@ -7,16 +7,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { createInstance, SepoliaConfig, initSDK, } from "@zama-fhe/relayer-sdk/web";
|
|
11
10
|
let fhevmInstance = null;
|
|
12
11
|
export const createFhevmInstance = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
12
|
if (!fhevmInstance) {
|
|
14
|
-
yield initSDK();
|
|
13
|
+
yield window.relayerSDK.initSDK();
|
|
15
14
|
if (config) {
|
|
16
|
-
fhevmInstance = yield createInstance(Object.assign({}, SepoliaConfig));
|
|
15
|
+
fhevmInstance = yield window.relayerSDK.createInstance(Object.assign({}, window.relayerSDK.SepoliaConfig));
|
|
17
16
|
}
|
|
18
17
|
else {
|
|
19
|
-
fhevmInstance = yield createInstance(SepoliaConfig);
|
|
18
|
+
fhevmInstance = yield window.relayerSDK.createInstance(window.relayerSDK.SepoliaConfig);
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
return fhevmInstance;
|