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
@@ -40,13 +40,24 @@ const Signature = z.object({
40
40
  })
41
41
 
42
42
  /** RPC secp256k1 signature envelope schema. */
43
- export const Secp256k1Rpc = z.object({
44
- r: z_Hex.Hex,
45
- s: z_Hex.Hex,
46
- type: z.literal('secp256k1'),
47
- v: z.optional(z_Hex.Hex),
48
- yParity: z.optional(z_Hex.Hex),
49
- })
43
+ export const Secp256k1Rpc = z
44
+ .object({
45
+ r: z_Hex.Hex,
46
+ s: z_Hex.Hex,
47
+ type: z.literal('secp256k1'),
48
+ v: z.optional(z_Hex.Hex),
49
+ yParity: z.optional(z_Hex.Hex),
50
+ })
51
+ .check(
52
+ z.refine((value) => {
53
+ try {
54
+ toYParity(value.v, value.yParity)
55
+ return true
56
+ } catch {
57
+ return false
58
+ }
59
+ }, 'expected yParity or supported v'),
60
+ )
50
61
 
51
62
  /** RPC P256 signature envelope schema. */
52
63
  export const P256Rpc = z.object({
@@ -65,7 +76,13 @@ export const WebAuthnRpc = z.object({
65
76
  r: z_Hex.Hex,
66
77
  s: z_Hex.Hex,
67
78
  type: z.literal('webAuthn'),
68
- webauthnData: z_Hex.Hex,
79
+ // 2048-byte WebAuthn signature limit minus the 128-byte signature and public key.
80
+ webauthnData: z_Hex.Hex.check(
81
+ z.refine(
82
+ (value) => core_Hex.size(value) <= 1920,
83
+ 'expected at most 1920 bytes',
84
+ ),
85
+ ),
69
86
  })
70
87
 
71
88
  /** RPC primitive signature envelope schema. */
@@ -324,14 +341,12 @@ function toYParity(
324
341
  v: core_Hex.Hex | undefined,
325
342
  yParity: core_Hex.Hex | undefined,
326
343
  ) {
327
- const v_ = v ? Number(v) : undefined
328
- let yParity_ = yParity ? Number(yParity) : undefined
329
- if (typeof v_ === 'number' && typeof yParity_ !== 'number') {
330
- if (v_ === 0 || v_ === 27) yParity_ = 0
331
- else if (v_ === 1 || v_ === 28) yParity_ = 1
332
- else if (v_ >= 35) yParity_ = v_ % 2 === 0 ? 1 : 0
333
- }
334
- return yParity_ as 0 | 1
344
+ if (yParity) return Number(yParity) as 0 | 1
345
+ const v_ = v && v !== '0x' ? BigInt(v) : undefined
346
+ if (v_ === 0n || v_ === 27n) return 0
347
+ if (v_ === 1n || v_ === 28n) return 1
348
+ if (typeof v_ === 'bigint' && v_ >= 35n) return v_ % 2n === 0n ? 1 : 0
349
+ throw new Error('Unable to derive yParity: expected yParity or supported v')
335
350
  }
336
351
 
337
352
  /** Parses concatenated WebAuthn metadata into its component parts. */
@@ -171,6 +171,42 @@ describe('KeyAuthorization', () => {
171
171
  ).toBe(false)
172
172
  })
173
173
 
174
+ test('rejects recipients without a selector', () => {
175
+ const address = '0x20c0000000000000000000000000000000000001'
176
+ const recipients = ['0x1111111111111111111111111111111111111111']
177
+ expect(
178
+ z.safeParse(z_KeyAuthorization.Scope, { address, recipients }).error
179
+ ?.issues,
180
+ ).toMatchInlineSnapshot(`
181
+ [
182
+ {
183
+ "code": "custom",
184
+ "message": "recipients require a selector",
185
+ "path": [],
186
+ },
187
+ ]
188
+ `)
189
+ expect(
190
+ z.safeEncode(z_KeyAuthorization.KeyAuthorization, {
191
+ ...core_KeyAuthorization.fromRpc(rpc),
192
+ scopes: [{ address, recipients }],
193
+ } as never).success,
194
+ ).toBe(false)
195
+ expect(
196
+ [
197
+ { address },
198
+ { address, recipients: [] },
199
+ { address, recipients, selector: '0xa9059cbb' },
200
+ ].map((scope) => z.safeParse(z_KeyAuthorization.Scope, scope).success),
201
+ ).toMatchInlineSnapshot(`
202
+ [
203
+ true,
204
+ true,
205
+ true,
206
+ ]
207
+ `)
208
+ })
209
+
174
210
  test('rejects legacy signatures without a config', () => {
175
211
  const legacyRpc = {
176
212
  account: '0x1111111111111111111111111111111111111111',
@@ -1,4 +1,5 @@
1
1
  import { describe, expect, test } from 'vp/test'
2
+ import * as core_Hex from '../../../core/Hex.js'
2
3
  import * as core_SignatureEnvelope from '../../../tempo/SignatureEnvelope.js'
3
4
  import * as z_SignatureEnvelope from '../SignatureEnvelope.js'
4
5
  import * as z from 'zod/mini'
@@ -49,6 +50,42 @@ describe('SignatureEnvelope', () => {
49
50
  )
50
51
  })
51
52
 
53
+ test('rejects WebAuthn data above the maximum size', () => {
54
+ const webAuthn = {
55
+ pubKeyX: p256.pubKeyX,
56
+ pubKeyY: p256.pubKeyY,
57
+ r: p256.r,
58
+ s: p256.s,
59
+ type: 'webAuthn',
60
+ } as const
61
+ // 37 (authenticatorData) + 16 + length (clientDataJSON) bytes
62
+ const webauthnData = (length: number) =>
63
+ core_Hex.concat(
64
+ `0x${'00'.repeat(37)}`,
65
+ core_Hex.fromString(JSON.stringify({ challenge: 'a'.repeat(length) })),
66
+ )
67
+ const max = { ...webAuthn, webauthnData: webauthnData(1867) }
68
+ expect(z.decode(z_SignatureEnvelope.SignatureEnvelope, max)).toEqual(
69
+ core_SignatureEnvelope.fromRpc(max),
70
+ )
71
+ expect(
72
+ z.safeDecode(z_SignatureEnvelope.SignatureEnvelope, {
73
+ ...webAuthn,
74
+ webauthnData: webauthnData(1868),
75
+ }).error?.issues,
76
+ ).toMatchInlineSnapshot(`
77
+ [
78
+ {
79
+ "code": "custom",
80
+ "message": "expected at most 1920 bytes",
81
+ "path": [
82
+ "webauthnData",
83
+ ],
84
+ },
85
+ ]
86
+ `)
87
+ })
88
+
52
89
  test('decodes a recursive keychain envelope', () => {
53
90
  const keychain = {
54
91
  signature: secp256k1,
@@ -140,10 +177,71 @@ describe('SignatureEnvelope', () => {
140
177
  ),
141
178
  ).toEqual(rpc)
142
179
  })
180
+
181
+ test('derives yParity from v when yParity is omitted', () => {
182
+ const { yParity: _, ...rest } = secp256k1
183
+ expect(
184
+ (
185
+ [
186
+ '0x0',
187
+ '0x1',
188
+ '0x1b',
189
+ '0x1c',
190
+ '0x25',
191
+ '0x26',
192
+ '0x1fffffffffffff',
193
+ '0x20000000000001',
194
+ '0x20000000000002',
195
+ '0xffffffffffffffff',
196
+ ] as const
197
+ ).map(
198
+ (v) =>
199
+ (
200
+ z.decode(z_SignatureEnvelope.SignatureEnvelope, {
201
+ ...rest,
202
+ v,
203
+ }) as core_SignatureEnvelope.Secp256k1
204
+ ).signature.yParity,
205
+ ),
206
+ ).toMatchInlineSnapshot(`
207
+ [
208
+ 0,
209
+ 1,
210
+ 0,
211
+ 1,
212
+ 0,
213
+ 1,
214
+ 0,
215
+ 0,
216
+ 1,
217
+ 0,
218
+ ]
219
+ `)
220
+ })
221
+
222
+ test('prefers yParity over v', () => {
223
+ expect(
224
+ z.decode(z_SignatureEnvelope.SignatureEnvelope, {
225
+ ...secp256k1,
226
+ v: '0x1c',
227
+ }),
228
+ ).toEqual(core_SignatureEnvelope.fromRpc(secp256k1))
229
+ })
230
+
231
+ test('rejects secp256k1 envelopes without yParity or a supported v', () => {
232
+ const { yParity: _, ...rest } = secp256k1
233
+ for (const v of ['0x2', '0x1a', '0x1d', '0x22', '0x', undefined])
234
+ expect(
235
+ z.safeDecode(z_SignatureEnvelope.SignatureEnvelope, {
236
+ ...rest,
237
+ ...(v ? { v } : {}),
238
+ } as never).success,
239
+ ).toMatchInlineSnapshot(`false`)
240
+ })
143
241
  })
144
242
 
145
243
  describe('Keychain', () => {
146
- test('rejects V1 wrappers with nested configurable delegates', () => {
244
+ test('rejects keychain wrappers around keychain-wrapped configurable delegates', () => {
147
245
  const inner = {
148
246
  inner: envelope,
149
247
  type: 'keychain',
@@ -179,12 +277,12 @@ describe('Keychain', () => {
179
277
  ...value,
180
278
  version: 'v2',
181
279
  }).success,
182
- ).toMatchInlineSnapshot(`true`)
280
+ ).toMatchInlineSnapshot(`false`)
183
281
  expect(
184
282
  z.safeDecode(z_SignatureEnvelope.SignatureEnvelope, {
185
283
  ...rpc,
186
284
  version: 'v2',
187
285
  }).success,
188
- ).toMatchInlineSnapshot(`true`)
286
+ ).toMatchInlineSnapshot(`false`)
189
287
  })
190
288
  })