tempo.ts 0.10.5 → 0.11.0
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 +30 -0
- package/README.md +0 -41
- package/dist/viem/Account.d.ts +8 -3
- package/dist/viem/Account.d.ts.map +1 -1
- package/dist/viem/Account.js +9 -2
- package/dist/viem/Account.js.map +1 -1
- package/dist/viem/Actions/amm.d.ts +1 -1
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +1 -2
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/dex.d.ts +0 -35
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/dex.js +0 -43
- package/dist/viem/Actions/dex.js.map +1 -1
- package/dist/viem/Actions/fee.d.ts +1 -1
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/fee.js +1 -1
- package/dist/viem/Actions/fee.js.map +1 -1
- package/dist/viem/Actions/nonce.d.ts.map +1 -1
- package/dist/viem/Actions/nonce.js +6 -4
- package/dist/viem/Actions/nonce.js.map +1 -1
- package/dist/viem/Actions/token.d.ts +1 -2
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +1 -2
- package/dist/viem/Actions/token.js.map +1 -1
- package/dist/viem/Chain.d.ts +34 -34
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +2 -0
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +5 -3
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/Transaction.d.ts +8 -5
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +13 -3
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/internal/types.d.ts +1 -1
- package/dist/viem/internal/types.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.d.ts +1 -45
- package/dist/wagmi/Actions/dex.d.ts.map +1 -1
- package/dist/wagmi/Actions/dex.js +0 -55
- package/dist/wagmi/Actions/dex.js.map +1 -1
- package/dist/wagmi/Connector.d.ts +1 -1
- package/dist/wagmi/Connector.d.ts.map +1 -1
- package/dist/wagmi/Connector.js +1 -2
- package/dist/wagmi/Connector.js.map +1 -1
- package/dist/wagmi/Hooks/dex.d.ts +3 -46
- package/dist/wagmi/Hooks/dex.d.ts.map +1 -1
- package/dist/wagmi/Hooks/dex.js +2 -54
- package/dist/wagmi/Hooks/dex.js.map +1 -1
- package/dist/wagmi/index.d.ts +1 -1
- package/dist/wagmi/index.d.ts.map +1 -1
- package/dist/wagmi/index.js +1 -1
- package/dist/wagmi/index.js.map +1 -1
- package/package.json +5 -23
- package/src/viem/Account.test.ts +1 -1
- package/src/viem/Account.ts +11 -2
- package/src/viem/Actions/account.ts +1 -1
- package/src/viem/Actions/amm.ts +1 -2
- package/src/viem/Actions/dex.test.ts +1 -195
- package/src/viem/Actions/dex.ts +0 -53
- package/src/viem/Actions/fee.test.ts +2 -2
- package/src/viem/Actions/fee.ts +1 -1
- package/src/viem/Actions/nonce.test.ts +27 -14
- package/src/viem/Actions/nonce.ts +6 -4
- package/src/viem/Actions/token.test.ts +18 -52
- package/src/viem/Actions/token.ts +1 -2
- package/src/viem/Chain.ts +3 -1
- package/src/viem/Decorator.ts +0 -30
- package/src/viem/Formatters.ts +9 -3
- package/src/viem/Transaction.ts +23 -7
- package/src/viem/e2e.test.ts +19 -0
- package/src/viem/index.ts +12 -1
- package/src/viem/internal/types.ts +1 -1
- package/src/wagmi/Actions/dex.test.ts +0 -26
- package/src/wagmi/Actions/dex.ts +1 -111
- package/src/wagmi/Actions/nonce.test.ts +8 -4
- package/src/wagmi/Actions/token.test.ts +2 -2
- package/src/wagmi/Connector.ts +1 -2
- package/src/wagmi/Hooks/dex.test.ts +0 -26
- package/src/wagmi/Hooks/dex.ts +1 -88
- package/src/wagmi/Hooks/nonce.test.ts +3 -3
- package/src/wagmi/index.ts +4 -1
- package/dist/chains.d.ts +0 -73
- package/dist/chains.d.ts.map +0 -1
- package/dist/chains.js +0 -51
- package/dist/chains.js.map +0 -1
- package/dist/ox/AuthorizationTempo.d.ts +0 -450
- package/dist/ox/AuthorizationTempo.d.ts.map +0 -1
- package/dist/ox/AuthorizationTempo.js +0 -433
- package/dist/ox/AuthorizationTempo.js.map +0 -1
- package/dist/ox/KeyAuthorization.d.ts +0 -356
- package/dist/ox/KeyAuthorization.d.ts.map +0 -1
- package/dist/ox/KeyAuthorization.js +0 -359
- package/dist/ox/KeyAuthorization.js.map +0 -1
- package/dist/ox/Order.d.ts +0 -92
- package/dist/ox/Order.d.ts.map +0 -1
- package/dist/ox/Order.js +0 -88
- package/dist/ox/Order.js.map +0 -1
- package/dist/ox/OrdersFilters.d.ts +0 -72
- package/dist/ox/OrdersFilters.d.ts.map +0 -1
- package/dist/ox/OrdersFilters.js +0 -100
- package/dist/ox/OrdersFilters.js.map +0 -1
- package/dist/ox/Pagination.d.ts +0 -128
- package/dist/ox/Pagination.d.ts.map +0 -1
- package/dist/ox/Pagination.js +0 -78
- package/dist/ox/Pagination.js.map +0 -1
- package/dist/ox/PoolId.d.ts +0 -18
- package/dist/ox/PoolId.d.ts.map +0 -1
- package/dist/ox/PoolId.js +0 -13
- package/dist/ox/PoolId.js.map +0 -1
- package/dist/ox/RpcSchema.d.ts +0 -32
- package/dist/ox/RpcSchema.d.ts.map +0 -1
- package/dist/ox/RpcSchema.js +0 -2
- package/dist/ox/RpcSchema.js.map +0 -1
- package/dist/ox/SignatureEnvelope.d.ts +0 -260
- package/dist/ox/SignatureEnvelope.d.ts.map +0 -1
- package/dist/ox/SignatureEnvelope.js +0 -477
- package/dist/ox/SignatureEnvelope.js.map +0 -1
- package/dist/ox/Tick.d.ts +0 -115
- package/dist/ox/Tick.d.ts.map +0 -1
- package/dist/ox/Tick.js +0 -127
- package/dist/ox/Tick.js.map +0 -1
- package/dist/ox/TokenId.d.ts +0 -25
- package/dist/ox/TokenId.d.ts.map +0 -1
- package/dist/ox/TokenId.js +0 -41
- package/dist/ox/TokenId.js.map +0 -1
- package/dist/ox/TokenRole.d.ts +0 -11
- package/dist/ox/TokenRole.d.ts.map +0 -1
- package/dist/ox/TokenRole.js +0 -22
- package/dist/ox/TokenRole.js.map +0 -1
- package/dist/ox/Transaction.d.ts +0 -201
- package/dist/ox/Transaction.d.ts.map +0 -1
- package/dist/ox/Transaction.js +0 -167
- package/dist/ox/Transaction.js.map +0 -1
- package/dist/ox/TransactionEnvelopeTempo.d.ts +0 -470
- package/dist/ox/TransactionEnvelopeTempo.d.ts.map +0 -1
- package/dist/ox/TransactionEnvelopeTempo.js +0 -547
- package/dist/ox/TransactionEnvelopeTempo.js.map +0 -1
- package/dist/ox/TransactionReceipt.d.ts +0 -155
- package/dist/ox/TransactionReceipt.d.ts.map +0 -1
- package/dist/ox/TransactionReceipt.js +0 -136
- package/dist/ox/TransactionReceipt.js.map +0 -1
- package/dist/ox/TransactionRequest.d.ts +0 -76
- package/dist/ox/TransactionRequest.d.ts.map +0 -1
- package/dist/ox/TransactionRequest.js +0 -93
- package/dist/ox/TransactionRequest.js.map +0 -1
- package/dist/ox/index.d.ts +0 -14
- package/dist/ox/index.d.ts.map +0 -1
- package/dist/ox/index.js +0 -14
- package/dist/ox/index.js.map +0 -1
- package/dist/prool/Instance.d.ts +0 -101
- package/dist/prool/Instance.d.ts.map +0 -1
- package/dist/prool/Instance.js +0 -136
- package/dist/prool/Instance.js.map +0 -1
- package/dist/prool/chain.json +0 -238
- package/dist/prool/index.d.ts +0 -2
- package/dist/prool/index.d.ts.map +0 -1
- package/dist/prool/index.js +0 -2
- package/dist/prool/index.js.map +0 -1
- package/dist/viem/Actions/account.d.ts +0 -40
- package/dist/viem/Actions/account.d.ts.map +0 -1
- package/dist/viem/Actions/account.js +0 -86
- package/dist/viem/Actions/account.js.map +0 -1
- package/dist/viem/Actions/index.d.ts +0 -10
- package/dist/viem/Actions/index.d.ts.map +0 -1
- package/dist/viem/Actions/index.js +0 -10
- package/dist/viem/Actions/index.js.map +0 -1
- package/dist/viem/Decorator.d.ts +0 -2810
- package/dist/viem/Decorator.d.ts.map +0 -1
- package/dist/viem/Decorator.js +0 -138
- package/dist/viem/Decorator.js.map +0 -1
- package/dist/viem/P256.d.ts +0 -2
- package/dist/viem/P256.d.ts.map +0 -1
- package/dist/viem/P256.js +0 -2
- package/dist/viem/P256.js.map +0 -1
- package/dist/viem/Secp256k1.d.ts +0 -2
- package/dist/viem/Secp256k1.d.ts.map +0 -1
- package/dist/viem/Secp256k1.js +0 -2
- package/dist/viem/Secp256k1.js.map +0 -1
- package/dist/viem/TokenIds.d.ts +0 -2
- package/dist/viem/TokenIds.d.ts.map +0 -1
- package/dist/viem/TokenIds.js +0 -2
- package/dist/viem/TokenIds.js.map +0 -1
- package/dist/viem/index.d.ts +0 -17
- package/dist/viem/index.d.ts.map +0 -1
- package/dist/viem/index.js +0 -17
- package/dist/viem/index.js.map +0 -1
- package/src/ox/AuthorizationTempo.test.ts +0 -1256
- package/src/ox/AuthorizationTempo.ts +0 -648
- package/src/ox/KeyAuthorization.test.ts +0 -1332
- package/src/ox/KeyAuthorization.ts +0 -540
- package/src/ox/Order.test.ts +0 -78
- package/src/ox/Order.ts +0 -125
- package/src/ox/OrdersFilters.test.ts +0 -182
- package/src/ox/OrdersFilters.ts +0 -125
- package/src/ox/Pagination.test.ts +0 -162
- package/src/ox/Pagination.ts +0 -164
- package/src/ox/PoolId.test.ts +0 -33
- package/src/ox/PoolId.ts +0 -27
- package/src/ox/RpcSchema.ts +0 -35
- package/src/ox/SignatureEnvelope.test.ts +0 -1876
- package/src/ox/SignatureEnvelope.ts +0 -791
- package/src/ox/Tick.test.ts +0 -281
- package/src/ox/Tick.ts +0 -181
- package/src/ox/TokenId.test.ts +0 -40
- package/src/ox/TokenId.ts +0 -50
- package/src/ox/TokenRole.test.ts +0 -16
- package/src/ox/TokenRole.ts +0 -27
- package/src/ox/Transaction.test.ts +0 -523
- package/src/ox/Transaction.ts +0 -332
- package/src/ox/TransactionEnvelopeTempo.test.ts +0 -1352
- package/src/ox/TransactionEnvelopeTempo.ts +0 -905
- package/src/ox/TransactionReceipt.ts +0 -190
- package/src/ox/TransactionRequest.ts +0 -147
- package/src/ox/e2e.test.ts +0 -1393
- package/src/ox/index.ts +0 -13
- package/src/prool/Instance.test.ts +0 -43
- package/src/prool/Instance.ts +0 -247
- package/src/prool/chain.json +0 -238
- package/src/prool/index.ts +0 -1
- package/src/viem/Actions/__snapshots__/dex.test.ts.snap +0 -850
- package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +0 -310
- package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +0 -457
|
@@ -1,905 +0,0 @@
|
|
|
1
|
-
import * as AccessList from 'ox/AccessList'
|
|
2
|
-
import * as Address from 'ox/Address'
|
|
3
|
-
import * as Errors from 'ox/Errors'
|
|
4
|
-
import * as Hash from 'ox/Hash'
|
|
5
|
-
import * as Hex from 'ox/Hex'
|
|
6
|
-
import * as Rlp from 'ox/Rlp'
|
|
7
|
-
import * as Signature from 'ox/Signature'
|
|
8
|
-
import * as TransactionEnvelope from 'ox/TransactionEnvelope'
|
|
9
|
-
import type { OneOf } from 'viem'
|
|
10
|
-
import type {
|
|
11
|
-
Assign,
|
|
12
|
-
Compute,
|
|
13
|
-
PartialBy,
|
|
14
|
-
UnionPartialBy,
|
|
15
|
-
} from '../internal/types.js'
|
|
16
|
-
import * as AuthorizationTempo from './AuthorizationTempo.js'
|
|
17
|
-
import * as KeyAuthorization from './KeyAuthorization.js'
|
|
18
|
-
import * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
19
|
-
import * as TokenId from './TokenId.js'
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Represents a single call within a Tempo transaction.
|
|
23
|
-
*/
|
|
24
|
-
export type Call<bigintType = bigint> = {
|
|
25
|
-
/** Call data. */
|
|
26
|
-
data?: Hex.Hex | undefined
|
|
27
|
-
/** The target address or contract creation. */
|
|
28
|
-
to?: Address.Address | undefined
|
|
29
|
-
/** Value to send (in wei). */
|
|
30
|
-
value?: bigintType | undefined
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export type TransactionEnvelopeTempo<
|
|
34
|
-
signed extends boolean = boolean,
|
|
35
|
-
bigintType = bigint,
|
|
36
|
-
numberType = number,
|
|
37
|
-
type extends string = Type,
|
|
38
|
-
> = Compute<
|
|
39
|
-
{
|
|
40
|
-
/** EIP-2930 Access List. */
|
|
41
|
-
accessList?: AccessList.AccessList | undefined
|
|
42
|
-
/** EIP-7702 (Tempo) Authorization list for the transaction. */
|
|
43
|
-
authorizationList?:
|
|
44
|
-
| AuthorizationTempo.ListSigned<bigintType, numberType>
|
|
45
|
-
| undefined
|
|
46
|
-
/** Array of calls to execute. */
|
|
47
|
-
calls: readonly Call<bigintType>[]
|
|
48
|
-
/** EIP-155 Chain ID. */
|
|
49
|
-
chainId: numberType
|
|
50
|
-
/** Sender of the transaction. */
|
|
51
|
-
from?: Address.Address | undefined
|
|
52
|
-
/** Gas provided for transaction execution */
|
|
53
|
-
gas?: bigintType | undefined
|
|
54
|
-
/** Fee payer signature. */
|
|
55
|
-
feePayerSignature?:
|
|
56
|
-
| Signature.Signature<true, bigintType, numberType>
|
|
57
|
-
| null
|
|
58
|
-
| undefined
|
|
59
|
-
/** Fee token preference. Address or ID of the TIP-20 token. */
|
|
60
|
-
feeToken?: TokenId.TokenIdOrAddress | undefined
|
|
61
|
-
/**
|
|
62
|
-
* Key authorization for provisioning a new access key.
|
|
63
|
-
*
|
|
64
|
-
* When present, this transaction will add the specified key to the AccountKeychain precompile,
|
|
65
|
-
* before verifying the transaction signature.
|
|
66
|
-
* The authorization must be signed with the root key, the tx can be signed by the Keychain signature.
|
|
67
|
-
*/
|
|
68
|
-
keyAuthorization?:
|
|
69
|
-
| KeyAuthorization.Signed<bigintType, numberType>
|
|
70
|
-
| undefined
|
|
71
|
-
/** Total fee per gas in wei (gasPrice/baseFeePerGas + maxPriorityFeePerGas). */
|
|
72
|
-
maxFeePerGas?: bigintType | undefined
|
|
73
|
-
/** Max priority fee per gas (in wei). */
|
|
74
|
-
maxPriorityFeePerGas?: bigintType | undefined
|
|
75
|
-
/** Nonce key for 2D nonce system (192 bits). */
|
|
76
|
-
nonceKey?: bigintType | undefined
|
|
77
|
-
/** Unique number identifying this transaction */
|
|
78
|
-
nonce?: bigintType | undefined
|
|
79
|
-
/** Transaction type */
|
|
80
|
-
type: type
|
|
81
|
-
/** Transaction can only be included in a block before this timestamp. */
|
|
82
|
-
validBefore?: numberType | undefined
|
|
83
|
-
/** Transaction can only be included in a block after this timestamp. */
|
|
84
|
-
validAfter?: numberType | undefined
|
|
85
|
-
} & (signed extends true
|
|
86
|
-
? {
|
|
87
|
-
signature: SignatureEnvelope.SignatureEnvelope<bigintType, numberType>
|
|
88
|
-
}
|
|
89
|
-
: {
|
|
90
|
-
signature?:
|
|
91
|
-
| SignatureEnvelope.SignatureEnvelope<bigintType, numberType>
|
|
92
|
-
| undefined
|
|
93
|
-
})
|
|
94
|
-
>
|
|
95
|
-
|
|
96
|
-
export type Rpc<signed extends boolean = boolean> = TransactionEnvelopeTempo<
|
|
97
|
-
signed,
|
|
98
|
-
Hex.Hex,
|
|
99
|
-
Hex.Hex,
|
|
100
|
-
'0x76'
|
|
101
|
-
>
|
|
102
|
-
|
|
103
|
-
export const feePayerMagic = '0x78' as const
|
|
104
|
-
export type FeePayerMagic = typeof feePayerMagic
|
|
105
|
-
|
|
106
|
-
export type Serialized = `${SerializedType}${string}`
|
|
107
|
-
|
|
108
|
-
export type Signed = TransactionEnvelopeTempo<true>
|
|
109
|
-
|
|
110
|
-
export const serializedType = '0x76' as const
|
|
111
|
-
export type SerializedType = typeof serializedType
|
|
112
|
-
|
|
113
|
-
export const type = 'tempo' as const
|
|
114
|
-
export type Type = typeof type
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Asserts a {@link ox#TransactionEnvelopeTempo.TransactionEnvelopeTempo} is valid.
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```ts twoslash
|
|
121
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
122
|
-
*
|
|
123
|
-
* TransactionEnvelopeTempo.assert({
|
|
124
|
-
* calls: [{ to: '0x0000000000000000000000000000000000000000', value: 0n }],
|
|
125
|
-
* chainId: 1,
|
|
126
|
-
* maxFeePerGas: 1000000000n,
|
|
127
|
-
* })
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
* @param envelope - The transaction envelope to assert.
|
|
131
|
-
*/
|
|
132
|
-
export function assert(envelope: PartialBy<TransactionEnvelopeTempo, 'type'>) {
|
|
133
|
-
const {
|
|
134
|
-
calls,
|
|
135
|
-
chainId,
|
|
136
|
-
maxFeePerGas,
|
|
137
|
-
maxPriorityFeePerGas,
|
|
138
|
-
validBefore,
|
|
139
|
-
validAfter,
|
|
140
|
-
} = envelope
|
|
141
|
-
|
|
142
|
-
// Calls must not be empty
|
|
143
|
-
if (!calls || calls.length === 0) throw new CallsEmptyError()
|
|
144
|
-
|
|
145
|
-
// validBefore must be greater than validAfter if both are set
|
|
146
|
-
if (
|
|
147
|
-
typeof validBefore === 'number' &&
|
|
148
|
-
typeof validAfter === 'number' &&
|
|
149
|
-
validBefore <= validAfter
|
|
150
|
-
) {
|
|
151
|
-
throw new InvalidValidityWindowError({
|
|
152
|
-
validBefore: validBefore,
|
|
153
|
-
validAfter: validAfter,
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Validate each call
|
|
158
|
-
if (calls)
|
|
159
|
-
for (const call of calls)
|
|
160
|
-
if (call.to) Address.assert(call.to, { strict: false })
|
|
161
|
-
|
|
162
|
-
// Validate chain ID
|
|
163
|
-
if (chainId <= 0)
|
|
164
|
-
throw new TransactionEnvelope.InvalidChainIdError({ chainId })
|
|
165
|
-
|
|
166
|
-
// Validate max fee per gas
|
|
167
|
-
if (maxFeePerGas && BigInt(maxFeePerGas) > 2n ** 256n - 1n)
|
|
168
|
-
throw new TransactionEnvelope.FeeCapTooHighError({
|
|
169
|
-
feeCap: maxFeePerGas,
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
maxPriorityFeePerGas &&
|
|
174
|
-
maxFeePerGas &&
|
|
175
|
-
maxPriorityFeePerGas > maxFeePerGas
|
|
176
|
-
)
|
|
177
|
-
throw new TransactionEnvelope.TipAboveFeeCapError({
|
|
178
|
-
maxFeePerGas,
|
|
179
|
-
maxPriorityFeePerGas,
|
|
180
|
-
})
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export declare namespace assert {
|
|
184
|
-
type ErrorType =
|
|
185
|
-
| Address.assert.ErrorType
|
|
186
|
-
| CallsEmptyError
|
|
187
|
-
| InvalidValidityWindowError
|
|
188
|
-
| Errors.GlobalErrorType
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Deserializes a {@link ox#TransactionEnvelopeTempo.TransactionEnvelopeTempo} from its serialized form.
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* ```ts twoslash
|
|
196
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
197
|
-
*
|
|
198
|
-
* const envelope = TransactionEnvelopeTempo.deserialize('0x76f84a0182031184773594008477359400809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c0808080')
|
|
199
|
-
* // @log: {
|
|
200
|
-
* // @log: type: 'tempo',
|
|
201
|
-
* // @log: nonce: 785n,
|
|
202
|
-
* // @log: maxFeePerGas: 2000000000n,
|
|
203
|
-
* // @log: gas: 1000000n,
|
|
204
|
-
* // @log: calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n }],
|
|
205
|
-
* // @log: }
|
|
206
|
-
* ```
|
|
207
|
-
*
|
|
208
|
-
* @param serialized - The serialized transaction.
|
|
209
|
-
* @returns Deserialized Transaction Envelope.
|
|
210
|
-
*/
|
|
211
|
-
export function deserialize(
|
|
212
|
-
serialized: Serialized,
|
|
213
|
-
): Compute<TransactionEnvelopeTempo> {
|
|
214
|
-
const transactionArray = Rlp.toHex(Hex.slice(serialized, 1))
|
|
215
|
-
|
|
216
|
-
const [
|
|
217
|
-
chainId,
|
|
218
|
-
maxPriorityFeePerGas,
|
|
219
|
-
maxFeePerGas,
|
|
220
|
-
gas,
|
|
221
|
-
calls,
|
|
222
|
-
accessList,
|
|
223
|
-
nonceKey,
|
|
224
|
-
nonce,
|
|
225
|
-
validBefore,
|
|
226
|
-
validAfter,
|
|
227
|
-
feeToken,
|
|
228
|
-
feePayerSignatureOrSender,
|
|
229
|
-
authorizationList,
|
|
230
|
-
keyAuthorizationOrSignature,
|
|
231
|
-
maybeSignature,
|
|
232
|
-
] = transactionArray as readonly Hex.Hex[]
|
|
233
|
-
|
|
234
|
-
const keyAuthorization = Array.isArray(keyAuthorizationOrSignature)
|
|
235
|
-
? keyAuthorizationOrSignature
|
|
236
|
-
: undefined
|
|
237
|
-
const signature = keyAuthorization
|
|
238
|
-
? maybeSignature
|
|
239
|
-
: keyAuthorizationOrSignature
|
|
240
|
-
|
|
241
|
-
if (
|
|
242
|
-
!(
|
|
243
|
-
transactionArray.length === 13 ||
|
|
244
|
-
transactionArray.length === 14 ||
|
|
245
|
-
transactionArray.length === 15
|
|
246
|
-
)
|
|
247
|
-
)
|
|
248
|
-
throw new TransactionEnvelope.InvalidSerializedError({
|
|
249
|
-
attributes: {
|
|
250
|
-
authorizationList,
|
|
251
|
-
chainId,
|
|
252
|
-
maxPriorityFeePerGas,
|
|
253
|
-
maxFeePerGas,
|
|
254
|
-
gas,
|
|
255
|
-
calls,
|
|
256
|
-
accessList,
|
|
257
|
-
keyAuthorization,
|
|
258
|
-
nonceKey,
|
|
259
|
-
nonce,
|
|
260
|
-
validBefore,
|
|
261
|
-
validAfter,
|
|
262
|
-
feeToken,
|
|
263
|
-
feePayerSignatureOrSender,
|
|
264
|
-
...(transactionArray.length > 12
|
|
265
|
-
? {
|
|
266
|
-
signature,
|
|
267
|
-
}
|
|
268
|
-
: {}),
|
|
269
|
-
},
|
|
270
|
-
serialized,
|
|
271
|
-
type,
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
let transaction = {
|
|
275
|
-
chainId: Number(chainId),
|
|
276
|
-
type,
|
|
277
|
-
} as TransactionEnvelopeTempo
|
|
278
|
-
|
|
279
|
-
if (Hex.validate(gas) && gas !== '0x') transaction.gas = BigInt(gas)
|
|
280
|
-
if (Hex.validate(nonce))
|
|
281
|
-
transaction.nonce = nonce === '0x' ? 0n : BigInt(nonce)
|
|
282
|
-
if (Hex.validate(maxFeePerGas) && maxFeePerGas !== '0x')
|
|
283
|
-
transaction.maxFeePerGas = BigInt(maxFeePerGas)
|
|
284
|
-
if (Hex.validate(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
|
|
285
|
-
transaction.maxPriorityFeePerGas = BigInt(maxPriorityFeePerGas)
|
|
286
|
-
if (Hex.validate(nonceKey))
|
|
287
|
-
transaction.nonceKey = nonceKey === '0x' ? 0n : BigInt(nonceKey)
|
|
288
|
-
if (Hex.validate(validBefore) && validBefore !== '0x')
|
|
289
|
-
transaction.validBefore = Number(validBefore)
|
|
290
|
-
if (Hex.validate(validAfter) && validAfter !== '0x')
|
|
291
|
-
transaction.validAfter = Number(validAfter)
|
|
292
|
-
if (Hex.validate(feeToken) && feeToken !== '0x')
|
|
293
|
-
transaction.feeToken = feeToken
|
|
294
|
-
|
|
295
|
-
// Parse calls array
|
|
296
|
-
if (calls && calls !== '0x') {
|
|
297
|
-
const callsArray = calls as unknown as readonly Hex.Hex[][]
|
|
298
|
-
transaction.calls = callsArray.map((callTuple) => {
|
|
299
|
-
const [to, value, data] = callTuple
|
|
300
|
-
const call: Call = {}
|
|
301
|
-
if (to && to !== '0x') call.to = to
|
|
302
|
-
if (value && value !== '0x') call.value = BigInt(value)
|
|
303
|
-
if (data && data !== '0x') call.data = data
|
|
304
|
-
return call
|
|
305
|
-
})
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (accessList?.length !== 0 && accessList !== '0x')
|
|
309
|
-
transaction.accessList = AccessList.fromTupleList(accessList as never)
|
|
310
|
-
|
|
311
|
-
if (authorizationList?.length !== 0 && authorizationList !== '0x')
|
|
312
|
-
transaction.authorizationList = AuthorizationTempo.fromTupleList(
|
|
313
|
-
authorizationList as never,
|
|
314
|
-
)
|
|
315
|
-
|
|
316
|
-
if (
|
|
317
|
-
feePayerSignatureOrSender !== '0x' &&
|
|
318
|
-
feePayerSignatureOrSender !== undefined
|
|
319
|
-
) {
|
|
320
|
-
if (
|
|
321
|
-
feePayerSignatureOrSender === '0x00' ||
|
|
322
|
-
Address.validate(feePayerSignatureOrSender)
|
|
323
|
-
)
|
|
324
|
-
transaction.feePayerSignature = null
|
|
325
|
-
else
|
|
326
|
-
transaction.feePayerSignature = Signature.fromTuple(
|
|
327
|
-
feePayerSignatureOrSender as never,
|
|
328
|
-
)
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (keyAuthorization)
|
|
332
|
-
transaction.keyAuthorization = KeyAuthorization.fromTuple(
|
|
333
|
-
keyAuthorization as never,
|
|
334
|
-
)
|
|
335
|
-
|
|
336
|
-
const signatureEnvelope = signature
|
|
337
|
-
? SignatureEnvelope.deserialize(signature)
|
|
338
|
-
: undefined
|
|
339
|
-
if (signatureEnvelope)
|
|
340
|
-
transaction = {
|
|
341
|
-
...transaction,
|
|
342
|
-
signature: signatureEnvelope,
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
assert(transaction)
|
|
346
|
-
|
|
347
|
-
return transaction
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export declare namespace deserialize {
|
|
351
|
-
type ErrorType = Errors.GlobalErrorType
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Converts an arbitrary transaction object into a Tempo Transaction Envelope.
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```ts twoslash
|
|
359
|
-
* import { Value } from 'ox'
|
|
360
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
361
|
-
*
|
|
362
|
-
* const envelope = TransactionEnvelopeTempo.from({ // [!code focus]
|
|
363
|
-
* chainId: 1, // [!code focus]
|
|
364
|
-
* calls: [{ to: '0x0000000000000000000000000000000000000000', value: Value.fromEther('1') }], // [!code focus]
|
|
365
|
-
* maxFeePerGas: Value.fromGwei('10'), // [!code focus]
|
|
366
|
-
* maxPriorityFeePerGas: Value.fromGwei('1'), // [!code focus]
|
|
367
|
-
* }) // [!code focus]
|
|
368
|
-
* ```
|
|
369
|
-
*
|
|
370
|
-
* @example
|
|
371
|
-
* ### Attaching Signatures
|
|
372
|
-
*
|
|
373
|
-
* It is possible to attach a `signature` to the transaction envelope.
|
|
374
|
-
*
|
|
375
|
-
* ```ts twoslash
|
|
376
|
-
* // @noErrors
|
|
377
|
-
* import { Secp256k1, Value } from 'ox'
|
|
378
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
379
|
-
*
|
|
380
|
-
* const envelope = TransactionEnvelopeTempo.from({
|
|
381
|
-
* chainId: 1,
|
|
382
|
-
* calls: [{ to: '0x0000000000000000000000000000000000000000', value: Value.fromEther('1') }],
|
|
383
|
-
* maxFeePerGas: Value.fromGwei('10'),
|
|
384
|
-
* maxPriorityFeePerGas: Value.fromGwei('1'),
|
|
385
|
-
* })
|
|
386
|
-
*
|
|
387
|
-
* const signature = Secp256k1.sign({
|
|
388
|
-
* payload: TransactionEnvelopeTempo.getSignPayload(envelope),
|
|
389
|
-
* privateKey: '0x...',
|
|
390
|
-
* })
|
|
391
|
-
*
|
|
392
|
-
* const envelope_signed = TransactionEnvelopeTempo.from(envelope, { // [!code focus]
|
|
393
|
-
* signature, // [!code focus]
|
|
394
|
-
* }) // [!code focus]
|
|
395
|
-
* // @log: {
|
|
396
|
-
* // @log: chainId: 1,
|
|
397
|
-
* // @log: calls: [{ to: '0x0000000000000000000000000000000000000000', value: 1000000000000000000n }],
|
|
398
|
-
* // @log: maxFeePerGas: 10000000000n,
|
|
399
|
-
* // @log: maxPriorityFeePerGas: 1000000000n,
|
|
400
|
-
* // @log: type: 'tempo',
|
|
401
|
-
* // @log: r: 125...n,
|
|
402
|
-
* // @log: s: 642...n,
|
|
403
|
-
* // @log: yParity: 0,
|
|
404
|
-
* // @log: }
|
|
405
|
-
* ```
|
|
406
|
-
*
|
|
407
|
-
* @example
|
|
408
|
-
* ### From Serialized
|
|
409
|
-
*
|
|
410
|
-
* It is possible to instantiate a Tempo Transaction Envelope from a {@link ox#TransactionEnvelopeTempo.Serialized} value.
|
|
411
|
-
*
|
|
412
|
-
* ```ts twoslash
|
|
413
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
414
|
-
*
|
|
415
|
-
* const envelope = TransactionEnvelopeTempo.from('0x76f84a0182031184773594008477359400809470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000080c0808080')
|
|
416
|
-
* // @log: {
|
|
417
|
-
* // @log: chainId: 1,
|
|
418
|
-
* // @log: calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n }],
|
|
419
|
-
* // @log: maxFeePerGas: 10000000000n,
|
|
420
|
-
* // @log: type: 'tempo',
|
|
421
|
-
* // @log: }
|
|
422
|
-
* ```
|
|
423
|
-
*
|
|
424
|
-
* @param envelope - The transaction object to convert.
|
|
425
|
-
* @param options - Options.
|
|
426
|
-
* @returns A Tempo Transaction Envelope.
|
|
427
|
-
*/
|
|
428
|
-
export function from<
|
|
429
|
-
const envelope extends
|
|
430
|
-
| UnionPartialBy<TransactionEnvelopeTempo, 'type'>
|
|
431
|
-
| Serialized,
|
|
432
|
-
const signature extends
|
|
433
|
-
| SignatureEnvelope.SignatureEnvelope
|
|
434
|
-
| undefined = undefined,
|
|
435
|
-
>(
|
|
436
|
-
envelope:
|
|
437
|
-
| envelope
|
|
438
|
-
| UnionPartialBy<TransactionEnvelopeTempo, 'type'>
|
|
439
|
-
| Serialized,
|
|
440
|
-
options: from.Options<signature> = {},
|
|
441
|
-
): from.ReturnValue<envelope, signature> {
|
|
442
|
-
const { feePayerSignature, signature } = options
|
|
443
|
-
|
|
444
|
-
const envelope_ = (
|
|
445
|
-
typeof envelope === 'string' ? deserialize(envelope) : envelope
|
|
446
|
-
) as TransactionEnvelopeTempo
|
|
447
|
-
|
|
448
|
-
assert(envelope_)
|
|
449
|
-
|
|
450
|
-
return {
|
|
451
|
-
...envelope_,
|
|
452
|
-
...(signature ? { signature: SignatureEnvelope.from(signature) } : {}),
|
|
453
|
-
...(feePayerSignature
|
|
454
|
-
? { feePayerSignature: Signature.from(feePayerSignature) }
|
|
455
|
-
: {}),
|
|
456
|
-
type: 'tempo',
|
|
457
|
-
} as never
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
export declare namespace from {
|
|
461
|
-
type Options<
|
|
462
|
-
signature extends
|
|
463
|
-
| SignatureEnvelope.SignatureEnvelope
|
|
464
|
-
| undefined = undefined,
|
|
465
|
-
> = {
|
|
466
|
-
feePayerSignature?: Signature.Signature | null | undefined
|
|
467
|
-
signature?: signature | SignatureEnvelope.SignatureEnvelope | undefined
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
type ReturnValue<
|
|
471
|
-
envelope extends
|
|
472
|
-
| UnionPartialBy<TransactionEnvelopeTempo, 'type'>
|
|
473
|
-
| Hex.Hex = TransactionEnvelopeTempo | Hex.Hex,
|
|
474
|
-
signature extends
|
|
475
|
-
| SignatureEnvelope.SignatureEnvelope
|
|
476
|
-
| undefined = undefined,
|
|
477
|
-
> = Compute<
|
|
478
|
-
envelope extends Hex.Hex
|
|
479
|
-
? TransactionEnvelopeTempo
|
|
480
|
-
: Assign<
|
|
481
|
-
envelope,
|
|
482
|
-
(signature extends SignatureEnvelope.SignatureEnvelope
|
|
483
|
-
? { signature: SignatureEnvelope.from.ReturnValue<signature> }
|
|
484
|
-
: {}) & {
|
|
485
|
-
readonly type: 'tempo'
|
|
486
|
-
}
|
|
487
|
-
>
|
|
488
|
-
>
|
|
489
|
-
|
|
490
|
-
type ErrorType =
|
|
491
|
-
| deserialize.ErrorType
|
|
492
|
-
| assert.ErrorType
|
|
493
|
-
| Errors.GlobalErrorType
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* Serializes a {@link ox#TransactionEnvelopeTempo.TransactionEnvelopeTempo}.
|
|
498
|
-
*
|
|
499
|
-
* @example
|
|
500
|
-
* ```ts twoslash
|
|
501
|
-
* // @noErrors
|
|
502
|
-
* import { Value } from 'ox'
|
|
503
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
504
|
-
*
|
|
505
|
-
* const envelope = TransactionEnvelopeTempo.from({
|
|
506
|
-
* chainId: 1,
|
|
507
|
-
* calls: [{ to: '0x0000000000000000000000000000000000000000', value: Value.fromEther('1') }],
|
|
508
|
-
* maxFeePerGas: Value.fromGwei('10'),
|
|
509
|
-
* })
|
|
510
|
-
*
|
|
511
|
-
* const serialized = TransactionEnvelopeTempo.serialize(envelope) // [!code focus]
|
|
512
|
-
* ```
|
|
513
|
-
*
|
|
514
|
-
* @example
|
|
515
|
-
* ### Attaching Signatures
|
|
516
|
-
*
|
|
517
|
-
* It is possible to attach a `signature` to the serialized Transaction Envelope.
|
|
518
|
-
*
|
|
519
|
-
* ```ts twoslash
|
|
520
|
-
* // @noErrors
|
|
521
|
-
* import { Secp256k1, Value } from 'ox'
|
|
522
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
523
|
-
*
|
|
524
|
-
* const envelope = TransactionEnvelopeTempo.from({
|
|
525
|
-
* chainId: 1,
|
|
526
|
-
* calls: [{ to: '0x0000000000000000000000000000000000000000', value: Value.fromEther('1') }],
|
|
527
|
-
* maxFeePerGas: Value.fromGwei('10'),
|
|
528
|
-
* })
|
|
529
|
-
*
|
|
530
|
-
* const signature = Secp256k1.sign({
|
|
531
|
-
* payload: TransactionEnvelopeTempo.getSignPayload(envelope),
|
|
532
|
-
* privateKey: '0x...',
|
|
533
|
-
* })
|
|
534
|
-
*
|
|
535
|
-
* const serialized = TransactionEnvelopeTempo.serialize(envelope, { // [!code focus]
|
|
536
|
-
* signature, // [!code focus]
|
|
537
|
-
* }) // [!code focus]
|
|
538
|
-
*
|
|
539
|
-
* // ... send `serialized` transaction to JSON-RPC `eth_sendRawTransaction`
|
|
540
|
-
* ```
|
|
541
|
-
*
|
|
542
|
-
* @param envelope - The Transaction Envelope to serialize.
|
|
543
|
-
* @param options - Options.
|
|
544
|
-
* @returns The serialized Transaction Envelope.
|
|
545
|
-
*/
|
|
546
|
-
export function serialize(
|
|
547
|
-
envelope: PartialBy<TransactionEnvelopeTempo, 'type'>,
|
|
548
|
-
options: serialize.Options = {},
|
|
549
|
-
): Serialized {
|
|
550
|
-
const {
|
|
551
|
-
accessList,
|
|
552
|
-
authorizationList,
|
|
553
|
-
calls,
|
|
554
|
-
chainId,
|
|
555
|
-
feeToken,
|
|
556
|
-
gas,
|
|
557
|
-
keyAuthorization,
|
|
558
|
-
nonce,
|
|
559
|
-
nonceKey,
|
|
560
|
-
maxFeePerGas,
|
|
561
|
-
maxPriorityFeePerGas,
|
|
562
|
-
validBefore,
|
|
563
|
-
validAfter,
|
|
564
|
-
} = envelope
|
|
565
|
-
|
|
566
|
-
assert(envelope)
|
|
567
|
-
|
|
568
|
-
const accessTupleList = AccessList.toTupleList(accessList)
|
|
569
|
-
const signature = options.signature || envelope.signature
|
|
570
|
-
|
|
571
|
-
const authorizationTupleList =
|
|
572
|
-
AuthorizationTempo.toTupleList(authorizationList)
|
|
573
|
-
|
|
574
|
-
// Encode calls as RLP list of [to, value, data] tuples
|
|
575
|
-
const callsTupleList = calls.map((call) => [
|
|
576
|
-
call.to ?? '0x',
|
|
577
|
-
call.value ? Hex.fromNumber(call.value) : '0x',
|
|
578
|
-
call.data ?? '0x',
|
|
579
|
-
])
|
|
580
|
-
|
|
581
|
-
const feePayerSignatureOrSender = (() => {
|
|
582
|
-
if (options.sender) return options.sender
|
|
583
|
-
const feePayerSignature =
|
|
584
|
-
typeof options.feePayerSignature !== 'undefined'
|
|
585
|
-
? options.feePayerSignature
|
|
586
|
-
: envelope.feePayerSignature
|
|
587
|
-
if (feePayerSignature === null) return '0x00'
|
|
588
|
-
if (!feePayerSignature) return '0x'
|
|
589
|
-
return Signature.toTuple(feePayerSignature)
|
|
590
|
-
})()
|
|
591
|
-
|
|
592
|
-
const serialized = [
|
|
593
|
-
Hex.fromNumber(chainId),
|
|
594
|
-
maxPriorityFeePerGas ? Hex.fromNumber(maxPriorityFeePerGas) : '0x',
|
|
595
|
-
maxFeePerGas ? Hex.fromNumber(maxFeePerGas) : '0x',
|
|
596
|
-
gas ? Hex.fromNumber(gas) : '0x',
|
|
597
|
-
callsTupleList,
|
|
598
|
-
accessTupleList,
|
|
599
|
-
nonceKey ? Hex.fromNumber(nonceKey) : '0x',
|
|
600
|
-
nonce ? Hex.fromNumber(nonce) : '0x',
|
|
601
|
-
typeof validBefore === 'number' ? Hex.fromNumber(validBefore) : '0x',
|
|
602
|
-
typeof validAfter === 'number' ? Hex.fromNumber(validAfter) : '0x',
|
|
603
|
-
typeof feeToken === 'bigint' || typeof feeToken === 'string'
|
|
604
|
-
? TokenId.toAddress(feeToken)
|
|
605
|
-
: '0x',
|
|
606
|
-
feePayerSignatureOrSender,
|
|
607
|
-
authorizationTupleList,
|
|
608
|
-
...(keyAuthorization ? [KeyAuthorization.toTuple(keyAuthorization)] : []),
|
|
609
|
-
...(signature
|
|
610
|
-
? [SignatureEnvelope.serialize(SignatureEnvelope.from(signature))]
|
|
611
|
-
: []),
|
|
612
|
-
] as const
|
|
613
|
-
|
|
614
|
-
return Hex.concat(
|
|
615
|
-
options.format === 'feePayer' ? feePayerMagic : serializedType,
|
|
616
|
-
Rlp.fromHex(serialized),
|
|
617
|
-
) as Serialized
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
export declare namespace serialize {
|
|
621
|
-
type Options = {
|
|
622
|
-
/**
|
|
623
|
-
* Sender signature to append to the serialized envelope.
|
|
624
|
-
*/
|
|
625
|
-
signature?: SignatureEnvelope.SignatureEnvelope | undefined
|
|
626
|
-
} & OneOf<
|
|
627
|
-
| {
|
|
628
|
-
/**
|
|
629
|
-
* Sender address to cover the fee of.
|
|
630
|
-
*/
|
|
631
|
-
sender: Address.Address
|
|
632
|
-
/**
|
|
633
|
-
* Whether to serialize the transaction in the fee payer format.
|
|
634
|
-
*
|
|
635
|
-
* - If `'feePayer'`, then the transaction will be serialized in the fee payer format.
|
|
636
|
-
* - If `undefined` (default), then the transaction will be serialized in the normal format.
|
|
637
|
-
*/
|
|
638
|
-
format: 'feePayer'
|
|
639
|
-
}
|
|
640
|
-
| {
|
|
641
|
-
/**
|
|
642
|
-
* Fee payer signature or the sender to cover the fee of.
|
|
643
|
-
*
|
|
644
|
-
* - If `Signature.Signature`, then this is the fee payer signature.
|
|
645
|
-
* - If `null`, then this indicates the envelope is intended to be signed by a fee payer.
|
|
646
|
-
*/
|
|
647
|
-
feePayerSignature?: Signature.Signature | null | undefined
|
|
648
|
-
format?: undefined
|
|
649
|
-
}
|
|
650
|
-
>
|
|
651
|
-
|
|
652
|
-
type ErrorType =
|
|
653
|
-
| assert.ErrorType
|
|
654
|
-
| Hex.fromNumber.ErrorType
|
|
655
|
-
| Signature.toTuple.ErrorType
|
|
656
|
-
| Hex.concat.ErrorType
|
|
657
|
-
| Rlp.fromHex.ErrorType
|
|
658
|
-
| Errors.GlobalErrorType
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* Returns the payload to sign for a {@link ox#TransactionEnvelopeTempo.TransactionEnvelopeTempo}.
|
|
663
|
-
*
|
|
664
|
-
* @example
|
|
665
|
-
* The example below demonstrates how to compute the sign payload which can be used
|
|
666
|
-
* with ECDSA signing utilities like {@link ox#Secp256k1.(sign:function)}.
|
|
667
|
-
*
|
|
668
|
-
* ```ts twoslash
|
|
669
|
-
* // @noErrors
|
|
670
|
-
* import { Secp256k1 } from 'ox'
|
|
671
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
672
|
-
*
|
|
673
|
-
* const envelope = TransactionEnvelopeTempo.from({
|
|
674
|
-
* chainId: 1,
|
|
675
|
-
* calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n }],
|
|
676
|
-
* nonce: 0n,
|
|
677
|
-
* maxFeePerGas: 1000000000n,
|
|
678
|
-
* gas: 21000n,
|
|
679
|
-
* })
|
|
680
|
-
*
|
|
681
|
-
* const payload = TransactionEnvelopeTempo.getSignPayload(envelope) // [!code focus]
|
|
682
|
-
* // @log: '0x...'
|
|
683
|
-
*
|
|
684
|
-
* const signature = Secp256k1.sign({ payload, privateKey: '0x...' })
|
|
685
|
-
* ```
|
|
686
|
-
*
|
|
687
|
-
* @param envelope - The transaction envelope to get the sign payload for.
|
|
688
|
-
* @returns The sign payload.
|
|
689
|
-
*/
|
|
690
|
-
export function getSignPayload(
|
|
691
|
-
envelope: TransactionEnvelopeTempo,
|
|
692
|
-
): getSignPayload.ReturnValue {
|
|
693
|
-
return hash(envelope, { presign: true })
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
export declare namespace getSignPayload {
|
|
697
|
-
type ReturnValue = Hex.Hex
|
|
698
|
-
|
|
699
|
-
type ErrorType = hash.ErrorType | Errors.GlobalErrorType
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Hashes a {@link ox#TransactionEnvelopeTempo.TransactionEnvelopeTempo}. This is the "transaction hash".
|
|
704
|
-
*
|
|
705
|
-
* @example
|
|
706
|
-
* ```ts twoslash
|
|
707
|
-
* // @noErrors
|
|
708
|
-
* import { Secp256k1 } from 'ox'
|
|
709
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
710
|
-
*
|
|
711
|
-
* const envelope = TransactionEnvelopeTempo.from({
|
|
712
|
-
* chainId: 1,
|
|
713
|
-
* calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n }],
|
|
714
|
-
* nonce: 0n,
|
|
715
|
-
* maxFeePerGas: 1000000000n,
|
|
716
|
-
* gas: 21000n,
|
|
717
|
-
* })
|
|
718
|
-
*
|
|
719
|
-
* const signature = Secp256k1.sign({
|
|
720
|
-
* payload: TransactionEnvelopeTempo.getSignPayload(envelope),
|
|
721
|
-
* privateKey: '0x...'
|
|
722
|
-
* })
|
|
723
|
-
*
|
|
724
|
-
* const envelope_signed = TransactionEnvelopeTempo.from(envelope, { signature })
|
|
725
|
-
*
|
|
726
|
-
* const hash = TransactionEnvelopeTempo.hash(envelope_signed) // [!code focus]
|
|
727
|
-
* ```
|
|
728
|
-
*
|
|
729
|
-
* @param envelope - The Tempo Transaction Envelope to hash.
|
|
730
|
-
* @param options - Options.
|
|
731
|
-
* @returns The hash of the transaction envelope.
|
|
732
|
-
*/
|
|
733
|
-
export function hash<presign extends boolean = false>(
|
|
734
|
-
envelope: TransactionEnvelopeTempo<presign extends true ? false : true>,
|
|
735
|
-
options: hash.Options<presign> = {},
|
|
736
|
-
): hash.ReturnValue {
|
|
737
|
-
const serialized = serialize({
|
|
738
|
-
...envelope,
|
|
739
|
-
...(options.presign
|
|
740
|
-
? {
|
|
741
|
-
signature: undefined,
|
|
742
|
-
}
|
|
743
|
-
: {}),
|
|
744
|
-
})
|
|
745
|
-
return Hash.keccak256(serialized)
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
export declare namespace hash {
|
|
749
|
-
type Options<presign extends boolean = false> = {
|
|
750
|
-
/**
|
|
751
|
-
* Whether to hash this transaction for signing.
|
|
752
|
-
*
|
|
753
|
-
* @default false
|
|
754
|
-
*/
|
|
755
|
-
presign?: presign | boolean | undefined
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
type ReturnValue = Hex.Hex
|
|
759
|
-
|
|
760
|
-
type ErrorType =
|
|
761
|
-
| Hash.keccak256.ErrorType
|
|
762
|
-
| serialize.ErrorType
|
|
763
|
-
| Errors.GlobalErrorType
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
/**
|
|
767
|
-
* Returns the fee payer payload to sign for a {@link ox#TransactionEnvelopeTempo.TransactionEnvelopeTempo}.
|
|
768
|
-
*
|
|
769
|
-
* @example
|
|
770
|
-
* ```ts twoslash
|
|
771
|
-
* // @noErrors
|
|
772
|
-
* import { Secp256k1 } from 'ox'
|
|
773
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
774
|
-
*
|
|
775
|
-
* const envelope = TransactionEnvelopeTempo.from({
|
|
776
|
-
* chainId: 1,
|
|
777
|
-
* calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', value: 1000000000000000000n }],
|
|
778
|
-
* nonce: 0n,
|
|
779
|
-
* maxFeePerGas: 1000000000n,
|
|
780
|
-
* gas: 21000n,
|
|
781
|
-
* })
|
|
782
|
-
*
|
|
783
|
-
* const payload = TransactionEnvelopeTempo.getFeePayerSignPayload(envelope, {
|
|
784
|
-
* sender: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045'
|
|
785
|
-
* }) // [!code focus]
|
|
786
|
-
* // @log: '0x...'
|
|
787
|
-
*
|
|
788
|
-
* const signature = Secp256k1.sign({ payload, privateKey: '0x...' })
|
|
789
|
-
* ```
|
|
790
|
-
*
|
|
791
|
-
* @param envelope - The transaction envelope to get the fee payer sign payload for.
|
|
792
|
-
* @param options - Options.
|
|
793
|
-
* @returns The fee payer sign payload.
|
|
794
|
-
*/
|
|
795
|
-
export function getFeePayerSignPayload(
|
|
796
|
-
envelope: TransactionEnvelopeTempo,
|
|
797
|
-
options: getFeePayerSignPayload.Options,
|
|
798
|
-
): getFeePayerSignPayload.ReturnValue {
|
|
799
|
-
const { sender } = options
|
|
800
|
-
const serialized = serialize(
|
|
801
|
-
{ ...envelope, signature: undefined },
|
|
802
|
-
{
|
|
803
|
-
sender,
|
|
804
|
-
format: 'feePayer',
|
|
805
|
-
},
|
|
806
|
-
)
|
|
807
|
-
return Hash.keccak256(serialized)
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
export declare namespace getFeePayerSignPayload {
|
|
811
|
-
type Options = {
|
|
812
|
-
/**
|
|
813
|
-
* Sender address to cover the fee of.
|
|
814
|
-
*/
|
|
815
|
-
sender: Address.Address
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
type ReturnValue = Hex.Hex
|
|
819
|
-
|
|
820
|
-
type ErrorType = hash.ErrorType | Errors.GlobalErrorType
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
/**
|
|
824
|
-
* Validates a {@link ox#TransactionEnvelopeTempo.TransactionEnvelopeTempo}. Returns `true` if the envelope is valid, `false` otherwise.
|
|
825
|
-
*
|
|
826
|
-
* @example
|
|
827
|
-
* ```ts twoslash
|
|
828
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
829
|
-
*
|
|
830
|
-
* const valid = TransactionEnvelopeTempo.validate({
|
|
831
|
-
* calls: [{ to: '0x0000000000000000000000000000000000000000', value: 0n }],
|
|
832
|
-
* chainId: 1,
|
|
833
|
-
* maxFeePerGas: 1000000000n,
|
|
834
|
-
* })
|
|
835
|
-
* // @log: true
|
|
836
|
-
* ```
|
|
837
|
-
*
|
|
838
|
-
* @param envelope - The transaction envelope to validate.
|
|
839
|
-
*/
|
|
840
|
-
export function validate(
|
|
841
|
-
envelope: PartialBy<TransactionEnvelopeTempo, 'type'>,
|
|
842
|
-
) {
|
|
843
|
-
try {
|
|
844
|
-
assert(envelope)
|
|
845
|
-
return true
|
|
846
|
-
} catch {
|
|
847
|
-
return false
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
|
|
851
|
-
export declare namespace validate {
|
|
852
|
-
type ErrorType = Errors.GlobalErrorType
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
/**
|
|
856
|
-
* Thrown when a transaction's calls list is empty.
|
|
857
|
-
*
|
|
858
|
-
* @example
|
|
859
|
-
* ```ts twoslash
|
|
860
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
861
|
-
*
|
|
862
|
-
* TransactionEnvelopeTempo.assert({
|
|
863
|
-
* calls: [],
|
|
864
|
-
* chainId: 1,
|
|
865
|
-
* })
|
|
866
|
-
* // @error: TransactionEnvelopeTempo.CallsEmptyError: Calls list cannot be empty.
|
|
867
|
-
* ```
|
|
868
|
-
*/
|
|
869
|
-
export class CallsEmptyError extends Errors.BaseError {
|
|
870
|
-
override readonly name = 'TransactionEnvelopeTempo.CallsEmptyError'
|
|
871
|
-
constructor() {
|
|
872
|
-
super('Calls list cannot be empty.')
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
/**
|
|
877
|
-
* Thrown when validBefore is not greater than validAfter.
|
|
878
|
-
*
|
|
879
|
-
* @example
|
|
880
|
-
* ```ts twoslash
|
|
881
|
-
* import { TransactionEnvelopeTempo } from 'ox/tempo'
|
|
882
|
-
*
|
|
883
|
-
* TransactionEnvelopeTempo.assert({
|
|
884
|
-
* calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
885
|
-
* chainId: 1,
|
|
886
|
-
* validBefore: 100n,
|
|
887
|
-
* validAfter: 200n,
|
|
888
|
-
* })
|
|
889
|
-
* // @error: TransactionEnvelopeTempo.InvalidValidityWindowError: validBefore (100) must be greater than validAfter (200).
|
|
890
|
-
* ```
|
|
891
|
-
*/
|
|
892
|
-
export class InvalidValidityWindowError extends Errors.BaseError {
|
|
893
|
-
override readonly name = 'TransactionEnvelopeTempo.InvalidValidityWindowError'
|
|
894
|
-
constructor({
|
|
895
|
-
validBefore,
|
|
896
|
-
validAfter,
|
|
897
|
-
}: {
|
|
898
|
-
validBefore: number
|
|
899
|
-
validAfter: number
|
|
900
|
-
}) {
|
|
901
|
-
super(
|
|
902
|
-
`validBefore (${validBefore}) must be greater than validAfter (${validAfter}).`,
|
|
903
|
-
)
|
|
904
|
-
}
|
|
905
|
-
}
|