Skip to content

Commit b084bb4

Browse files
chore: update regex for raw trx hex validation
TICKET: WIN-7341
1 parent 7cbb24e commit b084bb4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

modules/abstract-eth/src/lib/transactionBuilder.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { Transaction } from './transaction';
4949
import { TransferBuilder } from './transferBuilder';
5050

5151
const DEFAULT_M = 3;
52+
const RAW_TX_HEX_REGEX = /^(0x)?[0-9a-f]{1,}$/;
5253

5354
/**
5455
* EthereumLike transaction builder.
@@ -165,7 +166,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
165166
/** @inheritdoc */
166167
protected fromImplementation(rawTransaction: string, isFirstSigner?: boolean): Transaction {
167168
let tx: Transaction;
168-
if (/^0x?[0-9a-f]{1,}$/.test(rawTransaction.toLowerCase())) {
169+
if (RAW_TX_HEX_REGEX.test(rawTransaction.toLowerCase())) {
169170
tx = Transaction.fromSerialized(this._coinConfig, this._common, rawTransaction, isFirstSigner);
170171
this.loadBuilderInput(tx.toJson(), isFirstSigner);
171172
} else {
@@ -343,7 +344,7 @@ export abstract class TransactionBuilder extends BaseTransactionBuilder {
343344
throw new InvalidTransactionError('Raw transaction is empty');
344345
}
345346
if (typeof rawTransaction === 'string') {
346-
if (/^0x?[0-9a-f]{1,}$/.test(rawTransaction.toLowerCase())) {
347+
if (RAW_TX_HEX_REGEX.test(rawTransaction.toLowerCase())) {
347348
const txBytes = ethUtil.toBuffer(ethUtil.addHexPrefix(rawTransaction.toLowerCase()));
348349
if (!this.isEip1559Txn(txBytes) && !this.isRLPDecodable(txBytes)) {
349350
throw new ParseTransactionError('There was error in decoding the hex string');

0 commit comments

Comments
 (0)