quantumcoin 6.14.2 → 6.14.5
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 +442 -442
- package/FUNDING.json +10 -10
- package/LICENSE.md +21 -21
- package/README.md +132 -142
- package/SECURITY.md +34 -34
- package/dist/README.md +22 -22
- package/dist/quantumcoin.js +1127 -1324
- package/dist/quantumcoin.js.map +1 -1
- package/dist/quantumcoin.min.js +1 -1
- package/dist/quantumcoin.umd.js +1128 -1327
- package/dist/quantumcoin.umd.js.map +1 -1
- package/dist/quantumcoin.umd.min.js +1 -1
- package/dist/wordlists-extra.js +1 -1
- package/dist/wordlists-extra.js.map +1 -1
- package/dist/wordlists-extra.min.js +1 -1
- package/lib.commonjs/README.md +16 -16
- package/lib.commonjs/_version.js +1 -1
- package/lib.commonjs/crypto/signature.d.ts +3 -76
- package/lib.commonjs/crypto/signature.d.ts.map +1 -1
- package/lib.commonjs/crypto/signature.js +15 -199
- package/lib.commonjs/crypto/signature.js.map +1 -1
- package/lib.commonjs/crypto/signing-key.d.ts +1 -1
- package/lib.commonjs/crypto/signing-key.d.ts.map +1 -1
- package/lib.commonjs/crypto/signing-key.js +19 -10
- package/lib.commonjs/crypto/signing-key.js.map +1 -1
- package/lib.commonjs/package.json +12 -12
- package/lib.commonjs/providers/provider-jsonrpc.d.ts +0 -1
- package/lib.commonjs/providers/provider-jsonrpc.d.ts.map +1 -1
- package/lib.commonjs/providers/provider-jsonrpc.js +0 -1
- package/lib.commonjs/providers/provider-jsonrpc.js.map +1 -1
- package/lib.commonjs/quantumcoin.d.ts +2 -0
- package/lib.commonjs/quantumcoin.d.ts.map +1 -1
- package/lib.commonjs/quantumcoin.js +11 -5
- package/lib.commonjs/quantumcoin.js.map +1 -1
- package/lib.commonjs/transaction/address.d.ts.map +1 -1
- package/lib.commonjs/transaction/address.js +8 -3
- package/lib.commonjs/transaction/address.js.map +1 -1
- package/lib.commonjs/transaction/transaction.d.ts.map +1 -1
- package/lib.commonjs/transaction/transaction.js +7 -40
- package/lib.commonjs/transaction/transaction.js.map +1 -1
- package/lib.commonjs/wallet/json-keystore.d.ts.map +1 -1
- package/lib.commonjs/wallet/json-keystore.js +7 -7
- package/lib.commonjs/wallet/json-keystore.js.map +1 -1
- package/lib.commonjs/wallet/wallet.d.ts.map +1 -1
- package/lib.commonjs/wallet/wallet.js +2 -2
- package/lib.commonjs/wallet/wallet.js.map +1 -1
- package/lib.esm/README.md +16 -16
- package/lib.esm/_version.js +1 -1
- package/lib.esm/crypto/signature.d.ts +3 -76
- package/lib.esm/crypto/signature.d.ts.map +1 -1
- package/lib.esm/crypto/signature.js +16 -202
- package/lib.esm/crypto/signature.js.map +1 -1
- package/lib.esm/crypto/signing-key.d.ts +1 -1
- package/lib.esm/crypto/signing-key.d.ts.map +1 -1
- package/lib.esm/crypto/signing-key.js +20 -9
- package/lib.esm/crypto/signing-key.js.map +1 -1
- package/lib.esm/package.json +12 -12
- package/lib.esm/providers/provider-jsonrpc.d.ts +0 -1
- package/lib.esm/providers/provider-jsonrpc.d.ts.map +1 -1
- package/lib.esm/providers/provider-jsonrpc.js +0 -1
- package/lib.esm/providers/provider-jsonrpc.js.map +1 -1
- package/lib.esm/quantumcoin.d.ts +2 -0
- package/lib.esm/quantumcoin.d.ts.map +1 -1
- package/lib.esm/quantumcoin.js +6 -0
- package/lib.esm/quantumcoin.js.map +1 -1
- package/lib.esm/transaction/address.d.ts.map +1 -1
- package/lib.esm/transaction/address.js +8 -2
- package/lib.esm/transaction/address.js.map +1 -1
- package/lib.esm/transaction/transaction.d.ts.map +1 -1
- package/lib.esm/transaction/transaction.js +7 -40
- package/lib.esm/transaction/transaction.js.map +1 -1
- package/lib.esm/wallet/json-keystore.d.ts.map +1 -1
- package/lib.esm/wallet/json-keystore.js +11 -5
- package/lib.esm/wallet/json-keystore.js.map +1 -1
- package/lib.esm/wallet/wallet.d.ts.map +1 -1
- package/lib.esm/wallet/wallet.js +3 -1
- package/lib.esm/wallet/wallet.js.map +1 -1
- package/package.json +6 -5
- package/rollup.config.mjs +50 -50
- package/src.ts/_version.ts +1 -1
- package/src.ts/abi/abi-coder.ts +237 -237
- package/src.ts/abi/bytes32.ts +45 -45
- package/src.ts/abi/coders/abstract-coder.ts +541 -541
- package/src.ts/abi/coders/address.ts +36 -36
- package/src.ts/abi/coders/anonymous.ts +29 -29
- package/src.ts/abi/coders/array.ts +199 -199
- package/src.ts/abi/coders/boolean.ts +27 -27
- package/src.ts/abi/coders/bytes.ts +43 -43
- package/src.ts/abi/coders/fixed-bytes.ts +37 -37
- package/src.ts/abi/coders/null.ts +28 -28
- package/src.ts/abi/coders/number.ts +63 -63
- package/src.ts/abi/coders/string.ts +29 -29
- package/src.ts/abi/coders/tuple.ts +69 -69
- package/src.ts/abi/fragments.ts +1617 -1617
- package/src.ts/abi/index.ts +41 -41
- package/src.ts/abi/interface.ts +1271 -1271
- package/src.ts/abi/typed.ts +796 -796
- package/src.ts/address/address.ts +148 -148
- package/src.ts/address/checks.ts +123 -123
- package/src.ts/address/contract-address.ts +80 -80
- package/src.ts/address/index.ts +57 -57
- package/src.ts/constants/addresses.ts +8 -8
- package/src.ts/constants/hashes.ts +7 -7
- package/src.ts/constants/index.ts +16 -16
- package/src.ts/constants/numbers.ts +35 -35
- package/src.ts/constants/strings.ts +16 -16
- package/src.ts/contract/contract.ts +1120 -1120
- package/src.ts/contract/factory.ts +143 -143
- package/src.ts/contract/index.ts +31 -31
- package/src.ts/contract/types.ts +236 -236
- package/src.ts/contract/wrappers.ts +225 -225
- package/src.ts/crypto/crypto-browser.ts +64 -64
- package/src.ts/crypto/crypto.ts +4 -4
- package/src.ts/crypto/hmac.ts +51 -51
- package/src.ts/crypto/index.ts +59 -59
- package/src.ts/crypto/keccak.ts +54 -54
- package/src.ts/crypto/pbkdf2.ts +55 -55
- package/src.ts/crypto/random.ts +36 -36
- package/src.ts/crypto/ripemd160.ts +43 -43
- package/src.ts/crypto/scrypt.ts +114 -114
- package/src.ts/crypto/sha2.ts +78 -78
- package/src.ts/crypto/signature.ts +145 -349
- package/src.ts/crypto/signing-key.ts +126 -118
- package/src.ts/hash/authorization.ts +38 -38
- package/src.ts/hash/id.ts +17 -17
- package/src.ts/hash/index.ts +18 -18
- package/src.ts/hash/message.ts +51 -51
- package/src.ts/hash/namehash.ts +101 -101
- package/src.ts/hash/solidity.ts +117 -117
- package/src.ts/hash/typed-data.ts +658 -658
- package/src.ts/index.ts +12 -12
- package/src.ts/providers/abstract-provider.ts +1761 -1761
- package/src.ts/providers/abstract-signer.ts +314 -314
- package/src.ts/providers/community.ts +49 -49
- package/src.ts/providers/contracts.ts +42 -42
- package/src.ts/providers/default-provider.ts +96 -96
- package/src.ts/providers/ens-resolver.ts +606 -606
- package/src.ts/providers/format.ts +320 -320
- package/src.ts/providers/formatting.ts +418 -418
- package/src.ts/providers/index.ts +125 -125
- package/src.ts/providers/network.ts +327 -327
- package/src.ts/providers/pagination.ts +8 -8
- package/src.ts/providers/plugin-fallback.ts +35 -35
- package/src.ts/providers/plugins-network.ts +281 -281
- package/src.ts/providers/provider-browser.ts +334 -334
- package/src.ts/providers/provider-fallback.ts +801 -801
- package/src.ts/providers/provider-ipcsocket-browser.ts +3 -3
- package/src.ts/providers/provider-ipcsocket.ts +81 -81
- package/src.ts/providers/provider-jsonrpc.ts +1334 -1335
- package/src.ts/providers/provider-socket.ts +352 -352
- package/src.ts/providers/provider-websocket.ts +103 -103
- package/src.ts/providers/provider.ts +2136 -2136
- package/src.ts/providers/signer-noncemanager.ts +98 -98
- package/src.ts/providers/signer.ts +166 -166
- package/src.ts/providers/subscriber-connection.ts +74 -74
- package/src.ts/providers/subscriber-filterid.ts +199 -199
- package/src.ts/providers/subscriber-polling.ts +321 -321
- package/src.ts/providers/ws-browser.ts +11 -11
- package/src.ts/providers/ws.ts +3 -3
- package/src.ts/quantumcoin.ts +219 -211
- package/src.ts/thirdparty.d.ts +16 -16
- package/src.ts/transaction/accesslist.ts +43 -43
- package/src.ts/transaction/address.ts +35 -31
- package/src.ts/transaction/authorization.ts +14 -14
- package/src.ts/transaction/index.ts +51 -51
- package/src.ts/transaction/transaction.ts +1349 -1379
- package/src.ts/utils/base58.ts +73 -73
- package/src.ts/utils/base64-browser.ts +25 -25
- package/src.ts/utils/base64.ts +56 -56
- package/src.ts/utils/data.ts +199 -199
- package/src.ts/utils/errors.ts +793 -793
- package/src.ts/utils/events.ts +105 -105
- package/src.ts/utils/fetch.ts +970 -970
- package/src.ts/utils/fixednumber.ts +643 -643
- package/src.ts/utils/geturl-browser.ts +81 -81
- package/src.ts/utils/geturl.ts +134 -134
- package/src.ts/utils/index.ts +95 -95
- package/src.ts/utils/maths.ts +240 -240
- package/src.ts/utils/properties.ts +60 -60
- package/src.ts/utils/rlp-decode.ts +104 -104
- package/src.ts/utils/rlp-encode.ts +64 -64
- package/src.ts/utils/rlp.ts +20 -20
- package/src.ts/utils/units.ts +91 -91
- package/src.ts/utils/utf8.ts +325 -325
- package/src.ts/utils/uuid.ts +36 -36
- package/src.ts/wallet/base-wallet.ts +160 -160
- package/src.ts/wallet/index.ts +32 -32
- package/src.ts/wallet/json-keystore.ts +108 -106
- package/src.ts/wallet/utils.ts +147 -147
- package/src.ts/wallet/wallet.ts +138 -139
- package/src.ts/wordlists/bit-reader.ts +35 -35
- package/src.ts/wordlists/decode-owl.ts +58 -58
- package/src.ts/wordlists/decode-owla.ts +33 -33
- package/src.ts/wordlists/generation/encode-latin.ts +370 -370
- package/src.ts/wordlists/index.ts +26 -26
- package/src.ts/wordlists/lang-cz.ts +33 -33
- package/src.ts/wordlists/lang-en.ts +33 -33
- package/src.ts/wordlists/lang-es.ts +35 -35
- package/src.ts/wordlists/lang-fr.ts +34 -34
- package/src.ts/wordlists/lang-it.ts +33 -33
- package/src.ts/wordlists/lang-ja.ts +181 -181
- package/src.ts/wordlists/lang-ko.ts +104 -104
- package/src.ts/wordlists/lang-pt.ts +34 -34
- package/src.ts/wordlists/lang-zh.ts +112 -112
- package/src.ts/wordlists/wordlist-owl.ts +77 -77
- package/src.ts/wordlists/wordlist-owla.ts +41 -41
- package/src.ts/wordlists/wordlist.ts +59 -59
- package/src.ts/wordlists/wordlists-browser.ts +8 -8
- package/src.ts/wordlists/wordlists-extra.ts +9 -9
- package/src.ts/wordlists/wordlists.ts +38 -38
- package/dist/quantumcoin.min.js'.gz' +0 -0
- package/dist/quantumcoin.umd.min.js'.gz' +0 -0
- package/dist/wordlists-extra.min.js'.gz' +0 -0
- package/lib.commonjs/providers/provider-alchemy.d.ts +0 -50
- package/lib.commonjs/providers/provider-alchemy.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-alchemy.js +0 -151
- package/lib.commonjs/providers/provider-alchemy.js.map +0 -1
- package/lib.commonjs/providers/provider-ankr.d.ts +0 -61
- package/lib.commonjs/providers/provider-ankr.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-ankr.js +0 -137
- package/lib.commonjs/providers/provider-ankr.js.map +0 -1
- package/lib.commonjs/providers/provider-blockscout.d.ts +0 -59
- package/lib.commonjs/providers/provider-blockscout.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-blockscout.js +0 -145
- package/lib.commonjs/providers/provider-blockscout.js.map +0 -1
- package/lib.commonjs/providers/provider-chainstack.d.ts +0 -46
- package/lib.commonjs/providers/provider-chainstack.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-chainstack.js +0 -102
- package/lib.commonjs/providers/provider-chainstack.js.map +0 -1
- package/lib.commonjs/providers/provider-cloudflare.d.ts +0 -14
- package/lib.commonjs/providers/provider-cloudflare.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-cloudflare.js +0 -26
- package/lib.commonjs/providers/provider-cloudflare.js.map +0 -1
- package/lib.commonjs/providers/provider-etherscan.d.ts +0 -147
- package/lib.commonjs/providers/provider-etherscan.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-etherscan.js +0 -587
- package/lib.commonjs/providers/provider-etherscan.js.map +0 -1
- package/lib.commonjs/providers/provider-infura.d.ts +0 -101
- package/lib.commonjs/providers/provider-infura.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-infura.js +0 -206
- package/lib.commonjs/providers/provider-infura.js.map +0 -1
- package/lib.commonjs/providers/provider-pocket.d.ts +0 -54
- package/lib.commonjs/providers/provider-pocket.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-pocket.js +0 -109
- package/lib.commonjs/providers/provider-pocket.js.map +0 -1
- package/lib.commonjs/providers/provider-quicknode.d.ts +0 -59
- package/lib.commonjs/providers/provider-quicknode.d.ts.map +0 -1
- package/lib.commonjs/providers/provider-quicknode.js +0 -163
- package/lib.commonjs/providers/provider-quicknode.js.map +0 -1
- package/lib.commonjs/wallet/hdwallet.d.ts +0 -248
- package/lib.commonjs/wallet/hdwallet.d.ts.map +0 -1
- package/lib.commonjs/wallet/hdwallet.js +0 -505
- package/lib.commonjs/wallet/hdwallet.js.map +0 -1
- package/lib.commonjs/wallet/json-crowdsale.d.ts +0 -27
- package/lib.commonjs/wallet/json-crowdsale.d.ts.map +0 -1
- package/lib.commonjs/wallet/json-crowdsale.js +0 -60
- package/lib.commonjs/wallet/json-crowdsale.js.map +0 -1
- package/lib.commonjs/wallet/mnemonic.d.ts +0 -65
- package/lib.commonjs/wallet/mnemonic.d.ts.map +0 -1
- package/lib.commonjs/wallet/mnemonic.js +0 -169
- package/lib.commonjs/wallet/mnemonic.js.map +0 -1
- package/lib.commonjs/wallet/seedwallet.d.ts +0 -4
- package/lib.commonjs/wallet/seedwallet.d.ts.map +0 -1
- package/lib.commonjs/wallet/seedwallet.js +0 -8
- package/lib.commonjs/wallet/seedwallet.js.map +0 -1
- package/lib.esm/providers/provider-alchemy.d.ts +0 -50
- package/lib.esm/providers/provider-alchemy.d.ts.map +0 -1
- package/lib.esm/providers/provider-alchemy.js +0 -147
- package/lib.esm/providers/provider-alchemy.js.map +0 -1
- package/lib.esm/providers/provider-ankr.d.ts +0 -61
- package/lib.esm/providers/provider-ankr.d.ts.map +0 -1
- package/lib.esm/providers/provider-ankr.js +0 -133
- package/lib.esm/providers/provider-ankr.js.map +0 -1
- package/lib.esm/providers/provider-blockscout.d.ts +0 -59
- package/lib.esm/providers/provider-blockscout.d.ts.map +0 -1
- package/lib.esm/providers/provider-blockscout.js +0 -141
- package/lib.esm/providers/provider-blockscout.js.map +0 -1
- package/lib.esm/providers/provider-chainstack.d.ts +0 -46
- package/lib.esm/providers/provider-chainstack.d.ts.map +0 -1
- package/lib.esm/providers/provider-chainstack.js +0 -98
- package/lib.esm/providers/provider-chainstack.js.map +0 -1
- package/lib.esm/providers/provider-cloudflare.d.ts +0 -14
- package/lib.esm/providers/provider-cloudflare.d.ts.map +0 -1
- package/lib.esm/providers/provider-cloudflare.js +0 -22
- package/lib.esm/providers/provider-cloudflare.js.map +0 -1
- package/lib.esm/providers/provider-etherscan.d.ts +0 -147
- package/lib.esm/providers/provider-etherscan.d.ts.map +0 -1
- package/lib.esm/providers/provider-etherscan.js +0 -584
- package/lib.esm/providers/provider-etherscan.js.map +0 -1
- package/lib.esm/providers/provider-infura.d.ts +0 -101
- package/lib.esm/providers/provider-infura.d.ts.map +0 -1
- package/lib.esm/providers/provider-infura.js +0 -201
- package/lib.esm/providers/provider-infura.js.map +0 -1
- package/lib.esm/providers/provider-pocket.d.ts +0 -54
- package/lib.esm/providers/provider-pocket.d.ts.map +0 -1
- package/lib.esm/providers/provider-pocket.js +0 -105
- package/lib.esm/providers/provider-pocket.js.map +0 -1
- package/lib.esm/providers/provider-quicknode.d.ts +0 -59
- package/lib.esm/providers/provider-quicknode.d.ts.map +0 -1
- package/lib.esm/providers/provider-quicknode.js +0 -159
- package/lib.esm/providers/provider-quicknode.js.map +0 -1
- package/lib.esm/wallet/hdwallet.d.ts +0 -248
- package/lib.esm/wallet/hdwallet.d.ts.map +0 -1
- package/lib.esm/wallet/hdwallet.js +0 -498
- package/lib.esm/wallet/hdwallet.js.map +0 -1
- package/lib.esm/wallet/json-crowdsale.d.ts +0 -27
- package/lib.esm/wallet/json-crowdsale.d.ts.map +0 -1
- package/lib.esm/wallet/json-crowdsale.js +0 -55
- package/lib.esm/wallet/json-crowdsale.js.map +0 -1
- package/lib.esm/wallet/mnemonic.d.ts +0 -65
- package/lib.esm/wallet/mnemonic.d.ts.map +0 -1
- package/lib.esm/wallet/mnemonic.js +0 -165
- package/lib.esm/wallet/mnemonic.js.map +0 -1
- package/lib.esm/wallet/seedwallet.d.ts +0 -4
- package/lib.esm/wallet/seedwallet.d.ts.map +0 -1
- package/lib.esm/wallet/seedwallet.js +0 -4
- package/lib.esm/wallet/seedwallet.js.map +0 -1
|
@@ -1,1379 +1,1349 @@
|
|
|
1
|
-
|
|
2
|
-
import { getAddress } from "../address/index.js";
|
|
3
|
-
import { ZeroAddress } from "../constants/addresses.js";
|
|
4
|
-
import {
|
|
5
|
-
keccak256, sha256, Signature, SigningKey
|
|
6
|
-
} from "../crypto/index.js";
|
|
7
|
-
import {
|
|
8
|
-
concat, decodeRlp, encodeRlp, getBytes, getBigInt, getNumber, hexlify,
|
|
9
|
-
assert, assertArgument, isBytesLike, isHexString, toBeArray, zeroPadValue
|
|
10
|
-
} from "../utils/index.js";
|
|
11
|
-
|
|
12
|
-
import { accessListify } from "./accesslist.js";
|
|
13
|
-
import { authorizationify } from "./authorization.js";
|
|
14
|
-
import { recoverAddress } from "./address.js";
|
|
15
|
-
|
|
16
|
-
import type { BigNumberish, BytesLike } from "../utils/index.js";
|
|
17
|
-
import type { SignatureLike } from "../crypto/index.js";
|
|
18
|
-
|
|
19
|
-
import type {
|
|
20
|
-
AccessList, AccessListish, Authorization, AuthorizationLike
|
|
21
|
-
} from "./index.js";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const BN_0 = BigInt(0);
|
|
25
|
-
const BN_2 = BigInt(2);
|
|
26
|
-
const BN_27 = BigInt(27)
|
|
27
|
-
const BN_28 = BigInt(28)
|
|
28
|
-
const BN_35 = BigInt(35);
|
|
29
|
-
const BN_MAX_UINT = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
30
|
-
|
|
31
|
-
const BLOB_SIZE = 4096 * 32;
|
|
32
|
-
|
|
33
|
-
// The BLS Modulo; each field within a BLOb must be less than this
|
|
34
|
-
//const BLOB_BLS_MODULO = BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001");
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* A **TransactionLike** is an object which is appropriate as a loose
|
|
38
|
-
* input for many operations which will populate missing properties of
|
|
39
|
-
* a transaction.
|
|
40
|
-
*/
|
|
41
|
-
export interface TransactionLike<A = string> {
|
|
42
|
-
/**
|
|
43
|
-
* The type.
|
|
44
|
-
*/
|
|
45
|
-
type?: null | number;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* The recipient address or ``null`` for an ``init`` transaction.
|
|
49
|
-
*/
|
|
50
|
-
to?: null | A;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The sender.
|
|
54
|
-
*/
|
|
55
|
-
from?: null | A;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* The nonce.
|
|
59
|
-
*/
|
|
60
|
-
nonce?: null | number;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* The maximum amount of gas that can be used.
|
|
64
|
-
*/
|
|
65
|
-
gasLimit?: null | BigNumberish;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The gas price for legacy and berlin transactions.
|
|
69
|
-
*/
|
|
70
|
-
gasPrice?: null | BigNumberish;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* The maximum priority fee per gas for london transactions.
|
|
74
|
-
*/
|
|
75
|
-
maxPriorityFeePerGas?: null | BigNumberish;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* The maximum total fee per gas for london transactions.
|
|
79
|
-
*/
|
|
80
|
-
maxFeePerGas?: null | BigNumberish;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The data.
|
|
84
|
-
*/
|
|
85
|
-
data?: null | string;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* The value (in wei) to send.
|
|
89
|
-
*/
|
|
90
|
-
value?: null | BigNumberish;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* The chain ID the transaction is valid on.
|
|
94
|
-
*/
|
|
95
|
-
chainId?: null | BigNumberish;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* The transaction hash.
|
|
99
|
-
*/
|
|
100
|
-
hash?: null | string;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* The signature provided by the sender.
|
|
104
|
-
*/
|
|
105
|
-
signature?: null | SignatureLike;
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* The access list for berlin and london transactions.
|
|
109
|
-
*/
|
|
110
|
-
accessList?: null | AccessListish;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* The maximum fee per blob gas (see [[link-eip-4844]]).
|
|
114
|
-
*/
|
|
115
|
-
maxFeePerBlobGas?: null | BigNumberish;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* The versioned hashes (see [[link-eip-4844]]).
|
|
119
|
-
*/
|
|
120
|
-
blobVersionedHashes?: null | Array<string>;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* The blobs (if any) attached to this transaction (see [[link-eip-4844]]).
|
|
124
|
-
*/
|
|
125
|
-
blobs?: null | Array<BlobLike>
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* An external library for computing the KZG commitments and
|
|
129
|
-
* proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
|
|
130
|
-
*
|
|
131
|
-
* This is generally ``null``, unless you are creating BLOb
|
|
132
|
-
* transactions.
|
|
133
|
-
*/
|
|
134
|
-
kzg?: null | KzgLibraryLike;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* The [[link-eip-7702]] authorizations (if any).
|
|
138
|
-
*/
|
|
139
|
-
authorizationList?: null | Array<Authorization>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* A full-valid BLOb object for [[link-eip-4844]] transactions.
|
|
144
|
-
*
|
|
145
|
-
* The commitment and proof should have been computed using a
|
|
146
|
-
* KZG library.
|
|
147
|
-
*/
|
|
148
|
-
export interface Blob {
|
|
149
|
-
data: string;
|
|
150
|
-
proof: string;
|
|
151
|
-
commitment: string;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* A BLOb object that can be passed for [[link-eip-4844]]
|
|
156
|
-
* transactions.
|
|
157
|
-
*
|
|
158
|
-
* It may have had its commitment and proof already provided
|
|
159
|
-
* or rely on an attached [[KzgLibrary]] to compute them.
|
|
160
|
-
*/
|
|
161
|
-
export type BlobLike = BytesLike | {
|
|
162
|
-
data: BytesLike;
|
|
163
|
-
proof: BytesLike;
|
|
164
|
-
commitment: BytesLike;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* A KZG Library with the necessary functions to compute
|
|
169
|
-
* BLOb commitments and proofs.
|
|
170
|
-
*/
|
|
171
|
-
export interface KzgLibrary {
|
|
172
|
-
blobToKzgCommitment: (blob: Uint8Array) => Uint8Array;
|
|
173
|
-
computeBlobKzgProof: (blob: Uint8Array, commitment: Uint8Array) => Uint8Array;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* A KZG Library with any of the various API configurations.
|
|
178
|
-
* As the library is still experimental and the API is not
|
|
179
|
-
* stable, depending on the version used the method names and
|
|
180
|
-
* signatures are still in flux.
|
|
181
|
-
*
|
|
182
|
-
* This allows any of the versions to be passed into Transaction
|
|
183
|
-
* while providing a stable external API.
|
|
184
|
-
*/
|
|
185
|
-
export type KzgLibraryLike = KzgLibrary | {
|
|
186
|
-
// kzg-wasm >= 0.5.0
|
|
187
|
-
blobToKZGCommitment: (blob: string) => string;
|
|
188
|
-
computeBlobKZGProof: (blob: string, commitment: string) => string;
|
|
189
|
-
} | {
|
|
190
|
-
// micro-ecc-signer
|
|
191
|
-
blobToKzgCommitment: (blob: string) => string | Uint8Array;
|
|
192
|
-
computeBlobProof: (blob: string, commitment: string) => string | Uint8Array;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
function getKzgLibrary(kzg: KzgLibraryLike): KzgLibrary {
|
|
196
|
-
|
|
197
|
-
const blobToKzgCommitment = (blob: Uint8Array) => {
|
|
198
|
-
|
|
199
|
-
if ("computeBlobProof" in kzg) {
|
|
200
|
-
// micro-ecc-signer; check for computeBlobProof since this API
|
|
201
|
-
// expects a string while the kzg-wasm below expects a Unit8Array
|
|
202
|
-
|
|
203
|
-
if ("blobToKzgCommitment" in kzg && typeof(kzg.blobToKzgCommitment) === "function") {
|
|
204
|
-
return getBytes(kzg.blobToKzgCommitment(hexlify(blob)))
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
} else if ("blobToKzgCommitment" in kzg && typeof(kzg.blobToKzgCommitment) === "function") {
|
|
208
|
-
// kzg-wasm <0.5.0; blobToKzgCommitment(Uint8Array) => Uint8Array
|
|
209
|
-
|
|
210
|
-
return getBytes(kzg.blobToKzgCommitment(blob));
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// kzg-wasm >= 0.5.0; blobToKZGCommitment(string) => string
|
|
214
|
-
if ("blobToKZGCommitment" in kzg && typeof(kzg.blobToKZGCommitment) === "function") {
|
|
215
|
-
return getBytes(kzg.blobToKZGCommitment(hexlify(blob)));
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
assertArgument(false, "unsupported KZG library", "kzg", kzg);
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const computeBlobKzgProof = (blob: Uint8Array, commitment: Uint8Array) => {
|
|
222
|
-
|
|
223
|
-
// micro-ecc-signer
|
|
224
|
-
if ("computeBlobProof" in kzg && typeof(kzg.computeBlobProof) === "function") {
|
|
225
|
-
return getBytes(kzg.computeBlobProof(hexlify(blob), hexlify(commitment)))
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// kzg-wasm <0.5.0; computeBlobKzgProof(Uint8Array, Uint8Array) => Uint8Array
|
|
229
|
-
if ("computeBlobKzgProof" in kzg && typeof(kzg.computeBlobKzgProof) === "function") {
|
|
230
|
-
return kzg.computeBlobKzgProof(blob, commitment);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// kzg-wasm >= 0.5.0; computeBlobKZGProof(string, string) => string
|
|
234
|
-
if ("computeBlobKZGProof" in kzg && typeof(kzg.computeBlobKZGProof) === "function") {
|
|
235
|
-
return getBytes(kzg.computeBlobKZGProof(hexlify(blob), hexlify(commitment)));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
assertArgument(false, "unsupported KZG library", "kzg", kzg);
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
return { blobToKzgCommitment, computeBlobKzgProof };
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function getVersionedHash(version: number, hash: BytesLike): string {
|
|
245
|
-
let versioned = version.toString(16);
|
|
246
|
-
while (versioned.length < 2) { versioned = "0" + versioned; }
|
|
247
|
-
versioned += sha256(hash).substring(4);
|
|
248
|
-
return "0x" + versioned;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function handleAddress(value: string): null | string {
|
|
252
|
-
if (value === "0x") { return null; }
|
|
253
|
-
return getAddress(value);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function handleAccessList(value: any, param: string): AccessList {
|
|
257
|
-
try {
|
|
258
|
-
return accessListify(value);
|
|
259
|
-
} catch (error: any) {
|
|
260
|
-
assertArgument(false, error.message, param, value);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function handleAuthorizationList(value: any, param: string): Array<Authorization> {
|
|
265
|
-
try {
|
|
266
|
-
if (!Array.isArray(value)) { throw new Error("authorizationList: invalid array"); }
|
|
267
|
-
const result: Array<Authorization> = [ ];
|
|
268
|
-
for (let i = 0; i < value.length; i++) {
|
|
269
|
-
const auth: Array<string> = value[i];
|
|
270
|
-
if (!Array.isArray(auth)) { throw new Error(`authorization[${ i }]: invalid array`); }
|
|
271
|
-
if (auth.length !== 6) { throw new Error(`authorization[${ i }]: wrong length`); }
|
|
272
|
-
if (!auth[1]) { throw new Error(`authorization[${ i }]: null address`); }
|
|
273
|
-
result.push({
|
|
274
|
-
address: <string>handleAddress(auth[1]),
|
|
275
|
-
nonce: handleUint(auth[2], "nonce"),
|
|
276
|
-
chainId: handleUint(auth[0], "chainId"),
|
|
277
|
-
signature: Signature.from({
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
})
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
return result;
|
|
285
|
-
} catch (error: any) {
|
|
286
|
-
assertArgument(false, error.message, param, value);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
function handleNumber(_value: string, param: string): number {
|
|
291
|
-
if (_value === "0x") { return 0; }
|
|
292
|
-
return getNumber(_value, param);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
function handleUint(_value: string, param: string): bigint {
|
|
296
|
-
if (_value === "0x") { return BN_0; }
|
|
297
|
-
const value = getBigInt(_value, param);
|
|
298
|
-
assertArgument(value <= BN_MAX_UINT, "value exceeds uint size", param, value);
|
|
299
|
-
return value;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
function formatNumber(_value: BigNumberish, name: string): Uint8Array {
|
|
303
|
-
const value = getBigInt(_value, "value");
|
|
304
|
-
const result = toBeArray(value);
|
|
305
|
-
assertArgument(result.length <= 32, `value too large`, `tx.${ name }`, value);
|
|
306
|
-
return result;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function formatAccessList(value: AccessListish): Array<[ string, Array<string> ]> {
|
|
310
|
-
return accessListify(value).map((set) => [ set.address, set.storageKeys ]);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
function formatAuthorizationList(value: Array<Authorization>): Array<Array<string | Uint8Array>> {
|
|
314
|
-
return value.map((a) => {
|
|
315
|
-
return [
|
|
316
|
-
formatNumber(a.chainId, "chainId"),
|
|
317
|
-
a.address,
|
|
318
|
-
formatNumber(a.nonce, "nonce"),
|
|
319
|
-
|
|
320
|
-
a.signature.
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
formatNumber(tx.
|
|
387
|
-
formatNumber(tx.
|
|
388
|
-
|
|
389
|
-
(tx.
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
tx.
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
const
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
(
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
(
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
fields
|
|
646
|
-
fields
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
return
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
function
|
|
667
|
-
const fields: any =
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
*
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
case
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
*
|
|
825
|
-
*
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
*
|
|
856
|
-
*/
|
|
857
|
-
get
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
*
|
|
871
|
-
*
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
if
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
*
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
this.#
|
|
1049
|
-
this.#
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
this
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
this
|
|
1077
|
-
this
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
/**
|
|
1119
|
-
*
|
|
1120
|
-
*
|
|
1121
|
-
* This
|
|
1122
|
-
*
|
|
1123
|
-
*/
|
|
1124
|
-
|
|
1125
|
-
return this
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
*
|
|
1246
|
-
*
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
*
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
return
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
if (tx
|
|
1324
|
-
|
|
1325
|
-
if (
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
if (tx.
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
if (tx.data != null) { result.data = tx.data; }
|
|
1351
|
-
if (tx.value != null) { result.value = tx.value; }
|
|
1352
|
-
if (tx.chainId != null) { result.chainId = tx.chainId; }
|
|
1353
|
-
if (tx.signature != null) { result.signature = Signature.from(tx.signature); }
|
|
1354
|
-
if (tx.accessList != null) { result.accessList = tx.accessList; }
|
|
1355
|
-
if (tx.authorizationList != null) {
|
|
1356
|
-
result.authorizationList = tx.authorizationList;
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
// This will get overwritten by blobs, if present
|
|
1360
|
-
if (tx.blobVersionedHashes != null) { result.blobVersionedHashes = tx.blobVersionedHashes; }
|
|
1361
|
-
|
|
1362
|
-
// Make sure we assign the kzg before assigning blobs, which
|
|
1363
|
-
// require the library in the event raw blob data is provided.
|
|
1364
|
-
if (tx.kzg != null) { result.kzg = tx.kzg; }
|
|
1365
|
-
if (tx.blobs != null) { result.blobs = tx.blobs; }
|
|
1366
|
-
|
|
1367
|
-
if (tx.hash != null) {
|
|
1368
|
-
assertArgument(result.isSigned(), "unsigned transaction cannot define '.hash'", "tx", tx);
|
|
1369
|
-
assertArgument(result.hash === tx.hash, "hash mismatch", "tx", tx);
|
|
1370
|
-
}
|
|
1371
|
-
|
|
1372
|
-
if (tx.from != null) {
|
|
1373
|
-
assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
|
|
1374
|
-
assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
|
|
1375
|
-
}
|
|
1376
|
-
|
|
1377
|
-
return result;
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1
|
+
|
|
2
|
+
import { getAddress } from "../address/index.js";
|
|
3
|
+
import { ZeroAddress } from "../constants/addresses.js";
|
|
4
|
+
import {
|
|
5
|
+
keccak256, sha256, Signature, SigningKey
|
|
6
|
+
} from "../crypto/index.js";
|
|
7
|
+
import {
|
|
8
|
+
concat, decodeRlp, encodeRlp, getBytes, getBigInt, getNumber, hexlify,
|
|
9
|
+
assert, assertArgument, isBytesLike, isHexString, toBeArray, zeroPadValue
|
|
10
|
+
} from "../utils/index.js";
|
|
11
|
+
|
|
12
|
+
import { accessListify } from "./accesslist.js";
|
|
13
|
+
import { authorizationify } from "./authorization.js";
|
|
14
|
+
import { recoverAddress } from "./address.js";
|
|
15
|
+
|
|
16
|
+
import type { BigNumberish, BytesLike } from "../utils/index.js";
|
|
17
|
+
import type { SignatureLike } from "../crypto/index.js";
|
|
18
|
+
|
|
19
|
+
import type {
|
|
20
|
+
AccessList, AccessListish, Authorization, AuthorizationLike
|
|
21
|
+
} from "./index.js";
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const BN_0 = BigInt(0);
|
|
25
|
+
const BN_2 = BigInt(2);
|
|
26
|
+
const BN_27 = BigInt(27)
|
|
27
|
+
const BN_28 = BigInt(28)
|
|
28
|
+
const BN_35 = BigInt(35);
|
|
29
|
+
const BN_MAX_UINT = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
|
|
30
|
+
|
|
31
|
+
const BLOB_SIZE = 4096 * 32;
|
|
32
|
+
|
|
33
|
+
// The BLS Modulo; each field within a BLOb must be less than this
|
|
34
|
+
//const BLOB_BLS_MODULO = BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001");
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A **TransactionLike** is an object which is appropriate as a loose
|
|
38
|
+
* input for many operations which will populate missing properties of
|
|
39
|
+
* a transaction.
|
|
40
|
+
*/
|
|
41
|
+
export interface TransactionLike<A = string> {
|
|
42
|
+
/**
|
|
43
|
+
* The type.
|
|
44
|
+
*/
|
|
45
|
+
type?: null | number;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The recipient address or ``null`` for an ``init`` transaction.
|
|
49
|
+
*/
|
|
50
|
+
to?: null | A;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The sender.
|
|
54
|
+
*/
|
|
55
|
+
from?: null | A;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The nonce.
|
|
59
|
+
*/
|
|
60
|
+
nonce?: null | number;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The maximum amount of gas that can be used.
|
|
64
|
+
*/
|
|
65
|
+
gasLimit?: null | BigNumberish;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The gas price for legacy and berlin transactions.
|
|
69
|
+
*/
|
|
70
|
+
gasPrice?: null | BigNumberish;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The maximum priority fee per gas for london transactions.
|
|
74
|
+
*/
|
|
75
|
+
maxPriorityFeePerGas?: null | BigNumberish;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The maximum total fee per gas for london transactions.
|
|
79
|
+
*/
|
|
80
|
+
maxFeePerGas?: null | BigNumberish;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The data.
|
|
84
|
+
*/
|
|
85
|
+
data?: null | string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The value (in wei) to send.
|
|
89
|
+
*/
|
|
90
|
+
value?: null | BigNumberish;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The chain ID the transaction is valid on.
|
|
94
|
+
*/
|
|
95
|
+
chainId?: null | BigNumberish;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The transaction hash.
|
|
99
|
+
*/
|
|
100
|
+
hash?: null | string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The signature provided by the sender.
|
|
104
|
+
*/
|
|
105
|
+
signature?: null | SignatureLike;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The access list for berlin and london transactions.
|
|
109
|
+
*/
|
|
110
|
+
accessList?: null | AccessListish;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The maximum fee per blob gas (see [[link-eip-4844]]).
|
|
114
|
+
*/
|
|
115
|
+
maxFeePerBlobGas?: null | BigNumberish;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The versioned hashes (see [[link-eip-4844]]).
|
|
119
|
+
*/
|
|
120
|
+
blobVersionedHashes?: null | Array<string>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The blobs (if any) attached to this transaction (see [[link-eip-4844]]).
|
|
124
|
+
*/
|
|
125
|
+
blobs?: null | Array<BlobLike>
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* An external library for computing the KZG commitments and
|
|
129
|
+
* proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
|
|
130
|
+
*
|
|
131
|
+
* This is generally ``null``, unless you are creating BLOb
|
|
132
|
+
* transactions.
|
|
133
|
+
*/
|
|
134
|
+
kzg?: null | KzgLibraryLike;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* The [[link-eip-7702]] authorizations (if any).
|
|
138
|
+
*/
|
|
139
|
+
authorizationList?: null | Array<Authorization>;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* A full-valid BLOb object for [[link-eip-4844]] transactions.
|
|
144
|
+
*
|
|
145
|
+
* The commitment and proof should have been computed using a
|
|
146
|
+
* KZG library.
|
|
147
|
+
*/
|
|
148
|
+
export interface Blob {
|
|
149
|
+
data: string;
|
|
150
|
+
proof: string;
|
|
151
|
+
commitment: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A BLOb object that can be passed for [[link-eip-4844]]
|
|
156
|
+
* transactions.
|
|
157
|
+
*
|
|
158
|
+
* It may have had its commitment and proof already provided
|
|
159
|
+
* or rely on an attached [[KzgLibrary]] to compute them.
|
|
160
|
+
*/
|
|
161
|
+
export type BlobLike = BytesLike | {
|
|
162
|
+
data: BytesLike;
|
|
163
|
+
proof: BytesLike;
|
|
164
|
+
commitment: BytesLike;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* A KZG Library with the necessary functions to compute
|
|
169
|
+
* BLOb commitments and proofs.
|
|
170
|
+
*/
|
|
171
|
+
export interface KzgLibrary {
|
|
172
|
+
blobToKzgCommitment: (blob: Uint8Array) => Uint8Array;
|
|
173
|
+
computeBlobKzgProof: (blob: Uint8Array, commitment: Uint8Array) => Uint8Array;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* A KZG Library with any of the various API configurations.
|
|
178
|
+
* As the library is still experimental and the API is not
|
|
179
|
+
* stable, depending on the version used the method names and
|
|
180
|
+
* signatures are still in flux.
|
|
181
|
+
*
|
|
182
|
+
* This allows any of the versions to be passed into Transaction
|
|
183
|
+
* while providing a stable external API.
|
|
184
|
+
*/
|
|
185
|
+
export type KzgLibraryLike = KzgLibrary | {
|
|
186
|
+
// kzg-wasm >= 0.5.0
|
|
187
|
+
blobToKZGCommitment: (blob: string) => string;
|
|
188
|
+
computeBlobKZGProof: (blob: string, commitment: string) => string;
|
|
189
|
+
} | {
|
|
190
|
+
// micro-ecc-signer
|
|
191
|
+
blobToKzgCommitment: (blob: string) => string | Uint8Array;
|
|
192
|
+
computeBlobProof: (blob: string, commitment: string) => string | Uint8Array;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
function getKzgLibrary(kzg: KzgLibraryLike): KzgLibrary {
|
|
196
|
+
|
|
197
|
+
const blobToKzgCommitment = (blob: Uint8Array) => {
|
|
198
|
+
|
|
199
|
+
if ("computeBlobProof" in kzg) {
|
|
200
|
+
// micro-ecc-signer; check for computeBlobProof since this API
|
|
201
|
+
// expects a string while the kzg-wasm below expects a Unit8Array
|
|
202
|
+
|
|
203
|
+
if ("blobToKzgCommitment" in kzg && typeof(kzg.blobToKzgCommitment) === "function") {
|
|
204
|
+
return getBytes(kzg.blobToKzgCommitment(hexlify(blob)))
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
} else if ("blobToKzgCommitment" in kzg && typeof(kzg.blobToKzgCommitment) === "function") {
|
|
208
|
+
// kzg-wasm <0.5.0; blobToKzgCommitment(Uint8Array) => Uint8Array
|
|
209
|
+
|
|
210
|
+
return getBytes(kzg.blobToKzgCommitment(blob));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// kzg-wasm >= 0.5.0; blobToKZGCommitment(string) => string
|
|
214
|
+
if ("blobToKZGCommitment" in kzg && typeof(kzg.blobToKZGCommitment) === "function") {
|
|
215
|
+
return getBytes(kzg.blobToKZGCommitment(hexlify(blob)));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
assertArgument(false, "unsupported KZG library", "kzg", kzg);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const computeBlobKzgProof = (blob: Uint8Array, commitment: Uint8Array) => {
|
|
222
|
+
|
|
223
|
+
// micro-ecc-signer
|
|
224
|
+
if ("computeBlobProof" in kzg && typeof(kzg.computeBlobProof) === "function") {
|
|
225
|
+
return getBytes(kzg.computeBlobProof(hexlify(blob), hexlify(commitment)))
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// kzg-wasm <0.5.0; computeBlobKzgProof(Uint8Array, Uint8Array) => Uint8Array
|
|
229
|
+
if ("computeBlobKzgProof" in kzg && typeof(kzg.computeBlobKzgProof) === "function") {
|
|
230
|
+
return kzg.computeBlobKzgProof(blob, commitment);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// kzg-wasm >= 0.5.0; computeBlobKZGProof(string, string) => string
|
|
234
|
+
if ("computeBlobKZGProof" in kzg && typeof(kzg.computeBlobKZGProof) === "function") {
|
|
235
|
+
return getBytes(kzg.computeBlobKZGProof(hexlify(blob), hexlify(commitment)));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
assertArgument(false, "unsupported KZG library", "kzg", kzg);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
return { blobToKzgCommitment, computeBlobKzgProof };
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function getVersionedHash(version: number, hash: BytesLike): string {
|
|
245
|
+
let versioned = version.toString(16);
|
|
246
|
+
while (versioned.length < 2) { versioned = "0" + versioned; }
|
|
247
|
+
versioned += sha256(hash).substring(4);
|
|
248
|
+
return "0x" + versioned;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function handleAddress(value: string): null | string {
|
|
252
|
+
if (value === "0x") { return null; }
|
|
253
|
+
return getAddress(value);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function handleAccessList(value: any, param: string): AccessList {
|
|
257
|
+
try {
|
|
258
|
+
return accessListify(value);
|
|
259
|
+
} catch (error: any) {
|
|
260
|
+
assertArgument(false, error.message, param, value);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function handleAuthorizationList(value: any, param: string): Array<Authorization> {
|
|
265
|
+
try {
|
|
266
|
+
if (!Array.isArray(value)) { throw new Error("authorizationList: invalid array"); }
|
|
267
|
+
const result: Array<Authorization> = [ ];
|
|
268
|
+
for (let i = 0; i < value.length; i++) {
|
|
269
|
+
const auth: Array<string> = value[i];
|
|
270
|
+
if (!Array.isArray(auth)) { throw new Error(`authorization[${ i }]: invalid array`); }
|
|
271
|
+
if (auth.length !== 6) { throw new Error(`authorization[${ i }]: wrong length`); }
|
|
272
|
+
if (!auth[1]) { throw new Error(`authorization[${ i }]: null address`); }
|
|
273
|
+
result.push({
|
|
274
|
+
address: <string>handleAddress(auth[1]),
|
|
275
|
+
nonce: handleUint(auth[2], "nonce"),
|
|
276
|
+
chainId: handleUint(auth[0], "chainId"),
|
|
277
|
+
signature: Signature.from({
|
|
278
|
+
r: auth[4],
|
|
279
|
+
s: auth[5],
|
|
280
|
+
v: 1
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return result;
|
|
285
|
+
} catch (error: any) {
|
|
286
|
+
assertArgument(false, error.message, param, value);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function handleNumber(_value: string, param: string): number {
|
|
291
|
+
if (_value === "0x") { return 0; }
|
|
292
|
+
return getNumber(_value, param);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function handleUint(_value: string, param: string): bigint {
|
|
296
|
+
if (_value === "0x") { return BN_0; }
|
|
297
|
+
const value = getBigInt(_value, param);
|
|
298
|
+
assertArgument(value <= BN_MAX_UINT, "value exceeds uint size", param, value);
|
|
299
|
+
return value;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function formatNumber(_value: BigNumberish, name: string): Uint8Array {
|
|
303
|
+
const value = getBigInt(_value, "value");
|
|
304
|
+
const result = toBeArray(value);
|
|
305
|
+
assertArgument(result.length <= 32, `value too large`, `tx.${ name }`, value);
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function formatAccessList(value: AccessListish): Array<[ string, Array<string> ]> {
|
|
310
|
+
return accessListify(value).map((set) => [ set.address, set.storageKeys ]);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function formatAuthorizationList(value: Array<Authorization>): Array<Array<string | Uint8Array>> {
|
|
314
|
+
return value.map((a) => {
|
|
315
|
+
return [
|
|
316
|
+
formatNumber(a.chainId, "chainId"),
|
|
317
|
+
a.address,
|
|
318
|
+
formatNumber(a.nonce, "nonce"),
|
|
319
|
+
a.signature.r,
|
|
320
|
+
a.signature.s
|
|
321
|
+
];
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function formatHashes(value: Array<string>, param: string): Array<string> {
|
|
326
|
+
assertArgument(Array.isArray(value), `invalid ${ param }`, "value", value);
|
|
327
|
+
for (let i = 0; i < value.length; i++) {
|
|
328
|
+
assertArgument(isHexString(value[i], 32), "invalid ${ param } hash", `value[${ i }]`, value[i]);
|
|
329
|
+
}
|
|
330
|
+
return value;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function _parseLegacy(data: Uint8Array): TransactionLike {
|
|
334
|
+
const fields: any = decodeRlp(data);
|
|
335
|
+
|
|
336
|
+
assertArgument(Array.isArray(fields) && (fields.length === 9 || fields.length === 6),
|
|
337
|
+
"invalid field count for legacy transaction", "data", data);
|
|
338
|
+
|
|
339
|
+
const tx: TransactionLike = {
|
|
340
|
+
type: 0,
|
|
341
|
+
nonce: handleNumber(fields[0], "nonce"),
|
|
342
|
+
gasPrice: handleUint(fields[1], "gasPrice"),
|
|
343
|
+
gasLimit: handleUint(fields[2], "gasLimit"),
|
|
344
|
+
to: handleAddress(fields[3]),
|
|
345
|
+
value: handleUint(fields[4], "value"),
|
|
346
|
+
data: hexlify(fields[5]),
|
|
347
|
+
chainId: BN_0
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// Legacy unsigned transaction
|
|
351
|
+
if (fields.length === 6) { return tx; }
|
|
352
|
+
|
|
353
|
+
const v = handleUint(fields[6], "v");
|
|
354
|
+
const r = handleUint(fields[7], "r");
|
|
355
|
+
const s = handleUint(fields[8], "s");
|
|
356
|
+
|
|
357
|
+
if (r === BN_0 && s === BN_0) {
|
|
358
|
+
// EIP-155 unsigned transaction
|
|
359
|
+
tx.chainId = v;
|
|
360
|
+
|
|
361
|
+
} else {
|
|
362
|
+
|
|
363
|
+
// Compute the EIP-155 chain ID (or 0 for legacy)
|
|
364
|
+
let chainId = (v - BN_35) / BN_2;
|
|
365
|
+
if (chainId < BN_0) { chainId = BN_0; }
|
|
366
|
+
tx.chainId = chainId
|
|
367
|
+
|
|
368
|
+
// Signed Legacy Transaction
|
|
369
|
+
assertArgument(chainId !== BN_0 || (v === BN_27 || v === BN_28), "non-canonical legacy v", "v", fields[6]);
|
|
370
|
+
|
|
371
|
+
tx.signature = Signature.from({
|
|
372
|
+
r: zeroPadValue(fields[7], 32),
|
|
373
|
+
s: zeroPadValue(fields[8], 32),
|
|
374
|
+
v
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
//tx.hash = keccak256(data);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return tx;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function _serializeLegacy(tx: Transaction, sig: null | Signature): string {
|
|
384
|
+
const fields: Array<any> = [
|
|
385
|
+
formatNumber(tx.nonce, "nonce"),
|
|
386
|
+
formatNumber(tx.gasPrice || 0, "gasPrice"),
|
|
387
|
+
formatNumber(tx.gasLimit, "gasLimit"),
|
|
388
|
+
(tx.to || "0x"),
|
|
389
|
+
formatNumber(tx.value, "value"),
|
|
390
|
+
tx.data,
|
|
391
|
+
];
|
|
392
|
+
|
|
393
|
+
let chainId = BN_0;
|
|
394
|
+
if (tx.chainId != BN_0) {
|
|
395
|
+
// A chainId was provided; if non-zero we'll use EIP-155
|
|
396
|
+
chainId = getBigInt(tx.chainId, "tx.chainId");
|
|
397
|
+
|
|
398
|
+
} else if (tx.signature) {
|
|
399
|
+
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Requesting an unsigned transaction
|
|
403
|
+
if (!sig) {
|
|
404
|
+
// We have an EIP-155 transaction (chainId was specified and non-zero)
|
|
405
|
+
if (chainId !== BN_0) {
|
|
406
|
+
fields.push(toBeArray(chainId));
|
|
407
|
+
fields.push("0x");
|
|
408
|
+
fields.push("0x");
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return encodeRlp(fields);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
let v = sig.v;
|
|
415
|
+
|
|
416
|
+
// Add the signature
|
|
417
|
+
fields.push(toBeArray(v));
|
|
418
|
+
fields.push(toBeArray(sig.r));
|
|
419
|
+
fields.push(toBeArray(sig.s));
|
|
420
|
+
|
|
421
|
+
return encodeRlp(fields);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
function _parseEipSignature(tx: TransactionLike, fields: Array<string>): void {
|
|
425
|
+
const r = fields[1];
|
|
426
|
+
const s = fields[2]
|
|
427
|
+
|
|
428
|
+
const signature = Signature.from({ r, s });
|
|
429
|
+
tx.signature = signature;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
function _parseEip1559(data: Uint8Array): TransactionLike {
|
|
433
|
+
const fields: any = decodeRlp(getBytes(data).slice(1));
|
|
434
|
+
|
|
435
|
+
assertArgument(Array.isArray(fields) && (fields.length === 9 || fields.length === 12),
|
|
436
|
+
"invalid field count for transaction type: 2", "data", hexlify(data));
|
|
437
|
+
|
|
438
|
+
const tx: TransactionLike = {
|
|
439
|
+
type: 2,
|
|
440
|
+
chainId: handleUint(fields[0], "chainId"),
|
|
441
|
+
nonce: handleNumber(fields[1], "nonce"),
|
|
442
|
+
maxPriorityFeePerGas: handleUint(fields[2], "maxPriorityFeePerGas"),
|
|
443
|
+
maxFeePerGas: handleUint(fields[3], "maxFeePerGas"),
|
|
444
|
+
gasPrice: null,
|
|
445
|
+
gasLimit: handleUint(fields[4], "gasLimit"),
|
|
446
|
+
to: handleAddress(fields[5]),
|
|
447
|
+
value: handleUint(fields[6], "value"),
|
|
448
|
+
data: hexlify(fields[7]),
|
|
449
|
+
accessList: handleAccessList(fields[8], "accessList"),
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
// Unsigned EIP-1559 Transaction
|
|
453
|
+
if (fields.length === 9) { return tx; }
|
|
454
|
+
|
|
455
|
+
//tx.hash = keccak256(data);
|
|
456
|
+
|
|
457
|
+
_parseEipSignature(tx, fields.slice(9));
|
|
458
|
+
|
|
459
|
+
return tx;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function _serializeEip1559(tx: Transaction, sig: null | Signature): string {
|
|
463
|
+
const fields: Array<any> = [
|
|
464
|
+
formatNumber(tx.chainId, "chainId"),
|
|
465
|
+
formatNumber(tx.nonce, "nonce"),
|
|
466
|
+
formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
|
|
467
|
+
formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
|
|
468
|
+
formatNumber(tx.gasLimit, "gasLimit"),
|
|
469
|
+
(tx.to || "0x"),
|
|
470
|
+
formatNumber(tx.value, "value"),
|
|
471
|
+
tx.data,
|
|
472
|
+
formatAccessList(tx.accessList || [ ])
|
|
473
|
+
];
|
|
474
|
+
|
|
475
|
+
if (sig) {
|
|
476
|
+
fields.push(toBeArray(sig.r));
|
|
477
|
+
fields.push(toBeArray(sig.s));
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
return concat([ "0x02", encodeRlp(fields)]);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function _parseEip2930(data: Uint8Array): TransactionLike {
|
|
484
|
+
const fields: any = decodeRlp(getBytes(data).slice(1));
|
|
485
|
+
|
|
486
|
+
assertArgument(Array.isArray(fields) && (fields.length === 8 || fields.length === 11),
|
|
487
|
+
"invalid field count for transaction type: 1", "data", hexlify(data));
|
|
488
|
+
|
|
489
|
+
const tx: TransactionLike = {
|
|
490
|
+
type: 1,
|
|
491
|
+
chainId: handleUint(fields[0], "chainId"),
|
|
492
|
+
nonce: handleNumber(fields[1], "nonce"),
|
|
493
|
+
gasPrice: handleUint(fields[2], "gasPrice"),
|
|
494
|
+
gasLimit: handleUint(fields[3], "gasLimit"),
|
|
495
|
+
to: handleAddress(fields[4]),
|
|
496
|
+
value: handleUint(fields[5], "value"),
|
|
497
|
+
data: hexlify(fields[6]),
|
|
498
|
+
accessList: handleAccessList(fields[7], "accessList")
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
// Unsigned EIP-2930 Transaction
|
|
502
|
+
if (fields.length === 8) { return tx; }
|
|
503
|
+
|
|
504
|
+
//tx.hash = keccak256(data);
|
|
505
|
+
|
|
506
|
+
_parseEipSignature(tx, fields.slice(8));
|
|
507
|
+
|
|
508
|
+
return tx;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function _serializeEip2930(tx: Transaction, sig: null | Signature): string {
|
|
512
|
+
const fields: any = [
|
|
513
|
+
formatNumber(tx.chainId, "chainId"),
|
|
514
|
+
formatNumber(tx.nonce, "nonce"),
|
|
515
|
+
formatNumber(tx.gasPrice || 0, "gasPrice"),
|
|
516
|
+
formatNumber(tx.gasLimit, "gasLimit"),
|
|
517
|
+
(tx.to || "0x"),
|
|
518
|
+
formatNumber(tx.value, "value"),
|
|
519
|
+
tx.data,
|
|
520
|
+
formatAccessList(tx.accessList || [ ])
|
|
521
|
+
];
|
|
522
|
+
|
|
523
|
+
if (sig) {
|
|
524
|
+
fields.push(toBeArray(sig.r));
|
|
525
|
+
fields.push(toBeArray(sig.s));
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
return concat([ "0x01", encodeRlp(fields)]);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function _parseEip4844(data: Uint8Array): TransactionLike {
|
|
532
|
+
let fields: any = decodeRlp(getBytes(data).slice(1));
|
|
533
|
+
|
|
534
|
+
let typeName = "3";
|
|
535
|
+
|
|
536
|
+
let blobs: null | Array<Blob> = null;
|
|
537
|
+
|
|
538
|
+
// Parse the network format
|
|
539
|
+
if (fields.length === 4 && Array.isArray(fields[0])) {
|
|
540
|
+
typeName = "3 (network format)";
|
|
541
|
+
const fBlobs = fields[1], fCommits = fields[2], fProofs = fields[3];
|
|
542
|
+
assertArgument(Array.isArray(fBlobs), "invalid network format: blobs not an array", "fields[1]", fBlobs);
|
|
543
|
+
assertArgument(Array.isArray(fCommits), "invalid network format: commitments not an array", "fields[2]", fCommits);
|
|
544
|
+
assertArgument(Array.isArray(fProofs), "invalid network format: proofs not an array", "fields[3]", fProofs);
|
|
545
|
+
assertArgument(fBlobs.length === fCommits.length, "invalid network format: blobs/commitments length mismatch", "fields", fields);
|
|
546
|
+
assertArgument(fBlobs.length === fProofs.length, "invalid network format: blobs/proofs length mismatch", "fields", fields);
|
|
547
|
+
|
|
548
|
+
blobs = [ ];
|
|
549
|
+
for (let i = 0; i < fields[1].length; i++) {
|
|
550
|
+
blobs.push({
|
|
551
|
+
data: fBlobs[i],
|
|
552
|
+
commitment: fCommits[i],
|
|
553
|
+
proof: fProofs[i],
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
fields = fields[0];
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
assertArgument(Array.isArray(fields) && (fields.length === 11 || fields.length === 14),
|
|
561
|
+
`invalid field count for transaction type: ${ typeName }`, "data", hexlify(data));
|
|
562
|
+
|
|
563
|
+
const tx: TransactionLike = {
|
|
564
|
+
type: 3,
|
|
565
|
+
chainId: handleUint(fields[0], "chainId"),
|
|
566
|
+
nonce: handleNumber(fields[1], "nonce"),
|
|
567
|
+
maxPriorityFeePerGas: handleUint(fields[2], "maxPriorityFeePerGas"),
|
|
568
|
+
maxFeePerGas: handleUint(fields[3], "maxFeePerGas"),
|
|
569
|
+
gasPrice: null,
|
|
570
|
+
gasLimit: handleUint(fields[4], "gasLimit"),
|
|
571
|
+
to: handleAddress(fields[5]),
|
|
572
|
+
value: handleUint(fields[6], "value"),
|
|
573
|
+
data: hexlify(fields[7]),
|
|
574
|
+
accessList: handleAccessList(fields[8], "accessList"),
|
|
575
|
+
maxFeePerBlobGas: handleUint(fields[9], "maxFeePerBlobGas"),
|
|
576
|
+
blobVersionedHashes: fields[10]
|
|
577
|
+
};
|
|
578
|
+
|
|
579
|
+
if (blobs) { tx.blobs = blobs; }
|
|
580
|
+
|
|
581
|
+
assertArgument(tx.to != null, `invalid address for transaction type: ${ typeName }`, "data", data);
|
|
582
|
+
|
|
583
|
+
assertArgument(Array.isArray(tx.blobVersionedHashes), "invalid blobVersionedHashes: must be an array", "data", data);
|
|
584
|
+
for (let i = 0; i < tx.blobVersionedHashes.length; i++) {
|
|
585
|
+
assertArgument(isHexString(tx.blobVersionedHashes[i], 32), `invalid blobVersionedHash at index ${ i }: must be length 32`, "data", data);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Unsigned EIP-4844 Transaction
|
|
589
|
+
if (fields.length === 11) { return tx; }
|
|
590
|
+
|
|
591
|
+
// @TODO: Do we need to do this? This is only called internally
|
|
592
|
+
// and used to verify hashes; it might save time to not do this
|
|
593
|
+
//tx.hash = keccak256(concat([ "0x03", encodeRlp(fields) ]));
|
|
594
|
+
|
|
595
|
+
_parseEipSignature(tx, fields.slice(11));
|
|
596
|
+
|
|
597
|
+
return tx;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function _serializeEip4844(tx: Transaction, sig: null | Signature, blobs: null | Array<Blob>): string {
|
|
601
|
+
const fields: Array<any> = [
|
|
602
|
+
formatNumber(tx.chainId, "chainId"),
|
|
603
|
+
formatNumber(tx.nonce, "nonce"),
|
|
604
|
+
formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
|
|
605
|
+
formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
|
|
606
|
+
formatNumber(tx.gasLimit, "gasLimit"),
|
|
607
|
+
(tx.to || ZeroAddress),
|
|
608
|
+
formatNumber(tx.value, "value"),
|
|
609
|
+
tx.data,
|
|
610
|
+
formatAccessList(tx.accessList || [ ]),
|
|
611
|
+
formatNumber(tx.maxFeePerBlobGas || 0, "maxFeePerBlobGas"),
|
|
612
|
+
formatHashes(tx.blobVersionedHashes || [ ], "blobVersionedHashes")
|
|
613
|
+
];
|
|
614
|
+
|
|
615
|
+
if (sig) {
|
|
616
|
+
fields.push(toBeArray(sig.r));
|
|
617
|
+
fields.push(toBeArray(sig.s));
|
|
618
|
+
|
|
619
|
+
// We have blobs; return the network wrapped format
|
|
620
|
+
if (blobs) {
|
|
621
|
+
return concat([
|
|
622
|
+
"0x03",
|
|
623
|
+
encodeRlp([
|
|
624
|
+
fields,
|
|
625
|
+
blobs.map((b) => b.data),
|
|
626
|
+
blobs.map((b) => b.commitment),
|
|
627
|
+
blobs.map((b) => b.proof),
|
|
628
|
+
])
|
|
629
|
+
]);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
return concat([ "0x03", encodeRlp(fields)]);
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function _parseEip7702(data: Uint8Array): TransactionLike {
|
|
638
|
+
const fields: any = decodeRlp(getBytes(data).slice(1));
|
|
639
|
+
|
|
640
|
+
assertArgument(Array.isArray(fields) && (fields.length === 10 || fields.length === 13),
|
|
641
|
+
"invalid field count for transaction type: 4", "data", hexlify(data));
|
|
642
|
+
|
|
643
|
+
const tx: TransactionLike = {
|
|
644
|
+
type: 4,
|
|
645
|
+
chainId: handleUint(fields[0], "chainId"),
|
|
646
|
+
nonce: handleNumber(fields[1], "nonce"),
|
|
647
|
+
maxPriorityFeePerGas: handleUint(fields[2], "maxPriorityFeePerGas"),
|
|
648
|
+
maxFeePerGas: handleUint(fields[3], "maxFeePerGas"),
|
|
649
|
+
gasPrice: null,
|
|
650
|
+
gasLimit: handleUint(fields[4], "gasLimit"),
|
|
651
|
+
to: handleAddress(fields[5]),
|
|
652
|
+
value: handleUint(fields[6], "value"),
|
|
653
|
+
data: hexlify(fields[7]),
|
|
654
|
+
accessList: handleAccessList(fields[8], "accessList"),
|
|
655
|
+
authorizationList: handleAuthorizationList(fields[9], "authorizationList"),
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
// Unsigned EIP-7702 Transaction
|
|
659
|
+
if (fields.length === 10) { return tx; }
|
|
660
|
+
|
|
661
|
+
_parseEipSignature(tx, fields.slice(10));
|
|
662
|
+
|
|
663
|
+
return tx;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
function _serializeEip7702(tx: Transaction, sig: null | Signature): string {
|
|
667
|
+
const fields: Array<any> = [
|
|
668
|
+
formatNumber(tx.chainId, "chainId"),
|
|
669
|
+
formatNumber(tx.nonce, "nonce"),
|
|
670
|
+
formatNumber(tx.maxPriorityFeePerGas || 0, "maxPriorityFeePerGas"),
|
|
671
|
+
formatNumber(tx.maxFeePerGas || 0, "maxFeePerGas"),
|
|
672
|
+
formatNumber(tx.gasLimit, "gasLimit"),
|
|
673
|
+
(tx.to || "0x"),
|
|
674
|
+
formatNumber(tx.value, "value"),
|
|
675
|
+
tx.data,
|
|
676
|
+
formatAccessList(tx.accessList || [ ]),
|
|
677
|
+
formatAuthorizationList(tx.authorizationList || [ ])
|
|
678
|
+
];
|
|
679
|
+
|
|
680
|
+
if (sig) {
|
|
681
|
+
fields.push(toBeArray(sig.r));
|
|
682
|
+
fields.push(toBeArray(sig.s));
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
return concat([ "0x04", encodeRlp(fields)]);
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* A **Transaction** describes an operation to be executed on
|
|
690
|
+
* Ethereum by an Externally Owned Account (EOA). It includes
|
|
691
|
+
* who (the [[to]] address), what (the [[data]]) and how much (the
|
|
692
|
+
* [[value]] in ether) the operation should entail.
|
|
693
|
+
*
|
|
694
|
+
* @example:
|
|
695
|
+
* tx = new Transaction()
|
|
696
|
+
* //_result:
|
|
697
|
+
*
|
|
698
|
+
* tx.data = "0x1234";
|
|
699
|
+
* //_result:
|
|
700
|
+
*/
|
|
701
|
+
export class Transaction implements TransactionLike<string> {
|
|
702
|
+
#type: null | number;
|
|
703
|
+
#to: null | string;
|
|
704
|
+
#data: string;
|
|
705
|
+
#nonce: number;
|
|
706
|
+
#gasLimit: bigint;
|
|
707
|
+
#gasPrice: null | bigint;
|
|
708
|
+
#maxPriorityFeePerGas: null | bigint;
|
|
709
|
+
#maxFeePerGas: null | bigint;
|
|
710
|
+
#value: bigint;
|
|
711
|
+
#chainId: bigint;
|
|
712
|
+
#sig: null | Signature;
|
|
713
|
+
#accessList: null | AccessList;
|
|
714
|
+
#maxFeePerBlobGas: null | bigint;
|
|
715
|
+
#blobVersionedHashes: null | Array<string>;
|
|
716
|
+
#kzg: null | KzgLibrary;
|
|
717
|
+
#blobs: null | Array<Blob>;
|
|
718
|
+
#auths: null | Array<Authorization>;
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* The transaction type.
|
|
722
|
+
*
|
|
723
|
+
* If null, the type will be automatically inferred based on
|
|
724
|
+
* explicit properties.
|
|
725
|
+
*/
|
|
726
|
+
get type(): null | number { return this.#type; }
|
|
727
|
+
set type(value: null | number | string) {
|
|
728
|
+
switch (value) {
|
|
729
|
+
case null:
|
|
730
|
+
this.#type = null;
|
|
731
|
+
break;
|
|
732
|
+
case 0: case "legacy":
|
|
733
|
+
this.#type = 0;
|
|
734
|
+
break;
|
|
735
|
+
case 1: case "berlin": case "eip-2930":
|
|
736
|
+
this.#type = 1;
|
|
737
|
+
break;
|
|
738
|
+
case 2: case "london": case "eip-1559":
|
|
739
|
+
this.#type = 2;
|
|
740
|
+
break;
|
|
741
|
+
case 3: case "cancun": case "eip-4844":
|
|
742
|
+
this.#type = 3;
|
|
743
|
+
break;
|
|
744
|
+
case 4: case "pectra": case "eip-7702":
|
|
745
|
+
this.#type = 4;
|
|
746
|
+
break;
|
|
747
|
+
default:
|
|
748
|
+
assertArgument(false, "unsupported transaction type", "type", value);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* The name of the transaction type.
|
|
754
|
+
*/
|
|
755
|
+
get typeName(): null | string {
|
|
756
|
+
switch (this.type) {
|
|
757
|
+
case 0: return "legacy";
|
|
758
|
+
case 1: return "eip-2930";
|
|
759
|
+
case 2: return "eip-1559";
|
|
760
|
+
case 3: return "eip-4844";
|
|
761
|
+
case 4: return "eip-7702";
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
return null;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* The ``to`` address for the transaction or ``null`` if the
|
|
769
|
+
* transaction is an ``init`` transaction.
|
|
770
|
+
*/
|
|
771
|
+
get to(): null | string {
|
|
772
|
+
const value = this.#to;
|
|
773
|
+
if (value == null && this.type === 3) { return ZeroAddress; }
|
|
774
|
+
return value;
|
|
775
|
+
}
|
|
776
|
+
set to(value: null | string) {
|
|
777
|
+
this.#to = (value == null) ? null: getAddress(value);
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
/**
|
|
781
|
+
* The transaction nonce.
|
|
782
|
+
*/
|
|
783
|
+
get nonce(): number { return this.#nonce; }
|
|
784
|
+
set nonce(value: BigNumberish) { this.#nonce = getNumber(value, "value"); }
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* The gas limit.
|
|
788
|
+
*/
|
|
789
|
+
get gasLimit(): bigint { return this.#gasLimit; }
|
|
790
|
+
set gasLimit(value: BigNumberish) { this.#gasLimit = getBigInt(value); }
|
|
791
|
+
|
|
792
|
+
/**
|
|
793
|
+
* The gas price.
|
|
794
|
+
*
|
|
795
|
+
* On legacy networks this defines the fee that will be paid. On
|
|
796
|
+
* EIP-1559 networks, this should be ``null``.
|
|
797
|
+
*/
|
|
798
|
+
get gasPrice(): null | bigint {
|
|
799
|
+
const value = this.#gasPrice;
|
|
800
|
+
if (value == null && (this.type === 0 || this.type === 1)) { return BN_0; }
|
|
801
|
+
return value;
|
|
802
|
+
}
|
|
803
|
+
set gasPrice(value: null | BigNumberish) {
|
|
804
|
+
this.#gasPrice = (value == null) ? null: getBigInt(value, "gasPrice");
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* The maximum priority fee per unit of gas to pay. On legacy
|
|
809
|
+
* networks this should be ``null``.
|
|
810
|
+
*/
|
|
811
|
+
get maxPriorityFeePerGas(): null | bigint {
|
|
812
|
+
const value = this.#maxPriorityFeePerGas;
|
|
813
|
+
if (value == null) {
|
|
814
|
+
if (this.type === 2 || this.type === 3) { return BN_0; }
|
|
815
|
+
return null;
|
|
816
|
+
}
|
|
817
|
+
return value;
|
|
818
|
+
}
|
|
819
|
+
set maxPriorityFeePerGas(value: null | BigNumberish) {
|
|
820
|
+
this.#maxPriorityFeePerGas = (value == null) ? null: getBigInt(value, "maxPriorityFeePerGas");
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* The maximum total fee per unit of gas to pay. On legacy
|
|
825
|
+
* networks this should be ``null``.
|
|
826
|
+
*/
|
|
827
|
+
get maxFeePerGas(): null | bigint {
|
|
828
|
+
const value = this.#maxFeePerGas;
|
|
829
|
+
if (value == null) {
|
|
830
|
+
if (this.type === 2 || this.type === 3) { return BN_0; }
|
|
831
|
+
return null;
|
|
832
|
+
}
|
|
833
|
+
return value;
|
|
834
|
+
}
|
|
835
|
+
set maxFeePerGas(value: null | BigNumberish) {
|
|
836
|
+
this.#maxFeePerGas = (value == null) ? null: getBigInt(value, "maxFeePerGas");
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
/**
|
|
840
|
+
* The transaction data. For ``init`` transactions this is the
|
|
841
|
+
* deployment code.
|
|
842
|
+
*/
|
|
843
|
+
get data(): string { return this.#data; }
|
|
844
|
+
set data(value: BytesLike) { this.#data = hexlify(value); }
|
|
845
|
+
|
|
846
|
+
/**
|
|
847
|
+
* The amount of ether (in wei) to send in this transactions.
|
|
848
|
+
*/
|
|
849
|
+
get value(): bigint { return this.#value; }
|
|
850
|
+
set value(value: BigNumberish) {
|
|
851
|
+
this.#value = getBigInt(value, "value");
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* The chain ID this transaction is valid on.
|
|
856
|
+
*/
|
|
857
|
+
get chainId(): bigint { return this.#chainId; }
|
|
858
|
+
set chainId(value: BigNumberish) { this.#chainId = getBigInt(value); }
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* If signed, the signature for this transaction.
|
|
862
|
+
*/
|
|
863
|
+
get signature(): null | Signature { return this.#sig || null; }
|
|
864
|
+
set signature(value: null | SignatureLike) {
|
|
865
|
+
this.#sig = (value == null) ? null: Signature.from(value);
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/**
|
|
869
|
+
* The access list.
|
|
870
|
+
*
|
|
871
|
+
* An access list permits discounted (but pre-paid) access to
|
|
872
|
+
* bytecode and state variable access within contract execution.
|
|
873
|
+
*/
|
|
874
|
+
get accessList(): null | AccessList {
|
|
875
|
+
const value = this.#accessList || null;
|
|
876
|
+
if (value == null) {
|
|
877
|
+
if (this.type === 1 || this.type === 2 || this.type === 3) {
|
|
878
|
+
// @TODO: in v7, this should assign the value or become
|
|
879
|
+
// a live object itself, otherwise mutation is inconsistent
|
|
880
|
+
return [ ];
|
|
881
|
+
}
|
|
882
|
+
return null;
|
|
883
|
+
}
|
|
884
|
+
return value;
|
|
885
|
+
}
|
|
886
|
+
set accessList(value: null | AccessListish) {
|
|
887
|
+
this.#accessList = (value == null) ? null: accessListify(value);
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
get authorizationList(): null | Array<Authorization> {
|
|
891
|
+
const value = this.#auths || null;
|
|
892
|
+
if (value == null) {
|
|
893
|
+
if (this.type === 4) {
|
|
894
|
+
// @TODO: in v7, this should become a live object itself,
|
|
895
|
+
// otherwise mutation is inconsistent
|
|
896
|
+
return [ ];
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
return value;
|
|
900
|
+
}
|
|
901
|
+
set authorizationList(auths: null | Array<AuthorizationLike>) {
|
|
902
|
+
this.#auths = (auths == null) ? null: auths.map((a) =>
|
|
903
|
+
authorizationify(a));
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
/**
|
|
907
|
+
* The max fee per blob gas for Cancun transactions.
|
|
908
|
+
*/
|
|
909
|
+
get maxFeePerBlobGas(): null | bigint {
|
|
910
|
+
const value = this.#maxFeePerBlobGas;
|
|
911
|
+
if (value == null && this.type === 3) { return BN_0; }
|
|
912
|
+
return value;
|
|
913
|
+
}
|
|
914
|
+
set maxFeePerBlobGas(value: null | BigNumberish) {
|
|
915
|
+
this.#maxFeePerBlobGas = (value == null) ? null: getBigInt(value, "maxFeePerBlobGas");
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
/**
|
|
919
|
+
* The BLOb versioned hashes for Cancun transactions.
|
|
920
|
+
*/
|
|
921
|
+
get blobVersionedHashes(): null | Array<string> {
|
|
922
|
+
// @TODO: Mutation is inconsistent; if unset, the returned value
|
|
923
|
+
// cannot mutate the object, if set it can
|
|
924
|
+
let value = this.#blobVersionedHashes;
|
|
925
|
+
if (value == null && this.type === 3) { return [ ]; }
|
|
926
|
+
return value;
|
|
927
|
+
}
|
|
928
|
+
set blobVersionedHashes(value: null | Array<string>) {
|
|
929
|
+
if (value != null) {
|
|
930
|
+
assertArgument(Array.isArray(value), "blobVersionedHashes must be an Array", "value", value);
|
|
931
|
+
value = value.slice();
|
|
932
|
+
for (let i = 0; i < value.length; i++) {
|
|
933
|
+
assertArgument(isHexString(value[i], 32), "invalid blobVersionedHash", `value[${ i }]`, value[i]);
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
this.#blobVersionedHashes = value;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* The BLObs for the Transaction, if any.
|
|
941
|
+
*
|
|
942
|
+
* If ``blobs`` is non-``null``, then the [[seriailized]]
|
|
943
|
+
* will return the network formatted sidecar, otherwise it
|
|
944
|
+
* will return the standard [[link-eip-2718]] payload. The
|
|
945
|
+
* [[unsignedSerialized]] is unaffected regardless.
|
|
946
|
+
*
|
|
947
|
+
* When setting ``blobs``, either fully valid [[Blob]] objects
|
|
948
|
+
* may be specified (i.e. correctly padded, with correct
|
|
949
|
+
* committments and proofs) or a raw [[BytesLike]] may
|
|
950
|
+
* be provided.
|
|
951
|
+
*
|
|
952
|
+
* If raw [[BytesLike]] are provided, the [[kzg]] property **must**
|
|
953
|
+
* be already set. The blob will be correctly padded and the
|
|
954
|
+
* [[KzgLibrary]] will be used to compute the committment and
|
|
955
|
+
* proof for the blob.
|
|
956
|
+
*
|
|
957
|
+
* A BLOb is a sequence of field elements, each of which must
|
|
958
|
+
* be within the BLS field modulo, so some additional processing
|
|
959
|
+
* may be required to encode arbitrary data to ensure each 32 byte
|
|
960
|
+
* field is within the valid range.
|
|
961
|
+
*
|
|
962
|
+
* Setting this automatically populates [[blobVersionedHashes]],
|
|
963
|
+
* overwriting any existing values. Setting this to ``null``
|
|
964
|
+
* does **not** remove the [[blobVersionedHashes]], leaving them
|
|
965
|
+
* present.
|
|
966
|
+
*/
|
|
967
|
+
get blobs(): null | Array<Blob> {
|
|
968
|
+
if (this.#blobs == null) { return null; }
|
|
969
|
+
return this.#blobs.map((b) => Object.assign({ }, b));
|
|
970
|
+
}
|
|
971
|
+
set blobs(_blobs: null | Array<BlobLike>) {
|
|
972
|
+
if (_blobs == null) {
|
|
973
|
+
this.#blobs = null;
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
const blobs: Array<Blob> = [ ];
|
|
978
|
+
const versionedHashes: Array<string> = [ ];
|
|
979
|
+
for (let i = 0; i < _blobs.length; i++) {
|
|
980
|
+
const blob = _blobs[i];
|
|
981
|
+
|
|
982
|
+
if (isBytesLike(blob)) {
|
|
983
|
+
assert(this.#kzg, "adding a raw blob requires a KZG library", "UNSUPPORTED_OPERATION", {
|
|
984
|
+
operation: "set blobs()"
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
let data = getBytes(blob);
|
|
988
|
+
assertArgument(data.length <= BLOB_SIZE, "blob is too large", `blobs[${ i }]`, blob);
|
|
989
|
+
|
|
990
|
+
// Pad blob if necessary
|
|
991
|
+
if (data.length !== BLOB_SIZE) {
|
|
992
|
+
const padded = new Uint8Array(BLOB_SIZE);
|
|
993
|
+
padded.set(data);
|
|
994
|
+
data = padded;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
const commit = this.#kzg.blobToKzgCommitment(data);
|
|
998
|
+
const proof = hexlify(this.#kzg.computeBlobKzgProof(data, commit));
|
|
999
|
+
|
|
1000
|
+
blobs.push({
|
|
1001
|
+
data: hexlify(data),
|
|
1002
|
+
commitment: hexlify(commit),
|
|
1003
|
+
proof
|
|
1004
|
+
});
|
|
1005
|
+
versionedHashes.push(getVersionedHash(1, commit));
|
|
1006
|
+
|
|
1007
|
+
} else {
|
|
1008
|
+
const commit = hexlify(blob.commitment);
|
|
1009
|
+
blobs.push({
|
|
1010
|
+
data: hexlify(blob.data),
|
|
1011
|
+
commitment: commit,
|
|
1012
|
+
proof: hexlify(blob.proof)
|
|
1013
|
+
});
|
|
1014
|
+
versionedHashes.push(getVersionedHash(1, commit));
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
this.#blobs = blobs;
|
|
1019
|
+
this.#blobVersionedHashes = versionedHashes;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
get kzg(): null | KzgLibrary { return this.#kzg; }
|
|
1023
|
+
set kzg(kzg: null | KzgLibraryLike) {
|
|
1024
|
+
if (kzg == null) {
|
|
1025
|
+
this.#kzg = null;
|
|
1026
|
+
} else {
|
|
1027
|
+
this.#kzg = getKzgLibrary(kzg);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
/**
|
|
1032
|
+
* Creates a new Transaction with default values.
|
|
1033
|
+
*/
|
|
1034
|
+
constructor() {
|
|
1035
|
+
this.#type = null;
|
|
1036
|
+
this.#to = null;
|
|
1037
|
+
this.#nonce = 0;
|
|
1038
|
+
this.#gasLimit = BN_0;
|
|
1039
|
+
this.#gasPrice = null;
|
|
1040
|
+
this.#maxPriorityFeePerGas = null;
|
|
1041
|
+
this.#maxFeePerGas = null;
|
|
1042
|
+
this.#data = "0x";
|
|
1043
|
+
this.#value = BN_0;
|
|
1044
|
+
this.#chainId = BN_0;
|
|
1045
|
+
this.#sig = null;
|
|
1046
|
+
this.#accessList = null;
|
|
1047
|
+
this.#maxFeePerBlobGas = null;
|
|
1048
|
+
this.#blobVersionedHashes = null;
|
|
1049
|
+
this.#kzg = null;
|
|
1050
|
+
this.#blobs = null;
|
|
1051
|
+
this.#auths = null;
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* The transaction hash, if signed. Otherwise, ``null``.
|
|
1056
|
+
*/
|
|
1057
|
+
get hash(): null | string {
|
|
1058
|
+
if (this.signature == null) { return null; }
|
|
1059
|
+
return keccak256(this.#getSerialized(true, false));
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
/**
|
|
1063
|
+
* The pre-image hash of this transaction.
|
|
1064
|
+
*
|
|
1065
|
+
* This is the digest that a [[Signer]] must sign to authorize
|
|
1066
|
+
* this transaction.
|
|
1067
|
+
*/
|
|
1068
|
+
get unsignedHash(): string {
|
|
1069
|
+
return keccak256(this.unsignedSerialized);
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* The sending address, if signed. Otherwise, ``null``.
|
|
1074
|
+
*/
|
|
1075
|
+
get from(): null | string {
|
|
1076
|
+
if (this.signature == null) { return null; }
|
|
1077
|
+
return recoverAddress(this.unsignedHash, this.signature);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* The public key of the sender, if signed. Otherwise, ``null``.
|
|
1082
|
+
*/
|
|
1083
|
+
get fromPublicKey(): null | string {
|
|
1084
|
+
if (this.signature == null) { return null; }
|
|
1085
|
+
return SigningKey.recoverPublicKey(this.unsignedHash, this.signature);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Returns true if signed.
|
|
1090
|
+
*
|
|
1091
|
+
* This provides a Type Guard that properties requiring a signed
|
|
1092
|
+
* transaction are non-null.
|
|
1093
|
+
*/
|
|
1094
|
+
isSigned(): this is (Transaction & { type: number, typeName: string, from: string, signature: Signature }) {
|
|
1095
|
+
return this.signature != null;
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
#getSerialized(signed: boolean, sidecar: boolean): string {
|
|
1099
|
+
assert(!signed || this.signature != null, "cannot serialize unsigned transaction; maybe you meant .unsignedSerialized", "UNSUPPORTED_OPERATION", { operation: ".serialized"});
|
|
1100
|
+
|
|
1101
|
+
const sig = signed ? this.signature: null;
|
|
1102
|
+
switch (this.inferType()) {
|
|
1103
|
+
case 0:
|
|
1104
|
+
return _serializeLegacy(this, sig);
|
|
1105
|
+
case 1:
|
|
1106
|
+
return _serializeEip2930(this, sig);
|
|
1107
|
+
case 2:
|
|
1108
|
+
return _serializeEip1559(this, sig);
|
|
1109
|
+
case 3:
|
|
1110
|
+
return _serializeEip4844(this, sig, sidecar ? this.blobs: null);
|
|
1111
|
+
case 4:
|
|
1112
|
+
return _serializeEip7702(this, sig);
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
assert(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: ".serialized" });
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
/**
|
|
1119
|
+
* The serialized transaction.
|
|
1120
|
+
*
|
|
1121
|
+
* This throws if the transaction is unsigned. For the pre-image,
|
|
1122
|
+
* use [[unsignedSerialized]].
|
|
1123
|
+
*/
|
|
1124
|
+
get serialized(): string {
|
|
1125
|
+
return this.#getSerialized(true, true);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
/**
|
|
1129
|
+
* The transaction pre-image.
|
|
1130
|
+
*
|
|
1131
|
+
* The hash of this is the digest which needs to be signed to
|
|
1132
|
+
* authorize this transaction.
|
|
1133
|
+
*/
|
|
1134
|
+
get unsignedSerialized(): string {
|
|
1135
|
+
return this.#getSerialized(false, false);
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
/**
|
|
1139
|
+
* Return the most "likely" type; currently the highest
|
|
1140
|
+
* supported transaction type.
|
|
1141
|
+
*/
|
|
1142
|
+
inferType(): number {
|
|
1143
|
+
const types = this.inferTypes();
|
|
1144
|
+
|
|
1145
|
+
// Prefer London (EIP-1559) over Cancun (BLOb)
|
|
1146
|
+
if (types.indexOf(2) >= 0) { return 2; }
|
|
1147
|
+
|
|
1148
|
+
// Return the highest inferred type
|
|
1149
|
+
return <number>(types.pop());
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Validates the explicit properties and returns a list of compatible
|
|
1154
|
+
* transaction types.
|
|
1155
|
+
*/
|
|
1156
|
+
inferTypes(): Array<number> {
|
|
1157
|
+
|
|
1158
|
+
// Checks that there are no conflicting properties set
|
|
1159
|
+
const hasGasPrice = this.gasPrice != null;
|
|
1160
|
+
const hasFee = (this.maxFeePerGas != null || this.maxPriorityFeePerGas != null);
|
|
1161
|
+
const hasAccessList = (this.accessList != null);
|
|
1162
|
+
const hasBlob = (this.#maxFeePerBlobGas != null || this.#blobVersionedHashes);
|
|
1163
|
+
|
|
1164
|
+
//if (hasGasPrice && hasFee) {
|
|
1165
|
+
// throw new Error("transaction cannot have gasPrice and maxFeePerGas");
|
|
1166
|
+
//}
|
|
1167
|
+
|
|
1168
|
+
if (this.maxFeePerGas != null && this.maxPriorityFeePerGas != null) {
|
|
1169
|
+
assert(this.maxFeePerGas >= this.maxPriorityFeePerGas, "priorityFee cannot be more than maxFee", "BAD_DATA", { value: this });
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
//if (this.type === 2 && hasGasPrice) {
|
|
1173
|
+
// throw new Error("eip-1559 transaction cannot have gasPrice");
|
|
1174
|
+
//}
|
|
1175
|
+
|
|
1176
|
+
assert(!hasFee || (this.type !== 0 && this.type !== 1), "transaction type cannot have maxFeePerGas or maxPriorityFeePerGas", "BAD_DATA", { value: this });
|
|
1177
|
+
assert(this.type !== 0 || !hasAccessList, "legacy transaction cannot have accessList", "BAD_DATA", { value: this })
|
|
1178
|
+
|
|
1179
|
+
const types: Array<number> = [ ];
|
|
1180
|
+
|
|
1181
|
+
// Explicit type
|
|
1182
|
+
if (this.type != null) {
|
|
1183
|
+
types.push(this.type);
|
|
1184
|
+
|
|
1185
|
+
} else {
|
|
1186
|
+
if (this.authorizationList && this.authorizationList.length) {
|
|
1187
|
+
types.push(4);
|
|
1188
|
+
} else if (hasFee) {
|
|
1189
|
+
types.push(2);
|
|
1190
|
+
} else if (hasGasPrice) {
|
|
1191
|
+
types.push(1);
|
|
1192
|
+
if (!hasAccessList) { types.push(0); }
|
|
1193
|
+
} else if (hasAccessList) {
|
|
1194
|
+
types.push(1);
|
|
1195
|
+
types.push(2);
|
|
1196
|
+
} else if (hasBlob && this.to) {
|
|
1197
|
+
types.push(3);
|
|
1198
|
+
} else {
|
|
1199
|
+
types.push(0);
|
|
1200
|
+
types.push(1);
|
|
1201
|
+
types.push(2);
|
|
1202
|
+
types.push(3);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
types.sort();
|
|
1207
|
+
|
|
1208
|
+
return types;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
/**
|
|
1212
|
+
* Returns true if this transaction is a legacy transaction (i.e.
|
|
1213
|
+
* ``type === 0``).
|
|
1214
|
+
*
|
|
1215
|
+
* This provides a Type Guard that the related properties are
|
|
1216
|
+
* non-null.
|
|
1217
|
+
*/
|
|
1218
|
+
isLegacy(): this is (Transaction & { type: 0, gasPrice: bigint }) {
|
|
1219
|
+
return (this.type === 0);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
/**
|
|
1223
|
+
* Returns true if this transaction is berlin hardform transaction (i.e.
|
|
1224
|
+
* ``type === 1``).
|
|
1225
|
+
*
|
|
1226
|
+
* This provides a Type Guard that the related properties are
|
|
1227
|
+
* non-null.
|
|
1228
|
+
*/
|
|
1229
|
+
isBerlin(): this is (Transaction & { type: 1, gasPrice: bigint, accessList: AccessList }) {
|
|
1230
|
+
return (this.type === 1);
|
|
1231
|
+
}
|
|
1232
|
+
|
|
1233
|
+
/**
|
|
1234
|
+
* Returns true if this transaction is london hardform transaction (i.e.
|
|
1235
|
+
* ``type === 2``).
|
|
1236
|
+
*
|
|
1237
|
+
* This provides a Type Guard that the related properties are
|
|
1238
|
+
* non-null.
|
|
1239
|
+
*/
|
|
1240
|
+
isLondon(): this is (Transaction & { type: 2, accessList: AccessList, maxFeePerGas: bigint, maxPriorityFeePerGas: bigint }) {
|
|
1241
|
+
return (this.type === 2);
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
/**
|
|
1245
|
+
* Returns true if this transaction is an [[link-eip-4844]] BLOB
|
|
1246
|
+
* transaction.
|
|
1247
|
+
*
|
|
1248
|
+
* This provides a Type Guard that the related properties are
|
|
1249
|
+
* non-null.
|
|
1250
|
+
*/
|
|
1251
|
+
isCancun(): this is (Transaction & { type: 3, to: string, accessList: AccessList, maxFeePerGas: bigint, maxPriorityFeePerGas: bigint, maxFeePerBlobGas: bigint, blobVersionedHashes: Array<string> }) {
|
|
1252
|
+
return (this.type === 3);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
/**
|
|
1256
|
+
* Create a copy of this transaciton.
|
|
1257
|
+
*/
|
|
1258
|
+
clone(): Transaction {
|
|
1259
|
+
return Transaction.from(this);
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* Return a JSON-friendly object.
|
|
1264
|
+
*/
|
|
1265
|
+
toJSON(): any {
|
|
1266
|
+
const s = (v: null | bigint) => {
|
|
1267
|
+
if (v == null) { return null; }
|
|
1268
|
+
return v.toString();
|
|
1269
|
+
};
|
|
1270
|
+
|
|
1271
|
+
return {
|
|
1272
|
+
type: this.type,
|
|
1273
|
+
to: this.to,
|
|
1274
|
+
// from: this.from,
|
|
1275
|
+
data: this.data,
|
|
1276
|
+
nonce: this.nonce,
|
|
1277
|
+
gasLimit: s(this.gasLimit),
|
|
1278
|
+
gasPrice: s(this.gasPrice),
|
|
1279
|
+
maxPriorityFeePerGas: s(this.maxPriorityFeePerGas),
|
|
1280
|
+
maxFeePerGas: s(this.maxFeePerGas),
|
|
1281
|
+
value: s(this.value),
|
|
1282
|
+
chainId: s(this.chainId),
|
|
1283
|
+
sig: this.signature ? this.signature.toJSON(): null,
|
|
1284
|
+
accessList: this.accessList
|
|
1285
|
+
};
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Create a **Transaction** from a serialized transaction or a
|
|
1290
|
+
* Transaction-like object.
|
|
1291
|
+
*/
|
|
1292
|
+
static from(tx?: string | TransactionLike<string>): Transaction {
|
|
1293
|
+
if (tx == null) { return new Transaction(); }
|
|
1294
|
+
|
|
1295
|
+
if (typeof(tx) === "string") {
|
|
1296
|
+
const payload = getBytes(tx);
|
|
1297
|
+
|
|
1298
|
+
if (payload[0] >= 0x7f) { // @TODO: > vs >= ??
|
|
1299
|
+
return Transaction.from(_parseLegacy(payload));
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
switch(payload[0]) {
|
|
1303
|
+
case 1: return Transaction.from(_parseEip2930(payload));
|
|
1304
|
+
case 2: return Transaction.from(_parseEip1559(payload));
|
|
1305
|
+
case 3: return Transaction.from(_parseEip4844(payload));
|
|
1306
|
+
case 4: return Transaction.from(_parseEip7702(payload));
|
|
1307
|
+
}
|
|
1308
|
+
assert(false, "unsupported transaction type", "UNSUPPORTED_OPERATION", { operation: "from" });
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
const result = new Transaction();
|
|
1312
|
+
if (tx.type != null) { result.type = tx.type; }
|
|
1313
|
+
if (tx.to != null) { result.to = tx.to; }
|
|
1314
|
+
if (tx.nonce != null) { result.nonce = tx.nonce; }
|
|
1315
|
+
if (tx.gasLimit != null) { result.gasLimit = tx.gasLimit; }
|
|
1316
|
+
if (tx.gasPrice != null) { result.gasPrice = tx.gasPrice; }
|
|
1317
|
+
if (tx.maxPriorityFeePerGas != null) { result.maxPriorityFeePerGas = tx.maxPriorityFeePerGas; }
|
|
1318
|
+
if (tx.maxFeePerGas != null) { result.maxFeePerGas = tx.maxFeePerGas; }
|
|
1319
|
+
if (tx.maxFeePerBlobGas != null) { result.maxFeePerBlobGas = tx.maxFeePerBlobGas; }
|
|
1320
|
+
if (tx.data != null) { result.data = tx.data; }
|
|
1321
|
+
if (tx.value != null) { result.value = tx.value; }
|
|
1322
|
+
if (tx.chainId != null) { result.chainId = tx.chainId; }
|
|
1323
|
+
if (tx.signature != null) { result.signature = Signature.from(tx.signature); }
|
|
1324
|
+
if (tx.accessList != null) { result.accessList = tx.accessList; }
|
|
1325
|
+
if (tx.authorizationList != null) {
|
|
1326
|
+
result.authorizationList = tx.authorizationList;
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
// This will get overwritten by blobs, if present
|
|
1330
|
+
if (tx.blobVersionedHashes != null) { result.blobVersionedHashes = tx.blobVersionedHashes; }
|
|
1331
|
+
|
|
1332
|
+
// Make sure we assign the kzg before assigning blobs, which
|
|
1333
|
+
// require the library in the event raw blob data is provided.
|
|
1334
|
+
if (tx.kzg != null) { result.kzg = tx.kzg; }
|
|
1335
|
+
if (tx.blobs != null) { result.blobs = tx.blobs; }
|
|
1336
|
+
|
|
1337
|
+
if (tx.hash != null) {
|
|
1338
|
+
assertArgument(result.isSigned(), "unsigned transaction cannot define '.hash'", "tx", tx);
|
|
1339
|
+
assertArgument(result.hash === tx.hash, "hash mismatch", "tx", tx);
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
if (tx.from != null) {
|
|
1343
|
+
assertArgument(result.isSigned(), "unsigned transaction cannot define '.from'", "tx", tx);
|
|
1344
|
+
assertArgument(result.from.toLowerCase() === (tx.from || "").toLowerCase(), "from mismatch", "tx", tx);
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
return result;
|
|
1348
|
+
}
|
|
1349
|
+
}
|