ox 0.9.4 → 0.9.6

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 (137) hide show
  1. package/Abi/package.json +6 -0
  2. package/AbiConstructor/package.json +6 -0
  3. package/AbiError/package.json +6 -0
  4. package/AbiEvent/package.json +6 -0
  5. package/AbiFunction/package.json +6 -0
  6. package/AbiItem/package.json +6 -0
  7. package/AbiParameters/package.json +6 -0
  8. package/AccessList/package.json +6 -0
  9. package/AccountProof/package.json +6 -0
  10. package/Address/package.json +6 -0
  11. package/AesGcm/package.json +6 -0
  12. package/Authorization/package.json +6 -0
  13. package/Base58/package.json +6 -0
  14. package/Base64/package.json +6 -0
  15. package/BinaryStateTree/package.json +6 -0
  16. package/Blobs/package.json +6 -0
  17. package/Block/package.json +6 -0
  18. package/BlockOverrides/package.json +6 -0
  19. package/Bloom/package.json +6 -0
  20. package/Bls/package.json +6 -0
  21. package/BlsPoint/package.json +6 -0
  22. package/Bytes/package.json +6 -0
  23. package/CHANGELOG.md +28 -0
  24. package/Caches/package.json +6 -0
  25. package/ContractAddress/package.json +6 -0
  26. package/Ed25519/package.json +6 -0
  27. package/Ens/package.json +6 -0
  28. package/Errors/package.json +6 -0
  29. package/Fee/package.json +6 -0
  30. package/Filter/package.json +6 -0
  31. package/Hash/package.json +6 -0
  32. package/HdKey/package.json +6 -0
  33. package/Hex/package.json +6 -0
  34. package/Json/package.json +6 -0
  35. package/Keystore/package.json +6 -0
  36. package/Kzg/package.json +6 -0
  37. package/Log/package.json +6 -0
  38. package/Mnemonic/package.json +6 -0
  39. package/P256/package.json +6 -0
  40. package/PersonalMessage/package.json +6 -0
  41. package/Provider/package.json +6 -0
  42. package/PublicKey/package.json +6 -0
  43. package/Rlp/package.json +6 -0
  44. package/RpcRequest/package.json +6 -0
  45. package/RpcResponse/package.json +6 -0
  46. package/RpcSchema/package.json +6 -0
  47. package/RpcTransport/package.json +6 -0
  48. package/Secp256k1/package.json +6 -0
  49. package/Signature/package.json +6 -0
  50. package/Siwe/package.json +6 -0
  51. package/Solidity/package.json +6 -0
  52. package/StateOverrides/package.json +6 -0
  53. package/Transaction/package.json +6 -0
  54. package/TransactionEnvelope/package.json +6 -0
  55. package/TransactionEnvelopeEip1559/package.json +6 -0
  56. package/TransactionEnvelopeEip2930/package.json +6 -0
  57. package/TransactionEnvelopeEip4844/package.json +6 -0
  58. package/TransactionEnvelopeEip7702/package.json +6 -0
  59. package/TransactionEnvelopeLegacy/package.json +6 -0
  60. package/TransactionReceipt/package.json +6 -0
  61. package/TransactionRequest/package.json +6 -0
  62. package/TypedData/package.json +6 -0
  63. package/ValidatorData/package.json +6 -0
  64. package/Value/package.json +6 -0
  65. package/WebAuthnP256/package.json +6 -0
  66. package/WebCryptoP256/package.json +6 -0
  67. package/Withdrawal/package.json +6 -0
  68. package/X25519/package.json +6 -0
  69. package/_cjs/core/AbiConstructor.js +16 -2
  70. package/_cjs/core/AbiConstructor.js.map +1 -1
  71. package/_cjs/core/AbiError.js +17 -2
  72. package/_cjs/core/AbiError.js.map +1 -1
  73. package/_cjs/core/AbiEvent.js +17 -2
  74. package/_cjs/core/AbiEvent.js.map +1 -1
  75. package/_cjs/core/AbiFunction.js +35 -8
  76. package/_cjs/core/AbiFunction.js.map +1 -1
  77. package/_cjs/core/AbiItem.js +24 -3
  78. package/_cjs/core/AbiItem.js.map +1 -1
  79. package/_cjs/version.js +1 -1
  80. package/_esm/core/Abi.js +2 -2
  81. package/_esm/core/Abi.js.map +1 -1
  82. package/_esm/core/AbiConstructor.js +18 -56
  83. package/_esm/core/AbiConstructor.js.map +1 -1
  84. package/_esm/core/AbiError.js +19 -54
  85. package/_esm/core/AbiError.js.map +1 -1
  86. package/_esm/core/AbiEvent.js +19 -187
  87. package/_esm/core/AbiEvent.js.map +1 -1
  88. package/_esm/core/AbiFunction.js +39 -242
  89. package/_esm/core/AbiFunction.js.map +1 -1
  90. package/_esm/core/AbiItem.js +27 -93
  91. package/_esm/core/AbiItem.js.map +1 -1
  92. package/_esm/erc6492/SignatureErc6492.js +2 -2
  93. package/_esm/erc6492/index.js +2 -2
  94. package/_esm/erc8010/SignatureErc8010.js +2 -2
  95. package/_esm/erc8010/index.js +2 -2
  96. package/_esm/version.js +1 -1
  97. package/_types/core/AbiConstructor.d.ts +43 -4
  98. package/_types/core/AbiConstructor.d.ts.map +1 -1
  99. package/_types/core/AbiError.d.ts +29 -19
  100. package/_types/core/AbiError.d.ts.map +1 -1
  101. package/_types/core/AbiEvent.d.ts +60 -0
  102. package/_types/core/AbiEvent.d.ts.map +1 -1
  103. package/_types/core/AbiFunction.d.ts +84 -2
  104. package/_types/core/AbiFunction.d.ts.map +1 -1
  105. package/_types/core/AbiItem.d.ts +36 -0
  106. package/_types/core/AbiItem.d.ts.map +1 -1
  107. package/_types/erc6492/SignatureErc6492.d.ts +2 -2
  108. package/_types/erc6492/index.d.ts +2 -2
  109. package/_types/erc8010/SignatureErc8010.d.ts +2 -2
  110. package/_types/erc8010/index.d.ts +2 -2
  111. package/_types/version.d.ts +1 -1
  112. package/core/Abi.ts +2 -2
  113. package/core/AbiConstructor.ts +96 -12
  114. package/core/AbiError.ts +121 -27
  115. package/core/AbiEvent.ts +145 -1
  116. package/core/AbiFunction.ts +272 -11
  117. package/core/AbiItem.ts +87 -3
  118. package/erc4337/EntryPoint/package.json +6 -0
  119. package/erc4337/RpcSchema/package.json +6 -0
  120. package/erc4337/UserOperation/package.json +6 -0
  121. package/erc4337/UserOperationGas/package.json +6 -0
  122. package/erc4337/UserOperationReceipt/package.json +6 -0
  123. package/erc4337/package.json +6 -0
  124. package/erc6492/SignatureErc6492/package.json +6 -0
  125. package/erc6492/SignatureErc6492.ts +2 -2
  126. package/erc6492/index.ts +2 -2
  127. package/erc6492/package.json +6 -0
  128. package/erc8010/SignatureErc8010/package.json +6 -0
  129. package/erc8010/SignatureErc8010.ts +2 -2
  130. package/erc8010/index.ts +2 -2
  131. package/erc8010/package.json +6 -0
  132. package/index.docs/package.json +6 -0
  133. package/package.json +1 -1
  134. package/trusted-setups/Paths/package.json +6 -0
  135. package/trusted-setups/package.json +6 -0
  136. package/version.ts +1 -1
  137. package/window/package.json +6 -0
package/core/AbiError.ts CHANGED
@@ -75,6 +75,25 @@ export function decode<
75
75
  * ```
76
76
  *
77
77
  * @example
78
+ * ### ABI-shorthand
79
+ *
80
+ * You can also specify an entire ABI object as a parameter to {@link ox#AbiError.(decode:function)}:
81
+ *
82
+ * ```ts twoslash
83
+ * // @noErrors
84
+ * import { Abi, AbiError } from 'ox'
85
+ *
86
+ * const abi = Abi.from([...])
87
+ *
88
+ * const value = AbiError.decode(
89
+ * abi, // [!code hl]
90
+ * 'InvalidSignature', // [!code hl]
91
+ * '0x...'
92
+ * )
93
+ * // @log: [420n, 69n, 1]
94
+ * ```
95
+ *
96
+ * @example
78
97
  * ### End-to-end
79
98
  *
80
99
  * Below is an end-to-end example of using `AbiError.decode` to decode the revert error of an `approve` contract call on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
@@ -139,17 +158,58 @@ export function decode<
139
158
  * @param options - Decoding options.
140
159
  * @returns The decoded error.
141
160
  */
142
- export function decode(
143
- abiError: AbiError,
161
+ export function decode<
162
+ const abi extends Abi.Abi | readonly unknown[],
163
+ name extends Name<abi>,
164
+ const args extends
165
+ | AbiItem_internal.ExtractArgs<abi, name>
166
+ | undefined = undefined,
167
+ as extends 'Object' | 'Array' = 'Array',
168
+ //
169
+ abiError extends AbiError = AbiItem.fromAbi.ReturnType<
170
+ abi,
171
+ name,
172
+ args,
173
+ AbiError
174
+ >,
175
+ allNames = Name<abi>,
176
+ >(
177
+ abi: abi | Abi.Abi | readonly unknown[],
178
+ name: Hex.Hex | (name extends allNames ? name : never),
144
179
  data: Hex.Hex,
145
- options?: decode.Options | undefined,
146
- ): unknown | readonly unknown[] | undefined
147
- /** @internal */
148
- export function decode(
149
- abiError: AbiError,
180
+ options?: decode.Options<as> | undefined,
181
+ ): decode.ReturnType<abiError, as>
182
+ export function decode<
183
+ const abiError extends AbiError,
184
+ as extends 'Object' | 'Array' = 'Array',
185
+ >(
186
+ abiError: abiError | AbiError,
150
187
  data: Hex.Hex,
151
- options: decode.Options = {},
188
+ options?: decode.Options<as> | undefined,
189
+ ): decode.ReturnType<abiError, as>
190
+ // eslint-disable-next-line jsdoc/require-jsdoc
191
+ export function decode(
192
+ ...parameters:
193
+ | [
194
+ abi: Abi.Abi | readonly unknown[],
195
+ name: Hex.Hex | string,
196
+ data: Hex.Hex,
197
+ options?: decode.Options | undefined,
198
+ ]
199
+ | [abiError: AbiError, data: Hex.Hex, options?: decode.Options | undefined]
152
200
  ): decode.ReturnType {
201
+ const [abiError, data, options = {}] = (() => {
202
+ if (Array.isArray(parameters[0])) {
203
+ const [abi, name, data, options] = parameters as [
204
+ Abi.Abi | readonly unknown[],
205
+ Hex.Hex | string,
206
+ Hex.Hex,
207
+ decode.Options | undefined,
208
+ ]
209
+ return [fromAbi(abi, name), data, options]
210
+ }
211
+ return parameters as [AbiError, Hex.Hex, decode.Options | undefined]
212
+ })()
153
213
  if (Hex.size(data) < 4) throw new AbiItem.InvalidSelectorSizeError({ data })
154
214
  if (abiError.inputs.length === 0) return undefined
155
215
 
@@ -223,42 +283,76 @@ export declare namespace decode {
223
283
  * ```
224
284
  *
225
285
  * @example
226
- * You can extract an ABI Error from a JSON ABI with {@link ox#AbiError.(fromAbi:function)}:
286
+ * ### ABI-shorthand
287
+ *
288
+ * You can also specify an entire ABI object and an error name as parameters to `AbiError.encode`.
227
289
  *
228
290
  * ```ts twoslash
229
291
  * // @noErrors
230
292
  * import { Abi, AbiError } from 'ox'
231
293
  *
232
- * const abi = Abi.from([ // [!code hl]
233
- * // ... // [!code hl]
234
- * { // [!code hl]
235
- * name: 'InvalidSignature', // [!code hl]
236
- * type: 'error', // [!code hl]
237
- * inputs: [ // [!code hl]
238
- * { name: 'r', type: 'uint256' }, // [!code hl]
239
- * { name: 's', type: 'uint256' }, // [!code hl]
240
- * { name: 'yParity', type: 'uint8' }, // [!code hl]
241
- * ], // [!code hl]
242
- * }, // [!code hl]
243
- * // ... // [!code hl]
244
- * ]) // [!code hl]
245
- * const error = AbiError.fromAbi(abi, 'InvalidSignature') // [!code hl]
294
+ * const abi = Abi.from([...])
246
295
  *
247
296
  * const data = AbiError.encode(
248
- * error,
249
- * ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
297
+ * abi, // [!code hl]
298
+ * 'InvalidSignature', // [!code hl]
299
+ * [1n, 2n, 0]
250
300
  * )
251
- * // @log: '0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000010f2c'
252
301
  * ```
253
302
  *
254
303
  * @param abiError - ABI Error to encode
255
304
  * @param args - Error arguments
256
305
  * @returns ABI-encoded error name and arguments
257
306
  */
307
+ export function encode<
308
+ const abi extends Abi.Abi | readonly unknown[],
309
+ name extends Name<abi>,
310
+ const args extends
311
+ | AbiItem_internal.ExtractArgs<abi, name>
312
+ | undefined = undefined,
313
+ //
314
+ abiError extends AbiError = AbiItem.fromAbi.ReturnType<
315
+ abi,
316
+ name,
317
+ args,
318
+ AbiError
319
+ >,
320
+ allNames = Name<abi>,
321
+ >(
322
+ abi: abi | Abi.Abi | readonly unknown[],
323
+ name: Hex.Hex | (name extends allNames ? name : never),
324
+ ...args: encode.Args<abiError>
325
+ ): encode.ReturnType
258
326
  export function encode<const abiError extends AbiError>(
259
327
  abiError: abiError,
260
328
  ...args: encode.Args<abiError>
261
- ): encode.ReturnType {
329
+ ): encode.ReturnType
330
+ // eslint-disable-next-line jsdoc/require-jsdoc
331
+ export function encode(
332
+ ...parameters:
333
+ | [
334
+ abi: Abi.Abi | readonly unknown[],
335
+ name: Hex.Hex | string,
336
+ ...args: readonly unknown[],
337
+ ]
338
+ | [abiError: AbiError, ...args: readonly unknown[]]
339
+ ) {
340
+ const [abiError, args] = (() => {
341
+ if (Array.isArray(parameters[0])) {
342
+ const [abi, name, ...args] = parameters as [
343
+ Abi.Abi | readonly unknown[],
344
+ Hex.Hex | string,
345
+ ...(readonly unknown[]),
346
+ ]
347
+ return [fromAbi(abi, name), args]
348
+ }
349
+ const [abiError, ...args] = parameters as [
350
+ AbiError,
351
+ ...(readonly unknown[]),
352
+ ]
353
+ return [abiError, args]
354
+ })()
355
+
262
356
  const selector = getSelector(abiError)
263
357
 
264
358
  const data =
package/core/AbiEvent.ts CHANGED
@@ -237,6 +237,38 @@ export declare namespace assertArgs {
237
237
  * ```
238
238
  *
239
239
  * @example
240
+ * ### ABI-shorthand
241
+ *
242
+ * You can also specify an entire ABI object and an event name as parameters to {@link ox#AbiEvent.(decode:function)}:
243
+ *
244
+ * ```ts twoslash
245
+ * // @noErrors
246
+ * import { Abi, AbiEvent } from 'ox'
247
+ *
248
+ * const abi = Abi.from([...])
249
+ * const log = {
250
+ * // ...
251
+ * data: '0x0000000000000000000000000000000000000000000000000000000000000001',
252
+ * topics: [
253
+ * '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
254
+ * '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
255
+ * '0x000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac',
256
+ * ],
257
+ * } as const
258
+ *
259
+ * const decoded = AbiEvent.decode(
260
+ * abi, // [!code focus]
261
+ * 'Transfer', // [!code focus]
262
+ * log
263
+ * )
264
+ * // @log: {
265
+ * // @log: from: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
266
+ * // @log: to: '0xa5cc3c03994db5b0d9a5eedd10cabab0813678ac',
267
+ * // @log: value: 1n
268
+ * // @log: }
269
+ * ```
270
+ *
271
+ * @example
240
272
  * ### End-to-end
241
273
  *
242
274
  * Below is an end-to-end example of using `AbiEvent.decode` to decode the topics of a `Transfer` event on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
@@ -286,10 +318,51 @@ export declare namespace assertArgs {
286
318
  * @param log - `topics` & `data` to decode.
287
319
  * @returns The decoded event.
288
320
  */
321
+ export function decode<
322
+ const abi extends Abi.Abi | readonly unknown[],
323
+ name extends Name<abi>,
324
+ const args extends
325
+ | AbiItem_internal.ExtractArgs<abi, name>
326
+ | undefined = undefined,
327
+ //
328
+ abiEvent extends AbiEvent = AbiItem.fromAbi.ReturnType<
329
+ abi,
330
+ name,
331
+ args,
332
+ AbiEvent
333
+ >,
334
+ allNames = Name<abi>,
335
+ >(
336
+ abi: abi | Abi.Abi | readonly unknown[],
337
+ name: Hex.Hex | (name extends allNames ? name : never),
338
+ log: decode.Log,
339
+ ): decode.ReturnType<abiEvent>
289
340
  export function decode<const abiEvent extends AbiEvent>(
290
341
  abiEvent: abiEvent | AbiEvent,
291
342
  log: decode.Log,
292
- ): decode.ReturnType<abiEvent> {
343
+ ): decode.ReturnType<abiEvent>
344
+ // eslint-disable-next-line jsdoc/require-jsdoc
345
+ export function decode(
346
+ ...parameters:
347
+ | [
348
+ abi: Abi.Abi | readonly unknown[],
349
+ name: Hex.Hex | string,
350
+ log: decode.Log,
351
+ ]
352
+ | [abiEvent: AbiEvent, log: decode.Log]
353
+ ): decode.ReturnType {
354
+ const [abiEvent, log] = (() => {
355
+ if (Array.isArray(parameters[0])) {
356
+ const [abi, name, log] = parameters as [
357
+ Abi.Abi | readonly unknown[],
358
+ Hex.Hex | string,
359
+ decode.Log,
360
+ ]
361
+ return [fromAbi(abi, name), log]
362
+ }
363
+ return parameters as [AbiEvent, decode.Log]
364
+ })()
365
+
293
366
  const { data, topics } = log
294
367
 
295
368
  const [selector_, ...argTopics] = topics
@@ -449,6 +522,32 @@ export declare namespace decode {
449
522
  * ```
450
523
  *
451
524
  * @example
525
+ * ### ABI-shorthand
526
+ *
527
+ * You can also specify an entire ABI object and an event name as parameters to {@link ox#AbiEvent.(encode:function)}:
528
+ *
529
+ * ```ts twoslash
530
+ * // @noErrors
531
+ * import { Abi, AbiEvent } from 'ox'
532
+ *
533
+ * const abi = Abi.from([...])
534
+ *
535
+ * const { topics } = AbiEvent.encode(
536
+ * abi, // [!code focus]
537
+ * 'Transfer', // [!code focus]
538
+ * {
539
+ * from: '0xf39fd6e51aad88f6f4ce6ab882779cfffb92266', // [!code focus]
540
+ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
541
+ * }
542
+ * )
543
+ * // @log: [
544
+ * // @log: '0x406dade31f7ae4b5dbc276258c28dde5ae6d5c2773c5745802c493a2360e55e0',
545
+ * // @log: '0x00000000000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266',
546
+ * // @log: '0x0000000000000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c8'
547
+ * // @log: ]
548
+ * ```
549
+ *
550
+ * @example
452
551
  * ### End-to-end
453
552
  *
454
553
  * Below is an end-to-end example of using `AbiEvent.encode` to encode the topics of a `Transfer` event and query for events matching the encoded topics on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
@@ -496,10 +595,55 @@ export declare namespace decode {
496
595
  * @param args - The arguments to encode.
497
596
  * @returns The encoded event topics.
498
597
  */
598
+ export function encode<
599
+ const abi extends Abi.Abi | readonly unknown[],
600
+ name extends Name<abi>,
601
+ const args extends
602
+ | AbiItem_internal.ExtractArgs<abi, name>
603
+ | undefined = undefined,
604
+ //
605
+ abiEvent extends AbiEvent = AbiItem.fromAbi.ReturnType<
606
+ abi,
607
+ name,
608
+ args,
609
+ AbiEvent
610
+ >,
611
+ allNames = Name<abi>,
612
+ >(
613
+ abi: abi | Abi.Abi | readonly unknown[],
614
+ name: Hex.Hex | (name extends allNames ? name : never),
615
+ ...[args]: encode.Args<abiEvent>
616
+ ): encode.ReturnType
499
617
  export function encode<const abiEvent extends AbiEvent>(
500
618
  abiEvent: abiEvent | AbiEvent,
501
619
  ...[args]: encode.Args<abiEvent>
620
+ ): encode.ReturnType
621
+ // eslint-disable-next-line jsdoc/require-jsdoc
622
+ export function encode(
623
+ ...parameters:
624
+ | [
625
+ abi: Abi.Abi | readonly unknown[],
626
+ name: Hex.Hex | string,
627
+ args?: readonly unknown[] | Record<string, unknown>,
628
+ ]
629
+ | [abiEvent: AbiEvent, args?: readonly unknown[] | Record<string, unknown>]
502
630
  ): encode.ReturnType {
631
+ const [abiEvent, args] = (() => {
632
+ if (Array.isArray(parameters[0])) {
633
+ const [abi, name, args] = parameters as [
634
+ Abi.Abi | readonly unknown[],
635
+ Hex.Hex | string,
636
+ readonly unknown[] | Record<string, unknown> | undefined,
637
+ ]
638
+ return [fromAbi(abi, name), args]
639
+ }
640
+ const [abiEvent, args] = parameters as [
641
+ AbiEvent,
642
+ readonly unknown[] | Record<string, unknown> | undefined,
643
+ ]
644
+ return [abiEvent, args]
645
+ })()
646
+
503
647
  let topics: (Hex.Hex | Hex.Hex[] | null)[] = []
504
648
  if (args && abiEvent.inputs) {
505
649
  const indexedInputs = abiEvent.inputs.filter(