@pyratzlabs/react-fhevm-utils 1.1.2 → 2.0.1
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/{useDecryptBalance.d.ts → useDecryptHandles.d.ts} +14 -17
- package/dist/hooks/{useDecryptBalance.js → useDecryptHandles.js} +11 -6
- 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/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/lib/fhevm.d.ts +10 -1
- package/dist/lib/fhevm.js +7 -14
- package/dist/types/encryptedABI.d.ts +768 -97
- package/dist/types/encryptedABI.js +1281 -409
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from "react";
|
|
2
|
-
import { FhevmInstance } from "fhevmjs";
|
|
3
2
|
import { FhevmConfig } from "../types/fhevmConfig";
|
|
3
|
+
import { FhevmInstance } from "@zama-fhe/relayer-sdk/bundle";
|
|
4
4
|
interface ProviderProps {
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
config?: FhevmConfig;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
tokenAddress: Address;
|
|
4
|
-
}
|
|
5
|
-
export declare const useDecryptBalance: ({ tokenAddress }: DecryptBalanceParams) => {
|
|
1
|
+
import type { HandleContractPair } from "@zama-fhe/relayer-sdk/bundle";
|
|
2
|
+
export declare const useDecryptHandles: () => {
|
|
6
3
|
data: undefined;
|
|
7
4
|
variables: undefined;
|
|
8
5
|
error: null;
|
|
@@ -11,63 +8,63 @@ export declare const useDecryptBalance: ({ tokenAddress }: DecryptBalanceParams)
|
|
|
11
8
|
isPending: false;
|
|
12
9
|
isSuccess: false;
|
|
13
10
|
status: "idle";
|
|
14
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<
|
|
11
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
15
12
|
reset: () => void;
|
|
16
13
|
context: unknown;
|
|
17
14
|
failureCount: number;
|
|
18
15
|
failureReason: Error | null;
|
|
19
16
|
isPaused: boolean;
|
|
20
17
|
submittedAt: number;
|
|
21
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<
|
|
18
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
22
19
|
} | {
|
|
23
20
|
data: undefined;
|
|
24
|
-
variables:
|
|
21
|
+
variables: HandleContractPair[];
|
|
25
22
|
error: null;
|
|
26
23
|
isError: false;
|
|
27
24
|
isIdle: false;
|
|
28
25
|
isPending: true;
|
|
29
26
|
isSuccess: false;
|
|
30
27
|
status: "pending";
|
|
31
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<
|
|
28
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
32
29
|
reset: () => void;
|
|
33
30
|
context: unknown;
|
|
34
31
|
failureCount: number;
|
|
35
32
|
failureReason: Error | null;
|
|
36
33
|
isPaused: boolean;
|
|
37
34
|
submittedAt: number;
|
|
38
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<
|
|
35
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
39
36
|
} | {
|
|
40
37
|
data: undefined;
|
|
41
38
|
error: Error;
|
|
42
|
-
variables:
|
|
39
|
+
variables: HandleContractPair[];
|
|
43
40
|
isError: true;
|
|
44
41
|
isIdle: false;
|
|
45
42
|
isPending: false;
|
|
46
43
|
isSuccess: false;
|
|
47
44
|
status: "error";
|
|
48
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<
|
|
45
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
49
46
|
reset: () => void;
|
|
50
47
|
context: unknown;
|
|
51
48
|
failureCount: number;
|
|
52
49
|
failureReason: Error | null;
|
|
53
50
|
isPaused: boolean;
|
|
54
51
|
submittedAt: number;
|
|
55
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<
|
|
52
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
56
53
|
} | {
|
|
57
|
-
data:
|
|
54
|
+
data: import("@zama-fhe/relayer-sdk").DecryptedResults;
|
|
58
55
|
error: null;
|
|
59
|
-
variables:
|
|
56
|
+
variables: HandleContractPair[];
|
|
60
57
|
isError: false;
|
|
61
58
|
isIdle: false;
|
|
62
59
|
isPending: false;
|
|
63
60
|
isSuccess: true;
|
|
64
61
|
status: "success";
|
|
65
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<
|
|
62
|
+
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
66
63
|
reset: () => void;
|
|
67
64
|
context: unknown;
|
|
68
65
|
failureCount: number;
|
|
69
66
|
failureReason: Error | null;
|
|
70
67
|
isPaused: boolean;
|
|
71
68
|
submittedAt: number;
|
|
72
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<
|
|
69
|
+
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
73
70
|
};
|
|
@@ -10,25 +10,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { useMutation } from "@tanstack/react-query";
|
|
11
11
|
import { useAccount, useSignTypedData } from "wagmi";
|
|
12
12
|
import { useFhevmContext } from "../context/FhevmProvider";
|
|
13
|
-
export const
|
|
13
|
+
export const useDecryptHandles = () => {
|
|
14
14
|
const { instance } = useFhevmContext();
|
|
15
15
|
const { address } = useAccount();
|
|
16
16
|
const { signTypedDataAsync } = useSignTypedData();
|
|
17
17
|
const decryptMutation = useMutation({
|
|
18
|
-
mutationFn: (
|
|
18
|
+
mutationFn: (handles) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
if (!instance)
|
|
20
20
|
throw new Error("Instance is not defined");
|
|
21
21
|
if (!address)
|
|
22
22
|
throw new Error("User wallet is not connected");
|
|
23
|
+
const startTimeStamp = Math.floor(Date.now() / 1000).toString();
|
|
24
|
+
const durationDays = "1";
|
|
23
25
|
const { publicKey, privateKey } = instance.generateKeypair();
|
|
24
|
-
const
|
|
26
|
+
const contractAddresses = handles.map((handle) => handle.contractAddress);
|
|
27
|
+
const eip712 = instance.createEIP712(publicKey, contractAddresses, startTimeStamp, durationDays);
|
|
25
28
|
const signature = yield signTypedDataAsync({
|
|
26
29
|
domain: eip712.domain,
|
|
27
|
-
types: {
|
|
28
|
-
|
|
30
|
+
types: {
|
|
31
|
+
UserDecryptRequestVerification: eip712.types.UserDecryptRequestVerification,
|
|
32
|
+
},
|
|
33
|
+
primaryType: "UserDecryptRequestVerification",
|
|
29
34
|
message: eip712.message,
|
|
30
35
|
});
|
|
31
|
-
const decryptedBalance = yield instance.
|
|
36
|
+
const decryptedBalance = yield instance.userDecrypt(handles, privateKey, publicKey, signature.replace("0x", ""), contractAddresses, address, startTimeStamp, durationDays);
|
|
32
37
|
return decryptedBalance;
|
|
33
38
|
}),
|
|
34
39
|
});
|
|
@@ -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/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default } from "./context/FhevmProvider";
|
|
2
2
|
export { useFhevmInstance } from "./hooks/useFhevmInstance";
|
|
3
|
-
export {
|
|
3
|
+
export { useDecryptHandles } from "./hooks/useDecryptHandles";
|
|
4
4
|
export { useGetEncryptedBalance } from "./hooks/useGetEncryptedBalance";
|
|
5
5
|
export { useEncryptedTransfer } from "./hooks/useEncryptedTransfer";
|
|
6
6
|
export { useEncryptValue } from "./hooks/useEncryptValue";
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { default } from "./context/FhevmProvider";
|
|
3
3
|
// hooks
|
|
4
4
|
export { useFhevmInstance } from "./hooks/useFhevmInstance";
|
|
5
|
-
export {
|
|
5
|
+
export { useDecryptHandles } from "./hooks/useDecryptHandles";
|
|
6
6
|
export { useGetEncryptedBalance } from "./hooks/useGetEncryptedBalance";
|
|
7
7
|
export { useEncryptedTransfer } from "./hooks/useEncryptedTransfer";
|
|
8
8
|
export { useEncryptValue } from "./hooks/useEncryptValue";
|
package/dist/lib/fhevm.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { FhevmInstance } from "fhevmjs";
|
|
2
1
|
import { FhevmConfig } from "../types/fhevmConfig";
|
|
2
|
+
import type { createInstance, FhevmInstance, SepoliaConfig, initSDK } from "@zama-fhe/relayer-sdk/bundle";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
relayerSDK: {
|
|
6
|
+
initSDK: typeof initSDK;
|
|
7
|
+
createInstance: typeof createInstance;
|
|
8
|
+
SepoliaConfig: typeof SepoliaConfig;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
export declare const createFhevmInstance: (config?: FhevmConfig) => Promise<FhevmInstance>;
|
|
4
13
|
export declare const getOrCreateFhevmInstance: (config?: FhevmConfig) => Promise<FhevmInstance>;
|
|
5
14
|
export declare const getInstance: () => FhevmInstance | null;
|
package/dist/lib/fhevm.js
CHANGED
|
@@ -7,23 +7,16 @@ 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, initFhevm } from "fhevmjs";
|
|
11
|
-
import { config } from "../config";
|
|
12
|
-
import { sepolia } from "viem/chains";
|
|
13
|
-
const { ACL_ADDRESS, KMS_ADDRESS, GATEWAY_URL, RPC_URL } = config;
|
|
14
10
|
let fhevmInstance = null;
|
|
15
11
|
export const createFhevmInstance = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
var _a, _b;
|
|
17
12
|
if (!fhevmInstance) {
|
|
18
|
-
yield
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
kmsContractAddress: KMS_ADDRESS,
|
|
26
|
-
});
|
|
13
|
+
yield window.relayerSDK.initSDK();
|
|
14
|
+
if (config) {
|
|
15
|
+
fhevmInstance = yield window.relayerSDK.createInstance(Object.assign({}, window.relayerSDK.SepoliaConfig));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
fhevmInstance = yield window.relayerSDK.createInstance(window.relayerSDK.SepoliaConfig);
|
|
19
|
+
}
|
|
27
20
|
}
|
|
28
21
|
return fhevmInstance;
|
|
29
22
|
});
|