@gasfree-kit/evm-4337 0.3.0 → 0.3.2

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @gasfree-kit/evm-4337
2
2
 
3
- ERC-4337 USDT transfers for EVM chains using WDK-backed Safe smart accounts.
3
+ ERC-4337 USDT transfers for EVM chains using Safe smart accounts.
4
4
 
5
5
  This package gives you:
6
6
 
@@ -23,7 +23,7 @@ This package gives you:
23
23
 
24
24
  v
25
25
  ┌──────────────────────┐ ┌──────────────────────┐
26
- WDK wallet manager │──────>│ Safe smart account │
26
+ Wallet manager │──────>│ Safe smart account │
27
27
  └──────────────────────┘ └──────────┬───────────┘
28
28
 
29
29
  v
@@ -72,17 +72,7 @@ This package depends on [`@gasfree-kit/core`](../core/README.md) for:
72
72
  npm install @gasfree-kit/evm-4337 @gasfree-kit/core
73
73
  ```
74
74
 
75
- Required peer dependency:
76
-
77
- ```bash
78
- npm install @tetherto/wdk-wallet-evm-erc-4337
79
- ```
80
-
81
- Optional passkey peer dependencies:
82
-
83
- ```bash
84
- npm install @safe-global/protocol-kit @safe-global/relay-kit
85
- ```
75
+ After installing, your package manager will prompt you to install the required peer dependencies listed in `package.json`. Some peer dependencies are marked optional and only needed if you enable passkey linking.
86
76
 
87
77
  ## Choose Your Gas Mode
88
78
 
@@ -291,7 +281,7 @@ await unlinkPasskeyFromSafe(seedPhrase, sponsoredConfig, passkey.credential);
291
281
 
292
282
  | Export | What it does |
293
283
  | ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------- |
294
- | `setupErc4337Wallet` | Creates a WDK-backed ERC-4337 wallet and resolves the Safe address |
284
+ | `setupErc4337Wallet` | Creates an ERC-4337 wallet from a seed phrase and resolves the Safe address |
295
285
  | `EvmTransfer` | Estimates, checks balance, sends single transfers, and sends batch transfers |
296
286
  | `PasskeyTransfer` | Sends passkey-signed transfers after a passkey has been linked |
297
287
  | `linkPasskeyToSafe` | Registers a passkey and adds its signer to the Safe owner set |
package/dist/index.d.mts CHANGED
@@ -32,7 +32,6 @@ type EVM4337ClientConfig = {
32
32
  };
33
33
  /**
34
34
  * Build the full ERC-4337 network config from user-provided client config.
35
- * Matches the structure expected by @tetherto/wdk-wallet-evm-erc-4337.
36
35
  */
37
36
  declare function getErc4337ConfigForChain(config: EVM4337ClientConfig): EvmErc4337NetworkConfig;
38
37
  /** Conservative gas fee fallback estimates per chain (USDT 6 decimals). */
@@ -89,12 +88,14 @@ declare const SAFE_WEBAUTHN_SIGNER_FACTORY: Record<string, string>;
89
88
  declare const FCL_P256_VERIFIER: Record<string, string>;
90
89
 
91
90
  /**
92
- * Set up an ERC-4337 wallet via WDK.
91
+ * Set up an ERC-4337 wallet.
93
92
  *
94
- * Dynamically imports @tetherto/wdk-wallet-evm-erc-4337 and builds the
95
- * correct discriminated-union config:
96
- * - Sponsored mode → EvmErc4337WalletSponsorshipPolicyConfig
97
- * - Non-sponsored → EvmErc4337WalletPaymasterTokenConfig
93
+ * Builds the correct discriminated-union config:
94
+ * - Sponsored mode → sponsorship-policy config
95
+ * - Non-sponsored → paymaster-token config
96
+ *
97
+ * Derives the EOA at the BIP-44 path m/44'/60'/0'/0/{accountIndex} so the
98
+ * resulting Safe address stays stable across underlying-library upgrades.
98
99
  *
99
100
  * Optionally links a passkey to the Safe account when passkeyOptions is provided.
100
101
  */
@@ -193,6 +194,11 @@ declare function waitForUserOpConfirmation(userOpHash: string, bundlerUrl: strin
193
194
  */
194
195
  declare function handleTransferError(error: unknown, chain: string): Error;
195
196
 
197
+ declare function jsonRpcCall(rpcUrl: string, request: {
198
+ method: string;
199
+ params: unknown[];
200
+ }): Promise<string>;
201
+
196
202
  /**
197
203
  * Register a new passkey via WebAuthn and link it to an existing Safe account.
198
204
  *
@@ -290,4 +296,4 @@ interface CredentialStore {
290
296
  */
291
297
  declare function createCredentialStore(): CredentialStore;
292
298
 
293
- export { type CredentialStore, type EVM4337ClientConfig, type EvmErc4337NetworkConfig, EvmTransfer, FCL_P256_VERIFIER, GAS_FEE_ESTIMATES, GAS_FEE_FALLBACKS, type PasskeyConfig, type PasskeyCredential, type PasskeyLinkResult, type PasskeyOptions, type PasskeyStorageMode, PasskeyTransfer, SAFE_WEBAUTHN_SIGNER_FACTORY, createCredentialStore, encodeErc20Transfer, feeToUsdt, formatTokenBalance, getErc4337ConfigForChain, handleTransferError, isPasskeyLinked, linkPasskeyToSafe, setupErc4337Wallet, toUsdtBaseUnitsEvm, unlinkPasskeyFromSafe, waitForUserOpConfirmation };
299
+ export { type CredentialStore, type EVM4337ClientConfig, type EvmErc4337NetworkConfig, EvmTransfer, FCL_P256_VERIFIER, GAS_FEE_ESTIMATES, GAS_FEE_FALLBACKS, type PasskeyConfig, type PasskeyCredential, type PasskeyLinkResult, type PasskeyOptions, type PasskeyStorageMode, PasskeyTransfer, SAFE_WEBAUTHN_SIGNER_FACTORY, createCredentialStore, encodeErc20Transfer, feeToUsdt, formatTokenBalance, getErc4337ConfigForChain, handleTransferError, isPasskeyLinked, jsonRpcCall, linkPasskeyToSafe, setupErc4337Wallet, toUsdtBaseUnitsEvm, unlinkPasskeyFromSafe, waitForUserOpConfirmation };
package/dist/index.d.ts CHANGED
@@ -32,7 +32,6 @@ type EVM4337ClientConfig = {
32
32
  };
33
33
  /**
34
34
  * Build the full ERC-4337 network config from user-provided client config.
35
- * Matches the structure expected by @tetherto/wdk-wallet-evm-erc-4337.
36
35
  */
37
36
  declare function getErc4337ConfigForChain(config: EVM4337ClientConfig): EvmErc4337NetworkConfig;
38
37
  /** Conservative gas fee fallback estimates per chain (USDT 6 decimals). */
@@ -89,12 +88,14 @@ declare const SAFE_WEBAUTHN_SIGNER_FACTORY: Record<string, string>;
89
88
  declare const FCL_P256_VERIFIER: Record<string, string>;
90
89
 
91
90
  /**
92
- * Set up an ERC-4337 wallet via WDK.
91
+ * Set up an ERC-4337 wallet.
93
92
  *
94
- * Dynamically imports @tetherto/wdk-wallet-evm-erc-4337 and builds the
95
- * correct discriminated-union config:
96
- * - Sponsored mode → EvmErc4337WalletSponsorshipPolicyConfig
97
- * - Non-sponsored → EvmErc4337WalletPaymasterTokenConfig
93
+ * Builds the correct discriminated-union config:
94
+ * - Sponsored mode → sponsorship-policy config
95
+ * - Non-sponsored → paymaster-token config
96
+ *
97
+ * Derives the EOA at the BIP-44 path m/44'/60'/0'/0/{accountIndex} so the
98
+ * resulting Safe address stays stable across underlying-library upgrades.
98
99
  *
99
100
  * Optionally links a passkey to the Safe account when passkeyOptions is provided.
100
101
  */
@@ -193,6 +194,11 @@ declare function waitForUserOpConfirmation(userOpHash: string, bundlerUrl: strin
193
194
  */
194
195
  declare function handleTransferError(error: unknown, chain: string): Error;
195
196
 
197
+ declare function jsonRpcCall(rpcUrl: string, request: {
198
+ method: string;
199
+ params: unknown[];
200
+ }): Promise<string>;
201
+
196
202
  /**
197
203
  * Register a new passkey via WebAuthn and link it to an existing Safe account.
198
204
  *
@@ -290,4 +296,4 @@ interface CredentialStore {
290
296
  */
291
297
  declare function createCredentialStore(): CredentialStore;
292
298
 
293
- export { type CredentialStore, type EVM4337ClientConfig, type EvmErc4337NetworkConfig, EvmTransfer, FCL_P256_VERIFIER, GAS_FEE_ESTIMATES, GAS_FEE_FALLBACKS, type PasskeyConfig, type PasskeyCredential, type PasskeyLinkResult, type PasskeyOptions, type PasskeyStorageMode, PasskeyTransfer, SAFE_WEBAUTHN_SIGNER_FACTORY, createCredentialStore, encodeErc20Transfer, feeToUsdt, formatTokenBalance, getErc4337ConfigForChain, handleTransferError, isPasskeyLinked, linkPasskeyToSafe, setupErc4337Wallet, toUsdtBaseUnitsEvm, unlinkPasskeyFromSafe, waitForUserOpConfirmation };
299
+ export { type CredentialStore, type EVM4337ClientConfig, type EvmErc4337NetworkConfig, EvmTransfer, FCL_P256_VERIFIER, GAS_FEE_ESTIMATES, GAS_FEE_FALLBACKS, type PasskeyConfig, type PasskeyCredential, type PasskeyLinkResult, type PasskeyOptions, type PasskeyStorageMode, PasskeyTransfer, SAFE_WEBAUTHN_SIGNER_FACTORY, createCredentialStore, encodeErc20Transfer, feeToUsdt, formatTokenBalance, getErc4337ConfigForChain, handleTransferError, isPasskeyLinked, jsonRpcCall, linkPasskeyToSafe, setupErc4337Wallet, toUsdtBaseUnitsEvm, unlinkPasskeyFromSafe, waitForUserOpConfirmation };
package/dist/index.js CHANGED
@@ -43,6 +43,7 @@ __export(index_exports, {
43
43
  getErc4337ConfigForChain: () => getErc4337ConfigForChain,
44
44
  handleTransferError: () => handleTransferError,
45
45
  isPasskeyLinked: () => isPasskeyLinked,
46
+ jsonRpcCall: () => jsonRpcCall,
46
47
  linkPasskeyToSafe: () => linkPasskeyToSafe,
47
48
  setupErc4337Wallet: () => setupErc4337Wallet,
48
49
  toUsdtBaseUnitsEvm: () => toUsdtBaseUnitsEvm,
@@ -1178,6 +1179,7 @@ var PasskeyTransfer = class {
1178
1179
  getErc4337ConfigForChain,
1179
1180
  handleTransferError,
1180
1181
  isPasskeyLinked,
1182
+ jsonRpcCall,
1181
1183
  linkPasskeyToSafe,
1182
1184
  setupErc4337Wallet,
1183
1185
  toUsdtBaseUnitsEvm,
package/dist/index.mjs CHANGED
@@ -1128,6 +1128,7 @@ export {
1128
1128
  getErc4337ConfigForChain,
1129
1129
  handleTransferError,
1130
1130
  isPasskeyLinked,
1131
+ jsonRpcCall,
1131
1132
  linkPasskeyToSafe,
1132
1133
  setupErc4337Wallet,
1133
1134
  toUsdtBaseUnitsEvm,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gasfree-kit/evm-4337",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "ERC-4337 gasless transactions for EVM chains — powered by WDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -14,14 +14,12 @@
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
- "patches",
18
- "scripts",
19
17
  "README.md"
20
18
  ],
21
19
  "dependencies": {
22
20
  "@noble/hashes": "^2.0.1",
23
21
  "abstractionkit": "^0.2.30",
24
- "@gasfree-kit/core": "0.2.0"
22
+ "@gasfree-kit/core": "0.2.1"
25
23
  },
26
24
  "peerDependencies": {
27
25
  "@safe-global/protocol-kit": "^5.0.0",
@@ -36,12 +34,27 @@
36
34
  "optional": true
37
35
  }
38
36
  },
37
+ "keywords": [
38
+ "gasless",
39
+ "gas-free",
40
+ "erc-4337",
41
+ "account-abstraction",
42
+ "paymaster",
43
+ "bundler",
44
+ "user-operation",
45
+ "ethereum",
46
+ "evm",
47
+ "web3",
48
+ "sdk",
49
+ "meta-transactions",
50
+ "safe",
51
+ "smart-account"
52
+ ],
39
53
  "license": "MIT",
40
54
  "publishConfig": {
41
55
  "access": "public"
42
56
  },
43
57
  "scripts": {
44
- "postinstall": "node scripts/postinstall.js",
45
58
  "build": "tsup",
46
59
  "dev": "tsup --watch",
47
60
  "test": "vitest run",
@@ -1,68 +0,0 @@
1
- diff --git a/dist/cjs/src/index.cjs b/dist/cjs/src/index.cjs
2
- --- a/dist/cjs/src/index.cjs
3
- +++ b/dist/cjs/src/index.cjs
4
- @@ -1946,6 +1946,9 @@ var GenericFeeEstimator = class {
5
- const context = "paymasterTokenAddress" in paymasterOptions ? {
6
- token: paymasterOptions.paymasterTokenAddress
7
- } : paymasterOptions.paymasterContext ?? {};
8
- + if (paymasterOptions.sponsorshipPolicyId) {
9
- + context.sponsorshipPolicyId = paymasterOptions.sponsorshipPolicyId;
10
- + }
11
- const [feeData, paymasterStubData] = await Promise.all([
12
- this.#getUserOperationGasPrices(this.rpcUrl),
13
- paymasterClient.request({
14
- @@ -2017,7 +2020,8 @@ var GenericFeeEstimator = class {
15
- const sponsoredData = await paymasterClient.request({
16
- method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
17
- params
18
- });
19
- - return sponsoredData;
20
- + sponsoredData.callGasLimit = userOperation.callGasLimit.toString();
21
- + return sponsoredData;
22
- }
23
- const erc20PaymasterData = await paymasterClient.request({
24
- method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
25
- @@ -2032,7 +2036,8 @@ var GenericFeeEstimator = class {
26
- const threshold = await protocolKit.getThreshold();
27
- erc20PaymasterData.verificationGasLimit = (BigInt(erc20PaymasterData.verificationGasLimit) + BigInt(threshold) * this.defaultVerificationGasLimitOverhead).toString();
28
- }
29
- - return erc20PaymasterData;
30
- + erc20PaymasterData.callGasLimit = userOperation.callGasLimit.toString();
31
- + return erc20PaymasterData;
32
- }
33
- async #getUserOperationGasPrices(rpcUrl) {
34
- const client = (0, import_viem11.createPublicClient)({
35
- diff --git a/dist/esm/src/index.mjs b/dist/esm/src/index.mjs
36
- --- a/dist/esm/src/index.mjs
37
- +++ b/dist/esm/src/index.mjs
38
- @@ -1923,6 +1923,9 @@ var GenericFeeEstimator = class {
39
- const context = "paymasterTokenAddress" in paymasterOptions ? {
40
- token: paymasterOptions.paymasterTokenAddress
41
- } : paymasterOptions.paymasterContext ?? {};
42
- + if (paymasterOptions.sponsorshipPolicyId) {
43
- + context.sponsorshipPolicyId = paymasterOptions.sponsorshipPolicyId;
44
- + }
45
- const [feeData, paymasterStubData] = await Promise.all([
46
- this.#getUserOperationGasPrices(this.rpcUrl),
47
- paymasterClient.request({
48
- @@ -1994,7 +1997,8 @@ var GenericFeeEstimator = class {
49
- const sponsoredData = await paymasterClient.request({
50
- method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
51
- params
52
- });
53
- - return sponsoredData;
54
- + sponsoredData.callGasLimit = userOperation.callGasLimit.toString();
55
- + return sponsoredData;
56
- }
57
- const erc20PaymasterData = await paymasterClient.request({
58
- method: "pm_getPaymasterData" /* GET_PAYMASTER_DATA */,
59
- @@ -2009,7 +2013,8 @@ var GenericFeeEstimator = class {
60
- const threshold = await protocolKit.getThreshold();
61
- erc20PaymasterData.verificationGasLimit = (BigInt(erc20PaymasterData.verificationGasLimit) + BigInt(threshold) * this.defaultVerificationGasLimitOverhead).toString();
62
- }
63
- - return erc20PaymasterData;
64
- + erc20PaymasterData.callGasLimit = userOperation.callGasLimit.toString();
65
- + return erc20PaymasterData;
66
- }
67
- async #getUserOperationGasPrices(rpcUrl) {
68
- const client = createPublicClient2({
@@ -1,101 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Postinstall script for @gasfree-kit/evm-4337.
5
- *
6
- * Applies a critical patch to @tetherto/wdk-safe-relay-kit that fixes:
7
- * 1. sponsorshipPolicyId not being passed to Candide paymaster context
8
- * 2. callGasLimit being dropped by paymaster response (both sponsored & ERC-20)
9
- *
10
- * Without this patch, gas estimation fails on Candide-sponsored transactions.
11
- *
12
- * Works with npm, pnpm, and yarn.
13
- * pnpm users can also use patchedDependencies in package.json instead.
14
- */
15
-
16
- const { spawnSync } = require('child_process');
17
- const fs = require('fs');
18
- const path = require('path');
19
- const packageRoot = path.resolve(__dirname, '..');
20
-
21
- function findProjectRoot(startDir) {
22
- let current = startDir;
23
- while (true) {
24
- const parent = path.dirname(current);
25
- if (parent === current) {
26
- return startDir;
27
- }
28
- if (fs.existsSync(path.join(parent, 'package.json'))) {
29
- return parent;
30
- }
31
- current = parent;
32
- }
33
- }
34
-
35
- function runOrThrow(command, args, options) {
36
- const result = spawnSync(command, args, {
37
- stdio: 'pipe',
38
- windowsHide: true,
39
- ...options,
40
- });
41
-
42
- if (result.error) {
43
- throw result.error;
44
- }
45
-
46
- if (result.status !== 0) {
47
- const stderr = result.stderr ? result.stderr.toString().trim() : '';
48
- throw new Error(stderr || `${command} exited with code ${result.status}`);
49
- }
50
- }
51
-
52
- const patchFile = path.join(
53
- __dirname,
54
- '..',
55
- 'patches',
56
- '@tetherto__wdk-safe-relay-kit@4.1.5.patch',
57
- );
58
-
59
- if (!fs.existsSync(patchFile)) {
60
- // Patch file not found — skip (might be in a CI environment or already applied)
61
- process.exit(0);
62
- }
63
-
64
- // Find the target package
65
- const projectRoot = findProjectRoot(packageRoot);
66
- const possiblePaths = [
67
- path.join(projectRoot, 'node_modules', '@tetherto', 'wdk-safe-relay-kit'),
68
- path.join(packageRoot, 'node_modules', '@tetherto', 'wdk-safe-relay-kit'),
69
- ];
70
-
71
- const targetDir = possiblePaths.find((p) => fs.existsSync(p));
72
-
73
- if (!targetDir) {
74
- // @tetherto/wdk-safe-relay-kit not installed yet — skip
75
- // The user's package manager will install peer deps and this runs again
76
- process.exit(0);
77
- }
78
-
79
- // Check if patch is already applied by looking for our marker
80
- const cjsFile = path.join(targetDir, 'dist', 'cjs', 'src', 'index.cjs');
81
- if (fs.existsSync(cjsFile)) {
82
- const content = fs.readFileSync(cjsFile, 'utf8');
83
- if (content.includes('context.sponsorshipPolicyId')) {
84
- // Patch already applied
85
- process.exit(0);
86
- }
87
- }
88
-
89
- // Apply the patch using git apply without shell interpolation.
90
- try {
91
- runOrThrow('git', ['apply', '--unsafe-paths', `--directory=${targetDir}`, patchFile], {
92
- cwd: projectRoot,
93
- });
94
- console.log('@gasfree-kit/evm-4337: Applied wdk-safe-relay-kit patch (Candide paymaster fix)');
95
- } catch {
96
- console.warn(
97
- '@gasfree-kit/evm-4337: Could not auto-apply wdk-safe-relay-kit patch.\n' +
98
- 'Please apply manually: patches/@tetherto__wdk-safe-relay-kit@4.1.5.patch\n' +
99
- 'See: https://github.com/gasfree-kit/evm-4337#patch',
100
- );
101
- }