viem 2.7.22 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/_cjs/accounts/utils/sign.js +1 -0
- package/_cjs/accounts/utils/sign.js.map +1 -1
- package/_cjs/accounts/utils/signTransaction.js +11 -2
- package/_cjs/accounts/utils/signTransaction.js.map +1 -1
- package/_cjs/actions/index.js +4 -2
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/public/call.js +3 -1
- package/_cjs/actions/public/call.js.map +1 -1
- package/_cjs/actions/public/estimateGas.js +3 -1
- package/_cjs/actions/public/estimateGas.js.map +1 -1
- package/_cjs/actions/public/getBlobBaseFee.js +11 -0
- package/_cjs/actions/public/getBlobBaseFee.js.map +1 -0
- package/_cjs/actions/wallet/prepareTransactionRequest.js +11 -2
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendRawTransaction.js.map +1 -1
- package/_cjs/actions/wallet/sendTransaction.js +7 -8
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/signTransaction.js +7 -6
- package/_cjs/actions/wallet/signTransaction.js.map +1 -1
- package/_cjs/chains/celo/serializers.js +10 -15
- package/_cjs/chains/celo/serializers.js.map +1 -1
- package/_cjs/chains/definitions/plumeTestnet.js +30 -0
- package/_cjs/chains/definitions/plumeTestnet.js.map +1 -0
- package/_cjs/chains/index.js +5 -3
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/chains/opStack/actions/estimateL1Fee.js +1 -10
- package/_cjs/chains/opStack/actions/estimateL1Fee.js.map +1 -1
- package/_cjs/chains/opStack/actions/estimateL1Gas.js +1 -10
- package/_cjs/chains/opStack/actions/estimateL1Gas.js.map +1 -1
- package/_cjs/chains/opStack/actions/finalizeWithdrawal.js +1 -1
- package/_cjs/chains/opStack/actions/finalizeWithdrawal.js.map +1 -1
- package/_cjs/chains/opStack/actions/proveWithdrawal.js +1 -1
- package/_cjs/chains/opStack/actions/proveWithdrawal.js.map +1 -1
- package/_cjs/chains/opStack/serializers.js +3 -3
- package/_cjs/chains/opStack/serializers.js.map +1 -1
- package/_cjs/chains/zksync/actions/sendTransaction.js.map +1 -1
- package/_cjs/chains/zksync/actions/signEip712Transaction.js.map +1 -1
- package/_cjs/chains/zksync/serializers.js +6 -6
- package/_cjs/chains/zksync/serializers.js.map +1 -1
- package/_cjs/clients/decorators/public.js.map +1 -1
- package/_cjs/clients/decorators/wallet.js.map +1 -1
- package/_cjs/constants/blob.js +11 -0
- package/_cjs/constants/blob.js.map +1 -0
- package/_cjs/constants/kzg.js +7 -0
- package/_cjs/constants/kzg.js.map +1 -0
- package/_cjs/errors/blob.js +63 -0
- package/_cjs/errors/blob.js.map +1 -0
- package/_cjs/errors/transaction.js +1 -0
- package/_cjs/errors/transaction.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/errors/version.js.map +1 -1
- package/_cjs/index.js +22 -2
- package/_cjs/index.js.map +1 -1
- package/_cjs/node/index.js +3 -1
- package/_cjs/node/index.js.map +1 -1
- package/_cjs/node/trustedSetups.js +7 -0
- package/_cjs/node/trustedSetups.js.map +1 -0
- package/_cjs/types/eip4844.js +3 -0
- package/_cjs/types/eip4844.js.map +1 -0
- package/_cjs/types/kzg.js +3 -0
- package/_cjs/types/kzg.js.map +1 -0
- package/_cjs/utils/blob/blobsToCommitments.js +20 -0
- package/_cjs/utils/blob/blobsToCommitments.js.map +1 -0
- package/_cjs/utils/blob/blobsToProofs.js +26 -0
- package/_cjs/utils/blob/blobsToProofs.js.map +1 -0
- package/_cjs/utils/blob/commitmentToVersionedHash.js +14 -0
- package/_cjs/utils/blob/commitmentToVersionedHash.js.map +1 -0
- package/_cjs/utils/blob/commitmentsToVersionedHashes.js +19 -0
- package/_cjs/utils/blob/commitmentsToVersionedHashes.js.map +1 -0
- package/_cjs/utils/blob/fromBlobs.js +36 -0
- package/_cjs/utils/blob/fromBlobs.js.map +1 -0
- package/_cjs/utils/blob/sidecarsToVersionedHashes.js +19 -0
- package/_cjs/utils/blob/sidecarsToVersionedHashes.js.map +1 -0
- package/_cjs/utils/blob/toBlobSidecars.js +22 -0
- package/_cjs/utils/blob/toBlobSidecars.js.map +1 -0
- package/_cjs/utils/blob/toBlobs.js +48 -0
- package/_cjs/utils/blob/toBlobs.js.map +1 -0
- package/_cjs/utils/encoding/toRlp.js.map +1 -1
- package/_cjs/utils/formatters/transaction.js.map +1 -1
- package/_cjs/utils/formatters/transactionRequest.js +22 -25
- package/_cjs/utils/formatters/transactionRequest.js.map +1 -1
- package/_cjs/utils/kzg/defineKzg.js +11 -0
- package/_cjs/utils/kzg/defineKzg.js.map +1 -0
- package/_cjs/utils/kzg/setupKzg.js +17 -0
- package/_cjs/utils/kzg/setupKzg.js.map +1 -0
- package/_cjs/utils/signature/compactSignatureToSignature.js +3 -3
- package/_cjs/utils/signature/compactSignatureToSignature.js.map +1 -1
- package/_cjs/utils/signature/hexToSignature.js +6 -1
- package/_cjs/utils/signature/hexToSignature.js.map +1 -1
- package/_cjs/utils/signature/signatureToCompactSignature.js +3 -3
- package/_cjs/utils/signature/signatureToCompactSignature.js.map +1 -1
- package/_cjs/utils/signature/signatureToHex.js +9 -3
- package/_cjs/utils/signature/signatureToHex.js.map +1 -1
- package/_cjs/utils/transaction/assertTransaction.js +26 -1
- package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
- package/_cjs/utils/transaction/getSerializedTransactionType.js +2 -0
- package/_cjs/utils/transaction/getSerializedTransactionType.js.map +1 -1
- package/_cjs/utils/transaction/getTransactionType.js +7 -1
- package/_cjs/utils/transaction/getTransactionType.js.map +1 -1
- package/_cjs/utils/transaction/parseTransaction.js +73 -0
- package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/_cjs/utils/transaction/serializeAccessList.js.map +1 -1
- package/_cjs/utils/transaction/serializeTransaction.js +84 -21
- package/_cjs/utils/transaction/serializeTransaction.js.map +1 -1
- package/_esm/accounts/utils/sign.js +1 -0
- package/_esm/accounts/utils/sign.js.map +1 -1
- package/_esm/accounts/utils/signTransaction.js +13 -2
- package/_esm/accounts/utils/signTransaction.js.map +1 -1
- package/_esm/actions/index.js +1 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/public/call.js +3 -1
- package/_esm/actions/public/call.js.map +1 -1
- package/_esm/actions/public/estimateGas.js +3 -1
- package/_esm/actions/public/estimateGas.js.map +1 -1
- package/_esm/actions/public/getBlobBaseFee.js +27 -0
- package/_esm/actions/public/getBlobBaseFee.js.map +1 -0
- package/_esm/actions/wallet/prepareTransactionRequest.js +12 -2
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendRawTransaction.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +7 -8
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/signTransaction.js +6 -5
- package/_esm/actions/wallet/signTransaction.js.map +1 -1
- package/_esm/chains/celo/serializers.js +10 -17
- package/_esm/chains/celo/serializers.js.map +1 -1
- package/_esm/chains/definitions/plumeTestnet.js +27 -0
- package/_esm/chains/definitions/plumeTestnet.js.map +1 -0
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/chains/opStack/actions/estimateL1Fee.js +1 -10
- package/_esm/chains/opStack/actions/estimateL1Fee.js.map +1 -1
- package/_esm/chains/opStack/actions/estimateL1Gas.js +1 -10
- package/_esm/chains/opStack/actions/estimateL1Gas.js.map +1 -1
- package/_esm/chains/opStack/actions/finalizeWithdrawal.js +1 -1
- package/_esm/chains/opStack/actions/finalizeWithdrawal.js.map +1 -1
- package/_esm/chains/opStack/actions/proveWithdrawal.js +1 -1
- package/_esm/chains/opStack/actions/proveWithdrawal.js.map +1 -1
- package/_esm/chains/opStack/serializers.js +2 -2
- package/_esm/chains/opStack/serializers.js.map +1 -1
- package/_esm/chains/zksync/actions/sendTransaction.js.map +1 -1
- package/_esm/chains/zksync/actions/signEip712Transaction.js.map +1 -1
- package/_esm/chains/zksync/serializers.js +6 -6
- package/_esm/chains/zksync/serializers.js.map +1 -1
- package/_esm/clients/decorators/public.js.map +1 -1
- package/_esm/clients/decorators/wallet.js.map +1 -1
- package/_esm/constants/blob.js +16 -0
- package/_esm/constants/blob.js.map +1 -0
- package/_esm/constants/kzg.js +7 -0
- package/_esm/constants/kzg.js.map +1 -0
- package/_esm/errors/blob.js +56 -0
- package/_esm/errors/blob.js.map +1 -0
- package/_esm/errors/transaction.js +1 -0
- package/_esm/errors/transaction.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/errors/version.js.map +1 -1
- package/_esm/index.js +10 -0
- package/_esm/index.js.map +1 -1
- package/_esm/node/index.js +1 -0
- package/_esm/node/index.js.map +1 -1
- package/_esm/node/trustedSetups.js +4 -0
- package/_esm/node/trustedSetups.js.map +1 -0
- package/_esm/types/eip4844.js +2 -0
- package/_esm/types/eip4844.js.map +1 -0
- package/_esm/types/kzg.js +2 -0
- package/_esm/types/kzg.js.map +1 -0
- package/_esm/utils/blob/blobsToCommitments.js +28 -0
- package/_esm/utils/blob/blobsToCommitments.js.map +1 -0
- package/_esm/utils/blob/blobsToProofs.js +38 -0
- package/_esm/utils/blob/blobsToProofs.js.map +1 -0
- package/_esm/utils/blob/commitmentToVersionedHash.js +27 -0
- package/_esm/utils/blob/commitmentToVersionedHash.js.map +1 -0
- package/_esm/utils/blob/commitmentsToVersionedHashes.js +32 -0
- package/_esm/utils/blob/commitmentsToVersionedHashes.js.map +1 -0
- package/_esm/utils/blob/fromBlobs.js +33 -0
- package/_esm/utils/blob/fromBlobs.js.map +1 -0
- package/_esm/utils/blob/sidecarsToVersionedHashes.js +26 -0
- package/_esm/utils/blob/sidecarsToVersionedHashes.js.map +1 -0
- package/_esm/utils/blob/toBlobSidecars.js +45 -0
- package/_esm/utils/blob/toBlobSidecars.js.map +1 -0
- package/_esm/utils/blob/toBlobs.js +58 -0
- package/_esm/utils/blob/toBlobs.js.map +1 -0
- package/_esm/utils/encoding/toRlp.js.map +1 -1
- package/_esm/utils/formatters/transaction.js.map +1 -1
- package/_esm/utils/formatters/transactionRequest.js +23 -26
- package/_esm/utils/formatters/transactionRequest.js.map +1 -1
- package/_esm/utils/kzg/defineKzg.js +21 -0
- package/_esm/utils/kzg/defineKzg.js.map +1 -0
- package/_esm/utils/kzg/setupKzg.js +25 -0
- package/_esm/utils/kzg/setupKzg.js.map +1 -0
- package/_esm/utils/signature/compactSignatureToSignature.js +3 -3
- package/_esm/utils/signature/compactSignatureToSignature.js.map +1 -1
- package/_esm/utils/signature/hexToSignature.js +6 -1
- package/_esm/utils/signature/hexToSignature.js.map +1 -1
- package/_esm/utils/signature/signatureToCompactSignature.js +4 -4
- package/_esm/utils/signature/signatureToCompactSignature.js.map +1 -1
- package/_esm/utils/signature/signatureToHex.js +11 -4
- package/_esm/utils/signature/signatureToHex.js.map +1 -1
- package/_esm/utils/transaction/assertTransaction.js +24 -0
- package/_esm/utils/transaction/assertTransaction.js.map +1 -1
- package/_esm/utils/transaction/getSerializedTransactionType.js +2 -0
- package/_esm/utils/transaction/getSerializedTransactionType.js.map +1 -1
- package/_esm/utils/transaction/getTransactionType.js +7 -1
- package/_esm/utils/transaction/getTransactionType.js.map +1 -1
- package/_esm/utils/transaction/parseTransaction.js +74 -1
- package/_esm/utils/transaction/parseTransaction.js.map +1 -1
- package/_esm/utils/transaction/serializeAccessList.js.map +1 -1
- package/_esm/utils/transaction/serializeTransaction.js +85 -22
- package/_esm/utils/transaction/serializeTransaction.js.map +1 -1
- package/_types/accounts/types.d.ts +3 -3
- package/_types/accounts/types.d.ts.map +1 -1
- package/_types/accounts/utils/sign.d.ts.map +1 -1
- package/_types/accounts/utils/signTransaction.d.ts +5 -5
- package/_types/accounts/utils/signTransaction.d.ts.map +1 -1
- package/_types/actions/index.d.ts +1 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/public/call.d.ts.map +1 -1
- package/_types/actions/public/estimateGas.d.ts.map +1 -1
- package/_types/actions/public/getBlobBaseFee.d.ts +30 -0
- package/_types/actions/public/getBlobBaseFee.d.ts.map +1 -0
- package/_types/actions/wallet/prepareTransactionRequest.d.ts +27 -8
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendRawTransaction.d.ts +3 -5
- package/_types/actions/wallet/sendRawTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts +4 -2
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/signTransaction.d.ts +5 -2
- package/_types/actions/wallet/signTransaction.d.ts.map +1 -1
- package/_types/chains/celo/chainConfig.d.ts +1282 -376
- package/_types/chains/celo/chainConfig.d.ts.map +1 -1
- package/_types/chains/celo/formatters.d.ts +1282 -376
- package/_types/chains/celo/formatters.d.ts.map +1 -1
- package/_types/chains/celo/serializers.d.ts +3 -4
- package/_types/chains/celo/serializers.d.ts.map +1 -1
- package/_types/chains/celo/types.d.ts +3 -8
- package/_types/chains/celo/types.d.ts.map +1 -1
- package/_types/chains/definitions/ancient8.d.ts +452 -188
- package/_types/chains/definitions/ancient8.d.ts.map +1 -1
- package/_types/chains/definitions/ancient8Sepolia.d.ts +452 -188
- package/_types/chains/definitions/ancient8Sepolia.d.ts.map +1 -1
- package/_types/chains/definitions/base.d.ts +452 -188
- package/_types/chains/definitions/base.d.ts.map +1 -1
- package/_types/chains/definitions/baseGoerli.d.ts +452 -188
- package/_types/chains/definitions/baseGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/baseSepolia.d.ts +452 -188
- package/_types/chains/definitions/baseSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/celo.d.ts +1282 -376
- package/_types/chains/definitions/celo.d.ts.map +1 -1
- package/_types/chains/definitions/celoAlfajores.d.ts +1282 -376
- package/_types/chains/definitions/celoAlfajores.d.ts.map +1 -1
- package/_types/chains/definitions/fraxtal.d.ts +452 -188
- package/_types/chains/definitions/fraxtal.d.ts.map +1 -1
- package/_types/chains/definitions/fraxtalTestnet.d.ts +452 -188
- package/_types/chains/definitions/fraxtalTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/liskSepolia.d.ts +452 -188
- package/_types/chains/definitions/liskSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/optimism.d.ts +452 -188
- package/_types/chains/definitions/optimism.d.ts.map +1 -1
- package/_types/chains/definitions/optimismGoerli.d.ts +452 -188
- package/_types/chains/definitions/optimismGoerli.d.ts.map +1 -1
- package/_types/chains/definitions/optimismSepolia.d.ts +452 -188
- package/_types/chains/definitions/optimismSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/pgn.d.ts +451 -187
- package/_types/chains/definitions/pgn.d.ts.map +1 -1
- package/_types/chains/definitions/pgnTestnet.d.ts +451 -187
- package/_types/chains/definitions/pgnTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/plumeTestnet.d.ts +37 -0
- package/_types/chains/definitions/plumeTestnet.d.ts.map +1 -0
- package/_types/chains/definitions/zkSync.d.ts +692 -32
- package/_types/chains/definitions/zkSync.d.ts.map +1 -1
- package/_types/chains/definitions/zkSyncSepoliaTestnet.d.ts +692 -32
- package/_types/chains/definitions/zkSyncSepoliaTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/zkSyncTestnet.d.ts +692 -32
- package/_types/chains/definitions/zkSyncTestnet.d.ts.map +1 -1
- package/_types/chains/definitions/zora.d.ts +452 -188
- package/_types/chains/definitions/zora.d.ts.map +1 -1
- package/_types/chains/definitions/zoraSepolia.d.ts +452 -188
- package/_types/chains/definitions/zoraSepolia.d.ts.map +1 -1
- package/_types/chains/definitions/zoraTestnet.d.ts +452 -188
- package/_types/chains/definitions/zoraTestnet.d.ts.map +1 -1
- package/_types/chains/index.d.ts +2 -1
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/chains/opStack/actions/estimateL1Fee.d.ts.map +1 -1
- package/_types/chains/opStack/actions/estimateL1Gas.d.ts.map +1 -1
- package/_types/chains/opStack/actions/finalizeWithdrawal.d.ts.map +1 -1
- package/_types/chains/opStack/actions/proveWithdrawal.d.ts.map +1 -1
- package/_types/chains/opStack/chainConfig.d.ts +452 -188
- package/_types/chains/opStack/chainConfig.d.ts.map +1 -1
- package/_types/chains/opStack/formatters.d.ts +451 -187
- package/_types/chains/opStack/formatters.d.ts.map +1 -1
- package/_types/chains/opStack/serializers.d.ts +4 -3
- package/_types/chains/opStack/serializers.d.ts.map +1 -1
- package/_types/chains/opStack/types/transaction.d.ts +4 -8
- package/_types/chains/opStack/types/transaction.d.ts.map +1 -1
- package/_types/chains/zksync/actions/sendTransaction.d.ts.map +1 -1
- package/_types/chains/zksync/chainConfig.d.ts +692 -32
- package/_types/chains/zksync/chainConfig.d.ts.map +1 -1
- package/_types/chains/zksync/formatters.d.ts +692 -32
- package/_types/chains/zksync/formatters.d.ts.map +1 -1
- package/_types/chains/zksync/serializers.d.ts +3 -3
- package/_types/chains/zksync/serializers.d.ts.map +1 -1
- package/_types/chains/zksync/types/chain.d.ts +2 -2
- package/_types/chains/zksync/types/chain.d.ts.map +1 -1
- package/_types/chains/zksync/types/eip712.d.ts +2 -2
- package/_types/chains/zksync/types/eip712.d.ts.map +1 -1
- package/_types/clients/decorators/public.d.ts +2 -2
- package/_types/clients/decorators/public.d.ts.map +1 -1
- package/_types/clients/decorators/wallet.d.ts +4 -4
- package/_types/clients/decorators/wallet.d.ts.map +1 -1
- package/_types/constants/blob.d.ts +11 -0
- package/_types/constants/blob.d.ts.map +1 -0
- package/_types/constants/kzg.d.ts +6 -0
- package/_types/constants/kzg.d.ts.map +1 -0
- package/_types/errors/blob.d.ts +40 -0
- package/_types/errors/blob.d.ts.map +1 -0
- package/_types/errors/transaction.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/errors/version.d.ts.map +1 -1
- package/_types/index.d.ts +11 -0
- package/_types/index.d.ts.map +1 -1
- package/_types/node/index.d.ts +1 -0
- package/_types/node/index.d.ts.map +1 -1
- package/_types/node/trustedSetups.d.ts +3 -0
- package/_types/node/trustedSetups.d.ts.map +1 -0
- package/_types/types/account.d.ts +3 -3
- package/_types/types/account.d.ts.map +1 -1
- package/_types/types/chain.d.ts +2 -2
- package/_types/types/chain.d.ts.map +1 -1
- package/_types/types/eip1193.d.ts +3 -3
- package/_types/types/eip1193.d.ts.map +1 -1
- package/_types/types/eip4844.d.ts +11 -0
- package/_types/types/eip4844.d.ts.map +1 -0
- package/_types/types/fee.d.ts +2 -2
- package/_types/types/fee.d.ts.map +1 -1
- package/_types/types/kzg.d.ts +24 -0
- package/_types/types/kzg.d.ts.map +1 -0
- package/_types/types/misc.d.ts +15 -1
- package/_types/types/misc.d.ts.map +1 -1
- package/_types/types/rpc.d.ts +4 -4
- package/_types/types/rpc.d.ts.map +1 -1
- package/_types/types/transaction.d.ts +44 -9
- package/_types/types/transaction.d.ts.map +1 -1
- package/_types/types/utils.d.ts +38 -2
- package/_types/types/utils.d.ts.map +1 -1
- package/_types/utils/blob/blobsToCommitments.d.ts +31 -0
- package/_types/utils/blob/blobsToCommitments.d.ts.map +1 -0
- package/_types/utils/blob/blobsToProofs.d.ts +37 -0
- package/_types/utils/blob/blobsToProofs.d.ts.map +1 -0
- package/_types/utils/blob/commitmentToVersionedHash.d.ts +35 -0
- package/_types/utils/blob/commitmentToVersionedHash.d.ts.map +1 -0
- package/_types/utils/blob/commitmentsToVersionedHashes.d.ts +34 -0
- package/_types/utils/blob/commitmentsToVersionedHashes.d.ts.map +1 -0
- package/_types/utils/blob/fromBlobs.d.ts +16 -0
- package/_types/utils/blob/fromBlobs.d.ts.map +1 -0
- package/_types/utils/blob/sidecarsToVersionedHashes.d.ts +29 -0
- package/_types/utils/blob/sidecarsToVersionedHashes.d.ts.map +1 -0
- package/_types/utils/blob/toBlobSidecars.d.ts +57 -0
- package/_types/utils/blob/toBlobSidecars.d.ts.map +1 -0
- package/_types/utils/blob/toBlobs.d.ts +28 -0
- package/_types/utils/blob/toBlobs.d.ts.map +1 -0
- package/_types/utils/encoding/toRlp.d.ts +1 -1
- package/_types/utils/encoding/toRlp.d.ts.map +1 -1
- package/_types/utils/formatters/transaction.d.ts +25 -25
- package/_types/utils/formatters/transaction.d.ts.map +1 -1
- package/_types/utils/formatters/transactionRequest.d.ts +227 -3
- package/_types/utils/formatters/transactionRequest.d.ts.map +1 -1
- package/_types/utils/kzg/defineKzg.d.ts +21 -0
- package/_types/utils/kzg/defineKzg.d.ts.map +1 -0
- package/_types/utils/kzg/setupKzg.d.ts +21 -0
- package/_types/utils/kzg/setupKzg.d.ts.map +1 -0
- package/_types/utils/signature/hexToSignature.d.ts.map +1 -1
- package/_types/utils/signature/signatureToCompactSignature.d.ts +1 -1
- package/_types/utils/signature/signatureToHex.d.ts +2 -2
- package/_types/utils/signature/signatureToHex.d.ts.map +1 -1
- package/_types/utils/transaction/assertTransaction.d.ts +4 -1
- package/_types/utils/transaction/assertTransaction.d.ts.map +1 -1
- package/_types/utils/transaction/getSerializedTransactionType.d.ts +5 -3
- package/_types/utils/transaction/getSerializedTransactionType.d.ts.map +1 -1
- package/_types/utils/transaction/getTransactionType.d.ts +34 -3
- package/_types/utils/transaction/getTransactionType.d.ts.map +1 -1
- package/_types/utils/transaction/parseTransaction.d.ts +7 -5
- package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
- package/_types/utils/transaction/serializeTransaction.d.ts +13 -6
- package/_types/utils/transaction/serializeTransaction.d.ts.map +1 -1
- package/accounts/types.ts +9 -5
- package/accounts/utils/sign.ts +1 -0
- package/accounts/utils/signTransaction.ts +37 -22
- package/actions/index.ts +5 -0
- package/actions/public/call.ts +4 -0
- package/actions/public/estimateGas.ts +4 -0
- package/actions/public/getBlobBaseFee.ts +42 -0
- package/actions/wallet/prepareTransactionRequest.ts +134 -61
- package/actions/wallet/sendRawTransaction.ts +3 -5
- package/actions/wallet/sendTransaction.ts +32 -21
- package/actions/wallet/signTransaction.ts +34 -18
- package/chains/celo/serializers.ts +12 -25
- package/chains/celo/types.ts +5 -10
- package/chains/definitions/plumeTestnet.ts +28 -0
- package/chains/index.ts +1 -1
- package/chains/opStack/actions/estimateL1Fee.ts +12 -16
- package/chains/opStack/actions/estimateL1Gas.ts +12 -16
- package/chains/opStack/actions/finalizeWithdrawal.ts +3 -2
- package/chains/opStack/actions/proveWithdrawal.ts +3 -2
- package/chains/opStack/serializers.ts +5 -5
- package/chains/opStack/types/transaction.ts +9 -11
- package/chains/zksync/actions/sendTransaction.ts +2 -1
- package/chains/zksync/actions/signEip712Transaction.ts +2 -2
- package/chains/zksync/serializers.ts +14 -10
- package/chains/zksync/types/chain.ts +4 -7
- package/chains/zksync/types/eip712.ts +2 -2
- package/clients/decorators/public.ts +8 -4
- package/clients/decorators/wallet.ts +14 -6
- package/constants/blob.ts +21 -0
- package/constants/kzg.ts +9 -0
- package/errors/blob.ts +67 -0
- package/errors/transaction.ts +1 -0
- package/errors/version.ts +1 -1
- package/index.ts +64 -0
- package/node/index.ts +2 -0
- package/node/trustedSetups.ts +11 -0
- package/package.json +1 -1
- package/trusted-setups/mainnet.json +8265 -0
- package/trusted-setups/minimal.json +8265 -0
- package/types/account.ts +3 -3
- package/types/chain.ts +3 -1
- package/types/eip1193.ts +3 -3
- package/types/eip4844.ts +12 -0
- package/types/fee.ts +3 -2
- package/types/kzg.ts +32 -0
- package/types/misc.ts +20 -1
- package/types/rpc.ts +11 -6
- package/types/transaction.ts +75 -17
- package/types/utils.ts +49 -1
- package/utils/blob/blobsToCommitments.ts +69 -0
- package/utils/blob/blobsToProofs.ts +93 -0
- package/utils/blob/commitmentToVersionedHash.ts +62 -0
- package/utils/blob/commitmentsToVersionedHashes.ts +71 -0
- package/utils/blob/fromBlobs.ts +73 -0
- package/utils/blob/sidecarsToVersionedHashes.ts +66 -0
- package/utils/blob/toBlobSidecars.ts +109 -0
- package/utils/blob/toBlobs.ts +113 -0
- package/utils/encoding/toRlp.ts +2 -2
- package/utils/formatters/transaction.ts +3 -2
- package/utils/formatters/transactionRequest.ts +28 -35
- package/utils/kzg/defineKzg.ts +30 -0
- package/utils/kzg/setupKzg.ts +38 -0
- package/utils/signature/compactSignatureToSignature.ts +3 -3
- package/utils/signature/hexToSignature.ts +6 -1
- package/utils/signature/signatureToCompactSignature.ts +4 -4
- package/utils/signature/signatureToHex.ts +9 -4
- package/utils/transaction/assertTransaction.ts +41 -0
- package/utils/transaction/getSerializedTransactionType.ts +34 -11
- package/utils/transaction/getTransactionType.ts +109 -26
- package/utils/transaction/parseTransaction.ts +128 -8
- package/utils/transaction/serializeAccessList.ts +1 -1
- package/utils/transaction/serializeTransaction.ts +172 -39
@@ -0,0 +1,71 @@
|
|
1
|
+
import type { ErrorType } from '../../errors/utils.js'
|
2
|
+
import type { ByteArray, Hex } from '../../types/misc.js'
|
3
|
+
import {
|
4
|
+
type CommitmentToVersionedHashErrorType,
|
5
|
+
commitmentToVersionedHash,
|
6
|
+
} from './commitmentToVersionedHash.js'
|
7
|
+
|
8
|
+
type To = 'hex' | 'bytes'
|
9
|
+
|
10
|
+
export type CommitmentsToVersionedHashesParameters<
|
11
|
+
commitments extends Uint8Array[] | Hex[] = Uint8Array[] | Hex[],
|
12
|
+
to extends To | undefined = undefined,
|
13
|
+
> = {
|
14
|
+
/** Commitments from blobs. */
|
15
|
+
commitments: commitments | Uint8Array[] | Hex[]
|
16
|
+
/** Return type. */
|
17
|
+
to?: to | To | undefined
|
18
|
+
/** Version to tag onto the hashes. */
|
19
|
+
version?: number
|
20
|
+
}
|
21
|
+
|
22
|
+
export type CommitmentsToVersionedHashesReturnType<to extends To> =
|
23
|
+
| (to extends 'bytes' ? ByteArray[] : never)
|
24
|
+
| (to extends 'hex' ? Hex[] : never)
|
25
|
+
|
26
|
+
export type CommitmentsToVersionedHashesErrorType =
|
27
|
+
| CommitmentToVersionedHashErrorType
|
28
|
+
| ErrorType
|
29
|
+
|
30
|
+
/**
|
31
|
+
* Transform a list of commitments to their versioned hashes.
|
32
|
+
*
|
33
|
+
* @example
|
34
|
+
* ```ts
|
35
|
+
* import {
|
36
|
+
* blobsToCommitments,
|
37
|
+
* commitmentsToVersionedHashes,
|
38
|
+
* toBlobs
|
39
|
+
* } from 'viem'
|
40
|
+
* import { kzg } from './kzg'
|
41
|
+
*
|
42
|
+
* const blobs = toBlobs({ data: '0x1234' })
|
43
|
+
* const commitments = blobsToCommitments({ blobs, kzg })
|
44
|
+
* const versionedHashes = commitmentsToVersionedHashes({ commitments })
|
45
|
+
* ```
|
46
|
+
*/
|
47
|
+
export function commitmentsToVersionedHashes<
|
48
|
+
const commitments extends Uint8Array[] | Hex[],
|
49
|
+
to extends To =
|
50
|
+
| (commitments extends Hex[] ? 'hex' : never)
|
51
|
+
| (commitments extends ByteArray[] ? 'bytes' : never),
|
52
|
+
>(
|
53
|
+
parameters: CommitmentsToVersionedHashesParameters<commitments, to>,
|
54
|
+
): CommitmentsToVersionedHashesReturnType<to> {
|
55
|
+
const { commitments, version } = parameters
|
56
|
+
|
57
|
+
const to =
|
58
|
+
parameters.to ?? (typeof commitments[0] === 'string' ? 'hex' : 'bytes')
|
59
|
+
|
60
|
+
const hashes: Uint8Array[] | Hex[] = []
|
61
|
+
for (const commitment of commitments) {
|
62
|
+
hashes.push(
|
63
|
+
commitmentToVersionedHash({
|
64
|
+
commitment,
|
65
|
+
to,
|
66
|
+
version,
|
67
|
+
}) as any,
|
68
|
+
)
|
69
|
+
}
|
70
|
+
return hashes as CommitmentsToVersionedHashesReturnType<to>
|
71
|
+
}
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import type { ErrorType } from '../../errors/utils.js'
|
2
|
+
import type { ByteArray, Hex } from '../../types/misc.js'
|
3
|
+
import { type CreateCursorErrorType, createCursor } from '../cursor.js'
|
4
|
+
import { type HexToBytesErrorType, hexToBytes } from '../encoding/toBytes.js'
|
5
|
+
import { type BytesToHexErrorType, bytesToHex } from '../encoding/toHex.js'
|
6
|
+
|
7
|
+
type To = 'hex' | 'bytes'
|
8
|
+
|
9
|
+
export type FromBlobsParameters<
|
10
|
+
blobs extends readonly Hex[] | readonly ByteArray[] =
|
11
|
+
| readonly Hex[]
|
12
|
+
| readonly ByteArray[],
|
13
|
+
to extends To | undefined = undefined,
|
14
|
+
> = {
|
15
|
+
/** Blobs to transform to data. */
|
16
|
+
blobs: blobs | readonly Hex[] | readonly ByteArray[]
|
17
|
+
to?: to | To | undefined
|
18
|
+
}
|
19
|
+
|
20
|
+
export type FromBlobsReturnType<to extends To> =
|
21
|
+
| (to extends 'bytes' ? ByteArray : never)
|
22
|
+
| (to extends 'hex' ? Hex : never)
|
23
|
+
|
24
|
+
export type FromBlobsErrorType =
|
25
|
+
| BytesToHexErrorType
|
26
|
+
| CreateCursorErrorType
|
27
|
+
| HexToBytesErrorType
|
28
|
+
| ErrorType
|
29
|
+
|
30
|
+
export function fromBlobs<
|
31
|
+
const blobs extends readonly Hex[] | readonly ByteArray[],
|
32
|
+
to extends To =
|
33
|
+
| (blobs extends readonly Hex[] ? 'hex' : never)
|
34
|
+
| (blobs extends readonly ByteArray[] ? 'bytes' : never),
|
35
|
+
>(parameters: FromBlobsParameters<blobs, to>): FromBlobsReturnType<to> {
|
36
|
+
const to =
|
37
|
+
parameters.to ?? (typeof parameters.blobs[0] === 'string' ? 'hex' : 'bytes')
|
38
|
+
const blobs = (
|
39
|
+
typeof parameters.blobs[0] === 'string'
|
40
|
+
? parameters.blobs.map((x) => hexToBytes(x as Hex))
|
41
|
+
: parameters.blobs
|
42
|
+
) as ByteArray[]
|
43
|
+
|
44
|
+
const length = blobs.reduce((length, blob) => length + blob.length, 0)
|
45
|
+
const data = createCursor(new Uint8Array(length))
|
46
|
+
let active = true
|
47
|
+
|
48
|
+
for (const blob of blobs) {
|
49
|
+
const cursor = createCursor(blob)
|
50
|
+
while (active && cursor.position < blob.length) {
|
51
|
+
// First byte will be a zero 0x00 byte – we can skip.
|
52
|
+
cursor.incrementPosition(1)
|
53
|
+
|
54
|
+
let consume = 31
|
55
|
+
if (blob.length - cursor.position < 31)
|
56
|
+
consume = blob.length - cursor.position
|
57
|
+
const bytes = cursor.readBytes(consume)
|
58
|
+
|
59
|
+
for (const byte of bytes) {
|
60
|
+
if (byte === 0x80) {
|
61
|
+
active = false
|
62
|
+
break
|
63
|
+
}
|
64
|
+
data.pushByte(byte)
|
65
|
+
}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
const trimmedData = data.bytes.slice(0, data.position)
|
70
|
+
return (
|
71
|
+
to === 'hex' ? bytesToHex(trimmedData) : trimmedData
|
72
|
+
) as FromBlobsReturnType<to>
|
73
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import type { ErrorType } from '../../errors/utils.js'
|
2
|
+
import type { BlobSidecars } from '../../types/eip4844.js'
|
3
|
+
import type { ByteArray, Hex } from '../../types/misc.js'
|
4
|
+
import {
|
5
|
+
type CommitmentToVersionedHashErrorType,
|
6
|
+
commitmentToVersionedHash,
|
7
|
+
} from './commitmentToVersionedHash.js'
|
8
|
+
|
9
|
+
type To = 'hex' | 'bytes'
|
10
|
+
|
11
|
+
export type SidecarsToVersionedHashesParameters<
|
12
|
+
sidecars extends BlobSidecars = BlobSidecars,
|
13
|
+
to extends To | undefined = undefined,
|
14
|
+
> = {
|
15
|
+
/** Sidecars from blobs. */
|
16
|
+
sidecars: sidecars | BlobSidecars
|
17
|
+
/** Return type. */
|
18
|
+
to?: to | To | undefined
|
19
|
+
/** Version to tag onto the hashes. */
|
20
|
+
version?: number
|
21
|
+
}
|
22
|
+
|
23
|
+
export type SidecarsToVersionedHashesReturnType<to extends To> =
|
24
|
+
| (to extends 'bytes' ? ByteArray[] : never)
|
25
|
+
| (to extends 'hex' ? Hex[] : never)
|
26
|
+
|
27
|
+
export type SidecarsToVersionedHashesErrorType =
|
28
|
+
| CommitmentToVersionedHashErrorType
|
29
|
+
| ErrorType
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Transforms a list of sidecars to their versioned hashes.
|
33
|
+
*
|
34
|
+
* @example
|
35
|
+
* ```ts
|
36
|
+
* import { toBlobSidecars, sidecarsToVersionedHashes, stringToHex } from 'viem'
|
37
|
+
*
|
38
|
+
* const sidecars = toBlobSidecars({ data: stringToHex('hello world') })
|
39
|
+
* const versionedHashes = sidecarsToVersionedHashes({ sidecars })
|
40
|
+
* ```
|
41
|
+
*/
|
42
|
+
export function sidecarsToVersionedHashes<
|
43
|
+
const sidecars extends BlobSidecars,
|
44
|
+
to extends To =
|
45
|
+
| (sidecars extends BlobSidecars<Hex> ? 'hex' : never)
|
46
|
+
| (sidecars extends BlobSidecars<ByteArray> ? 'bytes' : never),
|
47
|
+
>(
|
48
|
+
parameters: SidecarsToVersionedHashesParameters<sidecars, to>,
|
49
|
+
): SidecarsToVersionedHashesReturnType<to> {
|
50
|
+
const { sidecars, version } = parameters
|
51
|
+
|
52
|
+
const to =
|
53
|
+
parameters.to ?? (typeof sidecars[0].blob === 'string' ? 'hex' : 'bytes')
|
54
|
+
|
55
|
+
const hashes: Uint8Array[] | Hex[] = []
|
56
|
+
for (const { commitment } of sidecars) {
|
57
|
+
hashes.push(
|
58
|
+
commitmentToVersionedHash({
|
59
|
+
commitment,
|
60
|
+
to,
|
61
|
+
version,
|
62
|
+
}) as any,
|
63
|
+
)
|
64
|
+
}
|
65
|
+
return hashes as SidecarsToVersionedHashesReturnType<to>
|
66
|
+
}
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import type { ErrorType } from '../../errors/utils.js'
|
2
|
+
import type { BlobSidecars } from '../../types/eip4844.js'
|
3
|
+
import type { Kzg } from '../../types/kzg.js'
|
4
|
+
import type { ByteArray, Hex } from '../../types/misc.js'
|
5
|
+
import type { OneOf } from '../../types/utils.js'
|
6
|
+
import {
|
7
|
+
type BlobsToCommitmentsErrorType,
|
8
|
+
blobsToCommitments,
|
9
|
+
} from './blobsToCommitments.js'
|
10
|
+
import { blobsToProofs, type blobsToProofsErrorType } from './blobsToProofs.js'
|
11
|
+
import { type ToBlobsErrorType, toBlobs } from './toBlobs.js'
|
12
|
+
|
13
|
+
type To = 'hex' | 'bytes'
|
14
|
+
|
15
|
+
export type ToBlobSidecarsParameters<
|
16
|
+
data extends Hex | ByteArray | undefined = undefined,
|
17
|
+
blobs extends Hex[] | ByteArray[] | undefined = undefined,
|
18
|
+
to extends To =
|
19
|
+
| (blobs extends Hex[] ? 'hex' : never)
|
20
|
+
| (blobs extends ByteArray[] ? 'bytes' : never),
|
21
|
+
///
|
22
|
+
_blobsType =
|
23
|
+
| (blobs extends Hex[] ? Hex[] : never)
|
24
|
+
| (blobs extends ByteArray[] ? ByteArray[] : never),
|
25
|
+
> = {
|
26
|
+
/** Return type. */
|
27
|
+
to?: to | To | undefined
|
28
|
+
} & OneOf<
|
29
|
+
| {
|
30
|
+
/** Data to transform into blobs. */
|
31
|
+
data: data | Hex | ByteArray
|
32
|
+
/** KZG implementation. */
|
33
|
+
kzg: Kzg
|
34
|
+
}
|
35
|
+
| {
|
36
|
+
/** Blobs. */
|
37
|
+
blobs: blobs | Hex[] | ByteArray[]
|
38
|
+
/** Commitment for each blob. */
|
39
|
+
commitments: _blobsType | Hex[] | ByteArray[]
|
40
|
+
/** Proof for each blob. */
|
41
|
+
proofs: _blobsType | Hex[] | ByteArray[]
|
42
|
+
}
|
43
|
+
>
|
44
|
+
|
45
|
+
export type ToBlobSidecarsReturnType<to extends To> =
|
46
|
+
| (to extends 'bytes' ? BlobSidecars<ByteArray> : never)
|
47
|
+
| (to extends 'hex' ? BlobSidecars<Hex> : never)
|
48
|
+
|
49
|
+
export type ToBlobSidecarsErrorType =
|
50
|
+
| BlobsToCommitmentsErrorType
|
51
|
+
| ToBlobsErrorType
|
52
|
+
| blobsToProofsErrorType
|
53
|
+
| ErrorType
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Transforms arbitrary data (or blobs, commitments, & proofs) into a sidecar array.
|
57
|
+
*
|
58
|
+
* @example
|
59
|
+
* ```ts
|
60
|
+
* import { toBlobSidecars, stringToHex } from 'viem'
|
61
|
+
*
|
62
|
+
* const sidecars = toBlobSidecars({ data: stringToHex('hello world') })
|
63
|
+
* ```
|
64
|
+
*
|
65
|
+
* @example
|
66
|
+
* ```ts
|
67
|
+
* import {
|
68
|
+
* blobsToCommitments,
|
69
|
+
* toBlobs,
|
70
|
+
* blobsToProofs,
|
71
|
+
* toBlobSidecars,
|
72
|
+
* stringToHex
|
73
|
+
* } from 'viem'
|
74
|
+
*
|
75
|
+
* const blobs = toBlobs({ data: stringToHex('hello world') })
|
76
|
+
* const commitments = blobsToCommitments({ blobs, kzg })
|
77
|
+
* const proofs = blobsToProofs({ blobs, commitments, kzg })
|
78
|
+
*
|
79
|
+
* const sidecars = toBlobSidecars({ blobs, commitments, proofs })
|
80
|
+
* ```
|
81
|
+
*/
|
82
|
+
export function toBlobSidecars<
|
83
|
+
const data extends Hex | ByteArray | undefined = undefined,
|
84
|
+
const blobs extends Hex[] | ByteArray[] | undefined = undefined,
|
85
|
+
to extends To =
|
86
|
+
| (data extends Hex ? 'hex' : never)
|
87
|
+
| (data extends ByteArray ? 'bytes' : never)
|
88
|
+
| (blobs extends Hex[] ? 'hex' : never)
|
89
|
+
| (blobs extends ByteArray[] ? 'bytes' : never),
|
90
|
+
>(
|
91
|
+
parameters: ToBlobSidecarsParameters<data, blobs, to>,
|
92
|
+
): ToBlobSidecarsReturnType<to> {
|
93
|
+
const { data, kzg, to } = parameters
|
94
|
+
const blobs = parameters.blobs ?? toBlobs({ data: data!, to })
|
95
|
+
const commitments =
|
96
|
+
parameters.commitments ?? blobsToCommitments({ blobs, kzg: kzg!, to })
|
97
|
+
const proofs =
|
98
|
+
parameters.proofs ?? blobsToProofs({ blobs, commitments, kzg: kzg!, to })
|
99
|
+
|
100
|
+
const sidecars: BlobSidecars = []
|
101
|
+
for (let i = 0; i < blobs.length; i++)
|
102
|
+
sidecars.push({
|
103
|
+
blob: blobs[i],
|
104
|
+
commitment: commitments[i],
|
105
|
+
proof: proofs[i],
|
106
|
+
})
|
107
|
+
|
108
|
+
return sidecars as ToBlobSidecarsReturnType<to>
|
109
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import {
|
2
|
+
bytesPerBlob,
|
3
|
+
bytesPerFieldElement,
|
4
|
+
fieldElementsPerBlob,
|
5
|
+
maxBytesPerTransaction,
|
6
|
+
} from '../../constants/blob.js'
|
7
|
+
import {
|
8
|
+
BlobSizeTooLargeError,
|
9
|
+
type BlobSizeTooLargeErrorType,
|
10
|
+
EmptyBlobError,
|
11
|
+
type EmptyBlobErrorType,
|
12
|
+
} from '../../errors/blob.js'
|
13
|
+
import type { ErrorType } from '../../errors/utils.js'
|
14
|
+
import type { ByteArray, Hex } from '../../types/misc.js'
|
15
|
+
import { createCursor } from '../cursor.js'
|
16
|
+
import { type SizeErrorType, size } from '../data/size.js'
|
17
|
+
import { type HexToBytesErrorType, hexToBytes } from '../encoding/toBytes.js'
|
18
|
+
import { type BytesToHexErrorType, bytesToHex } from '../encoding/toHex.js'
|
19
|
+
|
20
|
+
type To = 'hex' | 'bytes'
|
21
|
+
|
22
|
+
export type ToBlobsParameters<
|
23
|
+
data extends Hex | ByteArray = Hex | ByteArray,
|
24
|
+
to extends To | undefined = undefined,
|
25
|
+
> = {
|
26
|
+
/** Data to transform to a blob. */
|
27
|
+
data: data | Hex | ByteArray
|
28
|
+
/** Return type. */
|
29
|
+
to?: to | To | undefined
|
30
|
+
}
|
31
|
+
|
32
|
+
export type ToBlobsReturnType<to extends To> =
|
33
|
+
| (to extends 'bytes' ? ByteArray[] : never)
|
34
|
+
| (to extends 'hex' ? Hex[] : never)
|
35
|
+
|
36
|
+
export type ToBlobsErrorType =
|
37
|
+
| BlobSizeTooLargeErrorType
|
38
|
+
| BytesToHexErrorType
|
39
|
+
| EmptyBlobErrorType
|
40
|
+
| HexToBytesErrorType
|
41
|
+
| SizeErrorType
|
42
|
+
| ErrorType
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Transforms arbitrary data to blobs.
|
46
|
+
*
|
47
|
+
* @example
|
48
|
+
* ```ts
|
49
|
+
* import { toBlobs, stringToHex } from 'viem'
|
50
|
+
*
|
51
|
+
* const blobs = toBlobs({ data: stringToHex('hello world') })
|
52
|
+
* ```
|
53
|
+
*/
|
54
|
+
export function toBlobs<
|
55
|
+
const data extends Hex | ByteArray,
|
56
|
+
to extends To =
|
57
|
+
| (data extends Hex ? 'hex' : never)
|
58
|
+
| (data extends ByteArray ? 'bytes' : never),
|
59
|
+
>(parameters: ToBlobsParameters<data, to>): ToBlobsReturnType<to> {
|
60
|
+
const to =
|
61
|
+
parameters.to ?? (typeof parameters.data === 'string' ? 'hex' : 'bytes')
|
62
|
+
const data = (
|
63
|
+
typeof parameters.data === 'string'
|
64
|
+
? hexToBytes(parameters.data)
|
65
|
+
: parameters.data
|
66
|
+
) as ByteArray
|
67
|
+
|
68
|
+
const size_ = size(data)
|
69
|
+
if (!size_) throw new EmptyBlobError()
|
70
|
+
if (size_ > maxBytesPerTransaction)
|
71
|
+
throw new BlobSizeTooLargeError({
|
72
|
+
maxSize: maxBytesPerTransaction,
|
73
|
+
size: size_,
|
74
|
+
})
|
75
|
+
|
76
|
+
const blobs = []
|
77
|
+
|
78
|
+
let active = true
|
79
|
+
let position = 0
|
80
|
+
while (active) {
|
81
|
+
const blob = createCursor(new Uint8Array(bytesPerBlob))
|
82
|
+
|
83
|
+
let size = 0
|
84
|
+
while (size < fieldElementsPerBlob) {
|
85
|
+
const bytes = data.slice(position, position + (bytesPerFieldElement - 1))
|
86
|
+
|
87
|
+
// Push a zero byte so the field element doesn't overflow the BLS modulus.
|
88
|
+
blob.pushByte(0x00)
|
89
|
+
|
90
|
+
// Push the current segment of data bytes.
|
91
|
+
blob.pushBytes(bytes)
|
92
|
+
|
93
|
+
// If we detect that the current segment of data bytes is less than 31 bytes,
|
94
|
+
// we can stop processing and push a terminator byte to indicate the end of the blob.
|
95
|
+
if (bytes.length < 31) {
|
96
|
+
blob.pushByte(0x80)
|
97
|
+
active = false
|
98
|
+
break
|
99
|
+
}
|
100
|
+
|
101
|
+
size++
|
102
|
+
position += 31
|
103
|
+
}
|
104
|
+
|
105
|
+
blobs.push(blob)
|
106
|
+
}
|
107
|
+
|
108
|
+
return (
|
109
|
+
to === 'bytes'
|
110
|
+
? blobs.map((x) => x.bytes)
|
111
|
+
: blobs.map((x) => bytesToHex(x.bytes))
|
112
|
+
) as ToBlobsReturnType<to>
|
113
|
+
}
|
package/utils/encoding/toRlp.ts
CHANGED
@@ -10,7 +10,7 @@ import {
|
|
10
10
|
import { type HexToBytesErrorType, hexToBytes } from './toBytes.js'
|
11
11
|
import { type BytesToHexErrorType, bytesToHex } from './toHex.js'
|
12
12
|
|
13
|
-
export type RecursiveArray<T> = T | RecursiveArray<T>[]
|
13
|
+
export type RecursiveArray<T> = T | readonly RecursiveArray<T>[]
|
14
14
|
|
15
15
|
type To = 'hex' | 'bytes'
|
16
16
|
|
@@ -64,7 +64,7 @@ function getEncodable(
|
|
64
64
|
): Encodable {
|
65
65
|
if (Array.isArray(bytes))
|
66
66
|
return getEncodableList(bytes.map((x) => getEncodable(x)))
|
67
|
-
return getEncodableBytes(bytes)
|
67
|
+
return getEncodableBytes(bytes as any)
|
68
68
|
}
|
69
69
|
|
70
70
|
function getEncodableList(list: Encodable[]): Encodable {
|
@@ -5,8 +5,9 @@ import type {
|
|
5
5
|
ExtractChainFormatterExclude,
|
6
6
|
ExtractChainFormatterReturnType,
|
7
7
|
} from '../../types/chain.js'
|
8
|
+
import type { Hex } from '../../types/misc.js'
|
8
9
|
import type { RpcTransaction } from '../../types/rpc.js'
|
9
|
-
import type { Transaction } from '../../types/transaction.js'
|
10
|
+
import type { Transaction, TransactionType } from '../../types/transaction.js'
|
10
11
|
import type { UnionLooseOmit } from '../../types/utils.js'
|
11
12
|
import { hexToNumber } from '../encoding/fromHex.js'
|
12
13
|
import { type DefineFormatterErrorType, defineFormatter } from './formatter.js'
|
@@ -38,7 +39,7 @@ export const transactionType = {
|
|
38
39
|
'0x1': 'eip2930',
|
39
40
|
'0x2': 'eip1559',
|
40
41
|
'0x3': 'eip4844',
|
41
|
-
} as const
|
42
|
+
} as const satisfies Record<Hex, TransactionType>
|
42
43
|
|
43
44
|
export type FormatTransactionErrorType = ErrorType
|
44
45
|
|
@@ -3,9 +3,10 @@ import type {
|
|
3
3
|
Chain,
|
4
4
|
ExtractChainFormatterParameters,
|
5
5
|
} from '../../types/chain.js'
|
6
|
+
import type { ByteArray } from '../../types/misc.js'
|
6
7
|
import type { RpcTransactionRequest } from '../../types/rpc.js'
|
7
8
|
import type { TransactionRequest } from '../../types/transaction.js'
|
8
|
-
import { numberToHex } from '../encoding/toHex.js'
|
9
|
+
import { bytesToHex, numberToHex } from '../encoding/toHex.js'
|
9
10
|
import { type DefineFormatterErrorType, defineFormatter } from './formatter.js'
|
10
11
|
|
11
12
|
export type FormattedTransactionRequest<
|
@@ -25,40 +26,32 @@ export const rpcTransactionType = {
|
|
25
26
|
|
26
27
|
export type FormatTransactionRequestErrorType = ErrorType
|
27
28
|
|
28
|
-
export function formatTransactionRequest(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
maxPriorityFeePerGas
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
typeof transactionRequest.type !== 'undefined'
|
55
|
-
? rpcTransactionType[transactionRequest.type]
|
56
|
-
: undefined,
|
57
|
-
value:
|
58
|
-
typeof transactionRequest.value !== 'undefined'
|
59
|
-
? numberToHex(transactionRequest.value)
|
60
|
-
: undefined,
|
61
|
-
} as RpcTransactionRequest
|
29
|
+
export function formatTransactionRequest(request: Partial<TransactionRequest>) {
|
30
|
+
const rpcRequest = { ...request } as RpcTransactionRequest
|
31
|
+
|
32
|
+
if (
|
33
|
+
typeof request.blobs !== 'undefined' &&
|
34
|
+
typeof request.blobs[0] !== 'string'
|
35
|
+
)
|
36
|
+
rpcRequest.blobs = (request.blobs as ByteArray[]).map((x) => bytesToHex(x))
|
37
|
+
if (typeof request.gas !== 'undefined')
|
38
|
+
rpcRequest.gas = numberToHex(request.gas)
|
39
|
+
if (typeof request.gasPrice !== 'undefined')
|
40
|
+
rpcRequest.gasPrice = numberToHex(request.gasPrice)
|
41
|
+
if (typeof request.maxFeePerBlobGas !== 'undefined')
|
42
|
+
rpcRequest.maxFeePerBlobGas = numberToHex(request.maxFeePerBlobGas)
|
43
|
+
if (typeof request.maxFeePerGas !== 'undefined')
|
44
|
+
rpcRequest.maxFeePerGas = numberToHex(request.maxFeePerGas)
|
45
|
+
if (typeof request.maxPriorityFeePerGas !== 'undefined')
|
46
|
+
rpcRequest.maxPriorityFeePerGas = numberToHex(request.maxPriorityFeePerGas)
|
47
|
+
if (typeof request.nonce !== 'undefined')
|
48
|
+
rpcRequest.nonce = numberToHex(request.nonce)
|
49
|
+
if (typeof request.type !== 'undefined')
|
50
|
+
rpcRequest.type = rpcTransactionType[request.type]
|
51
|
+
if (typeof request.value !== 'undefined')
|
52
|
+
rpcRequest.value = numberToHex(request.value)
|
53
|
+
|
54
|
+
return rpcRequest
|
62
55
|
}
|
63
56
|
|
64
57
|
export type DefineTransactionRequestErrorType =
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import type { ErrorType } from '../../errors/utils.js'
|
2
|
+
import type { Kzg } from '../../types/kzg.js'
|
3
|
+
|
4
|
+
export type DefineKzgParameters = Kzg
|
5
|
+
export type DefineKzgReturnType = Kzg
|
6
|
+
export type DefineKzgErrorType = ErrorType
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Defines a KZG interface.
|
10
|
+
*
|
11
|
+
* @example
|
12
|
+
* ```ts
|
13
|
+
* import * as cKzg from 'c-kzg'
|
14
|
+
* import { defineKzg } from 'viem'
|
15
|
+
* import { mainnetTrustedSetupPath } from 'viem/node'
|
16
|
+
*
|
17
|
+
* cKzg.loadTrustedSetup(mainnetTrustedSetupPath)
|
18
|
+
*
|
19
|
+
* const kzg = defineKzg(cKzg)
|
20
|
+
* ```
|
21
|
+
*/
|
22
|
+
export function defineKzg({
|
23
|
+
blobToKzgCommitment,
|
24
|
+
computeBlobKzgProof,
|
25
|
+
}: DefineKzgParameters): DefineKzgReturnType {
|
26
|
+
return {
|
27
|
+
blobToKzgCommitment,
|
28
|
+
computeBlobKzgProof,
|
29
|
+
}
|
30
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import type { ErrorType } from '../../errors/utils.js'
|
2
|
+
import {
|
3
|
+
type DefineKzgErrorType,
|
4
|
+
type DefineKzgParameters,
|
5
|
+
type DefineKzgReturnType,
|
6
|
+
defineKzg,
|
7
|
+
} from './defineKzg.js'
|
8
|
+
|
9
|
+
export type SetupKzgParameters = DefineKzgParameters & {
|
10
|
+
loadTrustedSetup(path: string): void
|
11
|
+
}
|
12
|
+
export type SetupKzgReturnType = DefineKzgReturnType
|
13
|
+
export type SetupKzgErrorType = DefineKzgErrorType | ErrorType
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Sets up and returns a KZG interface.
|
17
|
+
*
|
18
|
+
* @example
|
19
|
+
* ```ts
|
20
|
+
* import * as cKzg from 'c-kzg'
|
21
|
+
* import { setupKzg } from 'viem'
|
22
|
+
* import { mainnetTrustedSetupPath } from 'viem/node'
|
23
|
+
*
|
24
|
+
* const kzg = setupKzg(cKzg, mainnetTrustedSetupPath)
|
25
|
+
* ```
|
26
|
+
*/
|
27
|
+
export function setupKzg(
|
28
|
+
parameters: SetupKzgParameters,
|
29
|
+
path: string,
|
30
|
+
): SetupKzgReturnType {
|
31
|
+
try {
|
32
|
+
parameters.loadTrustedSetup(path)
|
33
|
+
} catch (e) {
|
34
|
+
const error = e as Error
|
35
|
+
if (!error.message.includes('trusted setup is already loaded')) throw error
|
36
|
+
}
|
37
|
+
return defineKzg(parameters)
|
38
|
+
}
|
@@ -30,8 +30,8 @@ export function compactSignatureToSignature({
|
|
30
30
|
yParityAndS,
|
31
31
|
}: CompactSignature): Signature {
|
32
32
|
const yParityAndS_bytes = hexToBytes(yParityAndS)
|
33
|
-
const
|
33
|
+
const yParity = yParityAndS_bytes[0] & 0x80 ? 1 : 0
|
34
34
|
const s = yParityAndS_bytes
|
35
|
-
if (
|
36
|
-
return { r, s: bytesToHex(s),
|
35
|
+
if (yParity === 1) s[0] &= 0x7f
|
36
|
+
return { r, s: bytesToHex(s), yParity }
|
37
37
|
}
|
@@ -22,5 +22,10 @@ export type HexToSignatureErrorType = NumberToHexErrorType | ErrorType
|
|
22
22
|
export function hexToSignature(signatureHex: Hex): Signature {
|
23
23
|
const { r, s } = secp256k1.Signature.fromCompact(signatureHex.slice(2, 130))
|
24
24
|
const v = BigInt(`0x${signatureHex.slice(130)}`)
|
25
|
-
return {
|
25
|
+
return {
|
26
|
+
r: numberToHex(r, { size: 32 }),
|
27
|
+
s: numberToHex(s, { size: 32 }),
|
28
|
+
v,
|
29
|
+
yParity: v === 28n ? 1 : 0,
|
30
|
+
}
|
26
31
|
}
|
@@ -22,7 +22,7 @@ export type SignatureToCompactSignatureErrorType =
|
|
22
22
|
* signatureToCompactSignature({
|
23
23
|
* r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
|
24
24
|
* s: '0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
|
25
|
-
*
|
25
|
+
* yParity: 0
|
26
26
|
* })
|
27
27
|
* // {
|
28
28
|
* // r: '0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
|
@@ -32,10 +32,10 @@ export type SignatureToCompactSignatureErrorType =
|
|
32
32
|
export function signatureToCompactSignature(
|
33
33
|
signature: Signature,
|
34
34
|
): CompactSignature {
|
35
|
-
const { r, s, v } = signature
|
36
|
-
const
|
35
|
+
const { r, s, v, yParity } = signature
|
36
|
+
const yParity_ = Number(yParity ?? v! - 27n)
|
37
37
|
let yParityAndS = s
|
38
|
-
if (
|
38
|
+
if (yParity_ === 1) {
|
39
39
|
const bytes = hexToBytes(s)
|
40
40
|
bytes[0] |= 0x80
|
41
41
|
yParityAndS = bytesToHex(bytes)
|