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
@@ -90,13 +90,70 @@ export type ExtractNames<
90
90
  * // @log: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
91
91
  * ```
92
92
  *
93
+ * @example
94
+ * ### ABI-shorthand
95
+ *
96
+ * You can also specify an entire ABI object and a function name as parameters to {@link ox#AbiFunction.(decodeData:function)}:
97
+ *
98
+ * ```ts twoslash
99
+ * // @noErrors
100
+ * import { Abi, AbiFunction } from 'ox'
101
+ *
102
+ * const abi = Abi.from([...])
103
+ * const data = '0x...
104
+ *
105
+ * const input = AbiFunction.decodeData(
106
+ * abi, // [!code focus]
107
+ * 'approve', // [!code focus]
108
+ * data
109
+ * )
110
+ * // @log: ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
111
+ * ```
112
+ *
93
113
  * @param abiFunction - The ABI Item to decode.
94
114
  * @param data - The data to decode.
95
115
  */
116
+ export function decodeData<
117
+ const abi extends Abi.Abi | readonly unknown[],
118
+ name extends Name<abi>,
119
+ const args extends
120
+ | AbiItem_internal.ExtractArgs<abi, name>
121
+ | undefined = undefined,
122
+ //
123
+ abiFunction extends AbiFunction = AbiItem.fromAbi.ReturnType<
124
+ abi,
125
+ name,
126
+ args,
127
+ AbiFunction
128
+ >,
129
+ allNames = Name<abi>,
130
+ >(
131
+ abi: abi | Abi.Abi | readonly unknown[],
132
+ name: Hex.Hex | (name extends allNames ? name : never),
133
+ data: Hex.Hex,
134
+ ): decodeData.ReturnType<abiFunction>
96
135
  export function decodeData<const abiItem extends AbiFunction>(
97
136
  abiFunction: abiItem | AbiFunction,
98
137
  data: Hex.Hex,
99
- ): decodeData.ReturnType<abiItem> {
138
+ ): decodeData.ReturnType<abiItem>
139
+ // eslint-disable-next-line jsdoc/require-jsdoc
140
+ export function decodeData(
141
+ ...parameters:
142
+ | [abi: Abi.Abi | readonly unknown[], name: Hex.Hex | string, data: Hex.Hex]
143
+ | [abiFunction: AbiFunction, data: Hex.Hex]
144
+ ) {
145
+ const [abiFunction, data] = (() => {
146
+ if (Array.isArray(parameters[0])) {
147
+ const [abi, name, data] = parameters as [
148
+ Abi.Abi | readonly unknown[],
149
+ Hex.Hex | string,
150
+ Hex.Hex,
151
+ ]
152
+ return [fromAbi(abi, name), data]
153
+ }
154
+ return parameters as [AbiFunction, Hex.Hex]
155
+ })()
156
+
100
157
  const { overloads } = abiFunction
101
158
 
102
159
  if (Hex.size(data) < 4) throw new AbiItem.InvalidSelectorSizeError({ data })
@@ -174,6 +231,27 @@ export declare namespace decodeData {
174
231
  * ```
175
232
  *
176
233
  * @example
234
+ * ### ABI-shorthand
235
+ *
236
+ * You can also specify an entire ABI object and a function name as parameters to {@link ox#AbiFunction.(decodeResult:function)}:
237
+ *
238
+ * ```ts twoslash
239
+ * // @noErrors
240
+ * import { Abi, AbiFunction } from 'ox'
241
+ *
242
+ * const data = '0x000000000000000000000000000000000000000000000000000000000000002a'
243
+ *
244
+ * const erc20Abi = Abi.from([...])
245
+ *
246
+ * const output = AbiFunction.decodeResult(
247
+ * erc20Abi, // [!code focus]
248
+ * 'totalSupply', // [!code focus]
249
+ * data
250
+ * )
251
+ * // @log: 42n
252
+ * ```
253
+ *
254
+ * @example
177
255
  * ### End-to-end
178
256
  *
179
257
  * Below is an end-to-end example of using `AbiFunction.decodeResult` to decode the result of a `balanceOf` contract call on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
@@ -230,14 +308,67 @@ export declare namespace decodeData {
230
308
  * @param options - Decoding options
231
309
  * @returns Decoded function output
232
310
  */
311
+ export function decodeResult<
312
+ const abi extends Abi.Abi | readonly unknown[],
313
+ name extends Name<abi>,
314
+ const args extends
315
+ | AbiItem_internal.ExtractArgs<abi, name>
316
+ | undefined = undefined,
317
+ //
318
+ abiFunction extends AbiFunction = AbiItem.fromAbi.ReturnType<
319
+ abi,
320
+ name,
321
+ args,
322
+ AbiFunction
323
+ >,
324
+ allNames = Name<abi>,
325
+ as extends 'Object' | 'Array' = 'Array',
326
+ >(
327
+ abi: abi | Abi.Abi | readonly unknown[],
328
+ name: Hex.Hex | (name extends allNames ? name : never),
329
+ data: Hex.Hex,
330
+ options?: decodeResult.Options<as> | undefined,
331
+ ): decodeResult.ReturnType<abiFunction, as>
233
332
  export function decodeResult<
234
333
  const abiFunction extends AbiFunction,
235
334
  as extends 'Object' | 'Array' = 'Array',
236
335
  >(
237
336
  abiFunction: abiFunction | AbiFunction,
238
337
  data: Hex.Hex,
239
- options: decodeResult.Options<as> = {},
240
- ): decodeResult.ReturnType<abiFunction, as> {
338
+ options?: decodeResult.Options<as> | undefined,
339
+ ): decodeResult.ReturnType<abiFunction, as>
340
+ // eslint-disable-next-line jsdoc/require-jsdoc
341
+ export function decodeResult(
342
+ ...parameters:
343
+ | [
344
+ abi: Abi.Abi | readonly unknown[],
345
+ name: Hex.Hex | string,
346
+ data: Hex.Hex,
347
+ options?: decodeResult.Options | undefined,
348
+ ]
349
+ | [
350
+ abiFunction: AbiFunction,
351
+ data: Hex.Hex,
352
+ options?: decodeResult.Options | undefined,
353
+ ]
354
+ ) {
355
+ const [abiFunction, data, options = {}] = (() => {
356
+ if (Array.isArray(parameters[0])) {
357
+ const [abi, name, data, options] = parameters as [
358
+ Abi.Abi | readonly unknown[],
359
+ Hex.Hex | string,
360
+ Hex.Hex,
361
+ decodeResult.Options | undefined,
362
+ ]
363
+ return [fromAbi(abi, name), data, options]
364
+ }
365
+ return parameters as [
366
+ AbiFunction,
367
+ Hex.Hex,
368
+ decodeResult.Options | undefined,
369
+ ]
370
+ })()
371
+
241
372
  const values = AbiParameters.decode(abiFunction.outputs, data, options)
242
373
  if (values && Object.keys(values).length === 0) return undefined
243
374
  if (values && Object.keys(values).length === 1) {
@@ -248,7 +379,7 @@ export function decodeResult<
248
379
  }
249
380
 
250
381
  export declare namespace decodeResult {
251
- type Options<as extends 'Object' | 'Array'> = {
382
+ type Options<as extends 'Object' | 'Array' = 'Array'> = {
252
383
  /**
253
384
  * Whether the decoded values should be returned as an `Object` or `Array`.
254
385
  *
@@ -324,6 +455,24 @@ export declare namespace decodeResult {
324
455
  * ```
325
456
  *
326
457
  * @example
458
+ * ### ABI-shorthand
459
+ *
460
+ * You can specify an entire ABI object and a function name as parameters to {@link ox#AbiFunction.(encodeData:function)}:
461
+ *
462
+ * ```ts twoslash
463
+ * // @noErrors
464
+ * import { Abi, AbiFunction } from 'ox'
465
+ *
466
+ * const erc20Abi = Abi.from([...])
467
+ *
468
+ * const data = AbiFunction.encodeData(
469
+ * erc20Abi, // [!code focus]
470
+ * 'approve', // [!code focus]
471
+ * ['0xd8da6bf26964af9d7eed9e03e53415d37aa96045', 69420n]
472
+ * )
473
+ * ```
474
+ *
475
+ * @example
327
476
  * ### End-to-end
328
477
  *
329
478
  * Below is an end-to-end example of using `AbiFunction.encodeData` to encode the input of a `balanceOf` contract call on the [Wagmi Mint Example contract](https://etherscan.io/address/0xfba3912ca04dd458c843e2ee08967fc04f3579c2).
@@ -378,24 +527,64 @@ export declare namespace decodeResult {
378
527
  * @param args - Function arguments
379
528
  * @returns ABI-encoded function name and arguments
380
529
  */
530
+ export function encodeData<
531
+ const abi extends Abi.Abi | readonly unknown[],
532
+ name extends Name<abi>,
533
+ const args extends
534
+ | AbiItem_internal.ExtractArgs<abi, name>
535
+ | undefined = undefined,
536
+ //
537
+ abiFunction extends AbiFunction = AbiItem.fromAbi.ReturnType<
538
+ abi,
539
+ name,
540
+ args,
541
+ AbiFunction
542
+ >,
543
+ allNames = Name<abi>,
544
+ >(
545
+ abi: abi | Abi.Abi | readonly unknown[],
546
+ name: Hex.Hex | (name extends allNames ? name : never),
547
+ ...args: encodeData.Args<abiFunction>
548
+ ): Hex.Hex
381
549
  export function encodeData<const abiFunction extends AbiFunction>(
382
550
  abiFunction: abiFunction | AbiFunction,
383
551
  ...args: encodeData.Args<abiFunction>
384
- ): Hex.Hex {
552
+ ): Hex.Hex
553
+ // eslint-disable-next-line jsdoc/require-jsdoc
554
+ export function encodeData(
555
+ ...parameters:
556
+ | [
557
+ abi: Abi.Abi | readonly unknown[],
558
+ name: Hex.Hex | string,
559
+ ...args: readonly unknown[],
560
+ ]
561
+ | [abiFunction: AbiFunction, ...args: readonly unknown[]]
562
+ ) {
563
+ const [abiFunction, args = []] = (() => {
564
+ if (Array.isArray(parameters[0])) {
565
+ const [abi, name, args] = parameters as [
566
+ Abi.Abi | readonly unknown[],
567
+ Hex.Hex | string,
568
+ readonly unknown[],
569
+ ]
570
+ return [fromAbi(abi, name, { args }), args]
571
+ }
572
+ const [abiFunction, args] = parameters as [AbiFunction, readonly unknown[]]
573
+ return [abiFunction, args]
574
+ })()
575
+
385
576
  const { overloads } = abiFunction
386
577
 
387
578
  const item = overloads
388
579
  ? (fromAbi([abiFunction as AbiFunction, ...overloads], abiFunction.name, {
389
- args: (args as any)[0],
580
+ args,
390
581
  }) as AbiFunction)
391
582
  : abiFunction
392
583
 
393
584
  const selector = getSelector(item)
394
585
 
395
586
  const data =
396
- args.length > 0
397
- ? AbiParameters.encode(item.inputs, (args as any)[0])
398
- : undefined
587
+ args.length > 0 ? AbiParameters.encode(item.inputs, args) : undefined
399
588
 
400
589
  return data ? Hex.concat(selector, data) : selector
401
590
  }
@@ -438,19 +627,91 @@ export declare namespace encodeData {
438
627
  * // @log: '0x000000000000000000000000000000000000000000000000000000000000002a'
439
628
  * ```
440
629
  *
630
+ * @example
631
+ * ### ABI-shorthand
632
+ *
633
+ * You can also specify an entire ABI object and a function name as parameters to {@link ox#AbiFunction.(encodeResult:function)}:
634
+ *
635
+ * ```ts twoslash
636
+ * // @noErrors
637
+ * import { Abi, AbiFunction } from 'ox'
638
+ *
639
+ * const abi = Abi.from([...])
640
+ *
641
+ * const data = AbiFunction.encodeResult(
642
+ * abi, // [!code focus]
643
+ * 'totalSupply', // [!code focus]
644
+ * 42n
645
+ * )
646
+ * // @log: '0x000000000000000000000000000000000000000000000000000000000000002a'
647
+ * ```
648
+ *
441
649
  * @param abiFunction - The ABI item to encode the function output for.
442
650
  * @param output - The function output to encode.
443
651
  * @param options - Encoding options.
444
652
  * @returns The encoded function output.
445
653
  */
654
+ export function encodeResult<
655
+ const abi extends Abi.Abi | readonly unknown[],
656
+ name extends Name<abi>,
657
+ const args extends
658
+ | AbiItem_internal.ExtractArgs<abi, name>
659
+ | undefined = undefined,
660
+ as extends 'Object' | 'Array' = 'Array',
661
+ //
662
+ abiFunction extends AbiFunction = AbiItem.fromAbi.ReturnType<
663
+ abi,
664
+ name,
665
+ args,
666
+ AbiFunction
667
+ >,
668
+ allNames = Name<abi>,
669
+ >(
670
+ abi: abi | Abi.Abi | readonly unknown[],
671
+ name: Hex.Hex | (name extends allNames ? name : never),
672
+ output: encodeResult.Output<abiFunction, as>,
673
+ options?: encodeResult.Options<as>,
674
+ ): Hex.Hex
446
675
  export function encodeResult<
447
676
  const abiFunction extends AbiFunction,
448
677
  as extends 'Object' | 'Array' = 'Array',
449
678
  >(
450
679
  abiFunction: abiFunction | AbiFunction,
451
680
  output: encodeResult.Output<abiFunction, as>,
452
- options: encodeResult.Options<as> = {},
453
- ): Hex.Hex {
681
+ options?: encodeResult.Options<as>,
682
+ ): Hex.Hex
683
+ // eslint-disable-next-line jsdoc/require-jsdoc
684
+ export function encodeResult(
685
+ ...parameters:
686
+ | [
687
+ abi: Abi.Abi | readonly unknown[],
688
+ name: Hex.Hex | string,
689
+ output: any,
690
+ options?: encodeResult.Options<any> | undefined,
691
+ ]
692
+ | [
693
+ abiFunction: AbiFunction,
694
+ output: any,
695
+ options?: encodeResult.Options<any> | undefined,
696
+ ]
697
+ ) {
698
+ const [abiFunction, output, options = {}] = (() => {
699
+ if (Array.isArray(parameters[0])) {
700
+ const [abi, name, output, options] = parameters as [
701
+ Abi.Abi | readonly unknown[],
702
+ Hex.Hex | string,
703
+ any,
704
+ encodeResult.Options<any> | undefined,
705
+ ]
706
+ return [fromAbi(abi, name), output, options]
707
+ }
708
+ return parameters as [
709
+ AbiFunction,
710
+ any,
711
+ encodeResult.Options<any> | undefined,
712
+ ]
713
+ })()
714
+
454
715
  const { as = 'Array' } = options
455
716
 
456
717
  const values = (() => {
package/core/AbiItem.ts CHANGED
@@ -493,6 +493,17 @@ export declare namespace fromAbi {
493
493
  *
494
494
  * @example
495
495
  * ```ts twoslash
496
+ * // @noErrors
497
+ * import { Abi, AbiItem } from 'ox'
498
+ *
499
+ * const erc20Abi = Abi.from([...])
500
+ *
501
+ * const selector = AbiItem.getSelector(erc20Abi, 'ownerOf')
502
+ * // @log: '0x6352211e'
503
+ * ```
504
+ *
505
+ * @example
506
+ * ```ts twoslash
496
507
  * import { AbiItem } from 'ox'
497
508
  *
498
509
  * const selector = AbiItem.getSelector({
@@ -508,7 +519,24 @@ export declare namespace fromAbi {
508
519
  * @param abiItem - The ABI item to compute the selector for. Can be a signature or an ABI item for an error, event, function, etc.
509
520
  * @returns The first 4 bytes of the {@link ox#Hash.(keccak256:function)} hash of the function signature.
510
521
  */
511
- export function getSelector(abiItem: string | AbiItem): Hex.Hex {
522
+ export function getSelector<
523
+ abi extends Abi.Abi | readonly unknown[],
524
+ name extends Name<abi>,
525
+ >(abi: abi | Abi.Abi | readonly unknown[], name: name): Hex.Hex
526
+ export function getSelector(abiItem: string | AbiItem): Hex.Hex
527
+ // eslint-disable-next-line jsdoc/require-jsdoc
528
+ export function getSelector(
529
+ ...parameters:
530
+ | [abi: Abi.Abi | readonly unknown[], name: string]
531
+ | [string | AbiItem]
532
+ ): Hex.Hex {
533
+ const abiItem = (() => {
534
+ if (Array.isArray(parameters[0])) {
535
+ const [abi, name] = parameters as [Abi.Abi | readonly unknown[], string]
536
+ return fromAbi(abi, name)
537
+ }
538
+ return parameters[0] as string | AbiItem
539
+ })()
512
540
  return Hex.slice(getSignatureHash(abiItem), 0, 4)
513
541
  }
514
542
 
@@ -532,6 +560,17 @@ export declare namespace getSelector {
532
560
  *
533
561
  * @example
534
562
  * ```ts twoslash
563
+ * // @noErrors
564
+ * import { Abi, AbiItem } from 'ox'
565
+ *
566
+ * const erc20Abi = Abi.from([...])
567
+ *
568
+ * const signature = AbiItem.getSignature(erc20Abi, 'ownerOf')
569
+ * // @log: 'ownerOf(uint256)'
570
+ * ```
571
+ *
572
+ * @example
573
+ * ```ts twoslash
535
574
  * import { AbiItem } from 'ox'
536
575
  *
537
576
  * const signature = AbiItem.getSignature({
@@ -547,7 +586,24 @@ export declare namespace getSelector {
547
586
  * @param abiItem - The ABI Item to compute the signature for.
548
587
  * @returns The stringified signature of the ABI Item.
549
588
  */
550
- export function getSignature(abiItem: string | AbiItem): string {
589
+ export function getSignature<
590
+ abi extends Abi.Abi | readonly unknown[],
591
+ name extends Name<abi>,
592
+ >(abi: abi | Abi.Abi | readonly unknown[], name: name): string
593
+ export function getSignature(abiItem: string | AbiItem): string
594
+ // eslint-disable-next-line jsdoc/require-jsdoc
595
+ export function getSignature(
596
+ ...parameters:
597
+ | [abi: Abi.Abi | readonly unknown[], name: string]
598
+ | [string | AbiItem]
599
+ ): string {
600
+ const abiItem = (() => {
601
+ if (Array.isArray(parameters[0])) {
602
+ const [abi, name] = parameters as [Abi.Abi | readonly unknown[], string]
603
+ return fromAbi(abi, name)
604
+ }
605
+ return parameters[0] as string | AbiItem
606
+ })()
551
607
  const signature = (() => {
552
608
  if (typeof abiItem === 'string') return abiItem
553
609
  return abitype.formatAbiItem(abiItem)
@@ -576,6 +632,17 @@ export declare namespace getSignature {
576
632
  *
577
633
  * @example
578
634
  * ```ts twoslash
635
+ * // @noErrors
636
+ * import { Abi, AbiItem } from 'ox'
637
+ *
638
+ * const erc20Abi = Abi.from([...])
639
+ *
640
+ * const hash = AbiItem.getSignatureHash(erc20Abi, 'Transfer')
641
+ * // @log: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef'
642
+ * ```
643
+ *
644
+ * @example
645
+ * ```ts twoslash
579
646
  * import { AbiItem } from 'ox'
580
647
  *
581
648
  * const hash = AbiItem.getSignatureHash({
@@ -593,7 +660,24 @@ export declare namespace getSignature {
593
660
  * @param abiItem - The ABI Item to compute the signature hash for.
594
661
  * @returns The {@link ox#Hash.(keccak256:function)} hash of the ABI item's signature.
595
662
  */
596
- export function getSignatureHash(abiItem: string | AbiItem): Hex.Hex {
663
+ export function getSignatureHash<
664
+ abi extends Abi.Abi | readonly unknown[],
665
+ name extends Name<abi>,
666
+ >(abi: abi | Abi.Abi | readonly unknown[], name: name): Hex.Hex
667
+ export function getSignatureHash(abiItem: string | AbiItem): Hex.Hex
668
+ // eslint-disable-next-line jsdoc/require-jsdoc
669
+ export function getSignatureHash(
670
+ ...parameters:
671
+ | [abi: Abi.Abi | readonly unknown[], name: string]
672
+ | [string | AbiItem]
673
+ ): Hex.Hex {
674
+ const abiItem = (() => {
675
+ if (Array.isArray(parameters[0])) {
676
+ const [abi, name] = parameters as [Abi.Abi | readonly unknown[], string]
677
+ return fromAbi(abi, name)
678
+ }
679
+ return parameters[0] as string | AbiItem
680
+ })()
597
681
  if (typeof abiItem !== 'string' && 'hash' in abiItem && abiItem.hash)
598
682
  return abiItem.hash as Hex.Hex
599
683
  return Hash.keccak256(Hex.fromString(getSignature(abiItem)))
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc4337/EntryPoint.d.ts",
4
+ "main": "../../_cjs/erc4337/EntryPoint.js",
5
+ "module": "../../_esm/erc4337/EntryPoint.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc4337/RpcSchema.d.ts",
4
+ "main": "../../_cjs/erc4337/RpcSchema.js",
5
+ "module": "../../_esm/erc4337/RpcSchema.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc4337/UserOperation.d.ts",
4
+ "main": "../../_cjs/erc4337/UserOperation.js",
5
+ "module": "../../_esm/erc4337/UserOperation.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc4337/UserOperationGas.d.ts",
4
+ "main": "../../_cjs/erc4337/UserOperationGas.js",
5
+ "module": "../../_esm/erc4337/UserOperationGas.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc4337/UserOperationReceipt.d.ts",
4
+ "main": "../../_cjs/erc4337/UserOperationReceipt.js",
5
+ "module": "../../_esm/erc4337/UserOperationReceipt.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/erc4337/index.d.ts",
4
+ "main": "../_cjs/erc4337/index.js",
5
+ "module": "../_esm/erc4337/index.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc6492/SignatureErc6492.d.ts",
4
+ "main": "../../_cjs/erc6492/SignatureErc6492.js",
5
+ "module": "../../_esm/erc6492/SignatureErc6492.js"
6
+ }
@@ -187,7 +187,7 @@ export declare namespace unwrap {
187
187
  *
188
188
  * @example
189
189
  * ```ts twoslash
190
- * import { Secp256k1 } from 'ox'
190
+ * import { Secp256k1, Signature } from 'ox'
191
191
  * import { SignatureErc6492 } from 'ox/erc6492' // [!code focus]
192
192
  *
193
193
  * const signature = Secp256k1.sign({
@@ -197,7 +197,7 @@ export declare namespace unwrap {
197
197
  *
198
198
  * const wrapped = SignatureErc6492.wrap({ // [!code focus]
199
199
  * data: '0xdeadbeef', // [!code focus]
200
- * signature, // [!code focus]
200
+ * signature: Signature.toHex(signature), // [!code focus]
201
201
  * to: '0x00000000219ab540356cBB839Cbe05303d7705Fa', // [!code focus]
202
202
  * }) // [!code focus]
203
203
  * ```
package/erc6492/index.ts CHANGED
@@ -7,7 +7,7 @@ export type {}
7
7
  *
8
8
  * @example
9
9
  * ```ts twoslash
10
- * import { Secp256k1, PersonalMessage } from 'ox'
10
+ * import { PersonalMessage, Secp256k1, Signature } from 'ox'
11
11
  * import { SignatureErc6492 } from 'ox/erc6492' // [!code focus]
12
12
  *
13
13
  * const signature = Secp256k1.sign({
@@ -17,7 +17,7 @@ export type {}
17
17
  *
18
18
  * const wrapped = SignatureErc6492.wrap({ // [!code focus]
19
19
  * data: '0xcafebabe', // [!code focus]
20
- * signature, // [!code focus]
20
+ * signature: Signature.toHex(signature), // [!code focus]
21
21
  * to: '0xcafebabecafebabecafebabecafebabecafebabe', // [!code focus]
22
22
  * }) // [!code focus]
23
23
  * // @log: '0x000000000000000000000000cafebabecafebabecafebabecafebabecafebabe000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000004deadbeef000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041fa78c5905fb0b9d6066ef531f962a62bc6ef0d5eb59ecb134056d206f75aaed7780926ff2601a935c2c79707d9e1799948c9f19dcdde1e090e903b19a07923d01c000000000000000000000000000000000000000000000000000000000000006492649264926492649264926492649264926492649264926492649264926492'
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/erc6492/index.d.ts",
4
+ "main": "../_cjs/erc6492/index.js",
5
+ "module": "../_esm/erc6492/index.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/erc8010/SignatureErc8010.d.ts",
4
+ "main": "../../_cjs/erc8010/SignatureErc8010.js",
5
+ "module": "../../_esm/erc8010/SignatureErc8010.js"
6
+ }
@@ -146,7 +146,7 @@ export declare namespace unwrap {
146
146
  * @example
147
147
  * ```ts twoslash
148
148
  * // @noErrors
149
- * import { Secp256k1 } from 'ox'
149
+ * import { Secp256k1, Signature } from 'ox'
150
150
  * import { SignatureErc8010 } from 'ox/erc8010' // [!code focus]
151
151
  *
152
152
  * const signature = Secp256k1.sign({
@@ -157,7 +157,7 @@ export declare namespace unwrap {
157
157
  * const wrapped = SignatureErc8010.wrap({ // [!code focus]
158
158
  * authorization: { ... }, // [!code focus]
159
159
  * data: '0xdeadbeef', // [!code focus]
160
- * signature, // [!code focus]
160
+ * signature: Signature.toHex(signature), // [!code focus]
161
161
  * }) // [!code focus]
162
162
  * ```
163
163
  *
package/erc8010/index.ts CHANGED
@@ -7,7 +7,7 @@ export type {}
7
7
  *
8
8
  * @example
9
9
  * ```ts twoslash
10
- * import { Authorization, Secp256k1, PersonalMessage } from 'ox'
10
+ * import { Authorization, PersonalMessage, Secp256k1, Signature } from 'ox'
11
11
  * import { SignatureErc8010 } from 'ox/erc8010' // [!code focus]
12
12
  *
13
13
  * const authorization = Authorization.from({
@@ -33,7 +33,7 @@ export type {}
33
33
  * const wrapped = SignatureErc8010.wrap({ // [!code focus]
34
34
  * authorization: authorizationSigned, // [!code focus]
35
35
  * data: '0xcafebabe', // [!code focus]
36
- * signature, // [!code focus]
36
+ * signature: Signature.toHex(signature), // [!code focus]
37
37
  * }) // [!code focus]
38
38
  * // @log: '0x000000000000000000000000cafebabecafebabecafebabecafebabecafebabe000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000004deadbeef000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041fa78c5905fb0b9d6066ef531f962a62bc6ef0d5eb59ecb134056d206f75aaed7780926ff2601a935c2c79707d9e1799948c9f19dcdde1e090e903b19a07923d01c000000000000000000000000000000000000000000000000000000000000008010801080108010801080108010801080108010801080108010801080108010'
39
39
  * ```
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/erc8010/index.d.ts",
4
+ "main": "../_cjs/erc8010/index.js",
5
+ "module": "../_esm/erc8010/index.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/undefined/index.docs.d.ts",
4
+ "main": "../_cjs/undefined/index.docs.js",
5
+ "module": "../_esm/undefined/index.docs.js"
6
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
- "version": "0.9.4",
4
+ "version": "0.9.6",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/trusted-setups/Paths.d.ts",
4
+ "main": "../../_cjs/trusted-setups/Paths.js",
5
+ "module": "../../_esm/trusted-setups/Paths.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../_types/trusted-setups/index.d.ts",
4
+ "main": "../_cjs/trusted-setups/index.js",
5
+ "module": "../_esm/trusted-setups/index.js"
6
+ }