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.
- package/Abi/package.json +6 -0
- package/AbiConstructor/package.json +6 -0
- package/AbiError/package.json +6 -0
- package/AbiEvent/package.json +6 -0
- package/AbiFunction/package.json +6 -0
- package/AbiItem/package.json +6 -0
- package/AbiParameters/package.json +6 -0
- package/AccessList/package.json +6 -0
- package/AccountProof/package.json +6 -0
- package/Address/package.json +6 -0
- package/AesGcm/package.json +6 -0
- package/Authorization/package.json +6 -0
- package/Base58/package.json +6 -0
- package/Base64/package.json +6 -0
- package/BinaryStateTree/package.json +6 -0
- package/Blobs/package.json +6 -0
- package/Block/package.json +6 -0
- package/BlockOverrides/package.json +6 -0
- package/Bloom/package.json +6 -0
- package/Bls/package.json +6 -0
- package/BlsPoint/package.json +6 -0
- package/Bytes/package.json +6 -0
- package/CHANGELOG.md +28 -0
- package/Caches/package.json +6 -0
- package/ContractAddress/package.json +6 -0
- package/Ed25519/package.json +6 -0
- package/Ens/package.json +6 -0
- package/Errors/package.json +6 -0
- package/Fee/package.json +6 -0
- package/Filter/package.json +6 -0
- package/Hash/package.json +6 -0
- package/HdKey/package.json +6 -0
- package/Hex/package.json +6 -0
- package/Json/package.json +6 -0
- package/Keystore/package.json +6 -0
- package/Kzg/package.json +6 -0
- package/Log/package.json +6 -0
- package/Mnemonic/package.json +6 -0
- package/P256/package.json +6 -0
- package/PersonalMessage/package.json +6 -0
- package/Provider/package.json +6 -0
- package/PublicKey/package.json +6 -0
- package/Rlp/package.json +6 -0
- package/RpcRequest/package.json +6 -0
- package/RpcResponse/package.json +6 -0
- package/RpcSchema/package.json +6 -0
- package/RpcTransport/package.json +6 -0
- package/Secp256k1/package.json +6 -0
- package/Signature/package.json +6 -0
- package/Siwe/package.json +6 -0
- package/Solidity/package.json +6 -0
- package/StateOverrides/package.json +6 -0
- package/Transaction/package.json +6 -0
- package/TransactionEnvelope/package.json +6 -0
- package/TransactionEnvelopeEip1559/package.json +6 -0
- package/TransactionEnvelopeEip2930/package.json +6 -0
- package/TransactionEnvelopeEip4844/package.json +6 -0
- package/TransactionEnvelopeEip7702/package.json +6 -0
- package/TransactionEnvelopeLegacy/package.json +6 -0
- package/TransactionReceipt/package.json +6 -0
- package/TransactionRequest/package.json +6 -0
- package/TypedData/package.json +6 -0
- package/ValidatorData/package.json +6 -0
- package/Value/package.json +6 -0
- package/WebAuthnP256/package.json +6 -0
- package/WebCryptoP256/package.json +6 -0
- package/Withdrawal/package.json +6 -0
- package/X25519/package.json +6 -0
- package/_cjs/core/AbiConstructor.js +16 -2
- package/_cjs/core/AbiConstructor.js.map +1 -1
- package/_cjs/core/AbiError.js +17 -2
- package/_cjs/core/AbiError.js.map +1 -1
- package/_cjs/core/AbiEvent.js +17 -2
- package/_cjs/core/AbiEvent.js.map +1 -1
- package/_cjs/core/AbiFunction.js +35 -8
- package/_cjs/core/AbiFunction.js.map +1 -1
- package/_cjs/core/AbiItem.js +24 -3
- package/_cjs/core/AbiItem.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/core/Abi.js +2 -2
- package/_esm/core/Abi.js.map +1 -1
- package/_esm/core/AbiConstructor.js +18 -56
- package/_esm/core/AbiConstructor.js.map +1 -1
- package/_esm/core/AbiError.js +19 -54
- package/_esm/core/AbiError.js.map +1 -1
- package/_esm/core/AbiEvent.js +19 -187
- package/_esm/core/AbiEvent.js.map +1 -1
- package/_esm/core/AbiFunction.js +39 -242
- package/_esm/core/AbiFunction.js.map +1 -1
- package/_esm/core/AbiItem.js +27 -93
- package/_esm/core/AbiItem.js.map +1 -1
- package/_esm/erc6492/SignatureErc6492.js +2 -2
- package/_esm/erc6492/index.js +2 -2
- package/_esm/erc8010/SignatureErc8010.js +2 -2
- package/_esm/erc8010/index.js +2 -2
- package/_esm/version.js +1 -1
- package/_types/core/AbiConstructor.d.ts +43 -4
- package/_types/core/AbiConstructor.d.ts.map +1 -1
- package/_types/core/AbiError.d.ts +29 -19
- package/_types/core/AbiError.d.ts.map +1 -1
- package/_types/core/AbiEvent.d.ts +60 -0
- package/_types/core/AbiEvent.d.ts.map +1 -1
- package/_types/core/AbiFunction.d.ts +84 -2
- package/_types/core/AbiFunction.d.ts.map +1 -1
- package/_types/core/AbiItem.d.ts +36 -0
- package/_types/core/AbiItem.d.ts.map +1 -1
- package/_types/erc6492/SignatureErc6492.d.ts +2 -2
- package/_types/erc6492/index.d.ts +2 -2
- package/_types/erc8010/SignatureErc8010.d.ts +2 -2
- package/_types/erc8010/index.d.ts +2 -2
- package/_types/version.d.ts +1 -1
- package/core/Abi.ts +2 -2
- package/core/AbiConstructor.ts +96 -12
- package/core/AbiError.ts +121 -27
- package/core/AbiEvent.ts +145 -1
- package/core/AbiFunction.ts +272 -11
- package/core/AbiItem.ts +87 -3
- package/erc4337/EntryPoint/package.json +6 -0
- package/erc4337/RpcSchema/package.json +6 -0
- package/erc4337/UserOperation/package.json +6 -0
- package/erc4337/UserOperationGas/package.json +6 -0
- package/erc4337/UserOperationReceipt/package.json +6 -0
- package/erc4337/package.json +6 -0
- package/erc6492/SignatureErc6492/package.json +6 -0
- package/erc6492/SignatureErc6492.ts +2 -2
- package/erc6492/index.ts +2 -2
- package/erc6492/package.json +6 -0
- package/erc8010/SignatureErc8010/package.json +6 -0
- package/erc8010/SignatureErc8010.ts +2 -2
- package/erc8010/index.ts +2 -2
- package/erc8010/package.json +6 -0
- package/index.docs/package.json +6 -0
- package/package.json +1 -1
- package/trusted-setups/Paths/package.json +6 -0
- package/trusted-setups/package.json +6 -0
- package/version.ts +1 -1
- package/window/package.json +6 -0
package/core/AbiFunction.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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)))
|
|
@@ -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,
|
|
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'
|
|
@@ -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,
|
|
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
|
* ```
|
package/package.json
CHANGED