kentucky-signer-viem 0.1.4 → 0.1.5
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 +225 -0
- package/dist/index.d.mts +376 -10
- package/dist/index.d.ts +376 -10
- package/dist/index.js +281 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +282 -26
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +465 -3
- package/dist/react/index.d.ts +465 -3
- package/dist/react/index.js +390 -25
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +391 -26
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/account.ts +183 -23
- package/src/client.ts +4 -5
- package/src/index.ts +32 -0
- package/src/intent.ts +167 -0
- package/src/react/index.ts +33 -0
- package/src/react/relayer-hooks.ts +318 -0
- package/src/relayer-client.ts +305 -0
- package/src/secure-client.ts +2 -2
- package/src/types.ts +4 -3
package/README.md
CHANGED
|
@@ -15,6 +15,9 @@ A custom Viem account integration for the Kentucky Signer service, enabling EVM
|
|
|
15
15
|
- **React Integration** - Hooks and context for easy React app integration
|
|
16
16
|
- **TypeScript Support** - Full type definitions included
|
|
17
17
|
- **Session Management** - Automatic refresh and persistence options
|
|
18
|
+
- **EIP-7702 Support** - Sign authorizations for EOA code delegation
|
|
19
|
+
- **Relayer Integration** - Client for gasless transactions via relayer service
|
|
20
|
+
- **Intent Signing** - Sign execution intents for smart account operations
|
|
18
21
|
|
|
19
22
|
## Installation
|
|
20
23
|
|
|
@@ -204,6 +207,205 @@ const account = createKentuckySignerAccount({
|
|
|
204
207
|
})
|
|
205
208
|
```
|
|
206
209
|
|
|
210
|
+
## EIP-7702 Authorization
|
|
211
|
+
|
|
212
|
+
Sign authorizations to delegate your EOA's code to a smart contract, enabling features like batching and gas sponsorship.
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { createPublicClient, http } from 'viem'
|
|
216
|
+
import { arbitrum } from 'viem/chains'
|
|
217
|
+
|
|
218
|
+
const publicClient = createPublicClient({
|
|
219
|
+
chain: arbitrum,
|
|
220
|
+
transport: http(),
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
// Get current transaction count for the account
|
|
224
|
+
const txNonce = await publicClient.getTransactionCount({
|
|
225
|
+
address: account.address,
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
// Sign EIP-7702 authorization
|
|
229
|
+
const authorization = await account.sign7702Authorization({
|
|
230
|
+
contractAddress: '0x...', // Smart account delegate contract
|
|
231
|
+
chainId: 42161, // Arbitrum
|
|
232
|
+
}, BigInt(txNonce))
|
|
233
|
+
|
|
234
|
+
// Result:
|
|
235
|
+
// {
|
|
236
|
+
// chainId: 42161,
|
|
237
|
+
// contractAddress: '0x...',
|
|
238
|
+
// nonce: 0n,
|
|
239
|
+
// yParity: 0,
|
|
240
|
+
// r: '0x...',
|
|
241
|
+
// s: '0x...'
|
|
242
|
+
// }
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
The authorization can be included in an EIP-7702 transaction's `authorizationList` to delegate the EOA.
|
|
246
|
+
|
|
247
|
+
## Intent Signing for Relayed Execution
|
|
248
|
+
|
|
249
|
+
Sign execution intents for gasless transactions via a relayer.
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
import {
|
|
253
|
+
createExecutionIntent,
|
|
254
|
+
signIntent,
|
|
255
|
+
RelayerClient,
|
|
256
|
+
} from 'kentucky-signer-viem'
|
|
257
|
+
import { encodeFunctionData, parseEther } from 'viem'
|
|
258
|
+
|
|
259
|
+
// Create relayer client
|
|
260
|
+
const relayer = new RelayerClient({
|
|
261
|
+
baseUrl: 'https://relayer.example.com',
|
|
262
|
+
})
|
|
263
|
+
|
|
264
|
+
// Get current nonce from the delegate contract
|
|
265
|
+
const nonce = await relayer.getNonce(42161, account.address)
|
|
266
|
+
|
|
267
|
+
// Create an execution intent
|
|
268
|
+
const intent = createExecutionIntent({
|
|
269
|
+
nonce,
|
|
270
|
+
target: '0x...', // Contract to call
|
|
271
|
+
value: parseEther('0.1'), // ETH to send (optional)
|
|
272
|
+
data: encodeFunctionData({
|
|
273
|
+
abi: [...],
|
|
274
|
+
functionName: 'transfer',
|
|
275
|
+
args: ['0x...', 1000n],
|
|
276
|
+
}),
|
|
277
|
+
deadline: BigInt(Math.floor(Date.now() / 1000) + 3600), // 1 hour (optional)
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
// Sign the intent
|
|
281
|
+
const signedIntent = await signIntent(account, intent)
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Relayer Client
|
|
285
|
+
|
|
286
|
+
The `RelayerClient` communicates with a relayer service to submit transactions on behalf of users.
|
|
287
|
+
|
|
288
|
+
### Basic Usage
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import { RelayerClient, createRelayerClient } from 'kentucky-signer-viem'
|
|
292
|
+
|
|
293
|
+
// Create client
|
|
294
|
+
const relayer = new RelayerClient({
|
|
295
|
+
baseUrl: 'https://relayer.example.com',
|
|
296
|
+
timeout: 30000, // Optional, default 30s
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
// Or use the factory function
|
|
300
|
+
const relayer = createRelayerClient('https://relayer.example.com')
|
|
301
|
+
|
|
302
|
+
// Check health
|
|
303
|
+
const health = await relayer.health()
|
|
304
|
+
// { status: 'ok', relayer: '0x...', timestamp: '2024-...' }
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Get Nonce
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const nonce = await relayer.getNonce(42161, account.address)
|
|
311
|
+
// Returns bigint nonce from the delegate contract
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Estimate Gas
|
|
315
|
+
|
|
316
|
+
```typescript
|
|
317
|
+
const estimate = await relayer.estimate(42161, account.address, intent)
|
|
318
|
+
// {
|
|
319
|
+
// gasEstimate: '150000',
|
|
320
|
+
// gasCostWei: '30000000000000',
|
|
321
|
+
// sponsoredAvailable: true,
|
|
322
|
+
// tokenOptions: [
|
|
323
|
+
// { token: '0x...', symbol: 'USDC', estimatedFee: '0.05', feePercentage: 5 }
|
|
324
|
+
// ]
|
|
325
|
+
// }
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### Relay Transaction
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
// Sponsored (relayer pays gas)
|
|
332
|
+
const result = await relayer.relay(
|
|
333
|
+
42161,
|
|
334
|
+
account.address,
|
|
335
|
+
signedIntent,
|
|
336
|
+
'sponsored'
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
// Pay with ERC20 token
|
|
340
|
+
const result = await relayer.relay(
|
|
341
|
+
42161,
|
|
342
|
+
account.address,
|
|
343
|
+
signedIntent,
|
|
344
|
+
{ token: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831' } // USDC on Arbitrum
|
|
345
|
+
)
|
|
346
|
+
|
|
347
|
+
if (result.success) {
|
|
348
|
+
console.log('TX Hash:', result.txHash)
|
|
349
|
+
} else {
|
|
350
|
+
console.error('Failed:', result.error)
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Gasless Onboarding
|
|
355
|
+
|
|
356
|
+
For users with zero ETH, combine EIP-7702 authorization with relay to delegate and execute in a single transaction:
|
|
357
|
+
|
|
358
|
+
```typescript
|
|
359
|
+
import { createPublicClient, http } from 'viem'
|
|
360
|
+
import { arbitrum } from 'viem/chains'
|
|
361
|
+
|
|
362
|
+
const publicClient = createPublicClient({
|
|
363
|
+
chain: arbitrum,
|
|
364
|
+
transport: http(),
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
// Get current nonce
|
|
368
|
+
const txNonce = await publicClient.getTransactionCount({
|
|
369
|
+
address: account.address,
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
// Sign EIP-7702 authorization to delegate EOA
|
|
373
|
+
const authorization = await account.sign7702Authorization({
|
|
374
|
+
contractAddress: delegateAddress,
|
|
375
|
+
chainId: 42161,
|
|
376
|
+
}, BigInt(txNonce))
|
|
377
|
+
|
|
378
|
+
// Create and sign execution intent
|
|
379
|
+
const nonce = await relayer.getNonce(42161, account.address)
|
|
380
|
+
const intent = createExecutionIntent({
|
|
381
|
+
nonce,
|
|
382
|
+
target: '0x...',
|
|
383
|
+
data: '0x...',
|
|
384
|
+
})
|
|
385
|
+
const signedIntent = await signIntent(account, intent)
|
|
386
|
+
|
|
387
|
+
// Relay with authorization - delegates EOA and executes in one tx
|
|
388
|
+
const result = await relayer.relay(
|
|
389
|
+
42161,
|
|
390
|
+
account.address,
|
|
391
|
+
signedIntent,
|
|
392
|
+
'sponsored',
|
|
393
|
+
authorization // Include EIP-7702 authorization
|
|
394
|
+
)
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
### Check Transaction Status
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
const status = await relayer.getStatus(42161, txHash)
|
|
401
|
+
// {
|
|
402
|
+
// status: 'confirmed', // 'pending' | 'confirmed' | 'failed'
|
|
403
|
+
// txHash: '0x...',
|
|
404
|
+
// blockNumber: 12345678,
|
|
405
|
+
// gasUsed: '120000'
|
|
406
|
+
// }
|
|
407
|
+
```
|
|
408
|
+
|
|
207
409
|
## Two-Factor Authentication
|
|
208
410
|
|
|
209
411
|
### Setup TOTP (Authenticator App)
|
|
@@ -318,6 +520,16 @@ await client.completeRecovery(accountId)
|
|
|
318
520
|
| `createAccountWithPassword(options)` | Create new account with password |
|
|
319
521
|
| `authenticateWithToken(...)` | Create session from JWT token |
|
|
320
522
|
|
|
523
|
+
### Intent & Relayer Functions
|
|
524
|
+
|
|
525
|
+
| Function | Description |
|
|
526
|
+
|----------|-------------|
|
|
527
|
+
| `createExecutionIntent(params)` | Create an execution intent for relayed execution |
|
|
528
|
+
| `signIntent(account, intent)` | Sign an execution intent |
|
|
529
|
+
| `signBatchIntents(account, intents)` | Sign multiple intents for batch execution |
|
|
530
|
+
| `hashIntent(intent)` | Compute the hash of an execution intent |
|
|
531
|
+
| `createRelayerClient(baseUrl)` | Create a relayer client |
|
|
532
|
+
|
|
321
533
|
### React Hooks
|
|
322
534
|
|
|
323
535
|
| Hook | Description |
|
|
@@ -359,6 +571,19 @@ await client.completeRecovery(accountId)
|
|
|
359
571
|
- `setupPIN(pin, token)` - Setup PIN
|
|
360
572
|
- `disablePIN(pin, token)` - Disable PIN
|
|
361
573
|
|
|
574
|
+
### Account Methods
|
|
575
|
+
|
|
576
|
+
#### EIP-7702 Authorization
|
|
577
|
+
- `account.sign7702Authorization(params, nonce)` - Sign authorization to delegate EOA code
|
|
578
|
+
|
|
579
|
+
### Relayer Client Methods
|
|
580
|
+
|
|
581
|
+
- `health()` - Check relayer health
|
|
582
|
+
- `getNonce(chainId, address)` - Get account nonce from delegate contract
|
|
583
|
+
- `estimate(chainId, address, intent)` - Estimate gas and fees
|
|
584
|
+
- `relay(chainId, address, signedIntent, paymentMode, authorization?)` - Submit transaction
|
|
585
|
+
- `getStatus(chainId, txHash)` - Get transaction status
|
|
586
|
+
|
|
362
587
|
#### Guardian Recovery
|
|
363
588
|
- `addGuardian(request, token)` - Add guardian passkey
|
|
364
589
|
- `removeGuardian(guardianIndex, token)` - Remove guardian
|
package/dist/index.d.mts
CHANGED
|
@@ -61,16 +61,19 @@ interface AccountInfoResponse {
|
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
63
|
* EVM signature response from Kentucky Signer
|
|
64
|
+
*
|
|
65
|
+
* Note: v is always 27 or 28 (standard format).
|
|
66
|
+
* EIP-155 encoding should be applied by the caller when needed for legacy transactions.
|
|
64
67
|
*/
|
|
65
68
|
interface EvmSignatureResponse {
|
|
66
69
|
success: boolean;
|
|
67
70
|
signature: {
|
|
68
71
|
r: Hex;
|
|
69
72
|
s: Hex;
|
|
73
|
+
/** v value: 27 or 28 (recovery_id + 27) */
|
|
70
74
|
v: number;
|
|
71
75
|
full: Hex;
|
|
72
76
|
};
|
|
73
|
-
chain_id: number;
|
|
74
77
|
signer_address: string;
|
|
75
78
|
}
|
|
76
79
|
/**
|
|
@@ -142,8 +145,6 @@ interface ClientOptions {
|
|
|
142
145
|
interface SignEvmRequest {
|
|
143
146
|
/** Transaction hash to sign (32 bytes, hex encoded) */
|
|
144
147
|
tx_hash: Hex;
|
|
145
|
-
/** Chain ID */
|
|
146
|
-
chain_id: number;
|
|
147
148
|
}
|
|
148
149
|
/**
|
|
149
150
|
* Passkey registration options (for account creation)
|
|
@@ -745,7 +746,7 @@ declare class SecureKentuckySignerClient {
|
|
|
745
746
|
/**
|
|
746
747
|
* Sign a raw hash for EVM (signed request)
|
|
747
748
|
*/
|
|
748
|
-
signHash(hash: Hex,
|
|
749
|
+
signHash(hash: Hex, token: string): Promise<Hex>;
|
|
749
750
|
/**
|
|
750
751
|
* Add password to account (signed request)
|
|
751
752
|
*/
|
|
@@ -794,6 +795,41 @@ type TwoFactorCallback = (requirements: {
|
|
|
794
795
|
pinRequired: boolean;
|
|
795
796
|
pinLength: number;
|
|
796
797
|
}) => Promise<TwoFactorCodes | null | undefined>;
|
|
798
|
+
/**
|
|
799
|
+
* Parameters for signing an EIP-7702 authorization
|
|
800
|
+
*/
|
|
801
|
+
interface SignAuthorizationParameters {
|
|
802
|
+
/** The contract address to delegate to */
|
|
803
|
+
contractAddress: Address;
|
|
804
|
+
/** Chain ID (0 for all chains, defaults to client chain) */
|
|
805
|
+
chainId?: number;
|
|
806
|
+
/** Nonce for the authorization (defaults to account's current nonce) */
|
|
807
|
+
nonce?: bigint;
|
|
808
|
+
/**
|
|
809
|
+
* Whether the authorization will be executed by the signer themselves.
|
|
810
|
+
* If 'self', the nonce in the authorization will be incremented by 1
|
|
811
|
+
* over the transaction nonce.
|
|
812
|
+
*/
|
|
813
|
+
executor?: 'self';
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Signed EIP-7702 authorization
|
|
817
|
+
* Compatible with viem's SignedAuthorizationList
|
|
818
|
+
*/
|
|
819
|
+
interface SignedAuthorization {
|
|
820
|
+
/** Chain ID (0 for all chains) */
|
|
821
|
+
chainId: number;
|
|
822
|
+
/** Contract address to delegate to */
|
|
823
|
+
contractAddress: Address;
|
|
824
|
+
/** Nonce for the authorization */
|
|
825
|
+
nonce: bigint;
|
|
826
|
+
/** Recovery identifier (0 or 1) */
|
|
827
|
+
yParity: number;
|
|
828
|
+
/** Signature r component */
|
|
829
|
+
r: Hex;
|
|
830
|
+
/** Signature s component */
|
|
831
|
+
s: Hex;
|
|
832
|
+
}
|
|
797
833
|
/**
|
|
798
834
|
* Options for creating a Kentucky Signer account
|
|
799
835
|
*/
|
|
@@ -814,13 +850,41 @@ interface KentuckySignerAccountOptions {
|
|
|
814
850
|
/**
|
|
815
851
|
* Extended account type with Kentucky Signer specific properties
|
|
816
852
|
*/
|
|
817
|
-
interface KentuckySignerAccount extends LocalAccount<'kentuckySigner'> {
|
|
853
|
+
interface KentuckySignerAccount extends Omit<LocalAccount<'kentuckySigner'>, 'signAuthorization'> {
|
|
818
854
|
/** Account ID */
|
|
819
855
|
accountId: string;
|
|
820
856
|
/** Current session */
|
|
821
857
|
session: AuthSession;
|
|
822
858
|
/** Update the session (e.g., after refresh) */
|
|
823
859
|
updateSession: (session: AuthSession) => void;
|
|
860
|
+
/**
|
|
861
|
+
* Sign an EIP-7702 authorization to delegate code to this account
|
|
862
|
+
*
|
|
863
|
+
* @param params - Authorization parameters
|
|
864
|
+
* @param nonce - Current account nonce (required if params.nonce not specified)
|
|
865
|
+
* @returns Signed authorization compatible with viem's authorizationList
|
|
866
|
+
*
|
|
867
|
+
* @example
|
|
868
|
+
* ```typescript
|
|
869
|
+
* // Get current nonce
|
|
870
|
+
* const nonce = await publicClient.getTransactionCount({ address: account.address })
|
|
871
|
+
*
|
|
872
|
+
* // Sign authorization
|
|
873
|
+
* const authorization = await account.sign7702Authorization({
|
|
874
|
+
* contractAddress: '0x69007702764179f14F51cdce752f4f775d74E139', // Alchemy MA v2
|
|
875
|
+
* chainId: 1,
|
|
876
|
+
* executor: 'self', // Account will execute the tx
|
|
877
|
+
* }, nonce)
|
|
878
|
+
*
|
|
879
|
+
* // Send EIP-7702 transaction
|
|
880
|
+
* const hash = await walletClient.sendTransaction({
|
|
881
|
+
* authorizationList: [authorization],
|
|
882
|
+
* to: account.address,
|
|
883
|
+
* data: initializeCalldata,
|
|
884
|
+
* })
|
|
885
|
+
* ```
|
|
886
|
+
*/
|
|
887
|
+
sign7702Authorization: (params: SignAuthorizationParameters, nonce: bigint) => Promise<SignedAuthorization>;
|
|
824
888
|
}
|
|
825
889
|
/**
|
|
826
890
|
* Create a custom Viem account backed by Kentucky Signer
|
|
@@ -941,9 +1005,9 @@ declare class KentuckySignerClient {
|
|
|
941
1005
|
/**
|
|
942
1006
|
* Sign an EVM transaction hash
|
|
943
1007
|
*
|
|
944
|
-
* @param request - Sign request with tx_hash
|
|
1008
|
+
* @param request - Sign request with tx_hash
|
|
945
1009
|
* @param token - JWT token
|
|
946
|
-
* @returns Signature response with r, s, v components
|
|
1010
|
+
* @returns Signature response with r, s, v components (v is always 27 or 28)
|
|
947
1011
|
*/
|
|
948
1012
|
signEvmTransaction(request: SignEvmRequest, token: string): Promise<EvmSignatureResponse>;
|
|
949
1013
|
/**
|
|
@@ -952,11 +1016,10 @@ declare class KentuckySignerClient {
|
|
|
952
1016
|
* Convenience method that wraps signEvmTransaction.
|
|
953
1017
|
*
|
|
954
1018
|
* @param hash - 32-byte hash to sign (hex encoded with 0x prefix)
|
|
955
|
-
* @param chainId - Chain ID
|
|
956
1019
|
* @param token - JWT token
|
|
957
1020
|
* @returns Full signature (hex encoded with 0x prefix)
|
|
958
1021
|
*/
|
|
959
|
-
signHash(hash: Hex,
|
|
1022
|
+
signHash(hash: Hex, token: string): Promise<Hex>;
|
|
960
1023
|
/**
|
|
961
1024
|
* Create a new account with passkey authentication
|
|
962
1025
|
*
|
|
@@ -1395,4 +1458,307 @@ declare function getJwtExpiration(token: string): number | null;
|
|
|
1395
1458
|
*/
|
|
1396
1459
|
declare function formatError(error: unknown): string;
|
|
1397
1460
|
|
|
1398
|
-
|
|
1461
|
+
/**
|
|
1462
|
+
* Execution intent to be signed by the EOA owner
|
|
1463
|
+
*/
|
|
1464
|
+
interface ExecutionIntent {
|
|
1465
|
+
/** Replay protection nonce */
|
|
1466
|
+
nonce: bigint;
|
|
1467
|
+
/** Expiration timestamp (unix seconds) */
|
|
1468
|
+
deadline: bigint;
|
|
1469
|
+
/** Contract to call */
|
|
1470
|
+
target: Address;
|
|
1471
|
+
/** ETH value to send */
|
|
1472
|
+
value: bigint;
|
|
1473
|
+
/** Calldata for the call */
|
|
1474
|
+
data: Hex;
|
|
1475
|
+
}
|
|
1476
|
+
/**
|
|
1477
|
+
* Signed execution intent
|
|
1478
|
+
*/
|
|
1479
|
+
interface SignedIntent {
|
|
1480
|
+
/** The execution intent */
|
|
1481
|
+
intent: ExecutionIntent;
|
|
1482
|
+
/** Owner's signature on the intent */
|
|
1483
|
+
signature: Hex;
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Parameters for creating an execution intent
|
|
1487
|
+
*/
|
|
1488
|
+
interface CreateIntentParams {
|
|
1489
|
+
/** Account nonce (fetch from contract) */
|
|
1490
|
+
nonce: bigint;
|
|
1491
|
+
/** Expiration timestamp (unix seconds) */
|
|
1492
|
+
deadline?: bigint;
|
|
1493
|
+
/** Contract to call */
|
|
1494
|
+
target: Address;
|
|
1495
|
+
/** ETH value to send */
|
|
1496
|
+
value?: bigint;
|
|
1497
|
+
/** Calldata for the call */
|
|
1498
|
+
data?: Hex;
|
|
1499
|
+
}
|
|
1500
|
+
/**
|
|
1501
|
+
* Create an execution intent
|
|
1502
|
+
*
|
|
1503
|
+
* @param params - Intent parameters
|
|
1504
|
+
* @returns Execution intent
|
|
1505
|
+
*
|
|
1506
|
+
* @example
|
|
1507
|
+
* ```typescript
|
|
1508
|
+
* const intent = createExecutionIntent({
|
|
1509
|
+
* nonce: 0n,
|
|
1510
|
+
* target: '0x...',
|
|
1511
|
+
* value: parseEther('0.1'),
|
|
1512
|
+
* data: '0x',
|
|
1513
|
+
* })
|
|
1514
|
+
* ```
|
|
1515
|
+
*/
|
|
1516
|
+
declare function createExecutionIntent(params: CreateIntentParams): ExecutionIntent;
|
|
1517
|
+
/**
|
|
1518
|
+
* Compute the hash of an execution intent
|
|
1519
|
+
*
|
|
1520
|
+
* @param intent - The execution intent
|
|
1521
|
+
* @returns Intent hash
|
|
1522
|
+
*/
|
|
1523
|
+
declare function hashIntent(intent: ExecutionIntent): Hex;
|
|
1524
|
+
/**
|
|
1525
|
+
* Sign an execution intent using a Kentucky Signer account
|
|
1526
|
+
*
|
|
1527
|
+
* @param account - Kentucky Signer account
|
|
1528
|
+
* @param intent - The execution intent to sign
|
|
1529
|
+
* @returns Signed intent
|
|
1530
|
+
*
|
|
1531
|
+
* @example
|
|
1532
|
+
* ```typescript
|
|
1533
|
+
* const account = useKentuckySignerAccount()
|
|
1534
|
+
* const intent = createExecutionIntent({ nonce: 0n, target: '0x...' })
|
|
1535
|
+
* const signedIntent = await signIntent(account, intent)
|
|
1536
|
+
* ```
|
|
1537
|
+
*/
|
|
1538
|
+
declare function signIntent(account: KentuckySignerAccount, intent: ExecutionIntent): Promise<SignedIntent>;
|
|
1539
|
+
/**
|
|
1540
|
+
* Compute combined hash for batch intents
|
|
1541
|
+
*
|
|
1542
|
+
* @param intents - Array of execution intents
|
|
1543
|
+
* @returns Combined hash
|
|
1544
|
+
*/
|
|
1545
|
+
declare function hashBatchIntents(intents: ExecutionIntent[]): Hex;
|
|
1546
|
+
/**
|
|
1547
|
+
* Sign multiple execution intents for batch execution
|
|
1548
|
+
*
|
|
1549
|
+
* @param account - Kentucky Signer account
|
|
1550
|
+
* @param intents - Array of execution intents
|
|
1551
|
+
* @returns Array of signed intents
|
|
1552
|
+
*/
|
|
1553
|
+
declare function signBatchIntents(account: KentuckySignerAccount, intents: ExecutionIntent[]): Promise<SignedIntent[]>;
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* Payment mode for relaying
|
|
1557
|
+
*/
|
|
1558
|
+
type PaymentMode = 'sponsored' | {
|
|
1559
|
+
token: Address;
|
|
1560
|
+
};
|
|
1561
|
+
/**
|
|
1562
|
+
* EIP-7702 Authorization for gasless onboarding
|
|
1563
|
+
* When provided to relay(), allows users with 0 ETH to delegate their EOA
|
|
1564
|
+
* to the smart account delegate in the same transaction as execution
|
|
1565
|
+
*/
|
|
1566
|
+
interface Authorization7702 {
|
|
1567
|
+
/** Chain ID (0 for all chains) */
|
|
1568
|
+
chainId: number;
|
|
1569
|
+
/** Contract address to delegate to */
|
|
1570
|
+
contractAddress: Address;
|
|
1571
|
+
/** Nonce for the authorization */
|
|
1572
|
+
nonce: bigint;
|
|
1573
|
+
/** Recovery identifier (0 or 1) */
|
|
1574
|
+
yParity: number;
|
|
1575
|
+
/** Signature r component */
|
|
1576
|
+
r: Hex;
|
|
1577
|
+
/** Signature s component */
|
|
1578
|
+
s: Hex;
|
|
1579
|
+
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Token payment option returned by estimate
|
|
1582
|
+
*/
|
|
1583
|
+
interface TokenOption {
|
|
1584
|
+
/** Token address */
|
|
1585
|
+
token: Address;
|
|
1586
|
+
/** Token symbol */
|
|
1587
|
+
symbol: string;
|
|
1588
|
+
/** Estimated fee in token units */
|
|
1589
|
+
estimatedFee: string;
|
|
1590
|
+
/** Fee percentage (e.g., 5 = 5%) */
|
|
1591
|
+
feePercentage: number;
|
|
1592
|
+
}
|
|
1593
|
+
/**
|
|
1594
|
+
* Gas estimate response
|
|
1595
|
+
*/
|
|
1596
|
+
interface EstimateResponse {
|
|
1597
|
+
/** Estimated gas units */
|
|
1598
|
+
gasEstimate: string;
|
|
1599
|
+
/** Estimated gas cost in wei */
|
|
1600
|
+
gasCostWei: string;
|
|
1601
|
+
/** Whether sponsored mode is available */
|
|
1602
|
+
sponsoredAvailable: boolean;
|
|
1603
|
+
/** Available token payment options */
|
|
1604
|
+
tokenOptions: TokenOption[];
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* Relay response
|
|
1608
|
+
*/
|
|
1609
|
+
interface RelayResponse {
|
|
1610
|
+
/** Whether the relay was successful */
|
|
1611
|
+
success: boolean;
|
|
1612
|
+
/** Transaction hash if successful */
|
|
1613
|
+
txHash?: Hex;
|
|
1614
|
+
/** Error message if failed */
|
|
1615
|
+
error?: string;
|
|
1616
|
+
}
|
|
1617
|
+
/**
|
|
1618
|
+
* Transaction status
|
|
1619
|
+
*/
|
|
1620
|
+
type TransactionStatus = 'pending' | 'confirmed' | 'failed';
|
|
1621
|
+
/**
|
|
1622
|
+
* Status response
|
|
1623
|
+
*/
|
|
1624
|
+
interface StatusResponse {
|
|
1625
|
+
/** Current status */
|
|
1626
|
+
status: TransactionStatus;
|
|
1627
|
+
/** Transaction hash */
|
|
1628
|
+
txHash: Hex;
|
|
1629
|
+
/** Block number if confirmed */
|
|
1630
|
+
blockNumber?: number;
|
|
1631
|
+
/** Gas used if confirmed */
|
|
1632
|
+
gasUsed?: string;
|
|
1633
|
+
/** Token amount paid if applicable */
|
|
1634
|
+
tokenPaid?: string;
|
|
1635
|
+
}
|
|
1636
|
+
/**
|
|
1637
|
+
* Relayer client options
|
|
1638
|
+
*/
|
|
1639
|
+
interface RelayerClientOptions {
|
|
1640
|
+
/** Relayer API base URL */
|
|
1641
|
+
baseUrl: string;
|
|
1642
|
+
/** Request timeout in ms (default: 30000) */
|
|
1643
|
+
timeout?: number;
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Client for interacting with the Kentucky Signer Relayer API
|
|
1647
|
+
*
|
|
1648
|
+
* @example
|
|
1649
|
+
* ```typescript
|
|
1650
|
+
* const relayer = new RelayerClient({ baseUrl: 'https://relayer.example.com' })
|
|
1651
|
+
*
|
|
1652
|
+
* // Get nonce
|
|
1653
|
+
* const nonce = await relayer.getNonce(42161, accountAddress)
|
|
1654
|
+
*
|
|
1655
|
+
* // Create and sign intent
|
|
1656
|
+
* const intent = createExecutionIntent({ nonce, target: '0x...' })
|
|
1657
|
+
* const signed = await signIntent(account, intent)
|
|
1658
|
+
*
|
|
1659
|
+
* // Estimate fees
|
|
1660
|
+
* const estimate = await relayer.estimate(42161, accountAddress, intent)
|
|
1661
|
+
*
|
|
1662
|
+
* // Relay transaction
|
|
1663
|
+
* const result = await relayer.relay(42161, accountAddress, signed, 'sponsored')
|
|
1664
|
+
* console.log('TX Hash:', result.txHash)
|
|
1665
|
+
*
|
|
1666
|
+
* // Check status
|
|
1667
|
+
* const status = await relayer.getStatus(42161, result.txHash!)
|
|
1668
|
+
* ```
|
|
1669
|
+
*/
|
|
1670
|
+
declare class RelayerClient {
|
|
1671
|
+
private baseUrl;
|
|
1672
|
+
private timeout;
|
|
1673
|
+
constructor(options: RelayerClientOptions);
|
|
1674
|
+
/**
|
|
1675
|
+
* Check if the relayer is healthy
|
|
1676
|
+
*/
|
|
1677
|
+
health(): Promise<{
|
|
1678
|
+
status: string;
|
|
1679
|
+
relayer: Address;
|
|
1680
|
+
timestamp: string;
|
|
1681
|
+
}>;
|
|
1682
|
+
/**
|
|
1683
|
+
* Get the current nonce for an account
|
|
1684
|
+
*
|
|
1685
|
+
* @param chainId - Chain ID
|
|
1686
|
+
* @param address - Account address
|
|
1687
|
+
* @returns Current nonce as bigint
|
|
1688
|
+
*/
|
|
1689
|
+
getNonce(chainId: number, address: Address): Promise<bigint>;
|
|
1690
|
+
/**
|
|
1691
|
+
* Estimate gas and fees for an intent
|
|
1692
|
+
*
|
|
1693
|
+
* @param chainId - Chain ID
|
|
1694
|
+
* @param accountAddress - Account address (the delegated EOA)
|
|
1695
|
+
* @param intent - Execution intent
|
|
1696
|
+
* @returns Estimate response
|
|
1697
|
+
*/
|
|
1698
|
+
estimate(chainId: number, accountAddress: Address, intent: ExecutionIntent): Promise<EstimateResponse>;
|
|
1699
|
+
/**
|
|
1700
|
+
* Relay a signed intent
|
|
1701
|
+
*
|
|
1702
|
+
* @param chainId - Chain ID
|
|
1703
|
+
* @param accountAddress - Account address (the delegated EOA)
|
|
1704
|
+
* @param signedIntent - Signed execution intent
|
|
1705
|
+
* @param paymentMode - Payment mode ('sponsored' or { token: Address })
|
|
1706
|
+
* @param authorization - Optional EIP-7702 authorization for gasless onboarding
|
|
1707
|
+
* @returns Relay response with transaction hash
|
|
1708
|
+
*
|
|
1709
|
+
* @example Gasless onboarding (delegate + execute in one tx)
|
|
1710
|
+
* ```typescript
|
|
1711
|
+
* // Get current nonce for authorization
|
|
1712
|
+
* const txNonce = await publicClient.getTransactionCount({ address: accountAddress })
|
|
1713
|
+
*
|
|
1714
|
+
* // Sign EIP-7702 authorization
|
|
1715
|
+
* const authorization = await account.sign7702Authorization({
|
|
1716
|
+
* contractAddress: delegateAddress,
|
|
1717
|
+
* chainId: 42161,
|
|
1718
|
+
* }, txNonce)
|
|
1719
|
+
*
|
|
1720
|
+
* // Relay with authorization
|
|
1721
|
+
* const result = await relayer.relay(
|
|
1722
|
+
* 42161,
|
|
1723
|
+
* accountAddress,
|
|
1724
|
+
* signedIntent,
|
|
1725
|
+
* 'sponsored',
|
|
1726
|
+
* authorization
|
|
1727
|
+
* )
|
|
1728
|
+
* ```
|
|
1729
|
+
*/
|
|
1730
|
+
relay(chainId: number, accountAddress: Address, signedIntent: SignedIntent, paymentMode: PaymentMode, authorization?: Authorization7702): Promise<RelayResponse>;
|
|
1731
|
+
/**
|
|
1732
|
+
* Get transaction status
|
|
1733
|
+
*
|
|
1734
|
+
* @param chainId - Chain ID
|
|
1735
|
+
* @param txHash - Transaction hash
|
|
1736
|
+
* @returns Status response
|
|
1737
|
+
*/
|
|
1738
|
+
getStatus(chainId: number, txHash: Hex): Promise<StatusResponse>;
|
|
1739
|
+
/**
|
|
1740
|
+
* Make a fetch request to the relayer API
|
|
1741
|
+
*/
|
|
1742
|
+
private fetch;
|
|
1743
|
+
}
|
|
1744
|
+
/**
|
|
1745
|
+
* Create a relayer client
|
|
1746
|
+
*
|
|
1747
|
+
* @param baseUrl - Relayer API base URL
|
|
1748
|
+
* @returns Relayer client instance
|
|
1749
|
+
*/
|
|
1750
|
+
declare function createRelayerClient(baseUrl: string): RelayerClient;
|
|
1751
|
+
|
|
1752
|
+
/**
|
|
1753
|
+
* Kentucky Signer Viem Integration
|
|
1754
|
+
*
|
|
1755
|
+
* A custom Viem account implementation for signing EVM transactions
|
|
1756
|
+
* using the Kentucky Signer service with passkey authentication.
|
|
1757
|
+
*
|
|
1758
|
+
* @packageDocumentation
|
|
1759
|
+
*/
|
|
1760
|
+
|
|
1761
|
+
/** Alchemy's SemiModularAccount7702 implementation address (same across all EVM chains) */
|
|
1762
|
+
declare const ALCHEMY_SEMI_MODULAR_ACCOUNT_7702: "0x69007702764179f14F51cdce752f4f775d74E139";
|
|
1763
|
+
|
|
1764
|
+
export { ALCHEMY_SEMI_MODULAR_ACCOUNT_7702, type AccountCreationResponse, type AccountInfoExtendedResponse, type AccountInfoResponse, type AddGuardianRequest, type AddGuardianResponse, type AddPasskeyRequest, type AddPasskeyResponse, type AddPasswordRequest, type AddPasswordResponse, type ApiErrorResponse, type AuthConfig, type AuthResponse, type AuthResponseWithEphemeral, type AuthSession, type CancelRecoveryResponse, type ChallengeResponse, type ClientOptions, type CompleteRecoveryRequest, type CompleteRecoveryResponse, type CreateIntentParams, type CreatePasswordAccountRequest, EphemeralKeyManager, type EphemeralKeyPair, type EphemeralKeyStorage, type EstimateResponse, type EvmSignatureResponse, type ExecutionIntent, type GetGuardiansResponse, type GuardianInfo, IndexedDBEphemeralKeyStorage, type InitiateRecoveryRequest, type InitiateRecoveryResponse, type KentuckySignerAccount, type KentuckySignerAccountOptions, KentuckySignerClient, type KentuckySignerConfig, KentuckySignerError, LocalStorageTokenStorage, MemoryEphemeralKeyStorage, MemoryTokenStorage, type PasskeyAuthOptions, type PasskeyCredential, type PasskeyRegistrationOptions, type PasswordAccountCreationOptions, type PasswordAuthOptions, type PasswordAuthRequest, type PaymentMode, type PinSetupRequest, type PinSetupResponse, type RecoveryStatusRequest, type RecoveryStatusResponse, type RelayResponse, RelayerClient, type RelayerClientOptions, type RemoveGuardianResponse, type RemovePasskeyResponse, type SecureClientOptions, SecureKentuckySignerClient, type SignAuthorizationParameters, type SignEvmRequest, type SignEvmRequestWith2FA, type SignedAuthorization, type SignedIntent, type SignedPayload, type StatusResponse, type TokenOption, type TokenStorage, type TotpEnableRequest, type TotpSetupResponse, type TransactionStatus, type TwoFactorCallback, type TwoFactorCodes, type TwoFactorResponse, type TwoFactorStatusResponse, type TwoFactorVerifyResponse, type VerifyGuardianRequest, type VerifyGuardianResponse, authenticateWithPasskey, authenticateWithPassword, authenticateWithToken, base64UrlDecode, base64UrlEncode, bytesToHex, createAccountWithPassword, createClient, createExecutionIntent, createKentuckySignerAccount, createRelayerClient, createSecureClient, createServerAccount, formatError, generateEphemeralKeyPair, getJwtExpiration, hashBatchIntents, hashIntent, hexToBytes, isSessionValid, isValidAccountId, isValidEvmAddress, isWebAuthnAvailable, isWebCryptoAvailable, parseJwt, refreshSessionIfNeeded, registerPasskey, signBatchIntents, signIntent, signPayload, verifyPayload, withRetry };
|