viem 2.47.16 → 2.47.18

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 (59) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/_cjs/actions/wallet/prepareTransactionRequest.js +6 -0
  3. package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
  4. package/_cjs/errors/version.js +1 -1
  5. package/_cjs/op-stack/actions/getTimeToNextGame.js +11 -2
  6. package/_cjs/op-stack/actions/getTimeToNextGame.js.map +1 -1
  7. package/_cjs/tempo/Abis.js +15 -1
  8. package/_cjs/tempo/Abis.js.map +1 -1
  9. package/_cjs/tempo/Account.js +6 -1
  10. package/_cjs/tempo/Account.js.map +1 -1
  11. package/_cjs/tempo/Transaction.js +14 -10
  12. package/_cjs/tempo/Transaction.js.map +1 -1
  13. package/_cjs/tempo/Transport.js +42 -0
  14. package/_cjs/tempo/Transport.js.map +1 -1
  15. package/_cjs/tempo/index.js +2 -1
  16. package/_cjs/tempo/index.js.map +1 -1
  17. package/_esm/actions/wallet/prepareTransactionRequest.js +6 -0
  18. package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
  19. package/_esm/errors/version.js +1 -1
  20. package/_esm/op-stack/actions/getTimeToNextGame.js +12 -2
  21. package/_esm/op-stack/actions/getTimeToNextGame.js.map +1 -1
  22. package/_esm/tempo/Abis.js +14 -0
  23. package/_esm/tempo/Abis.js.map +1 -1
  24. package/_esm/tempo/Account.js +6 -1
  25. package/_esm/tempo/Account.js.map +1 -1
  26. package/_esm/tempo/Transaction.js +14 -10
  27. package/_esm/tempo/Transaction.js.map +1 -1
  28. package/_esm/tempo/Transport.js +59 -7
  29. package/_esm/tempo/Transport.js.map +1 -1
  30. package/_esm/tempo/index.js +1 -1
  31. package/_esm/tempo/index.js.map +1 -1
  32. package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
  33. package/_types/chains/definitions/tempo.d.ts +22 -22
  34. package/_types/chains/definitions/tempoDevnet.d.ts +22 -22
  35. package/_types/chains/definitions/tempoLocalnet.d.ts +22 -22
  36. package/_types/chains/definitions/tempoModerato.d.ts +22 -22
  37. package/_types/errors/version.d.ts +1 -1
  38. package/_types/op-stack/actions/getTimeToNextGame.d.ts.map +1 -1
  39. package/_types/tempo/Abis.d.ts +3541 -0
  40. package/_types/tempo/Abis.d.ts.map +1 -1
  41. package/_types/tempo/Account.d.ts.map +1 -1
  42. package/_types/tempo/Capabilities.d.ts +16 -1
  43. package/_types/tempo/Capabilities.d.ts.map +1 -1
  44. package/_types/tempo/Transaction.d.ts.map +1 -1
  45. package/_types/tempo/Transport.d.ts +22 -6
  46. package/_types/tempo/Transport.d.ts.map +1 -1
  47. package/_types/tempo/chainConfig.d.ts +11 -11
  48. package/_types/tempo/index.d.ts +1 -1
  49. package/_types/tempo/index.d.ts.map +1 -1
  50. package/actions/wallet/prepareTransactionRequest.ts +6 -0
  51. package/errors/version.ts +1 -1
  52. package/op-stack/actions/getTimeToNextGame.ts +26 -12
  53. package/package.json +1 -1
  54. package/tempo/Abis.ts +15 -0
  55. package/tempo/Account.ts +6 -1
  56. package/tempo/Capabilities.ts +20 -1
  57. package/tempo/Transaction.ts +14 -10
  58. package/tempo/Transport.ts +101 -7
  59. package/tempo/index.ts +1 -1
@@ -16,21 +16,104 @@ import type { Chain } from '../types/chain.js'
16
16
  import type { ChainConfig } from './chainConfig.js'
17
17
  import * as Transaction from './Transaction.js'
18
18
 
19
+ type RelayProxyParameters = {
20
+ /** Policy for how the relay should handle sponsored transactions. Defaults to `'sign-only'`. */
21
+ policy?: 'sign-only' | 'sign-and-broadcast' | undefined
22
+ }
23
+
19
24
  export type FeePayer = Transport<typeof withFeePayer.type>
25
+ export type Relay = Transport<typeof withRelay.type>
20
26
 
21
27
  /**
22
- * Creates a fee payer transport that routes requests between
23
- * the default transport or the fee payer transport.
28
+ * Creates a relay transport that routes requests between
29
+ * the default transport or the relay transport.
24
30
  *
25
- * The policy parameter controls how the fee payer handles transactions:
26
- * - `'sign-only'`: Fee payer co-signs the transaction and returns it to the client transport, which then broadcasts it via the default transport
27
- * - `'sign-and-broadcast'`: Fee payer co-signs and broadcasts the transaction directly
31
+ * All `eth_fillTransaction` requests are sent to the relay with the request's
32
+ * `feePayer` value preserved so the relay can decide whether to sponsor the transaction.
33
+ *
34
+ * The policy parameter controls how the relay handles sponsored transactions:
35
+ * - `'sign-only'`: Relay co-signs the transaction and returns it to the client transport, which then broadcasts it via the default transport
36
+ * - `'sign-and-broadcast'`: Relay co-signs and broadcasts the transaction directly
28
37
  *
29
38
  * @param defaultTransport - The default transport to use.
30
- * @param feePayerTransport - The fee payer transport to use.
39
+ * @param relayTransport - The relay transport to use.
31
40
  * @param parameters - Configuration parameters.
32
41
  * @returns A relay transport.
33
42
  */
43
+ export function withRelay(
44
+ defaultTransport: Transport,
45
+ relayTransport: Transport,
46
+ parameters?: withRelay.Parameters,
47
+ ): withRelay.ReturnValue {
48
+ const { policy = 'sign-only' } = parameters ?? {}
49
+
50
+ return (config) => {
51
+ const transport_default = defaultTransport(config)
52
+ const transport_relay = relayTransport(config)
53
+
54
+ return createTransport({
55
+ key: withRelay.type,
56
+ name: 'Relay Proxy',
57
+ async request({ method, params }, options) {
58
+ if (method === 'eth_fillTransaction')
59
+ return transport_relay.request({ method, params }, options) as never
60
+
61
+ if (
62
+ method === 'eth_sendRawTransactionSync' ||
63
+ method === 'eth_sendRawTransaction'
64
+ ) {
65
+ const serialized = (params as any)[0] as `0x76${string}`
66
+ const transaction = Transaction.deserialize(serialized)
67
+
68
+ // Serialized Tempo envelopes encode `feePayer: true` as a missing fee payer
69
+ // signature until the relay co-signs the transaction.
70
+ if (transaction.feePayerSignature === null) {
71
+ // For 'sign-and-broadcast', relay signs and broadcasts
72
+ if (policy === 'sign-and-broadcast')
73
+ return transport_relay.request(
74
+ { method, params },
75
+ options,
76
+ ) as never
77
+
78
+ // For 'sign-only', request signature from relay using eth_signRawTransaction
79
+ {
80
+ // Request signature from relay using eth_signRawTransaction
81
+ const signedTransaction = await transport_relay.request(
82
+ {
83
+ method: 'eth_signRawTransaction',
84
+ params: [serialized],
85
+ },
86
+ options,
87
+ )
88
+
89
+ // Broadcast the signed transaction via the default transport
90
+ return transport_default.request(
91
+ { method, params: [signedTransaction] },
92
+ options,
93
+ ) as never
94
+ }
95
+ }
96
+ }
97
+
98
+ return (await transport_default.request(
99
+ { method, params },
100
+ options,
101
+ )) as never
102
+ },
103
+ type: withRelay.type,
104
+ })
105
+ }
106
+ }
107
+
108
+ export declare namespace withRelay {
109
+ export const type = 'relay'
110
+
111
+ export type Parameters = RelayProxyParameters
112
+
113
+ export type ReturnValue = Relay
114
+ }
115
+
116
+ /** @deprecated Use `withRelay` instead. */
34
117
  export function withFeePayer(
35
118
  defaultTransport: Transport,
36
119
  relayTransport: Transport,
@@ -46,6 +129,16 @@ export function withFeePayer(
46
129
  key: withFeePayer.type,
47
130
  name: 'Relay Proxy',
48
131
  async request({ method, params }, options) {
132
+ if (method === 'eth_fillTransaction') {
133
+ const request = (params as readonly unknown[] | undefined)?.[0]
134
+ if (
135
+ request &&
136
+ typeof request === 'object' &&
137
+ 'feePayer' in request &&
138
+ request.feePayer === true
139
+ )
140
+ return transport_relay.request({ method, params }, options) as never
141
+ }
49
142
  if (
50
143
  method === 'eth_sendRawTransactionSync' ||
51
144
  method === 'eth_sendRawTransaction'
@@ -53,7 +146,8 @@ export function withFeePayer(
53
146
  const serialized = (params as any)[0] as `0x76${string}`
54
147
  const transaction = Transaction.deserialize(serialized)
55
148
 
56
- // If the transaction is intended to be sponsored, forward it to the relay.
149
+ // Serialized Tempo envelopes encode `feePayer: true` as a missing fee payer
150
+ // signature until the relay co-signs the transaction.
57
151
  if (transaction.feePayerSignature === null) {
58
152
  // For 'sign-and-broadcast', relay signs and broadcasts
59
153
  if (policy === 'sign-and-broadcast')
package/tempo/index.ts CHANGED
@@ -57,6 +57,6 @@ export type {
57
57
  } from './Transaction.js'
58
58
  export * as Transaction from './Transaction.js'
59
59
  export * as Transport from './Transport.js'
60
- export { walletNamespaceCompat, withFeePayer } from './Transport.js'
60
+ export { walletNamespaceCompat, withFeePayer, withRelay } from './Transport.js'
61
61
  export * as WebAuthnP256 from './WebAuthnP256.js'
62
62
  export * as WebCryptoP256 from './WebCryptoP256.js'