@cometh/connect-react-hooks 1.0.0 → 1.0.2-dev.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/index.cjs +280 -44
- package/dist/index.d.cts +7318 -1795
- package/dist/index.d.ts +7318 -1795
- package/dist/index.js +279 -43
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -7,6 +7,53 @@ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
8
8
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
9
9
|
|
10
|
+
// src/errors.ts
|
11
|
+
var NotWithinConnectProviderError = class extends Error {
|
12
|
+
constructor(hookName) {
|
13
|
+
super(`${hookName} must be used within a ConnectProvider`);
|
14
|
+
}
|
15
|
+
};
|
16
|
+
var NotWithinSmartAccountProviderError = class extends Error {
|
17
|
+
constructor() {
|
18
|
+
super("Hooks must be used within a SmartAccountProvider");
|
19
|
+
}
|
20
|
+
};
|
21
|
+
var SmartAccountNotFoundError = class extends Error {
|
22
|
+
constructor() {
|
23
|
+
super("No smart account found");
|
24
|
+
}
|
25
|
+
};
|
26
|
+
var SignerNotFoundError = class extends Error {
|
27
|
+
constructor() {
|
28
|
+
super("No signer found");
|
29
|
+
}
|
30
|
+
};
|
31
|
+
var ApiKeyNotFoundError = class extends Error {
|
32
|
+
constructor() {
|
33
|
+
super("No apikey found");
|
34
|
+
}
|
35
|
+
};
|
36
|
+
var BundlerUrlNotFoundError = class extends Error {
|
37
|
+
constructor() {
|
38
|
+
super("Bundler url not found");
|
39
|
+
}
|
40
|
+
};
|
41
|
+
var UseDisconnectError = class extends Error {
|
42
|
+
constructor() {
|
43
|
+
super("An error occurred during disconnection");
|
44
|
+
}
|
45
|
+
};
|
46
|
+
var UseSwitchChainError = class extends Error {
|
47
|
+
constructor() {
|
48
|
+
super("An error occurred while switching chain");
|
49
|
+
}
|
50
|
+
};
|
51
|
+
var NoCurrentConfigurationError = class extends Error {
|
52
|
+
constructor() {
|
53
|
+
super("No current configuration found");
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
10
57
|
// src/actions/createSmartAccount.ts
|
11
58
|
import {
|
12
59
|
createComethPaymasterClient,
|
@@ -51,15 +98,13 @@ async function createSmartAccount(config) {
|
|
51
98
|
estimateFeesPerGas: async () => {
|
52
99
|
return await paymasterClient.getUserOperationGasPrice();
|
53
100
|
}
|
54
|
-
}
|
55
|
-
publicClient
|
101
|
+
}
|
56
102
|
});
|
57
103
|
} else {
|
58
104
|
client = createSmartAccountClient({
|
59
105
|
account,
|
60
106
|
chain,
|
61
|
-
bundlerTransport: http(bundlerUrl)
|
62
|
-
publicClient
|
107
|
+
bundlerTransport: http(bundlerUrl)
|
63
108
|
});
|
64
109
|
}
|
65
110
|
const address = client.account.address;
|
@@ -79,10 +124,12 @@ var ConnectContext = createContext({
|
|
79
124
|
queryClient: void 0,
|
80
125
|
smartAccountClient: null,
|
81
126
|
smartAccountAddress: void 0,
|
82
|
-
updateSmartAccountClient: async () =>
|
127
|
+
updateSmartAccountClient: async () => {
|
128
|
+
},
|
83
129
|
disconnectSmartAccount: async () => {
|
84
130
|
},
|
85
|
-
networksConfig: void 0
|
131
|
+
networksConfig: void 0,
|
132
|
+
apikey: void 0
|
86
133
|
});
|
87
134
|
var ConnectProvider = ({
|
88
135
|
children,
|
@@ -103,7 +150,7 @@ var ConnectProvider = ({
|
|
103
150
|
const publicClient = config.networksConfig.find(
|
104
151
|
(network) => network.chain?.id === chain.id
|
105
152
|
)?.publicClient;
|
106
|
-
if (!bundlerUrl) throw new
|
153
|
+
if (!bundlerUrl) throw new BundlerUrlNotFoundError();
|
107
154
|
try {
|
108
155
|
const { client, address: newAddress } = await createSmartAccount({
|
109
156
|
...config,
|
@@ -120,10 +167,8 @@ var ConnectProvider = ({
|
|
120
167
|
setSmartAccountClient(client);
|
121
168
|
setSmartAccountAddress(newAddress);
|
122
169
|
localStorage.setItem(CHAIN_STORAGE_KEY, JSON.stringify(chain));
|
123
|
-
return client;
|
124
170
|
} catch (e) {
|
125
171
|
console.log(e);
|
126
|
-
return smartAccountClient;
|
127
172
|
}
|
128
173
|
},
|
129
174
|
[config, config.networksConfig[0].chain]
|
@@ -145,7 +190,8 @@ var ConnectProvider = ({
|
|
145
190
|
smartAccountAddress,
|
146
191
|
updateSmartAccountClient,
|
147
192
|
disconnectSmartAccount,
|
148
|
-
networksConfig: config.networksConfig
|
193
|
+
networksConfig: config.networksConfig,
|
194
|
+
apikey: config.apiKey
|
149
195
|
}),
|
150
196
|
[
|
151
197
|
queryClient,
|
@@ -164,7 +210,7 @@ import { useContext, useMemo as useMemo2 } from "react";
|
|
164
210
|
var useAccount = () => {
|
165
211
|
const context = useContext(ConnectContext);
|
166
212
|
if (context === void 0) {
|
167
|
-
throw new
|
213
|
+
throw new NotWithinConnectProviderError("useAccount");
|
168
214
|
}
|
169
215
|
const { smartAccountClient, smartAccountAddress } = context;
|
170
216
|
const { chain, chainId } = useMemo2(
|
@@ -197,7 +243,7 @@ import { useContext as useContext2 } from "react";
|
|
197
243
|
var useSmartAccount = () => {
|
198
244
|
const context = useContext2(ConnectContext);
|
199
245
|
if (context === void 0) {
|
200
|
-
throw new
|
246
|
+
throw new NotWithinSmartAccountProviderError();
|
201
247
|
}
|
202
248
|
return context;
|
203
249
|
};
|
@@ -1365,7 +1411,7 @@ var useSendTransaction = (mutationProps) => {
|
|
1365
1411
|
// Define the mutation function
|
1366
1412
|
mutationFn: (variables) => {
|
1367
1413
|
if (!smartAccountClient) {
|
1368
|
-
throw new
|
1414
|
+
throw new SmartAccountNotFoundError();
|
1369
1415
|
}
|
1370
1416
|
const { calls } = variables;
|
1371
1417
|
if (!Array.isArray(calls)) {
|
@@ -1399,7 +1445,7 @@ var useWriteContract = (mutationProps) => {
|
|
1399
1445
|
{
|
1400
1446
|
mutationFn: async (variables) => {
|
1401
1447
|
if (!smartAccountClient) {
|
1402
|
-
throw new
|
1448
|
+
throw new SmartAccountNotFoundError();
|
1403
1449
|
}
|
1404
1450
|
const { abi, address, functionName, args, value } = variables;
|
1405
1451
|
const data = encodeFunctionData({
|
@@ -1434,7 +1480,7 @@ import { useCallback as useCallback4, useContext as useContext6, useState as use
|
|
1434
1480
|
var useConnect = () => {
|
1435
1481
|
const context = useContext6(ConnectContext);
|
1436
1482
|
if (context === void 0) {
|
1437
|
-
throw new
|
1483
|
+
throw new NotWithinConnectProviderError("useConnect");
|
1438
1484
|
}
|
1439
1485
|
const { queryClient, updateSmartAccountClient } = context;
|
1440
1486
|
const [isPending, setIsPending] = useState5(false);
|
@@ -1486,7 +1532,7 @@ import { useCallback as useCallback5, useContext as useContext7, useState as use
|
|
1486
1532
|
var useDisconnect = () => {
|
1487
1533
|
const context = useContext7(ConnectContext);
|
1488
1534
|
if (context === void 0) {
|
1489
|
-
throw new
|
1535
|
+
throw new NotWithinConnectProviderError("useDisconnect");
|
1490
1536
|
}
|
1491
1537
|
const { queryClient, disconnectSmartAccount } = context;
|
1492
1538
|
const [isPending, setIsPending] = useState6(false);
|
@@ -1499,7 +1545,7 @@ var useDisconnect = () => {
|
|
1499
1545
|
queryKey: ["connect"]
|
1500
1546
|
});
|
1501
1547
|
}).catch((e) => {
|
1502
|
-
const err = e instanceof Error ? e : new
|
1548
|
+
const err = e instanceof Error ? e : new UseDisconnectError();
|
1503
1549
|
setError(err);
|
1504
1550
|
}).finally(() => {
|
1505
1551
|
setIsPending(false);
|
@@ -1512,7 +1558,7 @@ var useDisconnect = () => {
|
|
1512
1558
|
await disconnectSmartAccount();
|
1513
1559
|
queryClient?.invalidateQueries({ queryKey: ["connect"] });
|
1514
1560
|
} catch (e) {
|
1515
|
-
const err = e instanceof Error ? e : new
|
1561
|
+
const err = e instanceof Error ? e : new UseDisconnectError();
|
1516
1562
|
setError(err);
|
1517
1563
|
throw err;
|
1518
1564
|
} finally {
|
@@ -1532,11 +1578,9 @@ var useAddOwner = (mutationProps) => {
|
|
1532
1578
|
const { smartAccountClient, queryClient } = useSmartAccount();
|
1533
1579
|
const { mutate, mutateAsync, ...result } = useMutation(
|
1534
1580
|
{
|
1535
|
-
mutationFn: async ({
|
1536
|
-
ownerToAdd
|
1537
|
-
}) => {
|
1581
|
+
mutationFn: async ({ ownerToAdd }) => {
|
1538
1582
|
if (!smartAccountClient) {
|
1539
|
-
throw new
|
1583
|
+
throw new SmartAccountNotFoundError();
|
1540
1584
|
}
|
1541
1585
|
return await smartAccountClient.addOwner({ ownerToAdd });
|
1542
1586
|
},
|
@@ -1562,7 +1606,7 @@ var useRemoveOwner = (mutationProps) => {
|
|
1562
1606
|
ownerToRemove
|
1563
1607
|
}) => {
|
1564
1608
|
if (!smartAccountClient) {
|
1565
|
-
throw new
|
1609
|
+
throw new SmartAccountNotFoundError();
|
1566
1610
|
}
|
1567
1611
|
return await smartAccountClient.removeOwner({ ownerToRemove });
|
1568
1612
|
},
|
@@ -1587,7 +1631,7 @@ var useGetOwners = (queryProps) => {
|
|
1587
1631
|
queryKey: ["getOwners"],
|
1588
1632
|
queryFn: async () => {
|
1589
1633
|
if (!smartAccountClient) {
|
1590
|
-
throw new
|
1634
|
+
throw new SmartAccountNotFoundError();
|
1591
1635
|
}
|
1592
1636
|
return await smartAccountClient.getOwners();
|
1593
1637
|
},
|
@@ -1603,7 +1647,7 @@ var useGetEnrichedOwners = (queryProps) => {
|
|
1603
1647
|
queryKey: ["getEnrichedOwners"],
|
1604
1648
|
queryFn: async () => {
|
1605
1649
|
if (!smartAccountClient) {
|
1606
|
-
throw new
|
1650
|
+
throw new SmartAccountNotFoundError();
|
1607
1651
|
}
|
1608
1652
|
return await smartAccountClient.getEnrichedOwners();
|
1609
1653
|
},
|
@@ -1620,7 +1664,7 @@ var useValidateAddDevice = (mutationProps) => {
|
|
1620
1664
|
{
|
1621
1665
|
mutationFn: (variables) => {
|
1622
1666
|
if (!smartAccountClient) {
|
1623
|
-
throw new
|
1667
|
+
throw new SmartAccountNotFoundError();
|
1624
1668
|
}
|
1625
1669
|
const { signer } = variables;
|
1626
1670
|
return smartAccountClient.validateAddDevice({ signer });
|
@@ -1647,7 +1691,7 @@ var useVerifyMessage = (mutationProps) => {
|
|
1647
1691
|
{
|
1648
1692
|
mutationFn: async (variables) => {
|
1649
1693
|
if (!smartAccountClient) {
|
1650
|
-
throw new
|
1694
|
+
throw new SmartAccountNotFoundError();
|
1651
1695
|
}
|
1652
1696
|
const { message, signature } = variables;
|
1653
1697
|
return smartAccountClient.verifySignature({
|
@@ -1679,7 +1723,7 @@ var useGetGasPrice = (rpcUrl, queryProps) => {
|
|
1679
1723
|
queryKey: ["gasPrice", rpcUrl],
|
1680
1724
|
queryFn: async () => {
|
1681
1725
|
if (!smartAccountClient) {
|
1682
|
-
throw new
|
1726
|
+
throw new SmartAccountNotFoundError();
|
1683
1727
|
}
|
1684
1728
|
const publicClient = createPublicClient({
|
1685
1729
|
chain: smartAccountClient.chain,
|
@@ -1933,7 +1977,7 @@ function useSignMessage() {
|
|
1933
1977
|
{
|
1934
1978
|
mutationFn: async ({ message }) => {
|
1935
1979
|
if (!smartAccountClient) {
|
1936
|
-
throw new
|
1980
|
+
throw new SmartAccountNotFoundError();
|
1937
1981
|
}
|
1938
1982
|
const signature = await smartAccountClient.account.signMessage({
|
1939
1983
|
message
|
@@ -1961,7 +2005,7 @@ function useSetUpRecovery() {
|
|
1961
2005
|
{
|
1962
2006
|
mutationFn: async () => {
|
1963
2007
|
if (!smartAccountClient) {
|
1964
|
-
throw new
|
2008
|
+
throw new SmartAccountNotFoundError();
|
1965
2009
|
}
|
1966
2010
|
return smartAccountClient.setUpRecoveryModule();
|
1967
2011
|
}
|
@@ -1987,7 +2031,7 @@ function useIsRecoveryActive(props = {}) {
|
|
1987
2031
|
queryKey: ["isRecoveryActive"],
|
1988
2032
|
queryFn: async () => {
|
1989
2033
|
if (!smartAccountClient) {
|
1990
|
-
throw new
|
2034
|
+
throw new SmartAccountNotFoundError();
|
1991
2035
|
}
|
1992
2036
|
return smartAccountClient.isRecoveryActive(props);
|
1993
2037
|
},
|
@@ -2005,7 +2049,7 @@ function useGetRecoveryRequest(props = {}, queryOptions) {
|
|
2005
2049
|
queryKey: ["getRecoveryRequest"],
|
2006
2050
|
queryFn: async () => {
|
2007
2051
|
if (!smartAccountClient) {
|
2008
|
-
throw new
|
2052
|
+
throw new SmartAccountNotFoundError();
|
2009
2053
|
}
|
2010
2054
|
return smartAccountClient.getRecoveryRequest(props);
|
2011
2055
|
},
|
@@ -2029,7 +2073,7 @@ function useCancelRecoveryRequest() {
|
|
2029
2073
|
{
|
2030
2074
|
mutationFn: async (variables) => {
|
2031
2075
|
if (!smartAccountClient) {
|
2032
|
-
throw new
|
2076
|
+
throw new SmartAccountNotFoundError();
|
2033
2077
|
}
|
2034
2078
|
return smartAccountClient.cancelRecoveryRequest({
|
2035
2079
|
effectiveDelayAddress: variables.effectiveDelayAddress
|
@@ -2054,7 +2098,7 @@ import { useCallback as useCallback8, useContext as useContext8, useState as use
|
|
2054
2098
|
var useSwitchChain = () => {
|
2055
2099
|
const context = useContext8(ConnectContext);
|
2056
2100
|
if (context === void 0) {
|
2057
|
-
throw new
|
2101
|
+
throw new NotWithinConnectProviderError("useSwitchChain");
|
2058
2102
|
}
|
2059
2103
|
const {
|
2060
2104
|
queryClient,
|
@@ -2068,12 +2112,12 @@ var useSwitchChain = () => {
|
|
2068
2112
|
async (params) => {
|
2069
2113
|
const { chainId } = params;
|
2070
2114
|
if (!networksConfig)
|
2071
|
-
throw new
|
2115
|
+
throw new NoCurrentConfigurationError();
|
2072
2116
|
const selectedNetwork = networksConfig?.find(
|
2073
2117
|
(network) => network.chain?.id === chainId
|
2074
2118
|
);
|
2075
2119
|
if (!selectedNetwork)
|
2076
|
-
throw new
|
2120
|
+
throw new NoCurrentConfigurationError();
|
2077
2121
|
try {
|
2078
2122
|
const client = await updateSmartAccountClient({
|
2079
2123
|
address: smartAccountClient?.account.address,
|
@@ -2084,7 +2128,7 @@ var useSwitchChain = () => {
|
|
2084
2128
|
});
|
2085
2129
|
return client;
|
2086
2130
|
} catch (e) {
|
2087
|
-
throw e instanceof Error ? e : new
|
2131
|
+
throw e instanceof Error ? e : new UseSwitchChainError();
|
2088
2132
|
}
|
2089
2133
|
},
|
2090
2134
|
[
|
@@ -2099,9 +2143,7 @@ var useSwitchChain = () => {
|
|
2099
2143
|
setIsPending(true);
|
2100
2144
|
setError(null);
|
2101
2145
|
return switchChainInternal(params).catch((e) => {
|
2102
|
-
const err = e instanceof Error ? e : new
|
2103
|
-
"An error occurred while switching chain"
|
2104
|
-
);
|
2146
|
+
const err = e instanceof Error ? e : new UseSwitchChainError();
|
2105
2147
|
setError(err);
|
2106
2148
|
}).finally(() => {
|
2107
2149
|
setIsPending(false);
|
@@ -2117,7 +2159,7 @@ var useSwitchChain = () => {
|
|
2117
2159
|
const client = await switchChainInternal(params);
|
2118
2160
|
return client;
|
2119
2161
|
} catch (e) {
|
2120
|
-
const err = e instanceof Error ? e : new
|
2162
|
+
const err = e instanceof Error ? e : new UseSwitchChainError();
|
2121
2163
|
setError(err);
|
2122
2164
|
throw err;
|
2123
2165
|
} finally {
|
@@ -2145,7 +2187,7 @@ var useGetTransactionCost = (mutationProps) => {
|
|
2145
2187
|
{
|
2146
2188
|
mutationFn: async (variables) => {
|
2147
2189
|
if (!smartAccountClient) {
|
2148
|
-
throw new
|
2190
|
+
throw new SmartAccountNotFoundError();
|
2149
2191
|
}
|
2150
2192
|
const bundlerClient = createBundlerClient({
|
2151
2193
|
account: smartAccountClient.account,
|
@@ -2184,7 +2226,7 @@ var useEstimateGas = (mutationProps) => {
|
|
2184
2226
|
{
|
2185
2227
|
mutationFn: async (variables) => {
|
2186
2228
|
if (!smartAccountClient) {
|
2187
|
-
throw new
|
2229
|
+
throw new SmartAccountNotFoundError();
|
2188
2230
|
}
|
2189
2231
|
const publicClient = createPublicClient2({
|
2190
2232
|
chain: smartAccountClient.chain,
|
@@ -2232,6 +2274,196 @@ var useEstimateGas = (mutationProps) => {
|
|
2232
2274
|
estimateGasAsync: mutateAsync
|
2233
2275
|
};
|
2234
2276
|
};
|
2277
|
+
|
2278
|
+
// src/hooks/session-key/useGrantPermission.ts
|
2279
|
+
import { useMutation as useMutation2 } from "wagmi/query";
|
2280
|
+
import {
|
2281
|
+
erc7579Actions,
|
2282
|
+
smartSessionActions
|
2283
|
+
} from "@cometh/connect-sdk-4337";
|
2284
|
+
function useGrantPermission(mutationProps) {
|
2285
|
+
const { smartAccountClient } = useSmartAccount();
|
2286
|
+
const { mutate, mutateAsync, ...result } = useMutation2({
|
2287
|
+
mutationKey: ["session-key-grant-permission", smartAccountClient],
|
2288
|
+
mutationFn: async (args) => {
|
2289
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2290
|
+
const safe7559Account = smartAccountClient.extend(smartSessionActions()).extend(erc7579Actions());
|
2291
|
+
const createSessionsResponse = await safe7559Account.grantPermission(
|
2292
|
+
args
|
2293
|
+
);
|
2294
|
+
const response = await safe7559Account.waitForUserOperationReceipt({
|
2295
|
+
hash: createSessionsResponse.userOpHash
|
2296
|
+
});
|
2297
|
+
return {
|
2298
|
+
txHash: response.receipt.transactionHash,
|
2299
|
+
createSessionsResponse
|
2300
|
+
};
|
2301
|
+
},
|
2302
|
+
...mutationProps
|
2303
|
+
});
|
2304
|
+
return {
|
2305
|
+
data: result.data,
|
2306
|
+
error: result.error,
|
2307
|
+
isPending: result.isPending,
|
2308
|
+
isSuccess: result.isSuccess,
|
2309
|
+
isError: result.isError,
|
2310
|
+
grantPermission: mutate,
|
2311
|
+
grantPermissionAsync: mutateAsync
|
2312
|
+
};
|
2313
|
+
}
|
2314
|
+
|
2315
|
+
// src/hooks/session-key/useSendPermission.ts
|
2316
|
+
import { useMutation as useMutation3 } from "wagmi/query";
|
2317
|
+
import "@cometh/connect-sdk-4337";
|
2318
|
+
import "viem";
|
2319
|
+
|
2320
|
+
// src/hooks/session-key/useSessionKeySigner.ts
|
2321
|
+
import {
|
2322
|
+
erc7579Actions as erc7579Actions2,
|
2323
|
+
smartSessionActions as smartSessionActions2,
|
2324
|
+
toSmartSessionsSigner
|
2325
|
+
} from "@cometh/connect-sdk-4337";
|
2326
|
+
import { useQuery as useQuery2 } from "wagmi/query";
|
2327
|
+
import { privateKeyToAccount } from "viem/accounts";
|
2328
|
+
function useSessionKeySigner({
|
2329
|
+
sessionData,
|
2330
|
+
privateKey
|
2331
|
+
}) {
|
2332
|
+
const { smartAccountClient } = useSmartAccount();
|
2333
|
+
const query = useQuery2({
|
2334
|
+
queryKey: ["session-key-signer", smartAccountClient],
|
2335
|
+
queryFn: async () => {
|
2336
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2337
|
+
const safe7559Account = smartAccountClient.extend(smartSessionActions2()).extend(erc7579Actions2());
|
2338
|
+
return toSmartSessionsSigner(safe7559Account, {
|
2339
|
+
moduleData: {
|
2340
|
+
permissionIds: sessionData.permissionIds,
|
2341
|
+
action: sessionData.action,
|
2342
|
+
mode: "0x00",
|
2343
|
+
sessions: sessionData.sessions
|
2344
|
+
},
|
2345
|
+
signer: privateKeyToAccount(privateKey)
|
2346
|
+
});
|
2347
|
+
},
|
2348
|
+
enabled: !!smartAccountClient
|
2349
|
+
});
|
2350
|
+
return query;
|
2351
|
+
}
|
2352
|
+
|
2353
|
+
// src/actions/createSessionSmartAccount.ts
|
2354
|
+
import {
|
2355
|
+
createSafeSmartAccount as createSafeSmartAccount2,
|
2356
|
+
createSmartAccountClient as createSmartAccountClient2,
|
2357
|
+
smartSessionActions as smartSessionActions3
|
2358
|
+
} from "@cometh/connect-sdk-4337";
|
2359
|
+
import { http as http5 } from "viem";
|
2360
|
+
var createSessionSmartAccountClient = async (apiKey, smartAccountClient, sessionKeySigner) => {
|
2361
|
+
const sessionKeyAccount = await createSafeSmartAccount2({
|
2362
|
+
apiKey,
|
2363
|
+
chain: smartAccountClient.chain,
|
2364
|
+
smartAccountAddress: smartAccountClient.account.address,
|
2365
|
+
smartSessionSigner: sessionKeySigner
|
2366
|
+
});
|
2367
|
+
const paymasterClient = smartAccountClient.paymaster;
|
2368
|
+
const bundlerUrl = smartAccountClient.transport.url;
|
2369
|
+
return createSmartAccountClient2({
|
2370
|
+
account: sessionKeyAccount,
|
2371
|
+
chain: smartAccountClient.chain,
|
2372
|
+
bundlerTransport: http5(bundlerUrl),
|
2373
|
+
paymaster: paymasterClient,
|
2374
|
+
userOperation: {
|
2375
|
+
estimateFeesPerGas: async () => {
|
2376
|
+
return await paymasterClient.getUserOperationGasPrice();
|
2377
|
+
}
|
2378
|
+
}
|
2379
|
+
}).extend(smartSessionActions3());
|
2380
|
+
};
|
2381
|
+
|
2382
|
+
// src/hooks/session-key/useSendPermission.ts
|
2383
|
+
import { useContext as useContext9 } from "react";
|
2384
|
+
function useSendPermission({
|
2385
|
+
sessionData,
|
2386
|
+
privateKey,
|
2387
|
+
mutationProps
|
2388
|
+
}) {
|
2389
|
+
const context = useContext9(ConnectContext);
|
2390
|
+
if (context === void 0) {
|
2391
|
+
throw new NotWithinConnectProviderError("useSendPermission");
|
2392
|
+
}
|
2393
|
+
const { smartAccountClient } = useSmartAccount();
|
2394
|
+
const { data: sessionKeySigner } = useSessionKeySigner({
|
2395
|
+
sessionData,
|
2396
|
+
privateKey
|
2397
|
+
});
|
2398
|
+
const { mutate, mutateAsync, ...result } = useMutation3({
|
2399
|
+
mutationKey: [
|
2400
|
+
"session-key-send-permission",
|
2401
|
+
sessionKeySigner,
|
2402
|
+
smartAccountClient
|
2403
|
+
],
|
2404
|
+
mutationFn: async (args) => {
|
2405
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2406
|
+
if (!sessionKeySigner) throw new SignerNotFoundError();
|
2407
|
+
if (!context.apikey) throw new ApiKeyNotFoundError();
|
2408
|
+
const sessionKeyClient = await createSessionSmartAccountClient(
|
2409
|
+
context.apikey,
|
2410
|
+
smartAccountClient,
|
2411
|
+
sessionKeySigner
|
2412
|
+
);
|
2413
|
+
const userOpHash = await sessionKeyClient.usePermission(args);
|
2414
|
+
const userOp = await sessionKeyClient.waitForUserOperationReceipt({
|
2415
|
+
hash: userOpHash
|
2416
|
+
});
|
2417
|
+
return userOp.receipt.transactionHash;
|
2418
|
+
},
|
2419
|
+
...mutationProps
|
2420
|
+
});
|
2421
|
+
return {
|
2422
|
+
data: result.data,
|
2423
|
+
error: result.error,
|
2424
|
+
isPending: result.isPending,
|
2425
|
+
isSuccess: result.isSuccess,
|
2426
|
+
isError: result.isError,
|
2427
|
+
sendPermission: mutate,
|
2428
|
+
sendPermissionAsync: mutateAsync
|
2429
|
+
};
|
2430
|
+
}
|
2431
|
+
|
2432
|
+
// src/hooks/session-key/useSessionKeyClient.ts
|
2433
|
+
import { useQuery as useQuery3 } from "wagmi/query";
|
2434
|
+
import "@cometh/connect-sdk-4337";
|
2435
|
+
import "viem";
|
2436
|
+
import { useContext as useContext10 } from "react";
|
2437
|
+
function useSessionKeyClient({
|
2438
|
+
sessionData,
|
2439
|
+
privateKey
|
2440
|
+
}) {
|
2441
|
+
const { smartAccountClient } = useSmartAccount();
|
2442
|
+
const { data: sessionKeySigner } = useSessionKeySigner({
|
2443
|
+
sessionData,
|
2444
|
+
privateKey
|
2445
|
+
});
|
2446
|
+
const context = useContext10(ConnectContext);
|
2447
|
+
if (context === void 0) {
|
2448
|
+
throw new Error(
|
2449
|
+
"useSessionKeyClient must be used within a ConnectProvider"
|
2450
|
+
);
|
2451
|
+
}
|
2452
|
+
const query = useQuery3({
|
2453
|
+
queryKey: ["session-key-get-client", sessionKeySigner, smartAccountClient],
|
2454
|
+
queryFn: async () => {
|
2455
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2456
|
+
if (!sessionKeySigner) throw new SignerNotFoundError();
|
2457
|
+
if (!context.apikey) throw new ApiKeyNotFoundError();
|
2458
|
+
return createSessionSmartAccountClient(
|
2459
|
+
context.apikey,
|
2460
|
+
smartAccountClient,
|
2461
|
+
sessionKeySigner
|
2462
|
+
);
|
2463
|
+
}
|
2464
|
+
});
|
2465
|
+
return query;
|
2466
|
+
}
|
2235
2467
|
export {
|
2236
2468
|
ConnectProvider,
|
2237
2469
|
useAccount,
|
@@ -2247,12 +2479,16 @@ export {
|
|
2247
2479
|
useGetOwners,
|
2248
2480
|
useGetRecoveryRequest,
|
2249
2481
|
useGetTransactionCost,
|
2482
|
+
useGrantPermission,
|
2250
2483
|
useIsRecoveryActive,
|
2251
2484
|
useRemoveOwner,
|
2252
2485
|
useRetrieveAccountAddressFromPasskeyId,
|
2253
2486
|
useRetrieveAccountAddressFromPasskeys,
|
2487
|
+
useSendPermission,
|
2254
2488
|
useSendTransaction,
|
2255
2489
|
useSerializeUrlWithSignerPayload,
|
2490
|
+
useSessionKeyClient,
|
2491
|
+
useSessionKeySigner,
|
2256
2492
|
useSetUpRecovery,
|
2257
2493
|
useSignMessage,
|
2258
2494
|
useSwitchChain,
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"url": "https://twitter.com/slovaye"
|
8
8
|
}
|
9
9
|
],
|
10
|
-
"version": "1.0.
|
10
|
+
"version": "1.0.2-dev.1",
|
11
11
|
"description": "React hooks Connect 4337",
|
12
12
|
"repository": "https://github.com/cometh-hq/connect-sdk-4337.git",
|
13
13
|
"keywords": [
|
@@ -58,7 +58,7 @@
|
|
58
58
|
"typescript": "^5"
|
59
59
|
},
|
60
60
|
"dependencies": {
|
61
|
-
"@cometh/connect-sdk-4337": "^1.0.
|
61
|
+
"@cometh/connect-sdk-4337": "^1.0.6",
|
62
62
|
"permissionless": "^0.2.23"
|
63
63
|
}
|
64
64
|
}
|