@cometh/connect-react-hooks 1.0.0 → 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.js CHANGED
@@ -79,10 +79,12 @@ var ConnectContext = createContext({
79
79
  queryClient: void 0,
80
80
  smartAccountClient: null,
81
81
  smartAccountAddress: void 0,
82
- updateSmartAccountClient: async () => null,
82
+ updateSmartAccountClient: async () => {
83
+ },
83
84
  disconnectSmartAccount: async () => {
84
85
  },
85
- networksConfig: void 0
86
+ networksConfig: void 0,
87
+ apikey: void 0
86
88
  });
87
89
  var ConnectProvider = ({
88
90
  children,
@@ -120,10 +122,8 @@ var ConnectProvider = ({
120
122
  setSmartAccountClient(client);
121
123
  setSmartAccountAddress(newAddress);
122
124
  localStorage.setItem(CHAIN_STORAGE_KEY, JSON.stringify(chain));
123
- return client;
124
125
  } catch (e) {
125
126
  console.log(e);
126
- return smartAccountClient;
127
127
  }
128
128
  },
129
129
  [config, config.networksConfig[0].chain]
@@ -145,7 +145,8 @@ var ConnectProvider = ({
145
145
  smartAccountAddress,
146
146
  updateSmartAccountClient,
147
147
  disconnectSmartAccount,
148
- networksConfig: config.networksConfig
148
+ networksConfig: config.networksConfig,
149
+ apikey: config.apiKey
149
150
  }),
150
151
  [
151
152
  queryClient,
@@ -1532,9 +1533,7 @@ var useAddOwner = (mutationProps) => {
1532
1533
  const { smartAccountClient, queryClient } = useSmartAccount();
1533
1534
  const { mutate, mutateAsync, ...result } = useMutation(
1534
1535
  {
1535
- mutationFn: async ({
1536
- ownerToAdd
1537
- }) => {
1536
+ mutationFn: async ({ ownerToAdd }) => {
1538
1537
  if (!smartAccountClient) {
1539
1538
  throw new Error("No smart account found");
1540
1539
  }
@@ -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": "1.0.0",
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": [