tempo.ts 0.8.3 → 0.10.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 (66) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/dist/ox/AuthorizationTempo.d.ts +450 -0
  3. package/dist/ox/AuthorizationTempo.d.ts.map +1 -0
  4. package/dist/ox/AuthorizationTempo.js +433 -0
  5. package/dist/ox/AuthorizationTempo.js.map +1 -0
  6. package/dist/ox/KeyAuthorization.d.ts +4 -4
  7. package/dist/ox/KeyAuthorization.d.ts.map +1 -1
  8. package/dist/ox/KeyAuthorization.js +5 -6
  9. package/dist/ox/KeyAuthorization.js.map +1 -1
  10. package/dist/ox/Transaction.d.ts +11 -10
  11. package/dist/ox/Transaction.d.ts.map +1 -1
  12. package/dist/ox/Transaction.js +10 -3
  13. package/dist/ox/Transaction.js.map +1 -1
  14. package/dist/ox/{TransactionEnvelopeAA.d.ts → TransactionEnvelopeTempo.d.ts} +73 -73
  15. package/dist/ox/TransactionEnvelopeTempo.d.ts.map +1 -0
  16. package/dist/ox/{TransactionEnvelopeAA.js → TransactionEnvelopeTempo.js} +65 -61
  17. package/dist/ox/TransactionEnvelopeTempo.js.map +1 -0
  18. package/dist/ox/TransactionReceipt.d.ts +3 -3
  19. package/dist/ox/TransactionReceipt.d.ts.map +1 -1
  20. package/dist/ox/TransactionReceipt.js +2 -2
  21. package/dist/ox/TransactionReceipt.js.map +1 -1
  22. package/dist/ox/TransactionRequest.d.ts +7 -5
  23. package/dist/ox/TransactionRequest.d.ts.map +1 -1
  24. package/dist/ox/TransactionRequest.js +9 -3
  25. package/dist/ox/TransactionRequest.js.map +1 -1
  26. package/dist/ox/index.d.ts +2 -1
  27. package/dist/ox/index.d.ts.map +1 -1
  28. package/dist/ox/index.js +2 -1
  29. package/dist/ox/index.js.map +1 -1
  30. package/dist/viem/Chain.d.ts +11 -6
  31. package/dist/viem/Chain.d.ts.map +1 -1
  32. package/dist/viem/Chain.js +1 -0
  33. package/dist/viem/Chain.js.map +1 -1
  34. package/dist/viem/Formatters.d.ts.map +1 -1
  35. package/dist/viem/Formatters.js +4 -17
  36. package/dist/viem/Formatters.js.map +1 -1
  37. package/dist/viem/Transaction.d.ts +21 -21
  38. package/dist/viem/Transaction.d.ts.map +1 -1
  39. package/dist/viem/Transaction.js +17 -30
  40. package/dist/viem/Transaction.js.map +1 -1
  41. package/dist/viem/internal/types.d.ts +2 -2
  42. package/dist/viem/internal/types.d.ts.map +1 -1
  43. package/dist/wagmi/Connector.d.ts +6 -12
  44. package/dist/wagmi/Connector.d.ts.map +1 -1
  45. package/dist/wagmi/Connector.js +73 -18
  46. package/dist/wagmi/Connector.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/ox/AuthorizationTempo.test.ts +1256 -0
  49. package/src/ox/AuthorizationTempo.ts +648 -0
  50. package/src/ox/KeyAuthorization.ts +8 -10
  51. package/src/ox/Transaction.test.ts +6 -6
  52. package/src/ox/Transaction.ts +25 -14
  53. package/src/ox/{TransactionEnvelopeAA.test.ts → TransactionEnvelopeTempo.test.ts} +326 -141
  54. package/src/ox/{TransactionEnvelopeAA.ts → TransactionEnvelopeTempo.ts} +93 -81
  55. package/src/ox/TransactionReceipt.ts +3 -3
  56. package/src/ox/TransactionRequest.ts +22 -8
  57. package/src/ox/e2e.test.ts +159 -78
  58. package/src/ox/index.ts +2 -1
  59. package/src/viem/Chain.ts +1 -0
  60. package/src/viem/Formatters.ts +6 -19
  61. package/src/viem/Transaction.ts +50 -68
  62. package/src/viem/e2e.test.ts +28 -42
  63. package/src/viem/internal/types.ts +2 -2
  64. package/src/wagmi/Connector.ts +104 -31
  65. package/dist/ox/TransactionEnvelopeAA.d.ts.map +0 -1
  66. package/dist/ox/TransactionEnvelopeAA.js.map +0 -1
@@ -0,0 +1,648 @@
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
+ }
@@ -6,12 +6,10 @@ import * as Rlp from 'ox/Rlp'
6
6
  import type { Compute } from '../internal/types.js'
7
7
  import * as SignatureEnvelope from './SignatureEnvelope.js'
8
8
 
9
- const defaultExpiry = 0xffffffffffff
10
-
11
9
  /**
12
10
  * Key authorization for provisioning access keys.
13
11
  *
14
- * Used in TransactionEnvelopeAA to add a new key to the keychain precompile.
12
+ * Used in TransactionEnvelopeTempo to add a new key to the keychain precompile.
15
13
  * The transaction must be signed by the root key to authorize adding this access key.
16
14
  */
17
15
  export type KeyAuthorization<
@@ -43,8 +41,8 @@ export type Rpc = Omit<
43
41
  'address' | 'signature' | 'type'
44
42
  > & {
45
43
  keyId: Address.Address
46
- signature: SignatureEnvelope.SignatureEnvelopeRpc
47
44
  keyType: SignatureEnvelope.Type
45
+ signature: SignatureEnvelope.SignatureEnvelopeRpc
48
46
  }
49
47
 
50
48
  /** Signed representation of a Key Authorization. */
@@ -451,16 +449,16 @@ export function toRpc(authorization: Signed): Rpc {
451
449
  const {
452
450
  address,
453
451
  chainId = 0n,
454
- expiry = defaultExpiry,
455
- limits = [],
452
+ expiry,
453
+ limits,
456
454
  type,
457
455
  signature,
458
456
  } = authorization
459
457
 
460
458
  return {
461
459
  chainId: chainId === 0n ? '0x' : Hex.fromNumber(chainId),
462
- expiry: Hex.fromNumber(expiry),
463
- limits: limits.map(({ token, limit }) => ({
460
+ expiry: typeof expiry === 'number' ? Hex.fromNumber(expiry) : undefined,
461
+ limits: limits?.map(({ token, limit }) => ({
464
462
  token,
465
463
  limit: Hex.fromNumber(limit),
466
464
  })),
@@ -501,8 +499,8 @@ export declare namespace toRpc {
501
499
  * // @log: ]
502
500
  * ```
503
501
  *
504
- * @param authorization - The {@link ox#AuthorizationAA.AuthorizationAA}.
505
- * @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple.
502
+ * @param authorization - The {@link ox#KeyAuthorization.KeyAuthorization}.
503
+ * @returns A Tempo Key Authorization tuple.
506
504
  */
507
505
  export function toTuple<const authorization extends KeyAuthorization>(
508
506
  authorization: authorization,