ox 1.7.5 → 1.8.1
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/dist/core/Frame.d.ts +290 -0
- package/dist/core/Frame.d.ts.map +1 -0
- package/dist/core/Frame.js +306 -0
- package/dist/core/Frame.js.map +1 -0
- package/dist/core/FrameReceipt.d.ts +92 -0
- package/dist/core/FrameReceipt.d.ts.map +1 -0
- package/dist/core/FrameReceipt.js +72 -0
- package/dist/core/FrameReceipt.js.map +1 -0
- package/dist/core/FrameSignature.d.ts +357 -0
- package/dist/core/FrameSignature.d.ts.map +1 -0
- package/dist/core/FrameSignature.js +411 -0
- package/dist/core/FrameSignature.js.map +1 -0
- package/dist/core/Transaction.d.ts +29 -4
- package/dist/core/Transaction.d.ts.map +1 -1
- package/dist/core/Transaction.js +25 -4
- package/dist/core/Transaction.js.map +1 -1
- package/dist/core/TransactionReceipt.d.ts +13 -4
- package/dist/core/TransactionReceipt.d.ts.map +1 -1
- package/dist/core/TransactionReceipt.js +14 -0
- package/dist/core/TransactionReceipt.js.map +1 -1
- package/dist/core/TransactionRequest.d.ts +15 -7
- package/dist/core/TransactionRequest.d.ts.map +1 -1
- package/dist/core/TransactionRequest.js +47 -1
- package/dist/core/TransactionRequest.js.map +1 -1
- package/dist/core/TxEnvelope.d.ts +35 -21
- package/dist/core/TxEnvelope.d.ts.map +1 -1
- package/dist/core/TxEnvelope.js +46 -6
- package/dist/core/TxEnvelope.js.map +1 -1
- package/dist/core/TxEnvelopeEip8141.d.ts +341 -0
- package/dist/core/TxEnvelopeEip8141.d.ts.map +1 -0
- package/dist/core/TxEnvelopeEip8141.js +484 -0
- package/dist/core/TxEnvelopeEip8141.js.map +1 -0
- package/dist/core/internal/curves.d.ts +2 -0
- package/dist/core/internal/curves.d.ts.map +1 -1
- package/dist/core/internal/curves.js +2 -0
- package/dist/core/internal/curves.js.map +1 -1
- package/dist/index.d.ts +73 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -1
- package/dist/tempo/Transaction.d.ts +2 -0
- package/dist/tempo/Transaction.d.ts.map +1 -1
- package/dist/tempo/TransactionReceipt.d.ts +2 -0
- package/dist/tempo/TransactionReceipt.d.ts.map +1 -1
- package/dist/zod/Block.d.ts +123 -0
- package/dist/zod/Block.d.ts.map +1 -1
- package/dist/zod/Frame.d.ts +73 -0
- package/dist/zod/Frame.d.ts.map +1 -0
- package/dist/zod/Frame.js +74 -0
- package/dist/zod/Frame.js.map +1 -0
- package/dist/zod/FrameReceipt.d.ts +50 -0
- package/dist/zod/FrameReceipt.d.ts.map +1 -0
- package/dist/zod/FrameReceipt.js +37 -0
- package/dist/zod/FrameReceipt.js.map +1 -0
- package/dist/zod/FrameSignature.d.ts +63 -0
- package/dist/zod/FrameSignature.d.ts.map +1 -0
- package/dist/zod/FrameSignature.js +66 -0
- package/dist/zod/FrameSignature.js.map +1 -0
- package/dist/zod/RpcSchema.d.ts +806 -11
- package/dist/zod/RpcSchema.d.ts.map +1 -1
- package/dist/zod/Transaction.d.ts +252 -0
- package/dist/zod/Transaction.d.ts.map +1 -1
- package/dist/zod/Transaction.js +54 -0
- package/dist/zod/Transaction.js.map +1 -1
- package/dist/zod/TransactionEnvelope.d.ts +233 -4
- package/dist/zod/TransactionEnvelope.d.ts.map +1 -1
- package/dist/zod/TransactionEnvelope.js +9 -0
- package/dist/zod/TransactionEnvelope.js.map +1 -1
- package/dist/zod/TransactionReceipt.d.ts +48 -0
- package/dist/zod/TransactionReceipt.d.ts.map +1 -1
- package/dist/zod/TransactionReceipt.js +8 -3
- package/dist/zod/TransactionReceipt.js.map +1 -1
- package/dist/zod/TransactionRequest.d.ts +50 -2
- package/dist/zod/TransactionRequest.d.ts.map +1 -1
- package/dist/zod/TransactionRequest.js +10 -4
- package/dist/zod/TransactionRequest.js.map +1 -1
- package/dist/zod/TxEnvelopeEip8141.d.ts +166 -0
- package/dist/zod/TxEnvelopeEip8141.d.ts.map +1 -0
- package/dist/zod/TxEnvelopeEip8141.js +76 -0
- package/dist/zod/TxEnvelopeEip8141.js.map +1 -0
- package/dist/zod/internal/Frame.d.ts +4 -0
- package/dist/zod/internal/Frame.d.ts.map +1 -0
- package/dist/zod/internal/Frame.js +17 -0
- package/dist/zod/internal/Frame.js.map +1 -0
- package/dist/zod/internal/rpcSchemas/Eth.d.ts +842 -11
- package/dist/zod/internal/rpcSchemas/Eth.d.ts.map +1 -1
- package/dist/zod/internal/rpcSchemas/Wallet.d.ts +56 -2
- package/dist/zod/internal/rpcSchemas/Wallet.d.ts.map +1 -1
- package/dist/zod/tempo/RpcSchemaTempo.d.ts +140 -0
- package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/zod/tempo/Transaction.d.ts +123 -0
- package/dist/zod/tempo/Transaction.d.ts.map +1 -1
- package/dist/zod/z.d.ts +4 -0
- package/dist/zod/z.d.ts.map +1 -1
- package/dist/zod/z.js +4 -0
- package/dist/zod/z.js.map +1 -1
- package/package.json +41 -1
- package/src/core/Frame.ts +442 -0
- package/src/core/FrameReceipt.ts +117 -0
- package/src/core/FrameSignature.ts +593 -0
- package/src/core/Transaction.ts +82 -5
- package/src/core/TransactionReceipt.ts +41 -3
- package/src/core/TransactionRequest.ts +71 -4
- package/src/core/TxEnvelope.ts +159 -90
- package/src/core/TxEnvelopeEip8141.ts +714 -0
- package/src/core/_test/Frame.test-d.ts +108 -0
- package/src/core/_test/Frame.test.ts +280 -0
- package/src/core/_test/FrameReceipt.test.ts +86 -0
- package/src/core/_test/FrameSignature.test-d.ts +93 -0
- package/src/core/_test/FrameSignature.test.ts +554 -0
- package/src/core/_test/Transaction.test.ts +33 -0
- package/src/core/_test/TransactionEnvelope.test-d.ts +74 -0
- package/src/core/_test/TransactionEnvelope.test.ts +107 -0
- package/src/core/_test/TransactionReceipt.test.ts +59 -0
- package/src/core/_test/TransactionRequest.test-d.ts +50 -0
- package/src/core/_test/TransactionRequest.test.ts +88 -1
- package/src/core/_test/TxEnvelopeEip8141.test-d.ts +44 -0
- package/src/core/_test/TxEnvelopeEip8141.test.ts +1775 -0
- package/src/core/_test/curves.test.ts +6 -1
- package/src/core/_test/index.test.ts +4 -0
- package/src/core/internal/curves.ts +4 -0
- package/src/index.ts +77 -0
- package/src/version.ts +1 -1
- package/src/zod/Frame.ts +82 -0
- package/src/zod/FrameReceipt.ts +48 -0
- package/src/zod/FrameSignature.ts +78 -0
- package/src/zod/Transaction.ts +63 -0
- package/src/zod/TransactionEnvelope.ts +33 -0
- package/src/zod/TransactionReceipt.ts +14 -3
- package/src/zod/TransactionRequest.ts +18 -3
- package/src/zod/TxEnvelopeEip8141.ts +102 -0
- package/src/zod/_test/Frame.test-d.ts +41 -0
- package/src/zod/_test/Frame.test.ts +57 -0
- package/src/zod/_test/FrameReceipt.test.ts +75 -0
- package/src/zod/_test/FrameSignature.test.ts +94 -0
- package/src/zod/_test/TxEnvelopeEip8141.test.ts +116 -0
- package/src/zod/internal/Frame.ts +26 -0
- package/src/zod/z.ts +4 -0
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1.js'
|
|
1
2
|
import { p256 } from '@noble/curves/nist.js'
|
|
2
3
|
import { expect, test } from 'vp/test'
|
|
3
|
-
import { p256N } from '../internal/curves.js'
|
|
4
|
+
import { p256N, secp256k1N } from '../internal/curves.js'
|
|
4
5
|
|
|
5
6
|
test('p256N matches @noble/curves', () => {
|
|
6
7
|
expect(p256N).toEqual(p256.Point.CURVE().n)
|
|
7
8
|
})
|
|
9
|
+
|
|
10
|
+
test('secp256k1N matches @noble/curves', () => {
|
|
11
|
+
expect(secp256k1N).toEqual(secp256k1.Point.Fn.ORDER)
|
|
12
|
+
})
|
|
@@ -41,6 +41,9 @@ test('exports', () => {
|
|
|
41
41
|
"Errors",
|
|
42
42
|
"Fee",
|
|
43
43
|
"Filter",
|
|
44
|
+
"Frame",
|
|
45
|
+
"FrameReceipt",
|
|
46
|
+
"FrameSignature",
|
|
44
47
|
"Hash",
|
|
45
48
|
"HdKey",
|
|
46
49
|
"Hex",
|
|
@@ -73,6 +76,7 @@ test('exports', () => {
|
|
|
73
76
|
"TxEnvelopeEip2930",
|
|
74
77
|
"TxEnvelopeEip4844",
|
|
75
78
|
"TxEnvelopeEip7702",
|
|
79
|
+
"TxEnvelopeEip8141",
|
|
76
80
|
"TxEnvelopeLegacy",
|
|
77
81
|
"TypedData",
|
|
78
82
|
"ValidatorData",
|
package/src/index.ts
CHANGED
|
@@ -1603,6 +1603,63 @@ export * as Fee from './core/Fee.js'
|
|
|
1603
1603
|
* @category Execution Spec
|
|
1604
1604
|
*/
|
|
1605
1605
|
export * as Filter from './core/Filter.js'
|
|
1606
|
+
/**
|
|
1607
|
+
* Utilities for constructing, validating, and encoding [EIP-8141](https://eips.ethereum.org/EIPS/eip-8141) call frames.
|
|
1608
|
+
*
|
|
1609
|
+
* A {@link ox#Frame.Frame} describes a call with an execution mode, approval flags,
|
|
1610
|
+
* and separate execution and state gas limits.
|
|
1611
|
+
*
|
|
1612
|
+
* @example
|
|
1613
|
+
* ### Creating Frames
|
|
1614
|
+
*
|
|
1615
|
+
* Use {@link ox#Frame.(from:function)} to construct a frame with named mode and flags.
|
|
1616
|
+
*
|
|
1617
|
+
* ```ts twoslash
|
|
1618
|
+
* import { Frame } from 'ox'
|
|
1619
|
+
*
|
|
1620
|
+
* const frame = Frame.from({
|
|
1621
|
+
* flags: 'approveExecutionAndPayment',
|
|
1622
|
+
* gas: 50_000n,
|
|
1623
|
+
* mode: 'verify'
|
|
1624
|
+
* })
|
|
1625
|
+
* ```
|
|
1626
|
+
*
|
|
1627
|
+
* @category Transaction Envelopes
|
|
1628
|
+
*/
|
|
1629
|
+
export * as Frame from './core/Frame.js'
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* Utilities for converting EIP-8141 frame receipts between RPC and decoded forms.
|
|
1633
|
+
*
|
|
1634
|
+
* Frame receipts include execution gas, state gas, logs, and execution status.
|
|
1635
|
+
*
|
|
1636
|
+
* @category Execution Spec
|
|
1637
|
+
*/
|
|
1638
|
+
export * as FrameReceipt from './core/FrameReceipt.js'
|
|
1639
|
+
|
|
1640
|
+
/**
|
|
1641
|
+
* Utilities for constructing, validating, and encoding [EIP-8141](https://eips.ethereum.org/EIPS/eip-8141) signature entries.
|
|
1642
|
+
*
|
|
1643
|
+
* Supports {@link ox#FrameSignature.Arbitrary}, {@link ox#FrameSignature.Secp256k1},
|
|
1644
|
+
* and {@link ox#FrameSignature.P256} entries. An empty payload selects the canonical
|
|
1645
|
+
* transaction signing hash.
|
|
1646
|
+
*
|
|
1647
|
+
* @example
|
|
1648
|
+
* ### Creating Signature Entries
|
|
1649
|
+
*
|
|
1650
|
+
* Use {@link ox#FrameSignature.(from:function)} to wrap arbitrary witness bytes.
|
|
1651
|
+
*
|
|
1652
|
+
* ```ts twoslash
|
|
1653
|
+
* import { FrameSignature } from 'ox'
|
|
1654
|
+
*
|
|
1655
|
+
* const entry = FrameSignature.from('0xaabb')
|
|
1656
|
+
* // @log: { payload: '0x', scheme: 'arbitrary', signature: '0xaabb' }
|
|
1657
|
+
* ```
|
|
1658
|
+
*
|
|
1659
|
+
* @category Transaction Envelopes
|
|
1660
|
+
*/
|
|
1661
|
+
export * as FrameSignature from './core/FrameSignature.js'
|
|
1662
|
+
|
|
1606
1663
|
/**
|
|
1607
1664
|
* Utility functions for hashing (keccak256, sha256, etc).
|
|
1608
1665
|
*
|
|
@@ -3511,6 +3568,26 @@ export * as TxEnvelopeEip4844 from './core/TxEnvelopeEip4844.js'
|
|
|
3511
3568
|
* @category Transaction Envelopes
|
|
3512
3569
|
*/
|
|
3513
3570
|
export * as TxEnvelopeEip7702 from './core/TxEnvelopeEip7702.js'
|
|
3571
|
+
|
|
3572
|
+
/**
|
|
3573
|
+
* Utilities for constructing, signing, and encoding EIP-8141 frame transactions.
|
|
3574
|
+
*
|
|
3575
|
+
* @example
|
|
3576
|
+
* ### Basic Usage
|
|
3577
|
+
*
|
|
3578
|
+
* ```ts twoslash
|
|
3579
|
+
* import { TxEnvelopeEip8141 } from 'ox'
|
|
3580
|
+
*
|
|
3581
|
+
* const envelope = TxEnvelopeEip8141.from({
|
|
3582
|
+
* chainId: 1,
|
|
3583
|
+
* frames: [{ gas: 50_000n, mode: 'sender' }],
|
|
3584
|
+
* sender: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8'
|
|
3585
|
+
* })
|
|
3586
|
+
* ```
|
|
3587
|
+
*
|
|
3588
|
+
* @category Transaction Envelopes
|
|
3589
|
+
*/
|
|
3590
|
+
export * as TxEnvelopeEip8141 from './core/TxEnvelopeEip8141.js'
|
|
3514
3591
|
/**
|
|
3515
3592
|
* Utility functions for working
|
|
3516
3593
|
* with **Legacy Transaction Envelopes**.
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '1.
|
|
2
|
+
export const version = '1.8.1'
|
package/src/zod/Frame.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
|
|
2
|
+
import * as core_Frame from '../core/Frame.js'
|
|
3
|
+
import * as z_Address from './Address.js'
|
|
4
|
+
import * as z_Hex from './Hex.js'
|
|
5
|
+
import * as z from 'zod/mini'
|
|
6
|
+
|
|
7
|
+
const Mode = z.union([z.number(), z.enum(['default', 'sender', 'verify'])])
|
|
8
|
+
const Flags = z.union([
|
|
9
|
+
z.number(),
|
|
10
|
+
z.enum([
|
|
11
|
+
'approveExecution',
|
|
12
|
+
'approveExecutionAndPayment',
|
|
13
|
+
'approvePayment',
|
|
14
|
+
'atomicBatch',
|
|
15
|
+
'none',
|
|
16
|
+
]),
|
|
17
|
+
])
|
|
18
|
+
|
|
19
|
+
/** Decoded frame schema. */
|
|
20
|
+
export const Decoded: z.ZodMiniType<core_Frame.Frame, core_Frame.Frame> = z
|
|
21
|
+
.object(fields(z.bigint()))
|
|
22
|
+
.check(z.refine(core_Frame.validate, 'Invalid frame'))
|
|
23
|
+
|
|
24
|
+
/** RPC frame schema. */
|
|
25
|
+
export const Rpc = z
|
|
26
|
+
.object({
|
|
27
|
+
data: z_Hex.Hex,
|
|
28
|
+
executionGasLimit: z_Hex.Hex,
|
|
29
|
+
flags: z.number(),
|
|
30
|
+
mode: z.number(),
|
|
31
|
+
stateGasLimit: z_Hex.Hex,
|
|
32
|
+
target: z.optional(z.nullable(z_Address.Address)),
|
|
33
|
+
value: z_Hex.Hex,
|
|
34
|
+
})
|
|
35
|
+
.check(
|
|
36
|
+
z.refine((value) => {
|
|
37
|
+
try {
|
|
38
|
+
core_Frame.fromRpc(value)
|
|
39
|
+
return true
|
|
40
|
+
} catch {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}, 'Invalid frame'),
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
/** Codec between RPC and decoded frames. */
|
|
47
|
+
export const Frame = z.codec(Rpc, Decoded, {
|
|
48
|
+
decode: core_Frame.fromRpc,
|
|
49
|
+
encode: core_Frame.toRpc,
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
/** Decoded frame schema accepting numberish budgets. */
|
|
53
|
+
export const DecodedToRpc = z
|
|
54
|
+
.object(fields(z.union([z_Hex.Hex, z.bigint(), z.number()])))
|
|
55
|
+
.check(
|
|
56
|
+
z.refine((value) => {
|
|
57
|
+
try {
|
|
58
|
+
core_Frame.fromRpc(core_Frame.toRpc(value))
|
|
59
|
+
return true
|
|
60
|
+
} catch {
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
}, 'Invalid frame'),
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
/** Encode-only frame codec accepting numberish budgets. */
|
|
67
|
+
export const FrameToRpc = z.codec(Rpc, DecodedToRpc, {
|
|
68
|
+
decode: core_Frame.fromRpc,
|
|
69
|
+
encode: core_Frame.toRpc,
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
function fields<uint extends z.ZodMiniType>(uint: uint) {
|
|
73
|
+
return {
|
|
74
|
+
data: z.optional(z_Hex.Hex),
|
|
75
|
+
flags: z.optional(Flags),
|
|
76
|
+
gas: z.optional(uint),
|
|
77
|
+
mode: z.optional(Mode),
|
|
78
|
+
stateGas: z.optional(uint),
|
|
79
|
+
to: z.optional(z_Address.Address),
|
|
80
|
+
value: z.optional(uint),
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
|
|
2
|
+
import * as core_FrameReceipt from '../core/FrameReceipt.js'
|
|
3
|
+
import * as z_Address from './Address.js'
|
|
4
|
+
import * as z_Hex from './Hex.js'
|
|
5
|
+
import {
|
|
6
|
+
quantityHex,
|
|
7
|
+
uintBigint,
|
|
8
|
+
uintBigintNumberish,
|
|
9
|
+
} from './internal/Integer.js'
|
|
10
|
+
import * as z from 'zod/mini'
|
|
11
|
+
|
|
12
|
+
const frameLog = z.object({
|
|
13
|
+
address: z_Address.Address,
|
|
14
|
+
data: z_Hex.Hex,
|
|
15
|
+
topics: z.array(z_Hex.Hex),
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const frameReceiptRpc = z.object({
|
|
19
|
+
executionGasUsed: quantityHex(),
|
|
20
|
+
logs: z.readonly(z.array(frameLog)),
|
|
21
|
+
stateGasUsed: quantityHex(),
|
|
22
|
+
status: z.union([z.literal(0), z.literal(1), z.literal(2)]),
|
|
23
|
+
})
|
|
24
|
+
const frameReceiptDecoded = z.object({
|
|
25
|
+
gasUsed: uintBigint(),
|
|
26
|
+
logs: z.readonly(z.array(frameLog)),
|
|
27
|
+
stateGasUsed: uintBigint(),
|
|
28
|
+
status: z.enum(['reverted', 'success', 'skipped']),
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
/** Codec between RPC and decoded frame receipts. */
|
|
32
|
+
export const FrameReceipt = z.codec(frameReceiptRpc, frameReceiptDecoded, {
|
|
33
|
+
decode: core_FrameReceipt.fromRpc,
|
|
34
|
+
encode: core_FrameReceipt.toRpc,
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
/** Encode-only frame receipt codec accepting numberish gas. */
|
|
38
|
+
export const FrameReceiptToRpc = z.codec(
|
|
39
|
+
frameReceiptRpc,
|
|
40
|
+
z.extend(frameReceiptDecoded, {
|
|
41
|
+
gasUsed: uintBigintNumberish(),
|
|
42
|
+
stateGasUsed: uintBigintNumberish(),
|
|
43
|
+
}),
|
|
44
|
+
{
|
|
45
|
+
decode: core_FrameReceipt.fromRpc,
|
|
46
|
+
encode: core_FrameReceipt.toRpc,
|
|
47
|
+
},
|
|
48
|
+
)
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
|
|
2
|
+
import * as core_FrameSignature from '../core/FrameSignature.js'
|
|
3
|
+
import * as z_Address from './Address.js'
|
|
4
|
+
import * as z_Hex from './Hex.js'
|
|
5
|
+
import * as z from 'zod/mini'
|
|
6
|
+
|
|
7
|
+
const publicKey = z.object({ prefix: z.number(), x: z_Hex.Hex, y: z_Hex.Hex })
|
|
8
|
+
const signature = z.object({
|
|
9
|
+
r: z_Hex.Hex,
|
|
10
|
+
s: z_Hex.Hex,
|
|
11
|
+
yParity: z.optional(z.number()),
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
/** Contract-defined frame signature schema. */
|
|
15
|
+
export const Arbitrary = z.object({
|
|
16
|
+
payload: z.optional(z_Hex.Hex),
|
|
17
|
+
scheme: z.union([z.literal(0), z.literal('arbitrary')]),
|
|
18
|
+
signature: z_Hex.Hex,
|
|
19
|
+
signer: z.optional(z.undefined()),
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
/** secp256k1 frame signature schema. */
|
|
23
|
+
export const Secp256k1 = z.object({
|
|
24
|
+
payload: z.optional(z_Hex.Hex),
|
|
25
|
+
scheme: z.union([z.literal(1), z.literal('secp256k1')]),
|
|
26
|
+
signature: z.optional(
|
|
27
|
+
z.object({ r: z_Hex.Hex, s: z_Hex.Hex, yParity: z.number() }),
|
|
28
|
+
),
|
|
29
|
+
signer: z.optional(z_Address.Address),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const p256 = {
|
|
33
|
+
payload: z.optional(z_Hex.Hex),
|
|
34
|
+
scheme: z.union([z.literal(2), z.literal('p256')]),
|
|
35
|
+
signer: z.optional(z_Address.Address),
|
|
36
|
+
}
|
|
37
|
+
/** P-256 frame signature schema, including unsigned placeholders. */
|
|
38
|
+
export const P256 = z.union([
|
|
39
|
+
z.object({ ...p256, publicKey, signature }),
|
|
40
|
+
z.object({
|
|
41
|
+
...p256,
|
|
42
|
+
publicKey: z.optional(publicKey),
|
|
43
|
+
signature: z.optional(z.undefined()),
|
|
44
|
+
}),
|
|
45
|
+
])
|
|
46
|
+
|
|
47
|
+
/** Decoded frame signature schema. */
|
|
48
|
+
export const Decoded: z.ZodMiniType<
|
|
49
|
+
core_FrameSignature.FrameSignature,
|
|
50
|
+
core_FrameSignature.FrameSignature
|
|
51
|
+
> = z
|
|
52
|
+
.union([Arbitrary, Secp256k1, P256])
|
|
53
|
+
.check(z.refine(core_FrameSignature.validate, 'Invalid frame signature'))
|
|
54
|
+
|
|
55
|
+
/** RPC frame signature schema. */
|
|
56
|
+
export const Rpc = z
|
|
57
|
+
.object({
|
|
58
|
+
msg: z_Hex.Hex,
|
|
59
|
+
scheme: z.union([z.literal(0), z.literal(1), z.literal(2)]),
|
|
60
|
+
signature: z_Hex.Hex,
|
|
61
|
+
signer: z.optional(z.nullable(z_Address.Address)),
|
|
62
|
+
})
|
|
63
|
+
.check(
|
|
64
|
+
z.refine((value) => {
|
|
65
|
+
try {
|
|
66
|
+
core_FrameSignature.fromRpc(value)
|
|
67
|
+
return true
|
|
68
|
+
} catch {
|
|
69
|
+
return false
|
|
70
|
+
}
|
|
71
|
+
}, 'Invalid frame signature'),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
/** Codec between RPC and structured frame signatures. */
|
|
75
|
+
export const FrameSignature = z.codec(Rpc, Decoded, {
|
|
76
|
+
decode: core_FrameSignature.fromRpc,
|
|
77
|
+
encode: core_FrameSignature.toRpc,
|
|
78
|
+
})
|
package/src/zod/Transaction.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import * as z_AccessList from './AccessList.js'
|
|
3
3
|
import * as z_Address from './Address.js'
|
|
4
4
|
import * as z_Authorization from './Authorization.js'
|
|
5
|
+
import * as z_Frame from './Frame.js'
|
|
6
|
+
import * as z_FrameSignature from './FrameSignature.js'
|
|
7
|
+
import { chainId, chainIdToRpc } from './internal/Frame.js'
|
|
5
8
|
import * as z_Hex from './Hex.js'
|
|
6
9
|
import * as z_Number from './Number.js'
|
|
7
10
|
import * as z_Uint from './Uint.js'
|
|
@@ -13,6 +16,7 @@ const fromRpcType = {
|
|
|
13
16
|
'0x2': 'eip1559',
|
|
14
17
|
'0x3': 'eip4844',
|
|
15
18
|
'0x4': 'eip7702',
|
|
19
|
+
'0x6': 'eip8141',
|
|
16
20
|
} as const
|
|
17
21
|
|
|
18
22
|
const toRpcType = {
|
|
@@ -21,6 +25,7 @@ const toRpcType = {
|
|
|
21
25
|
eip1559: '0x2',
|
|
22
26
|
eip4844: '0x3',
|
|
23
27
|
eip7702: '0x4',
|
|
28
|
+
eip8141: '0x6',
|
|
24
29
|
} as const
|
|
25
30
|
|
|
26
31
|
/** Transaction type schema. */
|
|
@@ -134,6 +139,61 @@ export const PendingEip7702 = z.object(
|
|
|
134
139
|
),
|
|
135
140
|
)
|
|
136
141
|
|
|
142
|
+
const Eip8141Type = type('0x6', 'eip8141')
|
|
143
|
+
|
|
144
|
+
/** EIP-8141 transaction schema. */
|
|
145
|
+
export const Eip8141 = z.object({
|
|
146
|
+
...eip8141Fields(z_Uint.Uint, chainId, z_Frame.Frame),
|
|
147
|
+
blockHash: z_Hex.Hex,
|
|
148
|
+
blockNumber: z_Uint.Uint,
|
|
149
|
+
blockTimestamp: z.optional(z_Uint.Uint),
|
|
150
|
+
transactionIndex: z_Number.Number,
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
/** Encode-only EIP-8141 transaction schema accepting numberish values. */
|
|
154
|
+
export const Eip8141ToRpc = z.object({
|
|
155
|
+
...eip8141Fields(z_Uint.UintToRpc, chainIdToRpc, z_Frame.FrameToRpc),
|
|
156
|
+
blockHash: z_Hex.Hex,
|
|
157
|
+
blockNumber: z_Uint.UintToRpc,
|
|
158
|
+
blockTimestamp: z.optional(z_Uint.UintToRpc),
|
|
159
|
+
transactionIndex: z_Number.NumberToRpc,
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
/** Pending EIP-8141 transaction schema. */
|
|
163
|
+
export const PendingEip8141 = z.object({
|
|
164
|
+
...eip8141Fields(z_Uint.Uint, chainId, z_Frame.Frame),
|
|
165
|
+
blockHash: z.null(),
|
|
166
|
+
blockNumber: z.null(),
|
|
167
|
+
blockTimestamp: z.optional(z.null()),
|
|
168
|
+
transactionIndex: z.null(),
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
function eip8141Fields<
|
|
172
|
+
uint extends z.ZodMiniType,
|
|
173
|
+
num extends z.ZodMiniType,
|
|
174
|
+
frame extends z.ZodMiniType,
|
|
175
|
+
>(uint: uint, num: num, frame: frame) {
|
|
176
|
+
return {
|
|
177
|
+
blobVersionedHashes: z.readonly(z.array(z_Hex.Hex)),
|
|
178
|
+
chainId: num,
|
|
179
|
+
data: z.optional(z_Hex.Hex),
|
|
180
|
+
frames: z.readonly(z.array(frame)),
|
|
181
|
+
from: z_Address.Address,
|
|
182
|
+
gas: uint,
|
|
183
|
+
gasPrice: z.optional(uint),
|
|
184
|
+
hash: z_Hex.Hex,
|
|
185
|
+
input: z_Hex.Hex,
|
|
186
|
+
maxFeePerBlobGas: uint,
|
|
187
|
+
maxFeePerGas: uint,
|
|
188
|
+
maxPriorityFeePerGas: uint,
|
|
189
|
+
nonce: uint,
|
|
190
|
+
signatures: z.readonly(z.array(z_FrameSignature.FrameSignature)),
|
|
191
|
+
to: z.nullable(z_Address.Address),
|
|
192
|
+
type: Eip8141Type,
|
|
193
|
+
value: uint,
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
137
197
|
/** Unknown typed transaction schema. */
|
|
138
198
|
export const Unknown = z.object(
|
|
139
199
|
baseFields(UnknownType, z_Uint.Uint, z_Number.Number),
|
|
@@ -155,6 +215,7 @@ export const Transaction = z.union([
|
|
|
155
215
|
Eip1559,
|
|
156
216
|
Eip4844,
|
|
157
217
|
Eip7702,
|
|
218
|
+
Eip8141,
|
|
158
219
|
Unknown,
|
|
159
220
|
])
|
|
160
221
|
|
|
@@ -165,6 +226,7 @@ export const TransactionToRpc = z.union([
|
|
|
165
226
|
Eip1559ToRpc,
|
|
166
227
|
Eip4844ToRpc,
|
|
167
228
|
Eip7702ToRpc,
|
|
229
|
+
Eip8141ToRpc,
|
|
168
230
|
UnknownToRpc,
|
|
169
231
|
])
|
|
170
232
|
|
|
@@ -175,6 +237,7 @@ export const Pending = z.union([
|
|
|
175
237
|
PendingEip1559,
|
|
176
238
|
PendingEip4844,
|
|
177
239
|
PendingEip7702,
|
|
240
|
+
PendingEip8141,
|
|
178
241
|
PendingUnknown,
|
|
179
242
|
])
|
|
180
243
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as core_FrameSignature from '../core/FrameSignature.js'
|
|
1
2
|
/* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
|
|
2
3
|
import * as core_TxEnvelope from '../core/TxEnvelope.js'
|
|
3
4
|
import * as z_AccessList from './AccessList.js'
|
|
@@ -7,6 +8,7 @@ import * as z_TxEnvelopeEip1559 from './TxEnvelopeEip1559.js'
|
|
|
7
8
|
import * as z_TxEnvelopeEip2930 from './TxEnvelopeEip2930.js'
|
|
8
9
|
import * as z_TxEnvelopeEip4844 from './TxEnvelopeEip4844.js'
|
|
9
10
|
import * as z_TxEnvelopeEip7702 from './TxEnvelopeEip7702.js'
|
|
11
|
+
import * as z_TxEnvelopeEip8141 from './TxEnvelopeEip8141.js'
|
|
10
12
|
import * as z_TxEnvelopeLegacy from './TxEnvelopeLegacy.js'
|
|
11
13
|
import {
|
|
12
14
|
baseFields,
|
|
@@ -21,6 +23,7 @@ const fromRpcType = {
|
|
|
21
23
|
'0x2': 'eip1559',
|
|
22
24
|
'0x3': 'eip4844',
|
|
23
25
|
'0x4': 'eip7702',
|
|
26
|
+
'0x6': 'eip8141',
|
|
24
27
|
} as const
|
|
25
28
|
|
|
26
29
|
const toRpcType = {
|
|
@@ -29,6 +32,7 @@ const toRpcType = {
|
|
|
29
32
|
eip1559: '0x2',
|
|
30
33
|
eip4844: '0x3',
|
|
31
34
|
eip7702: '0x4',
|
|
35
|
+
eip8141: '0x6',
|
|
32
36
|
} as const
|
|
33
37
|
|
|
34
38
|
/** Transaction envelope type schema. */
|
|
@@ -47,6 +51,7 @@ export const BaseSigned = z.object(
|
|
|
47
51
|
|
|
48
52
|
/** Transaction envelope schema. */
|
|
49
53
|
export const TransactionEnvelope = z.union([
|
|
54
|
+
z_TxEnvelopeEip8141.TxEnvelopeEip8141,
|
|
50
55
|
z_TxEnvelopeLegacy.TxEnvelopeLegacy,
|
|
51
56
|
z_TxEnvelopeEip2930.TxEnvelopeEip2930,
|
|
52
57
|
z_TxEnvelopeEip1559.TxEnvelopeEip1559,
|
|
@@ -56,6 +61,7 @@ export const TransactionEnvelope = z.union([
|
|
|
56
61
|
|
|
57
62
|
/** Encode-only transaction envelope schema accepting numberish `toRpc` inputs. */
|
|
58
63
|
export const TransactionEnvelopeToRpc = z.union([
|
|
64
|
+
z_TxEnvelopeEip8141.TxEnvelopeEip8141ToRpc,
|
|
59
65
|
z_TxEnvelopeLegacy.TxEnvelopeLegacyToRpc,
|
|
60
66
|
z_TxEnvelopeEip2930.TxEnvelopeEip2930ToRpc,
|
|
61
67
|
z_TxEnvelopeEip1559.TxEnvelopeEip1559ToRpc,
|
|
@@ -65,6 +71,15 @@ export const TransactionEnvelopeToRpc = z.union([
|
|
|
65
71
|
|
|
66
72
|
/** Signed transaction envelope schema. */
|
|
67
73
|
export const Signed = z.union([
|
|
74
|
+
z_TxEnvelopeEip8141.TxEnvelopeEip8141.check(
|
|
75
|
+
z.refine(
|
|
76
|
+
(value) =>
|
|
77
|
+
(value.signatures ?? []).every((entry) =>
|
|
78
|
+
core_FrameSignature.validate(entry, { signed: true }),
|
|
79
|
+
),
|
|
80
|
+
'Invalid signed frame transaction',
|
|
81
|
+
),
|
|
82
|
+
),
|
|
68
83
|
z_TxEnvelopeLegacy.Signed,
|
|
69
84
|
z_TxEnvelopeEip2930.Signed,
|
|
70
85
|
z_TxEnvelopeEip1559.Signed,
|
|
@@ -74,6 +89,15 @@ export const Signed = z.union([
|
|
|
74
89
|
|
|
75
90
|
/** Encode-only signed transaction envelope schema accepting numberish `toRpc` inputs. */
|
|
76
91
|
export const SignedToRpc = z.union([
|
|
92
|
+
z_TxEnvelopeEip8141.TxEnvelopeEip8141ToRpc.check(
|
|
93
|
+
z.refine(
|
|
94
|
+
(value) =>
|
|
95
|
+
(value.signatures ?? []).every((entry) =>
|
|
96
|
+
core_FrameSignature.validate(entry, { signed: true }),
|
|
97
|
+
),
|
|
98
|
+
'Invalid signed frame transaction',
|
|
99
|
+
),
|
|
100
|
+
),
|
|
77
101
|
z_TxEnvelopeLegacy.SignedToRpc,
|
|
78
102
|
z_TxEnvelopeEip2930.SignedToRpc,
|
|
79
103
|
z_TxEnvelopeEip1559.SignedToRpc,
|
|
@@ -156,6 +180,15 @@ const SignedEip7702Decoded = z.object({
|
|
|
156
180
|
|
|
157
181
|
/** Decoded signed transaction envelope schema. */
|
|
158
182
|
export const SignedDecoded = z.union([
|
|
183
|
+
z_TxEnvelopeEip8141.Decoded.check(
|
|
184
|
+
z.refine(
|
|
185
|
+
(value) =>
|
|
186
|
+
(value.signatures ?? []).every((entry) =>
|
|
187
|
+
core_FrameSignature.validate(entry, { signed: true }),
|
|
188
|
+
),
|
|
189
|
+
'Invalid signed frame transaction',
|
|
190
|
+
),
|
|
191
|
+
),
|
|
159
192
|
SignedLegacyDecoded,
|
|
160
193
|
SignedEip2930Decoded,
|
|
161
194
|
SignedEip1559Decoded,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
|
|
2
2
|
import * as z_Address from './Address.js'
|
|
3
|
+
import * as z_FrameReceipt from './FrameReceipt.js'
|
|
3
4
|
import * as z_Hex from './Hex.js'
|
|
4
5
|
import * as z_Log from './Log.js'
|
|
5
6
|
import * as z_Number from './Number.js'
|
|
@@ -22,6 +23,7 @@ const fromRpcType = {
|
|
|
22
23
|
'0x2': 'eip1559',
|
|
23
24
|
'0x3': 'eip4844',
|
|
24
25
|
'0x4': 'eip7702',
|
|
26
|
+
'0x6': 'eip8141',
|
|
25
27
|
} as const
|
|
26
28
|
|
|
27
29
|
const toRpcType = {
|
|
@@ -30,6 +32,7 @@ const toRpcType = {
|
|
|
30
32
|
eip1559: '0x2',
|
|
31
33
|
eip4844: '0x3',
|
|
32
34
|
eip7702: '0x4',
|
|
35
|
+
eip8141: '0x6',
|
|
33
36
|
} as const
|
|
34
37
|
|
|
35
38
|
/** Transaction receipt status schema. */
|
|
@@ -50,19 +53,25 @@ export const Type = z.codec(z.string(), z.string(), {
|
|
|
50
53
|
|
|
51
54
|
/** Transaction receipt schema. */
|
|
52
55
|
export const TransactionReceipt = z.object(
|
|
53
|
-
fields(z_Uint.Uint, z_Number.Number, z_Log.Log),
|
|
56
|
+
fields(z_Uint.Uint, z_Number.Number, z_Log.Log, z_FrameReceipt.FrameReceipt),
|
|
54
57
|
)
|
|
55
58
|
|
|
56
59
|
/** Encode-only transaction receipt schema accepting numberish `toRpc` inputs. */
|
|
57
60
|
export const TransactionReceiptToRpc = z.object(
|
|
58
|
-
fields(
|
|
61
|
+
fields(
|
|
62
|
+
z_Uint.UintToRpc,
|
|
63
|
+
z_Number.NumberToRpc,
|
|
64
|
+
z_Log.LogToRpc,
|
|
65
|
+
z_FrameReceipt.FrameReceiptToRpc,
|
|
66
|
+
),
|
|
59
67
|
)
|
|
60
68
|
|
|
61
69
|
function fields<
|
|
62
70
|
uint extends z.ZodMiniType,
|
|
63
71
|
num extends z.ZodMiniType,
|
|
64
72
|
log extends z.ZodMiniType,
|
|
65
|
-
|
|
73
|
+
frame extends z.ZodMiniType,
|
|
74
|
+
>(uint: uint, num: num, log: log, frame: frame) {
|
|
66
75
|
return {
|
|
67
76
|
blobGasPrice: z.optional(uint),
|
|
68
77
|
blobGasUsed: z.optional(uint),
|
|
@@ -71,10 +80,12 @@ function fields<
|
|
|
71
80
|
contractAddress: z.optional(z.union([z_Address.Address, z.null()])),
|
|
72
81
|
cumulativeGasUsed: uint,
|
|
73
82
|
effectiveGasPrice: uint,
|
|
83
|
+
frameReceipts: z.optional(z.readonly(z.array(frame))),
|
|
74
84
|
from: z_Address.Address,
|
|
75
85
|
gasUsed: uint,
|
|
76
86
|
logs: z.array(log),
|
|
77
87
|
logsBloom: z_Hex.Hex,
|
|
88
|
+
payer: z.optional(z_Address.Address),
|
|
78
89
|
root: z.optional(z_Hex.Hex),
|
|
79
90
|
status: Status,
|
|
80
91
|
to: z.union([z_Address.Address, z.null()]),
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import * as z_AccessList from './AccessList.js'
|
|
3
3
|
import * as z_Address from './Address.js'
|
|
4
4
|
import * as z_Authorization from './Authorization.js'
|
|
5
|
+
import * as z_Frame from './Frame.js'
|
|
6
|
+
import * as z_FrameSignature from './FrameSignature.js'
|
|
5
7
|
import * as z_Hex from './Hex.js'
|
|
6
8
|
import * as z_Number from './Number.js'
|
|
7
9
|
import * as z_Uint from './Uint.js'
|
|
@@ -13,6 +15,7 @@ const fromRpcType = {
|
|
|
13
15
|
'0x2': 'eip1559',
|
|
14
16
|
'0x3': 'eip4844',
|
|
15
17
|
'0x4': 'eip7702',
|
|
18
|
+
'0x6': 'eip8141',
|
|
16
19
|
} as const
|
|
17
20
|
|
|
18
21
|
const toRpcType = {
|
|
@@ -21,6 +24,7 @@ const toRpcType = {
|
|
|
21
24
|
eip1559: '0x2',
|
|
22
25
|
eip4844: '0x3',
|
|
23
26
|
eip7702: '0x4',
|
|
27
|
+
eip8141: '0x6',
|
|
24
28
|
} as const
|
|
25
29
|
|
|
26
30
|
const type = z.codec(z.string(), z.string(), {
|
|
@@ -30,7 +34,12 @@ const type = z.codec(z.string(), z.string(), {
|
|
|
30
34
|
|
|
31
35
|
/** Transaction request schema. */
|
|
32
36
|
export const TransactionRequest = z.object(
|
|
33
|
-
fields(
|
|
37
|
+
fields(
|
|
38
|
+
z_Uint.Uint,
|
|
39
|
+
z_Number.Number,
|
|
40
|
+
z_Authorization.ListSigned,
|
|
41
|
+
z_Frame.Frame,
|
|
42
|
+
),
|
|
34
43
|
)
|
|
35
44
|
|
|
36
45
|
/** Encode-only transaction request schema accepting numberish `toRpc` inputs. */
|
|
@@ -39,6 +48,7 @@ export const TransactionRequestToRpc = z.object(
|
|
|
39
48
|
z_Uint.UintToRpc,
|
|
40
49
|
z_Number.NumberToRpc,
|
|
41
50
|
z_Authorization.ListSignedToRpc,
|
|
51
|
+
z_Frame.FrameToRpc,
|
|
42
52
|
),
|
|
43
53
|
)
|
|
44
54
|
|
|
@@ -46,7 +56,8 @@ function fields<
|
|
|
46
56
|
uint extends z.ZodMiniType,
|
|
47
57
|
num extends z.ZodMiniType,
|
|
48
58
|
authorizationList extends z.ZodMiniType,
|
|
49
|
-
|
|
59
|
+
frame extends z.ZodMiniType,
|
|
60
|
+
>(uint: uint, num: num, authorizationList: authorizationList, frame: frame) {
|
|
50
61
|
return {
|
|
51
62
|
accessList: z.optional(z_AccessList.AccessList),
|
|
52
63
|
authorizationList: z.optional(authorizationList),
|
|
@@ -54,14 +65,18 @@ function fields<
|
|
|
54
65
|
blobs: z.optional(z.readonly(z.array(z_Hex.Hex))),
|
|
55
66
|
chainId: z.optional(num),
|
|
56
67
|
data: z.optional(z_Hex.Hex),
|
|
57
|
-
|
|
68
|
+
frames: z.optional(z.readonly(z.array(frame))),
|
|
58
69
|
from: z.optional(z_Address.Address),
|
|
59
70
|
gas: z.optional(uint),
|
|
60
71
|
gasPrice: z.optional(uint),
|
|
72
|
+
input: z.optional(z_Hex.Hex),
|
|
61
73
|
maxFeePerBlobGas: z.optional(uint),
|
|
62
74
|
maxFeePerGas: z.optional(uint),
|
|
63
75
|
maxPriorityFeePerGas: z.optional(uint),
|
|
64
76
|
nonce: z.optional(uint),
|
|
77
|
+
signatures: z.optional(
|
|
78
|
+
z.readonly(z.array(z_FrameSignature.FrameSignature)),
|
|
79
|
+
),
|
|
65
80
|
to: z.optional(z.union([z_Address.Address, z.null()])),
|
|
66
81
|
type: z.optional(type),
|
|
67
82
|
value: z.optional(uint),
|