@dynamic-labs/ethereum-aa 4.0.0-alpha.47 → 4.0.0-alpha.49

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/CHANGELOG.md CHANGED
@@ -1,4 +1,40 @@
1
1
 
2
+ ## [4.0.0-alpha.49](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.48...v4.0.0-alpha.49) (2024-12-27)
3
+
4
+
5
+ ### ⚠ BREAKING CHANGES
6
+
7
+ * change openFunding to openExternalFunding (#7684)
8
+
9
+ ### Features
10
+
11
+ * aa blockaid simulations ([#7583](https://github.com/dynamic-labs/dynamic-auth/issues/7583)) ([6436220](https://github.com/dynamic-labs/dynamic-auth/commit/64362204d2c96291a37bf281d62531d6f2384fdf))
12
+ * add ethereum createConnector function ([#7607](https://github.com/dynamic-labs/dynamic-auth/issues/7607)) ([f306537](https://github.com/dynamic-labs/dynamic-auth/commit/f3065372f3c5dfc8bf26173dc722576e614af5e1))
13
+ * add fundWithExternalWallet method to useFunding ([#7688](https://github.com/dynamic-labs/dynamic-auth/issues/7688)) ([d48b1d2](https://github.com/dynamic-labs/dynamic-auth/commit/d48b1d2568ba928b322a4d81b6386e775ae4aa98))
14
+ * change openFunding to openExternalFunding ([#7684](https://github.com/dynamic-labs/dynamic-auth/issues/7684)) ([8efb9cb](https://github.com/dynamic-labs/dynamic-auth/commit/8efb9cb9ca3d7e2273c14e18f7be5892e50b8e12))
15
+ * connect global wallet in ethereum ([#7619](https://github.com/dynamic-labs/dynamic-auth/issues/7619)) ([fdb7f00](https://github.com/dynamic-labs/dynamic-auth/commit/fdb7f00c33f7da3ac95ae13ac674caa64b453cae))
16
+ * create wallet groups dynamically based on wallet options ([#7662](https://github.com/dynamic-labs/dynamic-auth/issues/7662)) ([981affc](https://github.com/dynamic-labs/dynamic-auth/commit/981affce5518f6532d960fe4e879e9cf40a66ce7))
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * **ethereum:** normalize user reject error from injected wallets ([#7702](https://github.com/dynamic-labs/dynamic-auth/issues/7702)) ([ce456a8](https://github.com/dynamic-labs/dynamic-auth/commit/ce456a8592197b07857baf32bb1b38867ffb37fe))
22
+ * fetch nonce when authenticating a user that connected in connect-only mode ([#7689](https://github.com/dynamic-labs/dynamic-auth/issues/7689)) ([f048bb9](https://github.com/dynamic-labs/dynamic-auth/commit/f048bb96b6cb5ae603966b2813f900a082cd158f))
23
+ * filter out wallets for the current network when using external wallet funding ([#7694](https://github.com/dynamic-labs/dynamic-auth/issues/7694)) ([65db665](https://github.com/dynamic-labs/dynamic-auth/commit/65db6652a934561e7d07379a65d2baa8f7813d8e))
24
+ * remove toaccount from signmessage and signtypeddata for zerodev ([#7650](https://github.com/dynamic-labs/dynamic-auth/issues/7650)) ([626e849](https://github.com/dynamic-labs/dynamic-auth/commit/626e849a4af3af51d60b42dd2787edb05126744b))
25
+ * save nonce to storage ([#7698](https://github.com/dynamic-labs/dynamic-auth/issues/7698)) ([93dc65b](https://github.com/dynamic-labs/dynamic-auth/commit/93dc65b7f78040367b85420c1374f3cafbfb598b))
26
+ * **sdk-react-core:** add timeout when getting connected accounts ([#7697](https://github.com/dynamic-labs/dynamic-auth/issues/7697)) ([9a4bd7c](https://github.com/dynamic-labs/dynamic-auth/commit/9a4bd7c02795205ec98d8d71aba75b51b9bbee7c))
27
+ * update auth token from new source ([#7666](https://github.com/dynamic-labs/dynamic-auth/issues/7666)) ([61798de](https://github.com/dynamic-labs/dynamic-auth/commit/61798de26d759db9064f5f84118540346a44ab50))
28
+ * update extension update_url endpoint ([#7655](https://github.com/dynamic-labs/dynamic-auth/issues/7655)) ([46cff3a](https://github.com/dynamic-labs/dynamic-auth/commit/46cff3a80c9efee659a764df47f927ed5a117079))
29
+ * zerodev confirmation UI closes properly ([#7664](https://github.com/dynamic-labs/dynamic-auth/issues/7664)) ([a78aded](https://github.com/dynamic-labs/dynamic-auth/commit/a78adedc054d09134198d22812aa5cab7bbff548))
30
+
31
+ ## [4.0.0-alpha.48](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.47...v4.0.0-alpha.48) (2024-12-17)
32
+
33
+
34
+ ### Bug Fixes
35
+
36
+ * Temp disable refreshing blockhash for solana transactions ([#7638](https://github.com/dynamic-labs/dynamic-auth/issues/7638)) ([fd457bf](https://github.com/dynamic-labs/dynamic-auth/commit/fd457bf0579ad35ba17fc2c7aa18a9feb49d8c7b))
37
+
2
38
  ## [4.0.0-alpha.47](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.46...v4.0.0-alpha.47) (2024-12-17)
3
39
 
4
40
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.0.0-alpha.47";
6
+ var version = "4.0.0-alpha.49";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.0.0-alpha.47";
2
+ var version = "4.0.0-alpha.49";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/ethereum-aa",
3
- "version": "4.0.0-alpha.47",
3
+ "version": "4.0.0-alpha.49",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -18,18 +18,18 @@
18
18
  },
19
19
  "homepage": "https://www.dynamic.xyz/",
20
20
  "dependencies": {
21
- "@dynamic-labs/sdk-api-core": "0.0.576",
21
+ "@dynamic-labs/sdk-api-core": "0.0.578",
22
22
  "@zerodev/ecdsa-validator": "5.3.1",
23
23
  "@zerodev/multi-chain-validator": "5.3.13",
24
24
  "@zerodev/sdk": "5.3.26",
25
25
  "permissionless": "^0.1.45",
26
- "@dynamic-labs/assert-package-version": "4.0.0-alpha.47",
27
- "@dynamic-labs/ethereum-core": "4.0.0-alpha.47",
28
- "@dynamic-labs/logger": "4.0.0-alpha.47",
29
- "@dynamic-labs/types": "4.0.0-alpha.47",
30
- "@dynamic-labs/utils": "4.0.0-alpha.47",
31
- "@dynamic-labs/wallet-book": "4.0.0-alpha.47",
32
- "@dynamic-labs/wallet-connector-core": "4.0.0-alpha.47"
26
+ "@dynamic-labs/assert-package-version": "4.0.0-alpha.49",
27
+ "@dynamic-labs/ethereum-core": "4.0.0-alpha.49",
28
+ "@dynamic-labs/logger": "4.0.0-alpha.49",
29
+ "@dynamic-labs/types": "4.0.0-alpha.49",
30
+ "@dynamic-labs/utils": "4.0.0-alpha.49",
31
+ "@dynamic-labs/wallet-book": "4.0.0-alpha.49",
32
+ "@dynamic-labs/wallet-connector-core": "4.0.0-alpha.49"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "viem": "^2.7.12"
@@ -294,7 +294,6 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
294
294
  onPersonalSign: (_a) => _tslib.__awaiter(this, [_a], void 0, function* ({ message }) {
295
295
  this._walletUiUtils.disabledConfirmationOnce();
296
296
  return provider.signMessage({
297
- account: accounts.toAccount(provider.account.address),
298
297
  message,
299
298
  });
300
299
  }),
@@ -325,7 +324,6 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
325
324
  this._walletUiUtils.disabledConfirmationOnce();
326
325
  const signTypedData = JSON.parse(message);
327
326
  return provider.signTypedData({
328
- account: accounts.toAccount(provider.account.address),
329
327
  domain: signTypedData.domain,
330
328
  message: signTypedData.message,
331
329
  primaryType: signTypedData.primaryType,
@@ -366,38 +364,110 @@ class ZeroDevConnector extends walletConnectorCore.WalletConnectorBase {
366
364
  return this.getWalletClient();
367
365
  });
368
366
  }
369
- canSponsorTransactionGas(transaction) {
367
+ formatUserOperation(params) {
370
368
  return _tslib.__awaiter(this, void 0, void 0, function* () {
369
+ var _a, _b, _c, _d, _e;
370
+ const entryPoint = (_a = this.getAccountAbstractionProvider()) === null || _a === void 0 ? void 0 : _a.account.entryPoint;
371
+ const isV6 = (entryPoint === null || entryPoint === void 0 ? void 0 : entryPoint.toLowerCase()) === utils$1.ENTRYPOINT_ADDRESS_V06.toLowerCase();
372
+ if (isV6) {
373
+ return {
374
+ callData: params.callData,
375
+ callGasLimit: viem.toHex(params.callGasLimit),
376
+ initCode: (_c = (yield ((_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account.getInitCode()))) !== null && _c !== void 0 ? _c : '0x',
377
+ maxFeePerGas: viem.toHex(params.maxFeePerGas),
378
+ maxPriorityFeePerGas: viem.toHex(params.maxPriorityFeePerGas),
379
+ nonce: viem.toHex(params.nonce),
380
+ paymasterAndData: params.paymasterAndData.toLowerCase(),
381
+ preVerificationGas: viem.toHex(params.preVerificationGas),
382
+ sender: params.sender,
383
+ signature: '0x',
384
+ verificationGasLimit: viem.toHex(params.verificationGasLimit),
385
+ };
386
+ }
387
+ const accountGasLimits = '0x' +
388
+ '000000000000000000000000000' + // 27 zeros
389
+ viem.toHex(params.verificationGasLimit).slice(2) +
390
+ '000000000000000000000000000' + // 27 zeros
391
+ viem.toHex(params.callGasLimit).slice(2);
392
+ const preVerificationGas = viem.toHex(params.preVerificationGas);
393
+ const gasFees = '0x' +
394
+ '00000000000000000000000000' + // 26 zeros
395
+ viem.toHex(params.maxPriorityFeePerGas).slice(2).padStart(6, '0') +
396
+ '0000000000000000000000' + // 22 zeros
397
+ viem.toHex(params.maxFeePerGas).slice(2).padStart(10, '0');
398
+ const paymasterAndData = params.paymaster
399
+ ? '0x' +
400
+ params.paymaster.slice(2).toLowerCase() +
401
+ viem.toHex(params.paymasterVerificationGasLimit).slice(2).padStart(32, '0') + // Make sure it's 32 chars
402
+ viem.toHex(params.paymasterPostOpGasLimit).slice(2).padStart(32, '0') + // Make sure it's 32 chars
403
+ params.paymasterData.slice(2) // Include full paymaster data
404
+ : '0x';
405
+ const initCode = (_e = (yield ((_d = this.kernelClient) === null || _d === void 0 ? void 0 : _d.account.getInitCode()))) !== null && _e !== void 0 ? _e : '0x';
406
+ return {
407
+ accountGasLimits: accountGasLimits,
408
+ callData: params.callData,
409
+ gasFees: gasFees,
410
+ initCode,
411
+ nonce: viem.toHex(params.nonce),
412
+ paymasterAndData: paymasterAndData.toLowerCase(),
413
+ preVerificationGas: preVerificationGas,
414
+ sender: params.sender,
415
+ signature: '0x',
416
+ };
417
+ });
418
+ }
419
+ getCurrentUserOperation(transaction) {
420
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
421
+ var _a, _b, _c;
371
422
  try {
372
423
  const { kernelClientWithSponsorship } = this;
373
424
  if (!kernelClientWithSponsorship) {
374
425
  throw new utils.DynamicError('No kernel client with sponsorship found');
375
426
  }
427
+ const value = BigInt((_a = transaction.value) !== null && _a !== void 0 ? _a : 0);
376
428
  const userOperation = {
377
429
  callData: yield kernelClientWithSponsorship.account.encodeCallData({
378
430
  data: transaction.data ? transaction.data : '0x',
379
431
  to: transaction.to,
380
- /**
381
- * if value is undefined, it will be set to 0x0 so the sponsorship
382
- * check does not fail
383
- */
384
- value: transaction.value && viem.isHex(transaction.value)
385
- ? viem.fromHex(transaction.value, 'bigint')
386
- : viem.fromHex('0x0', 'bigint'),
432
+ value,
387
433
  }),
388
434
  };
389
- const result = yield kernelClientWithSponsorship.prepareUserOperationRequest({
390
- account: kernelClientWithSponsorship.account,
391
- userOperation,
392
- });
393
- if (!result)
394
- return false;
395
- return result.paymasterAndData !== '0x';
435
+ let sponsorResult;
436
+ let unsponsoredResult;
437
+ try {
438
+ sponsorResult =
439
+ yield kernelClientWithSponsorship.prepareUserOperationRequest({
440
+ account: kernelClientWithSponsorship.account,
441
+ userOperation,
442
+ });
443
+ }
444
+ catch (err) {
445
+ logger.logger.debug('[ZeroDevConnector] Sponsored UserOp Attempt Failed:', err);
446
+ unsponsoredResult =
447
+ yield ((_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.prepareUserOperationRequest({
448
+ account: (_c = this.kernelClient) === null || _c === void 0 ? void 0 : _c.account,
449
+ userOperation,
450
+ }));
451
+ }
452
+ if ((sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) === '0x')
453
+ return { sponsored: false, userOperation: sponsorResult };
454
+ return sponsorResult
455
+ ? { sponsored: true, userOperation: sponsorResult }
456
+ : { sponsored: false, userOperation: unsponsoredResult };
396
457
  }
397
458
  catch (err) {
398
- logger.logger.debug(err);
459
+ logger.logger.debug('[ZeroDevConnector] Error in getCurrentUserOperation:', err);
460
+ return { sponsored: false, userOperation: undefined };
461
+ }
462
+ });
463
+ }
464
+ canSponsorTransactionGas(transaction) {
465
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
466
+ const { sponsored } = yield this.getCurrentUserOperation(transaction);
467
+ if (!sponsored) {
399
468
  return false;
400
469
  }
470
+ return sponsored;
401
471
  });
402
472
  }
403
473
  disableGasSponsorshipOnce() {
@@ -7755,6 +7755,39 @@ export declare class ZeroDevConnector extends WalletConnectorBase<typeof Ethereu
7755
7755
  uid?: undefined;
7756
7756
  } & import("viem").ExactPartial<Pick<import("viem").PublicActions<Transport, ViemChain, Account | 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<import("viem").WalletActions<ViemChain, Account | undefined>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<Transport, ViemChain, Account | undefined, import("viem").WalletRpcSchema, import("viem").WalletActions<ViemChain, Account | undefined>>) => client) => import("viem").Client<Transport, ViemChain, Account | undefined, import("viem").WalletRpcSchema, { [K_1 in keyof client]: client[K_1]; } & import("viem").WalletActions<ViemChain, Account | undefined>>;
7757
7757
  } | undefined>;
7758
+ formatUserOperation(params: any): Promise<{
7759
+ callData: any;
7760
+ callGasLimit: `0x${string}`;
7761
+ initCode: `0x${string}`;
7762
+ maxFeePerGas: `0x${string}`;
7763
+ maxPriorityFeePerGas: `0x${string}`;
7764
+ nonce: `0x${string}`;
7765
+ paymasterAndData: any;
7766
+ preVerificationGas: `0x${string}`;
7767
+ sender: any;
7768
+ signature: string;
7769
+ verificationGasLimit: `0x${string}`;
7770
+ accountGasLimits?: undefined;
7771
+ gasFees?: undefined;
7772
+ } | {
7773
+ accountGasLimits: string;
7774
+ callData: any;
7775
+ gasFees: string;
7776
+ initCode: `0x${string}`;
7777
+ nonce: `0x${string}`;
7778
+ paymasterAndData: string;
7779
+ preVerificationGas: `0x${string}`;
7780
+ sender: any;
7781
+ signature: string;
7782
+ callGasLimit?: undefined;
7783
+ maxFeePerGas?: undefined;
7784
+ maxPriorityFeePerGas?: undefined;
7785
+ verificationGasLimit?: undefined;
7786
+ }>;
7787
+ getCurrentUserOperation(transaction: IUITransaction): Promise<{
7788
+ userOperation: any;
7789
+ sponsored: boolean;
7790
+ }>;
7758
7791
  canSponsorTransactionGas(transaction: IUITransaction): Promise<boolean>;
7759
7792
  disableGasSponsorshipOnce(): void;
7760
7793
  getBalance(address: string): Promise<string | undefined>;
@@ -1,8 +1,8 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../_virtual/_tslib.js';
3
- import { publicActions, custom, createWalletClient, isHex, fromHex, formatEther } from 'viem';
3
+ import { publicActions, custom, createWalletClient, toHex, formatEther } from 'viem';
4
4
  import { toAccount } from 'viem/accounts';
5
- import { walletClientToSmartAccountSigner } from 'permissionless/utils';
5
+ import { walletClientToSmartAccountSigner, ENTRYPOINT_ADDRESS_V06 } from 'permissionless/utils';
6
6
  import { EthereumWallet, isEthWalletConnector, chainsMap, confirmationTransport, unFormatTransaction, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
7
7
  import { WalletConnectorBase, eventListenerHandlers } from '@dynamic-labs/wallet-connector-core';
8
8
  import { parseEvmNetworks, StorageService, DeferredPromise, parseChainId, DynamicError, wrapMethodWithCallback, TransactionGasCannotBeSponsoredError, InsufficientFundsError } from '@dynamic-labs/utils';
@@ -290,7 +290,6 @@ class ZeroDevConnector extends WalletConnectorBase {
290
290
  onPersonalSign: (_a) => __awaiter(this, [_a], void 0, function* ({ message }) {
291
291
  this._walletUiUtils.disabledConfirmationOnce();
292
292
  return provider.signMessage({
293
- account: toAccount(provider.account.address),
294
293
  message,
295
294
  });
296
295
  }),
@@ -321,7 +320,6 @@ class ZeroDevConnector extends WalletConnectorBase {
321
320
  this._walletUiUtils.disabledConfirmationOnce();
322
321
  const signTypedData = JSON.parse(message);
323
322
  return provider.signTypedData({
324
- account: toAccount(provider.account.address),
325
323
  domain: signTypedData.domain,
326
324
  message: signTypedData.message,
327
325
  primaryType: signTypedData.primaryType,
@@ -362,38 +360,110 @@ class ZeroDevConnector extends WalletConnectorBase {
362
360
  return this.getWalletClient();
363
361
  });
364
362
  }
365
- canSponsorTransactionGas(transaction) {
363
+ formatUserOperation(params) {
366
364
  return __awaiter(this, void 0, void 0, function* () {
365
+ var _a, _b, _c, _d, _e;
366
+ const entryPoint = (_a = this.getAccountAbstractionProvider()) === null || _a === void 0 ? void 0 : _a.account.entryPoint;
367
+ const isV6 = (entryPoint === null || entryPoint === void 0 ? void 0 : entryPoint.toLowerCase()) === ENTRYPOINT_ADDRESS_V06.toLowerCase();
368
+ if (isV6) {
369
+ return {
370
+ callData: params.callData,
371
+ callGasLimit: toHex(params.callGasLimit),
372
+ initCode: (_c = (yield ((_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.account.getInitCode()))) !== null && _c !== void 0 ? _c : '0x',
373
+ maxFeePerGas: toHex(params.maxFeePerGas),
374
+ maxPriorityFeePerGas: toHex(params.maxPriorityFeePerGas),
375
+ nonce: toHex(params.nonce),
376
+ paymasterAndData: params.paymasterAndData.toLowerCase(),
377
+ preVerificationGas: toHex(params.preVerificationGas),
378
+ sender: params.sender,
379
+ signature: '0x',
380
+ verificationGasLimit: toHex(params.verificationGasLimit),
381
+ };
382
+ }
383
+ const accountGasLimits = '0x' +
384
+ '000000000000000000000000000' + // 27 zeros
385
+ toHex(params.verificationGasLimit).slice(2) +
386
+ '000000000000000000000000000' + // 27 zeros
387
+ toHex(params.callGasLimit).slice(2);
388
+ const preVerificationGas = toHex(params.preVerificationGas);
389
+ const gasFees = '0x' +
390
+ '00000000000000000000000000' + // 26 zeros
391
+ toHex(params.maxPriorityFeePerGas).slice(2).padStart(6, '0') +
392
+ '0000000000000000000000' + // 22 zeros
393
+ toHex(params.maxFeePerGas).slice(2).padStart(10, '0');
394
+ const paymasterAndData = params.paymaster
395
+ ? '0x' +
396
+ params.paymaster.slice(2).toLowerCase() +
397
+ toHex(params.paymasterVerificationGasLimit).slice(2).padStart(32, '0') + // Make sure it's 32 chars
398
+ toHex(params.paymasterPostOpGasLimit).slice(2).padStart(32, '0') + // Make sure it's 32 chars
399
+ params.paymasterData.slice(2) // Include full paymaster data
400
+ : '0x';
401
+ const initCode = (_e = (yield ((_d = this.kernelClient) === null || _d === void 0 ? void 0 : _d.account.getInitCode()))) !== null && _e !== void 0 ? _e : '0x';
402
+ return {
403
+ accountGasLimits: accountGasLimits,
404
+ callData: params.callData,
405
+ gasFees: gasFees,
406
+ initCode,
407
+ nonce: toHex(params.nonce),
408
+ paymasterAndData: paymasterAndData.toLowerCase(),
409
+ preVerificationGas: preVerificationGas,
410
+ sender: params.sender,
411
+ signature: '0x',
412
+ };
413
+ });
414
+ }
415
+ getCurrentUserOperation(transaction) {
416
+ return __awaiter(this, void 0, void 0, function* () {
417
+ var _a, _b, _c;
367
418
  try {
368
419
  const { kernelClientWithSponsorship } = this;
369
420
  if (!kernelClientWithSponsorship) {
370
421
  throw new DynamicError('No kernel client with sponsorship found');
371
422
  }
423
+ const value = BigInt((_a = transaction.value) !== null && _a !== void 0 ? _a : 0);
372
424
  const userOperation = {
373
425
  callData: yield kernelClientWithSponsorship.account.encodeCallData({
374
426
  data: transaction.data ? transaction.data : '0x',
375
427
  to: transaction.to,
376
- /**
377
- * if value is undefined, it will be set to 0x0 so the sponsorship
378
- * check does not fail
379
- */
380
- value: transaction.value && isHex(transaction.value)
381
- ? fromHex(transaction.value, 'bigint')
382
- : fromHex('0x0', 'bigint'),
428
+ value,
383
429
  }),
384
430
  };
385
- const result = yield kernelClientWithSponsorship.prepareUserOperationRequest({
386
- account: kernelClientWithSponsorship.account,
387
- userOperation,
388
- });
389
- if (!result)
390
- return false;
391
- return result.paymasterAndData !== '0x';
431
+ let sponsorResult;
432
+ let unsponsoredResult;
433
+ try {
434
+ sponsorResult =
435
+ yield kernelClientWithSponsorship.prepareUserOperationRequest({
436
+ account: kernelClientWithSponsorship.account,
437
+ userOperation,
438
+ });
439
+ }
440
+ catch (err) {
441
+ logger.debug('[ZeroDevConnector] Sponsored UserOp Attempt Failed:', err);
442
+ unsponsoredResult =
443
+ yield ((_b = this.kernelClient) === null || _b === void 0 ? void 0 : _b.prepareUserOperationRequest({
444
+ account: (_c = this.kernelClient) === null || _c === void 0 ? void 0 : _c.account,
445
+ userOperation,
446
+ }));
447
+ }
448
+ if ((sponsorResult === null || sponsorResult === void 0 ? void 0 : sponsorResult.paymasterAndData) === '0x')
449
+ return { sponsored: false, userOperation: sponsorResult };
450
+ return sponsorResult
451
+ ? { sponsored: true, userOperation: sponsorResult }
452
+ : { sponsored: false, userOperation: unsponsoredResult };
392
453
  }
393
454
  catch (err) {
394
- logger.debug(err);
455
+ logger.debug('[ZeroDevConnector] Error in getCurrentUserOperation:', err);
456
+ return { sponsored: false, userOperation: undefined };
457
+ }
458
+ });
459
+ }
460
+ canSponsorTransactionGas(transaction) {
461
+ return __awaiter(this, void 0, void 0, function* () {
462
+ const { sponsored } = yield this.getCurrentUserOperation(transaction);
463
+ if (!sponsored) {
395
464
  return false;
396
465
  }
466
+ return sponsored;
397
467
  });
398
468
  }
399
469
  disableGasSponsorshipOnce() {