viem 1.18.9 → 1.19.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 +16 -0
- package/README.md +1 -1
- package/_cjs/actions/test/dumpState.js +10 -0
- package/_cjs/actions/test/dumpState.js.map +1 -0
- package/_cjs/actions/test/loadState.js +11 -0
- package/_cjs/actions/test/loadState.js.map +1 -0
- package/_cjs/chains/definitions/lukso.js +31 -0
- package/_cjs/chains/definitions/lukso.js.map +1 -0
- package/_cjs/chains/index.js +5 -3
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/decorators/test.js +4 -0
- package/_cjs/clients/decorators/test.js.map +1 -1
- package/_cjs/constants/bytes.js +5 -0
- package/_cjs/constants/bytes.js.map +1 -0
- package/_cjs/constants/strings.js +5 -0
- package/_cjs/constants/strings.js.map +1 -0
- package/_cjs/errors/node.js +11 -11
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/rpc.js +18 -18
- package/_cjs/errors/rpc.js.map +1 -1
- package/_cjs/index.js +10 -6
- package/_cjs/index.js.map +1 -1
- package/_cjs/utils/formatters/transaction.js +14 -0
- package/_cjs/utils/formatters/transaction.js.map +1 -1
- package/_cjs/utils/signature/hashMessage.js +2 -1
- package/_cjs/utils/signature/hashMessage.js.map +1 -1
- package/_cjs/utils/transaction/serializeTransaction.js +20 -4
- package/_cjs/utils/transaction/serializeTransaction.js.map +1 -1
- package/_esm/actions/test/dumpState.js +26 -0
- package/_esm/actions/test/dumpState.js.map +1 -0
- package/_esm/actions/test/loadState.js +27 -0
- package/_esm/actions/test/loadState.js.map +1 -0
- package/_esm/chains/definitions/lukso.js +28 -0
- package/_esm/chains/definitions/lukso.js.map +1 -0
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/decorators/test.js +4 -0
- package/_esm/clients/decorators/test.js.map +1 -1
- package/_esm/constants/bytes.js +2 -0
- package/_esm/constants/bytes.js.map +1 -0
- package/_esm/constants/strings.js +2 -0
- package/_esm/constants/strings.js.map +1 -0
- package/_esm/errors/node.js +22 -11
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/rpc.js +36 -18
- package/_esm/errors/rpc.js.map +1 -1
- package/_esm/index.js +2 -0
- package/_esm/index.js.map +1 -1
- package/_esm/utils/formatters/transaction.js +16 -0
- package/_esm/utils/formatters/transaction.js.map +1 -1
- package/_esm/utils/signature/hashMessage.js +2 -1
- package/_esm/utils/signature/hashMessage.js.map +1 -1
- package/_esm/utils/transaction/serializeTransaction.js +20 -6
- package/_esm/utils/transaction/serializeTransaction.js.map +1 -1
- package/_types/actions/test/dumpState.d.ts +31 -0
- package/_types/actions/test/dumpState.d.ts.map +1 -0
- package/_types/actions/test/loadState.d.ts +34 -0
- package/_types/actions/test/loadState.d.ts.map +1 -0
- package/_types/chains/celo/formatters.d.ts +24 -13
- package/_types/chains/celo/formatters.d.ts.map +1 -1
- package/_types/chains/definitions/base.d.ts +18 -10
- package/_types/chains/definitions/base.d.ts.map +1 -1
- package/_types/chains/definitions/baseGoerli.d.ts +18 -10
- package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/baseSepolia.d.ts +18 -10
- package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/celo.d.ts +24 -13
- package/_types/chains/definitions/celo.d.ts.map +1 -1
- package/_types/chains/definitions/celoAlfajores.d.ts +24 -13
- package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
- package/_types/chains/definitions/celoCannoli.d.ts +24 -13
- package/_types/chains/definitions/celoCannoli.d.ts.map +1 -1
- package/_types/chains/definitions/lukso.d.ts +27 -0
- package/_types/chains/definitions/lukso.d.ts.map +1 -0
- package/_types/chains/definitions/optimism.d.ts +18 -10
- package/_types/chains/definitions/optimism.d.ts.map +1 -1
- package/_types/chains/definitions/optimismGoerli.d.ts +18 -10
- package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/optimismSepolia.d.ts +18 -10
- package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/zkSync.d.ts +11 -0
- package/_types/chains/definitions/zkSync.d.ts.map +1 -1
- package/_types/chains/definitions/zkSyncTestnet.d.ts +11 -0
- package/_types/chains/definitions/zkSyncTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/zora.d.ts +18 -10
- package/_types/chains/definitions/zora.d.ts.map +1 -1
- package/_types/chains/definitions/zoraSepolia.d.ts +18 -10
- package/_types/chains/definitions/zoraSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/zoraTestnet.d.ts +18 -10
- package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/chains/optimism/formatters.d.ts +18 -10
- package/_types/chains/optimism/formatters.d.ts.map +1 -1
- package/_types/chains/zksync/formatters.d.ts +11 -0
- package/_types/chains/zksync/formatters.d.ts.map +1 -1
- package/_types/clients/decorators/test.d.ts +41 -0
- package/_types/clients/decorators/test.d.ts.map +1 -1
- package/_types/constants/bytes.d.ts +2 -0
- package/_types/constants/bytes.d.ts.map +1 -0
- package/_types/constants/strings.d.ts +2 -0
- package/_types/constants/strings.d.ts.map +1 -0
- package/_types/index.d.ts +2 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +16 -0
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/types/rpc.d.ts +2 -2
- package/_types/types/rpc.d.ts.map +1 -1
- package/_types/types/transaction.d.ts +10 -1
- package/_types/types/transaction.d.ts.map +1 -1
- package/_types/types/utils.d.ts +8 -0
- package/_types/types/utils.d.ts.map +1 -1
- package/_types/utils/formatters/transaction.d.ts +1 -1
- package/_types/utils/formatters/transaction.d.ts.map +1 -1
- package/_types/utils/formatters/transactionRequest.d.ts +1 -1
- package/_types/utils/signature/hashMessage.d.ts.map +1 -1
- package/_types/utils/transaction/serializeTransaction.d.ts.map +1 -1
- package/actions/test/dumpState.ts +44 -0
- package/actions/test/loadState.ts +47 -0
- package/chains/definitions/lukso.ts +28 -0
- package/chains/index.ts +1 -0
- package/clients/decorators/test.ts +50 -0
- package/constants/bytes.ts +2 -0
- package/constants/strings.ts +1 -0
- package/index.ts +2 -0
- package/package.json +1 -1
- package/types/eip1193.ts +16 -0
- package/types/rpc.ts +15 -6
- package/types/transaction.ts +10 -1
- package/types/utils.ts +11 -0
- package/utils/formatters/transaction.ts +17 -2
- package/utils/signature/hashMessage.ts +2 -1
- package/utils/transaction/serializeTransaction.ts +18 -12
@@ -0,0 +1 @@
|
|
1
|
+
export const presignMessagePrefix = '\x19Ethereum Signed Message:\n'
|
package/index.ts
CHANGED
@@ -582,6 +582,8 @@ export {
|
|
582
582
|
minInt248,
|
583
583
|
minInt256,
|
584
584
|
} from './constants/number.js'
|
585
|
+
export { zeroHash } from './constants/bytes.js'
|
586
|
+
export { presignMessagePrefix } from './constants/strings.js'
|
585
587
|
export {
|
586
588
|
AbiConstructorNotFoundError,
|
587
589
|
type AbiConstructorNotFoundErrorType,
|
package/package.json
CHANGED
package/types/eip1193.ts
CHANGED
@@ -707,6 +707,14 @@ export type TestRpcSchema<TMode extends string> = [
|
|
707
707
|
Parameters: [hash: Hash]
|
708
708
|
ReturnType: void
|
709
709
|
},
|
710
|
+
/**
|
711
|
+
* @description Serializes the current state (including contracts code, contract's storage, accounts properties, etc.) into a savable data blob.
|
712
|
+
*/
|
713
|
+
{
|
714
|
+
Method: `${TMode}_dumpState`
|
715
|
+
Parameters?: undefined
|
716
|
+
ReturnType: Hex
|
717
|
+
},
|
710
718
|
/**
|
711
719
|
* @description Turn on call traces for transactions that are returned to the user when they execute a transaction (instead of just txhash/receipt).
|
712
720
|
*/
|
@@ -733,6 +741,14 @@ export type TestRpcSchema<TMode extends string> = [
|
|
733
741
|
Parameters?: undefined
|
734
742
|
ReturnType: boolean
|
735
743
|
},
|
744
|
+
/**
|
745
|
+
* @description Adds state previously dumped with `dumpState` to the current chain.
|
746
|
+
*/
|
747
|
+
{
|
748
|
+
Method: `${TMode}_loadState`
|
749
|
+
Parameters?: [Hex]
|
750
|
+
ReturnType: void
|
751
|
+
},
|
736
752
|
/**
|
737
753
|
* @description Advance the block number of the network by a certain number of blocks
|
738
754
|
* @link https://hardhat.org/hardhat-network/docs/reference#hardhat_mine
|
package/types/rpc.ts
CHANGED
@@ -17,7 +17,7 @@ import type {
|
|
17
17
|
TransactionRequestEIP2930,
|
18
18
|
TransactionRequestLegacy,
|
19
19
|
} from './transaction.js'
|
20
|
-
import type { UnionOmit } from './utils.js'
|
20
|
+
import type { UnionOmit, UnionPartialBy } from './utils.js'
|
21
21
|
|
22
22
|
export type Index = `0x${string}`
|
23
23
|
export type Quantity = `0x${string}`
|
@@ -46,9 +46,18 @@ export type RpcTransactionRequest =
|
|
46
46
|
| TransactionRequestLegacy<Quantity, Index, '0x0'>
|
47
47
|
| TransactionRequestEIP2930<Quantity, Index, '0x1'>
|
48
48
|
| TransactionRequestEIP1559<Quantity, Index, '0x2'>
|
49
|
-
export type RpcTransaction<
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
'
|
49
|
+
export type RpcTransaction<
|
50
|
+
TPending extends boolean = boolean,
|
51
|
+
// `yParity` is optional on the RPC type as some nodes do not return it
|
52
|
+
// for 1559 & 2930 transactions (they should!).
|
53
|
+
_optionalProperties extends 'yParity' = 'yParity',
|
54
|
+
_excludedProperties extends string = 'typeHex',
|
55
|
+
> = UnionOmit<
|
56
|
+
UnionPartialBy<
|
57
|
+
| TransactionLegacy<Quantity, Index, TPending, '0x0'>
|
58
|
+
| TransactionEIP2930<Quantity, Index, TPending, '0x1'>
|
59
|
+
| TransactionEIP1559<Quantity, Index, TPending, '0x2'>,
|
60
|
+
_optionalProperties
|
61
|
+
>,
|
62
|
+
_excludedProperties
|
54
63
|
>
|
package/types/transaction.ts
CHANGED
@@ -80,16 +80,21 @@ export type TransactionBase<
|
|
80
80
|
v: TQuantity
|
81
81
|
/** Value in wei sent with this transaction */
|
82
82
|
value: TQuantity
|
83
|
+
/** The parity of the y-value of the secp256k1 signature. */
|
84
|
+
yParity: TIndex
|
83
85
|
}
|
84
86
|
export type TransactionLegacy<
|
85
87
|
TQuantity = bigint,
|
86
88
|
TIndex = number,
|
87
89
|
TPending extends boolean = boolean,
|
88
90
|
TType = 'legacy',
|
89
|
-
> = TransactionBase<TQuantity, TIndex, TPending> &
|
91
|
+
> = Omit<TransactionBase<TQuantity, TIndex, TPending>, 'yParity'> &
|
90
92
|
FeeValuesLegacy<TQuantity> & {
|
93
|
+
/** EIP-2930 Access List. */
|
91
94
|
accessList?: never
|
95
|
+
/** Chain ID that this transaction is valid on. */
|
92
96
|
chainId?: TIndex
|
97
|
+
yParity?: never
|
93
98
|
type: TType
|
94
99
|
}
|
95
100
|
export type TransactionEIP2930<
|
@@ -99,7 +104,9 @@ export type TransactionEIP2930<
|
|
99
104
|
TType = 'eip2930',
|
100
105
|
> = TransactionBase<TQuantity, TIndex, TPending> &
|
101
106
|
FeeValuesLegacy<TQuantity> & {
|
107
|
+
/** EIP-2930 Access List. */
|
102
108
|
accessList: AccessList
|
109
|
+
/** Chain ID that this transaction is valid on. */
|
103
110
|
chainId: TIndex
|
104
111
|
type: TType
|
105
112
|
}
|
@@ -110,7 +117,9 @@ export type TransactionEIP1559<
|
|
110
117
|
TType = 'eip1559',
|
111
118
|
> = TransactionBase<TQuantity, TIndex, TPending> &
|
112
119
|
FeeValuesEIP1559<TQuantity> & {
|
120
|
+
/** EIP-2930 Access List. */
|
113
121
|
accessList: AccessList
|
122
|
+
/** Chain ID that this transaction is valid on. */
|
114
123
|
chainId: TIndex
|
115
124
|
type: TType
|
116
125
|
}
|
package/types/utils.ts
CHANGED
@@ -194,6 +194,17 @@ export type UnionOmit<T, K extends keyof any> = T extends any
|
|
194
194
|
*/
|
195
195
|
export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
|
196
196
|
|
197
|
+
/**
|
198
|
+
* @description Creates a type that is a partial of T, but with the required keys K.
|
199
|
+
*
|
200
|
+
* @example
|
201
|
+
* PartialBy<{ a: string, b: number } | { a: string, b: undefined, c: number }, 'a'>
|
202
|
+
* => { a?: string, b: number } | { a?: string, b: undefined, c: number }
|
203
|
+
*/
|
204
|
+
export type UnionPartialBy<T, K extends keyof T> = T extends any
|
205
|
+
? PartialBy<T, K>
|
206
|
+
: never
|
207
|
+
|
197
208
|
/**
|
198
209
|
* @description Combines members of an intersection into a readable type.
|
199
210
|
*
|
@@ -68,18 +68,33 @@ export function formatTransaction(transaction: Partial<RpcTransaction>) {
|
|
68
68
|
typeHex: transaction.type ? transaction.type : undefined,
|
69
69
|
value: transaction.value ? BigInt(transaction.value) : undefined,
|
70
70
|
v: transaction.v ? BigInt(transaction.v) : undefined,
|
71
|
-
}
|
71
|
+
} as Transaction
|
72
|
+
|
73
|
+
transaction_.yParity = (() => {
|
74
|
+
// If `yParity` is provided, we will use it.
|
75
|
+
if (transaction.yParity) return Number(transaction.yParity)
|
76
|
+
|
77
|
+
// If no `yParity` provided, try derive from `v`.
|
78
|
+
if (typeof transaction_.v === 'bigint') {
|
79
|
+
if (transaction_.v === 0n || transaction_.v === 27n) return 0
|
80
|
+
if (transaction_.v === 1n || transaction_.v === 28n) return 1
|
81
|
+
if (transaction_.v >= 35n) return transaction_.v % 2n === 0n ? 1 : 0
|
82
|
+
}
|
83
|
+
|
84
|
+
return undefined
|
85
|
+
})()
|
72
86
|
|
73
87
|
if (transaction_.type === 'legacy') {
|
74
88
|
delete transaction_.accessList
|
75
89
|
delete transaction_.maxFeePerGas
|
76
90
|
delete transaction_.maxPriorityFeePerGas
|
91
|
+
delete transaction_.yParity
|
77
92
|
}
|
78
93
|
if (transaction_.type === 'eip2930') {
|
79
94
|
delete transaction_.maxFeePerGas
|
80
95
|
delete transaction_.maxPriorityFeePerGas
|
81
96
|
}
|
82
|
-
return transaction_
|
97
|
+
return transaction_
|
83
98
|
}
|
84
99
|
|
85
100
|
export type DefineTransactionErrorType = DefineFormatterErrorType | ErrorType
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { presignMessagePrefix } from '../../constants/strings.js'
|
1
2
|
import type { ErrorType } from '../../errors/utils.js'
|
2
3
|
import type { ByteArray, Hex, SignableMessage } from '../../types/misc.js'
|
3
4
|
import { type ConcatErrorType, concat } from '../data/concat.js'
|
@@ -32,7 +33,7 @@ export function hashMessage<TTo extends To = 'hex'>(
|
|
32
33
|
return toBytes(message.raw)
|
33
34
|
})()
|
34
35
|
const prefixBytes = stringToBytes(
|
35
|
-
|
36
|
+
`${presignMessagePrefix}${messageBytes.length}`,
|
36
37
|
)
|
37
38
|
return keccak256(concat([prefixBytes, messageBytes]), to_)
|
38
39
|
}
|
@@ -121,12 +121,15 @@ function serializeTransactionEIP1559(
|
|
121
121
|
serializedAccessList,
|
122
122
|
]
|
123
123
|
|
124
|
-
if (signature)
|
125
|
-
|
126
|
-
signature.v ===
|
127
|
-
|
128
|
-
|
129
|
-
|
124
|
+
if (signature) {
|
125
|
+
const yParity = (() => {
|
126
|
+
if (signature.v === 0n) return '0x'
|
127
|
+
if (signature.v === 1n) return toHex(1)
|
128
|
+
|
129
|
+
return signature.v === 27n ? '0x' : toHex(1)
|
130
|
+
})()
|
131
|
+
serializedTransaction.push(yParity, trim(signature.r), trim(signature.s))
|
132
|
+
}
|
130
133
|
|
131
134
|
return concatHex([
|
132
135
|
'0x02',
|
@@ -165,12 +168,15 @@ function serializeTransactionEIP2930(
|
|
165
168
|
serializedAccessList,
|
166
169
|
]
|
167
170
|
|
168
|
-
if (signature)
|
169
|
-
|
170
|
-
signature.v ===
|
171
|
-
signature.
|
172
|
-
|
173
|
-
|
171
|
+
if (signature) {
|
172
|
+
const yParity = (() => {
|
173
|
+
if (signature.v === 0n) return '0x'
|
174
|
+
if (signature.v === 1n) return toHex(1)
|
175
|
+
|
176
|
+
return signature.v === 27n ? '0x' : toHex(1)
|
177
|
+
})()
|
178
|
+
serializedTransaction.push(yParity, trim(signature.r), trim(signature.s))
|
179
|
+
}
|
174
180
|
|
175
181
|
return concatHex([
|
176
182
|
'0x01',
|