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,1352 +0,0 @@
1
- import { Hex, P256, Rlp, Secp256k1, Value, WebAuthnP256 } from 'ox'
2
- import { describe, expect, test } from 'vitest'
3
- import * as AuthorizationTempo from './AuthorizationTempo.js'
4
- import { SignatureEnvelope } from './index.js'
5
- import * as KeyAuthorization from './KeyAuthorization.js'
6
- import * as TransactionEnvelopeTempo from './TransactionEnvelopeTempo.js'
7
-
8
- const privateKey =
9
- '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
10
-
11
- describe('assert', () => {
12
- test('empty calls list', () => {
13
- expect(() =>
14
- TransactionEnvelopeTempo.assert({
15
- calls: [],
16
- chainId: 1,
17
- }),
18
- ).toThrowErrorMatchingInlineSnapshot(
19
- `[TransactionEnvelopeTempo.CallsEmptyError: Calls list cannot be empty.]`,
20
- )
21
- })
22
-
23
- test('missing calls', () => {
24
- expect(() =>
25
- TransactionEnvelopeTempo.assert({
26
- chainId: 1,
27
- } as any),
28
- ).toThrowErrorMatchingInlineSnapshot(
29
- `[TransactionEnvelopeTempo.CallsEmptyError: Calls list cannot be empty.]`,
30
- )
31
- })
32
-
33
- test('invalid validity window', () => {
34
- expect(() =>
35
- TransactionEnvelopeTempo.assert({
36
- calls: [{ to: '0x0000000000000000000000000000000000000000' }],
37
- chainId: 1,
38
- validBefore: 100,
39
- validAfter: 200,
40
- }),
41
- ).toThrowErrorMatchingInlineSnapshot(
42
- `[TransactionEnvelopeTempo.InvalidValidityWindowError: validBefore (100) must be greater than validAfter (200).]`,
43
- )
44
- })
45
-
46
- test('invalid validity window (equal)', () => {
47
- expect(() =>
48
- TransactionEnvelopeTempo.assert({
49
- calls: [{ to: '0x0000000000000000000000000000000000000000' }],
50
- chainId: 1,
51
- validBefore: 100,
52
- validAfter: 100,
53
- }),
54
- ).toThrowErrorMatchingInlineSnapshot(
55
- `[TransactionEnvelopeTempo.InvalidValidityWindowError: validBefore (100) must be greater than validAfter (100).]`,
56
- )
57
- })
58
-
59
- test('invalid call address', () => {
60
- expect(() =>
61
- TransactionEnvelopeTempo.assert({
62
- calls: [{ to: '0x000000000000000000000000000000000000000z' }],
63
- chainId: 1,
64
- }),
65
- ).toThrowErrorMatchingInlineSnapshot(
66
- `
67
- [Address.InvalidAddressError: Address "0x000000000000000000000000000000000000000z" is invalid.
68
-
69
- Details: Address is not a 20 byte (40 hexadecimal character) value.]
70
- `,
71
- )
72
- })
73
-
74
- test('fee cap too high', () => {
75
- expect(() =>
76
- TransactionEnvelopeTempo.assert({
77
- calls: [{ to: '0x0000000000000000000000000000000000000000' }],
78
- maxFeePerGas: 2n ** 256n - 1n + 1n,
79
- chainId: 1,
80
- }),
81
- ).toThrowErrorMatchingInlineSnapshot(
82
- `[TransactionEnvelope.FeeCapTooHighError: The fee cap (\`maxFeePerGas\`/\`maxPriorityFeePerGas\` = 115792089237316195423570985008687907853269984665640564039457584007913.129639936 gwei) cannot be higher than the maximum allowed value (2^256-1).]`,
83
- )
84
- })
85
-
86
- test('tip above fee cap', () => {
87
- expect(() =>
88
- TransactionEnvelopeTempo.assert({
89
- calls: [{ to: '0x0000000000000000000000000000000000000000' }],
90
- chainId: 1,
91
- maxFeePerGas: 10n,
92
- maxPriorityFeePerGas: 20n,
93
- }),
94
- ).toThrowErrorMatchingInlineSnapshot(
95
- `[TransactionEnvelope.TipAboveFeeCapError: The provided tip (\`maxPriorityFeePerGas\` = 0.00000002 gwei) cannot be higher than the fee cap (\`maxFeePerGas\` = 0.00000001 gwei).]`,
96
- )
97
- })
98
-
99
- test('invalid chain id', () => {
100
- expect(() =>
101
- TransactionEnvelopeTempo.assert({
102
- calls: [{ to: '0x0000000000000000000000000000000000000000' }],
103
- chainId: 0,
104
- }),
105
- ).toThrowErrorMatchingInlineSnapshot(
106
- `[TransactionEnvelope.InvalidChainIdError: Chain ID "0" is invalid.]`,
107
- )
108
- })
109
- })
110
-
111
- describe('deserialize', () => {
112
- const transaction = TransactionEnvelopeTempo.from({
113
- chainId: 1,
114
- calls: [
115
- {
116
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
117
- },
118
- ],
119
- nonce: 785n,
120
- nonceKey: 0n,
121
- maxFeePerGas: Value.fromGwei('2'),
122
- maxPriorityFeePerGas: Value.fromGwei('2'),
123
- })
124
-
125
- test('default', () => {
126
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
127
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
128
- expect(deserialized).toEqual(transaction)
129
- })
130
-
131
- test('minimal', () => {
132
- const transaction = TransactionEnvelopeTempo.from({
133
- chainId: 1,
134
- calls: [{}],
135
- nonce: 0n,
136
- nonceKey: 0n,
137
- })
138
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
139
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
140
- transaction,
141
- )
142
- })
143
-
144
- test('multiple calls', () => {
145
- const transaction_multiCall = TransactionEnvelopeTempo.from({
146
- ...transaction,
147
- calls: [
148
- {
149
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
150
- },
151
- {
152
- to: '0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc',
153
- value: Value.from('0.002', 6),
154
- data: '0x1234',
155
- },
156
- ],
157
- })
158
- const serialized = TransactionEnvelopeTempo.serialize(transaction_multiCall)
159
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
160
- transaction_multiCall,
161
- )
162
- })
163
-
164
- test('gas', () => {
165
- const transaction_gas = TransactionEnvelopeTempo.from({
166
- ...transaction,
167
- gas: 21001n,
168
- })
169
- const serialized = TransactionEnvelopeTempo.serialize(transaction_gas)
170
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
171
- transaction_gas,
172
- )
173
- })
174
-
175
- test('accessList', () => {
176
- const transaction_accessList = TransactionEnvelopeTempo.from({
177
- ...transaction,
178
- accessList: [
179
- {
180
- address: '0x0000000000000000000000000000000000000000',
181
- storageKeys: [
182
- '0x0000000000000000000000000000000000000000000000000000000000000001',
183
- '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe',
184
- ],
185
- },
186
- ],
187
- })
188
- const serialized = TransactionEnvelopeTempo.serialize(
189
- transaction_accessList,
190
- )
191
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
192
- transaction_accessList,
193
- )
194
- })
195
-
196
- test('nonce', () => {
197
- const transaction_nonce = TransactionEnvelopeTempo.from({
198
- ...transaction,
199
- nonce: 0n,
200
- })
201
- const serialized = TransactionEnvelopeTempo.serialize(transaction_nonce)
202
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
203
- transaction_nonce,
204
- )
205
- })
206
-
207
- test('nonceKey', () => {
208
- const transaction_nonceKey = TransactionEnvelopeTempo.from({
209
- ...transaction,
210
- nonceKey: 0n,
211
- })
212
- const serialized = TransactionEnvelopeTempo.serialize(transaction_nonceKey)
213
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
214
- transaction_nonceKey,
215
- )
216
- })
217
-
218
- test('validBefore', () => {
219
- const transaction_validBefore = TransactionEnvelopeTempo.from({
220
- ...transaction,
221
- validBefore: 1000000,
222
- })
223
- const serialized = TransactionEnvelopeTempo.serialize(
224
- transaction_validBefore,
225
- )
226
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
227
- transaction_validBefore,
228
- )
229
- })
230
-
231
- test('validAfter', () => {
232
- const transaction_validAfter = TransactionEnvelopeTempo.from({
233
- ...transaction,
234
- validAfter: 500000,
235
- })
236
- const serialized = TransactionEnvelopeTempo.serialize(
237
- transaction_validAfter,
238
- )
239
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
240
- transaction_validAfter,
241
- )
242
- })
243
-
244
- test('validBefore and validAfter', () => {
245
- const transaction_validity = TransactionEnvelopeTempo.from({
246
- ...transaction,
247
- validBefore: 1000000,
248
- validAfter: 500000,
249
- })
250
- const serialized = TransactionEnvelopeTempo.serialize(transaction_validity)
251
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
252
- transaction_validity,
253
- )
254
- })
255
-
256
- test('feeToken', () => {
257
- const transaction_feeToken = TransactionEnvelopeTempo.from({
258
- ...transaction,
259
- feeToken: '0x20c0000000000000000000000000000000000000',
260
- })
261
- const serialized = TransactionEnvelopeTempo.serialize(transaction_feeToken)
262
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
263
- transaction_feeToken,
264
- )
265
- })
266
-
267
- test('keyAuthorization', () => {
268
- const keyAuthorization = KeyAuthorization.from({
269
- expiry: 1234567890,
270
- address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
271
- type: 'secp256k1',
272
- limits: [
273
- {
274
- token: '0x20c0000000000000000000000000000000000001',
275
- limit: Value.from('10', 6),
276
- },
277
- ],
278
- signature: SignatureEnvelope.from({
279
- r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
280
- s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
281
- yParity: 0,
282
- }),
283
- })
284
-
285
- const transaction_keyAuthorization = TransactionEnvelopeTempo.from({
286
- ...transaction,
287
- keyAuthorization,
288
- })
289
-
290
- const serialized = TransactionEnvelopeTempo.serialize(
291
- transaction_keyAuthorization,
292
- )
293
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
294
- transaction_keyAuthorization,
295
- )
296
- })
297
-
298
- test('authorizationList', () => {
299
- const authorizationList = [
300
- AuthorizationTempo.from({
301
- address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
302
- chainId: 1,
303
- nonce: 40n,
304
- signature: SignatureEnvelope.from({
305
- r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
306
- s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
307
- yParity: 0,
308
- }),
309
- }),
310
- AuthorizationTempo.from({
311
- address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
312
- chainId: 1,
313
- nonce: 55n,
314
- signature: SignatureEnvelope.from({
315
- r: 12345678901234567890n,
316
- s: 98765432109876543210n,
317
- yParity: 1,
318
- }),
319
- }),
320
- ] as const
321
-
322
- const transaction_authorizationList = TransactionEnvelopeTempo.from({
323
- ...transaction,
324
- authorizationList,
325
- })
326
-
327
- const serialized = TransactionEnvelopeTempo.serialize(
328
- transaction_authorizationList,
329
- )
330
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
331
- transaction_authorizationList,
332
- )
333
- })
334
-
335
- test('authorizationList (empty)', () => {
336
- const transaction_authorizationList = TransactionEnvelopeTempo.from({
337
- ...transaction,
338
- authorizationList: [],
339
- })
340
-
341
- const serialized = TransactionEnvelopeTempo.serialize(
342
- transaction_authorizationList,
343
- )
344
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
345
-
346
- // Empty authorizationList should be undefined after deserialization
347
- expect(deserialized.authorizationList).toBeUndefined()
348
- })
349
-
350
- describe('signature', () => {
351
- test('secp256k1', () => {
352
- const signature = Secp256k1.sign({
353
- payload: TransactionEnvelopeTempo.getSignPayload(transaction),
354
- privateKey,
355
- })
356
- const serialized = TransactionEnvelopeTempo.serialize(transaction, {
357
- signature: SignatureEnvelope.from(signature),
358
- })
359
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual({
360
- ...transaction,
361
- signature: { signature, type: 'secp256k1' },
362
- })
363
- })
364
-
365
- test('p256', () => {
366
- const privateKey = P256.randomPrivateKey()
367
- const publicKey = P256.getPublicKey({ privateKey })
368
- const signature = P256.sign({
369
- payload: TransactionEnvelopeTempo.getSignPayload(transaction),
370
- privateKey,
371
- })
372
- const serialized = TransactionEnvelopeTempo.serialize(transaction, {
373
- signature: SignatureEnvelope.from({
374
- signature,
375
- publicKey,
376
- prehash: true,
377
- }),
378
- })
379
- // biome-ignore lint/suspicious/noTsIgnore: _
380
- // @ts-ignore
381
- delete signature.yParity
382
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual({
383
- ...transaction,
384
- signature: { prehash: true, publicKey, signature, type: 'p256' },
385
- })
386
- })
387
- })
388
-
389
- test('feePayerSignature null', () => {
390
- const transaction_feePayer = TransactionEnvelopeTempo.from({
391
- ...transaction,
392
- feePayerSignature: null,
393
- })
394
- const serialized = TransactionEnvelopeTempo.serialize(transaction_feePayer)
395
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual(
396
- transaction_feePayer,
397
- )
398
- })
399
-
400
- test('feePayerSignature with address', () => {
401
- const serialized = `0x76${Rlp.fromHex([
402
- Hex.fromNumber(1), // chainId
403
- Hex.fromNumber(1), // maxPriorityFeePerGas
404
- Hex.fromNumber(1), // maxFeePerGas
405
- Hex.fromNumber(1), // gas
406
- [
407
- [
408
- '0x0000000000000000000000000000000000000000', // to
409
- Hex.fromNumber(0), // value
410
- '0x', // data
411
- ],
412
- ], // calls
413
- '0x', // accessList
414
- Hex.fromNumber(0), // nonceKey
415
- Hex.fromNumber(0), // nonce
416
- '0x', // validBefore
417
- '0x', // validAfter
418
- '0x', // feeToken
419
- '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', // feePayerSignatureOrSender (address)
420
- [], // authorizationList
421
- ]).slice(2)}` as const
422
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
423
- expect(deserialized.feePayerSignature).toBe(null)
424
- })
425
-
426
- test('feePayerSignature with signature tuple', () => {
427
- const serialized = `0x76${Rlp.fromHex([
428
- Hex.fromNumber(1), // chainId
429
- Hex.fromNumber(1), // maxPriorityFeePerGas
430
- Hex.fromNumber(1), // maxFeePerGas
431
- Hex.fromNumber(1), // gas
432
- [
433
- [
434
- '0x0000000000000000000000000000000000000000', // to
435
- Hex.fromNumber(0), // value
436
- '0x', // data
437
- ],
438
- ], // calls
439
- '0x', // accessList
440
- Hex.fromNumber(0), // nonceKey
441
- Hex.fromNumber(0), // nonce
442
- '0x', // validBefore
443
- '0x', // validAfter
444
- '0x', // feeToken
445
- [Hex.fromNumber(0), Hex.fromNumber(1), Hex.fromNumber(2)], // feePayerSignatureOrSender (signature tuple)
446
- [], // authorizationList
447
- ]).slice(2)}` as const
448
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
449
- expect(deserialized.feePayerSignature).toEqual({
450
- yParity: 0,
451
- r: 1n,
452
- s: 2n,
453
- })
454
- })
455
-
456
- describe('raw', () => {
457
- test('default', () => {
458
- const serialized = `0x76${Rlp.fromHex([
459
- Hex.fromNumber(1), // chainId
460
- Hex.fromNumber(1), // maxPriorityFeePerGas
461
- Hex.fromNumber(1), // maxFeePerGas
462
- Hex.fromNumber(1), // gas
463
- [
464
- [
465
- '0x0000000000000000000000000000000000000000', // to
466
- Hex.fromNumber(0), // value
467
- '0x', // data
468
- ],
469
- ], // calls
470
- '0x', // accessList
471
- Hex.fromNumber(0), // nonceKey
472
- Hex.fromNumber(0), // nonce
473
- '0x', // validBefore
474
- '0x', // validAfter
475
- '0x', // feeToken
476
- '0x', // feePayerSignature
477
- [], // authorizationList
478
- ]).slice(2)}` as const
479
- expect(
480
- TransactionEnvelopeTempo.deserialize(serialized),
481
- ).toMatchInlineSnapshot(`
482
- {
483
- "calls": [
484
- {
485
- "to": "0x0000000000000000000000000000000000000000",
486
- "value": 0n,
487
- },
488
- ],
489
- "chainId": 1,
490
- "gas": 1n,
491
- "maxFeePerGas": 1n,
492
- "maxPriorityFeePerGas": 1n,
493
- "nonce": 0n,
494
- "nonceKey": 0n,
495
- "type": "tempo",
496
- }
497
- `)
498
- })
499
-
500
- test('empty sig', () => {
501
- const serialized = `0x76${Rlp.fromHex([
502
- Hex.fromNumber(1), // chainId
503
- Hex.fromNumber(1), // maxPriorityFeePerGas
504
- Hex.fromNumber(1), // maxFeePerGas
505
- Hex.fromNumber(1), // gas
506
- [
507
- [
508
- '0x0000000000000000000000000000000000000000', // to
509
- Hex.fromNumber(0), // value
510
- '0x', // data
511
- ],
512
- ], // calls
513
- '0x', // accessList
514
- Hex.fromNumber(0), // nonceKey
515
- Hex.fromNumber(0), // nonce
516
- '0x', // validBefore
517
- '0x', // validAfter
518
- '0x', // feeToken
519
- '0x', // feePayerSignature
520
- [], // authorizationList
521
- ]).slice(2)}` as const
522
- expect(
523
- TransactionEnvelopeTempo.deserialize(serialized),
524
- ).toMatchInlineSnapshot(`
525
- {
526
- "calls": [
527
- {
528
- "to": "0x0000000000000000000000000000000000000000",
529
- "value": 0n,
530
- },
531
- ],
532
- "chainId": 1,
533
- "gas": 1n,
534
- "maxFeePerGas": 1n,
535
- "maxPriorityFeePerGas": 1n,
536
- "nonce": 0n,
537
- "nonceKey": 0n,
538
- "type": "tempo",
539
- }
540
- `)
541
- })
542
- })
543
-
544
- describe('errors', () => {
545
- test('invalid transaction (all missing)', () => {
546
- expect(() =>
547
- TransactionEnvelopeTempo.deserialize(`0x76${Rlp.fromHex([]).slice(2)}`),
548
- ).toThrowErrorMatchingInlineSnapshot(`
549
- [TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "tempo" was provided.
550
-
551
- Serialized Transaction: "0x76c0"
552
- Missing Attributes: authorizationList, chainId, maxPriorityFeePerGas, maxFeePerGas, gas, calls, accessList, keyAuthorization, nonceKey, nonce, validBefore, validAfter, feeToken, feePayerSignatureOrSender]
553
- `)
554
- })
555
-
556
- test('invalid transaction (some missing)', () => {
557
- expect(() =>
558
- TransactionEnvelopeTempo.deserialize(
559
- `0x76${Rlp.fromHex(['0x00', '0x01']).slice(2)}`,
560
- ),
561
- ).toThrowErrorMatchingInlineSnapshot(`
562
- [TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "tempo" was provided.
563
-
564
- Serialized Transaction: "0x76c20001"
565
- Missing Attributes: authorizationList, maxFeePerGas, gas, calls, accessList, keyAuthorization, nonceKey, nonce, validBefore, validAfter, feeToken, feePayerSignatureOrSender]
566
- `)
567
- })
568
-
569
- test('invalid transaction (empty calls)', () => {
570
- expect(() =>
571
- TransactionEnvelopeTempo.deserialize(
572
- `0x76${Rlp.fromHex([
573
- Hex.fromNumber(1), // chainId
574
- Hex.fromNumber(1), // maxPriorityFeePerGas
575
- Hex.fromNumber(1), // maxFeePerGas
576
- Hex.fromNumber(1), // gas
577
- [], // calls (empty)
578
- '0x', // accessList
579
- Hex.fromNumber(0), // nonceKey
580
- Hex.fromNumber(0), // nonce
581
- '0x', // validBefore
582
- '0x', // validAfter
583
- '0x', // feeToken
584
- '0x', // feePayerSignature
585
- [], // authorizationList
586
- ]).slice(2)}`,
587
- ),
588
- ).toThrowErrorMatchingInlineSnapshot(
589
- `[TransactionEnvelopeTempo.CallsEmptyError: Calls list cannot be empty.]`,
590
- )
591
- })
592
-
593
- test('invalid transaction (too many fields with signature)', () => {
594
- expect(() =>
595
- TransactionEnvelopeTempo.deserialize(
596
- `0x76${Rlp.fromHex([
597
- Hex.fromNumber(1), // chainId
598
- Hex.fromNumber(1), // maxPriorityFeePerGas
599
- Hex.fromNumber(1), // maxFeePerGas
600
- Hex.fromNumber(1), // gas
601
- [
602
- [
603
- '0x0000000000000000000000000000000000000000',
604
- Hex.fromNumber(0),
605
- '0x',
606
- ],
607
- ], // calls
608
- '0x', // accessList
609
- Hex.fromNumber(0), // nonceKey
610
- Hex.fromNumber(0), // nonce
611
- '0x', // validBefore
612
- '0x', // validAfter
613
- '0x', // feeToken
614
- '0x', // feePayerSignature
615
- [], // authorizationList
616
- [], // keyAuthorization
617
- '0x1234', // signature
618
- '0x5678', // extra field
619
- ]).slice(2)}`,
620
- ),
621
- ).toThrowErrorMatchingInlineSnapshot(`
622
- [TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "tempo" was provided.
623
-
624
- Serialized Transaction: "0x76ec01010101d8d7940000000000000000000000000000000000000000008080000080808080c0c0821234825678"]
625
- `)
626
- })
627
- })
628
- })
629
-
630
- describe('from', () => {
631
- test('default', () => {
632
- {
633
- const envelope = TransactionEnvelopeTempo.from({
634
- chainId: 1,
635
- calls: [{}],
636
- nonce: 0n,
637
- nonceKey: 0n,
638
- })
639
- expect(envelope).toMatchInlineSnapshot(`
640
- {
641
- "calls": [
642
- {},
643
- ],
644
- "chainId": 1,
645
- "nonce": 0n,
646
- "nonceKey": 0n,
647
- "type": "tempo",
648
- }
649
- `)
650
- const serialized = TransactionEnvelopeTempo.serialize(envelope)
651
- const envelope2 = TransactionEnvelopeTempo.from(serialized)
652
- expect(envelope2).toEqual(envelope)
653
- }
654
-
655
- {
656
- const envelope = TransactionEnvelopeTempo.from({
657
- chainId: 1,
658
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
659
- nonce: 0n,
660
- nonceKey: 0n,
661
- signature: SignatureEnvelope.from({
662
- r: 0n,
663
- s: 1n,
664
- yParity: 0,
665
- }),
666
- })
667
- expect(envelope).toMatchInlineSnapshot(`
668
- {
669
- "calls": [
670
- {
671
- "to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
672
- },
673
- ],
674
- "chainId": 1,
675
- "nonce": 0n,
676
- "nonceKey": 0n,
677
- "signature": {
678
- "signature": {
679
- "r": 0n,
680
- "s": 1n,
681
- "yParity": 0,
682
- },
683
- "type": "secp256k1",
684
- },
685
- "type": "tempo",
686
- }
687
- `)
688
- const serialized = TransactionEnvelopeTempo.serialize(envelope)
689
- const envelope2 = TransactionEnvelopeTempo.from(serialized)
690
- expect(envelope2).toEqual({
691
- ...envelope,
692
- signature: { ...envelope.signature, type: 'secp256k1' },
693
- })
694
- }
695
- })
696
-
697
- test('options: signature', () => {
698
- const envelope = TransactionEnvelopeTempo.from(
699
- {
700
- chainId: 1,
701
- calls: [{}],
702
- nonce: 0n,
703
- nonceKey: 0n,
704
- },
705
- {
706
- signature: SignatureEnvelope.from({
707
- r: 0n,
708
- s: 1n,
709
- yParity: 0,
710
- }),
711
- },
712
- )
713
- expect(envelope).toMatchInlineSnapshot(`
714
- {
715
- "calls": [
716
- {},
717
- ],
718
- "chainId": 1,
719
- "nonce": 0n,
720
- "nonceKey": 0n,
721
- "signature": {
722
- "signature": {
723
- "r": 0n,
724
- "s": 1n,
725
- "yParity": 0,
726
- },
727
- "type": "secp256k1",
728
- },
729
- "type": "tempo",
730
- }
731
- `)
732
- const serialized = TransactionEnvelopeTempo.serialize(envelope)
733
- const envelope2 = TransactionEnvelopeTempo.from(serialized)
734
- expect(envelope2).toEqual(envelope)
735
- })
736
-
737
- test('options: feePayerSignature', () => {
738
- const envelope = TransactionEnvelopeTempo.from(
739
- {
740
- chainId: 1,
741
- calls: [{}],
742
- nonce: 0n,
743
- r: 1n,
744
- s: 2n,
745
- yParity: 0,
746
- },
747
- {
748
- feePayerSignature: {
749
- r: 0n,
750
- s: 1n,
751
- yParity: 0,
752
- },
753
- },
754
- )
755
- expect(envelope).toMatchInlineSnapshot(`
756
- {
757
- "calls": [
758
- {},
759
- ],
760
- "chainId": 1,
761
- "feePayerSignature": {
762
- "r": 0n,
763
- "s": 1n,
764
- "yParity": 0,
765
- },
766
- "nonce": 0n,
767
- "r": 1n,
768
- "s": 2n,
769
- "type": "tempo",
770
- "yParity": 0,
771
- }
772
- `)
773
- })
774
-
775
- test('options: feePayerSignature (null)', () => {
776
- const envelope = TransactionEnvelopeTempo.from(
777
- {
778
- chainId: 1,
779
- calls: [{}],
780
- nonce: 0n,
781
- },
782
- {
783
- feePayerSignature: null,
784
- },
785
- )
786
- expect(envelope).toMatchInlineSnapshot(`
787
- {
788
- "calls": [
789
- {},
790
- ],
791
- "chainId": 1,
792
- "nonce": 0n,
793
- "type": "tempo",
794
- }
795
- `)
796
- })
797
- })
798
-
799
- describe('serialize', () => {
800
- test('default', () => {
801
- const transaction = TransactionEnvelopeTempo.from({
802
- chainId: 1,
803
- calls: [
804
- {
805
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
806
- },
807
- ],
808
- nonce: 785n,
809
- maxFeePerGas: Value.fromGwei('2'),
810
- maxPriorityFeePerGas: Value.fromGwei('2'),
811
- })
812
- expect(
813
- TransactionEnvelopeTempo.serialize(transaction),
814
- ).toMatchInlineSnapshot(
815
- `"0x76ef018477359400847735940080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c08082031180808080c0"`,
816
- )
817
- })
818
-
819
- test('minimal', () => {
820
- const transaction = TransactionEnvelopeTempo.from({
821
- chainId: 1,
822
- calls: [{}],
823
- nonce: 0n,
824
- })
825
- expect(
826
- TransactionEnvelopeTempo.serialize(transaction),
827
- ).toMatchInlineSnapshot(`"0x76d101808080c4c3808080c0808080808080c0"`)
828
- })
829
-
830
- test('undefined nonceKey', () => {
831
- const transaction = TransactionEnvelopeTempo.from({
832
- chainId: 1,
833
- calls: [{}],
834
- nonce: 0n,
835
- nonceKey: undefined,
836
- })
837
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
838
- expect(serialized).toMatchInlineSnapshot(
839
- `"0x76d101808080c4c3808080c0808080808080c0"`,
840
- )
841
- })
842
-
843
- test('multiple calls', () => {
844
- const transaction = TransactionEnvelopeTempo.from({
845
- chainId: 1,
846
- calls: [
847
- {
848
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
849
- },
850
- {
851
- to: '0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc',
852
- value: Value.from('0.002', 6),
853
- data: '0x1234',
854
- },
855
- ],
856
- nonce: 0n,
857
- })
858
- expect(
859
- TransactionEnvelopeTempo.serialize(transaction),
860
- ).toMatchInlineSnapshot(
861
- `"0x76f84101808080f4d79470997970c51812dc3a010c7d01b50e0d17dc79c88080db943c44cdddb6a900fa2b585dd299e03d12fa4293bc8207d0821234c0808080808080c0"`,
862
- )
863
- })
864
-
865
- test('keyAuthorization (secp256k1)', () => {
866
- const keyAuthorization = KeyAuthorization.from({
867
- address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
868
- expiry: 1234567890,
869
- type: 'secp256k1',
870
- limits: [
871
- {
872
- token: '0x20c0000000000000000000000000000000000001',
873
- limit: Value.from('10', 6),
874
- },
875
- ],
876
- signature: SignatureEnvelope.from({
877
- r: 44944627813007772897391531230081695102703289123332187696115181104739239197517n,
878
- s: 36528503505192438307355164441104001310566505351980369085208178712678799181120n,
879
- yParity: 0,
880
- }),
881
- })
882
-
883
- const transaction = TransactionEnvelopeTempo.from({
884
- chainId: 1,
885
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
886
- nonce: 0n,
887
- keyAuthorization,
888
- })
889
-
890
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
891
- expect(serialized).toMatchInlineSnapshot(
892
- `"0x76f8a201808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080c0f87bf7808094be95c3f554e9fc85ec51be69a3d807a0d55bcf2c84499602d2dad99420c000000000000000000000000000000000000183989680b841635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f05401b"`,
893
- )
894
-
895
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
896
- expect(deserialized.keyAuthorization).toEqual(keyAuthorization)
897
- })
898
-
899
- test('keyAuthorization (p256)', () => {
900
- const keyAuthorization = KeyAuthorization.from({
901
- address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
902
- expiry: 1234567890,
903
- type: 'p256',
904
- limits: [
905
- {
906
- token: '0x20c0000000000000000000000000000000000001',
907
- limit: Value.from('10', 6),
908
- },
909
- ],
910
- signature: SignatureEnvelope.from({
911
- signature: {
912
- r: 92602584010956101470289867944347135737570451066466093224269890121909314569518n,
913
- s: 54171125190222965779385658110416711469231271457324878825831748147306957269813n,
914
- },
915
- publicKey: {
916
- prefix: 4,
917
- x: 78495282704852028275327922540131762143565388050940484317945369745559774511861n,
918
- y: 8109764566587999957624872393871720746996669263962991155166704261108473113504n,
919
- },
920
- prehash: true,
921
- }),
922
- })
923
-
924
- const transaction = TransactionEnvelopeTempo.from({
925
- chainId: 1,
926
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
927
- nonce: 0n,
928
- keyAuthorization,
929
- })
930
-
931
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
932
- expect(serialized).toMatchInlineSnapshot(
933
- `"0x76f8e301808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080c0f8bcf7800194be95c3f554e9fc85ec51be69a3d807a0d55bcf2c84499602d2dad99420c000000000000000000000000000000000000183989680b88201ccbb3485d4726235f13cb15ef394fb7158179fb7b1925eccec0147671090c52e77c3c53373cc1e3b05e7c23f609deb17cea8fe097300c45411237e9fe4166b35ad8ac16e167d6992c3e120d7f17d2376bc1cbcf30c46ba6dd00ce07303e742f511edf6ce1c32de66846f56afa7be1cbd729bc35750b6d0cdcf3ec9d75461aba001"`,
934
- )
935
-
936
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
937
- expect(deserialized.keyAuthorization).toEqual(keyAuthorization)
938
- })
939
-
940
- test('keyAuthorization (webAuthn)', () => {
941
- const metadata = {
942
- authenticatorData: WebAuthnP256.getAuthenticatorData({
943
- rpId: 'localhost',
944
- }),
945
- clientDataJSON: WebAuthnP256.getClientDataJSON({
946
- challenge: '0xdeadbeef',
947
- origin: 'http://localhost',
948
- }),
949
- }
950
-
951
- const keyAuthorization = KeyAuthorization.from({
952
- address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
953
- expiry: 1234567890,
954
- type: 'webAuthn',
955
- limits: [
956
- {
957
- token: '0x20c0000000000000000000000000000000000001',
958
- limit: Value.from('10', 6),
959
- },
960
- ],
961
- signature: SignatureEnvelope.from({
962
- signature: {
963
- r: 92602584010956101470289867944347135737570451066466093224269890121909314569518n,
964
- s: 54171125190222965779385658110416711469231271457324878825831748147306957269813n,
965
- },
966
- publicKey: {
967
- prefix: 4,
968
- x: 78495282704852028275327922540131762143565388050940484317945369745559774511861n,
969
- y: 8109764566587999957624872393871720746996669263962991155166704261108473113504n,
970
- },
971
- metadata,
972
- }),
973
- })
974
-
975
- const transaction = TransactionEnvelopeTempo.from({
976
- chainId: 1,
977
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
978
- nonce: 0n,
979
- keyAuthorization,
980
- })
981
-
982
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
983
- expect(serialized).toMatchInlineSnapshot(
984
- `"0x76f9016501808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080c0f9013df7800294be95c3f554e9fc85ec51be69a3d807a0d55bcf2c84499602d2dad99420c000000000000000000000000000000000000183989680b901020249960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d976305000000007b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a223371322d3777222c226f726967696e223a22687474703a2f2f6c6f63616c686f7374222c2263726f73734f726967696e223a66616c73657dccbb3485d4726235f13cb15ef394fb7158179fb7b1925eccec0147671090c52e77c3c53373cc1e3b05e7c23f609deb17cea8fe097300c45411237e9fe4166b35ad8ac16e167d6992c3e120d7f17d2376bc1cbcf30c46ba6dd00ce07303e742f511edf6ce1c32de66846f56afa7be1cbd729bc35750b6d0cdcf3ec9d75461aba0"`,
985
- )
986
-
987
- // Verify roundtrip
988
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
989
- expect(deserialized.keyAuthorization).toEqual(keyAuthorization)
990
- })
991
-
992
- test('authorizationList (secp256k1)', () => {
993
- const authorizationList = [
994
- AuthorizationTempo.from({
995
- address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
996
- chainId: 1,
997
- nonce: 40n,
998
- signature: SignatureEnvelope.from({
999
- r: 49782753348462494199823712700004552394425719014458918871452329774910450607807n,
1000
- s: 33726695977844476214676913201140481102225469284307016937915595756355928419768n,
1001
- yParity: 0,
1002
- }),
1003
- }),
1004
- AuthorizationTempo.from({
1005
- address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1006
- chainId: 1,
1007
- nonce: 55n,
1008
- signature: SignatureEnvelope.from({
1009
- r: 12345678901234567890n,
1010
- s: 98765432109876543210n,
1011
- yParity: 1,
1012
- }),
1013
- }),
1014
- ] as const
1015
-
1016
- const transaction = TransactionEnvelopeTempo.from({
1017
- chainId: 1,
1018
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1019
- nonce: 0n,
1020
- authorizationList,
1021
- })
1022
-
1023
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
1024
- expect(serialized).toMatchInlineSnapshot(
1025
- `"0x76f8de01808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080f8b8f85a0194be95c3f554e9fc85ec51be69a3d807a0d55bcf2c28b8416e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db81bf85a019470997970c51812dc3a010c7d01b50e0d17dc79c837b841000000000000000000000000000000000000000000000000ab54a98ceb1f0ad20000000000000000000000000000000000000000000000055aa54d38e5267eea1c"`,
1026
- )
1027
-
1028
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
1029
- expect(deserialized.authorizationList).toEqual(authorizationList)
1030
- })
1031
-
1032
- test('authorizationList (multiple types)', () => {
1033
- const privateKey = P256.randomPrivateKey()
1034
- const publicKey = P256.getPublicKey({ privateKey })
1035
-
1036
- const authorization1 = AuthorizationTempo.from({
1037
- address: '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
1038
- chainId: 1,
1039
- nonce: 40n,
1040
- })
1041
- const secp256k1Signature = Secp256k1.sign({
1042
- payload: AuthorizationTempo.getSignPayload(authorization1),
1043
- privateKey,
1044
- })
1045
-
1046
- const authorization2 = AuthorizationTempo.from({
1047
- address: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1048
- chainId: 1,
1049
- nonce: 55n,
1050
- })
1051
- const p256Signature = P256.sign({
1052
- payload: AuthorizationTempo.getSignPayload(authorization2),
1053
- privateKey,
1054
- })
1055
-
1056
- const authorizationList = [
1057
- AuthorizationTempo.from(authorization1, {
1058
- signature: SignatureEnvelope.from({ signature: secp256k1Signature }),
1059
- }),
1060
- AuthorizationTempo.from(authorization2, {
1061
- signature: SignatureEnvelope.from({
1062
- signature: p256Signature,
1063
- publicKey,
1064
- prehash: true,
1065
- }),
1066
- }),
1067
- ]
1068
-
1069
- const transaction = TransactionEnvelopeTempo.from({
1070
- chainId: 1,
1071
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1072
- nonce: 0n,
1073
- authorizationList,
1074
- })
1075
-
1076
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
1077
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
1078
-
1079
- expect(deserialized.authorizationList).toHaveLength(2)
1080
- expect(deserialized.authorizationList?.[0]?.address).toBe(
1081
- '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
1082
- )
1083
- expect(deserialized.authorizationList?.[0]?.signature?.type).toBe(
1084
- 'secp256k1',
1085
- )
1086
- expect(deserialized.authorizationList?.[1]?.address).toBe(
1087
- '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1088
- )
1089
- expect(deserialized.authorizationList?.[1]?.signature?.type).toBe('p256')
1090
- })
1091
-
1092
- test('authorizationList (empty)', () => {
1093
- const transaction = TransactionEnvelopeTempo.from({
1094
- chainId: 1,
1095
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1096
- nonce: 0n,
1097
- authorizationList: [],
1098
- })
1099
-
1100
- const serialized = TransactionEnvelopeTempo.serialize(transaction)
1101
- expect(serialized).toMatchInlineSnapshot(
1102
- `"0x76e501808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080c0"`,
1103
- )
1104
-
1105
- const deserialized = TransactionEnvelopeTempo.deserialize(serialized)
1106
- expect(deserialized.authorizationList).toBeUndefined()
1107
- })
1108
-
1109
- describe('with signature', () => {
1110
- test('secp256k1', () => {
1111
- const transaction = TransactionEnvelopeTempo.from({
1112
- chainId: 1,
1113
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1114
- nonce: 0n,
1115
- })
1116
- const signature = Secp256k1.sign({
1117
- payload: TransactionEnvelopeTempo.getSignPayload(transaction),
1118
- privateKey,
1119
- })
1120
- expect(
1121
- TransactionEnvelopeTempo.serialize(transaction, {
1122
- signature: SignatureEnvelope.from(signature),
1123
- }),
1124
- ).toMatchInlineSnapshot(
1125
- `"0x76f86801808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808080c0b8416b37e17bf41d92dfee5ffdce55431bf01dd7875b2229d6258350c5ee6fe6a54225b867dc1b19c9ec97833ebdccd830d2846c5b724b72dcd754d694d08b5e80ee1c"`,
1126
- )
1127
- })
1128
-
1129
- test('p256', () => {
1130
- const transaction = TransactionEnvelopeTempo.from({
1131
- chainId: 1,
1132
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1133
- nonce: 0n,
1134
- })
1135
- const privateKey = P256.randomPrivateKey()
1136
- const publicKey = P256.getPublicKey({ privateKey })
1137
- const signature = P256.sign({
1138
- payload: TransactionEnvelopeTempo.getSignPayload(transaction),
1139
- privateKey,
1140
- })
1141
- const serialized = TransactionEnvelopeTempo.serialize(transaction, {
1142
- signature: SignatureEnvelope.from({
1143
- signature,
1144
- publicKey,
1145
- prehash: true,
1146
- }),
1147
- })
1148
- // biome-ignore lint/suspicious/noTsIgnore: _
1149
- // @ts-ignore
1150
- delete signature.yParity
1151
- expect(TransactionEnvelopeTempo.deserialize(serialized)).toEqual({
1152
- ...transaction,
1153
- nonceKey: 0n,
1154
- signature: { prehash: true, publicKey, signature, type: 'p256' },
1155
- })
1156
- })
1157
- })
1158
-
1159
- test('with feePayerSignature', () => {
1160
- const transaction = TransactionEnvelopeTempo.from({
1161
- chainId: 1,
1162
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1163
- nonce: 0n,
1164
- })
1165
- expect(
1166
- TransactionEnvelopeTempo.serialize(transaction, {
1167
- feePayerSignature: {
1168
- r: 1n,
1169
- s: 2n,
1170
- yParity: 0,
1171
- },
1172
- }),
1173
- ).toMatchInlineSnapshot(
1174
- `"0x76e801808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c08080808080c3800102c0"`,
1175
- )
1176
- })
1177
-
1178
- test('with feePayerSignature (null)', () => {
1179
- const transaction = TransactionEnvelopeTempo.from({
1180
- chainId: 1,
1181
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1182
- nonce: 0n,
1183
- })
1184
- expect(
1185
- TransactionEnvelopeTempo.serialize(transaction, {
1186
- feePayerSignature: null,
1187
- }),
1188
- ).toMatchInlineSnapshot(
1189
- `"0x76e501808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808000c0"`,
1190
- )
1191
- })
1192
-
1193
- test('format: feePayer', () => {
1194
- const transaction = TransactionEnvelopeTempo.from({
1195
- chainId: 1,
1196
- calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1197
- nonce: 0n,
1198
- })
1199
- expect(
1200
- TransactionEnvelopeTempo.serialize(transaction, {
1201
- sender: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
1202
- format: 'feePayer',
1203
- }),
1204
- ).toMatchInlineSnapshot(
1205
- `"0x78f83901808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c0808080808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266c0"`,
1206
- )
1207
- })
1208
- })
1209
-
1210
- describe('hash', () => {
1211
- describe('default', () => {
1212
- test('secp256k1', () => {
1213
- const transaction = TransactionEnvelopeTempo.from({
1214
- chainId: 1,
1215
- calls: [
1216
- {
1217
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1218
- },
1219
- ],
1220
- nonce: 0n,
1221
- })
1222
- const signature = Secp256k1.sign({
1223
- payload: TransactionEnvelopeTempo.getSignPayload(transaction),
1224
- privateKey,
1225
- })
1226
- const signed = TransactionEnvelopeTempo.from(transaction, {
1227
- signature: SignatureEnvelope.from(signature),
1228
- })
1229
- expect(TransactionEnvelopeTempo.hash(signed)).toMatchInlineSnapshot(
1230
- `"0x04ad27d1607bc3fc37445724d8864b0843f88008bafd818814474e5ee94647eb"`,
1231
- )
1232
- })
1233
- })
1234
-
1235
- test('presign', () => {
1236
- const transaction = TransactionEnvelopeTempo.from({
1237
- chainId: 1,
1238
- calls: [
1239
- {
1240
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1241
- },
1242
- ],
1243
- nonce: 0n,
1244
- })
1245
- expect(
1246
- TransactionEnvelopeTempo.hash(transaction, { presign: true }),
1247
- ).toMatchInlineSnapshot(
1248
- `"0xe1222a45806457acbe3a13940aae4c34f3180659fa16613b5a45dc183adae07c"`,
1249
- )
1250
- })
1251
- })
1252
-
1253
- describe('getSignPayload', () => {
1254
- test('default', () => {
1255
- const transaction = TransactionEnvelopeTempo.from({
1256
- chainId: 1,
1257
- calls: [
1258
- {
1259
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1260
- },
1261
- ],
1262
- nonce: 0n,
1263
- })
1264
- expect(
1265
- TransactionEnvelopeTempo.getSignPayload(transaction),
1266
- ).toMatchInlineSnapshot(
1267
- `"0xe1222a45806457acbe3a13940aae4c34f3180659fa16613b5a45dc183adae07c"`,
1268
- )
1269
- })
1270
- })
1271
-
1272
- describe('getFeePayerSignPayload', () => {
1273
- test('default', () => {
1274
- const transaction = TransactionEnvelopeTempo.from({
1275
- chainId: 1,
1276
- calls: [
1277
- {
1278
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1279
- },
1280
- ],
1281
- nonce: 0n,
1282
- })
1283
- expect(
1284
- TransactionEnvelopeTempo.getFeePayerSignPayload(transaction, {
1285
- sender: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
1286
- }),
1287
- ).toMatchInlineSnapshot(
1288
- `"0xde7a88984d766d0f5aac705487b43e68261516d6e7c524698804d4970d39d77d"`,
1289
- )
1290
- })
1291
-
1292
- test('with feeToken', () => {
1293
- const transaction = TransactionEnvelopeTempo.from({
1294
- chainId: 1,
1295
- calls: [
1296
- {
1297
- to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
1298
- },
1299
- ],
1300
- nonce: 0n,
1301
- feeToken: '0x20c0000000000000000000000000000000000000',
1302
- })
1303
- const hash1 = TransactionEnvelopeTempo.getFeePayerSignPayload(transaction, {
1304
- sender: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
1305
- })
1306
-
1307
- // Change feeToken - hash should be different
1308
- const transaction2 = TransactionEnvelopeTempo.from({
1309
- ...transaction,
1310
- feeToken: '0x20c0000000000000000000000000000000000001',
1311
- })
1312
- const hash2 = TransactionEnvelopeTempo.getFeePayerSignPayload(
1313
- transaction2,
1314
- {
1315
- sender: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
1316
- },
1317
- )
1318
-
1319
- expect(hash1).not.toBe(hash2)
1320
- })
1321
- })
1322
-
1323
- describe('validate', () => {
1324
- test('valid', () => {
1325
- expect(
1326
- TransactionEnvelopeTempo.validate({
1327
- calls: [{ to: '0x0000000000000000000000000000000000000000' }],
1328
- chainId: 1,
1329
- }),
1330
- ).toBe(true)
1331
- })
1332
-
1333
- test('invalid (empty calls)', () => {
1334
- expect(
1335
- TransactionEnvelopeTempo.validate({
1336
- calls: [],
1337
- chainId: 1,
1338
- }),
1339
- ).toBe(false)
1340
- })
1341
-
1342
- test('invalid (validity window)', () => {
1343
- expect(
1344
- TransactionEnvelopeTempo.validate({
1345
- calls: [{ to: '0x0000000000000000000000000000000000000000' }],
1346
- chainId: 1,
1347
- validBefore: 100,
1348
- validAfter: 200,
1349
- }),
1350
- ).toBe(false)
1351
- })
1352
- })