ox 0.14.57 → 0.14.58
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/CHANGELOG.md +16 -0
- package/_cjs/core/AbiEvent.js +16 -4
- package/_cjs/core/AbiEvent.js.map +1 -1
- package/_cjs/core/Hex.js +5 -3
- package/_cjs/core/Hex.js.map +1 -1
- package/_cjs/core/RpcTransport.js +32 -19
- package/_cjs/core/RpcTransport.js.map +1 -1
- package/_cjs/core/TypedData.js +1 -1
- package/_cjs/core/TypedData.js.map +1 -1
- package/_cjs/core/internal/abiItem.js +46 -14
- package/_cjs/core/internal/abiItem.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/core/AbiEvent.js +19 -4
- package/_esm/core/AbiEvent.js.map +1 -1
- package/_esm/core/Hex.js +5 -3
- package/_esm/core/Hex.js.map +1 -1
- package/_esm/core/RpcTransport.js +38 -19
- package/_esm/core/RpcTransport.js.map +1 -1
- package/_esm/core/TypedData.js +1 -1
- package/_esm/core/TypedData.js.map +1 -1
- package/_esm/core/internal/abiItem.js +51 -17
- package/_esm/core/internal/abiItem.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/core/AbiEvent.d.ts.map +1 -1
- package/_types/core/Hex.d.ts +13 -1
- package/_types/core/Hex.d.ts.map +1 -1
- package/_types/core/RpcTransport.d.ts.map +1 -1
- package/_types/core/internal/abiItem.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/core/AbiEvent.ts +24 -3
- package/core/Hex.ts +17 -3
- package/core/RpcTransport.ts +40 -22
- package/core/TypedData.ts +1 -1
- package/core/internal/abiItem.ts +70 -21
- package/package.json +1 -1
- package/version.ts +1 -1
package/core/Hex.ts
CHANGED
|
@@ -34,17 +34,24 @@ export function assert(
|
|
|
34
34
|
value: unknown,
|
|
35
35
|
options: assert.Options = {},
|
|
36
36
|
): asserts value is Hex {
|
|
37
|
-
const { strict = false } = options
|
|
37
|
+
const { even = false, strict = false } = options
|
|
38
38
|
if (!value) throw new InvalidHexTypeError(value)
|
|
39
39
|
if (typeof value !== 'string') throw new InvalidHexTypeError(value)
|
|
40
40
|
if (strict) {
|
|
41
41
|
if (!/^0x[0-9a-fA-F]*$/.test(value)) throw new InvalidHexValueError(value)
|
|
42
42
|
}
|
|
43
43
|
if (!value.startsWith('0x')) throw new InvalidHexValueError(value)
|
|
44
|
+
if (even && value.length % 2 !== 0) throw new InvalidLengthError(value as Hex)
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export declare namespace assert {
|
|
47
48
|
type Options = {
|
|
49
|
+
/**
|
|
50
|
+
* Checks if the {@link ox#Hex.Hex} value has an even number of hexadecimal characters (whole bytes).
|
|
51
|
+
* Keep disabled for RPC quantities (e.g. `0x0`, `0x400`).
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
even?: boolean | undefined
|
|
48
55
|
/** Checks if the {@link ox#Hex.Hex} value contains invalid hexadecimal characters. @default false */
|
|
49
56
|
strict?: boolean | undefined
|
|
50
57
|
}
|
|
@@ -52,6 +59,7 @@ export declare namespace assert {
|
|
|
52
59
|
type ErrorType =
|
|
53
60
|
| InvalidHexTypeError
|
|
54
61
|
| InvalidHexValueError
|
|
62
|
+
| InvalidLengthError
|
|
55
63
|
| Errors.GlobalErrorType
|
|
56
64
|
}
|
|
57
65
|
|
|
@@ -741,9 +749,9 @@ export function validate(
|
|
|
741
749
|
value: unknown,
|
|
742
750
|
options: validate.Options = {},
|
|
743
751
|
): value is Hex {
|
|
744
|
-
const { strict = false } = options
|
|
752
|
+
const { even = false, strict = false } = options
|
|
745
753
|
try {
|
|
746
|
-
assert(value, { strict })
|
|
754
|
+
assert(value, { even, strict })
|
|
747
755
|
return true
|
|
748
756
|
} catch {
|
|
749
757
|
return false
|
|
@@ -752,6 +760,12 @@ export function validate(
|
|
|
752
760
|
|
|
753
761
|
export declare namespace validate {
|
|
754
762
|
type Options = {
|
|
763
|
+
/**
|
|
764
|
+
* Checks if the {@link ox#Hex.Hex} value has an even number of hexadecimal characters (whole bytes).
|
|
765
|
+
* Keep disabled for RPC quantities (e.g. `0x0`, `0x400`).
|
|
766
|
+
* @default false
|
|
767
|
+
*/
|
|
768
|
+
even?: boolean | undefined
|
|
755
769
|
/** Checks if the {@link ox#Hex.Hex} value contains invalid hexadecimal characters. @default false */
|
|
756
770
|
strict?: boolean | undefined
|
|
757
771
|
}
|
package/core/RpcTransport.ts
CHANGED
|
@@ -95,8 +95,14 @@ export function fromHttp<
|
|
|
95
95
|
? await fetchOptions_(body_)
|
|
96
96
|
: fetchOptions_
|
|
97
97
|
|
|
98
|
-
const response = await promise.withTimeout(
|
|
99
|
-
({ signal }) => {
|
|
98
|
+
const { data, response } = await promise.withTimeout(
|
|
99
|
+
async ({ signal }) => {
|
|
100
|
+
// Abort on whichever signal fires first, so that a caller's
|
|
101
|
+
// `signal` does not disable the timeout.
|
|
102
|
+
const signals = [
|
|
103
|
+
fetchOptions?.signal,
|
|
104
|
+
timeout > 0 ? signal : null,
|
|
105
|
+
].filter((s): s is AbortSignal => Boolean(s))
|
|
100
106
|
const init: RequestInit = {
|
|
101
107
|
...fetchOptions,
|
|
102
108
|
body,
|
|
@@ -105,10 +111,40 @@ export function fromHttp<
|
|
|
105
111
|
...fetchOptions?.headers,
|
|
106
112
|
},
|
|
107
113
|
method: fetchOptions?.method ?? 'POST',
|
|
108
|
-
signal:
|
|
114
|
+
signal: (() => {
|
|
115
|
+
if (signals.length < 2) return signals[0] ?? null
|
|
116
|
+
// Runtimes without `AbortSignal.any` (e.g. Node < 18.17) keep
|
|
117
|
+
// only the caller's signal, as before.
|
|
118
|
+
if (typeof AbortSignal.any !== 'function') return signals[0]!
|
|
119
|
+
return AbortSignal.any(signals)
|
|
120
|
+
})(),
|
|
109
121
|
}
|
|
110
122
|
const request = new Request(url, init)
|
|
111
|
-
|
|
123
|
+
const response = await fetchFn(request)
|
|
124
|
+
|
|
125
|
+
// Read the body within the timeout too, so a response that stalls
|
|
126
|
+
// after its headers cannot hang the request.
|
|
127
|
+
const data = await (async () => {
|
|
128
|
+
if (
|
|
129
|
+
response.headers
|
|
130
|
+
.get('Content-Type')
|
|
131
|
+
?.startsWith('application/json')
|
|
132
|
+
)
|
|
133
|
+
return response.json()
|
|
134
|
+
return response.text().then((data) => {
|
|
135
|
+
try {
|
|
136
|
+
return JSON.parse(data || '{}')
|
|
137
|
+
} catch (_err) {
|
|
138
|
+
if (response.ok)
|
|
139
|
+
throw new MalformedResponseError({
|
|
140
|
+
response: data,
|
|
141
|
+
})
|
|
142
|
+
return { error: data }
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
})()
|
|
146
|
+
|
|
147
|
+
return { data, response }
|
|
112
148
|
},
|
|
113
149
|
{
|
|
114
150
|
timeout,
|
|
@@ -116,24 +152,6 @@ export function fromHttp<
|
|
|
116
152
|
},
|
|
117
153
|
)
|
|
118
154
|
|
|
119
|
-
const data = await (async () => {
|
|
120
|
-
if (
|
|
121
|
-
response.headers.get('Content-Type')?.startsWith('application/json')
|
|
122
|
-
)
|
|
123
|
-
return response.json()
|
|
124
|
-
return response.text().then((data) => {
|
|
125
|
-
try {
|
|
126
|
-
return JSON.parse(data || '{}')
|
|
127
|
-
} catch (_err) {
|
|
128
|
-
if (response.ok)
|
|
129
|
-
throw new MalformedResponseError({
|
|
130
|
-
response: data,
|
|
131
|
-
})
|
|
132
|
-
return { error: data }
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
})()
|
|
136
|
-
|
|
137
155
|
if (!response.ok)
|
|
138
156
|
throw new HttpError({
|
|
139
157
|
body,
|
package/core/TypedData.ts
CHANGED
|
@@ -393,7 +393,7 @@ export function extractEip712DomainTypes(
|
|
|
393
393
|
): Parameter[] {
|
|
394
394
|
return [
|
|
395
395
|
typeof domain?.name === 'string' && { name: 'name', type: 'string' },
|
|
396
|
-
domain?.version && { name: 'version', type: 'string' },
|
|
396
|
+
typeof domain?.version === 'string' && { name: 'version', type: 'string' },
|
|
397
397
|
(typeof domain?.chainId === 'number' ||
|
|
398
398
|
typeof domain?.chainId === 'bigint') && {
|
|
399
399
|
name: 'chainId',
|
package/core/internal/abiItem.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type * as AbiItem from '../AbiItem.js'
|
|
|
4
4
|
import type * as AbiParameters from '../AbiParameters.js'
|
|
5
5
|
import * as Address from '../Address.js'
|
|
6
6
|
import * as Errors from '../Errors.js'
|
|
7
|
+
import { getArrayComponents } from './abiParameters.js'
|
|
7
8
|
import type {
|
|
8
9
|
Compute,
|
|
9
10
|
IsNever,
|
|
@@ -466,8 +467,9 @@ export function normalizeSignature(signature: string): string {
|
|
|
466
467
|
|
|
467
468
|
// Ignore spaces
|
|
468
469
|
if (char === ' ') {
|
|
469
|
-
//
|
|
470
|
-
|
|
470
|
+
// A space directly after a `(` or `,` separator is leading whitespace.
|
|
471
|
+
// Otherwise, it ends the type, so we want to deactivate.
|
|
472
|
+
if (!current.endsWith(',') && !current.endsWith('(')) {
|
|
471
473
|
current = ''
|
|
472
474
|
active = false
|
|
473
475
|
}
|
|
@@ -508,9 +510,12 @@ export function isArgOfType(
|
|
|
508
510
|
if (abiParameterType === 'tuple' && 'components' in abiParameter)
|
|
509
511
|
return Object.values(abiParameter.components).every(
|
|
510
512
|
(component, index) => {
|
|
511
|
-
return
|
|
512
|
-
|
|
513
|
-
|
|
513
|
+
return (
|
|
514
|
+
argType === 'object' &&
|
|
515
|
+
isArgOfType(
|
|
516
|
+
getComponentValue(arg, component, index),
|
|
517
|
+
component as AbiParameters.Parameter,
|
|
518
|
+
)
|
|
514
519
|
)
|
|
515
520
|
},
|
|
516
521
|
)
|
|
@@ -530,15 +535,16 @@ export function isArgOfType(
|
|
|
530
535
|
return argType === 'string' || arg instanceof Uint8Array
|
|
531
536
|
|
|
532
537
|
// fixed-length (`<type>[M]`) and dynamic (`<type>[]`) arrays
|
|
533
|
-
|
|
534
|
-
if (
|
|
538
|
+
const arrayComponents = getArrayComponents(abiParameterType)
|
|
539
|
+
if (arrayComponents) {
|
|
540
|
+
const [length, type] = arrayComponents
|
|
535
541
|
return (
|
|
536
542
|
Array.isArray(arg) &&
|
|
543
|
+
(length === null || arg.length === length) &&
|
|
537
544
|
arg.every((x: unknown) =>
|
|
538
545
|
isArgOfType(x, {
|
|
539
546
|
...abiParameter,
|
|
540
|
-
|
|
541
|
-
type: abiParameterType.replace(/(\[[0-9]{0,}\])$/, ''),
|
|
547
|
+
type,
|
|
542
548
|
} as AbiParameters.Parameter),
|
|
543
549
|
)
|
|
544
550
|
)
|
|
@@ -557,32 +563,65 @@ export function getAmbiguousTypes(
|
|
|
557
563
|
): AbiParameters.Parameter['type'][] | undefined {
|
|
558
564
|
for (const parameterIndex in sourceParameters) {
|
|
559
565
|
const sourceParameter = sourceParameters[parameterIndex]!
|
|
560
|
-
const targetParameter = targetParameters[parameterIndex]
|
|
566
|
+
const targetParameter = targetParameters[parameterIndex]
|
|
567
|
+
if (!targetParameter) continue
|
|
561
568
|
|
|
562
569
|
if (
|
|
563
570
|
sourceParameter.type === 'tuple' &&
|
|
564
571
|
targetParameter.type === 'tuple' &&
|
|
565
572
|
'components' in sourceParameter &&
|
|
566
573
|
'components' in targetParameter
|
|
567
|
-
)
|
|
568
|
-
|
|
574
|
+
) {
|
|
575
|
+
const value = args[parameterIndex]
|
|
576
|
+
const types = getAmbiguousTypes(
|
|
569
577
|
sourceParameter.components,
|
|
570
578
|
targetParameter.components,
|
|
571
|
-
(
|
|
579
|
+
sourceParameter.components.map((component, index) =>
|
|
580
|
+
getComponentValue(value, component, index),
|
|
581
|
+
),
|
|
572
582
|
)
|
|
583
|
+
if (types) return types
|
|
584
|
+
continue
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const sourceArray = getArrayComponents(sourceParameter.type)
|
|
588
|
+
const targetArray = getArrayComponents(targetParameter.type)
|
|
589
|
+
if (sourceArray && targetArray) {
|
|
590
|
+
// Every item matches both element types, so the first item (or `undefined` for an empty array) decides.
|
|
591
|
+
const types = getAmbiguousTypes(
|
|
592
|
+
[
|
|
593
|
+
{
|
|
594
|
+
...sourceParameter,
|
|
595
|
+
type: sourceArray[1],
|
|
596
|
+
} as AbiParameters.Parameter,
|
|
597
|
+
],
|
|
598
|
+
[
|
|
599
|
+
{
|
|
600
|
+
...targetParameter,
|
|
601
|
+
type: targetArray[1],
|
|
602
|
+
} as AbiParameters.Parameter,
|
|
603
|
+
],
|
|
604
|
+
[(args[parameterIndex] as readonly unknown[] | undefined)?.[0]],
|
|
605
|
+
)
|
|
606
|
+
if (types) return types
|
|
607
|
+
continue
|
|
608
|
+
}
|
|
573
609
|
|
|
574
610
|
const types = [sourceParameter.type, targetParameter.type]
|
|
575
611
|
|
|
612
|
+
const value = args[parameterIndex]
|
|
613
|
+
|
|
576
614
|
const ambiguous = (() => {
|
|
577
615
|
if (types.includes('address') && types.includes('bytes20')) return true
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
return
|
|
584
|
-
|
|
585
|
-
|
|
616
|
+
// An `undefined` value comes from an empty array, which matches both types.
|
|
617
|
+
if (
|
|
618
|
+
types.includes('address') &&
|
|
619
|
+
(types.includes('string') || types.includes('bytes'))
|
|
620
|
+
)
|
|
621
|
+
return (
|
|
622
|
+
value === undefined ||
|
|
623
|
+
Address.validate(value as Address.Address, { strict: false })
|
|
624
|
+
)
|
|
586
625
|
return false
|
|
587
626
|
})()
|
|
588
627
|
|
|
@@ -591,3 +630,13 @@ export function getAmbiguousTypes(
|
|
|
591
630
|
|
|
592
631
|
return
|
|
593
632
|
}
|
|
633
|
+
|
|
634
|
+
// Reads a tuple component's value by index from arrays and by name from objects, like `AbiParameters.encode`.
|
|
635
|
+
function getComponentValue(
|
|
636
|
+
arg: unknown,
|
|
637
|
+
component: AbiParameters.Parameter,
|
|
638
|
+
index: number,
|
|
639
|
+
): unknown {
|
|
640
|
+
if (Array.isArray(arg)) return arg[index]
|
|
641
|
+
return (arg as Record<string, unknown> | undefined)?.[component.name!]
|
|
642
|
+
}
|
package/package.json
CHANGED
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.14.
|
|
2
|
+
export const version = '0.14.58'
|