ox 1.8.15 → 1.8.16

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 (160) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/core/AbiError.d.ts +52 -6
  3. package/dist/core/AbiError.d.ts.map +1 -1
  4. package/dist/core/AbiError.js +60 -4
  5. package/dist/core/AbiError.js.map +1 -1
  6. package/dist/core/AbiEvent.d.ts +4 -2
  7. package/dist/core/AbiEvent.d.ts.map +1 -1
  8. package/dist/core/AbiEvent.js +62 -36
  9. package/dist/core/AbiEvent.js.map +1 -1
  10. package/dist/core/AbiFunction.d.ts +48 -2
  11. package/dist/core/AbiFunction.d.ts.map +1 -1
  12. package/dist/core/AbiFunction.js +59 -3
  13. package/dist/core/AbiFunction.js.map +1 -1
  14. package/dist/core/Address.d.ts +17 -2
  15. package/dist/core/Address.d.ts.map +1 -1
  16. package/dist/core/Address.js +17 -1
  17. package/dist/core/Address.js.map +1 -1
  18. package/dist/core/Authorization.d.ts +24 -2
  19. package/dist/core/Authorization.d.ts.map +1 -1
  20. package/dist/core/Authorization.js +29 -2
  21. package/dist/core/Authorization.js.map +1 -1
  22. package/dist/core/Keystore.d.ts +31 -2
  23. package/dist/core/Keystore.d.ts.map +1 -1
  24. package/dist/core/Keystore.js +28 -2
  25. package/dist/core/Keystore.js.map +1 -1
  26. package/dist/core/Secp256k1.d.ts.map +1 -1
  27. package/dist/core/Secp256k1.js +4 -1
  28. package/dist/core/Secp256k1.js.map +1 -1
  29. package/dist/core/Signature.d.ts +1 -1
  30. package/dist/core/Signature.d.ts.map +1 -1
  31. package/dist/core/Signature.js +4 -2
  32. package/dist/core/Signature.js.map +1 -1
  33. package/dist/core/Siwe.d.ts +4 -0
  34. package/dist/core/Siwe.d.ts.map +1 -1
  35. package/dist/core/Siwe.js +29 -3
  36. package/dist/core/Siwe.js.map +1 -1
  37. package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
  38. package/dist/core/TxEnvelopeEip1559.js +2 -1
  39. package/dist/core/TxEnvelopeEip1559.js.map +1 -1
  40. package/dist/core/TxEnvelopeEip2930.d.ts.map +1 -1
  41. package/dist/core/TxEnvelopeEip2930.js +2 -1
  42. package/dist/core/TxEnvelopeEip2930.js.map +1 -1
  43. package/dist/core/TxEnvelopeEip7702.d.ts +1 -1
  44. package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
  45. package/dist/core/TxEnvelopeEip7702.js +6 -1
  46. package/dist/core/TxEnvelopeEip7702.js.map +1 -1
  47. package/dist/core/TxEnvelopeLegacy.d.ts.map +1 -1
  48. package/dist/core/TxEnvelopeLegacy.js +49 -7
  49. package/dist/core/TxEnvelopeLegacy.js.map +1 -1
  50. package/dist/core/TypedData.d.ts +3 -1
  51. package/dist/core/TypedData.d.ts.map +1 -1
  52. package/dist/core/TypedData.js +9 -9
  53. package/dist/core/TypedData.js.map +1 -1
  54. package/dist/core/Value.d.ts.map +1 -1
  55. package/dist/core/Value.js +14 -3
  56. package/dist/core/Value.js.map +1 -1
  57. package/dist/core/internal/abiParameters.d.ts +1 -1
  58. package/dist/core/internal/abiParameters.d.ts.map +1 -1
  59. package/dist/core/internal/abiParameters.js +7 -2
  60. package/dist/core/internal/abiParameters.js.map +1 -1
  61. package/dist/core/internal/cursor.d.ts +13 -0
  62. package/dist/core/internal/cursor.d.ts.map +1 -1
  63. package/dist/core/internal/cursor.js +27 -0
  64. package/dist/core/internal/cursor.js.map +1 -1
  65. package/dist/erc4337/UserOperation.d.ts.map +1 -1
  66. package/dist/erc4337/UserOperation.js +1 -3
  67. package/dist/erc4337/UserOperation.js.map +1 -1
  68. package/dist/erc7821/Execute.d.ts +45 -0
  69. package/dist/erc7821/Execute.d.ts.map +1 -1
  70. package/dist/erc7821/Execute.js +70 -2
  71. package/dist/erc7821/Execute.js.map +1 -1
  72. package/dist/index.d.ts +1 -1
  73. package/dist/index.js +1 -1
  74. package/dist/tempo/KeyAuthorization.d.ts +9 -3
  75. package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
  76. package/dist/tempo/KeyAuthorization.js +16 -0
  77. package/dist/tempo/KeyAuthorization.js.map +1 -1
  78. package/dist/tempo/SignatureEnvelope.d.ts +1 -1
  79. package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
  80. package/dist/tempo/SignatureEnvelope.js +46 -13
  81. package/dist/tempo/SignatureEnvelope.js.map +1 -1
  82. package/dist/tempo/TransactionRequest.d.ts +1 -1
  83. package/dist/tempo/TransactionRequest.d.ts.map +1 -1
  84. package/dist/tempo/TransactionRequest.js +5 -2
  85. package/dist/tempo/TransactionRequest.js.map +1 -1
  86. package/dist/tempo/TxEnvelopeTempo.d.ts +30 -1
  87. package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  88. package/dist/tempo/TxEnvelopeTempo.js +51 -2
  89. package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
  90. package/dist/webauthn/Registration.d.ts +2 -0
  91. package/dist/webauthn/Registration.d.ts.map +1 -1
  92. package/dist/webauthn/Registration.js +2 -6
  93. package/dist/webauthn/Registration.js.map +1 -1
  94. package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
  95. package/dist/zod/tempo/KeyAuthorization.js +4 -2
  96. package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
  97. package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
  98. package/dist/zod/tempo/SignatureEnvelope.js +24 -14
  99. package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
  100. package/package.json +1 -1
  101. package/src/core/AbiError.ts +82 -8
  102. package/src/core/AbiEvent.ts +90 -45
  103. package/src/core/AbiFunction.ts +76 -4
  104. package/src/core/Address.ts +18 -1
  105. package/src/core/Authorization.ts +34 -4
  106. package/src/core/Keystore.ts +40 -3
  107. package/src/core/Secp256k1.ts +4 -1
  108. package/src/core/Signature.ts +7 -3
  109. package/src/core/Siwe.ts +29 -3
  110. package/src/core/TxEnvelopeEip1559.ts +4 -1
  111. package/src/core/TxEnvelopeEip2930.ts +4 -1
  112. package/src/core/TxEnvelopeEip7702.ts +9 -2
  113. package/src/core/TxEnvelopeLegacy.ts +58 -7
  114. package/src/core/TypedData.ts +10 -9
  115. package/src/core/Value.ts +14 -3
  116. package/src/core/_test/AbiError.test.ts +105 -2
  117. package/src/core/_test/AbiEvent.fuzz.ts +1 -1
  118. package/src/core/_test/AbiEvent.test-d.ts +46 -0
  119. package/src/core/_test/AbiEvent.test.ts +563 -11
  120. package/src/core/_test/AbiFunction.test.ts +74 -2
  121. package/src/core/_test/AbiParameters.adversarial.fuzz.ts +1 -0
  122. package/src/core/_test/AbiParameters.decode.test.ts +110 -0
  123. package/src/core/_test/AbiParameters.encode.test.ts +26 -1
  124. package/src/core/_test/Address.test.ts +41 -0
  125. package/src/core/_test/Authorization.test.ts +130 -0
  126. package/src/core/_test/Keystore.test.ts +65 -1
  127. package/src/core/_test/Secp256k1.test.ts +36 -0
  128. package/src/core/_test/Signature.test.ts +102 -0
  129. package/src/core/_test/Siwe.test.ts +123 -0
  130. package/src/core/_test/TransactionEnvelopeEip1559.test.ts +28 -0
  131. package/src/core/_test/TransactionEnvelopeEip2930.test.ts +28 -0
  132. package/src/core/_test/TransactionEnvelopeEip7702.test.ts +133 -0
  133. package/src/core/_test/TransactionEnvelopeLegacy.test.ts +322 -1
  134. package/src/core/_test/TypedData.test.ts +178 -0
  135. package/src/core/_test/Value.test.ts +21 -0
  136. package/src/core/_test/internal/cursor.test.ts +35 -0
  137. package/src/core/internal/abiParameters.ts +7 -2
  138. package/src/core/internal/cursor.ts +36 -0
  139. package/src/erc4337/UserOperation.ts +3 -4
  140. package/src/erc4337/_test/UserOperation.test.ts +59 -1
  141. package/src/erc7821/Execute.ts +83 -2
  142. package/src/erc7821/_test/Execute.test.ts +217 -1
  143. package/src/index.ts +1 -1
  144. package/src/tempo/KeyAuthorization.test.ts +91 -0
  145. package/src/tempo/KeyAuthorization.ts +32 -3
  146. package/src/tempo/SignatureEnvelope.test.ts +211 -27
  147. package/src/tempo/SignatureEnvelope.ts +55 -11
  148. package/src/tempo/TransactionRequest.test.ts +30 -0
  149. package/src/tempo/TransactionRequest.ts +7 -2
  150. package/src/tempo/TxEnvelopeTempo.test.ts +310 -0
  151. package/src/tempo/TxEnvelopeTempo.ts +64 -1
  152. package/src/tempo/configurableAccounts.e2e.test.ts +1 -1
  153. package/src/version.ts +1 -1
  154. package/src/webauthn/Registration.ts +4 -6
  155. package/src/webauthn/_test/Registration.browser.test.ts +14 -0
  156. package/src/webauthn/_test/Registration.test.ts +60 -0
  157. package/src/zod/tempo/KeyAuthorization.ts +12 -5
  158. package/src/zod/tempo/SignatureEnvelope.ts +31 -16
  159. package/src/zod/tempo/_test/KeyAuthorization.test.ts +36 -0
  160. package/src/zod/tempo/_test/SignatureEnvelope.test.ts +101 -3
@@ -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: '0x0000000000000000000000000000000000000000000000000000000000000001',
227
+ s: '0x0000000000000000000000000000000000000000000000000000000000000001',
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":"0x0000000000000000000000000000000000000000000000000000000000000001","s":"0x0000000000000000000000000000000000000000000000000000000000000001"}\` 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', () => {
@@ -805,6 +936,19 @@ describe('from', () => {
805
936
  }
806
937
  })
807
938
 
939
+ test('invalid validity bound', () => {
940
+ expect(() =>
941
+ TxEnvelopeTempo.from({
942
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
943
+ chainId: 1,
944
+ validAfter: 1700000000n as never,
945
+ validBefore: 1700003600n as never,
946
+ }),
947
+ ).toThrowErrorMatchingInlineSnapshot(
948
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
949
+ )
950
+ })
951
+
808
952
  test('options: signature', () => {
809
953
  const envelope = TxEnvelopeTempo.from(
810
954
  {
@@ -945,6 +1089,23 @@ describe('from', () => {
945
1089
  }
946
1090
  `)
947
1091
  })
1092
+
1093
+ test('invalid fee payer signature', () => {
1094
+ expect(() =>
1095
+ TxEnvelopeTempo.from({
1096
+ calls: [{}],
1097
+ chainId: 1,
1098
+ feePayerSignature: {
1099
+ r: '0x0000000000000000000000000000000000000000000000000000000000000001',
1100
+ s: '0x0000000000000000000000000000000000000000000000000000000000000001',
1101
+ yParity: 2,
1102
+ },
1103
+ nonce: 0n,
1104
+ }),
1105
+ ).toThrowErrorMatchingInlineSnapshot(
1106
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1107
+ )
1108
+ })
948
1109
  })
949
1110
 
950
1111
  describe('serialize', () => {
@@ -989,6 +1150,40 @@ describe('serialize', () => {
989
1150
  )
990
1151
  })
991
1152
 
1153
+ test('validBefore and validAfter', () => {
1154
+ const transaction = {
1155
+ chainId: 1,
1156
+ calls: [{}],
1157
+ nonce: 0n,
1158
+ } as const
1159
+ expect(
1160
+ TxEnvelopeTempo.serialize({
1161
+ ...transaction,
1162
+ validAfter: 1700000000,
1163
+ validBefore: 1700003600,
1164
+ }),
1165
+ ).toMatchInlineSnapshot(
1166
+ `"0x76d901808080c4c3808080c08080846553ff10846553f1008080c0"`,
1167
+ )
1168
+ expect(() =>
1169
+ TxEnvelopeTempo.serialize({
1170
+ ...transaction,
1171
+ validAfter: 1700000000n as never,
1172
+ validBefore: 1700003600n as never,
1173
+ }),
1174
+ ).toThrowErrorMatchingInlineSnapshot(
1175
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
1176
+ )
1177
+ expect(() =>
1178
+ TxEnvelopeTempo.serialize({
1179
+ ...transaction,
1180
+ validBefore: '0x6553ff10' as never,
1181
+ }),
1182
+ ).toThrowErrorMatchingInlineSnapshot(
1183
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore ("0x6553ff10") must be a non-negative safe integer number.]`,
1184
+ )
1185
+ })
1186
+
992
1187
  test('multiple calls', () => {
993
1188
  const transaction = TxEnvelopeTempo.from({
994
1189
  chainId: 1,
@@ -1341,6 +1536,47 @@ describe('serialize', () => {
1341
1536
  )
1342
1537
  })
1343
1538
 
1539
+ test('with feePayerSignature (invalid yParity)', () => {
1540
+ const transaction = {
1541
+ calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1542
+ chainId: 1,
1543
+ nonce: 0n,
1544
+ } as const
1545
+ const feePayerSignature = {
1546
+ r: '0x0000000000000000000000000000000000000000000000000000000000000001',
1547
+ s: '0x0000000000000000000000000000000000000000000000000000000000000001',
1548
+ } as const
1549
+ expect(
1550
+ TxEnvelopeTempo.serialize(transaction, {
1551
+ feePayerSignature: { ...feePayerSignature, yParity: 1 },
1552
+ }),
1553
+ ).toMatchInlineSnapshot(
1554
+ `"0x76e801808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c08080808080c3010101c0"`,
1555
+ )
1556
+ expect(() =>
1557
+ TxEnvelopeTempo.serialize(transaction, {
1558
+ feePayerSignature: { ...feePayerSignature, yParity: 2 },
1559
+ }),
1560
+ ).toThrowErrorMatchingInlineSnapshot(
1561
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1562
+ )
1563
+ expect(() =>
1564
+ TxEnvelopeTempo.serialize(transaction, {
1565
+ feePayerSignature: { ...feePayerSignature, yParity: 27 },
1566
+ }),
1567
+ ).toThrowErrorMatchingInlineSnapshot(
1568
+ `[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1569
+ )
1570
+ expect(() =>
1571
+ TxEnvelopeTempo.serialize({
1572
+ ...transaction,
1573
+ feePayerSignature: { ...feePayerSignature, yParity: 2 },
1574
+ }),
1575
+ ).toThrowErrorMatchingInlineSnapshot(
1576
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1577
+ )
1578
+ })
1579
+
1344
1580
  test('format: feePayer', () => {
1345
1581
  const transaction = TxEnvelopeTempo.from({
1346
1582
  chainId: 1,
@@ -1466,6 +1702,24 @@ describe('hash', () => {
1466
1702
  })
1467
1703
  })
1468
1704
 
1705
+ test('invalid fee payer signature', () => {
1706
+ expect(() =>
1707
+ TxEnvelopeTempo.hash({
1708
+ calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1709
+ chainId: 1,
1710
+ feePayerSignature: {
1711
+ r: '0x0000000000000000000000000000000000000000000000000000000000000001',
1712
+ s: '0x0000000000000000000000000000000000000000000000000000000000000001',
1713
+ yParity: 2,
1714
+ },
1715
+ nonce: 0n,
1716
+ type: 'tempo',
1717
+ } as never),
1718
+ ).toThrowErrorMatchingInlineSnapshot(
1719
+ `[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
1720
+ )
1721
+ })
1722
+
1469
1723
  test('presign', () => {
1470
1724
  const transaction = TxEnvelopeTempo.from({
1471
1725
  chainId: 1,
@@ -1482,6 +1736,23 @@ describe('hash', () => {
1482
1736
  `"0xe1222a45806457acbe3a13940aae4c34f3180659fa16613b5a45dc183adae07c"`,
1483
1737
  )
1484
1738
  })
1739
+
1740
+ test('invalid validity bound', () => {
1741
+ expect(() =>
1742
+ TxEnvelopeTempo.hash(
1743
+ {
1744
+ calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1745
+ chainId: 1,
1746
+ nonce: 0n,
1747
+ type: 'tempo',
1748
+ validBefore: 1700003600n as never,
1749
+ },
1750
+ { presign: true },
1751
+ ),
1752
+ ).toThrowErrorMatchingInlineSnapshot(
1753
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
1754
+ )
1755
+ })
1485
1756
  })
1486
1757
 
1487
1758
  describe('encodeForSigning', () => {
@@ -1560,6 +1831,20 @@ describe('getSignPayload', () => {
1560
1831
  `"0xe1222a45806457acbe3a13940aae4c34f3180659fa16613b5a45dc183adae07c"`,
1561
1832
  )
1562
1833
  })
1834
+
1835
+ test('invalid validity bound', () => {
1836
+ expect(() =>
1837
+ TxEnvelopeTempo.getSignPayload({
1838
+ calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
1839
+ chainId: 1,
1840
+ nonce: 0n,
1841
+ type: 'tempo',
1842
+ validBefore: 1700003600n as never,
1843
+ }),
1844
+ ).toThrowErrorMatchingInlineSnapshot(
1845
+ `[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
1846
+ )
1847
+ })
1563
1848
  })
1564
1849
 
1565
1850
  describe('getFeePayerSignPayload', () => {
@@ -1629,6 +1914,20 @@ describe('validate', () => {
1629
1914
  ).toBe(false)
1630
1915
  })
1631
1916
 
1917
+ test('invalid (fee payer signature)', () => {
1918
+ expect(
1919
+ TxEnvelopeTempo.validate({
1920
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
1921
+ chainId: 1,
1922
+ feePayerSignature: {
1923
+ r: '0x0000000000000000000000000000000000000000000000000000000000000001',
1924
+ s: '0x0000000000000000000000000000000000000000000000000000000000000001',
1925
+ yParity: 2,
1926
+ },
1927
+ }),
1928
+ ).toBe(false)
1929
+ })
1930
+
1632
1931
  test('invalid (validity window)', () => {
1633
1932
  expect(
1634
1933
  TxEnvelopeTempo.validate({
@@ -1639,6 +1938,17 @@ describe('validate', () => {
1639
1938
  }),
1640
1939
  ).toBe(false)
1641
1940
  })
1941
+
1942
+ test('invalid (validity bound)', () => {
1943
+ expect(
1944
+ TxEnvelopeTempo.validate({
1945
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
1946
+ chainId: 1,
1947
+ validBefore: 100n as never,
1948
+ validAfter: 200n as never,
1949
+ }),
1950
+ ).toBe(false)
1951
+ })
1642
1952
  })
1643
1953
 
1644
1954
  describe('toTransactionRequest', () => {
@@ -173,6 +173,7 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
173
173
  const {
174
174
  calls,
175
175
  chainId,
176
+ feePayerSignature,
176
177
  feeToken,
177
178
  maxFeePerGas,
178
179
  maxPriorityFeePerGas,
@@ -183,6 +184,18 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
183
184
  // Calls must not be empty
184
185
  if (!calls || calls.length === 0) throw new CallsEmptyError()
185
186
 
187
+ // validBefore and validAfter must be non-negative safe integers if set
188
+ for (const [name, value] of [
189
+ ['validBefore', validBefore],
190
+ ['validAfter', validAfter],
191
+ ] as const)
192
+ if (
193
+ value !== undefined &&
194
+ value !== null &&
195
+ !(Number.isSafeInteger(value) && value >= 0)
196
+ )
197
+ throw new InvalidValidityBoundError({ name, value })
198
+
186
199
  // validBefore must be greater than validAfter if both are set
187
200
  if (
188
201
  typeof validBefore === 'number' &&
@@ -204,7 +217,10 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
204
217
  if (feeToken) Address.assert(feeToken, { strict: false })
205
218
 
206
219
  // Validate chain ID
207
- if (chainId <= 0)
220
+ if (
221
+ typeof chainId !== 'undefined' &&
222
+ (!Number.isSafeInteger(chainId) || chainId <= 0)
223
+ )
208
224
  throw new TransactionEnvelope.InvalidChainIdError({ chainId })
209
225
 
210
226
  // Validate max fee per gas
@@ -222,13 +238,19 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
222
238
  maxFeePerGas,
223
239
  maxPriorityFeePerGas,
224
240
  })
241
+
242
+ // Validate fee payer signature
243
+ if (feePayerSignature)
244
+ Signature.assert(feePayerSignature, { recovered: true })
225
245
  }
226
246
 
227
247
  export declare namespace assert {
228
248
  type ErrorType =
229
249
  | Address.assert.ErrorType
230
250
  | CallsEmptyError
251
+ | InvalidValidityBoundError
231
252
  | InvalidValidityWindowError
253
+ | Signature.assert.ErrorType
232
254
  | Errors.GlobalErrorType
233
255
  }
234
256
 
@@ -716,6 +738,7 @@ export function serialize(
716
738
  // No fee payer involvement — omit from the envelope.
717
739
  if (!feePayerSignature) return '0x'
718
740
  // Fee payer has signed — encode the signature as an RLP tuple.
741
+ Signature.assert(feePayerSignature, { recovered: true })
719
742
  return Signature.toTuple(feePayerSignature)
720
743
  })()
721
744
 
@@ -1136,6 +1159,46 @@ export class CallsEmptyError extends Errors.BaseError {
1136
1159
  }
1137
1160
  }
1138
1161
 
1162
+ /**
1163
+ * Thrown when validBefore or validAfter is not a non-negative safe integer number.
1164
+ *
1165
+ * @example
1166
+ * ```ts twoslash
1167
+ * import { Address } from 'ox'
1168
+ * import { TxEnvelopeTempo } from 'ox/tempo'
1169
+ *
1170
+ * TxEnvelopeTempo.assert({
1171
+ * calls: [
1172
+ * {
1173
+ * to: Address.from(
1174
+ * '0x0000000000000000000000000000000000000000'
1175
+ * )
1176
+ * }
1177
+ * ],
1178
+ * chainId: 1,
1179
+ * validBefore: -1
1180
+ * })
1181
+ * // @error: TxEnvelopeTempo.InvalidValidityBoundError: validBefore (-1) must be a non-negative safe integer number.
1182
+ * ```
1183
+ */
1184
+ export class InvalidValidityBoundError extends Errors.BaseError {
1185
+ override readonly name = 'TxEnvelopeTempo.InvalidValidityBoundError'
1186
+ constructor({
1187
+ name,
1188
+ value,
1189
+ }: {
1190
+ name: 'validAfter' | 'validBefore'
1191
+ value: unknown
1192
+ }) {
1193
+ const value_ = (() => {
1194
+ if (typeof value === 'bigint') return `${value}n`
1195
+ if (typeof value === 'string') return `"${value}"`
1196
+ return String(value)
1197
+ })()
1198
+ super(`${name} (${value_}) must be a non-negative safe integer number.`)
1199
+ }
1200
+ }
1201
+
1139
1202
  /**
1140
1203
  * Thrown when validBefore is not greater than validAfter.
1141
1204
  *
@@ -245,7 +245,7 @@ describe('behavior: configurable accounts', () => {
245
245
  ...signature,
246
246
  signatures: signature.signatures.slice(0, 1),
247
247
  }),
248
- ).rejects.toThrow(/threshold|weight|quorum/)
248
+ ).rejects.toThrow('invalid transaction signature')
249
249
  expect((await submit(tx, signature)).status).toMatchInlineSnapshot(
250
250
  '"success"',
251
251
  )
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '1.8.15'
2
+ export const version = '1.8.16'
@@ -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
 
@@ -754,12 +756,8 @@ export function verify(options: verify.Options): verify.ReturnType {
754
756
  },
755
757
  counter,
756
758
  ...(uv ? { userVerified: true as const } : {}),
757
- ...(be ? { backedUp: bs } : {}),
758
- ...(be
759
- ? {
760
- deviceType: bs ? ('multiDevice' as const) : ('singleDevice' as const),
761
- }
762
- : {}),
759
+ backedUp: bs,
760
+ deviceType: be ? 'multiDevice' : 'singleDevice',
763
761
  }
764
762
  }
765
763
 
@@ -303,6 +303,20 @@ describe('behavior: BE/BS flag consistency', () => {
303
303
  rpId,
304
304
  })
305
305
 
306
+ expect(result.backedUp).toBe(false)
307
+ expect(result.deviceType).toBe('multiDevice')
308
+ })
309
+
310
+ test('accepts BE + BS both not set', () => {
311
+ const { credential, challenge } = buildPackedCredential({ flag: 0x45 })
312
+
313
+ const result = Registration.verify({
314
+ credential,
315
+ challenge,
316
+ origin: window.location.origin,
317
+ rpId,
318
+ })
319
+
306
320
  expect(result.backedUp).toBe(false)
307
321
  expect(result.deviceType).toBe('singleDevice')
308
322
  })
@@ -988,6 +988,66 @@ describe('verify', () => {
988
988
  ).toThrow('Backup state (BS) flag is set but backup eligibility (BE)')
989
989
  })
990
990
 
991
+ test('behavior: BE flag not set', async () => {
992
+ const { credential, challenge, origin, rpId } = await mockCreateCredential({
993
+ flag: 0x45,
994
+ }) // UP + UV + AT
995
+
996
+ const { backedUp, deviceType } = Registration.verify({
997
+ credential,
998
+ challenge,
999
+ origin,
1000
+ rpId,
1001
+ })
1002
+
1003
+ expect({ backedUp, deviceType }).toMatchInlineSnapshot(`
1004
+ {
1005
+ "backedUp": false,
1006
+ "deviceType": "singleDevice",
1007
+ }
1008
+ `)
1009
+ })
1010
+
1011
+ test('behavior: BE flag set without BS flag', async () => {
1012
+ const { credential, challenge, origin, rpId } = await mockCreateCredential({
1013
+ flag: 0x4d,
1014
+ }) // UP + UV + AT + BE
1015
+
1016
+ const { backedUp, deviceType } = Registration.verify({
1017
+ credential,
1018
+ challenge,
1019
+ origin,
1020
+ rpId,
1021
+ })
1022
+
1023
+ expect({ backedUp, deviceType }).toMatchInlineSnapshot(`
1024
+ {
1025
+ "backedUp": false,
1026
+ "deviceType": "multiDevice",
1027
+ }
1028
+ `)
1029
+ })
1030
+
1031
+ test('behavior: BE + BS flags set', async () => {
1032
+ const { credential, challenge, origin, rpId } = await mockCreateCredential({
1033
+ flag: 0x5d,
1034
+ }) // UP + UV + AT + BE + BS
1035
+
1036
+ const { backedUp, deviceType } = Registration.verify({
1037
+ credential,
1038
+ challenge,
1039
+ origin,
1040
+ rpId,
1041
+ })
1042
+
1043
+ expect({ backedUp, deviceType }).toMatchInlineSnapshot(`
1044
+ {
1045
+ "backedUp": true,
1046
+ "deviceType": "multiDevice",
1047
+ }
1048
+ `)
1049
+ })
1050
+
991
1051
  test('error: credential ID mismatch', async () => {
992
1052
  const { credential, challenge, origin, rpId } = await mockCreateCredential()
993
1053
 
@@ -63,11 +63,18 @@ export const TokenLimitToRpc = z.object({
63
63
  })
64
64
 
65
65
  /** Call scope schema. */
66
- export const Scope = z.object({
67
- address: z_Address.Address,
68
- recipients: z.optional(z.readonly(z.array(z_Address.Address))),
69
- selector: z.optional(z.union([z_Hex.Hex, z.string()])),
70
- })
66
+ export const Scope = z
67
+ .object({
68
+ address: z_Address.Address,
69
+ recipients: z.optional(z.readonly(z.array(z_Address.Address))),
70
+ selector: z.optional(z.union([z_Hex.Hex, z.string()])),
71
+ })
72
+ .check(
73
+ z.refine(
74
+ (value) => Boolean(value.selector) || !value.recipients?.length,
75
+ 'recipients require a selector',
76
+ ),
77
+ )
71
78
 
72
79
  const domainShape = {
73
80
  address: z_Address.Address,