viem 2.51.3 → 2.52.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/_cjs/errors/version.js +1 -1
  3. package/_cjs/tempo/Abis.js +189 -1
  4. package/_cjs/tempo/Abis.js.map +1 -1
  5. package/_cjs/tempo/Account.js +27 -20
  6. package/_cjs/tempo/Account.js.map +1 -1
  7. package/_cjs/tempo/Addresses.js +3 -1
  8. package/_cjs/tempo/Addresses.js.map +1 -1
  9. package/_cjs/tempo/Decorator.js +23 -0
  10. package/_cjs/tempo/Decorator.js.map +1 -1
  11. package/_cjs/tempo/Hardfork.js +3 -0
  12. package/_cjs/tempo/Hardfork.js.map +1 -1
  13. package/_cjs/tempo/actions/accessKey.js +238 -72
  14. package/_cjs/tempo/actions/accessKey.js.map +1 -1
  15. package/_cjs/tempo/actions/index.js +2 -1
  16. package/_cjs/tempo/actions/index.js.map +1 -1
  17. package/_cjs/tempo/actions/receivePolicy.js +363 -0
  18. package/_cjs/tempo/actions/receivePolicy.js.map +1 -0
  19. package/_cjs/tempo/index.js +2 -1
  20. package/_cjs/tempo/index.js.map +1 -1
  21. package/_esm/errors/version.js +1 -1
  22. package/_esm/tempo/Abis.js +188 -0
  23. package/_esm/tempo/Abis.js.map +1 -1
  24. package/_esm/tempo/Account.js +35 -20
  25. package/_esm/tempo/Account.js.map +1 -1
  26. package/_esm/tempo/Addresses.js +2 -0
  27. package/_esm/tempo/Addresses.js.map +1 -1
  28. package/_esm/tempo/Decorator.js +23 -0
  29. package/_esm/tempo/Decorator.js.map +1 -1
  30. package/_esm/tempo/Hardfork.js +3 -0
  31. package/_esm/tempo/Hardfork.js.map +1 -1
  32. package/_esm/tempo/actions/accessKey.js +562 -128
  33. package/_esm/tempo/actions/accessKey.js.map +1 -1
  34. package/_esm/tempo/actions/index.js +1 -0
  35. package/_esm/tempo/actions/index.js.map +1 -1
  36. package/_esm/tempo/actions/receivePolicy.js +753 -0
  37. package/_esm/tempo/actions/receivePolicy.js.map +1 -0
  38. package/_esm/tempo/index.js +1 -1
  39. package/_esm/tempo/index.js.map +1 -1
  40. package/_types/errors/version.d.ts +1 -1
  41. package/_types/tempo/Abis.d.ts +671 -4
  42. package/_types/tempo/Abis.d.ts.map +1 -1
  43. package/_types/tempo/Account.d.ts +13 -2
  44. package/_types/tempo/Account.d.ts.map +1 -1
  45. package/_types/tempo/Addresses.d.ts +2 -0
  46. package/_types/tempo/Addresses.d.ts.map +1 -1
  47. package/_types/tempo/Decorator.d.ts +501 -0
  48. package/_types/tempo/Decorator.d.ts.map +1 -1
  49. package/_types/tempo/Hardfork.d.ts +1 -1
  50. package/_types/tempo/Hardfork.d.ts.map +1 -1
  51. package/_types/tempo/actions/accessKey.d.ts +1520 -304
  52. package/_types/tempo/actions/accessKey.d.ts.map +1 -1
  53. package/_types/tempo/actions/dex.d.ts +75 -0
  54. package/_types/tempo/actions/dex.d.ts.map +1 -1
  55. package/_types/tempo/actions/index.d.ts +1 -0
  56. package/_types/tempo/actions/index.d.ts.map +1 -1
  57. package/_types/tempo/actions/policy.d.ts +352 -0
  58. package/_types/tempo/actions/policy.d.ts.map +1 -1
  59. package/_types/tempo/actions/receivePolicy.d.ts +1511 -0
  60. package/_types/tempo/actions/receivePolicy.d.ts.map +1 -0
  61. package/_types/tempo/index.d.ts +1 -1
  62. package/_types/tempo/index.d.ts.map +1 -1
  63. package/errors/version.ts +1 -1
  64. package/package.json +2 -2
  65. package/tempo/Abis.ts +189 -0
  66. package/tempo/Account.ts +56 -27
  67. package/tempo/Addresses.ts +2 -0
  68. package/tempo/Decorator.ts +578 -0
  69. package/tempo/Hardfork.ts +3 -0
  70. package/tempo/actions/accessKey.ts +1002 -279
  71. package/tempo/actions/index.ts +1 -0
  72. package/tempo/actions/receivePolicy.ts +1266 -0
  73. package/tempo/index.ts +1 -0
@@ -2,7 +2,10 @@ import type { Address } from 'abitype'
2
2
  import type { KeyAuthorization } from 'ox/tempo'
3
3
  import type { Account } from '../../accounts/types.js'
4
4
  import { parseAccount } from '../../accounts/utils/parseAccount.js'
5
+ import type { ReadContractReturnType } from '../../actions/public/readContract.js'
5
6
  import { readContract } from '../../actions/public/readContract.js'
7
+ import type { WatchContractEventParameters } from '../../actions/public/watchContractEvent.js'
8
+ import { watchContractEvent } from '../../actions/public/watchContractEvent.js'
6
9
  import { sendTransaction } from '../../actions/wallet/sendTransaction.js'
7
10
  import { sendTransactionSync } from '../../actions/wallet/sendTransactionSync.js'
8
11
  import type { WriteContractReturnType } from '../../actions/wallet/writeContract.js'
@@ -12,9 +15,10 @@ import type { Client } from '../../clients/createClient.js'
12
15
  import type { Transport } from '../../clients/transports/createTransport.js'
13
16
  import type { BaseErrorType } from '../../errors/base.js'
14
17
  import type { Chain } from '../../types/chain.js'
15
- import type { GetEventArgs } from '../../types/contract.js'
16
- import type { Log } from '../../types/log.js'
17
- import type { Compute } from '../../types/utils.js'
18
+ import type { ExtractAbiItem, GetEventArgs } from '../../types/contract.js'
19
+ import type { Log, Log as viem_Log } from '../../types/log.js'
20
+ import type { Hex } from '../../types/misc.js'
21
+ import type { Compute, UnionOmit } from '../../types/utils.js'
18
22
  import { parseEventLogs } from '../../utils/abi/parseEventLogs.js'
19
23
  import * as Abis from '../Abis.js'
20
24
  import type { AccessKeyAccount, resolveAccessKey } from '../Account.js'
@@ -92,6 +96,14 @@ export namespace authorize {
92
96
  export type Args = {
93
97
  /** The access key to authorize. */
94
98
  accessKey: resolveAccessKey.Parameters
99
+ /**
100
+ * Whether to authorize the key as an admin key. Admin keys are unrestricted
101
+ * and can manage the account's other access keys; `expiry`, `limits`, and
102
+ * `scopes` are ignored. Requires the T6 hardfork.
103
+ *
104
+ * [TIP-1049](https://tips.sh/1049)
105
+ */
106
+ admin?: boolean | undefined
95
107
  /** The chain ID. */
96
108
  chainId?: number | undefined
97
109
  /** Unix timestamp when the key expires. */
@@ -102,6 +114,17 @@ export namespace authorize {
102
114
  | undefined
103
115
  /** Call scopes restricting which contracts/selectors this key can call. */
104
116
  scopes?: KeyAuthorization.Scope[] | undefined
117
+ /**
118
+ * Optional 32-byte witness bound into the authorization's signing hash.
119
+ *
120
+ * Applications use this to bind a single signature to an arbitrary offchain
121
+ * context (e.g. a server-issued challenge), or as a revocation handle that
122
+ * can be burned onchain (see {@link burnWitness}) to invalidate the
123
+ * authorization before it is submitted.
124
+ *
125
+ * [TIP-1053](https://tips.sh/1053)
126
+ */
127
+ witness?: Hex | undefined
105
128
  }
106
129
 
107
130
  export type ReturnValue = WriteContractReturnType
@@ -121,10 +144,12 @@ export namespace authorize {
121
144
  ): Promise<ReturnType<action>> {
122
145
  const {
123
146
  accessKey,
147
+ admin,
124
148
  chainId = client.chain?.id,
125
149
  expiry,
126
150
  limits,
127
151
  scopes,
152
+ witness,
128
153
  ...rest
129
154
  } = parameters
130
155
  const account_ = rest.account ?? client.account
@@ -134,9 +159,11 @@ export namespace authorize {
134
159
  const keyAuthorization = await signKeyAuthorization(parsed as never, {
135
160
  chainId: BigInt(chainId),
136
161
  key: accessKey,
162
+ admin,
137
163
  expiry,
138
164
  limits,
139
165
  scopes,
166
+ witness,
140
167
  })
141
168
  return (await action(client, {
142
169
  ...rest,
@@ -229,7 +256,14 @@ export namespace authorizeSync {
229
256
  }
230
257
 
231
258
  /**
232
- * Revokes an authorized access key.
259
+ * Burns a key-authorization witness, invalidating any authorization bound to
260
+ * it before it is submitted onchain.
261
+ *
262
+ * Once burned, an `authorizeKey` call carrying the same `witness` will revert.
263
+ * This lets applications issue a signed authorization offchain (see
264
+ * {@link authorize}) while retaining the ability to revoke it.
265
+ *
266
+ * [TIP-1053](https://tips.sh/1053)
233
267
  *
234
268
  * @example
235
269
  * ```ts
@@ -244,8 +278,8 @@ export namespace authorizeSync {
244
278
  * transport: http(),
245
279
  * })
246
280
  *
247
- * const hash = await Actions.accessKey.revoke(client, {
248
- * accessKey: '0x...',
281
+ * const hash = await Actions.accessKey.burnWitness(client, {
282
+ * witness: '0x...',
249
283
  * })
250
284
  * ```
251
285
  *
@@ -253,25 +287,25 @@ export namespace authorizeSync {
253
287
  * @param parameters - Parameters.
254
288
  * @returns The transaction hash.
255
289
  */
256
- export async function revoke<
290
+ export async function burnWitness<
257
291
  chain extends Chain | undefined,
258
292
  account extends Account | undefined,
259
293
  >(
260
294
  client: Client<Transport, chain, account>,
261
- parameters: revoke.Parameters<chain, account>,
262
- ): Promise<revoke.ReturnValue> {
263
- return revoke.inner(writeContract, client, parameters)
295
+ parameters: burnWitness.Parameters<chain, account>,
296
+ ): Promise<burnWitness.ReturnValue> {
297
+ return burnWitness.inner(writeContract, client, parameters)
264
298
  }
265
299
 
266
- export namespace revoke {
300
+ export namespace burnWitness {
267
301
  export type Parameters<
268
302
  chain extends Chain | undefined = Chain | undefined,
269
303
  account extends Account | undefined = Account | undefined,
270
304
  > = WriteParameters<chain, account> & Args
271
305
 
272
306
  export type Args = {
273
- /** The access key to revoke. */
274
- accessKey: Address | AccessKeyAccount
307
+ /** The 32-byte witness to burn. */
308
+ witness: Hex
275
309
  }
276
310
 
277
311
  export type ReturnValue = WriteContractReturnType
@@ -287,10 +321,10 @@ export namespace revoke {
287
321
  >(
288
322
  action: action,
289
323
  client: Client<Transport, chain, account>,
290
- parameters: revoke.Parameters<chain, account>,
324
+ parameters: burnWitness.Parameters<chain, account>,
291
325
  ): Promise<ReturnType<action>> {
292
- const { accessKey, ...rest } = parameters
293
- const call = revoke.call({ accessKey })
326
+ const { witness, ...rest } = parameters
327
+ const call = burnWitness.call({ witness })
294
328
  return (await action(client, {
295
329
  ...rest,
296
330
  ...call,
@@ -298,7 +332,7 @@ export namespace revoke {
298
332
  }
299
333
 
300
334
  /**
301
- * Defines a call to the `revokeKey` function.
335
+ * Defines a call to the `burnKeyAuthorizationWitness` function.
302
336
  *
303
337
  * Can be passed as a parameter to:
304
338
  * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
@@ -318,7 +352,7 @@ export namespace revoke {
318
352
  *
319
353
  * const hash = await client.sendTransaction({
320
354
  * calls: [
321
- * Actions.accessKey.revoke.call({ accessKey: '0x...' }),
355
+ * Actions.accessKey.burnWitness.call({ witness: '0x...' }),
322
356
  * ],
323
357
  * })
324
358
  * ```
@@ -327,12 +361,12 @@ export namespace revoke {
327
361
  * @returns The call.
328
362
  */
329
363
  export function call(args: Args) {
330
- const { accessKey } = args
364
+ const { witness } = args
331
365
  return defineCall({
332
366
  address: Addresses.accountKeychain,
333
367
  abi: Abis.accountKeychain,
334
- functionName: 'revokeKey',
335
- args: [resolveAccessKeyAddress(accessKey)],
368
+ functionName: 'burnKeyAuthorizationWitness',
369
+ args: [witness],
336
370
  })
337
371
  }
338
372
 
@@ -340,16 +374,17 @@ export namespace revoke {
340
374
  const [log] = parseEventLogs({
341
375
  abi: Abis.accountKeychain,
342
376
  logs,
343
- eventName: 'KeyRevoked',
377
+ eventName: 'KeyAuthorizationWitnessBurned',
344
378
  strict: true,
345
379
  })
346
- if (!log) throw new Error('`KeyRevoked` event not found.')
380
+ if (!log)
381
+ throw new Error('`KeyAuthorizationWitnessBurned` event not found.')
347
382
  return log
348
383
  }
349
384
  }
350
385
 
351
386
  /**
352
- * Revokes an authorized access key and waits for the transaction receipt.
387
+ * Burns a key-authorization witness and waits for the transaction receipt.
353
388
  *
354
389
  * @example
355
390
  * ```ts
@@ -364,8 +399,8 @@ export namespace revoke {
364
399
  * transport: http(),
365
400
  * })
366
401
  *
367
- * const result = await Actions.accessKey.revokeSync(client, {
368
- * accessKey: '0x...',
402
+ * const { receipt, ...result } = await Actions.accessKey.burnWitnessSync(client, {
403
+ * witness: '0x...',
369
404
  * })
370
405
  * ```
371
406
  *
@@ -373,37 +408,37 @@ export namespace revoke {
373
408
  * @param parameters - Parameters.
374
409
  * @returns The transaction receipt and event data.
375
410
  */
376
- export async function revokeSync<
411
+ export async function burnWitnessSync<
377
412
  chain extends Chain | undefined,
378
413
  account extends Account | undefined,
379
414
  >(
380
415
  client: Client<Transport, chain, account>,
381
- parameters: revokeSync.Parameters<chain, account>,
382
- ): Promise<revokeSync.ReturnValue> {
416
+ parameters: burnWitnessSync.Parameters<chain, account>,
417
+ ): Promise<burnWitnessSync.ReturnValue> {
383
418
  const { throwOnReceiptRevert = true, ...rest } = parameters
384
- const receipt = await revoke.inner(writeContractSync, client, {
419
+ const receipt = await burnWitness.inner(writeContractSync, client, {
385
420
  ...rest,
386
421
  throwOnReceiptRevert,
387
422
  } as never)
388
- const { args } = revoke.extractEvent(receipt.logs)
423
+ const { args } = burnWitness.extractEvent(receipt.logs)
389
424
  return {
390
425
  ...args,
391
426
  receipt,
392
427
  } as never
393
428
  }
394
429
 
395
- export namespace revokeSync {
430
+ export namespace burnWitnessSync {
396
431
  export type Parameters<
397
432
  chain extends Chain | undefined = Chain | undefined,
398
433
  account extends Account | undefined = Account | undefined,
399
- > = revoke.Parameters<chain, account>
434
+ > = burnWitness.Parameters<chain, account>
400
435
 
401
- export type Args = revoke.Args
436
+ export type Args = burnWitness.Args
402
437
 
403
438
  export type ReturnValue = Compute<
404
439
  GetEventArgs<
405
440
  typeof Abis.accountKeychain,
406
- 'KeyRevoked',
441
+ 'KeyAuthorizationWitnessBurned',
407
442
  { IndexedOnly: false; Required: true }
408
443
  > & {
409
444
  receipt: TransactionReceipt
@@ -414,210 +449,6 @@ export namespace revokeSync {
414
449
  export type ErrorType = BaseErrorType
415
450
  }
416
451
 
417
- /**
418
- * Updates the spending limit for a specific token on an authorized access key.
419
- *
420
- * @example
421
- * ```ts
422
- * import { createClient, http } from 'viem'
423
- * import { tempo } from 'viem/chains'
424
- * import { Actions } from 'viem/tempo'
425
- * import { privateKeyToAccount } from 'viem/accounts'
426
- *
427
- * const client = createClient({
428
- * account: privateKeyToAccount('0x...'),
429
- * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
430
- * transport: http(),
431
- * })
432
- *
433
- * const hash = await Actions.accessKey.updateLimit(client, {
434
- * accessKey: '0x...',
435
- * token: '0x...',
436
- * limit: 1000000000000000000n,
437
- * })
438
- * ```
439
- *
440
- * @param client - Client.
441
- * @param parameters - Parameters.
442
- * @returns The transaction hash.
443
- */
444
- export async function updateLimit<
445
- chain extends Chain | undefined,
446
- account extends Account | undefined,
447
- >(
448
- client: Client<Transport, chain, account>,
449
- parameters: updateLimit.Parameters<chain, account>,
450
- ): Promise<updateLimit.ReturnValue> {
451
- return updateLimit.inner(writeContract, client, parameters)
452
- }
453
-
454
- export namespace updateLimit {
455
- export type Parameters<
456
- chain extends Chain | undefined = Chain | undefined,
457
- account extends Account | undefined = Account | undefined,
458
- > = WriteParameters<chain, account> & Args
459
-
460
- export type Args = {
461
- /** The access key to update. */
462
- accessKey: Address | AccessKeyAccount
463
- /** The token address. */
464
- token: Address
465
- /** The new spending limit. */
466
- limit: bigint
467
- }
468
-
469
- export type ReturnValue = WriteContractReturnType
470
-
471
- // TODO: exhaustive error type
472
- export type ErrorType = BaseErrorType
473
-
474
- /** @internal */
475
- export async function inner<
476
- action extends typeof writeContract | typeof writeContractSync,
477
- chain extends Chain | undefined,
478
- account extends Account | undefined,
479
- >(
480
- action: action,
481
- client: Client<Transport, chain, account>,
482
- parameters: updateLimit.Parameters<chain, account>,
483
- ): Promise<ReturnType<action>> {
484
- const { accessKey, token, limit, ...rest } = parameters
485
- const call = updateLimit.call({ accessKey, token, limit })
486
- return (await action(client, {
487
- ...rest,
488
- ...call,
489
- } as never)) as never
490
- }
491
-
492
- /**
493
- * Defines a call to the `updateSpendingLimit` function.
494
- *
495
- * Can be passed as a parameter to:
496
- * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
497
- * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
498
- * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
499
- *
500
- * @example
501
- * ```ts
502
- * import { createClient, http, walletActions } from 'viem'
503
- * import { tempo } from 'viem/chains'
504
- * import { Actions } from 'viem/tempo'
505
- *
506
- * const client = createClient({
507
- * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
508
- * transport: http(),
509
- * }).extend(walletActions)
510
- *
511
- * const hash = await client.sendTransaction({
512
- * calls: [
513
- * Actions.accessKey.updateLimit.call({
514
- * accessKey: '0x...',
515
- * token: '0x...',
516
- * limit: 1000000000000000000n,
517
- * }),
518
- * ],
519
- * })
520
- * ```
521
- *
522
- * @param args - Arguments.
523
- * @returns The call.
524
- */
525
- export function call(args: Args) {
526
- const { accessKey, token, limit } = args
527
- return defineCall({
528
- address: Addresses.accountKeychain,
529
- abi: Abis.accountKeychain,
530
- functionName: 'updateSpendingLimit',
531
- args: [resolveAccessKeyAddress(accessKey), token, limit],
532
- })
533
- }
534
-
535
- export function extractEvent(logs: Log[]) {
536
- const [log] = parseEventLogs({
537
- abi: Abis.accountKeychain,
538
- logs,
539
- eventName: 'SpendingLimitUpdated',
540
- strict: true,
541
- })
542
- if (!log) throw new Error('`SpendingLimitUpdated` event not found.')
543
- return log
544
- }
545
- }
546
-
547
- /**
548
- * Updates the spending limit and waits for the transaction receipt.
549
- *
550
- * @example
551
- * ```ts
552
- * import { createClient, http } from 'viem'
553
- * import { tempo } from 'viem/chains'
554
- * import { Actions } from 'viem/tempo'
555
- * import { privateKeyToAccount } from 'viem/accounts'
556
- *
557
- * const client = createClient({
558
- * account: privateKeyToAccount('0x...'),
559
- * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
560
- * transport: http(),
561
- * })
562
- *
563
- * const result = await Actions.accessKey.updateLimitSync(client, {
564
- * accessKey: '0x...',
565
- * token: '0x...',
566
- * limit: 1000000000000000000n,
567
- * })
568
- * ```
569
- *
570
- * @param client - Client.
571
- * @param parameters - Parameters.
572
- * @returns The transaction receipt and event data.
573
- */
574
- export async function updateLimitSync<
575
- chain extends Chain | undefined,
576
- account extends Account | undefined,
577
- >(
578
- client: Client<Transport, chain, account>,
579
- parameters: updateLimitSync.Parameters<chain, account>,
580
- ): Promise<updateLimitSync.ReturnValue> {
581
- const { throwOnReceiptRevert = true, ...rest } = parameters
582
- const receipt = await updateLimit.inner(writeContractSync, client, {
583
- ...rest,
584
- throwOnReceiptRevert,
585
- } as never)
586
- const { args } = updateLimit.extractEvent(receipt.logs)
587
- return {
588
- account: args.account,
589
- publicKey: args.publicKey,
590
- token: args.token,
591
- limit: args.newLimit,
592
- receipt,
593
- }
594
- }
595
-
596
- export namespace updateLimitSync {
597
- export type Parameters<
598
- chain extends Chain | undefined = Chain | undefined,
599
- account extends Account | undefined = Account | undefined,
600
- > = updateLimit.Parameters<chain, account>
601
-
602
- export type Args = updateLimit.Args
603
-
604
- export type ReturnValue = {
605
- /** The account that owns the key. */
606
- account: Address
607
- /** The access key address. */
608
- publicKey: Address
609
- /** The token address. */
610
- token: Address
611
- /** The new spending limit. */
612
- limit: bigint
613
- /** The transaction receipt. */
614
- receipt: TransactionReceipt
615
- }
616
-
617
- // TODO: exhaustive error type
618
- export type ErrorType = BaseErrorType
619
- }
620
-
621
452
  /**
622
453
  * Gets access key information.
623
454
  *
@@ -829,70 +660,962 @@ export namespace getRemainingLimit {
829
660
  }
830
661
 
831
662
  /**
832
- * Signs a key authorization for an access key.
663
+ * Checks whether an access key is an admin key for an account.
664
+ *
665
+ * Returns `true` for the account's root key or for an active admin access key
666
+ * (see {@link authorize} with `admin: true`).
667
+ *
668
+ * [TIP-1049](https://tips.sh/1049)
833
669
  *
834
670
  * @example
835
671
  * ```ts
836
- * import { generatePrivateKey } from 'viem/accounts'
837
- * import { Account, Actions } from 'viem/tempo'
672
+ * import { createClient, http } from 'viem'
673
+ * import { tempo } from 'viem/chains'
674
+ * import { Actions } from 'viem/tempo'
838
675
  *
839
- * const account = Account.from({ privateKey: '0x...' })
840
- * const accessKey = Account.fromP256(generatePrivateKey(), {
841
- * access: account,
676
+ * const client = createClient({
677
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
678
+ * transport: http(),
842
679
  * })
843
680
  *
844
- * const keyAuthorization = await Actions.accessKey.signAuthorization(
845
- * client,
846
- * {
847
- * account,
848
- * accessKey,
849
- * expiry: Math.floor((Date.now() + 30_000) / 1000),
850
- * },
851
- * )
681
+ * const isAdmin = await Actions.accessKey.isAdmin(client, {
682
+ * account: '0x...',
683
+ * accessKey: '0x...',
684
+ * })
852
685
  * ```
853
686
  *
854
687
  * @param client - Client.
855
688
  * @param parameters - Parameters.
856
- * @returns The signed key authorization.
689
+ * @returns Whether the access key is an admin key.
857
690
  */
858
- export async function signAuthorization<
691
+ export async function isAdmin<
859
692
  chain extends Chain | undefined,
860
693
  account extends Account | undefined,
861
694
  >(
862
695
  client: Client<Transport, chain, account>,
863
- parameters: signAuthorization.Parameters<account>,
864
- ): Promise<signAuthorization.ReturnValue> {
865
- const { accessKey, chainId = client.chain?.id, ...rest } = parameters
866
- const account_ = rest.account ?? client.account
696
+ parameters: isAdmin.Parameters<account>,
697
+ ): Promise<isAdmin.ReturnValue> {
698
+ const { account: account_ = client.account, accessKey, ...rest } = parameters
867
699
  if (!account_) throw new Error('account is required.')
868
- if (!chainId) throw new Error('chainId is required.')
869
- const parsed = parseAccount(account_)
870
- return signKeyAuthorization(parsed as never, {
871
- chainId: BigInt(chainId),
872
- key: accessKey,
700
+ const account = parseAccount(account_)
701
+ return readContract(client, {
873
702
  ...rest,
703
+ account: null as never,
704
+ ...isAdmin.call({ account: account.address, accessKey }),
874
705
  })
875
706
  }
876
707
 
877
- export namespace signAuthorization {
708
+ export namespace isAdmin {
878
709
  export type Parameters<
879
710
  account extends Account | undefined = Account | undefined,
880
- > = GetAccountParameter<account> & {
881
- /** The access key to authorize. */
882
- accessKey: resolveAccessKey.Parameters
883
- /** The chain ID. */
884
- chainId?: number | undefined
885
- /** Unix timestamp when the key expires. */
886
- expiry?: number | undefined
887
- /** Spending limits per token. */
888
- limits?:
889
- | { token: Address; limit: bigint; period?: number | undefined }[]
890
- | undefined
891
- /** Call scopes restricting which contracts/selectors this key can call. */
892
- scopes?: KeyAuthorization.Scope[] | undefined
711
+ > = ReadParameters & GetAccountParameter<account> & Pick<Args, 'accessKey'>
712
+
713
+ export type Args = {
714
+ /** Account address. */
715
+ account: Address
716
+ /** The access key. */
717
+ accessKey: Address | AccessKeyAccount
893
718
  }
894
719
 
895
- export type ReturnValue = Awaited<ReturnType<typeof signKeyAuthorization>>
720
+ export type ReturnValue = ReadContractReturnType<
721
+ typeof Abis.accountKeychain,
722
+ 'isAdminKey',
723
+ never
724
+ >
725
+
726
+ /**
727
+ * Defines a call to the `isAdminKey` function.
728
+ *
729
+ * @param args - Arguments.
730
+ * @returns The call.
731
+ */
732
+ export function call(args: Args) {
733
+ const { account, accessKey } = args
734
+ return defineCall({
735
+ address: Addresses.accountKeychain,
736
+ abi: Abis.accountKeychain,
737
+ functionName: 'isAdminKey',
738
+ args: [account, resolveAccessKeyAddress(accessKey)],
739
+ })
740
+ }
741
+ }
742
+
743
+ /**
744
+ * Checks whether a key-authorization witness has been burned for an account.
745
+ *
746
+ * @example
747
+ * ```ts
748
+ * import { createClient, http } from 'viem'
749
+ * import { tempo } from 'viem/chains'
750
+ * import { Actions } from 'viem/tempo'
751
+ *
752
+ * const client = createClient({
753
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
754
+ * transport: http(),
755
+ * })
756
+ *
757
+ * const isBurned = await Actions.accessKey.isWitnessBurned(client, {
758
+ * account: '0x...',
759
+ * witness: '0x...',
760
+ * })
761
+ * ```
762
+ *
763
+ * @param client - Client.
764
+ * @param parameters - Parameters.
765
+ * @returns Whether the witness has been burned.
766
+ */
767
+ export async function isWitnessBurned<
768
+ chain extends Chain | undefined,
769
+ account extends Account | undefined,
770
+ >(
771
+ client: Client<Transport, chain, account>,
772
+ parameters: isWitnessBurned.Parameters<account>,
773
+ ): Promise<isWitnessBurned.ReturnValue> {
774
+ const { account: account_ = client.account, witness, ...rest } = parameters
775
+ if (!account_) throw new Error('account is required.')
776
+ const account = parseAccount(account_)
777
+ return readContract(client, {
778
+ ...rest,
779
+ account: null as never,
780
+ ...isWitnessBurned.call({ account: account.address, witness }),
781
+ })
782
+ }
783
+
784
+ export namespace isWitnessBurned {
785
+ export type Parameters<
786
+ account extends Account | undefined = Account | undefined,
787
+ > = ReadParameters & GetAccountParameter<account> & Pick<Args, 'witness'>
788
+
789
+ export type Args = {
790
+ /** Account address. */
791
+ account: Address
792
+ /** The 32-byte witness to check. */
793
+ witness: Hex
794
+ }
795
+
796
+ export type ReturnValue = ReadContractReturnType<
797
+ typeof Abis.accountKeychain,
798
+ 'isKeyAuthorizationWitnessBurned',
799
+ never
800
+ >
801
+
802
+ /**
803
+ * Defines a call to the `isKeyAuthorizationWitnessBurned` function.
804
+ *
805
+ * @param args - Arguments.
806
+ * @returns The call.
807
+ */
808
+ export function call(args: Args) {
809
+ const { account, witness } = args
810
+ return defineCall({
811
+ address: Addresses.accountKeychain,
812
+ abi: Abis.accountKeychain,
813
+ functionName: 'isKeyAuthorizationWitnessBurned',
814
+ args: [account, witness],
815
+ })
816
+ }
817
+ }
818
+
819
+ /**
820
+ * Revokes an authorized access key.
821
+ *
822
+ * @example
823
+ * ```ts
824
+ * import { createClient, http } from 'viem'
825
+ * import { tempo } from 'viem/chains'
826
+ * import { Actions } from 'viem/tempo'
827
+ * import { privateKeyToAccount } from 'viem/accounts'
828
+ *
829
+ * const client = createClient({
830
+ * account: privateKeyToAccount('0x...'),
831
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
832
+ * transport: http(),
833
+ * })
834
+ *
835
+ * const hash = await Actions.accessKey.revoke(client, {
836
+ * accessKey: '0x...',
837
+ * })
838
+ * ```
839
+ *
840
+ * @param client - Client.
841
+ * @param parameters - Parameters.
842
+ * @returns The transaction hash.
843
+ */
844
+ export async function revoke<
845
+ chain extends Chain | undefined,
846
+ account extends Account | undefined,
847
+ >(
848
+ client: Client<Transport, chain, account>,
849
+ parameters: revoke.Parameters<chain, account>,
850
+ ): Promise<revoke.ReturnValue> {
851
+ return revoke.inner(writeContract, client, parameters)
852
+ }
853
+
854
+ export namespace revoke {
855
+ export type Parameters<
856
+ chain extends Chain | undefined = Chain | undefined,
857
+ account extends Account | undefined = Account | undefined,
858
+ > = WriteParameters<chain, account> & Args
859
+
860
+ export type Args = {
861
+ /** The access key to revoke. */
862
+ accessKey: Address | AccessKeyAccount
863
+ }
864
+
865
+ export type ReturnValue = WriteContractReturnType
866
+
867
+ // TODO: exhaustive error type
868
+ export type ErrorType = BaseErrorType
869
+
870
+ /** @internal */
871
+ export async function inner<
872
+ action extends typeof writeContract | typeof writeContractSync,
873
+ chain extends Chain | undefined,
874
+ account extends Account | undefined,
875
+ >(
876
+ action: action,
877
+ client: Client<Transport, chain, account>,
878
+ parameters: revoke.Parameters<chain, account>,
879
+ ): Promise<ReturnType<action>> {
880
+ const { accessKey, ...rest } = parameters
881
+ const call = revoke.call({ accessKey })
882
+ return (await action(client, {
883
+ ...rest,
884
+ ...call,
885
+ } as never)) as never
886
+ }
887
+
888
+ /**
889
+ * Defines a call to the `revokeKey` function.
890
+ *
891
+ * Can be passed as a parameter to:
892
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
893
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
894
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
895
+ *
896
+ * @example
897
+ * ```ts
898
+ * import { createClient, http, walletActions } from 'viem'
899
+ * import { tempo } from 'viem/chains'
900
+ * import { Actions } from 'viem/tempo'
901
+ *
902
+ * const client = createClient({
903
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
904
+ * transport: http(),
905
+ * }).extend(walletActions)
906
+ *
907
+ * const hash = await client.sendTransaction({
908
+ * calls: [
909
+ * Actions.accessKey.revoke.call({ accessKey: '0x...' }),
910
+ * ],
911
+ * })
912
+ * ```
913
+ *
914
+ * @param args - Arguments.
915
+ * @returns The call.
916
+ */
917
+ export function call(args: Args) {
918
+ const { accessKey } = args
919
+ return defineCall({
920
+ address: Addresses.accountKeychain,
921
+ abi: Abis.accountKeychain,
922
+ functionName: 'revokeKey',
923
+ args: [resolveAccessKeyAddress(accessKey)],
924
+ })
925
+ }
926
+
927
+ export function extractEvent(logs: Log[]) {
928
+ const [log] = parseEventLogs({
929
+ abi: Abis.accountKeychain,
930
+ logs,
931
+ eventName: 'KeyRevoked',
932
+ strict: true,
933
+ })
934
+ if (!log) throw new Error('`KeyRevoked` event not found.')
935
+ return log
936
+ }
937
+ }
938
+
939
+ /**
940
+ * Revokes an authorized access key and waits for the transaction receipt.
941
+ *
942
+ * @example
943
+ * ```ts
944
+ * import { createClient, http } from 'viem'
945
+ * import { tempo } from 'viem/chains'
946
+ * import { Actions } from 'viem/tempo'
947
+ * import { privateKeyToAccount } from 'viem/accounts'
948
+ *
949
+ * const client = createClient({
950
+ * account: privateKeyToAccount('0x...'),
951
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
952
+ * transport: http(),
953
+ * })
954
+ *
955
+ * const result = await Actions.accessKey.revokeSync(client, {
956
+ * accessKey: '0x...',
957
+ * })
958
+ * ```
959
+ *
960
+ * @param client - Client.
961
+ * @param parameters - Parameters.
962
+ * @returns The transaction receipt and event data.
963
+ */
964
+ export async function revokeSync<
965
+ chain extends Chain | undefined,
966
+ account extends Account | undefined,
967
+ >(
968
+ client: Client<Transport, chain, account>,
969
+ parameters: revokeSync.Parameters<chain, account>,
970
+ ): Promise<revokeSync.ReturnValue> {
971
+ const { throwOnReceiptRevert = true, ...rest } = parameters
972
+ const receipt = await revoke.inner(writeContractSync, client, {
973
+ ...rest,
974
+ throwOnReceiptRevert,
975
+ } as never)
976
+ const { args } = revoke.extractEvent(receipt.logs)
977
+ return {
978
+ ...args,
979
+ receipt,
980
+ } as never
981
+ }
982
+
983
+ export namespace revokeSync {
984
+ export type Parameters<
985
+ chain extends Chain | undefined = Chain | undefined,
986
+ account extends Account | undefined = Account | undefined,
987
+ > = revoke.Parameters<chain, account>
988
+
989
+ export type Args = revoke.Args
990
+
991
+ export type ReturnValue = Compute<
992
+ GetEventArgs<
993
+ typeof Abis.accountKeychain,
994
+ 'KeyRevoked',
995
+ { IndexedOnly: false; Required: true }
996
+ > & {
997
+ receipt: TransactionReceipt
998
+ }
999
+ >
1000
+
1001
+ // TODO: exhaustive error type
1002
+ export type ErrorType = BaseErrorType
1003
+ }
1004
+
1005
+ /**
1006
+ * Signs a key authorization for an access key.
1007
+ *
1008
+ * @example
1009
+ * ```ts
1010
+ * import { generatePrivateKey } from 'viem/accounts'
1011
+ * import { Account, Actions } from 'viem/tempo'
1012
+ *
1013
+ * const account = Account.from({ privateKey: '0x...' })
1014
+ * const accessKey = Account.fromP256(generatePrivateKey(), {
1015
+ * access: account,
1016
+ * })
1017
+ *
1018
+ * const keyAuthorization = await Actions.accessKey.signAuthorization(
1019
+ * client,
1020
+ * {
1021
+ * account,
1022
+ * accessKey,
1023
+ * expiry: Math.floor((Date.now() + 30_000) / 1000),
1024
+ * },
1025
+ * )
1026
+ * ```
1027
+ *
1028
+ * @param client - Client.
1029
+ * @param parameters - Parameters.
1030
+ * @returns The signed key authorization.
1031
+ */
1032
+ export async function signAuthorization<
1033
+ chain extends Chain | undefined,
1034
+ account extends Account | undefined,
1035
+ >(
1036
+ client: Client<Transport, chain, account>,
1037
+ parameters: signAuthorization.Parameters<account>,
1038
+ ): Promise<signAuthorization.ReturnValue> {
1039
+ const { accessKey, chainId = client.chain?.id, ...rest } = parameters
1040
+ const account_ = rest.account ?? client.account
1041
+ if (!account_) throw new Error('account is required.')
1042
+ if (!chainId) throw new Error('chainId is required.')
1043
+ const parsed = parseAccount(account_)
1044
+ return signKeyAuthorization(parsed as never, {
1045
+ chainId: BigInt(chainId),
1046
+ key: accessKey,
1047
+ ...rest,
1048
+ })
1049
+ }
1050
+
1051
+ export namespace signAuthorization {
1052
+ export type Parameters<
1053
+ account extends Account | undefined = Account | undefined,
1054
+ > = GetAccountParameter<account> & {
1055
+ /** The access key to authorize. */
1056
+ accessKey: resolveAccessKey.Parameters
1057
+ /**
1058
+ * Whether to authorize the key as an admin key. Admin keys are unrestricted
1059
+ * and can manage the account's other access keys; `expiry`, `limits`, and
1060
+ * `scopes` are ignored. Requires the T6 hardfork.
1061
+ *
1062
+ * [TIP-1049](https://tips.sh/1049)
1063
+ */
1064
+ admin?: boolean | undefined
1065
+ /** The chain ID. */
1066
+ chainId?: number | undefined
1067
+ /** Unix timestamp when the key expires. */
1068
+ expiry?: number | undefined
1069
+ /** Spending limits per token. */
1070
+ limits?:
1071
+ | { token: Address; limit: bigint; period?: number | undefined }[]
1072
+ | undefined
1073
+ /** Call scopes restricting which contracts/selectors this key can call. */
1074
+ scopes?: KeyAuthorization.Scope[] | undefined
1075
+ /**
1076
+ * Optional 32-byte witness bound into the authorization's signing hash.
1077
+ *
1078
+ * Applications use this to bind a single signature to an arbitrary offchain
1079
+ * context (e.g. a server-issued challenge), or as a revocation handle that
1080
+ * can be burned onchain (see {@link burnWitness}) to invalidate the
1081
+ * authorization before it is submitted.
1082
+ *
1083
+ * [TIP-1053](https://tips.sh/1053)
1084
+ */
1085
+ witness?: Hex | undefined
1086
+ }
1087
+
1088
+ export type ReturnValue = Awaited<ReturnType<typeof signKeyAuthorization>>
1089
+ }
1090
+
1091
+ /**
1092
+ * Updates the spending limit for a specific token on an authorized access key.
1093
+ *
1094
+ * @example
1095
+ * ```ts
1096
+ * import { createClient, http } from 'viem'
1097
+ * import { tempo } from 'viem/chains'
1098
+ * import { Actions } from 'viem/tempo'
1099
+ * import { privateKeyToAccount } from 'viem/accounts'
1100
+ *
1101
+ * const client = createClient({
1102
+ * account: privateKeyToAccount('0x...'),
1103
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1104
+ * transport: http(),
1105
+ * })
1106
+ *
1107
+ * const hash = await Actions.accessKey.updateLimit(client, {
1108
+ * accessKey: '0x...',
1109
+ * token: '0x...',
1110
+ * limit: 1000000000000000000n,
1111
+ * })
1112
+ * ```
1113
+ *
1114
+ * @param client - Client.
1115
+ * @param parameters - Parameters.
1116
+ * @returns The transaction hash.
1117
+ */
1118
+ export async function updateLimit<
1119
+ chain extends Chain | undefined,
1120
+ account extends Account | undefined,
1121
+ >(
1122
+ client: Client<Transport, chain, account>,
1123
+ parameters: updateLimit.Parameters<chain, account>,
1124
+ ): Promise<updateLimit.ReturnValue> {
1125
+ return updateLimit.inner(writeContract, client, parameters)
1126
+ }
1127
+
1128
+ export namespace updateLimit {
1129
+ export type Parameters<
1130
+ chain extends Chain | undefined = Chain | undefined,
1131
+ account extends Account | undefined = Account | undefined,
1132
+ > = WriteParameters<chain, account> & Args
1133
+
1134
+ export type Args = {
1135
+ /** The access key to update. */
1136
+ accessKey: Address | AccessKeyAccount
1137
+ /** The token address. */
1138
+ token: Address
1139
+ /** The new spending limit. */
1140
+ limit: bigint
1141
+ }
1142
+
1143
+ export type ReturnValue = WriteContractReturnType
1144
+
1145
+ // TODO: exhaustive error type
1146
+ export type ErrorType = BaseErrorType
1147
+
1148
+ /** @internal */
1149
+ export async function inner<
1150
+ action extends typeof writeContract | typeof writeContractSync,
1151
+ chain extends Chain | undefined,
1152
+ account extends Account | undefined,
1153
+ >(
1154
+ action: action,
1155
+ client: Client<Transport, chain, account>,
1156
+ parameters: updateLimit.Parameters<chain, account>,
1157
+ ): Promise<ReturnType<action>> {
1158
+ const { accessKey, token, limit, ...rest } = parameters
1159
+ const call = updateLimit.call({ accessKey, token, limit })
1160
+ return (await action(client, {
1161
+ ...rest,
1162
+ ...call,
1163
+ } as never)) as never
1164
+ }
1165
+
1166
+ /**
1167
+ * Defines a call to the `updateSpendingLimit` function.
1168
+ *
1169
+ * Can be passed as a parameter to:
1170
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
1171
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
1172
+ * - [`sendCalls`](https://viem.sh/docs/actions/wallet/sendCalls): send multiple calls
1173
+ *
1174
+ * @example
1175
+ * ```ts
1176
+ * import { createClient, http, walletActions } from 'viem'
1177
+ * import { tempo } from 'viem/chains'
1178
+ * import { Actions } from 'viem/tempo'
1179
+ *
1180
+ * const client = createClient({
1181
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1182
+ * transport: http(),
1183
+ * }).extend(walletActions)
1184
+ *
1185
+ * const hash = await client.sendTransaction({
1186
+ * calls: [
1187
+ * Actions.accessKey.updateLimit.call({
1188
+ * accessKey: '0x...',
1189
+ * token: '0x...',
1190
+ * limit: 1000000000000000000n,
1191
+ * }),
1192
+ * ],
1193
+ * })
1194
+ * ```
1195
+ *
1196
+ * @param args - Arguments.
1197
+ * @returns The call.
1198
+ */
1199
+ export function call(args: Args) {
1200
+ const { accessKey, token, limit } = args
1201
+ return defineCall({
1202
+ address: Addresses.accountKeychain,
1203
+ abi: Abis.accountKeychain,
1204
+ functionName: 'updateSpendingLimit',
1205
+ args: [resolveAccessKeyAddress(accessKey), token, limit],
1206
+ })
1207
+ }
1208
+
1209
+ export function extractEvent(logs: Log[]) {
1210
+ const [log] = parseEventLogs({
1211
+ abi: Abis.accountKeychain,
1212
+ logs,
1213
+ eventName: 'SpendingLimitUpdated',
1214
+ strict: true,
1215
+ })
1216
+ if (!log) throw new Error('`SpendingLimitUpdated` event not found.')
1217
+ return log
1218
+ }
1219
+ }
1220
+
1221
+ /**
1222
+ * Updates the spending limit and waits for the transaction receipt.
1223
+ *
1224
+ * @example
1225
+ * ```ts
1226
+ * import { createClient, http } from 'viem'
1227
+ * import { tempo } from 'viem/chains'
1228
+ * import { Actions } from 'viem/tempo'
1229
+ * import { privateKeyToAccount } from 'viem/accounts'
1230
+ *
1231
+ * const client = createClient({
1232
+ * account: privateKeyToAccount('0x...'),
1233
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1234
+ * transport: http(),
1235
+ * })
1236
+ *
1237
+ * const result = await Actions.accessKey.updateLimitSync(client, {
1238
+ * accessKey: '0x...',
1239
+ * token: '0x...',
1240
+ * limit: 1000000000000000000n,
1241
+ * })
1242
+ * ```
1243
+ *
1244
+ * @param client - Client.
1245
+ * @param parameters - Parameters.
1246
+ * @returns The transaction receipt and event data.
1247
+ */
1248
+ export async function updateLimitSync<
1249
+ chain extends Chain | undefined,
1250
+ account extends Account | undefined,
1251
+ >(
1252
+ client: Client<Transport, chain, account>,
1253
+ parameters: updateLimitSync.Parameters<chain, account>,
1254
+ ): Promise<updateLimitSync.ReturnValue> {
1255
+ const { throwOnReceiptRevert = true, ...rest } = parameters
1256
+ const receipt = await updateLimit.inner(writeContractSync, client, {
1257
+ ...rest,
1258
+ throwOnReceiptRevert,
1259
+ } as never)
1260
+ const { args } = updateLimit.extractEvent(receipt.logs)
1261
+ return {
1262
+ account: args.account,
1263
+ publicKey: args.publicKey,
1264
+ token: args.token,
1265
+ limit: args.newLimit,
1266
+ receipt,
1267
+ }
1268
+ }
1269
+
1270
+ export namespace updateLimitSync {
1271
+ export type Parameters<
1272
+ chain extends Chain | undefined = Chain | undefined,
1273
+ account extends Account | undefined = Account | undefined,
1274
+ > = updateLimit.Parameters<chain, account>
1275
+
1276
+ export type Args = updateLimit.Args
1277
+
1278
+ export type ReturnValue = {
1279
+ /** The account that owns the key. */
1280
+ account: Address
1281
+ /** The access key address. */
1282
+ publicKey: Address
1283
+ /** The token address. */
1284
+ token: Address
1285
+ /** The new spending limit. */
1286
+ limit: bigint
1287
+ /** The transaction receipt. */
1288
+ receipt: TransactionReceipt
1289
+ }
1290
+
1291
+ // TODO: exhaustive error type
1292
+ export type ErrorType = BaseErrorType
1293
+ }
1294
+
1295
+ /**
1296
+ * Watches for admin key authorization events.
1297
+ *
1298
+ * Emitted when an admin key is authorized (see {@link authorize} with
1299
+ * `admin: true`).
1300
+ *
1301
+ * [TIP-1049](https://tips.sh/1049)
1302
+ *
1303
+ * @example
1304
+ * ```ts
1305
+ * import { createClient, http } from 'viem'
1306
+ * import { tempo } from 'viem/chains'
1307
+ * import { Actions } from 'viem/tempo'
1308
+ *
1309
+ * const client = createClient({
1310
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1311
+ * transport: http(),
1312
+ * })
1313
+ *
1314
+ * const unwatch = Actions.accessKey.watchAdminAuthorized(client, {
1315
+ * onAuthorized: (args, log) => {
1316
+ * console.log('Admin key authorized:', args)
1317
+ * },
1318
+ * })
1319
+ * ```
1320
+ *
1321
+ * @param client - Client.
1322
+ * @param parameters - Parameters.
1323
+ * @returns A function to unsubscribe from the event.
1324
+ */
1325
+ export function watchAdminAuthorized<
1326
+ chain extends Chain | undefined,
1327
+ account extends Account | undefined,
1328
+ >(
1329
+ client: Client<Transport, chain, account>,
1330
+ parameters: watchAdminAuthorized.Parameters,
1331
+ ) {
1332
+ const { onAuthorized, ...rest } = parameters
1333
+ return watchContractEvent(client, {
1334
+ ...rest,
1335
+ address: Addresses.accountKeychain,
1336
+ abi: Abis.accountKeychain,
1337
+ eventName: 'AdminKeyAuthorized',
1338
+ onLogs: (logs) => {
1339
+ for (const log of logs) onAuthorized(log.args, log)
1340
+ },
1341
+ strict: true,
1342
+ })
1343
+ }
1344
+
1345
+ export declare namespace watchAdminAuthorized {
1346
+ export type Args = Compute<
1347
+ GetEventArgs<
1348
+ typeof Abis.accountKeychain,
1349
+ 'AdminKeyAuthorized',
1350
+ { IndexedOnly: false; Required: true }
1351
+ >
1352
+ >
1353
+
1354
+ export type Log = viem_Log<
1355
+ bigint,
1356
+ number,
1357
+ false,
1358
+ ExtractAbiItem<typeof Abis.accountKeychain, 'AdminKeyAuthorized'>,
1359
+ true
1360
+ >
1361
+
1362
+ export type Parameters = UnionOmit<
1363
+ WatchContractEventParameters<
1364
+ typeof Abis.accountKeychain,
1365
+ 'AdminKeyAuthorized',
1366
+ true
1367
+ >,
1368
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1369
+ > & {
1370
+ /** Callback to invoke when an admin key is authorized. */
1371
+ onAuthorized: (args: Args, log: Log) => void
1372
+ }
1373
+ }
1374
+
1375
+ /**
1376
+ * Watches for key-authorization witness events.
1377
+ *
1378
+ * Emitted when a key is authorized with a `witness` (see {@link authorize}).
1379
+ *
1380
+ * @example
1381
+ * ```ts
1382
+ * import { createClient, http } from 'viem'
1383
+ * import { tempo } from 'viem/chains'
1384
+ * import { Actions } from 'viem/tempo'
1385
+ *
1386
+ * const client = createClient({
1387
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1388
+ * transport: http(),
1389
+ * })
1390
+ *
1391
+ * const unwatch = Actions.accessKey.watchWitness(client, {
1392
+ * onWitness: (args, log) => {
1393
+ * console.log('Witness used:', args)
1394
+ * },
1395
+ * })
1396
+ * ```
1397
+ *
1398
+ * @param client - Client.
1399
+ * @param parameters - Parameters.
1400
+ * @returns A function to unsubscribe from the event.
1401
+ */
1402
+ export function watchWitness<
1403
+ chain extends Chain | undefined,
1404
+ account extends Account | undefined,
1405
+ >(
1406
+ client: Client<Transport, chain, account>,
1407
+ parameters: watchWitness.Parameters,
1408
+ ) {
1409
+ const { onWitness, ...rest } = parameters
1410
+ return watchContractEvent(client, {
1411
+ ...rest,
1412
+ address: Addresses.accountKeychain,
1413
+ abi: Abis.accountKeychain,
1414
+ eventName: 'KeyAuthorizationWitness',
1415
+ onLogs: (logs) => {
1416
+ for (const log of logs) onWitness(log.args, log)
1417
+ },
1418
+ strict: true,
1419
+ })
1420
+ }
1421
+
1422
+ export declare namespace watchWitness {
1423
+ export type Args = Compute<
1424
+ GetEventArgs<
1425
+ typeof Abis.accountKeychain,
1426
+ 'KeyAuthorizationWitness',
1427
+ { IndexedOnly: false; Required: true }
1428
+ >
1429
+ >
1430
+
1431
+ export type Log = viem_Log<
1432
+ bigint,
1433
+ number,
1434
+ false,
1435
+ ExtractAbiItem<typeof Abis.accountKeychain, 'KeyAuthorizationWitness'>,
1436
+ true
1437
+ >
1438
+
1439
+ export type Parameters = UnionOmit<
1440
+ WatchContractEventParameters<
1441
+ typeof Abis.accountKeychain,
1442
+ 'KeyAuthorizationWitness',
1443
+ true
1444
+ >,
1445
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1446
+ > & {
1447
+ /** Callback to invoke when a witness is used. */
1448
+ onWitness: (args: Args, log: Log) => void
1449
+ }
1450
+ }
1451
+
1452
+ /**
1453
+ * Watches for key-authorization witness burned events.
1454
+ *
1455
+ * Emitted when a witness is burned (see {@link burnWitness}).
1456
+ *
1457
+ * @example
1458
+ * ```ts
1459
+ * import { createClient, http } from 'viem'
1460
+ * import { tempo } from 'viem/chains'
1461
+ * import { Actions } from 'viem/tempo'
1462
+ *
1463
+ * const client = createClient({
1464
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1465
+ * transport: http(),
1466
+ * })
1467
+ *
1468
+ * const unwatch = Actions.accessKey.watchWitnessBurned(client, {
1469
+ * onBurned: (args, log) => {
1470
+ * console.log('Witness burned:', args)
1471
+ * },
1472
+ * })
1473
+ * ```
1474
+ *
1475
+ * @param client - Client.
1476
+ * @param parameters - Parameters.
1477
+ * @returns A function to unsubscribe from the event.
1478
+ */
1479
+ export function watchWitnessBurned<
1480
+ chain extends Chain | undefined,
1481
+ account extends Account | undefined,
1482
+ >(
1483
+ client: Client<Transport, chain, account>,
1484
+ parameters: watchWitnessBurned.Parameters,
1485
+ ) {
1486
+ const { onBurned, ...rest } = parameters
1487
+ return watchContractEvent(client, {
1488
+ ...rest,
1489
+ address: Addresses.accountKeychain,
1490
+ abi: Abis.accountKeychain,
1491
+ eventName: 'KeyAuthorizationWitnessBurned',
1492
+ onLogs: (logs) => {
1493
+ for (const log of logs) onBurned(log.args, log)
1494
+ },
1495
+ strict: true,
1496
+ })
1497
+ }
1498
+
1499
+ export declare namespace watchWitnessBurned {
1500
+ export type Args = Compute<
1501
+ GetEventArgs<
1502
+ typeof Abis.accountKeychain,
1503
+ 'KeyAuthorizationWitnessBurned',
1504
+ { IndexedOnly: false; Required: true }
1505
+ >
1506
+ >
1507
+
1508
+ export type Log = viem_Log<
1509
+ bigint,
1510
+ number,
1511
+ false,
1512
+ ExtractAbiItem<
1513
+ typeof Abis.accountKeychain,
1514
+ 'KeyAuthorizationWitnessBurned'
1515
+ >,
1516
+ true
1517
+ >
1518
+
1519
+ export type Parameters = UnionOmit<
1520
+ WatchContractEventParameters<
1521
+ typeof Abis.accountKeychain,
1522
+ 'KeyAuthorizationWitnessBurned',
1523
+ true
1524
+ >,
1525
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
1526
+ > & {
1527
+ /** Callback to invoke when a witness is burned. */
1528
+ onBurned: (args: Args, log: Log) => void
1529
+ }
1530
+ }
1531
+
1532
+ /**
1533
+ * Verifies that a keychain signature was produced by an active access key
1534
+ * for the expected account.
1535
+ *
1536
+ * By default (`admin: true`), returns `true` only if the signature was
1537
+ * produced by the account's root key or an active admin access key. Set
1538
+ * `admin: false` to accept any active access key.
1539
+ *
1540
+ * Returns `false` for account mismatches, unknown, revoked, or expired
1541
+ * access keys. [TIP-1049](https://tips.sh/1049)
1542
+ *
1543
+ * @example
1544
+ * ```ts
1545
+ * import { createClient, http } from 'viem'
1546
+ * import { tempo } from 'viem/chains'
1547
+ * import { Actions } from 'viem/tempo'
1548
+ *
1549
+ * const client = createClient({
1550
+ * chain: tempo.extend({ feeToken: '0x20c0000000000000000000000000000000000001' }),
1551
+ * transport: http(),
1552
+ * })
1553
+ *
1554
+ * const valid = await Actions.accessKey.verifyHash(client, {
1555
+ * account: '0x...',
1556
+ * hash: '0x...',
1557
+ * signature: '0x...',
1558
+ * })
1559
+ * ```
1560
+ *
1561
+ * @param client - Client.
1562
+ * @param parameters - Parameters.
1563
+ * @returns Whether the keychain signature is valid for the account.
1564
+ */
1565
+ export async function verifyHash<
1566
+ chain extends Chain | undefined,
1567
+ account extends Account | undefined,
1568
+ >(
1569
+ client: Client<Transport, chain, account>,
1570
+ parameters: verifyHash.Parameters,
1571
+ ): Promise<verifyHash.ReturnValue> {
1572
+ const { account, admin, hash, signature, ...rest } = parameters
1573
+ return readContract(client, {
1574
+ ...rest,
1575
+ ...verifyHash.call({ account, admin, hash, signature }),
1576
+ })
1577
+ }
1578
+
1579
+ export namespace verifyHash {
1580
+ export type Parameters = ReadParameters & Args
1581
+
1582
+ export type Args = {
1583
+ /** Account address the signature is expected to belong to. */
1584
+ account: Address
1585
+ /**
1586
+ * Whether to require the signer to be the account's root key or an
1587
+ * active admin access key. Defaults to `true`. Set to `false` to accept
1588
+ * any active access key.
1589
+ */
1590
+ admin?: boolean | undefined
1591
+ /** Original message hash that was signed. */
1592
+ hash: Hex
1593
+ /** Keychain signature envelope (V2). */
1594
+ signature: Hex
1595
+ }
1596
+
1597
+ export type ReturnValue = ReadContractReturnType<
1598
+ typeof Abis.signatureVerifier,
1599
+ 'verifyKeychain' | 'verifyKeychainAdmin',
1600
+ never
1601
+ >
1602
+
1603
+ /**
1604
+ * Defines a call to `verifyKeychain` or `verifyKeychainAdmin` on the
1605
+ * Signature Verifier precompile (controlled by `admin`).
1606
+ *
1607
+ * @param args - Arguments.
1608
+ * @returns The call.
1609
+ */
1610
+ export function call(args: Args) {
1611
+ const { account, admin = true, hash, signature } = args
1612
+ return defineCall({
1613
+ address: Addresses.signatureVerifier,
1614
+ abi: Abis.signatureVerifier,
1615
+ functionName: admin ? 'verifyKeychainAdmin' : 'verifyKeychain',
1616
+ args: [account, hash, signature],
1617
+ })
1618
+ }
896
1619
  }
897
1620
 
898
1621
  /** @internal */