tempo.ts 0.10.5 → 0.11.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 (224) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/README.md +0 -41
  3. package/dist/viem/Account.d.ts +8 -3
  4. package/dist/viem/Account.d.ts.map +1 -1
  5. package/dist/viem/Account.js +9 -2
  6. package/dist/viem/Account.js.map +1 -1
  7. package/dist/viem/Actions/amm.d.ts +1 -1
  8. package/dist/viem/Actions/amm.d.ts.map +1 -1
  9. package/dist/viem/Actions/amm.js +1 -2
  10. package/dist/viem/Actions/amm.js.map +1 -1
  11. package/dist/viem/Actions/dex.d.ts +0 -35
  12. package/dist/viem/Actions/dex.d.ts.map +1 -1
  13. package/dist/viem/Actions/dex.js +0 -43
  14. package/dist/viem/Actions/dex.js.map +1 -1
  15. package/dist/viem/Actions/fee.d.ts +1 -1
  16. package/dist/viem/Actions/fee.d.ts.map +1 -1
  17. package/dist/viem/Actions/fee.js +1 -1
  18. package/dist/viem/Actions/fee.js.map +1 -1
  19. package/dist/viem/Actions/nonce.d.ts.map +1 -1
  20. package/dist/viem/Actions/nonce.js +6 -4
  21. package/dist/viem/Actions/nonce.js.map +1 -1
  22. package/dist/viem/Actions/token.d.ts +1 -2
  23. package/dist/viem/Actions/token.d.ts.map +1 -1
  24. package/dist/viem/Actions/token.js +1 -2
  25. package/dist/viem/Actions/token.js.map +1 -1
  26. package/dist/viem/Chain.d.ts +34 -34
  27. package/dist/viem/Chain.d.ts.map +1 -1
  28. package/dist/viem/Chain.js +2 -0
  29. package/dist/viem/Chain.js.map +1 -1
  30. package/dist/viem/Formatters.d.ts.map +1 -1
  31. package/dist/viem/Formatters.js +5 -3
  32. package/dist/viem/Formatters.js.map +1 -1
  33. package/dist/viem/Transaction.d.ts +8 -5
  34. package/dist/viem/Transaction.d.ts.map +1 -1
  35. package/dist/viem/Transaction.js +13 -3
  36. package/dist/viem/Transaction.js.map +1 -1
  37. package/dist/viem/internal/types.d.ts +1 -1
  38. package/dist/viem/internal/types.d.ts.map +1 -1
  39. package/dist/wagmi/Actions/dex.d.ts +1 -45
  40. package/dist/wagmi/Actions/dex.d.ts.map +1 -1
  41. package/dist/wagmi/Actions/dex.js +0 -55
  42. package/dist/wagmi/Actions/dex.js.map +1 -1
  43. package/dist/wagmi/Connector.d.ts +1 -1
  44. package/dist/wagmi/Connector.d.ts.map +1 -1
  45. package/dist/wagmi/Connector.js +1 -2
  46. package/dist/wagmi/Connector.js.map +1 -1
  47. package/dist/wagmi/Hooks/dex.d.ts +3 -46
  48. package/dist/wagmi/Hooks/dex.d.ts.map +1 -1
  49. package/dist/wagmi/Hooks/dex.js +2 -54
  50. package/dist/wagmi/Hooks/dex.js.map +1 -1
  51. package/dist/wagmi/index.d.ts +1 -1
  52. package/dist/wagmi/index.d.ts.map +1 -1
  53. package/dist/wagmi/index.js +1 -1
  54. package/dist/wagmi/index.js.map +1 -1
  55. package/package.json +5 -23
  56. package/src/viem/Account.test.ts +1 -1
  57. package/src/viem/Account.ts +11 -2
  58. package/src/viem/Actions/account.ts +1 -1
  59. package/src/viem/Actions/amm.ts +1 -2
  60. package/src/viem/Actions/dex.test.ts +1 -195
  61. package/src/viem/Actions/dex.ts +0 -53
  62. package/src/viem/Actions/fee.test.ts +2 -2
  63. package/src/viem/Actions/fee.ts +1 -1
  64. package/src/viem/Actions/nonce.test.ts +27 -14
  65. package/src/viem/Actions/nonce.ts +6 -4
  66. package/src/viem/Actions/token.test.ts +18 -52
  67. package/src/viem/Actions/token.ts +1 -2
  68. package/src/viem/Chain.ts +3 -1
  69. package/src/viem/Decorator.ts +0 -30
  70. package/src/viem/Formatters.ts +9 -3
  71. package/src/viem/Transaction.ts +23 -7
  72. package/src/viem/e2e.test.ts +19 -0
  73. package/src/viem/index.ts +12 -1
  74. package/src/viem/internal/types.ts +1 -1
  75. package/src/wagmi/Actions/dex.test.ts +0 -26
  76. package/src/wagmi/Actions/dex.ts +1 -111
  77. package/src/wagmi/Actions/nonce.test.ts +8 -4
  78. package/src/wagmi/Actions/token.test.ts +2 -2
  79. package/src/wagmi/Connector.ts +1 -2
  80. package/src/wagmi/Hooks/dex.test.ts +0 -26
  81. package/src/wagmi/Hooks/dex.ts +1 -88
  82. package/src/wagmi/Hooks/nonce.test.ts +3 -3
  83. package/src/wagmi/index.ts +4 -1
  84. package/dist/chains.d.ts +0 -73
  85. package/dist/chains.d.ts.map +0 -1
  86. package/dist/chains.js +0 -51
  87. package/dist/chains.js.map +0 -1
  88. package/dist/ox/AuthorizationTempo.d.ts +0 -450
  89. package/dist/ox/AuthorizationTempo.d.ts.map +0 -1
  90. package/dist/ox/AuthorizationTempo.js +0 -433
  91. package/dist/ox/AuthorizationTempo.js.map +0 -1
  92. package/dist/ox/KeyAuthorization.d.ts +0 -356
  93. package/dist/ox/KeyAuthorization.d.ts.map +0 -1
  94. package/dist/ox/KeyAuthorization.js +0 -359
  95. package/dist/ox/KeyAuthorization.js.map +0 -1
  96. package/dist/ox/Order.d.ts +0 -92
  97. package/dist/ox/Order.d.ts.map +0 -1
  98. package/dist/ox/Order.js +0 -88
  99. package/dist/ox/Order.js.map +0 -1
  100. package/dist/ox/OrdersFilters.d.ts +0 -72
  101. package/dist/ox/OrdersFilters.d.ts.map +0 -1
  102. package/dist/ox/OrdersFilters.js +0 -100
  103. package/dist/ox/OrdersFilters.js.map +0 -1
  104. package/dist/ox/Pagination.d.ts +0 -128
  105. package/dist/ox/Pagination.d.ts.map +0 -1
  106. package/dist/ox/Pagination.js +0 -78
  107. package/dist/ox/Pagination.js.map +0 -1
  108. package/dist/ox/PoolId.d.ts +0 -18
  109. package/dist/ox/PoolId.d.ts.map +0 -1
  110. package/dist/ox/PoolId.js +0 -13
  111. package/dist/ox/PoolId.js.map +0 -1
  112. package/dist/ox/RpcSchema.d.ts +0 -32
  113. package/dist/ox/RpcSchema.d.ts.map +0 -1
  114. package/dist/ox/RpcSchema.js +0 -2
  115. package/dist/ox/RpcSchema.js.map +0 -1
  116. package/dist/ox/SignatureEnvelope.d.ts +0 -260
  117. package/dist/ox/SignatureEnvelope.d.ts.map +0 -1
  118. package/dist/ox/SignatureEnvelope.js +0 -477
  119. package/dist/ox/SignatureEnvelope.js.map +0 -1
  120. package/dist/ox/Tick.d.ts +0 -115
  121. package/dist/ox/Tick.d.ts.map +0 -1
  122. package/dist/ox/Tick.js +0 -127
  123. package/dist/ox/Tick.js.map +0 -1
  124. package/dist/ox/TokenId.d.ts +0 -25
  125. package/dist/ox/TokenId.d.ts.map +0 -1
  126. package/dist/ox/TokenId.js +0 -41
  127. package/dist/ox/TokenId.js.map +0 -1
  128. package/dist/ox/TokenRole.d.ts +0 -11
  129. package/dist/ox/TokenRole.d.ts.map +0 -1
  130. package/dist/ox/TokenRole.js +0 -22
  131. package/dist/ox/TokenRole.js.map +0 -1
  132. package/dist/ox/Transaction.d.ts +0 -201
  133. package/dist/ox/Transaction.d.ts.map +0 -1
  134. package/dist/ox/Transaction.js +0 -167
  135. package/dist/ox/Transaction.js.map +0 -1
  136. package/dist/ox/TransactionEnvelopeTempo.d.ts +0 -470
  137. package/dist/ox/TransactionEnvelopeTempo.d.ts.map +0 -1
  138. package/dist/ox/TransactionEnvelopeTempo.js +0 -547
  139. package/dist/ox/TransactionEnvelopeTempo.js.map +0 -1
  140. package/dist/ox/TransactionReceipt.d.ts +0 -155
  141. package/dist/ox/TransactionReceipt.d.ts.map +0 -1
  142. package/dist/ox/TransactionReceipt.js +0 -136
  143. package/dist/ox/TransactionReceipt.js.map +0 -1
  144. package/dist/ox/TransactionRequest.d.ts +0 -76
  145. package/dist/ox/TransactionRequest.d.ts.map +0 -1
  146. package/dist/ox/TransactionRequest.js +0 -93
  147. package/dist/ox/TransactionRequest.js.map +0 -1
  148. package/dist/ox/index.d.ts +0 -14
  149. package/dist/ox/index.d.ts.map +0 -1
  150. package/dist/ox/index.js +0 -14
  151. package/dist/ox/index.js.map +0 -1
  152. package/dist/prool/Instance.d.ts +0 -101
  153. package/dist/prool/Instance.d.ts.map +0 -1
  154. package/dist/prool/Instance.js +0 -136
  155. package/dist/prool/Instance.js.map +0 -1
  156. package/dist/prool/chain.json +0 -238
  157. package/dist/prool/index.d.ts +0 -2
  158. package/dist/prool/index.d.ts.map +0 -1
  159. package/dist/prool/index.js +0 -2
  160. package/dist/prool/index.js.map +0 -1
  161. package/dist/viem/Actions/account.d.ts +0 -40
  162. package/dist/viem/Actions/account.d.ts.map +0 -1
  163. package/dist/viem/Actions/account.js +0 -86
  164. package/dist/viem/Actions/account.js.map +0 -1
  165. package/dist/viem/Actions/index.d.ts +0 -10
  166. package/dist/viem/Actions/index.d.ts.map +0 -1
  167. package/dist/viem/Actions/index.js +0 -10
  168. package/dist/viem/Actions/index.js.map +0 -1
  169. package/dist/viem/Decorator.d.ts +0 -2810
  170. package/dist/viem/Decorator.d.ts.map +0 -1
  171. package/dist/viem/Decorator.js +0 -138
  172. package/dist/viem/Decorator.js.map +0 -1
  173. package/dist/viem/P256.d.ts +0 -2
  174. package/dist/viem/P256.d.ts.map +0 -1
  175. package/dist/viem/P256.js +0 -2
  176. package/dist/viem/P256.js.map +0 -1
  177. package/dist/viem/Secp256k1.d.ts +0 -2
  178. package/dist/viem/Secp256k1.d.ts.map +0 -1
  179. package/dist/viem/Secp256k1.js +0 -2
  180. package/dist/viem/Secp256k1.js.map +0 -1
  181. package/dist/viem/TokenIds.d.ts +0 -2
  182. package/dist/viem/TokenIds.d.ts.map +0 -1
  183. package/dist/viem/TokenIds.js +0 -2
  184. package/dist/viem/TokenIds.js.map +0 -1
  185. package/dist/viem/index.d.ts +0 -17
  186. package/dist/viem/index.d.ts.map +0 -1
  187. package/dist/viem/index.js +0 -17
  188. package/dist/viem/index.js.map +0 -1
  189. package/src/ox/AuthorizationTempo.test.ts +0 -1256
  190. package/src/ox/AuthorizationTempo.ts +0 -648
  191. package/src/ox/KeyAuthorization.test.ts +0 -1332
  192. package/src/ox/KeyAuthorization.ts +0 -540
  193. package/src/ox/Order.test.ts +0 -78
  194. package/src/ox/Order.ts +0 -125
  195. package/src/ox/OrdersFilters.test.ts +0 -182
  196. package/src/ox/OrdersFilters.ts +0 -125
  197. package/src/ox/Pagination.test.ts +0 -162
  198. package/src/ox/Pagination.ts +0 -164
  199. package/src/ox/PoolId.test.ts +0 -33
  200. package/src/ox/PoolId.ts +0 -27
  201. package/src/ox/RpcSchema.ts +0 -35
  202. package/src/ox/SignatureEnvelope.test.ts +0 -1876
  203. package/src/ox/SignatureEnvelope.ts +0 -791
  204. package/src/ox/Tick.test.ts +0 -281
  205. package/src/ox/Tick.ts +0 -181
  206. package/src/ox/TokenId.test.ts +0 -40
  207. package/src/ox/TokenId.ts +0 -50
  208. package/src/ox/TokenRole.test.ts +0 -16
  209. package/src/ox/TokenRole.ts +0 -27
  210. package/src/ox/Transaction.test.ts +0 -523
  211. package/src/ox/Transaction.ts +0 -332
  212. package/src/ox/TransactionEnvelopeTempo.test.ts +0 -1352
  213. package/src/ox/TransactionEnvelopeTempo.ts +0 -905
  214. package/src/ox/TransactionReceipt.ts +0 -190
  215. package/src/ox/TransactionRequest.ts +0 -147
  216. package/src/ox/e2e.test.ts +0 -1393
  217. package/src/ox/index.ts +0 -13
  218. package/src/prool/Instance.test.ts +0 -43
  219. package/src/prool/Instance.ts +0 -247
  220. package/src/prool/chain.json +0 -238
  221. package/src/prool/index.ts +0 -1
  222. package/src/viem/Actions/__snapshots__/dex.test.ts.snap +0 -850
  223. package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +0 -310
  224. package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +0 -457
@@ -1,648 +0,0 @@
1
- import type * as Address from 'ox/Address'
2
- import type * as Errors from 'ox/Errors'
3
- import * as Hash from 'ox/Hash'
4
- import * as Hex from 'ox/Hex'
5
- import * as Rlp from 'ox/Rlp'
6
- import type { Compute, Mutable } from '../internal/types.js'
7
- import * as SignatureEnvelope from './SignatureEnvelope.js'
8
-
9
- /** Root type for an AA Authorization. */
10
- export type AuthorizationTempo<
11
- signed extends boolean = boolean,
12
- bigintType = bigint,
13
- numberType = number,
14
- > = Compute<
15
- {
16
- /** Address of the contract to set as code for the Authority. */
17
- address: Address.Address
18
- /** Chain ID to authorize. */
19
- chainId: numberType
20
- /** Nonce of the Authority to authorize. */
21
- nonce: bigintType
22
- } & (signed extends true
23
- ? { signature: SignatureEnvelope.SignatureEnvelope<bigintType, numberType> }
24
- : {
25
- signature?:
26
- | SignatureEnvelope.SignatureEnvelope<bigintType, numberType>
27
- | undefined
28
- })
29
- >
30
-
31
- /** RPC representation of an {@link ox#AuthorizationTempo.AuthorizationTempo}. */
32
- export type Rpc = Omit<
33
- AuthorizationTempo<false, Hex.Hex, Hex.Hex>,
34
- 'signature'
35
- > & {
36
- signature: SignatureEnvelope.SignatureEnvelopeRpc
37
- }
38
-
39
- /** List of {@link ox#AuthorizationTempo.AuthorizationTempo}. */
40
- export type List<
41
- signed extends boolean = boolean,
42
- bigintType = bigint,
43
- numberType = number,
44
- > = Compute<readonly AuthorizationTempo<signed, bigintType, numberType>[]>
45
-
46
- /** RPC representation of a list of AA Authorizations. */
47
- export type ListRpc = readonly Rpc[]
48
-
49
- /** Signed representation of a list of AA Authorizations. */
50
- export type ListSigned<bigintType = bigint, numberType = number> = List<
51
- true,
52
- bigintType,
53
- numberType
54
- >
55
-
56
- /** Signed representation of an AA Authorization. */
57
- export type Signed<
58
- bigintType = bigint,
59
- numberType = number,
60
- > = AuthorizationTempo<true, bigintType, numberType>
61
-
62
- /** Tuple representation of an AA Authorization. */
63
- export type Tuple<signed extends boolean = boolean> = signed extends true
64
- ? readonly [
65
- chainId: Hex.Hex,
66
- address: Hex.Hex,
67
- nonce: Hex.Hex,
68
- signature: Hex.Hex,
69
- ]
70
- : readonly [chainId: Hex.Hex, address: Hex.Hex, nonce: Hex.Hex]
71
-
72
- /** Tuple representation of a signed {@link ox#AuthorizationTempo.AuthorizationTempo}. */
73
- export type TupleSigned = Tuple<true>
74
-
75
- /** Tuple representation of a list of {@link ox#AuthorizationTempo.AuthorizationTempo}. */
76
- export type TupleList<signed extends boolean = boolean> =
77
- readonly Tuple<signed>[]
78
-
79
- /** Tuple representation of a list of signed {@link ox#AuthorizationTempo.AuthorizationTempo}. */
80
- export type TupleListSigned = TupleList<true>
81
-
82
- /**
83
- * Converts an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization object into a typed {@link ox#AuthorizationTempo.AuthorizationTempo}.
84
- *
85
- * @example
86
- * An AA Authorization can be instantiated from an [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple in object format.
87
- *
88
- * ```ts twoslash
89
- * import { AuthorizationTempo } from 'ox'
90
- *
91
- * const authorization = AuthorizationTempo.from({
92
- * address: '0x1234567890abcdef1234567890abcdef12345678',
93
- * chainId: 1,
94
- * nonce: 69n,
95
- * })
96
- * ```
97
- *
98
- * @example
99
- * ### Attaching Signatures
100
- *
101
- * A {@link ox#SignatureEnvelope.SignatureEnvelope} can be attached with the `signature` option. The example below demonstrates signing
102
- * an AA Authorization with {@link ox#Secp256k1.(sign:function)}.
103
- *
104
- * ```ts twoslash
105
- * import { AuthorizationTempo, Secp256k1 } from 'ox'
106
- *
107
- * const authorization = AuthorizationTempo.from({
108
- * address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
109
- * chainId: 1,
110
- * nonce: 40n,
111
- * })
112
- *
113
- * const signature = Secp256k1.sign({
114
- * payload: AuthorizationTempo.getSignPayload(authorization),
115
- * privateKey: '0x...',
116
- * })
117
- *
118
- * const authorization_signed = AuthorizationTempo.from(authorization, { signature }) // [!code focus]
119
- * ```
120
- *
121
- * @param authorization - An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple in object format.
122
- * @param options - AA Authorization options.
123
- * @returns The {@link ox#AuthorizationTempo.AuthorizationTempo}.
124
- */
125
- export function from<
126
- const authorization extends AuthorizationTempo | Rpc,
127
- const signature extends
128
- | SignatureEnvelope.SignatureEnvelope
129
- | undefined = undefined,
130
- >(
131
- authorization: authorization | AuthorizationTempo,
132
- options: from.Options<signature> = {},
133
- ): from.ReturnType<authorization, signature> {
134
- if (typeof authorization.chainId === 'string')
135
- return fromRpc(authorization as Rpc) as never
136
- if (options.signature) {
137
- return { ...authorization, signature: options.signature } as never
138
- }
139
- return authorization as never
140
- }
141
-
142
- export declare namespace from {
143
- type Options<
144
- signature extends SignatureEnvelope.SignatureEnvelope | undefined =
145
- | SignatureEnvelope.SignatureEnvelope
146
- | undefined,
147
- > = {
148
- /** The {@link ox#SignatureEnvelope.SignatureEnvelope} to attach to the AA Authorization. */
149
- signature?: signature | SignatureEnvelope.SignatureEnvelope | undefined
150
- }
151
-
152
- type ReturnType<
153
- authorization extends AuthorizationTempo | Rpc = AuthorizationTempo,
154
- signature extends SignatureEnvelope.SignatureEnvelope | undefined =
155
- | SignatureEnvelope.SignatureEnvelope
156
- | undefined,
157
- > = Compute<
158
- authorization extends Rpc
159
- ? Signed
160
- : authorization &
161
- (signature extends SignatureEnvelope.SignatureEnvelope
162
- ? { signature: SignatureEnvelope.from.ReturnValue<signature> }
163
- : {})
164
- >
165
-
166
- type ErrorType = Errors.GlobalErrorType
167
- }
168
-
169
- /**
170
- * Converts an {@link ox#AuthorizationTempo.Rpc} to an {@link ox#AuthorizationTempo.AuthorizationTempo}.
171
- *
172
- * @example
173
- * ```ts twoslash
174
- * import { AuthorizationTempo } from 'ox'
175
- *
176
- * const authorization = AuthorizationTempo.fromRpc({
177
- * address: '0x0000000000000000000000000000000000000000',
178
- * chainId: '0x1',
179
- * nonce: '0x1',
180
- * signature: {
181
- * r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
182
- * s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
183
- * yParity: '0x0',
184
- * },
185
- * })
186
- * ```
187
- *
188
- * @param authorization - The RPC-formatted AA Authorization.
189
- * @returns A signed {@link ox#AuthorizationTempo.AuthorizationTempo}.
190
- */
191
- export function fromRpc(authorization: Rpc): Signed {
192
- const { address, chainId, nonce } = authorization
193
- const signature = SignatureEnvelope.fromRpc(authorization.signature)
194
- return {
195
- address,
196
- chainId: Number(chainId),
197
- nonce: BigInt(nonce),
198
- signature,
199
- } as never
200
- }
201
-
202
- export declare namespace fromRpc {
203
- type ErrorType = Errors.GlobalErrorType
204
- }
205
-
206
- /**
207
- * Converts an {@link ox#AuthorizationTempo.ListRpc} to an {@link ox#AuthorizationTempo.List}.
208
- *
209
- * @example
210
- * ```ts twoslash
211
- * import { AuthorizationTempo } from 'ox'
212
- *
213
- * const authorizationList = AuthorizationTempo.fromRpcList([{
214
- * address: '0x0000000000000000000000000000000000000000',
215
- * chainId: '0x1',
216
- * nonce: '0x1',
217
- * signature: {
218
- * r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
219
- * s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
220
- * yParity: '0x0',
221
- * },
222
- * }])
223
- * ```
224
- *
225
- * @param authorizationList - The RPC-formatted AA Authorization list.
226
- * @returns A signed {@link ox#AuthorizationTempo.List}.
227
- */
228
- export function fromRpcList(authorizationList: ListRpc): ListSigned {
229
- return authorizationList.map((x) => fromRpc(x as unknown as Rpc))
230
- }
231
-
232
- export declare namespace fromRpcList {
233
- type ErrorType = Errors.GlobalErrorType
234
- }
235
-
236
- /**
237
- * Converts an {@link ox#AuthorizationTempo.Tuple} to an {@link ox#AuthorizationTempo.AuthorizationTempo}.
238
- *
239
- * @example
240
- * ```ts twoslash
241
- * import { AuthorizationTempo } from 'ox'
242
- *
243
- * const authorization = AuthorizationTempo.fromTuple([
244
- * '0x1',
245
- * '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
246
- * '0x3'
247
- * ])
248
- * // @log: {
249
- * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
250
- * // @log: chainId: 1,
251
- * // @log: nonce: 3n
252
- * // @log: }
253
- * ```
254
- *
255
- * @example
256
- * It is also possible to append a serialized SignatureEnvelope to the end of an AA Authorization tuple.
257
- *
258
- * ```ts twoslash
259
- * import { AuthorizationTempo } from 'ox'
260
- *
261
- * const authorization = AuthorizationTempo.fromTuple([
262
- * '0x1',
263
- * '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
264
- * '0x3',
265
- * '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
266
- * ])
267
- * // @log: {
268
- * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
269
- * // @log: chainId: 1,
270
- * // @log: nonce: 3n
271
- * // @log: signature: {
272
- * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
273
- * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
274
- * // @log: yParity: 0,
275
- * // @log: },
276
- * // @log: }
277
- * ```
278
- *
279
- * @param tuple - The [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple.
280
- * @returns The {@link ox#AuthorizationTempo.AuthorizationTempo}.
281
- */
282
- export function fromTuple<const tuple extends Tuple>(
283
- tuple: tuple,
284
- ): fromTuple.ReturnType<tuple> {
285
- const [chainId, address, nonce, signatureSerialized] = tuple
286
- const args: AuthorizationTempo = {
287
- address,
288
- chainId: chainId === '0x' ? 0 : Number(chainId),
289
- nonce: nonce === '0x' ? 0n : BigInt(nonce),
290
- }
291
- if (signatureSerialized)
292
- args.signature = SignatureEnvelope.deserialize(signatureSerialized)
293
- return from(args) as never
294
- }
295
-
296
- export declare namespace fromTuple {
297
- type ReturnType<authorization extends Tuple = Tuple> = Compute<
298
- AuthorizationTempo<authorization extends Tuple<true> ? true : false>
299
- >
300
-
301
- type ErrorType = Errors.GlobalErrorType
302
- }
303
-
304
- /**
305
- * Converts an {@link ox#AuthorizationTempo.TupleList} to an {@link ox#AuthorizationTempo.List}.
306
- *
307
- * @example
308
- * ```ts twoslash
309
- * import { AuthorizationTempo } from 'ox'
310
- *
311
- * const authorizationList = AuthorizationTempo.fromTupleList([
312
- * ['0x1', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x3'],
313
- * ['0x3', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x14'],
314
- * ])
315
- * // @log: [
316
- * // @log: {
317
- * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
318
- * // @log: chainId: 1,
319
- * // @log: nonce: 3n,
320
- * // @log: },
321
- * // @log: {
322
- * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
323
- * // @log: chainId: 3,
324
- * // @log: nonce: 20n,
325
- * // @log: },
326
- * // @log: ]
327
- * ```
328
- *
329
- * @example
330
- * It is also possible to append a serialized SignatureEnvelope to the end of an AA Authorization tuple.
331
- *
332
- * ```ts twoslash
333
- * import { AuthorizationTempo } from 'ox'
334
- *
335
- * const authorizationList = AuthorizationTempo.fromTupleList([
336
- * ['0x1', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x3', '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'],
337
- * ['0x3', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x14', '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'],
338
- * ])
339
- * // @log: [
340
- * // @log: {
341
- * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
342
- * // @log: chainId: 1,
343
- * // @log: nonce: 3n,
344
- * // @log: signature: {
345
- * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
346
- * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
347
- * // @log: yParity: 0,
348
- * // @log: },
349
- * // @log: },
350
- * // @log: {
351
- * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
352
- * // @log: chainId: 3,
353
- * // @log: nonce: 20n,
354
- * // @log: signature: {
355
- * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
356
- * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
357
- * // @log: yParity: 0,
358
- * // @log: },
359
- * // @log: },
360
- * // @log: ]
361
- * ```
362
- *
363
- * @param tupleList - The [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple list.
364
- * @returns An {@link ox#AuthorizationTempo.List}.
365
- */
366
- export function fromTupleList<const tupleList extends TupleList>(
367
- tupleList: tupleList,
368
- ): fromTupleList.ReturnType<tupleList> {
369
- const list: Mutable<List> = []
370
- for (const tuple of tupleList) list.push(fromTuple(tuple))
371
- return list as never
372
- }
373
-
374
- export declare namespace fromTupleList {
375
- type ReturnType<tupleList extends TupleList> = Compute<
376
- TupleList<tupleList extends TupleList<true> ? true : false>
377
- >
378
-
379
- type ErrorType = Errors.GlobalErrorType
380
- }
381
-
382
- /**
383
- * Computes the sign payload for an {@link ox#AuthorizationTempo.AuthorizationTempo} in [EIP-7702 format](https://eips.ethereum.org/EIPS/eip-7702): `keccak256('0x05' || rlp([chain_id, address, nonce]))`.
384
- *
385
- * @example
386
- * The example below demonstrates computing the sign payload for an {@link ox#AuthorizationTempo.AuthorizationTempo}. This payload
387
- * can then be passed to signing functions like {@link ox#Secp256k1.(sign:function)}.
388
- *
389
- * ```ts twoslash
390
- * import { AuthorizationTempo, Secp256k1 } from 'ox'
391
- *
392
- * const authorization = AuthorizationTempo.from({
393
- * address: '0x1234567890abcdef1234567890abcdef12345678',
394
- * chainId: 1,
395
- * nonce: 69n,
396
- * })
397
- *
398
- * const payload = AuthorizationTempo.getSignPayload(authorization) // [!code focus]
399
- *
400
- * const signature = Secp256k1.sign({
401
- * payload,
402
- * privateKey: '0x...',
403
- * })
404
- * ```
405
- *
406
- * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}.
407
- * @returns The sign payload.
408
- */
409
- export function getSignPayload(authorization: AuthorizationTempo): Hex.Hex {
410
- return hash(authorization, { presign: true })
411
- }
412
-
413
- export declare namespace getSignPayload {
414
- type ErrorType = hash.ErrorType | Errors.GlobalErrorType
415
- }
416
-
417
- /**
418
- * Computes the hash for an {@link ox#AuthorizationTempo.AuthorizationTempo} in [EIP-7702 format](https://eips.ethereum.org/EIPS/eip-7702): `keccak256('0x05' || rlp([chain_id, address, nonce]))`.
419
- *
420
- * @example
421
- * ```ts twoslash
422
- * import { AuthorizationTempo } from 'ox'
423
- *
424
- * const authorization = AuthorizationTempo.from({
425
- * address: '0x1234567890abcdef1234567890abcdef12345678',
426
- * chainId: 1,
427
- * nonce: 69n,
428
- * })
429
- *
430
- * const hash = AuthorizationTempo.hash(authorization) // [!code focus]
431
- * ```
432
- *
433
- * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}.
434
- * @returns The hash.
435
- */
436
- export function hash(
437
- authorization: AuthorizationTempo,
438
- options: hash.Options = {},
439
- ): Hex.Hex {
440
- const { presign } = options
441
- return Hash.keccak256(
442
- Hex.concat(
443
- '0x05',
444
- Rlp.fromHex(
445
- toTuple(
446
- presign
447
- ? {
448
- address: authorization.address,
449
- chainId: authorization.chainId,
450
- nonce: authorization.nonce,
451
- }
452
- : authorization,
453
- ),
454
- ),
455
- ),
456
- )
457
- }
458
-
459
- export declare namespace hash {
460
- type ErrorType =
461
- | toTuple.ErrorType
462
- | Hash.keccak256.ErrorType
463
- | Hex.concat.ErrorType
464
- | Rlp.fromHex.ErrorType
465
- | Errors.GlobalErrorType
466
-
467
- type Options = {
468
- /** Whether to hash this authorization for signing. @default false */
469
- presign?: boolean | undefined
470
- }
471
- }
472
-
473
- /**
474
- * Converts an {@link ox#AuthorizationTempo.AuthorizationTempo} to an {@link ox#AuthorizationTempo.Rpc}.
475
- *
476
- * @example
477
- * ```ts twoslash
478
- * import { AuthorizationTempo } from 'ox'
479
- *
480
- * const authorization = AuthorizationTempo.toRpc({
481
- * address: '0x0000000000000000000000000000000000000000',
482
- * chainId: 1,
483
- * nonce: 1n,
484
- * signature: {
485
- * r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
486
- * s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
487
- * yParity: 0,
488
- * },
489
- * })
490
- * ```
491
- *
492
- * @param authorization - An AA Authorization.
493
- * @returns An RPC-formatted AA Authorization.
494
- */
495
- export function toRpc(authorization: Signed): Rpc {
496
- const { address, chainId, nonce, signature } = authorization
497
-
498
- return {
499
- address,
500
- chainId: Hex.fromNumber(chainId),
501
- nonce: Hex.fromNumber(nonce),
502
- signature: SignatureEnvelope.toRpc(signature),
503
- }
504
- }
505
-
506
- export declare namespace toRpc {
507
- type ErrorType = Errors.GlobalErrorType
508
- }
509
-
510
- /**
511
- * Converts an {@link ox#AuthorizationTempo.List} to an {@link ox#AuthorizationTempo.ListRpc}.
512
- *
513
- * @example
514
- * ```ts twoslash
515
- * import { AuthorizationTempo } from 'ox'
516
- *
517
- * const authorization = AuthorizationTempo.toRpcList([{
518
- * address: '0x0000000000000000000000000000000000000000',
519
- * chainId: 1,
520
- * nonce: 1n,
521
- * signature: {
522
- * r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
523
- * s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
524
- * yParity: 0,
525
- * },
526
- * }])
527
- * ```
528
- *
529
- * @param authorizationList - An AA Authorization List.
530
- * @returns An RPC-formatted AA Authorization List.
531
- */
532
- export function toRpcList(authorizationList: ListSigned): ListRpc {
533
- return authorizationList.map((x) => toRpc(x as unknown as Signed)) as never
534
- }
535
-
536
- export declare namespace toRpcList {
537
- type ErrorType = Errors.GlobalErrorType
538
- }
539
-
540
- /**
541
- * Converts an {@link ox#AuthorizationTempo.AuthorizationTempo} to an {@link ox#AuthorizationTempo.Tuple}.
542
- *
543
- * @example
544
- * ```ts twoslash
545
- * import { AuthorizationTempo } from 'ox'
546
- *
547
- * const authorization = AuthorizationTempo.from({
548
- * address: '0x1234567890abcdef1234567890abcdef12345678',
549
- * chainId: 1,
550
- * nonce: 69n,
551
- * })
552
- *
553
- * const tuple = AuthorizationTempo.toTuple(authorization) // [!code focus]
554
- * // @log: [
555
- * // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
556
- * // @log: chainId: 1,
557
- * // @log: nonce: 69n,
558
- * // @log: ]
559
- * ```
560
- *
561
- * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}.
562
- * @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple.
563
- */
564
- export function toTuple<const authorization extends AuthorizationTempo>(
565
- authorization: authorization,
566
- ): toTuple.ReturnType<authorization> {
567
- const { address, chainId, nonce } = authorization
568
- const signature = authorization.signature
569
- ? SignatureEnvelope.serialize(authorization.signature)
570
- : undefined
571
- return [
572
- chainId ? Hex.fromNumber(chainId) : '0x',
573
- address,
574
- nonce ? Hex.fromNumber(nonce) : '0x',
575
- ...(signature ? [signature] : []),
576
- ] as never
577
- }
578
-
579
- export declare namespace toTuple {
580
- type ReturnType<
581
- authorization extends AuthorizationTempo = AuthorizationTempo,
582
- > = Compute<
583
- Tuple<authorization extends AuthorizationTempo<true> ? true : false>
584
- >
585
-
586
- type ErrorType = Errors.GlobalErrorType
587
- }
588
-
589
- /**
590
- * Converts an {@link ox#AuthorizationTempo.List} to an {@link ox#AuthorizationTempo.TupleList}.
591
- *
592
- * @example
593
- * ```ts twoslash
594
- * import { AuthorizationTempo } from 'ox'
595
- *
596
- * const authorization_1 = AuthorizationTempo.from({
597
- * address: '0x1234567890abcdef1234567890abcdef12345678',
598
- * chainId: 1,
599
- * nonce: 69n,
600
- * })
601
- * const authorization_2 = AuthorizationTempo.from({
602
- * address: '0x1234567890abcdef1234567890abcdef12345678',
603
- * chainId: 3,
604
- * nonce: 20n,
605
- * })
606
- *
607
- * const tuple = AuthorizationTempo.toTupleList([authorization_1, authorization_2]) // [!code focus]
608
- * // @log: [
609
- * // @log: [
610
- * // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
611
- * // @log: chainId: 1,
612
- * // @log: nonce: 69n,
613
- * // @log: ],
614
- * // @log: [
615
- * // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
616
- * // @log: chainId: 3,
617
- * // @log: nonce: 20n,
618
- * // @log: ],
619
- * // @log: ]
620
- * ```
621
- *
622
- * @param list - An {@link ox#AuthorizationTempo.List}.
623
- * @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple list.
624
- */
625
- export function toTupleList<
626
- const list extends
627
- | readonly AuthorizationTempo<true>[]
628
- | readonly AuthorizationTempo<false>[],
629
- >(list?: list | undefined): toTupleList.ReturnType<list> {
630
- if (!list || list.length === 0) return []
631
-
632
- const tupleList: Mutable<TupleList> = []
633
- for (const authorization of list) tupleList.push(toTuple(authorization))
634
-
635
- return tupleList as never
636
- }
637
-
638
- export declare namespace toTupleList {
639
- type ReturnType<
640
- list extends
641
- | readonly AuthorizationTempo<true>[]
642
- | readonly AuthorizationTempo<false>[],
643
- > = Compute<
644
- TupleList<list extends readonly AuthorizationTempo<true>[] ? true : false>
645
- >
646
-
647
- type ErrorType = Errors.GlobalErrorType
648
- }