ox 0.14.65 → 0.14.67

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 (173) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/_cjs/core/AbiError.js +25 -4
  3. package/_cjs/core/AbiError.js.map +1 -1
  4. package/_cjs/core/AbiEvent.js +18 -3
  5. package/_cjs/core/AbiEvent.js.map +1 -1
  6. package/_cjs/core/AbiFunction.js +27 -3
  7. package/_cjs/core/AbiFunction.js.map +1 -1
  8. package/_cjs/core/Address.js +1 -0
  9. package/_cjs/core/Address.js.map +1 -1
  10. package/_cjs/core/Authorization.js +29 -2
  11. package/_cjs/core/Authorization.js.map +1 -1
  12. package/_cjs/core/Keystore.js +18 -0
  13. package/_cjs/core/Keystore.js.map +1 -1
  14. package/_cjs/core/Secp256k1.js +5 -1
  15. package/_cjs/core/Secp256k1.js.map +1 -1
  16. package/_cjs/core/Signature.js +4 -2
  17. package/_cjs/core/Signature.js.map +1 -1
  18. package/_cjs/core/Siwe.js +22 -3
  19. package/_cjs/core/Siwe.js.map +1 -1
  20. package/_cjs/core/TxEnvelopeEip1559.js +2 -1
  21. package/_cjs/core/TxEnvelopeEip1559.js.map +1 -1
  22. package/_cjs/core/TxEnvelopeEip2930.js +2 -1
  23. package/_cjs/core/TxEnvelopeEip2930.js.map +1 -1
  24. package/_cjs/core/TxEnvelopeEip7702.js +5 -1
  25. package/_cjs/core/TxEnvelopeEip7702.js.map +1 -1
  26. package/_cjs/core/TxEnvelopeLegacy.js +41 -8
  27. package/_cjs/core/TxEnvelopeLegacy.js.map +1 -1
  28. package/_cjs/core/TypedData.js +7 -9
  29. package/_cjs/core/TypedData.js.map +1 -1
  30. package/_cjs/core/Value.js +8 -3
  31. package/_cjs/core/Value.js.map +1 -1
  32. package/_cjs/core/internal/abiParameters.js +6 -2
  33. package/_cjs/core/internal/abiParameters.js.map +1 -1
  34. package/_cjs/core/internal/cursor.js +30 -1
  35. package/_cjs/core/internal/cursor.js.map +1 -1
  36. package/_cjs/erc4337/UserOperation.js +1 -1
  37. package/_cjs/erc4337/UserOperation.js.map +1 -1
  38. package/_cjs/erc7821/Execute.js +41 -3
  39. package/_cjs/erc7821/Execute.js.map +1 -1
  40. package/_cjs/tempo/KeyAuthorization.js +22 -1
  41. package/_cjs/tempo/KeyAuthorization.js.map +1 -1
  42. package/_cjs/tempo/SignatureEnvelope.js +44 -50
  43. package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
  44. package/_cjs/tempo/TxEnvelopeTempo.js +34 -3
  45. package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
  46. package/_cjs/tempo/internal/webauthnData.js +57 -0
  47. package/_cjs/tempo/internal/webauthnData.js.map +1 -0
  48. package/_cjs/version.js +1 -1
  49. package/_cjs/webauthn/Registration.js +2 -6
  50. package/_cjs/webauthn/Registration.js.map +1 -1
  51. package/_esm/core/AbiError.js +64 -3
  52. package/_esm/core/AbiError.js.map +1 -1
  53. package/_esm/core/AbiEvent.js +24 -3
  54. package/_esm/core/AbiEvent.js.map +1 -1
  55. package/_esm/core/AbiFunction.js +64 -3
  56. package/_esm/core/AbiFunction.js.map +1 -1
  57. package/_esm/core/Address.js +17 -1
  58. package/_esm/core/Address.js.map +1 -1
  59. package/_esm/core/Authorization.js +47 -2
  60. package/_esm/core/Authorization.js.map +1 -1
  61. package/_esm/core/Keystore.js +33 -2
  62. package/_esm/core/Keystore.js.map +1 -1
  63. package/_esm/core/Secp256k1.js +5 -1
  64. package/_esm/core/Secp256k1.js.map +1 -1
  65. package/_esm/core/Signature.js +4 -2
  66. package/_esm/core/Signature.js.map +1 -1
  67. package/_esm/core/Siwe.js +29 -3
  68. package/_esm/core/Siwe.js.map +1 -1
  69. package/_esm/core/TxEnvelopeEip1559.js +2 -1
  70. package/_esm/core/TxEnvelopeEip1559.js.map +1 -1
  71. package/_esm/core/TxEnvelopeEip2930.js +2 -1
  72. package/_esm/core/TxEnvelopeEip2930.js.map +1 -1
  73. package/_esm/core/TxEnvelopeEip7702.js +6 -1
  74. package/_esm/core/TxEnvelopeEip7702.js.map +1 -1
  75. package/_esm/core/TxEnvelopeLegacy.js +49 -9
  76. package/_esm/core/TxEnvelopeLegacy.js.map +1 -1
  77. package/_esm/core/TypedData.js +9 -9
  78. package/_esm/core/TypedData.js.map +1 -1
  79. package/_esm/core/Value.js +14 -3
  80. package/_esm/core/Value.js.map +1 -1
  81. package/_esm/core/internal/abiParameters.js +9 -2
  82. package/_esm/core/internal/abiParameters.js.map +1 -1
  83. package/_esm/core/internal/cursor.js +32 -0
  84. package/_esm/core/internal/cursor.js.map +1 -1
  85. package/_esm/erc4337/UserOperation.js +1 -1
  86. package/_esm/erc4337/UserOperation.js.map +1 -1
  87. package/_esm/erc7821/Execute.js +76 -2
  88. package/_esm/erc7821/Execute.js.map +1 -1
  89. package/_esm/index.js +1 -1
  90. package/_esm/tempo/KeyAuthorization.js +21 -0
  91. package/_esm/tempo/KeyAuthorization.js.map +1 -1
  92. package/_esm/tempo/SignatureEnvelope.js +53 -54
  93. package/_esm/tempo/SignatureEnvelope.js.map +1 -1
  94. package/_esm/tempo/TxEnvelopeTempo.js +56 -2
  95. package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
  96. package/_esm/tempo/internal/webauthnData.js +79 -0
  97. package/_esm/tempo/internal/webauthnData.js.map +1 -0
  98. package/_esm/version.js +1 -1
  99. package/_esm/webauthn/Registration.js +2 -6
  100. package/_esm/webauthn/Registration.js.map +1 -1
  101. package/_types/core/AbiError.d.ts +51 -5
  102. package/_types/core/AbiError.d.ts.map +1 -1
  103. package/_types/core/AbiEvent.d.ts +4 -2
  104. package/_types/core/AbiEvent.d.ts.map +1 -1
  105. package/_types/core/AbiFunction.d.ts +48 -2
  106. package/_types/core/AbiFunction.d.ts.map +1 -1
  107. package/_types/core/Address.d.ts +17 -2
  108. package/_types/core/Address.d.ts.map +1 -1
  109. package/_types/core/Authorization.d.ts +24 -2
  110. package/_types/core/Authorization.d.ts.map +1 -1
  111. package/_types/core/Keystore.d.ts +31 -2
  112. package/_types/core/Keystore.d.ts.map +1 -1
  113. package/_types/core/Secp256k1.d.ts.map +1 -1
  114. package/_types/core/Signature.d.ts +1 -1
  115. package/_types/core/Signature.d.ts.map +1 -1
  116. package/_types/core/Siwe.d.ts +4 -0
  117. package/_types/core/Siwe.d.ts.map +1 -1
  118. package/_types/core/TxEnvelopeEip1559.d.ts.map +1 -1
  119. package/_types/core/TxEnvelopeEip2930.d.ts.map +1 -1
  120. package/_types/core/TxEnvelopeEip7702.d.ts +1 -1
  121. package/_types/core/TxEnvelopeEip7702.d.ts.map +1 -1
  122. package/_types/core/TxEnvelopeLegacy.d.ts.map +1 -1
  123. package/_types/core/TypedData.d.ts +3 -1
  124. package/_types/core/TypedData.d.ts.map +1 -1
  125. package/_types/core/Value.d.ts.map +1 -1
  126. package/_types/core/internal/abiParameters.d.ts +1 -1
  127. package/_types/core/internal/abiParameters.d.ts.map +1 -1
  128. package/_types/core/internal/cursor.d.ts +13 -0
  129. package/_types/core/internal/cursor.d.ts.map +1 -1
  130. package/_types/erc7821/Execute.d.ts +46 -1
  131. package/_types/erc7821/Execute.d.ts.map +1 -1
  132. package/_types/index.d.ts +1 -1
  133. package/_types/tempo/KeyAuthorization.d.ts +9 -3
  134. package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
  135. package/_types/tempo/SignatureEnvelope.d.ts +1 -1
  136. package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
  137. package/_types/tempo/TxEnvelopeTempo.d.ts +30 -1
  138. package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  139. package/_types/tempo/internal/webauthnData.d.ts +26 -0
  140. package/_types/tempo/internal/webauthnData.d.ts.map +1 -0
  141. package/_types/version.d.ts +1 -1
  142. package/_types/webauthn/Registration.d.ts +2 -0
  143. package/_types/webauthn/Registration.d.ts.map +1 -1
  144. package/core/AbiError.ts +81 -7
  145. package/core/AbiEvent.ts +50 -11
  146. package/core/AbiFunction.ts +76 -4
  147. package/core/Address.ts +18 -1
  148. package/core/Authorization.ts +47 -4
  149. package/core/Keystore.ts +40 -3
  150. package/core/Secp256k1.ts +5 -1
  151. package/core/Signature.ts +7 -2
  152. package/core/Siwe.ts +29 -3
  153. package/core/TxEnvelopeEip1559.ts +4 -1
  154. package/core/TxEnvelopeEip2930.ts +4 -1
  155. package/core/TxEnvelopeEip7702.ts +9 -2
  156. package/core/TxEnvelopeLegacy.ts +56 -10
  157. package/core/TypedData.ts +10 -9
  158. package/core/Value.ts +14 -3
  159. package/core/internal/abiParameters.ts +8 -2
  160. package/core/internal/cursor.ts +36 -0
  161. package/erc4337/UserOperation.ts +1 -1
  162. package/erc7821/Execute.ts +84 -3
  163. package/index.ts +1 -1
  164. package/package.json +1 -1
  165. package/tempo/KeyAuthorization.test.ts +91 -0
  166. package/tempo/KeyAuthorization.ts +32 -3
  167. package/tempo/SignatureEnvelope.test.ts +300 -28
  168. package/tempo/SignatureEnvelope.ts +62 -54
  169. package/tempo/TxEnvelopeTempo.test.ts +310 -0
  170. package/tempo/TxEnvelopeTempo.ts +64 -1
  171. package/tempo/internal/webauthnData.ts +89 -0
  172. package/version.ts +1 -1
  173. package/webauthn/Registration.ts +4 -6
@@ -66,6 +66,50 @@ describe('assert', () => {
66
66
  )
67
67
  })
68
68
 
69
+ test('invalid validity bound', () => {
70
+ const envelope = {
71
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
72
+ chainId: 1,
73
+ } as const
74
+ expect(() =>
75
+ TxEnvelopeTempo.assert({
76
+ ...envelope,
77
+ validBefore: 1700003600n as never,
78
+ }),
79
+ ).toThrowErrorMatchingInlineSnapshot(
80
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
81
+ )
82
+ expect(() =>
83
+ TxEnvelopeTempo.assert({
84
+ ...envelope,
85
+ validAfter: '0x6553f100' as never,
86
+ }),
87
+ ).toThrowErrorMatchingInlineSnapshot(
88
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validAfter ("0x6553f100") must be a non-negative safe integer number.]`,
89
+ )
90
+ expect(() =>
91
+ TxEnvelopeTempo.assert({ ...envelope, validBefore: -1 }),
92
+ ).toThrowErrorMatchingInlineSnapshot(
93
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (-1) must be a non-negative safe integer number.]`,
94
+ )
95
+ expect(() =>
96
+ TxEnvelopeTempo.assert({ ...envelope, validAfter: 1.5 }),
97
+ ).toThrowErrorMatchingInlineSnapshot(
98
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validAfter (1.5) must be a non-negative safe integer number.]`,
99
+ )
100
+ expect(() =>
101
+ TxEnvelopeTempo.assert({
102
+ ...envelope,
103
+ validBefore: Number.MAX_SAFE_INTEGER + 1,
104
+ }),
105
+ ).toThrowErrorMatchingInlineSnapshot(
106
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (9007199254740992) must be a non-negative safe integer number.]`,
107
+ )
108
+ expect(() =>
109
+ TxEnvelopeTempo.assert({ ...envelope, validAfter: 0, validBefore: 1 }),
110
+ ).not.toThrow()
111
+ })
112
+
69
113
  test('invalid call address', () => {
70
114
  expect(() =>
71
115
  TxEnvelopeTempo.assert({
@@ -129,6 +173,93 @@ describe('assert', () => {
129
173
  `[TransactionEnvelope.InvalidChainIdError: Chain ID "0" is invalid.]`,
130
174
  )
131
175
  })
176
+
177
+ test('invalid chain id (not a positive safe integer)', () => {
178
+ expect(() =>
179
+ TxEnvelopeTempo.assert({
180
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
181
+ chainId: Number.NaN,
182
+ }),
183
+ ).toThrowErrorMatchingInlineSnapshot(
184
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "NaN" is invalid.]`,
185
+ )
186
+ expect(() =>
187
+ TxEnvelopeTempo.assert({
188
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
189
+ chainId: 1.5,
190
+ }),
191
+ ).toThrowErrorMatchingInlineSnapshot(
192
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1.5" is invalid.]`,
193
+ )
194
+ expect(() =>
195
+ TxEnvelopeTempo.assert({
196
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
197
+ chainId: Number.MAX_SAFE_INTEGER + 1,
198
+ }),
199
+ ).toThrowErrorMatchingInlineSnapshot(
200
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "9007199254740992" is invalid.]`,
201
+ )
202
+ expect(() =>
203
+ TxEnvelopeTempo.assert({
204
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
205
+ chainId: '1' as never,
206
+ }),
207
+ ).toThrowErrorMatchingInlineSnapshot(
208
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
209
+ )
210
+ expect(() =>
211
+ TxEnvelopeTempo.assert({
212
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
213
+ chainId: 1n as never,
214
+ }),
215
+ ).toThrowErrorMatchingInlineSnapshot(
216
+ `[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
217
+ )
218
+ })
219
+
220
+ test('invalid fee payer signature', () => {
221
+ const envelope = {
222
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
223
+ chainId: 1,
224
+ } as const
225
+ const feePayerSignature = {
226
+ r: 1n,
227
+ s: 1n,
228
+ } as const
229
+ expect(() =>
230
+ TxEnvelopeTempo.assert({
231
+ ...envelope,
232
+ feePayerSignature: { ...feePayerSignature, yParity: 2 },
233
+ }),
234
+ ).toThrowErrorMatchingInlineSnapshot(
235
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
236
+ )
237
+ expect(() =>
238
+ TxEnvelopeTempo.assert({
239
+ ...envelope,
240
+ feePayerSignature: { ...feePayerSignature, yParity: 27 },
241
+ }),
242
+ ).toThrowErrorMatchingInlineSnapshot(
243
+ `[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
244
+ )
245
+ expect(() =>
246
+ TxEnvelopeTempo.assert({
247
+ ...envelope,
248
+ feePayerSignature: feePayerSignature as never,
249
+ }),
250
+ ).toThrowErrorMatchingInlineSnapshot(
251
+ `[Signature.MissingPropertiesError: Signature \`{"r":"1#__bigint","s":"1#__bigint"}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.]`,
252
+ )
253
+ expect(() =>
254
+ TxEnvelopeTempo.assert({
255
+ ...envelope,
256
+ feePayerSignature: { ...feePayerSignature, yParity: 1 },
257
+ }),
258
+ ).not.toThrow()
259
+ expect(() =>
260
+ TxEnvelopeTempo.assert({ ...envelope, feePayerSignature: null }),
261
+ ).not.toThrow()
262
+ })
132
263
  })
133
264
 
134
265
  describe('deserialize', () => {
@@ -818,6 +949,19 @@ describe('from', () => {
818
949
  expect(envelope.from).toBe(Address.checksum(hexAddr))
819
950
  })
820
951
 
952
+ test('invalid validity bound', () => {
953
+ expect(() =>
954
+ TxEnvelopeTempo.from({
955
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
956
+ chainId: 1,
957
+ validAfter: 1700000000n as never,
958
+ validBefore: 1700003600n as never,
959
+ }),
960
+ ).toThrowErrorMatchingInlineSnapshot(
961
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
962
+ )
963
+ })
964
+
821
965
  test('options: signature', () => {
822
966
  const envelope = TxEnvelopeTempo.from(
823
967
  {
@@ -954,6 +1098,23 @@ describe('from', () => {
954
1098
  }
955
1099
  `)
956
1100
  })
1101
+
1102
+ test('invalid fee payer signature', () => {
1103
+ expect(() =>
1104
+ TxEnvelopeTempo.from({
1105
+ calls: [{}],
1106
+ chainId: 1,
1107
+ feePayerSignature: {
1108
+ r: 1n,
1109
+ s: 1n,
1110
+ yParity: 2,
1111
+ },
1112
+ nonce: 0n,
1113
+ }),
1114
+ ).toThrowErrorMatchingInlineSnapshot(
1115
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1116
+ )
1117
+ })
957
1118
  })
958
1119
 
959
1120
  describe('serialize', () => {
@@ -998,6 +1159,40 @@ describe('serialize', () => {
998
1159
  )
999
1160
  })
1000
1161
 
1162
+ test('validBefore and validAfter', () => {
1163
+ const transaction = {
1164
+ chainId: 1,
1165
+ calls: [{}],
1166
+ nonce: 0n,
1167
+ } as const
1168
+ expect(
1169
+ TxEnvelopeTempo.serialize({
1170
+ ...transaction,
1171
+ validAfter: 1700000000,
1172
+ validBefore: 1700003600,
1173
+ }),
1174
+ ).toMatchInlineSnapshot(
1175
+ `"0x76d901808080c4c3808080c08080846553ff10846553f1008080c0"`,
1176
+ )
1177
+ expect(() =>
1178
+ TxEnvelopeTempo.serialize({
1179
+ ...transaction,
1180
+ validAfter: 1700000000n as never,
1181
+ validBefore: 1700003600n as never,
1182
+ }),
1183
+ ).toThrowErrorMatchingInlineSnapshot(
1184
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
1185
+ )
1186
+ expect(() =>
1187
+ TxEnvelopeTempo.serialize({
1188
+ ...transaction,
1189
+ validBefore: '0x6553ff10' as never,
1190
+ }),
1191
+ ).toThrowErrorMatchingInlineSnapshot(
1192
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore ("0x6553ff10") must be a non-negative safe integer number.]`,
1193
+ )
1194
+ })
1195
+
1001
1196
  test('multiple calls', () => {
1002
1197
  const transaction = TxEnvelopeTempo.from({
1003
1198
  chainId: 1,
@@ -1350,6 +1545,47 @@ describe('serialize', () => {
1350
1545
  )
1351
1546
  })
1352
1547
 
1548
+ test('with feePayerSignature (invalid yParity)', () => {
1549
+ const transaction = {
1550
+ calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1551
+ chainId: 1,
1552
+ nonce: 0n,
1553
+ } as const
1554
+ const feePayerSignature = {
1555
+ r: 1n,
1556
+ s: 1n,
1557
+ } as const
1558
+ expect(
1559
+ TxEnvelopeTempo.serialize(transaction, {
1560
+ feePayerSignature: { ...feePayerSignature, yParity: 1 },
1561
+ }),
1562
+ ).toMatchInlineSnapshot(
1563
+ `"0x76e801808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c08080808080c3010101c0"`,
1564
+ )
1565
+ expect(() =>
1566
+ TxEnvelopeTempo.serialize(transaction, {
1567
+ feePayerSignature: { ...feePayerSignature, yParity: 2 },
1568
+ }),
1569
+ ).toThrowErrorMatchingInlineSnapshot(
1570
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1571
+ )
1572
+ expect(() =>
1573
+ TxEnvelopeTempo.serialize(transaction, {
1574
+ feePayerSignature: { ...feePayerSignature, yParity: 27 },
1575
+ }),
1576
+ ).toThrowErrorMatchingInlineSnapshot(
1577
+ `[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1578
+ )
1579
+ expect(() =>
1580
+ TxEnvelopeTempo.serialize({
1581
+ ...transaction,
1582
+ feePayerSignature: { ...feePayerSignature, yParity: 2 },
1583
+ }),
1584
+ ).toThrowErrorMatchingInlineSnapshot(
1585
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1586
+ )
1587
+ })
1588
+
1353
1589
  test('format: feePayer', () => {
1354
1590
  const transaction = TxEnvelopeTempo.from({
1355
1591
  chainId: 1,
@@ -1475,6 +1711,24 @@ describe('hash', () => {
1475
1711
  })
1476
1712
  })
1477
1713
 
1714
+ test('invalid fee payer signature', () => {
1715
+ expect(() =>
1716
+ TxEnvelopeTempo.hash({
1717
+ calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1718
+ chainId: 1,
1719
+ feePayerSignature: {
1720
+ r: 1n,
1721
+ s: 1n,
1722
+ yParity: 2,
1723
+ },
1724
+ nonce: 0n,
1725
+ type: 'tempo',
1726
+ } as never),
1727
+ ).toThrowErrorMatchingInlineSnapshot(
1728
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1729
+ )
1730
+ })
1731
+
1478
1732
  test('presign', () => {
1479
1733
  const transaction = TxEnvelopeTempo.from({
1480
1734
  chainId: 1,
@@ -1491,6 +1745,23 @@ describe('hash', () => {
1491
1745
  `"0xe1222a45806457acbe3a13940aae4c34f3180659fa16613b5a45dc183adae07c"`,
1492
1746
  )
1493
1747
  })
1748
+
1749
+ test('invalid validity bound', () => {
1750
+ expect(() =>
1751
+ TxEnvelopeTempo.hash(
1752
+ {
1753
+ calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1754
+ chainId: 1,
1755
+ nonce: 0n,
1756
+ type: 'tempo',
1757
+ validBefore: 1700003600n as never,
1758
+ },
1759
+ { presign: true },
1760
+ ),
1761
+ ).toThrowErrorMatchingInlineSnapshot(
1762
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
1763
+ )
1764
+ })
1494
1765
  })
1495
1766
 
1496
1767
  describe('encodeForSigning', () => {
@@ -1592,6 +1863,20 @@ describe('getSignPayload', () => {
1592
1863
  })
1593
1864
  expect(hashTempo).toBe(hashHex)
1594
1865
  })
1866
+
1867
+ test('invalid validity bound', () => {
1868
+ expect(() =>
1869
+ TxEnvelopeTempo.getSignPayload({
1870
+ calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1871
+ chainId: 1,
1872
+ nonce: 0n,
1873
+ type: 'tempo',
1874
+ validBefore: 1700003600n as never,
1875
+ }),
1876
+ ).toThrowErrorMatchingInlineSnapshot(
1877
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
1878
+ )
1879
+ })
1595
1880
  })
1596
1881
 
1597
1882
  describe('getFeePayerSignPayload', () => {
@@ -1684,6 +1969,20 @@ describe('validate', () => {
1684
1969
  ).toBe(false)
1685
1970
  })
1686
1971
 
1972
+ test('invalid (fee payer signature)', () => {
1973
+ expect(
1974
+ TxEnvelopeTempo.validate({
1975
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
1976
+ chainId: 1,
1977
+ feePayerSignature: {
1978
+ r: 1n,
1979
+ s: 1n,
1980
+ yParity: 2,
1981
+ },
1982
+ }),
1983
+ ).toBe(false)
1984
+ })
1985
+
1687
1986
  test('invalid (validity window)', () => {
1688
1987
  expect(
1689
1988
  TxEnvelopeTempo.validate({
@@ -1694,4 +1993,15 @@ describe('validate', () => {
1694
1993
  }),
1695
1994
  ).toBe(false)
1696
1995
  })
1996
+
1997
+ test('invalid (validity bound)', () => {
1998
+ expect(
1999
+ TxEnvelopeTempo.validate({
2000
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
2001
+ chainId: 1,
2002
+ validBefore: 100n as never,
2003
+ validAfter: 200n as never,
2004
+ }),
2005
+ ).toBe(false)
2006
+ })
1697
2007
  })
@@ -178,6 +178,7 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
178
178
  const {
179
179
  calls,
180
180
  chainId,
181
+ feePayerSignature,
181
182
  maxFeePerGas,
182
183
  maxPriorityFeePerGas,
183
184
  validBefore,
@@ -187,6 +188,18 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
187
188
  // Calls must not be empty
188
189
  if (!calls || calls.length === 0) throw new CallsEmptyError()
189
190
 
191
+ // validBefore and validAfter must be non-negative safe integers if set
192
+ for (const [name, value] of [
193
+ ['validBefore', validBefore],
194
+ ['validAfter', validAfter],
195
+ ] as const)
196
+ if (
197
+ value !== undefined &&
198
+ value !== null &&
199
+ !(Number.isSafeInteger(value) && value >= 0)
200
+ )
201
+ throw new InvalidValidityBoundError({ name, value })
202
+
190
203
  // validBefore must be greater than validAfter if both are set
191
204
  if (
192
205
  typeof validBefore === 'number' &&
@@ -205,7 +218,10 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
205
218
  if (call.to) Address.assert(call.to, { strict: false })
206
219
 
207
220
  // Validate chain ID
208
- if (chainId <= 0)
221
+ if (
222
+ typeof chainId !== 'undefined' &&
223
+ (!Number.isSafeInteger(chainId) || chainId <= 0)
224
+ )
209
225
  throw new TransactionEnvelope.InvalidChainIdError({ chainId })
210
226
 
211
227
  // Validate max fee per gas
@@ -223,13 +239,19 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
223
239
  maxFeePerGas,
224
240
  maxPriorityFeePerGas,
225
241
  })
242
+
243
+ // Validate fee payer signature
244
+ if (feePayerSignature)
245
+ Signature.assert(feePayerSignature, { recovered: true })
226
246
  }
227
247
 
228
248
  export declare namespace assert {
229
249
  type ErrorType =
230
250
  | Address.assert.ErrorType
231
251
  | CallsEmptyError
252
+ | InvalidValidityBoundError
232
253
  | InvalidValidityWindowError
254
+ | Signature.assert.ErrorType
233
255
  | Errors.GlobalErrorType
234
256
  }
235
257
 
@@ -708,6 +730,7 @@ export function serialize(
708
730
  // No fee payer involvement — omit from the envelope.
709
731
  if (!feePayerSignature) return '0x'
710
732
  // Fee payer has signed — encode the signature as an RLP tuple.
733
+ Signature.assert(feePayerSignature, { recovered: true })
711
734
  return Signature.toTuple(feePayerSignature)
712
735
  })()
713
736
 
@@ -1073,6 +1096,46 @@ export class CallsEmptyError extends Errors.BaseError {
1073
1096
  }
1074
1097
  }
1075
1098
 
1099
+ /**
1100
+ * Thrown when validBefore or validAfter is not a non-negative safe integer number.
1101
+ *
1102
+ * @example
1103
+ * ```ts twoslash
1104
+ * import { Address } from 'ox'
1105
+ * import { TxEnvelopeTempo } from 'ox/tempo'
1106
+ *
1107
+ * TxEnvelopeTempo.assert({
1108
+ * calls: [
1109
+ * {
1110
+ * to: Address.from(
1111
+ * '0x0000000000000000000000000000000000000000'
1112
+ * )
1113
+ * }
1114
+ * ],
1115
+ * chainId: 1,
1116
+ * validBefore: -1
1117
+ * })
1118
+ * // @error: TxEnvelopeTempo.InvalidValidityBoundError: validBefore (-1) must be a non-negative safe integer number.
1119
+ * ```
1120
+ */
1121
+ export class InvalidValidityBoundError extends Errors.BaseError {
1122
+ override readonly name = 'TxEnvelopeTempo.InvalidValidityBoundError'
1123
+ constructor({
1124
+ name,
1125
+ value,
1126
+ }: {
1127
+ name: 'validAfter' | 'validBefore'
1128
+ value: unknown
1129
+ }) {
1130
+ const value_ = (() => {
1131
+ if (typeof value === 'bigint') return `${value}n`
1132
+ if (typeof value === 'string') return `"${value}"`
1133
+ return String(value)
1134
+ })()
1135
+ super(`${name} (${value_}) must be a non-negative safe integer number.`)
1136
+ }
1137
+ }
1138
+
1076
1139
  /**
1077
1140
  * Thrown when validBefore is not greater than validAfter.
1078
1141
  *
@@ -0,0 +1,89 @@
1
+ import * as Bytes from '../../core/Bytes.js'
2
+ import * as Hex from '../../core/Hex.js'
3
+
4
+ /** Minimum size of `authenticatorData`: rpIdHash (32) + flags (1) + signCount (4). */
5
+ const minAuthenticatorDataSize = 37
6
+
7
+ const backslash = 0x5c
8
+ const closeBrace = 0x7d
9
+ const openBrace = 0x7b
10
+ const quote = 0x22
11
+
12
+ /**
13
+ * Splits WebAuthn data (`authenticatorData || clientDataJSON`) into its parts.
14
+ *
15
+ * `clientDataJSON` is the JSON object that ends at the last byte, so its
16
+ * opening brace is the one that pairs with the last byte. One backward pass
17
+ * finds that brace and one `JSON.parse` validates the object, which keeps the
18
+ * work linear in the size of the data.
19
+ *
20
+ * @param webauthnData - The concatenated WebAuthn data.
21
+ * @returns The parts, or `undefined` when the data does not end with a JSON
22
+ * object that starts at or after byte 37.
23
+ *
24
+ * @internal
25
+ */
26
+ export function split(webauthnData: Hex.Hex): split.ReturnType | undefined {
27
+ if (Hex.size(webauthnData) <= minAuthenticatorDataSize) return undefined
28
+
29
+ // `clientDataJSON` starts after the minimum `authenticatorData`.
30
+ const bytes = Bytes.fromHex(Hex.slice(webauthnData, minAuthenticatorDataSize))
31
+ const start = objectStart(bytes)
32
+ if (start === -1) return undefined
33
+
34
+ const clientDataJSON = Bytes.toString(bytes.subarray(start))
35
+ try {
36
+ JSON.parse(clientDataJSON)
37
+ } catch {
38
+ return undefined
39
+ }
40
+ return {
41
+ authenticatorData: Hex.slice(
42
+ webauthnData,
43
+ 0,
44
+ minAuthenticatorDataSize + start,
45
+ ),
46
+ clientDataJSON,
47
+ }
48
+ }
49
+
50
+ /** @internal */
51
+ export declare namespace split {
52
+ type ReturnType = {
53
+ /** Authenticator data. */
54
+ authenticatorData: Hex.Hex
55
+ /** Client data JSON. */
56
+ clientDataJSON: string
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Finds the opening brace that pairs with a closing brace in the last byte,
62
+ * or returns `-1`. Scans bytes rather than characters: UTF-8 never encodes a
63
+ * multi-byte character with an ASCII byte, so each structural byte is a
64
+ * structural character.
65
+ *
66
+ * @internal
67
+ */
68
+ function objectStart(bytes: Bytes.Bytes) {
69
+ if (bytes[bytes.length - 1] !== closeBrace) return -1
70
+
71
+ let depth = 0
72
+ let inString = false
73
+ for (let i = bytes.length - 1; i >= 0; i--) {
74
+ const byte = bytes[i]
75
+ if (byte === quote) {
76
+ if (inString) {
77
+ // A quote inside a string follows an odd number of backslashes.
78
+ let escapes = 0
79
+ while (bytes[i - 1 - escapes] === backslash) escapes++
80
+ i -= escapes
81
+ if (escapes % 2 === 1) continue
82
+ }
83
+ inString = !inString
84
+ } else if (inString) continue
85
+ else if (byte === closeBrace) depth++
86
+ else if (byte === openBrace && --depth === 0) return i
87
+ }
88
+ return -1
89
+ }
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.14.65'
2
+ export const version = '0.14.67'
@@ -30,7 +30,9 @@ export type Response<serialized extends boolean = false> = {
30
30
  credential: Credential_.Credential<serialized>
31
31
  counter: number
32
32
  userVerified?: true | undefined
33
+ /** Whether the credential is currently backed up (BS flag). */
33
34
  backedUp?: boolean | undefined
35
+ /** `'multiDevice'` if the credential is backup eligible (BE flag), otherwise `'singleDevice'`. */
34
36
  deviceType?: 'multiDevice' | 'singleDevice' | undefined
35
37
  }
36
38
 
@@ -747,12 +749,8 @@ export function verify(options: verify.Options): verify.ReturnType {
747
749
  },
748
750
  counter,
749
751
  ...(uv ? { userVerified: true as const } : {}),
750
- ...(be ? { backedUp: bs } : {}),
751
- ...(be
752
- ? {
753
- deviceType: bs ? ('multiDevice' as const) : ('singleDevice' as const),
754
- }
755
- : {}),
752
+ backedUp: bs,
753
+ deviceType: be ? 'multiDevice' : 'singleDevice',
756
754
  }
757
755
  }
758
756