@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.cjs +195 -9
- package/dist/index.d.cts +7322 -1795
- package/dist/index.d.ts +7322 -1795
- package/dist/index.js +194 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
@@ -79,10 +79,12 @@ var ConnectContext = _react.createContext.call(void 0, {
|
|
79
79
|
queryClient: void 0,
|
80
80
|
smartAccountClient: null,
|
81
81
|
smartAccountAddress: void 0,
|
82
|
-
updateSmartAccountClient: async () =>
|
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
|
}
|
@@ -2233,6 +2232,193 @@ var useEstimateGas = (mutationProps) => {
|
|
2233
2232
|
};
|
2234
2233
|
};
|
2235
2234
|
|
2235
|
+
// src/hooks/session-key/useGrantPermission.ts
|
2236
|
+
var _query = require('wagmi/query');
|
2237
|
+
|
2238
|
+
|
2239
|
+
|
2240
|
+
|
2241
|
+
function useGrantPermission(mutationProps) {
|
2242
|
+
const { smartAccountClient } = useSmartAccount();
|
2243
|
+
const { mutate, mutateAsync, ...result } = _query.useMutation.call(void 0, {
|
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(_connectsdk4337.smartSessionActions.call(void 0, )).extend(_connectsdk4337.erc7579Actions.call(void 0, ));
|
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
|
+
|
2274
|
+
|
2275
|
+
|
2276
|
+
|
2277
|
+
// src/hooks/session-key/useSessionKeySigner.ts
|
2278
|
+
|
2279
|
+
|
2280
|
+
|
2281
|
+
|
2282
|
+
|
2283
|
+
|
2284
|
+
var _accounts = require('viem/accounts');
|
2285
|
+
function useSessionKeySigner({
|
2286
|
+
sessionData,
|
2287
|
+
privateKey
|
2288
|
+
}) {
|
2289
|
+
const { smartAccountClient } = useSmartAccount();
|
2290
|
+
const query = _query.useQuery.call(void 0, {
|
2291
|
+
queryKey: ["session-key-signer", smartAccountClient],
|
2292
|
+
queryFn: async () => {
|
2293
|
+
if (!smartAccountClient) throw new Error("No smart account found");
|
2294
|
+
const safe7559Account = smartAccountClient.extend(_connectsdk4337.smartSessionActions.call(void 0, )).extend(_connectsdk4337.erc7579Actions.call(void 0, ));
|
2295
|
+
return _connectsdk4337.toSmartSessionsSigner.call(void 0, safe7559Account, {
|
2296
|
+
moduleData: {
|
2297
|
+
permissionIds: sessionData.permissionIds,
|
2298
|
+
action: sessionData.action,
|
2299
|
+
mode: "0x00",
|
2300
|
+
sessions: sessionData.sessions
|
2301
|
+
},
|
2302
|
+
signer: _accounts.privateKeyToAccount.call(void 0, privateKey)
|
2303
|
+
});
|
2304
|
+
},
|
2305
|
+
enabled: !!smartAccountClient
|
2306
|
+
});
|
2307
|
+
return query;
|
2308
|
+
}
|
2309
|
+
|
2310
|
+
// src/actions/createSessionSmartAccount.ts
|
2311
|
+
|
2312
|
+
|
2313
|
+
|
2314
|
+
|
2315
|
+
|
2316
|
+
|
2317
|
+
var createSessionSmartAccountClient = async (apiKey, smartAccountClient, sessionKeySigner) => {
|
2318
|
+
const sessionKeyAccount = await _connectsdk4337.createSafeSmartAccount.call(void 0, {
|
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 _connectsdk4337.createSmartAccountClient.call(void 0, {
|
2327
|
+
account: sessionKeyAccount,
|
2328
|
+
chain: smartAccountClient.chain,
|
2329
|
+
bundlerTransport: _viem.http.call(void 0, bundlerUrl),
|
2330
|
+
paymaster: paymasterClient,
|
2331
|
+
userOperation: {
|
2332
|
+
estimateFeesPerGas: async () => {
|
2333
|
+
return await paymasterClient.getUserOperationGasPrice();
|
2334
|
+
}
|
2335
|
+
}
|
2336
|
+
}).extend(_connectsdk4337.smartSessionActions.call(void 0, ));
|
2337
|
+
};
|
2338
|
+
|
2339
|
+
// src/hooks/session-key/useSendPermission.ts
|
2340
|
+
|
2341
|
+
function useSendPermission({
|
2342
|
+
sessionData,
|
2343
|
+
privateKey,
|
2344
|
+
mutationProps
|
2345
|
+
}) {
|
2346
|
+
const context = _react.useContext.call(void 0, 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 } = _query.useMutation.call(void 0, {
|
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
|
+
|
2391
|
+
|
2392
|
+
|
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 = _query.useQuery.call(void 0, {
|
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
|
+
}
|
2417
|
+
|
2418
|
+
|
2419
|
+
|
2420
|
+
|
2421
|
+
|
2236
2422
|
|
2237
2423
|
|
2238
2424
|
|
@@ -2259,4 +2445,4 @@ var useEstimateGas = (mutationProps) => {
|
|
2259
2445
|
|
2260
2446
|
|
2261
2447
|
|
2262
|
-
exports.ConnectProvider = ConnectProvider; exports.useAccount = useAccount; exports.useAddOwner = useAddOwner; exports.useCancelRecoveryRequest = useCancelRecoveryRequest; exports.useConnect = useConnect; exports.useCreateNewSigner = useCreateNewSigner; exports.useDisconnect = useDisconnect; exports.useEstimateGas = useEstimateGas; exports.useGenerateQRCodeUrl = useGenerateQRCodeUrl; exports.useGetEnrichedOwners = useGetEnrichedOwners; exports.useGetGasPrice = useGetGasPrice; exports.useGetOwners = useGetOwners; exports.useGetRecoveryRequest = useGetRecoveryRequest; exports.useGetTransactionCost = useGetTransactionCost; exports.useIsRecoveryActive = useIsRecoveryActive; exports.useRemoveOwner = useRemoveOwner; exports.useRetrieveAccountAddressFromPasskeyId = useRetrieveAccountAddressFromPasskeyId; exports.useRetrieveAccountAddressFromPasskeys = useRetrieveAccountAddressFromPasskeys; exports.useSendTransaction = useSendTransaction; exports.useSerializeUrlWithSignerPayload = useSerializeUrlWithSignerPayload; exports.useSetUpRecovery = useSetUpRecovery; exports.useSignMessage = useSignMessage; exports.useSwitchChain = useSwitchChain; exports.useValidateAddDevice = useValidateAddDevice; exports.useVerifyMessage = useVerifyMessage; exports.useWriteContract = useWriteContract;
|
2448
|
+
exports.ConnectProvider = ConnectProvider; exports.useAccount = useAccount; exports.useAddOwner = useAddOwner; exports.useCancelRecoveryRequest = useCancelRecoveryRequest; exports.useConnect = useConnect; exports.useCreateNewSigner = useCreateNewSigner; exports.useDisconnect = useDisconnect; exports.useEstimateGas = useEstimateGas; exports.useGenerateQRCodeUrl = useGenerateQRCodeUrl; exports.useGetEnrichedOwners = useGetEnrichedOwners; exports.useGetGasPrice = useGetGasPrice; exports.useGetOwners = useGetOwners; exports.useGetRecoveryRequest = useGetRecoveryRequest; exports.useGetTransactionCost = useGetTransactionCost; exports.useGrantPermission = useGrantPermission; exports.useIsRecoveryActive = useIsRecoveryActive; exports.useRemoveOwner = useRemoveOwner; exports.useRetrieveAccountAddressFromPasskeyId = useRetrieveAccountAddressFromPasskeyId; exports.useRetrieveAccountAddressFromPasskeys = useRetrieveAccountAddressFromPasskeys; exports.useSendPermission = useSendPermission; exports.useSendTransaction = useSendTransaction; exports.useSerializeUrlWithSignerPayload = useSerializeUrlWithSignerPayload; exports.useSessionKeyClient = useSessionKeyClient; exports.useSessionKeySigner = useSessionKeySigner; exports.useSetUpRecovery = useSetUpRecovery; exports.useSignMessage = useSignMessage; exports.useSwitchChain = useSwitchChain; exports.useValidateAddDevice = useValidateAddDevice; exports.useVerifyMessage = useVerifyMessage; exports.useWriteContract = useWriteContract;
|