@cometh/connect-react-hooks 0.1.0-dev.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +209 -23
- package/dist/index.d.cts +7340 -35
- package/dist/index.d.ts +7340 -35
- package/dist/index.js +208 -22
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -83,7 +83,8 @@ var ConnectContext = createContext({
|
|
83
83
|
},
|
84
84
|
disconnectSmartAccount: async () => {
|
85
85
|
},
|
86
|
-
networksConfig: void 0
|
86
|
+
networksConfig: void 0,
|
87
|
+
apikey: void 0
|
87
88
|
});
|
88
89
|
var ConnectProvider = ({
|
89
90
|
children,
|
@@ -101,9 +102,9 @@ var ConnectProvider = ({
|
|
101
102
|
const paymasterUrl = config.networksConfig.find(
|
102
103
|
(network) => network.chain?.id === chain.id
|
103
104
|
)?.paymasterUrl;
|
104
|
-
const
|
105
|
+
const publicClient = config.networksConfig.find(
|
105
106
|
(network) => network.chain?.id === chain.id
|
106
|
-
)?.
|
107
|
+
)?.publicClient;
|
107
108
|
if (!bundlerUrl) throw new Error("Bundler url not found");
|
108
109
|
try {
|
109
110
|
const { client, address: newAddress } = await createSmartAccount({
|
@@ -111,7 +112,7 @@ var ConnectProvider = ({
|
|
111
112
|
chain,
|
112
113
|
bundlerUrl,
|
113
114
|
paymasterUrl,
|
114
|
-
|
115
|
+
publicClient,
|
115
116
|
smartAccountAddress: params.address,
|
116
117
|
comethSignerConfig: {
|
117
118
|
...config.comethSignerConfig,
|
@@ -144,7 +145,8 @@ var ConnectProvider = ({
|
|
144
145
|
smartAccountAddress,
|
145
146
|
updateSmartAccountClient,
|
146
147
|
disconnectSmartAccount,
|
147
|
-
networksConfig: config.networksConfig
|
148
|
+
networksConfig: config.networksConfig,
|
149
|
+
apikey: config.apiKey
|
148
150
|
}),
|
149
151
|
[
|
150
152
|
queryClient,
|
@@ -1271,14 +1273,15 @@ function useBaseQuery(options, Observer, queryClient) {
|
|
1271
1273
|
)
|
1272
1274
|
);
|
1273
1275
|
const result = observer.getOptimisticResult(defaultedOptions);
|
1276
|
+
const shouldSubscribe = !isRestoring && options.subscribed !== false;
|
1274
1277
|
React6.useSyncExternalStore(
|
1275
1278
|
React6.useCallback(
|
1276
1279
|
(onStoreChange) => {
|
1277
|
-
const unsubscribe =
|
1280
|
+
const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop2;
|
1278
1281
|
observer.updateResult();
|
1279
1282
|
return unsubscribe;
|
1280
1283
|
},
|
1281
|
-
[observer,
|
1284
|
+
[observer, shouldSubscribe]
|
1282
1285
|
),
|
1283
1286
|
() => observer.getCurrentResult(),
|
1284
1287
|
() => observer.getCurrentResult()
|
@@ -1530,9 +1533,7 @@ var useAddOwner = (mutationProps) => {
|
|
1530
1533
|
const { smartAccountClient, queryClient } = useSmartAccount();
|
1531
1534
|
const { mutate, mutateAsync, ...result } = useMutation(
|
1532
1535
|
{
|
1533
|
-
mutationFn: async ({
|
1534
|
-
ownerToAdd
|
1535
|
-
}) => {
|
1536
|
+
mutationFn: async ({ ownerToAdd }) => {
|
1536
1537
|
if (!smartAccountClient) {
|
1537
1538
|
throw new Error("No smart account found");
|
1538
1539
|
}
|
@@ -1957,15 +1958,11 @@ function useSetUpRecovery() {
|
|
1957
1958
|
const { smartAccountClient, queryClient } = useSmartAccount();
|
1958
1959
|
const { mutate, mutateAsync, ...result } = useMutation(
|
1959
1960
|
{
|
1960
|
-
mutationFn: async (
|
1961
|
+
mutationFn: async () => {
|
1961
1962
|
if (!smartAccountClient) {
|
1962
1963
|
throw new Error("No smart account found");
|
1963
1964
|
}
|
1964
|
-
return smartAccountClient.setUpRecoveryModule(
|
1965
|
-
passKeyName: variables.passKeyName,
|
1966
|
-
publicClient: variables.publicClient,
|
1967
|
-
webAuthnOptions: variables.webAuthnOptions
|
1968
|
-
});
|
1965
|
+
return smartAccountClient.setUpRecoveryModule();
|
1969
1966
|
}
|
1970
1967
|
},
|
1971
1968
|
queryClient
|
@@ -1986,7 +1983,7 @@ function useIsRecoveryActive(props = {}) {
|
|
1986
1983
|
const { smartAccountClient, queryClient } = useSmartAccount();
|
1987
1984
|
return useQuery(
|
1988
1985
|
{
|
1989
|
-
queryKey: ["isRecoveryActive"
|
1986
|
+
queryKey: ["isRecoveryActive"],
|
1990
1987
|
queryFn: async () => {
|
1991
1988
|
if (!smartAccountClient) {
|
1992
1989
|
throw new Error("No smart account found");
|
@@ -2004,7 +2001,7 @@ function useGetRecoveryRequest(props = {}, queryOptions) {
|
|
2004
2001
|
const { smartAccountClient, queryClient } = useSmartAccount();
|
2005
2002
|
const { data, isLoading, isError, error } = useQuery(
|
2006
2003
|
{
|
2007
|
-
queryKey: ["getRecoveryRequest"
|
2004
|
+
queryKey: ["getRecoveryRequest"],
|
2008
2005
|
queryFn: async () => {
|
2009
2006
|
if (!smartAccountClient) {
|
2010
2007
|
throw new Error("No smart account found");
|
@@ -2034,7 +2031,7 @@ function useCancelRecoveryRequest() {
|
|
2034
2031
|
throw new Error("No smart account found");
|
2035
2032
|
}
|
2036
2033
|
return smartAccountClient.cancelRecoveryRequest({
|
2037
|
-
|
2034
|
+
effectiveDelayAddress: variables.effectiveDelayAddress
|
2038
2035
|
});
|
2039
2036
|
}
|
2040
2037
|
},
|
@@ -2077,13 +2074,14 @@ var useSwitchChain = () => {
|
|
2077
2074
|
if (!selectedNetwork)
|
2078
2075
|
throw new Error("No current configuration found");
|
2079
2076
|
try {
|
2080
|
-
await updateSmartAccountClient({
|
2077
|
+
const client = await updateSmartAccountClient({
|
2081
2078
|
address: smartAccountClient?.account.address,
|
2082
2079
|
chain: selectedNetwork.chain
|
2083
2080
|
});
|
2084
2081
|
queryClient?.invalidateQueries({
|
2085
2082
|
queryKey: ["switchChain"]
|
2086
2083
|
});
|
2084
|
+
return client;
|
2087
2085
|
} catch (e) {
|
2088
2086
|
throw e instanceof Error ? e : new Error("An error occurred while switching chain");
|
2089
2087
|
}
|
@@ -2099,7 +2097,7 @@ var useSwitchChain = () => {
|
|
2099
2097
|
(params) => {
|
2100
2098
|
setIsPending(true);
|
2101
2099
|
setError(null);
|
2102
|
-
switchChainInternal(params).catch((e) => {
|
2100
|
+
return switchChainInternal(params).catch((e) => {
|
2103
2101
|
const err = e instanceof Error ? e : new Error(
|
2104
2102
|
"An error occurred while switching chain"
|
2105
2103
|
);
|
@@ -2115,7 +2113,8 @@ var useSwitchChain = () => {
|
|
2115
2113
|
setIsPending(true);
|
2116
2114
|
setError(null);
|
2117
2115
|
try {
|
2118
|
-
await switchChainInternal(params);
|
2116
|
+
const client = await switchChainInternal(params);
|
2117
|
+
return client;
|
2119
2118
|
} catch (e) {
|
2120
2119
|
const err = e instanceof Error ? e : new Error("An error occurred while switching chain");
|
2121
2120
|
setError(err);
|
@@ -2232,6 +2231,189 @@ var useEstimateGas = (mutationProps) => {
|
|
2232
2231
|
estimateGasAsync: mutateAsync
|
2233
2232
|
};
|
2234
2233
|
};
|
2234
|
+
|
2235
|
+
// src/hooks/session-key/useGrantPermission.ts
|
2236
|
+
import { useMutation as useMutation2 } from "wagmi/query";
|
2237
|
+
import {
|
2238
|
+
erc7579Actions,
|
2239
|
+
smartSessionActions
|
2240
|
+
} from "@cometh/connect-sdk-4337";
|
2241
|
+
function useGrantPermission(mutationProps) {
|
2242
|
+
const { smartAccountClient } = useSmartAccount();
|
2243
|
+
const { mutate, mutateAsync, ...result } = useMutation2({
|
2244
|
+
mutationKey: ["session-key-grant-permission", smartAccountClient],
|
2245
|
+
mutationFn: async (args) => {
|
2246
|
+
if (!smartAccountClient) throw new Error("No smart account found");
|
2247
|
+
const safe7559Account = smartAccountClient.extend(smartSessionActions()).extend(erc7579Actions());
|
2248
|
+
const createSessionsResponse = await safe7559Account.grantPermission(
|
2249
|
+
args
|
2250
|
+
);
|
2251
|
+
const response = await safe7559Account.waitForUserOperationReceipt({
|
2252
|
+
hash: createSessionsResponse.userOpHash
|
2253
|
+
});
|
2254
|
+
return {
|
2255
|
+
txHash: response.receipt.transactionHash,
|
2256
|
+
createSessionsResponse
|
2257
|
+
};
|
2258
|
+
},
|
2259
|
+
...mutationProps
|
2260
|
+
});
|
2261
|
+
return {
|
2262
|
+
data: result.data,
|
2263
|
+
error: result.error,
|
2264
|
+
isPending: result.isPending,
|
2265
|
+
isSuccess: result.isSuccess,
|
2266
|
+
isError: result.isError,
|
2267
|
+
grantPermission: mutate,
|
2268
|
+
grantPermissionAsync: mutateAsync
|
2269
|
+
};
|
2270
|
+
}
|
2271
|
+
|
2272
|
+
// src/hooks/session-key/useSendPermission.ts
|
2273
|
+
import { useMutation as useMutation3 } from "wagmi/query";
|
2274
|
+
import "@cometh/connect-sdk-4337";
|
2275
|
+
import "viem";
|
2276
|
+
|
2277
|
+
// src/hooks/session-key/useSessionKeySigner.ts
|
2278
|
+
import {
|
2279
|
+
erc7579Actions as erc7579Actions2,
|
2280
|
+
smartSessionActions as smartSessionActions2,
|
2281
|
+
toSmartSessionsSigner
|
2282
|
+
} from "@cometh/connect-sdk-4337";
|
2283
|
+
import { useQuery as useQuery2 } from "wagmi/query";
|
2284
|
+
import { privateKeyToAccount } from "viem/accounts";
|
2285
|
+
function useSessionKeySigner({
|
2286
|
+
sessionData,
|
2287
|
+
privateKey
|
2288
|
+
}) {
|
2289
|
+
const { smartAccountClient } = useSmartAccount();
|
2290
|
+
const query = useQuery2({
|
2291
|
+
queryKey: ["session-key-signer", smartAccountClient],
|
2292
|
+
queryFn: async () => {
|
2293
|
+
if (!smartAccountClient) throw new Error("No smart account found");
|
2294
|
+
const safe7559Account = smartAccountClient.extend(smartSessionActions2()).extend(erc7579Actions2());
|
2295
|
+
return toSmartSessionsSigner(safe7559Account, {
|
2296
|
+
moduleData: {
|
2297
|
+
permissionIds: sessionData.permissionIds,
|
2298
|
+
action: sessionData.action,
|
2299
|
+
mode: "0x00",
|
2300
|
+
sessions: sessionData.sessions
|
2301
|
+
},
|
2302
|
+
signer: privateKeyToAccount(privateKey)
|
2303
|
+
});
|
2304
|
+
},
|
2305
|
+
enabled: !!smartAccountClient
|
2306
|
+
});
|
2307
|
+
return query;
|
2308
|
+
}
|
2309
|
+
|
2310
|
+
// src/actions/createSessionSmartAccount.ts
|
2311
|
+
import {
|
2312
|
+
createSafeSmartAccount as createSafeSmartAccount2,
|
2313
|
+
createSmartAccountClient as createSmartAccountClient2,
|
2314
|
+
smartSessionActions as smartSessionActions3
|
2315
|
+
} from "@cometh/connect-sdk-4337";
|
2316
|
+
import { http as http5 } from "viem";
|
2317
|
+
var createSessionSmartAccountClient = async (apiKey, smartAccountClient, sessionKeySigner) => {
|
2318
|
+
const sessionKeyAccount = await createSafeSmartAccount2({
|
2319
|
+
apiKey,
|
2320
|
+
chain: smartAccountClient.chain,
|
2321
|
+
smartAccountAddress: smartAccountClient.account.address,
|
2322
|
+
smartSessionSigner: sessionKeySigner
|
2323
|
+
});
|
2324
|
+
const paymasterClient = smartAccountClient.paymaster;
|
2325
|
+
const bundlerUrl = smartAccountClient.transport.url;
|
2326
|
+
return createSmartAccountClient2({
|
2327
|
+
account: sessionKeyAccount,
|
2328
|
+
chain: smartAccountClient.chain,
|
2329
|
+
bundlerTransport: http5(bundlerUrl),
|
2330
|
+
paymaster: paymasterClient,
|
2331
|
+
userOperation: {
|
2332
|
+
estimateFeesPerGas: async () => {
|
2333
|
+
return await paymasterClient.getUserOperationGasPrice();
|
2334
|
+
}
|
2335
|
+
}
|
2336
|
+
}).extend(smartSessionActions3());
|
2337
|
+
};
|
2338
|
+
|
2339
|
+
// src/hooks/session-key/useSendPermission.ts
|
2340
|
+
import { useContext as useContext9 } from "react";
|
2341
|
+
function useSendPermission({
|
2342
|
+
sessionData,
|
2343
|
+
privateKey,
|
2344
|
+
mutationProps
|
2345
|
+
}) {
|
2346
|
+
const context = useContext9(ConnectContext);
|
2347
|
+
if (context === void 0) {
|
2348
|
+
throw new Error("useSendPermission must be used within a ConnectProvider");
|
2349
|
+
}
|
2350
|
+
const { smartAccountClient } = useSmartAccount();
|
2351
|
+
const { data: sessionKeySigner } = useSessionKeySigner({
|
2352
|
+
sessionData,
|
2353
|
+
privateKey
|
2354
|
+
});
|
2355
|
+
const { mutate, mutateAsync, ...result } = useMutation3({
|
2356
|
+
mutationKey: [
|
2357
|
+
"session-key-send-permission",
|
2358
|
+
sessionKeySigner,
|
2359
|
+
smartAccountClient
|
2360
|
+
],
|
2361
|
+
mutationFn: async (args) => {
|
2362
|
+
if (!smartAccountClient) throw new Error("No smart account found");
|
2363
|
+
if (!sessionKeySigner) throw new Error("No signer found");
|
2364
|
+
if (!context.apikey) throw new Error("No apikey found");
|
2365
|
+
const sessionKeyClient = await createSessionSmartAccountClient(
|
2366
|
+
context.apikey,
|
2367
|
+
smartAccountClient,
|
2368
|
+
sessionKeySigner
|
2369
|
+
);
|
2370
|
+
const userOpHash = await sessionKeyClient.usePermission(args);
|
2371
|
+
const userOp = await sessionKeyClient.waitForUserOperationReceipt({
|
2372
|
+
hash: userOpHash
|
2373
|
+
});
|
2374
|
+
return userOp.receipt.transactionHash;
|
2375
|
+
},
|
2376
|
+
...mutationProps
|
2377
|
+
});
|
2378
|
+
return {
|
2379
|
+
data: result.data,
|
2380
|
+
error: result.error,
|
2381
|
+
isPending: result.isPending,
|
2382
|
+
isSuccess: result.isSuccess,
|
2383
|
+
isError: result.isError,
|
2384
|
+
sendPermission: mutate,
|
2385
|
+
sendPermissionAsync: mutateAsync
|
2386
|
+
};
|
2387
|
+
}
|
2388
|
+
|
2389
|
+
// src/hooks/session-key/useSessionKeyClient.ts
|
2390
|
+
import { useQuery as useQuery3 } from "wagmi/query";
|
2391
|
+
import "@cometh/connect-sdk-4337";
|
2392
|
+
import "viem";
|
2393
|
+
function useSessionKeyClient({
|
2394
|
+
apiKey,
|
2395
|
+
sessionData,
|
2396
|
+
privateKey
|
2397
|
+
}) {
|
2398
|
+
const { smartAccountClient } = useSmartAccount();
|
2399
|
+
const { data: sessionKeySigner } = useSessionKeySigner({
|
2400
|
+
sessionData,
|
2401
|
+
privateKey
|
2402
|
+
});
|
2403
|
+
const query = useQuery3({
|
2404
|
+
queryKey: ["session-key-get-client", sessionKeySigner, smartAccountClient],
|
2405
|
+
queryFn: async () => {
|
2406
|
+
if (!smartAccountClient) throw new Error("No smart account found");
|
2407
|
+
if (!sessionKeySigner) throw new Error("No signer found");
|
2408
|
+
return createSessionSmartAccountClient(
|
2409
|
+
apiKey,
|
2410
|
+
smartAccountClient,
|
2411
|
+
sessionKeySigner
|
2412
|
+
);
|
2413
|
+
}
|
2414
|
+
});
|
2415
|
+
return query;
|
2416
|
+
}
|
2235
2417
|
export {
|
2236
2418
|
ConnectProvider,
|
2237
2419
|
useAccount,
|
@@ -2247,12 +2429,16 @@ export {
|
|
2247
2429
|
useGetOwners,
|
2248
2430
|
useGetRecoveryRequest,
|
2249
2431
|
useGetTransactionCost,
|
2432
|
+
useGrantPermission,
|
2250
2433
|
useIsRecoveryActive,
|
2251
2434
|
useRemoveOwner,
|
2252
2435
|
useRetrieveAccountAddressFromPasskeyId,
|
2253
2436
|
useRetrieveAccountAddressFromPasskeys,
|
2437
|
+
useSendPermission,
|
2254
2438
|
useSendTransaction,
|
2255
2439
|
useSerializeUrlWithSignerPayload,
|
2440
|
+
useSessionKeyClient,
|
2441
|
+
useSessionKeySigner,
|
2256
2442
|
useSetUpRecovery,
|
2257
2443
|
useSignMessage,
|
2258
2444
|
useSwitchChain,
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"url": "https://twitter.com/slovaye"
|
8
8
|
}
|
9
9
|
],
|
10
|
-
"version": "
|
10
|
+
"version": "1.0.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": "^
|
61
|
+
"@cometh/connect-sdk-4337": "^1.0.1",
|
62
62
|
"permissionless": "^0.2.23"
|
63
63
|
}
|
64
64
|
}
|