viem 2.47.6 → 2.47.11

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 (210) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/_cjs/actions/wallet/prepareTransactionRequest.js +12 -0
  3. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  4. package/_cjs/actions/wallet/waitForCallsStatus.js.map +1 -1
  5. package/_cjs/chains/definitions/battlechainTestnet.js +26 -0
  6. package/_cjs/chains/definitions/battlechainTestnet.js.map +1 -0
  7. package/_cjs/chains/definitions/eden.js +32 -0
  8. package/_cjs/chains/definitions/eden.js.map +1 -0
  9. package/_cjs/chains/definitions/fluent.js +26 -0
  10. package/_cjs/chains/definitions/fluent.js.map +1 -0
  11. package/_cjs/chains/definitions/gensyn.js +29 -0
  12. package/_cjs/chains/definitions/gensyn.js.map +1 -0
  13. package/_cjs/chains/definitions/igra.js +26 -0
  14. package/_cjs/chains/definitions/igra.js.map +1 -0
  15. package/_cjs/chains/definitions/katana.js +6 -0
  16. package/_cjs/chains/definitions/katana.js.map +1 -1
  17. package/_cjs/chains/definitions/megaeth.js +25 -3
  18. package/_cjs/chains/definitions/megaeth.js.map +1 -1
  19. package/_cjs/chains/definitions/mezo.js +23 -0
  20. package/_cjs/chains/definitions/mezo.js.map +1 -0
  21. package/_cjs/chains/definitions/mezoTestnet.js +30 -0
  22. package/_cjs/chains/definitions/mezoTestnet.js.map +1 -0
  23. package/_cjs/chains/definitions/radius.js +22 -0
  24. package/_cjs/chains/definitions/radius.js.map +1 -0
  25. package/_cjs/chains/definitions/radiusTestnet.js +22 -0
  26. package/_cjs/chains/definitions/radiusTestnet.js.map +1 -0
  27. package/_cjs/chains/definitions/tempoDevnet.js +1 -0
  28. package/_cjs/chains/definitions/tempoDevnet.js.map +1 -1
  29. package/_cjs/chains/definitions/tempoLocalnet.js +1 -0
  30. package/_cjs/chains/definitions/tempoLocalnet.js.map +1 -1
  31. package/_cjs/chains/definitions/tempoModerato.js +1 -1
  32. package/_cjs/chains/definitions/tempoModerato.js.map +1 -1
  33. package/_cjs/chains/index.js +34 -17
  34. package/_cjs/chains/index.js.map +1 -1
  35. package/_cjs/errors/version.js +1 -1
  36. package/_cjs/errors/version.js.map +1 -1
  37. package/_cjs/tempo/Abis.js +701 -4
  38. package/_cjs/tempo/Abis.js.map +1 -1
  39. package/_cjs/tempo/Account.js +7 -5
  40. package/_cjs/tempo/Account.js.map +1 -1
  41. package/_cjs/tempo/Hardfork.js +18 -0
  42. package/_cjs/tempo/Hardfork.js.map +1 -0
  43. package/_cjs/tempo/Transaction.js +1 -0
  44. package/_cjs/tempo/Transaction.js.map +1 -1
  45. package/_cjs/tempo/actions/accessKey.js +28 -3
  46. package/_cjs/tempo/actions/accessKey.js.map +1 -1
  47. package/_cjs/tempo/actions/token.js +2 -1
  48. package/_cjs/tempo/actions/token.js.map +1 -1
  49. package/_cjs/tempo/actions/validator.js +11 -11
  50. package/_cjs/tempo/actions/validator.js.map +1 -1
  51. package/_cjs/tempo/chainConfig.js +44 -8
  52. package/_cjs/tempo/chainConfig.js.map +1 -1
  53. package/_cjs/tempo/index.js +3 -1
  54. package/_cjs/tempo/index.js.map +1 -1
  55. package/_cjs/utils/buildRequest.js +2 -0
  56. package/_cjs/utils/buildRequest.js.map +1 -1
  57. package/_esm/actions/wallet/prepareTransactionRequest.js +12 -0
  58. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  59. package/_esm/actions/wallet/waitForCallsStatus.js.map +1 -1
  60. package/_esm/chains/definitions/battlechainTestnet.js +23 -0
  61. package/_esm/chains/definitions/battlechainTestnet.js.map +1 -0
  62. package/_esm/chains/definitions/eden.js +29 -0
  63. package/_esm/chains/definitions/eden.js.map +1 -0
  64. package/_esm/chains/definitions/fluent.js +23 -0
  65. package/_esm/chains/definitions/fluent.js.map +1 -0
  66. package/_esm/chains/definitions/gensyn.js +26 -0
  67. package/_esm/chains/definitions/gensyn.js.map +1 -0
  68. package/_esm/chains/definitions/igra.js +23 -0
  69. package/_esm/chains/definitions/igra.js.map +1 -0
  70. package/_esm/chains/definitions/katana.js +6 -0
  71. package/_esm/chains/definitions/katana.js.map +1 -1
  72. package/_esm/chains/definitions/megaeth.js +25 -3
  73. package/_esm/chains/definitions/megaeth.js.map +1 -1
  74. package/_esm/chains/definitions/mezo.js +20 -0
  75. package/_esm/chains/definitions/mezo.js.map +1 -0
  76. package/_esm/chains/definitions/mezoTestnet.js +27 -0
  77. package/_esm/chains/definitions/mezoTestnet.js.map +1 -0
  78. package/_esm/chains/definitions/radius.js +19 -0
  79. package/_esm/chains/definitions/radius.js.map +1 -0
  80. package/_esm/chains/definitions/radiusTestnet.js +19 -0
  81. package/_esm/chains/definitions/radiusTestnet.js.map +1 -0
  82. package/_esm/chains/definitions/tempoDevnet.js +1 -0
  83. package/_esm/chains/definitions/tempoDevnet.js.map +1 -1
  84. package/_esm/chains/definitions/tempoLocalnet.js +1 -0
  85. package/_esm/chains/definitions/tempoLocalnet.js.map +1 -1
  86. package/_esm/chains/definitions/tempoModerato.js +1 -1
  87. package/_esm/chains/definitions/tempoModerato.js.map +1 -1
  88. package/_esm/chains/index.js +11 -7
  89. package/_esm/chains/index.js.map +1 -1
  90. package/_esm/errors/version.js +1 -1
  91. package/_esm/errors/version.js.map +1 -1
  92. package/_esm/tempo/Abis.js +700 -3
  93. package/_esm/tempo/Abis.js.map +1 -1
  94. package/_esm/tempo/Account.js +7 -7
  95. package/_esm/tempo/Account.js.map +1 -1
  96. package/_esm/tempo/Hardfork.js +15 -0
  97. package/_esm/tempo/Hardfork.js.map +1 -0
  98. package/_esm/tempo/Transaction.js +1 -0
  99. package/_esm/tempo/Transaction.js.map +1 -1
  100. package/_esm/tempo/actions/accessKey.js +36 -4
  101. package/_esm/tempo/actions/accessKey.js.map +1 -1
  102. package/_esm/tempo/actions/token.js +2 -1
  103. package/_esm/tempo/actions/token.js.map +1 -1
  104. package/_esm/tempo/actions/validator.js +11 -11
  105. package/_esm/tempo/actions/validator.js.map +1 -1
  106. package/_esm/tempo/chainConfig.js +52 -11
  107. package/_esm/tempo/chainConfig.js.map +1 -1
  108. package/_esm/tempo/index.js +2 -1
  109. package/_esm/tempo/index.js.map +1 -1
  110. package/_esm/utils/buildRequest.js +5 -0
  111. package/_esm/utils/buildRequest.js.map +1 -1
  112. package/_types/actions/public/verifyHash.d.ts +1 -1
  113. package/_types/actions/public/verifyHash.d.ts.map +1 -1
  114. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  115. package/_types/chains/definitions/battlechainTestnet.d.ts +441 -0
  116. package/_types/chains/definitions/battlechainTestnet.d.ts.map +1 -0
  117. package/_types/chains/definitions/eden.d.ts +46 -0
  118. package/_types/chains/definitions/eden.d.ts.map +1 -0
  119. package/_types/chains/definitions/fluent.d.ts +48 -0
  120. package/_types/chains/definitions/fluent.d.ts.map +1 -0
  121. package/_types/chains/definitions/gensyn.d.ts +45 -0
  122. package/_types/chains/definitions/gensyn.d.ts.map +1 -0
  123. package/_types/chains/definitions/igra.d.ts +48 -0
  124. package/_types/chains/definitions/igra.d.ts.map +1 -0
  125. package/_types/chains/definitions/katana.d.ts +6 -9
  126. package/_types/chains/definitions/katana.d.ts.map +1 -1
  127. package/_types/chains/definitions/megaeth.d.ts +274 -6
  128. package/_types/chains/definitions/megaeth.d.ts.map +1 -1
  129. package/_types/chains/definitions/mezo.d.ts +48 -0
  130. package/_types/chains/definitions/mezo.d.ts.map +1 -0
  131. package/_types/chains/definitions/mezoTestnet.d.ts +45 -0
  132. package/_types/chains/definitions/mezoTestnet.d.ts.map +1 -0
  133. package/_types/chains/definitions/radius.d.ts +48 -0
  134. package/_types/chains/definitions/radius.d.ts.map +1 -0
  135. package/_types/chains/definitions/radiusTestnet.d.ts +48 -0
  136. package/_types/chains/definitions/radiusTestnet.d.ts.map +1 -0
  137. package/_types/chains/definitions/tempo.d.ts +25 -22
  138. package/_types/chains/definitions/tempo.d.ts.map +1 -1
  139. package/_types/chains/definitions/tempoDevnet.d.ts +27 -22
  140. package/_types/chains/definitions/tempoDevnet.d.ts.map +1 -1
  141. package/_types/chains/definitions/tempoLocalnet.d.ts +27 -22
  142. package/_types/chains/definitions/tempoLocalnet.d.ts.map +1 -1
  143. package/_types/chains/definitions/tempoModerato.d.ts +27 -24
  144. package/_types/chains/definitions/tempoModerato.d.ts.map +1 -1
  145. package/_types/chains/index.d.ts +11 -7
  146. package/_types/chains/index.d.ts.map +1 -1
  147. package/_types/errors/version.d.ts +1 -1
  148. package/_types/errors/version.d.ts.map +1 -1
  149. package/_types/tempo/Abis.d.ts +1262 -150
  150. package/_types/tempo/Abis.d.ts.map +1 -1
  151. package/_types/tempo/Account.d.ts +2 -2
  152. package/_types/tempo/Account.d.ts.map +1 -1
  153. package/_types/tempo/Decorator.d.ts +2 -2
  154. package/_types/tempo/Hardfork.d.ts +5 -0
  155. package/_types/tempo/Hardfork.d.ts.map +1 -0
  156. package/_types/tempo/Transaction.d.ts.map +1 -1
  157. package/_types/tempo/actions/accessKey.d.ts +645 -3
  158. package/_types/tempo/actions/accessKey.d.ts.map +1 -1
  159. package/_types/tempo/actions/policy.d.ts +444 -4
  160. package/_types/tempo/actions/policy.d.ts.map +1 -1
  161. package/_types/tempo/actions/reward.d.ts +108 -0
  162. package/_types/tempo/actions/reward.d.ts.map +1 -1
  163. package/_types/tempo/actions/token.d.ts +828 -18
  164. package/_types/tempo/actions/token.d.ts.map +1 -1
  165. package/_types/tempo/actions/validator.d.ts +6 -6
  166. package/_types/tempo/actions/validator.d.ts.map +1 -1
  167. package/_types/tempo/chainConfig.d.ts +13 -11
  168. package/_types/tempo/chainConfig.d.ts.map +1 -1
  169. package/_types/tempo/index.d.ts +2 -1
  170. package/_types/tempo/index.d.ts.map +1 -1
  171. package/_types/utils/buildRequest.d.ts.map +1 -1
  172. package/actions/public/verifyHash.ts +1 -1
  173. package/actions/wallet/prepareTransactionRequest.ts +12 -0
  174. package/actions/wallet/waitForCallsStatus.ts +1 -1
  175. package/chains/definitions/battlechainTestnet.ts +24 -0
  176. package/chains/definitions/eden.ts +29 -0
  177. package/chains/definitions/fluent.ts +23 -0
  178. package/chains/definitions/gensyn.ts +26 -0
  179. package/chains/definitions/igra.ts +23 -0
  180. package/chains/definitions/katana.ts +6 -0
  181. package/chains/definitions/megaeth.ts +26 -3
  182. package/chains/definitions/mezo.ts +20 -0
  183. package/chains/definitions/mezoTestnet.ts +27 -0
  184. package/chains/definitions/radius.ts +19 -0
  185. package/chains/definitions/radiusTestnet.ts +19 -0
  186. package/chains/definitions/tempoDevnet.ts +1 -0
  187. package/chains/definitions/tempoLocalnet.ts +1 -0
  188. package/chains/definitions/tempoModerato.ts +1 -1
  189. package/chains/index.ts +14 -8
  190. package/errors/version.ts +1 -1
  191. package/package.json +2 -2
  192. package/tempo/Abis.ts +703 -3
  193. package/tempo/Account.ts +9 -8
  194. package/tempo/Decorator.ts +2 -2
  195. package/tempo/Hardfork.ts +17 -0
  196. package/tempo/Transaction.ts +2 -1
  197. package/tempo/actions/accessKey.ts +53 -11
  198. package/tempo/actions/token.ts +2 -1
  199. package/tempo/actions/validator.ts +17 -17
  200. package/tempo/chainConfig.ts +59 -15
  201. package/tempo/index.ts +2 -1
  202. package/tsconfig.json +1 -1
  203. package/utils/buildRequest.ts +4 -0
  204. package/_cjs/chains/definitions/tempoAndantino.js +0 -28
  205. package/_cjs/chains/definitions/tempoAndantino.js.map +0 -1
  206. package/_esm/chains/definitions/tempoAndantino.js +0 -25
  207. package/_esm/chains/definitions/tempoAndantino.js.map +0 -1
  208. package/_types/chains/definitions/tempoAndantino.d.ts +0 -918
  209. package/_types/chains/definitions/tempoAndantino.d.ts.map +0 -1
  210. package/chains/definitions/tempoAndantino.ts +0 -25
package/tempo/Account.ts CHANGED
@@ -48,7 +48,7 @@ export type RootAccount = Account_base<'root'> & {
48
48
  key: Pick<AccessKeyAccount, 'accessKeyAddress' | 'keyType'>,
49
49
  parameters: Pick<
50
50
  KeyAuthorization.KeyAuthorization,
51
- 'chainId' | 'expiry' | 'limits'
51
+ 'chainId' | 'expiry' | 'limits' | 'scopes'
52
52
  >,
53
53
  ) => Promise<KeyAuthorization.Signed>
54
54
  }
@@ -381,7 +381,7 @@ export async function signKeyAuthorization(
381
381
  account: LocalAccount,
382
382
  parameters: signKeyAuthorization.Parameters,
383
383
  ): Promise<signKeyAuthorization.ReturnValue> {
384
- const { chainId, key, expiry, limits } = parameters
384
+ const { chainId, key, expiry, limits, scopes } = parameters
385
385
  const { accessKeyAddress, keyType: type } = key
386
386
 
387
387
  const signature = await account.sign!({
@@ -390,6 +390,7 @@ export async function signKeyAuthorization(
390
390
  chainId,
391
391
  expiry,
392
392
  limits,
393
+ scopes,
393
394
  type,
394
395
  }),
395
396
  })
@@ -398,6 +399,7 @@ export async function signKeyAuthorization(
398
399
  chainId,
399
400
  expiry,
400
401
  limits,
402
+ scopes,
401
403
  signature: SignatureEnvelope.from(signature),
402
404
  type,
403
405
  })
@@ -406,7 +408,7 @@ export async function signKeyAuthorization(
406
408
  export declare namespace signKeyAuthorization {
407
409
  type Parameters = Pick<
408
410
  KeyAuthorization.KeyAuthorization,
409
- 'chainId' | 'expiry' | 'limits'
411
+ 'chainId' | 'expiry' | 'limits' | 'scopes'
410
412
  > & {
411
413
  key: Pick<AccessKeyAccount, 'accessKeyAddress' | 'keyType'>
412
414
  }
@@ -444,10 +446,7 @@ function fromBase(parameters: fromBase.Parameters): Account_base {
444
446
  version: internal_version,
445
447
  }),
446
448
  )
447
- // Don't need to append magic bytes to secp256k1 signatures as they are
448
- // backwards compatible with existing verification logic.
449
- if (keyType === 'secp256k1') return signature
450
- return Hex.concat(signature, SignatureEnvelope.magicBytes)
449
+ return signature
451
450
  }
452
451
 
453
452
  return {
@@ -525,7 +524,7 @@ function fromRoot(parameters: fromRoot.Parameters): RootAccount {
525
524
  ...account,
526
525
  source: 'root',
527
526
  async signKeyAuthorization(key, parameters) {
528
- const { chainId, expiry, limits } = parameters
527
+ const { chainId, expiry, limits, scopes } = parameters
529
528
  const { accessKeyAddress, keyType: type } = key
530
529
 
531
530
  const signature = await account.sign({
@@ -534,6 +533,7 @@ function fromRoot(parameters: fromRoot.Parameters): RootAccount {
534
533
  chainId,
535
534
  expiry,
536
535
  limits,
536
+ scopes,
537
537
  type,
538
538
  }),
539
539
  })
@@ -542,6 +542,7 @@ function fromRoot(parameters: fromRoot.Parameters): RootAccount {
542
542
  chainId,
543
543
  expiry,
544
544
  limits,
545
+ scopes,
545
546
  signature: SignatureEnvelope.from(signature),
546
547
  type,
547
548
  })
@@ -124,7 +124,7 @@ export type Decorator<
124
124
  * transport: http(),
125
125
  * }).extend(tempoActions())
126
126
  *
127
- * const remaining = await client.accessKey.getRemainingLimit({
127
+ * const { remaining, periodEnd } = await client.accessKey.getRemainingLimit({
128
128
  * account: '0x...',
129
129
  * accessKey: '0x...',
130
130
  * token: '0x...',
@@ -132,7 +132,7 @@ export type Decorator<
132
132
  * ```
133
133
  *
134
134
  * @param parameters - Parameters.
135
- * @returns The remaining spending amount.
135
+ * @returns The remaining spending amount and period end timestamp.
136
136
  */
137
137
  getRemainingLimit: (
138
138
  parameters: accessKeyActions.getRemainingLimit.Parameters<account>,
@@ -0,0 +1,17 @@
1
+ export const hardforks = [
2
+ 'genesis',
3
+ 't0',
4
+ 't1',
5
+ 't1a',
6
+ 't1b',
7
+ 't1c',
8
+ 't2',
9
+ 't3',
10
+ ] as const
11
+
12
+ export type Hardfork = (typeof hardforks)[number]
13
+
14
+ /** Returns `true` if `current` is before `target`. */
15
+ export function lt(current: string, target: Hardfork): boolean {
16
+ return hardforks.indexOf(current as Hardfork) < hardforks.indexOf(target)
17
+ }
@@ -163,10 +163,11 @@ export function getType(
163
163
  transaction: Record<string, unknown>,
164
164
  ): Transaction['type'] {
165
165
  const account = transaction.account as
166
- | { keyType?: string | undefined }
166
+ | { keyType?: string | undefined; source?: string | undefined }
167
167
  | undefined
168
168
  if (
169
169
  (account?.keyType && account.keyType !== 'secp256k1') ||
170
+ account?.source === 'accessKey' ||
170
171
  typeof transaction.calls !== 'undefined' ||
171
172
  typeof transaction.feePayer !== 'undefined' ||
172
173
  typeof transaction.feeToken !== 'undefined' ||
@@ -1,7 +1,7 @@
1
1
  import type { Address } from 'abitype'
2
+ import type { KeyAuthorization } from 'ox/tempo'
2
3
  import type { Account } from '../../accounts/types.js'
3
4
  import { parseAccount } from '../../accounts/utils/parseAccount.js'
4
- import type { ReadContractReturnType } from '../../actions/public/readContract.js'
5
5
  import { readContract } from '../../actions/public/readContract.js'
6
6
  import { sendTransaction } from '../../actions/wallet/sendTransaction.js'
7
7
  import { sendTransactionSync } from '../../actions/wallet/sendTransactionSync.js'
@@ -20,6 +20,7 @@ import * as Abis from '../Abis.js'
20
20
  import type { AccessKeyAccount } from '../Account.js'
21
21
  import { signKeyAuthorization } from '../Account.js'
22
22
  import * as Addresses from '../Addresses.js'
23
+ import * as Hardfork from '../Hardfork.js'
23
24
  import type {
24
25
  GetAccountParameter,
25
26
  ReadParameters,
@@ -96,7 +97,11 @@ export namespace authorize {
96
97
  /** Unix timestamp when the key expires. */
97
98
  expiry?: number | undefined
98
99
  /** Spending limits per token. */
99
- limits?: { token: Address; limit: bigint }[] | undefined
100
+ limits?:
101
+ | { token: Address; limit: bigint; period?: number | undefined }[]
102
+ | undefined
103
+ /** Call scopes restricting which contracts/selectors this key can call. */
104
+ scopes?: KeyAuthorization.Scope[] | undefined
100
105
  }
101
106
 
102
107
  export type ReturnValue = WriteContractReturnType
@@ -119,6 +124,7 @@ export namespace authorize {
119
124
  chainId = client.chain?.id,
120
125
  expiry,
121
126
  limits,
127
+ scopes,
122
128
  ...rest
123
129
  } = parameters
124
130
  const account_ = rest.account ?? client.account
@@ -130,6 +136,7 @@ export namespace authorize {
130
136
  key: accessKey,
131
137
  expiry,
132
138
  limits,
139
+ scopes,
133
140
  })
134
141
  return (await action(client, {
135
142
  ...rest,
@@ -742,10 +749,26 @@ export async function getRemainingLimit<
742
749
  } = parameters
743
750
  if (!account_) throw new Error('account is required.')
744
751
  const account = parseAccount(account_)
745
- return readContract(client, {
752
+
753
+ // TODO: remove pre-t3 branch once mainnet is on t3.
754
+ const hardfork = (client.chain as { hardfork?: string } | undefined)?.hardfork
755
+ if (hardfork && Hardfork.lt(hardfork, 't3')) {
756
+ const remaining = await readContract(client, {
757
+ ...rest,
758
+ ...getRemainingLimit.call({ account: account.address, accessKey, token }),
759
+ })
760
+ return { remaining, periodEnd: undefined }
761
+ }
762
+
763
+ const [remaining, periodEnd] = await readContract(client, {
746
764
  ...rest,
747
- ...getRemainingLimit.call({ account: account.address, accessKey, token }),
765
+ ...getRemainingLimit.callWithPeriod({
766
+ account: account.address,
767
+ accessKey,
768
+ token,
769
+ }),
748
770
  })
771
+ return { remaining, periodEnd }
749
772
  }
750
773
 
751
774
  export namespace getRemainingLimit {
@@ -764,14 +787,13 @@ export namespace getRemainingLimit {
764
787
  token: Address
765
788
  }
766
789
 
767
- export type ReturnValue = ReadContractReturnType<
768
- typeof Abis.accountKeychain,
769
- 'getRemainingLimit',
770
- never
771
- >
790
+ export type ReturnValue = {
791
+ remaining: bigint
792
+ periodEnd: bigint | undefined
793
+ }
772
794
 
773
795
  /**
774
- * Defines a call to the `getRemainingLimit` function.
796
+ * Defines a call to the `getRemainingLimit` function (pre-T3).
775
797
  *
776
798
  * @param args - Arguments.
777
799
  * @returns The call.
@@ -785,6 +807,22 @@ export namespace getRemainingLimit {
785
807
  args: [account, resolveAccessKey(accessKey), token],
786
808
  })
787
809
  }
810
+
811
+ /**
812
+ * Defines a call to the `getRemainingLimitWithPeriod` function (T3+).
813
+ *
814
+ * @param args - Arguments.
815
+ * @returns The call.
816
+ */
817
+ export function callWithPeriod(args: Args) {
818
+ const { account, accessKey, token } = args
819
+ return defineCall({
820
+ address: Addresses.accountKeychain,
821
+ abi: Abis.accountKeychain,
822
+ functionName: 'getRemainingLimitWithPeriod',
823
+ args: [account, resolveAccessKey(accessKey), token],
824
+ })
825
+ }
788
826
  }
789
827
 
790
828
  /**
@@ -844,7 +882,11 @@ export namespace signAuthorization {
844
882
  /** Unix timestamp when the key expires. */
845
883
  expiry?: number | undefined
846
884
  /** Spending limits per token. */
847
- limits?: { token: Address; limit: bigint }[] | undefined
885
+ limits?:
886
+ | { token: Address; limit: bigint; period?: number | undefined }[]
887
+ | undefined
888
+ /** Call scopes restricting which contracts/selectors this key can call. */
889
+ scopes?: KeyAuthorization.Scope[] | undefined
848
890
  }
849
891
 
850
892
  export type ReturnValue = Awaited<ReturnType<typeof signKeyAuthorization>>
@@ -2510,8 +2510,9 @@ export namespace revokeRoles {
2510
2510
  client: Client<Transport, chain, account>,
2511
2511
  parameters: revokeRoles.Parameters<chain, account>,
2512
2512
  ): Promise<ReturnType<action>> {
2513
+ const { from: _, ...rest } = parameters
2513
2514
  return (await action(client, {
2514
- ...parameters,
2515
+ ...rest,
2515
2516
  calls: parameters.roles.map((role) => {
2516
2517
  const call = revokeRoles.call({ ...parameters, role })
2517
2518
  return {
@@ -155,7 +155,7 @@ export namespace add {
155
155
  } = args
156
156
  return defineCall({
157
157
  address: Addresses.validator,
158
- abi: Abis.validator,
158
+ abi: Abis.validatorConfig,
159
159
  args: [
160
160
  newValidatorAddress,
161
161
  publicKey,
@@ -329,7 +329,7 @@ export namespace changeOwner {
329
329
  const { newOwner } = args
330
330
  return defineCall({
331
331
  address: Addresses.validator,
332
- abi: Abis.validator,
332
+ abi: Abis.validatorConfig,
333
333
  args: [newOwner],
334
334
  functionName: 'changeOwner',
335
335
  })
@@ -497,7 +497,7 @@ export namespace changeStatus {
497
497
  const { validator, active } = args
498
498
  return defineCall({
499
499
  address: Addresses.validator,
500
- abi: Abis.validator,
500
+ abi: Abis.validatorConfig,
501
501
  args: [validator, active],
502
502
  functionName: 'changeValidatorStatus',
503
503
  })
@@ -596,7 +596,7 @@ export namespace getNextFullDkgCeremony {
596
596
  export type Parameters = ReadParameters
597
597
 
598
598
  export type ReturnValue = ReadContractReturnType<
599
- typeof Abis.validator,
599
+ typeof Abis.validatorConfig,
600
600
  'getNextFullDkgCeremony',
601
601
  never
602
602
  >
@@ -630,7 +630,7 @@ export namespace getNextFullDkgCeremony {
630
630
  export function call() {
631
631
  return defineCall({
632
632
  address: Addresses.validator,
633
- abi: Abis.validator,
633
+ abi: Abis.validatorConfig,
634
634
  args: [],
635
635
  functionName: 'getNextFullDkgCeremony',
636
636
  })
@@ -675,7 +675,7 @@ export namespace getOwner {
675
675
  export type Parameters = ReadParameters
676
676
 
677
677
  export type ReturnValue = ReadContractReturnType<
678
- typeof Abis.validator,
678
+ typeof Abis.validatorConfig,
679
679
  'owner',
680
680
  never
681
681
  >
@@ -709,7 +709,7 @@ export namespace getOwner {
709
709
  export function call() {
710
710
  return defineCall({
711
711
  address: Addresses.validator,
712
- abi: Abis.validator,
712
+ abi: Abis.validatorConfig,
713
713
  args: [],
714
714
  functionName: 'owner',
715
715
  })
@@ -762,7 +762,7 @@ export namespace get {
762
762
  }
763
763
 
764
764
  export type ReturnValue = ReadContractReturnType<
765
- typeof Abis.validator,
765
+ typeof Abis.validatorConfig,
766
766
  'validators',
767
767
  never
768
768
  >
@@ -800,7 +800,7 @@ export namespace get {
800
800
  const { validator } = args
801
801
  return defineCall({
802
802
  address: Addresses.validator,
803
- abi: Abis.validator,
803
+ abi: Abis.validatorConfig,
804
804
  args: [validator],
805
805
  functionName: 'validators',
806
806
  })
@@ -853,7 +853,7 @@ export namespace getByIndex {
853
853
  }
854
854
 
855
855
  export type ReturnValue = ReadContractReturnType<
856
- typeof Abis.validator,
856
+ typeof Abis.validatorConfig,
857
857
  'validatorsArray',
858
858
  never
859
859
  >
@@ -892,7 +892,7 @@ export namespace getByIndex {
892
892
  const { index } = args
893
893
  return defineCall({
894
894
  address: Addresses.validator,
895
- abi: Abis.validator,
895
+ abi: Abis.validatorConfig,
896
896
  args: [index],
897
897
  functionName: 'validatorsArray',
898
898
  })
@@ -937,7 +937,7 @@ export namespace getCount {
937
937
  export type Parameters = ReadParameters
938
938
 
939
939
  export type ReturnValue = ReadContractReturnType<
940
- typeof Abis.validator,
940
+ typeof Abis.validatorConfig,
941
941
  'validatorCount',
942
942
  never
943
943
  >
@@ -971,7 +971,7 @@ export namespace getCount {
971
971
  export function call() {
972
972
  return defineCall({
973
973
  address: Addresses.validator,
974
- abi: Abis.validator,
974
+ abi: Abis.validatorConfig,
975
975
  args: [],
976
976
  functionName: 'validatorCount',
977
977
  })
@@ -1016,7 +1016,7 @@ export namespace list {
1016
1016
  export type Parameters = ReadParameters
1017
1017
 
1018
1018
  export type ReturnValue = ReadContractReturnType<
1019
- typeof Abis.validator,
1019
+ typeof Abis.validatorConfig,
1020
1020
  'getValidators',
1021
1021
  never
1022
1022
  >
@@ -1050,7 +1050,7 @@ export namespace list {
1050
1050
  export function call() {
1051
1051
  return defineCall({
1052
1052
  address: Addresses.validator,
1053
- abi: Abis.validator,
1053
+ abi: Abis.validatorConfig,
1054
1054
  args: [],
1055
1055
  functionName: 'getValidators',
1056
1056
  })
@@ -1161,7 +1161,7 @@ export namespace setNextFullDkgCeremony {
1161
1161
  const { epoch } = args
1162
1162
  return defineCall({
1163
1163
  address: Addresses.validator,
1164
- abi: Abis.validator,
1164
+ abi: Abis.validatorConfig,
1165
1165
  args: [epoch],
1166
1166
  functionName: 'setNextFullDkgCeremony',
1167
1167
  })
@@ -1353,7 +1353,7 @@ export namespace update {
1353
1353
  args
1354
1354
  return defineCall({
1355
1355
  address: Addresses.validator,
1356
- abi: Abis.validator,
1356
+ abi: Abis.validatorConfig,
1357
1357
  args: [newValidatorAddress, publicKey, inboundAddress, outboundAddress],
1358
1358
  functionName: 'updateValidator',
1359
1359
  })
@@ -1,3 +1,6 @@
1
+ import * as Address from 'ox/Address'
2
+ import * as Hex from 'ox/Hex'
3
+ import * as PublicKey from 'ox/PublicKey'
1
4
  import { SignatureEnvelope, type TokenId } from 'ox/tempo'
2
5
  import { getCode } from '../actions/public/getCode.js'
3
6
  import { verifyHash } from '../actions/public/verifyHash.js'
@@ -8,9 +11,12 @@ import { defineTransaction } from '../utils/formatters/transaction.js'
8
11
  import { defineTransactionReceipt } from '../utils/formatters/transactionReceipt.js'
9
12
  import { defineTransactionRequest } from '../utils/formatters/transactionRequest.js'
10
13
  import { getAction } from '../utils/getAction.js'
14
+ import { keccak256 } from '../utils/hash/keccak256.js'
11
15
  import type { SerializeTransactionFn } from '../utils/transaction/serializeTransaction.js'
12
16
  import type { Account } from './Account.js'
17
+ import { getMetadata } from './actions/accessKey.js'
13
18
  import * as Formatters from './Formatters.js'
19
+ import type { Hardfork } from './Hardfork.js'
14
20
  import * as Concurrent from './internal/concurrent.js'
15
21
  import * as Transaction from './Transaction.js'
16
22
 
@@ -20,6 +26,7 @@ export const chainConfig = {
20
26
  blockTime: 1_000,
21
27
  extendSchema: extendSchema<{
22
28
  feeToken?: TokenId.TokenIdOrAddress | undefined
29
+ hardfork?: Hardfork | undefined
23
30
  }>(),
24
31
  formatters: {
25
32
  transaction: defineTransaction({
@@ -42,13 +49,15 @@ export const chainConfig = {
42
49
  | undefined
43
50
  }
44
51
 
45
- // FIXME: node does not account for fee payer + key authorization combinartion; bump gas for now.
52
+ // FIXME: node estimates gas with secp256k1 dummy sig + null feePayerSignature.
53
+ // Actual tx has larger keychain/webAuthn sigs + real fee payer sig, costing more intrinsic gas.
46
54
  if (phase === 'afterFillParameters') {
47
- if (
48
- request.feePayer &&
49
- request.keyAuthorization?.signature.type === 'webAuthn'
50
- )
51
- request.gas = (request.gas ?? 0n) + 20_000n
55
+ if (request.feePayer) {
56
+ if (request.keyAuthorization?.signature.type === 'webAuthn')
57
+ request.gas = (request.gas ?? 0n) + 20_000n
58
+ else if (request.account?.source === 'accessKey')
59
+ request.gas = (request.gas ?? 0n) + 10_000n
60
+ }
52
61
  return request as unknown as typeof r
53
62
  }
54
63
 
@@ -89,18 +98,53 @@ export const chainConfig = {
89
98
  Transaction.serialize(transaction, signature)) as SerializeTransactionFn,
90
99
  },
91
100
  async verifyHash(client, parameters) {
92
- const { address, hash, signature } = parameters
101
+ const { address, hash, signature, mode } = parameters
102
+
103
+ const envelope = (() => {
104
+ if (typeof signature !== 'string') return
105
+ try {
106
+ return SignatureEnvelope.deserialize(signature)
107
+ } catch {
108
+ return undefined
109
+ }
110
+ })()
93
111
 
94
112
  // `verifyHash` supports "signature envelopes" (a Tempo proposal) to natively verify arbitrary
95
113
  // envelope-compatible (WebAuthn, P256, etc.) signatures.
96
- // We can directly verify stateless, non-keychain signature envelopes without a
97
- // network request to the chain.
98
- if (
99
- typeof signature === 'string' &&
100
- signature.endsWith(SignatureEnvelope.magicBytes.slice(2))
101
- ) {
102
- const envelope = SignatureEnvelope.deserialize(signature)
103
- if (envelope.type !== 'keychain') {
114
+ if (envelope) {
115
+ // Access key (keychain) signature verification: check the key is
116
+ // authorized, not expired, and not revoked on the AccountKeychain.
117
+ if (envelope?.type === 'keychain' && mode === 'allowAccessKey') {
118
+ const accessKeyAddress = Address.fromPublicKey(
119
+ PublicKey.from(envelope.inner.publicKey as PublicKey.PublicKey),
120
+ )
121
+
122
+ const keyInfo = await getMetadata(client, {
123
+ account: address,
124
+ accessKey: accessKeyAddress,
125
+ blockNumber: parameters.blockNumber,
126
+ blockTag: parameters.blockTag,
127
+ } as never)
128
+
129
+ if (keyInfo.isRevoked) return false
130
+ if (keyInfo.expiry <= BigInt(Math.floor(Date.now() / 1000)))
131
+ return false
132
+
133
+ // For v2 keychain envelopes, the inner signature signs
134
+ // keccak256(0x04 || hash || userAddress).
135
+ const innerPayload =
136
+ envelope.version === 'v2'
137
+ ? keccak256(Hex.concat('0x04', hash, address))
138
+ : hash
139
+ return SignatureEnvelope.verify(envelope.inner, {
140
+ address: accessKeyAddress,
141
+ payload: innerPayload,
142
+ })
143
+ }
144
+
145
+ // Stateless, non-keychain signature envelopes (P256, WebAuthn) can be
146
+ // verified directly without a network request.
147
+ if (envelope.type === 'p256' || envelope.type === 'webAuthn') {
104
148
  const code = await getCode(client, {
105
149
  address,
106
150
  blockNumber: parameters.blockNumber,
package/tempo/index.ts CHANGED
@@ -10,7 +10,7 @@ export type {
10
10
  TxEnvelopeTempo as z_TxEnvelopeTempo,
11
11
  } from 'ox/tempo'
12
12
  // biome-ignore lint/performance/noBarrelFile: _
13
- export { TempoAddress, Tick, TokenId } from 'ox/tempo'
13
+ export { Period, TempoAddress, Tick, TokenId } from 'ox/tempo'
14
14
  export * as Abis from './Abis.js'
15
15
  export * as Account from './Account.js'
16
16
  export * as Addresses from './Addresses.js'
@@ -21,6 +21,7 @@ export {
21
21
  decorator as tempoActions,
22
22
  } from './Decorator.js'
23
23
  export * as Formatters from './Formatters.js'
24
+ export * as Hardfork from './Hardfork.js'
24
25
  export * as P256 from './P256.js'
25
26
  export * as Secp256k1 from './Secp256k1.js'
26
27
  export * as TokenIds from './TokenIds.js'
package/tsconfig.json CHANGED
@@ -5,6 +5,6 @@
5
5
  "compilerOptions": {
6
6
  "composite": true,
7
7
  "noEmit": true,
8
- "baseUrl": ".",
8
+ "types": ["node"]
9
9
  }
10
10
  }
@@ -279,6 +279,10 @@ export function shouldRetry(error: Error) {
279
279
  if (error.code === -1) return true // Unknown error
280
280
  if (error.code === LimitExceededRpcError.code) return true
281
281
  if (error.code === InternalRpcError.code) return true
282
+ // Too Many Requests — some providers (e.g. Alchemy in batch mode) return
283
+ // HTTP 200 with a JSON-RPC body of `{ code: 429 }` instead of an HTTP 429,
284
+ // so we need to handle this code in addition to the HTTP status check below.
285
+ if (error.code === 429) return true
282
286
  return false
283
287
  }
284
288
  if (error instanceof HttpRequestError && error.status) {
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tempoAndantino = void 0;
4
- const chainConfig_js_1 = require("../../tempo/chainConfig.js");
5
- const defineChain_js_1 = require("../../utils/chain/defineChain.js");
6
- exports.tempoAndantino = (0, defineChain_js_1.defineChain)({
7
- ...chainConfig_js_1.chainConfig,
8
- id: 42429,
9
- blockExplorers: {
10
- default: {
11
- name: 'Tempo Explorer',
12
- url: 'https://explore.testnet.tempo.xyz',
13
- },
14
- },
15
- name: 'Tempo Testnet (Andantino)',
16
- nativeCurrency: {
17
- name: 'USD',
18
- symbol: 'USD',
19
- decimals: 6,
20
- },
21
- rpcUrls: {
22
- default: {
23
- http: ['https://rpc.testnet.tempo.xyz'],
24
- webSocket: ['wss://rpc.testnet.tempo.xyz'],
25
- },
26
- },
27
- });
28
- //# sourceMappingURL=tempoAndantino.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tempoAndantino.js","sourceRoot":"","sources":["../../../chains/definitions/tempoAndantino.ts"],"names":[],"mappings":";;;AAAA,+DAAwD;AACxD,qEAA8D;AAEjD,QAAA,cAAc,GAAiB,IAAA,4BAAW,EAAC;IACtD,GAAG,4BAAW;IACd,EAAE,EAAE,KAAK;IACT,cAAc,EAAE;QACd,OAAO,EAAE;YACP,IAAI,EAAE,gBAAgB;YACtB,GAAG,EAAE,mCAAmC;SACzC;KACF;IACD,IAAI,EAAE,2BAA2B;IACjC,cAAc,EAAE;QACd,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,CAAC;KACZ;IACD,OAAO,EAAE;QACP,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,+BAA+B,CAAC;YACvC,SAAS,EAAE,CAAC,6BAA6B,CAAC;SAC3C;KACF;CACF,CAAC,CAAA"}
@@ -1,25 +0,0 @@
1
- import { chainConfig } from '../../tempo/chainConfig.js';
2
- import { defineChain } from '../../utils/chain/defineChain.js';
3
- export const tempoAndantino = /*#__PURE__*/ defineChain({
4
- ...chainConfig,
5
- id: 42429,
6
- blockExplorers: {
7
- default: {
8
- name: 'Tempo Explorer',
9
- url: 'https://explore.testnet.tempo.xyz',
10
- },
11
- },
12
- name: 'Tempo Testnet (Andantino)',
13
- nativeCurrency: {
14
- name: 'USD',
15
- symbol: 'USD',
16
- decimals: 6,
17
- },
18
- rpcUrls: {
19
- default: {
20
- http: ['https://rpc.testnet.tempo.xyz'],
21
- webSocket: ['wss://rpc.testnet.tempo.xyz'],
22
- },
23
- },
24
- });
25
- //# sourceMappingURL=tempoAndantino.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tempoAndantino.js","sourceRoot":"","sources":["../../../chains/definitions/tempoAndantino.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAA;AAE9D,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC,WAAW,CAAC;IACtD,GAAG,WAAW;IACd,EAAE,EAAE,KAAK;IACT,cAAc,EAAE;QACd,OAAO,EAAE;YACP,IAAI,EAAE,gBAAgB;YACtB,GAAG,EAAE,mCAAmC;SACzC;KACF;IACD,IAAI,EAAE,2BAA2B;IACjC,cAAc,EAAE;QACd,IAAI,EAAE,KAAK;QACX,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,CAAC;KACZ;IACD,OAAO,EAAE;QACP,OAAO,EAAE;YACP,IAAI,EAAE,CAAC,+BAA+B,CAAC;YACvC,SAAS,EAAE,CAAC,6BAA6B,CAAC;SAC3C;KACF;CACF,CAAC,CAAA"}