@cometh/connect-react-hooks 1.0.1 → 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 +95 -45
- package/dist/index.d.cts +15 -19
- package/dist/index.d.ts +15 -19
- package/dist/index.js +95 -45
- package/package.json +2 -2
package/dist/index.cjs
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
|
|
12
59
|
|
@@ -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 = _connectsdk4337.createSmartAccountClient.call(void 0, {
|
59
105
|
account,
|
60
106
|
chain,
|
61
|
-
bundlerTransport: _wagmi.http.call(void 0, bundlerUrl)
|
62
|
-
publicClient
|
107
|
+
bundlerTransport: _wagmi.http.call(void 0, bundlerUrl)
|
63
108
|
});
|
64
109
|
}
|
65
110
|
const address = client.account.address;
|
@@ -105,7 +150,7 @@ var ConnectProvider = ({
|
|
105
150
|
const publicClient = _optionalChain([config, 'access', _14 => _14.networksConfig, 'access', _15 => _15.find, 'call', _16 => _16(
|
106
151
|
(network) => _optionalChain([network, 'access', _17 => _17.chain, 'optionalAccess', _18 => _18.id]) === chain.id
|
107
152
|
), 'optionalAccess', _19 => _19.publicClient]);
|
108
|
-
if (!bundlerUrl) throw new
|
153
|
+
if (!bundlerUrl) throw new BundlerUrlNotFoundError();
|
109
154
|
try {
|
110
155
|
const { client, address: newAddress } = await createSmartAccount({
|
111
156
|
...config,
|
@@ -165,7 +210,7 @@ var ConnectProvider = ({
|
|
165
210
|
var useAccount = () => {
|
166
211
|
const context = _react.useContext.call(void 0, ConnectContext);
|
167
212
|
if (context === void 0) {
|
168
|
-
throw new
|
213
|
+
throw new NotWithinConnectProviderError("useAccount");
|
169
214
|
}
|
170
215
|
const { smartAccountClient, smartAccountAddress } = context;
|
171
216
|
const { chain, chainId } = _react.useMemo.call(void 0,
|
@@ -198,7 +243,7 @@ var useAccount = () => {
|
|
198
243
|
var useSmartAccount = () => {
|
199
244
|
const context = _react.useContext.call(void 0, ConnectContext);
|
200
245
|
if (context === void 0) {
|
201
|
-
throw new
|
246
|
+
throw new NotWithinSmartAccountProviderError();
|
202
247
|
}
|
203
248
|
return context;
|
204
249
|
};
|
@@ -1366,7 +1411,7 @@ var useSendTransaction = (mutationProps) => {
|
|
1366
1411
|
// Define the mutation function
|
1367
1412
|
mutationFn: (variables) => {
|
1368
1413
|
if (!smartAccountClient) {
|
1369
|
-
throw new
|
1414
|
+
throw new SmartAccountNotFoundError();
|
1370
1415
|
}
|
1371
1416
|
const { calls } = variables;
|
1372
1417
|
if (!Array.isArray(calls)) {
|
@@ -1400,7 +1445,7 @@ var useWriteContract = (mutationProps) => {
|
|
1400
1445
|
{
|
1401
1446
|
mutationFn: async (variables) => {
|
1402
1447
|
if (!smartAccountClient) {
|
1403
|
-
throw new
|
1448
|
+
throw new SmartAccountNotFoundError();
|
1404
1449
|
}
|
1405
1450
|
const { abi, address, functionName, args, value } = variables;
|
1406
1451
|
const data = _viem.encodeFunctionData.call(void 0, {
|
@@ -1435,7 +1480,7 @@ var useWriteContract = (mutationProps) => {
|
|
1435
1480
|
var useConnect = () => {
|
1436
1481
|
const context = _react.useContext.call(void 0, ConnectContext);
|
1437
1482
|
if (context === void 0) {
|
1438
|
-
throw new
|
1483
|
+
throw new NotWithinConnectProviderError("useConnect");
|
1439
1484
|
}
|
1440
1485
|
const { queryClient, updateSmartAccountClient } = context;
|
1441
1486
|
const [isPending, setIsPending] = _react.useState.call(void 0, false);
|
@@ -1487,7 +1532,7 @@ var useConnect = () => {
|
|
1487
1532
|
var useDisconnect = () => {
|
1488
1533
|
const context = _react.useContext.call(void 0, ConnectContext);
|
1489
1534
|
if (context === void 0) {
|
1490
|
-
throw new
|
1535
|
+
throw new NotWithinConnectProviderError("useDisconnect");
|
1491
1536
|
}
|
1492
1537
|
const { queryClient, disconnectSmartAccount } = context;
|
1493
1538
|
const [isPending, setIsPending] = _react.useState.call(void 0, false);
|
@@ -1500,7 +1545,7 @@ var useDisconnect = () => {
|
|
1500
1545
|
queryKey: ["connect"]
|
1501
1546
|
})]);
|
1502
1547
|
}).catch((e) => {
|
1503
|
-
const err = e instanceof Error ? e : new
|
1548
|
+
const err = e instanceof Error ? e : new UseDisconnectError();
|
1504
1549
|
setError(err);
|
1505
1550
|
}).finally(() => {
|
1506
1551
|
setIsPending(false);
|
@@ -1513,7 +1558,7 @@ var useDisconnect = () => {
|
|
1513
1558
|
await disconnectSmartAccount();
|
1514
1559
|
_optionalChain([queryClient, 'optionalAccess', _93 => _93.invalidateQueries, 'call', _94 => _94({ queryKey: ["connect"] })]);
|
1515
1560
|
} catch (e) {
|
1516
|
-
const err = e instanceof Error ? e : new
|
1561
|
+
const err = e instanceof Error ? e : new UseDisconnectError();
|
1517
1562
|
setError(err);
|
1518
1563
|
throw err;
|
1519
1564
|
} finally {
|
@@ -1535,7 +1580,7 @@ var useAddOwner = (mutationProps) => {
|
|
1535
1580
|
{
|
1536
1581
|
mutationFn: async ({ ownerToAdd }) => {
|
1537
1582
|
if (!smartAccountClient) {
|
1538
|
-
throw new
|
1583
|
+
throw new SmartAccountNotFoundError();
|
1539
1584
|
}
|
1540
1585
|
return await smartAccountClient.addOwner({ ownerToAdd });
|
1541
1586
|
},
|
@@ -1561,7 +1606,7 @@ var useRemoveOwner = (mutationProps) => {
|
|
1561
1606
|
ownerToRemove
|
1562
1607
|
}) => {
|
1563
1608
|
if (!smartAccountClient) {
|
1564
|
-
throw new
|
1609
|
+
throw new SmartAccountNotFoundError();
|
1565
1610
|
}
|
1566
1611
|
return await smartAccountClient.removeOwner({ ownerToRemove });
|
1567
1612
|
},
|
@@ -1586,7 +1631,7 @@ var useGetOwners = (queryProps) => {
|
|
1586
1631
|
queryKey: ["getOwners"],
|
1587
1632
|
queryFn: async () => {
|
1588
1633
|
if (!smartAccountClient) {
|
1589
|
-
throw new
|
1634
|
+
throw new SmartAccountNotFoundError();
|
1590
1635
|
}
|
1591
1636
|
return await smartAccountClient.getOwners();
|
1592
1637
|
},
|
@@ -1602,7 +1647,7 @@ var useGetEnrichedOwners = (queryProps) => {
|
|
1602
1647
|
queryKey: ["getEnrichedOwners"],
|
1603
1648
|
queryFn: async () => {
|
1604
1649
|
if (!smartAccountClient) {
|
1605
|
-
throw new
|
1650
|
+
throw new SmartAccountNotFoundError();
|
1606
1651
|
}
|
1607
1652
|
return await smartAccountClient.getEnrichedOwners();
|
1608
1653
|
},
|
@@ -1619,7 +1664,7 @@ var useValidateAddDevice = (mutationProps) => {
|
|
1619
1664
|
{
|
1620
1665
|
mutationFn: (variables) => {
|
1621
1666
|
if (!smartAccountClient) {
|
1622
|
-
throw new
|
1667
|
+
throw new SmartAccountNotFoundError();
|
1623
1668
|
}
|
1624
1669
|
const { signer } = variables;
|
1625
1670
|
return smartAccountClient.validateAddDevice({ signer });
|
@@ -1646,7 +1691,7 @@ var useVerifyMessage = (mutationProps) => {
|
|
1646
1691
|
{
|
1647
1692
|
mutationFn: async (variables) => {
|
1648
1693
|
if (!smartAccountClient) {
|
1649
|
-
throw new
|
1694
|
+
throw new SmartAccountNotFoundError();
|
1650
1695
|
}
|
1651
1696
|
const { message, signature } = variables;
|
1652
1697
|
return smartAccountClient.verifySignature({
|
@@ -1678,7 +1723,7 @@ var useGetGasPrice = (rpcUrl, queryProps) => {
|
|
1678
1723
|
queryKey: ["gasPrice", rpcUrl],
|
1679
1724
|
queryFn: async () => {
|
1680
1725
|
if (!smartAccountClient) {
|
1681
|
-
throw new
|
1726
|
+
throw new SmartAccountNotFoundError();
|
1682
1727
|
}
|
1683
1728
|
const publicClient = _viem.createPublicClient.call(void 0, {
|
1684
1729
|
chain: smartAccountClient.chain,
|
@@ -1932,7 +1977,7 @@ function useSignMessage() {
|
|
1932
1977
|
{
|
1933
1978
|
mutationFn: async ({ message }) => {
|
1934
1979
|
if (!smartAccountClient) {
|
1935
|
-
throw new
|
1980
|
+
throw new SmartAccountNotFoundError();
|
1936
1981
|
}
|
1937
1982
|
const signature = await smartAccountClient.account.signMessage({
|
1938
1983
|
message
|
@@ -1960,7 +2005,7 @@ function useSetUpRecovery() {
|
|
1960
2005
|
{
|
1961
2006
|
mutationFn: async () => {
|
1962
2007
|
if (!smartAccountClient) {
|
1963
|
-
throw new
|
2008
|
+
throw new SmartAccountNotFoundError();
|
1964
2009
|
}
|
1965
2010
|
return smartAccountClient.setUpRecoveryModule();
|
1966
2011
|
}
|
@@ -1986,7 +2031,7 @@ function useIsRecoveryActive(props = {}) {
|
|
1986
2031
|
queryKey: ["isRecoveryActive"],
|
1987
2032
|
queryFn: async () => {
|
1988
2033
|
if (!smartAccountClient) {
|
1989
|
-
throw new
|
2034
|
+
throw new SmartAccountNotFoundError();
|
1990
2035
|
}
|
1991
2036
|
return smartAccountClient.isRecoveryActive(props);
|
1992
2037
|
},
|
@@ -2004,7 +2049,7 @@ function useGetRecoveryRequest(props = {}, queryOptions) {
|
|
2004
2049
|
queryKey: ["getRecoveryRequest"],
|
2005
2050
|
queryFn: async () => {
|
2006
2051
|
if (!smartAccountClient) {
|
2007
|
-
throw new
|
2052
|
+
throw new SmartAccountNotFoundError();
|
2008
2053
|
}
|
2009
2054
|
return smartAccountClient.getRecoveryRequest(props);
|
2010
2055
|
},
|
@@ -2028,7 +2073,7 @@ function useCancelRecoveryRequest() {
|
|
2028
2073
|
{
|
2029
2074
|
mutationFn: async (variables) => {
|
2030
2075
|
if (!smartAccountClient) {
|
2031
|
-
throw new
|
2076
|
+
throw new SmartAccountNotFoundError();
|
2032
2077
|
}
|
2033
2078
|
return smartAccountClient.cancelRecoveryRequest({
|
2034
2079
|
effectiveDelayAddress: variables.effectiveDelayAddress
|
@@ -2053,7 +2098,7 @@ function useCancelRecoveryRequest() {
|
|
2053
2098
|
var useSwitchChain = () => {
|
2054
2099
|
const context = _react.useContext.call(void 0, ConnectContext);
|
2055
2100
|
if (context === void 0) {
|
2056
|
-
throw new
|
2101
|
+
throw new NotWithinConnectProviderError("useSwitchChain");
|
2057
2102
|
}
|
2058
2103
|
const {
|
2059
2104
|
queryClient,
|
@@ -2067,12 +2112,12 @@ var useSwitchChain = () => {
|
|
2067
2112
|
async (params) => {
|
2068
2113
|
const { chainId } = params;
|
2069
2114
|
if (!networksConfig)
|
2070
|
-
throw new
|
2115
|
+
throw new NoCurrentConfigurationError();
|
2071
2116
|
const selectedNetwork = _optionalChain([networksConfig, 'optionalAccess', _99 => _99.find, 'call', _100 => _100(
|
2072
2117
|
(network) => _optionalChain([network, 'access', _101 => _101.chain, 'optionalAccess', _102 => _102.id]) === chainId
|
2073
2118
|
)]);
|
2074
2119
|
if (!selectedNetwork)
|
2075
|
-
throw new
|
2120
|
+
throw new NoCurrentConfigurationError();
|
2076
2121
|
try {
|
2077
2122
|
const client = await updateSmartAccountClient({
|
2078
2123
|
address: _optionalChain([smartAccountClient, 'optionalAccess', _103 => _103.account, 'access', _104 => _104.address]),
|
@@ -2083,7 +2128,7 @@ var useSwitchChain = () => {
|
|
2083
2128
|
})]);
|
2084
2129
|
return client;
|
2085
2130
|
} catch (e) {
|
2086
|
-
throw e instanceof Error ? e : new
|
2131
|
+
throw e instanceof Error ? e : new UseSwitchChainError();
|
2087
2132
|
}
|
2088
2133
|
},
|
2089
2134
|
[
|
@@ -2098,9 +2143,7 @@ var useSwitchChain = () => {
|
|
2098
2143
|
setIsPending(true);
|
2099
2144
|
setError(null);
|
2100
2145
|
return switchChainInternal(params).catch((e) => {
|
2101
|
-
const err = e instanceof Error ? e : new
|
2102
|
-
"An error occurred while switching chain"
|
2103
|
-
);
|
2146
|
+
const err = e instanceof Error ? e : new UseSwitchChainError();
|
2104
2147
|
setError(err);
|
2105
2148
|
}).finally(() => {
|
2106
2149
|
setIsPending(false);
|
@@ -2116,7 +2159,7 @@ var useSwitchChain = () => {
|
|
2116
2159
|
const client = await switchChainInternal(params);
|
2117
2160
|
return client;
|
2118
2161
|
} catch (e) {
|
2119
|
-
const err = e instanceof Error ? e : new
|
2162
|
+
const err = e instanceof Error ? e : new UseSwitchChainError();
|
2120
2163
|
setError(err);
|
2121
2164
|
throw err;
|
2122
2165
|
} finally {
|
@@ -2144,7 +2187,7 @@ var useGetTransactionCost = (mutationProps) => {
|
|
2144
2187
|
{
|
2145
2188
|
mutationFn: async (variables) => {
|
2146
2189
|
if (!smartAccountClient) {
|
2147
|
-
throw new
|
2190
|
+
throw new SmartAccountNotFoundError();
|
2148
2191
|
}
|
2149
2192
|
const bundlerClient = _accountabstraction.createBundlerClient.call(void 0, {
|
2150
2193
|
account: smartAccountClient.account,
|
@@ -2183,7 +2226,7 @@ var useEstimateGas = (mutationProps) => {
|
|
2183
2226
|
{
|
2184
2227
|
mutationFn: async (variables) => {
|
2185
2228
|
if (!smartAccountClient) {
|
2186
|
-
throw new
|
2229
|
+
throw new SmartAccountNotFoundError();
|
2187
2230
|
}
|
2188
2231
|
const publicClient = _viem.createPublicClient.call(void 0, {
|
2189
2232
|
chain: smartAccountClient.chain,
|
@@ -2243,7 +2286,7 @@ function useGrantPermission(mutationProps) {
|
|
2243
2286
|
const { mutate, mutateAsync, ...result } = _query.useMutation.call(void 0, {
|
2244
2287
|
mutationKey: ["session-key-grant-permission", smartAccountClient],
|
2245
2288
|
mutationFn: async (args) => {
|
2246
|
-
if (!smartAccountClient) throw new
|
2289
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2247
2290
|
const safe7559Account = smartAccountClient.extend(_connectsdk4337.smartSessionActions.call(void 0, )).extend(_connectsdk4337.erc7579Actions.call(void 0, ));
|
2248
2291
|
const createSessionsResponse = await safe7559Account.grantPermission(
|
2249
2292
|
args
|
@@ -2290,7 +2333,7 @@ function useSessionKeySigner({
|
|
2290
2333
|
const query = _query.useQuery.call(void 0, {
|
2291
2334
|
queryKey: ["session-key-signer", smartAccountClient],
|
2292
2335
|
queryFn: async () => {
|
2293
|
-
if (!smartAccountClient) throw new
|
2336
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2294
2337
|
const safe7559Account = smartAccountClient.extend(_connectsdk4337.smartSessionActions.call(void 0, )).extend(_connectsdk4337.erc7579Actions.call(void 0, ));
|
2295
2338
|
return _connectsdk4337.toSmartSessionsSigner.call(void 0, safe7559Account, {
|
2296
2339
|
moduleData: {
|
@@ -2345,7 +2388,7 @@ function useSendPermission({
|
|
2345
2388
|
}) {
|
2346
2389
|
const context = _react.useContext.call(void 0, ConnectContext);
|
2347
2390
|
if (context === void 0) {
|
2348
|
-
throw new
|
2391
|
+
throw new NotWithinConnectProviderError("useSendPermission");
|
2349
2392
|
}
|
2350
2393
|
const { smartAccountClient } = useSmartAccount();
|
2351
2394
|
const { data: sessionKeySigner } = useSessionKeySigner({
|
@@ -2359,9 +2402,9 @@ function useSendPermission({
|
|
2359
2402
|
smartAccountClient
|
2360
2403
|
],
|
2361
2404
|
mutationFn: async (args) => {
|
2362
|
-
if (!smartAccountClient) throw new
|
2363
|
-
if (!sessionKeySigner) throw new
|
2364
|
-
if (!context.apikey) throw new
|
2405
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2406
|
+
if (!sessionKeySigner) throw new SignerNotFoundError();
|
2407
|
+
if (!context.apikey) throw new ApiKeyNotFoundError();
|
2365
2408
|
const sessionKeyClient = await createSessionSmartAccountClient(
|
2366
2409
|
context.apikey,
|
2367
2410
|
smartAccountClient,
|
@@ -2390,8 +2433,8 @@ function useSendPermission({
|
|
2390
2433
|
|
2391
2434
|
|
2392
2435
|
|
2436
|
+
|
2393
2437
|
function useSessionKeyClient({
|
2394
|
-
apiKey,
|
2395
2438
|
sessionData,
|
2396
2439
|
privateKey
|
2397
2440
|
}) {
|
@@ -2400,13 +2443,20 @@ function useSessionKeyClient({
|
|
2400
2443
|
sessionData,
|
2401
2444
|
privateKey
|
2402
2445
|
});
|
2446
|
+
const context = _react.useContext.call(void 0, ConnectContext);
|
2447
|
+
if (context === void 0) {
|
2448
|
+
throw new Error(
|
2449
|
+
"useSessionKeyClient must be used within a ConnectProvider"
|
2450
|
+
);
|
2451
|
+
}
|
2403
2452
|
const query = _query.useQuery.call(void 0, {
|
2404
2453
|
queryKey: ["session-key-get-client", sessionKeySigner, smartAccountClient],
|
2405
2454
|
queryFn: async () => {
|
2406
|
-
if (!smartAccountClient) throw new
|
2407
|
-
if (!sessionKeySigner) throw new
|
2455
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2456
|
+
if (!sessionKeySigner) throw new SignerNotFoundError();
|
2457
|
+
if (!context.apikey) throw new ApiKeyNotFoundError();
|
2408
2458
|
return createSessionSmartAccountClient(
|
2409
|
-
|
2459
|
+
context.apikey,
|
2410
2460
|
smartAccountClient,
|
2411
2461
|
sessionKeySigner
|
2412
2462
|
);
|
package/dist/index.d.cts
CHANGED
@@ -1033,21 +1033,6 @@ type ActionData = {
|
|
1033
1033
|
actionPolicies: PolicyData[];
|
1034
1034
|
};
|
1035
1035
|
|
1036
|
-
type Execution = {
|
1037
|
-
target: Address;
|
1038
|
-
value: bigint;
|
1039
|
-
callData: Hex;
|
1040
|
-
};
|
1041
|
-
|
1042
|
-
type PreparePermissionResponse = {
|
1043
|
-
/** Array of permission IDs for the created sessions. */
|
1044
|
-
permissionIds: Hex[];
|
1045
|
-
/** The execution object for the action. */
|
1046
|
-
action: Execution;
|
1047
|
-
/** The sessions that were created. */
|
1048
|
-
sessions: Session[];
|
1049
|
-
};
|
1050
|
-
|
1051
1036
|
declare const createSessionSmartAccountClient: (apiKey: string, smartAccountClient: ContextComethSmartAccountClient, sessionKeySigner: SafeSigner<"safeSmartSessionsSigner">) => Promise<viem.Client<viem.HttpTransport, viem.Chain, _cometh_connect_sdk_4337.ComethSafeSmartAccount, viem.BundlerRpcSchema, {
|
1052
1037
|
grantPermission: (args: _cometh_connect_sdk_4337.GrantPermissionParameters<_cometh_connect_sdk_4337.ComethSafeSmartAccount>) => Promise<_cometh_connect_sdk_4337.GrantPermissionResponse>;
|
1053
1038
|
preparePermission: (args: {
|
@@ -7987,7 +7972,15 @@ declare const createSessionSmartAccountClient: (apiKey: string, smartAccountClie
|
|
7987
7972
|
} & viem.ExactPartial<Pick<viem.PublicActions<viem.Transport, viem.Chain | undefined, undefined>, "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getChainId" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "prepareTransactionRequest" | "readContract" | "sendRawTransaction" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<viem.WalletActions<viem.Chain | undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client: viem.Client<viem.Transport, viem.Chain | undefined, undefined, viem.PublicRpcSchema, viem.PublicActions<viem.Transport, viem.Chain | undefined>>) => client) => viem.Client<viem.Transport, viem.Chain | undefined, undefined, viem.PublicRpcSchema, { [K in keyof client]: client[K]; } & viem.PublicActions<viem.Transport, viem.Chain | undefined>>;
|
7988
7973
|
} | undefined;
|
7989
7974
|
account?: _cometh_connect_sdk_4337.ComethSafeSmartAccount | undefined;
|
7990
|
-
}) => Promise<
|
7975
|
+
}) => Promise<{
|
7976
|
+
permissionIds: viem.Hex[];
|
7977
|
+
action: {
|
7978
|
+
target: viem.Address;
|
7979
|
+
value: bigint;
|
7980
|
+
callData: viem.Hex;
|
7981
|
+
};
|
7982
|
+
sessions: Session[];
|
7983
|
+
}>;
|
7991
7984
|
isPermissionInstalled: (args: {
|
7992
7985
|
session: Session;
|
7993
7986
|
}) => Promise<boolean>;
|
@@ -8001,7 +7994,11 @@ declare const createSessionSmartAccountClient: (apiKey: string, smartAccountClie
|
|
8001
7994
|
threshold?: number;
|
8002
7995
|
} | undefined) => Promise<viem.Hash>;
|
8003
7996
|
usePermission: (args: {
|
8004
|
-
actions:
|
7997
|
+
actions: {
|
7998
|
+
target: viem.Address;
|
7999
|
+
value: bigint;
|
8000
|
+
callData: viem.Hex;
|
8001
|
+
}[];
|
8005
8002
|
maxFeePerGas?: bigint;
|
8006
8003
|
maxPriorityFeePerGas?: bigint;
|
8007
8004
|
verificationGasLimit?: bigint;
|
@@ -8272,8 +8269,7 @@ declare const createSessionSmartAccountClient: (apiKey: string, smartAccountClie
|
|
8272
8269
|
type SmartSessionClient = ReturnType<typeof createSessionSmartAccountClient>;
|
8273
8270
|
|
8274
8271
|
type UseSessionKeyClientReturn = QueryResultType<SmartSessionClient>;
|
8275
|
-
declare function useSessionKeyClient({
|
8276
|
-
apiKey: string;
|
8272
|
+
declare function useSessionKeyClient({ sessionData, privateKey, }: {
|
8277
8273
|
sessionData: GrantPermissionResponse;
|
8278
8274
|
privateKey: Hex;
|
8279
8275
|
}): UseSessionKeyClientReturn;
|
package/dist/index.d.ts
CHANGED
@@ -1033,21 +1033,6 @@ type ActionData = {
|
|
1033
1033
|
actionPolicies: PolicyData[];
|
1034
1034
|
};
|
1035
1035
|
|
1036
|
-
type Execution = {
|
1037
|
-
target: Address;
|
1038
|
-
value: bigint;
|
1039
|
-
callData: Hex;
|
1040
|
-
};
|
1041
|
-
|
1042
|
-
type PreparePermissionResponse = {
|
1043
|
-
/** Array of permission IDs for the created sessions. */
|
1044
|
-
permissionIds: Hex[];
|
1045
|
-
/** The execution object for the action. */
|
1046
|
-
action: Execution;
|
1047
|
-
/** The sessions that were created. */
|
1048
|
-
sessions: Session[];
|
1049
|
-
};
|
1050
|
-
|
1051
1036
|
declare const createSessionSmartAccountClient: (apiKey: string, smartAccountClient: ContextComethSmartAccountClient, sessionKeySigner: SafeSigner<"safeSmartSessionsSigner">) => Promise<viem.Client<viem.HttpTransport, viem.Chain, _cometh_connect_sdk_4337.ComethSafeSmartAccount, viem.BundlerRpcSchema, {
|
1052
1037
|
grantPermission: (args: _cometh_connect_sdk_4337.GrantPermissionParameters<_cometh_connect_sdk_4337.ComethSafeSmartAccount>) => Promise<_cometh_connect_sdk_4337.GrantPermissionResponse>;
|
1053
1038
|
preparePermission: (args: {
|
@@ -7987,7 +7972,15 @@ declare const createSessionSmartAccountClient: (apiKey: string, smartAccountClie
|
|
7987
7972
|
} & viem.ExactPartial<Pick<viem.PublicActions<viem.Transport, viem.Chain | undefined, undefined>, "call" | "createContractEventFilter" | "createEventFilter" | "estimateContractGas" | "estimateGas" | "getBlock" | "getBlockNumber" | "getChainId" | "getContractEvents" | "getEnsText" | "getFilterChanges" | "getGasPrice" | "getLogs" | "getTransaction" | "getTransactionCount" | "getTransactionReceipt" | "prepareTransactionRequest" | "readContract" | "sendRawTransaction" | "simulateContract" | "uninstallFilter" | "watchBlockNumber" | "watchContractEvent"> & Pick<viem.WalletActions<viem.Chain | undefined, undefined>, "sendTransaction" | "writeContract">>>(fn: (client: viem.Client<viem.Transport, viem.Chain | undefined, undefined, viem.PublicRpcSchema, viem.PublicActions<viem.Transport, viem.Chain | undefined>>) => client) => viem.Client<viem.Transport, viem.Chain | undefined, undefined, viem.PublicRpcSchema, { [K in keyof client]: client[K]; } & viem.PublicActions<viem.Transport, viem.Chain | undefined>>;
|
7988
7973
|
} | undefined;
|
7989
7974
|
account?: _cometh_connect_sdk_4337.ComethSafeSmartAccount | undefined;
|
7990
|
-
}) => Promise<
|
7975
|
+
}) => Promise<{
|
7976
|
+
permissionIds: viem.Hex[];
|
7977
|
+
action: {
|
7978
|
+
target: viem.Address;
|
7979
|
+
value: bigint;
|
7980
|
+
callData: viem.Hex;
|
7981
|
+
};
|
7982
|
+
sessions: Session[];
|
7983
|
+
}>;
|
7991
7984
|
isPermissionInstalled: (args: {
|
7992
7985
|
session: Session;
|
7993
7986
|
}) => Promise<boolean>;
|
@@ -8001,7 +7994,11 @@ declare const createSessionSmartAccountClient: (apiKey: string, smartAccountClie
|
|
8001
7994
|
threshold?: number;
|
8002
7995
|
} | undefined) => Promise<viem.Hash>;
|
8003
7996
|
usePermission: (args: {
|
8004
|
-
actions:
|
7997
|
+
actions: {
|
7998
|
+
target: viem.Address;
|
7999
|
+
value: bigint;
|
8000
|
+
callData: viem.Hex;
|
8001
|
+
}[];
|
8005
8002
|
maxFeePerGas?: bigint;
|
8006
8003
|
maxPriorityFeePerGas?: bigint;
|
8007
8004
|
verificationGasLimit?: bigint;
|
@@ -8272,8 +8269,7 @@ declare const createSessionSmartAccountClient: (apiKey: string, smartAccountClie
|
|
8272
8269
|
type SmartSessionClient = ReturnType<typeof createSessionSmartAccountClient>;
|
8273
8270
|
|
8274
8271
|
type UseSessionKeyClientReturn = QueryResultType<SmartSessionClient>;
|
8275
|
-
declare function useSessionKeyClient({
|
8276
|
-
apiKey: string;
|
8272
|
+
declare function useSessionKeyClient({ sessionData, privateKey, }: {
|
8277
8273
|
sessionData: GrantPermissionResponse;
|
8278
8274
|
privateKey: Hex;
|
8279
8275
|
}): UseSessionKeyClientReturn;
|
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;
|
@@ -105,7 +150,7 @@ var ConnectProvider = ({
|
|
105
150
|
const publicClient = config.networksConfig.find(
|
106
151
|
(network) => network.chain?.id === chain.id
|
107
152
|
)?.publicClient;
|
108
|
-
if (!bundlerUrl) throw new
|
153
|
+
if (!bundlerUrl) throw new BundlerUrlNotFoundError();
|
109
154
|
try {
|
110
155
|
const { client, address: newAddress } = await createSmartAccount({
|
111
156
|
...config,
|
@@ -165,7 +210,7 @@ import { useContext, useMemo as useMemo2 } from "react";
|
|
165
210
|
var useAccount = () => {
|
166
211
|
const context = useContext(ConnectContext);
|
167
212
|
if (context === void 0) {
|
168
|
-
throw new
|
213
|
+
throw new NotWithinConnectProviderError("useAccount");
|
169
214
|
}
|
170
215
|
const { smartAccountClient, smartAccountAddress } = context;
|
171
216
|
const { chain, chainId } = useMemo2(
|
@@ -198,7 +243,7 @@ import { useContext as useContext2 } from "react";
|
|
198
243
|
var useSmartAccount = () => {
|
199
244
|
const context = useContext2(ConnectContext);
|
200
245
|
if (context === void 0) {
|
201
|
-
throw new
|
246
|
+
throw new NotWithinSmartAccountProviderError();
|
202
247
|
}
|
203
248
|
return context;
|
204
249
|
};
|
@@ -1366,7 +1411,7 @@ var useSendTransaction = (mutationProps) => {
|
|
1366
1411
|
// Define the mutation function
|
1367
1412
|
mutationFn: (variables) => {
|
1368
1413
|
if (!smartAccountClient) {
|
1369
|
-
throw new
|
1414
|
+
throw new SmartAccountNotFoundError();
|
1370
1415
|
}
|
1371
1416
|
const { calls } = variables;
|
1372
1417
|
if (!Array.isArray(calls)) {
|
@@ -1400,7 +1445,7 @@ var useWriteContract = (mutationProps) => {
|
|
1400
1445
|
{
|
1401
1446
|
mutationFn: async (variables) => {
|
1402
1447
|
if (!smartAccountClient) {
|
1403
|
-
throw new
|
1448
|
+
throw new SmartAccountNotFoundError();
|
1404
1449
|
}
|
1405
1450
|
const { abi, address, functionName, args, value } = variables;
|
1406
1451
|
const data = encodeFunctionData({
|
@@ -1435,7 +1480,7 @@ import { useCallback as useCallback4, useContext as useContext6, useState as use
|
|
1435
1480
|
var useConnect = () => {
|
1436
1481
|
const context = useContext6(ConnectContext);
|
1437
1482
|
if (context === void 0) {
|
1438
|
-
throw new
|
1483
|
+
throw new NotWithinConnectProviderError("useConnect");
|
1439
1484
|
}
|
1440
1485
|
const { queryClient, updateSmartAccountClient } = context;
|
1441
1486
|
const [isPending, setIsPending] = useState5(false);
|
@@ -1487,7 +1532,7 @@ import { useCallback as useCallback5, useContext as useContext7, useState as use
|
|
1487
1532
|
var useDisconnect = () => {
|
1488
1533
|
const context = useContext7(ConnectContext);
|
1489
1534
|
if (context === void 0) {
|
1490
|
-
throw new
|
1535
|
+
throw new NotWithinConnectProviderError("useDisconnect");
|
1491
1536
|
}
|
1492
1537
|
const { queryClient, disconnectSmartAccount } = context;
|
1493
1538
|
const [isPending, setIsPending] = useState6(false);
|
@@ -1500,7 +1545,7 @@ var useDisconnect = () => {
|
|
1500
1545
|
queryKey: ["connect"]
|
1501
1546
|
});
|
1502
1547
|
}).catch((e) => {
|
1503
|
-
const err = e instanceof Error ? e : new
|
1548
|
+
const err = e instanceof Error ? e : new UseDisconnectError();
|
1504
1549
|
setError(err);
|
1505
1550
|
}).finally(() => {
|
1506
1551
|
setIsPending(false);
|
@@ -1513,7 +1558,7 @@ var useDisconnect = () => {
|
|
1513
1558
|
await disconnectSmartAccount();
|
1514
1559
|
queryClient?.invalidateQueries({ queryKey: ["connect"] });
|
1515
1560
|
} catch (e) {
|
1516
|
-
const err = e instanceof Error ? e : new
|
1561
|
+
const err = e instanceof Error ? e : new UseDisconnectError();
|
1517
1562
|
setError(err);
|
1518
1563
|
throw err;
|
1519
1564
|
} finally {
|
@@ -1535,7 +1580,7 @@ var useAddOwner = (mutationProps) => {
|
|
1535
1580
|
{
|
1536
1581
|
mutationFn: async ({ ownerToAdd }) => {
|
1537
1582
|
if (!smartAccountClient) {
|
1538
|
-
throw new
|
1583
|
+
throw new SmartAccountNotFoundError();
|
1539
1584
|
}
|
1540
1585
|
return await smartAccountClient.addOwner({ ownerToAdd });
|
1541
1586
|
},
|
@@ -1561,7 +1606,7 @@ var useRemoveOwner = (mutationProps) => {
|
|
1561
1606
|
ownerToRemove
|
1562
1607
|
}) => {
|
1563
1608
|
if (!smartAccountClient) {
|
1564
|
-
throw new
|
1609
|
+
throw new SmartAccountNotFoundError();
|
1565
1610
|
}
|
1566
1611
|
return await smartAccountClient.removeOwner({ ownerToRemove });
|
1567
1612
|
},
|
@@ -1586,7 +1631,7 @@ var useGetOwners = (queryProps) => {
|
|
1586
1631
|
queryKey: ["getOwners"],
|
1587
1632
|
queryFn: async () => {
|
1588
1633
|
if (!smartAccountClient) {
|
1589
|
-
throw new
|
1634
|
+
throw new SmartAccountNotFoundError();
|
1590
1635
|
}
|
1591
1636
|
return await smartAccountClient.getOwners();
|
1592
1637
|
},
|
@@ -1602,7 +1647,7 @@ var useGetEnrichedOwners = (queryProps) => {
|
|
1602
1647
|
queryKey: ["getEnrichedOwners"],
|
1603
1648
|
queryFn: async () => {
|
1604
1649
|
if (!smartAccountClient) {
|
1605
|
-
throw new
|
1650
|
+
throw new SmartAccountNotFoundError();
|
1606
1651
|
}
|
1607
1652
|
return await smartAccountClient.getEnrichedOwners();
|
1608
1653
|
},
|
@@ -1619,7 +1664,7 @@ var useValidateAddDevice = (mutationProps) => {
|
|
1619
1664
|
{
|
1620
1665
|
mutationFn: (variables) => {
|
1621
1666
|
if (!smartAccountClient) {
|
1622
|
-
throw new
|
1667
|
+
throw new SmartAccountNotFoundError();
|
1623
1668
|
}
|
1624
1669
|
const { signer } = variables;
|
1625
1670
|
return smartAccountClient.validateAddDevice({ signer });
|
@@ -1646,7 +1691,7 @@ var useVerifyMessage = (mutationProps) => {
|
|
1646
1691
|
{
|
1647
1692
|
mutationFn: async (variables) => {
|
1648
1693
|
if (!smartAccountClient) {
|
1649
|
-
throw new
|
1694
|
+
throw new SmartAccountNotFoundError();
|
1650
1695
|
}
|
1651
1696
|
const { message, signature } = variables;
|
1652
1697
|
return smartAccountClient.verifySignature({
|
@@ -1678,7 +1723,7 @@ var useGetGasPrice = (rpcUrl, queryProps) => {
|
|
1678
1723
|
queryKey: ["gasPrice", rpcUrl],
|
1679
1724
|
queryFn: async () => {
|
1680
1725
|
if (!smartAccountClient) {
|
1681
|
-
throw new
|
1726
|
+
throw new SmartAccountNotFoundError();
|
1682
1727
|
}
|
1683
1728
|
const publicClient = createPublicClient({
|
1684
1729
|
chain: smartAccountClient.chain,
|
@@ -1932,7 +1977,7 @@ function useSignMessage() {
|
|
1932
1977
|
{
|
1933
1978
|
mutationFn: async ({ message }) => {
|
1934
1979
|
if (!smartAccountClient) {
|
1935
|
-
throw new
|
1980
|
+
throw new SmartAccountNotFoundError();
|
1936
1981
|
}
|
1937
1982
|
const signature = await smartAccountClient.account.signMessage({
|
1938
1983
|
message
|
@@ -1960,7 +2005,7 @@ function useSetUpRecovery() {
|
|
1960
2005
|
{
|
1961
2006
|
mutationFn: async () => {
|
1962
2007
|
if (!smartAccountClient) {
|
1963
|
-
throw new
|
2008
|
+
throw new SmartAccountNotFoundError();
|
1964
2009
|
}
|
1965
2010
|
return smartAccountClient.setUpRecoveryModule();
|
1966
2011
|
}
|
@@ -1986,7 +2031,7 @@ function useIsRecoveryActive(props = {}) {
|
|
1986
2031
|
queryKey: ["isRecoveryActive"],
|
1987
2032
|
queryFn: async () => {
|
1988
2033
|
if (!smartAccountClient) {
|
1989
|
-
throw new
|
2034
|
+
throw new SmartAccountNotFoundError();
|
1990
2035
|
}
|
1991
2036
|
return smartAccountClient.isRecoveryActive(props);
|
1992
2037
|
},
|
@@ -2004,7 +2049,7 @@ function useGetRecoveryRequest(props = {}, queryOptions) {
|
|
2004
2049
|
queryKey: ["getRecoveryRequest"],
|
2005
2050
|
queryFn: async () => {
|
2006
2051
|
if (!smartAccountClient) {
|
2007
|
-
throw new
|
2052
|
+
throw new SmartAccountNotFoundError();
|
2008
2053
|
}
|
2009
2054
|
return smartAccountClient.getRecoveryRequest(props);
|
2010
2055
|
},
|
@@ -2028,7 +2073,7 @@ function useCancelRecoveryRequest() {
|
|
2028
2073
|
{
|
2029
2074
|
mutationFn: async (variables) => {
|
2030
2075
|
if (!smartAccountClient) {
|
2031
|
-
throw new
|
2076
|
+
throw new SmartAccountNotFoundError();
|
2032
2077
|
}
|
2033
2078
|
return smartAccountClient.cancelRecoveryRequest({
|
2034
2079
|
effectiveDelayAddress: variables.effectiveDelayAddress
|
@@ -2053,7 +2098,7 @@ import { useCallback as useCallback8, useContext as useContext8, useState as use
|
|
2053
2098
|
var useSwitchChain = () => {
|
2054
2099
|
const context = useContext8(ConnectContext);
|
2055
2100
|
if (context === void 0) {
|
2056
|
-
throw new
|
2101
|
+
throw new NotWithinConnectProviderError("useSwitchChain");
|
2057
2102
|
}
|
2058
2103
|
const {
|
2059
2104
|
queryClient,
|
@@ -2067,12 +2112,12 @@ var useSwitchChain = () => {
|
|
2067
2112
|
async (params) => {
|
2068
2113
|
const { chainId } = params;
|
2069
2114
|
if (!networksConfig)
|
2070
|
-
throw new
|
2115
|
+
throw new NoCurrentConfigurationError();
|
2071
2116
|
const selectedNetwork = networksConfig?.find(
|
2072
2117
|
(network) => network.chain?.id === chainId
|
2073
2118
|
);
|
2074
2119
|
if (!selectedNetwork)
|
2075
|
-
throw new
|
2120
|
+
throw new NoCurrentConfigurationError();
|
2076
2121
|
try {
|
2077
2122
|
const client = await updateSmartAccountClient({
|
2078
2123
|
address: smartAccountClient?.account.address,
|
@@ -2083,7 +2128,7 @@ var useSwitchChain = () => {
|
|
2083
2128
|
});
|
2084
2129
|
return client;
|
2085
2130
|
} catch (e) {
|
2086
|
-
throw e instanceof Error ? e : new
|
2131
|
+
throw e instanceof Error ? e : new UseSwitchChainError();
|
2087
2132
|
}
|
2088
2133
|
},
|
2089
2134
|
[
|
@@ -2098,9 +2143,7 @@ var useSwitchChain = () => {
|
|
2098
2143
|
setIsPending(true);
|
2099
2144
|
setError(null);
|
2100
2145
|
return switchChainInternal(params).catch((e) => {
|
2101
|
-
const err = e instanceof Error ? e : new
|
2102
|
-
"An error occurred while switching chain"
|
2103
|
-
);
|
2146
|
+
const err = e instanceof Error ? e : new UseSwitchChainError();
|
2104
2147
|
setError(err);
|
2105
2148
|
}).finally(() => {
|
2106
2149
|
setIsPending(false);
|
@@ -2116,7 +2159,7 @@ var useSwitchChain = () => {
|
|
2116
2159
|
const client = await switchChainInternal(params);
|
2117
2160
|
return client;
|
2118
2161
|
} catch (e) {
|
2119
|
-
const err = e instanceof Error ? e : new
|
2162
|
+
const err = e instanceof Error ? e : new UseSwitchChainError();
|
2120
2163
|
setError(err);
|
2121
2164
|
throw err;
|
2122
2165
|
} finally {
|
@@ -2144,7 +2187,7 @@ var useGetTransactionCost = (mutationProps) => {
|
|
2144
2187
|
{
|
2145
2188
|
mutationFn: async (variables) => {
|
2146
2189
|
if (!smartAccountClient) {
|
2147
|
-
throw new
|
2190
|
+
throw new SmartAccountNotFoundError();
|
2148
2191
|
}
|
2149
2192
|
const bundlerClient = createBundlerClient({
|
2150
2193
|
account: smartAccountClient.account,
|
@@ -2183,7 +2226,7 @@ var useEstimateGas = (mutationProps) => {
|
|
2183
2226
|
{
|
2184
2227
|
mutationFn: async (variables) => {
|
2185
2228
|
if (!smartAccountClient) {
|
2186
|
-
throw new
|
2229
|
+
throw new SmartAccountNotFoundError();
|
2187
2230
|
}
|
2188
2231
|
const publicClient = createPublicClient2({
|
2189
2232
|
chain: smartAccountClient.chain,
|
@@ -2243,7 +2286,7 @@ function useGrantPermission(mutationProps) {
|
|
2243
2286
|
const { mutate, mutateAsync, ...result } = useMutation2({
|
2244
2287
|
mutationKey: ["session-key-grant-permission", smartAccountClient],
|
2245
2288
|
mutationFn: async (args) => {
|
2246
|
-
if (!smartAccountClient) throw new
|
2289
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2247
2290
|
const safe7559Account = smartAccountClient.extend(smartSessionActions()).extend(erc7579Actions());
|
2248
2291
|
const createSessionsResponse = await safe7559Account.grantPermission(
|
2249
2292
|
args
|
@@ -2290,7 +2333,7 @@ function useSessionKeySigner({
|
|
2290
2333
|
const query = useQuery2({
|
2291
2334
|
queryKey: ["session-key-signer", smartAccountClient],
|
2292
2335
|
queryFn: async () => {
|
2293
|
-
if (!smartAccountClient) throw new
|
2336
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2294
2337
|
const safe7559Account = smartAccountClient.extend(smartSessionActions2()).extend(erc7579Actions2());
|
2295
2338
|
return toSmartSessionsSigner(safe7559Account, {
|
2296
2339
|
moduleData: {
|
@@ -2345,7 +2388,7 @@ function useSendPermission({
|
|
2345
2388
|
}) {
|
2346
2389
|
const context = useContext9(ConnectContext);
|
2347
2390
|
if (context === void 0) {
|
2348
|
-
throw new
|
2391
|
+
throw new NotWithinConnectProviderError("useSendPermission");
|
2349
2392
|
}
|
2350
2393
|
const { smartAccountClient } = useSmartAccount();
|
2351
2394
|
const { data: sessionKeySigner } = useSessionKeySigner({
|
@@ -2359,9 +2402,9 @@ function useSendPermission({
|
|
2359
2402
|
smartAccountClient
|
2360
2403
|
],
|
2361
2404
|
mutationFn: async (args) => {
|
2362
|
-
if (!smartAccountClient) throw new
|
2363
|
-
if (!sessionKeySigner) throw new
|
2364
|
-
if (!context.apikey) throw new
|
2405
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2406
|
+
if (!sessionKeySigner) throw new SignerNotFoundError();
|
2407
|
+
if (!context.apikey) throw new ApiKeyNotFoundError();
|
2365
2408
|
const sessionKeyClient = await createSessionSmartAccountClient(
|
2366
2409
|
context.apikey,
|
2367
2410
|
smartAccountClient,
|
@@ -2390,8 +2433,8 @@ function useSendPermission({
|
|
2390
2433
|
import { useQuery as useQuery3 } from "wagmi/query";
|
2391
2434
|
import "@cometh/connect-sdk-4337";
|
2392
2435
|
import "viem";
|
2436
|
+
import { useContext as useContext10 } from "react";
|
2393
2437
|
function useSessionKeyClient({
|
2394
|
-
apiKey,
|
2395
2438
|
sessionData,
|
2396
2439
|
privateKey
|
2397
2440
|
}) {
|
@@ -2400,13 +2443,20 @@ function useSessionKeyClient({
|
|
2400
2443
|
sessionData,
|
2401
2444
|
privateKey
|
2402
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
|
+
}
|
2403
2452
|
const query = useQuery3({
|
2404
2453
|
queryKey: ["session-key-get-client", sessionKeySigner, smartAccountClient],
|
2405
2454
|
queryFn: async () => {
|
2406
|
-
if (!smartAccountClient) throw new
|
2407
|
-
if (!sessionKeySigner) throw new
|
2455
|
+
if (!smartAccountClient) throw new SmartAccountNotFoundError();
|
2456
|
+
if (!sessionKeySigner) throw new SignerNotFoundError();
|
2457
|
+
if (!context.apikey) throw new ApiKeyNotFoundError();
|
2408
2458
|
return createSessionSmartAccountClient(
|
2409
|
-
|
2459
|
+
context.apikey,
|
2410
2460
|
smartAccountClient,
|
2411
2461
|
sessionKeySigner
|
2412
2462
|
);
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"url": "https://twitter.com/slovaye"
|
8
8
|
}
|
9
9
|
],
|
10
|
-
"version": "1.0.1",
|
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
|
}
|