@pyratzlabs/react-fhevm-utils 3.3.0 → 3.3.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/client/hooks/useAccount.d.ts +45 -0
- package/dist/client/hooks/useAccount.js +6 -0
- package/dist/client/hooks/useDecryptHandles.js +2 -1
- package/dist/client/hooks/useEncryptValue.js +1 -1
- package/dist/client/hooks/useEncryptedBatchTransfer.js +1 -1
- package/dist/client/hooks/useFinalizeUnwrap.js +1 -1
- package/dist/client/hooks/useGetEncryptedBalance.js +2 -1
- package/dist/client/hooks/useUnwrap.js +1 -1
- package/package.json +1 -1
- package/dist/client/hooks/useEncryptedApprove.d.ts +0 -11
- package/dist/client/hooks/useEncryptedApprove.js +0 -26
- package/dist/context/FhevmProvider.d.ts +0 -15
- package/dist/context/FhevmProvider.js +0 -34
- package/dist/hooks/useDecryptHandles.d.ts +0 -70
- package/dist/hooks/useDecryptHandles.js +0 -41
- package/dist/hooks/useEncryptValue.d.ts +0 -104
- package/dist/hooks/useEncryptValue.js +0 -30
- package/dist/hooks/useEncryptedApprove.d.ts +0 -11
- package/dist/hooks/useEncryptedApprove.js +0 -26
- package/dist/hooks/useEncryptedTransfer.d.ts +0 -11
- package/dist/hooks/useEncryptedTransfer.js +0 -24
- package/dist/hooks/useFhevmInstance.d.ts +0 -3
- package/dist/hooks/useFhevmInstance.js +0 -5
- package/dist/hooks/useGetEncryptedBalance.d.ts +0 -8
- package/dist/hooks/useGetEncryptedBalance.js +0 -16
- package/dist/hooks/useGetFhevmConfig.d.ts +0 -3
- package/dist/hooks/useGetFhevmConfig.js +0 -5
- package/dist/hooks/usePerformTransaction.d.ts +0 -17
- package/dist/hooks/usePerformTransaction.js +0 -40
- package/dist/types/encryptedABI.d.ts +0 -1180
- package/dist/types/encryptedABI.js +0 -1534
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export declare const useAccount: () => {
|
|
2
|
+
address: `0x${string}` | undefined;
|
|
3
|
+
addresses: undefined;
|
|
4
|
+
chain: undefined;
|
|
5
|
+
chainId: undefined;
|
|
6
|
+
connector: undefined;
|
|
7
|
+
isConnected: false;
|
|
8
|
+
isReconnecting: false;
|
|
9
|
+
isConnecting: false;
|
|
10
|
+
isDisconnected: true;
|
|
11
|
+
status: "disconnected";
|
|
12
|
+
} | {
|
|
13
|
+
address: `0x${string}` | undefined;
|
|
14
|
+
addresses: readonly [import("abitype").Address, ...import("abitype").Address[]];
|
|
15
|
+
chain: import("viem").Chain | undefined;
|
|
16
|
+
chainId: number;
|
|
17
|
+
connector: import("wagmi").Connector;
|
|
18
|
+
isConnected: true;
|
|
19
|
+
isConnecting: false;
|
|
20
|
+
isDisconnected: false;
|
|
21
|
+
isReconnecting: false;
|
|
22
|
+
status: "connected";
|
|
23
|
+
} | {
|
|
24
|
+
address: `0x${string}` | undefined;
|
|
25
|
+
addresses: readonly import("abitype").Address[] | undefined;
|
|
26
|
+
chain: import("viem").Chain | undefined;
|
|
27
|
+
chainId: number | undefined;
|
|
28
|
+
connector: import("wagmi").Connector | undefined;
|
|
29
|
+
isConnected: boolean;
|
|
30
|
+
isConnecting: false;
|
|
31
|
+
isDisconnected: false;
|
|
32
|
+
isReconnecting: true;
|
|
33
|
+
status: "reconnecting";
|
|
34
|
+
} | {
|
|
35
|
+
address: `0x${string}` | undefined;
|
|
36
|
+
addresses: readonly import("abitype").Address[] | undefined;
|
|
37
|
+
chain: import("viem").Chain | undefined;
|
|
38
|
+
chainId: number | undefined;
|
|
39
|
+
connector: import("wagmi").Connector | undefined;
|
|
40
|
+
isConnected: false;
|
|
41
|
+
isReconnecting: false;
|
|
42
|
+
isConnecting: true;
|
|
43
|
+
isDisconnected: false;
|
|
44
|
+
status: "connecting";
|
|
45
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getAddress } from "viem";
|
|
2
|
+
import { useAccount as useWagmiAccount } from "wagmi";
|
|
3
|
+
export const useAccount = () => {
|
|
4
|
+
const account = useWagmiAccount();
|
|
5
|
+
return Object.assign(Object.assign({}, account), { address: account.address ? getAddress(account.address) : undefined });
|
|
6
|
+
};
|
|
@@ -8,8 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { useMutation } from "@tanstack/react-query";
|
|
11
|
-
import {
|
|
11
|
+
import { useSignTypedData } from "wagmi";
|
|
12
12
|
import { useFhevmContext } from "../context/FhevmProvider";
|
|
13
|
+
import { useAccount } from "./useAccount";
|
|
13
14
|
export const useDecryptHandles = () => {
|
|
14
15
|
const { instance } = useFhevmContext();
|
|
15
16
|
const { address } = useAccount();
|
|
@@ -8,9 +8,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { useMutation } from "@tanstack/react-query";
|
|
11
|
-
import { useAccount } from "wagmi";
|
|
12
11
|
import { useFhevmContext } from "../context/FhevmProvider";
|
|
13
12
|
import { encryptValues } from "../../server/encrypt";
|
|
13
|
+
import { useAccount } from "./useAccount";
|
|
14
14
|
export const useEncryptValue = ({ tokenAddress }) => {
|
|
15
15
|
const { instance } = useFhevmContext();
|
|
16
16
|
const { address } = useAccount();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { usePerformTransaction } from "./usePerformTransaction";
|
|
2
2
|
import { TRANSFER_BATCHER_ABI } from "../../types/ABI/TransferBatcher.abi";
|
|
3
|
-
import { useAccount } from "
|
|
3
|
+
import { useAccount } from "./useAccount";
|
|
4
4
|
export const useEncryptedBatchTransfer = ({ batcherAddress }) => {
|
|
5
5
|
const { address } = useAccount();
|
|
6
6
|
const { perform, isLoading, isFailed, isSuccess, error } = usePerformTransaction({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { usePerformTransaction } from "./usePerformTransaction";
|
|
2
|
-
import { useAccount } from "wagmi";
|
|
3
2
|
import { WRAPPER_ABI } from "../../types/ABI/Wrapper.abi";
|
|
3
|
+
import { useAccount } from "./useAccount";
|
|
4
4
|
export const useFinalizeUnwrap = ({ wrapper }) => {
|
|
5
5
|
const { address } = useAccount();
|
|
6
6
|
const { perform, isFailed, isLoading, isSuccess } = usePerformTransaction({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useReadContract } from "wagmi";
|
|
2
2
|
import { encryptedABI } from "../../types/ABI/encryptedABI";
|
|
3
|
+
import { useAccount } from "./useAccount";
|
|
3
4
|
export const useGetEncryptedBalance = ({ tokenAddress, userAddress, }) => {
|
|
4
5
|
const { address } = useAccount();
|
|
5
6
|
const { data } = useReadContract({
|
|
@@ -2,7 +2,7 @@ import { encryptedABI } from "../../types/ABI/encryptedABI";
|
|
|
2
2
|
import { encodeAbiParameters } from "viem";
|
|
3
3
|
import { usePerformTransaction } from "./usePerformTransaction";
|
|
4
4
|
import { toHexString } from "../../utils/string.utils";
|
|
5
|
-
import { useAccount } from "
|
|
5
|
+
import { useAccount } from "./useAccount";
|
|
6
6
|
export const useUnwrap = ({ encryptedErc20 }) => {
|
|
7
7
|
const { address } = useAccount();
|
|
8
8
|
const { data, perform, isFailed, isLoading, isSuccess } = usePerformTransaction({
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Address } from "viem";
|
|
2
|
-
interface Props {
|
|
3
|
-
tokenAddress: Address;
|
|
4
|
-
}
|
|
5
|
-
export declare const useEncryptedApprove: ({ tokenAddress }: Props) => {
|
|
6
|
-
confidentialApprove: (spender: Address, handles: Uint8Array[], inputProof: Uint8Array) => void;
|
|
7
|
-
isFailed: boolean;
|
|
8
|
-
isLoading: boolean;
|
|
9
|
-
isSuccess: boolean;
|
|
10
|
-
};
|
|
11
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { padHex } from "viem";
|
|
2
|
-
import { usePerformTransaction } from "./usePerformTransaction";
|
|
3
|
-
import { encryptedABI } from "../types/encryptedABI";
|
|
4
|
-
import { toHexString } from "../utils/string.utils";
|
|
5
|
-
export const useEncryptedApprove = ({ tokenAddress }) => {
|
|
6
|
-
const { perform, isFailed, isLoading, isSuccess } = usePerformTransaction({
|
|
7
|
-
abi: encryptedABI,
|
|
8
|
-
address: tokenAddress,
|
|
9
|
-
functionName: "confidentialApprove",
|
|
10
|
-
});
|
|
11
|
-
const confidentialApprove = (spender, handles, inputProof) => {
|
|
12
|
-
if (handles.length === 0)
|
|
13
|
-
throw new Error("Bad handles format");
|
|
14
|
-
const encryptedAmount = padHex(toHexString(handles[0]), { size: 32 });
|
|
15
|
-
const proof = toHexString(inputProof);
|
|
16
|
-
perform({
|
|
17
|
-
args: [spender, encryptedAmount, proof],
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
return {
|
|
21
|
-
confidentialApprove,
|
|
22
|
-
isFailed,
|
|
23
|
-
isLoading,
|
|
24
|
-
isSuccess,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from "react";
|
|
2
|
-
import { FhevmConfig } from "../types/fhevmConfig";
|
|
3
|
-
import { FhevmInstance } from "@zama-fhe/relayer-sdk/bundle";
|
|
4
|
-
interface ProviderProps {
|
|
5
|
-
children: ReactNode;
|
|
6
|
-
config?: FhevmConfig;
|
|
7
|
-
}
|
|
8
|
-
interface ContextProps {
|
|
9
|
-
instance?: FhevmInstance;
|
|
10
|
-
config?: FhevmConfig;
|
|
11
|
-
}
|
|
12
|
-
export declare const FhevmContext: React.Context<ContextProps>;
|
|
13
|
-
declare const FhevmProvider: ({ children, config }: ProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
-
export declare const useFhevmContext: () => ContextProps;
|
|
15
|
-
export default FhevmProvider;
|
|
@@ -1,34 +0,0 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
-
import { createContext, useContext, useEffect, useState, } from "react";
|
|
12
|
-
import { getOrCreateFhevmInstance } from "../lib/fhevm";
|
|
13
|
-
export const FhevmContext = createContext({
|
|
14
|
-
instance: undefined,
|
|
15
|
-
config: undefined,
|
|
16
|
-
});
|
|
17
|
-
const FhevmProvider = ({ children, config }) => {
|
|
18
|
-
const [instance, setInstance] = useState();
|
|
19
|
-
const initFhevm = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
-
try {
|
|
21
|
-
const instance = yield getOrCreateFhevmInstance(config);
|
|
22
|
-
setInstance(instance);
|
|
23
|
-
}
|
|
24
|
-
catch (error) {
|
|
25
|
-
throw new Error(`Failed to initialize FHEVM: ${error}`);
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
initFhevm();
|
|
30
|
-
}, []);
|
|
31
|
-
return (_jsx(FhevmContext.Provider, { value: { instance, config }, children: children }));
|
|
32
|
-
};
|
|
33
|
-
export const useFhevmContext = () => useContext(FhevmContext);
|
|
34
|
-
export default FhevmProvider;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type { HandleContractPair } from "@zama-fhe/relayer-sdk/bundle";
|
|
2
|
-
export declare const useDecryptHandles: () => {
|
|
3
|
-
data: undefined;
|
|
4
|
-
variables: undefined;
|
|
5
|
-
error: null;
|
|
6
|
-
isError: false;
|
|
7
|
-
isIdle: true;
|
|
8
|
-
isPending: false;
|
|
9
|
-
isSuccess: false;
|
|
10
|
-
status: "idle";
|
|
11
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk/web").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
12
|
-
reset: () => void;
|
|
13
|
-
context: unknown;
|
|
14
|
-
failureCount: number;
|
|
15
|
-
failureReason: Error | null;
|
|
16
|
-
isPaused: boolean;
|
|
17
|
-
submittedAt: number;
|
|
18
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk/web").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
19
|
-
} | {
|
|
20
|
-
data: undefined;
|
|
21
|
-
variables: HandleContractPair[];
|
|
22
|
-
error: null;
|
|
23
|
-
isError: false;
|
|
24
|
-
isIdle: false;
|
|
25
|
-
isPending: true;
|
|
26
|
-
isSuccess: false;
|
|
27
|
-
status: "pending";
|
|
28
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk/web").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
29
|
-
reset: () => void;
|
|
30
|
-
context: unknown;
|
|
31
|
-
failureCount: number;
|
|
32
|
-
failureReason: Error | null;
|
|
33
|
-
isPaused: boolean;
|
|
34
|
-
submittedAt: number;
|
|
35
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk/web").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
36
|
-
} | {
|
|
37
|
-
data: undefined;
|
|
38
|
-
error: Error;
|
|
39
|
-
variables: HandleContractPair[];
|
|
40
|
-
isError: true;
|
|
41
|
-
isIdle: false;
|
|
42
|
-
isPending: false;
|
|
43
|
-
isSuccess: false;
|
|
44
|
-
status: "error";
|
|
45
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk/web").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
46
|
-
reset: () => void;
|
|
47
|
-
context: unknown;
|
|
48
|
-
failureCount: number;
|
|
49
|
-
failureReason: Error | null;
|
|
50
|
-
isPaused: boolean;
|
|
51
|
-
submittedAt: number;
|
|
52
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk/web").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
53
|
-
} | {
|
|
54
|
-
data: import("@zama-fhe/relayer-sdk/web").DecryptedResults;
|
|
55
|
-
error: null;
|
|
56
|
-
variables: HandleContractPair[];
|
|
57
|
-
isError: false;
|
|
58
|
-
isIdle: false;
|
|
59
|
-
isPending: false;
|
|
60
|
-
isSuccess: true;
|
|
61
|
-
status: "success";
|
|
62
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<import("@zama-fhe/relayer-sdk/web").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
63
|
-
reset: () => void;
|
|
64
|
-
context: unknown;
|
|
65
|
-
failureCount: number;
|
|
66
|
-
failureReason: Error | null;
|
|
67
|
-
isPaused: boolean;
|
|
68
|
-
submittedAt: number;
|
|
69
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<import("@zama-fhe/relayer-sdk/web").DecryptedResults, Error, HandleContractPair[], unknown>;
|
|
70
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
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 { useAccount, useSignTypedData } from "wagmi";
|
|
12
|
-
import { useFhevmContext } from "../context/FhevmProvider";
|
|
13
|
-
export const useDecryptHandles = () => {
|
|
14
|
-
const { instance } = useFhevmContext();
|
|
15
|
-
const { address } = useAccount();
|
|
16
|
-
const { signTypedDataAsync } = useSignTypedData();
|
|
17
|
-
const decryptMutation = useMutation({
|
|
18
|
-
mutationFn: (handles) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
-
if (!instance)
|
|
20
|
-
throw new Error("Instance is not defined");
|
|
21
|
-
if (!address)
|
|
22
|
-
throw new Error("User wallet is not connected");
|
|
23
|
-
const startTimeStamp = Math.floor(Date.now() / 1000).toString();
|
|
24
|
-
const durationDays = "1";
|
|
25
|
-
const { publicKey, privateKey } = instance.generateKeypair();
|
|
26
|
-
const contractAddresses = handles.map((handle) => handle.contractAddress);
|
|
27
|
-
const eip712 = instance.createEIP712(publicKey, contractAddresses, startTimeStamp, durationDays);
|
|
28
|
-
const signature = yield signTypedDataAsync({
|
|
29
|
-
domain: eip712.domain,
|
|
30
|
-
types: {
|
|
31
|
-
UserDecryptRequestVerification: eip712.types.UserDecryptRequestVerification,
|
|
32
|
-
},
|
|
33
|
-
primaryType: "UserDecryptRequestVerification",
|
|
34
|
-
message: eip712.message,
|
|
35
|
-
});
|
|
36
|
-
const decryptedBalance = yield instance.userDecrypt(handles, privateKey, publicKey, signature.replace("0x", ""), contractAddresses, address, startTimeStamp, durationDays);
|
|
37
|
-
return decryptedBalance;
|
|
38
|
-
}),
|
|
39
|
-
});
|
|
40
|
-
return Object.assign({}, decryptMutation);
|
|
41
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
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<{
|
|
19
|
-
handles: Uint8Array[];
|
|
20
|
-
inputProof: Uint8Array;
|
|
21
|
-
}, Error, bigint, unknown>;
|
|
22
|
-
reset: () => void;
|
|
23
|
-
context: unknown;
|
|
24
|
-
failureCount: number;
|
|
25
|
-
failureReason: Error | null;
|
|
26
|
-
isPaused: boolean;
|
|
27
|
-
submittedAt: number;
|
|
28
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
29
|
-
handles: Uint8Array[];
|
|
30
|
-
inputProof: Uint8Array;
|
|
31
|
-
}, Error, bigint, unknown>;
|
|
32
|
-
} | {
|
|
33
|
-
data: undefined;
|
|
34
|
-
variables: bigint;
|
|
35
|
-
error: null;
|
|
36
|
-
isError: false;
|
|
37
|
-
isIdle: false;
|
|
38
|
-
isPending: true;
|
|
39
|
-
isSuccess: false;
|
|
40
|
-
status: "pending";
|
|
41
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<{
|
|
42
|
-
handles: Uint8Array[];
|
|
43
|
-
inputProof: Uint8Array;
|
|
44
|
-
}, Error, bigint, unknown>;
|
|
45
|
-
reset: () => void;
|
|
46
|
-
context: unknown;
|
|
47
|
-
failureCount: number;
|
|
48
|
-
failureReason: Error | null;
|
|
49
|
-
isPaused: boolean;
|
|
50
|
-
submittedAt: number;
|
|
51
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
52
|
-
handles: Uint8Array[];
|
|
53
|
-
inputProof: Uint8Array;
|
|
54
|
-
}, Error, bigint, unknown>;
|
|
55
|
-
} | {
|
|
56
|
-
data: undefined;
|
|
57
|
-
error: Error;
|
|
58
|
-
variables: bigint;
|
|
59
|
-
isError: true;
|
|
60
|
-
isIdle: false;
|
|
61
|
-
isPending: false;
|
|
62
|
-
isSuccess: false;
|
|
63
|
-
status: "error";
|
|
64
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<{
|
|
65
|
-
handles: Uint8Array[];
|
|
66
|
-
inputProof: Uint8Array;
|
|
67
|
-
}, Error, bigint, unknown>;
|
|
68
|
-
reset: () => void;
|
|
69
|
-
context: unknown;
|
|
70
|
-
failureCount: number;
|
|
71
|
-
failureReason: Error | null;
|
|
72
|
-
isPaused: boolean;
|
|
73
|
-
submittedAt: number;
|
|
74
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
75
|
-
handles: Uint8Array[];
|
|
76
|
-
inputProof: Uint8Array;
|
|
77
|
-
}, Error, bigint, unknown>;
|
|
78
|
-
} | {
|
|
79
|
-
data: {
|
|
80
|
-
handles: Uint8Array[];
|
|
81
|
-
inputProof: Uint8Array;
|
|
82
|
-
};
|
|
83
|
-
error: null;
|
|
84
|
-
variables: bigint;
|
|
85
|
-
isError: false;
|
|
86
|
-
isIdle: false;
|
|
87
|
-
isPending: false;
|
|
88
|
-
isSuccess: true;
|
|
89
|
-
status: "success";
|
|
90
|
-
mutate: import("@tanstack/react-query").UseMutateFunction<{
|
|
91
|
-
handles: Uint8Array[];
|
|
92
|
-
inputProof: Uint8Array;
|
|
93
|
-
}, Error, bigint, unknown>;
|
|
94
|
-
reset: () => void;
|
|
95
|
-
context: unknown;
|
|
96
|
-
failureCount: number;
|
|
97
|
-
failureReason: Error | null;
|
|
98
|
-
isPaused: boolean;
|
|
99
|
-
submittedAt: number;
|
|
100
|
-
mutateAsync: import("@tanstack/react-query").UseMutateAsyncFunction<{
|
|
101
|
-
handles: Uint8Array[];
|
|
102
|
-
inputProof: Uint8Array;
|
|
103
|
-
}, Error, bigint, unknown>;
|
|
104
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
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 { useAccount } from "wagmi";
|
|
12
|
-
import { useFhevmContext } from "../context/FhevmProvider";
|
|
13
|
-
export const useEncryptValue = ({ tokenAddress }) => {
|
|
14
|
-
const { instance } = useFhevmContext();
|
|
15
|
-
const { address } = useAccount();
|
|
16
|
-
const encryptMutation = useMutation({
|
|
17
|
-
mutationFn: (value) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
if (!instance)
|
|
19
|
-
throw new Error("Instance is not defined");
|
|
20
|
-
if (!address)
|
|
21
|
-
throw new Error("User is not connected");
|
|
22
|
-
const result = yield instance
|
|
23
|
-
.createEncryptedInput(tokenAddress, address)
|
|
24
|
-
.add64(value)
|
|
25
|
-
.encrypt();
|
|
26
|
-
return result;
|
|
27
|
-
}),
|
|
28
|
-
});
|
|
29
|
-
return Object.assign({}, encryptMutation);
|
|
30
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Address } from "viem";
|
|
2
|
-
interface Props {
|
|
3
|
-
tokenAddress: Address;
|
|
4
|
-
}
|
|
5
|
-
export declare const useEncryptedApprove: ({ tokenAddress }: Props) => {
|
|
6
|
-
confidentialApprove: (spender: Address, handles: Uint8Array[], inputProof: Uint8Array) => void;
|
|
7
|
-
isFailed: boolean;
|
|
8
|
-
isLoading: boolean;
|
|
9
|
-
isSuccess: boolean;
|
|
10
|
-
};
|
|
11
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { padHex } from "viem";
|
|
2
|
-
import { usePerformTransaction } from "./usePerformTransaction";
|
|
3
|
-
import { encryptedABI } from "../types/encryptedABI";
|
|
4
|
-
import { toHexString } from "../utils/string.utils";
|
|
5
|
-
export const useEncryptedApprove = ({ tokenAddress }) => {
|
|
6
|
-
const { perform, isFailed, isLoading, isSuccess } = usePerformTransaction({
|
|
7
|
-
abi: encryptedABI,
|
|
8
|
-
address: tokenAddress,
|
|
9
|
-
functionName: "confidentialApprove",
|
|
10
|
-
});
|
|
11
|
-
const confidentialApprove = (spender, handles, inputProof) => {
|
|
12
|
-
if (handles.length === 0)
|
|
13
|
-
throw new Error("Bad handles format");
|
|
14
|
-
const encryptedAmount = padHex(toHexString(handles[0]), { size: 32 });
|
|
15
|
-
const proof = toHexString(inputProof);
|
|
16
|
-
perform({
|
|
17
|
-
args: [spender, encryptedAmount, proof],
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
return {
|
|
21
|
-
confidentialApprove,
|
|
22
|
-
isFailed,
|
|
23
|
-
isLoading,
|
|
24
|
-
isSuccess,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
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, transferFee?: number) => void;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
isFailed: boolean;
|
|
9
|
-
isSuccess: boolean;
|
|
10
|
-
error: import("@wagmi/core").WriteContractErrorType | null;
|
|
11
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { usePerformTransaction } from "./usePerformTransaction";
|
|
2
|
-
import { encryptedABI } from "../types/encryptedABI";
|
|
3
|
-
import { toHexString } from "../utils/string.utils";
|
|
4
|
-
import { decimalToToken } from "../utils/number.utils";
|
|
5
|
-
export const useEncryptedTransfer = ({ tokenAddress, }) => {
|
|
6
|
-
const { perform, isLoading, isFailed, isSuccess, error } = usePerformTransaction({
|
|
7
|
-
abi: encryptedABI,
|
|
8
|
-
address: tokenAddress,
|
|
9
|
-
functionName: "confidentialTransfer",
|
|
10
|
-
});
|
|
11
|
-
const transfer = (to, handles, inputProof, transferFee) => {
|
|
12
|
-
if (handles.length === 0)
|
|
13
|
-
throw new Error("Bad handles format");
|
|
14
|
-
if (!transferFee)
|
|
15
|
-
throw new Error("TRANSFER: No transfer fee provided");
|
|
16
|
-
const encryptedAmount = toHexString(handles[0]);
|
|
17
|
-
const proof = toHexString(inputProof);
|
|
18
|
-
perform({
|
|
19
|
-
args: [to, encryptedAmount, proof],
|
|
20
|
-
value: decimalToToken(transferFee, 18),
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
return { transfer, isLoading, isFailed, isSuccess, error };
|
|
24
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Address } from "viem";
|
|
2
|
-
export interface GetEncryptedBalanceParams {
|
|
3
|
-
tokenAddress: Address;
|
|
4
|
-
userAddress?: Address;
|
|
5
|
-
}
|
|
6
|
-
export declare const useGetEncryptedBalance: ({ tokenAddress, userAddress, }: GetEncryptedBalanceParams) => {
|
|
7
|
-
encryptedBalance: Address | undefined;
|
|
8
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useAccount, useReadContract } from "wagmi";
|
|
2
|
-
import { encryptedABI } from "../types/encryptedABI";
|
|
3
|
-
export const useGetEncryptedBalance = ({ tokenAddress, userAddress, }) => {
|
|
4
|
-
const { address } = useAccount();
|
|
5
|
-
const { data } = useReadContract({
|
|
6
|
-
address: tokenAddress,
|
|
7
|
-
abi: encryptedABI,
|
|
8
|
-
functionName: "confidentialBalanceOf",
|
|
9
|
-
args: [userAddress !== null && userAddress !== void 0 ? userAddress : address],
|
|
10
|
-
query: {
|
|
11
|
-
enabled: !!address,
|
|
12
|
-
refetchInterval: 5000,
|
|
13
|
-
},
|
|
14
|
-
});
|
|
15
|
-
return { encryptedBalance: data };
|
|
16
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
};
|