ox 0.9.16 → 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 (216) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +4 -4
  3. package/TxEnvelope/package.json +6 -0
  4. package/TxEnvelopeEip1559/package.json +6 -0
  5. package/TxEnvelopeEip2930/package.json +6 -0
  6. package/TxEnvelopeEip4844/package.json +6 -0
  7. package/TxEnvelopeEip7702/package.json +6 -0
  8. package/TxEnvelopeLegacy/package.json +6 -0
  9. package/_cjs/core/{TransactionEnvelope.js → TxEnvelope.js} +1 -1
  10. package/_cjs/core/TxEnvelope.js.map +1 -0
  11. package/_cjs/core/{TransactionEnvelopeEip1559.js → TxEnvelopeEip1559.js} +2 -2
  12. package/_cjs/core/TxEnvelopeEip1559.js.map +1 -0
  13. package/_cjs/core/{TransactionEnvelopeEip2930.js → TxEnvelopeEip2930.js} +2 -2
  14. package/_cjs/core/TxEnvelopeEip2930.js.map +1 -0
  15. package/_cjs/core/{TransactionEnvelopeEip4844.js → TxEnvelopeEip4844.js} +4 -4
  16. package/_cjs/core/TxEnvelopeEip4844.js.map +1 -0
  17. package/_cjs/core/{TransactionEnvelopeEip7702.js → TxEnvelopeEip7702.js} +4 -4
  18. package/_cjs/core/TxEnvelopeEip7702.js.map +1 -0
  19. package/_cjs/core/{TransactionEnvelopeLegacy.js → TxEnvelopeLegacy.js} +2 -2
  20. package/_cjs/core/TxEnvelopeLegacy.js.map +1 -0
  21. package/_cjs/core/WebAuthnP256.js +1 -1
  22. package/_cjs/core/WebAuthnP256.js.map +1 -1
  23. package/_cjs/erc8021/Attribution.js +36 -6
  24. package/_cjs/erc8021/Attribution.js.map +1 -1
  25. package/_cjs/index.docs.js +1 -0
  26. package/_cjs/index.docs.js.map +1 -1
  27. package/_cjs/index.js +7 -7
  28. package/_cjs/index.js.map +1 -1
  29. package/_cjs/tempo/AuthorizationTempo.js +101 -0
  30. package/_cjs/tempo/AuthorizationTempo.js.map +1 -0
  31. package/_cjs/tempo/KeyAuthorization.js +123 -0
  32. package/_cjs/tempo/KeyAuthorization.js.map +1 -0
  33. package/_cjs/tempo/PoolId.js +10 -0
  34. package/_cjs/tempo/PoolId.js.map +1 -0
  35. package/_cjs/tempo/SignatureEnvelope.js +394 -0
  36. package/_cjs/tempo/SignatureEnvelope.js.map +1 -0
  37. package/_cjs/tempo/Tick.js +77 -0
  38. package/_cjs/tempo/Tick.js.map +1 -0
  39. package/_cjs/tempo/TokenId.js +28 -0
  40. package/_cjs/tempo/TokenId.js.map +1 -0
  41. package/_cjs/tempo/TokenRole.js +26 -0
  42. package/_cjs/tempo/TokenRole.js.map +1 -0
  43. package/_cjs/tempo/Transaction.js +80 -0
  44. package/_cjs/tempo/Transaction.js.map +1 -0
  45. package/_cjs/tempo/TransactionReceipt.js +26 -0
  46. package/_cjs/tempo/TransactionReceipt.js.map +1 -0
  47. package/_cjs/tempo/TransactionRequest.js +53 -0
  48. package/_cjs/tempo/TransactionRequest.js.map +1 -0
  49. package/_cjs/tempo/TxEnvelopeTempo.js +267 -0
  50. package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -0
  51. package/_cjs/tempo/index.js +15 -0
  52. package/_cjs/tempo/index.js.map +1 -0
  53. package/_cjs/version.js +1 -1
  54. package/_esm/core/Blobs.js +8 -8
  55. package/_esm/core/{TransactionEnvelope.js → TxEnvelope.js} +11 -11
  56. package/_esm/core/TxEnvelope.js.map +1 -0
  57. package/_esm/core/{TransactionEnvelopeEip1559.js → TxEnvelopeEip1559.js} +42 -42
  58. package/_esm/core/TxEnvelopeEip1559.js.map +1 -0
  59. package/_esm/core/{TransactionEnvelopeEip2930.js → TxEnvelopeEip2930.js} +43 -43
  60. package/_esm/core/TxEnvelopeEip2930.js.map +1 -0
  61. package/_esm/core/{TransactionEnvelopeEip4844.js → TxEnvelopeEip4844.js} +42 -42
  62. package/_esm/core/TxEnvelopeEip4844.js.map +1 -0
  63. package/_esm/core/{TransactionEnvelopeEip7702.js → TxEnvelopeEip7702.js} +40 -40
  64. package/_esm/core/TxEnvelopeEip7702.js.map +1 -0
  65. package/_esm/core/{TransactionEnvelopeLegacy.js → TxEnvelopeLegacy.js} +42 -42
  66. package/_esm/core/TxEnvelopeLegacy.js.map +1 -0
  67. package/_esm/core/WebAuthnP256.js +1 -1
  68. package/_esm/core/WebAuthnP256.js.map +1 -1
  69. package/_esm/erc8021/Attribution.js +58 -13
  70. package/_esm/erc8021/Attribution.js.map +1 -1
  71. package/_esm/index.docs.js +1 -0
  72. package/_esm/index.docs.js.map +1 -1
  73. package/_esm/index.js +192 -192
  74. package/_esm/index.js.map +1 -1
  75. package/_esm/tempo/AuthorizationTempo.js +664 -0
  76. package/_esm/tempo/AuthorizationTempo.js.map +1 -0
  77. package/_esm/tempo/KeyAuthorization.js +426 -0
  78. package/_esm/tempo/KeyAuthorization.js.map +1 -0
  79. package/_esm/tempo/PoolId.js +28 -0
  80. package/_esm/tempo/PoolId.js.map +1 -0
  81. package/_esm/tempo/SignatureEnvelope.js +660 -0
  82. package/_esm/tempo/SignatureEnvelope.js.map +1 -0
  83. package/_esm/tempo/Tick.js +147 -0
  84. package/_esm/tempo/Tick.js.map +1 -0
  85. package/_esm/tempo/TokenId.js +71 -0
  86. package/_esm/tempo/TokenId.js.map +1 -0
  87. package/_esm/tempo/TokenRole.js +40 -0
  88. package/_esm/tempo/TokenRole.js.map +1 -0
  89. package/_esm/tempo/Transaction.js +167 -0
  90. package/_esm/tempo/Transaction.js.map +1 -0
  91. package/_esm/tempo/TransactionReceipt.js +138 -0
  92. package/_esm/tempo/TransactionReceipt.js.map +1 -0
  93. package/_esm/tempo/TransactionRequest.js +99 -0
  94. package/_esm/tempo/TransactionRequest.js.map +1 -0
  95. package/_esm/tempo/TxEnvelopeTempo.js +607 -0
  96. package/_esm/tempo/TxEnvelopeTempo.js.map +1 -0
  97. package/_esm/tempo/index.js +298 -0
  98. package/_esm/tempo/index.js.map +1 -0
  99. package/_esm/version.js +1 -1
  100. package/_types/core/Blobs.d.ts +8 -8
  101. package/_types/core/{TransactionEnvelope.d.ts → TxEnvelope.d.ts} +11 -11
  102. package/_types/core/TxEnvelope.d.ts.map +1 -0
  103. package/_types/core/{TransactionEnvelopeEip1559.d.ts → TxEnvelopeEip1559.d.ts} +54 -54
  104. package/_types/core/TxEnvelopeEip1559.d.ts.map +1 -0
  105. package/_types/core/{TransactionEnvelopeEip2930.d.ts → TxEnvelopeEip2930.d.ts} +55 -55
  106. package/_types/core/TxEnvelopeEip2930.d.ts.map +1 -0
  107. package/_types/core/{TransactionEnvelopeEip4844.d.ts → TxEnvelopeEip4844.d.ts} +54 -54
  108. package/_types/core/TxEnvelopeEip4844.d.ts.map +1 -0
  109. package/_types/core/{TransactionEnvelopeEip7702.d.ts → TxEnvelopeEip7702.d.ts} +49 -49
  110. package/_types/core/TxEnvelopeEip7702.d.ts.map +1 -0
  111. package/_types/core/{TransactionEnvelopeLegacy.d.ts → TxEnvelopeLegacy.d.ts} +54 -54
  112. package/_types/core/TxEnvelopeLegacy.d.ts.map +1 -0
  113. package/_types/core/WebAuthnP256.d.ts +1 -1
  114. package/_types/core/WebAuthnP256.d.ts.map +1 -1
  115. package/_types/erc8021/Attribution.d.ts +20 -6
  116. package/_types/erc8021/Attribution.d.ts.map +1 -1
  117. package/_types/index.d.ts +192 -192
  118. package/_types/index.d.ts.map +1 -1
  119. package/_types/index.docs.d.ts +1 -0
  120. package/_types/index.docs.d.ts.map +1 -1
  121. package/_types/tempo/AuthorizationTempo.d.ts +688 -0
  122. package/_types/tempo/AuthorizationTempo.d.ts.map +1 -0
  123. package/_types/tempo/KeyAuthorization.d.ts +437 -0
  124. package/_types/tempo/KeyAuthorization.d.ts.map +1 -0
  125. package/_types/tempo/PoolId.d.ts +33 -0
  126. package/_types/tempo/PoolId.d.ts.map +1 -0
  127. package/_types/tempo/SignatureEnvelope.d.ts +438 -0
  128. package/_types/tempo/SignatureEnvelope.d.ts.map +1 -0
  129. package/_types/tempo/Tick.d.ts +120 -0
  130. package/_types/tempo/Tick.d.ts.map +1 -0
  131. package/_types/tempo/TokenId.d.ts +55 -0
  132. package/_types/tempo/TokenId.d.ts.map +1 -0
  133. package/_types/tempo/TokenRole.d.ts +29 -0
  134. package/_types/tempo/TokenRole.d.ts.map +1 -0
  135. package/_types/tempo/Transaction.d.ts +208 -0
  136. package/_types/tempo/Transaction.d.ts.map +1 -0
  137. package/_types/tempo/TransactionReceipt.d.ts +165 -0
  138. package/_types/tempo/TransactionReceipt.d.ts.map +1 -0
  139. package/_types/tempo/TransactionRequest.d.ts +89 -0
  140. package/_types/tempo/TransactionRequest.d.ts.map +1 -0
  141. package/_types/tempo/TxEnvelopeTempo.d.ts +551 -0
  142. package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -0
  143. package/_types/tempo/index.d.ts +300 -0
  144. package/_types/tempo/index.d.ts.map +1 -0
  145. package/_types/version.d.ts +1 -1
  146. package/core/Blobs.ts +8 -8
  147. package/core/{TransactionEnvelope.ts → TxEnvelope.ts} +10 -10
  148. package/core/{TransactionEnvelopeEip1559.ts → TxEnvelopeEip1559.ts} +60 -69
  149. package/core/{TransactionEnvelopeEip2930.ts → TxEnvelopeEip2930.ts} +61 -72
  150. package/core/{TransactionEnvelopeEip4844.ts → TxEnvelopeEip4844.ts} +62 -71
  151. package/core/{TransactionEnvelopeEip7702.ts → TxEnvelopeEip7702.ts} +58 -67
  152. package/core/{TransactionEnvelopeLegacy.ts → TxEnvelopeLegacy.ts} +59 -68
  153. package/core/WebAuthnP256.ts +3 -1
  154. package/erc8021/Attribution.ts +77 -15
  155. package/index.docs.ts +1 -0
  156. package/index.ts +192 -195
  157. package/package.json +91 -31
  158. package/tempo/AuthorizationTempo/package.json +6 -0
  159. package/tempo/AuthorizationTempo.test.ts +1293 -0
  160. package/tempo/AuthorizationTempo.ts +884 -0
  161. package/tempo/KeyAuthorization/package.json +6 -0
  162. package/tempo/KeyAuthorization.test.ts +1373 -0
  163. package/tempo/KeyAuthorization.ts +622 -0
  164. package/tempo/PoolId/package.json +6 -0
  165. package/tempo/PoolId.test.ts +33 -0
  166. package/tempo/PoolId.ts +42 -0
  167. package/tempo/SignatureEnvelope/package.json +6 -0
  168. package/tempo/SignatureEnvelope.test.ts +1877 -0
  169. package/tempo/SignatureEnvelope.ts +973 -0
  170. package/tempo/Tick/package.json +6 -0
  171. package/tempo/Tick.test.ts +281 -0
  172. package/tempo/Tick.ts +186 -0
  173. package/tempo/TokenId/package.json +6 -0
  174. package/tempo/TokenId.test.ts +40 -0
  175. package/tempo/TokenId.ts +80 -0
  176. package/tempo/TokenRole/package.json +6 -0
  177. package/tempo/TokenRole.test.ts +16 -0
  178. package/tempo/TokenRole.ts +45 -0
  179. package/tempo/Transaction/package.json +6 -0
  180. package/tempo/Transaction.test.ts +523 -0
  181. package/tempo/Transaction.ts +339 -0
  182. package/tempo/TransactionReceipt/package.json +6 -0
  183. package/tempo/TransactionReceipt.ts +200 -0
  184. package/tempo/TransactionRequest/package.json +6 -0
  185. package/tempo/TransactionRequest.ts +160 -0
  186. package/tempo/TxEnvelopeTempo/package.json +6 -0
  187. package/tempo/TxEnvelopeTempo.test.ts +1371 -0
  188. package/tempo/TxEnvelopeTempo.ts +972 -0
  189. package/tempo/e2e.test.ts +1387 -0
  190. package/tempo/index.ts +308 -0
  191. package/tempo/package.json +6 -0
  192. package/version.ts +1 -1
  193. package/TransactionEnvelope/package.json +0 -6
  194. package/TransactionEnvelopeEip1559/package.json +0 -6
  195. package/TransactionEnvelopeEip2930/package.json +0 -6
  196. package/TransactionEnvelopeEip4844/package.json +0 -6
  197. package/TransactionEnvelopeEip7702/package.json +0 -6
  198. package/TransactionEnvelopeLegacy/package.json +0 -6
  199. package/_cjs/core/TransactionEnvelope.js.map +0 -1
  200. package/_cjs/core/TransactionEnvelopeEip1559.js.map +0 -1
  201. package/_cjs/core/TransactionEnvelopeEip2930.js.map +0 -1
  202. package/_cjs/core/TransactionEnvelopeEip4844.js.map +0 -1
  203. package/_cjs/core/TransactionEnvelopeEip7702.js.map +0 -1
  204. package/_cjs/core/TransactionEnvelopeLegacy.js.map +0 -1
  205. package/_esm/core/TransactionEnvelope.js.map +0 -1
  206. package/_esm/core/TransactionEnvelopeEip1559.js.map +0 -1
  207. package/_esm/core/TransactionEnvelopeEip2930.js.map +0 -1
  208. package/_esm/core/TransactionEnvelopeEip4844.js.map +0 -1
  209. package/_esm/core/TransactionEnvelopeEip7702.js.map +0 -1
  210. package/_esm/core/TransactionEnvelopeLegacy.js.map +0 -1
  211. package/_types/core/TransactionEnvelope.d.ts.map +0 -1
  212. package/_types/core/TransactionEnvelopeEip1559.d.ts.map +0 -1
  213. package/_types/core/TransactionEnvelopeEip2930.d.ts.map +0 -1
  214. package/_types/core/TransactionEnvelopeEip4844.d.ts.map +0 -1
  215. package/_types/core/TransactionEnvelopeEip7702.d.ts.map +0 -1
  216. package/_types/core/TransactionEnvelopeLegacy.d.ts.map +0 -1
@@ -0,0 +1,884 @@
1
+ import type * as Address from '../core/Address.js'
2
+ import type * as Errors from '../core/Errors.js'
3
+ import * as Hash from '../core/Hash.js'
4
+ import * as Hex from '../core/Hex.js'
5
+ import type { Compute, Mutable } from '../core/internal/types.js'
6
+ import * as Rlp from '../core/Rlp.js'
7
+ import * as SignatureEnvelope from './SignatureEnvelope.js'
8
+
9
+ /**
10
+ * Root type for a Tempo Authorization.
11
+ *
12
+ * Tempo extends EIP-7702 to support secp256k1, P256, and WebAuthn signature types,
13
+ * enabling passkey-based account delegation.
14
+ *
15
+ * [Tempo Authorization Specification](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#tempo-authorization-list)
16
+ */
17
+ export type AuthorizationTempo<
18
+ signed extends boolean = boolean,
19
+ bigintType = bigint,
20
+ numberType = number,
21
+ > = Compute<
22
+ {
23
+ /** Address of the contract to set as code for the Authority. */
24
+ address: Address.Address
25
+ /** Chain ID to authorize. */
26
+ chainId: numberType
27
+ /** Nonce of the Authority to authorize. */
28
+ nonce: bigintType
29
+ } & (signed extends true
30
+ ? { signature: SignatureEnvelope.SignatureEnvelope<bigintType, numberType> }
31
+ : {
32
+ signature?:
33
+ | SignatureEnvelope.SignatureEnvelope<bigintType, numberType>
34
+ | undefined
35
+ })
36
+ >
37
+
38
+ /** RPC representation of an {@link ox#AuthorizationTempo.AuthorizationTempo}. */
39
+ export type Rpc = Omit<
40
+ AuthorizationTempo<false, Hex.Hex, Hex.Hex>,
41
+ 'signature'
42
+ > & {
43
+ signature: SignatureEnvelope.SignatureEnvelopeRpc
44
+ }
45
+
46
+ /** List of {@link ox#AuthorizationTempo.AuthorizationTempo}. */
47
+ export type List<
48
+ signed extends boolean = boolean,
49
+ bigintType = bigint,
50
+ numberType = number,
51
+ > = Compute<readonly AuthorizationTempo<signed, bigintType, numberType>[]>
52
+
53
+ /** RPC representation of a list of AA Authorizations. */
54
+ export type ListRpc = readonly Rpc[]
55
+
56
+ /** Signed representation of a list of AA Authorizations. */
57
+ export type ListSigned<bigintType = bigint, numberType = number> = List<
58
+ true,
59
+ bigintType,
60
+ numberType
61
+ >
62
+
63
+ /** Signed representation of an AA Authorization. */
64
+ export type Signed<
65
+ bigintType = bigint,
66
+ numberType = number,
67
+ > = AuthorizationTempo<true, bigintType, numberType>
68
+
69
+ /** Tuple representation of an AA Authorization. */
70
+ export type Tuple<signed extends boolean = boolean> = signed extends true
71
+ ? readonly [
72
+ chainId: Hex.Hex,
73
+ address: Hex.Hex,
74
+ nonce: Hex.Hex,
75
+ signature: Hex.Hex,
76
+ ]
77
+ : readonly [chainId: Hex.Hex, address: Hex.Hex, nonce: Hex.Hex]
78
+
79
+ /** Tuple representation of a signed {@link ox#AuthorizationTempo.AuthorizationTempo}. */
80
+ export type TupleSigned = Tuple<true>
81
+
82
+ /** Tuple representation of a list of {@link ox#AuthorizationTempo.AuthorizationTempo}. */
83
+ export type TupleList<signed extends boolean = boolean> =
84
+ readonly Tuple<signed>[]
85
+
86
+ /** Tuple representation of a list of signed {@link ox#AuthorizationTempo.AuthorizationTempo}. */
87
+ export type TupleListSigned = TupleList<true>
88
+
89
+ /**
90
+ * Converts an EIP-7702 Authorization object into a typed {@link ox#AuthorizationTempo.AuthorizationTempo}.
91
+ *
92
+ * Tempo extends EIP-7702 to support secp256k1, P256, and WebAuthn signature types.
93
+ *
94
+ * [Tempo Authorization Specification](https://docs.tempo.xyz/protocol/transactions/spec-tempo-transaction#tempo-authorization-list)
95
+ *
96
+ * @example
97
+ * An Authorization can be instantiated from an EIP-7702 Authorization tuple in object format.
98
+ *
99
+ * ```ts twoslash
100
+ * import { AuthorizationTempo } from 'ox/tempo'
101
+ *
102
+ * const authorization = AuthorizationTempo.from({
103
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
104
+ * chainId: 1,
105
+ * nonce: 69n,
106
+ * })
107
+ * ```
108
+ *
109
+ * @example
110
+ * ### Attaching Signatures (Secp256k1)
111
+ *
112
+ * Standard Ethereum ECDSA signature using the secp256k1 curve.
113
+ *
114
+ * ```ts twoslash
115
+ * import { Secp256k1 } from 'ox'
116
+ * import { AuthorizationTempo } from 'ox/tempo'
117
+ *
118
+ * const privateKey = Secp256k1.randomPrivateKey()
119
+ *
120
+ * const authorization = AuthorizationTempo.from({
121
+ * address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
122
+ * chainId: 1,
123
+ * nonce: 40n,
124
+ * })
125
+ *
126
+ * const signature = Secp256k1.sign({
127
+ * payload: AuthorizationTempo.getSignPayload(authorization),
128
+ * privateKey,
129
+ * })
130
+ *
131
+ * const authorization_signed = AuthorizationTempo.from(
132
+ * authorization,
133
+ * { signature }, // [!code focus]
134
+ * )
135
+ * ```
136
+ *
137
+ * @example
138
+ * ### Attaching Signatures (P256)
139
+ *
140
+ * ECDSA signature using the P-256 (secp256r1) curve. Requires embedding the
141
+ * public key and a `prehash` flag indicating whether the payload was hashed
142
+ * before signing.
143
+ *
144
+ * ```ts twoslash
145
+ * import { P256 } from 'ox'
146
+ * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
147
+ *
148
+ * const { privateKey, publicKey } = P256.createKeyPair()
149
+ *
150
+ * const authorization = AuthorizationTempo.from({
151
+ * address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
152
+ * chainId: 1,
153
+ * nonce: 40n,
154
+ * })
155
+ *
156
+ * const signature = P256.sign({
157
+ * payload: AuthorizationTempo.getSignPayload(authorization),
158
+ * privateKey,
159
+ * })
160
+ * const signatureEnvelope = SignatureEnvelope.from({
161
+ * signature,
162
+ * publicKey,
163
+ * prehash: false,
164
+ * })
165
+ *
166
+ * const authorization_signed = AuthorizationTempo.from(
167
+ * authorization,
168
+ * { signature: signatureEnvelope }, // [!code focus]
169
+ * )
170
+ * ```
171
+ *
172
+ * @example
173
+ * ### Attaching Signatures (P256 WebCrypto)
174
+ *
175
+ * When using WebCrypto keys, `prehash` must be `true` since WebCrypto always
176
+ * hashes the payload internally before signing.
177
+ *
178
+ * ```ts twoslash
179
+ * // @noErrors
180
+ * import { WebCryptoP256 } from 'ox'
181
+ * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
182
+ *
183
+ * const { privateKey, publicKey } = await WebCryptoP256.createKeyPair()
184
+ *
185
+ * const authorization = AuthorizationTempo.from({
186
+ * address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
187
+ * chainId: 1,
188
+ * nonce: 40n,
189
+ * })
190
+ *
191
+ * const signature = await WebCryptoP256.sign({
192
+ * payload: AuthorizationTempo.getSignPayload(authorization),
193
+ * privateKey,
194
+ * })
195
+ * const signatureEnvelope = SignatureEnvelope.from({
196
+ * signature,
197
+ * publicKey,
198
+ * prehash: true,
199
+ * })
200
+ *
201
+ * const authorization_signed = AuthorizationTempo.from(
202
+ * authorization,
203
+ * { signature: signatureEnvelope }, // [!code focus]
204
+ * )
205
+ * ```
206
+ *
207
+ * @example
208
+ * ### Attaching Signatures (WebAuthn)
209
+ *
210
+ * Passkey-based signature using WebAuthn. Includes authenticator metadata
211
+ * (authenticatorData and clientDataJSON) along with the P-256 signature and
212
+ * public key.
213
+ *
214
+ * ```ts twoslash
215
+ * // @noErrors
216
+ * import { WebAuthnP256 } from 'ox'
217
+ * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
218
+ *
219
+ * const credential = await WebAuthnP256.createCredential({ name: 'Example' })
220
+ *
221
+ * const authorization = AuthorizationTempo.from({
222
+ * address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
223
+ * chainId: 1,
224
+ * nonce: 40n,
225
+ * })
226
+ *
227
+ * const { metadata, signature } = await WebAuthnP256.sign({
228
+ * challenge: AuthorizationTempo.getSignPayload(authorization),
229
+ * credentialId: credential.id,
230
+ * })
231
+ * const signatureEnvelope = SignatureEnvelope.from({
232
+ * signature,
233
+ * publicKey: credential.publicKey,
234
+ * metadata,
235
+ * })
236
+ *
237
+ * const authorization_signed = AuthorizationTempo.from(
238
+ * authorization,
239
+ * { signature: signatureEnvelope }, // [!code focus]
240
+ * )
241
+ * ```
242
+ *
243
+ * @param authorization - An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple in object format.
244
+ * @param options - AA Authorization options.
245
+ * @returns The {@link ox#AuthorizationTempo.AuthorizationTempo}.
246
+ */
247
+ export function from<
248
+ const authorization extends AuthorizationTempo | Rpc,
249
+ const signature extends SignatureEnvelope.from.Value | undefined = undefined,
250
+ >(
251
+ authorization: authorization | AuthorizationTempo,
252
+ options: from.Options<signature> = {},
253
+ ): from.ReturnType<authorization, signature> {
254
+ if (typeof authorization.chainId === 'string')
255
+ return fromRpc(authorization as Rpc) as never
256
+ if (options.signature) {
257
+ return { ...authorization, signature: options.signature } as never
258
+ }
259
+ return authorization as never
260
+ }
261
+
262
+ export declare namespace from {
263
+ type Options<
264
+ signature extends SignatureEnvelope.from.Value | undefined =
265
+ | SignatureEnvelope.from.Value
266
+ | undefined,
267
+ > = {
268
+ /** The {@link ox#SignatureEnvelope.SignatureEnvelope} to attach to the AA Authorization. */
269
+ signature?: signature | SignatureEnvelope.SignatureEnvelope | undefined
270
+ }
271
+
272
+ type ReturnType<
273
+ authorization extends AuthorizationTempo | Rpc = AuthorizationTempo,
274
+ signature extends SignatureEnvelope.from.Value | undefined =
275
+ | SignatureEnvelope.from.Value
276
+ | undefined,
277
+ > = Compute<
278
+ authorization extends Rpc
279
+ ? Signed
280
+ : authorization &
281
+ (signature extends SignatureEnvelope.from.Value
282
+ ? { signature: SignatureEnvelope.from.ReturnValue<signature> }
283
+ : {})
284
+ >
285
+
286
+ type ErrorType = Errors.GlobalErrorType
287
+ }
288
+
289
+ /**
290
+ * Converts an {@link ox#AuthorizationTempo.Rpc} to an {@link ox#AuthorizationTempo.AuthorizationTempo}.
291
+ *
292
+ * @example
293
+ * ```ts twoslash
294
+ * import { AuthorizationTempo } from 'ox/tempo'
295
+ *
296
+ * const authorization = AuthorizationTempo.fromRpc({
297
+ * address: '0x0000000000000000000000000000000000000000',
298
+ * chainId: '0x1',
299
+ * nonce: '0x1',
300
+ * signature: {
301
+ * type: 'secp256k1',
302
+ * r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
303
+ * s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
304
+ * yParity: '0x0',
305
+ * },
306
+ * })
307
+ * ```
308
+ *
309
+ * @param authorization - The RPC-formatted AA Authorization.
310
+ * @returns A signed {@link ox#AuthorizationTempo.AuthorizationTempo}.
311
+ */
312
+ export function fromRpc(authorization: Rpc): Signed {
313
+ const { address, chainId, nonce } = authorization
314
+ const signature = SignatureEnvelope.fromRpc(authorization.signature)
315
+ return {
316
+ address,
317
+ chainId: Number(chainId),
318
+ nonce: BigInt(nonce),
319
+ signature,
320
+ } as never
321
+ }
322
+
323
+ export declare namespace fromRpc {
324
+ type ErrorType = Errors.GlobalErrorType
325
+ }
326
+
327
+ /**
328
+ * Converts an {@link ox#AuthorizationTempo.ListRpc} to an {@link ox#AuthorizationTempo.List}.
329
+ *
330
+ * @example
331
+ * ```ts twoslash
332
+ * import { AuthorizationTempo } from 'ox/tempo'
333
+ *
334
+ * const authorizationList = AuthorizationTempo.fromRpcList([{
335
+ * address: '0x0000000000000000000000000000000000000000',
336
+ * chainId: '0x1',
337
+ * nonce: '0x1',
338
+ * signature: {
339
+ * type: 'secp256k1',
340
+ * r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
341
+ * s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
342
+ * yParity: '0x0',
343
+ * },
344
+ * }])
345
+ * ```
346
+ *
347
+ * @param authorizationList - The RPC-formatted AA Authorization list.
348
+ * @returns A signed {@link ox#AuthorizationTempo.List}.
349
+ */
350
+ export function fromRpcList(authorizationList: ListRpc): ListSigned {
351
+ return authorizationList.map((x) => fromRpc(x as unknown as Rpc))
352
+ }
353
+
354
+ export declare namespace fromRpcList {
355
+ type ErrorType = Errors.GlobalErrorType
356
+ }
357
+
358
+ /**
359
+ * Converts an {@link ox#AuthorizationTempo.Tuple} to an {@link ox#AuthorizationTempo.AuthorizationTempo}.
360
+ *
361
+ * @example
362
+ * ```ts twoslash
363
+ * import { AuthorizationTempo } from 'ox/tempo'
364
+ *
365
+ * const authorization = AuthorizationTempo.fromTuple([
366
+ * '0x1',
367
+ * '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
368
+ * '0x3'
369
+ * ])
370
+ * // @log: {
371
+ * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
372
+ * // @log: chainId: 1,
373
+ * // @log: nonce: 3n
374
+ * // @log: }
375
+ * ```
376
+ *
377
+ * @example
378
+ * It is also possible to append a serialized SignatureEnvelope to the end of an AA Authorization tuple.
379
+ *
380
+ * ```ts twoslash
381
+ * import { AuthorizationTempo } from 'ox/tempo'
382
+ *
383
+ * const authorization = AuthorizationTempo.fromTuple([
384
+ * '0x1',
385
+ * '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
386
+ * '0x3',
387
+ * '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
388
+ * ])
389
+ * // @log: {
390
+ * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
391
+ * // @log: chainId: 1,
392
+ * // @log: nonce: 3n
393
+ * // @log: signature: {
394
+ * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
395
+ * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
396
+ * // @log: yParity: 0,
397
+ * // @log: },
398
+ * // @log: }
399
+ * ```
400
+ *
401
+ * @param tuple - The [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple.
402
+ * @returns The {@link ox#AuthorizationTempo.AuthorizationTempo}.
403
+ */
404
+ export function fromTuple<const tuple extends Tuple>(
405
+ tuple: tuple,
406
+ ): fromTuple.ReturnType<tuple> {
407
+ const [chainId, address, nonce, signatureSerialized] = tuple
408
+ const args: AuthorizationTempo = {
409
+ address,
410
+ chainId: chainId === '0x' ? 0 : Number(chainId),
411
+ nonce: nonce === '0x' ? 0n : BigInt(nonce),
412
+ }
413
+ if (signatureSerialized)
414
+ args.signature = SignatureEnvelope.deserialize(signatureSerialized)
415
+ return from(args) as never
416
+ }
417
+
418
+ export declare namespace fromTuple {
419
+ type ReturnType<authorization extends Tuple = Tuple> = Compute<
420
+ AuthorizationTempo<authorization extends Tuple<true> ? true : false>
421
+ >
422
+
423
+ type ErrorType = Errors.GlobalErrorType
424
+ }
425
+
426
+ /**
427
+ * Converts an {@link ox#AuthorizationTempo.TupleList} to an {@link ox#AuthorizationTempo.List}.
428
+ *
429
+ * @example
430
+ * ```ts twoslash
431
+ * import { AuthorizationTempo } from 'ox/tempo'
432
+ *
433
+ * const authorizationList = AuthorizationTempo.fromTupleList([
434
+ * ['0x1', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x3'],
435
+ * ['0x3', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x14'],
436
+ * ])
437
+ * // @log: [
438
+ * // @log: {
439
+ * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
440
+ * // @log: chainId: 1,
441
+ * // @log: nonce: 3n,
442
+ * // @log: },
443
+ * // @log: {
444
+ * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
445
+ * // @log: chainId: 3,
446
+ * // @log: nonce: 20n,
447
+ * // @log: },
448
+ * // @log: ]
449
+ * ```
450
+ *
451
+ * @example
452
+ * It is also possible to append a serialized SignatureEnvelope to the end of an AA Authorization tuple.
453
+ *
454
+ * ```ts twoslash
455
+ * import { AuthorizationTempo } from 'ox/tempo'
456
+ *
457
+ * const authorizationList = AuthorizationTempo.fromTupleList([
458
+ * ['0x1', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x3', '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'],
459
+ * ['0x3', '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c', '0x14', '0x01a068a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b907e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'],
460
+ * ])
461
+ * // @log: [
462
+ * // @log: {
463
+ * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
464
+ * // @log: chainId: 1,
465
+ * // @log: nonce: 3n,
466
+ * // @log: signature: {
467
+ * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
468
+ * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
469
+ * // @log: yParity: 0,
470
+ * // @log: },
471
+ * // @log: },
472
+ * // @log: {
473
+ * // @log: address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
474
+ * // @log: chainId: 3,
475
+ * // @log: nonce: 20n,
476
+ * // @log: signature: {
477
+ * // @log: r: BigInt('0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'),
478
+ * // @log: s: BigInt('0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'),
479
+ * // @log: yParity: 0,
480
+ * // @log: },
481
+ * // @log: },
482
+ * // @log: ]
483
+ * ```
484
+ *
485
+ * @param tupleList - The [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple list.
486
+ * @returns An {@link ox#AuthorizationTempo.List}.
487
+ */
488
+ export function fromTupleList<const tupleList extends TupleList>(
489
+ tupleList: tupleList,
490
+ ): fromTupleList.ReturnType<tupleList> {
491
+ const list: Mutable<List> = []
492
+ for (const tuple of tupleList) list.push(fromTuple(tuple))
493
+ return list as never
494
+ }
495
+
496
+ export declare namespace fromTupleList {
497
+ type ReturnType<tupleList extends TupleList> = Compute<
498
+ TupleList<tupleList extends TupleList<true> ? true : false>
499
+ >
500
+
501
+ type ErrorType = Errors.GlobalErrorType
502
+ }
503
+
504
+ /**
505
+ * 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]))`.
506
+ *
507
+ * @example
508
+ * ### Secp256k1
509
+ *
510
+ * Standard Ethereum ECDSA signature using the secp256k1 curve.
511
+ *
512
+ * ```ts twoslash
513
+ * import { Secp256k1 } from 'ox'
514
+ * import { AuthorizationTempo } from 'ox/tempo'
515
+ *
516
+ * const privateKey = Secp256k1.randomPrivateKey()
517
+ *
518
+ * const authorization = AuthorizationTempo.from({
519
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
520
+ * chainId: 1,
521
+ * nonce: 69n,
522
+ * })
523
+ *
524
+ * const payload = AuthorizationTempo.getSignPayload(authorization) // [!code focus]
525
+ *
526
+ * const signature = Secp256k1.sign({ payload, privateKey })
527
+ * const authorization_signed = AuthorizationTempo.from(
528
+ * authorization,
529
+ * { signature }
530
+ * )
531
+ * ```
532
+ *
533
+ * @example
534
+ * ### P256
535
+ *
536
+ * ECDSA signature using the P-256 (secp256r1) curve. Requires embedding the
537
+ * public key and a `prehash` flag indicating whether the payload was hashed
538
+ * before signing.
539
+ *
540
+ * ```ts twoslash
541
+ * import { P256 } from 'ox'
542
+ * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
543
+ *
544
+ * const { privateKey, publicKey } = P256.createKeyPair()
545
+ *
546
+ * const authorization = AuthorizationTempo.from({
547
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
548
+ * chainId: 1,
549
+ * nonce: 69n,
550
+ * })
551
+ *
552
+ * const payload = AuthorizationTempo.getSignPayload(authorization) // [!code focus]
553
+ *
554
+ * const signature = P256.sign({ payload, privateKey })
555
+ * const signatureEnvelope = SignatureEnvelope.from({
556
+ * prehash: false,
557
+ * publicKey,
558
+ * signature,
559
+ * })
560
+ * const authorization_signed = AuthorizationTempo.from(
561
+ * authorization,
562
+ * { signature: signatureEnvelope }
563
+ * )
564
+ * ```
565
+ *
566
+ * @example
567
+ * ### P256 (WebCrypto)
568
+ *
569
+ * When using WebCrypto keys, `prehash` must be `true` since WebCrypto always
570
+ * hashes the payload internally before signing.
571
+ *
572
+ * ```ts twoslash
573
+ * // @noErrors
574
+ * import { WebCryptoP256 } from 'ox'
575
+ * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
576
+ *
577
+ * const { privateKey, publicKey } = await WebCryptoP256.createKeyPair()
578
+ *
579
+ * const authorization = AuthorizationTempo.from({
580
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
581
+ * chainId: 1,
582
+ * nonce: 69n,
583
+ * })
584
+ *
585
+ * const payload = AuthorizationTempo.getSignPayload(authorization) // [!code focus]
586
+ *
587
+ * const signature = await WebCryptoP256.sign({ payload, privateKey })
588
+ * const signatureEnvelope = SignatureEnvelope.from({
589
+ * prehash: true,
590
+ * publicKey,
591
+ * signature,
592
+ * })
593
+ * const authorization_signed = AuthorizationTempo.from(
594
+ * authorization,
595
+ * { signature: signatureEnvelope }
596
+ * )
597
+ * ```
598
+ *
599
+ * @example
600
+ * ### WebAuthn
601
+ *
602
+ * Passkey-based signature using WebAuthn. Includes authenticator metadata
603
+ * (authenticatorData and clientDataJSON) along with the P-256 signature and
604
+ * public key.
605
+ *
606
+ * ```ts twoslash
607
+ * // @noErrors
608
+ * import { WebAuthnP256 } from 'ox'
609
+ * import { AuthorizationTempo, SignatureEnvelope } from 'ox/tempo'
610
+ *
611
+ * const credential = await WebAuthnP256.createCredential({ name: 'Example' })
612
+ *
613
+ * const authorization = AuthorizationTempo.from({
614
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
615
+ * chainId: 1,
616
+ * nonce: 69n,
617
+ * })
618
+ *
619
+ * const challenge = AuthorizationTempo.getSignPayload(authorization) // [!code focus]
620
+ *
621
+ * const { metadata, signature } = await WebAuthnP256.sign({
622
+ * challenge,
623
+ * credentialId: credential.id,
624
+ * })
625
+ * const signatureEnvelope = SignatureEnvelope.from({
626
+ * signature,
627
+ * publicKey: credential.publicKey,
628
+ * metadata,
629
+ * })
630
+ * const authorization_signed = AuthorizationTempo.from(
631
+ * authorization,
632
+ * { signature: signatureEnvelope }
633
+ * )
634
+ * ```
635
+ *
636
+ * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}.
637
+ * @returns The sign payload.
638
+ */
639
+ export function getSignPayload(authorization: AuthorizationTempo): Hex.Hex {
640
+ return hash(authorization, { presign: true })
641
+ }
642
+
643
+ export declare namespace getSignPayload {
644
+ type ErrorType = hash.ErrorType | Errors.GlobalErrorType
645
+ }
646
+
647
+ /**
648
+ * 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]))`.
649
+ *
650
+ * @example
651
+ * ```ts twoslash
652
+ * import { AuthorizationTempo } from 'ox/tempo'
653
+ *
654
+ * const authorization = AuthorizationTempo.from({
655
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
656
+ * chainId: 1,
657
+ * nonce: 69n,
658
+ * })
659
+ *
660
+ * const hash = AuthorizationTempo.hash(authorization) // [!code focus]
661
+ * ```
662
+ *
663
+ * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}.
664
+ * @returns The hash.
665
+ */
666
+ export function hash(
667
+ authorization: AuthorizationTempo,
668
+ options: hash.Options = {},
669
+ ): Hex.Hex {
670
+ const { presign } = options
671
+ return Hash.keccak256(
672
+ Hex.concat(
673
+ '0x05',
674
+ Rlp.fromHex(
675
+ toTuple(
676
+ presign
677
+ ? {
678
+ address: authorization.address,
679
+ chainId: authorization.chainId,
680
+ nonce: authorization.nonce,
681
+ }
682
+ : authorization,
683
+ ),
684
+ ),
685
+ ),
686
+ )
687
+ }
688
+
689
+ export declare namespace hash {
690
+ type ErrorType =
691
+ | toTuple.ErrorType
692
+ | Hash.keccak256.ErrorType
693
+ | Hex.concat.ErrorType
694
+ | Rlp.fromHex.ErrorType
695
+ | Errors.GlobalErrorType
696
+
697
+ type Options = {
698
+ /** Whether to hash this authorization for signing. @default false */
699
+ presign?: boolean | undefined
700
+ }
701
+ }
702
+
703
+ /**
704
+ * Converts an {@link ox#AuthorizationTempo.AuthorizationTempo} to an {@link ox#AuthorizationTempo.Rpc}.
705
+ *
706
+ * @example
707
+ * ```ts twoslash
708
+ * import { AuthorizationTempo } from 'ox/tempo'
709
+ *
710
+ * const authorization = AuthorizationTempo.toRpc({
711
+ * address: '0x0000000000000000000000000000000000000000',
712
+ * chainId: 1,
713
+ * nonce: 1n,
714
+ * signature: {
715
+ * type: 'secp256k1',
716
+ * signature: {
717
+ * r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
718
+ * s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
719
+ * yParity: 0,
720
+ * },
721
+ * },
722
+ * })
723
+ * ```
724
+ *
725
+ * @param authorization - An AA Authorization.
726
+ * @returns An RPC-formatted AA Authorization.
727
+ */
728
+ export function toRpc(authorization: Signed): Rpc {
729
+ const { address, chainId, nonce, signature } = authorization
730
+
731
+ return {
732
+ address,
733
+ chainId: Hex.fromNumber(chainId),
734
+ nonce: Hex.fromNumber(nonce),
735
+ signature: SignatureEnvelope.toRpc(signature),
736
+ }
737
+ }
738
+
739
+ export declare namespace toRpc {
740
+ type ErrorType = Errors.GlobalErrorType
741
+ }
742
+
743
+ /**
744
+ * Converts an {@link ox#AuthorizationTempo.List} to an {@link ox#AuthorizationTempo.ListRpc}.
745
+ *
746
+ * @example
747
+ * ```ts twoslash
748
+ * import { AuthorizationTempo } from 'ox/tempo'
749
+ *
750
+ * const authorization = AuthorizationTempo.toRpcList([{
751
+ * address: '0x0000000000000000000000000000000000000000',
752
+ * chainId: 1,
753
+ * nonce: 1n,
754
+ * signature: {
755
+ * type: 'secp256k1',
756
+ * signature: {
757
+ * r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
758
+ * s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
759
+ * yParity: 0,
760
+ * },
761
+ * },
762
+ * }])
763
+ * ```
764
+ *
765
+ * @param authorizationList - An AA Authorization List.
766
+ * @returns An RPC-formatted AA Authorization List.
767
+ */
768
+ export function toRpcList(authorizationList: ListSigned): ListRpc {
769
+ return authorizationList.map((x) => toRpc(x as unknown as Signed)) as never
770
+ }
771
+
772
+ export declare namespace toRpcList {
773
+ type ErrorType = Errors.GlobalErrorType
774
+ }
775
+
776
+ /**
777
+ * Converts an {@link ox#AuthorizationTempo.AuthorizationTempo} to an {@link ox#AuthorizationTempo.Tuple}.
778
+ *
779
+ * @example
780
+ * ```ts twoslash
781
+ * import { AuthorizationTempo } from 'ox/tempo'
782
+ *
783
+ * const authorization = AuthorizationTempo.from({
784
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
785
+ * chainId: 1,
786
+ * nonce: 69n,
787
+ * })
788
+ *
789
+ * const tuple = AuthorizationTempo.toTuple(authorization) // [!code focus]
790
+ * // @log: [
791
+ * // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
792
+ * // @log: chainId: 1,
793
+ * // @log: nonce: 69n,
794
+ * // @log: ]
795
+ * ```
796
+ *
797
+ * @param authorization - The {@link ox#AuthorizationTempo.AuthorizationTempo}.
798
+ * @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple.
799
+ */
800
+ export function toTuple<const authorization extends AuthorizationTempo>(
801
+ authorization: authorization,
802
+ ): toTuple.ReturnType<authorization> {
803
+ const { address, chainId, nonce } = authorization
804
+ const signature = authorization.signature
805
+ ? SignatureEnvelope.serialize(authorization.signature)
806
+ : undefined
807
+ return [
808
+ chainId ? Hex.fromNumber(chainId) : '0x',
809
+ address,
810
+ nonce ? Hex.fromNumber(nonce) : '0x',
811
+ ...(signature ? [signature] : []),
812
+ ] as never
813
+ }
814
+
815
+ export declare namespace toTuple {
816
+ type ReturnType<
817
+ authorization extends AuthorizationTempo = AuthorizationTempo,
818
+ > = Compute<
819
+ Tuple<authorization extends AuthorizationTempo<true> ? true : false>
820
+ >
821
+
822
+ type ErrorType = Errors.GlobalErrorType
823
+ }
824
+
825
+ /**
826
+ * Converts an {@link ox#AuthorizationTempo.List} to an {@link ox#AuthorizationTempo.TupleList}.
827
+ *
828
+ * @example
829
+ * ```ts twoslash
830
+ * import { AuthorizationTempo } from 'ox/tempo'
831
+ *
832
+ * const authorization_1 = AuthorizationTempo.from({
833
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
834
+ * chainId: 1,
835
+ * nonce: 69n,
836
+ * })
837
+ * const authorization_2 = AuthorizationTempo.from({
838
+ * address: '0x1234567890abcdef1234567890abcdef12345678',
839
+ * chainId: 3,
840
+ * nonce: 20n,
841
+ * })
842
+ *
843
+ * const tuple = AuthorizationTempo.toTupleList([authorization_1, authorization_2]) // [!code focus]
844
+ * // @log: [
845
+ * // @log: [
846
+ * // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
847
+ * // @log: chainId: 1,
848
+ * // @log: nonce: 69n,
849
+ * // @log: ],
850
+ * // @log: [
851
+ * // @log: address: '0x1234567890abcdef1234567890abcdef12345678',
852
+ * // @log: chainId: 3,
853
+ * // @log: nonce: 20n,
854
+ * // @log: ],
855
+ * // @log: ]
856
+ * ```
857
+ *
858
+ * @param list - An {@link ox#AuthorizationTempo.List}.
859
+ * @returns An [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) AA Authorization tuple list.
860
+ */
861
+ export function toTupleList<
862
+ const list extends
863
+ | readonly AuthorizationTempo<true>[]
864
+ | readonly AuthorizationTempo<false>[],
865
+ >(list?: list | undefined): toTupleList.ReturnType<list> {
866
+ if (!list || list.length === 0) return []
867
+
868
+ const tupleList: Mutable<TupleList> = []
869
+ for (const authorization of list) tupleList.push(toTuple(authorization))
870
+
871
+ return tupleList as never
872
+ }
873
+
874
+ export declare namespace toTupleList {
875
+ type ReturnType<
876
+ list extends
877
+ | readonly AuthorizationTempo<true>[]
878
+ | readonly AuthorizationTempo<false>[],
879
+ > = Compute<
880
+ TupleList<list extends readonly AuthorizationTempo<true>[] ? true : false>
881
+ >
882
+
883
+ type ErrorType = Errors.GlobalErrorType
884
+ }