ox 1.8.12 → 1.8.14
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 +62 -0
- package/dist/core/AbiError.d.ts +2 -2
- package/dist/core/AbiError.d.ts.map +1 -1
- package/dist/core/AbiError.js +6 -2
- package/dist/core/AbiError.js.map +1 -1
- package/dist/core/AbiEvent.d.ts +71 -1
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +160 -19
- package/dist/core/AbiEvent.js.map +1 -1
- package/dist/core/AbiFunction.d.ts +1 -1
- package/dist/core/AbiFunction.d.ts.map +1 -1
- package/dist/core/AbiFunction.js +3 -5
- package/dist/core/AbiFunction.js.map +1 -1
- package/dist/core/AbiItem.d.ts.map +1 -1
- package/dist/core/AbiItem.js +18 -8
- package/dist/core/AbiItem.js.map +1 -1
- package/dist/core/Base32.d.ts +3 -3
- package/dist/core/Base32.d.ts.map +1 -1
- package/dist/core/Base32.js +5 -2
- package/dist/core/Base32.js.map +1 -1
- package/dist/core/Bytes.d.ts.map +1 -1
- package/dist/core/Bytes.js +4 -3
- package/dist/core/Bytes.js.map +1 -1
- package/dist/core/Caches.d.ts +1 -2
- package/dist/core/Caches.d.ts.map +1 -1
- package/dist/core/Caches.js +1 -4
- package/dist/core/Caches.js.map +1 -1
- package/dist/core/Cbor.d.ts.map +1 -1
- package/dist/core/Cbor.js +16 -2
- package/dist/core/Cbor.js.map +1 -1
- package/dist/core/CompactSize.d.ts +8 -1
- package/dist/core/CompactSize.d.ts.map +1 -1
- package/dist/core/CompactSize.js +9 -0
- package/dist/core/CompactSize.js.map +1 -1
- package/dist/core/Hex.d.ts.map +1 -1
- package/dist/core/Hex.js +9 -4
- package/dist/core/Hex.js.map +1 -1
- package/dist/core/Rlp.d.ts +9 -2
- package/dist/core/Rlp.d.ts.map +1 -1
- package/dist/core/Rlp.js +51 -8
- package/dist/core/Rlp.js.map +1 -1
- package/dist/core/RpcTransport.d.ts.map +1 -1
- package/dist/core/RpcTransport.js +11 -4
- package/dist/core/RpcTransport.js.map +1 -1
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +24 -9
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/TxEnvelope.d.ts.map +1 -1
- package/dist/core/TxEnvelope.js +5 -3
- package/dist/core/TxEnvelope.js.map +1 -1
- package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip1559.js +6 -2
- package/dist/core/TxEnvelopeEip1559.js.map +1 -1
- package/dist/core/TxEnvelopeEip4844.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip4844.js +4 -0
- package/dist/core/TxEnvelopeEip4844.js.map +1 -1
- package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip7702.js +4 -0
- package/dist/core/TxEnvelopeEip7702.js.map +1 -1
- package/dist/core/TypedData.d.ts +8 -1
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +55 -14
- package/dist/core/TypedData.js.map +1 -1
- package/dist/core/Value.d.ts.map +1 -1
- package/dist/core/Value.js +5 -3
- package/dist/core/Value.js.map +1 -1
- package/dist/core/internal/abiItem.d.ts +3 -1
- package/dist/core/internal/abiItem.d.ts.map +1 -1
- package/dist/core/internal/abiItem.js +46 -13
- package/dist/core/internal/abiItem.js.map +1 -1
- package/dist/core/internal/abiParameters.d.ts +2 -2
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +24 -7
- package/dist/core/internal/abiParameters.js.map +1 -1
- package/dist/core/internal/caches.d.ts +10 -0
- package/dist/core/internal/caches.d.ts.map +1 -0
- package/dist/core/internal/caches.js +10 -0
- package/dist/core/internal/caches.js.map +1 -0
- package/dist/core/internal/frameNonce.d.ts.map +1 -1
- package/dist/core/internal/frameNonce.js +2 -2
- package/dist/core/internal/frameNonce.js.map +1 -1
- package/dist/core/internal/rpcSchemas/eth.d.ts +3 -2
- package/dist/core/internal/rpcSchemas/eth.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.d.ts +15 -2
- package/dist/erc4337/UserOperation.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.js +8 -2
- package/dist/erc4337/UserOperation.js.map +1 -1
- package/dist/erc8021/Attribution.d.ts.map +1 -1
- package/dist/erc8021/Attribution.js +12 -3
- package/dist/erc8021/Attribution.js.map +1 -1
- package/dist/tempo/AccountOperation.d.ts +8 -0
- package/dist/tempo/AccountOperation.d.ts.map +1 -1
- package/dist/tempo/AccountOperation.js +26 -6
- package/dist/tempo/AccountOperation.js.map +1 -1
- package/dist/tempo/KeyAuthorization.d.ts +21 -6
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +7 -4
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +4 -4
- package/dist/tempo/Tick.d.ts.map +1 -1
- package/dist/tempo/Tick.js +4 -3
- package/dist/tempo/Tick.js.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.js +6 -2
- package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
- package/dist/zod/Address.d.ts.map +1 -1
- package/dist/zod/Address.js +2 -1
- package/dist/zod/Address.js.map +1 -1
- package/dist/zod/FrameRequest.d.ts.map +1 -1
- package/dist/zod/FrameRequest.js +2 -1
- package/dist/zod/FrameRequest.js.map +1 -1
- package/dist/zod/Hex.d.ts.map +1 -1
- package/dist/zod/Hex.js +2 -1
- package/dist/zod/Hex.js.map +1 -1
- package/dist/zod/Solidity.d.ts.map +1 -1
- package/dist/zod/Solidity.js +12 -7
- package/dist/zod/Solidity.js.map +1 -1
- package/dist/zod/TypedData.d.ts +12 -12
- package/package.json +5 -2
- package/src/core/AbiError.ts +33 -22
- package/src/core/AbiEvent.ts +177 -18
- package/src/core/AbiFunction.ts +10 -7
- package/src/core/AbiItem.ts +17 -8
- package/src/core/Base32.ts +8 -3
- package/src/core/Bytes.ts +4 -3
- package/src/core/Caches.ts +1 -6
- package/src/core/Cbor.ts +20 -2
- package/src/core/CompactSize.ts +13 -0
- package/src/core/Hex.ts +10 -5
- package/src/core/Rlp.ts +55 -5
- package/src/core/RpcTransport.ts +11 -4
- package/src/core/Siwe.ts +26 -11
- package/src/core/TxEnvelope.ts +5 -3
- package/src/core/TxEnvelopeEip1559.ts +8 -2
- package/src/core/TxEnvelopeEip4844.ts +6 -0
- package/src/core/TxEnvelopeEip7702.ts +6 -0
- package/src/core/TypedData.ts +62 -13
- package/src/core/Value.ts +6 -3
- package/src/core/_test/AbiError.test-d.ts +10 -0
- package/src/core/_test/AbiError.test.ts +73 -0
- package/src/core/_test/AbiEvent.fuzz.ts +260 -0
- package/src/core/_test/AbiEvent.snap-d.ts +9 -0
- package/src/core/_test/AbiEvent.test.ts +421 -0
- package/src/core/_test/AbiFunction.snap-d.ts +25 -0
- package/src/core/_test/AbiFunction.test.ts +101 -18
- package/src/core/_test/AbiItem.snap-d.ts +11 -0
- package/src/core/_test/AbiItem.test.ts +393 -5
- package/src/core/_test/AbiParameters.decode.test.ts +140 -1
- package/src/core/_test/Base32.test.ts +16 -0
- package/src/core/_test/Bytes.test.ts +15 -0
- package/src/core/_test/Caches.test.ts +10 -1
- package/src/core/_test/Cbor.test.ts +23 -0
- package/src/core/_test/CompactSize.test.ts +14 -0
- package/src/core/_test/Hex.test.ts +25 -0
- package/src/core/_test/Rlp.test.ts +51 -0
- package/src/core/_test/RpcSchema.test-d.ts +23 -1
- package/src/core/_test/RpcTransport.test.ts +47 -0
- package/src/core/_test/Siwe.test.ts +28 -0
- package/src/core/_test/TransactionEnvelopeEip1559.test.ts +24 -0
- package/src/core/_test/TransactionEnvelopeEip4844.test.ts +13 -0
- package/src/core/_test/TransactionEnvelopeEip7702.test.ts +13 -0
- package/src/core/_test/TypedData.test.ts +203 -1
- package/src/core/internal/abiItem.ts +58 -18
- package/src/core/internal/abiParameters.ts +26 -8
- package/src/core/internal/caches.ts +12 -0
- package/src/core/internal/frameNonce.ts +3 -4
- package/src/core/internal/rpcSchemas/eth.ts +2 -1
- package/src/erc4337/UserOperation.ts +30 -3
- package/src/erc4337/_test/UserOperation.test.ts +132 -35
- package/src/erc8021/Attribution.ts +9 -7
- package/src/erc8021/_test/Attribution.test.ts +37 -0
- package/src/tempo/AccountOperation.test.ts +116 -0
- package/src/tempo/AccountOperation.ts +38 -5
- package/src/tempo/AccountSimulation.test.ts +1 -1
- package/src/tempo/KeyAuthorization.test.ts +6 -4
- package/src/tempo/KeyAuthorization.ts +26 -8
- package/src/tempo/SignatureEnvelope.test.ts +12 -0
- package/src/tempo/SignatureEnvelope.ts +4 -4
- package/src/tempo/Tick.test.ts +10 -0
- package/src/tempo/Tick.ts +5 -3
- package/src/tempo/TxEnvelopeTempo.test.ts +26 -0
- package/src/tempo/TxEnvelopeTempo.ts +8 -2
- package/src/tempo/e2e.test.ts +73 -17
- package/src/version.ts +1 -1
- package/src/zod/Address.ts +3 -3
- package/src/zod/FrameRequest.ts +3 -4
- package/src/zod/Hex.ts +3 -1
- package/src/zod/Solidity.ts +15 -18
|
@@ -617,6 +617,28 @@ describe('decode', () => {
|
|
|
617
617
|
expect(decoded).toEqual({ '1': 2 })
|
|
618
618
|
})
|
|
619
619
|
|
|
620
|
+
test('map with `__proto__` key', () => {
|
|
621
|
+
// {"__proto__": {"polluted": true}}
|
|
622
|
+
const definite = Cbor.decode<Record<string, unknown>>(
|
|
623
|
+
'0xa1695f5f70726f746f5f5fa168706f6c6c75746564f5',
|
|
624
|
+
)
|
|
625
|
+
// {_ "__proto__": {"polluted": true}}
|
|
626
|
+
const indefinite = Cbor.decode<Record<string, unknown>>(
|
|
627
|
+
'0xbf695f5f70726f746f5f5fa168706f6c6c75746564f5ff',
|
|
628
|
+
)
|
|
629
|
+
for (const decoded of [definite, indefinite]) {
|
|
630
|
+
expect(Object.getPrototypeOf(decoded)).toBe(Object.prototype)
|
|
631
|
+
expect(Object.keys(decoded)).toEqual(['__proto__'])
|
|
632
|
+
expect(decoded.polluted).toBeUndefined()
|
|
633
|
+
expect(Object.getOwnPropertyDescriptor(decoded, '__proto__')?.value)
|
|
634
|
+
.toMatchInlineSnapshot(`
|
|
635
|
+
{
|
|
636
|
+
"polluted": true,
|
|
637
|
+
}
|
|
638
|
+
`)
|
|
639
|
+
}
|
|
640
|
+
})
|
|
641
|
+
|
|
620
642
|
test('invalid simple value throws', () => {
|
|
621
643
|
// Simple value < 32 (reserved)
|
|
622
644
|
const encoded = Hex.from([0xf8, 0x10]) // Simple value 16
|
|
@@ -688,6 +710,7 @@ describe('roundtrip', () => {
|
|
|
688
710
|
['object: simple', { a: 1, b: 2 }],
|
|
689
711
|
['object: nested', { a: 1, b: [2, 3] }],
|
|
690
712
|
['complex', { a: 'hello', b: [1, 2, { c: true }], d: null }],
|
|
713
|
+
['object: `__proto__` key', JSON.parse('{"__proto__":{"a":1},"b":2}')],
|
|
691
714
|
])('roundtrip: %s', (_, value) => {
|
|
692
715
|
const encoded = Cbor.encode(value)
|
|
693
716
|
const decoded = Cbor.decode(encoded)
|
|
@@ -79,6 +79,19 @@ describe('toBytes', () => {
|
|
|
79
79
|
`[CompactSize.NegativeValueError: CompactSize value must be non-negative, got -1.]`,
|
|
80
80
|
)
|
|
81
81
|
})
|
|
82
|
+
|
|
83
|
+
test('error: value larger than uint64', () => {
|
|
84
|
+
expect(() =>
|
|
85
|
+
CompactSize.toBytes(18446744073709551616n),
|
|
86
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
87
|
+
`[CompactSize.ValueTooLargeError: CompactSize value must be at most 18446744073709551615, got 18446744073709551616.]`,
|
|
88
|
+
)
|
|
89
|
+
expect(() =>
|
|
90
|
+
CompactSize.toBytes(18446744073709551616n + 4294967296n),
|
|
91
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
92
|
+
`[CompactSize.ValueTooLargeError: CompactSize value must be at most 18446744073709551615, got 18446744078004518912.]`,
|
|
93
|
+
)
|
|
94
|
+
})
|
|
82
95
|
})
|
|
83
96
|
|
|
84
97
|
describe('toHex', () => {
|
|
@@ -168,6 +181,7 @@ test('exports', () => {
|
|
|
168
181
|
"fromBytes",
|
|
169
182
|
"fromHex",
|
|
170
183
|
"NegativeValueError",
|
|
184
|
+
"ValueTooLargeError",
|
|
171
185
|
"InsufficientBytesError",
|
|
172
186
|
"InvalidValueError",
|
|
173
187
|
"NonMinimalEncodingError",
|
|
@@ -221,6 +221,12 @@ describe('fromNumber', () => {
|
|
|
221
221
|
).toThrowErrorMatchingInlineSnapshot(
|
|
222
222
|
'[Hex.IntegerOutOfRangeError: Number `-32769` is not in safe 16-bit signed integer range (`-32768` to `32767`)]',
|
|
223
223
|
)
|
|
224
|
+
expect(() =>
|
|
225
|
+
// @ts-expect-error `signed` requires `size`.
|
|
226
|
+
Hex.fromNumber(-1, { signed: true }),
|
|
227
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
228
|
+
'[Hex.IntegerOutOfRangeError: Number `-1` is not in safe signed integer range (`0` to `9007199254740991`)]',
|
|
229
|
+
)
|
|
224
230
|
})
|
|
225
231
|
})
|
|
226
232
|
|
|
@@ -404,6 +410,10 @@ describe('toBigInt', () => {
|
|
|
404
410
|
expect(Hex.toBigInt('0x7fff', { signed: true })).toBe(32767n)
|
|
405
411
|
expect(Hex.toBigInt('0x8000', { signed: true })).toBe(-32768n)
|
|
406
412
|
|
|
413
|
+
expect(Hex.toBigInt('0xf', { signed: true })).toBe(15n)
|
|
414
|
+
expect(Hex.toBigInt('0xfff', { signed: true })).toBe(4095n)
|
|
415
|
+
expect(Hex.toBigInt(Hex.fromNumber(420), { signed: true })).toBe(420n)
|
|
416
|
+
|
|
407
417
|
expect(
|
|
408
418
|
Hex.toBigInt(
|
|
409
419
|
'0x000000000000000000000000000000000000000000000000aade1ed08b0b325c',
|
|
@@ -590,6 +600,21 @@ describe('toBytes', () => {
|
|
|
590
600
|
`)
|
|
591
601
|
})
|
|
592
602
|
|
|
603
|
+
test('behavior: odd length with size', () => {
|
|
604
|
+
expect(Hex.toBytes('0x1', { size: 2 })).toMatchInlineSnapshot(`
|
|
605
|
+
Uint8Array [
|
|
606
|
+
1,
|
|
607
|
+
0,
|
|
608
|
+
]
|
|
609
|
+
`)
|
|
610
|
+
expect(Hex.toBytes('0xabc', { size: 2 })).toMatchInlineSnapshot(`
|
|
611
|
+
Uint8Array [
|
|
612
|
+
10,
|
|
613
|
+
188,
|
|
614
|
+
]
|
|
615
|
+
`)
|
|
616
|
+
})
|
|
617
|
+
|
|
593
618
|
test('error: size overflow', () => {
|
|
594
619
|
expect(() =>
|
|
595
620
|
Hex.toString(Hex.fromBytes(Bytes.fromArray([69, 420]), { size: 64 }), {
|
|
@@ -17,6 +17,7 @@ test('exports', () => {
|
|
|
17
17
|
"DepthLimitExceededError",
|
|
18
18
|
"ListBoundaryExceededError",
|
|
19
19
|
"TrailingBytesError",
|
|
20
|
+
"NonCanonicalError",
|
|
20
21
|
]
|
|
21
22
|
`)
|
|
22
23
|
})
|
|
@@ -547,3 +548,53 @@ describe('list boundary', () => {
|
|
|
547
548
|
)
|
|
548
549
|
})
|
|
549
550
|
})
|
|
551
|
+
|
|
552
|
+
describe('non-canonical encoding', () => {
|
|
553
|
+
// RLP is a bijection: every value has exactly one valid encoding (Yellow
|
|
554
|
+
// Paper, Appendix B). A decoder that accepts alternate encodings of the
|
|
555
|
+
// same value breaks that bijection and enables hash/identity malleability.
|
|
556
|
+
test('single byte < 0x80 wrapped in a length-1 prefix', () => {
|
|
557
|
+
expect(() => Rlp.toHex('0x8100')).toThrowErrorMatchingInlineSnapshot(
|
|
558
|
+
`[Rlp.NonCanonicalError: RLP payload is not canonically encoded: single byte \`0x00\` is wrapped in an explicit length prefix instead of being encoded as itself.]`,
|
|
559
|
+
)
|
|
560
|
+
expect(() => Rlp.toHex('0x817f')).toThrowErrorMatchingInlineSnapshot(
|
|
561
|
+
`[Rlp.NonCanonicalError: RLP payload is not canonically encoded: single byte \`0x7f\` is wrapped in an explicit length prefix instead of being encoded as itself.]`,
|
|
562
|
+
)
|
|
563
|
+
})
|
|
564
|
+
|
|
565
|
+
test('single byte >= 0x80 correctly requires a length-1 prefix', () => {
|
|
566
|
+
expect(Rlp.toHex('0x8180')).toMatchInlineSnapshot(`"0x80"`)
|
|
567
|
+
expect(Rlp.toHex('0x8185')).toMatchInlineSnapshot(`"0x85"`)
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
test('long-form length that fits the short form', () => {
|
|
571
|
+
// `0xb8` = long-form 1-byte-length string prefix; `0x00` declares length 0,
|
|
572
|
+
// which must instead be encoded directly as the short-form `0x80`.
|
|
573
|
+
expect(() => Rlp.toHex('0xb800')).toThrowErrorMatchingInlineSnapshot(
|
|
574
|
+
`[Rlp.NonCanonicalError: RLP payload is not canonically encoded: length \`0\` fits in the short form and must not use a one-byte length prefix.]`,
|
|
575
|
+
)
|
|
576
|
+
// declares length 1 (`0x41`), which fits the short form (`0x41` directly).
|
|
577
|
+
expect(() => Rlp.toHex('0xb80141')).toThrowErrorMatchingInlineSnapshot(
|
|
578
|
+
`[Rlp.NonCanonicalError: RLP payload is not canonically encoded: length \`1\` fits in the short form and must not use a one-byte length prefix.]`,
|
|
579
|
+
)
|
|
580
|
+
// list variant: `0xf8` = long-form 1-byte-length list prefix, length 2.
|
|
581
|
+
expect(() => Rlp.toHex('0xf8020102')).toThrowErrorMatchingInlineSnapshot(
|
|
582
|
+
`[Rlp.NonCanonicalError: RLP payload is not canonically encoded: length \`2\` fits in the short form and must not use a one-byte length prefix.]`,
|
|
583
|
+
)
|
|
584
|
+
})
|
|
585
|
+
|
|
586
|
+
test('long-form length with a leading zero length-byte', () => {
|
|
587
|
+
// `0xb9` = long-form 2-byte-length string prefix; `0x0001` (leading zero)
|
|
588
|
+
// declares length 1, which fits in a single length-byte.
|
|
589
|
+
expect(() => Rlp.toHex('0xb9000141')).toThrowErrorMatchingInlineSnapshot(
|
|
590
|
+
`[Rlp.NonCanonicalError: RLP payload is not canonically encoded: length \`1\` fits in fewer length-bytes and must not use a two-byte length prefix.]`,
|
|
591
|
+
)
|
|
592
|
+
})
|
|
593
|
+
|
|
594
|
+
test('long-form lengths at exact byte-count boundaries still decode', () => {
|
|
595
|
+
const bytes56 = `0x${'ab'.repeat(56)}` as const
|
|
596
|
+
expect(Rlp.toHex(Rlp.fromHex(bytes56))).toEqual(bytes56)
|
|
597
|
+
const bytes256 = `0x${'cd'.repeat(256)}` as const
|
|
598
|
+
expect(Rlp.toHex(Rlp.fromHex(bytes256))).toEqual(bytes256)
|
|
599
|
+
})
|
|
600
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RpcSchema } from 'ox'
|
|
1
|
+
import { type Frame, RpcSchema } from 'ox'
|
|
2
2
|
import { z } from 'ox/zod'
|
|
3
3
|
import { describe, expectTypeOf, test } from 'vp/test'
|
|
4
4
|
|
|
@@ -246,6 +246,28 @@ test('frame fill responses do not require raw bytes or lookup metadata', () => {
|
|
|
246
246
|
expectTypeOf(filled).toExtend<Filled>()
|
|
247
247
|
})
|
|
248
248
|
|
|
249
|
+
test('fill responses expose fields not shared by every envelope as optional', () => {
|
|
250
|
+
type Tx = Extract<
|
|
251
|
+
RpcSchema.Eth,
|
|
252
|
+
{ Request: { method: 'eth_fillTransaction' } }
|
|
253
|
+
>['ReturnType']['tx']
|
|
254
|
+
expectTypeOf<Tx['from']>().toEqualTypeOf<`0x${string}`>()
|
|
255
|
+
expectTypeOf<Tx['gas']>().toEqualTypeOf<`0x${string}` | undefined>()
|
|
256
|
+
expectTypeOf<Tx['frames']>().toEqualTypeOf<readonly Frame.Rpc[] | undefined>()
|
|
257
|
+
|
|
258
|
+
type Eip1559 = Extract<Tx, { type: '0x2' }>
|
|
259
|
+
expectTypeOf<Eip1559['gas']>().toEqualTypeOf<`0x${string}` | undefined>()
|
|
260
|
+
expectTypeOf<Eip1559['gasPrice']>().toEqualTypeOf<undefined>()
|
|
261
|
+
expectTypeOf<Eip1559['maxFeePerGas']>().toEqualTypeOf<
|
|
262
|
+
`0x${string}` | undefined
|
|
263
|
+
>()
|
|
264
|
+
expectTypeOf<Eip1559['frames']>().toEqualTypeOf<undefined>()
|
|
265
|
+
|
|
266
|
+
type Eip8141 = Extract<Tx, { type: '0x6' }>
|
|
267
|
+
expectTypeOf<Eip8141['frames']>().toEqualTypeOf<readonly Frame.Rpc[]>()
|
|
268
|
+
expectTypeOf<Eip8141['gas']>().toEqualTypeOf<undefined>()
|
|
269
|
+
})
|
|
270
|
+
|
|
249
271
|
test('frame simulation results expose payer and frame results', () => {
|
|
250
272
|
type Result = Extract<
|
|
251
273
|
RpcSchema.Eth,
|
|
@@ -89,6 +89,53 @@ describe('fromHttp', () => {
|
|
|
89
89
|
expect(blockNumber).toMatchInlineSnapshot(`"eth_accounts"`)
|
|
90
90
|
})
|
|
91
91
|
|
|
92
|
+
test('options: fetchOptions (headers)', async () => {
|
|
93
|
+
const server = await createHttpServer((req, res) => {
|
|
94
|
+
res.end(
|
|
95
|
+
JSON.stringify({
|
|
96
|
+
id: 0,
|
|
97
|
+
jsonrpc: '2.0',
|
|
98
|
+
result: [req.headers['content-type'], req.headers['x-custom-header']],
|
|
99
|
+
}),
|
|
100
|
+
)
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const results = []
|
|
104
|
+
for (const headers of [
|
|
105
|
+
{ 'Content-Type': 'application/json-rpc', 'x-custom-header': 'wagmi' },
|
|
106
|
+
new Headers({
|
|
107
|
+
'Content-Type': 'application/json-rpc',
|
|
108
|
+
'x-custom-header': 'wagmi',
|
|
109
|
+
}),
|
|
110
|
+
[
|
|
111
|
+
['Content-Type', 'application/json-rpc'],
|
|
112
|
+
['x-custom-header', 'wagmi'],
|
|
113
|
+
] as [string, string][],
|
|
114
|
+
]) {
|
|
115
|
+
const transport = RpcTransport.fromHttp(server.url, {
|
|
116
|
+
fetchOptions: { headers },
|
|
117
|
+
})
|
|
118
|
+
results.push(await transport.request({ method: 'eth_accounts' }))
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
expect(results).toMatchInlineSnapshot(`
|
|
122
|
+
[
|
|
123
|
+
[
|
|
124
|
+
"application/json-rpc",
|
|
125
|
+
"wagmi",
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
"application/json-rpc",
|
|
129
|
+
"wagmi",
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
"application/json-rpc",
|
|
133
|
+
"wagmi",
|
|
134
|
+
],
|
|
135
|
+
]
|
|
136
|
+
`)
|
|
137
|
+
})
|
|
138
|
+
|
|
92
139
|
test('options: timeout', async () => {
|
|
93
140
|
const server = await createHttpServer(async (_, res) => {
|
|
94
141
|
await setTimeout(100)
|
|
@@ -1080,6 +1080,34 @@ describe('validateMessage', () => {
|
|
|
1080
1080
|
).toBeFalsy()
|
|
1081
1081
|
})
|
|
1082
1082
|
|
|
1083
|
+
test('behavior: nonce shorter than 8 characters', () => {
|
|
1084
|
+
const parsed =
|
|
1085
|
+
Siwe.parseMessage(`example.com wants you to sign in with your Ethereum account:
|
|
1086
|
+
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
|
|
1087
|
+
|
|
1088
|
+
URI: https://example.com/path
|
|
1089
|
+
Version: 1
|
|
1090
|
+
Chain ID: 1
|
|
1091
|
+
Nonce: foobar
|
|
1092
|
+
Issued At: 2023-02-01T00:00:00.000Z`)
|
|
1093
|
+
|
|
1094
|
+
expect(Siwe.validateMessage({ message: parsed })).toBeFalsy()
|
|
1095
|
+
})
|
|
1096
|
+
|
|
1097
|
+
test('behavior: version other than 1', () => {
|
|
1098
|
+
const parsed =
|
|
1099
|
+
Siwe.parseMessage(`example.com wants you to sign in with your Ethereum account:
|
|
1100
|
+
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
|
|
1101
|
+
|
|
1102
|
+
URI: https://example.com/path
|
|
1103
|
+
Version: 2
|
|
1104
|
+
Chain ID: 1
|
|
1105
|
+
Nonce: foobarbaz
|
|
1106
|
+
Issued At: 2023-02-01T00:00:00.000Z`)
|
|
1107
|
+
|
|
1108
|
+
expect(Siwe.validateMessage({ message: parsed })).toBeFalsy()
|
|
1109
|
+
})
|
|
1110
|
+
|
|
1083
1111
|
test('behavior: scheme mismatch', () => {
|
|
1084
1112
|
expect(
|
|
1085
1113
|
Siwe.validateMessage({
|
|
@@ -27,6 +27,18 @@ describe('assert', () => {
|
|
|
27
27
|
)
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
+
test('tip higher than zero fee cap', () => {
|
|
31
|
+
expect(() =>
|
|
32
|
+
TxEnvelopeEip1559.assert({
|
|
33
|
+
maxFeePerGas: 0n,
|
|
34
|
+
maxPriorityFeePerGas: 1n,
|
|
35
|
+
chainId: 1,
|
|
36
|
+
}),
|
|
37
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
38
|
+
'[TransactionEnvelope.TipAboveFeeCapError: The provided tip (`maxPriorityFeePerGas` = 0.000000001 gwei) cannot be higher than the fee cap (`maxFeePerGas` = 0 gwei).]',
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
|
|
30
42
|
test('invalid chainId', () => {
|
|
31
43
|
expect(() =>
|
|
32
44
|
TxEnvelopeEip1559.assert({ chainId: 0 }),
|
|
@@ -225,6 +237,18 @@ describe('deserialize', () => {
|
|
|
225
237
|
})
|
|
226
238
|
|
|
227
239
|
describe('errors', () => {
|
|
240
|
+
test('tip above empty fee cap', () => {
|
|
241
|
+
const serialized = TxEnvelopeEip1559.serialize({
|
|
242
|
+
chainId: 1,
|
|
243
|
+
maxPriorityFeePerGas: 1n,
|
|
244
|
+
})
|
|
245
|
+
expect(() =>
|
|
246
|
+
TxEnvelopeEip1559.deserialize(serialized),
|
|
247
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
248
|
+
`[TransactionEnvelope.TipAboveFeeCapError: The provided tip (\`maxPriorityFeePerGas\` = 0.000000001 gwei) cannot be higher than the fee cap (\`maxFeePerGas\` = 0 gwei).]`,
|
|
249
|
+
)
|
|
250
|
+
})
|
|
251
|
+
|
|
228
252
|
test('invalid access list (invalid address)', () => {
|
|
229
253
|
expect(() =>
|
|
230
254
|
TxEnvelopeEip1559.deserialize(
|
|
@@ -203,6 +203,19 @@ describe('deserialize', () => {
|
|
|
203
203
|
})
|
|
204
204
|
|
|
205
205
|
describe('errors', () => {
|
|
206
|
+
test('tip above empty fee cap', () => {
|
|
207
|
+
const serialized = TxEnvelopeEip4844.serialize({
|
|
208
|
+
blobVersionedHashes,
|
|
209
|
+
chainId: 1,
|
|
210
|
+
maxPriorityFeePerGas: 1n,
|
|
211
|
+
})
|
|
212
|
+
expect(() =>
|
|
213
|
+
TxEnvelopeEip4844.deserialize(serialized),
|
|
214
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
215
|
+
`[TransactionEnvelope.TipAboveFeeCapError: The provided tip (\`maxPriorityFeePerGas\` = 0.000000001 gwei) cannot be higher than the fee cap (\`maxFeePerGas\` = 0 gwei).]`,
|
|
216
|
+
)
|
|
217
|
+
})
|
|
218
|
+
|
|
206
219
|
test('invalid access list (invalid address)', () => {
|
|
207
220
|
expect(() =>
|
|
208
221
|
TxEnvelopeEip4844.deserialize(
|
|
@@ -311,6 +311,19 @@ describe('deserialize', () => {
|
|
|
311
311
|
})
|
|
312
312
|
|
|
313
313
|
describe('errors', () => {
|
|
314
|
+
test('tip above empty fee cap', () => {
|
|
315
|
+
const serialized = TxEnvelopeEip7702.serialize({
|
|
316
|
+
authorizationList: [],
|
|
317
|
+
chainId: 1,
|
|
318
|
+
maxPriorityFeePerGas: 1n,
|
|
319
|
+
})
|
|
320
|
+
expect(() =>
|
|
321
|
+
TxEnvelopeEip7702.deserialize(serialized),
|
|
322
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
323
|
+
`[TransactionEnvelope.TipAboveFeeCapError: The provided tip (\`maxPriorityFeePerGas\` = 0.000000001 gwei) cannot be higher than the fee cap (\`maxFeePerGas\` = 0 gwei).]`,
|
|
324
|
+
)
|
|
325
|
+
})
|
|
326
|
+
|
|
314
327
|
test('invalid access list (invalid address)', () => {
|
|
315
328
|
expect(() =>
|
|
316
329
|
TxEnvelopeEip7702.deserialize(
|
|
@@ -425,7 +425,7 @@ describe('assert', () => {
|
|
|
425
425
|
).toThrowErrorMatchingInlineSnapshot(`
|
|
426
426
|
[TypedData.InvalidStructTypeError: Struct type "address" is invalid.
|
|
427
427
|
|
|
428
|
-
Struct type must not be a Solidity type.]
|
|
428
|
+
Struct type must contain only letters, digits, "_", "$" and ":", and must not be a Solidity type.]
|
|
429
429
|
`)
|
|
430
430
|
})
|
|
431
431
|
|
|
@@ -498,6 +498,161 @@ describe('assert', () => {
|
|
|
498
498
|
[Hex.IntegerOutOfRangeError: Number \`256n\` is not in safe 8-bit unsigned integer range (\`0n\` to \`255n\`)]
|
|
499
499
|
`)
|
|
500
500
|
})
|
|
501
|
+
test.each([
|
|
502
|
+
'1Order',
|
|
503
|
+
'_Order',
|
|
504
|
+
'bytesInfo',
|
|
505
|
+
'Foo$Bar',
|
|
506
|
+
'intent',
|
|
507
|
+
'interval',
|
|
508
|
+
'uintPair',
|
|
509
|
+
])('struct type: %s', (type) => {
|
|
510
|
+
TypedData.assert({
|
|
511
|
+
types: {
|
|
512
|
+
Order: [{ name: 'inner', type }],
|
|
513
|
+
[type]: [{ name: 'amount', type: 'uint256' }],
|
|
514
|
+
},
|
|
515
|
+
primaryType: 'Order',
|
|
516
|
+
message: { inner: { amount: 1n } },
|
|
517
|
+
} as any)
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
test.each([
|
|
521
|
+
'address',
|
|
522
|
+
'bool',
|
|
523
|
+
'bytes',
|
|
524
|
+
'bytes32',
|
|
525
|
+
'bytes32[]',
|
|
526
|
+
'bytes33',
|
|
527
|
+
'Foo.Bar',
|
|
528
|
+
'int',
|
|
529
|
+
'int8',
|
|
530
|
+
'int8[2]',
|
|
531
|
+
'string',
|
|
532
|
+
'uint',
|
|
533
|
+
'uint256',
|
|
534
|
+
'uint256 ',
|
|
535
|
+
'uint256[]',
|
|
536
|
+
'uint7',
|
|
537
|
+
])('invalid struct type: %s', (type) => {
|
|
538
|
+
expect(() =>
|
|
539
|
+
TypedData.assert({
|
|
540
|
+
types: {
|
|
541
|
+
Order: [{ name: 'inner', type }],
|
|
542
|
+
[type]: [{ name: 'amount', type: 'uint256' }],
|
|
543
|
+
},
|
|
544
|
+
primaryType: 'Order',
|
|
545
|
+
message: { inner: { amount: 1n } },
|
|
546
|
+
} as any),
|
|
547
|
+
).toThrowError(`Struct type "${type}" is invalid.`)
|
|
548
|
+
})
|
|
549
|
+
|
|
550
|
+
test('invalid struct type: array element', () => {
|
|
551
|
+
expect(() =>
|
|
552
|
+
TypedData.assert({
|
|
553
|
+
types: {
|
|
554
|
+
Message: [{ name: 'contents', type: 'bytes32[]' }],
|
|
555
|
+
bytes32: [],
|
|
556
|
+
},
|
|
557
|
+
primaryType: 'Message',
|
|
558
|
+
message: { contents: [Hex.padLeft('0x11', 32)] },
|
|
559
|
+
} as any),
|
|
560
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
561
|
+
[TypedData.InvalidStructTypeError: Struct type "bytes32" is invalid.
|
|
562
|
+
|
|
563
|
+
Struct type must contain only letters, digits, "_", "$" and ":", and must not be a Solidity type.]
|
|
564
|
+
`)
|
|
565
|
+
})
|
|
566
|
+
|
|
567
|
+
test.each([
|
|
568
|
+
'bytes0',
|
|
569
|
+
'bytes33',
|
|
570
|
+
'int0',
|
|
571
|
+
'int7',
|
|
572
|
+
'uint08',
|
|
573
|
+
'uint7',
|
|
574
|
+
'uint7[]',
|
|
575
|
+
'uint264',
|
|
576
|
+
'uint264[2]',
|
|
577
|
+
])('invalid type: %s', (type) => {
|
|
578
|
+
expect(() =>
|
|
579
|
+
TypedData.assert({
|
|
580
|
+
types: {
|
|
581
|
+
Message: [{ name: 'amount', type }],
|
|
582
|
+
},
|
|
583
|
+
primaryType: 'Message',
|
|
584
|
+
message: {
|
|
585
|
+
amount: type.includes('[')
|
|
586
|
+
? [1n, 2n]
|
|
587
|
+
: type.startsWith('bytes')
|
|
588
|
+
? '0x'
|
|
589
|
+
: 1n,
|
|
590
|
+
},
|
|
591
|
+
} as any),
|
|
592
|
+
).toThrowError(`Type "${type}" is not a valid EIP-712 type.`)
|
|
593
|
+
})
|
|
594
|
+
|
|
595
|
+
test('invalid type: alias', () => {
|
|
596
|
+
expect(() =>
|
|
597
|
+
TypedData.assert({
|
|
598
|
+
types: {
|
|
599
|
+
Message: [{ name: 'amount', type: 'uint' }],
|
|
600
|
+
},
|
|
601
|
+
primaryType: 'Message',
|
|
602
|
+
message: { amount: 1n },
|
|
603
|
+
} as any),
|
|
604
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
605
|
+
[TypedData.InvalidTypeError: Type "uint" is not a valid EIP-712 type.
|
|
606
|
+
|
|
607
|
+
Use "uint256" instead.]
|
|
608
|
+
`)
|
|
609
|
+
})
|
|
610
|
+
|
|
611
|
+
test('invalid type: undefined struct', () => {
|
|
612
|
+
expect(() =>
|
|
613
|
+
TypedData.assert({
|
|
614
|
+
types: {
|
|
615
|
+
Mail: [{ name: 'from', type: 'Person' }],
|
|
616
|
+
},
|
|
617
|
+
primaryType: 'Mail',
|
|
618
|
+
message: { from: { name: 'Cow' } },
|
|
619
|
+
} as any),
|
|
620
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
621
|
+
`[TypedData.InvalidTypeError: Type "Person" is not a valid EIP-712 type.]`,
|
|
622
|
+
)
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
test.each(['bytes0', 'Foo', 'uint', 'uint7', 'uint7[]'])(
|
|
626
|
+
'invalid type in array element struct: %s',
|
|
627
|
+
(type) => {
|
|
628
|
+
for (const to of ['Person[]', 'Person[][]', 'Person[2]'])
|
|
629
|
+
expect(() =>
|
|
630
|
+
TypedData.assert({
|
|
631
|
+
types: {
|
|
632
|
+
Mail: [{ name: 'to', type: to }],
|
|
633
|
+
Person: [{ name: 'x', type }],
|
|
634
|
+
},
|
|
635
|
+
primaryType: 'Mail',
|
|
636
|
+
message: { to: [] },
|
|
637
|
+
} as any),
|
|
638
|
+
).toThrowError(`Type "${type}" is not a valid EIP-712 type.`)
|
|
639
|
+
},
|
|
640
|
+
)
|
|
641
|
+
|
|
642
|
+
test.each(['__proto__', 'constructor', 'hasOwnProperty', 'toString'])(
|
|
643
|
+
'invalid type: %s',
|
|
644
|
+
(type) => {
|
|
645
|
+
expect(() =>
|
|
646
|
+
TypedData.assert({
|
|
647
|
+
types: {
|
|
648
|
+
Message: [{ name: 'value', type }],
|
|
649
|
+
},
|
|
650
|
+
primaryType: 'Message',
|
|
651
|
+
message: { value: {} },
|
|
652
|
+
} as any),
|
|
653
|
+
).toThrowError(`Type "${type}" is not a valid EIP-712 type.`)
|
|
654
|
+
},
|
|
655
|
+
)
|
|
501
656
|
})
|
|
502
657
|
|
|
503
658
|
describe('domainSeparator', () => {
|
|
@@ -1054,6 +1209,52 @@ describe('getSignPayload', () => {
|
|
|
1054
1209
|
`"0xd2669f23b7849020ad41bcbff5b51372793f91320e0f901641945568ed7322be"`,
|
|
1055
1210
|
)
|
|
1056
1211
|
})
|
|
1212
|
+
test('struct type: prefixed by a Solidity type', () => {
|
|
1213
|
+
expect(
|
|
1214
|
+
TypedData.getSignPayload({
|
|
1215
|
+
domain: { name: 'Domain' },
|
|
1216
|
+
types: {
|
|
1217
|
+
Message: [{ name: 'intent', type: 'intent' }],
|
|
1218
|
+
intent: [{ name: 'amount', type: 'uint256' }],
|
|
1219
|
+
},
|
|
1220
|
+
primaryType: 'Message',
|
|
1221
|
+
message: { intent: { amount: 1n } },
|
|
1222
|
+
}),
|
|
1223
|
+
).toMatchInlineSnapshot(
|
|
1224
|
+
`"0xcbeb995e95e87817f47e51736d0e5825644055cbcad196c2b26449ad78fd87ee"`,
|
|
1225
|
+
)
|
|
1226
|
+
})
|
|
1227
|
+
|
|
1228
|
+
test('struct type: with $', () => {
|
|
1229
|
+
expect(
|
|
1230
|
+
TypedData.getSignPayload({
|
|
1231
|
+
domain: { name: 'Domain' },
|
|
1232
|
+
types: {
|
|
1233
|
+
Message: [{ name: 'order', type: 'Order$1' }],
|
|
1234
|
+
Order$1: [{ name: 'amount', type: 'uint256' }],
|
|
1235
|
+
},
|
|
1236
|
+
primaryType: 'Message',
|
|
1237
|
+
message: { order: { amount: 1n } },
|
|
1238
|
+
}),
|
|
1239
|
+
).toMatchInlineSnapshot(
|
|
1240
|
+
`"0x97a137d1f96a18c6a214fd8e7b991ed7309ff25f223b68aa63a4670f9838a94a"`,
|
|
1241
|
+
)
|
|
1242
|
+
})
|
|
1243
|
+
|
|
1244
|
+
test('struct type: with colon', () => {
|
|
1245
|
+
expect(
|
|
1246
|
+
TypedData.getSignPayload({
|
|
1247
|
+
domain: { name: 'Domain' },
|
|
1248
|
+
types: {
|
|
1249
|
+
'Order:1': [{ name: 'amount', type: 'uint256' }],
|
|
1250
|
+
},
|
|
1251
|
+
primaryType: 'Order:1',
|
|
1252
|
+
message: { amount: 1n },
|
|
1253
|
+
}),
|
|
1254
|
+
).toMatchInlineSnapshot(
|
|
1255
|
+
`"0x3465390e0ea754dae581e653862bc7f8b71258ad85150e27ad18d87dd63fe6ab"`,
|
|
1256
|
+
)
|
|
1257
|
+
})
|
|
1057
1258
|
})
|
|
1058
1259
|
|
|
1059
1260
|
describe('hashDomain', () => {
|
|
@@ -1613,6 +1814,7 @@ test('exports', () => {
|
|
|
1613
1814
|
"InvalidDomainError",
|
|
1614
1815
|
"InvalidPrimaryTypeError",
|
|
1615
1816
|
"InvalidStructTypeError",
|
|
1817
|
+
"InvalidTypeError",
|
|
1616
1818
|
"InvalidArrayError",
|
|
1617
1819
|
"InvalidArrayLengthError",
|
|
1618
1820
|
"encodeData",
|