@gasfree-kit/evm-4337 0.1.0 → 0.2.0
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 +338 -0
- package/dist/index.d.mts +161 -14
- package/dist/index.d.ts +161 -14
- package/dist/index.js +819 -92
- package/dist/index.mjs +804 -86
- package/package.json +15 -3
- package/scripts/postinstall.js +44 -23
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,54 @@ declare const GAS_FEE_FALLBACKS: Record<string, bigint>;
|
|
|
40
40
|
/** Fallback fee estimates as human-readable strings. */
|
|
41
41
|
declare const GAS_FEE_ESTIMATES: Record<string, string>;
|
|
42
42
|
|
|
43
|
+
/** Passkey credential data — app developer must persist this (or use 'persist' storage mode). */
|
|
44
|
+
interface PasskeyCredential {
|
|
45
|
+
/** WebAuthn credential ID (base64url encoded) */
|
|
46
|
+
id: string;
|
|
47
|
+
/** P256 public key coordinates from WebAuthn attestation */
|
|
48
|
+
publicKey: {
|
|
49
|
+
x: bigint;
|
|
50
|
+
y: bigint;
|
|
51
|
+
};
|
|
52
|
+
/** On-chain SafeWebAuthnSigner contract address */
|
|
53
|
+
signerAddress: string;
|
|
54
|
+
/** The Safe smart account this passkey is linked to */
|
|
55
|
+
safeAddress: string;
|
|
56
|
+
}
|
|
57
|
+
/** Storage mode for passkey credentials. */
|
|
58
|
+
type PasskeyStorageMode = 'persist' | 'not_persist';
|
|
59
|
+
/** Result from linking a passkey to a Safe. */
|
|
60
|
+
interface PasskeyLinkResult {
|
|
61
|
+
/** Passkey credential — always returned regardless of storage mode */
|
|
62
|
+
credential: PasskeyCredential;
|
|
63
|
+
/** Safe smart account address */
|
|
64
|
+
safeAddress: string;
|
|
65
|
+
/** Transaction hash of the addOwner operation */
|
|
66
|
+
transactionHash: string;
|
|
67
|
+
/** Whether the SDK persisted the credential internally */
|
|
68
|
+
persisted: boolean;
|
|
69
|
+
}
|
|
70
|
+
/** Options for passkey registration and linking. */
|
|
71
|
+
interface PasskeyOptions {
|
|
72
|
+
/** Relying party ID (defaults to window.location.hostname) */
|
|
73
|
+
rpId?: string;
|
|
74
|
+
/** Relying party display name */
|
|
75
|
+
rpName?: string;
|
|
76
|
+
/** User display name for the passkey credential */
|
|
77
|
+
userName?: string;
|
|
78
|
+
/** Credential storage mode. Default: 'not_persist'. Convenience only; not secure storage. */
|
|
79
|
+
storage?: PasskeyStorageMode;
|
|
80
|
+
}
|
|
81
|
+
/** Config extending EVM4337ClientConfig with passkey-specific options. */
|
|
82
|
+
interface PasskeyConfig extends EVM4337ClientConfig {
|
|
83
|
+
/** WebAuthn and passkey registration options */
|
|
84
|
+
passkeyOptions?: PasskeyOptions;
|
|
85
|
+
}
|
|
86
|
+
/** Pre-deployed SafeWebAuthnSignerFactory addresses per chain. */
|
|
87
|
+
declare const SAFE_WEBAUTHN_SIGNER_FACTORY: Record<string, string>;
|
|
88
|
+
/** Pre-deployed FCLP256Verifier addresses per chain. */
|
|
89
|
+
declare const FCL_P256_VERIFIER: Record<string, string>;
|
|
90
|
+
|
|
43
91
|
/**
|
|
44
92
|
* Set up an ERC-4337 wallet via WDK.
|
|
45
93
|
*
|
|
@@ -47,21 +95,17 @@ declare const GAS_FEE_ESTIMATES: Record<string, string>;
|
|
|
47
95
|
* correct discriminated-union config:
|
|
48
96
|
* - Sponsored mode → EvmErc4337WalletSponsorshipPolicyConfig
|
|
49
97
|
* - Non-sponsored → EvmErc4337WalletPaymasterTokenConfig
|
|
98
|
+
*
|
|
99
|
+
* Optionally links a passkey to the Safe account when passkeyOptions is provided.
|
|
50
100
|
*/
|
|
51
|
-
declare function setupErc4337Wallet(seedPhrase: string, config: EVM4337ClientConfig, accountIndex?: number): Promise<{
|
|
101
|
+
declare function setupErc4337Wallet(seedPhrase: string, config: EVM4337ClientConfig, accountIndex?: number, passkeyOptions?: PasskeyOptions): Promise<{
|
|
52
102
|
wallet: _tetherto_wdk_wallet_evm_erc_4337.default;
|
|
53
103
|
account: _tetherto_wdk_wallet_evm_erc_4337.EvmAccount;
|
|
54
104
|
address: string;
|
|
105
|
+
passkey: PasskeyLinkResult | undefined;
|
|
55
106
|
}>;
|
|
56
107
|
|
|
57
|
-
declare class
|
|
58
|
-
/** Default timeout for UserOp confirmation: 120 seconds. */
|
|
59
|
-
private static readonly USER_OP_TIMEOUT_MS;
|
|
60
|
-
/**
|
|
61
|
-
* Wait for a UserOperation to be included on-chain via the Candide bundler.
|
|
62
|
-
* Times out after USER_OP_TIMEOUT_MS to prevent indefinite hangs.
|
|
63
|
-
*/
|
|
64
|
-
private static waitForUserOpConfirmation;
|
|
108
|
+
declare class EvmTransfer {
|
|
65
109
|
/**
|
|
66
110
|
* Get transaction fee estimate for a USDT transfer.
|
|
67
111
|
*
|
|
@@ -117,10 +161,6 @@ declare class TetherEVMERC4337Transfer {
|
|
|
117
161
|
amount: string;
|
|
118
162
|
}[];
|
|
119
163
|
}>;
|
|
120
|
-
/**
|
|
121
|
-
* Map raw errors into user-friendly messages.
|
|
122
|
-
*/
|
|
123
|
-
static handleTransferError(error: unknown, chain: string): Error;
|
|
124
164
|
}
|
|
125
165
|
|
|
126
166
|
/**
|
|
@@ -143,4 +183,111 @@ declare function encodeErc20Transfer(to: string, amount: bigint): string;
|
|
|
143
183
|
*/
|
|
144
184
|
declare function feeToUsdt(feeInWei: bigint, nativeTokenPriceUsdt: number): string;
|
|
145
185
|
|
|
146
|
-
|
|
186
|
+
/**
|
|
187
|
+
* Wait for a UserOperation to be included on-chain via the Candide bundler.
|
|
188
|
+
* Times out after USER_OP_TIMEOUT_MS to prevent indefinite hangs.
|
|
189
|
+
*/
|
|
190
|
+
declare function waitForUserOpConfirmation(userOpHash: string, bundlerUrl: string, entryPointAddress: string): Promise<string>;
|
|
191
|
+
/**
|
|
192
|
+
* Map raw errors into user-friendly messages.
|
|
193
|
+
*/
|
|
194
|
+
declare function handleTransferError(error: unknown, chain: string): Error;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Register a new passkey via WebAuthn and link it to an existing Safe account.
|
|
198
|
+
*
|
|
199
|
+
* 1. Validates the Safe is deployed on-chain
|
|
200
|
+
* 2. Registers a new WebAuthn passkey (triggers biometric prompt)
|
|
201
|
+
* 3. Checks the signer is not already a Safe owner
|
|
202
|
+
* 4. Deploys the SafeWebAuthnSigner contract on-chain via the factory
|
|
203
|
+
* 5. Adds the signer as a Safe owner with threshold 1 (1-of-2)
|
|
204
|
+
*
|
|
205
|
+
* The seed phrase signs both the deploy and addOwner transactions.
|
|
206
|
+
*/
|
|
207
|
+
declare function linkPasskeyToSafe(seedPhrase: string, config: EVM4337ClientConfig, passkeyOptions?: PasskeyOptions, accountIndex?: number): Promise<PasskeyLinkResult>;
|
|
208
|
+
/**
|
|
209
|
+
* Check if a Safe account already has a passkey signer linked.
|
|
210
|
+
*
|
|
211
|
+
* Fix #5: properly disposes wallet/account resources.
|
|
212
|
+
*/
|
|
213
|
+
declare function isPasskeyLinked(seedPhrase: string, config: EVM4337ClientConfig, accountIndex?: number): Promise<{
|
|
214
|
+
linked: boolean;
|
|
215
|
+
signerAddress?: string;
|
|
216
|
+
}>;
|
|
217
|
+
/**
|
|
218
|
+
* Remove a passkey signer from the Safe.
|
|
219
|
+
* Signs the removeOwner tx with the seed phrase.
|
|
220
|
+
*
|
|
221
|
+
* Fix #1: Queries the actual Safe owner list to determine the correct
|
|
222
|
+
* previous owner in the linked list, instead of hardcoding SENTINEL.
|
|
223
|
+
*/
|
|
224
|
+
declare function unlinkPasskeyFromSafe(seedPhrase: string, config: EVM4337ClientConfig, credential: PasskeyCredential, accountIndex?: number): Promise<{
|
|
225
|
+
transactionHash: string;
|
|
226
|
+
}>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Passkey-signed ERC-4337 transfers via Safe account.
|
|
230
|
+
*
|
|
231
|
+
* Uses Safe4337Pack from @safe-global/relay-kit to handle the full
|
|
232
|
+
* UserOperation lifecycle: construction, passkey signing (WebAuthn biometric),
|
|
233
|
+
* paymaster integration, and bundler submission.
|
|
234
|
+
*
|
|
235
|
+
* The passkey must first be linked to the Safe via `linkPasskeyToSafe()`.
|
|
236
|
+
*/
|
|
237
|
+
declare class PasskeyTransfer {
|
|
238
|
+
/**
|
|
239
|
+
* Send a single token transfer signed by passkey.
|
|
240
|
+
* Triggers biometric authentication via WebAuthn.
|
|
241
|
+
*/
|
|
242
|
+
static sendToken(credential: PasskeyCredential, config: EVM4337ClientConfig, tokenAddress: string, amount: string, recipientAddress: string): Promise<{
|
|
243
|
+
success: boolean;
|
|
244
|
+
transactionHash: string;
|
|
245
|
+
chain: _gasfree_kit_core.EvmChain;
|
|
246
|
+
amount: string;
|
|
247
|
+
}>;
|
|
248
|
+
/**
|
|
249
|
+
* Send a batch token transfer to multiple recipients, signed by passkey.
|
|
250
|
+
*/
|
|
251
|
+
static sendBatchToken(credential: PasskeyCredential, config: EVM4337ClientConfig, tokenAddress: string, recipients: Array<{
|
|
252
|
+
address: string;
|
|
253
|
+
amount: string;
|
|
254
|
+
}>): Promise<{
|
|
255
|
+
success: boolean;
|
|
256
|
+
transactionHash: string;
|
|
257
|
+
chain: _gasfree_kit_core.EvmChain;
|
|
258
|
+
recipients: {
|
|
259
|
+
address: string;
|
|
260
|
+
amount: string;
|
|
261
|
+
}[];
|
|
262
|
+
}>;
|
|
263
|
+
/**
|
|
264
|
+
* Check token balance for a passkey-linked Safe account.
|
|
265
|
+
* Does NOT require biometric — balance is publicly readable via RPC.
|
|
266
|
+
*/
|
|
267
|
+
static checkTokenBalance(credential: PasskeyCredential, config: EVM4337ClientConfig, tokenAddress: string): Promise<{
|
|
268
|
+
message: string;
|
|
269
|
+
success: boolean;
|
|
270
|
+
data: {
|
|
271
|
+
tokenBalance: string;
|
|
272
|
+
decimals: number;
|
|
273
|
+
usdBalance: string;
|
|
274
|
+
};
|
|
275
|
+
}>;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Interface for passkey credential persistence. */
|
|
279
|
+
interface CredentialStore {
|
|
280
|
+
save(credential: PasskeyCredential): Promise<void>;
|
|
281
|
+
load(safeAddress: string): Promise<PasskeyCredential | null>;
|
|
282
|
+
remove(safeAddress: string): Promise<void>;
|
|
283
|
+
listAll(): Promise<PasskeyCredential[]>;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Auto-detect environment and return the appropriate credential store.
|
|
287
|
+
*
|
|
288
|
+
* Fix #10: Stricter browser detection — checks for navigator.credentials
|
|
289
|
+
* to avoid false positives in SSR/jsdom environments.
|
|
290
|
+
*/
|
|
291
|
+
declare function createCredentialStore(): CredentialStore;
|
|
292
|
+
|
|
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 };
|